Source
x
/*
* Cypress APA trackpad with I2C interface
*
* Author: Dudley Du <dudl@cypress.com>
*
* Copyright (C) 2014-2015 Cypress Semiconductor, Inc.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*/
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/input/mt.h>
#include <linux/mutex.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <asm/unaligned.h>
#include <linux/crc-itu-t.h>
#include <linux/pm_runtime.h>
#include "cyapa.h"
/* Macro of TSG firmware image */
#define CYAPA_TSG_FLASH_MAP_BLOCK_SIZE 0x80
#define CYAPA_TSG_IMG_FW_HDR_SIZE 13
#define CYAPA_TSG_FW_ROW_SIZE (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE)
#define CYAPA_TSG_IMG_START_ROW_NUM 0x002e
#define CYAPA_TSG_IMG_END_ROW_NUM 0x01fe
#define CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM 0x01ff
#define CYAPA_TSG_IMG_MAX_RECORDS (CYAPA_TSG_IMG_END_ROW_NUM - \
CYAPA_TSG_IMG_START_ROW_NUM + 1 + 1)
#define CYAPA_TSG_IMG_READ_SIZE (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE / 2)
#define CYAPA_TSG_START_OF_APPLICATION 0x1700
#define CYAPA_TSG_APP_INTEGRITY_SIZE 60
#define CYAPA_TSG_FLASH_MAP_METADATA_SIZE 60
#define CYAPA_TSG_BL_KEY_SIZE 8
#define CYAPA_TSG_MAX_CMD_SIZE 256
/* Macro of PIP interface */
#define PIP_BL_INITIATE_RESP_LEN 11
#define PIP_BL_FAIL_EXIT_RESP_LEN 11
#define PIP_BL_FAIL_EXIT_STATUS_CODE 0x0c
#define PIP_BL_VERIFY_INTEGRITY_RESP_LEN 12
#define PIP_BL_INTEGRITY_CHEKC_PASS 0x00
#define PIP_BL_BLOCK_WRITE_RESP_LEN 11
#define PIP_TOUCH_REPORT_ID 0x01
#define PIP_BTN_REPORT_ID 0x03
#define PIP_WAKEUP_EVENT_REPORT_ID 0x04
#define PIP_PUSH_BTN_REPORT_ID 0x06
#define GEN5_OLD_PUSH_BTN_REPORT_ID 0x05 /* Special for old Gen5 TP. */
#define PIP_PROXIMITY_REPORT_ID 0x07
#define PIP_PROXIMITY_REPORT_SIZE 6
#define PIP_PROXIMITY_DISTANCE_OFFSET 0x05
#define PIP_PROXIMITY_DISTANCE_MASK 0x01
#define PIP_TOUCH_REPORT_HEAD_SIZE 7
#define PIP_TOUCH_REPORT_MAX_SIZE 127
#define PIP_BTN_REPORT_HEAD_SIZE 6
#define PIP_BTN_REPORT_MAX_SIZE 14
#define PIP_WAKEUP_EVENT_SIZE 4
#define PIP_NUMBER_OF_TOUCH_OFFSET 5
#define PIP_NUMBER_OF_TOUCH_MASK 0x1f
#define PIP_BUTTONS_OFFSET 5
#define PIP_BUTTONS_MASK 0x0f
#define PIP_GET_EVENT_ID(reg) (((reg) >> 5) & 0x03)
#define PIP_GET_TOUCH_ID(reg) ((reg) & 0x1f)
#define PIP_TOUCH_TYPE_FINGER 0x00
#define PIP_TOUCH_TYPE_PROXIMITY 0x01
#define PIP_TOUCH_TYPE_HOVER 0x02
#define PIP_GET_TOUCH_TYPE(reg) ((reg) & 0x07)
#define RECORD_EVENT_NONE 0
#define RECORD_EVENT_TOUCHDOWN 1
#define RECORD_EVENT_DISPLACE 2
#define RECORD_EVENT_LIFTOFF 3
#define PIP_SENSING_MODE_MUTUAL_CAP_FINE 0x00
#define PIP_SENSING_MODE_SELF_CAP 0x02
#define PIP_SET_PROXIMITY 0x49
/* Macro of Gen5 */
#define GEN5_BL_MAX_OUTPUT_LENGTH 0x0100
#define GEN5_APP_MAX_OUTPUT_LENGTH 0x00fe