Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 2 | /* |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 3 | * HID driver for Asus notebook built-in keyboard. |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 4 | * Fixes small logical maximum to match usage maximum. |
| 5 | * |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 6 | * Currently supported devices are: |
| 7 | * EeeBook X205TA |
| 8 | * VivoBook E200HA |
| 9 | * |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 10 | * Copyright (c) 2016 Yusuke Fujimaki <usk.fujimaki@gmail.com> |
| 11 | * |
| 12 | * This module based on hid-ortek by |
| 13 | * Copyright (c) 2010 Johnathon Harris <jmharris@gmail.com> |
| 14 | * Copyright (c) 2011 Jiri Kosina |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 15 | * |
| 16 | * This module has been updated to add support for Asus i2c touchpad. |
| 17 | * |
| 18 | * Copyright (c) 2016 Brendan McGrath <redmcg@redmandi.dyndns.org> |
| 19 | * Copyright (c) 2016 Victor Vlasenko <victor.vlasenko@sysgears.com> |
| 20 | * Copyright (c) 2016 Frederik Wenigwieser <frederik.wenigwieser@gmail.com> |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 24 | */ |
| 25 | |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 26 | #include <linux/dmi.h> |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 27 | #include <linux/hid.h> |
| 28 | #include <linux/module.h> |
Daniel Drake | 3b692c5 | 2018-10-09 14:40:56 +0800 | [diff] [blame] | 29 | #include <linux/platform_data/x86/asus-wmi.h> |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 30 | #include <linux/input/mt.h> |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 31 | #include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */ |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 32 | #include <linux/power_supply.h> |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 33 | |
| 34 | #include "hid-ids.h" |
| 35 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 36 | MODULE_AUTHOR("Yusuke Fujimaki <usk.fujimaki@gmail.com>"); |
| 37 | MODULE_AUTHOR("Brendan McGrath <redmcg@redmandi.dyndns.org>"); |
| 38 | MODULE_AUTHOR("Victor Vlasenko <victor.vlasenko@sysgears.com>"); |
| 39 | MODULE_AUTHOR("Frederik Wenigwieser <frederik.wenigwieser@gmail.com>"); |
| 40 | MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); |
| 41 | |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 42 | #define T100_TPAD_INTF 2 |
Hans de Goede | e271f6c | 2020-04-28 16:22:53 +0200 | [diff] [blame] | 43 | #define MEDION_E1239T_TPAD_INTF 1 |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 44 | |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 45 | #define E1239T_TP_TOGGLE_REPORT_ID 0x05 |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 46 | #define T100CHI_MOUSE_REPORT_ID 0x06 |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 47 | #define FEATURE_REPORT_ID 0x0d |
| 48 | #define INPUT_REPORT_ID 0x5d |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 49 | #define FEATURE_KBD_REPORT_ID 0x5a |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 50 | #define FEATURE_KBD_REPORT_SIZE 16 |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 51 | #define FEATURE_KBD_LED_REPORT_ID1 0x5d |
| 52 | #define FEATURE_KBD_LED_REPORT_ID2 0x5e |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 53 | |
| 54 | #define SUPPORT_KBD_BACKLIGHT BIT(0) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 55 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 56 | #define MAX_TOUCH_MAJOR 8 |
| 57 | #define MAX_PRESSURE 128 |
| 58 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 59 | #define BTN_LEFT_MASK 0x01 |
| 60 | #define CONTACT_TOOL_TYPE_MASK 0x80 |
| 61 | #define CONTACT_X_MSB_MASK 0xf0 |
| 62 | #define CONTACT_Y_MSB_MASK 0x0f |
| 63 | #define CONTACT_TOUCH_MAJOR_MASK 0x07 |
| 64 | #define CONTACT_PRESSURE_MASK 0x7f |
| 65 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 66 | #define BATTERY_REPORT_ID (0x03) |
| 67 | #define BATTERY_REPORT_SIZE (1 + 8) |
| 68 | #define BATTERY_LEVEL_MAX ((u8)255) |
| 69 | #define BATTERY_STAT_DISCONNECT (0) |
| 70 | #define BATTERY_STAT_CHARGING (1) |
| 71 | #define BATTERY_STAT_FULL (2) |
| 72 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 73 | #define QUIRK_FIX_NOTEBOOK_REPORT BIT(0) |
| 74 | #define QUIRK_NO_INIT_REPORTS BIT(1) |
| 75 | #define QUIRK_SKIP_INPUT_MAPPING BIT(2) |
| 76 | #define QUIRK_IS_MULTITOUCH BIT(3) |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 77 | #define QUIRK_NO_CONSUMER_USAGES BIT(4) |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 78 | #define QUIRK_USE_KBD_BACKLIGHT BIT(5) |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 79 | #define QUIRK_T100_KEYBOARD BIT(6) |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 80 | #define QUIRK_T100CHI BIT(7) |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 81 | #define QUIRK_G752_KEYBOARD BIT(8) |
Hans de Goede | a94f66a | 2021-05-05 23:39:34 +0200 | [diff] [blame] | 82 | #define QUIRK_T90CHI BIT(9) |
| 83 | #define QUIRK_MEDION_E1239T BIT(10) |
| 84 | #define QUIRK_ROG_NKEY_KEYBOARD BIT(11) |
Luke D. Jones | 87c7ee7 | 2021-08-07 14:49:21 +1200 | [diff] [blame] | 85 | #define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 86 | |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 87 | #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 88 | QUIRK_NO_INIT_REPORTS | \ |
| 89 | QUIRK_NO_CONSUMER_USAGES) |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 90 | #define I2C_TOUCHPAD_QUIRKS (QUIRK_NO_INIT_REPORTS | \ |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 91 | QUIRK_SKIP_INPUT_MAPPING | \ |
| 92 | QUIRK_IS_MULTITOUCH) |
| 93 | |
| 94 | #define TRKID_SGN ((TRKID_MAX + 1) >> 1) |
| 95 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 96 | struct asus_kbd_leds { |
| 97 | struct led_classdev cdev; |
| 98 | struct hid_device *hdev; |
| 99 | struct work_struct work; |
| 100 | unsigned int brightness; |
| 101 | bool removed; |
| 102 | }; |
| 103 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 104 | struct asus_touchpad_info { |
| 105 | int max_x; |
| 106 | int max_y; |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 107 | int res_x; |
| 108 | int res_y; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 109 | int contact_size; |
| 110 | int max_contacts; |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 111 | int report_size; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 114 | struct asus_drvdata { |
| 115 | unsigned long quirks; |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 116 | struct hid_device *hdev; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 117 | struct input_dev *input; |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 118 | struct input_dev *tp_kbd_input; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 119 | struct asus_kbd_leds *kbd_backlight; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 120 | const struct asus_touchpad_info *tp; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 121 | bool enable_backlight; |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 122 | struct power_supply *battery; |
| 123 | struct power_supply_desc battery_desc; |
| 124 | int battery_capacity; |
| 125 | int battery_stat; |
| 126 | bool battery_in_query; |
| 127 | unsigned long battery_next_query; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 128 | }; |
| 129 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 130 | static int asus_report_battery(struct asus_drvdata *, u8 *, int); |
| 131 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 132 | static const struct asus_touchpad_info asus_i2c_tp = { |
| 133 | .max_x = 2794, |
| 134 | .max_y = 1758, |
| 135 | .contact_size = 5, |
| 136 | .max_contacts = 5, |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 137 | .report_size = 28 /* 2 byte header + 5 * 5 + 1 byte footer */, |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static const struct asus_touchpad_info asus_t100ta_tp = { |
| 141 | .max_x = 2240, |
Hans de Goede | 25cc261 | 2017-07-02 16:34:13 +0200 | [diff] [blame] | 142 | .max_y = 1120, |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 143 | .res_x = 30, /* units/mm */ |
| 144 | .res_y = 27, /* units/mm */ |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 145 | .contact_size = 5, |
| 146 | .max_contacts = 5, |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 147 | .report_size = 28 /* 2 byte header + 5 * 5 + 1 byte footer */, |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 150 | static const struct asus_touchpad_info asus_t100ha_tp = { |
| 151 | .max_x = 2640, |
| 152 | .max_y = 1320, |
| 153 | .res_x = 30, /* units/mm */ |
| 154 | .res_y = 29, /* units/mm */ |
| 155 | .contact_size = 5, |
| 156 | .max_contacts = 5, |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 157 | .report_size = 28 /* 2 byte header + 5 * 5 + 1 byte footer */, |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 160 | static const struct asus_touchpad_info asus_t200ta_tp = { |
| 161 | .max_x = 3120, |
| 162 | .max_y = 1716, |
| 163 | .res_x = 30, /* units/mm */ |
| 164 | .res_y = 28, /* units/mm */ |
| 165 | .contact_size = 5, |
| 166 | .max_contacts = 5, |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 167 | .report_size = 28 /* 2 byte header + 5 * 5 + 1 byte footer */, |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 168 | }; |
| 169 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 170 | static const struct asus_touchpad_info asus_t100chi_tp = { |
| 171 | .max_x = 2640, |
| 172 | .max_y = 1320, |
| 173 | .res_x = 31, /* units/mm */ |
| 174 | .res_y = 29, /* units/mm */ |
| 175 | .contact_size = 3, |
| 176 | .max_contacts = 4, |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 177 | .report_size = 15 /* 2 byte header + 3 * 4 + 1 byte footer */, |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 178 | }; |
| 179 | |
Hans de Goede | e271f6c | 2020-04-28 16:22:53 +0200 | [diff] [blame] | 180 | static const struct asus_touchpad_info medion_e1239t_tp = { |
| 181 | .max_x = 2640, |
| 182 | .max_y = 1380, |
| 183 | .res_x = 29, /* units/mm */ |
| 184 | .res_y = 28, /* units/mm */ |
| 185 | .contact_size = 5, |
| 186 | .max_contacts = 5, |
| 187 | .report_size = 32 /* 2 byte header + 5 * 5 + 5 byte footer */, |
| 188 | }; |
| 189 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 190 | static void asus_report_contact_down(struct asus_drvdata *drvdat, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 191 | int toolType, u8 *data) |
| 192 | { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 193 | struct input_dev *input = drvdat->input; |
| 194 | int touch_major, pressure, x, y; |
| 195 | |
| 196 | x = (data[0] & CONTACT_X_MSB_MASK) << 4 | data[1]; |
| 197 | y = drvdat->tp->max_y - ((data[0] & CONTACT_Y_MSB_MASK) << 8 | data[2]); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 198 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 199 | input_report_abs(input, ABS_MT_POSITION_X, x); |
| 200 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
| 201 | |
| 202 | if (drvdat->tp->contact_size < 5) |
| 203 | return; |
| 204 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 205 | if (toolType == MT_TOOL_PALM) { |
| 206 | touch_major = MAX_TOUCH_MAJOR; |
| 207 | pressure = MAX_PRESSURE; |
| 208 | } else { |
| 209 | touch_major = (data[3] >> 4) & CONTACT_TOUCH_MAJOR_MASK; |
| 210 | pressure = data[4] & CONTACT_PRESSURE_MASK; |
| 211 | } |
| 212 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 213 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major); |
| 214 | input_report_abs(input, ABS_MT_PRESSURE, pressure); |
| 215 | } |
| 216 | |
| 217 | /* Required for Synaptics Palm Detection */ |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 218 | static void asus_report_tool_width(struct asus_drvdata *drvdat) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 219 | { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 220 | struct input_mt *mt = drvdat->input->mt; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 221 | struct input_mt_slot *oldest; |
| 222 | int oldid, count, i; |
| 223 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 224 | if (drvdat->tp->contact_size < 5) |
| 225 | return; |
| 226 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 227 | oldest = NULL; |
| 228 | oldid = mt->trkid; |
| 229 | count = 0; |
| 230 | |
| 231 | for (i = 0; i < mt->num_slots; ++i) { |
| 232 | struct input_mt_slot *ps = &mt->slots[i]; |
| 233 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); |
| 234 | |
| 235 | if (id < 0) |
| 236 | continue; |
| 237 | if ((id - oldid) & TRKID_SGN) { |
| 238 | oldest = ps; |
| 239 | oldid = id; |
| 240 | } |
| 241 | count++; |
| 242 | } |
| 243 | |
| 244 | if (oldest) { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 245 | input_report_abs(drvdat->input, ABS_TOOL_WIDTH, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 246 | input_mt_get_value(oldest, ABS_MT_TOUCH_MAJOR)); |
| 247 | } |
| 248 | } |
| 249 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 250 | static int asus_report_input(struct asus_drvdata *drvdat, u8 *data, int size) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 251 | { |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 252 | int i, toolType = MT_TOOL_FINGER; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 253 | u8 *contactData = data + 2; |
| 254 | |
Hans de Goede | a61f9e4 | 2020-04-28 16:22:52 +0200 | [diff] [blame] | 255 | if (size != drvdat->tp->report_size) |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 256 | return 0; |
| 257 | |
| 258 | for (i = 0; i < drvdat->tp->max_contacts; i++) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 259 | bool down = !!(data[1] & BIT(i+3)); |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 260 | |
| 261 | if (drvdat->tp->contact_size >= 5) |
| 262 | toolType = contactData[3] & CONTACT_TOOL_TYPE_MASK ? |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 263 | MT_TOOL_PALM : MT_TOOL_FINGER; |
| 264 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 265 | input_mt_slot(drvdat->input, i); |
| 266 | input_mt_report_slot_state(drvdat->input, toolType, down); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 267 | |
| 268 | if (down) { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 269 | asus_report_contact_down(drvdat, toolType, contactData); |
| 270 | contactData += drvdat->tp->contact_size; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 274 | input_report_key(drvdat->input, BTN_LEFT, data[1] & BTN_LEFT_MASK); |
| 275 | asus_report_tool_width(drvdat); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 276 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 277 | input_mt_sync_frame(drvdat->input); |
| 278 | input_sync(drvdat->input); |
| 279 | |
| 280 | return 1; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 281 | } |
| 282 | |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 283 | static int asus_e1239t_event(struct asus_drvdata *drvdat, u8 *data, int size) |
| 284 | { |
| 285 | if (size != 3) |
| 286 | return 0; |
| 287 | |
| 288 | /* Handle broken mute key which only sends press events */ |
| 289 | if (!drvdat->tp && |
| 290 | data[0] == 0x02 && data[1] == 0xe2 && data[2] == 0x00) { |
| 291 | input_report_key(drvdat->input, KEY_MUTE, 1); |
| 292 | input_sync(drvdat->input); |
| 293 | input_report_key(drvdat->input, KEY_MUTE, 0); |
| 294 | input_sync(drvdat->input); |
| 295 | return 1; |
| 296 | } |
| 297 | |
| 298 | /* Handle custom touchpad toggle key which only sends press events */ |
| 299 | if (drvdat->tp_kbd_input && |
| 300 | data[0] == 0x05 && data[1] == 0x02 && data[2] == 0x28) { |
| 301 | input_report_key(drvdat->tp_kbd_input, KEY_F21, 1); |
| 302 | input_sync(drvdat->tp_kbd_input); |
| 303 | input_report_key(drvdat->tp_kbd_input, KEY_F21, 0); |
| 304 | input_sync(drvdat->tp_kbd_input); |
| 305 | return 1; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Hans de Goede | e98e380 | 2018-11-26 11:52:16 +0100 | [diff] [blame] | 311 | static int asus_event(struct hid_device *hdev, struct hid_field *field, |
| 312 | struct hid_usage *usage, __s32 value) |
| 313 | { |
| 314 | if ((usage->hid & HID_USAGE_PAGE) == 0xff310000 && |
Hans de Goede | c07a025 | 2019-10-24 13:59:09 +0200 | [diff] [blame] | 315 | (usage->hid & HID_USAGE) != 0x00 && |
| 316 | (usage->hid & HID_USAGE) != 0xff && !usage->type) { |
Hans de Goede | e98e380 | 2018-11-26 11:52:16 +0100 | [diff] [blame] | 317 | hid_warn(hdev, "Unmapped Asus vendor usagepage code 0x%02x\n", |
| 318 | usage->hid & HID_USAGE); |
| 319 | } |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 324 | static int asus_raw_event(struct hid_device *hdev, |
| 325 | struct hid_report *report, u8 *data, int size) |
| 326 | { |
| 327 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 328 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 329 | if (drvdata->battery && data[0] == BATTERY_REPORT_ID) |
| 330 | return asus_report_battery(drvdata, data, size); |
| 331 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 332 | if (drvdata->tp && data[0] == INPUT_REPORT_ID) |
| 333 | return asus_report_input(drvdata, data, size); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 334 | |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 335 | if (drvdata->quirks & QUIRK_MEDION_E1239T) |
| 336 | return asus_e1239t_event(drvdata, data, size); |
| 337 | |
Luke D Jones | 4bfb2c7 | 2021-02-19 10:38:46 +1300 | [diff] [blame] | 338 | if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) { |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 339 | /* |
| 340 | * Skip these report ID, the device emits a continuous stream associated |
| 341 | * with the AURA mode it is in which looks like an 'echo'. |
| 342 | */ |
| 343 | if (report->id == FEATURE_KBD_LED_REPORT_ID1 || |
| 344 | report->id == FEATURE_KBD_LED_REPORT_ID2) { |
| 345 | return -1; |
| 346 | /* Additional report filtering */ |
| 347 | } else if (report->id == FEATURE_KBD_REPORT_ID) { |
| 348 | /* |
| 349 | * G14 and G15 send these codes on some keypresses with no |
| 350 | * discernable reason for doing so. We'll filter them out to avoid |
| 351 | * unmapped warning messages later. |
| 352 | */ |
| 353 | if (data[1] == 0xea || data[1] == 0xec || data[1] == 0x02 || |
| 354 | data[1] == 0x8a || data[1] == 0x9e) { |
| 355 | return -1; |
| 356 | } |
| 357 | } |
Luke D Jones | c980512 | 2021-04-18 21:12:29 +1200 | [diff] [blame] | 358 | if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) { |
| 359 | /* |
| 360 | * G713 and G733 send these codes on some keypresses, depending on |
| 361 | * the key pressed it can trigger a shutdown event if not caught. |
| 362 | */ |
| 363 | if(data[0] == 0x02 && data[1] == 0x30) { |
| 364 | return -1; |
| 365 | } |
| 366 | } |
| 367 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 368 | } |
| 369 | |
Luke D. Jones | 87c7ee7 | 2021-08-07 14:49:21 +1200 | [diff] [blame] | 370 | if (drvdata->quirks & QUIRK_ROG_CLAYMORE_II_KEYBOARD) { |
| 371 | /* |
| 372 | * CLAYMORE II keyboard sends this packet when it goes to sleep |
| 373 | * this causes the whole system to go into suspend. |
| 374 | */ |
| 375 | |
| 376 | if(size == 2 && data[0] == 0x02 && data[1] == 0x00) { |
| 377 | return -1; |
| 378 | } |
| 379 | } |
| 380 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 384 | static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size) |
| 385 | { |
| 386 | unsigned char *dmabuf; |
| 387 | int ret; |
| 388 | |
| 389 | dmabuf = kmemdup(buf, buf_size, GFP_KERNEL); |
| 390 | if (!dmabuf) |
| 391 | return -ENOMEM; |
| 392 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 393 | /* |
| 394 | * The report ID should be set from the incoming buffer due to LED and key |
| 395 | * interfaces having different pages |
| 396 | */ |
| 397 | ret = hid_hw_raw_request(hdev, buf[0], dmabuf, |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 398 | buf_size, HID_FEATURE_REPORT, |
| 399 | HID_REQ_SET_REPORT); |
| 400 | kfree(dmabuf); |
| 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | static int asus_kbd_init(struct hid_device *hdev) |
| 406 | { |
| 407 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54, |
| 408 | 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 }; |
| 409 | int ret; |
| 410 | |
| 411 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); |
| 412 | if (ret < 0) |
| 413 | hid_err(hdev, "Asus failed to send init command: %d\n", ret); |
| 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | static int asus_kbd_get_functions(struct hid_device *hdev, |
| 419 | unsigned char *kbd_func) |
| 420 | { |
| 421 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 }; |
| 422 | u8 *readbuf; |
| 423 | int ret; |
| 424 | |
| 425 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); |
| 426 | if (ret < 0) { |
| 427 | hid_err(hdev, "Asus failed to send configuration command: %d\n", ret); |
| 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); |
| 432 | if (!readbuf) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | ret = hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, readbuf, |
| 436 | FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT, |
| 437 | HID_REQ_GET_REPORT); |
| 438 | if (ret < 0) { |
| 439 | hid_err(hdev, "Asus failed to request functions: %d\n", ret); |
| 440 | kfree(readbuf); |
| 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | *kbd_func = readbuf[6]; |
| 445 | |
| 446 | kfree(readbuf); |
| 447 | return ret; |
| 448 | } |
| 449 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 450 | static int rog_nkey_led_init(struct hid_device *hdev) |
| 451 | { |
| 452 | u8 buf_init_start[] = { FEATURE_KBD_LED_REPORT_ID1, 0xB9 }; |
| 453 | u8 buf_init2[] = { FEATURE_KBD_LED_REPORT_ID1, 0x41, 0x53, 0x55, 0x53, 0x20, |
| 454 | 0x54, 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 }; |
| 455 | u8 buf_init3[] = { FEATURE_KBD_LED_REPORT_ID1, |
| 456 | 0x05, 0x20, 0x31, 0x00, 0x08 }; |
| 457 | int ret; |
| 458 | |
| 459 | hid_info(hdev, "Asus initialise N-KEY Device"); |
| 460 | /* The first message is an init start */ |
| 461 | ret = asus_kbd_set_report(hdev, buf_init_start, sizeof(buf_init_start)); |
| 462 | if (ret < 0) { |
| 463 | hid_warn(hdev, "Asus failed to send init start command: %d\n", ret); |
| 464 | return ret; |
| 465 | } |
| 466 | /* Followed by a string */ |
| 467 | ret = asus_kbd_set_report(hdev, buf_init2, sizeof(buf_init2)); |
| 468 | if (ret < 0) { |
| 469 | hid_warn(hdev, "Asus failed to send init command 1.0: %d\n", ret); |
| 470 | return ret; |
| 471 | } |
| 472 | /* Followed by a string */ |
| 473 | ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3)); |
| 474 | if (ret < 0) { |
| 475 | hid_warn(hdev, "Asus failed to send init command 1.1: %d\n", ret); |
| 476 | return ret; |
| 477 | } |
| 478 | |
| 479 | /* begin second report ID with same data */ |
| 480 | buf_init2[0] = FEATURE_KBD_LED_REPORT_ID2; |
| 481 | buf_init3[0] = FEATURE_KBD_LED_REPORT_ID2; |
| 482 | |
| 483 | ret = asus_kbd_set_report(hdev, buf_init2, sizeof(buf_init2)); |
| 484 | if (ret < 0) { |
| 485 | hid_warn(hdev, "Asus failed to send init command 2.0: %d\n", ret); |
| 486 | return ret; |
| 487 | } |
| 488 | ret = asus_kbd_set_report(hdev, buf_init3, sizeof(buf_init3)); |
| 489 | if (ret < 0) |
| 490 | hid_warn(hdev, "Asus failed to send init command 2.1: %d\n", ret); |
| 491 | |
| 492 | return ret; |
| 493 | } |
| 494 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 495 | static void asus_kbd_backlight_set(struct led_classdev *led_cdev, |
| 496 | enum led_brightness brightness) |
| 497 | { |
| 498 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, |
| 499 | cdev); |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 500 | led->brightness = brightness; |
| 501 | schedule_work(&led->work); |
| 502 | } |
| 503 | |
| 504 | static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev) |
| 505 | { |
| 506 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, |
| 507 | cdev); |
| 508 | |
| 509 | return led->brightness; |
| 510 | } |
| 511 | |
| 512 | static void asus_kbd_backlight_work(struct work_struct *work) |
| 513 | { |
| 514 | struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work); |
| 515 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, 0x00 }; |
| 516 | int ret; |
| 517 | |
| 518 | if (led->removed) |
| 519 | return; |
| 520 | |
| 521 | buf[4] = led->brightness; |
| 522 | |
| 523 | ret = asus_kbd_set_report(led->hdev, buf, sizeof(buf)); |
| 524 | if (ret < 0) |
| 525 | hid_err(led->hdev, "Asus failed to set keyboard backlight: %d\n", ret); |
| 526 | } |
| 527 | |
Daniel Drake | 3b692c5 | 2018-10-09 14:40:56 +0800 | [diff] [blame] | 528 | /* WMI-based keyboard backlight LED control (via asus-wmi driver) takes |
| 529 | * precedence. We only activate HID-based backlight control when the |
| 530 | * WMI control is not available. |
| 531 | */ |
| 532 | static bool asus_kbd_wmi_led_control_present(struct hid_device *hdev) |
| 533 | { |
| 534 | u32 value; |
| 535 | int ret; |
| 536 | |
Arnd Bergmann | 3fc202e | 2018-11-02 16:14:32 +0100 | [diff] [blame] | 537 | if (!IS_ENABLED(CONFIG_ASUS_WMI)) |
| 538 | return false; |
| 539 | |
Yurii Pavlovskyi | e0668f2 | 2019-05-14 21:00:31 +0200 | [diff] [blame] | 540 | ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, |
Daniel Drake | 3b692c5 | 2018-10-09 14:40:56 +0800 | [diff] [blame] | 541 | ASUS_WMI_DEVID_KBD_BACKLIGHT, 0, &value); |
| 542 | hid_dbg(hdev, "WMI backlight check: rc %d value %x", ret, value); |
| 543 | if (ret) |
| 544 | return false; |
| 545 | |
| 546 | return !!(value & ASUS_WMI_DSTS_PRESENCE_BIT); |
| 547 | } |
| 548 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 549 | static int asus_kbd_register_leds(struct hid_device *hdev) |
| 550 | { |
| 551 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 552 | unsigned char kbd_func; |
| 553 | int ret; |
| 554 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 555 | if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) { |
| 556 | ret = rog_nkey_led_init(hdev); |
| 557 | if (ret < 0) |
| 558 | return ret; |
| 559 | } else { |
| 560 | /* Initialize keyboard */ |
| 561 | ret = asus_kbd_init(hdev); |
| 562 | if (ret < 0) |
| 563 | return ret; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 564 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 565 | /* Get keyboard functions */ |
| 566 | ret = asus_kbd_get_functions(hdev, &kbd_func); |
| 567 | if (ret < 0) |
| 568 | return ret; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 569 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 570 | /* Check for backlight support */ |
| 571 | if (!(kbd_func & SUPPORT_KBD_BACKLIGHT)) |
| 572 | return -ENODEV; |
| 573 | } |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 574 | |
| 575 | drvdata->kbd_backlight = devm_kzalloc(&hdev->dev, |
| 576 | sizeof(struct asus_kbd_leds), |
| 577 | GFP_KERNEL); |
| 578 | if (!drvdata->kbd_backlight) |
| 579 | return -ENOMEM; |
| 580 | |
| 581 | drvdata->kbd_backlight->removed = false; |
| 582 | drvdata->kbd_backlight->brightness = 0; |
| 583 | drvdata->kbd_backlight->hdev = hdev; |
| 584 | drvdata->kbd_backlight->cdev.name = "asus::kbd_backlight"; |
| 585 | drvdata->kbd_backlight->cdev.max_brightness = 3; |
| 586 | drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; |
| 587 | drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; |
| 588 | INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work); |
| 589 | |
| 590 | ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev); |
| 591 | if (ret < 0) { |
| 592 | /* No need to have this still around */ |
| 593 | devm_kfree(&hdev->dev, drvdata->kbd_backlight); |
| 594 | } |
| 595 | |
| 596 | return ret; |
| 597 | } |
| 598 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 599 | /* |
| 600 | * [0] REPORT_ID (same value defined in report descriptor) |
| 601 | * [1] rest battery level. range [0..255] |
| 602 | * [2]..[7] Bluetooth hardware address (MAC address) |
| 603 | * [8] charging status |
| 604 | * = 0 : AC offline / discharging |
| 605 | * = 1 : AC online / charging |
| 606 | * = 2 : AC online / fully charged |
| 607 | */ |
| 608 | static int asus_parse_battery(struct asus_drvdata *drvdata, u8 *data, int size) |
| 609 | { |
| 610 | u8 sts; |
| 611 | u8 lvl; |
| 612 | int val; |
| 613 | |
| 614 | lvl = data[1]; |
| 615 | sts = data[8]; |
| 616 | |
| 617 | drvdata->battery_capacity = ((int)lvl * 100) / (int)BATTERY_LEVEL_MAX; |
| 618 | |
| 619 | switch (sts) { |
| 620 | case BATTERY_STAT_CHARGING: |
| 621 | val = POWER_SUPPLY_STATUS_CHARGING; |
| 622 | break; |
| 623 | case BATTERY_STAT_FULL: |
| 624 | val = POWER_SUPPLY_STATUS_FULL; |
| 625 | break; |
| 626 | case BATTERY_STAT_DISCONNECT: |
| 627 | default: |
| 628 | val = POWER_SUPPLY_STATUS_DISCHARGING; |
| 629 | break; |
| 630 | } |
| 631 | drvdata->battery_stat = val; |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int asus_report_battery(struct asus_drvdata *drvdata, u8 *data, int size) |
| 637 | { |
| 638 | /* notify only the autonomous event by device */ |
| 639 | if ((drvdata->battery_in_query == false) && |
| 640 | (size == BATTERY_REPORT_SIZE)) |
| 641 | power_supply_changed(drvdata->battery); |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static int asus_battery_query(struct asus_drvdata *drvdata) |
| 647 | { |
| 648 | u8 *buf; |
| 649 | int ret = 0; |
| 650 | |
| 651 | buf = kmalloc(BATTERY_REPORT_SIZE, GFP_KERNEL); |
| 652 | if (!buf) |
| 653 | return -ENOMEM; |
| 654 | |
| 655 | drvdata->battery_in_query = true; |
| 656 | ret = hid_hw_raw_request(drvdata->hdev, BATTERY_REPORT_ID, |
| 657 | buf, BATTERY_REPORT_SIZE, |
| 658 | HID_INPUT_REPORT, HID_REQ_GET_REPORT); |
| 659 | drvdata->battery_in_query = false; |
| 660 | if (ret == BATTERY_REPORT_SIZE) |
| 661 | ret = asus_parse_battery(drvdata, buf, BATTERY_REPORT_SIZE); |
| 662 | else |
| 663 | ret = -ENODATA; |
| 664 | |
| 665 | kfree(buf); |
| 666 | |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | static enum power_supply_property asus_battery_props[] = { |
| 671 | POWER_SUPPLY_PROP_STATUS, |
| 672 | POWER_SUPPLY_PROP_PRESENT, |
| 673 | POWER_SUPPLY_PROP_CAPACITY, |
| 674 | POWER_SUPPLY_PROP_SCOPE, |
| 675 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 676 | }; |
| 677 | |
| 678 | #define QUERY_MIN_INTERVAL (60 * HZ) /* 60[sec] */ |
| 679 | |
| 680 | static int asus_battery_get_property(struct power_supply *psy, |
| 681 | enum power_supply_property psp, |
| 682 | union power_supply_propval *val) |
| 683 | { |
| 684 | struct asus_drvdata *drvdata = power_supply_get_drvdata(psy); |
| 685 | int ret = 0; |
| 686 | |
| 687 | switch (psp) { |
| 688 | case POWER_SUPPLY_PROP_STATUS: |
| 689 | case POWER_SUPPLY_PROP_CAPACITY: |
| 690 | if (time_before(drvdata->battery_next_query, jiffies)) { |
| 691 | drvdata->battery_next_query = |
| 692 | jiffies + QUERY_MIN_INTERVAL; |
| 693 | ret = asus_battery_query(drvdata); |
| 694 | if (ret) |
| 695 | return ret; |
| 696 | } |
| 697 | if (psp == POWER_SUPPLY_PROP_STATUS) |
| 698 | val->intval = drvdata->battery_stat; |
| 699 | else |
| 700 | val->intval = drvdata->battery_capacity; |
| 701 | break; |
| 702 | case POWER_SUPPLY_PROP_PRESENT: |
| 703 | val->intval = 1; |
| 704 | break; |
| 705 | case POWER_SUPPLY_PROP_SCOPE: |
| 706 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 707 | break; |
| 708 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 709 | val->strval = drvdata->hdev->name; |
| 710 | break; |
| 711 | default: |
| 712 | ret = -EINVAL; |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | static int asus_battery_probe(struct hid_device *hdev) |
| 720 | { |
| 721 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 722 | struct power_supply_config pscfg = { .drv_data = drvdata }; |
| 723 | int ret = 0; |
| 724 | |
| 725 | drvdata->battery_capacity = 0; |
| 726 | drvdata->battery_stat = POWER_SUPPLY_STATUS_UNKNOWN; |
| 727 | drvdata->battery_in_query = false; |
| 728 | |
| 729 | drvdata->battery_desc.properties = asus_battery_props; |
| 730 | drvdata->battery_desc.num_properties = ARRAY_SIZE(asus_battery_props); |
| 731 | drvdata->battery_desc.get_property = asus_battery_get_property; |
| 732 | drvdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
| 733 | drvdata->battery_desc.use_for_apm = 0; |
| 734 | drvdata->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, |
| 735 | "asus-keyboard-%s-battery", |
| 736 | strlen(hdev->uniq) ? |
| 737 | hdev->uniq : dev_name(&hdev->dev)); |
| 738 | if (!drvdata->battery_desc.name) |
| 739 | return -ENOMEM; |
| 740 | |
| 741 | drvdata->battery_next_query = jiffies; |
| 742 | |
| 743 | drvdata->battery = devm_power_supply_register(&hdev->dev, |
| 744 | &(drvdata->battery_desc), &pscfg); |
| 745 | if (IS_ERR(drvdata->battery)) { |
| 746 | ret = PTR_ERR(drvdata->battery); |
| 747 | drvdata->battery = NULL; |
| 748 | hid_err(hdev, "Unable to register battery device\n"); |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | power_supply_powers(drvdata->battery, &hdev->dev); |
| 753 | |
| 754 | return ret; |
| 755 | } |
| 756 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 757 | static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) |
| 758 | { |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 759 | struct input_dev *input = hi->input; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 760 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 761 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 762 | /* T100CHI uses MULTI_INPUT, bind the touchpad to the mouse hid_input */ |
| 763 | if (drvdata->quirks & QUIRK_T100CHI && |
| 764 | hi->report->id != T100CHI_MOUSE_REPORT_ID) |
| 765 | return 0; |
| 766 | |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 767 | /* Handle MULTI_INPUT on E1239T mouse/touchpad USB interface */ |
| 768 | if (drvdata->tp && (drvdata->quirks & QUIRK_MEDION_E1239T)) { |
| 769 | switch (hi->report->id) { |
| 770 | case E1239T_TP_TOGGLE_REPORT_ID: |
| 771 | input_set_capability(input, EV_KEY, KEY_F21); |
| 772 | input->name = "Asus Touchpad Keys"; |
| 773 | drvdata->tp_kbd_input = input; |
| 774 | return 0; |
| 775 | case INPUT_REPORT_ID: |
| 776 | break; /* Touchpad report, handled below */ |
| 777 | default: |
| 778 | return 0; /* Ignore other reports */ |
| 779 | } |
| 780 | } |
| 781 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 782 | if (drvdata->tp) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 783 | int ret; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 784 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 785 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, |
| 786 | drvdata->tp->max_x, 0, 0); |
| 787 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, |
| 788 | drvdata->tp->max_y, 0, 0); |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 789 | input_abs_set_res(input, ABS_MT_POSITION_X, drvdata->tp->res_x); |
| 790 | input_abs_set_res(input, ABS_MT_POSITION_Y, drvdata->tp->res_y); |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 791 | |
| 792 | if (drvdata->tp->contact_size >= 5) { |
| 793 | input_set_abs_params(input, ABS_TOOL_WIDTH, 0, |
| 794 | MAX_TOUCH_MAJOR, 0, 0); |
| 795 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, |
| 796 | MAX_TOUCH_MAJOR, 0, 0); |
| 797 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, |
| 798 | MAX_PRESSURE, 0, 0); |
| 799 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 800 | |
| 801 | __set_bit(BTN_LEFT, input->keybit); |
| 802 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
| 803 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 804 | ret = input_mt_init_slots(input, drvdata->tp->max_contacts, |
| 805 | INPUT_MT_POINTER); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 806 | |
| 807 | if (ret) { |
| 808 | hid_err(hdev, "Asus input mt init slots failed: %d\n", ret); |
| 809 | return ret; |
| 810 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 811 | } |
| 812 | |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 813 | drvdata->input = input; |
| 814 | |
Daniel Drake | 3b692c5 | 2018-10-09 14:40:56 +0800 | [diff] [blame] | 815 | if (drvdata->enable_backlight && |
| 816 | !asus_kbd_wmi_led_control_present(hdev) && |
| 817 | asus_kbd_register_leds(hdev)) |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 818 | hid_warn(hdev, "Failed to initialize backlight.\n"); |
| 819 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 820 | return 0; |
| 821 | } |
| 822 | |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 823 | #define asus_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 824 | max, EV_KEY, (c)) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 825 | static int asus_input_mapping(struct hid_device *hdev, |
| 826 | struct hid_input *hi, struct hid_field *field, |
| 827 | struct hid_usage *usage, unsigned long **bit, |
| 828 | int *max) |
| 829 | { |
| 830 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 831 | |
| 832 | if (drvdata->quirks & QUIRK_SKIP_INPUT_MAPPING) { |
| 833 | /* Don't map anything from the HID report. |
| 834 | * We do it all manually in asus_input_configured |
| 835 | */ |
| 836 | return -1; |
| 837 | } |
| 838 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 839 | /* |
| 840 | * Ignore a bunch of bogus collections in the T100CHI descriptor. |
| 841 | * This avoids a bunch of non-functional hid_input devices getting |
| 842 | * created because of the T100CHI using HID_QUIRK_MULTI_INPUT. |
| 843 | */ |
Hans de Goede | a80b2f3 | 2020-04-28 16:22:50 +0200 | [diff] [blame] | 844 | if ((drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) && |
| 845 | (field->application == (HID_UP_GENDESK | 0x0080) || |
| 846 | field->application == HID_GD_MOUSE || |
| 847 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0024) || |
| 848 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0025) || |
| 849 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0026))) |
| 850 | return -1; |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 851 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 852 | /* ASUS-specific keyboard hotkeys and led backlight */ |
| 853 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR) { |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 854 | switch (usage->hid & HID_USAGE) { |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 855 | case 0x10: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 856 | case 0x20: asus_map_key_clear(KEY_BRIGHTNESSUP); break; |
Vinícius Angiolucci Reis | e3d9234 | 2021-11-11 19:47:35 -0300 | [diff] [blame] | 857 | case 0x35: asus_map_key_clear(KEY_DISPLAY_OFF); break; |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 858 | case 0x6c: asus_map_key_clear(KEY_SLEEP); break; |
Hans de Goede | 2340bad | 2018-11-26 11:52:17 +0100 | [diff] [blame] | 859 | case 0x7c: asus_map_key_clear(KEY_MICMUTE); break; |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 860 | case 0x82: asus_map_key_clear(KEY_CAMERA); break; |
Matjaz Hegedic | 802b24b | 2017-03-09 00:31:15 +0100 | [diff] [blame] | 861 | case 0x88: asus_map_key_clear(KEY_RFKILL); break; |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 862 | case 0xb5: asus_map_key_clear(KEY_CALC); break; |
| 863 | case 0xc4: asus_map_key_clear(KEY_KBDILLUMUP); break; |
| 864 | case 0xc5: asus_map_key_clear(KEY_KBDILLUMDOWN); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 865 | |
| 866 | /* ASUS touchpad toggle */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 867 | case 0x6b: asus_map_key_clear(KEY_F21); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 868 | |
| 869 | /* ROG key */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 870 | case 0x38: asus_map_key_clear(KEY_PROG1); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 871 | |
| 872 | /* Fn+C ASUS Splendid */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 873 | case 0xba: asus_map_key_clear(KEY_PROG2); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 874 | |
| 875 | /* Fn+Space Power4Gear Hybrid */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 876 | case 0x5c: asus_map_key_clear(KEY_PROG3); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 877 | |
Hans de Goede | 2340bad | 2018-11-26 11:52:17 +0100 | [diff] [blame] | 878 | /* Fn+F5 "fan" symbol on FX503VD */ |
| 879 | case 0x99: asus_map_key_clear(KEY_PROG4); break; |
| 880 | |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 881 | /* Fn+F5 "fan" symbol on N-Key keyboard */ |
| 882 | case 0xae: asus_map_key_clear(KEY_PROG4); break; |
| 883 | |
| 884 | /* Fn+Ret "Calc" symbol on N-Key keyboard */ |
| 885 | case 0x92: asus_map_key_clear(KEY_CALC); break; |
| 886 | |
| 887 | /* Fn+Left Aura mode previous on N-Key keyboard */ |
| 888 | case 0xb2: asus_map_key_clear(KEY_PROG2); break; |
| 889 | |
| 890 | /* Fn+Right Aura mode next on N-Key keyboard */ |
| 891 | case 0xb3: asus_map_key_clear(KEY_PROG3); break; |
| 892 | |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 893 | default: |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 894 | /* ASUS lazily declares 256 usages, ignore the rest, |
| 895 | * as some make the keyboard appear as a pointer device. */ |
| 896 | return -1; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 897 | } |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 898 | |
| 899 | /* |
| 900 | * Check and enable backlight only on devices with UsagePage == |
| 901 | * 0xff31 to avoid initializing the keyboard firmware multiple |
| 902 | * times on devices with multiple HID descriptors but same |
| 903 | * PID/VID. |
| 904 | */ |
| 905 | if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) |
| 906 | drvdata->enable_backlight = true; |
| 907 | |
Hans de Goede | 4e4c60f | 2020-04-28 16:22:49 +0200 | [diff] [blame] | 908 | set_bit(EV_REP, hi->input->evbit); |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 909 | return 1; |
| 910 | } |
| 911 | |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 912 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 913 | switch (usage->hid & HID_USAGE) { |
| 914 | case 0xff01: asus_map_key_clear(BTN_1); break; |
| 915 | case 0xff02: asus_map_key_clear(BTN_2); break; |
| 916 | case 0xff03: asus_map_key_clear(BTN_3); break; |
| 917 | case 0xff04: asus_map_key_clear(BTN_4); break; |
| 918 | case 0xff05: asus_map_key_clear(BTN_5); break; |
| 919 | case 0xff06: asus_map_key_clear(BTN_6); break; |
| 920 | case 0xff07: asus_map_key_clear(BTN_7); break; |
| 921 | case 0xff08: asus_map_key_clear(BTN_8); break; |
| 922 | case 0xff09: asus_map_key_clear(BTN_9); break; |
| 923 | case 0xff0a: asus_map_key_clear(BTN_A); break; |
| 924 | case 0xff0b: asus_map_key_clear(BTN_B); break; |
| 925 | case 0x00f1: asus_map_key_clear(KEY_WLAN); break; |
| 926 | case 0x00f2: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 927 | case 0x00f3: asus_map_key_clear(KEY_BRIGHTNESSUP); break; |
| 928 | case 0x00f4: asus_map_key_clear(KEY_DISPLAY_OFF); break; |
| 929 | case 0x00f7: asus_map_key_clear(KEY_CAMERA); break; |
| 930 | case 0x00f8: asus_map_key_clear(KEY_PROG1); break; |
| 931 | default: |
| 932 | return 0; |
| 933 | } |
| 934 | |
Hans de Goede | 4e4c60f | 2020-04-28 16:22:49 +0200 | [diff] [blame] | 935 | set_bit(EV_REP, hi->input->evbit); |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 936 | return 1; |
| 937 | } |
| 938 | |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 939 | if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES && |
| 940 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { |
| 941 | switch (usage->hid & HID_USAGE) { |
| 942 | case 0xe2: /* Mute */ |
| 943 | case 0xe9: /* Volume up */ |
| 944 | case 0xea: /* Volume down */ |
| 945 | return 0; |
| 946 | default: |
| 947 | /* Ignore dummy Consumer usages which make the |
| 948 | * keyboard incorrectly appear as a pointer device. |
| 949 | */ |
| 950 | return -1; |
| 951 | } |
| 952 | } |
| 953 | |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 954 | /* |
| 955 | * The mute button is broken and only sends press events, we |
| 956 | * deal with this in our raw_event handler, so do not map it. |
| 957 | */ |
| 958 | if ((drvdata->quirks & QUIRK_MEDION_E1239T) && |
| 959 | usage->hid == (HID_UP_CONSUMER | 0xe2)) { |
| 960 | input_set_capability(hi->input, EV_KEY, KEY_MUTE); |
| 961 | return -1; |
| 962 | } |
| 963 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | static int asus_start_multitouch(struct hid_device *hdev) |
| 968 | { |
| 969 | int ret; |
Colin Ian King | b9ec700 | 2018-01-06 15:50:27 +0000 | [diff] [blame] | 970 | static const unsigned char buf[] = { |
| 971 | FEATURE_REPORT_ID, 0x00, 0x03, 0x01, 0x00 |
| 972 | }; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 973 | unsigned char *dmabuf = kmemdup(buf, sizeof(buf), GFP_KERNEL); |
| 974 | |
| 975 | if (!dmabuf) { |
| 976 | ret = -ENOMEM; |
| 977 | hid_err(hdev, "Asus failed to alloc dma buf: %d\n", ret); |
| 978 | return ret; |
| 979 | } |
| 980 | |
| 981 | ret = hid_hw_raw_request(hdev, dmabuf[0], dmabuf, sizeof(buf), |
| 982 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 983 | |
| 984 | kfree(dmabuf); |
| 985 | |
| 986 | if (ret != sizeof(buf)) { |
| 987 | hid_err(hdev, "Asus failed to start multitouch: %d\n", ret); |
| 988 | return ret; |
| 989 | } |
| 990 | |
| 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | static int __maybe_unused asus_reset_resume(struct hid_device *hdev) |
| 995 | { |
| 996 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 997 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 998 | if (drvdata->tp) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 999 | return asus_start_multitouch(hdev); |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 1005 | { |
| 1006 | int ret; |
| 1007 | struct asus_drvdata *drvdata; |
| 1008 | |
| 1009 | drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); |
| 1010 | if (drvdata == NULL) { |
| 1011 | hid_err(hdev, "Can't alloc Asus descriptor\n"); |
| 1012 | return -ENOMEM; |
| 1013 | } |
| 1014 | |
| 1015 | hid_set_drvdata(hdev, drvdata); |
| 1016 | |
| 1017 | drvdata->quirks = id->driver_data; |
| 1018 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 1019 | /* |
| 1020 | * T90CHI's keyboard dock returns same ID values as T100CHI's dock. |
| 1021 | * Thus, identify T90CHI dock with product name string. |
| 1022 | */ |
NOGUCHI Hiroshi | 300c64d | 2019-01-29 13:23:20 +0900 | [diff] [blame] | 1023 | if (strstr(hdev->name, "T90CHI")) { |
| 1024 | drvdata->quirks &= ~QUIRK_T100CHI; |
| 1025 | drvdata->quirks |= QUIRK_T90CHI; |
| 1026 | } |
| 1027 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1028 | if (drvdata->quirks & QUIRK_IS_MULTITOUCH) |
| 1029 | drvdata->tp = &asus_i2c_tp; |
| 1030 | |
Greg Kroah-Hartman | f83baa0 | 2021-12-01 19:35:01 +0100 | [diff] [blame] | 1031 | if ((drvdata->quirks & QUIRK_T100_KEYBOARD) && hid_is_usb(hdev)) { |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 1032 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 1033 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1034 | if (intf->altsetting->desc.bInterfaceNumber == T100_TPAD_INTF) { |
| 1035 | drvdata->quirks = QUIRK_SKIP_INPUT_MAPPING; |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 1036 | /* |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 1037 | * The T100HA uses the same USB-ids as the T100TAF and |
| 1038 | * the T200TA uses the same USB-ids as the T100TA, while |
| 1039 | * both have different max x/y values as the T100TA[F]. |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 1040 | */ |
| 1041 | if (dmi_match(DMI_PRODUCT_NAME, "T100HAN")) |
| 1042 | drvdata->tp = &asus_t100ha_tp; |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 1043 | else if (dmi_match(DMI_PRODUCT_NAME, "T200TA")) |
| 1044 | drvdata->tp = &asus_t200ta_tp; |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 1045 | else |
| 1046 | drvdata->tp = &asus_t100ta_tp; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1047 | } |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 1050 | if (drvdata->quirks & QUIRK_T100CHI) { |
| 1051 | /* |
| 1052 | * All functionality is on a single HID interface and for |
| 1053 | * userspace the touchpad must be a separate input_dev. |
| 1054 | */ |
Benjamin Tissoires | 39335d1 | 2018-03-20 12:04:49 +0100 | [diff] [blame] | 1055 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 1056 | drvdata->tp = &asus_t100chi_tp; |
| 1057 | } |
| 1058 | |
Greg Kroah-Hartman | f83baa0 | 2021-12-01 19:35:01 +0100 | [diff] [blame] | 1059 | if ((drvdata->quirks & QUIRK_MEDION_E1239T) && hid_is_usb(hdev)) { |
Hans de Goede | e271f6c | 2020-04-28 16:22:53 +0200 | [diff] [blame] | 1060 | struct usb_host_interface *alt = |
| 1061 | to_usb_interface(hdev->dev.parent)->altsetting; |
| 1062 | |
| 1063 | if (alt->desc.bInterfaceNumber == MEDION_E1239T_TPAD_INTF) { |
Hans de Goede | 350bd24 | 2020-04-28 16:22:54 +0200 | [diff] [blame] | 1064 | /* For separate input-devs for tp and tp toggle key */ |
| 1065 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
Hans de Goede | e271f6c | 2020-04-28 16:22:53 +0200 | [diff] [blame] | 1066 | drvdata->quirks |= QUIRK_SKIP_INPUT_MAPPING; |
| 1067 | drvdata->tp = &medion_e1239t_tp; |
| 1068 | } |
| 1069 | } |
| 1070 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1071 | if (drvdata->quirks & QUIRK_NO_INIT_REPORTS) |
| 1072 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 1073 | |
NOGUCHI Hiroshi | 6311d32 | 2019-01-29 13:31:29 +0900 | [diff] [blame] | 1074 | drvdata->hdev = hdev; |
| 1075 | |
| 1076 | if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { |
| 1077 | ret = asus_battery_probe(hdev); |
| 1078 | if (ret) { |
| 1079 | hid_err(hdev, |
| 1080 | "Asus hid battery_probe failed: %d\n", ret); |
| 1081 | return ret; |
| 1082 | } |
| 1083 | } |
| 1084 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1085 | ret = hid_parse(hdev); |
| 1086 | if (ret) { |
| 1087 | hid_err(hdev, "Asus hid parse failed: %d\n", ret); |
| 1088 | return ret; |
| 1089 | } |
| 1090 | |
| 1091 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 1092 | if (ret) { |
| 1093 | hid_err(hdev, "Asus hw start failed: %d\n", ret); |
| 1094 | return ret; |
| 1095 | } |
| 1096 | |
| 1097 | if (!drvdata->input) { |
| 1098 | hid_err(hdev, "Asus input not registered\n"); |
| 1099 | ret = -ENOMEM; |
| 1100 | goto err_stop_hw; |
| 1101 | } |
| 1102 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1103 | if (drvdata->tp) { |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 1104 | drvdata->input->name = "Asus TouchPad"; |
| 1105 | } else { |
| 1106 | drvdata->input->name = "Asus Keyboard"; |
| 1107 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1108 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1109 | if (drvdata->tp) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1110 | ret = asus_start_multitouch(hdev); |
| 1111 | if (ret) |
| 1112 | goto err_stop_hw; |
| 1113 | } |
| 1114 | |
| 1115 | return 0; |
| 1116 | err_stop_hw: |
| 1117 | hid_hw_stop(hdev); |
| 1118 | return ret; |
| 1119 | } |
| 1120 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 1121 | static void asus_remove(struct hid_device *hdev) |
| 1122 | { |
| 1123 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 1124 | |
| 1125 | if (drvdata->kbd_backlight) { |
| 1126 | drvdata->kbd_backlight->removed = true; |
| 1127 | cancel_work_sync(&drvdata->kbd_backlight->work); |
| 1128 | } |
Carlo Caione | 715e944 | 2017-05-30 22:39:46 +0200 | [diff] [blame] | 1129 | |
| 1130 | hid_hw_stop(hdev); |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 1133 | static const __u8 asus_g752_fixed_rdesc[] = { |
| 1134 | 0x19, 0x00, /* Usage Minimum (0x00) */ |
| 1135 | 0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */ |
| 1136 | }; |
| 1137 | |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1138 | static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 1139 | unsigned int *rsize) |
| 1140 | { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1141 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 1142 | |
| 1143 | if (drvdata->quirks & QUIRK_FIX_NOTEBOOK_REPORT && |
| 1144 | *rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x65) { |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 1145 | hid_info(hdev, "Fixing up Asus notebook report descriptor\n"); |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1146 | rdesc[55] = 0xdd; |
| 1147 | } |
Hans de Goede | 33edee4 | 2018-01-05 12:09:19 +0100 | [diff] [blame] | 1148 | /* For the T100TA/T200TA keyboard dock */ |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 1149 | if (drvdata->quirks & QUIRK_T100_KEYBOARD && |
Hans de Goede | 33edee4 | 2018-01-05 12:09:19 +0100 | [diff] [blame] | 1150 | (*rsize == 76 || *rsize == 101) && |
| 1151 | rdesc[73] == 0x81 && rdesc[74] == 0x01) { |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 1152 | hid_info(hdev, "Fixing up Asus T100 keyb report descriptor\n"); |
| 1153 | rdesc[74] &= ~HID_MAIN_ITEM_CONSTANT; |
| 1154 | } |
NOGUCHI Hiroshi | 300c64d | 2019-01-29 13:23:20 +0900 | [diff] [blame] | 1155 | /* For the T100CHI/T90CHI keyboard dock */ |
| 1156 | if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { |
| 1157 | int rsize_orig; |
| 1158 | int offs; |
| 1159 | |
| 1160 | if (drvdata->quirks & QUIRK_T100CHI) { |
| 1161 | rsize_orig = 403; |
| 1162 | offs = 388; |
| 1163 | } else { |
| 1164 | rsize_orig = 306; |
| 1165 | offs = 291; |
| 1166 | } |
| 1167 | |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 1168 | /* |
| 1169 | * Change Usage (76h) to Usage Minimum (00h), Usage Maximum |
| 1170 | * (FFh) and clear the flags in the Input() byte. |
| 1171 | * Note the descriptor has a bogus 0 byte at the end so we |
| 1172 | * only need 1 extra byte. |
| 1173 | */ |
NOGUCHI Hiroshi | 300c64d | 2019-01-29 13:23:20 +0900 | [diff] [blame] | 1174 | if (*rsize == rsize_orig && |
| 1175 | rdesc[offs] == 0x09 && rdesc[offs + 1] == 0x76) { |
| 1176 | *rsize = rsize_orig + 1; |
| 1177 | rdesc = kmemdup(rdesc, *rsize, GFP_KERNEL); |
| 1178 | if (!rdesc) |
| 1179 | return NULL; |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 1180 | |
NOGUCHI Hiroshi | 300c64d | 2019-01-29 13:23:20 +0900 | [diff] [blame] | 1181 | hid_info(hdev, "Fixing up %s keyb report descriptor\n", |
| 1182 | drvdata->quirks & QUIRK_T100CHI ? |
| 1183 | "T100CHI" : "T90CHI"); |
| 1184 | memmove(rdesc + offs + 4, rdesc + offs + 2, 12); |
| 1185 | rdesc[offs] = 0x19; |
| 1186 | rdesc[offs + 1] = 0x00; |
| 1187 | rdesc[offs + 2] = 0x29; |
| 1188 | rdesc[offs + 3] = 0xff; |
| 1189 | rdesc[offs + 14] = 0x00; |
| 1190 | } |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 1191 | } |
NOGUCHI Hiroshi | 300c64d | 2019-01-29 13:23:20 +0900 | [diff] [blame] | 1192 | |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 1193 | if (drvdata->quirks & QUIRK_G752_KEYBOARD && |
| 1194 | *rsize == 75 && rdesc[61] == 0x15 && rdesc[62] == 0x00) { |
| 1195 | /* report is missing usage mninum and maximum */ |
| 1196 | __u8 *new_rdesc; |
| 1197 | size_t new_size = *rsize + sizeof(asus_g752_fixed_rdesc); |
| 1198 | |
| 1199 | new_rdesc = devm_kzalloc(&hdev->dev, new_size, GFP_KERNEL); |
| 1200 | if (new_rdesc == NULL) |
| 1201 | return rdesc; |
| 1202 | |
| 1203 | hid_info(hdev, "Fixing up Asus G752 keyb report descriptor\n"); |
| 1204 | /* copy the valid part */ |
| 1205 | memcpy(new_rdesc, rdesc, 61); |
| 1206 | /* insert missing part */ |
| 1207 | memcpy(new_rdesc + 61, asus_g752_fixed_rdesc, sizeof(asus_g752_fixed_rdesc)); |
| 1208 | /* copy remaining data */ |
| 1209 | memcpy(new_rdesc + 61 + sizeof(asus_g752_fixed_rdesc), rdesc + 61, *rsize - 61); |
| 1210 | |
| 1211 | *rsize = new_size; |
| 1212 | rdesc = new_rdesc; |
| 1213 | } |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 1214 | |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1215 | return rdesc; |
| 1216 | } |
| 1217 | |
| 1218 | static const struct hid_device_id asus_devices[] = { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1219 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 1220 | USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD), I2C_KEYBOARD_QUIRKS}, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1221 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 1222 | USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD), I2C_TOUCHPAD_QUIRKS }, |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 1223 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Mustafa Kuscu | 339ee3f | 2017-10-28 10:31:40 +0300 | [diff] [blame] | 1224 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1), QUIRK_USE_KBD_BACKLIGHT }, |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 1225 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 1226 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2), QUIRK_USE_KBD_BACKLIGHT }, |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 1227 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 1228 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD3), QUIRK_G752_KEYBOARD }, |
| 1229 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Hans de Goede | 2340bad | 2018-11-26 11:52:17 +0100 | [diff] [blame] | 1230 | USB_DEVICE_ID_ASUSTEK_FX503VD_KEYBOARD), |
| 1231 | QUIRK_USE_KBD_BACKLIGHT }, |
| 1232 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Luke D Jones | b92b802 | 2020-10-27 10:02:17 +1300 | [diff] [blame] | 1233 | USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD), |
| 1234 | QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, |
| 1235 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Luke D Jones | 9a0b44f | 2021-02-19 10:10:02 +1300 | [diff] [blame] | 1236 | USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2), |
| 1237 | QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, |
| 1238 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Luke D. Jones | 87c7ee7 | 2021-08-07 14:49:21 +1200 | [diff] [blame] | 1239 | USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD), |
| 1240 | QUIRK_ROG_CLAYMORE_II_KEYBOARD }, |
| 1241 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 1242 | USB_DEVICE_ID_ASUSTEK_T100TA_KEYBOARD), |
| 1243 | QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES }, |
| 1244 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
| 1245 | USB_DEVICE_ID_ASUSTEK_T100TAF_KEYBOARD), |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 1246 | QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES }, |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 1247 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_ASUS_AK1D) }, |
Daniel Drake | 38b2d78 | 2017-06-05 14:58:57 -0600 | [diff] [blame] | 1248 | { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_ASUS_MD_5110) }, |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 1249 | { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_ASUS_MD_5112) }, |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 1250 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK, |
| 1251 | USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD), QUIRK_T100CHI }, |
Hans de Goede | e271f6c | 2020-04-28 16:22:53 +0200 | [diff] [blame] | 1252 | { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE_MEDION_E1239T), |
| 1253 | QUIRK_MEDION_E1239T }, |
Hans de Goede | a94f66a | 2021-05-05 23:39:34 +0200 | [diff] [blame] | 1254 | /* |
| 1255 | * Note bind to the HID_GROUP_GENERIC group, so that we only bind to the keyboard |
| 1256 | * part, while letting hid-multitouch.c handle the touchpad. |
| 1257 | */ |
| 1258 | { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, |
| 1259 | USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) }, |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1260 | { } |
| 1261 | }; |
| 1262 | MODULE_DEVICE_TABLE(hid, asus_devices); |
| 1263 | |
| 1264 | static struct hid_driver asus_driver = { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1265 | .name = "asus", |
| 1266 | .id_table = asus_devices, |
| 1267 | .report_fixup = asus_report_fixup, |
| 1268 | .probe = asus_probe, |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 1269 | .remove = asus_remove, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1270 | .input_mapping = asus_input_mapping, |
| 1271 | .input_configured = asus_input_configured, |
| 1272 | #ifdef CONFIG_PM |
| 1273 | .reset_resume = asus_reset_resume, |
| 1274 | #endif |
Hans de Goede | e98e380 | 2018-11-26 11:52:16 +0100 | [diff] [blame] | 1275 | .event = asus_event, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 1276 | .raw_event = asus_raw_event |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1277 | }; |
| 1278 | module_hid_driver(asus_driver); |
| 1279 | |
| 1280 | MODULE_LICENSE("GPL"); |