1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
8 #define DSS_SUBSYS_NAME "HDMIWP"
10 #include <linux/kernel.h>
11 #include <linux/err.h>
13 #include <linux/platform_device.h>
14 #include <linux/seq_file.h>
20 void hdmi_wp_dump(struct hdmi_wp_data
*wp
, struct seq_file
*s
)
22 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, hdmi_read_reg(wp->base, r))
24 DUMPREG(HDMI_WP_REVISION
);
25 DUMPREG(HDMI_WP_SYSCONFIG
);
26 DUMPREG(HDMI_WP_IRQSTATUS_RAW
);
27 DUMPREG(HDMI_WP_IRQSTATUS
);
28 DUMPREG(HDMI_WP_IRQENABLE_SET
);
29 DUMPREG(HDMI_WP_IRQENABLE_CLR
);
30 DUMPREG(HDMI_WP_IRQWAKEEN
);
31 DUMPREG(HDMI_WP_PWR_CTRL
);
32 DUMPREG(HDMI_WP_DEBOUNCE
);
33 DUMPREG(HDMI_WP_VIDEO_CFG
);
34 DUMPREG(HDMI_WP_VIDEO_SIZE
);
35 DUMPREG(HDMI_WP_VIDEO_TIMING_H
);
36 DUMPREG(HDMI_WP_VIDEO_TIMING_V
);
38 DUMPREG(HDMI_WP_AUDIO_CFG
);
39 DUMPREG(HDMI_WP_AUDIO_CFG2
);
40 DUMPREG(HDMI_WP_AUDIO_CTRL
);
41 DUMPREG(HDMI_WP_AUDIO_DATA
);
44 u32
hdmi_wp_get_irqstatus(struct hdmi_wp_data
*wp
)
46 return hdmi_read_reg(wp
->base
, HDMI_WP_IRQSTATUS
);
49 void hdmi_wp_set_irqstatus(struct hdmi_wp_data
*wp
, u32 irqstatus
)
51 hdmi_write_reg(wp
->base
, HDMI_WP_IRQSTATUS
, irqstatus
);
52 /* flush posted write */
53 hdmi_read_reg(wp
->base
, HDMI_WP_IRQSTATUS
);
56 void hdmi_wp_set_irqenable(struct hdmi_wp_data
*wp
, u32 mask
)
58 hdmi_write_reg(wp
->base
, HDMI_WP_IRQENABLE_SET
, mask
);
61 void hdmi_wp_clear_irqenable(struct hdmi_wp_data
*wp
, u32 mask
)
63 hdmi_write_reg(wp
->base
, HDMI_WP_IRQENABLE_CLR
, mask
);
67 int hdmi_wp_set_phy_pwr(struct hdmi_wp_data
*wp
, enum hdmi_phy_pwr val
)
69 /* Return if already the state */
70 if (REG_GET(wp
->base
, HDMI_WP_PWR_CTRL
, 5, 4) == val
)
73 /* Command for power control of HDMI PHY */
74 REG_FLD_MOD(wp
->base
, HDMI_WP_PWR_CTRL
, val
, 7, 6);
76 /* Status of the power control of HDMI PHY */
77 if (hdmi_wait_for_bit_change(wp
->base
, HDMI_WP_PWR_CTRL
, 5, 4, val
)
79 DSSERR("Failed to set PHY power mode to %d\n", val
);
87 int hdmi_wp_set_pll_pwr(struct hdmi_wp_data
*wp
, enum hdmi_pll_pwr val
)
89 /* Command for power control of HDMI PLL */
90 REG_FLD_MOD(wp
->base
, HDMI_WP_PWR_CTRL
, val
, 3, 2);
92 /* wait till PHY_PWR_STATUS is set */
93 if (hdmi_wait_for_bit_change(wp
->base
, HDMI_WP_PWR_CTRL
, 1, 0, val
)
95 DSSERR("Failed to set PLL_PWR_STATUS\n");
102 int hdmi_wp_video_start(struct hdmi_wp_data
*wp
)
104 REG_FLD_MOD(wp
->base
, HDMI_WP_VIDEO_CFG
, true, 31, 31);
109 void hdmi_wp_video_stop(struct hdmi_wp_data
*wp
)
113 hdmi_write_reg(wp
->base
, HDMI_WP_IRQSTATUS
, HDMI_IRQ_VIDEO_FRAME_DONE
);
115 REG_FLD_MOD(wp
->base
, HDMI_WP_VIDEO_CFG
, false, 31, 31);
117 for (i
= 0; i
< 50; ++i
) {
122 v
= hdmi_read_reg(wp
->base
, HDMI_WP_IRQSTATUS_RAW
);
123 if (v
& HDMI_IRQ_VIDEO_FRAME_DONE
)
127 DSSERR("no HDMI FRAMEDONE when disabling output\n");
130 void hdmi_wp_video_config_format(struct hdmi_wp_data
*wp
,
131 const struct hdmi_video_format
*video_fmt
)
135 REG_FLD_MOD(wp
->base
, HDMI_WP_VIDEO_CFG
, video_fmt
->packing_mode
,
138 l
|= FLD_VAL(video_fmt
->y_res
, 31, 16);
139 l
|= FLD_VAL(video_fmt
->x_res
, 15, 0);
140 hdmi_write_reg(wp
->base
, HDMI_WP_VIDEO_SIZE
, l
);
143 void hdmi_wp_video_config_interface(struct hdmi_wp_data
*wp
,
144 const struct videomode
*vm
)
147 bool vsync_inv
, hsync_inv
;
148 DSSDBG("Enter hdmi_wp_video_config_interface\n");
150 vsync_inv
= !!(vm
->flags
& DISPLAY_FLAGS_VSYNC_LOW
);
151 hsync_inv
= !!(vm
->flags
& DISPLAY_FLAGS_HSYNC_LOW
);
153 r
= hdmi_read_reg(wp
->base
, HDMI_WP_VIDEO_CFG
);
154 r
= FLD_MOD(r
, 1, 7, 7); /* VSYNC_POL to dispc active high */
155 r
= FLD_MOD(r
, 1, 6, 6); /* HSYNC_POL to dispc active high */
156 r
= FLD_MOD(r
, vsync_inv
, 5, 5); /* CORE_VSYNC_INV */
157 r
= FLD_MOD(r
, hsync_inv
, 4, 4); /* CORE_HSYNC_INV */
158 r
= FLD_MOD(r
, !!(vm
->flags
& DISPLAY_FLAGS_INTERLACED
), 3, 3);
159 r
= FLD_MOD(r
, 1, 1, 0); /* HDMI_TIMING_MASTER_24BIT */
160 hdmi_write_reg(wp
->base
, HDMI_WP_VIDEO_CFG
, r
);
163 void hdmi_wp_video_config_timing(struct hdmi_wp_data
*wp
,
164 const struct videomode
*vm
)
168 unsigned int hsync_len_offset
= 1;
170 DSSDBG("Enter hdmi_wp_video_config_timing\n");
173 * On OMAP4 and OMAP5 ES1 the HSW field is programmed as is. On OMAP5
174 * ES2+ (including DRA7/AM5 SoCs) HSW field is programmed to hsync_len-1.
175 * However, we don't support OMAP5 ES1 at all, so we can just check for
178 if (wp
->version
== 4)
179 hsync_len_offset
= 0;
181 timing_h
|= FLD_VAL(vm
->hback_porch
, 31, 20);
182 timing_h
|= FLD_VAL(vm
->hfront_porch
, 19, 8);
183 timing_h
|= FLD_VAL(vm
->hsync_len
- hsync_len_offset
, 7, 0);
184 hdmi_write_reg(wp
->base
, HDMI_WP_VIDEO_TIMING_H
, timing_h
);
186 timing_v
|= FLD_VAL(vm
->vback_porch
, 31, 20);
187 timing_v
|= FLD_VAL(vm
->vfront_porch
, 19, 8);
188 timing_v
|= FLD_VAL(vm
->vsync_len
, 7, 0);
189 hdmi_write_reg(wp
->base
, HDMI_WP_VIDEO_TIMING_V
, timing_v
);
192 void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format
*video_fmt
,
193 struct videomode
*vm
, const struct hdmi_config
*param
)
195 DSSDBG("Enter hdmi_wp_video_init_format\n");
197 video_fmt
->packing_mode
= HDMI_PACK_10b_RGB_YUV444
;
198 video_fmt
->y_res
= param
->vm
.vactive
;
199 video_fmt
->x_res
= param
->vm
.hactive
;
201 vm
->hback_porch
= param
->vm
.hback_porch
;
202 vm
->hfront_porch
= param
->vm
.hfront_porch
;
203 vm
->hsync_len
= param
->vm
.hsync_len
;
204 vm
->vback_porch
= param
->vm
.vback_porch
;
205 vm
->vfront_porch
= param
->vm
.vfront_porch
;
206 vm
->vsync_len
= param
->vm
.vsync_len
;
208 vm
->flags
= param
->vm
.flags
;
210 if (param
->vm
.flags
& DISPLAY_FLAGS_INTERLACED
) {
211 video_fmt
->y_res
/= 2;
212 vm
->vback_porch
/= 2;
213 vm
->vfront_porch
/= 2;
217 if (param
->vm
.flags
& DISPLAY_FLAGS_DOUBLECLK
) {
218 video_fmt
->x_res
*= 2;
219 vm
->hfront_porch
*= 2;
221 vm
->hback_porch
*= 2;
225 void hdmi_wp_audio_config_format(struct hdmi_wp_data
*wp
,
226 struct hdmi_audio_format
*aud_fmt
)
230 DSSDBG("Enter hdmi_wp_audio_config_format\n");
232 r
= hdmi_read_reg(wp
->base
, HDMI_WP_AUDIO_CFG
);
233 if (wp
->version
== 4) {
234 r
= FLD_MOD(r
, aud_fmt
->stereo_channels
, 26, 24);
235 r
= FLD_MOD(r
, aud_fmt
->active_chnnls_msk
, 23, 16);
237 r
= FLD_MOD(r
, aud_fmt
->en_sig_blk_strt_end
, 5, 5);
238 r
= FLD_MOD(r
, aud_fmt
->type
, 4, 4);
239 r
= FLD_MOD(r
, aud_fmt
->justification
, 3, 3);
240 r
= FLD_MOD(r
, aud_fmt
->sample_order
, 2, 2);
241 r
= FLD_MOD(r
, aud_fmt
->samples_per_word
, 1, 1);
242 r
= FLD_MOD(r
, aud_fmt
->sample_size
, 0, 0);
243 hdmi_write_reg(wp
->base
, HDMI_WP_AUDIO_CFG
, r
);
246 void hdmi_wp_audio_config_dma(struct hdmi_wp_data
*wp
,
247 struct hdmi_audio_dma
*aud_dma
)
251 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
253 r
= hdmi_read_reg(wp
->base
, HDMI_WP_AUDIO_CFG2
);
254 r
= FLD_MOD(r
, aud_dma
->transfer_size
, 15, 8);
255 r
= FLD_MOD(r
, aud_dma
->block_size
, 7, 0);
256 hdmi_write_reg(wp
->base
, HDMI_WP_AUDIO_CFG2
, r
);
258 r
= hdmi_read_reg(wp
->base
, HDMI_WP_AUDIO_CTRL
);
259 r
= FLD_MOD(r
, aud_dma
->mode
, 9, 9);
260 r
= FLD_MOD(r
, aud_dma
->fifo_threshold
, 8, 0);
261 hdmi_write_reg(wp
->base
, HDMI_WP_AUDIO_CTRL
, r
);
264 int hdmi_wp_audio_enable(struct hdmi_wp_data
*wp
, bool enable
)
266 REG_FLD_MOD(wp
->base
, HDMI_WP_AUDIO_CTRL
, enable
, 31, 31);
271 int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data
*wp
, bool enable
)
273 REG_FLD_MOD(wp
->base
, HDMI_WP_AUDIO_CTRL
, enable
, 30, 30);
278 int hdmi_wp_init(struct platform_device
*pdev
, struct hdmi_wp_data
*wp
,
279 unsigned int version
)
281 struct resource
*res
;
283 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "wp");
284 wp
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
285 if (IS_ERR(wp
->base
))
286 return PTR_ERR(wp
->base
);
288 wp
->phys_base
= res
->start
;
289 wp
->version
= version
;
294 phys_addr_t
hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data
*wp
)
296 return wp
->phys_base
+ HDMI_WP_AUDIO_DATA
;