blob: 2b0a2aac8aeda04e8584cc068ec429bdd98978d6 [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
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030073 struct omap_dss_device 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 Valkeinene25001d2013-05-10 15:20:52 +0300331static int hdmi_init_regulator(void)
332{
333 struct regulator *reg;
334
335 if (hdmi.vdda_hdmi_dac_reg != NULL)
336 return 0;
337
338 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
339
340 /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
341 if (IS_ERR(reg))
342 reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
343
344 if (IS_ERR(reg)) {
345 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
346 return PTR_ERR(reg);
347 }
348
349 hdmi.vdda_hdmi_dac_reg = reg;
350
351 return 0;
352}
353
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300354static int hdmi_init_display(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530355{
Tomi Valkeinencca35012012-04-26 14:48:32 +0300356 int r;
357
358 struct gpio gpios[] = {
359 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
360 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
361 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
362 };
363
Mythri P Kc3198a52011-03-12 12:04:27 +0530364 DSSDBG("init_display\n");
365
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +0300366 dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
Tomi Valkeinencca35012012-04-26 14:48:32 +0300367
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300368 r = hdmi_init_regulator();
369 if (r)
370 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300371
Tomi Valkeinencca35012012-04-26 14:48:32 +0300372 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
373 if (r)
374 return r;
375
Mythri P Kc3198a52011-03-12 12:04:27 +0530376 return 0;
377}
378
Ricardo Neri37584762012-11-06 21:37:14 -0600379static void hdmi_uninit_display(struct omap_dss_device *dssdev)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300380{
381 DSSDBG("uninit_display\n");
382
383 gpio_free(hdmi.ct_cp_hpd_gpio);
384 gpio_free(hdmi.ls_oe_gpio);
385 gpio_free(hdmi.hpd_gpio);
386}
387
Mythri P K46095b22012-01-06 17:52:09 +0530388static const struct hdmi_config *hdmi_find_timing(
389 const struct hdmi_config *timings_arr,
390 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530391{
Mythri P K46095b22012-01-06 17:52:09 +0530392 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530393
Mythri P K46095b22012-01-06 17:52:09 +0530394 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530395 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530396 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530397 }
Mythri P K46095b22012-01-06 17:52:09 +0530398 return NULL;
399}
400
401static const struct hdmi_config *hdmi_get_timings(void)
402{
403 const struct hdmi_config *arr;
404 int len;
405
Mythri P K9e4ed602012-01-06 17:52:10 +0530406 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530407 arr = vesa_timings;
408 len = ARRAY_SIZE(vesa_timings);
409 } else {
410 arr = cea_timings;
411 len = ARRAY_SIZE(cea_timings);
412 }
413
414 return hdmi_find_timing(arr, len);
415}
416
417static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530418 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530419{
420 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
421
Tomi Valkeinenf236b892012-10-24 11:55:54 +0300422 if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
423 DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
Mythri P K46095b22012-01-06 17:52:09 +0530424 (timing2->x_res == timing1->x_res) &&
425 (timing2->y_res == timing1->y_res)) {
426
427 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
428 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
429 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
430 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
431
432 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
433 "timing2_hsync = %d timing2_vsync = %d\n",
434 timing1_hsync, timing1_vsync,
435 timing2_hsync, timing2_vsync);
436
437 if ((timing1_hsync == timing2_hsync) &&
438 (timing1_vsync == timing2_vsync)) {
439 return true;
440 }
441 }
442 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530443}
444
445static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
446{
Mythri P K46095b22012-01-06 17:52:09 +0530447 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530448 struct hdmi_cm cm = {-1};
449 DSSDBG("hdmi_get_code\n");
450
Mythri P K46095b22012-01-06 17:52:09 +0530451 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
452 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
453 cm = cea_timings[i].cm;
454 goto end;
455 }
456 }
457 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
458 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
459 cm = vesa_timings[i].cm;
460 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530461 }
462 }
463
Mythri P K46095b22012-01-06 17:52:09 +0530464end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530465
Mythri P Kc3198a52011-03-12 12:04:27 +0530466}
467
Archit Taneja6cb07b22011-04-12 13:52:25 +0530468static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
469 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530470{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530471 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530472 u32 mf;
473
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300474 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530475 /*
476 * Input clock is predivided by N + 1
477 * out put of which is reference clk
478 */
Tomi Valkeinen4fdfdf02013-02-12 15:15:21 +0200479
480 pi->regn = HDMI_DEFAULT_REGN;
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300481
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300482 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530483
Tomi Valkeinen4fdfdf02013-02-12 15:15:21 +0200484 pi->regm2 = HDMI_DEFAULT_REGM2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530485
486 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530487 * multiplier is pixel_clk/ref_clk
488 * Multiplying by 100 to avoid fractional part removal
489 */
490 pi->regm = phy * pi->regm2 / refclk;
491
492 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530493 * fractional multiplier is remainder of the difference between
494 * multiplier and actual phy(required pixel clock thus should be
495 * multiplied by 2^18(262144) divided by the reference clock
496 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530497 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
498 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530499
500 /*
501 * Dcofreq should be set to 1 if required pixel clock
502 * is greater than 1000MHz
503 */
504 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300505 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530506
Mythri P K7b27da52011-09-08 19:06:19 +0530507 /* Set the reference clock to sysclk reference */
508 pi->refsel = HDMI_REFSEL_SYSCLK;
509
Mythri P Kc3198a52011-03-12 12:04:27 +0530510 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
511 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
512}
513
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300514static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530515{
Mythri P K46095b22012-01-06 17:52:09 +0530516 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530517
Tomi Valkeinencca35012012-04-26 14:48:32 +0300518 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
519 gpio_set_value(hdmi.ls_oe_gpio, 1);
520
Tomi Valkeinena84b20654b2012-04-26 14:58:41 +0300521 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
522 udelay(300);
523
Tomi Valkeinen17486942012-08-15 15:55:04 +0300524 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
525 if (r)
526 goto err_vdac_enable;
527
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300528 r = hdmi_runtime_get();
529 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300530 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530531
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300532 /* Make selection of HDMI in DSS */
533 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
534
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300535 return 0;
536
537err_runtime_get:
538 regulator_disable(hdmi.vdda_hdmi_dac_reg);
539err_vdac_enable:
540 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
541 gpio_set_value(hdmi.ls_oe_gpio, 0);
542 return r;
543}
544
545static void hdmi_power_off_core(struct omap_dss_device *dssdev)
546{
547 hdmi_runtime_put();
548 regulator_disable(hdmi.vdda_hdmi_dac_reg);
549 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
550 gpio_set_value(hdmi.ls_oe_gpio, 0);
551}
552
553static int hdmi_power_on_full(struct omap_dss_device *dssdev)
554{
555 int r;
556 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300557 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300558 unsigned long phy;
559
560 r = hdmi_power_on_core(dssdev);
561 if (r)
562 return r;
563
Archit Tanejacea87b92012-09-07 17:56:20 +0530564 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530565
Archit Taneja78493982012-08-08 16:50:42 +0530566 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530567
Archit Taneja78493982012-08-08 16:50:42 +0530568 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 +0530569
Mythri P Kc3198a52011-03-12 12:04:27 +0530570 phy = p->pixel_clock;
571
Mythri P K7b27da52011-09-08 19:06:19 +0530572 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530573
Ricardo Neric0456be2012-04-27 13:48:45 -0500574 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530575
Mythri P K95a8aeb2011-09-08 19:06:18 +0530576 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530577 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530578 if (r) {
579 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300580 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530581 }
582
Mythri P K60634a22011-09-08 19:06:26 +0530583 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530584 if (r) {
585 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500586 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530587 }
588
Mythri P K60634a22011-09-08 19:06:26 +0530589 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530590
Mythri P Kc3198a52011-03-12 12:04:27 +0530591 /* bypass TV gamma table */
592 dispc_enable_gamma_table(0);
593
594 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530595 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530596
Ricardo Neric0456be2012-04-27 13:48:45 -0500597 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
598 if (r)
599 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530600
Archit Tanejacea87b92012-09-07 17:56:20 +0530601 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200602 if (r)
603 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300604
Mythri P Kc3198a52011-03-12 12:04:27 +0530605 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200606
607err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500608 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
609err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200610 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500611err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200612 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300613err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300614 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530615 return -EIO;
616}
617
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300618static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530619{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300620 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530621
622 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530623
Ricardo Neric0456be2012-04-27 13:48:45 -0500624 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P K60634a22011-09-08 19:06:26 +0530625 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
626 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300627
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300628 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530629}
630
631int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
632 struct omap_video_timings *timings)
633{
634 struct hdmi_cm cm;
635
636 cm = hdmi_get_code(timings);
637 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530638 return -EINVAL;
639 }
640
641 return 0;
642
643}
644
Archit Taneja78493982012-08-08 16:50:42 +0530645void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
646 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530647{
648 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530649 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530650
Archit Tanejaed1aa902012-08-15 00:40:31 +0530651 mutex_lock(&hdmi.lock);
652
Archit Taneja78493982012-08-08 16:50:42 +0530653 cm = hdmi_get_code(timings);
654 hdmi.ip_data.cfg.cm = cm;
655
656 t = hdmi_get_timings();
657 if (t != NULL)
658 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300659
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300660 dispc_set_tv_pclk(t->timings.pixel_clock * 1000);
661
Archit Tanejaed1aa902012-08-15 00:40:31 +0530662 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530663}
664
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200665static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530666{
667 mutex_lock(&hdmi.lock);
668
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800669 if (hdmi_runtime_get()) {
670 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530671 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800672 }
Mythri P K162874d2011-09-22 13:37:45 +0530673
674 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
675 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
676 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
677 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
678
679 hdmi_runtime_put();
680 mutex_unlock(&hdmi.lock);
681}
682
Tomi Valkeinen47024562011-08-25 17:12:56 +0300683int omapdss_hdmi_read_edid(u8 *buf, int len)
684{
685 int r;
686
687 mutex_lock(&hdmi.lock);
688
689 r = hdmi_runtime_get();
690 BUG_ON(r);
691
692 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
693
694 hdmi_runtime_put();
695 mutex_unlock(&hdmi.lock);
696
697 return r;
698}
699
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300700bool omapdss_hdmi_detect(void)
701{
702 int r;
703
704 mutex_lock(&hdmi.lock);
705
706 r = hdmi_runtime_get();
707 BUG_ON(r);
708
Tomi Valkeinen29356be2013-06-06 13:20:37 +0300709 r = gpio_get_value(hdmi.hpd_gpio);
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300710
711 hdmi_runtime_put();
712 mutex_unlock(&hdmi.lock);
713
714 return r == 1;
715}
716
Mythri P Kc3198a52011-03-12 12:04:27 +0530717int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
718{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300719 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530720 int r = 0;
721
722 DSSDBG("ENTER hdmi_display_enable\n");
723
724 mutex_lock(&hdmi.lock);
725
Archit Tanejacea87b92012-09-07 17:56:20 +0530726 if (out == NULL || out->manager == NULL) {
727 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300728 r = -ENODEV;
729 goto err0;
730 }
731
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300732 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530733 if (r) {
734 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300735 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530736 }
737
738 mutex_unlock(&hdmi.lock);
739 return 0;
740
Mythri P Kc3198a52011-03-12 12:04:27 +0530741err0:
742 mutex_unlock(&hdmi.lock);
743 return r;
744}
745
746void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
747{
748 DSSDBG("Enter hdmi_display_disable\n");
749
750 mutex_lock(&hdmi.lock);
751
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300752 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530753
Mythri P Kc3198a52011-03-12 12:04:27 +0530754 mutex_unlock(&hdmi.lock);
755}
756
Tomi Valkeinen44898232012-10-19 17:42:27 +0300757int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
758{
759 int r = 0;
760
761 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
762
763 mutex_lock(&hdmi.lock);
764
Tomi Valkeinen44898232012-10-19 17:42:27 +0300765 r = hdmi_power_on_core(dssdev);
766 if (r) {
767 DSSERR("failed to power on device\n");
768 goto err0;
769 }
770
771 mutex_unlock(&hdmi.lock);
772 return 0;
773
774err0:
775 mutex_unlock(&hdmi.lock);
776 return r;
777}
778
779void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
780{
781 DSSDBG("Enter omapdss_hdmi_core_disable\n");
782
783 mutex_lock(&hdmi.lock);
784
785 hdmi_power_off_core(dssdev);
786
787 mutex_unlock(&hdmi.lock);
788}
789
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300790static int hdmi_get_clocks(struct platform_device *pdev)
791{
792 struct clk *clk;
793
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300794 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300795 if (IS_ERR(clk)) {
796 DSSERR("can't get sys_clk\n");
797 return PTR_ERR(clk);
798 }
799
800 hdmi.sys_clk = clk;
801
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300802 return 0;
803}
804
Ricardo Neri35547622012-03-20 21:02:01 -0600805#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
806int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
807{
808 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600809 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600810 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
811
812 if (n == NULL || cts == NULL)
813 return -EINVAL;
814
815 /* TODO: When implemented, query deep color mode here. */
816 deep_color = 100;
817
Ricardo Neri25a65352012-03-23 15:49:02 -0600818 /*
819 * When using deep color, the default N value (as in the HDMI
820 * specification) yields to an non-integer CTS. Hence, we
821 * modify it while keeping the restrictions described in
822 * section 7.2.1 of the HDMI 1.4a specification.
823 */
Ricardo Neri35547622012-03-20 21:02:01 -0600824 switch (sample_freq) {
825 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600826 case 48000:
827 case 96000:
828 case 192000:
829 if (deep_color == 125)
830 if (pclk == 27027 || pclk == 74250)
831 deep_color_correct = true;
832 if (deep_color == 150)
833 if (pclk == 27027)
834 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600835 break;
836 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600837 case 88200:
838 case 176400:
839 if (deep_color == 125)
840 if (pclk == 27027)
841 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600842 break;
843 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600844 return -EINVAL;
845 }
846
Ricardo Neri25a65352012-03-23 15:49:02 -0600847 if (deep_color_correct) {
848 switch (sample_freq) {
849 case 32000:
850 *n = 8192;
851 break;
852 case 44100:
853 *n = 12544;
854 break;
855 case 48000:
856 *n = 8192;
857 break;
858 case 88200:
859 *n = 25088;
860 break;
861 case 96000:
862 *n = 16384;
863 break;
864 case 176400:
865 *n = 50176;
866 break;
867 case 192000:
868 *n = 32768;
869 break;
870 default:
871 return -EINVAL;
872 }
873 } else {
874 switch (sample_freq) {
875 case 32000:
876 *n = 4096;
877 break;
878 case 44100:
879 *n = 6272;
880 break;
881 case 48000:
882 *n = 6144;
883 break;
884 case 88200:
885 *n = 12544;
886 break;
887 case 96000:
888 *n = 12288;
889 break;
890 case 176400:
891 *n = 25088;
892 break;
893 case 192000:
894 *n = 24576;
895 break;
896 default:
897 return -EINVAL;
898 }
899 }
Ricardo Neri35547622012-03-20 21:02:01 -0600900 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
901 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
902
903 return 0;
904}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500905
906int hdmi_audio_enable(void)
907{
908 DSSDBG("audio_enable\n");
909
910 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
911}
912
913void hdmi_audio_disable(void)
914{
915 DSSDBG("audio_disable\n");
916
917 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
918}
919
920int hdmi_audio_start(void)
921{
922 DSSDBG("audio_start\n");
923
924 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
925}
926
927void hdmi_audio_stop(void)
928{
929 DSSDBG("audio_stop\n");
930
931 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
932}
933
934bool hdmi_mode_has_audio(void)
935{
936 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
937 return true;
938 else
939 return false;
940}
941
942int hdmi_audio_config(struct omap_dss_audio *audio)
943{
944 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
945}
946
Ricardo Neri35547622012-03-20 21:02:01 -0600947#endif
948
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300949static struct omap_dss_device *hdmi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300950{
951 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Tomi Valkeinen2bbcce52012-10-29 12:40:46 +0200952 const char *def_disp_name = omapdss_get_default_display_name();
Tomi Valkeinen15216532012-09-06 14:29:31 +0300953 struct omap_dss_device *def_dssdev;
954 int i;
955
956 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300957
958 for (i = 0; i < pdata->num_devices; ++i) {
959 struct omap_dss_device *dssdev = pdata->devices[i];
960
961 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
962 continue;
963
Tomi Valkeinen15216532012-09-06 14:29:31 +0300964 if (def_dssdev == NULL)
965 def_dssdev = dssdev;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300966
Tomi Valkeinen15216532012-09-06 14:29:31 +0300967 if (def_disp_name != NULL &&
968 strcmp(dssdev->name, def_disp_name) == 0) {
969 def_dssdev = dssdev;
970 break;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300971 }
Tomi Valkeinen15216532012-09-06 14:29:31 +0300972 }
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300973
Tomi Valkeinen15216532012-09-06 14:29:31 +0300974 return def_dssdev;
975}
976
Tomi Valkeinenc0980292013-04-26 14:52:23 +0300977static int hdmi_probe_pdata(struct platform_device *pdev)
Tomi Valkeinen15216532012-09-06 14:29:31 +0300978{
Tomi Valkeinen52744842012-09-10 13:58:29 +0300979 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300980 struct omap_dss_device *dssdev;
981 struct omap_dss_hdmi_data *priv;
982 int r;
983
Tomi Valkeinen52744842012-09-10 13:58:29 +0300984 plat_dssdev = hdmi_find_dssdev(pdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300985
Tomi Valkeinen52744842012-09-10 13:58:29 +0300986 if (!plat_dssdev)
Tomi Valkeinenc0980292013-04-26 14:52:23 +0300987 return 0;
Tomi Valkeinen52744842012-09-10 13:58:29 +0300988
989 dssdev = dss_alloc_and_init_device(&pdev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300990 if (!dssdev)
Tomi Valkeinenc0980292013-04-26 14:52:23 +0300991 return -ENOMEM;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300992
Tomi Valkeinen52744842012-09-10 13:58:29 +0300993 dss_copy_device_pdata(dssdev, plat_dssdev);
994
Tomi Valkeinen15216532012-09-06 14:29:31 +0300995 priv = dssdev->data;
996
997 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
998 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
999 hdmi.hpd_gpio = priv->hpd_gpio;
1000
1001 r = hdmi_init_display(dssdev);
1002 if (r) {
1003 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +03001004 dss_put_device(dssdev);
Tomi Valkeinenc0980292013-04-26 14:52:23 +03001005 return r;
Tomi Valkeinen15216532012-09-06 14:29:31 +03001006 }
1007
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02001008 r = omapdss_output_set_device(&hdmi.output, dssdev);
1009 if (r) {
1010 DSSERR("failed to connect output to new device: %s\n",
1011 dssdev->name);
1012 dss_put_device(dssdev);
Tomi Valkeinenc0980292013-04-26 14:52:23 +03001013 return r;
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02001014 }
1015
Tomi Valkeinen52744842012-09-10 13:58:29 +03001016 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03001017 if (r) {
1018 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02001019 omapdss_output_unset_device(&hdmi.output);
Ricardo Nerid18bc452012-11-06 00:19:15 -06001020 hdmi_uninit_display(dssdev);
Tomi Valkeinen52744842012-09-10 13:58:29 +03001021 dss_put_device(dssdev);
Tomi Valkeinenc0980292013-04-26 14:52:23 +03001022 return r;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001023 }
Tomi Valkeinenc0980292013-04-26 14:52:23 +03001024
1025 return 0;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001026}
1027
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001028static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +05301029{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001030 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301031
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001032 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +05301033 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001034 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +02001035 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02001036 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +03001037 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +05301038
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001039 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301040}
1041
1042static void __exit hdmi_uninit_output(struct platform_device *pdev)
1043{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001044 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +05301045
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03001046 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05301047}
1048
Mythri P Kc3198a52011-03-12 12:04:27 +05301049/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001050static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301051{
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001052 struct resource *res;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001053 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301054
Mythri P Kc3198a52011-03-12 12:04:27 +05301055 hdmi.pdev = pdev;
1056
1057 mutex_init(&hdmi.lock);
Ricardo Neri66a06b02012-11-06 00:19:14 -06001058 mutex_init(&hdmi.ip_data.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +05301059
Ricardo Neriaf23cb32012-11-06 00:19:11 -06001060 res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +05301061
1062 /* Base address taken from platform */
Thierry Redingbc3bad12013-01-21 11:09:23 +01001063 hdmi.ip_data.base_wp = devm_ioremap_resource(&pdev->dev, res);
1064 if (IS_ERR(hdmi.ip_data.base_wp))
1065 return PTR_ERR(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301066
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +03001067 hdmi.ip_data.irq = platform_get_irq(pdev, 0);
1068 if (hdmi.ip_data.irq < 0) {
1069 DSSERR("platform_get_irq failed\n");
1070 return -ENODEV;
1071 }
1072
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001073 r = hdmi_get_clocks(pdev);
1074 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -06001075 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001076 return r;
1077 }
1078
1079 pm_runtime_enable(&pdev->dev);
1080
Mythri P K95a8aeb2011-09-08 19:06:18 +05301081 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1082 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1083 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1084 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +05301085
Tomi Valkeinen002d3682013-02-13 12:17:43 +02001086 hdmi_init_output(pdev);
1087
Ricardo Neri66a06b02012-11-06 00:19:14 -06001088 r = hdmi_panel_init();
1089 if (r) {
1090 DSSERR("can't init panel\n");
Archit Tanejab2c9c8e2013-04-08 11:55:00 +03001091 return r;
Ricardo Neri66a06b02012-11-06 00:19:14 -06001092 }
Mythri P Kc3198a52011-03-12 12:04:27 +05301093
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001094 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1095
Tomi Valkeinenc6ca5b22013-03-14 15:47:29 +02001096 if (pdev->dev.platform_data) {
1097 r = hdmi_probe_pdata(pdev);
1098 if (r)
1099 goto err_probe;
Tomi Valkeinenc0980292013-04-26 14:52:23 +03001100 }
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001101
Mythri P Kc3198a52011-03-12 12:04:27 +05301102 return 0;
Tomi Valkeinenc6ca5b22013-03-14 15:47:29 +02001103
1104err_probe:
1105 hdmi_panel_exit();
1106 hdmi_uninit_output(pdev);
1107 pm_runtime_disable(&pdev->dev);
1108 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301109}
1110
Tomi Valkeinencca35012012-04-26 14:48:32 +03001111static int __exit hdmi_remove_child(struct device *dev, void *data)
1112{
1113 struct omap_dss_device *dssdev = to_dss_device(dev);
1114 hdmi_uninit_display(dssdev);
1115 return 0;
1116}
1117
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001118static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301119{
Tomi Valkeinencca35012012-04-26 14:48:32 +03001120 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1121
Tomi Valkeinen52744842012-09-10 13:58:29 +03001122 dss_unregister_child_devices(&pdev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001123
Mythri P Kc3198a52011-03-12 12:04:27 +05301124 hdmi_panel_exit();
1125
Archit Taneja81b87f52012-09-26 16:30:49 +05301126 hdmi_uninit_output(pdev);
1127
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001128 pm_runtime_disable(&pdev->dev);
1129
Mythri P Kc3198a52011-03-12 12:04:27 +05301130 return 0;
1131}
1132
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001133static int hdmi_runtime_suspend(struct device *dev)
1134{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301135 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001136
1137 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001138
1139 return 0;
1140}
1141
1142static int hdmi_runtime_resume(struct device *dev)
1143{
1144 int r;
1145
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001146 r = dispc_runtime_get();
1147 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001148 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001149
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301150 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001151
1152 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001153}
1154
1155static const struct dev_pm_ops hdmi_pm_ops = {
1156 .runtime_suspend = hdmi_runtime_suspend,
1157 .runtime_resume = hdmi_runtime_resume,
1158};
1159
Mythri P Kc3198a52011-03-12 12:04:27 +05301160static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001161 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001162 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301163 .driver = {
1164 .name = "omapdss_hdmi",
1165 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001166 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301167 },
1168};
1169
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001170int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301171{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +03001172 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301173}
1174
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001175void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301176{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001177 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301178}