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
774 /* interrupt count for next iteration */
775 intr_count
+= (rmi_fd
.intr_src_count
& MASK_3BIT
);
777 * We only want to add functions to the list
778 * that have data associated with them.
780 if (rfi
&& rmi_fd
.intr_src_count
) {
781 /* link this function info to the RMI module */
782 mutex_lock(&(pdata
->fn_list_mutex
));
783 list_add_tail(&rfi
->link
,
784 &pdata
->rmi4_mod_info
.support_fn_list
);
785 mutex_unlock(&(pdata
->fn_list_mutex
));
789 * A zero in the function number
790 * signals the end of the PDT
792 dev_dbg(&client
->dev
,
793 "%s:end of PDT\n", __func__
);
798 * calculate the interrupt register count - used in the
799 * ISR to read the correct number of interrupt registers
801 pdata
->number_of_interrupt_register
= (intr_count
+ 7) / 8;
803 * Function $01 will be used to query the product properties,
804 * and product ID so we had to read the PDT above first to get
805 * the Fn $01 query address and prior to filling in the product
806 * info. NOTE: Even an unflashed device will still have FN $01.
809 /* Load up the standard queries and get the RMI4 module info */
810 retval
= synaptics_rmi4_i2c_block_read(pdata
,
811 pdata
->fn01_query_base_addr
,
813 sizeof(std_queries
));
814 if (retval
!= sizeof(std_queries
)) {
815 dev_err(&client
->dev
, "%s:Failed reading queries\n",
820 /* Currently supported RMI version is 4.0 */
821 pdata
->rmi4_mod_info
.version_major
= 4;
822 pdata
->rmi4_mod_info
.version_minor
= 0;
824 * get manufacturer id, product_props, product info,
825 * date code, tester id, serial num and product id (name)
827 pdata
->rmi4_mod_info
.manufacturer_id
= std_queries
[0];
828 pdata
->rmi4_mod_info
.product_props
= std_queries
[1];
829 pdata
->rmi4_mod_info
.product_info
[0] = std_queries
[2];
830 pdata
->rmi4_mod_info
.product_info
[1] = std_queries
[3];
831 /* year - 2001-2032 */
832 pdata
->rmi4_mod_info
.date_code
[0] = std_queries
[4] & MASK_5BIT
;
834 pdata
->rmi4_mod_info
.date_code
[1] = std_queries
[5] & MASK_4BIT
;
836 pdata
->rmi4_mod_info
.date_code
[2] = std_queries
[6] & MASK_5BIT
;
837 pdata
->rmi4_mod_info
.tester_id
= ((std_queries
[7] & MASK_7BIT
) << 8) |
838 (std_queries
[8] & MASK_7BIT
);
839 pdata
->rmi4_mod_info
.serial_number
=
840 ((std_queries
[9] & MASK_7BIT
) << 8) |
841 (std_queries
[10] & MASK_7BIT
);
842 memcpy(pdata
->rmi4_mod_info
.product_id_string
, &std_queries
[11], 10);
844 /* Check if this is a Synaptics device - report if not. */
845 if (pdata
->rmi4_mod_info
.manufacturer_id
!= 1)
846 dev_err(&client
->dev
, "%s: non-Synaptics mfg id:%d\n",
847 __func__
, pdata
->rmi4_mod_info
.manufacturer_id
);
849 list_for_each_entry(rfi
, &pdata
->rmi4_mod_info
.support_fn_list
, link
)
850 data_sources
+= rfi
->num_of_data_sources
;
852 rmi
= &(pdata
->rmi4_mod_info
);
853 list_for_each_entry(rfi
, &rmi
->support_fn_list
, link
) {
854 if (rfi
->num_of_data_sources
) {
855 if (rfi
->fn_number
==
856 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM
) {
857 retval
= synpatics_rmi4_touchpad_config
862 dev_err(&client
->dev
,
863 "%s:fn_number not supported\n",
866 * Turn on interrupts for this
867 * function's data sources.
869 ctrl_offset
= pdata
->fn01_ctrl_base_addr
+ 1 +
870 rfi
->index_to_intr_reg
;
871 retval
= synaptics_rmi4_i2c_byte_write(pdata
,
883 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
884 * @i2c: i2c client structure pointer
885 * @id:i2c device id pointer
887 * This function will allocate and initialize the instance
888 * data and request the irq and set the instance data as the clients
889 * platform data then register the physical driver which will do a scan of
890 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
891 * have data sources associated with them.
893 static int __devinit synaptics_rmi4_probe
894 (struct i2c_client
*client
, const struct i2c_device_id
*dev_id
)
897 unsigned char intr_status
[4];
898 struct synaptics_rmi4_data
*rmi4_data
;
899 const struct synaptics_rmi4_platform_data
*platformdata
=
900 client
->dev
.platform_data
;
902 if (!i2c_check_functionality(client
->adapter
,
903 I2C_FUNC_SMBUS_BYTE_DATA
)) {
904 dev_err(&client
->dev
, "i2c smbus byte data not supported\n");
909 dev_err(&client
->dev
, "%s: no platform data\n", __func__
);
913 /* Allocate and initialize the instance data for this client */
914 rmi4_data
= kzalloc(sizeof(struct synaptics_rmi4_data
) * 2,
917 dev_err(&client
->dev
, "%s: no memory allocated\n", __func__
);
921 rmi4_data
->input_dev
= input_allocate_device();
922 if (rmi4_data
->input_dev
== NULL
) {
923 dev_err(&client
->dev
, "%s:input device alloc failed\n",
929 if (platformdata
->regulator_en
) {
930 rmi4_data
->regulator
= regulator_get(&client
->dev
, "vdd");
931 if (IS_ERR(rmi4_data
->regulator
)) {
932 dev_err(&client
->dev
, "%s:get regulator failed\n",
934 retval
= PTR_ERR(rmi4_data
->regulator
);
937 regulator_enable(rmi4_data
->regulator
);
940 init_waitqueue_head(&rmi4_data
->wait
);
942 * Copy i2c_client pointer into RTID's i2c_client pointer for
943 * later use in rmi4_read, rmi4_write, etc.
945 rmi4_data
->i2c_client
= client
;
946 /* So we set the page correctly the first time */
947 rmi4_data
->current_page
= MASK_16BIT
;
948 rmi4_data
->board
= platformdata
;
949 rmi4_data
->touch_stopped
= false;
951 /* init the mutexes for maintain the lists */
952 mutex_init(&(rmi4_data
->fn_list_mutex
));
953 mutex_init(&(rmi4_data
->rmi4_page_mutex
));
956 * Register physical driver - this will call the detect function that
957 * will then scan the device and determine the supported
960 retval
= synaptics_rmi4_i2c_query_device(rmi4_data
);
962 dev_err(&client
->dev
, "%s: rmi4 query device failed\n",
967 /* Store the instance data in the i2c_client */
968 i2c_set_clientdata(client
, rmi4_data
);
970 /*initialize the input device parameters */
971 rmi4_data
->input_dev
->name
= DRIVER_NAME
;
972 rmi4_data
->input_dev
->phys
= "Synaptics_Clearpad";
973 rmi4_data
->input_dev
->id
.bustype
= BUS_I2C
;
974 rmi4_data
->input_dev
->dev
.parent
= &client
->dev
;
975 input_set_drvdata(rmi4_data
->input_dev
, rmi4_data
);
977 /* Initialize the function handlers for rmi4 */
978 set_bit(EV_SYN
, rmi4_data
->input_dev
->evbit
);
979 set_bit(EV_KEY
, rmi4_data
->input_dev
->evbit
);
980 set_bit(EV_ABS
, rmi4_data
->input_dev
->evbit
);
982 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_POSITION_X
, 0,
983 rmi4_data
->sensor_max_x
, 0, 0);
984 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_POSITION_Y
, 0,
985 rmi4_data
->sensor_max_y
, 0, 0);
986 input_set_abs_params(rmi4_data
->input_dev
, ABS_MT_TOUCH_MAJOR
, 0,
987 MAX_TOUCH_MAJOR
, 0, 0);
989 /* Clear interrupts */
990 synaptics_rmi4_i2c_block_read(rmi4_data
,
991 rmi4_data
->fn01_data_base_addr
+ 1, intr_status
,
992 rmi4_data
->number_of_interrupt_register
);
993 retval
= request_threaded_irq(platformdata
->irq_number
, NULL
,
995 platformdata
->irq_type
,
996 DRIVER_NAME
, rmi4_data
);
998 dev_err(&client
->dev
, "%s:Unable to get attn irq %d\n",
999 __func__
, platformdata
->irq_number
);
1003 retval
= input_register_device(rmi4_data
->input_dev
);
1005 dev_err(&client
->dev
, "%s:input register failed\n", __func__
);
1012 free_irq(platformdata
->irq_number
, rmi4_data
);
1014 if (platformdata
->regulator_en
) {
1015 regulator_disable(rmi4_data
->regulator
);
1016 regulator_put(rmi4_data
->regulator
);
1019 input_free_device(rmi4_data
->input_dev
);
1020 rmi4_data
->input_dev
= NULL
;
1027 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1028 * @client: i2c client structure pointer
1030 * This funtion uses to remove the i2c-client
1031 * touchscreen driver and returns integer.
1033 static int __devexit
synaptics_rmi4_remove(struct i2c_client
*client
)
1035 struct synaptics_rmi4_data
*rmi4_data
= i2c_get_clientdata(client
);
1036 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1038 rmi4_data
->touch_stopped
= true;
1039 wake_up(&rmi4_data
->wait
);
1040 free_irq(pdata
->irq_number
, rmi4_data
);
1041 input_unregister_device(rmi4_data
->input_dev
);
1042 if (pdata
->regulator_en
) {
1043 regulator_disable(rmi4_data
->regulator
);
1044 regulator_put(rmi4_data
->regulator
);
1053 * synaptics_rmi4_suspend() - suspend the touch screen controller
1054 * @dev: pointer to device structure
1056 * This funtion is used to suspend the
1057 * touch panel controller and returns integer
1059 static int synaptics_rmi4_suspend(struct device
*dev
)
1061 /* Touch sleep mode */
1063 unsigned char intr_status
;
1064 struct synaptics_rmi4_data
*rmi4_data
= dev_get_drvdata(dev
);
1065 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1067 rmi4_data
->touch_stopped
= true;
1068 disable_irq(pdata
->irq_number
);
1070 retval
= synaptics_rmi4_i2c_block_read(rmi4_data
,
1071 rmi4_data
->fn01_data_base_addr
+ 1,
1073 rmi4_data
->number_of_interrupt_register
);
1077 retval
= synaptics_rmi4_i2c_byte_write(rmi4_data
,
1078 rmi4_data
->fn01_ctrl_base_addr
+ 1,
1079 (intr_status
& ~TOUCHPAD_CTRL_INTR
));
1083 if (pdata
->regulator_en
)
1084 regulator_disable(rmi4_data
->regulator
);
1089 * synaptics_rmi4_resume() - resume the touch screen controller
1090 * @dev: pointer to device structure
1092 * This funtion is used to resume the touch panel
1093 * controller and returns integer.
1095 static int synaptics_rmi4_resume(struct device
*dev
)
1098 unsigned char intr_status
;
1099 struct synaptics_rmi4_data
*rmi4_data
= dev_get_drvdata(dev
);
1100 const struct synaptics_rmi4_platform_data
*pdata
= rmi4_data
->board
;
1102 if (pdata
->regulator_en
)
1103 regulator_enable(rmi4_data
->regulator
);
1105 enable_irq(pdata
->irq_number
);
1106 rmi4_data
->touch_stopped
= false;
1108 retval
= synaptics_rmi4_i2c_block_read(rmi4_data
,
1109 rmi4_data
->fn01_data_base_addr
+ 1,
1111 rmi4_data
->number_of_interrupt_register
);
1115 retval
= synaptics_rmi4_i2c_byte_write(rmi4_data
,
1116 rmi4_data
->fn01_ctrl_base_addr
+ 1,
1117 (intr_status
| TOUCHPAD_CTRL_INTR
));
1124 static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops
= {
1125 .suspend
= synaptics_rmi4_suspend
,
1126 .resume
= synaptics_rmi4_resume
,
1130 static const struct i2c_device_id synaptics_rmi4_id_table
[] = {
1134 MODULE_DEVICE_TABLE(i2c
, synaptics_rmi4_id_table
);
1136 static struct i2c_driver synaptics_rmi4_driver
= {
1138 .name
= DRIVER_NAME
,
1139 .owner
= THIS_MODULE
,
1141 .pm
= &synaptics_rmi4_dev_pm_ops
,
1144 .probe
= synaptics_rmi4_probe
,
1145 .remove
= __devexit_p(synaptics_rmi4_remove
),
1146 .id_table
= synaptics_rmi4_id_table
,
1149 * synaptics_rmi4_init() - Initialize the touchscreen driver
1151 * This funtion uses to initializes the synaptics
1152 * touchscreen driver and returns integer.
1154 static int __init
synaptics_rmi4_init(void)
1156 return i2c_add_driver(&synaptics_rmi4_driver
);
1159 * synaptics_rmi4_exit() - De-initialize the touchscreen driver
1161 * This funtion uses to de-initialize the synaptics
1162 * touchscreen driver and returns none.
1164 static void __exit
synaptics_rmi4_exit(void)
1166 i2c_del_driver(&synaptics_rmi4_driver
);
1170 module_init(synaptics_rmi4_init
);
1171 module_exit(synaptics_rmi4_exit
);
1173 MODULE_LICENSE("GPL v2");
1174 MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
1175 MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
1176 MODULE_ALIAS("i2c:synaptics_rmi4_ts");