blob: 9a8713ca090c01561548a4e96d37cfd6fb5fb1db [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>
Mythri P Kc3198a52011-03-12 12:04:27 +053036
Archit Tanejaef269582013-09-12 17:45:57 +053037#include "hdmi4_core.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053038#include "dss.h"
Ricardo Neriad44cc32011-05-18 22:31:56 -050039#include "dss_features.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053040
41static struct {
42 struct mutex lock;
Mythri P Kc3198a52011-03-12 12:04:27 +053043 struct platform_device *pdev;
Ricardo Neri66a06b02012-11-06 00:19:14 -060044
Archit Taneja275cfa12013-10-08 14:22:03 +053045 struct hdmi_wp_data wp;
46 struct hdmi_pll_data pll;
47 struct hdmi_phy_data phy;
48 struct hdmi_core_data core;
49
50 struct hdmi_config cfg;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030051
52 struct clk *sys_clk;
Tomi Valkeinen17486942012-08-15 15:55:04 +030053 struct regulator *vdda_hdmi_dac_reg;
Tomi Valkeinencca35012012-04-26 14:48:32 +030054
Tomi Valkeinen0b450c32013-05-24 13:20:17 +030055 bool core_enabled;
56
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030057 struct omap_dss_device output;
Mythri P Kc3198a52011-03-12 12:04:27 +053058} hdmi;
59
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030060static int hdmi_runtime_get(void)
61{
62 int r;
63
64 DSSDBG("hdmi_runtime_get\n");
65
66 r = pm_runtime_get_sync(&hdmi.pdev->dev);
67 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +053068 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +020069 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +053070
71 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030072}
73
74static void hdmi_runtime_put(void)
75{
76 int r;
77
78 DSSDBG("hdmi_runtime_put\n");
79
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +020080 r = pm_runtime_put_sync(&hdmi.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +030081 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030082}
83
Tomi Valkeinendcf5f722013-10-28 11:47:34 +020084static irqreturn_t hdmi_irq_handler(int irq, void *data)
85{
86 struct hdmi_wp_data *wp = data;
87 u32 irqstatus;
88
89 irqstatus = hdmi_wp_get_irqstatus(wp);
90 hdmi_wp_set_irqstatus(wp, irqstatus);
91
92 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
93 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
94 /*
95 * If we get both connect and disconnect interrupts at the same
96 * time, turn off the PHY, clear interrupts, and restart, which
97 * raises connect interrupt if a cable is connected, or nothing
98 * if cable is not connected.
99 */
100 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
101
102 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
103 HDMI_IRQ_LINK_DISCONNECT);
104
105 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
106 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
107 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
108 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
109 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
110 }
111
112 return IRQ_HANDLED;
113}
114
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300115static int hdmi_init_regulator(void)
116{
Tomi Valkeinen818a0532013-09-23 18:42:11 +0530117 int r;
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300118 struct regulator *reg;
119
120 if (hdmi.vdda_hdmi_dac_reg != NULL)
121 return 0;
122
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +0300123 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300124
125 if (IS_ERR(reg)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200126 if (PTR_ERR(reg) != -EPROBE_DEFER)
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +0300127 DSSERR("can't get VDDA regulator\n");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300128 return PTR_ERR(reg);
129 }
130
Tomi Valkeinen818a0532013-09-23 18:42:11 +0530131 if (regulator_can_change_voltage(reg)) {
132 r = regulator_set_voltage(reg, 1800000, 1800000);
133 if (r) {
134 devm_regulator_put(reg);
135 DSSWARN("can't set the regulator voltage\n");
136 return r;
137 }
138 }
139
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300140 hdmi.vdda_hdmi_dac_reg = reg;
141
142 return 0;
143}
144
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300145static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530146{
Mythri P K46095b22012-01-06 17:52:09 +0530147 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530148
Tomi Valkeinen17486942012-08-15 15:55:04 +0300149 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
150 if (r)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300151 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300152
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300153 r = hdmi_runtime_get();
154 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300155 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530156
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300157 /* Make selection of HDMI in DSS */
158 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
159
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300160 hdmi.core_enabled = true;
161
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300162 return 0;
163
164err_runtime_get:
165 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300166
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300167 return r;
168}
169
170static void hdmi_power_off_core(struct omap_dss_device *dssdev)
171{
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300172 hdmi.core_enabled = false;
173
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300174 hdmi_runtime_put();
175 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300176}
177
178static int hdmi_power_on_full(struct omap_dss_device *dssdev)
179{
180 int r;
181 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300182 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300183 unsigned long phy;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200184 struct hdmi_wp_data *wp = &hdmi.wp;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300185
186 r = hdmi_power_on_core(dssdev);
187 if (r)
188 return r;
189
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200190 /* disable and clear irqs */
191 hdmi_wp_clear_irqenable(wp, 0xffffffff);
192 hdmi_wp_set_irqstatus(wp, 0xffffffff);
193
Archit Taneja275cfa12013-10-08 14:22:03 +0530194 p = &hdmi.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530195
Archit Taneja78493982012-08-08 16:50:42 +0530196 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 +0530197
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300198 /* the functions below use kHz pixel clock. TODO: change to Hz */
199 phy = p->pixelclock / 1000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530200
Archit Taneja275cfa12013-10-08 14:22:03 +0530201 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), phy);
Mythri P Kc3198a52011-03-12 12:04:27 +0530202
Mythri P K95a8aeb2011-09-08 19:06:18 +0530203 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Archit Taneja275cfa12013-10-08 14:22:03 +0530204 r = hdmi_pll_enable(&hdmi.pll, &hdmi.wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530205 if (r) {
206 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300207 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530208 }
209
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200210 r = hdmi_phy_configure(&hdmi.phy, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530211 if (r) {
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200212 DSSDBG("Failed to configure PHY\n");
213 goto err_phy_cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +0530214 }
215
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200216 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
217 if (r)
218 goto err_phy_pwr;
219
Archit Taneja275cfa12013-10-08 14:22:03 +0530220 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530221
Mythri P Kc3198a52011-03-12 12:04:27 +0530222 /* bypass TV gamma table */
223 dispc_enable_gamma_table(0);
224
225 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530226 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530227
Archit Taneja275cfa12013-10-08 14:22:03 +0530228 r = hdmi_wp_video_start(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500229 if (r)
230 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530231
Archit Tanejacea87b92012-09-07 17:56:20 +0530232 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200233 if (r)
234 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300235
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200236 hdmi_wp_set_irqenable(wp,
237 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
238
Mythri P Kc3198a52011-03-12 12:04:27 +0530239 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200240
241err_mgr_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530242 hdmi_wp_video_stop(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500243err_vid_enable:
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200244err_phy_cfg:
245 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
246err_phy_pwr:
Archit Taneja275cfa12013-10-08 14:22:03 +0530247 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300248err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300249 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530250 return -EIO;
251}
252
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300253static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530254{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300255 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530256
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200257 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
258
Archit Tanejacea87b92012-09-07 17:56:20 +0530259 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530260
Archit Taneja275cfa12013-10-08 14:22:03 +0530261 hdmi_wp_video_stop(&hdmi.wp);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200262
263 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
264
Archit Taneja275cfa12013-10-08 14:22:03 +0530265 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300266
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300267 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530268}
269
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300270static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530271 struct omap_video_timings *timings)
272{
Archit Taneja1e676242013-12-09 19:39:08 +0530273 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530274
Archit Taneja1e676242013-12-09 19:39:08 +0530275 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
Mythri P Kc3198a52011-03-12 12:04:27 +0530276 return -EINVAL;
Mythri P Kc3198a52011-03-12 12:04:27 +0530277
278 return 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530279}
280
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300281static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530282 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530283{
Archit Tanejaed1aa902012-08-15 00:40:31 +0530284 mutex_lock(&hdmi.lock);
285
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300286 hdmi.cfg.timings = *timings;
Archit Taneja78493982012-08-08 16:50:42 +0530287
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300288 dispc_set_tv_pclk(timings->pixelclock);
Archit Taneja1e676242013-12-09 19:39:08 +0530289
Archit Tanejaed1aa902012-08-15 00:40:31 +0530290 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530291}
292
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300293static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300294 struct omap_video_timings *timings)
295{
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300296 *timings = hdmi.cfg.timings;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300297}
298
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200299static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530300{
301 mutex_lock(&hdmi.lock);
302
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800303 if (hdmi_runtime_get()) {
304 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530305 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800306 }
Mythri P K162874d2011-09-22 13:37:45 +0530307
Archit Taneja275cfa12013-10-08 14:22:03 +0530308 hdmi_wp_dump(&hdmi.wp, s);
309 hdmi_pll_dump(&hdmi.pll, s);
310 hdmi_phy_dump(&hdmi.phy, s);
311 hdmi4_core_dump(&hdmi.core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530312
313 hdmi_runtime_put();
314 mutex_unlock(&hdmi.lock);
315}
316
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300317static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300318{
319 int r;
320
321 mutex_lock(&hdmi.lock);
322
323 r = hdmi_runtime_get();
324 BUG_ON(r);
325
Archit Taneja275cfa12013-10-08 14:22:03 +0530326 r = hdmi4_read_edid(&hdmi.core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300327
328 hdmi_runtime_put();
329 mutex_unlock(&hdmi.lock);
330
331 return r;
332}
333
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300334static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530335{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300336 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530337 int r = 0;
338
339 DSSDBG("ENTER hdmi_display_enable\n");
340
341 mutex_lock(&hdmi.lock);
342
Archit Tanejacea87b92012-09-07 17:56:20 +0530343 if (out == NULL || out->manager == NULL) {
344 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300345 r = -ENODEV;
346 goto err0;
347 }
348
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300349 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530350 if (r) {
351 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300352 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530353 }
354
355 mutex_unlock(&hdmi.lock);
356 return 0;
357
Mythri P Kc3198a52011-03-12 12:04:27 +0530358err0:
359 mutex_unlock(&hdmi.lock);
360 return r;
361}
362
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300363static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530364{
365 DSSDBG("Enter hdmi_display_disable\n");
366
367 mutex_lock(&hdmi.lock);
368
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300369 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530370
Mythri P Kc3198a52011-03-12 12:04:27 +0530371 mutex_unlock(&hdmi.lock);
372}
373
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300374static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300375{
376 int r = 0;
377
378 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
379
380 mutex_lock(&hdmi.lock);
381
Tomi Valkeinen44898232012-10-19 17:42:27 +0300382 r = hdmi_power_on_core(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
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300396static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300397{
398 DSSDBG("Enter omapdss_hdmi_core_disable\n");
399
400 mutex_lock(&hdmi.lock);
401
402 hdmi_power_off_core(dssdev);
403
404 mutex_unlock(&hdmi.lock);
405}
406
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300407static int hdmi_get_clocks(struct platform_device *pdev)
408{
409 struct clk *clk;
410
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300411 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300412 if (IS_ERR(clk)) {
413 DSSERR("can't get sys_clk\n");
414 return PTR_ERR(clk);
415 }
416
417 hdmi.sys_clk = clk;
418
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300419 return 0;
420}
421
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300422static int hdmi_connect(struct omap_dss_device *dssdev,
423 struct omap_dss_device *dst)
424{
425 struct omap_overlay_manager *mgr;
426 int r;
427
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300428 r = hdmi_init_regulator();
429 if (r)
430 return r;
431
432 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
433 if (!mgr)
434 return -ENODEV;
435
436 r = dss_mgr_connect(mgr, dssdev);
437 if (r)
438 return r;
439
440 r = omapdss_output_set_device(dssdev, dst);
441 if (r) {
442 DSSERR("failed to connect output to new device: %s\n",
443 dst->name);
444 dss_mgr_disconnect(mgr, dssdev);
445 return r;
446 }
447
448 return 0;
449}
450
451static void hdmi_disconnect(struct omap_dss_device *dssdev,
452 struct omap_dss_device *dst)
453{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300454 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300455
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300456 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300457 return;
458
459 omapdss_output_unset_device(dssdev);
460
461 if (dssdev->manager)
462 dss_mgr_disconnect(dssdev->manager, dssdev);
463}
464
465static int hdmi_read_edid(struct omap_dss_device *dssdev,
466 u8 *edid, int len)
467{
468 bool need_enable;
469 int r;
470
471 need_enable = hdmi.core_enabled == false;
472
473 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300474 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300475 if (r)
476 return r;
477 }
478
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300479 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300480
481 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300482 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300483
484 return r;
485}
486
487#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300488static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300489{
490 int r;
491
492 mutex_lock(&hdmi.lock);
493
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300494 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300495 r = -EPERM;
496 goto err;
497 }
498
Archit Taneja275cfa12013-10-08 14:22:03 +0530499 r = hdmi_wp_audio_enable(&hdmi.wp, true);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300500 if (r)
501 goto err;
502
503 mutex_unlock(&hdmi.lock);
504 return 0;
505
506err:
507 mutex_unlock(&hdmi.lock);
508 return r;
509}
510
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300511static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300512{
Archit Taneja275cfa12013-10-08 14:22:03 +0530513 hdmi_wp_audio_enable(&hdmi.wp, false);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300514}
515
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300516static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300517{
Archit Taneja275cfa12013-10-08 14:22:03 +0530518 return hdmi4_audio_start(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300519}
520
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300521static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300522{
Archit Taneja275cfa12013-10-08 14:22:03 +0530523 hdmi4_audio_stop(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300524}
525
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300526static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300527{
528 bool r;
529
530 mutex_lock(&hdmi.lock);
531
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300532 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300533
534 mutex_unlock(&hdmi.lock);
535 return r;
536}
537
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300538static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300539 struct omap_dss_audio *audio)
540{
541 int r;
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300542 u32 pclk = hdmi.cfg.timings.pixelclock;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300543
544 mutex_lock(&hdmi.lock);
545
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300546 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300547 r = -EPERM;
548 goto err;
549 }
550
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530551 r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300552 if (r)
553 goto err;
554
555 mutex_unlock(&hdmi.lock);
556 return 0;
557
558err:
559 mutex_unlock(&hdmi.lock);
560 return r;
561}
562#else
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300563static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300564{
565 return -EPERM;
566}
567
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300568static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300569{
570}
571
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300572static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300573{
574 return -EPERM;
575}
576
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300577static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300578{
579}
580
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300581static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300582{
583 return false;
584}
585
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300586static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300587 struct omap_dss_audio *audio)
588{
589 return -EPERM;
590}
591#endif
592
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300593static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
594 const struct hdmi_avi_infoframe *avi)
595{
596 hdmi.cfg.infoframe = *avi;
597 return 0;
598}
599
600static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
601 bool hdmi_mode)
602{
603 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
604 return 0;
605}
606
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300607static const struct omapdss_hdmi_ops hdmi_ops = {
608 .connect = hdmi_connect,
609 .disconnect = hdmi_disconnect,
610
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300611 .enable = hdmi_display_enable,
612 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300613
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300614 .check_timings = hdmi_display_check_timing,
615 .set_timings = hdmi_display_set_timing,
616 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300617
618 .read_edid = hdmi_read_edid,
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300619 .set_infoframe = hdmi_set_infoframe,
620 .set_hdmi_mode = hdmi_set_hdmi_mode,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300621
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300622 .audio_enable = hdmi_audio_enable,
623 .audio_disable = hdmi_audio_disable,
624 .audio_start = hdmi_audio_start,
625 .audio_stop = hdmi_audio_stop,
626 .audio_supported = hdmi_audio_supported,
627 .audio_config = hdmi_audio_config,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300628};
629
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300630static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530631{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300632 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530633
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300634 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530635 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300636 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200637 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200638 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300639 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300640 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530641
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300642 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530643}
644
645static void __exit hdmi_uninit_output(struct platform_device *pdev)
646{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300647 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530648
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300649 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530650}
651
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300652static int hdmi_probe_of(struct platform_device *pdev)
653{
654 struct device_node *node = pdev->dev.of_node;
655 struct device_node *ep;
656 int r;
657
658 ep = omapdss_of_get_first_endpoint(node);
659 if (!ep)
660 return 0;
661
662 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
663 if (r)
664 goto err;
665
666 of_node_put(ep);
667 return 0;
668
669err:
670 of_node_put(ep);
671 return r;
672}
673
Mythri P Kc3198a52011-03-12 12:04:27 +0530674/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300675static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530676{
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300677 int r;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200678 int irq;
Mythri P Kc3198a52011-03-12 12:04:27 +0530679
Mythri P Kc3198a52011-03-12 12:04:27 +0530680 hdmi.pdev = pdev;
681
682 mutex_init(&hdmi.lock);
683
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300684 if (pdev->dev.of_node) {
685 r = hdmi_probe_of(pdev);
686 if (r)
687 return r;
688 }
689
Archit Taneja275cfa12013-10-08 14:22:03 +0530690 r = hdmi_wp_init(pdev, &hdmi.wp);
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530691 if (r)
692 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530693
Archit Taneja275cfa12013-10-08 14:22:03 +0530694 r = hdmi_pll_init(pdev, &hdmi.pll);
Archit Tanejac1577c12013-10-08 12:55:26 +0530695 if (r)
696 return r;
697
Archit Taneja275cfa12013-10-08 14:22:03 +0530698 r = hdmi_phy_init(pdev, &hdmi.phy);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530699 if (r)
700 return r;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +0300701
Archit Taneja275cfa12013-10-08 14:22:03 +0530702 r = hdmi4_core_init(pdev, &hdmi.core);
Archit Taneja425f02f2013-10-08 14:16:05 +0530703 if (r)
704 return r;
705
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300706 r = hdmi_get_clocks(pdev);
707 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -0600708 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300709 return r;
710 }
711
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200712 irq = platform_get_irq(pdev, 0);
713 if (irq < 0) {
714 DSSERR("platform_get_irq failed\n");
715 return -ENODEV;
716 }
717
718 r = devm_request_threaded_irq(&pdev->dev, irq,
719 NULL, hdmi_irq_handler,
720 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
721 if (r) {
722 DSSERR("HDMI IRQ request failed\n");
723 return r;
724 }
725
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300726 pm_runtime_enable(&pdev->dev);
727
Tomi Valkeinen002d3682013-02-13 12:17:43 +0200728 hdmi_init_output(pdev);
729
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200730 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
731
Tomi Valkeinencca35012012-04-26 14:48:32 +0300732 return 0;
733}
734
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200735static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530736{
Archit Taneja81b87f52012-09-26 16:30:49 +0530737 hdmi_uninit_output(pdev);
738
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300739 pm_runtime_disable(&pdev->dev);
740
Mythri P Kc3198a52011-03-12 12:04:27 +0530741 return 0;
742}
743
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300744static int hdmi_runtime_suspend(struct device *dev)
745{
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530746 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300747
748 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300749
750 return 0;
751}
752
753static int hdmi_runtime_resume(struct device *dev)
754{
755 int r;
756
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300757 r = dispc_runtime_get();
758 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200759 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300760
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530761 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300762
763 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300764}
765
766static const struct dev_pm_ops hdmi_pm_ops = {
767 .runtime_suspend = hdmi_runtime_suspend,
768 .runtime_resume = hdmi_runtime_resume,
769};
770
Tomi Valkeinen04656162013-12-16 15:14:04 +0200771static const struct of_device_id hdmi_of_match[] = {
772 { .compatible = "ti,omap4-hdmi", },
773 {},
774};
775
Mythri P Kc3198a52011-03-12 12:04:27 +0530776static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300777 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200778 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +0530779 .driver = {
780 .name = "omapdss_hdmi",
781 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300782 .pm = &hdmi_pm_ops,
Tomi Valkeinen04656162013-12-16 15:14:04 +0200783 .of_match_table = hdmi_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300784 .suppress_bind_attrs = true,
Mythri P Kc3198a52011-03-12 12:04:27 +0530785 },
786};
787
Archit Tanejaef269582013-09-12 17:45:57 +0530788int __init hdmi4_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530789{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300790 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530791}
792
Archit Tanejaef269582013-09-12 17:45:57 +0530793void __exit hdmi4_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530794{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +0200795 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530796}