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