2 * linux/drivers/video/omap2/dss/dss.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 "DSS"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
28 #include <linux/export.h>
29 #include <linux/err.h>
30 #include <linux/delay.h>
31 #include <linux/seq_file.h>
32 #include <linux/clk.h>
33 #include <linux/platform_device.h>
34 #include <linux/pm_runtime.h>
35 #include <linux/gfp.h>
36 #include <linux/sizes.h>
37 #include <linux/mfd/syscon.h>
38 #include <linux/regmap.h>
40 #include <linux/regulator/consumer.h>
41 #include <linux/suspend.h>
42 #include <linux/component.h>
44 #include <video/omapdss.h>
47 #include "dss_features.h"
49 #define DSS_SZ_REGS SZ_512
55 #define DSS_REG(idx) ((const struct dss_reg) { idx })
57 #define DSS_REVISION DSS_REG(0x0000)
58 #define DSS_SYSCONFIG DSS_REG(0x0010)
59 #define DSS_SYSSTATUS DSS_REG(0x0014)
60 #define DSS_CONTROL DSS_REG(0x0040)
61 #define DSS_SDI_CONTROL DSS_REG(0x0044)
62 #define DSS_PLL_CONTROL DSS_REG(0x0048)
63 #define DSS_SDI_STATUS DSS_REG(0x005C)
65 #define REG_GET(idx, start, end) \
66 FLD_GET(dss_read_reg(idx), start, end)
68 #define REG_FLD_MOD(idx, val, start, end) \
69 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
73 u8 dss_fck_multiplier
;
74 const char *parent_clk_name
;
75 const enum omap_display_type
*ports
;
77 int (*dpi_select_source
)(int port
, enum omap_channel channel
);
81 struct platform_device
*pdev
;
83 struct regmap
*syscon_pll_ctrl
;
84 u32 syscon_pll_ctrl_offset
;
86 struct clk
*parent_clk
;
88 unsigned long dss_clk_rate
;
90 unsigned long cache_req_pck
;
91 unsigned long cache_prate
;
92 struct dispc_clock_info cache_dispc_cinfo
;
94 enum omap_dss_clk_source dsi_clk_source
[MAX_NUM_DSI
];
95 enum omap_dss_clk_source dispc_clk_source
;
96 enum omap_dss_clk_source lcd_clk_source
[MAX_DSS_LCD_MANAGERS
];
99 u32 ctx
[DSS_SZ_REGS
/ sizeof(u32
)];
101 const struct dss_features
*feat
;
103 struct dss_pll
*video1_pll
;
104 struct dss_pll
*video2_pll
;
107 static const char * const dss_generic_clk_source_names
[] = {
108 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
] = "DSI_PLL_HSDIV_DISPC",
109 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
] = "DSI_PLL_HSDIV_DSI",
110 [OMAP_DSS_CLK_SRC_FCK
] = "DSS_FCK",
111 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
] = "DSI_PLL2_HSDIV_DISPC",
112 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
] = "DSI_PLL2_HSDIV_DSI",
115 static bool dss_initialized
;
117 bool omapdss_is_initialized(void)
119 return dss_initialized
;
121 EXPORT_SYMBOL(omapdss_is_initialized
);
123 static inline void dss_write_reg(const struct dss_reg idx
, u32 val
)
125 __raw_writel(val
, dss
.base
+ idx
.idx
);
128 static inline u32
dss_read_reg(const struct dss_reg idx
)
130 return __raw_readl(dss
.base
+ idx
.idx
);
134 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
136 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
138 static void dss_save_context(void)
140 DSSDBG("dss_save_context\n");
144 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
145 OMAP_DISPLAY_TYPE_SDI
) {
150 dss
.ctx_valid
= true;
152 DSSDBG("context saved\n");
155 static void dss_restore_context(void)
157 DSSDBG("dss_restore_context\n");
164 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
165 OMAP_DISPLAY_TYPE_SDI
) {
170 DSSDBG("context restored\n");
176 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
)
181 if (!dss
.syscon_pll_ctrl
)
197 DSSERR("illegal DSS PLL ID %d\n", pll_id
);
201 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
202 1 << shift
, val
<< shift
);
205 void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id
,
206 enum omap_channel channel
)
210 if (!dss
.syscon_pll_ctrl
)
214 case OMAP_DSS_CHANNEL_LCD
:
223 DSSERR("error in PLL mux config for LCD\n");
228 case OMAP_DSS_CHANNEL_LCD2
:
239 DSSERR("error in PLL mux config for LCD2\n");
244 case OMAP_DSS_CHANNEL_LCD3
:
255 DSSERR("error in PLL mux config for LCD3\n");
261 DSSERR("error in PLL mux config\n");
265 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
266 0x3 << shift
, val
<< shift
);
269 void dss_sdi_init(int datapairs
)
273 BUG_ON(datapairs
> 3 || datapairs
< 1);
275 l
= dss_read_reg(DSS_SDI_CONTROL
);
276 l
= FLD_MOD(l
, 0xf, 19, 15); /* SDI_PDIV */
277 l
= FLD_MOD(l
, datapairs
-1, 3, 2); /* SDI_PRSEL */
278 l
= FLD_MOD(l
, 2, 1, 0); /* SDI_BWSEL */
279 dss_write_reg(DSS_SDI_CONTROL
, l
);
281 l
= dss_read_reg(DSS_PLL_CONTROL
);
282 l
= FLD_MOD(l
, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
283 l
= FLD_MOD(l
, 0xb, 16, 11); /* SDI_PLL_REGN */
284 l
= FLD_MOD(l
, 0xb4, 10, 1); /* SDI_PLL_REGM */
285 dss_write_reg(DSS_PLL_CONTROL
, l
);
288 int dss_sdi_enable(void)
290 unsigned long timeout
;
292 dispc_pck_free_enable(1);
295 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 18, 18); /* SDI_PLL_SYSRESET */
296 udelay(1); /* wait 2x PCLK */
299 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 28, 28); /* SDI_PLL_GOBIT */
301 /* Waiting for PLL lock request to complete */
302 timeout
= jiffies
+ msecs_to_jiffies(500);
303 while (dss_read_reg(DSS_SDI_STATUS
) & (1 << 6)) {
304 if (time_after_eq(jiffies
, timeout
)) {
305 DSSERR("PLL lock request timed out\n");
310 /* Clearing PLL_GO bit */
311 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 28, 28);
313 /* Waiting for PLL to lock */
314 timeout
= jiffies
+ msecs_to_jiffies(500);
315 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 5))) {
316 if (time_after_eq(jiffies
, timeout
)) {
317 DSSERR("PLL lock timed out\n");
322 dispc_lcd_enable_signal(1);
324 /* Waiting for SDI reset to complete */
325 timeout
= jiffies
+ msecs_to_jiffies(500);
326 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 2))) {
327 if (time_after_eq(jiffies
, timeout
)) {
328 DSSERR("SDI reset timed out\n");
336 dispc_lcd_enable_signal(0);
339 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
341 dispc_pck_free_enable(0);
346 void dss_sdi_disable(void)
348 dispc_lcd_enable_signal(0);
350 dispc_pck_free_enable(0);
353 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
356 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src
)
358 return dss_generic_clk_source_names
[clk_src
];
361 void dss_dump_clocks(struct seq_file
*s
)
363 const char *fclk_name
, *fclk_real_name
;
364 unsigned long fclk_rate
;
366 if (dss_runtime_get())
369 seq_printf(s
, "- DSS -\n");
371 fclk_name
= dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
372 fclk_real_name
= dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
373 fclk_rate
= clk_get_rate(dss
.dss_clk
);
375 seq_printf(s
, "%s (%s) = %lu\n",
376 fclk_name
, fclk_real_name
,
382 static void dss_dump_regs(struct seq_file
*s
)
384 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
386 if (dss_runtime_get())
389 DUMPREG(DSS_REVISION
);
390 DUMPREG(DSS_SYSCONFIG
);
391 DUMPREG(DSS_SYSSTATUS
);
392 DUMPREG(DSS_CONTROL
);
394 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
395 OMAP_DISPLAY_TYPE_SDI
) {
396 DUMPREG(DSS_SDI_CONTROL
);
397 DUMPREG(DSS_PLL_CONTROL
);
398 DUMPREG(DSS_SDI_STATUS
);
405 static void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src
)
411 case OMAP_DSS_CLK_SRC_FCK
:
414 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
417 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
425 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH
, &start
, &end
);
427 REG_FLD_MOD(DSS_CONTROL
, b
, start
, end
); /* DISPC_CLK_SWITCH */
429 dss
.dispc_clk_source
= clk_src
;
432 void dss_select_dsi_clk_source(int dsi_module
,
433 enum omap_dss_clk_source clk_src
)
438 case OMAP_DSS_CLK_SRC_FCK
:
441 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
:
442 BUG_ON(dsi_module
!= 0);
445 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
:
446 BUG_ON(dsi_module
!= 1);
454 pos
= dsi_module
== 0 ? 1 : 10;
455 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* DSIx_CLK_SWITCH */
457 dss
.dsi_clk_source
[dsi_module
] = clk_src
;
460 void dss_select_lcd_clk_source(enum omap_channel channel
,
461 enum omap_dss_clk_source clk_src
)
465 if (!dss_has_feature(FEAT_LCD_CLK_SRC
)) {
466 dss_select_dispc_clk_source(clk_src
);
471 case OMAP_DSS_CLK_SRC_FCK
:
474 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
475 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD
);
478 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
479 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD2
&&
480 channel
!= OMAP_DSS_CHANNEL_LCD3
);
488 pos
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
489 (channel
== OMAP_DSS_CHANNEL_LCD2
? 12 : 19);
490 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* LCDx_CLK_SWITCH */
492 ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
493 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
494 dss
.lcd_clk_source
[ix
] = clk_src
;
497 enum omap_dss_clk_source
dss_get_dispc_clk_source(void)
499 return dss
.dispc_clk_source
;
502 enum omap_dss_clk_source
dss_get_dsi_clk_source(int dsi_module
)
504 return dss
.dsi_clk_source
[dsi_module
];
507 enum omap_dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
)
509 if (dss_has_feature(FEAT_LCD_CLK_SRC
)) {
510 int ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
511 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
512 return dss
.lcd_clk_source
[ix
];
514 /* LCD_CLK source is the same as DISPC_FCLK source for
516 return dss
.dispc_clk_source
;
520 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
521 dss_div_calc_func func
, void *data
)
523 int fckd
, fckd_start
, fckd_stop
;
525 unsigned long fck_hw_max
;
526 unsigned long fckd_hw_max
;
530 fck_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
532 if (dss
.parent_clk
== NULL
) {
535 pckd
= fck_hw_max
/ pck
;
539 fck
= clk_round_rate(dss
.dss_clk
, fck
);
541 return func(fck
, data
);
544 fckd_hw_max
= dss
.feat
->fck_div_max
;
546 m
= dss
.feat
->dss_fck_multiplier
;
547 prate
= clk_get_rate(dss
.parent_clk
);
549 fck_min
= fck_min
? fck_min
: 1;
551 fckd_start
= min(prate
* m
/ fck_min
, fckd_hw_max
);
552 fckd_stop
= max(DIV_ROUND_UP(prate
* m
, fck_hw_max
), 1ul);
554 for (fckd
= fckd_start
; fckd
>= fckd_stop
; --fckd
) {
555 fck
= DIV_ROUND_UP(prate
, fckd
) * m
;
564 int dss_set_fck_rate(unsigned long rate
)
568 DSSDBG("set fck to %lu\n", rate
);
570 r
= clk_set_rate(dss
.dss_clk
, rate
);
574 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
576 WARN_ONCE(dss
.dss_clk_rate
!= rate
,
577 "clk rate mismatch: %lu != %lu", dss
.dss_clk_rate
,
583 unsigned long dss_get_dispc_clk_rate(void)
585 return dss
.dss_clk_rate
;
588 static int dss_setup_default_clock(void)
590 unsigned long max_dss_fck
, prate
;
595 max_dss_fck
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
597 if (dss
.parent_clk
== NULL
) {
598 fck
= clk_round_rate(dss
.dss_clk
, max_dss_fck
);
600 prate
= clk_get_rate(dss
.parent_clk
);
602 fck_div
= DIV_ROUND_UP(prate
* dss
.feat
->dss_fck_multiplier
,
604 fck
= DIV_ROUND_UP(prate
, fck_div
) * dss
.feat
->dss_fck_multiplier
;
607 r
= dss_set_fck_rate(fck
);
614 void dss_set_venc_output(enum omap_dss_venc_type type
)
618 if (type
== OMAP_DSS_VENC_TYPE_COMPOSITE
)
620 else if (type
== OMAP_DSS_VENC_TYPE_SVIDEO
)
625 /* venc out selection. 0 = comp, 1 = svideo */
626 REG_FLD_MOD(DSS_CONTROL
, l
, 6, 6);
629 void dss_set_dac_pwrdn_bgz(bool enable
)
631 REG_FLD_MOD(DSS_CONTROL
, enable
, 5, 5); /* DAC Power-Down Control */
634 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src
)
636 enum omap_display_type dp
;
637 dp
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
639 /* Complain about invalid selections */
640 WARN_ON((src
== DSS_VENC_TV_CLK
) && !(dp
& OMAP_DISPLAY_TYPE_VENC
));
641 WARN_ON((src
== DSS_HDMI_M_PCLK
) && !(dp
& OMAP_DISPLAY_TYPE_HDMI
));
643 /* Select only if we have options */
644 if ((dp
& OMAP_DISPLAY_TYPE_VENC
) && (dp
& OMAP_DISPLAY_TYPE_HDMI
))
645 REG_FLD_MOD(DSS_CONTROL
, src
, 15, 15); /* VENC_HDMI_SWITCH */
648 enum dss_hdmi_venc_clk_source_select
dss_get_hdmi_venc_clk_source(void)
650 enum omap_display_type displays
;
652 displays
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
653 if ((displays
& OMAP_DISPLAY_TYPE_HDMI
) == 0)
654 return DSS_VENC_TV_CLK
;
656 if ((displays
& OMAP_DISPLAY_TYPE_VENC
) == 0)
657 return DSS_HDMI_M_PCLK
;
659 return REG_GET(DSS_CONTROL
, 15, 15);
662 static int dss_dpi_select_source_omap2_omap3(int port
, enum omap_channel channel
)
664 if (channel
!= OMAP_DSS_CHANNEL_LCD
)
670 static int dss_dpi_select_source_omap4(int port
, enum omap_channel channel
)
675 case OMAP_DSS_CHANNEL_LCD2
:
678 case OMAP_DSS_CHANNEL_DIGIT
:
685 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 17);
690 static int dss_dpi_select_source_omap5(int port
, enum omap_channel channel
)
695 case OMAP_DSS_CHANNEL_LCD
:
698 case OMAP_DSS_CHANNEL_LCD2
:
701 case OMAP_DSS_CHANNEL_LCD3
:
704 case OMAP_DSS_CHANNEL_DIGIT
:
711 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 16);
716 static int dss_dpi_select_source_dra7xx(int port
, enum omap_channel channel
)
720 return dss_dpi_select_source_omap5(port
, channel
);
722 if (channel
!= OMAP_DSS_CHANNEL_LCD2
)
726 if (channel
!= OMAP_DSS_CHANNEL_LCD3
)
736 int dss_dpi_select_source(int port
, enum omap_channel channel
)
738 return dss
.feat
->dpi_select_source(port
, channel
);
741 static int dss_get_clocks(void)
745 clk
= devm_clk_get(&dss
.pdev
->dev
, "fck");
747 DSSERR("can't get clock fck\n");
753 if (dss
.feat
->parent_clk_name
) {
754 clk
= clk_get(NULL
, dss
.feat
->parent_clk_name
);
756 DSSERR("Failed to get %s\n", dss
.feat
->parent_clk_name
);
763 dss
.parent_clk
= clk
;
768 static void dss_put_clocks(void)
771 clk_put(dss
.parent_clk
);
774 int dss_runtime_get(void)
778 DSSDBG("dss_runtime_get\n");
780 r
= pm_runtime_get_sync(&dss
.pdev
->dev
);
782 return r
< 0 ? r
: 0;
785 void dss_runtime_put(void)
789 DSSDBG("dss_runtime_put\n");
791 r
= pm_runtime_put_sync(&dss
.pdev
->dev
);
792 WARN_ON(r
< 0 && r
!= -ENOSYS
&& r
!= -EBUSY
);
796 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
797 void dss_debug_dump_clocks(struct seq_file
*s
)
800 dispc_dump_clocks(s
);
801 #ifdef CONFIG_FB_OMAP2_DSS_DSI
808 static const enum omap_display_type omap2plus_ports
[] = {
809 OMAP_DISPLAY_TYPE_DPI
,
812 static const enum omap_display_type omap34xx_ports
[] = {
813 OMAP_DISPLAY_TYPE_DPI
,
814 OMAP_DISPLAY_TYPE_SDI
,
817 static const enum omap_display_type dra7xx_ports
[] = {
818 OMAP_DISPLAY_TYPE_DPI
,
819 OMAP_DISPLAY_TYPE_DPI
,
820 OMAP_DISPLAY_TYPE_DPI
,
823 static const struct dss_features omap24xx_dss_feats
= {
825 * fck div max is really 16, but the divider range has gaps. The range
826 * from 1 to 6 has no gaps, so let's use that as a max.
829 .dss_fck_multiplier
= 2,
830 .parent_clk_name
= "core_ck",
831 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
832 .ports
= omap2plus_ports
,
833 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
836 static const struct dss_features omap34xx_dss_feats
= {
838 .dss_fck_multiplier
= 2,
839 .parent_clk_name
= "dpll4_ck",
840 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
841 .ports
= omap34xx_ports
,
842 .num_ports
= ARRAY_SIZE(omap34xx_ports
),
845 static const struct dss_features omap3630_dss_feats
= {
847 .dss_fck_multiplier
= 1,
848 .parent_clk_name
= "dpll4_ck",
849 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
850 .ports
= omap2plus_ports
,
851 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
854 static const struct dss_features omap44xx_dss_feats
= {
856 .dss_fck_multiplier
= 1,
857 .parent_clk_name
= "dpll_per_x2_ck",
858 .dpi_select_source
= &dss_dpi_select_source_omap4
,
859 .ports
= omap2plus_ports
,
860 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
863 static const struct dss_features omap54xx_dss_feats
= {
865 .dss_fck_multiplier
= 1,
866 .parent_clk_name
= "dpll_per_x2_ck",
867 .dpi_select_source
= &dss_dpi_select_source_omap5
,
868 .ports
= omap2plus_ports
,
869 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
872 static const struct dss_features am43xx_dss_feats
= {
874 .dss_fck_multiplier
= 0,
875 .parent_clk_name
= NULL
,
876 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
877 .ports
= omap2plus_ports
,
878 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
881 static const struct dss_features dra7xx_dss_feats
= {
883 .dss_fck_multiplier
= 1,
884 .parent_clk_name
= "dpll_per_x2_ck",
885 .dpi_select_source
= &dss_dpi_select_source_dra7xx
,
886 .ports
= dra7xx_ports
,
887 .num_ports
= ARRAY_SIZE(dra7xx_ports
),
890 static int dss_init_features(struct platform_device
*pdev
)
892 const struct dss_features
*src
;
893 struct dss_features
*dst
;
895 dst
= devm_kzalloc(&pdev
->dev
, sizeof(*dst
), GFP_KERNEL
);
897 dev_err(&pdev
->dev
, "Failed to allocate local DSS Features\n");
901 switch (omapdss_get_version()) {
902 case OMAPDSS_VER_OMAP24xx
:
903 src
= &omap24xx_dss_feats
;
906 case OMAPDSS_VER_OMAP34xx_ES1
:
907 case OMAPDSS_VER_OMAP34xx_ES3
:
908 case OMAPDSS_VER_AM35xx
:
909 src
= &omap34xx_dss_feats
;
912 case OMAPDSS_VER_OMAP3630
:
913 src
= &omap3630_dss_feats
;
916 case OMAPDSS_VER_OMAP4430_ES1
:
917 case OMAPDSS_VER_OMAP4430_ES2
:
918 case OMAPDSS_VER_OMAP4
:
919 src
= &omap44xx_dss_feats
;
922 case OMAPDSS_VER_OMAP5
:
923 src
= &omap54xx_dss_feats
;
926 case OMAPDSS_VER_AM43xx
:
927 src
= &am43xx_dss_feats
;
930 case OMAPDSS_VER_DRA7xx
:
931 src
= &dra7xx_dss_feats
;
938 memcpy(dst
, src
, sizeof(*dst
));
944 static int dss_init_ports(struct platform_device
*pdev
)
946 struct device_node
*parent
= pdev
->dev
.of_node
;
947 struct device_node
*port
;
953 port
= omapdss_of_get_next_port(parent
, NULL
);
957 if (dss
.feat
->num_ports
== 0)
961 enum omap_display_type port_type
;
964 r
= of_property_read_u32(port
, "reg", ®
);
968 if (reg
>= dss
.feat
->num_ports
)
971 port_type
= dss
.feat
->ports
[reg
];
974 case OMAP_DISPLAY_TYPE_DPI
:
975 dpi_init_port(pdev
, port
);
977 case OMAP_DISPLAY_TYPE_SDI
:
978 sdi_init_port(pdev
, port
);
983 } while ((port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
988 static void dss_uninit_ports(struct platform_device
*pdev
)
990 struct device_node
*parent
= pdev
->dev
.of_node
;
991 struct device_node
*port
;
996 port
= omapdss_of_get_next_port(parent
, NULL
);
1000 if (dss
.feat
->num_ports
== 0)
1004 enum omap_display_type port_type
;
1008 r
= of_property_read_u32(port
, "reg", ®
);
1012 if (reg
>= dss
.feat
->num_ports
)
1015 port_type
= dss
.feat
->ports
[reg
];
1017 switch (port_type
) {
1018 case OMAP_DISPLAY_TYPE_DPI
:
1019 dpi_uninit_port(port
);
1021 case OMAP_DISPLAY_TYPE_SDI
:
1022 sdi_uninit_port(port
);
1027 } while ((port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
1030 static int dss_video_pll_probe(struct platform_device
*pdev
)
1032 struct device_node
*np
= pdev
->dev
.of_node
;
1033 struct regulator
*pll_regulator
;
1039 if (of_property_read_bool(np
, "syscon-pll-ctrl")) {
1040 dss
.syscon_pll_ctrl
= syscon_regmap_lookup_by_phandle(np
,
1042 if (IS_ERR(dss
.syscon_pll_ctrl
)) {
1044 "failed to get syscon-pll-ctrl regmap\n");
1045 return PTR_ERR(dss
.syscon_pll_ctrl
);
1048 if (of_property_read_u32_index(np
, "syscon-pll-ctrl", 1,
1049 &dss
.syscon_pll_ctrl_offset
)) {
1051 "failed to get syscon-pll-ctrl offset\n");
1056 pll_regulator
= devm_regulator_get(&pdev
->dev
, "vdda_video");
1057 if (IS_ERR(pll_regulator
)) {
1058 r
= PTR_ERR(pll_regulator
);
1062 pll_regulator
= NULL
;
1066 return -EPROBE_DEFER
;
1069 DSSERR("can't get DPLL VDDA regulator\n");
1074 if (of_property_match_string(np
, "reg-names", "pll1") >= 0) {
1075 dss
.video1_pll
= dss_video_pll_init(pdev
, 0, pll_regulator
);
1076 if (IS_ERR(dss
.video1_pll
))
1077 return PTR_ERR(dss
.video1_pll
);
1080 if (of_property_match_string(np
, "reg-names", "pll2") >= 0) {
1081 dss
.video2_pll
= dss_video_pll_init(pdev
, 1, pll_regulator
);
1082 if (IS_ERR(dss
.video2_pll
)) {
1083 dss_video_pll_uninit(dss
.video1_pll
);
1084 return PTR_ERR(dss
.video2_pll
);
1091 /* DSS HW IP initialisation */
1092 static int dss_bind(struct device
*dev
)
1094 struct platform_device
*pdev
= to_platform_device(dev
);
1095 struct resource
*dss_mem
;
1101 r
= dss_init_features(dss
.pdev
);
1105 dss_mem
= platform_get_resource(dss
.pdev
, IORESOURCE_MEM
, 0);
1107 DSSERR("can't get IORESOURCE_MEM DSS\n");
1111 dss
.base
= devm_ioremap(&pdev
->dev
, dss_mem
->start
,
1112 resource_size(dss_mem
));
1114 DSSERR("can't ioremap DSS\n");
1118 r
= dss_get_clocks();
1122 r
= dss_setup_default_clock();
1124 goto err_setup_clocks
;
1126 r
= dss_video_pll_probe(pdev
);
1130 r
= dss_init_ports(pdev
);
1132 goto err_init_ports
;
1134 pm_runtime_enable(&pdev
->dev
);
1136 r
= dss_runtime_get();
1138 goto err_runtime_get
;
1140 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
1143 REG_FLD_MOD(DSS_CONTROL
, 0, 0, 0);
1145 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK
);
1147 #ifdef CONFIG_FB_OMAP2_DSS_VENC
1148 REG_FLD_MOD(DSS_CONTROL
, 1, 4, 4); /* venc dac demen */
1149 REG_FLD_MOD(DSS_CONTROL
, 1, 3, 3); /* venc clock 4x enable */
1150 REG_FLD_MOD(DSS_CONTROL
, 0, 2, 2); /* venc clock mode = normal */
1152 dss
.dsi_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1153 dss
.dsi_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1154 dss
.dispc_clk_source
= OMAP_DSS_CLK_SRC_FCK
;
1155 dss
.lcd_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1156 dss
.lcd_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1158 rev
= dss_read_reg(DSS_REVISION
);
1159 printk(KERN_INFO
"OMAP DSS rev %d.%d\n",
1160 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
1164 r
= component_bind_all(&pdev
->dev
, NULL
);
1168 dss_debugfs_create_file("dss", dss_dump_regs
);
1170 pm_set_vt_switch(0);
1172 dss_initialized
= true;
1178 pm_runtime_disable(&pdev
->dev
);
1179 dss_uninit_ports(pdev
);
1182 dss_video_pll_uninit(dss
.video1_pll
);
1185 dss_video_pll_uninit(dss
.video2_pll
);
1192 static void dss_unbind(struct device
*dev
)
1194 struct platform_device
*pdev
= to_platform_device(dev
);
1196 dss_initialized
= false;
1198 component_unbind_all(&pdev
->dev
, NULL
);
1201 dss_video_pll_uninit(dss
.video1_pll
);
1204 dss_video_pll_uninit(dss
.video2_pll
);
1206 dss_uninit_ports(pdev
);
1208 pm_runtime_disable(&pdev
->dev
);
1213 static const struct component_master_ops dss_component_ops
= {
1215 .unbind
= dss_unbind
,
1218 static int dss_component_compare(struct device
*dev
, void *data
)
1220 struct device
*child
= data
;
1221 return dev
== child
;
1224 static int dss_add_child_component(struct device
*dev
, void *data
)
1226 struct component_match
**match
= data
;
1230 * We don't have a working driver for rfbi, so skip it here always.
1231 * Otherwise dss will never get probed successfully, as it will wait
1232 * for rfbi to get probed.
1234 if (strstr(dev_name(dev
), "rfbi"))
1237 component_match_add(dev
->parent
, match
, dss_component_compare
, dev
);
1242 static int dss_probe(struct platform_device
*pdev
)
1244 struct component_match
*match
= NULL
;
1247 /* add all the child devices as components */
1248 device_for_each_child(&pdev
->dev
, &match
, dss_add_child_component
);
1250 r
= component_master_add_with_match(&pdev
->dev
, &dss_component_ops
, match
);
1257 static int dss_remove(struct platform_device
*pdev
)
1259 component_master_del(&pdev
->dev
, &dss_component_ops
);
1263 static int dss_runtime_suspend(struct device
*dev
)
1266 dss_set_min_bus_tput(dev
, 0);
1268 pinctrl_pm_select_sleep_state(dev
);
1273 static int dss_runtime_resume(struct device
*dev
)
1277 pinctrl_pm_select_default_state(dev
);
1280 * Set an arbitrarily high tput request to ensure OPP100.
1281 * What we should really do is to make a request to stay in OPP100,
1282 * without any tput requirements, but that is not currently possible
1286 r
= dss_set_min_bus_tput(dev
, 1000000000);
1290 dss_restore_context();
1294 static const struct dev_pm_ops dss_pm_ops
= {
1295 .runtime_suspend
= dss_runtime_suspend
,
1296 .runtime_resume
= dss_runtime_resume
,
1299 static const struct of_device_id dss_of_match
[] = {
1300 { .compatible
= "ti,omap2-dss", },
1301 { .compatible
= "ti,omap3-dss", },
1302 { .compatible
= "ti,omap4-dss", },
1303 { .compatible
= "ti,omap5-dss", },
1304 { .compatible
= "ti,dra7-dss", },
1308 MODULE_DEVICE_TABLE(of
, dss_of_match
);
1310 static struct platform_driver omap_dsshw_driver
= {
1312 .remove
= dss_remove
,
1314 .name
= "omapdss_dss",
1316 .of_match_table
= dss_of_match
,
1317 .suppress_bind_attrs
= true,
1321 int __init
dss_init_platform_driver(void)
1323 return platform_driver_register(&omap_dsshw_driver
);
1326 void dss_uninit_platform_driver(void)
1328 platform_driver_unregister(&omap_dsshw_driver
);