blob: 8cef940b501015e60840d3008797ceb398b94c0b [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
Mythri P Kc3198a52011-03-12 12:04:27 +053063static struct {
64 struct mutex lock;
65 struct omap_display_platform_data *pdata;
66 struct platform_device *pdev;
Mythri P K95a8aeb2011-09-08 19:06:18 +053067 struct hdmi_ip_data ip_data;
Mythri P Kc3198a52011-03-12 12:04:27 +053068 int code;
69 int mode;
70 u8 edid[HDMI_EDID_MAX_LENGTH];
71 u8 edid_set;
72 bool custom_set;
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
162static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
163
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300164static int hdmi_runtime_get(void)
165{
166 int r;
167
168 DSSDBG("hdmi_runtime_get\n");
169
170 r = pm_runtime_get_sync(&hdmi.pdev->dev);
171 WARN_ON(r < 0);
172 return r < 0 ? r : 0;
173}
174
175static void hdmi_runtime_put(void)
176{
177 int r;
178
179 DSSDBG("hdmi_runtime_put\n");
180
181 r = pm_runtime_put(&hdmi.pdev->dev);
182 WARN_ON(r < 0);
183}
184
Mythri P Kc3198a52011-03-12 12:04:27 +0530185int hdmi_init_display(struct omap_dss_device *dssdev)
186{
187 DSSDBG("init_display\n");
188
Mythri P K60634a22011-09-08 19:06:26 +0530189 dss_init_hdmi_ip_ops(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530190 return 0;
191}
192
Mythri P K38863b72011-09-08 19:06:20 +0530193static void copy_hdmi_to_dss_timings(
194 const struct hdmi_video_timings *hdmi_timings,
195 struct omap_video_timings *timings)
196{
197 timings->x_res = hdmi_timings->x_res;
198 timings->y_res = hdmi_timings->y_res;
199 timings->pixel_clock = hdmi_timings->pixel_clock;
200 timings->hbp = hdmi_timings->hbp;
201 timings->hfp = hdmi_timings->hfp;
202 timings->hsw = hdmi_timings->hsw;
203 timings->vbp = hdmi_timings->vbp;
204 timings->vfp = hdmi_timings->vfp;
205 timings->vsw = hdmi_timings->vsw;
206}
207
Mythri P Kc3198a52011-03-12 12:04:27 +0530208static int get_timings_index(void)
209{
210 int code;
211
212 if (hdmi.mode == 0)
213 code = code_vesa[hdmi.code];
214 else
215 code = code_cea[hdmi.code];
216
217 if (code == -1) {
218 /* HDMI code 4 corresponds to 640 * 480 VGA */
219 hdmi.code = 4;
220 /* DVI mode 1 corresponds to HDMI 0 to DVI */
221 hdmi.mode = HDMI_DVI;
222
223 code = code_vesa[hdmi.code];
224 }
225 return code;
226}
227
228static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
229{
230 int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
231 int timing_vsync = 0, timing_hsync = 0;
Mythri P K38863b72011-09-08 19:06:20 +0530232 struct hdmi_video_timings temp;
Mythri P Kc3198a52011-03-12 12:04:27 +0530233 struct hdmi_cm cm = {-1};
234 DSSDBG("hdmi_get_code\n");
235
236 for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
237 temp = cea_vesa_timings[i].timings;
238 if ((temp.pixel_clock == timing->pixel_clock) &&
239 (temp.x_res == timing->x_res) &&
240 (temp.y_res == timing->y_res)) {
241
242 temp_hsync = temp.hfp + temp.hsw + temp.hbp;
243 timing_hsync = timing->hfp + timing->hsw + timing->hbp;
244 temp_vsync = temp.vfp + temp.vsw + temp.vbp;
245 timing_vsync = timing->vfp + timing->vsw + timing->vbp;
246
247 DSSDBG("temp_hsync = %d , temp_vsync = %d"
248 "timing_hsync = %d, timing_vsync = %d\n",
249 temp_hsync, temp_hsync,
250 timing_hsync, timing_vsync);
251
252 if ((temp_hsync == timing_hsync) &&
253 (temp_vsync == timing_vsync)) {
254 code = i;
255 cm.code = code_index[i];
256 if (code < 14)
257 cm.mode = HDMI_HDMI;
258 else
259 cm.mode = HDMI_DVI;
260 DSSDBG("Hdmi_code = %d mode = %d\n",
261 cm.code, cm.mode);
262 break;
263 }
264 }
265 }
266
267 return cm;
268}
269
270static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
271 struct omap_video_timings *timings)
272{
273 /* X and Y resolution */
274 timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
275 edid[current_descriptor_addrs + 2]);
276 timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
277 edid[current_descriptor_addrs + 5]);
278
279 timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
280 edid[current_descriptor_addrs]);
281
282 timings->pixel_clock = 10 * timings->pixel_clock;
283
284 /* HORIZONTAL FRONT PORCH */
285 timings->hfp = edid[current_descriptor_addrs + 8] |
286 ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
287 /* HORIZONTAL SYNC WIDTH */
288 timings->hsw = edid[current_descriptor_addrs + 9] |
289 ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
290 /* HORIZONTAL BACK PORCH */
291 timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
292 edid[current_descriptor_addrs + 3]) -
293 (timings->hfp + timings->hsw);
294 /* VERTICAL FRONT PORCH */
295 timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
296 ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
297 /* VERTICAL SYNC WIDTH */
298 timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
299 ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
300 /* VERTICAL BACK PORCH */
301 timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
302 edid[current_descriptor_addrs + 6]) -
303 (timings->vfp + timings->vsw);
304
305}
306
307/* Description : This function gets the resolution information from EDID */
308static void get_edid_timing_data(u8 *edid)
309{
310 u8 count;
311 u16 current_descriptor_addrs;
312 struct hdmi_cm cm;
313 struct omap_video_timings edid_timings;
314
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300315 /* search block 0, there are 4 DTDs arranged in priority order */
Mythri P Kc3198a52011-03-12 12:04:27 +0530316 for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
317 current_descriptor_addrs =
318 EDID_DESCRIPTOR_BLOCK0_ADDRESS +
319 count * EDID_TIMING_DESCRIPTOR_SIZE;
320 get_horz_vert_timing_info(current_descriptor_addrs,
321 edid, &edid_timings);
322 cm = hdmi_get_code(&edid_timings);
323 DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
324 count, cm.code, cm.mode);
325 if (cm.code == -1) {
326 continue;
327 } else {
328 hdmi.code = cm.code;
329 hdmi.mode = cm.mode;
330 DSSDBG("code = %d , mode = %d\n",
331 hdmi.code, hdmi.mode);
332 return;
333 }
334 }
335 if (edid[0x7e] != 0x00) {
336 for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
337 count++) {
338 current_descriptor_addrs =
339 EDID_DESCRIPTOR_BLOCK1_ADDRESS +
340 count * EDID_TIMING_DESCRIPTOR_SIZE;
341 get_horz_vert_timing_info(current_descriptor_addrs,
342 edid, &edid_timings);
343 cm = hdmi_get_code(&edid_timings);
344 DSSDBG("Block1[%d] value matches code = %d, mode = %d",
345 count, cm.code, cm.mode);
346 if (cm.code == -1) {
347 continue;
348 } else {
349 hdmi.code = cm.code;
350 hdmi.mode = cm.mode;
351 DSSDBG("code = %d , mode = %d\n",
352 hdmi.code, hdmi.mode);
353 return;
354 }
355 }
356 }
357
358 DSSINFO("no valid timing found , falling back to VGA\n");
359 hdmi.code = 4; /* setting default value of 640 480 VGA */
360 hdmi.mode = HDMI_DVI;
361}
362
363static void hdmi_read_edid(struct omap_video_timings *dp)
364{
365 int ret = 0, code;
366
367 memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
368
369 if (!hdmi.edid_set)
Mythri P K60634a22011-09-08 19:06:26 +0530370 ret = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, hdmi.edid,
Mythri P K95a8aeb2011-09-08 19:06:18 +0530371 HDMI_EDID_MAX_LENGTH);
Mythri P Kc3198a52011-03-12 12:04:27 +0530372 if (!ret) {
373 if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
374 /* search for timings of default resolution */
375 get_edid_timing_data(hdmi.edid);
376 hdmi.edid_set = true;
377 }
378 } else {
379 DSSWARN("failed to read E-EDID\n");
380 }
381
382 if (!hdmi.edid_set) {
383 DSSINFO("fallback to VGA\n");
384 hdmi.code = 4; /* setting default value of 640 480 VGA */
385 hdmi.mode = HDMI_DVI;
386 }
387
388 code = get_timings_index();
389
Mythri P K38863b72011-09-08 19:06:20 +0530390 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings, dp);
391
Mythri P Kc3198a52011-03-12 12:04:27 +0530392}
393
Mythri P Kc3198a52011-03-12 12:04:27 +0530394static void update_hdmi_timings(struct hdmi_config *cfg,
395 struct omap_video_timings *timings, int code)
396{
397 cfg->timings.timings.x_res = timings->x_res;
398 cfg->timings.timings.y_res = timings->y_res;
399 cfg->timings.timings.hbp = timings->hbp;
400 cfg->timings.timings.hfp = timings->hfp;
401 cfg->timings.timings.hsw = timings->hsw;
402 cfg->timings.timings.vbp = timings->vbp;
403 cfg->timings.timings.vfp = timings->vfp;
404 cfg->timings.timings.vsw = timings->vsw;
405 cfg->timings.timings.pixel_clock = timings->pixel_clock;
406 cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
407 cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
408}
409
Archit Taneja6cb07b22011-04-12 13:52:25 +0530410static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
411 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530412{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530413 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530414 u32 mf;
415
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300416 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530417 /*
418 * Input clock is predivided by N + 1
419 * out put of which is reference clk
420 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530421 pi->regn = dssdev->clocks.hdmi.regn;
422 refclk = clkin / (pi->regn + 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530423
424 /*
425 * multiplier is pixel_clk/ref_clk
426 * Multiplying by 100 to avoid fractional part removal
427 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530428 pi->regm = (phy * 100 / (refclk)) / 100;
429 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530430
431 /*
432 * fractional multiplier is remainder of the difference between
433 * multiplier and actual phy(required pixel clock thus should be
434 * multiplied by 2^18(262144) divided by the reference clock
435 */
436 mf = (phy - pi->regm * refclk) * 262144;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530437 pi->regmf = mf / (refclk);
Mythri P Kc3198a52011-03-12 12:04:27 +0530438
439 /*
440 * Dcofreq should be set to 1 if required pixel clock
441 * is greater than 1000MHz
442 */
443 pi->dcofreq = phy > 1000 * 100;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530444 pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530445
Mythri P K7b27da52011-09-08 19:06:19 +0530446 /* Set the reference clock to sysclk reference */
447 pi->refsel = HDMI_REFSEL_SYSCLK;
448
Mythri P Kc3198a52011-03-12 12:04:27 +0530449 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
450 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
451}
452
Mythri P Kc3198a52011-03-12 12:04:27 +0530453static int hdmi_power_on(struct omap_dss_device *dssdev)
454{
455 int r, code = 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530456 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530457 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +0530458
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300459 r = hdmi_runtime_get();
460 if (r)
461 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530462
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300463 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530464
465 p = &dssdev->panel.timings;
466
467 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
468 dssdev->panel.timings.x_res,
469 dssdev->panel.timings.y_res);
470
471 if (!hdmi.custom_set) {
472 DSSDBG("Read EDID as no EDID is not set on poweron\n");
473 hdmi_read_edid(p);
474 }
475 code = get_timings_index();
Mythri P K38863b72011-09-08 19:06:20 +0530476 copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings,
477 &dssdev->panel.timings);
Mythri P K7b27da52011-09-08 19:06:19 +0530478 update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
Mythri P Kc3198a52011-03-12 12:04:27 +0530479
Mythri P Kc3198a52011-03-12 12:04:27 +0530480 phy = p->pixel_clock;
481
Mythri P K7b27da52011-09-08 19:06:19 +0530482 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530483
Mythri P K60634a22011-09-08 19:06:26 +0530484 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530485
Mythri P K95a8aeb2011-09-08 19:06:18 +0530486 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530487 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530488 if (r) {
489 DSSDBG("Failed to lock PLL\n");
490 goto err;
491 }
492
Mythri P K60634a22011-09-08 19:06:26 +0530493 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530494 if (r) {
495 DSSDBG("Failed to start PHY\n");
496 goto err;
497 }
498
Mythri P K7b27da52011-09-08 19:06:19 +0530499 hdmi.ip_data.cfg.cm.mode = hdmi.mode;
500 hdmi.ip_data.cfg.cm.code = hdmi.code;
Mythri P K60634a22011-09-08 19:06:26 +0530501 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530502
503 /* Make selection of HDMI in DSS */
504 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
505
506 /* Select the dispc clock source as PRCM clock, to ensure that it is not
507 * DSI PLL source as the clock selected by DSI PLL might not be
508 * sufficient for the resolution selected / that can be changed
509 * dynamically by user. This can be moved to single location , say
510 * Boardfile.
511 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530512 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +0530513
514 /* bypass TV gamma table */
515 dispc_enable_gamma_table(0);
516
517 /* tv size */
518 dispc_set_digit_size(dssdev->panel.timings.x_res,
519 dssdev->panel.timings.y_res);
520
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300521 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530522
Mythri P K60634a22011-09-08 19:06:26 +0530523 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1);
Mythri P Kc3198a52011-03-12 12:04:27 +0530524
525 return 0;
526err:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300527 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +0530528 return -EIO;
529}
530
531static void hdmi_power_off(struct omap_dss_device *dssdev)
532{
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300533 dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530534
Mythri P K60634a22011-09-08 19:06:26 +0530535 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0);
536 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
537 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300538 hdmi_runtime_put();
Mythri P Kc3198a52011-03-12 12:04:27 +0530539
540 hdmi.edid_set = 0;
541}
542
543int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
544 struct omap_video_timings *timings)
545{
546 struct hdmi_cm cm;
547
548 cm = hdmi_get_code(timings);
549 if (cm.code == -1) {
550 DSSERR("Invalid timing entered\n");
551 return -EINVAL;
552 }
553
554 return 0;
555
556}
557
558void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
559{
560 struct hdmi_cm cm;
561
562 hdmi.custom_set = 1;
563 cm = hdmi_get_code(&dssdev->panel.timings);
564 hdmi.code = cm.code;
565 hdmi.mode = cm.mode;
566 omapdss_hdmi_display_enable(dssdev);
567 hdmi.custom_set = 0;
568}
569
570int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
571{
572 int r = 0;
573
574 DSSDBG("ENTER hdmi_display_enable\n");
575
576 mutex_lock(&hdmi.lock);
577
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300578 if (dssdev->manager == NULL) {
579 DSSERR("failed to enable display: no manager\n");
580 r = -ENODEV;
581 goto err0;
582 }
583
Mythri P Kc3198a52011-03-12 12:04:27 +0530584 r = omap_dss_start_device(dssdev);
585 if (r) {
586 DSSERR("failed to start device\n");
587 goto err0;
588 }
589
590 if (dssdev->platform_enable) {
591 r = dssdev->platform_enable(dssdev);
592 if (r) {
593 DSSERR("failed to enable GPIO's\n");
594 goto err1;
595 }
596 }
597
598 r = hdmi_power_on(dssdev);
599 if (r) {
600 DSSERR("failed to power on device\n");
601 goto err2;
602 }
603
604 mutex_unlock(&hdmi.lock);
605 return 0;
606
607err2:
608 if (dssdev->platform_disable)
609 dssdev->platform_disable(dssdev);
610err1:
611 omap_dss_stop_device(dssdev);
612err0:
613 mutex_unlock(&hdmi.lock);
614 return r;
615}
616
617void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
618{
619 DSSDBG("Enter hdmi_display_disable\n");
620
621 mutex_lock(&hdmi.lock);
622
623 hdmi_power_off(dssdev);
624
625 if (dssdev->platform_disable)
626 dssdev->platform_disable(dssdev);
627
628 omap_dss_stop_device(dssdev);
629
630 mutex_unlock(&hdmi.lock);
631}
632
Ricardo Neri82335c42011-04-05 16:05:18 -0500633#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
634 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
Ricardo Neriad44cc32011-05-18 22:31:56 -0500635
Mythri P K95a8aeb2011-09-08 19:06:18 +0530636static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
637 struct snd_pcm_substream *substream,
Ricardo Neriad44cc32011-05-18 22:31:56 -0500638 struct snd_pcm_hw_params *params,
639 struct snd_soc_dai *dai)
640{
641 struct hdmi_audio_format audio_format;
642 struct hdmi_audio_dma audio_dma;
643 struct hdmi_core_audio_config core_cfg;
644 struct hdmi_core_infoframe_audio aud_if_cfg;
645 int err, n, cts;
646 enum hdmi_core_audio_sample_freq sample_freq;
647
648 switch (params_format(params)) {
649 case SNDRV_PCM_FORMAT_S16_LE:
650 core_cfg.i2s_cfg.word_max_length =
651 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
652 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
653 core_cfg.i2s_cfg.in_length_bits =
654 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
655 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
656 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
657 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
658 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
659 audio_dma.transfer_size = 0x10;
660 break;
661 case SNDRV_PCM_FORMAT_S24_LE:
662 core_cfg.i2s_cfg.word_max_length =
663 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
664 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
665 core_cfg.i2s_cfg.in_length_bits =
666 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
667 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
668 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
669 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
670 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
671 audio_dma.transfer_size = 0x20;
672 break;
673 default:
674 return -EINVAL;
675 }
676
677 switch (params_rate(params)) {
678 case 32000:
679 sample_freq = HDMI_AUDIO_FS_32000;
680 break;
681 case 44100:
682 sample_freq = HDMI_AUDIO_FS_44100;
683 break;
684 case 48000:
685 sample_freq = HDMI_AUDIO_FS_48000;
686 break;
687 default:
688 return -EINVAL;
689 }
690
Mythri P K95a8aeb2011-09-08 19:06:18 +0530691 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500692 if (err < 0)
693 return err;
694
695 /* Audio wrapper config */
696 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
697 audio_format.active_chnnls_msk = 0x03;
698 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
699 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
700 /* Disable start/stop signals of IEC 60958 blocks */
701 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
702
703 audio_dma.block_size = 0xC0;
704 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
705 audio_dma.fifo_threshold = 0x20; /* in number of samples */
706
Mythri P K95a8aeb2011-09-08 19:06:18 +0530707 hdmi_wp_audio_config_dma(ip_data, &audio_dma);
708 hdmi_wp_audio_config_format(ip_data, &audio_format);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500709
710 /*
711 * I2S config
712 */
713 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
714 /* Only used with high bitrate audio */
715 core_cfg.i2s_cfg.cbit_order = false;
716 /* Serial data and word select should change on sck rising edge */
717 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
718 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
719 /* Set I2S word select polarity */
720 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
721 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
722 /* Set serial data to word select shift. See Phillips spec. */
723 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
724 /* Enable one of the four available serial data channels */
725 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
726
727 /* Core audio config */
728 core_cfg.freq_sample = sample_freq;
729 core_cfg.n = n;
730 core_cfg.cts = cts;
731 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
732 core_cfg.aud_par_busclk = 0;
733 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
734 core_cfg.use_mclk = false;
735 } else {
736 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
737 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
738 core_cfg.use_mclk = true;
739 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
740 }
741 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
742 core_cfg.en_spdif = false;
743 /* Use sample frequency from channel status word */
744 core_cfg.fs_override = true;
745 /* Enable ACR packets */
746 core_cfg.en_acr_pkt = true;
747 /* Disable direct streaming digital audio */
748 core_cfg.en_dsd_audio = false;
749 /* Use parallel audio interface */
750 core_cfg.en_parallel_aud_input = true;
751
Mythri P K95a8aeb2011-09-08 19:06:18 +0530752 hdmi_core_audio_config(ip_data, &core_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500753
754 /*
755 * Configure packet
756 * info frame audio see doc CEA861-D page 74
757 */
758 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
759 aud_if_cfg.db1_channel_count = 2;
760 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
761 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
762 aud_if_cfg.db4_channel_alloc = 0x00;
763 aud_if_cfg.db5_downmix_inh = false;
764 aud_if_cfg.db5_lsv = 0;
765
Mythri P K95a8aeb2011-09-08 19:06:18 +0530766 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
Ricardo Neriad44cc32011-05-18 22:31:56 -0500767 return 0;
768}
769
Ricardo Neriad44cc32011-05-18 22:31:56 -0500770static int hdmi_audio_startup(struct snd_pcm_substream *substream,
771 struct snd_soc_dai *dai)
772{
773 if (!hdmi.mode) {
774 pr_err("Current video settings do not support audio.\n");
775 return -EIO;
776 }
777 return 0;
778}
779
780static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
781};
782
783static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
784 .hw_params = hdmi_audio_hw_params,
785 .trigger = hdmi_audio_trigger,
786 .startup = hdmi_audio_startup,
787};
788
789static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
790 .name = "hdmi-audio-codec",
791 .playback = {
792 .channels_min = 2,
793 .channels_max = 2,
794 .rates = SNDRV_PCM_RATE_32000 |
795 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
796 .formats = SNDRV_PCM_FMTBIT_S16_LE |
797 SNDRV_PCM_FMTBIT_S24_LE,
798 },
799 .ops = &hdmi_audio_codec_ops,
800};
Ricardo Neri82335c42011-04-05 16:05:18 -0500801#endif
802
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300803static int hdmi_get_clocks(struct platform_device *pdev)
804{
805 struct clk *clk;
806
807 clk = clk_get(&pdev->dev, "sys_clk");
808 if (IS_ERR(clk)) {
809 DSSERR("can't get sys_clk\n");
810 return PTR_ERR(clk);
811 }
812
813 hdmi.sys_clk = clk;
814
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300815 return 0;
816}
817
818static void hdmi_put_clocks(void)
819{
820 if (hdmi.sys_clk)
821 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300822}
823
Mythri P Kc3198a52011-03-12 12:04:27 +0530824/* HDMI HW IP initialisation */
825static int omapdss_hdmihw_probe(struct platform_device *pdev)
826{
827 struct resource *hdmi_mem;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300828 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530829
830 hdmi.pdata = pdev->dev.platform_data;
831 hdmi.pdev = pdev;
832
833 mutex_init(&hdmi.lock);
834
835 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
836 if (!hdmi_mem) {
837 DSSERR("can't get IORESOURCE_MEM HDMI\n");
838 return -EINVAL;
839 }
840
841 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530842 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
843 resource_size(hdmi_mem));
844 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530845 DSSERR("can't ioremap WP\n");
846 return -ENOMEM;
847 }
848
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300849 r = hdmi_get_clocks(pdev);
850 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530851 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300852 return r;
853 }
854
855 pm_runtime_enable(&pdev->dev);
856
Mythri P K95a8aeb2011-09-08 19:06:18 +0530857 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
858 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
859 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
860 hdmi.ip_data.phy_offset = HDMI_PHY;
861
Mythri P Kc3198a52011-03-12 12:04:27 +0530862 hdmi_panel_init();
863
Ricardo Neriad44cc32011-05-18 22:31:56 -0500864#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
865 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
866
867 /* Register ASoC codec DAI */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300868 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
Ricardo Neriad44cc32011-05-18 22:31:56 -0500869 &hdmi_codec_dai_drv, 1);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300870 if (r) {
Ricardo Neriad44cc32011-05-18 22:31:56 -0500871 DSSERR("can't register ASoC HDMI audio codec\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300872 return r;
Ricardo Neriad44cc32011-05-18 22:31:56 -0500873 }
874#endif
Mythri P Kc3198a52011-03-12 12:04:27 +0530875 return 0;
876}
877
878static int omapdss_hdmihw_remove(struct platform_device *pdev)
879{
880 hdmi_panel_exit();
881
Ricardo Neriad44cc32011-05-18 22:31:56 -0500882#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
883 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
884 snd_soc_unregister_codec(&pdev->dev);
885#endif
886
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300887 pm_runtime_disable(&pdev->dev);
888
889 hdmi_put_clocks();
890
Mythri P K95a8aeb2011-09-08 19:06:18 +0530891 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530892
893 return 0;
894}
895
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300896static int hdmi_runtime_suspend(struct device *dev)
897{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300898 clk_disable(hdmi.sys_clk);
899
900 dispc_runtime_put();
901 dss_runtime_put();
902
903 return 0;
904}
905
906static int hdmi_runtime_resume(struct device *dev)
907{
908 int r;
909
910 r = dss_runtime_get();
911 if (r < 0)
912 goto err_get_dss;
913
914 r = dispc_runtime_get();
915 if (r < 0)
916 goto err_get_dispc;
917
918
919 clk_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300920
921 return 0;
922
923err_get_dispc:
924 dss_runtime_put();
925err_get_dss:
926 return r;
927}
928
929static const struct dev_pm_ops hdmi_pm_ops = {
930 .runtime_suspend = hdmi_runtime_suspend,
931 .runtime_resume = hdmi_runtime_resume,
932};
933
Mythri P Kc3198a52011-03-12 12:04:27 +0530934static struct platform_driver omapdss_hdmihw_driver = {
935 .probe = omapdss_hdmihw_probe,
936 .remove = omapdss_hdmihw_remove,
937 .driver = {
938 .name = "omapdss_hdmi",
939 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300940 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +0530941 },
942};
943
944int hdmi_init_platform_driver(void)
945{
946 return platform_driver_register(&omapdss_hdmihw_driver);
947}
948
949void hdmi_uninit_platform_driver(void)
950{
951 return platform_driver_unregister(&omapdss_hdmihw_driver);
952}