Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933784AbdDFJiG (ORCPT ); Thu, 6 Apr 2017 05:38:06 -0400 Received: from mail-db5eur01on0126.outbound.protection.outlook.com ([104.47.2.126]:12544 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754336AbdDFIjk (ORCPT ); Thu, 6 Apr 2017 04:39:40 -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> CC: , , , From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Thu, 6 Apr 2017 10:39:28 +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: <1491397671-14675-2-git-send-email-michael.hennerich@analog.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [81.224.171.159] X-ClientProxiedBy: VI1PR0802CA0003.eurprd08.prod.outlook.com (10.172.253.141) To AM5PR0202MB2547.eurprd02.prod.outlook.com (10.173.89.8) X-MS-Office365-Filtering-Correlation-Id: 3bc31146-0e66-4903-5ac6-08d47cc8738d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075);SRVR:AM5PR0202MB2547; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;3:kf5Q6cV8xtFUpyNhJ4GmOzvCjzAZztK4+HnWmQG3FFIEZPY4Z4L6XyC/x0hJzTybcX3+MZXMFxPMCAZu0TFaM7XDIos5Xpeeb2krcJj0TMdKMthX8B4Uxll1UawDfOH6LawmV3SN+3+b5zJ3mNZeZ0whxPjYzIuVVbLeyrVIXbaebLgCguyl2DzTBsfRhm5RWUqOVC3m//2H8MuEwNidnKkW7xG1bfKSN8mDwfCrekKgreB8eC87uh81GhPPG/5kM/VIW36cy61QAhS99N0EYBB+y7mKOva1rnxjRYpF31o4KayI+ywmbD9HYiY0fFje;25:Dlv2/t5q6fXrbvJZ+ey4spE5guZMI8sXXvNUgIL1v1fGv9L/htn/pu8MvZ9N8XYO8lx6huOBhMv4VyAVIm7kwtjI7POASK5MFkBWu7xuxskDL+cgJ4PeZU/e0oG8n1SsjVaTnsP4niT60tqjAdKPfW/ckTE9w8Pujlv1IynzywFqloiUpYkITYraqV6cTo+WyYno6c5VqAfo8y5ZP58MbN3Jp/H0ftU5+F3PSYXmZUcJzp6pTH/UkkA9qpEJRR05YOj+aIdodJHNxSy/9Gt24CY6SHMZVq2LqYiwAF2fZv28bFrxq6m8wqTEBopbzwX5JC0YH3TyjwvJU0qfoChmWvU4lMGAU2Q7o24TFuehYPBHmlfzYqiN2H1mpIE4KOf08DQ4z1puO3NnuP2bqcbH3iHZv0Z36i6aWyLFNF2O1PTColy5rM1CxBkQ+RlyF8TSZ/YyrDfWrpMu9MjvWHVc2A== X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;31:rLXNG7rx8e5bwsoyPV7qay/aCbqzdka5/WRicVIQUooIz0kIIt/mDpbSYiIjRhpz7joj9TvtD90q36buM6rRL4+OQa2QZjC1GZnAzzx2jbbznC1EXW9jR0tP6tJxoitTkW94x594VHFhGkkTCzueLv6SPyIxYE7CKZ8q7ZfkjS6ijZvdGkUbYI5J+sBpRM5X1RCi263t7l3VXmMcwqWo/PUbq83HJkEHUNCAPiLpRboq2tBPDXAQzfPJ0wWRbLrvtUJ4Bsuaf8euw66F6JxH34BkYB6PTU6ef5h4Mnjymzs= 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)(10201501046)(3002001)(6041248)(20161123562025)(2016111802025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123555025)(6072148)(6043046);SRVR:AM5PR0202MB2547;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0202MB2547; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;4:KDGTN/MSaPawzfRtHjTqVs+gcpR6im4GM9GYo2+JSkb2XB28QL4EVcavItDN5DtTe9Um3OEL4j2WewbYeFgiBtOxl8mQ5T+oH1q2YH9KfvPtdjyFt4ny5kX/RK8+QhoxTvqR1L6NjY/VHC1umG0rWcnJe188xlNxtZRhqdQBYdTJxkujC7jcZu3hhNbvNwfIs7d7vRCtRSmnKRXDxHKRGZ1LnLYgdlpg58Sq2U9aLb47qfRV04aQQBbA9WM8yxjk6e1G/cOGkPC8PQvpU1RFWx2r7BtJVGlWjhd2iQ0QYQKeaG7NEFJUXHce1cs4acum3DhHHNBvOwHZf/2RO0IB0TbUJXu4IhYsMivXXGecqT+pg9tvX75nx1ev77flZN0DPQpATuEtJEHkkRFg3AI+8Bo+zgI5uzU+iS4Wij2eTGLmbyHJYBzKTigJkVO22wu4df7ZotxEXH8LE/W3vhEM/HPG5doj/6BNJpgi0K5Zge6+Slk/yOZnh8Z8fVc4ZSrRQLyvtzA6ouP9Sd+mB8Q4K/RmHqiuxU+Mb7dsTw4gMKWP9XvF22qym+F5I7Sp97n+GO9PjJxfMGOqqE6zNBpZQtLdqHPVUAvt3zsWPPqy1xFMoSzGZFz3f2d7TQDJwFp9z3APkO3YlpCJY3H07NYCVc1wvMpRBqbltf2dcsmmeDrtehtWs6xOXGuqBetGeiTkvudbJEaVVD0AO+joCqTDQpAIAWkR9o/o6dfb1zd3lI6IGqjwwrv39+ZdQB1TwWSJkO6I+1LGM6F81wEdr/5fSSnixxoSeruBB4LaVV6kC8pk0qaJ+an2DFThvePPCRApNX691RTGwoqLe4qZ4WL2jm8vCcMGL0De9TRsAJejIjyfNECTvaRspV3IznbDcZJYWxkFXbwlQjoPk1s51/jBaRi/OMQnMtMxXffACSWyLEaJMI9uTSHt/QlRnVPR2Di0 X-Forefront-PRVS: 02698DF457 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(39830400002)(39450400003)(39400400002)(39410400002)(24454002)(52314003)(377424004)(81166006)(230700001)(3846002)(6116002)(7736002)(8676002)(33646002)(42186005)(117156002)(50986999)(77096006)(4326008)(229853002)(74482002)(2906002)(76176999)(54356999)(6486002)(66066001)(23746002)(83506001)(2950100002)(38730400002)(50466002)(6246003)(6666003)(54906002)(90366009)(31696002)(966004)(4001350100001)(86362001)(5660300001)(305945005)(31686004)(65826007)(1720100001)(65956001)(65806001)(53936002)(25786009)(3260700006)(8666007)(6306002)(47776003)(189998001)(53546009)(36756003)(562404015)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0202MB2547;H:[192.168.0.125];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;AM5PR0202MB2547;23:UCwFeVcaIlsCU8miEjgE2AbDJcTbfNXHXRh?= =?Windows-1252?Q?UwE/SCIFQcn4gvsGXHCgPU5rb39btXPH40YvDxrumG/jYx/FRF/tQLyO?= =?Windows-1252?Q?k2FHd7n8zKxjQc8ttrIe3VjYzNqF4H/IgkAlKdJv/IR17FnHSxvJLXxT?= =?Windows-1252?Q?Na8WBNjE2JEA9m7Uwe0uc0F8wOMoh4NXsvDNrUPqhXxFvH1r59nC8UEI?= =?Windows-1252?Q?Od89IIAX6j50Nme1UzfDM6Zb6mHt0EI/SLBMZ4Zf4n+L5hmZniUwVyVq?= =?Windows-1252?Q?hicg0RfVyZ4e9QiKeLaDTs3G2pBGYZocnT+Uo5UHcY75WkcbSIHAnUim?= =?Windows-1252?Q?FrTVdueSIzG0h6ypCoLtFkV06PtjPw8f1+g1vbm7HJS1594BTu3DsQUM?= =?Windows-1252?Q?N5S+y9UXvujiYNRISKvCqGVb/EuoFvZdltsjUx6BtPanxjUGZk90MA8a?= =?Windows-1252?Q?qFGax98It0yH/kBalIZFdEZc4Vlb4geX4yo+VeOUFXzzt9DflIgE6CY8?= =?Windows-1252?Q?i7bUvNZVHbXee8PbTRpmm+QNdCtx+7pBBabX3ssrt4IfBzpx+H4RTLLv?= =?Windows-1252?Q?ab+pKWYQ/hLZF7LSBDeaNKIzY3ZDS+66XEZfgx7yx131siyvtgHIIj8m?= =?Windows-1252?Q?uji8KTb4o03wFbb2pOSrOF5st/8HCd713/HUYm0dvfV/s1AlgQOH90K+?= =?Windows-1252?Q?PEssL7P7p+Wf0VYHIfvEf8N9eLkzX4ZXo3g3ERd2YiCuxzIV20Kk+kwg?= =?Windows-1252?Q?4CVTlA/m7yglx1YCilAtqSb91KC0Ra47lZyO2RKcIpNn4ZPl0W99Dn/r?= =?Windows-1252?Q?CB9jJo8MCWlPhVza30tAeZ35Zuvk+GTkUChP62KT0yUiftnnf4x3WY37?= =?Windows-1252?Q?re5vuK4kSnXpfQOTJwKMrtVxfxrCBXdCvYqkICztUvFzwcw2sSWBWTRh?= =?Windows-1252?Q?MerdRN5l6xF2icc0eMb4VzZxsBXOoS+rl2Fl7dea9yRzue/sf7wHJbnL?= =?Windows-1252?Q?SgiZNxp7qPgWF+yeQXsimoK8Jc+d1CnFuXLTqwHBMjP6fxfOzh8MpU2t?= =?Windows-1252?Q?PKKALL/qOwkCiml5UMQCkL9/JgGfRKMqYM1/7jToDrDidPF+xQvwpkd4?= =?Windows-1252?Q?PseN/tt6J0aG3pFw1Thbs53m/248MK4x3J3EJwdvv9s7aWTjCCHf/dPT?= =?Windows-1252?Q?0PtoonSa3+7kaf0wsUUAKzZr26d5lItCy4AZV4YXd3CKiH9lCjk5v3iU?= =?Windows-1252?Q?iR9zPQoeD8fw4delEbPTcPviwMrzKtRCHekf8hR5DNjkrK+3SiV5rd8e?= =?Windows-1252?Q?Y5QbyYg6FDPmeXSsE+TfTW4H6B2ERRZI5uL2+UaeaXeNWBqim8GgEX0j?= =?Windows-1252?Q?uZVTYgqk8LE8ISYPK1LMVz3VNQsqYjBLM8A6IwG+2i309rASMd+jkIcD?= =?Windows-1252?Q?c+OF9aO8hFM1BlF7ETftGD4UhIzs379tWXJjgdkiVb53rQGq8Wl4LE/6?= =?Windows-1252?Q?2ye/5J0jd+7h2LKN+fOeh2mYHysE5Gaywr9xwa41XeNjt11926b5aA1b?= =?Windows-1252?Q?pIz9XiSKdiN/Omig=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;6:4A92f+qaCiqzJsF5eEvQiFmyFlbSoq23btY4Jg7QIr8YWQ2T83kltHOb2gb6zIxSpfY8l5AtLXwy3NwifqaNZ9yV1Q3kr3jEWPFMeHqiV7BktEXNXG1PYkGvqIC1R/rsFesair8HmRla2AXXiLJMJHBKTUgV/3JetJJPt/awn7bFNJL7wZEt+M1NVexsIChDldRffaa31/b04tpUzI8oIcuFo6bLlu9enAnGGrhySO+PICHsH/FK30IMW6MEorr5/+GXw71lmDsln2xe/9XmTxpHiPIbaAlM7ETUWvBoE5X4BTzpAeCpkma+vn9UJ3ZzxueQc3QcnDAb1CAs0WkcPHKL86e5BkoovYz7y4fzNhbyOnd/2lphdlbY4MT68nvEr1NOUnCmJX3qTMZap21gQg==;5:YYO1ntu8L0augRcsxw8CTPPLQleYRYnyGeMRHOrzsBzlTK9hoctANzQHKnPlphQI0sgYSSQBpwslkEWlzChIDDfbVt8GeSHJOazaaeSMdwxLuXKVL3KcvtO6qs+j1dp1Opmok/kTnZ/1gwcjrwSzNA==;24:4blOxZfCjLnkkUr+Cw31/XG7QpllqDtcfwqrYEHX6vSm7kX/1dgNYgf36dja7kDc/IfueG/qqvm+md9v+ROwiwI8OwgZr9E7cSGftnM2rn4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2547;7:YLBa/dxJTVNqLe9yf2G6AqWJaj4tmGXYX8Xz7RnhMy6RQ1Goc8WcZS4IaGe6krSPJaRksohGSc/P6I3RHnzfyXigGrpKe9yfYumuFPGKHb8mDGttnk/rzUqV+fObYlDFrHxx3VVhjaYHxGuD8VIYNS1bulGCDOB3GEI8ECl9oTnD3bfoZ2B2/BanHnCm3ZW8y8sjwaz1G5kEGuOJoIfpp1ZhnAQtnlfsXXgnDIQDDAltViTyJp3dh9wTM8YAwzzsrK6mFYZWyBjrh8ZUKihcR7N5BxT+/eOrNmTcgI77hceB0p84uncPvHMn/RjCo2USCsn1Z8TrHLafNF2EdN6DwA== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2017 08:39:32.8600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0202MB2547 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13927 Lines: 470 Hi Michael, I would still like to hear from someone with more gpio experience. Anyway, from my point of view, there's just a few minor things left, with comments inline as usual. Thanks for you patience! 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? > + 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. > +}; > + > +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... > +} > + > +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? > + 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. > +} > + > +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"); >