gpio: mmio: handle "ngpios" properly in bgpio_init()
PATCH 1/1 gpio: mmio: handle "ngpios" properly in bgpio_init()
bgpio_init() uses "sz" argument to populate ngpio, which is not accurate. Instead, read the "ngpios" property from the DT and if it doesn't exist, use the "sz" argument. With this change, drivers no longer need to overwrite the ngpio variable after calling bgpio_init().
If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().
The following 2 patches were approved in the past but didn't make it into the tree. I combined them into one patch since the second one fixes a bug in the first one:
[PATCH v4] gpio: mmio: handle "ngpios" properly in bgpio_init() [PATCH v1] gpio: mmio: fix calculation of bgpio_bits
--- drivers/gpio/gpio-mmio.c | 9 +++++- drivers/gpio/gpiolib.c | 68 ++++++++++++++++++++++------------------ drivers/gpio/gpiolib.h | 1 + 3 files changed, 46 insertions(+), 32 deletions(-)
drivers/gpio/gpio-mmio.c +8 -1
@@ -60,6 +60,8 @@ o ` ~~~~\___/~~~~ ` controller in FPGA is ,.`#include <linux/of.h> #include <linux/of_device.h> +#include "gpiolib.h" +static void bgpio_write8 (void __iomem *reg,unsigned long data) {writeb (data, reg);
@@ -614,10 +616,15 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev, gc->parent = dev; gc->label =dev_name (dev); gc->base =-1 ; - gc->ngpio = gc->bgpio_bits; gc->request = bgpio_request; gc->be_bits = !!(flags &BGPIOF_BIG_ENDIAN ); + ret =gpiochip_get_ngpios (gc, dev); +if (ret) + gc->ngpio = gc->bgpio_bits; +else + gc->bgpio_bits =roundup_pow_of_two (round_up (gc->ngpio,8 )); + ret =bgpio_setup_io (gc, dat, set, clr, flags);if (ret)return ret;
drivers/gpio/gpiolib.c +37 -31
93 lines not on this page · raw message
drivers/gpio/gpiolib.h +1 -0
@@ -217,6 +217,7 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,int gpio_set_debounce_timeout (struct gpio_desc *desc,unsigned int debounce);int gpiod_hog (struct gpio_desc *desc,const char *name,unsigned long lflags,enum gpiod_flags dflags); +int gpiochip_get_ngpios (struct gpio_chip *gc,struct device *dev);/* * Return the GPIO number of the passed descriptor relative to its chip
Signature · 1 line
2.30.1
Quoted 11 lines · Asmaa Mnebhi
bgpio_init()uses "sz" argument to populate ngpio, which is not accurate. Instead, read the "ngpios" property from the DT and if it doesn't exist, use the "sz" argument. With this change, drivers no longer need to overwrite the ngpio variable after callingbgpio_init().If the "ngpios" property is specified,
bgpio_bitsis calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size inbgpio_setup_accessors().
The below should be in the changelog area. Moreover, it doesn't explain why you dropped my tags.
Quoted 5 lines
The following 2 patches were approved in the past but didn't make it into the tree. I combined them into one patch since the second one fixes a bug in the first one:
[PATCH v4] gpio: mmio: handle "ngpios" properly inbgpio_init()[PATCH v1] gpio: mmio: fix calculation ofbgpio_bits
Please, try again.
Signature · 2 lines
With Best Regards, Andy Shevchenko