xref: /openbmc/linux/drivers/gpu/drm/msm/hdmi/hdmi.c (revision d4fd6347)
1 /*
2  * Copyright (c) 2014 The Linux Foundation. All rights reserved.
3  * 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 
19 #include <linux/of_irq.h>
20 #include <linux/of_gpio.h>
21 
22 #include <sound/hdmi-codec.h>
23 #include "hdmi.h"
24 
25 void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on)
26 {
27 	uint32_t ctrl = 0;
28 	unsigned long flags;
29 
30 	spin_lock_irqsave(&hdmi->reg_lock, flags);
31 	if (power_on) {
32 		ctrl |= HDMI_CTRL_ENABLE;
33 		if (!hdmi->hdmi_mode) {
34 			ctrl |= HDMI_CTRL_HDMI;
35 			hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
36 			ctrl &= ~HDMI_CTRL_HDMI;
37 		} else {
38 			ctrl |= HDMI_CTRL_HDMI;
39 		}
40 	} else {
41 		ctrl = HDMI_CTRL_HDMI;
42 	}
43 
44 	hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
45 	spin_unlock_irqrestore(&hdmi->reg_lock, flags);
46 	DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
47 			power_on ? "Enable" : "Disable", ctrl);
48 }
49 
50 static irqreturn_t msm_hdmi_irq(int irq, void *dev_id)
51 {
52 	struct hdmi *hdmi = dev_id;
53 
54 	/* Process HPD: */
55 	msm_hdmi_connector_irq(hdmi->connector);
56 
57 	/* Process DDC: */
58 	msm_hdmi_i2c_irq(hdmi->i2c);
59 
60 	/* Process HDCP: */
61 	if (hdmi->hdcp_ctrl)
62 		msm_hdmi_hdcp_irq(hdmi->hdcp_ctrl);
63 
64 	/* TODO audio.. */
65 
66 	return IRQ_HANDLED;
67 }
68 
69 static void msm_hdmi_destroy(struct hdmi *hdmi)
70 {
71 	/*
72 	 * at this point, hpd has been disabled,
73 	 * after flush workq, it's safe to deinit hdcp
74 	 */
75 	if (hdmi->workq) {
76 		flush_workqueue(hdmi->workq);
77 		destroy_workqueue(hdmi->workq);
78 	}
79 	msm_hdmi_hdcp_destroy(hdmi);
80 
81 	if (hdmi->phy_dev) {
82 		put_device(hdmi->phy_dev);
83 		hdmi->phy = NULL;
84 		hdmi->phy_dev = NULL;
85 	}
86 
87 	if (hdmi->i2c)
88 		msm_hdmi_i2c_destroy(hdmi->i2c);
89 
90 	platform_set_drvdata(hdmi->pdev, NULL);
91 }
92 
93 static int msm_hdmi_get_phy(struct hdmi *hdmi)
94 {
95 	struct platform_device *pdev = hdmi->pdev;
96 	struct platform_device *phy_pdev;
97 	struct device_node *phy_node;
98 
99 	phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
100 	if (!phy_node) {
101 		DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n");
102 		return -ENXIO;
103 	}
104 
105 	phy_pdev = of_find_device_by_node(phy_node);
106 	if (phy_pdev)
107 		hdmi->phy = platform_get_drvdata(phy_pdev);
108 
109 	of_node_put(phy_node);
110 
111 	if (!phy_pdev || !hdmi->phy) {
112 		DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
113 		return -EPROBE_DEFER;
114 	}
115 
116 	hdmi->phy_dev = get_device(&phy_pdev->dev);
117 
118 	return 0;
119 }
120 
121 /* construct hdmi at bind/probe time, grab all the resources.  If
122  * we are to EPROBE_DEFER we want to do it here, rather than later
123  * at modeset_init() time
124  */
125 static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
126 {
127 	struct hdmi_platform_config *config = pdev->dev.platform_data;
128 	struct hdmi *hdmi = NULL;
129 	struct resource *res;
130 	int i, ret;
131 
132 	hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
133 	if (!hdmi) {
134 		ret = -ENOMEM;
135 		goto fail;
136 	}
137 
138 	hdmi->pdev = pdev;
139 	hdmi->config = config;
140 	spin_lock_init(&hdmi->reg_lock);
141 
142 	hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
143 	if (IS_ERR(hdmi->mmio)) {
144 		ret = PTR_ERR(hdmi->mmio);
145 		goto fail;
146 	}
147 
148 	/* HDCP needs physical address of hdmi register */
149 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
150 		config->mmio_name);
151 	hdmi->mmio_phy_addr = res->start;
152 
153 	hdmi->qfprom_mmio = msm_ioremap(pdev,
154 		config->qfprom_mmio_name, "HDMI_QFPROM");
155 	if (IS_ERR(hdmi->qfprom_mmio)) {
156 		DRM_DEV_INFO(&pdev->dev, "can't find qfprom resource\n");
157 		hdmi->qfprom_mmio = NULL;
158 	}
159 
160 	hdmi->hpd_regs = devm_kcalloc(&pdev->dev,
161 				      config->hpd_reg_cnt,
162 				      sizeof(hdmi->hpd_regs[0]),
163 				      GFP_KERNEL);
164 	if (!hdmi->hpd_regs) {
165 		ret = -ENOMEM;
166 		goto fail;
167 	}
168 	for (i = 0; i < config->hpd_reg_cnt; i++) {
169 		struct regulator *reg;
170 
171 		reg = devm_regulator_get(&pdev->dev,
172 				config->hpd_reg_names[i]);
173 		if (IS_ERR(reg)) {
174 			ret = PTR_ERR(reg);
175 			DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
176 					config->hpd_reg_names[i], ret);
177 			goto fail;
178 		}
179 
180 		hdmi->hpd_regs[i] = reg;
181 	}
182 
183 	hdmi->pwr_regs = devm_kcalloc(&pdev->dev,
184 				      config->pwr_reg_cnt,
185 				      sizeof(hdmi->pwr_regs[0]),
186 				      GFP_KERNEL);
187 	if (!hdmi->pwr_regs) {
188 		ret = -ENOMEM;
189 		goto fail;
190 	}
191 	for (i = 0; i < config->pwr_reg_cnt; i++) {
192 		struct regulator *reg;
193 
194 		reg = devm_regulator_get(&pdev->dev,
195 				config->pwr_reg_names[i]);
196 		if (IS_ERR(reg)) {
197 			ret = PTR_ERR(reg);
198 			DRM_DEV_ERROR(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
199 					config->pwr_reg_names[i], ret);
200 			goto fail;
201 		}
202 
203 		hdmi->pwr_regs[i] = reg;
204 	}
205 
206 	hdmi->hpd_clks = devm_kcalloc(&pdev->dev,
207 				      config->hpd_clk_cnt,
208 				      sizeof(hdmi->hpd_clks[0]),
209 				      GFP_KERNEL);
210 	if (!hdmi->hpd_clks) {
211 		ret = -ENOMEM;
212 		goto fail;
213 	}
214 	for (i = 0; i < config->hpd_clk_cnt; i++) {
215 		struct clk *clk;
216 
217 		clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
218 		if (IS_ERR(clk)) {
219 			ret = PTR_ERR(clk);
220 			DRM_DEV_ERROR(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
221 					config->hpd_clk_names[i], ret);
222 			goto fail;
223 		}
224 
225 		hdmi->hpd_clks[i] = clk;
226 	}
227 
228 	hdmi->pwr_clks = devm_kcalloc(&pdev->dev,
229 				      config->pwr_clk_cnt,
230 				      sizeof(hdmi->pwr_clks[0]),
231 				      GFP_KERNEL);
232 	if (!hdmi->pwr_clks) {
233 		ret = -ENOMEM;
234 		goto fail;
235 	}
236 	for (i = 0; i < config->pwr_clk_cnt; i++) {
237 		struct clk *clk;
238 
239 		clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
240 		if (IS_ERR(clk)) {
241 			ret = PTR_ERR(clk);
242 			DRM_DEV_ERROR(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
243 					config->pwr_clk_names[i], ret);
244 			goto fail;
245 		}
246 
247 		hdmi->pwr_clks[i] = clk;
248 	}
249 
250 	pm_runtime_enable(&pdev->dev);
251 
252 	hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
253 
254 	hdmi->i2c = msm_hdmi_i2c_init(hdmi);
255 	if (IS_ERR(hdmi->i2c)) {
256 		ret = PTR_ERR(hdmi->i2c);
257 		DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret);
258 		hdmi->i2c = NULL;
259 		goto fail;
260 	}
261 
262 	ret = msm_hdmi_get_phy(hdmi);
263 	if (ret) {
264 		DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n");
265 		goto fail;
266 	}
267 
268 	hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
269 	if (IS_ERR(hdmi->hdcp_ctrl)) {
270 		dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
271 		hdmi->hdcp_ctrl = NULL;
272 	}
273 
274 	return hdmi;
275 
276 fail:
277 	if (hdmi)
278 		msm_hdmi_destroy(hdmi);
279 
280 	return ERR_PTR(ret);
281 }
282 
283 /* Second part of initialization, the drm/kms level modeset_init,
284  * constructs/initializes mode objects, etc, is called from master
285  * driver (not hdmi sub-device's probe/bind!)
286  *
287  * Any resource (regulator/clk/etc) which could be missing at boot
288  * should be handled in msm_hdmi_init() so that failure happens from
289  * hdmi sub-device's probe.
290  */
291 int msm_hdmi_modeset_init(struct hdmi *hdmi,
292 		struct drm_device *dev, struct drm_encoder *encoder)
293 {
294 	struct msm_drm_private *priv = dev->dev_private;
295 	struct platform_device *pdev = hdmi->pdev;
296 	int ret;
297 
298 	hdmi->dev = dev;
299 	hdmi->encoder = encoder;
300 
301 	hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
302 
303 	hdmi->bridge = msm_hdmi_bridge_init(hdmi);
304 	if (IS_ERR(hdmi->bridge)) {
305 		ret = PTR_ERR(hdmi->bridge);
306 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret);
307 		hdmi->bridge = NULL;
308 		goto fail;
309 	}
310 
311 	hdmi->connector = msm_hdmi_connector_init(hdmi);
312 	if (IS_ERR(hdmi->connector)) {
313 		ret = PTR_ERR(hdmi->connector);
314 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret);
315 		hdmi->connector = NULL;
316 		goto fail;
317 	}
318 
319 	hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
320 	if (hdmi->irq < 0) {
321 		ret = hdmi->irq;
322 		DRM_DEV_ERROR(dev->dev, "failed to get irq: %d\n", ret);
323 		goto fail;
324 	}
325 
326 	ret = devm_request_irq(&pdev->dev, hdmi->irq,
327 			msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
328 			"hdmi_isr", hdmi);
329 	if (ret < 0) {
330 		DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
331 				hdmi->irq, ret);
332 		goto fail;
333 	}
334 
335 	ret = msm_hdmi_hpd_enable(hdmi->connector);
336 	if (ret < 0) {
337 		DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
338 		goto fail;
339 	}
340 
341 	encoder->bridge = hdmi->bridge;
342 
343 	priv->bridges[priv->num_bridges++]       = hdmi->bridge;
344 	priv->connectors[priv->num_connectors++] = hdmi->connector;
345 
346 	platform_set_drvdata(pdev, hdmi);
347 
348 	return 0;
349 
350 fail:
351 	/* bridge is normally destroyed by drm: */
352 	if (hdmi->bridge) {
353 		msm_hdmi_bridge_destroy(hdmi->bridge);
354 		hdmi->bridge = NULL;
355 	}
356 	if (hdmi->connector) {
357 		hdmi->connector->funcs->destroy(hdmi->connector);
358 		hdmi->connector = NULL;
359 	}
360 
361 	return ret;
362 }
363 
364 /*
365  * The hdmi device:
366  */
367 
368 #define HDMI_CFG(item, entry) \
369 	.item ## _names = item ##_names_ ## entry, \
370 	.item ## _cnt   = ARRAY_SIZE(item ## _names_ ## entry)
371 
372 static const char *pwr_reg_names_none[] = {};
373 static const char *hpd_reg_names_none[] = {};
374 
375 static struct hdmi_platform_config hdmi_tx_8660_config;
376 
377 static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
378 static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
379 
380 static struct hdmi_platform_config hdmi_tx_8960_config = {
381 		HDMI_CFG(hpd_reg, 8960),
382 		HDMI_CFG(hpd_clk, 8960),
383 };
384 
385 static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
386 static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
387 static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
388 static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
389 static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
390 
391 static struct hdmi_platform_config hdmi_tx_8974_config = {
392 		HDMI_CFG(pwr_reg, 8x74),
393 		HDMI_CFG(hpd_reg, 8x74),
394 		HDMI_CFG(pwr_clk, 8x74),
395 		HDMI_CFG(hpd_clk, 8x74),
396 		.hpd_freq      = hpd_clk_freq_8x74,
397 };
398 
399 static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
400 
401 static struct hdmi_platform_config hdmi_tx_8084_config = {
402 		HDMI_CFG(pwr_reg, 8x74),
403 		HDMI_CFG(hpd_reg, 8084),
404 		HDMI_CFG(pwr_clk, 8x74),
405 		HDMI_CFG(hpd_clk, 8x74),
406 		.hpd_freq      = hpd_clk_freq_8x74,
407 };
408 
409 static struct hdmi_platform_config hdmi_tx_8994_config = {
410 		HDMI_CFG(pwr_reg, 8x74),
411 		HDMI_CFG(hpd_reg, none),
412 		HDMI_CFG(pwr_clk, 8x74),
413 		HDMI_CFG(hpd_clk, 8x74),
414 		.hpd_freq      = hpd_clk_freq_8x74,
415 };
416 
417 static struct hdmi_platform_config hdmi_tx_8996_config = {
418 		HDMI_CFG(pwr_reg, none),
419 		HDMI_CFG(hpd_reg, none),
420 		HDMI_CFG(pwr_clk, 8x74),
421 		HDMI_CFG(hpd_clk, 8x74),
422 		.hpd_freq      = hpd_clk_freq_8x74,
423 };
424 
425 static const struct {
426 	const char *name;
427 	const bool output;
428 	const int value;
429 	const char *label;
430 } msm_hdmi_gpio_pdata[] = {
431 	{ "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
432 	{ "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
433 	{ "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
434 	{ "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
435 	{ "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
436 	{ "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
437 };
438 
439 static int msm_hdmi_get_gpio(struct device_node *of_node, const char *name)
440 {
441 	int gpio;
442 
443 	/* try with the gpio names as in the table (downstream bindings) */
444 	gpio = of_get_named_gpio(of_node, name, 0);
445 	if (gpio < 0) {
446 		char name2[32];
447 
448 		/* try with the gpio names as in the upstream bindings */
449 		snprintf(name2, sizeof(name2), "%s-gpios", name);
450 		gpio = of_get_named_gpio(of_node, name2, 0);
451 		if (gpio < 0) {
452 			char name3[32];
453 
454 			/*
455 			 * try again after stripping out the "qcom,hdmi-tx"
456 			 * prefix. This is mainly to match "hpd-gpios" used
457 			 * in the upstream bindings
458 			 */
459 			if (sscanf(name2, "qcom,hdmi-tx-%s", name3))
460 				gpio = of_get_named_gpio(of_node, name3, 0);
461 		}
462 
463 		if (gpio < 0) {
464 			DBG("failed to get gpio: %s (%d)", name, gpio);
465 			gpio = -1;
466 		}
467 	}
468 	return gpio;
469 }
470 
471 /*
472  * HDMI audio codec callbacks
473  */
474 static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
475 				    struct hdmi_codec_daifmt *daifmt,
476 				    struct hdmi_codec_params *params)
477 {
478 	struct hdmi *hdmi = dev_get_drvdata(dev);
479 	unsigned int chan;
480 	unsigned int channel_allocation = 0;
481 	unsigned int rate;
482 	unsigned int level_shift  = 0; /* 0dB */
483 	bool down_mix = false;
484 
485 	DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
486 		 params->sample_width, params->cea.channels);
487 
488 	switch (params->cea.channels) {
489 	case 2:
490 		/* FR and FL speakers */
491 		channel_allocation  = 0;
492 		chan = MSM_HDMI_AUDIO_CHANNEL_2;
493 		break;
494 	case 4:
495 		/* FC, LFE, FR and FL speakers */
496 		channel_allocation  = 0x3;
497 		chan = MSM_HDMI_AUDIO_CHANNEL_4;
498 		break;
499 	case 6:
500 		/* RR, RL, FC, LFE, FR and FL speakers */
501 		channel_allocation  = 0x0B;
502 		chan = MSM_HDMI_AUDIO_CHANNEL_6;
503 		break;
504 	case 8:
505 		/* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
506 		channel_allocation  = 0x1F;
507 		chan = MSM_HDMI_AUDIO_CHANNEL_8;
508 		break;
509 	default:
510 		return -EINVAL;
511 	}
512 
513 	switch (params->sample_rate) {
514 	case 32000:
515 		rate = HDMI_SAMPLE_RATE_32KHZ;
516 		break;
517 	case 44100:
518 		rate = HDMI_SAMPLE_RATE_44_1KHZ;
519 		break;
520 	case 48000:
521 		rate = HDMI_SAMPLE_RATE_48KHZ;
522 		break;
523 	case 88200:
524 		rate = HDMI_SAMPLE_RATE_88_2KHZ;
525 		break;
526 	case 96000:
527 		rate = HDMI_SAMPLE_RATE_96KHZ;
528 		break;
529 	case 176400:
530 		rate = HDMI_SAMPLE_RATE_176_4KHZ;
531 		break;
532 	case 192000:
533 		rate = HDMI_SAMPLE_RATE_192KHZ;
534 		break;
535 	default:
536 		DRM_DEV_ERROR(dev, "rate[%d] not supported!\n",
537 			params->sample_rate);
538 		return -EINVAL;
539 	}
540 
541 	msm_hdmi_audio_set_sample_rate(hdmi, rate);
542 	msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
543 			      level_shift, down_mix);
544 
545 	return 0;
546 }
547 
548 static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
549 {
550 	struct hdmi *hdmi = dev_get_drvdata(dev);
551 
552 	msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
553 }
554 
555 static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
556 	.hw_params = msm_hdmi_audio_hw_params,
557 	.audio_shutdown = msm_hdmi_audio_shutdown,
558 };
559 
560 static struct hdmi_codec_pdata codec_data = {
561 	.ops = &msm_hdmi_audio_codec_ops,
562 	.max_i2s_channels = 8,
563 	.i2s = 1,
564 };
565 
566 static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
567 {
568 	hdmi->audio_pdev = platform_device_register_data(dev,
569 							 HDMI_CODEC_DRV_NAME,
570 							 PLATFORM_DEVID_AUTO,
571 							 &codec_data,
572 							 sizeof(codec_data));
573 	return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
574 }
575 
576 static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
577 {
578 	struct drm_device *drm = dev_get_drvdata(master);
579 	struct msm_drm_private *priv = drm->dev_private;
580 	struct hdmi_platform_config *hdmi_cfg;
581 	struct hdmi *hdmi;
582 	struct device_node *of_node = dev->of_node;
583 	int i, err;
584 
585 	hdmi_cfg = (struct hdmi_platform_config *)
586 			of_device_get_match_data(dev);
587 	if (!hdmi_cfg) {
588 		DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node);
589 		return -ENXIO;
590 	}
591 
592 	hdmi_cfg->mmio_name     = "core_physical";
593 	hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
594 
595 	for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
596 		hdmi_cfg->gpios[i].num = msm_hdmi_get_gpio(of_node,
597 						msm_hdmi_gpio_pdata[i].name);
598 		hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
599 		hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
600 		hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label;
601 	}
602 
603 	dev->platform_data = hdmi_cfg;
604 
605 	hdmi = msm_hdmi_init(to_platform_device(dev));
606 	if (IS_ERR(hdmi))
607 		return PTR_ERR(hdmi);
608 	priv->hdmi = hdmi;
609 
610 	err = msm_hdmi_register_audio_driver(hdmi, dev);
611 	if (err) {
612 		DRM_ERROR("Failed to attach an audio codec %d\n", err);
613 		hdmi->audio_pdev = NULL;
614 	}
615 
616 	return 0;
617 }
618 
619 static void msm_hdmi_unbind(struct device *dev, struct device *master,
620 		void *data)
621 {
622 	struct drm_device *drm = dev_get_drvdata(master);
623 	struct msm_drm_private *priv = drm->dev_private;
624 	if (priv->hdmi) {
625 		if (priv->hdmi->audio_pdev)
626 			platform_device_unregister(priv->hdmi->audio_pdev);
627 
628 		msm_hdmi_destroy(priv->hdmi);
629 		priv->hdmi = NULL;
630 	}
631 }
632 
633 static const struct component_ops msm_hdmi_ops = {
634 		.bind   = msm_hdmi_bind,
635 		.unbind = msm_hdmi_unbind,
636 };
637 
638 static int msm_hdmi_dev_probe(struct platform_device *pdev)
639 {
640 	return component_add(&pdev->dev, &msm_hdmi_ops);
641 }
642 
643 static int msm_hdmi_dev_remove(struct platform_device *pdev)
644 {
645 	component_del(&pdev->dev, &msm_hdmi_ops);
646 	return 0;
647 }
648 
649 static const struct of_device_id msm_hdmi_dt_match[] = {
650 	{ .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
651 	{ .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
652 	{ .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
653 	{ .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
654 	{ .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
655 	{ .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
656 	{}
657 };
658 
659 static struct platform_driver msm_hdmi_driver = {
660 	.probe = msm_hdmi_dev_probe,
661 	.remove = msm_hdmi_dev_remove,
662 	.driver = {
663 		.name = "hdmi_msm",
664 		.of_match_table = msm_hdmi_dt_match,
665 	},
666 };
667 
668 void __init msm_hdmi_register(void)
669 {
670 	msm_hdmi_phy_driver_register();
671 	platform_driver_register(&msm_hdmi_driver);
672 }
673 
674 void __exit msm_hdmi_unregister(void)
675 {
676 	platform_driver_unregister(&msm_hdmi_driver);
677 	msm_hdmi_phy_driver_unregister();
678 }
679