diff options
Diffstat (limited to 'drivers/hid/hid-magicmouse.c')
| -rw-r--r-- | drivers/hid/hid-magicmouse.c | 325 |
1 files changed, 187 insertions, 138 deletions
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 319b0e57ee41..e6dc15171664 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * Apple "Magic" Wireless Mouse driver | 2 | * Apple "Magic" Wireless Mouse driver |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org> | 4 | * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org> |
| 5 | * Copyright (c) 2010 Chase Douglas <chase.douglas@canonical.com> | ||
| 5 | */ | 6 | */ |
| 6 | 7 | ||
| 7 | /* | 8 | /* |
| @@ -53,7 +54,9 @@ static bool report_undeciphered; | |||
| 53 | module_param(report_undeciphered, bool, 0644); | 54 | module_param(report_undeciphered, bool, 0644); |
| 54 | MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event"); | 55 | MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event"); |
| 55 | 56 | ||
| 56 | #define TOUCH_REPORT_ID 0x29 | 57 | #define TRACKPAD_REPORT_ID 0x28 |
| 58 | #define MOUSE_REPORT_ID 0x29 | ||
| 59 | #define DOUBLE_REPORT_ID 0xf7 | ||
| 57 | /* These definitions are not precise, but they're close enough. (Bits | 60 | /* These definitions are not precise, but they're close enough. (Bits |
| 58 | * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem | 61 | * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem |
| 59 | * to be some kind of bit mask -- 0x20 may be a near-field reading, | 62 | * to be some kind of bit mask -- 0x20 may be a near-field reading, |
| @@ -67,15 +70,19 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie | |||
| 67 | 70 | ||
| 68 | #define SCROLL_ACCEL_DEFAULT 7 | 71 | #define SCROLL_ACCEL_DEFAULT 7 |
| 69 | 72 | ||
| 73 | /* Single touch emulation should only begin when no touches are currently down. | ||
| 74 | * This is true when single_touch_id is equal to NO_TOUCHES. If multiple touches | ||
| 75 | * are down and the touch providing for single touch emulation is lifted, | ||
| 76 | * single_touch_id is equal to SINGLE_TOUCH_UP. While single touch emulation is | ||
| 77 | * occuring, single_touch_id corresponds with the tracking id of the touch used. | ||
| 78 | */ | ||
| 79 | #define NO_TOUCHES -1 | ||
| 80 | #define SINGLE_TOUCH_UP -2 | ||
| 81 | |||
| 70 | /** | 82 | /** |
| 71 | * struct magicmouse_sc - Tracks Magic Mouse-specific data. | 83 | * struct magicmouse_sc - Tracks Magic Mouse-specific data. |
| 72 | * @input: Input device through which we report events. | 84 | * @input: Input device through which we report events. |
| 73 | * @quirks: Currently unused. | 85 | * @quirks: Currently unused. |
| 74 | * @last_timestamp: Timestamp from most recent (18-bit) touch report | ||
| 75 | * (units of milliseconds over short windows, but seems to | ||
| 76 | * increase faster when there are no touches). | ||
| 77 | * @delta_time: 18-bit difference between the two most recent touch | ||
| 78 | * reports from the mouse. | ||
| 79 | * @ntouches: Number of touches in most recent touch report. | 86 | * @ntouches: Number of touches in most recent touch report. |
| 80 | * @scroll_accel: Number of consecutive scroll motions. | 87 | * @scroll_accel: Number of consecutive scroll motions. |
| 81 | * @scroll_jiffies: Time of last scroll motion. | 88 | * @scroll_jiffies: Time of last scroll motion. |
| @@ -86,8 +93,6 @@ struct magicmouse_sc { | |||
| 86 | struct input_dev *input; | 93 | struct input_dev *input; |
| 87 | unsigned long quirks; | 94 | unsigned long quirks; |
| 88 | 95 | ||
| 89 | int last_timestamp; | ||
| 90 | int delta_time; | ||
| 91 | int ntouches; | 96 | int ntouches; |
| 92 | int scroll_accel; | 97 | int scroll_accel; |
| 93 | unsigned long scroll_jiffies; | 98 | unsigned long scroll_jiffies; |
| @@ -98,9 +103,9 @@ struct magicmouse_sc { | |||
| 98 | short scroll_x; | 103 | short scroll_x; |
| 99 | short scroll_y; | 104 | short scroll_y; |
| 100 | u8 size; | 105 | u8 size; |
| 101 | u8 down; | ||
| 102 | } touches[16]; | 106 | } touches[16]; |
| 103 | int tracking_ids[16]; | 107 | int tracking_ids[16]; |
| 108 | int single_touch_id; | ||
| 104 | }; | 109 | }; |
| 105 | 110 | ||
| 106 | static int magicmouse_firm_touch(struct magicmouse_sc *msc) | 111 | static int magicmouse_firm_touch(struct magicmouse_sc *msc) |
| @@ -166,18 +171,35 @@ static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state) | |||
| 166 | static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata) | 171 | static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata) |
| 167 | { | 172 | { |
| 168 | struct input_dev *input = msc->input; | 173 | struct input_dev *input = msc->input; |
| 169 | __s32 x_y = tdata[0] << 8 | tdata[1] << 16 | tdata[2] << 24; | 174 | int id, x, y, size, orientation, touch_major, touch_minor, state, down; |
| 170 | int misc = tdata[5] | tdata[6] << 8; | 175 | |
| 171 | int id = (misc >> 6) & 15; | 176 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { |
| 172 | int x = x_y << 12 >> 20; | 177 | id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf; |
| 173 | int y = -(x_y >> 20); | 178 | x = (tdata[1] << 28 | tdata[0] << 20) >> 20; |
| 174 | int down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE; | 179 | y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); |
| 180 | size = tdata[5] & 0x3f; | ||
| 181 | orientation = (tdata[6] >> 2) - 32; | ||
| 182 | touch_major = tdata[3]; | ||
| 183 | touch_minor = tdata[4]; | ||
| 184 | state = tdata[7] & TOUCH_STATE_MASK; | ||
| 185 | down = state != TOUCH_STATE_NONE; | ||
| 186 | } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 187 | id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf; | ||
| 188 | x = (tdata[1] << 27 | tdata[0] << 19) >> 19; | ||
| 189 | y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19); | ||
| 190 | size = tdata[6] & 0x3f; | ||
| 191 | orientation = (tdata[7] >> 2) - 32; | ||
| 192 | touch_major = tdata[4]; | ||
| 193 | touch_minor = tdata[5]; | ||
| 194 | state = tdata[8] & TOUCH_STATE_MASK; | ||
| 195 | down = state != TOUCH_STATE_NONE; | ||
| 196 | } | ||
| 175 | 197 | ||
| 176 | /* Store tracking ID and other fields. */ | 198 | /* Store tracking ID and other fields. */ |
| 177 | msc->tracking_ids[raw_id] = id; | 199 | msc->tracking_ids[raw_id] = id; |
| 178 | msc->touches[id].x = x; | 200 | msc->touches[id].x = x; |
| 179 | msc->touches[id].y = y; | 201 | msc->touches[id].y = y; |
| 180 | msc->touches[id].size = misc & 63; | 202 | msc->touches[id].size = size; |
| 181 | 203 | ||
| 182 | /* If requested, emulate a scroll wheel by detecting small | 204 | /* If requested, emulate a scroll wheel by detecting small |
| 183 | * vertical touch motions. | 205 | * vertical touch motions. |
| @@ -188,7 +210,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda | |||
| 188 | int step_y = msc->touches[id].scroll_y - y; | 210 | int step_y = msc->touches[id].scroll_y - y; |
| 189 | 211 | ||
| 190 | /* Calculate and apply the scroll motion. */ | 212 | /* Calculate and apply the scroll motion. */ |
| 191 | switch (tdata[7] & TOUCH_STATE_MASK) { | 213 | switch (state) { |
| 192 | case TOUCH_STATE_START: | 214 | case TOUCH_STATE_START: |
| 193 | msc->touches[id].scroll_x = x; | 215 | msc->touches[id].scroll_x = x; |
| 194 | msc->touches[id].scroll_y = y; | 216 | msc->touches[id].scroll_y = y; |
| @@ -222,21 +244,28 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda | |||
| 222 | } | 244 | } |
| 223 | } | 245 | } |
| 224 | 246 | ||
| 247 | if (down) { | ||
| 248 | msc->ntouches++; | ||
| 249 | if (msc->single_touch_id == NO_TOUCHES) | ||
| 250 | msc->single_touch_id = id; | ||
| 251 | } else if (msc->single_touch_id == id) | ||
| 252 | msc->single_touch_id = SINGLE_TOUCH_UP; | ||
| 253 | |||
| 225 | /* Generate the input events for this touch. */ | 254 | /* Generate the input events for this touch. */ |
| 226 | if (report_touches && down) { | 255 | if (report_touches && down) { |
| 227 | int orientation = (misc >> 10) - 32; | ||
| 228 | |||
| 229 | msc->touches[id].down = 1; | ||
| 230 | |||
| 231 | input_report_abs(input, ABS_MT_TRACKING_ID, id); | 256 | input_report_abs(input, ABS_MT_TRACKING_ID, id); |
| 232 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]); | 257 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2); |
| 233 | input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]); | 258 | input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2); |
| 234 | input_report_abs(input, ABS_MT_ORIENTATION, orientation); | 259 | input_report_abs(input, ABS_MT_ORIENTATION, orientation); |
| 235 | input_report_abs(input, ABS_MT_POSITION_X, x); | 260 | input_report_abs(input, ABS_MT_POSITION_X, x); |
| 236 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 261 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
| 237 | 262 | ||
| 238 | if (report_undeciphered) | 263 | if (report_undeciphered) { |
| 239 | input_event(input, EV_MSC, MSC_RAW, tdata[7]); | 264 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) |
| 265 | input_event(input, EV_MSC, MSC_RAW, tdata[7]); | ||
| 266 | else /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 267 | input_event(input, EV_MSC, MSC_RAW, tdata[8]); | ||
| 268 | } | ||
| 240 | 269 | ||
| 241 | input_mt_sync(input); | 270 | input_mt_sync(input); |
| 242 | } | 271 | } |
| @@ -247,39 +276,43 @@ static int magicmouse_raw_event(struct hid_device *hdev, | |||
| 247 | { | 276 | { |
| 248 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); | 277 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); |
| 249 | struct input_dev *input = msc->input; | 278 | struct input_dev *input = msc->input; |
| 250 | int x, y, ts, ii, clicks, last_up; | 279 | int x = 0, y = 0, ii, clicks = 0, npoints; |
| 251 | 280 | ||
| 252 | switch (data[0]) { | 281 | switch (data[0]) { |
| 253 | case 0x10: | 282 | case TRACKPAD_REPORT_ID: |
| 254 | if (size != 6) | 283 | /* Expect four bytes of prefix, and N*9 bytes of touch data. */ |
| 284 | if (size < 4 || ((size - 4) % 9) != 0) | ||
| 255 | return 0; | 285 | return 0; |
| 256 | x = (__s16)(data[2] | data[3] << 8); | 286 | npoints = (size - 4) / 9; |
| 257 | y = (__s16)(data[4] | data[5] << 8); | 287 | msc->ntouches = 0; |
| 288 | for (ii = 0; ii < npoints; ii++) | ||
| 289 | magicmouse_emit_touch(msc, ii, data + ii * 9 + 4); | ||
| 290 | |||
| 291 | /* We don't need an MT sync here because trackpad emits a | ||
| 292 | * BTN_TOUCH event in a new frame when all touches are released. | ||
| 293 | */ | ||
| 294 | if (msc->ntouches == 0) | ||
| 295 | msc->single_touch_id = NO_TOUCHES; | ||
| 296 | |||
| 258 | clicks = data[1]; | 297 | clicks = data[1]; |
| 298 | |||
| 299 | /* The following bits provide a device specific timestamp. They | ||
| 300 | * are unused here. | ||
| 301 | * | ||
| 302 | * ts = data[1] >> 6 | data[2] << 2 | data[3] << 10; | ||
| 303 | */ | ||
| 259 | break; | 304 | break; |
| 260 | case TOUCH_REPORT_ID: | 305 | case MOUSE_REPORT_ID: |
| 261 | /* Expect six bytes of prefix, and N*8 bytes of touch data. */ | 306 | /* Expect six bytes of prefix, and N*8 bytes of touch data. */ |
| 262 | if (size < 6 || ((size - 6) % 8) != 0) | 307 | if (size < 6 || ((size - 6) % 8) != 0) |
| 263 | return 0; | 308 | return 0; |
| 264 | ts = data[3] >> 6 | data[4] << 2 | data[5] << 10; | 309 | npoints = (size - 6) / 8; |
| 265 | msc->delta_time = (ts - msc->last_timestamp) & 0x3ffff; | 310 | msc->ntouches = 0; |
| 266 | msc->last_timestamp = ts; | 311 | for (ii = 0; ii < npoints; ii++) |
| 267 | msc->ntouches = (size - 6) / 8; | ||
| 268 | for (ii = 0; ii < msc->ntouches; ii++) | ||
| 269 | magicmouse_emit_touch(msc, ii, data + ii * 8 + 6); | 312 | magicmouse_emit_touch(msc, ii, data + ii * 8 + 6); |
| 270 | 313 | ||
| 271 | if (report_touches) { | 314 | if (report_touches && msc->ntouches == 0) |
| 272 | last_up = 1; | 315 | input_mt_sync(input); |
| 273 | for (ii = 0; ii < ARRAY_SIZE(msc->touches); ii++) { | ||
| 274 | if (msc->touches[ii].down) { | ||
| 275 | last_up = 0; | ||
| 276 | msc->touches[ii].down = 0; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | if (last_up) { | ||
| 280 | input_mt_sync(input); | ||
| 281 | } | ||
| 282 | } | ||
| 283 | 316 | ||
| 284 | /* When emulating three-button mode, it is important | 317 | /* When emulating three-button mode, it is important |
| 285 | * to have the current touch information before | 318 | * to have the current touch information before |
| @@ -288,68 +321,72 @@ static int magicmouse_raw_event(struct hid_device *hdev, | |||
| 288 | x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22; | 321 | x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22; |
| 289 | y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22; | 322 | y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22; |
| 290 | clicks = data[3]; | 323 | clicks = data[3]; |
| 324 | |||
| 325 | /* The following bits provide a device specific timestamp. They | ||
| 326 | * are unused here. | ||
| 327 | * | ||
| 328 | * ts = data[3] >> 6 | data[4] << 2 | data[5] << 10; | ||
| 329 | */ | ||
| 330 | break; | ||
| 331 | case DOUBLE_REPORT_ID: | ||
| 332 | /* Sometimes the trackpad sends two touch reports in one | ||
| 333 | * packet. | ||
| 334 | */ | ||
| 335 | magicmouse_raw_event(hdev, report, data + 2, data[1]); | ||
| 336 | magicmouse_raw_event(hdev, report, data + 2 + data[1], | ||
| 337 | size - 2 - data[1]); | ||
| 291 | break; | 338 | break; |
| 292 | case 0x20: /* Theoretically battery status (0-100), but I have | ||
| 293 | * never seen it -- maybe it is only upon request. | ||
| 294 | */ | ||
| 295 | case 0x60: /* Unknown, maybe laser on/off. */ | ||
| 296 | case 0x61: /* Laser reflection status change. | ||
| 297 | * data[1]: 0 = spotted, 1 = lost | ||
| 298 | */ | ||
| 299 | default: | 339 | default: |
| 300 | return 0; | 340 | return 0; |
| 301 | } | 341 | } |
| 302 | 342 | ||
| 303 | magicmouse_emit_buttons(msc, clicks & 3); | 343 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { |
| 304 | input_report_rel(input, REL_X, x); | 344 | magicmouse_emit_buttons(msc, clicks & 3); |
| 305 | input_report_rel(input, REL_Y, y); | 345 | input_report_rel(input, REL_X, x); |
| 346 | input_report_rel(input, REL_Y, y); | ||
| 347 | } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 348 | input_report_key(input, BTN_MOUSE, clicks & 1); | ||
| 349 | input_report_key(input, BTN_TOUCH, msc->ntouches > 0); | ||
| 350 | input_report_key(input, BTN_TOOL_FINGER, msc->ntouches == 1); | ||
| 351 | input_report_key(input, BTN_TOOL_DOUBLETAP, msc->ntouches == 2); | ||
| 352 | input_report_key(input, BTN_TOOL_TRIPLETAP, msc->ntouches == 3); | ||
| 353 | input_report_key(input, BTN_TOOL_QUADTAP, msc->ntouches == 4); | ||
| 354 | if (msc->single_touch_id >= 0) { | ||
| 355 | input_report_abs(input, ABS_X, | ||
| 356 | msc->touches[msc->single_touch_id].x); | ||
| 357 | input_report_abs(input, ABS_Y, | ||
| 358 | msc->touches[msc->single_touch_id].y); | ||
| 359 | } | ||
| 360 | } | ||
| 361 | |||
| 306 | input_sync(input); | 362 | input_sync(input); |
| 307 | return 1; | 363 | return 1; |
| 308 | } | 364 | } |
| 309 | 365 | ||
| 310 | static int magicmouse_input_open(struct input_dev *dev) | ||
| 311 | { | ||
| 312 | struct hid_device *hid = input_get_drvdata(dev); | ||
| 313 | |||
| 314 | return hid->ll_driver->open(hid); | ||
| 315 | } | ||
| 316 | |||
| 317 | static void magicmouse_input_close(struct input_dev *dev) | ||
| 318 | { | ||
| 319 | struct hid_device *hid = input_get_drvdata(dev); | ||
| 320 | |||
| 321 | hid->ll_driver->close(hid); | ||
| 322 | } | ||
| 323 | |||
| 324 | static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev) | 366 | static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev) |
| 325 | { | 367 | { |
| 326 | input_set_drvdata(input, hdev); | ||
| 327 | input->event = hdev->ll_driver->hidinput_input_event; | ||
| 328 | input->open = magicmouse_input_open; | ||
| 329 | input->close = magicmouse_input_close; | ||
| 330 | |||
| 331 | input->name = hdev->name; | ||
| 332 | input->phys = hdev->phys; | ||
| 333 | input->uniq = hdev->uniq; | ||
| 334 | input->id.bustype = hdev->bus; | ||
| 335 | input->id.vendor = hdev->vendor; | ||
| 336 | input->id.product = hdev->product; | ||
| 337 | input->id.version = hdev->version; | ||
| 338 | input->dev.parent = hdev->dev.parent; | ||
| 339 | |||
| 340 | __set_bit(EV_KEY, input->evbit); | 368 | __set_bit(EV_KEY, input->evbit); |
| 341 | __set_bit(BTN_LEFT, input->keybit); | 369 | |
| 342 | __set_bit(BTN_RIGHT, input->keybit); | 370 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { |
| 343 | if (emulate_3button) | 371 | __set_bit(BTN_LEFT, input->keybit); |
| 344 | __set_bit(BTN_MIDDLE, input->keybit); | 372 | __set_bit(BTN_RIGHT, input->keybit); |
| 345 | __set_bit(BTN_TOOL_FINGER, input->keybit); | 373 | if (emulate_3button) |
| 346 | 374 | __set_bit(BTN_MIDDLE, input->keybit); | |
| 347 | __set_bit(EV_REL, input->evbit); | 375 | |
| 348 | __set_bit(REL_X, input->relbit); | 376 | __set_bit(EV_REL, input->evbit); |
| 349 | __set_bit(REL_Y, input->relbit); | 377 | __set_bit(REL_X, input->relbit); |
| 350 | if (emulate_scroll_wheel) { | 378 | __set_bit(REL_Y, input->relbit); |
| 351 | __set_bit(REL_WHEEL, input->relbit); | 379 | if (emulate_scroll_wheel) { |
| 352 | __set_bit(REL_HWHEEL, input->relbit); | 380 | __set_bit(REL_WHEEL, input->relbit); |
| 381 | __set_bit(REL_HWHEEL, input->relbit); | ||
| 382 | } | ||
| 383 | } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 384 | __set_bit(BTN_MOUSE, input->keybit); | ||
| 385 | __set_bit(BTN_TOOL_FINGER, input->keybit); | ||
| 386 | __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); | ||
| 387 | __set_bit(BTN_TOOL_TRIPLETAP, input->keybit); | ||
| 388 | __set_bit(BTN_TOOL_QUADTAP, input->keybit); | ||
| 389 | __set_bit(BTN_TOUCH, input->keybit); | ||
| 353 | } | 390 | } |
| 354 | 391 | ||
| 355 | if (report_touches) { | 392 | if (report_touches) { |
| @@ -359,16 +396,26 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h | |||
| 359 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0); | 396 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0); |
| 360 | input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0); | 397 | input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0); |
| 361 | input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0); | 398 | input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0); |
| 362 | input_set_abs_params(input, ABS_MT_POSITION_X, -1100, 1358, | 399 | |
| 363 | 4, 0); | ||
| 364 | /* Note: Touch Y position from the device is inverted relative | 400 | /* Note: Touch Y position from the device is inverted relative |
| 365 | * to how pointer motion is reported (and relative to how USB | 401 | * to how pointer motion is reported (and relative to how USB |
| 366 | * HID recommends the coordinates work). This driver keeps | 402 | * HID recommends the coordinates work). This driver keeps |
| 367 | * the origin at the same position, and just uses the additive | 403 | * the origin at the same position, and just uses the additive |
| 368 | * inverse of the reported Y. | 404 | * inverse of the reported Y. |
| 369 | */ | 405 | */ |
| 370 | input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, 2047, | 406 | if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) { |
| 371 | 4, 0); | 407 | input_set_abs_params(input, ABS_MT_POSITION_X, -1100, |
| 408 | 1358, 4, 0); | ||
| 409 | input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, | ||
| 410 | 2047, 4, 0); | ||
| 411 | } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 412 | input_set_abs_params(input, ABS_X, -2909, 3167, 4, 0); | ||
| 413 | input_set_abs_params(input, ABS_Y, -2456, 2565, 4, 0); | ||
| 414 | input_set_abs_params(input, ABS_MT_POSITION_X, -2909, | ||
| 415 | 3167, 4, 0); | ||
| 416 | input_set_abs_params(input, ABS_MT_POSITION_Y, -2456, | ||
| 417 | 2565, 4, 0); | ||
| 418 | } | ||
| 372 | } | 419 | } |
| 373 | 420 | ||
| 374 | if (report_undeciphered) { | 421 | if (report_undeciphered) { |
| @@ -377,12 +424,22 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h | |||
| 377 | } | 424 | } |
| 378 | } | 425 | } |
| 379 | 426 | ||
| 427 | static int magicmouse_input_mapping(struct hid_device *hdev, | ||
| 428 | struct hid_input *hi, struct hid_field *field, | ||
| 429 | struct hid_usage *usage, unsigned long **bit, int *max) | ||
| 430 | { | ||
| 431 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); | ||
| 432 | |||
| 433 | if (!msc->input) | ||
| 434 | msc->input = hi->input; | ||
| 435 | |||
| 436 | return 0; | ||
| 437 | } | ||
| 438 | |||
| 380 | static int magicmouse_probe(struct hid_device *hdev, | 439 | static int magicmouse_probe(struct hid_device *hdev, |
| 381 | const struct hid_device_id *id) | 440 | const struct hid_device_id *id) |
| 382 | { | 441 | { |
| 383 | __u8 feature_1[] = { 0xd7, 0x01 }; | 442 | __u8 feature[] = { 0xd7, 0x01 }; |
| 384 | __u8 feature_2[] = { 0xf8, 0x01, 0x32 }; | ||
| 385 | struct input_dev *input; | ||
| 386 | struct magicmouse_sc *msc; | 443 | struct magicmouse_sc *msc; |
| 387 | struct hid_report *report; | 444 | struct hid_report *report; |
| 388 | int ret; | 445 | int ret; |
| @@ -398,6 +455,8 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
| 398 | msc->quirks = id->driver_data; | 455 | msc->quirks = id->driver_data; |
| 399 | hid_set_drvdata(hdev, msc); | 456 | hid_set_drvdata(hdev, msc); |
| 400 | 457 | ||
| 458 | msc->single_touch_id = NO_TOUCHES; | ||
| 459 | |||
| 401 | ret = hid_parse(hdev); | 460 | ret = hid_parse(hdev); |
| 402 | if (ret) { | 461 | if (ret) { |
| 403 | dev_err(&hdev->dev, "magicmouse hid parse failed\n"); | 462 | dev_err(&hdev->dev, "magicmouse hid parse failed\n"); |
| @@ -410,10 +469,22 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
| 410 | goto err_free; | 469 | goto err_free; |
| 411 | } | 470 | } |
| 412 | 471 | ||
| 413 | /* we are handling the input ourselves */ | 472 | /* We do this after hid-input is done parsing reports so that |
| 414 | hidinput_disconnect(hdev); | 473 | * hid-input uses the most natural button and axis IDs. |
| 474 | */ | ||
| 475 | if (msc->input) | ||
| 476 | magicmouse_setup_input(msc->input, hdev); | ||
| 477 | |||
| 478 | if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) | ||
| 479 | report = hid_register_report(hdev, HID_INPUT_REPORT, | ||
| 480 | MOUSE_REPORT_ID); | ||
| 481 | else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ | ||
| 482 | report = hid_register_report(hdev, HID_INPUT_REPORT, | ||
| 483 | TRACKPAD_REPORT_ID); | ||
| 484 | report = hid_register_report(hdev, HID_INPUT_REPORT, | ||
| 485 | DOUBLE_REPORT_ID); | ||
| 486 | } | ||
| 415 | 487 | ||
| 416 | report = hid_register_report(hdev, HID_INPUT_REPORT, TOUCH_REPORT_ID); | ||
| 417 | if (!report) { | 488 | if (!report) { |
| 418 | dev_err(&hdev->dev, "unable to register touch report\n"); | 489 | dev_err(&hdev->dev, "unable to register touch report\n"); |
| 419 | ret = -ENOMEM; | 490 | ret = -ENOMEM; |
| @@ -421,39 +492,15 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
| 421 | } | 492 | } |
| 422 | report->size = 6; | 493 | report->size = 6; |
| 423 | 494 | ||
| 424 | ret = hdev->hid_output_raw_report(hdev, feature_1, sizeof(feature_1), | 495 | ret = hdev->hid_output_raw_report(hdev, feature, sizeof(feature), |
| 425 | HID_FEATURE_REPORT); | 496 | HID_FEATURE_REPORT); |
| 426 | if (ret != sizeof(feature_1)) { | 497 | if (ret != sizeof(feature)) { |
| 427 | dev_err(&hdev->dev, "unable to request touch data (1:%d)\n", | 498 | dev_err(&hdev->dev, "unable to request touch data (%d)\n", |
| 428 | ret); | ||
| 429 | goto err_stop_hw; | ||
| 430 | } | ||
| 431 | ret = hdev->hid_output_raw_report(hdev, feature_2, | ||
| 432 | sizeof(feature_2), HID_FEATURE_REPORT); | ||
| 433 | if (ret != sizeof(feature_2)) { | ||
| 434 | dev_err(&hdev->dev, "unable to request touch data (2:%d)\n", | ||
| 435 | ret); | 499 | ret); |
| 436 | goto err_stop_hw; | 500 | goto err_stop_hw; |
| 437 | } | 501 | } |
| 438 | 502 | ||
| 439 | input = input_allocate_device(); | ||
| 440 | if (!input) { | ||
| 441 | dev_err(&hdev->dev, "can't alloc input device\n"); | ||
| 442 | ret = -ENOMEM; | ||
| 443 | goto err_stop_hw; | ||
| 444 | } | ||
| 445 | magicmouse_setup_input(input, hdev); | ||
| 446 | |||
| 447 | ret = input_register_device(input); | ||
| 448 | if (ret) { | ||
| 449 | dev_err(&hdev->dev, "input device registration failed\n"); | ||
| 450 | goto err_input; | ||
| 451 | } | ||
| 452 | msc->input = input; | ||
| 453 | |||
| 454 | return 0; | 503 | return 0; |
| 455 | err_input: | ||
| 456 | input_free_device(input); | ||
| 457 | err_stop_hw: | 504 | err_stop_hw: |
| 458 | hid_hw_stop(hdev); | 505 | hid_hw_stop(hdev); |
| 459 | err_free: | 506 | err_free: |
| @@ -466,13 +513,14 @@ static void magicmouse_remove(struct hid_device *hdev) | |||
| 466 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); | 513 | struct magicmouse_sc *msc = hid_get_drvdata(hdev); |
| 467 | 514 | ||
| 468 | hid_hw_stop(hdev); | 515 | hid_hw_stop(hdev); |
| 469 | input_unregister_device(msc->input); | ||
| 470 | kfree(msc); | 516 | kfree(msc); |
| 471 | } | 517 | } |
| 472 | 518 | ||
| 473 | static const struct hid_device_id magic_mice[] = { | 519 | static const struct hid_device_id magic_mice[] = { |
| 474 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE), | 520 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, |
| 475 | .driver_data = 0 }, | 521 | USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 }, |
| 522 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, | ||
| 523 | USB_DEVICE_ID_APPLE_MAGICTRACKPAD), .driver_data = 0 }, | ||
| 476 | { } | 524 | { } |
| 477 | }; | 525 | }; |
| 478 | MODULE_DEVICE_TABLE(hid, magic_mice); | 526 | MODULE_DEVICE_TABLE(hid, magic_mice); |
| @@ -483,6 +531,7 @@ static struct hid_driver magicmouse_driver = { | |||
| 483 | .probe = magicmouse_probe, | 531 | .probe = magicmouse_probe, |
| 484 | .remove = magicmouse_remove, | 532 | .remove = magicmouse_remove, |
| 485 | .raw_event = magicmouse_raw_event, | 533 | .raw_event = magicmouse_raw_event, |
| 534 | .input_mapping = magicmouse_input_mapping, | ||
| 486 | }; | 535 | }; |
| 487 | 536 | ||
| 488 | static int __init magicmouse_init(void) | 537 | static int __init magicmouse_init(void) |
