Skip to content
17 changes: 17 additions & 0 deletions Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ properties:
description:
Reset line of the STM interface, pulsed on the coprocessor's request.

apple,afe-smc:
$ref: /schemas/types.yaml#/definitions/phandle
description:
The SMC whose gp1c key powers the trackpad analog front end. With it
the host drives the key low to power the multi-touch interface on
and high to power it off, between the coprocessor's power transition
notifications.

apple,no-stm:
type: boolean
description:
Expand Down Expand Up @@ -198,6 +206,15 @@ required:
additionalProperties: false

allOf:
- if:
properties:
compatible:
not:
contains:
const: apple,t6041-dockchannel-hid
then:
properties:
apple,afe-smc: false
- if:
properties:
multi-touch:
Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/boot/dts/apple/t6040-j616s.dts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
};

&mtp_hid {
/* SMC key gp1c powers the trackpad analog front end. */
apple,afe-smc = <&smc>;

multi-touch {
firmware-name = "apple/tpmtfw-j616s.bin";
};
Expand Down
1 change: 1 addition & 0 deletions drivers/hid/dockchannel-hid/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ menu "DockChannel HID support"
config HID_DOCKCHANNEL
tristate "HID over DockChannel transport layer for Apple Silicon SoCs"
depends on APPLE_DOCKCHANNEL && APPLE_RTKIT_HELPER && INPUT && OF && HID
depends on MFD_MACSMC || !MFD_MACSMC
help
Say Y here if you use an M2 or later Apple Silicon based laptop.
The keyboard and touchpad are HID based devices connected via the
Expand Down
62 changes: 62 additions & 0 deletions drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,66 @@ static void dchid_unaligned_checksum_test(struct kunit *test)
}
}

/* A ring whose next frame straddles the end of the data area. */
static void *dchid_test_ring(struct kunit *test, u32 consumer, u32 producer)
{
struct dockchannel_hid *dchid = ((struct dchid_iface *)test->priv)->dchid;
u32 *indices;

dchid->ring = kunit_kzalloc(test, DCHID_RING_SIZE, GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, dchid->ring);
indices = dchid->ring;
indices[0] = producer;
indices[1] = consumer;
dchid->ring_read = consumer;
dchid->ring_registered = true;
dchid->use_ring = true;
return dchid->ring + DCHID_RING_HEADER_SIZE;
}

static void dchid_ring_wrap_test(struct kunit *test)
{
struct dchid_iface *iface = test->priv;
const u32 capacity = DCHID_RING_SIZE - DCHID_RING_HEADER_SIZE;
const u32 consumer = capacity - 12;
struct {
struct dchid_hdr hdr;
struct dchid_subhdr sub;
u8 id;
u8 pad[3];
__le32 checksum;
} __packed frame = {
.hdr = { .hdr_len = sizeof(struct dchid_hdr), .channel = DCHID_CHANNEL_CMD,
.length = sizeof(struct dchid_subhdr) + 4, .seq = 7, .iface = 1 },
.sub = { .flags = 0x80, .length = 1 },
.id = 0x10,
};
u8 *data;

/* A complete, checksummed acknowledgment of the pending command. */
frame.checksum = cpu_to_le32(U32_MAX - dchid_checksum(&frame, sizeof(frame) - 4));
data = dchid_test_ring(test, consumer, sizeof(frame) - 12);
memcpy(data + consumer, &frame, 12);
memcpy(data, (u8 *)&frame + 12, sizeof(frame) - 12);

KUNIT_EXPECT_EQ(test, dchid_drain_ring(iface->dchid), 0);
/* The frame arrived whole: its acknowledgment matched the pending command. */
KUNIT_EXPECT_TRUE(test, completion_done(&iface->out_complete));
KUNIT_EXPECT_EQ(test, iface->dchid->ring_read, sizeof(frame) - 12);
KUNIT_EXPECT_EQ(test, ((u32 *)iface->dchid->ring)[1], sizeof(frame) - 12);
}

static void dchid_ring_bad_header_test(struct kunit *test)
{
struct dchid_iface *iface = test->priv;
struct dchid_hdr hdr = { .hdr_len = sizeof(hdr) + 1, .length = 4 };
u8 *data = dchid_test_ring(test, 0, 16);

memcpy(data, &hdr, sizeof(hdr));
KUNIT_EXPECT_EQ(test, dchid_drain_ring(iface->dchid), -EPROTO);
KUNIT_EXPECT_EQ(test, iface->dchid->ring_read, 0U);
}

static struct kunit_case dchid_parser_cases[] = {
KUNIT_CASE(dchid_unaligned_checksum_test),
KUNIT_CASE(dchid_short_ack_test),
Expand All @@ -206,6 +266,8 @@ static struct kunit_case dchid_parser_cases[] = {
KUNIT_CASE(dchid_short_input_test),
KUNIT_CASE(dchid_init_descriptor_test),
KUNIT_CASE(dchid_packet_checksum_test),
KUNIT_CASE(dchid_ring_wrap_test),
KUNIT_CASE(dchid_ring_bad_header_test),
{}
};

Expand Down
Loading