blob: 51b9ea552f9762c91c13f6a399b7314e2e9854c4 [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
Stephane Viau5eba5d82015-01-07 16:27:27 -05002 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
Rob Clarkc8afe682013-06-26 12:44:06 -04003 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
Rob Clarkf6a8eac2014-11-17 15:28:07 -050019#include <linux/of_irq.h>
Archit Taneja1fd6a442015-10-30 12:35:55 +053020#include <linux/of_gpio.h>
21
Rob Clarkc8afe682013-06-26 12:44:06 -040022#include "hdmi.h"
23
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010024void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on)
Rob Clarkc8afe682013-06-26 12:44:06 -040025{
26 uint32_t ctrl = 0;
jilai wangc6a57a52015-04-02 17:49:01 -040027 unsigned long flags;
Rob Clarkc8afe682013-06-26 12:44:06 -040028
jilai wangc6a57a52015-04-02 17:49:01 -040029 spin_lock_irqsave(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040030 if (power_on) {
31 ctrl |= HDMI_CTRL_ENABLE;
32 if (!hdmi->hdmi_mode) {
33 ctrl |= HDMI_CTRL_HDMI;
34 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
35 ctrl &= ~HDMI_CTRL_HDMI;
36 } else {
37 ctrl |= HDMI_CTRL_HDMI;
38 }
39 } else {
40 ctrl = HDMI_CTRL_HDMI;
41 }
42
43 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
jilai wangc6a57a52015-04-02 17:49:01 -040044 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040045 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
46 power_on ? "Enable" : "Disable", ctrl);
47}
48
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010049static irqreturn_t msm_hdmi_irq(int irq, void *dev_id)
Rob Clarkc8afe682013-06-26 12:44:06 -040050{
51 struct hdmi *hdmi = dev_id;
52
53 /* Process HPD: */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010054 msm_hdmi_connector_irq(hdmi->connector);
Rob Clarkc8afe682013-06-26 12:44:06 -040055
56 /* Process DDC: */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010057 msm_hdmi_i2c_irq(hdmi->i2c);
Rob Clarkc8afe682013-06-26 12:44:06 -040058
jilai wangc6a57a52015-04-02 17:49:01 -040059 /* Process HDCP: */
60 if (hdmi->hdcp_ctrl)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010061 msm_hdmi_hdcp_irq(hdmi->hdcp_ctrl);
jilai wangc6a57a52015-04-02 17:49:01 -040062
Rob Clarkc8afe682013-06-26 12:44:06 -040063 /* TODO audio.. */
64
65 return IRQ_HANDLED;
66}
67
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010068static void msm_hdmi_destroy(struct hdmi *hdmi)
Rob Clarkc8afe682013-06-26 12:44:06 -040069{
jilai wangc6a57a52015-04-02 17:49:01 -040070 /*
71 * at this point, hpd has been disabled,
72 * after flush workq, it's safe to deinit hdcp
73 */
74 if (hdmi->workq) {
75 flush_workqueue(hdmi->workq);
76 destroy_workqueue(hdmi->workq);
77 }
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010078 msm_hdmi_hdcp_destroy(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -040079
Archit Tanejae00012b2016-02-25 11:22:40 +053080 if (hdmi->phy_dev) {
81 put_device(hdmi->phy_dev);
82 hdmi->phy = NULL;
83 hdmi->phy_dev = NULL;
84 }
85
Rob Clarkc8afe682013-06-26 12:44:06 -040086 if (hdmi->i2c)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010087 msm_hdmi_i2c_destroy(hdmi->i2c);
Rob Clarkc8afe682013-06-26 12:44:06 -040088
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050089 platform_set_drvdata(hdmi->pdev, NULL);
Rob Clarkc8afe682013-06-26 12:44:06 -040090}
91
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010092static int msm_hdmi_get_phy(struct hdmi *hdmi)
Archit Tanejae00012b2016-02-25 11:22:40 +053093{
94 struct platform_device *pdev = hdmi->pdev;
95 struct platform_device *phy_pdev;
96 struct device_node *phy_node;
97
98 phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
99 if (!phy_node) {
100 dev_err(&pdev->dev, "cannot find phy device\n");
101 return -ENXIO;
102 }
103
104 phy_pdev = of_find_device_by_node(phy_node);
105 if (phy_pdev)
106 hdmi->phy = platform_get_drvdata(phy_pdev);
107
108 of_node_put(phy_node);
109
110 if (!phy_pdev || !hdmi->phy) {
111 dev_err(&pdev->dev, "phy driver is not ready\n");
112 return -EPROBE_DEFER;
113 }
114
115 hdmi->phy_dev = get_device(&phy_pdev->dev);
116
117 return 0;
118}
119
Rob Clark067fef32014-11-04 13:33:14 -0500120/* construct hdmi at bind/probe time, grab all the resources. If
121 * we are to EPROBE_DEFER we want to do it here, rather than later
122 * at modeset_init() time
123 */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100124static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400125{
Rob Clark067fef32014-11-04 13:33:14 -0500126 struct hdmi_platform_config *config = pdev->dev.platform_data;
Rob Clarka3376e32013-08-30 13:02:15 -0400127 struct hdmi *hdmi = NULL;
jilai wangc6a57a52015-04-02 17:49:01 -0400128 struct resource *res;
Rob Clarkdada25b2013-12-01 12:12:54 -0500129 int i, ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400130
Rob Clark067fef32014-11-04 13:33:14 -0500131 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
Rob Clarka3376e32013-08-30 13:02:15 -0400132 if (!hdmi) {
133 ret = -ENOMEM;
134 goto fail;
135 }
136
Rob Clarkc8afe682013-06-26 12:44:06 -0400137 hdmi->pdev = pdev;
Rob Clarkdada25b2013-12-01 12:12:54 -0500138 hdmi->config = config;
jilai wangc6a57a52015-04-02 17:49:01 -0400139 spin_lock_init(&hdmi->reg_lock);
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500140
Rob Clarkdada25b2013-12-01 12:12:54 -0500141 hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
Rob Clarkc8afe682013-06-26 12:44:06 -0400142 if (IS_ERR(hdmi->mmio)) {
143 ret = PTR_ERR(hdmi->mmio);
144 goto fail;
145 }
146
jilai wangc6a57a52015-04-02 17:49:01 -0400147 /* HDCP needs physical address of hdmi register */
148 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
149 config->mmio_name);
150 hdmi->mmio_phy_addr = res->start;
151
152 hdmi->qfprom_mmio = msm_ioremap(pdev,
153 config->qfprom_mmio_name, "HDMI_QFPROM");
154 if (IS_ERR(hdmi->qfprom_mmio)) {
155 dev_info(&pdev->dev, "can't find qfprom resource\n");
156 hdmi->qfprom_mmio = NULL;
157 }
158
Stephane Viau447fa522015-01-13 14:33:40 -0500159 hdmi->hpd_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_regs[0]) *
160 config->hpd_reg_cnt, GFP_KERNEL);
161 if (!hdmi->hpd_regs) {
162 ret = -ENOMEM;
163 goto fail;
164 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500165 for (i = 0; i < config->hpd_reg_cnt; i++) {
166 struct regulator *reg;
167
Rob Clark3e875992014-08-01 13:08:11 -0400168 reg = devm_regulator_get(&pdev->dev,
Rob Clark41e69772013-12-15 16:23:05 -0500169 config->hpd_reg_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500170 if (IS_ERR(reg)) {
171 ret = PTR_ERR(reg);
Rob Clark067fef32014-11-04 13:33:14 -0500172 dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500173 config->hpd_reg_names[i], ret);
174 goto fail;
175 }
176
177 hdmi->hpd_regs[i] = reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400178 }
179
Stephane Viau447fa522015-01-13 14:33:40 -0500180 hdmi->pwr_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_regs[0]) *
181 config->pwr_reg_cnt, GFP_KERNEL);
182 if (!hdmi->pwr_regs) {
183 ret = -ENOMEM;
184 goto fail;
185 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500186 for (i = 0; i < config->pwr_reg_cnt; i++) {
187 struct regulator *reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400188
Rob Clark3e875992014-08-01 13:08:11 -0400189 reg = devm_regulator_get(&pdev->dev,
Rob Clark41e69772013-12-15 16:23:05 -0500190 config->pwr_reg_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500191 if (IS_ERR(reg)) {
192 ret = PTR_ERR(reg);
Rob Clark067fef32014-11-04 13:33:14 -0500193 dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500194 config->pwr_reg_names[i], ret);
195 goto fail;
196 }
197
198 hdmi->pwr_regs[i] = reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400199 }
200
Stephane Viau447fa522015-01-13 14:33:40 -0500201 hdmi->hpd_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_clks[0]) *
202 config->hpd_clk_cnt, GFP_KERNEL);
203 if (!hdmi->hpd_clks) {
204 ret = -ENOMEM;
205 goto fail;
206 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500207 for (i = 0; i < config->hpd_clk_cnt; i++) {
208 struct clk *clk;
209
210 clk = devm_clk_get(&pdev->dev, config->hpd_clk_names[i]);
211 if (IS_ERR(clk)) {
212 ret = PTR_ERR(clk);
Rob Clark067fef32014-11-04 13:33:14 -0500213 dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500214 config->hpd_clk_names[i], ret);
215 goto fail;
216 }
217
218 hdmi->hpd_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400219 }
220
Stephane Viau447fa522015-01-13 14:33:40 -0500221 hdmi->pwr_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_clks[0]) *
222 config->pwr_clk_cnt, GFP_KERNEL);
223 if (!hdmi->pwr_clks) {
224 ret = -ENOMEM;
225 goto fail;
226 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500227 for (i = 0; i < config->pwr_clk_cnt; i++) {
228 struct clk *clk;
229
230 clk = devm_clk_get(&pdev->dev, config->pwr_clk_names[i]);
231 if (IS_ERR(clk)) {
232 ret = PTR_ERR(clk);
Rob Clark067fef32014-11-04 13:33:14 -0500233 dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500234 config->pwr_clk_names[i], ret);
235 goto fail;
236 }
237
238 hdmi->pwr_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400239 }
240
jilai wangc6a57a52015-04-02 17:49:01 -0400241 hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
242
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100243 hdmi->i2c = msm_hdmi_i2c_init(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400244 if (IS_ERR(hdmi->i2c)) {
245 ret = PTR_ERR(hdmi->i2c);
Rob Clark067fef32014-11-04 13:33:14 -0500246 dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
Rob Clarkc8afe682013-06-26 12:44:06 -0400247 hdmi->i2c = NULL;
248 goto fail;
249 }
250
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100251 ret = msm_hdmi_get_phy(hdmi);
Archit Tanejae00012b2016-02-25 11:22:40 +0530252 if (ret) {
253 dev_err(&pdev->dev, "failed to get phy\n");
254 goto fail;
255 }
256
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100257 hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
jilai wangc6a57a52015-04-02 17:49:01 -0400258 if (IS_ERR(hdmi->hdcp_ctrl)) {
259 dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
260 hdmi->hdcp_ctrl = NULL;
261 }
262
Rob Clark067fef32014-11-04 13:33:14 -0500263 return hdmi;
264
265fail:
266 if (hdmi)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100267 msm_hdmi_destroy(hdmi);
Rob Clark067fef32014-11-04 13:33:14 -0500268
269 return ERR_PTR(ret);
270}
271
272/* Second part of initialization, the drm/kms level modeset_init,
273 * constructs/initializes mode objects, etc, is called from master
274 * driver (not hdmi sub-device's probe/bind!)
275 *
276 * Any resource (regulator/clk/etc) which could be missing at boot
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100277 * should be handled in msm_hdmi_init() so that failure happens from
Rob Clark067fef32014-11-04 13:33:14 -0500278 * hdmi sub-device's probe.
279 */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100280int msm_hdmi_modeset_init(struct hdmi *hdmi,
Rob Clark067fef32014-11-04 13:33:14 -0500281 struct drm_device *dev, struct drm_encoder *encoder)
282{
283 struct msm_drm_private *priv = dev->dev_private;
284 struct platform_device *pdev = hdmi->pdev;
Rob Clark067fef32014-11-04 13:33:14 -0500285 int ret;
286
287 hdmi->dev = dev;
288 hdmi->encoder = encoder;
289
290 hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
291
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100292 hdmi->bridge = msm_hdmi_bridge_init(hdmi);
Rob Clarka3376e32013-08-30 13:02:15 -0400293 if (IS_ERR(hdmi->bridge)) {
294 ret = PTR_ERR(hdmi->bridge);
295 dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
296 hdmi->bridge = NULL;
297 goto fail;
298 }
299
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100300 hdmi->connector = msm_hdmi_connector_init(hdmi);
Rob Clarka3376e32013-08-30 13:02:15 -0400301 if (IS_ERR(hdmi->connector)) {
302 ret = PTR_ERR(hdmi->connector);
303 dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
304 hdmi->connector = NULL;
305 goto fail;
306 }
307
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500308 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
309 if (hdmi->irq < 0) {
310 ret = hdmi->irq;
311 dev_err(dev->dev, "failed to get irq: %d\n", ret);
312 goto fail;
313 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400314
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500315 ret = devm_request_irq(&pdev->dev, hdmi->irq,
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100316 msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500317 "hdmi_isr", hdmi);
318 if (ret < 0) {
319 dev_err(dev->dev, "failed to request IRQ%u: %d\n",
320 hdmi->irq, ret);
321 goto fail;
Rob Clarkc8afe682013-06-26 12:44:06 -0400322 }
323
Rob Clarka3376e32013-08-30 13:02:15 -0400324 encoder->bridge = hdmi->bridge;
325
326 priv->bridges[priv->num_bridges++] = hdmi->bridge;
327 priv->connectors[priv->num_connectors++] = hdmi->connector;
328
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500329 platform_set_drvdata(pdev, hdmi);
330
Rob Clark067fef32014-11-04 13:33:14 -0500331 return 0;
Rob Clarkc8afe682013-06-26 12:44:06 -0400332
333fail:
Ajay Kumar3d3f8b12015-01-20 22:08:44 +0530334 /* bridge is normally destroyed by drm: */
Rob Clark067fef32014-11-04 13:33:14 -0500335 if (hdmi->bridge) {
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100336 msm_hdmi_bridge_destroy(hdmi->bridge);
Rob Clark067fef32014-11-04 13:33:14 -0500337 hdmi->bridge = NULL;
338 }
339 if (hdmi->connector) {
340 hdmi->connector->funcs->destroy(hdmi->connector);
341 hdmi->connector = NULL;
Rob Clarka3376e32013-08-30 13:02:15 -0400342 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400343
Rob Clark067fef32014-11-04 13:33:14 -0500344 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400345}
346
347/*
348 * The hdmi device:
349 */
350
Stephane Viau5eba5d82015-01-07 16:27:27 -0500351#define HDMI_CFG(item, entry) \
352 .item ## _names = item ##_names_ ## entry, \
353 .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
354
Stephane Viau0afbe592015-09-15 08:41:49 -0400355static const char *pwr_reg_names_none[] = {};
356static const char *hpd_reg_names_none[] = {};
357
Archit Tanejaba3d7bf2016-02-25 11:22:41 +0530358static struct hdmi_platform_config hdmi_tx_8660_config;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500359
360static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
361static const char *hpd_clk_names_8960[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
362
363static struct hdmi_platform_config hdmi_tx_8960_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500364 HDMI_CFG(hpd_reg, 8960),
365 HDMI_CFG(hpd_clk, 8960),
366};
367
368static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
369static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
370static const char *pwr_clk_names_8x74[] = {"extp_clk", "alt_iface_clk"};
371static const char *hpd_clk_names_8x74[] = {"iface_clk", "core_clk", "mdp_core_clk"};
372static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
373
Rob Clark5cf3a45532015-07-27 20:52:50 -0400374static struct hdmi_platform_config hdmi_tx_8974_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500375 HDMI_CFG(pwr_reg, 8x74),
376 HDMI_CFG(hpd_reg, 8x74),
377 HDMI_CFG(pwr_clk, 8x74),
378 HDMI_CFG(hpd_clk, 8x74),
379 .hpd_freq = hpd_clk_freq_8x74,
380};
381
382static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
383
384static struct hdmi_platform_config hdmi_tx_8084_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500385 HDMI_CFG(pwr_reg, 8x74),
386 HDMI_CFG(hpd_reg, 8084),
387 HDMI_CFG(pwr_clk, 8x74),
388 HDMI_CFG(hpd_clk, 8x74),
389 .hpd_freq = hpd_clk_freq_8x74,
390};
391
Rob Clark5cf3a45532015-07-27 20:52:50 -0400392static struct hdmi_platform_config hdmi_tx_8994_config = {
Stephane Viau3a84f842015-06-19 16:04:47 -0400393 HDMI_CFG(pwr_reg, 8x74),
Stephane Viau0afbe592015-09-15 08:41:49 -0400394 HDMI_CFG(hpd_reg, none),
395 HDMI_CFG(pwr_clk, 8x74),
396 HDMI_CFG(hpd_clk, 8x74),
397 .hpd_freq = hpd_clk_freq_8x74,
398};
399
400static struct hdmi_platform_config hdmi_tx_8996_config = {
Stephane Viau0afbe592015-09-15 08:41:49 -0400401 HDMI_CFG(pwr_reg, none),
402 HDMI_CFG(hpd_reg, none),
Stephane Viau3a84f842015-06-19 16:04:47 -0400403 HDMI_CFG(pwr_clk, 8x74),
404 HDMI_CFG(hpd_clk, 8x74),
405 .hpd_freq = hpd_clk_freq_8x74,
406};
407
Archit Tanejadc50f7822016-02-25 11:22:36 +0530408static const struct {
409 const char *name;
410 const bool output;
411 const int value;
412 const char *label;
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100413} msm_hdmi_gpio_pdata[] = {
Archit Tanejadc50f7822016-02-25 11:22:36 +0530414 { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
415 { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
416 { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
417 { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
418 { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
419 { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
420};
421
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100422static int msm_hdmi_get_gpio(struct device_node *of_node, const char *name)
Mark Charleboisfc886102014-08-29 11:05:50 -0700423{
424 int gpio = of_get_named_gpio(of_node, name, 0);
425 if (gpio < 0) {
426 char name2[32];
427 snprintf(name2, sizeof(name2), "%s-gpio", name);
428 gpio = of_get_named_gpio(of_node, name2, 0);
429 if (gpio < 0) {
Stephane Viau3a84f842015-06-19 16:04:47 -0400430 DBG("failed to get gpio: %s (%d)", name, gpio);
Mark Charleboisfc886102014-08-29 11:05:50 -0700431 gpio = -1;
432 }
433 }
434 return gpio;
435}
Mark Charleboisfc886102014-08-29 11:05:50 -0700436
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100437static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
Rob Clarkc8afe682013-06-26 12:44:06 -0400438{
Rob Clarkd1a717b2014-11-18 08:40:44 -0500439 struct drm_device *drm = dev_get_drvdata(master);
440 struct msm_drm_private *priv = drm->dev_private;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500441 static struct hdmi_platform_config *hdmi_cfg;
Rob Clark067fef32014-11-04 13:33:14 -0500442 struct hdmi *hdmi;
Rob Clark060530f2014-03-03 14:19:12 -0500443 struct device_node *of_node = dev->of_node;
Archit Tanejadc50f7822016-02-25 11:22:36 +0530444 int i;
Rob Clarkdada25b2013-12-01 12:12:54 -0500445
Archit Taneja1fd6a442015-10-30 12:35:55 +0530446 hdmi_cfg = (struct hdmi_platform_config *)
447 of_device_get_match_data(dev);
448 if (!hdmi_cfg) {
449 dev_err(dev, "unknown hdmi_cfg: %s\n", of_node->name);
Stephane Viau5eba5d82015-01-07 16:27:27 -0500450 return -ENXIO;
Rob Clark41e69772013-12-15 16:23:05 -0500451 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500452
Stephane Viau5eba5d82015-01-07 16:27:27 -0500453 hdmi_cfg->mmio_name = "core_physical";
jilai wangc6a57a52015-04-02 17:49:01 -0400454 hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
Archit Tanejadc50f7822016-02-25 11:22:36 +0530455
456 for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100457 hdmi_cfg->gpios[i].num = msm_hdmi_get_gpio(of_node,
458 msm_hdmi_gpio_pdata[i].name);
459 hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
460 hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
461 hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label;
Archit Tanejadc50f7822016-02-25 11:22:36 +0530462 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500463
Stephane Viau5eba5d82015-01-07 16:27:27 -0500464 dev->platform_data = hdmi_cfg;
465
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100466 hdmi = msm_hdmi_init(to_platform_device(dev));
Rob Clark067fef32014-11-04 13:33:14 -0500467 if (IS_ERR(hdmi))
468 return PTR_ERR(hdmi);
Rob Clarkd1a717b2014-11-18 08:40:44 -0500469 priv->hdmi = hdmi;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500470
Rob Clarkc8afe682013-06-26 12:44:06 -0400471 return 0;
472}
473
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100474static void msm_hdmi_unbind(struct device *dev, struct device *master,
Rob Clark060530f2014-03-03 14:19:12 -0500475 void *data)
476{
Rob Clarkd1a717b2014-11-18 08:40:44 -0500477 struct drm_device *drm = dev_get_drvdata(master);
478 struct msm_drm_private *priv = drm->dev_private;
479 if (priv->hdmi) {
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100480 msm_hdmi_destroy(priv->hdmi);
Rob Clarkd1a717b2014-11-18 08:40:44 -0500481 priv->hdmi = NULL;
482 }
Rob Clark060530f2014-03-03 14:19:12 -0500483}
484
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100485static const struct component_ops msm_hdmi_ops = {
486 .bind = msm_hdmi_bind,
487 .unbind = msm_hdmi_unbind,
Rob Clark060530f2014-03-03 14:19:12 -0500488};
489
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100490static int msm_hdmi_dev_probe(struct platform_device *pdev)
Rob Clark060530f2014-03-03 14:19:12 -0500491{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100492 return component_add(&pdev->dev, &msm_hdmi_ops);
Rob Clark060530f2014-03-03 14:19:12 -0500493}
494
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100495static int msm_hdmi_dev_remove(struct platform_device *pdev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400496{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100497 component_del(&pdev->dev, &msm_hdmi_ops);
Rob Clarkc8afe682013-06-26 12:44:06 -0400498 return 0;
499}
500
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100501static const struct of_device_id msm_hdmi_dt_match[] = {
Archit Taneja1fd6a442015-10-30 12:35:55 +0530502 { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
503 { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
504 { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
505 { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
506 { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
507 { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
508 {}
509};
510
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100511static struct platform_driver msm_hdmi_driver = {
512 .probe = msm_hdmi_dev_probe,
513 .remove = msm_hdmi_dev_remove,
Rob Clarkdada25b2013-12-01 12:12:54 -0500514 .driver = {
515 .name = "hdmi_msm",
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100516 .of_match_table = msm_hdmi_dt_match,
Rob Clarkdada25b2013-12-01 12:12:54 -0500517 },
Rob Clarkc8afe682013-06-26 12:44:06 -0400518};
519
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100520void __init msm_hdmi_register(void)
Rob Clarkc8afe682013-06-26 12:44:06 -0400521{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100522 msm_hdmi_phy_driver_register();
523 platform_driver_register(&msm_hdmi_driver);
Rob Clarkc8afe682013-06-26 12:44:06 -0400524}
525
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100526void __exit msm_hdmi_unregister(void)
Rob Clarkc8afe682013-06-26 12:44:06 -0400527{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100528 platform_driver_unregister(&msm_hdmi_driver);
529 msm_hdmi_phy_driver_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -0400530}