blob: 769d0828581ccfec1f350b49b8d1d791732e9b04 [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 Valkeinencca35012012-04-26 14:48:32 +030035#include <linux/gpio.h>
Tomi Valkeinen17486942012-08-15 15:55:04 +030036#include <linux/regulator/consumer.h>
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030037#include <video/omapdss.h>
Mythri P Kc3198a52011-03-12 12:04:27 +053038
Mythri P K94c52982011-09-08 19:06:21 +053039#include "ti_hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053040#include "dss.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050041#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053042
Mythri P K95a8aeb2011-09-08 19:06:18 +053043#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
Mythri P K7c1f1ec2011-09-08 19:06:22 +053049/* 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
Tomi Valkeinenb44e4582011-08-22 13:16:24 +030057#define HDMI_DEFAULT_REGN 16
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +030058#define HDMI_DEFAULT_REGM2 1
59
Mythri P Kc3198a52011-03-12 12:04:27 +053060static struct {
61 struct mutex lock;
Mythri P Kc3198a52011-03-12 12:04:27 +053062 struct platform_device *pdev;
Ricardo Neri66a06b02012-11-06 00:19:14 -060063
Mythri P K95a8aeb2011-09-08 19:06:18 +053064 struct hdmi_ip_data ip_data;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030065
66 struct clk *sys_clk;
Tomi Valkeinen17486942012-08-15 15:55:04 +030067 struct regulator *vdda_hdmi_dac_reg;
Tomi Valkeinencca35012012-04-26 14:48:32 +030068
69 int ct_cp_hpd_gpio;
70 int ls_oe_gpio;
71 int hpd_gpio;
Archit Taneja81b87f52012-09-26 16:30:49 +053072
73 struct omap_dss_output output;
Mythri P Kc3198a52011-03-12 12:04:27 +053074} hdmi;
75
76/*
77 * Logic for the below structure :
78 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
79 * There is a correspondence between CEA/VESA timing and code, please
80 * refer to section 6.3 in HDMI 1.3 specification for timing code.
81 *
82 * In the below structure, cea_vesa_timings corresponds to all OMAP4
83 * supported CEA and VESA timing values.code_cea corresponds to the CEA
84 * code, It is used to get the timing from cea_vesa_timing array.Similarly
85 * with code_vesa. Code_index is used for back mapping, that is once EDID
86 * is read from the TV, EDID is parsed to find the timing values and then
87 * map it to corresponding CEA or VESA index.
88 */
89
Mythri P K46095b22012-01-06 17:52:09 +053090static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053091 {
92 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
93 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
94 false, },
95 { 1, HDMI_HDMI },
96 },
97 {
98 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
99 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
100 false, },
101 { 2, HDMI_HDMI },
102 },
103 {
104 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
105 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
106 false, },
107 { 4, HDMI_HDMI },
108 },
109 {
110 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
111 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
112 true, },
113 { 5, HDMI_HDMI },
114 },
115 {
116 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
117 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
118 true, },
119 { 6, HDMI_HDMI },
120 },
121 {
122 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
123 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
124 false, },
125 { 16, HDMI_HDMI },
126 },
127 {
128 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
129 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
130 false, },
131 { 17, HDMI_HDMI },
132 },
133 {
134 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
135 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
136 false, },
137 { 19, HDMI_HDMI },
138 },
139 {
140 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
141 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
142 true, },
143 { 20, HDMI_HDMI },
144 },
145 {
146 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
147 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
148 true, },
149 { 21, HDMI_HDMI },
150 },
151 {
152 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
153 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
154 false, },
155 { 29, HDMI_HDMI },
156 },
157 {
158 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
159 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
160 false, },
161 { 31, HDMI_HDMI },
162 },
163 {
164 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
165 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
166 false, },
167 { 32, HDMI_HDMI },
168 },
169 {
170 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
171 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
172 false, },
173 { 35, HDMI_HDMI },
174 },
175 {
176 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
177 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
178 false, },
179 { 37, HDMI_HDMI },
180 },
Mythri P K46095b22012-01-06 17:52:09 +0530181};
Archit Tanejacc937e52012-06-24 13:08:10 +0530182
Mythri P K46095b22012-01-06 17:52:09 +0530183static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530184/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530185 {
186 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
187 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
188 false, },
189 { 4, HDMI_DVI },
190 },
191 {
192 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
193 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
194 false, },
195 { 9, HDMI_DVI },
196 },
197 {
198 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
199 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
200 false, },
201 { 0xE, HDMI_DVI },
202 },
203 {
204 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
205 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
206 false, },
207 { 0x17, HDMI_DVI },
208 },
209 {
210 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
211 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
212 false, },
213 { 0x1C, HDMI_DVI },
214 },
215 {
216 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
217 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
218 false, },
219 { 0x27, HDMI_DVI },
220 },
221 {
222 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
223 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
224 false, },
225 { 0x20, HDMI_DVI },
226 },
227 {
228 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
229 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
230 false, },
231 { 0x23, HDMI_DVI },
232 },
233 {
234 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
235 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
236 false, },
237 { 0x10, HDMI_DVI },
238 },
239 {
240 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
241 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
242 false, },
243 { 0x2A, HDMI_DVI },
244 },
245 {
246 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
247 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
248 false, },
249 { 0x2F, HDMI_DVI },
250 },
251 {
252 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
253 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
254 false, },
255 { 0x3A, HDMI_DVI },
256 },
257 {
258 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
259 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
260 false, },
261 { 0x51, HDMI_DVI },
262 },
263 {
264 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
265 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
266 false, },
267 { 0x52, HDMI_DVI },
268 },
269 {
270 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
271 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
272 false, },
273 { 0x16, HDMI_DVI },
274 },
275 {
276 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
277 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
278 false, },
279 { 0x29, HDMI_DVI },
280 },
281 {
282 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
283 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
284 false, },
285 { 0x39, HDMI_DVI },
286 },
287 {
288 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
289 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
290 false, },
291 { 0x1B, HDMI_DVI },
292 },
293 {
294 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
295 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
296 false, },
297 { 0x55, HDMI_DVI },
298 },
Tomi Valkeinen7a7ce2c2012-10-24 11:55:39 +0300299 {
300 { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
301 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
302 false, },
303 { 0x44, HDMI_DVI },
304 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530305};
306
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300307static int hdmi_runtime_get(void)
308{
309 int r;
310
311 DSSDBG("hdmi_runtime_get\n");
312
313 r = pm_runtime_get_sync(&hdmi.pdev->dev);
314 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +0530315 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200316 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +0530317
318 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300319}
320
321static void hdmi_runtime_put(void)
322{
323 int r;
324
325 DSSDBG("hdmi_runtime_put\n");
326
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200327 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300328 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300329}
330
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200331static int __init hdmi_init_display(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530332{
Tomi Valkeinencca35012012-04-26 14:48:32 +0300333 int r;
334
335 struct gpio gpios[] = {
336 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
337 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
338 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
339 };
340
Mythri P Kc3198a52011-03-12 12:04:27 +0530341 DSSDBG("init_display\n");
342
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +0300343 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
Tomi Valkeinencca35012012-04-26 14:48:32 +0300344
Tomi Valkeinen17486942012-08-15 15:55:04 +0300345 if (hdmi.vdda_hdmi_dac_reg == NULL) {
346 struct regulator *reg;
347
348 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
349
Tomi Valkeinen76eed4b2012-11-05 13:41:25 +0200350 /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
351 if (IS_ERR(reg))
352 reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
353
Tomi Valkeinen17486942012-08-15 15:55:04 +0300354 if (IS_ERR(reg)) {
355 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
356 return PTR_ERR(reg);
357 }
358
359 hdmi.vdda_hdmi_dac_reg = reg;
360 }
361
Tomi Valkeinencca35012012-04-26 14:48:32 +0300362 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
363 if (r)
364 return r;
365
Mythri P Kc3198a52011-03-12 12:04:27 +0530366 return 0;
367}
368
Ricardo Neri37584762012-11-06 21:37:14 -0600369static void hdmi_uninit_display(struct omap_dss_device *dssdev)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300370{
371 DSSDBG("uninit_display\n");
372
373 gpio_free(hdmi.ct_cp_hpd_gpio);
374 gpio_free(hdmi.ls_oe_gpio);
375 gpio_free(hdmi.hpd_gpio);
376}
377
Mythri P K46095b22012-01-06 17:52:09 +0530378static const struct hdmi_config *hdmi_find_timing(
379 const struct hdmi_config *timings_arr,
380 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530381{
Mythri P K46095b22012-01-06 17:52:09 +0530382 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530383
Mythri P K46095b22012-01-06 17:52:09 +0530384 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530385 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530386 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530387 }
Mythri P K46095b22012-01-06 17:52:09 +0530388 return NULL;
389}
390
391static const struct hdmi_config *hdmi_get_timings(void)
392{
393 const struct hdmi_config *arr;
394 int len;
395
Mythri P K9e4ed602012-01-06 17:52:10 +0530396 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530397 arr = vesa_timings;
398 len = ARRAY_SIZE(vesa_timings);
399 } else {
400 arr = cea_timings;
401 len = ARRAY_SIZE(cea_timings);
402 }
403
404 return hdmi_find_timing(arr, len);
405}
406
407static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530408 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530409{
410 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
411
Tomi Valkeinenf236b892012-10-24 11:55:54 +0300412 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
413 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
Mythri P K46095b22012-01-06 17:52:09 +0530414 (timing2->x_res == timing1->x_res) &&
415 (timing2->y_res == timing1->y_res)) {
416
417 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
418 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
419 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
420 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
421
422 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
423 "timing2_hsync = %d timing2_vsync = %d\n",
424 timing1_hsync, timing1_vsync,
425 timing2_hsync, timing2_vsync);
426
427 if ((timing1_hsync == timing2_hsync) &&
428 (timing1_vsync == timing2_vsync)) {
429 return true;
430 }
431 }
432 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530433}
434
435static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
436{
Mythri P K46095b22012-01-06 17:52:09 +0530437 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530438 struct hdmi_cm cm = {-1};
439 DSSDBG("hdmi_get_code\n");
440
Mythri P K46095b22012-01-06 17:52:09 +0530441 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
442 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
443 cm = cea_timings[i].cm;
444 goto end;
445 }
446 }
447 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
448 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
449 cm = vesa_timings[i].cm;
450 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530451 }
452 }
453
Mythri P K46095b22012-01-06 17:52:09 +0530454end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530455
Mythri P Kc3198a52011-03-12 12:04:27 +0530456}
457
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530458unsigned long hdmi_get_pixel_clock(void)
459{
460 /* HDMI Pixel Clock in Mhz */
Mythri P Ka05ce782012-01-06 17:52:08 +0530461 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530462}
463
Archit Taneja6cb07b22011-04-12 13:52:25 +0530464static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
465 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530466{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530467 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530468 u32 mf;
469
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300470 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530471 /*
472 * Input clock is predivided by N + 1
473 * out put of which is reference clk
474 */
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300475 if (dssdev->clocks.hdmi.regn == 0)
476 pi->regn = HDMI_DEFAULT_REGN;
477 else
478 pi->regn = dssdev->clocks.hdmi.regn;
479
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300480 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530481
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300482 if (dssdev->clocks.hdmi.regm2 == 0)
483 pi->regm2 = HDMI_DEFAULT_REGM2;
484 else
485 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530486
487 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530488 * multiplier is pixel_clk/ref_clk
489 * Multiplying by 100 to avoid fractional part removal
490 */
491 pi->regm = phy * pi->regm2 / refclk;
492
493 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530494 * fractional multiplier is remainder of the difference between
495 * multiplier and actual phy(required pixel clock thus should be
496 * multiplied by 2^18(262144) divided by the reference clock
497 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530498 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
499 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530500
501 /*
502 * Dcofreq should be set to 1 if required pixel clock
503 * is greater than 1000MHz
504 */
505 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300506 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530507
Mythri P K7b27da52011-09-08 19:06:19 +0530508 /* Set the reference clock to sysclk reference */
509 pi->refsel = HDMI_REFSEL_SYSCLK;
510
Mythri P Kc3198a52011-03-12 12:04:27 +0530511 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
512 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
513}
514
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300515static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530516{
Mythri P K46095b22012-01-06 17:52:09 +0530517 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530518
Tomi Valkeinencca35012012-04-26 14:48:32 +0300519 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
520 gpio_set_value(hdmi.ls_oe_gpio, 1);
521
Tomi Valkeinena84b20654b2012-04-26 14:58:41 +0300522 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
523 udelay(300);
524
Tomi Valkeinen17486942012-08-15 15:55:04 +0300525 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
526 if (r)
527 goto err_vdac_enable;
528
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300529 r = hdmi_runtime_get();
530 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300531 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530532
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300533 /* Make selection of HDMI in DSS */
534 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
535
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300536 return 0;
537
538err_runtime_get:
539 regulator_disable(hdmi.vdda_hdmi_dac_reg);
540err_vdac_enable:
541 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
542 gpio_set_value(hdmi.ls_oe_gpio, 0);
543 return r;
544}
545
546static void hdmi_power_off_core(struct omap_dss_device *dssdev)
547{
548 hdmi_runtime_put();
549 regulator_disable(hdmi.vdda_hdmi_dac_reg);
550 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
551 gpio_set_value(hdmi.ls_oe_gpio, 0);
552}
553
554static int hdmi_power_on_full(struct omap_dss_device *dssdev)
555{
556 int r;
557 struct omap_video_timings *p;
558 struct omap_overlay_manager *mgr = dssdev->output->manager;
559 unsigned long phy;
560
561 r = hdmi_power_on_core(dssdev);
562 if (r)
563 return r;
564
Archit Tanejacea87b92012-09-07 17:56:20 +0530565 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530566
Archit Taneja78493982012-08-08 16:50:42 +0530567 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530568
Archit Taneja78493982012-08-08 16:50:42 +0530569 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
Mythri P Kc3198a52011-03-12 12:04:27 +0530570
Mythri P Kc3198a52011-03-12 12:04:27 +0530571 phy = p->pixel_clock;
572
Mythri P K7b27da52011-09-08 19:06:19 +0530573 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530574
Ricardo Neric0456be2012-04-27 13:48:45 -0500575 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530576
Mythri P K95a8aeb2011-09-08 19:06:18 +0530577 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530578 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530579 if (r) {
580 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300581 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530582 }
583
Mythri P K60634a22011-09-08 19:06:26 +0530584 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530585 if (r) {
586 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500587 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530588 }
589
Mythri P K60634a22011-09-08 19:06:26 +0530590 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530591
Mythri P Kc3198a52011-03-12 12:04:27 +0530592 /* bypass TV gamma table */
593 dispc_enable_gamma_table(0);
594
595 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530596 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530597
Ricardo Neric0456be2012-04-27 13:48:45 -0500598 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
599 if (r)
600 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530601
Archit Tanejacea87b92012-09-07 17:56:20 +0530602 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200603 if (r)
604 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300605
Mythri P Kc3198a52011-03-12 12:04:27 +0530606 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200607
608err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500609 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
610err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200611 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500612err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200613 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300614err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300615 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530616 return -EIO;
617}
618
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300619static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530620{
Archit Tanejacea87b92012-09-07 17:56:20 +0530621 struct omap_overlay_manager *mgr = dssdev->output->manager;
622
623 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530624
Ricardo Neric0456be2012-04-27 13:48:45 -0500625 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P K60634a22011-09-08 19:06:26 +0530626 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
627 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300628
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300629 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530630}
631
632int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
633 struct omap_video_timings *timings)
634{
635 struct hdmi_cm cm;
636
637 cm = hdmi_get_code(timings);
638 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530639 return -EINVAL;
640 }
641
642 return 0;
643
644}
645
Archit Taneja78493982012-08-08 16:50:42 +0530646void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
647 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530648{
649 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530650 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530651
Archit Tanejaed1aa902012-08-15 00:40:31 +0530652 mutex_lock(&hdmi.lock);
653
Archit Taneja78493982012-08-08 16:50:42 +0530654 cm = hdmi_get_code(timings);
655 hdmi.ip_data.cfg.cm = cm;
656
657 t = hdmi_get_timings();
658 if (t != NULL)
659 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300660
Archit Tanejaed1aa902012-08-15 00:40:31 +0530661 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530662}
663
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200664static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530665{
666 mutex_lock(&hdmi.lock);
667
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800668 if (hdmi_runtime_get()) {
669 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530670 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800671 }
Mythri P K162874d2011-09-22 13:37:45 +0530672
673 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
674 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
675 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
676 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
677
678 hdmi_runtime_put();
679 mutex_unlock(&hdmi.lock);
680}
681
Tomi Valkeinen47024562011-08-25 17:12:56 +0300682int omapdss_hdmi_read_edid(u8 *buf, int len)
683{
684 int r;
685
686 mutex_lock(&hdmi.lock);
687
688 r = hdmi_runtime_get();
689 BUG_ON(r);
690
691 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
692
693 hdmi_runtime_put();
694 mutex_unlock(&hdmi.lock);
695
696 return r;
697}
698
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300699bool omapdss_hdmi_detect(void)
700{
701 int r;
702
703 mutex_lock(&hdmi.lock);
704
705 r = hdmi_runtime_get();
706 BUG_ON(r);
707
708 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
709
710 hdmi_runtime_put();
711 mutex_unlock(&hdmi.lock);
712
713 return r == 1;
714}
715
Mythri P Kc3198a52011-03-12 12:04:27 +0530716int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
717{
Archit Tanejacea87b92012-09-07 17:56:20 +0530718 struct omap_dss_output *out = dssdev->output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530719 int r = 0;
720
721 DSSDBG("ENTER hdmi_display_enable\n");
722
723 mutex_lock(&hdmi.lock);
724
Archit Tanejacea87b92012-09-07 17:56:20 +0530725 if (out == NULL || out->manager == NULL) {
726 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300727 r = -ENODEV;
728 goto err0;
729 }
730
Tomi Valkeinencca35012012-04-26 14:48:32 +0300731 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
Tomi Valkeinenc49d0052012-01-17 11:09:57 +0200732
Mythri P Kc3198a52011-03-12 12:04:27 +0530733 r = omap_dss_start_device(dssdev);
734 if (r) {
735 DSSERR("failed to start device\n");
736 goto err0;
737 }
738
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300739 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530740 if (r) {
741 DSSERR("failed to power on device\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300742 goto err1;
Mythri P Kc3198a52011-03-12 12:04:27 +0530743 }
744
745 mutex_unlock(&hdmi.lock);
746 return 0;
747
Mythri P Kc3198a52011-03-12 12:04:27 +0530748err1:
749 omap_dss_stop_device(dssdev);
750err0:
751 mutex_unlock(&hdmi.lock);
752 return r;
753}
754
755void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
756{
757 DSSDBG("Enter hdmi_display_disable\n");
758
759 mutex_lock(&hdmi.lock);
760
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300761 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530762
Mythri P Kc3198a52011-03-12 12:04:27 +0530763 omap_dss_stop_device(dssdev);
764
765 mutex_unlock(&hdmi.lock);
766}
767
Tomi Valkeinen44898232012-10-19 17:42:27 +0300768int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
769{
770 int r = 0;
771
772 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
773
774 mutex_lock(&hdmi.lock);
775
776 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
777
778 r = hdmi_power_on_core(dssdev);
779 if (r) {
780 DSSERR("failed to power on device\n");
781 goto err0;
782 }
783
784 mutex_unlock(&hdmi.lock);
785 return 0;
786
787err0:
788 mutex_unlock(&hdmi.lock);
789 return r;
790}
791
792void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
793{
794 DSSDBG("Enter omapdss_hdmi_core_disable\n");
795
796 mutex_lock(&hdmi.lock);
797
798 hdmi_power_off_core(dssdev);
799
800 mutex_unlock(&hdmi.lock);
801}
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
Ricardo Neri35547622012-03-20 21:02:01 -0600824#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
825int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
826{
827 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600828 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600829 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
830
831 if (n == NULL || cts == NULL)
832 return -EINVAL;
833
834 /* TODO: When implemented, query deep color mode here. */
835 deep_color = 100;
836
Ricardo Neri25a65352012-03-23 15:49:02 -0600837 /*
838 * When using deep color, the default N value (as in the HDMI
839 * specification) yields to an non-integer CTS. Hence, we
840 * modify it while keeping the restrictions described in
841 * section 7.2.1 of the HDMI 1.4a specification.
842 */
Ricardo Neri35547622012-03-20 21:02:01 -0600843 switch (sample_freq) {
844 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600845 case 48000:
846 case 96000:
847 case 192000:
848 if (deep_color == 125)
849 if (pclk == 27027 || pclk == 74250)
850 deep_color_correct = true;
851 if (deep_color == 150)
852 if (pclk == 27027)
853 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600854 break;
855 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600856 case 88200:
857 case 176400:
858 if (deep_color == 125)
859 if (pclk == 27027)
860 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600861 break;
862 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600863 return -EINVAL;
864 }
865
Ricardo Neri25a65352012-03-23 15:49:02 -0600866 if (deep_color_correct) {
867 switch (sample_freq) {
868 case 32000:
869 *n = 8192;
870 break;
871 case 44100:
872 *n = 12544;
873 break;
874 case 48000:
875 *n = 8192;
876 break;
877 case 88200:
878 *n = 25088;
879 break;
880 case 96000:
881 *n = 16384;
882 break;
883 case 176400:
884 *n = 50176;
885 break;
886 case 192000:
887 *n = 32768;
888 break;
889 default:
890 return -EINVAL;
891 }
892 } else {
893 switch (sample_freq) {
894 case 32000:
895 *n = 4096;
896 break;
897 case 44100:
898 *n = 6272;
899 break;
900 case 48000:
901 *n = 6144;
902 break;
903 case 88200:
904 *n = 12544;
905 break;
906 case 96000:
907 *n = 12288;
908 break;
909 case 176400:
910 *n = 25088;
911 break;
912 case 192000:
913 *n = 24576;
914 break;
915 default:
916 return -EINVAL;
917 }
918 }
Ricardo Neri35547622012-03-20 21:02:01 -0600919 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
920 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
921
922 return 0;
923}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500924
925int hdmi_audio_enable(void)
926{
927 DSSDBG("audio_enable\n");
928
929 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
930}
931
932void hdmi_audio_disable(void)
933{
934 DSSDBG("audio_disable\n");
935
936 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
937}
938
939int hdmi_audio_start(void)
940{
941 DSSDBG("audio_start\n");
942
943 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
944}
945
946void hdmi_audio_stop(void)
947{
948 DSSDBG("audio_stop\n");
949
950 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
951}
952
953bool hdmi_mode_has_audio(void)
954{
955 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
956 return true;
957 else
958 return false;
959}
960
961int hdmi_audio_config(struct omap_dss_audio *audio)
962{
963 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
964}
965
Ricardo Neri35547622012-03-20 21:02:01 -0600966#endif
967
Tomi Valkeinen15216532012-09-06 14:29:31 +0300968static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300969{
970 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Tomi Valkeinen2bbcce52012-10-29 12:40:46 +0200971 const char *def_disp_name = omapdss_get_default_display_name();
Tomi Valkeinen15216532012-09-06 14:29:31 +0300972 struct omap_dss_device *def_dssdev;
973 int i;
974
975 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300976
977 for (i = 0; i < pdata->num_devices; ++i) {
978 struct omap_dss_device *dssdev = pdata->devices[i];
979
980 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
981 continue;
982
Tomi Valkeinen15216532012-09-06 14:29:31 +0300983 if (def_dssdev == NULL)
984 def_dssdev = dssdev;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300985
Tomi Valkeinen15216532012-09-06 14:29:31 +0300986 if (def_disp_name != NULL &&
987 strcmp(dssdev->name, def_disp_name) == 0) {
988 def_dssdev = dssdev;
989 break;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300990 }
Tomi Valkeinen15216532012-09-06 14:29:31 +0300991 }
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300992
Tomi Valkeinen15216532012-09-06 14:29:31 +0300993 return def_dssdev;
994}
995
996static void __init hdmi_probe_pdata(struct platform_device *pdev)
997{
Tomi Valkeinen52744842012-09-10 13:58:29 +0300998 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300999 struct omap_dss_device *dssdev;
1000 struct omap_dss_hdmi_data *priv;
1001 int r;
1002
Tomi Valkeinen52744842012-09-10 13:58:29 +03001003 plat_dssdev = hdmi_find_dssdev(pdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001004
Tomi Valkeinen52744842012-09-10 13:58:29 +03001005 if (!plat_dssdev)
1006 return;
1007
1008 dssdev = dss_alloc_and_init_device(&pdev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001009 if (!dssdev)
1010 return;
1011
Tomi Valkeinen52744842012-09-10 13:58:29 +03001012 dss_copy_device_pdata(dssdev, plat_dssdev);
1013
Tomi Valkeinen15216532012-09-06 14:29:31 +03001014 priv = dssdev->data;
1015
1016 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
1017 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
1018 hdmi.hpd_gpio = priv->hpd_gpio;
1019
Tomi Valkeinenbcb226a2012-09-07 15:21:36 +03001020 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
1021
Tomi Valkeinen15216532012-09-06 14:29:31 +03001022 r = hdmi_init_display(dssdev);
1023 if (r) {
1024 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +03001025 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001026 return;
1027 }
1028
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02001029 r = omapdss_output_set_device(&hdmi.output, dssdev);
1030 if (r) {
1031 DSSERR("failed to connect output to new device: %s\n",
1032 dssdev->name);
1033 dss_put_device(dssdev);
1034 return;
1035 }
1036
Tomi Valkeinen52744842012-09-10 13:58:29 +03001037 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001038 if (r) {
1039 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02001040 omapdss_output_unset_device(&hdmi.output);
Ricardo Nerid18bc452012-11-06 00:19:15 -06001041 hdmi_uninit_display(dssdev);
Tomi Valkeinen52744842012-09-10 13:58:29 +03001042 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001043 return;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001044 }
1045}
1046
Archit Taneja81b87f52012-09-26 16:30:49 +05301047static void __init hdmi_init_output(struct platform_device *pdev)
1048{
1049 struct omap_dss_output *out = &hdmi.output;
1050
1051 out->pdev = pdev;
1052 out->id = OMAP_DSS_OUTPUT_HDMI;
1053 out->type = OMAP_DISPLAY_TYPE_HDMI;
1054
1055 dss_register_output(out);
1056}
1057
1058static void __exit hdmi_uninit_output(struct platform_device *pdev)
1059{
1060 struct omap_dss_output *out = &hdmi.output;
1061
1062 dss_unregister_output(out);
1063}
1064
Mythri P Kc3198a52011-03-12 12:04:27 +05301065/* HDMI HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001066static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301067{
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001068 struct resource *res;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001069 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301070
Mythri P Kc3198a52011-03-12 12:04:27 +05301071 hdmi.pdev = pdev;
1072
1073 mutex_init(&hdmi.lock);
Ricardo Neri66a06b02012-11-06 00:19:14 -06001074 mutex_init(&hdmi.ip_data.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +05301075
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001076 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1077 if (!res) {
Mythri P Kc3198a52011-03-12 12:04:27 +05301078 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1079 return -EINVAL;
1080 }
1081
1082 /* Base address taken from platform */
Ricardo Neri47e443b2012-11-06 00:19:12 -06001083 hdmi.ip_data.base_wp = devm_request_and_ioremap(&pdev->dev, res);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301084 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +05301085 DSSERR("can't ioremap WP\n");
1086 return -ENOMEM;
1087 }
1088
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001089 r = hdmi_get_clocks(pdev);
1090 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -06001091 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001092 return r;
1093 }
1094
1095 pm_runtime_enable(&pdev->dev);
1096
Mythri P K95a8aeb2011-09-08 19:06:18 +05301097 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1098 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1099 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1100 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +05301101
Ricardo Neri66a06b02012-11-06 00:19:14 -06001102 r = hdmi_panel_init();
1103 if (r) {
1104 DSSERR("can't init panel\n");
1105 goto err_panel_init;
1106 }
Mythri P Kc3198a52011-03-12 12:04:27 +05301107
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001108 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1109
Archit Taneja81b87f52012-09-26 16:30:49 +05301110 hdmi_init_output(pdev);
1111
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001112 hdmi_probe_pdata(pdev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001113
Mythri P Kc3198a52011-03-12 12:04:27 +05301114 return 0;
Ricardo Neri66a06b02012-11-06 00:19:14 -06001115
1116err_panel_init:
1117 hdmi_put_clocks();
1118 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301119}
1120
Tomi Valkeinencca35012012-04-26 14:48:32 +03001121static int __exit hdmi_remove_child(struct device *dev, void *data)
1122{
1123 struct omap_dss_device *dssdev = to_dss_device(dev);
1124 hdmi_uninit_display(dssdev);
1125 return 0;
1126}
1127
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001128static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301129{
Tomi Valkeinencca35012012-04-26 14:48:32 +03001130 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1131
Tomi Valkeinen52744842012-09-10 13:58:29 +03001132 dss_unregister_child_devices(&pdev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001133
Mythri P Kc3198a52011-03-12 12:04:27 +05301134 hdmi_panel_exit();
1135
Archit Taneja81b87f52012-09-26 16:30:49 +05301136 hdmi_uninit_output(pdev);
1137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001138 pm_runtime_disable(&pdev->dev);
1139
1140 hdmi_put_clocks();
1141
Mythri P Kc3198a52011-03-12 12:04:27 +05301142 return 0;
1143}
1144
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001145static int hdmi_runtime_suspend(struct device *dev)
1146{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301147 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001148
1149 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001150
1151 return 0;
1152}
1153
1154static int hdmi_runtime_resume(struct device *dev)
1155{
1156 int r;
1157
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001158 r = dispc_runtime_get();
1159 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001160 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001161
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301162 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001163
1164 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001165}
1166
1167static const struct dev_pm_ops hdmi_pm_ops = {
1168 .runtime_suspend = hdmi_runtime_suspend,
1169 .runtime_resume = hdmi_runtime_resume,
1170};
1171
Mythri P Kc3198a52011-03-12 12:04:27 +05301172static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001173 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301174 .driver = {
1175 .name = "omapdss_hdmi",
1176 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001177 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301178 },
1179};
1180
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001181int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301182{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02001183 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
Mythri P Kc3198a52011-03-12 12:04:27 +05301184}
1185
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001186void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301187{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001188 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301189}