forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 223293205a7265c8b02882461ba8996650048ade
kernel/drivers/gpu/drm/msm/hdmi/hdmi.c
....@@ -1,19 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
34 * Copyright (C) 2013 Red Hat
45 * 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/>.
176 */
187
198 #include <linux/of_irq.h>
....@@ -98,7 +87,7 @@
9887
9988 phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
10089 if (!phy_node) {
101
- dev_err(&pdev->dev, "cannot find phy device\n");
90
+ DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n");
10291 return -ENXIO;
10392 }
10493
....@@ -108,8 +97,13 @@
10897
10998 of_node_put(phy_node);
11099
111
- if (!phy_pdev || !hdmi->phy) {
112
- dev_err(&pdev->dev, "phy driver is not ready\n");
100
+ if (!phy_pdev) {
101
+ DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
102
+ return -EPROBE_DEFER;
103
+ }
104
+ if (!hdmi->phy) {
105
+ DRM_DEV_ERROR(&pdev->dev, "phy driver is not ready\n");
106
+ put_device(&phy_pdev->dev);
113107 return -EPROBE_DEFER;
114108 }
115109
....@@ -148,12 +142,16 @@
148142 /* HDCP needs physical address of hdmi register */
149143 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
150144 config->mmio_name);
145
+ if (!res) {
146
+ ret = -EINVAL;
147
+ goto fail;
148
+ }
151149 hdmi->mmio_phy_addr = res->start;
152150
153151 hdmi->qfprom_mmio = msm_ioremap(pdev,
154152 config->qfprom_mmio_name, "HDMI_QFPROM");
155153 if (IS_ERR(hdmi->qfprom_mmio)) {
156
- dev_info(&pdev->dev, "can't find qfprom resource\n");
154
+ DRM_DEV_INFO(&pdev->dev, "can't find qfprom resource\n");
157155 hdmi->qfprom_mmio = NULL;
158156 }
159157
....@@ -172,7 +170,7 @@
172170 config->hpd_reg_names[i]);
173171 if (IS_ERR(reg)) {
174172 ret = PTR_ERR(reg);
175
- dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
173
+ DRM_DEV_ERROR(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
176174 config->hpd_reg_names[i], ret);
177175 goto fail;
178176 }
....@@ -195,7 +193,7 @@
195193 config->pwr_reg_names[i]);
196194 if (IS_ERR(reg)) {
197195 ret = PTR_ERR(reg);
198
- dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
196
+ DRM_DEV_ERROR(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
199197 config->pwr_reg_names[i], ret);
200198 goto fail;
201199 }
....@@ -217,7 +215,7 @@
217215 clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
218216 if (IS_ERR(clk)) {
219217 ret = PTR_ERR(clk);
220
- dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
218
+ DRM_DEV_ERROR(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
221219 config->hpd_clk_names[i], ret);
222220 goto fail;
223221 }
....@@ -239,7 +237,7 @@
239237 clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
240238 if (IS_ERR(clk)) {
241239 ret = PTR_ERR(clk);
242
- dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
240
+ DRM_DEV_ERROR(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
243241 config->pwr_clk_names[i], ret);
244242 goto fail;
245243 }
....@@ -254,14 +252,14 @@
254252 hdmi->i2c = msm_hdmi_i2c_init(hdmi);
255253 if (IS_ERR(hdmi->i2c)) {
256254 ret = PTR_ERR(hdmi->i2c);
257
- dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
255
+ DRM_DEV_ERROR(&pdev->dev, "failed to get i2c: %d\n", ret);
258256 hdmi->i2c = NULL;
259257 goto fail;
260258 }
261259
262260 ret = msm_hdmi_get_phy(hdmi);
263261 if (ret) {
264
- dev_err(&pdev->dev, "failed to get phy\n");
262
+ DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n");
265263 goto fail;
266264 }
267265
....@@ -295,6 +293,11 @@
295293 struct platform_device *pdev = hdmi->pdev;
296294 int ret;
297295
296
+ if (priv->num_bridges == ARRAY_SIZE(priv->bridges)) {
297
+ DRM_DEV_ERROR(dev->dev, "too many bridges\n");
298
+ return -ENOSPC;
299
+ }
300
+
298301 hdmi->dev = dev;
299302 hdmi->encoder = encoder;
300303
....@@ -303,7 +306,7 @@
303306 hdmi->bridge = msm_hdmi_bridge_init(hdmi);
304307 if (IS_ERR(hdmi->bridge)) {
305308 ret = PTR_ERR(hdmi->bridge);
306
- dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
309
+ DRM_DEV_ERROR(dev->dev, "failed to create HDMI bridge: %d\n", ret);
307310 hdmi->bridge = NULL;
308311 goto fail;
309312 }
....@@ -311,23 +314,23 @@
311314 hdmi->connector = msm_hdmi_connector_init(hdmi);
312315 if (IS_ERR(hdmi->connector)) {
313316 ret = PTR_ERR(hdmi->connector);
314
- dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
317
+ DRM_DEV_ERROR(dev->dev, "failed to create HDMI connector: %d\n", ret);
315318 hdmi->connector = NULL;
316319 goto fail;
317320 }
318321
319322 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
320
- if (hdmi->irq < 0) {
321
- ret = hdmi->irq;
322
- dev_err(dev->dev, "failed to get irq: %d\n", ret);
323
+ if (!hdmi->irq) {
324
+ ret = -EINVAL;
325
+ DRM_DEV_ERROR(dev->dev, "failed to get irq\n");
323326 goto fail;
324327 }
325328
326
- ret = devm_request_irq(&pdev->dev, hdmi->irq,
327
- msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
329
+ ret = devm_request_irq(dev->dev, hdmi->irq,
330
+ msm_hdmi_irq, IRQF_TRIGGER_HIGH,
328331 "hdmi_isr", hdmi);
329332 if (ret < 0) {
330
- dev_err(dev->dev, "failed to request IRQ%u: %d\n",
333
+ DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
331334 hdmi->irq, ret);
332335 goto fail;
333336 }
....@@ -337,8 +340,6 @@
337340 DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
338341 goto fail;
339342 }
340
-
341
- encoder->bridge = hdmi->bridge;
342343
343344 priv->bridges[priv->num_bridges++] = hdmi->bridge;
344345 priv->connectors[priv->num_connectors++] = hdmi->connector;
....@@ -436,38 +437,6 @@
436437 { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
437438 };
438439
439
-static int msm_hdmi_get_gpio(struct device_node *of_node, const char *name)
440
-{
441
- int gpio;
442
-
443
- /* try with the gpio names as in the table (downstream bindings) */
444
- gpio = of_get_named_gpio(of_node, name, 0);
445
- if (gpio < 0) {
446
- char name2[32];
447
-
448
- /* try with the gpio names as in the upstream bindings */
449
- snprintf(name2, sizeof(name2), "%s-gpios", name);
450
- gpio = of_get_named_gpio(of_node, name2, 0);
451
- if (gpio < 0) {
452
- char name3[32];
453
-
454
- /*
455
- * try again after stripping out the "qcom,hdmi-tx"
456
- * prefix. This is mainly to match "hpd-gpios" used
457
- * in the upstream bindings
458
- */
459
- if (sscanf(name2, "qcom,hdmi-tx-%s", name3))
460
- gpio = of_get_named_gpio(of_node, name3, 0);
461
- }
462
-
463
- if (gpio < 0) {
464
- DBG("failed to get gpio: %s (%d)", name, gpio);
465
- gpio = -1;
466
- }
467
- }
468
- return gpio;
469
-}
470
-
471440 /*
472441 * HDMI audio codec callbacks
473442 */
....@@ -482,7 +451,7 @@
482451 unsigned int level_shift = 0; /* 0dB */
483452 bool down_mix = false;
484453
485
- dev_dbg(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
454
+ DRM_DEV_DEBUG(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
486455 params->sample_width, params->cea.channels);
487456
488457 switch (params->cea.channels) {
....@@ -533,7 +502,7 @@
533502 rate = HDMI_SAMPLE_RATE_192KHZ;
534503 break;
535504 default:
536
- dev_err(dev, "rate[%d] not supported!\n",
505
+ DRM_DEV_ERROR(dev, "rate[%d] not supported!\n",
537506 params->sample_rate);
538507 return -EINVAL;
539508 }
....@@ -577,7 +546,7 @@
577546 {
578547 struct drm_device *drm = dev_get_drvdata(master);
579548 struct msm_drm_private *priv = drm->dev_private;
580
- static struct hdmi_platform_config *hdmi_cfg;
549
+ struct hdmi_platform_config *hdmi_cfg;
581550 struct hdmi *hdmi;
582551 struct device_node *of_node = dev->of_node;
583552 int i, err;
....@@ -585,7 +554,7 @@
585554 hdmi_cfg = (struct hdmi_platform_config *)
586555 of_device_get_match_data(dev);
587556 if (!hdmi_cfg) {
588
- dev_err(dev, "unknown hdmi_cfg: %s\n", of_node->name);
557
+ DRM_DEV_ERROR(dev, "unknown hdmi_cfg: %pOFn\n", of_node);
589558 return -ENXIO;
590559 }
591560
....@@ -593,11 +562,39 @@
593562 hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
594563
595564 for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
596
- hdmi_cfg->gpios[i].num = msm_hdmi_get_gpio(of_node,
597
- msm_hdmi_gpio_pdata[i].name);
565
+ const char *name = msm_hdmi_gpio_pdata[i].name;
566
+ struct gpio_desc *gpiod;
567
+
568
+ /*
569
+ * We are fetching the GPIO lines "as is" since the connector
570
+ * code is enabling and disabling the lines. Until that point
571
+ * the power-on default value will be kept.
572
+ */
573
+ gpiod = devm_gpiod_get_optional(dev, name, GPIOD_ASIS);
574
+ /* This will catch e.g. -PROBE_DEFER */
575
+ if (IS_ERR(gpiod))
576
+ return PTR_ERR(gpiod);
577
+ if (!gpiod) {
578
+ /* Try a second time, stripping down the name */
579
+ char name3[32];
580
+
581
+ /*
582
+ * Try again after stripping out the "qcom,hdmi-tx"
583
+ * prefix. This is mainly to match "hpd-gpios" used
584
+ * in the upstream bindings.
585
+ */
586
+ if (sscanf(name, "qcom,hdmi-tx-%s", name3))
587
+ gpiod = devm_gpiod_get_optional(dev, name3, GPIOD_ASIS);
588
+ if (IS_ERR(gpiod))
589
+ return PTR_ERR(gpiod);
590
+ if (!gpiod)
591
+ DBG("failed to get gpio: %s", name);
592
+ }
593
+ hdmi_cfg->gpios[i].gpiod = gpiod;
594
+ if (gpiod)
595
+ gpiod_set_consumer_name(gpiod, msm_hdmi_gpio_pdata[i].label);
598596 hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
599597 hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
600
- hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label;
601598 }
602599
603600 dev->platform_data = hdmi_cfg;