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