Lines Matching +full:mode +full:- +full:bootloader
9 * Copyright (C) 2011-2015 Cypress Semiconductor, Inc.
10 * Copyright (C) 2011-2012 Google, Inc.
60 * Used in register 0x00, bit1-0, DeviceStatus field.
88 * bit 7 - 4: high 4 bits of x position value
89 * bit 3 - 0: high 4 bits of y position value
95 /* id range is 1 - 15. It is incremented with every new touch. */
101 * bit 0 - 1: device status
102 * bit 3 - 2: power mode
103 * bit 6 - 4: reserved
108 * bit 7 - 4: number of fingers currently touching pad
122 u8 key[8]; /* 8-byte security key */
125 u8 block_checksum; /* Calculated using bytes 12 - 75 */
126 u8 cmd_checksum; /* Calculated using bytes 0-76 */
171 /* register block read/write command in bootloader mode */
178 /* register block read/write command in operational mode */
232 * cyapa_smbus_read_block - perform smbus block read command
233 * @cyapa - private data structure of the driver
234 * @cmd - the properly encoded smbus command
235 * @len - expected length of smbus command result
236 * @values - buffer to store smbus command result
251 struct i2c_client *client = cyapa->client; in cyapa_smbus_read_block()
254 return -EINVAL; in cyapa_smbus_read_block()
281 if (cyapa->smbus) { in cyapa_read_byte()
287 return i2c_smbus_read_byte_data(cyapa->client, cmd); in cyapa_read_byte()
294 if (cyapa->smbus) { in cyapa_write_byte()
300 return i2c_smbus_write_byte_data(cyapa->client, cmd, value); in cyapa_write_byte()
306 return i2c_smbus_read_i2c_block_data(cyapa->client, reg, len, values); in cyapa_i2c_reg_read_block()
312 return i2c_smbus_write_i2c_block_data(cyapa->client, reg, len, values); in cyapa_i2c_reg_write_block()
320 if (cyapa->smbus) { in cyapa_read_block()
336 cyapa->state = CYAPA_STATE_NO_DEVICE; in cyapa_gen3_state_parse()
349 cyapa->gen = CYAPA_GEN3; in cyapa_gen3_state_parse()
350 cyapa->state = CYAPA_STATE_BL_IDLE; in cyapa_gen3_state_parse()
354 cyapa->gen = CYAPA_GEN3; in cyapa_gen3_state_parse()
356 cyapa->state = CYAPA_STATE_BL_BUSY; in cyapa_gen3_state_parse()
360 cyapa->state = CYAPA_STATE_BL_ACTIVE; in cyapa_gen3_state_parse()
362 cyapa->state = CYAPA_STATE_BL_IDLE; in cyapa_gen3_state_parse()
367 * Normal state when running in operational mode, in cyapa_gen3_state_parse()
374 cyapa->gen = CYAPA_GEN3; in cyapa_gen3_state_parse()
375 cyapa->state = CYAPA_STATE_OP; in cyapa_gen3_state_parse()
380 cyapa->gen = CYAPA_GEN3; in cyapa_gen3_state_parse()
381 cyapa->state = CYAPA_STATE_OP; in cyapa_gen3_state_parse()
384 cyapa->gen = CYAPA_GEN3; in cyapa_gen3_state_parse()
385 cyapa->state = CYAPA_STATE_BL_BUSY; in cyapa_gen3_state_parse()
388 if (cyapa->gen == CYAPA_GEN3 && (cyapa->state == CYAPA_STATE_OP || in cyapa_gen3_state_parse()
389 cyapa->state == CYAPA_STATE_BL_IDLE || in cyapa_gen3_state_parse()
390 cyapa->state == CYAPA_STATE_BL_ACTIVE || in cyapa_gen3_state_parse()
391 cyapa->state == CYAPA_STATE_BL_BUSY)) in cyapa_gen3_state_parse()
394 return -EAGAIN; in cyapa_gen3_state_parse()
398 * Enter bootloader by soft resetting the device.
400 * If device is already in the bootloader, the function just returns.
401 * Otherwise, reset the device; after reset, device enters bootloader idle
406 * -EAGAIN device was reset, but is not now in bootloader idle state
417 if (cyapa->state == CYAPA_STATE_BL_IDLE) { in cyapa_gen3_bl_enter()
422 if (cyapa->state != CYAPA_STATE_OP) in cyapa_gen3_bl_enter()
423 return -EAGAIN; in cyapa_gen3_bl_enter()
425 cyapa->operational = false; in cyapa_gen3_bl_enter()
426 cyapa->state = CYAPA_STATE_NO_DEVICE; in cyapa_gen3_bl_enter()
429 return -EIO; in cyapa_gen3_bl_enter()
436 if (error == -ETIMEDOUT) { in cyapa_gen3_bl_enter()
437 waiting_time -= 500; in cyapa_gen3_bl_enter()
443 if ((cyapa->state == CYAPA_STATE_BL_IDLE) && in cyapa_gen3_bl_enter()
444 !(cyapa->status[REG_BL_STATUS] & BL_STATUS_WATCHDOG)) in cyapa_gen3_bl_enter()
448 waiting_time -= 100; in cyapa_gen3_bl_enter()
451 if ((cyapa->state != CYAPA_STATE_BL_IDLE) || in cyapa_gen3_bl_enter()
452 (cyapa->status[REG_BL_STATUS] & BL_STATUS_WATCHDOG)) in cyapa_gen3_bl_enter()
453 return -EAGAIN; in cyapa_gen3_bl_enter()
467 /* Wait for bootloader to activate; takes between 2 and 12 seconds */ in cyapa_gen3_bl_activate()
472 if (cyapa->state != CYAPA_STATE_BL_ACTIVE) in cyapa_gen3_bl_activate()
473 return -EAGAIN; in cyapa_gen3_bl_activate()
487 /* Wait for bootloader to switch to idle state; should take < 100ms */ in cyapa_gen3_bl_deactivate()
492 if (cyapa->state != CYAPA_STATE_BL_IDLE) in cyapa_gen3_bl_deactivate()
493 return -EAGAIN; in cyapa_gen3_bl_deactivate()
498 * Exit bootloader
500 * Send bl_exit command, then wait 50 - 100 ms to let device transition to
501 * operational mode. If this is the first time the device's firmware is
506 * -EIO failure while reading from device
507 * -EAGAIN device is stuck in bootloader, b/c it has invalid firmware
508 * 0 device is supported and in operational mode
519 * Wait for bootloader to exit, and operation mode to start. in cyapa_gen3_bl_exit()
532 if (cyapa->state != CYAPA_STATE_OP) in cyapa_gen3_bl_exit()
533 return -EAGAIN; in cyapa_gen3_bl_exit()
552 * The firmware image file is 30848 bytes, composed of 482 64-byte blocks.
562 * Both checksums are stored little-endian.
566 struct device *dev = &cyapa->client->dev; in cyapa_gen3_check_fw()
570 /* Firmware must match exact 30848 bytes = 482 64-byte blocks. */ in cyapa_gen3_check_fw()
571 if (fw->size != CYAPA_FW_SIZE) { in cyapa_gen3_check_fw()
573 fw->size, CYAPA_FW_SIZE); in cyapa_gen3_check_fw()
574 return -EINVAL; in cyapa_gen3_check_fw()
578 csum_expected = (fw->data[0] << 8) | fw->data[1]; in cyapa_gen3_check_fw()
579 csum = cyapa_gen3_csum(&fw->data[2], CYAPA_FW_HDR_SIZE - 2); in cyapa_gen3_check_fw()
584 return -EINVAL; in cyapa_gen3_check_fw()
588 csum_expected = (fw->data[CYAPA_FW_HDR_SIZE - 2] << 8) | in cyapa_gen3_check_fw()
589 fw->data[CYAPA_FW_HDR_SIZE - 1]; in cyapa_gen3_check_fw()
590 csum = cyapa_gen3_csum(&fw->data[CYAPA_FW_HDR_SIZE], in cyapa_gen3_check_fw()
596 return -EINVAL; in cyapa_gen3_check_fw()
603 * sequence of smaller |CYAPA_CMD_LEN|-length write commands.
605 * The data bytes for a write command are prepended with the 1-byte offset
619 cmd_len = (len - i >= CYAPA_CMD_LEN) ? CYAPA_CMD_LEN : len - i; in cyapa_gen3_write_buffer()
632 * page in the device. The 78-byte block write command has the format:
633 * <0xff> <CMD> <Key> <Start> <Data> <Data-Checksum> <CMD Checksum>
635 * <0xff> - every command starts with 0xff
636 * <CMD> - the write command value is 0x39
637 * <Key> - write commands include an 8-byte key: { 00 01 02 03 04 05 06 07 }
638 * <Block> - Memory Block number (address / 64) (16-bit, big-endian)
639 * <Data> - 64 bytes of firmware image data
640 * <Data Checksum> - sum of 64 <Data> bytes, modulo 0xff
641 * <CMD Checksum> - sum of 77 bytes, from 0xff to <Data Checksum>
664 sizeof(write_block_cmd) - 1); in cyapa_gen3_write_fw_block()
680 return (ret < 0) ? ret : -EIO; in cyapa_gen3_write_fw_block()
681 } while ((status[REG_BL_STATUS] & BL_STATUS_BUSY) && --tries); in cyapa_gen3_write_fw_block()
688 ret = -ETIMEDOUT; in cyapa_gen3_write_fw_block()
691 ret = -EIO; in cyapa_gen3_write_fw_block()
720 struct device *dev = &cyapa->client->dev; in cyapa_gen3_do_fw_update()
723 /* First write data, starting at byte 128 of fw->data */ in cyapa_gen3_do_fw_update()
726 &fw->data[CYAPA_FW_HDR_BLOCK_COUNT * CYAPA_FW_BLOCK_SIZE]); in cyapa_gen3_do_fw_update()
735 &fw->data[0]); in cyapa_gen3_do_fw_update()
760 ret = -EAGAIN; in cyapa_gen3_do_calibrate()
777 * The average time is approximately 500 - 700 ms, and we in cyapa_gen3_do_calibrate()
778 * will check the status every 100 - 200ms. in cyapa_gen3_do_calibrate()
793 ret = -ETIMEDOUT; in cyapa_gen3_do_calibrate()
815 ret = -EAGAIN; in cyapa_gen3_show_baseline()
839 } while (--tries); in cyapa_gen3_show_baseline()
843 ret = -ETIMEDOUT; in cyapa_gen3_show_baseline()
873 * power mode. The touchpad needs to consume the incoming power mode set
888 * Set device power mode
905 * Device power mode can only be set when device is in operational mode.
910 struct input_dev *input = cyapa->input; in cyapa_gen3_set_power_mode()
917 if (cyapa->state != CYAPA_STATE_OP) in cyapa_gen3_set_power_mode()
921 while (tries--) { in cyapa_gen3_set_power_mode()
931 * Return early if the power mode to set is the same as the current in cyapa_gen3_set_power_mode()
942 while (tries--) { in cyapa_gen3_set_power_mode()
955 if (cyapa->operational && in cyapa_gen3_set_power_mode()
966 sleep_time -= interval; in cyapa_gen3_set_power_mode()
978 return -EOPNOTSUPP; in cyapa_gen3_set_proximity()
986 if (cyapa->state != CYAPA_STATE_OP) in cyapa_gen3_get_query_data()
987 return -EBUSY; in cyapa_gen3_get_query_data()
991 return (ret < 0) ? ret : -EIO; in cyapa_gen3_get_query_data()
993 memcpy(&cyapa->product_id[0], &query_data[0], 5); in cyapa_gen3_get_query_data()
994 cyapa->product_id[5] = '-'; in cyapa_gen3_get_query_data()
995 memcpy(&cyapa->product_id[6], &query_data[5], 6); in cyapa_gen3_get_query_data()
996 cyapa->product_id[12] = '-'; in cyapa_gen3_get_query_data()
997 memcpy(&cyapa->product_id[13], &query_data[11], 2); in cyapa_gen3_get_query_data()
998 cyapa->product_id[15] = '\0'; in cyapa_gen3_get_query_data()
1000 cyapa->fw_maj_ver = query_data[15]; in cyapa_gen3_get_query_data()
1001 cyapa->fw_min_ver = query_data[16]; in cyapa_gen3_get_query_data()
1003 cyapa->btn_capability = query_data[19] & CAPABILITY_BTN_MASK; in cyapa_gen3_get_query_data()
1005 cyapa->gen = query_data[20] & 0x0f; in cyapa_gen3_get_query_data()
1007 cyapa->max_abs_x = ((query_data[21] & 0xf0) << 4) | query_data[22]; in cyapa_gen3_get_query_data()
1008 cyapa->max_abs_y = ((query_data[21] & 0x0f) << 8) | query_data[23]; in cyapa_gen3_get_query_data()
1010 cyapa->physical_size_x = in cyapa_gen3_get_query_data()
1012 cyapa->physical_size_y = in cyapa_gen3_get_query_data()
1015 cyapa->max_z = 255; in cyapa_gen3_get_query_data()
1027 return (ret < 0) ? ret : -EIO; in cyapa_gen3_bl_query_data()
1030 * This value will be updated again when entered application mode. in cyapa_gen3_bl_query_data()
1031 * If TP failed to enter application mode, this fw version values in cyapa_gen3_bl_query_data()
1037 cyapa->fw_maj_ver = bl_data[GEN3_BL_IDLE_FW_MAJ_VER_OFFSET]; in cyapa_gen3_bl_query_data()
1038 cyapa->fw_min_ver = bl_data[GEN3_BL_IDLE_FW_MIN_VER_OFFSET]; in cyapa_gen3_bl_query_data()
1047 * An operational device is responding, has exited bootloader, and has
1051 * -EBUSY no device or in bootloader
1052 * -EIO failure while reading from device
1053 * -EAGAIN device is still in bootloader
1054 * if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
1055 * -EINVAL device is in operational mode, but not supported by this driver
1060 struct device *dev = &cyapa->client->dev; in cyapa_gen3_do_operational_check()
1063 switch (cyapa->state) { in cyapa_gen3_do_operational_check()
1073 /* Try to get firmware version in bootloader mode. */ in cyapa_gen3_do_operational_check()
1085 * Reading query data before going back to the full mode in cyapa_gen3_do_operational_check()
1086 * may cause problems, so we set the power mode first here. in cyapa_gen3_do_operational_check()
1091 dev_err(dev, "%s: set full power mode failed: %d\n", in cyapa_gen3_do_operational_check()
1098 if (cyapa->gen != CYAPA_GEN3) { in cyapa_gen3_do_operational_check()
1100 cyapa->gen); in cyapa_gen3_do_operational_check()
1101 return -EINVAL; in cyapa_gen3_do_operational_check()
1105 if (memcmp(cyapa->product_id, product_id, in cyapa_gen3_do_operational_check()
1108 cyapa->product_id); in cyapa_gen3_do_operational_check()
1109 return -EINVAL; in cyapa_gen3_do_operational_check()
1115 return -EIO; in cyapa_gen3_do_operational_check()
1127 if (cyapa->gen != CYAPA_GEN3) in cyapa_gen3_irq_cmd_handler()
1130 if (cyapa->operational) in cyapa_gen3_irq_cmd_handler()
1139 * as touch inputs when gen3 failed to launch into application mode, in cyapa_gen3_irq_cmd_handler()
1140 * which will cause gen3 stays in bootloader mode. in cyapa_gen3_irq_cmd_handler()
1148 struct input_dev *input = cyapa->input; in cyapa_gen3_event_process()
1152 num_fingers = (data->finger_btn >> 4) & 0x0f; in cyapa_gen3_event_process()
1154 const struct cyapa_touch *touch = &data->touches[i]; in cyapa_gen3_event_process()
1155 /* Note: touch->id range is 1 to 15; slots are 0 to 14. */ in cyapa_gen3_event_process()
1156 int slot = touch->id - 1; in cyapa_gen3_event_process()
1161 ((touch->xy_hi & 0xf0) << 4) | touch->x_lo); in cyapa_gen3_event_process()
1163 ((touch->xy_hi & 0x0f) << 8) | touch->y_lo); in cyapa_gen3_event_process()
1164 input_report_abs(input, ABS_MT_PRESSURE, touch->pressure); in cyapa_gen3_event_process()
1169 if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) in cyapa_gen3_event_process()
1171 !!(data->finger_btn & OP_DATA_LEFT_BTN)); in cyapa_gen3_event_process()
1172 if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK) in cyapa_gen3_event_process()
1174 !!(data->finger_btn & OP_DATA_MIDDLE_BTN)); in cyapa_gen3_event_process()
1175 if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK) in cyapa_gen3_event_process()
1177 !!(data->finger_btn & OP_DATA_RIGHT_BTN)); in cyapa_gen3_event_process()
1185 struct device *dev = &cyapa->client->dev; in cyapa_gen3_irq_handler()
1192 return -EINVAL; in cyapa_gen3_irq_handler()
1200 return -EINVAL; in cyapa_gen3_irq_handler()
1209 * mode command was sent. So this function is aimed to avoid the knwon
1219 return -EINVAL; in cyapa_gen3_try_poll_handler()
1224 return -EINVAL; in cyapa_gen3_try_poll_handler()