1 #define CT363_POINT_NUM 10
3 struct ct363_finger_data {
4 unsigned char xhi; // X coordinate Hi
5 unsigned char yhi; // Y coordinate Hi
6 unsigned char ylo : 4; // Y coordinate Lo
7 unsigned char xlo : 4; // X coordinate Lo
8 unsigned char status : 3; // Action information, 1: Down; 2: Move; 3: Up
9 unsigned char id : 5; // ID information, from 1 to CFG_MAX_POINT_NUM
10 unsigned char area; // Touch area
11 unsigned char pressure; // Touch Pressure
20 struct ct363_finger_data pts[CT363_POINT_NUM];
21 char buf[CT363_POINT_NUM * sizeof(struct ct363_finger_data)];
25 static int ct363_init_hw(struct ct36x_data *ts)
29 ret = gpio_request(ts->rst_io.gpio, "ct363_rst");
31 dev_err(ts->dev, "Failed to request rst gpio\n");
35 ret = gpio_request(ts->irq_io.gpio, "ct363_irq");
37 gpio_free(ts->rst_io.gpio);
38 dev_err(ts->dev, "Failed to request irq gpio\n");
41 gpio_direction_input(ts->irq_io.gpio);
42 //gpio_pull_updown(ts->irq_io.gpio, 1);
43 //gpio_set_value(ts->irq_io.gpio,1);
44 gpio_direction_output(ts->rst_io.gpio, ts->rst_io.active_low);
48 static void ct363_deinit_hw(struct ct36x_data *ts)
50 gpio_free(ts->rst_io.gpio);
51 gpio_free(ts->irq_io.gpio);
54 static void ct363_reset_hw(struct ct36x_data *ts)
56 gpio_direction_output(ts->rst_io.gpio, ts->rst_io.active_low);
58 gpio_set_value(ts->rst_io.gpio, !ts->rst_io.active_low);
60 gpio_set_value(ts->rst_io.gpio, ts->rst_io.active_low);
64 static int ct363_init(struct ct36x_data *ts)
66 int ret = 0, fwchksum, binchksum, updcnt = 5;
67 struct ct363_priv *ct363 = NULL;
69 ret = ct363_init_hw(ts);
75 // Get binary Checksum
76 binchksum = ct36x_chip_get_binchksum();
77 ct36x_dbg(ts, "CT363 init: binchksum = %d\n", binchksum);
79 ret = ct36x_chip_get_fwchksum(ts);
81 dev_err(ts->dev, "CT36X chip: Failed to get fwchksum\n");
85 ct36x_dbg(ts, "CT363 init: fwchksum = %d\n", fwchksum);
86 while(binchksum != fwchksum && updcnt--) {
88 ret = ct36x_chip_go_bootloader(ts);
90 dev_err(ts->dev, "CT36X chip: Failed to go bootloader\n");
96 ret = ct36x_chip_get_fwchksum(ts);
98 dev_err(ts->dev, "CT36X chip: Failed to get fwchksum\n");
102 ct36x_dbg(ts, "CT363 update FW: fwchksum = %d\n", fwchksum);
104 if(binchksum != fwchksum){
105 dev_err(ts->dev, "Fail to update FW\n");
113 ts->point_num = CT363_POINT_NUM;
115 ct363 = kzalloc(sizeof(struct ct363_priv), GFP_KERNEL);
117 dev_err(ts->dev, "No memory for ct36x");
125 static void ct363_deinit(struct ct36x_data *ts)
127 struct ct363_priv *ct363 = ts->priv;
136 static int ct363_first_init_flag = 1;
137 static int ct363_suspend(struct ct36x_data *ts)
141 ret = ct36x_chip_go_sleep(ts);
142 ct363_first_init_flag=0;
144 dev_warn(ts->dev, "CT363 chip: failed to go to sleep\n");
148 static int ct363_resume(struct ct36x_data *ts)
153 if(ct363_first_init_flag)
157 // gpio_direction_output(ts->rst_io.gpio, ts->rst_io.active_low);
159 gpio_set_value(ts->rst_io.gpio, !ts->rst_io.active_low);
161 gpio_set_value(ts->rst_io.gpio, ts->rst_io.active_low);
164 for(i = 0; i < ts->point_num; i++){
165 input_mt_slot(ts->input, i);
166 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
168 input_sync(ts->input);
173 static void ct363_report(struct ct36x_data *ts)
178 int len = sizeof(struct ct363_finger_data) * ts->point_num;
179 struct ct363_priv *ct363 = ts->priv;
181 ret = ct36x_read(ts, ct363->buf, len);
183 dev_warn(ts->dev, "Failed to read finger data\n");
187 if(ct36x_dbg_level==2)
188 for(t=0;t< ts->point_num;t++){
189 ct36x_dbg(ts, "CT363buf[%d]: ", t);
191 ct36x_dbg(ts, " 0x%x %x %x %x %x %x %x %x ",ct363->pts[t].xhi,
195 ct363->pts[t].status,
198 ct363->pts[t].pressure);
200 ct36x_dbg(ts, " \n ");
204 for(i = 0; i < ts->point_num; i++){
205 if((ct363->pts[i].xhi != 0xFF && ct363->pts[i].yhi != 0xFF) &&
206 (ct363->pts[i].status == 1 || ct363->pts[i].status == 2)){
207 x = (ct363->pts[i].xhi<<4)|(ct363->pts[i].xlo&0xF);
208 y = (ct363->pts[i].yhi<<4)|(ct363->pts[i].ylo&0xF);
210 ct363->x = ts->orientation[0] * x + ts->orientation[1] * y;
211 ct363->y = ts->orientation[2] * x + ts->orientation[3] * y;
213 if( (ct363->x > ts->x_max) || (ct363->y > ts->y_max) || (ct363->x < 0) || (ct363->y < 0) ){
216 if(flag_ct36x_model==363){
217 ct363->y = ts->y_max - ct363->y; //add for p977
219 input_mt_slot(ts->input, ct363->pts[i].id - 1);
220 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, true);
221 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, 1);
222 input_report_abs(ts->input, ABS_MT_POSITION_X, ct363->x);
223 input_report_abs(ts->input, ABS_MT_POSITION_Y, ct363->y);
224 input_report_abs(ts->input, ABS_MT_PRESSURE, ct363->pts[i].pressure);
225 ct36x_dbg(ts, "CT363 report value: id: %d, x: %d, y:%d\n",ct363->pts[i].id - 1, ct363->x, ct363->y);
228 ct363->press |= 0x01 << (ct363->pts[i].id - 1);
231 ct363->release &= ct363->release ^ ct363->press;
232 for(i = 0; i < ts->point_num; i++){
233 if ( ct363->release & (0x01<<i) ) {
234 input_mt_slot(ts->input, i);
235 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
236 ct36x_dbg(ts, "CT363 release\n");
240 ct363->release = ct363->press;
243 input_sync(ts->input);
247 struct ct36x_ops ct363_ops = {
249 .deinit = ct363_deinit,
250 .suspend = ct363_suspend,
251 .resume = ct363_resume,
252 .report = ct363_report,