[PATCH 2/2] pinctrl: sx150x: move wide registers in a single block transfer

From: Dean Sellers

Date: Wed Nov 18 2026 - 02:03:20 EST


The regmap accessors build each logical register from one SMBus byte
access per byte. On a 16-line part every register on the interrupt path
is 16 bits wide, so servicing one interrupt costs six i2c transfers: two
to read RegInterruptSource, two to ack it, and two more when gpiolib
reads RegData back to report the line level.

Measured on an SX1509Q on a 100 kHz bus, each transfer costs about
0.6 ms, of which roughly 0.36 ms is time on the wire and the rest is
fixed adapter overhead. The transfer count dominates interrupt latency,
and it is well above the minimum hardware debounce period of 0.5 ms. The
longer the latency, the wider the window in which a second edge merges
into a latch bit that is already set and is lost.

The 789 parts auto-increment the register address across a multi-byte
access unless that is disabled in RegMisc[1]. The bit is clear out of
reset and sx150x_init_misc() leaves it clear, so a wide register can be
moved in one transfer. That takes the interrupt path from six transfers
to three.

Enable this only on the 789 models, and only when the adapter advertises
I2C_FUNC_SMBUS_I2C_BLOCK. The 123 and 456 parts stay on byte-at-a-time
access, because their datasheets do not document the same
auto-increment behaviour.

A short block read is reported as -EIO, so a truncated transfer is
never returned as a register value.

Signed-off-by: Dean Sellers <dean@xxxxxxxxxxxxx>
---
drivers/pinctrl/pinctrl-sx150x.c | 44 ++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index c97e9bc3a33f..970f9d8bd809 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -38,6 +38,8 @@ enum {
enum {
SX150X_789_REG_MISC_AUTOCLEAR_OFF = 1 << 0,
SX150X_MAX_REGISTER = 0xad,
+ /* Widest logical register is the 32-bit RegSense quartet. */
+ SX150X_MAX_REG_BYTES = 4,
SX150X_IRQ_TYPE_EDGE_RISING = 0x1,
SX150X_IRQ_TYPE_EDGE_FALLING = 0x2,
SX150X_789_RESET_KEY1 = 0x12,
@@ -105,6 +107,8 @@ struct sx150x_pinctrl {
} irq;
struct mutex lock;
const struct sx150x_device_data *data;
+ /* Wide registers can be moved in one i2c block transfer */
+ bool block_xfer;
};

static const struct pinctrl_pin_desc sx150x_4_pins[] = {
@@ -1065,6 +1069,24 @@ static int sx150x_regmap_reg_read(void *context, unsigned int reg,
* reg + 3 [ 3 3 2 2 1 1 0 0 ]
*/

+ if (pctl->block_xfer && width > 8) {
+ const int count = width / 8;
+ u8 buf[SX150X_MAX_REG_BYTES];
+
+ ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
+ if (ret < 0)
+ return ret;
+ if (ret != count)
+ return -EIO;
+
+ for (n = 0, val = 0; n < count; n++)
+ val = (val << 8) | buf[n];
+
+ *result = sx150x_maybe_swizzle(pctl, reg, val);
+
+ return 0;
+ }
+
for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) {
val <<= 8;

@@ -1090,6 +1112,17 @@ static int sx150x_regmap_reg_write(void *context, unsigned int reg,

val = sx150x_maybe_swizzle(pctl, reg, val);

+ if (pctl->block_xfer && width > 8) {
+ const int count = width / 8;
+ u8 buf[SX150X_MAX_REG_BYTES];
+ int i;
+
+ for (i = 0, n = (width - 1) & ~7; i < count; i++, n -= 8)
+ buf[i] = (val >> n) & 0xff;
+
+ return i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
+ }
+
n = (width - 1) & ~7;
do {
const u8 byte = (val >> n) & 0xff;
@@ -1150,6 +1183,17 @@ static int sx150x_probe(struct i2c_client *client)
if (!pctl->data)
return -EINVAL;

+ /*
+ * The 789 parts auto-increment the register address across a
+ * multi-byte access unless that is disabled in RegMisc, which
+ * sx150x_init_misc() leaves enabled, so a wide register can be moved
+ * in one transfer. The 123 and 456 datasheets do not document the
+ * same behaviour, so those parts stay on byte-at-a-time access.
+ */
+ pctl->block_xfer = pctl->data->model == SX150X_789 &&
+ i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_I2C_BLOCK);
+
pctl->regmap = devm_regmap_init(dev, NULL, pctl,
&sx150x_regmap_config);
if (IS_ERR(pctl->regmap)) {
--
2.43.0