blob: 3b10e18efa22478cdeeb302e9fa847ce4733b128 [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;
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;
Mythri P Kc3198a52011-03-12 12:04:27 +053071} hdmi;
72
73/*
74 * Logic for the below structure :
75 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
76 * There is a correspondence between CEA/VESA timing and code, please
77 * refer to section 6.3 in HDMI 1.3 specification for timing code.
78 *
79 * In the below structure, cea_vesa_timings corresponds to all OMAP4
80 * supported CEA and VESA timing values.code_cea corresponds to the CEA
81 * code, It is used to get the timing from cea_vesa_timing array.Similarly
82 * with code_vesa. Code_index is used for back mapping, that is once EDID
83 * is read from the TV, EDID is parsed to find the timing values and then
84 * map it to corresponding CEA or VESA index.
85 */
86
Mythri P K46095b22012-01-06 17:52:09 +053087static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053088 {
89 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
90 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
91 false, },
92 { 1, HDMI_HDMI },
93 },
94 {
95 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
96 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
97 false, },
98 { 2, HDMI_HDMI },
99 },
100 {
101 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
102 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
103 false, },
104 { 4, HDMI_HDMI },
105 },
106 {
107 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
108 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
109 true, },
110 { 5, HDMI_HDMI },
111 },
112 {
113 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
114 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
115 true, },
116 { 6, HDMI_HDMI },
117 },
118 {
119 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
120 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
121 false, },
122 { 16, HDMI_HDMI },
123 },
124 {
125 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
126 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
127 false, },
128 { 17, HDMI_HDMI },
129 },
130 {
131 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
132 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
133 false, },
134 { 19, HDMI_HDMI },
135 },
136 {
137 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
138 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
139 true, },
140 { 20, HDMI_HDMI },
141 },
142 {
143 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
144 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
145 true, },
146 { 21, HDMI_HDMI },
147 },
148 {
149 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
150 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
151 false, },
152 { 29, HDMI_HDMI },
153 },
154 {
155 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
156 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
157 false, },
158 { 31, HDMI_HDMI },
159 },
160 {
161 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
162 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
163 false, },
164 { 32, HDMI_HDMI },
165 },
166 {
167 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
168 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
169 false, },
170 { 35, HDMI_HDMI },
171 },
172 {
173 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
174 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
175 false, },
176 { 37, HDMI_HDMI },
177 },
Mythri P K46095b22012-01-06 17:52:09 +0530178};
Archit Tanejacc937e52012-06-24 13:08:10 +0530179
Mythri P K46095b22012-01-06 17:52:09 +0530180static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530181/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530182 {
183 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
184 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
185 false, },
186 { 4, HDMI_DVI },
187 },
188 {
189 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
190 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
191 false, },
192 { 9, HDMI_DVI },
193 },
194 {
195 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
196 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
197 false, },
198 { 0xE, HDMI_DVI },
199 },
200 {
201 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
202 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
203 false, },
204 { 0x17, HDMI_DVI },
205 },
206 {
207 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
208 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
209 false, },
210 { 0x1C, HDMI_DVI },
211 },
212 {
213 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
214 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
215 false, },
216 { 0x27, HDMI_DVI },
217 },
218 {
219 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
220 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
221 false, },
222 { 0x20, HDMI_DVI },
223 },
224 {
225 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
226 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
227 false, },
228 { 0x23, HDMI_DVI },
229 },
230 {
231 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
232 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
233 false, },
234 { 0x10, HDMI_DVI },
235 },
236 {
237 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
238 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
239 false, },
240 { 0x2A, HDMI_DVI },
241 },
242 {
243 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
244 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
245 false, },
246 { 0x2F, HDMI_DVI },
247 },
248 {
249 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
250 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
251 false, },
252 { 0x3A, HDMI_DVI },
253 },
254 {
255 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
256 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
257 false, },
258 { 0x51, HDMI_DVI },
259 },
260 {
261 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
262 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
263 false, },
264 { 0x52, HDMI_DVI },
265 },
266 {
267 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
268 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
269 false, },
270 { 0x16, HDMI_DVI },
271 },
272 {
273 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
274 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
275 false, },
276 { 0x29, HDMI_DVI },
277 },
278 {
279 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
280 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
281 false, },
282 { 0x39, HDMI_DVI },
283 },
284 {
285 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
286 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
287 false, },
288 { 0x1B, HDMI_DVI },
289 },
290 {
291 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
292 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
293 false, },
294 { 0x55, HDMI_DVI },
295 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530296};
297
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300298static int hdmi_runtime_get(void)
299{
300 int r;
301
302 DSSDBG("hdmi_runtime_get\n");
303
304 r = pm_runtime_get_sync(&hdmi.pdev->dev);
305 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +0530306 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200307 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +0530308
309 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300310}
311
312static void hdmi_runtime_put(void)
313{
314 int r;
315
316 DSSDBG("hdmi_runtime_put\n");
317
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200318 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300319 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300320}
321
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200322static int __init hdmi_init_display(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530323{
Tomi Valkeinencca35012012-04-26 14:48:32 +0300324 int r;
325
326 struct gpio gpios[] = {
327 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
328 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
329 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
330 };
331
Mythri P Kc3198a52011-03-12 12:04:27 +0530332 DSSDBG("init_display\n");
333
Mythri P K60634a22011-09-08 19:06:26 +0530334 dss_init_hdmi_ip_ops(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300335
Tomi Valkeinen17486942012-08-15 15:55:04 +0300336 if (hdmi.vdda_hdmi_dac_reg == NULL) {
337 struct regulator *reg;
338
339 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
340
341 if (IS_ERR(reg)) {
342 DSSERR("can't get VDDA_HDMI_DAC regulator\n");
343 return PTR_ERR(reg);
344 }
345
346 hdmi.vdda_hdmi_dac_reg = reg;
347 }
348
Tomi Valkeinencca35012012-04-26 14:48:32 +0300349 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
350 if (r)
351 return r;
352
Mythri P Kc3198a52011-03-12 12:04:27 +0530353 return 0;
354}
355
Tomi Valkeinencca35012012-04-26 14:48:32 +0300356static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev)
357{
358 DSSDBG("uninit_display\n");
359
360 gpio_free(hdmi.ct_cp_hpd_gpio);
361 gpio_free(hdmi.ls_oe_gpio);
362 gpio_free(hdmi.hpd_gpio);
363}
364
Mythri P K46095b22012-01-06 17:52:09 +0530365static const struct hdmi_config *hdmi_find_timing(
366 const struct hdmi_config *timings_arr,
367 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530368{
Mythri P K46095b22012-01-06 17:52:09 +0530369 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530370
Mythri P K46095b22012-01-06 17:52:09 +0530371 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530372 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530373 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530374 }
Mythri P K46095b22012-01-06 17:52:09 +0530375 return NULL;
376}
377
378static const struct hdmi_config *hdmi_get_timings(void)
379{
380 const struct hdmi_config *arr;
381 int len;
382
Mythri P K9e4ed602012-01-06 17:52:10 +0530383 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530384 arr = vesa_timings;
385 len = ARRAY_SIZE(vesa_timings);
386 } else {
387 arr = cea_timings;
388 len = ARRAY_SIZE(cea_timings);
389 }
390
391 return hdmi_find_timing(arr, len);
392}
393
394static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530395 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530396{
397 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
398
399 if ((timing2->pixel_clock == timing1->pixel_clock) &&
400 (timing2->x_res == timing1->x_res) &&
401 (timing2->y_res == timing1->y_res)) {
402
403 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
404 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
405 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
406 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
407
408 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
409 "timing2_hsync = %d timing2_vsync = %d\n",
410 timing1_hsync, timing1_vsync,
411 timing2_hsync, timing2_vsync);
412
413 if ((timing1_hsync == timing2_hsync) &&
414 (timing1_vsync == timing2_vsync)) {
415 return true;
416 }
417 }
418 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530419}
420
421static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
422{
Mythri P K46095b22012-01-06 17:52:09 +0530423 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530424 struct hdmi_cm cm = {-1};
425 DSSDBG("hdmi_get_code\n");
426
Mythri P K46095b22012-01-06 17:52:09 +0530427 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
428 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
429 cm = cea_timings[i].cm;
430 goto end;
431 }
432 }
433 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
434 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
435 cm = vesa_timings[i].cm;
436 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530437 }
438 }
439
Mythri P K46095b22012-01-06 17:52:09 +0530440end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530441
Mythri P Kc3198a52011-03-12 12:04:27 +0530442}
443
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530444unsigned long hdmi_get_pixel_clock(void)
445{
446 /* HDMI Pixel Clock in Mhz */
Mythri P Ka05ce782012-01-06 17:52:08 +0530447 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530448}
449
Archit Taneja6cb07b22011-04-12 13:52:25 +0530450static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
451 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530452{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530453 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530454 u32 mf;
455
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300456 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530457 /*
458 * Input clock is predivided by N + 1
459 * out put of which is reference clk
460 */
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300461 if (dssdev->clocks.hdmi.regn == 0)
462 pi->regn = HDMI_DEFAULT_REGN;
463 else
464 pi->regn = dssdev->clocks.hdmi.regn;
465
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300466 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530467
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300468 if (dssdev->clocks.hdmi.regm2 == 0)
469 pi->regm2 = HDMI_DEFAULT_REGM2;
470 else
471 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530472
473 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530474 * multiplier is pixel_clk/ref_clk
475 * Multiplying by 100 to avoid fractional part removal
476 */
477 pi->regm = phy * pi->regm2 / refclk;
478
479 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530480 * fractional multiplier is remainder of the difference between
481 * multiplier and actual phy(required pixel clock thus should be
482 * multiplied by 2^18(262144) divided by the reference clock
483 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530484 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
485 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530486
487 /*
488 * Dcofreq should be set to 1 if required pixel clock
489 * is greater than 1000MHz
490 */
491 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300492 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530493
Mythri P K7b27da52011-09-08 19:06:19 +0530494 /* Set the reference clock to sysclk reference */
495 pi->refsel = HDMI_REFSEL_SYSCLK;
496
Mythri P Kc3198a52011-03-12 12:04:27 +0530497 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
498 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
499}
500
Mythri P Kc3198a52011-03-12 12:04:27 +0530501static int hdmi_power_on(struct omap_dss_device *dssdev)
502{
Mythri P K46095b22012-01-06 17:52:09 +0530503 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530504 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530505 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +0530506
Tomi Valkeinencca35012012-04-26 14:48:32 +0300507 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
508 gpio_set_value(hdmi.ls_oe_gpio, 1);
509
Tomi Valkeinena84b20654b2012-04-26 14:58:41 +0300510 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
511 udelay(300);
512
Tomi Valkeinen17486942012-08-15 15:55:04 +0300513 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
514 if (r)
515 goto err_vdac_enable;
516
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300517 r = hdmi_runtime_get();
518 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300519 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530520
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200521 dss_mgr_disable(dssdev->manager);
Mythri P Kc3198a52011-03-12 12:04:27 +0530522
Archit Taneja78493982012-08-08 16:50:42 +0530523 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530524
Archit Taneja78493982012-08-08 16:50:42 +0530525 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 +0530526
Mythri P Kc3198a52011-03-12 12:04:27 +0530527 phy = p->pixel_clock;
528
Mythri P K7b27da52011-09-08 19:06:19 +0530529 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530530
Ricardo Neric0456be2012-04-27 13:48:45 -0500531 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530532
Mythri P K95a8aeb2011-09-08 19:06:18 +0530533 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530534 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530535 if (r) {
536 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300537 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530538 }
539
Mythri P K60634a22011-09-08 19:06:26 +0530540 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530541 if (r) {
542 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500543 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530544 }
545
Mythri P K60634a22011-09-08 19:06:26 +0530546 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530547
548 /* Make selection of HDMI in DSS */
549 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
550
551 /* Select the dispc clock source as PRCM clock, to ensure that it is not
552 * DSI PLL source as the clock selected by DSI PLL might not be
553 * sufficient for the resolution selected / that can be changed
554 * dynamically by user. This can be moved to single location , say
555 * Boardfile.
556 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530557 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +0530558
559 /* bypass TV gamma table */
560 dispc_enable_gamma_table(0);
561
562 /* tv size */
Archit Taneja78493982012-08-08 16:50:42 +0530563 dss_mgr_set_timings(dssdev->manager, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530564
Ricardo Neric0456be2012-04-27 13:48:45 -0500565 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
566 if (r)
567 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530568
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200569 r = dss_mgr_enable(dssdev->manager);
570 if (r)
571 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300572
Mythri P Kc3198a52011-03-12 12:04:27 +0530573 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200574
575err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500576 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
577err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200578 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500579err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200580 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300581err_pll_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300582 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300583err_runtime_get:
Tomi Valkeinen17486942012-08-15 15:55:04 +0300584 regulator_disable(hdmi.vdda_hdmi_dac_reg);
585err_vdac_enable:
Tomi Valkeinencca35012012-04-26 14:48:32 +0300586 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
587 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530588 return -EIO;
589}
590
591static void hdmi_power_off(struct omap_dss_device *dssdev)
592{
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200593 dss_mgr_disable(dssdev->manager);
Mythri P Kc3198a52011-03-12 12:04:27 +0530594
Ricardo Neric0456be2012-04-27 13:48:45 -0500595 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P K60634a22011-09-08 19:06:26 +0530596 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
597 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300598 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300599
Tomi Valkeinen17486942012-08-15 15:55:04 +0300600 regulator_disable(hdmi.vdda_hdmi_dac_reg);
601
Tomi Valkeinencca35012012-04-26 14:48:32 +0300602 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
603 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530604}
605
606int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
607 struct omap_video_timings *timings)
608{
609 struct hdmi_cm cm;
610
611 cm = hdmi_get_code(timings);
612 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530613 return -EINVAL;
614 }
615
616 return 0;
617
618}
619
Archit Taneja78493982012-08-08 16:50:42 +0530620void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
621 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530622{
623 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530624 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530625
Archit Tanejaed1aa902012-08-15 00:40:31 +0530626 mutex_lock(&hdmi.lock);
627
Archit Taneja78493982012-08-08 16:50:42 +0530628 cm = hdmi_get_code(timings);
629 hdmi.ip_data.cfg.cm = cm;
630
631 t = hdmi_get_timings();
632 if (t != NULL)
633 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300634
Archit Tanejaed1aa902012-08-15 00:40:31 +0530635 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530636}
637
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200638static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530639{
640 mutex_lock(&hdmi.lock);
641
642 if (hdmi_runtime_get())
643 return;
644
645 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
646 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
647 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
648 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
649
650 hdmi_runtime_put();
651 mutex_unlock(&hdmi.lock);
652}
653
Tomi Valkeinen47024562011-08-25 17:12:56 +0300654int omapdss_hdmi_read_edid(u8 *buf, int len)
655{
656 int r;
657
658 mutex_lock(&hdmi.lock);
659
660 r = hdmi_runtime_get();
661 BUG_ON(r);
662
663 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
664
665 hdmi_runtime_put();
666 mutex_unlock(&hdmi.lock);
667
668 return r;
669}
670
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300671bool omapdss_hdmi_detect(void)
672{
673 int r;
674
675 mutex_lock(&hdmi.lock);
676
677 r = hdmi_runtime_get();
678 BUG_ON(r);
679
680 r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
681
682 hdmi_runtime_put();
683 mutex_unlock(&hdmi.lock);
684
685 return r == 1;
686}
687
Mythri P Kc3198a52011-03-12 12:04:27 +0530688int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
689{
690 int r = 0;
691
692 DSSDBG("ENTER hdmi_display_enable\n");
693
694 mutex_lock(&hdmi.lock);
695
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300696 if (dssdev->manager == NULL) {
697 DSSERR("failed to enable display: no manager\n");
698 r = -ENODEV;
699 goto err0;
700 }
701
Tomi Valkeinencca35012012-04-26 14:48:32 +0300702 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
Tomi Valkeinenc49d0052012-01-17 11:09:57 +0200703
Mythri P Kc3198a52011-03-12 12:04:27 +0530704 r = omap_dss_start_device(dssdev);
705 if (r) {
706 DSSERR("failed to start device\n");
707 goto err0;
708 }
709
Mythri P Kc3198a52011-03-12 12:04:27 +0530710 r = hdmi_power_on(dssdev);
711 if (r) {
712 DSSERR("failed to power on device\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300713 goto err1;
Mythri P Kc3198a52011-03-12 12:04:27 +0530714 }
715
716 mutex_unlock(&hdmi.lock);
717 return 0;
718
Mythri P Kc3198a52011-03-12 12:04:27 +0530719err1:
720 omap_dss_stop_device(dssdev);
721err0:
722 mutex_unlock(&hdmi.lock);
723 return r;
724}
725
726void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
727{
728 DSSDBG("Enter hdmi_display_disable\n");
729
730 mutex_lock(&hdmi.lock);
731
732 hdmi_power_off(dssdev);
733
Mythri P Kc3198a52011-03-12 12:04:27 +0530734 omap_dss_stop_device(dssdev);
735
736 mutex_unlock(&hdmi.lock);
737}
738
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300739static int hdmi_get_clocks(struct platform_device *pdev)
740{
741 struct clk *clk;
742
743 clk = clk_get(&pdev->dev, "sys_clk");
744 if (IS_ERR(clk)) {
745 DSSERR("can't get sys_clk\n");
746 return PTR_ERR(clk);
747 }
748
749 hdmi.sys_clk = clk;
750
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300751 return 0;
752}
753
754static void hdmi_put_clocks(void)
755{
756 if (hdmi.sys_clk)
757 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300758}
759
Ricardo Neri35547622012-03-20 21:02:01 -0600760#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
761int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
762{
763 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600764 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600765 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
766
767 if (n == NULL || cts == NULL)
768 return -EINVAL;
769
770 /* TODO: When implemented, query deep color mode here. */
771 deep_color = 100;
772
Ricardo Neri25a65352012-03-23 15:49:02 -0600773 /*
774 * When using deep color, the default N value (as in the HDMI
775 * specification) yields to an non-integer CTS. Hence, we
776 * modify it while keeping the restrictions described in
777 * section 7.2.1 of the HDMI 1.4a specification.
778 */
Ricardo Neri35547622012-03-20 21:02:01 -0600779 switch (sample_freq) {
780 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600781 case 48000:
782 case 96000:
783 case 192000:
784 if (deep_color == 125)
785 if (pclk == 27027 || pclk == 74250)
786 deep_color_correct = true;
787 if (deep_color == 150)
788 if (pclk == 27027)
789 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600790 break;
791 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600792 case 88200:
793 case 176400:
794 if (deep_color == 125)
795 if (pclk == 27027)
796 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600797 break;
798 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600799 return -EINVAL;
800 }
801
Ricardo Neri25a65352012-03-23 15:49:02 -0600802 if (deep_color_correct) {
803 switch (sample_freq) {
804 case 32000:
805 *n = 8192;
806 break;
807 case 44100:
808 *n = 12544;
809 break;
810 case 48000:
811 *n = 8192;
812 break;
813 case 88200:
814 *n = 25088;
815 break;
816 case 96000:
817 *n = 16384;
818 break;
819 case 176400:
820 *n = 50176;
821 break;
822 case 192000:
823 *n = 32768;
824 break;
825 default:
826 return -EINVAL;
827 }
828 } else {
829 switch (sample_freq) {
830 case 32000:
831 *n = 4096;
832 break;
833 case 44100:
834 *n = 6272;
835 break;
836 case 48000:
837 *n = 6144;
838 break;
839 case 88200:
840 *n = 12544;
841 break;
842 case 96000:
843 *n = 12288;
844 break;
845 case 176400:
846 *n = 25088;
847 break;
848 case 192000:
849 *n = 24576;
850 break;
851 default:
852 return -EINVAL;
853 }
854 }
Ricardo Neri35547622012-03-20 21:02:01 -0600855 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
856 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
857
858 return 0;
859}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500860
861int hdmi_audio_enable(void)
862{
863 DSSDBG("audio_enable\n");
864
865 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
866}
867
868void hdmi_audio_disable(void)
869{
870 DSSDBG("audio_disable\n");
871
872 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
873}
874
875int hdmi_audio_start(void)
876{
877 DSSDBG("audio_start\n");
878
879 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
880}
881
882void hdmi_audio_stop(void)
883{
884 DSSDBG("audio_stop\n");
885
886 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
887}
888
889bool hdmi_mode_has_audio(void)
890{
891 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
892 return true;
893 else
894 return false;
895}
896
897int hdmi_audio_config(struct omap_dss_audio *audio)
898{
899 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
900}
901
Ricardo Neri35547622012-03-20 21:02:01 -0600902#endif
903
Tomi Valkeinen15216532012-09-06 14:29:31 +0300904static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300905{
906 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300907 const char *def_disp_name = dss_get_default_display_name();
908 struct omap_dss_device *def_dssdev;
909 int i;
910
911 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300912
913 for (i = 0; i < pdata->num_devices; ++i) {
914 struct omap_dss_device *dssdev = pdata->devices[i];
915
916 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
917 continue;
918
Tomi Valkeinen15216532012-09-06 14:29:31 +0300919 if (def_dssdev == NULL)
920 def_dssdev = dssdev;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300921
Tomi Valkeinen15216532012-09-06 14:29:31 +0300922 if (def_disp_name != NULL &&
923 strcmp(dssdev->name, def_disp_name) == 0) {
924 def_dssdev = dssdev;
925 break;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300926 }
Tomi Valkeinen15216532012-09-06 14:29:31 +0300927 }
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300928
Tomi Valkeinen15216532012-09-06 14:29:31 +0300929 return def_dssdev;
930}
931
932static void __init hdmi_probe_pdata(struct platform_device *pdev)
933{
934 struct omap_dss_device *dssdev;
935 struct omap_dss_hdmi_data *priv;
936 int r;
937
938 dssdev = hdmi_find_dssdev(pdev);
939
940 if (!dssdev)
941 return;
942
943 priv = dssdev->data;
944
945 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
946 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
947 hdmi.hpd_gpio = priv->hpd_gpio;
948
Tomi Valkeinenbcb226a2012-09-07 15:21:36 +0300949 dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
950
Tomi Valkeinen15216532012-09-06 14:29:31 +0300951 r = hdmi_init_display(dssdev);
952 if (r) {
953 DSSERR("device %s init failed: %d\n", dssdev->name, r);
954 return;
955 }
956
957 r = omap_dss_register_device(dssdev, &pdev->dev);
958 if (r) {
959 DSSERR("device %s register failed: %d\n", dssdev->name, r);
960 return;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300961 }
962}
963
Mythri P Kc3198a52011-03-12 12:04:27 +0530964/* HDMI HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200965static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530966{
967 struct resource *hdmi_mem;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300968 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530969
Mythri P Kc3198a52011-03-12 12:04:27 +0530970 hdmi.pdev = pdev;
971
972 mutex_init(&hdmi.lock);
973
974 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
975 if (!hdmi_mem) {
976 DSSERR("can't get IORESOURCE_MEM HDMI\n");
977 return -EINVAL;
978 }
979
980 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530981 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
982 resource_size(hdmi_mem));
983 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530984 DSSERR("can't ioremap WP\n");
985 return -ENOMEM;
986 }
987
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300988 r = hdmi_get_clocks(pdev);
989 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530990 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300991 return r;
992 }
993
994 pm_runtime_enable(&pdev->dev);
995
Mythri P K95a8aeb2011-09-08 19:06:18 +0530996 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
997 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
998 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
999 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +05301000
Jassi Brar3a5383a2012-06-27 19:34:56 +05301001 mutex_init(&hdmi.ip_data.lock);
Mythri P K95a8aeb2011-09-08 19:06:18 +05301002
Mythri P Kc3198a52011-03-12 12:04:27 +05301003 hdmi_panel_init();
1004
Tomi Valkeinene40402c2012-03-02 18:01:07 +02001005 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
1006
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03001007 hdmi_probe_pdata(pdev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001008
Mythri P Kc3198a52011-03-12 12:04:27 +05301009 return 0;
1010}
1011
Tomi Valkeinencca35012012-04-26 14:48:32 +03001012static int __exit hdmi_remove_child(struct device *dev, void *data)
1013{
1014 struct omap_dss_device *dssdev = to_dss_device(dev);
1015 hdmi_uninit_display(dssdev);
1016 return 0;
1017}
1018
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001019static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +05301020{
Tomi Valkeinencca35012012-04-26 14:48:32 +03001021 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
1022
Tomi Valkeinen35deca32012-03-01 15:45:53 +02001023 omap_dss_unregister_child_devices(&pdev->dev);
1024
Mythri P Kc3198a52011-03-12 12:04:27 +05301025 hdmi_panel_exit();
1026
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001027 pm_runtime_disable(&pdev->dev);
1028
1029 hdmi_put_clocks();
1030
Mythri P K95a8aeb2011-09-08 19:06:18 +05301031 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +05301032
1033 return 0;
1034}
1035
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001036static int hdmi_runtime_suspend(struct device *dev)
1037{
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301038 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001039
1040 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001041
1042 return 0;
1043}
1044
1045static int hdmi_runtime_resume(struct device *dev)
1046{
1047 int r;
1048
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001049 r = dispc_runtime_get();
1050 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001051 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001052
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301053 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001054
1055 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001056}
1057
1058static const struct dev_pm_ops hdmi_pm_ops = {
1059 .runtime_suspend = hdmi_runtime_suspend,
1060 .runtime_resume = hdmi_runtime_resume,
1061};
1062
Mythri P Kc3198a52011-03-12 12:04:27 +05301063static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001064 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301065 .driver = {
1066 .name = "omapdss_hdmi",
1067 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001068 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301069 },
1070};
1071
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001072int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301073{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02001074 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
Mythri P Kc3198a52011-03-12 12:04:27 +05301075}
1076
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001077void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301078{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001079 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301080}