Skip to contentSkip to conversation

Support tablet mode switch for Dell laptops

PATCH In review Marco Martin 5 participants 10 messages Jan 18, 2018 – Jan 22, 2018 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support tablet mode switch for Dell laptops

Dell laptops send events to intel-vbtn.c
0xCC when the laptop enters in tablet mode and
0xCD when the laptop goes out of it

This has been confirmed working on a Dell Inspiron 13-7352 and an Inspiron 13-7000

I'm not sure intel-vbtn is the right place for it, as it should be dell-specific, but this is the only device driver where those events arrive at all
also, it would need a way to query the initial state of the switch

CC Matthew Garrett <[email protected]>
CC "Pali Rohár" <[email protected]>
CC Darren Hart <[email protected]>
CC Andy Shevchenko <[email protected]>
---
 drivers/platform/x86/intel-vbtn.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/platform/x86/intel-vbtn.c +11 -1
index 146d02f..1fa63e8 100644
@@ -61,6 +61,10 @@ static int intel_vbtn_input_setup(struct platform_device *device)
 	priv->input_dev->name = "Intel Virtual Button driver";
 	priv->input_dev->id.bustype = BUS_HOST;
 
+	input_set_capability(priv->input_dev, EV_SW, SW_TABLET_MODE);
+	/*TODO: query initial state (and if the switch is present*/
+	input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+
 	ret = input_register_device(priv->input_dev);
 	if (ret)
 		goto err_free_device;
@@ -84,7 +88,13 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
 	struct platform_device *device = context;
 	struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
 
-	if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+	if (event == 0xCC) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+		input_sync(priv->input_dev);
+	} else if (event == 0xCD) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+		input_sync(priv->input_dev);
+	} else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
 		dev_info(&device->dev, "unknown event index 0x%x\n",
 			 event);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 11 lines · Marco Martin

Dell laptops send events to intel-vbtn.c
0xCC when the laptop enters in tablet mode and
0xCD when the laptop goes out of it

This has been confirmed working on a Dell Inspiron 13-7352 and an Inspiron 13-7000

I'm not sure intel-vbtn is the right place for it, as it should be dell-specific, but this is the only device driver where those events arrive at all
also, it would need a way to query the initial state of the switch

Yeah, to me sounds like a hack for now.
So, I would like to hear from everyone: Pali, Mario, Darren?

Quoted 44 lines
CC Matthew Garrett <[email protected]>
CC "Pali Rohár" <[email protected]>
CC Darren Hart <[email protected]>
CC Andy Shevchenko <[email protected]>
---
 drivers/platform/x86/intel-vbtn.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/platform/x86/intel-vbtn.c +11 -2
index 146d02f..1fa63e8 100644
@@ -61,6 +61,10 @@ static int intel_vbtn_input_setup(struct platform_device *device)
        priv->input_dev->name = "Intel Virtual Button driver";
        priv->input_dev->id.bustype = BUS_HOST;
 
+       input_set_capability(priv->input_dev, EV_SW, SW_TABLET_MODE);
+       /*TODO: query initial state (and if the switch is present*/
+       input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+
        ret = input_register_device(priv->input_dev);
        if (ret)
                goto err_free_device;
@@ -84,7 +88,13 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
        struct platform_device *device = context;
        struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
 
-       if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+       if (event == 0xCC) {
+               input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+               input_sync(priv->input_dev);
+       } else if (event == 0xCD) {
+               input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+               input_sync(priv->input_dev);
+       } else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
                dev_info(&device->dev, "unknown event index 0x%x\n",
                         event);
 }
--

2.7.4

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 20 lines

-----Original Message-----
From: [email protected] [mailto:platform-driver-x86- [email protected]] On Behalf Of Andy Shevchenko
Sent: Thursday, January 18, 2018 9:13 AM
To: Marco Martin <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>; Matthew Garrett <[email protected]>; Pali Rohár <[email protected]>; Darren Hart <[email protected]>; Andy Shevchenko <[email protected]>; [email protected]; Platform Driver <[email protected]>
Subject: Re: [PATCH] Support tablet mode switch for Dell laptops

Quoted 7 lines · Marco Martin

Dell laptops send events to intel-vbtn.c
0xCC when the laptop enters in tablet mode and
0xCD when the laptop goes out of it

This has been confirmed working on a Dell Inspiron 13-7352 and an Inspiron 13-7000

Quoted 7 lines
Quoted 4 lines

I'm not sure intel-vbtn is the right place for it, as it should be dell-specific, but this is the only device driver where those events arrive at all
also, it would need a way to query the initial state of the switch

Yeah, to me sounds like a hack for now.
So, I would like to hear from everyone: Pali, Mario, Darren?

AFAIK we don't have a public specification for the ACPI interface that intel-vbtn uses, it's all reverse engineered.

I think the appropriate thing to do would be open a kernel Bugzilla for your issue and attach:
1) kernel log without your patch (do you get unknown event index?)
2) your DSDT there to review.

You can subscribe us to it.

Also you should subscribe Alex Hung, who has done lots of work on intel-vbtn and intel-hid.

Quoted 53 lines

