Skip to contentSkip to conversation

ACPI / button: add support for tablet mode switch

PATCH In review Wei-Ning Huang 4 participants 4 messages Aug 31, 2016 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / button: add support for tablet mode switch

From: Wei-Ning Huang <[email protected]>

ACPI PNP device HID 'PNP0C60' is a device that indicates tablet mode status. Add support for mapping this device to the SW_TABLET_MODE input event.

---
 drivers/acpi/button.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/acpi/button.c +36 -0
index 148f4e5..50e9de6 100644
@@ -53,6 +53,11 @@
 #define ACPI_BUTTON_DEVICE_NAME_LID	"Lid Switch"
 #define ACPI_BUTTON_TYPE_LID		0x05
 
+#define ACPI_BUTTON_SUBCLASS_TABLET	"tablet"
+#define ACPI_BUTTON_HID_TABLET		"PNP0C60"
+#define ACPI_BUTTON_DEVICE_NAME_TABLET	"Tablet Mode Switch"
+#define ACPI_BUTTON_TYPE_TABLET		0x07
+
 #define ACPI_BUTTON_LID_INIT_IGNORE	0x00
 #define ACPI_BUTTON_LID_INIT_OPEN	0x01
 #define ACPI_BUTTON_LID_INIT_METHOD	0x02
@@ -70,6 +75,7 @@ static const struct acpi_device_id button_device_ids[] = {
 	{ACPI_BUTTON_HID_SLEEPF, 0},
 	{ACPI_BUTTON_HID_POWER,  0},
 	{ACPI_BUTTON_HID_POWERF, 0},
+	{ACPI_BUTTON_HID_TABLET, 0},
 	{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, button_device_ids);
@@ -305,6 +311,23 @@ static void acpi_lid_initialize_state(struct acpi_device *device)
 	}
 }
 
+static int acpi_tablet_send_state(struct acpi_device *device)
+{
+	struct acpi_button *button = acpi_driver_data(device);
+	unsigned long long state;
+	acpi_status status;
+
+	status = acpi_evaluate_integer(device->handle, "_TBL", NULL, &state);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	/* input layer checks if event is redundant */
+	input_report_switch(button->input, SW_TABLET_MODE, state);
+	input_sync(button->input);
+
+	return 0;
+}
+
 static void acpi_button_notify(struct acpi_device *device, u32 event)
 {
 	struct acpi_button *button = acpi_driver_data(device);
@@ -318,6 +341,8 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
 		input = button->input;
 		if (button->type == ACPI_BUTTON_TYPE_LID) {
 			acpi_lid_update_state(device);
+		} else if (button->type == ACPI_BUTTON_TYPE_TABLET) {
+			acpi_tablet_send_state(device);
 		} else {
 			int keycode;
 
@@ -407,6 +432,11 @@ static int acpi_button_add(struct acpi_device *device)
 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
+	} else if (!strcmp(hid, ACPI_BUTTON_HID_TABLET)) {
+		button->type = ACPI_BUTTON_TYPE_TABLET;
+		strcpy(name, ACPI_BUTTON_DEVICE_NAME_TABLET);
+		sprintf(class, "%s/%s",
+			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_TABLET);
 	} else {
 		printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
 		error = -ENODEV;
@@ -437,6 +467,10 @@ static int acpi_button_add(struct acpi_device *device)
 	case ACPI_BUTTON_TYPE_LID:
 		input_set_capability(input, EV_SW, SW_LID);
 		break;
+
+	case ACPI_BUTTON_TYPE_TABLET:
+		input_set_capability(input, EV_SW, SW_TABLET_MODE);
+		break;
 	}
 
 	error = input_register_device(input);
@@ -450,6 +484,8 @@ static int acpi_button_add(struct acpi_device *device)
 		 */
 		lid_device = device;
 	}
+	if (button->type == ACPI_BUTTON_TYPE_TABLET)
+		acpi_tablet_send_state(device);
 
 	printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
 	return 0;
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw
Quoted 49 lines · Wei-Ning Huang

From: Wei-Ning Huang <[email protected]>

ACPI PNP device HID 'PNP0C60' is a device that indicates tablet mode status. Add support for mapping this device to the SW_TABLET_MODE input
event.

---
 drivers/acpi/button.c | 36 ++++++++++++++++++++++++++++++++++++

 1 file changed, 36 insertions(+)
