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 <video/omapdss.h>
39 #include "dss_features.h"
42 struct platform_device *pdev;
44 struct regulator *vdds_dsi_reg;
45 struct regulator *vdds_sdi_reg;
47 const char *default_display_name;
50 static char *def_disp_name;
51 module_param_named(def_disp, def_disp_name, charp, 0);
52 MODULE_PARM_DESC(def_disp, "default display name");
56 module_param_named(debug, dss_debug, bool, 0644);
61 struct regulator *dss_get_vdds_dsi(void)
63 struct regulator *reg;
65 if (core.vdds_dsi_reg != NULL)
66 return core.vdds_dsi_reg;
68 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
70 core.vdds_dsi_reg = reg;
75 struct regulator *dss_get_vdds_sdi(void)
77 struct regulator *reg;
79 if (core.vdds_sdi_reg != NULL)
80 return core.vdds_sdi_reg;
82 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
84 core.vdds_sdi_reg = reg;
89 int dss_get_ctx_loss_count(struct device *dev)
91 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
94 if (!board_data->get_context_loss_count)
97 cnt = board_data->get_context_loss_count(dev);
99 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
104 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
106 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
108 if (!board_data->dsi_enable_pads)
111 return board_data->dsi_enable_pads(dsi_id, lane_mask);
114 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
116 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
118 if (!board_data->dsi_enable_pads)
121 return board_data->dsi_disable_pads(dsi_id, lane_mask);
124 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
126 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
128 if (pdata->set_min_bus_tput)
129 return pdata->set_min_bus_tput(dev, tput);
134 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
135 static int dss_debug_show(struct seq_file *s, void *unused)
137 void (*func)(struct seq_file *) = s->private;
142 static int dss_debug_open(struct inode *inode, struct file *file)
144 return single_open(file, dss_debug_show, inode->i_private);
147 static const struct file_operations dss_debug_fops = {
148 .open = dss_debug_open,
151 .release = single_release,
154 static struct dentry *dss_debugfs_dir;
156 static int dss_initialize_debugfs(void)
158 dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
159 if (IS_ERR(dss_debugfs_dir)) {
160 int err = PTR_ERR(dss_debugfs_dir);
161 dss_debugfs_dir = NULL;
165 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
166 &dss_debug_dump_clocks, &dss_debug_fops);
171 static void dss_uninitialize_debugfs(void)
174 debugfs_remove_recursive(dss_debugfs_dir);
177 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
181 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
182 write, &dss_debug_fops);
189 #else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
190 static inline int dss_initialize_debugfs(void)
194 static inline void dss_uninitialize_debugfs(void)
197 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
201 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
203 /* PLATFORM DEVICE */
204 static int __init omap_dss_probe(struct platform_device *pdev)
206 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
215 dss_init_overlay_managers(pdev);
216 dss_init_overlays(pdev);
218 r = dss_initialize_debugfs();
223 core.default_display_name = def_disp_name;
224 else if (pdata->default_device)
225 core.default_display_name = pdata->default_device->name;
234 static int omap_dss_remove(struct platform_device *pdev)
236 dss_uninitialize_debugfs();
238 dss_uninit_overlays(pdev);
239 dss_uninit_overlay_managers(pdev);
244 static void omap_dss_shutdown(struct platform_device *pdev)
246 DSSDBG("shutdown\n");
247 dss_disable_all_devices();
250 static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
252 DSSDBG("suspend %d\n", state.event);
254 return dss_suspend_all_devices();
257 static int omap_dss_resume(struct platform_device *pdev)
261 return dss_resume_all_devices();
264 static struct platform_driver omap_dss_driver = {
265 .remove = omap_dss_remove,
266 .shutdown = omap_dss_shutdown,
267 .suspend = omap_dss_suspend,
268 .resume = omap_dss_resume,
271 .owner = THIS_MODULE,
276 static int dss_bus_match(struct device *dev, struct device_driver *driver)
278 struct omap_dss_device *dssdev = to_dss_device(dev);
280 DSSDBG("bus_match. dev %s/%s, drv %s\n",
281 dev_name(dev), dssdev->driver_name, driver->name);
283 return strcmp(dssdev->driver_name, driver->name) == 0;
286 static ssize_t device_name_show(struct device *dev,
287 struct device_attribute *attr, char *buf)
289 struct omap_dss_device *dssdev = to_dss_device(dev);
290 return snprintf(buf, PAGE_SIZE, "%s\n",
295 static struct device_attribute default_dev_attrs[] = {
296 __ATTR(name, S_IRUGO, device_name_show, NULL),
300 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
302 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
303 return snprintf(buf, PAGE_SIZE, "%s\n",
304 dssdrv->driver.name ?
305 dssdrv->driver.name : "");
307 static struct driver_attribute default_drv_attrs[] = {
308 __ATTR(name, S_IRUGO, driver_name_show, NULL),
312 static struct bus_type dss_bus_type = {
314 .match = dss_bus_match,
315 .dev_attrs = default_dev_attrs,
316 .drv_attrs = default_drv_attrs,
319 static void dss_bus_release(struct device *dev)
321 DSSDBG("bus_release\n");
324 static struct device dss_bus = {
325 .release = dss_bus_release,
328 struct bus_type *dss_get_bus(void)
330 return &dss_bus_type;
334 static int dss_driver_probe(struct device *dev)
337 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
338 struct omap_dss_device *dssdev = to_dss_device(dev);
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 = core.default_display_name &&
348 strcmp(core.default_display_name, dssdev->name) == 0;
349 dss_recheck_connections(dssdev, force);
351 r = dssdrv->probe(dssdev);
354 DSSERR("driver probe failed: %d\n", r);
355 dss_uninit_device(core.pdev, dssdev);
359 DSSDBG("probe done for device %s\n", dev_name(dev));
361 dssdev->driver = dssdrv;
366 static int dss_driver_remove(struct device *dev)
368 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
369 struct omap_dss_device *dssdev = to_dss_device(dev);
371 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
372 dssdev->driver_name);
374 dssdrv->remove(dssdev);
376 dss_uninit_device(core.pdev, dssdev);
378 dssdev->driver = NULL;
383 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
385 dssdriver->driver.bus = &dss_bus_type;
386 dssdriver->driver.probe = dss_driver_probe;
387 dssdriver->driver.remove = dss_driver_remove;
389 if (dssdriver->get_resolution == NULL)
390 dssdriver->get_resolution = omapdss_default_get_resolution;
391 if (dssdriver->get_recommended_bpp == NULL)
392 dssdriver->get_recommended_bpp =
393 omapdss_default_get_recommended_bpp;
394 if (dssdriver->get_timings == NULL)
395 dssdriver->get_timings = omapdss_default_get_timings;
397 return driver_register(&dssdriver->driver);
399 EXPORT_SYMBOL(omap_dss_register_driver);
401 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
403 driver_unregister(&dssdriver->driver);
405 EXPORT_SYMBOL(omap_dss_unregister_driver);
408 static void reset_device(struct device *dev, int check)
410 u8 *dev_p = (u8 *)dev;
411 u8 *dev_end = dev_p + sizeof(*dev);
414 saved_pdata = dev->platform_data;
417 * Check if there is any other setting than platform_data
418 * in struct device; warn that these will be reset by our
421 dev->platform_data = NULL;
422 while (dev_p < dev_end) {
424 WARN("%s: struct device fields will be "
432 memset(dev, 0, sizeof(*dev));
433 dev->platform_data = saved_pdata;
437 static void omap_dss_dev_release(struct device *dev)
439 reset_device(dev, 0);
442 int omap_dss_register_device(struct omap_dss_device *dssdev,
443 struct device *parent, int disp_num)
445 WARN_ON(!dssdev->driver_name);
447 reset_device(&dssdev->dev, 1);
448 dssdev->dev.bus = &dss_bus_type;
449 dssdev->dev.parent = parent;
450 dssdev->dev.release = omap_dss_dev_release;
451 dev_set_name(&dssdev->dev, "display%d", disp_num);
452 return device_register(&dssdev->dev);
455 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
457 device_unregister(&dssdev->dev);
460 static int dss_unregister_dss_dev(struct device *dev, void *data)
462 struct omap_dss_device *dssdev = to_dss_device(dev);
463 omap_dss_unregister_device(dssdev);
467 void omap_dss_unregister_child_devices(struct device *parent)
469 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
473 static int __init omap_dss_bus_register(void)
477 r = bus_register(&dss_bus_type);
479 DSSERR("bus register failed\n");
483 dev_set_name(&dss_bus, "omapdss");
484 r = device_register(&dss_bus);
486 DSSERR("bus driver register failed\n");
487 bus_unregister(&dss_bus_type);
495 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
496 #ifdef CONFIG_OMAP2_DSS_DPI
497 dpi_init_platform_driver,
499 #ifdef CONFIG_OMAP2_DSS_SDI
500 sdi_init_platform_driver,
502 #ifdef CONFIG_OMAP2_DSS_RFBI
503 rfbi_init_platform_driver,
505 #ifdef CONFIG_OMAP2_DSS_VENC
506 venc_init_platform_driver,
508 #ifdef CONFIG_OMAP2_DSS_DSI
509 dsi_init_platform_driver,
511 #ifdef CONFIG_OMAP4_DSS_HDMI
512 hdmi_init_platform_driver,
516 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
517 #ifdef CONFIG_OMAP2_DSS_DPI
518 dpi_uninit_platform_driver,
520 #ifdef CONFIG_OMAP2_DSS_SDI
521 sdi_uninit_platform_driver,
523 #ifdef CONFIG_OMAP2_DSS_RFBI
524 rfbi_uninit_platform_driver,
526 #ifdef CONFIG_OMAP2_DSS_VENC
527 venc_uninit_platform_driver,
529 #ifdef CONFIG_OMAP2_DSS_DSI
530 dsi_uninit_platform_driver,
532 #ifdef CONFIG_OMAP4_DSS_HDMI
533 hdmi_uninit_platform_driver,
537 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
539 static int __init omap_dss_register_drivers(void)
544 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
548 r = dss_init_platform_driver();
550 DSSERR("Failed to initialize DSS platform driver\n");
554 r = dispc_init_platform_driver();
556 DSSERR("Failed to initialize dispc platform driver\n");
561 * It's ok if the output-driver register fails. It happens, for example,
562 * when there is no output-device (e.g. SDI for OMAP4).
564 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
565 r = dss_output_drv_reg_funcs[i]();
567 dss_output_drv_loaded[i] = true;
573 dss_uninit_platform_driver();
575 platform_driver_unregister(&omap_dss_driver);
580 static void __exit omap_dss_unregister_drivers(void)
584 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
585 if (dss_output_drv_loaded[i])
586 dss_output_drv_unreg_funcs[i]();
589 dispc_uninit_platform_driver();
590 dss_uninit_platform_driver();
592 platform_driver_unregister(&omap_dss_driver);
595 #ifdef CONFIG_OMAP2_DSS_MODULE
596 static void omap_dss_bus_unregister(void)
598 device_unregister(&dss_bus);
600 bus_unregister(&dss_bus_type);
603 static int __init omap_dss_init(void)
607 r = omap_dss_bus_register();
611 r = omap_dss_register_drivers();
613 omap_dss_bus_unregister();
620 static void __exit omap_dss_exit(void)
622 if (core.vdds_dsi_reg != NULL) {
623 regulator_put(core.vdds_dsi_reg);
624 core.vdds_dsi_reg = NULL;
627 if (core.vdds_sdi_reg != NULL) {
628 regulator_put(core.vdds_sdi_reg);
629 core.vdds_sdi_reg = NULL;
632 omap_dss_unregister_drivers();
634 omap_dss_bus_unregister();
637 module_init(omap_dss_init);
638 module_exit(omap_dss_exit);
640 static int __init omap_dss_init(void)
642 return omap_dss_bus_register();
645 static int __init omap_dss_init2(void)
647 return omap_dss_register_drivers();
650 core_initcall(omap_dss_init);
651 device_initcall(omap_dss_init2);
654 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
655 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
656 MODULE_LICENSE("GPL v2");