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