blob: 3acdeae25caf09e0c093132b4572a012c57f81e0 [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001// SPDX-License-Identifier: GPL-2.0-only
Rob Clarkc8afe682013-06-26 12:44:06 -04002/*
Stephane Viau5eba5d82015-01-07 16:27:27 -05003 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
Rob Clarkc8afe682013-06-26 12:44:06 -04004 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
Rob Clarkc8afe682013-06-26 12:44:06 -04006 */
7
Rob Clarkf6a8eac2014-11-17 15:28:07 -05008#include <linux/of_irq.h>
Archit Taneja1fd6a442015-10-30 12:35:55 +05309#include <linux/of_gpio.h>
10
Dmitry Baryshkovcaa24222021-10-15 03:11:00 +030011#include <drm/drm_bridge_connector.h>
12
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +010013#include <sound/hdmi-codec.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040014#include "hdmi.h"
15
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010016void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on)
Rob Clarkc8afe682013-06-26 12:44:06 -040017{
18 uint32_t ctrl = 0;
jilai wangc6a57a52015-04-02 17:49:01 -040019 unsigned long flags;
Rob Clarkc8afe682013-06-26 12:44:06 -040020
jilai wangc6a57a52015-04-02 17:49:01 -040021 spin_lock_irqsave(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040022 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 wangc6a57a52015-04-02 17:49:01 -040036 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
Rob Clarkc8afe682013-06-26 12:44:06 -040037 DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
38 power_on ? "Enable" : "Disable", ctrl);
39}
40
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010041static irqreturn_t msm_hdmi_irq(int irq, void *dev_id)
Rob Clarkc8afe682013-06-26 12:44:06 -040042{
43 struct hdmi *hdmi = dev_id;
44
45 /* Process HPD: */
Dmitry Baryshkovcaa24222021-10-15 03:11:00 +030046 msm_hdmi_hpd_irq(hdmi->bridge);
Rob Clarkc8afe682013-06-26 12:44:06 -040047
48 /* Process DDC: */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010049 msm_hdmi_i2c_irq(hdmi->i2c);
Rob Clarkc8afe682013-06-26 12:44:06 -040050
jilai wangc6a57a52015-04-02 17:49:01 -040051 /* Process HDCP: */
52 if (hdmi->hdcp_ctrl)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010053 msm_hdmi_hdcp_irq(hdmi->hdcp_ctrl);
jilai wangc6a57a52015-04-02 17:49:01 -040054
Rob Clarkc8afe682013-06-26 12:44:06 -040055 /* TODO audio.. */
56
57 return IRQ_HANDLED;
58}
59
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010060static void msm_hdmi_destroy(struct hdmi *hdmi)
Rob Clarkc8afe682013-06-26 12:44:06 -040061{
jilai wangc6a57a52015-04-02 17:49:01 -040062 /*
63 * at this point, hpd has been disabled,
64 * after flush workq, it's safe to deinit hdcp
65 */
Christophe JAILLETf8e7bce2021-10-10 15:59:40 +020066 if (hdmi->workq)
jilai wangc6a57a52015-04-02 17:49:01 -040067 destroy_workqueue(hdmi->workq);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010068 msm_hdmi_hdcp_destroy(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -040069
Archit Tanejae00012b2016-02-25 11:22:40 +053070 if (hdmi->phy_dev) {
71 put_device(hdmi->phy_dev);
72 hdmi->phy = NULL;
73 hdmi->phy_dev = NULL;
74 }
75
Rob Clarkc8afe682013-06-26 12:44:06 -040076 if (hdmi->i2c)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010077 msm_hdmi_i2c_destroy(hdmi->i2c);
Rob Clarkc8afe682013-06-26 12:44:06 -040078
Rob Clarkc0c0d9e2013-12-11 14:44:02 -050079 platform_set_drvdata(hdmi->pdev, NULL);
Rob Clarkc8afe682013-06-26 12:44:06 -040080}
81
Arnd Bergmannfcda50c2016-02-22 22:08:35 +010082static int msm_hdmi_get_phy(struct hdmi *hdmi)
Archit Tanejae00012b2016-02-25 11:22:40 +053083{
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 Shukla6a41da12018-10-20 23:19:26 +053090 DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n");
Archit Tanejae00012b2016-02-25 11:22:40 +053091 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
100 if (!phy_pdev || !hdmi->phy) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530101 DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
Archit Tanejae00012b2016-02-25 11:22:40 +0530102 return -EPROBE_DEFER;
103 }
104
105 hdmi->phy_dev = get_device(&phy_pdev->dev);
106
107 return 0;
108}
109
Rob Clark067fef32014-11-04 13:33:14 -0500110/* construct hdmi at bind/probe time, grab all the resources. If
111 * we are to EPROBE_DEFER we want to do it here, rather than later
112 * at modeset_init() time
113 */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100114static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400115{
Rob Clark067fef32014-11-04 13:33:14 -0500116 struct hdmi_platform_config *config = pdev->dev.platform_data;
Rob Clarka3376e32013-08-30 13:02:15 -0400117 struct hdmi *hdmi = NULL;
jilai wangc6a57a52015-04-02 17:49:01 -0400118 struct resource *res;
Rob Clarkdada25b2013-12-01 12:12:54 -0500119 int i, ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400120
Rob Clark067fef32014-11-04 13:33:14 -0500121 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
Rob Clarka3376e32013-08-30 13:02:15 -0400122 if (!hdmi) {
123 ret = -ENOMEM;
124 goto fail;
125 }
126
Rob Clarkc8afe682013-06-26 12:44:06 -0400127 hdmi->pdev = pdev;
Rob Clarkdada25b2013-12-01 12:12:54 -0500128 hdmi->config = config;
jilai wangc6a57a52015-04-02 17:49:01 -0400129 spin_lock_init(&hdmi->reg_lock);
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500130
Rob Clarkdada25b2013-12-01 12:12:54 -0500131 hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
Rob Clarkc8afe682013-06-26 12:44:06 -0400132 if (IS_ERR(hdmi->mmio)) {
133 ret = PTR_ERR(hdmi->mmio);
134 goto fail;
135 }
136
jilai wangc6a57a52015-04-02 17:49:01 -0400137 /* HDCP needs physical address of hdmi register */
138 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
139 config->mmio_name);
140 hdmi->mmio_phy_addr = res->start;
141
142 hdmi->qfprom_mmio = msm_ioremap(pdev,
143 config->qfprom_mmio_name, "HDMI_QFPROM");
144 if (IS_ERR(hdmi->qfprom_mmio)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530145 DRM_DEV_INFO(&pdev->dev, "can't find qfprom resource\n");
jilai wangc6a57a52015-04-02 17:49:01 -0400146 hdmi->qfprom_mmio = NULL;
147 }
148
Kees Cooka86854d2018-06-12 14:07:58 -0700149 hdmi->hpd_regs = devm_kcalloc(&pdev->dev,
150 config->hpd_reg_cnt,
151 sizeof(hdmi->hpd_regs[0]),
152 GFP_KERNEL);
Stephane Viau447fa522015-01-13 14:33:40 -0500153 if (!hdmi->hpd_regs) {
154 ret = -ENOMEM;
155 goto fail;
156 }
Dmitry Baryshkov31b3b1f2021-10-15 03:10:59 +0300157 for (i = 0; i < config->hpd_reg_cnt; i++)
158 hdmi->hpd_regs[i].supply = config->hpd_reg_names[i];
Rob Clarkdada25b2013-12-01 12:12:54 -0500159
Dmitry Baryshkov31b3b1f2021-10-15 03:10:59 +0300160 ret = devm_regulator_bulk_get(&pdev->dev, config->hpd_reg_cnt, hdmi->hpd_regs);
161 if (ret) {
162 DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %d\n", ret);
163 goto fail;
Rob Clarkc8afe682013-06-26 12:44:06 -0400164 }
165
Kees Cooka86854d2018-06-12 14:07:58 -0700166 hdmi->pwr_regs = devm_kcalloc(&pdev->dev,
167 config->pwr_reg_cnt,
168 sizeof(hdmi->pwr_regs[0]),
169 GFP_KERNEL);
Stephane Viau447fa522015-01-13 14:33:40 -0500170 if (!hdmi->pwr_regs) {
171 ret = -ENOMEM;
172 goto fail;
173 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400174
Dmitry Baryshkov31b3b1f2021-10-15 03:10:59 +0300175 ret = devm_regulator_bulk_get(&pdev->dev, config->pwr_reg_cnt, hdmi->pwr_regs);
176 if (ret) {
177 DRM_DEV_ERROR(&pdev->dev, "failed to get pwr regulator: %d\n", ret);
178 goto fail;
Rob Clarkc8afe682013-06-26 12:44:06 -0400179 }
180
Kees Cooka86854d2018-06-12 14:07:58 -0700181 hdmi->hpd_clks = devm_kcalloc(&pdev->dev,
182 config->hpd_clk_cnt,
183 sizeof(hdmi->hpd_clks[0]),
184 GFP_KERNEL);
Stephane Viau447fa522015-01-13 14:33:40 -0500185 if (!hdmi->hpd_clks) {
186 ret = -ENOMEM;
187 goto fail;
188 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500189 for (i = 0; i < config->hpd_clk_cnt; i++) {
190 struct clk *clk;
191
Rob Clarkaede1e92017-10-16 16:56:28 -0400192 clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500193 if (IS_ERR(clk)) {
194 ret = PTR_ERR(clk);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530195 DRM_DEV_ERROR(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500196 config->hpd_clk_names[i], ret);
197 goto fail;
198 }
199
200 hdmi->hpd_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400201 }
202
Kees Cooka86854d2018-06-12 14:07:58 -0700203 hdmi->pwr_clks = devm_kcalloc(&pdev->dev,
204 config->pwr_clk_cnt,
205 sizeof(hdmi->pwr_clks[0]),
206 GFP_KERNEL);
Stephane Viau447fa522015-01-13 14:33:40 -0500207 if (!hdmi->pwr_clks) {
208 ret = -ENOMEM;
209 goto fail;
210 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500211 for (i = 0; i < config->pwr_clk_cnt; i++) {
212 struct clk *clk;
213
Rob Clarkaede1e92017-10-16 16:56:28 -0400214 clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
Rob Clarkdada25b2013-12-01 12:12:54 -0500215 if (IS_ERR(clk)) {
216 ret = PTR_ERR(clk);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530217 DRM_DEV_ERROR(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
Rob Clarkdada25b2013-12-01 12:12:54 -0500218 config->pwr_clk_names[i], ret);
219 goto fail;
220 }
221
222 hdmi->pwr_clks[i] = clk;
Rob Clarkc8afe682013-06-26 12:44:06 -0400223 }
224
Archit Taneja6ed9ed42017-07-28 16:17:02 +0530225 pm_runtime_enable(&pdev->dev);
226
jilai wangc6a57a52015-04-02 17:49:01 -0400227 hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
228
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100229 hdmi->i2c = msm_hdmi_i2c_init(hdmi);
Rob Clarkc8afe682013-06-26 12:44:06 -0400230 if (IS_ERR(hdmi->i2c)) {
231 ret = PTR_ERR(hdmi->i2c);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530232 DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret);
Rob Clarkc8afe682013-06-26 12:44:06 -0400233 hdmi->i2c = NULL;
234 goto fail;
235 }
236
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100237 ret = msm_hdmi_get_phy(hdmi);
Archit Tanejae00012b2016-02-25 11:22:40 +0530238 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530239 DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n");
Archit Tanejae00012b2016-02-25 11:22:40 +0530240 goto fail;
241 }
242
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100243 hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
jilai wangc6a57a52015-04-02 17:49:01 -0400244 if (IS_ERR(hdmi->hdcp_ctrl)) {
245 dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
246 hdmi->hdcp_ctrl = NULL;
247 }
248
Rob Clark067fef32014-11-04 13:33:14 -0500249 return hdmi;
250
251fail:
252 if (hdmi)
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100253 msm_hdmi_destroy(hdmi);
Rob Clark067fef32014-11-04 13:33:14 -0500254
255 return ERR_PTR(ret);
256}
257
258/* Second part of initialization, the drm/kms level modeset_init,
259 * constructs/initializes mode objects, etc, is called from master
260 * driver (not hdmi sub-device's probe/bind!)
261 *
262 * Any resource (regulator/clk/etc) which could be missing at boot
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100263 * should be handled in msm_hdmi_init() so that failure happens from
Rob Clark067fef32014-11-04 13:33:14 -0500264 * hdmi sub-device's probe.
265 */
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100266int msm_hdmi_modeset_init(struct hdmi *hdmi,
Rob Clark067fef32014-11-04 13:33:14 -0500267 struct drm_device *dev, struct drm_encoder *encoder)
268{
269 struct msm_drm_private *priv = dev->dev_private;
270 struct platform_device *pdev = hdmi->pdev;
Rob Clark067fef32014-11-04 13:33:14 -0500271 int ret;
272
273 hdmi->dev = dev;
274 hdmi->encoder = encoder;
275
276 hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
277
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100278 hdmi->bridge = msm_hdmi_bridge_init(hdmi);
Rob Clarka3376e32013-08-30 13:02:15 -0400279 if (IS_ERR(hdmi->bridge)) {
280 ret = PTR_ERR(hdmi->bridge);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530281 DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret);
Rob Clarka3376e32013-08-30 13:02:15 -0400282 hdmi->bridge = NULL;
283 goto fail;
284 }
285
Dmitry Baryshkovcaa24222021-10-15 03:11:00 +0300286 hdmi->connector = drm_bridge_connector_init(hdmi->dev, encoder);
Rob Clarka3376e32013-08-30 13:02:15 -0400287 if (IS_ERR(hdmi->connector)) {
288 ret = PTR_ERR(hdmi->connector);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530289 DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret);
Rob Clarka3376e32013-08-30 13:02:15 -0400290 hdmi->connector = NULL;
291 goto fail;
292 }
293
Dmitry Baryshkovcaa24222021-10-15 03:11:00 +0300294 drm_connector_attach_encoder(hdmi->connector, hdmi->encoder);
295
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500296 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
297 if (hdmi->irq < 0) {
298 ret = hdmi->irq;
Mamta Shukla6a41da12018-10-20 23:19:26 +0530299 DRM_DEV_ERROR(dev->dev, "failed to get irq: %d\n", ret);
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500300 goto fail;
301 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400302
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500303 ret = devm_request_irq(&pdev->dev, hdmi->irq,
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100304 msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500305 "hdmi_isr", hdmi);
306 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530307 DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
Rob Clarkf6a8eac2014-11-17 15:28:07 -0500308 hdmi->irq, ret);
309 goto fail;
Rob Clarkc8afe682013-06-26 12:44:06 -0400310 }
311
Dmitry Baryshkovcaa24222021-10-15 03:11:00 +0300312 drm_bridge_connector_enable_hpd(hdmi->connector);
313
314 ret = msm_hdmi_hpd_enable(hdmi->bridge);
Todor Tomovee445632018-10-19 17:07:22 +0300315 if (ret < 0) {
316 DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
317 goto fail;
318 }
319
Rob Clarka3376e32013-08-30 13:02:15 -0400320 priv->bridges[priv->num_bridges++] = hdmi->bridge;
321 priv->connectors[priv->num_connectors++] = hdmi->connector;
322
Rob Clarkc0c0d9e2013-12-11 14:44:02 -0500323 platform_set_drvdata(pdev, hdmi);
324
Rob Clark067fef32014-11-04 13:33:14 -0500325 return 0;
Rob Clarkc8afe682013-06-26 12:44:06 -0400326
327fail:
Ajay Kumar3d3f8b12015-01-20 22:08:44 +0530328 /* bridge is normally destroyed by drm: */
Rob Clark067fef32014-11-04 13:33:14 -0500329 if (hdmi->bridge) {
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100330 msm_hdmi_bridge_destroy(hdmi->bridge);
Rob Clark067fef32014-11-04 13:33:14 -0500331 hdmi->bridge = NULL;
332 }
333 if (hdmi->connector) {
334 hdmi->connector->funcs->destroy(hdmi->connector);
335 hdmi->connector = NULL;
Rob Clarka3376e32013-08-30 13:02:15 -0400336 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400337
Rob Clark067fef32014-11-04 13:33:14 -0500338 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400339}
340
341/*
342 * The hdmi device:
343 */
344
Stephane Viau5eba5d82015-01-07 16:27:27 -0500345#define HDMI_CFG(item, entry) \
346 .item ## _names = item ##_names_ ## entry, \
347 .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
348
Stephane Viau0afbe592015-09-15 08:41:49 -0400349static const char *pwr_reg_names_none[] = {};
350static const char *hpd_reg_names_none[] = {};
351
Archit Tanejaba3d7bf2016-02-25 11:22:41 +0530352static struct hdmi_platform_config hdmi_tx_8660_config;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500353
354static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
Rob Clarkaede1e92017-10-16 16:56:28 -0400355static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
Stephane Viau5eba5d82015-01-07 16:27:27 -0500356
357static struct hdmi_platform_config hdmi_tx_8960_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500358 HDMI_CFG(hpd_reg, 8960),
359 HDMI_CFG(hpd_clk, 8960),
360};
361
362static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
363static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
Rob Clarkaede1e92017-10-16 16:56:28 -0400364static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
365static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
Stephane Viau5eba5d82015-01-07 16:27:27 -0500366static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
367
Rob Clark5cf3a45532015-07-27 20:52:50 -0400368static struct hdmi_platform_config hdmi_tx_8974_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500369 HDMI_CFG(pwr_reg, 8x74),
370 HDMI_CFG(hpd_reg, 8x74),
371 HDMI_CFG(pwr_clk, 8x74),
372 HDMI_CFG(hpd_clk, 8x74),
373 .hpd_freq = hpd_clk_freq_8x74,
374};
375
376static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
377
378static struct hdmi_platform_config hdmi_tx_8084_config = {
Stephane Viau5eba5d82015-01-07 16:27:27 -0500379 HDMI_CFG(pwr_reg, 8x74),
380 HDMI_CFG(hpd_reg, 8084),
381 HDMI_CFG(pwr_clk, 8x74),
382 HDMI_CFG(hpd_clk, 8x74),
383 .hpd_freq = hpd_clk_freq_8x74,
384};
385
Rob Clark5cf3a45532015-07-27 20:52:50 -0400386static struct hdmi_platform_config hdmi_tx_8994_config = {
Stephane Viau3a84f842015-06-19 16:04:47 -0400387 HDMI_CFG(pwr_reg, 8x74),
Stephane Viau0afbe592015-09-15 08:41:49 -0400388 HDMI_CFG(hpd_reg, none),
389 HDMI_CFG(pwr_clk, 8x74),
390 HDMI_CFG(hpd_clk, 8x74),
391 .hpd_freq = hpd_clk_freq_8x74,
392};
393
394static struct hdmi_platform_config hdmi_tx_8996_config = {
Stephane Viau0afbe592015-09-15 08:41:49 -0400395 HDMI_CFG(pwr_reg, none),
396 HDMI_CFG(hpd_reg, none),
Stephane Viau3a84f842015-06-19 16:04:47 -0400397 HDMI_CFG(pwr_clk, 8x74),
398 HDMI_CFG(hpd_clk, 8x74),
399 .hpd_freq = hpd_clk_freq_8x74,
400};
401
Archit Tanejadc50f7822016-02-25 11:22:36 +0530402static const struct {
403 const char *name;
404 const bool output;
405 const int value;
406 const char *label;
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100407} msm_hdmi_gpio_pdata[] = {
Archit Tanejadc50f7822016-02-25 11:22:36 +0530408 { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
409 { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
410 { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
411 { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
412 { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
413 { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
414};
415
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100416/*
417 * HDMI audio codec callbacks
418 */
419static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
420 struct hdmi_codec_daifmt *daifmt,
421 struct hdmi_codec_params *params)
422{
423 struct hdmi *hdmi = dev_get_drvdata(dev);
424 unsigned int chan;
425 unsigned int channel_allocation = 0;
426 unsigned int rate;
427 unsigned int level_shift = 0; /* 0dB */
428 bool down_mix = false;
429
Mamta Shukla6a41da12018-10-20 23:19:26 +0530430 DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100431 params->sample_width, params->cea.channels);
432
433 switch (params->cea.channels) {
434 case 2:
435 /* FR and FL speakers */
436 channel_allocation = 0;
437 chan = MSM_HDMI_AUDIO_CHANNEL_2;
438 break;
439 case 4:
440 /* FC, LFE, FR and FL speakers */
441 channel_allocation = 0x3;
442 chan = MSM_HDMI_AUDIO_CHANNEL_4;
443 break;
444 case 6:
445 /* RR, RL, FC, LFE, FR and FL speakers */
446 channel_allocation = 0x0B;
447 chan = MSM_HDMI_AUDIO_CHANNEL_6;
448 break;
449 case 8:
450 /* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
451 channel_allocation = 0x1F;
452 chan = MSM_HDMI_AUDIO_CHANNEL_8;
453 break;
454 default:
455 return -EINVAL;
456 }
457
458 switch (params->sample_rate) {
459 case 32000:
460 rate = HDMI_SAMPLE_RATE_32KHZ;
461 break;
462 case 44100:
463 rate = HDMI_SAMPLE_RATE_44_1KHZ;
464 break;
465 case 48000:
466 rate = HDMI_SAMPLE_RATE_48KHZ;
467 break;
468 case 88200:
469 rate = HDMI_SAMPLE_RATE_88_2KHZ;
470 break;
471 case 96000:
472 rate = HDMI_SAMPLE_RATE_96KHZ;
473 break;
474 case 176400:
475 rate = HDMI_SAMPLE_RATE_176_4KHZ;
476 break;
477 case 192000:
478 rate = HDMI_SAMPLE_RATE_192KHZ;
479 break;
480 default:
Mamta Shukla6a41da12018-10-20 23:19:26 +0530481 DRM_DEV_ERROR(dev, "rate[%d] not supported!\n",
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100482 params->sample_rate);
483 return -EINVAL;
484 }
485
486 msm_hdmi_audio_set_sample_rate(hdmi, rate);
487 msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
488 level_shift, down_mix);
489
490 return 0;
491}
492
493static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
494{
495 struct hdmi *hdmi = dev_get_drvdata(dev);
496
497 msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
498}
499
500static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
501 .hw_params = msm_hdmi_audio_hw_params,
502 .audio_shutdown = msm_hdmi_audio_shutdown,
503};
504
505static struct hdmi_codec_pdata codec_data = {
506 .ops = &msm_hdmi_audio_codec_ops,
507 .max_i2s_channels = 8,
508 .i2s = 1,
509};
510
511static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
512{
513 hdmi->audio_pdev = platform_device_register_data(dev,
514 HDMI_CODEC_DRV_NAME,
515 PLATFORM_DEVID_AUTO,
516 &codec_data,
517 sizeof(codec_data));
Wei Yongjun06f32172016-07-12 11:06:52 +0000518 return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100519}
520
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100521static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
Rob Clarkc8afe682013-06-26 12:44:06 -0400522{
AngeloGioacchino Del Regnoec919e62021-12-01 11:52:09 +0100523 struct msm_drm_private *priv = dev_get_drvdata(master);
YueHaibing67146512018-11-14 09:55:34 +0000524 struct hdmi_platform_config *hdmi_cfg;
Rob Clark067fef32014-11-04 13:33:14 -0500525 struct hdmi *hdmi;
Rob Clark060530f2014-03-03 14:19:12 -0500526 struct device_node *of_node = dev->of_node;
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100527 int i, err;
Rob Clarkdada25b2013-12-01 12:12:54 -0500528
Archit Taneja1fd6a442015-10-30 12:35:55 +0530529 hdmi_cfg = (struct hdmi_platform_config *)
530 of_device_get_match_data(dev);
531 if (!hdmi_cfg) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530532 DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node);
Stephane Viau5eba5d82015-01-07 16:27:27 -0500533 return -ENXIO;
Rob Clark41e69772013-12-15 16:23:05 -0500534 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500535
Stephane Viau5eba5d82015-01-07 16:27:27 -0500536 hdmi_cfg->mmio_name = "core_physical";
jilai wangc6a57a52015-04-02 17:49:01 -0400537 hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
Archit Tanejadc50f7822016-02-25 11:22:36 +0530538
539 for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
Linus Walleija44769b2019-06-29 14:59:31 +0200540 const char *name = msm_hdmi_gpio_pdata[i].name;
541 struct gpio_desc *gpiod;
542
543 /*
544 * We are fetching the GPIO lines "as is" since the connector
545 * code is enabling and disabling the lines. Until that point
546 * the power-on default value will be kept.
547 */
548 gpiod = devm_gpiod_get_optional(dev, name, GPIOD_ASIS);
549 /* This will catch e.g. -PROBE_DEFER */
550 if (IS_ERR(gpiod))
551 return PTR_ERR(gpiod);
552 if (!gpiod) {
553 /* Try a second time, stripping down the name */
554 char name3[32];
555
556 /*
557 * Try again after stripping out the "qcom,hdmi-tx"
558 * prefix. This is mainly to match "hpd-gpios" used
559 * in the upstream bindings.
560 */
561 if (sscanf(name, "qcom,hdmi-tx-%s", name3))
562 gpiod = devm_gpiod_get_optional(dev, name3, GPIOD_ASIS);
563 if (IS_ERR(gpiod))
564 return PTR_ERR(gpiod);
565 if (!gpiod)
566 DBG("failed to get gpio: %s", name);
567 }
568 hdmi_cfg->gpios[i].gpiod = gpiod;
569 if (gpiod)
570 gpiod_set_consumer_name(gpiod, msm_hdmi_gpio_pdata[i].label);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100571 hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
572 hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
Archit Tanejadc50f7822016-02-25 11:22:36 +0530573 }
Rob Clarkdada25b2013-12-01 12:12:54 -0500574
Stephane Viau5eba5d82015-01-07 16:27:27 -0500575 dev->platform_data = hdmi_cfg;
576
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100577 hdmi = msm_hdmi_init(to_platform_device(dev));
Rob Clark067fef32014-11-04 13:33:14 -0500578 if (IS_ERR(hdmi))
579 return PTR_ERR(hdmi);
Rob Clarkd1a717b2014-11-18 08:40:44 -0500580 priv->hdmi = hdmi;
Stephane Viau5eba5d82015-01-07 16:27:27 -0500581
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100582 err = msm_hdmi_register_audio_driver(hdmi, dev);
583 if (err) {
584 DRM_ERROR("Failed to attach an audio codec %d\n", err);
585 hdmi->audio_pdev = NULL;
586 }
587
Rob Clarkc8afe682013-06-26 12:44:06 -0400588 return 0;
589}
590
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100591static void msm_hdmi_unbind(struct device *dev, struct device *master,
Rob Clark060530f2014-03-03 14:19:12 -0500592 void *data)
593{
AngeloGioacchino Del Regnoec919e62021-12-01 11:52:09 +0100594 struct msm_drm_private *priv = dev_get_drvdata(master);
595
Rob Clarkd1a717b2014-11-18 08:40:44 -0500596 if (priv->hdmi) {
Srinivas Kandagatlaf1427012016-06-10 10:45:56 +0100597 if (priv->hdmi->audio_pdev)
598 platform_device_unregister(priv->hdmi->audio_pdev);
599
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100600 msm_hdmi_destroy(priv->hdmi);
Rob Clarkd1a717b2014-11-18 08:40:44 -0500601 priv->hdmi = NULL;
602 }
Rob Clark060530f2014-03-03 14:19:12 -0500603}
604
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100605static const struct component_ops msm_hdmi_ops = {
606 .bind = msm_hdmi_bind,
607 .unbind = msm_hdmi_unbind,
Rob Clark060530f2014-03-03 14:19:12 -0500608};
609
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100610static int msm_hdmi_dev_probe(struct platform_device *pdev)
Rob Clark060530f2014-03-03 14:19:12 -0500611{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100612 return component_add(&pdev->dev, &msm_hdmi_ops);
Rob Clark060530f2014-03-03 14:19:12 -0500613}
614
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100615static int msm_hdmi_dev_remove(struct platform_device *pdev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400616{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100617 component_del(&pdev->dev, &msm_hdmi_ops);
Rob Clarkc8afe682013-06-26 12:44:06 -0400618 return 0;
619}
620
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100621static const struct of_device_id msm_hdmi_dt_match[] = {
Archit Taneja1fd6a442015-10-30 12:35:55 +0530622 { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
623 { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
624 { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
625 { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
626 { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
627 { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
628 {}
629};
630
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100631static struct platform_driver msm_hdmi_driver = {
632 .probe = msm_hdmi_dev_probe,
633 .remove = msm_hdmi_dev_remove,
Rob Clarkdada25b2013-12-01 12:12:54 -0500634 .driver = {
635 .name = "hdmi_msm",
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100636 .of_match_table = msm_hdmi_dt_match,
Rob Clarkdada25b2013-12-01 12:12:54 -0500637 },
Rob Clarkc8afe682013-06-26 12:44:06 -0400638};
639
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100640void __init msm_hdmi_register(void)
Rob Clarkc8afe682013-06-26 12:44:06 -0400641{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100642 msm_hdmi_phy_driver_register();
643 platform_driver_register(&msm_hdmi_driver);
Rob Clarkc8afe682013-06-26 12:44:06 -0400644}
645
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100646void __exit msm_hdmi_unregister(void)
Rob Clarkc8afe682013-06-26 12:44:06 -0400647{
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100648 platform_driver_unregister(&msm_hdmi_driver);
649 msm_hdmi_phy_driver_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -0400650}