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