Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp318223ybh; Wed, 18 Mar 2020 00:08:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsIvsYLwn6glEdoo5FrWiyIHo4gv7z/D5LPH14Ddw6kJZp/gv/MEzjYf102jR0rf301YUnx X-Received: by 2002:aca:fd0d:: with SMTP id b13mr2104136oii.179.1584515292698; Wed, 18 Mar 2020 00:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584515292; cv=none; d=google.com; s=arc-20160816; b=i2TvXcAAMDin7F0I0c7kgp4yMTuZhdHokazLIu5Na/e2gh5oJ7Nh9b5SQghAD6vGsg RJy9Ksn+yGnSpxFk2xgbnvCq4sTqsY/V7X8mOWYEhgE5RprEd3r+LU76pOBeu7x8Z/Ke jKOVvH9IXSeXUNW+9P75ApSi2fwd2wAIzt/DvtcYV3kAwV0k9bICPDcZ+KrWp3GmCm1Q BZtWsYWyAU84A+o8+zEqSQF5QweeyqYBa9KotLujd1MGWizhBDYJG/t1mtSl7OTuOGF1 uPL/DRlBNaIF0DMP47QeujaZ5DdGbRt/pyla0msF3lokJPVSTijONSePF1eNbxLTBu3G ZCeQ== 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=5AJQY/MQlaStSlcCBX66KchdhQ5TLLYy1BNWXh4lHuI=; b=YV1Qazx8I3QcJ7J74noLOuogouJ4OGslt6uvLb8Riif32TK5wMXSnPmkLvwp82DJm6 lZGdO7N/LAUDaLqqT/KBiFQp7LBdDdl76INoMx4IdHKdcf6SkOozqeYfEh9r5IEok1QY q14r83cES+8DCcwCXZjc1YHvt0n54k0sZ/ZcxVvnblrb50lw/LvfIaAXvTPRCJgDXcuk vTDuEYc0rgHNtDmopFjoXFevGy6hOngxMk4t2fnB8v0zR16WiKJKKB0MIoz7CFpuTlPl dfcn2QblET2Ae+W1bX0d/7sVhebTb+zXimMiQU3p6PCK71dLaYofnf2rVte55te+m7tH Ay2A== 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 j1si2988705otp.318.2020.03.18.00.07.59; Wed, 18 Mar 2020 00:08:12 -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 S1727240AbgCRHHm (ORCPT + 99 others); Wed, 18 Mar 2020 03:07:42 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40254 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbgCRHHl (ORCPT ); Wed, 18 Mar 2020 03:07:41 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 3DB422924A1 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, Lee Jones Subject: [PATCH v4 2/4] mfd: anx7688: Add driver for Analogix ANX7688 chip Date: Wed, 18 Mar 2020 08:07:28 +0100 Message-Id: <20200318070730.4012371-2-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 The ANX7688 chip is a Type-C Port Controller, HDMI to DP converter and USB-C mux between USB 3.0 lanes and the DP output. For our use case a big part of the chip, like power supplies, control gpios and usb-c parts are managed by an Embedded Controller, hence, this is its simplest form of it. Other users of this chip might introduce new functionalities as per their requirements. Signed-off-by: Enric Balletbo i Serra --- Changes in v4: None Changes in v3: None Changes in v2: None drivers/mfd/Kconfig | 11 +++++ drivers/mfd/Makefile | 1 + drivers/mfd/anx7688.c | 87 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/anx7688.h | 39 +++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 drivers/mfd/anx7688.c create mode 100644 include/linux/mfd/anx7688.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 2b203290e7b9..ac4ef4f20518 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -51,6 +51,17 @@ config MFD_ACT8945A linear regulators, along with a complete ActivePath battery charger. +config MFD_ANX7688 + tristate "Analogix ANX7688" + select MFD_CORE + select REGMAP_I2C + depends on I2C && OF + help + Support the ANX7688 from Analogix. This device features a USB + Type-C Port Controller (TCPC), and HDMI to DP converter, and + USB-C mux between USB 3.0 lanes and the DP output of the + embedded converter. + config MFD_SUN4I_GPADC tristate "Allwinner sunxi platforms' GPADC MFD driver" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index b83f172545e1..4c6ca8a7d260 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o obj-$(CONFIG_MFD_ACT8945A) += act8945a.o obj-$(CONFIG_MFD_SM501) += sm501.o +obj-$(CONFIG_MFD_ANX7688) += anx7688.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o diff --git a/drivers/mfd/anx7688.c b/drivers/mfd/anx7688.c new file mode 100644 index 000000000000..fab7ed410c46 --- /dev/null +++ b/drivers/mfd/anx7688.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * HDMI to USB Type-C Bridge and Port Controller with MUX + * + * Copyright 2020 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include + +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; + u8 buffer[4]; + int ret; + + anx7688 = devm_kzalloc(dev, sizeof(*anx7688), GFP_KERNEL); + if (!anx7688) + return -ENOMEM; + + 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, ANX7688_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 != ANX7688_VENDOR_ID || device != ANX7688_DEVICE_ID) { + dev_err(dev, "Invalid vendor/device id %04x/%04x\n", + vendor, device); + return -ENODEV; + } + + ret = regmap_bulk_read(anx7688->regmap, ANX7688_FW_VERSION_REG, + buffer, 2); + if (ret) { + dev_err(&client->dev, "Failed to read firmware version\n"); + return ret; + } + + anx7688->fw_version = (u16)buffer[0] << 8 | buffer[1]; + dev_info(dev, "ANX7688 firwmare version 0x%04x\n", + anx7688->fw_version); + + return devm_of_platform_populate(dev); +} + +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, + .driver = { + .name = "anx7688", + .of_match_table = anx7688_match_table, + }, +}; + +module_i2c_driver(anx7688_driver); + +MODULE_DESCRIPTION("HDMI to USB Type-C Bridge and Port Controller with MUX driver"); +MODULE_AUTHOR("Nicolas Boichat "); +MODULE_AUTHOR("Enric Balletbo i Serra "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/anx7688.h b/include/linux/mfd/anx7688.h new file mode 100644 index 000000000000..f2760856f045 --- /dev/null +++ b/include/linux/mfd/anx7688.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * HDMI to USB Type-C Bridge and Port Controller with MUX + * + * Copyright 2020 Google LLC + */ +#ifndef __LINUX_MFD_ANX7688_H +#define __LINUX_MFD_ANX7688_H + +#include + +/* Register addresses */ +#define ANX7688_VENDOR_ID_REG 0x00 +#define ANX7688_DEVICE_ID_REG 0x02 + +#define ANX7688_FW_VERSION_REG 0x80 + +#define ANX7688_DP_BANDWIDTH_REG 0x85 +#define ANX7688_DP_LANE_COUNT_REG 0x86 + +#define ANX7688_VENDOR_ID 0x1f29 +#define ANX7688_DEVICE_ID 0x7688 + +/* First supported firmware version (0.85) */ +#define ANX7688_MINIMUM_FW_VERSION 0x0085 + +struct gpio_desc; +struct i2c_client; +struct regulator; +struct regmap; + +struct anx7688 { + struct i2c_client *client; + struct regmap *regmap; + + u16 fw_version; +}; + +#endif /* __LINUX_MFD_ANX7688_H */ -- 2.25.1