drivers/acpi/button.c +0 -0
index 148f4e5..50e9de6 100644
@@ -53,6 +53,11 @@
  #define ACPI_BUTTON_DEVICE_NAME_LID	"Lid Switch"
  #define ACPI_BUTTON_TYPE_LID		0x05

drivers/acpi/button.c +5 -0
+#define ACPI_BUTTON_SUBCLASS_TABLET	"tablet"
+#define ACPI_BUTTON_HID_TABLET		"PNP0C60"
+#define ACPI_BUTTON_DEVICE_NAME_TABLET	"Tablet Mode Switch"
+#define ACPI_BUTTON_TYPE_TABLET		0x07
+

 #define ACPI_BUTTON_LID_INIT_IGNORE 0x00
 #define ACPI_BUTTON_LID_INIT_OPEN 0x01
 #define ACPI_BUTTON_LID_INIT_METHOD 0x02

drivers/acpi/button.c +1 -0
@@ -70,6 +75,7 @@ static const struct acpi_device_id
 button_device_ids[] = {
  	{ACPI_BUTTON_HID_SLEEPF, 0},
  	{ACPI_BUTTON_HID_POWER,  0},
  	{ACPI_BUTTON_HID_POWERF, 0},
+	{ACPI_BUTTON_HID_TABLET, 0},
  	{"", 0},
  };

 MODULE_DEVICE_TABLE(acpi, button_device_ids);

drivers/acpi/button.c +0 -0
@@ -305,6 +311,23 @@ static void acpi_lid_initialize_state(struct
 acpi_device *device)
  	}
  }

drivers/acpi/button.c +7 -0
+static int acpi_tablet_send_state(struct acpi_device *device)
+{
+	struct acpi_button *button = acpi_driver_data(device);
+	unsigned long long state;
+	acpi_status status;
+
+	status = acpi_evaluate_integer(device->handle, "_TBL", NULL,
Quoted 1 line

&state);

Control methods with prefix "_" suggests this is an ACPI predefined control method, but I can not find it in ACPI spec 6.1. Can you illustrate me where I can find the definition of _TBL?

thanks,
rui

Quoted 64 lines
drivers/acpi/button.c +10 -0
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	/* input layer checks if event is redundant */
+	input_report_switch(button->input, SW_TABLET_MODE, state);
+	input_sync(button->input);
+
+	return 0;
+}
+

 static void acpi_button_notify(struct acpi_device *device, u32 event)
 {
  struct acpi_button *button = acpi_driver_data(device);

drivers/acpi/button.c +2 -0
@@ -318,6 +341,8 @@ static void acpi_button_notify(struct acpi_device
 *device, u32 event)
  		input = button->input;
  		if (button->type == ACPI_BUTTON_TYPE_LID) {
  			acpi_lid_update_state(device);
+		} else if (button->type == ACPI_BUTTON_TYPE_TABLET)
 {
+			acpi_tablet_send_state(device);
  		} else {

  int keycode;

drivers/acpi/button.c +5 -0
@@ -407,6 +432,11 @@ static int acpi_button_add(struct acpi_device
 *device)
  		strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
  		sprintf(class, "%s/%s",
  			ACPI_BUTTON_CLASS,
 ACPI_BUTTON_SUBCLASS_LID);
+	} else if (!strcmp(hid, ACPI_BUTTON_HID_TABLET)) {
+		button->type = ACPI_BUTTON_TYPE_TABLET;
+		strcpy(name, ACPI_BUTTON_DEVICE_NAME_TABLET);
+		sprintf(class, "%s/%s",
+			ACPI_BUTTON_CLASS,
 ACPI_BUTTON_SUBCLASS_TABLET);

  } else {
  printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
  error = -ENODEV;

drivers/acpi/button.c +0 -0
@@ -437,6 +467,10 @@ static int acpi_button_add(struct acpi_device
 *device)

  case ACPI_BUTTON_TYPE_LID:
  input_set_capability(input, EV_SW, SW_LID); break;

drivers/acpi/button.c +4 -0
+
+	case ACPI_BUTTON_TYPE_TABLET:
+		input_set_capability(input, EV_SW, SW_TABLET_MODE);
+		break;

  }

  error = input_register_device(input);

drivers/acpi/button.c +2 -0
@@ -450,6 +484,8 @@ static int acpi_button_add(struct acpi_device
 *device)
  		 */
  		lid_device = device;
  	}
