3 * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
4 * For use with Cypress Txx4xx parts.
5 * Supported parts include:
9 * Copyright (C) 2012 Cypress Semiconductor
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2, and only version 2, as published by the
14 * Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
25 #include "cyttsp4_core.h"
26 #include <linux/delay.h>
27 #include <linux/gpio.h>
28 #include <linux/input/mt.h>
29 #include <linux/interrupt.h>
30 #include <linux/pm_runtime.h>
31 #include <linux/sched.h>
32 #include <linux/slab.h>
35 #define CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT 500
36 #define CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT 5000
37 #define CY_CORE_MODE_CHANGE_TIMEOUT 1000
38 #define CY_CORE_RESET_AND_WAIT_TIMEOUT 500
39 #define CY_CORE_WAKEUP_TIMEOUT 500
41 #define CY_CORE_STARTUP_RETRY_COUNT 3
43 static const u8 ldr_exit
[] = {
44 0xFF, 0x01, 0x3B, 0x00, 0x00, 0x4F, 0x6D, 0x17
47 static const u8 ldr_err_app
[] = {
48 0x01, 0x02, 0x00, 0x00, 0x55, 0xDD, 0x17
51 static inline size_t merge_bytes(u8 high
, u8 low
)
53 return (high
<< 8) + low
;
57 static void cyttsp4_pr_buf(struct device
*dev
, u8
*pr_buf
, u8
*dptr
, int size
,
58 const char *data_name
)
61 const char fmt
[] = "%02X ";
67 max
= (CY_MAX_PRBUF_SIZE
- 1) - sizeof(CY_PR_TRUNCATED
);
70 for (i
= k
= 0; i
< size
&& k
< max
; i
++, k
+= 3)
71 scnprintf(pr_buf
+ k
, CY_MAX_PRBUF_SIZE
, fmt
, dptr
[i
]);
73 dev_vdbg(dev
, "%s: %s[0..%d]=%s%s\n", __func__
, data_name
, size
- 1,
74 pr_buf
, size
<= max
? "" : CY_PR_TRUNCATED
);
77 #define cyttsp4_pr_buf(dev, pr_buf, dptr, size, data_name) do { } while (0)
80 static int cyttsp4_load_status_regs(struct cyttsp4
*cd
)
82 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
83 struct device
*dev
= cd
->dev
;
86 rc
= cyttsp4_adap_read(cd
, CY_REG_BASE
, si
->si_ofs
.mode_size
,
89 dev_err(dev
, "%s: fail read mode regs r=%d\n",
92 cyttsp4_pr_buf(dev
, cd
->pr_buf
, si
->xy_mode
,
93 si
->si_ofs
.mode_size
, "xy_mode");
98 static int cyttsp4_handshake(struct cyttsp4
*cd
, u8 mode
)
100 u8 cmd
= mode
^ CY_HST_TOGGLE
;
104 * Mode change issued, handshaking now will cause endless mode change
105 * requests, for sync mode modechange will do same with handshake
107 if (mode
& CY_HST_MODE_CHANGE
)
110 rc
= cyttsp4_adap_write(cd
, CY_REG_BASE
, sizeof(cmd
), &cmd
);
112 dev_err(cd
->dev
, "%s: bus write fail on handshake (ret=%d)\n",
118 static int cyttsp4_hw_soft_reset(struct cyttsp4
*cd
)
120 u8 cmd
= CY_HST_RESET
;
121 int rc
= cyttsp4_adap_write(cd
, CY_REG_BASE
, sizeof(cmd
), &cmd
);
123 dev_err(cd
->dev
, "%s: FAILED to execute SOFT reset\n",
130 static int cyttsp4_hw_hard_reset(struct cyttsp4
*cd
)
132 if (cd
->cpdata
->xres
) {
133 cd
->cpdata
->xres(cd
->cpdata
, cd
->dev
);
134 dev_dbg(cd
->dev
, "%s: execute HARD reset\n", __func__
);
137 dev_err(cd
->dev
, "%s: FAILED to execute HARD reset\n", __func__
);
141 static int cyttsp4_hw_reset(struct cyttsp4
*cd
)
143 int rc
= cyttsp4_hw_hard_reset(cd
);
145 rc
= cyttsp4_hw_soft_reset(cd
);
150 * Gets number of bits for a touch filed as parameter,
151 * sets maximum value for field which is used as bit mask
152 * and returns number of bytes required for that field
154 static int cyttsp4_bits_2_bytes(unsigned int nbits
, size_t *max
)
157 return (nbits
+ 7) / 8;
160 static int cyttsp4_si_data_offsets(struct cyttsp4
*cd
)
162 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
163 int rc
= cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(si
->si_data
),
166 dev_err(cd
->dev
, "%s: fail read sysinfo data offsets r=%d\n",
171 /* Print sysinfo data offsets */
172 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)&si
->si_data
,
173 sizeof(si
->si_data
), "sysinfo_data_offsets");
175 /* convert sysinfo data offset bytes into integers */
177 si
->si_ofs
.map_sz
= merge_bytes(si
->si_data
.map_szh
,
178 si
->si_data
.map_szl
);
179 si
->si_ofs
.map_sz
= merge_bytes(si
->si_data
.map_szh
,
180 si
->si_data
.map_szl
);
181 si
->si_ofs
.cydata_ofs
= merge_bytes(si
->si_data
.cydata_ofsh
,
182 si
->si_data
.cydata_ofsl
);
183 si
->si_ofs
.test_ofs
= merge_bytes(si
->si_data
.test_ofsh
,
184 si
->si_data
.test_ofsl
);
185 si
->si_ofs
.pcfg_ofs
= merge_bytes(si
->si_data
.pcfg_ofsh
,
186 si
->si_data
.pcfg_ofsl
);
187 si
->si_ofs
.opcfg_ofs
= merge_bytes(si
->si_data
.opcfg_ofsh
,
188 si
->si_data
.opcfg_ofsl
);
189 si
->si_ofs
.ddata_ofs
= merge_bytes(si
->si_data
.ddata_ofsh
,
190 si
->si_data
.ddata_ofsl
);
191 si
->si_ofs
.mdata_ofs
= merge_bytes(si
->si_data
.mdata_ofsh
,
192 si
->si_data
.mdata_ofsl
);
196 static int cyttsp4_si_get_cydata(struct cyttsp4
*cd
)
198 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
200 int mfgid_sz
, calc_mfgid_sz
;
204 si
->si_ofs
.cydata_size
= si
->si_ofs
.test_ofs
- si
->si_ofs
.cydata_ofs
;
205 dev_dbg(cd
->dev
, "%s: cydata size: %Zd\n", __func__
,
206 si
->si_ofs
.cydata_size
);
208 p
= krealloc(si
->si_ptrs
.cydata
, si
->si_ofs
.cydata_size
, GFP_KERNEL
);
210 dev_err(cd
->dev
, "%s: fail alloc cydata memory\n", __func__
);
213 si
->si_ptrs
.cydata
= p
;
215 read_offset
= si
->si_ofs
.cydata_ofs
;
217 /* Read the CYDA registers up to MFGID field */
218 rc
= cyttsp4_adap_read(cd
, read_offset
,
219 offsetof(struct cyttsp4_cydata
, mfgid_sz
)
220 + sizeof(si
->si_ptrs
.cydata
->mfgid_sz
),
223 dev_err(cd
->dev
, "%s: fail read cydata r=%d\n",
228 /* Check MFGID size */
229 mfgid_sz
= si
->si_ptrs
.cydata
->mfgid_sz
;
230 calc_mfgid_sz
= si
->si_ofs
.cydata_size
- sizeof(struct cyttsp4_cydata
);
231 if (mfgid_sz
!= calc_mfgid_sz
) {
232 dev_err(cd
->dev
, "%s: mismatch in MFGID size, reported:%d calculated:%d\n",
233 __func__
, mfgid_sz
, calc_mfgid_sz
);
237 read_offset
+= offsetof(struct cyttsp4_cydata
, mfgid_sz
)
238 + sizeof(si
->si_ptrs
.cydata
->mfgid_sz
);
240 /* Read the CYDA registers for MFGID field */
241 rc
= cyttsp4_adap_read(cd
, read_offset
, si
->si_ptrs
.cydata
->mfgid_sz
,
242 si
->si_ptrs
.cydata
->mfg_id
);
244 dev_err(cd
->dev
, "%s: fail read cydata r=%d\n",
249 read_offset
+= si
->si_ptrs
.cydata
->mfgid_sz
;
251 /* Read the rest of the CYDA registers */
252 rc
= cyttsp4_adap_read(cd
, read_offset
,
253 sizeof(struct cyttsp4_cydata
)
254 - offsetof(struct cyttsp4_cydata
, cyito_idh
),
255 &si
->si_ptrs
.cydata
->cyito_idh
);
257 dev_err(cd
->dev
, "%s: fail read cydata r=%d\n",
262 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)si
->si_ptrs
.cydata
,
263 si
->si_ofs
.cydata_size
, "sysinfo_cydata");
267 static int cyttsp4_si_get_test_data(struct cyttsp4
*cd
)
269 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
273 si
->si_ofs
.test_size
= si
->si_ofs
.pcfg_ofs
- si
->si_ofs
.test_ofs
;
275 p
= krealloc(si
->si_ptrs
.test
, si
->si_ofs
.test_size
, GFP_KERNEL
);
277 dev_err(cd
->dev
, "%s: fail alloc test memory\n", __func__
);
280 si
->si_ptrs
.test
= p
;
282 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.test_ofs
, si
->si_ofs
.test_size
,
285 dev_err(cd
->dev
, "%s: fail read test data r=%d\n",
290 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
291 (u8
*)si
->si_ptrs
.test
, si
->si_ofs
.test_size
,
292 "sysinfo_test_data");
293 if (si
->si_ptrs
.test
->post_codel
&
294 CY_POST_CODEL_WDG_RST
)
295 dev_info(cd
->dev
, "%s: %s codel=%02X\n",
296 __func__
, "Reset was a WATCHDOG RESET",
297 si
->si_ptrs
.test
->post_codel
);
299 if (!(si
->si_ptrs
.test
->post_codel
&
300 CY_POST_CODEL_CFG_DATA_CRC_FAIL
))
301 dev_info(cd
->dev
, "%s: %s codel=%02X\n", __func__
,
302 "Config Data CRC FAIL",
303 si
->si_ptrs
.test
->post_codel
);
305 if (!(si
->si_ptrs
.test
->post_codel
&
306 CY_POST_CODEL_PANEL_TEST_FAIL
))
307 dev_info(cd
->dev
, "%s: %s codel=%02X\n",
308 __func__
, "PANEL TEST FAIL",
309 si
->si_ptrs
.test
->post_codel
);
311 dev_info(cd
->dev
, "%s: SCANNING is %s codel=%02X\n",
312 __func__
, si
->si_ptrs
.test
->post_codel
& 0x08 ?
313 "ENABLED" : "DISABLED",
314 si
->si_ptrs
.test
->post_codel
);
318 static int cyttsp4_si_get_pcfg_data(struct cyttsp4
*cd
)
320 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
324 si
->si_ofs
.pcfg_size
= si
->si_ofs
.opcfg_ofs
- si
->si_ofs
.pcfg_ofs
;
326 p
= krealloc(si
->si_ptrs
.pcfg
, si
->si_ofs
.pcfg_size
, GFP_KERNEL
);
329 dev_err(cd
->dev
, "%s: fail alloc pcfg memory r=%d\n",
333 si
->si_ptrs
.pcfg
= p
;
335 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.pcfg_ofs
, si
->si_ofs
.pcfg_size
,
338 dev_err(cd
->dev
, "%s: fail read pcfg data r=%d\n",
343 si
->si_ofs
.max_x
= merge_bytes((si
->si_ptrs
.pcfg
->res_xh
344 & CY_PCFG_RESOLUTION_X_MASK
), si
->si_ptrs
.pcfg
->res_xl
);
345 si
->si_ofs
.x_origin
= !!(si
->si_ptrs
.pcfg
->res_xh
346 & CY_PCFG_ORIGIN_X_MASK
);
347 si
->si_ofs
.max_y
= merge_bytes((si
->si_ptrs
.pcfg
->res_yh
348 & CY_PCFG_RESOLUTION_Y_MASK
), si
->si_ptrs
.pcfg
->res_yl
);
349 si
->si_ofs
.y_origin
= !!(si
->si_ptrs
.pcfg
->res_yh
350 & CY_PCFG_ORIGIN_Y_MASK
);
351 si
->si_ofs
.max_p
= merge_bytes(si
->si_ptrs
.pcfg
->max_zh
,
352 si
->si_ptrs
.pcfg
->max_zl
);
354 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
355 (u8
*)si
->si_ptrs
.pcfg
,
356 si
->si_ofs
.pcfg_size
, "sysinfo_pcfg_data");
360 static int cyttsp4_si_get_opcfg_data(struct cyttsp4
*cd
)
362 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
363 struct cyttsp4_tch_abs_params
*tch
;
364 struct cyttsp4_tch_rec_params
*tch_old
, *tch_new
;
365 enum cyttsp4_tch_abs abs
;
370 si
->si_ofs
.opcfg_size
= si
->si_ofs
.ddata_ofs
- si
->si_ofs
.opcfg_ofs
;
372 p
= krealloc(si
->si_ptrs
.opcfg
, si
->si_ofs
.opcfg_size
, GFP_KERNEL
);
374 dev_err(cd
->dev
, "%s: fail alloc opcfg memory\n", __func__
);
376 goto cyttsp4_si_get_opcfg_data_exit
;
378 si
->si_ptrs
.opcfg
= p
;
380 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.opcfg_ofs
, si
->si_ofs
.opcfg_size
,
383 dev_err(cd
->dev
, "%s: fail read opcfg data r=%d\n",
385 goto cyttsp4_si_get_opcfg_data_exit
;
387 si
->si_ofs
.cmd_ofs
= si
->si_ptrs
.opcfg
->cmd_ofs
;
388 si
->si_ofs
.rep_ofs
= si
->si_ptrs
.opcfg
->rep_ofs
;
389 si
->si_ofs
.rep_sz
= (si
->si_ptrs
.opcfg
->rep_szh
* 256) +
390 si
->si_ptrs
.opcfg
->rep_szl
;
391 si
->si_ofs
.num_btns
= si
->si_ptrs
.opcfg
->num_btns
;
392 si
->si_ofs
.num_btn_regs
= (si
->si_ofs
.num_btns
+
393 CY_NUM_BTN_PER_REG
- 1) / CY_NUM_BTN_PER_REG
;
394 si
->si_ofs
.tt_stat_ofs
= si
->si_ptrs
.opcfg
->tt_stat_ofs
;
395 si
->si_ofs
.obj_cfg0
= si
->si_ptrs
.opcfg
->obj_cfg0
;
396 si
->si_ofs
.max_tchs
= si
->si_ptrs
.opcfg
->max_tchs
&
398 si
->si_ofs
.tch_rec_size
= si
->si_ptrs
.opcfg
->tch_rec_size
&
401 /* Get the old touch fields */
402 for (abs
= CY_TCH_X
; abs
< CY_NUM_TCH_FIELDS
; abs
++) {
403 tch
= &si
->si_ofs
.tch_abs
[abs
];
404 tch_old
= &si
->si_ptrs
.opcfg
->tch_rec_old
[abs
];
406 tch
->ofs
= tch_old
->loc
& CY_BYTE_OFS_MASK
;
407 tch
->size
= cyttsp4_bits_2_bytes(tch_old
->size
,
409 tch
->bofs
= (tch_old
->loc
& CY_BOFS_MASK
) >> CY_BOFS_SHIFT
;
413 si
->si_ofs
.btn_rec_size
= si
->si_ptrs
.opcfg
->btn_rec_size
;
414 si
->si_ofs
.btn_diff_ofs
= si
->si_ptrs
.opcfg
->btn_diff_ofs
;
415 si
->si_ofs
.btn_diff_size
= si
->si_ptrs
.opcfg
->btn_diff_size
;
417 if (si
->si_ofs
.tch_rec_size
> CY_TMA1036_TCH_REC_SIZE
) {
418 /* Get the extended touch fields */
419 for (i
= 0; i
< CY_NUM_EXT_TCH_FIELDS
; abs
++, i
++) {
420 tch
= &si
->si_ofs
.tch_abs
[abs
];
421 tch_new
= &si
->si_ptrs
.opcfg
->tch_rec_new
[i
];
423 tch
->ofs
= tch_new
->loc
& CY_BYTE_OFS_MASK
;
424 tch
->size
= cyttsp4_bits_2_bytes(tch_new
->size
,
426 tch
->bofs
= (tch_new
->loc
& CY_BOFS_MASK
) >> CY_BOFS_SHIFT
;
430 for (abs
= 0; abs
< CY_TCH_NUM_ABS
; abs
++) {
431 dev_dbg(cd
->dev
, "%s: tch_rec_%s\n", __func__
,
432 cyttsp4_tch_abs_string
[abs
]);
433 dev_dbg(cd
->dev
, "%s: ofs =%2Zd\n", __func__
,
434 si
->si_ofs
.tch_abs
[abs
].ofs
);
435 dev_dbg(cd
->dev
, "%s: siz =%2Zd\n", __func__
,
436 si
->si_ofs
.tch_abs
[abs
].size
);
437 dev_dbg(cd
->dev
, "%s: max =%2Zd\n", __func__
,
438 si
->si_ofs
.tch_abs
[abs
].max
);
439 dev_dbg(cd
->dev
, "%s: bofs=%2Zd\n", __func__
,
440 si
->si_ofs
.tch_abs
[abs
].bofs
);
443 si
->si_ofs
.mode_size
= si
->si_ofs
.tt_stat_ofs
+ 1;
444 si
->si_ofs
.data_size
= si
->si_ofs
.max_tchs
*
445 si
->si_ptrs
.opcfg
->tch_rec_size
;
447 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)si
->si_ptrs
.opcfg
,
448 si
->si_ofs
.opcfg_size
, "sysinfo_opcfg_data");
450 cyttsp4_si_get_opcfg_data_exit
:
454 static int cyttsp4_si_get_ddata(struct cyttsp4
*cd
)
456 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
460 si
->si_ofs
.ddata_size
= si
->si_ofs
.mdata_ofs
- si
->si_ofs
.ddata_ofs
;
462 p
= krealloc(si
->si_ptrs
.ddata
, si
->si_ofs
.ddata_size
, GFP_KERNEL
);
464 dev_err(cd
->dev
, "%s: fail alloc ddata memory\n", __func__
);
467 si
->si_ptrs
.ddata
= p
;
469 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.ddata_ofs
, si
->si_ofs
.ddata_size
,
472 dev_err(cd
->dev
, "%s: fail read ddata data r=%d\n",
475 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
476 (u8
*)si
->si_ptrs
.ddata
,
477 si
->si_ofs
.ddata_size
, "sysinfo_ddata");
481 static int cyttsp4_si_get_mdata(struct cyttsp4
*cd
)
483 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
487 si
->si_ofs
.mdata_size
= si
->si_ofs
.map_sz
- si
->si_ofs
.mdata_ofs
;
489 p
= krealloc(si
->si_ptrs
.mdata
, si
->si_ofs
.mdata_size
, GFP_KERNEL
);
491 dev_err(cd
->dev
, "%s: fail alloc mdata memory\n", __func__
);
494 si
->si_ptrs
.mdata
= p
;
496 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.mdata_ofs
, si
->si_ofs
.mdata_size
,
499 dev_err(cd
->dev
, "%s: fail read mdata data r=%d\n",
502 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
503 (u8
*)si
->si_ptrs
.mdata
,
504 si
->si_ofs
.mdata_size
, "sysinfo_mdata");
508 static int cyttsp4_si_get_btn_data(struct cyttsp4
*cd
)
510 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
512 int num_defined_keys
;
517 if (si
->si_ofs
.num_btns
) {
518 si
->si_ofs
.btn_keys_size
= si
->si_ofs
.num_btns
*
519 sizeof(struct cyttsp4_btn
);
521 p
= krealloc(si
->btn
, si
->si_ofs
.btn_keys_size
,
522 GFP_KERNEL
|__GFP_ZERO
);
524 dev_err(cd
->dev
, "%s: %s\n", __func__
,
525 "fail alloc btn_keys memory");
530 if (cd
->cpdata
->sett
[CY_IC_GRPNUM_BTN_KEYS
] == NULL
)
531 num_defined_keys
= 0;
532 else if (cd
->cpdata
->sett
[CY_IC_GRPNUM_BTN_KEYS
]->data
== NULL
)
533 num_defined_keys
= 0;
535 num_defined_keys
= cd
->cpdata
->sett
536 [CY_IC_GRPNUM_BTN_KEYS
]->size
;
538 for (btn
= 0; btn
< si
->si_ofs
.num_btns
&&
539 btn
< num_defined_keys
; btn
++) {
540 key_table
= (u16
*)cd
->cpdata
->sett
541 [CY_IC_GRPNUM_BTN_KEYS
]->data
;
542 si
->btn
[btn
].key_code
= key_table
[btn
];
543 si
->btn
[btn
].state
= CY_BTN_RELEASED
;
544 si
->btn
[btn
].enabled
= true;
546 for (; btn
< si
->si_ofs
.num_btns
; btn
++) {
547 si
->btn
[btn
].key_code
= KEY_RESERVED
;
548 si
->btn
[btn
].state
= CY_BTN_RELEASED
;
549 si
->btn
[btn
].enabled
= true;
555 si
->si_ofs
.btn_keys_size
= 0;
561 static int cyttsp4_si_get_op_data_ptrs(struct cyttsp4
*cd
)
563 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
566 p
= krealloc(si
->xy_mode
, si
->si_ofs
.mode_size
, GFP_KERNEL
|__GFP_ZERO
);
571 p
= krealloc(si
->xy_data
, si
->si_ofs
.data_size
, GFP_KERNEL
|__GFP_ZERO
);
576 p
= krealloc(si
->btn_rec_data
,
577 si
->si_ofs
.btn_rec_size
* si
->si_ofs
.num_btns
,
578 GFP_KERNEL
|__GFP_ZERO
);
581 si
->btn_rec_data
= p
;
586 static void cyttsp4_si_put_log_data(struct cyttsp4
*cd
)
588 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
589 dev_dbg(cd
->dev
, "%s: cydata_ofs =%4Zd siz=%4Zd\n", __func__
,
590 si
->si_ofs
.cydata_ofs
, si
->si_ofs
.cydata_size
);
591 dev_dbg(cd
->dev
, "%s: test_ofs =%4Zd siz=%4Zd\n", __func__
,
592 si
->si_ofs
.test_ofs
, si
->si_ofs
.test_size
);
593 dev_dbg(cd
->dev
, "%s: pcfg_ofs =%4Zd siz=%4Zd\n", __func__
,
594 si
->si_ofs
.pcfg_ofs
, si
->si_ofs
.pcfg_size
);
595 dev_dbg(cd
->dev
, "%s: opcfg_ofs =%4Zd siz=%4Zd\n", __func__
,
596 si
->si_ofs
.opcfg_ofs
, si
->si_ofs
.opcfg_size
);
597 dev_dbg(cd
->dev
, "%s: ddata_ofs =%4Zd siz=%4Zd\n", __func__
,
598 si
->si_ofs
.ddata_ofs
, si
->si_ofs
.ddata_size
);
599 dev_dbg(cd
->dev
, "%s: mdata_ofs =%4Zd siz=%4Zd\n", __func__
,
600 si
->si_ofs
.mdata_ofs
, si
->si_ofs
.mdata_size
);
602 dev_dbg(cd
->dev
, "%s: cmd_ofs =%4Zd\n", __func__
,
604 dev_dbg(cd
->dev
, "%s: rep_ofs =%4Zd\n", __func__
,
606 dev_dbg(cd
->dev
, "%s: rep_sz =%4Zd\n", __func__
,
608 dev_dbg(cd
->dev
, "%s: num_btns =%4Zd\n", __func__
,
609 si
->si_ofs
.num_btns
);
610 dev_dbg(cd
->dev
, "%s: num_btn_regs =%4Zd\n", __func__
,
611 si
->si_ofs
.num_btn_regs
);
612 dev_dbg(cd
->dev
, "%s: tt_stat_ofs =%4Zd\n", __func__
,
613 si
->si_ofs
.tt_stat_ofs
);
614 dev_dbg(cd
->dev
, "%s: tch_rec_size =%4Zd\n", __func__
,
615 si
->si_ofs
.tch_rec_size
);
616 dev_dbg(cd
->dev
, "%s: max_tchs =%4Zd\n", __func__
,
617 si
->si_ofs
.max_tchs
);
618 dev_dbg(cd
->dev
, "%s: mode_size =%4Zd\n", __func__
,
619 si
->si_ofs
.mode_size
);
620 dev_dbg(cd
->dev
, "%s: data_size =%4Zd\n", __func__
,
621 si
->si_ofs
.data_size
);
622 dev_dbg(cd
->dev
, "%s: map_sz =%4Zd\n", __func__
,
625 dev_dbg(cd
->dev
, "%s: btn_rec_size =%2Zd\n", __func__
,
626 si
->si_ofs
.btn_rec_size
);
627 dev_dbg(cd
->dev
, "%s: btn_diff_ofs =%2Zd\n", __func__
,
628 si
->si_ofs
.btn_diff_ofs
);
629 dev_dbg(cd
->dev
, "%s: btn_diff_size =%2Zd\n", __func__
,
630 si
->si_ofs
.btn_diff_size
);
632 dev_dbg(cd
->dev
, "%s: max_x = 0x%04ZX (%Zd)\n", __func__
,
633 si
->si_ofs
.max_x
, si
->si_ofs
.max_x
);
634 dev_dbg(cd
->dev
, "%s: x_origin = %Zd (%s)\n", __func__
,
636 si
->si_ofs
.x_origin
== CY_NORMAL_ORIGIN
?
637 "left corner" : "right corner");
638 dev_dbg(cd
->dev
, "%s: max_y = 0x%04ZX (%Zd)\n", __func__
,
639 si
->si_ofs
.max_y
, si
->si_ofs
.max_y
);
640 dev_dbg(cd
->dev
, "%s: y_origin = %Zd (%s)\n", __func__
,
642 si
->si_ofs
.y_origin
== CY_NORMAL_ORIGIN
?
643 "upper corner" : "lower corner");
644 dev_dbg(cd
->dev
, "%s: max_p = 0x%04ZX (%Zd)\n", __func__
,
645 si
->si_ofs
.max_p
, si
->si_ofs
.max_p
);
647 dev_dbg(cd
->dev
, "%s: xy_mode=%p xy_data=%p\n", __func__
,
648 si
->xy_mode
, si
->xy_data
);
651 static int cyttsp4_get_sysinfo_regs(struct cyttsp4
*cd
)
653 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
656 rc
= cyttsp4_si_data_offsets(cd
);
660 rc
= cyttsp4_si_get_cydata(cd
);
664 rc
= cyttsp4_si_get_test_data(cd
);
668 rc
= cyttsp4_si_get_pcfg_data(cd
);
672 rc
= cyttsp4_si_get_opcfg_data(cd
);
676 rc
= cyttsp4_si_get_ddata(cd
);
680 rc
= cyttsp4_si_get_mdata(cd
);
684 rc
= cyttsp4_si_get_btn_data(cd
);
688 rc
= cyttsp4_si_get_op_data_ptrs(cd
);
690 dev_err(cd
->dev
, "%s: failed to get_op_data\n",
695 cyttsp4_si_put_log_data(cd
);
697 /* provide flow control handshake */
698 rc
= cyttsp4_handshake(cd
, si
->si_data
.hst_mode
);
700 dev_err(cd
->dev
, "%s: handshake fail on sysinfo reg\n",
707 static void cyttsp4_queue_startup_(struct cyttsp4
*cd
)
709 if (cd
->startup_state
== STARTUP_NONE
) {
710 cd
->startup_state
= STARTUP_QUEUED
;
711 schedule_work(&cd
->startup_work
);
712 dev_dbg(cd
->dev
, "%s: cyttsp4_startup queued\n", __func__
);
714 dev_dbg(cd
->dev
, "%s: startup_state = %d\n", __func__
,
719 static void cyttsp4_report_slot_liftoff(struct cyttsp4_mt_data
*md
,
724 if (md
->num_prv_tch
== 0)
727 for (t
= 0; t
< max_slots
; t
++) {
728 input_mt_slot(md
->input
, t
);
729 input_mt_report_slot_state(md
->input
,
730 MT_TOOL_FINGER
, false);
734 static void cyttsp4_lift_all(struct cyttsp4_mt_data
*md
)
739 if (md
->num_prv_tch
!= 0) {
740 cyttsp4_report_slot_liftoff(md
,
741 md
->si
->si_ofs
.tch_abs
[CY_TCH_T
].max
);
742 input_sync(md
->input
);
747 static void cyttsp4_get_touch_axis(struct cyttsp4_mt_data
*md
,
748 int *axis
, int size
, int max
, u8
*xy_data
, int bofs
)
753 for (nbyte
= 0, *axis
= 0, next
= 0; nbyte
< size
; nbyte
++) {
754 dev_vdbg(&md
->input
->dev
,
755 "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p"
756 " xy_data[%d]=%02X(%d) bofs=%d\n",
757 __func__
, *axis
, *axis
, size
, max
, xy_data
, next
,
758 xy_data
[next
], xy_data
[next
], bofs
);
759 *axis
= (*axis
* 256) + (xy_data
[next
] >> bofs
);
765 dev_vdbg(&md
->input
->dev
,
766 "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p"
767 " xy_data[%d]=%02X(%d)\n",
768 __func__
, *axis
, *axis
, size
, max
, xy_data
, next
,
769 xy_data
[next
], xy_data
[next
]);
772 static void cyttsp4_get_touch(struct cyttsp4_mt_data
*md
,
773 struct cyttsp4_touch
*touch
, u8
*xy_data
)
775 struct device
*dev
= &md
->input
->dev
;
776 struct cyttsp4_sysinfo
*si
= md
->si
;
777 enum cyttsp4_tch_abs abs
;
781 for (abs
= CY_TCH_X
; abs
< CY_TCH_NUM_ABS
; abs
++) {
782 cyttsp4_get_touch_axis(md
, &touch
->abs
[abs
],
783 si
->si_ofs
.tch_abs
[abs
].size
,
784 si
->si_ofs
.tch_abs
[abs
].max
,
785 xy_data
+ si
->si_ofs
.tch_abs
[abs
].ofs
,
786 si
->si_ofs
.tch_abs
[abs
].bofs
);
787 dev_vdbg(dev
, "%s: get %s=%04X(%d)\n", __func__
,
788 cyttsp4_tch_abs_string
[abs
],
789 touch
->abs
[abs
], touch
->abs
[abs
]);
792 if (md
->pdata
->flags
& CY_FLAG_FLIP
) {
793 tmp
= touch
->abs
[CY_TCH_X
];
794 touch
->abs
[CY_TCH_X
] = touch
->abs
[CY_TCH_Y
];
795 touch
->abs
[CY_TCH_Y
] = tmp
;
800 if (md
->pdata
->flags
& CY_FLAG_INV_X
) {
802 touch
->abs
[CY_TCH_X
] = md
->si
->si_ofs
.max_y
-
803 touch
->abs
[CY_TCH_X
];
805 touch
->abs
[CY_TCH_X
] = md
->si
->si_ofs
.max_x
-
806 touch
->abs
[CY_TCH_X
];
808 if (md
->pdata
->flags
& CY_FLAG_INV_Y
) {
810 touch
->abs
[CY_TCH_Y
] = md
->si
->si_ofs
.max_x
-
811 touch
->abs
[CY_TCH_Y
];
813 touch
->abs
[CY_TCH_Y
] = md
->si
->si_ofs
.max_y
-
814 touch
->abs
[CY_TCH_Y
];
817 dev_vdbg(dev
, "%s: flip=%s inv-x=%s inv-y=%s x=%04X(%d) y=%04X(%d)\n",
818 __func__
, flipped
? "true" : "false",
819 md
->pdata
->flags
& CY_FLAG_INV_X
? "true" : "false",
820 md
->pdata
->flags
& CY_FLAG_INV_Y
? "true" : "false",
821 touch
->abs
[CY_TCH_X
], touch
->abs
[CY_TCH_X
],
822 touch
->abs
[CY_TCH_Y
], touch
->abs
[CY_TCH_Y
]);
825 static void cyttsp4_final_sync(struct input_dev
*input
, int max_slots
, int *ids
)
829 for (t
= 0; t
< max_slots
; t
++) {
832 input_mt_slot(input
, t
);
833 input_mt_report_slot_state(input
, MT_TOOL_FINGER
, false);
839 static void cyttsp4_get_mt_touches(struct cyttsp4_mt_data
*md
, int num_cur_tch
)
841 struct device
*dev
= &md
->input
->dev
;
842 struct cyttsp4_sysinfo
*si
= md
->si
;
843 struct cyttsp4_touch tch
;
846 int ids
[max(CY_TMA1036_MAX_TCH
, CY_TMA4XX_MAX_TCH
)];
848 memset(ids
, 0, si
->si_ofs
.tch_abs
[CY_TCH_T
].max
* sizeof(int));
849 for (i
= 0; i
< num_cur_tch
; i
++) {
850 cyttsp4_get_touch(md
, &tch
, si
->xy_data
+
851 (i
* si
->si_ofs
.tch_rec_size
));
852 if ((tch
.abs
[CY_TCH_T
] < md
->pdata
->frmwrk
->abs
853 [(CY_ABS_ID_OST
* CY_NUM_ABS_SET
) + CY_MIN_OST
]) ||
854 (tch
.abs
[CY_TCH_T
] > md
->pdata
->frmwrk
->abs
855 [(CY_ABS_ID_OST
* CY_NUM_ABS_SET
) + CY_MAX_OST
])) {
856 dev_err(dev
, "%s: tch=%d -> bad trk_id=%d max_id=%d\n",
857 __func__
, i
, tch
.abs
[CY_TCH_T
],
858 md
->pdata
->frmwrk
->abs
[(CY_ABS_ID_OST
*
859 CY_NUM_ABS_SET
) + CY_MAX_OST
]);
863 /* use 0 based track id's */
864 sig
= md
->pdata
->frmwrk
->abs
865 [(CY_ABS_ID_OST
* CY_NUM_ABS_SET
) + 0];
866 if (sig
!= CY_IGNORE_VALUE
) {
867 t
= tch
.abs
[CY_TCH_T
] - md
->pdata
->frmwrk
->abs
868 [(CY_ABS_ID_OST
* CY_NUM_ABS_SET
) + CY_MIN_OST
];
869 if (tch
.abs
[CY_TCH_E
] == CY_EV_LIFTOFF
) {
870 dev_dbg(dev
, "%s: t=%d e=%d lift-off\n",
871 __func__
, t
, tch
.abs
[CY_TCH_E
]);
872 goto cyttsp4_get_mt_touches_pr_tch
;
874 input_mt_slot(md
->input
, t
);
875 input_mt_report_slot_state(md
->input
, MT_TOOL_FINGER
,
880 /* all devices: position and pressure fields */
881 for (j
= 0; j
<= CY_ABS_W_OST
; j
++) {
882 sig
= md
->pdata
->frmwrk
->abs
[((CY_ABS_X_OST
+ j
) *
883 CY_NUM_ABS_SET
) + 0];
884 if (sig
!= CY_IGNORE_VALUE
)
885 input_report_abs(md
->input
, sig
,
886 tch
.abs
[CY_TCH_X
+ j
]);
888 if (si
->si_ofs
.tch_rec_size
> CY_TMA1036_TCH_REC_SIZE
) {
890 * TMA400 size and orientation fields:
891 * if pressure is non-zero and major touch
892 * signal is zero, then set major and minor touch
893 * signals to minimum non-zero value
895 if (tch
.abs
[CY_TCH_P
] > 0 && tch
.abs
[CY_TCH_MAJ
] == 0)
896 tch
.abs
[CY_TCH_MAJ
] = tch
.abs
[CY_TCH_MIN
] = 1;
898 /* Get the extended touch fields */
899 for (j
= 0; j
< CY_NUM_EXT_TCH_FIELDS
; j
++) {
900 sig
= md
->pdata
->frmwrk
->abs
901 [((CY_ABS_MAJ_OST
+ j
) *
902 CY_NUM_ABS_SET
) + 0];
903 if (sig
!= CY_IGNORE_VALUE
)
904 input_report_abs(md
->input
, sig
,
905 tch
.abs
[CY_TCH_MAJ
+ j
]);
909 cyttsp4_get_mt_touches_pr_tch
:
910 if (si
->si_ofs
.tch_rec_size
> CY_TMA1036_TCH_REC_SIZE
)
912 "%s: t=%d x=%d y=%d z=%d M=%d m=%d o=%d e=%d\n",
923 "%s: t=%d x=%d y=%d z=%d e=%d\n", __func__
,
931 cyttsp4_final_sync(md
->input
, si
->si_ofs
.tch_abs
[CY_TCH_T
].max
, ids
);
933 md
->num_prv_tch
= num_cur_tch
;
938 /* read xy_data for all current touches */
939 static int cyttsp4_xy_worker(struct cyttsp4
*cd
)
941 struct cyttsp4_mt_data
*md
= &cd
->md
;
942 struct device
*dev
= &md
->input
->dev
;
943 struct cyttsp4_sysinfo
*si
= md
->si
;
952 * Get event data from cyttsp4 device.
953 * The event data includes all data
954 * for all active touches.
955 * Event data also includes button data
959 * 1st read to get mode + button bytes + touch count (core)
960 * 2nd read (optional) to get touch 1 - touch n data
962 hst_mode
= si
->xy_mode
[CY_REG_BASE
];
963 rep_len
= si
->xy_mode
[si
->si_ofs
.rep_ofs
];
964 rep_stat
= si
->xy_mode
[si
->si_ofs
.rep_ofs
+ 1];
965 tt_stat
= si
->xy_mode
[si
->si_ofs
.tt_stat_ofs
];
966 dev_vdbg(dev
, "%s: %s%02X %s%d %s%02X %s%02X\n", __func__
,
967 "hst_mode=", hst_mode
, "rep_len=", rep_len
,
968 "rep_stat=", rep_stat
, "tt_stat=", tt_stat
);
970 num_cur_tch
= GET_NUM_TOUCHES(tt_stat
);
971 dev_vdbg(dev
, "%s: num_cur_tch=%d\n", __func__
, num_cur_tch
);
973 if (rep_len
== 0 && num_cur_tch
> 0) {
974 dev_err(dev
, "%s: report length error rep_len=%d num_tch=%d\n",
975 __func__
, rep_len
, num_cur_tch
);
976 goto cyttsp4_xy_worker_exit
;
980 if (num_cur_tch
> 0) {
981 rc
= cyttsp4_adap_read(cd
, si
->si_ofs
.tt_stat_ofs
+ 1,
982 num_cur_tch
* si
->si_ofs
.tch_rec_size
,
985 dev_err(dev
, "%s: read fail on touch regs r=%d\n",
987 goto cyttsp4_xy_worker_exit
;
992 cyttsp4_pr_buf(dev
, cd
->pr_buf
, si
->xy_data
, num_cur_tch
*
993 si
->si_ofs
.tch_rec_size
, "xy_data");
995 /* check any error conditions */
996 if (IS_BAD_PKT(rep_stat
)) {
997 dev_dbg(dev
, "%s: Invalid buffer detected\n", __func__
);
999 goto cyttsp4_xy_worker_exit
;
1002 if (IS_LARGE_AREA(tt_stat
))
1003 dev_dbg(dev
, "%s: Large area detected\n", __func__
);
1005 if (num_cur_tch
> si
->si_ofs
.max_tchs
) {
1006 dev_err(dev
, "%s: too many tch; set to max tch (n=%d c=%Zd)\n",
1007 __func__
, num_cur_tch
, si
->si_ofs
.max_tchs
);
1008 num_cur_tch
= si
->si_ofs
.max_tchs
;
1011 /* extract xy_data for all currently reported touches */
1012 dev_vdbg(dev
, "%s: extract data num_cur_tch=%d\n", __func__
,
1015 cyttsp4_get_mt_touches(md
, num_cur_tch
);
1017 cyttsp4_lift_all(md
);
1021 cyttsp4_xy_worker_exit
:
1025 static int cyttsp4_mt_attention(struct cyttsp4
*cd
)
1027 struct device
*dev
= cd
->dev
;
1028 struct cyttsp4_mt_data
*md
= &cd
->md
;
1034 mutex_lock(&md
->report_lock
);
1035 if (!md
->is_suspended
) {
1036 /* core handles handshake */
1037 rc
= cyttsp4_xy_worker(cd
);
1039 dev_vdbg(dev
, "%s: Ignoring report while suspended\n",
1042 mutex_unlock(&md
->report_lock
);
1044 dev_err(dev
, "%s: xy_worker error r=%d\n", __func__
, rc
);
1049 static irqreturn_t
cyttsp4_irq(int irq
, void *handle
)
1051 struct cyttsp4
*cd
= handle
;
1052 struct device
*dev
= cd
->dev
;
1053 enum cyttsp4_mode cur_mode
;
1054 u8 cmd_ofs
= cd
->sysinfo
.si_ofs
.cmd_ofs
;
1059 * Check whether this IRQ should be ignored (external)
1060 * This should be the very first thing to check since
1061 * ignore_irq may be set for a very short period of time
1063 if (atomic_read(&cd
->ignore_irq
)) {
1064 dev_vdbg(dev
, "%s: Ignoring IRQ\n", __func__
);
1068 dev_dbg(dev
, "%s int:0x%x\n", __func__
, cd
->int_status
);
1070 mutex_lock(&cd
->system_lock
);
1073 if (cd
->sleep_state
== SS_SLEEP_ON
|| cd
->sleep_state
== SS_SLEEPING
)
1074 dev_vdbg(dev
, "%s: Received IRQ while in sleep\n", __func__
);
1076 rc
= cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(mode
), mode
);
1078 dev_err(cd
->dev
, "%s: Fail read adapter r=%d\n", __func__
, rc
);
1079 goto cyttsp4_irq_exit
;
1081 dev_vdbg(dev
, "%s mode[0-2]:0x%X 0x%X 0x%X\n", __func__
,
1082 mode
[0], mode
[1], mode
[2]);
1084 if (IS_BOOTLOADER(mode
[0], mode
[1])) {
1085 cur_mode
= CY_MODE_BOOTLOADER
;
1086 dev_vdbg(dev
, "%s: bl running\n", __func__
);
1087 if (cd
->mode
== CY_MODE_BOOTLOADER
) {
1088 /* Signal bootloader heartbeat heard */
1089 wake_up(&cd
->wait_q
);
1090 goto cyttsp4_irq_exit
;
1093 /* switch to bootloader */
1094 dev_dbg(dev
, "%s: restart switch to bl m=%d -> m=%d\n",
1095 __func__
, cd
->mode
, cur_mode
);
1097 /* catch operation->bl glitch */
1098 if (cd
->mode
!= CY_MODE_UNKNOWN
) {
1099 /* Incase startup_state do not let startup_() */
1100 cd
->mode
= CY_MODE_UNKNOWN
;
1101 cyttsp4_queue_startup_(cd
);
1102 goto cyttsp4_irq_exit
;
1106 * do not wake thread on this switch since
1107 * it is possible to get an early heartbeat
1108 * prior to performing the reset
1110 cd
->mode
= cur_mode
;
1112 goto cyttsp4_irq_exit
;
1115 switch (mode
[0] & CY_HST_MODE
) {
1116 case CY_HST_OPERATE
:
1117 cur_mode
= CY_MODE_OPERATIONAL
;
1118 dev_vdbg(dev
, "%s: operational\n", __func__
);
1121 cur_mode
= CY_MODE_CAT
;
1122 dev_vdbg(dev
, "%s: CaT\n", __func__
);
1124 case CY_HST_SYSINFO
:
1125 cur_mode
= CY_MODE_SYSINFO
;
1126 dev_vdbg(dev
, "%s: sysinfo\n", __func__
);
1129 cur_mode
= CY_MODE_UNKNOWN
;
1130 dev_err(dev
, "%s: unknown HST mode 0x%02X\n", __func__
,
1135 /* Check whether this IRQ should be ignored (internal) */
1136 if (cd
->int_status
& CY_INT_IGNORE
) {
1137 dev_vdbg(dev
, "%s: Ignoring IRQ\n", __func__
);
1138 goto cyttsp4_irq_exit
;
1141 /* Check for wake up interrupt */
1142 if (cd
->int_status
& CY_INT_AWAKE
) {
1143 cd
->int_status
&= ~CY_INT_AWAKE
;
1144 wake_up(&cd
->wait_q
);
1145 dev_vdbg(dev
, "%s: Received wake up interrupt\n", __func__
);
1146 goto cyttsp4_irq_handshake
;
1149 /* Expecting mode change interrupt */
1150 if ((cd
->int_status
& CY_INT_MODE_CHANGE
)
1151 && (mode
[0] & CY_HST_MODE_CHANGE
) == 0) {
1152 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1153 dev_dbg(dev
, "%s: finish mode switch m=%d -> m=%d\n",
1154 __func__
, cd
->mode
, cur_mode
);
1155 cd
->mode
= cur_mode
;
1156 wake_up(&cd
->wait_q
);
1157 goto cyttsp4_irq_handshake
;
1160 /* compare current core mode to current device mode */
1161 dev_vdbg(dev
, "%s: cd->mode=%d cur_mode=%d\n",
1162 __func__
, cd
->mode
, cur_mode
);
1163 if ((mode
[0] & CY_HST_MODE_CHANGE
) == 0 && cd
->mode
!= cur_mode
) {
1164 /* Unexpected mode change occurred */
1165 dev_err(dev
, "%s %d->%d 0x%x\n", __func__
, cd
->mode
,
1166 cur_mode
, cd
->int_status
);
1167 dev_dbg(dev
, "%s: Unexpected mode change, startup\n",
1169 cyttsp4_queue_startup_(cd
);
1170 goto cyttsp4_irq_exit
;
1173 /* Expecting command complete interrupt */
1174 dev_vdbg(dev
, "%s: command byte:0x%x\n", __func__
, mode
[cmd_ofs
]);
1175 if ((cd
->int_status
& CY_INT_EXEC_CMD
)
1176 && mode
[cmd_ofs
] & CY_CMD_COMPLETE
) {
1177 cd
->int_status
&= ~CY_INT_EXEC_CMD
;
1178 dev_vdbg(dev
, "%s: Received command complete interrupt\n",
1180 wake_up(&cd
->wait_q
);
1182 * It is possible to receive a single interrupt for
1183 * command complete and touch/button status report.
1184 * Continue processing for a possible status report.
1188 /* This should be status report, read status regs */
1189 if (cd
->mode
== CY_MODE_OPERATIONAL
) {
1190 dev_vdbg(dev
, "%s: Read status registers\n", __func__
);
1191 rc
= cyttsp4_load_status_regs(cd
);
1193 dev_err(dev
, "%s: fail read mode regs r=%d\n",
1197 cyttsp4_mt_attention(cd
);
1199 cyttsp4_irq_handshake
:
1200 /* handshake the event */
1201 dev_vdbg(dev
, "%s: Handshake mode=0x%02X r=%d\n",
1202 __func__
, mode
[0], rc
);
1203 rc
= cyttsp4_handshake(cd
, mode
[0]);
1205 dev_err(dev
, "%s: Fail handshake mode=0x%02X r=%d\n",
1206 __func__
, mode
[0], rc
);
1209 * a non-zero udelay period is required for using
1210 * IRQF_TRIGGER_LOW in order to delay until the
1211 * device completes isr deassert
1213 udelay(cd
->cpdata
->level_irq_udelay
);
1216 mutex_unlock(&cd
->system_lock
);
1220 static void cyttsp4_start_wd_timer(struct cyttsp4
*cd
)
1222 if (!CY_WATCHDOG_TIMEOUT
)
1225 mod_timer(&cd
->watchdog_timer
, jiffies
+
1226 msecs_to_jiffies(CY_WATCHDOG_TIMEOUT
));
1229 static void cyttsp4_stop_wd_timer(struct cyttsp4
*cd
)
1231 if (!CY_WATCHDOG_TIMEOUT
)
1235 * Ensure we wait until the watchdog timer
1236 * running on a different CPU finishes
1238 del_timer_sync(&cd
->watchdog_timer
);
1239 cancel_work_sync(&cd
->watchdog_work
);
1240 del_timer_sync(&cd
->watchdog_timer
);
1243 static void cyttsp4_watchdog_timer(unsigned long handle
)
1245 struct cyttsp4
*cd
= (struct cyttsp4
*)handle
;
1247 dev_vdbg(cd
->dev
, "%s: Watchdog timer triggered\n", __func__
);
1252 if (!work_pending(&cd
->watchdog_work
))
1253 schedule_work(&cd
->watchdog_work
);
1258 static int cyttsp4_request_exclusive(struct cyttsp4
*cd
, void *ownptr
,
1261 int t
= msecs_to_jiffies(timeout_ms
);
1262 bool with_timeout
= (timeout_ms
!= 0);
1264 mutex_lock(&cd
->system_lock
);
1265 if (!cd
->exclusive_dev
&& cd
->exclusive_waits
== 0) {
1266 cd
->exclusive_dev
= ownptr
;
1270 cd
->exclusive_waits
++;
1272 mutex_unlock(&cd
->system_lock
);
1274 t
= wait_event_timeout(cd
->wait_q
, !cd
->exclusive_dev
, t
);
1276 dev_err(cd
->dev
, "%s: tmo waiting exclusive access\n",
1278 mutex_lock(&cd
->system_lock
);
1279 cd
->exclusive_waits
--;
1280 mutex_unlock(&cd
->system_lock
);
1284 wait_event(cd
->wait_q
, !cd
->exclusive_dev
);
1286 mutex_lock(&cd
->system_lock
);
1287 if (cd
->exclusive_dev
)
1289 cd
->exclusive_dev
= ownptr
;
1290 cd
->exclusive_waits
--;
1292 mutex_unlock(&cd
->system_lock
);
1298 * returns error if was not owned
1300 static int cyttsp4_release_exclusive(struct cyttsp4
*cd
, void *ownptr
)
1302 mutex_lock(&cd
->system_lock
);
1303 if (cd
->exclusive_dev
!= ownptr
) {
1304 mutex_unlock(&cd
->system_lock
);
1308 dev_vdbg(cd
->dev
, "%s: exclusive_dev %p freed\n",
1309 __func__
, cd
->exclusive_dev
);
1310 cd
->exclusive_dev
= NULL
;
1311 wake_up(&cd
->wait_q
);
1312 mutex_unlock(&cd
->system_lock
);
1316 static int cyttsp4_wait_bl_heartbeat(struct cyttsp4
*cd
)
1321 /* wait heartbeat */
1322 dev_vdbg(cd
->dev
, "%s: wait heartbeat...\n", __func__
);
1323 t
= wait_event_timeout(cd
->wait_q
, cd
->mode
== CY_MODE_BOOTLOADER
,
1324 msecs_to_jiffies(CY_CORE_RESET_AND_WAIT_TIMEOUT
));
1326 dev_err(cd
->dev
, "%s: tmo waiting bl heartbeat cd->mode=%d\n",
1327 __func__
, cd
->mode
);
1334 static int cyttsp4_wait_sysinfo_mode(struct cyttsp4
*cd
)
1338 dev_vdbg(cd
->dev
, "%s: wait sysinfo...\n", __func__
);
1340 t
= wait_event_timeout(cd
->wait_q
, cd
->mode
== CY_MODE_SYSINFO
,
1341 msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT
));
1343 dev_err(cd
->dev
, "%s: tmo waiting exit bl cd->mode=%d\n",
1344 __func__
, cd
->mode
);
1345 mutex_lock(&cd
->system_lock
);
1346 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1347 mutex_unlock(&cd
->system_lock
);
1354 static int cyttsp4_reset_and_wait(struct cyttsp4
*cd
)
1358 /* reset hardware */
1359 mutex_lock(&cd
->system_lock
);
1360 dev_dbg(cd
->dev
, "%s: reset hw...\n", __func__
);
1361 rc
= cyttsp4_hw_reset(cd
);
1362 cd
->mode
= CY_MODE_UNKNOWN
;
1363 mutex_unlock(&cd
->system_lock
);
1365 dev_err(cd
->dev
, "%s:Fail hw reset r=%d\n", __func__
, rc
);
1369 return cyttsp4_wait_bl_heartbeat(cd
);
1373 * returns err if refused or timeout; block until mode change complete
1374 * bit is set (mode change interrupt)
1376 static int cyttsp4_set_mode(struct cyttsp4
*cd
, int new_mode
)
1384 case CY_MODE_OPERATIONAL
:
1385 new_dev_mode
= CY_HST_OPERATE
;
1387 case CY_MODE_SYSINFO
:
1388 new_dev_mode
= CY_HST_SYSINFO
;
1391 new_dev_mode
= CY_HST_CAT
;
1394 dev_err(cd
->dev
, "%s: invalid mode: %02X(%d)\n",
1395 __func__
, new_mode
, new_mode
);
1400 dev_dbg(cd
->dev
, "%s: %s=%p new_dev_mode=%02X new_mode=%d\n",
1401 __func__
, "have exclusive", cd
->exclusive_dev
,
1402 new_dev_mode
, new_mode
);
1404 mutex_lock(&cd
->system_lock
);
1405 rc
= cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(mode
), &mode
);
1407 mutex_unlock(&cd
->system_lock
);
1408 dev_err(cd
->dev
, "%s: Fail read mode r=%d\n",
1413 /* Clear device mode bits and set to new mode */
1414 mode
&= ~CY_HST_MODE
;
1415 mode
|= new_dev_mode
| CY_HST_MODE_CHANGE
;
1417 cd
->int_status
|= CY_INT_MODE_CHANGE
;
1418 rc
= cyttsp4_adap_write(cd
, CY_REG_BASE
, sizeof(mode
), &mode
);
1419 mutex_unlock(&cd
->system_lock
);
1421 dev_err(cd
->dev
, "%s: Fail write mode change r=%d\n",
1426 /* wait for mode change done interrupt */
1427 t
= wait_event_timeout(cd
->wait_q
,
1428 (cd
->int_status
& CY_INT_MODE_CHANGE
) == 0,
1429 msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT
));
1430 dev_dbg(cd
->dev
, "%s: back from wait t=%ld cd->mode=%d\n",
1431 __func__
, t
, cd
->mode
);
1434 dev_err(cd
->dev
, "%s: %s\n", __func__
,
1435 "tmo waiting mode change");
1436 mutex_lock(&cd
->system_lock
);
1437 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1438 mutex_unlock(&cd
->system_lock
);
1446 static void cyttsp4_watchdog_work(struct work_struct
*work
)
1448 struct cyttsp4
*cd
=
1449 container_of(work
, struct cyttsp4
, watchdog_work
);
1453 mutex_lock(&cd
->system_lock
);
1454 retval
= cyttsp4_load_status_regs(cd
);
1457 "%s: failed to access device in watchdog timer r=%d\n",
1459 cyttsp4_queue_startup_(cd
);
1460 goto cyttsp4_timer_watchdog_exit_error
;
1462 mode
= &cd
->sysinfo
.xy_mode
[CY_REG_BASE
];
1463 if (IS_BOOTLOADER(mode
[0], mode
[1])) {
1465 "%s: device found in bootloader mode when operational mode\n",
1467 cyttsp4_queue_startup_(cd
);
1468 goto cyttsp4_timer_watchdog_exit_error
;
1471 cyttsp4_start_wd_timer(cd
);
1472 cyttsp4_timer_watchdog_exit_error
:
1473 mutex_unlock(&cd
->system_lock
);
1477 static int cyttsp4_core_sleep_(struct cyttsp4
*cd
)
1479 enum cyttsp4_sleep_state ss
= SS_SLEEP_ON
;
1480 enum cyttsp4_int_state int_status
= CY_INT_IGNORE
;
1484 /* Already in sleep mode? */
1485 mutex_lock(&cd
->system_lock
);
1486 if (cd
->sleep_state
== SS_SLEEP_ON
) {
1487 mutex_unlock(&cd
->system_lock
);
1490 cd
->sleep_state
= SS_SLEEPING
;
1491 mutex_unlock(&cd
->system_lock
);
1493 cyttsp4_stop_wd_timer(cd
);
1495 /* Wait until currently running IRQ handler exits and disable IRQ */
1496 disable_irq(cd
->irq
);
1498 dev_vdbg(cd
->dev
, "%s: write DEEP SLEEP...\n", __func__
);
1499 mutex_lock(&cd
->system_lock
);
1500 rc
= cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(mode
), &mode
);
1502 mutex_unlock(&cd
->system_lock
);
1503 dev_err(cd
->dev
, "%s: Fail read adapter r=%d\n", __func__
, rc
);
1507 if (IS_BOOTLOADER(mode
[0], mode
[1])) {
1508 mutex_unlock(&cd
->system_lock
);
1509 dev_err(cd
->dev
, "%s: Device in BOOTLADER mode.\n", __func__
);
1514 mode
[0] |= CY_HST_SLEEP
;
1515 rc
= cyttsp4_adap_write(cd
, CY_REG_BASE
, sizeof(mode
[0]), &mode
[0]);
1516 mutex_unlock(&cd
->system_lock
);
1518 dev_err(cd
->dev
, "%s: Fail write adapter r=%d\n", __func__
, rc
);
1521 dev_vdbg(cd
->dev
, "%s: write DEEP SLEEP succeeded\n", __func__
);
1523 if (cd
->cpdata
->power
) {
1524 dev_dbg(cd
->dev
, "%s: Power down HW\n", __func__
);
1525 rc
= cd
->cpdata
->power(cd
->cpdata
, 0, cd
->dev
, &cd
->ignore_irq
);
1527 dev_dbg(cd
->dev
, "%s: No power function\n", __func__
);
1531 dev_err(cd
->dev
, "%s: HW Power down fails r=%d\n",
1536 /* Give time to FW to sleep */
1543 int_status
= CY_INT_NONE
;
1544 cyttsp4_start_wd_timer(cd
);
1547 mutex_lock(&cd
->system_lock
);
1548 cd
->sleep_state
= ss
;
1549 cd
->int_status
|= int_status
;
1550 mutex_unlock(&cd
->system_lock
);
1551 enable_irq(cd
->irq
);
1555 static int cyttsp4_core_sleep(struct cyttsp4
*cd
)
1559 rc
= cyttsp4_request_exclusive(cd
, cd
->dev
,
1560 CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT
);
1562 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
1563 __func__
, cd
->exclusive_dev
, cd
->dev
);
1567 rc
= cyttsp4_core_sleep_(cd
);
1569 if (cyttsp4_release_exclusive(cd
, cd
->dev
) < 0)
1570 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
1572 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
1577 static int cyttsp4_core_wake_(struct cyttsp4
*cd
)
1579 struct device
*dev
= cd
->dev
;
1584 /* Already woken? */
1585 mutex_lock(&cd
->system_lock
);
1586 if (cd
->sleep_state
== SS_SLEEP_OFF
) {
1587 mutex_unlock(&cd
->system_lock
);
1590 cd
->int_status
&= ~CY_INT_IGNORE
;
1591 cd
->int_status
|= CY_INT_AWAKE
;
1592 cd
->sleep_state
= SS_WAKING
;
1594 if (cd
->cpdata
->power
) {
1595 dev_dbg(dev
, "%s: Power up HW\n", __func__
);
1596 rc
= cd
->cpdata
->power(cd
->cpdata
, 1, dev
, &cd
->ignore_irq
);
1598 dev_dbg(dev
, "%s: No power function\n", __func__
);
1602 dev_err(dev
, "%s: HW Power up fails r=%d\n",
1605 /* Initiate a read transaction to wake up */
1606 cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(mode
), &mode
);
1608 dev_vdbg(cd
->dev
, "%s: HW power up succeeds\n",
1610 mutex_unlock(&cd
->system_lock
);
1612 t
= wait_event_timeout(cd
->wait_q
,
1613 (cd
->int_status
& CY_INT_AWAKE
) == 0,
1614 msecs_to_jiffies(CY_CORE_WAKEUP_TIMEOUT
));
1616 dev_err(dev
, "%s: TMO waiting for wakeup\n", __func__
);
1617 mutex_lock(&cd
->system_lock
);
1618 cd
->int_status
&= ~CY_INT_AWAKE
;
1619 /* Try starting up */
1620 cyttsp4_queue_startup_(cd
);
1621 mutex_unlock(&cd
->system_lock
);
1624 mutex_lock(&cd
->system_lock
);
1625 cd
->sleep_state
= SS_SLEEP_OFF
;
1626 mutex_unlock(&cd
->system_lock
);
1628 cyttsp4_start_wd_timer(cd
);
1633 static int cyttsp4_core_wake(struct cyttsp4
*cd
)
1637 rc
= cyttsp4_request_exclusive(cd
, cd
->dev
,
1638 CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
1640 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
1641 __func__
, cd
->exclusive_dev
, cd
->dev
);
1645 rc
= cyttsp4_core_wake_(cd
);
1647 if (cyttsp4_release_exclusive(cd
, cd
->dev
) < 0)
1648 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
1650 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
1655 static int cyttsp4_startup_(struct cyttsp4
*cd
)
1657 int retry
= CY_CORE_STARTUP_RETRY_COUNT
;
1660 cyttsp4_stop_wd_timer(cd
);
1663 if (retry
!= CY_CORE_STARTUP_RETRY_COUNT
)
1664 dev_dbg(cd
->dev
, "%s: Retry %d\n", __func__
,
1665 CY_CORE_STARTUP_RETRY_COUNT
- retry
);
1667 /* reset hardware and wait for heartbeat */
1668 rc
= cyttsp4_reset_and_wait(cd
);
1670 dev_err(cd
->dev
, "%s: Error on h/w reset r=%d\n", __func__
, rc
);
1676 /* exit bl into sysinfo mode */
1677 dev_vdbg(cd
->dev
, "%s: write exit ldr...\n", __func__
);
1678 mutex_lock(&cd
->system_lock
);
1679 cd
->int_status
&= ~CY_INT_IGNORE
;
1680 cd
->int_status
|= CY_INT_MODE_CHANGE
;
1682 rc
= cyttsp4_adap_write(cd
, CY_REG_BASE
, sizeof(ldr_exit
),
1684 mutex_unlock(&cd
->system_lock
);
1686 dev_err(cd
->dev
, "%s: Fail write r=%d\n", __func__
, rc
);
1692 rc
= cyttsp4_wait_sysinfo_mode(cd
);
1694 u8 buf
[sizeof(ldr_err_app
)];
1697 /* Check for invalid/corrupted touch application */
1698 rc1
= cyttsp4_adap_read(cd
, CY_REG_BASE
, sizeof(ldr_err_app
),
1701 dev_err(cd
->dev
, "%s: Fail read r=%d\n", __func__
, rc1
);
1702 } else if (!memcmp(buf
, ldr_err_app
, sizeof(ldr_err_app
))) {
1703 dev_err(cd
->dev
, "%s: Error launching touch application\n",
1705 mutex_lock(&cd
->system_lock
);
1706 cd
->invalid_touch_app
= true;
1707 mutex_unlock(&cd
->system_lock
);
1716 mutex_lock(&cd
->system_lock
);
1717 cd
->invalid_touch_app
= false;
1718 mutex_unlock(&cd
->system_lock
);
1720 /* read sysinfo data */
1721 dev_vdbg(cd
->dev
, "%s: get sysinfo regs..\n", __func__
);
1722 rc
= cyttsp4_get_sysinfo_regs(cd
);
1724 dev_err(cd
->dev
, "%s: failed to get sysinfo regs rc=%d\n",
1731 rc
= cyttsp4_set_mode(cd
, CY_MODE_OPERATIONAL
);
1733 dev_err(cd
->dev
, "%s: failed to set mode to operational rc=%d\n",
1740 cyttsp4_lift_all(&cd
->md
);
1742 /* restore to sleep if was suspended */
1743 mutex_lock(&cd
->system_lock
);
1744 if (cd
->sleep_state
== SS_SLEEP_ON
) {
1745 cd
->sleep_state
= SS_SLEEP_OFF
;
1746 mutex_unlock(&cd
->system_lock
);
1747 cyttsp4_core_sleep_(cd
);
1750 mutex_unlock(&cd
->system_lock
);
1753 cyttsp4_start_wd_timer(cd
);
1758 static int cyttsp4_startup(struct cyttsp4
*cd
)
1762 mutex_lock(&cd
->system_lock
);
1763 cd
->startup_state
= STARTUP_RUNNING
;
1764 mutex_unlock(&cd
->system_lock
);
1766 rc
= cyttsp4_request_exclusive(cd
, cd
->dev
,
1767 CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
1769 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
1770 __func__
, cd
->exclusive_dev
, cd
->dev
);
1774 rc
= cyttsp4_startup_(cd
);
1776 if (cyttsp4_release_exclusive(cd
, cd
->dev
) < 0)
1777 /* Don't return fail code, mode is already changed. */
1778 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
1780 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
1783 mutex_lock(&cd
->system_lock
);
1784 cd
->startup_state
= STARTUP_NONE
;
1785 mutex_unlock(&cd
->system_lock
);
1787 /* Wake the waiters for end of startup */
1788 wake_up(&cd
->wait_q
);
1793 static void cyttsp4_startup_work_function(struct work_struct
*work
)
1795 struct cyttsp4
*cd
= container_of(work
, struct cyttsp4
, startup_work
);
1798 rc
= cyttsp4_startup(cd
);
1800 dev_err(cd
->dev
, "%s: Fail queued startup r=%d\n",
1804 static void cyttsp4_free_si_ptrs(struct cyttsp4
*cd
)
1806 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
1811 kfree(si
->si_ptrs
.cydata
);
1812 kfree(si
->si_ptrs
.test
);
1813 kfree(si
->si_ptrs
.pcfg
);
1814 kfree(si
->si_ptrs
.opcfg
);
1815 kfree(si
->si_ptrs
.ddata
);
1816 kfree(si
->si_ptrs
.mdata
);
1820 kfree(si
->btn_rec_data
);
1823 #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_RUNTIME)
1824 static int cyttsp4_core_suspend(struct device
*dev
)
1826 struct cyttsp4
*cd
= dev_get_drvdata(dev
);
1827 struct cyttsp4_mt_data
*md
= &cd
->md
;
1830 md
->is_suspended
= true;
1832 rc
= cyttsp4_core_sleep(cd
);
1834 dev_err(dev
, "%s: Error on sleep\n", __func__
);
1840 static int cyttsp4_core_resume(struct device
*dev
)
1842 struct cyttsp4
*cd
= dev_get_drvdata(dev
);
1843 struct cyttsp4_mt_data
*md
= &cd
->md
;
1846 md
->is_suspended
= false;
1848 rc
= cyttsp4_core_wake(cd
);
1850 dev_err(dev
, "%s: Error on wake\n", __func__
);
1858 const struct dev_pm_ops cyttsp4_pm_ops
= {
1859 SET_SYSTEM_SLEEP_PM_OPS(cyttsp4_core_suspend
, cyttsp4_core_resume
)
1860 SET_RUNTIME_PM_OPS(cyttsp4_core_suspend
, cyttsp4_core_resume
, NULL
)
1862 EXPORT_SYMBOL_GPL(cyttsp4_pm_ops
);
1864 static int cyttsp4_mt_open(struct input_dev
*input
)
1866 pm_runtime_get(input
->dev
.parent
);
1870 static void cyttsp4_mt_close(struct input_dev
*input
)
1872 struct cyttsp4_mt_data
*md
= input_get_drvdata(input
);
1873 mutex_lock(&md
->report_lock
);
1874 if (!md
->is_suspended
)
1875 pm_runtime_put(input
->dev
.parent
);
1876 mutex_unlock(&md
->report_lock
);
1880 static int cyttsp4_setup_input_device(struct cyttsp4
*cd
)
1882 struct device
*dev
= cd
->dev
;
1883 struct cyttsp4_mt_data
*md
= &cd
->md
;
1884 int signal
= CY_IGNORE_VALUE
;
1885 int max_x
, max_y
, max_p
, min
, max
;
1886 int max_x_tmp
, max_y_tmp
;
1890 dev_vdbg(dev
, "%s: Initialize event signals\n", __func__
);
1891 __set_bit(EV_ABS
, md
->input
->evbit
);
1892 __set_bit(EV_REL
, md
->input
->evbit
);
1893 __set_bit(EV_KEY
, md
->input
->evbit
);
1895 max_x_tmp
= md
->si
->si_ofs
.max_x
;
1896 max_y_tmp
= md
->si
->si_ofs
.max_y
;
1898 /* get maximum values from the sysinfo data */
1899 if (md
->pdata
->flags
& CY_FLAG_FLIP
) {
1900 max_x
= max_y_tmp
- 1;
1901 max_y
= max_x_tmp
- 1;
1903 max_x
= max_x_tmp
- 1;
1904 max_y
= max_y_tmp
- 1;
1906 max_p
= md
->si
->si_ofs
.max_p
;
1908 /* set event signal capabilities */
1909 for (i
= 0; i
< (md
->pdata
->frmwrk
->size
/ CY_NUM_ABS_SET
); i
++) {
1910 signal
= md
->pdata
->frmwrk
->abs
1911 [(i
* CY_NUM_ABS_SET
) + CY_SIGNAL_OST
];
1912 if (signal
!= CY_IGNORE_VALUE
) {
1913 __set_bit(signal
, md
->input
->absbit
);
1914 min
= md
->pdata
->frmwrk
->abs
1915 [(i
* CY_NUM_ABS_SET
) + CY_MIN_OST
];
1916 max
= md
->pdata
->frmwrk
->abs
1917 [(i
* CY_NUM_ABS_SET
) + CY_MAX_OST
];
1918 if (i
== CY_ABS_ID_OST
) {
1919 /* shift track ids down to start at 0 */
1922 } else if (i
== CY_ABS_X_OST
)
1924 else if (i
== CY_ABS_Y_OST
)
1926 else if (i
== CY_ABS_P_OST
)
1928 input_set_abs_params(md
->input
, signal
, min
, max
,
1929 md
->pdata
->frmwrk
->abs
1930 [(i
* CY_NUM_ABS_SET
) + CY_FUZZ_OST
],
1931 md
->pdata
->frmwrk
->abs
1932 [(i
* CY_NUM_ABS_SET
) + CY_FLAT_OST
]);
1933 dev_dbg(dev
, "%s: register signal=%02X min=%d max=%d\n",
1934 __func__
, signal
, min
, max
);
1935 if ((i
== CY_ABS_ID_OST
) &&
1936 (md
->si
->si_ofs
.tch_rec_size
<
1937 CY_TMA4XX_TCH_REC_SIZE
))
1942 input_mt_init_slots(md
->input
, md
->si
->si_ofs
.tch_abs
[CY_TCH_T
].max
,
1944 rc
= input_register_device(md
->input
);
1946 dev_err(dev
, "%s: Error, failed register input device r=%d\n",
1951 static int cyttsp4_mt_probe(struct cyttsp4
*cd
)
1953 struct device
*dev
= cd
->dev
;
1954 struct cyttsp4_mt_data
*md
= &cd
->md
;
1955 struct cyttsp4_mt_platform_data
*pdata
= cd
->pdata
->mt_pdata
;
1958 mutex_init(&md
->report_lock
);
1960 /* Create the input device and register it. */
1961 dev_vdbg(dev
, "%s: Create the input device and register it\n",
1963 md
->input
= input_allocate_device();
1964 if (md
->input
== NULL
) {
1965 dev_err(dev
, "%s: Error, failed to allocate input device\n",
1968 goto error_alloc_failed
;
1971 md
->input
->name
= pdata
->inp_dev_name
;
1972 scnprintf(md
->phys
, sizeof(md
->phys
)-1, "%s", dev_name(dev
));
1973 md
->input
->phys
= md
->phys
;
1974 md
->input
->id
.bustype
= cd
->bus_ops
->bustype
;
1975 md
->input
->dev
.parent
= dev
;
1976 md
->input
->open
= cyttsp4_mt_open
;
1977 md
->input
->close
= cyttsp4_mt_close
;
1978 input_set_drvdata(md
->input
, md
);
1981 md
->si
= &cd
->sysinfo
;
1983 dev_err(dev
, "%s: Fail get sysinfo pointer from core p=%p\n",
1985 goto error_get_sysinfo
;
1988 rc
= cyttsp4_setup_input_device(cd
);
1990 goto error_init_input
;
1995 input_free_device(md
->input
);
1997 input_set_drvdata(md
->input
, NULL
);
1999 dev_err(dev
, "%s failed.\n", __func__
);
2003 struct cyttsp4
*cyttsp4_probe(const struct cyttsp4_bus_ops
*ops
,
2004 struct device
*dev
, u16 irq
, size_t xfer_buf_size
)
2007 struct cyttsp4_platform_data
*pdata
= dev_get_platdata(dev
);
2008 unsigned long irq_flags
;
2011 if (!pdata
|| !pdata
->core_pdata
|| !pdata
->mt_pdata
) {
2012 dev_err(dev
, "%s: Missing platform data\n", __func__
);
2014 goto error_no_pdata
;
2017 cd
= kzalloc(sizeof(*cd
), GFP_KERNEL
);
2019 dev_err(dev
, "%s: Error, kzalloc\n", __func__
);
2021 goto error_alloc_data
;
2024 cd
->xfer_buf
= kzalloc(xfer_buf_size
, GFP_KERNEL
);
2025 if (!cd
->xfer_buf
) {
2026 dev_err(dev
, "%s: Error, kzalloc\n", __func__
);
2031 /* Initialize device info */
2034 cd
->cpdata
= pdata
->core_pdata
;
2037 /* Initialize mutexes and spinlocks */
2038 mutex_init(&cd
->system_lock
);
2039 mutex_init(&cd
->adap_lock
);
2041 /* Initialize wait queue */
2042 init_waitqueue_head(&cd
->wait_q
);
2044 /* Initialize works */
2045 INIT_WORK(&cd
->startup_work
, cyttsp4_startup_work_function
);
2046 INIT_WORK(&cd
->watchdog_work
, cyttsp4_watchdog_work
);
2048 /* Initialize IRQ */
2049 cd
->irq
= gpio_to_irq(cd
->cpdata
->irq_gpio
);
2052 goto error_free_xfer
;
2055 dev_set_drvdata(dev
, cd
);
2057 /* Call platform init function */
2058 if (cd
->cpdata
->init
) {
2059 dev_dbg(cd
->dev
, "%s: Init HW\n", __func__
);
2060 rc
= cd
->cpdata
->init(cd
->cpdata
, 1, cd
->dev
);
2062 dev_dbg(cd
->dev
, "%s: No HW INIT function\n", __func__
);
2066 dev_err(cd
->dev
, "%s: HW Init fail r=%d\n", __func__
, rc
);
2068 dev_dbg(dev
, "%s: initialize threaded irq=%d\n", __func__
, cd
->irq
);
2069 if (cd
->cpdata
->level_irq_udelay
> 0)
2070 /* use level triggered interrupts */
2071 irq_flags
= IRQF_TRIGGER_LOW
| IRQF_ONESHOT
;
2073 /* use edge triggered interrupts */
2074 irq_flags
= IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
;
2076 rc
= request_threaded_irq(cd
->irq
, NULL
, cyttsp4_irq
, irq_flags
,
2079 dev_err(dev
, "%s: Error, could not request irq\n", __func__
);
2080 goto error_request_irq
;
2083 /* Setup watchdog timer */
2084 setup_timer(&cd
->watchdog_timer
, cyttsp4_watchdog_timer
,
2088 * call startup directly to ensure that the device
2089 * is tested before leaving the probe
2091 rc
= cyttsp4_startup(cd
);
2093 /* Do not fail probe if startup fails but the device is detected */
2094 if (rc
< 0 && cd
->mode
== CY_MODE_UNKNOWN
) {
2095 dev_err(cd
->dev
, "%s: Fail initial startup r=%d\n",
2100 rc
= cyttsp4_mt_probe(cd
);
2102 dev_err(dev
, "%s: Error, fail mt probe\n", __func__
);
2106 pm_runtime_enable(dev
);
2111 cancel_work_sync(&cd
->startup_work
);
2112 cyttsp4_stop_wd_timer(cd
);
2113 pm_runtime_disable(dev
);
2114 cyttsp4_free_si_ptrs(cd
);
2115 free_irq(cd
->irq
, cd
);
2117 if (cd
->cpdata
->init
)
2118 cd
->cpdata
->init(cd
->cpdata
, 0, dev
);
2119 dev_set_drvdata(dev
, NULL
);
2121 kfree(cd
->xfer_buf
);
2126 dev_err(dev
, "%s failed.\n", __func__
);
2129 EXPORT_SYMBOL_GPL(cyttsp4_probe
);
2131 static void cyttsp4_mt_release(struct cyttsp4_mt_data
*md
)
2133 input_unregister_device(md
->input
);
2134 input_set_drvdata(md
->input
, NULL
);
2137 int cyttsp4_remove(struct cyttsp4
*cd
)
2139 struct device
*dev
= cd
->dev
;
2141 cyttsp4_mt_release(&cd
->md
);
2144 * Suspend the device before freeing the startup_work and stopping
2145 * the watchdog since sleep function restarts watchdog on failure
2147 pm_runtime_suspend(dev
);
2148 pm_runtime_disable(dev
);
2150 cancel_work_sync(&cd
->startup_work
);
2152 cyttsp4_stop_wd_timer(cd
);
2154 free_irq(cd
->irq
, cd
);
2155 if (cd
->cpdata
->init
)
2156 cd
->cpdata
->init(cd
->cpdata
, 0, dev
);
2157 dev_set_drvdata(dev
, NULL
);
2158 cyttsp4_free_si_ptrs(cd
);
2162 EXPORT_SYMBOL_GPL(cyttsp4_remove
);
2164 MODULE_LICENSE("GPL");
2165 MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen core driver");
2166 MODULE_AUTHOR("Cypress");