Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2237288ybv; Fri, 14 Feb 2020 14:20:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwtYKdT8uiH2b5XtKrH1YNJ2pyenS5pUGdrLqjIdKymGPd9nQROZaPtGZgMKJQKJ+FrtE7J X-Received: by 2002:a05:6830:1f0c:: with SMTP id u12mr3940467otg.253.1581718838700; Fri, 14 Feb 2020 14:20:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581718838; cv=none; d=google.com; s=arc-20160816; b=mGipYcGSXS+Tt5cWlRJhHgbxaV/+MnHppFiFYR0gEO96qsYr9SZV6nvYukTSbW9aNR BEcxudi9M9U4wXgC/MliNPDBqUJKzAVVAMDHLZ3g4k6tMCaF5gGrcaW7t/wXAjcdVHj/ sWXgjJWOMucQWcDEOPtTy9Dxf0gywrPl2bloQa7gMPpiC14qRFt6+KmXxMtMgsgNGhUK z75QOcFPstpYM8aRnT5smgHXegm7EGUrwtBfaR3riRSpU/9DOw5fO1dI19ZAJZoTdlZl fdW/cStu2SkspBBNpRJOn3qFoDdbERxZH+huDiAGtcszgLF7i76yPUBVx96GUSoV33oT 8MWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=lVsOaxhE8/tLJ1UyF9Wdu153b36/ZTFgP+xFkwmRVqA=; b=neZ1Zph/qejnkTT2rnIgvdr7Xhg1a0xlitF8qE9dd1LFLku8ufh3TD7W7u+Wg5F5l/ +gRCdu69EgpHTJXQPYkfV1ee1hTSOOBR1ORWju/ZtMj0ZtQEVkpT5ZCST5F6XTunCT0S ITiTUwo8hd0BjfQ1VLhpbZCq0iIDbJvnMAsYSBsksqglwRV++mpk5WAUfwlQ4AyCWODN 1YRRtkP0a0aBJ/k0N2O9790+GfztuT2KpNfOOBS81ehg79jdU0LpJyt2g3uQwD5DhVuZ dArZpALid4igNZALMAin0mobcpHcSGaT1R7JbSFXTkE98Lem+rihvSsx/RETwW98m0MI dqKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I92ouAhI; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si3407347oid.189.2020.02.14.14.20.26; Fri, 14 Feb 2020 14:20:38 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I92ouAhI; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbgBNWUQ (ORCPT + 99 others); Fri, 14 Feb 2020 17:20:16 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:40346 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727566AbgBNWUP (ORCPT ); Fri, 14 Feb 2020 17:20:15 -0500 Received: by mail-qt1-f196.google.com with SMTP id v25so8033658qto.7 for ; Fri, 14 Feb 2020 14:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lVsOaxhE8/tLJ1UyF9Wdu153b36/ZTFgP+xFkwmRVqA=; b=I92ouAhIblt4CaF9We+FZCryDFqKr1CYXQwRsLYZIfa8YwU+6OzrusXTehQgNRQX0e A3LnMSHlAMpOF0VxhwXTsRuqHP5G21zClwiECHmlqQyYWVTgTnypqYqnnNsGnqBWhOCU TId9XqlP65R/105IEnwRSuPgBWeCEqLlyJGZrvMriLJwu6v/sgee4igdLhOHDfzmqdFE kVlXz8yg2+vR0rboLxfb98W4Ocqrg9Yduz0IkR9RMRf3uR15zQz6zBph3vuTJwbbz40e 1qyH6C9ALktRtI52km19pUSGSBE2HxgAZvoSIO7tFGpqVQUW1jvVrBbi0J3f0f9lYFly d4cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lVsOaxhE8/tLJ1UyF9Wdu153b36/ZTFgP+xFkwmRVqA=; b=qHIk2KonSgwcAKx7IaK2/hvDz+hh5VAEyoh3UDrEcqyg+Y/LDud52JDuJhg2a81Xkn IPMaliqRwcyxJ8+ljF1phXbzhMKn4Qaeopa3c1ETkRrkfEsRfFMNRYR+RyRekCu/EbXD QgZBAD0ZGSiMNUreI5awnwXmIbOKAGVMakfArUOZM7UB3cJKdV0aH7Dn2snySaoLp+0C qztX3Tp8EBm1ocVGrUxZdAY4fl+uwgU2FZNPMB0unXdQHN+hJnACrRk2kb3H1PAeoBo9 O+TEfiA7bPcejsO+Pl+nEpeOWfiiHetwOYNcVA9fk0BLcvwiwIsTRWbVzhyg87HIVJMl elaw== X-Gm-Message-State: APjAAAV8wTmAIA3tggpvAkGKiedap3eJDeVKCgu4/i3gr7ZpW6Kwujjy YDYbe81noqS4hmm4pbpIDm23R8o+aVE52X54PUg= X-Received: by 2002:ac8:3602:: with SMTP id m2mr4275735qtb.356.1581718812833; Fri, 14 Feb 2020 14:20:12 -0800 (PST) MIME-Version: 1.0 References: <20200213145416.890080-1-enric.balletbo@collabora.com> <20200213145416.890080-2-enric.balletbo@collabora.com> In-Reply-To: From: Enric Balletbo Serra Date: Fri, 14 Feb 2020 23:20:01 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] drm/bridge: anx7688: Add anx7688 bridge driver support To: Vasily Khoruzhick Cc: Icenowy Zheng , Enric Balletbo i Serra , Jernej Skrabec , Nicolas Boichat , Laurent Pinchart , Neil Armstrong , David Airlie , Torsten Duwe , Jonas Karlman , linux-kernel , dri-devel , Andrzej Hajda , Maxime Ripard , Hsin-Yi Wang , Matthias Brugger , Thomas Gleixner , Collabora Kernel ML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vasily, Missatge de Vasily Khoruzhick del dia dv., 14 de febr. 2020 a les 23:17: > > On Fri, Feb 14, 2020 at 1:53 PM Enric Balletbo Serra > wrote: > > > > Hi Vasily, > > > > Missatge de Vasily Khoruzhick del dia dv., 14 de > > febr. 2020 a les 22:36: > > > > > > On Thu, Feb 13, 2020 at 6:54 AM Enric Balletbo i Serra > > > wrote: > > > > > > > > From: Nicolas Boichat > > > > > > > > ANX7688 is a HDMI to DP converter (as well as USB-C port controller), > > > > that has an internal microcontroller. > > > > > > > > The only reason a 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 on I2C. > > > > > > It is true only for your particular platform where usb-c part is > > > managed by firmware. Pinephone has the same anx7688 but linux will > > > need a driver that manages usb-c in addition to DP. > > > > > > I'd suggest making it MFD driver from the beginning, or at least make > > > proper bindings so we don't have to rework it and introduce binding > > > incompatibilities in future. > > > > > > > Do you have example code on how the ANX7866 is used in pinephone? > > There is a repo somewhere? > > I don't think it's implemented yet. I've CCed Icenowy in case if she > has anything. > It would be good to join the effort. Just because I am curious, there are public schematics for the pinephone that is using that bridge? > > Thanks, > > Enric > > > > > > Signed-off-by: Nicolas Boichat > > > > Signed-off-by: Hsin-Yi Wang > > > > Signed-off-by: Enric Balletbo i Serra > > > > --- > > > > > > > > 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 | 12 ++ > > > > drivers/gpu/drm/bridge/analogix/Makefile | 1 + > > > > .../drm/bridge/analogix/analogix-anx7688.c | 188 ++++++++++++++++++ > > > > 3 files changed, 201 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..af7c2939403c 100644 > > > > --- a/drivers/gpu/drm/bridge/analogix/Kconfig > > > > +++ b/drivers/gpu/drm/bridge/analogix/Kconfig > > > > @@ -11,6 +11,18 @@ 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 REGMAP_I2C > > > > + 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 > > > > + including an intelligent crosspoint switch to support > > > > + USB Type-C. > > > > + > > > > 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..10a7cd0f9126 > > > > --- /dev/null > > > > +++ b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c > > > > @@ -0,0 +1,188 @@ > > > > +// SPDX-License-Identifier: GPL-2.0-only > > > > +/* > > > > + * ANX7688 HDMI->DP bridge driver > > > > + * > > > > + * Copyright 2020 Google LLC > > > > + */ > > > > + > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > + > > > > +/* Register addresses */ > > > > +#define VENDOR_ID_REG 0x00 > > > > +#define DEVICE_ID_REG 0x02 > > > > + > > > > +#define FW_VERSION_REG 0x80 > > > > + > > > > +#define DP_BANDWIDTH_REG 0x85 > > > > +#define DP_LANE_COUNT_REG 0x86 > > > > + > > > > +#define VENDOR_ID 0x1f29 > > > > +#define DEVICE_ID 0x7688 > > > > + > > > > +/* First supported firmware version (0.85) */ > > > > +#define MINIMUM_FW_VERSION 0x0085 > > > > + > > > > +struct anx7688 { > > > > + struct drm_bridge bridge; > > > > + struct i2c_client *client; > > > > + struct regmap *regmap; > > > > + > > > > + bool filter; > > > > +}; > > > > + > > > > +static inline struct anx7688 *bridge_to_anx7688(struct drm_bridge *bridge) > > > > +{ > > > > + return container_of(bridge, struct anx7688, 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 *anx7688 = bridge_to_anx7688(bridge); > > > > + int totalbw, requiredbw; > > > > + u8 dpbw, lanecount; > > > > + u8 regs[2]; > > > > + int ret; > > > > + > > > > + if (!anx7688->filter) > > > > + return true; > > > > + > > > > + /* Read both regs 0x85 (bandwidth) and 0x86 (lane count). */ > > > > + ret = regmap_bulk_read(anx7688->regmap, DP_BANDWIDTH_REG, regs, 2); > > > > + if (ret < 0) { > > > > + dev_err(&anx7688->client->dev, > > > > + "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) { > > > > + dev_err(&anx7688->client->dev, > > > > + "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; > > > > + > > > > + dev_dbg(&anx7688->client->dev, > > > > + "DP bandwidth: %d kHz (%02x/%d); mode requires %d Khz\n", > > > > + totalbw, dpbw, lanecount, requiredbw); > > > > + > > > > + if (totalbw == 0) { > > > > + dev_warn(&anx7688->client->dev, > > > > + "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 const struct regmap_config anx7688_regmap_config = { > > > > + .reg_bits = 8, > > > > + .val_bits = 8, > > > > +}; > > > > + > > > > +static int anx7688_i2c_probe(struct i2c_client *client) > > > > +{ > > > > + struct device *dev = &client->dev; > > > > + struct anx7688 *anx7688; > > > > + u16 vendor, device; > > > > + u16 fwversion; > > > > + u8 buffer[4]; > > > > + int ret; > > > > + > > > > + anx7688 = devm_kzalloc(dev, sizeof(*anx7688), GFP_KERNEL); > > > > + if (!anx7688) > > > > + return -ENOMEM; > > > > + > > > > + anx7688->bridge.of_node = dev->of_node; > > > > + anx7688->client = client; > > > > + i2c_set_clientdata(client, anx7688); > > > > + > > > > + anx7688->regmap = devm_regmap_init_i2c(client, &anx7688_regmap_config); > > > > + > > > > + /* Read both vendor and device id (4 bytes). */ > > > > + ret = regmap_bulk_read(anx7688->regmap, VENDOR_ID_REG, buffer, 4); > > > > + if (ret) { > > > > + dev_err(dev, "Failed to read chip vendor/device id\n"); > > > > + return ret; > > > > + } > > > > + > > > > + vendor = (u16)buffer[1] << 8 | buffer[0]; > > > > + device = (u16)buffer[3] << 8 | buffer[2]; > > > > + if (vendor != VENDOR_ID || device != DEVICE_ID) { > > > > + dev_err(dev, "Invalid vendor/device id %04x/%04x\n", > > > > + vendor, device); > > > > + return -ENODEV; > > > > + } > > > > + > > > > + ret = regmap_bulk_read(anx7688->regmap, FW_VERSION_REG, buffer, 2); > > > > + if (ret) { > > > > + dev_err(&client->dev, "Failed to read firmware version\n"); > > > > + return ret; > > > > + } > > > > + > > > > + fwversion = (u16)buffer[0] << 8 | buffer[1]; > > > > + dev_info(dev, "ANX7688 firwmare version %02x.%02x\n", > > > > + buffer[0], buffer[1]); > > > > + > > > > + /* FW version >= 0.85 supports bandwidth/lane count registers */ > > > > + if (fwversion >= MINIMUM_FW_VERSION) { > > > > + anx7688->filter = true; > > > > + } else { > > > > + /* Warn, but not fail, for backwards compatibility. */ > > > > + dev_warn(dev, > > > > + "Old ANX7688 FW version (%02x.%02x), not filtering\n", > > > > + buffer[0], buffer[1]); > > > > + } > > > > + > > > > + anx7688->bridge.funcs = &anx7688_bridge_funcs; > > > > + drm_bridge_add(&anx7688->bridge); > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +static int anx7688_i2c_remove(struct i2c_client *client) > > > > +{ > > > > + struct anx7688 *anx7688 = i2c_get_clientdata(client); > > > > + > > > > + drm_bridge_remove(&anx7688->bridge); > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +static const struct of_device_id anx7688_match_table[] = { > > > > + { .compatible = "analogix,anx7688", }, > > > > + { } > > > > +}; > > > > +MODULE_DEVICE_TABLE(of, anx7688_match_table); > > > > + > > > > +static struct i2c_driver anx7688_driver = { > > > > + .probe_new = anx7688_i2c_probe, > > > > + .remove = anx7688_i2c_remove, > > > > + .driver = { > > > > + .name = "anx7688", > > > > + .of_match_table = anx7688_match_table, > > > > + }, > > > > +}; > > > > + > > > > +module_i2c_driver(anx7688_driver); > > > > + > > > > +MODULE_DESCRIPTION("ANX7688 HDMI->DP bridge driver"); > > > > +MODULE_AUTHOR("Nicolas Boichat "); > > > > +MODULE_LICENSE("GPL"); > > > > -- > > > > 2.25.0 > > > > > > > _______________________________________________ > > > dri-devel mailing list > > > dri-devel@lists.freedesktop.org > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel