Commit | Line | Data |
---|---|---|
f5bab222 TV |
1 | /* |
2 | * OMAP5 HDMI CORE IP driver library | |
3 | * | |
4 | * Copyright (C) 2014 Texas Instruments Incorporated | |
5 | * | |
6 | * Authors: | |
7 | * Yong Zhi | |
8 | * Mythri pk | |
9 | * Archit Taneja <archit@ti.com> | |
10 | * Tomi Valkeinen <tomi.valkeinen@ti.com> | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License version 2 as published by | |
14 | * the Free Software Foundation. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
19 | * more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along with | |
22 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
23 | */ | |
24 | ||
25 | #include <linux/kernel.h> | |
26 | #include <linux/module.h> | |
27 | #include <linux/err.h> | |
28 | #include <linux/io.h> | |
29 | #include <linux/delay.h> | |
30 | #include <linux/string.h> | |
31 | #include <linux/seq_file.h> | |
32 | #include <drm/drm_edid.h> | |
33 | #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO) | |
34 | #include <sound/asound.h> | |
35 | #include <sound/asoundef.h> | |
36 | #endif | |
37 | ||
38 | #include "hdmi5_core.h" | |
39 | ||
40 | /* only 24 bit color depth used for now */ | |
41 | static const struct csc_table csc_table_deepcolor[] = { | |
42 | /* HDMI_DEEP_COLOR_24BIT */ | |
43 | [0] = { 7036, 0, 0, 32, 0, 7036, 0, 32, 0, 0, 7036, 32, }, | |
44 | /* HDMI_DEEP_COLOR_30BIT */ | |
45 | [1] = { 7015, 0, 0, 128, 0, 7015, 0, 128, 0, 0, 7015, 128, }, | |
46 | /* HDMI_DEEP_COLOR_36BIT */ | |
47 | [2] = { 7010, 0, 0, 512, 0, 7010, 0, 512, 0, 0, 7010, 512, }, | |
48 | /* FULL RANGE */ | |
49 | [3] = { 8192, 0, 0, 0, 0, 8192, 0, 0, 0, 0, 8192, 0, }, | |
50 | }; | |
51 | ||
52 | static void hdmi_core_ddc_init(struct hdmi_core_data *core) | |
53 | { | |
54 | void __iomem *base = core->base; | |
55 | const unsigned long long iclk = 266000000; /* DSS L3 ICLK */ | |
56 | const unsigned ss_scl_high = 4000; /* ns */ | |
57 | const unsigned ss_scl_low = 4700; /* ns */ | |
58 | const unsigned fs_scl_high = 600; /* ns */ | |
59 | const unsigned fs_scl_low = 1300; /* ns */ | |
60 | const unsigned sda_hold = 300; /* ns */ | |
61 | const unsigned sfr_div = 10; | |
62 | unsigned long long sfr; | |
63 | unsigned v; | |
64 | ||
65 | sfr = iclk / sfr_div; /* SFR_DIV */ | |
66 | sfr /= 1000; /* SFR clock in kHz */ | |
67 | ||
68 | /* Reset */ | |
69 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SOFTRSTZ, 0, 0, 0); | |
70 | if (hdmi_wait_for_bit_change(base, HDMI_CORE_I2CM_SOFTRSTZ, | |
71 | 0, 0, 1) != 1) | |
72 | DSSERR("HDMI I2CM reset failed\n"); | |
73 | ||
74 | /* Standard (0) or Fast (1) Mode */ | |
75 | REG_FLD_MOD(base, HDMI_CORE_I2CM_DIV, 0, 3, 3); | |
76 | ||
77 | /* Standard Mode SCL High counter */ | |
78 | v = DIV_ROUND_UP_ULL(ss_scl_high * sfr, 1000000); | |
79 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_HCNT_1_ADDR, | |
80 | (v >> 8) & 0xff, 7, 0); | |
81 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_HCNT_0_ADDR, | |
82 | v & 0xff, 7, 0); | |
83 | ||
84 | /* Standard Mode SCL Low counter */ | |
85 | v = DIV_ROUND_UP_ULL(ss_scl_low * sfr, 1000000); | |
86 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_LCNT_1_ADDR, | |
87 | (v >> 8) & 0xff, 7, 0); | |
88 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_LCNT_0_ADDR, | |
89 | v & 0xff, 7, 0); | |
90 | ||
91 | /* Fast Mode SCL High Counter */ | |
92 | v = DIV_ROUND_UP_ULL(fs_scl_high * sfr, 1000000); | |
93 | REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_HCNT_1_ADDR, | |
94 | (v >> 8) & 0xff, 7, 0); | |
95 | REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_HCNT_0_ADDR, | |
96 | v & 0xff, 7, 0); | |
97 | ||
98 | /* Fast Mode SCL Low Counter */ | |
99 | v = DIV_ROUND_UP_ULL(fs_scl_low * sfr, 1000000); | |
100 | REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_LCNT_1_ADDR, | |
101 | (v >> 8) & 0xff, 7, 0); | |
102 | REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_LCNT_0_ADDR, | |
103 | v & 0xff, 7, 0); | |
104 | ||
105 | /* SDA Hold Time */ | |
106 | v = DIV_ROUND_UP_ULL(sda_hold * sfr, 1000000); | |
107 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SDA_HOLD_ADDR, v & 0xff, 7, 0); | |
108 | ||
109 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SLAVE, 0x50, 6, 0); | |
110 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SEGADDR, 0x30, 6, 0); | |
111 | ||
112 | /* NACK_POL to high */ | |
113 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 7, 7); | |
114 | ||
115 | /* NACK_MASK to unmasked */ | |
116 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x0, 6, 6); | |
117 | ||
118 | /* ARBITRATION_POL to high */ | |
119 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 3, 3); | |
120 | ||
121 | /* ARBITRATION_MASK to unmasked */ | |
122 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x0, 2, 2); | |
123 | ||
124 | /* DONE_POL to high */ | |
125 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 3, 3); | |
126 | ||
127 | /* DONE_MASK to unmasked */ | |
128 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x0, 2, 2); | |
129 | } | |
130 | ||
131 | static void hdmi_core_ddc_uninit(struct hdmi_core_data *core) | |
132 | { | |
133 | void __iomem *base = core->base; | |
134 | ||
135 | /* Mask I2C interrupts */ | |
136 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 6, 6); | |
137 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 2, 2); | |
138 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2); | |
139 | } | |
140 | ||
141 | static int hdmi_core_ddc_edid(struct hdmi_core_data *core, u8 *pedid, u8 ext) | |
142 | { | |
143 | void __iomem *base = core->base; | |
144 | u8 cur_addr; | |
145 | char checksum = 0; | |
146 | const int retries = 1000; | |
147 | u8 seg_ptr = ext / 2; | |
148 | u8 edidbase = ((ext % 2) * 0x80); | |
149 | ||
150 | REG_FLD_MOD(base, HDMI_CORE_I2CM_SEGPTR, seg_ptr, 7, 0); | |
151 | ||
152 | /* | |
153 | * TODO: We use polling here, although we probably should use proper | |
154 | * interrupts. | |
155 | */ | |
156 | for (cur_addr = 0; cur_addr < 128; ++cur_addr) { | |
157 | int i; | |
158 | ||
159 | /* clear ERROR and DONE */ | |
160 | REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0x3, 1, 0); | |
161 | ||
162 | REG_FLD_MOD(base, HDMI_CORE_I2CM_ADDRESS, | |
163 | edidbase + cur_addr, 7, 0); | |
164 | ||
165 | if (seg_ptr) | |
166 | REG_FLD_MOD(base, HDMI_CORE_I2CM_OPERATION, 1, 1, 1); | |
167 | else | |
168 | REG_FLD_MOD(base, HDMI_CORE_I2CM_OPERATION, 1, 0, 0); | |
169 | ||
170 | for (i = 0; i < retries; ++i) { | |
171 | u32 stat; | |
172 | ||
173 | stat = REG_GET(base, HDMI_CORE_IH_I2CM_STAT0, 1, 0); | |
174 | ||
175 | /* I2CM_ERROR */ | |
176 | if (stat & 1) { | |
177 | DSSERR("HDMI I2C Master Error\n"); | |
178 | return -EIO; | |
179 | } | |
180 | ||
181 | /* I2CM_DONE */ | |
182 | if (stat & (1 << 1)) | |
183 | break; | |
184 | ||
185 | usleep_range(250, 1000); | |
186 | } | |
187 | ||
188 | if (i == retries) { | |
189 | DSSERR("HDMI I2C timeout reading EDID\n"); | |
190 | return -EIO; | |
191 | } | |
192 | ||
193 | pedid[cur_addr] = REG_GET(base, HDMI_CORE_I2CM_DATAI, 7, 0); | |
194 | checksum += pedid[cur_addr]; | |
195 | } | |
196 | ||
197 | return 0; | |
198 | ||
199 | } | |
200 | ||
201 | int hdmi5_read_edid(struct hdmi_core_data *core, u8 *edid, int len) | |
202 | { | |
203 | int r, n, i; | |
204 | int max_ext_blocks = (len / 128) - 1; | |
205 | ||
206 | if (len < 128) | |
207 | return -EINVAL; | |
208 | ||
209 | hdmi_core_ddc_init(core); | |
210 | ||
211 | r = hdmi_core_ddc_edid(core, edid, 0); | |
212 | if (r) | |
213 | goto out; | |
214 | ||
215 | n = edid[0x7e]; | |
216 | ||
217 | if (n > max_ext_blocks) | |
218 | n = max_ext_blocks; | |
219 | ||
220 | for (i = 1; i <= n; i++) { | |
221 | r = hdmi_core_ddc_edid(core, edid + i * EDID_LENGTH, i); | |
222 | if (r) | |
223 | goto out; | |
224 | } | |
225 | ||
226 | out: | |
227 | hdmi_core_ddc_uninit(core); | |
228 | ||
229 | return r ? r : len; | |
230 | } | |
231 | ||
232 | void hdmi5_core_dump(struct hdmi_core_data *core, struct seq_file *s) | |
233 | { | |
234 | ||
235 | #define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\ | |
236 | hdmi_read_reg(core->base, r)) | |
237 | ||
238 | DUMPCORE(HDMI_CORE_FC_INVIDCONF); | |
239 | DUMPCORE(HDMI_CORE_FC_INHACTIV0); | |
240 | DUMPCORE(HDMI_CORE_FC_INHACTIV1); | |
241 | DUMPCORE(HDMI_CORE_FC_INHBLANK0); | |
242 | DUMPCORE(HDMI_CORE_FC_INHBLANK1); | |
243 | DUMPCORE(HDMI_CORE_FC_INVACTIV0); | |
244 | DUMPCORE(HDMI_CORE_FC_INVACTIV1); | |
245 | DUMPCORE(HDMI_CORE_FC_INVBLANK); | |
246 | DUMPCORE(HDMI_CORE_FC_HSYNCINDELAY0); | |
247 | DUMPCORE(HDMI_CORE_FC_HSYNCINDELAY1); | |
248 | DUMPCORE(HDMI_CORE_FC_HSYNCINWIDTH0); | |
249 | DUMPCORE(HDMI_CORE_FC_HSYNCINWIDTH1); | |
250 | DUMPCORE(HDMI_CORE_FC_VSYNCINDELAY); | |
251 | DUMPCORE(HDMI_CORE_FC_VSYNCINWIDTH); | |
252 | DUMPCORE(HDMI_CORE_FC_CTRLDUR); | |
253 | DUMPCORE(HDMI_CORE_FC_EXCTRLDUR); | |
254 | DUMPCORE(HDMI_CORE_FC_EXCTRLSPAC); | |
255 | DUMPCORE(HDMI_CORE_FC_CH0PREAM); | |
256 | DUMPCORE(HDMI_CORE_FC_CH1PREAM); | |
257 | DUMPCORE(HDMI_CORE_FC_CH2PREAM); | |
258 | DUMPCORE(HDMI_CORE_FC_AVICONF0); | |
259 | DUMPCORE(HDMI_CORE_FC_AVICONF1); | |
260 | DUMPCORE(HDMI_CORE_FC_AVICONF2); | |
261 | DUMPCORE(HDMI_CORE_FC_AVIVID); | |
262 | DUMPCORE(HDMI_CORE_FC_PRCONF); | |
263 | ||
264 | DUMPCORE(HDMI_CORE_MC_CLKDIS); | |
265 | DUMPCORE(HDMI_CORE_MC_SWRSTZREQ); | |
266 | DUMPCORE(HDMI_CORE_MC_FLOWCTRL); | |
267 | DUMPCORE(HDMI_CORE_MC_PHYRSTZ); | |
268 | DUMPCORE(HDMI_CORE_MC_LOCKONCLOCK); | |
269 | ||
270 | DUMPCORE(HDMI_CORE_I2CM_SLAVE); | |
271 | DUMPCORE(HDMI_CORE_I2CM_ADDRESS); | |
272 | DUMPCORE(HDMI_CORE_I2CM_DATAO); | |
273 | DUMPCORE(HDMI_CORE_I2CM_DATAI); | |
274 | DUMPCORE(HDMI_CORE_I2CM_OPERATION); | |
275 | DUMPCORE(HDMI_CORE_I2CM_INT); | |
276 | DUMPCORE(HDMI_CORE_I2CM_CTLINT); | |
277 | DUMPCORE(HDMI_CORE_I2CM_DIV); | |
278 | DUMPCORE(HDMI_CORE_I2CM_SEGADDR); | |
279 | DUMPCORE(HDMI_CORE_I2CM_SOFTRSTZ); | |
280 | DUMPCORE(HDMI_CORE_I2CM_SEGPTR); | |
281 | DUMPCORE(HDMI_CORE_I2CM_SS_SCL_HCNT_1_ADDR); | |
282 | DUMPCORE(HDMI_CORE_I2CM_SS_SCL_HCNT_0_ADDR); | |
283 | DUMPCORE(HDMI_CORE_I2CM_SS_SCL_LCNT_1_ADDR); | |
284 | DUMPCORE(HDMI_CORE_I2CM_SS_SCL_LCNT_0_ADDR); | |
285 | DUMPCORE(HDMI_CORE_I2CM_FS_SCL_HCNT_1_ADDR); | |
286 | DUMPCORE(HDMI_CORE_I2CM_FS_SCL_HCNT_0_ADDR); | |
287 | DUMPCORE(HDMI_CORE_I2CM_FS_SCL_LCNT_1_ADDR); | |
288 | DUMPCORE(HDMI_CORE_I2CM_FS_SCL_LCNT_0_ADDR); | |
289 | DUMPCORE(HDMI_CORE_I2CM_SDA_HOLD_ADDR); | |
290 | } | |
291 | ||
292 | static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg, | |
293 | struct hdmi_core_infoframe_avi *avi_cfg, | |
294 | struct hdmi_config *cfg) | |
295 | { | |
296 | DSSDBG("hdmi_core_init\n"); | |
297 | ||
298 | /* video core */ | |
299 | video_cfg->data_enable_pol = 1; /* It is always 1*/ | |
300 | video_cfg->v_fc_config.timings.hsync_level = cfg->timings.hsync_level; | |
301 | video_cfg->v_fc_config.timings.x_res = cfg->timings.x_res; | |
302 | video_cfg->v_fc_config.timings.hsw = cfg->timings.hsw - 1; | |
303 | video_cfg->v_fc_config.timings.hbp = cfg->timings.hbp; | |
304 | video_cfg->v_fc_config.timings.hfp = cfg->timings.hfp; | |
305 | video_cfg->hblank = cfg->timings.hfp + | |
306 | cfg->timings.hbp + cfg->timings.hsw - 1; | |
307 | video_cfg->v_fc_config.timings.vsync_level = cfg->timings.vsync_level; | |
308 | video_cfg->v_fc_config.timings.y_res = cfg->timings.y_res; | |
309 | video_cfg->v_fc_config.timings.vsw = cfg->timings.vsw; | |
310 | video_cfg->v_fc_config.timings.vfp = cfg->timings.vfp; | |
311 | video_cfg->v_fc_config.timings.vbp = cfg->timings.vbp; | |
312 | video_cfg->vblank_osc = 0; /* Always 0 - need to confirm */ | |
313 | video_cfg->vblank = cfg->timings.vsw + | |
314 | cfg->timings.vfp + cfg->timings.vbp; | |
315 | video_cfg->v_fc_config.cm.mode = cfg->cm.mode; | |
316 | video_cfg->v_fc_config.timings.interlace = cfg->timings.interlace; | |
317 | ||
318 | /* info frame */ | |
319 | avi_cfg->db1_format = 0; | |
320 | avi_cfg->db1_active_info = 0; | |
321 | avi_cfg->db1_bar_info_dv = 0; | |
322 | avi_cfg->db1_scan_info = 0; | |
323 | avi_cfg->db2_colorimetry = 0; | |
324 | avi_cfg->db2_aspect_ratio = 0; | |
325 | avi_cfg->db2_active_fmt_ar = 0; | |
326 | avi_cfg->db3_itc = 0; | |
327 | avi_cfg->db3_ec = 0; | |
328 | avi_cfg->db3_q_range = 0; | |
329 | avi_cfg->db3_nup_scaling = 0; | |
330 | avi_cfg->db4_videocode = 0; | |
331 | avi_cfg->db5_pixel_repeat = 0; | |
332 | avi_cfg->db6_7_line_eoftop = 0; | |
333 | avi_cfg->db8_9_line_sofbottom = 0; | |
334 | avi_cfg->db10_11_pixel_eofleft = 0; | |
335 | avi_cfg->db12_13_pixel_sofright = 0; | |
336 | } | |
337 | ||
338 | /* DSS_HDMI_CORE_VIDEO_CONFIG */ | |
339 | static void hdmi_core_video_config(struct hdmi_core_data *core, | |
340 | struct hdmi_core_vid_config *cfg) | |
341 | { | |
342 | void __iomem *base = core->base; | |
343 | unsigned char r = 0; | |
344 | bool vsync_pol, hsync_pol; | |
345 | ||
346 | vsync_pol = | |
347 | cfg->v_fc_config.timings.vsync_level == OMAPDSS_SIG_ACTIVE_HIGH; | |
348 | hsync_pol = | |
349 | cfg->v_fc_config.timings.hsync_level == OMAPDSS_SIG_ACTIVE_HIGH; | |
350 | ||
351 | /* Set hsync, vsync and data-enable polarity */ | |
352 | r = hdmi_read_reg(base, HDMI_CORE_FC_INVIDCONF); | |
353 | r = FLD_MOD(r, vsync_pol, 6, 6); | |
354 | r = FLD_MOD(r, hsync_pol, 5, 5); | |
355 | r = FLD_MOD(r, cfg->data_enable_pol, 4, 4); | |
356 | r = FLD_MOD(r, cfg->vblank_osc, 1, 1); | |
357 | r = FLD_MOD(r, cfg->v_fc_config.timings.interlace, 0, 0); | |
358 | hdmi_write_reg(base, HDMI_CORE_FC_INVIDCONF, r); | |
359 | ||
360 | /* set x resolution */ | |
361 | REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV1, | |
362 | cfg->v_fc_config.timings.x_res >> 8, 4, 0); | |
363 | REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV0, | |
364 | cfg->v_fc_config.timings.x_res & 0xFF, 7, 0); | |
365 | ||
366 | /* set y resolution */ | |
367 | REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV1, | |
368 | cfg->v_fc_config.timings.y_res >> 8, 4, 0); | |
369 | REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV0, | |
370 | cfg->v_fc_config.timings.y_res & 0xFF, 7, 0); | |
371 | ||
372 | /* set horizontal blanking pixels */ | |
373 | REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK1, cfg->hblank >> 8, 4, 0); | |
374 | REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK0, cfg->hblank & 0xFF, 7, 0); | |
375 | ||
376 | /* set vertial blanking pixels */ | |
377 | REG_FLD_MOD(base, HDMI_CORE_FC_INVBLANK, cfg->vblank, 7, 0); | |
378 | ||
379 | /* set horizontal sync offset */ | |
380 | REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY1, | |
381 | cfg->v_fc_config.timings.hfp >> 8, 4, 0); | |
382 | REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY0, | |
383 | cfg->v_fc_config.timings.hfp & 0xFF, 7, 0); | |
384 | ||
385 | /* set vertical sync offset */ | |
386 | REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINDELAY, | |
387 | cfg->v_fc_config.timings.vfp, 7, 0); | |
388 | ||
389 | /* set horizontal sync pulse width */ | |
390 | REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH1, | |
391 | (cfg->v_fc_config.timings.hsw >> 8), 1, 0); | |
392 | REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH0, | |
393 | cfg->v_fc_config.timings.hsw & 0xFF, 7, 0); | |
394 | ||
395 | /* set vertical sync pulse width */ | |
396 | REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINWIDTH, | |
397 | cfg->v_fc_config.timings.vsw, 5, 0); | |
398 | ||
399 | /* select DVI mode */ | |
400 | REG_FLD_MOD(base, HDMI_CORE_FC_INVIDCONF, | |
401 | cfg->v_fc_config.cm.mode, 3, 3); | |
402 | } | |
403 | ||
404 | static void hdmi_core_config_video_packetizer(struct hdmi_core_data *core) | |
405 | { | |
406 | void __iomem *base = core->base; | |
407 | int clr_depth = 0; /* 24 bit color depth */ | |
408 | ||
409 | /* COLOR_DEPTH */ | |
410 | REG_FLD_MOD(base, HDMI_CORE_VP_PR_CD, clr_depth, 7, 4); | |
411 | /* BYPASS_EN */ | |
412 | REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 1, 6, 6); | |
413 | /* PP_EN */ | |
414 | REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 1 : 0, 5, 5); | |
415 | /* YCC422_EN */ | |
416 | REG_FLD_MOD(base, HDMI_CORE_VP_CONF, 0, 3, 3); | |
417 | /* PP_STUFFING */ | |
418 | REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, clr_depth ? 1 : 0, 1, 1); | |
419 | /* YCC422_STUFFING */ | |
420 | REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, 1, 2, 2); | |
421 | /* OUTPUT_SELECTOR */ | |
422 | REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 2, 1, 0); | |
423 | } | |
424 | ||
425 | static void hdmi_core_config_csc(struct hdmi_core_data *core) | |
426 | { | |
427 | int clr_depth = 0; /* 24 bit color depth */ | |
428 | ||
429 | /* CSC_COLORDEPTH */ | |
430 | REG_FLD_MOD(core->base, HDMI_CORE_CSC_SCALE, clr_depth, 7, 4); | |
431 | } | |
432 | ||
433 | static void hdmi_core_config_video_sampler(struct hdmi_core_data *core) | |
434 | { | |
435 | int video_mapping = 1; /* for 24 bit color depth */ | |
436 | ||
437 | /* VIDEO_MAPPING */ | |
438 | REG_FLD_MOD(core->base, HDMI_CORE_TX_INVID0, video_mapping, 4, 0); | |
439 | } | |
440 | ||
441 | static void hdmi_core_aux_infoframe_avi_config(struct hdmi_core_data *core) | |
442 | { | |
443 | void __iomem *base = core->base; | |
444 | struct hdmi_core_infoframe_avi avi = core->avi_cfg; | |
445 | ||
446 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF0, avi.db1_format, 1, 0); | |
447 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF0, avi.db1_active_info, 6, 6); | |
448 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF0, avi.db1_bar_info_dv, 3, 2); | |
449 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF0, avi.db1_scan_info, 5, 4); | |
450 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF1, avi.db2_colorimetry, 7, 6); | |
451 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF1, avi.db2_aspect_ratio, 5, 4); | |
452 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF1, avi.db2_active_fmt_ar, 3, 0); | |
453 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF2, avi.db3_itc, 7, 7); | |
454 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF2, avi.db3_ec, 6, 4); | |
455 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF2, avi.db3_q_range, 3, 2); | |
456 | REG_FLD_MOD(base, HDMI_CORE_FC_AVICONF2, avi.db3_nup_scaling, 1, 0); | |
457 | REG_FLD_MOD(base, HDMI_CORE_FC_AVIVID, avi.db4_videocode, 6, 0); | |
458 | REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, avi.db5_pixel_repeat, 3, 0); | |
459 | } | |
460 | ||
461 | static void hdmi_core_csc_config(struct hdmi_core_data *core, | |
462 | struct csc_table csc_coeff) | |
463 | { | |
464 | void __iomem *base = core->base; | |
465 | ||
466 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_MSB, csc_coeff.a1 >> 8 , 6, 0); | |
467 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_LSB, csc_coeff.a1, 7, 0); | |
468 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_MSB, csc_coeff.a2 >> 8, 6, 0); | |
469 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_LSB, csc_coeff.a2, 7, 0); | |
470 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_MSB, csc_coeff.a3 >> 8, 6, 0); | |
471 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_LSB, csc_coeff.a3, 7, 0); | |
472 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_MSB, csc_coeff.a4 >> 8, 6, 0); | |
473 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_LSB, csc_coeff.a4, 7, 0); | |
474 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_MSB, csc_coeff.b1 >> 8, 6, 0); | |
475 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_LSB, csc_coeff.b1, 7, 0); | |
476 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_MSB, csc_coeff.b2 >> 8, 6, 0); | |
477 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_LSB, csc_coeff.b2, 7, 0); | |
478 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_MSB, csc_coeff.b3 >> 8, 6, 0); | |
479 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_LSB, csc_coeff.b3, 7, 0); | |
480 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_MSB, csc_coeff.b4 >> 8, 6, 0); | |
481 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_LSB, csc_coeff.b4, 7, 0); | |
482 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_MSB, csc_coeff.c1 >> 8, 6, 0); | |
483 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_LSB, csc_coeff.c1, 7, 0); | |
484 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_MSB, csc_coeff.c2 >> 8, 6, 0); | |
485 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_LSB, csc_coeff.c2, 7, 0); | |
486 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_MSB, csc_coeff.c3 >> 8, 6, 0); | |
487 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_LSB, csc_coeff.c3, 7, 0); | |
488 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_MSB, csc_coeff.c4 >> 8, 6, 0); | |
489 | REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_LSB, csc_coeff.c4, 7, 0); | |
490 | ||
491 | REG_FLD_MOD(base, HDMI_CORE_MC_FLOWCTRL, 0x1, 0, 0); | |
492 | } | |
493 | ||
494 | static void hdmi_core_configure_range(struct hdmi_core_data *core) | |
495 | { | |
496 | struct csc_table csc_coeff = { 0 }; | |
497 | ||
498 | /* support limited range with 24 bit color depth for now */ | |
499 | csc_coeff = csc_table_deepcolor[0]; | |
500 | core->avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_LR; | |
501 | ||
502 | hdmi_core_csc_config(core, csc_coeff); | |
503 | hdmi_core_aux_infoframe_avi_config(core); | |
504 | } | |
505 | ||
506 | static void hdmi_core_enable_video_path(struct hdmi_core_data *core) | |
507 | { | |
508 | void __iomem *base = core->base; | |
509 | ||
510 | DSSDBG("hdmi_core_enable_video_path\n"); | |
511 | ||
512 | REG_FLD_MOD(base, HDMI_CORE_FC_CTRLDUR, 0x0C, 7, 0); | |
513 | REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLDUR, 0x20, 7, 0); | |
514 | REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLSPAC, 0x01, 7, 0); | |
515 | REG_FLD_MOD(base, HDMI_CORE_FC_CH0PREAM, 0x0B, 7, 0); | |
516 | REG_FLD_MOD(base, HDMI_CORE_FC_CH1PREAM, 0x16, 5, 0); | |
517 | REG_FLD_MOD(base, HDMI_CORE_FC_CH2PREAM, 0x21, 5, 0); | |
518 | REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 0, 0); | |
519 | REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 1, 1); | |
520 | } | |
521 | ||
522 | static void hdmi_core_mask_interrupts(struct hdmi_core_data *core) | |
523 | { | |
524 | void __iomem *base = core->base; | |
525 | ||
526 | /* Master IRQ mask */ | |
527 | REG_FLD_MOD(base, HDMI_CORE_IH_MUTE, 0x3, 1, 0); | |
528 | ||
529 | /* Mask all the interrupts in HDMI core */ | |
530 | ||
531 | REG_FLD_MOD(base, HDMI_CORE_VP_MASK, 0xff, 7, 0); | |
532 | REG_FLD_MOD(base, HDMI_CORE_FC_MASK0, 0xe7, 7, 0); | |
533 | REG_FLD_MOD(base, HDMI_CORE_FC_MASK1, 0xfb, 7, 0); | |
534 | REG_FLD_MOD(base, HDMI_CORE_FC_MASK2, 0x3, 1, 0); | |
535 | ||
536 | REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 0x3, 3, 2); | |
537 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 0x3, 1, 0); | |
538 | ||
539 | REG_FLD_MOD(base, HDMI_CORE_CEC_MASK, 0x7f, 6, 0); | |
540 | ||
541 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 6, 6); | |
542 | REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 2, 2); | |
543 | REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2); | |
544 | ||
545 | REG_FLD_MOD(base, HDMI_CORE_PHY_MASK0, 0xf3, 7, 0); | |
546 | ||
547 | REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0); | |
548 | ||
549 | /* Clear all the current interrupt bits */ | |
550 | ||
551 | REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0); | |
552 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xe7, 7, 0); | |
553 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xfb, 7, 0); | |
554 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0x3, 1, 0); | |
555 | ||
556 | REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0x7, 2, 0); | |
557 | ||
558 | REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0x7f, 6, 0); | |
559 | ||
560 | REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0x3, 1, 0); | |
561 | ||
562 | REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0); | |
563 | } | |
564 | ||
565 | static void hdmi_core_enable_interrupts(struct hdmi_core_data *core) | |
566 | { | |
567 | /* Unmute interrupts */ | |
568 | REG_FLD_MOD(core->base, HDMI_CORE_IH_MUTE, 0x0, 1, 0); | |
569 | } | |
570 | ||
571 | int hdmi5_core_handle_irqs(struct hdmi_core_data *core) | |
572 | { | |
573 | void __iomem *base = core->base; | |
574 | ||
575 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xff, 7, 0); | |
576 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xff, 7, 0); | |
577 | REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0xff, 7, 0); | |
578 | REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0xff, 7, 0); | |
579 | REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0); | |
580 | REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0xff, 7, 0); | |
581 | REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0xff, 7, 0); | |
582 | REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0); | |
583 | REG_FLD_MOD(base, HDMI_CORE_IH_I2CMPHY_STAT0, 0xff, 7, 0); | |
584 | ||
585 | return 0; | |
586 | } | |
587 | ||
588 | void hdmi5_configure(struct hdmi_core_data *core, struct hdmi_wp_data *wp, | |
589 | struct hdmi_config *cfg) | |
590 | { | |
591 | struct omap_video_timings video_timing; | |
592 | struct hdmi_video_format video_format; | |
593 | struct hdmi_core_vid_config v_core_cfg; | |
594 | struct hdmi_core_infoframe_avi *avi_cfg = &core->avi_cfg; | |
595 | ||
596 | hdmi_core_mask_interrupts(core); | |
597 | ||
598 | hdmi_core_init(&v_core_cfg, avi_cfg, cfg); | |
599 | ||
600 | hdmi_wp_init_vid_fmt_timings(&video_format, &video_timing, cfg); | |
601 | ||
602 | hdmi_wp_video_config_timing(wp, &video_timing); | |
603 | ||
604 | /* video config */ | |
605 | video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422; | |
606 | ||
607 | hdmi_wp_video_config_format(wp, &video_format); | |
608 | ||
609 | hdmi_wp_video_config_interface(wp, &video_timing); | |
610 | ||
611 | hdmi_core_configure_range(core); | |
612 | ||
613 | /* | |
614 | * configure core video part, set software reset in the core | |
615 | */ | |
616 | v_core_cfg.packet_mode = HDMI_PACKETMODE24BITPERPIXEL; | |
617 | ||
618 | hdmi_core_video_config(core, &v_core_cfg); | |
619 | ||
620 | hdmi_core_config_video_packetizer(core); | |
621 | hdmi_core_config_csc(core); | |
622 | hdmi_core_config_video_sampler(core); | |
623 | ||
624 | /* | |
625 | * configure packet info frame video see doc CEA861-D page 65 | |
626 | */ | |
627 | avi_cfg->db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB; | |
628 | avi_cfg->db1_active_info = | |
629 | HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF; | |
630 | avi_cfg->db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO; | |
631 | avi_cfg->db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0; | |
632 | avi_cfg->db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO; | |
633 | avi_cfg->db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO; | |
634 | avi_cfg->db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME; | |
635 | avi_cfg->db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO; | |
636 | avi_cfg->db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601; | |
637 | avi_cfg->db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT; | |
638 | avi_cfg->db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO; | |
639 | avi_cfg->db4_videocode = cfg->cm.code; | |
640 | avi_cfg->db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO; | |
641 | avi_cfg->db6_7_line_eoftop = 0; | |
642 | avi_cfg->db8_9_line_sofbottom = 0; | |
643 | avi_cfg->db10_11_pixel_eofleft = 0; | |
644 | avi_cfg->db12_13_pixel_sofright = 0; | |
645 | ||
646 | hdmi_core_aux_infoframe_avi_config(core); | |
647 | ||
648 | hdmi_core_enable_video_path(core); | |
649 | ||
650 | hdmi_core_enable_interrupts(core); | |
651 | } | |
652 | ||
653 | ||
654 | #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO) | |
655 | ||
656 | static void hdmi5_core_audio_config(struct hdmi_core_data *core, | |
657 | struct hdmi_core_audio_config *cfg) | |
658 | { | |
659 | void __iomem *base = core->base; | |
660 | u8 val; | |
661 | ||
662 | /* Mute audio before configuring */ | |
663 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0xf, 7, 4); | |
664 | ||
665 | /* Set the N parameter */ | |
666 | REG_FLD_MOD(base, HDMI_CORE_AUD_N1, cfg->n, 7, 0); | |
667 | REG_FLD_MOD(base, HDMI_CORE_AUD_N2, cfg->n >> 8, 7, 0); | |
668 | REG_FLD_MOD(base, HDMI_CORE_AUD_N3, cfg->n >> 16, 3, 0); | |
669 | ||
670 | /* | |
671 | * CTS manual mode. Automatic mode is not supported when using audio | |
672 | * parallel interface. | |
673 | */ | |
674 | REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, 1, 4, 4); | |
675 | REG_FLD_MOD(base, HDMI_CORE_AUD_CTS1, cfg->cts, 7, 0); | |
676 | REG_FLD_MOD(base, HDMI_CORE_AUD_CTS2, cfg->cts >> 8, 7, 0); | |
677 | REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, cfg->cts >> 16, 3, 0); | |
678 | ||
679 | /* Layout of Audio Sample Packets: 2-channel or multichannels */ | |
680 | if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH) | |
681 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0, 0, 0); | |
682 | else | |
683 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 1, 0, 0); | |
684 | ||
685 | /* Configure IEC-609580 Validity bits */ | |
686 | /* Channel 0 is valid */ | |
687 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 0, 0); | |
688 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 4, 4); | |
689 | ||
690 | if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH) | |
691 | val = 1; | |
692 | else | |
693 | val = 0; | |
694 | ||
695 | /* Channels 1, 2 setting */ | |
696 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 1, 1); | |
697 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 5, 5); | |
698 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 2, 2); | |
699 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 6, 6); | |
700 | /* Channel 3 setting */ | |
701 | if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH) | |
702 | val = 1; | |
703 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 3, 3); | |
704 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 7, 7); | |
705 | ||
706 | /* Configure IEC-60958 User bits */ | |
707 | /* TODO: should be set by user. */ | |
708 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSU, 0, 7, 0); | |
709 | ||
710 | /* Configure IEC-60958 Channel Status word */ | |
711 | /* CGMSA */ | |
712 | val = cfg->iec60958_cfg->status[5] & IEC958_AES5_CON_CGMSA; | |
713 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 5, 4); | |
714 | ||
715 | /* Copyright */ | |
716 | val = (cfg->iec60958_cfg->status[0] & | |
717 | IEC958_AES0_CON_NOT_COPYRIGHT) >> 2; | |
718 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 0, 0); | |
719 | ||
720 | /* Category */ | |
721 | hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(1), | |
722 | cfg->iec60958_cfg->status[1]); | |
723 | ||
724 | /* PCM audio mode */ | |
725 | val = (cfg->iec60958_cfg->status[0] & IEC958_AES0_CON_MODE) >> 6; | |
726 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 6, 4); | |
727 | ||
728 | /* Source number */ | |
729 | val = cfg->iec60958_cfg->status[2] & IEC958_AES2_CON_SOURCE; | |
730 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 3, 4); | |
731 | ||
732 | /* Channel number right 0 */ | |
733 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 2, 3, 0); | |
734 | /* Channel number right 1*/ | |
735 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 4, 7, 4); | |
736 | /* Channel number right 2 */ | |
737 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 6, 3, 0); | |
738 | /* Channel number right 3*/ | |
739 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 8, 7, 4); | |
740 | /* Channel number left 0 */ | |
741 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 1, 3, 0); | |
742 | /* Channel number left 1*/ | |
743 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 3, 7, 4); | |
744 | /* Channel number left 2 */ | |
745 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 5, 3, 0); | |
746 | /* Channel number left 3*/ | |
747 | REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 7, 7, 4); | |
748 | ||
749 | /* Clock accuracy and sample rate */ | |
750 | hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(7), | |
751 | cfg->iec60958_cfg->status[3]); | |
752 | ||
753 | /* Original sample rate and word length */ | |
754 | hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(8), | |
755 | cfg->iec60958_cfg->status[4]); | |
756 | ||
757 | /* Enable FIFO empty and full interrupts */ | |
758 | REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 3, 3, 2); | |
759 | ||
760 | /* Configure GPA */ | |
761 | /* select HBR/SPDIF interfaces */ | |
762 | if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH) { | |
763 | /* select HBR/SPDIF interfaces */ | |
764 | REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5); | |
765 | /* enable two channels in GPA */ | |
766 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 3, 7, 0); | |
767 | } else if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH) { | |
768 | /* select HBR/SPDIF interfaces */ | |
769 | REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5); | |
770 | /* enable six channels in GPA */ | |
771 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0x3F, 7, 0); | |
772 | } else { | |
773 | /* select HBR/SPDIF interfaces */ | |
774 | REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5); | |
775 | /* enable eight channels in GPA */ | |
776 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0xFF, 7, 0); | |
777 | } | |
778 | ||
779 | /* disable HBR */ | |
780 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 0, 0, 0); | |
781 | /* enable PCUV */ | |
782 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 1, 1, 1); | |
783 | /* enable GPA FIFO full and empty mask */ | |
784 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 3, 1, 0); | |
785 | /* set polarity of GPA FIFO empty interrupts */ | |
786 | REG_FLD_MOD(base, HDMI_CORE_AUD_GP_POL, 1, 0, 0); | |
787 | ||
788 | /* unmute audio */ | |
789 | REG_FLD_MOD(core_sys_base, HDMI_CORE_FC_AUDSCONF, 0, 7, 4); | |
790 | } | |
791 | ||
792 | static void hdmi5_core_audio_infoframe_cfg(struct hdmi_core_data *core, | |
793 | struct snd_cea_861_aud_if *info_aud) | |
794 | { | |
795 | void __iomem *base = core->base; | |
796 | ||
797 | /* channel count and coding type fields in AUDICONF0 are swapped */ | |
798 | hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF0, | |
799 | (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC) << 4 | | |
800 | (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CT) >> 4); | |
801 | ||
802 | hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF1, info_aud->db2_sf_ss); | |
803 | hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF2, info_aud->db4_ca); | |
804 | hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF3, info_aud->db5_dminh_lsv); | |
805 | } | |
806 | ||
807 | int hdmi5_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp, | |
808 | struct omap_dss_audio *audio, u32 pclk) | |
809 | { | |
810 | struct hdmi_audio_format audio_format; | |
811 | struct hdmi_audio_dma audio_dma; | |
812 | struct hdmi_core_audio_config core_cfg; | |
813 | int err, n, cts, channel_count; | |
814 | unsigned int fs_nr; | |
815 | bool word_length_16b = false; | |
816 | ||
817 | if (!audio || !audio->iec || !audio->cea || !core) | |
818 | return -EINVAL; | |
819 | ||
820 | core_cfg.iec60958_cfg = audio->iec; | |
821 | ||
822 | if (!(audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24) && | |
823 | (audio->iec->status[4] & IEC958_AES4_CON_WORDLEN_20_16)) | |
824 | word_length_16b = true; | |
825 | ||
826 | /* only 16-bit word length supported atm */ | |
827 | if (!word_length_16b) | |
828 | return -EINVAL; | |
829 | ||
830 | switch (audio->iec->status[3] & IEC958_AES3_CON_FS) { | |
831 | case IEC958_AES3_CON_FS_32000: | |
832 | fs_nr = 32000; | |
833 | break; | |
834 | case IEC958_AES3_CON_FS_44100: | |
835 | fs_nr = 44100; | |
836 | break; | |
837 | case IEC958_AES3_CON_FS_48000: | |
838 | fs_nr = 48000; | |
839 | break; | |
840 | case IEC958_AES3_CON_FS_88200: | |
841 | fs_nr = 88200; | |
842 | break; | |
843 | case IEC958_AES3_CON_FS_96000: | |
844 | fs_nr = 96000; | |
845 | break; | |
846 | case IEC958_AES3_CON_FS_176400: | |
847 | fs_nr = 176400; | |
848 | break; | |
849 | case IEC958_AES3_CON_FS_192000: | |
850 | fs_nr = 192000; | |
851 | break; | |
852 | default: | |
853 | return -EINVAL; | |
854 | } | |
855 | ||
856 | err = hdmi_compute_acr(pclk, fs_nr, &n, &cts); | |
857 | core_cfg.n = n; | |
858 | core_cfg.cts = cts; | |
859 | ||
860 | /* Audio channels settings */ | |
861 | channel_count = (audio->cea->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC) | |
862 | + 1; | |
863 | ||
864 | if (channel_count == 2) | |
865 | core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH; | |
866 | else if (channel_count == 6) | |
867 | core_cfg.layout = HDMI_AUDIO_LAYOUT_6CH; | |
868 | else | |
869 | core_cfg.layout = HDMI_AUDIO_LAYOUT_8CH; | |
870 | ||
871 | /* DMA settings */ | |
872 | if (word_length_16b) | |
873 | audio_dma.transfer_size = 0x10; | |
874 | else | |
875 | audio_dma.transfer_size = 0x20; | |
876 | audio_dma.block_size = 0xC0; | |
877 | audio_dma.mode = HDMI_AUDIO_TRANSF_DMA; | |
878 | audio_dma.fifo_threshold = 0x20; /* in number of samples */ | |
879 | ||
880 | /* audio FIFO format settings for 16-bit samples*/ | |
881 | audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES; | |
882 | audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS; | |
883 | audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT; | |
884 | ||
885 | /* only LPCM atm */ | |
886 | audio_format.type = HDMI_AUDIO_TYPE_LPCM; | |
887 | ||
888 | /* disable start/stop signals of IEC 60958 blocks */ | |
889 | audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_ON; | |
890 | ||
891 | /* configure DMA and audio FIFO format*/ | |
892 | hdmi_wp_audio_config_dma(wp, &audio_dma); | |
893 | hdmi_wp_audio_config_format(wp, &audio_format); | |
894 | ||
895 | /* configure the core */ | |
896 | hdmi5_core_audio_config(core, &core_cfg); | |
897 | ||
898 | /* configure CEA 861 audio infoframe */ | |
899 | hdmi5_core_audio_infoframe_cfg(core, audio->cea); | |
900 | ||
901 | return 0; | |
902 | } | |
903 | #endif | |
904 | ||
905 | int hdmi5_core_init(struct platform_device *pdev, struct hdmi_core_data *core) | |
906 | { | |
907 | struct resource *res; | |
908 | ||
909 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); | |
910 | if (!res) { | |
911 | DSSERR("can't get CORE IORESOURCE_MEM HDMI\n"); | |
912 | return -EINVAL; | |
913 | } | |
914 | ||
915 | core->base = devm_request_and_ioremap(&pdev->dev, res); | |
916 | if (!core->base) { | |
917 | DSSERR("can't ioremap HDMI core\n"); | |
918 | return -ENOMEM; | |
919 | } | |
920 | ||
921 | return 0; | |
922 | } |