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