Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbdIEHrR (ORCPT ); Tue, 5 Sep 2017 03:47:17 -0400 Received: from mail-eopbgr40109.outbound.protection.outlook.com ([40.107.4.109]:38517 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751138AbdIEHrK (ORCPT ); Tue, 5 Sep 2017 03:47:10 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Subject: Re: [PATCH 06/11] mux: Add Pericom PI3USB30532 Type-C mux driver From: Peter Rosin To: Hans de Goede , MyungJoo Ham , Chanwoo Choi , Guenter Roeck , Heikki Krogerus , Darren Hart , Andy Shevchenko , Mathias Nyman Cc: platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, Kuppuswamy Sathyanarayanan , Sathyanarayanan Kuppuswamy Natarajan , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org References: <20170901214845.7153-1-hdegoede@redhat.com> <20170901214845.7153-7-hdegoede@redhat.com> <600628b1-5555-1b96-743f-0593af5a6069@axentia.se> Organization: Axentia Technologies AB Message-ID: Date: Tue, 5 Sep 2017 09:46:58 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <600628b1-5555-1b96-743f-0593af5a6069@axentia.se> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [81.224.168.30] X-ClientProxiedBy: VI1PR08CA0116.eurprd08.prod.outlook.com (2603:10a6:800:d4::18) To DB6PR0202MB2552.eurprd02.prod.outlook.com (2603:10a6:4:1b::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f025636b-f758-4b09-1b75-08d4f4324dac X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(2017082002075)(300000503095)(300135400095)(201703131423075)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DB6PR0202MB2552; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2552;3:dBYp/0obHBQ2F585zDIeYw2on99VhkJ6RFuJrWDe4Hiqsr1/tyfZKVTRQl+1qslY+2fgPZTB6Yei9LL6kQlKZVhiZZ1DwxCrIYCVvXP/LGr+hUdjNWHt+I/uUiexVCFL6e60kLsnkp82oDrEzW5GZBKaHkGgeeL44pjhEfIt2Ij4wUgzPxf+j6VA03DYd9T6NH3kN+L5R/+Jo1z7xWYRs7rG20EI8Ktp3nDLfD9n+qsX+lTzNPY7QUXIYMjUDAwh;25:VjRTPMJbSioyPfsAu/Bvrrypu0+jv/OZ0frMUck88Z64n7vxW4BEQ9ARRXTpvqFOkEe4cSRGago7vTqdaB0FIaKpocdHbZAlQhasQgSztDbVGOVRiKuS87K4rCkBRGkSBC7xIzQa3rPeu0YneED97QSW2LrxbEF0NXyRXcQXlo9k3eXBlA5fkfm6ark7mNVsfEsS+9B765JYILdNmkwHi5sSc4+Y2NOhWALYG9DTSezF9uT6BdKZ0lk+PIOHai75sLgP4N9SxavC0l41tpNj5tgyB1A0x4wu49pZG/Lw8ZKD5DBAxalFXXNRHKCbiadaUN6Dk+Hzpr8oJTlbxHbtKQ==;31:Nq/YjVI/kBJKJ/t0CdPDu1qFQasXiXdK+irGi+ucuV0LBT87GHDD87Lq5jtXFUzDX2NrPYsaX5nmY5c6AF5EF2dhzZ52zNP9lCTVk6nSdlbgvIPBxpc7ObqjRq6yzwdRca0IppSddOcTdS/ZpRlobVZsBd2IUXuZCpNCyzp9PadQsr/tcoruCw8UqZTRPsd+5E9DXmcpADhRckYR2fztzNL9PX8m9C6idDnv6S3xAQk= X-MS-TrafficTypeDiagnostic: DB6PR0202MB2552: X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(2016111802025)(20161123560025)(20161123555025)(6072148)(6043046)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR0202MB2552;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR0202MB2552; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2552;4:sbXxXPQOOosEJzDazaPsph1P3v2lZ2NxNg91ExnzU7R++VKlRDSmqZwb1NAqmy/pzpnyQlcAM/uahSTqPtTqkQBFoKfe83s/ll06qN0VEZ2IpCekjD08FFIP6tIiH2Fq5LXIl1B1nkwXH1LTyAok3Jx0Zkz8aApOgbzUZ2SupwwPFgTeCfnTIXuxGIFV1vLHfVVYBjI6in8134nkk6ml45P/L90DieKuZdZjFbQQn2yCLj8yspbK1/OXI+PoH2K+ X-Forefront-PRVS: 0421BF7135 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(7370300001)(4630300001)(6009001)(6049001)(189002)(24454002)(377424004)(199003)(65806001)(76176999)(66066001)(8676002)(2906002)(81166006)(81156014)(229853002)(50986999)(54356999)(33646002)(478600001)(6486002)(54906002)(305945005)(7736002)(77096006)(53936002)(31686004)(74482002)(36756003)(23676002)(6246003)(65956001)(53546010)(68736007)(47776003)(101416001)(105586002)(106356001)(189998001)(42186005)(86362001)(3260700006)(7350300001)(25786009)(31696002)(97736004)(4326008)(3846002)(230700001)(65826007)(7416002)(64126003)(5660300001)(6666003)(4001350100001)(83506001)(117156002)(2950100002)(6116002)(50466002)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QKiGFW9GRLU7PGEh9N/Ofj6NPc5YnVY45R7lNPvm5zKPYXyW4b39LzW/q9Za3OStlnwqCSApPGP1fGW+gmIlPqJhy7IpvrvaUGyKhEwRhD7AiN+27uX2WCgDuR8L2bhgLfcZWEi52XhCFGiiJfN8QRHW8+KCE73XH9NcwysUAxWicIIyD9xw2gLX59NtsilIJnyns= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2017 07:47:03.3030 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0202MB2552 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5615 Lines: 181 On 2017-09-04 13:19, Peter Rosin wrote: > Hi! > > One comment inline... Oh, and one more small nit, I think you should do s/pi3usb30532_mux/pi3usb30532/g to shorten the identifiers a bit. The _mux suffix (or infix) is kind of selfevident from where the file lives anyway. pi3usb30532_mux_set_mux in particular feels a bit much.... Cheers, peda > On 2017-09-01 23:48, Hans de Goede wrote: >> 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 >> --- >> drivers/mux/Kconfig | 10 +++++ >> drivers/mux/Makefile | 2 + >> drivers/mux/pi3usb30532.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 109 insertions(+) >> create mode 100644 drivers/mux/pi3usb30532.c >> >> diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig >> index 17938918bf93..19a3065c34e6 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 a12e812c7966..7563dbf04593 100644 >> --- a/drivers/mux/Makefile >> +++ b/drivers/mux/Makefile >> @@ -7,9 +7,11 @@ mux-adg792a-objs := adg792a.o >> mux-gpio-objs := gpio.o >> mux-mmio-objs := mmio.o >> mux-intel_cht_usb_mux-objs := intel_cht_usb_mux.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_MMIO) += mux-mmio.o >> obj-$(CONFIG_MUX_CHT_USB_MUX) += mux-intel_cht_usb_mux.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..fa8abd851520 >> --- /dev/null >> +++ b/drivers/mux/pi3usb30532.c >> @@ -0,0 +1,97 @@ >> +/* >> + * 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 /* For the MUX_USB_* defines */ >> +#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 >> + >> +struct pi3usb30532_mux { >> + struct i2c_client *client; >> +}; >> + >> +static int pi3usb30532_mux_set_mux(struct mux_control *mux_ctrl, int state) >> +{ >> + struct pi3usb30532_mux *mux = mux_chip_priv(mux_ctrl->chip); > > The "mux" variable name is used for the mux_control in other drivers, and > I don't think the private data is needed. Like so: > > static int pi3usb30532_mux_set_mux(struct mux_control *mux, int state) > { > struct i2c_client *i2c = to_i2c_client(mux->chip->dev.parent); > > ... > > Cheers, > Peter > >> + u8 conf = PI3USB30532_CONF_OPEN; >> + >> + switch (state & ~MUX_USB_POLARITY_INV) { >> + case MUX_USB_NONE: >> + conf = PI3USB30532_CONF_OPEN; >> + break; >> + case MUX_USB_DEVICE: >> + case MUX_USB_HOST: >> + conf = PI3USB30532_CONF_USB3; >> + break; >> + case MUX_USB_HOST_AND_DP_SRC: >> + conf = PI3USB30532_CONF_USB3_AND_2LANE_DP; >> + break; >> + case MUX_USB_DP_SRC: >> + conf = PI3USB30532_CONF_4LANE_DP; >> + break; >> + } >> + >> + if (state & MUX_USB_POLARITY_INV) >> + conf |= PI3USB30532_CONF_SWAP; >> + >> + return i2c_smbus_write_byte_data(mux->client, PI3USB30532_CONF, conf); >> +} >> + >> +static const struct mux_control_ops pi3usb30532_mux_ops = { >> + .set = pi3usb30532_mux_set_mux, >> +}; >> + >> +static int pi3usb30532_mux_probe(struct i2c_client *client) >> +{ >> + struct device *dev = &client->dev; >> + struct pi3usb30532_mux *mux; >> + struct mux_chip *mux_chip; >> + >> + mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux)); >> + if (IS_ERR(mux_chip)) >> + return PTR_ERR(mux_chip); >> + >> + mux_chip->ops = &pi3usb30532_mux_ops; >> + mux_chip->mux[0].states = MUX_USB_STATES; >> + mux = mux_chip_priv(mux_chip); >> + mux->client = client; >> + >> + return devm_mux_chip_register(dev, mux_chip); >> +} >> + >> +static const struct i2c_device_id pi3usb30532_mux_table[] = { >> + { "pi3usb30532" }, >> + { } >> +}; >> +MODULE_DEVICE_TABLE(i2c, pi3usb30532_mux_table); >> + >> +static struct i2c_driver pi3usb30532_mux_driver = { >> + .driver = { >> + .name = "pi3usb30532", >> + }, >> + .probe_new = pi3usb30532_mux_probe, >> + .id_table = pi3usb30532_mux_table, >> +}; >> + >> +module_i2c_driver(pi3usb30532_mux_driver); >> + >> +MODULE_AUTHOR("Hans de Goede "); >> +MODULE_DESCRIPTION("Pericom PI3USB30532 Type-C mux driver"); >> +MODULE_LICENSE("GPL"); >> >