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 static inline int dss_debugfs_create_file(const char *name,
198 void (*write)(struct seq_file *))
202 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
204 /* PLATFORM DEVICE */
205 static int __init omap_dss_probe(struct platform_device *pdev)
207 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
216 dss_init_overlay_managers(pdev);
217 dss_init_overlays(pdev);
219 r = dss_initialize_debugfs();
224 core.default_display_name = def_disp_name;
225 else if (pdata->default_device)
226 core.default_display_name = pdata->default_device->name;
235 static int omap_dss_remove(struct platform_device *pdev)
237 dss_uninitialize_debugfs();
239 dss_uninit_overlays(pdev);
240 dss_uninit_overlay_managers(pdev);
245 static void omap_dss_shutdown(struct platform_device *pdev)
247 DSSDBG("shutdown\n");
248 dss_disable_all_devices();
251 static int omap_dss_suspend(struct platform_device *pdev, pm_message_t state)
253 DSSDBG("suspend %d\n", state.event);
255 return dss_suspend_all_devices();
258 static int omap_dss_resume(struct platform_device *pdev)
262 return dss_resume_all_devices();
265 static struct platform_driver omap_dss_driver = {
266 .remove = omap_dss_remove,
267 .shutdown = omap_dss_shutdown,
268 .suspend = omap_dss_suspend,
269 .resume = omap_dss_resume,
272 .owner = THIS_MODULE,
277 static int dss_bus_match(struct device *dev, struct device_driver *driver)
279 struct omap_dss_device *dssdev = to_dss_device(dev);
281 DSSDBG("bus_match. dev %s/%s, drv %s\n",
282 dev_name(dev), dssdev->driver_name, driver->name);
284 return strcmp(dssdev->driver_name, driver->name) == 0;
287 static ssize_t device_name_show(struct device *dev,
288 struct device_attribute *attr, char *buf)
290 struct omap_dss_device *dssdev = to_dss_device(dev);
291 return snprintf(buf, PAGE_SIZE, "%s\n",
296 static struct device_attribute default_dev_attrs[] = {
297 __ATTR(name, S_IRUGO, device_name_show, NULL),
301 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
303 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
304 return snprintf(buf, PAGE_SIZE, "%s\n",
305 dssdrv->driver.name ?
306 dssdrv->driver.name : "");
308 static struct driver_attribute default_drv_attrs[] = {
309 __ATTR(name, S_IRUGO, driver_name_show, NULL),
313 static struct bus_type dss_bus_type = {
315 .match = dss_bus_match,
316 .dev_attrs = default_dev_attrs,
317 .drv_attrs = default_drv_attrs,
320 static void dss_bus_release(struct device *dev)
322 DSSDBG("bus_release\n");
325 static struct device dss_bus = {
326 .release = dss_bus_release,
329 struct bus_type *dss_get_bus(void)
331 return &dss_bus_type;
335 static int dss_driver_probe(struct device *dev)
338 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
339 struct omap_dss_device *dssdev = to_dss_device(dev);
342 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
343 dev_name(dev), dssdev->driver_name,
344 dssdrv->driver.name);
346 dss_init_device(core.pdev, dssdev);
348 force = core.default_display_name &&
349 strcmp(core.default_display_name, dssdev->name) == 0;
350 dss_recheck_connections(dssdev, force);
352 r = dssdrv->probe(dssdev);
355 DSSERR("driver probe failed: %d\n", r);
356 dss_uninit_device(core.pdev, dssdev);
360 DSSDBG("probe done for device %s\n", dev_name(dev));
362 dssdev->driver = dssdrv;
367 static int dss_driver_remove(struct device *dev)
369 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
370 struct omap_dss_device *dssdev = to_dss_device(dev);
372 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
373 dssdev->driver_name);
375 dssdrv->remove(dssdev);
377 dss_uninit_device(core.pdev, dssdev);
379 dssdev->driver = NULL;
384 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
386 dssdriver->driver.bus = &dss_bus_type;
387 dssdriver->driver.probe = dss_driver_probe;
388 dssdriver->driver.remove = dss_driver_remove;
390 if (dssdriver->get_resolution == NULL)
391 dssdriver->get_resolution = omapdss_default_get_resolution;
392 if (dssdriver->get_recommended_bpp == NULL)
393 dssdriver->get_recommended_bpp =
394 omapdss_default_get_recommended_bpp;
395 if (dssdriver->get_timings == NULL)
396 dssdriver->get_timings = omapdss_default_get_timings;
398 return driver_register(&dssdriver->driver);
400 EXPORT_SYMBOL(omap_dss_register_driver);
402 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
404 driver_unregister(&dssdriver->driver);
406 EXPORT_SYMBOL(omap_dss_unregister_driver);
409 static void reset_device(struct device *dev, int check)
411 u8 *dev_p = (u8 *)dev;
412 u8 *dev_end = dev_p + sizeof(*dev);
415 saved_pdata = dev->platform_data;
418 * Check if there is any other setting than platform_data
419 * in struct device; warn that these will be reset by our
422 dev->platform_data = NULL;
423 while (dev_p < dev_end) {
425 WARN("%s: struct device fields will be "
433 memset(dev, 0, sizeof(*dev));
434 dev->platform_data = saved_pdata;
438 static void omap_dss_dev_release(struct device *dev)
440 reset_device(dev, 0);
443 int omap_dss_register_device(struct omap_dss_device *dssdev,
444 struct device *parent, int disp_num)
446 WARN_ON(!dssdev->driver_name);
448 reset_device(&dssdev->dev, 1);
449 dssdev->dev.bus = &dss_bus_type;
450 dssdev->dev.parent = parent;
451 dssdev->dev.release = omap_dss_dev_release;
452 dev_set_name(&dssdev->dev, "display%d", disp_num);
453 return device_register(&dssdev->dev);
456 void omap_dss_unregister_device(struct omap_dss_device *dssdev)
458 device_unregister(&dssdev->dev);
461 static int dss_unregister_dss_dev(struct device *dev, void *data)
463 struct omap_dss_device *dssdev = to_dss_device(dev);
464 omap_dss_unregister_device(dssdev);
468 void omap_dss_unregister_child_devices(struct device *parent)
470 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
474 static int __init omap_dss_bus_register(void)
478 r = bus_register(&dss_bus_type);
480 DSSERR("bus register failed\n");
484 dev_set_name(&dss_bus, "omapdss");
485 r = device_register(&dss_bus);
487 DSSERR("bus driver register failed\n");
488 bus_unregister(&dss_bus_type);
496 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
497 #ifdef CONFIG_OMAP2_DSS_DPI
498 dpi_init_platform_driver,
500 #ifdef CONFIG_OMAP2_DSS_SDI
501 sdi_init_platform_driver,
503 #ifdef CONFIG_OMAP2_DSS_RFBI
504 rfbi_init_platform_driver,
506 #ifdef CONFIG_OMAP2_DSS_VENC
507 venc_init_platform_driver,
509 #ifdef CONFIG_OMAP2_DSS_DSI
510 dsi_init_platform_driver,
512 #ifdef CONFIG_OMAP4_DSS_HDMI
513 hdmi_init_platform_driver,
517 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
518 #ifdef CONFIG_OMAP2_DSS_DPI
519 dpi_uninit_platform_driver,
521 #ifdef CONFIG_OMAP2_DSS_SDI
522 sdi_uninit_platform_driver,
524 #ifdef CONFIG_OMAP2_DSS_RFBI
525 rfbi_uninit_platform_driver,
527 #ifdef CONFIG_OMAP2_DSS_VENC
528 venc_uninit_platform_driver,
530 #ifdef CONFIG_OMAP2_DSS_DSI
531 dsi_uninit_platform_driver,
533 #ifdef CONFIG_OMAP4_DSS_HDMI
534 hdmi_uninit_platform_driver,
538 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
540 static int __init omap_dss_register_drivers(void)
545 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
549 r = dss_init_platform_driver();
551 DSSERR("Failed to initialize DSS platform driver\n");
555 r = dispc_init_platform_driver();
557 DSSERR("Failed to initialize dispc platform driver\n");
562 * It's ok if the output-driver register fails. It happens, for example,
563 * when there is no output-device (e.g. SDI for OMAP4).
565 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
566 r = dss_output_drv_reg_funcs[i]();
568 dss_output_drv_loaded[i] = true;
574 dss_uninit_platform_driver();
576 platform_driver_unregister(&omap_dss_driver);
581 static void __exit omap_dss_unregister_drivers(void)
585 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
586 if (dss_output_drv_loaded[i])
587 dss_output_drv_unreg_funcs[i]();
590 dispc_uninit_platform_driver();
591 dss_uninit_platform_driver();
593 platform_driver_unregister(&omap_dss_driver);
596 #ifdef CONFIG_OMAP2_DSS_MODULE
597 static void omap_dss_bus_unregister(void)
599 device_unregister(&dss_bus);
601 bus_unregister(&dss_bus_type);
604 static int __init omap_dss_init(void)
608 r = omap_dss_bus_register();
612 r = omap_dss_register_drivers();
614 omap_dss_bus_unregister();
621 static void __exit omap_dss_exit(void)
623 if (core.vdds_dsi_reg != NULL) {
624 regulator_put(core.vdds_dsi_reg);
625 core.vdds_dsi_reg = NULL;
628 if (core.vdds_sdi_reg != NULL) {
629 regulator_put(core.vdds_sdi_reg);
630 core.vdds_sdi_reg = NULL;
633 omap_dss_unregister_drivers();
635 omap_dss_bus_unregister();
638 module_init(omap_dss_init);
639 module_exit(omap_dss_exit);
641 static int __init omap_dss_init(void)
643 return omap_dss_bus_register();
646 static int __init omap_dss_init2(void)
648 return omap_dss_register_drivers();
651 core_initcall(omap_dss_init);
652 device_initcall(omap_dss_init2);
655 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
656 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
657 MODULE_LICENSE("GPL v2");