From e36c31f8cac54d6d900d270078d6b33de74e1b0a Mon Sep 17 00:00:00 2001 From: Louis Morhet Date: Tue, 4 Apr 2023 14:15:14 +0200 Subject: HID: mcp2221: fix report layout for gpio get The documentation of the component (section 3.1.12 GET GPIO VALUES) describes the hid report structure with two fields per gpio: its value, followed by its direction. However, the driver describes it with a wrong order: direction followed by value. Fix the structure representing the report answered by the chip to the GET GPIO VALUES command. Fixes commit 567b8e9fed8a ("HID: mcp2221: Fix GPIO output handling") Signed-off-by: Louis Morhet Link: https://lore.kernel.org/r/945967fbab56d53f9630ad3844b64734f8c3107e.1680602387.git.lmorhet@kalrayinc.com Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-mcp2221.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index f74a977cf8f8..fa20ed4d395a 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -79,8 +79,8 @@ struct mcp_get_gpio { u8 cmd; u8 dummy; struct { - u8 direction; u8 value; + u8 direction; } gpio[MCP_NGPIO]; } __packed; -- cgit v1.2.3 From ca6961d8a851f3720175f500be38fe9cee5a2c13 Mon Sep 17 00:00:00 2001 From: Louis Morhet Date: Tue, 4 Apr 2023 14:15:25 +0200 Subject: HID: mcp2221: fix get and get_direction for gpio The mcp2221_raw_event retrieves the value and direction of gpio on the same command, by setting the value on mcp->status and the direction on mcp->gpio_dir; and the offset at which they are read is based on mcp->gp_idx, set by the gpiochip callbacks. However, the individual gpiochip calls set the index to look for directly on the field they want to track. This create a "double offset" in the final read in the response report. Align the behaviour of mcp2221_raw_event and mcp_gpio_get/mcp_gpio_get_direction by putting gp_idx on those calls to the base offset of the gpio status struct. Signed-off-by: Louis Morhet Link: https://lore.kernel.org/r/dd0b23800a79d2a464e1e9ed429b018b69fd5df2.1680602387.git.lmorhet@kalrayinc.com Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-mcp2221.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index fa20ed4d395a..72883e0ce757 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -594,7 +594,7 @@ static int mcp_gpio_get(struct gpio_chip *gc, mcp->txbuf[0] = MCP2221_GPIO_GET; - mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].value); + mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset]); mutex_lock(&mcp->lock); ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); @@ -675,7 +675,7 @@ static int mcp_gpio_get_direction(struct gpio_chip *gc, mcp->txbuf[0] = MCP2221_GPIO_GET; - mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].direction); + mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset]); mutex_lock(&mcp->lock); ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); -- cgit v1.2.3