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);
210 case PM_SUSPEND_PREPARE:
211 DSSDBG("suspending displays\n");
212 return dss_suspend_all_devices();
214 case PM_POST_SUSPEND:
215 DSSDBG("resuming displays\n");
216 return dss_resume_all_devices();
223 static struct notifier_block omap_dss_pm_notif_block = {
224 .notifier_call = omap_dss_pm_notif,
227 static int __init omap_dss_probe(struct platform_device *pdev)
229 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
238 dss_init_overlay_managers(pdev);
239 dss_init_overlays(pdev);
241 r = dss_initialize_debugfs();
246 core.default_display_name = def_disp_name;
247 else if (pdata->default_device)
248 core.default_display_name = pdata->default_device->name;
250 register_pm_notifier(&omap_dss_pm_notif_block);
259 static int omap_dss_remove(struct platform_device *pdev)
261 unregister_pm_notifier(&omap_dss_pm_notif_block);
263 dss_uninitialize_debugfs();
265 dss_uninit_overlays(pdev);
266 dss_uninit_overlay_managers(pdev);
271 static void omap_dss_shutdown(struct platform_device *pdev)
273 DSSDBG("shutdown\n");
274 dss_disable_all_devices();
277 static struct platform_driver omap_dss_driver = {
278 .remove = omap_dss_remove,
279 .shutdown = omap_dss_shutdown,
282 .owner = THIS_MODULE,
287 static int dss_bus_match(struct device *dev, struct device_driver *driver)
289 struct omap_dss_device *dssdev = to_dss_device(dev);
291 DSSDBG("bus_match. dev %s/%s, drv %s\n",
292 dev_name(dev), dssdev->driver_name, driver->name);
294 return strcmp(dssdev->driver_name, driver->name) == 0;
297 static ssize_t device_name_show(struct device *dev,
298 struct device_attribute *attr, char *buf)
300 struct omap_dss_device *dssdev = to_dss_device(dev);
301 return snprintf(buf, PAGE_SIZE, "%s\n",
306 static struct device_attribute default_dev_attrs[] = {
307 __ATTR(name, S_IRUGO, device_name_show, NULL),
311 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
313 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
314 return snprintf(buf, PAGE_SIZE, "%s\n",
315 dssdrv->driver.name ?
316 dssdrv->driver.name : "");
318 static struct driver_attribute default_drv_attrs[] = {
319 __ATTR(name, S_IRUGO, driver_name_show, NULL),
323 static struct bus_type dss_bus_type = {
325 .match = dss_bus_match,
326 .dev_attrs = default_dev_attrs,
327 .drv_attrs = default_drv_attrs,
330 static void dss_bus_release(struct device *dev)
332 DSSDBG("bus_release\n");
335 static struct device dss_bus = {
336 .release = dss_bus_release,
339 struct bus_type *dss_get_bus(void)
341 return &dss_bus_type;
345 static int dss_driver_probe(struct device *dev)
348 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
349 struct omap_dss_device *dssdev = to_dss_device(dev);
352 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
353 dev_name(dev), dssdev->driver_name,
354 dssdrv->driver.name);
356 dss_init_device(core.pdev, dssdev);
358 force = core.default_display_name &&
359 strcmp(core.default_display_name, dssdev->name) == 0;
360 dss_recheck_connections(dssdev, force);
362 r = dssdrv->probe(dssdev);
365 DSSERR("driver probe failed: %d\n", r);
366 dss_uninit_device(core.pdev, dssdev);
370 DSSDBG("probe done for device %s\n", dev_name(dev));
372 dssdev->driver = dssdrv;
377 static int dss_driver_remove(struct device *dev)
379 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
380 struct omap_dss_device *dssdev = to_dss_device(dev);
382 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
383 dssdev->driver_name);
385 dssdrv->remove(dssdev);
387 dss_uninit_device(core.pdev, dssdev);
389 dssdev->driver = NULL;
394 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
396 dssdriver->driver.bus = &dss_bus_type;
397 dssdriver->driver.probe = dss_driver_probe;
398 dssdriver->driver.remove = dss_driver_remove;
400 if (dssdriver->get_resolution == NULL)
401 dssdriver->get_resolution = omapdss_default_get_resolution;
402 if (dssdriver->get_recommended_bpp == NULL)
403 dssdriver->get_recommended_bpp =
404 omapdss_default_get_recommended_bpp;
405 if (dssdriver->get_timings == NULL)
406 dssdriver->get_timings = omapdss_default_get_timings;
408 return driver_register(&dssdriver->driver);
410 EXPORT_SYMBOL(omap_dss_register_driver);
412 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
414 driver_unregister(&dssdriver->driver);
416 EXPORT_SYMBOL(omap_dss_unregister_driver);
419 static void reset_device(struct device *dev, int check)
421 u8 *dev_p = (u8 *)dev;
422 u8 *dev_end = dev_p + sizeof(*dev);
425 saved_pdata = dev->platform_data;
428 * Check if there is any other setting than platform_data
429 * in struct device; warn that these will be reset by our
432 dev->platform_data = NULL;
433 while (dev_p < dev_end) {
435 WARN("%s: struct device fields will be "
443 memset(dev, 0, sizeof(*dev));
444 dev->platform_data = saved_pdata;
448 static void omap_dss_dev_release(struct device *dev)
450 reset_device(dev, 0);
453 int omap_dss_register_device(struct omap_dss_device *dssdev,
454 struct device *parent, int disp_num)
456 WARN_ON(!dssdev->driver_name);
458 reset_device(&dssdev->dev, 1);
459 dssdev->dev.bus = &dss_bus_type;
460 dssdev->dev.parent = parent;
461 dssdev->dev.release = omap_dss_dev_release;
462 dev_set_name(&dssdev->dev, "display%d", disp_num);
463 return device_register(&dssdev->dev);
466 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
468 device_unregister(&dssdev->dev);
471 static int dss_unregister_dss_dev(struct device *dev, void *data)
473 struct omap_dss_device *dssdev = to_dss_device(dev);
474 omap_dss_unregister_device(dssdev);
478 void omap_dss_unregister_child_devices(struct device *parent)
480 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
484 static int __init omap_dss_bus_register(void)
488 r = bus_register(&dss_bus_type);
490 DSSERR("bus register failed\n");
494 dev_set_name(&dss_bus, "omapdss");
495 r = device_register(&dss_bus);
497 DSSERR("bus driver register failed\n");
498 bus_unregister(&dss_bus_type);
506 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
507 #ifdef CONFIG_OMAP2_DSS_DPI
508 dpi_init_platform_driver,
510 #ifdef CONFIG_OMAP2_DSS_SDI
511 sdi_init_platform_driver,
513 #ifdef CONFIG_OMAP2_DSS_RFBI
514 rfbi_init_platform_driver,
516 #ifdef CONFIG_OMAP2_DSS_VENC
517 venc_init_platform_driver,
519 #ifdef CONFIG_OMAP2_DSS_DSI
520 dsi_init_platform_driver,
522 #ifdef CONFIG_OMAP4_DSS_HDMI
523 hdmi_init_platform_driver,
527 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
528 #ifdef CONFIG_OMAP2_DSS_DPI
529 dpi_uninit_platform_driver,
531 #ifdef CONFIG_OMAP2_DSS_SDI
532 sdi_uninit_platform_driver,
534 #ifdef CONFIG_OMAP2_DSS_RFBI
535 rfbi_uninit_platform_driver,
537 #ifdef CONFIG_OMAP2_DSS_VENC
538 venc_uninit_platform_driver,
540 #ifdef CONFIG_OMAP2_DSS_DSI
541 dsi_uninit_platform_driver,
543 #ifdef CONFIG_OMAP4_DSS_HDMI
544 hdmi_uninit_platform_driver,
548 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
550 static int __init omap_dss_register_drivers(void)
555 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
559 r = dss_init_platform_driver();
561 DSSERR("Failed to initialize DSS platform driver\n");
565 r = dispc_init_platform_driver();
567 DSSERR("Failed to initialize dispc platform driver\n");
572 * It's ok if the output-driver register fails. It happens, for example,
573 * when there is no output-device (e.g. SDI for OMAP4).
575 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
576 r = dss_output_drv_reg_funcs[i]();
578 dss_output_drv_loaded[i] = true;
584 dss_uninit_platform_driver();
586 platform_driver_unregister(&omap_dss_driver);
591 static void __exit omap_dss_unregister_drivers(void)
595 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
596 if (dss_output_drv_loaded[i])
597 dss_output_drv_unreg_funcs[i]();
600 dispc_uninit_platform_driver();
601 dss_uninit_platform_driver();
603 platform_driver_unregister(&omap_dss_driver);
606 #ifdef CONFIG_OMAP2_DSS_MODULE
607 static void omap_dss_bus_unregister(void)
609 device_unregister(&dss_bus);
611 bus_unregister(&dss_bus_type);
614 static int __init omap_dss_init(void)
618 r = omap_dss_bus_register();
622 r = omap_dss_register_drivers();
624 omap_dss_bus_unregister();
631 static void __exit omap_dss_exit(void)
633 if (core.vdds_dsi_reg != NULL) {
634 regulator_put(core.vdds_dsi_reg);
635 core.vdds_dsi_reg = NULL;
638 if (core.vdds_sdi_reg != NULL) {
639 regulator_put(core.vdds_sdi_reg);
640 core.vdds_sdi_reg = NULL;
643 omap_dss_unregister_drivers();
645 omap_dss_bus_unregister();
648 module_init(omap_dss_init);
649 module_exit(omap_dss_exit);
651 static int __init omap_dss_init(void)
653 return omap_dss_bus_register();
656 static int __init omap_dss_init2(void)
658 return omap_dss_register_drivers();
661 core_initcall(omap_dss_init);
662 device_initcall(omap_dss_init2);
665 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
666 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
667 MODULE_LICENSE("GPL v2");