blob: 67facf87b3707247e6f124efc5b1ac19a8031b3d [file] [log] [blame]
Tomi Valkeinenf5bab222014-03-13 12:44:14 +02001/*
2 * HDMI driver for OMAP5
3 *
4 * Copyright (C) 2014 Texas Instruments Incorporated
5 *
6 * Authors:
7 * Yong Zhi
8 * Mythri pk
9 * Archit Taneja <archit@ti.com>
10 * Tomi Valkeinen <tomi.valkeinen@ti.com>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published by
14 * the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25#define DSS_SUBSYS_NAME "HDMI"
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/err.h>
30#include <linux/io.h>
31#include <linux/interrupt.h>
32#include <linux/mutex.h>
33#include <linux/delay.h>
34#include <linux/string.h>
35#include <linux/platform_device.h>
36#include <linux/pm_runtime.h>
37#include <linux/clk.h>
38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h>
40#include <video/omapdss.h>
41
42#include "hdmi5_core.h"
43#include "dss.h"
44#include "dss_features.h"
45
46static struct {
47 struct mutex lock;
48 struct platform_device *pdev;
49
50 struct hdmi_wp_data wp;
51 struct hdmi_pll_data pll;
52 struct hdmi_phy_data phy;
53 struct hdmi_core_data core;
54
55 struct hdmi_config cfg;
56
Tomi Valkeinenf5bab222014-03-13 12:44:14 +020057 struct regulator *vdda_reg;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +030058 struct clk *sys_clk;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +020059
60 bool core_enabled;
61
62 struct omap_dss_device output;
63} hdmi;
64
65static int hdmi_runtime_get(void)
66{
67 int r;
68
69 DSSDBG("hdmi_runtime_get\n");
70
71 r = pm_runtime_get_sync(&hdmi.pdev->dev);
72 WARN_ON(r < 0);
73 if (r < 0)
74 return r;
75
76 return 0;
77}
78
79static void hdmi_runtime_put(void)
80{
81 int r;
82
83 DSSDBG("hdmi_runtime_put\n");
84
85 r = pm_runtime_put_sync(&hdmi.pdev->dev);
86 WARN_ON(r < 0 && r != -ENOSYS);
87}
88
89static irqreturn_t hdmi_irq_handler(int irq, void *data)
90{
91 struct hdmi_wp_data *wp = data;
92 u32 irqstatus;
93
94 irqstatus = hdmi_wp_get_irqstatus(wp);
95 hdmi_wp_set_irqstatus(wp, irqstatus);
96
97 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
98 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
99 u32 v;
100 /*
101 * If we get both connect and disconnect interrupts at the same
102 * time, turn off the PHY, clear interrupts, and restart, which
103 * raises connect interrupt if a cable is connected, or nothing
104 * if cable is not connected.
105 */
106
107 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
108
109 /*
110 * We always get bogus CONNECT & DISCONNECT interrupts when
111 * setting the PHY to LDOON. To ignore those, we force the RXDET
112 * line to 0 until the PHY power state has been changed.
113 */
114 v = hdmi_read_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL);
115 v = FLD_MOD(v, 1, 15, 15); /* FORCE_RXDET_HIGH */
116 v = FLD_MOD(v, 0, 14, 7); /* RXDET_LINE */
117 hdmi_write_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, v);
118
119 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
120 HDMI_IRQ_LINK_DISCONNECT);
121
122 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
123
124 REG_FLD_MOD(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, 0, 15, 15);
125
126 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
127 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
128 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
129 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
130 }
131
132 return IRQ_HANDLED;
133}
134
135static int hdmi_init_regulator(void)
136{
137 int r;
138 struct regulator *reg;
139
140 if (hdmi.vdda_reg != NULL)
141 return 0;
142
143 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
144 if (IS_ERR(reg)) {
145 DSSERR("can't get VDDA regulator\n");
146 return PTR_ERR(reg);
147 }
148
149 if (regulator_can_change_voltage(reg)) {
150 r = regulator_set_voltage(reg, 1800000, 1800000);
151 if (r) {
152 devm_regulator_put(reg);
153 DSSWARN("can't set the regulator voltage\n");
154 return r;
155 }
156 }
157
158 hdmi.vdda_reg = reg;
159
160 return 0;
161}
162
163static int hdmi_power_on_core(struct omap_dss_device *dssdev)
164{
165 int r;
166
167 r = regulator_enable(hdmi.vdda_reg);
168 if (r)
169 return r;
170
171 r = hdmi_runtime_get();
172 if (r)
173 goto err_runtime_get;
174
175 /* Make selection of HDMI in DSS */
176 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
177
178 hdmi.core_enabled = true;
179
180 return 0;
181
182err_runtime_get:
183 regulator_disable(hdmi.vdda_reg);
184
185 return r;
186}
187
188static void hdmi_power_off_core(struct omap_dss_device *dssdev)
189{
190 hdmi.core_enabled = false;
191
192 hdmi_runtime_put();
193 regulator_disable(hdmi.vdda_reg);
194}
195
196static int hdmi_power_on_full(struct omap_dss_device *dssdev)
197{
198 int r;
199 struct omap_video_timings *p;
200 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300201 struct dss_pll_clock_info hdmi_cinfo = { 0 };
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200202
203 r = hdmi_power_on_core(dssdev);
204 if (r)
205 return r;
206
207 p = &hdmi.cfg.timings;
208
209 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
210
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300211 hdmi_pll_compute(&hdmi.pll, p->pixelclock, &hdmi_cinfo);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200212
213 /* disable and clear irqs */
214 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
215 hdmi_wp_set_irqstatus(&hdmi.wp,
216 hdmi_wp_get_irqstatus(&hdmi.wp));
217
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300218 r = dss_pll_enable(&hdmi.pll.pll);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200219 if (r) {
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300220 DSSERR("Failed to enable PLL\n");
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200221 goto err_pll_enable;
222 }
223
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300224 r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo);
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300225 if (r) {
226 DSSERR("Failed to configure PLL\n");
227 goto err_pll_cfg;
228 }
229
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300230 r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco,
231 hdmi_cinfo.clkout[0]);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200232 if (r) {
233 DSSDBG("Failed to start PHY\n");
234 goto err_phy_cfg;
235 }
236
237 r = hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_LDOON);
238 if (r)
239 goto err_phy_pwr;
240
241 hdmi5_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
242
243 /* bypass TV gamma table */
244 dispc_enable_gamma_table(0);
245
246 /* tv size */
247 dss_mgr_set_timings(mgr, p);
248
249 r = hdmi_wp_video_start(&hdmi.wp);
250 if (r)
251 goto err_vid_enable;
252
253 r = dss_mgr_enable(mgr);
254 if (r)
255 goto err_mgr_enable;
256
257 hdmi_wp_set_irqenable(&hdmi.wp,
258 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
259
260 return 0;
261
262err_mgr_enable:
263 hdmi_wp_video_stop(&hdmi.wp);
264err_vid_enable:
265 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
266err_phy_pwr:
267err_phy_cfg:
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300268err_pll_cfg:
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300269 dss_pll_disable(&hdmi.pll.pll);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200270err_pll_enable:
271 hdmi_power_off_core(dssdev);
272 return -EIO;
273}
274
275static void hdmi_power_off_full(struct omap_dss_device *dssdev)
276{
277 struct omap_overlay_manager *mgr = hdmi.output.manager;
278
279 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
280
281 dss_mgr_disable(mgr);
282
283 hdmi_wp_video_stop(&hdmi.wp);
284
285 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
286
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300287 dss_pll_disable(&hdmi.pll.pll);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200288
289 hdmi_power_off_core(dssdev);
290}
291
292static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
293 struct omap_video_timings *timings)
294{
295 struct omap_dss_device *out = &hdmi.output;
296
Tomi Valkeinen31dd0f42014-09-16 12:46:33 +0300297 /* TODO: proper interlace support */
298 if (timings->interlace)
299 return -EINVAL;
300
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200301 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
302 return -EINVAL;
303
304 return 0;
305}
306
307static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
308 struct omap_video_timings *timings)
309{
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200310 mutex_lock(&hdmi.lock);
311
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300312 hdmi.cfg.timings = *timings;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200313
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300314 dispc_set_tv_pclk(timings->pixelclock);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200315
316 mutex_unlock(&hdmi.lock);
317}
318
319static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
320 struct omap_video_timings *timings)
321{
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300322 *timings = hdmi.cfg.timings;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200323}
324
325static void hdmi_dump_regs(struct seq_file *s)
326{
327 mutex_lock(&hdmi.lock);
328
329 if (hdmi_runtime_get()) {
330 mutex_unlock(&hdmi.lock);
331 return;
332 }
333
334 hdmi_wp_dump(&hdmi.wp, s);
335 hdmi_pll_dump(&hdmi.pll, s);
336 hdmi_phy_dump(&hdmi.phy, s);
337 hdmi5_core_dump(&hdmi.core, s);
338
339 hdmi_runtime_put();
340 mutex_unlock(&hdmi.lock);
341}
342
343static int read_edid(u8 *buf, int len)
344{
345 int r;
346 int idlemode;
347
348 mutex_lock(&hdmi.lock);
349
350 r = hdmi_runtime_get();
351 BUG_ON(r);
352
353 idlemode = REG_GET(hdmi.wp.base, HDMI_WP_SYSCONFIG, 3, 2);
354 /* No-idle mode */
355 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2);
356
357 r = hdmi5_read_edid(&hdmi.core, buf, len);
358
359 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, idlemode, 3, 2);
360
361 hdmi_runtime_put();
362 mutex_unlock(&hdmi.lock);
363
364 return r;
365}
366
367static int hdmi_display_enable(struct omap_dss_device *dssdev)
368{
369 struct omap_dss_device *out = &hdmi.output;
370 int r = 0;
371
372 DSSDBG("ENTER hdmi_display_enable\n");
373
374 mutex_lock(&hdmi.lock);
375
376 if (out == NULL || out->manager == NULL) {
377 DSSERR("failed to enable display: no output/manager\n");
378 r = -ENODEV;
379 goto err0;
380 }
381
382 r = hdmi_power_on_full(dssdev);
383 if (r) {
384 DSSERR("failed to power on device\n");
385 goto err0;
386 }
387
388 mutex_unlock(&hdmi.lock);
389 return 0;
390
391err0:
392 mutex_unlock(&hdmi.lock);
393 return r;
394}
395
396static void hdmi_display_disable(struct omap_dss_device *dssdev)
397{
398 DSSDBG("Enter hdmi_display_disable\n");
399
400 mutex_lock(&hdmi.lock);
401
402 hdmi_power_off_full(dssdev);
403
404 mutex_unlock(&hdmi.lock);
405}
406
407static int hdmi_core_enable(struct omap_dss_device *dssdev)
408{
409 int r = 0;
410
411 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
412
413 mutex_lock(&hdmi.lock);
414
415 r = hdmi_power_on_core(dssdev);
416 if (r) {
417 DSSERR("failed to power on device\n");
418 goto err0;
419 }
420
421 mutex_unlock(&hdmi.lock);
422 return 0;
423
424err0:
425 mutex_unlock(&hdmi.lock);
426 return r;
427}
428
429static void hdmi_core_disable(struct omap_dss_device *dssdev)
430{
431 DSSDBG("Enter omapdss_hdmi_core_disable\n");
432
433 mutex_lock(&hdmi.lock);
434
435 hdmi_power_off_core(dssdev);
436
437 mutex_unlock(&hdmi.lock);
438}
439
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200440static int hdmi_connect(struct omap_dss_device *dssdev,
441 struct omap_dss_device *dst)
442{
443 struct omap_overlay_manager *mgr;
444 int r;
445
446 r = hdmi_init_regulator();
447 if (r)
448 return r;
449
450 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
451 if (!mgr)
452 return -ENODEV;
453
454 r = dss_mgr_connect(mgr, dssdev);
455 if (r)
456 return r;
457
458 r = omapdss_output_set_device(dssdev, dst);
459 if (r) {
460 DSSERR("failed to connect output to new device: %s\n",
461 dst->name);
462 dss_mgr_disconnect(mgr, dssdev);
463 return r;
464 }
465
466 return 0;
467}
468
469static void hdmi_disconnect(struct omap_dss_device *dssdev,
470 struct omap_dss_device *dst)
471{
472 WARN_ON(dst != dssdev->dst);
473
474 if (dst != dssdev->dst)
475 return;
476
477 omapdss_output_unset_device(dssdev);
478
479 if (dssdev->manager)
480 dss_mgr_disconnect(dssdev->manager, dssdev);
481}
482
483static int hdmi_read_edid(struct omap_dss_device *dssdev,
484 u8 *edid, int len)
485{
486 bool need_enable;
487 int r;
488
489 need_enable = hdmi.core_enabled == false;
490
491 if (need_enable) {
492 r = hdmi_core_enable(dssdev);
493 if (r)
494 return r;
495 }
496
497 r = read_edid(edid, len);
498
499 if (need_enable)
500 hdmi_core_disable(dssdev);
501
502 return r;
503}
504
505#if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
506static int hdmi_audio_enable(struct omap_dss_device *dssdev)
507{
508 int r;
509
510 mutex_lock(&hdmi.lock);
511
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300512 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200513 r = -EPERM;
514 goto err;
515 }
516
517 r = hdmi_wp_audio_enable(&hdmi.wp, true);
518 if (r)
519 goto err;
520
521 mutex_unlock(&hdmi.lock);
522 return 0;
523
524err:
525 mutex_unlock(&hdmi.lock);
526 return r;
527}
528
529static void hdmi_audio_disable(struct omap_dss_device *dssdev)
530{
531 hdmi_wp_audio_enable(&hdmi.wp, false);
532}
533
534static int hdmi_audio_start(struct omap_dss_device *dssdev)
535{
536 return hdmi_wp_audio_core_req_enable(&hdmi.wp, true);
537}
538
539static void hdmi_audio_stop(struct omap_dss_device *dssdev)
540{
541 hdmi_wp_audio_core_req_enable(&hdmi.wp, false);
542}
543
544static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
545{
546 bool r;
547
548 mutex_lock(&hdmi.lock);
549
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300550 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200551
552 mutex_unlock(&hdmi.lock);
553 return r;
554}
555
556static int hdmi_audio_config(struct omap_dss_device *dssdev,
557 struct omap_dss_audio *audio)
558{
559 int r;
560 u32 pclk = hdmi.cfg.timings.pixelclock;
561
562 mutex_lock(&hdmi.lock);
563
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300564 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200565 r = -EPERM;
566 goto err;
567 }
568
569 r = hdmi5_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
570 if (r)
571 goto err;
572
573 mutex_unlock(&hdmi.lock);
574 return 0;
575
576err:
577 mutex_unlock(&hdmi.lock);
578 return r;
579}
580#else
581static int hdmi_audio_enable(struct omap_dss_device *dssdev)
582{
583 return -EPERM;
584}
585
586static void hdmi_audio_disable(struct omap_dss_device *dssdev)
587{
588}
589
590static int hdmi_audio_start(struct omap_dss_device *dssdev)
591{
592 return -EPERM;
593}
594
595static void hdmi_audio_stop(struct omap_dss_device *dssdev)
596{
597}
598
599static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
600{
601 return false;
602}
603
604static int hdmi_audio_config(struct omap_dss_device *dssdev,
605 struct omap_dss_audio *audio)
606{
607 return -EPERM;
608}
609#endif
610
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300611static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
612 const struct hdmi_avi_infoframe *avi)
613{
614 hdmi.cfg.infoframe = *avi;
615 return 0;
616}
617
618static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
619 bool hdmi_mode)
620{
621 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
622 return 0;
623}
624
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200625static const struct omapdss_hdmi_ops hdmi_ops = {
626 .connect = hdmi_connect,
627 .disconnect = hdmi_disconnect,
628
629 .enable = hdmi_display_enable,
630 .disable = hdmi_display_disable,
631
632 .check_timings = hdmi_display_check_timing,
633 .set_timings = hdmi_display_set_timing,
634 .get_timings = hdmi_display_get_timings,
635
636 .read_edid = hdmi_read_edid,
Tomi Valkeinen769dcb12014-06-18 14:21:55 +0300637 .set_infoframe = hdmi_set_infoframe,
638 .set_hdmi_mode = hdmi_set_hdmi_mode,
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200639
640 .audio_enable = hdmi_audio_enable,
641 .audio_disable = hdmi_audio_disable,
642 .audio_start = hdmi_audio_start,
643 .audio_stop = hdmi_audio_stop,
644 .audio_supported = hdmi_audio_supported,
645 .audio_config = hdmi_audio_config,
646};
647
648static void hdmi_init_output(struct platform_device *pdev)
649{
650 struct omap_dss_device *out = &hdmi.output;
651
652 out->dev = &pdev->dev;
653 out->id = OMAP_DSS_OUTPUT_HDMI;
654 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
655 out->name = "hdmi.0";
656 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
657 out->ops.hdmi = &hdmi_ops;
658 out->owner = THIS_MODULE;
659
660 omapdss_register_output(out);
661}
662
663static void __exit hdmi_uninit_output(struct platform_device *pdev)
664{
665 struct omap_dss_device *out = &hdmi.output;
666
667 omapdss_unregister_output(out);
668}
669
670static int hdmi_probe_of(struct platform_device *pdev)
671{
672 struct device_node *node = pdev->dev.of_node;
673 struct device_node *ep;
674 int r;
675
676 ep = omapdss_of_get_first_endpoint(node);
677 if (!ep)
678 return 0;
679
680 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
681 if (r)
682 goto err;
683
684 of_node_put(ep);
685 return 0;
686
687err:
688 of_node_put(ep);
689 return r;
690}
691
692/* HDMI HW IP initialisation */
693static int omapdss_hdmihw_probe(struct platform_device *pdev)
694{
695 int r;
696 int irq;
697
698 hdmi.pdev = pdev;
699
700 mutex_init(&hdmi.lock);
701
702 if (pdev->dev.of_node) {
703 r = hdmi_probe_of(pdev);
704 if (r)
705 return r;
706 }
707
708 r = hdmi_wp_init(pdev, &hdmi.wp);
709 if (r)
710 return r;
711
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300712 r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200713 if (r)
714 return r;
715
716 r = hdmi_phy_init(pdev, &hdmi.phy);
717 if (r)
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300718 goto err;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200719
720 r = hdmi5_core_init(pdev, &hdmi.core);
721 if (r)
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300722 goto err;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200723
724 irq = platform_get_irq(pdev, 0);
725 if (irq < 0) {
726 DSSERR("platform_get_irq failed\n");
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300727 r = -ENODEV;
728 goto err;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200729 }
730
731 r = devm_request_threaded_irq(&pdev->dev, irq,
732 NULL, hdmi_irq_handler,
733 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
734 if (r) {
735 DSSERR("HDMI IRQ request failed\n");
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300736 goto err;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200737 }
738
739 pm_runtime_enable(&pdev->dev);
740
741 hdmi_init_output(pdev);
742
743 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
744
745 return 0;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300746err:
747 hdmi_pll_uninit(&hdmi.pll);
748 return r;
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200749}
750
751static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
752{
753 hdmi_uninit_output(pdev);
754
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300755 hdmi_pll_uninit(&hdmi.pll);
756
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200757 pm_runtime_disable(&pdev->dev);
758
759 return 0;
760}
761
762static int hdmi_runtime_suspend(struct device *dev)
763{
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200764 dispc_runtime_put();
765
766 return 0;
767}
768
769static int hdmi_runtime_resume(struct device *dev)
770{
771 int r;
772
773 r = dispc_runtime_get();
774 if (r < 0)
775 return r;
776
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200777 return 0;
778}
779
780static const struct dev_pm_ops hdmi_pm_ops = {
781 .runtime_suspend = hdmi_runtime_suspend,
782 .runtime_resume = hdmi_runtime_resume,
783};
784
785static const struct of_device_id hdmi_of_match[] = {
786 { .compatible = "ti,omap5-hdmi", },
787 {},
788};
789
790static struct platform_driver omapdss_hdmihw_driver = {
791 .probe = omapdss_hdmihw_probe,
792 .remove = __exit_p(omapdss_hdmihw_remove),
793 .driver = {
794 .name = "omapdss_hdmi5",
795 .owner = THIS_MODULE,
796 .pm = &hdmi_pm_ops,
797 .of_match_table = hdmi_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300798 .suppress_bind_attrs = true,
Tomi Valkeinenf5bab222014-03-13 12:44:14 +0200799 },
800};
801
802int __init hdmi5_init_platform_driver(void)
803{
804 return platform_driver_register(&omapdss_hdmihw_driver);
805}
806
807void __exit hdmi5_uninit_platform_driver(void)
808{
809 platform_driver_unregister(&omapdss_hdmihw_driver);
810}