RFC: gpio: mmio: add support for 3 direction regs

From: Fried, Ramon
Date: Thu Jan 03 2019 - 02:36:11 EST


Hi.

I'm working on a driver for STA2X11 GPIO controller who seems to fit best to the generic mmio driver,
the only problem I have is with the dir register case.
The STA2X11 has 3 registers for dir, one for data, one for set and one for clear.
The generic-mmio driver has support for this fashion for the dat & set & clear registers but not for dirout/dirin registers.

I wonder if support for this is generic enough to deserve a patch, if so I'm willing to quickly add this support, if not, adding a flag such as below, will allow partly using the generic mmio driver only for set/get and the direction can be handled outside the driver.

Thanks,
Ramon

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index a4d5eb3..4f91526 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -435,6 +435,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
Â#define BGPIOF_BIG_ENDIAN_BYTE_ORDERÂÂ BIT(3)
Â#define BGPIOF_READ_OUTPUT_REG_SETÂÂÂÂ BIT(4) /* reg_set stores output value */
Â#define BGPIOF_NO_OUTPUTÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BIT(5) /* only input */
+#define BGPIOF_NO_DIRECTIONÂÂÂÂÂÂÂÂÂÂÂ BIT(6)
Â
Â#endif

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index 935292a..66f6448 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -554,6 +554,8 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->direction_input = bgpio_dir_in;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->get_direction = bgpio_get_dir;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->bgpio_dir_inverted = true;
+ÂÂÂÂÂÂ } else if (flags & BGPIOF_NO_DIRECTION) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
ÂÂÂÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (flags & BGPIOF_NO_OUTPUT)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->direction_output = bgpio_dir_out_err;
@@ -638,7 +640,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
ÂÂÂÂÂÂÂ if (gc->set == bgpio_set_set &&
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ !(flags & BGPIOF_UNREADABLE_REG_SET))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->bgpio_data = gc->read_reg(gc->reg_set);
-ÂÂÂÂÂÂ if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR))
+ÂÂÂÂÂÂ if (gc->reg_dir && !(flags & (BGPIOF_UNREADABLE_REG_DIR | BGPIOF_NO_DIRECTION)))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gc->bgpio_dir = gc->read_reg(gc->reg_dir);
Â
ÂÂÂÂÂÂÂ return ret;