1 /* BEGIN PN:DTS2013051703879 ,Added by l00184147, 2013/5/17*/
2 //add Touch driver for G610-T11
3 /* BEGIN PN:DTS2013012601133 ,Modified by l00184147, 2013/1/26*/
4 /* BEGIN PN:DTS2013011401860 ,Modified by l00184147, 2013/1/14*/
5 /* BEGIN PN:SPBB-1218 ,Added by l00184147, 2012/12/20*/
8 * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
9 * For use with Cypress Txx4xx parts.
10 * Supported parts include:
14 * Copyright (C) 2012 Cypress Semiconductor
15 * Copyright (C) 2011 Sony Ericsson Mobile Communications AB.
17 * Author: Aleksej Makarov <aleksej.makarov@sonyericsson.com>
18 * Modified by: Cypress Semiconductor to add device functions
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * version 2, and only version 2, as published by the
23 * Free Software Foundation.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
37 extern void cyttsp4_mtk_gpio_interrupt_register();
38 extern void cyttsp4_mtk_gpio_interrupt_enable();
39 extern void cyttsp4_mtk_gpio_interrupt_disable();
43 #include <asm/unaligned.h>
44 #include <linux/delay.h>
45 #include <linux/gpio.h>
46 #include <linux/input.h>
47 #include <linux/interrupt.h>
48 #include <linux/irq.h>
49 #include <linux/limits.h>
50 #include <linux/module.h>
51 #include <linux/pm_runtime.h>
52 #include <linux/sched.h>
53 #include <linux/slab.h>
54 #include <linux/workqueue.h>
55 #include <linux/kthread.h>
56 /* BEGIN PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
57 //add earlysuspend head file
58 #ifdef CONFIG_HAS_EARLYSUSPEND
59 #include <linux/earlysuspend.h>
61 /* END PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
63 #include "cyttsp4_bus.h"
64 #include "cyttsp4_core.h"
65 #include "cyttsp4_regs.h"
66 /* BEGIN PN:DTS2013040204005 ,Added by l00184147, 2013/4/2*/
67 //#include <linux/hardware_self_adapt.h>
68 #include <mach/mt_gpio.h>
69 #include <mach/mt_pm_ldo.h>
70 #include <cust_gpio_usage.h>
72 //#define GPIO_CTP_RST_PIN GPIO8
73 /* END PN:DTS2013040204005 ,Modified by l00184147, 2013/4/2*/
77 #define CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT 5000
78 /* BEGIN PN: SPBB-1254 ,Modified by f00184246, 2013/2/18*/
79 #define CY_CORE_MODE_CHANGE_TIMEOUT 5000
80 /* BEGIN PN: SPBB-1254 ,Modified by f00184246, 2013/2/18*/
81 #define CY_CORE_RESET_AND_WAIT_TIMEOUT 1000
82 #define CY_CORE_WAKEUP_TIMEOUT 1000
84 #define CY_CORE_BL_HOST_SYNC_BYTE 0xFF
86 #define CY_CORE_READTIMES 3
88 #define HI_BYTE(x) (u8)(((x) >> 8) & 0xFF)
89 #define LO_BYTE(x) (u8)((x) & 0xFF)
90 /* BEGIN PN:DTS2013021701945 ,Added by l00184147, 2013/2/17*/
91 #define CYTTSP4_WATCHDOG_NULL_CMD
92 /* END PN:DTS2013021701945 ,Added by l00184147, 2013/2/17*/
93 /* BEGIN PN:DTS2013033005872 ,Added by F00184246, 2013/3/30*/
94 #define HUAWEI_SET_FINGER_MODE_BY_DEFAULT
95 /* END PN:DTS2013033005872 ,Added by F00184246, 2013/3/30*/
96 static const u8 security_key
[] = {
97 0xA5, 0x01, 0x02, 0x03, 0xFF, 0xFE, 0xFD, 0x5A
100 static const u8 ldr_exit
[] = {
101 0xFF, 0x01, 0x3B, 0x00, 0x00, 0x4F, 0x6D, 0x17
104 static const u8 ldr_err_app
[] = {
105 0x01, 0x02, 0x00, 0x00, 0x55, 0xDD, 0x17
108 /* BEGIN PN: SPBB-1253 ,Modified by l00184147, 2013/2/19*/
109 /* BEGIN PN:DTS2013053100307 ,Added by l00184147, 2013/06/17*/
110 MODULE_FIRMWARE(CY_FW_FILE_G750_NAME
);
111 /* END PN:DTS2013053100307 ,Added by l00184147, 2013/06/17*/
112 /* END PN: SPBB-1253 ,Modified by l00184147, 2013/2/19*/
114 const char *cy_driver_core_name
= CYTTSP4_CORE_NAME
;
115 const char *cy_driver_core_version
= CY_DRIVER_VERSION
;
116 const char *cy_driver_core_date
= CY_DRIVER_DATE
;
118 enum cyttsp4_sleep_state
{
125 enum cyttsp4_startup_state
{
132 enum cyttsp4_opmode
{
138 struct cyttsp4_core_data
{
140 struct cyttsp4_core
*core
;
141 struct list_head atten_list
[CY_ATTEN_NUM_ATTEN
];
142 struct mutex system_lock
;
143 struct mutex adap_lock
;
144 enum cyttsp4_mode mode
;
145 enum cyttsp4_sleep_state sleep_state
;
146 enum cyttsp4_startup_state startup_state
;
147 enum cyttsp4_opmode opmode
;
151 struct cyttsp4_core_platform_data
*pdata
;
152 wait_queue_head_t wait_q
;
153 wait_queue_head_t sleep_q
;
155 struct workqueue_struct
*startup_work_q
;
156 struct work_struct startup_work
;
157 struct workqueue_struct
*mode_change_work_q
;
158 struct work_struct mode_change_work
;
159 struct cyttsp4_sysinfo sysinfo
;
165 u8 pr_buf
[CY_MAX_PRBUF_SIZE
];
167 struct work_struct watchdog_work
;
168 struct timer_list watchdog_timer
;
169 /* BEGIN PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
170 //add the early_suspend structure
171 #ifdef CONFIG_HAS_EARLYSUSPEND
172 struct early_suspend es
;
174 /* END PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
178 struct list_head node
;
179 int (*func
)(struct cyttsp4_device
*);
180 struct cyttsp4_device
*ttsp
;
184 static inline size_t merge_bytes(u8 high
, u8 low
)
186 return (high
<< 8) + low
;
190 void cyttsp4_pr_buf(struct device
*dev
, u8
*pr_buf
, u8
*dptr
, int size
,
191 const char *data_name
)
194 const char fmt
[] = "%02X ";
200 max
= (CY_MAX_PRBUF_SIZE
- 1) - sizeof(CY_PR_TRUNCATED
);
203 for (i
= k
= 0; i
< size
&& k
< max
; i
++, k
+= 3)
204 scnprintf(pr_buf
+ k
, CY_MAX_PRBUF_SIZE
, fmt
, dptr
[i
]);
206 dev_vdbg(dev
, "%s: %s[0..%d]=%s%s\n", __func__
, data_name
, size
- 1,
207 pr_buf
, size
<= max
? "" : CY_PR_TRUNCATED
);
209 EXPORT_SYMBOL(cyttsp4_pr_buf
);
212 static u16
cyttsp4_calc_partial_app_crc(const u8
*data
, int size
, u16 crc
)
216 for (i
= 0; i
< size
; i
++) {
217 crc
^= ((u16
)data
[i
] << 8);
218 for (j
= 8; j
> 0; j
--)
220 crc
= (crc
<< 1) ^ 0x1021;
228 static inline u16
cyttsp4_calc_app_crc(const u8
*data
, int size
)
230 return cyttsp4_calc_partial_app_crc(data
, size
, 0xFFFF);
233 static int cyttsp4_load_status_regs(struct cyttsp4_core_data
*cd
)
235 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
236 struct device
*dev
= cd
->dev
;
240 dev_err(cd
->dev
, "%s: NULL xy_mode pointer\n", __func__
);
244 rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
,
245 si
->xy_mode
, si
->si_ofs
.mode_size
);
247 dev_err(dev
, "%s: fail read mode regs r=%d\n",
250 cyttsp4_pr_buf(dev
, cd
->pr_buf
, si
->xy_mode
,
251 si
->si_ofs
.mode_size
, "xy_mode");
256 static int cyttsp4_handshake(struct cyttsp4_core_data
*cd
, u8 mode
)
258 u8 cmd
= mode
^ CY_HST_TOGGLE
;
261 if (mode
& CY_HST_MODE_CHANGE
) {
262 dev_err(cd
->dev
, "%s: Host mode change bit set, NO handshake\n",
267 rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
, &cmd
,
271 dev_err(cd
->dev
, "%s: bus write fail on handshake (ret=%d)\n",
277 static int cyttsp4_toggle_low_power(struct cyttsp4_core_data
*cd
, u8 mode
)
279 u8 cmd
= mode
^ CY_HST_LOWPOW
;
280 int rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
, &cmd
,
284 "%s: bus write fail on toggle low power (ret=%d)\n",
289 static int cyttsp4_set_low_power(struct cyttsp4_core_data
*cd
, bool enable
)
292 int rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, &mode
,
296 "%s: bus read fail on set low power (ret=%d)\n",
302 mode
|= CY_HST_LOWPOW
;
304 mode
&= ~CY_HST_LOWPOW
;
306 rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
, &mode
,
310 "%s: bus write fail on set low power (ret=%d)\n",
318 static int cyttsp4_get_low_power(struct cyttsp4_core_data
*cd
, bool *enable
)
321 int rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, &mode
,
325 "%s: bus read fail on set low power (ret=%d)\n",
330 if (mode
& CY_HST_LOWPOW
)
339 static int cyttsp4_hw_soft_reset(struct cyttsp4_core_data
*cd
)
341 u8 cmd
= CY_HST_RESET
| CY_HST_MODE_CHANGE
;
342 int rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
, &cmd
,
345 dev_err(cd
->dev
, "%s: FAILED to execute SOFT reset\n",
349 dev_dbg(cd
->dev
, "%s: execute SOFT reset\n", __func__
);
353 static int cyttsp4_hw_hard_reset(struct cyttsp4_core_data
*cd
)
355 if (cd
->pdata
->xres
) {
356 cd
->pdata
->xres(cd
->pdata
, cd
->dev
);
357 dev_dbg(cd
->dev
, "%s: execute HARD reset\n", __func__
);
360 dev_err(cd
->dev
, "%s: FAILED to execute HARD reset\n", __func__
);
364 static int cyttsp4_hw_reset(struct cyttsp4_core_data
*cd
)
366 int rc
= cyttsp4_hw_hard_reset(cd
);
368 rc
= cyttsp4_hw_soft_reset(cd
);
372 static inline int cyttsp4_bits_2_bytes(int nbits
, int *max
)
375 return (nbits
+ 7) / 8;
378 static int cyttsp4_si_data_offsets(struct cyttsp4_core_data
*cd
)
380 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
381 int rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, &si
->si_data
,
382 sizeof(si
->si_data
));
384 dev_err(cd
->dev
, "%s: fail read sysinfo data offsets r=%d\n",
389 /* Print sysinfo data offsets */
390 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)&si
->si_data
,
391 sizeof(si
->si_data
), "sysinfo_data_offsets");
393 /* convert sysinfo data offset bytes into integers */
395 si
->si_ofs
.map_sz
= merge_bytes(si
->si_data
.map_szh
,
396 si
->si_data
.map_szl
);
397 si
->si_ofs
.map_sz
= merge_bytes(si
->si_data
.map_szh
,
398 si
->si_data
.map_szl
);
399 si
->si_ofs
.cydata_ofs
= merge_bytes(si
->si_data
.cydata_ofsh
,
400 si
->si_data
.cydata_ofsl
);
401 si
->si_ofs
.test_ofs
= merge_bytes(si
->si_data
.test_ofsh
,
402 si
->si_data
.test_ofsl
);
403 si
->si_ofs
.pcfg_ofs
= merge_bytes(si
->si_data
.pcfg_ofsh
,
404 si
->si_data
.pcfg_ofsl
);
405 si
->si_ofs
.opcfg_ofs
= merge_bytes(si
->si_data
.opcfg_ofsh
,
406 si
->si_data
.opcfg_ofsl
);
407 si
->si_ofs
.ddata_ofs
= merge_bytes(si
->si_data
.ddata_ofsh
,
408 si
->si_data
.ddata_ofsl
);
409 si
->si_ofs
.mdata_ofs
= merge_bytes(si
->si_data
.mdata_ofsh
,
410 si
->si_data
.mdata_ofsl
);
414 static int cyttsp4_si_get_cydata(struct cyttsp4_core_data
*cd
)
416 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
421 struct cyttsp4_cydata
*cydata
;
423 /* Allocate a temp buffer for reading CYDATA registers */
424 si
->si_ofs
.cydata_size
= si
->si_ofs
.test_ofs
- si
->si_ofs
.cydata_ofs
;
425 dev_dbg(cd
->dev
, "%s: cydata size: %d\n", __func__
,
426 si
->si_ofs
.cydata_size
);
427 buf
= kzalloc(si
->si_ofs
.cydata_size
, GFP_KERNEL
);
429 dev_err(cd
->dev
, "%s: fail alloc buffer for reading cydata\n",
434 /* Read the CYDA registers to the temp buf */
435 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.cydata_ofs
,
436 buf
, si
->si_ofs
.cydata_size
);
438 dev_err(cd
->dev
, "%s: fail read cydata r=%d\n",
443 /* Allocate local cydata structure */
444 if (si
->si_ptrs
.cydata
== NULL
)
445 si
->si_ptrs
.cydata
= kzalloc(sizeof(struct cyttsp4_cydata
),
447 if (si
->si_ptrs
.cydata
== NULL
) {
448 dev_err(cd
->dev
, "%s: fail alloc cydata memory\n", __func__
);
453 cydata
= (struct cyttsp4_cydata
*)buf
;
455 /* Allocate MFGID memory */
456 if (si
->si_ptrs
.cydata
->mfg_id
== NULL
)
457 si
->si_ptrs
.cydata
->mfg_id
= kzalloc(cydata
->mfgid_sz
,
459 if (si
->si_ptrs
.cydata
->mfg_id
== NULL
) {
460 kfree(si
->si_ptrs
.cydata
);
461 si
->si_ptrs
.cydata
= NULL
;
462 dev_err(cd
->dev
, "%s: fail alloc mfgid memory\n", __func__
);
467 /* Copy all fields up to MFGID to local cydata structure */
469 size
= offsetof(struct cyttsp4_cydata
, mfgid_sz
) + 1;
470 memcpy(si
->si_ptrs
.cydata
, p
, size
);
472 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)si
->si_ptrs
.cydata
,
473 size
, "sysinfo_cydata");
477 memcpy(si
->si_ptrs
.cydata
->mfg_id
, p
, si
->si_ptrs
.cydata
->mfgid_sz
);
479 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)si
->si_ptrs
.cydata
->mfg_id
,
480 si
->si_ptrs
.cydata
->mfgid_sz
, "sysinfo_cydata mfgid");
482 /* Copy remaining registers after MFGID */
483 p
+= si
->si_ptrs
.cydata
->mfgid_sz
;
484 size
= sizeof(struct cyttsp4_cydata
) -
485 offsetof(struct cyttsp4_cydata
, cyito_idh
);
486 memcpy((u8
*)&si
->si_ptrs
.cydata
->cyito_idh
, p
, size
);
488 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, &si
->si_ptrs
.cydata
->cyito_idh
,
489 size
, "sysinfo_cydata");
496 static int cyttsp4_si_get_test_data(struct cyttsp4_core_data
*cd
)
498 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
501 si
->si_ofs
.test_size
= si
->si_ofs
.pcfg_ofs
- si
->si_ofs
.test_ofs
;
502 if (si
->si_ptrs
.test
== NULL
)
503 si
->si_ptrs
.test
= kzalloc(si
->si_ofs
.test_size
, GFP_KERNEL
);
504 if (si
->si_ptrs
.test
== NULL
) {
505 dev_err(cd
->dev
, "%s: fail alloc test memory\n", __func__
);
509 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.test_ofs
,
510 si
->si_ptrs
.test
, si
->si_ofs
.test_size
);
512 dev_err(cd
->dev
, "%s: fail read test data r=%d\n",
517 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
518 (u8
*)si
->si_ptrs
.test
, si
->si_ofs
.test_size
,
519 "sysinfo_test_data");
520 if (si
->si_ptrs
.test
->post_codel
&
521 CY_POST_CODEL_WDG_RST
)
522 dev_info(cd
->dev
, "%s: %s codel=%02X\n",
523 __func__
, "Reset was a WATCHDOG RESET",
524 si
->si_ptrs
.test
->post_codel
);
526 if (!(si
->si_ptrs
.test
->post_codel
&
527 CY_POST_CODEL_CFG_DATA_CRC_FAIL
))
528 dev_info(cd
->dev
, "%s: %s codel=%02X\n", __func__
,
529 "Config Data CRC FAIL",
530 si
->si_ptrs
.test
->post_codel
);
532 if (!(si
->si_ptrs
.test
->post_codel
&
533 CY_POST_CODEL_PANEL_TEST_FAIL
))
534 dev_info(cd
->dev
, "%s: %s codel=%02X\n",
535 __func__
, "PANEL TEST FAIL",
536 si
->si_ptrs
.test
->post_codel
);
538 dev_info(cd
->dev
, "%s: SCANNING is %s codel=%02X\n",
539 __func__
, si
->si_ptrs
.test
->post_codel
& 0x08 ?
540 "ENABLED" : "DISABLED",
541 si
->si_ptrs
.test
->post_codel
);
545 static int cyttsp4_si_get_pcfg_data(struct cyttsp4_core_data
*cd
)
547 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
550 dev_vdbg(cd
->dev
, "%s: get pcfg data\n", __func__
);
551 si
->si_ofs
.pcfg_size
= si
->si_ofs
.opcfg_ofs
- si
->si_ofs
.pcfg_ofs
;
552 if (si
->si_ptrs
.pcfg
== NULL
)
553 si
->si_ptrs
.pcfg
= kzalloc(si
->si_ofs
.pcfg_size
, GFP_KERNEL
);
554 if (si
->si_ptrs
.pcfg
== NULL
) {
556 dev_err(cd
->dev
, "%s: fail alloc pcfg memory r=%d\n",
560 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.pcfg_ofs
,
561 si
->si_ptrs
.pcfg
, si
->si_ofs
.pcfg_size
);
563 dev_err(cd
->dev
, "%s: fail read pcfg data r=%d\n",
568 si
->si_ofs
.max_x
= merge_bytes((si
->si_ptrs
.pcfg
->res_xh
569 & CY_PCFG_RESOLUTION_X_MASK
), si
->si_ptrs
.pcfg
->res_xl
);
570 si
->si_ofs
.x_origin
= !!(si
->si_ptrs
.pcfg
->res_xh
571 & CY_PCFG_ORIGIN_X_MASK
);
572 si
->si_ofs
.max_y
= merge_bytes((si
->si_ptrs
.pcfg
->res_yh
573 & CY_PCFG_RESOLUTION_Y_MASK
), si
->si_ptrs
.pcfg
->res_yl
);
574 si
->si_ofs
.y_origin
= !!(si
->si_ptrs
.pcfg
->res_yh
575 & CY_PCFG_ORIGIN_Y_MASK
);
576 si
->si_ofs
.max_p
= merge_bytes(si
->si_ptrs
.pcfg
->max_zh
,
577 si
->si_ptrs
.pcfg
->max_zl
);
579 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
580 (u8
*)si
->si_ptrs
.pcfg
,
581 si
->si_ofs
.pcfg_size
, "sysinfo_pcfg_data");
585 static int cyttsp4_si_get_opcfg_data(struct cyttsp4_core_data
*cd
)
587 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
589 enum cyttsp4_tch_abs abs
;
592 dev_vdbg(cd
->dev
, "%s: get opcfg data\n", __func__
);
593 si
->si_ofs
.opcfg_size
= si
->si_ofs
.ddata_ofs
- si
->si_ofs
.opcfg_ofs
;
594 if (si
->si_ptrs
.opcfg
== NULL
)
595 si
->si_ptrs
.opcfg
= kzalloc(si
->si_ofs
.opcfg_size
, GFP_KERNEL
);
596 if (si
->si_ptrs
.opcfg
== NULL
) {
597 dev_err(cd
->dev
, "%s: fail alloc opcfg memory\n", __func__
);
599 goto cyttsp4_si_get_opcfg_data_exit
;
602 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.opcfg_ofs
,
603 si
->si_ptrs
.opcfg
, si
->si_ofs
.opcfg_size
);
605 dev_err(cd
->dev
, "%s: fail read opcfg data r=%d\n",
607 goto cyttsp4_si_get_opcfg_data_exit
;
609 si
->si_ofs
.cmd_ofs
= si
->si_ptrs
.opcfg
->cmd_ofs
;
610 si
->si_ofs
.rep_ofs
= si
->si_ptrs
.opcfg
->rep_ofs
;
611 si
->si_ofs
.rep_sz
= (si
->si_ptrs
.opcfg
->rep_szh
* 256) +
612 si
->si_ptrs
.opcfg
->rep_szl
;
613 si
->si_ofs
.num_btns
= si
->si_ptrs
.opcfg
->num_btns
;
614 si
->si_ofs
.num_btn_regs
= (si
->si_ofs
.num_btns
+
615 CY_NUM_BTN_PER_REG
- 1) / CY_NUM_BTN_PER_REG
;
616 si
->si_ofs
.tt_stat_ofs
= si
->si_ptrs
.opcfg
->tt_stat_ofs
;
617 si
->si_ofs
.obj_cfg0
= si
->si_ptrs
.opcfg
->obj_cfg0
;
618 si
->si_ofs
.max_tchs
= si
->si_ptrs
.opcfg
->max_tchs
&
620 si
->si_ofs
.tch_rec_size
= si
->si_ptrs
.opcfg
->tch_rec_size
&
623 /* Get the old touch fields */
624 for (abs
= CY_TCH_X
; abs
< CY_NUM_TCH_FIELDS
; abs
++) {
625 si
->si_ofs
.tch_abs
[abs
].ofs
=
626 si
->si_ptrs
.opcfg
->tch_rec_old
[abs
].loc
&
628 si
->si_ofs
.tch_abs
[abs
].size
=
630 (si
->si_ptrs
.opcfg
->tch_rec_old
[abs
].size
,
631 &si
->si_ofs
.tch_abs
[abs
].max
);
632 si
->si_ofs
.tch_abs
[abs
].bofs
=
633 (si
->si_ptrs
.opcfg
->tch_rec_old
[abs
].loc
&
634 CY_BOFS_MASK
) >> CY_BOFS_SHIFT
;
638 si
->si_ofs
.btn_rec_size
= si
->si_ptrs
.opcfg
->btn_rec_size
;
639 si
->si_ofs
.btn_diff_ofs
= si
->si_ptrs
.opcfg
->btn_diff_ofs
;
640 si
->si_ofs
.btn_diff_size
= si
->si_ptrs
.opcfg
->btn_diff_size
;
642 if (si
->si_ofs
.tch_rec_size
> CY_TMA1036_TCH_REC_SIZE
) {
643 /* Get the extended touch fields */
644 for (i
= 0; i
< CY_NUM_EXT_TCH_FIELDS
; abs
++, i
++) {
645 si
->si_ofs
.tch_abs
[abs
].ofs
=
646 si
->si_ptrs
.opcfg
->tch_rec_new
[i
].loc
&
648 si
->si_ofs
.tch_abs
[abs
].size
=
650 (si
->si_ptrs
.opcfg
->tch_rec_new
[i
].size
,
651 &si
->si_ofs
.tch_abs
[abs
].max
);
652 si
->si_ofs
.tch_abs
[abs
].bofs
=
653 (si
->si_ptrs
.opcfg
->tch_rec_new
[i
].loc
654 & CY_BOFS_MASK
) >> CY_BOFS_SHIFT
;
658 for (abs
= 0; abs
< CY_TCH_NUM_ABS
; abs
++) {
659 dev_dbg(cd
->dev
, "%s: tch_rec_%s\n", __func__
,
660 cyttsp4_tch_abs_string
[abs
]);
661 dev_dbg(cd
->dev
, "%s: ofs =%2d\n", __func__
,
662 si
->si_ofs
.tch_abs
[abs
].ofs
);
663 dev_dbg(cd
->dev
, "%s: siz =%2d\n", __func__
,
664 si
->si_ofs
.tch_abs
[abs
].size
);
665 dev_dbg(cd
->dev
, "%s: max =%2d\n", __func__
,
666 si
->si_ofs
.tch_abs
[abs
].max
);
667 dev_dbg(cd
->dev
, "%s: bofs=%2d\n", __func__
,
668 si
->si_ofs
.tch_abs
[abs
].bofs
);
671 si
->si_ofs
.mode_size
= si
->si_ofs
.tt_stat_ofs
+ 1;
672 si
->si_ofs
.data_size
= si
->si_ofs
.max_tchs
*
673 si
->si_ptrs
.opcfg
->tch_rec_size
;
675 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, (u8
*)si
->si_ptrs
.opcfg
,
676 si
->si_ofs
.opcfg_size
, "sysinfo_opcfg_data");
678 cyttsp4_si_get_opcfg_data_exit
:
682 static int cyttsp4_si_get_ddata(struct cyttsp4_core_data
*cd
)
684 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
687 dev_vdbg(cd
->dev
, "%s: get ddata data\n", __func__
);
688 si
->si_ofs
.ddata_size
= si
->si_ofs
.mdata_ofs
- si
->si_ofs
.ddata_ofs
;
689 if (si
->si_ptrs
.ddata
== NULL
)
690 si
->si_ptrs
.ddata
= kzalloc(si
->si_ofs
.ddata_size
, GFP_KERNEL
);
691 if (si
->si_ptrs
.ddata
== NULL
) {
692 dev_err(cd
->dev
, "%s: fail alloc ddata memory\n", __func__
);
696 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.ddata_ofs
,
697 si
->si_ptrs
.ddata
, si
->si_ofs
.ddata_size
);
699 dev_err(cd
->dev
, "%s: fail read ddata data r=%d\n",
702 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
703 (u8
*)si
->si_ptrs
.ddata
,
704 si
->si_ofs
.ddata_size
, "sysinfo_ddata");
708 static int cyttsp4_si_get_mdata(struct cyttsp4_core_data
*cd
)
710 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
713 dev_vdbg(cd
->dev
, "%s: get mdata data\n", __func__
);
714 si
->si_ofs
.mdata_size
= si
->si_ofs
.map_sz
- si
->si_ofs
.mdata_ofs
;
715 if (si
->si_ptrs
.mdata
== NULL
)
716 si
->si_ptrs
.mdata
= kzalloc(si
->si_ofs
.mdata_size
, GFP_KERNEL
);
717 if (si
->si_ptrs
.mdata
== NULL
) {
718 dev_err(cd
->dev
, "%s: fail alloc mdata memory\n", __func__
);
722 rc
= cyttsp4_adap_read(cd
->core
->adap
, si
->si_ofs
.mdata_ofs
,
723 si
->si_ptrs
.mdata
, si
->si_ofs
.mdata_size
);
725 dev_err(cd
->dev
, "%s: fail read mdata data r=%d\n",
728 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
,
729 (u8
*)si
->si_ptrs
.mdata
,
730 si
->si_ofs
.mdata_size
, "sysinfo_mdata");
734 static int cyttsp4_si_get_btn_data(struct cyttsp4_core_data
*cd
)
736 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
738 int num_defined_keys
;
742 dev_vdbg(cd
->dev
, "%s: get btn data\n", __func__
);
743 if (si
->si_ofs
.num_btns
) {
744 si
->si_ofs
.btn_keys_size
= si
->si_ofs
.num_btns
*
745 sizeof(struct cyttsp4_btn
);
747 si
->btn
= kzalloc(si
->si_ofs
.btn_keys_size
, GFP_KERNEL
);
748 if (si
->btn
== NULL
) {
749 dev_err(cd
->dev
, "%s: %s\n", __func__
,
750 "fail alloc btn_keys memory");
753 if (cd
->pdata
->sett
[CY_IC_GRPNUM_BTN_KEYS
] == NULL
)
754 num_defined_keys
= 0;
755 else if (cd
->pdata
->sett
[CY_IC_GRPNUM_BTN_KEYS
]->data
== NULL
)
756 num_defined_keys
= 0;
758 num_defined_keys
= cd
->pdata
->sett
759 [CY_IC_GRPNUM_BTN_KEYS
]->size
;
761 for (btn
= 0; btn
< si
->si_ofs
.num_btns
&&
762 btn
< num_defined_keys
; btn
++) {
763 key_table
= (u16
*)cd
->pdata
->sett
764 [CY_IC_GRPNUM_BTN_KEYS
]->data
;
765 si
->btn
[btn
].key_code
= key_table
[btn
];
766 si
->btn
[btn
].enabled
= true;
768 for (; btn
< si
->si_ofs
.num_btns
; btn
++) {
769 si
->btn
[btn
].key_code
= KEY_RESERVED
;
770 si
->btn
[btn
].enabled
= true;
776 si
->si_ofs
.btn_keys_size
= 0;
782 static int cyttsp4_si_get_op_data_ptrs(struct cyttsp4_core_data
*cd
)
784 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
785 if (si
->xy_mode
== NULL
) {
786 si
->xy_mode
= kzalloc(si
->si_ofs
.mode_size
, GFP_KERNEL
);
787 if (si
->xy_mode
== NULL
)
791 if (si
->xy_data
== NULL
) {
792 si
->xy_data
= kzalloc(si
->si_ofs
.data_size
, GFP_KERNEL
);
793 if (si
->xy_data
== NULL
)
797 if (si
->btn_rec_data
== NULL
) {
798 si
->btn_rec_data
= kzalloc(si
->si_ofs
.btn_rec_size
*
799 si
->si_ofs
.num_btns
, GFP_KERNEL
);
800 if (si
->btn_rec_data
== NULL
)
803 #ifdef SHOK_SENSOR_DATA_MODE
805 si
->monitor
.mntr_status
= CY_MNTR_DISABLED
;
806 memset(si
->monitor
.sensor_data
, 0, sizeof(si
->monitor
.sensor_data
));
811 static void cyttsp4_si_put_log_data(struct cyttsp4_core_data
*cd
)
813 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
814 dev_dbg(cd
->dev
, "%s: cydata_ofs =%4d siz=%4d\n", __func__
,
815 si
->si_ofs
.cydata_ofs
, si
->si_ofs
.cydata_size
);
816 dev_dbg(cd
->dev
, "%s: test_ofs =%4d siz=%4d\n", __func__
,
817 si
->si_ofs
.test_ofs
, si
->si_ofs
.test_size
);
818 dev_dbg(cd
->dev
, "%s: pcfg_ofs =%4d siz=%4d\n", __func__
,
819 si
->si_ofs
.pcfg_ofs
, si
->si_ofs
.pcfg_size
);
820 dev_dbg(cd
->dev
, "%s: opcfg_ofs =%4d siz=%4d\n", __func__
,
821 si
->si_ofs
.opcfg_ofs
, si
->si_ofs
.opcfg_size
);
822 dev_dbg(cd
->dev
, "%s: ddata_ofs =%4d siz=%4d\n", __func__
,
823 si
->si_ofs
.ddata_ofs
, si
->si_ofs
.ddata_size
);
824 dev_dbg(cd
->dev
, "%s: mdata_ofs =%4d siz=%4d\n", __func__
,
825 si
->si_ofs
.mdata_ofs
, si
->si_ofs
.mdata_size
);
827 dev_dbg(cd
->dev
, "%s: cmd_ofs =%4d\n", __func__
,
829 dev_dbg(cd
->dev
, "%s: rep_ofs =%4d\n", __func__
,
831 dev_dbg(cd
->dev
, "%s: rep_sz =%4d\n", __func__
,
833 dev_dbg(cd
->dev
, "%s: num_btns =%4d\n", __func__
,
834 si
->si_ofs
.num_btns
);
835 dev_dbg(cd
->dev
, "%s: num_btn_regs =%4d\n", __func__
,
836 si
->si_ofs
.num_btn_regs
);
837 dev_dbg(cd
->dev
, "%s: tt_stat_ofs =%4d\n", __func__
,
838 si
->si_ofs
.tt_stat_ofs
);
839 dev_dbg(cd
->dev
, "%s: tch_rec_size =%4d\n", __func__
,
840 si
->si_ofs
.tch_rec_size
);
841 dev_dbg(cd
->dev
, "%s: max_tchs =%4d\n", __func__
,
842 si
->si_ofs
.max_tchs
);
843 dev_dbg(cd
->dev
, "%s: mode_size =%4d\n", __func__
,
844 si
->si_ofs
.mode_size
);
845 dev_dbg(cd
->dev
, "%s: data_size =%4d\n", __func__
,
846 si
->si_ofs
.data_size
);
847 dev_dbg(cd
->dev
, "%s: map_sz =%4d\n", __func__
,
850 dev_dbg(cd
->dev
, "%s: btn_rec_size =%2d\n", __func__
,
851 si
->si_ofs
.btn_rec_size
);
852 dev_dbg(cd
->dev
, "%s: btn_diff_ofs =%2d\n", __func__
,
853 si
->si_ofs
.btn_diff_ofs
);
854 dev_dbg(cd
->dev
, "%s: btn_diff_size =%2d\n", __func__
,
855 si
->si_ofs
.btn_diff_size
);
857 dev_dbg(cd
->dev
, "%s: max_x = 0x%04X (%d)\n", __func__
,
858 si
->si_ofs
.max_x
, si
->si_ofs
.max_x
);
859 dev_dbg(cd
->dev
, "%s: x_origin = %d (%s)\n", __func__
,
861 si
->si_ofs
.x_origin
== CY_NORMAL_ORIGIN
?
862 "left corner" : "right corner");
863 dev_dbg(cd
->dev
, "%s: max_y = 0x%04X (%d)\n", __func__
,
864 si
->si_ofs
.max_y
, si
->si_ofs
.max_y
);
865 dev_dbg(cd
->dev
, "%s: y_origin = %d (%s)\n", __func__
,
867 si
->si_ofs
.y_origin
== CY_NORMAL_ORIGIN
?
868 "upper corner" : "lower corner");
869 dev_dbg(cd
->dev
, "%s: max_p = 0x%04X (%d)\n", __func__
,
870 si
->si_ofs
.max_p
, si
->si_ofs
.max_p
);
872 dev_dbg(cd
->dev
, "%s: xy_mode=%p xy_data=%p\n", __func__
,
873 si
->xy_mode
, si
->xy_data
);
876 static int cyttsp4_get_sysinfo_regs(struct cyttsp4_core_data
*cd
)
878 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
881 rc
= cyttsp4_si_data_offsets(cd
);
885 rc
= cyttsp4_si_get_cydata(cd
);
889 rc
= cyttsp4_si_get_test_data(cd
);
893 rc
= cyttsp4_si_get_pcfg_data(cd
);
897 rc
= cyttsp4_si_get_opcfg_data(cd
);
901 rc
= cyttsp4_si_get_ddata(cd
);
905 rc
= cyttsp4_si_get_mdata(cd
);
909 rc
= cyttsp4_si_get_btn_data(cd
);
913 rc
= cyttsp4_si_get_op_data_ptrs(cd
);
915 dev_err(cd
->dev
, "%s: failed to get_op_data\n",
920 cyttsp4_si_put_log_data(cd
);
922 /* provide flow control handshake */
923 rc
= cyttsp4_handshake(cd
, si
->si_data
.hst_mode
);
925 dev_err(cd
->dev
, "%s: handshake fail on sysinfo reg\n",
932 static void cyttsp4_queue_startup_(struct cyttsp4_core_data
*cd
)
934 if (cd
->startup_state
== STARTUP_NONE
) {
935 cd
->startup_state
= STARTUP_QUEUED
;
936 queue_work(cd
->startup_work_q
, &cd
->startup_work
);
937 dev_info(cd
->dev
, "%s: cyttsp4_startup queued\n", __func__
);
939 dev_dbg(cd
->dev
, "%s: startup_state = %d\n", __func__
,
944 static void cyttsp4_queue_startup(struct cyttsp4_core_data
*cd
)
946 dev_vdbg(cd
->dev
, "%s: enter\n", __func__
);
947 mutex_lock(&cd
->system_lock
);
948 cyttsp4_queue_startup_(cd
);
949 mutex_unlock(&cd
->system_lock
);
952 static void call_atten_cb(struct cyttsp4_core_data
*cd
,
953 enum cyttsp4_atten_type type
, int mode
)
955 struct atten_node
*atten
, *atten_n
;
957 dev_vdbg(cd
->dev
, "%s: check list type=%d mode=%d\n",
958 __func__
, type
, mode
);
959 spin_lock(&cd
->spinlock
);
960 list_for_each_entry_safe(atten
, atten_n
,
961 &cd
->atten_list
[type
], node
) {
962 if (!mode
|| atten
->mode
& mode
) {
963 spin_unlock(&cd
->spinlock
);
964 dev_vdbg(cd
->dev
, "%s: attention for '%s'", __func__
,
965 dev_name(&atten
->ttsp
->dev
));
966 atten
->func(atten
->ttsp
);
967 spin_lock(&cd
->spinlock
);
970 spin_unlock(&cd
->spinlock
);
973 static irqreturn_t
cyttsp4_irq(int irq
, void *handle
)
975 struct cyttsp4_core_data
*cd
= handle
;
976 struct device
*dev
= cd
->dev
;
977 enum cyttsp4_mode cur_mode
;
978 u8 cmd_ofs
= cd
->sysinfo
.si_ofs
.cmd_ofs
;
984 * Check whether this IRQ should be ignored (external)
985 * This should be the very first thing to check since
986 * ignore_irq may be set for a very short period of time
988 if (atomic_read(&cd
->ignore_irq
)) {
989 dev_vdbg(dev
, "%s: Ignoring IRQ\n", __func__
);
993 dev_dbg(dev
, "%s int:0x%x\n", __func__
, cd
->int_status
);
995 mutex_lock(&cd
->system_lock
);
998 if (cd
->sleep_state
== SS_SLEEP_ON
) {
999 dev_vdbg(dev
, "%s: Received IRQ while in sleep\n",
1001 } else if (cd
->sleep_state
== SS_SLEEPING
) {
1002 dev_vdbg(dev
, "%s: Received IRQ while sleeping\n",
1006 rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, mode
, sizeof(mode
));
1008 dev_err(cd
->dev
, "%s: Fail read adapter r=%d\n", __func__
, rc
);
1009 goto cyttsp4_irq_exit
;
1011 dev_vdbg(dev
, "%s mode[0-2]:0x%X 0x%X 0x%X\n", __func__
,
1012 mode
[0], mode
[1], mode
[2]);
1015 /* Check for false bootloader interrupt */
1016 if (unlikely(mode
[0] == CY_CORE_BL_HOST_SYNC_BYTE
)
1017 && unlikely(cd
->mode
== CY_MODE_BOOTLOADER
)) {
1018 dev_err(dev
, "%s: False interrupt in bootloader mode\n", __func__
);
1019 goto cyttsp4_irq_exit
;
1022 if (IS_BOOTLOADER(mode
[0])) {
1023 cur_mode
= CY_MODE_BOOTLOADER
;
1024 dev_vdbg(dev
, "%s: bl running\n", __func__
);
1025 call_atten_cb(cd
, CY_ATTEN_IRQ
, cur_mode
);
1026 if (cd
->mode
== CY_MODE_BOOTLOADER
) {
1027 /* Signal bootloader heartbeat heard */
1028 wake_up(&cd
->wait_q
);
1029 goto cyttsp4_irq_exit
;
1032 /* switch to bootloader */
1033 dev_dbg(dev
, "%s: restart switch to bl m=%d -> m=%d\n",
1034 __func__
, cd
->mode
, cur_mode
);
1036 /* catch operation->bl glitch */
1037 if (cd
->mode
!= CY_MODE_UNKNOWN
) {
1038 /* Incase startup_state do not let startup_() */
1039 cd
->mode
= CY_MODE_UNKNOWN
;
1040 cyttsp4_queue_startup_(cd
);
1041 goto cyttsp4_irq_exit
;
1045 * do not wake thread on this switch since
1046 * it is possible to get an early heartbeat
1047 * prior to performing the reset
1049 cd
->mode
= cur_mode
;
1051 goto cyttsp4_irq_exit
;
1054 switch (mode
[0] & CY_HST_MODE
) {
1055 case CY_HST_OPERATE
:
1056 cur_mode
= CY_MODE_OPERATIONAL
;
1057 dev_vdbg(dev
, "%s: operational\n", __func__
);
1060 cur_mode
= CY_MODE_CAT
;
1061 /* set the start sensor mode state. */
1062 cat_masked_cmd
= mode
[2] & CY_CMD_MASK
;
1064 #ifdef SHOK_SENSOR_DATA_MODE
1065 if (cat_masked_cmd
== CY_CMD_CAT_START_SENSOR_DATA_MODE
)
1066 cd
->sysinfo
.monitor
.mntr_status
= CY_MNTR_INITIATED
;
1068 cd
->sysinfo
.monitor
.mntr_status
= CY_MNTR_DISABLED
;
1070 /* Get the Debug info for the interrupt. */
1071 if (cat_masked_cmd
!= CY_CMD_CAT_NULL
&&
1073 CY_CMD_CAT_RETRIEVE_PANEL_SCAN
&&
1074 cat_masked_cmd
!= CY_CMD_CAT_EXEC_PANEL_SCAN
)
1076 "%s: cyttsp4_CaT_IRQ=%02X %02X %02X\n",
1077 __func__
, mode
[0], mode
[1], mode
[2]);
1078 dev_vdbg(dev
, "%s: CaT\n", __func__
);
1080 case CY_HST_SYSINFO
:
1081 cur_mode
= CY_MODE_SYSINFO
;
1082 dev_vdbg(dev
, "%s: sysinfo\n", __func__
);
1085 cur_mode
= CY_MODE_UNKNOWN
;
1086 dev_err(dev
, "%s: unknown HST mode 0x%02X\n", __func__
,
1091 /* Check whether this IRQ should be ignored (internal) */
1092 if (cd
->int_status
& CY_INT_IGNORE
) {
1093 dev_vdbg(dev
, "%s: Ignoring IRQ\n", __func__
);
1094 goto cyttsp4_irq_exit
;
1097 /* Check for wake up interrupt */
1098 if (cd
->int_status
& CY_INT_AWAKE
) {
1099 cd
->int_status
&= ~CY_INT_AWAKE
;
1100 wake_up(&cd
->sleep_q
);
1101 dev_vdbg(dev
, "%s: Received wake up interrupt\n", __func__
);
1102 goto cyttsp4_irq_handshake
;
1105 /* Expecting mode change interrupt */
1106 if ((cd
->int_status
& CY_INT_MODE_CHANGE
)
1107 && (mode
[0] & CY_HST_MODE_CHANGE
) == 0) {
1108 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1109 dev_dbg(dev
, "%s: finish mode switch m=%d -> m=%d\n",
1110 __func__
, cd
->mode
, cur_mode
);
1111 cd
->mode
= cur_mode
;
1112 wake_up(&cd
->wait_q
);
1113 goto cyttsp4_irq_handshake
;
1116 /* compare current core mode to current device mode */
1117 dev_vdbg(dev
, "%s: cd->mode=%d cur_mode=%d\n",
1118 __func__
, cd
->mode
, cur_mode
);
1119 if (((mode
[0] & CY_HST_MODE_CHANGE
) == 0 || IS_BOOTLOADER(mode
[1]))
1120 && cd
->mode
!= cur_mode
) {
1121 /* Unexpected mode change occurred */
1122 dev_err(dev
, "%s %d->%d 0x%x\n", __func__
, cd
->mode
,
1123 cur_mode
, cd
->int_status
);
1124 dev_vdbg(dev
, "%s: Unexpected mode change, startup\n",
1126 cyttsp4_queue_startup_(cd
);
1127 goto cyttsp4_irq_exit
;
1130 /* Expecting command complete interrupt */
1131 dev_vdbg(dev
, "%s: command byte:0x%x, toggle:0x%x\n",
1132 __func__
, mode
[cmd_ofs
], cd
->cmd_toggle
);
1133 if ((cd
->int_status
& CY_INT_EXEC_CMD
)
1134 && mode
[cmd_ofs
] & CY_CMD_COMPLETE
) {
1135 cd
->int_status
&= ~CY_INT_EXEC_CMD
;
1136 dev_vdbg(dev
, "%s: Received command complete interrupt\n",
1138 wake_up(&cd
->wait_q
);
1140 * It is possible to receive a single interrupt for
1141 * command complete and touch/button status report.
1142 * Continue processing for a possible status report.
1146 /* This should be status report, read status regs */
1147 if (cd
->mode
== CY_MODE_OPERATIONAL
) {
1148 dev_vdbg(dev
, "%s: Read status registers\n", __func__
);
1149 rc
= cyttsp4_load_status_regs(cd
);
1151 dev_err(dev
, "%s: fail read mode regs r=%d\n",
1156 call_atten_cb(cd
, CY_ATTEN_IRQ
, cd
->mode
);
1158 cyttsp4_irq_handshake
:
1159 /* handshake the event */
1160 dev_vdbg(dev
, "%s: Handshake mode=0x%02X r=%d\n",
1161 __func__
, mode
[0], rc
);
1162 rc
= cyttsp4_handshake(cd
, mode
[0]);
1164 dev_err(dev
, "%s: Fail handshake mode=0x%02X r=%d\n",
1165 __func__
, mode
[0], rc
);
1168 * a non-zero udelay period is required for using
1169 * IRQF_TRIGGER_LOW in order to delay until the
1170 * device completes isr deassert
1172 udelay(cd
->pdata
->level_irq_udelay
);
1175 mutex_unlock(&cd
->system_lock
);
1176 dev_vdbg(dev
, "%s: irq done\n", __func__
);
1180 static void cyttsp4_start_wd_timer(struct cyttsp4_core_data
*cd
)
1182 if (!CY_WATCHDOG_TIMEOUT
)
1185 mod_timer(&cd
->watchdog_timer
, jiffies
+
1186 msecs_to_jiffies(CY_WATCHDOG_TIMEOUT
));
1190 static void cyttsp4_stop_wd_timer(struct cyttsp4_core_data
*cd
)
1192 if (!CY_WATCHDOG_TIMEOUT
)
1195 del_timer(&cd
->watchdog_timer
);
1196 cancel_work_sync(&cd
->watchdog_work
);
1197 del_timer(&cd
->watchdog_timer
);
1201 #ifndef CYTTSP4_WATCHDOG_NULL_CMD
1202 static void cyttsp4_watchdog_work(struct work_struct
*work
)
1204 struct cyttsp4_core_data
*cd
=
1205 container_of(work
, struct cyttsp4_core_data
, watchdog_work
);
1211 dev_err(cd
->dev
, "%s: NULL context pointer\n", __func__
);
1215 mutex_lock(&cd
->system_lock
);
1216 retval
= cyttsp4_load_status_regs(cd
);
1219 "%s: failed to access device in watchdog timer r=%d\n",
1221 cyttsp4_queue_startup_(cd
);
1222 goto cyttsp4_timer_watchdog_exit_error
;
1224 mode
= cd
->sysinfo
.xy_mode
[CY_REG_BASE
];
1225 rep_stat
= cd
->sysinfo
.xy_mode
[cd
->sysinfo
.si_ofs
.rep_ofs
];
1226 if (IS_BOOTLOADER(mode
) && IS_BOOTLOADER(rep_stat
)) {
1228 "%s: device found in bootloader mode when operational mode rep_stat=0x%02X\n",
1229 __func__
, rep_stat
);
1230 cyttsp4_queue_startup_(cd
);
1231 goto cyttsp4_timer_watchdog_exit_error
;
1234 cyttsp4_start_wd_timer(cd
);
1235 cyttsp4_timer_watchdog_exit_error
:
1236 mutex_unlock(&cd
->system_lock
);
1241 static void cyttsp4_watchdog_timer(unsigned long handle
)
1243 struct cyttsp4_core_data
*cd
= (struct cyttsp4_core_data
*)handle
;
1245 dev_vdbg(cd
->dev
, "%s: Timer triggered\n", __func__
);
1250 if (!work_pending(&cd
->watchdog_work
))
1251 schedule_work(&cd
->watchdog_work
);
1256 static int cyttsp4_write_(struct cyttsp4_device
*ttsp
, int mode
, u8 addr
,
1257 const void *buf
, int size
)
1259 struct device
*dev
= &ttsp
->dev
;
1260 struct cyttsp4_core
*core
= ttsp
->core
;
1261 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1264 mutex_lock(&cd
->adap_lock
);
1265 if (mode
!= cd
->mode
) {
1266 dev_dbg(dev
, "%s: %s (having %x while %x requested)\n",
1267 __func__
, "attempt to write in missing mode",
1272 rc
= cyttsp4_adap_write(core
->adap
, addr
, buf
, size
);
1274 mutex_unlock(&cd
->adap_lock
);
1278 static int cyttsp4_read_(struct cyttsp4_device
*ttsp
, int mode
, u8 addr
,
1279 void *buf
, int size
)
1281 struct device
*dev
= &ttsp
->dev
;
1282 struct cyttsp4_core
*core
= ttsp
->core
;
1283 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1286 mutex_lock(&cd
->adap_lock
);
1287 if (mode
!= cd
->mode
) {
1288 dev_dbg(dev
, "%s: %s (having %x while %x requested)\n",
1289 __func__
, "attempt to read in missing mode",
1294 rc
= cyttsp4_adap_read(core
->adap
, addr
, buf
, size
);
1296 mutex_unlock(&cd
->adap_lock
);
1300 static int cyttsp4_subscribe_attention_(struct cyttsp4_device
*ttsp
,
1301 enum cyttsp4_atten_type type
,
1302 int (*func
)(struct cyttsp4_device
*), int mode
)
1304 struct cyttsp4_core
*core
= ttsp
->core
;
1305 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1306 unsigned long flags
;
1307 struct atten_node
*atten
, *atten_new
;
1309 atten_new
= kzalloc(sizeof(*atten_new
), GFP_KERNEL
);
1311 dev_err(cd
->dev
, "%s: Fail alloc atten node\n", __func__
);
1315 dev_dbg(cd
->dev
, "%s from '%s'\n", __func__
, dev_name(cd
->dev
));
1317 spin_lock_irqsave(&cd
->spinlock
, flags
);
1318 list_for_each_entry(atten
, &cd
->atten_list
[type
], node
) {
1319 if (atten
->ttsp
== ttsp
&& atten
->mode
== mode
) {
1320 spin_unlock_irqrestore(&cd
->spinlock
, flags
);
1321 dev_vdbg(cd
->dev
, "%s: %s=%p %s=%d\n",
1323 "already subscribed attention",
1324 ttsp
, "mode", mode
);
1330 atten_new
->ttsp
= ttsp
;
1331 atten_new
->mode
= mode
;
1332 atten_new
->func
= func
;
1334 list_add(&atten_new
->node
, &cd
->atten_list
[type
]);
1335 spin_unlock_irqrestore(&cd
->spinlock
, flags
);
1340 static int cyttsp4_unsubscribe_attention_(struct cyttsp4_device
*ttsp
,
1341 enum cyttsp4_atten_type type
, int (*func
)(struct cyttsp4_device
*),
1344 struct cyttsp4_core
*core
= ttsp
->core
;
1345 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1346 struct atten_node
*atten
, *atten_n
;
1347 unsigned long flags
;
1349 spin_lock_irqsave(&cd
->spinlock
, flags
);
1350 list_for_each_entry_safe(atten
, atten_n
, &cd
->atten_list
[type
], node
) {
1351 if (atten
->ttsp
== ttsp
&& atten
->mode
== mode
) {
1352 list_del(&atten
->node
);
1353 spin_unlock_irqrestore(&cd
->spinlock
, flags
);
1355 dev_vdbg(cd
->dev
, "%s: %s=%p %s=%d\n",
1357 "unsub for atten->ttsp", atten
->ttsp
,
1358 "atten->mode", atten
->mode
);
1362 spin_unlock_irqrestore(&cd
->spinlock
, flags
);
1367 static int request_exclusive(struct cyttsp4_core_data
*cd
, void *ownptr
,
1370 int t
= msecs_to_jiffies(timeout_ms
);
1371 bool with_timeout
= (timeout_ms
!= 0);
1373 mutex_lock(&cd
->system_lock
);
1374 if (!cd
->exclusive_dev
&& cd
->exclusive_waits
== 0) {
1375 cd
->exclusive_dev
= ownptr
;
1379 cd
->exclusive_waits
++;
1381 mutex_unlock(&cd
->system_lock
);
1383 t
= wait_event_timeout(cd
->wait_q
, !cd
->exclusive_dev
, t
);
1385 dev_err(cd
->dev
, "%s: tmo waiting exclusive access\n",
1390 wait_event(cd
->wait_q
, !cd
->exclusive_dev
);
1392 mutex_lock(&cd
->system_lock
);
1393 if (cd
->exclusive_dev
)
1395 cd
->exclusive_dev
= ownptr
;
1396 cd
->exclusive_waits
--;
1398 mutex_unlock(&cd
->system_lock
);
1399 dev_vdbg(cd
->dev
, "%s: request_exclusive ok=%p\n",
1405 static int cyttsp4_request_exclusive_(struct cyttsp4_device
*ttsp
,
1408 struct cyttsp4_core
*core
= ttsp
->core
;
1409 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1410 return request_exclusive(cd
, (void *)ttsp
, timeout_ms
);
1414 * returns error if was not owned
1416 static int release_exclusive(struct cyttsp4_core_data
*cd
, void *ownptr
)
1418 mutex_lock(&cd
->system_lock
);
1419 if (cd
->exclusive_dev
!= ownptr
) {
1420 mutex_unlock(&cd
->system_lock
);
1424 dev_vdbg(cd
->dev
, "%s: exclusive_dev %p freed\n",
1425 __func__
, cd
->exclusive_dev
);
1426 cd
->exclusive_dev
= NULL
;
1427 wake_up(&cd
->wait_q
);
1428 mutex_unlock(&cd
->system_lock
);
1432 static int cyttsp4_release_exclusive_(struct cyttsp4_device
*ttsp
)
1434 struct cyttsp4_core
*core
= ttsp
->core
;
1435 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1436 return release_exclusive(cd
, (void *)ttsp
);
1440 static int cyttsp4_reset_checkout(struct cyttsp4_core_data
*cd
)
1446 /* reset hardware */
1447 mutex_lock(&cd
->system_lock
);
1448 dev_dbg(cd
->dev
, "%s: reset hw...\n", __func__
);
1449 rc
= cyttsp4_hw_reset(cd
);
1450 cd
->mode
= CY_MODE_UNKNOWN
;
1451 mutex_unlock(&cd
->system_lock
);
1453 dev_err(cd
->dev
, "%s: %s adap='%s' r=%d\n", __func__
,
1454 "Fail hw reset", cd
->core
->adap
->id
, rc
);
1458 dev_dbg(cd
->dev
, "%s: msleep 70 ms\n", __func__
);
1460 dev_dbg(cd
->dev
, "%s: begin to check cypress device\n", __func__
);
1461 for (i
= 0; i
< CY_CORE_READTIMES
; i
++) {
1462 rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
,
1464 dev_dbg(cd
->dev
, "%s: rc =%d\n", __func__
,rc
);
1466 dev_err(cd
->dev
,"%s:I2C cannot communicate, no cypress device, exit!!!\n",__func__
);
1469 dev_dbg(cd
->dev
, "%s: find cypress device!!!\n", __func__
);
1477 static int cyttsp4_wait_bl_heartbeat(struct cyttsp4_core_data
*cd
)
1482 /* wait heartbeat */
1483 dev_vdbg(cd
->dev
, "%s: wait heartbeat...\n", __func__
);
1484 t
= wait_event_timeout(cd
->wait_q
, cd
->mode
== CY_MODE_BOOTLOADER
,
1485 msecs_to_jiffies(CY_CORE_RESET_AND_WAIT_TIMEOUT
));
1487 dev_err(cd
->dev
, "%s: tmo waiting bl heartbeat cd->mode=%d\n",
1488 __func__
, cd
->mode
);
1495 static int cyttsp4_wait_sysinfo_mode(struct cyttsp4_core_data
*cd
)
1499 dev_vdbg(cd
->dev
, "%s: wait sysinfo...\n", __func__
);
1501 t
= wait_event_timeout(cd
->wait_q
, cd
->mode
== CY_MODE_SYSINFO
,
1502 msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT
));
1504 dev_err(cd
->dev
, "%s: tmo waiting exit bl cd->mode=%d\n",
1505 __func__
, cd
->mode
);
1506 mutex_lock(&cd
->system_lock
);
1507 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1508 mutex_unlock(&cd
->system_lock
);
1515 static int cyttsp4_reset_and_wait(struct cyttsp4_core_data
*cd
)
1519 /* reset hardware */
1520 mutex_lock(&cd
->system_lock
);
1521 dev_dbg(cd
->dev
, "%s: reset hw...\n", __func__
);
1522 rc
= cyttsp4_hw_reset(cd
);
1523 cd
->mode
= CY_MODE_UNKNOWN
;
1524 mutex_unlock(&cd
->system_lock
);
1526 dev_err(cd
->dev
, "%s: %s adap='%s' r=%d\n", __func__
,
1527 "Fail hw reset", cd
->core
->adap
->id
, rc
);
1531 return cyttsp4_wait_bl_heartbeat(cd
);
1535 * returns err if refused or timeout; block until mode change complete
1536 * bit is set (mode change interrupt)
1538 static int set_mode(struct cyttsp4_core_data
*cd
, int new_mode
)
1546 case CY_MODE_OPERATIONAL
:
1547 new_dev_mode
= CY_HST_OPERATE
;
1549 case CY_MODE_SYSINFO
:
1550 new_dev_mode
= CY_HST_SYSINFO
;
1553 new_dev_mode
= CY_HST_CAT
;
1556 dev_err(cd
->dev
, "%s: invalid mode: %02X(%d)\n",
1557 __func__
, new_mode
, new_mode
);
1562 dev_dbg(cd
->dev
, "%s: %s=%p new_dev_mode=%02X new_mode=%d\n",
1563 __func__
, "have exclusive", cd
->exclusive_dev
,
1564 new_dev_mode
, new_mode
);
1566 rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
,
1567 &mode
, sizeof(mode
));
1569 dev_err(cd
->dev
, "%s: Fail read mode r=%d\n",
1574 /* Clear device mode bits and set to new mode */
1575 mode
&= ~CY_HST_MODE
;
1576 mode
|= new_dev_mode
| CY_HST_MODE_CHANGE
;
1578 mutex_lock(&cd
->system_lock
);
1579 cd
->int_status
|= CY_INT_MODE_CHANGE
;
1580 rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
,
1581 &mode
, sizeof(mode
));
1583 dev_err(cd
->dev
, "%s: Fail write mode change r=%d\n",
1585 mutex_unlock(&cd
->system_lock
);
1587 /* wait for mode change done interrupt */
1588 t
= wait_event_timeout(cd
->wait_q
,
1589 (cd
->int_status
& CY_INT_MODE_CHANGE
) == 0,
1590 msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT
));
1591 dev_dbg(cd
->dev
, "%s: back from wait t=%ld cd->mode=%d\n",
1592 __func__
, t
, cd
->mode
);
1595 dev_err(cd
->dev
, "%s: %s\n", __func__
,
1596 "tmo waiting mode change");
1597 mutex_lock(&cd
->system_lock
);
1598 cd
->int_status
&= ~CY_INT_MODE_CHANGE
;
1599 mutex_unlock(&cd
->system_lock
);
1608 * returns err if refused or timeout(core uses fixed timeout period) occurs;
1609 * blocks until ISR occurs
1611 static int cyttsp4_request_reset_(struct cyttsp4_device
*ttsp
)
1613 struct cyttsp4_core
*core
= ttsp
->core
;
1614 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1617 rc
= cyttsp4_reset_and_wait(cd
);
1619 dev_err(cd
->dev
, "%s: Error on h/w reset r=%d\n",
1626 * returns err if refused ; if no error then restart has completed
1627 * and system is in normal operating mode
1629 static int cyttsp4_request_restart_(struct cyttsp4_device
*ttsp
, bool wait
)
1631 struct cyttsp4_core
*core
= ttsp
->core
;
1632 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1634 cyttsp4_queue_startup(cd
);
1637 wait_event(cd
->wait_q
, cd
->startup_state
== STARTUP_NONE
);
1641 static int cyttsp4_request_set_mode_(struct cyttsp4_device
*ttsp
, int mode
)
1643 struct cyttsp4_core
*core
= ttsp
->core
;
1644 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1647 rc
= set_mode(cd
, mode
);
1649 dev_err(cd
->dev
, "%s: fail set_mode=%02X(%d)\n",
1650 __func__
, cd
->mode
, cd
->mode
);
1651 #ifdef SHOK_SENSOR_DATA_MODE
1652 if (cd
->sysinfo
.monitor
.mntr_status
== CY_MNTR_INITIATED
&&
1653 mode
== CY_MODE_OPERATIONAL
)
1654 cd
->sysinfo
.monitor
.mntr_status
= CY_MNTR_STARTED
;
1656 cd
->sysinfo
.monitor
.mntr_status
= CY_MNTR_DISABLED
;
1663 * returns NULL if sysinfo has not been acquired from the device yet
1665 static struct cyttsp4_sysinfo
*cyttsp4_request_sysinfo_(
1666 struct cyttsp4_device
*ttsp
)
1668 struct cyttsp4_core
*core
= ttsp
->core
;
1669 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1671 if (cd
->sysinfo
.ready
)
1672 return &cd
->sysinfo
;
1677 static struct cyttsp4_loader_platform_data
*cyttsp4_request_loader_pdata_(
1678 struct cyttsp4_device
*ttsp
)
1680 struct cyttsp4_core
*core
= ttsp
->core
;
1681 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1682 return cd
->pdata
->loader_pdata
;
1685 static int cyttsp4_request_handshake_(struct cyttsp4_device
*ttsp
, u8 mode
)
1687 struct cyttsp4_core
*core
= ttsp
->core
;
1688 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1691 rc
= cyttsp4_handshake(cd
, mode
);
1693 dev_err(&core
->dev
, "%s: Fail handshake r=%d\n", __func__
, rc
);
1698 static int cyttsp4_request_toggle_lowpower_(struct cyttsp4_device
*ttsp
,
1701 struct cyttsp4_core
*core
= ttsp
->core
;
1702 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1703 int rc
= cyttsp4_toggle_low_power(cd
, mode
);
1705 dev_err(&core
->dev
, "%s: Fail toggle low power r=%d\n",
1711 * Send command to device for CAT and OP modes
1712 * return negative value on error, 0 on success
1714 static int cyttsp4_exec_cmd(struct cyttsp4_core_data
*cd
, u8 mode
,
1715 u8
*cmd_buf
, size_t cmd_size
, u8
*return_buf
,
1716 size_t return_buf_size
, int timeout_ms
)
1718 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
1719 struct device
*dev
= cd
->dev
;
1724 mutex_lock(&cd
->system_lock
);
1725 if (mode
!= cd
->mode
) {
1726 dev_err(dev
, "%s: %s (having %x while %x requested)\n",
1727 __func__
, "attempt to exec cmd in missing mode",
1729 mutex_unlock(&cd
->system_lock
);
1735 cmd_ofs
= CY_REG_CAT_CMD
;
1737 case CY_MODE_OPERATIONAL
:
1738 cmd_ofs
= si
->si_ofs
.cmd_ofs
;
1741 dev_err(dev
, "%s: Unsupported mode %x for exec cmd\n",
1743 mutex_unlock(&cd
->system_lock
);
1747 /* Check if complete is set, so write new command */
1748 rc
= cyttsp4_adap_read(cd
->core
->adap
, cmd_ofs
, &command
, 1);
1750 dev_err(dev
, "%s: Error on read r=%d\n", __func__
, rc
);
1751 mutex_unlock(&cd
->system_lock
);
1755 cd
->cmd_toggle
= GET_TOGGLE(command
);
1756 cd
->int_status
|= CY_INT_EXEC_CMD
;
1758 if ((command
& CY_CMD_COMPLETE_MASK
) == 0) {
1759 /* Let irq handler run */
1760 mutex_unlock(&cd
->system_lock
);
1761 rc
= wait_event_timeout(cd
->wait_q
,
1762 (cd
->int_status
& CY_INT_EXEC_CMD
) == 0,
1763 msecs_to_jiffies(timeout_ms
));
1765 dev_err(dev
, "%s: Command execution timed out\n",
1767 cd
->int_status
&= ~CY_INT_EXEC_CMD
;
1771 /* For next command */
1772 mutex_lock(&cd
->system_lock
);
1773 rc
= cyttsp4_adap_read(cd
->core
->adap
, cmd_ofs
, &command
, 1);
1775 dev_err(dev
, "%s: Error on read r=%d\n", __func__
, rc
);
1776 mutex_unlock(&cd
->system_lock
);
1779 cd
->cmd_toggle
= GET_TOGGLE(command
);
1780 cd
->int_status
|= CY_INT_EXEC_CMD
;
1785 * Only update command bits 0:5
1786 * Clear command complete bit & toggle bit
1788 cmd_buf
[0] = cmd_buf
[0] & CY_CMD_MASK
;
1789 rc
= cyttsp4_adap_write(cd
->core
->adap
, cmd_ofs
, cmd_buf
, cmd_size
);
1791 dev_err(dev
, "%s: Error on write command r=%d\n",
1793 mutex_unlock(&cd
->system_lock
);
1798 * Wait command to be completed
1800 mutex_unlock(&cd
->system_lock
);
1801 rc
= wait_event_timeout(cd
->wait_q
,
1802 (cd
->int_status
& CY_INT_EXEC_CMD
) == 0,
1803 msecs_to_jiffies(timeout_ms
));
1805 dev_err(dev
, "%s: Command execution timed out\n", __func__
);
1806 cd
->int_status
&= ~CY_INT_EXEC_CMD
;
1810 if (return_buf_size
== 0 || return_buf
== NULL
)
1813 rc
= cyttsp4_adap_read(cd
->core
->adap
, cmd_ofs
+ 1, return_buf
,
1816 dev_err(dev
, "%s: Error on read 3 r=%d\n", __func__
, rc
);
1823 static int cyttsp4_request_exec_cmd_(struct cyttsp4_device
*ttsp
, u8 mode
,
1824 u8
*cmd_buf
, size_t cmd_size
, u8
*return_buf
,
1825 size_t return_buf_size
, int timeout_ms
)
1827 struct cyttsp4_core
*core
= ttsp
->core
;
1828 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
1829 return cyttsp4_exec_cmd(cd
, mode
, cmd_buf
, cmd_size
,
1830 return_buf
, return_buf_size
, timeout_ms
);
1833 static int cyttsp4_read_config_block(struct cyttsp4_core_data
*cd
, u8 ebid
,
1834 u16 row
, u8
*data
, u16 length
)
1841 /* Allocate buffer for read config block command response
1842 * Header(5) + Data(length) + CRC(2)
1844 return_buf
= kmalloc(length
+ 7, GFP_KERNEL
);
1846 dev_err(cd
->dev
, "%s: Cannot allocate buffer\n",
1852 command_buf
[0] = CY_CMD_CAT_READ_CFG_BLK
;
1853 command_buf
[1] = HI_BYTE(row
);
1854 command_buf
[2] = LO_BYTE(row
);
1855 command_buf
[3] = HI_BYTE(length
);
1856 command_buf
[4] = LO_BYTE(length
);
1857 command_buf
[5] = ebid
;
1859 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_CAT
, command_buf
, 6,
1860 return_buf
, length
+ 7, CY_COMMAND_COMPLETE_TIMEOUT
);
1862 dev_err(cd
->dev
, "%s: Error executing command r=%d\n",
1867 crc
= cyttsp4_calc_app_crc(&return_buf
[5], length
);
1869 /* Validate response */
1870 if (return_buf
[0] != CY_CMD_STATUS_SUCCESS
1871 || return_buf
[1] != ebid
1872 || return_buf
[2] != HI_BYTE(length
)
1873 || return_buf
[3] != LO_BYTE(length
)
1874 || return_buf
[5 + length
] != HI_BYTE(crc
)
1875 || return_buf
[6 + length
] != LO_BYTE(crc
)) {
1876 dev_err(cd
->dev
, "%s: Fail executing command\n",
1882 memcpy(data
, &return_buf
[5], length
);
1884 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, data
, length
, "read_config_block");
1892 static int cyttsp4_write_config_block(struct cyttsp4_core_data
*cd
, u8 ebid
,
1893 u16 row
, const u8
*data
, u16 length
)
1900 /* Allocate buffer for write config block command
1901 * Header(6) + Data(length) + Security Key(8) + CRC(2)
1903 command_buf
= kmalloc(length
+ 8 + sizeof(security_key
), GFP_KERNEL
);
1905 dev_err(cd
->dev
, "%s: Cannot allocate buffer\n",
1911 crc
= cyttsp4_calc_app_crc(data
, length
);
1913 command_buf
[0] = CY_CMD_CAT_WRITE_CFG_BLK
;
1914 command_buf
[1] = HI_BYTE(row
);
1915 command_buf
[2] = LO_BYTE(row
);
1916 command_buf
[3] = HI_BYTE(length
);
1917 command_buf
[4] = LO_BYTE(length
);
1918 command_buf
[5] = ebid
;
1920 command_buf
[6 + length
+ sizeof(security_key
)] = HI_BYTE(crc
);
1921 command_buf
[7 + length
+ sizeof(security_key
)] = LO_BYTE(crc
);
1923 memcpy(&command_buf
[6], data
, length
);
1924 memcpy(&command_buf
[6 + length
], security_key
, sizeof(security_key
));
1927 cyttsp4_pr_buf(cd
->dev
, cd
->pr_buf
, command_buf
, length
+ 8 +
1928 sizeof(security_key
), "write_config_block");
1930 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_CAT
,
1931 command_buf
, length
+ 8 + sizeof(security_key
),
1932 return_buf
, 5, CY_COMMAND_COMPLETE_TIMEOUT
);
1934 dev_err(cd
->dev
, "%s: Error executing command r=%d\n",
1939 /* Validate response */
1940 if (return_buf
[0] != CY_CMD_STATUS_SUCCESS
1941 || return_buf
[1] != ebid
1942 || return_buf
[2] != HI_BYTE(length
)
1943 || return_buf
[3] != LO_BYTE(length
)) {
1944 dev_err(cd
->dev
, "%s: Fail executing command\n",
1956 static int cyttsp4_get_config_row_size(struct cyttsp4_core_data
*cd
,
1957 u16
*config_row_size
)
1963 command_buf
[0] = CY_CMD_CAT_GET_CFG_ROW_SZ
;
1965 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_CAT
, command_buf
, 1,
1966 return_buf
, 2, CY_COMMAND_COMPLETE_TIMEOUT
);
1968 dev_err(cd
->dev
, "%s: Error executing command r=%d\n",
1973 *config_row_size
= get_unaligned_be16(&return_buf
[0]);
1979 static int cyttsp4_verify_config_block_crc(struct cyttsp4_core_data
*cd
,
1980 u8 ebid
, u16
*calc_crc
, u16
*stored_crc
, bool *match
)
1986 command_buf
[0] = CY_CMD_CAT_VERIFY_CFG_BLK_CRC
;
1987 command_buf
[1] = ebid
;
1989 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_CAT
, command_buf
, 2,
1990 return_buf
, 5, CY_COMMAND_COMPLETE_TIMEOUT
);
1992 dev_err(cd
->dev
, "%s: Error executing command r=%d\n",
1997 *calc_crc
= get_unaligned_be16(&return_buf
[1]);
1998 *stored_crc
= get_unaligned_be16(&return_buf
[3]);
2000 *match
= !return_buf
[0];
2005 static int cyttsp4_get_config_block_crc(struct cyttsp4_core_data
*cd
,
2012 command_buf
[0] = CY_CMD_OP_GET_CRC
;
2013 command_buf
[1] = ebid
;
2015 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_OPERATIONAL
, command_buf
, 2,
2016 return_buf
, 3, CY_COMMAND_COMPLETE_TIMEOUT
);
2018 dev_err(cd
->dev
, "%s: Error executing command r=%d\n",
2023 /* Validate response */
2024 if (return_buf
[0] != CY_CMD_STATUS_SUCCESS
) {
2025 dev_err(cd
->dev
, "%s: Fail executing command\n",
2031 *crc
= get_unaligned_be16(&return_buf
[1]);
2037 static int cyttsp4_get_ttconfig_version(struct cyttsp4_core_data
*cd
,
2040 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
2041 u8 data
[CY_TTCONFIG_OFFSET
+ 2];
2049 rc
= cyttsp4_read_config_block(cd
, CY_TCH_PARM_EBID
, 0, data
,
2050 CY_TTCONFIG_OFFSET
+ 2);
2052 dev_err(cd
->dev
, "%s: Error on read config block\n",
2057 if (IS_LITTLEENDIAN(si
->si_ptrs
.cydata
->device_info
))
2058 *version
= get_unaligned_le16(&data
[CY_TTCONFIG_OFFSET
]);
2060 *version
= get_unaligned_be16(&data
[CY_TTCONFIG_OFFSET
]);
2066 static int cyttsp4_get_config_length(struct cyttsp4_core_data
*cd
, u8 ebid
,
2067 u16
*length
, u16
*max_length
)
2069 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
2078 rc
= cyttsp4_read_config_block(cd
, ebid
, 0, data
, 4);
2080 dev_err(cd
->dev
, "%s: Error on read config block\n",
2085 if (IS_LITTLEENDIAN(si
->si_ptrs
.cydata
->device_info
)) {
2086 *length
= get_unaligned_le16(&data
[0]);
2087 *max_length
= get_unaligned_le16(&data
[2]);
2089 *length
= get_unaligned_be16(&data
[0]);
2090 *max_length
= get_unaligned_be16(&data
[2]);
2097 static int cyttsp4_write_config_common(struct cyttsp4_core_data
*cd
, u8 ebid
,
2098 u16 offset
, u8
*data
, u16 length
)
2100 u16 cur_block
, cur_off
, end_block
, end_off
;
2101 int read_write_len
, copy_len
;
2102 u16 config_row_size
= 0;
2103 u8
*row_data
= NULL
;
2106 rc
= cyttsp4_get_config_row_size(cd
, &config_row_size
);
2108 dev_err(cd
->dev
, "%s: Cannot get config row size\n",
2113 cur_block
= offset
/ config_row_size
;
2114 cur_off
= offset
% config_row_size
;
2116 end_block
= (offset
+ length
) / config_row_size
;
2117 end_off
= (offset
+ length
) % config_row_size
;
2119 /* Check whether we need to fetch the whole block first */
2123 row_data
= kmalloc(config_row_size
, GFP_KERNEL
);
2125 dev_err(cd
->dev
, "%s: Cannot allocate buffer\n", __func__
);
2130 if (cur_block
== end_block
) {
2131 read_write_len
= length
+ cur_off
;
2134 read_write_len
= config_row_size
;
2135 copy_len
= config_row_size
- cur_off
;
2138 /* Get the block, update it and write it back */
2139 rc
= cyttsp4_read_config_block(cd
, ebid
, cur_block
, row_data
,
2142 dev_err(cd
->dev
, "%s: Error on read config block\n", __func__
);
2146 memcpy(&row_data
[cur_off
], data
, copy_len
);
2148 rc
= cyttsp4_write_config_block(cd
, ebid
, cur_block
, row_data
,
2151 dev_err(cd
->dev
, "%s: Error on write config block\n", __func__
);
2155 data
+= config_row_size
- cur_off
;
2160 while (cur_block
< end_block
) {
2161 rc
= cyttsp4_write_config_block(cd
, ebid
, cur_block
, data
,
2164 dev_err(cd
->dev
, "%s: Error on write config block\n",
2169 data
+= config_row_size
;
2174 if (cur_block
== end_block
) {
2175 rc
= cyttsp4_write_config_block(cd
, ebid
, end_block
, data
,
2178 dev_err(cd
->dev
, "%s: Error on write config block\n",
2190 static int cyttsp4_write_config(struct cyttsp4_core_data
*cd
, u8 ebid
,
2191 u16 offset
, u8
*data
, u16 length
) {
2192 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
2193 u16 crc_new
, crc_old
;
2204 /* CRC is stored at config max length offset */
2205 rc
= cyttsp4_get_config_length(cd
, ebid
, &conf_len
, &crc_offset
);
2207 dev_err(cd
->dev
, "%s: Error on get config length\n",
2212 /* Allow CRC update also */
2213 if (offset
+ length
> crc_offset
+ 2) {
2214 dev_err(cd
->dev
, "%s: offset + length exceeds max length(%d)\n",
2215 __func__
, crc_offset
+ 2);
2220 rc
= cyttsp4_write_config_common(cd
, ebid
, offset
, data
, length
);
2222 dev_err(cd
->dev
, "%s: Error on write config\n",
2227 /* Verify config block CRC */
2228 rc
= cyttsp4_verify_config_block_crc(cd
, ebid
,
2229 &crc_new
, &crc_old
, NULL
);
2231 dev_err(cd
->dev
, "%s: Error on verify config block crc\n",
2236 dev_vdbg(cd
->dev
, "%s: crc_new:%04X crc_old:%04X\n",
2237 __func__
, crc_new
, crc_old
);
2239 if (crc_new
== crc_old
) {
2240 dev_vdbg(cd
->dev
, "%s: Calculated crc matches stored crc\n",
2245 if (IS_LITTLEENDIAN(si
->si_ptrs
.cydata
->device_info
))
2246 put_unaligned_le16(crc_new
, crc_data
);
2248 put_unaligned_be16(crc_new
, crc_data
);
2250 rc
= cyttsp4_write_config_common(cd
, ebid
, crc_offset
, crc_data
, 2);
2252 dev_err(cd
->dev
, "%s: Error on write config crc\n",
2261 static int cyttsp4_request_write_config_(struct cyttsp4_device
*ttsp
, u8 ebid
,
2262 u16 offset
, u8
*data
, u16 length
) {
2263 struct cyttsp4_core
*core
= ttsp
->core
;
2264 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
2266 return cyttsp4_write_config(cd
, ebid
, offset
, data
, length
);
2269 /* BEGIN PN:DTS2013021701945 ,Modified by l00184147, 2013/2/17*/
2270 #ifdef CYTTSP4_WATCHDOG_NULL_CMD
2271 static void cyttsp4_watchdog_work_null(struct work_struct
*work
)
2273 struct cyttsp4_core_data
*cd
=
2274 container_of(work
, struct cyttsp4_core_data
, watchdog_work
);
2275 u8 cmd_buf
[CY_CMD_OP_NULL_CMD_SZ
];
2276 bool restart
= false;
2279 rc
= request_exclusive(cd
, cd
->core
, 1);
2281 dev_vdbg(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
2282 __func__
, cd
->exclusive_dev
, cd
->core
);
2286 cmd_buf
[0] = CY_CMD_OP_NULL
;
2287 rc
= cyttsp4_exec_cmd(cd
, cd
->mode
,
2288 cmd_buf
, CY_CMD_OP_NULL_CMD_SZ
,
2289 NULL
, CY_CMD_OP_NULL_RET_SZ
,
2290 CY_COMMAND_COMPLETE_TIMEOUT
);
2292 dev_err(cd
->dev
, "%s: Watchdog NULL cmd failed.\n", __func__
);
2296 if (release_exclusive(cd
, cd
->core
) < 0)
2297 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
2299 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
2303 cyttsp4_queue_startup(cd
);
2305 cyttsp4_start_wd_timer(cd
);
2308 /* END PN:DTS2013021701945 ,Modified by l00184147, 2013/2/17*/
2310 static int cyttsp4_request_stop_wd_(struct cyttsp4_device
*ttsp
)
2312 struct cyttsp4_core
*core
= ttsp
->core
;
2313 struct cyttsp4_core_data
*cd
= dev_get_drvdata(&core
->dev
);
2314 cyttsp4_stop_wd_timer(cd
);
2318 static int cyttsp4_core_sleep_(struct cyttsp4_core_data
*cd
)
2320 enum cyttsp4_sleep_state ss
= SS_SLEEP_ON
;
2321 enum cyttsp4_int_state int_status
= CY_INT_IGNORE
;
2325 printk("printk cyttsp4_core_sleep_\n");
2327 dev_vdbg(cd
->dev
, "%s: enter...\n", __func__
);
2329 /* Already in sleep mode? */
2330 mutex_lock(&cd
->system_lock
);
2331 if (cd
->sleep_state
== SS_SLEEP_ON
) {
2332 mutex_unlock(&cd
->system_lock
);
2335 cd
->sleep_state
= SS_SLEEPING
;
2336 mutex_unlock(&cd
->system_lock
);
2338 /* Wait until currently running IRQ handler exits and disable IRQ */
2340 cyttsp4_mtk_gpio_interrupt_disable();
2342 /* disable_irq(cd->irq); */
2345 cyttsp4_stop_wd_timer(cd
);
2347 dev_vdbg(cd
->dev
, "%s: write DEEP SLEEP...\n", __func__
);
2348 rc
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, &mode
,
2351 dev_err(cd
->dev
, "%s: Fail read adapter r=%d\n", __func__
, rc
);
2355 if (IS_BOOTLOADER(mode
)) {
2356 dev_err(cd
->dev
, "%s: Device in BOOTLADER mode.\n", __func__
);
2361 mode
|= CY_HST_SLEEP
;
2362 rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
, &mode
,
2365 dev_err(cd
->dev
, "%s: Fail write adapter r=%d\n", __func__
, rc
);
2368 dev_vdbg(cd
->dev
, "%s: write DEEP SLEEP succeeded\n", __func__
);
2370 if (cd
->pdata
->power
) {
2371 dev_dbg(cd
->dev
, "%s: Power down HW\n", __func__
);
2372 rc
= cd
->pdata
->power(cd
->pdata
, 0, cd
->dev
, &cd
->ignore_irq
);
2374 dev_dbg(cd
->dev
, "%s: No power function\n", __func__
);
2378 dev_err(cd
->dev
, "%s: HW Power down fails r=%d\n",
2383 /* Give time to FW to sleep */
2390 int_status
= CY_INT_NONE
;
2391 cyttsp4_start_wd_timer(cd
);
2394 mutex_lock(&cd
->system_lock
);
2395 cd
->sleep_state
= ss
;
2396 cd
->int_status
|= int_status
;
2397 mutex_unlock(&cd
->system_lock
);
2399 // mt65xx_eint_mask mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
2400 cyttsp4_mtk_gpio_interrupt_enable();
2402 /* enable_irq(cd->irq); */
2407 static int cyttsp4_core_sleep(struct cyttsp4_core_data
*cd
)
2411 /* First wait for any possible running startup to finish */
2412 wait_event(cd
->wait_q
, cd
->startup_state
== STARTUP_NONE
);
2414 rc
= request_exclusive(cd
, cd
->core
,
2415 CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
2417 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
2418 __func__
, cd
->exclusive_dev
, cd
->core
);
2422 rc
= cyttsp4_core_sleep_(cd
);
2424 if (release_exclusive(cd
, cd
->core
) < 0)
2425 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
2427 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
2432 static int cyttsp4_core_wake_(struct cyttsp4_core_data
*cd
)
2434 struct device
*dev
= cd
->dev
;
2439 dev_vdbg(cd
->dev
, "%s: enter...\n", __func__
);
2441 /* Already woken? */
2442 mutex_lock(&cd
->system_lock
);
2443 if (cd
->sleep_state
== SS_SLEEP_OFF
) {
2444 mutex_unlock(&cd
->system_lock
);
2447 cd
->int_status
&= ~CY_INT_IGNORE
;
2448 cd
->int_status
|= CY_INT_AWAKE
;
2449 cd
->sleep_state
= SS_WAKING
;
2451 /* Do not start watchdog in already woken state */
2452 cyttsp4_start_wd_timer(cd
);
2454 if (cd
->pdata
->power
) {
2455 dev_dbg(dev
, "%s: Power up HW\n", __func__
);
2456 rc
= cd
->pdata
->power(cd
->pdata
, 1, dev
, &cd
->ignore_irq
);
2458 dev_dbg(dev
, "%s: No power function\n", __func__
);
2462 dev_err(dev
, "%s: HW Power up fails r=%d\n",
2465 /* Initiate a read transaction to wake up */
2466 cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
, &mode
,
2469 dev_vdbg(cd
->dev
, "%s: HW power up succeeds\n",
2471 mutex_unlock(&cd
->system_lock
);
2473 t
= wait_event_timeout(cd
->sleep_q
,
2474 (cd
->int_status
& CY_INT_AWAKE
) == 0,
2475 msecs_to_jiffies(CY_CORE_WAKEUP_TIMEOUT
));
2477 dev_err(dev
, "%s: TMO waiting for wakeup\n", __func__
);
2478 mutex_lock(&cd
->system_lock
);
2479 cd
->int_status
&= ~CY_INT_AWAKE
;
2480 /* Try starting up */
2481 cyttsp4_queue_startup_(cd
);
2482 mutex_unlock(&cd
->system_lock
);
2485 mutex_lock(&cd
->system_lock
);
2486 cd
->sleep_state
= SS_SLEEP_OFF
;
2487 mutex_unlock(&cd
->system_lock
);
2492 static int cyttsp4_core_wake(struct cyttsp4_core_data
*cd
)
2496 rc
= request_exclusive(cd
, cd
->core
,
2497 CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
2499 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
2500 __func__
, cd
->exclusive_dev
, cd
->core
);
2504 rc
= cyttsp4_core_wake_(cd
);
2506 if (release_exclusive(cd
, cd
->core
) < 0)
2507 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
2509 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
2514 static int cyttsp4_get_ttconfig_info(struct cyttsp4_core_data
*cd
)
2516 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
2517 u16 length
, max_length
;
2522 rc
= set_mode(cd
, CY_MODE_CAT
);
2524 dev_err(cd
->dev
, "%s: failed to set mode to CAT rc=%d\n",
2529 rc
= cyttsp4_get_ttconfig_version(cd
, &version
);
2531 dev_err(cd
->dev
, "%s: failed to get ttconfig version rc=%d\n",
2536 rc
= cyttsp4_get_config_length(cd
, CY_TCH_PARM_EBID
,
2537 &length
, &max_length
);
2539 dev_err(cd
->dev
, "%s: failed to get ttconfig length rc=%d\n",
2544 rc
= set_mode(cd
, CY_MODE_OPERATIONAL
);
2546 dev_err(cd
->dev
, "%s: failed to set mode to Operational rc=%d\n",
2551 rc
= cyttsp4_get_config_block_crc(cd
, CY_TCH_PARM_EBID
, &crc
);
2553 dev_err(cd
->dev
, "%s: failed to get ttconfig crc rc=%d\n",
2558 si
->ttconfig
.version
= version
;
2559 si
->ttconfig
.length
= length
;
2560 si
->ttconfig
.max_length
= max_length
;
2561 si
->ttconfig
.crc
= crc
;
2563 dev_vdbg(cd
->dev
, "%s: TT Config Version:%04X Length:%d Max Length:%d CRC:%04X\n",
2564 __func__
, si
->ttconfig
.version
, si
->ttconfig
.length
,
2565 si
->ttconfig
.length
, si
->ttconfig
.crc
);
2570 static int cyttsp4_set_opmode(struct cyttsp4_core_data
*cd
)
2572 u8 cmd_buf
[CY_CMD_OP_SET_PARA_CMD_SZ
];
2573 u8 return_buf
[CY_CMD_OP_SET_PARA_RET_SZ
];
2577 mutex_lock(&cd
->system_lock
);
2578 switch (cd
->opmode
) {
2580 mutex_unlock(&cd
->system_lock
);
2583 scan_type
= CY_OP_PARA_SCAN_TYPE_NORMAL
;
2586 scan_type
= CY_OP_PARA_SCAN_TYPE_APAMC_MASK
|
2587 CY_OP_PARA_SCAN_TYPE_GLOVE_MASK
;
2590 mutex_unlock(&cd
->system_lock
);
2592 cmd_buf
[0] = CY_CMD_OP_SET_PARA
;
2593 cmd_buf
[1] = CY_OP_PARA_SCAN_TYPE
;
2594 cmd_buf
[2] = CY_OP_PARA_SCAN_TYPE_SZ
;
2595 cmd_buf
[3] = scan_type
;
2597 rc
= cyttsp4_exec_cmd(cd
, cd
->mode
,
2598 cmd_buf
, sizeof(cmd_buf
),
2599 return_buf
, sizeof(return_buf
),
2600 CY_COMMAND_COMPLETE_TIMEOUT
);
2602 dev_err(cd
->dev
, "%s: exec cmd error.\n", __func__
);
2607 static int cyttsp4_startup_(struct cyttsp4_core_data
*cd
)
2611 dev_dbg(cd
->dev
, "%s: enter...\n", __func__
);
2613 cyttsp4_stop_wd_timer(cd
);
2615 /* reset hardware and wait for heartbeat */
2616 rc
= cyttsp4_reset_and_wait(cd
);
2617 /* BEGIN PN:DTS2013040204005 ,Modified by l00184147, 2013/4/2*/
2619 dev_err(cd
->dev
, "%s: Error on h/w reset r=%d\n", __func__
, rc
);
2621 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
2623 hwPowerDown(MT6323_POWER_LDO_VGP2
, "TP");
2625 hwPowerOn(MT6323_POWER_LDO_VGP2
, VOL_1800
, "TP");
2627 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
2630 rc
= cyttsp4_reset_and_wait(cd
);
2633 dev_err(cd
->dev
, "%s: Error on h/w reset2 r=%d\n", __func__
, rc
);
2636 /* END PN:DTS2013040204005 ,Modified by l00184147, 2013/4/2*/
2638 /* exit bl into sysinfo mode */
2639 dev_vdbg(cd
->dev
, "%s: write exit ldr...\n", __func__
);
2640 mutex_lock(&cd
->system_lock
);
2641 cd
->int_status
&= ~CY_INT_IGNORE
;
2642 cd
->int_status
|= CY_INT_MODE_CHANGE
;
2643 rc
= cyttsp4_adap_write(cd
->core
->adap
, CY_REG_BASE
,
2644 (u8
*)ldr_exit
, sizeof(ldr_exit
));
2646 dev_err(cd
->dev
, "%s: Fail write adap='%s' r=%d\n",
2647 __func__
, cd
->core
->adap
->id
, rc
);
2648 mutex_unlock(&cd
->system_lock
);
2650 rc
= cyttsp4_wait_sysinfo_mode(cd
);
2652 u8 buf
[sizeof(ldr_err_app
)];
2655 rc1
= cyttsp4_adap_read(cd
->core
->adap
, CY_REG_BASE
,
2656 (u8
*)buf
, sizeof(ldr_err_app
));
2657 if (!rc1
&& !memcmp(buf
, ldr_err_app
, sizeof(ldr_err_app
)))
2658 dev_err(cd
->dev
, "%s: Invalid touch application\n", __func__
);
2660 cyttsp4_start_wd_timer(cd
);
2663 * Unable to switch to SYSINFO mode,
2664 * Corrupted FW may cause crash, exit here.
2666 dev_err(cd
->dev
, "%s: HGZ: Fail enter sysinfo mode\n",
2668 //return rc;// return 0 --> return rc
2672 /* read sysinfo data */
2673 dev_vdbg(cd
->dev
, "%s: get sysinfo regs..\n", __func__
);
2674 rc
= cyttsp4_get_sysinfo_regs(cd
);
2676 dev_err(cd
->dev
, "%s: failed to get sysinfo regs rc=%d\n",
2678 /* BEGIN PN:SPBB-1257 ,Deleted by l00184147, 2013/2/21*/
2679 //restart watchdog timer in another place for resovling ESD issue
2680 //cyttsp4_start_wd_timer(cd);
2681 /* END PN:SPBB-1257 ,Deleted by l00184147, 2013/2/21*/
2682 /* switch to operational mode */
2683 dev_vdbg(cd
->dev
, "%s: set mode cd->core=%p hst_mode=%02X mode=%d...\n",
2684 __func__
, cd
->core
, CY_HST_OPERATE
, CY_MODE_OPERATIONAL
);
2685 set_mode(cd
, CY_MODE_OPERATIONAL
);
2687 rc
= cyttsp4_get_ttconfig_info(cd
);
2689 dev_err(cd
->dev
, "%s: failed to get ttconfig info rc=%d\n",
2693 rc
= cyttsp4_set_opmode(cd
);
2695 dev_err(cd
->dev
, "%s: failed to set opmode rc=%d\n",
2698 /* attention startup */
2699 call_atten_cb(cd
, CY_ATTEN_STARTUP
, 0);
2700 /* BEGIN PN:SPBB-1257 ,Modified by l00184147, 2013/2/21*/
2701 /* restore to sleep if was suspended */
2702 mutex_lock(&cd
->system_lock
);
2703 if (cd
->sleep_state
== SS_SLEEP_ON
) {
2704 cd
->sleep_state
= SS_SLEEP_OFF
;
2705 mutex_unlock(&cd
->system_lock
);
2706 cyttsp4_core_sleep_(cd
);
2709 mutex_unlock(&cd
->system_lock
);
2711 cyttsp4_start_wd_timer(cd
);//restart watchdog timer here for resovling ESD issue
2714 /* Required for signal to the TTHE */
2715 dev_info(cd
->dev
, "%s: cyttsp4_exit startup r=%d...\n", __func__
, rc
);
2716 /* END PN:SPBB-1257 ,Modified by l00184147, 2013/2/21*/
2720 static int cyttsp4_startup(struct cyttsp4_core_data
*cd
)
2724 mutex_lock(&cd
->system_lock
);
2725 cd
->startup_state
= STARTUP_RUNNING
;
2726 mutex_unlock(&cd
->system_lock
);
2728 rc
= request_exclusive(cd
, cd
->core
,
2729 CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
2731 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
2732 __func__
, cd
->exclusive_dev
, cd
->core
);
2736 rc
= cyttsp4_startup_(cd
);
2738 if (release_exclusive(cd
, cd
->core
) < 0)
2739 /* Don't return fail code, mode is already changed. */
2740 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
2742 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
2745 mutex_lock(&cd
->system_lock
);
2746 cd
->startup_state
= STARTUP_NONE
;
2747 mutex_unlock(&cd
->system_lock
);
2749 wake_up(&cd
->wait_q
);
2754 static void cyttsp4_startup_work_function(struct work_struct
*work
)
2756 struct cyttsp4_core_data
*cd
= container_of(work
,
2757 struct cyttsp4_core_data
, startup_work
);
2761 * Force clear exclusive access
2762 * startup queue is called for abnormal case,
2763 * and when a this called access can be acquired in other context
2765 mutex_lock(&cd
->system_lock
);
2766 if (cd
->exclusive_dev
!= cd
->core
)
2767 cd
->exclusive_dev
= NULL
;
2768 mutex_unlock(&cd
->system_lock
);
2769 rc
= cyttsp4_startup(cd
);
2771 dev_err(cd
->dev
, "%s: Fail queued startup r=%d\n",
2775 static void cyttsp4_free_si_ptrs(struct cyttsp4_core_data
*cd
)
2777 struct cyttsp4_sysinfo
*si
= &cd
->sysinfo
;
2782 if (si
->si_ptrs
.cydata
)
2783 kfree(si
->si_ptrs
.cydata
->mfg_id
);
2784 kfree(si
->si_ptrs
.cydata
);
2785 kfree(si
->si_ptrs
.test
);
2786 kfree(si
->si_ptrs
.pcfg
);
2787 kfree(si
->si_ptrs
.opcfg
);
2788 kfree(si
->si_ptrs
.ddata
);
2789 kfree(si
->si_ptrs
.mdata
);
2793 kfree(si
->btn_rec_data
);
2796 #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_RUNTIME)
2797 static int cyttsp4_core_suspend(struct device
*dev
)
2799 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2802 dev_dbg(dev
, "%s\n", __func__
);
2804 rc
= cyttsp4_core_sleep(cd
);
2806 dev_err(dev
, "%s: Error on sleep\n", __func__
);
2812 static int cyttsp4_core_resume(struct device
*dev
)
2814 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2817 dev_dbg(dev
, "%s\n", __func__
);
2819 rc
= cyttsp4_core_wake(cd
);
2821 dev_err(dev
, "%s: Error on wake\n", __func__
);
2828 /* BEGIN PN:SPBB-1257 ,Modified by l00184147, 2013/2/21*/
2829 //Don't use the pm operation with PM sleep and runtime sleep
2830 //static const struct dev_pm_ops cyttsp4_core_pm_ops = {
2831 // SET_SYSTEM_SLEEP_PM_OPS(cyttsp4_core_suspend, cyttsp4_core_resume)
2832 // SET_RUNTIME_PM_OPS(cyttsp4_core_suspend, cyttsp4_core_resume, NULL)
2835 #ifdef CONFIG_HAS_EARLYSUSPEND
2836 /******************************************************************************
2837 Function:cyttsp4_core_early_suspend
2838 Description:called by Power management to make the touch sleep earlier
2839 ******************************************************************************/
2840 static void cyttsp4_core_early_suspend(struct early_suspend
*h
)
2842 struct cyttsp4_core_data
*cd
=
2843 container_of(h
, struct cyttsp4_core_data
, es
);
2846 dev_dbg(cd
->dev
, "%s\n", __func__
);
2848 rc
= cyttsp4_core_sleep(cd
);
2850 dev_err(cd
->dev
, "%s: Error on sleep\n", __func__
);
2854 /******************************************************************************
2855 Function:cyttsp4_core_late_resume
2856 Description:called by Power management to make the touch resume later
2857 ******************************************************************************/
2858 static void cyttsp4_core_late_resume(struct early_suspend
*h
)
2860 struct cyttsp4_core_data
*cd
=
2861 container_of(h
, struct cyttsp4_core_data
, es
);
2863 dev_dbg(cd
->dev
, "%s\n", __func__
);
2866 rc
= cyttsp4_core_wake(cd
);
2868 dev_err(cd
->dev
, "%s: Error on wake\n", __func__
);
2872 /******************************************************************************
2873 Function:cyttsp4_core_setup_early_suspend
2874 Description:regist early suspend for touch driver
2875 ******************************************************************************/
2876 void cyttsp4_core_setup_early_suspend(struct cyttsp4_core_data
*cd
)
2878 cd
->es
.level
= EARLY_SUSPEND_LEVEL_BLANK_SCREEN
+ 1;
2879 cd
->es
.suspend
= cyttsp4_core_early_suspend
;
2880 cd
->es
.resume
= cyttsp4_core_late_resume
;
2882 register_early_suspend(&cd
->es
);
2885 /* END PN:SPBB-1257 ,Modified by l00184147, 2013/2/21*/
2887 * Show Firmware version via sysfs
2889 static ssize_t
cyttsp4_ic_ver_show(struct device
*dev
,
2890 struct device_attribute
*attr
, char *buf
)
2892 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2893 struct cyttsp4_cydata
*cydata
;
2895 if (!cd
->sysinfo
.ready
)
2896 return sprintf(buf
, "Corrupted Touch application!\n");
2898 cydata
= cd
->sysinfo
.si_ptrs
.cydata
;
2901 "%s: 0x%02X 0x%02X\n"
2904 "%s: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n"
2908 "TrueTouch Product ID", cydata
->ttpidh
, cydata
->ttpidl
,
2909 "Firmware Major Version", cydata
->fw_ver_major
,
2910 "Firmware Minor Version", cydata
->fw_ver_minor
,
2911 "Revision Control Number", cydata
->revctrl
[0],
2912 cydata
->revctrl
[1], cydata
->revctrl
[2], cydata
->revctrl
[3],
2913 cydata
->revctrl
[4], cydata
->revctrl
[5], cydata
->revctrl
[6],
2915 "TrueTouch Config Version", cd
->sysinfo
.ttconfig
.version
,
2916 "Bootloader Major Version", cydata
->blver_major
,
2917 "Bootloader Minor Version", cydata
->blver_minor
);
2921 * Show TT Config version via sysfs
2923 static ssize_t
cyttsp4_ttconfig_ver_show(struct device
*dev
,
2924 struct device_attribute
*attr
, char *buf
)
2926 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2928 return sprintf(buf
, "0x%04X\n", cd
->sysinfo
.ttconfig
.version
);
2932 * Show Low power mode via sysfs
2934 static ssize_t
cyttsp4_low_power_show(struct device
*dev
,
2935 struct device_attribute
*attr
, char *buf
)
2937 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2941 rc
= cyttsp4_get_low_power(cd
, &enabled
);
2946 rc
= snprintf(buf
, CY_MAX_PRBUF_SIZE
,
2947 "Low power is ENABLED\n");
2949 rc
= snprintf(buf
, CY_MAX_PRBUF_SIZE
,
2950 "Low power is DISABLED\n");
2956 * Set Low power mode via sysfs
2958 static ssize_t
cyttsp4_low_power_store(struct device
*dev
,
2959 struct device_attribute
*attr
, const char *buf
, size_t size
)
2961 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2962 unsigned long value
;
2965 rc
= kstrtoul(buf
, 10, &value
);
2967 dev_err(dev
, "%s: Invalid value\n", __func__
);
2973 rc
= cyttsp4_set_low_power(cd
, false);
2976 rc
= cyttsp4_set_low_power(cd
, true);
2979 dev_err(dev
, "%s: Invalid value\n", __func__
);
2990 * Show Panel ID via sysfs
2992 static ssize_t
cyttsp4_panel_id_show(struct device
*dev
,
2993 struct device_attribute
*attr
, char *buf
)
2995 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
2997 if (!cd
->sysinfo
.ready
)
2998 return sprintf(buf
, "SysInfo not ready!\n");
3000 return sprintf(buf
, "%d\n",
3001 GET_PANELID(cd
->sysinfo
.si_ptrs
.pcfg
->panel_info0
));
3005 * Show Driver version via sysfs
3007 static ssize_t
cyttsp4_drv_ver_show(struct device
*dev
,
3008 struct device_attribute
*attr
, char *buf
)
3010 return snprintf(buf
, CY_MAX_PRBUF_SIZE
,
3011 "Driver: %s\nVersion: %s\nDate: %s\n",
3012 cy_driver_core_name
, cy_driver_core_version
,
3013 cy_driver_core_date
);
3017 * HW reset via sysfs
3019 static ssize_t
cyttsp4_hw_reset_store(struct device
*dev
,
3020 struct device_attribute
*attr
, const char *buf
, size_t size
)
3022 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3025 rc
= cyttsp4_startup(cd
);
3027 dev_err(dev
, "%s: HW reset failed r=%d\n",
3034 * Show IRQ status via sysfs
3036 /* static ssize_t cyttsp4_hw_irq_stat_show(struct device *dev, */
3037 /* struct device_attribute *attr, char *buf) */
3039 /* struct cyttsp4_core_data *cd = dev_get_drvdata(dev); */
3042 /* if (cd->pdata->irq_stat) { */
3043 /* retval = cd->pdata->irq_stat(cd->pdata, dev); */
3044 /* switch (retval) { */
3046 /* return snprintf(buf, CY_MAX_PRBUF_SIZE, */
3047 /* "Interrupt line is LOW.\n"); */
3049 /* return snprintf(buf, CY_MAX_PRBUF_SIZE, */
3050 /* "Interrupt line is HIGH.\n"); */
3052 /* return snprintf(buf, CY_MAX_PRBUF_SIZE, */
3053 /* "Function irq_stat() returned %d.\n", retval); */
3057 /* return snprintf(buf, CY_MAX_PRBUF_SIZE, */
3058 /* "Function irq_stat() undefined.\n"); */
3062 /* * Show IRQ enable/disable status via sysfs */
3064 /* static ssize_t cyttsp4_drv_irq_show(struct device *dev, */
3065 /* struct device_attribute *attr, char *buf) */
3067 /* struct cyttsp4_core_data *cd = dev_get_drvdata(dev); */
3070 /* mutex_lock(&cd->system_lock); */
3071 /* if (cd->irq_enabled) */
3072 /* ret = snprintf(buf, CY_MAX_PRBUF_SIZE, */
3073 /* "Driver interrupt is ENABLED\n"); */
3075 /* ret = snprintf(buf, CY_MAX_PRBUF_SIZE, */
3076 /* "Driver interrupt is DISABLED\n"); */
3077 /* mutex_unlock(&cd->system_lock); */
3083 * Enable/disable IRQ via sysfs
3085 /* static ssize_t cyttsp4_drv_irq_store(struct device *dev, */
3086 /* struct device_attribute *attr, const char *buf, size_t size) */
3088 /* struct cyttsp4_core_data *cd = dev_get_drvdata(dev); */
3089 /* unsigned long value; */
3090 /* int retval = 0; */
3092 /* if (cd->irq < 0) { */
3093 /* dev_err(dev, "%s: Invalid irq\n", __func__); */
3094 /* goto cyttsp4_drv_irq_store_error_exit; */
3097 /* retval = kstrtoul(buf, 10, &value); */
3098 /* if (retval < 0) { */
3099 /* dev_err(dev, "%s: Invalid value\n", __func__); */
3100 /* goto cyttsp4_drv_irq_store_error_exit; */
3103 /* mutex_lock(&cd->system_lock); */
3104 /* switch (value) { */
3106 /* if (cd->irq_enabled) { */
3107 /* cd->irq_enabled = false; */
3108 /* /\* Disable IRQ *\/ */
3109 /* disable_irq_nosync(cd->irq); */
3110 /* dev_info(dev, "%s: Driver IRQ now disabled\n", */
3113 /* dev_info(dev, "%s: Driver IRQ already disabled\n", */
3118 /* if (cd->irq_enabled == false) { */
3119 /* cd->irq_enabled = true; */
3120 /* /\* Enable IRQ *\/ */
3121 /* enable_irq(cd->irq); */
3122 /* dev_info(dev, "%s: Driver IRQ now enabled\n", */
3125 /* dev_info(dev, "%s: Driver IRQ already enabled\n", */
3130 /* dev_err(dev, "%s: Invalid value\n", __func__); */
3132 /* mutex_unlock(&(cd->system_lock)); */
3134 /* cyttsp4_drv_irq_store_error_exit: */
3140 * Debugging options via sysfs
3142 static ssize_t
cyttsp4_drv_debug_store(struct device
*dev
,
3143 struct device_attribute
*attr
, const char *buf
, size_t size
)
3145 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3146 unsigned long value
= 0;
3150 rc
= kstrtoul(buf
, 10, &value
);
3152 dev_err(dev
, "%s: Invalid value\n", __func__
);
3153 goto cyttsp4_drv_debug_store_exit
;
3157 case CY_DBG_SUSPEND
:
3158 dev_info(dev
, "%s: SUSPEND (cd=%p)\n", __func__
, cd
);
3159 rc
= cyttsp4_core_sleep(cd
);
3160 printk("cyttsp4_drv_debug_store, rc1 = %d\n", rc1
);
3162 dev_err(dev
, "%s: Suspend failed rc=%d\n",
3165 dev_info(dev
, "%s: Suspend succeeded\n", __func__
);
3169 dev_info(dev
, "%s: RESUME (cd=%p)\n", __func__
, cd
);
3170 rc
= cyttsp4_core_wake(cd
);
3172 dev_err(dev
, "%s: Resume failed rc=%d\n",
3175 dev_info(dev
, "%s: Resume succeeded\n", __func__
);
3177 case CY_DBG_SOFT_RESET
:
3178 dev_info(dev
, "%s: SOFT RESET (cd=%p)\n", __func__
, cd
);
3179 rc
= cyttsp4_hw_soft_reset(cd
);
3182 dev_info(dev
, "%s: HARD RESET (cd=%p)\n", __func__
, cd
);
3183 rc
= cyttsp4_hw_hard_reset(cd
);
3186 dev_err(dev
, "%s: Invalid value\n", __func__
);
3189 cyttsp4_drv_debug_store_exit
:
3194 * Show system status on deep sleep status via sysfs
3196 static ssize_t
cyttsp4_sleep_status_show(struct device
*dev
,
3197 struct device_attribute
*attr
, char *buf
)
3199 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3202 mutex_lock(&cd
->system_lock
);
3203 if (cd
->sleep_state
== SS_SLEEP_ON
)
3204 ret
= snprintf(buf
, CY_MAX_PRBUF_SIZE
,
3205 "Deep Sleep is ENABLED\n");
3207 ret
= snprintf(buf
, CY_MAX_PRBUF_SIZE
,
3208 "Deep Sleep is DISABLED\n");
3209 mutex_unlock(&cd
->system_lock
);
3214 static ssize_t
cyttsp4_signal_disparity_show(struct device
*dev
,
3215 struct device_attribute
*attr
, char *buf
)
3217 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3218 u8 cmd_buf
[CY_CMD_OP_GET_PARA_CMD_SZ
];
3219 u8 return_buf
[CY_CMD_OP_GET_PARA_RET_SZ
];
3222 cmd_buf
[0] = CY_CMD_OP_GET_PARA
;
3223 cmd_buf
[1] = CY_OP_PARA_SCAN_TYPE
;
3225 pm_runtime_get_sync(dev
);
3227 rc
= request_exclusive(cd
, cd
->core
, CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
3229 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
3230 __func__
, cd
->exclusive_dev
, cd
->core
);
3234 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_OPERATIONAL
,
3235 cmd_buf
, sizeof(cmd_buf
),
3236 return_buf
, sizeof(return_buf
),
3237 CY_COMMAND_COMPLETE_TIMEOUT
);
3239 dev_err(dev
, "%s: exec cmd error.\n", __func__
);
3243 dev_dbg(dev
, "%s: return_buf=0x%x,0x%x,0x%x\n", __func__
,
3244 return_buf
[0], return_buf
[1], return_buf
[2]);
3246 if (return_buf
[0] != CY_OP_PARA_SCAN_TYPE
) {
3247 dev_err(dev
, "%s: return data error.\n", __func__
);
3255 if (release_exclusive(cd
, cd
->core
) < 0)
3256 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
3258 pm_runtime_put(dev
);
3259 return scnprintf(buf
, CY_MAX_PRBUF_SIZE
, "%d\n", rc
);
3262 static ssize_t
cyttsp4_signal_disparity_store(struct device
*dev
,
3263 struct device_attribute
*attr
, const char *buf
, size_t size
)
3265 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3266 unsigned long disparity_val
;
3267 u8 cmd_buf
[CY_CMD_OP_SET_PARA_CMD_SZ
];
3268 u8 return_buf
[CY_CMD_OP_SET_PARA_RET_SZ
];
3272 rc
= kstrtoul(buf
, 10, &disparity_val
);
3274 dev_err(dev
, "%s: Invalid value.\n", __func__
);
3278 mutex_lock(&cd
->system_lock
);
3279 switch (disparity_val
) {
3280 case CY_SIGNAL_DISPARITY_NONE
:
3281 cd
->opmode
= OPMODE_FINGER
;
3282 scan_type
= CY_OP_PARA_SCAN_TYPE_NORMAL
;
3284 case CY_SIGNAL_DISPARITY_SENSITIVITY
:
3285 cd
->opmode
= OPMODE_GLOVE
;
3286 scan_type
= CY_OP_PARA_SCAN_TYPE_APAMC_MASK
|
3287 CY_OP_PARA_SCAN_TYPE_GLOVE_MASK
;
3290 mutex_unlock(&cd
->system_lock
);
3291 dev_err(dev
, "%s: Invalid signal disparity=%d\n", __func__
,
3292 (int)disparity_val
);
3296 mutex_unlock(&cd
->system_lock
);
3298 cmd_buf
[0] = CY_CMD_OP_SET_PARA
;
3299 cmd_buf
[1] = CY_OP_PARA_SCAN_TYPE
;
3300 cmd_buf
[2] = CY_OP_PARA_SCAN_TYPE_SZ
;
3301 cmd_buf
[3] = scan_type
;
3303 pm_runtime_get_sync(dev
);
3305 rc
= request_exclusive(cd
, cd
->core
, CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
3307 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
3308 __func__
, cd
->exclusive_dev
, cd
->core
);
3312 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_OPERATIONAL
,
3313 cmd_buf
, sizeof(cmd_buf
),
3314 return_buf
, sizeof(return_buf
),
3315 CY_COMMAND_COMPLETE_TIMEOUT
);
3317 dev_err(dev
, "%s: exec cmd error.\n", __func__
);
3322 dev_dbg(dev
, "%s: return_buf=0x%x,0x%x\n", __func__
,
3323 return_buf
[0], return_buf
[1]);
3325 if (release_exclusive(cd
, cd
->core
) < 0)
3326 /* Don't return fail code, mode is already changed. */
3327 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
3329 dev_vdbg(cd
->dev
, "%s: pass release exclusive\n", __func__
);
3331 pm_runtime_put(dev
);
3337 * Show finger threshold value via sysfs
3339 static ssize_t
cyttsp4_finger_threshold_show(struct device
*dev
,
3340 struct device_attribute
*attr
, char *buf
)
3342 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3343 u8 cmd_buf
[CY_CMD_OP_GET_PARA_CMD_SZ
];
3344 u8 return_buf
[CY_CMD_OP_GET_PARA_RET_SZ
];
3345 u8 finger_threshold_h
, finger_threshold_l
;
3348 cmd_buf
[0] = CY_CMD_OP_GET_PARA
;
3349 cmd_buf
[1] = CY_OP_PARA_FINGER_THRESHOLD
;
3351 pm_runtime_get_sync(dev
);
3352 rc
= request_exclusive(cd
, cd
->core
, CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
3354 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
3355 __func__
, cd
->exclusive_dev
, cd
->core
);
3359 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_OPERATIONAL
,
3360 cmd_buf
, sizeof(cmd_buf
),
3361 return_buf
, sizeof(return_buf
),
3362 CY_COMMAND_COMPLETE_TIMEOUT
);
3364 dev_err(dev
, "%s: exec cmd error.\n", __func__
);
3368 dev_dbg(dev
, "%s: return_buf=0x%x,0x%x,0x%x,0x%x\n", __func__
,
3369 return_buf
[0], return_buf
[1], return_buf
[2],
3372 if (return_buf
[0] != CY_OP_PARA_FINGER_THRESHOLD
) {
3373 dev_err(dev
, "%s: return data error.\n", __func__
);
3378 finger_threshold_h
= return_buf
[2];
3379 finger_threshold_l
= return_buf
[3];
3380 rc
= merge_bytes(finger_threshold_h
, finger_threshold_l
);
3383 if (release_exclusive(cd
, cd
->core
) < 0)
3384 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
3386 pm_runtime_put(dev
);
3387 return scnprintf(buf
, CY_MAX_PRBUF_SIZE
, "%d\n", rc
);
3391 * change finger threshold via sysfs
3393 static ssize_t
cyttsp4_finger_threshold_store(struct device
*dev
,
3394 struct device_attribute
*attr
, const char *buf
, size_t size
)
3396 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3397 unsigned long threshold_val
;
3398 u8 cmd_buf
[CY_CMD_OP_SET_PARA_CMD_SZ
];
3399 u8 return_buf
[CY_CMD_OP_SET_PARA_RET_SZ
];
3402 rc
= kstrtoul(buf
, 10, &threshold_val
);
3404 dev_err(dev
, "%s: Invalid value.\n", __func__
);
3408 if ((threshold_val
< CY_OP_PARA_FINGER_THRESHOLD_MIN_VAL
) ||
3409 (threshold_val
> CY_OP_PARA_FINGER_THRESHOLD_MAX_VAL
)) {
3410 dev_err(dev
, "%s: Invalid value, value=%d.\n", __func__
,
3411 (int)threshold_val
);
3416 cmd_buf
[0] = CY_CMD_OP_SET_PARA
;
3417 cmd_buf
[1] = CY_OP_PARA_FINGER_THRESHOLD
;
3418 cmd_buf
[2] = CY_OP_PARA_FINGER_THRESHOLD_SZ
;
3419 cmd_buf
[3] = (u8
)((threshold_val
>> 8) & 0xFF);
3420 cmd_buf
[4] = (u8
)(threshold_val
& 0xFF);
3422 pm_runtime_get_sync(dev
);
3423 rc
= request_exclusive(cd
, cd
->core
, CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT
);
3425 dev_err(cd
->dev
, "%s: fail get exclusive ex=%p own=%p\n",
3426 __func__
, cd
->exclusive_dev
, cd
->core
);
3430 rc
= cyttsp4_exec_cmd(cd
, CY_MODE_OPERATIONAL
,
3431 cmd_buf
, sizeof(cmd_buf
),
3432 return_buf
, sizeof(return_buf
),
3433 CY_COMMAND_COMPLETE_TIMEOUT
);
3435 dev_err(dev
, "%s: exec cmd error.\n", __func__
);
3440 dev_dbg(dev
, "%s: return_buf=0x%x,0x%x\n", __func__
,
3441 return_buf
[0], return_buf
[1]);
3444 if (release_exclusive(cd
, cd
->core
) < 0)
3445 dev_err(cd
->dev
, "%s: fail to release exclusive\n", __func__
);
3447 pm_runtime_put(dev
);
3453 static struct device_attribute attributes
[] = {
3454 __ATTR(ic_ver
, S_IRUGO
, cyttsp4_ic_ver_show
, NULL
),
3455 __ATTR(ttconfig_ver
, S_IRUGO
, cyttsp4_ttconfig_ver_show
, NULL
),
3456 __ATTR(low_power
, S_IRUSR
| S_IWUSR
, cyttsp4_low_power_show
,
3457 cyttsp4_low_power_store
),
3458 __ATTR(panel_id
, S_IRUSR
, cyttsp4_panel_id_show
, NULL
),
3459 __ATTR(drv_ver
, S_IRUGO
, cyttsp4_drv_ver_show
, NULL
),
3460 __ATTR(hw_reset
, S_IWUSR
, NULL
, cyttsp4_hw_reset_store
),
3461 /* __ATTR(hw_irq_stat, S_IRUSR, cyttsp4_hw_irq_stat_show, NULL), */
3462 /* __ATTR(drv_irq, S_IRUSR | S_IWUSR, cyttsp4_drv_irq_show, */
3463 /* cyttsp4_drv_irq_store), */
3464 __ATTR(drv_debug
, S_IWUSR
, NULL
, cyttsp4_drv_debug_store
),
3465 __ATTR(sleep_status
, S_IRUSR
, cyttsp4_sleep_status_show
, NULL
),
3468 static int add_sysfs_interfaces(struct device
*dev
)
3472 for (i
= 0; i
< ARRAY_SIZE(attributes
); i
++)
3473 if (device_create_file(dev
, attributes
+ i
))
3477 for (; i
>= 0 ; i
--)
3478 device_remove_file(dev
, attributes
+ i
);
3479 dev_err(dev
, "%s: failed to create sysfs interface\n", __func__
);
3483 static void remove_sysfs_interfaces(struct device
*dev
)
3486 for (i
= 0; i
< ARRAY_SIZE(attributes
); i
++)
3487 device_remove_file(dev
, attributes
+ i
);
3490 /* BEGIN PN:DTS2013033005872 ,Modified by F00184246, 2013/3/30*/
3491 /* BEGIN PN: SPBB-1264 ,Modified by l00184147, 2013/2/27*/
3492 static struct device_attribute sensitivity_attributes
[] = {
3493 __ATTR(signal_disparity
, S_IRUGO
| S_IWUSR
| S_IWGRP
,
3494 cyttsp4_signal_disparity_show
, cyttsp4_signal_disparity_store
),
3495 __ATTR(finger_threshold
, S_IRUGO
| S_IWUSR
|S_IWGRP
,
3496 cyttsp4_finger_threshold_show
, cyttsp4_finger_threshold_store
),
3498 /* END PN: SPBB-1264 ,Modified by l00184147, 2013/2/27*/
3499 /* END PN:DTS2013033005872 ,Modified by F00184246, 2013/3/30*/
3501 static int add_sensitivity_sysfs_interfaces(struct device
*dev
)
3505 for (i
= 0; i
< ARRAY_SIZE(sensitivity_attributes
); i
++)
3506 if (device_create_file(dev
, sensitivity_attributes
+ i
))
3510 for (i
--; i
>= 0 ; i
--)
3511 device_remove_file(dev
, sensitivity_attributes
+ i
);
3512 dev_err(dev
, "%s: failed to create sysfs interface\n", __func__
);
3516 static void remove_sensitivity_sysfs_interfaces(struct device
*dev
)
3519 for (i
= 0; i
< ARRAY_SIZE(sensitivity_attributes
); i
++)
3520 device_remove_file(dev
, sensitivity_attributes
+ i
);
3523 static DECLARE_WAIT_QUEUE_HEAD(waiter
);
3524 static int cyttsp4_event_flag
= 0;
3525 static int tpd_halt
=0;
3526 static struct task_struct
*cyttsp4_event_thread
= NULL
;
3528 void eint_interrupt_handler(void) {
3529 cyttsp4_event_flag
=1;
3530 wake_up_interruptible(&waiter
);
3533 static int cyttsp4_event_handler(void *unused
) {
3535 struct cyttsp4_core_data
*cd
= (struct cyttsp4_core_data
*)unused
;
3536 struct sched_param param
= { .sched_priority
= RTPM_PRIO_TPD
};
3538 sched_setscheduler(current
, SCHED_RR
, ¶m
);
3541 set_current_state(TASK_INTERRUPTIBLE
);
3542 signal
= wait_event_interruptible(waiter
, cyttsp4_event_flag
!= 0);
3544 cyttsp4_event_flag
= 0;
3545 set_current_state(TASK_RUNNING
);
3549 cyttsp4_mtk_gpio_interrupt_enable();
3550 } while (!kthread_should_stop());
3554 static int cyttsp4_core_probe(struct cyttsp4_core
*core
)
3556 struct cyttsp4_core_data
*cd
;
3557 struct device
*dev
= &core
->dev
;
3558 struct cyttsp4_core_platform_data
*pdata
= dev_get_platdata(dev
);
3559 enum cyttsp4_atten_type type
;
3560 unsigned long irq_flags
;
3564 dev_info(dev
, "%s: startup\n", __func__
);
3565 dev_dbg(dev
, "%s: debug on\n", __func__
);
3566 dev_vdbg(dev
, "%s: verbose debug on\n", __func__
);
3568 if (pdata
== NULL
) {
3569 dev_err(dev
, "%s: Missing platform data\n", __func__
);
3571 goto error_no_pdata
;
3574 /* get context and debug print buffers */
3575 cd
= kzalloc(sizeof(*cd
), GFP_KERNEL
);
3577 dev_err(dev
, "%s: Error, kzalloc\n", __func__
);
3579 goto error_alloc_data_failed
;
3582 /* point to core device and init lists */
3584 mutex_init(&cd
->system_lock
);
3585 mutex_init(&cd
->adap_lock
);
3586 for (type
= 0; type
< CY_ATTEN_NUM_ATTEN
; type
++)
3587 INIT_LIST_HEAD(&cd
->atten_list
[type
]);
3588 init_waitqueue_head(&cd
->wait_q
);
3589 init_waitqueue_head(&cd
->sleep_q
);
3590 cd
->startup_work_q
= create_singlethread_workqueue("startup_work_q");
3591 if (cd
->startup_work_q
== NULL
) {
3592 dev_err(dev
, "%s: No memory for %s\n", __func__
,
3597 dev_dbg(dev
, "%s: initialize core data\n", __func__
);
3598 spin_lock_init(&cd
->spinlock
);
3601 #ifdef HUAWEI_SET_FINGER_MODE_BY_DEFAULT
3602 /* Initialize with Finger mode */
3603 cd
->opmode
= OPMODE_FINGER
;
3605 /* BEGIN PN:DTS2013051404084 ,Added by f00184246, 2013/5/14*/
3606 /* init cd->startup_work before intertupt*/
3607 INIT_WORK(&cd
->startup_work
, cyttsp4_startup_work_function
);
3608 /* BEGIN PN:DTS2013051404084 ,Added by f00184246, 2013/5/14*/
3610 cyttsp4_event_thread
= kthread_run(cyttsp4_event_handler
, cd
, "cyttsp4_event_handler");
3611 if (IS_ERR(cyttsp4_event_thread
)) {
3612 err
= PTR_ERR(cyttsp4_event_thread
);
3614 cyttsp4_mtk_gpio_interrupt_register();
3615 cyttsp4_mtk_gpio_interrupt_enable();
3618 /* cd->irq = gpio_to_irq(pdata->irq_gpio); */
3619 /* cd->irq_enabled = true; */
3620 /* if (cd->irq < 0) { */
3622 /* goto error_gpio_irq; */
3625 dev_set_drvdata(dev
, cd
);
3627 if (cd
->pdata
->init
) {
3628 dev_info(cd
->dev
, "%s: Init HW\n", __func__
);
3629 rc
= cd
->pdata
->init(cd
->pdata
, 1, cd
->dev
);
3631 dev_info(cd
->dev
, "%s: No HW INIT function\n", __func__
);
3635 dev_err(cd
->dev
, "%s: HW Init fail r=%d\n", __func__
, rc
);
3637 dev_info(cd
->dev
, "%s: check cypress device exit or not\n", __func__
);
3638 rc
= cyttsp4_reset_checkout(cd
);
3640 dev_err(cd
->dev
, "%s: there is no cypress device!!! rc=%d\n", __func__
, rc
);
3641 goto error_request_irq
;
3643 /* BEGIN PN:DTS2013051404084 ,Deleted by f00184246, 2013/5/14*/
3644 //INIT_WORK(&cd->startup_work, cyttsp4_startup_work_function);
3645 /* END PN:DTS2013051404084 ,Deleted by f00184246, 2013/5/14*/
3647 /* dev_dbg(dev, "%s: initialize threaded irq=%d\n", __func__, cd->irq); */
3648 /* if (cd->pdata->level_irq_udelay > 0) */
3649 /* /\* use level triggered interrupts *\/ */
3650 /* irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT; */
3652 /* /\* use edge triggered interrupts *\/ */
3653 /* irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; */
3655 /* rc = request_threaded_irq(cd->irq, NULL, cyttsp4_irq, irq_flags, */
3656 /* dev_name(dev), cd); */
3658 /* dev_err(dev, "%s: Error, could not request irq\n", __func__); */
3659 /* goto error_request_irq; */
3663 #ifdef CYTTSP4_WATCHDOG_NULL_CMD
3664 INIT_WORK(&cd
->watchdog_work
, cyttsp4_watchdog_work_null
);
3666 INIT_WORK(&cd
->watchdog_work
, cyttsp4_watchdog_work
);
3668 setup_timer(&cd
->watchdog_timer
, cyttsp4_watchdog_timer
,
3671 dev_dbg(dev
, "%s: add sysfs interfaces\n", __func__
);
3672 rc
= add_sysfs_interfaces(dev
);
3674 dev_err(dev
, "%s: Error, fail sysfs init\n", __func__
);
3675 goto error_attr_create
;
3678 if (cd
->pdata
->use_configure_sensitivity
) {
3679 rc
= add_sensitivity_sysfs_interfaces(dev
);
3681 dev_err(dev
, "%s: Error, fail sensitivity sysfs init\n",
3683 goto error_sens_attr_create
;
3687 pm_runtime_enable(dev
);
3690 * call startup directly to ensure that the device
3691 * is tested before leaving the probe
3693 dev_dbg(dev
, "%s: call startup\n", __func__
);
3695 pm_runtime_get_sync(dev
);
3696 rc
= cyttsp4_startup(cd
);
3697 pm_runtime_put(dev
);
3700 dev_err(cd
->dev
, "%s: Fail initial startup r=%d\n",
3704 /* BEGIN PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
3705 #ifdef CONFIG_HAS_EARLYSUSPEND
3706 cyttsp4_core_setup_early_suspend(cd
);
3708 /* END PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
3709 dev_info(dev
, "%s: ok\n", __func__
);
3714 /* BEGIN PN:DTS2013062405322 ,Modified by l00184147, 2013/6/24*/
3715 cyttsp4_stop_wd_timer(cd
);
3716 /* END PN:DTS2013062405322 ,Modified by l00184147, 2013/6/24*/
3717 pm_runtime_disable(dev
);
3718 cyttsp4_free_si_ptrs(cd
);
3719 error_sens_attr_create
:
3720 remove_sysfs_interfaces(dev
);
3722 /* if (cd->irq >= 0) */
3723 /* free_irq(cd->irq, cd); */
3726 destroy_workqueue(cd
->startup_work_q
);
3728 pdata
->init(pdata
, 0, dev
);
3730 dev_set_drvdata(dev
, NULL
);
3732 error_alloc_data_failed
:
3734 dev_err(dev
, "%s failed.\n", __func__
);
3735 return -ENOMEM
; //hgz
3740 static int cyttsp4_core_release(struct cyttsp4_core
*core
)
3742 struct device
*dev
= &core
->dev
;
3743 struct cyttsp4_core_data
*cd
= dev_get_drvdata(dev
);
3745 dev_dbg(dev
, "%s\n", __func__
);
3746 /* BEGIN PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
3747 #ifdef CONFIG_HAS_EARLYSUSPEND
3748 unregister_early_suspend(&cd
->es
);
3750 /* END PN:SPBB-1257 ,Added by l00184147, 2013/2/21*/
3752 * Suspend the device before freeing the startup_work and stopping
3753 * the watchdog since sleep function restarts watchdog on failure
3755 pm_runtime_suspend(dev
);
3756 pm_runtime_disable(dev
);
3758 cancel_work_sync(&cd
->startup_work
);
3759 destroy_workqueue(cd
->startup_work_q
);
3761 cyttsp4_stop_wd_timer(cd
);
3763 remove_sysfs_interfaces(dev
);
3764 /* if (cd->irq >= 0) */
3765 /* free_irq(cd->irq, cd); */
3766 if (cd
->pdata
->init
)
3767 cd
->pdata
->init(cd
->pdata
, 0, dev
);
3768 dev_set_drvdata(dev
, NULL
);
3769 cyttsp4_free_si_ptrs(cd
);
3774 struct cyttsp4_core_driver cyttsp4_core_driver
= {
3775 .probe
= cyttsp4_core_probe
,
3776 .remove
= cyttsp4_core_release
,
3777 .subscribe_attention
= cyttsp4_subscribe_attention_
,
3778 .unsubscribe_attention
= cyttsp4_unsubscribe_attention_
,
3779 .request_exclusive
= cyttsp4_request_exclusive_
,
3780 .release_exclusive
= cyttsp4_release_exclusive_
,
3781 .request_reset
= cyttsp4_request_reset_
,
3782 .request_restart
= cyttsp4_request_restart_
,
3783 .request_set_mode
= cyttsp4_request_set_mode_
,
3784 .request_sysinfo
= cyttsp4_request_sysinfo_
,
3785 .request_loader_pdata
= cyttsp4_request_loader_pdata_
,
3786 .request_handshake
= cyttsp4_request_handshake_
,
3787 .request_exec_cmd
= cyttsp4_request_exec_cmd_
,
3788 .request_stop_wd
= cyttsp4_request_stop_wd_
,
3789 .request_toggle_lowpower
= cyttsp4_request_toggle_lowpower_
,
3790 .request_write_config
= cyttsp4_request_write_config_
,
3791 .write
= cyttsp4_write_
,
3792 .read
= cyttsp4_read_
,
3794 .name
= CYTTSP4_CORE_NAME
,
3795 .bus
= &cyttsp4_bus_type
,
3796 .owner
= THIS_MODULE
,
3797 /* BEGIN PN:SPBB-1257 ,Deleted by l00184147, 2013/2/21*/
3798 //no longer to use pm operation
3799 //.pm = &cyttsp4_core_pm_ops,
3800 /* END PN:SPBB-1257 ,Deleted by l00184147, 2013/2/21*/
3804 static int __init
cyttsp4_core_init(void)
3808 rc
= cyttsp4_register_core_driver(&cyttsp4_core_driver
);
3809 pr_info("%s: Cypress TTSP v4 core driver (Built %s) rc=%d\n",
3810 __func__
, CY_DRIVER_DATE
, rc
);
3813 module_init(cyttsp4_core_init
);
3815 static void __exit
cyttsp4_core_exit(void)
3817 cyttsp4_unregister_core_driver(&cyttsp4_core_driver
);
3818 pr_info("%s: module exit\n", __func__
);
3820 module_exit(cyttsp4_core_exit
);
3822 MODULE_LICENSE("GPL");
3823 MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen core driver");
3824 MODULE_AUTHOR("Aleksej Makarov <aleksej.makarov@sonyericsson.com>");
3825 /* END PN:SPBB-1218 ,Added by l00184147, 2012/12/20*/
3826 /* END PN:DTS2013011401860 ,Modified by l00184147, 2013/1/14*/
3827 /* END PN:DTS2013012601133 ,Modified by l00184147, 2013/1/26*/
3828 /* END PN:DTS2013051703879 ,Added by l00184147, 2013/5/17*/