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