xref: /linux/drivers/gpu/drm/msm/hdmi/hdmi.c (revision dec1c62e91ba268ab2a6e339d4d7a59287d5eba1)
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 	if (!res) {
146 		ret = -EINVAL;
147 		goto fail;
148 	}
149 	hdmi->mmio_phy_addr = res->start;
150 
151 	hdmi->qfprom_mmio = msm_ioremap(pdev, config->qfprom_mmio_name);
152 	if (IS_ERR(hdmi->qfprom_mmio)) {
153 		DRM_DEV_INFO(&pdev->dev, "can't find qfprom resource\n");
154 		hdmi->qfprom_mmio = NULL;
155 	}
156 
157 	hdmi->hpd_regs = devm_kcalloc(&pdev->dev,
158 				      config->hpd_reg_cnt,
159 				      sizeof(hdmi->hpd_regs[0]),
160 				      GFP_KERNEL);
161 	if (!hdmi->hpd_regs) {
162 		ret = -ENOMEM;
163 		goto fail;
164 	}
165 	for (i = 0; i < config->hpd_reg_cnt; i++)
166 		hdmi->hpd_regs[i].supply = config->hpd_reg_names[i];
167 
168 	ret = devm_regulator_bulk_get(&pdev->dev, config->hpd_reg_cnt, hdmi->hpd_regs);
169 	if (ret) {
170 		DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %d\n", ret);
171 		goto fail;
172 	}
173 
174 	hdmi->pwr_regs = devm_kcalloc(&pdev->dev,
175 				      config->pwr_reg_cnt,
176 				      sizeof(hdmi->pwr_regs[0]),
177 				      GFP_KERNEL);
178 	if (!hdmi->pwr_regs) {
179 		ret = -ENOMEM;
180 		goto fail;
181 	}
182 
183 	ret = devm_regulator_bulk_get(&pdev->dev, config->pwr_reg_cnt, hdmi->pwr_regs);
184 	if (ret) {
185 		DRM_DEV_ERROR(&pdev->dev, "failed to get pwr regulator: %d\n", ret);
186 		goto fail;
187 	}
188 
189 	hdmi->hpd_clks = devm_kcalloc(&pdev->dev,
190 				      config->hpd_clk_cnt,
191 				      sizeof(hdmi->hpd_clks[0]),
192 				      GFP_KERNEL);
193 	if (!hdmi->hpd_clks) {
194 		ret = -ENOMEM;
195 		goto fail;
196 	}
197 	for (i = 0; i < config->hpd_clk_cnt; i++) {
198 		struct clk *clk;
199 
200 		clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
201 		if (IS_ERR(clk)) {
202 			ret = PTR_ERR(clk);
203 			DRM_DEV_ERROR(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
204 					config->hpd_clk_names[i], ret);
205 			goto fail;
206 		}
207 
208 		hdmi->hpd_clks[i] = clk;
209 	}
210 
211 	hdmi->pwr_clks = devm_kcalloc(&pdev->dev,
212 				      config->pwr_clk_cnt,
213 				      sizeof(hdmi->pwr_clks[0]),
214 				      GFP_KERNEL);
215 	if (!hdmi->pwr_clks) {
216 		ret = -ENOMEM;
217 		goto fail;
218 	}
219 	for (i = 0; i < config->pwr_clk_cnt; i++) {
220 		struct clk *clk;
221 
222 		clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
223 		if (IS_ERR(clk)) {
224 			ret = PTR_ERR(clk);
225 			DRM_DEV_ERROR(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
226 					config->pwr_clk_names[i], ret);
227 			goto fail;
228 		}
229 
230 		hdmi->pwr_clks[i] = clk;
231 	}
232 
233 	pm_runtime_enable(&pdev->dev);
234 
235 	hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
236 
237 	hdmi->i2c = msm_hdmi_i2c_init(hdmi);
238 	if (IS_ERR(hdmi->i2c)) {
239 		ret = PTR_ERR(hdmi->i2c);
240 		DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret);
241 		hdmi->i2c = NULL;
242 		goto fail;
243 	}
244 
245 	ret = msm_hdmi_get_phy(hdmi);
246 	if (ret) {
247 		DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n");
248 		goto fail;
249 	}
250 
251 	hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
252 	if (IS_ERR(hdmi->hdcp_ctrl)) {
253 		dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
254 		hdmi->hdcp_ctrl = NULL;
255 	}
256 
257 	return hdmi;
258 
259 fail:
260 	if (hdmi)
261 		msm_hdmi_destroy(hdmi);
262 
263 	return ERR_PTR(ret);
264 }
265 
266 /* Second part of initialization, the drm/kms level modeset_init,
267  * constructs/initializes mode objects, etc, is called from master
268  * driver (not hdmi sub-device's probe/bind!)
269  *
270  * Any resource (regulator/clk/etc) which could be missing at boot
271  * should be handled in msm_hdmi_init() so that failure happens from
272  * hdmi sub-device's probe.
273  */
274 int msm_hdmi_modeset_init(struct hdmi *hdmi,
275 		struct drm_device *dev, struct drm_encoder *encoder)
276 {
277 	struct msm_drm_private *priv = dev->dev_private;
278 	struct platform_device *pdev = hdmi->pdev;
279 	int ret;
280 
281 	hdmi->dev = dev;
282 	hdmi->encoder = encoder;
283 
284 	hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
285 
286 	hdmi->bridge = msm_hdmi_bridge_init(hdmi);
287 	if (IS_ERR(hdmi->bridge)) {
288 		ret = PTR_ERR(hdmi->bridge);
289 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret);
290 		hdmi->bridge = NULL;
291 		goto fail;
292 	}
293 
294 	hdmi->connector = drm_bridge_connector_init(hdmi->dev, encoder);
295 	if (IS_ERR(hdmi->connector)) {
296 		ret = PTR_ERR(hdmi->connector);
297 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret);
298 		hdmi->connector = NULL;
299 		goto fail;
300 	}
301 
302 	drm_connector_attach_encoder(hdmi->connector, hdmi->encoder);
303 
304 	hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
305 	if (!hdmi->irq) {
306 		ret = -EINVAL;
307 		DRM_DEV_ERROR(dev->dev, "failed to get irq\n");
308 		goto fail;
309 	}
310 
311 	ret = devm_request_irq(&pdev->dev, hdmi->irq,
312 			msm_hdmi_irq, IRQF_TRIGGER_HIGH,
313 			"hdmi_isr", hdmi);
314 	if (ret < 0) {
315 		DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
316 				hdmi->irq, ret);
317 		goto fail;
318 	}
319 
320 	drm_bridge_connector_enable_hpd(hdmi->connector);
321 
322 	ret = msm_hdmi_hpd_enable(hdmi->bridge);
323 	if (ret < 0) {
324 		DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
325 		goto fail;
326 	}
327 
328 	priv->bridges[priv->num_bridges++]       = hdmi->bridge;
329 
330 	platform_set_drvdata(pdev, hdmi);
331 
332 	return 0;
333 
334 fail:
335 	/* bridge is normally destroyed by drm: */
336 	if (hdmi->bridge) {
337 		msm_hdmi_bridge_destroy(hdmi->bridge);
338 		hdmi->bridge = NULL;
339 	}
340 	if (hdmi->connector) {
341 		hdmi->connector->funcs->destroy(hdmi->connector);
342 		hdmi->connector = NULL;
343 	}
344 
345 	return ret;
346 }
347 
348 /*
349  * The hdmi device:
350  */
351 
352 #define HDMI_CFG(item, entry) \
353 	.item ## _names = item ##_names_ ## entry, \
354 	.item ## _cnt   = ARRAY_SIZE(item ## _names_ ## entry)
355 
356 static const char *pwr_reg_names_none[] = {};
357 static const char *hpd_reg_names_none[] = {};
358 
359 static struct hdmi_platform_config hdmi_tx_8660_config;
360 
361 static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
362 static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
363 
364 static struct hdmi_platform_config hdmi_tx_8960_config = {
365 		HDMI_CFG(hpd_reg, 8960),
366 		HDMI_CFG(hpd_clk, 8960),
367 };
368 
369 static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
370 static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
371 static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
372 static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
373 static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
374 
375 static struct hdmi_platform_config hdmi_tx_8974_config = {
376 		HDMI_CFG(pwr_reg, 8x74),
377 		HDMI_CFG(hpd_reg, 8x74),
378 		HDMI_CFG(pwr_clk, 8x74),
379 		HDMI_CFG(hpd_clk, 8x74),
380 		.hpd_freq      = hpd_clk_freq_8x74,
381 };
382 
383 static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
384 
385 static struct hdmi_platform_config hdmi_tx_8084_config = {
386 		HDMI_CFG(pwr_reg, 8x74),
387 		HDMI_CFG(hpd_reg, 8084),
388 		HDMI_CFG(pwr_clk, 8x74),
389 		HDMI_CFG(hpd_clk, 8x74),
390 		.hpd_freq      = hpd_clk_freq_8x74,
391 };
392 
393 static struct hdmi_platform_config hdmi_tx_8994_config = {
394 		HDMI_CFG(pwr_reg, 8x74),
395 		HDMI_CFG(hpd_reg, none),
396 		HDMI_CFG(pwr_clk, 8x74),
397 		HDMI_CFG(hpd_clk, 8x74),
398 		.hpd_freq      = hpd_clk_freq_8x74,
399 };
400 
401 static struct hdmi_platform_config hdmi_tx_8996_config = {
402 		HDMI_CFG(pwr_reg, none),
403 		HDMI_CFG(hpd_reg, none),
404 		HDMI_CFG(pwr_clk, 8x74),
405 		HDMI_CFG(hpd_clk, 8x74),
406 		.hpd_freq      = hpd_clk_freq_8x74,
407 };
408 
409 static const struct {
410 	const char *name;
411 	const bool output;
412 	const int value;
413 	const char *label;
414 } msm_hdmi_gpio_pdata[] = {
415 	{ "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
416 	{ "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
417 	{ "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
418 	{ "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
419 	{ "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
420 	{ "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
421 };
422 
423 /*
424  * HDMI audio codec callbacks
425  */
426 static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
427 				    struct hdmi_codec_daifmt *daifmt,
428 				    struct hdmi_codec_params *params)
429 {
430 	struct hdmi *hdmi = dev_get_drvdata(dev);
431 	unsigned int chan;
432 	unsigned int channel_allocation = 0;
433 	unsigned int rate;
434 	unsigned int level_shift  = 0; /* 0dB */
435 	bool down_mix = false;
436 
437 	DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
438 		 params->sample_width, params->cea.channels);
439 
440 	switch (params->cea.channels) {
441 	case 2:
442 		/* FR and FL speakers */
443 		channel_allocation  = 0;
444 		chan = MSM_HDMI_AUDIO_CHANNEL_2;
445 		break;
446 	case 4:
447 		/* FC, LFE, FR and FL speakers */
448 		channel_allocation  = 0x3;
449 		chan = MSM_HDMI_AUDIO_CHANNEL_4;
450 		break;
451 	case 6:
452 		/* RR, RL, FC, LFE, FR and FL speakers */
453 		channel_allocation  = 0x0B;
454 		chan = MSM_HDMI_AUDIO_CHANNEL_6;
455 		break;
456 	case 8:
457 		/* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
458 		channel_allocation  = 0x1F;
459 		chan = MSM_HDMI_AUDIO_CHANNEL_8;
460 		break;
461 	default:
462 		return -EINVAL;
463 	}
464 
465 	switch (params->sample_rate) {
466 	case 32000:
467 		rate = HDMI_SAMPLE_RATE_32KHZ;
468 		break;
469 	case 44100:
470 		rate = HDMI_SAMPLE_RATE_44_1KHZ;
471 		break;
472 	case 48000:
473 		rate = HDMI_SAMPLE_RATE_48KHZ;
474 		break;
475 	case 88200:
476 		rate = HDMI_SAMPLE_RATE_88_2KHZ;
477 		break;
478 	case 96000:
479 		rate = HDMI_SAMPLE_RATE_96KHZ;
480 		break;
481 	case 176400:
482 		rate = HDMI_SAMPLE_RATE_176_4KHZ;
483 		break;
484 	case 192000:
485 		rate = HDMI_SAMPLE_RATE_192KHZ;
486 		break;
487 	default:
488 		DRM_DEV_ERROR(dev, "rate[%d] not supported!\n",
489 			params->sample_rate);
490 		return -EINVAL;
491 	}
492 
493 	msm_hdmi_audio_set_sample_rate(hdmi, rate);
494 	msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
495 			      level_shift, down_mix);
496 
497 	return 0;
498 }
499 
500 static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
501 {
502 	struct hdmi *hdmi = dev_get_drvdata(dev);
503 
504 	msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
505 }
506 
507 static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
508 	.hw_params = msm_hdmi_audio_hw_params,
509 	.audio_shutdown = msm_hdmi_audio_shutdown,
510 };
511 
512 static struct hdmi_codec_pdata codec_data = {
513 	.ops = &msm_hdmi_audio_codec_ops,
514 	.max_i2s_channels = 8,
515 	.i2s = 1,
516 };
517 
518 static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
519 {
520 	hdmi->audio_pdev = platform_device_register_data(dev,
521 							 HDMI_CODEC_DRV_NAME,
522 							 PLATFORM_DEVID_AUTO,
523 							 &codec_data,
524 							 sizeof(codec_data));
525 	return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
526 }
527 
528 static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
529 {
530 	struct msm_drm_private *priv = dev_get_drvdata(master);
531 	struct hdmi_platform_config *hdmi_cfg;
532 	struct hdmi *hdmi;
533 	struct device_node *of_node = dev->of_node;
534 	int i, err;
535 
536 	hdmi_cfg = (struct hdmi_platform_config *)
537 			of_device_get_match_data(dev);
538 	if (!hdmi_cfg) {
539 		DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node);
540 		return -ENXIO;
541 	}
542 
543 	hdmi_cfg->mmio_name     = "core_physical";
544 	hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
545 
546 	for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
547 		const char *name = msm_hdmi_gpio_pdata[i].name;
548 		struct gpio_desc *gpiod;
549 
550 		/*
551 		 * We are fetching the GPIO lines "as is" since the connector
552 		 * code is enabling and disabling the lines. Until that point
553 		 * the power-on default value will be kept.
554 		 */
555 		gpiod = devm_gpiod_get_optional(dev, name, GPIOD_ASIS);
556 		/* This will catch e.g. -PROBE_DEFER */
557 		if (IS_ERR(gpiod))
558 			return PTR_ERR(gpiod);
559 		if (!gpiod) {
560 			/* Try a second time, stripping down the name */
561 			char name3[32];
562 
563 			/*
564 			 * Try again after stripping out the "qcom,hdmi-tx"
565 			 * prefix. This is mainly to match "hpd-gpios" used
566 			 * in the upstream bindings.
567 			 */
568 			if (sscanf(name, "qcom,hdmi-tx-%s", name3))
569 				gpiod = devm_gpiod_get_optional(dev, name3, GPIOD_ASIS);
570 			if (IS_ERR(gpiod))
571 				return PTR_ERR(gpiod);
572 			if (!gpiod)
573 				DBG("failed to get gpio: %s", name);
574 		}
575 		hdmi_cfg->gpios[i].gpiod = gpiod;
576 		if (gpiod)
577 			gpiod_set_consumer_name(gpiod, msm_hdmi_gpio_pdata[i].label);
578 		hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
579 		hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
580 	}
581 
582 	dev->platform_data = hdmi_cfg;
583 
584 	hdmi = msm_hdmi_init(to_platform_device(dev));
585 	if (IS_ERR(hdmi))
586 		return PTR_ERR(hdmi);
587 	priv->hdmi = hdmi;
588 
589 	err = msm_hdmi_register_audio_driver(hdmi, dev);
590 	if (err) {
591 		DRM_ERROR("Failed to attach an audio codec %d\n", err);
592 		hdmi->audio_pdev = NULL;
593 	}
594 
595 	return 0;
596 }
597 
598 static void msm_hdmi_unbind(struct device *dev, struct device *master,
599 		void *data)
600 {
601 	struct msm_drm_private *priv = dev_get_drvdata(master);
602 
603 	if (priv->hdmi) {
604 		if (priv->hdmi->audio_pdev)
605 			platform_device_unregister(priv->hdmi->audio_pdev);
606 
607 		msm_hdmi_destroy(priv->hdmi);
608 		priv->hdmi = NULL;
609 	}
610 }
611 
612 static const struct component_ops msm_hdmi_ops = {
613 		.bind   = msm_hdmi_bind,
614 		.unbind = msm_hdmi_unbind,
615 };
616 
617 static int msm_hdmi_dev_probe(struct platform_device *pdev)
618 {
619 	return component_add(&pdev->dev, &msm_hdmi_ops);
620 }
621 
622 static int msm_hdmi_dev_remove(struct platform_device *pdev)
623 {
624 	component_del(&pdev->dev, &msm_hdmi_ops);
625 	return 0;
626 }
627 
628 static const struct of_device_id msm_hdmi_dt_match[] = {
629 	{ .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
630 	{ .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
631 	{ .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
632 	{ .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
633 	{ .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
634 	{ .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
635 	{}
636 };
637 
638 static struct platform_driver msm_hdmi_driver = {
639 	.probe = msm_hdmi_dev_probe,
640 	.remove = msm_hdmi_dev_remove,
641 	.driver = {
642 		.name = "hdmi_msm",
643 		.of_match_table = msm_hdmi_dt_match,
644 	},
645 };
646 
647 void __init msm_hdmi_register(void)
648 {
649 	msm_hdmi_phy_driver_register();
650 	platform_driver_register(&msm_hdmi_driver);
651 }
652 
653 void __exit msm_hdmi_unregister(void)
654 {
655 	platform_driver_unregister(&msm_hdmi_driver);
656 	msm_hdmi_phy_driver_unregister();
657 }
658