diff mbox series

[v5,4/4] gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

Message ID 20221123053512.1195309-5-mranostay@ti.com (mailing list archive)
State New, archived
Headers show
Series mfd: add tps6594 support for Jacinto platforms | expand

Commit Message

Matt Ranostay Nov. 23, 2022, 5:35 a.m. UTC
Add support for TPS6594 PMICs GPIO interface that has 11 that can be
configured as input or outputs.

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 drivers/gpio/Kconfig        |  9 +++++
 drivers/gpio/Makefile       |  1 +
 drivers/gpio/gpio-tps6594.c | 78 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594.h |  4 ++
 4 files changed, 92 insertions(+)
 create mode 100644 drivers/gpio/gpio-tps6594.c

Comments

Tony Lindgren Nov. 23, 2022, 7:11 a.m. UTC | #1
* Matt Ranostay <mranostay@ti.com> [221123 05:35]:
> Add support for TPS6594 PMICs GPIO interface that has 11 that can be
> configured as input or outputs.

Reviewed-by: Tony Lindgren <tony@atomide.com>
Michael Walle Nov. 23, 2022, 8:40 a.m. UTC | #2
Am 2022-11-23 06:35, schrieb Matt Ranostay:

> +static int tps6594_regmap_xlate(struct gpio_regmap *gpio,
> +				    unsigned int base, unsigned int offset,
> +				    unsigned int *reg, unsigned int *mask)
> +{
> +	if (base == TPS6594_GPIO_CONF) {
> +		*reg = base + offset;
> +		*mask = GPIO_CFG_MASK;
> +	} else {
> +		unsigned int line = offset % GPIO_BANK_SIZE;
> +		unsigned int stride = offset / GPIO_BANK_SIZE;
> +
> +		*reg = base + stride;
> +		*mask = BIT(line);
> +	}

This looks like a duplcate from gpio_regmap_simple_xlate(). Maybe
we can export it and do

if (base == TPS6594_GPIO_CONF) {
	*reg = base + offset;
	*mask = GPIO_CFG_MASK;
} else {
	return gpio_regmap_simple_xlate(gpio, base, offset, reg, mask);
}

Apart from that
Reviewed-by: Michael Walle <michael@walle.cc>

-michael
Bartosz Golaszewski Dec. 1, 2022, 9:10 a.m. UTC | #3
On Wed, Nov 23, 2022 at 6:35 AM Matt Ranostay <mranostay@ti.com> wrote:
>
> Add support for TPS6594 PMICs GPIO interface that has 11 that can be
> configured as input or outputs.
>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---

I think you forgot to collect Linus' and my review tags.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index ec7cfd4f52b1..f34b3746075a 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1405,6 +1405,15 @@  config GPIO_TPS65912
 	help
 	  This driver supports TPS65912 GPIO chip.
 
+config GPIO_TPS6594
+	tristate "TI TPS6594 GPIO driver"
+	depends on MFD_TPS6594 || COMPILE_TEST
+	select REGMAP
+	select GPIO_REGMAP
+	help
+	  Select this option to enable GPIO driver for the TPS6954
+	  PMIC chip family. There are 11 GPIOs that can be configured.
+
 config GPIO_TPS68470
 	tristate "TPS68470 GPIO"
 	depends on INTEL_SKL_INT3472
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 010587025fc8..31bef1cc112f 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -159,6 +159,7 @@  obj-$(CONFIG_GPIO_TPS65218)		+= gpio-tps65218.o
 obj-$(CONFIG_GPIO_TPS6586X)		+= gpio-tps6586x.o
 obj-$(CONFIG_GPIO_TPS65910)		+= gpio-tps65910.o
 obj-$(CONFIG_GPIO_TPS65912)		+= gpio-tps65912.o
+obj-$(CONFIG_GPIO_TPS6594)		+= gpio-tps6594.o
 obj-$(CONFIG_GPIO_TPS68470)		+= gpio-tps68470.o
 obj-$(CONFIG_GPIO_TQMX86)		+= gpio-tqmx86.o
 obj-$(CONFIG_GPIO_TS4800)		+= gpio-ts4800.o
diff --git a/drivers/gpio/gpio-tps6594.c b/drivers/gpio/gpio-tps6594.c
new file mode 100644
index 000000000000..983c37a77266
--- /dev/null
+++ b/drivers/gpio/gpio-tps6594.c
@@ -0,0 +1,78 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPIO driver for TI TPS6594 PMICs
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#include <linux/gpio/regmap.h>
+#include <linux/gpio/driver.h>
+#include <linux/mfd/tps6594.h>
+
+#define GPIO_BANK_SIZE	8
+#define GPIO_CFG_MASK	BIT(0)
+
+static int tps6594_regmap_xlate(struct gpio_regmap *gpio,
+				    unsigned int base, unsigned int offset,
+				    unsigned int *reg, unsigned int *mask)
+{
+	if (base == TPS6594_GPIO_CONF) {
+		*reg = base + offset;
+		*mask = GPIO_CFG_MASK;
+	} else {
+		unsigned int line = offset % GPIO_BANK_SIZE;
+		unsigned int stride = offset / GPIO_BANK_SIZE;
+
+		*reg = base + stride;
+		*mask = BIT(line);
+	}
+
+	return 0;
+}
+
+static int tps6594_gpio_probe(struct platform_device *pdev)
+{
+	struct gpio_regmap_config config = {0};
+	struct regmap *regmap;
+
+	regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!regmap)
+		return -ENODEV;
+
+	config.regmap = regmap;
+	config.parent = &pdev->dev;
+	config.ngpio = 11;
+	config.ngpio_per_reg = GPIO_BANK_SIZE;
+
+	config.reg_dat_base = TPS6594_GPIO_IN;
+	config.reg_set_base = TPS6594_GPIO_OUT;
+	config.reg_dir_out_base = TPS6594_GPIO_CONF;
+	config.reg_mask_xlate = tps6594_regmap_xlate;
+
+	return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config));
+}
+
+static const struct of_device_id of_tps6594_gpio_match[] = {
+	{ .compatible = "ti,tps6594-gpio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594_gpio_match);
+
+static struct platform_driver tps6594_gpio_driver = {
+	.driver = {
+		.name = "tps6594-gpio",
+		.of_match_table = of_tps6594_gpio_match,
+	},
+	.probe = tps6594_gpio_probe,
+};
+module_platform_driver(tps6594_gpio_driver);
+
+MODULE_ALIAS("platform:tps6594-gpio");
+MODULE_AUTHOR("Matt Ranostay <mranostay@ti.com>");
+MODULE_DESCRIPTION("TPS6594 GPIO driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h
index f721ec9880dd..758b1bc44178 100644
--- a/include/linux/mfd/tps6594.h
+++ b/include/linux/mfd/tps6594.h
@@ -21,6 +21,10 @@ 
 #define TPS6594_FSM_I2C_TRIGGERS		0x85
 #define TPS6594_FSM_NSLEEP_TRIGGERS		0x86
 
+#define TPS6594_GPIO_CONF			0x31
+#define TPS6594_GPIO_OUT			0x3d
+#define TPS6594_GPIO_IN			0x3f
+
 #define TPS6594_RTC_SECONDS			0xb5
 #define TPS6594_RTC_MINUTES			0xb6
 #define TPS6594_RTC_HOURS			0xb7