lede/target/linux/bcm27xx/patches-6.12/950-0501-gpiolib-Override-gpiochip-numbers-with-DT-aliases.patch
=?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= d81c03f05e bcm27xx: add 6.12 patches from RPi repo
These patches were generated from:
https://github.com/raspberrypi/linux/commits/rpi-6.12.y
With the following command:
git format-patch -N v6.12.27..HEAD
(HEAD -> 8d3206ee456a5ecdf9ddbfd8e5e231e4f0cd716e)

Exceptions:
- (def)configs patches
- github workflows patches
- applied & reverted patches
- readme patches
- wireless patches

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2025-06-20 17:01:06 +08:00

51 lines
1.6 KiB
Diff

From ca7e4be0461beb04e2433f802e97721b6ff40fe0 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Thu, 2 May 2024 16:17:02 +0100
Subject: [PATCH] gpiolib: Override gpiochip numbers with DT aliases
In the same way that other subsystems support the setting of device
id numbers from Device Tree aliases, allow gpiochip numbers to be
derived from "gpiochip<n>" aliases.
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
drivers/gpio/gpiolib.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -105,6 +105,7 @@ static int gpiochip_irqchip_init_valid_m
static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
static bool gpiolib_initialized;
+static int first_dynamic_gpiochip_num = -1;
const char *gpiod_get_label(struct gpio_desc *desc)
{
@@ -927,6 +928,7 @@ int gpiochip_add_data_with_key(struct gp
unsigned int desc_index;
int base = 0;
int ret = 0;
+ int id;
/*
* First: allocate and populate the internal stat container, and
@@ -953,7 +955,16 @@ int gpiochip_add_data_with_key(struct gp
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;