Skip to content

Use gpiochip0 for the user-facing GPIOs on Pi 5 #6144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/arm64/boot/dts/broadcom/bcm2712-rpi.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
gpio2 = &gio_aon;
gpio3 = &pinctrl;
gpio4 = &pinctrl_aon;
gpiochip0 = &gpio;
gpiochip10 = &gio;
i2c = &i2c_arm;
i2c0 = &i2c0;
i2c1 = &i2c1;
Expand Down
13 changes: 12 additions & 1 deletion drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);

static bool gpiolib_initialized;
static int first_dynamic_gpiochip_num = -1;

static inline void desc_set_label(struct gpio_desc *d, const char *label)
{
Expand Down Expand Up @@ -745,6 +746,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
unsigned int i;
int base = 0;
int ret = 0;
int id;

/*
* First: allocate and populate the internal stat container, and
Expand All @@ -769,7 +771,16 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
else if (gc->parent)
device_set_node(&gdev->dev, dev_fwnode(gc->parent));

gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL);
if (first_dynamic_gpiochip_num < 0) {
id = of_alias_get_highest_id("gpiochip");
first_dynamic_gpiochip_num = (id >= 0) ? (id + 1) : 0;
}

id = of_alias_get_id(gdev->dev.of_node, "gpiochip");
if (id < 0)
id = first_dynamic_gpiochip_num;

gdev->id = ida_alloc_range(&gpio_ida, id, ~0, GFP_KERNEL);
if (gdev->id < 0) {
ret = gdev->id;
goto err_free_gdev;
Expand Down