Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp318340ybh; Wed, 18 Mar 2020 00:08:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtoX9K7m2YzUDSjaii5mBw0CMp69uoDP/89wOQhMk8f+JAkwnsFInkI6xMAVDV0lgEUAWRH X-Received: by 2002:aca:dc08:: with SMTP id t8mr1966993oig.135.1584515301486; Wed, 18 Mar 2020 00:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584515301; cv=none; d=google.com; s=arc-20160816; b=SjJJY2JTL7Or5i8R2euyjHBU9LQ70zhuBSc6xo6hIXyjXN66QprIHDp/ANBhxG9hl3 l5JaXE3473DYx1BW76+N0h+BPMo7hEgLNkbawHAEn3NMMxqET2yZkaLGJbs4LgGCqLoa 0ZTeLDupZNJHaDdn2J7hoxltIH6HMxqKtODwa7OuQaFhOUYHUU9YzNlnbUZde2qrABLn oFgcD7use87pgUvPfFe3fSW+pS5FOqMl+EWMcT3MaJNELKp2b/G85kkZJRCCkE3ofdF0 0Mu5RJXmCPZ0yMG3DuZgCghP+3BI9i2JJiJTj2zqdsUmnYC38euNEJmQgVRcAF2XBNtL 3REQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=taBKDNvSe2QBZdFQL4tj4S4hh81dFl7V5WNbbYFwxIg=; b=m5kzys6pp8bqLrvnDVXqb2J9h2QaZ+6ttooHcNJQRqVlBEyrhRCVd8IaQiUg8ijM6j Wvei/DZLLHbBEULXEBWrRXXUt7sdlGRum7Ufq4DsHqBTXceSrafQKa+CWVd+XjJL8Tmn GtKrCQlEWoQaifxSYagEGp2tTlKhDzmyXui76heQMOBxV3z2oU9QibZpIglSkao1vEWe QmrnbbvnvR1y/nKQmGnOZLq4fGoTfj2V5UFD0CqPKkY3bgk0Mk92n54OnH8ZDbdGMNZ8 +nQlcgoF0jjLL1UOsAjcML1dafnwO8CDzpctcLpkfvYQ2epI4M1U0F9n+hNqBDg/R/r8 XOWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v129si2718133oib.58.2020.03.18.00.08.08; Wed, 18 Mar 2020 00:08:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727326AbgCRHHn (ORCPT + 99 others); Wed, 18 Mar 2020 03:07:43 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40278 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbgCRHHn (ORCPT ); Wed, 18 Mar 2020 03:07:43 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 8CCD929360F From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org Cc: Collabora Kernel ML , Andrzej Hajda , icenowy@aosc.io, anarsoul@gmail.com, Neil Armstrong , matthias.bgg@gmail.com, drinkcat@chromium.org, hsinyi@chromium.org, megous@megous.com, kbuild test robot , Daniel Vetter , David Airlie , Jernej Skrabec , Jonas Karlman , Laurent Pinchart , Maxime Ripard , Thomas Gleixner , Torsten Duwe , dri-devel@lists.freedesktop.org Subject: [PATCH v4 4/4] drm/bridge: anx7688: Add ANX7688 bridge driver support Date: Wed, 18 Mar 2020 08:07:30 +0100 Message-Id: <20200318070730.4012371-4-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318070730.4012371-1-enric.balletbo@collabora.com> References: <20200318070730.4012371-1-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Boichat This driver adds support for the ANX7688 HDMI to DP converter block of the ANX7688 multi-function device. For our use case, the only reason the Linux kernel driver is necessary is to reject resolutions that require more bandwidth than what is available on the DP side. DP bandwidth and lane count are reported by the bridge via 2 registers and, as far as we know, only for chips that have a firmware version greather than 0.85 supports these two registers. Signed-off-by: Nicolas Boichat Signed-off-by: Hsin-Yi Wang [The driver is OF only so should depends on CONFIG_OF] Reported-by: kbuild test robot Signed-off-by: Enric Balletbo i Serra --- Changes in v4: - Fix build issue reported by kbuild test robot Changes in v3: - Convert to a child of ANX7688 multi-function device. Changes in v2: - Move driver to drivers/gpu/drm/bridge/analogix. - Make the driver OF only so we can reduce the ifdefs. - Update the Copyright to 2020. - Use probe_new so we can get rid of the i2c_device_id table. drivers/gpu/drm/bridge/analogix/Kconfig | 10 ++ drivers/gpu/drm/bridge/analogix/Makefile | 1 + .../drm/bridge/analogix/analogix-anx7688.c | 135 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/gpu/drm/bridge/analogix/analogix-anx7688.c diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig index e1fa7d820373..1f096055c036 100644 --- a/drivers/gpu/drm/bridge/analogix/Kconfig +++ b/drivers/gpu/drm/bridge/analogix/Kconfig @@ -11,6 +11,16 @@ config DRM_ANALOGIX_ANX6345 ANX6345 transforms the LVTTL RGB output of an application processor to eDP or DisplayPort. +config DRM_ANALOGIX_ANX7688 + tristate "Analogix ANX7688 bridge" + depends on OF + select DRM_KMS_HELPER + select MFD_ANX7688 + help + ANX7688 is an ultra-low power 4k Ultra-HD (4096x2160p60) + mobile HD transmitter designed for portable devices. The + ANX7688 converts HDMI 2.0 to DisplayPort 1.3 Ultra-HD. + config DRM_ANALOGIX_ANX78XX tristate "Analogix ANX78XX bridge" select DRM_ANALOGIX_DP diff --git a/drivers/gpu/drm/bridge/analogix/Makefile b/drivers/gpu/drm/bridge/analogix/Makefile index 97669b374098..27cd73635c8c 100644 --- a/drivers/gpu/drm/bridge/analogix/Makefile +++ b/drivers/gpu/drm/bridge/analogix/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only analogix_dp-objs := analogix_dp_core.o analogix_dp_reg.o analogix-i2c-dptx.o obj-$(CONFIG_DRM_ANALOGIX_ANX6345) += analogix-anx6345.o +obj-$(CONFIG_DRM_ANALOGIX_ANX7688) += analogix-anx7688.o obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix_dp.o diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c new file mode 100644 index 000000000000..81b950ecde27 --- /dev/null +++ b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ANX7688 HDMI->DP bridge driver + * + * Copyright 2020 Google LLC + */ + +#include +#include +#include +#include +#include +#include + +struct anx7688_bridge_data { + struct drm_bridge bridge; + struct regmap *regmap; + + bool filter; +}; + +static inline struct anx7688_bridge_data * +bridge_to_anx7688(struct drm_bridge *bridge) +{ + return container_of(bridge, struct anx7688_bridge_data, bridge); +} + +static bool anx7688_bridge_mode_fixup(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct anx7688_bridge_data *data = bridge_to_anx7688(bridge); + int totalbw, requiredbw; + u8 dpbw, lanecount; + u8 regs[2]; + int ret; + + if (!data->filter) + return true; + + /* Read both regs 0x85 (bandwidth) and 0x86 (lane count). */ + ret = regmap_bulk_read(data->regmap, ANX7688_DP_BANDWIDTH_REG, regs, + 2); + if (ret < 0) { + DRM_ERROR("Failed to read bandwidth/lane count\n"); + return false; + } + dpbw = regs[0]; + lanecount = regs[1]; + + /* Maximum 0x19 bandwidth (6.75 Gbps Turbo mode), 2 lanes */ + if (dpbw > 0x19 || lanecount > 2) { + DRM_ERROR("Invalid bandwidth/lane count (%02x/%d)\n", dpbw, + lanecount); + return false; + } + + /* Compute available bandwidth (kHz) */ + totalbw = dpbw * lanecount * 270000 * 8 / 10; + + /* Required bandwidth (8 bpc, kHz) */ + requiredbw = mode->clock * 8 * 3; + + DRM_DEBUG_KMS("DP bandwidth: %d kHz (%02x/%d); mode requires %d Khz\n", + totalbw, dpbw, lanecount, requiredbw); + + if (totalbw == 0) { + DRM_ERROR("Bandwidth/lane count are 0, not rejecting modes\n"); + return true; + } + + return totalbw >= requiredbw; +} + +static const struct drm_bridge_funcs anx7688_bridge_funcs = { + .mode_fixup = anx7688_bridge_mode_fixup, +}; + +static int anx7688_bridge_probe(struct platform_device *pdev) +{ + struct anx7688 *anx7688 = dev_get_drvdata(pdev->dev.parent); + struct anx7688_bridge_data *data; + struct device *dev = &pdev->dev; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->bridge.of_node = dev->of_node; + data->regmap = anx7688->regmap; + + /* FW version >= 0.85 supports bandwidth/lane count registers */ + if (anx7688->fw_version >= ANX7688_MINIMUM_FW_VERSION) + data->filter = true; + else + /* Warn, but not fail, for backwards compatibility */ + DRM_WARN("Old ANX7688 FW version (0x%04x), not filtering\n", + anx7688->fw_version); + + data->bridge.funcs = &anx7688_bridge_funcs; + drm_bridge_add(&data->bridge); + + return 0; +} + +static int anx7688_bridge_remove(struct platform_device *pdev) +{ + struct anx7688_bridge_data *data = dev_get_drvdata(&pdev->dev); + + drm_bridge_remove(&data->bridge); + + return 0; +} + +static const struct of_device_id anx7688_bridge_match_table[] = { + { .compatible = "analogix,anx7688-bridge", }, + { } +}; +MODULE_DEVICE_TABLE(of, anx7688_bridge_match_table); + +static struct platform_driver anx7688_bridge_driver = { + .probe = anx7688_bridge_probe, + .remove = anx7688_bridge_remove, + .driver = { + .name = "anx7688-bridge", + .of_match_table = anx7688_bridge_match_table, + }, +}; + +module_platform_driver(anx7688_bridge_driver); + +MODULE_DESCRIPTION("ANX7688 HDMI->DP bridge driver"); +MODULE_AUTHOR("Nicolas Boichat "); +MODULE_AUTHOR("Enric Balletbo i Serra "); +MODULE_LICENSE("GPL"); -- 2.25.1