1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/omap2/dss/dss.c
5 * Copyright (C) 2009 Nokia Corporation
6 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Some code and ideas taken from drivers/video/omap/ driver
12 #define DSS_SUBSYS_NAME "DSS"
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/export.h>
18 #include <linux/err.h>
19 #include <linux/delay.h>
20 #include <linux/seq_file.h>
21 #include <linux/clk.h>
22 #include <linux/platform_device.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/gfp.h>
25 #include <linux/sizes.h>
26 #include <linux/mfd/syscon.h>
27 #include <linux/regmap.h>
29 #include <linux/regulator/consumer.h>
30 #include <linux/suspend.h>
31 #include <linux/component.h>
32 #include <linux/pinctrl/consumer.h>
34 #include <video/omapfb_dss.h>
37 #include "dss_features.h"
39 #define DSS_SZ_REGS SZ_512
45 #define DSS_REG(idx) ((const struct dss_reg) { idx })
47 #define DSS_REVISION DSS_REG(0x0000)
48 #define DSS_SYSCONFIG DSS_REG(0x0010)
49 #define DSS_SYSSTATUS DSS_REG(0x0014)
50 #define DSS_CONTROL DSS_REG(0x0040)
51 #define DSS_SDI_CONTROL DSS_REG(0x0044)
52 #define DSS_PLL_CONTROL DSS_REG(0x0048)
53 #define DSS_SDI_STATUS DSS_REG(0x005C)
55 #define REG_GET(idx, start, end) \
56 FLD_GET(dss_read_reg(idx), start, end)
58 #define REG_FLD_MOD(idx, val, start, end) \
59 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
63 u8 dss_fck_multiplier
;
64 const char *parent_clk_name
;
65 const enum omap_display_type
*ports
;
67 int (*dpi_select_source
)(int port
, enum omap_channel channel
);
71 struct platform_device
*pdev
;
73 struct regmap
*syscon_pll_ctrl
;
74 u32 syscon_pll_ctrl_offset
;
76 struct clk
*parent_clk
;
78 unsigned long dss_clk_rate
;
80 unsigned long cache_req_pck
;
81 unsigned long cache_prate
;
82 struct dispc_clock_info cache_dispc_cinfo
;
84 enum omap_dss_clk_source dsi_clk_source
[MAX_NUM_DSI
];
85 enum omap_dss_clk_source dispc_clk_source
;
86 enum omap_dss_clk_source lcd_clk_source
[MAX_DSS_LCD_MANAGERS
];
89 u32 ctx
[DSS_SZ_REGS
/ sizeof(u32
)];
91 const struct dss_features
*feat
;
93 struct dss_pll
*video1_pll
;
94 struct dss_pll
*video2_pll
;
97 static const char * const dss_generic_clk_source_names
[] = {
98 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
] = "DSI_PLL_HSDIV_DISPC",
99 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
] = "DSI_PLL_HSDIV_DSI",
100 [OMAP_DSS_CLK_SRC_FCK
] = "DSS_FCK",
101 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
] = "DSI_PLL2_HSDIV_DISPC",
102 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
] = "DSI_PLL2_HSDIV_DSI",
105 static bool dss_initialized
;
107 bool omapdss_is_initialized(void)
109 return dss_initialized
;
111 EXPORT_SYMBOL(omapdss_is_initialized
);
113 static inline void dss_write_reg(const struct dss_reg idx
, u32 val
)
115 __raw_writel(val
, dss
.base
+ idx
.idx
);
118 static inline u32
dss_read_reg(const struct dss_reg idx
)
120 return __raw_readl(dss
.base
+ idx
.idx
);
124 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
126 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
128 static void dss_save_context(void)
130 DSSDBG("dss_save_context\n");
134 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
135 OMAP_DISPLAY_TYPE_SDI
) {
140 dss
.ctx_valid
= true;
142 DSSDBG("context saved\n");
145 static void dss_restore_context(void)
147 DSSDBG("dss_restore_context\n");
154 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
155 OMAP_DISPLAY_TYPE_SDI
) {
160 DSSDBG("context restored\n");
166 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
)
171 if (!dss
.syscon_pll_ctrl
)
187 DSSERR("illegal DSS PLL ID %d\n", pll_id
);
191 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
192 1 << shift
, val
<< shift
);
195 void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id
,
196 enum omap_channel channel
)
200 if (!dss
.syscon_pll_ctrl
)
204 case OMAP_DSS_CHANNEL_LCD
:
213 DSSERR("error in PLL mux config for LCD\n");
218 case OMAP_DSS_CHANNEL_LCD2
:
229 DSSERR("error in PLL mux config for LCD2\n");
234 case OMAP_DSS_CHANNEL_LCD3
:
245 DSSERR("error in PLL mux config for LCD3\n");
251 DSSERR("error in PLL mux config\n");
255 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
256 0x3 << shift
, val
<< shift
);
259 void dss_sdi_init(int datapairs
)
263 BUG_ON(datapairs
> 3 || datapairs
< 1);
265 l
= dss_read_reg(DSS_SDI_CONTROL
);
266 l
= FLD_MOD(l
, 0xf, 19, 15); /* SDI_PDIV */
267 l
= FLD_MOD(l
, datapairs
-1, 3, 2); /* SDI_PRSEL */
268 l
= FLD_MOD(l
, 2, 1, 0); /* SDI_BWSEL */
269 dss_write_reg(DSS_SDI_CONTROL
, l
);
271 l
= dss_read_reg(DSS_PLL_CONTROL
);
272 l
= FLD_MOD(l
, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
273 l
= FLD_MOD(l
, 0xb, 16, 11); /* SDI_PLL_REGN */
274 l
= FLD_MOD(l
, 0xb4, 10, 1); /* SDI_PLL_REGM */
275 dss_write_reg(DSS_PLL_CONTROL
, l
);
278 int dss_sdi_enable(void)
280 unsigned long timeout
;
282 dispc_pck_free_enable(1);
285 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 18, 18); /* SDI_PLL_SYSRESET */
286 udelay(1); /* wait 2x PCLK */
289 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 28, 28); /* SDI_PLL_GOBIT */
291 /* Waiting for PLL lock request to complete */
292 timeout
= jiffies
+ msecs_to_jiffies(500);
293 while (dss_read_reg(DSS_SDI_STATUS
) & (1 << 6)) {
294 if (time_after_eq(jiffies
, timeout
)) {
295 DSSERR("PLL lock request timed out\n");
300 /* Clearing PLL_GO bit */
301 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 28, 28);
303 /* Waiting for PLL to lock */
304 timeout
= jiffies
+ msecs_to_jiffies(500);
305 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 5))) {
306 if (time_after_eq(jiffies
, timeout
)) {
307 DSSERR("PLL lock timed out\n");
312 dispc_lcd_enable_signal(1);
314 /* Waiting for SDI reset to complete */
315 timeout
= jiffies
+ msecs_to_jiffies(500);
316 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 2))) {
317 if (time_after_eq(jiffies
, timeout
)) {
318 DSSERR("SDI reset timed out\n");
326 dispc_lcd_enable_signal(0);
329 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
331 dispc_pck_free_enable(0);
336 void dss_sdi_disable(void)
338 dispc_lcd_enable_signal(0);
340 dispc_pck_free_enable(0);
343 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
346 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src
)
348 return dss_generic_clk_source_names
[clk_src
];
351 void dss_dump_clocks(struct seq_file
*s
)
353 const char *fclk_name
, *fclk_real_name
;
354 unsigned long fclk_rate
;
356 if (dss_runtime_get())
359 seq_printf(s
, "- DSS -\n");
361 fclk_name
= dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
362 fclk_real_name
= dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
363 fclk_rate
= clk_get_rate(dss
.dss_clk
);
365 seq_printf(s
, "%s (%s) = %lu\n",
366 fclk_name
, fclk_real_name
,
372 static void dss_dump_regs(struct seq_file
*s
)
374 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
376 if (dss_runtime_get())
379 DUMPREG(DSS_REVISION
);
380 DUMPREG(DSS_SYSCONFIG
);
381 DUMPREG(DSS_SYSSTATUS
);
382 DUMPREG(DSS_CONTROL
);
384 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
385 OMAP_DISPLAY_TYPE_SDI
) {
386 DUMPREG(DSS_SDI_CONTROL
);
387 DUMPREG(DSS_PLL_CONTROL
);
388 DUMPREG(DSS_SDI_STATUS
);
395 static void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src
)
401 case OMAP_DSS_CLK_SRC_FCK
:
404 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
407 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
415 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH
, &start
, &end
);
417 REG_FLD_MOD(DSS_CONTROL
, b
, start
, end
); /* DISPC_CLK_SWITCH */
419 dss
.dispc_clk_source
= clk_src
;
422 void dss_select_dsi_clk_source(int dsi_module
,
423 enum omap_dss_clk_source clk_src
)
428 case OMAP_DSS_CLK_SRC_FCK
:
431 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
:
432 BUG_ON(dsi_module
!= 0);
435 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
:
436 BUG_ON(dsi_module
!= 1);
444 pos
= dsi_module
== 0 ? 1 : 10;
445 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* DSIx_CLK_SWITCH */
447 dss
.dsi_clk_source
[dsi_module
] = clk_src
;
450 void dss_select_lcd_clk_source(enum omap_channel channel
,
451 enum omap_dss_clk_source clk_src
)
455 if (!dss_has_feature(FEAT_LCD_CLK_SRC
)) {
456 dss_select_dispc_clk_source(clk_src
);
461 case OMAP_DSS_CLK_SRC_FCK
:
464 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
465 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD
);
468 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
469 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD2
&&
470 channel
!= OMAP_DSS_CHANNEL_LCD3
);
478 pos
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
479 (channel
== OMAP_DSS_CHANNEL_LCD2
? 12 : 19);
480 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* LCDx_CLK_SWITCH */
482 ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
483 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
484 dss
.lcd_clk_source
[ix
] = clk_src
;
487 enum omap_dss_clk_source
dss_get_dispc_clk_source(void)
489 return dss
.dispc_clk_source
;
492 enum omap_dss_clk_source
dss_get_dsi_clk_source(int dsi_module
)
494 return dss
.dsi_clk_source
[dsi_module
];
497 enum omap_dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
)
499 if (dss_has_feature(FEAT_LCD_CLK_SRC
)) {
500 int ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
501 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
502 return dss
.lcd_clk_source
[ix
];
504 /* LCD_CLK source is the same as DISPC_FCLK source for
506 return dss
.dispc_clk_source
;
510 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
511 dss_div_calc_func func
, void *data
)
513 int fckd
, fckd_start
, fckd_stop
;
515 unsigned long fck_hw_max
;
516 unsigned long fckd_hw_max
;
520 fck_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
522 if (dss
.parent_clk
== NULL
) {
525 pckd
= fck_hw_max
/ pck
;
529 fck
= clk_round_rate(dss
.dss_clk
, fck
);
531 return func(fck
, data
);
534 fckd_hw_max
= dss
.feat
->fck_div_max
;
536 m
= dss
.feat
->dss_fck_multiplier
;
537 prate
= clk_get_rate(dss
.parent_clk
);
539 fck_min
= fck_min
? fck_min
: 1;
541 fckd_start
= min(prate
* m
/ fck_min
, fckd_hw_max
);
542 fckd_stop
= max(DIV_ROUND_UP(prate
* m
, fck_hw_max
), 1ul);
544 for (fckd
= fckd_start
; fckd
>= fckd_stop
; --fckd
) {
545 fck
= DIV_ROUND_UP(prate
, fckd
) * m
;
554 int dss_set_fck_rate(unsigned long rate
)
558 DSSDBG("set fck to %lu\n", rate
);
560 r
= clk_set_rate(dss
.dss_clk
, rate
);
564 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
566 WARN_ONCE(dss
.dss_clk_rate
!= rate
,
567 "clk rate mismatch: %lu != %lu", dss
.dss_clk_rate
,
573 unsigned long dss_get_dispc_clk_rate(void)
575 return dss
.dss_clk_rate
;
578 static int dss_setup_default_clock(void)
580 unsigned long max_dss_fck
, prate
;
585 max_dss_fck
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
587 if (dss
.parent_clk
== NULL
) {
588 fck
= clk_round_rate(dss
.dss_clk
, max_dss_fck
);
590 prate
= clk_get_rate(dss
.parent_clk
);
592 fck_div
= DIV_ROUND_UP(prate
* dss
.feat
->dss_fck_multiplier
,
594 fck
= DIV_ROUND_UP(prate
, fck_div
) * dss
.feat
->dss_fck_multiplier
;
597 r
= dss_set_fck_rate(fck
);
604 void dss_set_venc_output(enum omap_dss_venc_type type
)
608 if (type
== OMAP_DSS_VENC_TYPE_COMPOSITE
)
610 else if (type
== OMAP_DSS_VENC_TYPE_SVIDEO
)
615 /* venc out selection. 0 = comp, 1 = svideo */
616 REG_FLD_MOD(DSS_CONTROL
, l
, 6, 6);
619 void dss_set_dac_pwrdn_bgz(bool enable
)
621 REG_FLD_MOD(DSS_CONTROL
, enable
, 5, 5); /* DAC Power-Down Control */
624 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src
)
626 enum omap_display_type dp
;
627 dp
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
629 /* Complain about invalid selections */
630 WARN_ON((src
== DSS_VENC_TV_CLK
) && !(dp
& OMAP_DISPLAY_TYPE_VENC
));
631 WARN_ON((src
== DSS_HDMI_M_PCLK
) && !(dp
& OMAP_DISPLAY_TYPE_HDMI
));
633 /* Select only if we have options */
634 if ((dp
& OMAP_DISPLAY_TYPE_VENC
) && (dp
& OMAP_DISPLAY_TYPE_HDMI
))
635 REG_FLD_MOD(DSS_CONTROL
, src
, 15, 15); /* VENC_HDMI_SWITCH */
638 enum dss_hdmi_venc_clk_source_select
dss_get_hdmi_venc_clk_source(void)
640 enum omap_display_type displays
;
642 displays
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
643 if ((displays
& OMAP_DISPLAY_TYPE_HDMI
) == 0)
644 return DSS_VENC_TV_CLK
;
646 if ((displays
& OMAP_DISPLAY_TYPE_VENC
) == 0)
647 return DSS_HDMI_M_PCLK
;
649 return REG_GET(DSS_CONTROL
, 15, 15);
652 static int dss_dpi_select_source_omap2_omap3(int port
, enum omap_channel channel
)
654 if (channel
!= OMAP_DSS_CHANNEL_LCD
)
660 static int dss_dpi_select_source_omap4(int port
, enum omap_channel channel
)
665 case OMAP_DSS_CHANNEL_LCD2
:
668 case OMAP_DSS_CHANNEL_DIGIT
:
675 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 17);
680 static int dss_dpi_select_source_omap5(int port
, enum omap_channel channel
)
685 case OMAP_DSS_CHANNEL_LCD
:
688 case OMAP_DSS_CHANNEL_LCD2
:
691 case OMAP_DSS_CHANNEL_LCD3
:
694 case OMAP_DSS_CHANNEL_DIGIT
:
701 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 16);
706 static int dss_dpi_select_source_dra7xx(int port
, enum omap_channel channel
)
710 return dss_dpi_select_source_omap5(port
, channel
);
712 if (channel
!= OMAP_DSS_CHANNEL_LCD2
)
716 if (channel
!= OMAP_DSS_CHANNEL_LCD3
)
726 int dss_dpi_select_source(int port
, enum omap_channel channel
)
728 return dss
.feat
->dpi_select_source(port
, channel
);
731 static int dss_get_clocks(void)
735 clk
= devm_clk_get(&dss
.pdev
->dev
, "fck");
737 DSSERR("can't get clock fck\n");
743 if (dss
.feat
->parent_clk_name
) {
744 clk
= clk_get(NULL
, dss
.feat
->parent_clk_name
);
746 DSSERR("Failed to get %s\n", dss
.feat
->parent_clk_name
);
753 dss
.parent_clk
= clk
;
758 static void dss_put_clocks(void)
761 clk_put(dss
.parent_clk
);
764 int dss_runtime_get(void)
768 DSSDBG("dss_runtime_get\n");
770 r
= pm_runtime_get_sync(&dss
.pdev
->dev
);
771 if (WARN_ON(r
< 0)) {
772 pm_runtime_put_sync(&dss
.pdev
->dev
);
778 void dss_runtime_put(void)
782 DSSDBG("dss_runtime_put\n");
784 r
= pm_runtime_put_sync(&dss
.pdev
->dev
);
785 WARN_ON(r
< 0 && r
!= -ENOSYS
&& r
!= -EBUSY
);
789 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
790 void dss_debug_dump_clocks(struct seq_file
*s
)
793 dispc_dump_clocks(s
);
794 #ifdef CONFIG_FB_OMAP2_DSS_DSI
801 static const enum omap_display_type omap2plus_ports
[] = {
802 OMAP_DISPLAY_TYPE_DPI
,
805 static const enum omap_display_type omap34xx_ports
[] = {
806 OMAP_DISPLAY_TYPE_DPI
,
807 OMAP_DISPLAY_TYPE_SDI
,
810 static const enum omap_display_type dra7xx_ports
[] = {
811 OMAP_DISPLAY_TYPE_DPI
,
812 OMAP_DISPLAY_TYPE_DPI
,
813 OMAP_DISPLAY_TYPE_DPI
,
816 static const struct dss_features omap24xx_dss_feats
= {
818 * fck div max is really 16, but the divider range has gaps. The range
819 * from 1 to 6 has no gaps, so let's use that as a max.
822 .dss_fck_multiplier
= 2,
823 .parent_clk_name
= "core_ck",
824 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
825 .ports
= omap2plus_ports
,
826 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
829 static const struct dss_features omap34xx_dss_feats
= {
831 .dss_fck_multiplier
= 2,
832 .parent_clk_name
= "dpll4_ck",
833 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
834 .ports
= omap34xx_ports
,
835 .num_ports
= ARRAY_SIZE(omap34xx_ports
),
838 static const struct dss_features omap3630_dss_feats
= {
840 .dss_fck_multiplier
= 1,
841 .parent_clk_name
= "dpll4_ck",
842 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
843 .ports
= omap2plus_ports
,
844 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
847 static const struct dss_features omap44xx_dss_feats
= {
849 .dss_fck_multiplier
= 1,
850 .parent_clk_name
= "dpll_per_x2_ck",
851 .dpi_select_source
= &dss_dpi_select_source_omap4
,
852 .ports
= omap2plus_ports
,
853 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
856 static const struct dss_features omap54xx_dss_feats
= {
858 .dss_fck_multiplier
= 1,
859 .parent_clk_name
= "dpll_per_x2_ck",
860 .dpi_select_source
= &dss_dpi_select_source_omap5
,
861 .ports
= omap2plus_ports
,
862 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
865 static const struct dss_features am43xx_dss_feats
= {
867 .dss_fck_multiplier
= 0,
868 .parent_clk_name
= NULL
,
869 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
870 .ports
= omap2plus_ports
,
871 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
874 static const struct dss_features dra7xx_dss_feats
= {
876 .dss_fck_multiplier
= 1,
877 .parent_clk_name
= "dpll_per_x2_ck",
878 .dpi_select_source
= &dss_dpi_select_source_dra7xx
,
879 .ports
= dra7xx_ports
,
880 .num_ports
= ARRAY_SIZE(dra7xx_ports
),
883 static const struct dss_features
*dss_get_features(void)
885 switch (omapdss_get_version()) {
886 case OMAPDSS_VER_OMAP24xx
:
887 return &omap24xx_dss_feats
;
889 case OMAPDSS_VER_OMAP34xx_ES1
:
890 case OMAPDSS_VER_OMAP34xx_ES3
:
891 case OMAPDSS_VER_AM35xx
:
892 return &omap34xx_dss_feats
;
894 case OMAPDSS_VER_OMAP3630
:
895 return &omap3630_dss_feats
;
897 case OMAPDSS_VER_OMAP4430_ES1
:
898 case OMAPDSS_VER_OMAP4430_ES2
:
899 case OMAPDSS_VER_OMAP4
:
900 return &omap44xx_dss_feats
;
902 case OMAPDSS_VER_OMAP5
:
903 return &omap54xx_dss_feats
;
905 case OMAPDSS_VER_AM43xx
:
906 return &am43xx_dss_feats
;
908 case OMAPDSS_VER_DRA7xx
:
909 return &dra7xx_dss_feats
;
916 static void dss_uninit_ports(struct platform_device
*pdev
);
918 static int dss_init_ports(struct platform_device
*pdev
)
920 struct device_node
*parent
= pdev
->dev
.of_node
;
921 struct device_node
*port
;
927 port
= omapdss_of_get_next_port(parent
, NULL
);
931 if (dss
.feat
->num_ports
== 0)
935 enum omap_display_type port_type
;
938 r
= of_property_read_u32(port
, "reg", ®
);
942 if (reg
>= dss
.feat
->num_ports
)
945 port_type
= dss
.feat
->ports
[reg
];
948 case OMAP_DISPLAY_TYPE_DPI
:
949 ret
= dpi_init_port(pdev
, port
);
951 case OMAP_DISPLAY_TYPE_SDI
:
952 ret
= sdi_init_port(pdev
, port
);
958 (port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
961 dss_uninit_ports(pdev
);
966 static void dss_uninit_ports(struct platform_device
*pdev
)
968 struct device_node
*parent
= pdev
->dev
.of_node
;
969 struct device_node
*port
;
974 port
= omapdss_of_get_next_port(parent
, NULL
);
978 if (dss
.feat
->num_ports
== 0)
982 enum omap_display_type port_type
;
986 r
= of_property_read_u32(port
, "reg", ®
);
990 if (reg
>= dss
.feat
->num_ports
)
993 port_type
= dss
.feat
->ports
[reg
];
996 case OMAP_DISPLAY_TYPE_DPI
:
997 dpi_uninit_port(port
);
999 case OMAP_DISPLAY_TYPE_SDI
:
1000 sdi_uninit_port(port
);
1005 } while ((port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
1008 static int dss_video_pll_probe(struct platform_device
*pdev
)
1010 struct device_node
*np
= pdev
->dev
.of_node
;
1011 struct regulator
*pll_regulator
;
1017 if (of_property_read_bool(np
, "syscon-pll-ctrl")) {
1018 dss
.syscon_pll_ctrl
= syscon_regmap_lookup_by_phandle(np
,
1020 if (IS_ERR(dss
.syscon_pll_ctrl
)) {
1022 "failed to get syscon-pll-ctrl regmap\n");
1023 return PTR_ERR(dss
.syscon_pll_ctrl
);
1026 if (of_property_read_u32_index(np
, "syscon-pll-ctrl", 1,
1027 &dss
.syscon_pll_ctrl_offset
)) {
1029 "failed to get syscon-pll-ctrl offset\n");
1034 pll_regulator
= devm_regulator_get(&pdev
->dev
, "vdda_video");
1035 if (IS_ERR(pll_regulator
)) {
1036 r
= PTR_ERR(pll_regulator
);
1040 pll_regulator
= NULL
;
1044 return -EPROBE_DEFER
;
1047 DSSERR("can't get DPLL VDDA regulator\n");
1052 if (of_property_match_string(np
, "reg-names", "pll1") >= 0) {
1053 dss
.video1_pll
= dss_video_pll_init(pdev
, 0, pll_regulator
);
1054 if (IS_ERR(dss
.video1_pll
))
1055 return PTR_ERR(dss
.video1_pll
);
1058 if (of_property_match_string(np
, "reg-names", "pll2") >= 0) {
1059 dss
.video2_pll
= dss_video_pll_init(pdev
, 1, pll_regulator
);
1060 if (IS_ERR(dss
.video2_pll
)) {
1061 dss_video_pll_uninit(dss
.video1_pll
);
1062 return PTR_ERR(dss
.video2_pll
);
1069 /* DSS HW IP initialisation */
1070 static int dss_bind(struct device
*dev
)
1072 struct platform_device
*pdev
= to_platform_device(dev
);
1073 struct resource
*dss_mem
;
1079 dss
.feat
= dss_get_features();
1083 dss_mem
= platform_get_resource(dss
.pdev
, IORESOURCE_MEM
, 0);
1085 DSSERR("can't get IORESOURCE_MEM DSS\n");
1089 dss
.base
= devm_ioremap(&pdev
->dev
, dss_mem
->start
,
1090 resource_size(dss_mem
));
1092 DSSERR("can't ioremap DSS\n");
1096 r
= dss_get_clocks();
1100 r
= dss_setup_default_clock();
1102 goto err_setup_clocks
;
1104 r
= dss_video_pll_probe(pdev
);
1108 r
= dss_init_ports(pdev
);
1110 goto err_init_ports
;
1112 pm_runtime_enable(&pdev
->dev
);
1114 r
= dss_runtime_get();
1116 goto err_runtime_get
;
1118 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
1121 REG_FLD_MOD(DSS_CONTROL
, 0, 0, 0);
1123 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK
);
1125 #ifdef CONFIG_FB_OMAP2_DSS_VENC
1126 REG_FLD_MOD(DSS_CONTROL
, 1, 4, 4); /* venc dac demen */
1127 REG_FLD_MOD(DSS_CONTROL
, 1, 3, 3); /* venc clock 4x enable */
1128 REG_FLD_MOD(DSS_CONTROL
, 0, 2, 2); /* venc clock mode = normal */
1130 dss
.dsi_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1131 dss
.dsi_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1132 dss
.dispc_clk_source
= OMAP_DSS_CLK_SRC_FCK
;
1133 dss
.lcd_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1134 dss
.lcd_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1136 rev
= dss_read_reg(DSS_REVISION
);
1137 printk(KERN_INFO
"OMAP DSS rev %d.%d\n",
1138 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
1142 r
= component_bind_all(&pdev
->dev
, NULL
);
1146 dss_debugfs_create_file("dss", dss_dump_regs
);
1148 pm_set_vt_switch(0);
1150 dss_initialized
= true;
1156 pm_runtime_disable(&pdev
->dev
);
1157 dss_uninit_ports(pdev
);
1160 dss_video_pll_uninit(dss
.video1_pll
);
1163 dss_video_pll_uninit(dss
.video2_pll
);
1170 static void dss_unbind(struct device
*dev
)
1172 struct platform_device
*pdev
= to_platform_device(dev
);
1174 dss_initialized
= false;
1176 component_unbind_all(&pdev
->dev
, NULL
);
1179 dss_video_pll_uninit(dss
.video1_pll
);
1182 dss_video_pll_uninit(dss
.video2_pll
);
1184 dss_uninit_ports(pdev
);
1186 pm_runtime_disable(&pdev
->dev
);
1191 static const struct component_master_ops dss_component_ops
= {
1193 .unbind
= dss_unbind
,
1196 static int dss_component_compare(struct device
*dev
, void *data
)
1198 struct device
*child
= data
;
1199 return dev
== child
;
1202 static int dss_add_child_component(struct device
*dev
, void *data
)
1204 struct component_match
**match
= data
;
1208 * We don't have a working driver for rfbi, so skip it here always.
1209 * Otherwise dss will never get probed successfully, as it will wait
1210 * for rfbi to get probed.
1212 if (strstr(dev_name(dev
), "rfbi"))
1215 component_match_add(dev
->parent
, match
, dss_component_compare
, dev
);
1220 static int dss_probe(struct platform_device
*pdev
)
1222 struct component_match
*match
= NULL
;
1225 /* add all the child devices as components */
1226 device_for_each_child(&pdev
->dev
, &match
, dss_add_child_component
);
1228 r
= component_master_add_with_match(&pdev
->dev
, &dss_component_ops
, match
);
1235 static int dss_remove(struct platform_device
*pdev
)
1237 component_master_del(&pdev
->dev
, &dss_component_ops
);
1241 static int dss_runtime_suspend(struct device
*dev
)
1244 dss_set_min_bus_tput(dev
, 0);
1246 pinctrl_pm_select_sleep_state(dev
);
1251 static int dss_runtime_resume(struct device
*dev
)
1255 pinctrl_pm_select_default_state(dev
);
1258 * Set an arbitrarily high tput request to ensure OPP100.
1259 * What we should really do is to make a request to stay in OPP100,
1260 * without any tput requirements, but that is not currently possible
1264 r
= dss_set_min_bus_tput(dev
, 1000000000);
1268 dss_restore_context();
1272 static const struct dev_pm_ops dss_pm_ops
= {
1273 .runtime_suspend
= dss_runtime_suspend
,
1274 .runtime_resume
= dss_runtime_resume
,
1277 static const struct of_device_id dss_of_match
[] = {
1278 { .compatible
= "ti,omap2-dss", },
1279 { .compatible
= "ti,omap3-dss", },
1280 { .compatible
= "ti,omap4-dss", },
1281 { .compatible
= "ti,omap5-dss", },
1282 { .compatible
= "ti,dra7-dss", },
1286 MODULE_DEVICE_TABLE(of
, dss_of_match
);
1288 static struct platform_driver omap_dsshw_driver
= {
1290 .remove
= dss_remove
,
1292 .name
= "omapdss_dss",
1294 .of_match_table
= dss_of_match
,
1295 .suppress_bind_attrs
= true,
1299 int __init
dss_init_platform_driver(void)
1301 return platform_driver_register(&omap_dsshw_driver
);
1304 void dss_uninit_platform_driver(void)
1306 platform_driver_unregister(&omap_dsshw_driver
);