blob: f5f7944a1fd1d6521624e8d4a5f62971bac916ed [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 Valkeinene25001d2013-05-10 15:20:52 +030084static int hdmi_init_regulator(void)
85{
86 struct regulator *reg;
87
88 if (hdmi.vdda_hdmi_dac_reg != NULL)
89 return 0;
90
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +030091 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
Tomi Valkeinene25001d2013-05-10 15:20:52 +030092
93 if (IS_ERR(reg)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +020094 if (PTR_ERR(reg) != -EPROBE_DEFER)
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +030095 DSSERR("can't get VDDA regulator\n");
Tomi Valkeinene25001d2013-05-10 15:20:52 +030096 return PTR_ERR(reg);
97 }
98
99 hdmi.vdda_hdmi_dac_reg = reg;
100
101 return 0;
102}
103
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300104static int hdmi_power_on_core(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530105{
Mythri P K46095b22012-01-06 17:52:09 +0530106 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530107
Tomi Valkeinen17486942012-08-15 15:55:04 +0300108 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
109 if (r)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300110 return r;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300111
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300112 r = hdmi_runtime_get();
113 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300114 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530115
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300116 /* Make selection of HDMI in DSS */
117 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
118
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300119 hdmi.core_enabled = true;
120
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300121 return 0;
122
123err_runtime_get:
124 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300125
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300126 return r;
127}
128
129static void hdmi_power_off_core(struct omap_dss_device *dssdev)
130{
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300131 hdmi.core_enabled = false;
132
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300133 hdmi_runtime_put();
134 regulator_disable(hdmi.vdda_hdmi_dac_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300135}
136
137static int hdmi_power_on_full(struct omap_dss_device *dssdev)
138{
139 int r;
140 struct omap_video_timings *p;
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300141 struct omap_overlay_manager *mgr = hdmi.output.manager;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300142 unsigned long phy;
143
144 r = hdmi_power_on_core(dssdev);
145 if (r)
146 return r;
147
Archit Taneja275cfa12013-10-08 14:22:03 +0530148 p = &hdmi.cfg.timings;
Mythri P Kc3198a52011-03-12 12:04:27 +0530149
Archit Taneja78493982012-08-08 16:50:42 +0530150 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 +0530151
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300152 /* the functions below use kHz pixel clock. TODO: change to Hz */
153 phy = p->pixelclock / 1000;
Mythri P Kc3198a52011-03-12 12:04:27 +0530154
Archit Taneja275cfa12013-10-08 14:22:03 +0530155 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), phy);
Mythri P Kc3198a52011-03-12 12:04:27 +0530156
Mythri P K95a8aeb2011-09-08 19:06:18 +0530157 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
Archit Taneja275cfa12013-10-08 14:22:03 +0530158 r = hdmi_pll_enable(&hdmi.pll, &hdmi.wp);
Mythri P Kc3198a52011-03-12 12:04:27 +0530159 if (r) {
160 DSSDBG("Failed to lock PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300161 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530162 }
163
Archit Taneja275cfa12013-10-08 14:22:03 +0530164 r = hdmi_phy_enable(&hdmi.phy, &hdmi.wp, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530165 if (r) {
166 DSSDBG("Failed to start PHY\n");
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500167 goto err_phy_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530168 }
169
Archit Taneja275cfa12013-10-08 14:22:03 +0530170 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530171
Mythri P Kc3198a52011-03-12 12:04:27 +0530172 /* bypass TV gamma table */
173 dispc_enable_gamma_table(0);
174
175 /* tv size */
Archit Tanejacea87b92012-09-07 17:56:20 +0530176 dss_mgr_set_timings(mgr, p);
Mythri P Kc3198a52011-03-12 12:04:27 +0530177
Archit Taneja275cfa12013-10-08 14:22:03 +0530178 r = hdmi_wp_video_start(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500179 if (r)
180 goto err_vid_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530181
Archit Tanejacea87b92012-09-07 17:56:20 +0530182 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200183 if (r)
184 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300185
Mythri P Kc3198a52011-03-12 12:04:27 +0530186 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200187
188err_mgr_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530189 hdmi_wp_video_stop(&hdmi.wp);
Ricardo Neric0456be2012-04-27 13:48:45 -0500190err_vid_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530191 hdmi_phy_disable(&hdmi.phy, &hdmi.wp);
Ricardo Nerid3b4aa52012-07-30 19:12:02 -0500192err_phy_enable:
Archit Taneja275cfa12013-10-08 14:22:03 +0530193 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300194err_pll_enable:
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300195 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530196 return -EIO;
197}
198
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300199static void hdmi_power_off_full(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530200{
Tomi Valkeinen7ae9a712013-05-10 15:27:07 +0300201 struct omap_overlay_manager *mgr = hdmi.output.manager;
Archit Tanejacea87b92012-09-07 17:56:20 +0530202
203 dss_mgr_disable(mgr);
Mythri P Kc3198a52011-03-12 12:04:27 +0530204
Archit Taneja275cfa12013-10-08 14:22:03 +0530205 hdmi_wp_video_stop(&hdmi.wp);
206 hdmi_phy_disable(&hdmi.phy, &hdmi.wp);
207 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300208
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300209 hdmi_power_off_core(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530210}
211
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300212static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Mythri P Kc3198a52011-03-12 12:04:27 +0530213 struct omap_video_timings *timings)
214{
Archit Taneja1e676242013-12-09 19:39:08 +0530215 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530216
Archit Taneja1e676242013-12-09 19:39:08 +0530217 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
Mythri P Kc3198a52011-03-12 12:04:27 +0530218 return -EINVAL;
Mythri P Kc3198a52011-03-12 12:04:27 +0530219
220 return 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530221}
222
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300223static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Archit Taneja78493982012-08-08 16:50:42 +0530224 struct omap_video_timings *timings)
Mythri P Kc3198a52011-03-12 12:04:27 +0530225{
226 struct hdmi_cm cm;
Archit Taneja78493982012-08-08 16:50:42 +0530227 const struct hdmi_config *t;
Mythri P Kc3198a52011-03-12 12:04:27 +0530228
Archit Tanejaed1aa902012-08-15 00:40:31 +0530229 mutex_lock(&hdmi.lock);
230
Archit Taneja78493982012-08-08 16:50:42 +0530231 cm = hdmi_get_code(timings);
Archit Taneja275cfa12013-10-08 14:22:03 +0530232 hdmi.cfg.cm = cm;
Archit Taneja78493982012-08-08 16:50:42 +0530233
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530234 t = hdmi_get_timings(cm.mode, cm.code);
Tomi Valkeinendb680c62013-08-27 14:11:48 +0300235 if (t != NULL) {
Archit Taneja275cfa12013-10-08 14:22:03 +0530236 hdmi.cfg = *t;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300237
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300238 dispc_set_tv_pclk(t->timings.pixelclock);
Archit Taneja1e676242013-12-09 19:39:08 +0530239 } else {
240 hdmi.cfg.timings = *timings;
241 hdmi.cfg.cm.code = 0;
242 hdmi.cfg.cm.mode = HDMI_DVI;
243
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300244 dispc_set_tv_pclk(timings->pixelclock);
Tomi Valkeinendb680c62013-08-27 14:11:48 +0300245 }
Tomi Valkeinen5391e872013-05-16 10:44:13 +0300246
Archit Taneja1e676242013-12-09 19:39:08 +0530247 DSSDBG("using mode: %s, code %d\n", hdmi.cfg.cm.mode == HDMI_DVI ?
248 "DVI" : "HDMI", hdmi.cfg.cm.code);
249
Archit Tanejaed1aa902012-08-15 00:40:31 +0530250 mutex_unlock(&hdmi.lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530251}
252
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300253static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300254 struct omap_video_timings *timings)
255{
256 const struct hdmi_config *cfg;
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530257 struct hdmi_cm cm = hdmi.cfg.cm;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300258
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530259 cfg = hdmi_get_timings(cm.mode, cm.code);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300260 if (cfg == NULL)
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530261 cfg = hdmi_default_timing();
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300262
263 memcpy(timings, &cfg->timings, sizeof(cfg->timings));
264}
265
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200266static void hdmi_dump_regs(struct seq_file *s)
Mythri P K162874d2011-09-22 13:37:45 +0530267{
268 mutex_lock(&hdmi.lock);
269
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800270 if (hdmi_runtime_get()) {
271 mutex_unlock(&hdmi.lock);
Mythri P K162874d2011-09-22 13:37:45 +0530272 return;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800273 }
Mythri P K162874d2011-09-22 13:37:45 +0530274
Archit Taneja275cfa12013-10-08 14:22:03 +0530275 hdmi_wp_dump(&hdmi.wp, s);
276 hdmi_pll_dump(&hdmi.pll, s);
277 hdmi_phy_dump(&hdmi.phy, s);
278 hdmi4_core_dump(&hdmi.core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530279
280 hdmi_runtime_put();
281 mutex_unlock(&hdmi.lock);
282}
283
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300284static int read_edid(u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300285{
286 int r;
287
288 mutex_lock(&hdmi.lock);
289
290 r = hdmi_runtime_get();
291 BUG_ON(r);
292
Archit Taneja275cfa12013-10-08 14:22:03 +0530293 r = hdmi4_read_edid(&hdmi.core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300294
295 hdmi_runtime_put();
296 mutex_unlock(&hdmi.lock);
297
298 return r;
299}
300
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300301static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530302{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300303 struct omap_dss_device *out = &hdmi.output;
Mythri P Kc3198a52011-03-12 12:04:27 +0530304 int r = 0;
305
306 DSSDBG("ENTER hdmi_display_enable\n");
307
308 mutex_lock(&hdmi.lock);
309
Archit Tanejacea87b92012-09-07 17:56:20 +0530310 if (out == NULL || out->manager == NULL) {
311 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300312 r = -ENODEV;
313 goto err0;
314 }
315
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300316 r = hdmi_power_on_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530317 if (r) {
318 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300319 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530320 }
321
322 mutex_unlock(&hdmi.lock);
323 return 0;
324
Mythri P Kc3198a52011-03-12 12:04:27 +0530325err0:
326 mutex_unlock(&hdmi.lock);
327 return r;
328}
329
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300330static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530331{
332 DSSDBG("Enter hdmi_display_disable\n");
333
334 mutex_lock(&hdmi.lock);
335
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300336 hdmi_power_off_full(dssdev);
Mythri P Kc3198a52011-03-12 12:04:27 +0530337
Mythri P Kc3198a52011-03-12 12:04:27 +0530338 mutex_unlock(&hdmi.lock);
339}
340
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300341static int hdmi_core_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300342{
343 int r = 0;
344
345 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
346
347 mutex_lock(&hdmi.lock);
348
Tomi Valkeinen44898232012-10-19 17:42:27 +0300349 r = hdmi_power_on_core(dssdev);
350 if (r) {
351 DSSERR("failed to power on device\n");
352 goto err0;
353 }
354
355 mutex_unlock(&hdmi.lock);
356 return 0;
357
358err0:
359 mutex_unlock(&hdmi.lock);
360 return r;
361}
362
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300363static void hdmi_core_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300364{
365 DSSDBG("Enter omapdss_hdmi_core_disable\n");
366
367 mutex_lock(&hdmi.lock);
368
369 hdmi_power_off_core(dssdev);
370
371 mutex_unlock(&hdmi.lock);
372}
373
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300374static int hdmi_get_clocks(struct platform_device *pdev)
375{
376 struct clk *clk;
377
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300378 clk = devm_clk_get(&pdev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300379 if (IS_ERR(clk)) {
380 DSSERR("can't get sys_clk\n");
381 return PTR_ERR(clk);
382 }
383
384 hdmi.sys_clk = clk;
385
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300386 return 0;
387}
388
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300389static int hdmi_connect(struct omap_dss_device *dssdev,
390 struct omap_dss_device *dst)
391{
392 struct omap_overlay_manager *mgr;
393 int r;
394
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300395 r = hdmi_init_regulator();
396 if (r)
397 return r;
398
399 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
400 if (!mgr)
401 return -ENODEV;
402
403 r = dss_mgr_connect(mgr, dssdev);
404 if (r)
405 return r;
406
407 r = omapdss_output_set_device(dssdev, dst);
408 if (r) {
409 DSSERR("failed to connect output to new device: %s\n",
410 dst->name);
411 dss_mgr_disconnect(mgr, dssdev);
412 return r;
413 }
414
415 return 0;
416}
417
418static void hdmi_disconnect(struct omap_dss_device *dssdev,
419 struct omap_dss_device *dst)
420{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300421 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300422
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300423 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300424 return;
425
426 omapdss_output_unset_device(dssdev);
427
428 if (dssdev->manager)
429 dss_mgr_disconnect(dssdev->manager, dssdev);
430}
431
432static int hdmi_read_edid(struct omap_dss_device *dssdev,
433 u8 *edid, int len)
434{
435 bool need_enable;
436 int r;
437
438 need_enable = hdmi.core_enabled == false;
439
440 if (need_enable) {
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300441 r = hdmi_core_enable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300442 if (r)
443 return r;
444 }
445
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300446 r = read_edid(edid, len);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300447
448 if (need_enable)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300449 hdmi_core_disable(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300450
451 return r;
452}
453
454#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300455static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300456{
457 int r;
458
459 mutex_lock(&hdmi.lock);
460
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530461 if (!hdmi_mode_has_audio(hdmi.cfg.cm.mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300462 r = -EPERM;
463 goto err;
464 }
465
Archit Taneja275cfa12013-10-08 14:22:03 +0530466 r = hdmi_wp_audio_enable(&hdmi.wp, true);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300467 if (r)
468 goto err;
469
470 mutex_unlock(&hdmi.lock);
471 return 0;
472
473err:
474 mutex_unlock(&hdmi.lock);
475 return r;
476}
477
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300478static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300479{
Archit Taneja275cfa12013-10-08 14:22:03 +0530480 hdmi_wp_audio_enable(&hdmi.wp, false);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300481}
482
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300483static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300484{
Archit Taneja275cfa12013-10-08 14:22:03 +0530485 return hdmi4_audio_start(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300486}
487
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300488static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300489{
Archit Taneja275cfa12013-10-08 14:22:03 +0530490 hdmi4_audio_stop(&hdmi.core, &hdmi.wp);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300491}
492
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300493static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300494{
495 bool r;
496
497 mutex_lock(&hdmi.lock);
498
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530499 r = hdmi_mode_has_audio(hdmi.cfg.cm.mode);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300500
501 mutex_unlock(&hdmi.lock);
502 return r;
503}
504
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300505static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300506 struct omap_dss_audio *audio)
507{
508 int r;
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300509 u32 pclk = hdmi.cfg.timings.pixelclock;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300510
511 mutex_lock(&hdmi.lock);
512
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530513 if (!hdmi_mode_has_audio(hdmi.cfg.cm.mode)) {
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300514 r = -EPERM;
515 goto err;
516 }
517
Archit Taneja08d83e4e2013-09-17 11:43:15 +0530518 r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300519 if (r)
520 goto err;
521
522 mutex_unlock(&hdmi.lock);
523 return 0;
524
525err:
526 mutex_unlock(&hdmi.lock);
527 return r;
528}
529#else
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300530static int hdmi_audio_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300531{
532 return -EPERM;
533}
534
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300535static void hdmi_audio_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300536{
537}
538
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300539static int hdmi_audio_start(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300540{
541 return -EPERM;
542}
543
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300544static void hdmi_audio_stop(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300545{
546}
547
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300548static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300549{
550 return false;
551}
552
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300553static int hdmi_audio_config(struct omap_dss_device *dssdev,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300554 struct omap_dss_audio *audio)
555{
556 return -EPERM;
557}
558#endif
559
560static const struct omapdss_hdmi_ops hdmi_ops = {
561 .connect = hdmi_connect,
562 .disconnect = hdmi_disconnect,
563
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300564 .enable = hdmi_display_enable,
565 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300566
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300567 .check_timings = hdmi_display_check_timing,
568 .set_timings = hdmi_display_set_timing,
569 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300570
571 .read_edid = hdmi_read_edid,
572
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300573 .audio_enable = hdmi_audio_enable,
574 .audio_disable = hdmi_audio_disable,
575 .audio_start = hdmi_audio_start,
576 .audio_stop = hdmi_audio_stop,
577 .audio_supported = hdmi_audio_supported,
578 .audio_config = hdmi_audio_config,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300579};
580
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300581static void hdmi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530582{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300583 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530584
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300585 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530586 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300587 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200588 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200589 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300590 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300591 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530592
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300593 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530594}
595
596static void __exit hdmi_uninit_output(struct platform_device *pdev)
597{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300598 struct omap_dss_device *out = &hdmi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530599
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300600 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530601}
602
Mythri P Kc3198a52011-03-12 12:04:27 +0530603/* HDMI HW IP initialisation */
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300604static int omapdss_hdmihw_probe(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530605{
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300606 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530607
Mythri P Kc3198a52011-03-12 12:04:27 +0530608 hdmi.pdev = pdev;
609
610 mutex_init(&hdmi.lock);
611
Archit Taneja275cfa12013-10-08 14:22:03 +0530612 r = hdmi_wp_init(pdev, &hdmi.wp);
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530613 if (r)
614 return r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530615
Archit Taneja275cfa12013-10-08 14:22:03 +0530616 r = hdmi_pll_init(pdev, &hdmi.pll);
Archit Tanejac1577c12013-10-08 12:55:26 +0530617 if (r)
618 return r;
619
Archit Taneja275cfa12013-10-08 14:22:03 +0530620 r = hdmi_phy_init(pdev, &hdmi.phy);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530621 if (r)
622 return r;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +0300623
Archit Taneja275cfa12013-10-08 14:22:03 +0530624 r = hdmi4_core_init(pdev, &hdmi.core);
Archit Taneja425f02f2013-10-08 14:16:05 +0530625 if (r)
626 return r;
627
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300628 r = hdmi_get_clocks(pdev);
629 if (r) {
Ricardo Neri47e443b2012-11-06 00:19:12 -0600630 DSSERR("can't get clocks\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300631 return r;
632 }
633
634 pm_runtime_enable(&pdev->dev);
635
Tomi Valkeinen002d3682013-02-13 12:17:43 +0200636 hdmi_init_output(pdev);
637
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200638 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
639
Tomi Valkeinencca35012012-04-26 14:48:32 +0300640 return 0;
641}
642
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200643static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530644{
Archit Taneja81b87f52012-09-26 16:30:49 +0530645 hdmi_uninit_output(pdev);
646
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300647 pm_runtime_disable(&pdev->dev);
648
Mythri P Kc3198a52011-03-12 12:04:27 +0530649 return 0;
650}
651
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300652static int hdmi_runtime_suspend(struct device *dev)
653{
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530654 clk_disable_unprepare(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300655
656 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300657
658 return 0;
659}
660
661static int hdmi_runtime_resume(struct device *dev)
662{
663 int r;
664
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300665 r = dispc_runtime_get();
666 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200667 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300668
Rajendra Nayakf11766d2012-06-27 14:21:26 +0530669 clk_prepare_enable(hdmi.sys_clk);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300670
671 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300672}
673
674static const struct dev_pm_ops hdmi_pm_ops = {
675 .runtime_suspend = hdmi_runtime_suspend,
676 .runtime_resume = hdmi_runtime_resume,
677};
678
Tomi Valkeinen04656162013-12-16 15:14:04 +0200679static const struct of_device_id hdmi_of_match[] = {
680 { .compatible = "ti,omap4-hdmi", },
681 {},
682};
683
Mythri P Kc3198a52011-03-12 12:04:27 +0530684static struct platform_driver omapdss_hdmihw_driver = {
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300685 .probe = omapdss_hdmihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200686 .remove = __exit_p(omapdss_hdmihw_remove),
Mythri P Kc3198a52011-03-12 12:04:27 +0530687 .driver = {
688 .name = "omapdss_hdmi",
689 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300690 .pm = &hdmi_pm_ops,
Tomi Valkeinen04656162013-12-16 15:14:04 +0200691 .of_match_table = hdmi_of_match,
Mythri P Kc3198a52011-03-12 12:04:27 +0530692 },
693};
694
Archit Tanejaef269582013-09-12 17:45:57 +0530695int __init hdmi4_init_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530696{
Tomi Valkeinen17ae4e82013-04-26 14:48:43 +0300697 return platform_driver_register(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530698}
699
Archit Tanejaef269582013-09-12 17:45:57 +0530700void __exit hdmi4_uninit_platform_driver(void)
Mythri P Kc3198a52011-03-12 12:04:27 +0530701{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +0200702 platform_driver_unregister(&omapdss_hdmihw_driver);
Mythri P Kc3198a52011-03-12 12:04:27 +0530703}