1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 29960aa7cSTomi Valkeinen /* 39960aa7cSTomi Valkeinen * HDMI interface DSS driver for TI's OMAP4 family of SoCs. 4bb5cdf8dSAndrew F. Davis * 59960aa7cSTomi Valkeinen * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/ 69960aa7cSTomi Valkeinen * Authors: Yong Zhi 79960aa7cSTomi Valkeinen * Mythri pk <mythripk@ti.com> 89960aa7cSTomi Valkeinen */ 99960aa7cSTomi Valkeinen 109960aa7cSTomi Valkeinen #define DSS_SUBSYS_NAME "HDMI" 119960aa7cSTomi Valkeinen 129960aa7cSTomi Valkeinen #include <linux/kernel.h> 139960aa7cSTomi Valkeinen #include <linux/module.h> 149960aa7cSTomi Valkeinen #include <linux/err.h> 159960aa7cSTomi Valkeinen #include <linux/io.h> 169960aa7cSTomi Valkeinen #include <linux/interrupt.h> 179960aa7cSTomi Valkeinen #include <linux/mutex.h> 189960aa7cSTomi Valkeinen #include <linux/delay.h> 199960aa7cSTomi Valkeinen #include <linux/string.h> 209960aa7cSTomi Valkeinen #include <linux/platform_device.h> 219960aa7cSTomi Valkeinen #include <linux/pm_runtime.h> 229960aa7cSTomi Valkeinen #include <linux/clk.h> 239960aa7cSTomi Valkeinen #include <linux/gpio.h> 249960aa7cSTomi Valkeinen #include <linux/regulator/consumer.h> 259960aa7cSTomi Valkeinen #include <linux/component.h> 26d9e32ecdSTomi Valkeinen #include <linux/of.h> 2709bffa6eSRob Herring #include <linux/of_graph.h> 289960aa7cSTomi Valkeinen #include <sound/omap-hdmi-audio.h> 291897e1a3SHans Verkuil #include <media/cec.h> 309960aa7cSTomi Valkeinen 31*3c983905SLaurent Pinchart #include <drm/drm_atomic.h> 32*3c983905SLaurent Pinchart #include <drm/drm_atomic_state_helper.h> 33*3c983905SLaurent Pinchart 3432043da7SPeter Ujfalusi #include "omapdss.h" 359960aa7cSTomi Valkeinen #include "hdmi4_core.h" 361897e1a3SHans Verkuil #include "hdmi4_cec.h" 379960aa7cSTomi Valkeinen #include "dss.h" 389960aa7cSTomi Valkeinen #include "hdmi.h" 399960aa7cSTomi Valkeinen 40ac767456SLaurent Pinchart static int hdmi_runtime_get(struct omap_hdmi *hdmi) 419960aa7cSTomi Valkeinen { 429960aa7cSTomi Valkeinen int r; 439960aa7cSTomi Valkeinen 449960aa7cSTomi Valkeinen DSSDBG("hdmi_runtime_get\n"); 459960aa7cSTomi Valkeinen 46ac767456SLaurent Pinchart r = pm_runtime_get_sync(&hdmi->pdev->dev); 479960aa7cSTomi Valkeinen WARN_ON(r < 0); 489960aa7cSTomi Valkeinen if (r < 0) 499960aa7cSTomi Valkeinen return r; 509960aa7cSTomi Valkeinen 519960aa7cSTomi Valkeinen return 0; 529960aa7cSTomi Valkeinen } 539960aa7cSTomi Valkeinen 54ac767456SLaurent Pinchart static void hdmi_runtime_put(struct omap_hdmi *hdmi) 559960aa7cSTomi Valkeinen { 569960aa7cSTomi Valkeinen int r; 579960aa7cSTomi Valkeinen 589960aa7cSTomi Valkeinen DSSDBG("hdmi_runtime_put\n"); 599960aa7cSTomi Valkeinen 60ac767456SLaurent Pinchart r = pm_runtime_put_sync(&hdmi->pdev->dev); 619960aa7cSTomi Valkeinen WARN_ON(r < 0 && r != -ENOSYS); 629960aa7cSTomi Valkeinen } 639960aa7cSTomi Valkeinen 649960aa7cSTomi Valkeinen static irqreturn_t hdmi_irq_handler(int irq, void *data) 659960aa7cSTomi Valkeinen { 66f3096a4aSHans Verkuil struct omap_hdmi *hdmi = data; 67f3096a4aSHans Verkuil struct hdmi_wp_data *wp = &hdmi->wp; 689960aa7cSTomi Valkeinen u32 irqstatus; 699960aa7cSTomi Valkeinen 709960aa7cSTomi Valkeinen irqstatus = hdmi_wp_get_irqstatus(wp); 719960aa7cSTomi Valkeinen hdmi_wp_set_irqstatus(wp, irqstatus); 729960aa7cSTomi Valkeinen 739960aa7cSTomi Valkeinen if ((irqstatus & HDMI_IRQ_LINK_CONNECT) && 749960aa7cSTomi Valkeinen irqstatus & HDMI_IRQ_LINK_DISCONNECT) { 759960aa7cSTomi Valkeinen /* 769960aa7cSTomi Valkeinen * If we get both connect and disconnect interrupts at the same 779960aa7cSTomi Valkeinen * time, turn off the PHY, clear interrupts, and restart, which 789960aa7cSTomi Valkeinen * raises connect interrupt if a cable is connected, or nothing 799960aa7cSTomi Valkeinen * if cable is not connected. 809960aa7cSTomi Valkeinen */ 819960aa7cSTomi Valkeinen hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF); 829960aa7cSTomi Valkeinen 839960aa7cSTomi Valkeinen hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT | 849960aa7cSTomi Valkeinen HDMI_IRQ_LINK_DISCONNECT); 859960aa7cSTomi Valkeinen 869960aa7cSTomi Valkeinen hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 879960aa7cSTomi Valkeinen } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) { 889960aa7cSTomi Valkeinen hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON); 899960aa7cSTomi Valkeinen } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) { 909960aa7cSTomi Valkeinen hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 919960aa7cSTomi Valkeinen } 921897e1a3SHans Verkuil if (irqstatus & HDMI_IRQ_CORE) { 931897e1a3SHans Verkuil u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4); 941897e1a3SHans Verkuil 951897e1a3SHans Verkuil hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4); 961897e1a3SHans Verkuil if (intr4 & 8) 971897e1a3SHans Verkuil hdmi4_cec_irq(&hdmi->core); 981897e1a3SHans Verkuil } 999960aa7cSTomi Valkeinen 1009960aa7cSTomi Valkeinen return IRQ_HANDLED; 1019960aa7cSTomi Valkeinen } 1029960aa7cSTomi Valkeinen 103ac767456SLaurent Pinchart static int hdmi_power_on_core(struct omap_hdmi *hdmi) 1049960aa7cSTomi Valkeinen { 1059960aa7cSTomi Valkeinen int r; 1069960aa7cSTomi Valkeinen 107ac767456SLaurent Pinchart if (hdmi->core.core_pwr_cnt++) 108a141a296SHans Verkuil return 0; 109a141a296SHans Verkuil 110ac767456SLaurent Pinchart r = regulator_enable(hdmi->vdda_reg); 1119960aa7cSTomi Valkeinen if (r) 112a141a296SHans Verkuil goto err_reg_enable; 1139960aa7cSTomi Valkeinen 114ac767456SLaurent Pinchart r = hdmi_runtime_get(hdmi); 1159960aa7cSTomi Valkeinen if (r) 1169960aa7cSTomi Valkeinen goto err_runtime_get; 1179960aa7cSTomi Valkeinen 118ac767456SLaurent Pinchart hdmi4_core_powerdown_disable(&hdmi->core); 1191d54ecf2SHans Verkuil 1209960aa7cSTomi Valkeinen /* Make selection of HDMI in DSS */ 121ac767456SLaurent Pinchart dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK); 1229960aa7cSTomi Valkeinen 123ac767456SLaurent Pinchart hdmi->core_enabled = true; 1249960aa7cSTomi Valkeinen 1259960aa7cSTomi Valkeinen return 0; 1269960aa7cSTomi Valkeinen 1279960aa7cSTomi Valkeinen err_runtime_get: 128ac767456SLaurent Pinchart regulator_disable(hdmi->vdda_reg); 129a141a296SHans Verkuil err_reg_enable: 130ac767456SLaurent Pinchart hdmi->core.core_pwr_cnt--; 1319960aa7cSTomi Valkeinen 1329960aa7cSTomi Valkeinen return r; 1339960aa7cSTomi Valkeinen } 1349960aa7cSTomi Valkeinen 135ac767456SLaurent Pinchart static void hdmi_power_off_core(struct omap_hdmi *hdmi) 1369960aa7cSTomi Valkeinen { 137ac767456SLaurent Pinchart if (--hdmi->core.core_pwr_cnt) 138a141a296SHans Verkuil return; 139a141a296SHans Verkuil 140ac767456SLaurent Pinchart hdmi->core_enabled = false; 1419960aa7cSTomi Valkeinen 142ac767456SLaurent Pinchart hdmi_runtime_put(hdmi); 143ac767456SLaurent Pinchart regulator_disable(hdmi->vdda_reg); 1449960aa7cSTomi Valkeinen } 1459960aa7cSTomi Valkeinen 146ac767456SLaurent Pinchart static int hdmi_power_on_full(struct omap_hdmi *hdmi) 1479960aa7cSTomi Valkeinen { 1489960aa7cSTomi Valkeinen int r; 14995e472daSLaurent Pinchart const struct videomode *vm; 150ac767456SLaurent Pinchart struct hdmi_wp_data *wp = &hdmi->wp; 1519960aa7cSTomi Valkeinen struct dss_pll_clock_info hdmi_cinfo = { 0 }; 152d11e5c82SLaurent Pinchart unsigned int pc; 1539960aa7cSTomi Valkeinen 154ac767456SLaurent Pinchart r = hdmi_power_on_core(hdmi); 1559960aa7cSTomi Valkeinen if (r) 1569960aa7cSTomi Valkeinen return r; 1579960aa7cSTomi Valkeinen 1589960aa7cSTomi Valkeinen /* disable and clear irqs */ 159f3096a4aSHans Verkuil hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE); 160f3096a4aSHans Verkuil hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE); 1619960aa7cSTomi Valkeinen 162ac767456SLaurent Pinchart vm = &hdmi->cfg.vm; 1639960aa7cSTomi Valkeinen 164da11bbbbSPeter Ujfalusi DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive, 165da11bbbbSPeter Ujfalusi vm->vactive); 1669960aa7cSTomi Valkeinen 167da11bbbbSPeter Ujfalusi pc = vm->pixelclock; 168da11bbbbSPeter Ujfalusi if (vm->flags & DISPLAY_FLAGS_DOUBLECLK) 16967d8ffddSTomi Valkeinen pc *= 2; 17067d8ffddSTomi Valkeinen 171c107751dSTomi Valkeinen /* DSS_HDMI_TCLK is bitclk / 10 */ 172c107751dSTomi Valkeinen pc *= 10; 173c107751dSTomi Valkeinen 174ac767456SLaurent Pinchart dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin), 175c17dc0e3STomi Valkeinen pc, &hdmi_cinfo); 1769960aa7cSTomi Valkeinen 177ac767456SLaurent Pinchart r = dss_pll_enable(&hdmi->pll.pll); 1789960aa7cSTomi Valkeinen if (r) { 1799960aa7cSTomi Valkeinen DSSERR("Failed to enable PLL\n"); 1809960aa7cSTomi Valkeinen goto err_pll_enable; 1819960aa7cSTomi Valkeinen } 1829960aa7cSTomi Valkeinen 183ac767456SLaurent Pinchart r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo); 1849960aa7cSTomi Valkeinen if (r) { 1859960aa7cSTomi Valkeinen DSSERR("Failed to configure PLL\n"); 1869960aa7cSTomi Valkeinen goto err_pll_cfg; 1879960aa7cSTomi Valkeinen } 1889960aa7cSTomi Valkeinen 189ac767456SLaurent Pinchart r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco, 1909960aa7cSTomi Valkeinen hdmi_cinfo.clkout[0]); 1919960aa7cSTomi Valkeinen if (r) { 1929960aa7cSTomi Valkeinen DSSDBG("Failed to configure PHY\n"); 1939960aa7cSTomi Valkeinen goto err_phy_cfg; 1949960aa7cSTomi Valkeinen } 1959960aa7cSTomi Valkeinen 1969960aa7cSTomi Valkeinen r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); 1979960aa7cSTomi Valkeinen if (r) 1989960aa7cSTomi Valkeinen goto err_phy_pwr; 1999960aa7cSTomi Valkeinen 200ac767456SLaurent Pinchart hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg); 2019960aa7cSTomi Valkeinen 202ac767456SLaurent Pinchart r = dss_mgr_enable(&hdmi->output); 2039960aa7cSTomi Valkeinen if (r) 2049960aa7cSTomi Valkeinen goto err_mgr_enable; 2059960aa7cSTomi Valkeinen 206ac767456SLaurent Pinchart r = hdmi_wp_video_start(&hdmi->wp); 2074e4b53ceSTomi Valkeinen if (r) 2084e4b53ceSTomi Valkeinen goto err_vid_enable; 2094e4b53ceSTomi Valkeinen 2109960aa7cSTomi Valkeinen hdmi_wp_set_irqenable(wp, 2119960aa7cSTomi Valkeinen HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT); 2129960aa7cSTomi Valkeinen 2139960aa7cSTomi Valkeinen return 0; 2149960aa7cSTomi Valkeinen 2159960aa7cSTomi Valkeinen err_vid_enable: 216ac767456SLaurent Pinchart dss_mgr_disable(&hdmi->output); 2174e4b53ceSTomi Valkeinen err_mgr_enable: 218ac767456SLaurent Pinchart hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF); 2199960aa7cSTomi Valkeinen err_phy_pwr: 2209960aa7cSTomi Valkeinen err_phy_cfg: 2219960aa7cSTomi Valkeinen err_pll_cfg: 222ac767456SLaurent Pinchart dss_pll_disable(&hdmi->pll.pll); 2239960aa7cSTomi Valkeinen err_pll_enable: 224ac767456SLaurent Pinchart hdmi_power_off_core(hdmi); 2259960aa7cSTomi Valkeinen return -EIO; 2269960aa7cSTomi Valkeinen } 2279960aa7cSTomi Valkeinen 228ac767456SLaurent Pinchart static void hdmi_power_off_full(struct omap_hdmi *hdmi) 2299960aa7cSTomi Valkeinen { 230ac767456SLaurent Pinchart hdmi_wp_clear_irqenable(&hdmi->wp, ~HDMI_IRQ_CORE); 2319960aa7cSTomi Valkeinen 232ac767456SLaurent Pinchart hdmi_wp_video_stop(&hdmi->wp); 2339960aa7cSTomi Valkeinen 234ac767456SLaurent Pinchart dss_mgr_disable(&hdmi->output); 2354e4b53ceSTomi Valkeinen 236ac767456SLaurent Pinchart hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF); 2379960aa7cSTomi Valkeinen 238ac767456SLaurent Pinchart dss_pll_disable(&hdmi->pll.pll); 2399960aa7cSTomi Valkeinen 240ac767456SLaurent Pinchart hdmi_power_off_core(hdmi); 2419960aa7cSTomi Valkeinen } 2429960aa7cSTomi Valkeinen 243f33656e1SLaurent Pinchart static int hdmi_dump_regs(struct seq_file *s, void *p) 2449960aa7cSTomi Valkeinen { 245ac767456SLaurent Pinchart struct omap_hdmi *hdmi = s->private; 2469960aa7cSTomi Valkeinen 247ac767456SLaurent Pinchart mutex_lock(&hdmi->lock); 248ac767456SLaurent Pinchart 249ac767456SLaurent Pinchart if (hdmi_runtime_get(hdmi)) { 250ac767456SLaurent Pinchart mutex_unlock(&hdmi->lock); 251f33656e1SLaurent Pinchart return 0; 2529960aa7cSTomi Valkeinen } 2539960aa7cSTomi Valkeinen 254ac767456SLaurent Pinchart hdmi_wp_dump(&hdmi->wp, s); 255ac767456SLaurent Pinchart hdmi_pll_dump(&hdmi->pll, s); 256ac767456SLaurent Pinchart hdmi_phy_dump(&hdmi->phy, s); 257ac767456SLaurent Pinchart hdmi4_core_dump(&hdmi->core, s); 2589960aa7cSTomi Valkeinen 259ac767456SLaurent Pinchart hdmi_runtime_put(hdmi); 260ac767456SLaurent Pinchart mutex_unlock(&hdmi->lock); 261f33656e1SLaurent Pinchart return 0; 2629960aa7cSTomi Valkeinen } 2639960aa7cSTomi Valkeinen 2649960aa7cSTomi Valkeinen static void hdmi_start_audio_stream(struct omap_hdmi *hd) 2659960aa7cSTomi Valkeinen { 2669960aa7cSTomi Valkeinen hdmi_wp_audio_enable(&hd->wp, true); 2679960aa7cSTomi Valkeinen hdmi4_audio_start(&hd->core, &hd->wp); 2689960aa7cSTomi Valkeinen } 2699960aa7cSTomi Valkeinen 2709960aa7cSTomi Valkeinen static void hdmi_stop_audio_stream(struct omap_hdmi *hd) 2719960aa7cSTomi Valkeinen { 2729960aa7cSTomi Valkeinen hdmi4_audio_stop(&hd->core, &hd->wp); 2739960aa7cSTomi Valkeinen hdmi_wp_audio_enable(&hd->wp, false); 2749960aa7cSTomi Valkeinen } 2759960aa7cSTomi Valkeinen 276ac767456SLaurent Pinchart int hdmi4_core_enable(struct hdmi_core_data *core) 2779960aa7cSTomi Valkeinen { 278ac767456SLaurent Pinchart struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core); 2799960aa7cSTomi Valkeinen int r = 0; 2809960aa7cSTomi Valkeinen 2815bebbbfeSHans Verkuil DSSDBG("ENTER omapdss_hdmi4_core_enable\n"); 2829960aa7cSTomi Valkeinen 283ac767456SLaurent Pinchart mutex_lock(&hdmi->lock); 2849960aa7cSTomi Valkeinen 285ac767456SLaurent Pinchart r = hdmi_power_on_core(hdmi); 2869960aa7cSTomi Valkeinen if (r) { 2879960aa7cSTomi Valkeinen DSSERR("failed to power on device\n"); 2889960aa7cSTomi Valkeinen goto err0; 2899960aa7cSTomi Valkeinen } 2909960aa7cSTomi Valkeinen 291ac767456SLaurent Pinchart mutex_unlock(&hdmi->lock); 2929960aa7cSTomi Valkeinen return 0; 2939960aa7cSTomi Valkeinen 2949960aa7cSTomi Valkeinen err0: 295ac767456SLaurent Pinchart mutex_unlock(&hdmi->lock); 2969960aa7cSTomi Valkeinen return r; 2979960aa7cSTomi Valkeinen } 2989960aa7cSTomi Valkeinen 299ac767456SLaurent Pinchart void hdmi4_core_disable(struct hdmi_core_data *core) 3009960aa7cSTomi Valkeinen { 301ac767456SLaurent Pinchart struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core); 302ac767456SLaurent Pinchart 3035bebbbfeSHans Verkuil DSSDBG("Enter omapdss_hdmi4_core_disable\n"); 3049960aa7cSTomi Valkeinen 305ac767456SLaurent Pinchart mutex_lock(&hdmi->lock); 3069960aa7cSTomi Valkeinen 307ac767456SLaurent Pinchart hdmi_power_off_core(hdmi); 3089960aa7cSTomi Valkeinen 309ac767456SLaurent Pinchart mutex_unlock(&hdmi->lock); 3109960aa7cSTomi Valkeinen } 3119960aa7cSTomi Valkeinen 312511afb44SLaurent Pinchart static int hdmi_connect(struct omap_dss_device *src, 3139960aa7cSTomi Valkeinen struct omap_dss_device *dst) 3149960aa7cSTomi Valkeinen { 315f8a8eabbSLaurent Pinchart return omapdss_device_connect(dst->dss, dst, dst->next); 31671316556SLaurent Pinchart } 31771316556SLaurent Pinchart 318511afb44SLaurent Pinchart static void hdmi_disconnect(struct omap_dss_device *src, 3199960aa7cSTomi Valkeinen struct omap_dss_device *dst) 3209960aa7cSTomi Valkeinen { 321511afb44SLaurent Pinchart omapdss_device_disconnect(dst, dst->next); 3229960aa7cSTomi Valkeinen } 3239960aa7cSTomi Valkeinen 3240fe37173SLaurent Pinchart #define MAX_EDID 512 3250fe37173SLaurent Pinchart 326ee34f23aSLaurent Pinchart static struct edid *hdmi_read_edid_data(struct omap_hdmi *hdmi, 327ee34f23aSLaurent Pinchart struct drm_connector *connector) 3289960aa7cSTomi Valkeinen { 3290fe37173SLaurent Pinchart u8 *edid; 3309960aa7cSTomi Valkeinen int r; 3319960aa7cSTomi Valkeinen 3320fe37173SLaurent Pinchart edid = kzalloc(MAX_EDID, GFP_KERNEL); 3330fe37173SLaurent Pinchart if (!edid) 3340fe37173SLaurent Pinchart return NULL; 3350fe37173SLaurent Pinchart 336a4659694SLaurent Pinchart r = hdmi4_core_ddc_read(&hdmi->core, edid, 0, EDID_LENGTH); 337a4659694SLaurent Pinchart if (r) 338a4659694SLaurent Pinchart goto error; 339a4659694SLaurent Pinchart 340a4659694SLaurent Pinchart if (edid[0x7e] > 0) { 341a4659694SLaurent Pinchart char checksum = 0; 342a4659694SLaurent Pinchart unsigned int i; 343a4659694SLaurent Pinchart 344a4659694SLaurent Pinchart r = hdmi4_core_ddc_read(&hdmi->core, edid + EDID_LENGTH, 1, 345a4659694SLaurent Pinchart EDID_LENGTH); 346a4659694SLaurent Pinchart if (r) 347a4659694SLaurent Pinchart goto error; 348a4659694SLaurent Pinchart 349a4659694SLaurent Pinchart for (i = 0; i < EDID_LENGTH; ++i) 350a4659694SLaurent Pinchart checksum += edid[EDID_LENGTH + i]; 351a4659694SLaurent Pinchart 352a4659694SLaurent Pinchart if (checksum != 0) { 353a4659694SLaurent Pinchart DSSERR("E-EDID checksum failed!!\n"); 354a4659694SLaurent Pinchart goto error; 355a4659694SLaurent Pinchart } 356a4659694SLaurent Pinchart } 357a4659694SLaurent Pinchart 358a4659694SLaurent Pinchart return (struct edid *)edid; 359a4659694SLaurent Pinchart 360a4659694SLaurent Pinchart error: 361a4659694SLaurent Pinchart kfree(edid); 362a4659694SLaurent Pinchart return NULL; 363a4659694SLaurent Pinchart } 364a4659694SLaurent Pinchart 365ee34f23aSLaurent Pinchart static struct edid * 366ee34f23aSLaurent Pinchart hdmi_do_read_edid(struct omap_hdmi *hdmi, 367ee34f23aSLaurent Pinchart struct edid *(*read)(struct omap_hdmi *hdmi, 368ee34f23aSLaurent Pinchart struct drm_connector *connector), 369ee34f23aSLaurent Pinchart struct drm_connector *connector) 370a4659694SLaurent Pinchart { 371a4659694SLaurent Pinchart struct edid *edid = NULL; 372a4659694SLaurent Pinchart unsigned int cec_addr; 373a4659694SLaurent Pinchart bool need_enable; 374a4659694SLaurent Pinchart int r; 375a4659694SLaurent Pinchart 376ac767456SLaurent Pinchart need_enable = hdmi->core_enabled == false; 3779960aa7cSTomi Valkeinen 3789960aa7cSTomi Valkeinen if (need_enable) { 379ac767456SLaurent Pinchart r = hdmi4_core_enable(&hdmi->core); 380a4659694SLaurent Pinchart if (r) 3810fe37173SLaurent Pinchart return NULL; 3820fe37173SLaurent Pinchart } 3839960aa7cSTomi Valkeinen 384a4659694SLaurent Pinchart mutex_lock(&hdmi->lock); 385a4659694SLaurent Pinchart r = hdmi_runtime_get(hdmi); 386a4659694SLaurent Pinchart BUG_ON(r); 387a4659694SLaurent Pinchart 388a4659694SLaurent Pinchart r = hdmi4_core_ddc_init(&hdmi->core); 389a4659694SLaurent Pinchart if (r) 390a4659694SLaurent Pinchart goto done; 391a4659694SLaurent Pinchart 392ee34f23aSLaurent Pinchart edid = read(hdmi, connector); 393a4659694SLaurent Pinchart 394a4659694SLaurent Pinchart done: 395a4659694SLaurent Pinchart hdmi_runtime_put(hdmi); 396a4659694SLaurent Pinchart mutex_unlock(&hdmi->lock); 397a4659694SLaurent Pinchart 398a4659694SLaurent Pinchart if (edid && edid->extensions) { 399a4659694SLaurent Pinchart unsigned int len = (edid->extensions + 1) * EDID_LENGTH; 400a4659694SLaurent Pinchart 401a4659694SLaurent Pinchart cec_addr = cec_get_edid_phys_addr((u8 *)edid, len, NULL); 4020fe37173SLaurent Pinchart } else { 403a4659694SLaurent Pinchart cec_addr = CEC_PHYS_ADDR_INVALID; 4040fe37173SLaurent Pinchart } 4050fe37173SLaurent Pinchart 406a4659694SLaurent Pinchart hdmi4_cec_set_phys_addr(&hdmi->core, cec_addr); 407a4659694SLaurent Pinchart 4089960aa7cSTomi Valkeinen if (need_enable) 409ac767456SLaurent Pinchart hdmi4_core_disable(&hdmi->core); 4109960aa7cSTomi Valkeinen 411a4659694SLaurent Pinchart return edid; 4129960aa7cSTomi Valkeinen } 4139960aa7cSTomi Valkeinen 414ee34f23aSLaurent Pinchart static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev) 415ee34f23aSLaurent Pinchart { 416ee34f23aSLaurent Pinchart return hdmi_do_read_edid(dssdev_to_hdmi(dssdev), hdmi_read_edid_data, 417ee34f23aSLaurent Pinchart NULL); 418ee34f23aSLaurent Pinchart } 419ee34f23aSLaurent Pinchart 420019114efSHans Verkuil static void hdmi_lost_hotplug(struct omap_dss_device *dssdev) 421019114efSHans Verkuil { 422ac767456SLaurent Pinchart struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); 423ac767456SLaurent Pinchart 424ac767456SLaurent Pinchart hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID); 425019114efSHans Verkuil } 426019114efSHans Verkuil 427b93109d7SLaurent Pinchart static const struct omap_dss_device_ops hdmi_ops = { 4289960aa7cSTomi Valkeinen .connect = hdmi_connect, 4299960aa7cSTomi Valkeinen .disconnect = hdmi_disconnect, 4309960aa7cSTomi Valkeinen 4319960aa7cSTomi Valkeinen .read_edid = hdmi_read_edid, 43283910ad3SLaurent Pinchart 43383910ad3SLaurent Pinchart .hdmi = { 434019114efSHans Verkuil .lost_hotplug = hdmi_lost_hotplug, 435b93109d7SLaurent Pinchart }, 4369960aa7cSTomi Valkeinen }; 4379960aa7cSTomi Valkeinen 4385fc15d98SLaurent Pinchart /* ----------------------------------------------------------------------------- 439ee34f23aSLaurent Pinchart * DRM Bridge Operations 440ee34f23aSLaurent Pinchart */ 441ee34f23aSLaurent Pinchart 442ee34f23aSLaurent Pinchart static int hdmi4_bridge_attach(struct drm_bridge *bridge, 443ee34f23aSLaurent Pinchart enum drm_bridge_attach_flags flags) 444ee34f23aSLaurent Pinchart { 445ee34f23aSLaurent Pinchart struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); 446ee34f23aSLaurent Pinchart 447ee34f23aSLaurent Pinchart if (!hdmi->output.next_bridge) 448ee34f23aSLaurent Pinchart return 0; 449ee34f23aSLaurent Pinchart 450ee34f23aSLaurent Pinchart return drm_bridge_attach(bridge->encoder, hdmi->output.next_bridge, 451ee34f23aSLaurent Pinchart bridge, flags); 452ee34f23aSLaurent Pinchart } 453ee34f23aSLaurent Pinchart 454*3c983905SLaurent Pinchart static void hdmi4_bridge_mode_set(struct drm_bridge *bridge, 455*3c983905SLaurent Pinchart const struct drm_display_mode *mode, 456*3c983905SLaurent Pinchart const struct drm_display_mode *adjusted_mode) 457*3c983905SLaurent Pinchart { 458*3c983905SLaurent Pinchart struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); 459*3c983905SLaurent Pinchart 460*3c983905SLaurent Pinchart mutex_lock(&hdmi->lock); 461*3c983905SLaurent Pinchart 462*3c983905SLaurent Pinchart drm_display_mode_to_videomode(adjusted_mode, &hdmi->cfg.vm); 463*3c983905SLaurent Pinchart 464*3c983905SLaurent Pinchart dispc_set_tv_pclk(hdmi->dss->dispc, adjusted_mode->clock * 1000); 465*3c983905SLaurent Pinchart 466*3c983905SLaurent Pinchart mutex_unlock(&hdmi->lock); 467*3c983905SLaurent Pinchart } 468*3c983905SLaurent Pinchart 469*3c983905SLaurent Pinchart static void hdmi4_bridge_enable(struct drm_bridge *bridge, 470*3c983905SLaurent Pinchart struct drm_bridge_state *bridge_state) 471*3c983905SLaurent Pinchart { 472*3c983905SLaurent Pinchart struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); 473*3c983905SLaurent Pinchart struct drm_atomic_state *state = bridge_state->base.state; 474*3c983905SLaurent Pinchart struct drm_connector_state *conn_state; 475*3c983905SLaurent Pinchart struct drm_connector *connector; 476*3c983905SLaurent Pinchart struct drm_crtc_state *crtc_state; 477*3c983905SLaurent Pinchart unsigned long flags; 478*3c983905SLaurent Pinchart int ret; 479*3c983905SLaurent Pinchart 480*3c983905SLaurent Pinchart /* 481*3c983905SLaurent Pinchart * None of these should fail, as the bridge can't be enabled without a 482*3c983905SLaurent Pinchart * valid CRTC to connector path with fully populated new states. 483*3c983905SLaurent Pinchart */ 484*3c983905SLaurent Pinchart connector = drm_atomic_get_new_connector_for_encoder(state, 485*3c983905SLaurent Pinchart bridge->encoder); 486*3c983905SLaurent Pinchart if (WARN_ON(!connector)) 487*3c983905SLaurent Pinchart return; 488*3c983905SLaurent Pinchart conn_state = drm_atomic_get_new_connector_state(state, connector); 489*3c983905SLaurent Pinchart if (WARN_ON(!conn_state)) 490*3c983905SLaurent Pinchart return; 491*3c983905SLaurent Pinchart crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); 492*3c983905SLaurent Pinchart if (WARN_ON(!crtc_state)) 493*3c983905SLaurent Pinchart return; 494*3c983905SLaurent Pinchart 495*3c983905SLaurent Pinchart hdmi->cfg.hdmi_dvi_mode = connector->display_info.is_hdmi 496*3c983905SLaurent Pinchart ? HDMI_HDMI : HDMI_DVI; 497*3c983905SLaurent Pinchart 498*3c983905SLaurent Pinchart if (connector->display_info.is_hdmi) { 499*3c983905SLaurent Pinchart const struct drm_display_mode *mode; 500*3c983905SLaurent Pinchart struct hdmi_avi_infoframe avi; 501*3c983905SLaurent Pinchart 502*3c983905SLaurent Pinchart mode = &crtc_state->adjusted_mode; 503*3c983905SLaurent Pinchart ret = drm_hdmi_avi_infoframe_from_display_mode(&avi, connector, 504*3c983905SLaurent Pinchart mode); 505*3c983905SLaurent Pinchart if (ret == 0) 506*3c983905SLaurent Pinchart hdmi->cfg.infoframe = avi; 507*3c983905SLaurent Pinchart } 508*3c983905SLaurent Pinchart 509*3c983905SLaurent Pinchart mutex_lock(&hdmi->lock); 510*3c983905SLaurent Pinchart 511*3c983905SLaurent Pinchart ret = hdmi_power_on_full(hdmi); 512*3c983905SLaurent Pinchart if (ret) { 513*3c983905SLaurent Pinchart DSSERR("failed to power on device\n"); 514*3c983905SLaurent Pinchart goto done; 515*3c983905SLaurent Pinchart } 516*3c983905SLaurent Pinchart 517*3c983905SLaurent Pinchart if (hdmi->audio_configured) { 518*3c983905SLaurent Pinchart ret = hdmi4_audio_config(&hdmi->core, &hdmi->wp, 519*3c983905SLaurent Pinchart &hdmi->audio_config, 520*3c983905SLaurent Pinchart hdmi->cfg.vm.pixelclock); 521*3c983905SLaurent Pinchart if (ret) { 522*3c983905SLaurent Pinchart DSSERR("Error restoring audio configuration: %d", ret); 523*3c983905SLaurent Pinchart hdmi->audio_abort_cb(&hdmi->pdev->dev); 524*3c983905SLaurent Pinchart hdmi->audio_configured = false; 525*3c983905SLaurent Pinchart } 526*3c983905SLaurent Pinchart } 527*3c983905SLaurent Pinchart 528*3c983905SLaurent Pinchart spin_lock_irqsave(&hdmi->audio_playing_lock, flags); 529*3c983905SLaurent Pinchart if (hdmi->audio_configured && hdmi->audio_playing) 530*3c983905SLaurent Pinchart hdmi_start_audio_stream(hdmi); 531*3c983905SLaurent Pinchart hdmi->display_enabled = true; 532*3c983905SLaurent Pinchart spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags); 533*3c983905SLaurent Pinchart 534*3c983905SLaurent Pinchart done: 535*3c983905SLaurent Pinchart mutex_unlock(&hdmi->lock); 536*3c983905SLaurent Pinchart } 537*3c983905SLaurent Pinchart 538*3c983905SLaurent Pinchart static void hdmi4_bridge_disable(struct drm_bridge *bridge, 539*3c983905SLaurent Pinchart struct drm_bridge_state *bridge_state) 540*3c983905SLaurent Pinchart { 541*3c983905SLaurent Pinchart struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); 542*3c983905SLaurent Pinchart unsigned long flags; 543*3c983905SLaurent Pinchart 544*3c983905SLaurent Pinchart mutex_lock(&hdmi->lock); 545*3c983905SLaurent Pinchart 546*3c983905SLaurent Pinchart spin_lock_irqsave(&hdmi->audio_playing_lock, flags); 547*3c983905SLaurent Pinchart hdmi_stop_audio_stream(hdmi); 548*3c983905SLaurent Pinchart hdmi->display_enabled = false; 549*3c983905SLaurent Pinchart spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags); 550*3c983905SLaurent Pinchart 551*3c983905SLaurent Pinchart hdmi_power_off_full(hdmi); 552*3c983905SLaurent Pinchart 553*3c983905SLaurent Pinchart mutex_unlock(&hdmi->lock); 554*3c983905SLaurent Pinchart } 555*3c983905SLaurent Pinchart 556ee34f23aSLaurent Pinchart static struct edid *hdmi4_bridge_read_edid(struct omap_hdmi *hdmi, 557ee34f23aSLaurent Pinchart struct drm_connector *connector) 558ee34f23aSLaurent Pinchart { 559ee34f23aSLaurent Pinchart return drm_do_get_edid(connector, hdmi4_core_ddc_read, &hdmi->core); 560ee34f23aSLaurent Pinchart } 561ee34f23aSLaurent Pinchart 562ee34f23aSLaurent Pinchart static struct edid *hdmi4_bridge_get_edid(struct drm_bridge *bridge, 563ee34f23aSLaurent Pinchart struct drm_connector *connector) 564ee34f23aSLaurent Pinchart { 565ee34f23aSLaurent Pinchart struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); 566ee34f23aSLaurent Pinchart 567ee34f23aSLaurent Pinchart return hdmi_do_read_edid(hdmi, hdmi4_bridge_read_edid, connector); 568ee34f23aSLaurent Pinchart } 569ee34f23aSLaurent Pinchart 570ee34f23aSLaurent Pinchart static const struct drm_bridge_funcs hdmi4_bridge_funcs = { 571ee34f23aSLaurent Pinchart .attach = hdmi4_bridge_attach, 572*3c983905SLaurent Pinchart .mode_set = hdmi4_bridge_mode_set, 573*3c983905SLaurent Pinchart .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 574*3c983905SLaurent Pinchart .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 575*3c983905SLaurent Pinchart .atomic_reset = drm_atomic_helper_bridge_reset, 576*3c983905SLaurent Pinchart .atomic_enable = hdmi4_bridge_enable, 577*3c983905SLaurent Pinchart .atomic_disable = hdmi4_bridge_disable, 578ee34f23aSLaurent Pinchart .get_edid = hdmi4_bridge_get_edid, 579ee34f23aSLaurent Pinchart }; 580ee34f23aSLaurent Pinchart 581ee34f23aSLaurent Pinchart static void hdmi4_bridge_init(struct omap_hdmi *hdmi) 582ee34f23aSLaurent Pinchart { 583ee34f23aSLaurent Pinchart hdmi->bridge.funcs = &hdmi4_bridge_funcs; 584ee34f23aSLaurent Pinchart hdmi->bridge.of_node = hdmi->pdev->dev.of_node; 585ee34f23aSLaurent Pinchart hdmi->bridge.ops = DRM_BRIDGE_OP_EDID; 586ee34f23aSLaurent Pinchart hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; 587ee34f23aSLaurent Pinchart 588ee34f23aSLaurent Pinchart drm_bridge_add(&hdmi->bridge); 589ee34f23aSLaurent Pinchart } 590ee34f23aSLaurent Pinchart 591ee34f23aSLaurent Pinchart static void hdmi4_bridge_cleanup(struct omap_hdmi *hdmi) 592ee34f23aSLaurent Pinchart { 593ee34f23aSLaurent Pinchart drm_bridge_remove(&hdmi->bridge); 594ee34f23aSLaurent Pinchart } 595ee34f23aSLaurent Pinchart 596ee34f23aSLaurent Pinchart /* ----------------------------------------------------------------------------- 5975fc15d98SLaurent Pinchart * Audio Callbacks 5985fc15d98SLaurent Pinchart */ 5999960aa7cSTomi Valkeinen 6009960aa7cSTomi Valkeinen static int hdmi_audio_startup(struct device *dev, 6019960aa7cSTomi Valkeinen void (*abort_cb)(struct device *dev)) 6029960aa7cSTomi Valkeinen { 6039960aa7cSTomi Valkeinen struct omap_hdmi *hd = dev_get_drvdata(dev); 6049960aa7cSTomi Valkeinen 6059960aa7cSTomi Valkeinen mutex_lock(&hd->lock); 6069960aa7cSTomi Valkeinen 607c1899cb3SJyri Sarha WARN_ON(hd->audio_abort_cb != NULL); 6089960aa7cSTomi Valkeinen 6099960aa7cSTomi Valkeinen hd->audio_abort_cb = abort_cb; 6109960aa7cSTomi Valkeinen 6119960aa7cSTomi Valkeinen mutex_unlock(&hd->lock); 6129960aa7cSTomi Valkeinen 613c1899cb3SJyri Sarha return 0; 6149960aa7cSTomi Valkeinen } 6159960aa7cSTomi Valkeinen 6169960aa7cSTomi Valkeinen static int hdmi_audio_shutdown(struct device *dev) 6179960aa7cSTomi Valkeinen { 6189960aa7cSTomi Valkeinen struct omap_hdmi *hd = dev_get_drvdata(dev); 6199960aa7cSTomi Valkeinen 6209960aa7cSTomi Valkeinen mutex_lock(&hd->lock); 6219960aa7cSTomi Valkeinen hd->audio_abort_cb = NULL; 6229960aa7cSTomi Valkeinen hd->audio_configured = false; 6239960aa7cSTomi Valkeinen hd->audio_playing = false; 6249960aa7cSTomi Valkeinen mutex_unlock(&hd->lock); 6259960aa7cSTomi Valkeinen 6269960aa7cSTomi Valkeinen return 0; 6279960aa7cSTomi Valkeinen } 6289960aa7cSTomi Valkeinen 6299960aa7cSTomi Valkeinen static int hdmi_audio_start(struct device *dev) 6309960aa7cSTomi Valkeinen { 6319960aa7cSTomi Valkeinen struct omap_hdmi *hd = dev_get_drvdata(dev); 6329960aa7cSTomi Valkeinen unsigned long flags; 6339960aa7cSTomi Valkeinen 6349960aa7cSTomi Valkeinen spin_lock_irqsave(&hd->audio_playing_lock, flags); 6359960aa7cSTomi Valkeinen 636c1899cb3SJyri Sarha if (hd->display_enabled) { 637c1899cb3SJyri Sarha if (!hdmi_mode_has_audio(&hd->cfg)) 638c1899cb3SJyri Sarha DSSERR("%s: Video mode does not support audio\n", 639c1899cb3SJyri Sarha __func__); 6409960aa7cSTomi Valkeinen hdmi_start_audio_stream(hd); 641c1899cb3SJyri Sarha } 6429960aa7cSTomi Valkeinen hd->audio_playing = true; 6439960aa7cSTomi Valkeinen 6449960aa7cSTomi Valkeinen spin_unlock_irqrestore(&hd->audio_playing_lock, flags); 6459960aa7cSTomi Valkeinen return 0; 6469960aa7cSTomi Valkeinen } 6479960aa7cSTomi Valkeinen 6489960aa7cSTomi Valkeinen static void hdmi_audio_stop(struct device *dev) 6499960aa7cSTomi Valkeinen { 6509960aa7cSTomi Valkeinen struct omap_hdmi *hd = dev_get_drvdata(dev); 6519960aa7cSTomi Valkeinen unsigned long flags; 6529960aa7cSTomi Valkeinen 6539960aa7cSTomi Valkeinen WARN_ON(!hdmi_mode_has_audio(&hd->cfg)); 6549960aa7cSTomi Valkeinen 6559960aa7cSTomi Valkeinen spin_lock_irqsave(&hd->audio_playing_lock, flags); 6569960aa7cSTomi Valkeinen 6579960aa7cSTomi Valkeinen if (hd->display_enabled) 6589960aa7cSTomi Valkeinen hdmi_stop_audio_stream(hd); 6599960aa7cSTomi Valkeinen hd->audio_playing = false; 6609960aa7cSTomi Valkeinen 6619960aa7cSTomi Valkeinen spin_unlock_irqrestore(&hd->audio_playing_lock, flags); 6629960aa7cSTomi Valkeinen } 6639960aa7cSTomi Valkeinen 6649960aa7cSTomi Valkeinen static int hdmi_audio_config(struct device *dev, 6659960aa7cSTomi Valkeinen struct omap_dss_audio *dss_audio) 6669960aa7cSTomi Valkeinen { 6679960aa7cSTomi Valkeinen struct omap_hdmi *hd = dev_get_drvdata(dev); 66877eeac24STomi Valkeinen int ret = 0; 6699960aa7cSTomi Valkeinen 6709960aa7cSTomi Valkeinen mutex_lock(&hd->lock); 6719960aa7cSTomi Valkeinen 672c1899cb3SJyri Sarha if (hd->display_enabled) { 673c1899cb3SJyri Sarha ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio, 674c1899cb3SJyri Sarha hd->cfg.vm.pixelclock); 675c1899cb3SJyri Sarha if (ret) 6769960aa7cSTomi Valkeinen goto out; 6779960aa7cSTomi Valkeinen } 6789960aa7cSTomi Valkeinen 6799960aa7cSTomi Valkeinen hd->audio_configured = true; 6809960aa7cSTomi Valkeinen hd->audio_config = *dss_audio; 6819960aa7cSTomi Valkeinen out: 6829960aa7cSTomi Valkeinen mutex_unlock(&hd->lock); 6839960aa7cSTomi Valkeinen 6849960aa7cSTomi Valkeinen return ret; 6859960aa7cSTomi Valkeinen } 6869960aa7cSTomi Valkeinen 6879960aa7cSTomi Valkeinen static const struct omap_hdmi_audio_ops hdmi_audio_ops = { 6889960aa7cSTomi Valkeinen .audio_startup = hdmi_audio_startup, 6899960aa7cSTomi Valkeinen .audio_shutdown = hdmi_audio_shutdown, 6909960aa7cSTomi Valkeinen .audio_start = hdmi_audio_start, 6919960aa7cSTomi Valkeinen .audio_stop = hdmi_audio_stop, 6929960aa7cSTomi Valkeinen .audio_config = hdmi_audio_config, 6939960aa7cSTomi Valkeinen }; 6949960aa7cSTomi Valkeinen 695ac767456SLaurent Pinchart static int hdmi_audio_register(struct omap_hdmi *hdmi) 6969960aa7cSTomi Valkeinen { 6979960aa7cSTomi Valkeinen struct omap_hdmi_audio_pdata pdata = { 698ac767456SLaurent Pinchart .dev = &hdmi->pdev->dev, 699d20fa5a0SLaurent Pinchart .version = 4, 700ac767456SLaurent Pinchart .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp), 7019960aa7cSTomi Valkeinen .ops = &hdmi_audio_ops, 7029960aa7cSTomi Valkeinen }; 7039960aa7cSTomi Valkeinen 704ac767456SLaurent Pinchart hdmi->audio_pdev = platform_device_register_data( 705ac767456SLaurent Pinchart &hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO, 7069960aa7cSTomi Valkeinen &pdata, sizeof(pdata)); 7079960aa7cSTomi Valkeinen 708ac767456SLaurent Pinchart if (IS_ERR(hdmi->audio_pdev)) 709ac767456SLaurent Pinchart return PTR_ERR(hdmi->audio_pdev); 7109960aa7cSTomi Valkeinen 7119960aa7cSTomi Valkeinen return 0; 7129960aa7cSTomi Valkeinen } 7139960aa7cSTomi Valkeinen 7145fc15d98SLaurent Pinchart /* ----------------------------------------------------------------------------- 7155fc15d98SLaurent Pinchart * Component Bind & Unbind 7165fc15d98SLaurent Pinchart */ 7175fc15d98SLaurent Pinchart 7189960aa7cSTomi Valkeinen static int hdmi4_bind(struct device *dev, struct device *master, void *data) 7199960aa7cSTomi Valkeinen { 7207b295257SLaurent Pinchart struct dss_device *dss = dss_get_device(master); 7215fc15d98SLaurent Pinchart struct omap_hdmi *hdmi = dev_get_drvdata(dev); 7229960aa7cSTomi Valkeinen int r; 7239960aa7cSTomi Valkeinen 724ac767456SLaurent Pinchart hdmi->dss = dss; 7259960aa7cSTomi Valkeinen 726f8523b64SLaurent Pinchart r = hdmi_runtime_get(hdmi); 7279960aa7cSTomi Valkeinen if (r) 7285fc15d98SLaurent Pinchart return r; 7299960aa7cSTomi Valkeinen 730f8523b64SLaurent Pinchart r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp); 731f8523b64SLaurent Pinchart if (r) 732f8523b64SLaurent Pinchart goto err_runtime_put; 733f8523b64SLaurent Pinchart 7345fc15d98SLaurent Pinchart r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp); 7359960aa7cSTomi Valkeinen if (r) 7365fc15d98SLaurent Pinchart goto err_pll_uninit; 7379960aa7cSTomi Valkeinen 738ac767456SLaurent Pinchart r = hdmi_audio_register(hdmi); 7399960aa7cSTomi Valkeinen if (r) { 7409960aa7cSTomi Valkeinen DSSERR("Registering HDMI audio failed\n"); 7415fc15d98SLaurent Pinchart goto err_cec_uninit; 7429960aa7cSTomi Valkeinen } 7439960aa7cSTomi Valkeinen 744ac767456SLaurent Pinchart hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs, 745ac767456SLaurent Pinchart hdmi); 7469960aa7cSTomi Valkeinen 747f8523b64SLaurent Pinchart hdmi_runtime_put(hdmi); 748f8523b64SLaurent Pinchart 7499960aa7cSTomi Valkeinen return 0; 750ac767456SLaurent Pinchart 7515fc15d98SLaurent Pinchart err_cec_uninit: 7525fc15d98SLaurent Pinchart hdmi4_cec_uninit(&hdmi->core); 7535fc15d98SLaurent Pinchart err_pll_uninit: 754ac767456SLaurent Pinchart hdmi_pll_uninit(&hdmi->pll); 755f8523b64SLaurent Pinchart err_runtime_put: 756f8523b64SLaurent Pinchart hdmi_runtime_put(hdmi); 7579960aa7cSTomi Valkeinen return r; 7589960aa7cSTomi Valkeinen } 7599960aa7cSTomi Valkeinen 7609960aa7cSTomi Valkeinen static void hdmi4_unbind(struct device *dev, struct device *master, void *data) 7619960aa7cSTomi Valkeinen { 762ac767456SLaurent Pinchart struct omap_hdmi *hdmi = dev_get_drvdata(dev); 7639960aa7cSTomi Valkeinen 764ac767456SLaurent Pinchart dss_debugfs_remove_file(hdmi->debugfs); 765f33656e1SLaurent Pinchart 766ac767456SLaurent Pinchart if (hdmi->audio_pdev) 767ac767456SLaurent Pinchart platform_device_unregister(hdmi->audio_pdev); 7689960aa7cSTomi Valkeinen 769ac767456SLaurent Pinchart hdmi4_cec_uninit(&hdmi->core); 770ac767456SLaurent Pinchart hdmi_pll_uninit(&hdmi->pll); 7719960aa7cSTomi Valkeinen } 7729960aa7cSTomi Valkeinen 7739960aa7cSTomi Valkeinen static const struct component_ops hdmi4_component_ops = { 7749960aa7cSTomi Valkeinen .bind = hdmi4_bind, 7759960aa7cSTomi Valkeinen .unbind = hdmi4_unbind, 7769960aa7cSTomi Valkeinen }; 7779960aa7cSTomi Valkeinen 7785fc15d98SLaurent Pinchart /* ----------------------------------------------------------------------------- 7795fc15d98SLaurent Pinchart * Probe & Remove, Suspend & Resume 7805fc15d98SLaurent Pinchart */ 7815fc15d98SLaurent Pinchart 78227d62452SLaurent Pinchart static int hdmi4_init_output(struct omap_hdmi *hdmi) 7835fc15d98SLaurent Pinchart { 7845fc15d98SLaurent Pinchart struct omap_dss_device *out = &hdmi->output; 78571316556SLaurent Pinchart int r; 7865fc15d98SLaurent Pinchart 787ee34f23aSLaurent Pinchart hdmi4_bridge_init(hdmi); 788ee34f23aSLaurent Pinchart 7895fc15d98SLaurent Pinchart out->dev = &hdmi->pdev->dev; 7905fc15d98SLaurent Pinchart out->id = OMAP_DSS_OUTPUT_HDMI; 7910dbfc396SLaurent Pinchart out->type = OMAP_DISPLAY_TYPE_HDMI; 7925fc15d98SLaurent Pinchart out->name = "hdmi.0"; 7935fc15d98SLaurent Pinchart out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT; 7945fc15d98SLaurent Pinchart out->ops = &hdmi_ops; 7955fc15d98SLaurent Pinchart out->owner = THIS_MODULE; 796c83fefd7SLaurent Pinchart out->of_port = 0; 79790279e95SLaurent Pinchart out->ops_flags = OMAP_DSS_DEVICE_OP_EDID; 7985fc15d98SLaurent Pinchart 799ee34f23aSLaurent Pinchart r = omapdss_device_init_output(out, &hdmi->bridge); 800ee34f23aSLaurent Pinchart if (r < 0) { 801ee34f23aSLaurent Pinchart hdmi4_bridge_cleanup(hdmi); 80271316556SLaurent Pinchart return r; 803ee34f23aSLaurent Pinchart } 80471316556SLaurent Pinchart 8055fc15d98SLaurent Pinchart omapdss_device_register(out); 80627d62452SLaurent Pinchart 80727d62452SLaurent Pinchart return 0; 8085fc15d98SLaurent Pinchart } 8095fc15d98SLaurent Pinchart 8105fc15d98SLaurent Pinchart static void hdmi4_uninit_output(struct omap_hdmi *hdmi) 8115fc15d98SLaurent Pinchart { 8125fc15d98SLaurent Pinchart struct omap_dss_device *out = &hdmi->output; 8135fc15d98SLaurent Pinchart 8145fc15d98SLaurent Pinchart omapdss_device_unregister(out); 815d17eb453SLaurent Pinchart omapdss_device_cleanup_output(out); 816ee34f23aSLaurent Pinchart 817ee34f23aSLaurent Pinchart hdmi4_bridge_cleanup(hdmi); 8185fc15d98SLaurent Pinchart } 8195fc15d98SLaurent Pinchart 8205fc15d98SLaurent Pinchart static int hdmi4_probe_of(struct omap_hdmi *hdmi) 8215fc15d98SLaurent Pinchart { 8225fc15d98SLaurent Pinchart struct platform_device *pdev = hdmi->pdev; 8235fc15d98SLaurent Pinchart struct device_node *node = pdev->dev.of_node; 8245fc15d98SLaurent Pinchart struct device_node *ep; 8255fc15d98SLaurent Pinchart int r; 8265fc15d98SLaurent Pinchart 8275fc15d98SLaurent Pinchart ep = of_graph_get_endpoint_by_regs(node, 0, 0); 8285fc15d98SLaurent Pinchart if (!ep) 8295fc15d98SLaurent Pinchart return 0; 8305fc15d98SLaurent Pinchart 8315fc15d98SLaurent Pinchart r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy); 8325fc15d98SLaurent Pinchart of_node_put(ep); 8335fc15d98SLaurent Pinchart return r; 8345fc15d98SLaurent Pinchart } 8355fc15d98SLaurent Pinchart 8369960aa7cSTomi Valkeinen static int hdmi4_probe(struct platform_device *pdev) 8379960aa7cSTomi Valkeinen { 8385fc15d98SLaurent Pinchart struct omap_hdmi *hdmi; 8395fc15d98SLaurent Pinchart int irq; 8405fc15d98SLaurent Pinchart int r; 8415fc15d98SLaurent Pinchart 8425fc15d98SLaurent Pinchart hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL); 8435fc15d98SLaurent Pinchart if (!hdmi) 8445fc15d98SLaurent Pinchart return -ENOMEM; 8455fc15d98SLaurent Pinchart 8465fc15d98SLaurent Pinchart hdmi->pdev = pdev; 8475fc15d98SLaurent Pinchart 8485fc15d98SLaurent Pinchart dev_set_drvdata(&pdev->dev, hdmi); 8495fc15d98SLaurent Pinchart 8505fc15d98SLaurent Pinchart mutex_init(&hdmi->lock); 8515fc15d98SLaurent Pinchart spin_lock_init(&hdmi->audio_playing_lock); 8525fc15d98SLaurent Pinchart 8535fc15d98SLaurent Pinchart r = hdmi4_probe_of(hdmi); 8545fc15d98SLaurent Pinchart if (r) 8555fc15d98SLaurent Pinchart goto err_free; 8565fc15d98SLaurent Pinchart 8575fc15d98SLaurent Pinchart r = hdmi_wp_init(pdev, &hdmi->wp, 4); 8585fc15d98SLaurent Pinchart if (r) 8595fc15d98SLaurent Pinchart goto err_free; 8605fc15d98SLaurent Pinchart 8615fc15d98SLaurent Pinchart r = hdmi_phy_init(pdev, &hdmi->phy, 4); 8625fc15d98SLaurent Pinchart if (r) 8635fc15d98SLaurent Pinchart goto err_free; 8645fc15d98SLaurent Pinchart 8655fc15d98SLaurent Pinchart r = hdmi4_core_init(pdev, &hdmi->core); 8665fc15d98SLaurent Pinchart if (r) 8675fc15d98SLaurent Pinchart goto err_free; 8685fc15d98SLaurent Pinchart 8695fc15d98SLaurent Pinchart irq = platform_get_irq(pdev, 0); 8705fc15d98SLaurent Pinchart if (irq < 0) { 8715fc15d98SLaurent Pinchart DSSERR("platform_get_irq failed\n"); 8725fc15d98SLaurent Pinchart r = -ENODEV; 8735fc15d98SLaurent Pinchart goto err_free; 8745fc15d98SLaurent Pinchart } 8755fc15d98SLaurent Pinchart 8765fc15d98SLaurent Pinchart r = devm_request_threaded_irq(&pdev->dev, irq, 8775fc15d98SLaurent Pinchart NULL, hdmi_irq_handler, 8785fc15d98SLaurent Pinchart IRQF_ONESHOT, "OMAP HDMI", hdmi); 8795fc15d98SLaurent Pinchart if (r) { 8805fc15d98SLaurent Pinchart DSSERR("HDMI IRQ request failed\n"); 8815fc15d98SLaurent Pinchart goto err_free; 8825fc15d98SLaurent Pinchart } 8835fc15d98SLaurent Pinchart 8848a36357aSLaurent Pinchart hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda"); 8858a36357aSLaurent Pinchart if (IS_ERR(hdmi->vdda_reg)) { 8868a36357aSLaurent Pinchart r = PTR_ERR(hdmi->vdda_reg); 8878a36357aSLaurent Pinchart if (r != -EPROBE_DEFER) 8888a36357aSLaurent Pinchart DSSERR("can't get VDDA regulator\n"); 8898a36357aSLaurent Pinchart goto err_free; 8908a36357aSLaurent Pinchart } 8918a36357aSLaurent Pinchart 8925fc15d98SLaurent Pinchart pm_runtime_enable(&pdev->dev); 8935fc15d98SLaurent Pinchart 89427d62452SLaurent Pinchart r = hdmi4_init_output(hdmi); 89527d62452SLaurent Pinchart if (r) 89627d62452SLaurent Pinchart goto err_pm_disable; 8975fc15d98SLaurent Pinchart 8985fc15d98SLaurent Pinchart r = component_add(&pdev->dev, &hdmi4_component_ops); 8995fc15d98SLaurent Pinchart if (r) 9005fc15d98SLaurent Pinchart goto err_uninit_output; 9015fc15d98SLaurent Pinchart 9025fc15d98SLaurent Pinchart return 0; 9035fc15d98SLaurent Pinchart 9045fc15d98SLaurent Pinchart err_uninit_output: 9055fc15d98SLaurent Pinchart hdmi4_uninit_output(hdmi); 90627d62452SLaurent Pinchart err_pm_disable: 9075fc15d98SLaurent Pinchart pm_runtime_disable(&pdev->dev); 9085fc15d98SLaurent Pinchart err_free: 9095fc15d98SLaurent Pinchart kfree(hdmi); 9105fc15d98SLaurent Pinchart return r; 9119960aa7cSTomi Valkeinen } 9129960aa7cSTomi Valkeinen 9139960aa7cSTomi Valkeinen static int hdmi4_remove(struct platform_device *pdev) 9149960aa7cSTomi Valkeinen { 9155fc15d98SLaurent Pinchart struct omap_hdmi *hdmi = platform_get_drvdata(pdev); 9165fc15d98SLaurent Pinchart 9179960aa7cSTomi Valkeinen component_del(&pdev->dev, &hdmi4_component_ops); 9185fc15d98SLaurent Pinchart 9195fc15d98SLaurent Pinchart hdmi4_uninit_output(hdmi); 9205fc15d98SLaurent Pinchart 9215fc15d98SLaurent Pinchart pm_runtime_disable(&pdev->dev); 9225fc15d98SLaurent Pinchart 9235fc15d98SLaurent Pinchart kfree(hdmi); 9249960aa7cSTomi Valkeinen return 0; 9259960aa7cSTomi Valkeinen } 9269960aa7cSTomi Valkeinen 9279960aa7cSTomi Valkeinen static const struct of_device_id hdmi_of_match[] = { 9289960aa7cSTomi Valkeinen { .compatible = "ti,omap4-hdmi", }, 9299960aa7cSTomi Valkeinen {}, 9309960aa7cSTomi Valkeinen }; 9319960aa7cSTomi Valkeinen 932d66c36a3SAndrew F. Davis struct platform_driver omapdss_hdmi4hw_driver = { 9339960aa7cSTomi Valkeinen .probe = hdmi4_probe, 9349960aa7cSTomi Valkeinen .remove = hdmi4_remove, 9359960aa7cSTomi Valkeinen .driver = { 9369960aa7cSTomi Valkeinen .name = "omapdss_hdmi", 9379960aa7cSTomi Valkeinen .of_match_table = hdmi_of_match, 9389960aa7cSTomi Valkeinen .suppress_bind_attrs = true, 9399960aa7cSTomi Valkeinen }, 9409960aa7cSTomi Valkeinen }; 941