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"
48 struct omap_display_platform_data
*pdata
;
49 struct platform_device
*pdev
;
50 void __iomem
*base_wp
; /* HDMI wrapper */
53 u8 edid
[HDMI_EDID_MAX_LENGTH
];
56 struct hdmi_config cfg
;
63 * Logic for the below structure :
64 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
65 * There is a correspondence between CEA/VESA timing and code, please
66 * refer to section 6.3 in HDMI 1.3 specification for timing code.
68 * In the below structure, cea_vesa_timings corresponds to all OMAP4
69 * supported CEA and VESA timing values.code_cea corresponds to the CEA
70 * code, It is used to get the timing from cea_vesa_timing array.Similarly
71 * with code_vesa. Code_index is used for back mapping, that is once EDID
72 * is read from the TV, EDID is parsed to find the timing values and then
73 * map it to corresponding CEA or VESA index.
76 static const struct hdmi_timings cea_vesa_timings
[OMAP_HDMI_TIMINGS_NB
] = {
77 { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
78 { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
79 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
80 { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
81 { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
82 { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
83 { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
84 { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
85 { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
86 { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
87 { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
88 { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
89 { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
90 { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
91 { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
93 { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
94 { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
95 { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
96 { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
97 { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
98 { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
99 { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
100 { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
101 { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
102 { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
103 { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
104 { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
105 { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
106 { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
107 { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
108 { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
109 { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
110 { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
111 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
115 * This is a static mapping array which maps the timing values
116 * with corresponding CEA / VESA code
118 static const int code_index
[OMAP_HDMI_TIMINGS_NB
] = {
119 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
120 /* <--15 CEA 17--> vesa*/
121 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
122 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
126 * This is reverse static mapping which maps the CEA / VESA code
127 * to the corresponding timing values
129 static const int code_cea
[39] = {
130 -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
131 -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
132 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
133 11, 12, 14, -1, -1, 13, 13, 4, 4
136 static const int code_vesa
[85] = {
137 -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
138 -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
139 -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
140 -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
141 -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
142 -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
143 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
144 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
147 static const u8 edid_header
[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
149 static inline void hdmi_write_reg(const struct hdmi_reg idx
, u32 val
)
151 __raw_writel(val
, hdmi
.base_wp
+ idx
.idx
);
154 static inline u32
hdmi_read_reg(const struct hdmi_reg idx
)
156 return __raw_readl(hdmi
.base_wp
+ idx
.idx
);
159 static inline int hdmi_wait_for_bit_change(const struct hdmi_reg idx
,
160 int b2
, int b1
, u32 val
)
163 while (val
!= REG_GET(idx
, b2
, b1
)) {
171 static int hdmi_runtime_get(void)
175 DSSDBG("hdmi_runtime_get\n");
177 r
= pm_runtime_get_sync(&hdmi
.pdev
->dev
);
179 return r
< 0 ? r
: 0;
182 static void hdmi_runtime_put(void)
186 DSSDBG("hdmi_runtime_put\n");
188 r
= pm_runtime_put(&hdmi
.pdev
->dev
);
192 int hdmi_init_display(struct omap_dss_device
*dssdev
)
194 DSSDBG("init_display\n");
199 static int hdmi_pll_init(enum hdmi_clk_refsel refsel
, int dcofreq
,
200 struct hdmi_pll_info
*fmt
, u16 sd
)
204 /* PLL start always use manual mode */
205 REG_FLD_MOD(PLLCTRL_PLL_CONTROL
, 0x0, 0, 0);
207 r
= hdmi_read_reg(PLLCTRL_CFG1
);
208 r
= FLD_MOD(r
, fmt
->regm
, 20, 9); /* CFG1_PLL_REGM */
209 r
= FLD_MOD(r
, fmt
->regn
, 8, 1); /* CFG1_PLL_REGN */
211 hdmi_write_reg(PLLCTRL_CFG1
, r
);
213 r
= hdmi_read_reg(PLLCTRL_CFG2
);
215 r
= FLD_MOD(r
, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
216 r
= FLD_MOD(r
, 0x1, 13, 13); /* PLL_REFEN */
217 r
= FLD_MOD(r
, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
220 /* divider programming for frequency beyond 1000Mhz */
221 REG_FLD_MOD(PLLCTRL_CFG3
, sd
, 17, 10);
222 r
= FLD_MOD(r
, 0x4, 3, 1); /* 1000MHz and 2000MHz */
224 r
= FLD_MOD(r
, 0x2, 3, 1); /* 500MHz and 1000MHz */
227 hdmi_write_reg(PLLCTRL_CFG2
, r
);
229 r
= hdmi_read_reg(PLLCTRL_CFG4
);
230 r
= FLD_MOD(r
, fmt
->regm2
, 24, 18);
231 r
= FLD_MOD(r
, fmt
->regmf
, 17, 0);
233 hdmi_write_reg(PLLCTRL_CFG4
, r
);
236 REG_FLD_MOD(PLLCTRL_PLL_GO
, 0x1, 0, 0);
238 /* wait for bit change */
239 if (hdmi_wait_for_bit_change(PLLCTRL_PLL_GO
, 0, 0, 1) != 1) {
240 DSSERR("PLL GO bit not set\n");
244 /* Wait till the lock bit is set in PLL status */
245 if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS
, 1, 1, 1) != 1) {
246 DSSWARN("cannot lock PLL\n");
247 DSSWARN("CFG1 0x%x\n",
248 hdmi_read_reg(PLLCTRL_CFG1
));
249 DSSWARN("CFG2 0x%x\n",
250 hdmi_read_reg(PLLCTRL_CFG2
));
251 DSSWARN("CFG4 0x%x\n",
252 hdmi_read_reg(PLLCTRL_CFG4
));
256 DSSDBG("PLL locked!\n");
262 static int hdmi_set_phy_pwr(enum hdmi_phy_pwr val
)
264 /* Command for power control of HDMI PHY */
265 REG_FLD_MOD(HDMI_WP_PWR_CTRL
, val
, 7, 6);
267 /* Status of the power control of HDMI PHY */
268 if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL
, 5, 4, val
) != val
) {
269 DSSERR("Failed to set PHY power mode to %d\n", val
);
277 static int hdmi_set_pll_pwr(enum hdmi_pll_pwr val
)
279 /* Command for power control of HDMI PLL */
280 REG_FLD_MOD(HDMI_WP_PWR_CTRL
, val
, 3, 2);
282 /* wait till PHY_PWR_STATUS is set */
283 if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL
, 1, 0, val
) != val
) {
284 DSSERR("Failed to set PHY_PWR_STATUS\n");
291 static int hdmi_pll_reset(void)
293 /* SYSRESET controlled by power FSM */
294 REG_FLD_MOD(PLLCTRL_PLL_CONTROL
, 0x0, 3, 3);
296 /* READ 0x0 reset is in progress */
297 if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS
, 0, 0, 1) != 1) {
298 DSSERR("Failed to sysreset PLL\n");
305 static int hdmi_phy_init(void)
309 r
= hdmi_set_phy_pwr(HDMI_PHYPWRCMD_LDOON
);
313 r
= hdmi_set_phy_pwr(HDMI_PHYPWRCMD_TXON
);
318 * Read address 0 in order to get the SCP reset done completed
319 * Dummy access performed to make sure reset is done
321 hdmi_read_reg(HDMI_TXPHY_TX_CTRL
);
324 * Write to phy address 0 to configure the clock
325 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
327 REG_FLD_MOD(HDMI_TXPHY_TX_CTRL
, 0x1, 31, 30);
329 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
330 hdmi_write_reg(HDMI_TXPHY_DIGITAL_CTRL
, 0xF0000000);
332 /* Setup max LDO voltage */
333 REG_FLD_MOD(HDMI_TXPHY_POWER_CTRL
, 0xB, 3, 0);
335 /* Write to phy address 3 to change the polarity control */
336 REG_FLD_MOD(HDMI_TXPHY_PAD_CFG_CTRL
, 0x1, 27, 27);
341 static int hdmi_pll_program(struct hdmi_pll_info
*fmt
)
344 enum hdmi_clk_refsel refsel
;
346 r
= hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF
);
350 r
= hdmi_set_pll_pwr(HDMI_PLLPWRCMD_BOTHON_ALLCLKS
);
354 r
= hdmi_pll_reset();
358 refsel
= HDMI_REFSEL_SYSCLK
;
360 r
= hdmi_pll_init(refsel
, fmt
->dcofreq
, fmt
, fmt
->regsd
);
367 static void hdmi_phy_off(void)
369 hdmi_set_phy_pwr(HDMI_PHYPWRCMD_OFF
);
372 static int hdmi_core_ddc_edid(u8
*pedid
, int ext
)
378 /* Turn on CLK for DDC */
379 REG_FLD_MOD(HDMI_CORE_AV_DPD
, 0x7, 2, 0);
382 * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
383 * right shifted values( The behavior is not consistent and seen only
386 usleep_range(800, 1000);
389 /* Clk SCL Devices */
390 REG_FLD_MOD(HDMI_CORE_DDC_CMD
, 0xA, 3, 0);
392 /* HDMI_CORE_DDC_STATUS_IN_PROG */
393 if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS
,
395 DSSERR("Failed to program DDC\n");
400 REG_FLD_MOD(HDMI_CORE_DDC_CMD
, 0x9, 3, 0);
402 /* HDMI_CORE_DDC_STATUS_IN_PROG */
403 if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS
,
405 DSSERR("Failed to program DDC\n");
414 /* Load Segment Address Register */
415 REG_FLD_MOD(HDMI_CORE_DDC_SEGM
, ext
/2, 7, 0);
417 /* Load Slave Address Register */
418 REG_FLD_MOD(HDMI_CORE_DDC_ADDR
, 0xA0 >> 1, 7, 1);
420 /* Load Offset Address Register */
421 REG_FLD_MOD(HDMI_CORE_DDC_OFFSET
, offset
, 7, 0);
423 /* Load Byte Count */
424 REG_FLD_MOD(HDMI_CORE_DDC_COUNT1
, 0x80, 7, 0);
425 REG_FLD_MOD(HDMI_CORE_DDC_COUNT2
, 0x0, 1, 0);
429 REG_FLD_MOD(HDMI_CORE_DDC_CMD
, 0x4, 3, 0);
431 REG_FLD_MOD(HDMI_CORE_DDC_CMD
, 0x2, 3, 0);
433 /* HDMI_CORE_DDC_STATUS_BUS_LOW */
434 if (REG_GET(HDMI_CORE_DDC_STATUS
, 6, 6) == 1) {
435 DSSWARN("I2C Bus Low?\n");
438 /* HDMI_CORE_DDC_STATUS_NO_ACK */
439 if (REG_GET(HDMI_CORE_DDC_STATUS
, 5, 5) == 1) {
440 DSSWARN("I2C No Ack\n");
446 while (((REG_GET(HDMI_CORE_DDC_STATUS
, 4, 4) == 1) ||
447 (REG_GET(HDMI_CORE_DDC_STATUS
, 2, 2) == 0)) &&
450 if (REG_GET(HDMI_CORE_DDC_STATUS
, 2, 2) == 0) {
452 pedid
[i
++] = REG_GET(HDMI_CORE_DDC_DATA
, 7, 0);
457 for (j
= 0; j
< 128; j
++)
458 checksum
+= pedid
[j
];
461 DSSERR("E-EDID checksum failed!!\n");
468 static int read_edid(u8
*pedid
, u16 max_length
)
470 int r
= 0, n
= 0, i
= 0;
471 int max_ext_blocks
= (max_length
/ 128) - 1;
473 r
= hdmi_core_ddc_edid(pedid
, 0);
480 * README: need to comply with max_length set by the caller.
481 * Better implementation should be to allocate necessary
482 * memory to store EDID according to nb_block field found
485 if (n
> max_ext_blocks
)
488 for (i
= 1; i
<= n
; i
++) {
489 r
= hdmi_core_ddc_edid(pedid
, i
);
497 static int get_timings_index(void)
502 code
= code_vesa
[hdmi
.code
];
504 code
= code_cea
[hdmi
.code
];
507 /* HDMI code 4 corresponds to 640 * 480 VGA */
509 /* DVI mode 1 corresponds to HDMI 0 to DVI */
510 hdmi
.mode
= HDMI_DVI
;
512 code
= code_vesa
[hdmi
.code
];
517 static struct hdmi_cm
hdmi_get_code(struct omap_video_timings
*timing
)
519 int i
= 0, code
= -1, temp_vsync
= 0, temp_hsync
= 0;
520 int timing_vsync
= 0, timing_hsync
= 0;
521 struct omap_video_timings temp
;
522 struct hdmi_cm cm
= {-1};
523 DSSDBG("hdmi_get_code\n");
525 for (i
= 0; i
< OMAP_HDMI_TIMINGS_NB
; i
++) {
526 temp
= cea_vesa_timings
[i
].timings
;
527 if ((temp
.pixel_clock
== timing
->pixel_clock
) &&
528 (temp
.x_res
== timing
->x_res
) &&
529 (temp
.y_res
== timing
->y_res
)) {
531 temp_hsync
= temp
.hfp
+ temp
.hsw
+ temp
.hbp
;
532 timing_hsync
= timing
->hfp
+ timing
->hsw
+ timing
->hbp
;
533 temp_vsync
= temp
.vfp
+ temp
.vsw
+ temp
.vbp
;
534 timing_vsync
= timing
->vfp
+ timing
->vsw
+ timing
->vbp
;
536 DSSDBG("temp_hsync = %d , temp_vsync = %d"
537 "timing_hsync = %d, timing_vsync = %d\n",
538 temp_hsync
, temp_hsync
,
539 timing_hsync
, timing_vsync
);
541 if ((temp_hsync
== timing_hsync
) &&
542 (temp_vsync
== timing_vsync
)) {
544 cm
.code
= code_index
[i
];
549 DSSDBG("Hdmi_code = %d mode = %d\n",
559 static void get_horz_vert_timing_info(int current_descriptor_addrs
, u8
*edid
,
560 struct omap_video_timings
*timings
)
562 /* X and Y resolution */
563 timings
->x_res
= (((edid
[current_descriptor_addrs
+ 4] & 0xF0) << 4) |
564 edid
[current_descriptor_addrs
+ 2]);
565 timings
->y_res
= (((edid
[current_descriptor_addrs
+ 7] & 0xF0) << 4) |
566 edid
[current_descriptor_addrs
+ 5]);
568 timings
->pixel_clock
= ((edid
[current_descriptor_addrs
+ 1] << 8) |
569 edid
[current_descriptor_addrs
]);
571 timings
->pixel_clock
= 10 * timings
->pixel_clock
;
573 /* HORIZONTAL FRONT PORCH */
574 timings
->hfp
= edid
[current_descriptor_addrs
+ 8] |
575 ((edid
[current_descriptor_addrs
+ 11] & 0xc0) << 2);
576 /* HORIZONTAL SYNC WIDTH */
577 timings
->hsw
= edid
[current_descriptor_addrs
+ 9] |
578 ((edid
[current_descriptor_addrs
+ 11] & 0x30) << 4);
579 /* HORIZONTAL BACK PORCH */
580 timings
->hbp
= (((edid
[current_descriptor_addrs
+ 4] & 0x0F) << 8) |
581 edid
[current_descriptor_addrs
+ 3]) -
582 (timings
->hfp
+ timings
->hsw
);
583 /* VERTICAL FRONT PORCH */
584 timings
->vfp
= ((edid
[current_descriptor_addrs
+ 10] & 0xF0) >> 4) |
585 ((edid
[current_descriptor_addrs
+ 11] & 0x0f) << 2);
586 /* VERTICAL SYNC WIDTH */
587 timings
->vsw
= (edid
[current_descriptor_addrs
+ 10] & 0x0F) |
588 ((edid
[current_descriptor_addrs
+ 11] & 0x03) << 4);
589 /* VERTICAL BACK PORCH */
590 timings
->vbp
= (((edid
[current_descriptor_addrs
+ 7] & 0x0F) << 8) |
591 edid
[current_descriptor_addrs
+ 6]) -
592 (timings
->vfp
+ timings
->vsw
);
596 /* Description : This function gets the resolution information from EDID */
597 static void get_edid_timing_data(u8
*edid
)
600 u16 current_descriptor_addrs
;
602 struct omap_video_timings edid_timings
;
604 /* search block 0, there are 4 DTDs arranged in priority order */
605 for (count
= 0; count
< EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR
; count
++) {
606 current_descriptor_addrs
=
607 EDID_DESCRIPTOR_BLOCK0_ADDRESS
+
608 count
* EDID_TIMING_DESCRIPTOR_SIZE
;
609 get_horz_vert_timing_info(current_descriptor_addrs
,
610 edid
, &edid_timings
);
611 cm
= hdmi_get_code(&edid_timings
);
612 DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
613 count
, cm
.code
, cm
.mode
);
619 DSSDBG("code = %d , mode = %d\n",
620 hdmi
.code
, hdmi
.mode
);
624 if (edid
[0x7e] != 0x00) {
625 for (count
= 0; count
< EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR
;
627 current_descriptor_addrs
=
628 EDID_DESCRIPTOR_BLOCK1_ADDRESS
+
629 count
* EDID_TIMING_DESCRIPTOR_SIZE
;
630 get_horz_vert_timing_info(current_descriptor_addrs
,
631 edid
, &edid_timings
);
632 cm
= hdmi_get_code(&edid_timings
);
633 DSSDBG("Block1[%d] value matches code = %d, mode = %d",
634 count
, cm
.code
, cm
.mode
);
640 DSSDBG("code = %d , mode = %d\n",
641 hdmi
.code
, hdmi
.mode
);
647 DSSINFO("no valid timing found , falling back to VGA\n");
648 hdmi
.code
= 4; /* setting default value of 640 480 VGA */
649 hdmi
.mode
= HDMI_DVI
;
652 static void hdmi_read_edid(struct omap_video_timings
*dp
)
656 memset(hdmi
.edid
, 0, HDMI_EDID_MAX_LENGTH
);
659 ret
= read_edid(hdmi
.edid
, HDMI_EDID_MAX_LENGTH
);
662 if (!memcmp(hdmi
.edid
, edid_header
, sizeof(edid_header
))) {
663 /* search for timings of default resolution */
664 get_edid_timing_data(hdmi
.edid
);
665 hdmi
.edid_set
= true;
668 DSSWARN("failed to read E-EDID\n");
671 if (!hdmi
.edid_set
) {
672 DSSINFO("fallback to VGA\n");
673 hdmi
.code
= 4; /* setting default value of 640 480 VGA */
674 hdmi
.mode
= HDMI_DVI
;
677 code
= get_timings_index();
679 *dp
= cea_vesa_timings
[code
].timings
;
682 static void hdmi_core_init(struct hdmi_core_video_config
*video_cfg
,
683 struct hdmi_core_infoframe_avi
*avi_cfg
,
684 struct hdmi_core_packet_enable_repeat
*repeat_cfg
)
686 DSSDBG("Enter hdmi_core_init\n");
689 video_cfg
->ip_bus_width
= HDMI_INPUT_8BIT
;
690 video_cfg
->op_dither_truc
= HDMI_OUTPUTTRUNCATION_8BIT
;
691 video_cfg
->deep_color_pkt
= HDMI_DEEPCOLORPACKECTDISABLE
;
692 video_cfg
->pkt_mode
= HDMI_PACKETMODERESERVEDVALUE
;
693 video_cfg
->hdmi_dvi
= HDMI_DVI
;
694 video_cfg
->tclk_sel_clkmult
= HDMI_FPLL10IDCK
;
697 avi_cfg
->db1_format
= 0;
698 avi_cfg
->db1_active_info
= 0;
699 avi_cfg
->db1_bar_info_dv
= 0;
700 avi_cfg
->db1_scan_info
= 0;
701 avi_cfg
->db2_colorimetry
= 0;
702 avi_cfg
->db2_aspect_ratio
= 0;
703 avi_cfg
->db2_active_fmt_ar
= 0;
704 avi_cfg
->db3_itc
= 0;
706 avi_cfg
->db3_q_range
= 0;
707 avi_cfg
->db3_nup_scaling
= 0;
708 avi_cfg
->db4_videocode
= 0;
709 avi_cfg
->db5_pixel_repeat
= 0;
710 avi_cfg
->db6_7_line_eoftop
= 0 ;
711 avi_cfg
->db8_9_line_sofbottom
= 0;
712 avi_cfg
->db10_11_pixel_eofleft
= 0;
713 avi_cfg
->db12_13_pixel_sofright
= 0;
715 /* packet enable and repeat */
716 repeat_cfg
->audio_pkt
= 0;
717 repeat_cfg
->audio_pkt_repeat
= 0;
718 repeat_cfg
->avi_infoframe
= 0;
719 repeat_cfg
->avi_infoframe_repeat
= 0;
720 repeat_cfg
->gen_cntrl_pkt
= 0;
721 repeat_cfg
->gen_cntrl_pkt_repeat
= 0;
722 repeat_cfg
->generic_pkt
= 0;
723 repeat_cfg
->generic_pkt_repeat
= 0;
726 static void hdmi_core_powerdown_disable(void)
728 DSSDBG("Enter hdmi_core_powerdown_disable\n");
729 REG_FLD_MOD(HDMI_CORE_CTRL1
, 0x0, 0, 0);
732 static void hdmi_core_swreset_release(void)
734 DSSDBG("Enter hdmi_core_swreset_release\n");
735 REG_FLD_MOD(HDMI_CORE_SYS_SRST
, 0x0, 0, 0);
738 static void hdmi_core_swreset_assert(void)
740 DSSDBG("Enter hdmi_core_swreset_assert\n");
741 REG_FLD_MOD(HDMI_CORE_SYS_SRST
, 0x1, 0, 0);
744 /* DSS_HDMI_CORE_VIDEO_CONFIG */
745 static void hdmi_core_video_config(struct hdmi_core_video_config
*cfg
)
749 /* sys_ctrl1 default configuration not tunable */
750 r
= hdmi_read_reg(HDMI_CORE_CTRL1
);
751 r
= FLD_MOD(r
, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC
, 5, 5);
752 r
= FLD_MOD(r
, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC
, 4, 4);
753 r
= FLD_MOD(r
, HDMI_CORE_CTRL1_BSEL_24BITBUS
, 2, 2);
754 r
= FLD_MOD(r
, HDMI_CORE_CTRL1_EDGE_RISINGEDGE
, 1, 1);
755 hdmi_write_reg(HDMI_CORE_CTRL1
, r
);
757 REG_FLD_MOD(HDMI_CORE_SYS_VID_ACEN
, cfg
->ip_bus_width
, 7, 6);
760 r
= hdmi_read_reg(HDMI_CORE_SYS_VID_MODE
);
762 /* dither truncation configuration */
763 if (cfg
->op_dither_truc
> HDMI_OUTPUTTRUNCATION_12BIT
) {
764 r
= FLD_MOD(r
, cfg
->op_dither_truc
- 3, 7, 6);
765 r
= FLD_MOD(r
, 1, 5, 5);
767 r
= FLD_MOD(r
, cfg
->op_dither_truc
, 7, 6);
768 r
= FLD_MOD(r
, 0, 5, 5);
770 hdmi_write_reg(HDMI_CORE_SYS_VID_MODE
, r
);
773 r
= hdmi_read_reg(HDMI_CORE_AV_HDMI_CTRL
);
774 r
= FLD_MOD(r
, cfg
->deep_color_pkt
, 6, 6);
775 r
= FLD_MOD(r
, cfg
->pkt_mode
, 5, 3);
776 r
= FLD_MOD(r
, cfg
->hdmi_dvi
, 0, 0);
777 hdmi_write_reg(HDMI_CORE_AV_HDMI_CTRL
, r
);
780 REG_FLD_MOD(HDMI_CORE_SYS_TMDS_CTRL
,
781 cfg
->tclk_sel_clkmult
, 6, 5);
784 static void hdmi_core_aux_infoframe_avi_config(
785 struct hdmi_core_infoframe_avi info_avi
)
788 char sum
= 0, checksum
= 0;
790 sum
+= 0x82 + 0x002 + 0x00D;
791 hdmi_write_reg(HDMI_CORE_AV_AVI_TYPE
, 0x082);
792 hdmi_write_reg(HDMI_CORE_AV_AVI_VERS
, 0x002);
793 hdmi_write_reg(HDMI_CORE_AV_AVI_LEN
, 0x00D);
795 val
= (info_avi
.db1_format
<< 5) |
796 (info_avi
.db1_active_info
<< 4) |
797 (info_avi
.db1_bar_info_dv
<< 2) |
798 (info_avi
.db1_scan_info
);
799 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(0), val
);
802 val
= (info_avi
.db2_colorimetry
<< 6) |
803 (info_avi
.db2_aspect_ratio
<< 4) |
804 (info_avi
.db2_active_fmt_ar
);
805 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(1), val
);
808 val
= (info_avi
.db3_itc
<< 7) |
809 (info_avi
.db3_ec
<< 4) |
810 (info_avi
.db3_q_range
<< 2) |
811 (info_avi
.db3_nup_scaling
);
812 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(2), val
);
815 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(3), info_avi
.db4_videocode
);
816 sum
+= info_avi
.db4_videocode
;
818 val
= info_avi
.db5_pixel_repeat
;
819 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(4), val
);
822 val
= info_avi
.db6_7_line_eoftop
& 0x00FF;
823 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(5), val
);
826 val
= ((info_avi
.db6_7_line_eoftop
>> 8) & 0x00FF);
827 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(6), val
);
830 val
= info_avi
.db8_9_line_sofbottom
& 0x00FF;
831 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(7), val
);
834 val
= ((info_avi
.db8_9_line_sofbottom
>> 8) & 0x00FF);
835 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(8), val
);
838 val
= info_avi
.db10_11_pixel_eofleft
& 0x00FF;
839 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(9), val
);
842 val
= ((info_avi
.db10_11_pixel_eofleft
>> 8) & 0x00FF);
843 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(10), val
);
846 val
= info_avi
.db12_13_pixel_sofright
& 0x00FF;
847 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(11), val
);
850 val
= ((info_avi
.db12_13_pixel_sofright
>> 8) & 0x00FF);
851 hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(12), val
);
854 checksum
= 0x100 - sum
;
855 hdmi_write_reg(HDMI_CORE_AV_AVI_CHSUM
, checksum
);
858 static void hdmi_core_av_packet_config(
859 struct hdmi_core_packet_enable_repeat repeat_cfg
)
861 /* enable/repeat the infoframe */
862 hdmi_write_reg(HDMI_CORE_AV_PB_CTRL1
,
863 (repeat_cfg
.audio_pkt
<< 5) |
864 (repeat_cfg
.audio_pkt_repeat
<< 4) |
865 (repeat_cfg
.avi_infoframe
<< 1) |
866 (repeat_cfg
.avi_infoframe_repeat
));
868 /* enable/repeat the packet */
869 hdmi_write_reg(HDMI_CORE_AV_PB_CTRL2
,
870 (repeat_cfg
.gen_cntrl_pkt
<< 3) |
871 (repeat_cfg
.gen_cntrl_pkt_repeat
<< 2) |
872 (repeat_cfg
.generic_pkt
<< 1) |
873 (repeat_cfg
.generic_pkt_repeat
));
876 static void hdmi_wp_init(struct omap_video_timings
*timings
,
877 struct hdmi_video_format
*video_fmt
,
878 struct hdmi_video_interface
*video_int
)
880 DSSDBG("Enter hdmi_wp_init\n");
889 video_fmt
->packing_mode
= HDMI_PACK_10b_RGB_YUV444
;
890 video_fmt
->y_res
= 0;
891 video_fmt
->x_res
= 0;
896 video_int
->interlacing
= 0;
897 video_int
->tm
= 0; /* HDMI_TIMING_SLAVE */
901 static void hdmi_wp_video_start(bool start
)
903 REG_FLD_MOD(HDMI_WP_VIDEO_CFG
, start
, 31, 31);
906 static void hdmi_wp_video_init_format(struct hdmi_video_format
*video_fmt
,
907 struct omap_video_timings
*timings
, struct hdmi_config
*param
)
909 DSSDBG("Enter hdmi_wp_video_init_format\n");
911 video_fmt
->y_res
= param
->timings
.timings
.y_res
;
912 video_fmt
->x_res
= param
->timings
.timings
.x_res
;
914 timings
->hbp
= param
->timings
.timings
.hbp
;
915 timings
->hfp
= param
->timings
.timings
.hfp
;
916 timings
->hsw
= param
->timings
.timings
.hsw
;
917 timings
->vbp
= param
->timings
.timings
.vbp
;
918 timings
->vfp
= param
->timings
.timings
.vfp
;
919 timings
->vsw
= param
->timings
.timings
.vsw
;
922 static void hdmi_wp_video_config_format(
923 struct hdmi_video_format
*video_fmt
)
927 REG_FLD_MOD(HDMI_WP_VIDEO_CFG
, video_fmt
->packing_mode
, 10, 8);
929 l
|= FLD_VAL(video_fmt
->y_res
, 31, 16);
930 l
|= FLD_VAL(video_fmt
->x_res
, 15, 0);
931 hdmi_write_reg(HDMI_WP_VIDEO_SIZE
, l
);
934 static void hdmi_wp_video_config_interface(
935 struct hdmi_video_interface
*video_int
)
938 DSSDBG("Enter hdmi_wp_video_config_interface\n");
940 r
= hdmi_read_reg(HDMI_WP_VIDEO_CFG
);
941 r
= FLD_MOD(r
, video_int
->vsp
, 7, 7);
942 r
= FLD_MOD(r
, video_int
->hsp
, 6, 6);
943 r
= FLD_MOD(r
, video_int
->interlacing
, 3, 3);
944 r
= FLD_MOD(r
, video_int
->tm
, 1, 0);
945 hdmi_write_reg(HDMI_WP_VIDEO_CFG
, r
);
948 static void hdmi_wp_video_config_timing(
949 struct omap_video_timings
*timings
)
954 DSSDBG("Enter hdmi_wp_video_config_timing\n");
956 timing_h
|= FLD_VAL(timings
->hbp
, 31, 20);
957 timing_h
|= FLD_VAL(timings
->hfp
, 19, 8);
958 timing_h
|= FLD_VAL(timings
->hsw
, 7, 0);
959 hdmi_write_reg(HDMI_WP_VIDEO_TIMING_H
, timing_h
);
961 timing_v
|= FLD_VAL(timings
->vbp
, 31, 20);
962 timing_v
|= FLD_VAL(timings
->vfp
, 19, 8);
963 timing_v
|= FLD_VAL(timings
->vsw
, 7, 0);
964 hdmi_write_reg(HDMI_WP_VIDEO_TIMING_V
, timing_v
);
967 static void hdmi_basic_configure(struct hdmi_config
*cfg
)
970 struct omap_video_timings video_timing
;
971 struct hdmi_video_format video_format
;
972 struct hdmi_video_interface video_interface
;
974 struct hdmi_core_infoframe_avi avi_cfg
;
975 struct hdmi_core_video_config v_core_cfg
;
976 struct hdmi_core_packet_enable_repeat repeat_cfg
;
978 hdmi_wp_init(&video_timing
, &video_format
,
981 hdmi_core_init(&v_core_cfg
,
985 hdmi_wp_video_init_format(&video_format
,
988 hdmi_wp_video_config_timing(&video_timing
);
991 video_format
.packing_mode
= HDMI_PACK_24b_RGB_YUV444_YUV422
;
993 hdmi_wp_video_config_format(&video_format
);
995 video_interface
.vsp
= cfg
->timings
.vsync_pol
;
996 video_interface
.hsp
= cfg
->timings
.hsync_pol
;
997 video_interface
.interlacing
= cfg
->interlace
;
998 video_interface
.tm
= 1 ; /* HDMI_TIMING_MASTER_24BIT */
1000 hdmi_wp_video_config_interface(&video_interface
);
1003 * configure core video part
1004 * set software reset in the core
1006 hdmi_core_swreset_assert();
1008 /* power down off */
1009 hdmi_core_powerdown_disable();
1011 v_core_cfg
.pkt_mode
= HDMI_PACKETMODE24BITPERPIXEL
;
1012 v_core_cfg
.hdmi_dvi
= cfg
->cm
.mode
;
1014 hdmi_core_video_config(&v_core_cfg
);
1016 /* release software reset in the core */
1017 hdmi_core_swreset_release();
1021 * info frame video see doc CEA861-D page 65
1023 avi_cfg
.db1_format
= HDMI_INFOFRAME_AVI_DB1Y_RGB
;
1024 avi_cfg
.db1_active_info
=
1025 HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF
;
1026 avi_cfg
.db1_bar_info_dv
= HDMI_INFOFRAME_AVI_DB1B_NO
;
1027 avi_cfg
.db1_scan_info
= HDMI_INFOFRAME_AVI_DB1S_0
;
1028 avi_cfg
.db2_colorimetry
= HDMI_INFOFRAME_AVI_DB2C_NO
;
1029 avi_cfg
.db2_aspect_ratio
= HDMI_INFOFRAME_AVI_DB2M_NO
;
1030 avi_cfg
.db2_active_fmt_ar
= HDMI_INFOFRAME_AVI_DB2R_SAME
;
1031 avi_cfg
.db3_itc
= HDMI_INFOFRAME_AVI_DB3ITC_NO
;
1032 avi_cfg
.db3_ec
= HDMI_INFOFRAME_AVI_DB3EC_XVYUV601
;
1033 avi_cfg
.db3_q_range
= HDMI_INFOFRAME_AVI_DB3Q_DEFAULT
;
1034 avi_cfg
.db3_nup_scaling
= HDMI_INFOFRAME_AVI_DB3SC_NO
;
1035 avi_cfg
.db4_videocode
= cfg
->cm
.code
;
1036 avi_cfg
.db5_pixel_repeat
= HDMI_INFOFRAME_AVI_DB5PR_NO
;
1037 avi_cfg
.db6_7_line_eoftop
= 0;
1038 avi_cfg
.db8_9_line_sofbottom
= 0;
1039 avi_cfg
.db10_11_pixel_eofleft
= 0;
1040 avi_cfg
.db12_13_pixel_sofright
= 0;
1042 hdmi_core_aux_infoframe_avi_config(avi_cfg
);
1044 /* enable/repeat the infoframe */
1045 repeat_cfg
.avi_infoframe
= HDMI_PACKETENABLE
;
1046 repeat_cfg
.avi_infoframe_repeat
= HDMI_PACKETREPEATON
;
1048 repeat_cfg
.audio_pkt
= HDMI_PACKETENABLE
;
1049 repeat_cfg
.audio_pkt_repeat
= HDMI_PACKETREPEATON
;
1050 hdmi_core_av_packet_config(repeat_cfg
);
1053 static void update_hdmi_timings(struct hdmi_config
*cfg
,
1054 struct omap_video_timings
*timings
, int code
)
1056 cfg
->timings
.timings
.x_res
= timings
->x_res
;
1057 cfg
->timings
.timings
.y_res
= timings
->y_res
;
1058 cfg
->timings
.timings
.hbp
= timings
->hbp
;
1059 cfg
->timings
.timings
.hfp
= timings
->hfp
;
1060 cfg
->timings
.timings
.hsw
= timings
->hsw
;
1061 cfg
->timings
.timings
.vbp
= timings
->vbp
;
1062 cfg
->timings
.timings
.vfp
= timings
->vfp
;
1063 cfg
->timings
.timings
.vsw
= timings
->vsw
;
1064 cfg
->timings
.timings
.pixel_clock
= timings
->pixel_clock
;
1065 cfg
->timings
.vsync_pol
= cea_vesa_timings
[code
].vsync_pol
;
1066 cfg
->timings
.hsync_pol
= cea_vesa_timings
[code
].hsync_pol
;
1069 static void hdmi_compute_pll(struct omap_dss_device
*dssdev
, int phy
,
1070 struct hdmi_pll_info
*pi
)
1072 unsigned long clkin
, refclk
;
1075 clkin
= clk_get_rate(hdmi
.sys_clk
) / 10000;
1077 * Input clock is predivided by N + 1
1078 * out put of which is reference clk
1080 pi
->regn
= dssdev
->clocks
.hdmi
.regn
;
1081 refclk
= clkin
/ (pi
->regn
+ 1);
1084 * multiplier is pixel_clk/ref_clk
1085 * Multiplying by 100 to avoid fractional part removal
1087 pi
->regm
= (phy
* 100 / (refclk
)) / 100;
1088 pi
->regm2
= dssdev
->clocks
.hdmi
.regm2
;
1091 * fractional multiplier is remainder of the difference between
1092 * multiplier and actual phy(required pixel clock thus should be
1093 * multiplied by 2^18(262144) divided by the reference clock
1095 mf
= (phy
- pi
->regm
* refclk
) * 262144;
1096 pi
->regmf
= mf
/ (refclk
);
1099 * Dcofreq should be set to 1 if required pixel clock
1100 * is greater than 1000MHz
1102 pi
->dcofreq
= phy
> 1000 * 100;
1103 pi
->regsd
= ((pi
->regm
* clkin
/ 10) / ((pi
->regn
+ 1) * 250) + 5) / 10;
1105 DSSDBG("M = %d Mf = %d\n", pi
->regm
, pi
->regmf
);
1106 DSSDBG("range = %d sd = %d\n", pi
->dcofreq
, pi
->regsd
);
1109 static int hdmi_power_on(struct omap_dss_device
*dssdev
)
1112 struct hdmi_pll_info pll_data
;
1113 struct omap_video_timings
*p
;
1116 r
= hdmi_runtime_get();
1120 dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT
, 0);
1122 p
= &dssdev
->panel
.timings
;
1124 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
1125 dssdev
->panel
.timings
.x_res
,
1126 dssdev
->panel
.timings
.y_res
);
1128 if (!hdmi
.custom_set
) {
1129 DSSDBG("Read EDID as no EDID is not set on poweron\n");
1132 code
= get_timings_index();
1133 dssdev
->panel
.timings
= cea_vesa_timings
[code
].timings
;
1134 update_hdmi_timings(&hdmi
.cfg
, p
, code
);
1136 phy
= p
->pixel_clock
;
1138 hdmi_compute_pll(dssdev
, phy
, &pll_data
);
1140 hdmi_wp_video_start(0);
1142 /* config the PLL and PHY first */
1143 r
= hdmi_pll_program(&pll_data
);
1145 DSSDBG("Failed to lock PLL\n");
1149 r
= hdmi_phy_init();
1151 DSSDBG("Failed to start PHY\n");
1155 hdmi
.cfg
.cm
.mode
= hdmi
.mode
;
1156 hdmi
.cfg
.cm
.code
= hdmi
.code
;
1157 hdmi_basic_configure(&hdmi
.cfg
);
1159 /* Make selection of HDMI in DSS */
1160 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK
);
1162 /* Select the dispc clock source as PRCM clock, to ensure that it is not
1163 * DSI PLL source as the clock selected by DSI PLL might not be
1164 * sufficient for the resolution selected / that can be changed
1165 * dynamically by user. This can be moved to single location , say
1168 dss_select_dispc_clk_source(dssdev
->clocks
.dispc
.dispc_fclk_src
);
1170 /* bypass TV gamma table */
1171 dispc_enable_gamma_table(0);
1174 dispc_set_digit_size(dssdev
->panel
.timings
.x_res
,
1175 dssdev
->panel
.timings
.y_res
);
1177 dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT
, 1);
1179 hdmi_wp_video_start(1);
1187 static void hdmi_power_off(struct omap_dss_device
*dssdev
)
1189 dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT
, 0);
1191 hdmi_wp_video_start(0);
1193 hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF
);
1199 int omapdss_hdmi_display_check_timing(struct omap_dss_device
*dssdev
,
1200 struct omap_video_timings
*timings
)
1204 cm
= hdmi_get_code(timings
);
1205 if (cm
.code
== -1) {
1206 DSSERR("Invalid timing entered\n");
1214 void omapdss_hdmi_display_set_timing(struct omap_dss_device
*dssdev
)
1218 hdmi
.custom_set
= 1;
1219 cm
= hdmi_get_code(&dssdev
->panel
.timings
);
1220 hdmi
.code
= cm
.code
;
1221 hdmi
.mode
= cm
.mode
;
1222 omapdss_hdmi_display_enable(dssdev
);
1223 hdmi
.custom_set
= 0;
1226 int omapdss_hdmi_display_enable(struct omap_dss_device
*dssdev
)
1230 DSSDBG("ENTER hdmi_display_enable\n");
1232 mutex_lock(&hdmi
.lock
);
1234 r
= omap_dss_start_device(dssdev
);
1236 DSSERR("failed to start device\n");
1240 if (dssdev
->platform_enable
) {
1241 r
= dssdev
->platform_enable(dssdev
);
1243 DSSERR("failed to enable GPIO's\n");
1248 r
= hdmi_power_on(dssdev
);
1250 DSSERR("failed to power on device\n");
1254 mutex_unlock(&hdmi
.lock
);
1258 if (dssdev
->platform_disable
)
1259 dssdev
->platform_disable(dssdev
);
1261 omap_dss_stop_device(dssdev
);
1263 mutex_unlock(&hdmi
.lock
);
1267 void omapdss_hdmi_display_disable(struct omap_dss_device
*dssdev
)
1269 DSSDBG("Enter hdmi_display_disable\n");
1271 mutex_lock(&hdmi
.lock
);
1273 hdmi_power_off(dssdev
);
1275 if (dssdev
->platform_disable
)
1276 dssdev
->platform_disable(dssdev
);
1278 omap_dss_stop_device(dssdev
);
1280 mutex_unlock(&hdmi
.lock
);
1283 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1284 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1285 static void hdmi_wp_audio_config_format(
1286 struct hdmi_audio_format
*aud_fmt
)
1290 DSSDBG("Enter hdmi_wp_audio_config_format\n");
1292 r
= hdmi_read_reg(HDMI_WP_AUDIO_CFG
);
1293 r
= FLD_MOD(r
, aud_fmt
->stereo_channels
, 26, 24);
1294 r
= FLD_MOD(r
, aud_fmt
->active_chnnls_msk
, 23, 16);
1295 r
= FLD_MOD(r
, aud_fmt
->en_sig_blk_strt_end
, 5, 5);
1296 r
= FLD_MOD(r
, aud_fmt
->type
, 4, 4);
1297 r
= FLD_MOD(r
, aud_fmt
->justification
, 3, 3);
1298 r
= FLD_MOD(r
, aud_fmt
->sample_order
, 2, 2);
1299 r
= FLD_MOD(r
, aud_fmt
->samples_per_word
, 1, 1);
1300 r
= FLD_MOD(r
, aud_fmt
->sample_size
, 0, 0);
1301 hdmi_write_reg(HDMI_WP_AUDIO_CFG
, r
);
1304 static void hdmi_wp_audio_config_dma(struct hdmi_audio_dma
*aud_dma
)
1308 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
1310 r
= hdmi_read_reg(HDMI_WP_AUDIO_CFG2
);
1311 r
= FLD_MOD(r
, aud_dma
->transfer_size
, 15, 8);
1312 r
= FLD_MOD(r
, aud_dma
->block_size
, 7, 0);
1313 hdmi_write_reg(HDMI_WP_AUDIO_CFG2
, r
);
1315 r
= hdmi_read_reg(HDMI_WP_AUDIO_CTRL
);
1316 r
= FLD_MOD(r
, aud_dma
->mode
, 9, 9);
1317 r
= FLD_MOD(r
, aud_dma
->fifo_threshold
, 8, 0);
1318 hdmi_write_reg(HDMI_WP_AUDIO_CTRL
, r
);
1321 static void hdmi_core_audio_config(struct hdmi_core_audio_config
*cfg
)
1325 /* audio clock recovery parameters */
1326 r
= hdmi_read_reg(HDMI_CORE_AV_ACR_CTRL
);
1327 r
= FLD_MOD(r
, cfg
->use_mclk
, 2, 2);
1328 r
= FLD_MOD(r
, cfg
->en_acr_pkt
, 1, 1);
1329 r
= FLD_MOD(r
, cfg
->cts_mode
, 0, 0);
1330 hdmi_write_reg(HDMI_CORE_AV_ACR_CTRL
, r
);
1332 REG_FLD_MOD(HDMI_CORE_AV_N_SVAL1
, cfg
->n
, 7, 0);
1333 REG_FLD_MOD(HDMI_CORE_AV_N_SVAL2
, cfg
->n
>> 8, 7, 0);
1334 REG_FLD_MOD(HDMI_CORE_AV_N_SVAL3
, cfg
->n
>> 16, 7, 0);
1336 if (cfg
->cts_mode
== HDMI_AUDIO_CTS_MODE_SW
) {
1337 REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL1
, cfg
->cts
, 7, 0);
1338 REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL2
, cfg
->cts
>> 8, 7, 0);
1339 REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL3
, cfg
->cts
>> 16, 7, 0);
1342 * HDMI IP uses this configuration to divide the MCLK to
1345 REG_FLD_MOD(HDMI_CORE_AV_FREQ_SVAL
, cfg
->mclk_mode
, 2, 0);
1347 /* Configure clock for audio packets */
1348 REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_1
,
1349 cfg
->aud_par_busclk
, 7, 0);
1350 REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_2
,
1351 (cfg
->aud_par_busclk
>> 8), 7, 0);
1352 REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_3
,
1353 (cfg
->aud_par_busclk
>> 16), 7, 0);
1356 /* Override of SPDIF sample frequency with value in I2S_CHST4 */
1357 REG_FLD_MOD(HDMI_CORE_AV_SPDIF_CTRL
, cfg
->fs_override
, 1, 1);
1359 /* I2S parameters */
1360 REG_FLD_MOD(HDMI_CORE_AV_I2S_CHST4
, cfg
->freq_sample
, 3, 0);
1362 r
= hdmi_read_reg(HDMI_CORE_AV_I2S_IN_CTRL
);
1363 r
= FLD_MOD(r
, cfg
->i2s_cfg
.en_high_bitrate_aud
, 7, 7);
1364 r
= FLD_MOD(r
, cfg
->i2s_cfg
.sck_edge_mode
, 6, 6);
1365 r
= FLD_MOD(r
, cfg
->i2s_cfg
.cbit_order
, 5, 5);
1366 r
= FLD_MOD(r
, cfg
->i2s_cfg
.vbit
, 4, 4);
1367 r
= FLD_MOD(r
, cfg
->i2s_cfg
.ws_polarity
, 3, 3);
1368 r
= FLD_MOD(r
, cfg
->i2s_cfg
.justification
, 2, 2);
1369 r
= FLD_MOD(r
, cfg
->i2s_cfg
.direction
, 1, 1);
1370 r
= FLD_MOD(r
, cfg
->i2s_cfg
.shift
, 0, 0);
1371 hdmi_write_reg(HDMI_CORE_AV_I2S_IN_CTRL
, r
);
1373 r
= hdmi_read_reg(HDMI_CORE_AV_I2S_CHST5
);
1374 r
= FLD_MOD(r
, cfg
->freq_sample
, 7, 4);
1375 r
= FLD_MOD(r
, cfg
->i2s_cfg
.word_length
, 3, 1);
1376 r
= FLD_MOD(r
, cfg
->i2s_cfg
.word_max_length
, 0, 0);
1377 hdmi_write_reg(HDMI_CORE_AV_I2S_CHST5
, r
);
1379 REG_FLD_MOD(HDMI_CORE_AV_I2S_IN_LEN
, cfg
->i2s_cfg
.in_length_bits
, 3, 0);
1381 /* Audio channels and mode parameters */
1382 REG_FLD_MOD(HDMI_CORE_AV_HDMI_CTRL
, cfg
->layout
, 2, 1);
1383 r
= hdmi_read_reg(HDMI_CORE_AV_AUD_MODE
);
1384 r
= FLD_MOD(r
, cfg
->i2s_cfg
.active_sds
, 7, 4);
1385 r
= FLD_MOD(r
, cfg
->en_dsd_audio
, 3, 3);
1386 r
= FLD_MOD(r
, cfg
->en_parallel_aud_input
, 2, 2);
1387 r
= FLD_MOD(r
, cfg
->en_spdif
, 1, 1);
1388 hdmi_write_reg(HDMI_CORE_AV_AUD_MODE
, r
);
1391 static void hdmi_core_audio_infoframe_config(
1392 struct hdmi_core_infoframe_audio
*info_aud
)
1395 u8 sum
= 0, checksum
= 0;
1398 * Set audio info frame type, version and length as
1399 * described in HDMI 1.4a Section 8.2.2 specification.
1400 * Checksum calculation is defined in Section 5.3.5.
1402 hdmi_write_reg(HDMI_CORE_AV_AUDIO_TYPE
, 0x84);
1403 hdmi_write_reg(HDMI_CORE_AV_AUDIO_VERS
, 0x01);
1404 hdmi_write_reg(HDMI_CORE_AV_AUDIO_LEN
, 0x0a);
1405 sum
+= 0x84 + 0x001 + 0x00a;
1407 val
= (info_aud
->db1_coding_type
<< 4)
1408 | (info_aud
->db1_channel_count
- 1);
1409 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(0), val
);
1412 val
= (info_aud
->db2_sample_freq
<< 2) | info_aud
->db2_sample_size
;
1413 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(1), val
);
1416 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
1418 val
= info_aud
->db4_channel_alloc
;
1419 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(3), val
);
1422 val
= (info_aud
->db5_downmix_inh
<< 7) | (info_aud
->db5_lsv
<< 3);
1423 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(4), val
);
1426 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
1427 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
1428 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
1429 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
1430 hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
1432 checksum
= 0x100 - sum
;
1433 hdmi_write_reg(HDMI_CORE_AV_AUDIO_CHSUM
, checksum
);
1436 * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
1441 static int hdmi_config_audio_acr(u32 sample_freq
, u32
*n
, u32
*cts
)
1445 u32 pclk
= hdmi
.cfg
.timings
.timings
.pixel_clock
;
1447 if (n
== NULL
|| cts
== NULL
)
1450 * Obtain current deep color configuration. This needed
1451 * to calculate the TMDS clock based on the pixel clock.
1453 r
= REG_GET(HDMI_WP_VIDEO_CFG
, 1, 0);
1455 case 1: /* No deep color selected */
1458 case 2: /* 10-bit deep color selected */
1461 case 3: /* 12-bit deep color selected */
1468 switch (sample_freq
) {
1470 if ((deep_color
== 125) && ((pclk
== 54054)
1471 || (pclk
== 74250)))
1480 if ((deep_color
== 125) && ((pclk
== 54054)
1481 || (pclk
== 74250)))
1491 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
1492 *cts
= pclk
* (*n
/ 128) * deep_color
/ (sample_freq
/ 10);
1497 static int hdmi_audio_hw_params(struct snd_pcm_substream
*substream
,
1498 struct snd_pcm_hw_params
*params
,
1499 struct snd_soc_dai
*dai
)
1501 struct hdmi_audio_format audio_format
;
1502 struct hdmi_audio_dma audio_dma
;
1503 struct hdmi_core_audio_config core_cfg
;
1504 struct hdmi_core_infoframe_audio aud_if_cfg
;
1506 enum hdmi_core_audio_sample_freq sample_freq
;
1508 switch (params_format(params
)) {
1509 case SNDRV_PCM_FORMAT_S16_LE
:
1510 core_cfg
.i2s_cfg
.word_max_length
=
1511 HDMI_AUDIO_I2S_MAX_WORD_20BITS
;
1512 core_cfg
.i2s_cfg
.word_length
= HDMI_AUDIO_I2S_CHST_WORD_16_BITS
;
1513 core_cfg
.i2s_cfg
.in_length_bits
=
1514 HDMI_AUDIO_I2S_INPUT_LENGTH_16
;
1515 core_cfg
.i2s_cfg
.justification
= HDMI_AUDIO_JUSTIFY_LEFT
;
1516 audio_format
.samples_per_word
= HDMI_AUDIO_ONEWORD_TWOSAMPLES
;
1517 audio_format
.sample_size
= HDMI_AUDIO_SAMPLE_16BITS
;
1518 audio_format
.justification
= HDMI_AUDIO_JUSTIFY_LEFT
;
1519 audio_dma
.transfer_size
= 0x10;
1521 case SNDRV_PCM_FORMAT_S24_LE
:
1522 core_cfg
.i2s_cfg
.word_max_length
=
1523 HDMI_AUDIO_I2S_MAX_WORD_24BITS
;
1524 core_cfg
.i2s_cfg
.word_length
= HDMI_AUDIO_I2S_CHST_WORD_24_BITS
;
1525 core_cfg
.i2s_cfg
.in_length_bits
=
1526 HDMI_AUDIO_I2S_INPUT_LENGTH_24
;
1527 audio_format
.samples_per_word
= HDMI_AUDIO_ONEWORD_ONESAMPLE
;
1528 audio_format
.sample_size
= HDMI_AUDIO_SAMPLE_24BITS
;
1529 audio_format
.justification
= HDMI_AUDIO_JUSTIFY_RIGHT
;
1530 core_cfg
.i2s_cfg
.justification
= HDMI_AUDIO_JUSTIFY_RIGHT
;
1531 audio_dma
.transfer_size
= 0x20;
1537 switch (params_rate(params
)) {
1539 sample_freq
= HDMI_AUDIO_FS_32000
;
1542 sample_freq
= HDMI_AUDIO_FS_44100
;
1545 sample_freq
= HDMI_AUDIO_FS_48000
;
1551 err
= hdmi_config_audio_acr(params_rate(params
), &n
, &cts
);
1555 /* Audio wrapper config */
1556 audio_format
.stereo_channels
= HDMI_AUDIO_STEREO_ONECHANNEL
;
1557 audio_format
.active_chnnls_msk
= 0x03;
1558 audio_format
.type
= HDMI_AUDIO_TYPE_LPCM
;
1559 audio_format
.sample_order
= HDMI_AUDIO_SAMPLE_LEFT_FIRST
;
1560 /* Disable start/stop signals of IEC 60958 blocks */
1561 audio_format
.en_sig_blk_strt_end
= HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF
;
1563 audio_dma
.block_size
= 0xC0;
1564 audio_dma
.mode
= HDMI_AUDIO_TRANSF_DMA
;
1565 audio_dma
.fifo_threshold
= 0x20; /* in number of samples */
1567 hdmi_wp_audio_config_dma(&audio_dma
);
1568 hdmi_wp_audio_config_format(&audio_format
);
1573 core_cfg
.i2s_cfg
.en_high_bitrate_aud
= false;
1574 /* Only used with high bitrate audio */
1575 core_cfg
.i2s_cfg
.cbit_order
= false;
1576 /* Serial data and word select should change on sck rising edge */
1577 core_cfg
.i2s_cfg
.sck_edge_mode
= HDMI_AUDIO_I2S_SCK_EDGE_RISING
;
1578 core_cfg
.i2s_cfg
.vbit
= HDMI_AUDIO_I2S_VBIT_FOR_PCM
;
1579 /* Set I2S word select polarity */
1580 core_cfg
.i2s_cfg
.ws_polarity
= HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT
;
1581 core_cfg
.i2s_cfg
.direction
= HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST
;
1582 /* Set serial data to word select shift. See Phillips spec. */
1583 core_cfg
.i2s_cfg
.shift
= HDMI_AUDIO_I2S_FIRST_BIT_SHIFT
;
1584 /* Enable one of the four available serial data channels */
1585 core_cfg
.i2s_cfg
.active_sds
= HDMI_AUDIO_I2S_SD0_EN
;
1587 /* Core audio config */
1588 core_cfg
.freq_sample
= sample_freq
;
1591 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE
)) {
1592 core_cfg
.aud_par_busclk
= 0;
1593 core_cfg
.cts_mode
= HDMI_AUDIO_CTS_MODE_SW
;
1594 core_cfg
.use_mclk
= false;
1596 core_cfg
.aud_par_busclk
= (((128 * 31) - 1) << 8);
1597 core_cfg
.cts_mode
= HDMI_AUDIO_CTS_MODE_HW
;
1598 core_cfg
.use_mclk
= true;
1599 core_cfg
.mclk_mode
= HDMI_AUDIO_MCLK_128FS
;
1601 core_cfg
.layout
= HDMI_AUDIO_LAYOUT_2CH
;
1602 core_cfg
.en_spdif
= false;
1603 /* Use sample frequency from channel status word */
1604 core_cfg
.fs_override
= true;
1605 /* Enable ACR packets */
1606 core_cfg
.en_acr_pkt
= true;
1607 /* Disable direct streaming digital audio */
1608 core_cfg
.en_dsd_audio
= false;
1609 /* Use parallel audio interface */
1610 core_cfg
.en_parallel_aud_input
= true;
1612 hdmi_core_audio_config(&core_cfg
);
1616 * info frame audio see doc CEA861-D page 74
1618 aud_if_cfg
.db1_coding_type
= HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM
;
1619 aud_if_cfg
.db1_channel_count
= 2;
1620 aud_if_cfg
.db2_sample_freq
= HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM
;
1621 aud_if_cfg
.db2_sample_size
= HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM
;
1622 aud_if_cfg
.db4_channel_alloc
= 0x00;
1623 aud_if_cfg
.db5_downmix_inh
= false;
1624 aud_if_cfg
.db5_lsv
= 0;
1626 hdmi_core_audio_infoframe_config(&aud_if_cfg
);
1630 static int hdmi_audio_trigger(struct snd_pcm_substream
*substream
, int cmd
,
1631 struct snd_soc_dai
*dai
)
1635 case SNDRV_PCM_TRIGGER_START
:
1636 case SNDRV_PCM_TRIGGER_RESUME
:
1637 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1638 REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE
, 1, 0, 0);
1639 REG_FLD_MOD(HDMI_WP_AUDIO_CTRL
, 1, 31, 31);
1640 REG_FLD_MOD(HDMI_WP_AUDIO_CTRL
, 1, 30, 30);
1643 case SNDRV_PCM_TRIGGER_STOP
:
1644 case SNDRV_PCM_TRIGGER_SUSPEND
:
1645 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1646 REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE
, 0, 0, 0);
1647 REG_FLD_MOD(HDMI_WP_AUDIO_CTRL
, 0, 30, 30);
1648 REG_FLD_MOD(HDMI_WP_AUDIO_CTRL
, 0, 31, 31);
1656 static int hdmi_audio_startup(struct snd_pcm_substream
*substream
,
1657 struct snd_soc_dai
*dai
)
1660 pr_err("Current video settings do not support audio.\n");
1666 static struct snd_soc_codec_driver hdmi_audio_codec_drv
= {
1669 static struct snd_soc_dai_ops hdmi_audio_codec_ops
= {
1670 .hw_params
= hdmi_audio_hw_params
,
1671 .trigger
= hdmi_audio_trigger
,
1672 .startup
= hdmi_audio_startup
,
1675 static struct snd_soc_dai_driver hdmi_codec_dai_drv
= {
1676 .name
= "hdmi-audio-codec",
1680 .rates
= SNDRV_PCM_RATE_32000
|
1681 SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
,
1682 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
1683 SNDRV_PCM_FMTBIT_S24_LE
,
1685 .ops
= &hdmi_audio_codec_ops
,
1689 static int hdmi_get_clocks(struct platform_device
*pdev
)
1693 clk
= clk_get(&pdev
->dev
, "sys_clk");
1695 DSSERR("can't get sys_clk\n");
1696 return PTR_ERR(clk
);
1701 clk
= clk_get(&pdev
->dev
, "dss_48mhz_clk");
1703 DSSERR("can't get hdmi_clk\n");
1704 clk_put(hdmi
.sys_clk
);
1705 return PTR_ERR(clk
);
1708 hdmi
.hdmi_clk
= clk
;
1713 static void hdmi_put_clocks(void)
1716 clk_put(hdmi
.sys_clk
);
1718 clk_put(hdmi
.hdmi_clk
);
1721 /* HDMI HW IP initialisation */
1722 static int omapdss_hdmihw_probe(struct platform_device
*pdev
)
1724 struct resource
*hdmi_mem
;
1727 hdmi
.pdata
= pdev
->dev
.platform_data
;
1730 mutex_init(&hdmi
.lock
);
1732 hdmi_mem
= platform_get_resource(hdmi
.pdev
, IORESOURCE_MEM
, 0);
1734 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1738 /* Base address taken from platform */
1739 hdmi
.base_wp
= ioremap(hdmi_mem
->start
, resource_size(hdmi_mem
));
1740 if (!hdmi
.base_wp
) {
1741 DSSERR("can't ioremap WP\n");
1745 r
= hdmi_get_clocks(pdev
);
1747 iounmap(hdmi
.base_wp
);
1751 pm_runtime_enable(&pdev
->dev
);
1755 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1756 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1758 /* Register ASoC codec DAI */
1759 r
= snd_soc_register_codec(&pdev
->dev
, &hdmi_audio_codec_drv
,
1760 &hdmi_codec_dai_drv
, 1);
1762 DSSERR("can't register ASoC HDMI audio codec\n");
1769 static int omapdss_hdmihw_remove(struct platform_device
*pdev
)
1773 #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1774 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1775 snd_soc_unregister_codec(&pdev
->dev
);
1778 pm_runtime_disable(&pdev
->dev
);
1782 iounmap(hdmi
.base_wp
);
1787 static int hdmi_runtime_suspend(struct device
*dev
)
1789 clk_disable(hdmi
.hdmi_clk
);
1790 clk_disable(hdmi
.sys_clk
);
1792 dispc_runtime_put();
1798 static int hdmi_runtime_resume(struct device
*dev
)
1802 r
= dss_runtime_get();
1806 r
= dispc_runtime_get();
1811 clk_enable(hdmi
.sys_clk
);
1812 clk_enable(hdmi
.hdmi_clk
);
1822 static const struct dev_pm_ops hdmi_pm_ops
= {
1823 .runtime_suspend
= hdmi_runtime_suspend
,
1824 .runtime_resume
= hdmi_runtime_resume
,
1827 static struct platform_driver omapdss_hdmihw_driver
= {
1828 .probe
= omapdss_hdmihw_probe
,
1829 .remove
= omapdss_hdmihw_remove
,
1831 .name
= "omapdss_hdmi",
1832 .owner
= THIS_MODULE
,
1837 int hdmi_init_platform_driver(void)
1839 return platform_driver_register(&omapdss_hdmihw_driver
);
1842 void hdmi_uninit_platform_driver(void)
1844 return platform_driver_unregister(&omapdss_hdmihw_driver
);