blob: 75f3c740ef8cd129b5f2da04fcbc7b286a2f8958 [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
Tomi Valkeinen0b450c32013-05-24 13:20:17 +030069 bool core_enabled;
70
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030071 struct omap_dss_device output;
Mythri P Kc3198a52011-03-12 12:04:27 +053072} hdmi;
73
74/*
75 * Logic for the below structure :
76 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
77 * There is a correspondence between CEA/VESA timing and code, please
78 * refer to section 6.3 in HDMI 1.3 specification for timing code.
79 *
80 * In the below structure, cea_vesa_timings corresponds to all OMAP4
81 * supported CEA and VESA timing values.code_cea corresponds to the CEA
82 * code, It is used to get the timing from cea_vesa_timing array.Similarly
83 * with code_vesa. Code_index is used for back mapping, that is once EDID
84 * is read from the TV, EDID is parsed to find the timing values and then
85 * map it to corresponding CEA or VESA index.
86 */
87
Mythri P K46095b22012-01-06 17:52:09 +053088static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053089 {
90 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
91 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
92 false, },
93 { 1, HDMI_HDMI },
94 },
95 {
96 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
97 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
98 false, },
99 { 2, HDMI_HDMI },
100 },
101 {
102 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
103 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
104 false, },
105 { 4, HDMI_HDMI },
106 },
107 {
108 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
109 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
110 true, },
111 { 5, HDMI_HDMI },
112 },
113 {
114 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
115 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
116 true, },
117 { 6, HDMI_HDMI },
118 },
119 {
120 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
121 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
122 false, },
123 { 16, HDMI_HDMI },
124 },
125 {
126 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
127 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
128 false, },
129 { 17, HDMI_HDMI },
130 },
131 {
132 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
133 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
134 false, },
135 { 19, HDMI_HDMI },
136 },
137 {
138 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
139 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
140 true, },
141 { 20, HDMI_HDMI },
142 },
143 {
144 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
145 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
146 true, },
147 { 21, HDMI_HDMI },
148 },
149 {
150 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
151 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
152 false, },
153 { 29, HDMI_HDMI },
154 },
155 {
156 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
157 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
158 false, },
159 { 31, HDMI_HDMI },
160 },
161 {
162 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
163 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
164 false, },
165 { 32, HDMI_HDMI },
166 },
167 {
168 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
169 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
170 false, },
171 { 35, HDMI_HDMI },
172 },
173 {
174 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
175 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
176 false, },
177 { 37, HDMI_HDMI },
178 },
Mythri P K46095b22012-01-06 17:52:09 +0530179};
Archit Tanejacc937e52012-06-24 13:08:10 +0530180
Mythri P K46095b22012-01-06 17:52:09 +0530181static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530182/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530183 {
184 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
185 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
186 false, },
187 { 4, HDMI_DVI },
188 },
189 {
190 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
191 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
192 false, },
193 { 9, HDMI_DVI },
194 },
195 {
196 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
197 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
198 false, },
199 { 0xE, HDMI_DVI },
200 },
201 {
202 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
203 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
204 false, },
205 { 0x17, HDMI_DVI },
206 },
207 {
208 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
209 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
210 false, },
211 { 0x1C, HDMI_DVI },
212 },
213 {
214 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
215 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
216 false, },
217 { 0x27, HDMI_DVI },
218 },
219 {
220 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
221 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
222 false, },
223 { 0x20, HDMI_DVI },
224 },
225 {
226 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
227 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
228 false, },
229 { 0x23, HDMI_DVI },
230 },
231 {
232 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
233 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
234 false, },
235 { 0x10, HDMI_DVI },
236 },
237 {
238 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
239 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
240 false, },
241 { 0x2A, HDMI_DVI },
242 },
243 {
244 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
245 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
246 false, },
247 { 0x2F, HDMI_DVI },
248 },
249 {
250 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
251 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
252 false, },
253 { 0x3A, HDMI_DVI },
254 },
255 {
256 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
257 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
258 false, },
259 { 0x51, HDMI_DVI },
260 },
261 {
262 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
263 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
264 false, },
265 { 0x52, HDMI_DVI },
266 },
267 {
268 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
269 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
270 false, },
271 { 0x16, HDMI_DVI },
272 },
273 {
274 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
275 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
276 false, },
277 { 0x29, HDMI_DVI },
278 },
279 {
280 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
281 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
282 false, },
283 { 0x39, HDMI_DVI },
284 },
285 {
286 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
287 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
288 false, },
289 { 0x1B, HDMI_DVI },
290 },
291 {
292 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
293 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
294 false, },
295 { 0x55, HDMI_DVI },
296 },
Tomi Valkeinen7a7ce2c2012-10-24 11:55:39 +0300297 {
298 { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
299 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
300 false, },
301 { 0x44, HDMI_DVI },
302 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530303};
304
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300305static int hdmi_runtime_get(void)
306{
307 int r;
308
309 DSSDBG("hdmi_runtime_get\n");
310
311 r = pm_runtime_get_sync(&hdmi.pdev->dev);
312 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +0530313 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200314 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +0530315
316 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300317}
318
319static void hdmi_runtime_put(void)
320{
321 int r;
322
323 DSSDBG("hdmi_runtime_put\n");
324
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200325 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300326 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300327}
328
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300329static int hdmi_init_regulator(void)
330{
331 struct regulator *reg;
332
333 if (hdmi.vdda_hdmi_dac_reg != NULL)
334 return 0;
335
336 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
337
338 /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
339 if (IS_ERR(reg))
340 reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
341
342 if (IS_ERR(reg)) {
343 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
344 return PTR_ERR(reg);
345 }
346
347 hdmi.vdda_hdmi_dac_reg = reg;
348
349 return 0;
350}
351
Mythri P K46095b22012-01-06 17:52:09 +0530352static const struct hdmi_config *hdmi_find_timing(
353 const struct hdmi_config *timings_arr,
354 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530355{
Mythri P K46095b22012-01-06 17:52:09 +0530356 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530357
Mythri P K46095b22012-01-06 17:52:09 +0530358 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530359 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530360 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530361 }
Mythri P K46095b22012-01-06 17:52:09 +0530362 return NULL;
363}
364
365static const struct hdmi_config *hdmi_get_timings(void)
366{
367 const struct hdmi_config *arr;
368 int len;
369
Mythri P K9e4ed602012-01-06 17:52:10 +0530370 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530371 arr = vesa_timings;
372 len = ARRAY_SIZE(vesa_timings);
373 } else {
374 arr = cea_timings;
375 len = ARRAY_SIZE(cea_timings);
376 }
377
378 return hdmi_find_timing(arr, len);
379}
380
381static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530382 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530383{
384 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
385
Tomi Valkeinenf236b892012-10-24 11:55:54 +0300386 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
387 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
Mythri P K46095b22012-01-06 17:52:09 +0530388 (timing2->x_res == timing1->x_res) &&
389 (timing2->y_res == timing1->y_res)) {
390
391 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
392 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
393 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
394 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
395
396 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
397 "timing2_hsync = %d timing2_vsync = %d\n",
398 timing1_hsync, timing1_vsync,
399 timing2_hsync, timing2_vsync);
400
401 if ((timing1_hsync == timing2_hsync) &&
402 (timing1_vsync == timing2_vsync)) {
403 return true;
404 }
405 }
406 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530407}
408
409static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
410{
Mythri P K46095b22012-01-06 17:52:09 +0530411 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530412 struct hdmi_cm cm = {-1};
413 DSSDBG("hdmi_get_code\n");
414
Mythri P K46095b22012-01-06 17:52:09 +0530415 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
416 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
417 cm = cea_timings[i].cm;
418 goto end;
419 }
420 }
421 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
422 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
423 cm = vesa_timings[i].cm;
424 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530425 }
426 }
427
Mythri P K46095b22012-01-06 17:52:09 +0530428end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530429
Mythri P Kc3198a52011-03-12 12:04:27 +0530430}
431
Archit Taneja6cb07b22011-04-12 13:52:25 +0530432static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
433 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530434{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530435 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530436 u32 mf;
437
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300438 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530439 /*
440 * Input clock is predivided by N + 1
441 * out put of which is reference clk
442 */
Tomi Valkeinen4fdfdf02013-02-12 15:15:21 +0200443
444 pi->regn = HDMI_DEFAULT_REGN;
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300445
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300446 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530447
Tomi Valkeinen4fdfdf02013-02-12 15:15:21 +0200448 pi->regm2 = HDMI_DEFAULT_REGM2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530449
450 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530451 * multiplier is pixel_clk/ref_clk
452 * Multiplying by 100 to avoid fractional part removal
453 */
454 pi->regm = phy * pi->regm2 / refclk;
455
456 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530457 * fractional multiplier is remainder of the difference between
458 * multiplier and actual phy(required pixel clock thus should be
459 * multiplied by 2^18(262144) divided by the reference clock
460 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530461 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
462 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530463
464 /*
465 * Dcofreq should be set to 1 if required pixel clock
466 * is greater than 1000MHz
467 */
468 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300469 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530470
Mythri P K7b27da52011-09-08 19:06:19 +0530471 /* Set the reference clock to sysclk reference */
472 pi->refsel = HDMI_REFSEL_SYSCLK;
473
Mythri P Kc3198a52011-03-12 12:04:27 +0530474 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
475 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
476}
477
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300478static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530479{
Mythri P K46095b22012-01-06 17:52:09 +0530480 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530481
Tomi Valkeinen17486942012-08-15 15:55:04 +0300482 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
483 if (r)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300484 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300485
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300486 r = hdmi_runtime_get();
487 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300488 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530489
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300490 /* Make selection of HDMI in DSS */
491 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
492
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300493 hdmi.core_enabled = true;
494
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300495 return 0;
496
497err_runtime_get:
498 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300499
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300500 return r;
501}
502
503static void hdmi_power_off_core(struct omap_dss_device *dssdev)
504{
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300505 hdmi.core_enabled = false;
506
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300507 hdmi_runtime_put();
508 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300509}
510
511static int hdmi_power_on_full(struct omap_dss_device *dssdev)
512{
513 int r;
514 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300515 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300516 unsigned long phy;
517
518 r = hdmi_power_on_core(dssdev);
519 if (r)
520 return r;
521
Archit Tanejacea87b92012-09-07 17:56:20 +0530522 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530523
Archit Taneja78493982012-08-08 16:50:42 +0530524 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530525
Archit Taneja78493982012-08-08 16:50:42 +0530526 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 +0530527
Mythri P Kc3198a52011-03-12 12:04:27 +0530528 phy = p->pixel_clock;
529
Mythri P K7b27da52011-09-08 19:06:19 +0530530 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530531
Ricardo Neric0456be2012-04-27 13:48:45 -0500532 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530533
Mythri P K95a8aeb2011-09-08 19:06:18 +0530534 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530535 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530536 if (r) {
537 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300538 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530539 }
540
Mythri P K60634a22011-09-08 19:06:26 +0530541 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530542 if (r) {
543 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500544 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530545 }
546
Mythri P K60634a22011-09-08 19:06:26 +0530547 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530548
Mythri P Kc3198a52011-03-12 12:04:27 +0530549 /* bypass TV gamma table */
550 dispc_enable_gamma_table(0);
551
552 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530553 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530554
Ricardo Neric0456be2012-04-27 13:48:45 -0500555 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
556 if (r)
557 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530558
Archit Tanejacea87b92012-09-07 17:56:20 +0530559 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200560 if (r)
561 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300562
Mythri P Kc3198a52011-03-12 12:04:27 +0530563 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200564
565err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500566 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
567err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200568 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500569err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200570 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300571err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300572 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530573 return -EIO;
574}
575
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300576static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530577{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300578 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530579
580 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530581
Ricardo Neric0456be2012-04-27 13:48:45 -0500582 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P K60634a22011-09-08 19:06:26 +0530583 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
584 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300585
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300586 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530587}
588
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300589static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530590 struct omap_video_timings *timings)
591{
592 struct hdmi_cm cm;
593
594 cm = hdmi_get_code(timings);
595 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530596 return -EINVAL;
597 }
598
599 return 0;
600
601}
602
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300603static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530604 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530605{
606 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530607 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530608
Archit Tanejaed1aa902012-08-15 00:40:31 +0530609 mutex_lock(&hdmi.lock);
610
Archit Taneja78493982012-08-08 16:50:42 +0530611 cm = hdmi_get_code(timings);
612 hdmi.ip_data.cfg.cm = cm;
613
614 t = hdmi_get_timings();
615 if (t != NULL)
616 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300617
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300618 dispc_set_tv_pclk(t->timings.pixel_clock * 1000);
619
Archit Tanejaed1aa902012-08-15 00:40:31 +0530620 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530621}
622
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300623static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300624 struct omap_video_timings *timings)
625{
626 const struct hdmi_config *cfg;
627
628 cfg = hdmi_get_timings();
629 if (cfg == NULL)
630 cfg = &vesa_timings[0];
631
632 memcpy(timings, &cfg->timings, sizeof(cfg->timings));
633}
634
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200635static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530636{
637 mutex_lock(&hdmi.lock);
638
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800639 if (hdmi_runtime_get()) {
640 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530641 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800642 }
Mythri P K162874d2011-09-22 13:37:45 +0530643
644 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
645 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
646 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
647 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
648
649 hdmi_runtime_put();
650 mutex_unlock(&hdmi.lock);
651}
652
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300653static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300654{
655 int r;
656
657 mutex_lock(&hdmi.lock);
658
659 r = hdmi_runtime_get();
660 BUG_ON(r);
661
662 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
663
664 hdmi_runtime_put();
665 mutex_unlock(&hdmi.lock);
666
667 return r;
668}
669
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300670static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530671{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300672 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530673 int r = 0;
674
675 DSSDBG("ENTER hdmi_display_enable\n");
676
677 mutex_lock(&hdmi.lock);
678
Archit Tanejacea87b92012-09-07 17:56:20 +0530679 if (out == NULL || out->manager == NULL) {
680 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300681 r = -ENODEV;
682 goto err0;
683 }
684
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300685 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530686 if (r) {
687 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300688 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530689 }
690
691 mutex_unlock(&hdmi.lock);
692 return 0;
693
Mythri P Kc3198a52011-03-12 12:04:27 +0530694err0:
695 mutex_unlock(&hdmi.lock);
696 return r;
697}
698
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300699static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530700{
701 DSSDBG("Enter hdmi_display_disable\n");
702
703 mutex_lock(&hdmi.lock);
704
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300705 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530706
Mythri P Kc3198a52011-03-12 12:04:27 +0530707 mutex_unlock(&hdmi.lock);
708}
709
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300710static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300711{
712 int r = 0;
713
714 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
715
716 mutex_lock(&hdmi.lock);
717
Tomi Valkeinen44898232012-10-19 17:42:27 +0300718 r = hdmi_power_on_core(dssdev);
719 if (r) {
720 DSSERR("failed to power on device\n");
721 goto err0;
722 }
723
724 mutex_unlock(&hdmi.lock);
725 return 0;
726
727err0:
728 mutex_unlock(&hdmi.lock);
729 return r;
730}
731
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300732static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300733{
734 DSSDBG("Enter omapdss_hdmi_core_disable\n");
735
736 mutex_lock(&hdmi.lock);
737
738 hdmi_power_off_core(dssdev);
739
740 mutex_unlock(&hdmi.lock);
741}
742
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300743static int hdmi_get_clocks(struct platform_device *pdev)
744{
745 struct clk *clk;
746
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300747 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300748 if (IS_ERR(clk)) {
749 DSSERR("can't get sys_clk\n");
750 return PTR_ERR(clk);
751 }
752
753 hdmi.sys_clk = clk;
754
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300755 return 0;
756}
757
Ricardo Neri35547622012-03-20 21:02:01 -0600758#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
759int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
760{
761 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600762 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600763 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
764
765 if (n == NULL || cts == NULL)
766 return -EINVAL;
767
768 /* TODO: When implemented, query deep color mode here. */
769 deep_color = 100;
770
Ricardo Neri25a65352012-03-23 15:49:02 -0600771 /*
772 * When using deep color, the default N value (as in the HDMI
773 * specification) yields to an non-integer CTS. Hence, we
774 * modify it while keeping the restrictions described in
775 * section 7.2.1 of the HDMI 1.4a specification.
776 */
Ricardo Neri35547622012-03-20 21:02:01 -0600777 switch (sample_freq) {
778 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600779 case 48000:
780 case 96000:
781 case 192000:
782 if (deep_color == 125)
783 if (pclk == 27027 || pclk == 74250)
784 deep_color_correct = true;
785 if (deep_color == 150)
786 if (pclk == 27027)
787 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600788 break;
789 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600790 case 88200:
791 case 176400:
792 if (deep_color == 125)
793 if (pclk == 27027)
794 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600795 break;
796 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600797 return -EINVAL;
798 }
799
Ricardo Neri25a65352012-03-23 15:49:02 -0600800 if (deep_color_correct) {
801 switch (sample_freq) {
802 case 32000:
803 *n = 8192;
804 break;
805 case 44100:
806 *n = 12544;
807 break;
808 case 48000:
809 *n = 8192;
810 break;
811 case 88200:
812 *n = 25088;
813 break;
814 case 96000:
815 *n = 16384;
816 break;
817 case 176400:
818 *n = 50176;
819 break;
820 case 192000:
821 *n = 32768;
822 break;
823 default:
824 return -EINVAL;
825 }
826 } else {
827 switch (sample_freq) {
828 case 32000:
829 *n = 4096;
830 break;
831 case 44100:
832 *n = 6272;
833 break;
834 case 48000:
835 *n = 6144;
836 break;
837 case 88200:
838 *n = 12544;
839 break;
840 case 96000:
841 *n = 12288;
842 break;
843 case 176400:
844 *n = 25088;
845 break;
846 case 192000:
847 *n = 24576;
848 break;
849 default:
850 return -EINVAL;
851 }
852 }
Ricardo Neri35547622012-03-20 21:02:01 -0600853 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
854 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
855
856 return 0;
857}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500858
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300859static bool hdmi_mode_has_audio(void)
Ricardo Nerif3a974912012-05-09 21:09:50 -0500860{
861 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
862 return true;
863 else
864 return false;
865}
866
Ricardo Neri35547622012-03-20 21:02:01 -0600867#endif
868
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300869static int hdmi_connect(struct omap_dss_device *dssdev,
870 struct omap_dss_device *dst)
871{
872 struct omap_overlay_manager *mgr;
873 int r;
874
875 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
876
877 r = hdmi_init_regulator();
878 if (r)
879 return r;
880
881 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
882 if (!mgr)
883 return -ENODEV;
884
885 r = dss_mgr_connect(mgr, dssdev);
886 if (r)
887 return r;
888
889 r = omapdss_output_set_device(dssdev, dst);
890 if (r) {
891 DSSERR("failed to connect output to new device: %s\n",
892 dst->name);
893 dss_mgr_disconnect(mgr, dssdev);
894 return r;
895 }
896
897 return 0;
898}
899
900static void hdmi_disconnect(struct omap_dss_device *dssdev,
901 struct omap_dss_device *dst)
902{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300903 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300904
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300905 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300906 return;
907
908 omapdss_output_unset_device(dssdev);
909
910 if (dssdev->manager)
911 dss_mgr_disconnect(dssdev->manager, dssdev);
912}
913
914static int hdmi_read_edid(struct omap_dss_device *dssdev,
915 u8 *edid, int len)
916{
917 bool need_enable;
918 int r;
919
920 need_enable = hdmi.core_enabled == false;
921
922 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300923 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300924 if (r)
925 return r;
926 }
927
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300928 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300929
930 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300931 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300932
933 return r;
934}
935
936#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300937static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300938{
939 int r;
940
941 mutex_lock(&hdmi.lock);
942
943 if (!hdmi_mode_has_audio()) {
944 r = -EPERM;
945 goto err;
946 }
947
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300948
949 r = hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300950 if (r)
951 goto err;
952
953 mutex_unlock(&hdmi.lock);
954 return 0;
955
956err:
957 mutex_unlock(&hdmi.lock);
958 return r;
959}
960
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300961static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300962{
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300963 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300964}
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{
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300968 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300969}
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{
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300973 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300974}
975
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300976static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300977{
978 bool r;
979
980 mutex_lock(&hdmi.lock);
981
982 r = hdmi_mode_has_audio();
983
984 mutex_unlock(&hdmi.lock);
985 return r;
986}
987
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300988static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300989 struct omap_dss_audio *audio)
990{
991 int r;
992
993 mutex_lock(&hdmi.lock);
994
995 if (!hdmi_mode_has_audio()) {
996 r = -EPERM;
997 goto err;
998 }
999
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001000 r = hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001001 if (r)
1002 goto err;
1003
1004 mutex_unlock(&hdmi.lock);
1005 return 0;
1006
1007err:
1008 mutex_unlock(&hdmi.lock);
1009 return r;
1010}
1011#else
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001012static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001013{
1014 return -EPERM;
1015}
1016
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001017static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001018{
1019}
1020
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001021static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001022{
1023 return -EPERM;
1024}
1025
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001026static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001027{
1028}
1029
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001030static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001031{
1032 return false;
1033}
1034
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001035static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001036 struct omap_dss_audio *audio)
1037{
1038 return -EPERM;
1039}
1040#endif
1041
1042static const struct omapdss_hdmi_ops hdmi_ops = {
1043 .connect = hdmi_connect,
1044 .disconnect = hdmi_disconnect,
1045
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001046 .enable = hdmi_display_enable,
1047 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001048
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001049 .check_timings = hdmi_display_check_timing,
1050 .set_timings = hdmi_display_set_timing,
1051 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001052
1053 .read_edid = hdmi_read_edid,
1054
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +03001055 .audio_enable = hdmi_audio_enable,
1056 .audio_disable = hdmi_audio_disable,
1057 .audio_start = hdmi_audio_start,
1058 .audio_stop = hdmi_audio_stop,
1059 .audio_supported = hdmi_audio_supported,
1060 .audio_config = hdmi_audio_config,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001061};
1062
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001063static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +05301064{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001065 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301066
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001067 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +05301068 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001069 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +02001070 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02001071 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +03001072 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +03001073 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +05301074
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001075 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301076}
1077
1078static void __exit hdmi_uninit_output(struct platform_device *pdev)
1079{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001080 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301081
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001082 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301083}
1084
Mythri P Kc3198a52011-03-12 12:04:27 +05301085/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001086static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301087{
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001088 struct resource *res;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001089 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301090
Mythri P Kc3198a52011-03-12 12:04:27 +05301091 hdmi.pdev = pdev;
1092
1093 mutex_init(&hdmi.lock);
Ricardo Neri66a06b02012-11-06 00:19:14 -06001094 mutex_init(&hdmi.ip_data.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +05301095
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001096 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301097
1098 /* Base address taken from platform */
Thierry Redingbc3bad12013-01-21 11:09:23 +01001099 hdmi.ip_data.base_wp = devm_ioremap_resource(&pdev->dev, res);
1100 if (IS_ERR(hdmi.ip_data.base_wp))
1101 return PTR_ERR(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301102
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +03001103 hdmi.ip_data.irq = platform_get_irq(pdev, 0);
1104 if (hdmi.ip_data.irq < 0) {
1105 DSSERR("platform_get_irq failed\n");
1106 return -ENODEV;
1107 }
1108
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001109 r = hdmi_get_clocks(pdev);
1110 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -06001111 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001112 return r;
1113 }
1114
1115 pm_runtime_enable(&pdev->dev);
1116
Mythri P K95a8aeb2011-09-08 19:06:18 +05301117 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1118 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1119 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1120 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +05301121
Tomi Valkeinen002d3682013-02-13 12:17:43 +02001122 hdmi_init_output(pdev);
1123
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001124 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1125
Tomi Valkeinencca35012012-04-26 14:48:32 +03001126 return 0;
1127}
1128
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001129static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301130{
Archit Taneja81b87f52012-09-26 16:30:49 +05301131 hdmi_uninit_output(pdev);
1132
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001133 pm_runtime_disable(&pdev->dev);
1134
Mythri P Kc3198a52011-03-12 12:04:27 +05301135 return 0;
1136}
1137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001138static int hdmi_runtime_suspend(struct device *dev)
1139{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301140 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001141
1142 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001143
1144 return 0;
1145}
1146
1147static int hdmi_runtime_resume(struct device *dev)
1148{
1149 int r;
1150
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001151 r = dispc_runtime_get();
1152 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001153 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001154
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301155 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001156
1157 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001158}
1159
1160static const struct dev_pm_ops hdmi_pm_ops = {
1161 .runtime_suspend = hdmi_runtime_suspend,
1162 .runtime_resume = hdmi_runtime_resume,
1163};
1164
Mythri P Kc3198a52011-03-12 12:04:27 +05301165static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001166 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001167 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301168 .driver = {
1169 .name = "omapdss_hdmi",
1170 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001171 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301172 },
1173};
1174
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001175int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301176{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001177 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301178}
1179
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001180void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301181{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001182 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301183}