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