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 omapdss_compat_init();
237 dss_init_overlay_managers(pdev
);
238 dss_init_overlays(pdev
);
240 r
= dss_initialize_debugfs();
245 core
.default_display_name
= def_disp_name
;
246 else if (pdata
->default_device
)
247 core
.default_display_name
= pdata
->default_device
->name
;
249 register_pm_notifier(&omap_dss_pm_notif_block
);
258 static int omap_dss_remove(struct platform_device
*pdev
)
260 unregister_pm_notifier(&omap_dss_pm_notif_block
);
262 dss_uninitialize_debugfs();
264 dss_uninit_overlays(pdev
);
265 dss_uninit_overlay_managers(pdev
);
267 omapdss_compat_uninit();
272 static void omap_dss_shutdown(struct platform_device
*pdev
)
274 DSSDBG("shutdown\n");
275 dss_disable_all_devices();
278 static struct platform_driver omap_dss_driver
= {
279 .remove
= omap_dss_remove
,
280 .shutdown
= omap_dss_shutdown
,
283 .owner
= THIS_MODULE
,
288 static int dss_bus_match(struct device
*dev
, struct device_driver
*driver
)
290 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
292 DSSDBG("bus_match. dev %s/%s, drv %s\n",
293 dev_name(dev
), dssdev
->driver_name
, driver
->name
);
295 return strcmp(dssdev
->driver_name
, driver
->name
) == 0;
298 static ssize_t
device_name_show(struct device
*dev
,
299 struct device_attribute
*attr
, char *buf
)
301 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
302 return snprintf(buf
, PAGE_SIZE
, "%s\n",
307 static struct device_attribute default_dev_attrs
[] = {
308 __ATTR(name
, S_IRUGO
, device_name_show
, NULL
),
312 static ssize_t
driver_name_show(struct device_driver
*drv
, char *buf
)
314 struct omap_dss_driver
*dssdrv
= to_dss_driver(drv
);
315 return snprintf(buf
, PAGE_SIZE
, "%s\n",
316 dssdrv
->driver
.name
?
317 dssdrv
->driver
.name
: "");
319 static struct driver_attribute default_drv_attrs
[] = {
320 __ATTR(name
, S_IRUGO
, driver_name_show
, NULL
),
324 static struct bus_type dss_bus_type
= {
326 .match
= dss_bus_match
,
327 .dev_attrs
= default_dev_attrs
,
328 .drv_attrs
= default_drv_attrs
,
331 static void dss_bus_release(struct device
*dev
)
333 DSSDBG("bus_release\n");
336 static struct device dss_bus
= {
337 .release
= dss_bus_release
,
340 struct bus_type
*dss_get_bus(void)
342 return &dss_bus_type
;
346 static int dss_driver_probe(struct device
*dev
)
349 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
350 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 r
= dss_init_device(core
.pdev
, dssdev
);
360 r
= dssdrv
->probe(dssdev
);
363 DSSERR("driver probe failed: %d\n", r
);
364 dss_uninit_device(core
.pdev
, dssdev
);
368 DSSDBG("probe done for device %s\n", dev_name(dev
));
370 dssdev
->driver
= dssdrv
;
375 static int dss_driver_remove(struct device
*dev
)
377 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
378 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
380 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev
),
381 dssdev
->driver_name
);
383 dssdrv
->remove(dssdev
);
385 dss_uninit_device(core
.pdev
, dssdev
);
387 dssdev
->driver
= NULL
;
392 int omap_dss_register_driver(struct omap_dss_driver
*dssdriver
)
394 dssdriver
->driver
.bus
= &dss_bus_type
;
395 dssdriver
->driver
.probe
= dss_driver_probe
;
396 dssdriver
->driver
.remove
= dss_driver_remove
;
398 if (dssdriver
->get_resolution
== NULL
)
399 dssdriver
->get_resolution
= omapdss_default_get_resolution
;
400 if (dssdriver
->get_recommended_bpp
== NULL
)
401 dssdriver
->get_recommended_bpp
=
402 omapdss_default_get_recommended_bpp
;
403 if (dssdriver
->get_timings
== NULL
)
404 dssdriver
->get_timings
= omapdss_default_get_timings
;
406 return driver_register(&dssdriver
->driver
);
408 EXPORT_SYMBOL(omap_dss_register_driver
);
410 void omap_dss_unregister_driver(struct omap_dss_driver
*dssdriver
)
412 driver_unregister(&dssdriver
->driver
);
414 EXPORT_SYMBOL(omap_dss_unregister_driver
);
418 static void omap_dss_dev_release(struct device
*dev
)
420 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
424 static int disp_num_counter
;
426 struct omap_dss_device
*dss_alloc_and_init_device(struct device
*parent
)
428 struct omap_dss_device
*dssdev
;
430 dssdev
= kzalloc(sizeof(*dssdev
), GFP_KERNEL
);
434 dssdev
->dev
.bus
= &dss_bus_type
;
435 dssdev
->dev
.parent
= parent
;
436 dssdev
->dev
.release
= omap_dss_dev_release
;
437 dev_set_name(&dssdev
->dev
, "display%d", disp_num_counter
++);
439 device_initialize(&dssdev
->dev
);
444 int dss_add_device(struct omap_dss_device
*dssdev
)
446 return device_add(&dssdev
->dev
);
449 void dss_put_device(struct omap_dss_device
*dssdev
)
451 put_device(&dssdev
->dev
);
454 void dss_unregister_device(struct omap_dss_device
*dssdev
)
456 device_unregister(&dssdev
->dev
);
459 static int dss_unregister_dss_dev(struct device
*dev
, void *data
)
461 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
462 dss_unregister_device(dssdev
);
466 void dss_unregister_child_devices(struct device
*parent
)
468 device_for_each_child(parent
, NULL
, dss_unregister_dss_dev
);
471 void dss_copy_device_pdata(struct omap_dss_device
*dst
,
472 const struct omap_dss_device
*src
)
476 size_t dsize
= sizeof(struct device
);
478 memcpy(d
+ dsize
, s
+ dsize
, sizeof(struct omap_dss_device
) - dsize
);
482 static int __init
omap_dss_bus_register(void)
486 r
= bus_register(&dss_bus_type
);
488 DSSERR("bus register failed\n");
492 dev_set_name(&dss_bus
, "omapdss");
493 r
= device_register(&dss_bus
);
495 DSSERR("bus driver register failed\n");
496 bus_unregister(&dss_bus_type
);
504 static int (*dss_output_drv_reg_funcs
[])(void) __initdata
= {
505 #ifdef CONFIG_OMAP2_DSS_DSI
506 dsi_init_platform_driver
,
508 #ifdef CONFIG_OMAP2_DSS_DPI
509 dpi_init_platform_driver
,
511 #ifdef CONFIG_OMAP2_DSS_SDI
512 sdi_init_platform_driver
,
514 #ifdef CONFIG_OMAP2_DSS_RFBI
515 rfbi_init_platform_driver
,
517 #ifdef CONFIG_OMAP2_DSS_VENC
518 venc_init_platform_driver
,
520 #ifdef CONFIG_OMAP4_DSS_HDMI
521 hdmi_init_platform_driver
,
525 static void (*dss_output_drv_unreg_funcs
[])(void) __exitdata
= {
526 #ifdef CONFIG_OMAP2_DSS_DSI
527 dsi_uninit_platform_driver
,
529 #ifdef CONFIG_OMAP2_DSS_DPI
530 dpi_uninit_platform_driver
,
532 #ifdef CONFIG_OMAP2_DSS_SDI
533 sdi_uninit_platform_driver
,
535 #ifdef CONFIG_OMAP2_DSS_RFBI
536 rfbi_uninit_platform_driver
,
538 #ifdef CONFIG_OMAP2_DSS_VENC
539 venc_uninit_platform_driver
,
541 #ifdef CONFIG_OMAP4_DSS_HDMI
542 hdmi_uninit_platform_driver
,
546 static bool dss_output_drv_loaded
[ARRAY_SIZE(dss_output_drv_reg_funcs
)];
548 static int __init
omap_dss_register_drivers(void)
553 r
= platform_driver_probe(&omap_dss_driver
, omap_dss_probe
);
557 r
= dss_init_platform_driver();
559 DSSERR("Failed to initialize DSS platform driver\n");
563 r
= dispc_init_platform_driver();
565 DSSERR("Failed to initialize dispc platform driver\n");
570 * It's ok if the output-driver register fails. It happens, for example,
571 * when there is no output-device (e.g. SDI for OMAP4).
573 for (i
= 0; i
< ARRAY_SIZE(dss_output_drv_reg_funcs
); ++i
) {
574 r
= dss_output_drv_reg_funcs
[i
]();
576 dss_output_drv_loaded
[i
] = true;
582 dss_uninit_platform_driver();
584 platform_driver_unregister(&omap_dss_driver
);
589 static void __exit
omap_dss_unregister_drivers(void)
593 for (i
= 0; i
< ARRAY_SIZE(dss_output_drv_unreg_funcs
); ++i
) {
594 if (dss_output_drv_loaded
[i
])
595 dss_output_drv_unreg_funcs
[i
]();
598 dispc_uninit_platform_driver();
599 dss_uninit_platform_driver();
601 platform_driver_unregister(&omap_dss_driver
);
604 #ifdef CONFIG_OMAP2_DSS_MODULE
605 static void omap_dss_bus_unregister(void)
607 device_unregister(&dss_bus
);
609 bus_unregister(&dss_bus_type
);
612 static int __init
omap_dss_init(void)
616 r
= omap_dss_bus_register();
620 r
= omap_dss_register_drivers();
622 omap_dss_bus_unregister();
629 static void __exit
omap_dss_exit(void)
631 if (core
.vdds_dsi_reg
!= NULL
) {
632 regulator_put(core
.vdds_dsi_reg
);
633 core
.vdds_dsi_reg
= NULL
;
636 if (core
.vdds_sdi_reg
!= NULL
) {
637 regulator_put(core
.vdds_sdi_reg
);
638 core
.vdds_sdi_reg
= NULL
;
641 omap_dss_unregister_drivers();
643 omap_dss_bus_unregister();
646 module_init(omap_dss_init
);
647 module_exit(omap_dss_exit
);
649 static int __init
omap_dss_init(void)
651 return omap_dss_bus_register();
654 static int __init
omap_dss_init2(void)
656 return omap_dss_register_drivers();
659 core_initcall(omap_dss_init
);
660 device_initcall(omap_dss_init2
);
663 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
664 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
665 MODULE_LICENSE("GPL v2");