From nobody Sat Jun 13 08:44:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9DBD3DFC92; Fri, 8 May 2026 12:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778244692; cv=none; b=M1NbGAx+tmf/BI1GflBH5XrL4BOAQ4waHOfU5ljuEVKGz/+qSEwetTsh39IsjYhAFWAgwM9ShGR4Nb2Vz8NO/z5wA38e3APURvUHp9ITi4f+NwUv3kbMDJ8lZNOfl+s6vfwywz+OGCKbF2U6EU5j17CXFEmHKjOWScEO9+0B21o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778244692; c=relaxed/simple; bh=Z4d/UAJ3M/A/sbfOgSOipQRQ0aIMTxR/C/kevDeLGxI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bHt5SfuF9pYegBKujLWwTMQrdvrf3WmtA1wZ1WyLuNaWJdpLyE5dRBPmejbS4qy48sgZy1L1Tcj0CYNaSie9AnLSPVh4SUEKoHBQyKlm9DnRmXCYuT34JK2PdUxTk3Ggj7RYcjphomU7wRnj9mIsHLQN9Q/ZAePtFtOGtJgaSZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FKUyhf6a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FKUyhf6a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09DC9C2BCC7; Fri, 8 May 2026 12:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778244692; bh=Z4d/UAJ3M/A/sbfOgSOipQRQ0aIMTxR/C/kevDeLGxI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FKUyhf6aEYY/o1EdFVCeQCxr6Yi1+RaEskmn0l6hwp5p5pvLn21uINwH60p1B/q7t 7cUQZuCYXYU2nnC9BZqSxL1NeuAhbmp1uRjXf0MmTCfr30VeQs9TiJawFgF6oY1a/s UEoyh6zf37dV1Sim8ejtSFqk5zpD0Yh6BhG4FQpmbPL9FgctP9792IY7x0U1H0mxoO ZwAPEYOrKV3+ZlkAk1Kl+wu5ERk5Cc987ygRlHlg6CDAcg+NqsabcxnaetaHABDuow nyGINvFDHk+EsHhd+FpcAIUsEk0dZG16JYgch71xRwTMYDumqxZ+jhQLoL7I13UYwU zGdnmwFNvmZ0w== From: Linus Walleij Date: Fri, 08 May 2026 14:51:26 +0200 Subject: [PATCH v2 1/2] gpio: regmap: Support sparsed fixed direction Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260508-regmap-gpio-sparse-fixed-dir-v2-1-deee84df3027@kernel.org> References: <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org> In-Reply-To: <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org> To: Michael Walle , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij , Alex Elder X-Mailer: b4 0.15.2 On some regmapped GPIOs apparently only a sparser selection of the lines (not all) are actually fixed direction. Support this situation by adding an optional bitmap indicating which GPIOs are actually fixed direction and which are not. Cc: Alex Elder Link: https://lore.kernel.org/linux-gpio/20260501155421.3329862-10-elder@ri= scstar.com/ Tested-by: Alex Elder Signed-off-by: Linus Walleij Reviewed-by: Alex Elder --- drivers/gpio/gpio-regmap.c | 37 +++++++++++++++++++++++++++++++++---- include/linux/gpio/regmap.h | 7 +++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 9ae4a41a2427..f45a432e8ebe 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -31,6 +31,7 @@ struct gpio_regmap { unsigned int reg_clr_base; unsigned int reg_dir_in_base; unsigned int reg_dir_out_base; + unsigned long *fixed_direction_sparse; unsigned long *fixed_direction_output; =20 #ifdef CONFIG_REGMAP_IRQ @@ -138,6 +139,20 @@ static int gpio_regmap_set_with_clear(struct gpio_chip= *chip, return regmap_write(gpio->regmap, reg, mask); } =20 +static bool gpio_regmap_fixed_direction(struct gpio_regmap *gpio, + unsigned int offset) +{ + if (!gpio->fixed_direction_output) + return false; + + /* In this case only some GPIOs are fixed as input/output */ + if (gpio->fixed_direction_sparse && + !test_bit(offset, gpio->fixed_direction_sparse)) + return false; + + return true; +} + static int gpio_regmap_get_direction(struct gpio_chip *chip, unsigned int offset) { @@ -145,7 +160,7 @@ static int gpio_regmap_get_direction(struct gpio_chip *= chip, unsigned int base, val, reg, mask; int invert, ret; =20 - if (gpio->fixed_direction_output) { + if (gpio_regmap_fixed_direction(gpio, offset)) { if (test_bit(offset, gpio->fixed_direction_output)) return GPIO_LINE_DIRECTION_OUT; else @@ -302,12 +317,23 @@ struct gpio_regmap *gpio_regmap_register(const struct= gpio_regmap_config *config goto err_free_gpio; } =20 + if (config->fixed_direction_sparse) { + gpio->fixed_direction_sparse =3D bitmap_alloc(chip->ngpio, + GFP_KERNEL); + if (!gpio->fixed_direction_sparse) { + ret =3D -ENOMEM; + goto err_free_gpio; + } + bitmap_copy(gpio->fixed_direction_sparse, + config->fixed_direction_sparse, chip->ngpio); + } + if (config->fixed_direction_output) { gpio->fixed_direction_output =3D bitmap_alloc(chip->ngpio, GFP_KERNEL); if (!gpio->fixed_direction_output) { ret =3D -ENOMEM; - goto err_free_gpio; + goto err_free_bitmap_sparse; } bitmap_copy(gpio->fixed_direction_output, config->fixed_direction_output, chip->ngpio); @@ -329,7 +355,7 @@ struct gpio_regmap *gpio_regmap_register(const struct g= pio_regmap_config *config =20 ret =3D gpiochip_add_data(chip, gpio); if (ret < 0) - goto err_free_bitmap; + goto err_free_bitmap_output; =20 #ifdef CONFIG_REGMAP_IRQ if (config->regmap_irq_chip) { @@ -355,8 +381,10 @@ struct gpio_regmap *gpio_regmap_register(const struct = gpio_regmap_config *config =20 err_remove_gpiochip: gpiochip_remove(chip); -err_free_bitmap: +err_free_bitmap_output: bitmap_free(gpio->fixed_direction_output); +err_free_bitmap_sparse: + bitmap_free(gpio->fixed_direction_sparse); err_free_gpio: kfree(gpio); return ERR_PTR(ret); @@ -376,6 +404,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio) =20 gpiochip_remove(&gpio->gpio_chip); bitmap_free(gpio->fixed_direction_output); + bitmap_free(gpio->fixed_direction_sparse); kfree(gpio); } EXPORT_SYMBOL_GPL(gpio_regmap_unregister); diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 12d154732ca9..ff00b4aeaf1c 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -38,6 +38,12 @@ struct regmap; * offset to a register/bitmask pair. If not * given the default gpio_regmap_simple_xlate() * is used. + * @fixed_direction_sparse: + * (Optional) Bitmap representing the GPIO lines that + * make use of the @fixed_direction_output list to + * enforce direction of the GPIO. If this is NULL + * and @fixed_direction_output is defined, ALL GPIOs + * are assumed to be fixed direction (out or in). * @fixed_direction_output: * (Optional) Bitmap representing the fixed direction of * the GPIO lines. Useful when there are GPIO lines with a @@ -89,6 +95,7 @@ struct gpio_regmap_config { int reg_stride; int ngpio_per_reg; struct irq_domain *irq_domain; + unsigned long *fixed_direction_sparse; unsigned long *fixed_direction_output; =20 #ifdef CONFIG_REGMAP_IRQ --=20 2.54.0 From nobody Sat Jun 13 08:44:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8B6D3E0C4B; Fri, 8 May 2026 12:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778244694; cv=none; b=WWYvCnpq/0MrFNUg8Z/mRKWvBZo3qdq80BGPs4vrGGlnfFKhDAgRRUvlkl0rT6wYYiJWF2iEJLG4FH4XE0maYzc979wa6XztLYMPRMfWdqXSQcKx3sKg7gJtPw+bwri+4uPUGWRcNOJKo5R/eiq9dWHKMtUGey/9sCDdnv/rRAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778244694; c=relaxed/simple; bh=1VxQGneYMsXJIX225dqHkzOd38aTPB8bOOneM5Nayi0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kuWFPZz3g5+sU3+0FIprDjhLwbtRgoU9uugdOwDY4XkWRjRjXG1IsQA6Idsr2aV4052oRPQdGhagPBclL29kT9f7hJ8nE6y1VPMh4RhrB9egiYlQYQkqie66fNjj94F2Yy3xjPq1v+9I6YrXZXvhD9jR4npZ2fywkV9BMYE9CQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TNuM9Of1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TNuM9Of1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15E60C2BCC7; Fri, 8 May 2026 12:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778244694; bh=1VxQGneYMsXJIX225dqHkzOd38aTPB8bOOneM5Nayi0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TNuM9Of1kHTccbRfVLYhTkeB0VeVGgtE64fqo8yacSSWyfNw6OyRGO1X/n77go8QT QS1LjouH/lvB9GHTKTHzFSRLmJxDibJUwpXnEszhJKcztZDfAA6KqNKGsNChYl0NOI 8CZgDUW1XqQfbshtgcNdWtK5pLQjDbGN9qBvOoo9uifC4JnRJbOraXc9bpiz2hGMv+ GdvpqIldj360fiGk0zI+cIVP1XIvKPLBi4p1JIxwqf14+vwbuW3MLvHr3lz9BLl2OF sNx8dWo/086iQd+LG4BskF/zJevKVESIYMLYD8NWHOl5cWu4d/ArkUl1I02IlpKPNY EkEgYmVmDIutQ== From: Linus Walleij Date: Fri, 08 May 2026 14:51:27 +0200 Subject: [PATCH v2 2/2] gpio: regmap: Don't set a fixed direction line Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260508-regmap-gpio-sparse-fixed-dir-v2-2-deee84df3027@kernel.org> References: <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org> In-Reply-To: <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org> To: Michael Walle , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij , Sashiko X-Mailer: b4 0.15.2 If a GPIO line has a fixed direction, there is no point in trying to set the direction. This didn't happen much before because what we supported was all lines input or output and then the implementer would probably not specify the direction registers, but with sparse fixed direction we can have a mixture so let's take this into account. Suggested-by: Sashiko Link: https://sashiko.dev/#/patchset/20260507-regmap-gpio-sparse-fixed-dir-= v1-1-a2e5855e2701%40kernel.org Signed-off-by: Linus Walleij --- drivers/gpio/gpio-regmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index f45a432e8ebe..52a67dea8107 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -203,6 +203,9 @@ static int gpio_regmap_set_direction(struct gpio_chip *= chip, unsigned int base, val, reg, mask; int invert, ret; =20 + if (gpio_regmap_fixed_direction(gpio, offset)) + return 0; + if (gpio->reg_dir_out_base) { base =3D gpio_regmap_addr(gpio->reg_dir_out_base); invert =3D 0; --=20 2.54.0