From 185dc0f3991ab61406293b634e205fb7dd82d99f Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Wed, 2 Dec 2026 07:27:19 -0500 Subject: [PATCH 1/2] HID: dockchannel-hid: bind afe_reset on power-method-2 fallback and clear starting on timeout When an interface does not pin apple,power-method in DT, dchid_get_interface() initializes it with power method 1 and leaves iface->reset NULL. On Macs whose MTP 27.2+ firmware rejects power method 1 with 0xe00002c2 (for example J516s), dchid_start_interface() switches iface->power_method to DCHID_POWER_METHOD_2 at runtime, asserts dchid->afe_reset when adopting a retained MTP session, resends the firmware, and calls dchid_pm2_set_power(iface, DCHID_POWER_STATE_ON). Commit 4e9a79628fc5 ("HID: dockchannel-hid: bring up the kiwi (touch screen) interface") refactored dchid_pm2_set_power() to drive iface->reset through dchid_set_own_lines() instead of dchid->afe_reset directly, but the runtime fallback path never assigned iface->reset = dchid->afe_reset. Because gpiod_direction_output(NULL, 0) silently returns 0, AFE reset was never released (and the 50 ms settle was skipped), leaving the multi-touch AFE held in reset until start timed out after 10 s. In addition, when wait_for_completion_timeout(&iface->ready, ...) timed out in dchid_open(), iface->starting remained true permanently, causing every subsequent open of the HID input device to fail with -EINPROGRESS ("Interface multi-touch is already starting"). Bind iface->reset = iface->dchid->afe_reset when falling back to power method 2, reject a NULL iface->reset in dchid_set_own_lines() with -EINVAL instead of silently no-oping, and clear iface->starting when waiting for ready finishes or times out. Add KUnit tests for both cases. Fixes: 4e9a79628fc5 ("HID: dockchannel-hid: bring up the kiwi (touch screen) interface") Signed-off-by: Diljit Singh --- .../dockchannel-hid-parser-test.c | 34 +++++++++++++++++++ drivers/hid/dockchannel-hid/dockchannel-hid.c | 32 +++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c index fcbc4a3cc9e19..2edb745534bca 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c @@ -498,6 +498,38 @@ static void dchid_ring_bad_header_test(struct kunit *test) KUNIT_EXPECT_EQ(test, iface->dchid->ring_read, 0U); } +static void dchid_pm2_fallback_binds_afe_reset_test(struct kunit *test) +{ + struct dchid_iface *iface = test->priv; + struct gpio_desc *fake_afe_reset = (struct gpio_desc *)0x1; + + iface->dchid->afe_reset = fake_afe_reset; + iface->power_method = DCHID_POWER_METHOD_1; + iface->reset = NULL; + + /* Without a bound reset line, driving lines must fail instead of no-oping. */ + KUNIT_EXPECT_EQ(test, dchid_set_own_lines(iface, DCHID_POWER_STATE_ON), -EINVAL); + + dchid_enter_pm2_fallback(iface); + KUNIT_EXPECT_EQ(test, iface->power_method, DCHID_POWER_METHOD_2); + KUNIT_EXPECT_PTR_EQ(test, iface->reset, fake_afe_reset); +} + +static void dchid_wait_ready_timeout_clears_starting_test(struct kunit *test) +{ + struct dchid_iface *iface = test->priv; + + init_completion(&iface->ready); + iface->starting = true; + KUNIT_EXPECT_EQ(test, dchid_wait_ready(iface, 0), -ETIMEDOUT); + KUNIT_EXPECT_FALSE(test, iface->starting); + + iface->starting = true; + complete_all(&iface->ready); + KUNIT_EXPECT_EQ(test, dchid_wait_ready(iface, 0), 0); + KUNIT_EXPECT_FALSE(test, iface->starting); +} + static struct kunit_case dchid_parser_cases[] = { KUNIT_CASE(dchid_unaligned_checksum_test), KUNIT_CASE(dchid_short_ack_test), @@ -515,6 +547,8 @@ static struct kunit_case dchid_parser_cases[] = { KUNIT_CASE(dchid_packet_checksum_test), KUNIT_CASE(dchid_ring_wrap_test), KUNIT_CASE(dchid_ring_bad_header_test), + KUNIT_CASE(dchid_pm2_fallback_binds_afe_reset_test), + KUNIT_CASE(dchid_wait_ready_timeout_clears_starting_test), {} }; diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index 1104ccc6b801d..f33817063803b 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -711,9 +711,11 @@ static int dchid_register_ring(struct dockchannel_hid *dchid) static int dchid_set_own_lines(struct dchid_iface *iface, u8 state) { bool on = state == DCHID_POWER_STATE_ON; - int ret; + if (!iface->reset) + return -EINVAL; + if (on && iface->power) { ret = gpiod_direction_output(iface->power, 1); if (ret < 0) @@ -723,6 +725,12 @@ static int dchid_set_own_lines(struct dchid_iface *iface, u8 state) return gpiod_direction_output(iface->reset, !on); } +static void dchid_enter_pm2_fallback(struct dchid_iface *iface) +{ + iface->power_method = DCHID_POWER_METHOD_2; + iface->reset = iface->dchid->afe_reset; +} + /* * Power method 2: announce the transition, drive the interface's reset line * to the new state and confirm the transition. The reset is asserted for a @@ -1025,9 +1033,9 @@ static int dchid_start_interface(struct dchid_iface *iface) dev_info(iface->dchid->dev, "%s: power method 1 rejected (0x%x); retrying with power method 2\n", iface->name, fw_retcode); - iface->power_method = DCHID_POWER_METHOD_2; + dchid_enter_pm2_fallback(iface); if (iface->dchid->inherited_mtp) { - ret = gpiod_direction_output(iface->dchid->afe_reset, 1); + ret = gpiod_direction_output(iface->reset, 1); if (ret < 0) goto err; fsleep(50 * USEC_PER_MSEC); @@ -1088,6 +1096,17 @@ static void dchid_stop(struct hid_device *hdev) device_remove_file(&hdev->dev, &dev_attr_apple_layout_id); } +static int dchid_wait_ready(struct dchid_iface *iface, unsigned int timeout_ms) +{ + if (!wait_for_completion_timeout(&iface->ready, msecs_to_jiffies(timeout_ms))) { + iface->starting = false; + dev_err(iface->dchid->dev, "iface %s start timed out\n", iface->name); + return -ETIMEDOUT; + } + iface->starting = false; + return 0; +} + static int dchid_open(struct hid_device *hdev) { struct dchid_iface *iface = hdev->driver_data; @@ -1104,10 +1123,9 @@ static int dchid_open(struct hid_device *hdev) timeout_ms = iface->power_method == DCHID_POWER_METHOD_2 ? PM2_START_TIMEOUT_MS : START_TIMEOUT_MS; - if (!wait_for_completion_timeout(&iface->ready, msecs_to_jiffies(timeout_ms))) { - dev_err(iface->dchid->dev, "iface %s start timed out\n", iface->name); - return -ETIMEDOUT; - } + ret = dchid_wait_ready(iface, timeout_ms); + if (ret < 0) + return ret; } /* Pairs with the acquire in dchid_handle_report(); publishes iface->hid. */ From ea8ac57f6efd196803ebe425367e477232248c5b Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:57:32 +0000 Subject: [PATCH 2/2] HID: dockchannel-hid: keep a missing reset line a no-op Returning -EINVAL from dchid_set_own_lines() when iface->reset is NULL turns the old optional-GPIO no-op into a hard failure, including on suspend and resume, for any power-method-2 interface without a DT reset line on other boards. Drop the check and its KUnit assertion. The power-method-2 fallback still binds iface->reset to afe_reset, so the J516s multi-touch fix is unchanged. Signed-off-by: DjDeveloperr --- drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c | 3 --- drivers/hid/dockchannel-hid/dockchannel-hid.c | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c index 2edb745534bca..3b2f2fb1f9e28 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c @@ -507,9 +507,6 @@ static void dchid_pm2_fallback_binds_afe_reset_test(struct kunit *test) iface->power_method = DCHID_POWER_METHOD_1; iface->reset = NULL; - /* Without a bound reset line, driving lines must fail instead of no-oping. */ - KUNIT_EXPECT_EQ(test, dchid_set_own_lines(iface, DCHID_POWER_STATE_ON), -EINVAL); - dchid_enter_pm2_fallback(iface); KUNIT_EXPECT_EQ(test, iface->power_method, DCHID_POWER_METHOD_2); KUNIT_EXPECT_PTR_EQ(test, iface->reset, fake_afe_reset); diff --git a/drivers/hid/dockchannel-hid/dockchannel-hid.c b/drivers/hid/dockchannel-hid/dockchannel-hid.c index f33817063803b..d4290e457d69f 100644 --- a/drivers/hid/dockchannel-hid/dockchannel-hid.c +++ b/drivers/hid/dockchannel-hid/dockchannel-hid.c @@ -711,10 +711,8 @@ static int dchid_register_ring(struct dockchannel_hid *dchid) static int dchid_set_own_lines(struct dchid_iface *iface, u8 state) { bool on = state == DCHID_POWER_STATE_ON; - int ret; - if (!iface->reset) - return -EINVAL; + int ret; if (on && iface->power) { ret = gpiod_direction_output(iface->power, 1);