From patchwork Tue Sep 5 16:42:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9939327 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 A4EA5604D3 for ; Tue, 5 Sep 2017 16:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C8A289B4 for ; Tue, 5 Sep 2017 16:44:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C4E0289D0; Tue, 5 Sep 2017 16:44:30 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7825289B4 for ; Tue, 5 Sep 2017 16:44:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752420AbdIEQnJ (ORCPT ); Tue, 5 Sep 2017 12:43:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55784 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752363AbdIEQm6 (ORCPT ); Tue, 5 Sep 2017 12:42:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 982547F364; Tue, 5 Sep 2017 16:42:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 982547F364 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=hdegoede@redhat.com Received: from dhcp-45-79.space.revspace.nl.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9D6384D92; Tue, 5 Sep 2017 16:42:54 +0000 (UTC) From: Hans de Goede To: MyungJoo Ham , Chanwoo Choi , Guenter Roeck , Heikki Krogerus , Darren Hart , Andy Shevchenko , Peter Rosin , Mathias Nyman Cc: Hans de Goede , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, Kuppuswamy Sathyanarayanan , Sathyanarayanan Kuppuswamy Natarajan , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [PATCH v2 06/11] mux: Add Pericom PI3USB30532 Type-C mux driver Date: Tue, 5 Sep 2017 18:42:16 +0200 Message-Id: <20170905164221.11266-7-hdegoede@redhat.com> In-Reply-To: <20170905164221.11266-1-hdegoede@redhat.com> References: <20170905164221.11266-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Sep 2017 16:42:58 +0000 (UTC) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a driver for the Pericom PI3USB30532 Type-C cross switch / mux chip found on some devices with a Type-C port. Signed-off-by: Hans de Goede --- Changes in v2: -Adjust for new MUX_TYPEC_foo state defines -Add MAINTAINERS entry -Various code-style fixes --- MAINTAINERS | 5 +++ drivers/mux/Kconfig | 10 +++++ drivers/mux/Makefile | 2 + drivers/mux/pi3usb30532.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 drivers/mux/pi3usb30532.c diff --git a/MAINTAINERS b/MAINTAINERS index dfaed958db85..5527b0efcef3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8996,6 +8996,11 @@ M: Hans de Goede S: Maintained F: drivers/mix/intel-cht-usb-mux.c +MULTIPLEXER SUBSYSTEM PI3USB30532 DRIVER +M: Hans de Goede +S: Maintained +F: drivers/mix/pi3usb30532.c + MULTISOUND SOUND DRIVER M: Andrew Veliath S: Maintained diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig index 947cfd7af02a..1f6f017ee920 100644 --- a/drivers/mux/Kconfig +++ b/drivers/mux/Kconfig @@ -58,4 +58,14 @@ config MUX_MMIO To compile the driver as a module, choose M here: the module will be called mux-mmio. +config MUX_PI3USB30532 + tristate "Pericom PI3USB30532 Type-C cross switch driver" + depends on I2C + help + This driver adds support for the Pericom PI3USB30532 Type-C cross + switch / mux chip found on some devices with a Type-C port. + + To compile the driver as a module, choose M here: the module will + be called mux-pi3usb30532. + endmenu diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile index 6cf41be2754f..df381c219708 100644 --- a/drivers/mux/Makefile +++ b/drivers/mux/Makefile @@ -7,9 +7,11 @@ mux-adg792a-objs := adg792a.o mux-gpio-objs := gpio.o mux-intel-cht-usb-mux-objs := intel-cht-usb-mux.o mux-mmio-objs := mmio.o +mux-pi3usb30532-objs := pi3usb30532.o obj-$(CONFIG_MULTIPLEXER) += mux-core.o obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o obj-$(CONFIG_MUX_GPIO) += mux-gpio.o obj-$(CONFIG_MUX_INTEL_CHT_USB_MUX) += mux-intel-cht-usb-mux.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.o +obj-$(CONFIG_MUX_PI3USB30532) += mux-pi3usb30532.o diff --git a/drivers/mux/pi3usb30532.c b/drivers/mux/pi3usb30532.c new file mode 100644 index 000000000000..3d959e3ee8c6 --- /dev/null +++ b/drivers/mux/pi3usb30532.c @@ -0,0 +1,93 @@ +/* + * Pericom PI3USB30532 Type-C cross switch / mux driver + * + * Copyright (c) 2017 Hans de Goede + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation, or (at your option) + * any later version. + */ + +#include +#include +#include +#include +#include + +#define PI3USB30532_CONF 0x00 + +#define PI3USB30532_CONF_OPEN 0x00 +#define PI3USB30532_CONF_SWAP 0x01 +#define PI3USB30532_CONF_4LANE_DP 0x02 +#define PI3USB30532_CONF_USB3 0x04 +#define PI3USB30532_CONF_USB3_AND_2LANE_DP 0x06 + +static int pi3usb30532_set_mux(struct mux_control *mux, int state) +{ + struct i2c_client *i2c = to_i2c_client(mux->chip->dev.parent); + u8 conf = PI3USB30532_CONF_OPEN; + + if (state == MUX_IDLE_DISCONNECT) + return i2c_smbus_write_byte_data(i2c, PI3USB30532_CONF, conf); + + switch (state & ~MUX_TYPEC_POLARITY_INV) { + case MUX_TYPEC_DEVICE: + case MUX_TYPEC_HOST: + conf = PI3USB30532_CONF_USB3; + break; + case MUX_TYPEC_HOST_AND_DP_SRC: + conf = PI3USB30532_CONF_USB3_AND_2LANE_DP; + break; + case MUX_TYPEC_DP_SRC: + conf = PI3USB30532_CONF_4LANE_DP; + break; + } + + if (state & MUX_TYPEC_POLARITY_INV) + conf |= PI3USB30532_CONF_SWAP; + + return i2c_smbus_write_byte_data(i2c, PI3USB30532_CONF, conf); +} + +static const struct mux_control_ops pi3usb30532_ops = { + .set = pi3usb30532_set_mux, +}; + +static int pi3usb30532_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct mux_chip *mux_chip; + + mux_chip = devm_mux_chip_alloc(dev, 1, 0); + if (IS_ERR(mux_chip)) + return PTR_ERR(mux_chip); + + mux_chip->ops = &pi3usb30532_ops; + mux_chip->mux[0].idle_state = MUX_IDLE_DISCONNECT; + /* Keep initial state as is, for e.g. booting from an USB disk */ + mux_chip->mux[0].cached_state = MUX_IDLE_DISCONNECT; + mux_chip->mux[0].states = MUX_TYPEC_STATES; + + return devm_mux_chip_register(dev, mux_chip); +} + +static const struct i2c_device_id pi3usb30532_table[] = { + { "pi3usb30532" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, pi3usb30532_table); + +static struct i2c_driver pi3usb30532_driver = { + .driver = { + .name = "pi3usb30532", + }, + .probe_new = pi3usb30532_probe, + .id_table = pi3usb30532_table, +}; + +module_i2c_driver(pi3usb30532_driver); + +MODULE_AUTHOR("Hans de Goede "); +MODULE_DESCRIPTION("Pericom PI3USB30532 Type-C mux driver"); +MODULE_LICENSE("GPL");