OMAPDSS: HDMI: split power_on/off to two parts
[deliverable/linux.git] / drivers / video / omap2 / dss / hdmi.c
CommitLineData
c3198a5e
M
1/*
2 * hdmi.c
3 *
4 * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
6 * Authors: Yong Zhi
7 * Mythri pk <mythripk@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#define DSS_SUBSYS_NAME "HDMI"
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/interrupt.h>
29#include <linux/mutex.h>
30#include <linux/delay.h>
31#include <linux/string.h>
24e6289c 32#include <linux/platform_device.h>
4fbafaf3
TV
33#include <linux/pm_runtime.h>
34#include <linux/clk.h>
cca35017 35#include <linux/gpio.h>
17486943 36#include <linux/regulator/consumer.h>
a0b38cc4 37#include <video/omapdss.h>
c3198a5e 38
94c52987 39#include "ti_hdmi.h"
c3198a5e 40#include "dss.h"
ad44cc32 41#include "dss_features.h"
c3198a5e 42
95a8aeb6
M
43#define HDMI_WP 0x0
44#define HDMI_CORE_SYS 0x400
45#define HDMI_CORE_AV 0x900
46#define HDMI_PLLCTRL 0x200
47#define HDMI_PHY 0x300
48
7c1f1eca
M
49/* HDMI EDID Length move this */
50#define HDMI_EDID_MAX_LENGTH 256
51#define EDID_TIMING_DESCRIPTOR_SIZE 0x12
52#define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
53#define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
54#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
55#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
56
b44e4582 57#define HDMI_DEFAULT_REGN 16
8d88767a
TV
58#define HDMI_DEFAULT_REGM2 1
59
c3198a5e
M
60static struct {
61 struct mutex lock;
c3198a5e 62 struct platform_device *pdev;
95a8aeb6 63 struct hdmi_ip_data ip_data;
4fbafaf3
TV
64
65 struct clk *sys_clk;
17486943 66 struct regulator *vdda_hdmi_dac_reg;
cca35017
TV
67
68 int ct_cp_hpd_gpio;
69 int ls_oe_gpio;
70 int hpd_gpio;
81b87f51
AT
71
72 struct omap_dss_output output;
c3198a5e
M
73} hdmi;
74
75/*
76 * Logic for the below structure :
77 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
78 * There is a correspondence between CEA/VESA timing and code, please
79 * refer to section 6.3 in HDMI 1.3 specification for timing code.
80 *
81 * In the below structure, cea_vesa_timings corresponds to all OMAP4
82 * supported CEA and VESA timing values.code_cea corresponds to the CEA
83 * code, It is used to get the timing from cea_vesa_timing array.Similarly
84 * with code_vesa. Code_index is used for back mapping, that is once EDID
85 * is read from the TV, EDID is parsed to find the timing values and then
86 * map it to corresponding CEA or VESA index.
87 */
88
46095b2d 89static const struct hdmi_config cea_timings[] = {
cc937e5e
AT
90 {
91 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
92 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
93 false, },
94 { 1, HDMI_HDMI },
95 },
96 {
97 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
98 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
99 false, },
100 { 2, HDMI_HDMI },
101 },
102 {
103 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
104 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
105 false, },
106 { 4, HDMI_HDMI },
107 },
108 {
109 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
110 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
111 true, },
112 { 5, HDMI_HDMI },
113 },
114 {
115 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
116 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
117 true, },
118 { 6, HDMI_HDMI },
119 },
120 {
121 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
122 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
123 false, },
124 { 16, HDMI_HDMI },
125 },
126 {
127 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
128 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
129 false, },
130 { 17, HDMI_HDMI },
131 },
132 {
133 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
134 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
135 false, },
136 { 19, HDMI_HDMI },
137 },
138 {
139 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
140 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
141 true, },
142 { 20, HDMI_HDMI },
143 },
144 {
145 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
146 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
147 true, },
148 { 21, HDMI_HDMI },
149 },
150 {
151 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
152 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
153 false, },
154 { 29, HDMI_HDMI },
155 },
156 {
157 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
158 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
159 false, },
160 { 31, HDMI_HDMI },
161 },
162 {
163 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
164 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
165 false, },
166 { 32, HDMI_HDMI },
167 },
168 {
169 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
170 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
171 false, },
172 { 35, HDMI_HDMI },
173 },
174 {
175 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
176 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
177 false, },
178 { 37, HDMI_HDMI },
179 },
46095b2d 180};
cc937e5e 181
46095b2d 182static const struct hdmi_config vesa_timings[] = {
a05ce78f 183/* VESA From Here */
cc937e5e
AT
184 {
185 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
186 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
187 false, },
188 { 4, HDMI_DVI },
189 },
190 {
191 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
192 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
193 false, },
194 { 9, HDMI_DVI },
195 },
196 {
197 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
198 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
199 false, },
200 { 0xE, HDMI_DVI },
201 },
202 {
203 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
204 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
205 false, },
206 { 0x17, HDMI_DVI },
207 },
208 {
209 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
210 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
211 false, },
212 { 0x1C, HDMI_DVI },
213 },
214 {
215 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
216 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
217 false, },
218 { 0x27, HDMI_DVI },
219 },
220 {
221 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
222 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
223 false, },
224 { 0x20, HDMI_DVI },
225 },
226 {
227 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
228 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
229 false, },
230 { 0x23, HDMI_DVI },
231 },
232 {
233 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
234 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
235 false, },
236 { 0x10, HDMI_DVI },
237 },
238 {
239 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
240 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
241 false, },
242 { 0x2A, HDMI_DVI },
243 },
244 {
245 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
246 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
247 false, },
248 { 0x2F, HDMI_DVI },
249 },
250 {
251 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
252 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
253 false, },
254 { 0x3A, HDMI_DVI },
255 },
256 {
257 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
258 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
259 false, },
260 { 0x51, HDMI_DVI },
261 },
262 {
263 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
264 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
265 false, },
266 { 0x52, HDMI_DVI },
267 },
268 {
269 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
270 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
271 false, },
272 { 0x16, HDMI_DVI },
273 },
274 {
275 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
276 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
277 false, },
278 { 0x29, HDMI_DVI },
279 },
280 {
281 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
282 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
283 false, },
284 { 0x39, HDMI_DVI },
285 },
286 {
287 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
288 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
289 false, },
290 { 0x1B, HDMI_DVI },
291 },
292 {
293 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
294 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
295 false, },
296 { 0x55, HDMI_DVI },
297 },
c3198a5e
M
298};
299
4fbafaf3
TV
300static int hdmi_runtime_get(void)
301{
302 int r;
303
304 DSSDBG("hdmi_runtime_get\n");
305
306 r = pm_runtime_get_sync(&hdmi.pdev->dev);
307 WARN_ON(r < 0);
a247ce78 308 if (r < 0)
852f0838 309 return r;
a247ce78
AT
310
311 return 0;
4fbafaf3
TV
312}
313
314static void hdmi_runtime_put(void)
315{
316 int r;
317
318 DSSDBG("hdmi_runtime_put\n");
319
0eaf9f52 320 r = pm_runtime_put_sync(&hdmi.pdev->dev);
5be3aebd 321 WARN_ON(r < 0 && r != -ENOSYS);
4fbafaf3
TV
322}
323
9d8232a7 324static int __init hdmi_init_display(struct omap_dss_device *dssdev)
c3198a5e 325{
cca35017
TV
326 int r;
327
328 struct gpio gpios[] = {
329 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
330 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
331 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
332 };
333
c3198a5e
M
334 DSSDBG("init_display\n");
335
b2c7d54f 336 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
cca35017 337
17486943
TV
338 if (hdmi.vdda_hdmi_dac_reg == NULL) {
339 struct regulator *reg;
340
341 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
342
343 if (IS_ERR(reg)) {
344 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
345 return PTR_ERR(reg);
346 }
347
348 hdmi.vdda_hdmi_dac_reg = reg;
349 }
350
cca35017
TV
351 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
352 if (r)
353 return r;
354
c3198a5e
M
355 return 0;
356}
357
cca35017
TV
358static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev)
359{
360 DSSDBG("uninit_display\n");
361
362 gpio_free(hdmi.ct_cp_hpd_gpio);
363 gpio_free(hdmi.ls_oe_gpio);
364 gpio_free(hdmi.hpd_gpio);
365}
366
46095b2d
M
367static const struct hdmi_config *hdmi_find_timing(
368 const struct hdmi_config *timings_arr,
369 int len)
c3198a5e 370{
46095b2d 371 int i;
c3198a5e 372
46095b2d 373 for (i = 0; i < len; i++) {
9e4ed603 374 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
46095b2d
M
375 return &timings_arr[i];
376 }
377 return NULL;
378}
c3198a5e 379
46095b2d
M
380static const struct hdmi_config *hdmi_get_timings(void)
381{
382 const struct hdmi_config *arr;
383 int len;
384
9e4ed603 385 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
46095b2d
M
386 arr = vesa_timings;
387 len = ARRAY_SIZE(vesa_timings);
388 } else {
389 arr = cea_timings;
390 len = ARRAY_SIZE(cea_timings);
391 }
392
393 return hdmi_find_timing(arr, len);
394}
395
396static bool hdmi_timings_compare(struct omap_video_timings *timing1,
cc937e5e 397 const struct omap_video_timings *timing2)
46095b2d
M
398{
399 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
400
401 if ((timing2->pixel_clock == timing1->pixel_clock) &&
402 (timing2->x_res == timing1->x_res) &&
403 (timing2->y_res == timing1->y_res)) {
c3198a5e 404
46095b2d
M
405 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
406 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
407 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
408 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
409
410 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
411 "timing2_hsync = %d timing2_vsync = %d\n",
412 timing1_hsync, timing1_vsync,
413 timing2_hsync, timing2_vsync);
414
415 if ((timing1_hsync == timing2_hsync) &&
416 (timing1_vsync == timing2_vsync)) {
417 return true;
418 }
c3198a5e 419 }
46095b2d 420 return false;
c3198a5e
M
421}
422
423static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
424{
46095b2d 425 int i;
c3198a5e
M
426 struct hdmi_cm cm = {-1};
427 DSSDBG("hdmi_get_code\n");
428
46095b2d
M
429 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
430 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
431 cm = cea_timings[i].cm;
432 goto end;
433 }
434 }
435 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
436 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
437 cm = vesa_timings[i].cm;
438 goto end;
c3198a5e
M
439 }
440 }
441
46095b2d 442end: return cm;
c3198a5e 443
c3198a5e
M
444}
445
c3dc6a7a
AT
446unsigned long hdmi_get_pixel_clock(void)
447{
448 /* HDMI Pixel Clock in Mhz */
a05ce78f 449 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
c3dc6a7a
AT
450}
451
6cb07b25
AT
452static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
453 struct hdmi_pll_info *pi)
c3198a5e 454{
6cb07b25 455 unsigned long clkin, refclk;
c3198a5e
M
456 u32 mf;
457
4fbafaf3 458 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
c3198a5e
M
459 /*
460 * Input clock is predivided by N + 1
461 * out put of which is reference clk
462 */
8d88767a
TV
463 if (dssdev->clocks.hdmi.regn == 0)
464 pi->regn = HDMI_DEFAULT_REGN;
465 else
466 pi->regn = dssdev->clocks.hdmi.regn;
467
b44e4582 468 refclk = clkin / pi->regn;
c3198a5e 469
8d88767a
TV
470 if (dssdev->clocks.hdmi.regm2 == 0)
471 pi->regm2 = HDMI_DEFAULT_REGM2;
472 else
473 pi->regm2 = dssdev->clocks.hdmi.regm2;
c3198a5e 474
dd2116a3
M
475 /*
476 * multiplier is pixel_clk/ref_clk
477 * Multiplying by 100 to avoid fractional part removal
478 */
479 pi->regm = phy * pi->regm2 / refclk;
480
c3198a5e
M
481 /*
482 * fractional multiplier is remainder of the difference between
483 * multiplier and actual phy(required pixel clock thus should be
484 * multiplied by 2^18(262144) divided by the reference clock
485 */
dd2116a3
M
486 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
487 pi->regmf = pi->regm2 * mf / refclk;
c3198a5e
M
488
489 /*
490 * Dcofreq should be set to 1 if required pixel clock
491 * is greater than 1000MHz
492 */
493 pi->dcofreq = phy > 1000 * 100;
b44e4582 494 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
c3198a5e 495
7b27da54
M
496 /* Set the reference clock to sysclk reference */
497 pi->refsel = HDMI_REFSEL_SYSCLK;
498
c3198a5e
M
499 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
500 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
501}
502
bb426fc9 503static int hdmi_power_on_core(struct omap_dss_device *dssdev)
c3198a5e 504{
46095b2d 505 int r;
c3198a5e 506
cca35017
TV
507 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
508 gpio_set_value(hdmi.ls_oe_gpio, 1);
509
a84b2065
TV
510 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
511 udelay(300);
512
17486943
TV
513 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
514 if (r)
515 goto err_vdac_enable;
516
4fbafaf3
TV
517 r = hdmi_runtime_get();
518 if (r)
cca35017 519 goto err_runtime_get;
c3198a5e 520
bb426fc9
TV
521 /* Make selection of HDMI in DSS */
522 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
523
524 /* Select the dispc clock source as PRCM clock, to ensure that it is not
525 * DSI PLL source as the clock selected by DSI PLL might not be
526 * sufficient for the resolution selected / that can be changed
527 * dynamically by user. This can be moved to single location , say
528 * Boardfile.
529 */
530 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
531
532 return 0;
533
534err_runtime_get:
535 regulator_disable(hdmi.vdda_hdmi_dac_reg);
536err_vdac_enable:
537 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
538 gpio_set_value(hdmi.ls_oe_gpio, 0);
539 return r;
540}
541
542static void hdmi_power_off_core(struct omap_dss_device *dssdev)
543{
544 hdmi_runtime_put();
545 regulator_disable(hdmi.vdda_hdmi_dac_reg);
546 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
547 gpio_set_value(hdmi.ls_oe_gpio, 0);
548}
549
550static int hdmi_power_on_full(struct omap_dss_device *dssdev)
551{
552 int r;
553 struct omap_video_timings *p;
554 struct omap_overlay_manager *mgr = dssdev->output->manager;
555 unsigned long phy;
556
557 r = hdmi_power_on_core(dssdev);
558 if (r)
559 return r;
560
cea87b92 561 dss_mgr_disable(mgr);
c3198a5e 562
7849398f 563 p = &hdmi.ip_data.cfg.timings;
c3198a5e 564
7849398f 565 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
c3198a5e 566
c3198a5e
M
567 phy = p->pixel_clock;
568
7b27da54 569 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
c3198a5e 570
c0456be3 571 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
c3198a5e 572
95a8aeb6 573 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
60634a28 574 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
c3198a5e
M
575 if (r) {
576 DSSDBG("Failed to lock PLL\n");
cca35017 577 goto err_pll_enable;
c3198a5e
M
578 }
579
60634a28 580 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
c3198a5e
M
581 if (r) {
582 DSSDBG("Failed to start PHY\n");
d3b4aa51 583 goto err_phy_enable;
c3198a5e
M
584 }
585
60634a28 586 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
c3198a5e 587
c3198a5e
M
588 /* bypass TV gamma table */
589 dispc_enable_gamma_table(0);
590
591 /* tv size */
cea87b92 592 dss_mgr_set_timings(mgr, p);
c3198a5e 593
c0456be3
RN
594 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
595 if (r)
596 goto err_vid_enable;
c3198a5e 597
cea87b92 598 r = dss_mgr_enable(mgr);
33ca237f
TV
599 if (r)
600 goto err_mgr_enable;
3870c909 601
c3198a5e 602 return 0;
33ca237f
TV
603
604err_mgr_enable:
c0456be3
RN
605 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
606err_vid_enable:
33ca237f 607 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
d3b4aa51 608err_phy_enable:
33ca237f 609 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
cca35017 610err_pll_enable:
bb426fc9 611 hdmi_power_off_core(dssdev);
c3198a5e
M
612 return -EIO;
613}
614
bb426fc9 615static void hdmi_power_off_full(struct omap_dss_device *dssdev)
c3198a5e 616{
cea87b92
AT
617 struct omap_overlay_manager *mgr = dssdev->output->manager;
618
619 dss_mgr_disable(mgr);
c3198a5e 620
c0456be3 621 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
60634a28
M
622 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
623 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
cca35017 624
bb426fc9 625 hdmi_power_off_core(dssdev);
c3198a5e
M
626}
627
628int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
629 struct omap_video_timings *timings)
630{
631 struct hdmi_cm cm;
632
633 cm = hdmi_get_code(timings);
634 if (cm.code == -1) {
c3198a5e
M
635 return -EINVAL;
636 }
637
638 return 0;
639
640}
641
7849398f
AT
642void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
643 struct omap_video_timings *timings)
c3198a5e
M
644{
645 struct hdmi_cm cm;
7849398f 646 const struct hdmi_config *t;
c3198a5e 647
ed1aa900
AT
648 mutex_lock(&hdmi.lock);
649
7849398f
AT
650 cm = hdmi_get_code(timings);
651 hdmi.ip_data.cfg.cm = cm;
652
653 t = hdmi_get_timings();
654 if (t != NULL)
655 hdmi.ip_data.cfg = *t;
fa70dc5f 656
ed1aa900 657 mutex_unlock(&hdmi.lock);
c3198a5e
M
658}
659
e40402cf 660static void hdmi_dump_regs(struct seq_file *s)
162874d5
M
661{
662 mutex_lock(&hdmi.lock);
663
664 if (hdmi_runtime_get())
665 return;
666
667 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
668 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
669 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
670 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
671
672 hdmi_runtime_put();
673 mutex_unlock(&hdmi.lock);
674}
675
47024565
TV
676int omapdss_hdmi_read_edid(u8 *buf, int len)
677{
678 int r;
679
680 mutex_lock(&hdmi.lock);
681
682 r = hdmi_runtime_get();
683 BUG_ON(r);
684
685 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
686
687 hdmi_runtime_put();
688 mutex_unlock(&hdmi.lock);
689
690 return r;
691}
692
759593ff
TV
693bool omapdss_hdmi_detect(void)
694{
695 int r;
696
697 mutex_lock(&hdmi.lock);
698
699 r = hdmi_runtime_get();
700 BUG_ON(r);
701
702 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
703
704 hdmi_runtime_put();
705 mutex_unlock(&hdmi.lock);
706
707 return r == 1;
708}
709
c3198a5e
M
710int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
711{
cea87b92 712 struct omap_dss_output *out = dssdev->output;
c3198a5e
M
713 int r = 0;
714
715 DSSDBG("ENTER hdmi_display_enable\n");
716
717 mutex_lock(&hdmi.lock);
718
cea87b92
AT
719 if (out == NULL || out->manager == NULL) {
720 DSSERR("failed to enable display: no output/manager\n");
05e1d606
TV
721 r = -ENODEV;
722 goto err0;
723 }
724
cca35017 725 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
c49d005b 726
c3198a5e
M
727 r = omap_dss_start_device(dssdev);
728 if (r) {
729 DSSERR("failed to start device\n");
730 goto err0;
731 }
732
bb426fc9 733 r = hdmi_power_on_full(dssdev);
c3198a5e
M
734 if (r) {
735 DSSERR("failed to power on device\n");
cca35017 736 goto err1;
c3198a5e
M
737 }
738
739 mutex_unlock(&hdmi.lock);
740 return 0;
741
c3198a5e
M
742err1:
743 omap_dss_stop_device(dssdev);
744err0:
745 mutex_unlock(&hdmi.lock);
746 return r;
747}
748
749void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
750{
751 DSSDBG("Enter hdmi_display_disable\n");
752
753 mutex_lock(&hdmi.lock);
754
bb426fc9 755 hdmi_power_off_full(dssdev);
c3198a5e 756
c3198a5e
M
757 omap_dss_stop_device(dssdev);
758
759 mutex_unlock(&hdmi.lock);
760}
761
4fbafaf3
TV
762static int hdmi_get_clocks(struct platform_device *pdev)
763{
764 struct clk *clk;
765
766 clk = clk_get(&pdev->dev, "sys_clk");
767 if (IS_ERR(clk)) {
768 DSSERR("can't get sys_clk\n");
769 return PTR_ERR(clk);
770 }
771
772 hdmi.sys_clk = clk;
773
4fbafaf3
TV
774 return 0;
775}
776
777static void hdmi_put_clocks(void)
778{
779 if (hdmi.sys_clk)
780 clk_put(hdmi.sys_clk);
4fbafaf3
TV
781}
782
35547626
RN
783#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
784int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
785{
786 u32 deep_color;
25a65359 787 bool deep_color_correct = false;
35547626
RN
788 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
789
790 if (n == NULL || cts == NULL)
791 return -EINVAL;
792
793 /* TODO: When implemented, query deep color mode here. */
794 deep_color = 100;
795
25a65359
RN
796 /*
797 * When using deep color, the default N value (as in the HDMI
798 * specification) yields to an non-integer CTS. Hence, we
799 * modify it while keeping the restrictions described in
800 * section 7.2.1 of the HDMI 1.4a specification.
801 */
35547626
RN
802 switch (sample_freq) {
803 case 32000:
25a65359
RN
804 case 48000:
805 case 96000:
806 case 192000:
807 if (deep_color == 125)
808 if (pclk == 27027 || pclk == 74250)
809 deep_color_correct = true;
810 if (deep_color == 150)
811 if (pclk == 27027)
812 deep_color_correct = true;
35547626
RN
813 break;
814 case 44100:
25a65359
RN
815 case 88200:
816 case 176400:
817 if (deep_color == 125)
818 if (pclk == 27027)
819 deep_color_correct = true;
35547626
RN
820 break;
821 default:
35547626
RN
822 return -EINVAL;
823 }
824
25a65359
RN
825 if (deep_color_correct) {
826 switch (sample_freq) {
827 case 32000:
828 *n = 8192;
829 break;
830 case 44100:
831 *n = 12544;
832 break;
833 case 48000:
834 *n = 8192;
835 break;
836 case 88200:
837 *n = 25088;
838 break;
839 case 96000:
840 *n = 16384;
841 break;
842 case 176400:
843 *n = 50176;
844 break;
845 case 192000:
846 *n = 32768;
847 break;
848 default:
849 return -EINVAL;
850 }
851 } else {
852 switch (sample_freq) {
853 case 32000:
854 *n = 4096;
855 break;
856 case 44100:
857 *n = 6272;
858 break;
859 case 48000:
860 *n = 6144;
861 break;
862 case 88200:
863 *n = 12544;
864 break;
865 case 96000:
866 *n = 12288;
867 break;
868 case 176400:
869 *n = 25088;
870 break;
871 case 192000:
872 *n = 24576;
873 break;
874 default:
875 return -EINVAL;
876 }
877 }
35547626
RN
878 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
879 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
880
881 return 0;
882}
f3a97491
RN
883
884int hdmi_audio_enable(void)
885{
886 DSSDBG("audio_enable\n");
887
888 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
889}
890
891void hdmi_audio_disable(void)
892{
893 DSSDBG("audio_disable\n");
894
895 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
896}
897
898int hdmi_audio_start(void)
899{
900 DSSDBG("audio_start\n");
901
902 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
903}
904
905void hdmi_audio_stop(void)
906{
907 DSSDBG("audio_stop\n");
908
909 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
910}
911
912bool hdmi_mode_has_audio(void)
913{
914 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
915 return true;
916 else
917 return false;
918}
919
920int hdmi_audio_config(struct omap_dss_audio *audio)
921{
922 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
923}
924
35547626
RN
925#endif
926
1521653c 927static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
38f3daf6
TV
928{
929 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
2bbcce5e 930 const char *def_disp_name = omapdss_get_default_display_name();
1521653c
TV
931 struct omap_dss_device *def_dssdev;
932 int i;
933
934 def_dssdev = NULL;
38f3daf6
TV
935
936 for (i = 0; i < pdata->num_devices; ++i) {
937 struct omap_dss_device *dssdev = pdata->devices[i];
938
939 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
940 continue;
941
1521653c
TV
942 if (def_dssdev == NULL)
943 def_dssdev = dssdev;
cca35017 944
1521653c
TV
945 if (def_disp_name != NULL &&
946 strcmp(dssdev->name, def_disp_name) == 0) {
947 def_dssdev = dssdev;
948 break;
38f3daf6 949 }
1521653c
TV
950 }
951
952 return def_dssdev;
953}
954
955static void __init hdmi_probe_pdata(struct platform_device *pdev)
956{
5274484b 957 struct omap_dss_device *plat_dssdev;
1521653c
TV
958 struct omap_dss_device *dssdev;
959 struct omap_dss_hdmi_data *priv;
960 int r;
38f3daf6 961
5274484b 962 plat_dssdev = hdmi_find_dssdev(pdev);
1521653c 963
5274484b
TV
964 if (!plat_dssdev)
965 return;
966
967 dssdev = dss_alloc_and_init_device(&pdev->dev);
1521653c
TV
968 if (!dssdev)
969 return;
970
5274484b
TV
971 dss_copy_device_pdata(dssdev, plat_dssdev);
972
1521653c
TV
973 priv = dssdev->data;
974
975 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
976 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
977 hdmi.hpd_gpio = priv->hpd_gpio;
978
bcb226a9
TV
979 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
980
1521653c
TV
981 r = hdmi_init_display(dssdev);
982 if (r) {
983 DSSERR("device %s init failed: %d\n", dssdev->name, r);
5274484b 984 dss_put_device(dssdev);
1521653c
TV
985 return;
986 }
987
5274484b 988 r = dss_add_device(dssdev);
1521653c
TV
989 if (r) {
990 DSSERR("device %s register failed: %d\n", dssdev->name, r);
5274484b 991 dss_put_device(dssdev);
1521653c 992 return;
38f3daf6
TV
993 }
994}
995
81b87f51
AT
996static void __init hdmi_init_output(struct platform_device *pdev)
997{
998 struct omap_dss_output *out = &hdmi.output;
999
1000 out->pdev = pdev;
1001 out->id = OMAP_DSS_OUTPUT_HDMI;
1002 out->type = OMAP_DISPLAY_TYPE_HDMI;
1003
1004 dss_register_output(out);
1005}
1006
1007static void __exit hdmi_uninit_output(struct platform_device *pdev)
1008{
1009 struct omap_dss_output *out = &hdmi.output;
1010
1011 dss_unregister_output(out);
1012}
1013
c3198a5e 1014/* HDMI HW IP initialisation */
6e7e8f06 1015static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
c3198a5e
M
1016{
1017 struct resource *hdmi_mem;
38f3daf6 1018 int r;
c3198a5e 1019
c3198a5e
M
1020 hdmi.pdev = pdev;
1021
1022 mutex_init(&hdmi.lock);
1023
1024 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1025 if (!hdmi_mem) {
1026 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1027 return -EINVAL;
1028 }
1029
1030 /* Base address taken from platform */
95a8aeb6
M
1031 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
1032 resource_size(hdmi_mem));
1033 if (!hdmi.ip_data.base_wp) {
c3198a5e
M
1034 DSSERR("can't ioremap WP\n");
1035 return -ENOMEM;
1036 }
1037
4fbafaf3
TV
1038 r = hdmi_get_clocks(pdev);
1039 if (r) {
95a8aeb6 1040 iounmap(hdmi.ip_data.base_wp);
4fbafaf3
TV
1041 return r;
1042 }
1043
1044 pm_runtime_enable(&pdev->dev);
1045
95a8aeb6
M
1046 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1047 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1048 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1049 hdmi.ip_data.phy_offset = HDMI_PHY;
7849398f 1050
3a5383a2 1051 mutex_init(&hdmi.ip_data.lock);
95a8aeb6 1052
c3198a5e
M
1053 hdmi_panel_init();
1054
e40402cf
TV
1055 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1056
81b87f51
AT
1057 hdmi_init_output(pdev);
1058
38f3daf6 1059 hdmi_probe_pdata(pdev);
35deca3d 1060
c3198a5e
M
1061 return 0;
1062}
1063
cca35017
TV
1064static int __exit hdmi_remove_child(struct device *dev, void *data)
1065{
1066 struct omap_dss_device *dssdev = to_dss_device(dev);
1067 hdmi_uninit_display(dssdev);
1068 return 0;
1069}
1070
6e7e8f06 1071static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
c3198a5e 1072{
cca35017
TV
1073 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1074
5274484b 1075 dss_unregister_child_devices(&pdev->dev);
35deca3d 1076
c3198a5e
M
1077 hdmi_panel_exit();
1078
81b87f51
AT
1079 hdmi_uninit_output(pdev);
1080
4fbafaf3
TV
1081 pm_runtime_disable(&pdev->dev);
1082
1083 hdmi_put_clocks();
1084
95a8aeb6 1085 iounmap(hdmi.ip_data.base_wp);
c3198a5e
M
1086
1087 return 0;
1088}
1089
4fbafaf3
TV
1090static int hdmi_runtime_suspend(struct device *dev)
1091{
f11766d1 1092 clk_disable_unprepare(hdmi.sys_clk);
4fbafaf3
TV
1093
1094 dispc_runtime_put();
4fbafaf3
TV
1095
1096 return 0;
1097}
1098
1099static int hdmi_runtime_resume(struct device *dev)
1100{
1101 int r;
1102
4fbafaf3
TV
1103 r = dispc_runtime_get();
1104 if (r < 0)
852f0838 1105 return r;
4fbafaf3 1106
f11766d1 1107 clk_prepare_enable(hdmi.sys_clk);
4fbafaf3
TV
1108
1109 return 0;
4fbafaf3
TV
1110}
1111
1112static const struct dev_pm_ops hdmi_pm_ops = {
1113 .runtime_suspend = hdmi_runtime_suspend,
1114 .runtime_resume = hdmi_runtime_resume,
1115};
1116
c3198a5e 1117static struct platform_driver omapdss_hdmihw_driver = {
6e7e8f06 1118 .remove = __exit_p(omapdss_hdmihw_remove),
c3198a5e
M
1119 .driver = {
1120 .name = "omapdss_hdmi",
1121 .owner = THIS_MODULE,
4fbafaf3 1122 .pm = &hdmi_pm_ops,
c3198a5e
M
1123 },
1124};
1125
6e7e8f06 1126int __init hdmi_init_platform_driver(void)
c3198a5e 1127{
61055d4b 1128 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
c3198a5e
M
1129}
1130
6e7e8f06 1131void __exit hdmi_uninit_platform_driver(void)
c3198a5e 1132{
04c742c3 1133 platform_driver_unregister(&omapdss_hdmihw_driver);
c3198a5e 1134}
This page took 0.147189 seconds and 5 git commands to generate.