blob: bf76c87024b263b8c6bb1d69bce5f78231990f15 [file] [log] [blame]
Mythri P Kc3198a52011-03-12 12:04:27 +05301/*
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 Valkeinen24e62892011-05-23 11:51:18 +030032#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030033#include <linux/pm_runtime.h>
34#include <linux/clk.h>
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030035#include <video/omapdss.h>
Ricardo Neriad44cc32011-05-18 22:31:56 -050036#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 Kc3198a52011-03-12 12:04:27 +053041
Mythri P K94c52982011-09-08 19:06:21 +053042#include "ti_hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053043#include "dss.h"
44#include "hdmi.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050045#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053046
Mythri P K95a8aeb2011-09-08 19:06:18 +053047#define HDMI_WP 0x0
48#define HDMI_CORE_SYS 0x400
49#define HDMI_CORE_AV 0x900
50#define HDMI_PLLCTRL 0x200
51#define HDMI_PHY 0x300
52
Mythri P Kc3198a52011-03-12 12:04:27 +053053static struct {
54 struct mutex lock;
55 struct omap_display_platform_data *pdata;
56 struct platform_device *pdev;
Mythri P K95a8aeb2011-09-08 19:06:18 +053057 struct hdmi_ip_data ip_data;
Mythri P Kc3198a52011-03-12 12:04:27 +053058 int code;
59 int mode;
60 u8 edid[HDMI_EDID_MAX_LENGTH];
61 u8 edid_set;
62 bool custom_set;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030063
64 struct clk *sys_clk;
Mythri P Kc3198a52011-03-12 12:04:27 +053065} hdmi;
66
67/*
68 * Logic for the below structure :
69 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
70 * There is a correspondence between CEA/VESA timing and code, please
71 * refer to section 6.3 in HDMI 1.3 specification for timing code.
72 *
73 * In the below structure, cea_vesa_timings corresponds to all OMAP4
74 * supported CEA and VESA timing values.code_cea corresponds to the CEA
75 * code, It is used to get the timing from cea_vesa_timing array.Similarly
76 * with code_vesa. Code_index is used for back mapping, that is once EDID
77 * is read from the TV, EDID is parsed to find the timing values and then
78 * map it to corresponding CEA or VESA index.
79 */
80
81static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
82 { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
83 { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
84 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
85 { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
86 { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
87 { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
88 { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
89 { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
90 { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
91 { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
92 { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
93 { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
94 { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
95 { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
96 { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
97 /* VESA From Here */
98 { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
99 { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
100 { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
101 { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
102 { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
103 { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
104 { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
105 { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
106 { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
107 { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
108 { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
109 { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
110 { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
111 { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
112 { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
113 { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
114 { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
115 { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
116 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
117};
118
119/*
120 * This is a static mapping array which maps the timing values
121 * with corresponding CEA / VESA code
122 */
123static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
124 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
125 /* <--15 CEA 17--> vesa*/
126 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
127 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
128};
129
130/*
131 * This is reverse static mapping which maps the CEA / VESA code
132 * to the corresponding timing values
133 */
134static const int code_cea[39] = {
135 -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
136 -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
137 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
138 11, 12, 14, -1, -1, 13, 13, 4, 4
139};
140
141static const int code_vesa[85] = {
142 -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
143 -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
144 -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
145 -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
146 -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
147 -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
148 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150 -1, 27, 28, -1, 33};
151
152static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
153
Mythri P K95a8aeb2011-09-08 19:06:18 +0530154static inline void hdmi_write_reg(void __iomem *base_addr,
155 const struct hdmi_reg idx, u32 val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530156{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530157 __raw_writel(val, base_addr + idx.idx);
Mythri P Kc3198a52011-03-12 12:04:27 +0530158}
159
Mythri P K95a8aeb2011-09-08 19:06:18 +0530160static inline u32 hdmi_read_reg(void __iomem *base_addr,
161 const struct hdmi_reg idx)
Mythri P Kc3198a52011-03-12 12:04:27 +0530162{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530163 return __raw_readl(base_addr + idx.idx);
Mythri P Kc3198a52011-03-12 12:04:27 +0530164}
165
Mythri P K95a8aeb2011-09-08 19:06:18 +0530166static inline void __iomem *hdmi_wp_base(struct hdmi_ip_data *ip_data)
167{
168 return ip_data->base_wp;
169}
170
171static inline void __iomem *hdmi_phy_base(struct hdmi_ip_data *ip_data)
172{
173 return ip_data->base_wp + ip_data->phy_offset;
174}
175
176static inline void __iomem *hdmi_pll_base(struct hdmi_ip_data *ip_data)
177{
178 return ip_data->base_wp + ip_data->pll_offset;
179}
180
181static inline void __iomem *hdmi_av_base(struct hdmi_ip_data *ip_data)
182{
183 return ip_data->base_wp + ip_data->core_av_offset;
184}
185
186static inline void __iomem *hdmi_core_sys_base(struct hdmi_ip_data *ip_data)
187{
188 return ip_data->base_wp + ip_data->core_sys_offset;
189}
190
191static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
192 const struct hdmi_reg idx,
Mythri P Kc3198a52011-03-12 12:04:27 +0530193 int b2, int b1, u32 val)
194{
195 u32 t = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530196 while (val != REG_GET(base_addr, idx, b2, b1)) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530197 udelay(1);
198 if (t++ > 10000)
199 return !val;
200 }
201 return val;
202}
203
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300204static int hdmi_runtime_get(void)
205{
206 int r;
207
208 DSSDBG("hdmi_runtime_get\n");
209
210 r = pm_runtime_get_sync(&hdmi.pdev->dev);
211 WARN_ON(r < 0);
212 return r < 0 ? r : 0;
213}
214
215static void hdmi_runtime_put(void)
216{
217 int r;
218
219 DSSDBG("hdmi_runtime_put\n");
220
221 r = pm_runtime_put(&hdmi.pdev->dev);
222 WARN_ON(r < 0);
223}
224
Mythri P Kc3198a52011-03-12 12:04:27 +0530225int hdmi_init_display(struct omap_dss_device *dssdev)
226{
227 DSSDBG("init_display\n");
228
229 return 0;
230}
231
Mythri P K7b27da52011-09-08 19:06:19 +0530232static int hdmi_pll_init(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530233{
234 u32 r;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530235 void __iomem *pll_base = hdmi_pll_base(ip_data);
Mythri P K7b27da52011-09-08 19:06:19 +0530236 struct hdmi_pll_info *fmt = &ip_data->pll_data;
Mythri P Kc3198a52011-03-12 12:04:27 +0530237
238 /* PLL start always use manual mode */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530239 REG_FLD_MOD(pll_base, PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530240
Mythri P K95a8aeb2011-09-08 19:06:18 +0530241 r = hdmi_read_reg(pll_base, PLLCTRL_CFG1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530242 r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
243 r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */
244
Mythri P K95a8aeb2011-09-08 19:06:18 +0530245 hdmi_write_reg(pll_base, PLLCTRL_CFG1, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530246
Mythri P K95a8aeb2011-09-08 19:06:18 +0530247 r = hdmi_read_reg(pll_base, PLLCTRL_CFG2);
Mythri P Kc3198a52011-03-12 12:04:27 +0530248
249 r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
250 r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
251 r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
Mythri P K7b27da52011-09-08 19:06:19 +0530252 r = FLD_MOD(r, fmt->refsel, 22, 21); /* REFSEL */
Mythri P Kc3198a52011-03-12 12:04:27 +0530253
Mythri P K7b27da52011-09-08 19:06:19 +0530254 if (fmt->dcofreq) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530255 /* divider programming for frequency beyond 1000Mhz */
Mythri P K7b27da52011-09-08 19:06:19 +0530256 REG_FLD_MOD(pll_base, PLLCTRL_CFG3, fmt->regsd, 17, 10);
Mythri P Kc3198a52011-03-12 12:04:27 +0530257 r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
258 } else {
259 r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
260 }
261
Mythri P K95a8aeb2011-09-08 19:06:18 +0530262 hdmi_write_reg(pll_base, PLLCTRL_CFG2, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530263
Mythri P K95a8aeb2011-09-08 19:06:18 +0530264 r = hdmi_read_reg(pll_base, PLLCTRL_CFG4);
Mythri P Kc3198a52011-03-12 12:04:27 +0530265 r = FLD_MOD(r, fmt->regm2, 24, 18);
266 r = FLD_MOD(r, fmt->regmf, 17, 0);
267
Mythri P K95a8aeb2011-09-08 19:06:18 +0530268 hdmi_write_reg(pll_base, PLLCTRL_CFG4, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530269
270 /* go now */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530271 REG_FLD_MOD(pll_base, PLLCTRL_PLL_GO, 0x1, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530272
273 /* wait for bit change */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530274 if (hdmi_wait_for_bit_change(pll_base, PLLCTRL_PLL_GO,
275 0, 0, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530276 DSSERR("PLL GO bit not set\n");
277 return -ETIMEDOUT;
278 }
279
280 /* Wait till the lock bit is set in PLL status */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530281 if (hdmi_wait_for_bit_change(pll_base,
282 PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530283 DSSWARN("cannot lock PLL\n");
284 DSSWARN("CFG1 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530285 hdmi_read_reg(pll_base, PLLCTRL_CFG1));
Mythri P Kc3198a52011-03-12 12:04:27 +0530286 DSSWARN("CFG2 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530287 hdmi_read_reg(pll_base, PLLCTRL_CFG2));
Mythri P Kc3198a52011-03-12 12:04:27 +0530288 DSSWARN("CFG4 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530289 hdmi_read_reg(pll_base, PLLCTRL_CFG4));
Mythri P Kc3198a52011-03-12 12:04:27 +0530290 return -ETIMEDOUT;
291 }
292
293 DSSDBG("PLL locked!\n");
294
295 return 0;
296}
297
298/* PHY_PWR_CMD */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530299static int hdmi_set_phy_pwr(struct hdmi_ip_data *ip_data, enum hdmi_phy_pwr val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530300{
301 /* Command for power control of HDMI PHY */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530302 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 7, 6);
Mythri P Kc3198a52011-03-12 12:04:27 +0530303
304 /* Status of the power control of HDMI PHY */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530305 if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data),
306 HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530307 DSSERR("Failed to set PHY power mode to %d\n", val);
308 return -ETIMEDOUT;
309 }
310
311 return 0;
312}
313
314/* PLL_PWR_CMD */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530315int hdmi_set_pll_pwr(struct hdmi_ip_data *ip_data, enum hdmi_pll_pwr val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530316{
317 /* Command for power control of HDMI PLL */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530318 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 3, 2);
Mythri P Kc3198a52011-03-12 12:04:27 +0530319
320 /* wait till PHY_PWR_STATUS is set */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530321 if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL,
322 1, 0, val) != val) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530323 DSSERR("Failed to set PHY_PWR_STATUS\n");
324 return -ETIMEDOUT;
325 }
326
327 return 0;
328}
329
Mythri P K95a8aeb2011-09-08 19:06:18 +0530330static int hdmi_pll_reset(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530331{
332 /* SYSRESET controlled by power FSM */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530333 REG_FLD_MOD(hdmi_pll_base(ip_data), PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
Mythri P Kc3198a52011-03-12 12:04:27 +0530334
335 /* READ 0x0 reset is in progress */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530336 if (hdmi_wait_for_bit_change(hdmi_pll_base(ip_data),
337 PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530338 DSSERR("Failed to sysreset PLL\n");
339 return -ETIMEDOUT;
340 }
341
342 return 0;
343}
344
Mythri P K95a8aeb2011-09-08 19:06:18 +0530345static int hdmi_phy_init(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530346{
347 u16 r = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530348 void __iomem *phy_base = hdmi_phy_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530349
Mythri P K95a8aeb2011-09-08 19:06:18 +0530350 r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
Mythri P Kc3198a52011-03-12 12:04:27 +0530351 if (r)
352 return r;
353
Mythri P K95a8aeb2011-09-08 19:06:18 +0530354 r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
Mythri P Kc3198a52011-03-12 12:04:27 +0530355 if (r)
356 return r;
357
358 /*
359 * Read address 0 in order to get the SCP reset done completed
360 * Dummy access performed to make sure reset is done
361 */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530362 hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
Mythri P Kc3198a52011-03-12 12:04:27 +0530363
364 /*
365 * Write to phy address 0 to configure the clock
366 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
367 */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530368 REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
Mythri P Kc3198a52011-03-12 12:04:27 +0530369
370 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530371 hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
Mythri P Kc3198a52011-03-12 12:04:27 +0530372
373 /* Setup max LDO voltage */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530374 REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530375
376 /* Write to phy address 3 to change the polarity control */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530377 REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
Mythri P Kc3198a52011-03-12 12:04:27 +0530378
379 return 0;
380}
381
Mythri P K7b27da52011-09-08 19:06:19 +0530382static int hdmi_pll_program(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530383{
384 u16 r = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530385
Mythri P K95a8aeb2011-09-08 19:06:18 +0530386 r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
Mythri P Kc3198a52011-03-12 12:04:27 +0530387 if (r)
388 return r;
389
Mythri P K95a8aeb2011-09-08 19:06:18 +0530390 r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
Mythri P Kc3198a52011-03-12 12:04:27 +0530391 if (r)
392 return r;
393
Mythri P K95a8aeb2011-09-08 19:06:18 +0530394 r = hdmi_pll_reset(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530395 if (r)
396 return r;
397
Mythri P K7b27da52011-09-08 19:06:19 +0530398 r = hdmi_pll_init(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530399 if (r)
400 return r;
401
402 return 0;
403}
404
Mythri P K95a8aeb2011-09-08 19:06:18 +0530405static void hdmi_phy_off(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530406{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530407 hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
Mythri P Kc3198a52011-03-12 12:04:27 +0530408}
409
Mythri P K95a8aeb2011-09-08 19:06:18 +0530410static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
411 u8 *pedid, int ext)
Mythri P Kc3198a52011-03-12 12:04:27 +0530412{
413 u32 i, j;
414 char checksum = 0;
415 u32 offset = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530416 void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530417
418 /* Turn on CLK for DDC */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530419 REG_FLD_MOD(hdmi_av_base(ip_data), HDMI_CORE_AV_DPD, 0x7, 2, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530420
421 /*
422 * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
423 * right shifted values( The behavior is not consistent and seen only
424 * with some TV's)
425 */
426 usleep_range(800, 1000);
427
428 if (!ext) {
429 /* Clk SCL Devices */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530430 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530431
432 /* HDMI_CORE_DDC_STATUS_IN_PROG */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530433 if (hdmi_wait_for_bit_change(core_sys_base,
434 HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530435 DSSERR("Failed to program DDC\n");
436 return -ETIMEDOUT;
437 }
438
439 /* Clear FIFO */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530440 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530441
442 /* HDMI_CORE_DDC_STATUS_IN_PROG */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530443 if (hdmi_wait_for_bit_change(core_sys_base,
444 HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530445 DSSERR("Failed to program DDC\n");
446 return -ETIMEDOUT;
447 }
448
449 } else {
450 if (ext % 2 != 0)
451 offset = 0x80;
452 }
453
454 /* Load Segment Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530455 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530456
457 /* Load Slave Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530458 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530459
460 /* Load Offset Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530461 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530462
463 /* Load Byte Count */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530464 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
465 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530466
467 /* Set DDC_CMD */
468 if (ext)
Mythri P K95a8aeb2011-09-08 19:06:18 +0530469 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530470 else
Mythri P K95a8aeb2011-09-08 19:06:18 +0530471 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530472
473 /* HDMI_CORE_DDC_STATUS_BUS_LOW */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530474 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530475 DSSWARN("I2C Bus Low?\n");
476 return -EIO;
477 }
478 /* HDMI_CORE_DDC_STATUS_NO_ACK */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530479 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530480 DSSWARN("I2C No Ack\n");
481 return -EIO;
482 }
483
484 i = ext * 128;
485 j = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530486 while (((REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
487 (REG_GET(core_sys_base,
488 HDMI_CORE_DDC_STATUS, 2, 2) == 0)) && j < 128) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530489
Mythri P K95a8aeb2011-09-08 19:06:18 +0530490 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530491 /* FIFO not empty */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530492 pedid[i++] = REG_GET(core_sys_base,
493 HDMI_CORE_DDC_DATA, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530494 j++;
495 }
496 }
497
498 for (j = 0; j < 128; j++)
499 checksum += pedid[j];
500
501 if (checksum != 0) {
502 DSSERR("E-EDID checksum failed!!\n");
503 return -EIO;
504 }
505
506 return 0;
507}
508
Mythri P K95a8aeb2011-09-08 19:06:18 +0530509static int read_edid(struct hdmi_ip_data *ip_data, u8 *pedid, u16 max_length)
Mythri P Kc3198a52011-03-12 12:04:27 +0530510{
511 int r = 0, n = 0, i = 0;
512 int max_ext_blocks = (max_length / 128) - 1;
513
Mythri P K95a8aeb2011-09-08 19:06:18 +0530514 r = hdmi_core_ddc_edid(ip_data, pedid, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530515 if (r) {
516 return r;
517 } else {
518 n = pedid[0x7e];
519
520 /*
521 * README: need to comply with max_length set by the caller.
522 * Better implementation should be to allocate necessary
523 * memory to store EDID according to nb_block field found
524 * in first block
525 */
526 if (n > max_ext_blocks)
527 n = max_ext_blocks;
528
529 for (i = 1; i <= n; i++) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530530 r = hdmi_core_ddc_edid(ip_data, pedid, i);
Mythri P Kc3198a52011-03-12 12:04:27 +0530531 if (r)
532 return r;
533 }
534 }
535 return 0;
536}
537
Mythri P K38863b72011-09-08 19:06:20 +0530538static void copy_hdmi_to_dss_timings(
539 const struct hdmi_video_timings *hdmi_timings,
540 struct omap_video_timings *timings)
541{
542 timings->x_res = hdmi_timings->x_res;
543 timings->y_res = hdmi_timings->y_res;
544 timings->pixel_clock = hdmi_timings->pixel_clock;
545 timings->hbp = hdmi_timings->hbp;
546 timings->hfp = hdmi_timings->hfp;
547 timings->hsw = hdmi_timings->hsw;
548 timings->vbp = hdmi_timings->vbp;
549 timings->vfp = hdmi_timings->vfp;
550 timings->vsw = hdmi_timings->vsw;
551}
552
Mythri P Kc3198a52011-03-12 12:04:27 +0530553static int get_timings_index(void)
554{
555 int code;
556
557 if (hdmi.mode == 0)
558 code = code_vesa[hdmi.code];
559 else
560 code = code_cea[hdmi.code];
561
562 if (code == -1) {
563 /* HDMI code 4 corresponds to 640 * 480 VGA */
564 hdmi.code = 4;
565 /* DVI mode 1 corresponds to HDMI 0 to DVI */
566 hdmi.mode = HDMI_DVI;
567
568 code = code_vesa[hdmi.code];
569 }
570 return code;
571}
572
573static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
574{
575 int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
576 int timing_vsync = 0, timing_hsync = 0;
Mythri P K38863b72011-09-08 19:06:20 +0530577 struct hdmi_video_timings temp;
Mythri P Kc3198a52011-03-12 12:04:27 +0530578 struct hdmi_cm cm = {-1};
579 DSSDBG("hdmi_get_code\n");
580
581 for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
582 temp = cea_vesa_timings[i].timings;
583 if ((temp.pixel_clock == timing->pixel_clock) &&
584 (temp.x_res == timing->x_res) &&
585 (temp.y_res == timing->y_res)) {
586
587 temp_hsync = temp.hfp + temp.hsw + temp.hbp;
588 timing_hsync = timing->hfp + timing->hsw + timing->hbp;
589 temp_vsync = temp.vfp + temp.vsw + temp.vbp;
590 timing_vsync = timing->vfp + timing->vsw + timing->vbp;
591
592 DSSDBG("temp_hsync = %d , temp_vsync = %d"
593 "timing_hsync = %d, timing_vsync = %d\n",
594 temp_hsync, temp_hsync,
595 timing_hsync, timing_vsync);
596
597 if ((temp_hsync == timing_hsync) &&
598 (temp_vsync == timing_vsync)) {
599 code = i;
600 cm.code = code_index[i];
601 if (code < 14)
602 cm.mode = HDMI_HDMI;
603 else
604 cm.mode = HDMI_DVI;
605 DSSDBG("Hdmi_code = %d mode = %d\n",
606 cm.code, cm.mode);
607 break;
608 }
609 }
610 }
611
612 return cm;
613}
614
615static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
616 struct omap_video_timings *timings)
617{
618 /* X and Y resolution */
619 timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
620 edid[current_descriptor_addrs + 2]);
621 timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
622 edid[current_descriptor_addrs + 5]);
623
624 timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
625 edid[current_descriptor_addrs]);
626
627 timings->pixel_clock = 10 * timings->pixel_clock;
628
629 /* HORIZONTAL FRONT PORCH */
630 timings->hfp = edid[current_descriptor_addrs + 8] |
631 ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
632 /* HORIZONTAL SYNC WIDTH */
633 timings->hsw = edid[current_descriptor_addrs + 9] |
634 ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
635 /* HORIZONTAL BACK PORCH */
636 timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
637 edid[current_descriptor_addrs + 3]) -
638 (timings->hfp + timings->hsw);
639 /* VERTICAL FRONT PORCH */
640 timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
641 ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
642 /* VERTICAL SYNC WIDTH */
643 timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
644 ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
645 /* VERTICAL BACK PORCH */
646 timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
647 edid[current_descriptor_addrs + 6]) -
648 (timings->vfp + timings->vsw);
649
650}
651
652/* Description : This function gets the resolution information from EDID */
653static void get_edid_timing_data(u8 *edid)
654{
655 u8 count;
656 u16 current_descriptor_addrs;
657 struct hdmi_cm cm;
658 struct omap_video_timings edid_timings;
659
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300660 /* search block 0, there are 4 DTDs arranged in priority order */
Mythri P Kc3198a52011-03-12 12:04:27 +0530661 for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
662 current_descriptor_addrs =
663 EDID_DESCRIPTOR_BLOCK0_ADDRESS +
664 count * EDID_TIMING_DESCRIPTOR_SIZE;
665 get_horz_vert_timing_info(current_descriptor_addrs,
666 edid, &edid_timings);
667 cm = hdmi_get_code(&edid_timings);
668 DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
669 count, cm.code, cm.mode);
670 if (cm.code == -1) {
671 continue;
672 } else {
673 hdmi.code = cm.code;
674 hdmi.mode = cm.mode;
675 DSSDBG("code = %d , mode = %d\n",
676 hdmi.code, hdmi.mode);
677 return;
678 }
679 }
680 if (edid[0x7e] != 0x00) {
681 for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
682 count++) {
683 current_descriptor_addrs =
684 EDID_DESCRIPTOR_BLOCK1_ADDRESS +
685 count * EDID_TIMING_DESCRIPTOR_SIZE;
686 get_horz_vert_timing_info(current_descriptor_addrs,
687 edid, &edid_timings);
688 cm = hdmi_get_code(&edid_timings);
689 DSSDBG("Block1[%d] value matches code = %d, mode = %d",
690 count, cm.code, cm.mode);
691 if (cm.code == -1) {
692 continue;
693 } else {
694 hdmi.code = cm.code;
695 hdmi.mode = cm.mode;
696 DSSDBG("code = %d , mode = %d\n",
697 hdmi.code, hdmi.mode);
698 return;
699 }
700 }
701 }
702
703 DSSINFO("no valid timing found , falling back to VGA\n");
704 hdmi.code = 4; /* setting default value of 640 480 VGA */
705 hdmi.mode = HDMI_DVI;
706}
707
708static void hdmi_read_edid(struct omap_video_timings *dp)
709{
710 int ret = 0, code;
711
712 memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
713
714 if (!hdmi.edid_set)
Mythri P K95a8aeb2011-09-08 19:06:18 +0530715 ret = read_edid(&hdmi.ip_data, hdmi.edid,
716 HDMI_EDID_MAX_LENGTH);
Mythri P Kc3198a52011-03-12 12:04:27 +0530717 if (!ret) {
718 if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
719 /* search for timings of default resolution */
720 get_edid_timing_data(hdmi.edid);
721 hdmi.edid_set = true;
722 }
723 } else {
724 DSSWARN("failed to read E-EDID\n");
725 }
726
727 if (!hdmi.edid_set) {
728 DSSINFO("fallback to VGA\n");
729 hdmi.code = 4; /* setting default value of 640 480 VGA */
730 hdmi.mode = HDMI_DVI;
731 }
732
733 code = get_timings_index();
734
Mythri P K38863b72011-09-08 19:06:20 +0530735 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings, dp);
736
Mythri P Kc3198a52011-03-12 12:04:27 +0530737}
738
739static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
740 struct hdmi_core_infoframe_avi *avi_cfg,
741 struct hdmi_core_packet_enable_repeat *repeat_cfg)
742{
743 DSSDBG("Enter hdmi_core_init\n");
744
745 /* video core */
746 video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
747 video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
748 video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
749 video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
750 video_cfg->hdmi_dvi = HDMI_DVI;
751 video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
752
753 /* info frame */
754 avi_cfg->db1_format = 0;
755 avi_cfg->db1_active_info = 0;
756 avi_cfg->db1_bar_info_dv = 0;
757 avi_cfg->db1_scan_info = 0;
758 avi_cfg->db2_colorimetry = 0;
759 avi_cfg->db2_aspect_ratio = 0;
760 avi_cfg->db2_active_fmt_ar = 0;
761 avi_cfg->db3_itc = 0;
762 avi_cfg->db3_ec = 0;
763 avi_cfg->db3_q_range = 0;
764 avi_cfg->db3_nup_scaling = 0;
765 avi_cfg->db4_videocode = 0;
766 avi_cfg->db5_pixel_repeat = 0;
767 avi_cfg->db6_7_line_eoftop = 0 ;
768 avi_cfg->db8_9_line_sofbottom = 0;
769 avi_cfg->db10_11_pixel_eofleft = 0;
770 avi_cfg->db12_13_pixel_sofright = 0;
771
772 /* packet enable and repeat */
773 repeat_cfg->audio_pkt = 0;
774 repeat_cfg->audio_pkt_repeat = 0;
775 repeat_cfg->avi_infoframe = 0;
776 repeat_cfg->avi_infoframe_repeat = 0;
777 repeat_cfg->gen_cntrl_pkt = 0;
778 repeat_cfg->gen_cntrl_pkt_repeat = 0;
779 repeat_cfg->generic_pkt = 0;
780 repeat_cfg->generic_pkt_repeat = 0;
781}
782
Mythri P K95a8aeb2011-09-08 19:06:18 +0530783static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530784{
785 DSSDBG("Enter hdmi_core_powerdown_disable\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530786 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530787}
788
Mythri P K95a8aeb2011-09-08 19:06:18 +0530789static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530790{
791 DSSDBG("Enter hdmi_core_swreset_release\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530792 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530793}
794
Mythri P K95a8aeb2011-09-08 19:06:18 +0530795static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530796{
797 DSSDBG("Enter hdmi_core_swreset_assert\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530798 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530799}
800
Mythri P K95a8aeb2011-09-08 19:06:18 +0530801/* HDMI_CORE_VIDEO_CONFIG */
802static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
803 struct hdmi_core_video_config *cfg)
Mythri P Kc3198a52011-03-12 12:04:27 +0530804{
805 u32 r = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530806 void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530807
808 /* sys_ctrl1 default configuration not tunable */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530809 r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530810 r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
811 r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
812 r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
813 r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530814 hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530815
Mythri P K95a8aeb2011-09-08 19:06:18 +0530816 REG_FLD_MOD(core_sys_base,
817 HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
Mythri P Kc3198a52011-03-12 12:04:27 +0530818
819 /* Vid_Mode */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530820 r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
Mythri P Kc3198a52011-03-12 12:04:27 +0530821
822 /* dither truncation configuration */
823 if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
824 r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
825 r = FLD_MOD(r, 1, 5, 5);
826 } else {
827 r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
828 r = FLD_MOD(r, 0, 5, 5);
829 }
Mythri P K95a8aeb2011-09-08 19:06:18 +0530830 hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530831
832 /* HDMI_Ctrl */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530833 r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
Mythri P Kc3198a52011-03-12 12:04:27 +0530834 r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
835 r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
836 r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530837 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530838
839 /* TMDS_CTRL */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530840 REG_FLD_MOD(core_sys_base,
841 HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
Mythri P Kc3198a52011-03-12 12:04:27 +0530842}
843
Mythri P K95a8aeb2011-09-08 19:06:18 +0530844static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530845 struct hdmi_core_infoframe_avi info_avi)
846{
847 u32 val;
848 char sum = 0, checksum = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530849 void __iomem *av_base = hdmi_av_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530850
851 sum += 0x82 + 0x002 + 0x00D;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530852 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
853 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
854 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
Mythri P Kc3198a52011-03-12 12:04:27 +0530855
856 val = (info_avi.db1_format << 5) |
857 (info_avi.db1_active_info << 4) |
858 (info_avi.db1_bar_info_dv << 2) |
859 (info_avi.db1_scan_info);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530860 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530861 sum += val;
862
863 val = (info_avi.db2_colorimetry << 6) |
864 (info_avi.db2_aspect_ratio << 4) |
865 (info_avi.db2_active_fmt_ar);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530866 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530867 sum += val;
868
869 val = (info_avi.db3_itc << 7) |
870 (info_avi.db3_ec << 4) |
871 (info_avi.db3_q_range << 2) |
872 (info_avi.db3_nup_scaling);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530873 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530874 sum += val;
875
Mythri P K95a8aeb2011-09-08 19:06:18 +0530876 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
877 info_avi.db4_videocode);
Mythri P Kc3198a52011-03-12 12:04:27 +0530878 sum += info_avi.db4_videocode;
879
880 val = info_avi.db5_pixel_repeat;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530881 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530882 sum += val;
883
884 val = info_avi.db6_7_line_eoftop & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530885 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530886 sum += val;
887
888 val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530889 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530890 sum += val;
891
892 val = info_avi.db8_9_line_sofbottom & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530893 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530894 sum += val;
895
896 val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530897 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530898 sum += val;
899
900 val = info_avi.db10_11_pixel_eofleft & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530901 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530902 sum += val;
903
904 val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530905 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530906 sum += val;
907
908 val = info_avi.db12_13_pixel_sofright & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530909 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530910 sum += val;
911
912 val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530913 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530914 sum += val;
915
916 checksum = 0x100 - sum;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530917 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
Mythri P Kc3198a52011-03-12 12:04:27 +0530918}
919
Mythri P K95a8aeb2011-09-08 19:06:18 +0530920static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530921 struct hdmi_core_packet_enable_repeat repeat_cfg)
922{
923 /* enable/repeat the infoframe */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530924 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
Mythri P Kc3198a52011-03-12 12:04:27 +0530925 (repeat_cfg.audio_pkt << 5) |
926 (repeat_cfg.audio_pkt_repeat << 4) |
927 (repeat_cfg.avi_infoframe << 1) |
928 (repeat_cfg.avi_infoframe_repeat));
929
930 /* enable/repeat the packet */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530931 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
Mythri P Kc3198a52011-03-12 12:04:27 +0530932 (repeat_cfg.gen_cntrl_pkt << 3) |
933 (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
934 (repeat_cfg.generic_pkt << 1) |
935 (repeat_cfg.generic_pkt_repeat));
936}
937
938static void hdmi_wp_init(struct omap_video_timings *timings,
939 struct hdmi_video_format *video_fmt,
940 struct hdmi_video_interface *video_int)
941{
942 DSSDBG("Enter hdmi_wp_init\n");
943
944 timings->hbp = 0;
945 timings->hfp = 0;
946 timings->hsw = 0;
947 timings->vbp = 0;
948 timings->vfp = 0;
949 timings->vsw = 0;
950
951 video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
952 video_fmt->y_res = 0;
953 video_fmt->x_res = 0;
954
955 video_int->vsp = 0;
956 video_int->hsp = 0;
957
958 video_int->interlacing = 0;
959 video_int->tm = 0; /* HDMI_TIMING_SLAVE */
960
961}
962
Mythri P K95a8aeb2011-09-08 19:06:18 +0530963static void hdmi_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
Mythri P Kc3198a52011-03-12 12:04:27 +0530964{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530965 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
Mythri P Kc3198a52011-03-12 12:04:27 +0530966}
967
968static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
969 struct omap_video_timings *timings, struct hdmi_config *param)
970{
971 DSSDBG("Enter hdmi_wp_video_init_format\n");
972
973 video_fmt->y_res = param->timings.timings.y_res;
974 video_fmt->x_res = param->timings.timings.x_res;
975
976 timings->hbp = param->timings.timings.hbp;
977 timings->hfp = param->timings.timings.hfp;
978 timings->hsw = param->timings.timings.hsw;
979 timings->vbp = param->timings.timings.vbp;
980 timings->vfp = param->timings.timings.vfp;
981 timings->vsw = param->timings.timings.vsw;
982}
983
Mythri P K95a8aeb2011-09-08 19:06:18 +0530984static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530985 struct hdmi_video_format *video_fmt)
986{
987 u32 l = 0;
988
Mythri P K95a8aeb2011-09-08 19:06:18 +0530989 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
990 video_fmt->packing_mode, 10, 8);
Mythri P Kc3198a52011-03-12 12:04:27 +0530991
992 l |= FLD_VAL(video_fmt->y_res, 31, 16);
993 l |= FLD_VAL(video_fmt->x_res, 15, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530994 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
Mythri P Kc3198a52011-03-12 12:04:27 +0530995}
996
Mythri P K95a8aeb2011-09-08 19:06:18 +0530997static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530998 struct hdmi_video_interface *video_int)
999{
1000 u32 r;
1001 DSSDBG("Enter hdmi_wp_video_config_interface\n");
1002
Mythri P K95a8aeb2011-09-08 19:06:18 +05301003 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
Mythri P Kc3198a52011-03-12 12:04:27 +05301004 r = FLD_MOD(r, video_int->vsp, 7, 7);
1005 r = FLD_MOD(r, video_int->hsp, 6, 6);
1006 r = FLD_MOD(r, video_int->interlacing, 3, 3);
1007 r = FLD_MOD(r, video_int->tm, 1, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301008 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
Mythri P Kc3198a52011-03-12 12:04:27 +05301009}
1010
Mythri P K95a8aeb2011-09-08 19:06:18 +05301011static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +05301012 struct omap_video_timings *timings)
1013{
1014 u32 timing_h = 0;
1015 u32 timing_v = 0;
1016
1017 DSSDBG("Enter hdmi_wp_video_config_timing\n");
1018
1019 timing_h |= FLD_VAL(timings->hbp, 31, 20);
1020 timing_h |= FLD_VAL(timings->hfp, 19, 8);
1021 timing_h |= FLD_VAL(timings->hsw, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301022 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
Mythri P Kc3198a52011-03-12 12:04:27 +05301023
1024 timing_v |= FLD_VAL(timings->vbp, 31, 20);
1025 timing_v |= FLD_VAL(timings->vfp, 19, 8);
1026 timing_v |= FLD_VAL(timings->vsw, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301027 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
Mythri P Kc3198a52011-03-12 12:04:27 +05301028}
1029
Mythri P K7b27da52011-09-08 19:06:19 +05301030static void hdmi_basic_configure(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +05301031{
1032 /* HDMI */
1033 struct omap_video_timings video_timing;
1034 struct hdmi_video_format video_format;
1035 struct hdmi_video_interface video_interface;
1036 /* HDMI core */
1037 struct hdmi_core_infoframe_avi avi_cfg;
1038 struct hdmi_core_video_config v_core_cfg;
1039 struct hdmi_core_packet_enable_repeat repeat_cfg;
Mythri P K7b27da52011-09-08 19:06:19 +05301040 struct hdmi_config *cfg = &ip_data->cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +05301041
1042 hdmi_wp_init(&video_timing, &video_format,
1043 &video_interface);
1044
1045 hdmi_core_init(&v_core_cfg,
1046 &avi_cfg,
1047 &repeat_cfg);
1048
Mythri P K7b27da52011-09-08 19:06:19 +05301049 hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301050
Mythri P K95a8aeb2011-09-08 19:06:18 +05301051 hdmi_wp_video_config_timing(ip_data, &video_timing);
Mythri P Kc3198a52011-03-12 12:04:27 +05301052
1053 /* video config */
1054 video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
1055
Mythri P K95a8aeb2011-09-08 19:06:18 +05301056 hdmi_wp_video_config_format(ip_data, &video_format);
Mythri P Kc3198a52011-03-12 12:04:27 +05301057
1058 video_interface.vsp = cfg->timings.vsync_pol;
1059 video_interface.hsp = cfg->timings.hsync_pol;
1060 video_interface.interlacing = cfg->interlace;
1061 video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
1062
Mythri P K95a8aeb2011-09-08 19:06:18 +05301063 hdmi_wp_video_config_interface(ip_data, &video_interface);
Mythri P Kc3198a52011-03-12 12:04:27 +05301064
1065 /*
1066 * configure core video part
1067 * set software reset in the core
1068 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301069 hdmi_core_swreset_assert(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301070
1071 /* power down off */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301072 hdmi_core_powerdown_disable(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301073
1074 v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
1075 v_core_cfg.hdmi_dvi = cfg->cm.mode;
1076
Mythri P K95a8aeb2011-09-08 19:06:18 +05301077 hdmi_core_video_config(ip_data, &v_core_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301078
1079 /* release software reset in the core */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301080 hdmi_core_swreset_release(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301081
1082 /*
1083 * configure packet
1084 * info frame video see doc CEA861-D page 65
1085 */
1086 avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
1087 avi_cfg.db1_active_info =
1088 HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
1089 avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
1090 avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
1091 avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
1092 avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
1093 avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
1094 avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
1095 avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
1096 avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
1097 avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
1098 avi_cfg.db4_videocode = cfg->cm.code;
1099 avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
1100 avi_cfg.db6_7_line_eoftop = 0;
1101 avi_cfg.db8_9_line_sofbottom = 0;
1102 avi_cfg.db10_11_pixel_eofleft = 0;
1103 avi_cfg.db12_13_pixel_sofright = 0;
1104
Mythri P K95a8aeb2011-09-08 19:06:18 +05301105 hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301106
1107 /* enable/repeat the infoframe */
1108 repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
1109 repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
1110 /* wakeup */
1111 repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
1112 repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301113 hdmi_core_av_packet_config(ip_data, repeat_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301114}
1115
1116static void update_hdmi_timings(struct hdmi_config *cfg,
1117 struct omap_video_timings *timings, int code)
1118{
1119 cfg->timings.timings.x_res = timings->x_res;
1120 cfg->timings.timings.y_res = timings->y_res;
1121 cfg->timings.timings.hbp = timings->hbp;
1122 cfg->timings.timings.hfp = timings->hfp;
1123 cfg->timings.timings.hsw = timings->hsw;
1124 cfg->timings.timings.vbp = timings->vbp;
1125 cfg->timings.timings.vfp = timings->vfp;
1126 cfg->timings.timings.vsw = timings->vsw;
1127 cfg->timings.timings.pixel_clock = timings->pixel_clock;
1128 cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
1129 cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
1130}
1131
Archit Taneja6cb07b22011-04-12 13:52:25 +05301132static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
1133 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +05301134{
Archit Taneja6cb07b22011-04-12 13:52:25 +05301135 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +05301136 u32 mf;
1137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001138 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +05301139 /*
1140 * Input clock is predivided by N + 1
1141 * out put of which is reference clk
1142 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301143 pi->regn = dssdev->clocks.hdmi.regn;
1144 refclk = clkin / (pi->regn + 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301145
1146 /*
1147 * multiplier is pixel_clk/ref_clk
1148 * Multiplying by 100 to avoid fractional part removal
1149 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301150 pi->regm = (phy * 100 / (refclk)) / 100;
1151 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +05301152
1153 /*
1154 * fractional multiplier is remainder of the difference between
1155 * multiplier and actual phy(required pixel clock thus should be
1156 * multiplied by 2^18(262144) divided by the reference clock
1157 */
1158 mf = (phy - pi->regm * refclk) * 262144;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301159 pi->regmf = mf / (refclk);
Mythri P Kc3198a52011-03-12 12:04:27 +05301160
1161 /*
1162 * Dcofreq should be set to 1 if required pixel clock
1163 * is greater than 1000MHz
1164 */
1165 pi->dcofreq = phy > 1000 * 100;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301166 pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +05301167
Mythri P K7b27da52011-09-08 19:06:19 +05301168 /* Set the reference clock to sysclk reference */
1169 pi->refsel = HDMI_REFSEL_SYSCLK;
1170
Mythri P Kc3198a52011-03-12 12:04:27 +05301171 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
1172 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
1173}
1174
Mythri P Kc3198a52011-03-12 12:04:27 +05301175static int hdmi_power_on(struct omap_dss_device *dssdev)
1176{
1177 int r, code = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +05301178 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301179 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +05301180
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001181 r = hdmi_runtime_get();
1182 if (r)
1183 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301184
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001185 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301186
1187 p = &dssdev->panel.timings;
1188
1189 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
1190 dssdev->panel.timings.x_res,
1191 dssdev->panel.timings.y_res);
1192
1193 if (!hdmi.custom_set) {
1194 DSSDBG("Read EDID as no EDID is not set on poweron\n");
1195 hdmi_read_edid(p);
1196 }
1197 code = get_timings_index();
Mythri P K38863b72011-09-08 19:06:20 +05301198 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings,
1199 &dssdev->panel.timings);
Mythri P K7b27da52011-09-08 19:06:19 +05301200 update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
Mythri P Kc3198a52011-03-12 12:04:27 +05301201
Mythri P Kc3198a52011-03-12 12:04:27 +05301202 phy = p->pixel_clock;
1203
Mythri P K7b27da52011-09-08 19:06:19 +05301204 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301205
Mythri P K95a8aeb2011-09-08 19:06:18 +05301206 hdmi_wp_video_start(&hdmi.ip_data, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301207
Mythri P K95a8aeb2011-09-08 19:06:18 +05301208 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K7b27da52011-09-08 19:06:19 +05301209 r = hdmi_pll_program(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301210 if (r) {
1211 DSSDBG("Failed to lock PLL\n");
1212 goto err;
1213 }
1214
Mythri P K95a8aeb2011-09-08 19:06:18 +05301215 r = hdmi_phy_init(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301216 if (r) {
1217 DSSDBG("Failed to start PHY\n");
1218 goto err;
1219 }
1220
Mythri P K7b27da52011-09-08 19:06:19 +05301221 hdmi.ip_data.cfg.cm.mode = hdmi.mode;
1222 hdmi.ip_data.cfg.cm.code = hdmi.code;
1223 hdmi_basic_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301224
1225 /* Make selection of HDMI in DSS */
1226 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
1227
1228 /* Select the dispc clock source as PRCM clock, to ensure that it is not
1229 * DSI PLL source as the clock selected by DSI PLL might not be
1230 * sufficient for the resolution selected / that can be changed
1231 * dynamically by user. This can be moved to single location , say
1232 * Boardfile.
1233 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301234 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +05301235
1236 /* bypass TV gamma table */
1237 dispc_enable_gamma_table(0);
1238
1239 /* tv size */
1240 dispc_set_digit_size(dssdev->panel.timings.x_res,
1241 dssdev->panel.timings.y_res);
1242
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001243 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301244
Mythri P K95a8aeb2011-09-08 19:06:18 +05301245 hdmi_wp_video_start(&hdmi.ip_data, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301246
1247 return 0;
1248err:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001249 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +05301250 return -EIO;
1251}
1252
1253static void hdmi_power_off(struct omap_dss_device *dssdev)
1254{
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001255 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301256
Mythri P K95a8aeb2011-09-08 19:06:18 +05301257 hdmi_wp_video_start(&hdmi.ip_data, 0);
1258 hdmi_phy_off(&hdmi.ip_data);
1259 hdmi_set_pll_pwr(&hdmi.ip_data, HDMI_PLLPWRCMD_ALLOFF);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001260 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +05301261
1262 hdmi.edid_set = 0;
1263}
1264
1265int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
1266 struct omap_video_timings *timings)
1267{
1268 struct hdmi_cm cm;
1269
1270 cm = hdmi_get_code(timings);
1271 if (cm.code == -1) {
1272 DSSERR("Invalid timing entered\n");
1273 return -EINVAL;
1274 }
1275
1276 return 0;
1277
1278}
1279
1280void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
1281{
1282 struct hdmi_cm cm;
1283
1284 hdmi.custom_set = 1;
1285 cm = hdmi_get_code(&dssdev->panel.timings);
1286 hdmi.code = cm.code;
1287 hdmi.mode = cm.mode;
1288 omapdss_hdmi_display_enable(dssdev);
1289 hdmi.custom_set = 0;
1290}
1291
1292int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
1293{
1294 int r = 0;
1295
1296 DSSDBG("ENTER hdmi_display_enable\n");
1297
1298 mutex_lock(&hdmi.lock);
1299
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03001300 if (dssdev->manager == NULL) {
1301 DSSERR("failed to enable display: no manager\n");
1302 r = -ENODEV;
1303 goto err0;
1304 }
1305
Mythri P Kc3198a52011-03-12 12:04:27 +05301306 r = omap_dss_start_device(dssdev);
1307 if (r) {
1308 DSSERR("failed to start device\n");
1309 goto err0;
1310 }
1311
1312 if (dssdev->platform_enable) {
1313 r = dssdev->platform_enable(dssdev);
1314 if (r) {
1315 DSSERR("failed to enable GPIO's\n");
1316 goto err1;
1317 }
1318 }
1319
1320 r = hdmi_power_on(dssdev);
1321 if (r) {
1322 DSSERR("failed to power on device\n");
1323 goto err2;
1324 }
1325
1326 mutex_unlock(&hdmi.lock);
1327 return 0;
1328
1329err2:
1330 if (dssdev->platform_disable)
1331 dssdev->platform_disable(dssdev);
1332err1:
1333 omap_dss_stop_device(dssdev);
1334err0:
1335 mutex_unlock(&hdmi.lock);
1336 return r;
1337}
1338
1339void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
1340{
1341 DSSDBG("Enter hdmi_display_disable\n");
1342
1343 mutex_lock(&hdmi.lock);
1344
1345 hdmi_power_off(dssdev);
1346
1347 if (dssdev->platform_disable)
1348 dssdev->platform_disable(dssdev);
1349
1350 omap_dss_stop_device(dssdev);
1351
1352 mutex_unlock(&hdmi.lock);
1353}
1354
Ricardo Neri82335c42011-04-05 16:05:18 -05001355#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1356 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
Mythri P K95a8aeb2011-09-08 19:06:18 +05301357static void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
1358 struct hdmi_audio_format *aud_fmt)
Ricardo Neri82335c42011-04-05 16:05:18 -05001359{
1360 u32 r;
1361
1362 DSSDBG("Enter hdmi_wp_audio_config_format\n");
1363
Mythri P K95a8aeb2011-09-08 19:06:18 +05301364 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
Ricardo Neri82335c42011-04-05 16:05:18 -05001365 r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
1366 r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
1367 r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
1368 r = FLD_MOD(r, aud_fmt->type, 4, 4);
1369 r = FLD_MOD(r, aud_fmt->justification, 3, 3);
1370 r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
1371 r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
1372 r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301373 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001374}
1375
Mythri P K95a8aeb2011-09-08 19:06:18 +05301376static void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
1377 struct hdmi_audio_dma *aud_dma)
Ricardo Neri82335c42011-04-05 16:05:18 -05001378{
1379 u32 r;
1380
1381 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
1382
Mythri P K95a8aeb2011-09-08 19:06:18 +05301383 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
Ricardo Neri82335c42011-04-05 16:05:18 -05001384 r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
1385 r = FLD_MOD(r, aud_dma->block_size, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301386 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001387
Mythri P K95a8aeb2011-09-08 19:06:18 +05301388 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001389 r = FLD_MOD(r, aud_dma->mode, 9, 9);
1390 r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301391 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001392}
1393
Mythri P K95a8aeb2011-09-08 19:06:18 +05301394static void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
1395 struct hdmi_core_audio_config *cfg)
Ricardo Neri82335c42011-04-05 16:05:18 -05001396{
1397 u32 r;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301398 void __iomem *av_base = hdmi_av_base(ip_data);
Ricardo Neri82335c42011-04-05 16:05:18 -05001399
1400 /* audio clock recovery parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301401 r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001402 r = FLD_MOD(r, cfg->use_mclk, 2, 2);
1403 r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
1404 r = FLD_MOD(r, cfg->cts_mode, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301405 hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001406
Mythri P K95a8aeb2011-09-08 19:06:18 +05301407 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
1408 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
1409 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001410
1411 if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
Mythri P K95a8aeb2011-09-08 19:06:18 +05301412 REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
1413 REG_FLD_MOD(av_base,
1414 HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
1415 REG_FLD_MOD(av_base,
1416 HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001417 } else {
1418 /*
1419 * HDMI IP uses this configuration to divide the MCLK to
1420 * update CTS value.
1421 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301422 REG_FLD_MOD(av_base,
1423 HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001424
1425 /* Configure clock for audio packets */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301426 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
1427 cfg->aud_par_busclk, 7, 0);
1428 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
1429 (cfg->aud_par_busclk >> 8), 7, 0);
1430 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
1431 (cfg->aud_par_busclk >> 16), 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001432 }
1433
1434 /* Override of SPDIF sample frequency with value in I2S_CHST4 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301435 REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
1436 cfg->fs_override, 1, 1);
Ricardo Neri82335c42011-04-05 16:05:18 -05001437
1438 /* I2S parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301439 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
1440 cfg->freq_sample, 3, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001441
Mythri P K95a8aeb2011-09-08 19:06:18 +05301442 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001443 r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
1444 r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
1445 r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
1446 r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
1447 r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
1448 r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
1449 r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
1450 r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301451 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001452
Mythri P K95a8aeb2011-09-08 19:06:18 +05301453 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
Ricardo Neri82335c42011-04-05 16:05:18 -05001454 r = FLD_MOD(r, cfg->freq_sample, 7, 4);
1455 r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
1456 r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301457 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001458
Mythri P K95a8aeb2011-09-08 19:06:18 +05301459 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
1460 cfg->i2s_cfg.in_length_bits, 3, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001461
1462 /* Audio channels and mode parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301463 REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
1464 r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
Ricardo Neri82335c42011-04-05 16:05:18 -05001465 r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
1466 r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
1467 r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
1468 r = FLD_MOD(r, cfg->en_spdif, 1, 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301469 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001470}
1471
Mythri P K95a8aeb2011-09-08 19:06:18 +05301472static void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
Ricardo Neri82335c42011-04-05 16:05:18 -05001473 struct hdmi_core_infoframe_audio *info_aud)
1474{
1475 u8 val;
1476 u8 sum = 0, checksum = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301477 void __iomem *av_base = hdmi_av_base(ip_data);
Ricardo Neri82335c42011-04-05 16:05:18 -05001478
1479 /*
1480 * Set audio info frame type, version and length as
1481 * described in HDMI 1.4a Section 8.2.2 specification.
1482 * Checksum calculation is defined in Section 5.3.5.
1483 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301484 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
1485 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
1486 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
Ricardo Neri82335c42011-04-05 16:05:18 -05001487 sum += 0x84 + 0x001 + 0x00a;
1488
1489 val = (info_aud->db1_coding_type << 4)
1490 | (info_aud->db1_channel_count - 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301491 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001492 sum += val;
1493
1494 val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301495 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001496 sum += val;
1497
Mythri P K95a8aeb2011-09-08 19:06:18 +05301498 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
Ricardo Neri82335c42011-04-05 16:05:18 -05001499
1500 val = info_aud->db4_channel_alloc;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301501 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001502 sum += val;
1503
1504 val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301505 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001506 sum += val;
1507
Mythri P K95a8aeb2011-09-08 19:06:18 +05301508 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
1509 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
1510 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
1511 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
1512 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
Ricardo Neri82335c42011-04-05 16:05:18 -05001513
1514 checksum = 0x100 - sum;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301515 hdmi_write_reg(av_base,
1516 HDMI_CORE_AV_AUDIO_CHSUM, checksum);
Ricardo Neri82335c42011-04-05 16:05:18 -05001517
1518 /*
1519 * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
1520 * is available.
1521 */
1522}
1523
Mythri P K95a8aeb2011-09-08 19:06:18 +05301524static int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
1525 u32 sample_freq, u32 *n, u32 *cts)
Ricardo Neri82335c42011-04-05 16:05:18 -05001526{
1527 u32 r;
1528 u32 deep_color = 0;
1529 u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
1530
1531 if (n == NULL || cts == NULL)
1532 return -EINVAL;
1533 /*
1534 * Obtain current deep color configuration. This needed
1535 * to calculate the TMDS clock based on the pixel clock.
1536 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301537 r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001538 switch (r) {
1539 case 1: /* No deep color selected */
1540 deep_color = 100;
1541 break;
1542 case 2: /* 10-bit deep color selected */
1543 deep_color = 125;
1544 break;
1545 case 3: /* 12-bit deep color selected */
1546 deep_color = 150;
1547 break;
1548 default:
1549 return -EINVAL;
1550 }
1551
1552 switch (sample_freq) {
1553 case 32000:
1554 if ((deep_color == 125) && ((pclk == 54054)
1555 || (pclk == 74250)))
1556 *n = 8192;
1557 else
1558 *n = 4096;
1559 break;
1560 case 44100:
1561 *n = 6272;
1562 break;
1563 case 48000:
1564 if ((deep_color == 125) && ((pclk == 54054)
1565 || (pclk == 74250)))
1566 *n = 8192;
1567 else
1568 *n = 6144;
1569 break;
1570 default:
1571 *n = 0;
1572 return -EINVAL;
1573 }
1574
1575 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
1576 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
1577
1578 return 0;
1579}
Ricardo Neriad44cc32011-05-18 22:31:56 -05001580
Mythri P K95a8aeb2011-09-08 19:06:18 +05301581static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
1582 struct snd_pcm_substream *substream,
Ricardo Neriad44cc32011-05-18 22:31:56 -05001583 struct snd_pcm_hw_params *params,
1584 struct snd_soc_dai *dai)
1585{
1586 struct hdmi_audio_format audio_format;
1587 struct hdmi_audio_dma audio_dma;
1588 struct hdmi_core_audio_config core_cfg;
1589 struct hdmi_core_infoframe_audio aud_if_cfg;
1590 int err, n, cts;
1591 enum hdmi_core_audio_sample_freq sample_freq;
1592
1593 switch (params_format(params)) {
1594 case SNDRV_PCM_FORMAT_S16_LE:
1595 core_cfg.i2s_cfg.word_max_length =
1596 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
1597 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
1598 core_cfg.i2s_cfg.in_length_bits =
1599 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
1600 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1601 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
1602 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
1603 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1604 audio_dma.transfer_size = 0x10;
1605 break;
1606 case SNDRV_PCM_FORMAT_S24_LE:
1607 core_cfg.i2s_cfg.word_max_length =
1608 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
1609 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
1610 core_cfg.i2s_cfg.in_length_bits =
1611 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
1612 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
1613 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
1614 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1615 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1616 audio_dma.transfer_size = 0x20;
1617 break;
1618 default:
1619 return -EINVAL;
1620 }
1621
1622 switch (params_rate(params)) {
1623 case 32000:
1624 sample_freq = HDMI_AUDIO_FS_32000;
1625 break;
1626 case 44100:
1627 sample_freq = HDMI_AUDIO_FS_44100;
1628 break;
1629 case 48000:
1630 sample_freq = HDMI_AUDIO_FS_48000;
1631 break;
1632 default:
1633 return -EINVAL;
1634 }
1635
Mythri P K95a8aeb2011-09-08 19:06:18 +05301636 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001637 if (err < 0)
1638 return err;
1639
1640 /* Audio wrapper config */
1641 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
1642 audio_format.active_chnnls_msk = 0x03;
1643 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
1644 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
1645 /* Disable start/stop signals of IEC 60958 blocks */
1646 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
1647
1648 audio_dma.block_size = 0xC0;
1649 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
1650 audio_dma.fifo_threshold = 0x20; /* in number of samples */
1651
Mythri P K95a8aeb2011-09-08 19:06:18 +05301652 hdmi_wp_audio_config_dma(ip_data, &audio_dma);
1653 hdmi_wp_audio_config_format(ip_data, &audio_format);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001654
1655 /*
1656 * I2S config
1657 */
1658 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
1659 /* Only used with high bitrate audio */
1660 core_cfg.i2s_cfg.cbit_order = false;
1661 /* Serial data and word select should change on sck rising edge */
1662 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
1663 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
1664 /* Set I2S word select polarity */
1665 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
1666 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
1667 /* Set serial data to word select shift. See Phillips spec. */
1668 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
1669 /* Enable one of the four available serial data channels */
1670 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
1671
1672 /* Core audio config */
1673 core_cfg.freq_sample = sample_freq;
1674 core_cfg.n = n;
1675 core_cfg.cts = cts;
1676 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
1677 core_cfg.aud_par_busclk = 0;
1678 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
1679 core_cfg.use_mclk = false;
1680 } else {
1681 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
1682 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
1683 core_cfg.use_mclk = true;
1684 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
1685 }
1686 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
1687 core_cfg.en_spdif = false;
1688 /* Use sample frequency from channel status word */
1689 core_cfg.fs_override = true;
1690 /* Enable ACR packets */
1691 core_cfg.en_acr_pkt = true;
1692 /* Disable direct streaming digital audio */
1693 core_cfg.en_dsd_audio = false;
1694 /* Use parallel audio interface */
1695 core_cfg.en_parallel_aud_input = true;
1696
Mythri P K95a8aeb2011-09-08 19:06:18 +05301697 hdmi_core_audio_config(ip_data, &core_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001698
1699 /*
1700 * Configure packet
1701 * info frame audio see doc CEA861-D page 74
1702 */
1703 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
1704 aud_if_cfg.db1_channel_count = 2;
1705 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
1706 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
1707 aud_if_cfg.db4_channel_alloc = 0x00;
1708 aud_if_cfg.db5_downmix_inh = false;
1709 aud_if_cfg.db5_lsv = 0;
1710
Mythri P K95a8aeb2011-09-08 19:06:18 +05301711 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001712 return 0;
1713}
1714
Mythri P K95a8aeb2011-09-08 19:06:18 +05301715static int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
1716 struct snd_pcm_substream *substream, int cmd,
1717 struct snd_soc_dai *dai)
Ricardo Neriad44cc32011-05-18 22:31:56 -05001718{
1719 int err = 0;
1720 switch (cmd) {
1721 case SNDRV_PCM_TRIGGER_START:
1722 case SNDRV_PCM_TRIGGER_RESUME:
1723 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Mythri P K95a8aeb2011-09-08 19:06:18 +05301724 REG_FLD_MOD(hdmi_av_base(ip_data),
1725 HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
1726 REG_FLD_MOD(hdmi_wp_base(ip_data),
1727 HDMI_WP_AUDIO_CTRL, 1, 31, 31);
1728 REG_FLD_MOD(hdmi_wp_base(ip_data),
1729 HDMI_WP_AUDIO_CTRL, 1, 30, 30);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001730 break;
1731
1732 case SNDRV_PCM_TRIGGER_STOP:
1733 case SNDRV_PCM_TRIGGER_SUSPEND:
1734 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Mythri P K95a8aeb2011-09-08 19:06:18 +05301735 REG_FLD_MOD(hdmi_av_base(ip_data),
1736 HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
1737 REG_FLD_MOD(hdmi_wp_base(ip_data),
1738 HDMI_WP_AUDIO_CTRL, 0, 30, 30);
1739 REG_FLD_MOD(hdmi_wp_base(ip_data),
1740 HDMI_WP_AUDIO_CTRL, 0, 31, 31);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001741 break;
1742 default:
1743 err = -EINVAL;
1744 }
1745 return err;
1746}
1747
1748static int hdmi_audio_startup(struct snd_pcm_substream *substream,
1749 struct snd_soc_dai *dai)
1750{
1751 if (!hdmi.mode) {
1752 pr_err("Current video settings do not support audio.\n");
1753 return -EIO;
1754 }
1755 return 0;
1756}
1757
1758static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
1759};
1760
1761static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
1762 .hw_params = hdmi_audio_hw_params,
1763 .trigger = hdmi_audio_trigger,
1764 .startup = hdmi_audio_startup,
1765};
1766
1767static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
1768 .name = "hdmi-audio-codec",
1769 .playback = {
1770 .channels_min = 2,
1771 .channels_max = 2,
1772 .rates = SNDRV_PCM_RATE_32000 |
1773 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
1774 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1775 SNDRV_PCM_FMTBIT_S24_LE,
1776 },
1777 .ops = &hdmi_audio_codec_ops,
1778};
Ricardo Neri82335c42011-04-05 16:05:18 -05001779#endif
1780
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001781static int hdmi_get_clocks(struct platform_device *pdev)
1782{
1783 struct clk *clk;
1784
1785 clk = clk_get(&pdev->dev, "sys_clk");
1786 if (IS_ERR(clk)) {
1787 DSSERR("can't get sys_clk\n");
1788 return PTR_ERR(clk);
1789 }
1790
1791 hdmi.sys_clk = clk;
1792
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001793 return 0;
1794}
1795
1796static void hdmi_put_clocks(void)
1797{
1798 if (hdmi.sys_clk)
1799 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001800}
1801
Mythri P Kc3198a52011-03-12 12:04:27 +05301802/* HDMI HW IP initialisation */
1803static int omapdss_hdmihw_probe(struct platform_device *pdev)
1804{
1805 struct resource *hdmi_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001806 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301807
1808 hdmi.pdata = pdev->dev.platform_data;
1809 hdmi.pdev = pdev;
1810
1811 mutex_init(&hdmi.lock);
1812
1813 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1814 if (!hdmi_mem) {
1815 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1816 return -EINVAL;
1817 }
1818
1819 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301820 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
1821 resource_size(hdmi_mem));
1822 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +05301823 DSSERR("can't ioremap WP\n");
1824 return -ENOMEM;
1825 }
1826
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001827 r = hdmi_get_clocks(pdev);
1828 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +05301829 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001830 return r;
1831 }
1832
1833 pm_runtime_enable(&pdev->dev);
1834
Mythri P K95a8aeb2011-09-08 19:06:18 +05301835 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1836 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1837 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1838 hdmi.ip_data.phy_offset = HDMI_PHY;
1839
Mythri P Kc3198a52011-03-12 12:04:27 +05301840 hdmi_panel_init();
1841
Ricardo Neriad44cc32011-05-18 22:31:56 -05001842#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1843 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1844
1845 /* Register ASoC codec DAI */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001846 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
Ricardo Neriad44cc32011-05-18 22:31:56 -05001847 &hdmi_codec_dai_drv, 1);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001848 if (r) {
Ricardo Neriad44cc32011-05-18 22:31:56 -05001849 DSSERR("can't register ASoC HDMI audio codec\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001850 return r;
Ricardo Neriad44cc32011-05-18 22:31:56 -05001851 }
1852#endif
Mythri P Kc3198a52011-03-12 12:04:27 +05301853 return 0;
1854}
1855
1856static int omapdss_hdmihw_remove(struct platform_device *pdev)
1857{
1858 hdmi_panel_exit();
1859
Ricardo Neriad44cc32011-05-18 22:31:56 -05001860#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1861 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1862 snd_soc_unregister_codec(&pdev->dev);
1863#endif
1864
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001865 pm_runtime_disable(&pdev->dev);
1866
1867 hdmi_put_clocks();
1868
Mythri P K95a8aeb2011-09-08 19:06:18 +05301869 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301870
1871 return 0;
1872}
1873
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001874static int hdmi_runtime_suspend(struct device *dev)
1875{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001876 clk_disable(hdmi.sys_clk);
1877
1878 dispc_runtime_put();
1879 dss_runtime_put();
1880
1881 return 0;
1882}
1883
1884static int hdmi_runtime_resume(struct device *dev)
1885{
1886 int r;
1887
1888 r = dss_runtime_get();
1889 if (r < 0)
1890 goto err_get_dss;
1891
1892 r = dispc_runtime_get();
1893 if (r < 0)
1894 goto err_get_dispc;
1895
1896
1897 clk_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001898
1899 return 0;
1900
1901err_get_dispc:
1902 dss_runtime_put();
1903err_get_dss:
1904 return r;
1905}
1906
1907static const struct dev_pm_ops hdmi_pm_ops = {
1908 .runtime_suspend = hdmi_runtime_suspend,
1909 .runtime_resume = hdmi_runtime_resume,
1910};
1911
Mythri P Kc3198a52011-03-12 12:04:27 +05301912static struct platform_driver omapdss_hdmihw_driver = {
1913 .probe = omapdss_hdmihw_probe,
1914 .remove = omapdss_hdmihw_remove,
1915 .driver = {
1916 .name = "omapdss_hdmi",
1917 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001918 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301919 },
1920};
1921
1922int hdmi_init_platform_driver(void)
1923{
1924 return platform_driver_register(&omapdss_hdmihw_driver);
1925}
1926
1927void hdmi_uninit_platform_driver(void)
1928{
1929 return platform_driver_unregister(&omapdss_hdmihw_driver);
1930}