4 * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
7 * Mythri pk <mythripk@ti.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #define DSS_SUBSYS_NAME "HDMI"
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/err.h>
28 #include <linux/interrupt.h>
29 #include <linux/mutex.h>
30 #include <linux/delay.h>
31 #include <linux/string.h>
32 #include <linux/platform_device.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/clk.h>
35 #include <video/omapdss.h>
36 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
37 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
38 #include <sound/soc.h>
39 #include <sound/pcm_params.h>
44 #include "dss_features.h"
47 #define HDMI_CORE_SYS 0x400
48 #define HDMI_CORE_AV 0x900
49 #define HDMI_PLLCTRL 0x200
50 #define HDMI_PHY 0x300
52 /* HDMI EDID Length move this */
53 #define HDMI_EDID_MAX_LENGTH 256
54 #define EDID_TIMING_DESCRIPTOR_SIZE 0x12
55 #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
56 #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
57 #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
58 #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
60 #define OMAP_HDMI_TIMINGS_NB 34
64 struct omap_display_platform_data *pdata;
65 struct platform_device *pdev;
66 struct hdmi_ip_data ip_data;
69 u8 edid[HDMI_EDID_MAX_LENGTH];
77 * Logic for the below structure :
78 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
79 * There is a correspondence between CEA/VESA timing and code, please
80 * refer to section 6.3 in HDMI 1.3 specification for timing code.
82 * In the below structure, cea_vesa_timings corresponds to all OMAP4
83 * supported CEA and VESA timing values.code_cea corresponds to the CEA
84 * code, It is used to get the timing from cea_vesa_timing array.Similarly
85 * with code_vesa. Code_index is used for back mapping, that is once EDID
86 * is read from the TV, EDID is parsed to find the timing values and then
87 * map it to corresponding CEA or VESA index.
90 static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
91 { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
92 { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
93 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
94 { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
95 { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
96 { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
97 { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
98 { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
99 { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
100 { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
101 { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
102 { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
103 { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
104 { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
105 { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
107 { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
108 { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
109 { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
110 { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
111 { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
112 { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
113 { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
114 { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
115 { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
116 { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
117 { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
118 { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
119 { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
120 { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
121 { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
122 { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
123 { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
124 { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
125 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
129 * This is a static mapping array which maps the timing values
130 * with corresponding CEA / VESA code
132 static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
133 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
134 /* <--15 CEA 17--> vesa*/
135 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
136 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
140 * This is reverse static mapping which maps the CEA / VESA code
141 * to the corresponding timing values
143 static const int code_cea[39] = {
144 -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
145 -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
146 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
147 11, 12, 14, -1, -1, 13, 13, 4, 4
150 static const int code_vesa[85] = {
151 -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
152 -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
153 -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
154 -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
155 -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
163 static int hdmi_runtime_get(void)
167 DSSDBG("hdmi_runtime_get\n");
169 r = pm_runtime_get_sync(&hdmi.pdev->dev);
171 return r < 0 ? r : 0;
174 static void hdmi_runtime_put(void)
178 DSSDBG("hdmi_runtime_put\n");
180 r = pm_runtime_put(&hdmi.pdev->dev);
184 int hdmi_init_display(struct omap_dss_device *dssdev)
186 DSSDBG("init_display\n");
191 static void copy_hdmi_to_dss_timings(
192 const struct hdmi_video_timings *hdmi_timings,
193 struct omap_video_timings *timings)
195 timings->x_res = hdmi_timings->x_res;
196 timings->y_res = hdmi_timings->y_res;
197 timings->pixel_clock = hdmi_timings->pixel_clock;
198 timings->hbp = hdmi_timings->hbp;
199 timings->hfp = hdmi_timings->hfp;
200 timings->hsw = hdmi_timings->hsw;
201 timings->vbp = hdmi_timings->vbp;
202 timings->vfp = hdmi_timings->vfp;
203 timings->vsw = hdmi_timings->vsw;
206 static int get_timings_index(void)
211 code = code_vesa[hdmi.code];
213 code = code_cea[hdmi.code];
216 /* HDMI code 4 corresponds to 640 * 480 VGA */
218 /* DVI mode 1 corresponds to HDMI 0 to DVI */
219 hdmi.mode = HDMI_DVI;
221 code = code_vesa[hdmi.code];
226 static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
228 int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
229 int timing_vsync = 0, timing_hsync = 0;
230 struct hdmi_video_timings temp;
231 struct hdmi_cm cm = {-1};
232 DSSDBG("hdmi_get_code\n");
234 for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
235 temp = cea_vesa_timings[i].timings;
236 if ((temp.pixel_clock == timing->pixel_clock) &&
237 (temp.x_res == timing->x_res) &&
238 (temp.y_res == timing->y_res)) {
240 temp_hsync = temp.hfp + temp.hsw + temp.hbp;
241 timing_hsync = timing->hfp + timing->hsw + timing->hbp;
242 temp_vsync = temp.vfp + temp.vsw + temp.vbp;
243 timing_vsync = timing->vfp + timing->vsw + timing->vbp;
245 DSSDBG("temp_hsync = %d , temp_vsync = %d"
246 "timing_hsync = %d, timing_vsync = %d\n",
247 temp_hsync, temp_hsync,
248 timing_hsync, timing_vsync);
250 if ((temp_hsync == timing_hsync) &&
251 (temp_vsync == timing_vsync)) {
253 cm.code = code_index[i];
258 DSSDBG("Hdmi_code = %d mode = %d\n",
268 static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
269 struct omap_video_timings *timings)
271 /* X and Y resolution */
272 timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
273 edid[current_descriptor_addrs + 2]);
274 timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
275 edid[current_descriptor_addrs + 5]);
277 timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
278 edid[current_descriptor_addrs]);
280 timings->pixel_clock = 10 * timings->pixel_clock;
282 /* HORIZONTAL FRONT PORCH */
283 timings->hfp = edid[current_descriptor_addrs + 8] |
284 ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
285 /* HORIZONTAL SYNC WIDTH */
286 timings->hsw = edid[current_descriptor_addrs + 9] |
287 ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
288 /* HORIZONTAL BACK PORCH */
289 timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
290 edid[current_descriptor_addrs + 3]) -
291 (timings->hfp + timings->hsw);
292 /* VERTICAL FRONT PORCH */
293 timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
294 ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
295 /* VERTICAL SYNC WIDTH */
296 timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
297 ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
298 /* VERTICAL BACK PORCH */
299 timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
300 edid[current_descriptor_addrs + 6]) -
301 (timings->vfp + timings->vsw);
305 /* Description : This function gets the resolution information from EDID */
306 static void get_edid_timing_data(u8 *edid)
309 u16 current_descriptor_addrs;
311 struct omap_video_timings edid_timings;
313 /* search block 0, there are 4 DTDs arranged in priority order */
314 for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
315 current_descriptor_addrs =
316 EDID_DESCRIPTOR_BLOCK0_ADDRESS +
317 count * EDID_TIMING_DESCRIPTOR_SIZE;
318 get_horz_vert_timing_info(current_descriptor_addrs,
319 edid, &edid_timings);
320 cm = hdmi_get_code(&edid_timings);
321 DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
322 count, cm.code, cm.mode);
328 DSSDBG("code = %d , mode = %d\n",
329 hdmi.code, hdmi.mode);
333 if (edid[0x7e] != 0x00) {
334 for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
336 current_descriptor_addrs =
337 EDID_DESCRIPTOR_BLOCK1_ADDRESS +
338 count * EDID_TIMING_DESCRIPTOR_SIZE;
339 get_horz_vert_timing_info(current_descriptor_addrs,
340 edid, &edid_timings);
341 cm = hdmi_get_code(&edid_timings);
342 DSSDBG("Block1[%d] value matches code = %d, mode = %d",
343 count, cm.code, cm.mode);
349 DSSDBG("code = %d , mode = %d\n",
350 hdmi.code, hdmi.mode);
356 DSSINFO("no valid timing found , falling back to VGA\n");
357 hdmi.code = 4; /* setting default value of 640 480 VGA */
358 hdmi.mode = HDMI_DVI;
361 static void hdmi_read_edid(struct omap_video_timings *dp)
365 memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
368 ret = read_edid(&hdmi.ip_data, hdmi.edid,
369 HDMI_EDID_MAX_LENGTH);
371 if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
372 /* search for timings of default resolution */
373 get_edid_timing_data(hdmi.edid);
374 hdmi.edid_set = true;
377 DSSWARN("failed to read E-EDID\n");
380 if (!hdmi.edid_set) {
381 DSSINFO("fallback to VGA\n");
382 hdmi.code = 4; /* setting default value of 640 480 VGA */
383 hdmi.mode = HDMI_DVI;
386 code = get_timings_index();
388 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings, dp);
392 static void update_hdmi_timings(struct hdmi_config *cfg,
393 struct omap_video_timings *timings, int code)
395 cfg->timings.timings.x_res = timings->x_res;
396 cfg->timings.timings.y_res = timings->y_res;
397 cfg->timings.timings.hbp = timings->hbp;
398 cfg->timings.timings.hfp = timings->hfp;
399 cfg->timings.timings.hsw = timings->hsw;
400 cfg->timings.timings.vbp = timings->vbp;
401 cfg->timings.timings.vfp = timings->vfp;
402 cfg->timings.timings.vsw = timings->vsw;
403 cfg->timings.timings.pixel_clock = timings->pixel_clock;
404 cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
405 cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
408 static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
409 struct hdmi_pll_info *pi)
411 unsigned long clkin, refclk;
414 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
416 * Input clock is predivided by N + 1
417 * out put of which is reference clk
419 pi->regn = dssdev->clocks.hdmi.regn;
420 refclk = clkin / (pi->regn + 1);
423 * multiplier is pixel_clk/ref_clk
424 * Multiplying by 100 to avoid fractional part removal
426 pi->regm = (phy * 100 / (refclk)) / 100;
427 pi->regm2 = dssdev->clocks.hdmi.regm2;
430 * fractional multiplier is remainder of the difference between
431 * multiplier and actual phy(required pixel clock thus should be
432 * multiplied by 2^18(262144) divided by the reference clock
434 mf = (phy - pi->regm * refclk) * 262144;
435 pi->regmf = mf / (refclk);
438 * Dcofreq should be set to 1 if required pixel clock
439 * is greater than 1000MHz
441 pi->dcofreq = phy > 1000 * 100;
442 pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
444 /* Set the reference clock to sysclk reference */
445 pi->refsel = HDMI_REFSEL_SYSCLK;
447 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
448 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
451 static int hdmi_power_on(struct omap_dss_device *dssdev)
454 struct omap_video_timings *p;
457 r = hdmi_runtime_get();
461 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
463 p = &dssdev->panel.timings;
465 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
466 dssdev->panel.timings.x_res,
467 dssdev->panel.timings.y_res);
469 if (!hdmi.custom_set) {
470 DSSDBG("Read EDID as no EDID is not set on poweron\n");
473 code = get_timings_index();
474 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings,
475 &dssdev->panel.timings);
476 update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
478 phy = p->pixel_clock;
480 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
482 hdmi_wp_video_start(&hdmi.ip_data, 0);
484 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
485 r = hdmi_pll_program(&hdmi.ip_data);
487 DSSDBG("Failed to lock PLL\n");
491 r = hdmi_phy_init(&hdmi.ip_data);
493 DSSDBG("Failed to start PHY\n");
497 hdmi.ip_data.cfg.cm.mode = hdmi.mode;
498 hdmi.ip_data.cfg.cm.code = hdmi.code;
499 hdmi_basic_configure(&hdmi.ip_data);
501 /* Make selection of HDMI in DSS */
502 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
504 /* Select the dispc clock source as PRCM clock, to ensure that it is not
505 * DSI PLL source as the clock selected by DSI PLL might not be
506 * sufficient for the resolution selected / that can be changed
507 * dynamically by user. This can be moved to single location , say
510 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
512 /* bypass TV gamma table */
513 dispc_enable_gamma_table(0);
516 dispc_set_digit_size(dssdev->panel.timings.x_res,
517 dssdev->panel.timings.y_res);
519 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
521 hdmi_wp_video_start(&hdmi.ip_data, 1);
529 static void hdmi_power_off(struct omap_dss_device *dssdev)
531 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
533 hdmi_wp_video_start(&hdmi.ip_data, 0);
534 hdmi_phy_off(&hdmi.ip_data);
535 hdmi_set_pll_pwr(&hdmi.ip_data, HDMI_PLLPWRCMD_ALLOFF);
541 int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
542 struct omap_video_timings *timings)
546 cm = hdmi_get_code(timings);
548 DSSERR("Invalid timing entered\n");
556 void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
561 cm = hdmi_get_code(&dssdev->panel.timings);
564 omapdss_hdmi_display_enable(dssdev);
568 int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
572 DSSDBG("ENTER hdmi_display_enable\n");
574 mutex_lock(&hdmi.lock);
576 if (dssdev->manager == NULL) {
577 DSSERR("failed to enable display: no manager\n");
582 r = omap_dss_start_device(dssdev);
584 DSSERR("failed to start device\n");
588 if (dssdev->platform_enable) {
589 r = dssdev->platform_enable(dssdev);
591 DSSERR("failed to enable GPIO's\n");
596 r = hdmi_power_on(dssdev);
598 DSSERR("failed to power on device\n");
602 mutex_unlock(&hdmi.lock);
606 if (dssdev->platform_disable)
607 dssdev->platform_disable(dssdev);
609 omap_dss_stop_device(dssdev);
611 mutex_unlock(&hdmi.lock);
615 void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
617 DSSDBG("Enter hdmi_display_disable\n");
619 mutex_lock(&hdmi.lock);
621 hdmi_power_off(dssdev);
623 if (dssdev->platform_disable)
624 dssdev->platform_disable(dssdev);
626 omap_dss_stop_device(dssdev);
628 mutex_unlock(&hdmi.lock);
631 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
632 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
633 static void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
634 struct hdmi_audio_format *aud_fmt)
638 DSSDBG("Enter hdmi_wp_audio_config_format\n");
640 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
641 r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
642 r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
643 r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
644 r = FLD_MOD(r, aud_fmt->type, 4, 4);
645 r = FLD_MOD(r, aud_fmt->justification, 3, 3);
646 r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
647 r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
648 r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
649 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
652 static void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
653 struct hdmi_audio_dma *aud_dma)
657 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
659 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
660 r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
661 r = FLD_MOD(r, aud_dma->block_size, 7, 0);
662 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
664 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
665 r = FLD_MOD(r, aud_dma->mode, 9, 9);
666 r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
667 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
670 static void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
671 struct hdmi_core_audio_config *cfg)
674 void __iomem *av_base = hdmi_av_base(ip_data);
676 /* audio clock recovery parameters */
677 r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
678 r = FLD_MOD(r, cfg->use_mclk, 2, 2);
679 r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
680 r = FLD_MOD(r, cfg->cts_mode, 0, 0);
681 hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
683 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
684 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
685 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
687 if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
688 REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
690 HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
692 HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
695 * HDMI IP uses this configuration to divide the MCLK to
699 HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
701 /* Configure clock for audio packets */
702 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
703 cfg->aud_par_busclk, 7, 0);
704 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
705 (cfg->aud_par_busclk >> 8), 7, 0);
706 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
707 (cfg->aud_par_busclk >> 16), 7, 0);
710 /* Override of SPDIF sample frequency with value in I2S_CHST4 */
711 REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
712 cfg->fs_override, 1, 1);
715 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
716 cfg->freq_sample, 3, 0);
718 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
719 r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
720 r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
721 r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
722 r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
723 r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
724 r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
725 r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
726 r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
727 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
729 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
730 r = FLD_MOD(r, cfg->freq_sample, 7, 4);
731 r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
732 r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
733 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
735 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
736 cfg->i2s_cfg.in_length_bits, 3, 0);
738 /* Audio channels and mode parameters */
739 REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
740 r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
741 r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
742 r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
743 r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
744 r = FLD_MOD(r, cfg->en_spdif, 1, 1);
745 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
748 static void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
749 struct hdmi_core_infoframe_audio *info_aud)
752 u8 sum = 0, checksum = 0;
753 void __iomem *av_base = hdmi_av_base(ip_data);
756 * Set audio info frame type, version and length as
757 * described in HDMI 1.4a Section 8.2.2 specification.
758 * Checksum calculation is defined in Section 5.3.5.
760 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
761 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
762 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
763 sum += 0x84 + 0x001 + 0x00a;
765 val = (info_aud->db1_coding_type << 4)
766 | (info_aud->db1_channel_count - 1);
767 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
770 val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
771 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
774 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
776 val = info_aud->db4_channel_alloc;
777 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
780 val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
781 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
784 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
785 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
786 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
787 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
788 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
790 checksum = 0x100 - sum;
791 hdmi_write_reg(av_base,
792 HDMI_CORE_AV_AUDIO_CHSUM, checksum);
795 * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
800 static int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
801 u32 sample_freq, u32 *n, u32 *cts)
805 u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
807 if (n == NULL || cts == NULL)
810 * Obtain current deep color configuration. This needed
811 * to calculate the TMDS clock based on the pixel clock.
813 r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
815 case 1: /* No deep color selected */
818 case 2: /* 10-bit deep color selected */
821 case 3: /* 12-bit deep color selected */
828 switch (sample_freq) {
830 if ((deep_color == 125) && ((pclk == 54054)
840 if ((deep_color == 125) && ((pclk == 54054)
851 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
852 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
857 static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
858 struct snd_pcm_substream *substream,
859 struct snd_pcm_hw_params *params,
860 struct snd_soc_dai *dai)
862 struct hdmi_audio_format audio_format;
863 struct hdmi_audio_dma audio_dma;
864 struct hdmi_core_audio_config core_cfg;
865 struct hdmi_core_infoframe_audio aud_if_cfg;
867 enum hdmi_core_audio_sample_freq sample_freq;
869 switch (params_format(params)) {
870 case SNDRV_PCM_FORMAT_S16_LE:
871 core_cfg.i2s_cfg.word_max_length =
872 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
873 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
874 core_cfg.i2s_cfg.in_length_bits =
875 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
876 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
877 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
878 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
879 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
880 audio_dma.transfer_size = 0x10;
882 case SNDRV_PCM_FORMAT_S24_LE:
883 core_cfg.i2s_cfg.word_max_length =
884 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
885 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
886 core_cfg.i2s_cfg.in_length_bits =
887 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
888 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
889 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
890 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
891 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
892 audio_dma.transfer_size = 0x20;
898 switch (params_rate(params)) {
900 sample_freq = HDMI_AUDIO_FS_32000;
903 sample_freq = HDMI_AUDIO_FS_44100;
906 sample_freq = HDMI_AUDIO_FS_48000;
912 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
916 /* Audio wrapper config */
917 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
918 audio_format.active_chnnls_msk = 0x03;
919 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
920 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
921 /* Disable start/stop signals of IEC 60958 blocks */
922 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
924 audio_dma.block_size = 0xC0;
925 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
926 audio_dma.fifo_threshold = 0x20; /* in number of samples */
928 hdmi_wp_audio_config_dma(ip_data, &audio_dma);
929 hdmi_wp_audio_config_format(ip_data, &audio_format);
934 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
935 /* Only used with high bitrate audio */
936 core_cfg.i2s_cfg.cbit_order = false;
937 /* Serial data and word select should change on sck rising edge */
938 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
939 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
940 /* Set I2S word select polarity */
941 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
942 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
943 /* Set serial data to word select shift. See Phillips spec. */
944 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
945 /* Enable one of the four available serial data channels */
946 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
948 /* Core audio config */
949 core_cfg.freq_sample = sample_freq;
952 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
953 core_cfg.aud_par_busclk = 0;
954 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
955 core_cfg.use_mclk = false;
957 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
958 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
959 core_cfg.use_mclk = true;
960 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
962 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
963 core_cfg.en_spdif = false;
964 /* Use sample frequency from channel status word */
965 core_cfg.fs_override = true;
966 /* Enable ACR packets */
967 core_cfg.en_acr_pkt = true;
968 /* Disable direct streaming digital audio */
969 core_cfg.en_dsd_audio = false;
970 /* Use parallel audio interface */
971 core_cfg.en_parallel_aud_input = true;
973 hdmi_core_audio_config(ip_data, &core_cfg);
977 * info frame audio see doc CEA861-D page 74
979 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
980 aud_if_cfg.db1_channel_count = 2;
981 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
982 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
983 aud_if_cfg.db4_channel_alloc = 0x00;
984 aud_if_cfg.db5_downmix_inh = false;
985 aud_if_cfg.db5_lsv = 0;
987 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
991 static int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
992 struct snd_pcm_substream *substream, int cmd,
993 struct snd_soc_dai *dai)
997 case SNDRV_PCM_TRIGGER_START:
998 case SNDRV_PCM_TRIGGER_RESUME:
999 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1000 REG_FLD_MOD(hdmi_av_base(ip_data),
1001 HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
1002 REG_FLD_MOD(hdmi_wp_base(ip_data),
1003 HDMI_WP_AUDIO_CTRL, 1, 31, 31);
1004 REG_FLD_MOD(hdmi_wp_base(ip_data),
1005 HDMI_WP_AUDIO_CTRL, 1, 30, 30);
1008 case SNDRV_PCM_TRIGGER_STOP:
1009 case SNDRV_PCM_TRIGGER_SUSPEND:
1010 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1011 REG_FLD_MOD(hdmi_av_base(ip_data),
1012 HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
1013 REG_FLD_MOD(hdmi_wp_base(ip_data),
1014 HDMI_WP_AUDIO_CTRL, 0, 30, 30);
1015 REG_FLD_MOD(hdmi_wp_base(ip_data),
1016 HDMI_WP_AUDIO_CTRL, 0, 31, 31);
1024 static int hdmi_audio_startup(struct snd_pcm_substream *substream,
1025 struct snd_soc_dai *dai)
1028 pr_err("Current video settings do not support audio.\n");
1034 static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
1037 static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
1038 .hw_params = hdmi_audio_hw_params,
1039 .trigger = hdmi_audio_trigger,
1040 .startup = hdmi_audio_startup,
1043 static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
1044 .name = "hdmi-audio-codec",
1048 .rates = SNDRV_PCM_RATE_32000 |
1049 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
1050 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1051 SNDRV_PCM_FMTBIT_S24_LE,
1053 .ops = &hdmi_audio_codec_ops,
1057 static int hdmi_get_clocks(struct platform_device *pdev)
1061 clk = clk_get(&pdev->dev, "sys_clk");
1063 DSSERR("can't get sys_clk\n");
1064 return PTR_ERR(clk);
1072 static void hdmi_put_clocks(void)
1075 clk_put(hdmi.sys_clk);
1078 /* HDMI HW IP initialisation */
1079 static int omapdss_hdmihw_probe(struct platform_device *pdev)
1081 struct resource *hdmi_mem;
1084 hdmi.pdata = pdev->dev.platform_data;
1087 mutex_init(&hdmi.lock);
1089 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1091 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1095 /* Base address taken from platform */
1096 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
1097 resource_size(hdmi_mem));
1098 if (!hdmi.ip_data.base_wp) {
1099 DSSERR("can't ioremap WP\n");
1103 r = hdmi_get_clocks(pdev);
1105 iounmap(hdmi.ip_data.base_wp);
1109 pm_runtime_enable(&pdev->dev);
1111 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1112 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1113 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1114 hdmi.ip_data.phy_offset = HDMI_PHY;
1118 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1119 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1121 /* Register ASoC codec DAI */
1122 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
1123 &hdmi_codec_dai_drv, 1);
1125 DSSERR("can't register ASoC HDMI audio codec\n");
1132 static int omapdss_hdmihw_remove(struct platform_device *pdev)
1136 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1137 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1138 snd_soc_unregister_codec(&pdev->dev);
1141 pm_runtime_disable(&pdev->dev);
1145 iounmap(hdmi.ip_data.base_wp);
1150 static int hdmi_runtime_suspend(struct device *dev)
1152 clk_disable(hdmi.sys_clk);
1154 dispc_runtime_put();
1160 static int hdmi_runtime_resume(struct device *dev)
1164 r = dss_runtime_get();
1168 r = dispc_runtime_get();
1173 clk_enable(hdmi.sys_clk);
1183 static const struct dev_pm_ops hdmi_pm_ops = {
1184 .runtime_suspend = hdmi_runtime_suspend,
1185 .runtime_resume = hdmi_runtime_resume,
1188 static struct platform_driver omapdss_hdmihw_driver = {
1189 .probe = omapdss_hdmihw_probe,
1190 .remove = omapdss_hdmihw_remove,
1192 .name = "omapdss_hdmi",
1193 .owner = THIS_MODULE,
1198 int hdmi_init_platform_driver(void)
1200 return platform_driver_register(&omapdss_hdmihw_driver);
1203 void hdmi_uninit_platform_driver(void)
1205 return platform_driver_unregister(&omapdss_hdmihw_driver);