Lines Matching +full:deep +full:- +full:touch
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (C) 2011-2014 Atmel Corporation
29 #include <media/v4l2-device.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/videobuf2-v4l2.h>
32 #include <media/videobuf2-vmalloc.h>
158 /* T100 Multiple Touch Touchscreen */
352 return obj->size_minus_one + 1; in mxt_obj_size()
357 return obj->instances_minus_one + 1; in mxt_obj_instances()
397 dev_dbg(&data->client->dev, "message: %*ph\n", in mxt_dump_message()
398 data->T5_msg_size, message); in mxt_dump_message()
405 struct device *dev = &data->client->dev; in mxt_wait_for_completion()
414 return -ETIMEDOUT; in mxt_wait_for_completion()
425 msg.addr = data->bootloader_addr; in mxt_bootloader_read()
426 msg.flags = data->client->flags & I2C_M_TEN; in mxt_bootloader_read()
431 ret = i2c_transfer(data->client->adapter, &msg, 1); in mxt_bootloader_read()
435 ret = ret < 0 ? ret : -EIO; in mxt_bootloader_read()
436 dev_err(&data->client->dev, "%s: i2c recv failed (%d)\n", in mxt_bootloader_read()
449 msg.addr = data->bootloader_addr; in mxt_bootloader_write()
450 msg.flags = data->client->flags & I2C_M_TEN; in mxt_bootloader_write()
454 ret = i2c_transfer(data->client->adapter, &msg, 1); in mxt_bootloader_write()
458 ret = ret < 0 ? ret : -EIO; in mxt_bootloader_write()
459 dev_err(&data->client->dev, "%s: i2c send failed (%d)\n", in mxt_bootloader_write()
468 u8 appmode = data->client->addr; in mxt_lookup_bootloader_address()
470 u8 family_id = data->info ? data->info->family_id : 0; in mxt_lookup_bootloader_address()
477 bootloader = appmode - 0x24; in mxt_lookup_bootloader_address()
485 bootloader = appmode - 0x26; in mxt_lookup_bootloader_address()
489 dev_err(&data->client->dev, in mxt_lookup_bootloader_address()
492 return -EINVAL; in mxt_lookup_bootloader_address()
495 data->bootloader_addr = bootloader; in mxt_lookup_bootloader_address()
501 struct device *dev = &data->client->dev; in mxt_probe_bootloader()
525 struct device *dev = &data->client->dev; in mxt_get_bootloader_version()
547 struct device *dev = &data->client->dev; in mxt_check_bootloader()
559 ret = mxt_wait_for_completion(data, &data->bl_completion, in mxt_check_bootloader()
563 * TODO: handle -ERESTARTSYS better by terminating in mxt_check_bootloader()
591 return -EINVAL; in mxt_check_bootloader()
595 return -EINVAL; in mxt_check_bootloader()
601 return -EINVAL; in mxt_check_bootloader()
638 xfer[0].addr = client->addr; in __mxt_read_reg()
644 xfer[1].addr = client->addr; in __mxt_read_reg()
649 ret = i2c_transfer(client->adapter, xfer, 2); in __mxt_read_reg()
654 ret = -EIO; in __mxt_read_reg()
655 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", in __mxt_read_reg()
672 return -ENOMEM; in __mxt_write_reg()
683 ret = -EIO; in __mxt_write_reg()
684 dev_err(&client->dev, "%s: i2c send failed (%d)\n", in __mxt_write_reg()
703 for (i = 0; i < data->info->object_num; i++) { in mxt_get_object()
704 object = data->object_table + i; in mxt_get_object()
705 if (object->type == type) in mxt_get_object()
709 dev_warn(&data->client->dev, "Invalid object type T%u\n", type); in mxt_get_object()
715 struct device *dev = &data->client->dev; in mxt_proc_t6_messages()
719 if (crc != data->config_crc) { in mxt_proc_t6_messages()
720 data->config_crc = crc; in mxt_proc_t6_messages()
724 complete(&data->crc_completion); in mxt_proc_t6_messages()
728 complete(&data->reset_completion); in mxt_proc_t6_messages()
731 if (status != data->t6_status) in mxt_proc_t6_messages()
743 data->t6_status = status; in mxt_proc_t6_messages()
754 return -EINVAL; in mxt_write_object()
756 reg = object->start_address; in mxt_write_object()
757 return mxt_write_reg(data->client, reg + offset, val); in mxt_write_object()
762 struct input_dev *input = data->input_dev; in mxt_input_button()
765 for (i = 0; i < data->t19_num_keys; i++) { in mxt_input_button()
766 if (data->t19_keymap[i] == KEY_RESERVED) in mxt_input_button()
769 /* Active-low switch */ in mxt_input_button()
770 input_report_key(input, data->t19_keymap[i], in mxt_input_button()
777 input_mt_report_pointer_emulation(data->input_dev, in mxt_input_sync()
778 data->t19_num_keys); in mxt_input_sync()
779 input_sync(data->input_dev); in mxt_input_sync()
784 struct device *dev = &data->client->dev; in mxt_proc_t9_message()
785 struct input_dev *input_dev = data->input_dev; in mxt_proc_t9_message()
793 id = message[0] - data->T9_reportid_min; in mxt_proc_t9_message()
799 if (data->max_x < 1024) in mxt_proc_t9_message()
801 if (data->max_y < 1024) in mxt_proc_t9_message()
833 /* if active, pressure must be non-zero */ in mxt_proc_t9_message()
837 /* Touch active */ in mxt_proc_t9_message()
844 /* Touch no longer active, close out slot */ in mxt_proc_t9_message()
848 data->update_input = true; in mxt_proc_t9_message()
853 struct device *dev = &data->client->dev; in mxt_proc_t100_message()
854 struct input_dev *input_dev = data->input_dev; in mxt_proc_t100_message()
866 id = message[0] - data->T100_reportid_min - 2; in mxt_proc_t100_message()
884 if (data->t100_aux_vect) in mxt_proc_t100_message()
885 orientation = message[data->t100_aux_vect]; in mxt_proc_t100_message()
894 if (data->t100_aux_area) in mxt_proc_t100_message()
895 major = message[data->t100_aux_area]; in mxt_proc_t100_message()
897 if (data->t100_aux_ampl) in mxt_proc_t100_message()
898 pressure = message[data->t100_aux_ampl]; in mxt_proc_t100_message()
900 if (data->t100_aux_vect) in mxt_proc_t100_message()
901 orientation = message[data->t100_aux_vect]; in mxt_proc_t100_message()
914 if (data->t100_aux_ampl) in mxt_proc_t100_message()
915 pressure = message[data->t100_aux_ampl]; in mxt_proc_t100_message()
920 /* Ignore suppressed touch */ in mxt_proc_t100_message()
930 * Values reported should be non-zero if tool is touching the in mxt_proc_t100_message()
956 data->update_input = true; in mxt_proc_t100_message()
966 if (report_id == data->T6_reportid) { in mxt_proc_message()
968 } else if (!data->input_dev) { in mxt_proc_message()
974 } else if (report_id >= data->T9_reportid_min && in mxt_proc_message()
975 report_id <= data->T9_reportid_max) { in mxt_proc_message()
977 } else if (report_id >= data->T100_reportid_min && in mxt_proc_message()
978 report_id <= data->T100_reportid_max) { in mxt_proc_message()
980 } else if (report_id == data->T19_reportid) { in mxt_proc_message()
982 data->update_input = true; in mxt_proc_message()
992 struct device *dev = &data->client->dev; in mxt_read_and_process_messages()
998 if (count > data->max_reportid) in mxt_read_and_process_messages()
999 return -EINVAL; in mxt_read_and_process_messages()
1002 ret = __mxt_read_reg(data->client, data->T5_address, in mxt_read_and_process_messages()
1003 data->T5_msg_size * count, data->msg_buf); in mxt_read_and_process_messages()
1011 data->msg_buf + data->T5_msg_size * i); in mxt_read_and_process_messages()
1023 struct device *dev = &data->client->dev; in mxt_process_messages_t44()
1028 ret = __mxt_read_reg(data->client, data->T44_address, in mxt_process_messages_t44()
1029 data->T5_msg_size + 1, data->msg_buf); in mxt_process_messages_t44()
1035 count = data->msg_buf[0]; in mxt_process_messages_t44()
1044 if (count > data->max_reportid) { in mxt_process_messages_t44()
1046 count = data->max_reportid; in mxt_process_messages_t44()
1050 ret = mxt_proc_message(data, data->msg_buf + 1); in mxt_process_messages_t44()
1056 num_left = count - 1; in mxt_process_messages_t44()
1068 if (data->update_input) { in mxt_process_messages_t44()
1070 data->update_input = false; in mxt_process_messages_t44()
1078 struct device *dev = &data->client->dev; in mxt_process_messages_until_invalid()
1082 count = data->max_reportid; in mxt_process_messages_until_invalid()
1089 } while (--tries); in mxt_process_messages_until_invalid()
1091 if (data->update_input) { in mxt_process_messages_until_invalid()
1093 data->update_input = false; in mxt_process_messages_until_invalid()
1097 return -EBUSY; in mxt_process_messages_until_invalid()
1103 u8 count = data->last_message_count; in mxt_process_messages()
1105 if (count < 1 || count > data->max_reportid) in mxt_process_messages()
1126 } while (total_handled < data->num_touchids); in mxt_process_messages()
1129 data->last_message_count = total_handled; in mxt_process_messages()
1131 if (data->update_input) { in mxt_process_messages()
1133 data->update_input = false; in mxt_process_messages()
1143 if (data->in_bootloader) { in mxt_interrupt()
1145 complete(&data->bl_completion); in mxt_interrupt()
1149 if (!data->object_table) in mxt_interrupt()
1152 if (data->T44_address) { in mxt_interrupt()
1167 reg = data->T6_address + cmd_offset; in mxt_t6_command()
1169 ret = mxt_write_reg(data->client, reg, value); in mxt_t6_command()
1178 ret = __mxt_read_reg(data->client, reg, 1, &command_register); in mxt_t6_command()
1184 dev_err(&data->client->dev, "Command failed!\n"); in mxt_t6_command()
1185 return -EIO; in mxt_t6_command()
1195 enable_irq(data->irq); in mxt_acquire_irq()
1197 if (data->use_retrigen_workaround) { in mxt_acquire_irq()
1208 struct device *dev = &data->client->dev; in mxt_soft_reset()
1213 disable_irq(data->irq); in mxt_soft_reset()
1215 reinit_completion(&data->reset_completion); in mxt_soft_reset()
1226 ret = mxt_wait_for_completion(data, &data->reset_completion, in mxt_soft_reset()
1240 data->config_crc = 0; in mxt_update_crc()
1241 reinit_completion(&data->crc_completion); in mxt_update_crc()
1249 mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT); in mxt_update_crc()
1271 u8 *last_val = base + end_off - 1; in mxt_calculate_crc()
1274 return -EINVAL; in mxt_calculate_crc()
1285 /* Mask to 24-bit */ in mxt_calculate_crc()
1293 struct i2c_client *client = data->client; in mxt_check_retrigen()
1298 data->use_retrigen_workaround = false; in mxt_check_retrigen()
1300 irqd = irq_get_irq_data(data->irq); in mxt_check_retrigen()
1302 return -EINVAL; in mxt_check_retrigen()
1307 if (data->T18_address) { in mxt_check_retrigen()
1309 data->T18_address + MXT_COMMS_CTRL, in mxt_check_retrigen()
1318 dev_warn(&client->dev, "Enabling RETRIGEN workaround\n"); in mxt_check_retrigen()
1319 data->use_retrigen_workaround = true; in mxt_check_retrigen()
1325 struct device *dev = &data->client->dev; in mxt_prepare_cfg_mem()
1334 while (cfg->raw_pos < cfg->raw_size) { in mxt_prepare_cfg_mem()
1336 ret = sscanf(cfg->raw + cfg->raw_pos, "%x %x %x%n", in mxt_prepare_cfg_mem()
1343 return -EINVAL; in mxt_prepare_cfg_mem()
1345 cfg->raw_pos += offset; in mxt_prepare_cfg_mem()
1351 ret = sscanf(cfg->raw + cfg->raw_pos, "%hhx%n", in mxt_prepare_cfg_mem()
1356 return -EINVAL; in mxt_prepare_cfg_mem()
1358 cfg->raw_pos += offset; in mxt_prepare_cfg_mem()
1367 * or the file is corrupt or hand-edited. in mxt_prepare_cfg_mem()
1370 size - mxt_obj_size(object), type); in mxt_prepare_cfg_mem()
1375 * to zero these bytes - previous behaviour will be in mxt_prepare_cfg_mem()
1378 * updated. We warn here but do nothing else - the in mxt_prepare_cfg_mem()
1382 mxt_obj_size(object) - size, type); in mxt_prepare_cfg_mem()
1387 return -EINVAL; in mxt_prepare_cfg_mem()
1390 reg = object->start_address + mxt_obj_size(object) * instance; in mxt_prepare_cfg_mem()
1393 ret = sscanf(cfg->raw + cfg->raw_pos, "%hhx%n", in mxt_prepare_cfg_mem()
1399 return -EINVAL; in mxt_prepare_cfg_mem()
1401 cfg->raw_pos += offset; in mxt_prepare_cfg_mem()
1406 byte_offset = reg + i - cfg->start_ofs; in mxt_prepare_cfg_mem()
1408 if (byte_offset >= 0 && byte_offset < cfg->mem_size) { in mxt_prepare_cfg_mem()
1409 *(cfg->mem + byte_offset) = val; in mxt_prepare_cfg_mem()
1412 reg, object->type, byte_offset); in mxt_prepare_cfg_mem()
1413 return -EINVAL; in mxt_prepare_cfg_mem()
1427 while (byte_offset < cfg->mem_size) { in mxt_upload_cfg_mem()
1428 unsigned int size = cfg->mem_size - byte_offset; in mxt_upload_cfg_mem()
1433 error = __mxt_write_reg(data->client, in mxt_upload_cfg_mem()
1434 cfg->start_ofs + byte_offset, in mxt_upload_cfg_mem()
1435 size, cfg->mem + byte_offset); in mxt_upload_cfg_mem()
1437 dev_err(&data->client->dev, in mxt_upload_cfg_mem()
1451 * mxt_update_cfg - download configuration to chip
1458 * 3) Chip Information Block 24-bit CRC Checksum
1459 * 4) Chip Configuration 24-bit CRC Checksum
1464 * <TYPE> - 2-byte object type as hex
1465 * <INSTANCE> - 2-byte object instance number as hex
1466 * <SIZE> - 2-byte object size as hex
1467 * <CONTENTS> - array of <SIZE> 1-byte hex values
1471 struct device *dev = &data->client->dev; in mxt_update_cfg()
1480 cfg.raw = kmemdup_nul(fw->data, fw->size, GFP_KERNEL); in mxt_update_cfg()
1482 return -ENOMEM; in mxt_update_cfg()
1484 cfg.raw_size = fw->size; in mxt_update_cfg()
1490 ret = -EINVAL; in mxt_update_cfg()
1503 ret = -EINVAL; in mxt_update_cfg()
1510 if (cfg.info.family_id != data->info->family_id) { in mxt_update_cfg()
1512 ret = -EINVAL; in mxt_update_cfg()
1516 if (cfg.info.variant_id != data->info->variant_id) { in mxt_update_cfg()
1518 ret = -EINVAL; in mxt_update_cfg()
1526 ret = -EINVAL; in mxt_update_cfg()
1534 ret = -EINVAL; in mxt_update_cfg()
1545 if (info_crc == data->info_crc) { in mxt_update_cfg()
1546 if (config_crc == 0 || data->config_crc == 0) { in mxt_update_cfg()
1548 } else if (config_crc == data->config_crc) { in mxt_update_cfg()
1550 data->config_crc); in mxt_update_cfg()
1555 data->config_crc, config_crc); in mxt_update_cfg()
1559 "Warning: Info CRC error - device=0x%06X file=0x%06X\n", in mxt_update_cfg()
1560 data->info_crc, info_crc); in mxt_update_cfg()
1565 data->info->object_num * sizeof(struct mxt_object) + in mxt_update_cfg()
1567 cfg.mem_size = data->mem_size - cfg.start_ofs; in mxt_update_cfg()
1570 ret = -ENOMEM; in mxt_update_cfg()
1579 if (data->T71_address) in mxt_update_cfg()
1580 crc_start = data->T71_address; in mxt_update_cfg()
1581 else if (data->T7_address) in mxt_update_cfg()
1582 crc_start = data->T7_address; in mxt_update_cfg()
1588 crc_start - cfg.start_ofs, in mxt_update_cfg()
1624 if (data->input_dev) { in mxt_free_input_device()
1625 input_unregister_device(data->input_dev); in mxt_free_input_device()
1626 data->input_dev = NULL; in mxt_free_input_device()
1633 video_unregister_device(&data->dbg.vdev); in mxt_free_object_table()
1634 v4l2_device_unregister(&data->dbg.v4l2); in mxt_free_object_table()
1636 data->object_table = NULL; in mxt_free_object_table()
1637 data->info = NULL; in mxt_free_object_table()
1638 kfree(data->raw_info_block); in mxt_free_object_table()
1639 data->raw_info_block = NULL; in mxt_free_object_table()
1640 kfree(data->msg_buf); in mxt_free_object_table()
1641 data->msg_buf = NULL; in mxt_free_object_table()
1642 data->T5_address = 0; in mxt_free_object_table()
1643 data->T5_msg_size = 0; in mxt_free_object_table()
1644 data->T6_reportid = 0; in mxt_free_object_table()
1645 data->T7_address = 0; in mxt_free_object_table()
1646 data->T71_address = 0; in mxt_free_object_table()
1647 data->T9_reportid_min = 0; in mxt_free_object_table()
1648 data->T9_reportid_max = 0; in mxt_free_object_table()
1649 data->T18_address = 0; in mxt_free_object_table()
1650 data->T19_reportid = 0; in mxt_free_object_table()
1651 data->T44_address = 0; in mxt_free_object_table()
1652 data->T100_reportid_min = 0; in mxt_free_object_table()
1653 data->T100_reportid_max = 0; in mxt_free_object_table()
1654 data->max_reportid = 0; in mxt_free_object_table()
1660 struct i2c_client *client = data->client; in mxt_parse_object_table()
1667 data->mem_size = 0; in mxt_parse_object_table()
1668 for (i = 0; i < data->info->object_num; i++) { in mxt_parse_object_table()
1672 le16_to_cpus(&object->start_address); in mxt_parse_object_table()
1674 if (object->num_report_ids) { in mxt_parse_object_table()
1676 reportid += object->num_report_ids * in mxt_parse_object_table()
1678 max_id = reportid - 1; in mxt_parse_object_table()
1684 dev_dbg(&data->client->dev, in mxt_parse_object_table()
1685 "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n", in mxt_parse_object_table()
1686 object->type, object->start_address, in mxt_parse_object_table()
1690 switch (object->type) { in mxt_parse_object_table()
1692 if (data->info->family_id == 0x80 && in mxt_parse_object_table()
1693 data->info->version < 0x20) { in mxt_parse_object_table()
1699 data->T5_msg_size = mxt_obj_size(object); in mxt_parse_object_table()
1702 data->T5_msg_size = mxt_obj_size(object) - 1; in mxt_parse_object_table()
1704 data->T5_address = object->start_address; in mxt_parse_object_table()
1707 data->T6_reportid = min_id; in mxt_parse_object_table()
1708 data->T6_address = object->start_address; in mxt_parse_object_table()
1711 data->T7_address = object->start_address; in mxt_parse_object_table()
1714 data->T71_address = object->start_address; in mxt_parse_object_table()
1717 data->multitouch = MXT_TOUCH_MULTI_T9; in mxt_parse_object_table()
1719 data->T9_reportid_min = min_id; in mxt_parse_object_table()
1720 data->T9_reportid_max = min_id + in mxt_parse_object_table()
1721 object->num_report_ids - 1; in mxt_parse_object_table()
1722 data->num_touchids = object->num_report_ids; in mxt_parse_object_table()
1725 data->T18_address = object->start_address; in mxt_parse_object_table()
1728 data->T44_address = object->start_address; in mxt_parse_object_table()
1731 data->T19_reportid = min_id; in mxt_parse_object_table()
1734 data->multitouch = MXT_TOUCH_MULTITOUCHSCREEN_T100; in mxt_parse_object_table()
1735 data->T100_reportid_min = min_id; in mxt_parse_object_table()
1736 data->T100_reportid_max = max_id; in mxt_parse_object_table()
1738 data->num_touchids = object->num_report_ids - 2; in mxt_parse_object_table()
1742 end_address = object->start_address in mxt_parse_object_table()
1743 + mxt_obj_size(object) * mxt_obj_instances(object) - 1; in mxt_parse_object_table()
1745 if (end_address >= data->mem_size) in mxt_parse_object_table()
1746 data->mem_size = end_address + 1; in mxt_parse_object_table()
1750 data->max_reportid = reportid; in mxt_parse_object_table()
1753 if (data->T44_address && (data->T5_address != data->T44_address + 1)) { in mxt_parse_object_table()
1754 dev_err(&client->dev, "Invalid T44 position\n"); in mxt_parse_object_table()
1755 return -EINVAL; in mxt_parse_object_table()
1758 data->msg_buf = kcalloc(data->max_reportid, in mxt_parse_object_table()
1759 data->T5_msg_size, GFP_KERNEL); in mxt_parse_object_table()
1760 if (!data->msg_buf) in mxt_parse_object_table()
1761 return -ENOMEM; in mxt_parse_object_table()
1768 struct i2c_client *client = data->client; in mxt_read_info_block()
1777 if (data->raw_info_block) in mxt_read_info_block()
1780 /* Read 7-byte ID information block starting at address 0 */ in mxt_read_info_block()
1784 return -ENOMEM; in mxt_read_info_block()
1791 num_objects = ((struct mxt_info *)id_buf)->object_num; in mxt_read_info_block()
1797 error = -ENOMEM; in mxt_read_info_block()
1804 size - MXT_OBJECT_START, in mxt_read_info_block()
1810 crc_ptr = id_buf + size - MXT_INFO_CHECKSUM_SIZE; in mxt_read_info_block()
1811 data->info_crc = crc_ptr[0] | (crc_ptr[1] << 8) | (crc_ptr[2] << 16); in mxt_read_info_block()
1814 size - MXT_INFO_CHECKSUM_SIZE); in mxt_read_info_block()
1818 * issue or else device is not using Object Based Protocol (eg i2c-hid) in mxt_read_info_block()
1820 if ((data->info_crc == 0) || (data->info_crc != calculated_crc)) { in mxt_read_info_block()
1821 dev_err(&client->dev, in mxt_read_info_block()
1823 calculated_crc, data->info_crc); in mxt_read_info_block()
1824 error = -EIO; in mxt_read_info_block()
1828 data->raw_info_block = id_buf; in mxt_read_info_block()
1829 data->info = (struct mxt_info *)id_buf; in mxt_read_info_block()
1831 dev_info(&client->dev, in mxt_read_info_block()
1833 data->info->family_id, data->info->variant_id, in mxt_read_info_block()
1834 data->info->version >> 4, data->info->version & 0xf, in mxt_read_info_block()
1835 data->info->build, data->info->object_num); in mxt_read_info_block()
1840 dev_err(&client->dev, "Error %d parsing object table\n", error); in mxt_read_info_block()
1845 data->object_table = (struct mxt_object *)(id_buf + MXT_OBJECT_START); in mxt_read_info_block()
1856 struct i2c_client *client = data->client; in mxt_read_t9_resolution()
1864 return -EINVAL; in mxt_read_t9_resolution()
1867 object->start_address + MXT_T9_XSIZE, in mxt_read_t9_resolution()
1868 sizeof(data->xsize), &data->xsize); in mxt_read_t9_resolution()
1873 object->start_address + MXT_T9_YSIZE, in mxt_read_t9_resolution()
1874 sizeof(data->ysize), &data->ysize); in mxt_read_t9_resolution()
1879 object->start_address + MXT_T9_RANGE, in mxt_read_t9_resolution()
1884 data->max_x = get_unaligned_le16(&range.x); in mxt_read_t9_resolution()
1885 data->max_y = get_unaligned_le16(&range.y); in mxt_read_t9_resolution()
1888 object->start_address + MXT_T9_ORIENT, in mxt_read_t9_resolution()
1893 data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; in mxt_read_t9_resolution()
1894 data->invertx = orient & MXT_T9_ORIENT_INVERTX; in mxt_read_t9_resolution()
1895 data->inverty = orient & MXT_T9_ORIENT_INVERTY; in mxt_read_t9_resolution()
1902 struct i2c_client *client = data->client; in mxt_read_t100_config()
1911 return -EINVAL; in mxt_read_t100_config()
1915 object->start_address + MXT_T100_XRANGE, in mxt_read_t100_config()
1920 data->max_x = get_unaligned_le16(&range_x); in mxt_read_t100_config()
1923 object->start_address + MXT_T100_YRANGE, in mxt_read_t100_config()
1928 data->max_y = get_unaligned_le16(&range_y); in mxt_read_t100_config()
1931 object->start_address + MXT_T100_XSIZE, in mxt_read_t100_config()
1932 sizeof(data->xsize), &data->xsize); in mxt_read_t100_config()
1937 object->start_address + MXT_T100_YSIZE, in mxt_read_t100_config()
1938 sizeof(data->ysize), &data->ysize); in mxt_read_t100_config()
1944 object->start_address + MXT_T100_CFG1, in mxt_read_t100_config()
1949 data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; in mxt_read_t100_config()
1950 data->invertx = cfg & MXT_T100_CFG_INVERTX; in mxt_read_t100_config()
1951 data->inverty = cfg & MXT_T100_CFG_INVERTY; in mxt_read_t100_config()
1955 object->start_address + MXT_T100_TCHAUX, in mxt_read_t100_config()
1963 data->t100_aux_vect = aux++; in mxt_read_t100_config()
1966 data->t100_aux_ampl = aux++; in mxt_read_t100_config()
1969 data->t100_aux_area = aux++; in mxt_read_t100_config()
1971 dev_dbg(&client->dev, in mxt_read_t100_config()
1973 data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area); in mxt_read_t100_config()
1986 input_dev->name = "Atmel maXTouch Touchpad"; in mxt_set_up_as_touchpad()
1988 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); in mxt_set_up_as_touchpad()
1997 for (i = 0; i < data->t19_num_keys; i++) in mxt_set_up_as_touchpad()
1998 if (data->t19_keymap[i] != KEY_RESERVED) in mxt_set_up_as_touchpad()
2000 data->t19_keymap[i]); in mxt_set_up_as_touchpad()
2005 struct device *dev = &data->client->dev; in mxt_initialize_input_device()
2011 switch (data->multitouch) { in mxt_initialize_input_device()
2013 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; in mxt_initialize_input_device()
2020 num_mt_slots = data->num_touchids; in mxt_initialize_input_device()
2028 return -EINVAL; in mxt_initialize_input_device()
2032 if (data->max_x == 0) in mxt_initialize_input_device()
2033 data->max_x = 1023; in mxt_initialize_input_device()
2035 if (data->max_y == 0) in mxt_initialize_input_device()
2036 data->max_y = 1023; in mxt_initialize_input_device()
2038 if (data->xy_switch) in mxt_initialize_input_device()
2039 swap(data->max_x, data->max_y); in mxt_initialize_input_device()
2041 dev_info(dev, "Touchscreen size X%uY%u\n", data->max_x, data->max_y); in mxt_initialize_input_device()
2046 return -ENOMEM; in mxt_initialize_input_device()
2048 input_dev->name = "Atmel maXTouch Touchscreen"; in mxt_initialize_input_device()
2049 input_dev->phys = data->phys; in mxt_initialize_input_device()
2050 input_dev->id.bustype = BUS_I2C; in mxt_initialize_input_device()
2051 input_dev->dev.parent = dev; in mxt_initialize_input_device()
2052 input_dev->open = mxt_input_open; in mxt_initialize_input_device()
2053 input_dev->close = mxt_input_close; in mxt_initialize_input_device()
2057 /* For single touch */ in mxt_initialize_input_device()
2058 input_set_abs_params(input_dev, ABS_X, 0, data->max_x, 0, 0); in mxt_initialize_input_device()
2059 input_set_abs_params(input_dev, ABS_Y, 0, data->max_y, 0, 0); in mxt_initialize_input_device()
2061 if (data->multitouch == MXT_TOUCH_MULTI_T9 || in mxt_initialize_input_device()
2062 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && in mxt_initialize_input_device()
2063 data->t100_aux_ampl)) { in mxt_initialize_input_device()
2068 if (data->t19_num_keys) { in mxt_initialize_input_device()
2075 /* For multi touch */ in mxt_initialize_input_device()
2082 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100) { in mxt_initialize_input_device()
2092 0, data->max_x, 0, 0); in mxt_initialize_input_device()
2094 0, data->max_y, 0, 0); in mxt_initialize_input_device()
2096 if (data->multitouch == MXT_TOUCH_MULTI_T9 || in mxt_initialize_input_device()
2097 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && in mxt_initialize_input_device()
2098 data->t100_aux_area)) { in mxt_initialize_input_device()
2103 if (data->multitouch == MXT_TOUCH_MULTI_T9 || in mxt_initialize_input_device()
2104 (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && in mxt_initialize_input_device()
2105 data->t100_aux_ampl)) { in mxt_initialize_input_device()
2110 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && in mxt_initialize_input_device()
2111 data->t100_aux_vect) { in mxt_initialize_input_device()
2116 if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && in mxt_initialize_input_device()
2117 data->t100_aux_vect) { in mxt_initialize_input_device()
2130 data->input_dev = input_dev; in mxt_initialize_input_device()
2150 struct i2c_client *client = data->client; in mxt_initialize()
2162 dev_info(&client->dev, "Trying alternate bootloader address\n"); in mxt_initialize()
2172 dev_err(&client->dev, "Could not recover from bootloader mode\n"); in mxt_initialize()
2177 data->in_bootloader = true; in mxt_initialize()
2195 &client->dev, GFP_KERNEL, data, in mxt_initialize()
2198 dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", in mxt_initialize()
2208 struct device *dev = &data->client->dev; in mxt_set_t7_power_cfg()
2216 new_config = &data->t7_cfg; in mxt_set_t7_power_cfg()
2218 error = __mxt_write_reg(data->client, data->T7_address, in mxt_set_t7_power_cfg()
2219 sizeof(data->t7_cfg), new_config); in mxt_set_t7_power_cfg()
2224 new_config->active, new_config->idle); in mxt_set_t7_power_cfg()
2231 struct device *dev = &data->client->dev; in mxt_init_t7_power_cfg()
2236 error = __mxt_read_reg(data->client, data->T7_address, in mxt_init_t7_power_cfg()
2237 sizeof(data->t7_cfg), &data->t7_cfg); in mxt_init_t7_power_cfg()
2241 if (data->t7_cfg.active == 0 || data->t7_cfg.idle == 0) { in mxt_init_t7_power_cfg()
2249 data->t7_cfg.active = 20; in mxt_init_t7_power_cfg()
2250 data->t7_cfg.idle = 100; in mxt_init_t7_power_cfg()
2256 data->t7_cfg.active, data->t7_cfg.idle); in mxt_init_t7_power_cfg()
2274 struct mxt_info *info = data->info; in mxt_get_debug_value()
2275 struct mxt_dbg *dbg = &data->dbg; in mxt_get_debug_value()
2280 if (info->family_id == MXT_FAMILY_1386) { in mxt_get_debug_value()
2281 col_width = info->matrix_ysize / MXT1386_COLUMNS; in mxt_get_debug_value()
2285 col_width = info->matrix_ysize; in mxt_get_debug_value()
2292 if (info->family_id == MXT_FAMILY_1386) in mxt_get_debug_value()
2295 return get_unaligned_le16(&dbg->t37_buf[page].data[ofs]); in mxt_get_debug_value()
2300 struct mxt_dbg *dbg = &data->dbg; in mxt_convert_debug_pages()
2305 for (i = 0; i < dbg->t37_nodes; i++) { in mxt_convert_debug_pages()
2307 rx = data->xy_switch ? y : x; in mxt_convert_debug_pages()
2308 ry = data->xy_switch ? x : y; in mxt_convert_debug_pages()
2309 rx = data->invertx ? (data->xsize - 1 - rx) : rx; in mxt_convert_debug_pages()
2310 ry = data->inverty ? (data->ysize - 1 - ry) : ry; in mxt_convert_debug_pages()
2315 if (++x >= (data->xy_switch ? data->ysize : data->xsize)) { in mxt_convert_debug_pages()
2327 struct mxt_dbg *dbg = &data->dbg; in mxt_read_diagnostic_debug()
2335 for (page = 0; page < dbg->t37_pages; page++) { in mxt_read_diagnostic_debug()
2336 p = dbg->t37_buf + page; in mxt_read_diagnostic_debug()
2338 ret = mxt_write_reg(data->client, dbg->diag_cmd_address, in mxt_read_diagnostic_debug()
2347 ret = __mxt_read_reg(data->client, dbg->diag_cmd_address, in mxt_read_diagnostic_debug()
2355 return -EINVAL; in mxt_read_diagnostic_debug()
2362 ret = __mxt_read_reg(data->client, dbg->t37_address, in mxt_read_diagnostic_debug()
2367 if (p->mode != mode || p->page != page) { in mxt_read_diagnostic_debug()
2368 dev_err(&data->client->dev, "T37 page mismatch\n"); in mxt_read_diagnostic_debug()
2369 return -EINVAL; in mxt_read_diagnostic_debug()
2372 dev_dbg(&data->client->dev, "%s page:%d retries:%d\n", in mxt_read_diagnostic_debug()
2386 struct mxt_data *data = q->drv_priv; in mxt_queue_setup()
2387 size_t size = data->dbg.t37_nodes * sizeof(u16); in mxt_queue_setup()
2390 return sizes[0] < size ? -EINVAL : 0; in mxt_queue_setup()
2400 struct mxt_data *data = vb2_get_drv_priv(vb->vb2_queue); in mxt_buffer_queue()
2407 dev_err(&data->client->dev, "Error acquiring frame ptr\n"); in mxt_buffer_queue()
2411 switch (data->dbg.input) { in mxt_buffer_queue()
2426 vb2_set_plane_payload(vb, 0, data->dbg.t37_nodes * sizeof(u16)); in mxt_buffer_queue()
2457 strlcpy(cap->driver, "atmel_mxt_ts", sizeof(cap->driver)); in mxt_vidioc_querycap()
2458 strlcpy(cap->card, "atmel_mxt_ts touch", sizeof(cap->card)); in mxt_vidioc_querycap()
2459 snprintf(cap->bus_info, sizeof(cap->bus_info), in mxt_vidioc_querycap()
2460 "I2C:%s", dev_name(&data->client->dev)); in mxt_vidioc_querycap()
2467 if (i->index >= MXT_V4L_INPUT_MAX) in mxt_vidioc_enum_input()
2468 return -EINVAL; in mxt_vidioc_enum_input()
2470 i->type = V4L2_INPUT_TYPE_TOUCH; in mxt_vidioc_enum_input()
2472 switch (i->index) { in mxt_vidioc_enum_input()
2474 strlcpy(i->name, "Mutual Capacitance References", in mxt_vidioc_enum_input()
2475 sizeof(i->name)); in mxt_vidioc_enum_input()
2478 strlcpy(i->name, "Mutual Capacitance Deltas", sizeof(i->name)); in mxt_vidioc_enum_input()
2487 struct v4l2_pix_format *f = &data->dbg.format; in mxt_set_input()
2490 return -EINVAL; in mxt_set_input()
2493 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in mxt_set_input()
2495 f->pixelformat = V4L2_TCH_FMT_TU16; in mxt_set_input()
2497 f->width = data->xy_switch ? data->ysize : data->xsize; in mxt_set_input()
2498 f->height = data->xy_switch ? data->xsize : data->ysize; in mxt_set_input()
2499 f->field = V4L2_FIELD_NONE; in mxt_set_input()
2500 f->colorspace = V4L2_COLORSPACE_RAW; in mxt_set_input()
2501 f->bytesperline = f->width * sizeof(u16); in mxt_set_input()
2502 f->sizeimage = f->width * f->height * sizeof(u16); in mxt_set_input()
2504 data->dbg.input = i; in mxt_set_input()
2518 *i = data->dbg.input; in mxt_vidioc_g_input()
2527 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in mxt_vidioc_fmt()
2528 f->fmt.pix = data->dbg.format; in mxt_vidioc_fmt()
2536 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in mxt_vidioc_enum_fmt()
2537 return -EINVAL; in mxt_vidioc_enum_fmt()
2539 switch (fmt->index) { in mxt_vidioc_enum_fmt()
2541 fmt->pixelformat = V4L2_TCH_FMT_TU16; in mxt_vidioc_enum_fmt()
2545 fmt->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in mxt_vidioc_enum_fmt()
2549 return -EINVAL; in mxt_vidioc_enum_fmt()
2558 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in mxt_vidioc_g_parm()
2559 return -EINVAL; in mxt_vidioc_g_parm()
2561 a->parm.capture.readbuffers = 1; in mxt_vidioc_g_parm()
2562 a->parm.capture.timeperframe.numerator = 1; in mxt_vidioc_g_parm()
2563 a->parm.capture.timeperframe.denominator = 10; in mxt_vidioc_g_parm()
2602 struct mxt_info *info = data->info; in mxt_debug_init()
2603 struct mxt_dbg *dbg = &data->dbg; in mxt_debug_init()
2611 dbg->diag_cmd_address = object->start_address + MXT_COMMAND_DIAGNOSTIC; in mxt_debug_init()
2618 dev_warn(&data->client->dev, "Bad T37 size"); in mxt_debug_init()
2622 dbg->t37_address = object->start_address; in mxt_debug_init()
2625 dbg->t37_nodes = data->xsize * data->ysize; in mxt_debug_init()
2627 if (info->family_id == MXT_FAMILY_1386) in mxt_debug_init()
2628 dbg->t37_pages = MXT1386_COLUMNS * MXT1386_PAGES_PER_COLUMN; in mxt_debug_init()
2630 dbg->t37_pages = DIV_ROUND_UP(data->xsize * in mxt_debug_init()
2631 info->matrix_ysize * in mxt_debug_init()
2633 sizeof(dbg->t37_buf->data)); in mxt_debug_init()
2635 dbg->t37_buf = devm_kmalloc_array(&data->client->dev, dbg->t37_pages, in mxt_debug_init()
2637 if (!dbg->t37_buf) in mxt_debug_init()
2644 snprintf(dbg->v4l2.name, sizeof(dbg->v4l2.name), "%s", "atmel_mxt_ts"); in mxt_debug_init()
2645 error = v4l2_device_register(&data->client->dev, &dbg->v4l2); in mxt_debug_init()
2650 mutex_init(&dbg->lock); in mxt_debug_init()
2651 dbg->queue = mxt_queue; in mxt_debug_init()
2652 dbg->queue.drv_priv = data; in mxt_debug_init()
2653 dbg->queue.lock = &dbg->lock; in mxt_debug_init()
2654 dbg->queue.dev = &data->client->dev; in mxt_debug_init()
2656 error = vb2_queue_init(&dbg->queue); in mxt_debug_init()
2660 dbg->vdev = mxt_video_device; in mxt_debug_init()
2661 dbg->vdev.v4l2_dev = &dbg->v4l2; in mxt_debug_init()
2662 dbg->vdev.lock = &dbg->lock; in mxt_debug_init()
2663 dbg->vdev.vfl_dir = VFL_DIR_RX; in mxt_debug_init()
2664 dbg->vdev.queue = &dbg->queue; in mxt_debug_init()
2665 video_set_drvdata(&dbg->vdev, data); in mxt_debug_init()
2667 error = video_register_device(&dbg->vdev, VFL_TYPE_TOUCH, -1); in mxt_debug_init()
2674 v4l2_device_unregister(&dbg->v4l2); in mxt_debug_init()
2676 dev_warn(&data->client->dev, "Error initializing T37\n"); in mxt_debug_init()
2687 struct device *dev = &data->client->dev; in mxt_configure_objects()
2702 if (data->multitouch) { in mxt_configure_objects()
2707 dev_warn(dev, "No touch object detected\n"); in mxt_configure_objects()
2720 struct mxt_info *info = data->info; in mxt_fw_version_show()
2722 info->version >> 4, info->version & 0xf, info->build); in mxt_fw_version_show()
2730 struct mxt_info *info = data->info; in mxt_hw_version_show()
2732 info->family_id, info->variant_id); in mxt_hw_version_show()
2742 count += scnprintf(buf + count, PAGE_SIZE - count, in mxt_show_instance()
2746 count += scnprintf(buf + count, PAGE_SIZE - count, in mxt_show_instance()
2748 count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); in mxt_show_instance()
2763 /* Pre-allocate buffer large enough to hold max sized object. */ in mxt_object_show()
2766 return -ENOMEM; in mxt_object_show()
2769 for (i = 0; i < data->info->object_num; i++) { in mxt_object_show()
2770 object = data->object_table + i; in mxt_object_show()
2772 if (!mxt_object_readable(object->type)) in mxt_object_show()
2775 count += scnprintf(buf + count, PAGE_SIZE - count, in mxt_object_show()
2776 "T%u:\n", object->type); in mxt_object_show()
2780 u16 addr = object->start_address + j * size; in mxt_object_show()
2782 error = __mxt_read_reg(data->client, addr, size, obuf); in mxt_object_show()
2801 while (pos < fw->size) { in mxt_check_firmware_format()
2802 c = *(fw->data + pos); in mxt_check_firmware_format()
2812 * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw in mxt_check_firmware_format()
2816 return -EINVAL; in mxt_check_firmware_format()
2840 if (!data->in_bootloader) { in mxt_load_fw()
2842 data->in_bootloader = true; in mxt_load_fw()
2859 enable_irq(data->irq); in mxt_load_fw()
2862 reinit_completion(&data->bl_completion); in mxt_load_fw()
2879 while (pos < fw->size) { in mxt_load_fw()
2884 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); in mxt_load_fw()
2890 ret = mxt_bootloader_write(data, fw->data + pos, frame_size); in mxt_load_fw()
2913 frame, pos, fw->size); in mxt_load_fw()
2917 ret = mxt_wait_for_completion(data, &data->bl_completion, in mxt_load_fw()
2929 mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); in mxt_load_fw()
2931 data->in_bootloader = false; in mxt_load_fw()
2934 disable_irq(data->irq); in mxt_load_fw()
2981 switch (data->suspend_mode) { in mxt_start()
2985 /* Touch enable */ in mxt_start()
2995 /* Recalibrate since chip has been in deep sleep */ in mxt_start()
3003 switch (data->suspend_mode) { in mxt_stop()
3005 /* Touch disable */ in mxt_stop()
3035 static const char keymap_property[] = "linux,gpio-keymap"; in mxt_parse_device_properties()
3036 struct device *dev = &data->client->dev; in mxt_parse_device_properties()
3044 error = n_keys < 0 ? n_keys : -EINVAL; in mxt_parse_device_properties()
3053 return -ENOMEM; in mxt_parse_device_properties()
3063 data->t19_keymap = keymap; in mxt_parse_device_properties()
3064 data->t19_num_keys = n_keys; in mxt_parse_device_properties()
3093 * touch screen or touchpad. in mxt_probe()
3095 * So far on x86 the only users of Atmel touch controllers are in mxt_probe()
3099 if (!device_property_present(&client->dev, "compatible")) in mxt_probe()
3100 return -ENXIO; in mxt_probe()
3112 if (ACPI_COMPANION(&client->dev) && client->addr < 0x40) in mxt_probe()
3113 return -ENXIO; in mxt_probe()
3115 data = devm_kzalloc(&client->dev, sizeof(struct mxt_data), GFP_KERNEL); in mxt_probe()
3117 return -ENOMEM; in mxt_probe()
3119 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", in mxt_probe()
3120 client->adapter->nr, client->addr); in mxt_probe()
3122 data->client = client; in mxt_probe()
3123 data->irq = client->irq; in mxt_probe()
3126 init_completion(&data->bl_completion); in mxt_probe()
3127 init_completion(&data->reset_completion); in mxt_probe()
3128 init_completion(&data->crc_completion); in mxt_probe()
3130 data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ? in mxt_probe()
3137 data->reset_gpio = devm_gpiod_get_optional(&client->dev, in mxt_probe()
3139 if (IS_ERR(data->reset_gpio)) { in mxt_probe()
3140 error = PTR_ERR(data->reset_gpio); in mxt_probe()
3141 dev_err(&client->dev, "Failed to get reset gpio: %d\n", error); in mxt_probe()
3145 error = devm_request_threaded_irq(&client->dev, client->irq, in mxt_probe()
3147 client->name, data); in mxt_probe()
3149 dev_err(&client->dev, "Failed to register interrupt\n"); in mxt_probe()
3153 disable_irq(client->irq); in mxt_probe()
3155 if (data->reset_gpio) { in mxt_probe()
3157 gpiod_set_value(data->reset_gpio, 1); in mxt_probe()
3165 error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); in mxt_probe()
3167 dev_err(&client->dev, "Failure %d creating sysfs group\n", in mxt_probe()
3184 disable_irq(data->irq); in mxt_remove()
3185 sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); in mxt_remove()
3196 struct input_dev *input_dev = data->input_dev; in mxt_suspend()
3201 mutex_lock(&input_dev->mutex); in mxt_suspend()
3203 if (input_dev->users) in mxt_suspend()
3206 mutex_unlock(&input_dev->mutex); in mxt_suspend()
3208 disable_irq(data->irq); in mxt_suspend()
3217 struct input_dev *input_dev = data->input_dev; in mxt_resume()
3222 enable_irq(data->irq); in mxt_resume()
3224 mutex_lock(&input_dev->mutex); in mxt_resume()
3226 if (input_dev->users) in mxt_resume()
3229 mutex_unlock(&input_dev->mutex); in mxt_resume()