From patchwork Mon Oct 16 15:31:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 10008955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7D0C601E7 for ; Mon, 16 Oct 2017 15:32:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7CC22856B for ; Mon, 16 Oct 2017 15:32:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAFB42860C; Mon, 16 Oct 2017 15:32:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 24FFF2856B for ; Mon, 16 Oct 2017 15:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CsSuIZvFAppI+d9I7JP6uDn5O7AOcHuPOv1oQh/Chf8=; b=pqvXNZAEUp6WtIdWjeHc5dVAan /ENMoLNhKq7K6taoo2X0dcVTgQXGsD8YMXjoGB9W3FEsZ+SHOUEvb07acNPX08qyiOMoEpVOMhKgw AFgjAqS0hyOZNy4nRN13IxIQ624o8CePxstm7F8bMMdL3PS4YwcVvceRk4Ot8P3czAo0u4OEpTiyF oxKx2OMhUK94EfJQkBhzlz3JRPzNgPCU9rcnv3fprw3X/hFtEfh0V6tQHkaWXYioMylClt+vSWwPx XBmWVHFNwzonuHoBc4QEMxPQA21KvBQhQom98Har2zGesRSodyk3VeEgChhKDit4BVdFadTqcMWk0 i1hUWdTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e47Nq-0004Hc-Qu; Mon, 16 Oct 2017 15:32:50 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e47NG-0003bm-LG; Mon, 16 Oct 2017 15:32:27 +0000 Received: by mail-wm0-x244.google.com with SMTP id q132so4594751wmd.2; Mon, 16 Oct 2017 08:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=LtCoBYNtgmfp1TRu8/7XiCx/CDGgyKZ0+lEAuPx19cI=; b=V3MDPkkrWPBHTpfw3+BwpzZ72IEZC/YpiBQHV+7KhDY8N81oJ4HIUYoUiiat3x07QR rdsciGCweVAdLFkk39hf0BeQFHgLi/I+CUdcGYbNtE5TLfMWOcHdfPFu6+QssPV7iwgN xcHgdm3wZh16VsHSxsfFHR/0MQj8Z/YU9WxzzsWKFdYdbxPMZGDBC7KM7XzvXQ2L9fip l/rsIWlGDlu+uO6GGQa1/lysbn0d8TexIauII9qgtQcFIkODowpUKbL/iXCD1BJ0Ln/2 PLRq8HIVVeLZPGcWxAdjOJ0ibC5Sr8TECMIEpFswrr7FjixuAzYs0zYCYQlJBUHA2JtK INJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=LtCoBYNtgmfp1TRu8/7XiCx/CDGgyKZ0+lEAuPx19cI=; b=qoxzV0y2moM4UArRCjS2Z/gMaf82LC7g+E4WWftrroLklPo9amZ75PJ23XXr8Rc8AB Ossb3Sr+dGW+obrqNmq41lHOlq8fVH+jXLvvzNU3UJySPPG+lGXn1QqK3DHxTGWC0BAn /R2ORBJ1PDwuO8ErjyxD2+djlANm7IMQ8wDjcpgEXJbmBzkeiEi7p6vgq5g0OrMvkQWS KgxDHl8RsB4i7m/7ahOV3Tx7e/lKnfpNUTAQXnDn8EmdV6JOGhssDExc6jFYZk4Ong0T zRbPnAuDT7C4pSIYYwHzPZLh1ZfeiGK///JorkjCy460M+xn3mxchq8BY9gcFCA/eYDp Q2Mg== X-Gm-Message-State: AMCzsaUhYAxey+DpVMHUtjtqtGT+N3ZJzf0spmDpByaGesgpLGUT+OtY P7N+eqexcTEMa+Vu/RqJwOoQ6iI= X-Google-Smtp-Source: ABhQp+TdlGbc1SX/KZ3QZd1sLht0SbLJhAf/Xky/qlQqzi23f2HizoM/ZefEMV5T7XcJ+c5KTv7TfA== X-Received: by 10.28.8.212 with SMTP id 203mr1177457wmi.43.1508167916938; Mon, 16 Oct 2017 08:31:56 -0700 (PDT) Received: from groucho.site (ipbcc0ce42.dynamic.kabel-deutschland.de. [188.192.206.66]) by smtp.gmail.com with ESMTPSA id v2sm6897751wmf.40.2017.10.16.08.31.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Oct 2017 08:31:56 -0700 (PDT) From: Ulrich Hecht To: linux-mediatek@lists.infradead.org Subject: [RFC v2 4/8] drm/bridge: Analogix ANX7688 HDMI -> DP bridge driver Date: Mon, 16 Oct 2017 17:31:36 +0200 Message-Id: <1508167900-27415-5-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508167900-27415-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1508167900-27415-1-git-send-email-ulrich.hecht+renesas@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171016_083215_165791_B65F0F9B X-CRM114-Status: GOOD ( 22.40 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jacopo@jmondi.org, magnus.damm@gmail.com, dri-devel@lists.freedesktop.org, Ulrich Hecht , laurent.pinchart@ideasonboard.com, ck.hu@mediatek.com, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Ported from chromeos-3.18. Signed-off-by: Ulrich Hecht --- drivers/gpu/drm/bridge/Kconfig | 9 ++ drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/analogix-anx7688.c | 233 ++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 drivers/gpu/drm/bridge/analogix-anx7688.c diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index a1c0d95..712ac0a 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -38,6 +38,15 @@ config DRM_PARADE_PS8640 The PS8640 is a high-performance and low-power MIPI DSI to eDP converter +config DRM_ANALOGIX_ANX7688 + tristate "Analogix ANX7688 bridge" + depends on DRM + select DRM_KMS_HELPER + ---help--- + ANX7688 is a transmitter to support DisplayPort over USB-C for + smartphone and tablets. + This driver only supports the HDMI to DP component of the chip. + config DRM_ANALOGIX_ANX78XX tristate "Analogix ANX78XX bridge" select DRM_KMS_HELPER diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile index 6be8a9d..9cbf788 100644 --- a/drivers/gpu/drm/bridge/Makefile +++ b/drivers/gpu/drm/bridge/Makefile @@ -1,6 +1,7 @@ ccflags-y := -Iinclude/drm obj-$(CONFIG_DRM_PARADE_PS8640) += parade-ps8640.o +obj-$(CONFIG_DRM_ANALOGIX_ANX7688) += analogix-anx7688.o obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o obj-$(CONFIG_DRM_GENERIC_GPIO_MUX) += generic-gpio-mux.o obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o diff --git a/drivers/gpu/drm/bridge/analogix-anx7688.c b/drivers/gpu/drm/bridge/analogix-anx7688.c new file mode 100644 index 0000000..cc995c8 --- /dev/null +++ b/drivers/gpu/drm/bridge/analogix-anx7688.c @@ -0,0 +1,233 @@ +/* + * ANX7688 HDMI->DP bridge driver + * + * Copyright (C) 2016 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#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; + + bool filter; +}; + +static int anx7688_read(struct i2c_client *client, u8 reg, u8 *data, + u16 data_len) +{ + int ret; + struct i2c_msg msgs[] = { + { + .addr = client->addr, + .flags = 0, + .len = 1, + .buf = ®, + }, + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = data_len, + .buf = data, + } + }; + + ret = i2c_transfer(client->adapter, msgs, 2); + + if (ret == 2) + return 0; + if (ret < 0) + return ret; + else + return -EIO; +} + +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); + u8 regs[2]; + u8 dpbw, lanecount; + int totalbw, requiredbw; + int ret; + + if (!anx7688->filter) + return true; + + /* Read both regs 0x85 (bandwidth) and 0x86 (lane count). */ + ret = anx7688_read(anx7688->client, 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 int anx7688_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct anx7688 *anx7688; + int ret; + u8 buffer[4]; + u16 vendor, device, fwversion; + + anx7688 = devm_kzalloc(&client->dev, sizeof(*anx7688), GFP_KERNEL); + if (!anx7688) + return -ENOMEM; + +#if IS_ENABLED(CONFIG_OF) + anx7688->bridge.of_node = client->dev.of_node; +#endif + + anx7688->client = client; + i2c_set_clientdata(client, anx7688); + + /* Read both vendor and device id (4 bytes). */ + ret = anx7688_read(client, VENDOR_ID_REG, buffer, 4); + if (ret) { + dev_err(&client->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(&client->dev, + "Invalid vendor/device id %04x/%04x\n", + vendor, device); + return -ENODEV; + } + + ret = anx7688_read(client, 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(&client->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(&client->dev, + "Old ANX7688 FW version (%02x.%02x), not filtering\n", + buffer[0], buffer[1]); + } + + anx7688->bridge.funcs = &anx7688_bridge_funcs; + ret = drm_bridge_add(&anx7688->bridge); + if (ret < 0) { + dev_err(&client->dev, "Failed to add drm bridge\n"); + return ret; + } + + 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 i2c_device_id anx7688_id[] = { + { "anx7688", 0 }, + { /* sentinel */ } +}; + +MODULE_DEVICE_TABLE(i2c, anx7688_id); + +#if IS_ENABLED(CONFIG_OF) +static const struct of_device_id anx7688_match_table[] = { + { .compatible = "analogix,anx7688", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, anx7688_match_table); +#endif + +static struct i2c_driver anx7688_driver = { + .driver = { + .name = "anx7688", + .of_match_table = of_match_ptr(anx7688_match_table), + }, + .probe = anx7688_i2c_probe, + .remove = anx7688_i2c_remove, + .id_table = anx7688_id, +}; + +module_i2c_driver(anx7688_driver); + +MODULE_DESCRIPTION("ANX7688 SlimPort Transmitter driver"); +MODULE_AUTHOR("Nicolas Boichat "); +MODULE_LICENSE("GPL v2");