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 .probe = omap_dss_probe,
266 .remove = omap_dss_remove,
267 .shutdown = omap_dss_shutdown,
270 .owner = THIS_MODULE,
275 static int dss_bus_match(struct device *dev, struct device_driver *driver)
277 struct omap_dss_device *dssdev = to_dss_device(dev);
279 DSSDBG("bus_match. dev %s/%s, drv %s\n",
280 dev_name(dev), dssdev->driver_name, driver->name);
282 return strcmp(dssdev->driver_name, driver->name) == 0;
285 static ssize_t device_name_show(struct device *dev,
286 struct device_attribute *attr, char *buf)
288 struct omap_dss_device *dssdev = to_dss_device(dev);
289 return snprintf(buf, PAGE_SIZE, "%s\n",
294 static struct device_attribute default_dev_attrs[] = {
295 __ATTR(name, S_IRUGO, device_name_show, NULL),
299 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
301 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
302 return snprintf(buf, PAGE_SIZE, "%s\n",
303 dssdrv->driver.name ?
304 dssdrv->driver.name : "");
306 static struct driver_attribute default_drv_attrs[] = {
307 __ATTR(name, S_IRUGO, driver_name_show, NULL),
311 static struct bus_type dss_bus_type = {
313 .match = dss_bus_match,
314 .dev_attrs = default_dev_attrs,
315 .drv_attrs = default_drv_attrs,
318 static void dss_bus_release(struct device *dev)
320 DSSDBG("bus_release\n");
323 static struct device dss_bus = {
324 .release = dss_bus_release,
327 struct bus_type *dss_get_bus(void)
329 return &dss_bus_type;
333 static int dss_driver_probe(struct device *dev)
336 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
337 struct omap_dss_device *dssdev = to_dss_device(dev);
338 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
341 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
342 dev_name(dev), dssdev->driver_name,
343 dssdrv->driver.name);
345 dss_init_device(core.pdev, dssdev);
347 force = pdata->default_device == dssdev;
348 dss_recheck_connections(dssdev, force);
350 r = dssdrv->probe(dssdev);
353 DSSERR("driver probe failed: %d\n", r);
354 dss_uninit_device(core.pdev, dssdev);
358 DSSDBG("probe done for device %s\n", dev_name(dev));
360 dssdev->driver = dssdrv;
365 static int dss_driver_remove(struct device *dev)
367 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
368 struct omap_dss_device *dssdev = to_dss_device(dev);
370 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
371 dssdev->driver_name);
373 dssdrv->remove(dssdev);
375 dss_uninit_device(core.pdev, dssdev);
377 dssdev->driver = NULL;
382 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
384 dssdriver->driver.bus = &dss_bus_type;
385 dssdriver->driver.probe = dss_driver_probe;
386 dssdriver->driver.remove = dss_driver_remove;
388 if (dssdriver->get_resolution == NULL)
389 dssdriver->get_resolution = omapdss_default_get_resolution;
390 if (dssdriver->get_recommended_bpp == NULL)
391 dssdriver->get_recommended_bpp =
392 omapdss_default_get_recommended_bpp;
393 if (dssdriver->get_timings == NULL)
394 dssdriver->get_timings = omapdss_default_get_timings;
396 return driver_register(&dssdriver->driver);
398 EXPORT_SYMBOL(omap_dss_register_driver);
400 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
402 driver_unregister(&dssdriver->driver);
404 EXPORT_SYMBOL(omap_dss_unregister_driver);
407 static void reset_device(struct device *dev, int check)
409 u8 *dev_p = (u8 *)dev;
410 u8 *dev_end = dev_p + sizeof(*dev);
413 saved_pdata = dev->platform_data;
416 * Check if there is any other setting than platform_data
417 * in struct device; warn that these will be reset by our
420 dev->platform_data = NULL;
421 while (dev_p < dev_end) {
423 WARN("%s: struct device fields will be "
431 memset(dev, 0, sizeof(*dev));
432 dev->platform_data = saved_pdata;
436 static void omap_dss_dev_release(struct device *dev)
438 reset_device(dev, 0);
441 static int omap_dss_register_device(struct omap_dss_device *dssdev)
445 WARN_ON(!dssdev->driver_name);
447 reset_device(&dssdev->dev, 1);
448 dssdev->dev.bus = &dss_bus_type;
449 dssdev->dev.parent = &dss_bus;
450 dssdev->dev.release = omap_dss_dev_release;
451 dev_set_name(&dssdev->dev, "display%d", dev_num++);
452 return device_register(&dssdev->dev);
455 static void omap_dss_unregister_device(struct omap_dss_device *dssdev)
457 device_unregister(&dssdev->dev);
461 static int omap_dss_bus_register(void)
465 r = bus_register(&dss_bus_type);
467 DSSERR("bus register failed\n");
471 dev_set_name(&dss_bus, "omapdss");
472 r = device_register(&dss_bus);
474 DSSERR("bus driver register failed\n");
475 bus_unregister(&dss_bus_type);
484 static int __init omap_dss_register_drivers(void)
488 r = platform_driver_register(&omap_dss_driver);
492 r = dss_init_platform_driver();
494 DSSERR("Failed to initialize DSS platform driver\n");
498 r = dispc_init_platform_driver();
500 DSSERR("Failed to initialize dispc platform driver\n");
504 r = rfbi_init_platform_driver();
506 DSSERR("Failed to initialize rfbi platform driver\n");
510 r = venc_init_platform_driver();
512 DSSERR("Failed to initialize venc platform driver\n");
516 r = dsi_init_platform_driver();
518 DSSERR("Failed to initialize DSI platform driver\n");
522 r = hdmi_init_platform_driver();
524 DSSERR("Failed to initialize hdmi\n");
531 dsi_uninit_platform_driver();
533 venc_uninit_platform_driver();
535 rfbi_uninit_platform_driver();
537 dispc_uninit_platform_driver();
539 dss_uninit_platform_driver();
541 platform_driver_unregister(&omap_dss_driver);
546 static void __exit omap_dss_unregister_drivers(void)
548 hdmi_uninit_platform_driver();
549 dsi_uninit_platform_driver();
550 venc_uninit_platform_driver();
551 rfbi_uninit_platform_driver();
552 dispc_uninit_platform_driver();
553 dss_uninit_platform_driver();
555 platform_driver_unregister(&omap_dss_driver);
558 #ifdef CONFIG_OMAP2_DSS_MODULE
559 static void omap_dss_bus_unregister(void)
561 device_unregister(&dss_bus);
563 bus_unregister(&dss_bus_type);
566 static int __init omap_dss_init(void)
570 r = omap_dss_bus_register();
574 r = omap_dss_register_drivers();
576 omap_dss_bus_unregister();
583 static void __exit omap_dss_exit(void)
585 if (core.vdds_dsi_reg != NULL) {
586 regulator_put(core.vdds_dsi_reg);
587 core.vdds_dsi_reg = NULL;
590 if (core.vdds_sdi_reg != NULL) {
591 regulator_put(core.vdds_sdi_reg);
592 core.vdds_sdi_reg = NULL;
595 omap_dss_unregister_drivers();
597 omap_dss_bus_unregister();
600 module_init(omap_dss_init);
601 module_exit(omap_dss_exit);
603 static int __init omap_dss_init(void)
605 return omap_dss_bus_register();
608 static int __init omap_dss_init2(void)
610 return omap_dss_register_drivers();
613 core_initcall(omap_dss_init);
614 device_initcall(omap_dss_init2);
617 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
618 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
619 MODULE_LICENSE("GPL v2");