+	if (button->type == ACPI_BUTTON_TYPE_TABLET)
+		acpi_tablet_send_state(device);


  printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
  return 0;

#2 lore raw
Quoted 43 lines · Zhang Rui
Quoted 42 lines · Wei-Ning Huang

From: Wei-Ning Huang <[email protected]>

ACPI PNP device HID 'PNP0C60' is a device that indicates tablet mode status. Add support for mapping this device to the SW_TABLET_MODE input
event.

---
 drivers/acpi/button.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/acpi/button.c +6 -0
index 148f4e5..50e9de6 100644
@@ -53,6 +53,11 @@
 #define ACPI_BUTTON_DEVICE_NAME_LID  "Lid Switch"
 #define ACPI_BUTTON_TYPE_LID         0x05
 
+#define ACPI_BUTTON_SUBCLASS_TABLET  "tablet"
+#define ACPI_BUTTON_HID_TABLET               "PNP0C60"
+#define ACPI_BUTTON_DEVICE_NAME_TABLET       "Tablet Mode Switch"
+#define ACPI_BUTTON_TYPE_TABLET              0x07
+
 #define ACPI_BUTTON_LID_INIT_IGNORE  0x00
 #define ACPI_BUTTON_LID_INIT_OPEN    0x01
 #define ACPI_BUTTON_LID_INIT_METHOD  0x02
@@ -70,6 +75,7 @@ static const struct acpi_device_id
 button_device_ids[] = {
      {ACPI_BUTTON_HID_SLEEPF, 0},
      {ACPI_BUTTON_HID_POWER,  0},
      {ACPI_BUTTON_HID_POWERF, 0},
+     {ACPI_BUTTON_HID_TABLET, 0},
      {"", 0},
 };

MODULE_DEVICE_TABLE(acpi, button_device_ids);

drivers/acpi/button.c +0 -0
@@ -305,6 +311,23 @@ static void acpi_lid_initialize_state(struct
 acpi_device *device)
      }
 }
 
Quoted 12 lines

drivers/acpi/button.c static void acpi_lid_initialize_state(struct acpi_device *device)

Quoted 8 lines
drivers/acpi/button.c +7 -0
+static int acpi_tablet_send_state(struct acpi_device *device)
+{
+     struct acpi_button *button = acpi_driver_data(device);
+     unsigned long long state;
+     acpi_status status;
+
+     status = acpi_evaluate_integer(device->handle, "_TBL", NULL,
 &state);

Control methods with prefix "_" suggests this is an ACPI predefined control method, but I can not find it in ACPI spec 6.1. Can you illustrate me where I can find the definition of _TBL?

Sorry, I'm not very familiar with ACPI's control method.
'_TBL' is not a predefined ACPI control method according to the ACPI 6.1 spec. Maybe I should change it to '_LID'? As a tablet switch is sort of a 'inverted' lid switch.

Wei-Ning

Quoted 67 lines

thanks,
rui

Quoted 64 lines
drivers/acpi/button.c +10 -0
+     if (ACPI_FAILURE(status))
+             return -ENODEV;
+
+     /* input layer checks if event is redundant */
+     input_report_switch(button->input, SW_TABLET_MODE, state);
+     input_sync(button->input);
+
+     return 0;
+}
+
 static void acpi_button_notify(struct acpi_device *device, u32

event)

 {
      struct acpi_button *button = acpi_driver_data(device);
drivers/acpi/button.c +2 -0
@@ -318,6 +341,8 @@ static void acpi_button_notify(struct acpi_device
 *device, u32 event)
              input = button->input;
              if (button->type == ACPI_BUTTON_TYPE_LID) {
                      acpi_lid_update_state(device);
+             } else if (button->type == ACPI_BUTTON_TYPE_TABLET)
 {
+                     acpi_tablet_send_state(device);
              } else {
                      int keycode;
drivers/acpi/button.c +5 -0
@@ -407,6 +432,11 @@ static int acpi_button_add(struct acpi_device
 *device)
              strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
              sprintf(class, "%s/%s",
                      ACPI_BUTTON_CLASS,
 ACPI_BUTTON_SUBCLASS_LID);
+     } else if (!strcmp(hid, ACPI_BUTTON_HID_TABLET)) {
+             button->type = ACPI_BUTTON_TYPE_TABLET;
+             strcpy(name, ACPI_BUTTON_DEVICE_NAME_TABLET);
+             sprintf(class, "%s/%s",
+                     ACPI_BUTTON_CLASS,
 ACPI_BUTTON_SUBCLASS_TABLET);

} else {
printk(KERN_ERR PREFIX "Unsupported hid [%s]\n",

hid);
              error = -ENODEV;
drivers/acpi/button.c +4 -0
@@ -437,6 +467,10 @@ static int acpi_button_add(struct acpi_device
 *device)
      case ACPI_BUTTON_TYPE_LID:
              input_set_capability(input, EV_SW, SW_LID);
              break;
+
+     case ACPI_BUTTON_TYPE_TABLET:
+             input_set_capability(input, EV_SW, SW_TABLET_MODE);
+             break;
      }
 
      error = input_register_device(input);
drivers/acpi/button.c +2 -0
@@ -450,6 +484,8 @@ static int acpi_button_add(struct acpi_device
 *device)
               */
              lid_device = device;
      }
