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
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
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>
33 #include <linux/device.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/suspend.h>
37 #include <video/omapdss.h>
40 #include "dss_features.h"
43 struct platform_device *pdev;
45 struct regulator *vdds_dsi_reg;
46 struct regulator *vdds_sdi_reg;
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");
54 unsigned int dss_debug;
55 module_param_named(debug, dss_debug, bool, 0644);
58 static int omap_dss_register_device(struct omap_dss_device *);
59 static void omap_dss_unregister_device(struct omap_dss_device *);
63 struct regulator *dss_get_vdds_dsi(void)
65 struct regulator *reg;
67 if (core.vdds_dsi_reg != NULL)
68 return core.vdds_dsi_reg;
70 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
72 core.vdds_dsi_reg = reg;
77 struct regulator *dss_get_vdds_sdi(void)
79 struct regulator *reg;
81 if (core.vdds_sdi_reg != NULL)
82 return core.vdds_sdi_reg;
84 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
86 core.vdds_sdi_reg = reg;
91 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
92 static int dss_debug_show(struct seq_file *s, void *unused)
94 void (*func)(struct seq_file *) = s->private;
99 static int dss_debug_open(struct inode *inode, struct file *file)
101 return single_open(file, dss_debug_show, inode->i_private);
104 static const struct file_operations dss_debug_fops = {
105 .open = dss_debug_open,
108 .release = single_release,
111 static struct dentry *dss_debugfs_dir;
113 static int dss_initialize_debugfs(void)
115 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
116 if (IS_ERR(dss_debugfs_dir)) {
117 int err = PTR_ERR(dss_debugfs_dir);
118 dss_debugfs_dir = NULL;
122 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
123 &dss_debug_dump_clocks, &dss_debug_fops);
125 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
126 debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
127 &dispc_dump_irqs, &dss_debug_fops);
130 #if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
131 dsi_create_debugfs_files_irq(dss_debugfs_dir, &dss_debug_fops);
134 debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
135 &dss_dump_regs, &dss_debug_fops);
136 debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
137 &dispc_dump_regs, &dss_debug_fops);
138 #ifdef CONFIG_OMAP2_DSS_RFBI
139 debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
140 &rfbi_dump_regs, &dss_debug_fops);
142 #ifdef CONFIG_OMAP2_DSS_DSI
143 dsi_create_debugfs_files_reg(dss_debugfs_dir, &dss_debug_fops);
145 #ifdef CONFIG_OMAP2_DSS_VENC
146 debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
147 &venc_dump_regs, &dss_debug_fops);
149 #ifdef CONFIG_OMAP4_DSS_HDMI
150 debugfs_create_file("hdmi", S_IRUGO, dss_debugfs_dir,
151 &hdmi_dump_regs, &dss_debug_fops);
156 static void dss_uninitialize_debugfs(void)
159 debugfs_remove_recursive(dss_debugfs_dir);
161 #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
162 static inline int dss_initialize_debugfs(void)
166 static inline void dss_uninitialize_debugfs(void)
169 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
171 /* PLATFORM DEVICE */
172 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
174 DSSDBG("pm notif %lu\n", v);
177 case PM_SUSPEND_PREPARE:
178 DSSDBG("suspending displays\n");
179 return dss_suspend_all_devices();
181 case PM_POST_SUSPEND:
182 DSSDBG("resuming displays\n");
183 return dss_resume_all_devices();
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;
204 dss_init_overlay_managers(pdev);
205 dss_init_overlays(pdev);
207 r = dss_initialize_debugfs();
211 for (i = 0; i < pdata->num_devices; ++i) {
212 struct omap_dss_device *dssdev = pdata->devices[i];
214 r = omap_dss_register_device(dssdev);
216 DSSERR("device %d %s register failed %d\n", i,
217 dssdev->name ?: "unnamed", r);
220 omap_dss_unregister_device(pdata->devices[i]);
225 if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
226 pdata->default_device = dssdev;
229 register_pm_notifier(&omap_dss_pm_notif_block);
234 dss_uninitialize_debugfs();
240 static int omap_dss_remove(struct platform_device *pdev)
242 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
245 unregister_pm_notifier(&omap_dss_pm_notif_block);
247 dss_uninitialize_debugfs();
249 dss_uninit_overlays(pdev);
250 dss_uninit_overlay_managers(pdev);
252 for (i = 0; i < pdata->num_devices; ++i)
253 omap_dss_unregister_device(pdata->devices[i]);
258 static void omap_dss_shutdown(struct platform_device *pdev)
260 DSSDBG("shutdown\n");
261 dss_disable_all_devices();
264 static struct platform_driver omap_dss_driver = {
265 .remove = omap_dss_remove,
266 .shutdown = omap_dss_shutdown,
269 .owner = THIS_MODULE,
274 static int dss_bus_match(struct device *dev, struct device_driver *driver)
276 struct omap_dss_device *dssdev = to_dss_device(dev);
278 DSSDBG("bus_match. dev %s/%s, drv %s\n",
279 dev_name(dev), dssdev->driver_name, driver->name);
281 return strcmp(dssdev->driver_name, driver->name) == 0;
284 static ssize_t device_name_show(struct device *dev,
285 struct device_attribute *attr, char *buf)
287 struct omap_dss_device *dssdev = to_dss_device(dev);
288 return snprintf(buf, PAGE_SIZE, "%s\n",
293 static struct device_attribute default_dev_attrs[] = {
294 __ATTR(name, S_IRUGO, device_name_show, NULL),
298 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
300 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
301 return snprintf(buf, PAGE_SIZE, "%s\n",
302 dssdrv->driver.name ?
303 dssdrv->driver.name : "");
305 static struct driver_attribute default_drv_attrs[] = {
306 __ATTR(name, S_IRUGO, driver_name_show, NULL),
310 static struct bus_type dss_bus_type = {
312 .match = dss_bus_match,
313 .dev_attrs = default_dev_attrs,
314 .drv_attrs = default_drv_attrs,
317 static void dss_bus_release(struct device *dev)
319 DSSDBG("bus_release\n");
322 static struct device dss_bus = {
323 .release = dss_bus_release,
326 struct bus_type *dss_get_bus(void)
328 return &dss_bus_type;
332 static int dss_driver_probe(struct device *dev)
335 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
336 struct omap_dss_device *dssdev = to_dss_device(dev);
337 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
340 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
341 dev_name(dev), dssdev->driver_name,
342 dssdrv->driver.name);
344 dss_init_device(core.pdev, dssdev);
346 force = pdata->default_device == dssdev;
347 dss_recheck_connections(dssdev, force);
349 r = dssdrv->probe(dssdev);
352 DSSERR("driver probe failed: %d\n", r);
353 dss_uninit_device(core.pdev, dssdev);
357 DSSDBG("probe done for device %s\n", dev_name(dev));
359 dssdev->driver = dssdrv;
364 static int dss_driver_remove(struct device *dev)
366 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
367 struct omap_dss_device *dssdev = to_dss_device(dev);
369 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
370 dssdev->driver_name);
372 dssdrv->remove(dssdev);
374 dss_uninit_device(core.pdev, dssdev);
376 dssdev->driver = NULL;
381 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
383 dssdriver->driver.bus = &dss_bus_type;
384 dssdriver->driver.probe = dss_driver_probe;
385 dssdriver->driver.remove = dss_driver_remove;
387 if (dssdriver->get_resolution == NULL)
388 dssdriver->get_resolution = omapdss_default_get_resolution;
389 if (dssdriver->get_recommended_bpp == NULL)
390 dssdriver->get_recommended_bpp =
391 omapdss_default_get_recommended_bpp;
392 if (dssdriver->get_timings == NULL)
393 dssdriver->get_timings = omapdss_default_get_timings;
395 return driver_register(&dssdriver->driver);
397 EXPORT_SYMBOL(omap_dss_register_driver);
399 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
401 driver_unregister(&dssdriver->driver);
403 EXPORT_SYMBOL(omap_dss_unregister_driver);
406 static void reset_device(struct device *dev, int check)
408 u8 *dev_p = (u8 *)dev;
409 u8 *dev_end = dev_p + sizeof(*dev);
412 saved_pdata = dev->platform_data;
415 * Check if there is any other setting than platform_data
416 * in struct device; warn that these will be reset by our
419 dev->platform_data = NULL;
420 while (dev_p < dev_end) {
422 WARN("%s: struct device fields will be "
430 memset(dev, 0, sizeof(*dev));
431 dev->platform_data = saved_pdata;
435 static void omap_dss_dev_release(struct device *dev)
437 reset_device(dev, 0);
440 static int omap_dss_register_device(struct omap_dss_device *dssdev)
444 WARN_ON(!dssdev->driver_name);
446 reset_device(&dssdev->dev, 1);
447 dssdev->dev.bus = &dss_bus_type;
448 dssdev->dev.parent = &dss_bus;
449 dssdev->dev.release = omap_dss_dev_release;
450 dev_set_name(&dssdev->dev, "display%d", dev_num++);
451 return device_register(&dssdev->dev);
454 static void omap_dss_unregister_device(struct omap_dss_device *dssdev)
456 device_unregister(&dssdev->dev);
460 static int omap_dss_bus_register(void)
464 r = bus_register(&dss_bus_type);
466 DSSERR("bus register failed\n");
470 dev_set_name(&dss_bus, "omapdss");
471 r = device_register(&dss_bus);
473 DSSERR("bus driver register failed\n");
474 bus_unregister(&dss_bus_type);
483 static int __init omap_dss_register_drivers(void)
487 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
491 r = dss_init_platform_driver();
493 DSSERR("Failed to initialize DSS platform driver\n");
497 r = dispc_init_platform_driver();
499 DSSERR("Failed to initialize dispc platform driver\n");
503 r = rfbi_init_platform_driver();
505 DSSERR("Failed to initialize rfbi platform driver\n");
509 r = venc_init_platform_driver();
511 DSSERR("Failed to initialize venc platform driver\n");
515 r = dsi_init_platform_driver();
517 DSSERR("Failed to initialize DSI platform driver\n");
521 r = hdmi_init_platform_driver();
523 DSSERR("Failed to initialize hdmi\n");
530 dsi_uninit_platform_driver();
532 venc_uninit_platform_driver();
534 rfbi_uninit_platform_driver();
536 dispc_uninit_platform_driver();
538 dss_uninit_platform_driver();
540 platform_driver_unregister(&omap_dss_driver);
545 static void __exit omap_dss_unregister_drivers(void)
547 hdmi_uninit_platform_driver();
548 dsi_uninit_platform_driver();
549 venc_uninit_platform_driver();
550 rfbi_uninit_platform_driver();
551 dispc_uninit_platform_driver();
552 dss_uninit_platform_driver();
554 platform_driver_unregister(&omap_dss_driver);
557 #ifdef CONFIG_OMAP2_DSS_MODULE
558 static void omap_dss_bus_unregister(void)
560 device_unregister(&dss_bus);
562 bus_unregister(&dss_bus_type);
565 static int __init omap_dss_init(void)
569 r = omap_dss_bus_register();
573 r = omap_dss_register_drivers();
575 omap_dss_bus_unregister();
582 static void __exit omap_dss_exit(void)
584 if (core.vdds_dsi_reg != NULL) {
585 regulator_put(core.vdds_dsi_reg);
586 core.vdds_dsi_reg = NULL;
589 if (core.vdds_sdi_reg != NULL) {
590 regulator_put(core.vdds_sdi_reg);
591 core.vdds_sdi_reg = NULL;
594 omap_dss_unregister_drivers();
596 omap_dss_bus_unregister();
599 module_init(omap_dss_init);
600 module_exit(omap_dss_exit);
602 static int __init omap_dss_init(void)
604 return omap_dss_bus_register();
607 static int __init omap_dss_init2(void)
609 return omap_dss_register_drivers();
612 core_initcall(omap_dss_init);
613 device_initcall(omap_dss_init2);
616 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
617 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
618 MODULE_LICENSE("GPL v2");