linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] HID: i2c-hid: expand the quirk lookup table to support dmi_table
@ 2020-12-04 15:29 Hui Wang
  2020-12-04 15:29 ` [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown Hui Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Hui Wang @ 2020-12-04 15:29 UTC (permalink / raw)
  To: linux-input, jikos, benjamin.tissoires

After adding the dmi_table, we could apply the quirk to the specific
machine, and the dmi_table is optional when define a quirk table, if
not define the dmi_table, the lookup_quirk() works the same as before.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 drivers/hid/i2c-hid/i2c-hid-core.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index aeff1ffb0c8b..953877cf1051 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -37,6 +37,7 @@
 #include <linux/mutex.h>
 #include <linux/acpi.h>
 #include <linux/of.h>
+#include <linux/dmi.h>
 #include <linux/regulator/consumer.h>
 
 #include <linux/platform_data/i2c-hid.h>
@@ -166,6 +167,7 @@ static const struct i2c_hid_quirks {
 	__u16 idVendor;
 	__u16 idProduct;
 	__u32 quirks;
+	const struct dmi_system_id *dmi_table;
 } i2c_hid_quirks[] = {
 	{ USB_VENDOR_ID_WEIDA, HID_ANY_ID,
 		I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
@@ -188,21 +190,20 @@ static const struct i2c_hid_quirks {
  * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device
  * @idVendor: the 16-bit vendor ID
  * @idProduct: the 16-bit product ID
+ * @table: struct i2c_hid_quirks table pointer
+ * @len: the 32-bit table length
  *
  * Returns: a u32 quirks value.
  */
-static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
+static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct,
+				const struct i2c_hid_quirks *table, u32 len)
 {
-	u32 quirks = 0;
-	int n;
+	for (; len > 0; len--, table++)
+		if (table->idVendor == idVendor && table->idProduct == idProduct)
+			if (!table->dmi_table || dmi_check_system(table->dmi_table))
+				return table->quirks;
 
-	for (n = 0; i2c_hid_quirks[n].idVendor; n++)
-		if (i2c_hid_quirks[n].idVendor == idVendor &&
-		    (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID ||
-		     i2c_hid_quirks[n].idProduct == idProduct))
-			quirks = i2c_hid_quirks[n].quirks;
-
-	return quirks;
+	return 0;
 }
 
 static int __i2c_hid_command(struct i2c_client *client,
@@ -1133,7 +1134,8 @@ static int i2c_hid_probe(struct i2c_client *client,
 		 client->name, hid->vendor, hid->product);
 	strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys));
 
-	ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product);
+	ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product, i2c_hid_quirks,
+					    ARRAY_SIZE(i2c_hid_quirks));
 
 	ret = hid_add_device(hid);
 	if (ret) {
-- 
2.25.1


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

* [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown
  2020-12-04 15:29 [PATCH 1/2] HID: i2c-hid: expand the quirk lookup table to support dmi_table Hui Wang
@ 2020-12-04 15:29 ` Hui Wang
  2021-01-07  9:12   ` Jiri Kosina
  0 siblings, 1 reply; 6+ messages in thread
From: Hui Wang @ 2020-12-04 15:29 UTC (permalink / raw)
  To: linux-input, jikos, benjamin.tissoires

On the latest Thinkpad Yoga laptop, the touchscreen module is wacom
I2C WACF2200 (056a:5276), we found the touchscreen could not work
after rebooting, needs to poweroff the machine then poweron the
machine to let it work.

It is highly possible that this is a BIOS issue, but the windows
doesn't have this problem with the same BIOS.

If keeping the power on when calling shutdown, the touchscreen could
work after rebooting. Let us add a quirk for it and apply the quirk
to this machine only.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 drivers/hid/hid-ids.h              |  1 +
 drivers/hid/i2c-hid/i2c-hid-core.c | 20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index f170feaac40b..ecc1d4040b6f 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -1223,6 +1223,7 @@
 #define USB_VENDOR_ID_WACOM		0x056a
 #define USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH	0x81
 #define USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH   0x00BD
+#define USB_DEVICE_ID_WACOM_5276		0x5276
 
 #define USB_VENDOR_ID_WALTOP				0x172f
 #define USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH	0x0032
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 953877cf1051..7c6d5b8175fd 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -51,7 +51,7 @@
 #define I2C_HID_QUIRK_BOGUS_IRQ			BIT(4)
 #define I2C_HID_QUIRK_RESET_ON_RESUME		BIT(5)
 #define I2C_HID_QUIRK_BAD_INPUT_SIZE		BIT(6)
-
+#define I2C_HID_QUIRK_KEEP_PWR_ON_SHUTDOWN	BIT(7)
 
 /* flags */
 #define I2C_HID_STARTED		0
@@ -183,6 +183,20 @@ static const struct i2c_hid_quirks {
 		 I2C_HID_QUIRK_RESET_ON_RESUME },
 	{ USB_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720,
 		I2C_HID_QUIRK_BAD_INPUT_SIZE },
+	{
+		.idVendor = USB_VENDOR_ID_WACOM,
+		.idProduct = USB_DEVICE_ID_WACOM_5276,
+		.quirks = I2C_HID_QUIRK_KEEP_PWR_ON_SHUTDOWN,
+		.dmi_table = (const struct dmi_system_id []) {
+			{
+				.matches = {
+					DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+					DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "LENOVO_MT_20XY_BU_Think_FM_ThinkPad X1 Yoga Gen 6"),
+				}
+			},
+			{}
+		}
+	},
 	{ 0, 0 }
 };
 
@@ -1182,7 +1196,9 @@ static void i2c_hid_shutdown(struct i2c_client *client)
 {
 	struct i2c_hid *ihid = i2c_get_clientdata(client);
 
-	i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
+	if (!(ihid->quirks & I2C_HID_QUIRK_KEEP_PWR_ON_SHUTDOWN))
+		i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
+
 	free_irq(client->irq, ihid);
 
 	i2c_hid_acpi_shutdown(&client->dev);
-- 
2.25.1


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

* Re: [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown
  2020-12-04 15:29 ` [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown Hui Wang
@ 2021-01-07  9:12   ` Jiri Kosina
  2021-01-07 11:46     ` Hui Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Kosina @ 2021-01-07  9:12 UTC (permalink / raw)
  To: Hui Wang; +Cc: linux-input, benjamin.tissoires

On Fri, 4 Dec 2020, Hui Wang wrote:

> On the latest Thinkpad Yoga laptop, the touchscreen module is wacom
> I2C WACF2200 (056a:5276), we found the touchscreen could not work
> after rebooting, needs to poweroff the machine then poweron the
> machine to let it work.
> 
> It is highly possible that this is a BIOS issue, but the windows
> doesn't have this problem with the same BIOS.
> 
> If keeping the power on when calling shutdown, the touchscreen could
> work after rebooting. Let us add a quirk for it and apply the quirk
> to this machine only.

I wonder what do Windows do differently here. Perhaps they never put the 
i2c device to sleep while in shutdown anyway? Is there any downside to 
(not) doing the same?

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* Re: [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown
  2021-01-07  9:12   ` Jiri Kosina
@ 2021-01-07 11:46     ` Hui Wang
  2021-01-08 15:01       ` Jiri Kosina
  0 siblings, 1 reply; 6+ messages in thread
From: Hui Wang @ 2021-01-07 11:46 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: linux-input, benjamin.tissoires


On 1/7/21 5:12 PM, Jiri Kosina wrote:
> On Fri, 4 Dec 2020, Hui Wang wrote:
>
>> On the latest Thinkpad Yoga laptop, the touchscreen module is wacom
>> I2C WACF2200 (056a:5276), we found the touchscreen could not work
>> after rebooting, needs to poweroff the machine then poweron the
>> machine to let it work.
>>
>> It is highly possible that this is a BIOS issue, but the windows
>> doesn't have this problem with the same BIOS.
>>
>> If keeping the power on when calling shutdown, the touchscreen could
>> work after rebooting. Let us add a quirk for it and apply the quirk
>> to this machine only.
> I wonder what do Windows do differently here. Perhaps they never put the
> i2c device to sleep while in shutdown anyway? Is there any downside to
> (not) doing the same?

It is highly possible the Windows doesn't sleep the i2c device in 
shutdown. When calling shutdown, it usually means reboot or poweroff the 
machine, so the sleep is meaningless in this situation. In other 
situations like users manually unload the i2c driver, maybe it will add 
a bit power consumption without sleeping the device.

Anyway, I will try to ask for help from vendor, maybe they could provide 
how Windows do when shutdown.

Thanks.

> Thanks,
>

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

* Re: [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown
  2021-01-07 11:46     ` Hui Wang
@ 2021-01-08 15:01       ` Jiri Kosina
  2021-01-26  8:57         ` Hui Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Kosina @ 2021-01-08 15:01 UTC (permalink / raw)
  To: Hui Wang; +Cc: linux-input, benjamin.tissoires

On Thu, 7 Jan 2021, Hui Wang wrote:

> >> On the latest Thinkpad Yoga laptop, the touchscreen module is wacom
> >> I2C WACF2200 (056a:5276), we found the touchscreen could not work
> >> after rebooting, needs to poweroff the machine then poweron the
> >> machine to let it work.
> >>
> >> It is highly possible that this is a BIOS issue, but the windows
> >> doesn't have this problem with the same BIOS.
> >>
> >> If keeping the power on when calling shutdown, the touchscreen could
> >> work after rebooting. Let us add a quirk for it and apply the quirk
> >> to this machine only.
> > I wonder what do Windows do differently here. Perhaps they never put the
> > i2c device to sleep while in shutdown anyway? Is there any downside to
> > (not) doing the same?
> 
> It is highly possible the Windows doesn't sleep the i2c device in shutdown.
> When calling shutdown, it usually means reboot or poweroff the machine, so the
> sleep is meaningless in this situation. In other situations like users
> manually unload the i2c driver, maybe it will add a bit power consumption
> without sleeping the device.

Agreed, but if windows really don't put the device to sleep before 
shutting down, odds are there will be more devices behaving the same, and 
therefore we'd rather make it the default case instead of growing just 
another quirk list.

> Anyway, I will try to ask for help from vendor, maybe they could provide 
> how Windows do when shutdown.

Thank you,

-- 
Jiri Kosina
SUSE Labs


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

* Re: [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown
  2021-01-08 15:01       ` Jiri Kosina
@ 2021-01-26  8:57         ` Hui Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Hui Wang @ 2021-01-26  8:57 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: linux-input, benjamin.tissoires


On 1/8/21 11:01 PM, Jiri Kosina wrote:
> On Thu, 7 Jan 2021, Hui Wang wrote:
>
>>>> On the latest Thinkpad Yoga laptop, the touchscreen module is wacom
>>>> I2C WACF2200 (056a:5276), we found the touchscreen could not work
>>>> after rebooting, needs to poweroff the machine then poweron the
>>>> machine to let it work.
>>>>
>>>> It is highly possible that this is a BIOS issue, but the windows
>>>> doesn't have this problem with the same BIOS.
>>>>
>>>> If keeping the power on when calling shutdown, the touchscreen could
>>>> work after rebooting. Let us add a quirk for it and apply the quirk
>>>> to this machine only.
>>> I wonder what do Windows do differently here. Perhaps they never put the
>>> i2c device to sleep while in shutdown anyway? Is there any downside to
>>> (not) doing the same?
>> It is highly possible the Windows doesn't sleep the i2c device in shutdown.
>> When calling shutdown, it usually means reboot or poweroff the machine, so the
>> sleep is meaningless in this situation. In other situations like users
>> manually unload the i2c driver, maybe it will add a bit power consumption
>> without sleeping the device.
> Agreed, but if windows really don't put the device to sleep before
> shutting down, odds are there will be more devices behaving the same, and
> therefore we'd rather make it the default case instead of growing just
> another quirk list.

Got the feedback from the ODM, the root cause of this issue is the I2C 
device will send clock stretching when changing from PWR_SLEEP to 
PWR_ON, but the driver in the BIOS doesn't handle the clock stretching 
or the timeout is not enough. ODM already provided a testing BIOS and 
this issue is fixed by the testing BIOS.

And ODM captured the I2C data transfer log under Windows, according to 
the log, the Windows also set the I2C touchscreen to PWR_SLEEP before 
rebooting, it is same as the current Linux hid i2c driver.

Regards,

Hui.

>> Anyway, I will try to ask for help from vendor, maybe they could provide
>> how Windows do when shutdown.
> Thank you,
>

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

end of thread, other threads:[~2021-01-26 18:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04 15:29 [PATCH 1/2] HID: i2c-hid: expand the quirk lookup table to support dmi_table Hui Wang
2020-12-04 15:29 ` [PATCH 2/2] HID: i2c-hid: Add a quirk to keep the power in shutdown Hui Wang
2021-01-07  9:12   ` Jiri Kosina
2021-01-07 11:46     ` Hui Wang
2021-01-08 15:01       ` Jiri Kosina
2021-01-26  8:57         ` Hui Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).