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 "synaptics_i2c_rmi4.h"
35 /* TODO: for multiple device support will need a per-device mutex */
36 #define DRIVER_NAME "synaptics_rmi4_i2c"
38 #define MAX_ERROR_REPORT 6
39 #define MAX_TOUCH_MAJOR 15
40 #define MAX_RETRY_COUNT 5
41 #define STD_QUERY_LEN 21
43 #define DATA_BUF_LEN 32
48 #define HAS_PALMDETECT 0x01
49 #define HAS_ROTATE 0x02
50 #define HAS_TAPANDHOLD 0x02
51 #define HAS_DOUBLETAP 0x04
52 #define HAS_EARLYTAP 0x08
53 #define HAS_RELEASE 0x08
54 #define HAS_FLICK 0x10
55 #define HAS_PRESS 0x20
56 #define HAS_PINCH 0x40
58 #define MASK_16BIT 0xFFFF
59 #define MASK_8BIT 0xFF
60 #define MASK_7BIT 0x7F
61 #define MASK_5BIT 0x1F
62 #define MASK_4BIT 0x0F
63 #define MASK_3BIT 0x07
64 #define MASK_2BIT 0x03
65 #define TOUCHPAD_CTRL_INTR 0x8
66 #define PDT_START_SCAN_LOCATION (0x00E9)
67 #define PDT_END_SCAN_LOCATION (0x000A)
68 #define PDT_ENTRY_SIZE (0x0006)
69 #define RMI4_NUMBER_OF_MAX_FINGERS (8)
70 #define SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM (0x11)
71 #define SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM (0x01)
74 * struct synaptics_rmi4_fn_desc - contains the funtion descriptor information
75 * @query_base_addr: base address for query
76 * @cmd_base_addr: base address for command
77 * @ctrl_base_addr: base address for control
78 * @data_base_addr: base address for data
79 * @intr_src_count: count for the interrupt source
80 * @fn_number: function number
82 * This structure is used to gives the function descriptor information
83 * of the particular functionality.
85 struct synaptics_rmi4_fn_desc
{
86 unsigned char query_base_addr
;
87 unsigned char cmd_base_addr
;
88 unsigned char ctrl_base_addr
;
89 unsigned char data_base_addr
;
90 unsigned char intr_src_count
;
91 unsigned char fn_number
;
95 * struct synaptics_rmi4_fn - contains the funtion information
96 * @fn_number: function number
97 * @num_of_data_sources: number of data sources
98 * @num_of_data_points: number of fingers touched
99 * @size_of_data_register_block: data register block size
100 * @index_to_intr_reg: index for interrupt register
101 * @intr_mask: interrupt mask value
102 * @fn_desc: variable for function descriptor structure
103 * @link: linked list for function descriptors
105 * This structure gives information about the number of data sources and
106 * the number of data registers associated with the function.
108 struct synaptics_rmi4_fn
{
109 unsigned char fn_number
;
110 unsigned char num_of_data_sources
;
111 unsigned char num_of_data_points
;
112 unsigned char size_of_data_register_block
;
113 unsigned char index_to_intr_reg
;
114 unsigned char intr_mask
;
115 struct synaptics_rmi4_fn_desc fn_desc
;
116 struct list_head link
;
120 * struct synaptics_rmi4_device_info - contains the rmi4 device information
121 * @version_major: protocol major version number
122 * @version_minor: protocol minor version number
123 * @manufacturer_id: manufacturer identification byte
124 * @product_props: product properties information
125 * @product_info: product info array
126 * @date_code: device manufacture date
127 * @tester_id: tester id array
128 * @serial_number: serial number for that device
129 * @product_id_string: product id for the device
130 * @support_fn_list: linked list for device information
132 * This structure gives information about the number of data sources and
133 * the number of data registers associated with the function.
135 struct synaptics_rmi4_device_info
{
136 unsigned int version_major
;
137 unsigned int version_minor
;
138 unsigned char manufacturer_id
;
139 unsigned char product_props
;
140 unsigned char product_info
[2];
141 unsigned char date_code
[3];
142 unsigned short tester_id
;
143 unsigned short serial_number
;
144 unsigned char product_id_string
[11];
145 struct list_head support_fn_list
;
149 * struct synaptics_rmi4_data - contains the rmi4 device data
150 * @rmi4_mod_info: structure variable for rmi4 device info
151 * @input_dev: pointer for input device
152 * @i2c_client: pointer for i2c client
153 * @board: constant pointer for touch platform data
154 * @fn_list_mutex: mutex for funtion list
155 * @rmi4_page_mutex: mutex for rmi4 page
156 * @current_page: variable for integer
157 * @number_of_interrupt_register: interrupt registers count
158 * @fn01_ctrl_base_addr: control base address for fn01
159 * @fn01_query_base_addr: query base address for fn01
160 * @fn01_data_base_addr: data base address for fn01
161 * @sensor_max_x: sensor maximum x value
162 * @sensor_max_y: sensor maximum y value
163 * @regulator: pointer to the regulator structure
164 * @wait: wait queue structure variable
165 * @touch_stopped: flag to stop the thread function
167 * This structure gives the device data information.
169 struct synaptics_rmi4_data
{
170 struct synaptics_rmi4_device_info rmi4_mod_info
;
171 struct input_dev
*input_dev
;
172 struct i2c_client
*i2c_client
;
173 const struct synaptics_rmi4_platform_data
*board
;
174 struct mutex fn_list_mutex
;
175 struct mutex rmi4_page_mutex
;
177 unsigned int number_of_interrupt_register
;
178 unsigned short fn01_ctrl_base_addr
;
179 unsigned short fn01_query_base_addr
;
180 unsigned short fn01_data_base_addr
;
183 struct regulator
*regulator
;
184 wait_queue_head_t wait
;
189 * synaptics_rmi4_set_page() - sets the page
190 * @pdata: pointer to synaptics_rmi4_data structure
191 * @address: set the address of the page
193 * This function is used to set the page and returns integer.
195 static int synaptics_rmi4_set_page(struct synaptics_rmi4_data
*pdata
,
196 unsigned int address
)
198 unsigned char txbuf
[PAGE_LEN
];
201 struct i2c_client
*i2c
= pdata
->i2c_client
;
203 page
= ((address
>> 8) & MASK_8BIT
);
204 if (page
!= pdata
->current_page
) {
205 txbuf
[0] = MASK_8BIT
;
207 retval
= i2c_master_send(i2c
, txbuf
, PAGE_LEN
);
208 if (retval
!= PAGE_LEN
)
209 dev_err(&i2c
->dev
, "%s:failed:%d\n", __func__
, retval
);
211 pdata
->current_page
= page
;
217 * synaptics_rmi4_i2c_block_read() - read the block of data
218 * @pdata: pointer to synaptics_rmi4_data structure
219 * @address: read the block of data from this offset
220 * @valp: pointer to a buffer containing the data to be read
221 * @size: number of bytes to read
223 * This function is to read the block of data and returns integer.
225 static int synaptics_rmi4_i2c_block_read(struct synaptics_rmi4_data
*pdata
,
226 unsigned short address
,
227 unsigned char *valp
, int size
)
232 struct i2c_client
*i2c
= pdata
->i2c_client
;
234 mutex_lock(&(pdata
->rmi4_page_mutex
));
235 retval
= synaptics_rmi4_set_page(pdata
, address
);
236 if (retval
!= PAGE_LEN
)
238 index
= address
& MASK_8BIT
;
240 retval
= i2c_smbus_read_i2c_block_data(i2c
, index
, size
, valp
);
241 if (retval
!= size
) {
242 if (++retry_count
== MAX_RETRY_COUNT
)
244 "%s:address 0x%04x size %d failed:%d\n",
245 __func__
, address
, size
, retval
);
247 synaptics_rmi4_set_page(pdata
, address
);
252 mutex_unlock(&(pdata
->rmi4_page_mutex
));
257 * synaptics_rmi4_i2c_byte_write() - write the single byte data
258 * @pdata: pointer to synaptics_rmi4_data structure
259 * @address: write the block of data from this offset
260 * @data: data to be write
262 * This function is to write the single byte data and returns integer.
264 static int synaptics_rmi4_i2c_byte_write(struct synaptics_rmi4_data
*pdata
,
265 unsigned short address
,
268 unsigned char txbuf
[2];
270 struct i2c_client
*i2c
= pdata
->i2c_client
;
272 /* Can't have anyone else changing the page behind our backs */
273 mutex_lock(&(pdata
->rmi4_page_mutex
));
275 retval
= synaptics_rmi4_set_page(pdata
, address
);
276 if (retval
!= PAGE_LEN
)
278 txbuf
[0] = address
& MASK_8BIT
;
280 retval
= i2c_master_send(pdata
->i2c_client
, txbuf
, 2);
281 /* Add in retry on writes only in certian error return values */
283 dev_err(&i2c
->dev
, "%s:failed:%d\n", __func__
, retval
);
288 mutex_unlock(&(pdata
->rmi4_page_mutex
));
293 * synpatics_rmi4_touchpad_report() - reports for the rmi4 touchpad device
294 * @pdata: pointer to synaptics_rmi4_data structure
295 * @rfi: pointer to synaptics_rmi4_fn structure
297 * This function calls to reports for the rmi4 touchpad device
299 static int synpatics_rmi4_touchpad_report(struct synaptics_rmi4_data
*pdata
,
300 struct synaptics_rmi4_fn
*rfi
)
302 /* number of touch points - fingers down in this case */
305 int fingers_supported
;
306 int finger_registers
;
311 unsigned short data_base_addr
;
312 unsigned short data_offset
;
313 unsigned char data_reg_blk_size
;
314 unsigned char values
[2];
315 unsigned char data
[DATA_LEN
];
316 int x
[RMI4_NUMBER_OF_MAX_FINGERS
];
317 int y
[RMI4_NUMBER_OF_MAX_FINGERS
];
318 int wx
[RMI4_NUMBER_OF_MAX_FINGERS
];
319 int wy
[RMI4_NUMBER_OF_MAX_FINGERS
];
320 struct i2c_client
*client
= pdata
->i2c_client
;
322 /* get 2D sensor finger data */
324 * First get the finger status field - the size of the finger status
325 * field is determined by the number of finger supporte - 2 bits per
326 * finger, so the number of registers to read is:
327 * registerCount = ceil(numberOfFingers/4).
328 * Read the required number of registers and check each 2 bit field to
329 * determine if a finger is down:
330 * 00 = finger not present,
331 * 01 = finger present and data accurate,
332 * 10 = finger present but data may not be accurate,
333 * 11 = reserved for product use.
335 fingers_supported
= rfi
->num_of_data_points
;
336 finger_registers
= (fingers_supported
+ 3)/4;
337 data_base_addr
= rfi
->fn_desc
.data_base_addr
;
338 retval
= synaptics_rmi4_i2c_block_read(pdata
, data_base_addr
, values
,
340 if (retval
!= finger_registers
) {
341 dev_err(&client
->dev
, "%s:read status registers failed\n",
346 * For each finger present, read the proper number of registers
347 * to get absolute data.
349 data_reg_blk_size
= rfi
->size_of_data_register_block
;
350 for (finger
= 0; finger
< fingers_supported
; finger
++) {
351 /* determine which data byte the finger status is in */
353 /* bit shift to get finger's status */
354 finger_shift
= (finger
% 4) * 2;
355 finger_status
= (values
[reg
] >> finger_shift
) & 3;
357 * if finger status indicates a finger is present then
358 * read the finger data and report it
360 if (finger_status
== 1 || finger_status
== 2) {
361 /* Read the finger data */
362 data_offset
= data_base_addr
+
363 ((finger
* data_reg_blk_size
) +
365 retval
= synaptics_rmi4_i2c_block_read(pdata
,
368 if (retval
!= data_reg_blk_size
) {
369 printk(KERN_ERR
"%s:read data failed\n",
374 (data
[0] << 4) | (data
[2] & MASK_4BIT
);
377 ((data
[2] >> 4) & MASK_4BIT
);
379 (data
[3] >> 4) & MASK_4BIT
;
381 (data
[3] & MASK_4BIT
);
383 if (pdata
->board
->x_flip
)
385 pdata
->sensor_max_x
-
387 if (pdata
->board
->y_flip
)
389 pdata
->sensor_max_y
-
392 /* number of active touch points */
397 /* report to input subsystem */
399 for (finger
= 0; finger
< touch_count
; finger
++) {
400 input_report_abs(pdata
->input_dev
, ABS_MT_TOUCH_MAJOR
,
401 max(wx
[finger
] , wy
[finger
]));
402 input_report_abs(pdata
->input_dev
, ABS_MT_POSITION_X
,
404 input_report_abs(pdata
->input_dev
, ABS_MT_POSITION_Y
,
406 input_mt_sync(pdata
->input_dev
);
409 input_mt_sync(pdata
->input_dev
);
411 /* sync after groups of events */
412 input_sync(pdata
->input_dev
);
413 /* return the number of touch points */
418 * synaptics_rmi4_report_device() - reports the rmi4 device
419 * @pdata: pointer to synaptics_rmi4_data structure
420 * @rfi: pointer to synaptics_rmi4_fn
422 * This function is used to call the report function of the rmi4 device.
424 static int synaptics_rmi4_report_device(struct synaptics_rmi4_data
*pdata
,
425 struct synaptics_rmi4_fn
*rfi
)
428 struct i2c_client
*client
= pdata
->i2c_client
;
429 static int num_error_reports
;
430 if (rfi
->fn_number
!= SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM
) {
432 if (num_error_reports
< MAX_ERROR_REPORT
)
433 dev_err(&client
->dev
, "%s:report not supported\n",
436 touch
= synpatics_rmi4_touchpad_report(pdata
, rfi
);
440 * synaptics_rmi4_sensor_report() - reports to input subsystem
441 * @pdata: pointer to synaptics_rmi4_data structure
443 * This function is used to reads in all data sources and reports
444 * them to the input subsystem.
446 static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data
*pdata
)
448 unsigned char intr_status
[4];
449 /* number of touch points - fingers or buttons */
452 struct synaptics_rmi4_fn
*rfi
;
453 struct synaptics_rmi4_device_info
*rmi
;
454 struct i2c_client
*client
= pdata
->i2c_client
;
457 * Get the interrupt status from the function $01
458 * control register+1 to find which source(s) were interrupting
459 * so we can read the data from the source(s) (2D sensor, buttons..)
461 retval
= synaptics_rmi4_i2c_block_read(pdata
,
462 pdata
->fn01_data_base_addr
+ 1,
464 pdata
->number_of_interrupt_register
);
465 if (retval
!= pdata
->number_of_interrupt_register
) {
466 dev_err(&client
->dev
,
467 "could not read interrupt status registers\n");
471 * check each function that has data sources and if the interrupt for
472 * that triggered then call that RMI4 functions report() function to
473 * gather data and report it to the input subsystem
475 rmi
= &(pdata
->rmi4_mod_info
);
476 list_for_each_entry(rfi
, &rmi
->support_fn_list
, link
) {
477 if (rfi
->num_of_data_sources
) {
478 if (intr_status
[rfi
->index_to_intr_reg
] &
480 touch
= synaptics_rmi4_report_device(pdata
,
484 /* return the number of touch points */
489 * synaptics_rmi4_irq() - thread function for rmi4 attention line
491 * @data: void pointer
493 * This function is interrupt thread function. It just notifies the
494 * application layer that attention is required.
496 static irqreturn_t
synaptics_rmi4_irq(int irq
, void *data
)
498 struct synaptics_rmi4_data
*pdata
= data
;
501 touch_count
= synaptics_rmi4_sensor_report(pdata
);
503 wait_event_timeout(pdata
->wait
, pdata
->touch_stopped
,
504 msecs_to_jiffies(1));
507 } while (!pdata
->touch_stopped
);
512 * synpatics_rmi4_touchpad_detect() - detects the rmi4 touchpad device
513 * @pdata: pointer to synaptics_rmi4_data structure
514 * @rfi: pointer to synaptics_rmi4_fn structure
515 * @fd: pointer to synaptics_rmi4_fn_desc structure
516 * @interruptcount: count the number of interrupts
518 * This function calls to detects the rmi4 touchpad device
520 static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data
*pdata
,
521 struct synaptics_rmi4_fn
*rfi
,
522 struct synaptics_rmi4_fn_desc
*fd
,
523 unsigned int interruptcount
)
525 unsigned char queries
[QUERY_LEN
];
526 unsigned short intr_offset
;
527 unsigned char abs_data_size
;
528 unsigned char abs_data_blk_size
;
529 unsigned char egr_0
, egr_1
;
530 unsigned int all_data_blk_size
;
531 int has_pinch
, has_flick
, has_tap
;
532 int has_tapandhold
, has_doubletap
;
533 int has_earlytap
, has_press
;
534 int has_palmdetect
, has_rotate
;
538 struct i2c_client
*client
= pdata
->i2c_client
;
540 rfi
->fn_desc
.query_base_addr
= fd
->query_base_addr
;
541 rfi
->fn_desc
.data_base_addr
= fd
->data_base_addr
;
542 rfi
->fn_desc
.intr_src_count
= fd
->intr_src_count
;
543 rfi
->fn_desc
.fn_number
= fd
->fn_number
;
544 rfi
->fn_number
= fd
->fn_number
;
545 rfi
->num_of_data_sources
= fd
->intr_src_count
;
546 rfi
->fn_desc
.ctrl_base_addr
= fd
->ctrl_base_addr
;
547 rfi
->fn_desc
.cmd_base_addr
= fd
->cmd_base_addr
;
550 * need to get number of fingers supported, data size, etc.
551 * to be used when getting data since the number of registers to
552 * read depends on the number of fingers supported and data size.
554 retval
= synaptics_rmi4_i2c_block_read(pdata
, fd
->query_base_addr
,
557 if (retval
!= sizeof(queries
)) {
558 dev_err(&client
->dev
, "%s:read function query registers\n",
563 * 2D data sources have only 3 bits for the number of fingers
564 * supported - so the encoding is a bit wierd.
566 if ((queries
[1] & MASK_3BIT
) <= 4)
567 /* add 1 since zero based */
568 rfi
->num_of_data_points
= (queries
[1] & MASK_3BIT
) + 1;
571 * a value of 5 is up to 10 fingers - 6 and 7 are reserved
572 * (shouldn't get these i int retval;n a normal 2D source).
574 if ((queries
[1] & MASK_3BIT
) == 5)
575 rfi
->num_of_data_points
= 10;
577 /* Need to get interrupt info for handling interrupts */
578 rfi
->index_to_intr_reg
= (interruptcount
+ 7)/8;
579 if (rfi
->index_to_intr_reg
!= 0)
580 rfi
->index_to_intr_reg
-= 1;
582 * loop through interrupts for each source in fn $11
583 * and or in a bit to the interrupt mask for each.
585 intr_offset
= interruptcount
% 8;
587 for (i
= intr_offset
;
588 i
< ((fd
->intr_src_count
& MASK_3BIT
) + intr_offset
); i
++)
589 rfi
->intr_mask
|= 1 << i
;
591 /* Size of just the absolute data for one finger */
592 abs_data_size
= queries
[5] & MASK_2BIT
;
593 /* One each for X and Y, one for LSB for X & Y, one for W, one for Z */
594 abs_data_blk_size
= 3 + (2 * (abs_data_size
== 0 ? 1 : 0));
595 rfi
->size_of_data_register_block
= abs_data_blk_size
;
598 * need to determine the size of data to read - this depends on
599 * conditions such as whether Relative data is reported and if Gesture
606 * Get info about what EGR data is supported, whether it has
607 * Relative data supported, etc.
609 has_pinch
= egr_0
& HAS_PINCH
;
610 has_flick
= egr_0
& HAS_FLICK
;
611 has_tap
= egr_0
& HAS_TAP
;
612 has_earlytap
= egr_0
& HAS_EARLYTAP
;
613 has_press
= egr_0
& HAS_PRESS
;
614 has_rotate
= egr_1
& HAS_ROTATE
;
615 has_rel
= queries
[1] & HAS_RELEASE
;
616 has_tapandhold
= egr_0
& HAS_TAPANDHOLD
;
617 has_doubletap
= egr_0
& HAS_DOUBLETAP
;
618 has_palmdetect
= egr_1
& HAS_PALMDETECT
;
621 * Size of all data including finger status, absolute data for each
622 * finger, relative data and EGR data
625 /* finger status, four fingers per register */
626 ((rfi
->num_of_data_points
+ 3) / 4) +
627 /* absolute data, per finger times number of fingers */
628 (abs_data_blk_size
* rfi
->num_of_data_points
) +
630 * two relative registers (if relative is being reported)
634 * F11_2D_data8 is only present if the egr_0
635 * register is non-zero.
639 * F11_2D_data9 is only present if either egr_0 or
640 * egr_1 registers are non-zero.
644 * F11_2D_data10 is only present if EGR_PINCH or EGR_FLICK of
645 * egr_0 reports as 1.
647 !!(has_pinch
| has_flick
) +
649 * F11_2D_data11 and F11_2D_data12 are only present if
650 * EGR_FLICK of egr_0 reports as 1.
657 * synpatics_rmi4_touchpad_config() - confiures the rmi4 touchpad device
658 * @pdata: pointer to synaptics_rmi4_data structure
659 * @rfi: pointer to synaptics_rmi4_fn structure
661 * This function calls to confiures the rmi4 touchpad device
663 int synpatics_rmi4_touchpad_config(struct synaptics_rmi4_data
*pdata
,
664 struct synaptics_rmi4_fn
*rfi
)
667 * For the data source - print info and do any
668 * source specific configuration.
670 unsigned char data
[BUF_LEN
];
672 struct i2c_client
*client
= pdata
->i2c_client
;
674 /* Get and print some info about the data source... */
675 /* To Query 2D devices we need to read from the address obtained
676 * from the function descriptor stored in the RMI function info.
678 retval
= synaptics_rmi4_i2c_block_read(pdata
,
679 rfi
->fn_desc
.query_base_addr
,
681 if (retval
!= QUERY_LEN
)
682 dev_err(&client
->dev
, "%s:read query registers failed\n",
685 retval
= synaptics_rmi4_i2c_block_read(pdata
,
686 rfi
->fn_desc
.ctrl_base_addr
,
688 if (retval
!= DATA_BUF_LEN
) {
689 dev_err(&client
->dev
,
690 "%s:read control registers failed\n",
694 /* Store these for use later*/
695 pdata
->sensor_max_x
= ((data
[6] & MASK_8BIT
) << 0) |
696 ((data
[7] & MASK_4BIT
) << 8);
697 pdata
->sensor_max_y
= ((data
[8] & MASK_5BIT
) << 0) |
698 ((data
[9] & MASK_4BIT
) << 8);
704 * synaptics_rmi4_i2c_query_device() - query the rmi4 device
705 * @pdata: pointer to synaptics_rmi4_data structure
707 * This function is used to query the rmi4 device.
709 static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data
*pdata
)
713 unsigned char std_queries
[STD_QUERY_LEN
];
714 unsigned char intr_count
= 0;
715 int data_sources
= 0;
716 unsigned int ctrl_offset
;
717 struct synaptics_rmi4_fn
*rfi
;
718 struct synaptics_rmi4_fn_desc rmi_fd
;
719 struct synaptics_rmi4_device_info
*rmi
;
720 struct i2c_client
*client
= pdata
->i2c_client
;
723 * init the physical drivers RMI module
724 * info list of functions
726 INIT_LIST_HEAD(&pdata
->rmi4_mod_info
.support_fn_list
);
729 * Read the Page Descriptor Table to determine what functions
732 for (i
= PDT_START_SCAN_LOCATION
; i
> PDT_END_SCAN_LOCATION
;
733 i
-= PDT_ENTRY_SIZE
) {
734 retval
= synaptics_rmi4_i2c_block_read(pdata
, i
,
735 (unsigned char *)&rmi_fd
,
737 if (retval
!= sizeof(rmi_fd
)) {
738 /* failed to read next PDT entry */
739 dev_err(&client
->dev
, "%s: read error\n", __func__
);
743 if (rmi_fd
.fn_number
) {
744 switch (rmi_fd
.fn_number
& MASK_8BIT
) {
745 case SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM
:
746 pdata
->fn01_query_base_addr
=
747 rmi_fd
.query_base_addr
;
748 pdata
->fn01_ctrl_base_addr
=
749 rmi_fd
.ctrl_base_addr
;
750 pdata
->fn01_data_base_addr
=
751 rmi_fd
.data_base_addr
;
753 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM
:
754 if (rmi_fd
.intr_src_count
) {
755 rfi
= kmalloc(sizeof(*rfi
),
758 dev_err(&client
->dev
,
759 "%s:kmalloc failed\n",
763 retval
= synpatics_rmi4_touchpad_detect
772 /* interrupt count for next iteration */
773 intr_count
+= (rmi_fd
.intr_src_count
& MASK_3BIT
);
775 * We only want to add functions to the list
776 * that have data associated with them.
778 if (rfi
&& rmi_fd
.intr_src_count
) {
779 /* link this function info to the RMI module */
780 mutex_lock(&(pdata
->fn_list_mutex
));
781 list_add_tail(&rfi
->link
,
782 &pdata
->rmi4_mod_info
.support_fn_list
);
783 mutex_unlock(&(pdata
->fn_list_mutex
));
787 * A zero in the function number
788 * signals the end of the PDT
790 dev_dbg(&client
->dev
,
791 "%s:end of PDT\n", __func__
);
796 * calculate the interrupt register count - used in the
797 * ISR to read the correct number of interrupt registers
799 pdata
->number_of_interrupt_register
= (intr_count
+ 7) / 8;
801 * Function $01 will be used to query the product properties,
802 * and product ID so we had to read the PDT above first to get
803 * the Fn $01 query address and prior to filling in the product
804 * info. NOTE: Even an unflashed device will still have FN $01.
807 /* Load up the standard queries and get the RMI4 module info */
808 retval
= synaptics_rmi4_i2c_block_read(pdata
,
809 pdata
->fn01_query_base_addr
,
811 sizeof(std_queries
));
812 if (retval
!= sizeof(std_queries
)) {
813 dev_err(&client
->dev
, "%s:Failed reading queries\n",
818 /* Currently supported RMI version is 4.0 */
819 pdata
->rmi4_mod_info
.version_major
= 4;
820 pdata
->rmi4_mod_info
.version_minor
= 0;
822 * get manufacturer id, product_props, product info,
823 * date code, tester id, serial num and product id (name)
825 pdata
->rmi4_mod_info
.manufacturer_id
= std_queries
[0];
826 pdata
->rmi4_mod_info
.product_props
= std_queries
[1];
827 pdata
->rmi4_mod_info
.product_info
[0] = std_queries
[2];
828 pdata
->rmi4_mod_info
.product_info
[1] = std_queries
[3];
829 /* year - 2001-2032 */
830 pdata
->rmi4_mod_info
.date_code
[0] = std_queries
[4] & MASK_5BIT
;
832 pdata
->rmi4_mod_info
.date_code
[1] = std_queries
[5] & MASK_4BIT
;
834 pdata
->rmi4_mod_info
.date_code
[2] = std_queries
[6] & MASK_5BIT
;
835 pdata
->rmi4_mod_info
.tester_id
= ((std_queries
[7] & MASK_7BIT
) << 8) |
836 (std_queries
[8] & MASK_7BIT
);
837 pdata
->rmi4_mod_info
.serial_number
=
838 ((std_queries
[9] & MASK_7BIT
) << 8) |
839 (std_queries
[10] & MASK_7BIT
);
840 memcpy(pdata
->rmi4_mod_info
.product_id_string
, &std_queries
[11], 10);
842 /* Check if this is a Synaptics device - report if not. */
843 if (pdata
->rmi4_mod_info
.manufacturer_id
!= 1)
844 dev_err(&client
->dev
, "%s: non-Synaptics mfg id:%d\n",
845 __func__
, pdata
->rmi4_mod_info
.manufacturer_id
);
847 list_for_each_entry(rfi
, &pdata
->rmi4_mod_info
.support_fn_list
, link
)
848 data_sources
+= rfi
->num_of_data_sources
;
850 rmi
= &(pdata
->rmi4_mod_info
);
851 list_for_each_entry(rfi
, &rmi
->support_fn_list
, link
) {
852 if (rfi
->num_of_data_sources
) {
853 if (rfi
->fn_number
==
854 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM
) {
855 retval
= synpatics_rmi4_touchpad_config
860 dev_err(&client
->dev
,
861 "%s:fn_number not supported\n",
864 * Turn on interrupts for this
865 * function's data sources.
867 ctrl_offset
= pdata
->fn01_ctrl_base_addr
+ 1 +
868 rfi
->index_to_intr_reg
;
869 retval
= synaptics_rmi4_i2c_byte_write(pdata
,
881 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
882 * @i2c: i2c client structure pointer
883 * @id:i2c device id pointer
885 * This function will allocate and initialize the instance
886 * data and request the irq and set the instance data as the clients
887 * platform data then register the physical driver which will do a scan of
888 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
889 * have data sources associated with them.
891 static int __devinit synaptics_rmi4_probe
892 (struct i2c_client
*client
, const struct i2c_device_id
*dev_id
)
895 unsigned char intr_status
[4];
896 struct synaptics_rmi4_data
*rmi4_data
;
897 const struct synaptics_rmi4_platform_data
*platformdata
=
898 client
->dev
.platform_data
;
900 if (!i2c_check_functionality(client
->adapter
,
901 I2C_FUNC_SMBUS_BYTE_DATA
)) {
902 dev_err(&client
->dev
, "i2c smbus byte data not supported\n");
907 dev_err(&client
->dev
, "%s: no platform data\n", __func__
);
911 /* Allocate and initialize the instance data for this client */
912 rmi4_data
= kzalloc(sizeof(struct synaptics_rmi4_data
) * 2,
915 dev_err(&client
->dev
, "%s: no memory allocated\n", __func__
);
919 rmi4_data
->input_dev
= input_allocate_device();
920 if (rmi4_data
->input_dev
== NULL
) {
921 dev_err(&client
->dev
, "%s:input device alloc failed\n",
927 if (platformdata
->regulator_en
) {
928 rmi4_data
->regulator
= regulator_get(&client
->dev
, "vdd");
929 if (IS_ERR(rmi4_data
->regulator
)) {
930 dev_err(&client
->dev
, "%s:get regulator failed\n",
932 retval
= PTR_ERR(rmi4_data
->regulator
);
935 regulator_enable(rmi4_data
->regulator
);
938 init_waitqueue_head(&rmi4_data
->wait
);
940 * Copy i2c_client pointer into RTID's i2c_client pointer for
941 * later use in rmi4_read, rmi4_write, etc.
943 rmi4_data
->i2c_client
= client
;
944 /* So we set the page correctly the first time */
945 rmi4_data
->current_page
= MASK_16BIT
;
946 rmi4_data
->board
= platformdata
;
947 rmi4_data
->touch_stopped
= false;
949 /* init the mutexes for maintain the lists */
950 mutex_init(&(rmi4_data
->fn_list_mutex
));
951 mutex_init(&(rmi4_data
->rmi4_page_mutex
));
954 * Register physical driver - this will call the detect function that
955 * will then scan the device and determine the supported
958 retval
= synaptics_rmi4_i2c_query_device(rmi4_data
);
960 dev_err(&client
->dev
, "%s: rmi4 query device failed\n",
965 /* Store the instance data in the i2c_client */
966 i2c_set_clientdata(client
, rmi4_data
);
968 /*initialize the input device parameters */
969 rmi4_data
->input_dev
->name
= DRIVER_NAME
;
970 rmi4_data
->input_dev
->phys
= "Synaptics_Clearpad";
971 rmi4_data
->input_dev
->id
.bustype
= BUS_I2C
;
972 rmi4_data
->input_dev
->dev
.parent
= &client
->dev
;
973 input_set_drvdata(rmi4_data
->input_dev
, rmi4_data
);
975 /* Initialize the function handlers for rmi4 */
976 set_bit(EV_SYN
, rmi4_data
->input_dev
->evbit
);
977 set_bit(EV_KEY
, rmi4_data
->input_dev
->evbit
);
978 set_bit(EV_ABS
, rmi4_data
->input_dev
->evbit
);
980 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_POSITION_X
, 0,
981 rmi4_data
->sensor_max_x
, 0, 0);
982 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_POSITION_Y
, 0,
983 rmi4_data
->sensor_max_y
, 0, 0);
984 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_TOUCH_MAJOR
, 0,
985 MAX_TOUCH_MAJOR
, 0, 0);
987 /* Clear interrupts */
988 synaptics_rmi4_i2c_block_read(rmi4_data
,
989 rmi4_data
->fn01_data_base_addr
+ 1, intr_status
,
990 rmi4_data
->number_of_interrupt_register
);
991 retval
= request_threaded_irq(platformdata
->irq_number
, NULL
,
993 platformdata
->irq_type
,
994 DRIVER_NAME
, rmi4_data
);
996 dev_err(&client
->dev
, "%s:Unable to get attn irq %d\n",
997 __func__
, platformdata
->irq_number
);
1001 retval
= input_register_device(rmi4_data
->input_dev
);
1003 dev_err(&client
->dev
, "%s:input register failed\n", __func__
);
1010 free_irq(platformdata
->irq_number
, rmi4_data
);
1012 if (platformdata
->regulator_en
) {
1013 regulator_disable(rmi4_data
->regulator
);
1014 regulator_put(rmi4_data
->regulator
);
1017 input_free_device(rmi4_data
->input_dev
);
1018 rmi4_data
->input_dev
= NULL
;
1025 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1026 * @client: i2c client structure pointer
1028 * This funtion uses to remove the i2c-client
1029 * touchscreen driver and returns integer.
1031 static int __devexit
synaptics_rmi4_remove(struct i2c_client
*client
)
1033 struct synaptics_rmi4_data
*rmi4_data
= i2c_get_clientdata(client
);
1034 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1036 rmi4_data
->touch_stopped
= true;
1037 wake_up(&rmi4_data
->wait
);
1038 free_irq(pdata
->irq_number
, rmi4_data
);
1039 input_unregister_device(rmi4_data
->input_dev
);
1040 if (pdata
->regulator_en
) {
1041 regulator_disable(rmi4_data
->regulator
);
1042 regulator_put(rmi4_data
->regulator
);
1051 * synaptics_rmi4_suspend() - suspend the touch screen controller
1052 * @dev: pointer to device structure
1054 * This funtion is used to suspend the
1055 * touch panel controller and returns integer
1057 static int synaptics_rmi4_suspend(struct device
*dev
)
1059 /* Touch sleep mode */
1061 unsigned char intr_status
;
1062 struct synaptics_rmi4_data
*rmi4_data
= dev_get_drvdata(dev
);
1063 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1065 rmi4_data
->touch_stopped
= true;
1066 disable_irq(pdata
->irq_number
);
1068 retval
= synaptics_rmi4_i2c_block_read(rmi4_data
,
1069 rmi4_data
->fn01_data_base_addr
+ 1,
1071 rmi4_data
->number_of_interrupt_register
);
1075 retval
= synaptics_rmi4_i2c_byte_write(rmi4_data
,
1076 rmi4_data
->fn01_ctrl_base_addr
+ 1,
1077 (intr_status
& ~TOUCHPAD_CTRL_INTR
));
1081 if (pdata
->regulator_en
)
1082 regulator_disable(rmi4_data
->regulator
);
1087 * synaptics_rmi4_resume() - resume the touch screen controller
1088 * @dev: pointer to device structure
1090 * This funtion is used to resume the touch panel
1091 * controller and returns integer.
1093 static int synaptics_rmi4_resume(struct device
*dev
)
1096 unsigned char intr_status
;
1097 struct synaptics_rmi4_data
*rmi4_data
= dev_get_drvdata(dev
);
1098 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1100 if (pdata
->regulator_en
)
1101 regulator_enable(rmi4_data
->regulator
);
1103 enable_irq(pdata
->irq_number
);
1104 rmi4_data
->touch_stopped
= false;
1106 retval
= synaptics_rmi4_i2c_block_read(rmi4_data
,
1107 rmi4_data
->fn01_data_base_addr
+ 1,
1109 rmi4_data
->number_of_interrupt_register
);
1113 retval
= synaptics_rmi4_i2c_byte_write(rmi4_data
,
1114 rmi4_data
->fn01_ctrl_base_addr
+ 1,
1115 (intr_status
| TOUCHPAD_CTRL_INTR
));
1122 static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops
= {
1123 .suspend
= synaptics_rmi4_suspend
,
1124 .resume
= synaptics_rmi4_resume
,
1128 static const struct i2c_device_id synaptics_rmi4_id_table
[] = {
1132 MODULE_DEVICE_TABLE(i2c
, synaptics_rmi4_id_table
);
1134 static struct i2c_driver synaptics_rmi4_driver
= {
1136 .name
= DRIVER_NAME
,
1137 .owner
= THIS_MODULE
,
1139 .pm
= &synaptics_rmi4_dev_pm_ops
,
1142 .probe
= synaptics_rmi4_probe
,
1143 .remove
= __devexit_p(synaptics_rmi4_remove
),
1144 .id_table
= synaptics_rmi4_id_table
,
1147 * synaptics_rmi4_init() - Initialize the touchscreen driver
1149 * This funtion uses to initializes the synaptics
1150 * touchscreen driver and returns integer.
1152 static int __init
synaptics_rmi4_init(void)
1154 return i2c_add_driver(&synaptics_rmi4_driver
);
1157 * synaptics_rmi4_exit() - De-initialize the touchscreen driver
1159 * This funtion uses to de-initialize the synaptics
1160 * touchscreen driver and returns none.
1162 static void __exit
synaptics_rmi4_exit(void)
1164 i2c_del_driver(&synaptics_rmi4_driver
);
1168 module_init(synaptics_rmi4_init
);
1169 module_exit(synaptics_rmi4_exit
);
1171 MODULE_LICENSE("GPL v2");
1172 MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
1173 MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
1174 MODULE_ALIAS("i2c:synaptics_rmi4_ts");