blob: adcc906d12f860fee01fce8089d2cce253960a73 [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 Valkeinen8d887672011-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;
Mythri P K95a8aeb2011-09-08 19:06:18 +053063 struct hdmi_ip_data ip_data;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030064
65 struct clk *sys_clk;
Tomi Valkeinen17486942012-08-15 15:55:04 +030066 struct regulator *vdda_hdmi_dac_reg;
Tomi Valkeinencca35012012-04-26 14:48:32 +030067
68 int ct_cp_hpd_gpio;
69 int ls_oe_gpio;
70 int hpd_gpio;
Archit Taneja81b87f52012-09-26 16:30:49 +053071
72 struct omap_dss_output output;
Mythri P Kc3198a52011-03-12 12:04:27 +053073} hdmi;
74
75/*
76 * Logic for the below structure :
77 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
78 * There is a correspondence between CEA/VESA timing and code, please
79 * refer to section 6.3 in HDMI 1.3 specification for timing code.
80 *
81 * In the below structure, cea_vesa_timings corresponds to all OMAP4
82 * supported CEA and VESA timing values.code_cea corresponds to the CEA
83 * code, It is used to get the timing from cea_vesa_timing array.Similarly
84 * with code_vesa. Code_index is used for back mapping, that is once EDID
85 * is read from the TV, EDID is parsed to find the timing values and then
86 * map it to corresponding CEA or VESA index.
87 */
88
Mythri P K46095b22012-01-06 17:52:09 +053089static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053090 {
91 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
92 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
93 false, },
94 { 1, HDMI_HDMI },
95 },
96 {
97 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
98 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
99 false, },
100 { 2, HDMI_HDMI },
101 },
102 {
103 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
104 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
105 false, },
106 { 4, HDMI_HDMI },
107 },
108 {
109 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
110 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
111 true, },
112 { 5, HDMI_HDMI },
113 },
114 {
115 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
116 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
117 true, },
118 { 6, HDMI_HDMI },
119 },
120 {
121 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
122 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
123 false, },
124 { 16, HDMI_HDMI },
125 },
126 {
127 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
128 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
129 false, },
130 { 17, HDMI_HDMI },
131 },
132 {
133 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
134 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
135 false, },
136 { 19, HDMI_HDMI },
137 },
138 {
139 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
140 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
141 true, },
142 { 20, HDMI_HDMI },
143 },
144 {
145 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
146 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
147 true, },
148 { 21, HDMI_HDMI },
149 },
150 {
151 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
152 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
153 false, },
154 { 29, HDMI_HDMI },
155 },
156 {
157 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
158 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
159 false, },
160 { 31, HDMI_HDMI },
161 },
162 {
163 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
164 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
165 false, },
166 { 32, HDMI_HDMI },
167 },
168 {
169 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
170 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
171 false, },
172 { 35, HDMI_HDMI },
173 },
174 {
175 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
176 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
177 false, },
178 { 37, HDMI_HDMI },
179 },
Mythri P K46095b22012-01-06 17:52:09 +0530180};
Archit Tanejacc937e52012-06-24 13:08:10 +0530181
Mythri P K46095b22012-01-06 17:52:09 +0530182static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530183/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530184 {
185 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
186 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
187 false, },
188 { 4, HDMI_DVI },
189 },
190 {
191 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
192 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
193 false, },
194 { 9, HDMI_DVI },
195 },
196 {
197 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
198 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
199 false, },
200 { 0xE, HDMI_DVI },
201 },
202 {
203 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
204 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
205 false, },
206 { 0x17, HDMI_DVI },
207 },
208 {
209 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
210 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
211 false, },
212 { 0x1C, HDMI_DVI },
213 },
214 {
215 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
216 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
217 false, },
218 { 0x27, HDMI_DVI },
219 },
220 {
221 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
222 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
223 false, },
224 { 0x20, HDMI_DVI },
225 },
226 {
227 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
228 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
229 false, },
230 { 0x23, HDMI_DVI },
231 },
232 {
233 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
234 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
235 false, },
236 { 0x10, HDMI_DVI },
237 },
238 {
239 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
240 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
241 false, },
242 { 0x2A, HDMI_DVI },
243 },
244 {
245 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
246 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
247 false, },
248 { 0x2F, HDMI_DVI },
249 },
250 {
251 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
252 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
253 false, },
254 { 0x3A, HDMI_DVI },
255 },
256 {
257 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
258 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
259 false, },
260 { 0x51, HDMI_DVI },
261 },
262 {
263 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
264 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
265 false, },
266 { 0x52, HDMI_DVI },
267 },
268 {
269 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
270 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
271 false, },
272 { 0x16, HDMI_DVI },
273 },
274 {
275 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
276 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
277 false, },
278 { 0x29, HDMI_DVI },
279 },
280 {
281 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
282 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
283 false, },
284 { 0x39, HDMI_DVI },
285 },
286 {
287 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
288 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
289 false, },
290 { 0x1B, HDMI_DVI },
291 },
292 {
293 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
294 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
295 false, },
296 { 0x55, HDMI_DVI },
297 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530298};
299
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300300static int hdmi_runtime_get(void)
301{
302 int r;
303
304 DSSDBG("hdmi_runtime_get\n");
305
306 r = pm_runtime_get_sync(&hdmi.pdev->dev);
307 WARN_ON(r < 0);
Archit Tanejaa247ce72012-02-10 11:45:52 +0530308 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200309 return r;
Archit Tanejaa247ce72012-02-10 11:45:52 +0530310
311 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300312}
313
314static void hdmi_runtime_put(void)
315{
316 int r;
317
318 DSSDBG("hdmi_runtime_put\n");
319
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200320 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300321 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300322}
323
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200324static int __init hdmi_init_display(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530325{
Tomi Valkeinen6fa44902012-09-28 13:00:33 +0300326 struct omap_dss_board_info *pdata = hdmi.pdev->dev.platform_data;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300327 int r;
328
329 struct gpio gpios[] = {
330 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
331 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
332 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
333 };
334
Mythri P Kc3198a52011-03-12 12:04:27 +0530335 DSSDBG("init_display\n");
336
Tomi Valkeinen6fa44902012-09-28 13:00:33 +0300337 dss_init_hdmi_ip_ops(&hdmi.ip_data, pdata->version);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300338
Tomi Valkeinen17486942012-08-15 15:55:04 +0300339 if (hdmi.vdda_hdmi_dac_reg == NULL) {
340 struct regulator *reg;
341
342 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
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
Tomi Valkeinencca35012012-04-26 14:48:32 +0300352 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
353 if (r)
354 return r;
355
Mythri P Kc3198a52011-03-12 12:04:27 +0530356 return 0;
357}
358
Tomi Valkeinencca35012012-04-26 14:48:32 +0300359static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev)
360{
361 DSSDBG("uninit_display\n");
362
363 gpio_free(hdmi.ct_cp_hpd_gpio);
364 gpio_free(hdmi.ls_oe_gpio);
365 gpio_free(hdmi.hpd_gpio);
366}
367
Mythri P K46095b22012-01-06 17:52:09 +0530368static const struct hdmi_config *hdmi_find_timing(
369 const struct hdmi_config *timings_arr,
370 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530371{
Mythri P K46095b22012-01-06 17:52:09 +0530372 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530373
Mythri P K46095b22012-01-06 17:52:09 +0530374 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530375 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530376 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530377 }
Mythri P K46095b22012-01-06 17:52:09 +0530378 return NULL;
379}
380
381static const struct hdmi_config *hdmi_get_timings(void)
382{
383 const struct hdmi_config *arr;
384 int len;
385
Mythri P K9e4ed602012-01-06 17:52:10 +0530386 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530387 arr = vesa_timings;
388 len = ARRAY_SIZE(vesa_timings);
389 } else {
390 arr = cea_timings;
391 len = ARRAY_SIZE(cea_timings);
392 }
393
394 return hdmi_find_timing(arr, len);
395}
396
397static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530398 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530399{
400 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
401
402 if ((timing2->pixel_clock == timing1->pixel_clock) &&
403 (timing2->x_res == timing1->x_res) &&
404 (timing2->y_res == timing1->y_res)) {
405
406 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
407 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
408 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
409 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
410
411 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
412 "timing2_hsync = %d timing2_vsync = %d\n",
413 timing1_hsync, timing1_vsync,
414 timing2_hsync, timing2_vsync);
415
416 if ((timing1_hsync == timing2_hsync) &&
417 (timing1_vsync == timing2_vsync)) {
418 return true;
419 }
420 }
421 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530422}
423
424static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
425{
Mythri P K46095b22012-01-06 17:52:09 +0530426 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530427 struct hdmi_cm cm = {-1};
428 DSSDBG("hdmi_get_code\n");
429
Mythri P K46095b22012-01-06 17:52:09 +0530430 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
431 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
432 cm = cea_timings[i].cm;
433 goto end;
434 }
435 }
436 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
437 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
438 cm = vesa_timings[i].cm;
439 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530440 }
441 }
442
Mythri P K46095b22012-01-06 17:52:09 +0530443end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530444
Mythri P Kc3198a52011-03-12 12:04:27 +0530445}
446
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530447unsigned long hdmi_get_pixel_clock(void)
448{
449 /* HDMI Pixel Clock in Mhz */
Mythri P Ka05ce782012-01-06 17:52:08 +0530450 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530451}
452
Archit Taneja6cb07b22011-04-12 13:52:25 +0530453static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
454 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530455{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530456 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530457 u32 mf;
458
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300459 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530460 /*
461 * Input clock is predivided by N + 1
462 * out put of which is reference clk
463 */
Tomi Valkeinen8d887672011-08-22 13:02:52 +0300464 if (dssdev->clocks.hdmi.regn == 0)
465 pi->regn = HDMI_DEFAULT_REGN;
466 else
467 pi->regn = dssdev->clocks.hdmi.regn;
468
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300469 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530470
Tomi Valkeinen8d887672011-08-22 13:02:52 +0300471 if (dssdev->clocks.hdmi.regm2 == 0)
472 pi->regm2 = HDMI_DEFAULT_REGM2;
473 else
474 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530475
476 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530477 * multiplier is pixel_clk/ref_clk
478 * Multiplying by 100 to avoid fractional part removal
479 */
480 pi->regm = phy * pi->regm2 / refclk;
481
482 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530483 * fractional multiplier is remainder of the difference between
484 * multiplier and actual phy(required pixel clock thus should be
485 * multiplied by 2^18(262144) divided by the reference clock
486 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530487 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
488 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530489
490 /*
491 * Dcofreq should be set to 1 if required pixel clock
492 * is greater than 1000MHz
493 */
494 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300495 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530496
Mythri P K7b27da52011-09-08 19:06:19 +0530497 /* Set the reference clock to sysclk reference */
498 pi->refsel = HDMI_REFSEL_SYSCLK;
499
Mythri P Kc3198a52011-03-12 12:04:27 +0530500 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
501 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
502}
503
Mythri P Kc3198a52011-03-12 12:04:27 +0530504static int hdmi_power_on(struct omap_dss_device *dssdev)
505{
Mythri P K46095b22012-01-06 17:52:09 +0530506 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530507 struct omap_video_timings *p;
Archit Tanejacea87b92012-09-07 17:56:20 +0530508 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530509 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +0530510
Tomi Valkeinencca35012012-04-26 14:48:32 +0300511 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
512 gpio_set_value(hdmi.ls_oe_gpio, 1);
513
Tomi Valkeinena84b2062012-04-26 14:58:41 +0300514 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
515 udelay(300);
516
Tomi Valkeinen17486942012-08-15 15:55:04 +0300517 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
518 if (r)
519 goto err_vdac_enable;
520
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300521 r = hdmi_runtime_get();
522 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300523 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530524
Archit Tanejacea87b92012-09-07 17:56:20 +0530525 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530526
Archit Taneja78493982012-08-08 16:50:42 +0530527 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530528
Archit Taneja78493982012-08-08 16:50:42 +0530529 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 +0530530
Mythri P Kc3198a52011-03-12 12:04:27 +0530531 phy = p->pixel_clock;
532
Mythri P K7b27da52011-09-08 19:06:19 +0530533 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530534
Ricardo Neric0456be2012-04-27 13:48:45 -0500535 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530536
Mythri P K95a8aeb2011-09-08 19:06:18 +0530537 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530538 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530539 if (r) {
540 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300541 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530542 }
543
Mythri P K60634a22011-09-08 19:06:26 +0530544 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530545 if (r) {
546 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500547 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530548 }
549
Mythri P K60634a22011-09-08 19:06:26 +0530550 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530551
552 /* Make selection of HDMI in DSS */
553 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
554
555 /* Select the dispc clock source as PRCM clock, to ensure that it is not
556 * DSI PLL source as the clock selected by DSI PLL might not be
557 * sufficient for the resolution selected / that can be changed
558 * dynamically by user. This can be moved to single location , say
559 * Boardfile.
560 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530561 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +0530562
563 /* bypass TV gamma table */
564 dispc_enable_gamma_table(0);
565
566 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530567 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530568
Ricardo Neric0456be2012-04-27 13:48:45 -0500569 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
570 if (r)
571 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530572
Archit Tanejacea87b92012-09-07 17:56:20 +0530573 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200574 if (r)
575 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300576
Mythri P Kc3198a52011-03-12 12:04:27 +0530577 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200578
579err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500580 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
581err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200582 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500583err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200584 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300585err_pll_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300586 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300587err_runtime_get:
Tomi Valkeinen17486942012-08-15 15:55:04 +0300588 regulator_disable(hdmi.vdda_hdmi_dac_reg);
589err_vdac_enable:
Tomi Valkeinencca35012012-04-26 14:48:32 +0300590 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
591 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530592 return -EIO;
593}
594
595static void hdmi_power_off(struct omap_dss_device *dssdev)
596{
Archit Tanejacea87b92012-09-07 17:56:20 +0530597 struct omap_overlay_manager *mgr = dssdev->output->manager;
598
599 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530600
Ricardo Neric0456be2012-04-27 13:48:45 -0500601 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P K60634a22011-09-08 19:06:26 +0530602 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
603 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300604 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300605
Tomi Valkeinen17486942012-08-15 15:55:04 +0300606 regulator_disable(hdmi.vdda_hdmi_dac_reg);
607
Tomi Valkeinencca35012012-04-26 14:48:32 +0300608 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
609 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530610}
611
612int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
613 struct omap_video_timings *timings)
614{
615 struct hdmi_cm cm;
616
617 cm = hdmi_get_code(timings);
618 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530619 return -EINVAL;
620 }
621
622 return 0;
623
624}
625
Archit Taneja78493982012-08-08 16:50:42 +0530626void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
627 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530628{
629 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530630 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530631
Archit Tanejaed1aa902012-08-15 00:40:31 +0530632 mutex_lock(&hdmi.lock);
633
Archit Taneja78493982012-08-08 16:50:42 +0530634 cm = hdmi_get_code(timings);
635 hdmi.ip_data.cfg.cm = cm;
636
637 t = hdmi_get_timings();
638 if (t != NULL)
639 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300640
Archit Tanejaed1aa902012-08-15 00:40:31 +0530641 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530642}
643
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200644static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530645{
646 mutex_lock(&hdmi.lock);
647
648 if (hdmi_runtime_get())
649 return;
650
651 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
652 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
653 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
654 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
655
656 hdmi_runtime_put();
657 mutex_unlock(&hdmi.lock);
658}
659
Tomi Valkeinen47024562011-08-25 17:12:56 +0300660int omapdss_hdmi_read_edid(u8 *buf, int len)
661{
662 int r;
663
664 mutex_lock(&hdmi.lock);
665
666 r = hdmi_runtime_get();
667 BUG_ON(r);
668
669 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
670
671 hdmi_runtime_put();
672 mutex_unlock(&hdmi.lock);
673
674 return r;
675}
676
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300677bool omapdss_hdmi_detect(void)
678{
679 int r;
680
681 mutex_lock(&hdmi.lock);
682
683 r = hdmi_runtime_get();
684 BUG_ON(r);
685
686 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
687
688 hdmi_runtime_put();
689 mutex_unlock(&hdmi.lock);
690
691 return r == 1;
692}
693
Mythri P Kc3198a52011-03-12 12:04:27 +0530694int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
695{
Archit Tanejacea87b92012-09-07 17:56:20 +0530696 struct omap_dss_output *out = dssdev->output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530697 int r = 0;
698
699 DSSDBG("ENTER hdmi_display_enable\n");
700
701 mutex_lock(&hdmi.lock);
702
Archit Tanejacea87b92012-09-07 17:56:20 +0530703 if (out == NULL || out->manager == NULL) {
704 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300705 r = -ENODEV;
706 goto err0;
707 }
708
Tomi Valkeinencca35012012-04-26 14:48:32 +0300709 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
Tomi Valkeinenc49d0052012-01-17 11:09:57 +0200710
Mythri P Kc3198a52011-03-12 12:04:27 +0530711 r = omap_dss_start_device(dssdev);
712 if (r) {
713 DSSERR("failed to start device\n");
714 goto err0;
715 }
716
Mythri P Kc3198a52011-03-12 12:04:27 +0530717 r = hdmi_power_on(dssdev);
718 if (r) {
719 DSSERR("failed to power on device\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300720 goto err1;
Mythri P Kc3198a52011-03-12 12:04:27 +0530721 }
722
723 mutex_unlock(&hdmi.lock);
724 return 0;
725
Mythri P Kc3198a52011-03-12 12:04:27 +0530726err1:
727 omap_dss_stop_device(dssdev);
728err0:
729 mutex_unlock(&hdmi.lock);
730 return r;
731}
732
733void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
734{
735 DSSDBG("Enter hdmi_display_disable\n");
736
737 mutex_lock(&hdmi.lock);
738
739 hdmi_power_off(dssdev);
740
Mythri P Kc3198a52011-03-12 12:04:27 +0530741 omap_dss_stop_device(dssdev);
742
743 mutex_unlock(&hdmi.lock);
744}
745
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300746static int hdmi_get_clocks(struct platform_device *pdev)
747{
748 struct clk *clk;
749
750 clk = clk_get(&pdev->dev, "sys_clk");
751 if (IS_ERR(clk)) {
752 DSSERR("can't get sys_clk\n");
753 return PTR_ERR(clk);
754 }
755
756 hdmi.sys_clk = clk;
757
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300758 return 0;
759}
760
761static void hdmi_put_clocks(void)
762{
763 if (hdmi.sys_clk)
764 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300765}
766
Ricardo Neri35547622012-03-20 21:02:01 -0600767#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
768int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
769{
770 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600771 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600772 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
773
774 if (n == NULL || cts == NULL)
775 return -EINVAL;
776
777 /* TODO: When implemented, query deep color mode here. */
778 deep_color = 100;
779
Ricardo Neri25a65352012-03-23 15:49:02 -0600780 /*
781 * When using deep color, the default N value (as in the HDMI
782 * specification) yields to an non-integer CTS. Hence, we
783 * modify it while keeping the restrictions described in
784 * section 7.2.1 of the HDMI 1.4a specification.
785 */
Ricardo Neri35547622012-03-20 21:02:01 -0600786 switch (sample_freq) {
787 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600788 case 48000:
789 case 96000:
790 case 192000:
791 if (deep_color == 125)
792 if (pclk == 27027 || pclk == 74250)
793 deep_color_correct = true;
794 if (deep_color == 150)
795 if (pclk == 27027)
796 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600797 break;
798 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600799 case 88200:
800 case 176400:
801 if (deep_color == 125)
802 if (pclk == 27027)
803 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600804 break;
805 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600806 return -EINVAL;
807 }
808
Ricardo Neri25a65352012-03-23 15:49:02 -0600809 if (deep_color_correct) {
810 switch (sample_freq) {
811 case 32000:
812 *n = 8192;
813 break;
814 case 44100:
815 *n = 12544;
816 break;
817 case 48000:
818 *n = 8192;
819 break;
820 case 88200:
821 *n = 25088;
822 break;
823 case 96000:
824 *n = 16384;
825 break;
826 case 176400:
827 *n = 50176;
828 break;
829 case 192000:
830 *n = 32768;
831 break;
832 default:
833 return -EINVAL;
834 }
835 } else {
836 switch (sample_freq) {
837 case 32000:
838 *n = 4096;
839 break;
840 case 44100:
841 *n = 6272;
842 break;
843 case 48000:
844 *n = 6144;
845 break;
846 case 88200:
847 *n = 12544;
848 break;
849 case 96000:
850 *n = 12288;
851 break;
852 case 176400:
853 *n = 25088;
854 break;
855 case 192000:
856 *n = 24576;
857 break;
858 default:
859 return -EINVAL;
860 }
861 }
Ricardo Neri35547622012-03-20 21:02:01 -0600862 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
863 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
864
865 return 0;
866}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500867
868int hdmi_audio_enable(void)
869{
870 DSSDBG("audio_enable\n");
871
872 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
873}
874
875void hdmi_audio_disable(void)
876{
877 DSSDBG("audio_disable\n");
878
879 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
880}
881
882int hdmi_audio_start(void)
883{
884 DSSDBG("audio_start\n");
885
886 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
887}
888
889void hdmi_audio_stop(void)
890{
891 DSSDBG("audio_stop\n");
892
893 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
894}
895
896bool hdmi_mode_has_audio(void)
897{
898 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
899 return true;
900 else
901 return false;
902}
903
904int hdmi_audio_config(struct omap_dss_audio *audio)
905{
906 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
907}
908
Ricardo Neri35547622012-03-20 21:02:01 -0600909#endif
910
Tomi Valkeinen15216532012-09-06 14:29:31 +0300911static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300912{
913 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300914 const char *def_disp_name = dss_get_default_display_name();
915 struct omap_dss_device *def_dssdev;
916 int i;
917
918 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300919
920 for (i = 0; i < pdata->num_devices; ++i) {
921 struct omap_dss_device *dssdev = pdata->devices[i];
922
923 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
924 continue;
925
Tomi Valkeinen15216532012-09-06 14:29:31 +0300926 if (def_dssdev == NULL)
927 def_dssdev = dssdev;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300928
Tomi Valkeinen15216532012-09-06 14:29:31 +0300929 if (def_disp_name != NULL &&
930 strcmp(dssdev->name, def_disp_name) == 0) {
931 def_dssdev = dssdev;
932 break;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300933 }
Tomi Valkeinen15216532012-09-06 14:29:31 +0300934 }
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300935
Tomi Valkeinen15216532012-09-06 14:29:31 +0300936 return def_dssdev;
937}
938
939static void __init hdmi_probe_pdata(struct platform_device *pdev)
940{
Tomi Valkeinen52744842012-09-10 13:58:29 +0300941 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300942 struct omap_dss_device *dssdev;
943 struct omap_dss_hdmi_data *priv;
944 int r;
945
Tomi Valkeinen52744842012-09-10 13:58:29 +0300946 plat_dssdev = hdmi_find_dssdev(pdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300947
Tomi Valkeinen52744842012-09-10 13:58:29 +0300948 if (!plat_dssdev)
949 return;
950
951 dssdev = dss_alloc_and_init_device(&pdev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300952 if (!dssdev)
953 return;
954
Tomi Valkeinen52744842012-09-10 13:58:29 +0300955 dss_copy_device_pdata(dssdev, plat_dssdev);
956
Tomi Valkeinen15216532012-09-06 14:29:31 +0300957 priv = dssdev->data;
958
959 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
960 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
961 hdmi.hpd_gpio = priv->hpd_gpio;
962
Tomi Valkeinenbcb226a2012-09-07 15:21:36 +0300963 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
964
Tomi Valkeinen15216532012-09-06 14:29:31 +0300965 r = hdmi_init_display(dssdev);
966 if (r) {
967 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +0300968 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300969 return;
970 }
971
Tomi Valkeinen52744842012-09-10 13:58:29 +0300972 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300973 if (r) {
974 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +0300975 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300976 return;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300977 }
978}
979
Archit Taneja81b87f52012-09-26 16:30:49 +0530980static void __init hdmi_init_output(struct platform_device *pdev)
981{
982 struct omap_dss_output *out = &hdmi.output;
983
984 out->pdev = pdev;
985 out->id = OMAP_DSS_OUTPUT_HDMI;
986 out->type = OMAP_DISPLAY_TYPE_HDMI;
987
988 dss_register_output(out);
989}
990
991static void __exit hdmi_uninit_output(struct platform_device *pdev)
992{
993 struct omap_dss_output *out = &hdmi.output;
994
995 dss_unregister_output(out);
996}
997
Mythri P Kc3198a52011-03-12 12:04:27 +0530998/* HDMI HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200999static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301000{
1001 struct resource *hdmi_mem;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001002 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +05301003
Mythri P Kc3198a52011-03-12 12:04:27 +05301004 hdmi.pdev = pdev;
1005
1006 mutex_init(&hdmi.lock);
1007
1008 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
1009 if (!hdmi_mem) {
1010 DSSERR("can't get IORESOURCE_MEM HDMI\n");
1011 return -EINVAL;
1012 }
1013
1014 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +05301015 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
1016 resource_size(hdmi_mem));
1017 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +05301018 DSSERR("can't ioremap WP\n");
1019 return -ENOMEM;
1020 }
1021
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001022 r = hdmi_get_clocks(pdev);
1023 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +05301024 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001025 return r;
1026 }
1027
1028 pm_runtime_enable(&pdev->dev);
1029
Mythri P K95a8aeb2011-09-08 19:06:18 +05301030 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
1031 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
1032 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
1033 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +05301034
Jassi Brar3a5383a2012-06-27 19:34:56 +05301035 mutex_init(&hdmi.ip_data.lock);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301036
Mythri P Kc3198a52011-03-12 12:04:27 +05301037 hdmi_panel_init();
1038
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001039 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1040
Archit Taneja81b87f52012-09-26 16:30:49 +05301041 hdmi_init_output(pdev);
1042
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001043 hdmi_probe_pdata(pdev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001044
Mythri P Kc3198a52011-03-12 12:04:27 +05301045 return 0;
1046}
1047
Tomi Valkeinencca35012012-04-26 14:48:32 +03001048static int __exit hdmi_remove_child(struct device *dev, void *data)
1049{
1050 struct omap_dss_device *dssdev = to_dss_device(dev);
1051 hdmi_uninit_display(dssdev);
1052 return 0;
1053}
1054
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001055static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301056{
Tomi Valkeinencca35012012-04-26 14:48:32 +03001057 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1058
Tomi Valkeinen52744842012-09-10 13:58:29 +03001059 dss_unregister_child_devices(&pdev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001060
Mythri P Kc3198a52011-03-12 12:04:27 +05301061 hdmi_panel_exit();
1062
Archit Taneja81b87f52012-09-26 16:30:49 +05301063 hdmi_uninit_output(pdev);
1064
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001065 pm_runtime_disable(&pdev->dev);
1066
1067 hdmi_put_clocks();
1068
Mythri P K95a8aeb2011-09-08 19:06:18 +05301069 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301070
1071 return 0;
1072}
1073
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001074static int hdmi_runtime_suspend(struct device *dev)
1075{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301076 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001077
1078 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001079
1080 return 0;
1081}
1082
1083static int hdmi_runtime_resume(struct device *dev)
1084{
1085 int r;
1086
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001087 r = dispc_runtime_get();
1088 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001089 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001090
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301091 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001092
1093 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001094}
1095
1096static const struct dev_pm_ops hdmi_pm_ops = {
1097 .runtime_suspend = hdmi_runtime_suspend,
1098 .runtime_resume = hdmi_runtime_resume,
1099};
1100
Mythri P Kc3198a52011-03-12 12:04:27 +05301101static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001102 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301103 .driver = {
1104 .name = "omapdss_hdmi",
1105 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001106 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301107 },
1108};
1109
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001110int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301111{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02001112 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
Mythri P Kc3198a52011-03-12 12:04:27 +05301113}
1114
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001115void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301116{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001117 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301118}