Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 2 | /* |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 4 | * Copyright (C) 2013 Red Hat |
| 5 | * Author: Rob Clark <robdclark@gmail.com> |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 8 | #include <linux/of_irq.h> |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 9 | #include <linux/of_gpio.h> |
| 10 | |
Dmitry Baryshkov | caa2422 | 2021-10-15 03:11:00 +0300 | [diff] [blame] | 11 | #include <drm/drm_bridge_connector.h> |
| 12 | |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 13 | #include <sound/hdmi-codec.h> |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 14 | #include "hdmi.h" |
| 15 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 16 | void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 17 | { |
| 18 | uint32_t ctrl = 0; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 19 | unsigned long flags; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 20 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 21 | spin_lock_irqsave(&hdmi->reg_lock, flags); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 22 | if (power_on) { |
| 23 | ctrl |= HDMI_CTRL_ENABLE; |
| 24 | if (!hdmi->hdmi_mode) { |
| 25 | ctrl |= HDMI_CTRL_HDMI; |
| 26 | hdmi_write(hdmi, REG_HDMI_CTRL, ctrl); |
| 27 | ctrl &= ~HDMI_CTRL_HDMI; |
| 28 | } else { |
| 29 | ctrl |= HDMI_CTRL_HDMI; |
| 30 | } |
| 31 | } else { |
| 32 | ctrl = HDMI_CTRL_HDMI; |
| 33 | } |
| 34 | |
| 35 | hdmi_write(hdmi, REG_HDMI_CTRL, ctrl); |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 36 | spin_unlock_irqrestore(&hdmi->reg_lock, flags); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 37 | DBG("HDMI Core: %s, HDMI_CTRL=0x%08x", |
| 38 | power_on ? "Enable" : "Disable", ctrl); |
| 39 | } |
| 40 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 41 | static irqreturn_t msm_hdmi_irq(int irq, void *dev_id) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 42 | { |
| 43 | struct hdmi *hdmi = dev_id; |
| 44 | |
| 45 | /* Process HPD: */ |
Dmitry Baryshkov | caa2422 | 2021-10-15 03:11:00 +0300 | [diff] [blame] | 46 | msm_hdmi_hpd_irq(hdmi->bridge); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 47 | |
| 48 | /* Process DDC: */ |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 49 | msm_hdmi_i2c_irq(hdmi->i2c); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 50 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 51 | /* Process HDCP: */ |
| 52 | if (hdmi->hdcp_ctrl) |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 53 | msm_hdmi_hdcp_irq(hdmi->hdcp_ctrl); |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 54 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 55 | /* TODO audio.. */ |
| 56 | |
| 57 | return IRQ_HANDLED; |
| 58 | } |
| 59 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 60 | static void msm_hdmi_destroy(struct hdmi *hdmi) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 61 | { |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 62 | /* |
| 63 | * at this point, hpd has been disabled, |
| 64 | * after flush workq, it's safe to deinit hdcp |
| 65 | */ |
Christophe JAILLET | f8e7bce | 2021-10-10 15:59:40 +0200 | [diff] [blame] | 66 | if (hdmi->workq) |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 67 | destroy_workqueue(hdmi->workq); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 68 | msm_hdmi_hdcp_destroy(hdmi); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 69 | |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 70 | if (hdmi->phy_dev) { |
| 71 | put_device(hdmi->phy_dev); |
| 72 | hdmi->phy = NULL; |
| 73 | hdmi->phy_dev = NULL; |
| 74 | } |
| 75 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 76 | if (hdmi->i2c) |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 77 | msm_hdmi_i2c_destroy(hdmi->i2c); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 78 | |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 79 | platform_set_drvdata(hdmi->pdev, NULL); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 82 | static int msm_hdmi_get_phy(struct hdmi *hdmi) |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 83 | { |
| 84 | struct platform_device *pdev = hdmi->pdev; |
| 85 | struct platform_device *phy_pdev; |
| 86 | struct device_node *phy_node; |
| 87 | |
| 88 | phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0); |
| 89 | if (!phy_node) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 90 | DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n"); |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 91 | return -ENXIO; |
| 92 | } |
| 93 | |
| 94 | phy_pdev = of_find_device_by_node(phy_node); |
| 95 | if (phy_pdev) |
| 96 | hdmi->phy = platform_get_drvdata(phy_pdev); |
| 97 | |
| 98 | of_node_put(phy_node); |
| 99 | |
Miaoqian Lin | 774fe0c | 2022-01-07 08:50:22 +0000 | [diff] [blame] | 100 | if (!phy_pdev) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 101 | DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n"); |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 102 | return -EPROBE_DEFER; |
| 103 | } |
Miaoqian Lin | 774fe0c | 2022-01-07 08:50:22 +0000 | [diff] [blame] | 104 | if (!hdmi->phy) { |
| 105 | DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n"); |
| 106 | put_device(&phy_pdev->dev); |
| 107 | return -EPROBE_DEFER; |
| 108 | } |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 109 | |
| 110 | hdmi->phy_dev = get_device(&phy_pdev->dev); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 115 | /* construct hdmi at bind/probe time, grab all the resources. If |
| 116 | * we are to EPROBE_DEFER we want to do it here, rather than later |
| 117 | * at modeset_init() time |
| 118 | */ |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 119 | static struct hdmi *msm_hdmi_init(struct platform_device *pdev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 120 | { |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 121 | struct hdmi_platform_config *config = pdev->dev.platform_data; |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 122 | struct hdmi *hdmi = NULL; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 123 | struct resource *res; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 124 | int i, ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 125 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 126 | hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 127 | if (!hdmi) { |
| 128 | ret = -ENOMEM; |
| 129 | goto fail; |
| 130 | } |
| 131 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 132 | hdmi->pdev = pdev; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 133 | hdmi->config = config; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 134 | spin_lock_init(&hdmi->reg_lock); |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 135 | |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 136 | hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI"); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 137 | if (IS_ERR(hdmi->mmio)) { |
| 138 | ret = PTR_ERR(hdmi->mmio); |
| 139 | goto fail; |
| 140 | } |
| 141 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 142 | /* HDCP needs physical address of hdmi register */ |
| 143 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
| 144 | config->mmio_name); |
| 145 | hdmi->mmio_phy_addr = res->start; |
| 146 | |
| 147 | hdmi->qfprom_mmio = msm_ioremap(pdev, |
| 148 | config->qfprom_mmio_name, "HDMI_QFPROM"); |
| 149 | if (IS_ERR(hdmi->qfprom_mmio)) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 150 | DRM_DEV_INFO(&pdev->dev, "can't find qfprom resource\n"); |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 151 | hdmi->qfprom_mmio = NULL; |
| 152 | } |
| 153 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 154 | hdmi->hpd_regs = devm_kcalloc(&pdev->dev, |
| 155 | config->hpd_reg_cnt, |
| 156 | sizeof(hdmi->hpd_regs[0]), |
| 157 | GFP_KERNEL); |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 158 | if (!hdmi->hpd_regs) { |
| 159 | ret = -ENOMEM; |
| 160 | goto fail; |
| 161 | } |
Dmitry Baryshkov | 31b3b1f | 2021-10-15 03:10:59 +0300 | [diff] [blame] | 162 | for (i = 0; i < config->hpd_reg_cnt; i++) |
| 163 | hdmi->hpd_regs[i].supply = config->hpd_reg_names[i]; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 164 | |
Dmitry Baryshkov | 31b3b1f | 2021-10-15 03:10:59 +0300 | [diff] [blame] | 165 | ret = devm_regulator_bulk_get(&pdev->dev, config->hpd_reg_cnt, hdmi->hpd_regs); |
| 166 | if (ret) { |
| 167 | DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %d\n", ret); |
| 168 | goto fail; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 169 | } |
| 170 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 171 | hdmi->pwr_regs = devm_kcalloc(&pdev->dev, |
| 172 | config->pwr_reg_cnt, |
| 173 | sizeof(hdmi->pwr_regs[0]), |
| 174 | GFP_KERNEL); |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 175 | if (!hdmi->pwr_regs) { |
| 176 | ret = -ENOMEM; |
| 177 | goto fail; |
| 178 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 179 | |
Dmitry Baryshkov | 31b3b1f | 2021-10-15 03:10:59 +0300 | [diff] [blame] | 180 | ret = devm_regulator_bulk_get(&pdev->dev, config->pwr_reg_cnt, hdmi->pwr_regs); |
| 181 | if (ret) { |
| 182 | DRM_DEV_ERROR(&pdev->dev, "failed to get pwr regulator: %d\n", ret); |
| 183 | goto fail; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 184 | } |
| 185 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 186 | hdmi->hpd_clks = devm_kcalloc(&pdev->dev, |
| 187 | config->hpd_clk_cnt, |
| 188 | sizeof(hdmi->hpd_clks[0]), |
| 189 | GFP_KERNEL); |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 190 | if (!hdmi->hpd_clks) { |
| 191 | ret = -ENOMEM; |
| 192 | goto fail; |
| 193 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 194 | for (i = 0; i < config->hpd_clk_cnt; i++) { |
| 195 | struct clk *clk; |
| 196 | |
Rob Clark | aede1e9 | 2017-10-16 16:56:28 -0400 | [diff] [blame] | 197 | clk = msm_clk_get(pdev, config->hpd_clk_names[i]); |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 198 | if (IS_ERR(clk)) { |
| 199 | ret = PTR_ERR(clk); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 200 | DRM_DEV_ERROR(&pdev->dev, "failed to get hpd clk: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 201 | config->hpd_clk_names[i], ret); |
| 202 | goto fail; |
| 203 | } |
| 204 | |
| 205 | hdmi->hpd_clks[i] = clk; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 208 | hdmi->pwr_clks = devm_kcalloc(&pdev->dev, |
| 209 | config->pwr_clk_cnt, |
| 210 | sizeof(hdmi->pwr_clks[0]), |
| 211 | GFP_KERNEL); |
Stephane Viau | 447fa52 | 2015-01-13 14:33:40 -0500 | [diff] [blame] | 212 | if (!hdmi->pwr_clks) { |
| 213 | ret = -ENOMEM; |
| 214 | goto fail; |
| 215 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 216 | for (i = 0; i < config->pwr_clk_cnt; i++) { |
| 217 | struct clk *clk; |
| 218 | |
Rob Clark | aede1e9 | 2017-10-16 16:56:28 -0400 | [diff] [blame] | 219 | clk = msm_clk_get(pdev, config->pwr_clk_names[i]); |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 220 | if (IS_ERR(clk)) { |
| 221 | ret = PTR_ERR(clk); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 222 | DRM_DEV_ERROR(&pdev->dev, "failed to get pwr clk: %s (%d)\n", |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 223 | config->pwr_clk_names[i], ret); |
| 224 | goto fail; |
| 225 | } |
| 226 | |
| 227 | hdmi->pwr_clks[i] = clk; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Archit Taneja | 6ed9ed4 | 2017-07-28 16:17:02 +0530 | [diff] [blame] | 230 | pm_runtime_enable(&pdev->dev); |
| 231 | |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 232 | hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0); |
| 233 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 234 | hdmi->i2c = msm_hdmi_i2c_init(hdmi); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 235 | if (IS_ERR(hdmi->i2c)) { |
| 236 | ret = PTR_ERR(hdmi->i2c); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 237 | DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 238 | hdmi->i2c = NULL; |
| 239 | goto fail; |
| 240 | } |
| 241 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 242 | ret = msm_hdmi_get_phy(hdmi); |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 243 | if (ret) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 244 | DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n"); |
Archit Taneja | e00012b | 2016-02-25 11:22:40 +0530 | [diff] [blame] | 245 | goto fail; |
| 246 | } |
| 247 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 248 | hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi); |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 249 | if (IS_ERR(hdmi->hdcp_ctrl)) { |
| 250 | dev_warn(&pdev->dev, "failed to init hdcp: disabled\n"); |
| 251 | hdmi->hdcp_ctrl = NULL; |
| 252 | } |
| 253 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 254 | return hdmi; |
| 255 | |
| 256 | fail: |
| 257 | if (hdmi) |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 258 | msm_hdmi_destroy(hdmi); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 259 | |
| 260 | return ERR_PTR(ret); |
| 261 | } |
| 262 | |
| 263 | /* Second part of initialization, the drm/kms level modeset_init, |
| 264 | * constructs/initializes mode objects, etc, is called from master |
| 265 | * driver (not hdmi sub-device's probe/bind!) |
| 266 | * |
| 267 | * Any resource (regulator/clk/etc) which could be missing at boot |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 268 | * should be handled in msm_hdmi_init() so that failure happens from |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 269 | * hdmi sub-device's probe. |
| 270 | */ |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 271 | int msm_hdmi_modeset_init(struct hdmi *hdmi, |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 272 | struct drm_device *dev, struct drm_encoder *encoder) |
| 273 | { |
| 274 | struct msm_drm_private *priv = dev->dev_private; |
| 275 | struct platform_device *pdev = hdmi->pdev; |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 276 | int ret; |
| 277 | |
| 278 | hdmi->dev = dev; |
| 279 | hdmi->encoder = encoder; |
| 280 | |
| 281 | hdmi_audio_infoframe_init(&hdmi->audio.infoframe); |
| 282 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 283 | hdmi->bridge = msm_hdmi_bridge_init(hdmi); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 284 | if (IS_ERR(hdmi->bridge)) { |
| 285 | ret = PTR_ERR(hdmi->bridge); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 286 | DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 287 | hdmi->bridge = NULL; |
| 288 | goto fail; |
| 289 | } |
| 290 | |
Dmitry Baryshkov | caa2422 | 2021-10-15 03:11:00 +0300 | [diff] [blame] | 291 | hdmi->connector = drm_bridge_connector_init(hdmi->dev, encoder); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 292 | if (IS_ERR(hdmi->connector)) { |
| 293 | ret = PTR_ERR(hdmi->connector); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 294 | DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret); |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 295 | hdmi->connector = NULL; |
| 296 | goto fail; |
| 297 | } |
| 298 | |
Dmitry Baryshkov | caa2422 | 2021-10-15 03:11:00 +0300 | [diff] [blame] | 299 | drm_connector_attach_encoder(hdmi->connector, hdmi->encoder); |
| 300 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 301 | hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0); |
| 302 | if (hdmi->irq < 0) { |
| 303 | ret = hdmi->irq; |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 304 | DRM_DEV_ERROR(dev->dev, "failed to get irq: %d\n", ret); |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 305 | goto fail; |
| 306 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 307 | |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 308 | ret = devm_request_irq(&pdev->dev, hdmi->irq, |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 309 | msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 310 | "hdmi_isr", hdmi); |
| 311 | if (ret < 0) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 312 | DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n", |
Rob Clark | f6a8eac | 2014-11-17 15:28:07 -0500 | [diff] [blame] | 313 | hdmi->irq, ret); |
| 314 | goto fail; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Dmitry Baryshkov | caa2422 | 2021-10-15 03:11:00 +0300 | [diff] [blame] | 317 | drm_bridge_connector_enable_hpd(hdmi->connector); |
| 318 | |
| 319 | ret = msm_hdmi_hpd_enable(hdmi->bridge); |
Todor Tomov | ee44563 | 2018-10-19 17:07:22 +0300 | [diff] [blame] | 320 | if (ret < 0) { |
| 321 | DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret); |
| 322 | goto fail; |
| 323 | } |
| 324 | |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 325 | priv->bridges[priv->num_bridges++] = hdmi->bridge; |
| 326 | priv->connectors[priv->num_connectors++] = hdmi->connector; |
| 327 | |
Rob Clark | c0c0d9e | 2013-12-11 14:44:02 -0500 | [diff] [blame] | 328 | platform_set_drvdata(pdev, hdmi); |
| 329 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 330 | return 0; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 331 | |
| 332 | fail: |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 333 | /* bridge is normally destroyed by drm: */ |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 334 | if (hdmi->bridge) { |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 335 | msm_hdmi_bridge_destroy(hdmi->bridge); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 336 | hdmi->bridge = NULL; |
| 337 | } |
| 338 | if (hdmi->connector) { |
| 339 | hdmi->connector->funcs->destroy(hdmi->connector); |
| 340 | hdmi->connector = NULL; |
Rob Clark | a3376e3 | 2013-08-30 13:02:15 -0400 | [diff] [blame] | 341 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 342 | |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 343 | return ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
| 347 | * The hdmi device: |
| 348 | */ |
| 349 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 350 | #define HDMI_CFG(item, entry) \ |
| 351 | .item ## _names = item ##_names_ ## entry, \ |
| 352 | .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry) |
| 353 | |
Stephane Viau | 0afbe59 | 2015-09-15 08:41:49 -0400 | [diff] [blame] | 354 | static const char *pwr_reg_names_none[] = {}; |
| 355 | static const char *hpd_reg_names_none[] = {}; |
| 356 | |
Archit Taneja | ba3d7bf | 2016-02-25 11:22:41 +0530 | [diff] [blame] | 357 | static struct hdmi_platform_config hdmi_tx_8660_config; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 358 | |
| 359 | static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"}; |
Rob Clark | aede1e9 | 2017-10-16 16:56:28 -0400 | [diff] [blame] | 360 | static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"}; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 361 | |
| 362 | static struct hdmi_platform_config hdmi_tx_8960_config = { |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 363 | HDMI_CFG(hpd_reg, 8960), |
| 364 | HDMI_CFG(hpd_clk, 8960), |
| 365 | }; |
| 366 | |
| 367 | static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"}; |
| 368 | static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"}; |
Rob Clark | aede1e9 | 2017-10-16 16:56:28 -0400 | [diff] [blame] | 369 | static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"}; |
| 370 | static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"}; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 371 | static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0}; |
| 372 | |
Rob Clark | 5cf3a4553 | 2015-07-27 20:52:50 -0400 | [diff] [blame] | 373 | static struct hdmi_platform_config hdmi_tx_8974_config = { |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 374 | HDMI_CFG(pwr_reg, 8x74), |
| 375 | HDMI_CFG(hpd_reg, 8x74), |
| 376 | HDMI_CFG(pwr_clk, 8x74), |
| 377 | HDMI_CFG(hpd_clk, 8x74), |
| 378 | .hpd_freq = hpd_clk_freq_8x74, |
| 379 | }; |
| 380 | |
| 381 | static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"}; |
| 382 | |
| 383 | static struct hdmi_platform_config hdmi_tx_8084_config = { |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 384 | HDMI_CFG(pwr_reg, 8x74), |
| 385 | HDMI_CFG(hpd_reg, 8084), |
| 386 | HDMI_CFG(pwr_clk, 8x74), |
| 387 | HDMI_CFG(hpd_clk, 8x74), |
| 388 | .hpd_freq = hpd_clk_freq_8x74, |
| 389 | }; |
| 390 | |
Rob Clark | 5cf3a4553 | 2015-07-27 20:52:50 -0400 | [diff] [blame] | 391 | static struct hdmi_platform_config hdmi_tx_8994_config = { |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 392 | HDMI_CFG(pwr_reg, 8x74), |
Stephane Viau | 0afbe59 | 2015-09-15 08:41:49 -0400 | [diff] [blame] | 393 | HDMI_CFG(hpd_reg, none), |
| 394 | HDMI_CFG(pwr_clk, 8x74), |
| 395 | HDMI_CFG(hpd_clk, 8x74), |
| 396 | .hpd_freq = hpd_clk_freq_8x74, |
| 397 | }; |
| 398 | |
| 399 | static struct hdmi_platform_config hdmi_tx_8996_config = { |
Stephane Viau | 0afbe59 | 2015-09-15 08:41:49 -0400 | [diff] [blame] | 400 | HDMI_CFG(pwr_reg, none), |
| 401 | HDMI_CFG(hpd_reg, none), |
Stephane Viau | 3a84f84 | 2015-06-19 16:04:47 -0400 | [diff] [blame] | 402 | HDMI_CFG(pwr_clk, 8x74), |
| 403 | HDMI_CFG(hpd_clk, 8x74), |
| 404 | .hpd_freq = hpd_clk_freq_8x74, |
| 405 | }; |
| 406 | |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame] | 407 | static const struct { |
| 408 | const char *name; |
| 409 | const bool output; |
| 410 | const int value; |
| 411 | const char *label; |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 412 | } msm_hdmi_gpio_pdata[] = { |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame] | 413 | { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" }, |
| 414 | { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" }, |
| 415 | { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" }, |
| 416 | { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" }, |
| 417 | { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" }, |
| 418 | { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" }, |
| 419 | }; |
| 420 | |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 421 | /* |
| 422 | * HDMI audio codec callbacks |
| 423 | */ |
| 424 | static int msm_hdmi_audio_hw_params(struct device *dev, void *data, |
| 425 | struct hdmi_codec_daifmt *daifmt, |
| 426 | struct hdmi_codec_params *params) |
| 427 | { |
| 428 | struct hdmi *hdmi = dev_get_drvdata(dev); |
| 429 | unsigned int chan; |
| 430 | unsigned int channel_allocation = 0; |
| 431 | unsigned int rate; |
| 432 | unsigned int level_shift = 0; /* 0dB */ |
| 433 | bool down_mix = false; |
| 434 | |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 435 | DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate, |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 436 | params->sample_width, params->cea.channels); |
| 437 | |
| 438 | switch (params->cea.channels) { |
| 439 | case 2: |
| 440 | /* FR and FL speakers */ |
| 441 | channel_allocation = 0; |
| 442 | chan = MSM_HDMI_AUDIO_CHANNEL_2; |
| 443 | break; |
| 444 | case 4: |
| 445 | /* FC, LFE, FR and FL speakers */ |
| 446 | channel_allocation = 0x3; |
| 447 | chan = MSM_HDMI_AUDIO_CHANNEL_4; |
| 448 | break; |
| 449 | case 6: |
| 450 | /* RR, RL, FC, LFE, FR and FL speakers */ |
| 451 | channel_allocation = 0x0B; |
| 452 | chan = MSM_HDMI_AUDIO_CHANNEL_6; |
| 453 | break; |
| 454 | case 8: |
| 455 | /* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */ |
| 456 | channel_allocation = 0x1F; |
| 457 | chan = MSM_HDMI_AUDIO_CHANNEL_8; |
| 458 | break; |
| 459 | default: |
| 460 | return -EINVAL; |
| 461 | } |
| 462 | |
| 463 | switch (params->sample_rate) { |
| 464 | case 32000: |
| 465 | rate = HDMI_SAMPLE_RATE_32KHZ; |
| 466 | break; |
| 467 | case 44100: |
| 468 | rate = HDMI_SAMPLE_RATE_44_1KHZ; |
| 469 | break; |
| 470 | case 48000: |
| 471 | rate = HDMI_SAMPLE_RATE_48KHZ; |
| 472 | break; |
| 473 | case 88200: |
| 474 | rate = HDMI_SAMPLE_RATE_88_2KHZ; |
| 475 | break; |
| 476 | case 96000: |
| 477 | rate = HDMI_SAMPLE_RATE_96KHZ; |
| 478 | break; |
| 479 | case 176400: |
| 480 | rate = HDMI_SAMPLE_RATE_176_4KHZ; |
| 481 | break; |
| 482 | case 192000: |
| 483 | rate = HDMI_SAMPLE_RATE_192KHZ; |
| 484 | break; |
| 485 | default: |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 486 | DRM_DEV_ERROR(dev, "rate[%d] not supported!\n", |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 487 | params->sample_rate); |
| 488 | return -EINVAL; |
| 489 | } |
| 490 | |
| 491 | msm_hdmi_audio_set_sample_rate(hdmi, rate); |
| 492 | msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation, |
| 493 | level_shift, down_mix); |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static void msm_hdmi_audio_shutdown(struct device *dev, void *data) |
| 499 | { |
| 500 | struct hdmi *hdmi = dev_get_drvdata(dev); |
| 501 | |
| 502 | msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0); |
| 503 | } |
| 504 | |
| 505 | static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = { |
| 506 | .hw_params = msm_hdmi_audio_hw_params, |
| 507 | .audio_shutdown = msm_hdmi_audio_shutdown, |
| 508 | }; |
| 509 | |
| 510 | static struct hdmi_codec_pdata codec_data = { |
| 511 | .ops = &msm_hdmi_audio_codec_ops, |
| 512 | .max_i2s_channels = 8, |
| 513 | .i2s = 1, |
| 514 | }; |
| 515 | |
| 516 | static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev) |
| 517 | { |
| 518 | hdmi->audio_pdev = platform_device_register_data(dev, |
| 519 | HDMI_CODEC_DRV_NAME, |
| 520 | PLATFORM_DEVID_AUTO, |
| 521 | &codec_data, |
| 522 | sizeof(codec_data)); |
Wei Yongjun | 06f3217 | 2016-07-12 11:06:52 +0000 | [diff] [blame] | 523 | return PTR_ERR_OR_ZERO(hdmi->audio_pdev); |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 526 | static int msm_hdmi_bind(struct device *dev, struct device *master, void *data) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 527 | { |
AngeloGioacchino Del Regno | ec919e6 | 2021-12-01 11:52:09 +0100 | [diff] [blame] | 528 | struct msm_drm_private *priv = dev_get_drvdata(master); |
YueHaibing | 6714651 | 2018-11-14 09:55:34 +0000 | [diff] [blame] | 529 | struct hdmi_platform_config *hdmi_cfg; |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 530 | struct hdmi *hdmi; |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 531 | struct device_node *of_node = dev->of_node; |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 532 | int i, err; |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 533 | |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 534 | hdmi_cfg = (struct hdmi_platform_config *) |
| 535 | of_device_get_match_data(dev); |
| 536 | if (!hdmi_cfg) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 537 | DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node); |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 538 | return -ENXIO; |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 539 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 540 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 541 | hdmi_cfg->mmio_name = "core_physical"; |
jilai wang | c6a57a5 | 2015-04-02 17:49:01 -0400 | [diff] [blame] | 542 | hdmi_cfg->qfprom_mmio_name = "qfprom_physical"; |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame] | 543 | |
| 544 | for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) { |
Linus Walleij | a44769b | 2019-06-29 14:59:31 +0200 | [diff] [blame] | 545 | const char *name = msm_hdmi_gpio_pdata[i].name; |
| 546 | struct gpio_desc *gpiod; |
| 547 | |
| 548 | /* |
| 549 | * We are fetching the GPIO lines "as is" since the connector |
| 550 | * code is enabling and disabling the lines. Until that point |
| 551 | * the power-on default value will be kept. |
| 552 | */ |
| 553 | gpiod = devm_gpiod_get_optional(dev, name, GPIOD_ASIS); |
| 554 | /* This will catch e.g. -PROBE_DEFER */ |
| 555 | if (IS_ERR(gpiod)) |
| 556 | return PTR_ERR(gpiod); |
| 557 | if (!gpiod) { |
| 558 | /* Try a second time, stripping down the name */ |
| 559 | char name3[32]; |
| 560 | |
| 561 | /* |
| 562 | * Try again after stripping out the "qcom,hdmi-tx" |
| 563 | * prefix. This is mainly to match "hpd-gpios" used |
| 564 | * in the upstream bindings. |
| 565 | */ |
| 566 | if (sscanf(name, "qcom,hdmi-tx-%s", name3)) |
| 567 | gpiod = devm_gpiod_get_optional(dev, name3, GPIOD_ASIS); |
| 568 | if (IS_ERR(gpiod)) |
| 569 | return PTR_ERR(gpiod); |
| 570 | if (!gpiod) |
| 571 | DBG("failed to get gpio: %s", name); |
| 572 | } |
| 573 | hdmi_cfg->gpios[i].gpiod = gpiod; |
| 574 | if (gpiod) |
| 575 | gpiod_set_consumer_name(gpiod, msm_hdmi_gpio_pdata[i].label); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 576 | hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output; |
| 577 | hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value; |
Archit Taneja | dc50f782 | 2016-02-25 11:22:36 +0530 | [diff] [blame] | 578 | } |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 579 | |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 580 | dev->platform_data = hdmi_cfg; |
| 581 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 582 | hdmi = msm_hdmi_init(to_platform_device(dev)); |
Rob Clark | 067fef3 | 2014-11-04 13:33:14 -0500 | [diff] [blame] | 583 | if (IS_ERR(hdmi)) |
| 584 | return PTR_ERR(hdmi); |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 585 | priv->hdmi = hdmi; |
Stephane Viau | 5eba5d8 | 2015-01-07 16:27:27 -0500 | [diff] [blame] | 586 | |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 587 | err = msm_hdmi_register_audio_driver(hdmi, dev); |
| 588 | if (err) { |
| 589 | DRM_ERROR("Failed to attach an audio codec %d\n", err); |
| 590 | hdmi->audio_pdev = NULL; |
| 591 | } |
| 592 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 596 | static void msm_hdmi_unbind(struct device *dev, struct device *master, |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 597 | void *data) |
| 598 | { |
AngeloGioacchino Del Regno | ec919e6 | 2021-12-01 11:52:09 +0100 | [diff] [blame] | 599 | struct msm_drm_private *priv = dev_get_drvdata(master); |
| 600 | |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 601 | if (priv->hdmi) { |
Srinivas Kandagatla | f142701 | 2016-06-10 10:45:56 +0100 | [diff] [blame] | 602 | if (priv->hdmi->audio_pdev) |
| 603 | platform_device_unregister(priv->hdmi->audio_pdev); |
| 604 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 605 | msm_hdmi_destroy(priv->hdmi); |
Rob Clark | d1a717b | 2014-11-18 08:40:44 -0500 | [diff] [blame] | 606 | priv->hdmi = NULL; |
| 607 | } |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 608 | } |
| 609 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 610 | static const struct component_ops msm_hdmi_ops = { |
| 611 | .bind = msm_hdmi_bind, |
| 612 | .unbind = msm_hdmi_unbind, |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 613 | }; |
| 614 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 615 | static int msm_hdmi_dev_probe(struct platform_device *pdev) |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 616 | { |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 617 | return component_add(&pdev->dev, &msm_hdmi_ops); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 618 | } |
| 619 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 620 | static int msm_hdmi_dev_remove(struct platform_device *pdev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 621 | { |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 622 | component_del(&pdev->dev, &msm_hdmi_ops); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 626 | static const struct of_device_id msm_hdmi_dt_match[] = { |
Archit Taneja | 1fd6a44 | 2015-10-30 12:35:55 +0530 | [diff] [blame] | 627 | { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config }, |
| 628 | { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config }, |
| 629 | { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config }, |
| 630 | { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config }, |
| 631 | { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config }, |
| 632 | { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config }, |
| 633 | {} |
| 634 | }; |
| 635 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 636 | static struct platform_driver msm_hdmi_driver = { |
| 637 | .probe = msm_hdmi_dev_probe, |
| 638 | .remove = msm_hdmi_dev_remove, |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 639 | .driver = { |
| 640 | .name = "hdmi_msm", |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 641 | .of_match_table = msm_hdmi_dt_match, |
Rob Clark | dada25b | 2013-12-01 12:12:54 -0500 | [diff] [blame] | 642 | }, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 643 | }; |
| 644 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 645 | void __init msm_hdmi_register(void) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 646 | { |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 647 | msm_hdmi_phy_driver_register(); |
| 648 | platform_driver_register(&msm_hdmi_driver); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 651 | void __exit msm_hdmi_unregister(void) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 652 | { |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 653 | platform_driver_unregister(&msm_hdmi_driver); |
| 654 | msm_hdmi_phy_driver_unregister(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 655 | } |