diff mbox

[3/4] hid-lenovo: Handle X1 Tablet cover FNLock function appropriately

Message ID 110694ef-bbad-f211-ac5d-3fe5e10600f2@secunet.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dennis Wassenberg Dec. 9, 2016, 3:05 p.m. UTC
The FNLock state is not handled by the X1 tablet cover itself.
There is the need to set the FNLock LED which actually enables
the FNLock state of the cover. This means activating the FNLock LED
will enable FNLock state and FNLock LED.
---
 drivers/hid/hid-lenovo.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox

Patch

diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
index 2efd5b0..3ace8c3 100644
--- a/drivers/hid/hid-lenovo.c
+++ b/drivers/hid/hid-lenovo.c
@@ -526,6 +526,29 @@  static void lenovo_led_brightness_set_tpx1cover(struct led_classdev *led_cdev,
 	}
 }
 
+static int lenovo_event_tpx1cover(struct hid_device *hdev,
+		struct hid_field *field, struct hid_usage *usage, __s32 value)
+{
+	int ret = 0;
+
+	if (usage->hid == HID_CP_CONSUMERCONTROL) {
+		if (usage->usage_index == 8 && value == 1) {
+			struct lenovo_drvdata_tpx1cover *drv_data = hid_get_drvdata(hdev);
+
+			if (drv_data && drv_data->led_present) {
+				drv_data->fnlock_state = lenovo_led_brightness_get_tpx1cover(
+						&drv_data->led_fnlock) == LED_OFF ? 1 : 0;
+				lenovo_led_brightness_set_tpx1cover(
+					&drv_data->led_fnlock,
+					drv_data->fnlock_state ? LED_FULL : LED_OFF);
+			}
+		}
+
+	}
+
+	return ret;
+}
+
 static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
 		struct hid_usage *usage, __s32 value)
 {
@@ -533,6 +556,8 @@  static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
 	case USB_DEVICE_ID_LENOVO_CUSBKBD:
 	case USB_DEVICE_ID_LENOVO_CBTKBD:
 		return lenovo_event_cptkbd(hdev, field, usage, value);
+	case USB_DEVICE_ID_LENOVO_X1_COVER:
+		return lenovo_event_tpx1cover(hdev, field, usage, value);
 	default:
 		return 0;
 	}