blob: 47e9f4abe322ee9ff928e31f01e12c415bb4d9f8 [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
42#include "dss.h"
43#include "hdmi.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050044#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053045
Mythri P K95a8aeb2011-09-08 19:06:18 +053046#define HDMI_WP 0x0
47#define HDMI_CORE_SYS 0x400
48#define HDMI_CORE_AV 0x900
49#define HDMI_PLLCTRL 0x200
50#define HDMI_PHY 0x300
51
Mythri P Kc3198a52011-03-12 12:04:27 +053052static struct {
53 struct mutex lock;
54 struct omap_display_platform_data *pdata;
55 struct platform_device *pdev;
Mythri P K95a8aeb2011-09-08 19:06:18 +053056 struct hdmi_ip_data ip_data;
Mythri P Kc3198a52011-03-12 12:04:27 +053057 int code;
58 int mode;
59 u8 edid[HDMI_EDID_MAX_LENGTH];
60 u8 edid_set;
61 bool custom_set;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030062
63 struct clk *sys_clk;
Mythri P Kc3198a52011-03-12 12:04:27 +053064} hdmi;
65
66/*
67 * Logic for the below structure :
68 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
69 * There is a correspondence between CEA/VESA timing and code, please
70 * refer to section 6.3 in HDMI 1.3 specification for timing code.
71 *
72 * In the below structure, cea_vesa_timings corresponds to all OMAP4
73 * supported CEA and VESA timing values.code_cea corresponds to the CEA
74 * code, It is used to get the timing from cea_vesa_timing array.Similarly
75 * with code_vesa. Code_index is used for back mapping, that is once EDID
76 * is read from the TV, EDID is parsed to find the timing values and then
77 * map it to corresponding CEA or VESA index.
78 */
79
80static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
81 { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
82 { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
83 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
84 { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
85 { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
86 { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
87 { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
88 { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
89 { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
90 { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
91 { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
92 { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
93 { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
94 { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
95 { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
96 /* VESA From Here */
97 { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
98 { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
99 { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
100 { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
101 { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
102 { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
103 { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
104 { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
105 { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
106 { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
107 { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
108 { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
109 { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
110 { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
111 { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
112 { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
113 { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
114 { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
115 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
116};
117
118/*
119 * This is a static mapping array which maps the timing values
120 * with corresponding CEA / VESA code
121 */
122static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
123 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
124 /* <--15 CEA 17--> vesa*/
125 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
126 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
127};
128
129/*
130 * This is reverse static mapping which maps the CEA / VESA code
131 * to the corresponding timing values
132 */
133static const int code_cea[39] = {
134 -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
135 -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
136 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
137 11, 12, 14, -1, -1, 13, 13, 4, 4
138};
139
140static const int code_vesa[85] = {
141 -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
142 -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
143 -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
144 -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
145 -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
146 -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
147 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, 27, 28, -1, 33};
150
151static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
152
Mythri P K95a8aeb2011-09-08 19:06:18 +0530153static inline void hdmi_write_reg(void __iomem *base_addr,
154 const struct hdmi_reg idx, u32 val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530155{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530156 __raw_writel(val, base_addr + idx.idx);
Mythri P Kc3198a52011-03-12 12:04:27 +0530157}
158
Mythri P K95a8aeb2011-09-08 19:06:18 +0530159static inline u32 hdmi_read_reg(void __iomem *base_addr,
160 const struct hdmi_reg idx)
Mythri P Kc3198a52011-03-12 12:04:27 +0530161{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530162 return __raw_readl(base_addr + idx.idx);
Mythri P Kc3198a52011-03-12 12:04:27 +0530163}
164
Mythri P K95a8aeb2011-09-08 19:06:18 +0530165static inline void __iomem *hdmi_wp_base(struct hdmi_ip_data *ip_data)
166{
167 return ip_data->base_wp;
168}
169
170static inline void __iomem *hdmi_phy_base(struct hdmi_ip_data *ip_data)
171{
172 return ip_data->base_wp + ip_data->phy_offset;
173}
174
175static inline void __iomem *hdmi_pll_base(struct hdmi_ip_data *ip_data)
176{
177 return ip_data->base_wp + ip_data->pll_offset;
178}
179
180static inline void __iomem *hdmi_av_base(struct hdmi_ip_data *ip_data)
181{
182 return ip_data->base_wp + ip_data->core_av_offset;
183}
184
185static inline void __iomem *hdmi_core_sys_base(struct hdmi_ip_data *ip_data)
186{
187 return ip_data->base_wp + ip_data->core_sys_offset;
188}
189
190static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
191 const struct hdmi_reg idx,
Mythri P Kc3198a52011-03-12 12:04:27 +0530192 int b2, int b1, u32 val)
193{
194 u32 t = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530195 while (val != REG_GET(base_addr, idx, b2, b1)) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530196 udelay(1);
197 if (t++ > 10000)
198 return !val;
199 }
200 return val;
201}
202
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300203static int hdmi_runtime_get(void)
204{
205 int r;
206
207 DSSDBG("hdmi_runtime_get\n");
208
209 r = pm_runtime_get_sync(&hdmi.pdev->dev);
210 WARN_ON(r < 0);
211 return r < 0 ? r : 0;
212}
213
214static void hdmi_runtime_put(void)
215{
216 int r;
217
218 DSSDBG("hdmi_runtime_put\n");
219
220 r = pm_runtime_put(&hdmi.pdev->dev);
221 WARN_ON(r < 0);
222}
223
Mythri P Kc3198a52011-03-12 12:04:27 +0530224int hdmi_init_display(struct omap_dss_device *dssdev)
225{
226 DSSDBG("init_display\n");
227
228 return 0;
229}
230
Mythri P K7b27da52011-09-08 19:06:19 +0530231static int hdmi_pll_init(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530232{
233 u32 r;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530234 void __iomem *pll_base = hdmi_pll_base(ip_data);
Mythri P K7b27da52011-09-08 19:06:19 +0530235 struct hdmi_pll_info *fmt = &ip_data->pll_data;
Mythri P Kc3198a52011-03-12 12:04:27 +0530236
237 /* PLL start always use manual mode */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530238 REG_FLD_MOD(pll_base, PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530239
Mythri P K95a8aeb2011-09-08 19:06:18 +0530240 r = hdmi_read_reg(pll_base, PLLCTRL_CFG1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530241 r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
242 r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */
243
Mythri P K95a8aeb2011-09-08 19:06:18 +0530244 hdmi_write_reg(pll_base, PLLCTRL_CFG1, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530245
Mythri P K95a8aeb2011-09-08 19:06:18 +0530246 r = hdmi_read_reg(pll_base, PLLCTRL_CFG2);
Mythri P Kc3198a52011-03-12 12:04:27 +0530247
248 r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
249 r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
250 r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
Mythri P K7b27da52011-09-08 19:06:19 +0530251 r = FLD_MOD(r, fmt->refsel, 22, 21); /* REFSEL */
Mythri P Kc3198a52011-03-12 12:04:27 +0530252
Mythri P K7b27da52011-09-08 19:06:19 +0530253 if (fmt->dcofreq) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530254 /* divider programming for frequency beyond 1000Mhz */
Mythri P K7b27da52011-09-08 19:06:19 +0530255 REG_FLD_MOD(pll_base, PLLCTRL_CFG3, fmt->regsd, 17, 10);
Mythri P Kc3198a52011-03-12 12:04:27 +0530256 r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
257 } else {
258 r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
259 }
260
Mythri P K95a8aeb2011-09-08 19:06:18 +0530261 hdmi_write_reg(pll_base, PLLCTRL_CFG2, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530262
Mythri P K95a8aeb2011-09-08 19:06:18 +0530263 r = hdmi_read_reg(pll_base, PLLCTRL_CFG4);
Mythri P Kc3198a52011-03-12 12:04:27 +0530264 r = FLD_MOD(r, fmt->regm2, 24, 18);
265 r = FLD_MOD(r, fmt->regmf, 17, 0);
266
Mythri P K95a8aeb2011-09-08 19:06:18 +0530267 hdmi_write_reg(pll_base, PLLCTRL_CFG4, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530268
269 /* go now */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530270 REG_FLD_MOD(pll_base, PLLCTRL_PLL_GO, 0x1, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530271
272 /* wait for bit change */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530273 if (hdmi_wait_for_bit_change(pll_base, PLLCTRL_PLL_GO,
274 0, 0, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530275 DSSERR("PLL GO bit not set\n");
276 return -ETIMEDOUT;
277 }
278
279 /* Wait till the lock bit is set in PLL status */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530280 if (hdmi_wait_for_bit_change(pll_base,
281 PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530282 DSSWARN("cannot lock PLL\n");
283 DSSWARN("CFG1 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530284 hdmi_read_reg(pll_base, PLLCTRL_CFG1));
Mythri P Kc3198a52011-03-12 12:04:27 +0530285 DSSWARN("CFG2 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530286 hdmi_read_reg(pll_base, PLLCTRL_CFG2));
Mythri P Kc3198a52011-03-12 12:04:27 +0530287 DSSWARN("CFG4 0x%x\n",
Mythri P K95a8aeb2011-09-08 19:06:18 +0530288 hdmi_read_reg(pll_base, PLLCTRL_CFG4));
Mythri P Kc3198a52011-03-12 12:04:27 +0530289 return -ETIMEDOUT;
290 }
291
292 DSSDBG("PLL locked!\n");
293
294 return 0;
295}
296
297/* PHY_PWR_CMD */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530298static int hdmi_set_phy_pwr(struct hdmi_ip_data *ip_data, enum hdmi_phy_pwr val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530299{
300 /* Command for power control of HDMI PHY */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530301 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 7, 6);
Mythri P Kc3198a52011-03-12 12:04:27 +0530302
303 /* Status of the power control of HDMI PHY */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530304 if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data),
305 HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530306 DSSERR("Failed to set PHY power mode to %d\n", val);
307 return -ETIMEDOUT;
308 }
309
310 return 0;
311}
312
313/* PLL_PWR_CMD */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530314int hdmi_set_pll_pwr(struct hdmi_ip_data *ip_data, enum hdmi_pll_pwr val)
Mythri P Kc3198a52011-03-12 12:04:27 +0530315{
316 /* Command for power control of HDMI PLL */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530317 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 3, 2);
Mythri P Kc3198a52011-03-12 12:04:27 +0530318
319 /* wait till PHY_PWR_STATUS is set */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530320 if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL,
321 1, 0, val) != val) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530322 DSSERR("Failed to set PHY_PWR_STATUS\n");
323 return -ETIMEDOUT;
324 }
325
326 return 0;
327}
328
Mythri P K95a8aeb2011-09-08 19:06:18 +0530329static int hdmi_pll_reset(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530330{
331 /* SYSRESET controlled by power FSM */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530332 REG_FLD_MOD(hdmi_pll_base(ip_data), PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
Mythri P Kc3198a52011-03-12 12:04:27 +0530333
334 /* READ 0x0 reset is in progress */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530335 if (hdmi_wait_for_bit_change(hdmi_pll_base(ip_data),
336 PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530337 DSSERR("Failed to sysreset PLL\n");
338 return -ETIMEDOUT;
339 }
340
341 return 0;
342}
343
Mythri P K95a8aeb2011-09-08 19:06:18 +0530344static int hdmi_phy_init(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530345{
346 u16 r = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530347 void __iomem *phy_base = hdmi_phy_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530348
Mythri P K95a8aeb2011-09-08 19:06:18 +0530349 r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
Mythri P Kc3198a52011-03-12 12:04:27 +0530350 if (r)
351 return r;
352
Mythri P K95a8aeb2011-09-08 19:06:18 +0530353 r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
Mythri P Kc3198a52011-03-12 12:04:27 +0530354 if (r)
355 return r;
356
357 /*
358 * Read address 0 in order to get the SCP reset done completed
359 * Dummy access performed to make sure reset is done
360 */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530361 hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
Mythri P Kc3198a52011-03-12 12:04:27 +0530362
363 /*
364 * Write to phy address 0 to configure the clock
365 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
366 */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530367 REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
Mythri P Kc3198a52011-03-12 12:04:27 +0530368
369 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530370 hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
Mythri P Kc3198a52011-03-12 12:04:27 +0530371
372 /* Setup max LDO voltage */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530373 REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530374
375 /* Write to phy address 3 to change the polarity control */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530376 REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
Mythri P Kc3198a52011-03-12 12:04:27 +0530377
378 return 0;
379}
380
Mythri P K7b27da52011-09-08 19:06:19 +0530381static int hdmi_pll_program(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530382{
383 u16 r = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530384
Mythri P K95a8aeb2011-09-08 19:06:18 +0530385 r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
Mythri P Kc3198a52011-03-12 12:04:27 +0530386 if (r)
387 return r;
388
Mythri P K95a8aeb2011-09-08 19:06:18 +0530389 r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
Mythri P Kc3198a52011-03-12 12:04:27 +0530390 if (r)
391 return r;
392
Mythri P K95a8aeb2011-09-08 19:06:18 +0530393 r = hdmi_pll_reset(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530394 if (r)
395 return r;
396
Mythri P K7b27da52011-09-08 19:06:19 +0530397 r = hdmi_pll_init(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530398 if (r)
399 return r;
400
401 return 0;
402}
403
Mythri P K95a8aeb2011-09-08 19:06:18 +0530404static void hdmi_phy_off(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530405{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530406 hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
Mythri P Kc3198a52011-03-12 12:04:27 +0530407}
408
Mythri P K95a8aeb2011-09-08 19:06:18 +0530409static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
410 u8 *pedid, int ext)
Mythri P Kc3198a52011-03-12 12:04:27 +0530411{
412 u32 i, j;
413 char checksum = 0;
414 u32 offset = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530415 void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530416
417 /* Turn on CLK for DDC */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530418 REG_FLD_MOD(hdmi_av_base(ip_data), HDMI_CORE_AV_DPD, 0x7, 2, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530419
420 /*
421 * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
422 * right shifted values( The behavior is not consistent and seen only
423 * with some TV's)
424 */
425 usleep_range(800, 1000);
426
427 if (!ext) {
428 /* Clk SCL Devices */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530429 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530430
431 /* HDMI_CORE_DDC_STATUS_IN_PROG */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530432 if (hdmi_wait_for_bit_change(core_sys_base,
433 HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530434 DSSERR("Failed to program DDC\n");
435 return -ETIMEDOUT;
436 }
437
438 /* Clear FIFO */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530439 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530440
441 /* HDMI_CORE_DDC_STATUS_IN_PROG */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530442 if (hdmi_wait_for_bit_change(core_sys_base,
443 HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530444 DSSERR("Failed to program DDC\n");
445 return -ETIMEDOUT;
446 }
447
448 } else {
449 if (ext % 2 != 0)
450 offset = 0x80;
451 }
452
453 /* Load Segment Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530454 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530455
456 /* Load Slave Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530457 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530458
459 /* Load Offset Address Register */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530460 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530461
462 /* Load Byte Count */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530463 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
464 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530465
466 /* Set DDC_CMD */
467 if (ext)
Mythri P K95a8aeb2011-09-08 19:06:18 +0530468 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530469 else
Mythri P K95a8aeb2011-09-08 19:06:18 +0530470 REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530471
472 /* HDMI_CORE_DDC_STATUS_BUS_LOW */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530473 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530474 DSSWARN("I2C Bus Low?\n");
475 return -EIO;
476 }
477 /* HDMI_CORE_DDC_STATUS_NO_ACK */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530478 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530479 DSSWARN("I2C No Ack\n");
480 return -EIO;
481 }
482
483 i = ext * 128;
484 j = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530485 while (((REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
486 (REG_GET(core_sys_base,
487 HDMI_CORE_DDC_STATUS, 2, 2) == 0)) && j < 128) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530488
Mythri P K95a8aeb2011-09-08 19:06:18 +0530489 if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530490 /* FIFO not empty */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530491 pedid[i++] = REG_GET(core_sys_base,
492 HDMI_CORE_DDC_DATA, 7, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530493 j++;
494 }
495 }
496
497 for (j = 0; j < 128; j++)
498 checksum += pedid[j];
499
500 if (checksum != 0) {
501 DSSERR("E-EDID checksum failed!!\n");
502 return -EIO;
503 }
504
505 return 0;
506}
507
Mythri P K95a8aeb2011-09-08 19:06:18 +0530508static int read_edid(struct hdmi_ip_data *ip_data, u8 *pedid, u16 max_length)
Mythri P Kc3198a52011-03-12 12:04:27 +0530509{
510 int r = 0, n = 0, i = 0;
511 int max_ext_blocks = (max_length / 128) - 1;
512
Mythri P K95a8aeb2011-09-08 19:06:18 +0530513 r = hdmi_core_ddc_edid(ip_data, pedid, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530514 if (r) {
515 return r;
516 } else {
517 n = pedid[0x7e];
518
519 /*
520 * README: need to comply with max_length set by the caller.
521 * Better implementation should be to allocate necessary
522 * memory to store EDID according to nb_block field found
523 * in first block
524 */
525 if (n > max_ext_blocks)
526 n = max_ext_blocks;
527
528 for (i = 1; i <= n; i++) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530529 r = hdmi_core_ddc_edid(ip_data, pedid, i);
Mythri P Kc3198a52011-03-12 12:04:27 +0530530 if (r)
531 return r;
532 }
533 }
534 return 0;
535}
536
537static int get_timings_index(void)
538{
539 int code;
540
541 if (hdmi.mode == 0)
542 code = code_vesa[hdmi.code];
543 else
544 code = code_cea[hdmi.code];
545
546 if (code == -1) {
547 /* HDMI code 4 corresponds to 640 * 480 VGA */
548 hdmi.code = 4;
549 /* DVI mode 1 corresponds to HDMI 0 to DVI */
550 hdmi.mode = HDMI_DVI;
551
552 code = code_vesa[hdmi.code];
553 }
554 return code;
555}
556
557static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
558{
559 int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
560 int timing_vsync = 0, timing_hsync = 0;
561 struct omap_video_timings temp;
562 struct hdmi_cm cm = {-1};
563 DSSDBG("hdmi_get_code\n");
564
565 for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
566 temp = cea_vesa_timings[i].timings;
567 if ((temp.pixel_clock == timing->pixel_clock) &&
568 (temp.x_res == timing->x_res) &&
569 (temp.y_res == timing->y_res)) {
570
571 temp_hsync = temp.hfp + temp.hsw + temp.hbp;
572 timing_hsync = timing->hfp + timing->hsw + timing->hbp;
573 temp_vsync = temp.vfp + temp.vsw + temp.vbp;
574 timing_vsync = timing->vfp + timing->vsw + timing->vbp;
575
576 DSSDBG("temp_hsync = %d , temp_vsync = %d"
577 "timing_hsync = %d, timing_vsync = %d\n",
578 temp_hsync, temp_hsync,
579 timing_hsync, timing_vsync);
580
581 if ((temp_hsync == timing_hsync) &&
582 (temp_vsync == timing_vsync)) {
583 code = i;
584 cm.code = code_index[i];
585 if (code < 14)
586 cm.mode = HDMI_HDMI;
587 else
588 cm.mode = HDMI_DVI;
589 DSSDBG("Hdmi_code = %d mode = %d\n",
590 cm.code, cm.mode);
591 break;
592 }
593 }
594 }
595
596 return cm;
597}
598
599static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
600 struct omap_video_timings *timings)
601{
602 /* X and Y resolution */
603 timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
604 edid[current_descriptor_addrs + 2]);
605 timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
606 edid[current_descriptor_addrs + 5]);
607
608 timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
609 edid[current_descriptor_addrs]);
610
611 timings->pixel_clock = 10 * timings->pixel_clock;
612
613 /* HORIZONTAL FRONT PORCH */
614 timings->hfp = edid[current_descriptor_addrs + 8] |
615 ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
616 /* HORIZONTAL SYNC WIDTH */
617 timings->hsw = edid[current_descriptor_addrs + 9] |
618 ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
619 /* HORIZONTAL BACK PORCH */
620 timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
621 edid[current_descriptor_addrs + 3]) -
622 (timings->hfp + timings->hsw);
623 /* VERTICAL FRONT PORCH */
624 timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
625 ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
626 /* VERTICAL SYNC WIDTH */
627 timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
628 ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
629 /* VERTICAL BACK PORCH */
630 timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
631 edid[current_descriptor_addrs + 6]) -
632 (timings->vfp + timings->vsw);
633
634}
635
636/* Description : This function gets the resolution information from EDID */
637static void get_edid_timing_data(u8 *edid)
638{
639 u8 count;
640 u16 current_descriptor_addrs;
641 struct hdmi_cm cm;
642 struct omap_video_timings edid_timings;
643
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300644 /* search block 0, there are 4 DTDs arranged in priority order */
Mythri P Kc3198a52011-03-12 12:04:27 +0530645 for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
646 current_descriptor_addrs =
647 EDID_DESCRIPTOR_BLOCK0_ADDRESS +
648 count * EDID_TIMING_DESCRIPTOR_SIZE;
649 get_horz_vert_timing_info(current_descriptor_addrs,
650 edid, &edid_timings);
651 cm = hdmi_get_code(&edid_timings);
652 DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
653 count, cm.code, cm.mode);
654 if (cm.code == -1) {
655 continue;
656 } else {
657 hdmi.code = cm.code;
658 hdmi.mode = cm.mode;
659 DSSDBG("code = %d , mode = %d\n",
660 hdmi.code, hdmi.mode);
661 return;
662 }
663 }
664 if (edid[0x7e] != 0x00) {
665 for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
666 count++) {
667 current_descriptor_addrs =
668 EDID_DESCRIPTOR_BLOCK1_ADDRESS +
669 count * EDID_TIMING_DESCRIPTOR_SIZE;
670 get_horz_vert_timing_info(current_descriptor_addrs,
671 edid, &edid_timings);
672 cm = hdmi_get_code(&edid_timings);
673 DSSDBG("Block1[%d] value matches code = %d, mode = %d",
674 count, cm.code, cm.mode);
675 if (cm.code == -1) {
676 continue;
677 } else {
678 hdmi.code = cm.code;
679 hdmi.mode = cm.mode;
680 DSSDBG("code = %d , mode = %d\n",
681 hdmi.code, hdmi.mode);
682 return;
683 }
684 }
685 }
686
687 DSSINFO("no valid timing found , falling back to VGA\n");
688 hdmi.code = 4; /* setting default value of 640 480 VGA */
689 hdmi.mode = HDMI_DVI;
690}
691
692static void hdmi_read_edid(struct omap_video_timings *dp)
693{
694 int ret = 0, code;
695
696 memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
697
698 if (!hdmi.edid_set)
Mythri P K95a8aeb2011-09-08 19:06:18 +0530699 ret = read_edid(&hdmi.ip_data, hdmi.edid,
700 HDMI_EDID_MAX_LENGTH);
Mythri P Kc3198a52011-03-12 12:04:27 +0530701 if (!ret) {
702 if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
703 /* search for timings of default resolution */
704 get_edid_timing_data(hdmi.edid);
705 hdmi.edid_set = true;
706 }
707 } else {
708 DSSWARN("failed to read E-EDID\n");
709 }
710
711 if (!hdmi.edid_set) {
712 DSSINFO("fallback to VGA\n");
713 hdmi.code = 4; /* setting default value of 640 480 VGA */
714 hdmi.mode = HDMI_DVI;
715 }
716
717 code = get_timings_index();
718
719 *dp = cea_vesa_timings[code].timings;
720}
721
722static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
723 struct hdmi_core_infoframe_avi *avi_cfg,
724 struct hdmi_core_packet_enable_repeat *repeat_cfg)
725{
726 DSSDBG("Enter hdmi_core_init\n");
727
728 /* video core */
729 video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
730 video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
731 video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
732 video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
733 video_cfg->hdmi_dvi = HDMI_DVI;
734 video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
735
736 /* info frame */
737 avi_cfg->db1_format = 0;
738 avi_cfg->db1_active_info = 0;
739 avi_cfg->db1_bar_info_dv = 0;
740 avi_cfg->db1_scan_info = 0;
741 avi_cfg->db2_colorimetry = 0;
742 avi_cfg->db2_aspect_ratio = 0;
743 avi_cfg->db2_active_fmt_ar = 0;
744 avi_cfg->db3_itc = 0;
745 avi_cfg->db3_ec = 0;
746 avi_cfg->db3_q_range = 0;
747 avi_cfg->db3_nup_scaling = 0;
748 avi_cfg->db4_videocode = 0;
749 avi_cfg->db5_pixel_repeat = 0;
750 avi_cfg->db6_7_line_eoftop = 0 ;
751 avi_cfg->db8_9_line_sofbottom = 0;
752 avi_cfg->db10_11_pixel_eofleft = 0;
753 avi_cfg->db12_13_pixel_sofright = 0;
754
755 /* packet enable and repeat */
756 repeat_cfg->audio_pkt = 0;
757 repeat_cfg->audio_pkt_repeat = 0;
758 repeat_cfg->avi_infoframe = 0;
759 repeat_cfg->avi_infoframe_repeat = 0;
760 repeat_cfg->gen_cntrl_pkt = 0;
761 repeat_cfg->gen_cntrl_pkt_repeat = 0;
762 repeat_cfg->generic_pkt = 0;
763 repeat_cfg->generic_pkt_repeat = 0;
764}
765
Mythri P K95a8aeb2011-09-08 19:06:18 +0530766static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530767{
768 DSSDBG("Enter hdmi_core_powerdown_disable\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530769 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530770}
771
Mythri P K95a8aeb2011-09-08 19:06:18 +0530772static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530773{
774 DSSDBG("Enter hdmi_core_swreset_release\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530775 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530776}
777
Mythri P K95a8aeb2011-09-08 19:06:18 +0530778static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530779{
780 DSSDBG("Enter hdmi_core_swreset_assert\n");
Mythri P K95a8aeb2011-09-08 19:06:18 +0530781 REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530782}
783
Mythri P K95a8aeb2011-09-08 19:06:18 +0530784/* HDMI_CORE_VIDEO_CONFIG */
785static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
786 struct hdmi_core_video_config *cfg)
Mythri P Kc3198a52011-03-12 12:04:27 +0530787{
788 u32 r = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530789 void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530790
791 /* sys_ctrl1 default configuration not tunable */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530792 r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530793 r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
794 r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
795 r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
796 r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530797 hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530798
Mythri P K95a8aeb2011-09-08 19:06:18 +0530799 REG_FLD_MOD(core_sys_base,
800 HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
Mythri P Kc3198a52011-03-12 12:04:27 +0530801
802 /* Vid_Mode */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530803 r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
Mythri P Kc3198a52011-03-12 12:04:27 +0530804
805 /* dither truncation configuration */
806 if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
807 r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
808 r = FLD_MOD(r, 1, 5, 5);
809 } else {
810 r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
811 r = FLD_MOD(r, 0, 5, 5);
812 }
Mythri P K95a8aeb2011-09-08 19:06:18 +0530813 hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530814
815 /* HDMI_Ctrl */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530816 r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
Mythri P Kc3198a52011-03-12 12:04:27 +0530817 r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
818 r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
819 r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530820 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530821
822 /* TMDS_CTRL */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530823 REG_FLD_MOD(core_sys_base,
824 HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
Mythri P Kc3198a52011-03-12 12:04:27 +0530825}
826
Mythri P K95a8aeb2011-09-08 19:06:18 +0530827static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530828 struct hdmi_core_infoframe_avi info_avi)
829{
830 u32 val;
831 char sum = 0, checksum = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530832 void __iomem *av_base = hdmi_av_base(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530833
834 sum += 0x82 + 0x002 + 0x00D;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530835 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
836 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
837 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
Mythri P Kc3198a52011-03-12 12:04:27 +0530838
839 val = (info_avi.db1_format << 5) |
840 (info_avi.db1_active_info << 4) |
841 (info_avi.db1_bar_info_dv << 2) |
842 (info_avi.db1_scan_info);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530843 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530844 sum += val;
845
846 val = (info_avi.db2_colorimetry << 6) |
847 (info_avi.db2_aspect_ratio << 4) |
848 (info_avi.db2_active_fmt_ar);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530849 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530850 sum += val;
851
852 val = (info_avi.db3_itc << 7) |
853 (info_avi.db3_ec << 4) |
854 (info_avi.db3_q_range << 2) |
855 (info_avi.db3_nup_scaling);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530856 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530857 sum += val;
858
Mythri P K95a8aeb2011-09-08 19:06:18 +0530859 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
860 info_avi.db4_videocode);
Mythri P Kc3198a52011-03-12 12:04:27 +0530861 sum += info_avi.db4_videocode;
862
863 val = info_avi.db5_pixel_repeat;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530864 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530865 sum += val;
866
867 val = info_avi.db6_7_line_eoftop & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530868 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530869 sum += val;
870
871 val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530872 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530873 sum += val;
874
875 val = info_avi.db8_9_line_sofbottom & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530876 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530877 sum += val;
878
879 val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530880 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530881 sum += val;
882
883 val = info_avi.db10_11_pixel_eofleft & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530884 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530885 sum += val;
886
887 val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530888 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530889 sum += val;
890
891 val = info_avi.db12_13_pixel_sofright & 0x00FF;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530892 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530893 sum += val;
894
895 val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530896 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
Mythri P Kc3198a52011-03-12 12:04:27 +0530897 sum += val;
898
899 checksum = 0x100 - sum;
Mythri P K95a8aeb2011-09-08 19:06:18 +0530900 hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
Mythri P Kc3198a52011-03-12 12:04:27 +0530901}
902
Mythri P K95a8aeb2011-09-08 19:06:18 +0530903static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530904 struct hdmi_core_packet_enable_repeat repeat_cfg)
905{
906 /* enable/repeat the infoframe */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530907 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
Mythri P Kc3198a52011-03-12 12:04:27 +0530908 (repeat_cfg.audio_pkt << 5) |
909 (repeat_cfg.audio_pkt_repeat << 4) |
910 (repeat_cfg.avi_infoframe << 1) |
911 (repeat_cfg.avi_infoframe_repeat));
912
913 /* enable/repeat the packet */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530914 hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
Mythri P Kc3198a52011-03-12 12:04:27 +0530915 (repeat_cfg.gen_cntrl_pkt << 3) |
916 (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
917 (repeat_cfg.generic_pkt << 1) |
918 (repeat_cfg.generic_pkt_repeat));
919}
920
921static void hdmi_wp_init(struct omap_video_timings *timings,
922 struct hdmi_video_format *video_fmt,
923 struct hdmi_video_interface *video_int)
924{
925 DSSDBG("Enter hdmi_wp_init\n");
926
927 timings->hbp = 0;
928 timings->hfp = 0;
929 timings->hsw = 0;
930 timings->vbp = 0;
931 timings->vfp = 0;
932 timings->vsw = 0;
933
934 video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
935 video_fmt->y_res = 0;
936 video_fmt->x_res = 0;
937
938 video_int->vsp = 0;
939 video_int->hsp = 0;
940
941 video_int->interlacing = 0;
942 video_int->tm = 0; /* HDMI_TIMING_SLAVE */
943
944}
945
Mythri P K95a8aeb2011-09-08 19:06:18 +0530946static void hdmi_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
Mythri P Kc3198a52011-03-12 12:04:27 +0530947{
Mythri P K95a8aeb2011-09-08 19:06:18 +0530948 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
Mythri P Kc3198a52011-03-12 12:04:27 +0530949}
950
951static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
952 struct omap_video_timings *timings, struct hdmi_config *param)
953{
954 DSSDBG("Enter hdmi_wp_video_init_format\n");
955
956 video_fmt->y_res = param->timings.timings.y_res;
957 video_fmt->x_res = param->timings.timings.x_res;
958
959 timings->hbp = param->timings.timings.hbp;
960 timings->hfp = param->timings.timings.hfp;
961 timings->hsw = param->timings.timings.hsw;
962 timings->vbp = param->timings.timings.vbp;
963 timings->vfp = param->timings.timings.vfp;
964 timings->vsw = param->timings.timings.vsw;
965}
966
Mythri P K95a8aeb2011-09-08 19:06:18 +0530967static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530968 struct hdmi_video_format *video_fmt)
969{
970 u32 l = 0;
971
Mythri P K95a8aeb2011-09-08 19:06:18 +0530972 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
973 video_fmt->packing_mode, 10, 8);
Mythri P Kc3198a52011-03-12 12:04:27 +0530974
975 l |= FLD_VAL(video_fmt->y_res, 31, 16);
976 l |= FLD_VAL(video_fmt->x_res, 15, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530977 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
Mythri P Kc3198a52011-03-12 12:04:27 +0530978}
979
Mythri P K95a8aeb2011-09-08 19:06:18 +0530980static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530981 struct hdmi_video_interface *video_int)
982{
983 u32 r;
984 DSSDBG("Enter hdmi_wp_video_config_interface\n");
985
Mythri P K95a8aeb2011-09-08 19:06:18 +0530986 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
Mythri P Kc3198a52011-03-12 12:04:27 +0530987 r = FLD_MOD(r, video_int->vsp, 7, 7);
988 r = FLD_MOD(r, video_int->hsp, 6, 6);
989 r = FLD_MOD(r, video_int->interlacing, 3, 3);
990 r = FLD_MOD(r, video_int->tm, 1, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530991 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
Mythri P Kc3198a52011-03-12 12:04:27 +0530992}
993
Mythri P K95a8aeb2011-09-08 19:06:18 +0530994static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
Mythri P Kc3198a52011-03-12 12:04:27 +0530995 struct omap_video_timings *timings)
996{
997 u32 timing_h = 0;
998 u32 timing_v = 0;
999
1000 DSSDBG("Enter hdmi_wp_video_config_timing\n");
1001
1002 timing_h |= FLD_VAL(timings->hbp, 31, 20);
1003 timing_h |= FLD_VAL(timings->hfp, 19, 8);
1004 timing_h |= FLD_VAL(timings->hsw, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301005 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
Mythri P Kc3198a52011-03-12 12:04:27 +05301006
1007 timing_v |= FLD_VAL(timings->vbp, 31, 20);
1008 timing_v |= FLD_VAL(timings->vfp, 19, 8);
1009 timing_v |= FLD_VAL(timings->vsw, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301010 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
Mythri P Kc3198a52011-03-12 12:04:27 +05301011}
1012
Mythri P K7b27da52011-09-08 19:06:19 +05301013static void hdmi_basic_configure(struct hdmi_ip_data *ip_data)
Mythri P Kc3198a52011-03-12 12:04:27 +05301014{
1015 /* HDMI */
1016 struct omap_video_timings video_timing;
1017 struct hdmi_video_format video_format;
1018 struct hdmi_video_interface video_interface;
1019 /* HDMI core */
1020 struct hdmi_core_infoframe_avi avi_cfg;
1021 struct hdmi_core_video_config v_core_cfg;
1022 struct hdmi_core_packet_enable_repeat repeat_cfg;
Mythri P K7b27da52011-09-08 19:06:19 +05301023 struct hdmi_config *cfg = &ip_data->cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +05301024
1025 hdmi_wp_init(&video_timing, &video_format,
1026 &video_interface);
1027
1028 hdmi_core_init(&v_core_cfg,
1029 &avi_cfg,
1030 &repeat_cfg);
1031
Mythri P K7b27da52011-09-08 19:06:19 +05301032 hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301033
Mythri P K95a8aeb2011-09-08 19:06:18 +05301034 hdmi_wp_video_config_timing(ip_data, &video_timing);
Mythri P Kc3198a52011-03-12 12:04:27 +05301035
1036 /* video config */
1037 video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
1038
Mythri P K95a8aeb2011-09-08 19:06:18 +05301039 hdmi_wp_video_config_format(ip_data, &video_format);
Mythri P Kc3198a52011-03-12 12:04:27 +05301040
1041 video_interface.vsp = cfg->timings.vsync_pol;
1042 video_interface.hsp = cfg->timings.hsync_pol;
1043 video_interface.interlacing = cfg->interlace;
1044 video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
1045
Mythri P K95a8aeb2011-09-08 19:06:18 +05301046 hdmi_wp_video_config_interface(ip_data, &video_interface);
Mythri P Kc3198a52011-03-12 12:04:27 +05301047
1048 /*
1049 * configure core video part
1050 * set software reset in the core
1051 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301052 hdmi_core_swreset_assert(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301053
1054 /* power down off */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301055 hdmi_core_powerdown_disable(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301056
1057 v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
1058 v_core_cfg.hdmi_dvi = cfg->cm.mode;
1059
Mythri P K95a8aeb2011-09-08 19:06:18 +05301060 hdmi_core_video_config(ip_data, &v_core_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301061
1062 /* release software reset in the core */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301063 hdmi_core_swreset_release(ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301064
1065 /*
1066 * configure packet
1067 * info frame video see doc CEA861-D page 65
1068 */
1069 avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
1070 avi_cfg.db1_active_info =
1071 HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
1072 avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
1073 avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
1074 avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
1075 avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
1076 avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
1077 avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
1078 avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
1079 avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
1080 avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
1081 avi_cfg.db4_videocode = cfg->cm.code;
1082 avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
1083 avi_cfg.db6_7_line_eoftop = 0;
1084 avi_cfg.db8_9_line_sofbottom = 0;
1085 avi_cfg.db10_11_pixel_eofleft = 0;
1086 avi_cfg.db12_13_pixel_sofright = 0;
1087
Mythri P K95a8aeb2011-09-08 19:06:18 +05301088 hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301089
1090 /* enable/repeat the infoframe */
1091 repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
1092 repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
1093 /* wakeup */
1094 repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
1095 repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301096 hdmi_core_av_packet_config(ip_data, repeat_cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +05301097}
1098
1099static void update_hdmi_timings(struct hdmi_config *cfg,
1100 struct omap_video_timings *timings, int code)
1101{
1102 cfg->timings.timings.x_res = timings->x_res;
1103 cfg->timings.timings.y_res = timings->y_res;
1104 cfg->timings.timings.hbp = timings->hbp;
1105 cfg->timings.timings.hfp = timings->hfp;
1106 cfg->timings.timings.hsw = timings->hsw;
1107 cfg->timings.timings.vbp = timings->vbp;
1108 cfg->timings.timings.vfp = timings->vfp;
1109 cfg->timings.timings.vsw = timings->vsw;
1110 cfg->timings.timings.pixel_clock = timings->pixel_clock;
1111 cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
1112 cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
1113}
1114
Archit Taneja6cb07b22011-04-12 13:52:25 +05301115static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
1116 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +05301117{
Archit Taneja6cb07b22011-04-12 13:52:25 +05301118 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +05301119 u32 mf;
1120
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001121 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +05301122 /*
1123 * Input clock is predivided by N + 1
1124 * out put of which is reference clk
1125 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301126 pi->regn = dssdev->clocks.hdmi.regn;
1127 refclk = clkin / (pi->regn + 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301128
1129 /*
1130 * multiplier is pixel_clk/ref_clk
1131 * Multiplying by 100 to avoid fractional part removal
1132 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301133 pi->regm = (phy * 100 / (refclk)) / 100;
1134 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +05301135
1136 /*
1137 * fractional multiplier is remainder of the difference between
1138 * multiplier and actual phy(required pixel clock thus should be
1139 * multiplied by 2^18(262144) divided by the reference clock
1140 */
1141 mf = (phy - pi->regm * refclk) * 262144;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301142 pi->regmf = mf / (refclk);
Mythri P Kc3198a52011-03-12 12:04:27 +05301143
1144 /*
1145 * Dcofreq should be set to 1 if required pixel clock
1146 * is greater than 1000MHz
1147 */
1148 pi->dcofreq = phy > 1000 * 100;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301149 pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +05301150
Mythri P K7b27da52011-09-08 19:06:19 +05301151 /* Set the reference clock to sysclk reference */
1152 pi->refsel = HDMI_REFSEL_SYSCLK;
1153
Mythri P Kc3198a52011-03-12 12:04:27 +05301154 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
1155 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
1156}
1157
Mythri P Kc3198a52011-03-12 12:04:27 +05301158static int hdmi_power_on(struct omap_dss_device *dssdev)
1159{
1160 int r, code = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +05301161 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +05301162 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +05301163
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001164 r = hdmi_runtime_get();
1165 if (r)
1166 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301167
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001168 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301169
1170 p = &dssdev->panel.timings;
1171
1172 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
1173 dssdev->panel.timings.x_res,
1174 dssdev->panel.timings.y_res);
1175
1176 if (!hdmi.custom_set) {
1177 DSSDBG("Read EDID as no EDID is not set on poweron\n");
1178 hdmi_read_edid(p);
1179 }
1180 code = get_timings_index();
1181 dssdev->panel.timings = cea_vesa_timings[code].timings;
Mythri P K7b27da52011-09-08 19:06:19 +05301182 update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
Mythri P Kc3198a52011-03-12 12:04:27 +05301183
Mythri P Kc3198a52011-03-12 12:04:27 +05301184 phy = p->pixel_clock;
1185
Mythri P K7b27da52011-09-08 19:06:19 +05301186 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301187
Mythri P K95a8aeb2011-09-08 19:06:18 +05301188 hdmi_wp_video_start(&hdmi.ip_data, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301189
Mythri P K95a8aeb2011-09-08 19:06:18 +05301190 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K7b27da52011-09-08 19:06:19 +05301191 r = hdmi_pll_program(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301192 if (r) {
1193 DSSDBG("Failed to lock PLL\n");
1194 goto err;
1195 }
1196
Mythri P K95a8aeb2011-09-08 19:06:18 +05301197 r = hdmi_phy_init(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301198 if (r) {
1199 DSSDBG("Failed to start PHY\n");
1200 goto err;
1201 }
1202
Mythri P K7b27da52011-09-08 19:06:19 +05301203 hdmi.ip_data.cfg.cm.mode = hdmi.mode;
1204 hdmi.ip_data.cfg.cm.code = hdmi.code;
1205 hdmi_basic_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +05301206
1207 /* Make selection of HDMI in DSS */
1208 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
1209
1210 /* Select the dispc clock source as PRCM clock, to ensure that it is not
1211 * DSI PLL source as the clock selected by DSI PLL might not be
1212 * sufficient for the resolution selected / that can be changed
1213 * dynamically by user. This can be moved to single location , say
1214 * Boardfile.
1215 */
Archit Taneja6cb07b22011-04-12 13:52:25 +05301216 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +05301217
1218 /* bypass TV gamma table */
1219 dispc_enable_gamma_table(0);
1220
1221 /* tv size */
1222 dispc_set_digit_size(dssdev->panel.timings.x_res,
1223 dssdev->panel.timings.y_res);
1224
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001225 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301226
Mythri P K95a8aeb2011-09-08 19:06:18 +05301227 hdmi_wp_video_start(&hdmi.ip_data, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +05301228
1229 return 0;
1230err:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001231 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +05301232 return -EIO;
1233}
1234
1235static void hdmi_power_off(struct omap_dss_device *dssdev)
1236{
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001237 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301238
Mythri P K95a8aeb2011-09-08 19:06:18 +05301239 hdmi_wp_video_start(&hdmi.ip_data, 0);
1240 hdmi_phy_off(&hdmi.ip_data);
1241 hdmi_set_pll_pwr(&hdmi.ip_data, HDMI_PLLPWRCMD_ALLOFF);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001242 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +05301243
1244 hdmi.edid_set = 0;
1245}
1246
1247int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
1248 struct omap_video_timings *timings)
1249{
1250 struct hdmi_cm cm;
1251
1252 cm = hdmi_get_code(timings);
1253 if (cm.code == -1) {
1254 DSSERR("Invalid timing entered\n");
1255 return -EINVAL;
1256 }
1257
1258 return 0;
1259
1260}
1261
1262void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
1263{
1264 struct hdmi_cm cm;
1265
1266 hdmi.custom_set = 1;
1267 cm = hdmi_get_code(&dssdev->panel.timings);
1268 hdmi.code = cm.code;
1269 hdmi.mode = cm.mode;
1270 omapdss_hdmi_display_enable(dssdev);
1271 hdmi.custom_set = 0;
1272}
1273
1274int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
1275{
1276 int r = 0;
1277
1278 DSSDBG("ENTER hdmi_display_enable\n");
1279
1280 mutex_lock(&hdmi.lock);
1281
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03001282 if (dssdev->manager == NULL) {
1283 DSSERR("failed to enable display: no manager\n");
1284 r = -ENODEV;
1285 goto err0;
1286 }
1287
Mythri P Kc3198a52011-03-12 12:04:27 +05301288 r = omap_dss_start_device(dssdev);
1289 if (r) {
1290 DSSERR("failed to start device\n");
1291 goto err0;
1292 }
1293
1294 if (dssdev->platform_enable) {
1295 r = dssdev->platform_enable(dssdev);
1296 if (r) {
1297 DSSERR("failed to enable GPIO's\n");
1298 goto err1;
1299 }
1300 }
1301
1302 r = hdmi_power_on(dssdev);
1303 if (r) {
1304 DSSERR("failed to power on device\n");
1305 goto err2;
1306 }
1307
1308 mutex_unlock(&hdmi.lock);
1309 return 0;
1310
1311err2:
1312 if (dssdev->platform_disable)
1313 dssdev->platform_disable(dssdev);
1314err1:
1315 omap_dss_stop_device(dssdev);
1316err0:
1317 mutex_unlock(&hdmi.lock);
1318 return r;
1319}
1320
1321void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
1322{
1323 DSSDBG("Enter hdmi_display_disable\n");
1324
1325 mutex_lock(&hdmi.lock);
1326
1327 hdmi_power_off(dssdev);
1328
1329 if (dssdev->platform_disable)
1330 dssdev->platform_disable(dssdev);
1331
1332 omap_dss_stop_device(dssdev);
1333
1334 mutex_unlock(&hdmi.lock);
1335}
1336
Ricardo Neri82335c42011-04-05 16:05:18 -05001337#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1338 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
Mythri P K95a8aeb2011-09-08 19:06:18 +05301339static void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
1340 struct hdmi_audio_format *aud_fmt)
Ricardo Neri82335c42011-04-05 16:05:18 -05001341{
1342 u32 r;
1343
1344 DSSDBG("Enter hdmi_wp_audio_config_format\n");
1345
Mythri P K95a8aeb2011-09-08 19:06:18 +05301346 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
Ricardo Neri82335c42011-04-05 16:05:18 -05001347 r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
1348 r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
1349 r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
1350 r = FLD_MOD(r, aud_fmt->type, 4, 4);
1351 r = FLD_MOD(r, aud_fmt->justification, 3, 3);
1352 r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
1353 r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
1354 r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301355 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001356}
1357
Mythri P K95a8aeb2011-09-08 19:06:18 +05301358static void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
1359 struct hdmi_audio_dma *aud_dma)
Ricardo Neri82335c42011-04-05 16:05:18 -05001360{
1361 u32 r;
1362
1363 DSSDBG("Enter hdmi_wp_audio_config_dma\n");
1364
Mythri P K95a8aeb2011-09-08 19:06:18 +05301365 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
Ricardo Neri82335c42011-04-05 16:05:18 -05001366 r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
1367 r = FLD_MOD(r, aud_dma->block_size, 7, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301368 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001369
Mythri P K95a8aeb2011-09-08 19:06:18 +05301370 r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001371 r = FLD_MOD(r, aud_dma->mode, 9, 9);
1372 r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301373 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001374}
1375
Mythri P K95a8aeb2011-09-08 19:06:18 +05301376static void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
1377 struct hdmi_core_audio_config *cfg)
Ricardo Neri82335c42011-04-05 16:05:18 -05001378{
1379 u32 r;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301380 void __iomem *av_base = hdmi_av_base(ip_data);
Ricardo Neri82335c42011-04-05 16:05:18 -05001381
1382 /* audio clock recovery parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301383 r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001384 r = FLD_MOD(r, cfg->use_mclk, 2, 2);
1385 r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
1386 r = FLD_MOD(r, cfg->cts_mode, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301387 hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001388
Mythri P K95a8aeb2011-09-08 19:06:18 +05301389 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
1390 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
1391 REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001392
1393 if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
Mythri P K95a8aeb2011-09-08 19:06:18 +05301394 REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
1395 REG_FLD_MOD(av_base,
1396 HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
1397 REG_FLD_MOD(av_base,
1398 HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001399 } else {
1400 /*
1401 * HDMI IP uses this configuration to divide the MCLK to
1402 * update CTS value.
1403 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301404 REG_FLD_MOD(av_base,
1405 HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001406
1407 /* Configure clock for audio packets */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301408 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
1409 cfg->aud_par_busclk, 7, 0);
1410 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
1411 (cfg->aud_par_busclk >> 8), 7, 0);
1412 REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
1413 (cfg->aud_par_busclk >> 16), 7, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001414 }
1415
1416 /* Override of SPDIF sample frequency with value in I2S_CHST4 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301417 REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
1418 cfg->fs_override, 1, 1);
Ricardo Neri82335c42011-04-05 16:05:18 -05001419
1420 /* I2S parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301421 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
1422 cfg->freq_sample, 3, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001423
Mythri P K95a8aeb2011-09-08 19:06:18 +05301424 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
Ricardo Neri82335c42011-04-05 16:05:18 -05001425 r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
1426 r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
1427 r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
1428 r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
1429 r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
1430 r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
1431 r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
1432 r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301433 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001434
Mythri P K95a8aeb2011-09-08 19:06:18 +05301435 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
Ricardo Neri82335c42011-04-05 16:05:18 -05001436 r = FLD_MOD(r, cfg->freq_sample, 7, 4);
1437 r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
1438 r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301439 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001440
Mythri P K95a8aeb2011-09-08 19:06:18 +05301441 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
1442 cfg->i2s_cfg.in_length_bits, 3, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001443
1444 /* Audio channels and mode parameters */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301445 REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
1446 r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
Ricardo Neri82335c42011-04-05 16:05:18 -05001447 r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
1448 r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
1449 r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
1450 r = FLD_MOD(r, cfg->en_spdif, 1, 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301451 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
Ricardo Neri82335c42011-04-05 16:05:18 -05001452}
1453
Mythri P K95a8aeb2011-09-08 19:06:18 +05301454static void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
Ricardo Neri82335c42011-04-05 16:05:18 -05001455 struct hdmi_core_infoframe_audio *info_aud)
1456{
1457 u8 val;
1458 u8 sum = 0, checksum = 0;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301459 void __iomem *av_base = hdmi_av_base(ip_data);
Ricardo Neri82335c42011-04-05 16:05:18 -05001460
1461 /*
1462 * Set audio info frame type, version and length as
1463 * described in HDMI 1.4a Section 8.2.2 specification.
1464 * Checksum calculation is defined in Section 5.3.5.
1465 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301466 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
1467 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
1468 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
Ricardo Neri82335c42011-04-05 16:05:18 -05001469 sum += 0x84 + 0x001 + 0x00a;
1470
1471 val = (info_aud->db1_coding_type << 4)
1472 | (info_aud->db1_channel_count - 1);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301473 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001474 sum += val;
1475
1476 val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301477 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001478 sum += val;
1479
Mythri P K95a8aeb2011-09-08 19:06:18 +05301480 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
Ricardo Neri82335c42011-04-05 16:05:18 -05001481
1482 val = info_aud->db4_channel_alloc;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301483 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001484 sum += val;
1485
1486 val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301487 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
Ricardo Neri82335c42011-04-05 16:05:18 -05001488 sum += val;
1489
Mythri P K95a8aeb2011-09-08 19:06:18 +05301490 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
1491 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
1492 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
1493 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
1494 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
Ricardo Neri82335c42011-04-05 16:05:18 -05001495
1496 checksum = 0x100 - sum;
Mythri P K95a8aeb2011-09-08 19:06:18 +05301497 hdmi_write_reg(av_base,
1498 HDMI_CORE_AV_AUDIO_CHSUM, checksum);
Ricardo Neri82335c42011-04-05 16:05:18 -05001499
1500 /*
1501 * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
1502 * is available.
1503 */
1504}
1505
Mythri P K95a8aeb2011-09-08 19:06:18 +05301506static int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
1507 u32 sample_freq, u32 *n, u32 *cts)
Ricardo Neri82335c42011-04-05 16:05:18 -05001508{
1509 u32 r;
1510 u32 deep_color = 0;
1511 u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
1512
1513 if (n == NULL || cts == NULL)
1514 return -EINVAL;
1515 /*
1516 * Obtain current deep color configuration. This needed
1517 * to calculate the TMDS clock based on the pixel clock.
1518 */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301519 r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
Ricardo Neri82335c42011-04-05 16:05:18 -05001520 switch (r) {
1521 case 1: /* No deep color selected */
1522 deep_color = 100;
1523 break;
1524 case 2: /* 10-bit deep color selected */
1525 deep_color = 125;
1526 break;
1527 case 3: /* 12-bit deep color selected */
1528 deep_color = 150;
1529 break;
1530 default:
1531 return -EINVAL;
1532 }
1533
1534 switch (sample_freq) {
1535 case 32000:
1536 if ((deep_color == 125) && ((pclk == 54054)
1537 || (pclk == 74250)))
1538 *n = 8192;
1539 else
1540 *n = 4096;
1541 break;
1542 case 44100:
1543 *n = 6272;
1544 break;
1545 case 48000:
1546 if ((deep_color == 125) && ((pclk == 54054)
1547 || (pclk == 74250)))
1548 *n = 8192;
1549 else
1550 *n = 6144;
1551 break;
1552 default:
1553 *n = 0;
1554 return -EINVAL;
1555 }
1556
1557 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
1558 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
1559
1560 return 0;
1561}
Ricardo Neriad44cc32011-05-18 22:31:56 -05001562
Mythri P K95a8aeb2011-09-08 19:06:18 +05301563static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
1564 struct snd_pcm_substream *substream,
Ricardo Neriad44cc32011-05-18 22:31:56 -05001565 struct snd_pcm_hw_params *params,
1566 struct snd_soc_dai *dai)
1567{
1568 struct hdmi_audio_format audio_format;
1569 struct hdmi_audio_dma audio_dma;
1570 struct hdmi_core_audio_config core_cfg;
1571 struct hdmi_core_infoframe_audio aud_if_cfg;
1572 int err, n, cts;
1573 enum hdmi_core_audio_sample_freq sample_freq;
1574
1575 switch (params_format(params)) {
1576 case SNDRV_PCM_FORMAT_S16_LE:
1577 core_cfg.i2s_cfg.word_max_length =
1578 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
1579 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
1580 core_cfg.i2s_cfg.in_length_bits =
1581 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
1582 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1583 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
1584 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
1585 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1586 audio_dma.transfer_size = 0x10;
1587 break;
1588 case SNDRV_PCM_FORMAT_S24_LE:
1589 core_cfg.i2s_cfg.word_max_length =
1590 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
1591 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
1592 core_cfg.i2s_cfg.in_length_bits =
1593 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
1594 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
1595 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
1596 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1597 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1598 audio_dma.transfer_size = 0x20;
1599 break;
1600 default:
1601 return -EINVAL;
1602 }
1603
1604 switch (params_rate(params)) {
1605 case 32000:
1606 sample_freq = HDMI_AUDIO_FS_32000;
1607 break;
1608 case 44100:
1609 sample_freq = HDMI_AUDIO_FS_44100;
1610 break;
1611 case 48000:
1612 sample_freq = HDMI_AUDIO_FS_48000;
1613 break;
1614 default:
1615 return -EINVAL;
1616 }
1617
Mythri P K95a8aeb2011-09-08 19:06:18 +05301618 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001619 if (err < 0)
1620 return err;
1621
1622 /* Audio wrapper config */
1623 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
1624 audio_format.active_chnnls_msk = 0x03;
1625 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
1626 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
1627 /* Disable start/stop signals of IEC 60958 blocks */
1628 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
1629
1630 audio_dma.block_size = 0xC0;
1631 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
1632 audio_dma.fifo_threshold = 0x20; /* in number of samples */
1633
Mythri P K95a8aeb2011-09-08 19:06:18 +05301634 hdmi_wp_audio_config_dma(ip_data, &audio_dma);
1635 hdmi_wp_audio_config_format(ip_data, &audio_format);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001636
1637 /*
1638 * I2S config
1639 */
1640 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
1641 /* Only used with high bitrate audio */
1642 core_cfg.i2s_cfg.cbit_order = false;
1643 /* Serial data and word select should change on sck rising edge */
1644 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
1645 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
1646 /* Set I2S word select polarity */
1647 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
1648 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
1649 /* Set serial data to word select shift. See Phillips spec. */
1650 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
1651 /* Enable one of the four available serial data channels */
1652 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
1653
1654 /* Core audio config */
1655 core_cfg.freq_sample = sample_freq;
1656 core_cfg.n = n;
1657 core_cfg.cts = cts;
1658 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
1659 core_cfg.aud_par_busclk = 0;
1660 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
1661 core_cfg.use_mclk = false;
1662 } else {
1663 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
1664 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
1665 core_cfg.use_mclk = true;
1666 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
1667 }
1668 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
1669 core_cfg.en_spdif = false;
1670 /* Use sample frequency from channel status word */
1671 core_cfg.fs_override = true;
1672 /* Enable ACR packets */
1673 core_cfg.en_acr_pkt = true;
1674 /* Disable direct streaming digital audio */
1675 core_cfg.en_dsd_audio = false;
1676 /* Use parallel audio interface */
1677 core_cfg.en_parallel_aud_input = true;
1678
Mythri P K95a8aeb2011-09-08 19:06:18 +05301679 hdmi_core_audio_config(ip_data, &core_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001680
1681 /*
1682 * Configure packet
1683 * info frame audio see doc CEA861-D page 74
1684 */
1685 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
1686 aud_if_cfg.db1_channel_count = 2;
1687 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
1688 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
1689 aud_if_cfg.db4_channel_alloc = 0x00;
1690 aud_if_cfg.db5_downmix_inh = false;
1691 aud_if_cfg.db5_lsv = 0;
1692
Mythri P K95a8aeb2011-09-08 19:06:18 +05301693 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001694 return 0;
1695}
1696
Mythri P K95a8aeb2011-09-08 19:06:18 +05301697static int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
1698 struct snd_pcm_substream *substream, int cmd,
1699 struct snd_soc_dai *dai)
Ricardo Neriad44cc32011-05-18 22:31:56 -05001700{
1701 int err = 0;
1702 switch (cmd) {
1703 case SNDRV_PCM_TRIGGER_START:
1704 case SNDRV_PCM_TRIGGER_RESUME:
1705 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Mythri P K95a8aeb2011-09-08 19:06:18 +05301706 REG_FLD_MOD(hdmi_av_base(ip_data),
1707 HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
1708 REG_FLD_MOD(hdmi_wp_base(ip_data),
1709 HDMI_WP_AUDIO_CTRL, 1, 31, 31);
1710 REG_FLD_MOD(hdmi_wp_base(ip_data),
1711 HDMI_WP_AUDIO_CTRL, 1, 30, 30);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001712 break;
1713
1714 case SNDRV_PCM_TRIGGER_STOP:
1715 case SNDRV_PCM_TRIGGER_SUSPEND:
1716 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Mythri P K95a8aeb2011-09-08 19:06:18 +05301717 REG_FLD_MOD(hdmi_av_base(ip_data),
1718 HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
1719 REG_FLD_MOD(hdmi_wp_base(ip_data),
1720 HDMI_WP_AUDIO_CTRL, 0, 30, 30);
1721 REG_FLD_MOD(hdmi_wp_base(ip_data),
1722 HDMI_WP_AUDIO_CTRL, 0, 31, 31);
Ricardo Neriad44cc32011-05-18 22:31:56 -05001723 break;
1724 default:
1725 err = -EINVAL;
1726 }
1727 return err;
1728}
1729
1730static int hdmi_audio_startup(struct snd_pcm_substream *substream,
1731 struct snd_soc_dai *dai)
1732{
1733 if (!hdmi.mode) {
1734 pr_err("Current video settings do not support audio.\n");
1735 return -EIO;
1736 }
1737 return 0;
1738}
1739
1740static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
1741};
1742
1743static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
1744 .hw_params = hdmi_audio_hw_params,
1745 .trigger = hdmi_audio_trigger,
1746 .startup = hdmi_audio_startup,
1747};
1748
1749static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
1750 .name = "hdmi-audio-codec",
1751 .playback = {
1752 .channels_min = 2,
1753 .channels_max = 2,
1754 .rates = SNDRV_PCM_RATE_32000 |
1755 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
1756 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1757 SNDRV_PCM_FMTBIT_S24_LE,
1758 },
1759 .ops = &hdmi_audio_codec_ops,
1760};
Ricardo Neri82335c42011-04-05 16:05:18 -05001761#endif
1762
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001763static int hdmi_get_clocks(struct platform_device *pdev)
1764{
1765 struct clk *clk;
1766
1767 clk = clk_get(&pdev->dev, "sys_clk");
1768 if (IS_ERR(clk)) {
1769 DSSERR("can't get sys_clk\n");
1770 return PTR_ERR(clk);
1771 }
1772
1773 hdmi.sys_clk = clk;
1774
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001775 return 0;
1776}
1777
1778static void hdmi_put_clocks(void)
1779{
1780 if (hdmi.sys_clk)
1781 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001782}
1783
Mythri P Kc3198a52011-03-12 12:04:27 +05301784/* HDMI HW IP initialisation */
1785static int omapdss_hdmihw_probe(struct platform_device *pdev)
1786{
1787 struct resource *hdmi_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001788 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301789
1790 hdmi.pdata = pdev->dev.platform_data;
1791 hdmi.pdev = pdev;
1792
1793 mutex_init(&hdmi.lock);
1794
1795 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1796 if (!hdmi_mem) {
1797 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1798 return -EINVAL;
1799 }
1800
1801 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301802 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
1803 resource_size(hdmi_mem));
1804 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +05301805 DSSERR("can't ioremap WP\n");
1806 return -ENOMEM;
1807 }
1808
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001809 r = hdmi_get_clocks(pdev);
1810 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +05301811 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001812 return r;
1813 }
1814
1815 pm_runtime_enable(&pdev->dev);
1816
Mythri P K95a8aeb2011-09-08 19:06:18 +05301817 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1818 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1819 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1820 hdmi.ip_data.phy_offset = HDMI_PHY;
1821
Mythri P Kc3198a52011-03-12 12:04:27 +05301822 hdmi_panel_init();
1823
Ricardo Neriad44cc32011-05-18 22:31:56 -05001824#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
1825 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
1826
1827 /* Register ASoC codec DAI */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001828 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
Ricardo Neriad44cc32011-05-18 22:31:56 -05001829 &hdmi_codec_dai_drv, 1);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001830 if (r) {
Ricardo Neriad44cc32011-05-18 22:31:56 -05001831 DSSERR("can't register ASoC HDMI audio codec\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001832 return r;
Ricardo Neriad44cc32011-05-18 22:31:56 -05001833 }
1834#endif
Mythri P Kc3198a52011-03-12 12:04:27 +05301835 return 0;
1836}
1837
1838static int omapdss_hdmihw_remove(struct platform_device *pdev)
1839{
1840 hdmi_panel_exit();
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 snd_soc_unregister_codec(&pdev->dev);
1845#endif
1846
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001847 pm_runtime_disable(&pdev->dev);
1848
1849 hdmi_put_clocks();
1850
Mythri P K95a8aeb2011-09-08 19:06:18 +05301851 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301852
1853 return 0;
1854}
1855
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001856static int hdmi_runtime_suspend(struct device *dev)
1857{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001858 clk_disable(hdmi.sys_clk);
1859
1860 dispc_runtime_put();
1861 dss_runtime_put();
1862
1863 return 0;
1864}
1865
1866static int hdmi_runtime_resume(struct device *dev)
1867{
1868 int r;
1869
1870 r = dss_runtime_get();
1871 if (r < 0)
1872 goto err_get_dss;
1873
1874 r = dispc_runtime_get();
1875 if (r < 0)
1876 goto err_get_dispc;
1877
1878
1879 clk_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001880
1881 return 0;
1882
1883err_get_dispc:
1884 dss_runtime_put();
1885err_get_dss:
1886 return r;
1887}
1888
1889static const struct dev_pm_ops hdmi_pm_ops = {
1890 .runtime_suspend = hdmi_runtime_suspend,
1891 .runtime_resume = hdmi_runtime_resume,
1892};
1893
Mythri P Kc3198a52011-03-12 12:04:27 +05301894static struct platform_driver omapdss_hdmihw_driver = {
1895 .probe = omapdss_hdmihw_probe,
1896 .remove = omapdss_hdmihw_remove,
1897 .driver = {
1898 .name = "omapdss_hdmi",
1899 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001900 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301901 },
1902};
1903
1904int hdmi_init_platform_driver(void)
1905{
1906 return platform_driver_register(&omapdss_hdmihw_driver);
1907}
1908
1909void hdmi_uninit_platform_driver(void)
1910{
1911 return platform_driver_unregister(&omapdss_hdmihw_driver);
1912}