0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _LINUX_CYTTSP4_CORE_H
0016 #define _LINUX_CYTTSP4_CORE_H
0017
0018 #include <linux/device.h>
0019 #include <linux/err.h>
0020 #include <linux/input.h>
0021 #include <linux/kernel.h>
0022 #include <linux/limits.h>
0023 #include <linux/module.h>
0024 #include <linux/stringify.h>
0025 #include <linux/types.h>
0026 #include <linux/platform_data/cyttsp4.h>
0027
0028 #define CY_REG_BASE 0x00
0029
0030 #define CY_POST_CODEL_WDG_RST 0x01
0031 #define CY_POST_CODEL_CFG_DATA_CRC_FAIL 0x02
0032 #define CY_POST_CODEL_PANEL_TEST_FAIL 0x04
0033
0034 #define CY_NUM_BTN_PER_REG 4
0035
0036
0037 #define CY_BYTE_OFS_MASK 0x1F
0038 #define CY_BOFS_MASK 0xE0
0039 #define CY_BOFS_SHIFT 5
0040
0041 #define CY_TMA1036_TCH_REC_SIZE 6
0042 #define CY_TMA4XX_TCH_REC_SIZE 9
0043 #define CY_TMA1036_MAX_TCH 0x0E
0044 #define CY_TMA4XX_MAX_TCH 0x1E
0045
0046 #define CY_NORMAL_ORIGIN 0
0047 #define CY_INVERT_ORIGIN 1
0048
0049
0050 #define GET_NUM_TOUCHES(x) ((x) & 0x1F)
0051 #define IS_LARGE_AREA(x) ((x) & 0x20)
0052 #define IS_BAD_PKT(x) ((x) & 0x20)
0053 #define IS_BOOTLOADER(hst_mode, reset_detect) \
0054 ((hst_mode) & 0x01 || (reset_detect) != 0)
0055 #define IS_TMO(t) ((t) == 0)
0056
0057
0058 enum cyttsp_cmd_bits {
0059 CY_CMD_COMPLETE = (1 << 6),
0060 };
0061
0062
0063 #define CY_WATCHDOG_TIMEOUT 1000
0064
0065 #define CY_MAX_PRINT_SIZE 512
0066 #ifdef VERBOSE_DEBUG
0067 #define CY_MAX_PRBUF_SIZE PIPE_BUF
0068 #define CY_PR_TRUNCATED " truncated..."
0069 #endif
0070
0071 enum cyttsp4_ic_grpnum {
0072 CY_IC_GRPNUM_RESERVED,
0073 CY_IC_GRPNUM_CMD_REGS,
0074 CY_IC_GRPNUM_TCH_REP,
0075 CY_IC_GRPNUM_DATA_REC,
0076 CY_IC_GRPNUM_TEST_REC,
0077 CY_IC_GRPNUM_PCFG_REC,
0078 CY_IC_GRPNUM_TCH_PARM_VAL,
0079 CY_IC_GRPNUM_TCH_PARM_SIZE,
0080 CY_IC_GRPNUM_RESERVED1,
0081 CY_IC_GRPNUM_RESERVED2,
0082 CY_IC_GRPNUM_OPCFG_REC,
0083 CY_IC_GRPNUM_DDATA_REC,
0084 CY_IC_GRPNUM_MDATA_REC,
0085 CY_IC_GRPNUM_TEST_REGS,
0086 CY_IC_GRPNUM_BTN_KEYS,
0087 CY_IC_GRPNUM_TTHE_REGS,
0088 CY_IC_GRPNUM_NUM
0089 };
0090
0091 enum cyttsp4_int_state {
0092 CY_INT_NONE,
0093 CY_INT_IGNORE = (1 << 0),
0094 CY_INT_MODE_CHANGE = (1 << 1),
0095 CY_INT_EXEC_CMD = (1 << 2),
0096 CY_INT_AWAKE = (1 << 3),
0097 };
0098
0099 enum cyttsp4_mode {
0100 CY_MODE_UNKNOWN,
0101 CY_MODE_BOOTLOADER = (1 << 1),
0102 CY_MODE_OPERATIONAL = (1 << 2),
0103 CY_MODE_SYSINFO = (1 << 3),
0104 CY_MODE_CAT = (1 << 4),
0105 CY_MODE_STARTUP = (1 << 5),
0106 CY_MODE_LOADER = (1 << 6),
0107 CY_MODE_CHANGE_MODE = (1 << 7),
0108 CY_MODE_CHANGED = (1 << 8),
0109 CY_MODE_CMD_COMPLETE = (1 << 9),
0110 };
0111
0112 enum cyttsp4_sleep_state {
0113 SS_SLEEP_OFF,
0114 SS_SLEEP_ON,
0115 SS_SLEEPING,
0116 SS_WAKING,
0117 };
0118
0119 enum cyttsp4_startup_state {
0120 STARTUP_NONE,
0121 STARTUP_QUEUED,
0122 STARTUP_RUNNING,
0123 };
0124
0125 #define CY_NUM_REVCTRL 8
0126 struct cyttsp4_cydata {
0127 u8 ttpidh;
0128 u8 ttpidl;
0129 u8 fw_ver_major;
0130 u8 fw_ver_minor;
0131 u8 revctrl[CY_NUM_REVCTRL];
0132 u8 blver_major;
0133 u8 blver_minor;
0134 u8 jtag_si_id3;
0135 u8 jtag_si_id2;
0136 u8 jtag_si_id1;
0137 u8 jtag_si_id0;
0138 u8 mfgid_sz;
0139 u8 cyito_idh;
0140 u8 cyito_idl;
0141 u8 cyito_verh;
0142 u8 cyito_verl;
0143 u8 ttsp_ver_major;
0144 u8 ttsp_ver_minor;
0145 u8 device_info;
0146 u8 mfg_id[];
0147 } __packed;
0148
0149 struct cyttsp4_test {
0150 u8 post_codeh;
0151 u8 post_codel;
0152 } __packed;
0153
0154 struct cyttsp4_pcfg {
0155 u8 electrodes_x;
0156 u8 electrodes_y;
0157 u8 len_xh;
0158 u8 len_xl;
0159 u8 len_yh;
0160 u8 len_yl;
0161 u8 res_xh;
0162 u8 res_xl;
0163 u8 res_yh;
0164 u8 res_yl;
0165 u8 max_zh;
0166 u8 max_zl;
0167 u8 panel_info0;
0168 } __packed;
0169
0170 struct cyttsp4_tch_rec_params {
0171 u8 loc;
0172 u8 size;
0173 } __packed;
0174
0175 #define CY_NUM_TCH_FIELDS 7
0176 #define CY_NUM_EXT_TCH_FIELDS 3
0177 struct cyttsp4_opcfg {
0178 u8 cmd_ofs;
0179 u8 rep_ofs;
0180 u8 rep_szh;
0181 u8 rep_szl;
0182 u8 num_btns;
0183 u8 tt_stat_ofs;
0184 u8 obj_cfg0;
0185 u8 max_tchs;
0186 u8 tch_rec_size;
0187 struct cyttsp4_tch_rec_params tch_rec_old[CY_NUM_TCH_FIELDS];
0188 u8 btn_rec_size;
0189 u8 btn_diff_ofs;
0190 u8 btn_diff_size;
0191 struct cyttsp4_tch_rec_params tch_rec_new[CY_NUM_EXT_TCH_FIELDS];
0192 } __packed;
0193
0194 struct cyttsp4_sysinfo_ptr {
0195 struct cyttsp4_cydata *cydata;
0196 struct cyttsp4_test *test;
0197 struct cyttsp4_pcfg *pcfg;
0198 struct cyttsp4_opcfg *opcfg;
0199 struct cyttsp4_ddata *ddata;
0200 struct cyttsp4_mdata *mdata;
0201 } __packed;
0202
0203 struct cyttsp4_sysinfo_data {
0204 u8 hst_mode;
0205 u8 reserved;
0206 u8 map_szh;
0207 u8 map_szl;
0208 u8 cydata_ofsh;
0209 u8 cydata_ofsl;
0210 u8 test_ofsh;
0211 u8 test_ofsl;
0212 u8 pcfg_ofsh;
0213 u8 pcfg_ofsl;
0214 u8 opcfg_ofsh;
0215 u8 opcfg_ofsl;
0216 u8 ddata_ofsh;
0217 u8 ddata_ofsl;
0218 u8 mdata_ofsh;
0219 u8 mdata_ofsl;
0220 } __packed;
0221
0222 enum cyttsp4_tch_abs {
0223 CY_TCH_X,
0224 CY_TCH_Y,
0225 CY_TCH_P,
0226 CY_TCH_T,
0227 CY_TCH_E,
0228 CY_TCH_O,
0229 CY_TCH_W,
0230 CY_TCH_MAJ,
0231 CY_TCH_MIN,
0232 CY_TCH_OR,
0233 CY_TCH_NUM_ABS
0234 };
0235
0236 struct cyttsp4_touch {
0237 int abs[CY_TCH_NUM_ABS];
0238 };
0239
0240 struct cyttsp4_tch_abs_params {
0241 size_t ofs;
0242 size_t size;
0243 size_t max;
0244 size_t bofs;
0245 };
0246
0247 struct cyttsp4_sysinfo_ofs {
0248 size_t chip_type;
0249 size_t cmd_ofs;
0250 size_t rep_ofs;
0251 size_t rep_sz;
0252 size_t num_btns;
0253 size_t num_btn_regs;
0254 size_t tt_stat_ofs;
0255 size_t tch_rec_size;
0256 size_t obj_cfg0;
0257 size_t max_tchs;
0258 size_t mode_size;
0259 size_t data_size;
0260 size_t map_sz;
0261 size_t max_x;
0262 size_t x_origin;
0263 size_t max_y;
0264 size_t y_origin;
0265 size_t max_p;
0266 size_t cydata_ofs;
0267 size_t test_ofs;
0268 size_t pcfg_ofs;
0269 size_t opcfg_ofs;
0270 size_t ddata_ofs;
0271 size_t mdata_ofs;
0272 size_t cydata_size;
0273 size_t test_size;
0274 size_t pcfg_size;
0275 size_t opcfg_size;
0276 size_t ddata_size;
0277 size_t mdata_size;
0278 size_t btn_keys_size;
0279 struct cyttsp4_tch_abs_params tch_abs[CY_TCH_NUM_ABS];
0280 size_t btn_rec_size;
0281 size_t btn_diff_ofs;
0282 size_t btn_diff_size;
0283 };
0284
0285 enum cyttsp4_btn_state {
0286 CY_BTN_RELEASED,
0287 CY_BTN_PRESSED,
0288 CY_BTN_NUM_STATE
0289 };
0290
0291 struct cyttsp4_btn {
0292 bool enabled;
0293 int state;
0294 int key_code;
0295 };
0296
0297 struct cyttsp4_sysinfo {
0298 bool ready;
0299 struct cyttsp4_sysinfo_data si_data;
0300 struct cyttsp4_sysinfo_ptr si_ptrs;
0301 struct cyttsp4_sysinfo_ofs si_ofs;
0302 struct cyttsp4_btn *btn;
0303 u8 *btn_rec_data;
0304 u8 *xy_mode;
0305 u8 *xy_data;
0306 };
0307
0308 struct cyttsp4_mt_data {
0309 struct cyttsp4_mt_platform_data *pdata;
0310 struct cyttsp4_sysinfo *si;
0311 struct input_dev *input;
0312 struct mutex report_lock;
0313 bool is_suspended;
0314 char phys[NAME_MAX];
0315 int num_prv_tch;
0316 };
0317
0318 struct cyttsp4 {
0319 struct device *dev;
0320 struct mutex system_lock;
0321 struct mutex adap_lock;
0322 enum cyttsp4_mode mode;
0323 enum cyttsp4_sleep_state sleep_state;
0324 enum cyttsp4_startup_state startup_state;
0325 int int_status;
0326 wait_queue_head_t wait_q;
0327 int irq;
0328 struct work_struct startup_work;
0329 struct work_struct watchdog_work;
0330 struct timer_list watchdog_timer;
0331 struct cyttsp4_sysinfo sysinfo;
0332 void *exclusive_dev;
0333 int exclusive_waits;
0334 atomic_t ignore_irq;
0335 bool invalid_touch_app;
0336 struct cyttsp4_mt_data md;
0337 struct cyttsp4_platform_data *pdata;
0338 struct cyttsp4_core_platform_data *cpdata;
0339 const struct cyttsp4_bus_ops *bus_ops;
0340 u8 *xfer_buf;
0341 #ifdef VERBOSE_DEBUG
0342 u8 pr_buf[CY_MAX_PRBUF_SIZE];
0343 #endif
0344 };
0345
0346 struct cyttsp4_bus_ops {
0347 u16 bustype;
0348 int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
0349 const void *values);
0350 int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
0351 void *values);
0352 };
0353
0354 enum cyttsp4_hst_mode_bits {
0355 CY_HST_TOGGLE = (1 << 7),
0356 CY_HST_MODE_CHANGE = (1 << 3),
0357 CY_HST_MODE = (7 << 4),
0358 CY_HST_OPERATE = (0 << 4),
0359 CY_HST_SYSINFO = (1 << 4),
0360 CY_HST_CAT = (2 << 4),
0361 CY_HST_LOWPOW = (1 << 2),
0362 CY_HST_SLEEP = (1 << 1),
0363 CY_HST_RESET = (1 << 0),
0364 };
0365
0366
0367 #define CY_IGNORE_VALUE 0xFFFF
0368
0369
0370 enum cyttsp4_sig_caps {
0371 CY_SIGNAL_OST,
0372 CY_MIN_OST,
0373 CY_MAX_OST,
0374 CY_FUZZ_OST,
0375 CY_FLAT_OST,
0376 CY_NUM_ABS_SET
0377 };
0378
0379
0380 enum cyttsp4_sig_ost {
0381 CY_ABS_X_OST,
0382 CY_ABS_Y_OST,
0383 CY_ABS_P_OST,
0384 CY_ABS_W_OST,
0385 CY_ABS_ID_OST,
0386 CY_ABS_MAJ_OST,
0387 CY_ABS_MIN_OST,
0388 CY_ABS_OR_OST,
0389 CY_NUM_ABS_OST
0390 };
0391
0392 enum cyttsp4_flags {
0393 CY_FLAG_NONE = 0x00,
0394 CY_FLAG_HOVER = 0x04,
0395 CY_FLAG_FLIP = 0x08,
0396 CY_FLAG_INV_X = 0x10,
0397 CY_FLAG_INV_Y = 0x20,
0398 CY_FLAG_VKEYS = 0x40,
0399 };
0400
0401 enum cyttsp4_object_id {
0402 CY_OBJ_STANDARD_FINGER,
0403 CY_OBJ_LARGE_OBJECT,
0404 CY_OBJ_STYLUS,
0405 CY_OBJ_HOVER,
0406 };
0407
0408 enum cyttsp4_event_id {
0409 CY_EV_NO_EVENT,
0410 CY_EV_TOUCHDOWN,
0411 CY_EV_MOVE,
0412 CY_EV_LIFTOFF,
0413 };
0414
0415
0416 #define CY_PCFG_RESOLUTION_X_MASK 0x7F
0417
0418
0419 #define CY_PCFG_RESOLUTION_Y_MASK 0x7F
0420
0421
0422 #define CY_PCFG_ORIGIN_X_MASK 0x80
0423
0424
0425 #define CY_PCFG_ORIGIN_Y_MASK 0x80
0426
0427 static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size,
0428 void *buf)
0429 {
0430 return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf);
0431 }
0432
0433 static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size,
0434 const void *buf)
0435 {
0436 return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf);
0437 }
0438
0439 extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
0440 struct device *dev, u16 irq, size_t xfer_buf_size);
0441 extern int cyttsp4_remove(struct cyttsp4 *ts);
0442 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
0443 u8 length, const void *values);
0444 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
0445 u8 length, void *values);
0446 extern const struct dev_pm_ops cyttsp4_pm_ops;
0447
0448 #endif