From ab05515757fcb77edbbe7c68fbc7c0c930c0f668 Mon Sep 17 00:00:00 2001 From: Romain Sioen Date: Fri, 6 Feb 2026 17:31:53 +0100 Subject: [PATCH 1/3] HID: mcp2221: use mcp_i2c_smbus_read for block reads Refactor mcp_smbus_xfer() to use the mcp_i2c_smbus_read() helper function for I2C_SMBUS_BLOCK_DATA and I2C_SMBUS_I2C_BLOCK_DATA read operations. This replaces the manual setup of the receive buffer and explicit calls to mcp_send_data_req_status(), making the code cleaner and more consistent with other read paths in the driver. Signed-off-by: Romain Sioen Signed-off-by: Marius Cristea Signed-off-by: Jiri Kosina --- drivers/hid/hid-mcp2221.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 33603b019f97..64dcedbcc0fc 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -534,10 +534,10 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr, if (ret) goto exit; - mcp->rxbuf_idx = 0; - mcp->rxbuf = data->block; - mcp->txbuf[0] = MCP2221_I2C_GET_DATA; - ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); + ret = mcp_i2c_smbus_read(mcp, NULL, + MCP2221_I2C_RD_RPT_START, + addr, data->block[0] + 1, + data->block); if (ret) goto exit; } else { @@ -553,14 +553,14 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr, case I2C_SMBUS_I2C_BLOCK_DATA: if (read_write == I2C_SMBUS_READ) { ret = mcp_smbus_write(mcp, addr, command, NULL, - 0, MCP2221_I2C_WR_NO_STOP, 1); + 0, MCP2221_I2C_WR_NO_STOP, 0); if (ret) goto exit; - mcp->rxbuf_idx = 0; - mcp->rxbuf = data->block; - mcp->txbuf[0] = MCP2221_I2C_GET_DATA; - ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); + ret = mcp_i2c_smbus_read(mcp, NULL, + MCP2221_I2C_RD_RPT_START, + addr, data->block[0], + &data->block[1]); if (ret) goto exit; } else { From 200e6c6e94fa786e36e4fe33eebf16b822181b99 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 18 Feb 2026 14:44:38 +0100 Subject: [PATCH 2/3] HID: mcp2221: Add module parameter to enfoce GPIO mode Add a module parameter to MCP2221 to enfor GPIO mode on the general purpose pins GP0 thru GP3. If I plug a device of this type into my machine, it will use the GP0, GP1, GP2 and GP3 pins for IIO voltage readings by default if CONFIG_IIO is set. However there may be cases where IIO is available but we want to use the GP0 thru GP3 lines for GPIO anyway. Example use: insmode hid-mcp2221.ko gpio_mode_enforce=1 Result in dmesg: mcp2221 0003:04D8:00DD.0005: GPIO 0 not in gpio mode mcp2221 0003:04D8:00DD.0005: GPIO 1 not in gpio mode mcp2221 0003:04D8:00DD.0005: GPIO 2 not in gpio mode mcp2221 0003:04D8:00DD.0005: GPIO 3 not in gpio mode mcp2221 0003:04D8:00DD.0005: Set GPIO mode for gpio pin 0! mcp2221 0003:04D8:00DD.0005: Set GPIO mode for gpio pin 1! mcp2221 0003:04D8:00DD.0005: Set GPIO mode for gpio pin 2! mcp2221 0003:04D8:00DD.0005: Set GPIO mode for gpio pin 3! After this the gpiolib tools such as gpioset can be used to alter the GPIO line values successfully. Signed-off-by: Linus Walleij Signed-off-by: Jiri Kosina --- drivers/hid/hid-mcp2221.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 64dcedbcc0fc..5c643f3c8c97 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -19,8 +19,15 @@ #include #include #include +#include #include "hid-ids.h" +static bool gpio_mode_enforce; + +module_param(gpio_mode_enforce, bool, 0644); +MODULE_PARM_DESC(gpio_mode_enforce, + "Enfore GPIO mode for GP0 thru GP3 (default: false, will be used for IIO)"); + /* Commands codes in a raw output report */ enum { MCP2221_I2C_WR_DATA = 0x90, @@ -648,7 +655,7 @@ static int mcp2221_check_gpio_pinfunc(struct mcp2221 *mcp) int needgpiofix = 0; int ret; - if (IS_ENABLED(CONFIG_IIO)) + if (IS_ENABLED(CONFIG_IIO) && !gpio_mode_enforce) return 0; ret = mcp_gpio_read_sram(mcp); @@ -1043,7 +1050,8 @@ static void mcp2221_remove(struct hid_device *hdev) #if IS_REACHABLE(CONFIG_IIO) struct mcp2221 *mcp = hid_get_drvdata(hdev); - cancel_delayed_work_sync(&mcp->init_work); + if (!gpio_mode_enforce) + cancel_delayed_work_sync(&mcp->init_work); #endif } @@ -1317,8 +1325,10 @@ static int mcp2221_probe(struct hid_device *hdev, #endif #if IS_REACHABLE(CONFIG_IIO) - INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work); - schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100)); + if (!gpio_mode_enforce) { + INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work); + schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100)); + } #endif return 0; From ac977b900907f621e117184e71766f297a2f702b Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sat, 14 Mar 2026 17:02:25 +0000 Subject: [PATCH 3/3] HID: mcp2221: Fix spelling mistake "Enfore" -> "Enforce" There is a spelling mistake in a module description. Fix it. Signed-off-by: Colin Ian King Reviewed-by: Linus Walleij Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-mcp2221.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 5c643f3c8c97..f503d1a557b8 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -26,7 +26,7 @@ static bool gpio_mode_enforce; module_param(gpio_mode_enforce, bool, 0644); MODULE_PARM_DESC(gpio_mode_enforce, - "Enfore GPIO mode for GP0 thru GP3 (default: false, will be used for IIO)"); + "Enforce GPIO mode for GP0 thru GP3 (default: false, will be used for IIO)"); /* Commands codes in a raw output report */ enum {