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>
43 #include <linux/pinctrl/consumer.h>
45 #include <video/omapfb_dss.h>
48 #include "dss_features.h"
50 #define DSS_SZ_REGS SZ_512
56 #define DSS_REG(idx) ((const struct dss_reg) { idx })
58 #define DSS_REVISION DSS_REG(0x0000)
59 #define DSS_SYSCONFIG DSS_REG(0x0010)
60 #define DSS_SYSSTATUS DSS_REG(0x0014)
61 #define DSS_CONTROL DSS_REG(0x0040)
62 #define DSS_SDI_CONTROL DSS_REG(0x0044)
63 #define DSS_PLL_CONTROL DSS_REG(0x0048)
64 #define DSS_SDI_STATUS DSS_REG(0x005C)
66 #define REG_GET(idx, start, end) \
67 FLD_GET(dss_read_reg(idx), start, end)
69 #define REG_FLD_MOD(idx, val, start, end) \
70 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
74 u8 dss_fck_multiplier
;
75 const char *parent_clk_name
;
76 const enum omap_display_type
*ports
;
78 int (*dpi_select_source
)(int port
, enum omap_channel channel
);
82 struct platform_device
*pdev
;
84 struct regmap
*syscon_pll_ctrl
;
85 u32 syscon_pll_ctrl_offset
;
87 struct clk
*parent_clk
;
89 unsigned long dss_clk_rate
;
91 unsigned long cache_req_pck
;
92 unsigned long cache_prate
;
93 struct dispc_clock_info cache_dispc_cinfo
;
95 enum omap_dss_clk_source dsi_clk_source
[MAX_NUM_DSI
];
96 enum omap_dss_clk_source dispc_clk_source
;
97 enum omap_dss_clk_source lcd_clk_source
[MAX_DSS_LCD_MANAGERS
];
100 u32 ctx
[DSS_SZ_REGS
/ sizeof(u32
)];
102 const struct dss_features
*feat
;
104 struct dss_pll
*video1_pll
;
105 struct dss_pll
*video2_pll
;
108 static const char * const dss_generic_clk_source_names
[] = {
109 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
] = "DSI_PLL_HSDIV_DISPC",
110 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
] = "DSI_PLL_HSDIV_DSI",
111 [OMAP_DSS_CLK_SRC_FCK
] = "DSS_FCK",
112 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
] = "DSI_PLL2_HSDIV_DISPC",
113 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
] = "DSI_PLL2_HSDIV_DSI",
116 static bool dss_initialized
;
118 bool omapdss_is_initialized(void)
120 return dss_initialized
;
122 EXPORT_SYMBOL(omapdss_is_initialized
);
124 static inline void dss_write_reg(const struct dss_reg idx
, u32 val
)
126 __raw_writel(val
, dss
.base
+ idx
.idx
);
129 static inline u32
dss_read_reg(const struct dss_reg idx
)
131 return __raw_readl(dss
.base
+ idx
.idx
);
135 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
137 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
139 static void dss_save_context(void)
141 DSSDBG("dss_save_context\n");
145 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
146 OMAP_DISPLAY_TYPE_SDI
) {
151 dss
.ctx_valid
= true;
153 DSSDBG("context saved\n");
156 static void dss_restore_context(void)
158 DSSDBG("dss_restore_context\n");
165 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
166 OMAP_DISPLAY_TYPE_SDI
) {
171 DSSDBG("context restored\n");
177 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
)
182 if (!dss
.syscon_pll_ctrl
)
198 DSSERR("illegal DSS PLL ID %d\n", pll_id
);
202 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
203 1 << shift
, val
<< shift
);
206 void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id
,
207 enum omap_channel channel
)
211 if (!dss
.syscon_pll_ctrl
)
215 case OMAP_DSS_CHANNEL_LCD
:
224 DSSERR("error in PLL mux config for LCD\n");
229 case OMAP_DSS_CHANNEL_LCD2
:
240 DSSERR("error in PLL mux config for LCD2\n");
245 case OMAP_DSS_CHANNEL_LCD3
:
256 DSSERR("error in PLL mux config for LCD3\n");
262 DSSERR("error in PLL mux config\n");
266 regmap_update_bits(dss
.syscon_pll_ctrl
, dss
.syscon_pll_ctrl_offset
,
267 0x3 << shift
, val
<< shift
);
270 void dss_sdi_init(int datapairs
)
274 BUG_ON(datapairs
> 3 || datapairs
< 1);
276 l
= dss_read_reg(DSS_SDI_CONTROL
);
277 l
= FLD_MOD(l
, 0xf, 19, 15); /* SDI_PDIV */
278 l
= FLD_MOD(l
, datapairs
-1, 3, 2); /* SDI_PRSEL */
279 l
= FLD_MOD(l
, 2, 1, 0); /* SDI_BWSEL */
280 dss_write_reg(DSS_SDI_CONTROL
, l
);
282 l
= dss_read_reg(DSS_PLL_CONTROL
);
283 l
= FLD_MOD(l
, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
284 l
= FLD_MOD(l
, 0xb, 16, 11); /* SDI_PLL_REGN */
285 l
= FLD_MOD(l
, 0xb4, 10, 1); /* SDI_PLL_REGM */
286 dss_write_reg(DSS_PLL_CONTROL
, l
);
289 int dss_sdi_enable(void)
291 unsigned long timeout
;
293 dispc_pck_free_enable(1);
296 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 18, 18); /* SDI_PLL_SYSRESET */
297 udelay(1); /* wait 2x PCLK */
300 REG_FLD_MOD(DSS_PLL_CONTROL
, 1, 28, 28); /* SDI_PLL_GOBIT */
302 /* Waiting for PLL lock request to complete */
303 timeout
= jiffies
+ msecs_to_jiffies(500);
304 while (dss_read_reg(DSS_SDI_STATUS
) & (1 << 6)) {
305 if (time_after_eq(jiffies
, timeout
)) {
306 DSSERR("PLL lock request timed out\n");
311 /* Clearing PLL_GO bit */
312 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 28, 28);
314 /* Waiting for PLL to lock */
315 timeout
= jiffies
+ msecs_to_jiffies(500);
316 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 5))) {
317 if (time_after_eq(jiffies
, timeout
)) {
318 DSSERR("PLL lock timed out\n");
323 dispc_lcd_enable_signal(1);
325 /* Waiting for SDI reset to complete */
326 timeout
= jiffies
+ msecs_to_jiffies(500);
327 while (!(dss_read_reg(DSS_SDI_STATUS
) & (1 << 2))) {
328 if (time_after_eq(jiffies
, timeout
)) {
329 DSSERR("SDI reset timed out\n");
337 dispc_lcd_enable_signal(0);
340 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
342 dispc_pck_free_enable(0);
347 void dss_sdi_disable(void)
349 dispc_lcd_enable_signal(0);
351 dispc_pck_free_enable(0);
354 REG_FLD_MOD(DSS_PLL_CONTROL
, 0, 18, 18); /* SDI_PLL_SYSRESET */
357 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src
)
359 return dss_generic_clk_source_names
[clk_src
];
362 void dss_dump_clocks(struct seq_file
*s
)
364 const char *fclk_name
, *fclk_real_name
;
365 unsigned long fclk_rate
;
367 if (dss_runtime_get())
370 seq_printf(s
, "- DSS -\n");
372 fclk_name
= dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
373 fclk_real_name
= dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK
);
374 fclk_rate
= clk_get_rate(dss
.dss_clk
);
376 seq_printf(s
, "%s (%s) = %lu\n",
377 fclk_name
, fclk_real_name
,
383 static void dss_dump_regs(struct seq_file
*s
)
385 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
387 if (dss_runtime_get())
390 DUMPREG(DSS_REVISION
);
391 DUMPREG(DSS_SYSCONFIG
);
392 DUMPREG(DSS_SYSSTATUS
);
393 DUMPREG(DSS_CONTROL
);
395 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD
) &
396 OMAP_DISPLAY_TYPE_SDI
) {
397 DUMPREG(DSS_SDI_CONTROL
);
398 DUMPREG(DSS_PLL_CONTROL
);
399 DUMPREG(DSS_SDI_STATUS
);
406 static void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src
)
412 case OMAP_DSS_CLK_SRC_FCK
:
415 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
418 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
426 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH
, &start
, &end
);
428 REG_FLD_MOD(DSS_CONTROL
, b
, start
, end
); /* DISPC_CLK_SWITCH */
430 dss
.dispc_clk_source
= clk_src
;
433 void dss_select_dsi_clk_source(int dsi_module
,
434 enum omap_dss_clk_source clk_src
)
439 case OMAP_DSS_CLK_SRC_FCK
:
442 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
:
443 BUG_ON(dsi_module
!= 0);
446 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
:
447 BUG_ON(dsi_module
!= 1);
455 pos
= dsi_module
== 0 ? 1 : 10;
456 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* DSIx_CLK_SWITCH */
458 dss
.dsi_clk_source
[dsi_module
] = clk_src
;
461 void dss_select_lcd_clk_source(enum omap_channel channel
,
462 enum omap_dss_clk_source clk_src
)
466 if (!dss_has_feature(FEAT_LCD_CLK_SRC
)) {
467 dss_select_dispc_clk_source(clk_src
);
472 case OMAP_DSS_CLK_SRC_FCK
:
475 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
476 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD
);
479 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
480 BUG_ON(channel
!= OMAP_DSS_CHANNEL_LCD2
&&
481 channel
!= OMAP_DSS_CHANNEL_LCD3
);
489 pos
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
490 (channel
== OMAP_DSS_CHANNEL_LCD2
? 12 : 19);
491 REG_FLD_MOD(DSS_CONTROL
, b
, pos
, pos
); /* LCDx_CLK_SWITCH */
493 ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
494 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
495 dss
.lcd_clk_source
[ix
] = clk_src
;
498 enum omap_dss_clk_source
dss_get_dispc_clk_source(void)
500 return dss
.dispc_clk_source
;
503 enum omap_dss_clk_source
dss_get_dsi_clk_source(int dsi_module
)
505 return dss
.dsi_clk_source
[dsi_module
];
508 enum omap_dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
)
510 if (dss_has_feature(FEAT_LCD_CLK_SRC
)) {
511 int ix
= channel
== OMAP_DSS_CHANNEL_LCD
? 0 :
512 (channel
== OMAP_DSS_CHANNEL_LCD2
? 1 : 2);
513 return dss
.lcd_clk_source
[ix
];
515 /* LCD_CLK source is the same as DISPC_FCLK source for
517 return dss
.dispc_clk_source
;
521 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
522 dss_div_calc_func func
, void *data
)
524 int fckd
, fckd_start
, fckd_stop
;
526 unsigned long fck_hw_max
;
527 unsigned long fckd_hw_max
;
531 fck_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
533 if (dss
.parent_clk
== NULL
) {
536 pckd
= fck_hw_max
/ pck
;
540 fck
= clk_round_rate(dss
.dss_clk
, fck
);
542 return func(fck
, data
);
545 fckd_hw_max
= dss
.feat
->fck_div_max
;
547 m
= dss
.feat
->dss_fck_multiplier
;
548 prate
= clk_get_rate(dss
.parent_clk
);
550 fck_min
= fck_min
? fck_min
: 1;
552 fckd_start
= min(prate
* m
/ fck_min
, fckd_hw_max
);
553 fckd_stop
= max(DIV_ROUND_UP(prate
* m
, fck_hw_max
), 1ul);
555 for (fckd
= fckd_start
; fckd
>= fckd_stop
; --fckd
) {
556 fck
= DIV_ROUND_UP(prate
, fckd
) * m
;
565 int dss_set_fck_rate(unsigned long rate
)
569 DSSDBG("set fck to %lu\n", rate
);
571 r
= clk_set_rate(dss
.dss_clk
, rate
);
575 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
577 WARN_ONCE(dss
.dss_clk_rate
!= rate
,
578 "clk rate mismatch: %lu != %lu", dss
.dss_clk_rate
,
584 unsigned long dss_get_dispc_clk_rate(void)
586 return dss
.dss_clk_rate
;
589 static int dss_setup_default_clock(void)
591 unsigned long max_dss_fck
, prate
;
596 max_dss_fck
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
598 if (dss
.parent_clk
== NULL
) {
599 fck
= clk_round_rate(dss
.dss_clk
, max_dss_fck
);
601 prate
= clk_get_rate(dss
.parent_clk
);
603 fck_div
= DIV_ROUND_UP(prate
* dss
.feat
->dss_fck_multiplier
,
605 fck
= DIV_ROUND_UP(prate
, fck_div
) * dss
.feat
->dss_fck_multiplier
;
608 r
= dss_set_fck_rate(fck
);
615 void dss_set_venc_output(enum omap_dss_venc_type type
)
619 if (type
== OMAP_DSS_VENC_TYPE_COMPOSITE
)
621 else if (type
== OMAP_DSS_VENC_TYPE_SVIDEO
)
626 /* venc out selection. 0 = comp, 1 = svideo */
627 REG_FLD_MOD(DSS_CONTROL
, l
, 6, 6);
630 void dss_set_dac_pwrdn_bgz(bool enable
)
632 REG_FLD_MOD(DSS_CONTROL
, enable
, 5, 5); /* DAC Power-Down Control */
635 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src
)
637 enum omap_display_type dp
;
638 dp
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
640 /* Complain about invalid selections */
641 WARN_ON((src
== DSS_VENC_TV_CLK
) && !(dp
& OMAP_DISPLAY_TYPE_VENC
));
642 WARN_ON((src
== DSS_HDMI_M_PCLK
) && !(dp
& OMAP_DISPLAY_TYPE_HDMI
));
644 /* Select only if we have options */
645 if ((dp
& OMAP_DISPLAY_TYPE_VENC
) && (dp
& OMAP_DISPLAY_TYPE_HDMI
))
646 REG_FLD_MOD(DSS_CONTROL
, src
, 15, 15); /* VENC_HDMI_SWITCH */
649 enum dss_hdmi_venc_clk_source_select
dss_get_hdmi_venc_clk_source(void)
651 enum omap_display_type displays
;
653 displays
= dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT
);
654 if ((displays
& OMAP_DISPLAY_TYPE_HDMI
) == 0)
655 return DSS_VENC_TV_CLK
;
657 if ((displays
& OMAP_DISPLAY_TYPE_VENC
) == 0)
658 return DSS_HDMI_M_PCLK
;
660 return REG_GET(DSS_CONTROL
, 15, 15);
663 static int dss_dpi_select_source_omap2_omap3(int port
, enum omap_channel channel
)
665 if (channel
!= OMAP_DSS_CHANNEL_LCD
)
671 static int dss_dpi_select_source_omap4(int port
, enum omap_channel channel
)
676 case OMAP_DSS_CHANNEL_LCD2
:
679 case OMAP_DSS_CHANNEL_DIGIT
:
686 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 17);
691 static int dss_dpi_select_source_omap5(int port
, enum omap_channel channel
)
696 case OMAP_DSS_CHANNEL_LCD
:
699 case OMAP_DSS_CHANNEL_LCD2
:
702 case OMAP_DSS_CHANNEL_LCD3
:
705 case OMAP_DSS_CHANNEL_DIGIT
:
712 REG_FLD_MOD(DSS_CONTROL
, val
, 17, 16);
717 static int dss_dpi_select_source_dra7xx(int port
, enum omap_channel channel
)
721 return dss_dpi_select_source_omap5(port
, channel
);
723 if (channel
!= OMAP_DSS_CHANNEL_LCD2
)
727 if (channel
!= OMAP_DSS_CHANNEL_LCD3
)
737 int dss_dpi_select_source(int port
, enum omap_channel channel
)
739 return dss
.feat
->dpi_select_source(port
, channel
);
742 static int dss_get_clocks(void)
746 clk
= devm_clk_get(&dss
.pdev
->dev
, "fck");
748 DSSERR("can't get clock fck\n");
754 if (dss
.feat
->parent_clk_name
) {
755 clk
= clk_get(NULL
, dss
.feat
->parent_clk_name
);
757 DSSERR("Failed to get %s\n", dss
.feat
->parent_clk_name
);
764 dss
.parent_clk
= clk
;
769 static void dss_put_clocks(void)
772 clk_put(dss
.parent_clk
);
775 int dss_runtime_get(void)
779 DSSDBG("dss_runtime_get\n");
781 r
= pm_runtime_get_sync(&dss
.pdev
->dev
);
783 return r
< 0 ? r
: 0;
786 void dss_runtime_put(void)
790 DSSDBG("dss_runtime_put\n");
792 r
= pm_runtime_put_sync(&dss
.pdev
->dev
);
793 WARN_ON(r
< 0 && r
!= -ENOSYS
&& r
!= -EBUSY
);
797 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
798 void dss_debug_dump_clocks(struct seq_file
*s
)
801 dispc_dump_clocks(s
);
802 #ifdef CONFIG_FB_OMAP2_DSS_DSI
809 static const enum omap_display_type omap2plus_ports
[] = {
810 OMAP_DISPLAY_TYPE_DPI
,
813 static const enum omap_display_type omap34xx_ports
[] = {
814 OMAP_DISPLAY_TYPE_DPI
,
815 OMAP_DISPLAY_TYPE_SDI
,
818 static const enum omap_display_type dra7xx_ports
[] = {
819 OMAP_DISPLAY_TYPE_DPI
,
820 OMAP_DISPLAY_TYPE_DPI
,
821 OMAP_DISPLAY_TYPE_DPI
,
824 static const struct dss_features omap24xx_dss_feats
= {
826 * fck div max is really 16, but the divider range has gaps. The range
827 * from 1 to 6 has no gaps, so let's use that as a max.
830 .dss_fck_multiplier
= 2,
831 .parent_clk_name
= "core_ck",
832 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
833 .ports
= omap2plus_ports
,
834 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
837 static const struct dss_features omap34xx_dss_feats
= {
839 .dss_fck_multiplier
= 2,
840 .parent_clk_name
= "dpll4_ck",
841 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
842 .ports
= omap34xx_ports
,
843 .num_ports
= ARRAY_SIZE(omap34xx_ports
),
846 static const struct dss_features omap3630_dss_feats
= {
848 .dss_fck_multiplier
= 1,
849 .parent_clk_name
= "dpll4_ck",
850 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
851 .ports
= omap2plus_ports
,
852 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
855 static const struct dss_features omap44xx_dss_feats
= {
857 .dss_fck_multiplier
= 1,
858 .parent_clk_name
= "dpll_per_x2_ck",
859 .dpi_select_source
= &dss_dpi_select_source_omap4
,
860 .ports
= omap2plus_ports
,
861 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
864 static const struct dss_features omap54xx_dss_feats
= {
866 .dss_fck_multiplier
= 1,
867 .parent_clk_name
= "dpll_per_x2_ck",
868 .dpi_select_source
= &dss_dpi_select_source_omap5
,
869 .ports
= omap2plus_ports
,
870 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
873 static const struct dss_features am43xx_dss_feats
= {
875 .dss_fck_multiplier
= 0,
876 .parent_clk_name
= NULL
,
877 .dpi_select_source
= &dss_dpi_select_source_omap2_omap3
,
878 .ports
= omap2plus_ports
,
879 .num_ports
= ARRAY_SIZE(omap2plus_ports
),
882 static const struct dss_features dra7xx_dss_feats
= {
884 .dss_fck_multiplier
= 1,
885 .parent_clk_name
= "dpll_per_x2_ck",
886 .dpi_select_source
= &dss_dpi_select_source_dra7xx
,
887 .ports
= dra7xx_ports
,
888 .num_ports
= ARRAY_SIZE(dra7xx_ports
),
891 static const struct dss_features
*dss_get_features(void)
893 switch (omapdss_get_version()) {
894 case OMAPDSS_VER_OMAP24xx
:
895 return &omap24xx_dss_feats
;
897 case OMAPDSS_VER_OMAP34xx_ES1
:
898 case OMAPDSS_VER_OMAP34xx_ES3
:
899 case OMAPDSS_VER_AM35xx
:
900 return &omap34xx_dss_feats
;
902 case OMAPDSS_VER_OMAP3630
:
903 return &omap3630_dss_feats
;
905 case OMAPDSS_VER_OMAP4430_ES1
:
906 case OMAPDSS_VER_OMAP4430_ES2
:
907 case OMAPDSS_VER_OMAP4
:
908 return &omap44xx_dss_feats
;
910 case OMAPDSS_VER_OMAP5
:
911 return &omap54xx_dss_feats
;
913 case OMAPDSS_VER_AM43xx
:
914 return &am43xx_dss_feats
;
916 case OMAPDSS_VER_DRA7xx
:
917 return &dra7xx_dss_feats
;
924 static void dss_uninit_ports(struct platform_device
*pdev
);
926 static int dss_init_ports(struct platform_device
*pdev
)
928 struct device_node
*parent
= pdev
->dev
.of_node
;
929 struct device_node
*port
;
935 port
= omapdss_of_get_next_port(parent
, NULL
);
939 if (dss
.feat
->num_ports
== 0)
943 enum omap_display_type port_type
;
946 r
= of_property_read_u32(port
, "reg", ®
);
950 if (reg
>= dss
.feat
->num_ports
)
953 port_type
= dss
.feat
->ports
[reg
];
956 case OMAP_DISPLAY_TYPE_DPI
:
957 ret
= dpi_init_port(pdev
, port
);
959 case OMAP_DISPLAY_TYPE_SDI
:
960 ret
= sdi_init_port(pdev
, port
);
966 (port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
969 dss_uninit_ports(pdev
);
974 static void dss_uninit_ports(struct platform_device
*pdev
)
976 struct device_node
*parent
= pdev
->dev
.of_node
;
977 struct device_node
*port
;
982 port
= omapdss_of_get_next_port(parent
, NULL
);
986 if (dss
.feat
->num_ports
== 0)
990 enum omap_display_type port_type
;
994 r
= of_property_read_u32(port
, "reg", ®
);
998 if (reg
>= dss
.feat
->num_ports
)
1001 port_type
= dss
.feat
->ports
[reg
];
1003 switch (port_type
) {
1004 case OMAP_DISPLAY_TYPE_DPI
:
1005 dpi_uninit_port(port
);
1007 case OMAP_DISPLAY_TYPE_SDI
:
1008 sdi_uninit_port(port
);
1013 } while ((port
= omapdss_of_get_next_port(parent
, port
)) != NULL
);
1016 static int dss_video_pll_probe(struct platform_device
*pdev
)
1018 struct device_node
*np
= pdev
->dev
.of_node
;
1019 struct regulator
*pll_regulator
;
1025 if (of_property_read_bool(np
, "syscon-pll-ctrl")) {
1026 dss
.syscon_pll_ctrl
= syscon_regmap_lookup_by_phandle(np
,
1028 if (IS_ERR(dss
.syscon_pll_ctrl
)) {
1030 "failed to get syscon-pll-ctrl regmap\n");
1031 return PTR_ERR(dss
.syscon_pll_ctrl
);
1034 if (of_property_read_u32_index(np
, "syscon-pll-ctrl", 1,
1035 &dss
.syscon_pll_ctrl_offset
)) {
1037 "failed to get syscon-pll-ctrl offset\n");
1042 pll_regulator
= devm_regulator_get(&pdev
->dev
, "vdda_video");
1043 if (IS_ERR(pll_regulator
)) {
1044 r
= PTR_ERR(pll_regulator
);
1048 pll_regulator
= NULL
;
1052 return -EPROBE_DEFER
;
1055 DSSERR("can't get DPLL VDDA regulator\n");
1060 if (of_property_match_string(np
, "reg-names", "pll1") >= 0) {
1061 dss
.video1_pll
= dss_video_pll_init(pdev
, 0, pll_regulator
);
1062 if (IS_ERR(dss
.video1_pll
))
1063 return PTR_ERR(dss
.video1_pll
);
1066 if (of_property_match_string(np
, "reg-names", "pll2") >= 0) {
1067 dss
.video2_pll
= dss_video_pll_init(pdev
, 1, pll_regulator
);
1068 if (IS_ERR(dss
.video2_pll
)) {
1069 dss_video_pll_uninit(dss
.video1_pll
);
1070 return PTR_ERR(dss
.video2_pll
);
1077 /* DSS HW IP initialisation */
1078 static int dss_bind(struct device
*dev
)
1080 struct platform_device
*pdev
= to_platform_device(dev
);
1081 struct resource
*dss_mem
;
1087 dss
.feat
= dss_get_features();
1091 dss_mem
= platform_get_resource(dss
.pdev
, IORESOURCE_MEM
, 0);
1093 DSSERR("can't get IORESOURCE_MEM DSS\n");
1097 dss
.base
= devm_ioremap(&pdev
->dev
, dss_mem
->start
,
1098 resource_size(dss_mem
));
1100 DSSERR("can't ioremap DSS\n");
1104 r
= dss_get_clocks();
1108 r
= dss_setup_default_clock();
1110 goto err_setup_clocks
;
1112 r
= dss_video_pll_probe(pdev
);
1116 r
= dss_init_ports(pdev
);
1118 goto err_init_ports
;
1120 pm_runtime_enable(&pdev
->dev
);
1122 r
= dss_runtime_get();
1124 goto err_runtime_get
;
1126 dss
.dss_clk_rate
= clk_get_rate(dss
.dss_clk
);
1129 REG_FLD_MOD(DSS_CONTROL
, 0, 0, 0);
1131 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK
);
1133 #ifdef CONFIG_FB_OMAP2_DSS_VENC
1134 REG_FLD_MOD(DSS_CONTROL
, 1, 4, 4); /* venc dac demen */
1135 REG_FLD_MOD(DSS_CONTROL
, 1, 3, 3); /* venc clock 4x enable */
1136 REG_FLD_MOD(DSS_CONTROL
, 0, 2, 2); /* venc clock mode = normal */
1138 dss
.dsi_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1139 dss
.dsi_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1140 dss
.dispc_clk_source
= OMAP_DSS_CLK_SRC_FCK
;
1141 dss
.lcd_clk_source
[0] = OMAP_DSS_CLK_SRC_FCK
;
1142 dss
.lcd_clk_source
[1] = OMAP_DSS_CLK_SRC_FCK
;
1144 rev
= dss_read_reg(DSS_REVISION
);
1145 printk(KERN_INFO
"OMAP DSS rev %d.%d\n",
1146 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
1150 r
= component_bind_all(&pdev
->dev
, NULL
);
1154 dss_debugfs_create_file("dss", dss_dump_regs
);
1156 pm_set_vt_switch(0);
1158 dss_initialized
= true;
1164 pm_runtime_disable(&pdev
->dev
);
1165 dss_uninit_ports(pdev
);
1168 dss_video_pll_uninit(dss
.video1_pll
);
1171 dss_video_pll_uninit(dss
.video2_pll
);
1178 static void dss_unbind(struct device
*dev
)
1180 struct platform_device
*pdev
= to_platform_device(dev
);
1182 dss_initialized
= false;
1184 component_unbind_all(&pdev
->dev
, NULL
);
1187 dss_video_pll_uninit(dss
.video1_pll
);
1190 dss_video_pll_uninit(dss
.video2_pll
);
1192 dss_uninit_ports(pdev
);
1194 pm_runtime_disable(&pdev
->dev
);
1199 static const struct component_master_ops dss_component_ops
= {
1201 .unbind
= dss_unbind
,
1204 static int dss_component_compare(struct device
*dev
, void *data
)
1206 struct device
*child
= data
;
1207 return dev
== child
;
1210 static int dss_add_child_component(struct device
*dev
, void *data
)
1212 struct component_match
**match
= data
;
1216 * We don't have a working driver for rfbi, so skip it here always.
1217 * Otherwise dss will never get probed successfully, as it will wait
1218 * for rfbi to get probed.
1220 if (strstr(dev_name(dev
), "rfbi"))
1223 component_match_add(dev
->parent
, match
, dss_component_compare
, dev
);
1228 static int dss_probe(struct platform_device
*pdev
)
1230 struct component_match
*match
= NULL
;
1233 /* add all the child devices as components */
1234 device_for_each_child(&pdev
->dev
, &match
, dss_add_child_component
);
1236 r
= component_master_add_with_match(&pdev
->dev
, &dss_component_ops
, match
);
1243 static int dss_remove(struct platform_device
*pdev
)
1245 component_master_del(&pdev
->dev
, &dss_component_ops
);
1249 static int dss_runtime_suspend(struct device
*dev
)
1252 dss_set_min_bus_tput(dev
, 0);
1254 pinctrl_pm_select_sleep_state(dev
);
1259 static int dss_runtime_resume(struct device
*dev
)
1263 pinctrl_pm_select_default_state(dev
);
1266 * Set an arbitrarily high tput request to ensure OPP100.
1267 * What we should really do is to make a request to stay in OPP100,
1268 * without any tput requirements, but that is not currently possible
1272 r
= dss_set_min_bus_tput(dev
, 1000000000);
1276 dss_restore_context();
1280 static const struct dev_pm_ops dss_pm_ops
= {
1281 .runtime_suspend
= dss_runtime_suspend
,
1282 .runtime_resume
= dss_runtime_resume
,
1285 static const struct of_device_id dss_of_match
[] = {
1286 { .compatible
= "ti,omap2-dss", },
1287 { .compatible
= "ti,omap3-dss", },
1288 { .compatible
= "ti,omap4-dss", },
1289 { .compatible
= "ti,omap5-dss", },
1290 { .compatible
= "ti,dra7-dss", },
1294 MODULE_DEVICE_TABLE(of
, dss_of_match
);
1296 static struct platform_driver omap_dsshw_driver
= {
1298 .remove
= dss_remove
,
1300 .name
= "omapdss_dss",
1302 .of_match_table
= dss_of_match
,
1303 .suppress_bind_attrs
= true,
1307 int __init
dss_init_platform_driver(void)
1309 return platform_driver_register(&omap_dsshw_driver
);
1312 void dss_uninit_platform_driver(void)
1314 platform_driver_unregister(&omap_dsshw_driver
);