+     if (button->type == ACPI_BUTTON_TYPE_TABLET)
+             acpi_tablet_send_state(device);
 
      printk(KERN_INFO PREFIX "%s [%s]\n", name,
acpi_device_bid(device));
      return 0;
Signature · 2 lines
Wei-Ning Huang, 黃偉寧 | Software Engineer, Google Inc., Taiwan |
[email protected] | Cell: +886 910-380678
#3 lore raw
Quoted 57 lines · Wei-Ning Huang
Quoted 43 lines · Zhang Rui
Quoted 42 lines · Wei-Ning Huang

From: Wei-Ning Huang <[email protected]>

ACPI PNP device HID 'PNP0C60' is a device that indicates tablet mode status. Add support for mapping this device to the SW_TABLET_MODE input
event.

---
 drivers/acpi/button.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/acpi/button.c +6 -0
index 148f4e5..50e9de6 100644
@@ -53,6 +53,11 @@
 #define ACPI_BUTTON_DEVICE_NAME_LID  "Lid Switch"
 #define ACPI_BUTTON_TYPE_LID         0x05
 
+#define ACPI_BUTTON_SUBCLASS_TABLET  "tablet"
+#define ACPI_BUTTON_HID_TABLET               "PNP0C60"
+#define ACPI_BUTTON_DEVICE_NAME_TABLET       "Tablet Mode Switch"
+#define ACPI_BUTTON_TYPE_TABLET              0x07
+
 #define ACPI_BUTTON_LID_INIT_IGNORE  0x00
 #define ACPI_BUTTON_LID_INIT_OPEN    0x01
 #define ACPI_BUTTON_LID_INIT_METHOD  0x02
@@ -70,6 +75,7 @@ static const struct acpi_device_id
 button_device_ids[] = {
      {ACPI_BUTTON_HID_SLEEPF, 0},
      {ACPI_BUTTON_HID_POWER,  0},
      {ACPI_BUTTON_HID_POWERF, 0},
+     {ACPI_BUTTON_HID_TABLET, 0},
      {"", 0},
 };

MODULE_DEVICE_TABLE(acpi, button_device_ids);

drivers/acpi/button.c +0 -0
@@ -305,6 +311,23 @@ static void acpi_lid_initialize_state(struct
 acpi_device *device)
      }
 }
 
Quoted 12 lines

drivers/acpi/button.c static void acpi_lid_initialize_state(struct acpi_device *device)

Quoted 8 lines
drivers/acpi/button.c +7 -0
+static int acpi_tablet_send_state(struct acpi_device *device)
+{
+     struct acpi_button *button = acpi_driver_data(device);
+     unsigned long long state;
+     acpi_status status;
+
+     status = acpi_evaluate_integer(device->handle, "_TBL", NULL,
 &state);

Control methods with prefix "_" suggests this is an ACPI predefined control method, but I can not find it in ACPI spec 6.1. Can you illustrate me where I can find the definition of _TBL?

Quoted 1 line

Sorry, I'm not very familiar with ACPI's control method.

So apparently you don't really know what the patch you've posted is doing.

Quoted 3 lines

'_TBL' is not a predefined ACPI control method according to the ACPI 6.1 spec. Maybe I should change it to '_LID'? As a tablet switch is sort of a 'inverted' lid switch.

Is that _TBL thing documented anywhere?

Thanks,
Rafael