Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[sfrench/cifs-2.6.git] / drivers / gpu / drm / omapdrm / dss / core.c
1 /*
2  * linux/drivers/video/omap2/dss/core.c
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6  *
7  * Some code and ideas taken from drivers/video/omap/ driver
8  * by Imre Deak.
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License version 2 as published by
12  * the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17  * more details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #define DSS_SUBSYS_NAME "CORE"
24
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/clk.h>
28 #include <linux/err.h>
29 #include <linux/platform_device.h>
30 #include <linux/seq_file.h>
31 #include <linux/debugfs.h>
32 #include <linux/io.h>
33 #include <linux/device.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/suspend.h>
36 #include <linux/slab.h>
37
38 #include "omapdss.h"
39 #include "dss.h"
40 #include "dss_features.h"
41
42 static struct {
43         struct platform_device *pdev;
44 } core;
45
46 enum omapdss_version omapdss_get_version(void)
47 {
48         struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
49         return pdata->version;
50 }
51 EXPORT_SYMBOL(omapdss_get_version);
52
53 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
54 {
55         struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
56
57         if (!board_data->dsi_enable_pads)
58                 return -ENOENT;
59
60         return board_data->dsi_enable_pads(dsi_id, lane_mask);
61 }
62
63 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
64 {
65         struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
66
67         if (!board_data->dsi_disable_pads)
68                 return;
69
70         return board_data->dsi_disable_pads(dsi_id, lane_mask);
71 }
72
73 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
74 {
75         struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
76
77         if (pdata->set_min_bus_tput)
78                 return pdata->set_min_bus_tput(dev, tput);
79         else
80                 return 0;
81 }
82
83 #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
84 static int dss_debug_show(struct seq_file *s, void *unused)
85 {
86         void (*func)(struct seq_file *) = s->private;
87         func(s);
88         return 0;
89 }
90
91 static int dss_debug_open(struct inode *inode, struct file *file)
92 {
93         return single_open(file, dss_debug_show, inode->i_private);
94 }
95
96 static const struct file_operations dss_debug_fops = {
97         .open           = dss_debug_open,
98         .read           = seq_read,
99         .llseek         = seq_lseek,
100         .release        = single_release,
101 };
102
103 static struct dentry *dss_debugfs_dir;
104
105 static int dss_initialize_debugfs(void)
106 {
107         dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
108         if (IS_ERR(dss_debugfs_dir)) {
109                 int err = PTR_ERR(dss_debugfs_dir);
110                 dss_debugfs_dir = NULL;
111                 return err;
112         }
113
114         debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
115                         &dss_debug_dump_clocks, &dss_debug_fops);
116
117         return 0;
118 }
119
120 static void dss_uninitialize_debugfs(void)
121 {
122         if (dss_debugfs_dir)
123                 debugfs_remove_recursive(dss_debugfs_dir);
124 }
125
126 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
127 {
128         struct dentry *d;
129
130         d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
131                         write, &dss_debug_fops);
132
133         return PTR_ERR_OR_ZERO(d);
134 }
135 #else /* CONFIG_OMAP2_DSS_DEBUGFS */
136 static inline int dss_initialize_debugfs(void)
137 {
138         return 0;
139 }
140 static inline void dss_uninitialize_debugfs(void)
141 {
142 }
143 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
144 {
145         return 0;
146 }
147 #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
148
149 /* PLATFORM DEVICE */
150
151 static void dss_disable_all_devices(void)
152 {
153         struct omap_dss_device *dssdev = NULL;
154
155         for_each_dss_dev(dssdev) {
156                 if (!dssdev->driver)
157                         continue;
158
159                 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
160                         dssdev->driver->disable(dssdev);
161         }
162 }
163
164 static int __init omap_dss_probe(struct platform_device *pdev)
165 {
166         int r;
167
168         core.pdev = pdev;
169
170         dss_features_init(omapdss_get_version());
171
172         r = dss_initialize_debugfs();
173         if (r)
174                 goto err_debugfs;
175
176         return 0;
177
178 err_debugfs:
179
180         return r;
181 }
182
183 static int omap_dss_remove(struct platform_device *pdev)
184 {
185         dss_uninitialize_debugfs();
186
187         return 0;
188 }
189
190 static void omap_dss_shutdown(struct platform_device *pdev)
191 {
192         DSSDBG("shutdown\n");
193         dss_disable_all_devices();
194 }
195
196 static struct platform_driver omap_dss_driver = {
197         .remove         = omap_dss_remove,
198         .shutdown       = omap_dss_shutdown,
199         .driver         = {
200                 .name   = "omapdss",
201         },
202 };
203
204 /* INIT */
205 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
206         dss_init_platform_driver,
207         dispc_init_platform_driver,
208 #ifdef CONFIG_OMAP2_DSS_DSI
209         dsi_init_platform_driver,
210 #endif
211 #ifdef CONFIG_OMAP2_DSS_VENC
212         venc_init_platform_driver,
213 #endif
214 #ifdef CONFIG_OMAP4_DSS_HDMI
215         hdmi4_init_platform_driver,
216 #endif
217 #ifdef CONFIG_OMAP5_DSS_HDMI
218         hdmi5_init_platform_driver,
219 #endif
220 };
221
222 static void (*dss_output_drv_unreg_funcs[])(void) = {
223 #ifdef CONFIG_OMAP5_DSS_HDMI
224         hdmi5_uninit_platform_driver,
225 #endif
226 #ifdef CONFIG_OMAP4_DSS_HDMI
227         hdmi4_uninit_platform_driver,
228 #endif
229 #ifdef CONFIG_OMAP2_DSS_VENC
230         venc_uninit_platform_driver,
231 #endif
232 #ifdef CONFIG_OMAP2_DSS_DSI
233         dsi_uninit_platform_driver,
234 #endif
235         dispc_uninit_platform_driver,
236         dss_uninit_platform_driver,
237 };
238
239 static int __init omap_dss_init(void)
240 {
241         int r;
242         int i;
243
244         r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
245         if (r)
246                 return r;
247
248         for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
249                 r = dss_output_drv_reg_funcs[i]();
250                 if (r)
251                         goto err_reg;
252         }
253
254         return 0;
255
256 err_reg:
257         for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
258                         i < ARRAY_SIZE(dss_output_drv_reg_funcs);
259                         ++i)
260                 dss_output_drv_unreg_funcs[i]();
261
262         platform_driver_unregister(&omap_dss_driver);
263
264         return r;
265 }
266
267 static void __exit omap_dss_exit(void)
268 {
269         int i;
270
271         for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
272                 dss_output_drv_unreg_funcs[i]();
273
274         platform_driver_unregister(&omap_dss_driver);
275 }
276
277 module_init(omap_dss_init);
278 module_exit(omap_dss_exit);
279
280 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
281 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
282 MODULE_LICENSE("GPL v2");
283