Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752775AbdDFUEM (ORCPT ); Thu, 6 Apr 2017 16:04:12 -0400 Received: from mail-db5eur01on0113.outbound.protection.outlook.com ([104.47.2.113]:56265 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751593AbdDFUEG (ORCPT ); Thu, 6 Apr 2017 16:04:06 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=axentia.se; Subject: Re: [PATCH v4 2/2] i2c: mux: ltc4306: LTC4306 and LTC4305 I2C multiplexer/switch To: , , , , References: <1491397671-14675-1-git-send-email-michael.hennerich@analog.com> <1491397671-14675-2-git-send-email-michael.hennerich@analog.com> <376f970f-9e0f-1d44-3813-93691c849b83@analog.com> CC: , , , From: Peter Rosin Organization: Axentia Technologies AB Message-ID: <67c557ae-f094-9fe4-d2f3-d7a2af2df9ca@axentia.se> Date: Thu, 6 Apr 2017 22:03:54 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <376f970f-9e0f-1d44-3813-93691c849b83@analog.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [81.224.171.159] X-ClientProxiedBy: DB6P195CA0002.EURP195.PROD.OUTLOOK.COM (10.171.120.140) To AM5PR0202MB2546.eurprd02.prod.outlook.com (10.173.89.7) X-MS-Office365-Filtering-Correlation-Id: f338e94c-e3b3-4a15-68ae-08d47d281180 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075);SRVR:AM5PR0202MB2546; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2546;3:5fGbnk+KA1YM8r98BWOaFJhb0G/nLtQPWMQkxv7+xacIbk/De1emt01+JYED9DBKoMjoDs3yOk6awbRmKRUjGTBgFhal9/8maJvYhU9r7YeHxGT6AJeYt1stY6WwPujsFarA5qRQQ29G1eZ44GCZlRGdvZPMS87oCWsbVLPjvxoS9hF99EEr0e6xQJ2KEB95hWp7V/+1/6c1satZK7jSZFutyUvuHqeLvv5NCm/6yBpZy0mVmRTNV6jf7vzkDZikS6fayKnudwXyHTdp1xUdqzW25yciI1XAiJRWMHiMw3SrH61f6zWsxuWBK7ZE8JHm;25:is5b5YCMZyOQKrewb654UESBj9qUbWAPMNW8zpYRjrJpm96iefMVKCxiJknjHbU1+kfv7VpppF/3XnpXGIPvIJqszCLNa5iIte31P0S6i5c4KglC336vGMuOhzVRl5VMg8RxkU6Hrp0R4mxomQE+dFomz2dFQLBaeiKLg1UHrSXoCOiFq4Vk+vYTHKi99IBV0tkAcnw7jskT2WTKfuN+iyrdSMl47Hz8vLH3rwXAMZyYNKcstl455MY56MeK7aSzcnaNoRuta9tYDbBG2l1MYQrlqe1P3eFytM4yS1Io5y4Xv+CbaHKjPvdz7bQ+hSA+2aOB/WG0qdGtUNTMzgmBgWvGXLE3wxOSKP54LbBV8ZYztwSi0r0O+PEdcVEALr9NzxFAB4qbtqK5PB8lQeQDnrFavSmZPMka6io3Tj+75HLM034GtclKwCzvqkT0x5ZtyEE19SOnS7120HINUOfGmw== X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2546;31:LnZ9JrdOqRoo8cqVQILa+JYmMRjZ3Xol1q89q7bOsd2LxdbZ22FcORKElyXln32IzXmogdOp0N4CHbLl3OPAnIsh4PLCks+gpaxz0iO2ti8BE/aCtZ8aQ7g/4NseRxEONg4R7UsjEHm+TITz2F3aYMwrS3pXw5RTSS3LhFKLU9S9emqndF2pTR7nqn6El6zwMe+elh8LtnsUbjjA+Zz1Ja7L0VTSKMSTL4FeNNvBpF/JgoqD5G81XmglarnFK1hxODRR1cokydW2VNRQCAVAAw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(232431446821674)(788757137089)(211171220733660)(170811661138872); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(2016111802025)(20161123564025)(20161123562025)(20161123560025)(6043046)(6072148);SRVR:AM5PR0202MB2546;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0202MB2546; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2546;4:2tOpXKFERLAPv0cR03wmG6JDbRkbeLjNnHBthWpyiVODyHmd/EGVsiloxvnIvuUUbb0zWTA7LiF2ke9SbNLPmxsUG0pWkRPrfsLSlgQDZoh/hTDXoujh95ds4wvQrDP+RdApTh5bZOE/JEBPzpYqYmCw78AbEG4M9gRAHIiMz01jD03qXMG7KTCKi3PuIJTCwnfTWuDCNkdgjCIda8PL03LFYkiKX2rS27f6Wz5YHp7PLIo0jtaMRWbImLcWEczzXSr4ITwfBhuPkVjeCaW5eTPSUSSrHrCfUV5cF85zt4k3S5vKePc00d+RiZg3p84FXb+VkLpagXYhffz4yHJ5kPo8jEto8Bm2eKJlyiYbmgRGnZtMDXE7WXzdYCBvHcaTPt4S5zOJt2AHvFkTbKSMH+AGOkTavGKcXwDUmTLcYlSt56vWrkd+epITcsaZXc+OgDNC/V/94lblq9pBnVwclDTdXhFW9fNcAUj1J/n31AI9pyP9Rc/qFUzTxtWLV9uCjr5Ox2OmtOhMPi5Q+9Uw4XUZieh0k1P9jSSxdlYi8dioSvoNxGJL4DadTn2Yq6edWVnYf4DQsdb8wndRvcrAPrQSRoRqn4iAirdv0BGrKrK+I3nXdK67otqKjZjiN8QABtMgqokXT4VxFOKCL6Ips4cs+5YHu1xMJEcCPD+y3CSb2de3xJ5IjrhA6e7obcrYryE08tbFdLTlAyQSdgM2KKtufnECD0nCJRL1RkJ103GRbeeWPA8JSBjDhWzoJAde8xsQmr3WeMI+/Zrjzz7sPKPYN+9GuBveJEjrjwjwaM4wOhIi/VRY2seg2T2AJDXFFhDC2Z5LUT8U+H9BtAOsmnVe2ZLrcKqao/QvKvu+YB44ArAm6Cf24zeBqMZZNVM5S4nwX8upnd9SixCJPl0hJ/2voHiqWk3ix9VQPf3G37OaCd2QMbbLMX6hdGH3B3I2 X-Forefront-PRVS: 02698DF457 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(39410400002)(39400400002)(39830400002)(39450400003)(377424004)(52314003)(24454002)(74482002)(77096006)(6666003)(6486002)(54906002)(81166006)(2906002)(4326008)(53546009)(31686004)(42186005)(6306002)(25786009)(31696002)(230700001)(53936002)(229853002)(93886004)(90366009)(38730400002)(5660300001)(3260700006)(117156002)(2950100002)(33646002)(86362001)(23746002)(8676002)(4001350100001)(83506001)(50986999)(305945005)(64126003)(50466002)(189998001)(65956001)(47776003)(66066001)(3846002)(36756003)(1720100001)(6116002)(7736002)(54356999)(966004)(76176999)(42262002)(562404015);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0202MB2546;H:[192.168.0.125];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;AM5PR0202MB2546;23:EbEYS0cnunaWXeORibFILGm6DDe2+Riuxrh?= =?Windows-1252?Q?OjQoqAAEJbTjtfE+D0Bke70WRHy4v4m84HsVyWVR26eZitfrNvYjRDz8?= =?Windows-1252?Q?Jt+QN97A7GhcU0MnxMtNND8mJMZKNnnSzAhth8OHKF7ck36DcBdgCw6B?= =?Windows-1252?Q?18/vbkX5JSK3Jev4S1Sa0u/6T1N5Gz+L7yDehXkkzFWjZC0roCoQaoO4?= =?Windows-1252?Q?o9YNDr2QUMJB7eTIAGMFkKUWK/5lhA6DvGrDyf1RSpKJ2nnYJLWav11B?= =?Windows-1252?Q?5Vf0C24h9DKTDEJVq5CG0iBLivF/4FbfYXjlCJGD9Q/bNoc7fbqX+LnI?= =?Windows-1252?Q?MGbbmMDKF2s9PdiD69UJysNu/8Wo9ufbfg2AbBn4noy3EyvSpym1i6kK?= =?Windows-1252?Q?n6tYeCIHRfKIouX1kPFDaHc5J6F3C8MeNJHLcrhzKb+FgaL5nVnxsb6m?= =?Windows-1252?Q?HOZUjsDSSUnp9jo5nGM8mk+ukOmiiG0UVibXZ0yXyM6l+dMIcWFrrN9S?= =?Windows-1252?Q?DNl9hEL+jIh7UuP/6iu88eQmAQVQbQRMi6Tz0BiFW39Ve1f/99adEXGF?= =?Windows-1252?Q?mJ9YKNw6DJMpA5pKhGaXsVWDCnqbbyh3kpHU9MTFlE5REiOPwNyuMGje?= =?Windows-1252?Q?VRndfVmKyvTozDEfHgTUm+9AtsnWX9Ox+ZXUAl5A7VxSmyeNvnHq5VVB?= =?Windows-1252?Q?nm/Xa2vSA6ZJDyHlmK5PpKUh8WbAUsFozWQvPWajqLsppBotCjMQ88uI?= =?Windows-1252?Q?r8tmh1cf8S++rYvWjcNVSwewM9Mwz/33OOtahamVbH/qlxGtGbezgLtS?= =?Windows-1252?Q?sucACpDAHFytRRNEuZhr1AKcvJIruNkfq/Z3/5CtvMiOYXJ/80Ebaynk?= =?Windows-1252?Q?9yCUBsGfUZNbrJ4ZwJH+3wlaw1R2rIif9b6H0YLVZRoP+dgDwET6kt0D?= =?Windows-1252?Q?EyOJAZL6LIhzTbFqhlDBwCABf5UurZWBiSe2JWtW0ITYpJxFdCk7Oegb?= =?Windows-1252?Q?29YwsLDJ9JusNOWhgkUBjrTmryieodcFanmEsItEtpDn39MkQ33HN69a?= =?Windows-1252?Q?rFbTtmyWbXfxZPZTF9SDQvcW/r+iqkQXUFaihNTTiTAejL7CyNUHGTnq?= =?Windows-1252?Q?LiPHBZ6iqWrpmBCYioK0ibI0siNaOf83YFV4JW++rNCY2vERcjfXnaeX?= =?Windows-1252?Q?VexdEFCQWNWbIR7pu0prNp0GJFRhCAHMg8jrXz0qGJZxYcYuZvUiOJ6B?= =?Windows-1252?Q?CoU9jUTN9vDkGnMOXekKmvqTi23UPfWOMghrUkI0Bv9SgF6I7dAyQNXm?= =?Windows-1252?Q?Whm+7DwCqaCwsl1eBC9bmxvOwddQwOR25IkoaQRH+FrWuDOsngRbBBVv?= =?Windows-1252?Q?I5/vNdkYKvZ1ntE+sD1bPD3k4u5WVkRk1Hvg6CavBARjBcIo2aPdgsHS?= =?Windows-1252?Q?Ew4VMXyrU7XfEpieSs5X4vk87shQi3qbOJXCSe9ZgrO/0tgQerz/LY8j?= =?Windows-1252?Q?tBf8mqpaaYWhUh16+9NzJViEgcSs9S7G18L7kgxTNxfED49FFlw=3D?= =?Windows-1252?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2546;6:mr453bzWAnJSlpG9imdbA99eJ9rXMG/b9tZVrWdP/hvRHBX+6YGiuwFE9kxbNHHjHe4q9QGWW03jHNuNRL1zvzZONW/LAZYXF2lHUW0HXd5a2WQmraxrgtvrukmpaIrinYxIrrhwwJW5VIBowN7dx2lbaejIXm1+PFUJP8vMVffl3Gxmm8wLUPNsenDtKyorcRUckXz1jMW1I9Mppke1AHCntNOY2amqtK83IRaY8qvj0rkgo/EtYWR49oo79s8v1guhHzGvkNmKBgI7O24cZBYL49P7ng8V1foUgM2zgOfzIHaDwef3zbYkx1iPH2z/pFAkRx5fW30xxkLyrsalwZ5HOFjVZ/cG+xl8I1hS2tNwkcpXl5UQB6factFppaKxtVUfDXJmux4ho/uQtmo4iA==;5:CCWVU4vJf5rcXubTxdci0WlSMKee9XI0pqQutx86ILOCLMaWpFAH1SUIX3rmF/yEzTbu8+vVVvuvr53ae69b2grvdfIDzvNy+snTGPPlmj6obb3sIR9h0Y+AgmfThOPkABlio3BSvu9bEHwG8I3bkQ==;24:MPrFCtxExhCYVGm195WbGJGuZuvFIf8zb1so5fajF12MSQi94fZ9iBOVbR5QW32PmmoMBBCz+2dxeyW6bF1YiZkzAPxCTej3y9BIpnXKPgE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2546;7:zr/Mn0CzAunhnL8agL7ufMJgxqoyWUj8QLmuft02wh9LWaTxin91qPShHHxlsSbKOWJfru0npGPzsySkO2RuVDwKu7QSR2YVvA0D9+RV/QtN2xBsx8JW1EvdN09mIwlnMMiUJ2DwZEbF67YFlLlQ0a20sG9XmXyHAlYP07gFxD1bGyfh+ie46Gu+ud1juu/spjYg3TSI6aqVToxbOSZZKw+TlMahIdh5JjjDH7Cp1Gscf1/3go6V1fkrignqCMct+d/NY9mdgnnZ7rFMIf6QtCUsjVrNvffZYgDW5L5s1kyEa4zY6eVE2Mdpk4LxshhomrGl4FuFIOEGdruD+Mzp0g== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2017 20:03:59.0776 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0202MB2546 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 16706 Lines: 540 On 2017-04-06 13:31, Michael Hennerich wrote: > On 06.04.2017 10:39, Peter Rosin wrote: >> Hi Michael, >> >> I would still like to hear from someone with more gpio experience. > > I'll ping Linus. > >> >> Anyway, from my point of view, there's just a few minor things left, >> with comments inline as usual. >> >> Thanks for you patience! s/you/your/ > > Thanks for review. > >> >> Cheers, >> peda >> >> On 2017-04-05 15:07, michael.hennerich@analog.com wrote: >>> From: Michael Hennerich >>> >>> This patch adds support for the Analog Devices / Linear Technology >>> LTC4306 and LTC4305 4/2 Channel I2C Bus Multiplexer/Switches. >>> The LTC4306 optionally provides two general purpose input/output pins >>> (GPIOs) that can be configured as logic inputs, opendrain outputs or >>> push-pull outputs via the generic GPIOLIB framework. >>> >>> Signed-off-by: Michael Hennerich >>> >>> --- >>> >>> Changes since v1: >>> >>> - Sort makefile entries >>> - Sort driver includes >>> - Use proper defines >>> - Miscellaneous coding style fixups >>> - Rename mux select callback >>> - Revise i2c-mux-idle-disconnect handling >>> - Add ENABLE GPIO handling on error and device removal. >>> - Remove surplus of_match_device call. >>> >>> Changes since v2: >>> >>> - Stop double error reporting (i2c_mux_add_adapter) >>> - Change subject >>> - Split dt bindings to separate patch >>> >>> Changes since v3: >>> >>> - Change subject and add spaces >>> - Convert to I2C_MUX_LOCKED >>> - Convert to regmap >>> - Remove local register cache >>> - Restore previous ENABLE GPIO handling >>> - Initially pulse ENABLE low >>> - Eliminate i2c client struct in driver state structure >>> - Simplify error return path >>> - Misc minor cleanups >>> --- >>> MAINTAINERS | 8 + >>> drivers/i2c/muxes/Kconfig | 11 ++ >>> drivers/i2c/muxes/Makefile | 1 + >>> drivers/i2c/muxes/i2c-mux-ltc4306.c | 310 ++++++++++++++++++++++++++++++++++++ >>> 4 files changed, 330 insertions(+) >>> create mode 100644 drivers/i2c/muxes/i2c-mux-ltc4306.c >>> >>> diff --git a/MAINTAINERS b/MAINTAINERS >>> index c776906..9a27a19 100644 >>> --- a/MAINTAINERS >>> +++ b/MAINTAINERS >>> @@ -7698,6 +7698,14 @@ S: Maintained >>> F: Documentation/hwmon/ltc4261 >>> F: drivers/hwmon/ltc4261.c >>> >>> +LTC4306 I2C MULTIPLEXER DRIVER >>> +M: Michael Hennerich >>> +W: http://ez.analog.com/community/linux-device-drivers >>> +L: linux-i2c@vger.kernel.org >>> +S: Supported >>> +F: drivers/i2c/muxes/i2c-mux-ltc4306.c >>> +F: Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt >>> + >>> LTP (Linux Test Project) >>> M: Mike Frysinger >>> M: Cyril Hrubis >>> diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig >>> index 10b3d17..41153b4 100644 >>> --- a/drivers/i2c/muxes/Kconfig >>> +++ b/drivers/i2c/muxes/Kconfig >>> @@ -30,6 +30,17 @@ config I2C_MUX_GPIO >>> This driver can also be built as a module. If so, the module >>> will be called i2c-mux-gpio. >>> >>> +config I2C_MUX_LTC4306 >>> + tristate "LTC LTC4306/5 I2C multiplexer" >>> + select GPIOLIB >>> + select REGMAP_I2C >>> + help >>> + If you say yes here you get support for the LTC LTC4306 or LTC4305 >> >> This reads a bit funny, and I think you should just spell out the >> first LTC? But perhaps not in the tristate above though, depending >> on how long it gets? > > Ok - I rename LTC -> Analog Devices > >> >>> + I2C mux/switch devices. >>> + >>> + This driver can also be built as a module. If so, the module >>> + will be called i2c-mux-ltc4306. >>> + >>> config I2C_MUX_PCA9541 >>> tristate "NXP PCA9541 I2C Master Selector" >>> help >>> diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile >>> index 9948fa4..ff7618c 100644 >>> --- a/drivers/i2c/muxes/Makefile >>> +++ b/drivers/i2c/muxes/Makefile >>> @@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o >>> obj-$(CONFIG_I2C_DEMUX_PINCTRL) += i2c-demux-pinctrl.o >>> >>> obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o >>> +obj-$(CONFIG_I2C_MUX_LTC4306) += i2c-mux-ltc4306.o >>> obj-$(CONFIG_I2C_MUX_MLXCPLD) += i2c-mux-mlxcpld.o >>> obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o >>> obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o >>> diff --git a/drivers/i2c/muxes/i2c-mux-ltc4306.c b/drivers/i2c/muxes/i2c-mux-ltc4306.c >>> new file mode 100644 >>> index 0000000..7d34434 >>> --- /dev/null >>> +++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c >>> @@ -0,0 +1,310 @@ >>> +/* >>> + * Linear Technology LTC4306 and LTC4305 I2C multiplexer/switch >>> + * >>> + * Copyright (C) 2017 Analog Devices Inc. >>> + * >>> + * Licensed under the GPL-2. >>> + * >>> + * Based on: i2c-mux-pca954x.c >>> + * >>> + * Datasheet: http://cds.linear.com/docs/en/datasheet/4306.pdf >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> +#define LTC4305_MAX_NCHANS 2 >>> +#define LTC4306_MAX_NCHANS 4 >>> + >>> +#define LTC_REG_STATUS 0x0 >>> +#define LTC_REG_CONFIG 0x1 >>> +#define LTC_REG_MODE 0x2 >>> +#define LTC_REG_SWITCH 0x3 >>> + >>> +#define LTC_DOWNSTREAM_ACCL_EN BIT(6) >>> +#define LTC_UPSTREAM_ACCL_EN BIT(7) >>> + >>> +#define LTC_GPIO_ALL_INPUT 0xC0 >>> +#define LTC_SWITCH_MASK 0xF0 >>> + >>> +enum ltc_type { >>> + ltc_4305, >>> + ltc_4306, >>> +}; >>> + >>> +struct chip_desc { >>> + u8 nchans; >>> + u8 num_gpios; >>> +}; >>> + >>> +struct ltc4306 { >>> + struct regmap *regmap; >>> + struct gpio_chip gpiochip; >>> + const struct chip_desc *chip; >>> +}; >>> + >>> +static const struct chip_desc chips[] = { >>> + [ltc_4305] = { >>> + .nchans = LTC4305_MAX_NCHANS, >>> + }, >>> + [ltc_4306] = { >>> + .nchans = LTC4306_MAX_NCHANS, >>> + .num_gpios = 2, >>> + }, >>> +}; >>> + >>> +static bool ltc4306_is_volatile_reg(struct device *dev, unsigned int reg) >>> +{ >>> + return (reg == LTC_REG_CONFIG) ? true : false; >>> +} >>> + >>> +static const struct regmap_config ltc4306_regmap_config = { >>> + .reg_bits = 8, >>> + .val_bits = 8, >>> + .max_register = LTC_REG_SWITCH, >>> + .volatile_reg = ltc4306_is_volatile_reg, >>> + .cache_type = REGCACHE_RBTREE, >> >> Did you consider REGCACHE_FLAT? There are very few registers and no hole >> in the map, and maintaining a tree seems like total overkill. > > There is no reason to use REGCACHE_FLAT, in our case it will be a single > node. Ok, so that makes me wonder what need REGCACHE_FLAT satisfies? To me, a flat regmap seems like a perfect fit here. Oh well... >> >>> +}; >>> + >>> +static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + unsigned int val; >>> + int ret; >>> + >>> + ret = regmap_read(data->regmap, LTC_REG_CONFIG, &val); >>> + if (ret < 0) >>> + return ret; >>> + >>> + return (val & BIT(1 - offset)); >> >> The outer parentheses do not add anything, and I think they might remain >> from when you just removed a double negation at some point. But is it >> good practice to indicate "high" with anything other than one? Sure, the >> gpiolib function that wraps the ->get() op does the !! dance for you, >> but even so, every single one of the half dozen random gpio providers I >> looked at had code to coerce the value to 0/1 (or error). Which makes me >> think you should also have it. And the gpio_chip documentation on ->get() >> agrees with me... > > I'll restore the double negations. Thanks! >> >>> +} >>> + >>> +static void ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset, >>> + int value) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + >>> + regmap_update_bits(data->regmap, LTC_REG_CONFIG, BIT(5 - offset), >>> + value ? BIT(5 - offset) : 0); >>> +} >>> + >>> +static int ltc4306_gpio_direction_input(struct gpio_chip *chip, >>> + unsigned int offset) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + >>> + return regmap_update_bits(data->regmap, LTC_REG_MODE, >>> + BIT(7 - offset), BIT(7 - offset)); >>> +} >>> + >>> +static int ltc4306_gpio_direction_output(struct gpio_chip *chip, >>> + unsigned int offset, int value) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + >>> + ltc4306_gpio_set(chip, offset, value); >>> + return regmap_update_bits(data->regmap, LTC_REG_MODE, >>> + BIT(7 - offset), 0); >>> +} >>> + >>> +static int ltc4306_gpio_set_config(struct gpio_chip *chip, >>> + unsigned int offset, unsigned long config) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + unsigned int val; >>> + >>> + switch (pinconf_to_config_param(config)) { >>> + case PIN_CONFIG_DRIVE_OPEN_DRAIN: >>> + val = 0; >>> + break; >>> + case PIN_CONFIG_DRIVE_PUSH_PULL: >>> + val = BIT(4 - offset); >>> + break; >>> + default: >>> + return -ENOTSUPP; >>> + } >>> + >>> + return regmap_update_bits(data->regmap, LTC_REG_MODE, >>> + BIT(4 - offset), val); >>> +} >>> + >>> +static int ltc4306_gpio_init(struct ltc4306 *data) >>> +{ >>> + struct device *dev = regmap_get_device(data->regmap); >>> + >>> + if (!data->chip->num_gpios) >>> + return 0; >>> + >>> + data->gpiochip.label = dev_name(dev); >>> + data->gpiochip.base = -1; >>> + data->gpiochip.ngpio = data->chip->num_gpios; >>> + data->gpiochip.parent = dev; >>> + data->gpiochip.can_sleep = true; >>> + data->gpiochip.direction_input = ltc4306_gpio_direction_input; >>> + data->gpiochip.direction_output = ltc4306_gpio_direction_output; >> >> I'm missing a get_direction op? > > No - its purely optional - the vast majority of gpiochips don't > implement it. > > linux/drivers/gpio$ grep -lr --include \*.c get_direction | wc > 36 36 523 > linux/drivers/gpio$ grep -Lr --include \*.c get_direction | wc > 101 101 1461 Ok, but while optional, why not provide it? The implementation would be about as simple as ltc4306_gpio_get, no? >> >>> + data->gpiochip.get = ltc4306_gpio_get; >>> + data->gpiochip.set = ltc4306_gpio_set; >>> + data->gpiochip.set_config = ltc4306_gpio_set_config; >>> + data->gpiochip.owner = THIS_MODULE; >>> + >>> + /* gpiolib assumes all GPIOs default input */ >>> + regmap_write(data->regmap, LTC_REG_MODE, LTC_GPIO_ALL_INPUT); >>> + >>> + return devm_gpiochip_add_data(dev, &data->gpiochip, data); >>> +} >>> + >>> +static int ltc4306_select_mux(struct i2c_mux_core *muxc, u32 chan) >>> +{ >>> + struct ltc4306 *data = i2c_mux_priv(muxc); >>> + >>> + return regmap_update_bits(data->regmap, LTC_REG_SWITCH, >>> + LTC_SWITCH_MASK, BIT(7 - chan)); >> >> Since the bits outside the mask are ignored for writes, I'd go with >> regmap_write. Especially since those bits are volatile, which admittedly >> will not have much impact until there is a need to read those volatile >> bits outside the mask. But still. > > Yes they are volatile - but not declared as such. > So regmap cache just ignores them. > And we totally ignore these RONLY status bits, too. Of course. I was referring to future changes that would perhaps need to get at those status bits. > regmap_write() will always write and ignore the cache, while > regmap_update_bits() uses the cached value. Ah, I was not aware of that. > Are these callbacks guaranteed to be never called with the same CHAN > sequentially? if yes - use regmap_write() otherwise its more efficient > to use regmap_update_bits(). If you have the mux disconnect on idle, then yes, we are guaranteed to not call with the same "CHAN". But, if not disconnecting and given the above, it is more efficient to rely on the cache given the above properties of regmap. So, let's do it your way and keep update_bits and worry about volatile etc when/if it happens. Ok, move on, nothing to see. And thanks for explaining. Cheers, peda >> >>> +} >>> + >>> +static int ltc4306_deselect_mux(struct i2c_mux_core *muxc, u32 chan) >>> +{ >>> + struct ltc4306 *data = i2c_mux_priv(muxc); >>> + >>> + return regmap_update_bits(data->regmap, LTC_REG_SWITCH, >>> + LTC_SWITCH_MASK, 0); >> >> Dito. >> >>> +} >>> + >>> +static const struct i2c_device_id ltc4306_id[] = { >>> + { "ltc4305", ltc_4305 }, >>> + { "ltc4306", ltc_4306 }, >>> + { } >>> +}; >>> +MODULE_DEVICE_TABLE(i2c, ltc4306_id); >>> + >>> +static const struct of_device_id ltc4306_of_match[] = { >>> + { .compatible = "lltc,ltc4305", .data = &chips[ltc_4305] }, >>> + { .compatible = "lltc,ltc4306", .data = &chips[ltc_4306] }, >>> + { } >>> +}; >>> +MODULE_DEVICE_TABLE(of, ltc4306_of_match); >>> + >>> +static int ltc4306_probe(struct i2c_client *client, >>> + const struct i2c_device_id *id) >>> +{ >>> + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); >>> + struct device_node *of_node = client->dev.of_node; >>> + struct i2c_mux_core *muxc; >>> + struct ltc4306 *data; >>> + struct gpio_desc *gpio; >>> + bool idle_disc = false; >>> + int num, ret; >>> + >>> + if (of_node) >>> + idle_disc = of_property_read_bool(of_node, >>> + "i2c-mux-idle-disconnect"); >>> + >>> + muxc = i2c_mux_alloc(adap, &client->dev, >>> + LTC4306_MAX_NCHANS, sizeof(*data), >> >> Hmmm, I didn't see this before, but if you do some more rearranging, it >> should be possible to replace LTC4306_MAX_NCHANS with data->chip->nchans >> and reduce resource waste for ltc4305. But it's just storage for two >> pointers which is really really minor... Feel free to ignore. >> >> But you want to set a good example, right :-) >> >>> + I2C_MUX_LOCKED, ltc4306_select_mux, >>> + idle_disc ? ltc4306_deselect_mux : NULL); >>> + if (!muxc) >>> + return -ENOMEM; >>> + data = i2c_mux_priv(muxc); >>> + >>> + i2c_set_clientdata(client, muxc); >>> + >>> + data->regmap = devm_regmap_init_i2c(client, <c4306_regmap_config); >>> + if (IS_ERR(data->regmap)) { >>> + ret = PTR_ERR(data->regmap); >>> + dev_err(&client->dev, "Failed to allocate register map: %d\n", >>> + ret); >>> + return ret; >>> + } >>> + >>> + /* Reset and enable the mux if an enable GPIO is specified. */ >>> + gpio = devm_gpiod_get_optional(&client->dev, "enable", GPIOD_OUT_LOW); >>> + if (IS_ERR(gpio)) >>> + return PTR_ERR(gpio); >>> + >>> + if (gpio) { >>> + udelay(1); >>> + gpiod_set_value(gpio, 1); >>> + } >>> + >>> + /* >>> + * Write the mux register at addr to verify >>> + * that the mux is in fact present. This also >>> + * initializes the mux to disconnected state. >>> + */ >>> + if (regmap_write(data->regmap, LTC_REG_SWITCH, 0) < 0) { >>> + dev_warn(&client->dev, "probe failed\n"); >>> + return -ENODEV; >>> + } >>> + >>> + if (of_node) { >>> + unsigned int val = 0; >>> + >>> + data->chip = of_device_get_match_data(&client->dev); >>> + >>> + if (of_property_read_bool(of_node, >>> + "ltc,downstream-accelerators-enable")) >>> + val |= LTC_DOWNSTREAM_ACCL_EN; >>> + >>> + if (of_property_read_bool(of_node, >>> + "ltc,upstream-accelerators-enable")) >>> + val |= LTC_UPSTREAM_ACCL_EN; >>> + >>> + if (regmap_write(data->regmap, LTC_REG_CONFIG, val) < 0) >>> + return -ENODEV; >>> + } else { >>> + data->chip = &chips[id->driver_data]; >>> + } >>> + >>> + ret = ltc4306_gpio_init(data); >>> + if (ret < 0) >>> + return ret; >>> + >>> + /* Now create an adapter for each channel */ >>> + for (num = 0; num < data->chip->nchans; num++) { >>> + ret = i2c_mux_add_adapter(muxc, 0, num, 0); >>> + if (ret) { >>> + i2c_mux_del_adapters(muxc); >>> + return ret; >>> + } >>> + } >>> + >>> + dev_info(&client->dev, >>> + "registered %d multiplexed busses for I2C switch %s\n", >>> + num, client->name); >>> + >>> + return 0; >>> +} >>> + >>> +static int ltc4306_remove(struct i2c_client *client) >>> +{ >>> + struct i2c_mux_core *muxc = i2c_get_clientdata(client); >>> + >>> + i2c_mux_del_adapters(muxc); >>> + >>> + return 0; >>> +} >>> + >>> +static struct i2c_driver ltc4306_driver = { >>> + .driver = { >>> + .name = "ltc4306", >>> + .of_match_table = of_match_ptr(ltc4306_of_match), >>> + }, >>> + .probe = ltc4306_probe, >>> + .remove = ltc4306_remove, >>> + .id_table = ltc4306_id, >>> +}; >>> + >>> +module_i2c_driver(ltc4306_driver); >>> + >>> +MODULE_AUTHOR("Michael Hennerich "); >>> +MODULE_DESCRIPTION("Linear Technology LTC4306, LTC4305 I2C mux/switch driver"); >>> +MODULE_LICENSE("GPL v2"); >>> >> >> > >