Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,35 @@ 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;

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),
Expand All @@ -515,6 +544,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),
{}
};

Expand Down
28 changes: 22 additions & 6 deletions drivers/hid/dockchannel-hid/dockchannel-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,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
Expand Down Expand Up @@ -1025,9 +1031,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);
Expand Down Expand Up @@ -1088,6 +1094,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;
Expand All @@ -1104,10 +1121,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. */
Expand Down
Loading