blob: 0e9ecd691c5c71d32d6a45b0c217c97aafdb789c [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"
Archit Taneja425f02f2013-10-08 14:16:05 +053040#include "ti_hdmi_4xxx_ip.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053041#include "dss.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050042#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053043
Mythri P K7c1f1ec2011-09-08 19:06:22 +053044/* HDMI EDID Length move this */
45#define HDMI_EDID_MAX_LENGTH 256
46#define EDID_TIMING_DESCRIPTOR_SIZE 0x12
47#define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
48#define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
49#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
50#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
51
Mythri P Kc3198a52011-03-12 12:04:27 +053052static struct {
53 struct mutex lock;
Mythri P Kc3198a52011-03-12 12:04:27 +053054 struct platform_device *pdev;
Ricardo Neri66a06b02012-11-06 00:19:14 -060055
Mythri P K95a8aeb2011-09-08 19:06:18 +053056 struct hdmi_ip_data ip_data;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030057
58 struct clk *sys_clk;
Tomi Valkeinen17486942012-08-15 15:55:04 +030059 struct regulator *vdda_hdmi_dac_reg;
Tomi Valkeinencca35012012-04-26 14:48:32 +030060
Tomi Valkeinen0b450c32013-05-24 13:20:17 +030061 bool core_enabled;
62
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030063 struct omap_dss_device output;
Mythri P Kc3198a52011-03-12 12:04:27 +053064} hdmi;
65
66/*
67 * Logic for the below structure :
68 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
69 * There is a correspondence between CEA/VESA timing and code, please
70 * refer to section 6.3 in HDMI 1.3 specification for timing code.
71 *
72 * In the below structure, cea_vesa_timings corresponds to all OMAP4
73 * supported CEA and VESA timing values.code_cea corresponds to the CEA
74 * code, It is used to get the timing from cea_vesa_timing array.Similarly
75 * with code_vesa. Code_index is used for back mapping, that is once EDID
76 * is read from the TV, EDID is parsed to find the timing values and then
77 * map it to corresponding CEA or VESA index.
78 */
79
Mythri P K46095b22012-01-06 17:52:09 +053080static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053081 {
82 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
83 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
84 false, },
85 { 1, HDMI_HDMI },
86 },
87 {
88 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
89 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
90 false, },
91 { 2, HDMI_HDMI },
92 },
93 {
94 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
95 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
96 false, },
97 { 4, HDMI_HDMI },
98 },
99 {
100 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
101 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
102 true, },
103 { 5, HDMI_HDMI },
104 },
105 {
106 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
107 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
108 true, },
109 { 6, HDMI_HDMI },
110 },
111 {
112 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
113 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
114 false, },
115 { 16, HDMI_HDMI },
116 },
117 {
118 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
119 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
120 false, },
121 { 17, HDMI_HDMI },
122 },
123 {
124 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
125 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
126 false, },
127 { 19, HDMI_HDMI },
128 },
129 {
130 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
131 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
132 true, },
133 { 20, HDMI_HDMI },
134 },
135 {
136 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
137 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
138 true, },
139 { 21, HDMI_HDMI },
140 },
141 {
142 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
143 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
144 false, },
145 { 29, HDMI_HDMI },
146 },
147 {
148 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
149 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
150 false, },
151 { 31, HDMI_HDMI },
152 },
153 {
154 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
155 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
156 false, },
157 { 32, HDMI_HDMI },
158 },
159 {
160 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
161 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
162 false, },
163 { 35, HDMI_HDMI },
164 },
165 {
166 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
167 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
168 false, },
169 { 37, HDMI_HDMI },
170 },
Mythri P K46095b22012-01-06 17:52:09 +0530171};
Archit Tanejacc937e52012-06-24 13:08:10 +0530172
Mythri P K46095b22012-01-06 17:52:09 +0530173static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530174/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530175 {
176 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
177 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
178 false, },
179 { 4, HDMI_DVI },
180 },
181 {
182 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
183 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
184 false, },
185 { 9, HDMI_DVI },
186 },
187 {
188 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
189 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
190 false, },
191 { 0xE, HDMI_DVI },
192 },
193 {
194 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
195 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
196 false, },
197 { 0x17, HDMI_DVI },
198 },
199 {
200 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
201 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
202 false, },
203 { 0x1C, HDMI_DVI },
204 },
205 {
206 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
207 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
208 false, },
209 { 0x27, HDMI_DVI },
210 },
211 {
212 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
213 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
214 false, },
215 { 0x20, HDMI_DVI },
216 },
217 {
218 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
219 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
220 false, },
221 { 0x23, HDMI_DVI },
222 },
223 {
224 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
225 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
226 false, },
227 { 0x10, HDMI_DVI },
228 },
229 {
230 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
231 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
232 false, },
233 { 0x2A, HDMI_DVI },
234 },
235 {
236 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
237 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
238 false, },
239 { 0x2F, HDMI_DVI },
240 },
241 {
242 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
243 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
244 false, },
245 { 0x3A, HDMI_DVI },
246 },
247 {
248 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
249 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
250 false, },
251 { 0x51, HDMI_DVI },
252 },
253 {
254 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
255 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
256 false, },
257 { 0x52, HDMI_DVI },
258 },
259 {
260 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
261 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
262 false, },
263 { 0x16, HDMI_DVI },
264 },
265 {
266 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
267 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
268 false, },
269 { 0x29, HDMI_DVI },
270 },
271 {
272 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
273 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
274 false, },
275 { 0x39, HDMI_DVI },
276 },
277 {
278 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
279 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
280 false, },
281 { 0x1B, HDMI_DVI },
282 },
283 {
284 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
285 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
286 false, },
287 { 0x55, HDMI_DVI },
288 },
Tomi Valkeinen7a7ce2c2012-10-24 11:55:39 +0300289 {
290 { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
291 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
292 false, },
293 { 0x44, HDMI_DVI },
294 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530295};
296
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300297static int hdmi_runtime_get(void)
298{
299 int r;
300
301 DSSDBG("hdmi_runtime_get\n");
302
303 r = pm_runtime_get_sync(&hdmi.pdev->dev);
304 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +0530305 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200306 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +0530307
308 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300309}
310
311static void hdmi_runtime_put(void)
312{
313 int r;
314
315 DSSDBG("hdmi_runtime_put\n");
316
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200317 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300318 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300319}
320
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300321static int hdmi_init_regulator(void)
322{
323 struct regulator *reg;
324
325 if (hdmi.vdda_hdmi_dac_reg != NULL)
326 return 0;
327
328 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
329
330 /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
331 if (IS_ERR(reg))
332 reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
333
334 if (IS_ERR(reg)) {
335 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
336 return PTR_ERR(reg);
337 }
338
339 hdmi.vdda_hdmi_dac_reg = reg;
340
341 return 0;
342}
343
Mythri P K46095b22012-01-06 17:52:09 +0530344static const struct hdmi_config *hdmi_find_timing(
345 const struct hdmi_config *timings_arr,
346 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530347{
Mythri P K46095b22012-01-06 17:52:09 +0530348 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530349
Mythri P K46095b22012-01-06 17:52:09 +0530350 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530351 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530352 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530353 }
Mythri P K46095b22012-01-06 17:52:09 +0530354 return NULL;
355}
356
357static const struct hdmi_config *hdmi_get_timings(void)
358{
359 const struct hdmi_config *arr;
360 int len;
361
Mythri P K9e4ed602012-01-06 17:52:10 +0530362 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530363 arr = vesa_timings;
364 len = ARRAY_SIZE(vesa_timings);
365 } else {
366 arr = cea_timings;
367 len = ARRAY_SIZE(cea_timings);
368 }
369
370 return hdmi_find_timing(arr, len);
371}
372
373static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530374 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530375{
376 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
377
Tomi Valkeinenf236b892012-10-24 11:55:54 +0300378 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
379 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
Mythri P K46095b22012-01-06 17:52:09 +0530380 (timing2->x_res == timing1->x_res) &&
381 (timing2->y_res == timing1->y_res)) {
382
383 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
384 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
385 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
386 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
387
388 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
389 "timing2_hsync = %d timing2_vsync = %d\n",
390 timing1_hsync, timing1_vsync,
391 timing2_hsync, timing2_vsync);
392
393 if ((timing1_hsync == timing2_hsync) &&
394 (timing1_vsync == timing2_vsync)) {
395 return true;
396 }
397 }
398 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530399}
400
401static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
402{
Mythri P K46095b22012-01-06 17:52:09 +0530403 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530404 struct hdmi_cm cm = {-1};
405 DSSDBG("hdmi_get_code\n");
406
Mythri P K46095b22012-01-06 17:52:09 +0530407 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
408 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
409 cm = cea_timings[i].cm;
410 goto end;
411 }
412 }
413 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
414 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
415 cm = vesa_timings[i].cm;
416 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530417 }
418 }
419
Mythri P K46095b22012-01-06 17:52:09 +0530420end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530421
Mythri P Kc3198a52011-03-12 12:04:27 +0530422}
423
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300424static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530425{
Mythri P K46095b22012-01-06 17:52:09 +0530426 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530427
Tomi Valkeinen17486942012-08-15 15:55:04 +0300428 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
429 if (r)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300430 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300431
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300432 r = hdmi_runtime_get();
433 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300434 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530435
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300436 /* Make selection of HDMI in DSS */
437 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
438
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300439 hdmi.core_enabled = true;
440
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300441 return 0;
442
443err_runtime_get:
444 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300445
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300446 return r;
447}
448
449static void hdmi_power_off_core(struct omap_dss_device *dssdev)
450{
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300451 hdmi.core_enabled = false;
452
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300453 hdmi_runtime_put();
454 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300455}
456
457static int hdmi_power_on_full(struct omap_dss_device *dssdev)
458{
459 int r;
460 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300461 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300462 unsigned long phy;
463
464 r = hdmi_power_on_core(dssdev);
465 if (r)
466 return r;
467
Archit Tanejacea87b92012-09-07 17:56:20 +0530468 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530469
Archit Taneja78493982012-08-08 16:50:42 +0530470 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530471
Archit Taneja78493982012-08-08 16:50:42 +0530472 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 +0530473
Mythri P Kc3198a52011-03-12 12:04:27 +0530474 phy = p->pixel_clock;
475
Archit Tanejac1577c12013-10-08 12:55:26 +0530476 hdmi_pll_compute(&hdmi.ip_data.pll, clk_get_rate(hdmi.sys_clk), phy);
Mythri P Kc3198a52011-03-12 12:04:27 +0530477
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530478 hdmi_wp_video_stop(&hdmi.ip_data.wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530479
Mythri P K95a8aeb2011-09-08 19:06:18 +0530480 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Archit Tanejac1577c12013-10-08 12:55:26 +0530481 r = hdmi_pll_enable(&hdmi.ip_data.pll, &hdmi.ip_data.wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530482 if (r) {
483 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300484 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530485 }
486
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530487 r = hdmi_phy_enable(&hdmi.ip_data.phy, &hdmi.ip_data.wp,
488 &hdmi.ip_data.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530489 if (r) {
490 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500491 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530492 }
493
Archit Taneja425f02f2013-10-08 14:16:05 +0530494 hdmi4_configure(&hdmi.ip_data.core, &hdmi.ip_data.wp,
495 &hdmi.ip_data.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530496
Mythri P Kc3198a52011-03-12 12:04:27 +0530497 /* bypass TV gamma table */
498 dispc_enable_gamma_table(0);
499
500 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530501 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530502
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530503 r = hdmi_wp_video_start(&hdmi.ip_data.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500504 if (r)
505 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530506
Archit Tanejacea87b92012-09-07 17:56:20 +0530507 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200508 if (r)
509 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300510
Mythri P Kc3198a52011-03-12 12:04:27 +0530511 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200512
513err_mgr_enable:
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530514 hdmi_wp_video_stop(&hdmi.ip_data.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500515err_vid_enable:
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530516 hdmi_phy_disable(&hdmi.ip_data.phy, &hdmi.ip_data.wp);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500517err_phy_enable:
Archit Tanejac1577c12013-10-08 12:55:26 +0530518 hdmi_pll_disable(&hdmi.ip_data.pll, &hdmi.ip_data.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300519err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300520 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530521 return -EIO;
522}
523
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300524static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530525{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300526 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530527
528 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530529
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530530 hdmi_wp_video_stop(&hdmi.ip_data.wp);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530531 hdmi_phy_disable(&hdmi.ip_data.phy, &hdmi.ip_data.wp);
Archit Tanejac1577c12013-10-08 12:55:26 +0530532 hdmi_pll_disable(&hdmi.ip_data.pll, &hdmi.ip_data.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300533
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300534 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530535}
536
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300537static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530538 struct omap_video_timings *timings)
539{
540 struct hdmi_cm cm;
541
542 cm = hdmi_get_code(timings);
543 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530544 return -EINVAL;
545 }
546
547 return 0;
548
549}
550
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300551static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530552 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530553{
554 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530555 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530556
Archit Tanejaed1aa902012-08-15 00:40:31 +0530557 mutex_lock(&hdmi.lock);
558
Archit Taneja78493982012-08-08 16:50:42 +0530559 cm = hdmi_get_code(timings);
560 hdmi.ip_data.cfg.cm = cm;
561
562 t = hdmi_get_timings();
Tomi Valkeinendb680c62013-08-27 14:11:48 +0300563 if (t != NULL) {
Archit Taneja78493982012-08-08 16:50:42 +0530564 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300565
Tomi Valkeinendb680c62013-08-27 14:11:48 +0300566 dispc_set_tv_pclk(t->timings.pixel_clock * 1000);
567 }
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300568
Archit Tanejaed1aa902012-08-15 00:40:31 +0530569 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530570}
571
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300572static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300573 struct omap_video_timings *timings)
574{
575 const struct hdmi_config *cfg;
576
577 cfg = hdmi_get_timings();
578 if (cfg == NULL)
579 cfg = &vesa_timings[0];
580
581 memcpy(timings, &cfg->timings, sizeof(cfg->timings));
582}
583
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200584static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530585{
586 mutex_lock(&hdmi.lock);
587
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800588 if (hdmi_runtime_get()) {
589 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530590 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800591 }
Mythri P K162874d2011-09-22 13:37:45 +0530592
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530593 hdmi_wp_dump(&hdmi.ip_data.wp, s);
Archit Tanejac1577c12013-10-08 12:55:26 +0530594 hdmi_pll_dump(&hdmi.ip_data.pll, s);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530595 hdmi_phy_dump(&hdmi.ip_data.phy, s);
Archit Taneja425f02f2013-10-08 14:16:05 +0530596 hdmi4_core_dump(&hdmi.ip_data.core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530597
598 hdmi_runtime_put();
599 mutex_unlock(&hdmi.lock);
600}
601
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300602static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300603{
604 int r;
605
606 mutex_lock(&hdmi.lock);
607
608 r = hdmi_runtime_get();
609 BUG_ON(r);
610
Archit Taneja425f02f2013-10-08 14:16:05 +0530611 r = hdmi4_read_edid(&hdmi.ip_data.core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300612
613 hdmi_runtime_put();
614 mutex_unlock(&hdmi.lock);
615
616 return r;
617}
618
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300619static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530620{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300621 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530622 int r = 0;
623
624 DSSDBG("ENTER hdmi_display_enable\n");
625
626 mutex_lock(&hdmi.lock);
627
Archit Tanejacea87b92012-09-07 17:56:20 +0530628 if (out == NULL || out->manager == NULL) {
629 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300630 r = -ENODEV;
631 goto err0;
632 }
633
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300634 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530635 if (r) {
636 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300637 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530638 }
639
640 mutex_unlock(&hdmi.lock);
641 return 0;
642
Mythri P Kc3198a52011-03-12 12:04:27 +0530643err0:
644 mutex_unlock(&hdmi.lock);
645 return r;
646}
647
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300648static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530649{
650 DSSDBG("Enter hdmi_display_disable\n");
651
652 mutex_lock(&hdmi.lock);
653
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300654 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530655
Mythri P Kc3198a52011-03-12 12:04:27 +0530656 mutex_unlock(&hdmi.lock);
657}
658
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300659static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300660{
661 int r = 0;
662
663 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
664
665 mutex_lock(&hdmi.lock);
666
Tomi Valkeinen44898232012-10-19 17:42:27 +0300667 r = hdmi_power_on_core(dssdev);
668 if (r) {
669 DSSERR("failed to power on device\n");
670 goto err0;
671 }
672
673 mutex_unlock(&hdmi.lock);
674 return 0;
675
676err0:
677 mutex_unlock(&hdmi.lock);
678 return r;
679}
680
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300681static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300682{
683 DSSDBG("Enter omapdss_hdmi_core_disable\n");
684
685 mutex_lock(&hdmi.lock);
686
687 hdmi_power_off_core(dssdev);
688
689 mutex_unlock(&hdmi.lock);
690}
691
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300692static int hdmi_get_clocks(struct platform_device *pdev)
693{
694 struct clk *clk;
695
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300696 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300697 if (IS_ERR(clk)) {
698 DSSERR("can't get sys_clk\n");
699 return PTR_ERR(clk);
700 }
701
702 hdmi.sys_clk = clk;
703
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300704 return 0;
705}
706
Ricardo Neri35547622012-03-20 21:02:01 -0600707#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
708int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
709{
710 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600711 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600712 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
713
714 if (n == NULL || cts == NULL)
715 return -EINVAL;
716
717 /* TODO: When implemented, query deep color mode here. */
718 deep_color = 100;
719
Ricardo Neri25a65352012-03-23 15:49:02 -0600720 /*
721 * When using deep color, the default N value (as in the HDMI
722 * specification) yields to an non-integer CTS. Hence, we
723 * modify it while keeping the restrictions described in
724 * section 7.2.1 of the HDMI 1.4a specification.
725 */
Ricardo Neri35547622012-03-20 21:02:01 -0600726 switch (sample_freq) {
727 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600728 case 48000:
729 case 96000:
730 case 192000:
731 if (deep_color == 125)
732 if (pclk == 27027 || pclk == 74250)
733 deep_color_correct = true;
734 if (deep_color == 150)
735 if (pclk == 27027)
736 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600737 break;
738 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600739 case 88200:
740 case 176400:
741 if (deep_color == 125)
742 if (pclk == 27027)
743 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600744 break;
745 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600746 return -EINVAL;
747 }
748
Ricardo Neri25a65352012-03-23 15:49:02 -0600749 if (deep_color_correct) {
750 switch (sample_freq) {
751 case 32000:
752 *n = 8192;
753 break;
754 case 44100:
755 *n = 12544;
756 break;
757 case 48000:
758 *n = 8192;
759 break;
760 case 88200:
761 *n = 25088;
762 break;
763 case 96000:
764 *n = 16384;
765 break;
766 case 176400:
767 *n = 50176;
768 break;
769 case 192000:
770 *n = 32768;
771 break;
772 default:
773 return -EINVAL;
774 }
775 } else {
776 switch (sample_freq) {
777 case 32000:
778 *n = 4096;
779 break;
780 case 44100:
781 *n = 6272;
782 break;
783 case 48000:
784 *n = 6144;
785 break;
786 case 88200:
787 *n = 12544;
788 break;
789 case 96000:
790 *n = 12288;
791 break;
792 case 176400:
793 *n = 25088;
794 break;
795 case 192000:
796 *n = 24576;
797 break;
798 default:
799 return -EINVAL;
800 }
801 }
Ricardo Neri35547622012-03-20 21:02:01 -0600802 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
803 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
804
805 return 0;
806}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500807
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300808static bool hdmi_mode_has_audio(void)
Ricardo Nerif3a974912012-05-09 21:09:50 -0500809{
810 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
811 return true;
812 else
813 return false;
814}
Ricardo Neri35547622012-03-20 21:02:01 -0600815#endif
816
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300817static int hdmi_connect(struct omap_dss_device *dssdev,
818 struct omap_dss_device *dst)
819{
820 struct omap_overlay_manager *mgr;
821 int r;
822
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300823 r = hdmi_init_regulator();
824 if (r)
825 return r;
826
827 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
828 if (!mgr)
829 return -ENODEV;
830
831 r = dss_mgr_connect(mgr, dssdev);
832 if (r)
833 return r;
834
835 r = omapdss_output_set_device(dssdev, dst);
836 if (r) {
837 DSSERR("failed to connect output to new device: %s\n",
838 dst->name);
839 dss_mgr_disconnect(mgr, dssdev);
840 return r;
841 }
842
843 return 0;
844}
845
846static void hdmi_disconnect(struct omap_dss_device *dssdev,
847 struct omap_dss_device *dst)
848{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300849 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300850
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300851 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300852 return;
853
854 omapdss_output_unset_device(dssdev);
855
856 if (dssdev->manager)
857 dss_mgr_disconnect(dssdev->manager, dssdev);
858}
859
860static int hdmi_read_edid(struct omap_dss_device *dssdev,
861 u8 *edid, int len)
862{
863 bool need_enable;
864 int r;
865
866 need_enable = hdmi.core_enabled == false;
867
868 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300869 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300870 if (r)
871 return r;
872 }
873
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300874 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300875
876 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300877 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300878
879 return r;
880}
881
882#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300883static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300884{
885 int r;
886
887 mutex_lock(&hdmi.lock);
888
889 if (!hdmi_mode_has_audio()) {
890 r = -EPERM;
891 goto err;
892 }
893
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530894 r = hdmi_wp_audio_enable(&hdmi.ip_data.wp, true);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300895 if (r)
896 goto err;
897
898 mutex_unlock(&hdmi.lock);
899 return 0;
900
901err:
902 mutex_unlock(&hdmi.lock);
903 return r;
904}
905
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300906static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300907{
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530908 hdmi_wp_audio_enable(&hdmi.ip_data.wp, false);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300909}
910
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300911static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300912{
Archit Taneja425f02f2013-10-08 14:16:05 +0530913 return hdmi4_audio_start(&hdmi.ip_data.core, &hdmi.ip_data.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300914}
915
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300916static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300917{
Archit Taneja425f02f2013-10-08 14:16:05 +0530918 hdmi4_audio_stop(&hdmi.ip_data.core, &hdmi.ip_data.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300919}
920
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300921static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300922{
923 bool r;
924
925 mutex_lock(&hdmi.lock);
926
927 r = hdmi_mode_has_audio();
928
929 mutex_unlock(&hdmi.lock);
930 return r;
931}
932
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300933static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300934 struct omap_dss_audio *audio)
935{
936 int r;
937
938 mutex_lock(&hdmi.lock);
939
940 if (!hdmi_mode_has_audio()) {
941 r = -EPERM;
942 goto err;
943 }
944
Archit Taneja425f02f2013-10-08 14:16:05 +0530945 r = hdmi4_audio_config(&hdmi.ip_data.core, &hdmi.ip_data.wp, audio);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300946 if (r)
947 goto err;
948
949 mutex_unlock(&hdmi.lock);
950 return 0;
951
952err:
953 mutex_unlock(&hdmi.lock);
954 return r;
955}
956#else
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300957static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300958{
959 return -EPERM;
960}
961
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300962static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300963{
964}
965
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300966static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300967{
968 return -EPERM;
969}
970
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300971static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300972{
973}
974
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300975static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300976{
977 return false;
978}
979
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300980static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300981 struct omap_dss_audio *audio)
982{
983 return -EPERM;
984}
985#endif
986
987static const struct omapdss_hdmi_ops hdmi_ops = {
988 .connect = hdmi_connect,
989 .disconnect = hdmi_disconnect,
990
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300991 .enable = hdmi_display_enable,
992 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300993
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300994 .check_timings = hdmi_display_check_timing,
995 .set_timings = hdmi_display_set_timing,
996 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300997
998 .read_edid = hdmi_read_edid,
999
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001000 .audio_enable = hdmi_audio_enable,
1001 .audio_disable = hdmi_audio_disable,
1002 .audio_start = hdmi_audio_start,
1003 .audio_stop = hdmi_audio_stop,
1004 .audio_supported = hdmi_audio_supported,
1005 .audio_config = hdmi_audio_config,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001006};
1007
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001008static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +05301009{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001010 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301011
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001012 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +05301013 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001014 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +02001015 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02001016 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001017 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +03001018 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +05301019
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001020 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301021}
1022
1023static void __exit hdmi_uninit_output(struct platform_device *pdev)
1024{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001025 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301026
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001027 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301028}
1029
Mythri P Kc3198a52011-03-12 12:04:27 +05301030/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001031static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301032{
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001033 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301034
Mythri P Kc3198a52011-03-12 12:04:27 +05301035 hdmi.pdev = pdev;
1036
1037 mutex_init(&hdmi.lock);
Ricardo Neri66a06b02012-11-06 00:19:14 -06001038 mutex_init(&hdmi.ip_data.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +05301039
Archit Tanejaf382d9e2013-08-06 14:56:55 +05301040 r = hdmi_wp_init(pdev, &hdmi.ip_data.wp);
1041 if (r)
1042 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301043
Archit Tanejac1577c12013-10-08 12:55:26 +05301044 r = hdmi_pll_init(pdev, &hdmi.ip_data.pll);
1045 if (r)
1046 return r;
1047
Archit Taneja5cac5ae2013-10-08 13:07:00 +05301048 r = hdmi_phy_init(pdev, &hdmi.ip_data.phy);
1049 if (r)
1050 return r;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +03001051
Archit Taneja425f02f2013-10-08 14:16:05 +05301052 r = hdmi4_core_init(pdev, &hdmi.ip_data.core);
1053 if (r)
1054 return r;
1055
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001056 r = hdmi_get_clocks(pdev);
1057 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -06001058 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001059 return r;
1060 }
1061
1062 pm_runtime_enable(&pdev->dev);
1063
Tomi Valkeinen002d3682013-02-13 12:17:43 +02001064 hdmi_init_output(pdev);
1065
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001066 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1067
Tomi Valkeinencca35012012-04-26 14:48:32 +03001068 return 0;
1069}
1070
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001071static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301072{
Archit Taneja81b87f52012-09-26 16:30:49 +05301073 hdmi_uninit_output(pdev);
1074
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001075 pm_runtime_disable(&pdev->dev);
1076
Mythri P Kc3198a52011-03-12 12:04:27 +05301077 return 0;
1078}
1079
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001080static int hdmi_runtime_suspend(struct device *dev)
1081{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301082 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001083
1084 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001085
1086 return 0;
1087}
1088
1089static int hdmi_runtime_resume(struct device *dev)
1090{
1091 int r;
1092
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001093 r = dispc_runtime_get();
1094 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001095 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001096
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301097 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001098
1099 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001100}
1101
1102static const struct dev_pm_ops hdmi_pm_ops = {
1103 .runtime_suspend = hdmi_runtime_suspend,
1104 .runtime_resume = hdmi_runtime_resume,
1105};
1106
Mythri P Kc3198a52011-03-12 12:04:27 +05301107static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001108 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001109 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301110 .driver = {
1111 .name = "omapdss_hdmi",
1112 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001113 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301114 },
1115};
1116
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001117int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301118{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001119 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301120}
1121
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001122void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301123{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001124 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301125}