blob: 5879f45f6fc9bb5889f80884b7a352fcb6836363 [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.
Andrew F. Davisbb5cdf82017-12-05 14:29:31 -06003 *
Mythri P Kc3198a52011-03-12 12:04:27 +05304 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
5 * Authors: Yong Zhi
6 * Mythri pk <mythripk@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#define DSS_SUBSYS_NAME "HDMI"
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/err.h>
26#include <linux/io.h>
27#include <linux/interrupt.h>
28#include <linux/mutex.h>
29#include <linux/delay.h>
30#include <linux/string.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030031#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030032#include <linux/pm_runtime.h>
33#include <linux/clk.h>
Tomi Valkeinencca35012012-04-26 14:48:32 +030034#include <linux/gpio.h>
Tomi Valkeinen17486942012-08-15 15:55:04 +030035#include <linux/regulator/consumer.h>
Tomi Valkeinen736e60d2015-06-04 15:22:23 +030036#include <linux/component.h>
Tomi Valkeinend9e32ec2016-03-18 09:02:18 +020037#include <linux/of.h>
Rob Herring09bffa62017-03-22 08:26:08 -050038#include <linux/of_graph.h>
Jyri Sarha4d594df2014-05-23 12:48:28 +030039#include <sound/omap-hdmi-audio.h>
Hans Verkuil1897e1a2017-08-02 10:54:07 +020040#include <media/cec.h>
Mythri P Kc3198a52011-03-12 12:04:27 +053041
Peter Ujfalusi32043da2016-05-27 14:40:49 +030042#include "omapdss.h"
Archit Tanejaef269582013-09-12 17:45:57 +053043#include "hdmi4_core.h"
Hans Verkuil1897e1a2017-08-02 10:54:07 +020044#include "hdmi4_cec.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053045#include "dss.h"
Jyri Sarha945514b2014-06-27 16:47:00 +030046#include "hdmi.h"
Mythri P Kc3198a52011-03-12 12:04:27 +053047
Laurent Pinchartac767452018-02-13 14:00:45 +020048static int hdmi_runtime_get(struct omap_hdmi *hdmi)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030049{
50 int r;
51
52 DSSDBG("hdmi_runtime_get\n");
53
Laurent Pinchartac767452018-02-13 14:00:45 +020054 r = pm_runtime_get_sync(&hdmi->pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030055 WARN_ON(r < 0);
Archit Tanejaa247ce782012-02-10 11:45:52 +053056 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +020057 return r;
Archit Tanejaa247ce782012-02-10 11:45:52 +053058
59 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030060}
61
Laurent Pinchartac767452018-02-13 14:00:45 +020062static void hdmi_runtime_put(struct omap_hdmi *hdmi)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030063{
64 int r;
65
66 DSSDBG("hdmi_runtime_put\n");
67
Laurent Pinchartac767452018-02-13 14:00:45 +020068 r = pm_runtime_put_sync(&hdmi->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +030069 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030070}
71
Tomi Valkeinendcf5f722013-10-28 11:47:34 +020072static irqreturn_t hdmi_irq_handler(int irq, void *data)
73{
Hans Verkuilf3096a42017-08-02 10:54:03 +020074 struct omap_hdmi *hdmi = data;
75 struct hdmi_wp_data *wp = &hdmi->wp;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +020076 u32 irqstatus;
77
78 irqstatus = hdmi_wp_get_irqstatus(wp);
79 hdmi_wp_set_irqstatus(wp, irqstatus);
80
81 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
82 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
83 /*
84 * If we get both connect and disconnect interrupts at the same
85 * time, turn off the PHY, clear interrupts, and restart, which
86 * raises connect interrupt if a cable is connected, or nothing
87 * if cable is not connected.
88 */
89 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
90
91 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
92 HDMI_IRQ_LINK_DISCONNECT);
93
94 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
95 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
96 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
97 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
98 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
99 }
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200100 if (irqstatus & HDMI_IRQ_CORE) {
101 u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4);
102
103 hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4);
104 if (intr4 & 8)
105 hdmi4_cec_irq(&hdmi->core);
106 }
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200107
108 return IRQ_HANDLED;
109}
110
Laurent Pinchartac767452018-02-13 14:00:45 +0200111static int hdmi_init_regulator(struct omap_hdmi *hdmi)
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300112{
113 struct regulator *reg;
114
Laurent Pinchartac767452018-02-13 14:00:45 +0200115 if (hdmi->vdda_reg != NULL)
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300116 return 0;
117
Laurent Pinchartac767452018-02-13 14:00:45 +0200118 reg = devm_regulator_get(&hdmi->pdev->dev, "vdda");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300119
120 if (IS_ERR(reg)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200121 if (PTR_ERR(reg) != -EPROBE_DEFER)
Tomi Valkeinen931d4bd2013-06-10 14:05:10 +0300122 DSSERR("can't get VDDA regulator\n");
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300123 return PTR_ERR(reg);
124 }
125
Laurent Pinchartac767452018-02-13 14:00:45 +0200126 hdmi->vdda_reg = reg;
Tomi Valkeinene25001d2013-05-10 15:20:52 +0300127
128 return 0;
129}
130
Laurent Pinchartac767452018-02-13 14:00:45 +0200131static int hdmi_power_on_core(struct omap_hdmi *hdmi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530132{
Mythri P K46095b22012-01-06 17:52:09 +0530133 int r;
Mythri P Kc3198a52011-03-12 12:04:27 +0530134
Laurent Pinchartac767452018-02-13 14:00:45 +0200135 if (hdmi->core.core_pwr_cnt++)
Hans Verkuila141a292017-08-02 10:54:05 +0200136 return 0;
137
Laurent Pinchartac767452018-02-13 14:00:45 +0200138 r = regulator_enable(hdmi->vdda_reg);
Tomi Valkeinen17486942012-08-15 15:55:04 +0300139 if (r)
Hans Verkuila141a292017-08-02 10:54:05 +0200140 goto err_reg_enable;
Tomi Valkeinen17486942012-08-15 15:55:04 +0300141
Laurent Pinchartac767452018-02-13 14:00:45 +0200142 r = hdmi_runtime_get(hdmi);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300143 if (r)
Tomi Valkeinencca35012012-04-26 14:48:32 +0300144 goto err_runtime_get;
Mythri P Kc3198a52011-03-12 12:04:27 +0530145
Laurent Pinchartac767452018-02-13 14:00:45 +0200146 hdmi4_core_powerdown_disable(&hdmi->core);
Hans Verkuil1d54ecf2017-08-02 10:54:04 +0200147
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300148 /* Make selection of HDMI in DSS */
Laurent Pinchartac767452018-02-13 14:00:45 +0200149 dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300150
Laurent Pinchartac767452018-02-13 14:00:45 +0200151 hdmi->core_enabled = true;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300152
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300153 return 0;
154
155err_runtime_get:
Laurent Pinchartac767452018-02-13 14:00:45 +0200156 regulator_disable(hdmi->vdda_reg);
Hans Verkuila141a292017-08-02 10:54:05 +0200157err_reg_enable:
Laurent Pinchartac767452018-02-13 14:00:45 +0200158 hdmi->core.core_pwr_cnt--;
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300159
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300160 return r;
161}
162
Laurent Pinchartac767452018-02-13 14:00:45 +0200163static void hdmi_power_off_core(struct omap_hdmi *hdmi)
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300164{
Laurent Pinchartac767452018-02-13 14:00:45 +0200165 if (--hdmi->core.core_pwr_cnt)
Hans Verkuila141a292017-08-02 10:54:05 +0200166 return;
167
Laurent Pinchartac767452018-02-13 14:00:45 +0200168 hdmi->core_enabled = false;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300169
Laurent Pinchartac767452018-02-13 14:00:45 +0200170 hdmi_runtime_put(hdmi);
171 regulator_disable(hdmi->vdda_reg);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300172}
173
Laurent Pinchartac767452018-02-13 14:00:45 +0200174static int hdmi_power_on_full(struct omap_hdmi *hdmi)
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300175{
176 int r;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300177 struct videomode *vm;
Laurent Pinchartac767452018-02-13 14:00:45 +0200178 struct hdmi_wp_data *wp = &hdmi->wp;
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300179 struct dss_pll_clock_info hdmi_cinfo = { 0 };
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200180 unsigned int pc;
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300181
Laurent Pinchartac767452018-02-13 14:00:45 +0200182 r = hdmi_power_on_core(hdmi);
Tomi Valkeinenbb426fc92012-10-19 17:42:10 +0300183 if (r)
184 return r;
185
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200186 /* disable and clear irqs */
Hans Verkuilf3096a42017-08-02 10:54:03 +0200187 hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE);
188 hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200189
Laurent Pinchartac767452018-02-13 14:00:45 +0200190 vm = &hdmi->cfg.vm;
Mythri P Kc3198a52011-03-12 12:04:27 +0530191
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300192 DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive,
193 vm->vactive);
Mythri P Kc3198a52011-03-12 12:04:27 +0530194
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300195 pc = vm->pixelclock;
196 if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
Tomi Valkeinen67d8ffd2016-01-13 18:41:33 +0200197 pc *= 2;
198
Tomi Valkeinenc1077512016-05-18 11:15:21 +0300199 /* DSS_HDMI_TCLK is bitclk / 10 */
200 pc *= 10;
201
Laurent Pinchartac767452018-02-13 14:00:45 +0200202 dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin),
Tomi Valkeinenc17dc0e2016-05-18 10:45:20 +0300203 pc, &hdmi_cinfo);
Mythri P Kc3198a52011-03-12 12:04:27 +0530204
Laurent Pinchartac767452018-02-13 14:00:45 +0200205 r = dss_pll_enable(&hdmi->pll.pll);
Mythri P Kc3198a52011-03-12 12:04:27 +0530206 if (r) {
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300207 DSSERR("Failed to enable PLL\n");
Tomi Valkeinencca35012012-04-26 14:48:32 +0300208 goto err_pll_enable;
Mythri P Kc3198a52011-03-12 12:04:27 +0530209 }
210
Laurent Pinchartac767452018-02-13 14:00:45 +0200211 r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo);
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300212 if (r) {
213 DSSERR("Failed to configure PLL\n");
214 goto err_pll_cfg;
215 }
216
Laurent Pinchartac767452018-02-13 14:00:45 +0200217 r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco,
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300218 hdmi_cinfo.clkout[0]);
Mythri P Kc3198a52011-03-12 12:04:27 +0530219 if (r) {
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200220 DSSDBG("Failed to configure PHY\n");
221 goto err_phy_cfg;
Mythri P Kc3198a52011-03-12 12:04:27 +0530222 }
223
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200224 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
225 if (r)
226 goto err_phy_pwr;
227
Laurent Pinchartac767452018-02-13 14:00:45 +0200228 hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
Mythri P Kc3198a52011-03-12 12:04:27 +0530229
Mythri P Kc3198a52011-03-12 12:04:27 +0530230 /* tv size */
Laurent Pinchartac767452018-02-13 14:00:45 +0200231 dss_mgr_set_timings(&hdmi->output, vm);
Mythri P Kc3198a52011-03-12 12:04:27 +0530232
Laurent Pinchartac767452018-02-13 14:00:45 +0200233 r = dss_mgr_enable(&hdmi->output);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200234 if (r)
235 goto err_mgr_enable;
Tomi Valkeinen3870c902011-08-31 14:47:11 +0300236
Laurent Pinchartac767452018-02-13 14:00:45 +0200237 r = hdmi_wp_video_start(&hdmi->wp);
Tomi Valkeinen4e4b53c2015-03-24 15:46:35 +0200238 if (r)
239 goto err_vid_enable;
240
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200241 hdmi_wp_set_irqenable(wp,
242 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
243
Mythri P Kc3198a52011-03-12 12:04:27 +0530244 return 0;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200245
Ricardo Neric0456be2012-04-27 13:48:45 -0500246err_vid_enable:
Laurent Pinchartac767452018-02-13 14:00:45 +0200247 dss_mgr_disable(&hdmi->output);
Tomi Valkeinen4e4b53c2015-03-24 15:46:35 +0200248err_mgr_enable:
Laurent Pinchartac767452018-02-13 14:00:45 +0200249 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200250err_phy_pwr:
Tomi Valkeinen9bba13f2015-03-24 15:46:33 +0200251err_phy_cfg:
Tomi Valkeinenc2fbd062014-10-16 16:01:51 +0300252err_pll_cfg:
Laurent Pinchartac767452018-02-13 14:00:45 +0200253 dss_pll_disable(&hdmi->pll.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300254err_pll_enable:
Laurent Pinchartac767452018-02-13 14:00:45 +0200255 hdmi_power_off_core(hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530256 return -EIO;
257}
258
Laurent Pinchartac767452018-02-13 14:00:45 +0200259static void hdmi_power_off_full(struct omap_hdmi *hdmi)
Mythri P Kc3198a52011-03-12 12:04:27 +0530260{
Laurent Pinchartac767452018-02-13 14:00:45 +0200261 hdmi_wp_clear_irqenable(&hdmi->wp, ~HDMI_IRQ_CORE);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200262
Laurent Pinchartac767452018-02-13 14:00:45 +0200263 hdmi_wp_video_stop(&hdmi->wp);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200264
Laurent Pinchartac767452018-02-13 14:00:45 +0200265 dss_mgr_disable(&hdmi->output);
Tomi Valkeinen4e4b53c2015-03-24 15:46:35 +0200266
Laurent Pinchartac767452018-02-13 14:00:45 +0200267 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200268
Laurent Pinchartac767452018-02-13 14:00:45 +0200269 dss_pll_disable(&hdmi->pll.pll);
Tomi Valkeinencca35012012-04-26 14:48:32 +0300270
Laurent Pinchartac767452018-02-13 14:00:45 +0200271 hdmi_power_off_core(hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530272}
273
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300274static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300275 struct videomode *vm)
Mythri P Kc3198a52011-03-12 12:04:27 +0530276{
Laurent Pinchartac767452018-02-13 14:00:45 +0200277 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
278
279 if (!dispc_mgr_timings_ok(hdmi->dss->dispc, dssdev->dispc_channel, vm))
Mythri P Kc3198a52011-03-12 12:04:27 +0530280 return -EINVAL;
Mythri P Kc3198a52011-03-12 12:04:27 +0530281
282 return 0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530283}
284
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300285static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300286 struct videomode *vm)
Mythri P Kc3198a52011-03-12 12:04:27 +0530287{
Laurent Pinchartac767452018-02-13 14:00:45 +0200288 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
Archit Tanejaed1aa902012-08-15 00:40:31 +0530289
Laurent Pinchartac767452018-02-13 14:00:45 +0200290 mutex_lock(&hdmi->lock);
Archit Taneja78493982012-08-08 16:50:42 +0530291
Laurent Pinchartac767452018-02-13 14:00:45 +0200292 hdmi->cfg.vm = *vm;
Archit Taneja1e676242013-12-09 19:39:08 +0530293
Laurent Pinchartac767452018-02-13 14:00:45 +0200294 dispc_set_tv_pclk(hdmi->dss->dispc, vm->pixelclock);
295
296 mutex_unlock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530297}
298
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300299static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300300 struct videomode *vm)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300301{
Laurent Pinchartac767452018-02-13 14:00:45 +0200302 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
303
304 *vm = hdmi->cfg.vm;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300305}
306
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200307static int hdmi_dump_regs(struct seq_file *s, void *p)
Mythri P K162874d2011-09-22 13:37:45 +0530308{
Laurent Pinchartac767452018-02-13 14:00:45 +0200309 struct omap_hdmi *hdmi = s->private;
Mythri P K162874d2011-09-22 13:37:45 +0530310
Laurent Pinchartac767452018-02-13 14:00:45 +0200311 mutex_lock(&hdmi->lock);
312
313 if (hdmi_runtime_get(hdmi)) {
314 mutex_unlock(&hdmi->lock);
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200315 return 0;
Wei Yongjunf8fb7d72012-10-21 20:54:26 +0800316 }
Mythri P K162874d2011-09-22 13:37:45 +0530317
Laurent Pinchartac767452018-02-13 14:00:45 +0200318 hdmi_wp_dump(&hdmi->wp, s);
319 hdmi_pll_dump(&hdmi->pll, s);
320 hdmi_phy_dump(&hdmi->phy, s);
321 hdmi4_core_dump(&hdmi->core, s);
Mythri P K162874d2011-09-22 13:37:45 +0530322
Laurent Pinchartac767452018-02-13 14:00:45 +0200323 hdmi_runtime_put(hdmi);
324 mutex_unlock(&hdmi->lock);
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200325 return 0;
Mythri P K162874d2011-09-22 13:37:45 +0530326}
327
Laurent Pinchartac767452018-02-13 14:00:45 +0200328static int read_edid(struct omap_hdmi *hdmi, u8 *buf, int len)
Tomi Valkeinen47024562011-08-25 17:12:56 +0300329{
330 int r;
331
Laurent Pinchartac767452018-02-13 14:00:45 +0200332 mutex_lock(&hdmi->lock);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300333
Laurent Pinchartac767452018-02-13 14:00:45 +0200334 r = hdmi_runtime_get(hdmi);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300335 BUG_ON(r);
336
Laurent Pinchartac767452018-02-13 14:00:45 +0200337 r = hdmi4_read_edid(&hdmi->core, buf, len);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300338
Laurent Pinchartac767452018-02-13 14:00:45 +0200339 hdmi_runtime_put(hdmi);
340 mutex_unlock(&hdmi->lock);
Tomi Valkeinen47024562011-08-25 17:12:56 +0300341
342 return r;
343}
344
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300345static void hdmi_start_audio_stream(struct omap_hdmi *hd)
346{
347 hdmi_wp_audio_enable(&hd->wp, true);
348 hdmi4_audio_start(&hd->core, &hd->wp);
349}
350
351static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
352{
353 hdmi4_audio_stop(&hd->core, &hd->wp);
354 hdmi_wp_audio_enable(&hd->wp, false);
355}
356
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300357static int hdmi_display_enable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530358{
Laurent Pinchartac767452018-02-13 14:00:45 +0200359 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300360 unsigned long flags;
Mythri P Kc3198a52011-03-12 12:04:27 +0530361 int r = 0;
362
363 DSSDBG("ENTER hdmi_display_enable\n");
364
Laurent Pinchartac767452018-02-13 14:00:45 +0200365 mutex_lock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530366
Laurent Pinchartac767452018-02-13 14:00:45 +0200367 if (!dssdev->dispc_channel_connected) {
Archit Tanejacea87b92012-09-07 17:56:20 +0530368 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300369 r = -ENODEV;
370 goto err0;
371 }
372
Laurent Pinchartac767452018-02-13 14:00:45 +0200373 r = hdmi_power_on_full(hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530374 if (r) {
375 DSSERR("failed to power on device\n");
Tomi Valkeinend3923932013-04-25 13:12:07 +0300376 goto err0;
Mythri P Kc3198a52011-03-12 12:04:27 +0530377 }
378
Laurent Pinchartac767452018-02-13 14:00:45 +0200379 if (hdmi->audio_configured) {
380 r = hdmi4_audio_config(&hdmi->core, &hdmi->wp,
381 &hdmi->audio_config,
382 hdmi->cfg.vm.pixelclock);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300383 if (r) {
384 DSSERR("Error restoring audio configuration: %d", r);
Laurent Pinchartac767452018-02-13 14:00:45 +0200385 hdmi->audio_abort_cb(&hdmi->pdev->dev);
386 hdmi->audio_configured = false;
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300387 }
388 }
389
Laurent Pinchartac767452018-02-13 14:00:45 +0200390 spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
391 if (hdmi->audio_configured && hdmi->audio_playing)
392 hdmi_start_audio_stream(hdmi);
393 hdmi->display_enabled = true;
394 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300395
Laurent Pinchartac767452018-02-13 14:00:45 +0200396 mutex_unlock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530397 return 0;
398
Mythri P Kc3198a52011-03-12 12:04:27 +0530399err0:
Laurent Pinchartac767452018-02-13 14:00:45 +0200400 mutex_unlock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530401 return r;
402}
403
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300404static void hdmi_display_disable(struct omap_dss_device *dssdev)
Mythri P Kc3198a52011-03-12 12:04:27 +0530405{
Laurent Pinchartac767452018-02-13 14:00:45 +0200406 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300407 unsigned long flags;
408
Mythri P Kc3198a52011-03-12 12:04:27 +0530409 DSSDBG("Enter hdmi_display_disable\n");
410
Laurent Pinchartac767452018-02-13 14:00:45 +0200411 mutex_lock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530412
Laurent Pinchartac767452018-02-13 14:00:45 +0200413 spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
414 hdmi_stop_audio_stream(hdmi);
415 hdmi->display_enabled = false;
416 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300417
Laurent Pinchartac767452018-02-13 14:00:45 +0200418 hdmi_power_off_full(hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530419
Laurent Pinchartac767452018-02-13 14:00:45 +0200420 mutex_unlock(&hdmi->lock);
Mythri P Kc3198a52011-03-12 12:04:27 +0530421}
422
Laurent Pinchartac767452018-02-13 14:00:45 +0200423int hdmi4_core_enable(struct hdmi_core_data *core)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300424{
Laurent Pinchartac767452018-02-13 14:00:45 +0200425 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300426 int r = 0;
427
Hans Verkuil5bebbbf2017-08-02 10:54:02 +0200428 DSSDBG("ENTER omapdss_hdmi4_core_enable\n");
Tomi Valkeinen44898232012-10-19 17:42:27 +0300429
Laurent Pinchartac767452018-02-13 14:00:45 +0200430 mutex_lock(&hdmi->lock);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300431
Laurent Pinchartac767452018-02-13 14:00:45 +0200432 r = hdmi_power_on_core(hdmi);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300433 if (r) {
434 DSSERR("failed to power on device\n");
435 goto err0;
436 }
437
Laurent Pinchartac767452018-02-13 14:00:45 +0200438 mutex_unlock(&hdmi->lock);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300439 return 0;
440
441err0:
Laurent Pinchartac767452018-02-13 14:00:45 +0200442 mutex_unlock(&hdmi->lock);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300443 return r;
444}
445
Laurent Pinchartac767452018-02-13 14:00:45 +0200446void hdmi4_core_disable(struct hdmi_core_data *core)
Tomi Valkeinen44898232012-10-19 17:42:27 +0300447{
Laurent Pinchartac767452018-02-13 14:00:45 +0200448 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
449
Hans Verkuil5bebbbf2017-08-02 10:54:02 +0200450 DSSDBG("Enter omapdss_hdmi4_core_disable\n");
Tomi Valkeinen44898232012-10-19 17:42:27 +0300451
Laurent Pinchartac767452018-02-13 14:00:45 +0200452 mutex_lock(&hdmi->lock);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300453
Laurent Pinchartac767452018-02-13 14:00:45 +0200454 hdmi_power_off_core(hdmi);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300455
Laurent Pinchartac767452018-02-13 14:00:45 +0200456 mutex_unlock(&hdmi->lock);
Tomi Valkeinen44898232012-10-19 17:42:27 +0300457}
458
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300459static int hdmi_connect(struct omap_dss_device *dssdev,
460 struct omap_dss_device *dst)
461{
Laurent Pinchartac767452018-02-13 14:00:45 +0200462 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300463 int r;
464
Laurent Pinchartac767452018-02-13 14:00:45 +0200465 r = hdmi_init_regulator(hdmi);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300466 if (r)
467 return r;
468
Laurent Pinchartac767452018-02-13 14:00:45 +0200469 r = dss_mgr_connect(&hdmi->output, dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300470 if (r)
471 return r;
472
473 r = omapdss_output_set_device(dssdev, dst);
474 if (r) {
475 DSSERR("failed to connect output to new device: %s\n",
476 dst->name);
Laurent Pinchartac767452018-02-13 14:00:45 +0200477 dss_mgr_disconnect(&hdmi->output, dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300478 return r;
479 }
480
481 return 0;
482}
483
484static void hdmi_disconnect(struct omap_dss_device *dssdev,
485 struct omap_dss_device *dst)
486{
Laurent Pinchartac767452018-02-13 14:00:45 +0200487 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
488
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300489 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300490
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300491 if (dst != dssdev->dst)
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300492 return;
493
494 omapdss_output_unset_device(dssdev);
495
Laurent Pinchartac767452018-02-13 14:00:45 +0200496 dss_mgr_disconnect(&hdmi->output, dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300497}
498
499static int hdmi_read_edid(struct omap_dss_device *dssdev,
500 u8 *edid, int len)
501{
Laurent Pinchartac767452018-02-13 14:00:45 +0200502 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300503 bool need_enable;
504 int r;
505
Laurent Pinchartac767452018-02-13 14:00:45 +0200506 need_enable = hdmi->core_enabled == false;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300507
508 if (need_enable) {
Laurent Pinchartac767452018-02-13 14:00:45 +0200509 r = hdmi4_core_enable(&hdmi->core);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300510 if (r)
511 return r;
512 }
513
Laurent Pinchartac767452018-02-13 14:00:45 +0200514 r = read_edid(hdmi, edid, len);
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200515 if (r >= 256)
Laurent Pinchartac767452018-02-13 14:00:45 +0200516 hdmi4_cec_set_phys_addr(&hdmi->core,
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200517 cec_get_edid_phys_addr(edid, r, NULL));
518 else
Laurent Pinchartac767452018-02-13 14:00:45 +0200519 hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300520 if (need_enable)
Laurent Pinchartac767452018-02-13 14:00:45 +0200521 hdmi4_core_disable(&hdmi->core);
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300522
523 return r;
524}
525
Hans Verkuil019114e2017-08-17 15:19:57 +0200526static void hdmi_lost_hotplug(struct omap_dss_device *dssdev)
527{
Laurent Pinchartac767452018-02-13 14:00:45 +0200528 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
529
530 hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID);
Hans Verkuil019114e2017-08-17 15:19:57 +0200531}
532
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300533static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
534 const struct hdmi_avi_infoframe *avi)
535{
Laurent Pinchartac767452018-02-13 14:00:45 +0200536 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
537
538 hdmi->cfg.infoframe = *avi;
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300539 return 0;
540}
541
542static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
543 bool hdmi_mode)
544{
Laurent Pinchartac767452018-02-13 14:00:45 +0200545 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
546
547 hdmi->cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300548 return 0;
549}
550
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300551static const struct omapdss_hdmi_ops hdmi_ops = {
552 .connect = hdmi_connect,
553 .disconnect = hdmi_disconnect,
554
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300555 .enable = hdmi_display_enable,
556 .disable = hdmi_display_disable,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300557
Tomi Valkeinen164ebdd2013-05-15 10:48:45 +0300558 .check_timings = hdmi_display_check_timing,
559 .set_timings = hdmi_display_set_timing,
560 .get_timings = hdmi_display_get_timings,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300561
562 .read_edid = hdmi_read_edid,
Hans Verkuil019114e2017-08-17 15:19:57 +0200563 .lost_hotplug = hdmi_lost_hotplug,
Tomi Valkeinenab0aee92014-06-18 14:21:44 +0300564 .set_infoframe = hdmi_set_infoframe,
565 .set_hdmi_mode = hdmi_set_hdmi_mode,
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300566};
567
Laurent Pinchartac767452018-02-13 14:00:45 +0200568static void hdmi_init_output(struct omap_hdmi *hdmi)
Archit Taneja81b87f52012-09-26 16:30:49 +0530569{
Laurent Pinchartac767452018-02-13 14:00:45 +0200570 struct omap_dss_device *out = &hdmi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530571
Laurent Pinchartac767452018-02-13 14:00:45 +0200572 out->dev = &hdmi->pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530573 out->id = OMAP_DSS_OUTPUT_HDMI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300574 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200575 out->name = "hdmi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200576 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeinen0b450c32013-05-24 13:20:17 +0300577 out->ops.hdmi = &hdmi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300578 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530579
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300580 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530581}
582
Laurent Pinchartac767452018-02-13 14:00:45 +0200583static void hdmi_uninit_output(struct omap_hdmi *hdmi)
Archit Taneja81b87f52012-09-26 16:30:49 +0530584{
Laurent Pinchartac767452018-02-13 14:00:45 +0200585 struct omap_dss_device *out = &hdmi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530586
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300587 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530588}
589
Laurent Pinchartac767452018-02-13 14:00:45 +0200590static int hdmi_probe_of(struct omap_hdmi *hdmi)
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300591{
Laurent Pinchartac767452018-02-13 14:00:45 +0200592 struct platform_device *pdev = hdmi->pdev;
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300593 struct device_node *node = pdev->dev.of_node;
594 struct device_node *ep;
595 int r;
596
Rob Herring09bffa62017-03-22 08:26:08 -0500597 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300598 if (!ep)
599 return 0;
600
Laurent Pinchartac767452018-02-13 14:00:45 +0200601 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300602 if (r)
603 goto err;
604
605 of_node_put(ep);
606 return 0;
607
608err:
609 of_node_put(ep);
610 return r;
611}
612
Jyri Sarha4d594df2014-05-23 12:48:28 +0300613/* Audio callbacks */
614static int hdmi_audio_startup(struct device *dev,
615 void (*abort_cb)(struct device *dev))
616{
617 struct omap_hdmi *hd = dev_get_drvdata(dev);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300618
619 mutex_lock(&hd->lock);
620
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200621 WARN_ON(hd->audio_abort_cb != NULL);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300622
623 hd->audio_abort_cb = abort_cb;
624
Jyri Sarha4d594df2014-05-23 12:48:28 +0300625 mutex_unlock(&hd->lock);
626
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200627 return 0;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300628}
629
630static int hdmi_audio_shutdown(struct device *dev)
631{
632 struct omap_hdmi *hd = dev_get_drvdata(dev);
633
634 mutex_lock(&hd->lock);
635 hd->audio_abort_cb = NULL;
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300636 hd->audio_configured = false;
637 hd->audio_playing = false;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300638 mutex_unlock(&hd->lock);
639
640 return 0;
641}
642
643static int hdmi_audio_start(struct device *dev)
644{
645 struct omap_hdmi *hd = dev_get_drvdata(dev);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300646 unsigned long flags;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300647
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300648 spin_lock_irqsave(&hd->audio_playing_lock, flags);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300649
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200650 if (hd->display_enabled) {
651 if (!hdmi_mode_has_audio(&hd->cfg))
652 DSSERR("%s: Video mode does not support audio\n",
653 __func__);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300654 hdmi_start_audio_stream(hd);
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200655 }
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300656 hd->audio_playing = true;
657
658 spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300659 return 0;
660}
661
662static void hdmi_audio_stop(struct device *dev)
663{
664 struct omap_hdmi *hd = dev_get_drvdata(dev);
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300665 unsigned long flags;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300666
667 WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
Jyri Sarha4d594df2014-05-23 12:48:28 +0300668
Jyri Sarha8a9d46262015-08-28 17:21:46 +0300669 spin_lock_irqsave(&hd->audio_playing_lock, flags);
670
671 if (hd->display_enabled)
672 hdmi_stop_audio_stream(hd);
673 hd->audio_playing = false;
674
675 spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300676}
677
678static int hdmi_audio_config(struct device *dev,
679 struct omap_dss_audio *dss_audio)
680{
681 struct omap_hdmi *hd = dev_get_drvdata(dev);
Tomi Valkeinen77eeac22018-03-29 13:40:36 +0300682 int ret = 0;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300683
684 mutex_lock(&hd->lock);
685
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200686 if (hd->display_enabled) {
687 ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
688 hd->cfg.vm.pixelclock);
689 if (ret)
690 goto out;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300691 }
692
Jyri Sarhac1899cb2017-03-16 12:05:04 +0200693 hd->audio_configured = true;
694 hd->audio_config = *dss_audio;
Jyri Sarha4d594df2014-05-23 12:48:28 +0300695out:
696 mutex_unlock(&hd->lock);
697
698 return ret;
699}
700
701static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
702 .audio_startup = hdmi_audio_startup,
703 .audio_shutdown = hdmi_audio_shutdown,
704 .audio_start = hdmi_audio_start,
705 .audio_stop = hdmi_audio_stop,
706 .audio_config = hdmi_audio_config,
707};
708
Laurent Pinchartac767452018-02-13 14:00:45 +0200709static int hdmi_audio_register(struct omap_hdmi *hdmi)
Jyri Sarha4d594df2014-05-23 12:48:28 +0300710{
711 struct omap_hdmi_audio_pdata pdata = {
Laurent Pinchartac767452018-02-13 14:00:45 +0200712 .dev = &hdmi->pdev->dev,
Laurent Pinchartd20fa5a2017-08-11 16:49:04 +0300713 .version = 4,
Laurent Pinchartac767452018-02-13 14:00:45 +0200714 .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp),
Jyri Sarha4d594df2014-05-23 12:48:28 +0300715 .ops = &hdmi_audio_ops,
716 };
717
Laurent Pinchartac767452018-02-13 14:00:45 +0200718 hdmi->audio_pdev = platform_device_register_data(
719 &hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
Jyri Sarha4d594df2014-05-23 12:48:28 +0300720 &pdata, sizeof(pdata));
721
Laurent Pinchartac767452018-02-13 14:00:45 +0200722 if (IS_ERR(hdmi->audio_pdev))
723 return PTR_ERR(hdmi->audio_pdev);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300724
725 return 0;
726}
727
Mythri P Kc3198a52011-03-12 12:04:27 +0530728/* HDMI HW IP initialisation */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300729static int hdmi4_bind(struct device *dev, struct device *master, void *data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530730{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300731 struct platform_device *pdev = to_platform_device(dev);
Laurent Pinchart7b295252018-02-13 14:00:21 +0200732 struct dss_device *dss = dss_get_device(master);
Laurent Pinchartac767452018-02-13 14:00:45 +0200733 struct omap_hdmi *hdmi;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300734 int r;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200735 int irq;
Mythri P Kc3198a52011-03-12 12:04:27 +0530736
Laurent Pinchartac767452018-02-13 14:00:45 +0200737 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
738 if (!hdmi)
739 return -ENOMEM;
Mythri P Kc3198a52011-03-12 12:04:27 +0530740
Laurent Pinchartac767452018-02-13 14:00:45 +0200741 hdmi->pdev = pdev;
742 hdmi->dss = dss;
743 dev_set_drvdata(&pdev->dev, hdmi);
Mythri P Kc3198a52011-03-12 12:04:27 +0530744
Laurent Pinchartac767452018-02-13 14:00:45 +0200745 mutex_init(&hdmi->lock);
746 spin_lock_init(&hdmi->audio_playing_lock);
747
748 r = hdmi_probe_of(hdmi);
Laurent Pinchart1dff2122017-05-07 00:42:26 +0300749 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200750 goto err_free;
Tomi Valkeinen2f5dc672014-04-17 12:54:02 +0300751
Laurent Pinchartac767452018-02-13 14:00:45 +0200752 r = hdmi_wp_init(pdev, &hdmi->wp, 4);
Archit Tanejaf382d9e2013-08-06 14:56:55 +0530753 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200754 goto err_free;
Mythri P Kc3198a52011-03-12 12:04:27 +0530755
Laurent Pinchartac767452018-02-13 14:00:45 +0200756 r = hdmi_pll_init(dss, pdev, &hdmi->pll, &hdmi->wp);
Archit Tanejac1577c12013-10-08 12:55:26 +0530757 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200758 goto err_free;
Archit Tanejac1577c12013-10-08 12:55:26 +0530759
Laurent Pinchartac767452018-02-13 14:00:45 +0200760 r = hdmi_phy_init(pdev, &hdmi->phy, 4);
Archit Taneja5cac5ae2013-10-08 13:07:00 +0530761 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200762 goto err_pll;
Tomi Valkeinenddb1d5c2013-06-06 13:08:35 +0300763
Laurent Pinchartac767452018-02-13 14:00:45 +0200764 r = hdmi4_core_init(pdev, &hdmi->core);
Archit Taneja425f02f2013-10-08 14:16:05 +0530765 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200766 goto err_pll;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300767
Laurent Pinchartac767452018-02-13 14:00:45 +0200768 r = hdmi4_cec_init(pdev, &hdmi->core, &hdmi->wp);
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200769 if (r)
Laurent Pinchartac767452018-02-13 14:00:45 +0200770 goto err_pll;
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200771
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200772 irq = platform_get_irq(pdev, 0);
773 if (irq < 0) {
774 DSSERR("platform_get_irq failed\n");
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300775 r = -ENODEV;
Laurent Pinchartac767452018-02-13 14:00:45 +0200776 goto err_pll;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200777 }
778
779 r = devm_request_threaded_irq(&pdev->dev, irq,
780 NULL, hdmi_irq_handler,
Laurent Pinchartac767452018-02-13 14:00:45 +0200781 IRQF_ONESHOT, "OMAP HDMI", hdmi);
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200782 if (r) {
783 DSSERR("HDMI IRQ request failed\n");
Laurent Pinchartac767452018-02-13 14:00:45 +0200784 goto err_pll;
Tomi Valkeinendcf5f722013-10-28 11:47:34 +0200785 }
786
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300787 pm_runtime_enable(&pdev->dev);
788
Laurent Pinchartac767452018-02-13 14:00:45 +0200789 hdmi_init_output(hdmi);
Tomi Valkeinen002d3682013-02-13 12:17:43 +0200790
Laurent Pinchartac767452018-02-13 14:00:45 +0200791 r = hdmi_audio_register(hdmi);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300792 if (r) {
793 DSSERR("Registering HDMI audio failed\n");
Laurent Pinchartac767452018-02-13 14:00:45 +0200794 hdmi_uninit_output(hdmi);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300795 pm_runtime_disable(&pdev->dev);
796 return r;
797 }
798
Laurent Pinchartac767452018-02-13 14:00:45 +0200799 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
800 hdmi);
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200801
Tomi Valkeinencca35012012-04-26 14:48:32 +0300802 return 0;
Laurent Pinchartac767452018-02-13 14:00:45 +0200803
804err_pll:
805 hdmi_pll_uninit(&hdmi->pll);
806err_free:
807 kfree(hdmi);
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300808 return r;
Tomi Valkeinencca35012012-04-26 14:48:32 +0300809}
810
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300811static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
Mythri P Kc3198a52011-03-12 12:04:27 +0530812{
Laurent Pinchartac767452018-02-13 14:00:45 +0200813 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300814
Laurent Pinchartac767452018-02-13 14:00:45 +0200815 dss_debugfs_remove_file(hdmi->debugfs);
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200816
Laurent Pinchartac767452018-02-13 14:00:45 +0200817 if (hdmi->audio_pdev)
818 platform_device_unregister(hdmi->audio_pdev);
Jyri Sarha4d594df2014-05-23 12:48:28 +0300819
Laurent Pinchartac767452018-02-13 14:00:45 +0200820 hdmi_uninit_output(hdmi);
Archit Taneja81b87f52012-09-26 16:30:49 +0530821
Laurent Pinchartac767452018-02-13 14:00:45 +0200822 hdmi4_cec_uninit(&hdmi->core);
Hans Verkuil1897e1a2017-08-02 10:54:07 +0200823
Laurent Pinchartac767452018-02-13 14:00:45 +0200824 hdmi_pll_uninit(&hdmi->pll);
Tomi Valkeinenc84c3a52014-10-22 15:02:17 +0300825
Laurent Pinchartac767452018-02-13 14:00:45 +0200826 pm_runtime_disable(dev);
827
828 kfree(hdmi);
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300829}
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300830
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300831static const struct component_ops hdmi4_component_ops = {
832 .bind = hdmi4_bind,
833 .unbind = hdmi4_unbind,
834};
835
836static int hdmi4_probe(struct platform_device *pdev)
837{
838 return component_add(&pdev->dev, &hdmi4_component_ops);
839}
840
841static int hdmi4_remove(struct platform_device *pdev)
842{
843 component_del(&pdev->dev, &hdmi4_component_ops);
Mythri P Kc3198a52011-03-12 12:04:27 +0530844 return 0;
845}
846
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300847static int hdmi_runtime_suspend(struct device *dev)
848{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200849 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
850
851 dispc_runtime_put(hdmi->dss->dispc);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300852
853 return 0;
854}
855
856static int hdmi_runtime_resume(struct device *dev)
857{
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200858 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300859 int r;
860
Laurent Pinchart50638ae2018-02-13 14:00:42 +0200861 r = dispc_runtime_get(hdmi->dss->dispc);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300862 if (r < 0)
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200863 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300864
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300865 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300866}
867
868static const struct dev_pm_ops hdmi_pm_ops = {
869 .runtime_suspend = hdmi_runtime_suspend,
870 .runtime_resume = hdmi_runtime_resume,
871};
872
Tomi Valkeinen04656162013-12-16 15:14:04 +0200873static const struct of_device_id hdmi_of_match[] = {
874 { .compatible = "ti,omap4-hdmi", },
875 {},
876};
877
Andrew F. Davisd66c36a2017-12-05 14:29:32 -0600878struct platform_driver omapdss_hdmi4hw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +0300879 .probe = hdmi4_probe,
880 .remove = hdmi4_remove,
Mythri P Kc3198a52011-03-12 12:04:27 +0530881 .driver = {
882 .name = "omapdss_hdmi",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300883 .pm = &hdmi_pm_ops,
Tomi Valkeinen04656162013-12-16 15:14:04 +0200884 .of_match_table = hdmi_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300885 .suppress_bind_attrs = true,
Mythri P Kc3198a52011-03-12 12:04:27 +0530886 },
887};