[PATCH] gpio: cgbc: Add init_valid_mask() operation

From: Thomas Richard (congatec GmbH)

Date: Fri Oct 16 2026 - 13:14:09 EST


Some pins can be reconfigured from the BIOS as alternate functions,
which makes the corresponding GPIO lines unusable. Add the
init_valid_mask() operation to mark as valid only the GPIOs which are
usable.

Signed-off-by: Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>
---
drivers/gpio/gpio-cgbc.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/drivers/gpio/gpio-cgbc.c b/drivers/gpio/gpio-cgbc.c
index 84b5ed3c6e22..1b603d8eccda 100644
--- a/drivers/gpio/gpio-cgbc.c
+++ b/drivers/gpio/gpio-cgbc.c
@@ -18,6 +18,7 @@
#define CGBC_GPIO_CMD_SET 0x65
#define CGBC_GPIO_CMD_DIR_GET 0x66
#define CGBC_GPIO_CMD_DIR_SET 0x67
+#define CGBC_GPIO_CMD_ENA_RD 0x84

struct cgbc_gpio_data {
struct gpio_chip chip;
@@ -146,6 +147,30 @@ static int cgbc_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
return GPIO_LINE_DIRECTION_IN;
}

+static int cgbc_gpio_init_valid_mask(struct gpio_chip *chip,
+ unsigned long *valid_mask,
+ unsigned int ngpios)
+{
+ struct cgbc_gpio_data *gpio = gpiochip_get_data(chip);
+ struct cgbc_device_data *cgbc = gpio->cgbc;
+ int ret;
+ u8 val;
+
+ ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_ENA_RD, 0, 0, &val);
+ if (ret)
+ return ret;
+
+ *valid_mask = val;
+
+ ret = cgbc_gpio_cmd(cgbc, CGBC_GPIO_CMD_ENA_RD, 1, 0, &val);
+ if (ret)
+ return ret;
+
+ *valid_mask |= (val << 8);
+
+ return 0;
+}
+
static int cgbc_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -172,6 +197,7 @@ static int cgbc_gpio_probe(struct platform_device *pdev)
chip->get_direction = cgbc_gpio_get_direction;
chip->get = cgbc_gpio_get;
chip->set = cgbc_gpio_set;
+ chip->init_valid_mask = cgbc_gpio_init_valid_mask;
chip->ngpio = CGBC_GPIO_NGPIO;

ret = devm_mutex_init(dev, &gpio->lock);

---
base-commit: 7b47e2aec8d31ded7b996b7676d4d01d5e71736d
change-id: 20261016-cgbc-gpio-valid-mask-a08c365d0a4f

Best regards,
--
Thomas Richard (congatec GmbH) <thomas.richard@xxxxxxxxxxx>