3 * Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
4 * Copyright (c) 2007-2010, Synaptics Incorporated
6 * Author: Js HA <js.ha@stericsson.com> for ST-Ericsson
7 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
8 * Copyright 2010 (c) ST-Ericsson AB
11 * This file is licensed under the GPL2 license.
13 *#############################################################################
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 *#############################################################################
28 #include <linux/input.h>
29 #include <linux/slab.h>
30 #include <linux/i2c.h>
31 #include <linux/interrupt.h>
32 #include <linux/regulator/consumer.h>
33 #include <linux/earlysuspend.h>
35 #include <linux/workqueue.h>
36 #include <linux/delay.h>
37 #include <linux/input/mt.h>
39 #include <mach/gpio.h>
40 #include <mach/board.h>
42 #include "synaptics_i2c_rmi4.h"
44 /* TODO: for multiple device support will need a per-device mutex */
45 #define DRIVER_NAME "synaptics_rmi4_i2c"
47 #define MAX_ERROR_REPORT 6
48 #define MAX_TOUCH_MAJOR 15
49 #define MAX_RETRY_COUNT 5
50 #define STD_QUERY_LEN 21
52 #define DATA_BUF_LEN 32
57 #define HAS_PALMDETECT 0x01
58 #define HAS_ROTATE 0x02
59 #define HAS_TAPANDHOLD 0x02
60 #define HAS_DOUBLETAP 0x04
61 #define HAS_EARLYTAP 0x08
62 #define HAS_RELEASE 0x08
63 #define HAS_FLICK 0x10
64 #define HAS_PRESS 0x20
65 #define HAS_PINCH 0x40
67 #define MASK_16BIT 0xFFFF
68 #define MASK_8BIT 0xFF
69 #define MASK_7BIT 0x7F
70 #define MASK_5BIT 0x1F
71 #define MASK_4BIT 0x0F
72 #define MASK_3BIT 0x07
73 #define MASK_2BIT 0x03
74 /* cwz: change 0x08 -> 0x04 for RMI version 4.03 */
76 #define TOUCHPAD_CTRL_INTR 0x8
78 #define TOUCHPAD_CTRL_INTR 0x4 //rmi4_acgzx modified
80 #define PDT_START_SCAN_LOCATION (0x00E9)
81 #define PDT_END_SCAN_LOCATION (0x000A)
82 #define PDT_ENTRY_SIZE (0x0006)
84 #define RMI4_NUMBER_OF_MAX_FINGERS (8)
85 #define SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM (0x11)
86 #define SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM (0x01)
88 #define SYNA_SUPPORT_POINT_MAX (5)
89 #define SYNA_FINGER_MAX (5)
91 #define SYNA_I2C_BUS_IO 1 /* cwz: 1 for i2c io poart. */
92 #define RMI4_MULTI_TOUCH 1 /* cwz: 1 for kernel new report mode */
94 #define RMI4_I2C_SPEED (400*1000) /* cwz: i2c io speed */
96 #define SYNA_WIDTH_DELTA (2) /* rmi4_acgzx: test empirical value */
98 #define SYNA_AIXS_REVISE_FORCE (0)
99 #if SYNA_AIXS_REVISE_FORCE
100 #define SYNA_AIXS_X_DELTA (0x40) //rmi4_acgzx: revise synaptics s7010 demo tp axis x for kindle
101 #define SYNA_WIDTH_DELTA_FOR_X_MAX (6)
103 #define SYNA_AIXS_X_DELTA (0)
104 #define SYNA_WIDTH_DELTA_FOR_X_MAX (0)
107 static struct i2c_client *syna_client;
109 #ifdef CONFIG_HAS_EARLYSUSPEND
110 static void synaptics_rmi4_early_suspend(struct early_suspend *h);
111 static void synaptics_rmi4_late_resume(struct early_suspend *h);
115 #define rmi4_debug(level, ...) \
117 printk(KERN_ERR __VA_ARGS__); \
120 #define rmi4_debug(level, ...)
123 #if (RMI4_MULTI_TOUCH != 0)
124 enum synaptics_rmi4_touch_status {
125 SYNA_TOUCH_ORIGINAL = 0,
132 * struct synaptics_rmi4_fn_desc - contains the function descriptor information
133 * @query_base_addr: base address for query
134 * @cmd_base_addr: base address for command
135 * @ctrl_base_addr: base address for control
136 * @data_base_addr: base address for data
137 * @intr_src_count: count for the interrupt source
138 * @fn_number: function number
140 * This structure is used to gives the function descriptor information
141 * of the particular functionality.
143 struct synaptics_rmi4_fn_desc {
144 unsigned char query_base_addr;
145 unsigned char cmd_base_addr;
146 unsigned char ctrl_base_addr;
147 unsigned char data_base_addr;
148 unsigned char intr_src_count;
149 unsigned char fn_number;
153 * struct synaptics_rmi4_fn - contains the function information
154 * @fn_number: function number
155 * @num_of_data_sources: number of data sources
156 * @num_of_data_points: number of fingers touched
157 * @size_of_data_register_block: data register block size
158 * @index_to_intr_reg: index for interrupt register
159 * @intr_mask: interrupt mask value
160 * @fn_desc: variable for function descriptor structure
161 * @link: linked list for function descriptors
163 * This structure gives information about the number of data sources and
164 * the number of data registers associated with the function.
166 struct synaptics_rmi4_fn {
167 unsigned char fn_number;
168 unsigned char num_of_data_sources;
169 unsigned char num_of_data_points;
170 unsigned char size_of_data_register_block;
171 unsigned char index_to_intr_reg;
172 unsigned char intr_mask;
173 struct synaptics_rmi4_fn_desc fn_desc;
174 struct list_head link;
178 * struct synaptics_rmi4_device_info - contains the rmi4 device information
179 * @version_major: protocol major version number
180 * @version_minor: protocol minor version number
181 * @manufacturer_id: manufacturer identification byte
182 * @product_props: product properties information
183 * @product_info: product info array
184 * @date_code: device manufacture date
185 * @tester_id: tester id array
186 * @serial_number: serial number for that device
187 * @product_id_string: product id for the device
188 * @support_fn_list: linked list for device information
190 * This structure gives information about the number of data sources and
191 * the number of data registers associated with the function.
193 struct synaptics_rmi4_device_info {
194 unsigned int version_major;
195 unsigned int version_minor;
196 unsigned char manufacturer_id;
197 unsigned char product_props;
198 unsigned char product_info[2];
199 unsigned char date_code[3];
200 unsigned short tester_id;
201 unsigned short serial_number;
202 unsigned char product_id_string[11];
203 struct list_head support_fn_list;
207 * struct synaptics_rmi4_data - contains the rmi4 device data
208 * @rmi4_mod_info: structure variable for rmi4 device info
209 * @input_dev: pointer for input device
210 * @i2c_client: pointer for i2c client
211 * @board: constant pointer for touch platform data
212 * @fn_list_mutex: mutex for function list
213 * @rmi4_page_mutex: mutex for rmi4 page
214 * @current_page: variable for integer
215 * @number_of_interrupt_register: interrupt registers count
216 * @fn01_ctrl_base_addr: control base address for fn01
217 * @fn01_query_base_addr: query base address for fn01
218 * @fn01_data_base_addr: data base address for fn01
219 * @sensor_max_x: sensor maximum x value
220 * @sensor_max_y: sensor maximum y value
221 * @regulator: pointer to the regulator structure
222 * @wait: wait queue structure variable
223 * @touch_stopped: flag to stop the thread function
225 * This structure gives the device data information.
227 struct synaptics_rmi4_data {
228 struct synaptics_rmi4_device_info rmi4_mod_info;
229 struct input_dev *input_dev;
230 struct i2c_client *i2c_client;
231 const struct synaptics_rmi4_platform_data *board;
232 struct mutex fn_list_mutex;
233 struct mutex rmi4_page_mutex;
235 unsigned int number_of_interrupt_register;
236 unsigned short fn01_ctrl_base_addr;
237 unsigned short fn01_query_base_addr;
238 unsigned short fn01_data_base_addr;
241 struct regulator *regulator;
242 wait_queue_head_t wait;
245 struct mutex rmi4_wq_mutex;
246 struct work_struct work;
247 struct workqueue_struct *rmi4_wq;
248 struct early_suspend m_early_suspend;
251 #if (SYNA_I2C_BUS_IO != 0)
252 static int synaptics_rmi4_read_block(struct i2c_client *client,
257 struct i2c_adapter *adapter = client->adapter;
258 struct i2c_msg msg[2];
262 le_addr = cpu_to_le16(addr);
264 msg[0].scl_rate = RMI4_I2C_SPEED;
265 msg[0].addr = client->addr;
268 msg[0].buf = (u8*) &le_addr;
270 msg[1].scl_rate = RMI4_I2C_SPEED;
271 msg[1].addr = client->addr;
272 msg[1].flags = I2C_M_RD;
274 msg[1].buf = (u8*) value;
276 ret = i2c_transfer(adapter, msg, 2);
278 return (ret == 2)? length : ret;
283 * synaptics_rmi4_set_page() - sets the page
284 * @pdata: pointer to synaptics_rmi4_data structure
285 * @address: set the address of the page
287 * This function is used to set the page and returns integer.
289 static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *pdata,
290 unsigned int address)
292 unsigned char txbuf[PAGE_LEN];
295 struct i2c_client *i2c = pdata->i2c_client;
297 page = ((address >> 8) & MASK_8BIT);
298 if (page != pdata->current_page) {
299 txbuf[0] = MASK_8BIT;
301 retval = i2c_master_send(i2c, txbuf, PAGE_LEN);
302 if (retval != PAGE_LEN)
303 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
305 pdata->current_page = page;
311 * synaptics_rmi4_i2c_block_read() - read the block of data
312 * @pdata: pointer to synaptics_rmi4_data structure
313 * @address: read the block of data from this offset
314 * @valp: pointer to a buffer containing the data to be read
315 * @size: number of bytes to read
317 * This function is to read the block of data and returns integer.
319 static int synaptics_rmi4_i2c_block_read(struct synaptics_rmi4_data *pdata,
320 unsigned short address,
321 unsigned char *valp, int size)
326 struct i2c_client *i2c = pdata->i2c_client;
328 mutex_lock(&(pdata->rmi4_page_mutex));
329 retval = synaptics_rmi4_set_page(pdata, address);
330 if (retval != PAGE_LEN)
332 index = address & MASK_8BIT;
334 #if (SYNA_I2C_BUS_IO != 0)
335 retval = synaptics_rmi4_read_block(i2c, index, size, valp);
337 retval = i2c_smbus_read_i2c_block_data(i2c, index, size, valp);
339 if (retval != size) {
340 if (++retry_count == MAX_RETRY_COUNT)
342 "%s:address 0x%04x size %d failed:%d\n",
343 __func__, address, size, retval);
345 synaptics_rmi4_set_page(pdata, address);
350 mutex_unlock(&(pdata->rmi4_page_mutex));
355 * synaptics_rmi4_i2c_byte_write() - write the single byte data
356 * @pdata: pointer to synaptics_rmi4_data structure
357 * @address: write the block of data from this offset
358 * @data: data to be write
360 * This function is to write the single byte data and returns integer.
362 static int synaptics_rmi4_i2c_byte_write(struct synaptics_rmi4_data *pdata,
363 unsigned short address,
366 unsigned char txbuf[2];
368 struct i2c_client *i2c = pdata->i2c_client;
370 /* Can't have anyone else changing the page behind our backs */
371 mutex_lock(&(pdata->rmi4_page_mutex));
373 retval = synaptics_rmi4_set_page(pdata, address);
374 if (retval != PAGE_LEN)
376 txbuf[0] = address & MASK_8BIT;
378 retval = i2c_master_send(pdata->i2c_client, txbuf, 2);
379 /* Add in retry on writes only in certain error return values */
381 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
386 mutex_unlock(&(pdata->rmi4_page_mutex));
390 static int synaptics_rmi4_i2c_block_write(struct synaptics_rmi4_data *pdata,
391 unsigned short address, unsigned char *data, unsigned char size)
393 unsigned char txbuf[8];
395 struct i2c_client *i2c = pdata->i2c_client;
397 /* Can't have anyone else changing the page behind our backs */
398 mutex_lock(&(pdata->rmi4_page_mutex));
400 retval = synaptics_rmi4_set_page(pdata, address);
401 if (retval != PAGE_LEN)
403 txbuf[0] = address & MASK_8BIT;
404 memcpy(txbuf + 1, data, size);
405 retval = i2c_master_send(pdata->i2c_client, txbuf, size + 1);
406 /* Add in retry on writes only in certain error return values */
408 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
413 mutex_unlock(&(pdata->rmi4_page_mutex));
419 * synpatics_rmi4_touchpad_report() - reports for the rmi4 touchpad device
420 * @pdata: pointer to synaptics_rmi4_data structure
421 * @rfi: pointer to synaptics_rmi4_fn structure
423 * This function calls to reports for the rmi4 touchpad device
425 static int synpatics_rmi4_touchpad_report(struct synaptics_rmi4_data *pdata,
426 struct synaptics_rmi4_fn *rfi)
428 /* number of touch points - fingers down in this case */
431 int fingers_supported;
432 int finger_registers;
437 unsigned short data_base_addr;
438 unsigned short data_offset;
439 unsigned char data_reg_blk_size;
440 unsigned char values[2];
441 unsigned char data[DATA_LEN];
442 int x[RMI4_NUMBER_OF_MAX_FINGERS];
443 int y[RMI4_NUMBER_OF_MAX_FINGERS];
444 int wx[RMI4_NUMBER_OF_MAX_FINGERS];
445 int wy[RMI4_NUMBER_OF_MAX_FINGERS];
446 struct i2c_client *client = pdata->i2c_client;
448 #if (RMI4_MULTI_TOUCH != 0)
449 volatile enum synaptics_rmi4_touch_status cur_touch_status[SYNA_SUPPORT_POINT_MAX];
450 static volatile enum synaptics_rmi4_touch_status pre_touch_status[SYNA_SUPPORT_POINT_MAX];
453 /* get 2D sensor finger data */
455 * First get the finger status field - the size of the finger status
456 * field is determined by the number of finger supporte - 2 bits per
457 * finger, so the number of registers to read is:
458 * registerCount = ceil(numberOfFingers/4).
459 * Read the required number of registers and check each 2 bit field to
460 * determine if a finger is down:
461 * 00 = finger not present,
462 * 01 = finger present and data accurate,
463 * 10 = finger present but data may not be accurate,
464 * 11 = reserved for product use.
466 fingers_supported = rfi->num_of_data_points;
467 finger_registers = (fingers_supported + 3)/4;
468 data_base_addr = rfi->fn_desc.data_base_addr;
469 retval = synaptics_rmi4_i2c_block_read(pdata, data_base_addr, values,
471 if (retval != finger_registers) {
472 dev_err(&client->dev, "%s:read status registers failed\n",
477 * For each finger present, read the proper number of registers
478 * to get absolute data.
480 data_reg_blk_size = rfi->size_of_data_register_block;
482 for (finger = 0; finger < fingers_supported; finger++) {
483 //mutex_lock(&pdata->rmi4_wq_mutex);
484 cur_touch_status[finger] = SYNA_TOUCH_ORIGINAL;
485 //mutex_unlock(&pdata->rmi4_wq_mutex);
488 for (finger = 0; finger < fingers_supported; finger++) {
489 /* determine which data byte the finger status is in */
491 /* bit shift to get finger's status */
492 finger_shift = (finger % 4) * 2;
493 finger_status = (values[reg] >> finger_shift) & 3;
495 * if finger status indicates a finger is present then
496 * read the finger data and report it
498 if (finger_status == 1 || finger_status == 2) {
499 rmi4_debug(DEBUG_TRACE, "---> finger[%d] press ??\n", finger);
501 //mutex_lock(&pdata->rmi4_wq_mutex);
502 cur_touch_status[finger] = SYNA_TOUCH_PRESS;
503 //mutex_unlock(&pdata->rmi4_wq_mutex);
505 /* Read the finger data */
506 data_offset = data_base_addr +
507 ((finger * data_reg_blk_size) +
509 retval = synaptics_rmi4_i2c_block_read(pdata,
510 data_offset, data, data_reg_blk_size);
511 if (retval != data_reg_blk_size) {
512 printk(KERN_ERR "%s:read data failed\n", __func__);
513 //mutex_lock(&pdata->rmi4_wq_mutex);
514 cur_touch_status[finger] = SYNA_TOUCH_ORIGINAL;
515 //mutex_unlock(&pdata->rmi4_wq_mutex);
519 (data[0] << 4) | (data[2] & MASK_4BIT);
522 ((data[2] >> 4) & MASK_4BIT);
524 (data[3] >> 4) & MASK_4BIT;
526 (data[3] & MASK_4BIT);
529 if (x[finger] >= pdata->sensor_max_x)
530 rmi4_debug(DEBUG_TRACE, "x[%d] = 0x%x, y[%d] = 0x%x\n"
531 "wx[%d] = 0x%x, wy[%d] = 0x%x\n"
532 "sensor_max_x = 0x%x, sensor_max_y = 0x%x\n",
533 finger, x[finger], finger, y[finger],
534 finger, wx[finger], finger, wy[finger],
535 pdata->sensor_max_x, pdata->sensor_max_y
539 #if SYNA_AIXS_REVISE_FORCE
543 axis_bak = x[finger];
545 /*rmi4_acgzx: because these s7010 tp is assembling for a short time, sensor and lines isn't matching.
546 * force revise axis x and special handing.
548 x[finger] -= SYNA_AIXS_X_DELTA;
549 x[finger] = (x[finger] < 0) ? 0 : x[finger];
551 //rmi4_acgzx: special handing for sensor_max_x.
552 if (axis_bak >= pdata->sensor_max_x && wx[finger] <= SYNA_WIDTH_DELTA_FOR_X_MAX)
553 x[finger] += SYNA_AIXS_X_DELTA;
557 /* rmi4_acgzx: do not support touch key, ignore outside touch */
558 if (x[finger] >= (pdata->sensor_max_x - SYNA_AIXS_X_DELTA) && wx[finger] <= SYNA_WIDTH_DELTA) {
559 //mutex_lock(&pdata->rmi4_wq_mutex);
560 cur_touch_status[finger] = SYNA_TOUCH_RELEASE;
561 //mutex_unlock(&pdata->rmi4_wq_mutex);
562 rmi4_debug(DEBUG_TRACE, "touch point beyond lcd display area.\n");
565 if (pdata->board->x_flip)
566 x[finger] = pdata->sensor_max_x - x[finger];
567 if (pdata->board->y_flip)
568 y[finger] = pdata->sensor_max_y - y[finger];
571 /* rmi4_acgzx: touch press, touch_count increase */
572 if (SYNA_TOUCH_PRESS == cur_touch_status[finger])
576 //mutex_lock(&pdata->rmi4_wq_mutex);
577 cur_touch_status[finger] = SYNA_TOUCH_RELEASE;
578 //mutex_unlock(&pdata->rmi4_wq_mutex);
582 for (finger = 0; finger < fingers_supported; finger++) {
583 if (SYNA_TOUCH_PRESS == cur_touch_status[finger]) {
584 rmi4_debug(DEBUG_TRACE, "====> finger[%d] press!\n", finger);
585 /* number of active touch points */
586 input_mt_slot(pdata->input_dev, finger);
587 input_mt_report_slot_state(pdata->input_dev, MT_TOOL_FINGER, true);
588 input_report_abs(pdata->input_dev, ABS_MT_TRACKING_ID, finger);
589 input_report_abs(pdata->input_dev, ABS_MT_TOUCH_MAJOR, MAX_TOUCH_MAJOR);
590 input_report_abs(pdata->input_dev, ABS_MT_POSITION_X, x[finger]);
591 input_report_abs(pdata->input_dev, ABS_MT_POSITION_Y, y[finger]);
592 //mutex_lock(&pdata->rmi4_wq_mutex);
593 pre_touch_status[finger] = cur_touch_status[finger];
594 //mutex_unlock(&pdata->rmi4_wq_mutex);
598 for (finger = 0; finger < fingers_supported; finger++) {
599 if (SYNA_TOUCH_RELEASE == cur_touch_status[finger] &&
600 SYNA_TOUCH_PRESS == pre_touch_status[finger]) {
601 rmi4_debug(DEBUG_TRACE, "====> finger[%d] release!\n", finger);
602 /* number of active touch points */
603 input_mt_slot(pdata->input_dev, finger);
604 input_mt_report_slot_state(pdata->input_dev, MT_TOOL_FINGER, false);
605 input_report_abs(pdata->input_dev, ABS_MT_TRACKING_ID, -1);
606 //mutex_lock(&pdata->rmi4_wq_mutex);
607 pre_touch_status[finger] = cur_touch_status[finger];
608 //mutex_unlock(&pdata->rmi4_wq_mutex);
612 /* sync after groups of events */
613 input_sync(pdata->input_dev);
614 /* return the number of touch points */
619 * synaptics_rmi4_report_device() - reports the rmi4 device
620 * @pdata: pointer to synaptics_rmi4_data structure
621 * @rfi: pointer to synaptics_rmi4_fn
623 * This function is used to call the report function of the rmi4 device.
625 static int synaptics_rmi4_report_device(struct synaptics_rmi4_data *pdata,
626 struct synaptics_rmi4_fn *rfi)
629 struct i2c_client *client = pdata->i2c_client;
630 static int num_error_reports;
631 if (rfi->fn_number != SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
632 rmi4_debug(DEBUG_TRACE, "====> %s fn_number no equal enter!\n", __func__);
634 if (num_error_reports < MAX_ERROR_REPORT)
635 dev_err(&client->dev, "%s:report not supported\n",
638 touch = synpatics_rmi4_touchpad_report(pdata, rfi);
642 * synaptics_rmi4_sensor_report() - reports to input subsystem
643 * @pdata: pointer to synaptics_rmi4_data structure
645 * This function is used to reads in all data sources and reports
646 * them to the input subsystem.
648 static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *pdata)
650 unsigned char intr_status[4];
651 /* number of touch points - fingers or buttons */
654 struct synaptics_rmi4_fn *rfi;
655 struct synaptics_rmi4_device_info *rmi;
656 struct i2c_client *client = pdata->i2c_client;
659 * Get the interrupt status from the function $01
660 * control register+1 to find which source(s) were interrupting
661 * so we can read the data from the source(s) (2D sensor, buttons..)
663 retval = synaptics_rmi4_i2c_block_read(pdata,
664 pdata->fn01_data_base_addr + 1,
666 pdata->number_of_interrupt_register);
667 if (retval != pdata->number_of_interrupt_register) {
668 dev_err(&client->dev,
669 "could not read interrupt status registers\n");
673 * check each function that has data sources and if the interrupt for
674 * that triggered then call that RMI4 functions report() function to
675 * gather data and report it to the input subsystem
677 rmi = &(pdata->rmi4_mod_info);
678 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
679 if (rfi->num_of_data_sources) {
680 if (intr_status[rfi->index_to_intr_reg] &
682 touch = synaptics_rmi4_report_device(pdata,
686 /* return the number of touch points */
690 static void synaptics_rmi4_work_func(struct work_struct *work)
692 struct synaptics_rmi4_data *rmi4_data = container_of(work, struct synaptics_rmi4_data, work);
693 struct i2c_client *client = rmi4_data->i2c_client;
694 unsigned char intr_status;
696 /* rmi4_acgzx note: important!! disable tp interrupt avoid lost attn */
697 synaptics_rmi4_i2c_byte_write(rmi4_data, rmi4_data->fn01_data_base_addr + 1, 0x00);
699 synaptics_rmi4_sensor_report(rmi4_data);
701 enable_irq(client->irq);
703 /* rmi4_acgzx note: important!! enable tp interrupt again*/
704 synaptics_rmi4_i2c_byte_write(rmi4_data, rmi4_data->fn01_data_base_addr + 1, 0x0f);
706 /* rmi4_acgzx note: may be cause lose attn, gpio irq is low, that is small probability in rk30 platform.
707 * need read int status register again just in case.
709 if (0 == gpio_get_value(client->irq)) {
710 rmi4_debug(DEBUG_TRACE, "----> %s: irq change low value enter! <----\n", __func__);
711 synaptics_rmi4_i2c_block_read(rmi4_data,
712 rmi4_data->fn01_data_base_addr + 1,
714 rmi4_data->number_of_interrupt_register);
718 //rmi4_debug(DEBUG_TRACE, "%s: exit!\n", __func__); //rmi4_acgzx
722 * synaptics_rmi4_irq() - thread function for rmi4 attention line
724 * @data: void pointer
726 * This function is interrupt thread function. It just notifies the
727 * application layer that attention is required.
729 static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
731 struct synaptics_rmi4_data *pdata = data;
733 //rmi4_debug(DEBUG_TRACE, "%s: enter!\n", __func__); //rmi4_acgzx
735 disable_irq_nosync(irq);
736 queue_work(pdata->rmi4_wq, &pdata->work);
742 * synpatics_rmi4_touchpad_detect() - detects the rmi4 touchpad device
743 * @pdata: pointer to synaptics_rmi4_data structure
744 * @rfi: pointer to synaptics_rmi4_fn structure
745 * @fd: pointer to synaptics_rmi4_fn_desc structure
746 * @interruptcount: count the number of interrupts
748 * This function calls to detects the rmi4 touchpad device
750 static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data *pdata,
751 struct synaptics_rmi4_fn *rfi,
752 struct synaptics_rmi4_fn_desc *fd,
753 unsigned int interruptcount)
755 unsigned char queries[QUERY_LEN];
756 unsigned short intr_offset;
757 unsigned char abs_data_size;
758 unsigned char abs_data_blk_size;
759 unsigned char egr_0, egr_1;
760 unsigned int all_data_blk_size;
761 int has_pinch, has_flick, has_tap;
762 int has_tapandhold, has_doubletap;
763 int has_earlytap, has_press;
764 int has_palmdetect, has_rotate;
768 struct i2c_client *client = pdata->i2c_client;
770 rfi->fn_desc.query_base_addr = fd->query_base_addr;
771 rfi->fn_desc.data_base_addr = fd->data_base_addr;
772 rfi->fn_desc.intr_src_count = fd->intr_src_count;
773 rfi->fn_desc.fn_number = fd->fn_number;
774 rfi->fn_number = fd->fn_number;
775 rfi->num_of_data_sources = fd->intr_src_count;
776 rfi->fn_desc.ctrl_base_addr = fd->ctrl_base_addr;
777 rfi->fn_desc.cmd_base_addr = fd->cmd_base_addr;
780 * need to get number of fingers supported, data size, etc.
781 * to be used when getting data since the number of registers to
782 * read depends on the number of fingers supported and data size.
784 retval = synaptics_rmi4_i2c_block_read(pdata, fd->query_base_addr,
787 if (retval != sizeof(queries)) {
788 dev_err(&client->dev, "%s:read function query registers\n",
793 * 2D data sources have only 3 bits for the number of fingers
794 * supported - so the encoding is a bit weird.
796 if ((queries[1] & MASK_3BIT) <= 4)
797 /* add 1 since zero based */
798 rfi->num_of_data_points = (queries[1] & MASK_3BIT) + 1;
801 * a value of 5 is up to 10 fingers - 6 and 7 are reserved
802 * (shouldn't get these i int retval;n a normal 2D source).
804 if ((queries[1] & MASK_3BIT) == 5)
805 rfi->num_of_data_points = 10;
807 /* Need to get interrupt info for handling interrupts */
808 rfi->index_to_intr_reg = (interruptcount + 7)/8;
809 if (rfi->index_to_intr_reg != 0)
810 rfi->index_to_intr_reg -= 1;
812 * loop through interrupts for each source in fn $11
813 * and or in a bit to the interrupt mask for each.
815 intr_offset = interruptcount % 8;
817 for (i = intr_offset;
818 i < ((fd->intr_src_count & MASK_3BIT) + intr_offset); i++)
819 rfi->intr_mask |= 1 << i;
821 /* Size of just the absolute data for one finger */
822 abs_data_size = queries[5] & MASK_2BIT;
823 /* One each for X and Y, one for LSB for X & Y, one for W, one for Z */
824 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
825 rfi->size_of_data_register_block = abs_data_blk_size;
828 * need to determine the size of data to read - this depends on
829 * conditions such as whether Relative data is reported and if Gesture
836 * Get info about what EGR data is supported, whether it has
837 * Relative data supported, etc.
839 has_pinch = egr_0 & HAS_PINCH;
840 has_flick = egr_0 & HAS_FLICK;
841 has_tap = egr_0 & HAS_TAP;
842 has_earlytap = egr_0 & HAS_EARLYTAP;
843 has_press = egr_0 & HAS_PRESS;
844 has_rotate = egr_1 & HAS_ROTATE;
845 has_rel = queries[1] & HAS_RELEASE;
846 has_tapandhold = egr_0 & HAS_TAPANDHOLD;
847 has_doubletap = egr_0 & HAS_DOUBLETAP;
848 has_palmdetect = egr_1 & HAS_PALMDETECT;
851 * Size of all data including finger status, absolute data for each
852 * finger, relative data and EGR data
855 /* finger status, four fingers per register */
856 ((rfi->num_of_data_points + 3) / 4) +
857 /* absolute data, per finger times number of fingers */
858 (abs_data_blk_size * rfi->num_of_data_points) +
860 * two relative registers (if relative is being reported)
864 * F11_2D_data8 is only present if the egr_0
865 * register is non-zero.
869 * F11_2D_data9 is only present if either egr_0 or
870 * egr_1 registers are non-zero.
874 * F11_2D_data10 is only present if EGR_PINCH or EGR_FLICK of
875 * egr_0 reports as 1.
877 !!(has_pinch | has_flick) +
879 * F11_2D_data11 and F11_2D_data12 are only present if
880 * EGR_FLICK of egr_0 reports as 1.
887 * synpatics_rmi4_touchpad_config() - confiures the rmi4 touchpad device
888 * @pdata: pointer to synaptics_rmi4_data structure
889 * @rfi: pointer to synaptics_rmi4_fn structure
891 * This function calls to confiures the rmi4 touchpad device
893 int synpatics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
894 struct synaptics_rmi4_fn *rfi)
897 * For the data source - print info and do any
898 * source specific configuration.
900 unsigned char data[BUF_LEN];
902 struct i2c_client *client = pdata->i2c_client;
904 /* Get and print some info about the data source... */
905 /* To Query 2D devices we need to read from the address obtained
906 * from the function descriptor stored in the RMI function info.
908 retval = synaptics_rmi4_i2c_block_read(pdata,
909 rfi->fn_desc.query_base_addr,
911 if (retval != QUERY_LEN)
912 dev_err(&client->dev, "%s:read query registers failed\n",
916 //hhb@rock-chips.com add virtual_keys function
917 if (pdata->board->virtual_keys == true) {
922 pdata->sensor_max_x = pdata->board->lcd_width;
923 pdata->sensor_max_y = pdata->board->lcd_height;
925 w = pdata->board->lcd_width + pdata->board->w_delta;
926 h = pdata->board->lcd_height + pdata->board->h_delta;
929 buf[0] = w & MASK_8BIT;
930 buf[1] = (w >> 8) & MASK_4BIT;
931 synaptics_rmi4_i2c_block_write(pdata, rfi->fn_desc.ctrl_base_addr + 6, buf, 2);
932 buf[0] = h & MASK_8BIT;
933 buf[1] = (h >> 8) & MASK_4BIT;
934 synaptics_rmi4_i2c_block_write(pdata, rfi->fn_desc.ctrl_base_addr + 8, buf, 2);
936 synaptics_rmi4_i2c_byte_write(pdata, rfi->fn_desc.ctrl_base_addr + 6, w & MASK_8BIT);
937 synaptics_rmi4_i2c_byte_write(pdata, rfi->fn_desc.ctrl_base_addr + 7, (w >> 8) & MASK_4BIT);
939 synaptics_rmi4_i2c_byte_write(pdata, rfi->fn_desc.ctrl_base_addr + 8, h & MASK_8BIT);
940 synaptics_rmi4_i2c_byte_write(pdata, rfi->fn_desc.ctrl_base_addr + 9, (h >> 8) & MASK_4BIT);
943 retval = synaptics_rmi4_i2c_block_read(pdata,
944 rfi->fn_desc.ctrl_base_addr,
946 if (retval != DATA_BUF_LEN) {
947 dev_err(&client->dev,
948 "%s:read control registers failed\n",
953 w = ((data[6] & MASK_8BIT) << 0) |
954 ((data[7] & MASK_4BIT) << 8);
955 h = ((data[8] & MASK_8BIT) << 0) |
956 ((data[9] & MASK_4BIT) << 8);
958 if(pdata->board->lcd_width != w || pdata->board->lcd_height != h){
959 printk("set tp x:%d, y:%d, but read x:%d, y:%d\n", pdata->board->lcd_width, pdata->board->lcd_height, w, h);
964 retval = synaptics_rmi4_i2c_block_read(pdata,
965 rfi->fn_desc.ctrl_base_addr,
967 if (retval != DATA_BUF_LEN) {
968 dev_err(&client->dev,
969 "%s:read control registers failed\n",
974 /* Store these for use later*/
976 pdata->sensor_max_x = ((data[6] & MASK_8BIT) << 0) |
977 ((data[7] & MASK_4BIT) << 8);
978 pdata->sensor_max_y = ((data[8] & MASK_8BIT) << 0) |
979 ((data[9] & MASK_4BIT) << 8);
982 rmi4_debug(DEBUG_TRACE, "sensor_max_x = 0x%x, sensor_max_y = 0x%x.\n",
983 pdata->sensor_max_x, pdata->sensor_max_y);
989 * synaptics_rmi4_i2c_query_device() - query the rmi4 device
990 * @pdata: pointer to synaptics_rmi4_data structure
992 * This function is used to query the rmi4 device.
994 static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
998 unsigned char std_queries[STD_QUERY_LEN];
999 unsigned char intr_count = 0;
1000 int data_sources = 0;
1001 unsigned int ctrl_offset;
1002 struct synaptics_rmi4_fn *rfi;
1003 struct synaptics_rmi4_fn_desc rmi_fd;
1004 struct synaptics_rmi4_device_info *rmi;
1005 struct i2c_client *client = pdata->i2c_client;
1008 * init the physical drivers RMI module
1009 * info list of functions
1011 INIT_LIST_HEAD(&pdata->rmi4_mod_info.support_fn_list);
1014 * Read the Page Descriptor Table to determine what functions
1017 for (i = PDT_START_SCAN_LOCATION; i > PDT_END_SCAN_LOCATION;
1018 i -= PDT_ENTRY_SIZE) {
1019 retval = synaptics_rmi4_i2c_block_read(pdata, i,
1020 (unsigned char *)&rmi_fd,
1022 if (retval != sizeof(rmi_fd)) {
1023 /* failed to read next PDT entry */
1024 dev_err(&client->dev, "%s: read error\n", __func__);
1028 rmi4_debug(DEBUG_TRACE, "----> query_base_addr = 0x%x\n"
1029 "cmd_base_addr = 0x%x\n"
1030 "ctrl_base_addr = 0x%x\n"
1031 "data_base_addr = 0x%x\n"
1032 "intr_src_count = 0x%x\n"
1033 "fn_number = 0x%x\n",
1034 rmi_fd.query_base_addr,
1035 rmi_fd.cmd_base_addr,
1036 rmi_fd.ctrl_base_addr,
1037 rmi_fd.data_base_addr,
1038 rmi_fd.intr_src_count,
1043 if (rmi_fd.fn_number) {
1044 switch (rmi_fd.fn_number & MASK_8BIT) {
1045 case SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM:
1046 pdata->fn01_query_base_addr =
1047 rmi_fd.query_base_addr;
1048 pdata->fn01_ctrl_base_addr =
1049 rmi_fd.ctrl_base_addr;
1050 pdata->fn01_data_base_addr =
1051 rmi_fd.data_base_addr;
1053 rmi4_debug(DEBUG_TRACE, "----> fn01_query_base_addr = 0x%x\n,"
1054 "fn01_ctrl_base_addr = 0x%x\n,"
1055 "fn01_data_base_addr = 0x%x\n,",
1056 pdata->fn01_query_base_addr,
1057 pdata->fn01_ctrl_base_addr,
1058 pdata->fn01_data_base_addr
1061 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM:
1062 if (rmi_fd.intr_src_count) {
1063 rfi = kmalloc(sizeof(*rfi),
1066 dev_err(&client->dev,
1067 "%s:kmalloc failed\n",
1071 retval = synpatics_rmi4_touchpad_detect
1082 /* interrupt count for next iteration */
1083 intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
1085 * We only want to add functions to the list
1086 * that have data associated with them.
1088 if (rfi && rmi_fd.intr_src_count) {
1089 /* link this function info to the RMI module */
1090 mutex_lock(&(pdata->fn_list_mutex));
1091 list_add_tail(&rfi->link,
1092 &pdata->rmi4_mod_info.support_fn_list);
1093 mutex_unlock(&(pdata->fn_list_mutex));
1097 * A zero in the function number
1098 * signals the end of the PDT
1100 dev_dbg(&client->dev,
1101 "%s:end of PDT\n", __func__);
1106 * calculate the interrupt register count - used in the
1107 * ISR to read the correct number of interrupt registers
1109 pdata->number_of_interrupt_register = (intr_count + 7) / 8;
1111 * Function $01 will be used to query the product properties,
1112 * and product ID so we had to read the PDT above first to get
1113 * the Fn $01 query address and prior to filling in the product
1114 * info. NOTE: Even an unflashed device will still have FN $01.
1117 /* Load up the standard queries and get the RMI4 module info */
1118 retval = synaptics_rmi4_i2c_block_read(pdata,
1119 pdata->fn01_query_base_addr,
1121 sizeof(std_queries));
1122 if (retval != sizeof(std_queries)) {
1123 dev_err(&client->dev, "%s:Failed reading queries\n",
1128 /* Currently supported RMI version is 4.0 */
1129 pdata->rmi4_mod_info.version_major = 4;
1130 pdata->rmi4_mod_info.version_minor = 0;
1132 * get manufacturer id, product_props, product info,
1133 * date code, tester id, serial num and product id (name)
1135 pdata->rmi4_mod_info.manufacturer_id = std_queries[0];
1136 pdata->rmi4_mod_info.product_props = std_queries[1];
1137 pdata->rmi4_mod_info.product_info[0] = std_queries[2];
1138 pdata->rmi4_mod_info.product_info[1] = std_queries[3];
1139 /* year - 2001-2032 */
1140 pdata->rmi4_mod_info.date_code[0] = std_queries[4] & MASK_5BIT;
1142 pdata->rmi4_mod_info.date_code[1] = std_queries[5] & MASK_4BIT;
1144 pdata->rmi4_mod_info.date_code[2] = std_queries[6] & MASK_5BIT;
1145 pdata->rmi4_mod_info.tester_id = ((std_queries[7] & MASK_7BIT) << 8) |
1146 (std_queries[8] & MASK_7BIT);
1147 pdata->rmi4_mod_info.serial_number =
1148 ((std_queries[9] & MASK_7BIT) << 8) |
1149 (std_queries[10] & MASK_7BIT);
1150 memcpy(pdata->rmi4_mod_info.product_id_string, &std_queries[11], 10);
1152 rmi4_debug(DEBUG_TRACE, "version_major = 0x%x, version_minor = 0x%x.\n"
1153 "manufacturer_id = 0x%x, product_props = 0x%x.\n"
1154 "product_info[1] = 0x%x, product_info[0] = 0x%x.\n"
1155 "date_code[2] = 0x%x, date_code[1] = 0x%x, date_code[0] = 0x%x.\n"
1156 "tester_id = 0x%x, serial_number = 0x%x.\n"
1157 "product_id_string = %s.\n",
1158 pdata->rmi4_mod_info.version_major, pdata->rmi4_mod_info.version_minor,
1159 pdata->rmi4_mod_info.manufacturer_id, pdata->rmi4_mod_info.product_props,
1160 pdata->rmi4_mod_info.product_info[1], pdata->rmi4_mod_info.product_info[0],
1161 pdata->rmi4_mod_info.date_code[2], pdata->rmi4_mod_info.date_code[1], pdata->rmi4_mod_info.date_code[0],
1162 pdata->rmi4_mod_info.tester_id, pdata->rmi4_mod_info.serial_number,
1163 pdata->rmi4_mod_info.product_id_string
1166 /* Check if this is a Synaptics device - report if not. */
1167 if (pdata->rmi4_mod_info.manufacturer_id != 1)
1168 dev_err(&client->dev, "%s: non-Synaptics mfg id:%d\n",
1169 __func__, pdata->rmi4_mod_info.manufacturer_id);
1171 list_for_each_entry(rfi, &pdata->rmi4_mod_info.support_fn_list, link)
1172 data_sources += rfi->num_of_data_sources;
1174 rmi = &(pdata->rmi4_mod_info);
1175 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
1176 if (rfi->num_of_data_sources) {
1177 if (rfi->fn_number ==
1178 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
1179 retval = synpatics_rmi4_touchpad_config
1184 dev_err(&client->dev,
1185 "%s:fn_number not supported\n",
1188 * Turn on interrupts for this
1189 * function's data sources.
1191 ctrl_offset = pdata->fn01_ctrl_base_addr + 1 +
1192 rfi->index_to_intr_reg;
1194 rmi4_debug(DEBUG_TRACE, "----> fn01_ctrl_base_addr = 0x%x, intr_mask = 0x%x\n"
1195 "index_to_intr_reg = 0x%x, ctrl_offset = 0x%x.\n",
1196 pdata->fn01_ctrl_base_addr, rfi->intr_mask,
1197 rfi->index_to_intr_reg, ctrl_offset
1200 retval = synaptics_rmi4_i2c_byte_write(pdata,
1213 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
1214 * @i2c: i2c client structure pointer
1215 * @id:i2c device id pointer
1217 * This function will allocate and initialize the instance
1218 * data and request the irq and set the instance data as the clients
1219 * platform data then register the physical driver which will do a scan of
1220 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
1221 * have data sources associated with them.
1223 static int __devinit synaptics_rmi4_probe
1224 (struct i2c_client *client, const struct i2c_device_id *dev_id)
1227 unsigned char intr_status[4];
1228 struct synaptics_rmi4_data *rmi4_data;
1229 struct synaptics_rmi4_platform_data *platformdata =
1230 client->dev.platform_data;
1232 #if (SYNA_I2C_BUS_IO != 0)
1233 if (!i2c_check_functionality(client->adapter,
1235 dev_err(&client->dev, "i2c smbus byte data not supported\n");
1239 if (!i2c_check_functionality(client->adapter,
1240 I2C_FUNC_SMBUS_BYTE_DATA)) {
1241 dev_err(&client->dev, "i2c smbus byte data not supported\n");
1246 if (!platformdata) {
1247 dev_err(&client->dev, "%s: no platform data\n", __func__);
1251 //if (platformdata->init_hw)
1252 // platformdata->init_hw();
1254 platformdata->irq_number = gpio_to_irq(client->irq);
1255 //platformdata->x_flip = false; // hhb
1256 //platformdata->y_flip = false;
1257 //platformdata->irq_type = IRQF_TRIGGER_FALLING;
1258 //platformdata->regulator_en = false;
1260 rmi4_debug(DEBUG_TRACE, "irq_number = %d, client->irq = %d\n",
1261 platformdata->irq_number, client->irq);
1263 /* Allocate and initialize the instance data for this client */
1264 rmi4_data = kzalloc(sizeof(struct synaptics_rmi4_data) * 2,
1267 dev_err(&client->dev, "%s: no memory allocated\n", __func__);
1271 rmi4_data->input_dev = input_allocate_device();
1272 if (rmi4_data->input_dev == NULL) {
1273 dev_err(&client->dev, "%s:input device alloc failed\n",
1279 if (platformdata->regulator_en) {
1280 rmi4_data->regulator = regulator_get(&client->dev, "vdd");
1281 if (IS_ERR(rmi4_data->regulator)) {
1282 dev_err(&client->dev, "%s:get regulator failed\n",
1284 retval = PTR_ERR(rmi4_data->regulator);
1287 regulator_enable(rmi4_data->regulator);
1290 init_waitqueue_head(&rmi4_data->wait);
1292 * Copy i2c_client pointer into RTID's i2c_client pointer for
1293 * later use in rmi4_read, rmi4_write, etc.
1295 rmi4_data->i2c_client = client;
1296 /* So we set the page correctly the first time */
1297 rmi4_data->current_page = MASK_16BIT;
1298 rmi4_data->board = platformdata;
1299 rmi4_data->touch_stopped = false;
1301 /* init the mutexes for maintain the lists */
1302 mutex_init(&(rmi4_data->fn_list_mutex));
1303 mutex_init(&(rmi4_data->rmi4_page_mutex));
1305 mutex_init(&(rmi4_data->rmi4_wq_mutex));
1308 * Register physical driver - this will call the detect function that
1309 * will then scan the device and determine the supported
1312 retval = synaptics_rmi4_i2c_query_device(rmi4_data);
1314 dev_err(&client->dev, "%s: rmi4 query device failed\n",
1319 /* Store the instance data in the i2c_client */
1320 i2c_set_clientdata(client, rmi4_data);
1322 /*initialize the input device parameters */
1323 rmi4_data->input_dev->name = DRIVER_NAME;
1324 rmi4_data->input_dev->phys = "Synaptics_Clearpad";
1325 rmi4_data->input_dev->id.bustype = BUS_I2C;
1326 rmi4_data->input_dev->dev.parent = &client->dev;
1327 input_set_drvdata(rmi4_data->input_dev, rmi4_data);
1329 /* Initialize the function handlers for rmi4 */
1331 __set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
1332 __set_bit(EV_ABS, rmi4_data->input_dev->evbit);
1334 input_mt_init_slots(rmi4_data->input_dev, SYNA_SUPPORT_POINT_MAX);
1336 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_X, 0,
1337 rmi4_data->sensor_max_x, 0, 0);
1338 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_Y, 0,
1339 rmi4_data->sensor_max_y, 0, 0);
1340 input_set_abs_params(rmi4_data->input_dev, ABS_MT_TOUCH_MAJOR, 0,
1341 MAX_TOUCH_MAJOR, 0, 0);
1343 /* Clear interrupts */
1344 synaptics_rmi4_i2c_block_read(rmi4_data,
1345 rmi4_data->fn01_data_base_addr + 1, intr_status,
1346 rmi4_data->number_of_interrupt_register);
1348 rmi4_debug(DEBUG_TRACE, "intr_status: %d %d %d %d, number_of_interrupt_register = %d\n",
1349 intr_status[0], intr_status[1], intr_status[2], intr_status[3],
1350 rmi4_data->number_of_interrupt_register);
1352 rmi4_data->rmi4_wq = create_workqueue("rmi4_wq");
1353 rmi4_debug(DEBUG_TRACE, "----> create_workqueue start!\n");
1355 INIT_WORK(&rmi4_data->work, synaptics_rmi4_work_func);
1357 retval = request_threaded_irq(platformdata->irq_number, NULL,
1359 platformdata->irq_type,
1360 DRIVER_NAME, rmi4_data);
1362 dev_err(&client->dev, "%s:Unable to get attn irq %d\n",
1363 __func__, platformdata->irq_number);
1367 retval = input_register_device(rmi4_data->input_dev);
1369 dev_err(&client->dev, "%s:input register failed\n", __func__);
1373 #ifdef CONFIG_HAS_EARLYSUSPEND
1374 syna_client = client;
1376 rmi4_data->m_early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1377 rmi4_data->m_early_suspend.suspend = synaptics_rmi4_early_suspend;
1378 rmi4_data->m_early_suspend.resume = synaptics_rmi4_late_resume;
1379 register_early_suspend(&rmi4_data->m_early_suspend);
1381 rmi4_data->m_early_suspend.level = -1;
1382 rmi4_data->m_early_suspend.suspend = NULL;
1383 rmi4_data->m_early_suspend.resume = NULL;
1389 free_irq(platformdata->irq_number, rmi4_data);
1391 if (platformdata->regulator_en) {
1392 regulator_disable(rmi4_data->regulator);
1393 regulator_put(rmi4_data->regulator);
1396 input_free_device(rmi4_data->input_dev);
1397 rmi4_data->input_dev = NULL;
1404 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1405 * @client: i2c client structure pointer
1407 * This function uses to remove the i2c-client
1408 * touchscreen driver and returns integer.
1410 static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
1412 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1413 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1415 #ifdef CONFIG_HAS_EARLYSUSPEND
1416 if (rmi4_data->m_early_suspend.suspend && rmi4_data->m_early_suspend.resume)
1417 unregister_early_suspend(&rmi4_data->m_early_suspend);
1420 rmi4_data->touch_stopped = true;
1421 wake_up(&rmi4_data->wait);
1422 free_irq(pdata->irq_number, rmi4_data);
1423 input_unregister_device(rmi4_data->input_dev);
1424 if (pdata->regulator_en) {
1425 regulator_disable(rmi4_data->regulator);
1426 regulator_put(rmi4_data->regulator);
1433 #ifdef CONFIG_HAS_EARLYSUSPEND
1434 static void synaptics_rmi4_early_suspend(struct early_suspend *h)
1436 struct i2c_client *client = syna_client;
1437 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1439 rmi4_debug(DEBUG_TRACE, "%s: enter!\n", __func__); //rmi4_acgzx
1441 disable_irq(client->irq);
1442 synaptics_rmi4_i2c_byte_write(rmi4_data, rmi4_data->fn01_data_base_addr + 1, 0x00);
1445 static void synaptics_rmi4_late_resume(struct early_suspend *h)
1447 struct i2c_client *client = syna_client;
1448 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1450 unsigned char intr_status;
1452 rmi4_debug(DEBUG_TRACE, "%s: enter!\n", __func__); //rmi4_acgzx
1454 enable_irq(client->irq);
1456 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1457 rmi4_data->fn01_data_base_addr + 1,
1459 rmi4_data->number_of_interrupt_register);
1463 synaptics_rmi4_i2c_byte_write(rmi4_data, rmi4_data->fn01_data_base_addr + 1, 0x0f);
1470 * synaptics_rmi4_suspend() - suspend the touch screen controller
1471 * @dev: pointer to device structure
1473 * This function is used to suspend the
1474 * touch panel controller and returns integer
1476 static int synaptics_rmi4_suspend(struct device *dev)
1478 /* Touch sleep mode */
1480 unsigned char intr_status;
1481 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1482 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1484 rmi4_debug(DEBUG_TRACE, "%s: enter!\n", __func__); //rmi4_acgzx
1486 rmi4_data->touch_stopped = true;
1487 disable_irq(pdata->irq_number);
1489 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1490 rmi4_data->fn01_data_base_addr + 1,
1492 rmi4_data->number_of_interrupt_register);
1496 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1497 rmi4_data->fn01_ctrl_base_addr + 1,
1498 (intr_status & ~TOUCHPAD_CTRL_INTR));
1502 if (pdata->regulator_en)
1503 regulator_disable(rmi4_data->regulator);
1508 * synaptics_rmi4_resume() - resume the touch screen controller
1509 * @dev: pointer to device structure
1511 * This function is used to resume the touch panel
1512 * controller and returns integer.
1514 static int synaptics_rmi4_resume(struct device *dev)
1517 unsigned char intr_status;
1518 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1519 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1521 rmi4_debug(DEBUG_TRACE, "%s: enter!\n", __func__); //rmi4_acgzx
1523 if (pdata->regulator_en)
1524 regulator_enable(rmi4_data->regulator);
1526 enable_irq(pdata->irq_number);
1527 rmi4_data->touch_stopped = false;
1529 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1530 rmi4_data->fn01_data_base_addr + 1,
1532 rmi4_data->number_of_interrupt_register);
1536 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1537 rmi4_data->fn01_ctrl_base_addr + 1,
1538 (intr_status | TOUCHPAD_CTRL_INTR));
1545 static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
1546 .suspend = synaptics_rmi4_suspend,
1547 .resume = synaptics_rmi4_resume,
1551 static const struct i2c_device_id synaptics_rmi4_id_table[] = {
1555 MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
1557 static struct i2c_driver synaptics_rmi4_driver = {
1559 .name = DRIVER_NAME,
1560 .owner = THIS_MODULE,
1561 #if (0 == CONFIG_HAS_EARLYSUSPEND) //rmi4_acgzx
1563 .pm = &synaptics_rmi4_dev_pm_ops,
1567 .probe = synaptics_rmi4_probe,
1568 .remove = __devexit_p(synaptics_rmi4_remove),
1569 .id_table = synaptics_rmi4_id_table,
1572 * synaptics_rmi4_init() - Initialize the touchscreen driver
1574 * This function uses to initializes the synaptics
1575 * touchscreen driver and returns integer.
1577 static int __init synaptics_rmi4_init(void)
1579 return i2c_add_driver(&synaptics_rmi4_driver);
1582 * synaptics_rmi4_exit() - De-initialize the touchscreen driver
1584 * This function uses to de-initialize the synaptics
1585 * touchscreen driver and returns none.
1587 static void __exit synaptics_rmi4_exit(void)
1589 i2c_del_driver(&synaptics_rmi4_driver);
1593 module_init(synaptics_rmi4_init);
1594 module_exit(synaptics_rmi4_exit);
1596 MODULE_LICENSE("GPL v2");
1597 MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
1598 MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
1599 MODULE_ALIAS("i2c:synaptics_rmi4_ts");