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/of_graph.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/suspend.h>
32 #include <linux/component.h>
33 #include <linux/pinctrl/consumer.h>
35 #include <video/omapfb_dss.h>
38 #include "dss_features.h"
40 #define DSS_SZ_REGS SZ_512
46 #define DSS_REG(idx) ((const struct dss_reg) { idx })
48 #define DSS_REVISION DSS_REG(0x0000)
49 #define DSS_SYSCONFIG DSS_REG(0x0010)
50 #define DSS_SYSSTATUS DSS_REG(0x0014)
51 #define DSS_CONTROL DSS_REG(0x0040)
52 #define DSS_SDI_CONTROL DSS_REG(0x0044)
53 #define DSS_PLL_CONTROL DSS_REG(0x0048)
54 #define DSS_SDI_STATUS DSS_REG(0x005C)
56 #define REG_GET(idx, start, end) \
57 FLD_GET(dss_read_reg(idx), start, end)
59 #define REG_FLD_MOD(idx, val, start, end) \
60 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
64 u8 dss_fck_multiplier
;
65 const char *parent_clk_name
;
66 const enum omap_display_type
*ports
;
68 int (*dpi_select_source
)(int port
, enum omap_channel channel
);
72 struct platform_device
*pdev
;
74 struct regmap
*syscon_pll_ctrl
;
75 u32 syscon_pll_ctrl_offset
;
77 struct clk
*parent_clk
;
79 unsigned long dss_clk_rate
;
81 unsigned long cache_req_pck
;
82 unsigned long cache_prate
;
83 struct dispc_clock_info cache_dispc_cinfo
;
85 enum omap_dss_clk_source dsi_clk_source
[MAX_NUM_DSI
];
86 enum omap_dss_clk_source dispc_clk_source
;
87 enum omap_dss_clk_source lcd_clk_source
[MAX_DSS_LCD_MANAGERS
];
90 u32 ctx
[DSS_SZ_REGS
/ sizeof(u32
)];
92 const struct dss_features
*feat
;
94 struct dss_pll
*video1_pll
;
95 struct dss_pll
*video2_pll
;
98 static const char * const dss_generic_clk_source_names
[] = {
99 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
] = "DSI_PLL_HSDIV_DISPC",
100 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
] = "DSI_PLL_HSDIV_DSI",
101 [OMAP_DSS_CLK_SRC_FCK
] = "DSS_FCK",
102 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
] = "DSI_PLL2_HSDIV_DISPC",
103 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
] = "DSI_PLL2_HSDIV_DSI",
106 static bool dss_initialized
;
108 bool omapdss_is_initialized(void)
110 return dss_initialized
;
112 EXPORT_SYMBOL(omapdss_is_initialized
);
114 static inline void dss_write_reg(const struct dss_reg idx
, u32 val
)
116 __raw_writel(val
, dss
.base
+ idx
.idx
);
119 static inline u32
dss_read_reg(const struct dss_reg idx
)
121 return __raw_readl(dss
.base
+ idx
.idx
);
125 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
127 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
129 static void dss_save_context(void)
131 DSSDBG("dss_save_context\n");
135 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
136 OMAP_DISPLAY_TYPE_SDI
) {
141 dss
.ctx_valid
= true;
143 DSSDBG("context saved\n");
146 static void dss_restore_context(void)
148 DSSDBG("dss_restore_context\n");
155 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
156 OMAP_DISPLAY_TYPE_SDI
) {
161 DSSDBG("context restored\n");
167 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
)
172 if (!dss
.syscon_pll_ctrl
)
188 DSSERR("illegal DSS PLL ID %d\n", pll_id
);
192 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
193 1 << shift
, val
<< shift
);
196 void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id
,
197 enum omap_channel channel
)
201 if (!dss
.syscon_pll_ctrl
)
205 case OMAP_DSS_CHANNEL_LCD
:
214 DSSERR("error in PLL mux config for LCD\n");
219 case OMAP_DSS_CHANNEL_LCD2
:
230 DSSERR("error in PLL mux config for LCD2\n");
235 case OMAP_DSS_CHANNEL_LCD3
:
246 DSSERR("error in PLL mux config for LCD3\n");
252 DSSERR("error in PLL mux config\n");
256 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
257 0x3 << shift
, val
<< shift
);
260 void dss_sdi_init(int datapairs
)
264 BUG_ON(datapairs
> 3 || datapairs
< 1);
266 l
= dss_read_reg(DSS_SDI_CONTROL
);
267 l
= FLD_MOD(l
, 0xf, 19, 15); /* SDI_PDIV */
268 l
= FLD_MOD(l
, datapairs
-1, 3, 2); /* SDI_PRSEL */
269 l
= FLD_MOD(l
, 2, 1, 0); /* SDI_BWSEL */
270 dss_write_reg(DSS_SDI_CONTROL
, l
);
272 l
= dss_read_reg(DSS_PLL_CONTROL
);
273 l
= FLD_MOD(l
, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
274 l
= FLD_MOD(l
, 0xb, 16, 11); /* SDI_PLL_REGN */
275 l
= FLD_MOD(l
, 0xb4, 10, 1); /* SDI_PLL_REGM */
276 dss_write_reg(DSS_PLL_CONTROL
, l
);
279 int dss_sdi_enable(void)
281 unsigned long timeout
;
283 dispc_pck_free_enable(1);
286 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 18, 18); /* SDI_PLL_SYSRESET */
287 udelay(1); /* wait 2x PCLK */
290 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 28, 28); /* SDI_PLL_GOBIT */
292 /* Waiting for PLL lock request to complete */
293 timeout
= jiffies
+ msecs_to_jiffies(500);
294 while (dss_read_reg(DSS_SDI_STATUS
) & (1 << 6)) {
295 if (time_after_eq(jiffies
, timeout
)) {
296 DSSERR("PLL lock request timed out\n");
301 /* Clearing PLL_GO bit */
302 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 28, 28);
304 /* Waiting for PLL to lock */
305 timeout
= jiffies
+ msecs_to_jiffies(500);
306 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 5))) {
307 if (time_after_eq(jiffies
, timeout
)) {
308 DSSERR("PLL lock timed out\n");
313 dispc_lcd_enable_signal(1);
315 /* Waiting for SDI reset to complete */
316 timeout
= jiffies
+ msecs_to_jiffies(500);
317 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 2))) {
318 if (time_after_eq(jiffies
, timeout
)) {
319 DSSERR("SDI reset timed out\n");
327 dispc_lcd_enable_signal(0);
330 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
332 dispc_pck_free_enable(0);
337 void dss_sdi_disable(void)
339 dispc_lcd_enable_signal(0);
341 dispc_pck_free_enable(0);
344 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
347 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src
)
349 return dss_generic_clk_source_names
[clk_src
];
352 void dss_dump_clocks(struct seq_file
*s
)
354 const char *fclk_name
, *fclk_real_name
;
355 unsigned long fclk_rate
;
357 if (dss_runtime_get())
360 seq_printf(s
, "- DSS -\n");
362 fclk_name
= dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
363 fclk_real_name
= dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
364 fclk_rate
= clk_get_rate(dss
.dss_clk
);
366 seq_printf(s
, "%s (%s) = %lu\n",
367 fclk_name
, fclk_real_name
,
373 static void dss_dump_regs(struct seq_file
*s
)
375 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
377 if (dss_runtime_get())
380 DUMPREG(DSS_REVISION
);
381 DUMPREG(DSS_SYSCONFIG
);
382 DUMPREG(DSS_SYSSTATUS
);
383 DUMPREG(DSS_CONTROL
);
385 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
386 OMAP_DISPLAY_TYPE_SDI
) {
387 DUMPREG(DSS_SDI_CONTROL
);
388 DUMPREG(DSS_PLL_CONTROL
);
389 DUMPREG(DSS_SDI_STATUS
);
396 static void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src
)
402 case OMAP_DSS_CLK_SRC_FCK
:
405 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
408 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
416 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH
, &start
, &end
);
418 REG_FLD_MOD(DSS_CONTROL
, b
, start
, end
); /* DISPC_CLK_SWITCH */
420 dss
.dispc_clk_source
= clk_src
;
423 void dss_select_dsi_clk_source(int dsi_module
,
424 enum omap_dss_clk_source clk_src
)
429 case OMAP_DSS_CLK_SRC_FCK
:
432 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
:
433 BUG_ON(dsi_module
!= 0);
436 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
:
437 BUG_ON(dsi_module
!= 1);
445 pos
= dsi_module
== 0 ? 1 : 10;
446 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* DSIx_CLK_SWITCH */
448 dss
.dsi_clk_source
[dsi_module
] = clk_src
;
451 void dss_select_lcd_clk_source(enum omap_channel channel
,
452 enum omap_dss_clk_source clk_src
)
456 if (!dss_has_feature(FEAT_LCD_CLK_SRC
)) {
457 dss_select_dispc_clk_source(clk_src
);
462 case OMAP_DSS_CLK_SRC_FCK
:
465 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
466 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD
);
469 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
470 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD2
&&
471 channel
!= OMAP_DSS_CHANNEL_LCD3
);
479 pos
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
480 (channel
== OMAP_DSS_CHANNEL_LCD2
? 12 : 19);
481 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* LCDx_CLK_SWITCH */
483 ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
484 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
485 dss
.lcd_clk_source
[ix
] = clk_src
;
488 enum omap_dss_clk_source
dss_get_dispc_clk_source(void)
490 return dss
.dispc_clk_source
;
493 enum omap_dss_clk_source
dss_get_dsi_clk_source(int dsi_module
)
495 return dss
.dsi_clk_source
[dsi_module
];
498 enum omap_dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
)
500 if (dss_has_feature(FEAT_LCD_CLK_SRC
)) {
501 int ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
502 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
503 return dss
.lcd_clk_source
[ix
];
505 /* LCD_CLK source is the same as DISPC_FCLK source for
507 return dss
.dispc_clk_source
;
511 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
512 dss_div_calc_func func
, void *data
)
514 int fckd
, fckd_start
, fckd_stop
;
516 unsigned long fck_hw_max
;
517 unsigned long fckd_hw_max
;
521 fck_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
523 if (dss
.parent_clk
== NULL
) {
526 pckd
= fck_hw_max
/ pck
;
530 fck
= clk_round_rate(dss
.dss_clk
, fck
);
532 return func(fck
, data
);
535 fckd_hw_max
= dss
.feat
->fck_div_max
;
537 m
= dss
.feat
->dss_fck_multiplier
;
538 prate
= clk_get_rate(dss
.parent_clk
);
540 fck_min
= fck_min
? fck_min
: 1;
542 fckd_start
= min(prate
* m
/ fck_min
, fckd_hw_max
);
543 fckd_stop
= max(DIV_ROUND_UP(prate
* m
, fck_hw_max
), 1ul);
545 for (fckd
= fckd_start
; fckd
>= fckd_stop
; --fckd
) {
546 fck
= DIV_ROUND_UP(prate
, fckd
) * m
;
555 int dss_set_fck_rate(unsigned long rate
)
559 DSSDBG("set fck to %lu\n", rate
);
561 r
= clk_set_rate(dss
.dss_clk
, rate
);
565 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
567 WARN_ONCE(dss
.dss_clk_rate
!= rate
,
568 "clk rate mismatch: %lu != %lu", dss
.dss_clk_rate
,
574 unsigned long dss_get_dispc_clk_rate(void)
576 return dss
.dss_clk_rate
;
579 static int dss_setup_default_clock(void)
581 unsigned long max_dss_fck
, prate
;
586 max_dss_fck
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
588 if (dss
.parent_clk
== NULL
) {
589 fck
= clk_round_rate(dss
.dss_clk
, max_dss_fck
);
591 prate
= clk_get_rate(dss
.parent_clk
);
593 fck_div
= DIV_ROUND_UP(prate
* dss
.feat
->dss_fck_multiplier
,
595 fck
= DIV_ROUND_UP(prate
, fck_div
) * dss
.feat
->dss_fck_multiplier
;
598 r
= dss_set_fck_rate(fck
);
605 void dss_set_venc_output(enum omap_dss_venc_type type
)
609 if (type
== OMAP_DSS_VENC_TYPE_COMPOSITE
)
611 else if (type
== OMAP_DSS_VENC_TYPE_SVIDEO
)
616 /* venc out selection. 0 = comp, 1 = svideo */
617 REG_FLD_MOD(DSS_CONTROL
, l
, 6, 6);
620 void dss_set_dac_pwrdn_bgz(bool enable
)
622 REG_FLD_MOD(DSS_CONTROL
, enable
, 5, 5); /* DAC Power-Down Control */
625 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src
)
627 enum omap_display_type dp
;
628 dp
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
630 /* Complain about invalid selections */
631 WARN_ON((src
== DSS_VENC_TV_CLK
) && !(dp
& OMAP_DISPLAY_TYPE_VENC
));
632 WARN_ON((src
== DSS_HDMI_M_PCLK
) && !(dp
& OMAP_DISPLAY_TYPE_HDMI
));
634 /* Select only if we have options */
635 if ((dp
& OMAP_DISPLAY_TYPE_VENC
) && (dp
& OMAP_DISPLAY_TYPE_HDMI
))
636 REG_FLD_MOD(DSS_CONTROL
, src
, 15, 15); /* VENC_HDMI_SWITCH */
639 enum dss_hdmi_venc_clk_source_select
dss_get_hdmi_venc_clk_source(void)
641 enum omap_display_type displays
;
643 displays
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
644 if ((displays
& OMAP_DISPLAY_TYPE_HDMI
) == 0)
645 return DSS_VENC_TV_CLK
;
647 if ((displays
& OMAP_DISPLAY_TYPE_VENC
) == 0)
648 return DSS_HDMI_M_PCLK
;
650 return REG_GET(DSS_CONTROL
, 15, 15);
653 static int dss_dpi_select_source_omap2_omap3(int port
, enum omap_channel channel
)
655 if (channel
!= OMAP_DSS_CHANNEL_LCD
)
661 static int dss_dpi_select_source_omap4(int port
, enum omap_channel channel
)
666 case OMAP_DSS_CHANNEL_LCD2
:
669 case OMAP_DSS_CHANNEL_DIGIT
:
676 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 17);
681 static int dss_dpi_select_source_omap5(int port
, enum omap_channel channel
)
686 case OMAP_DSS_CHANNEL_LCD
:
689 case OMAP_DSS_CHANNEL_LCD2
:
692 case OMAP_DSS_CHANNEL_LCD3
:
695 case OMAP_DSS_CHANNEL_DIGIT
:
702 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 16);
707 static int dss_dpi_select_source_dra7xx(int port
, enum omap_channel channel
)
711 return dss_dpi_select_source_omap5(port
, channel
);
713 if (channel
!= OMAP_DSS_CHANNEL_LCD2
)
717 if (channel
!= OMAP_DSS_CHANNEL_LCD3
)
727 int dss_dpi_select_source(int port
, enum omap_channel channel
)
729 return dss
.feat
->dpi_select_source(port
, channel
);
732 static int dss_get_clocks(void)
736 clk
= devm_clk_get(&dss
.pdev
->dev
, "fck");
738 DSSERR("can't get clock fck\n");
744 if (dss
.feat
->parent_clk_name
) {
745 clk
= clk_get(NULL
, dss
.feat
->parent_clk_name
);
747 DSSERR("Failed to get %s\n", dss
.feat
->parent_clk_name
);
754 dss
.parent_clk
= clk
;
759 static void dss_put_clocks(void)
762 clk_put(dss
.parent_clk
);
765 int dss_runtime_get(void)
769 DSSDBG("dss_runtime_get\n");
771 r
= pm_runtime_resume_and_get(&dss
.pdev
->dev
);
777 void dss_runtime_put(void)
781 DSSDBG("dss_runtime_put\n");
783 r
= pm_runtime_put_sync(&dss
.pdev
->dev
);
784 WARN_ON(r
< 0 && r
!= -ENOSYS
&& r
!= -EBUSY
);
788 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
789 void dss_debug_dump_clocks(struct seq_file
*s
)
792 dispc_dump_clocks(s
);
793 #ifdef CONFIG_FB_OMAP2_DSS_DSI
800 static const enum omap_display_type omap2plus_ports
[] = {
801 OMAP_DISPLAY_TYPE_DPI
,
804 static const enum omap_display_type omap34xx_ports
[] = {
805 OMAP_DISPLAY_TYPE_DPI
,
806 OMAP_DISPLAY_TYPE_SDI
,
809 static const enum omap_display_type dra7xx_ports
[] = {
810 OMAP_DISPLAY_TYPE_DPI
,
811 OMAP_DISPLAY_TYPE_DPI
,
812 OMAP_DISPLAY_TYPE_DPI
,
815 static const struct dss_features omap24xx_dss_feats
= {
817 * fck div max is really 16, but the divider range has gaps. The range
818 * from 1 to 6 has no gaps, so let's use that as a max.
821 .dss_fck_multiplier
= 2,
822 .parent_clk_name
= "core_ck",
823 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
824 .ports
= omap2plus_ports
,
825 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
828 static const struct dss_features omap34xx_dss_feats
= {
830 .dss_fck_multiplier
= 2,
831 .parent_clk_name
= "dpll4_ck",
832 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
833 .ports
= omap34xx_ports
,
834 .num_ports
= ARRAY_SIZE(omap34xx_ports
),
837 static const struct dss_features omap3630_dss_feats
= {
839 .dss_fck_multiplier
= 1,
840 .parent_clk_name
= "dpll4_ck",
841 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
842 .ports
= omap2plus_ports
,
843 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
846 static const struct dss_features omap44xx_dss_feats
= {
848 .dss_fck_multiplier
= 1,
849 .parent_clk_name
= "dpll_per_x2_ck",
850 .dpi_select_source
= &dss_dpi_select_source_omap4
,
851 .ports
= omap2plus_ports
,
852 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
855 static const struct dss_features omap54xx_dss_feats
= {
857 .dss_fck_multiplier
= 1,
858 .parent_clk_name
= "dpll_per_x2_ck",
859 .dpi_select_source
= &dss_dpi_select_source_omap5
,
860 .ports
= omap2plus_ports
,
861 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
864 static const struct dss_features am43xx_dss_feats
= {
866 .dss_fck_multiplier
= 0,
867 .parent_clk_name
= NULL
,
868 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
869 .ports
= omap2plus_ports
,
870 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
873 static const struct dss_features dra7xx_dss_feats
= {
875 .dss_fck_multiplier
= 1,
876 .parent_clk_name
= "dpll_per_x2_ck",
877 .dpi_select_source
= &dss_dpi_select_source_dra7xx
,
878 .ports
= dra7xx_ports
,
879 .num_ports
= ARRAY_SIZE(dra7xx_ports
),
882 static const struct dss_features
*dss_get_features(void)
884 switch (omapdss_get_version()) {
885 case OMAPDSS_VER_OMAP24xx
:
886 return &omap24xx_dss_feats
;
888 case OMAPDSS_VER_OMAP34xx_ES1
:
889 case OMAPDSS_VER_OMAP34xx_ES3
:
890 case OMAPDSS_VER_AM35xx
:
891 return &omap34xx_dss_feats
;
893 case OMAPDSS_VER_OMAP3630
:
894 return &omap3630_dss_feats
;
896 case OMAPDSS_VER_OMAP4430_ES1
:
897 case OMAPDSS_VER_OMAP4430_ES2
:
898 case OMAPDSS_VER_OMAP4
:
899 return &omap44xx_dss_feats
;
901 case OMAPDSS_VER_OMAP5
:
902 return &omap54xx_dss_feats
;
904 case OMAPDSS_VER_AM43xx
:
905 return &am43xx_dss_feats
;
907 case OMAPDSS_VER_DRA7xx
:
908 return &dra7xx_dss_feats
;
915 static void dss_uninit_ports(struct platform_device
*pdev
);
917 static int dss_init_ports(struct platform_device
*pdev
)
919 struct device_node
*parent
= pdev
->dev
.of_node
;
920 struct device_node
*port
;
923 port
= of_graph_get_next_port(parent
, NULL
);
927 if (dss
.feat
->num_ports
== 0)
931 enum omap_display_type port_type
;
934 r
= of_property_read_u32(port
, "reg", ®
);
938 if (reg
>= dss
.feat
->num_ports
)
941 port_type
= dss
.feat
->ports
[reg
];
944 case OMAP_DISPLAY_TYPE_DPI
:
945 ret
= dpi_init_port(pdev
, port
);
947 case OMAP_DISPLAY_TYPE_SDI
:
948 ret
= sdi_init_port(pdev
, port
);
954 port
= of_graph_get_next_port(parent
, port
);
955 } while (!ret
&& port
);
958 dss_uninit_ports(pdev
);
963 static void dss_uninit_ports(struct platform_device
*pdev
)
965 struct device_node
*parent
= pdev
->dev
.of_node
;
966 struct device_node
*port
;
968 port
= of_graph_get_next_port(parent
, NULL
);
972 if (dss
.feat
->num_ports
== 0)
976 enum omap_display_type port_type
;
980 r
= of_property_read_u32(port
, "reg", ®
);
984 if (reg
>= dss
.feat
->num_ports
)
987 port_type
= dss
.feat
->ports
[reg
];
990 case OMAP_DISPLAY_TYPE_DPI
:
991 dpi_uninit_port(port
);
993 case OMAP_DISPLAY_TYPE_SDI
:
994 sdi_uninit_port(port
);
1000 port
= of_graph_get_next_port(parent
, port
);
1004 static int dss_video_pll_probe(struct platform_device
*pdev
)
1006 struct device_node
*np
= pdev
->dev
.of_node
;
1007 struct regulator
*pll_regulator
;
1013 if (of_property_read_bool(np
, "syscon-pll-ctrl")) {
1014 dss
.syscon_pll_ctrl
= syscon_regmap_lookup_by_phandle(np
,
1016 if (IS_ERR(dss
.syscon_pll_ctrl
)) {
1018 "failed to get syscon-pll-ctrl regmap\n");
1019 return PTR_ERR(dss
.syscon_pll_ctrl
);
1022 if (of_property_read_u32_index(np
, "syscon-pll-ctrl", 1,
1023 &dss
.syscon_pll_ctrl_offset
)) {
1025 "failed to get syscon-pll-ctrl offset\n");
1030 pll_regulator
= devm_regulator_get(&pdev
->dev
, "vdda_video");
1031 if (IS_ERR(pll_regulator
)) {
1032 r
= PTR_ERR(pll_regulator
);
1036 pll_regulator
= NULL
;
1040 return -EPROBE_DEFER
;
1043 DSSERR("can't get DPLL VDDA regulator\n");
1048 if (of_property_match_string(np
, "reg-names", "pll1") >= 0) {
1049 dss
.video1_pll
= dss_video_pll_init(pdev
, 0, pll_regulator
);
1050 if (IS_ERR(dss
.video1_pll
))
1051 return PTR_ERR(dss
.video1_pll
);
1054 if (of_property_match_string(np
, "reg-names", "pll2") >= 0) {
1055 dss
.video2_pll
= dss_video_pll_init(pdev
, 1, pll_regulator
);
1056 if (IS_ERR(dss
.video2_pll
)) {
1057 dss_video_pll_uninit(dss
.video1_pll
);
1058 return PTR_ERR(dss
.video2_pll
);
1065 /* DSS HW IP initialisation */
1066 static int dss_bind(struct device
*dev
)
1068 struct platform_device
*pdev
= to_platform_device(dev
);
1069 struct resource
*dss_mem
;
1075 dss
.feat
= dss_get_features();
1079 dss_mem
= platform_get_resource(dss
.pdev
, IORESOURCE_MEM
, 0);
1081 DSSERR("can't get IORESOURCE_MEM DSS\n");
1085 dss
.base
= devm_ioremap(&pdev
->dev
, dss_mem
->start
,
1086 resource_size(dss_mem
));
1088 DSSERR("can't ioremap DSS\n");
1092 r
= dss_get_clocks();
1096 r
= dss_setup_default_clock();
1098 goto err_setup_clocks
;
1100 r
= dss_video_pll_probe(pdev
);
1104 r
= dss_init_ports(pdev
);
1106 goto err_init_ports
;
1108 pm_runtime_enable(&pdev
->dev
);
1110 r
= dss_runtime_get();
1112 goto err_runtime_get
;
1114 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
1117 REG_FLD_MOD(DSS_CONTROL
, 0, 0, 0);
1119 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK
);
1121 #ifdef CONFIG_FB_OMAP2_DSS_VENC
1122 REG_FLD_MOD(DSS_CONTROL
, 1, 4, 4); /* venc dac demen */
1123 REG_FLD_MOD(DSS_CONTROL
, 1, 3, 3); /* venc clock 4x enable */
1124 REG_FLD_MOD(DSS_CONTROL
, 0, 2, 2); /* venc clock mode = normal */
1126 dss
.dsi_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1127 dss
.dsi_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1128 dss
.dispc_clk_source
= OMAP_DSS_CLK_SRC_FCK
;
1129 dss
.lcd_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1130 dss
.lcd_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1132 rev
= dss_read_reg(DSS_REVISION
);
1133 printk(KERN_INFO
"OMAP DSS rev %d.%d\n",
1134 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
1138 r
= component_bind_all(&pdev
->dev
, NULL
);
1142 dss_debugfs_create_file("dss", dss_dump_regs
);
1144 pm_set_vt_switch(0);
1146 dss_initialized
= true;
1152 pm_runtime_disable(&pdev
->dev
);
1153 dss_uninit_ports(pdev
);
1156 dss_video_pll_uninit(dss
.video1_pll
);
1159 dss_video_pll_uninit(dss
.video2_pll
);
1166 static void dss_unbind(struct device
*dev
)
1168 struct platform_device
*pdev
= to_platform_device(dev
);
1170 dss_initialized
= false;
1172 component_unbind_all(&pdev
->dev
, NULL
);
1175 dss_video_pll_uninit(dss
.video1_pll
);
1178 dss_video_pll_uninit(dss
.video2_pll
);
1180 dss_uninit_ports(pdev
);
1182 pm_runtime_disable(&pdev
->dev
);
1187 static const struct component_master_ops dss_component_ops
= {
1189 .unbind
= dss_unbind
,
1192 static int dss_add_child_component(struct device
*dev
, void *data
)
1194 struct component_match
**match
= data
;
1198 * We don't have a working driver for rfbi, so skip it here always.
1199 * Otherwise dss will never get probed successfully, as it will wait
1200 * for rfbi to get probed.
1202 if (strstr(dev_name(dev
), "rfbi"))
1205 component_match_add(dev
->parent
, match
, component_compare_dev
, dev
);
1210 static int dss_probe(struct platform_device
*pdev
)
1212 struct component_match
*match
= NULL
;
1215 /* add all the child devices as components */
1216 device_for_each_child(&pdev
->dev
, &match
, dss_add_child_component
);
1218 r
= component_master_add_with_match(&pdev
->dev
, &dss_component_ops
, match
);
1225 static void dss_remove(struct platform_device
*pdev
)
1227 component_master_del(&pdev
->dev
, &dss_component_ops
);
1230 static int dss_runtime_suspend(struct device
*dev
)
1233 dss_set_min_bus_tput(dev
, 0);
1235 pinctrl_pm_select_sleep_state(dev
);
1240 static int dss_runtime_resume(struct device
*dev
)
1244 pinctrl_pm_select_default_state(dev
);
1247 * Set an arbitrarily high tput request to ensure OPP100.
1248 * What we should really do is to make a request to stay in OPP100,
1249 * without any tput requirements, but that is not currently possible
1253 r
= dss_set_min_bus_tput(dev
, 1000000000);
1257 dss_restore_context();
1261 static const struct dev_pm_ops dss_pm_ops
= {
1262 .runtime_suspend
= dss_runtime_suspend
,
1263 .runtime_resume
= dss_runtime_resume
,
1266 static const struct of_device_id dss_of_match
[] = {
1267 { .compatible
= "ti,omap2-dss", },
1268 { .compatible
= "ti,omap3-dss", },
1269 { .compatible
= "ti,omap4-dss", },
1270 { .compatible
= "ti,omap5-dss", },
1271 { .compatible
= "ti,dra7-dss", },
1275 MODULE_DEVICE_TABLE(of
, dss_of_match
);
1277 static struct platform_driver omap_dsshw_driver
= {
1279 .remove
= dss_remove
,
1281 .name
= "omapdss_dss",
1283 .of_match_table
= dss_of_match
,
1284 .suppress_bind_attrs
= true,
1288 int __init
dss_init_platform_driver(void)
1290 return platform_driver_register(&omap_dsshw_driver
);
1293 void dss_uninit_platform_driver(void)
1295 platform_driver_unregister(&omap_dsshw_driver
);