Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755926AbdC2KOl (ORCPT ); Wed, 29 Mar 2017 06:14:41 -0400 Received: from mail-sn1nam01on0066.outbound.protection.outlook.com ([104.47.32.66]:15313 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755393AbdC2KOe (ORCPT ); Wed, 29 Mar 2017 06:14:34 -0400 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=analog.com; From: To: , , , , CC: , , , , "Michael Hennerich" Subject: [PATCH v2] i2c/muxes/i2c-mux-ltc4306: LTC4306 and LTC4305 I2C multiplexer/switch Date: Wed, 29 Mar 2017 12:15:41 +0200 Message-ID: <1490782541-7832-1-git-send-email-michael.hennerich@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(39450400003)(39400400002)(39850400002)(39410400002)(39840400002)(2980300002)(438002)(199003)(189002)(6666003)(966004)(5660300001)(2906002)(8676002)(2876002)(77096006)(1720100001)(50986999)(107886003)(7636002)(5003940100001)(38730400002)(6306002)(33646002)(36756003)(86152003)(189998001)(48376002)(47776003)(4326008)(50226002)(50466002)(305945005)(106466001)(230783001)(86362001)(356003)(8936002)(562404015);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB0875;H:nwd2mta2.analog.com;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD031;1:z8fAiblf0YgCIV8FkTHdz343ykO580e/wLs0A6gvIdGWkKTSC5EAnMAOodvSz6BBKH5xudAAKWIAekKKeM4QaCgVkMPZh8Bfqbrh/EVQz3+rqEUQD7esSvIItgTnhADFutfKG5Ku/H2Xc74sxSKV1D0ThV+Fd4eINKPCchaf2RHkJTfz6mm3mOItAxQ7WPhf4EfBUS6TedCgCaSK3Kf4hoPyWtj2Sg6tu6N6lfHtmWaHfq7OyspEDun3HNBhXTfpcLeUVYMOS8eMEbQ894OUvHdjbb3mbTsSa5rZNlNY1V7re9Zw/SzFvOZmktFJUetQjN0Ol82R1++qpMwbzv9QzFpRHy8/6tjDTJI3MD6Cxhra6ZfJ9shnDbBGfOmYTt0FUIGAp1IQe2G+JzHklrIXzOJr1fOPkaJ31th18NuyRJ5gKyoeVRnSU6BgKphQ+S71ulwFkt2LD5QIlH/UykcEWJYUTzvG2wuL2GNEtJu485t1ol2zMAtRRG8CyfrjlRVCNC11zE2rsw4OqqjLecIvh0WPZ3bW73IqG3n2zVAmWkmCNvERfauDPG/ddVc2qtHns+eeMmbtJx2WskzXz84lx8d5UFJd8JEcwoDEU2orAXk= X-MS-Office365-Filtering-Correlation-Id: 91b88a0d-e700-4bd4-67b9-08d4768c606e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(8251501002)(2017030254075)(201703131423074)(201703031133080)(201702281549074);SRVR:CY1PR0301MB0875; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0875;3:zWjn+rqJ9eZD1d6mkuKErO+SPU670h3ceHfgZUdT0TW1HftkCXz3qwzJRybHGqj3hOTKGGfOeFVFVk02XZzNGAF2WTWICJlyRMyMfp17eYyW4/sh+Kd9TmzE3rJzw4P7IceH6AGY4v3dJf+BVeKk6ySJVhRogGcpth8C/QIm/o+BXPPu/Fpyz4aTyh+KKvdFhZXQbYvcrCl43+H/mEIZzq211ZjGKUylc/9vh5hcDYhJljPv970o17ZXgvgAiNie3vfW63yh32CrPhO7M2oqsXfr9eEFjtMeBYmKKgbQcleCyjKSlf3dhHm2ejkq2nUSN/Y2TOxGSf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ZS0vcfzm6Kbx6Y6jq1WCX0QwVGzt8XBqUZEGxkJQtY18kEjpjahMBMBygVXQkHEX59uT1eDhLWyzftOwVlOqM9Brxwi17QXQOBDDeEhP/fb0Ty6OBtb2avq3hF2F/zlknYfI6FDOr63su+V6ppi7w2YYvTBUqky///W4u5owhP2Veh8dKEUIML+t5YEJ21/Rq7lVXlAmfdkA/1lbZB+TGMkeReWWdBf77uNQmjJr9TQJ5QuSDA6UttDtcf74PUqu3sWLM9axQ70xM5S6mrltdG0Q8kOM++i3rA9LMl9AxGoBokcKCoG0VmR8cJFg8Y9JM6awMkWuipx6iemszymrf6CSOtXaHPeWOP/awEk/P+C2raa4RIrj3r6tBc+TCWHbfSCgcZA8A6CjmU+k9wHHXAhSwKUe1FDIGvvXO7gFQD17zzFxDlcXwEx02vShQ+TLyAbVgdvEENCIjNRa/Lt4BZkTUKxOvxIfaevEiY+7PtJ63vTS213pqV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(232431446821674)(170811661138872); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040449)(601004)(2401047)(8121501046)(13018025)(5005006)(13017025)(13015025)(13024025)(13023025)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(201703131423074)(201702281528074)(201703061421074)(201703061406074)(20161123558025)(6072148);SRVR:CY1PR0301MB0875;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0875; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB0875;4:RYaZzymFvTvPKX6vMSbeJtlPBUixFy5NeXwq0ATL?= =?us-ascii?Q?KYbmrMDBsFR916X21OKna8kw7C7Ygf610YlH1nzZpK+lm4spztv+yEXfzRG7?= =?us-ascii?Q?F53MAFVD+V2NqS7fOSpbtsvPYOE8lmoh1OCyEZhEU85r0HDpC+xH/WaTwSgH?= =?us-ascii?Q?uDMafXyhs/ccmkBkfUK4SOGD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CXzHj9P70kQ/Oe2QTijvjjlAMoMq3FoPItnk1w+o9Dg0cx09VwVZCWn?= =?us-ascii?Q?9PDg0gWPQAG8+VY9o32iBJZpdbqWteRkqar3iCq5TrS/n1rdtBX8vzmd7A1G?= =?us-ascii?Q?RsdrZXqjMd9+nRIIK5AaT3/d40JpLxvLonB4fgt9SvojrUg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0875;6:7hsPQcunVdLe2Lz3DAchbkWJfup1UkWuZLhyBYn1jxWZDb70NI//A8/YaGaEf4WgRZzbAkbqoySt6ACCzbxJUb5RQnfdiTKRouV6rfmTNPdVHACFL32tt1L7gP3VpT61QY7u+e9wgFZdzRCDdrLTzz8yHYpuYeLs+MJI51cdn61DDKG19DGZ3PbnmN/gjX8UqWJUQPk33A37k3kadDUqtkuHSkPVvAQIyaYyoS8FZv7FPtkIqPONioO0uavb3mv5A6PU5pQfjjzKYKI/AJ5V8tezm54lMhYr+j7dJcEPeAJWqL8lQEBb00hlW/Df8EITBiZOu1XE/yjQCda9o1HmZtBF7Yhpexb+HY5uIcldiFG4DSTIBug9iqxjwVN/M3f7snGk3ruA3Z1F5LZhEF6XmRfPWzureZQYA2kuqEz8oO8=;5:ZVSAsi3vErPTk1O0XVASqUmXsOSOY4EkWI4Lr0gqAlmVVldAFkiNGziTM1Hw0KOPhlsloTAP3CXffFrzH2d1jHavAThrhhe6jp3r7eFZmZwBJ5kkoMXt9OWmVRbeHAYlI95z0Pgp8CVsBYhAIukduPwZQ9Qo1lykOdCn/y56q3Q=;24:OMS7xIUtEEDFZlzquzgGaDwn2yLo7NlcRLRaDzJTT4ybuqS7jqCCqmrQqlIkrno4eiRizSuvsSA59M9S7FG9xcfBck23t9+L2bXo60d9Lvg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0875;7:/YOd4mh7aiICBlMBZsHNH9zYr/gauqfRSg5OTEaxJ2Ak9GPHrKUQHTqzfb8fqZR+XZjDM9FjrvYjdOfCTBMzjrDcNjqKbdSvCc+rsA/BMe8TMzFdjGCNs/cqZD4xasWkKOOHn4tW16RYHM5+MCOi6OCLHIv1EzeGA6KRg+VnbcBKQ+Yk48aT4GDklW4anu1bnvfu+hJetHSbl28op8Y1ReALj5pjMtq2G3xm6Cvq23DpEL9YieYkHXOFNW772cKhGwyhpdexQ3Ts/gcDLpza/ybQXqE+Fre76w14zhdyHfrIOoT7inWe3AI5pLzNLEXup6qdktvOoTTPSun9YbnFUw== X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2017 10:14:25.0181 (UTC) X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.57];Helo=[nwd2mta2.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0875 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 14740 Lines: 526 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. --- .../devicetree/bindings/i2c/i2c-mux-ltc4306.txt | 61 ++++ MAINTAINERS | 8 + drivers/i2c/muxes/Kconfig | 10 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-ltc4306.c | 367 +++++++++++++++++++++ 5 files changed, 447 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt create mode 100644 drivers/i2c/muxes/i2c-mux-ltc4306.c diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt b/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt new file mode 100644 index 0000000..1e98c6b --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt @@ -0,0 +1,61 @@ +* Linear Technology / Analog Devices I2C bus switch + +Required Properties: + + - compatible: Must contain one of the following. + "lltc,ltc4305", "lltc,ltc4306" + - reg: The I2C address of the device. + + The following required properties are defined externally: + + - Standard I2C mux properties. See i2c-mux.txt in this directory. + - I2C child bus nodes. See i2c-mux.txt in this directory. + +Optional Properties: + + - enable-gpios: Reference to the GPIO connected to the enable input. + - i2c-mux-idle-disconnect: Boolean; if defined, forces mux to disconnect all + children in idle state. This is necessary for example, if there are several + multiplexers on the bus and the devices behind them use same I2C addresses. + - gpio-controller: Marks the device node as a GPIO Controller. + - #gpio-cells: Should be two. The first cell is the pin number and + the second cell is used to specify flags. + See ../gpio/gpio.txt for more information. + - ltc,downstream-accelerators-enable: Enables the rise time accelerators + on the downstream port. + - ltc,upstream-accelerators-enable: Enables the rise time accelerators + on the upstream port. + +Example: + + ltc4306: i2c-mux@4a { + compatible = "lltc,ltc4306"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4a>; + + gpio-controller; + #gpio-cells = <2>; + + i2c@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + eeprom@50 { + compatible = "at,24c02"; + reg = <0x50>; + }; + }; + + i2c@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1>; + + eeprom@50 { + compatible = "at,24c02"; + reg = <0x50>; + }; + }; + }; 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..f501b3b 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig @@ -30,6 +30,16 @@ 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 + help + If you say yes here you get support for the LTC LTC4306 or LTC4305 + 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..c15a8a4 --- /dev/null +++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c @@ -0,0 +1,367 @@ +/* + * 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 + +#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 + +enum ltc_type { + ltc_4305, + ltc_4306, +}; + +struct chip_desc { + u8 nchans; + u8 num_gpios; +}; + +struct ltc4306 { + struct i2c_client *client; + struct gpio_desc *en_gpio; + struct gpio_chip gpiochip; + const struct chip_desc *chip; + u8 regs[LTC_REG_SWITCH + 1]; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [ltc_4305] = { + .nchans = LTC4305_MAX_NCHANS, + }, + [ltc_4306] = { + .nchans = LTC4306_MAX_NCHANS, + .num_gpios = 2, + }, +}; + +static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct ltc4306 *data = gpiochip_get_data(chip); + int ret = 0; + + if (gpiochip_line_is_open_drain(chip, offset) || + (data->regs[LTC_REG_MODE] & BIT(7 - offset))) { + /* Open Drain or Input */ + ret = i2c_smbus_read_byte_data(data->client, LTC_REG_CONFIG); + if (ret < 0) + return ret; + + return !!(ret & BIT(1 - offset)); + } else { + return !!(data->regs[LTC_REG_CONFIG] & BIT(5 - offset)); + } +} + +static void ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset, + int value) +{ + struct ltc4306 *data = gpiochip_get_data(chip); + + if (value) + data->regs[LTC_REG_CONFIG] |= BIT(5 - offset); + else + data->regs[LTC_REG_CONFIG] &= ~BIT(5 - offset); + + i2c_smbus_write_byte_data(data->client, LTC_REG_CONFIG, + data->regs[LTC_REG_CONFIG]); +} + +static int ltc4306_gpio_direction_input(struct gpio_chip *chip, + unsigned int offset) +{ + struct ltc4306 *data = gpiochip_get_data(chip); + + data->regs[LTC_REG_MODE] |= BIT(7 - offset); + + return i2c_smbus_write_byte_data(data->client, LTC_REG_MODE, + data->regs[LTC_REG_MODE]); +} + +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); + data->regs[LTC_REG_MODE] &= ~BIT(7 - offset); + + return i2c_smbus_write_byte_data(data->client, LTC_REG_MODE, + data->regs[LTC_REG_MODE]); +} + +static int ltc4306_gpio_set_config(struct gpio_chip *chip, + unsigned int offset, unsigned long config) +{ + struct ltc4306 *data = gpiochip_get_data(chip); + + switch (pinconf_to_config_param(config)) { + case PIN_CONFIG_DRIVE_OPEN_DRAIN: + data->regs[LTC_REG_MODE] &= ~BIT(4 - offset); + break; + case PIN_CONFIG_DRIVE_PUSH_PULL: + data->regs[LTC_REG_MODE] |= BIT(4 - offset); + break; + default: + return -ENOTSUPP; + } + + return i2c_smbus_write_byte_data(data->client, LTC_REG_MODE, + data->regs[LTC_REG_MODE]); +} + +static int ltc4306_gpio_init(struct ltc4306 *data) +{ + if (!data->chip->num_gpios) + return 0; + + data->gpiochip.label = dev_name(&data->client->dev); + data->gpiochip.base = -1; + data->gpiochip.ngpio = data->chip->num_gpios; + data->gpiochip.parent = &data->client->dev; + data->gpiochip.can_sleep = true; + data->gpiochip.direction_input = ltc4306_gpio_direction_input; + data->gpiochip.direction_output = ltc4306_gpio_direction_output; + 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 */ + data->regs[LTC_REG_MODE] |= LTC_GPIO_ALL_INPUT; + i2c_smbus_write_byte_data(data->client, LTC_REG_MODE, + data->regs[LTC_REG_MODE]); + + return devm_gpiochip_add_data(&data->client->dev, + &data->gpiochip, data); +} + +/* + * Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer() + * as they will try to lock the adapter a second time. + */ +static int ltc4306_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 reg, u8 val) +{ + int ret; + + if (adap->algo->master_xfer) { + struct i2c_msg msg; + char buf[2]; + + msg.addr = client->addr; + msg.flags = 0; + msg.len = 2; + buf[0] = reg; + buf[1] = val; + msg.buf = buf; + ret = __i2c_transfer(adap, &msg, 1); + } else { + union i2c_smbus_data data; + + data.byte = val; + ret = adap->algo->smbus_xfer(adap, client->addr, + client->flags, + I2C_SMBUS_WRITE, + reg, + I2C_SMBUS_BYTE_DATA, &data); + } + + return ret; +} + +static int ltc4306_select_mux(struct i2c_mux_core *muxc, u32 chan) +{ + struct ltc4306 *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; + u8 regval; + int ret = 0; + + regval = BIT(7 - chan); + + /* Only select the channel if its different from the last channel */ + if (data->regs[LTC_REG_SWITCH] != regval) { + ret = ltc4306_reg_write(muxc->parent, client, + LTC_REG_SWITCH, regval); + data->regs[LTC_REG_SWITCH] = ret < 0 ? 0 : regval; + } + + return ret; +} + +static int ltc4306_deselect_mux(struct i2c_mux_core *muxc, u32 chan) +{ + struct ltc4306 *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; + + /* Deselect all channels */ + data->regs[LTC_REG_SWITCH] = 0; + + return ltc4306_reg_write(muxc->parent, client, + LTC_REG_SWITCH, data->regs[LTC_REG_SWITCH]); +} + +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; + bool idle_disconnect_dt = false; + struct i2c_mux_core *muxc; + struct ltc4306 *data; + int num, ret; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA)) + return -ENODEV; + + if (of_node) { + idle_disconnect_dt = + of_property_read_bool(of_node, + "i2c-mux-idle-disconnect"); + } + + muxc = i2c_mux_alloc(adap, &client->dev, + LTC4306_MAX_NCHANS, sizeof(*data), 0, + ltc4306_select_mux, idle_disconnect_dt ? + ltc4306_deselect_mux : NULL); + if (!muxc) + return -ENOMEM; + data = i2c_mux_priv(muxc); + + i2c_set_clientdata(client, muxc); + data->client = client; + + /* Enable the mux if an enable GPIO is specified. */ + data->en_gpio = devm_gpiod_get_optional(&client->dev, "enable", + GPIOD_OUT_HIGH); + if (IS_ERR(data->en_gpio)) + return PTR_ERR(data->en_gpio); + + /* + * Write the mux register at addr to verify + * that the mux is in fact present. This also + * initializes the mux to disconnected state. + */ + if (i2c_smbus_write_byte_data(client, LTC_REG_SWITCH, 0) < 0) { + dev_warn(&client->dev, "probe failed\n"); + ret = -ENODEV; + goto gpio_default; + } + + if (of_node) { + data->chip = of_device_get_match_data(&client->dev); + + if (of_property_read_bool(of_node, + "ltc,downstream-accelerators-enable")) + data->regs[LTC_REG_CONFIG] |= LTC_DOWNSTREAM_ACCL_EN; + + if (of_property_read_bool(of_node, + "ltc,upstream-accelerators-enable")) + data->regs[LTC_REG_CONFIG] |= LTC_UPSTREAM_ACCL_EN; + + if (i2c_smbus_write_byte_data(client, LTC_REG_CONFIG, + data->regs[LTC_REG_CONFIG]) < 0) { + dev_warn(&client->dev, "probe failed\n"); + ret = -ENODEV; + goto gpio_default; + } + } else { + data->chip = &chips[id->driver_data]; + } + + ret = ltc4306_gpio_init(data); + if (ret < 0) + goto gpio_default; + + /* 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) { + dev_err(&client->dev, + "failed to register multiplexed adapter %d\n", + num); + goto add_adapter_failed; + } + } + + dev_info(&client->dev, + "registered %d multiplexed busses for I2C switch %s\n", + num, client->name); + + return 0; + +add_adapter_failed: + i2c_mux_del_adapters(muxc); +gpio_default: + gpiod_direction_input(data->en_gpio); + return ret; +} + +static int ltc4306_remove(struct i2c_client *client) +{ + struct i2c_mux_core *muxc = i2c_get_clientdata(client); + struct ltc4306 *data = i2c_mux_priv(muxc); + + i2c_mux_del_adapters(muxc); + gpiod_direction_input(data->en_gpio); + + 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"); -- 2.7.4