Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / video / fbdev / omap2 / omapfb / dss / core.c
blob29de4827589dc5cee33128e8b01c93eaacda805d
1 /*
2 * linux/drivers/video/omap2/dss/core.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
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.
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.
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/>.
23 #define DSS_SUBSYS_NAME "CORE"
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>
38 #include <video/omapfb_dss.h>
40 #include "dss.h"
41 #include "dss_features.h"
43 static struct {
44 struct platform_device *pdev;
46 const char *default_display_name;
47 } core;
49 static char *def_disp_name;
50 module_param_named(def_disp, def_disp_name, charp, 0);
51 MODULE_PARM_DESC(def_disp, "default display name");
53 const char *omapdss_get_default_display_name(void)
55 return core.default_display_name;
57 EXPORT_SYMBOL(omapdss_get_default_display_name);
59 enum omapdss_version omapdss_get_version(void)
61 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
62 return pdata->version;
64 EXPORT_SYMBOL(omapdss_get_version);
66 struct platform_device *dss_get_core_pdev(void)
68 return core.pdev;
71 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
73 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
75 if (!board_data->dsi_enable_pads)
76 return -ENOENT;
78 return board_data->dsi_enable_pads(dsi_id, lane_mask);
81 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
83 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
85 if (!board_data->dsi_disable_pads)
86 return;
88 return board_data->dsi_disable_pads(dsi_id, lane_mask);
91 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
93 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
95 if (pdata->set_min_bus_tput)
96 return pdata->set_min_bus_tput(dev, tput);
97 else
98 return 0;
101 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
102 static int dss_debug_show(struct seq_file *s, void *unused)
104 void (*func)(struct seq_file *) = s->private;
105 func(s);
106 return 0;
109 static int dss_debug_open(struct inode *inode, struct file *file)
111 return single_open(file, dss_debug_show, inode->i_private);
114 static const struct file_operations dss_debug_fops = {
115 .open = dss_debug_open,
116 .read = seq_read,
117 .llseek = seq_lseek,
118 .release = single_release,
121 static struct dentry *dss_debugfs_dir;
123 static int dss_initialize_debugfs(void)
125 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
126 if (IS_ERR(dss_debugfs_dir)) {
127 int err = PTR_ERR(dss_debugfs_dir);
128 dss_debugfs_dir = NULL;
129 return err;
132 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
133 &dss_debug_dump_clocks, &dss_debug_fops);
135 return 0;
138 static void dss_uninitialize_debugfs(void)
140 if (dss_debugfs_dir)
141 debugfs_remove_recursive(dss_debugfs_dir);
144 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
146 struct dentry *d;
148 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
149 write, &dss_debug_fops);
151 return PTR_ERR_OR_ZERO(d);
153 #else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
154 static inline int dss_initialize_debugfs(void)
156 return 0;
158 static inline void dss_uninitialize_debugfs(void)
161 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
163 return 0;
165 #endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
167 /* PLATFORM DEVICE */
168 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
170 DSSDBG("pm notif %lu\n", v);
172 switch (v) {
173 case PM_SUSPEND_PREPARE:
174 case PM_HIBERNATION_PREPARE:
175 case PM_RESTORE_PREPARE:
176 DSSDBG("suspending displays\n");
177 return dss_suspend_all_devices();
179 case PM_POST_SUSPEND:
180 case PM_POST_HIBERNATION:
181 case PM_POST_RESTORE:
182 DSSDBG("resuming displays\n");
183 return dss_resume_all_devices();
185 default:
186 return 0;
190 static struct notifier_block omap_dss_pm_notif_block = {
191 .notifier_call = omap_dss_pm_notif,
194 static int __init omap_dss_probe(struct platform_device *pdev)
196 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
197 int r;
199 core.pdev = pdev;
201 dss_features_init(omapdss_get_version());
203 r = dss_initialize_debugfs();
204 if (r)
205 goto err_debugfs;
207 if (def_disp_name)
208 core.default_display_name = def_disp_name;
209 else if (pdata->default_display_name)
210 core.default_display_name = pdata->default_display_name;
212 register_pm_notifier(&omap_dss_pm_notif_block);
214 return 0;
216 err_debugfs:
218 return r;
221 static int omap_dss_remove(struct platform_device *pdev)
223 unregister_pm_notifier(&omap_dss_pm_notif_block);
225 dss_uninitialize_debugfs();
227 return 0;
230 static void omap_dss_shutdown(struct platform_device *pdev)
232 DSSDBG("shutdown\n");
233 dss_disable_all_devices();
236 static struct platform_driver omap_dss_driver = {
237 .remove = omap_dss_remove,
238 .shutdown = omap_dss_shutdown,
239 .driver = {
240 .name = "omapdss",
244 /* INIT */
245 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
246 dss_init_platform_driver,
247 dispc_init_platform_driver,
248 #ifdef CONFIG_FB_OMAP2_DSS_DSI
249 dsi_init_platform_driver,
250 #endif
251 #ifdef CONFIG_FB_OMAP2_DSS_DPI
252 dpi_init_platform_driver,
253 #endif
254 #ifdef CONFIG_FB_OMAP2_DSS_SDI
255 sdi_init_platform_driver,
256 #endif
257 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
258 rfbi_init_platform_driver,
259 #endif
260 #ifdef CONFIG_FB_OMAP2_DSS_VENC
261 venc_init_platform_driver,
262 #endif
263 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
264 hdmi4_init_platform_driver,
265 #endif
266 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
267 hdmi5_init_platform_driver,
268 #endif
271 static void (*dss_output_drv_unreg_funcs[])(void) = {
272 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
273 hdmi5_uninit_platform_driver,
274 #endif
275 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
276 hdmi4_uninit_platform_driver,
277 #endif
278 #ifdef CONFIG_FB_OMAP2_DSS_VENC
279 venc_uninit_platform_driver,
280 #endif
281 #ifdef CONFIG_FB_OMAP2_DSS_RFBI
282 rfbi_uninit_platform_driver,
283 #endif
284 #ifdef CONFIG_FB_OMAP2_DSS_SDI
285 sdi_uninit_platform_driver,
286 #endif
287 #ifdef CONFIG_FB_OMAP2_DSS_DPI
288 dpi_uninit_platform_driver,
289 #endif
290 #ifdef CONFIG_FB_OMAP2_DSS_DSI
291 dsi_uninit_platform_driver,
292 #endif
293 dispc_uninit_platform_driver,
294 dss_uninit_platform_driver,
297 static int __init omap_dss_init(void)
299 int r;
300 int i;
302 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
303 if (r)
304 return r;
306 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
307 r = dss_output_drv_reg_funcs[i]();
308 if (r)
309 goto err_reg;
312 return 0;
314 err_reg:
315 for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
316 i < ARRAY_SIZE(dss_output_drv_reg_funcs);
317 ++i)
318 dss_output_drv_unreg_funcs[i]();
320 platform_driver_unregister(&omap_dss_driver);
322 return r;
325 static void __exit omap_dss_exit(void)
327 int i;
329 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
330 dss_output_drv_unreg_funcs[i]();
332 platform_driver_unregister(&omap_dss_driver);
335 module_init(omap_dss_init);
336 module_exit(omap_dss_exit);
338 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
339 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
340 MODULE_LICENSE("GPL v2");