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;
48 const char *default_display_name;
51 static char *def_disp_name;
52 module_param_named(def_disp, def_disp_name, charp, 0);
53 MODULE_PARM_DESC(def_disp, "default display name");
57 module_param_named(debug, dss_debug, bool, 0644);
62 struct regulator *dss_get_vdds_dsi(void)
64 struct regulator *reg;
66 if (core.vdds_dsi_reg != NULL)
67 return core.vdds_dsi_reg;
69 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
71 core.vdds_dsi_reg = reg;
76 struct regulator *dss_get_vdds_sdi(void)
78 struct regulator *reg;
80 if (core.vdds_sdi_reg != NULL)
81 return core.vdds_sdi_reg;
83 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
85 core.vdds_sdi_reg = reg;
90 int dss_get_ctx_loss_count(struct device *dev)
92 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
95 if (!board_data->get_context_loss_count)
98 cnt = board_data->get_context_loss_count(dev);
100 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
105 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
107 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
109 if (!board_data->dsi_enable_pads)
112 return board_data->dsi_enable_pads(dsi_id, lane_mask);
115 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
117 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
119 if (!board_data->dsi_enable_pads)
122 return board_data->dsi_disable_pads(dsi_id, lane_mask);
125 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
127 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
129 if (pdata->set_min_bus_tput)
130 return pdata->set_min_bus_tput(dev, tput);
135 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
136 static int dss_debug_show(struct seq_file *s, void *unused)
138 void (*func)(struct seq_file *) = s->private;
143 static int dss_debug_open(struct inode *inode, struct file *file)
145 return single_open(file, dss_debug_show, inode->i_private);
148 static const struct file_operations dss_debug_fops = {
149 .open = dss_debug_open,
152 .release = single_release,
155 static struct dentry *dss_debugfs_dir;
157 static int dss_initialize_debugfs(void)
159 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
160 if (IS_ERR(dss_debugfs_dir)) {
161 int err = PTR_ERR(dss_debugfs_dir);
162 dss_debugfs_dir = NULL;
166 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
167 &dss_debug_dump_clocks, &dss_debug_fops);
172 static void dss_uninitialize_debugfs(void)
175 debugfs_remove_recursive(dss_debugfs_dir);
178 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
182 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
183 write, &dss_debug_fops);
190 #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
191 static inline int dss_initialize_debugfs(void)
195 static inline void dss_uninitialize_debugfs(void)
198 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
202 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
204 /* PLATFORM DEVICE */
205 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
207 DSSDBG("pm notif %lu\n", v);
211 case PM_SUSPEND_PREPARE:
212 DSSDBG("suspending displays\n");
213 return dss_suspend_all_devices();
215 case PM_POST_SUSPEND:
216 DSSDBG("resuming displays\n");
217 return dss_resume_all_devices();
224 static struct notifier_block omap_dss_pm_notif_block =
226 .notifier_call = omap_dss_pm_notif,
229 static int __init omap_dss_probe(struct platform_device *pdev)
231 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
240 dss_init_overlay_managers(pdev);
241 dss_init_overlays(pdev);
243 r = dss_initialize_debugfs();
248 core.default_display_name = def_disp_name;
249 else if (pdata->default_device)
250 core.default_display_name = pdata->default_device->name;
252 register_pm_notifier(&omap_dss_pm_notif_block);
261 static int omap_dss_remove(struct platform_device *pdev)
263 unregister_pm_notifier(&omap_dss_pm_notif_block);
265 dss_uninitialize_debugfs();
267 dss_uninit_overlays(pdev);
268 dss_uninit_overlay_managers(pdev);
273 static void omap_dss_shutdown(struct platform_device *pdev)
275 DSSDBG("shutdown\n");
276 dss_disable_all_devices();
279 static struct platform_driver omap_dss_driver = {
280 .remove = omap_dss_remove,
281 .shutdown = omap_dss_shutdown,
284 .owner = THIS_MODULE,
289 static int dss_bus_match(struct device *dev, struct device_driver *driver)
291 struct omap_dss_device *dssdev = to_dss_device(dev);
293 DSSDBG("bus_match. dev %s/%s, drv %s\n",
294 dev_name(dev), dssdev->driver_name, driver->name);
296 return strcmp(dssdev->driver_name, driver->name) == 0;
299 static ssize_t device_name_show(struct device *dev,
300 struct device_attribute *attr, char *buf)
302 struct omap_dss_device *dssdev = to_dss_device(dev);
303 return snprintf(buf, PAGE_SIZE, "%s\n",
308 static struct device_attribute default_dev_attrs[] = {
309 __ATTR(name, S_IRUGO, device_name_show, NULL),
313 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
315 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
316 return snprintf(buf, PAGE_SIZE, "%s\n",
317 dssdrv->driver.name ?
318 dssdrv->driver.name : "");
320 static struct driver_attribute default_drv_attrs[] = {
321 __ATTR(name, S_IRUGO, driver_name_show, NULL),
325 static struct bus_type dss_bus_type = {
327 .match = dss_bus_match,
328 .dev_attrs = default_dev_attrs,
329 .drv_attrs = default_drv_attrs,
332 static void dss_bus_release(struct device *dev)
334 DSSDBG("bus_release\n");
337 static struct device dss_bus = {
338 .release = dss_bus_release,
341 struct bus_type *dss_get_bus(void)
343 return &dss_bus_type;
347 static int dss_driver_probe(struct device *dev)
350 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
351 struct omap_dss_device *dssdev = to_dss_device(dev);
354 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
355 dev_name(dev), dssdev->driver_name,
356 dssdrv->driver.name);
358 dss_init_device(core.pdev, dssdev);
360 force = core.default_display_name &&
361 strcmp(core.default_display_name, dssdev->name) == 0;
362 dss_recheck_connections(dssdev, force);
364 r = dssdrv->probe(dssdev);
367 DSSERR("driver probe failed: %d\n", r);
368 dss_uninit_device(core.pdev, dssdev);
372 DSSDBG("probe done for device %s\n", dev_name(dev));
374 dssdev->driver = dssdrv;
379 static int dss_driver_remove(struct device *dev)
381 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
382 struct omap_dss_device *dssdev = to_dss_device(dev);
384 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
385 dssdev->driver_name);
387 dssdrv->remove(dssdev);
389 dss_uninit_device(core.pdev, dssdev);
391 dssdev->driver = NULL;
396 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
398 dssdriver->driver.bus = &dss_bus_type;
399 dssdriver->driver.probe = dss_driver_probe;
400 dssdriver->driver.remove = dss_driver_remove;
402 if (dssdriver->get_resolution == NULL)
403 dssdriver->get_resolution = omapdss_default_get_resolution;
404 if (dssdriver->get_recommended_bpp == NULL)
405 dssdriver->get_recommended_bpp =
406 omapdss_default_get_recommended_bpp;
407 if (dssdriver->get_timings == NULL)
408 dssdriver->get_timings = omapdss_default_get_timings;
410 return driver_register(&dssdriver->driver);
412 EXPORT_SYMBOL(omap_dss_register_driver);
414 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
416 driver_unregister(&dssdriver->driver);
418 EXPORT_SYMBOL(omap_dss_unregister_driver);
421 static void reset_device(struct device *dev, int check)
423 u8 *dev_p = (u8 *)dev;
424 u8 *dev_end = dev_p + sizeof(*dev);
427 saved_pdata = dev->platform_data;
430 * Check if there is any other setting than platform_data
431 * in struct device; warn that these will be reset by our
434 dev->platform_data = NULL;
435 while (dev_p < dev_end) {
437 WARN("%s: struct device fields will be "
445 memset(dev, 0, sizeof(*dev));
446 dev->platform_data = saved_pdata;
450 static void omap_dss_dev_release(struct device *dev)
452 reset_device(dev, 0);
455 int omap_dss_register_device(struct omap_dss_device *dssdev,
456 struct device *parent, int disp_num)
458 WARN_ON(!dssdev->driver_name);
460 reset_device(&dssdev->dev, 1);
461 dssdev->dev.bus = &dss_bus_type;
462 dssdev->dev.parent = parent;
463 dssdev->dev.release = omap_dss_dev_release;
464 dev_set_name(&dssdev->dev, "display%d", disp_num);
465 return device_register(&dssdev->dev);
468 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
470 device_unregister(&dssdev->dev);
473 static int dss_unregister_dss_dev(struct device *dev, void *data)
475 struct omap_dss_device *dssdev = to_dss_device(dev);
476 omap_dss_unregister_device(dssdev);
480 void omap_dss_unregister_child_devices(struct device *parent)
482 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
486 static int __init omap_dss_bus_register(void)
490 r = bus_register(&dss_bus_type);
492 DSSERR("bus register failed\n");
496 dev_set_name(&dss_bus, "omapdss");
497 r = device_register(&dss_bus);
499 DSSERR("bus driver register failed\n");
500 bus_unregister(&dss_bus_type);
508 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
509 #ifdef CONFIG_OMAP2_DSS_DPI
510 dpi_init_platform_driver,
512 #ifdef CONFIG_OMAP2_DSS_SDI
513 sdi_init_platform_driver,
515 #ifdef CONFIG_OMAP2_DSS_RFBI
516 rfbi_init_platform_driver,
518 #ifdef CONFIG_OMAP2_DSS_VENC
519 venc_init_platform_driver,
521 #ifdef CONFIG_OMAP2_DSS_DSI
522 dsi_init_platform_driver,
524 #ifdef CONFIG_OMAP4_DSS_HDMI
525 hdmi_init_platform_driver,
529 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
530 #ifdef CONFIG_OMAP2_DSS_DPI
531 dpi_uninit_platform_driver,
533 #ifdef CONFIG_OMAP2_DSS_SDI
534 sdi_uninit_platform_driver,
536 #ifdef CONFIG_OMAP2_DSS_RFBI
537 rfbi_uninit_platform_driver,
539 #ifdef CONFIG_OMAP2_DSS_VENC
540 venc_uninit_platform_driver,
542 #ifdef CONFIG_OMAP2_DSS_DSI
543 dsi_uninit_platform_driver,
545 #ifdef CONFIG_OMAP4_DSS_HDMI
546 hdmi_uninit_platform_driver,
550 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
552 static int __init omap_dss_register_drivers(void)
557 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
561 r = dss_init_platform_driver();
563 DSSERR("Failed to initialize DSS platform driver\n");
567 r = dispc_init_platform_driver();
569 DSSERR("Failed to initialize dispc platform driver\n");
574 * It's ok if the output-driver register fails. It happens, for example,
575 * when there is no output-device (e.g. SDI for OMAP4).
577 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
578 r = dss_output_drv_reg_funcs[i]();
580 dss_output_drv_loaded[i] = true;
586 dss_uninit_platform_driver();
588 platform_driver_unregister(&omap_dss_driver);
593 static void __exit omap_dss_unregister_drivers(void)
597 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
598 if (dss_output_drv_loaded[i])
599 dss_output_drv_unreg_funcs[i]();
602 dispc_uninit_platform_driver();
603 dss_uninit_platform_driver();
605 platform_driver_unregister(&omap_dss_driver);
608 #ifdef CONFIG_OMAP2_DSS_MODULE
609 static void omap_dss_bus_unregister(void)
611 device_unregister(&dss_bus);
613 bus_unregister(&dss_bus_type);
616 static int __init omap_dss_init(void)
620 r = omap_dss_bus_register();
624 r = omap_dss_register_drivers();
626 omap_dss_bus_unregister();
633 static void __exit omap_dss_exit(void)
635 if (core.vdds_dsi_reg != NULL) {
636 regulator_put(core.vdds_dsi_reg);
637 core.vdds_dsi_reg = NULL;
640 if (core.vdds_sdi_reg != NULL) {
641 regulator_put(core.vdds_sdi_reg);
642 core.vdds_sdi_reg = NULL;
645 omap_dss_unregister_drivers();
647 omap_dss_bus_unregister();
650 module_init(omap_dss_init);
651 module_exit(omap_dss_exit);
653 static int __init omap_dss_init(void)
655 return omap_dss_bus_register();
658 static int __init omap_dss_init2(void)
660 return omap_dss_register_drivers();
663 core_initcall(omap_dss_init);
664 device_initcall(omap_dss_init2);
667 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
668 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
669 MODULE_LICENSE("GPL v2");