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
);
186 #else /* CONFIG_OMAP2_DSS_DEBUGFS */
187 static inline int dss_initialize_debugfs(void)
191 static inline void dss_uninitialize_debugfs(void)
194 int dss_debugfs_create_file(const char *name
, void (*write
)(struct seq_file
*))
198 #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
200 /* PLATFORM DEVICE */
201 static int omap_dss_pm_notif(struct notifier_block
*b
, unsigned long v
, void *d
)
203 DSSDBG("pm notif %lu\n", v
);
206 case PM_SUSPEND_PREPARE
:
207 DSSDBG("suspending displays\n");
208 return dss_suspend_all_devices();
210 case PM_POST_SUSPEND
:
211 DSSDBG("resuming displays\n");
212 return dss_resume_all_devices();
219 static struct notifier_block omap_dss_pm_notif_block
= {
220 .notifier_call
= omap_dss_pm_notif
,
223 static int __init
omap_dss_probe(struct platform_device
*pdev
)
225 struct omap_dss_board_info
*pdata
= pdev
->dev
.platform_data
;
230 dss_features_init(omapdss_get_version());
232 r
= dss_initialize_debugfs();
237 core
.default_display_name
= def_disp_name
;
238 else if (pdata
->default_device
)
239 core
.default_display_name
= pdata
->default_device
->name
;
241 register_pm_notifier(&omap_dss_pm_notif_block
);
250 static int omap_dss_remove(struct platform_device
*pdev
)
252 unregister_pm_notifier(&omap_dss_pm_notif_block
);
254 dss_uninitialize_debugfs();
259 static void omap_dss_shutdown(struct platform_device
*pdev
)
261 DSSDBG("shutdown\n");
262 dss_disable_all_devices();
265 static struct platform_driver omap_dss_driver
= {
266 .remove
= omap_dss_remove
,
267 .shutdown
= omap_dss_shutdown
,
270 .owner
= THIS_MODULE
,
275 static int dss_bus_match(struct device
*dev
, struct device_driver
*driver
)
277 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
279 DSSDBG("bus_match. dev %s/%s, drv %s\n",
280 dev_name(dev
), dssdev
->driver_name
, driver
->name
);
282 return strcmp(dssdev
->driver_name
, driver
->name
) == 0;
285 static ssize_t
device_name_show(struct device
*dev
,
286 struct device_attribute
*attr
, char *buf
)
288 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
289 return snprintf(buf
, PAGE_SIZE
, "%s\n",
294 static struct device_attribute default_dev_attrs
[] = {
295 __ATTR(name
, S_IRUGO
, device_name_show
, NULL
),
299 static ssize_t
driver_name_show(struct device_driver
*drv
, char *buf
)
301 struct omap_dss_driver
*dssdrv
= to_dss_driver(drv
);
302 return snprintf(buf
, PAGE_SIZE
, "%s\n",
303 dssdrv
->driver
.name
?
304 dssdrv
->driver
.name
: "");
306 static struct driver_attribute default_drv_attrs
[] = {
307 __ATTR(name
, S_IRUGO
, driver_name_show
, NULL
),
311 static struct bus_type dss_bus_type
= {
313 .match
= dss_bus_match
,
314 .dev_attrs
= default_dev_attrs
,
315 .drv_attrs
= default_drv_attrs
,
318 static void dss_bus_release(struct device
*dev
)
320 DSSDBG("bus_release\n");
323 static struct device dss_bus
= {
324 .release
= dss_bus_release
,
327 struct bus_type
*dss_get_bus(void)
329 return &dss_bus_type
;
333 static int dss_driver_probe(struct device
*dev
)
336 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
337 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
339 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
340 dev_name(dev
), dssdev
->driver_name
,
341 dssdrv
->driver
.name
);
343 r
= dssdrv
->probe(dssdev
);
346 DSSERR("driver probe failed: %d\n", r
);
350 DSSDBG("probe done for device %s\n", dev_name(dev
));
352 dssdev
->driver
= dssdrv
;
357 static int dss_driver_remove(struct device
*dev
)
359 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
360 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
362 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev
),
363 dssdev
->driver_name
);
365 dssdrv
->remove(dssdev
);
367 dssdev
->driver
= NULL
;
372 int omap_dss_register_driver(struct omap_dss_driver
*dssdriver
)
374 dssdriver
->driver
.bus
= &dss_bus_type
;
375 dssdriver
->driver
.probe
= dss_driver_probe
;
376 dssdriver
->driver
.remove
= dss_driver_remove
;
378 if (dssdriver
->get_resolution
== NULL
)
379 dssdriver
->get_resolution
= omapdss_default_get_resolution
;
380 if (dssdriver
->get_recommended_bpp
== NULL
)
381 dssdriver
->get_recommended_bpp
=
382 omapdss_default_get_recommended_bpp
;
383 if (dssdriver
->get_timings
== NULL
)
384 dssdriver
->get_timings
= omapdss_default_get_timings
;
386 return driver_register(&dssdriver
->driver
);
388 EXPORT_SYMBOL(omap_dss_register_driver
);
390 void omap_dss_unregister_driver(struct omap_dss_driver
*dssdriver
)
392 driver_unregister(&dssdriver
->driver
);
394 EXPORT_SYMBOL(omap_dss_unregister_driver
);
398 static void omap_dss_dev_release(struct device
*dev
)
400 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
404 static int disp_num_counter
;
406 struct omap_dss_device
*dss_alloc_and_init_device(struct device
*parent
)
408 struct omap_dss_device
*dssdev
;
410 dssdev
= kzalloc(sizeof(*dssdev
), GFP_KERNEL
);
414 dssdev
->dev
.bus
= &dss_bus_type
;
415 dssdev
->dev
.parent
= parent
;
416 dssdev
->dev
.release
= omap_dss_dev_release
;
417 dev_set_name(&dssdev
->dev
, "display%d", disp_num_counter
++);
419 device_initialize(&dssdev
->dev
);
424 int dss_add_device(struct omap_dss_device
*dssdev
)
426 return device_add(&dssdev
->dev
);
429 void dss_put_device(struct omap_dss_device
*dssdev
)
431 put_device(&dssdev
->dev
);
434 void dss_unregister_device(struct omap_dss_device
*dssdev
)
436 device_unregister(&dssdev
->dev
);
439 static int dss_unregister_dss_dev(struct device
*dev
, void *data
)
441 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
442 dss_unregister_device(dssdev
);
446 void dss_unregister_child_devices(struct device
*parent
)
448 device_for_each_child(parent
, NULL
, dss_unregister_dss_dev
);
451 void dss_copy_device_pdata(struct omap_dss_device
*dst
,
452 const struct omap_dss_device
*src
)
456 size_t dsize
= sizeof(struct device
);
458 memcpy(d
+ dsize
, s
+ dsize
, sizeof(struct omap_dss_device
) - dsize
);
462 static int __init
omap_dss_bus_register(void)
466 r
= bus_register(&dss_bus_type
);
468 DSSERR("bus register failed\n");
472 dev_set_name(&dss_bus
, "omapdss");
473 r
= device_register(&dss_bus
);
475 DSSERR("bus driver register failed\n");
476 bus_unregister(&dss_bus_type
);
484 static int (*dss_output_drv_reg_funcs
[])(void) __initdata
= {
485 #ifdef CONFIG_OMAP2_DSS_DSI
486 dsi_init_platform_driver
,
488 #ifdef CONFIG_OMAP2_DSS_DPI
489 dpi_init_platform_driver
,
491 #ifdef CONFIG_OMAP2_DSS_SDI
492 sdi_init_platform_driver
,
494 #ifdef CONFIG_OMAP2_DSS_RFBI
495 rfbi_init_platform_driver
,
497 #ifdef CONFIG_OMAP2_DSS_VENC
498 venc_init_platform_driver
,
500 #ifdef CONFIG_OMAP4_DSS_HDMI
501 hdmi_init_platform_driver
,
505 static void (*dss_output_drv_unreg_funcs
[])(void) __exitdata
= {
506 #ifdef CONFIG_OMAP2_DSS_DSI
507 dsi_uninit_platform_driver
,
509 #ifdef CONFIG_OMAP2_DSS_DPI
510 dpi_uninit_platform_driver
,
512 #ifdef CONFIG_OMAP2_DSS_SDI
513 sdi_uninit_platform_driver
,
515 #ifdef CONFIG_OMAP2_DSS_RFBI
516 rfbi_uninit_platform_driver
,
518 #ifdef CONFIG_OMAP2_DSS_VENC
519 venc_uninit_platform_driver
,
521 #ifdef CONFIG_OMAP4_DSS_HDMI
522 hdmi_uninit_platform_driver
,
526 static bool dss_output_drv_loaded
[ARRAY_SIZE(dss_output_drv_reg_funcs
)];
528 static int __init
omap_dss_register_drivers(void)
533 r
= platform_driver_probe(&omap_dss_driver
, omap_dss_probe
);
537 r
= dss_init_platform_driver();
539 DSSERR("Failed to initialize DSS platform driver\n");
543 r
= dispc_init_platform_driver();
545 DSSERR("Failed to initialize dispc platform driver\n");
550 * It's ok if the output-driver register fails. It happens, for example,
551 * when there is no output-device (e.g. SDI for OMAP4).
553 for (i
= 0; i
< ARRAY_SIZE(dss_output_drv_reg_funcs
); ++i
) {
554 r
= dss_output_drv_reg_funcs
[i
]();
556 dss_output_drv_loaded
[i
] = true;
562 dss_uninit_platform_driver();
564 platform_driver_unregister(&omap_dss_driver
);
569 static void __exit
omap_dss_unregister_drivers(void)
573 for (i
= 0; i
< ARRAY_SIZE(dss_output_drv_unreg_funcs
); ++i
) {
574 if (dss_output_drv_loaded
[i
])
575 dss_output_drv_unreg_funcs
[i
]();
578 dispc_uninit_platform_driver();
579 dss_uninit_platform_driver();
581 platform_driver_unregister(&omap_dss_driver
);
584 #ifdef CONFIG_OMAP2_DSS_MODULE
585 static void omap_dss_bus_unregister(void)
587 device_unregister(&dss_bus
);
589 bus_unregister(&dss_bus_type
);
592 static int __init
omap_dss_init(void)
596 r
= omap_dss_bus_register();
600 r
= omap_dss_register_drivers();
602 omap_dss_bus_unregister();
609 static void __exit
omap_dss_exit(void)
611 if (core
.vdds_dsi_reg
!= NULL
) {
612 regulator_put(core
.vdds_dsi_reg
);
613 core
.vdds_dsi_reg
= NULL
;
616 if (core
.vdds_sdi_reg
!= NULL
) {
617 regulator_put(core
.vdds_sdi_reg
);
618 core
.vdds_sdi_reg
= NULL
;
621 omap_dss_unregister_drivers();
623 omap_dss_bus_unregister();
626 module_init(omap_dss_init
);
627 module_exit(omap_dss_exit
);
629 static int __init
omap_dss_init(void)
631 return omap_dss_bus_register();
634 static int __init
omap_dss_init2(void)
636 return omap_dss_register_drivers();
639 core_initcall(omap_dss_init
);
640 device_initcall(omap_dss_init2
);
643 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
644 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
645 MODULE_LICENSE("GPL v2");