blob: e76cc5fb8430209a655d65df1a124b4f0b7c80a2 [file] [log] [blame]
Mythri P Kc3198a52011-03-12 12:04:27 +05301/*
Archit Tanejaef269582013-09-12 17:45:57 +05302 * HDMI interface DSS driver for TI's OMAP4 family of SoCs.
Mythri P Kc3198a52011-03-12 12:04:27 +05303 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
4 * Authors: Yong Zhi
5 * Mythri pk <mythripk@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DSS_SUBSYS_NAME "HDMI"
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/err.h>
25#include <linux/io.h>
26#include <linux/interrupt.h>
27#include <linux/mutex.h>
28#include <linux/delay.h>
29#include <linux/string.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030030#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030031#include <linux/pm_runtime.h>
32#include <linux/clk.h>
Tomi Valkeinencca35012012-04-26 14:48:32 +030033#include <linux/gpio.h>
Tomi Valkeinen17486942012-08-15 15:55:04 +030034#include <linux/regulator/consumer.h>
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030035#include <video/omapdss.h>
Jyri Sarha4d594df2014-05-23 12:48:28 +030036#include <sound/omap-hdmi-audio.h>
Mythri P Kc3198a52011-03-12 12:04:27 +053037
Archit Tanejaef269582013-09-12 17:45:57 +053038#include "hdmi4_core.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"
Jyri Sarha945514b2014-06-27 16:47:00 +030041#include "hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053042
Jyri Sarha945514b2014-06-27 16:47:00 +030043static struct omap_hdmi hdmi;
Mythri P Kc3198a52011-03-12 12:04:27 +053044
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030045static int hdmi_runtime_get(void)
46{
47 int r;
48
49 DSSDBG("hdmi_runtime_get\n");
50
51 r = pm_runtime_get_sync(&hdmi.pdev->dev);
52 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +053053 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +020054 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +053055
56 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030057}
58
59static void hdmi_runtime_put(void)
60{
61 int r;
62
63 DSSDBG("hdmi_runtime_put\n");
64
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +020065 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +030066 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030067}
68
Tomi Valkeinendcf5f722013-10-28 11:47:34 +020069static irqreturn_t hdmi_irq_handler(int irq, void *data)
70{
71 struct hdmi_wp_data *wp = data;
72 u32 irqstatus;
73
74 irqstatus = hdmi_wp_get_irqstatus(wp);
75 hdmi_wp_set_irqstatus(wp, irqstatus);
76
77 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
78 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
79 /*
80 * If we get both connect and disconnect interrupts at the same
81 * time, turn off the PHY, clear interrupts, and restart, which
82 * raises connect interrupt if a cable is connected, or nothing
83 * if cable is not connected.
84 */
85 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
86
87 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
88 HDMI_IRQ_LINK_DISCONNECT);
89
90 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
91 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
92 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
93 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
94 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
95 }
96
97 return IRQ_HANDLED;
98}
99
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300100static int hdmi_init_regulator(void)
101{
Tomi Valkeinen818a0532013-09-23 18:42:11 +0530102 int r;
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300103 struct regulator *reg;
104
Jyri Sarha945514b2014-06-27 16:47:00 +0300105 if (hdmi.vdda_reg != NULL)
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300106 return 0;
107
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +0300108 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300109
110 if (IS_ERR(reg)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200111 if (PTR_ERR(reg) != -EPROBE_DEFER)
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +0300112 DSSERR("can't get VDDA regulator\n");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300113 return PTR_ERR(reg);
114 }
115
Tomi Valkeinen818a0532013-09-23 18:42:11 +0530116 if (regulator_can_change_voltage(reg)) {
117 r = regulator_set_voltage(reg, 1800000, 1800000);
118 if (r) {
119 devm_regulator_put(reg);
120 DSSWARN("can't set the regulator voltage\n");
121 return r;
122 }
123 }
124
Jyri Sarha945514b2014-06-27 16:47:00 +0300125 hdmi.vdda_reg = reg;
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300126
127 return 0;
128}
129
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300130static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530131{
Mythri P K46095b22012-01-06 17:52:09 +0530132 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530133
Jyri Sarha945514b2014-06-27 16:47:00 +0300134 r = regulator_enable(hdmi.vdda_reg);
Tomi Valkeinen17486942012-08-15 15:55:04 +0300135 if (r)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300136 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300138 r = hdmi_runtime_get();
139 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300140 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530141
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300142 /* Make selection of HDMI in DSS */
143 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
144
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300145 hdmi.core_enabled = true;
146
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300147 return 0;
148
149err_runtime_get:
Jyri Sarha945514b2014-06-27 16:47:00 +0300150 regulator_disable(hdmi.vdda_reg);
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300151
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300152 return r;
153}
154
155static void hdmi_power_off_core(struct omap_dss_device *dssdev)
156{
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300157 hdmi.core_enabled = false;
158
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300159 hdmi_runtime_put();
Jyri Sarha945514b2014-06-27 16:47:00 +0300160 regulator_disable(hdmi.vdda_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300161}
162
163static int hdmi_power_on_full(struct omap_dss_device *dssdev)
164{
165 int r;
166 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300167 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200168 struct hdmi_wp_data *wp = &hdmi.wp;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300169 struct dss_pll_clock_info hdmi_cinfo = { 0 };
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300170
171 r = hdmi_power_on_core(dssdev);
172 if (r)
173 return r;
174
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200175 /* disable and clear irqs */
176 hdmi_wp_clear_irqenable(wp, 0xffffffff);
177 hdmi_wp_set_irqstatus(wp, 0xffffffff);
178
Archit Taneja275cfa12013-10-08 14:22:03 +0530179 p = &hdmi.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530180
Archit Taneja78493982012-08-08 16:50:42 +0530181 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 +0530182
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300183 hdmi_pll_compute(&hdmi.pll, p->pixelclock, &hdmi_cinfo);
Mythri P Kc3198a52011-03-12 12:04:27 +0530184
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300185 r = dss_pll_enable(&hdmi.pll.pll);
Mythri P Kc3198a52011-03-12 12:04:27 +0530186 if (r) {
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300187 DSSERR("Failed to enable PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300188 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530189 }
190
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300191 r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo);
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300192 if (r) {
193 DSSERR("Failed to configure PLL\n");
194 goto err_pll_cfg;
195 }
196
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300197 r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco,
198 hdmi_cinfo.clkout[0]);
Mythri P Kc3198a52011-03-12 12:04:27 +0530199 if (r) {
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200200 DSSDBG("Failed to configure PHY\n");
201 goto err_phy_cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +0530202 }
203
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200204 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
205 if (r)
206 goto err_phy_pwr;
207
Archit Taneja275cfa12013-10-08 14:22:03 +0530208 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530209
Mythri P Kc3198a52011-03-12 12:04:27 +0530210 /* bypass TV gamma table */
211 dispc_enable_gamma_table(0);
212
213 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530214 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530215
Archit Taneja275cfa12013-10-08 14:22:03 +0530216 r = hdmi_wp_video_start(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500217 if (r)
218 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530219
Archit Tanejacea87b92012-09-07 17:56:20 +0530220 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200221 if (r)
222 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300223
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200224 hdmi_wp_set_irqenable(wp,
225 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
226
Mythri P Kc3198a52011-03-12 12:04:27 +0530227 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200228
229err_mgr_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530230 hdmi_wp_video_stop(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500231err_vid_enable:
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200232err_phy_cfg:
233 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
234err_phy_pwr:
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300235err_pll_cfg:
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300236 dss_pll_disable(&hdmi.pll.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300237err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300238 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530239 return -EIO;
240}
241
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300242static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530243{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300244 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530245
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200246 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
247
Archit Tanejacea87b92012-09-07 17:56:20 +0530248 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530249
Archit Taneja275cfa12013-10-08 14:22:03 +0530250 hdmi_wp_video_stop(&hdmi.wp);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200251
252 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
253
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300254 dss_pll_disable(&hdmi.pll.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300255
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300256 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530257}
258
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300259static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530260 struct omap_video_timings *timings)
261{
Archit Taneja1e676242013-12-09 19:39:08 +0530262 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530263
Archit Taneja1e676242013-12-09 19:39:08 +0530264 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
Mythri P Kc3198a52011-03-12 12:04:27 +0530265 return -EINVAL;
Mythri P Kc3198a52011-03-12 12:04:27 +0530266
267 return 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530268}
269
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300270static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530271 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530272{
Archit Tanejaed1aa902012-08-15 00:40:31 +0530273 mutex_lock(&hdmi.lock);
274
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300275 hdmi.cfg.timings = *timings;
Archit Taneja78493982012-08-08 16:50:42 +0530276
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300277 dispc_set_tv_pclk(timings->pixelclock);
Archit Taneja1e676242013-12-09 19:39:08 +0530278
Archit Tanejaed1aa902012-08-15 00:40:31 +0530279 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530280}
281
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300282static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300283 struct omap_video_timings *timings)
284{
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300285 *timings = hdmi.cfg.timings;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300286}
287
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200288static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530289{
290 mutex_lock(&hdmi.lock);
291
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800292 if (hdmi_runtime_get()) {
293 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530294 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800295 }
Mythri P K162874d2011-09-22 13:37:45 +0530296
Archit Taneja275cfa12013-10-08 14:22:03 +0530297 hdmi_wp_dump(&hdmi.wp, s);
298 hdmi_pll_dump(&hdmi.pll, s);
299 hdmi_phy_dump(&hdmi.phy, s);
300 hdmi4_core_dump(&hdmi.core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530301
302 hdmi_runtime_put();
303 mutex_unlock(&hdmi.lock);
304}
305
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300306static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300307{
308 int r;
309
310 mutex_lock(&hdmi.lock);
311
312 r = hdmi_runtime_get();
313 BUG_ON(r);
314
Archit Taneja275cfa12013-10-08 14:22:03 +0530315 r = hdmi4_read_edid(&hdmi.core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300316
317 hdmi_runtime_put();
318 mutex_unlock(&hdmi.lock);
319
320 return r;
321}
322
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300323static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530324{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300325 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530326 int r = 0;
327
328 DSSDBG("ENTER hdmi_display_enable\n");
329
330 mutex_lock(&hdmi.lock);
331
Archit Tanejacea87b92012-09-07 17:56:20 +0530332 if (out == NULL || out->manager == NULL) {
333 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300334 r = -ENODEV;
335 goto err0;
336 }
337
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300338 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530339 if (r) {
340 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300341 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530342 }
343
Jyri Sarha4d594df2014-05-23 12:48:28 +0300344 hdmi.display_enabled = true;
345
Mythri P Kc3198a52011-03-12 12:04:27 +0530346 mutex_unlock(&hdmi.lock);
347 return 0;
348
Mythri P Kc3198a52011-03-12 12:04:27 +0530349err0:
350 mutex_unlock(&hdmi.lock);
351 return r;
352}
353
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300354static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530355{
356 DSSDBG("Enter hdmi_display_disable\n");
357
358 mutex_lock(&hdmi.lock);
359
Jyri Sarha4d594df2014-05-23 12:48:28 +0300360 if (hdmi.audio_pdev && hdmi.audio_abort_cb)
361 hdmi.audio_abort_cb(&hdmi.audio_pdev->dev);
362
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300363 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530364
Jyri Sarha4d594df2014-05-23 12:48:28 +0300365 hdmi.display_enabled = false;
366
Mythri P Kc3198a52011-03-12 12:04:27 +0530367 mutex_unlock(&hdmi.lock);
368}
369
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300370static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300371{
372 int r = 0;
373
374 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
375
376 mutex_lock(&hdmi.lock);
377
Tomi Valkeinen44898232012-10-19 17:42:27 +0300378 r = hdmi_power_on_core(dssdev);
379 if (r) {
380 DSSERR("failed to power on device\n");
381 goto err0;
382 }
383
384 mutex_unlock(&hdmi.lock);
385 return 0;
386
387err0:
388 mutex_unlock(&hdmi.lock);
389 return r;
390}
391
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300392static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300393{
394 DSSDBG("Enter omapdss_hdmi_core_disable\n");
395
396 mutex_lock(&hdmi.lock);
397
398 hdmi_power_off_core(dssdev);
399
400 mutex_unlock(&hdmi.lock);
401}
402
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300403static int hdmi_connect(struct omap_dss_device *dssdev,
404 struct omap_dss_device *dst)
405{
406 struct omap_overlay_manager *mgr;
407 int r;
408
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300409 r = hdmi_init_regulator();
410 if (r)
411 return r;
412
413 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
414 if (!mgr)
415 return -ENODEV;
416
417 r = dss_mgr_connect(mgr, dssdev);
418 if (r)
419 return r;
420
421 r = omapdss_output_set_device(dssdev, dst);
422 if (r) {
423 DSSERR("failed to connect output to new device: %s\n",
424 dst->name);
425 dss_mgr_disconnect(mgr, dssdev);
426 return r;
427 }
428
429 return 0;
430}
431
432static void hdmi_disconnect(struct omap_dss_device *dssdev,
433 struct omap_dss_device *dst)
434{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300435 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300436
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300437 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300438 return;
439
440 omapdss_output_unset_device(dssdev);
441
442 if (dssdev->manager)
443 dss_mgr_disconnect(dssdev->manager, dssdev);
444}
445
446static int hdmi_read_edid(struct omap_dss_device *dssdev,
447 u8 *edid, int len)
448{
449 bool need_enable;
450 int r;
451
452 need_enable = hdmi.core_enabled == false;
453
454 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300455 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300456 if (r)
457 return r;
458 }
459
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300460 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300461
462 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300463 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300464
465 return r;
466}
467
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300468static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
469 const struct hdmi_avi_infoframe *avi)
470{
471 hdmi.cfg.infoframe = *avi;
472 return 0;
473}
474
475static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
476 bool hdmi_mode)
477{
478 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
479 return 0;
480}
481
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300482static const struct omapdss_hdmi_ops hdmi_ops = {
483 .connect = hdmi_connect,
484 .disconnect = hdmi_disconnect,
485
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300486 .enable = hdmi_display_enable,
487 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300488
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300489 .check_timings = hdmi_display_check_timing,
490 .set_timings = hdmi_display_set_timing,
491 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300492
493 .read_edid = hdmi_read_edid,
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300494 .set_infoframe = hdmi_set_infoframe,
495 .set_hdmi_mode = hdmi_set_hdmi_mode,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300496};
497
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300498static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530499{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300500 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530501
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300502 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530503 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300504 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200505 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200506 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300507 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300508 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530509
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300510 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530511}
512
513static void __exit hdmi_uninit_output(struct platform_device *pdev)
514{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300515 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530516
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300517 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530518}
519
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300520static int hdmi_probe_of(struct platform_device *pdev)
521{
522 struct device_node *node = pdev->dev.of_node;
523 struct device_node *ep;
524 int r;
525
526 ep = omapdss_of_get_first_endpoint(node);
527 if (!ep)
528 return 0;
529
530 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
531 if (r)
532 goto err;
533
534 of_node_put(ep);
535 return 0;
536
537err:
538 of_node_put(ep);
539 return r;
540}
541
Jyri Sarha4d594df2014-05-23 12:48:28 +0300542/* Audio callbacks */
543static int hdmi_audio_startup(struct device *dev,
544 void (*abort_cb)(struct device *dev))
545{
546 struct omap_hdmi *hd = dev_get_drvdata(dev);
547 int ret = 0;
548
549 mutex_lock(&hd->lock);
550
551 if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
552 ret = -EPERM;
553 goto out;
554 }
555
556 hd->audio_abort_cb = abort_cb;
557
558out:
559 mutex_unlock(&hd->lock);
560
561 return ret;
562}
563
564static int hdmi_audio_shutdown(struct device *dev)
565{
566 struct omap_hdmi *hd = dev_get_drvdata(dev);
567
568 mutex_lock(&hd->lock);
569 hd->audio_abort_cb = NULL;
570 mutex_unlock(&hd->lock);
571
572 return 0;
573}
574
575static int hdmi_audio_start(struct device *dev)
576{
577 struct omap_hdmi *hd = dev_get_drvdata(dev);
578
579 WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
580 WARN_ON(!hd->display_enabled);
581
582 hdmi_wp_audio_enable(&hd->wp, true);
583 hdmi4_audio_start(&hd->core, &hd->wp);
584
585 return 0;
586}
587
588static void hdmi_audio_stop(struct device *dev)
589{
590 struct omap_hdmi *hd = dev_get_drvdata(dev);
591
592 WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
593 WARN_ON(!hd->display_enabled);
594
595 hdmi4_audio_stop(&hd->core, &hd->wp);
596 hdmi_wp_audio_enable(&hd->wp, false);
597}
598
599static int hdmi_audio_config(struct device *dev,
600 struct omap_dss_audio *dss_audio)
601{
602 struct omap_hdmi *hd = dev_get_drvdata(dev);
603 int ret;
604
605 mutex_lock(&hd->lock);
606
607 if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
608 ret = -EPERM;
609 goto out;
610 }
611
612 ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
613 hd->cfg.timings.pixelclock);
614
615out:
616 mutex_unlock(&hd->lock);
617
618 return ret;
619}
620
621static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
622 .audio_startup = hdmi_audio_startup,
623 .audio_shutdown = hdmi_audio_shutdown,
624 .audio_start = hdmi_audio_start,
625 .audio_stop = hdmi_audio_stop,
626 .audio_config = hdmi_audio_config,
627};
628
629static int hdmi_audio_register(struct device *dev)
630{
631 struct omap_hdmi_audio_pdata pdata = {
632 .dev = dev,
633 .dss_version = omapdss_get_version(),
634 .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi.wp),
635 .ops = &hdmi_audio_ops,
636 };
637
638 hdmi.audio_pdev = platform_device_register_data(
639 dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
640 &pdata, sizeof(pdata));
641
642 if (IS_ERR(hdmi.audio_pdev))
643 return PTR_ERR(hdmi.audio_pdev);
644
645 return 0;
646}
647
Mythri P Kc3198a52011-03-12 12:04:27 +0530648/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300649static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530650{
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300651 int r;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200652 int irq;
Mythri P Kc3198a52011-03-12 12:04:27 +0530653
Mythri P Kc3198a52011-03-12 12:04:27 +0530654 hdmi.pdev = pdev;
Jyri Sarha945514b2014-06-27 16:47:00 +0300655 dev_set_drvdata(&pdev->dev, &hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530656
657 mutex_init(&hdmi.lock);
658
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300659 if (pdev->dev.of_node) {
660 r = hdmi_probe_of(pdev);
661 if (r)
662 return r;
663 }
664
Archit Taneja275cfa12013-10-08 14:22:03 +0530665 r = hdmi_wp_init(pdev, &hdmi.wp);
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530666 if (r)
667 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530668
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300669 r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
Archit Tanejac1577c12013-10-08 12:55:26 +0530670 if (r)
671 return r;
672
Archit Taneja275cfa12013-10-08 14:22:03 +0530673 r = hdmi_phy_init(pdev, &hdmi.phy);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530674 if (r)
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300675 goto err;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +0300676
Archit Taneja275cfa12013-10-08 14:22:03 +0530677 r = hdmi4_core_init(pdev, &hdmi.core);
Archit Taneja425f02f2013-10-08 14:16:05 +0530678 if (r)
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300679 goto err;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300680
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200681 irq = platform_get_irq(pdev, 0);
682 if (irq < 0) {
683 DSSERR("platform_get_irq failed\n");
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300684 r = -ENODEV;
685 goto err;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200686 }
687
688 r = devm_request_threaded_irq(&pdev->dev, irq,
689 NULL, hdmi_irq_handler,
690 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
691 if (r) {
692 DSSERR("HDMI IRQ request failed\n");
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300693 goto err;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200694 }
695
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300696 pm_runtime_enable(&pdev->dev);
697
Tomi Valkeinen002d3682013-02-13 12:17:43 +0200698 hdmi_init_output(pdev);
699
Jyri Sarha4d594df2014-05-23 12:48:28 +0300700 r = hdmi_audio_register(&pdev->dev);
701 if (r) {
702 DSSERR("Registering HDMI audio failed\n");
703 hdmi_uninit_output(pdev);
704 pm_runtime_disable(&pdev->dev);
705 return r;
706 }
707
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200708 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
709
Tomi Valkeinencca35012012-04-26 14:48:32 +0300710 return 0;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300711err:
712 hdmi_pll_uninit(&hdmi.pll);
713 return r;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300714}
715
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200716static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530717{
Jyri Sarha4d594df2014-05-23 12:48:28 +0300718 if (hdmi.audio_pdev)
719 platform_device_unregister(hdmi.audio_pdev);
720
Archit Taneja81b87f52012-09-26 16:30:49 +0530721 hdmi_uninit_output(pdev);
722
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300723 hdmi_pll_uninit(&hdmi.pll);
724
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300725 pm_runtime_disable(&pdev->dev);
726
Mythri P Kc3198a52011-03-12 12:04:27 +0530727 return 0;
728}
729
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300730static int hdmi_runtime_suspend(struct device *dev)
731{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300732 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300733
734 return 0;
735}
736
737static int hdmi_runtime_resume(struct device *dev)
738{
739 int r;
740
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300741 r = dispc_runtime_get();
742 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200743 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300744
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300745 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300746}
747
748static const struct dev_pm_ops hdmi_pm_ops = {
749 .runtime_suspend = hdmi_runtime_suspend,
750 .runtime_resume = hdmi_runtime_resume,
751};
752
Tomi Valkeinen04656162013-12-16 15:14:04 +0200753static const struct of_device_id hdmi_of_match[] = {
754 { .compatible = "ti,omap4-hdmi", },
755 {},
756};
757
Mythri P Kc3198a52011-03-12 12:04:27 +0530758static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300759 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200760 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +0530761 .driver = {
762 .name = "omapdss_hdmi",
763 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300764 .pm = &hdmi_pm_ops,
Tomi Valkeinen04656162013-12-16 15:14:04 +0200765 .of_match_table = hdmi_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300766 .suppress_bind_attrs = true,
Mythri P Kc3198a52011-03-12 12:04:27 +0530767 },
768};
769
Archit Tanejaef269582013-09-12 17:45:57 +0530770int __init hdmi4_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530771{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300772 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530773}
774
Archit Tanejaef269582013-09-12 17:45:57 +0530775void __exit hdmi4_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530776{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +0200777 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530778}