diff options
| author | Linus Walleij <linus.walleij@linaro.org> | 2025-02-25 20:40:34 +0100 | 
|---|---|---|
| committer | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2025-03-04 11:29:04 +0100 | 
| commit | bd3ce71078bde4ecbfc60d49c96d1c55de0635cc (patch) | |
| tree | 6c44c1888e4dab5cace37953b9b6b57edb3fed41 /rust/helpers/err.c | |
| parent | 732457dc46d62f1df4b2b48c6dbf22b4332da14b (diff) | |
gpiolib: of: Handle threecell GPIO chips
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@riscstar.com>
Tested-by: Yixun Lan <dlan@gentoo.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://lore.kernel.org/r/20250225-gpio-ranges-fourcell-v3-2-860382ba4713@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'rust/helpers/err.c')
0 files changed, 0 insertions, 0 deletions
