blob: 96a6e298873ba195affb5b344eb0ee1007d981de [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 Valkeinena0b38cc2011-05-11 14:05:07 +030036#include <video/omapdss.h>
Mythri P Kc3198a52011-03-12 12:04:27 +053037
Mythri P K94c52982011-09-08 19:06:21 +053038#include "ti_hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053039#include "dss.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050040#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053041
Mythri P K95a8aeb2011-09-08 19:06:18 +053042#define HDMI_WP 0x0
43#define HDMI_CORE_SYS 0x400
44#define HDMI_CORE_AV 0x900
45#define HDMI_PLLCTRL 0x200
46#define HDMI_PHY 0x300
47
Mythri P K7c1f1ec2011-09-08 19:06:22 +053048/* HDMI EDID Length move this */
49#define HDMI_EDID_MAX_LENGTH 256
50#define EDID_TIMING_DESCRIPTOR_SIZE 0x12
51#define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
52#define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
53#define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
54#define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
55
Tomi Valkeinenb44e4582011-08-22 13:16:24 +030056#define HDMI_DEFAULT_REGN 16
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +030057#define HDMI_DEFAULT_REGM2 1
58
Mythri P Kc3198a52011-03-12 12:04:27 +053059static struct {
60 struct mutex lock;
Mythri P Kc3198a52011-03-12 12:04:27 +053061 struct platform_device *pdev;
Mythri P K95a8aeb2011-09-08 19:06:18 +053062 struct hdmi_ip_data ip_data;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030063
64 struct clk *sys_clk;
Tomi Valkeinencca35012012-04-26 14:48:32 +030065
66 int ct_cp_hpd_gpio;
67 int ls_oe_gpio;
68 int hpd_gpio;
Mythri P Kc3198a52011-03-12 12:04:27 +053069} hdmi;
70
71/*
72 * Logic for the below structure :
73 * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
74 * There is a correspondence between CEA/VESA timing and code, please
75 * refer to section 6.3 in HDMI 1.3 specification for timing code.
76 *
77 * In the below structure, cea_vesa_timings corresponds to all OMAP4
78 * supported CEA and VESA timing values.code_cea corresponds to the CEA
79 * code, It is used to get the timing from cea_vesa_timing array.Similarly
80 * with code_vesa. Code_index is used for back mapping, that is once EDID
81 * is read from the TV, EDID is parsed to find the timing values and then
82 * map it to corresponding CEA or VESA index.
83 */
84
Mythri P K46095b22012-01-06 17:52:09 +053085static const struct hdmi_config cea_timings[] = {
Archit Tanejacc937e52012-06-24 13:08:10 +053086 {
87 { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
88 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
89 false, },
90 { 1, HDMI_HDMI },
91 },
92 {
93 { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
94 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
95 false, },
96 { 2, HDMI_HDMI },
97 },
98 {
99 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
100 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
101 false, },
102 { 4, HDMI_HDMI },
103 },
104 {
105 { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
106 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
107 true, },
108 { 5, HDMI_HDMI },
109 },
110 {
111 { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
112 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
113 true, },
114 { 6, HDMI_HDMI },
115 },
116 {
117 { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
118 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
119 false, },
120 { 16, HDMI_HDMI },
121 },
122 {
123 { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
124 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
125 false, },
126 { 17, HDMI_HDMI },
127 },
128 {
129 { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
130 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
131 false, },
132 { 19, HDMI_HDMI },
133 },
134 {
135 { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
136 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
137 true, },
138 { 20, HDMI_HDMI },
139 },
140 {
141 { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
142 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
143 true, },
144 { 21, HDMI_HDMI },
145 },
146 {
147 { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
148 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
149 false, },
150 { 29, HDMI_HDMI },
151 },
152 {
153 { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
154 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
155 false, },
156 { 31, HDMI_HDMI },
157 },
158 {
159 { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
160 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
161 false, },
162 { 32, HDMI_HDMI },
163 },
164 {
165 { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
166 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
167 false, },
168 { 35, HDMI_HDMI },
169 },
170 {
171 { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
172 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
173 false, },
174 { 37, HDMI_HDMI },
175 },
Mythri P K46095b22012-01-06 17:52:09 +0530176};
Archit Tanejacc937e52012-06-24 13:08:10 +0530177
Mythri P K46095b22012-01-06 17:52:09 +0530178static const struct hdmi_config vesa_timings[] = {
Mythri P Ka05ce782012-01-06 17:52:08 +0530179/* VESA From Here */
Archit Tanejacc937e52012-06-24 13:08:10 +0530180 {
181 { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
182 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
183 false, },
184 { 4, HDMI_DVI },
185 },
186 {
187 { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
188 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
189 false, },
190 { 9, HDMI_DVI },
191 },
192 {
193 { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
194 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
195 false, },
196 { 0xE, HDMI_DVI },
197 },
198 {
199 { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
200 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
201 false, },
202 { 0x17, HDMI_DVI },
203 },
204 {
205 { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
206 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
207 false, },
208 { 0x1C, HDMI_DVI },
209 },
210 {
211 { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
212 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
213 false, },
214 { 0x27, HDMI_DVI },
215 },
216 {
217 { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
218 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
219 false, },
220 { 0x20, HDMI_DVI },
221 },
222 {
223 { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
224 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
225 false, },
226 { 0x23, HDMI_DVI },
227 },
228 {
229 { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
230 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
231 false, },
232 { 0x10, HDMI_DVI },
233 },
234 {
235 { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
236 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
237 false, },
238 { 0x2A, HDMI_DVI },
239 },
240 {
241 { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
242 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
243 false, },
244 { 0x2F, HDMI_DVI },
245 },
246 {
247 { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
248 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
249 false, },
250 { 0x3A, HDMI_DVI },
251 },
252 {
253 { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
254 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
255 false, },
256 { 0x51, HDMI_DVI },
257 },
258 {
259 { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
260 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
261 false, },
262 { 0x52, HDMI_DVI },
263 },
264 {
265 { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
266 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
267 false, },
268 { 0x16, HDMI_DVI },
269 },
270 {
271 { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
272 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
273 false, },
274 { 0x29, HDMI_DVI },
275 },
276 {
277 { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
278 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
279 false, },
280 { 0x39, HDMI_DVI },
281 },
282 {
283 { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
284 OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
285 false, },
286 { 0x1B, HDMI_DVI },
287 },
288 {
289 { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
290 OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
291 false, },
292 { 0x55, HDMI_DVI },
293 },
Mythri P Kc3198a52011-03-12 12:04:27 +0530294};
295
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300296static int hdmi_runtime_get(void)
297{
298 int r;
299
300 DSSDBG("hdmi_runtime_get\n");
301
302 r = pm_runtime_get_sync(&hdmi.pdev->dev);
303 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +0530304 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200305 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +0530306
307 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300308}
309
310static void hdmi_runtime_put(void)
311{
312 int r;
313
314 DSSDBG("hdmi_runtime_put\n");
315
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200316 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300317 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300318}
319
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200320static int __init hdmi_init_display(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530321{
Tomi Valkeinencca35012012-04-26 14:48:32 +0300322 int r;
323
324 struct gpio gpios[] = {
325 { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
326 { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
327 { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
328 };
329
Mythri P Kc3198a52011-03-12 12:04:27 +0530330 DSSDBG("init_display\n");
331
Mythri P K60634a22011-09-08 19:06:26 +0530332 dss_init_hdmi_ip_ops(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300333
334 r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
335 if (r)
336 return r;
337
Mythri P Kc3198a52011-03-12 12:04:27 +0530338 return 0;
339}
340
Tomi Valkeinencca35012012-04-26 14:48:32 +0300341static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev)
342{
343 DSSDBG("uninit_display\n");
344
345 gpio_free(hdmi.ct_cp_hpd_gpio);
346 gpio_free(hdmi.ls_oe_gpio);
347 gpio_free(hdmi.hpd_gpio);
348}
349
Mythri P K46095b22012-01-06 17:52:09 +0530350static const struct hdmi_config *hdmi_find_timing(
351 const struct hdmi_config *timings_arr,
352 int len)
Mythri P Kc3198a52011-03-12 12:04:27 +0530353{
Mythri P K46095b22012-01-06 17:52:09 +0530354 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530355
Mythri P K46095b22012-01-06 17:52:09 +0530356 for (i = 0; i < len; i++) {
Mythri P K9e4ed602012-01-06 17:52:10 +0530357 if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
Mythri P K46095b22012-01-06 17:52:09 +0530358 return &timings_arr[i];
Mythri P Kc3198a52011-03-12 12:04:27 +0530359 }
Mythri P K46095b22012-01-06 17:52:09 +0530360 return NULL;
361}
362
363static const struct hdmi_config *hdmi_get_timings(void)
364{
365 const struct hdmi_config *arr;
366 int len;
367
Mythri P K9e4ed602012-01-06 17:52:10 +0530368 if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
Mythri P K46095b22012-01-06 17:52:09 +0530369 arr = vesa_timings;
370 len = ARRAY_SIZE(vesa_timings);
371 } else {
372 arr = cea_timings;
373 len = ARRAY_SIZE(cea_timings);
374 }
375
376 return hdmi_find_timing(arr, len);
377}
378
379static bool hdmi_timings_compare(struct omap_video_timings *timing1,
Archit Tanejacc937e52012-06-24 13:08:10 +0530380 const struct omap_video_timings *timing2)
Mythri P K46095b22012-01-06 17:52:09 +0530381{
382 int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
383
384 if ((timing2->pixel_clock == timing1->pixel_clock) &&
385 (timing2->x_res == timing1->x_res) &&
386 (timing2->y_res == timing1->y_res)) {
387
388 timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
389 timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
390 timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
391 timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
392
393 DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
394 "timing2_hsync = %d timing2_vsync = %d\n",
395 timing1_hsync, timing1_vsync,
396 timing2_hsync, timing2_vsync);
397
398 if ((timing1_hsync == timing2_hsync) &&
399 (timing1_vsync == timing2_vsync)) {
400 return true;
401 }
402 }
403 return false;
Mythri P Kc3198a52011-03-12 12:04:27 +0530404}
405
406static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
407{
Mythri P K46095b22012-01-06 17:52:09 +0530408 int i;
Mythri P Kc3198a52011-03-12 12:04:27 +0530409 struct hdmi_cm cm = {-1};
410 DSSDBG("hdmi_get_code\n");
411
Mythri P K46095b22012-01-06 17:52:09 +0530412 for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
413 if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
414 cm = cea_timings[i].cm;
415 goto end;
416 }
417 }
418 for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
419 if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
420 cm = vesa_timings[i].cm;
421 goto end;
Mythri P Kc3198a52011-03-12 12:04:27 +0530422 }
423 }
424
Mythri P K46095b22012-01-06 17:52:09 +0530425end: return cm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530426
Mythri P Kc3198a52011-03-12 12:04:27 +0530427}
428
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530429unsigned long hdmi_get_pixel_clock(void)
430{
431 /* HDMI Pixel Clock in Mhz */
Mythri P Ka05ce782012-01-06 17:52:08 +0530432 return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
Archit Tanejac3dc6a72011-09-13 18:28:41 +0530433}
434
Archit Taneja6cb07b22011-04-12 13:52:25 +0530435static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
436 struct hdmi_pll_info *pi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530437{
Archit Taneja6cb07b22011-04-12 13:52:25 +0530438 unsigned long clkin, refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530439 u32 mf;
440
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300441 clkin = clk_get_rate(hdmi.sys_clk) / 10000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530442 /*
443 * Input clock is predivided by N + 1
444 * out put of which is reference clk
445 */
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300446 if (dssdev->clocks.hdmi.regn == 0)
447 pi->regn = HDMI_DEFAULT_REGN;
448 else
449 pi->regn = dssdev->clocks.hdmi.regn;
450
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300451 refclk = clkin / pi->regn;
Mythri P Kc3198a52011-03-12 12:04:27 +0530452
Tomi Valkeinen8d88767a2011-08-22 13:02:52 +0300453 if (dssdev->clocks.hdmi.regm2 == 0)
454 pi->regm2 = HDMI_DEFAULT_REGM2;
455 else
456 pi->regm2 = dssdev->clocks.hdmi.regm2;
Mythri P Kc3198a52011-03-12 12:04:27 +0530457
458 /*
Mythri P Kdd2116a2012-02-21 12:10:58 +0530459 * multiplier is pixel_clk/ref_clk
460 * Multiplying by 100 to avoid fractional part removal
461 */
462 pi->regm = phy * pi->regm2 / refclk;
463
464 /*
Mythri P Kc3198a52011-03-12 12:04:27 +0530465 * fractional multiplier is remainder of the difference between
466 * multiplier and actual phy(required pixel clock thus should be
467 * multiplied by 2^18(262144) divided by the reference clock
468 */
Mythri P Kdd2116a2012-02-21 12:10:58 +0530469 mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
470 pi->regmf = pi->regm2 * mf / refclk;
Mythri P Kc3198a52011-03-12 12:04:27 +0530471
472 /*
473 * Dcofreq should be set to 1 if required pixel clock
474 * is greater than 1000MHz
475 */
476 pi->dcofreq = phy > 1000 * 100;
Tomi Valkeinenb44e4582011-08-22 13:16:24 +0300477 pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
Mythri P Kc3198a52011-03-12 12:04:27 +0530478
Mythri P K7b27da52011-09-08 19:06:19 +0530479 /* Set the reference clock to sysclk reference */
480 pi->refsel = HDMI_REFSEL_SYSCLK;
481
Mythri P Kc3198a52011-03-12 12:04:27 +0530482 DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
483 DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
484}
485
Mythri P Kc3198a52011-03-12 12:04:27 +0530486static int hdmi_power_on(struct omap_dss_device *dssdev)
487{
Mythri P K46095b22012-01-06 17:52:09 +0530488 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530489 struct omap_video_timings *p;
Archit Taneja6cb07b22011-04-12 13:52:25 +0530490 unsigned long phy;
Mythri P Kc3198a52011-03-12 12:04:27 +0530491
Tomi Valkeinencca35012012-04-26 14:48:32 +0300492 gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
493 gpio_set_value(hdmi.ls_oe_gpio, 1);
494
Tomi Valkeinena84b20654b2012-04-26 14:58:41 +0300495 /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
496 udelay(300);
497
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300498 r = hdmi_runtime_get();
499 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300500 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530501
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200502 dss_mgr_disable(dssdev->manager);
Mythri P Kc3198a52011-03-12 12:04:27 +0530503
Archit Taneja78493982012-08-08 16:50:42 +0530504 p = &hdmi.ip_data.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530505
Archit Taneja78493982012-08-08 16:50:42 +0530506 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 +0530507
Mythri P Kc3198a52011-03-12 12:04:27 +0530508 phy = p->pixel_clock;
509
Mythri P K7b27da52011-09-08 19:06:19 +0530510 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530511
Ricardo Neric0456be2012-04-27 13:48:45 -0500512 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530513
Mythri P K95a8aeb2011-09-08 19:06:18 +0530514 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Mythri P K60634a22011-09-08 19:06:26 +0530515 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530516 if (r) {
517 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300518 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530519 }
520
Mythri P K60634a22011-09-08 19:06:26 +0530521 r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530522 if (r) {
523 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500524 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530525 }
526
Mythri P K60634a22011-09-08 19:06:26 +0530527 hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
Mythri P Kc3198a52011-03-12 12:04:27 +0530528
529 /* Make selection of HDMI in DSS */
530 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
531
532 /* Select the dispc clock source as PRCM clock, to ensure that it is not
533 * DSI PLL source as the clock selected by DSI PLL might not be
534 * sufficient for the resolution selected / that can be changed
535 * dynamically by user. This can be moved to single location , say
536 * Boardfile.
537 */
Archit Taneja6cb07b22011-04-12 13:52:25 +0530538 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Mythri P Kc3198a52011-03-12 12:04:27 +0530539
540 /* bypass TV gamma table */
541 dispc_enable_gamma_table(0);
542
543 /* tv size */
Archit Taneja78493982012-08-08 16:50:42 +0530544 dss_mgr_set_timings(dssdev->manager, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530545
Ricardo Neric0456be2012-04-27 13:48:45 -0500546 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
547 if (r)
548 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530549
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200550 r = dss_mgr_enable(dssdev->manager);
551 if (r)
552 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300553
Mythri P Kc3198a52011-03-12 12:04:27 +0530554 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200555
556err_mgr_enable:
Ricardo Neric0456be2012-04-27 13:48:45 -0500557 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
558err_vid_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200559 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500560err_phy_enable:
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200561 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300562err_pll_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300563 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300564err_runtime_get:
565 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
566 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530567 return -EIO;
568}
569
570static void hdmi_power_off(struct omap_dss_device *dssdev)
571{
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200572 dss_mgr_disable(dssdev->manager);
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 K60634a22011-09-08 19:06:26 +0530575 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
576 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300577 hdmi_runtime_put();
Tomi Valkeinencca35012012-04-26 14:48:32 +0300578
579 gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
580 gpio_set_value(hdmi.ls_oe_gpio, 0);
Mythri P Kc3198a52011-03-12 12:04:27 +0530581}
582
583int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
584 struct omap_video_timings *timings)
585{
586 struct hdmi_cm cm;
587
588 cm = hdmi_get_code(timings);
589 if (cm.code == -1) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530590 return -EINVAL;
591 }
592
593 return 0;
594
595}
596
Archit Taneja78493982012-08-08 16:50:42 +0530597void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
598 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530599{
600 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530601 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530602
Archit Tanejaed1aa902012-08-15 00:40:31 +0530603 mutex_lock(&hdmi.lock);
604
Archit Taneja78493982012-08-08 16:50:42 +0530605 cm = hdmi_get_code(timings);
606 hdmi.ip_data.cfg.cm = cm;
607
608 t = hdmi_get_timings();
609 if (t != NULL)
610 hdmi.ip_data.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300611
612 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
613 int r;
614
615 hdmi_power_off(dssdev);
616
617 r = hdmi_power_on(dssdev);
618 if (r)
619 DSSERR("failed to power on device\n");
Archit Tanejafcc36612012-05-03 20:03:11 +0530620 } else {
Archit Taneja78493982012-08-08 16:50:42 +0530621 dss_mgr_set_timings(dssdev->manager, &t->timings);
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300622 }
Archit Tanejaed1aa902012-08-15 00:40:31 +0530623
624 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530625}
626
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200627static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530628{
629 mutex_lock(&hdmi.lock);
630
631 if (hdmi_runtime_get())
632 return;
633
634 hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
635 hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
636 hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
637 hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
638
639 hdmi_runtime_put();
640 mutex_unlock(&hdmi.lock);
641}
642
Tomi Valkeinen47024562011-08-25 17:12:56 +0300643int omapdss_hdmi_read_edid(u8 *buf, int len)
644{
645 int r;
646
647 mutex_lock(&hdmi.lock);
648
649 r = hdmi_runtime_get();
650 BUG_ON(r);
651
652 r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
653
654 hdmi_runtime_put();
655 mutex_unlock(&hdmi.lock);
656
657 return r;
658}
659
Tomi Valkeinen759593f2011-08-29 18:10:20 +0300660bool omapdss_hdmi_detect(void)
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->detect(&hdmi.ip_data);
670
671 hdmi_runtime_put();
672 mutex_unlock(&hdmi.lock);
673
674 return r == 1;
675}
676
Mythri P Kc3198a52011-03-12 12:04:27 +0530677int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
678{
679 int r = 0;
680
681 DSSDBG("ENTER hdmi_display_enable\n");
682
683 mutex_lock(&hdmi.lock);
684
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300685 if (dssdev->manager == NULL) {
686 DSSERR("failed to enable display: no manager\n");
687 r = -ENODEV;
688 goto err0;
689 }
690
Tomi Valkeinencca35012012-04-26 14:48:32 +0300691 hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
Tomi Valkeinenc49d0052012-01-17 11:09:57 +0200692
Mythri P Kc3198a52011-03-12 12:04:27 +0530693 r = omap_dss_start_device(dssdev);
694 if (r) {
695 DSSERR("failed to start device\n");
696 goto err0;
697 }
698
Mythri P Kc3198a52011-03-12 12:04:27 +0530699 r = hdmi_power_on(dssdev);
700 if (r) {
701 DSSERR("failed to power on device\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300702 goto err1;
Mythri P Kc3198a52011-03-12 12:04:27 +0530703 }
704
705 mutex_unlock(&hdmi.lock);
706 return 0;
707
Mythri P Kc3198a52011-03-12 12:04:27 +0530708err1:
709 omap_dss_stop_device(dssdev);
710err0:
711 mutex_unlock(&hdmi.lock);
712 return r;
713}
714
715void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
716{
717 DSSDBG("Enter hdmi_display_disable\n");
718
719 mutex_lock(&hdmi.lock);
720
721 hdmi_power_off(dssdev);
722
Mythri P Kc3198a52011-03-12 12:04:27 +0530723 omap_dss_stop_device(dssdev);
724
725 mutex_unlock(&hdmi.lock);
726}
727
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300728static int hdmi_get_clocks(struct platform_device *pdev)
729{
730 struct clk *clk;
731
732 clk = clk_get(&pdev->dev, "sys_clk");
733 if (IS_ERR(clk)) {
734 DSSERR("can't get sys_clk\n");
735 return PTR_ERR(clk);
736 }
737
738 hdmi.sys_clk = clk;
739
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300740 return 0;
741}
742
743static void hdmi_put_clocks(void)
744{
745 if (hdmi.sys_clk)
746 clk_put(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300747}
748
Ricardo Neri35547622012-03-20 21:02:01 -0600749#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
750int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
751{
752 u32 deep_color;
Ricardo Neri25a65352012-03-23 15:49:02 -0600753 bool deep_color_correct = false;
Ricardo Neri35547622012-03-20 21:02:01 -0600754 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
755
756 if (n == NULL || cts == NULL)
757 return -EINVAL;
758
759 /* TODO: When implemented, query deep color mode here. */
760 deep_color = 100;
761
Ricardo Neri25a65352012-03-23 15:49:02 -0600762 /*
763 * When using deep color, the default N value (as in the HDMI
764 * specification) yields to an non-integer CTS. Hence, we
765 * modify it while keeping the restrictions described in
766 * section 7.2.1 of the HDMI 1.4a specification.
767 */
Ricardo Neri35547622012-03-20 21:02:01 -0600768 switch (sample_freq) {
769 case 32000:
Ricardo Neri25a65352012-03-23 15:49:02 -0600770 case 48000:
771 case 96000:
772 case 192000:
773 if (deep_color == 125)
774 if (pclk == 27027 || pclk == 74250)
775 deep_color_correct = true;
776 if (deep_color == 150)
777 if (pclk == 27027)
778 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600779 break;
780 case 44100:
Ricardo Neri25a65352012-03-23 15:49:02 -0600781 case 88200:
782 case 176400:
783 if (deep_color == 125)
784 if (pclk == 27027)
785 deep_color_correct = true;
Ricardo Neri35547622012-03-20 21:02:01 -0600786 break;
787 default:
Ricardo Neri35547622012-03-20 21:02:01 -0600788 return -EINVAL;
789 }
790
Ricardo Neri25a65352012-03-23 15:49:02 -0600791 if (deep_color_correct) {
792 switch (sample_freq) {
793 case 32000:
794 *n = 8192;
795 break;
796 case 44100:
797 *n = 12544;
798 break;
799 case 48000:
800 *n = 8192;
801 break;
802 case 88200:
803 *n = 25088;
804 break;
805 case 96000:
806 *n = 16384;
807 break;
808 case 176400:
809 *n = 50176;
810 break;
811 case 192000:
812 *n = 32768;
813 break;
814 default:
815 return -EINVAL;
816 }
817 } else {
818 switch (sample_freq) {
819 case 32000:
820 *n = 4096;
821 break;
822 case 44100:
823 *n = 6272;
824 break;
825 case 48000:
826 *n = 6144;
827 break;
828 case 88200:
829 *n = 12544;
830 break;
831 case 96000:
832 *n = 12288;
833 break;
834 case 176400:
835 *n = 25088;
836 break;
837 case 192000:
838 *n = 24576;
839 break;
840 default:
841 return -EINVAL;
842 }
843 }
Ricardo Neri35547622012-03-20 21:02:01 -0600844 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
845 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
846
847 return 0;
848}
Ricardo Nerif3a974912012-05-09 21:09:50 -0500849
850int hdmi_audio_enable(void)
851{
852 DSSDBG("audio_enable\n");
853
854 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
855}
856
857void hdmi_audio_disable(void)
858{
859 DSSDBG("audio_disable\n");
860
861 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
862}
863
864int hdmi_audio_start(void)
865{
866 DSSDBG("audio_start\n");
867
868 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
869}
870
871void hdmi_audio_stop(void)
872{
873 DSSDBG("audio_stop\n");
874
875 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
876}
877
878bool hdmi_mode_has_audio(void)
879{
880 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
881 return true;
882 else
883 return false;
884}
885
886int hdmi_audio_config(struct omap_dss_audio *audio)
887{
888 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
889}
890
Ricardo Neri35547622012-03-20 21:02:01 -0600891#endif
892
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300893static void __init hdmi_probe_pdata(struct platform_device *pdev)
894{
895 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
896 int r, i;
897
898 for (i = 0; i < pdata->num_devices; ++i) {
899 struct omap_dss_device *dssdev = pdata->devices[i];
Tomi Valkeinencca35012012-04-26 14:48:32 +0300900 struct omap_dss_hdmi_data *priv = dssdev->data;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300901
902 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
903 continue;
904
Tomi Valkeinencca35012012-04-26 14:48:32 +0300905 hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
906 hdmi.ls_oe_gpio = priv->ls_oe_gpio;
907 hdmi.hpd_gpio = priv->hpd_gpio;
908
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300909 r = hdmi_init_display(dssdev);
910 if (r) {
911 DSSERR("device %s init failed: %d\n", dssdev->name, r);
912 continue;
913 }
914
915 r = omap_dss_register_device(dssdev, &pdev->dev, i);
916 if (r)
917 DSSERR("device %s register failed: %d\n",
918 dssdev->name, r);
919 }
920}
921
Mythri P Kc3198a52011-03-12 12:04:27 +0530922/* HDMI HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200923static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530924{
925 struct resource *hdmi_mem;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300926 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530927
Mythri P Kc3198a52011-03-12 12:04:27 +0530928 hdmi.pdev = pdev;
929
930 mutex_init(&hdmi.lock);
931
932 hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
933 if (!hdmi_mem) {
934 DSSERR("can't get IORESOURCE_MEM HDMI\n");
935 return -EINVAL;
936 }
937
938 /* Base address taken from platform */
Mythri P K95a8aeb2011-09-08 19:06:18 +0530939 hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
940 resource_size(hdmi_mem));
941 if (!hdmi.ip_data.base_wp) {
Mythri P Kc3198a52011-03-12 12:04:27 +0530942 DSSERR("can't ioremap WP\n");
943 return -ENOMEM;
944 }
945
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300946 r = hdmi_get_clocks(pdev);
947 if (r) {
Mythri P K95a8aeb2011-09-08 19:06:18 +0530948 iounmap(hdmi.ip_data.base_wp);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300949 return r;
950 }
951
952 pm_runtime_enable(&pdev->dev);
953
Mythri P K95a8aeb2011-09-08 19:06:18 +0530954 hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
955 hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
956 hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
957 hdmi.ip_data.phy_offset = HDMI_PHY;
Archit Taneja78493982012-08-08 16:50:42 +0530958
Jassi Brar3a5383a2012-06-27 19:34:56 +0530959 mutex_init(&hdmi.ip_data.lock);
Mythri P K95a8aeb2011-09-08 19:06:18 +0530960
Mythri P Kc3198a52011-03-12 12:04:27 +0530961 hdmi_panel_init();
962
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200963 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
964
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300965 hdmi_probe_pdata(pdev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200966
Mythri P Kc3198a52011-03-12 12:04:27 +0530967 return 0;
968}
969
Tomi Valkeinencca35012012-04-26 14:48:32 +0300970static int __exit hdmi_remove_child(struct device *dev, void *data)
971{
972 struct omap_dss_device *dssdev = to_dss_device(dev);
973 hdmi_uninit_display(dssdev);
974 return 0;
975}
976
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200977static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530978{
Tomi Valkeinencca35012012-04-26 14:48:32 +0300979 device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
980
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200981 omap_dss_unregister_child_devices(&pdev->dev);
982
Mythri P Kc3198a52011-03-12 12:04:27 +0530983 hdmi_panel_exit();
984
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300985 pm_runtime_disable(&pdev->dev);
986
987 hdmi_put_clocks();
988
Mythri P K95a8aeb2011-09-08 19:06:18 +0530989 iounmap(hdmi.ip_data.base_wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530990
991 return 0;
992}
993
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300994static int hdmi_runtime_suspend(struct device *dev)
995{
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530996 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300997
998 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300999
1000 return 0;
1001}
1002
1003static int hdmi_runtime_resume(struct device *dev)
1004{
1005 int r;
1006
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001007 r = dispc_runtime_get();
1008 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02001009 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001010
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301011 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001012
1013 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001014}
1015
1016static const struct dev_pm_ops hdmi_pm_ops = {
1017 .runtime_suspend = hdmi_runtime_suspend,
1018 .runtime_resume = hdmi_runtime_resume,
1019};
1020
Mythri P Kc3198a52011-03-12 12:04:27 +05301021static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001022 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +05301023 .driver = {
1024 .name = "omapdss_hdmi",
1025 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001026 .pm = &hdmi_pm_ops,
Mythri P Kc3198a52011-03-12 12:04:27 +05301027 },
1028};
1029
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001030int __init hdmi_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301031{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02001032 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
Mythri P Kc3198a52011-03-12 12:04:27 +05301033}
1034
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02001035void __exit hdmi_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +05301036{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02001037 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +05301038}