drivers/platform/x86/intel-vbtn.c static int intel_vbtn_input_setup(struct platform_device

Quoted 17 lines
CC Matthew Garrett <[email protected]>
CC "Pali Rohár" <[email protected]>
CC Darren Hart <[email protected]>
CC Andy Shevchenko <[email protected]>
---
 drivers/platform/x86/intel-vbtn.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/platform/x86/intel-vbtn.c +0 -0
index 146d02f..1fa63e8 100644
@@ -61,6 +61,10 @@ static int intel_vbtn_input_setup(struct platform_device

*device)

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event,

Quoted 11 lines
drivers/platform/x86/intel-vbtn.c +4 -0
        priv->input_dev->name = "Intel Virtual Button driver";
        priv->input_dev->id.bustype = BUS_HOST;
 
+       input_set_capability(priv->input_dev, EV_SW, SW_TABLET_MODE);
+       /*TODO: query initial state (and if the switch is present*/
+       input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+
        ret = input_register_device(priv->input_dev);
        if (ret)
                goto err_free_device;
@@ -84,7 +88,13 @@ static void notify_handler(acpi_handle handle, u32 event,

void *context)

Quoted 15 lines
drivers/platform/x86/intel-vbtn.c +7 -2
        struct platform_device *device = context;
        struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
 
-       if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+       if (event == 0xCC) {
+               input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+               input_sync(priv->input_dev);
+       } else if (event == 0xCD) {
+               input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+               input_sync(priv->input_dev);
+       } else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
                dev_info(&device->dev, "unknown event index 0x%x\n",
                         event);
 }
--
Quoted 2 lines

2.7.4

--
With Best Regards,
Andy Shevchenko

#3 lore raw
Quoted 9 lines · On Thu, Jan 18, 2018 at 4:23 PM, <[email protected]> wrote:

AFAIK we don't have a public specification for the ACPI interface that intel-vbtn uses, it's all reverse engineered.

I think the appropriate thing to do would be open a kernel Bugzilla for your issue and attach:
1) kernel log without your patch (do you get unknown event index?)
2) your DSDT there to review.

You can subscribe us to it.

done at
https://bugzilla.kernel.org/show_bug.cgi?id=198507

#4 lore raw
In reply to Marco Martin

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event, void *context) · line 97

Quoted 8 lines · On Thursday 18 January 2018 14:59:50 Marco Martin wrote:
drivers/platform/x86/intel-vbtn.c +7 -1
-	if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+	if (event == 0xCC) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+		input_sync(priv->input_dev);
+	} else if (event == 0xCD) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+		input_sync(priv->input_dev);
+	} else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))

Is not it possible to put 0xCC and 0xCD into sparse keymap table? Because IIRC sparse keymap was created just to avoid that big if-elseif-elseif-else blocks.

Quoted 3 lines
drivers/platform/x86/intel-vbtn.c +0 -0
 		dev_info(&device->dev, "unknown event index 0x%x\n",
 			 event);
 }
Signature · 2 lines
Pali Rohár
[email protected]
#5 lore raw
Quoted 13 lines · On Thursday 18 January 2018 16:44:08 Pali Rohár wrote:

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event, void *context) · line 97

Quoted 8 lines · On Thursday 18 January 2018 14:59:50 Marco Martin wrote:
drivers/platform/x86/intel-vbtn.c +7 -1
-	if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+	if (event == 0xCC) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+		input_sync(priv->input_dev);
+	} else if (event == 0xCD) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+		input_sync(priv->input_dev);
+	} else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))

Is not it possible to put 0xCC and 0xCD into sparse keymap table? Because IIRC sparse keymap was created just to avoid that big if-elseif-elseif-else blocks.

Dmitry, can you comment above part? I think that there should be better way how to handle above switches and sparse keymap via one input device.

Quoted 4 lines
Quoted 3 lines
drivers/platform/x86/intel-vbtn.c +0 -0
 		dev_info(&device->dev, "unknown event index 0x%x\n",
 			 event);
 }
Signature · 2 lines
Pali Rohár
[email protected]
#6 lore raw
Quoted 28 lines

-----Original Message-----
From: [email protected] [mailto:platform-driver-x86- [email protected]] On Behalf Of Pali Rohár
Sent: Friday, January 19, 2018 10:01 AM
To: Dmitry Torokhov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Marco Martin <[email protected]>
Subject: Re: [PATCH] Support tablet mode switch for Dell laptops

Quoted 13 lines · On Thursday 18 January 2018 16:44:08 Pali Rohár wrote:

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event, void *context) · line 97

Quoted 8 lines · On Thursday 18 January 2018 14:59:50 Marco Martin wrote:
drivers/platform/x86/intel-vbtn.c +7 -1
-	if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+	if (event == 0xCC) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+		input_sync(priv->input_dev);
+	} else if (event == 0xCD) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+		input_sync(priv->input_dev);
+	} else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))

Is not it possible to put 0xCC and 0xCD into sparse keymap table? Because IIRC sparse keymap was created just to avoid that big if-elseif-elseif-else blocks.

Dmitry, can you comment above part? I think that there should be better way how to handle above switches and sparse keymap via one input device.

