Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Pull input changes from Henrik Rydberg, including large update to atmel_mxt_ts driver by Daniel and MT protocol addition for win8 devices.

Conflicts:
drivers/input/touchscreen/atmel_mxt_ts.c

+339 -252
+92 -26
Documentation/input/multi-touch-protocol.txt
··· 162 162 minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which 163 163 allows for multiple contacts to be tracked. If the device supports it, the 164 164 ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size 165 - of the contact area and approaching contact, respectively. 165 + of the contact area and approaching tool, respectively. 166 166 167 167 The TOUCH and WIDTH parameters have a geometrical interpretation; imagine 168 168 looking through a window at someone gently holding a finger against the 169 169 glass. You will see two regions, one inner region consisting of the part 170 170 of the finger actually touching the glass, and one outer region formed by 171 - the perimeter of the finger. The diameter of the inner region is the 172 - ABS_MT_TOUCH_MAJOR, the diameter of the outer region is 173 - ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger harder 174 - against the glass. The inner region will increase, and in general, the 175 - ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller than 176 - unity, is related to the contact pressure. For pressure-based devices, 171 + the perimeter of the finger. The center of the touching region (a) is 172 + ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is 173 + ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger 174 + diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger 175 + harder against the glass. The touch region will increase, and in general, 176 + the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller 177 + than unity, is related to the contact pressure. For pressure-based devices, 177 178 ABS_MT_PRESSURE may be used to provide the pressure on the contact area 178 179 instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to 179 180 indicate the distance between the contact and the surface. 180 181 181 - In addition to the MAJOR parameters, the oval shape of the contact can be 182 - described by adding the MINOR parameters, such that MAJOR and MINOR are the 183 - major and minor axis of an ellipse. Finally, the orientation of the oval 184 - shape can be describe with the ORIENTATION parameter. 182 + 183 + Linux MT Win8 184 + __________ _______________________ 185 + / \ | | 186 + / \ | | 187 + / ____ \ | | 188 + / / \ \ | | 189 + \ \ a \ \ | a | 190 + \ \____/ \ | | 191 + \ \ | | 192 + \ b \ | b | 193 + \ \ | | 194 + \ \ | | 195 + \ \ | | 196 + \ / | | 197 + \ / | | 198 + \ / | | 199 + \__________/ |_______________________| 200 + 201 + 202 + In addition to the MAJOR parameters, the oval shape of the touch and finger 203 + regions can be described by adding the MINOR parameters, such that MAJOR 204 + and MINOR are the major and minor axis of an ellipse. The orientation of 205 + the touch ellipse can be described with the ORIENTATION parameter, and the 206 + direction of the finger ellipse is given by the vector (a - b). 185 207 186 208 For type A devices, further specification of the touch shape is possible 187 209 via ABS_MT_BLOB_ID. ··· 246 224 The above four values can be used to derive additional information about 247 225 the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates 248 226 the notion of pressure. The fingers of the hand and the palm all have 249 - different characteristic widths [1]. 227 + different characteristic widths. 250 228 251 229 ABS_MT_PRESSURE 252 230 ··· 262 240 263 241 ABS_MT_ORIENTATION 264 242 265 - The orientation of the ellipse. The value should describe a signed quarter 266 - of a revolution clockwise around the touch center. The signed value range 267 - is arbitrary, but zero should be returned for a finger aligned along the Y 268 - axis of the surface, a negative value when finger is turned to the left, and 269 - a positive value when finger turned to the right. When completely aligned with 270 - the X axis, the range max should be returned. Orientation can be omitted 271 - if the touching object is circular, or if the information is not available 272 - in the kernel driver. Partial orientation support is possible if the device 273 - can distinguish between the two axis, but not (uniquely) any values in 274 - between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1] 275 - [4]. 243 + The orientation of the touching ellipse. The value should describe a signed 244 + quarter of a revolution clockwise around the touch center. The signed value 245 + range is arbitrary, but zero should be returned for an ellipse aligned with 246 + the Y axis of the surface, a negative value when the ellipse is turned to 247 + the left, and a positive value when the ellipse is turned to the 248 + right. When completely aligned with the X axis, the range max should be 249 + returned. 250 + 251 + Touch ellipsis are symmetrical by default. For devices capable of true 360 252 + degree orientation, the reported orientation must exceed the range max to 253 + indicate more than a quarter of a revolution. For an upside-down finger, 254 + range max * 2 should be returned. 255 + 256 + Orientation can be omitted if the touch area is circular, or if the 257 + information is not available in the kernel driver. Partial orientation 258 + support is possible if the device can distinguish between the two axis, but 259 + not (uniquely) any values in between. In such cases, the range of 260 + ABS_MT_ORIENTATION should be [0, 1] [4]. 276 261 277 262 ABS_MT_POSITION_X 278 263 ··· 288 259 ABS_MT_POSITION_Y 289 260 290 261 The surface Y coordinate of the center of the touching ellipse. 262 + 263 + ABS_MT_TOOL_X 264 + 265 + The surface X coordinate of the center of the approaching tool. Omit if 266 + the device cannot distinguish between the intended touch point and the 267 + tool itself. 268 + 269 + ABS_MT_TOOL_Y 270 + 271 + The surface Y coordinate of the center of the approaching tool. Omit if the 272 + device cannot distinguish between the intended touch point and the tool 273 + itself. 274 + 275 + The four position values can be used to separate the position of the touch 276 + from the position of the tool. If both positions are present, the major 277 + tool axis points towards the touch point [1]. Otherwise, the tool axes are 278 + aligned with the touch axes. 291 279 292 280 ABS_MT_TOOL_TYPE 293 281 ··· 351 305 the device can distinguish between a finger along the Y axis (0) and a 352 306 finger along the X axis (1). 353 307 308 + For win8 devices with both T and C coordinates, the position mapping is 309 + 310 + ABS_MT_POSITION_X := T_X 311 + ABS_MT_POSITION_Y := T_Y 312 + ABS_MT_TOOL_X := C_X 313 + ABS_MT_TOOL_X := C_Y 314 + 315 + Unfortunately, there is not enough information to specify both the touching 316 + ellipse and the tool ellipse, so one has to resort to approximations. One 317 + simple scheme, which is compatible with earlier usage, is: 318 + 319 + ABS_MT_TOUCH_MAJOR := min(X, Y) 320 + ABS_MT_TOUCH_MINOR := <not used> 321 + ABS_MT_ORIENTATION := <not used> 322 + ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C) 323 + ABS_MT_WIDTH_MINOR := min(X, Y) 324 + 325 + Rationale: We have no information about the orientation of the touching 326 + ellipse, so approximate it with an inscribed circle instead. The tool 327 + ellipse should align with the the vector (T - C), so the diameter must 328 + increase with distance(T, C). Finally, assume that the touch diameter is 329 + equal to the tool thickness, and we arrive at the formulas above. 354 330 355 331 Finger Tracking 356 332 --------------- ··· 406 338 For example usage of the type A protocol, see the bcm5974 driver. For 407 339 example usage of the type B protocol, see the hid-egalax driver. 408 340 409 - [1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the 410 - difference between the contact position and the approaching tool position 411 - could be used to derive tilt. 341 + [1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt. 412 342 [2] The list can of course be extended. 413 343 [3] The mtdev project: http://bitmath.org/code/mtdev/. 414 344 [4] See the section on event computation.
+1 -1
drivers/input/input-mt.c
··· 135 135 */ 136 136 void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count) 137 137 { 138 - struct input_mt_slot *oldest = 0; 138 + struct input_mt_slot *oldest = NULL; 139 139 int oldid = dev->trkid; 140 140 int count = 0; 141 141 int i;
+241 -222
drivers/input/touchscreen/atmel_mxt_ts.c
··· 36 36 #define MXT_FW_NAME "maxtouch.fw" 37 37 38 38 /* Registers */ 39 + #define MXT_INFO 0x00 39 40 #define MXT_FAMILY_ID 0x00 40 41 #define MXT_VARIANT_ID 0x01 41 42 #define MXT_VERSION 0x02 ··· 195 194 #define MXT_BOOT_STATUS_MASK 0x3f 196 195 197 196 /* Touch status */ 197 + #define MXT_UNGRIP (1 << 0) 198 198 #define MXT_SUPPRESS (1 << 1) 199 199 #define MXT_AMP (1 << 2) 200 200 #define MXT_VECTOR (1 << 3) ··· 212 210 /* Touchscreen absolute values */ 213 211 #define MXT_MAX_AREA 0xff 214 212 215 - #define MXT_MAX_FINGER 10 216 - 217 213 struct mxt_info { 218 214 u8 family_id; 219 215 u8 variant_id; ··· 225 225 struct mxt_object { 226 226 u8 type; 227 227 u16 start_address; 228 - u8 size; 229 - u8 instances; 228 + u8 size; /* Size of each instance - 1 */ 229 + u8 instances; /* Number of instances - 1 */ 230 230 u8 num_report_ids; 231 - 232 - /* to map object and message */ 233 - u8 max_reportid; 234 - }; 231 + } __packed; 235 232 236 233 struct mxt_message { 237 234 u8 reportid; 238 235 u8 message[7]; 239 236 }; 240 237 241 - struct mxt_finger { 242 - int status; 243 - int x; 244 - int y; 245 - int area; 246 - int pressure; 247 - }; 248 - 249 238 /* Each client has this additional data */ 250 239 struct mxt_data { 251 240 struct i2c_client *client; 252 241 struct input_dev *input_dev; 242 + char phys[64]; /* device physical location */ 253 243 const struct mxt_platform_data *pdata; 254 244 struct mxt_object *object_table; 255 245 struct mxt_info info; 256 - struct mxt_finger finger[MXT_MAX_FINGER]; 257 246 unsigned int irq; 258 247 unsigned int max_x; 259 248 unsigned int max_y; 249 + 250 + /* Cached parameters from object table */ 251 + u8 T6_reportid; 252 + u8 T9_reportid_min; 253 + u8 T9_reportid_max; 260 254 }; 261 255 262 256 static bool mxt_object_readable(unsigned int type) 263 257 { 264 258 switch (type) { 265 - case MXT_GEN_MESSAGE_T5: 266 259 case MXT_GEN_COMMAND_T6: 267 260 case MXT_GEN_POWER_T7: 268 261 case MXT_GEN_ACQUIRE_T8: ··· 389 396 { 390 397 struct i2c_msg xfer[2]; 391 398 u8 buf[2]; 399 + int ret; 392 400 393 401 buf[0] = reg & 0xff; 394 402 buf[1] = (reg >> 8) & 0xff; ··· 406 412 xfer[1].len = len; 407 413 xfer[1].buf = val; 408 414 409 - if (i2c_transfer(client->adapter, xfer, 2) != 2) { 410 - dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); 411 - return -EIO; 415 + ret = i2c_transfer(client->adapter, xfer, 2); 416 + if (ret == 2) { 417 + ret = 0; 418 + } else { 419 + if (ret >= 0) 420 + ret = -EIO; 421 + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", 422 + __func__, ret); 412 423 } 413 424 414 - return 0; 425 + return ret; 415 426 } 416 427 417 428 static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) ··· 424 425 return __mxt_read_reg(client, reg, 1, val); 425 426 } 426 427 427 - static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) 428 + static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, 429 + const void *val) 428 430 { 429 - u8 buf[3]; 431 + u8 *buf; 432 + size_t count; 433 + int ret; 434 + 435 + count = len + 2; 436 + buf = kmalloc(count, GFP_KERNEL); 437 + if (!buf) 438 + return -ENOMEM; 430 439 431 440 buf[0] = reg & 0xff; 432 441 buf[1] = (reg >> 8) & 0xff; 433 - buf[2] = val; 442 + memcpy(&buf[2], val, len); 434 443 435 - if (i2c_master_send(client, buf, 3) != 3) { 436 - dev_err(&client->dev, "%s: i2c send failed\n", __func__); 437 - return -EIO; 444 + ret = i2c_master_send(client, buf, count); 445 + if (ret == count) { 446 + ret = 0; 447 + } else { 448 + if (ret >= 0) 449 + ret = -EIO; 450 + dev_err(&client->dev, "%s: i2c send failed (%d)\n", 451 + __func__, ret); 438 452 } 439 453 440 - return 0; 454 + kfree(buf); 455 + return ret; 441 456 } 442 457 443 - static int mxt_read_object_table(struct i2c_client *client, 444 - u16 reg, u8 *object_buf) 458 + static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) 445 459 { 446 - return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, 447 - object_buf); 460 + return __mxt_write_reg(client, reg, 1, &val); 448 461 } 449 462 450 463 static struct mxt_object * ··· 490 479 sizeof(struct mxt_message), message); 491 480 } 492 481 493 - static int mxt_read_object(struct mxt_data *data, 494 - u8 type, u8 offset, u8 *val) 495 - { 496 - struct mxt_object *object; 497 - u16 reg; 498 - 499 - object = mxt_get_object(data, type); 500 - if (!object) 501 - return -EINVAL; 502 - 503 - reg = object->start_address; 504 - return __mxt_read_reg(data->client, reg + offset, 1, val); 505 - } 506 - 507 482 static int mxt_write_object(struct mxt_data *data, 508 483 u8 type, u8 offset, u8 val) 509 484 { ··· 504 507 return mxt_write_reg(data->client, reg + offset, val); 505 508 } 506 509 507 - static void mxt_input_report(struct mxt_data *data, int single_id) 508 - { 509 - struct mxt_finger *finger = data->finger; 510 - struct input_dev *input_dev = data->input_dev; 511 - int status = finger[single_id].status; 512 - int finger_num = 0; 513 - int id; 514 - 515 - for (id = 0; id < MXT_MAX_FINGER; id++) { 516 - if (!finger[id].status) 517 - continue; 518 - 519 - input_mt_slot(input_dev, id); 520 - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 521 - finger[id].status != MXT_RELEASE); 522 - 523 - if (finger[id].status != MXT_RELEASE) { 524 - finger_num++; 525 - input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 526 - finger[id].area); 527 - input_report_abs(input_dev, ABS_MT_POSITION_X, 528 - finger[id].x); 529 - input_report_abs(input_dev, ABS_MT_POSITION_Y, 530 - finger[id].y); 531 - input_report_abs(input_dev, ABS_MT_PRESSURE, 532 - finger[id].pressure); 533 - } else { 534 - finger[id].status = 0; 535 - } 536 - } 537 - 538 - input_report_key(input_dev, BTN_TOUCH, finger_num > 0); 539 - 540 - if (status != MXT_RELEASE) { 541 - input_report_abs(input_dev, ABS_X, finger[single_id].x); 542 - input_report_abs(input_dev, ABS_Y, finger[single_id].y); 543 - input_report_abs(input_dev, 544 - ABS_PRESSURE, finger[single_id].pressure); 545 - } 546 - 547 - input_sync(input_dev); 548 - } 549 - 550 510 static void mxt_input_touchevent(struct mxt_data *data, 551 511 struct mxt_message *message, int id) 552 512 { 553 - struct mxt_finger *finger = data->finger; 554 513 struct device *dev = &data->client->dev; 555 514 u8 status = message->message[0]; 515 + struct input_dev *input_dev = data->input_dev; 556 516 int x; 557 517 int y; 558 518 int area; 559 519 int pressure; 560 - 561 - /* Check the touch is present on the screen */ 562 - if (!(status & MXT_DETECT)) { 563 - if (status & MXT_RELEASE) { 564 - dev_dbg(dev, "[%d] released\n", id); 565 - 566 - finger[id].status = MXT_RELEASE; 567 - mxt_input_report(data, id); 568 - } 569 - return; 570 - } 571 - 572 - /* Check only AMP detection */ 573 - if (!(status & (MXT_PRESS | MXT_MOVE))) 574 - return; 575 520 576 521 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); 577 522 y = (message->message[2] << 4) | ((message->message[3] & 0xf)); ··· 525 586 area = message->message[4]; 526 587 pressure = message->message[5]; 527 588 528 - dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, 529 - status & MXT_MOVE ? "moved" : "pressed", 530 - x, y, area); 589 + dev_dbg(dev, 590 + "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n", 591 + id, 592 + (status & MXT_DETECT) ? 'D' : '.', 593 + (status & MXT_PRESS) ? 'P' : '.', 594 + (status & MXT_RELEASE) ? 'R' : '.', 595 + (status & MXT_MOVE) ? 'M' : '.', 596 + (status & MXT_VECTOR) ? 'V' : '.', 597 + (status & MXT_AMP) ? 'A' : '.', 598 + (status & MXT_SUPPRESS) ? 'S' : '.', 599 + (status & MXT_UNGRIP) ? 'U' : '.', 600 + x, y, area, pressure); 531 601 532 - finger[id].status = status & MXT_MOVE ? 533 - MXT_MOVE : MXT_PRESS; 534 - finger[id].x = x; 535 - finger[id].y = y; 536 - finger[id].area = area; 537 - finger[id].pressure = pressure; 602 + input_mt_slot(input_dev, id); 603 + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 604 + status & MXT_DETECT); 538 605 539 - mxt_input_report(data, id); 606 + if (status & MXT_DETECT) { 607 + input_report_abs(input_dev, ABS_MT_POSITION_X, x); 608 + input_report_abs(input_dev, ABS_MT_POSITION_Y, y); 609 + input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); 610 + input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); 611 + } 612 + } 613 + 614 + static unsigned mxt_extract_T6_csum(const u8 *csum) 615 + { 616 + return csum[0] | (csum[1] << 8) | (csum[2] << 16); 617 + } 618 + 619 + static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg) 620 + { 621 + u8 id = msg->reportid; 622 + return (id >= data->T9_reportid_min && id <= data->T9_reportid_max); 540 623 } 541 624 542 625 static irqreturn_t mxt_interrupt(int irq, void *dev_id) 543 626 { 544 627 struct mxt_data *data = dev_id; 545 628 struct mxt_message message; 546 - struct mxt_object *object; 629 + const u8 *payload = &message.message[0]; 547 630 struct device *dev = &data->client->dev; 548 - int id; 549 631 u8 reportid; 550 - u8 max_reportid; 551 - u8 min_reportid; 632 + bool update_input = false; 552 633 553 634 do { 554 635 if (mxt_read_message(data, &message)) { ··· 578 619 579 620 reportid = message.reportid; 580 621 581 - /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */ 582 - object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); 583 - if (!object) 584 - goto end; 585 - 586 - max_reportid = object->max_reportid; 587 - min_reportid = max_reportid - object->num_report_ids + 1; 588 - id = reportid - min_reportid; 589 - 590 - if (reportid >= min_reportid && reportid <= max_reportid) 622 + if (reportid == data->T6_reportid) { 623 + u8 status = payload[0]; 624 + unsigned csum = mxt_extract_T6_csum(&payload[1]); 625 + dev_dbg(dev, "Status: %02x Config Checksum: %06x\n", 626 + status, csum); 627 + } else if (mxt_is_T9_message(data, &message)) { 628 + int id = reportid - data->T9_reportid_min; 591 629 mxt_input_touchevent(data, &message, id); 592 - else 630 + update_input = true; 631 + } else { 593 632 mxt_dump_message(dev, &message); 633 + } 594 634 } while (reportid != 0xff); 635 + 636 + if (update_input) { 637 + input_mt_report_pointer_emulation(data->input_dev, false); 638 + input_sync(data->input_dev); 639 + } 595 640 596 641 end: 597 642 return IRQ_HANDLED; ··· 607 644 struct mxt_object *object; 608 645 struct device *dev = &data->client->dev; 609 646 int index = 0; 610 - int i, j, config_offset; 647 + int i, size; 648 + int ret; 611 649 612 650 if (!pdata->config) { 613 651 dev_dbg(dev, "No cfg data defined, skipping reg init\n"); ··· 621 657 if (!mxt_object_writable(object->type)) 622 658 continue; 623 659 624 - for (j = 0; 625 - j < (object->size + 1) * (object->instances + 1); 626 - j++) { 627 - config_offset = index + j; 628 - if (config_offset > pdata->config_length) { 629 - dev_err(dev, "Not enough config data!\n"); 630 - return -EINVAL; 631 - } 632 - mxt_write_object(data, object->type, j, 633 - pdata->config[config_offset]); 660 + size = (object->size + 1) * (object->instances + 1); 661 + if (index + size > pdata->config_length) { 662 + dev_err(dev, "Not enough config data!\n"); 663 + return -EINVAL; 634 664 } 635 - index += (object->size + 1) * (object->instances + 1); 665 + 666 + ret = __mxt_write_reg(data->client, object->start_address, 667 + size, &pdata->config[index]); 668 + if (ret) 669 + return ret; 670 + index += size; 636 671 } 637 672 638 673 return 0; ··· 712 749 struct i2c_client *client = data->client; 713 750 struct mxt_info *info = &data->info; 714 751 int error; 715 - u8 val; 716 752 717 - error = mxt_read_reg(client, MXT_FAMILY_ID, &val); 753 + /* Read 7-byte info block starting at address 0 */ 754 + error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info); 718 755 if (error) 719 756 return error; 720 - info->family_id = val; 721 - 722 - error = mxt_read_reg(client, MXT_VARIANT_ID, &val); 723 - if (error) 724 - return error; 725 - info->variant_id = val; 726 - 727 - error = mxt_read_reg(client, MXT_VERSION, &val); 728 - if (error) 729 - return error; 730 - info->version = val; 731 - 732 - error = mxt_read_reg(client, MXT_BUILD, &val); 733 - if (error) 734 - return error; 735 - info->build = val; 736 - 737 - error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); 738 - if (error) 739 - return error; 740 - info->object_num = val; 741 757 742 758 return 0; 743 759 } 744 760 745 761 static int mxt_get_object_table(struct mxt_data *data) 746 762 { 763 + struct i2c_client *client = data->client; 764 + size_t table_size; 747 765 int error; 748 766 int i; 749 - u16 reg; 750 - u8 reportid = 0; 751 - u8 buf[MXT_OBJECT_SIZE]; 767 + u8 reportid; 752 768 769 + table_size = data->info.object_num * sizeof(struct mxt_object); 770 + error = __mxt_read_reg(client, MXT_OBJECT_START, table_size, 771 + data->object_table); 772 + if (error) 773 + return error; 774 + 775 + /* Valid Report IDs start counting from 1 */ 776 + reportid = 1; 753 777 for (i = 0; i < data->info.object_num; i++) { 754 778 struct mxt_object *object = data->object_table + i; 779 + u8 min_id, max_id; 755 780 756 - reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; 757 - error = mxt_read_object_table(data->client, reg, buf); 758 - if (error) 759 - return error; 760 - 761 - object->type = buf[0]; 762 - object->start_address = (buf[2] << 8) | buf[1]; 763 - object->size = buf[3]; 764 - object->instances = buf[4]; 765 - object->num_report_ids = buf[5]; 781 + le16_to_cpus(&object->start_address); 766 782 767 783 if (object->num_report_ids) { 784 + min_id = reportid; 768 785 reportid += object->num_report_ids * 769 786 (object->instances + 1); 770 - object->max_reportid = reportid; 787 + max_id = reportid - 1; 788 + } else { 789 + min_id = 0; 790 + max_id = 0; 791 + } 792 + 793 + dev_dbg(&data->client->dev, 794 + "Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n", 795 + object->type, object->start_address, object->size + 1, 796 + object->instances + 1, min_id, max_id); 797 + 798 + switch (object->type) { 799 + case MXT_GEN_COMMAND_T6: 800 + data->T6_reportid = min_id; 801 + break; 802 + case MXT_TOUCH_MULTI_T9: 803 + data->T9_reportid_min = min_id; 804 + data->T9_reportid_max = max_id; 805 + break; 771 806 } 772 807 } 773 808 774 809 return 0; 810 + } 811 + 812 + static void mxt_free_object_table(struct mxt_data *data) 813 + { 814 + kfree(data->object_table); 815 + data->object_table = NULL; 816 + data->T6_reportid = 0; 817 + data->T9_reportid_min = 0; 818 + data->T9_reportid_max = 0; 819 + 775 820 } 776 821 777 822 static int mxt_initialize(struct mxt_data *data) ··· 804 833 /* Get object table information */ 805 834 error = mxt_get_object_table(data); 806 835 if (error) 807 - return error; 836 + goto err_free_object_table; 808 837 809 838 /* Check register init values */ 810 839 error = mxt_check_reg_init(data); 811 840 if (error) 812 - return error; 841 + goto err_free_object_table; 813 842 814 843 mxt_handle_pdata(data); 815 844 ··· 827 856 /* Update matrix size at info struct */ 828 857 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); 829 858 if (error) 830 - return error; 859 + goto err_free_object_table; 831 860 info->matrix_xsize = val; 832 861 833 862 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); 834 863 if (error) 835 - return error; 864 + goto err_free_object_table; 836 865 info->matrix_ysize = val; 837 866 838 867 dev_info(&client->dev, 839 - "Family ID: %d Variant ID: %d Version: %d Build: %d\n", 840 - info->family_id, info->variant_id, info->version, 841 - info->build); 868 + "Family ID: %u Variant ID: %u Major.Minor.Build: %u.%u.%02X\n", 869 + info->family_id, info->variant_id, info->version >> 4, 870 + info->version & 0xf, info->build); 842 871 843 872 dev_info(&client->dev, 844 - "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", 873 + "Matrix X Size: %u Matrix Y Size: %u Object Num: %u\n", 845 874 info->matrix_xsize, info->matrix_ysize, 846 875 info->object_num); 847 876 848 877 return 0; 878 + 879 + err_free_object_table: 880 + mxt_free_object_table(data); 881 + return error; 849 882 } 850 883 851 884 static void mxt_calc_resolution(struct mxt_data *data) ··· 866 891 } 867 892 } 868 893 894 + /* Firmware Version is returned as Major.Minor.Build */ 895 + static ssize_t mxt_fw_version_show(struct device *dev, 896 + struct device_attribute *attr, char *buf) 897 + { 898 + struct mxt_data *data = dev_get_drvdata(dev); 899 + struct mxt_info *info = &data->info; 900 + return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n", 901 + info->version >> 4, info->version & 0xf, info->build); 902 + } 903 + 904 + /* Hardware Version is returned as FamilyID.VariantID */ 905 + static ssize_t mxt_hw_version_show(struct device *dev, 906 + struct device_attribute *attr, char *buf) 907 + { 908 + struct mxt_data *data = dev_get_drvdata(dev); 909 + struct mxt_info *info = &data->info; 910 + return scnprintf(buf, PAGE_SIZE, "%u.%u\n", 911 + info->family_id, info->variant_id); 912 + } 913 + 914 + static ssize_t mxt_show_instance(char *buf, int count, 915 + struct mxt_object *object, int instance, 916 + const u8 *val) 917 + { 918 + int i; 919 + 920 + if (object->instances > 0) 921 + count += scnprintf(buf + count, PAGE_SIZE - count, 922 + "Instance %u\n", instance); 923 + 924 + for (i = 0; i < object->size + 1; i++) 925 + count += scnprintf(buf + count, PAGE_SIZE - count, 926 + "\t[%2u]: %02x (%d)\n", i, val[i], val[i]); 927 + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); 928 + 929 + return count; 930 + } 931 + 869 932 static ssize_t mxt_object_show(struct device *dev, 870 933 struct device_attribute *attr, char *buf) 871 934 { ··· 912 899 int count = 0; 913 900 int i, j; 914 901 int error; 915 - u8 val; 902 + u8 *obuf; 916 903 904 + /* Pre-allocate buffer large enough to hold max sized object. */ 905 + obuf = kmalloc(256, GFP_KERNEL); 906 + if (!obuf) 907 + return -ENOMEM; 908 + 909 + error = 0; 917 910 for (i = 0; i < data->info.object_num; i++) { 918 911 object = data->object_table + i; 919 912 920 - count += snprintf(buf + count, PAGE_SIZE - count, 921 - "Object[%d] (Type %d)\n", 922 - i + 1, object->type); 923 - if (count >= PAGE_SIZE) 924 - return PAGE_SIZE - 1; 925 - 926 - if (!mxt_object_readable(object->type)) { 927 - count += snprintf(buf + count, PAGE_SIZE - count, 928 - "\n"); 929 - if (count >= PAGE_SIZE) 930 - return PAGE_SIZE - 1; 913 + if (!mxt_object_readable(object->type)) 931 914 continue; 932 - } 933 915 934 - for (j = 0; j < object->size + 1; j++) { 935 - error = mxt_read_object(data, 936 - object->type, j, &val); 916 + count += scnprintf(buf + count, PAGE_SIZE - count, 917 + "T%u:\n", object->type); 918 + 919 + for (j = 0; j < object->instances + 1; j++) { 920 + u16 size = object->size + 1; 921 + u16 addr = object->start_address + j * size; 922 + 923 + error = __mxt_read_reg(data->client, addr, size, obuf); 937 924 if (error) 938 - return error; 925 + goto done; 939 926 940 - count += snprintf(buf + count, PAGE_SIZE - count, 941 - "\t[%2d]: %02x (%d)\n", j, val, val); 942 - if (count >= PAGE_SIZE) 943 - return PAGE_SIZE - 1; 927 + count = mxt_show_instance(buf, count, object, j, obuf); 944 928 } 945 - 946 - count += snprintf(buf + count, PAGE_SIZE - count, "\n"); 947 - if (count >= PAGE_SIZE) 948 - return PAGE_SIZE - 1; 949 929 } 950 930 951 - return count; 931 + done: 932 + kfree(obuf); 933 + return error ?: count; 952 934 } 953 935 954 936 static int mxt_load_fw(struct device *dev, const char *fn) ··· 1036 1028 /* Wait for reset */ 1037 1029 msleep(MXT_FWRESET_TIME); 1038 1030 1039 - kfree(data->object_table); 1040 - data->object_table = NULL; 1031 + mxt_free_object_table(data); 1041 1032 1042 1033 mxt_initialize(data); 1043 1034 } ··· 1050 1043 return count; 1051 1044 } 1052 1045 1046 + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); 1047 + static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); 1053 1048 static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); 1054 1049 static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); 1055 1050 1056 1051 static struct attribute *mxt_attrs[] = { 1052 + &dev_attr_fw_version.attr, 1053 + &dev_attr_hw_version.attr, 1057 1054 &dev_attr_object.attr, 1058 1055 &dev_attr_update_fw.attr, 1059 1056 NULL ··· 1104 1093 struct mxt_data *data; 1105 1094 struct input_dev *input_dev; 1106 1095 int error; 1096 + unsigned int num_mt_slots; 1107 1097 1108 1098 if (!pdata) 1109 1099 return -EINVAL; ··· 1118 1106 } 1119 1107 1120 1108 input_dev->name = "Atmel maXTouch Touchscreen"; 1109 + snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", 1110 + client->adapter->nr, client->addr); 1111 + input_dev->phys = data->phys; 1112 + 1121 1113 input_dev->id.bustype = BUS_I2C; 1122 1114 input_dev->dev.parent = &client->dev; 1123 1115 input_dev->open = mxt_input_open; ··· 1133 1117 data->irq = client->irq; 1134 1118 1135 1119 mxt_calc_resolution(data); 1120 + 1121 + error = mxt_initialize(data); 1122 + if (error) 1123 + goto err_free_mem; 1136 1124 1137 1125 __set_bit(EV_ABS, input_dev->evbit); 1138 1126 __set_bit(EV_KEY, input_dev->evbit); ··· 1151 1131 0, 255, 0, 0); 1152 1132 1153 1133 /* For multi touch */ 1154 - input_mt_init_slots(input_dev, MXT_MAX_FINGER); 1134 + num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; 1135 + error = input_mt_init_slots(input_dev, num_mt_slots); 1136 + if (error) 1137 + goto err_free_object; 1155 1138 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1156 1139 0, MXT_MAX_AREA, 0, 0); 1157 1140 input_set_abs_params(input_dev, ABS_MT_POSITION_X, ··· 1167 1144 input_set_drvdata(input_dev, data); 1168 1145 i2c_set_clientdata(client, data); 1169 1146 1170 - error = mxt_initialize(data); 1171 - if (error) 1172 - goto err_free_object; 1173 - 1174 1147 error = request_threaded_irq(client->irq, NULL, mxt_interrupt, 1175 1148 pdata->irqflags | IRQF_ONESHOT, 1176 - client->dev.driver->name, data); 1149 + client->name, data); 1177 1150 if (error) { 1178 1151 dev_err(&client->dev, "Failed to register interrupt\n"); 1179 1152 goto err_free_object;
+5 -3
include/linux/input.h
··· 807 807 #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ 808 808 #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ 809 809 #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ 810 - #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ 811 - #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ 810 + #define ABS_MT_POSITION_X 0x35 /* Center X touch position */ 811 + #define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */ 812 812 #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ 813 813 #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ 814 814 #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ 815 815 #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ 816 816 #define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ 817 + #define ABS_MT_TOOL_X 0x3c /* Center X tool position */ 818 + #define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */ 817 819 818 820 #ifdef __KERNEL__ 819 821 /* Implementation details, userspace should not care about these */ 820 822 #define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR 821 - #define ABS_MT_LAST ABS_MT_DISTANCE 823 + #define ABS_MT_LAST ABS_MT_TOOL_Y 822 824 #endif 823 825 824 826 #define ABS_MAX 0x3f