Add support for the LEDs around the mode switch to the generic code path in
support of the second generation Intuos Pro.

Backport note: Kernel control of the LED mode switch is not present in
kernels before 4.5, and the WACOM_HID_WD_BUTTONCENTER usage is mapped,
but not handled specially by the driver here.

Signed-off-by: Aaron Skomra <aaron.sko...@wacom.com>
Reviewed-by: Ping Cheng <pi...@wacom.com>
Signed-off-by: Jiri Kosina <jkos...@suse.cz>
[aaron.sko...@wacom.com: Imported into input-wacom repository (10c55ca)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
[aaron.sko...@wacom.com: Backported from input-wacom repository (fc3d6d5)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
---
 3.17/wacom.h     |  2 ++
 3.17/wacom_sys.c | 38 +++++++++++++++++++++++++++++++++++---
 3.17/wacom_wac.c | 11 ++++++++++-
 3.17/wacom_wac.h |  1 +
 4 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/3.17/wacom.h b/3.17/wacom.h
index 100cad4..8adc02c 100644
--- a/3.17/wacom.h
+++ b/3.17/wacom.h
@@ -169,6 +169,7 @@ struct wacom {
        struct work_struct remote_work;
        struct delayed_work init_work;
        struct wacom_remote *remote;
+       bool generic_has_leds;
        struct wacom_leds {
                struct wacom_group_leds *groups;
                u8 llv;       /* status led brightness no button (1..127) */
@@ -218,6 +219,7 @@ void wacom_wac_event(struct hid_device *hdev, struct 
hid_field *field,
 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report);
 void wacom_battery_work(struct work_struct *work);
 int wacom_equivalent_usage(int usage);
+int wacom_initialize_leds(struct wacom *wacom);
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
 static int wacom_hid_report_len(struct hid_report *report)
diff --git a/3.17/wacom_sys.c b/3.17/wacom_sys.c
index 13b1ee7..6d1a380 100644
--- a/3.17/wacom_sys.c
+++ b/3.17/wacom_sys.c
@@ -779,8 +779,13 @@ static int wacom_led_control(struct wacom *wacom)
        if (!buf)
                return -ENOMEM;
 
-       if (wacom->wacom_wac.features.type >= INTUOS5S &&
-           wacom->wacom_wac.features.type <= INTUOSPL) {
+       if (wacom->wacom_wac.features.type == HID_GENERIC) {
+               buf[0] = WAC_CMD_LED_CONTROL_GENERIC;
+               buf[1] = wacom->led.llv;
+               buf[2] = wacom->led.groups[0].select & 0x03;
+
+       } else if ((wacom->wacom_wac.features.type >= INTUOS5S &&
+           wacom->wacom_wac.features.type <= INTUOSPL)) {
                /*
                 * Touch Ring and crop mark LED luminance may take on
                 * one of four values:
@@ -1050,6 +1055,17 @@ static struct attribute_group intuos5_led_attr_group = {
        .attrs = intuos5_led_attrs,
 };
 
+static struct attribute *generic_led_attrs[] = {
+       &dev_attr_status0_luminance.attr,
+       &dev_attr_status_led0_select.attr,
+       NULL
+};
+
+static struct attribute_group generic_led_attr_group = {
+       .name = "wacom_led",
+       .attrs = generic_led_attrs,
+};
+
 struct wacom_sysfs_group_devres {
        struct attribute_group *group;
        struct kobject *root;
@@ -1138,7 +1154,7 @@ static int wacom_led_groups_allocate(struct wacom *wacom, 
int count)
        return 0;
 }
 
-static int wacom_initialize_leds(struct wacom *wacom)
+int wacom_initialize_leds(struct wacom *wacom)
 {
        int error;
 
@@ -1147,6 +1163,22 @@ static int wacom_initialize_leds(struct wacom *wacom)
 
        /* Initialize default values */
        switch (wacom->wacom_wac.features.type) {
+       case HID_GENERIC:
+               if (!wacom->generic_has_leds)
+                       return 0;
+               wacom->led.llv = 100;
+
+               error = wacom_led_groups_allocate(wacom, 1);
+               if (error) {
+                       hid_err(wacom->hdev,
+                               "cannot create leds err: %d\n", error);
+                       return error;
+               }
+
+               error = wacom_devm_sysfs_create_group(wacom,
+                                                     &generic_led_attr_group);
+               break;
+
        case INTUOS4S:
        case INTUOS4:
        case INTUOS4WL:
diff --git a/3.17/wacom_wac.c b/3.17/wacom_wac.c
index 09dabbf..c51631a 100644
--- a/3.17/wacom_wac.c
+++ b/3.17/wacom_wac.c
@@ -1725,12 +1725,14 @@ static void wacom_wac_pad_usage_mapping(struct 
hid_device *hdev,
                wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
                features->device_type |= WACOM_DEVICETYPE_PAD;
                break;
+       case WACOM_HID_WD_BUTTONCENTER:
+               wacom->generic_has_leds = true;
+               /* fall through */
        case WACOM_HID_WD_BUTTONHOME:
        case WACOM_HID_WD_BUTTONUP:
        case WACOM_HID_WD_BUTTONDOWN:
        case WACOM_HID_WD_BUTTONLEFT:
        case WACOM_HID_WD_BUTTONRIGHT:
-       case WACOM_HID_WD_BUTTONCENTER:
                wacom_map_usage(input, usage, field, EV_KEY,
                                
wacom_numbered_button_to_key(features->numbered_buttons),
                                0);
@@ -1834,6 +1836,13 @@ static void wacom_wac_pad_event(struct hid_device *hdev, 
struct hid_field *field
                        input_sync(wacom_wac->shared->touch_input);
                }
                break;
+
+       case WACOM_HID_WD_BUTTONCENTER:
+               /*
+                * In kernels before 4.5, changing the LED is
+                * handled by gnome-settings-daemon.
+                */
+               /* fall through */
        default:
                input_event(input, usage->type, usage->code, value);
                break;
diff --git a/3.17/wacom_wac.h b/3.17/wacom_wac.h
index e3ac560..b7e2fd3 100644
--- a/3.17/wacom_wac.h
+++ b/3.17/wacom_wac.h
@@ -79,6 +79,7 @@
 #define WAC_CMD_ICON_XFER               0x23
 #define WAC_CMD_ICON_BT_XFER            0x26
 #define WAC_CMD_DELETE_PAIRING          0x20
+#define WAC_CMD_LED_CONTROL_GENERIC     0x32
 #define WAC_CMD_UNPAIR_ALL              0xFF
 #define WAC_CMD_WL_INTUOSP2             0x82
 
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to