From patchwork Mon Mar 6 08:34:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 64516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1731619wrd; Mon, 6 Mar 2023 01:01:08 -0800 (PST) X-Google-Smtp-Source: AK7set/yTom/M/5fNB79RHd1jIBfo+ufACfFS5+PsJykgqfFH1izM4fJgBjleh1Bx0N0rZkCGSta X-Received: by 2002:a17:906:e4d:b0:8b1:7b5d:fe9b with SMTP id q13-20020a1709060e4d00b008b17b5dfe9bmr10945148eji.28.1678093268656; Mon, 06 Mar 2023 01:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678093268; cv=none; d=google.com; s=arc-20160816; b=z2UYJRs/DVRPau4oERfv1NPkejCpsSjhSCD7OWBaNUiWJozn+e4u74KWqtGOG9yjE7 oqe2h+ZG9ss/d4TpnDpgaw3oaB7xjckwmoSJ7iLcjFBBs6N/6JBRdMymOenslSmKXTOp LPNKfZGwoq9bS7ghbMvz1L8zq+8faq6mmjidQ+HiOAJKK9vEHDGTphiff5k8Cbz94+Yh iWeYn3fY1OPHFfEA2wj2PGOBUPcV1+eoAGjhf0C7YNcHUb2ib1dEvK6JloOxCoO6vGzx OgU8bGxWbaSndm7bkcFM6ZrCywOxeMn3Zyd1bh3UkXtPoUBR4jaji5jfl/LHWbGmD1Zy Auxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=s8tEzPeHE9yCpcFKg4lMZXj79oif2DBoeesb7eM/EOo=; b=lHaWOqxgF8IGh9n4a6ZAvPkrK/m935ju3ZcN8TAN+4GhC9DN1OW2V8x98+DfGlM5FT AnNs+ZHN+rTgqse34bxBgy/ixL86Wl5onnBjn90hovcK0mcL0wnm1OpGe8YrqgpsxU7e ujL8gAAkKcLUvlmi35EwGa46mpBvjJgAytHb5ea1FfqFQQT/VWaI0UkoamwYIcHl2VlA TByW7k//tqRY2Xn4GzUVXgXKtxV5hUbsogE9MNXLAdmVw6xvmhYsiNEIz08CPkIh5vuY bwrwo1WU3WOm2NSJW6eoiRloMfxxSUOKG+h4YLWFkhC0ILCOAfhovCqdA3SazM4wmLb9 6prA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020aa7c6c4000000b004ad745ab9cdsi9502006eds.530.2023.03.06.01.00.44; Mon, 06 Mar 2023 01:01:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjCFIu0 (ORCPT + 99 others); Mon, 6 Mar 2023 03:50:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjCFIuY (ORCPT ); Mon, 6 Mar 2023 03:50:24 -0500 X-Greylist: delayed 607 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 06 Mar 2023 00:50:21 PST Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 929DF113C4; Mon, 6 Mar 2023 00:50:21 -0800 (PST) Received: from francesco-nb.pivistrello.it (93-49-2-63.ip317.fastwebnet.it [93.49.2.63]) by mail11.truemail.it (Postfix) with ESMTPA id DE9B620BA7; Mon, 6 Mar 2023 09:34:50 +0100 (CET) From: Francesco Dolcini To: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org Cc: Emanuele Ghidoli , Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] dt-bindings: gpio: add fcs,fxl6408-gpio binding document Date: Mon, 6 Mar 2023 09:34:45 +0100 Message-Id: <20230306083446.41082-2-francesco@dolcini.it> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230306083446.41082-1-francesco@dolcini.it> References: <20230306083446.41082-1-francesco@dolcini.it> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759607535690829288?= X-GMAIL-MSGID: =?utf-8?q?1759608327183989985?= From: Emanuele Ghidoli Add binding document for Fairchild FXL6408 GPIO expander. Signed-off-by: Emanuele Ghidoli --- .../bindings/gpio/fcs,fxl6408-gpio.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/fcs,fxl6408-gpio.yaml diff --git a/Documentation/devicetree/bindings/gpio/fcs,fxl6408-gpio.yaml b/Documentation/devicetree/bindings/gpio/fcs,fxl6408-gpio.yaml new file mode 100644 index 000000000000..ccf946040d00 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/fcs,fxl6408-gpio.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/fcs,fxl6408-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: FXL6408 GPIO driver + +maintainers: + - Emanuele Ghidoli + +description: | + Driver for Fairchild FXL6408 GPIO expander + +properties: + compatible: + enum: + - fcs,fxl6408 + + reg: + maxItems: 1 + + "#gpio-cells": + const: 2 + + gpio-controller: true + + gpio-line-names: + minItems: 1 + maxItems: 8 + +patternProperties: + "^(hog-[0-9]+|.+-hog(-[0-9]+)?)$": + type: object + properties: + gpio-hog: true + gpios: true + input: true + output-high: true + output-low: true + line-name: true + + required: + - gpio-hog + - gpios + + additionalProperties: false + +required: + - compatible + - reg + - gpio-controller + - "#gpio-cells" + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + gpio_expander_43: gpio-expander@43 { + compatible = "fcs,fxl6408"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x43>; + gpio-line-names = "Wi-Fi_W_DISABLE", "Wi-Fi_WKUP_WLAN", + "PWR_EN_+V3.3_WiFi_N", "PCIe_REF_CLK_EN", + "USB_RESET_N", "USB_BYPASS_N", "Wi-Fi_PDn", + "Wi-Fi_WKUP_BT"; + }; + }; From patchwork Mon Mar 6 08:34:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 64520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1735650wrd; Mon, 6 Mar 2023 01:11:24 -0800 (PST) X-Google-Smtp-Source: AK7set/9JCxqWTCWDQN17qst5qwp3p8UL33HvIri1s1UmlTGpwKUw8ITVrsLt6kKH+AoOLYl5UyP X-Received: by 2002:aa7:dd06:0:b0:4ac:b31c:83d3 with SMTP id i6-20020aa7dd06000000b004acb31c83d3mr8849732edv.14.1678093884011; Mon, 06 Mar 2023 01:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678093883; cv=none; d=google.com; s=arc-20160816; b=VeCSthBoPZ00PwHKAkRZMhZeHXhmX4zJpqQapGmoP4lZMhLOYI4rD52k6xtLE/UCE0 OQlhVQ4OKMHSCk9kANzXRWA791hCC8k9XHImVtEWnhLpX8knSiDjX8EUB9dpJthmBf/N ASBaBCg3RMab3h8loAeE0aDlbfFcOpHD4r+DBHBYIGE6lHUm21HHXqXrtC+OJFxePBBS FENt7eSHMOyJdc88T81rco7HQaYnCv5K1svbOaB14MZTxDBZbTW3UprwdpNd+bSV8Iel rId+AHK6gsTvAqF3n6eiZVf90i/XUPzU9wu1C9WIDsJWF/oXRJstYgut8l0HUEp7JeMy zLtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=og0ecnaje4XmSe39iAYi9mMnyu+jVqwclnvQvPEpjrQ=; b=YsniVp0zlj9xNme9fiKQSY7ktcrx/0P9UFJGTkV4ggO4p7NoWWkDBMaIn91thdNpte Pn2BzBx4Z2k3Q+TTcXMKXG2tbf0FEEI6phex/WREkT/XKn1aohCXP9m5oymwqzQGfs7/ h6qTRZ3rRODbz3TD3RcT3NOjNjlJr+3JZfkw+5f4cwWIJLuIEzHLyVXucxizT0tbSN5C T9ae080aJdxZVE5bnNGtuLEE+SLVOvMUMqB7VrEBXfcOxYYGKK/POFZ0HBYsjgSxZZH0 xZ9za+ZYa+gzr9SoFw4QgK1NMuYMT+t3JE6CAA3kj0DGpyiPmoC/yPqc+h9ShfMSc03O MuEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy22-20020a05640231f600b004c40c7e12f4si10786677edb.125.2023.03.06.01.11.00; Mon, 06 Mar 2023 01:11:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbjCFIub (ORCPT + 99 others); Mon, 6 Mar 2023 03:50:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbjCFIuY (ORCPT ); Mon, 6 Mar 2023 03:50:24 -0500 Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BBBB113EF; Mon, 6 Mar 2023 00:50:21 -0800 (PST) Received: from francesco-nb.pivistrello.it (93-49-2-63.ip317.fastwebnet.it [93.49.2.63]) by mail11.truemail.it (Postfix) with ESMTPA id 5675620BAA; Mon, 6 Mar 2023 09:34:51 +0100 (CET) From: Francesco Dolcini To: linux-gpio@vger.kernel.org, Linus Walleij , Bartosz Golaszewski Cc: Emanuele Ghidoli , linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] gpio: fxl6408: add I2C GPIO expander driver Date: Mon, 6 Mar 2023 09:34:46 +0100 Message-Id: <20230306083446.41082-3-francesco@dolcini.it> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230306083446.41082-1-francesco@dolcini.it> References: <20230306083446.41082-1-francesco@dolcini.it> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759608382211274729?= X-GMAIL-MSGID: =?utf-8?q?1759608972682181050?= From: Emanuele Ghidoli Support Fairchild (now ON Semiconductor) fxl6408 which has 8 GPIO lines and is controlled by I2C bus. Signed-off-by: Emanuele Ghidoli --- drivers/gpio/Kconfig | 6 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-fxl6408.c | 160 ++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 drivers/gpio/gpio-fxl6408.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 13be729710f2..34ed748dba5c 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1000,6 +1000,12 @@ config GPIO_ADNP enough to represent all pins, but the driver will assume a register layout for 64 pins (8 registers). +config GPIO_FXL6408 + tristate "FXL6408 I2C GPIO expander" + select GPIO_REGMAP + help + GPIO driver for Fairchild Semiconductor FXL6408 GPIO expander + config GPIO_GW_PLD tristate "Gateworks PLD GPIO Expander" depends on OF_GPIO diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index c048ba003367..12027f4c3bee 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o obj-$(CONFIG_GPIO_FTGPIO010) += gpio-ftgpio010.o +obj-$(CONFIG_GPIO_FXL6408) += gpio-fxl6408.o obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o diff --git a/drivers/gpio/gpio-fxl6408.c b/drivers/gpio/gpio-fxl6408.c new file mode 100644 index 000000000000..7b28b09c7b66 --- /dev/null +++ b/drivers/gpio/gpio-fxl6408.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * FXL6408 GPIO driver + * + * Copyright 2023 Toradex + * + * Author: Emanuele Ghidoli + * + */ + +#include +#include +#include +#include +#include +#include + +#define FXL6408_REG_DEVICE_ID 0x01 +#define FXL6408_MF_FAIRCHILD 0b101 +#define FXL6408_MF_SHIFT 5 + +/* Bits set here indicate that the GPIO is an output. */ +#define FXL6408_REG_IO_DIR 0x03 + +/* Bits set here, when the corresponding bit of IO_DIR is set, drive + * the output high instead of low. + */ +#define FXL6408_REG_OUTPUT 0x05 + +/* Bits here make the output High-Z, instead of the OUTPUT value. */ +#define FXL6408_REG_OUTPUT_HIGH_Z 0x07 + +/* Returns the current status (1 = HIGH) of the input pins. */ +#define FXL6408_REG_INPUT_STATUS 0x0f + +#define FXL6408_MAX_REGISTER 0x13 + +#define FXL6408_NGPIO 8 + +static const struct regmap_range rd_range[] = { + { FXL6408_REG_DEVICE_ID, FXL6408_REG_DEVICE_ID }, + { FXL6408_REG_IO_DIR, FXL6408_REG_OUTPUT }, + { FXL6408_REG_INPUT_STATUS, FXL6408_REG_INPUT_STATUS } +}; + +static const struct regmap_range wr_range[] = { + { FXL6408_REG_DEVICE_ID, FXL6408_REG_DEVICE_ID }, + { FXL6408_REG_IO_DIR, FXL6408_REG_OUTPUT }, + { FXL6408_REG_OUTPUT_HIGH_Z, FXL6408_REG_OUTPUT_HIGH_Z } +}; + +static const struct regmap_range volatile_range[] = { + { FXL6408_REG_DEVICE_ID, FXL6408_REG_DEVICE_ID }, + { FXL6408_REG_INPUT_STATUS, FXL6408_REG_INPUT_STATUS } +}; + +static const struct regmap_access_table rd_table = { + .yes_ranges = rd_range, + .n_yes_ranges = ARRAY_SIZE(rd_range) +}; + +static const struct regmap_access_table wr_table = { + .yes_ranges = wr_range, + .n_yes_ranges = ARRAY_SIZE(wr_range) +}; + +static const struct regmap_access_table volatile_table = { + .yes_ranges = volatile_range, + .n_yes_ranges = ARRAY_SIZE(volatile_range) +}; + +static const struct regmap_config regmap = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = FXL6408_MAX_REGISTER, + .wr_table = &wr_table, + .rd_table = &rd_table, + .volatile_table = &volatile_table, + + .cache_type = REGCACHE_RBTREE, + .num_reg_defaults_raw = FXL6408_MAX_REGISTER + 1 +}; + +static int fxl6408_identify(struct device *dev, struct regmap *regmap) +{ + int val, ret; + + ret = regmap_read(regmap, FXL6408_REG_DEVICE_ID, &val); + if (ret) { + dev_err(dev, "error %d reading DEVICE_ID\n", ret); + } else if (val >> FXL6408_MF_SHIFT != FXL6408_MF_FAIRCHILD) { + dev_err(dev, "invalid device id 0x%02x\n", val); + ret = -ENODEV; + } + + return ret; +} + +static int fxl6408_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + int ret; + struct gpio_regmap_config gpio_config = { + .parent = dev, + .ngpio = FXL6408_NGPIO, + .reg_dat_base = GPIO_REGMAP_ADDR(FXL6408_REG_INPUT_STATUS), + .reg_set_base = GPIO_REGMAP_ADDR(FXL6408_REG_OUTPUT), + .reg_dir_out_base = GPIO_REGMAP_ADDR(FXL6408_REG_IO_DIR), + .ngpio_per_reg = FXL6408_NGPIO + }; + gpio_config.regmap = devm_regmap_init_i2c(client, ®map); + + if (IS_ERR(gpio_config.regmap)) { + dev_err(dev, "failed to allocate register map\n"); + return PTR_ERR(gpio_config.regmap); + } + + ret = fxl6408_identify(dev, gpio_config.regmap); + if (ret) + return ret; + + /* Disable High-Z of outputs, so that our OUTPUT updates + * actually take effect. + */ + ret = regmap_write(gpio_config.regmap, FXL6408_REG_OUTPUT_HIGH_Z, 0); + if (ret) { + dev_err(dev, "failed to write 'output high Z' register\n"); + return ret; + } + + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config)); +} + +static const __maybe_unused struct of_device_id fxl6408_dt_ids[] = { + { .compatible = "fcs,fxl6408" }, + { } +}; +MODULE_DEVICE_TABLE(of, fxl6408_dt_ids); + +static const struct i2c_device_id fxl6408_id[] = { + { "fxl6408", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, fxl6408_id); + +static struct i2c_driver fxl6408_driver = { + .driver = { + .name = "fxl6408", + .of_match_table = fxl6408_dt_ids, + }, + .probe_new = fxl6408_probe, + .id_table = fxl6408_id, +}; + +module_i2c_driver(fxl6408_driver); + +MODULE_AUTHOR("Emanuele Ghidoli "); +MODULE_DESCRIPTION("FXL6408 GPIO driver"); +MODULE_LICENSE("GPL");