Quoted 8 lines
Quoted 4 lines

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event, void *context) · line 100

Quoted 3 lines
drivers/platform/x86/intel-vbtn.c +0 -0
 		dev_info(&device->dev, "unknown event index 0x%x\n",
 			 event);
 }

--
Pali Rohár
[email protected]

We discussed a little more on the bug he filed with attached DSDT. I think that in sparse keymap he can use KE_VSW for the entries and sparse keymap can handle.

Assuming that works I'm expecting him to resubmit soon with that and some other changes I recommended on the bug.

#7 lore raw
Quoted 33 lines · On Fri, Jan 19, 2018 at 04:09:09PM +0000, [email protected] wrote:
Quoted 33 lines

-----Original Message-----
From: [email protected] [mailto:platform-driver-x86- [email protected]] On Behalf Of Pali Rohár
Sent: Friday, January 19, 2018 10:01 AM
To: Dmitry Torokhov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Marco Martin <[email protected]>
Subject: Re: [PATCH] Support tablet mode switch for Dell laptops

Quoted 13 lines · On Thursday 18 January 2018 16:44:08 Pali Rohár wrote:

drivers/platform/x86/intel-vbtn.c static void notify_handler(acpi_handle handle, u32 event, void *context) · line 97

Quoted 8 lines · On Thursday 18 January 2018 14:59:50 Marco Martin wrote:
drivers/platform/x86/intel-vbtn.c +7 -1
-	if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))
+	if (event == 0xCC) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 1);
+		input_sync(priv->input_dev);
+	} else if (event == 0xCD) {
+		input_report_switch(priv->input_dev, SW_TABLET_MODE, 0);
+		input_sync(priv->input_dev);
+	} else if (!sparse_keymap_report_event(priv->input_dev, event, 1, true))

Is not it possible to put 0xCC and 0xCD into sparse keymap table? Because IIRC sparse keymap was created just to avoid that big if-elseif-elseif-else blocks.

Dmitry, can you comment above part? I think that there should be better way how to handle above switches and sparse keymap via one input device.

Quoted 4 lines
Quoted 3 lines
drivers/platform/x86/intel-vbtn.c +0 -0
 		dev_info(&device->dev, "unknown event index 0x%x\n",
 			 event);
 }
Quoted 6 lines
Quoted 3 lines

--
Pali Rohár
[email protected]

We discussed a little more on the bug he filed with attached DSDT. I think that in sparse keymap he can use KE_VSW for the entries and sparse keymap can handle.

No it should be KE_SW I believe, as the "keycode" encodes the state. See example in intel-hid.c.

So you probably want:

	...
	{ KE_SW, 0xCC, { .sw = { SW_TABLET_MODE, 1 } } }, /* Press */
	{ KE_SW, 0xCD, { .sw = { SW_TABLET_MODE, 0 } } }, /* Release */

Thanks.

Signature · 1 line
Dmitry
#8 lore raw
Quoted 6 lines · Dmitry Torokhov
Quoted 2 lines

We discussed a little more on the bug he filed with attached DSDT. I think that in sparse keymap he can use KE_VSW for the entries and sparse keymap can handle.

No it should be KE_SW I believe, as the "keycode" encodes the state. See example in intel-hid.c.

Quoted 7 lines

So you probably want:

        ...
        { KE_SW, 0xCC, { .sw = { SW_TABLET_MODE, 1 } } }, /* Press */
        { KE_SW, 0xCD, { .sw = { SW_TABLET_MODE, 0 } } }, /* Release */

Thanks.

If I add those lines to intel_vbtn_keymap and remove the two special cases for 0xCC and 0xCD, it does work, but only if I explicitly call input_sync(priv->input_dev) after sparse_keymap_report_event() otherwise i don't get the event (cheching for instance with evtest) until a sync gets called (i tried to put the sync only for 0xcd and in that case i get both 0xcc and 0xcd when i go out of tablet mode)

#9 lore raw
Quoted 14 lines · Marco Martin
Quoted 12 lines · Dmitry Torokhov
Quoted 2 lines

We discussed a little more on the bug he filed with attached DSDT. I think that in sparse keymap he can use KE_VSW for the entries and sparse keymap can handle.

No it should be KE_SW I believe, as the "keycode" encodes the state. See example in intel-hid.c.

So you probably want:

        ...
        { KE_SW, 0xCC, { .sw = { SW_TABLET_MODE, 1 } } }, /* Press */
        { KE_SW, 0xCD, { .sw = { SW_TABLET_MODE, 0 } } }, /* Release */
Quoted 8 lines
Quoted 1 line

Thanks.

If I add those lines to intel_vbtn_keymap and remove the two special cases for 0xCC and 0xCD, it does work, but only if I explicitly call input_sync(priv->input_dev) after sparse_keymap_report_event() otherwise i don't get the event (cheching for instance with evtest) until a sync gets called (i tried to put the sync only for 0xcd and in that case i get both 0xcc and 0xcd when i go out of tablet mode)

with the caveat of an input_sync every event, new patch as a new thread with Mario's
and Dmitry's suggestions integrated in, and formatted to conform
checkpatch controls