a731144d7d4503f23e413b08cc2745577db1d50a
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 */
22 #define DSS_SUBSYS_NAME "HDMI"
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>
32 #include <linux/platform_device.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/clk.h>
35 #include <linux/gpio.h>
36 #include <linux/regulator/consumer.h>
37 #include <linux/slab.h>
38 #include <linux/of_gpio.h>
39 #include <linux/of_i2c.h>
40 #include <linux/fb.h>
41 #include <linux/omapfb.h>
42 #include <video/omapdss.h>
43 #include <linux/i2c.h>
44 #include <linux/i2c-algo-bit.h>
46 #include "ti_hdmi.h"
47 #include "dss.h"
48 #include "dss_features.h"
50 /* HDMI EDID Length move this */
51 #define HDMI_EDID_MAX_LENGTH 512
52 #define EDID_TIMING_DESCRIPTOR_SIZE 0x12
53 #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
54 #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
55 #define EDID_HDMI_VENDOR_SPECIFIC_DATA_BLOCK 128
56 #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
57 #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
59 static struct {
60 struct mutex lock;
61 struct platform_device *pdev;
62 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) || \
63 defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
64 struct platform_device *audio_pdev;
65 #endif
66 int code;
67 int mode;
68 u8 edid[HDMI_EDID_MAX_LENGTH];
69 bool edid_set;
70 bool custom_set;
71 bool can_do_hdmi;
72 bool force_timings;
73 int source_physical_address;
75 struct hdmi_ip_data ip_data;
76 int hdmi_irq;
78 struct clk *sys_clk;
79 struct regulator *vdda_hdmi_dac_reg;
81 /* GPIO pins */
82 int ct_cp_hpd_gpio;
83 int ls_oe_gpio;
84 int hpd_gpio;
86 /* level shifter state */
87 enum level_shifter_state ls_state;
89 /*
90 * i2c adapter info(this could be either a bitbanged adapter, or a
91 * 'real' i2c adapter
92 */
93 struct i2c_adapter *adap;
95 /* these are needed in case it's a bitbanged adapter */
96 struct i2c_algo_bit_data bit_data;
97 int scl_pin;
98 int sda_pin;
100 struct omap_dss_output output;
101 } hdmi;
103 static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
105 /*
106 * Logic for the below structure :
107 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
108 * There is a correspondence between CEA/VESA timing and code, please
109 * refer to section 6.3 in HDMI 1.3 specification for timing code.
110 *
111 * In the below structure, cea_vesa_timings corresponds to all OMAP4
112 * supported CEA and VESA timing values.code_cea corresponds to the CEA
113 * code, It is used to get the timing from cea_vesa_timing array.Similarly
114 * with code_vesa. Code_index is used for back mapping, that is once EDID
115 * is read from the TV, EDID is parsed to find the timing values and then
116 * map it to corresponding CEA or VESA index.
117 */
119 static const struct hdmi_config cea_timings[] = {
120 {
121 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
122 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
123 false, },
124 { 1, HDMI_HDMI },
125 },
126 {
127 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
128 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
129 false, },
130 { 2, HDMI_HDMI },
131 },
132 {
133 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
134 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
135 false, },
136 { 4, HDMI_HDMI },
137 },
138 {
139 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
140 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
141 true, },
142 { 5, HDMI_HDMI },
143 },
144 {
145 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
146 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
147 true, },
148 { 6, HDMI_HDMI },
149 },
150 {
151 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
152 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
153 false, },
154 { 16, HDMI_HDMI },
155 },
156 {
157 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
158 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
159 false, },
160 { 17, HDMI_HDMI },
161 },
162 {
163 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
164 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
165 false, },
166 { 19, HDMI_HDMI },
167 },
168 {
169 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
170 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
171 true, },
172 { 20, HDMI_HDMI },
173 },
174 {
175 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
176 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
177 true, },
178 { 21, HDMI_HDMI },
179 },
180 {
181 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
182 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
183 false, },
184 { 29, HDMI_HDMI },
185 },
186 {
187 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
188 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
189 false, },
190 { 31, HDMI_HDMI },
191 },
192 {
193 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
194 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
195 false, },
196 { 32, HDMI_HDMI },
197 },
198 {
199 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
200 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
201 false, },
202 { 35, HDMI_HDMI },
203 },
204 {
205 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
206 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
207 false, },
208 { 37, HDMI_HDMI },
209 },
210 };
212 static const struct hdmi_config vesa_timings[] = {
213 /* VESA From Here */
214 {
215 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
216 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
217 false, },
218 { 4, HDMI_DVI },
219 },
220 {
221 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
222 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
223 false, },
224 { 9, HDMI_DVI },
225 },
226 {
227 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
228 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
229 false, },
230 { 0xE, HDMI_DVI },
231 },
232 {
233 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
234 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
235 false, },
236 { 0x17, HDMI_DVI },
237 },
238 {
239 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
240 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
241 false, },
242 { 0x1C, HDMI_DVI },
243 },
244 {
245 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
246 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
247 false, },
248 { 0x27, HDMI_DVI },
249 },
250 {
251 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
252 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
253 false, },
254 { 0x20, HDMI_DVI },
255 },
256 {
257 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
258 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
259 false, },
260 { 0x23, HDMI_DVI },
261 },
262 {
263 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
264 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
265 false, },
266 { 0x10, HDMI_DVI },
267 },
268 {
269 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
270 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
271 false, },
272 { 0x2A, HDMI_DVI },
273 },
274 {
275 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
276 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
277 false, },
278 { 0x2F, HDMI_DVI },
279 },
280 {
281 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
282 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
283 false, },
284 { 0x3A, HDMI_DVI },
285 },
286 {
287 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
288 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
289 false, },
290 { 0x51, HDMI_DVI },
291 },
292 {
293 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
294 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
295 false, },
296 { 0x52, HDMI_DVI },
297 },
298 {
299 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
300 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
301 false, },
302 { 0x16, HDMI_DVI },
303 },
304 {
305 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
306 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
307 false, },
308 { 0x29, HDMI_DVI },
309 },
310 {
311 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
312 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
313 false, },
314 { 0x39, HDMI_DVI },
315 },
316 {
317 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
318 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
319 false, },
320 { 0x1B, HDMI_DVI },
321 },
322 {
323 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
324 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
325 false, },
326 { 0x55, HDMI_DVI },
327 },
328 {
329 { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
330 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
331 false, },
332 { 0x44, HDMI_DVI },
333 },
334 };
336 static const struct hdmi_config s3d_timings[] = {
337 {
338 { 1280, 1470, 148500, 40, 110, 220, 5, 5, 20,
339 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
340 false, },
341 { 4, HDMI_HDMI },
342 },
343 {
344 { 1280, 1470, 148500, 40, 440, 220, 5, 5, 20,
345 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
346 false, },
347 { 19, HDMI_HDMI },
348 },
349 {
350 { 1920, 2205, 148500, 44, 638, 148, 5, 4, 36,
351 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
352 false, },
353 { 32, HDMI_HDMI },
354 },
355 };
357 static void hdmi_set_ls_state(enum level_shifter_state state)
358 {
359 bool hpd_enable = false;
360 bool ls_enable = false;
362 /* return early if we have nothing to do */
363 if (state == hdmi.ls_state)
364 return;
366 sel_i2c();
368 switch (state) {
369 case LS_HPD_ON:
370 hpd_enable = true;
371 break;
373 case LS_ENABLED:
374 hpd_enable = true;
375 ls_enable = true;
376 break;
378 case LS_DISABLED:
379 default:
380 break;
381 }
383 gpio_set_value_cansleep(hdmi.ct_cp_hpd_gpio, hpd_enable);
385 gpio_set_value_cansleep(hdmi.ls_oe_gpio, ls_enable);
387 /* wait 300us after asserting CT_CP_HPD for the 5V rail to reach 90% */
388 if (hdmi.ls_state == LS_DISABLED)
389 udelay(300);
391 hdmi.ls_state = state;
393 sel_hdmi();
394 }
396 static int relaxed_fb_mode_is_equal(const struct fb_videomode *mode1,
397 const struct fb_videomode *mode2)
398 {
399 u32 ratio1 = mode1->flag & (FB_FLAG_RATIO_4_3 | FB_FLAG_RATIO_16_9);
400 u32 ratio2 = mode2->flag & (FB_FLAG_RATIO_4_3 | FB_FLAG_RATIO_16_9);
401 return (mode1->xres == mode2->xres &&
402 mode1->yres == mode2->yres &&
403 mode1->pixclock <= mode2->pixclock * 201 / 200 &&
404 mode1->pixclock >= mode2->pixclock * 200 / 201 &&
405 mode1->hsync_len + mode1->left_margin + mode1->right_margin ==
406 mode2->hsync_len + mode2->left_margin + mode2->right_margin &&
407 mode1->vsync_len + mode1->upper_margin + mode1->lower_margin ==
408 mode2->vsync_len + mode2->upper_margin + mode2->lower_margin &&
409 (!ratio1 || !ratio2 || ratio1 == ratio2) &&
410 (mode1->vmode & FB_VMODE_INTERLACED) ==
411 (mode2->vmode & FB_VMODE_INTERLACED));
413 }
415 static int hdmi_set_timings(struct fb_videomode *vm, bool check_only)
416 {
417 int i = 0;
418 int r = 0;
419 DSSDBG("hdmi_set_timings\n");
421 if (!vm->xres || !vm->yres || !vm->pixclock)
422 goto fail;
424 for (i = 0; i < CEA_MODEDB_SIZE; i++) {
425 if (relaxed_fb_mode_is_equal(cea_modes + i, vm)) {
426 *vm = cea_modes[i];
427 if (check_only)
428 return 1;
429 hdmi.ip_data.cfg.cm.code = i;
430 hdmi.ip_data.cfg.cm.mode = HDMI_HDMI;
431 hdmi.ip_data.cfg.timingsfb =
432 cea_modes[hdmi.ip_data.cfg.cm.code];
433 goto done;
434 }
435 }
436 for (i = 0; i < VESA_MODEDB_SIZE; i++) {
437 if (relaxed_fb_mode_is_equal(vesa_modes + i, vm)) {
438 *vm = vesa_modes[i];
439 if (check_only)
440 return 1;
441 hdmi.ip_data.cfg.cm.code = i;
442 hdmi.ip_data.cfg.cm.mode = HDMI_DVI;
443 hdmi.ip_data.cfg.timingsfb =
444 vesa_modes[hdmi.ip_data.cfg.cm.code];
445 goto done;
446 }
447 }
448 fail:
449 if (check_only)
450 return 0;
451 hdmi.ip_data.cfg.cm.code = 1;
452 hdmi.ip_data.cfg.cm.mode = HDMI_HDMI;
453 hdmi.ip_data.cfg.timingsfb = cea_modes[hdmi.ip_data.cfg.cm.code];
454 i = -1;
455 done:
456 DSSDBG("%s-%d\n", hdmi.ip_data.cfg.cm.mode ? "CEA" : "VESA",
457 hdmi.ip_data.cfg.cm.code);
459 /* convert fb timing to dss timings to be in sync. */
460 omapfb_fb2dss_timings(&hdmi.ip_data.cfg.timingsfb,&hdmi.ip_data.cfg.timings);
462 r = i >= 0 ? 1 : 0;
463 return r;
465 }
467 void hdmi_get_monspecs(struct omap_dss_device *dssdev)
468 {
469 int i, j;
470 char *edid = (char *)hdmi.edid;
471 struct fb_monspecs *specs = &dssdev->panel.monspecs;
472 u32 fclk = dispc_fclk_rate() / 1000;
473 u32 max_pclk = dssdev->clocks.hdmi.max_pixclk_khz;
475 if (max_pclk && max_pclk < fclk)
476 fclk = max_pclk;
478 memset(specs, 0x0, sizeof(*specs));
479 if (!hdmi.edid_set)
480 return;
481 fb_edid_to_monspecs(edid, specs);
482 if (specs->modedb == NULL)
483 return;
485 for (i = 1; i <= edid[0x7e] && i * 128 < HDMI_EDID_MAX_LENGTH; i++) {
486 if (edid[i * 128] == 0x2)
487 fb_edid_add_monspecs(edid + i * 128, specs);
488 }
489 if (hdmi.force_timings) {
490 for (i = 0; i < specs->modedb_len; i++) {
491 specs->modedb[i++] = hdmi.ip_data.cfg.timingsfb;
492 break;
493 }
494 specs->modedb_len = i;
495 hdmi.force_timings = false;
496 return;
497 }
499 hdmi.can_do_hdmi = specs->misc & FB_MISC_HDMI;
501 /* filter out resolutions we don't support */
502 for (i = j = 0; i < specs->modedb_len; i++) {
503 if (!hdmi_set_timings(&specs->modedb[i], true))
504 continue;
505 if (fclk < PICOS2KHZ(specs->modedb[i].pixclock))
506 continue;
507 if (specs->modedb[i].flag & FB_FLAG_PIXEL_REPEAT)
508 continue;
509 specs->modedb[j++] = specs->modedb[i];
510 }
511 specs->modedb_len = j;
513 }
515 static int hdmi_runtime_get(void)
516 {
517 int r;
519 DSSDBG("hdmi_runtime_get\n");
521 r = pm_runtime_get_sync(&hdmi.pdev->dev);
522 WARN_ON(r < 0);
523 if (r < 0)
524 return r;
526 return 0;
527 }
529 static void hdmi_runtime_put(void)
530 {
531 int r;
533 DSSDBG("hdmi_runtime_put\n");
535 r = pm_runtime_put_sync(&hdmi.pdev->dev);
536 WARN_ON(r < 0 && r != -ENOSYS);
537 }
539 static int __init hdmi_init_display(struct omap_dss_device *dssdev)
540 {
541 int r;
543 struct gpio gpios[] = {
544 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
545 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
546 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
547 };
549 DSSDBG("init_display\n");
551 if (hdmi.vdda_hdmi_dac_reg == NULL) {
552 struct regulator *reg;
554 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
556 /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
557 if (IS_ERR(reg))
558 reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
560 if (IS_ERR(reg)) {
561 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
562 return PTR_ERR(reg);
563 }
565 hdmi.vdda_hdmi_dac_reg = reg;
566 }
568 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
569 if (r)
570 return r;
572 return 0;
573 }
575 static void hdmi_uninit_display(struct omap_dss_device *dssdev)
576 {
577 DSSDBG("uninit_display\n");
579 gpio_free(hdmi.ct_cp_hpd_gpio);
580 gpio_free(hdmi.ls_oe_gpio);
581 gpio_free(hdmi.hpd_gpio);
582 }
584 static const struct hdmi_config *hdmi_find_timing(
585 const struct hdmi_config *timings_arr,
586 int len)
587 {
588 int i;
590 for (i = 0; i < len; i++) {
591 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
592 return &timings_arr[i];
593 }
594 return NULL;
595 }
597 static const struct hdmi_config *hdmi_get_timings(void)
598 {
599 const struct hdmi_config *arr;
600 int len;
602 if (!hdmi.ip_data.cfg.s3d_enabled) {
603 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
604 arr = vesa_timings;
605 len = ARRAY_SIZE(vesa_timings);
606 } else {
607 arr = cea_timings;
608 len = ARRAY_SIZE(cea_timings);
609 }
610 } else {
611 arr = s3d_timings;
612 len = ARRAY_SIZE(s3d_timings);
613 }
615 return hdmi_find_timing(arr, len);
616 }
618 static bool hdmi_timings_compare(struct omap_video_timings *timing1,
619 const struct omap_video_timings *timing2)
620 {
621 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
623 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
624 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
625 (timing2->x_res == timing1->x_res) &&
626 (timing2->y_res == timing1->y_res)) {
628 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
629 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
630 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
631 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
633 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
634 "timing2_hsync = %d timing2_vsync = %d\n",
635 timing1_hsync, timing1_vsync,
636 timing2_hsync, timing2_vsync);
638 if ((timing1_hsync == timing2_hsync) &&
639 (timing1_vsync == timing2_vsync)) {
640 return true;
641 }
642 }
643 return false;
644 }
646 static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
647 {
648 int i;
649 struct hdmi_cm cm = {-1};
650 DSSDBG("hdmi_get_code\n");
652 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
653 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
654 cm = cea_timings[i].cm;
655 goto end;
656 }
657 }
658 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
659 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
660 cm = vesa_timings[i].cm;
661 goto end;
662 }
663 }
664 for (i = 0; i < ARRAY_SIZE(s3d_timings); i++) {
665 if (hdmi_timings_compare(timing, &s3d_timings[i].timings)) {
666 cm = s3d_timings[i].cm;
667 goto end;
668 }
669 }
671 end: return cm;
673 }
675 u8 *hdmi_read_valid_edid(void)
676 {
677 int ret, i;
679 if (hdmi.edid_set)
680 return hdmi.edid;
682 memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
684 hdmi_runtime_get();
686 ret = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, hdmi.edid,
687 HDMI_EDID_MAX_LENGTH);
689 hdmi_runtime_put();
691 for (i = 0; i < HDMI_EDID_MAX_LENGTH; i += 16)
692 DSSDBG("edid[%03x] = %02x %02x %02x %02x %02x %02x %02x %02x "\
693 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
694 hdmi.edid[i], hdmi.edid[i + 1], hdmi.edid[i + 2],
695 hdmi.edid[i + 3], hdmi.edid[i + 4], hdmi.edid[i + 5],
696 hdmi.edid[i + 6], hdmi.edid[i + 7], hdmi.edid[i + 8],
697 hdmi.edid[i + 9], hdmi.edid[i + 10], hdmi.edid[i + 11],
698 hdmi.edid[i + 12], hdmi.edid[i + 13], hdmi.edid[i + 14],
699 hdmi.edid[i + 15]);
701 if (ret) {
702 DSSWARN("failed to read E-EDID\n");
703 return NULL;
704 }
705 if (memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
706 DSSWARN("failed to read E-EDID: wrong header\n");
707 return NULL;
708 }
709 hdmi.edid_set = true;
711 return hdmi.edid;
712 }
714 unsigned long hdmi_get_pixel_clock(void)
715 {
716 /* HDMI Pixel Clock in Mhz */
717 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
718 }
720 static int hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
721 struct hdmi_pll_info *pi)
722 {
723 unsigned long clkin, refclk;
724 int phy_calc;
725 unsigned long regn_max, regn_min, regm_min, regm_max;
726 unsigned long fint_min, fint_max;
727 unsigned long dco_low_min, dco_high_min;
728 bool found = false;
729 u32 mf;
731 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
733 fint_min = dss_feat_get_param_min(FEAT_PARAM_HDMIPLL_FINT) / 10000;
734 fint_max = dss_feat_get_param_max(FEAT_PARAM_HDMIPLL_FINT) / 10000;
736 /* clkin limits */
737 /* .62 MHz < CLKIN/REGN < 2.5MHz */
738 regn_min = clkin / fint_max + 1;
739 regn_max = clkin / fint_min;
741 /* Fractional limits on REGM */
742 regm_min = dss_feat_get_param_min(FEAT_PARAM_HDMIPLL_REGM);
743 regm_max = dss_feat_get_param_max(FEAT_PARAM_HDMIPLL_REGM);
745 /* DCO frequency ranges */
747 /* DCO lowest frequency supported */
748 dco_low_min = dss_feat_get_param_min(FEAT_PARAM_DCOFREQ_LOW) / 10000;
750 /* Starting frequency of high frequency range(in Mhz) */
751 dco_high_min = dss_feat_get_param_min(FEAT_PARAM_DCOFREQ_HIGH);
753 /* set dcofreq to 1 if required clock is > 1.25GHz */
754 pi->dcofreq = phy > (dco_high_min / 10000);
756 if (phy < dco_low_min) {
757 /* Calculate CLKOUTLDO - low frequency */
758 for (pi->regn = regn_min; pi->regn < regn_max; pi->regn++) {
759 refclk = clkin / pi->regn;
761 regm_min = ((dco_low_min / refclk) < regm_min) ?
762 regm_min : (dco_low_min / refclk);
764 for (pi->regm2 = 3; pi->regm2 <= 127; pi->regm2++) {
765 pi->regm = phy * pi->regm2 / refclk;
766 if (pi->regm < regm_min || pi->regm > regm_max)
767 continue;
769 pi->regsd = DIV_ROUND_UP((pi->regm * clkin / 100),
770 pi->regn * 250);
771 phy_calc = clkin * pi->regm / pi->regn /
772 pi->regm2;
774 if (pi->regsd && pi->regsd < 255 &&
775 phy_calc <= phy) {
776 found = true;
777 break;
778 }
779 }
781 if (found)
782 break;
783 }
784 } else {
785 pi->regm2 = 1;
787 /* CLKDCOLDO - high frequency */
788 for (pi->regn = regn_min; pi->regn < regn_max; pi->regn++) {
789 refclk = clkin / pi->regn;
790 pi->regm = phy / refclk;
792 if (pi->regm < regm_min || pi->regm > regm_max)
793 continue;
795 pi->regsd = DIV_ROUND_UP((pi->regm * clkin / 100),
796 pi->regn * 250);
798 phy_calc = clkin * pi->regm / pi->regn;
800 if (pi->regsd < 255 && phy_calc <= phy) {
801 found = true;
802 break;
803 }
804 }
805 }
807 if (!found) {
808 DSSERR("Failed to find pll settings\n");
809 return 1;
810 }
812 /*
813 * fractional multiplier is remainder of the difference between
814 * multiplier and actual phy(required pixel clock thus should be
815 * multiplied by 2^18(262144) divided by the reference clock
816 */
817 mf = (phy - refclk * pi->regm / pi->regm2) * 262144;
818 pi->regmf = pi->regm2 * mf / refclk;
820 if (pi->regmf > 262144)
821 pi->regmf = 0;
823 /* Set the reference clock to sysclk reference */
824 pi->refsel = HDMI_REFSEL_SYSCLK;
826 DSSERR("M = %d Mf = %d\n", pi->regm, pi->regmf);
827 DSSERR("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
829 return 0;
830 }
832 static int hdmi_power_on_core(struct omap_dss_device *dssdev)
833 {
834 int r;
836 hdmi_set_ls_state(LS_ENABLED);
838 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
839 if (r)
840 goto err_vdac_enable;
842 r = hdmi_runtime_get();
843 if (r)
844 goto err_runtime_get;
846 /* Make selection of HDMI in DSS */
847 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
849 return 0;
851 err_runtime_get:
852 regulator_disable(hdmi.vdda_hdmi_dac_reg);
853 err_vdac_enable:
854 hdmi_set_ls_state(LS_HPD_ON);
855 return r;
856 }
858 static void hdmi_power_off_core(struct omap_dss_device *dssdev)
859 {
860 hdmi_runtime_put();
861 regulator_disable(hdmi.vdda_hdmi_dac_reg);
863 hdmi_set_ls_state(LS_HPD_ON);
864 }
866 static int hdmi_power_on_full(struct omap_dss_device *dssdev)
867 {
868 int r;
869 struct omap_video_timings *p;
870 struct omap_overlay_manager *mgr = dssdev->output->manager;
871 unsigned long phy;
873 r = hdmi_power_on_core(dssdev);
874 if (r)
875 return r;
877 dss_mgr_disable(mgr);
879 p = &hdmi.ip_data.cfg.timings;
881 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
882 #ifdef CONFIG_USE_FB_MODE_DB
883 if (!hdmi.custom_set) {
884 struct fb_videomode fb_mode = vesa_modes[4];
885 if ((hdmi.ip_data.cfg.cm.code != 4) &&
886 (hdmi.ip_data.cfg.cm.mode != HDMI_DVI)) {
887 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI)
888 fb_mode = vesa_modes[hdmi.ip_data.cfg.cm.code];
889 else
890 fb_mode = cea_modes[hdmi.ip_data.cfg.cm.code];
891 }
892 if (!hdmi_set_timings(&fb_mode, false)) {
893 /* Fallback in case we cannot set the timings */
894 DSSERR("fallback to vesa default code");
895 fb_mode = vesa_modes[4];
896 hdmi_set_timings(&fb_mode, false);
897 }
898 }
900 /* Update the panel timing in dssdev */
901 omapfb_fb2dss_timings(&hdmi.ip_data.cfg.timingsfb,
902 &dssdev->panel.timings);
903 #endif
904 switch (hdmi.ip_data.cfg.deep_color) {
905 case HDMI_DEEP_COLOR_30BIT:
906 phy = (p->pixel_clock * 125) / 100 ;
907 break;
908 case HDMI_DEEP_COLOR_36BIT:
909 phy = (p->pixel_clock * 150) / 100;
911 if (phy >= dss_feat_get_param_max(FEAT_PARAM_HDMI_PCLK)) {
912 DSSERR("36 bit deep color not supported for the pixel clock %d\n",
913 p->pixel_clock);
914 goto err_deep_color;
915 }
916 break;
917 case HDMI_DEEP_COLOR_24BIT:
918 default:
919 phy = p->pixel_clock;
920 break;
921 }
923 if (hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data))
924 goto err_pll_compute;
926 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
928 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
929 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
930 if (r) {
931 DSSDBG("Failed to lock PLL\n");
932 goto err_pll_enable;
933 }
935 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
936 /*
937 * DRA7xx doesn't show the correct PHY transition changes in the
938 * WP_PWR_CTRL register, need to investigate
939 */
940 if (omapdss_get_version() == OMAPDSS_VER_DRA7xx)
941 r = 0;
943 if (r) {
944 DSSDBG("Failed to start PHY\n");
945 goto err_phy_enable;
946 }
948 hdmi.ip_data.cfg.cm.mode = hdmi.can_do_hdmi ? hdmi.mode : HDMI_DVI;
950 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
952 /* Make selection of HDMI in DSS */
953 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
955 /* Select the dispc clock source as PRCM clock, to ensure that it is not
956 * DSI PLL source as the clock selected by DSI PLL might not be
957 * sufficient for the resolution selected / that can be changed
958 * dynamically by user. This can be moved to single location , say
959 * Boardfile.
960 */
961 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
963 /* bypass TV gamma table */
964 dispc_enable_gamma_table(0);
966 /* tv size */
967 dss_mgr_set_timings(mgr, p);
969 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
970 if (r)
971 goto err_vid_enable;
973 r = dss_mgr_enable(mgr);
974 if (r)
975 goto err_mgr_enable;
977 return 0;
979 err_mgr_enable:
980 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
981 err_vid_enable:
982 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
983 err_phy_enable:
984 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
985 err_pll_enable:
986 err_pll_compute:
987 err_deep_color:
988 hdmi_power_off_core(dssdev);
989 return -EIO;
990 }
992 static void hdmi_power_off_full(struct omap_dss_device *dssdev)
993 {
994 struct omap_overlay_manager *mgr = dssdev->output->manager;
996 dss_mgr_disable(mgr);
998 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
999 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
1000 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
1002 hdmi.ip_data.cfg.deep_color = HDMI_DEEP_COLOR_24BIT;
1004 hdmi_power_off_core(dssdev);
1005 }
1007 int omapdss_hdmi_set_deepcolor(struct omap_dss_device *dssdev, int val,
1008 bool hdmi_restart)
1009 {
1010 int r;
1012 if (!hdmi_restart) {
1013 hdmi.ip_data.cfg.deep_color = val;
1014 return 0;
1015 }
1017 omapdss_hdmi_display_disable(dssdev);
1019 hdmi.ip_data.cfg.deep_color = val;
1021 r = omapdss_hdmi_display_enable(dssdev);
1022 if (r)
1023 return r;
1025 return 0;
1026 }
1028 int omapdss_hdmi_get_deepcolor(void)
1029 {
1030 return hdmi.ip_data.cfg.deep_color;
1031 }
1033 int omapdss_hdmi_set_range(int range)
1034 {
1035 int r = 0;
1036 enum hdmi_range old_range;
1038 old_range = hdmi.ip_data.cfg.range;
1039 hdmi.ip_data.cfg.range = range;
1041 /* HDMI 1.3 section 6.6 VGA (640x480) format requires Full Range */
1042 if ((range == 0) &&
1043 ((hdmi.ip_data.cfg.cm.code == 4 &&
1044 hdmi.ip_data.cfg.cm.mode == HDMI_DVI) ||
1045 (hdmi.ip_data.cfg.cm.code == 1 &&
1046 hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)))
1047 return -EINVAL;
1049 r = hdmi.ip_data.ops->configure_range(&hdmi.ip_data);
1050 if (r)
1051 hdmi.ip_data.cfg.range = old_range;
1053 return r;
1054 }
1056 int omapdss_hdmi_get_range(void)
1057 {
1058 return hdmi.ip_data.cfg.range;
1059 }
1061 int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
1062 struct omap_video_timings *timings)
1063 {
1064 #ifdef CONFIG_USE_FB_MODE_DB
1065 struct fb_videomode t;
1066 omapfb_dss2fb_timings(timings, &t);
1068 /* also check interlaced timings */
1069 if (!hdmi_set_timings(&t, true)) {
1070 t.yres *= 2;
1071 t.vmode |= FB_VMODE_INTERLACED;
1072 }
1073 if (!hdmi_set_timings(&t, true))
1074 return -EINVAL;
1075 #else
1076 struct hdmi_cm cm;
1078 cm = hdmi_get_code(timings);
1079 if (cm.code == -1) {
1080 return -EINVAL;
1081 }
1083 #endif
1084 return 0;
1086 }
1088 int omapdss_hdmi_display_set_mode(struct omap_dss_device *dssdev,
1089 struct fb_videomode *vm)
1090 {
1091 int r1, r2;
1092 /* turn the hdmi off and on to get new timings to use */
1093 hdmi.ip_data.set_mode = true;
1094 dssdev->driver->disable(dssdev);
1095 hdmi.ip_data.set_mode = false;
1096 r1 = hdmi_set_timings(vm, false) ? 0 : -EINVAL;
1097 hdmi.custom_set = true;
1098 hdmi.code = hdmi.ip_data.cfg.cm.code;
1099 hdmi.mode = hdmi.ip_data.cfg.cm.mode;
1100 r2 = dssdev->driver->enable(dssdev);
1101 return r1 ? : r2;
1102 }
1104 int omapdss_hdmi_display_3d_enable(struct omap_dss_device *dssdev,
1105 struct s3d_disp_info *info, int code)
1106 {
1107 struct omap_dss_output *out = dssdev->output;
1108 int r = 0;
1110 DSSDBG("ENTER hdmi_display_3d_enable\n");
1112 mutex_lock(&hdmi.lock);
1114 if (out == NULL || out->manager == NULL) {
1115 DSSERR("failed to enable display: no output/manager\n");
1116 r = -ENODEV;
1117 goto err0;
1118 }
1120 r = omap_dss_start_device(dssdev);
1121 if (r) {
1122 DSSERR("failed to start device\n");
1123 goto err0;
1124 }
1126 if (dssdev->platform_enable) {
1127 r = dssdev->platform_enable(dssdev);
1128 if (r) {
1129 DSSERR("failed to enable GPIO's\n");
1130 goto err1;
1131 }
1132 }
1134 /* hdmi.s3d_enabled will be updated when powering display up */
1135 /* if there's no S3D support it will be reset to false */
1136 switch (info->type) {
1137 case S3D_DISP_OVERUNDER:
1138 if (info->sub_samp == S3D_DISP_SUB_SAMPLE_NONE) {
1139 dssdev->panel.s3d_info = *info;
1140 hdmi.ip_data.cfg.s3d_info.frame_struct =
1141 HDMI_S3D_FRAME_PACKING;
1142 hdmi.ip_data.cfg.s3d_info.subsamp = false;
1143 hdmi.ip_data.cfg.s3d_info.subsamp_pos = 0;
1144 hdmi.ip_data.cfg.s3d_enabled = true;
1145 hdmi.ip_data.cfg.s3d_info.vsi_enabled = true;
1146 } else {
1147 goto err2;
1148 }
1149 break;
1150 case S3D_DISP_SIDEBYSIDE:
1151 dssdev->panel.s3d_info = *info;
1152 if (info->sub_samp == S3D_DISP_SUB_SAMPLE_NONE) {
1153 hdmi.ip_data.cfg.s3d_info.frame_struct =
1154 HDMI_S3D_SIDE_BY_SIDE_FULL;
1155 hdmi.ip_data.cfg.s3d_info.subsamp = true;
1156 hdmi.ip_data.cfg.s3d_info.subsamp_pos =
1157 HDMI_S3D_HOR_EL_ER;
1158 hdmi.ip_data.cfg.s3d_enabled = true;
1159 hdmi.ip_data.cfg.s3d_info.vsi_enabled = true;
1160 } else if (info->sub_samp == S3D_DISP_SUB_SAMPLE_H) {
1161 hdmi.ip_data.cfg.s3d_info.frame_struct =
1162 HDMI_S3D_SIDE_BY_SIDE_HALF;
1163 hdmi.ip_data.cfg.s3d_info.subsamp = true;
1164 hdmi.ip_data.cfg.s3d_info.subsamp_pos =
1165 HDMI_S3D_HOR_EL_ER;
1166 hdmi.ip_data.cfg.s3d_info.vsi_enabled = true;
1167 } else {
1168 goto err2;
1169 }
1170 break;
1171 default:
1172 goto err2;
1173 }
1174 if (hdmi.ip_data.cfg.s3d_enabled) {
1175 hdmi.ip_data.cfg.cm.code = code;
1176 hdmi.ip_data.cfg.cm.mode = HDMI_HDMI;
1177 }
1179 r = hdmi_power_on_full(dssdev);
1180 if (r) {
1181 DSSERR("failed to power on device\n");
1182 goto err2;
1183 }
1185 mutex_unlock(&hdmi.lock);
1186 return 0;
1188 err2:
1189 if (dssdev->platform_disable)
1190 dssdev->platform_disable(dssdev);
1191 err1:
1192 omap_dss_stop_device(dssdev);
1193 err0:
1194 mutex_unlock(&hdmi.lock);
1195 return r;
1196 }
1198 void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
1199 struct omap_video_timings *timings)
1200 {
1201 #ifdef CONFIG_USE_FB_MODE_DB
1202 struct fb_videomode t;
1204 DSSDBG("x_res= %d y_res = %d\n",
1205 dssdev->panel.timings.x_res,
1206 dssdev->panel.timings.y_res);
1208 omapfb_dss2fb_timings(&dssdev->panel.timings, &t);
1209 /* also check interlaced timings */
1210 if (!hdmi_set_timings(&t, true)) {
1211 t.yres *= 2;
1212 t.vmode |= FB_VMODE_INTERLACED;
1213 }
1214 omapdss_hdmi_display_set_mode(dssdev, &t);
1215 #else
1216 struct hdmi_cm cm;
1217 const struct hdmi_config *t;
1219 mutex_lock(&hdmi.lock);
1221 cm = hdmi_get_code(timings);
1222 hdmi.ip_data.cfg.cm = cm;
1224 t = hdmi_get_timings();
1225 if (t != NULL)
1226 hdmi.ip_data.cfg = *t;
1228 mutex_unlock(&hdmi.lock);
1229 #endif
1230 }
1232 static void hdmi_dump_regs(struct seq_file *s)
1233 {
1234 mutex_lock(&hdmi.lock);
1236 if (hdmi_runtime_get()) {
1237 mutex_unlock(&hdmi.lock);
1238 return;
1239 }
1241 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
1242 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
1243 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
1244 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
1246 hdmi_runtime_put();
1247 mutex_unlock(&hdmi.lock);
1248 }
1250 int omapdss_hdmi_read_edid(u8 *buf, int len)
1251 {
1252 int r;
1253 enum level_shifter_state restore_state = hdmi.ls_state;
1255 /* skip if no monitor attached */
1256 if (!gpio_get_value(hdmi.hpd_gpio))
1257 return -ENODEV;
1259 mutex_lock(&hdmi.lock);
1261 r = hdmi_runtime_get();
1262 BUG_ON(r);
1265 hdmi_set_ls_state(LS_ENABLED);
1267 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
1269 /* restore level shifter state */
1270 hdmi_set_ls_state(restore_state);
1272 hdmi_runtime_put();
1273 mutex_unlock(&hdmi.lock);
1275 return r;
1276 }
1278 bool omapdss_hdmi_detect(void)
1279 {
1280 int r;
1282 mutex_lock(&hdmi.lock);
1284 r = hdmi_runtime_get();
1285 BUG_ON(r);
1287 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
1289 hdmi_runtime_put();
1290 mutex_unlock(&hdmi.lock);
1292 return r == 1;
1293 }
1295 int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
1296 {
1297 struct omap_dss_output *out = dssdev->output;
1298 int r = 0;
1300 DSSDBG("ENTER hdmi_display_enable\n");
1302 mutex_lock(&hdmi.lock);
1304 if (out == NULL || out->manager == NULL) {
1305 DSSERR("failed to enable display: no output/manager\n");
1306 r = -ENODEV;
1307 goto err0;
1308 }
1310 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
1312 r = omap_dss_start_device(dssdev);
1313 if (r) {
1314 DSSERR("failed to start device\n");
1315 goto err0;
1316 }
1318 r = hdmi_power_on_full(dssdev);
1319 if (r) {
1320 DSSERR("failed to power on device\n");
1321 goto err1;
1322 }
1324 mutex_unlock(&hdmi.lock);
1325 return 0;
1327 err1:
1328 omap_dss_stop_device(dssdev);
1329 err0:
1330 mutex_unlock(&hdmi.lock);
1331 return r;
1332 }
1334 void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
1335 {
1336 DSSDBG("Enter hdmi_display_disable\n");
1338 mutex_lock(&hdmi.lock);
1340 hdmi_power_off_full(dssdev);
1342 omap_dss_stop_device(dssdev);
1344 mutex_unlock(&hdmi.lock);
1345 }
1347 int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
1348 {
1349 int r = 0;
1351 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
1353 mutex_lock(&hdmi.lock);
1355 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
1357 r = hdmi_power_on_core(dssdev);
1358 if (r) {
1359 DSSERR("failed to power on device\n");
1360 goto err0;
1361 }
1363 mutex_unlock(&hdmi.lock);
1364 return 0;
1366 err0:
1367 mutex_unlock(&hdmi.lock);
1368 return r;
1369 }
1371 void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
1372 {
1373 DSSDBG("Enter omapdss_hdmi_core_disable\n");
1375 mutex_lock(&hdmi.lock);
1377 hdmi_power_off_core(dssdev);
1379 mutex_unlock(&hdmi.lock);
1380 }
1382 void omapdss_hdmi_clear_edid(void)
1383 {
1384 hdmi.edid_set = false;
1385 hdmi.custom_set = false;
1386 }
1388 ssize_t omapdss_get_edid(char *buf)
1389 {
1390 ssize_t size = hdmi.edid_set ? HDMI_EDID_MAX_LENGTH : 0;
1391 memcpy(buf, hdmi.edid, size);
1392 return size;
1393 }
1395 static irqreturn_t hdmi_irq_handler(int irq, void *arg)
1396 {
1397 int r = 0;
1399 r = hdmi.ip_data.ops->irq_handler(&hdmi.ip_data);
1400 DSSDBG("Received HDMI IRQ = %08x\n", r);
1402 r = hdmi.ip_data.ops->irq_core_handler(&hdmi.ip_data);
1403 DSSDBG("Received HDMI core IRQ = %08x\n", r);
1405 return IRQ_HANDLED;
1406 }
1408 static int hdmi_get_clocks(struct platform_device *pdev)
1409 {
1410 struct clk *clk;
1412 clk = clk_get(&pdev->dev, "sys_clk");
1413 if (IS_ERR(clk)) {
1414 DSSERR("can't get sys_clk\n");
1415 return PTR_ERR(clk);
1416 }
1418 hdmi.sys_clk = clk;
1420 return 0;
1421 }
1423 static void hdmi_put_clocks(void)
1424 {
1425 if (hdmi.sys_clk)
1426 clk_put(hdmi.sys_clk);
1427 }
1429 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) || \
1430 defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
1431 static int hdmi_probe_audio(struct platform_device *pdev)
1432 {
1433 struct resource *res;
1434 struct platform_device *aud_pdev;
1435 u32 port_offset, port_size;
1436 struct resource aud_res[2] = {
1437 DEFINE_RES_MEM(-1, -1),
1438 DEFINE_RES_DMA(-1),
1439 };
1441 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1442 if (!res) {
1443 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1444 return -EINVAL;
1445 }
1447 /*
1448 * Pass DMA audio port to audio drivers.
1449 * Audio drivers should not ioremap it.
1450 */
1451 hdmi.ip_data.ops->audio_get_dma_port(&port_offset, &port_size);
1453 aud_res[0].start = res->start + port_offset;
1454 aud_res[0].end = aud_res[0].start + port_size - 1;
1456 res = platform_get_resource(hdmi.pdev, IORESOURCE_DMA, 0);
1457 if (!res) {
1458 DSSERR("can't get IORESOURCE_DMA HDMI\n");
1459 return -EINVAL;
1460 }
1462 /* Pass the audio DMA request resource to audio drivers. */
1463 aud_res[1].start = res->start;
1465 /* create platform device for HDMI audio driver */
1466 aud_pdev = platform_device_register_simple("omap-hdmi-audio",
1467 pdev->id, aud_res,
1468 ARRAY_SIZE(aud_res));
1469 if (IS_ERR(aud_pdev)) {
1470 DSSERR("Can't instantiate hdmi-audio\n");
1471 return -ENODEV;
1472 }
1474 hdmi.audio_pdev = aud_pdev;
1476 return 0;
1477 }
1479 int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
1480 {
1481 int r;
1482 u32 deep_color;
1483 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
1485 if (n == NULL || cts == NULL || sample_freq == 0)
1486 return -EINVAL;
1488 /* TODO: When implemented, query deep color mode here. */
1489 deep_color = 100;
1491 switch (sample_freq) {
1492 case 32000:
1493 if (deep_color == 125 && pclk == 74250) {
1494 *n = 8192;
1495 break;
1496 }
1498 if (deep_color == 125 && pclk == 27027) {
1499 /*
1500 * For this specific configuration, no value within the
1501 * allowed interval of N (as per the HDMI spec) will
1502 * produce an integer value of CTS. The value we use
1503 * here will produce CTS = 11587.000427246, which is
1504 * slightly larger than the integer. This difference
1505 * could cause the audio clock at the sink to slowly
1506 * drift. The true solution requires alternating between
1507 * two CTS relevant values with careful timing in order
1508 * to, on average, obtain the true CTS float value.
1509 */
1510 *n = 13529;
1511 break;
1512 }
1514 if (deep_color == 150 && pclk == 27027) {
1515 *n = 8192;
1516 break;
1517 }
1519 *n = 4096;
1520 break;
1521 case 44100:
1522 if (deep_color == 125 && pclk == 27027) {
1523 *n = 12544;
1524 break;
1525 }
1527 *n = 6272;
1528 break;
1529 case 48000:
1530 if (deep_color == 125 && (pclk == 27027 || pclk == 74250)) {
1531 *n = 8192;
1532 break;
1533 }
1535 if (deep_color == 150 && pclk == 27027) {
1536 *n = 8192;
1537 break;
1538 }
1540 *n = 6144;
1541 break;
1542 case 88200:
1543 r = hdmi_compute_acr(44100, n, cts);
1544 *n *= 2;
1545 return r;
1546 case 96000:
1547 r = hdmi_compute_acr(48000, n, cts);
1548 *n *= 2;
1549 return r;
1550 case 176400:
1551 r = hdmi_compute_acr(44100, n, cts);
1552 *n *= 4;
1553 return r;
1554 case 192000:
1555 r = hdmi_compute_acr(48000, n, cts);
1556 *n *= 4;
1557 return r;
1558 default:
1559 return -EINVAL;
1560 }
1562 /*
1563 * Calculate CTS. See HDMI 1.3a or 1.4a specifications. Preserve the
1564 * remainder in case N is not a multiple of 128.
1565 */
1566 *cts = (*n / 128) * pclk * deep_color;
1567 *cts += (*n % 128) * pclk * deep_color / 128;
1568 *cts /= (sample_freq / 10);
1570 if ((pclk * (*n / 128) * deep_color) % (sample_freq / 10))
1571 DSSWARN("CTS is not integer fs[%u]pclk[%u]N[%u]\n",
1572 sample_freq, pclk, *n);
1574 return 0;
1575 }
1577 int hdmi_audio_enable(void)
1578 {
1579 DSSDBG("audio_enable\n");
1581 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
1582 }
1584 void hdmi_audio_disable(void)
1585 {
1586 DSSDBG("audio_disable\n");
1588 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
1589 }
1591 int hdmi_audio_start(void)
1592 {
1593 DSSDBG("audio_start\n");
1595 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
1596 }
1598 void hdmi_audio_stop(void)
1599 {
1600 DSSDBG("audio_stop\n");
1602 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
1603 }
1605 bool hdmi_mode_has_audio(void)
1606 {
1607 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
1608 return true;
1609 else
1610 return false;
1611 }
1613 int hdmi_audio_config(struct omap_dss_audio *audio)
1614 {
1615 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
1616 }
1618 #endif
1620 static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
1621 {
1622 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
1623 const char *def_disp_name = omapdss_get_default_display_name();
1624 struct omap_dss_device *def_dssdev;
1625 int i;
1627 def_dssdev = NULL;
1629 for (i = 0; i < pdata->num_devices; ++i) {
1630 struct omap_dss_device *dssdev = pdata->devices[i];
1632 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
1633 continue;
1635 if (def_dssdev == NULL)
1636 def_dssdev = dssdev;
1638 if (def_disp_name != NULL &&
1639 strcmp(dssdev->name, def_disp_name) == 0) {
1640 def_dssdev = dssdev;
1641 break;
1642 }
1643 }
1645 return def_dssdev;
1646 }
1648 static void __init hdmi_probe_pdata(struct platform_device *pdev)
1649 {
1650 struct omap_dss_device *plat_dssdev;
1651 struct omap_dss_device *dssdev;
1652 struct omap_dss_hdmi_data *priv;
1653 int r;
1655 plat_dssdev = hdmi_find_dssdev(pdev);
1657 if (!plat_dssdev)
1658 return;
1660 dssdev = dss_alloc_and_init_device(&pdev->dev);
1661 if (!dssdev)
1662 return;
1664 dss_copy_device_pdata(dssdev, plat_dssdev);
1666 priv = dssdev->data;
1668 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
1669 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
1670 hdmi.hpd_gpio = priv->hpd_gpio;
1672 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
1674 r = hdmi_init_display(dssdev);
1675 if (r) {
1676 DSSERR("device %s init failed: %d\n", dssdev->name, r);
1677 dss_put_device(dssdev);
1678 return;
1679 }
1681 r = omapdss_output_set_device(&hdmi.output, dssdev);
1682 if (r) {
1683 DSSERR("failed to connect output to new device: %s\n",
1684 dssdev->name);
1685 dss_put_device(dssdev);
1686 return;
1687 }
1689 r = dss_add_device(dssdev);
1690 if (r) {
1691 DSSERR("device %s register failed: %d\n", dssdev->name, r);
1692 omapdss_output_unset_device(&hdmi.output);
1693 hdmi_uninit_display(dssdev);
1694 dss_put_device(dssdev);
1695 return;
1696 }
1697 }
1699 struct i2c_adapter *omapdss_hdmi_adapter(void)
1700 {
1701 return hdmi.adap;
1702 }
1704 static void ddc_set_sda(void *data, int state)
1705 {
1706 if (state)
1707 gpio_direction_input(hdmi.sda_pin);
1708 else
1709 gpio_direction_output(hdmi.sda_pin, 0);
1710 }
1712 static void ddc_set_scl(void *data, int state)
1713 {
1714 if (state)
1715 gpio_direction_input(hdmi.scl_pin);
1716 else
1717 gpio_direction_output(hdmi.scl_pin, 0);
1718 }
1720 static int ddc_get_sda(void *data)
1721 {
1722 return gpio_get_value(hdmi.sda_pin);
1723 }
1725 static int ddc_get_scl(void *data)
1726 {
1727 return gpio_get_value(hdmi.scl_pin);
1728 }
1730 static int ddc_pre_xfer(struct i2c_adapter *adap)
1731 {
1732 /* don't read if no hdmi connected */
1733 if (!gpio_get_value(hdmi.hpd_gpio))
1734 return -ENODEV;
1736 gpio_set_value_cansleep(hdmi.ls_oe_gpio, 1);
1738 return 0;
1739 }
1740 static void ddc_post_xfer(struct i2c_adapter *adap)
1741 {
1742 hdmi_set_ls_state(hdmi.ls_state);
1743 }
1745 static void ddc_i2c_init(struct platform_device *pdev)
1746 {
1748 hdmi.adap = kzalloc(sizeof(*hdmi.adap), GFP_KERNEL);
1750 if (!hdmi.adap) {
1751 pr_err("Failed to allocate i2c adapter\n");
1752 return;
1753 }
1755 hdmi.adap->owner = THIS_MODULE;
1756 hdmi.adap->class = I2C_CLASS_DDC;
1757 hdmi.adap->dev.parent = &pdev->dev;
1758 hdmi.adap->algo_data = &hdmi.bit_data;
1759 hdmi.adap->algo = &i2c_bit_algo;
1760 hdmi.bit_data.udelay = 2;
1761 hdmi.bit_data.timeout = HZ/10;
1762 hdmi.bit_data.setsda = ddc_set_sda;
1763 hdmi.bit_data.setscl = ddc_set_scl;
1764 hdmi.bit_data.getsda = ddc_get_sda;
1765 hdmi.bit_data.getscl = ddc_get_scl;
1766 hdmi.bit_data.pre_xfer = ddc_pre_xfer;
1767 hdmi.bit_data.post_xfer = ddc_post_xfer;
1769 gpio_request(hdmi.sda_pin, "DDC SDA");
1770 gpio_request(hdmi.scl_pin, "DDC SCL");
1771 snprintf(hdmi.adap->name, sizeof(hdmi.adap->name),
1772 "DSS DDC-EDID adapter");
1773 if (i2c_add_adapter(hdmi.adap)) {
1774 DSSERR("Cannot initialize DDC I2c\n");
1775 kfree(hdmi.adap);
1776 hdmi.adap = NULL;
1777 }
1778 }
1780 static void init_sel_i2c_hdmi(void)
1781 {
1782 void __iomem *clk_base = ioremap(0x4A009000, SZ_4K);
1783 void __iomem *mcasp2_base = ioremap(0x48464000, SZ_1K);
1784 void __iomem *pinmux = ioremap(0x4a003600, SZ_1K);
1785 u32 val;
1787 if (omapdss_get_version() != OMAPDSS_VER_DRA7xx)
1788 goto err;
1790 if (!clk_base || !mcasp2_base || !pinmux)
1791 DSSERR("couldn't ioremap for clk or mcasp2\n");
1793 __raw_writel(0x40000, pinmux + 0xfc);
1794 /* sw supervised wkup */
1795 __raw_writel(0x2, clk_base + 0x8fc);
1797 /* enable clock domain */
1798 __raw_writel(0x2, clk_base + 0x860);
1800 /* see what status looks like */
1801 val = __raw_readl(clk_base + 0x8fc);
1802 printk("CM_L4PER2_CLKSTCTRL %x\n", val);
1804 /*
1805 * mcasp2 regs should be hopefully accessible, make mcasp2_aclkr
1806 * a gpio, write necessary stuff to MCASP_PFUNC and PDIR
1807 */
1808 __raw_writel(0x1 << 29, mcasp2_base + 0x10);
1809 __raw_writel(0x1 << 29, mcasp2_base + 0x14);
1811 err:
1812 iounmap(clk_base);
1813 iounmap(mcasp2_base);
1814 iounmap(pinmux);
1815 }
1817 /* use this to configure the pcf8575@22 to set LS_OE and CT_HPD */
1818 void sel_i2c(void)
1819 {
1820 void __iomem *base = ioremap(0x48464000, SZ_1K);
1822 if (omapdss_get_version() != OMAPDSS_VER_DRA7xx)
1823 goto err;
1825 /* PDOUT */
1826 __raw_writel(0x0, base + 0x18);
1828 DSSDBG("PDOUT sel_i2c %x\n", __raw_readl(base + 0x18));
1830 err:
1831 iounmap(base);
1832 }
1834 /* use this to read edid and detect hpd ? */
1835 void sel_hdmi(void)
1836 {
1837 void __iomem *base = ioremap(0x48464000, SZ_1K);
1839 if (omapdss_get_version() != OMAPDSS_VER_DRA7xx)
1840 goto err;
1842 /* PDOUT */
1843 __raw_writel(0x20000000, base + 0x18);
1845 DSSDBG("PDOUT sel_hdmi %x\n", __raw_readl(base + 0x18));
1847 err:
1848 iounmap(base);
1849 }
1851 static void __init hdmi_probe_of(struct platform_device *pdev)
1852 {
1853 struct device_node *node = pdev->dev.of_node;
1854 struct device_node *child;
1855 struct omap_dss_device *dssdev;
1856 struct device_node *adapter_node;
1857 struct i2c_adapter *adapter = NULL;
1858 int r, gpio;
1859 enum omap_channel channel;
1860 u32 v;
1861 int gpio_count;
1863 r = of_property_read_u32(node, "video-source", &v);
1864 if (r) {
1865 DSSERR("parsing channel failed\n");
1866 return;
1867 }
1869 channel = v;
1871 node = of_find_compatible_node(node, NULL, "ti,tpd12s015");
1872 if (!node)
1873 return;
1875 child = of_get_next_available_child(node, NULL);
1876 if (!child)
1877 return;
1879 gpio_count = of_gpio_count(node);
1881 /* OMAP4 derivatives have 3 pins defined, OMAP5 derivatives have 5 */
1882 if (gpio_count != 5 && gpio_count != 3) {
1883 DSSERR("wrong number of GPIOs\n");
1884 return;
1885 }
1887 gpio = of_get_gpio(node, 0);
1888 if (gpio_is_valid(gpio)) {
1889 hdmi.ct_cp_hpd_gpio = gpio;
1890 } else {
1891 DSSERR("failed to parse CT CP HPD gpio\n");
1892 return;
1893 }
1895 gpio = of_get_gpio(node, 1);
1896 if (gpio_is_valid(gpio)) {
1897 hdmi.ls_oe_gpio = gpio;
1898 } else {
1899 DSSERR("failed to parse LS OE gpio\n");
1900 return;
1901 }
1903 gpio = of_get_gpio(node, 2);
1904 if (gpio_is_valid(gpio)) {
1905 hdmi.hpd_gpio = gpio;
1906 } else {
1907 DSSERR("failed to parse HPD gpio\n");
1908 return;
1909 }
1911 adapter_node = of_parse_phandle(node, "hdmi_ddc", 0);
1912 if (adapter_node)
1913 adapter = of_find_i2c_adapter_by_node(adapter_node);
1915 /*
1916 * if I2C SCL and SDA pins are defined, parse them, if an adapter is
1917 * present, use the i2c adapter rather than bitbanging i2c. If there
1918 * isn't an adapter either, assume that we are using the hdmi core IP's
1919 * ddc.
1920 */
1921 if (gpio_count == 5) {
1922 gpio = of_get_gpio(node, 3);
1923 if (gpio_is_valid(gpio)) {
1924 hdmi.scl_pin = gpio;
1925 } else {
1926 DSSERR("failed to parse SCL gpio\n");
1927 return;
1928 }
1930 gpio = of_get_gpio(node, 4);
1931 if (gpio_is_valid(gpio)) {
1932 hdmi.sda_pin = gpio;
1933 } else {
1934 DSSERR("failed to parse SDA gpio\n");
1935 return;
1936 }
1937 } else if (adapter != NULL) {
1938 hdmi.adap = adapter;
1940 /*
1941 * we have SEL_I2C_HDMI pin which acts as a control line to
1942 * a demux which choses the i2c lines to go either to hdmi
1943 * or to the other i2c2 slaves. This line is used as a mcasp2
1944 * gpio. Init the gpio pin so that it can be used to control
1945 * the demux.
1946 */
1947 init_sel_i2c_hdmi();
1948 sel_i2c();
1949 }
1951 dssdev = dss_alloc_and_init_device(&pdev->dev);
1952 if (!dssdev)
1953 return;
1955 dssdev->dev.of_node = child;
1956 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
1957 dssdev->name = child->name;
1958 dssdev->channel = channel;
1960 r = hdmi_init_display(dssdev);
1961 if (r) {
1962 DSSERR("device %s init failed: %d\n", dssdev->name, r);
1963 dss_put_device(dssdev);
1964 return;
1965 }
1967 r = omapdss_output_set_device(&hdmi.output, dssdev);
1968 if (r) {
1969 DSSERR("failed to connect output to new device: %s\n",
1970 dssdev->name);
1971 dss_put_device(dssdev);
1972 return;
1973 }
1975 r = dss_add_device(dssdev);
1976 if (r) {
1977 DSSERR("dss_add_device failed %d\n", r);
1978 dss_put_device(dssdev);
1979 return;
1980 }
1981 }
1983 static void __init hdmi_init_output(struct platform_device *pdev)
1984 {
1985 struct omap_dss_output *out = &hdmi.output;
1987 out->pdev = pdev;
1988 out->id = OMAP_DSS_OUTPUT_HDMI;
1989 out->type = OMAP_DISPLAY_TYPE_HDMI;
1991 dss_register_output(out);
1992 }
1994 static void __exit hdmi_uninit_output(struct platform_device *pdev)
1995 {
1996 struct omap_dss_output *out = &hdmi.output;
1998 dss_unregister_output(out);
1999 }
2001 /* HDMI HW IP initialisation */
2002 static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
2003 {
2004 struct resource *res;
2005 int r;
2007 hdmi.pdev = pdev;
2009 mutex_init(&hdmi.lock);
2010 mutex_init(&hdmi.ip_data.lock);
2012 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
2014 /* HDMI wrapper memory remap */
2015 res = platform_get_resource_byname(hdmi.pdev,
2016 IORESOURCE_MEM, "hdmi_wp");
2017 if (!res) {
2018 DSSERR("can't get WP IORESOURCE_MEM HDMI\n");
2019 return -EINVAL;
2020 }
2022 /* Base address taken from platform */
2023 hdmi.ip_data.base_wp = devm_request_and_ioremap(&pdev->dev, res);
2024 if (!hdmi.ip_data.base_wp) {
2025 DSSERR("can't ioremap WP\n");
2026 return -ENOMEM;
2027 }
2029 /* HDMI PLLCTRL memory remap */
2030 res = platform_get_resource_byname(hdmi.pdev,
2031 IORESOURCE_MEM, "pllctrl");
2032 if (!res) {
2033 DSSERR("can't get PLL CTRL IORESOURCE_MEM HDMI\n");
2034 return -EINVAL;
2035 }
2037 hdmi.ip_data.base_pllctrl = devm_request_and_ioremap(&pdev->dev, res);
2038 if (!hdmi.ip_data.base_pllctrl) {
2039 DSSERR("can't ioremap PLL ctrl\n");
2040 return -ENOMEM;
2041 }
2043 /* HDMI TXPHYCTRL memory remap */
2044 res = platform_get_resource_byname(hdmi.pdev,
2045 IORESOURCE_MEM, "hdmitxphy");
2046 if (!res) {
2047 DSSERR("can't get TXPHY CTRL IORESOURCE_MEM HDMI\n");
2048 return -EINVAL;
2049 }
2051 hdmi.ip_data.base_txphyctrl = devm_request_and_ioremap(&pdev->dev, res);
2052 if (!hdmi.ip_data.base_txphyctrl) {
2053 DSSERR("can't ioremap TXPHY ctrl\n");
2054 return -ENOMEM;
2055 }
2057 /* HDMI core memory remap */
2058 res = platform_get_resource_byname(hdmi.pdev,
2059 IORESOURCE_MEM, "hdmi_core");
2060 if (!res) {
2061 DSSERR("can't get core IORESOURCE_MEM HDMI\n");
2062 return -EINVAL;
2063 }
2065 hdmi.ip_data.base_core = devm_request_and_ioremap(&pdev->dev, res);
2066 if (!hdmi.ip_data.base_core) {
2067 DSSERR("can't ioremap core\n");
2068 return -ENOMEM;
2069 }
2071 r = hdmi_get_clocks(pdev);
2072 if (r) {
2073 DSSERR("can't get clocks\n");
2074 return r;
2075 }
2077 pm_runtime_enable(&pdev->dev);
2079 hdmi.hdmi_irq = platform_get_irq(pdev, 0);
2080 r = request_irq(hdmi.hdmi_irq, hdmi_irq_handler, 0, "OMAP HDMI", NULL);
2081 if (r < 0) {
2082 pr_err("hdmi: request_irq %s failed\n", pdev->name);
2083 return -EINVAL;
2084 }
2086 r = hdmi_panel_init();
2087 if (r) {
2088 DSSERR("can't init panel\n");
2089 goto err_panel_init;
2090 }
2092 hdmi.edid_set = false;
2094 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
2096 hdmi_init_output(pdev);
2098 if (pdev->dev.of_node)
2099 hdmi_probe_of(pdev);
2100 else if (pdev->dev.platform_data)
2101 hdmi_probe_pdata(pdev);
2103 /* if i2c pins defined, setup I2C adapter */
2104 if (hdmi.scl_pin && hdmi.sda_pin)
2105 ddc_i2c_init(pdev);
2107 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) || \
2108 defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
2109 r = hdmi_probe_audio(pdev);
2110 if (r)
2111 DSSWARN("could not create platform device for audio");
2112 #endif
2114 return 0;
2116 err_panel_init:
2117 hdmi_put_clocks();
2118 return r;
2119 }
2121 static int __exit hdmi_remove_child(struct device *dev, void *data)
2122 {
2123 struct omap_dss_device *dssdev = to_dss_device(dev);
2124 hdmi_uninit_display(dssdev);
2125 return 0;
2126 }
2128 static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
2129 {
2130 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) || \
2131 defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
2132 if (hdmi.audio_pdev != NULL)
2133 platform_device_unregister(hdmi.audio_pdev);
2134 #endif
2136 kfree(hdmi.adap);
2138 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
2140 dss_unregister_child_devices(&pdev->dev);
2142 hdmi_panel_exit();
2144 hdmi_uninit_output(pdev);
2146 pm_runtime_disable(&pdev->dev);
2148 hdmi_put_clocks();
2150 return 0;
2151 }
2153 static int hdmi_runtime_suspend(struct device *dev)
2154 {
2155 clk_disable_unprepare(hdmi.sys_clk);
2157 dispc_runtime_put();
2159 return 0;
2160 }
2162 static int hdmi_runtime_resume(struct device *dev)
2163 {
2164 int r;
2166 r = dispc_runtime_get();
2167 if (r < 0)
2168 return r;
2170 clk_prepare_enable(hdmi.sys_clk);
2172 return 0;
2173 }
2175 static const struct dev_pm_ops hdmi_pm_ops = {
2176 .runtime_suspend = hdmi_runtime_suspend,
2177 .runtime_resume = hdmi_runtime_resume,
2178 };
2180 #if defined(CONFIG_OF)
2181 static const struct of_device_id hdmi_of_match[] = {
2182 {
2183 .compatible = "ti,omap4-hdmi",
2184 },
2185 {},
2186 };
2187 #else
2188 #define hdmi_of_match NULL
2189 #endif
2191 static struct platform_driver omapdss_hdmihw_driver = {
2192 .remove = __exit_p(omapdss_hdmihw_remove),
2193 .driver = {
2194 .name = "omapdss_hdmi",
2195 .owner = THIS_MODULE,
2196 .pm = &hdmi_pm_ops,
2197 .of_match_table = hdmi_of_match,
2198 },
2199 };
2201 int __init hdmi_init_platform_driver(void)
2202 {
2203 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
2204 }
2206 void __exit hdmi_uninit_platform_driver(void)
2207 {
2208 platform_driver_unregister(&omapdss_hdmihw_driver);
2209 }