Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | * hdmi.c |
| 3 | * |
| 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/ |
| 6 | * Authors: Yong Zhi |
| 7 | * Mythri pk <mythripk@ti.com> |
| 8 | * |
| 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. |
| 12 | * |
| 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 |
| 16 | * more details. |
| 17 | * |
| 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/>. |
| 20 | */ |
| 21 | |
| 22 | #define DSS_SUBSYS_NAME "HDMI" |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/mutex.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/string.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
| 34 | #include <linux/clk.h> |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 35 | #include <video/omapdss.h> |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 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> |
| 40 | #endif |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 41 | |
| 42 | #include "dss.h" |
| 43 | #include "hdmi.h" |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 44 | #include "dss_features.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 45 | |
| 46 | static struct { |
| 47 | struct mutex lock; |
| 48 | struct omap_display_platform_data *pdata; |
| 49 | struct platform_device *pdev; |
| 50 | void __iomem *base_wp; /* HDMI wrapper */ |
| 51 | int code; |
| 52 | int mode; |
| 53 | u8 edid[HDMI_EDID_MAX_LENGTH]; |
| 54 | u8 edid_set; |
| 55 | bool custom_set; |
| 56 | struct hdmi_config cfg; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 57 | |
| 58 | struct clk *sys_clk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 59 | } hdmi; |
| 60 | |
| 61 | /* |
| 62 | * Logic for the below structure : |
| 63 | * user enters the CEA or VESA timings by specifying the HDMI/DVI code. |
| 64 | * There is a correspondence between CEA/VESA timing and code, please |
| 65 | * refer to section 6.3 in HDMI 1.3 specification for timing code. |
| 66 | * |
| 67 | * In the below structure, cea_vesa_timings corresponds to all OMAP4 |
| 68 | * supported CEA and VESA timing values.code_cea corresponds to the CEA |
| 69 | * code, It is used to get the timing from cea_vesa_timing array.Similarly |
| 70 | * with code_vesa. Code_index is used for back mapping, that is once EDID |
| 71 | * is read from the TV, EDID is parsed to find the timing values and then |
| 72 | * map it to corresponding CEA or VESA index. |
| 73 | */ |
| 74 | |
| 75 | static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = { |
| 76 | { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0}, |
| 77 | { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1}, |
| 78 | { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}, |
| 79 | { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0}, |
| 80 | { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0}, |
| 81 | { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0}, |
| 82 | { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0}, |
| 83 | { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1}, |
| 84 | { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1}, |
| 85 | { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1}, |
| 86 | { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0}, |
| 87 | { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0}, |
| 88 | { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1}, |
| 89 | { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0}, |
| 90 | { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1}, |
| 91 | /* VESA From Here */ |
| 92 | { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0}, |
| 93 | { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1}, |
| 94 | { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1}, |
| 95 | { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0}, |
| 96 | { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0}, |
| 97 | { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1}, |
| 98 | { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1}, |
| 99 | { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1}, |
| 100 | { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0}, |
| 101 | { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0}, |
| 102 | { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0}, |
| 103 | { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0}, |
| 104 | { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1}, |
| 105 | { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1}, |
| 106 | { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1}, |
| 107 | { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1}, |
| 108 | { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1}, |
| 109 | { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1}, |
| 110 | { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1} |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * This is a static mapping array which maps the timing values |
| 115 | * with corresponding CEA / VESA code |
| 116 | */ |
| 117 | static const int code_index[OMAP_HDMI_TIMINGS_NB] = { |
| 118 | 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32, |
| 119 | /* <--15 CEA 17--> vesa*/ |
| 120 | 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A, |
| 121 | 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B |
| 122 | }; |
| 123 | |
| 124 | /* |
| 125 | * This is reverse static mapping which maps the CEA / VESA code |
| 126 | * to the corresponding timing values |
| 127 | */ |
| 128 | static const int code_cea[39] = { |
| 129 | -1, 0, 3, 3, 2, 8, 5, 5, -1, -1, |
| 130 | -1, -1, -1, -1, -1, -1, 9, 10, 10, 1, |
| 131 | 7, 6, 6, -1, -1, -1, -1, -1, -1, 11, |
| 132 | 11, 12, 14, -1, -1, 13, 13, 4, 4 |
| 133 | }; |
| 134 | |
| 135 | static const int code_vesa[85] = { |
| 136 | -1, -1, -1, -1, 15, -1, -1, -1, -1, 16, |
| 137 | -1, -1, -1, -1, 17, -1, 23, -1, -1, -1, |
| 138 | -1, -1, 29, 18, -1, -1, -1, 32, 19, -1, |
| 139 | -1, -1, 21, -1, -1, 22, -1, -1, -1, 20, |
| 140 | -1, 30, 24, -1, -1, -1, -1, 25, -1, -1, |
| 141 | -1, -1, -1, -1, -1, -1, -1, 31, 26, -1, |
| 142 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 143 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 144 | -1, 27, 28, -1, 33}; |
| 145 | |
| 146 | static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0}; |
| 147 | |
| 148 | static inline void hdmi_write_reg(const struct hdmi_reg idx, u32 val) |
| 149 | { |
| 150 | __raw_writel(val, hdmi.base_wp + idx.idx); |
| 151 | } |
| 152 | |
| 153 | static inline u32 hdmi_read_reg(const struct hdmi_reg idx) |
| 154 | { |
| 155 | return __raw_readl(hdmi.base_wp + idx.idx); |
| 156 | } |
| 157 | |
| 158 | static inline int hdmi_wait_for_bit_change(const struct hdmi_reg idx, |
| 159 | int b2, int b1, u32 val) |
| 160 | { |
| 161 | u32 t = 0; |
| 162 | while (val != REG_GET(idx, b2, b1)) { |
| 163 | udelay(1); |
| 164 | if (t++ > 10000) |
| 165 | return !val; |
| 166 | } |
| 167 | return val; |
| 168 | } |
| 169 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 170 | static int hdmi_runtime_get(void) |
| 171 | { |
| 172 | int r; |
| 173 | |
| 174 | DSSDBG("hdmi_runtime_get\n"); |
| 175 | |
| 176 | r = pm_runtime_get_sync(&hdmi.pdev->dev); |
| 177 | WARN_ON(r < 0); |
| 178 | return r < 0 ? r : 0; |
| 179 | } |
| 180 | |
| 181 | static void hdmi_runtime_put(void) |
| 182 | { |
| 183 | int r; |
| 184 | |
| 185 | DSSDBG("hdmi_runtime_put\n"); |
| 186 | |
| 187 | r = pm_runtime_put(&hdmi.pdev->dev); |
| 188 | WARN_ON(r < 0); |
| 189 | } |
| 190 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 191 | int hdmi_init_display(struct omap_dss_device *dssdev) |
| 192 | { |
| 193 | DSSDBG("init_display\n"); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int hdmi_pll_init(enum hdmi_clk_refsel refsel, int dcofreq, |
| 199 | struct hdmi_pll_info *fmt, u16 sd) |
| 200 | { |
| 201 | u32 r; |
| 202 | |
| 203 | /* PLL start always use manual mode */ |
| 204 | REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 0, 0); |
| 205 | |
| 206 | r = hdmi_read_reg(PLLCTRL_CFG1); |
| 207 | r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */ |
| 208 | r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */ |
| 209 | |
| 210 | hdmi_write_reg(PLLCTRL_CFG1, r); |
| 211 | |
| 212 | r = hdmi_read_reg(PLLCTRL_CFG2); |
| 213 | |
| 214 | r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */ |
| 215 | r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */ |
| 216 | r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */ |
| 217 | |
| 218 | if (dcofreq) { |
| 219 | /* divider programming for frequency beyond 1000Mhz */ |
| 220 | REG_FLD_MOD(PLLCTRL_CFG3, sd, 17, 10); |
| 221 | r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */ |
| 222 | } else { |
| 223 | r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */ |
| 224 | } |
| 225 | |
| 226 | hdmi_write_reg(PLLCTRL_CFG2, r); |
| 227 | |
| 228 | r = hdmi_read_reg(PLLCTRL_CFG4); |
| 229 | r = FLD_MOD(r, fmt->regm2, 24, 18); |
| 230 | r = FLD_MOD(r, fmt->regmf, 17, 0); |
| 231 | |
| 232 | hdmi_write_reg(PLLCTRL_CFG4, r); |
| 233 | |
| 234 | /* go now */ |
| 235 | REG_FLD_MOD(PLLCTRL_PLL_GO, 0x1, 0, 0); |
| 236 | |
| 237 | /* wait for bit change */ |
| 238 | if (hdmi_wait_for_bit_change(PLLCTRL_PLL_GO, 0, 0, 1) != 1) { |
| 239 | DSSERR("PLL GO bit not set\n"); |
| 240 | return -ETIMEDOUT; |
| 241 | } |
| 242 | |
| 243 | /* Wait till the lock bit is set in PLL status */ |
| 244 | if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) { |
| 245 | DSSWARN("cannot lock PLL\n"); |
| 246 | DSSWARN("CFG1 0x%x\n", |
| 247 | hdmi_read_reg(PLLCTRL_CFG1)); |
| 248 | DSSWARN("CFG2 0x%x\n", |
| 249 | hdmi_read_reg(PLLCTRL_CFG2)); |
| 250 | DSSWARN("CFG4 0x%x\n", |
| 251 | hdmi_read_reg(PLLCTRL_CFG4)); |
| 252 | return -ETIMEDOUT; |
| 253 | } |
| 254 | |
| 255 | DSSDBG("PLL locked!\n"); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | /* PHY_PWR_CMD */ |
| 261 | static int hdmi_set_phy_pwr(enum hdmi_phy_pwr val) |
| 262 | { |
| 263 | /* Command for power control of HDMI PHY */ |
| 264 | REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 7, 6); |
| 265 | |
| 266 | /* Status of the power control of HDMI PHY */ |
| 267 | if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 5, 4, val) != val) { |
| 268 | DSSERR("Failed to set PHY power mode to %d\n", val); |
| 269 | return -ETIMEDOUT; |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /* PLL_PWR_CMD */ |
| 276 | static int hdmi_set_pll_pwr(enum hdmi_pll_pwr val) |
| 277 | { |
| 278 | /* Command for power control of HDMI PLL */ |
| 279 | REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 3, 2); |
| 280 | |
| 281 | /* wait till PHY_PWR_STATUS is set */ |
| 282 | if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 1, 0, val) != val) { |
| 283 | DSSERR("Failed to set PHY_PWR_STATUS\n"); |
| 284 | return -ETIMEDOUT; |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int hdmi_pll_reset(void) |
| 291 | { |
| 292 | /* SYSRESET controlled by power FSM */ |
| 293 | REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 3, 3); |
| 294 | |
| 295 | /* READ 0x0 reset is in progress */ |
| 296 | if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) { |
| 297 | DSSERR("Failed to sysreset PLL\n"); |
| 298 | return -ETIMEDOUT; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int hdmi_phy_init(void) |
| 305 | { |
| 306 | u16 r = 0; |
| 307 | |
| 308 | r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_LDOON); |
| 309 | if (r) |
| 310 | return r; |
| 311 | |
| 312 | r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_TXON); |
| 313 | if (r) |
| 314 | return r; |
| 315 | |
| 316 | /* |
| 317 | * Read address 0 in order to get the SCP reset done completed |
| 318 | * Dummy access performed to make sure reset is done |
| 319 | */ |
| 320 | hdmi_read_reg(HDMI_TXPHY_TX_CTRL); |
| 321 | |
| 322 | /* |
| 323 | * Write to phy address 0 to configure the clock |
| 324 | * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field |
| 325 | */ |
| 326 | REG_FLD_MOD(HDMI_TXPHY_TX_CTRL, 0x1, 31, 30); |
| 327 | |
| 328 | /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */ |
| 329 | hdmi_write_reg(HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000); |
| 330 | |
| 331 | /* Setup max LDO voltage */ |
| 332 | REG_FLD_MOD(HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0); |
| 333 | |
| 334 | /* Write to phy address 3 to change the polarity control */ |
| 335 | REG_FLD_MOD(HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 340 | static int hdmi_pll_program(struct hdmi_pll_info *fmt) |
| 341 | { |
| 342 | u16 r = 0; |
| 343 | enum hdmi_clk_refsel refsel; |
| 344 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 345 | r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF); |
| 346 | if (r) |
| 347 | return r; |
| 348 | |
| 349 | r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_BOTHON_ALLCLKS); |
| 350 | if (r) |
| 351 | return r; |
| 352 | |
| 353 | r = hdmi_pll_reset(); |
| 354 | if (r) |
| 355 | return r; |
| 356 | |
| 357 | refsel = HDMI_REFSEL_SYSCLK; |
| 358 | |
| 359 | r = hdmi_pll_init(refsel, fmt->dcofreq, fmt, fmt->regsd); |
| 360 | if (r) |
| 361 | return r; |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static void hdmi_phy_off(void) |
| 367 | { |
| 368 | hdmi_set_phy_pwr(HDMI_PHYPWRCMD_OFF); |
| 369 | } |
| 370 | |
| 371 | static int hdmi_core_ddc_edid(u8 *pedid, int ext) |
| 372 | { |
| 373 | u32 i, j; |
| 374 | char checksum = 0; |
| 375 | u32 offset = 0; |
| 376 | |
| 377 | /* Turn on CLK for DDC */ |
| 378 | REG_FLD_MOD(HDMI_CORE_AV_DPD, 0x7, 2, 0); |
| 379 | |
| 380 | /* |
| 381 | * SW HACK : Without the Delay DDC(i2c bus) reads 0 values / |
| 382 | * right shifted values( The behavior is not consistent and seen only |
| 383 | * with some TV's) |
| 384 | */ |
| 385 | usleep_range(800, 1000); |
| 386 | |
| 387 | if (!ext) { |
| 388 | /* Clk SCL Devices */ |
| 389 | REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0xA, 3, 0); |
| 390 | |
| 391 | /* HDMI_CORE_DDC_STATUS_IN_PROG */ |
| 392 | if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS, |
| 393 | 4, 4, 0) != 0) { |
| 394 | DSSERR("Failed to program DDC\n"); |
| 395 | return -ETIMEDOUT; |
| 396 | } |
| 397 | |
| 398 | /* Clear FIFO */ |
| 399 | REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x9, 3, 0); |
| 400 | |
| 401 | /* HDMI_CORE_DDC_STATUS_IN_PROG */ |
| 402 | if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS, |
| 403 | 4, 4, 0) != 0) { |
| 404 | DSSERR("Failed to program DDC\n"); |
| 405 | return -ETIMEDOUT; |
| 406 | } |
| 407 | |
| 408 | } else { |
| 409 | if (ext % 2 != 0) |
| 410 | offset = 0x80; |
| 411 | } |
| 412 | |
| 413 | /* Load Segment Address Register */ |
| 414 | REG_FLD_MOD(HDMI_CORE_DDC_SEGM, ext/2, 7, 0); |
| 415 | |
| 416 | /* Load Slave Address Register */ |
| 417 | REG_FLD_MOD(HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1); |
| 418 | |
| 419 | /* Load Offset Address Register */ |
| 420 | REG_FLD_MOD(HDMI_CORE_DDC_OFFSET, offset, 7, 0); |
| 421 | |
| 422 | /* Load Byte Count */ |
| 423 | REG_FLD_MOD(HDMI_CORE_DDC_COUNT1, 0x80, 7, 0); |
| 424 | REG_FLD_MOD(HDMI_CORE_DDC_COUNT2, 0x0, 1, 0); |
| 425 | |
| 426 | /* Set DDC_CMD */ |
| 427 | if (ext) |
| 428 | REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x4, 3, 0); |
| 429 | else |
| 430 | REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x2, 3, 0); |
| 431 | |
| 432 | /* HDMI_CORE_DDC_STATUS_BUS_LOW */ |
| 433 | if (REG_GET(HDMI_CORE_DDC_STATUS, 6, 6) == 1) { |
| 434 | DSSWARN("I2C Bus Low?\n"); |
| 435 | return -EIO; |
| 436 | } |
| 437 | /* HDMI_CORE_DDC_STATUS_NO_ACK */ |
| 438 | if (REG_GET(HDMI_CORE_DDC_STATUS, 5, 5) == 1) { |
| 439 | DSSWARN("I2C No Ack\n"); |
| 440 | return -EIO; |
| 441 | } |
| 442 | |
| 443 | i = ext * 128; |
| 444 | j = 0; |
| 445 | while (((REG_GET(HDMI_CORE_DDC_STATUS, 4, 4) == 1) || |
| 446 | (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0)) && |
| 447 | j < 128) { |
| 448 | |
| 449 | if (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0) { |
| 450 | /* FIFO not empty */ |
| 451 | pedid[i++] = REG_GET(HDMI_CORE_DDC_DATA, 7, 0); |
| 452 | j++; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | for (j = 0; j < 128; j++) |
| 457 | checksum += pedid[j]; |
| 458 | |
| 459 | if (checksum != 0) { |
| 460 | DSSERR("E-EDID checksum failed!!\n"); |
| 461 | return -EIO; |
| 462 | } |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static int read_edid(u8 *pedid, u16 max_length) |
| 468 | { |
| 469 | int r = 0, n = 0, i = 0; |
| 470 | int max_ext_blocks = (max_length / 128) - 1; |
| 471 | |
| 472 | r = hdmi_core_ddc_edid(pedid, 0); |
| 473 | if (r) { |
| 474 | return r; |
| 475 | } else { |
| 476 | n = pedid[0x7e]; |
| 477 | |
| 478 | /* |
| 479 | * README: need to comply with max_length set by the caller. |
| 480 | * Better implementation should be to allocate necessary |
| 481 | * memory to store EDID according to nb_block field found |
| 482 | * in first block |
| 483 | */ |
| 484 | if (n > max_ext_blocks) |
| 485 | n = max_ext_blocks; |
| 486 | |
| 487 | for (i = 1; i <= n; i++) { |
| 488 | r = hdmi_core_ddc_edid(pedid, i); |
| 489 | if (r) |
| 490 | return r; |
| 491 | } |
| 492 | } |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int get_timings_index(void) |
| 497 | { |
| 498 | int code; |
| 499 | |
| 500 | if (hdmi.mode == 0) |
| 501 | code = code_vesa[hdmi.code]; |
| 502 | else |
| 503 | code = code_cea[hdmi.code]; |
| 504 | |
| 505 | if (code == -1) { |
| 506 | /* HDMI code 4 corresponds to 640 * 480 VGA */ |
| 507 | hdmi.code = 4; |
| 508 | /* DVI mode 1 corresponds to HDMI 0 to DVI */ |
| 509 | hdmi.mode = HDMI_DVI; |
| 510 | |
| 511 | code = code_vesa[hdmi.code]; |
| 512 | } |
| 513 | return code; |
| 514 | } |
| 515 | |
| 516 | static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing) |
| 517 | { |
| 518 | int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0; |
| 519 | int timing_vsync = 0, timing_hsync = 0; |
| 520 | struct omap_video_timings temp; |
| 521 | struct hdmi_cm cm = {-1}; |
| 522 | DSSDBG("hdmi_get_code\n"); |
| 523 | |
| 524 | for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) { |
| 525 | temp = cea_vesa_timings[i].timings; |
| 526 | if ((temp.pixel_clock == timing->pixel_clock) && |
| 527 | (temp.x_res == timing->x_res) && |
| 528 | (temp.y_res == timing->y_res)) { |
| 529 | |
| 530 | temp_hsync = temp.hfp + temp.hsw + temp.hbp; |
| 531 | timing_hsync = timing->hfp + timing->hsw + timing->hbp; |
| 532 | temp_vsync = temp.vfp + temp.vsw + temp.vbp; |
| 533 | timing_vsync = timing->vfp + timing->vsw + timing->vbp; |
| 534 | |
| 535 | DSSDBG("temp_hsync = %d , temp_vsync = %d" |
| 536 | "timing_hsync = %d, timing_vsync = %d\n", |
| 537 | temp_hsync, temp_hsync, |
| 538 | timing_hsync, timing_vsync); |
| 539 | |
| 540 | if ((temp_hsync == timing_hsync) && |
| 541 | (temp_vsync == timing_vsync)) { |
| 542 | code = i; |
| 543 | cm.code = code_index[i]; |
| 544 | if (code < 14) |
| 545 | cm.mode = HDMI_HDMI; |
| 546 | else |
| 547 | cm.mode = HDMI_DVI; |
| 548 | DSSDBG("Hdmi_code = %d mode = %d\n", |
| 549 | cm.code, cm.mode); |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return cm; |
| 556 | } |
| 557 | |
| 558 | static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid , |
| 559 | struct omap_video_timings *timings) |
| 560 | { |
| 561 | /* X and Y resolution */ |
| 562 | timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) | |
| 563 | edid[current_descriptor_addrs + 2]); |
| 564 | timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) | |
| 565 | edid[current_descriptor_addrs + 5]); |
| 566 | |
| 567 | timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) | |
| 568 | edid[current_descriptor_addrs]); |
| 569 | |
| 570 | timings->pixel_clock = 10 * timings->pixel_clock; |
| 571 | |
| 572 | /* HORIZONTAL FRONT PORCH */ |
| 573 | timings->hfp = edid[current_descriptor_addrs + 8] | |
| 574 | ((edid[current_descriptor_addrs + 11] & 0xc0) << 2); |
| 575 | /* HORIZONTAL SYNC WIDTH */ |
| 576 | timings->hsw = edid[current_descriptor_addrs + 9] | |
| 577 | ((edid[current_descriptor_addrs + 11] & 0x30) << 4); |
| 578 | /* HORIZONTAL BACK PORCH */ |
| 579 | timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) | |
| 580 | edid[current_descriptor_addrs + 3]) - |
| 581 | (timings->hfp + timings->hsw); |
| 582 | /* VERTICAL FRONT PORCH */ |
| 583 | timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) | |
| 584 | ((edid[current_descriptor_addrs + 11] & 0x0f) << 2); |
| 585 | /* VERTICAL SYNC WIDTH */ |
| 586 | timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) | |
| 587 | ((edid[current_descriptor_addrs + 11] & 0x03) << 4); |
| 588 | /* VERTICAL BACK PORCH */ |
| 589 | timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) | |
| 590 | edid[current_descriptor_addrs + 6]) - |
| 591 | (timings->vfp + timings->vsw); |
| 592 | |
| 593 | } |
| 594 | |
| 595 | /* Description : This function gets the resolution information from EDID */ |
| 596 | static void get_edid_timing_data(u8 *edid) |
| 597 | { |
| 598 | u8 count; |
| 599 | u16 current_descriptor_addrs; |
| 600 | struct hdmi_cm cm; |
| 601 | struct omap_video_timings edid_timings; |
| 602 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 603 | /* search block 0, there are 4 DTDs arranged in priority order */ |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 604 | for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) { |
| 605 | current_descriptor_addrs = |
| 606 | EDID_DESCRIPTOR_BLOCK0_ADDRESS + |
| 607 | count * EDID_TIMING_DESCRIPTOR_SIZE; |
| 608 | get_horz_vert_timing_info(current_descriptor_addrs, |
| 609 | edid, &edid_timings); |
| 610 | cm = hdmi_get_code(&edid_timings); |
| 611 | DSSDBG("Block0[%d] value matches code = %d , mode = %d\n", |
| 612 | count, cm.code, cm.mode); |
| 613 | if (cm.code == -1) { |
| 614 | continue; |
| 615 | } else { |
| 616 | hdmi.code = cm.code; |
| 617 | hdmi.mode = cm.mode; |
| 618 | DSSDBG("code = %d , mode = %d\n", |
| 619 | hdmi.code, hdmi.mode); |
| 620 | return; |
| 621 | } |
| 622 | } |
| 623 | if (edid[0x7e] != 0x00) { |
| 624 | for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR; |
| 625 | count++) { |
| 626 | current_descriptor_addrs = |
| 627 | EDID_DESCRIPTOR_BLOCK1_ADDRESS + |
| 628 | count * EDID_TIMING_DESCRIPTOR_SIZE; |
| 629 | get_horz_vert_timing_info(current_descriptor_addrs, |
| 630 | edid, &edid_timings); |
| 631 | cm = hdmi_get_code(&edid_timings); |
| 632 | DSSDBG("Block1[%d] value matches code = %d, mode = %d", |
| 633 | count, cm.code, cm.mode); |
| 634 | if (cm.code == -1) { |
| 635 | continue; |
| 636 | } else { |
| 637 | hdmi.code = cm.code; |
| 638 | hdmi.mode = cm.mode; |
| 639 | DSSDBG("code = %d , mode = %d\n", |
| 640 | hdmi.code, hdmi.mode); |
| 641 | return; |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | DSSINFO("no valid timing found , falling back to VGA\n"); |
| 647 | hdmi.code = 4; /* setting default value of 640 480 VGA */ |
| 648 | hdmi.mode = HDMI_DVI; |
| 649 | } |
| 650 | |
| 651 | static void hdmi_read_edid(struct omap_video_timings *dp) |
| 652 | { |
| 653 | int ret = 0, code; |
| 654 | |
| 655 | memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH); |
| 656 | |
| 657 | if (!hdmi.edid_set) |
| 658 | ret = read_edid(hdmi.edid, HDMI_EDID_MAX_LENGTH); |
| 659 | |
| 660 | if (!ret) { |
| 661 | if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) { |
| 662 | /* search for timings of default resolution */ |
| 663 | get_edid_timing_data(hdmi.edid); |
| 664 | hdmi.edid_set = true; |
| 665 | } |
| 666 | } else { |
| 667 | DSSWARN("failed to read E-EDID\n"); |
| 668 | } |
| 669 | |
| 670 | if (!hdmi.edid_set) { |
| 671 | DSSINFO("fallback to VGA\n"); |
| 672 | hdmi.code = 4; /* setting default value of 640 480 VGA */ |
| 673 | hdmi.mode = HDMI_DVI; |
| 674 | } |
| 675 | |
| 676 | code = get_timings_index(); |
| 677 | |
| 678 | *dp = cea_vesa_timings[code].timings; |
| 679 | } |
| 680 | |
| 681 | static void hdmi_core_init(struct hdmi_core_video_config *video_cfg, |
| 682 | struct hdmi_core_infoframe_avi *avi_cfg, |
| 683 | struct hdmi_core_packet_enable_repeat *repeat_cfg) |
| 684 | { |
| 685 | DSSDBG("Enter hdmi_core_init\n"); |
| 686 | |
| 687 | /* video core */ |
| 688 | video_cfg->ip_bus_width = HDMI_INPUT_8BIT; |
| 689 | video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT; |
| 690 | video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE; |
| 691 | video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE; |
| 692 | video_cfg->hdmi_dvi = HDMI_DVI; |
| 693 | video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK; |
| 694 | |
| 695 | /* info frame */ |
| 696 | avi_cfg->db1_format = 0; |
| 697 | avi_cfg->db1_active_info = 0; |
| 698 | avi_cfg->db1_bar_info_dv = 0; |
| 699 | avi_cfg->db1_scan_info = 0; |
| 700 | avi_cfg->db2_colorimetry = 0; |
| 701 | avi_cfg->db2_aspect_ratio = 0; |
| 702 | avi_cfg->db2_active_fmt_ar = 0; |
| 703 | avi_cfg->db3_itc = 0; |
| 704 | avi_cfg->db3_ec = 0; |
| 705 | avi_cfg->db3_q_range = 0; |
| 706 | avi_cfg->db3_nup_scaling = 0; |
| 707 | avi_cfg->db4_videocode = 0; |
| 708 | avi_cfg->db5_pixel_repeat = 0; |
| 709 | avi_cfg->db6_7_line_eoftop = 0 ; |
| 710 | avi_cfg->db8_9_line_sofbottom = 0; |
| 711 | avi_cfg->db10_11_pixel_eofleft = 0; |
| 712 | avi_cfg->db12_13_pixel_sofright = 0; |
| 713 | |
| 714 | /* packet enable and repeat */ |
| 715 | repeat_cfg->audio_pkt = 0; |
| 716 | repeat_cfg->audio_pkt_repeat = 0; |
| 717 | repeat_cfg->avi_infoframe = 0; |
| 718 | repeat_cfg->avi_infoframe_repeat = 0; |
| 719 | repeat_cfg->gen_cntrl_pkt = 0; |
| 720 | repeat_cfg->gen_cntrl_pkt_repeat = 0; |
| 721 | repeat_cfg->generic_pkt = 0; |
| 722 | repeat_cfg->generic_pkt_repeat = 0; |
| 723 | } |
| 724 | |
| 725 | static void hdmi_core_powerdown_disable(void) |
| 726 | { |
| 727 | DSSDBG("Enter hdmi_core_powerdown_disable\n"); |
| 728 | REG_FLD_MOD(HDMI_CORE_CTRL1, 0x0, 0, 0); |
| 729 | } |
| 730 | |
| 731 | static void hdmi_core_swreset_release(void) |
| 732 | { |
| 733 | DSSDBG("Enter hdmi_core_swreset_release\n"); |
| 734 | REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x0, 0, 0); |
| 735 | } |
| 736 | |
| 737 | static void hdmi_core_swreset_assert(void) |
| 738 | { |
| 739 | DSSDBG("Enter hdmi_core_swreset_assert\n"); |
| 740 | REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x1, 0, 0); |
| 741 | } |
| 742 | |
| 743 | /* DSS_HDMI_CORE_VIDEO_CONFIG */ |
| 744 | static void hdmi_core_video_config(struct hdmi_core_video_config *cfg) |
| 745 | { |
| 746 | u32 r = 0; |
| 747 | |
| 748 | /* sys_ctrl1 default configuration not tunable */ |
| 749 | r = hdmi_read_reg(HDMI_CORE_CTRL1); |
| 750 | r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5); |
| 751 | r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4); |
| 752 | r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2); |
| 753 | r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1); |
| 754 | hdmi_write_reg(HDMI_CORE_CTRL1, r); |
| 755 | |
| 756 | REG_FLD_MOD(HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6); |
| 757 | |
| 758 | /* Vid_Mode */ |
| 759 | r = hdmi_read_reg(HDMI_CORE_SYS_VID_MODE); |
| 760 | |
| 761 | /* dither truncation configuration */ |
| 762 | if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) { |
| 763 | r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6); |
| 764 | r = FLD_MOD(r, 1, 5, 5); |
| 765 | } else { |
| 766 | r = FLD_MOD(r, cfg->op_dither_truc, 7, 6); |
| 767 | r = FLD_MOD(r, 0, 5, 5); |
| 768 | } |
| 769 | hdmi_write_reg(HDMI_CORE_SYS_VID_MODE, r); |
| 770 | |
| 771 | /* HDMI_Ctrl */ |
| 772 | r = hdmi_read_reg(HDMI_CORE_AV_HDMI_CTRL); |
| 773 | r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6); |
| 774 | r = FLD_MOD(r, cfg->pkt_mode, 5, 3); |
| 775 | r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0); |
| 776 | hdmi_write_reg(HDMI_CORE_AV_HDMI_CTRL, r); |
| 777 | |
| 778 | /* TMDS_CTRL */ |
| 779 | REG_FLD_MOD(HDMI_CORE_SYS_TMDS_CTRL, |
| 780 | cfg->tclk_sel_clkmult, 6, 5); |
| 781 | } |
| 782 | |
| 783 | static void hdmi_core_aux_infoframe_avi_config( |
| 784 | struct hdmi_core_infoframe_avi info_avi) |
| 785 | { |
| 786 | u32 val; |
| 787 | char sum = 0, checksum = 0; |
| 788 | |
| 789 | sum += 0x82 + 0x002 + 0x00D; |
| 790 | hdmi_write_reg(HDMI_CORE_AV_AVI_TYPE, 0x082); |
| 791 | hdmi_write_reg(HDMI_CORE_AV_AVI_VERS, 0x002); |
| 792 | hdmi_write_reg(HDMI_CORE_AV_AVI_LEN, 0x00D); |
| 793 | |
| 794 | val = (info_avi.db1_format << 5) | |
| 795 | (info_avi.db1_active_info << 4) | |
| 796 | (info_avi.db1_bar_info_dv << 2) | |
| 797 | (info_avi.db1_scan_info); |
| 798 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(0), val); |
| 799 | sum += val; |
| 800 | |
| 801 | val = (info_avi.db2_colorimetry << 6) | |
| 802 | (info_avi.db2_aspect_ratio << 4) | |
| 803 | (info_avi.db2_active_fmt_ar); |
| 804 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(1), val); |
| 805 | sum += val; |
| 806 | |
| 807 | val = (info_avi.db3_itc << 7) | |
| 808 | (info_avi.db3_ec << 4) | |
| 809 | (info_avi.db3_q_range << 2) | |
| 810 | (info_avi.db3_nup_scaling); |
| 811 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(2), val); |
| 812 | sum += val; |
| 813 | |
| 814 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(3), info_avi.db4_videocode); |
| 815 | sum += info_avi.db4_videocode; |
| 816 | |
| 817 | val = info_avi.db5_pixel_repeat; |
| 818 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(4), val); |
| 819 | sum += val; |
| 820 | |
| 821 | val = info_avi.db6_7_line_eoftop & 0x00FF; |
| 822 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(5), val); |
| 823 | sum += val; |
| 824 | |
| 825 | val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF); |
| 826 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(6), val); |
| 827 | sum += val; |
| 828 | |
| 829 | val = info_avi.db8_9_line_sofbottom & 0x00FF; |
| 830 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(7), val); |
| 831 | sum += val; |
| 832 | |
| 833 | val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF); |
| 834 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(8), val); |
| 835 | sum += val; |
| 836 | |
| 837 | val = info_avi.db10_11_pixel_eofleft & 0x00FF; |
| 838 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(9), val); |
| 839 | sum += val; |
| 840 | |
| 841 | val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF); |
| 842 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(10), val); |
| 843 | sum += val; |
| 844 | |
| 845 | val = info_avi.db12_13_pixel_sofright & 0x00FF; |
| 846 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(11), val); |
| 847 | sum += val; |
| 848 | |
| 849 | val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF); |
| 850 | hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(12), val); |
| 851 | sum += val; |
| 852 | |
| 853 | checksum = 0x100 - sum; |
| 854 | hdmi_write_reg(HDMI_CORE_AV_AVI_CHSUM, checksum); |
| 855 | } |
| 856 | |
| 857 | static void hdmi_core_av_packet_config( |
| 858 | struct hdmi_core_packet_enable_repeat repeat_cfg) |
| 859 | { |
| 860 | /* enable/repeat the infoframe */ |
| 861 | hdmi_write_reg(HDMI_CORE_AV_PB_CTRL1, |
| 862 | (repeat_cfg.audio_pkt << 5) | |
| 863 | (repeat_cfg.audio_pkt_repeat << 4) | |
| 864 | (repeat_cfg.avi_infoframe << 1) | |
| 865 | (repeat_cfg.avi_infoframe_repeat)); |
| 866 | |
| 867 | /* enable/repeat the packet */ |
| 868 | hdmi_write_reg(HDMI_CORE_AV_PB_CTRL2, |
| 869 | (repeat_cfg.gen_cntrl_pkt << 3) | |
| 870 | (repeat_cfg.gen_cntrl_pkt_repeat << 2) | |
| 871 | (repeat_cfg.generic_pkt << 1) | |
| 872 | (repeat_cfg.generic_pkt_repeat)); |
| 873 | } |
| 874 | |
| 875 | static void hdmi_wp_init(struct omap_video_timings *timings, |
| 876 | struct hdmi_video_format *video_fmt, |
| 877 | struct hdmi_video_interface *video_int) |
| 878 | { |
| 879 | DSSDBG("Enter hdmi_wp_init\n"); |
| 880 | |
| 881 | timings->hbp = 0; |
| 882 | timings->hfp = 0; |
| 883 | timings->hsw = 0; |
| 884 | timings->vbp = 0; |
| 885 | timings->vfp = 0; |
| 886 | timings->vsw = 0; |
| 887 | |
| 888 | video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444; |
| 889 | video_fmt->y_res = 0; |
| 890 | video_fmt->x_res = 0; |
| 891 | |
| 892 | video_int->vsp = 0; |
| 893 | video_int->hsp = 0; |
| 894 | |
| 895 | video_int->interlacing = 0; |
| 896 | video_int->tm = 0; /* HDMI_TIMING_SLAVE */ |
| 897 | |
| 898 | } |
| 899 | |
| 900 | static void hdmi_wp_video_start(bool start) |
| 901 | { |
| 902 | REG_FLD_MOD(HDMI_WP_VIDEO_CFG, start, 31, 31); |
| 903 | } |
| 904 | |
| 905 | static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt, |
| 906 | struct omap_video_timings *timings, struct hdmi_config *param) |
| 907 | { |
| 908 | DSSDBG("Enter hdmi_wp_video_init_format\n"); |
| 909 | |
| 910 | video_fmt->y_res = param->timings.timings.y_res; |
| 911 | video_fmt->x_res = param->timings.timings.x_res; |
| 912 | |
| 913 | timings->hbp = param->timings.timings.hbp; |
| 914 | timings->hfp = param->timings.timings.hfp; |
| 915 | timings->hsw = param->timings.timings.hsw; |
| 916 | timings->vbp = param->timings.timings.vbp; |
| 917 | timings->vfp = param->timings.timings.vfp; |
| 918 | timings->vsw = param->timings.timings.vsw; |
| 919 | } |
| 920 | |
| 921 | static void hdmi_wp_video_config_format( |
| 922 | struct hdmi_video_format *video_fmt) |
| 923 | { |
| 924 | u32 l = 0; |
| 925 | |
| 926 | REG_FLD_MOD(HDMI_WP_VIDEO_CFG, video_fmt->packing_mode, 10, 8); |
| 927 | |
| 928 | l |= FLD_VAL(video_fmt->y_res, 31, 16); |
| 929 | l |= FLD_VAL(video_fmt->x_res, 15, 0); |
| 930 | hdmi_write_reg(HDMI_WP_VIDEO_SIZE, l); |
| 931 | } |
| 932 | |
| 933 | static void hdmi_wp_video_config_interface( |
| 934 | struct hdmi_video_interface *video_int) |
| 935 | { |
| 936 | u32 r; |
| 937 | DSSDBG("Enter hdmi_wp_video_config_interface\n"); |
| 938 | |
| 939 | r = hdmi_read_reg(HDMI_WP_VIDEO_CFG); |
| 940 | r = FLD_MOD(r, video_int->vsp, 7, 7); |
| 941 | r = FLD_MOD(r, video_int->hsp, 6, 6); |
| 942 | r = FLD_MOD(r, video_int->interlacing, 3, 3); |
| 943 | r = FLD_MOD(r, video_int->tm, 1, 0); |
| 944 | hdmi_write_reg(HDMI_WP_VIDEO_CFG, r); |
| 945 | } |
| 946 | |
| 947 | static void hdmi_wp_video_config_timing( |
| 948 | struct omap_video_timings *timings) |
| 949 | { |
| 950 | u32 timing_h = 0; |
| 951 | u32 timing_v = 0; |
| 952 | |
| 953 | DSSDBG("Enter hdmi_wp_video_config_timing\n"); |
| 954 | |
| 955 | timing_h |= FLD_VAL(timings->hbp, 31, 20); |
| 956 | timing_h |= FLD_VAL(timings->hfp, 19, 8); |
| 957 | timing_h |= FLD_VAL(timings->hsw, 7, 0); |
| 958 | hdmi_write_reg(HDMI_WP_VIDEO_TIMING_H, timing_h); |
| 959 | |
| 960 | timing_v |= FLD_VAL(timings->vbp, 31, 20); |
| 961 | timing_v |= FLD_VAL(timings->vfp, 19, 8); |
| 962 | timing_v |= FLD_VAL(timings->vsw, 7, 0); |
| 963 | hdmi_write_reg(HDMI_WP_VIDEO_TIMING_V, timing_v); |
| 964 | } |
| 965 | |
| 966 | static void hdmi_basic_configure(struct hdmi_config *cfg) |
| 967 | { |
| 968 | /* HDMI */ |
| 969 | struct omap_video_timings video_timing; |
| 970 | struct hdmi_video_format video_format; |
| 971 | struct hdmi_video_interface video_interface; |
| 972 | /* HDMI core */ |
| 973 | struct hdmi_core_infoframe_avi avi_cfg; |
| 974 | struct hdmi_core_video_config v_core_cfg; |
| 975 | struct hdmi_core_packet_enable_repeat repeat_cfg; |
| 976 | |
| 977 | hdmi_wp_init(&video_timing, &video_format, |
| 978 | &video_interface); |
| 979 | |
| 980 | hdmi_core_init(&v_core_cfg, |
| 981 | &avi_cfg, |
| 982 | &repeat_cfg); |
| 983 | |
| 984 | hdmi_wp_video_init_format(&video_format, |
| 985 | &video_timing, cfg); |
| 986 | |
| 987 | hdmi_wp_video_config_timing(&video_timing); |
| 988 | |
| 989 | /* video config */ |
| 990 | video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422; |
| 991 | |
| 992 | hdmi_wp_video_config_format(&video_format); |
| 993 | |
| 994 | video_interface.vsp = cfg->timings.vsync_pol; |
| 995 | video_interface.hsp = cfg->timings.hsync_pol; |
| 996 | video_interface.interlacing = cfg->interlace; |
| 997 | video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */ |
| 998 | |
| 999 | hdmi_wp_video_config_interface(&video_interface); |
| 1000 | |
| 1001 | /* |
| 1002 | * configure core video part |
| 1003 | * set software reset in the core |
| 1004 | */ |
| 1005 | hdmi_core_swreset_assert(); |
| 1006 | |
| 1007 | /* power down off */ |
| 1008 | hdmi_core_powerdown_disable(); |
| 1009 | |
| 1010 | v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL; |
| 1011 | v_core_cfg.hdmi_dvi = cfg->cm.mode; |
| 1012 | |
| 1013 | hdmi_core_video_config(&v_core_cfg); |
| 1014 | |
| 1015 | /* release software reset in the core */ |
| 1016 | hdmi_core_swreset_release(); |
| 1017 | |
| 1018 | /* |
| 1019 | * configure packet |
| 1020 | * info frame video see doc CEA861-D page 65 |
| 1021 | */ |
| 1022 | avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB; |
| 1023 | avi_cfg.db1_active_info = |
| 1024 | HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF; |
| 1025 | avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO; |
| 1026 | avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0; |
| 1027 | avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO; |
| 1028 | avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO; |
| 1029 | avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME; |
| 1030 | avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO; |
| 1031 | avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601; |
| 1032 | avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT; |
| 1033 | avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO; |
| 1034 | avi_cfg.db4_videocode = cfg->cm.code; |
| 1035 | avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO; |
| 1036 | avi_cfg.db6_7_line_eoftop = 0; |
| 1037 | avi_cfg.db8_9_line_sofbottom = 0; |
| 1038 | avi_cfg.db10_11_pixel_eofleft = 0; |
| 1039 | avi_cfg.db12_13_pixel_sofright = 0; |
| 1040 | |
| 1041 | hdmi_core_aux_infoframe_avi_config(avi_cfg); |
| 1042 | |
| 1043 | /* enable/repeat the infoframe */ |
| 1044 | repeat_cfg.avi_infoframe = HDMI_PACKETENABLE; |
| 1045 | repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON; |
| 1046 | /* wakeup */ |
| 1047 | repeat_cfg.audio_pkt = HDMI_PACKETENABLE; |
| 1048 | repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON; |
| 1049 | hdmi_core_av_packet_config(repeat_cfg); |
| 1050 | } |
| 1051 | |
| 1052 | static void update_hdmi_timings(struct hdmi_config *cfg, |
| 1053 | struct omap_video_timings *timings, int code) |
| 1054 | { |
| 1055 | cfg->timings.timings.x_res = timings->x_res; |
| 1056 | cfg->timings.timings.y_res = timings->y_res; |
| 1057 | cfg->timings.timings.hbp = timings->hbp; |
| 1058 | cfg->timings.timings.hfp = timings->hfp; |
| 1059 | cfg->timings.timings.hsw = timings->hsw; |
| 1060 | cfg->timings.timings.vbp = timings->vbp; |
| 1061 | cfg->timings.timings.vfp = timings->vfp; |
| 1062 | cfg->timings.timings.vsw = timings->vsw; |
| 1063 | cfg->timings.timings.pixel_clock = timings->pixel_clock; |
| 1064 | cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol; |
| 1065 | cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol; |
| 1066 | } |
| 1067 | |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1068 | static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy, |
| 1069 | struct hdmi_pll_info *pi) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1070 | { |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1071 | unsigned long clkin, refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1072 | u32 mf; |
| 1073 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1074 | clkin = clk_get_rate(hdmi.sys_clk) / 10000; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1075 | /* |
| 1076 | * Input clock is predivided by N + 1 |
| 1077 | * out put of which is reference clk |
| 1078 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1079 | pi->regn = dssdev->clocks.hdmi.regn; |
| 1080 | refclk = clkin / (pi->regn + 1); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1081 | |
| 1082 | /* |
| 1083 | * multiplier is pixel_clk/ref_clk |
| 1084 | * Multiplying by 100 to avoid fractional part removal |
| 1085 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1086 | pi->regm = (phy * 100 / (refclk)) / 100; |
| 1087 | pi->regm2 = dssdev->clocks.hdmi.regm2; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1088 | |
| 1089 | /* |
| 1090 | * fractional multiplier is remainder of the difference between |
| 1091 | * multiplier and actual phy(required pixel clock thus should be |
| 1092 | * multiplied by 2^18(262144) divided by the reference clock |
| 1093 | */ |
| 1094 | mf = (phy - pi->regm * refclk) * 262144; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1095 | pi->regmf = mf / (refclk); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1096 | |
| 1097 | /* |
| 1098 | * Dcofreq should be set to 1 if required pixel clock |
| 1099 | * is greater than 1000MHz |
| 1100 | */ |
| 1101 | pi->dcofreq = phy > 1000 * 100; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1102 | pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1103 | |
| 1104 | DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf); |
| 1105 | DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd); |
| 1106 | } |
| 1107 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1108 | static int hdmi_power_on(struct omap_dss_device *dssdev) |
| 1109 | { |
| 1110 | int r, code = 0; |
| 1111 | struct hdmi_pll_info pll_data; |
| 1112 | struct omap_video_timings *p; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1113 | unsigned long phy; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1114 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1115 | r = hdmi_runtime_get(); |
| 1116 | if (r) |
| 1117 | return r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1118 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame^] | 1119 | dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1120 | |
| 1121 | p = &dssdev->panel.timings; |
| 1122 | |
| 1123 | DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", |
| 1124 | dssdev->panel.timings.x_res, |
| 1125 | dssdev->panel.timings.y_res); |
| 1126 | |
| 1127 | if (!hdmi.custom_set) { |
| 1128 | DSSDBG("Read EDID as no EDID is not set on poweron\n"); |
| 1129 | hdmi_read_edid(p); |
| 1130 | } |
| 1131 | code = get_timings_index(); |
| 1132 | dssdev->panel.timings = cea_vesa_timings[code].timings; |
| 1133 | update_hdmi_timings(&hdmi.cfg, p, code); |
| 1134 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1135 | phy = p->pixel_clock; |
| 1136 | |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1137 | hdmi_compute_pll(dssdev, phy, &pll_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1138 | |
| 1139 | hdmi_wp_video_start(0); |
| 1140 | |
| 1141 | /* config the PLL and PHY first */ |
| 1142 | r = hdmi_pll_program(&pll_data); |
| 1143 | if (r) { |
| 1144 | DSSDBG("Failed to lock PLL\n"); |
| 1145 | goto err; |
| 1146 | } |
| 1147 | |
| 1148 | r = hdmi_phy_init(); |
| 1149 | if (r) { |
| 1150 | DSSDBG("Failed to start PHY\n"); |
| 1151 | goto err; |
| 1152 | } |
| 1153 | |
| 1154 | hdmi.cfg.cm.mode = hdmi.mode; |
| 1155 | hdmi.cfg.cm.code = hdmi.code; |
| 1156 | hdmi_basic_configure(&hdmi.cfg); |
| 1157 | |
| 1158 | /* Make selection of HDMI in DSS */ |
| 1159 | dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); |
| 1160 | |
| 1161 | /* Select the dispc clock source as PRCM clock, to ensure that it is not |
| 1162 | * DSI PLL source as the clock selected by DSI PLL might not be |
| 1163 | * sufficient for the resolution selected / that can be changed |
| 1164 | * dynamically by user. This can be moved to single location , say |
| 1165 | * Boardfile. |
| 1166 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 1167 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1168 | |
| 1169 | /* bypass TV gamma table */ |
| 1170 | dispc_enable_gamma_table(0); |
| 1171 | |
| 1172 | /* tv size */ |
| 1173 | dispc_set_digit_size(dssdev->panel.timings.x_res, |
| 1174 | dssdev->panel.timings.y_res); |
| 1175 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame^] | 1176 | dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1177 | |
| 1178 | hdmi_wp_video_start(1); |
| 1179 | |
| 1180 | return 0; |
| 1181 | err: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1182 | hdmi_runtime_put(); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1183 | return -EIO; |
| 1184 | } |
| 1185 | |
| 1186 | static void hdmi_power_off(struct omap_dss_device *dssdev) |
| 1187 | { |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame^] | 1188 | dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1189 | |
| 1190 | hdmi_wp_video_start(0); |
| 1191 | hdmi_phy_off(); |
| 1192 | hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1193 | hdmi_runtime_put(); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1194 | |
| 1195 | hdmi.edid_set = 0; |
| 1196 | } |
| 1197 | |
| 1198 | int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev, |
| 1199 | struct omap_video_timings *timings) |
| 1200 | { |
| 1201 | struct hdmi_cm cm; |
| 1202 | |
| 1203 | cm = hdmi_get_code(timings); |
| 1204 | if (cm.code == -1) { |
| 1205 | DSSERR("Invalid timing entered\n"); |
| 1206 | return -EINVAL; |
| 1207 | } |
| 1208 | |
| 1209 | return 0; |
| 1210 | |
| 1211 | } |
| 1212 | |
| 1213 | void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev) |
| 1214 | { |
| 1215 | struct hdmi_cm cm; |
| 1216 | |
| 1217 | hdmi.custom_set = 1; |
| 1218 | cm = hdmi_get_code(&dssdev->panel.timings); |
| 1219 | hdmi.code = cm.code; |
| 1220 | hdmi.mode = cm.mode; |
| 1221 | omapdss_hdmi_display_enable(dssdev); |
| 1222 | hdmi.custom_set = 0; |
| 1223 | } |
| 1224 | |
| 1225 | int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev) |
| 1226 | { |
| 1227 | int r = 0; |
| 1228 | |
| 1229 | DSSDBG("ENTER hdmi_display_enable\n"); |
| 1230 | |
| 1231 | mutex_lock(&hdmi.lock); |
| 1232 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 1233 | if (dssdev->manager == NULL) { |
| 1234 | DSSERR("failed to enable display: no manager\n"); |
| 1235 | r = -ENODEV; |
| 1236 | goto err0; |
| 1237 | } |
| 1238 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1239 | r = omap_dss_start_device(dssdev); |
| 1240 | if (r) { |
| 1241 | DSSERR("failed to start device\n"); |
| 1242 | goto err0; |
| 1243 | } |
| 1244 | |
| 1245 | if (dssdev->platform_enable) { |
| 1246 | r = dssdev->platform_enable(dssdev); |
| 1247 | if (r) { |
| 1248 | DSSERR("failed to enable GPIO's\n"); |
| 1249 | goto err1; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | r = hdmi_power_on(dssdev); |
| 1254 | if (r) { |
| 1255 | DSSERR("failed to power on device\n"); |
| 1256 | goto err2; |
| 1257 | } |
| 1258 | |
| 1259 | mutex_unlock(&hdmi.lock); |
| 1260 | return 0; |
| 1261 | |
| 1262 | err2: |
| 1263 | if (dssdev->platform_disable) |
| 1264 | dssdev->platform_disable(dssdev); |
| 1265 | err1: |
| 1266 | omap_dss_stop_device(dssdev); |
| 1267 | err0: |
| 1268 | mutex_unlock(&hdmi.lock); |
| 1269 | return r; |
| 1270 | } |
| 1271 | |
| 1272 | void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev) |
| 1273 | { |
| 1274 | DSSDBG("Enter hdmi_display_disable\n"); |
| 1275 | |
| 1276 | mutex_lock(&hdmi.lock); |
| 1277 | |
| 1278 | hdmi_power_off(dssdev); |
| 1279 | |
| 1280 | if (dssdev->platform_disable) |
| 1281 | dssdev->platform_disable(dssdev); |
| 1282 | |
| 1283 | omap_dss_stop_device(dssdev); |
| 1284 | |
| 1285 | mutex_unlock(&hdmi.lock); |
| 1286 | } |
| 1287 | |
Ricardo Neri | 82335c4 | 2011-04-05 16:05:18 -0500 | [diff] [blame] | 1288 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 1289 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 1290 | static void hdmi_wp_audio_config_format( |
| 1291 | struct hdmi_audio_format *aud_fmt) |
| 1292 | { |
| 1293 | u32 r; |
| 1294 | |
| 1295 | DSSDBG("Enter hdmi_wp_audio_config_format\n"); |
| 1296 | |
| 1297 | r = hdmi_read_reg(HDMI_WP_AUDIO_CFG); |
| 1298 | r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24); |
| 1299 | r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16); |
| 1300 | r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5); |
| 1301 | r = FLD_MOD(r, aud_fmt->type, 4, 4); |
| 1302 | r = FLD_MOD(r, aud_fmt->justification, 3, 3); |
| 1303 | r = FLD_MOD(r, aud_fmt->sample_order, 2, 2); |
| 1304 | r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1); |
| 1305 | r = FLD_MOD(r, aud_fmt->sample_size, 0, 0); |
| 1306 | hdmi_write_reg(HDMI_WP_AUDIO_CFG, r); |
| 1307 | } |
| 1308 | |
| 1309 | static void hdmi_wp_audio_config_dma(struct hdmi_audio_dma *aud_dma) |
| 1310 | { |
| 1311 | u32 r; |
| 1312 | |
| 1313 | DSSDBG("Enter hdmi_wp_audio_config_dma\n"); |
| 1314 | |
| 1315 | r = hdmi_read_reg(HDMI_WP_AUDIO_CFG2); |
| 1316 | r = FLD_MOD(r, aud_dma->transfer_size, 15, 8); |
| 1317 | r = FLD_MOD(r, aud_dma->block_size, 7, 0); |
| 1318 | hdmi_write_reg(HDMI_WP_AUDIO_CFG2, r); |
| 1319 | |
| 1320 | r = hdmi_read_reg(HDMI_WP_AUDIO_CTRL); |
| 1321 | r = FLD_MOD(r, aud_dma->mode, 9, 9); |
| 1322 | r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0); |
| 1323 | hdmi_write_reg(HDMI_WP_AUDIO_CTRL, r); |
| 1324 | } |
| 1325 | |
| 1326 | static void hdmi_core_audio_config(struct hdmi_core_audio_config *cfg) |
| 1327 | { |
| 1328 | u32 r; |
| 1329 | |
| 1330 | /* audio clock recovery parameters */ |
| 1331 | r = hdmi_read_reg(HDMI_CORE_AV_ACR_CTRL); |
| 1332 | r = FLD_MOD(r, cfg->use_mclk, 2, 2); |
| 1333 | r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1); |
| 1334 | r = FLD_MOD(r, cfg->cts_mode, 0, 0); |
| 1335 | hdmi_write_reg(HDMI_CORE_AV_ACR_CTRL, r); |
| 1336 | |
| 1337 | REG_FLD_MOD(HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0); |
| 1338 | REG_FLD_MOD(HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0); |
| 1339 | REG_FLD_MOD(HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0); |
| 1340 | |
| 1341 | if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) { |
| 1342 | REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0); |
| 1343 | REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0); |
| 1344 | REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0); |
| 1345 | } else { |
| 1346 | /* |
| 1347 | * HDMI IP uses this configuration to divide the MCLK to |
| 1348 | * update CTS value. |
| 1349 | */ |
| 1350 | REG_FLD_MOD(HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0); |
| 1351 | |
| 1352 | /* Configure clock for audio packets */ |
| 1353 | REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_1, |
| 1354 | cfg->aud_par_busclk, 7, 0); |
| 1355 | REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_2, |
| 1356 | (cfg->aud_par_busclk >> 8), 7, 0); |
| 1357 | REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_3, |
| 1358 | (cfg->aud_par_busclk >> 16), 7, 0); |
| 1359 | } |
| 1360 | |
| 1361 | /* Override of SPDIF sample frequency with value in I2S_CHST4 */ |
| 1362 | REG_FLD_MOD(HDMI_CORE_AV_SPDIF_CTRL, cfg->fs_override, 1, 1); |
| 1363 | |
| 1364 | /* I2S parameters */ |
| 1365 | REG_FLD_MOD(HDMI_CORE_AV_I2S_CHST4, cfg->freq_sample, 3, 0); |
| 1366 | |
| 1367 | r = hdmi_read_reg(HDMI_CORE_AV_I2S_IN_CTRL); |
| 1368 | r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7); |
| 1369 | r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6); |
| 1370 | r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5); |
| 1371 | r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4); |
| 1372 | r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3); |
| 1373 | r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2); |
| 1374 | r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1); |
| 1375 | r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0); |
| 1376 | hdmi_write_reg(HDMI_CORE_AV_I2S_IN_CTRL, r); |
| 1377 | |
| 1378 | r = hdmi_read_reg(HDMI_CORE_AV_I2S_CHST5); |
| 1379 | r = FLD_MOD(r, cfg->freq_sample, 7, 4); |
| 1380 | r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1); |
| 1381 | r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0); |
| 1382 | hdmi_write_reg(HDMI_CORE_AV_I2S_CHST5, r); |
| 1383 | |
| 1384 | REG_FLD_MOD(HDMI_CORE_AV_I2S_IN_LEN, cfg->i2s_cfg.in_length_bits, 3, 0); |
| 1385 | |
| 1386 | /* Audio channels and mode parameters */ |
| 1387 | REG_FLD_MOD(HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1); |
| 1388 | r = hdmi_read_reg(HDMI_CORE_AV_AUD_MODE); |
| 1389 | r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4); |
| 1390 | r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3); |
| 1391 | r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2); |
| 1392 | r = FLD_MOD(r, cfg->en_spdif, 1, 1); |
| 1393 | hdmi_write_reg(HDMI_CORE_AV_AUD_MODE, r); |
| 1394 | } |
| 1395 | |
| 1396 | static void hdmi_core_audio_infoframe_config( |
| 1397 | struct hdmi_core_infoframe_audio *info_aud) |
| 1398 | { |
| 1399 | u8 val; |
| 1400 | u8 sum = 0, checksum = 0; |
| 1401 | |
| 1402 | /* |
| 1403 | * Set audio info frame type, version and length as |
| 1404 | * described in HDMI 1.4a Section 8.2.2 specification. |
| 1405 | * Checksum calculation is defined in Section 5.3.5. |
| 1406 | */ |
| 1407 | hdmi_write_reg(HDMI_CORE_AV_AUDIO_TYPE, 0x84); |
| 1408 | hdmi_write_reg(HDMI_CORE_AV_AUDIO_VERS, 0x01); |
| 1409 | hdmi_write_reg(HDMI_CORE_AV_AUDIO_LEN, 0x0a); |
| 1410 | sum += 0x84 + 0x001 + 0x00a; |
| 1411 | |
| 1412 | val = (info_aud->db1_coding_type << 4) |
| 1413 | | (info_aud->db1_channel_count - 1); |
| 1414 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(0), val); |
| 1415 | sum += val; |
| 1416 | |
| 1417 | val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size; |
| 1418 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(1), val); |
| 1419 | sum += val; |
| 1420 | |
| 1421 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(2), 0x00); |
| 1422 | |
| 1423 | val = info_aud->db4_channel_alloc; |
| 1424 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(3), val); |
| 1425 | sum += val; |
| 1426 | |
| 1427 | val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3); |
| 1428 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(4), val); |
| 1429 | sum += val; |
| 1430 | |
| 1431 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(5), 0x00); |
| 1432 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(6), 0x00); |
| 1433 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(7), 0x00); |
| 1434 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(8), 0x00); |
| 1435 | hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(9), 0x00); |
| 1436 | |
| 1437 | checksum = 0x100 - sum; |
| 1438 | hdmi_write_reg(HDMI_CORE_AV_AUDIO_CHSUM, checksum); |
| 1439 | |
| 1440 | /* |
| 1441 | * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing |
| 1442 | * is available. |
| 1443 | */ |
| 1444 | } |
| 1445 | |
| 1446 | static int hdmi_config_audio_acr(u32 sample_freq, u32 *n, u32 *cts) |
| 1447 | { |
| 1448 | u32 r; |
| 1449 | u32 deep_color = 0; |
| 1450 | u32 pclk = hdmi.cfg.timings.timings.pixel_clock; |
| 1451 | |
| 1452 | if (n == NULL || cts == NULL) |
| 1453 | return -EINVAL; |
| 1454 | /* |
| 1455 | * Obtain current deep color configuration. This needed |
| 1456 | * to calculate the TMDS clock based on the pixel clock. |
| 1457 | */ |
| 1458 | r = REG_GET(HDMI_WP_VIDEO_CFG, 1, 0); |
| 1459 | switch (r) { |
| 1460 | case 1: /* No deep color selected */ |
| 1461 | deep_color = 100; |
| 1462 | break; |
| 1463 | case 2: /* 10-bit deep color selected */ |
| 1464 | deep_color = 125; |
| 1465 | break; |
| 1466 | case 3: /* 12-bit deep color selected */ |
| 1467 | deep_color = 150; |
| 1468 | break; |
| 1469 | default: |
| 1470 | return -EINVAL; |
| 1471 | } |
| 1472 | |
| 1473 | switch (sample_freq) { |
| 1474 | case 32000: |
| 1475 | if ((deep_color == 125) && ((pclk == 54054) |
| 1476 | || (pclk == 74250))) |
| 1477 | *n = 8192; |
| 1478 | else |
| 1479 | *n = 4096; |
| 1480 | break; |
| 1481 | case 44100: |
| 1482 | *n = 6272; |
| 1483 | break; |
| 1484 | case 48000: |
| 1485 | if ((deep_color == 125) && ((pclk == 54054) |
| 1486 | || (pclk == 74250))) |
| 1487 | *n = 8192; |
| 1488 | else |
| 1489 | *n = 6144; |
| 1490 | break; |
| 1491 | default: |
| 1492 | *n = 0; |
| 1493 | return -EINVAL; |
| 1494 | } |
| 1495 | |
| 1496 | /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */ |
| 1497 | *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10); |
| 1498 | |
| 1499 | return 0; |
| 1500 | } |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1501 | |
| 1502 | static int hdmi_audio_hw_params(struct snd_pcm_substream *substream, |
| 1503 | struct snd_pcm_hw_params *params, |
| 1504 | struct snd_soc_dai *dai) |
| 1505 | { |
| 1506 | struct hdmi_audio_format audio_format; |
| 1507 | struct hdmi_audio_dma audio_dma; |
| 1508 | struct hdmi_core_audio_config core_cfg; |
| 1509 | struct hdmi_core_infoframe_audio aud_if_cfg; |
| 1510 | int err, n, cts; |
| 1511 | enum hdmi_core_audio_sample_freq sample_freq; |
| 1512 | |
| 1513 | switch (params_format(params)) { |
| 1514 | case SNDRV_PCM_FORMAT_S16_LE: |
| 1515 | core_cfg.i2s_cfg.word_max_length = |
| 1516 | HDMI_AUDIO_I2S_MAX_WORD_20BITS; |
| 1517 | core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS; |
| 1518 | core_cfg.i2s_cfg.in_length_bits = |
| 1519 | HDMI_AUDIO_I2S_INPUT_LENGTH_16; |
| 1520 | core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT; |
| 1521 | audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES; |
| 1522 | audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS; |
| 1523 | audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT; |
| 1524 | audio_dma.transfer_size = 0x10; |
| 1525 | break; |
| 1526 | case SNDRV_PCM_FORMAT_S24_LE: |
| 1527 | core_cfg.i2s_cfg.word_max_length = |
| 1528 | HDMI_AUDIO_I2S_MAX_WORD_24BITS; |
| 1529 | core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS; |
| 1530 | core_cfg.i2s_cfg.in_length_bits = |
| 1531 | HDMI_AUDIO_I2S_INPUT_LENGTH_24; |
| 1532 | audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE; |
| 1533 | audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS; |
| 1534 | audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT; |
| 1535 | core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT; |
| 1536 | audio_dma.transfer_size = 0x20; |
| 1537 | break; |
| 1538 | default: |
| 1539 | return -EINVAL; |
| 1540 | } |
| 1541 | |
| 1542 | switch (params_rate(params)) { |
| 1543 | case 32000: |
| 1544 | sample_freq = HDMI_AUDIO_FS_32000; |
| 1545 | break; |
| 1546 | case 44100: |
| 1547 | sample_freq = HDMI_AUDIO_FS_44100; |
| 1548 | break; |
| 1549 | case 48000: |
| 1550 | sample_freq = HDMI_AUDIO_FS_48000; |
| 1551 | break; |
| 1552 | default: |
| 1553 | return -EINVAL; |
| 1554 | } |
| 1555 | |
| 1556 | err = hdmi_config_audio_acr(params_rate(params), &n, &cts); |
| 1557 | if (err < 0) |
| 1558 | return err; |
| 1559 | |
| 1560 | /* Audio wrapper config */ |
| 1561 | audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL; |
| 1562 | audio_format.active_chnnls_msk = 0x03; |
| 1563 | audio_format.type = HDMI_AUDIO_TYPE_LPCM; |
| 1564 | audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST; |
| 1565 | /* Disable start/stop signals of IEC 60958 blocks */ |
| 1566 | audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF; |
| 1567 | |
| 1568 | audio_dma.block_size = 0xC0; |
| 1569 | audio_dma.mode = HDMI_AUDIO_TRANSF_DMA; |
| 1570 | audio_dma.fifo_threshold = 0x20; /* in number of samples */ |
| 1571 | |
| 1572 | hdmi_wp_audio_config_dma(&audio_dma); |
| 1573 | hdmi_wp_audio_config_format(&audio_format); |
| 1574 | |
| 1575 | /* |
| 1576 | * I2S config |
| 1577 | */ |
| 1578 | core_cfg.i2s_cfg.en_high_bitrate_aud = false; |
| 1579 | /* Only used with high bitrate audio */ |
| 1580 | core_cfg.i2s_cfg.cbit_order = false; |
| 1581 | /* Serial data and word select should change on sck rising edge */ |
| 1582 | core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING; |
| 1583 | core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM; |
| 1584 | /* Set I2S word select polarity */ |
| 1585 | core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT; |
| 1586 | core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST; |
| 1587 | /* Set serial data to word select shift. See Phillips spec. */ |
| 1588 | core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT; |
| 1589 | /* Enable one of the four available serial data channels */ |
| 1590 | core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN; |
| 1591 | |
| 1592 | /* Core audio config */ |
| 1593 | core_cfg.freq_sample = sample_freq; |
| 1594 | core_cfg.n = n; |
| 1595 | core_cfg.cts = cts; |
| 1596 | if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) { |
| 1597 | core_cfg.aud_par_busclk = 0; |
| 1598 | core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW; |
| 1599 | core_cfg.use_mclk = false; |
| 1600 | } else { |
| 1601 | core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8); |
| 1602 | core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW; |
| 1603 | core_cfg.use_mclk = true; |
| 1604 | core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS; |
| 1605 | } |
| 1606 | core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH; |
| 1607 | core_cfg.en_spdif = false; |
| 1608 | /* Use sample frequency from channel status word */ |
| 1609 | core_cfg.fs_override = true; |
| 1610 | /* Enable ACR packets */ |
| 1611 | core_cfg.en_acr_pkt = true; |
| 1612 | /* Disable direct streaming digital audio */ |
| 1613 | core_cfg.en_dsd_audio = false; |
| 1614 | /* Use parallel audio interface */ |
| 1615 | core_cfg.en_parallel_aud_input = true; |
| 1616 | |
| 1617 | hdmi_core_audio_config(&core_cfg); |
| 1618 | |
| 1619 | /* |
| 1620 | * Configure packet |
| 1621 | * info frame audio see doc CEA861-D page 74 |
| 1622 | */ |
| 1623 | aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM; |
| 1624 | aud_if_cfg.db1_channel_count = 2; |
| 1625 | aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM; |
| 1626 | aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM; |
| 1627 | aud_if_cfg.db4_channel_alloc = 0x00; |
| 1628 | aud_if_cfg.db5_downmix_inh = false; |
| 1629 | aud_if_cfg.db5_lsv = 0; |
| 1630 | |
| 1631 | hdmi_core_audio_infoframe_config(&aud_if_cfg); |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd, |
| 1636 | struct snd_soc_dai *dai) |
| 1637 | { |
| 1638 | int err = 0; |
| 1639 | switch (cmd) { |
| 1640 | case SNDRV_PCM_TRIGGER_START: |
| 1641 | case SNDRV_PCM_TRIGGER_RESUME: |
| 1642 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1643 | REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 1, 0, 0); |
| 1644 | REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 31, 31); |
| 1645 | REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 30, 30); |
| 1646 | break; |
| 1647 | |
| 1648 | case SNDRV_PCM_TRIGGER_STOP: |
| 1649 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 1650 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1651 | REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 0, 0, 0); |
| 1652 | REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 30, 30); |
| 1653 | REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 31, 31); |
| 1654 | break; |
| 1655 | default: |
| 1656 | err = -EINVAL; |
| 1657 | } |
| 1658 | return err; |
| 1659 | } |
| 1660 | |
| 1661 | static int hdmi_audio_startup(struct snd_pcm_substream *substream, |
| 1662 | struct snd_soc_dai *dai) |
| 1663 | { |
| 1664 | if (!hdmi.mode) { |
| 1665 | pr_err("Current video settings do not support audio.\n"); |
| 1666 | return -EIO; |
| 1667 | } |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | static struct snd_soc_codec_driver hdmi_audio_codec_drv = { |
| 1672 | }; |
| 1673 | |
| 1674 | static struct snd_soc_dai_ops hdmi_audio_codec_ops = { |
| 1675 | .hw_params = hdmi_audio_hw_params, |
| 1676 | .trigger = hdmi_audio_trigger, |
| 1677 | .startup = hdmi_audio_startup, |
| 1678 | }; |
| 1679 | |
| 1680 | static struct snd_soc_dai_driver hdmi_codec_dai_drv = { |
| 1681 | .name = "hdmi-audio-codec", |
| 1682 | .playback = { |
| 1683 | .channels_min = 2, |
| 1684 | .channels_max = 2, |
| 1685 | .rates = SNDRV_PCM_RATE_32000 | |
| 1686 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, |
| 1687 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 1688 | SNDRV_PCM_FMTBIT_S24_LE, |
| 1689 | }, |
| 1690 | .ops = &hdmi_audio_codec_ops, |
| 1691 | }; |
Ricardo Neri | 82335c4 | 2011-04-05 16:05:18 -0500 | [diff] [blame] | 1692 | #endif |
| 1693 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1694 | static int hdmi_get_clocks(struct platform_device *pdev) |
| 1695 | { |
| 1696 | struct clk *clk; |
| 1697 | |
| 1698 | clk = clk_get(&pdev->dev, "sys_clk"); |
| 1699 | if (IS_ERR(clk)) { |
| 1700 | DSSERR("can't get sys_clk\n"); |
| 1701 | return PTR_ERR(clk); |
| 1702 | } |
| 1703 | |
| 1704 | hdmi.sys_clk = clk; |
| 1705 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | static void hdmi_put_clocks(void) |
| 1710 | { |
| 1711 | if (hdmi.sys_clk) |
| 1712 | clk_put(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1713 | } |
| 1714 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1715 | /* HDMI HW IP initialisation */ |
| 1716 | static int omapdss_hdmihw_probe(struct platform_device *pdev) |
| 1717 | { |
| 1718 | struct resource *hdmi_mem; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1719 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1720 | |
| 1721 | hdmi.pdata = pdev->dev.platform_data; |
| 1722 | hdmi.pdev = pdev; |
| 1723 | |
| 1724 | mutex_init(&hdmi.lock); |
| 1725 | |
| 1726 | hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0); |
| 1727 | if (!hdmi_mem) { |
| 1728 | DSSERR("can't get IORESOURCE_MEM HDMI\n"); |
| 1729 | return -EINVAL; |
| 1730 | } |
| 1731 | |
| 1732 | /* Base address taken from platform */ |
| 1733 | hdmi.base_wp = ioremap(hdmi_mem->start, resource_size(hdmi_mem)); |
| 1734 | if (!hdmi.base_wp) { |
| 1735 | DSSERR("can't ioremap WP\n"); |
| 1736 | return -ENOMEM; |
| 1737 | } |
| 1738 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1739 | r = hdmi_get_clocks(pdev); |
| 1740 | if (r) { |
| 1741 | iounmap(hdmi.base_wp); |
| 1742 | return r; |
| 1743 | } |
| 1744 | |
| 1745 | pm_runtime_enable(&pdev->dev); |
| 1746 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1747 | hdmi_panel_init(); |
| 1748 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1749 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 1750 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 1751 | |
| 1752 | /* Register ASoC codec DAI */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1753 | r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv, |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1754 | &hdmi_codec_dai_drv, 1); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1755 | if (r) { |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1756 | DSSERR("can't register ASoC HDMI audio codec\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1757 | return r; |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1758 | } |
| 1759 | #endif |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | static int omapdss_hdmihw_remove(struct platform_device *pdev) |
| 1764 | { |
| 1765 | hdmi_panel_exit(); |
| 1766 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 1767 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 1768 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 1769 | snd_soc_unregister_codec(&pdev->dev); |
| 1770 | #endif |
| 1771 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1772 | pm_runtime_disable(&pdev->dev); |
| 1773 | |
| 1774 | hdmi_put_clocks(); |
| 1775 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1776 | iounmap(hdmi.base_wp); |
| 1777 | |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1781 | static int hdmi_runtime_suspend(struct device *dev) |
| 1782 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1783 | clk_disable(hdmi.sys_clk); |
| 1784 | |
| 1785 | dispc_runtime_put(); |
| 1786 | dss_runtime_put(); |
| 1787 | |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | static int hdmi_runtime_resume(struct device *dev) |
| 1792 | { |
| 1793 | int r; |
| 1794 | |
| 1795 | r = dss_runtime_get(); |
| 1796 | if (r < 0) |
| 1797 | goto err_get_dss; |
| 1798 | |
| 1799 | r = dispc_runtime_get(); |
| 1800 | if (r < 0) |
| 1801 | goto err_get_dispc; |
| 1802 | |
| 1803 | |
| 1804 | clk_enable(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1805 | |
| 1806 | return 0; |
| 1807 | |
| 1808 | err_get_dispc: |
| 1809 | dss_runtime_put(); |
| 1810 | err_get_dss: |
| 1811 | return r; |
| 1812 | } |
| 1813 | |
| 1814 | static const struct dev_pm_ops hdmi_pm_ops = { |
| 1815 | .runtime_suspend = hdmi_runtime_suspend, |
| 1816 | .runtime_resume = hdmi_runtime_resume, |
| 1817 | }; |
| 1818 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1819 | static struct platform_driver omapdss_hdmihw_driver = { |
| 1820 | .probe = omapdss_hdmihw_probe, |
| 1821 | .remove = omapdss_hdmihw_remove, |
| 1822 | .driver = { |
| 1823 | .name = "omapdss_hdmi", |
| 1824 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1825 | .pm = &hdmi_pm_ops, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1826 | }, |
| 1827 | }; |
| 1828 | |
| 1829 | int hdmi_init_platform_driver(void) |
| 1830 | { |
| 1831 | return platform_driver_register(&omapdss_hdmihw_driver); |
| 1832 | } |
| 1833 | |
| 1834 | void hdmi_uninit_platform_driver(void) |
| 1835 | { |
| 1836 | return platform_driver_unregister(&omapdss_hdmihw_driver); |
| 1837 | } |