Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] HID: mcp2221: Keep IIO initialization retries per device
@ 2026-11-13  1:40 tuhaowen
  2026-11-13  1:45 ` sashiko-bot
  2026-11-13  1:55 ` [PATCH v2] " Haowen Tu
  0 siblings, 2 replies; 3+ messages in thread
From: tuhaowen @ 2026-11-13  1:40 UTC (permalink / raw)
  To: gupt21; +Cc: jikos, bentiss, linux-i2c, linux-input, linux-kernel, tuhaowen

mcp_init_work() uses a static retry counter, so all MCP2221 devices share
the same retry budget. Initializing one device can exhaust the retries
available to another device, including a new instance after unplugging
and reconnecting the bridge.

When the counter reaches zero, the post-decrement also changes it to -1.
A subsequent instance that receives -EAGAIN will then keep rescheduling
its initialization work instead of stopping at the intended limit.
Different devices can also update the shared counter concurrently.

Store the retry budget in struct mcp2221 and initialize it before queuing
the IIO initialization work. Check for exhaustion before decrementing so
the counter stays at zero once the retry limit is reached.

Fixes: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
Signed-off-by: tuhaowen <tuhaowen@uniontech.com>
---
 drivers/hid/hid-mcp2221.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 3f05d6e288f9..f8f4788ba935 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -136,6 +136,7 @@ struct mcp2221 {
 	u8 gpio_dir;
 	u8 mode[4];
 #if IS_REACHABLE(CONFIG_IIO)
+	unsigned int iio_init_retries;
 	struct iio_chan_spec iio_channels[3];
 	u16 adc_values[3];
 	u8 adc_scale;
@@ -1190,7 +1191,6 @@ static void mcp_init_work(struct work_struct *work)
 	struct iio_dev *indio_dev;
 	struct mcp2221 *mcp = container_of(work, struct mcp2221, init_work.work);
 	struct mcp2221_iio *data;
-	static int retries = 5;
 	int ret, num_channels;
 
 	hid_hw_power(mcp->hdev, PM_HINT_FULLON);
@@ -1238,8 +1238,9 @@ static void mcp_init_work(struct work_struct *work)
 	mutex_unlock(&mcp->lock);
 	hid_hw_power(mcp->hdev, PM_HINT_NORMAL);
 
-	if (!retries--)
+	if (!mcp->iio_init_retries)
 		return;
+	mcp->iio_init_retries--;
 
 	/* Device is not ready to read SRAM or FLASH data, try again */
 	schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
@@ -1346,6 +1347,7 @@ static int mcp2221_probe(struct hid_device *hdev,
 #endif
 
 #if IS_REACHABLE(CONFIG_IIO)
+	mcp->iio_init_retries = 5;
 	INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work);
 	if (!gpio_mode_enforce)
 		schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-13  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  1:40 [PATCH] HID: mcp2221: Keep IIO initialization retries per device tuhaowen
2026-11-13  1:45 ` sashiko-bot
2026-11-13  1:55 ` [PATCH v2] " Haowen Tu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox