blob: 1b6dbe1095a7dbe9637280c2186e1d441ce8b111 [file] [log] [blame]
Archit Tanejaf382d9e2013-08-06 14:56:55 +05301/*
2 * HDMI wrapper
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/delay.h>
13#include <linux/err.h>
14#include <linux/io.h>
15#include <linux/platform_device.h>
16#include <video/omapdss.h>
17
18#include "dss.h"
19#include "ti_hdmi.h"
20#include "ti_hdmi_4xxx_ip.h"
21
22static inline void hdmi_write_reg(void __iomem *base_addr, const u16 idx,
23 u32 val)
24{
25 __raw_writel(val, base_addr + idx);
26}
27
28static inline u32 hdmi_read_reg(void __iomem *base_addr, const u16 idx)
29{
30 return __raw_readl(base_addr + idx);
31}
32
33#define REG_FLD_MOD(base, idx, val, start, end) \
34 hdmi_write_reg(base, idx, FLD_MOD(hdmi_read_reg(base, idx),\
35 val, start, end))
36#define REG_GET(base, idx, start, end) \
37 FLD_GET(hdmi_read_reg(base, idx), start, end)
38
39static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
40 const u16 idx, int b2, int b1, u32 val)
41{
42 u32 t = 0;
43 while (val != REG_GET(base_addr, idx, b2, b1)) {
44 udelay(1);
45 if (t++ > 10000)
46 return !val;
47 }
48 return val;
49}
50
51void hdmi_wp_dump(struct hdmi_wp_data *wp, struct seq_file *s)
52{
53#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, hdmi_read_reg(wp->base, r))
54
55 DUMPREG(HDMI_WP_REVISION);
56 DUMPREG(HDMI_WP_SYSCONFIG);
57 DUMPREG(HDMI_WP_IRQSTATUS_RAW);
58 DUMPREG(HDMI_WP_IRQSTATUS);
59 DUMPREG(HDMI_WP_IRQENABLE_SET);
60 DUMPREG(HDMI_WP_IRQENABLE_CLR);
61 DUMPREG(HDMI_WP_IRQWAKEEN);
62 DUMPREG(HDMI_WP_PWR_CTRL);
63 DUMPREG(HDMI_WP_DEBOUNCE);
64 DUMPREG(HDMI_WP_VIDEO_CFG);
65 DUMPREG(HDMI_WP_VIDEO_SIZE);
66 DUMPREG(HDMI_WP_VIDEO_TIMING_H);
67 DUMPREG(HDMI_WP_VIDEO_TIMING_V);
68 DUMPREG(HDMI_WP_WP_CLK);
69 DUMPREG(HDMI_WP_AUDIO_CFG);
70 DUMPREG(HDMI_WP_AUDIO_CFG2);
71 DUMPREG(HDMI_WP_AUDIO_CTRL);
72 DUMPREG(HDMI_WP_AUDIO_DATA);
73}
74
75u32 hdmi_wp_get_irqstatus(struct hdmi_wp_data *wp)
76{
77 return hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
78}
79
80void hdmi_wp_set_irqstatus(struct hdmi_wp_data *wp, u32 irqstatus)
81{
82 hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, irqstatus);
83 /* flush posted write */
84 hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
85}
86
87void hdmi_wp_set_irqenable(struct hdmi_wp_data *wp, u32 mask)
88{
89 hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_SET, mask);
90}
91
92void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask)
93{
94 hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_CLR, mask);
95}
96
97/* PHY_PWR_CMD */
98int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val)
99{
100 /* Return if already the state */
101 if (REG_GET(wp->base, HDMI_WP_PWR_CTRL, 5, 4) == val)
102 return 0;
103
104 /* Command for power control of HDMI PHY */
105 REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 7, 6);
106
107 /* Status of the power control of HDMI PHY */
108 if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 5, 4, val)
109 != val) {
110 pr_err("Failed to set PHY power mode to %d\n", val);
111 return -ETIMEDOUT;
112 }
113
114 return 0;
115}
116
117/* PLL_PWR_CMD */
118int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val)
119{
120 /* Command for power control of HDMI PLL */
121 REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 3, 2);
122
123 /* wait till PHY_PWR_STATUS is set */
124 if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 1, 0, val)
125 != val) {
126 pr_err("Failed to set PLL_PWR_STATUS\n");
127 return -ETIMEDOUT;
128 }
129
130 return 0;
131}
132
133int hdmi_wp_video_start(struct hdmi_wp_data *wp)
134{
135 REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, true, 31, 31);
136
137 return 0;
138}
139
140void hdmi_wp_video_stop(struct hdmi_wp_data *wp)
141{
142 REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, false, 31, 31);
143}
144
145void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
146 struct hdmi_video_format *video_fmt)
147{
148 u32 l = 0;
149
150 REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, video_fmt->packing_mode,
151 10, 8);
152
153 l |= FLD_VAL(video_fmt->y_res, 31, 16);
154 l |= FLD_VAL(video_fmt->x_res, 15, 0);
155 hdmi_write_reg(wp->base, HDMI_WP_VIDEO_SIZE, l);
156}
157
158void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
159 struct omap_video_timings *timings)
160{
161 u32 r;
162 bool vsync_pol, hsync_pol;
163 pr_debug("Enter hdmi_wp_video_config_interface\n");
164
165 vsync_pol = timings->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
166 hsync_pol = timings->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
167
168 r = hdmi_read_reg(wp->base, HDMI_WP_VIDEO_CFG);
169 r = FLD_MOD(r, vsync_pol, 7, 7);
170 r = FLD_MOD(r, hsync_pol, 6, 6);
171 r = FLD_MOD(r, timings->interlace, 3, 3);
172 r = FLD_MOD(r, 1, 1, 0); /* HDMI_TIMING_MASTER_24BIT */
173 hdmi_write_reg(wp->base, HDMI_WP_VIDEO_CFG, r);
174}
175
176void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
177 struct omap_video_timings *timings)
178{
179 u32 timing_h = 0;
180 u32 timing_v = 0;
181
182 pr_debug("Enter hdmi_wp_video_config_timing\n");
183
184 timing_h |= FLD_VAL(timings->hbp, 31, 20);
185 timing_h |= FLD_VAL(timings->hfp, 19, 8);
186 timing_h |= FLD_VAL(timings->hsw, 7, 0);
187 hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_H, timing_h);
188
189 timing_v |= FLD_VAL(timings->vbp, 31, 20);
190 timing_v |= FLD_VAL(timings->vfp, 19, 8);
191 timing_v |= FLD_VAL(timings->vsw, 7, 0);
192 hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_V, timing_v);
193}
194
195void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
196 struct omap_video_timings *timings, struct hdmi_config *param)
197{
198 pr_debug("Enter hdmi_wp_video_init_format\n");
199
200 video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
201 video_fmt->y_res = param->timings.y_res;
202 video_fmt->x_res = param->timings.x_res;
203
204 timings->hbp = param->timings.hbp;
205 timings->hfp = param->timings.hfp;
206 timings->hsw = param->timings.hsw;
207 timings->vbp = param->timings.vbp;
208 timings->vfp = param->timings.vfp;
209 timings->vsw = param->timings.vsw;
210 timings->vsync_level = param->timings.vsync_level;
211 timings->hsync_level = param->timings.hsync_level;
212 timings->interlace = param->timings.interlace;
213}
214
215#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
216void hdmi_wp_audio_config_format(struct hdmi_wp_data *wp,
217 struct hdmi_audio_format *aud_fmt)
218{
219 u32 r;
220
221 DSSDBG("Enter hdmi_wp_audio_config_format\n");
222
223 r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG);
224 r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
225 r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
226 r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
227 r = FLD_MOD(r, aud_fmt->type, 4, 4);
228 r = FLD_MOD(r, aud_fmt->justification, 3, 3);
229 r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
230 r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
231 r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
232 hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG, r);
233}
234
235void hdmi_wp_audio_config_dma(struct hdmi_wp_data *wp,
236 struct hdmi_audio_dma *aud_dma)
237{
238 u32 r;
239
240 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
241
242 r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG2);
243 r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
244 r = FLD_MOD(r, aud_dma->block_size, 7, 0);
245 hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG2, r);
246
247 r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CTRL);
248 r = FLD_MOD(r, aud_dma->mode, 9, 9);
249 r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
250 hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CTRL, r);
251}
252
253int hdmi_wp_audio_enable(struct hdmi_wp_data *wp, bool enable)
254{
255 REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 31, 31);
256
257 return 0;
258}
259
260int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data *wp, bool enable)
261{
262 REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 30, 30);
263
264 return 0;
265}
266#endif
267
268#define WP_SIZE 0x200
269
270int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp)
271{
272 struct resource *res;
273 struct resource temp_res;
274
275 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hdmi_wp");
276 if (!res) {
277 DSSDBG("can't get WP mem resource by name\n");
278 /*
279 * if hwmod/DT doesn't have the memory resource information
280 * split into HDMI sub blocks by name, we try again by getting
281 * the platform's first resource. this code will be removed when
282 * the driver can get the mem resources by name
283 */
284 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
285 if (!res) {
286 DSSERR("can't get WP mem resource\n");
287 return -EINVAL;
288 }
289
290 temp_res.start = res->start;
291 temp_res.end = temp_res.start + WP_SIZE - 1;
292 res = &temp_res;
293 }
294
295 wp->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
296 if (!wp->base) {
297 DSSERR("can't ioremap HDMI WP\n");
298 return -ENOMEM;
299 }
300
301 return 0;
302}