Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1 | /* |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 2 | * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 3 | * Copyright (C) 2013 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 19 | #include <linux/of_irq.h> |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 20 | #include <linux/of_gpio.h> |
| 21 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 22 | #include "hdmi.h" |
| 23 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 24 | void hdmi_set_mode(struct hdmi *hdmi, bool power_on) |
| 25 | { |
| 26 | uint32_t ctrl = 0; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 27 | unsigned long flags; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 28 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 29 | spin_lock_irqsave(&hdmi->reg_lock, flags); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 30 | if (power_on) { |
| 31 | ctrl |= HDMI_CTRL_ENABLE; |
| 32 | if (!hdmi->hdmi_mode) { |
| 33 | ctrl |= HDMI_CTRL_HDMI; |
| 34 | hdmi_write(hdmi, REG_HDMI_CTRL, ctrl); |
| 35 | ctrl &= ~HDMI_CTRL_HDMI; |
| 36 | } else { |
| 37 | ctrl |= HDMI_CTRL_HDMI; |
| 38 | } |
| 39 | } else { |
| 40 | ctrl = HDMI_CTRL_HDMI; |
| 41 | } |
| 42 | |
| 43 | hdmi_write(hdmi, REG_HDMI_CTRL, ctrl); |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 44 | spin_unlock_irqrestore(&hdmi->reg_lock, flags); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 45 | DBG("HDMI Core: %s, HDMI_CTRL=0x%08x", |
| 46 | power_on ? "Enable" : "Disable", ctrl); |
| 47 | } |
| 48 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 49 | static irqreturn_t hdmi_irq(int irq, void *dev_id) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 50 | { |
| 51 | struct hdmi *hdmi = dev_id; |
| 52 | |
| 53 | /* Process HPD: */ |
| 54 | hdmi_connector_irq(hdmi->connector); |
| 55 | |
| 56 | /* Process DDC: */ |
| 57 | hdmi_i2c_irq(hdmi->i2c); |
| 58 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 59 | /* Process HDCP: */ |
| 60 | if (hdmi->hdcp_ctrl) |
| 61 | hdmi_hdcp_irq(hdmi->hdcp_ctrl); |
| 62 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 63 | /* TODO audio.. */ |
| 64 | |
| 65 | return IRQ_HANDLED; |
| 66 | } |
| 67 | |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 68 | static void hdmi_destroy(struct hdmi *hdmi) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 69 | { |
| 70 | struct hdmi_phy *phy = hdmi->phy; |
| 71 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 72 | /* |
| 73 | * at this point, hpd has been disabled, |
| 74 | * after flush workq, it's safe to deinit hdcp |
| 75 | */ |
| 76 | if (hdmi->workq) { |
| 77 | flush_workqueue(hdmi->workq); |
| 78 | destroy_workqueue(hdmi->workq); |
| 79 | } |
| 80 | hdmi_hdcp_destroy(hdmi); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 81 | if (phy) |
| 82 | phy->funcs->destroy(phy); |
| 83 | |
| 84 | if (hdmi->i2c) |
| 85 | hdmi_i2c_destroy(hdmi->i2c); |
| 86 | |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 87 | platform_set_drvdata(hdmi->pdev, NULL); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 90 | /* construct hdmi at bind/probe time, grab all the resources. If |
| 91 | * we are to EPROBE_DEFER we want to do it here, rather than later |
| 92 | * at modeset_init() time |
| 93 | */ |
| 94 | static struct hdmi *hdmi_init(struct platform_device *pdev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 95 | { |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 96 | struct hdmi_platform_config *config = pdev->dev.platform_data; |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 97 | struct hdmi *hdmi = NULL; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 98 | struct resource *res; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 99 | int i, ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 100 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 101 | hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 102 | if (!hdmi) { |
| 103 | ret = -ENOMEM; |
| 104 | goto fail; |
| 105 | } |
| 106 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 107 | hdmi->pdev = pdev; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 108 | hdmi->config = config; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 109 | spin_lock_init(&hdmi->reg_lock); |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 110 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 111 | /* not sure about which phy maps to which msm.. probably I miss some */ |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 112 | if (config->phy_init) { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 113 | hdmi->phy = config->phy_init(hdmi); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 114 | |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 115 | if (IS_ERR(hdmi->phy)) { |
| 116 | ret = PTR_ERR(hdmi->phy); |
| 117 | dev_err(&pdev->dev, "failed to load phy: %d\n", ret); |
| 118 | hdmi->phy = NULL; |
| 119 | goto fail; |
| 120 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 123 | hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI"); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 124 | if (IS_ERR(hdmi->mmio)) { |
| 125 | ret = PTR_ERR(hdmi->mmio); |
| 126 | goto fail; |
| 127 | } |
| 128 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 129 | /* HDCP needs physical address of hdmi register */ |
| 130 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 131 | config->mmio_name); |
| 132 | hdmi->mmio_phy_addr = res->start; |
| 133 | |
| 134 | hdmi->qfprom_mmio = msm_ioremap(pdev, |
| 135 | config->qfprom_mmio_name, "HDMI_QFPROM"); |
| 136 | if (IS_ERR(hdmi->qfprom_mmio)) { |
| 137 | dev_info(&pdev->dev, "can't find qfprom resource\n"); |
| 138 | hdmi->qfprom_mmio = NULL; |
| 139 | } |
| 140 | |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 141 | hdmi->hpd_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_regs[0]) * |
| 142 | config->hpd_reg_cnt, GFP_KERNEL); |
| 143 | if (!hdmi->hpd_regs) { |
| 144 | ret = -ENOMEM; |
| 145 | goto fail; |
| 146 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 147 | for (i = 0; i < config->hpd_reg_cnt; i++) { |
| 148 | struct regulator *reg; |
| 149 | |
Rob Clark | 3e87599 | 2014-08-01 13:08:11 -0400 | [diff] [blame] | 150 | reg = devm_regulator_get(&pdev->dev, |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 151 | config->hpd_reg_names[i]); |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 152 | if (IS_ERR(reg)) { |
| 153 | ret = PTR_ERR(reg); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 154 | dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 155 | config->hpd_reg_names[i], ret); |
| 156 | goto fail; |
| 157 | } |
| 158 | |
| 159 | hdmi->hpd_regs[i] = reg; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 162 | hdmi->pwr_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_regs[0]) * |
| 163 | config->pwr_reg_cnt, GFP_KERNEL); |
| 164 | if (!hdmi->pwr_regs) { |
| 165 | ret = -ENOMEM; |
| 166 | goto fail; |
| 167 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 168 | for (i = 0; i < config->pwr_reg_cnt; i++) { |
| 169 | struct regulator *reg; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 170 | |
Rob Clark | 3e87599 | 2014-08-01 13:08:11 -0400 | [diff] [blame] | 171 | reg = devm_regulator_get(&pdev->dev, |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 172 | config->pwr_reg_names[i]); |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 173 | if (IS_ERR(reg)) { |
| 174 | ret = PTR_ERR(reg); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 175 | dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 176 | config->pwr_reg_names[i], ret); |
| 177 | goto fail; |
| 178 | } |
| 179 | |
| 180 | hdmi->pwr_regs[i] = reg; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 183 | hdmi->hpd_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_clks[0]) * |
| 184 | config->hpd_clk_cnt, GFP_KERNEL); |
| 185 | if (!hdmi->hpd_clks) { |
| 186 | ret = -ENOMEM; |
| 187 | goto fail; |
| 188 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 189 | for (i = 0; i < config->hpd_clk_cnt; i++) { |
| 190 | struct clk *clk; |
| 191 | |
| 192 | clk = devm_clk_get(&pdev->dev, config->hpd_clk_names[i]); |
| 193 | if (IS_ERR(clk)) { |
| 194 | ret = PTR_ERR(clk); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 195 | dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 196 | config->hpd_clk_names[i], ret); |
| 197 | goto fail; |
| 198 | } |
| 199 | |
| 200 | hdmi->hpd_clks[i] = clk; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 203 | hdmi->pwr_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_clks[0]) * |
| 204 | config->pwr_clk_cnt, GFP_KERNEL); |
| 205 | if (!hdmi->pwr_clks) { |
| 206 | ret = -ENOMEM; |
| 207 | goto fail; |
| 208 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 209 | for (i = 0; i < config->pwr_clk_cnt; i++) { |
| 210 | struct clk *clk; |
| 211 | |
| 212 | clk = devm_clk_get(&pdev->dev, config->pwr_clk_names[i]); |
| 213 | if (IS_ERR(clk)) { |
| 214 | ret = PTR_ERR(clk); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 215 | dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 216 | config->pwr_clk_names[i], ret); |
| 217 | goto fail; |
| 218 | } |
| 219 | |
| 220 | hdmi->pwr_clks[i] = clk; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 221 | } |
| 222 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 223 | hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0); |
| 224 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 225 | hdmi->i2c = hdmi_i2c_init(hdmi); |
| 226 | if (IS_ERR(hdmi->i2c)) { |
| 227 | ret = PTR_ERR(hdmi->i2c); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 228 | dev_err(&pdev->dev, "failed to get i2c: %d\n", ret); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 229 | hdmi->i2c = NULL; |
| 230 | goto fail; |
| 231 | } |
| 232 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 233 | hdmi->hdcp_ctrl = hdmi_hdcp_init(hdmi); |
| 234 | if (IS_ERR(hdmi->hdcp_ctrl)) { |
| 235 | dev_warn(&pdev->dev, "failed to init hdcp: disabled\n"); |
| 236 | hdmi->hdcp_ctrl = NULL; |
| 237 | } |
| 238 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 239 | return hdmi; |
| 240 | |
| 241 | fail: |
| 242 | if (hdmi) |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 243 | hdmi_destroy(hdmi); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 244 | |
| 245 | return ERR_PTR(ret); |
| 246 | } |
| 247 | |
| 248 | /* Second part of initialization, the drm/kms level modeset_init, |
| 249 | * constructs/initializes mode objects, etc, is called from master |
| 250 | * driver (not hdmi sub-device's probe/bind!) |
| 251 | * |
| 252 | * Any resource (regulator/clk/etc) which could be missing at boot |
| 253 | * should be handled in hdmi_init() so that failure happens from |
| 254 | * hdmi sub-device's probe. |
| 255 | */ |
| 256 | int hdmi_modeset_init(struct hdmi *hdmi, |
| 257 | struct drm_device *dev, struct drm_encoder *encoder) |
| 258 | { |
| 259 | struct msm_drm_private *priv = dev->dev_private; |
| 260 | struct platform_device *pdev = hdmi->pdev; |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 261 | int ret; |
| 262 | |
| 263 | hdmi->dev = dev; |
| 264 | hdmi->encoder = encoder; |
| 265 | |
| 266 | hdmi_audio_infoframe_init(&hdmi->audio.infoframe); |
| 267 | |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 268 | hdmi->bridge = hdmi_bridge_init(hdmi); |
| 269 | if (IS_ERR(hdmi->bridge)) { |
| 270 | ret = PTR_ERR(hdmi->bridge); |
| 271 | dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret); |
| 272 | hdmi->bridge = NULL; |
| 273 | goto fail; |
| 274 | } |
| 275 | |
| 276 | hdmi->connector = hdmi_connector_init(hdmi); |
| 277 | if (IS_ERR(hdmi->connector)) { |
| 278 | ret = PTR_ERR(hdmi->connector); |
| 279 | dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret); |
| 280 | hdmi->connector = NULL; |
| 281 | goto fail; |
| 282 | } |
| 283 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 284 | hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); |
| 285 | if (hdmi->irq < 0) { |
| 286 | ret = hdmi->irq; |
| 287 | dev_err(dev->dev, "failed to get irq: %d\n", ret); |
| 288 | goto fail; |
| 289 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 290 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 291 | ret = devm_request_irq(&pdev->dev, hdmi->irq, |
| 292 | hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 293 | "hdmi_isr", hdmi); |
| 294 | if (ret < 0) { |
| 295 | dev_err(dev->dev, "failed to request IRQ%u: %d\n", |
| 296 | hdmi->irq, ret); |
| 297 | goto fail; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 300 | encoder->bridge = hdmi->bridge; |
| 301 | |
| 302 | priv->bridges[priv->num_bridges++] = hdmi->bridge; |
| 303 | priv->connectors[priv->num_connectors++] = hdmi->connector; |
| 304 | |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 305 | platform_set_drvdata(pdev, hdmi); |
| 306 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 307 | return 0; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 308 | |
| 309 | fail: |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 310 | /* bridge is normally destroyed by drm: */ |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 311 | if (hdmi->bridge) { |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 312 | hdmi_bridge_destroy(hdmi->bridge); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 313 | hdmi->bridge = NULL; |
| 314 | } |
| 315 | if (hdmi->connector) { |
| 316 | hdmi->connector->funcs->destroy(hdmi->connector); |
| 317 | hdmi->connector = NULL; |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 318 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 319 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 320 | return ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* |
| 324 | * The hdmi device: |
| 325 | */ |
| 326 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 327 | #define HDMI_CFG(item, entry) \ |
| 328 | .item ## _names = item ##_names_ ## entry, \ |
| 329 | .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry) |
| 330 | |
Stephane Viau | 0afbe59 | 2015-09-15 08:41:49 -0400 | [diff] [blame] | 331 | static const char *pwr_reg_names_none[] = {}; |
| 332 | static const char *hpd_reg_names_none[] = {}; |
| 333 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 334 | static struct hdmi_platform_config hdmi_tx_8660_config = { |
| 335 | .phy_init = hdmi_phy_8x60_init, |
| 336 | }; |
| 337 | |
| 338 | static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"}; |
| 339 | static const char *hpd_clk_names_8960[] = {"core_clk", "master_iface_clk", "slave_iface_clk"}; |
| 340 | |
| 341 | static struct hdmi_platform_config hdmi_tx_8960_config = { |
| 342 | .phy_init = hdmi_phy_8960_init, |
| 343 | HDMI_CFG(hpd_reg, 8960), |
| 344 | HDMI_CFG(hpd_clk, 8960), |
| 345 | }; |
| 346 | |
| 347 | static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"}; |
| 348 | static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"}; |
| 349 | static const char *pwr_clk_names_8x74[] = {"extp_clk", "alt_iface_clk"}; |
| 350 | static const char *hpd_clk_names_8x74[] = {"iface_clk", "core_clk", "mdp_core_clk"}; |
| 351 | static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0}; |
| 352 | |
Rob Clark | 5cf3a45 | 2015-07-27 20:52:50 -0400 | [diff] [blame] | 353 | static struct hdmi_platform_config hdmi_tx_8974_config = { |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 354 | .phy_init = hdmi_phy_8x74_init, |
| 355 | HDMI_CFG(pwr_reg, 8x74), |
| 356 | HDMI_CFG(hpd_reg, 8x74), |
| 357 | HDMI_CFG(pwr_clk, 8x74), |
| 358 | HDMI_CFG(hpd_clk, 8x74), |
| 359 | .hpd_freq = hpd_clk_freq_8x74, |
| 360 | }; |
| 361 | |
| 362 | static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"}; |
| 363 | |
| 364 | static struct hdmi_platform_config hdmi_tx_8084_config = { |
| 365 | .phy_init = hdmi_phy_8x74_init, |
| 366 | HDMI_CFG(pwr_reg, 8x74), |
| 367 | HDMI_CFG(hpd_reg, 8084), |
| 368 | HDMI_CFG(pwr_clk, 8x74), |
| 369 | HDMI_CFG(hpd_clk, 8x74), |
| 370 | .hpd_freq = hpd_clk_freq_8x74, |
| 371 | }; |
| 372 | |
Rob Clark | 5cf3a45 | 2015-07-27 20:52:50 -0400 | [diff] [blame] | 373 | static struct hdmi_platform_config hdmi_tx_8994_config = { |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 374 | .phy_init = NULL, /* nothing to do for this HDMI PHY 20nm */ |
| 375 | HDMI_CFG(pwr_reg, 8x74), |
Stephane Viau | 0afbe59 | 2015-09-15 08:41:49 -0400 | [diff] [blame] | 376 | HDMI_CFG(hpd_reg, none), |
| 377 | HDMI_CFG(pwr_clk, 8x74), |
| 378 | HDMI_CFG(hpd_clk, 8x74), |
| 379 | .hpd_freq = hpd_clk_freq_8x74, |
| 380 | }; |
| 381 | |
| 382 | static struct hdmi_platform_config hdmi_tx_8996_config = { |
| 383 | .phy_init = NULL, |
| 384 | HDMI_CFG(pwr_reg, none), |
| 385 | HDMI_CFG(hpd_reg, none), |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 386 | HDMI_CFG(pwr_clk, 8x74), |
| 387 | HDMI_CFG(hpd_clk, 8x74), |
| 388 | .hpd_freq = hpd_clk_freq_8x74, |
| 389 | }; |
| 390 | |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame^] | 391 | static const struct { |
| 392 | const char *name; |
| 393 | const bool output; |
| 394 | const int value; |
| 395 | const char *label; |
| 396 | } hdmi_gpio_pdata[] = { |
| 397 | { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" }, |
| 398 | { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" }, |
| 399 | { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" }, |
| 400 | { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" }, |
| 401 | { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" }, |
| 402 | { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" }, |
| 403 | }; |
| 404 | |
| 405 | static int get_gpio(struct device_node *of_node, const char *name) |
Mark Charlebois | fc88610 | 2014-08-29 11:05:50 -0700 | [diff] [blame] | 406 | { |
| 407 | int gpio = of_get_named_gpio(of_node, name, 0); |
| 408 | if (gpio < 0) { |
| 409 | char name2[32]; |
| 410 | snprintf(name2, sizeof(name2), "%s-gpio", name); |
| 411 | gpio = of_get_named_gpio(of_node, name2, 0); |
| 412 | if (gpio < 0) { |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 413 | DBG("failed to get gpio: %s (%d)", name, gpio); |
Mark Charlebois | fc88610 | 2014-08-29 11:05:50 -0700 | [diff] [blame] | 414 | gpio = -1; |
| 415 | } |
| 416 | } |
| 417 | return gpio; |
| 418 | } |
Mark Charlebois | fc88610 | 2014-08-29 11:05:50 -0700 | [diff] [blame] | 419 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 420 | static int hdmi_bind(struct device *dev, struct device *master, void *data) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 421 | { |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 422 | struct drm_device *drm = dev_get_drvdata(master); |
| 423 | struct msm_drm_private *priv = drm->dev_private; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 424 | static struct hdmi_platform_config *hdmi_cfg; |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 425 | struct hdmi *hdmi; |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 426 | struct device_node *of_node = dev->of_node; |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame^] | 427 | int i; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 428 | |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 429 | hdmi_cfg = (struct hdmi_platform_config *) |
| 430 | of_device_get_match_data(dev); |
| 431 | if (!hdmi_cfg) { |
| 432 | dev_err(dev, "unknown hdmi_cfg: %s\n", of_node->name); |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 433 | return -ENXIO; |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 434 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 435 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 436 | hdmi_cfg->mmio_name = "core_physical"; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 437 | hdmi_cfg->qfprom_mmio_name = "qfprom_physical"; |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame^] | 438 | |
| 439 | for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) { |
| 440 | hdmi_cfg->gpios[i].num = get_gpio(of_node, |
| 441 | hdmi_gpio_pdata[i].name); |
| 442 | hdmi_cfg->gpios[i].output = hdmi_gpio_pdata[i].output; |
| 443 | hdmi_cfg->gpios[i].value = hdmi_gpio_pdata[i].value; |
| 444 | hdmi_cfg->gpios[i].label = hdmi_gpio_pdata[i].label; |
| 445 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 446 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 447 | dev->platform_data = hdmi_cfg; |
| 448 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 449 | hdmi = hdmi_init(to_platform_device(dev)); |
| 450 | if (IS_ERR(hdmi)) |
| 451 | return PTR_ERR(hdmi); |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 452 | priv->hdmi = hdmi; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 453 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 457 | static void hdmi_unbind(struct device *dev, struct device *master, |
| 458 | void *data) |
| 459 | { |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 460 | struct drm_device *drm = dev_get_drvdata(master); |
| 461 | struct msm_drm_private *priv = drm->dev_private; |
| 462 | if (priv->hdmi) { |
| 463 | hdmi_destroy(priv->hdmi); |
| 464 | priv->hdmi = NULL; |
| 465 | } |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static const struct component_ops hdmi_ops = { |
| 469 | .bind = hdmi_bind, |
| 470 | .unbind = hdmi_unbind, |
| 471 | }; |
| 472 | |
| 473 | static int hdmi_dev_probe(struct platform_device *pdev) |
| 474 | { |
| 475 | return component_add(&pdev->dev, &hdmi_ops); |
| 476 | } |
| 477 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 478 | static int hdmi_dev_remove(struct platform_device *pdev) |
| 479 | { |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 480 | component_del(&pdev->dev, &hdmi_ops); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 484 | static const struct of_device_id dt_match[] = { |
| 485 | { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config }, |
| 486 | { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config }, |
| 487 | { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config }, |
| 488 | { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config }, |
| 489 | { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config }, |
| 490 | { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config }, |
| 491 | {} |
| 492 | }; |
| 493 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 494 | static struct platform_driver hdmi_driver = { |
| 495 | .probe = hdmi_dev_probe, |
| 496 | .remove = hdmi_dev_remove, |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 497 | .driver = { |
| 498 | .name = "hdmi_msm", |
| 499 | .of_match_table = dt_match, |
| 500 | }, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | void __init hdmi_register(void) |
| 504 | { |
| 505 | platform_driver_register(&hdmi_driver); |
| 506 | } |
| 507 | |
| 508 | void __exit hdmi_unregister(void) |
| 509 | { |
| 510 | platform_driver_unregister(&hdmi_driver); |
| 511 | } |