1 /* 2 * HDMI interface DSS driver for TI's OMAP4 family of SoCs. 3 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/ 4 * Authors: Yong Zhi 5 * Mythri pk <mythripk@ti.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 as published by 9 * the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #define DSS_SUBSYS_NAME "HDMI" 21 22 #include <linux/kernel.h> 23 #include <linux/module.h> 24 #include <linux/err.h> 25 #include <linux/io.h> 26 #include <linux/interrupt.h> 27 #include <linux/mutex.h> 28 #include <linux/delay.h> 29 #include <linux/string.h> 30 #include <linux/platform_device.h> 31 #include <linux/pm_runtime.h> 32 #include <linux/clk.h> 33 #include <linux/gpio.h> 34 #include <linux/regulator/consumer.h> 35 #include <linux/component.h> 36 #include <linux/of.h> 37 #include <linux/of_graph.h> 38 #include <sound/omap-hdmi-audio.h> 39 #include <media/cec.h> 40 41 #include "omapdss.h" 42 #include "hdmi4_core.h" 43 #include "hdmi4_cec.h" 44 #include "dss.h" 45 #include "hdmi.h" 46 47 static struct omap_hdmi hdmi; 48 49 static int hdmi_runtime_get(void) 50 { 51 int r; 52 53 DSSDBG("hdmi_runtime_get\n"); 54 55 r = pm_runtime_get_sync(&hdmi.pdev->dev); 56 WARN_ON(r < 0); 57 if (r < 0) 58 return r; 59 60 return 0; 61 } 62 63 static void hdmi_runtime_put(void) 64 { 65 int r; 66 67 DSSDBG("hdmi_runtime_put\n"); 68 69 r = pm_runtime_put_sync(&hdmi.pdev->dev); 70 WARN_ON(r < 0 && r != -ENOSYS); 71 } 72 73 static irqreturn_t hdmi_irq_handler(int irq, void *data) 74 { 75 struct omap_hdmi *hdmi = data; 76 struct hdmi_wp_data *wp = &hdmi->wp; 77 u32 irqstatus; 78 79 irqstatus = hdmi_wp_get_irqstatus(wp); 80 hdmi_wp_set_irqstatus(wp, irqstatus); 81 82 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) && 83 irqstatus & HDMI_IRQ_LINK_DISCONNECT) { 84 /* 85 * If we get both connect and disconnect interrupts at the same 86 * time, turn off the PHY, clear interrupts, and restart, which 87 * raises connect interrupt if a cable is connected, or nothing 88 * if cable is not connected. 89 */ 90 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF); 91 92 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT | 93 HDMI_IRQ_LINK_DISCONNECT); 94 95 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 96 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) { 97 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON); 98 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) { 99 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 100 } 101 if (irqstatus & HDMI_IRQ_CORE) { 102 u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4); 103 104 hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4); 105 if (intr4 & 8) 106 hdmi4_cec_irq(&hdmi->core); 107 } 108 109 return IRQ_HANDLED; 110 } 111 112 static int hdmi_init_regulator(void) 113 { 114 struct regulator *reg; 115 116 if (hdmi.vdda_reg != NULL) 117 return 0; 118 119 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda"); 120 121 if (IS_ERR(reg)) { 122 if (PTR_ERR(reg) != -EPROBE_DEFER) 123 DSSERR("can't get VDDA regulator\n"); 124 return PTR_ERR(reg); 125 } 126 127 hdmi.vdda_reg = reg; 128 129 return 0; 130 } 131 132 static int hdmi_power_on_core(struct omap_dss_device *dssdev) 133 { 134 int r; 135 136 if (hdmi.core.core_pwr_cnt++) 137 return 0; 138 139 r = regulator_enable(hdmi.vdda_reg); 140 if (r) 141 goto err_reg_enable; 142 143 r = hdmi_runtime_get(); 144 if (r) 145 goto err_runtime_get; 146 147 hdmi4_core_powerdown_disable(&hdmi.core); 148 149 /* Make selection of HDMI in DSS */ 150 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); 151 152 hdmi.core_enabled = true; 153 154 return 0; 155 156 err_runtime_get: 157 regulator_disable(hdmi.vdda_reg); 158 err_reg_enable: 159 hdmi.core.core_pwr_cnt--; 160 161 return r; 162 } 163 164 static void hdmi_power_off_core(struct omap_dss_device *dssdev) 165 { 166 if (--hdmi.core.core_pwr_cnt) 167 return; 168 169 hdmi.core_enabled = false; 170 171 hdmi_runtime_put(); 172 regulator_disable(hdmi.vdda_reg); 173 } 174 175 static int hdmi_power_on_full(struct omap_dss_device *dssdev) 176 { 177 int r; 178 struct videomode *vm; 179 enum omap_channel channel = dssdev->dispc_channel; 180 struct hdmi_wp_data *wp = &hdmi.wp; 181 struct dss_pll_clock_info hdmi_cinfo = { 0 }; 182 unsigned pc; 183 184 r = hdmi_power_on_core(dssdev); 185 if (r) 186 return r; 187 188 /* disable and clear irqs */ 189 hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE); 190 hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE); 191 192 vm = &hdmi.cfg.vm; 193 194 DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive, 195 vm->vactive); 196 197 pc = vm->pixelclock; 198 if (vm->flags & DISPLAY_FLAGS_DOUBLECLK) 199 pc *= 2; 200 201 /* DSS_HDMI_TCLK is bitclk / 10 */ 202 pc *= 10; 203 204 dss_pll_calc_b(&hdmi.pll.pll, clk_get_rate(hdmi.pll.pll.clkin), 205 pc, &hdmi_cinfo); 206 207 r = dss_pll_enable(&hdmi.pll.pll); 208 if (r) { 209 DSSERR("Failed to enable PLL\n"); 210 goto err_pll_enable; 211 } 212 213 r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo); 214 if (r) { 215 DSSERR("Failed to configure PLL\n"); 216 goto err_pll_cfg; 217 } 218 219 r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco, 220 hdmi_cinfo.clkout[0]); 221 if (r) { 222 DSSDBG("Failed to configure PHY\n"); 223 goto err_phy_cfg; 224 } 225 226 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 227 if (r) 228 goto err_phy_pwr; 229 230 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg); 231 232 /* tv size */ 233 dss_mgr_set_timings(channel, vm); 234 235 r = dss_mgr_enable(channel); 236 if (r) 237 goto err_mgr_enable; 238 239 r = hdmi_wp_video_start(&hdmi.wp); 240 if (r) 241 goto err_vid_enable; 242 243 hdmi_wp_set_irqenable(wp, 244 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT); 245 246 return 0; 247 248 err_vid_enable: 249 dss_mgr_disable(channel); 250 err_mgr_enable: 251 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF); 252 err_phy_pwr: 253 err_phy_cfg: 254 err_pll_cfg: 255 dss_pll_disable(&hdmi.pll.pll); 256 err_pll_enable: 257 hdmi_power_off_core(dssdev); 258 return -EIO; 259 } 260 261 static void hdmi_power_off_full(struct omap_dss_device *dssdev) 262 { 263 enum omap_channel channel = dssdev->dispc_channel; 264 265 hdmi_wp_clear_irqenable(&hdmi.wp, ~HDMI_IRQ_CORE); 266 267 hdmi_wp_video_stop(&hdmi.wp); 268 269 dss_mgr_disable(channel); 270 271 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF); 272 273 dss_pll_disable(&hdmi.pll.pll); 274 275 hdmi_power_off_core(dssdev); 276 } 277 278 static int hdmi_display_check_timing(struct omap_dss_device *dssdev, 279 struct videomode *vm) 280 { 281 if (!dispc_mgr_timings_ok(dssdev->dispc_channel, vm)) 282 return -EINVAL; 283 284 return 0; 285 } 286 287 static void hdmi_display_set_timing(struct omap_dss_device *dssdev, 288 struct videomode *vm) 289 { 290 mutex_lock(&hdmi.lock); 291 292 hdmi.cfg.vm = *vm; 293 294 dispc_set_tv_pclk(vm->pixelclock); 295 296 mutex_unlock(&hdmi.lock); 297 } 298 299 static void hdmi_display_get_timings(struct omap_dss_device *dssdev, 300 struct videomode *vm) 301 { 302 *vm = hdmi.cfg.vm; 303 } 304 305 static void hdmi_dump_regs(struct seq_file *s) 306 { 307 mutex_lock(&hdmi.lock); 308 309 if (hdmi_runtime_get()) { 310 mutex_unlock(&hdmi.lock); 311 return; 312 } 313 314 hdmi_wp_dump(&hdmi.wp, s); 315 hdmi_pll_dump(&hdmi.pll, s); 316 hdmi_phy_dump(&hdmi.phy, s); 317 hdmi4_core_dump(&hdmi.core, s); 318 319 hdmi_runtime_put(); 320 mutex_unlock(&hdmi.lock); 321 } 322 323 static int read_edid(u8 *buf, int len) 324 { 325 int r; 326 327 mutex_lock(&hdmi.lock); 328 329 r = hdmi_runtime_get(); 330 BUG_ON(r); 331 332 r = hdmi4_read_edid(&hdmi.core, buf, len); 333 334 hdmi_runtime_put(); 335 mutex_unlock(&hdmi.lock); 336 337 return r; 338 } 339 340 static void hdmi_start_audio_stream(struct omap_hdmi *hd) 341 { 342 hdmi_wp_audio_enable(&hd->wp, true); 343 hdmi4_audio_start(&hd->core, &hd->wp); 344 } 345 346 static void hdmi_stop_audio_stream(struct omap_hdmi *hd) 347 { 348 hdmi4_audio_stop(&hd->core, &hd->wp); 349 hdmi_wp_audio_enable(&hd->wp, false); 350 } 351 352 static int hdmi_display_enable(struct omap_dss_device *dssdev) 353 { 354 struct omap_dss_device *out = &hdmi.output; 355 unsigned long flags; 356 int r = 0; 357 358 DSSDBG("ENTER hdmi_display_enable\n"); 359 360 mutex_lock(&hdmi.lock); 361 362 if (!out->dispc_channel_connected) { 363 DSSERR("failed to enable display: no output/manager\n"); 364 r = -ENODEV; 365 goto err0; 366 } 367 368 r = hdmi_power_on_full(dssdev); 369 if (r) { 370 DSSERR("failed to power on device\n"); 371 goto err0; 372 } 373 374 if (hdmi.audio_configured) { 375 r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, &hdmi.audio_config, 376 hdmi.cfg.vm.pixelclock); 377 if (r) { 378 DSSERR("Error restoring audio configuration: %d", r); 379 hdmi.audio_abort_cb(&hdmi.pdev->dev); 380 hdmi.audio_configured = false; 381 } 382 } 383 384 spin_lock_irqsave(&hdmi.audio_playing_lock, flags); 385 if (hdmi.audio_configured && hdmi.audio_playing) 386 hdmi_start_audio_stream(&hdmi); 387 hdmi.display_enabled = true; 388 spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags); 389 390 mutex_unlock(&hdmi.lock); 391 return 0; 392 393 err0: 394 mutex_unlock(&hdmi.lock); 395 return r; 396 } 397 398 static void hdmi_display_disable(struct omap_dss_device *dssdev) 399 { 400 unsigned long flags; 401 402 DSSDBG("Enter hdmi_display_disable\n"); 403 404 mutex_lock(&hdmi.lock); 405 406 spin_lock_irqsave(&hdmi.audio_playing_lock, flags); 407 hdmi_stop_audio_stream(&hdmi); 408 hdmi.display_enabled = false; 409 spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags); 410 411 hdmi_power_off_full(dssdev); 412 413 mutex_unlock(&hdmi.lock); 414 } 415 416 int hdmi4_core_enable(struct omap_dss_device *dssdev) 417 { 418 int r = 0; 419 420 DSSDBG("ENTER omapdss_hdmi4_core_enable\n"); 421 422 mutex_lock(&hdmi.lock); 423 424 r = hdmi_power_on_core(dssdev); 425 if (r) { 426 DSSERR("failed to power on device\n"); 427 goto err0; 428 } 429 430 mutex_unlock(&hdmi.lock); 431 return 0; 432 433 err0: 434 mutex_unlock(&hdmi.lock); 435 return r; 436 } 437 438 void hdmi4_core_disable(struct omap_dss_device *dssdev) 439 { 440 DSSDBG("Enter omapdss_hdmi4_core_disable\n"); 441 442 mutex_lock(&hdmi.lock); 443 444 hdmi_power_off_core(dssdev); 445 446 mutex_unlock(&hdmi.lock); 447 } 448 449 static int hdmi_connect(struct omap_dss_device *dssdev, 450 struct omap_dss_device *dst) 451 { 452 enum omap_channel channel = dssdev->dispc_channel; 453 int r; 454 455 r = hdmi_init_regulator(); 456 if (r) 457 return r; 458 459 r = dss_mgr_connect(channel, dssdev); 460 if (r) 461 return r; 462 463 r = omapdss_output_set_device(dssdev, dst); 464 if (r) { 465 DSSERR("failed to connect output to new device: %s\n", 466 dst->name); 467 dss_mgr_disconnect(channel, dssdev); 468 return r; 469 } 470 471 return 0; 472 } 473 474 static void hdmi_disconnect(struct omap_dss_device *dssdev, 475 struct omap_dss_device *dst) 476 { 477 enum omap_channel channel = dssdev->dispc_channel; 478 479 WARN_ON(dst != dssdev->dst); 480 481 if (dst != dssdev->dst) 482 return; 483 484 omapdss_output_unset_device(dssdev); 485 486 dss_mgr_disconnect(channel, dssdev); 487 } 488 489 static int hdmi_read_edid(struct omap_dss_device *dssdev, 490 u8 *edid, int len) 491 { 492 bool need_enable; 493 int r; 494 495 need_enable = hdmi.core_enabled == false; 496 497 if (need_enable) { 498 r = hdmi4_core_enable(dssdev); 499 if (r) 500 return r; 501 } 502 503 r = read_edid(edid, len); 504 if (r >= 256) 505 hdmi4_cec_set_phys_addr(&hdmi.core, 506 cec_get_edid_phys_addr(edid, r, NULL)); 507 else 508 hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID); 509 if (need_enable) 510 hdmi4_core_disable(dssdev); 511 512 return r; 513 } 514 515 static void hdmi_lost_hotplug(struct omap_dss_device *dssdev) 516 { 517 hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID); 518 } 519 520 static int hdmi_set_infoframe(struct omap_dss_device *dssdev, 521 const struct hdmi_avi_infoframe *avi) 522 { 523 hdmi.cfg.infoframe = *avi; 524 return 0; 525 } 526 527 static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev, 528 bool hdmi_mode) 529 { 530 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI; 531 return 0; 532 } 533 534 static const struct omapdss_hdmi_ops hdmi_ops = { 535 .connect = hdmi_connect, 536 .disconnect = hdmi_disconnect, 537 538 .enable = hdmi_display_enable, 539 .disable = hdmi_display_disable, 540 541 .check_timings = hdmi_display_check_timing, 542 .set_timings = hdmi_display_set_timing, 543 .get_timings = hdmi_display_get_timings, 544 545 .read_edid = hdmi_read_edid, 546 .lost_hotplug = hdmi_lost_hotplug, 547 .set_infoframe = hdmi_set_infoframe, 548 .set_hdmi_mode = hdmi_set_hdmi_mode, 549 }; 550 551 static void hdmi_init_output(struct platform_device *pdev) 552 { 553 struct omap_dss_device *out = &hdmi.output; 554 555 out->dev = &pdev->dev; 556 out->id = OMAP_DSS_OUTPUT_HDMI; 557 out->output_type = OMAP_DISPLAY_TYPE_HDMI; 558 out->name = "hdmi.0"; 559 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT; 560 out->ops.hdmi = &hdmi_ops; 561 out->owner = THIS_MODULE; 562 563 omapdss_register_output(out); 564 } 565 566 static void hdmi_uninit_output(struct platform_device *pdev) 567 { 568 struct omap_dss_device *out = &hdmi.output; 569 570 omapdss_unregister_output(out); 571 } 572 573 static int hdmi_probe_of(struct platform_device *pdev) 574 { 575 struct device_node *node = pdev->dev.of_node; 576 struct device_node *ep; 577 int r; 578 579 ep = of_graph_get_endpoint_by_regs(node, 0, 0); 580 if (!ep) 581 return 0; 582 583 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy); 584 if (r) 585 goto err; 586 587 of_node_put(ep); 588 return 0; 589 590 err: 591 of_node_put(ep); 592 return r; 593 } 594 595 /* Audio callbacks */ 596 static int hdmi_audio_startup(struct device *dev, 597 void (*abort_cb)(struct device *dev)) 598 { 599 struct omap_hdmi *hd = dev_get_drvdata(dev); 600 int ret = 0; 601 602 mutex_lock(&hd->lock); 603 604 if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) { 605 ret = -EPERM; 606 goto out; 607 } 608 609 hd->audio_abort_cb = abort_cb; 610 611 out: 612 mutex_unlock(&hd->lock); 613 614 return ret; 615 } 616 617 static int hdmi_audio_shutdown(struct device *dev) 618 { 619 struct omap_hdmi *hd = dev_get_drvdata(dev); 620 621 mutex_lock(&hd->lock); 622 hd->audio_abort_cb = NULL; 623 hd->audio_configured = false; 624 hd->audio_playing = false; 625 mutex_unlock(&hd->lock); 626 627 return 0; 628 } 629 630 static int hdmi_audio_start(struct device *dev) 631 { 632 struct omap_hdmi *hd = dev_get_drvdata(dev); 633 unsigned long flags; 634 635 WARN_ON(!hdmi_mode_has_audio(&hd->cfg)); 636 637 spin_lock_irqsave(&hd->audio_playing_lock, flags); 638 639 if (hd->display_enabled) 640 hdmi_start_audio_stream(hd); 641 hd->audio_playing = true; 642 643 spin_unlock_irqrestore(&hd->audio_playing_lock, flags); 644 return 0; 645 } 646 647 static void hdmi_audio_stop(struct device *dev) 648 { 649 struct omap_hdmi *hd = dev_get_drvdata(dev); 650 unsigned long flags; 651 652 WARN_ON(!hdmi_mode_has_audio(&hd->cfg)); 653 654 spin_lock_irqsave(&hd->audio_playing_lock, flags); 655 656 if (hd->display_enabled) 657 hdmi_stop_audio_stream(hd); 658 hd->audio_playing = false; 659 660 spin_unlock_irqrestore(&hd->audio_playing_lock, flags); 661 } 662 663 static int hdmi_audio_config(struct device *dev, 664 struct omap_dss_audio *dss_audio) 665 { 666 struct omap_hdmi *hd = dev_get_drvdata(dev); 667 int ret; 668 669 mutex_lock(&hd->lock); 670 671 if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) { 672 ret = -EPERM; 673 goto out; 674 } 675 676 ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio, 677 hd->cfg.vm.pixelclock); 678 if (!ret) { 679 hd->audio_configured = true; 680 hd->audio_config = *dss_audio; 681 } 682 out: 683 mutex_unlock(&hd->lock); 684 685 return ret; 686 } 687 688 static const struct omap_hdmi_audio_ops hdmi_audio_ops = { 689 .audio_startup = hdmi_audio_startup, 690 .audio_shutdown = hdmi_audio_shutdown, 691 .audio_start = hdmi_audio_start, 692 .audio_stop = hdmi_audio_stop, 693 .audio_config = hdmi_audio_config, 694 }; 695 696 static int hdmi_audio_register(struct device *dev) 697 { 698 struct omap_hdmi_audio_pdata pdata = { 699 .dev = dev, 700 .version = 4, 701 .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi.wp), 702 .ops = &hdmi_audio_ops, 703 }; 704 705 hdmi.audio_pdev = platform_device_register_data( 706 dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO, 707 &pdata, sizeof(pdata)); 708 709 if (IS_ERR(hdmi.audio_pdev)) 710 return PTR_ERR(hdmi.audio_pdev); 711 712 return 0; 713 } 714 715 /* HDMI HW IP initialisation */ 716 static int hdmi4_bind(struct device *dev, struct device *master, void *data) 717 { 718 struct platform_device *pdev = to_platform_device(dev); 719 int r; 720 int irq; 721 722 hdmi.pdev = pdev; 723 dev_set_drvdata(&pdev->dev, &hdmi); 724 725 mutex_init(&hdmi.lock); 726 spin_lock_init(&hdmi.audio_playing_lock); 727 728 r = hdmi_probe_of(pdev); 729 if (r) 730 return r; 731 732 r = hdmi_wp_init(pdev, &hdmi.wp, 4); 733 if (r) 734 return r; 735 736 r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp); 737 if (r) 738 return r; 739 740 r = hdmi_phy_init(pdev, &hdmi.phy, 4); 741 if (r) 742 goto err; 743 744 r = hdmi4_core_init(pdev, &hdmi.core); 745 if (r) 746 goto err; 747 748 r = hdmi4_cec_init(pdev, &hdmi.core, &hdmi.wp); 749 if (r) 750 goto err; 751 752 irq = platform_get_irq(pdev, 0); 753 if (irq < 0) { 754 DSSERR("platform_get_irq failed\n"); 755 r = -ENODEV; 756 goto err; 757 } 758 759 r = devm_request_threaded_irq(&pdev->dev, irq, 760 NULL, hdmi_irq_handler, 761 IRQF_ONESHOT, "OMAP HDMI", &hdmi); 762 if (r) { 763 DSSERR("HDMI IRQ request failed\n"); 764 goto err; 765 } 766 767 pm_runtime_enable(&pdev->dev); 768 769 hdmi_init_output(pdev); 770 771 r = hdmi_audio_register(&pdev->dev); 772 if (r) { 773 DSSERR("Registering HDMI audio failed\n"); 774 hdmi_uninit_output(pdev); 775 pm_runtime_disable(&pdev->dev); 776 return r; 777 } 778 779 dss_debugfs_create_file("hdmi", hdmi_dump_regs); 780 781 return 0; 782 err: 783 hdmi_pll_uninit(&hdmi.pll); 784 return r; 785 } 786 787 static void hdmi4_unbind(struct device *dev, struct device *master, void *data) 788 { 789 struct platform_device *pdev = to_platform_device(dev); 790 791 if (hdmi.audio_pdev) 792 platform_device_unregister(hdmi.audio_pdev); 793 794 hdmi_uninit_output(pdev); 795 796 hdmi4_cec_uninit(&hdmi.core); 797 798 hdmi_pll_uninit(&hdmi.pll); 799 800 pm_runtime_disable(&pdev->dev); 801 } 802 803 static const struct component_ops hdmi4_component_ops = { 804 .bind = hdmi4_bind, 805 .unbind = hdmi4_unbind, 806 }; 807 808 static int hdmi4_probe(struct platform_device *pdev) 809 { 810 return component_add(&pdev->dev, &hdmi4_component_ops); 811 } 812 813 static int hdmi4_remove(struct platform_device *pdev) 814 { 815 component_del(&pdev->dev, &hdmi4_component_ops); 816 return 0; 817 } 818 819 static int hdmi_runtime_suspend(struct device *dev) 820 { 821 dispc_runtime_put(); 822 823 return 0; 824 } 825 826 static int hdmi_runtime_resume(struct device *dev) 827 { 828 int r; 829 830 r = dispc_runtime_get(); 831 if (r < 0) 832 return r; 833 834 return 0; 835 } 836 837 static const struct dev_pm_ops hdmi_pm_ops = { 838 .runtime_suspend = hdmi_runtime_suspend, 839 .runtime_resume = hdmi_runtime_resume, 840 }; 841 842 static const struct of_device_id hdmi_of_match[] = { 843 { .compatible = "ti,omap4-hdmi", }, 844 {}, 845 }; 846 847 static struct platform_driver omapdss_hdmihw_driver = { 848 .probe = hdmi4_probe, 849 .remove = hdmi4_remove, 850 .driver = { 851 .name = "omapdss_hdmi", 852 .pm = &hdmi_pm_ops, 853 .of_match_table = hdmi_of_match, 854 .suppress_bind_attrs = true, 855 }, 856 }; 857 858 int __init hdmi4_init_platform_driver(void) 859 { 860 return platform_driver_register(&omapdss_hdmihw_driver); 861 } 862 863 void hdmi4_uninit_platform_driver(void) 864 { 865 platform_driver_unregister(&omapdss_hdmihw_driver); 866 } 867