mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
gpio: ad7768: Add AD7768 GPIO auxiliary driver
The AD7768 provides five GPIOs controlled through registers shared with the parent IIO device. Register an auxiliary gpio-regmap driver and use the parent device for runtime PM. The device has separate input-state and output-latch registers. Add a reg_mask_xlate() callback that checks the line direction and reads the programmed output latch for output lines while retaining input-state reads for input lines. Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Signed-off-by: Janani Sunil <janani.sunil@analog.com> Link: https://patch.msgid.link/20260910-ad7768-gpio-v8-3-6aaaa15adeb3@analog.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
This commit is contained in:
parent
73748b4ec5
commit
ea4f5a734c
|
|
@ -1818,6 +1818,18 @@ endmenu
|
|||
menu "Auxiliary Bus GPIO drivers"
|
||||
depends on AUXILIARY_BUS
|
||||
|
||||
config GPIO_AD7768
|
||||
tristate "Analog Devices AD7768 GPIO support"
|
||||
depends on AD7768
|
||||
depends on GPIOLIB
|
||||
select GPIO_REGMAP
|
||||
help
|
||||
Say yes here to expose the AD7768 utility pins as GPIOs when the
|
||||
device tree node is marked as a GPIO controller.
|
||||
|
||||
To compile this driver as a module, choose M here: the module will be
|
||||
called gpio-ad7768.
|
||||
|
||||
config GPIO_LTC4283
|
||||
tristate "Analog Devices LTC4283 GPIO support"
|
||||
depends on SENSORS_LTC4283
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o
|
|||
obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o
|
||||
obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o
|
||||
obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o
|
||||
obj-$(CONFIG_GPIO_AD7768) += gpio-ad7768.o
|
||||
obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
|
||||
obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
|
||||
obj-$(CONFIG_GPIO_ADP5585) += gpio-adp5585.o
|
||||
|
|
|
|||
121
drivers/gpio/gpio-ad7768.c
Normal file
121
drivers/gpio/gpio-ad7768.c
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Analog Devices AD7768 GPIO auxiliary driver
|
||||
*
|
||||
* Copyright 2026 Analog Devices Inc.
|
||||
*/
|
||||
|
||||
#include <linux/auxiliary_bus.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/gpio/driver.h>
|
||||
#include <linux/gpio/regmap.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/property.h>
|
||||
#include <linux/regmap.h>
|
||||
|
||||
#define AD7768_REG_GPIO_CONTROL 0x0E
|
||||
#define AD7768_GPIO_UGPIO_ENABLE BIT(7)
|
||||
|
||||
#define AD7768_REG_GPIO_WRITE 0x0F
|
||||
#define AD7768_REG_GPIO_READ 0x10
|
||||
|
||||
#define AD7768_NUM_GPIOS 5
|
||||
#define AD7768_FILTER_GPIO 4
|
||||
|
||||
static int ad7768_gpio_init_valid_mask(struct gpio_chip *gc,
|
||||
unsigned long *valid_mask,
|
||||
unsigned int ngpios)
|
||||
{
|
||||
if (ngpios > AD7768_FILTER_GPIO &&
|
||||
fwnode_property_match_string(gc->fwnode, "clock-names", "mclk") < 0)
|
||||
__clear_bit(AD7768_FILTER_GPIO, valid_mask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ad7768_gpio_reg_mask_xlate(struct gpio_regmap *gpio,
|
||||
enum gpio_regmap_operation op,
|
||||
unsigned int base, unsigned int offset,
|
||||
unsigned int *reg, unsigned int *mask)
|
||||
{
|
||||
struct regmap *regmap = gpio_regmap_get_drvdata(gpio);
|
||||
int ret;
|
||||
|
||||
*reg = base;
|
||||
*mask = BIT(offset);
|
||||
|
||||
if (op != GPIO_REGMAP_GET_OP)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* AD7768 has separate input-state and output-latch registers. For an
|
||||
* output line, report the programmed value from the output latch;
|
||||
* input lines continue to use the input-state register.
|
||||
*/
|
||||
ret = regmap_test_bits(regmap, AD7768_REG_GPIO_CONTROL, *mask);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret)
|
||||
*reg = AD7768_REG_GPIO_WRITE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ad7768_gpio_probe(struct auxiliary_device *adev,
|
||||
const struct auxiliary_device_id *id)
|
||||
{
|
||||
struct gpio_regmap_config config;
|
||||
struct device *dev = &adev->dev;
|
||||
struct device *parent = dev->parent;
|
||||
struct regmap *map;
|
||||
int ret;
|
||||
|
||||
map = dev_get_regmap(parent, NULL);
|
||||
if (!map)
|
||||
return -ENODEV;
|
||||
|
||||
PM_RUNTIME_ACQUIRE_AUTOSUSPEND(parent, pm);
|
||||
ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regmap_set_bits(map, AD7768_REG_GPIO_CONTROL, AD7768_GPIO_UGPIO_ENABLE);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
config = (struct gpio_regmap_config) {
|
||||
.parent = dev,
|
||||
.regmap = map,
|
||||
.label = dev_name(parent),
|
||||
.ngpio = AD7768_NUM_GPIOS,
|
||||
.reg_dat_base = AD7768_REG_GPIO_READ,
|
||||
.reg_set_base = AD7768_REG_GPIO_WRITE,
|
||||
.reg_dir_out_base = AD7768_REG_GPIO_CONTROL,
|
||||
.pm_dev = parent,
|
||||
.fwnode = dev_fwnode(parent),
|
||||
.reg_mask_xlate = ad7768_gpio_reg_mask_xlate,
|
||||
.init_valid_mask = ad7768_gpio_init_valid_mask,
|
||||
.drvdata = map,
|
||||
};
|
||||
|
||||
return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &config));
|
||||
}
|
||||
|
||||
static const struct auxiliary_device_id ad7768_gpio_ids[] = {
|
||||
{ .name = "ad7768.gpio" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(auxiliary, ad7768_gpio_ids);
|
||||
|
||||
static struct auxiliary_driver ad7768_gpio_driver = {
|
||||
.probe = ad7768_gpio_probe,
|
||||
.id_table = ad7768_gpio_ids,
|
||||
};
|
||||
module_auxiliary_driver(ad7768_gpio_driver);
|
||||
|
||||
MODULE_AUTHOR("Janani Sunil <janani.sunil@analog.com>");
|
||||
MODULE_DESCRIPTION("Analog Devices AD7768 GPIO auxiliary driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
Loading…
Reference in New Issue
Block a user