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>
35 #include <plat/display.h>
36 #include <plat/clock.h>
41 struct platform_device
*pdev
;
47 struct clk
*dss_54m_fck
;
48 struct clk
*dss_96m_fck
;
49 unsigned num_clks_enabled
;
52 static void dss_clk_enable_all_no_ctx(void);
53 static void dss_clk_disable_all_no_ctx(void);
54 static void dss_clk_enable_no_ctx(enum dss_clock clks
);
55 static void dss_clk_disable_no_ctx(enum dss_clock clks
);
57 static char *def_disp_name
;
58 module_param_named(def_disp
, def_disp_name
, charp
, 0);
59 MODULE_PARM_DESC(def_disp_name
, "default display name");
62 unsigned int dss_debug
;
63 module_param_named(debug
, dss_debug
, bool, 0644);
67 static int dss_get_ctx_id(void)
69 struct omap_dss_board_info
*pdata
= core
.pdev
->dev
.platform_data
;
72 if (!pdata
->get_last_off_on_transaction_id
)
74 r
= pdata
->get_last_off_on_transaction_id(&core
.pdev
->dev
);
76 dev_err(&core
.pdev
->dev
, "getting transaction ID failed, "
77 "will force context restore\n");
83 int dss_need_ctx_restore(void)
85 int id
= dss_get_ctx_id();
87 if (id
< 0 || id
!= core
.ctx_id
) {
88 DSSDBG("ctx id %d -> id %d\n",
97 static void save_all_ctx(void)
99 DSSDBG("save context\n");
101 dss_clk_enable_no_ctx(DSS_CLK_ICK
| DSS_CLK_FCK1
);
104 dispc_save_context();
105 #ifdef CONFIG_OMAP2_DSS_DSI
109 dss_clk_disable_no_ctx(DSS_CLK_ICK
| DSS_CLK_FCK1
);
112 static void restore_all_ctx(void)
114 DSSDBG("restore context\n");
116 dss_clk_enable_all_no_ctx();
118 dss_restore_context();
119 dispc_restore_context();
120 #ifdef CONFIG_OMAP2_DSS_DSI
121 dsi_restore_context();
124 dss_clk_disable_all_no_ctx();
128 void core_dump_clocks(struct seq_file
*s
)
131 struct clk
*clocks
[5] = {
139 seq_printf(s
, "- CORE -\n");
141 seq_printf(s
, "internal clk count\t\t%u\n", core
.num_clks_enabled
);
143 for (i
= 0; i
< 5; i
++) {
146 seq_printf(s
, "%-15s\t%lu\t%d\n",
148 clk_get_rate(clocks
[i
]),
149 clocks
[i
]->usecount
);
153 static int dss_get_clock(struct clk
**clock
, const char *clk_name
)
157 clk
= clk_get(&core
.pdev
->dev
, clk_name
);
160 DSSERR("can't get clock %s", clk_name
);
166 DSSDBG("clk %s, rate %ld\n", clk_name
, clk_get_rate(clk
));
171 static int dss_get_clocks(void)
176 core
.dss1_fck
= NULL
;
177 core
.dss2_fck
= NULL
;
178 core
.dss_54m_fck
= NULL
;
179 core
.dss_96m_fck
= NULL
;
181 r
= dss_get_clock(&core
.dss_ick
, "ick");
185 r
= dss_get_clock(&core
.dss1_fck
, "dss1_fck");
189 r
= dss_get_clock(&core
.dss2_fck
, "dss2_fck");
193 r
= dss_get_clock(&core
.dss_54m_fck
, "tv_fck");
197 r
= dss_get_clock(&core
.dss_96m_fck
, "video_fck");
205 clk_put(core
.dss_ick
);
207 clk_put(core
.dss1_fck
);
209 clk_put(core
.dss2_fck
);
210 if (core
.dss_54m_fck
)
211 clk_put(core
.dss_54m_fck
);
212 if (core
.dss_96m_fck
)
213 clk_put(core
.dss_96m_fck
);
218 static void dss_put_clocks(void)
220 if (core
.dss_96m_fck
)
221 clk_put(core
.dss_96m_fck
);
222 clk_put(core
.dss_54m_fck
);
223 clk_put(core
.dss1_fck
);
224 clk_put(core
.dss2_fck
);
225 clk_put(core
.dss_ick
);
228 unsigned long dss_clk_get_rate(enum dss_clock clk
)
232 return clk_get_rate(core
.dss_ick
);
234 return clk_get_rate(core
.dss1_fck
);
236 return clk_get_rate(core
.dss2_fck
);
238 return clk_get_rate(core
.dss_54m_fck
);
240 return clk_get_rate(core
.dss_96m_fck
);
247 static unsigned count_clk_bits(enum dss_clock clks
)
249 unsigned num_clks
= 0;
251 if (clks
& DSS_CLK_ICK
)
253 if (clks
& DSS_CLK_FCK1
)
255 if (clks
& DSS_CLK_FCK2
)
257 if (clks
& DSS_CLK_54M
)
259 if (clks
& DSS_CLK_96M
)
265 static void dss_clk_enable_no_ctx(enum dss_clock clks
)
267 unsigned num_clks
= count_clk_bits(clks
);
269 if (clks
& DSS_CLK_ICK
)
270 clk_enable(core
.dss_ick
);
271 if (clks
& DSS_CLK_FCK1
)
272 clk_enable(core
.dss1_fck
);
273 if (clks
& DSS_CLK_FCK2
)
274 clk_enable(core
.dss2_fck
);
275 if (clks
& DSS_CLK_54M
)
276 clk_enable(core
.dss_54m_fck
);
277 if (clks
& DSS_CLK_96M
)
278 clk_enable(core
.dss_96m_fck
);
280 core
.num_clks_enabled
+= num_clks
;
283 void dss_clk_enable(enum dss_clock clks
)
285 dss_clk_enable_no_ctx(clks
);
287 if (cpu_is_omap34xx() && dss_need_ctx_restore())
291 static void dss_clk_disable_no_ctx(enum dss_clock clks
)
293 unsigned num_clks
= count_clk_bits(clks
);
295 if (clks
& DSS_CLK_ICK
)
296 clk_disable(core
.dss_ick
);
297 if (clks
& DSS_CLK_FCK1
)
298 clk_disable(core
.dss1_fck
);
299 if (clks
& DSS_CLK_FCK2
)
300 clk_disable(core
.dss2_fck
);
301 if (clks
& DSS_CLK_54M
)
302 clk_disable(core
.dss_54m_fck
);
303 if (clks
& DSS_CLK_96M
)
304 clk_disable(core
.dss_96m_fck
);
306 core
.num_clks_enabled
-= num_clks
;
309 void dss_clk_disable(enum dss_clock clks
)
311 if (cpu_is_omap34xx()) {
312 unsigned num_clks
= count_clk_bits(clks
);
314 BUG_ON(core
.num_clks_enabled
< num_clks
);
316 if (core
.num_clks_enabled
== num_clks
)
320 dss_clk_disable_no_ctx(clks
);
323 static void dss_clk_enable_all_no_ctx(void)
327 clks
= DSS_CLK_ICK
| DSS_CLK_FCK1
| DSS_CLK_FCK2
| DSS_CLK_54M
;
328 if (cpu_is_omap34xx())
330 dss_clk_enable_no_ctx(clks
);
333 static void dss_clk_disable_all_no_ctx(void)
337 clks
= DSS_CLK_ICK
| DSS_CLK_FCK1
| DSS_CLK_FCK2
| DSS_CLK_54M
;
338 if (cpu_is_omap34xx())
340 dss_clk_disable_no_ctx(clks
);
343 static void dss_clk_disable_all(void)
347 clks
= DSS_CLK_ICK
| DSS_CLK_FCK1
| DSS_CLK_FCK2
| DSS_CLK_54M
;
348 if (cpu_is_omap34xx())
350 dss_clk_disable(clks
);
354 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
355 static void dss_debug_dump_clocks(struct seq_file
*s
)
359 dispc_dump_clocks(s
);
360 #ifdef CONFIG_OMAP2_DSS_DSI
365 static int dss_debug_show(struct seq_file
*s
, void *unused
)
367 void (*func
)(struct seq_file
*) = s
->private;
372 static int dss_debug_open(struct inode
*inode
, struct file
*file
)
374 return single_open(file
, dss_debug_show
, inode
->i_private
);
377 static const struct file_operations dss_debug_fops
= {
378 .open
= dss_debug_open
,
381 .release
= single_release
,
384 static struct dentry
*dss_debugfs_dir
;
386 static int dss_initialize_debugfs(void)
388 dss_debugfs_dir
= debugfs_create_dir("omapdss", NULL
);
389 if (IS_ERR(dss_debugfs_dir
)) {
390 int err
= PTR_ERR(dss_debugfs_dir
);
391 dss_debugfs_dir
= NULL
;
395 debugfs_create_file("clk", S_IRUGO
, dss_debugfs_dir
,
396 &dss_debug_dump_clocks
, &dss_debug_fops
);
398 debugfs_create_file("dss", S_IRUGO
, dss_debugfs_dir
,
399 &dss_dump_regs
, &dss_debug_fops
);
400 debugfs_create_file("dispc", S_IRUGO
, dss_debugfs_dir
,
401 &dispc_dump_regs
, &dss_debug_fops
);
402 #ifdef CONFIG_OMAP2_DSS_RFBI
403 debugfs_create_file("rfbi", S_IRUGO
, dss_debugfs_dir
,
404 &rfbi_dump_regs
, &dss_debug_fops
);
406 #ifdef CONFIG_OMAP2_DSS_DSI
407 debugfs_create_file("dsi", S_IRUGO
, dss_debugfs_dir
,
408 &dsi_dump_regs
, &dss_debug_fops
);
410 #ifdef CONFIG_OMAP2_DSS_VENC
411 debugfs_create_file("venc", S_IRUGO
, dss_debugfs_dir
,
412 &venc_dump_regs
, &dss_debug_fops
);
417 static void dss_uninitialize_debugfs(void)
420 debugfs_remove_recursive(dss_debugfs_dir
);
422 #endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
424 /* PLATFORM DEVICE */
425 static int omap_dss_probe(struct platform_device
*pdev
)
427 struct omap_dss_board_info
*pdata
= pdev
->dev
.platform_data
;
434 dss_init_overlay_managers(pdev
);
435 dss_init_overlays(pdev
);
437 r
= dss_get_clocks();
441 dss_clk_enable_all_no_ctx();
443 core
.ctx_id
= dss_get_ctx_id();
444 DSSDBG("initial ctx id %u\n", core
.ctx_id
);
446 #ifdef CONFIG_FB_OMAP_BOOTLOADER_INIT
448 if (omap_readl(0x48050440) & 1) /* LCD enabled? */
452 r
= dss_init(skip_init
);
454 DSSERR("Failed to initialize DSS\n");
458 #ifdef CONFIG_OMAP2_DSS_RFBI
461 DSSERR("Failed to initialize rfbi\n");
468 DSSERR("Failed to initialize dpi\n");
474 DSSERR("Failed to initialize dispc\n");
477 #ifdef CONFIG_OMAP2_DSS_VENC
480 DSSERR("Failed to initialize venc\n");
484 if (cpu_is_omap34xx()) {
485 #ifdef CONFIG_OMAP2_DSS_SDI
486 r
= sdi_init(skip_init
);
488 DSSERR("Failed to initialize SDI\n");
492 #ifdef CONFIG_OMAP2_DSS_DSI
495 DSSERR("Failed to initialize DSI\n");
501 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
502 r
= dss_initialize_debugfs();
507 for (i
= 0; i
< pdata
->num_devices
; ++i
) {
508 struct omap_dss_device
*dssdev
= pdata
->devices
[i
];
510 r
= omap_dss_register_device(dssdev
);
512 DSSERR("device reg failed %d\n", i
);
514 if (def_disp_name
&& strcmp(def_disp_name
, dssdev
->name
) == 0)
515 pdata
->default_device
= dssdev
;
518 dss_clk_disable_all();
522 /* XXX fail correctly */
527 static int omap_dss_remove(struct platform_device
*pdev
)
529 struct omap_dss_board_info
*pdata
= pdev
->dev
.platform_data
;
533 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
534 dss_uninitialize_debugfs();
537 #ifdef CONFIG_OMAP2_DSS_VENC
542 #ifdef CONFIG_OMAP2_DSS_RFBI
545 if (cpu_is_omap34xx()) {
546 #ifdef CONFIG_OMAP2_DSS_DSI
549 #ifdef CONFIG_OMAP2_DSS_SDI
556 /* these should be removed at some point */
557 c
= core
.dss_ick
->usecount
;
559 DSSERR("warning: dss_ick usecount %d, disabling\n", c
);
561 clk_disable(core
.dss_ick
);
564 c
= core
.dss1_fck
->usecount
;
566 DSSERR("warning: dss1_fck usecount %d, disabling\n", c
);
568 clk_disable(core
.dss1_fck
);
571 c
= core
.dss2_fck
->usecount
;
573 DSSERR("warning: dss2_fck usecount %d, disabling\n", c
);
575 clk_disable(core
.dss2_fck
);
578 c
= core
.dss_54m_fck
->usecount
;
580 DSSERR("warning: dss_54m_fck usecount %d, disabling\n", c
);
582 clk_disable(core
.dss_54m_fck
);
585 if (core
.dss_96m_fck
) {
586 c
= core
.dss_96m_fck
->usecount
;
588 DSSERR("warning: dss_96m_fck usecount %d, disabling\n",
591 clk_disable(core
.dss_96m_fck
);
597 dss_uninit_overlays(pdev
);
598 dss_uninit_overlay_managers(pdev
);
600 for (i
= 0; i
< pdata
->num_devices
; ++i
)
601 omap_dss_unregister_device(pdata
->devices
[i
]);
606 static void omap_dss_shutdown(struct platform_device
*pdev
)
608 DSSDBG("shutdown\n");
609 dss_disable_all_devices();
612 static int omap_dss_suspend(struct platform_device
*pdev
, pm_message_t state
)
614 DSSDBG("suspend %d\n", state
.event
);
616 return dss_suspend_all_devices();
619 static int omap_dss_resume(struct platform_device
*pdev
)
623 return dss_resume_all_devices();
626 static struct platform_driver omap_dss_driver
= {
627 .probe
= omap_dss_probe
,
628 .remove
= omap_dss_remove
,
629 .shutdown
= omap_dss_shutdown
,
630 .suspend
= omap_dss_suspend
,
631 .resume
= omap_dss_resume
,
634 .owner
= THIS_MODULE
,
639 static int dss_bus_match(struct device
*dev
, struct device_driver
*driver
)
641 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
643 DSSDBG("bus_match. dev %s/%s, drv %s\n",
644 dev_name(dev
), dssdev
->driver_name
, driver
->name
);
646 return strcmp(dssdev
->driver_name
, driver
->name
) == 0;
649 static ssize_t
device_name_show(struct device
*dev
,
650 struct device_attribute
*attr
, char *buf
)
652 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
653 return snprintf(buf
, PAGE_SIZE
, "%s\n",
658 static struct device_attribute default_dev_attrs
[] = {
659 __ATTR(name
, S_IRUGO
, device_name_show
, NULL
),
663 static ssize_t
driver_name_show(struct device_driver
*drv
, char *buf
)
665 struct omap_dss_driver
*dssdrv
= to_dss_driver(drv
);
666 return snprintf(buf
, PAGE_SIZE
, "%s\n",
667 dssdrv
->driver
.name
?
668 dssdrv
->driver
.name
: "");
670 static struct driver_attribute default_drv_attrs
[] = {
671 __ATTR(name
, S_IRUGO
, driver_name_show
, NULL
),
675 static struct bus_type dss_bus_type
= {
677 .match
= dss_bus_match
,
678 .dev_attrs
= default_dev_attrs
,
679 .drv_attrs
= default_drv_attrs
,
682 static void dss_bus_release(struct device
*dev
)
684 DSSDBG("bus_release\n");
687 static struct device dss_bus
= {
688 .release
= dss_bus_release
,
691 struct bus_type
*dss_get_bus(void)
693 return &dss_bus_type
;
697 static int dss_driver_probe(struct device
*dev
)
700 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
701 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
702 struct omap_dss_board_info
*pdata
= core
.pdev
->dev
.platform_data
;
705 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
706 dev_name(dev
), dssdev
->driver_name
,
707 dssdrv
->driver
.name
);
709 dss_init_device(core
.pdev
, dssdev
);
711 /* skip this if the device is behind a ctrl */
712 if (!dssdev
->panel
.ctrl
) {
713 force
= pdata
->default_device
== dssdev
;
714 dss_recheck_connections(dssdev
, force
);
717 r
= dssdrv
->probe(dssdev
);
720 DSSERR("driver probe failed: %d\n", r
);
724 DSSDBG("probe done for device %s\n", dev_name(dev
));
726 dssdev
->driver
= dssdrv
;
731 static int dss_driver_remove(struct device
*dev
)
733 struct omap_dss_driver
*dssdrv
= to_dss_driver(dev
->driver
);
734 struct omap_dss_device
*dssdev
= to_dss_device(dev
);
736 DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev
),
737 dssdev
->driver_name
);
739 dssdrv
->remove(dssdev
);
741 dss_uninit_device(core
.pdev
, dssdev
);
743 dssdev
->driver
= NULL
;
748 int omap_dss_register_driver(struct omap_dss_driver
*dssdriver
)
750 dssdriver
->driver
.bus
= &dss_bus_type
;
751 dssdriver
->driver
.probe
= dss_driver_probe
;
752 dssdriver
->driver
.remove
= dss_driver_remove
;
753 return driver_register(&dssdriver
->driver
);
755 EXPORT_SYMBOL(omap_dss_register_driver
);
757 void omap_dss_unregister_driver(struct omap_dss_driver
*dssdriver
)
759 driver_unregister(&dssdriver
->driver
);
761 EXPORT_SYMBOL(omap_dss_unregister_driver
);
764 static void reset_device(struct device
*dev
, int check
)
766 u8
*dev_p
= (u8
*)dev
;
767 u8
*dev_end
= dev_p
+ sizeof(*dev
);
770 saved_pdata
= dev
->platform_data
;
773 * Check if there is any other setting than platform_data
774 * in struct device; warn that these will be reset by our
777 dev
->platform_data
= NULL
;
778 while (dev_p
< dev_end
) {
780 WARN("%s: struct device fields will be "
788 memset(dev
, 0, sizeof(*dev
));
789 dev
->platform_data
= saved_pdata
;
793 static void omap_dss_dev_release(struct device
*dev
)
795 reset_device(dev
, 0);
798 int omap_dss_register_device(struct omap_dss_device
*dssdev
)
801 static int panel_num
;
804 WARN_ON(!dssdev
->driver_name
);
806 reset_device(&dssdev
->dev
, 1);
807 dssdev
->dev
.bus
= &dss_bus_type
;
808 dssdev
->dev
.parent
= &dss_bus
;
809 dssdev
->dev
.release
= omap_dss_dev_release
;
810 dev_set_name(&dssdev
->dev
, "display%d", dev_num
++);
811 r
= device_register(&dssdev
->dev
);
815 if (dssdev
->ctrl
.panel
) {
816 struct omap_dss_device
*panel
= dssdev
->ctrl
.panel
;
818 panel
->panel
.ctrl
= dssdev
;
820 reset_device(&panel
->dev
, 1);
821 panel
->dev
.bus
= &dss_bus_type
;
822 panel
->dev
.parent
= &dssdev
->dev
;
823 panel
->dev
.release
= omap_dss_dev_release
;
824 dev_set_name(&panel
->dev
, "panel%d", panel_num
++);
825 r
= device_register(&panel
->dev
);
833 void omap_dss_unregister_device(struct omap_dss_device
*dssdev
)
835 device_unregister(&dssdev
->dev
);
837 if (dssdev
->ctrl
.panel
) {
838 struct omap_dss_device
*panel
= dssdev
->ctrl
.panel
;
839 device_unregister(&panel
->dev
);
844 static int omap_dss_bus_register(void)
848 r
= bus_register(&dss_bus_type
);
850 DSSERR("bus register failed\n");
854 dev_set_name(&dss_bus
, "omapdss");
855 r
= device_register(&dss_bus
);
857 DSSERR("bus driver register failed\n");
858 bus_unregister(&dss_bus_type
);
867 #ifdef CONFIG_OMAP2_DSS_MODULE
868 static void omap_dss_bus_unregister(void)
870 device_unregister(&dss_bus
);
872 bus_unregister(&dss_bus_type
);
875 static int __init
omap_dss_init(void)
879 r
= omap_dss_bus_register();
883 r
= platform_driver_register(&omap_dss_driver
);
885 omap_dss_bus_unregister();
892 static void __exit
omap_dss_exit(void)
894 platform_driver_unregister(&omap_dss_driver
);
896 omap_dss_bus_unregister();
899 module_init(omap_dss_init
);
900 module_exit(omap_dss_exit
);
902 static int __init
omap_dss_init(void)
904 return omap_dss_bus_register();
907 static int __init
omap_dss_init2(void)
909 return platform_driver_register(&omap_dss_driver
);
912 core_initcall(omap_dss_init
);
913 device_initcall(omap_dss_init2
);
916 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
917 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
918 MODULE_LICENSE("GPL v2");