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 /include/linux/gpio | |
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 'include/linux/gpio')
-rw-r--r-- | include/linux/gpio/driver.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 783897d94be8..83e0a7e86962 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -531,11 +531,33 @@ struct gpio_chip { /** * @of_gpio_n_cells: * - * Number of cells used to form the GPIO specifier. + * Number of cells used to form the GPIO specifier. The standard is 2 + * cells: + * + * gpios = <&gpio offset flags>; + * + * some complex GPIO controllers instantiate more than one chip per + * device tree node and have 3 cells: + * + * gpios = <&gpio instance offset flags>; + * + * Legacy GPIO controllers may even have 1 cell: + * + * gpios = <&gpio offset>; */ unsigned int of_gpio_n_cells; /** + * of_node_instance_match: + * + * Determine if a chip is the right instance. Must be implemented by + * any driver using more than one gpio_chip per device tree node. + * Returns true if gc is the instance indicated by i (which is the + * first cell in the phandles for GPIO lines and gpio-ranges). + */ + bool (*of_node_instance_match)(struct gpio_chip *gc, unsigned int i); + + /** * @of_xlate: * * Callback to translate a device tree GPIO specifier into a chip- |