blob: 98aa910241b818ed0a1b117c074feea3c8803e6c [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 Valkeinendcf5f722013-10-28 11:47:34 +0200183 struct hdmi_wp_data *wp = &hdmi.wp;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300184
185 r = hdmi_power_on_core(dssdev);
186 if (r)
187 return r;
188
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200189 /* disable and clear irqs */
190 hdmi_wp_clear_irqenable(wp, 0xffffffff);
191 hdmi_wp_set_irqstatus(wp, 0xffffffff);
192
Archit Taneja275cfa12013-10-08 14:22:03 +0530193 p = &hdmi.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530194
Archit Taneja78493982012-08-08 16:50:42 +0530195 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 +0530196
Tomi Valkeinen33f13122014-09-15 15:40:47 +0300197 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), p->pixelclock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530198
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300199 r = hdmi_pll_enable(&hdmi.pll);
Mythri P Kc3198a52011-03-12 12:04:27 +0530200 if (r) {
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300201 DSSERR("Failed to enable PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300202 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530203 }
204
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300205 r = hdmi_pll_set_config(&hdmi.pll);
206 if (r) {
207 DSSERR("Failed to configure PLL\n");
208 goto err_pll_cfg;
209 }
210
Tomi Valkeinen33f13122014-09-15 15:40:47 +0300211 r = hdmi_phy_configure(&hdmi.phy, hdmi.pll.info.clkdco,
212 hdmi.pll.info.clkout);
Mythri P Kc3198a52011-03-12 12:04:27 +0530213 if (r) {
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200214 DSSDBG("Failed to configure PHY\n");
215 goto err_phy_cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +0530216 }
217
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200218 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
219 if (r)
220 goto err_phy_pwr;
221
Archit Taneja275cfa12013-10-08 14:22:03 +0530222 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530223
Mythri P Kc3198a52011-03-12 12:04:27 +0530224 /* bypass TV gamma table */
225 dispc_enable_gamma_table(0);
226
227 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530228 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530229
Archit Taneja275cfa12013-10-08 14:22:03 +0530230 r = hdmi_wp_video_start(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500231 if (r)
232 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530233
Archit Tanejacea87b92012-09-07 17:56:20 +0530234 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200235 if (r)
236 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300237
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200238 hdmi_wp_set_irqenable(wp,
239 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
240
Mythri P Kc3198a52011-03-12 12:04:27 +0530241 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200242
243err_mgr_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530244 hdmi_wp_video_stop(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500245err_vid_enable:
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200246err_phy_cfg:
247 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
248err_phy_pwr:
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300249err_pll_cfg:
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300250 hdmi_pll_disable(&hdmi.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300251err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300252 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530253 return -EIO;
254}
255
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300256static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530257{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300258 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530259
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200260 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
261
Archit Tanejacea87b92012-09-07 17:56:20 +0530262 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530263
Archit Taneja275cfa12013-10-08 14:22:03 +0530264 hdmi_wp_video_stop(&hdmi.wp);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200265
266 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
267
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300268 hdmi_pll_disable(&hdmi.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300269
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300270 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530271}
272
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300273static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530274 struct omap_video_timings *timings)
275{
Archit Taneja1e676242013-12-09 19:39:08 +0530276 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530277
Archit Taneja1e676242013-12-09 19:39:08 +0530278 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
Mythri P Kc3198a52011-03-12 12:04:27 +0530279 return -EINVAL;
Mythri P Kc3198a52011-03-12 12:04:27 +0530280
281 return 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530282}
283
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300284static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530285 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530286{
Archit Tanejaed1aa902012-08-15 00:40:31 +0530287 mutex_lock(&hdmi.lock);
288
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300289 hdmi.cfg.timings = *timings;
Archit Taneja78493982012-08-08 16:50:42 +0530290
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300291 dispc_set_tv_pclk(timings->pixelclock);
Archit Taneja1e676242013-12-09 19:39:08 +0530292
Archit Tanejaed1aa902012-08-15 00:40:31 +0530293 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530294}
295
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300296static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300297 struct omap_video_timings *timings)
298{
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300299 *timings = hdmi.cfg.timings;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300300}
301
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200302static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530303{
304 mutex_lock(&hdmi.lock);
305
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800306 if (hdmi_runtime_get()) {
307 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530308 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800309 }
Mythri P K162874d2011-09-22 13:37:45 +0530310
Archit Taneja275cfa12013-10-08 14:22:03 +0530311 hdmi_wp_dump(&hdmi.wp, s);
312 hdmi_pll_dump(&hdmi.pll, s);
313 hdmi_phy_dump(&hdmi.phy, s);
314 hdmi4_core_dump(&hdmi.core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530315
316 hdmi_runtime_put();
317 mutex_unlock(&hdmi.lock);
318}
319
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300320static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300321{
322 int r;
323
324 mutex_lock(&hdmi.lock);
325
326 r = hdmi_runtime_get();
327 BUG_ON(r);
328
Archit Taneja275cfa12013-10-08 14:22:03 +0530329 r = hdmi4_read_edid(&hdmi.core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300330
331 hdmi_runtime_put();
332 mutex_unlock(&hdmi.lock);
333
334 return r;
335}
336
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300337static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530338{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300339 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530340 int r = 0;
341
342 DSSDBG("ENTER hdmi_display_enable\n");
343
344 mutex_lock(&hdmi.lock);
345
Archit Tanejacea87b92012-09-07 17:56:20 +0530346 if (out == NULL || out->manager == NULL) {
347 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300348 r = -ENODEV;
349 goto err0;
350 }
351
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300352 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530353 if (r) {
354 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300355 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530356 }
357
358 mutex_unlock(&hdmi.lock);
359 return 0;
360
Mythri P Kc3198a52011-03-12 12:04:27 +0530361err0:
362 mutex_unlock(&hdmi.lock);
363 return r;
364}
365
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300366static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530367{
368 DSSDBG("Enter hdmi_display_disable\n");
369
370 mutex_lock(&hdmi.lock);
371
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300372 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530373
Mythri P Kc3198a52011-03-12 12:04:27 +0530374 mutex_unlock(&hdmi.lock);
375}
376
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300377static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300378{
379 int r = 0;
380
381 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
382
383 mutex_lock(&hdmi.lock);
384
Tomi Valkeinen44898232012-10-19 17:42:27 +0300385 r = hdmi_power_on_core(dssdev);
386 if (r) {
387 DSSERR("failed to power on device\n");
388 goto err0;
389 }
390
391 mutex_unlock(&hdmi.lock);
392 return 0;
393
394err0:
395 mutex_unlock(&hdmi.lock);
396 return r;
397}
398
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300399static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300400{
401 DSSDBG("Enter omapdss_hdmi_core_disable\n");
402
403 mutex_lock(&hdmi.lock);
404
405 hdmi_power_off_core(dssdev);
406
407 mutex_unlock(&hdmi.lock);
408}
409
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300410static int hdmi_get_clocks(struct platform_device *pdev)
411{
412 struct clk *clk;
413
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300414 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300415 if (IS_ERR(clk)) {
416 DSSERR("can't get sys_clk\n");
417 return PTR_ERR(clk);
418 }
419
420 hdmi.sys_clk = clk;
421
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300422 return 0;
423}
424
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300425static int hdmi_connect(struct omap_dss_device *dssdev,
426 struct omap_dss_device *dst)
427{
428 struct omap_overlay_manager *mgr;
429 int r;
430
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300431 r = hdmi_init_regulator();
432 if (r)
433 return r;
434
435 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
436 if (!mgr)
437 return -ENODEV;
438
439 r = dss_mgr_connect(mgr, dssdev);
440 if (r)
441 return r;
442
443 r = omapdss_output_set_device(dssdev, dst);
444 if (r) {
445 DSSERR("failed to connect output to new device: %s\n",
446 dst->name);
447 dss_mgr_disconnect(mgr, dssdev);
448 return r;
449 }
450
451 return 0;
452}
453
454static void hdmi_disconnect(struct omap_dss_device *dssdev,
455 struct omap_dss_device *dst)
456{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300457 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300458
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300459 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300460 return;
461
462 omapdss_output_unset_device(dssdev);
463
464 if (dssdev->manager)
465 dss_mgr_disconnect(dssdev->manager, dssdev);
466}
467
468static int hdmi_read_edid(struct omap_dss_device *dssdev,
469 u8 *edid, int len)
470{
471 bool need_enable;
472 int r;
473
474 need_enable = hdmi.core_enabled == false;
475
476 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300477 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300478 if (r)
479 return r;
480 }
481
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300482 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300483
484 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300485 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300486
487 return r;
488}
489
490#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300491static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300492{
493 int r;
494
495 mutex_lock(&hdmi.lock);
496
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300497 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300498 r = -EPERM;
499 goto err;
500 }
501
Archit Taneja275cfa12013-10-08 14:22:03 +0530502 r = hdmi_wp_audio_enable(&hdmi.wp, true);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300503 if (r)
504 goto err;
505
506 mutex_unlock(&hdmi.lock);
507 return 0;
508
509err:
510 mutex_unlock(&hdmi.lock);
511 return r;
512}
513
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300514static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300515{
Archit Taneja275cfa12013-10-08 14:22:03 +0530516 hdmi_wp_audio_enable(&hdmi.wp, false);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300517}
518
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300519static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300520{
Archit Taneja275cfa12013-10-08 14:22:03 +0530521 return hdmi4_audio_start(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300522}
523
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300524static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300525{
Archit Taneja275cfa12013-10-08 14:22:03 +0530526 hdmi4_audio_stop(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300527}
528
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300529static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300530{
531 bool r;
532
533 mutex_lock(&hdmi.lock);
534
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300535 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300536
537 mutex_unlock(&hdmi.lock);
538 return r;
539}
540
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300541static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300542 struct omap_dss_audio *audio)
543{
544 int r;
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300545 u32 pclk = hdmi.cfg.timings.pixelclock;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300546
547 mutex_lock(&hdmi.lock);
548
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300549 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300550 r = -EPERM;
551 goto err;
552 }
553
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530554 r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300555 if (r)
556 goto err;
557
558 mutex_unlock(&hdmi.lock);
559 return 0;
560
561err:
562 mutex_unlock(&hdmi.lock);
563 return r;
564}
565#else
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300566static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300567{
568 return -EPERM;
569}
570
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300571static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300572{
573}
574
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300575static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300576{
577 return -EPERM;
578}
579
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300580static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300581{
582}
583
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300584static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300585{
586 return false;
587}
588
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300589static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300590 struct omap_dss_audio *audio)
591{
592 return -EPERM;
593}
594#endif
595
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300596static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
597 const struct hdmi_avi_infoframe *avi)
598{
599 hdmi.cfg.infoframe = *avi;
600 return 0;
601}
602
603static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
604 bool hdmi_mode)
605{
606 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
607 return 0;
608}
609
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300610static const struct omapdss_hdmi_ops hdmi_ops = {
611 .connect = hdmi_connect,
612 .disconnect = hdmi_disconnect,
613
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300614 .enable = hdmi_display_enable,
615 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300616
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300617 .check_timings = hdmi_display_check_timing,
618 .set_timings = hdmi_display_set_timing,
619 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300620
621 .read_edid = hdmi_read_edid,
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300622 .set_infoframe = hdmi_set_infoframe,
623 .set_hdmi_mode = hdmi_set_hdmi_mode,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300624
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300625 .audio_enable = hdmi_audio_enable,
626 .audio_disable = hdmi_audio_disable,
627 .audio_start = hdmi_audio_start,
628 .audio_stop = hdmi_audio_stop,
629 .audio_supported = hdmi_audio_supported,
630 .audio_config = hdmi_audio_config,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300631};
632
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300633static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530634{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300635 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530636
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300637 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530638 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300639 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200640 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200641 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300642 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300643 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530644
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300645 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530646}
647
648static void __exit hdmi_uninit_output(struct platform_device *pdev)
649{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300650 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530651
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300652 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530653}
654
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300655static int hdmi_probe_of(struct platform_device *pdev)
656{
657 struct device_node *node = pdev->dev.of_node;
658 struct device_node *ep;
659 int r;
660
661 ep = omapdss_of_get_first_endpoint(node);
662 if (!ep)
663 return 0;
664
665 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
666 if (r)
667 goto err;
668
669 of_node_put(ep);
670 return 0;
671
672err:
673 of_node_put(ep);
674 return r;
675}
676
Mythri P Kc3198a52011-03-12 12:04:27 +0530677/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300678static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530679{
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300680 int r;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200681 int irq;
Mythri P Kc3198a52011-03-12 12:04:27 +0530682
Mythri P Kc3198a52011-03-12 12:04:27 +0530683 hdmi.pdev = pdev;
684
685 mutex_init(&hdmi.lock);
686
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300687 if (pdev->dev.of_node) {
688 r = hdmi_probe_of(pdev);
689 if (r)
690 return r;
691 }
692
Archit Taneja275cfa12013-10-08 14:22:03 +0530693 r = hdmi_wp_init(pdev, &hdmi.wp);
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530694 if (r)
695 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530696
Tomi Valkeinen03aafa22014-10-16 15:31:38 +0300697 r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
Archit Tanejac1577c12013-10-08 12:55:26 +0530698 if (r)
699 return r;
700
Archit Taneja275cfa12013-10-08 14:22:03 +0530701 r = hdmi_phy_init(pdev, &hdmi.phy);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530702 if (r)
703 return r;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +0300704
Archit Taneja275cfa12013-10-08 14:22:03 +0530705 r = hdmi4_core_init(pdev, &hdmi.core);
Archit Taneja425f02f2013-10-08 14:16:05 +0530706 if (r)
707 return r;
708
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300709 r = hdmi_get_clocks(pdev);
710 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -0600711 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300712 return r;
713 }
714
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200715 irq = platform_get_irq(pdev, 0);
716 if (irq < 0) {
717 DSSERR("platform_get_irq failed\n");
718 return -ENODEV;
719 }
720
721 r = devm_request_threaded_irq(&pdev->dev, irq,
722 NULL, hdmi_irq_handler,
723 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
724 if (r) {
725 DSSERR("HDMI IRQ request failed\n");
726 return r;
727 }
728
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300729 pm_runtime_enable(&pdev->dev);
730
Tomi Valkeinen002d3682013-02-13 12:17:43 +0200731 hdmi_init_output(pdev);
732
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200733 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
734
Tomi Valkeinencca35012012-04-26 14:48:32 +0300735 return 0;
736}
737
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200738static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530739{
Archit Taneja81b87f52012-09-26 16:30:49 +0530740 hdmi_uninit_output(pdev);
741
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300742 pm_runtime_disable(&pdev->dev);
743
Mythri P Kc3198a52011-03-12 12:04:27 +0530744 return 0;
745}
746
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300747static int hdmi_runtime_suspend(struct device *dev)
748{
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530749 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300750
751 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300752
753 return 0;
754}
755
756static int hdmi_runtime_resume(struct device *dev)
757{
758 int r;
759
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300760 r = dispc_runtime_get();
761 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200762 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300763
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530764 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300765
766 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300767}
768
769static const struct dev_pm_ops hdmi_pm_ops = {
770 .runtime_suspend = hdmi_runtime_suspend,
771 .runtime_resume = hdmi_runtime_resume,
772};
773
Tomi Valkeinen04656162013-12-16 15:14:04 +0200774static const struct of_device_id hdmi_of_match[] = {
775 { .compatible = "ti,omap4-hdmi", },
776 {},
777};
778
Mythri P Kc3198a52011-03-12 12:04:27 +0530779static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300780 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200781 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +0530782 .driver = {
783 .name = "omapdss_hdmi",
784 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300785 .pm = &hdmi_pm_ops,
Tomi Valkeinen04656162013-12-16 15:14:04 +0200786 .of_match_table = hdmi_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300787 .suppress_bind_attrs = true,
Mythri P Kc3198a52011-03-12 12:04:27 +0530788 },
789};
790
Archit Tanejaef269582013-09-12 17:45:57 +0530791int __init hdmi4_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530792{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300793 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530794}
795
Archit Tanejaef269582013-09-12 17:45:57 +0530796void __exit hdmi4_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530797{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +0200798 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530799}