Re: [PATCH v3 2/2] gpiolib: of: Handle threecell GPIO chips

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 25, 2025 at 1:40 PM Linus Walleij <linus.walleij@xxxxxxxxxx> wrote:
>
> When describing GPIO controllers in the device tree, the ambition
> of device tree to describe the hardware may require a three-cell
> scheme:
>
> gpios = <&gpio instance offset flags>;
>
> This implements support for this scheme in the gpiolib OF core.
>
> Drivers that want to handle multiple gpiochip instances from one
> OF node need to implement a callback similar to this to
> determine if a certain gpio chip is a pointer to the right
> instance (pseudo-code):
>
> struct my_gpio {
>     struct gpio_chip gcs[MAX_CHIPS];
> };
>
> static bool my_of_node_instance_match(struct gpio_chip *gc
>                                       unsigned int instance)
> {
>     struct my_gpio *mg = gpiochip_get_data(gc);
>
>     if (instance >= MAX_CHIPS)
>         return false;
>     return (gc == &mg->gcs[instance]);
> }
>
> probe() {
>     struct my_gpio *mg;
>     struct gpio_chip *gc;
>     int i, ret;
>
>     for (i = 0; i++; i < MAX_CHIPS) {
>         gc = &mg->gcs[i];
>         /* This tells gpiolib we have several instances per node */
>         gc->of_gpio_n_cells = 3;
>         gc->of_node_instance_match = my_of_node_instance_match;
>         gc->base = -1;
>         ...
>
>         ret = devm_gpiochip_add_data(dev, gc, mg);
>         if (ret)
>             return ret;
>     }
> }
>
> Rename the "simple" of_xlate function to "twocell" which is closer
> to what it actually does.
>
> In the device tree bindings, the provide node needs
> to specify #gpio-cells = <3>; where the first cell is the instance
> number:
>
> gpios = <&gpio instance offset flags>;
>
> Conversely ranges need to have four cells:
>
> gpio-ranges = <&pinctrl instance gpio_offset pin_offset count>;
>
> Reviewed-by: Alex Elder <elder@xxxxxxxxxxxx>
> Tested-by: Yixun Lan <dlan@xxxxxxxxxx>
> Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
> ---
>  drivers/gpio/gpiolib-of.c   | 95 +++++++++++++++++++++++++++++++++++++++------
>  include/linux/gpio/driver.h | 24 +++++++++++-
>  2 files changed, 107 insertions(+), 12 deletions(-)

Reviewed-by: Rob Herring (Arm) <robh@xxxxxxxxxx>





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux