| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
|---|
| 3 | 4 | * Copyright (C) 2013 Red Hat |
|---|
| 4 | 5 | * 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 | 6 | */ |
|---|
| 18 | 7 | |
|---|
| 19 | 8 | #include <linux/of_irq.h> |
|---|
| .. | .. |
|---|
| 98 | 87 | |
|---|
| 99 | 88 | phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0); |
|---|
| 100 | 89 | if (!phy_node) { |
|---|
| 101 | | - dev_err(&pdev->dev, "cannot find phy device\n"); |
|---|
| 90 | + DRM_DEV_ERROR(&pdev->dev, "cannot find phy device\n"); |
|---|
| 102 | 91 | return -ENXIO; |
|---|
| 103 | 92 | } |
|---|
| 104 | 93 | |
|---|
| .. | .. |
|---|
| 108 | 97 | |
|---|
| 109 | 98 | of_node_put(phy_node); |
|---|
| 110 | 99 | |
|---|
| 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); |
|---|
| 113 | 107 | return -EPROBE_DEFER; |
|---|
| 114 | 108 | } |
|---|
| 115 | 109 | |
|---|
| .. | .. |
|---|
| 148 | 142 | /* HDCP needs physical address of hdmi register */ |
|---|
| 149 | 143 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
|---|
| 150 | 144 | config->mmio_name); |
|---|
| 145 | + if (!res) { |
|---|
| 146 | + ret = -EINVAL; |
|---|
| 147 | + goto fail; |
|---|
| 148 | + } |
|---|
| 151 | 149 | hdmi->mmio_phy_addr = res->start; |
|---|
| 152 | 150 | |
|---|
| 153 | 151 | hdmi->qfprom_mmio = msm_ioremap(pdev, |
|---|
| 154 | 152 | config->qfprom_mmio_name, "HDMI_QFPROM"); |
|---|
| 155 | 153 | 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"); |
|---|
| 157 | 155 | hdmi->qfprom_mmio = NULL; |
|---|
| 158 | 156 | } |
|---|
| 159 | 157 | |
|---|
| .. | .. |
|---|
| 172 | 170 | config->hpd_reg_names[i]); |
|---|
| 173 | 171 | if (IS_ERR(reg)) { |
|---|
| 174 | 172 | 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", |
|---|
| 176 | 174 | config->hpd_reg_names[i], ret); |
|---|
| 177 | 175 | goto fail; |
|---|
| 178 | 176 | } |
|---|
| .. | .. |
|---|
| 195 | 193 | config->pwr_reg_names[i]); |
|---|
| 196 | 194 | if (IS_ERR(reg)) { |
|---|
| 197 | 195 | 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", |
|---|
| 199 | 197 | config->pwr_reg_names[i], ret); |
|---|
| 200 | 198 | goto fail; |
|---|
| 201 | 199 | } |
|---|
| .. | .. |
|---|
| 217 | 215 | clk = msm_clk_get(pdev, config->hpd_clk_names[i]); |
|---|
| 218 | 216 | if (IS_ERR(clk)) { |
|---|
| 219 | 217 | 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", |
|---|
| 221 | 219 | config->hpd_clk_names[i], ret); |
|---|
| 222 | 220 | goto fail; |
|---|
| 223 | 221 | } |
|---|
| .. | .. |
|---|
| 239 | 237 | clk = msm_clk_get(pdev, config->pwr_clk_names[i]); |
|---|
| 240 | 238 | if (IS_ERR(clk)) { |
|---|
| 241 | 239 | 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", |
|---|
| 243 | 241 | config->pwr_clk_names[i], ret); |
|---|
| 244 | 242 | goto fail; |
|---|
| 245 | 243 | } |
|---|
| .. | .. |
|---|
| 254 | 252 | hdmi->i2c = msm_hdmi_i2c_init(hdmi); |
|---|
| 255 | 253 | if (IS_ERR(hdmi->i2c)) { |
|---|
| 256 | 254 | 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); |
|---|
| 258 | 256 | hdmi->i2c = NULL; |
|---|
| 259 | 257 | goto fail; |
|---|
| 260 | 258 | } |
|---|
| 261 | 259 | |
|---|
| 262 | 260 | ret = msm_hdmi_get_phy(hdmi); |
|---|
| 263 | 261 | if (ret) { |
|---|
| 264 | | - dev_err(&pdev->dev, "failed to get phy\n"); |
|---|
| 262 | + DRM_DEV_ERROR(&pdev->dev, "failed to get phy\n"); |
|---|
| 265 | 263 | goto fail; |
|---|
| 266 | 264 | } |
|---|
| 267 | 265 | |
|---|
| .. | .. |
|---|
| 295 | 293 | struct platform_device *pdev = hdmi->pdev; |
|---|
| 296 | 294 | int ret; |
|---|
| 297 | 295 | |
|---|
| 296 | + if (priv->num_bridges == ARRAY_SIZE(priv->bridges)) { |
|---|
| 297 | + DRM_DEV_ERROR(dev->dev, "too many bridges\n"); |
|---|
| 298 | + return -ENOSPC; |
|---|
| 299 | + } |
|---|
| 300 | + |
|---|
| 298 | 301 | hdmi->dev = dev; |
|---|
| 299 | 302 | hdmi->encoder = encoder; |
|---|
| 300 | 303 | |
|---|
| .. | .. |
|---|
| 303 | 306 | hdmi->bridge = msm_hdmi_bridge_init(hdmi); |
|---|
| 304 | 307 | if (IS_ERR(hdmi->bridge)) { |
|---|
| 305 | 308 | 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); |
|---|
| 307 | 310 | hdmi->bridge = NULL; |
|---|
| 308 | 311 | goto fail; |
|---|
| 309 | 312 | } |
|---|
| .. | .. |
|---|
| 311 | 314 | hdmi->connector = msm_hdmi_connector_init(hdmi); |
|---|
| 312 | 315 | if (IS_ERR(hdmi->connector)) { |
|---|
| 313 | 316 | 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); |
|---|
| 315 | 318 | hdmi->connector = NULL; |
|---|
| 316 | 319 | goto fail; |
|---|
| 317 | 320 | } |
|---|
| 318 | 321 | |
|---|
| 319 | 322 | 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"); |
|---|
| 323 | 326 | goto fail; |
|---|
| 324 | 327 | } |
|---|
| 325 | 328 | |
|---|
| 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, |
|---|
| 328 | 331 | "hdmi_isr", hdmi); |
|---|
| 329 | 332 | 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", |
|---|
| 331 | 334 | hdmi->irq, ret); |
|---|
| 332 | 335 | goto fail; |
|---|
| 333 | 336 | } |
|---|
| .. | .. |
|---|
| 337 | 340 | DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret); |
|---|
| 338 | 341 | goto fail; |
|---|
| 339 | 342 | } |
|---|
| 340 | | - |
|---|
| 341 | | - encoder->bridge = hdmi->bridge; |
|---|
| 342 | 343 | |
|---|
| 343 | 344 | priv->bridges[priv->num_bridges++] = hdmi->bridge; |
|---|
| 344 | 345 | priv->connectors[priv->num_connectors++] = hdmi->connector; |
|---|
| .. | .. |
|---|
| 436 | 437 | { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" }, |
|---|
| 437 | 438 | }; |
|---|
| 438 | 439 | |
|---|
| 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 | | - |
|---|
| 471 | 440 | /* |
|---|
| 472 | 441 | * HDMI audio codec callbacks |
|---|
| 473 | 442 | */ |
|---|
| .. | .. |
|---|
| 482 | 451 | unsigned int level_shift = 0; /* 0dB */ |
|---|
| 483 | 452 | bool down_mix = false; |
|---|
| 484 | 453 | |
|---|
| 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, |
|---|
| 486 | 455 | params->sample_width, params->cea.channels); |
|---|
| 487 | 456 | |
|---|
| 488 | 457 | switch (params->cea.channels) { |
|---|
| .. | .. |
|---|
| 533 | 502 | rate = HDMI_SAMPLE_RATE_192KHZ; |
|---|
| 534 | 503 | break; |
|---|
| 535 | 504 | default: |
|---|
| 536 | | - dev_err(dev, "rate[%d] not supported!\n", |
|---|
| 505 | + DRM_DEV_ERROR(dev, "rate[%d] not supported!\n", |
|---|
| 537 | 506 | params->sample_rate); |
|---|
| 538 | 507 | return -EINVAL; |
|---|
| 539 | 508 | } |
|---|
| .. | .. |
|---|
| 577 | 546 | { |
|---|
| 578 | 547 | struct drm_device *drm = dev_get_drvdata(master); |
|---|
| 579 | 548 | struct msm_drm_private *priv = drm->dev_private; |
|---|
| 580 | | - static struct hdmi_platform_config *hdmi_cfg; |
|---|
| 549 | + struct hdmi_platform_config *hdmi_cfg; |
|---|
| 581 | 550 | struct hdmi *hdmi; |
|---|
| 582 | 551 | struct device_node *of_node = dev->of_node; |
|---|
| 583 | 552 | int i, err; |
|---|
| .. | .. |
|---|
| 585 | 554 | hdmi_cfg = (struct hdmi_platform_config *) |
|---|
| 586 | 555 | of_device_get_match_data(dev); |
|---|
| 587 | 556 | 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); |
|---|
| 589 | 558 | return -ENXIO; |
|---|
| 590 | 559 | } |
|---|
| 591 | 560 | |
|---|
| .. | .. |
|---|
| 593 | 562 | hdmi_cfg->qfprom_mmio_name = "qfprom_physical"; |
|---|
| 594 | 563 | |
|---|
| 595 | 564 | 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); |
|---|
| 598 | 596 | hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output; |
|---|
| 599 | 597 | hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value; |
|---|
| 600 | | - hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label; |
|---|
| 601 | 598 | } |
|---|
| 602 | 599 | |
|---|
| 603 | 600 | dev->platform_data = hdmi_cfg; |
|---|