blob: 7818670026622877ab957a291eb01ec195ea970e [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>
Mythri P K73341672011-09-08 19:06:24 +053040#include "ti_hdmi_4xxx_ip.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050041#endif
Mythri P Kc3198a52011-03-12 12:04:27 +053042
Mythri P K94c52982011-09-08 19:06:21 +053043#include "ti_hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053044#include "dss.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 K7c1f1ec2011-09-08 19:06:22 +053053/* HDMI EDID Length move this */
54#define HDMI_EDID_MAX_LENGTH 256
55#define EDID_TIMING_DESCRIPTOR_SIZE 0x12
56#define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
57#define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
58#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
59#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
60
61#define OMAP_HDMI_TIMINGS_NB 34
62
Tomi Valkeinenb44e4582011-08-22 13:16:24 +030063#define HDMI_DEFAULT_REGN 16
Tomi Valkeinen8d887672011-08-22 13:02:52 +030064#define HDMI_DEFAULT_REGM2 1
65
Mythri P Kc3198a52011-03-12 12:04:27 +053066static struct {
67 struct mutex lock;
68 struct omap_display_platform_data *pdata;
69 struct platform_device *pdev;
Mythri P K95a8aeb2011-09-08 19:06:18 +053070 struct hdmi_ip_data ip_data;
Mythri P Kc3198a52011-03-12 12:04:27 +053071 int code;
72 int mode;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030073
74 struct clk *sys_clk;
Mythri P Kc3198a52011-03-12 12:04:27 +053075} hdmi;
76
77/*
78 * Logic for the below structure :
79 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
80 * There is a correspondence between CEA/VESA timing and code, please
81 * refer to section 6.3 in HDMI 1.3 specification for timing code.
82 *
83 * In the below structure, cea_vesa_timings corresponds to all OMAP4
84 * supported CEA and VESA timing values.code_cea corresponds to the CEA
85 * code, It is used to get the timing from cea_vesa_timing array.Similarly
86 * with code_vesa. Code_index is used for back mapping, that is once EDID
87 * is read from the TV, EDID is parsed to find the timing values and then
88 * map it to corresponding CEA or VESA index.
89 */
90
91static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
92 { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
93 { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
94 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
95 { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
96 { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
97 { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
98 { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
99 { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
100 { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
101 { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
102 { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
103 { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
104 { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
105 { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
106 { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
107 /* VESA From Here */
108 { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
109 { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
110 { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
111 { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
112 { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
113 { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
114 { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
115 { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
116 { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
117 { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
118 { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
119 { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
120 { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
121 { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
122 { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
123 { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
124 { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
125 { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
126 { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
127};
128
129/*
130 * This is a static mapping array which maps the timing values
131 * with corresponding CEA / VESA code
132 */
133static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
134 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
135 /* <--15 CEA 17--> vesa*/
136 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
137 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
138};
139
140/*
141 * This is reverse static mapping which maps the CEA / VESA code
142 * to the corresponding timing values
143 */
144static const int code_cea[39] = {
145 -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
146 -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
147 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
148 11, 12, 14, -1, -1, 13, 13, 4, 4
149};
150
151static const int code_vesa[85] = {
152 -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
153 -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
154 -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
155 -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
156 -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
160 -1, 27, 28, -1, 33};
161
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300162static int hdmi_runtime_get(void)
163{
164 int r;
165
166 DSSDBG("hdmi_runtime_get\n");
167
168 r = pm_runtime_get_sync(&hdmi.pdev->dev);
169 WARN_ON(r < 0);
170 return r < 0 ? r : 0;
171}
172
173static void hdmi_runtime_put(void)
174{
175 int r;
176
177 DSSDBG("hdmi_runtime_put\n");
178
179 r = pm_runtime_put(&hdmi.pdev->dev);
180 WARN_ON(r < 0);
181}
182
Mythri P Kc3198a52011-03-12 12:04:27 +0530183int hdmi_init_display(struct omap_dss_device *dssdev)
184{
185 DSSDBG("init_display\n");
186
Mythri P K60634a22011-09-08 19:06:26 +0530187 dss_init_hdmi_ip_ops(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530188 return 0;
189}
190
Mythri P Kc3198a52011-03-12 12:04:27 +0530191static int get_timings_index(void)
192{
193 int code;
194
195 if (hdmi.mode == 0)
196 code = code_vesa[hdmi.code];
197 else
198 code = code_cea[hdmi.code];
199
200 if (code == -1) {
201 /* HDMI code 4 corresponds to 640 * 480 VGA */
202 hdmi.code = 4;
203 /* DVI mode 1 corresponds to HDMI 0 to DVI */
204 hdmi.mode = HDMI_DVI;
205
206 code = code_vesa[hdmi.code];
207 }
208 return code;
209}
210
211static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
212{
213 int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
214 int timing_vsync = 0, timing_hsync = 0;
Mythri P K38863b72011-09-08 19:06:20 +0530215 struct hdmi_video_timings temp;
Mythri P Kc3198a52011-03-12 12:04:27 +0530216 struct hdmi_cm cm = {-1};
217 DSSDBG("hdmi_get_code\n");
218
219 for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
220 temp = cea_vesa_timings[i].timings;
221 if ((temp.pixel_clock == timing->pixel_clock) &&
222 (temp.x_res == timing->x_res) &&
223 (temp.y_res == timing->y_res)) {
224
225 temp_hsync = temp.hfp + temp.hsw + temp.hbp;
226 timing_hsync = timing->hfp + timing->hsw + timing->hbp;
227 temp_vsync = temp.vfp + temp.vsw + temp.vbp;
228 timing_vsync = timing->vfp + timing->vsw + timing->vbp;
229
230 DSSDBG("temp_hsync = %d , temp_vsync = %d"
231 "timing_hsync = %d, timing_vsync = %d\n",
232 temp_hsync, temp_hsync,
233 timing_hsync, timing_vsync);
234
235 if ((temp_hsync == timing_hsync) &&
236 (temp_vsync == timing_vsync)) {
237 code = i;
238 cm.code = code_index[i];
239 if (code < 14)
240 cm.mode = HDMI_HDMI;
241 else
242 cm.mode = HDMI_DVI;
243 DSSDBG("Hdmi_code = %d mode = %d\n",
244 cm.code, cm.mode);
245 break;
246 }
247 }
248 }
249
250 return cm;
251}
252
Mythri P Kc3198a52011-03-12 12:04:27 +0530253static void update_hdmi_timings(struct hdmi_config *cfg,
254 struct omap_video_timings *timings, int code)
255{
256 cfg->timings.timings.x_res = timings->x_res;
257 cfg->timings.timings.y_res = timings->y_res;
258 cfg->timings.timings.hbp = timings->hbp;
259 cfg->timings.timings.hfp = timings->hfp;
260 cfg->timings.timings.hsw = timings->hsw;
261 cfg->timings.timings.vbp = timings->vbp;
262 cfg->timings.timings.vfp = timings->vfp;
263 cfg->timings.timings.vsw = timings->vsw;
264 cfg->timings.timings.pixel_clock = timings->pixel_clock;
265 cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
266 cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
267}
268
Archit Taneja6cb07b22011-04-12 13:52:25 +0530269static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
270 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530271{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530272 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530273 u32 mf;
274
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300275 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530276 /*
277 * Input clock is predivided by N + 1
278 * out put of which is reference clk
279 */
Tomi Valkeinen8d887672011-08-22 13:02:52 +0300280 if (dssdev->clocks.hdmi.regn == 0)
281 pi->regn = HDMI_DEFAULT_REGN;
282 else
283 pi->regn = dssdev->clocks.hdmi.regn;
284
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300285 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530286
287 /*
288 * multiplier is pixel_clk/ref_clk
289 * Multiplying by 100 to avoid fractional part removal
290 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530291 pi->regm = (phy * 100 / (refclk)) / 100;
Tomi Valkeinen8d887672011-08-22 13:02:52 +0300292
293 if (dssdev->clocks.hdmi.regm2 == 0)
294 pi->regm2 = HDMI_DEFAULT_REGM2;
295 else
296 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530297
298 /*
299 * fractional multiplier is remainder of the difference between
300 * multiplier and actual phy(required pixel clock thus should be
301 * multiplied by 2^18(262144) divided by the reference clock
302 */
303 mf = (phy - pi->regm * refclk) * 262144;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530304 pi->regmf = mf / (refclk);
Mythri P Kc3198a52011-03-12 12:04:27 +0530305
306 /*
307 * Dcofreq should be set to 1 if required pixel clock
308 * is greater than 1000MHz
309 */
310 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300311 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530312
Mythri P K7b27da52011-09-08 19:06:19 +0530313 /* Set the reference clock to sysclk reference */
314 pi->refsel = HDMI_REFSEL_SYSCLK;
315
Mythri P Kc3198a52011-03-12 12:04:27 +0530316 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
317 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
318}
319
Mythri P Kc3198a52011-03-12 12:04:27 +0530320static int hdmi_power_on(struct omap_dss_device *dssdev)
321{
322 int r, code = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530323 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530324 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +0530325
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300326 r = hdmi_runtime_get();
327 if (r)
328 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530329
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300330 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530331
332 p = &dssdev->panel.timings;
333
334 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
335 dssdev->panel.timings.x_res,
336 dssdev->panel.timings.y_res);
337
Mythri P Kc3198a52011-03-12 12:04:27 +0530338 code = get_timings_index();
Mythri P K7b27da52011-09-08 19:06:19 +0530339 update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
Mythri P Kc3198a52011-03-12 12:04:27 +0530340
Mythri P Kc3198a52011-03-12 12:04:27 +0530341 phy = p->pixel_clock;
342
Mythri P K7b27da52011-09-08 19:06:19 +0530343 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530344
Mythri P K60634a22011-09-08 19:06:26 +0530345 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530346
Mythri P K95a8aeb2011-09-08 19:06:18 +0530347 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530348 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530349 if (r) {
350 DSSDBG("Failed to lock PLL\n");
351 goto err;
352 }
353
Mythri P K60634a22011-09-08 19:06:26 +0530354 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530355 if (r) {
356 DSSDBG("Failed to start PHY\n");
357 goto err;
358 }
359
Mythri P K7b27da52011-09-08 19:06:19 +0530360 hdmi.ip_data.cfg.cm.mode = hdmi.mode;
361 hdmi.ip_data.cfg.cm.code = hdmi.code;
Mythri P K60634a22011-09-08 19:06:26 +0530362 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530363
364 /* Make selection of HDMI in DSS */
365 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
366
367 /* Select the dispc clock source as PRCM clock, to ensure that it is not
368 * DSI PLL source as the clock selected by DSI PLL might not be
369 * sufficient for the resolution selected / that can be changed
370 * dynamically by user. This can be moved to single location , say
371 * Boardfile.
372 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530373 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +0530374
375 /* bypass TV gamma table */
376 dispc_enable_gamma_table(0);
377
378 /* tv size */
379 dispc_set_digit_size(dssdev->panel.timings.x_res,
380 dssdev->panel.timings.y_res);
381
Mythri P K60634a22011-09-08 19:06:26 +0530382 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530383
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300384 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
385
Mythri P Kc3198a52011-03-12 12:04:27 +0530386 return 0;
387err:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300388 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +0530389 return -EIO;
390}
391
392static void hdmi_power_off(struct omap_dss_device *dssdev)
393{
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300394 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530395
Mythri P K60634a22011-09-08 19:06:26 +0530396 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
397 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
398 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300399 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +0530400}
401
402int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
403 struct omap_video_timings *timings)
404{
405 struct hdmi_cm cm;
406
407 cm = hdmi_get_code(timings);
408 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530409 return -EINVAL;
410 }
411
412 return 0;
413
414}
415
416void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
417{
418 struct hdmi_cm cm;
419
Mythri P Kc3198a52011-03-12 12:04:27 +0530420 cm = hdmi_get_code(&dssdev->panel.timings);
421 hdmi.code = cm.code;
422 hdmi.mode = cm.mode;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300423
424 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
425 int r;
426
427 hdmi_power_off(dssdev);
428
429 r = hdmi_power_on(dssdev);
430 if (r)
431 DSSERR("failed to power on device\n");
432 }
Mythri P Kc3198a52011-03-12 12:04:27 +0530433}
434
Tomi Valkeinen47024562011-08-25 17:12:56 +0300435int omapdss_hdmi_read_edid(u8 *buf, int len)
436{
437 int r;
438
439 mutex_lock(&hdmi.lock);
440
441 r = hdmi_runtime_get();
442 BUG_ON(r);
443
444 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
445
446 hdmi_runtime_put();
447 mutex_unlock(&hdmi.lock);
448
449 return r;
450}
451
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300452bool omapdss_hdmi_detect(void)
453{
454 int r;
455
456 mutex_lock(&hdmi.lock);
457
458 r = hdmi_runtime_get();
459 BUG_ON(r);
460
461 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
462
463 hdmi_runtime_put();
464 mutex_unlock(&hdmi.lock);
465
466 return r == 1;
467}
468
Mythri P Kc3198a52011-03-12 12:04:27 +0530469int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
470{
471 int r = 0;
472
473 DSSDBG("ENTER hdmi_display_enable\n");
474
475 mutex_lock(&hdmi.lock);
476
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300477 if (dssdev->manager == NULL) {
478 DSSERR("failed to enable display: no manager\n");
479 r = -ENODEV;
480 goto err0;
481 }
482
Mythri P Kc3198a52011-03-12 12:04:27 +0530483 r = omap_dss_start_device(dssdev);
484 if (r) {
485 DSSERR("failed to start device\n");
486 goto err0;
487 }
488
489 if (dssdev->platform_enable) {
490 r = dssdev->platform_enable(dssdev);
491 if (r) {
492 DSSERR("failed to enable GPIO's\n");
493 goto err1;
494 }
495 }
496
497 r = hdmi_power_on(dssdev);
498 if (r) {
499 DSSERR("failed to power on device\n");
500 goto err2;
501 }
502
503 mutex_unlock(&hdmi.lock);
504 return 0;
505
506err2:
507 if (dssdev->platform_disable)
508 dssdev->platform_disable(dssdev);
509err1:
510 omap_dss_stop_device(dssdev);
511err0:
512 mutex_unlock(&hdmi.lock);
513 return r;
514}
515
516void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
517{
518 DSSDBG("Enter hdmi_display_disable\n");
519
520 mutex_lock(&hdmi.lock);
521
522 hdmi_power_off(dssdev);
523
524 if (dssdev->platform_disable)
525 dssdev->platform_disable(dssdev);
526
527 omap_dss_stop_device(dssdev);
528
529 mutex_unlock(&hdmi.lock);
530}
531
Ricardo Neri82335c42011-04-05 16:05:18 -0500532#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
533 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
Ricardo Neriad44cc32011-05-18 22:31:56 -0500534
Mythri P K95a8aeb2011-09-08 19:06:18 +0530535static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
536 struct snd_pcm_substream *substream,
Ricardo Neriad44cc32011-05-18 22:31:56 -0500537 struct snd_pcm_hw_params *params,
538 struct snd_soc_dai *dai)
539{
540 struct hdmi_audio_format audio_format;
541 struct hdmi_audio_dma audio_dma;
542 struct hdmi_core_audio_config core_cfg;
543 struct hdmi_core_infoframe_audio aud_if_cfg;
544 int err, n, cts;
545 enum hdmi_core_audio_sample_freq sample_freq;
546
547 switch (params_format(params)) {
548 case SNDRV_PCM_FORMAT_S16_LE:
549 core_cfg.i2s_cfg.word_max_length =
550 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
551 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
552 core_cfg.i2s_cfg.in_length_bits =
553 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
554 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
555 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
556 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
557 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
558 audio_dma.transfer_size = 0x10;
559 break;
560 case SNDRV_PCM_FORMAT_S24_LE:
561 core_cfg.i2s_cfg.word_max_length =
562 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
563 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
564 core_cfg.i2s_cfg.in_length_bits =
565 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
566 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
567 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
568 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
569 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
570 audio_dma.transfer_size = 0x20;
571 break;
572 default:
573 return -EINVAL;
574 }
575
576 switch (params_rate(params)) {
577 case 32000:
578 sample_freq = HDMI_AUDIO_FS_32000;
579 break;
580 case 44100:
581 sample_freq = HDMI_AUDIO_FS_44100;
582 break;
583 case 48000:
584 sample_freq = HDMI_AUDIO_FS_48000;
585 break;
586 default:
587 return -EINVAL;
588 }
589
Mythri P K95a8aeb2011-09-08 19:06:18 +0530590 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500591 if (err < 0)
592 return err;
593
594 /* Audio wrapper config */
595 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
596 audio_format.active_chnnls_msk = 0x03;
597 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
598 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
599 /* Disable start/stop signals of IEC 60958 blocks */
600 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
601
602 audio_dma.block_size = 0xC0;
603 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
604 audio_dma.fifo_threshold = 0x20; /* in number of samples */
605
Mythri P K95a8aeb2011-09-08 19:06:18 +0530606 hdmi_wp_audio_config_dma(ip_data, &audio_dma);
607 hdmi_wp_audio_config_format(ip_data, &audio_format);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500608
609 /*
610 * I2S config
611 */
612 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
613 /* Only used with high bitrate audio */
614 core_cfg.i2s_cfg.cbit_order = false;
615 /* Serial data and word select should change on sck rising edge */
616 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
617 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
618 /* Set I2S word select polarity */
619 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
620 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
621 /* Set serial data to word select shift. See Phillips spec. */
622 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
623 /* Enable one of the four available serial data channels */
624 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
625
626 /* Core audio config */
627 core_cfg.freq_sample = sample_freq;
628 core_cfg.n = n;
629 core_cfg.cts = cts;
630 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
631 core_cfg.aud_par_busclk = 0;
632 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
633 core_cfg.use_mclk = false;
634 } else {
635 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
636 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
637 core_cfg.use_mclk = true;
638 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
639 }
640 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
641 core_cfg.en_spdif = false;
642 /* Use sample frequency from channel status word */
643 core_cfg.fs_override = true;
644 /* Enable ACR packets */
645 core_cfg.en_acr_pkt = true;
646 /* Disable direct streaming digital audio */
647 core_cfg.en_dsd_audio = false;
648 /* Use parallel audio interface */
649 core_cfg.en_parallel_aud_input = true;
650
Mythri P K95a8aeb2011-09-08 19:06:18 +0530651 hdmi_core_audio_config(ip_data, &core_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500652
653 /*
654 * Configure packet
655 * info frame audio see doc CEA861-D page 74
656 */
657 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
658 aud_if_cfg.db1_channel_count = 2;
659 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
660 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
661 aud_if_cfg.db4_channel_alloc = 0x00;
662 aud_if_cfg.db5_downmix_inh = false;
663 aud_if_cfg.db5_lsv = 0;
664
Mythri P K95a8aeb2011-09-08 19:06:18 +0530665 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500666 return 0;
667}
668
Ricardo Neriad44cc32011-05-18 22:31:56 -0500669static int hdmi_audio_startup(struct snd_pcm_substream *substream,
670 struct snd_soc_dai *dai)
671{
672 if (!hdmi.mode) {
673 pr_err("Current video settings do not support audio.\n");
674 return -EIO;
675 }
676 return 0;
677}
678
679static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
680};
681
682static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
683 .hw_params = hdmi_audio_hw_params,
684 .trigger = hdmi_audio_trigger,
685 .startup = hdmi_audio_startup,
686};
687
688static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
689 .name = "hdmi-audio-codec",
690 .playback = {
691 .channels_min = 2,
692 .channels_max = 2,
693 .rates = SNDRV_PCM_RATE_32000 |
694 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
695 .formats = SNDRV_PCM_FMTBIT_S16_LE |
696 SNDRV_PCM_FMTBIT_S24_LE,
697 },
698 .ops = &hdmi_audio_codec_ops,
699};
Ricardo Neri82335c42011-04-05 16:05:18 -0500700#endif
701
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300702static int hdmi_get_clocks(struct platform_device *pdev)
703{
704 struct clk *clk;
705
706 clk = clk_get(&pdev->dev, "sys_clk");
707 if (IS_ERR(clk)) {
708 DSSERR("can't get sys_clk\n");
709 return PTR_ERR(clk);
710 }
711
712 hdmi.sys_clk = clk;
713
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300714 return 0;
715}
716
717static void hdmi_put_clocks(void)
718{
719 if (hdmi.sys_clk)
720 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300721}
722
Mythri P Kc3198a52011-03-12 12:04:27 +0530723/* HDMI HW IP initialisation */
724static int omapdss_hdmihw_probe(struct platform_device *pdev)
725{
726 struct resource *hdmi_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300727 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530728
729 hdmi.pdata = pdev->dev.platform_data;
730 hdmi.pdev = pdev;
731
732 mutex_init(&hdmi.lock);
733
734 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
735 if (!hdmi_mem) {
736 DSSERR("can't get IORESOURCE_MEM HDMI\n");
737 return -EINVAL;
738 }
739
740 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530741 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
742 resource_size(hdmi_mem));
743 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530744 DSSERR("can't ioremap WP\n");
745 return -ENOMEM;
746 }
747
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300748 r = hdmi_get_clocks(pdev);
749 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530750 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300751 return r;
752 }
753
754 pm_runtime_enable(&pdev->dev);
755
Mythri P K95a8aeb2011-09-08 19:06:18 +0530756 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
757 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
758 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
759 hdmi.ip_data.phy_offset = HDMI_PHY;
760
Mythri P Kc3198a52011-03-12 12:04:27 +0530761 hdmi_panel_init();
762
Ricardo Neriad44cc32011-05-18 22:31:56 -0500763#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
764 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
765
766 /* Register ASoC codec DAI */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300767 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
Ricardo Neriad44cc32011-05-18 22:31:56 -0500768 &hdmi_codec_dai_drv, 1);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300769 if (r) {
Ricardo Neriad44cc32011-05-18 22:31:56 -0500770 DSSERR("can't register ASoC HDMI audio codec\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300771 return r;
Ricardo Neriad44cc32011-05-18 22:31:56 -0500772 }
773#endif
Mythri P Kc3198a52011-03-12 12:04:27 +0530774 return 0;
775}
776
777static int omapdss_hdmihw_remove(struct platform_device *pdev)
778{
779 hdmi_panel_exit();
780
Ricardo Neriad44cc32011-05-18 22:31:56 -0500781#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
782 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
783 snd_soc_unregister_codec(&pdev->dev);
784#endif
785
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300786 pm_runtime_disable(&pdev->dev);
787
788 hdmi_put_clocks();
789
Mythri P K95a8aeb2011-09-08 19:06:18 +0530790 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530791
792 return 0;
793}
794
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300795static int hdmi_runtime_suspend(struct device *dev)
796{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300797 clk_disable(hdmi.sys_clk);
798
799 dispc_runtime_put();
800 dss_runtime_put();
801
802 return 0;
803}
804
805static int hdmi_runtime_resume(struct device *dev)
806{
807 int r;
808
809 r = dss_runtime_get();
810 if (r < 0)
811 goto err_get_dss;
812
813 r = dispc_runtime_get();
814 if (r < 0)
815 goto err_get_dispc;
816
817
818 clk_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300819
820 return 0;
821
822err_get_dispc:
823 dss_runtime_put();
824err_get_dss:
825 return r;
826}
827
828static const struct dev_pm_ops hdmi_pm_ops = {
829 .runtime_suspend = hdmi_runtime_suspend,
830 .runtime_resume = hdmi_runtime_resume,
831};
832
Mythri P Kc3198a52011-03-12 12:04:27 +0530833static struct platform_driver omapdss_hdmihw_driver = {
834 .probe = omapdss_hdmihw_probe,
835 .remove = omapdss_hdmihw_remove,
836 .driver = {
837 .name = "omapdss_hdmi",
838 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300839 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +0530840 },
841};
842
843int hdmi_init_platform_driver(void)
844{
845 return platform_driver_register(&omapdss_hdmihw_driver);
846}
847
848void hdmi_uninit_platform_driver(void)
849{
850 return platform_driver_unregister(&omapdss_hdmihw_driver);
851}