• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
msm_hdmi_set_mode(struct hdmi * hdmi,bool power_on)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 
msm_hdmi_irq(int irq,void * dev_id)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 
msm_hdmi_destroy(struct hdmi * hdmi)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 		flush_workqueue(hdmi->workq);
68 		destroy_workqueue(hdmi->workq);
69 	}
70 	msm_hdmi_hdcp_destroy(hdmi);
71 
72 	if (hdmi->phy_dev) {
73 		put_device(hdmi->phy_dev);
74 		hdmi->phy = NULL;
75 		hdmi->phy_dev = NULL;
76 	}
77 
78 	if (hdmi->i2c)
79 		msm_hdmi_i2c_destroy(hdmi->i2c);
80 
81 	platform_set_drvdata(hdmi->pdev, NULL);
82 }
83 
msm_hdmi_get_phy(struct hdmi * hdmi)84 static int msm_hdmi_get_phy(struct hdmi *hdmi)
85 {
86 	struct platform_device *pdev = hdmi->pdev;
87 	struct platform_device *phy_pdev;
88 	struct device_node *phy_node;
89 
90 	phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
91 	if (!phy_node) {
92 		DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n");
93 		return -ENXIO;
94 	}
95 
96 	phy_pdev = of_find_device_by_node(phy_node);
97 	if (phy_pdev)
98 		hdmi->phy = platform_get_drvdata(phy_pdev);
99 
100 	of_node_put(phy_node);
101 
102 	if (!phy_pdev) {
103 		DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
104 		return -EPROBE_DEFER;
105 	}
106 	if (!hdmi->phy) {
107 		DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
108 		put_device(&phy_pdev->dev);
109 		return -EPROBE_DEFER;
110 	}
111 
112 	hdmi->phy_dev = get_device(&phy_pdev->dev);
113 
114 	return 0;
115 }
116 
117 /* construct hdmi at bind/probe time, grab all the resources.  If
118  * we are to EPROBE_DEFER we want to do it here, rather than later
119  * at modeset_init() time
120  */
msm_hdmi_init(struct platform_device * pdev)121 static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
122 {
123 	struct hdmi_platform_config *config = pdev->dev.platform_data;
124 	struct hdmi *hdmi = NULL;
125 	struct resource *res;
126 	int i, ret;
127 
128 	hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
129 	if (!hdmi) {
130 		ret = -ENOMEM;
131 		goto fail;
132 	}
133 
134 	hdmi->pdev = pdev;
135 	hdmi->config = config;
136 	spin_lock_init(&hdmi->reg_lock);
137 
138 	hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
139 	if (IS_ERR(hdmi->mmio)) {
140 		ret = PTR_ERR(hdmi->mmio);
141 		goto fail;
142 	}
143 
144 	/* HDCP needs physical address of hdmi register */
145 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
146 		config->mmio_name);
147 	if (!res) {
148 		ret = -EINVAL;
149 		goto fail;
150 	}
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 	hdmi->hpd_gpiod = devm_gpiod_get_optional(&pdev->dev, "hpd", GPIOD_IN);
251 	/* This will catch e.g. -EPROBE_DEFER */
252 	if (IS_ERR(hdmi->hpd_gpiod)) {
253 		ret = PTR_ERR(hdmi->hpd_gpiod);
254 		DRM_DEV_ERROR(&pdev->dev, "failed to get hpd gpio: (%d)\n", ret);
255 		goto fail;
256 	}
257 
258 	if (!hdmi->hpd_gpiod)
259 		DBG("failed to get HPD gpio");
260 
261 	if (hdmi->hpd_gpiod)
262 		gpiod_set_consumer_name(hdmi->hpd_gpiod, "HDMI_HPD");
263 
264 	pm_runtime_enable(&pdev->dev);
265 
266 	hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
267 
268 	hdmi->i2c = msm_hdmi_i2c_init(hdmi);
269 	if (IS_ERR(hdmi->i2c)) {
270 		ret = PTR_ERR(hdmi->i2c);
271 		DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret);
272 		hdmi->i2c = NULL;
273 		goto fail;
274 	}
275 
276 	ret = msm_hdmi_get_phy(hdmi);
277 	if (ret) {
278 		DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n");
279 		goto fail;
280 	}
281 
282 	hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
283 	if (IS_ERR(hdmi->hdcp_ctrl)) {
284 		dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
285 		hdmi->hdcp_ctrl = NULL;
286 	}
287 
288 	return hdmi;
289 
290 fail:
291 	if (hdmi)
292 		msm_hdmi_destroy(hdmi);
293 
294 	return ERR_PTR(ret);
295 }
296 
297 /* Second part of initialization, the drm/kms level modeset_init,
298  * constructs/initializes mode objects, etc, is called from master
299  * driver (not hdmi sub-device's probe/bind!)
300  *
301  * Any resource (regulator/clk/etc) which could be missing at boot
302  * should be handled in msm_hdmi_init() so that failure happens from
303  * hdmi sub-device's probe.
304  */
msm_hdmi_modeset_init(struct hdmi * hdmi,struct drm_device * dev,struct drm_encoder * encoder)305 int msm_hdmi_modeset_init(struct hdmi *hdmi,
306 		struct drm_device *dev, struct drm_encoder *encoder)
307 {
308 	struct msm_drm_private *priv = dev->dev_private;
309 	struct platform_device *pdev = hdmi->pdev;
310 	int ret;
311 
312 	if (priv->num_bridges == ARRAY_SIZE(priv->bridges)) {
313 		DRM_DEV_ERROR(dev->dev, "too many bridges\n");
314 		return -ENOSPC;
315 	}
316 
317 	hdmi->dev = dev;
318 	hdmi->encoder = encoder;
319 
320 	hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
321 
322 	hdmi->bridge = msm_hdmi_bridge_init(hdmi);
323 	if (IS_ERR(hdmi->bridge)) {
324 		ret = PTR_ERR(hdmi->bridge);
325 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret);
326 		hdmi->bridge = NULL;
327 		goto fail;
328 	}
329 
330 	hdmi->connector = drm_bridge_connector_init(hdmi->dev, encoder);
331 	if (IS_ERR(hdmi->connector)) {
332 		ret = PTR_ERR(hdmi->connector);
333 		DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret);
334 		hdmi->connector = NULL;
335 		goto fail;
336 	}
337 
338 	drm_connector_attach_encoder(hdmi->connector, hdmi->encoder);
339 
340 	hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
341 	if (!hdmi->irq) {
342 		ret = -EINVAL;
343 		DRM_DEV_ERROR(dev->dev, "failed to get irq\n");
344 		goto fail;
345 	}
346 
347 	ret = devm_request_irq(dev->dev, hdmi->irq,
348 			msm_hdmi_irq, IRQF_TRIGGER_HIGH,
349 			"hdmi_isr", hdmi);
350 	if (ret < 0) {
351 		DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
352 				hdmi->irq, ret);
353 		goto fail;
354 	}
355 
356 	drm_bridge_connector_enable_hpd(hdmi->connector);
357 
358 	ret = msm_hdmi_hpd_enable(hdmi->bridge);
359 	if (ret < 0) {
360 		DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
361 		goto fail;
362 	}
363 
364 	priv->bridges[priv->num_bridges++]       = hdmi->bridge;
365 	priv->connectors[priv->num_connectors++] = hdmi->connector;
366 
367 	platform_set_drvdata(pdev, hdmi);
368 
369 	return 0;
370 
371 fail:
372 	/* bridge is normally destroyed by drm: */
373 	if (hdmi->bridge) {
374 		msm_hdmi_bridge_destroy(hdmi->bridge);
375 		hdmi->bridge = NULL;
376 	}
377 	if (hdmi->connector) {
378 		hdmi->connector->funcs->destroy(hdmi->connector);
379 		hdmi->connector = NULL;
380 	}
381 
382 	return ret;
383 }
384 
385 /*
386  * The hdmi device:
387  */
388 
389 #define HDMI_CFG(item, entry) \
390 	.item ## _names = item ##_names_ ## entry, \
391 	.item ## _cnt   = ARRAY_SIZE(item ## _names_ ## entry)
392 
393 static const char *pwr_reg_names_none[] = {};
394 static const char *hpd_reg_names_none[] = {};
395 
396 static struct hdmi_platform_config hdmi_tx_8660_config;
397 
398 static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
399 static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
400 
401 static struct hdmi_platform_config hdmi_tx_8960_config = {
402 		HDMI_CFG(hpd_reg, 8960),
403 		HDMI_CFG(hpd_clk, 8960),
404 };
405 
406 static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
407 static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
408 static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
409 static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
410 static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
411 
412 static struct hdmi_platform_config hdmi_tx_8974_config = {
413 		HDMI_CFG(pwr_reg, 8x74),
414 		HDMI_CFG(hpd_reg, 8x74),
415 		HDMI_CFG(pwr_clk, 8x74),
416 		HDMI_CFG(hpd_clk, 8x74),
417 		.hpd_freq      = hpd_clk_freq_8x74,
418 };
419 
420 static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
421 
422 static struct hdmi_platform_config hdmi_tx_8084_config = {
423 		HDMI_CFG(pwr_reg, 8x74),
424 		HDMI_CFG(hpd_reg, 8084),
425 		HDMI_CFG(pwr_clk, 8x74),
426 		HDMI_CFG(hpd_clk, 8x74),
427 		.hpd_freq      = hpd_clk_freq_8x74,
428 };
429 
430 static struct hdmi_platform_config hdmi_tx_8994_config = {
431 		HDMI_CFG(pwr_reg, 8x74),
432 		HDMI_CFG(hpd_reg, none),
433 		HDMI_CFG(pwr_clk, 8x74),
434 		HDMI_CFG(hpd_clk, 8x74),
435 		.hpd_freq      = hpd_clk_freq_8x74,
436 };
437 
438 static struct hdmi_platform_config hdmi_tx_8996_config = {
439 		HDMI_CFG(pwr_reg, none),
440 		HDMI_CFG(hpd_reg, none),
441 		HDMI_CFG(pwr_clk, 8x74),
442 		HDMI_CFG(hpd_clk, 8x74),
443 		.hpd_freq      = hpd_clk_freq_8x74,
444 };
445 
446 /*
447  * HDMI audio codec callbacks
448  */
msm_hdmi_audio_hw_params(struct device * dev,void * data,struct hdmi_codec_daifmt * daifmt,struct hdmi_codec_params * params)449 static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
450 				    struct hdmi_codec_daifmt *daifmt,
451 				    struct hdmi_codec_params *params)
452 {
453 	struct hdmi *hdmi = dev_get_drvdata(dev);
454 	unsigned int chan;
455 	unsigned int channel_allocation = 0;
456 	unsigned int rate;
457 	unsigned int level_shift  = 0; /* 0dB */
458 	bool down_mix = false;
459 
460 	DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
461 		 params->sample_width, params->cea.channels);
462 
463 	switch (params->cea.channels) {
464 	case 2:
465 		/* FR and FL speakers */
466 		channel_allocation  = 0;
467 		chan = MSM_HDMI_AUDIO_CHANNEL_2;
468 		break;
469 	case 4:
470 		/* FC, LFE, FR and FL speakers */
471 		channel_allocation  = 0x3;
472 		chan = MSM_HDMI_AUDIO_CHANNEL_4;
473 		break;
474 	case 6:
475 		/* RR, RL, FC, LFE, FR and FL speakers */
476 		channel_allocation  = 0x0B;
477 		chan = MSM_HDMI_AUDIO_CHANNEL_6;
478 		break;
479 	case 8:
480 		/* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
481 		channel_allocation  = 0x1F;
482 		chan = MSM_HDMI_AUDIO_CHANNEL_8;
483 		break;
484 	default:
485 		return -EINVAL;
486 	}
487 
488 	switch (params->sample_rate) {
489 	case 32000:
490 		rate = HDMI_SAMPLE_RATE_32KHZ;
491 		break;
492 	case 44100:
493 		rate = HDMI_SAMPLE_RATE_44_1KHZ;
494 		break;
495 	case 48000:
496 		rate = HDMI_SAMPLE_RATE_48KHZ;
497 		break;
498 	case 88200:
499 		rate = HDMI_SAMPLE_RATE_88_2KHZ;
500 		break;
501 	case 96000:
502 		rate = HDMI_SAMPLE_RATE_96KHZ;
503 		break;
504 	case 176400:
505 		rate = HDMI_SAMPLE_RATE_176_4KHZ;
506 		break;
507 	case 192000:
508 		rate = HDMI_SAMPLE_RATE_192KHZ;
509 		break;
510 	default:
511 		DRM_DEV_ERROR(dev, "rate[%d] not supported!\n",
512 			params->sample_rate);
513 		return -EINVAL;
514 	}
515 
516 	msm_hdmi_audio_set_sample_rate(hdmi, rate);
517 	msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
518 			      level_shift, down_mix);
519 
520 	return 0;
521 }
522 
msm_hdmi_audio_shutdown(struct device * dev,void * data)523 static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
524 {
525 	struct hdmi *hdmi = dev_get_drvdata(dev);
526 
527 	msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
528 }
529 
530 static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
531 	.hw_params = msm_hdmi_audio_hw_params,
532 	.audio_shutdown = msm_hdmi_audio_shutdown,
533 };
534 
535 static struct hdmi_codec_pdata codec_data = {
536 	.ops = &msm_hdmi_audio_codec_ops,
537 	.max_i2s_channels = 8,
538 	.i2s = 1,
539 };
540 
msm_hdmi_register_audio_driver(struct hdmi * hdmi,struct device * dev)541 static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
542 {
543 	hdmi->audio_pdev = platform_device_register_data(dev,
544 							 HDMI_CODEC_DRV_NAME,
545 							 PLATFORM_DEVID_AUTO,
546 							 &codec_data,
547 							 sizeof(codec_data));
548 	return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
549 }
550 
msm_hdmi_bind(struct device * dev,struct device * master,void * data)551 static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
552 {
553 	struct drm_device *drm = dev_get_drvdata(master);
554 	struct msm_drm_private *priv = drm->dev_private;
555 	struct hdmi_platform_config *hdmi_cfg;
556 	struct hdmi *hdmi;
557 	struct device_node *of_node = dev->of_node;
558 	int err;
559 
560 	hdmi_cfg = (struct hdmi_platform_config *)
561 			of_device_get_match_data(dev);
562 	if (!hdmi_cfg) {
563 		DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node);
564 		return -ENXIO;
565 	}
566 
567 	hdmi_cfg->mmio_name     = "core_physical";
568 	hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
569 
570 	dev->platform_data = hdmi_cfg;
571 
572 	hdmi = msm_hdmi_init(to_platform_device(dev));
573 	if (IS_ERR(hdmi))
574 		return PTR_ERR(hdmi);
575 	priv->hdmi = hdmi;
576 
577 	err = msm_hdmi_register_audio_driver(hdmi, dev);
578 	if (err) {
579 		DRM_ERROR("Failed to attach an audio codec %d\n", err);
580 		hdmi->audio_pdev = NULL;
581 	}
582 
583 	return 0;
584 }
585 
msm_hdmi_unbind(struct device * dev,struct device * master,void * data)586 static void msm_hdmi_unbind(struct device *dev, struct device *master,
587 		void *data)
588 {
589 	struct drm_device *drm = dev_get_drvdata(master);
590 	struct msm_drm_private *priv = drm->dev_private;
591 	if (priv->hdmi) {
592 		if (priv->hdmi->audio_pdev)
593 			platform_device_unregister(priv->hdmi->audio_pdev);
594 
595 		msm_hdmi_destroy(priv->hdmi);
596 		priv->hdmi = NULL;
597 	}
598 }
599 
600 static const struct component_ops msm_hdmi_ops = {
601 		.bind   = msm_hdmi_bind,
602 		.unbind = msm_hdmi_unbind,
603 };
604 
msm_hdmi_dev_probe(struct platform_device * pdev)605 static int msm_hdmi_dev_probe(struct platform_device *pdev)
606 {
607 	return component_add(&pdev->dev, &msm_hdmi_ops);
608 }
609 
msm_hdmi_dev_remove(struct platform_device * pdev)610 static int msm_hdmi_dev_remove(struct platform_device *pdev)
611 {
612 	component_del(&pdev->dev, &msm_hdmi_ops);
613 	return 0;
614 }
615 
616 static const struct of_device_id msm_hdmi_dt_match[] = {
617 	{ .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
618 	{ .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
619 	{ .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
620 	{ .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
621 	{ .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
622 	{ .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
623 	{}
624 };
625 
626 static struct platform_driver msm_hdmi_driver = {
627 	.probe = msm_hdmi_dev_probe,
628 	.remove = msm_hdmi_dev_remove,
629 	.driver = {
630 		.name = "hdmi_msm",
631 		.of_match_table = msm_hdmi_dt_match,
632 	},
633 };
634 
msm_hdmi_register(void)635 void __init msm_hdmi_register(void)
636 {
637 	msm_hdmi_phy_driver_register();
638 	platform_driver_register(&msm_hdmi_driver);
639 }
640 
msm_hdmi_unregister(void)641 void __exit msm_hdmi_unregister(void)
642 {
643 	platform_driver_unregister(&msm_hdmi_driver);
644 	msm_hdmi_phy_driver_unregister();
645 }
646