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>
36 #include <linux/slab.h>
38 #include <video/omapdss.h>
41 #include "dss_features.h"
44 struct platform_device *pdev;
46 struct regulator *vdds_dsi_reg;
47 struct regulator *vdds_sdi_reg;
49 const char *default_display_name;
52 static char *def_disp_name;
53 module_param_named(def_disp, def_disp_name, charp, 0);
54 MODULE_PARM_DESC(def_disp, "default display name");
56 const char *omapdss_get_default_display_name(void)
58 return core.default_display_name;
60 EXPORT_SYMBOL(omapdss_get_default_display_name);
62 enum omapdss_version omapdss_get_version(void)
64 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
65 return pdata->version;
67 EXPORT_SYMBOL(omapdss_get_version);
69 struct platform_device *dss_get_core_pdev(void)
76 struct regulator *dss_get_vdds_dsi(void)
78 struct regulator *reg;
80 if (core.vdds_dsi_reg != NULL)
81 return core.vdds_dsi_reg;
83 reg = regulator_get(&core.pdev->dev, "vdds_dsi");
85 core.vdds_dsi_reg = reg;
90 struct regulator *dss_get_vdds_sdi(void)
92 struct regulator *reg;
94 if (core.vdds_sdi_reg != NULL)
95 return core.vdds_sdi_reg;
97 reg = regulator_get(&core.pdev->dev, "vdds_sdi");
99 core.vdds_sdi_reg = reg;
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_disable_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_OMAP2_DSS_DEBUGFS)
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_OMAP2_DSS_DEBUGFS */
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_OMAP2_DSS_DEBUGFS */
203 /* PLATFORM DEVICE */
204 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
206 DSSDBG("pm notif %lu\n", v);
209 case PM_SUSPEND_PREPARE:
210 DSSDBG("suspending displays\n");
211 return dss_suspend_all_devices();
213 case PM_POST_SUSPEND:
214 DSSDBG("resuming displays\n");
215 return dss_resume_all_devices();
222 static struct notifier_block omap_dss_pm_notif_block = {
223 .notifier_call = omap_dss_pm_notif,
226 static int __init omap_dss_probe(struct platform_device *pdev)
228 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
233 dss_features_init(omapdss_get_version());
235 r = dss_initialize_debugfs();
240 core.default_display_name = def_disp_name;
241 else if (pdata->default_device)
242 core.default_display_name = pdata->default_device->name;
244 register_pm_notifier(&omap_dss_pm_notif_block);
253 static int omap_dss_remove(struct platform_device *pdev)
255 unregister_pm_notifier(&omap_dss_pm_notif_block);
257 dss_uninitialize_debugfs();
262 static void omap_dss_shutdown(struct platform_device *pdev)
264 DSSDBG("shutdown\n");
265 dss_disable_all_devices();
268 static struct platform_driver omap_dss_driver = {
269 .remove = omap_dss_remove,
270 .shutdown = omap_dss_shutdown,
273 .owner = THIS_MODULE,
278 static int dss_bus_match(struct device *dev, struct device_driver *driver)
280 struct omap_dss_device *dssdev = to_dss_device(dev);
282 DSSDBG("bus_match. dev %s/%s, drv %s\n",
283 dev_name(dev), dssdev->driver_name, driver->name);
285 return strcmp(dssdev->driver_name, driver->name) == 0;
288 static ssize_t device_name_show(struct device *dev,
289 struct device_attribute *attr, char *buf)
291 struct omap_dss_device *dssdev = to_dss_device(dev);
292 return snprintf(buf, PAGE_SIZE, "%s\n",
297 static struct device_attribute default_dev_attrs[] = {
298 __ATTR(name, S_IRUGO, device_name_show, NULL),
302 static ssize_t driver_name_show(struct device_driver *drv, char *buf)
304 struct omap_dss_driver *dssdrv = to_dss_driver(drv);
305 return snprintf(buf, PAGE_SIZE, "%s\n",
306 dssdrv->driver.name ?
307 dssdrv->driver.name : "");
309 static struct driver_attribute default_drv_attrs[] = {
310 __ATTR(name, S_IRUGO, driver_name_show, NULL),
314 static struct bus_type dss_bus_type = {
316 .match = dss_bus_match,
317 .dev_attrs = default_dev_attrs,
318 .drv_attrs = default_drv_attrs,
321 static void dss_bus_release(struct device *dev)
323 DSSDBG("bus_release\n");
326 static struct device dss_bus = {
327 .release = dss_bus_release,
330 struct bus_type *dss_get_bus(void)
332 return &dss_bus_type;
336 static int dss_driver_probe(struct device *dev)
339 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
340 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 r = dssdrv->probe(dssdev);
349 DSSERR("driver probe failed: %d\n", r);
353 DSSDBG("probe done for device %s\n", dev_name(dev));
355 dssdev->driver = dssdrv;
360 static int dss_driver_remove(struct device *dev)
362 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
363 struct omap_dss_device *dssdev = to_dss_device(dev);
365 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
366 dssdev->driver_name);
368 dssdrv->remove(dssdev);
370 dssdev->driver = NULL;
375 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
377 dssdriver->driver.bus = &dss_bus_type;
378 dssdriver->driver.probe = dss_driver_probe;
379 dssdriver->driver.remove = dss_driver_remove;
381 if (dssdriver->get_resolution == NULL)
382 dssdriver->get_resolution = omapdss_default_get_resolution;
383 if (dssdriver->get_recommended_bpp == NULL)
384 dssdriver->get_recommended_bpp =
385 omapdss_default_get_recommended_bpp;
386 if (dssdriver->get_timings == NULL)
387 dssdriver->get_timings = omapdss_default_get_timings;
389 return driver_register(&dssdriver->driver);
391 EXPORT_SYMBOL(omap_dss_register_driver);
393 void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
395 driver_unregister(&dssdriver->driver);
397 EXPORT_SYMBOL(omap_dss_unregister_driver);
401 static void omap_dss_dev_release(struct device *dev)
403 struct omap_dss_device *dssdev = to_dss_device(dev);
407 static int disp_num_counter;
409 struct omap_dss_device *dss_alloc_and_init_device(struct device *parent)
411 struct omap_dss_device *dssdev;
413 dssdev = kzalloc(sizeof(*dssdev), GFP_KERNEL);
417 dssdev->dev.bus = &dss_bus_type;
418 dssdev->dev.parent = parent;
419 dssdev->dev.release = omap_dss_dev_release;
420 dev_set_name(&dssdev->dev, "display%d", disp_num_counter++);
422 device_initialize(&dssdev->dev);
427 int dss_add_device(struct omap_dss_device *dssdev)
429 return device_add(&dssdev->dev);
432 void dss_put_device(struct omap_dss_device *dssdev)
434 put_device(&dssdev->dev);
437 void dss_unregister_device(struct omap_dss_device *dssdev)
439 device_unregister(&dssdev->dev);
442 static int dss_unregister_dss_dev(struct device *dev, void *data)
444 struct omap_dss_device *dssdev = to_dss_device(dev);
445 dss_unregister_device(dssdev);
449 void dss_unregister_child_devices(struct device *parent)
451 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
454 void dss_copy_device_pdata(struct omap_dss_device *dst,
455 const struct omap_dss_device *src)
459 size_t dsize = sizeof(struct device);
461 memcpy(d + dsize, s + dsize, sizeof(struct omap_dss_device) - dsize);
465 static int __init omap_dss_bus_register(void)
469 r = bus_register(&dss_bus_type);
471 DSSERR("bus register failed\n");
475 dev_set_name(&dss_bus, "omapdss");
476 r = device_register(&dss_bus);
478 DSSERR("bus driver register failed\n");
479 bus_unregister(&dss_bus_type);
487 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
488 #ifdef CONFIG_OMAP2_DSS_DSI
489 dsi_init_platform_driver,
491 #ifdef CONFIG_OMAP2_DSS_DPI
492 dpi_init_platform_driver,
494 #ifdef CONFIG_OMAP2_DSS_SDI
495 sdi_init_platform_driver,
497 #ifdef CONFIG_OMAP2_DSS_RFBI
498 rfbi_init_platform_driver,
500 #ifdef CONFIG_OMAP2_DSS_VENC
501 venc_init_platform_driver,
503 #ifdef CONFIG_OMAP4_DSS_HDMI
504 hdmi_init_platform_driver,
508 static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
509 #ifdef CONFIG_OMAP2_DSS_DSI
510 dsi_uninit_platform_driver,
512 #ifdef CONFIG_OMAP2_DSS_DPI
513 dpi_uninit_platform_driver,
515 #ifdef CONFIG_OMAP2_DSS_SDI
516 sdi_uninit_platform_driver,
518 #ifdef CONFIG_OMAP2_DSS_RFBI
519 rfbi_uninit_platform_driver,
521 #ifdef CONFIG_OMAP2_DSS_VENC
522 venc_uninit_platform_driver,
524 #ifdef CONFIG_OMAP4_DSS_HDMI
525 hdmi_uninit_platform_driver,
529 static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
531 static int __init omap_dss_register_drivers(void)
536 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
540 r = dss_init_platform_driver();
542 DSSERR("Failed to initialize DSS platform driver\n");
546 r = dispc_init_platform_driver();
548 DSSERR("Failed to initialize dispc platform driver\n");
553 * It's ok if the output-driver register fails. It happens, for example,
554 * when there is no output-device (e.g. SDI for OMAP4).
556 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
557 r = dss_output_drv_reg_funcs[i]();
559 dss_output_drv_loaded[i] = true;
565 dss_uninit_platform_driver();
567 platform_driver_unregister(&omap_dss_driver);
572 static void __exit omap_dss_unregister_drivers(void)
576 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
577 if (dss_output_drv_loaded[i])
578 dss_output_drv_unreg_funcs[i]();
581 dispc_uninit_platform_driver();
582 dss_uninit_platform_driver();
584 platform_driver_unregister(&omap_dss_driver);
587 #ifdef CONFIG_OMAP2_DSS_MODULE
588 static void omap_dss_bus_unregister(void)
590 device_unregister(&dss_bus);
592 bus_unregister(&dss_bus_type);
595 static int __init omap_dss_init(void)
599 r = omap_dss_bus_register();
603 r = omap_dss_register_drivers();
605 omap_dss_bus_unregister();
612 static void __exit omap_dss_exit(void)
614 if (core.vdds_dsi_reg != NULL) {
615 regulator_put(core.vdds_dsi_reg);
616 core.vdds_dsi_reg = NULL;
619 if (core.vdds_sdi_reg != NULL) {
620 regulator_put(core.vdds_sdi_reg);
621 core.vdds_sdi_reg = NULL;
624 omap_dss_unregister_drivers();
626 omap_dss_bus_unregister();
629 module_init(omap_dss_init);
630 module_exit(omap_dss_exit);
632 static int __init omap_dss_init(void)
634 return omap_dss_bus_register();
637 static int __init omap_dss_init2(void)
639 return omap_dss_register_drivers();
642 core_initcall(omap_dss_init);
643 device_initcall(omap_dss_init2);
646 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
647 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
648 MODULE_LICENSE("GPL v2");