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>
36 #include <plat/display.h>
39 #include "dss_features.h"
42 struct platform_device *pdev;
44 struct regulator *vdds_dsi_reg;
45 struct regulator *vdds_sdi_reg;
46 struct regulator *vdda_dac_reg;
49 static char *def_disp_name;
50 module_param_named(def_disp, def_disp_name, charp, 0);
51 MODULE_PARM_DESC(def_disp_name, "default display name");
54 unsigned int dss_debug;
55 module_param_named(debug, dss_debug, bool, 0644);
60 struct regulator *dss_get_vdds_dsi(void)
62 struct regulator *reg;
64 if (core.vdds_dsi_reg != NULL)
65 return core.vdds_dsi_reg;
67 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
69 core.vdds_dsi_reg = reg;
74 struct regulator *dss_get_vdds_sdi(void)
76 struct regulator *reg;
78 if (core.vdds_sdi_reg != NULL)
79 return core.vdds_sdi_reg;
81 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
83 core.vdds_sdi_reg = reg;
88 struct regulator *dss_get_vdda_dac(void)
90 struct regulator *reg;
92 if (core.vdda_dac_reg != NULL)
93 return core.vdda_dac_reg;
95 reg = regulator_get(&core.pdev->dev, "vdda_dac");
97 core.vdda_dac_reg = reg;
102 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
103 static int dss_debug_show(struct seq_file *s, void *unused)
105 void (*func)(struct seq_file *) = s->private;
110 static int dss_debug_open(struct inode *inode, struct file *file)
112 return single_open(file, dss_debug_show, inode->i_private);
115 static const struct file_operations dss_debug_fops = {
116 .open = dss_debug_open,
119 .release = single_release,
122 static struct dentry *dss_debugfs_dir;
124 static int dss_initialize_debugfs(void)
126 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
127 if (IS_ERR(dss_debugfs_dir)) {
128 int err = PTR_ERR(dss_debugfs_dir);
129 dss_debugfs_dir = NULL;
133 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
134 &dss_debug_dump_clocks, &dss_debug_fops);
136 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
137 debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
138 &dispc_dump_irqs, &dss_debug_fops);
141 #if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
142 debugfs_create_file("dsi_irq", S_IRUGO, dss_debugfs_dir,
143 &dsi_dump_irqs, &dss_debug_fops);
146 debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
147 &dss_dump_regs, &dss_debug_fops);
148 debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
149 &dispc_dump_regs, &dss_debug_fops);
150 #ifdef CONFIG_OMAP2_DSS_RFBI
151 debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
152 &rfbi_dump_regs, &dss_debug_fops);
154 #ifdef CONFIG_OMAP2_DSS_DSI
155 debugfs_create_file("dsi", S_IRUGO, dss_debugfs_dir,
156 &dsi_dump_regs, &dss_debug_fops);
158 #ifdef CONFIG_OMAP2_DSS_VENC
159 debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
160 &venc_dump_regs, &dss_debug_fops);
165 static void dss_uninitialize_debugfs(void)
168 debugfs_remove_recursive(dss_debugfs_dir);
170 #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
171 static inline int dss_initialize_debugfs(void)
175 static inline void dss_uninitialize_debugfs(void)
178 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
180 /* PLATFORM DEVICE */
181 static int omap_dss_probe(struct platform_device *pdev)
183 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
192 dss_init_overlay_managers(pdev);
193 dss_init_overlays(pdev);
195 r = dss_init_platform_driver();
197 DSSERR("Failed to initialize DSS platform driver\n");
201 /* keep clocks enabled to prevent context saves/restores during init */
202 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
206 DSSERR("Failed to initialize rfbi\n");
212 DSSERR("Failed to initialize dpi\n");
218 DSSERR("Failed to initialize dispc\n");
224 DSSERR("Failed to initialize venc\n");
228 #ifdef CONFIG_FB_OMAP_BOOTLOADER_INIT
230 if (omap_readl(0x48050440) & 1) /* LCD enabled? */
233 if (cpu_is_omap34xx()) {
234 r = sdi_init(skip_init);
236 DSSERR("Failed to initialize SDI\n");
242 DSSERR("Failed to initialize DSI\n");
247 r = dss_initialize_debugfs();
251 for (i = 0; i < pdata->num_devices; ++i) {
252 struct omap_dss_device *dssdev = pdata->devices[i];
254 r = omap_dss_register_device(dssdev);
256 DSSERR("device %d %s register failed %d\n", i,
257 dssdev->name ?: "unnamed", r);
260 omap_dss_unregister_device(pdata->devices[i]);
265 if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
266 pdata->default_device = dssdev;
269 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
274 dss_uninitialize_debugfs();
276 if (cpu_is_omap34xx())
279 if (cpu_is_omap34xx())
290 dss_uninit_platform_driver();
296 static int omap_dss_remove(struct platform_device *pdev)
298 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
301 dss_uninitialize_debugfs();
307 if (cpu_is_omap34xx()) {
312 dss_uninit_platform_driver();
314 dss_uninit_overlays(pdev);
315 dss_uninit_overlay_managers(pdev);
317 for (i = 0; i < pdata->num_devices; ++i)
318 omap_dss_unregister_device(pdata->devices[i]);
323 static void omap_dss_shutdown(struct platform_device *pdev)
325 DSSDBG("shutdown\n");
326 dss_disable_all_devices();
329 static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
331 DSSDBG("suspend %d\n", state.event);
333 return dss_suspend_all_devices();
336 static int omap_dss_resume(struct platform_device *pdev)
340 return dss_resume_all_devices();
343 static struct platform_driver omap_dss_driver = {
344 .probe = omap_dss_probe,
345 .remove = omap_dss_remove,
346 .shutdown = omap_dss_shutdown,
347 .suspend = omap_dss_suspend,
348 .resume = omap_dss_resume,
351 .owner = THIS_MODULE,
356 static int dss_bus_match(struct device *dev, struct device_driver *driver)
358 struct omap_dss_device *dssdev = to_dss_device(dev);
360 DSSDBG("bus_match. dev %s/%s, drv %s\n",
361 dev_name(dev), dssdev->driver_name, driver->name);
363 return strcmp(dssdev->driver_name, driver->name) == 0;
366 static ssize_t device_name_show(struct device *dev,
367 struct device_attribute *attr, char *buf)
369 struct omap_dss_device *dssdev = to_dss_device(dev);
370 return snprintf(buf, PAGE_SIZE, "%s\n",
375 static struct device_attribute default_dev_attrs[] = {
376 __ATTR(name, S_IRUGO, device_name_show, NULL),
380 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
382 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
383 return snprintf(buf, PAGE_SIZE, "%s\n",
384 dssdrv->driver.name ?
385 dssdrv->driver.name : "");
387 static struct driver_attribute default_drv_attrs[] = {
388 __ATTR(name, S_IRUGO, driver_name_show, NULL),
392 static struct bus_type dss_bus_type = {
394 .match = dss_bus_match,
395 .dev_attrs = default_dev_attrs,
396 .drv_attrs = default_drv_attrs,
399 static void dss_bus_release(struct device *dev)
401 DSSDBG("bus_release\n");
404 static struct device dss_bus = {
405 .release = dss_bus_release,
408 struct bus_type *dss_get_bus(void)
410 return &dss_bus_type;
414 static int dss_driver_probe(struct device *dev)
417 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
418 struct omap_dss_device *dssdev = to_dss_device(dev);
419 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
422 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
423 dev_name(dev), dssdev->driver_name,
424 dssdrv->driver.name);
426 dss_init_device(core.pdev, dssdev);
428 force = pdata->default_device == dssdev;
429 dss_recheck_connections(dssdev, force);
431 r = dssdrv->probe(dssdev);
434 DSSERR("driver probe failed: %d\n", r);
435 dss_uninit_device(core.pdev, dssdev);
439 DSSDBG("probe done for device %s\n", dev_name(dev));
441 dssdev->driver = dssdrv;
446 static int dss_driver_remove(struct device *dev)
448 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
449 struct omap_dss_device *dssdev = to_dss_device(dev);
451 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
452 dssdev->driver_name);
454 dssdrv->remove(dssdev);
456 dss_uninit_device(core.pdev, dssdev);
458 dssdev->driver = NULL;
463 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
465 dssdriver->driver.bus = &dss_bus_type;
466 dssdriver->driver.probe = dss_driver_probe;
467 dssdriver->driver.remove = dss_driver_remove;
469 if (dssdriver->get_resolution == NULL)
470 dssdriver->get_resolution = omapdss_default_get_resolution;
471 if (dssdriver->get_recommended_bpp == NULL)
472 dssdriver->get_recommended_bpp =
473 omapdss_default_get_recommended_bpp;
475 return driver_register(&dssdriver->driver);
477 EXPORT_SYMBOL(omap_dss_register_driver);
479 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
481 driver_unregister(&dssdriver->driver);
483 EXPORT_SYMBOL(omap_dss_unregister_driver);
486 static void reset_device(struct device *dev, int check)
488 u8 *dev_p = (u8 *)dev;
489 u8 *dev_end = dev_p + sizeof(*dev);
492 saved_pdata = dev->platform_data;
495 * Check if there is any other setting than platform_data
496 * in struct device; warn that these will be reset by our
499 dev->platform_data = NULL;
500 while (dev_p < dev_end) {
502 WARN("%s: struct device fields will be "
510 memset(dev, 0, sizeof(*dev));
511 dev->platform_data = saved_pdata;
515 static void omap_dss_dev_release(struct device *dev)
517 reset_device(dev, 0);
520 int omap_dss_register_device(struct omap_dss_device *dssdev)
524 WARN_ON(!dssdev->driver_name);
526 reset_device(&dssdev->dev, 1);
527 dssdev->dev.bus = &dss_bus_type;
528 dssdev->dev.parent = &dss_bus;
529 dssdev->dev.release = omap_dss_dev_release;
530 dev_set_name(&dssdev->dev, "display%d", dev_num++);
531 return device_register(&dssdev->dev);
534 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
536 device_unregister(&dssdev->dev);
540 static int omap_dss_bus_register(void)
544 r = bus_register(&dss_bus_type);
546 DSSERR("bus register failed\n");
550 dev_set_name(&dss_bus, "omapdss");
551 r = device_register(&dss_bus);
553 DSSERR("bus driver register failed\n");
554 bus_unregister(&dss_bus_type);
563 #ifdef CONFIG_OMAP2_DSS_MODULE
564 static void omap_dss_bus_unregister(void)
566 device_unregister(&dss_bus);
568 bus_unregister(&dss_bus_type);
571 static int __init omap_dss_init(void)
575 r = omap_dss_bus_register();
579 r = platform_driver_register(&omap_dss_driver);
581 omap_dss_bus_unregister();
588 static void __exit omap_dss_exit(void)
590 if (core.vdds_dsi_reg != NULL) {
591 regulator_put(core.vdds_dsi_reg);
592 core.vdds_dsi_reg = NULL;
595 if (core.vdds_sdi_reg != NULL) {
596 regulator_put(core.vdds_sdi_reg);
597 core.vdds_sdi_reg = NULL;
600 if (core.vdda_dac_reg != NULL) {
601 regulator_put(core.vdda_dac_reg);
602 core.vdda_dac_reg = NULL;
605 platform_driver_unregister(&omap_dss_driver);
607 omap_dss_bus_unregister();
610 module_init(omap_dss_init);
611 module_exit(omap_dss_exit);
613 static int __init omap_dss_init(void)
615 return omap_dss_bus_register();
618 static int __init omap_dss_init2(void)
620 return platform_driver_register(&omap_dss_driver);
623 core_initcall(omap_dss_init);
624 device_initcall(omap_dss_init2);
627 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
628 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
629 MODULE_LICENSE("GPL v2");