0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #define DSS_SUBSYS_NAME "HDMI"
0011
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/err.h>
0015 #include <linux/io.h>
0016 #include <linux/interrupt.h>
0017 #include <linux/mutex.h>
0018 #include <linux/delay.h>
0019 #include <linux/string.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/pm_runtime.h>
0022 #include <linux/clk.h>
0023 #include <linux/regulator/consumer.h>
0024 #include <linux/component.h>
0025 #include <linux/of.h>
0026 #include <linux/of_graph.h>
0027 #include <sound/omap-hdmi-audio.h>
0028 #include <media/cec.h>
0029
0030 #include <drm/drm_atomic.h>
0031 #include <drm/drm_atomic_state_helper.h>
0032 #include <drm/drm_edid.h>
0033
0034 #include "omapdss.h"
0035 #include "hdmi4_core.h"
0036 #include "hdmi4_cec.h"
0037 #include "dss.h"
0038 #include "hdmi.h"
0039
0040 static int hdmi_runtime_get(struct omap_hdmi *hdmi)
0041 {
0042 int r;
0043
0044 DSSDBG("hdmi_runtime_get\n");
0045
0046 r = pm_runtime_get_sync(&hdmi->pdev->dev);
0047 if (WARN_ON(r < 0)) {
0048 pm_runtime_put_noidle(&hdmi->pdev->dev);
0049 return r;
0050 }
0051 return 0;
0052 }
0053
0054 static void hdmi_runtime_put(struct omap_hdmi *hdmi)
0055 {
0056 int r;
0057
0058 DSSDBG("hdmi_runtime_put\n");
0059
0060 r = pm_runtime_put_sync(&hdmi->pdev->dev);
0061 WARN_ON(r < 0 && r != -ENOSYS);
0062 }
0063
0064 static irqreturn_t hdmi_irq_handler(int irq, void *data)
0065 {
0066 struct omap_hdmi *hdmi = data;
0067 struct hdmi_wp_data *wp = &hdmi->wp;
0068 u32 irqstatus;
0069
0070 irqstatus = hdmi_wp_get_irqstatus(wp);
0071 hdmi_wp_set_irqstatus(wp, irqstatus);
0072
0073 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
0074 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
0075
0076
0077
0078
0079
0080
0081 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
0082
0083 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
0084 HDMI_IRQ_LINK_DISCONNECT);
0085
0086 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
0087 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
0088 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
0089 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
0090 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
0091 }
0092 if (irqstatus & HDMI_IRQ_CORE) {
0093 u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4);
0094
0095 hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4);
0096 if (intr4 & 8)
0097 hdmi4_cec_irq(&hdmi->core);
0098 }
0099
0100 return IRQ_HANDLED;
0101 }
0102
0103 static int hdmi_power_on_core(struct omap_hdmi *hdmi)
0104 {
0105 int r;
0106
0107 if (hdmi->core.core_pwr_cnt++)
0108 return 0;
0109
0110 r = regulator_enable(hdmi->vdda_reg);
0111 if (r)
0112 goto err_reg_enable;
0113
0114 r = hdmi_runtime_get(hdmi);
0115 if (r)
0116 goto err_runtime_get;
0117
0118 hdmi4_core_powerdown_disable(&hdmi->core);
0119
0120
0121 dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK);
0122
0123 hdmi->core_enabled = true;
0124
0125 return 0;
0126
0127 err_runtime_get:
0128 regulator_disable(hdmi->vdda_reg);
0129 err_reg_enable:
0130 hdmi->core.core_pwr_cnt--;
0131
0132 return r;
0133 }
0134
0135 static void hdmi_power_off_core(struct omap_hdmi *hdmi)
0136 {
0137 if (--hdmi->core.core_pwr_cnt)
0138 return;
0139
0140 hdmi->core_enabled = false;
0141
0142 hdmi_runtime_put(hdmi);
0143 regulator_disable(hdmi->vdda_reg);
0144 }
0145
0146 static int hdmi_power_on_full(struct omap_hdmi *hdmi)
0147 {
0148 int r;
0149 const struct videomode *vm;
0150 struct hdmi_wp_data *wp = &hdmi->wp;
0151 struct dss_pll_clock_info hdmi_cinfo = { 0 };
0152 unsigned int pc;
0153
0154 r = hdmi_power_on_core(hdmi);
0155 if (r)
0156 return r;
0157
0158
0159 hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE);
0160 hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE);
0161
0162 vm = &hdmi->cfg.vm;
0163
0164 DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive,
0165 vm->vactive);
0166
0167 pc = vm->pixelclock;
0168 if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
0169 pc *= 2;
0170
0171
0172 pc *= 10;
0173
0174 dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin),
0175 pc, &hdmi_cinfo);
0176
0177 r = dss_pll_enable(&hdmi->pll.pll);
0178 if (r) {
0179 DSSERR("Failed to enable PLL\n");
0180 goto err_pll_enable;
0181 }
0182
0183 r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo);
0184 if (r) {
0185 DSSERR("Failed to configure PLL\n");
0186 goto err_pll_cfg;
0187 }
0188
0189 r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco,
0190 hdmi_cinfo.clkout[0]);
0191 if (r) {
0192 DSSDBG("Failed to configure PHY\n");
0193 goto err_phy_cfg;
0194 }
0195
0196 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
0197 if (r)
0198 goto err_phy_pwr;
0199
0200 hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
0201
0202 r = dss_mgr_enable(&hdmi->output);
0203 if (r)
0204 goto err_mgr_enable;
0205
0206 r = hdmi_wp_video_start(&hdmi->wp);
0207 if (r)
0208 goto err_vid_enable;
0209
0210 hdmi_wp_set_irqenable(wp,
0211 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
0212
0213 return 0;
0214
0215 err_vid_enable:
0216 dss_mgr_disable(&hdmi->output);
0217 err_mgr_enable:
0218 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
0219 err_phy_pwr:
0220 err_phy_cfg:
0221 err_pll_cfg:
0222 dss_pll_disable(&hdmi->pll.pll);
0223 err_pll_enable:
0224 hdmi_power_off_core(hdmi);
0225 return -EIO;
0226 }
0227
0228 static void hdmi_power_off_full(struct omap_hdmi *hdmi)
0229 {
0230 hdmi_wp_clear_irqenable(&hdmi->wp, ~HDMI_IRQ_CORE);
0231
0232 hdmi_wp_video_stop(&hdmi->wp);
0233
0234 dss_mgr_disable(&hdmi->output);
0235
0236 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
0237
0238 dss_pll_disable(&hdmi->pll.pll);
0239
0240 hdmi_power_off_core(hdmi);
0241 }
0242
0243 static int hdmi_dump_regs(struct seq_file *s, void *p)
0244 {
0245 struct omap_hdmi *hdmi = s->private;
0246
0247 mutex_lock(&hdmi->lock);
0248
0249 if (hdmi_runtime_get(hdmi)) {
0250 mutex_unlock(&hdmi->lock);
0251 return 0;
0252 }
0253
0254 hdmi_wp_dump(&hdmi->wp, s);
0255 hdmi_pll_dump(&hdmi->pll, s);
0256 hdmi_phy_dump(&hdmi->phy, s);
0257 hdmi4_core_dump(&hdmi->core, s);
0258
0259 hdmi_runtime_put(hdmi);
0260 mutex_unlock(&hdmi->lock);
0261 return 0;
0262 }
0263
0264 static void hdmi_start_audio_stream(struct omap_hdmi *hd)
0265 {
0266 hdmi_wp_audio_enable(&hd->wp, true);
0267 hdmi4_audio_start(&hd->core, &hd->wp);
0268 }
0269
0270 static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
0271 {
0272 hdmi4_audio_stop(&hd->core, &hd->wp);
0273 hdmi_wp_audio_enable(&hd->wp, false);
0274 }
0275
0276 int hdmi4_core_enable(struct hdmi_core_data *core)
0277 {
0278 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
0279 int r = 0;
0280
0281 DSSDBG("ENTER omapdss_hdmi4_core_enable\n");
0282
0283 mutex_lock(&hdmi->lock);
0284
0285 r = hdmi_power_on_core(hdmi);
0286 if (r) {
0287 DSSERR("failed to power on device\n");
0288 goto err0;
0289 }
0290
0291 mutex_unlock(&hdmi->lock);
0292 return 0;
0293
0294 err0:
0295 mutex_unlock(&hdmi->lock);
0296 return r;
0297 }
0298
0299 void hdmi4_core_disable(struct hdmi_core_data *core)
0300 {
0301 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
0302
0303 DSSDBG("Enter omapdss_hdmi4_core_disable\n");
0304
0305 mutex_lock(&hdmi->lock);
0306
0307 hdmi_power_off_core(hdmi);
0308
0309 mutex_unlock(&hdmi->lock);
0310 }
0311
0312
0313
0314
0315
0316 static int hdmi4_bridge_attach(struct drm_bridge *bridge,
0317 enum drm_bridge_attach_flags flags)
0318 {
0319 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0320
0321 if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
0322 return -EINVAL;
0323
0324 return drm_bridge_attach(bridge->encoder, hdmi->output.next_bridge,
0325 bridge, flags);
0326 }
0327
0328 static void hdmi4_bridge_mode_set(struct drm_bridge *bridge,
0329 const struct drm_display_mode *mode,
0330 const struct drm_display_mode *adjusted_mode)
0331 {
0332 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0333
0334 mutex_lock(&hdmi->lock);
0335
0336 drm_display_mode_to_videomode(adjusted_mode, &hdmi->cfg.vm);
0337
0338 dispc_set_tv_pclk(hdmi->dss->dispc, adjusted_mode->clock * 1000);
0339
0340 mutex_unlock(&hdmi->lock);
0341 }
0342
0343 static void hdmi4_bridge_enable(struct drm_bridge *bridge,
0344 struct drm_bridge_state *bridge_state)
0345 {
0346 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0347 struct drm_atomic_state *state = bridge_state->base.state;
0348 struct drm_connector_state *conn_state;
0349 struct drm_connector *connector;
0350 struct drm_crtc_state *crtc_state;
0351 unsigned long flags;
0352 int ret;
0353
0354
0355
0356
0357
0358 connector = drm_atomic_get_new_connector_for_encoder(state,
0359 bridge->encoder);
0360 if (WARN_ON(!connector))
0361 return;
0362 conn_state = drm_atomic_get_new_connector_state(state, connector);
0363 if (WARN_ON(!conn_state))
0364 return;
0365 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
0366 if (WARN_ON(!crtc_state))
0367 return;
0368
0369 hdmi->cfg.hdmi_dvi_mode = connector->display_info.is_hdmi
0370 ? HDMI_HDMI : HDMI_DVI;
0371
0372 if (connector->display_info.is_hdmi) {
0373 const struct drm_display_mode *mode;
0374 struct hdmi_avi_infoframe avi;
0375
0376 mode = &crtc_state->adjusted_mode;
0377 ret = drm_hdmi_avi_infoframe_from_display_mode(&avi, connector,
0378 mode);
0379 if (ret == 0)
0380 hdmi->cfg.infoframe = avi;
0381 }
0382
0383 mutex_lock(&hdmi->lock);
0384
0385 ret = hdmi_power_on_full(hdmi);
0386 if (ret) {
0387 DSSERR("failed to power on device\n");
0388 goto done;
0389 }
0390
0391 if (hdmi->audio_configured) {
0392 ret = hdmi4_audio_config(&hdmi->core, &hdmi->wp,
0393 &hdmi->audio_config,
0394 hdmi->cfg.vm.pixelclock);
0395 if (ret) {
0396 DSSERR("Error restoring audio configuration: %d", ret);
0397 hdmi->audio_abort_cb(&hdmi->pdev->dev);
0398 hdmi->audio_configured = false;
0399 }
0400 }
0401
0402 spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
0403 if (hdmi->audio_configured && hdmi->audio_playing)
0404 hdmi_start_audio_stream(hdmi);
0405 hdmi->display_enabled = true;
0406 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
0407
0408 done:
0409 mutex_unlock(&hdmi->lock);
0410 }
0411
0412 static void hdmi4_bridge_disable(struct drm_bridge *bridge,
0413 struct drm_bridge_state *bridge_state)
0414 {
0415 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0416 unsigned long flags;
0417
0418 mutex_lock(&hdmi->lock);
0419
0420 spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
0421 hdmi_stop_audio_stream(hdmi);
0422 hdmi->display_enabled = false;
0423 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
0424
0425 hdmi_power_off_full(hdmi);
0426
0427 mutex_unlock(&hdmi->lock);
0428 }
0429
0430 static void hdmi4_bridge_hpd_notify(struct drm_bridge *bridge,
0431 enum drm_connector_status status)
0432 {
0433 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0434
0435 if (status == connector_status_disconnected)
0436 hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID);
0437 }
0438
0439 static struct edid *hdmi4_bridge_get_edid(struct drm_bridge *bridge,
0440 struct drm_connector *connector)
0441 {
0442 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
0443 struct edid *edid = NULL;
0444 unsigned int cec_addr;
0445 bool need_enable;
0446 int r;
0447
0448 need_enable = hdmi->core_enabled == false;
0449
0450 if (need_enable) {
0451 r = hdmi4_core_enable(&hdmi->core);
0452 if (r)
0453 return NULL;
0454 }
0455
0456 mutex_lock(&hdmi->lock);
0457 r = hdmi_runtime_get(hdmi);
0458 BUG_ON(r);
0459
0460 r = hdmi4_core_ddc_init(&hdmi->core);
0461 if (r)
0462 goto done;
0463
0464 edid = drm_do_get_edid(connector, hdmi4_core_ddc_read, &hdmi->core);
0465
0466 done:
0467 hdmi_runtime_put(hdmi);
0468 mutex_unlock(&hdmi->lock);
0469
0470 if (edid && edid->extensions) {
0471 unsigned int len = (edid->extensions + 1) * EDID_LENGTH;
0472
0473 cec_addr = cec_get_edid_phys_addr((u8 *)edid, len, NULL);
0474 } else {
0475 cec_addr = CEC_PHYS_ADDR_INVALID;
0476 }
0477
0478 hdmi4_cec_set_phys_addr(&hdmi->core, cec_addr);
0479
0480 if (need_enable)
0481 hdmi4_core_disable(&hdmi->core);
0482
0483 return edid;
0484 }
0485
0486 static const struct drm_bridge_funcs hdmi4_bridge_funcs = {
0487 .attach = hdmi4_bridge_attach,
0488 .mode_set = hdmi4_bridge_mode_set,
0489 .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
0490 .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
0491 .atomic_reset = drm_atomic_helper_bridge_reset,
0492 .atomic_enable = hdmi4_bridge_enable,
0493 .atomic_disable = hdmi4_bridge_disable,
0494 .hpd_notify = hdmi4_bridge_hpd_notify,
0495 .get_edid = hdmi4_bridge_get_edid,
0496 };
0497
0498 static void hdmi4_bridge_init(struct omap_hdmi *hdmi)
0499 {
0500 hdmi->bridge.funcs = &hdmi4_bridge_funcs;
0501 hdmi->bridge.of_node = hdmi->pdev->dev.of_node;
0502 hdmi->bridge.ops = DRM_BRIDGE_OP_EDID;
0503 hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
0504
0505 drm_bridge_add(&hdmi->bridge);
0506 }
0507
0508 static void hdmi4_bridge_cleanup(struct omap_hdmi *hdmi)
0509 {
0510 drm_bridge_remove(&hdmi->bridge);
0511 }
0512
0513
0514
0515
0516
0517 static int hdmi_audio_startup(struct device *dev,
0518 void (*abort_cb)(struct device *dev))
0519 {
0520 struct omap_hdmi *hd = dev_get_drvdata(dev);
0521
0522 mutex_lock(&hd->lock);
0523
0524 WARN_ON(hd->audio_abort_cb != NULL);
0525
0526 hd->audio_abort_cb = abort_cb;
0527
0528 mutex_unlock(&hd->lock);
0529
0530 return 0;
0531 }
0532
0533 static int hdmi_audio_shutdown(struct device *dev)
0534 {
0535 struct omap_hdmi *hd = dev_get_drvdata(dev);
0536
0537 mutex_lock(&hd->lock);
0538 hd->audio_abort_cb = NULL;
0539 hd->audio_configured = false;
0540 hd->audio_playing = false;
0541 mutex_unlock(&hd->lock);
0542
0543 return 0;
0544 }
0545
0546 static int hdmi_audio_start(struct device *dev)
0547 {
0548 struct omap_hdmi *hd = dev_get_drvdata(dev);
0549 unsigned long flags;
0550
0551 spin_lock_irqsave(&hd->audio_playing_lock, flags);
0552
0553 if (hd->display_enabled) {
0554 if (!hdmi_mode_has_audio(&hd->cfg))
0555 DSSERR("%s: Video mode does not support audio\n",
0556 __func__);
0557 hdmi_start_audio_stream(hd);
0558 }
0559 hd->audio_playing = true;
0560
0561 spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
0562 return 0;
0563 }
0564
0565 static void hdmi_audio_stop(struct device *dev)
0566 {
0567 struct omap_hdmi *hd = dev_get_drvdata(dev);
0568 unsigned long flags;
0569
0570 WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
0571
0572 spin_lock_irqsave(&hd->audio_playing_lock, flags);
0573
0574 if (hd->display_enabled)
0575 hdmi_stop_audio_stream(hd);
0576 hd->audio_playing = false;
0577
0578 spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
0579 }
0580
0581 static int hdmi_audio_config(struct device *dev,
0582 struct omap_dss_audio *dss_audio)
0583 {
0584 struct omap_hdmi *hd = dev_get_drvdata(dev);
0585 int ret = 0;
0586
0587 mutex_lock(&hd->lock);
0588
0589 if (hd->display_enabled) {
0590 ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
0591 hd->cfg.vm.pixelclock);
0592 if (ret)
0593 goto out;
0594 }
0595
0596 hd->audio_configured = true;
0597 hd->audio_config = *dss_audio;
0598 out:
0599 mutex_unlock(&hd->lock);
0600
0601 return ret;
0602 }
0603
0604 static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
0605 .audio_startup = hdmi_audio_startup,
0606 .audio_shutdown = hdmi_audio_shutdown,
0607 .audio_start = hdmi_audio_start,
0608 .audio_stop = hdmi_audio_stop,
0609 .audio_config = hdmi_audio_config,
0610 };
0611
0612 static int hdmi_audio_register(struct omap_hdmi *hdmi)
0613 {
0614 struct omap_hdmi_audio_pdata pdata = {
0615 .dev = &hdmi->pdev->dev,
0616 .version = 4,
0617 .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp),
0618 .ops = &hdmi_audio_ops,
0619 };
0620
0621 hdmi->audio_pdev = platform_device_register_data(
0622 &hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
0623 &pdata, sizeof(pdata));
0624
0625 if (IS_ERR(hdmi->audio_pdev))
0626 return PTR_ERR(hdmi->audio_pdev);
0627
0628 return 0;
0629 }
0630
0631
0632
0633
0634
0635 static int hdmi4_bind(struct device *dev, struct device *master, void *data)
0636 {
0637 struct dss_device *dss = dss_get_device(master);
0638 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
0639 int r;
0640
0641 hdmi->dss = dss;
0642
0643 r = hdmi_runtime_get(hdmi);
0644 if (r)
0645 return r;
0646
0647 r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
0648 if (r)
0649 goto err_runtime_put;
0650
0651 r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp);
0652 if (r)
0653 goto err_pll_uninit;
0654
0655 r = hdmi_audio_register(hdmi);
0656 if (r) {
0657 DSSERR("Registering HDMI audio failed\n");
0658 goto err_cec_uninit;
0659 }
0660
0661 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
0662 hdmi);
0663
0664 hdmi_runtime_put(hdmi);
0665
0666 return 0;
0667
0668 err_cec_uninit:
0669 hdmi4_cec_uninit(&hdmi->core);
0670 err_pll_uninit:
0671 hdmi_pll_uninit(&hdmi->pll);
0672 err_runtime_put:
0673 hdmi_runtime_put(hdmi);
0674 return r;
0675 }
0676
0677 static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
0678 {
0679 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
0680
0681 dss_debugfs_remove_file(hdmi->debugfs);
0682
0683 if (hdmi->audio_pdev)
0684 platform_device_unregister(hdmi->audio_pdev);
0685
0686 hdmi4_cec_uninit(&hdmi->core);
0687 hdmi_pll_uninit(&hdmi->pll);
0688 }
0689
0690 static const struct component_ops hdmi4_component_ops = {
0691 .bind = hdmi4_bind,
0692 .unbind = hdmi4_unbind,
0693 };
0694
0695
0696
0697
0698
0699 static int hdmi4_init_output(struct omap_hdmi *hdmi)
0700 {
0701 struct omap_dss_device *out = &hdmi->output;
0702 int r;
0703
0704 hdmi4_bridge_init(hdmi);
0705
0706 out->dev = &hdmi->pdev->dev;
0707 out->id = OMAP_DSS_OUTPUT_HDMI;
0708 out->type = OMAP_DISPLAY_TYPE_HDMI;
0709 out->name = "hdmi.0";
0710 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
0711 out->of_port = 0;
0712
0713 r = omapdss_device_init_output(out, &hdmi->bridge);
0714 if (r < 0) {
0715 hdmi4_bridge_cleanup(hdmi);
0716 return r;
0717 }
0718
0719 omapdss_device_register(out);
0720
0721 return 0;
0722 }
0723
0724 static void hdmi4_uninit_output(struct omap_hdmi *hdmi)
0725 {
0726 struct omap_dss_device *out = &hdmi->output;
0727
0728 omapdss_device_unregister(out);
0729 omapdss_device_cleanup_output(out);
0730
0731 hdmi4_bridge_cleanup(hdmi);
0732 }
0733
0734 static int hdmi4_probe_of(struct omap_hdmi *hdmi)
0735 {
0736 struct platform_device *pdev = hdmi->pdev;
0737 struct device_node *node = pdev->dev.of_node;
0738 struct device_node *ep;
0739 int r;
0740
0741 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
0742 if (!ep)
0743 return 0;
0744
0745 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
0746 of_node_put(ep);
0747 return r;
0748 }
0749
0750 static int hdmi4_probe(struct platform_device *pdev)
0751 {
0752 struct omap_hdmi *hdmi;
0753 int irq;
0754 int r;
0755
0756 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
0757 if (!hdmi)
0758 return -ENOMEM;
0759
0760 hdmi->pdev = pdev;
0761
0762 dev_set_drvdata(&pdev->dev, hdmi);
0763
0764 mutex_init(&hdmi->lock);
0765 spin_lock_init(&hdmi->audio_playing_lock);
0766
0767 r = hdmi4_probe_of(hdmi);
0768 if (r)
0769 goto err_free;
0770
0771 r = hdmi_wp_init(pdev, &hdmi->wp, 4);
0772 if (r)
0773 goto err_free;
0774
0775 r = hdmi_phy_init(pdev, &hdmi->phy, 4);
0776 if (r)
0777 goto err_free;
0778
0779 r = hdmi4_core_init(pdev, &hdmi->core);
0780 if (r)
0781 goto err_free;
0782
0783 irq = platform_get_irq(pdev, 0);
0784 if (irq < 0) {
0785 DSSERR("platform_get_irq failed\n");
0786 r = -ENODEV;
0787 goto err_free;
0788 }
0789
0790 r = devm_request_threaded_irq(&pdev->dev, irq,
0791 NULL, hdmi_irq_handler,
0792 IRQF_ONESHOT, "OMAP HDMI", hdmi);
0793 if (r) {
0794 DSSERR("HDMI IRQ request failed\n");
0795 goto err_free;
0796 }
0797
0798 hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda");
0799 if (IS_ERR(hdmi->vdda_reg)) {
0800 r = PTR_ERR(hdmi->vdda_reg);
0801 if (r != -EPROBE_DEFER)
0802 DSSERR("can't get VDDA regulator\n");
0803 goto err_free;
0804 }
0805
0806 pm_runtime_enable(&pdev->dev);
0807
0808 r = hdmi4_init_output(hdmi);
0809 if (r)
0810 goto err_pm_disable;
0811
0812 r = component_add(&pdev->dev, &hdmi4_component_ops);
0813 if (r)
0814 goto err_uninit_output;
0815
0816 return 0;
0817
0818 err_uninit_output:
0819 hdmi4_uninit_output(hdmi);
0820 err_pm_disable:
0821 pm_runtime_disable(&pdev->dev);
0822 err_free:
0823 kfree(hdmi);
0824 return r;
0825 }
0826
0827 static int hdmi4_remove(struct platform_device *pdev)
0828 {
0829 struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
0830
0831 component_del(&pdev->dev, &hdmi4_component_ops);
0832
0833 hdmi4_uninit_output(hdmi);
0834
0835 pm_runtime_disable(&pdev->dev);
0836
0837 kfree(hdmi);
0838 return 0;
0839 }
0840
0841 static const struct of_device_id hdmi_of_match[] = {
0842 { .compatible = "ti,omap4-hdmi", },
0843 {},
0844 };
0845
0846 struct platform_driver omapdss_hdmi4hw_driver = {
0847 .probe = hdmi4_probe,
0848 .remove = hdmi4_remove,
0849 .driver = {
0850 .name = "omapdss_hdmi",
0851 .of_match_table = hdmi_of_match,
0852 .suppress_bind_attrs = true,
0853 },
0854 };