From: Chanhong Jung <happycpu@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Maxime Ripard <mripard@kernel.org>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] gpio: 74x164: support lines-initial-states for boot-time output state
Date: Wed, 29 Apr 2026 12:51:34 +0900 [thread overview]
Message-ID: <20260429035134.1023330-3-happycpu@gmail.com> (raw)
In-Reply-To: <cover.1776872453.git.happycpu@gmail.com>
74HC595 and 74LVC594 chains retain their output state from the first
serial write onwards. Today the driver always kicks that first write
from a zero-initialised buffer, so every output comes up low until user
space issues a write. Boards that rely on the chain to drive signals
whose power-on state matters (active-low indicators, reset lines, etc.)
have no way to express the desired initial pattern via DT.
Read the optional lines-initial-states bitmask, recently documented for
this binding, into chip->buffer before the first
__gen_74x164_write_config() so the chain comes up in a known state on
the very first SPI transaction. Bit N maps to GPIO line N (matching the
nxp,pcf8575 convention); on this output-only device, bit=0 drives the
line low and bit=1 drives it high. Property absence keeps the existing
zeroing behaviour intact.
Suggested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Chanhong Jung <happycpu@gmail.com>
---
drivers/gpio/gpio-74x164.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
index c226524ef..5ca61cf52 100644
--- a/drivers/gpio/gpio-74x164.c
+++ b/drivers/gpio/gpio-74x164.c
@@ -112,7 +112,7 @@ static int gen_74x164_probe(struct spi_device *spi)
{
struct device *dev = &spi->dev;
struct gen_74x164_chip *chip;
- u32 nregs;
+ u32 nregs, init_state;
int ret;
/*
@@ -134,6 +134,21 @@ static int gen_74x164_probe(struct spi_device *spi)
chip->registers = nregs;
+ /*
+ * Optionally seed the chain with a board-specified pattern so the
+ * outputs come up in a known state on the first SPI write. The
+ * property follows the nxp,pcf8575 convention where bit N maps to
+ * GPIO line N. On this output-only device, bit=0 drives the line
+ * low and bit=1 drives it high. The bitmask covers up to 32 lines;
+ * any further outputs come up zeroed by devm_kzalloc().
+ */
+ if (!device_property_read_u32(dev, "lines-initial-states", &init_state)) {
+ unsigned int i;
+
+ for (i = 0; i < min(nregs, 4U); i++)
+ chip->buffer[nregs - 1 - i] = (init_state >> (i * 8)) & 0xff;
+ }
+
chip->gpiod_oe = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
if (IS_ERR(chip->gpiod_oe))
return PTR_ERR(chip->gpiod_oe);
--
2.34.1
next prev parent reply other threads:[~2026-04-29 3:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 16:05 [PATCH v1 0/2] gpio: 74x164: seed the chain from DT at probe time Chanhong Jung
2026-04-22 16:05 ` [PATCH v1 1/2] dt-bindings: gpio: fairchild,74hc595: add registers-default property Chanhong Jung
2026-04-23 8:59 ` Krzysztof Kozlowski
2026-04-23 10:33 ` Chanhong Jung
2026-04-28 8:40 ` Krzysztof Kozlowski
2026-04-28 9:07 ` Linus Walleij
2026-04-29 3:50 ` Chanhong Jung
2026-04-29 9:03 ` Bartosz Golaszewski
2026-05-05 9:45 ` Linus Walleij
2026-05-05 11:00 ` Bartosz Golaszewski
2026-05-05 20:24 ` Rob Herring
2026-04-22 16:05 ` [PATCH v1 2/2] gpio: 74x164: support 'registers-default' DT property for initial state Chanhong Jung
2026-04-29 3:51 ` [PATCH v2 0/2] gpio: 74x164: seed the chain from DT at probe time Chanhong Jung
2026-05-06 8:09 ` Bartosz Golaszewski
2026-04-29 3:51 ` [PATCH v2 1/2] dt-bindings: gpio: fairchild,74hc595: add lines-initial-states property Chanhong Jung
2026-04-30 12:08 ` Linus Walleij
2026-05-06 1:43 ` Rob Herring (Arm)
2026-04-29 3:51 ` Chanhong Jung [this message]
2026-04-30 12:09 ` [PATCH v2 2/2] gpio: 74x164: support lines-initial-states for boot-time output state Linus Walleij
2026-04-30 22:14 ` 정찬홍
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260429035134.1023330-3-happycpu@gmail.com \
--to=happycpu@gmail.com \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.