blob: 1f4a95eeb348190a01aaa05207abc9c20679982a [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>
Rob Clarkc8afe682013-06-26 12:44:06 -040020#include "hdmi.h"
21
Rob Clarkc8afe682013-06-26 12:44:06 -040022void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
23{
24 uint32_t ctrl = 0;
jilai wangc6a57a52015-04-02 17:49:01 -040025 unsigned long flags;
Rob Clarkc8afe682013-06-26 12:44:06 -040026
jilai wangc6a57a52015-04-02 17:49:01 -040027 spin_lock_irqsave(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040028 if (power_on) {
29 ctrl |= HDMI_CTRL_ENABLE;
30 if (!hdmi->hdmi_mode) {
31 ctrl |= HDMI_CTRL_HDMI;
32 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
33 ctrl &= ~HDMI_CTRL_HDMI;
34 } else {
35 ctrl |= HDMI_CTRL_HDMI;
36 }
37 } else {
38 ctrl = HDMI_CTRL_HDMI;
39 }
40
41 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
jilai wangc6a57a52015-04-02 17:49:01 -040042 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040043 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
44 power_on ? "Enable" : "Disable", ctrl);
45}
46
Rob Clarkf6a8eac2014-11-17 15:28:07 -050047static irqreturn_t hdmi_irq(int irq, void *dev_id)
Rob Clarkc8afe682013-06-26 12:44:06 -040048{
49 struct hdmi *hdmi = dev_id;
50
51 /* Process HPD: */
52 hdmi_connector_irq(hdmi->connector);
53
54 /* Process DDC: */
55 hdmi_i2c_irq(hdmi->i2c);
56
jilai wangc6a57a52015-04-02 17:49:01 -040057 /* Process HDCP: */
58 if (hdmi->hdcp_ctrl)
59 hdmi_hdcp_irq(hdmi->hdcp_ctrl);
60
Rob Clarkc8afe682013-06-26 12:44:06 -040061 /* TODO audio.. */
62
63 return IRQ_HANDLED;
64}
65
Rob Clarkd1a717b2014-11-18 08:40:44 -050066static void hdmi_destroy(struct hdmi *hdmi)
Rob Clarkc8afe682013-06-26 12:44:06 -040067{
68 struct hdmi_phy *phy = hdmi->phy;
69
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 }
78 hdmi_hdcp_destroy(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -040079 if (phy)
80 phy->funcs->destroy(phy);
81
82 if (hdmi->i2c)
83 hdmi_i2c_destroy(hdmi->i2c);
84
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050085 platform_set_drvdata(hdmi->pdev, NULL);
Rob Clarkc8afe682013-06-26 12:44:06 -040086}
87
Rob Clark067fef32014-11-04 13:33:14 -050088/* construct hdmi at bind/probe time, grab all the resources. If
89 * we are to EPROBE_DEFER we want to do it here, rather than later
90 * at modeset_init() time
91 */
92static struct hdmi *hdmi_init(struct platform_device *pdev)
Rob Clarkc8afe682013-06-26 12:44:06 -040093{
Rob Clark067fef32014-11-04 13:33:14 -050094 struct hdmi_platform_config *config = pdev->dev.platform_data;
Rob Clarka3376e32013-08-30 13:02:15 -040095 struct hdmi *hdmi = NULL;
jilai wangc6a57a52015-04-02 17:49:01 -040096 struct resource *res;
Rob Clarkdada25b2013-12-01 12:12:54 -050097 int i, ret;
Rob Clarkc8afe682013-06-26 12:44:06 -040098
Rob Clark067fef32014-11-04 13:33:14 -050099 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
Rob Clarka3376e32013-08-30 13:02:15 -0400100 if (!hdmi) {
101 ret = -ENOMEM;
102 goto fail;
103 }
104
Rob Clarkc8afe682013-06-26 12:44:06 -0400105 hdmi->pdev = pdev;
Rob Clarkdada25b2013-12-01 12:12:54 -0500106 hdmi->config = config;
jilai wangc6a57a52015-04-02 17:49:01 -0400107 spin_lock_init(&hdmi->reg_lock);
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500108
Rob Clarkc8afe682013-06-26 12:44:06 -0400109 /* not sure about which phy maps to which msm.. probably I miss some */
Stephane Viau3a84f842015-06-19 16:04:47 -0400110 if (config->phy_init) {
Rob Clarkc8afe682013-06-26 12:44:06 -0400111 hdmi->phy = config->phy_init(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400112
Stephane Viau3a84f842015-06-19 16:04:47 -0400113 if (IS_ERR(hdmi->phy)) {
114 ret = PTR_ERR(hdmi->phy);
115 dev_err(&pdev->dev, "failed to load phy: %d\n", ret);
116 hdmi->phy = NULL;
117 goto fail;
118 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400119 }
120
Rob Clarkdada25b2013-12-01 12:12:54 -0500121 hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
Rob Clarkc8afe682013-06-26 12:44:06 -0400122 if (IS_ERR(hdmi->mmio)) {
123 ret = PTR_ERR(hdmi->mmio);
124 goto fail;
125 }
126
jilai wangc6a57a52015-04-02 17:49:01 -0400127 /* HDCP needs physical address of hdmi register */
128 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
129 config->mmio_name);
130 hdmi->mmio_phy_addr = res->start;
131
132 hdmi->qfprom_mmio = msm_ioremap(pdev,
133 config->qfprom_mmio_name, "HDMI_QFPROM");
134 if (IS_ERR(hdmi->qfprom_mmio)) {
135 dev_info(&pdev->dev, "can't find qfprom resource\n");
136 hdmi->qfprom_mmio = NULL;
137 }
138
Stephane Viau447fa522015-01-13 14:33:40 -0500139 hdmi->hpd_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_regs[0]) *
140 config->hpd_reg_cnt, GFP_KERNEL);
141 if (!hdmi->hpd_regs) {
142 ret = -ENOMEM;
143 goto fail;
144 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500145 for (i = 0; i < config->hpd_reg_cnt; i++) {
146 struct regulator *reg;
147
Rob Clark3e875992014-08-01 13:08:11 -0400148 reg = devm_regulator_get(&pdev->dev,
Rob Clark41e69772013-12-15 16:23:05 -0500149 config->hpd_reg_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500150 if (IS_ERR(reg)) {
151 ret = PTR_ERR(reg);
Rob Clark067fef32014-11-04 13:33:14 -0500152 dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500153 config->hpd_reg_names[i], ret);
154 goto fail;
155 }
156
157 hdmi->hpd_regs[i] = reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400158 }
159
Stephane Viau447fa522015-01-13 14:33:40 -0500160 hdmi->pwr_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_regs[0]) *
161 config->pwr_reg_cnt, GFP_KERNEL);
162 if (!hdmi->pwr_regs) {
163 ret = -ENOMEM;
164 goto fail;
165 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500166 for (i = 0; i < config->pwr_reg_cnt; i++) {
167 struct regulator *reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400168
Rob Clark3e875992014-08-01 13:08:11 -0400169 reg = devm_regulator_get(&pdev->dev,
Rob Clark41e69772013-12-15 16:23:05 -0500170 config->pwr_reg_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500171 if (IS_ERR(reg)) {
172 ret = PTR_ERR(reg);
Rob Clark067fef32014-11-04 13:33:14 -0500173 dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500174 config->pwr_reg_names[i], ret);
175 goto fail;
176 }
177
178 hdmi->pwr_regs[i] = reg;
Rob Clarkc8afe682013-06-26 12:44:06 -0400179 }
180
Stephane Viau447fa522015-01-13 14:33:40 -0500181 hdmi->hpd_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_clks[0]) *
182 config->hpd_clk_cnt, GFP_KERNEL);
183 if (!hdmi->hpd_clks) {
184 ret = -ENOMEM;
185 goto fail;
186 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500187 for (i = 0; i < config->hpd_clk_cnt; i++) {
188 struct clk *clk;
189
190 clk = devm_clk_get(&pdev->dev, config->hpd_clk_names[i]);
191 if (IS_ERR(clk)) {
192 ret = PTR_ERR(clk);
Rob Clark067fef32014-11-04 13:33:14 -0500193 dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500194 config->hpd_clk_names[i], ret);
195 goto fail;
196 }
197
198 hdmi->hpd_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400199 }
200
Stephane Viau447fa522015-01-13 14:33:40 -0500201 hdmi->pwr_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_clks[0]) *
202 config->pwr_clk_cnt, GFP_KERNEL);
203 if (!hdmi->pwr_clks) {
204 ret = -ENOMEM;
205 goto fail;
206 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500207 for (i = 0; i < config->pwr_clk_cnt; i++) {
208 struct clk *clk;
209
210 clk = devm_clk_get(&pdev->dev, config->pwr_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 pwr clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500214 config->pwr_clk_names[i], ret);
215 goto fail;
216 }
217
218 hdmi->pwr_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400219 }
220
jilai wangc6a57a52015-04-02 17:49:01 -0400221 hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
222
Rob Clarkc8afe682013-06-26 12:44:06 -0400223 hdmi->i2c = hdmi_i2c_init(hdmi);
224 if (IS_ERR(hdmi->i2c)) {
225 ret = PTR_ERR(hdmi->i2c);
Rob Clark067fef32014-11-04 13:33:14 -0500226 dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
Rob Clarkc8afe682013-06-26 12:44:06 -0400227 hdmi->i2c = NULL;
228 goto fail;
229 }
230
jilai wangc6a57a52015-04-02 17:49:01 -0400231 hdmi->hdcp_ctrl = hdmi_hdcp_init(hdmi);
232 if (IS_ERR(hdmi->hdcp_ctrl)) {
233 dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
234 hdmi->hdcp_ctrl = NULL;
235 }
236
Rob Clark067fef32014-11-04 13:33:14 -0500237 return hdmi;
238
239fail:
240 if (hdmi)
Rob Clarkd1a717b2014-11-18 08:40:44 -0500241 hdmi_destroy(hdmi);
Rob Clark067fef32014-11-04 13:33:14 -0500242
243 return ERR_PTR(ret);
244}
245
246/* Second part of initialization, the drm/kms level modeset_init,
247 * constructs/initializes mode objects, etc, is called from master
248 * driver (not hdmi sub-device's probe/bind!)
249 *
250 * Any resource (regulator/clk/etc) which could be missing at boot
251 * should be handled in hdmi_init() so that failure happens from
252 * hdmi sub-device's probe.
253 */
254int hdmi_modeset_init(struct hdmi *hdmi,
255 struct drm_device *dev, struct drm_encoder *encoder)
256{
257 struct msm_drm_private *priv = dev->dev_private;
258 struct platform_device *pdev = hdmi->pdev;
Rob Clark067fef32014-11-04 13:33:14 -0500259 int ret;
260
261 hdmi->dev = dev;
262 hdmi->encoder = encoder;
263
264 hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
265
Rob Clarka3376e32013-08-30 13:02:15 -0400266 hdmi->bridge = hdmi_bridge_init(hdmi);
267 if (IS_ERR(hdmi->bridge)) {
268 ret = PTR_ERR(hdmi->bridge);
269 dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
270 hdmi->bridge = NULL;
271 goto fail;
272 }
273
274 hdmi->connector = hdmi_connector_init(hdmi);
275 if (IS_ERR(hdmi->connector)) {
276 ret = PTR_ERR(hdmi->connector);
277 dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
278 hdmi->connector = NULL;
279 goto fail;
280 }
281
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500282 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
283 if (hdmi->irq < 0) {
284 ret = hdmi->irq;
285 dev_err(dev->dev, "failed to get irq: %d\n", ret);
286 goto fail;
287 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400288
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500289 ret = devm_request_irq(&pdev->dev, hdmi->irq,
290 hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
291 "hdmi_isr", hdmi);
292 if (ret < 0) {
293 dev_err(dev->dev, "failed to request IRQ%u: %d\n",
294 hdmi->irq, ret);
295 goto fail;
Rob Clarkc8afe682013-06-26 12:44:06 -0400296 }
297
Rob Clarka3376e32013-08-30 13:02:15 -0400298 encoder->bridge = hdmi->bridge;
299
300 priv->bridges[priv->num_bridges++] = hdmi->bridge;
301 priv->connectors[priv->num_connectors++] = hdmi->connector;
302
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500303 platform_set_drvdata(pdev, hdmi);
304
Rob Clark067fef32014-11-04 13:33:14 -0500305 return 0;
Rob Clarkc8afe682013-06-26 12:44:06 -0400306
307fail:
Ajay Kumar3d3f8b12015-01-20 22:08:44 +0530308 /* bridge is normally destroyed by drm: */
Rob Clark067fef32014-11-04 13:33:14 -0500309 if (hdmi->bridge) {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +0530310 hdmi_bridge_destroy(hdmi->bridge);
Rob Clark067fef32014-11-04 13:33:14 -0500311 hdmi->bridge = NULL;
312 }
313 if (hdmi->connector) {
314 hdmi->connector->funcs->destroy(hdmi->connector);
315 hdmi->connector = NULL;
Rob Clarka3376e32013-08-30 13:02:15 -0400316 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400317
Rob Clark067fef32014-11-04 13:33:14 -0500318 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400319}
320
321/*
322 * The hdmi device:
323 */
324
Rob Clarkdada25b2013-12-01 12:12:54 -0500325#include <linux/of_gpio.h>
326
Stephane Viau5eba5d82015-01-07 16:27:27 -0500327#define HDMI_CFG(item, entry) \
328 .item ## _names = item ##_names_ ## entry, \
329 .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
330
Stephane Viau0afbe592015-09-15 08:41:49 -0400331static const char *pwr_reg_names_none[] = {};
332static const char *hpd_reg_names_none[] = {};
333
Stephane Viau5eba5d82015-01-07 16:27:27 -0500334static struct hdmi_platform_config hdmi_tx_8660_config = {
335 .phy_init = hdmi_phy_8x60_init,
336};
337
338static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
339static const char *hpd_clk_names_8960[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
340
341static struct hdmi_platform_config hdmi_tx_8960_config = {
342 .phy_init = hdmi_phy_8960_init,
343 HDMI_CFG(hpd_reg, 8960),
344 HDMI_CFG(hpd_clk, 8960),
345};
346
347static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
348static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
349static const char *pwr_clk_names_8x74[] = {"extp_clk", "alt_iface_clk"};
350static const char *hpd_clk_names_8x74[] = {"iface_clk", "core_clk", "mdp_core_clk"};
351static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
352
Rob Clark5cf3a452015-07-27 20:52:50 -0400353static struct hdmi_platform_config hdmi_tx_8974_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500354 .phy_init = hdmi_phy_8x74_init,
355 HDMI_CFG(pwr_reg, 8x74),
356 HDMI_CFG(hpd_reg, 8x74),
357 HDMI_CFG(pwr_clk, 8x74),
358 HDMI_CFG(hpd_clk, 8x74),
359 .hpd_freq = hpd_clk_freq_8x74,
360};
361
362static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
363
364static struct hdmi_platform_config hdmi_tx_8084_config = {
365 .phy_init = hdmi_phy_8x74_init,
366 HDMI_CFG(pwr_reg, 8x74),
367 HDMI_CFG(hpd_reg, 8084),
368 HDMI_CFG(pwr_clk, 8x74),
369 HDMI_CFG(hpd_clk, 8x74),
370 .hpd_freq = hpd_clk_freq_8x74,
371};
372
Rob Clark5cf3a452015-07-27 20:52:50 -0400373static struct hdmi_platform_config hdmi_tx_8994_config = {
Stephane Viau3a84f842015-06-19 16:04:47 -0400374 .phy_init = NULL, /* nothing to do for this HDMI PHY 20nm */
375 HDMI_CFG(pwr_reg, 8x74),
Stephane Viau0afbe592015-09-15 08:41:49 -0400376 HDMI_CFG(hpd_reg, none),
377 HDMI_CFG(pwr_clk, 8x74),
378 HDMI_CFG(hpd_clk, 8x74),
379 .hpd_freq = hpd_clk_freq_8x74,
380};
381
382static struct hdmi_platform_config hdmi_tx_8996_config = {
383 .phy_init = NULL,
384 HDMI_CFG(pwr_reg, none),
385 HDMI_CFG(hpd_reg, none),
Stephane Viau3a84f842015-06-19 16:04:47 -0400386 HDMI_CFG(pwr_clk, 8x74),
387 HDMI_CFG(hpd_clk, 8x74),
388 .hpd_freq = hpd_clk_freq_8x74,
389};
390
Stephane Viau5eba5d82015-01-07 16:27:27 -0500391static const struct of_device_id dt_match[] = {
Stephane Viau0afbe592015-09-15 08:41:49 -0400392 { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
Rob Clark5cf3a452015-07-27 20:52:50 -0400393 { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
Stephane Viau5eba5d82015-01-07 16:27:27 -0500394 { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
Rob Clark5cf3a452015-07-27 20:52:50 -0400395 { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
Stephane Viau5eba5d82015-01-07 16:27:27 -0500396 { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
397 { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
398 {}
399};
400
Mark Charleboisfc886102014-08-29 11:05:50 -0700401#ifdef CONFIG_OF
402static int get_gpio(struct device *dev, struct device_node *of_node, const char *name)
403{
404 int gpio = of_get_named_gpio(of_node, name, 0);
405 if (gpio < 0) {
406 char name2[32];
407 snprintf(name2, sizeof(name2), "%s-gpio", name);
408 gpio = of_get_named_gpio(of_node, name2, 0);
409 if (gpio < 0) {
Stephane Viau3a84f842015-06-19 16:04:47 -0400410 DBG("failed to get gpio: %s (%d)", name, gpio);
Mark Charleboisfc886102014-08-29 11:05:50 -0700411 gpio = -1;
412 }
413 }
414 return gpio;
415}
416#endif
417
Rob Clark060530f2014-03-03 14:19:12 -0500418static int hdmi_bind(struct device *dev, struct device *master, void *data)
Rob Clarkc8afe682013-06-26 12:44:06 -0400419{
Rob Clarkd1a717b2014-11-18 08:40:44 -0500420 struct drm_device *drm = dev_get_drvdata(master);
421 struct msm_drm_private *priv = drm->dev_private;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500422 static struct hdmi_platform_config *hdmi_cfg;
Rob Clark067fef32014-11-04 13:33:14 -0500423 struct hdmi *hdmi;
Rob Clarkc8afe682013-06-26 12:44:06 -0400424#ifdef CONFIG_OF
Rob Clark060530f2014-03-03 14:19:12 -0500425 struct device_node *of_node = dev->of_node;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500426 const struct of_device_id *match;
Rob Clarkdada25b2013-12-01 12:12:54 -0500427
Stephane Viau5eba5d82015-01-07 16:27:27 -0500428 match = of_match_node(dt_match, of_node);
429 if (match && match->data) {
430 hdmi_cfg = (struct hdmi_platform_config *)match->data;
431 DBG("hdmi phy: %s", match->compatible);
Rob Clark41e69772013-12-15 16:23:05 -0500432 } else {
433 dev_err(dev, "unknown phy: %s\n", of_node->name);
Stephane Viau5eba5d82015-01-07 16:27:27 -0500434 return -ENXIO;
Rob Clark41e69772013-12-15 16:23:05 -0500435 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500436
Stephane Viau5eba5d82015-01-07 16:27:27 -0500437 hdmi_cfg->mmio_name = "core_physical";
jilai wangc6a57a52015-04-02 17:49:01 -0400438 hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
Stephane Viau5eba5d82015-01-07 16:27:27 -0500439 hdmi_cfg->ddc_clk_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-clk");
440 hdmi_cfg->ddc_data_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-data");
441 hdmi_cfg->hpd_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-hpd");
442 hdmi_cfg->mux_en_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-en");
443 hdmi_cfg->mux_sel_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-sel");
444 hdmi_cfg->mux_lpm_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-lpm");
Rob Clarkdada25b2013-12-01 12:12:54 -0500445
Rob Clarkc8afe682013-06-26 12:44:06 -0400446#else
Stephane Viau5eba5d82015-01-07 16:27:27 -0500447 static struct hdmi_platform_config config = {};
Rob Clarkdada25b2013-12-01 12:12:54 -0500448 static const char *hpd_clk_names[] = {
449 "core_clk", "master_iface_clk", "slave_iface_clk",
450 };
Rob Clarkc8afe682013-06-26 12:44:06 -0400451 if (cpu_is_apq8064()) {
Rob Clarkdada25b2013-12-01 12:12:54 -0500452 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
Rob Clarkc8afe682013-06-26 12:44:06 -0400453 config.phy_init = hdmi_phy_8960_init;
Rob Clarkdada25b2013-12-01 12:12:54 -0500454 config.hpd_reg_names = hpd_reg_names;
455 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
456 config.hpd_clk_names = hpd_clk_names;
457 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
Rob Clarkc8afe682013-06-26 12:44:06 -0400458 config.ddc_clk_gpio = 70;
459 config.ddc_data_gpio = 71;
460 config.hpd_gpio = 72;
Rob Clarkdada25b2013-12-01 12:12:54 -0500461 config.mux_en_gpio = -1;
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500462 config.mux_sel_gpio = -1;
Rob Clarke529c7e2013-11-16 13:07:31 -0500463 } else if (cpu_is_msm8960() || cpu_is_msm8960ab()) {
Rob Clarkdada25b2013-12-01 12:12:54 -0500464 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
Rob Clarkc8afe682013-06-26 12:44:06 -0400465 config.phy_init = hdmi_phy_8960_init;
Rob Clarkdada25b2013-12-01 12:12:54 -0500466 config.hpd_reg_names = hpd_reg_names;
467 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
468 config.hpd_clk_names = hpd_clk_names;
469 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
Rob Clarkc8afe682013-06-26 12:44:06 -0400470 config.ddc_clk_gpio = 100;
471 config.ddc_data_gpio = 101;
472 config.hpd_gpio = 102;
Rob Clarkdada25b2013-12-01 12:12:54 -0500473 config.mux_en_gpio = -1;
474 config.mux_sel_gpio = -1;
Rob Clarkc8afe682013-06-26 12:44:06 -0400475 } else if (cpu_is_msm8x60()) {
Rob Clarkdada25b2013-12-01 12:12:54 -0500476 static const char *hpd_reg_names[] = {
477 "8901_hdmi_mvs", "8901_mpp0"
478 };
Rob Clarkc8afe682013-06-26 12:44:06 -0400479 config.phy_init = hdmi_phy_8x60_init;
Rob Clarkdada25b2013-12-01 12:12:54 -0500480 config.hpd_reg_names = hpd_reg_names;
481 config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names);
482 config.hpd_clk_names = hpd_clk_names;
483 config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names);
Rob Clarkc8afe682013-06-26 12:44:06 -0400484 config.ddc_clk_gpio = 170;
485 config.ddc_data_gpio = 171;
486 config.hpd_gpio = 172;
Rob Clarkdada25b2013-12-01 12:12:54 -0500487 config.mux_en_gpio = -1;
488 config.mux_sel_gpio = -1;
Rob Clarkc8afe682013-06-26 12:44:06 -0400489 }
jilai wangc6a57a52015-04-02 17:49:01 -0400490 config.mmio_name = "hdmi_msm_hdmi_addr";
491 config.qfprom_mmio_name = "hdmi_msm_qfprom_addr";
492
Stephane Viau5eba5d82015-01-07 16:27:27 -0500493 hdmi_cfg = &config;
Rob Clarkc8afe682013-06-26 12:44:06 -0400494#endif
Stephane Viau5eba5d82015-01-07 16:27:27 -0500495 dev->platform_data = hdmi_cfg;
496
Rob Clark067fef32014-11-04 13:33:14 -0500497 hdmi = hdmi_init(to_platform_device(dev));
498 if (IS_ERR(hdmi))
499 return PTR_ERR(hdmi);
Rob Clarkd1a717b2014-11-18 08:40:44 -0500500 priv->hdmi = hdmi;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500501
Rob Clarkc8afe682013-06-26 12:44:06 -0400502 return 0;
503}
504
Rob Clark060530f2014-03-03 14:19:12 -0500505static void hdmi_unbind(struct device *dev, struct device *master,
506 void *data)
507{
Rob Clarkd1a717b2014-11-18 08:40:44 -0500508 struct drm_device *drm = dev_get_drvdata(master);
509 struct msm_drm_private *priv = drm->dev_private;
510 if (priv->hdmi) {
511 hdmi_destroy(priv->hdmi);
512 priv->hdmi = NULL;
513 }
Rob Clark060530f2014-03-03 14:19:12 -0500514}
515
516static const struct component_ops hdmi_ops = {
517 .bind = hdmi_bind,
518 .unbind = hdmi_unbind,
519};
520
521static int hdmi_dev_probe(struct platform_device *pdev)
522{
523 return component_add(&pdev->dev, &hdmi_ops);
524}
525
Rob Clarkc8afe682013-06-26 12:44:06 -0400526static int hdmi_dev_remove(struct platform_device *pdev)
527{
Rob Clark060530f2014-03-03 14:19:12 -0500528 component_del(&pdev->dev, &hdmi_ops);
Rob Clarkc8afe682013-06-26 12:44:06 -0400529 return 0;
530}
531
532static struct platform_driver hdmi_driver = {
533 .probe = hdmi_dev_probe,
534 .remove = hdmi_dev_remove,
Rob Clarkdada25b2013-12-01 12:12:54 -0500535 .driver = {
536 .name = "hdmi_msm",
537 .of_match_table = dt_match,
538 },
Rob Clarkc8afe682013-06-26 12:44:06 -0400539};
540
541void __init hdmi_register(void)
542{
543 platform_driver_register(&hdmi_driver);
544}
545
546void __exit hdmi_unregister(void)
547{
548 platform_driver_unregister(&hdmi_driver);
549}