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/module.h>
34 #include "synaptics_i2c_rmi4.h"
36 /* TODO: for multiple device support will need a per-device mutex */
37 #define DRIVER_NAME "synaptics_rmi4_i2c"
39 #define MAX_ERROR_REPORT 6
40 #define MAX_TOUCH_MAJOR 15
41 #define MAX_RETRY_COUNT 5
42 #define STD_QUERY_LEN 21
44 #define DATA_BUF_LEN 32
49 #define HAS_PALMDETECT 0x01
50 #define HAS_ROTATE 0x02
51 #define HAS_TAPANDHOLD 0x02
52 #define HAS_DOUBLETAP 0x04
53 #define HAS_EARLYTAP 0x08
54 #define HAS_RELEASE 0x08
55 #define HAS_FLICK 0x10
56 #define HAS_PRESS 0x20
57 #define HAS_PINCH 0x40
59 #define MASK_16BIT 0xFFFF
60 #define MASK_8BIT 0xFF
61 #define MASK_7BIT 0x7F
62 #define MASK_5BIT 0x1F
63 #define MASK_4BIT 0x0F
64 #define MASK_3BIT 0x07
65 #define MASK_2BIT 0x03
66 #define TOUCHPAD_CTRL_INTR 0x8
67 #define PDT_START_SCAN_LOCATION (0x00E9)
68 #define PDT_END_SCAN_LOCATION (0x000A)
69 #define PDT_ENTRY_SIZE (0x0006)
70 #define RMI4_NUMBER_OF_MAX_FINGERS (8)
71 #define SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM (0x11)
72 #define SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM (0x01)
75 * struct synaptics_rmi4_fn_desc - contains the function descriptor information
76 * @query_base_addr: base address for query
77 * @cmd_base_addr: base address for command
78 * @ctrl_base_addr: base address for control
79 * @data_base_addr: base address for data
80 * @intr_src_count: count for the interrupt source
81 * @fn_number: function number
83 * This structure is used to gives the function descriptor information
84 * of the particular functionality.
86 struct synaptics_rmi4_fn_desc {
87 unsigned char query_base_addr;
88 unsigned char cmd_base_addr;
89 unsigned char ctrl_base_addr;
90 unsigned char data_base_addr;
91 unsigned char intr_src_count;
92 unsigned char fn_number;
96 * struct synaptics_rmi4_fn - contains the function information
97 * @fn_number: function number
98 * @num_of_data_sources: number of data sources
99 * @num_of_data_points: number of fingers touched
100 * @size_of_data_register_block: data register block size
101 * @index_to_intr_reg: index for interrupt register
102 * @intr_mask: interrupt mask value
103 * @fn_desc: variable for function descriptor structure
104 * @link: linked list for function descriptors
106 * This structure gives information about the number of data sources and
107 * the number of data registers associated with the function.
109 struct synaptics_rmi4_fn {
110 unsigned char fn_number;
111 unsigned char num_of_data_sources;
112 unsigned char num_of_data_points;
113 unsigned char size_of_data_register_block;
114 unsigned char index_to_intr_reg;
115 unsigned char intr_mask;
116 struct synaptics_rmi4_fn_desc fn_desc;
117 struct list_head link;
121 * struct synaptics_rmi4_device_info - contains the rmi4 device information
122 * @version_major: protocol major version number
123 * @version_minor: protocol minor version number
124 * @manufacturer_id: manufacturer identification byte
125 * @product_props: product properties information
126 * @product_info: product info array
127 * @date_code: device manufacture date
128 * @tester_id: tester id array
129 * @serial_number: serial number for that device
130 * @product_id_string: product id for the device
131 * @support_fn_list: linked list for device information
133 * This structure gives information about the number of data sources and
134 * the number of data registers associated with the function.
136 struct synaptics_rmi4_device_info {
137 unsigned int version_major;
138 unsigned int version_minor;
139 unsigned char manufacturer_id;
140 unsigned char product_props;
141 unsigned char product_info[2];
142 unsigned char date_code[3];
143 unsigned short tester_id;
144 unsigned short serial_number;
145 unsigned char product_id_string[11];
146 struct list_head support_fn_list;
150 * struct synaptics_rmi4_data - contains the rmi4 device data
151 * @rmi4_mod_info: structure variable for rmi4 device info
152 * @input_dev: pointer for input device
153 * @i2c_client: pointer for i2c client
154 * @board: constant pointer for touch platform data
155 * @fn_list_mutex: mutex for function list
156 * @rmi4_page_mutex: mutex for rmi4 page
157 * @current_page: variable for integer
158 * @number_of_interrupt_register: interrupt registers count
159 * @fn01_ctrl_base_addr: control base address for fn01
160 * @fn01_query_base_addr: query base address for fn01
161 * @fn01_data_base_addr: data base address for fn01
162 * @sensor_max_x: sensor maximum x value
163 * @sensor_max_y: sensor maximum y value
164 * @regulator: pointer to the regulator structure
165 * @wait: wait queue structure variable
166 * @touch_stopped: flag to stop the thread function
168 * This structure gives the device data information.
170 struct synaptics_rmi4_data {
171 struct synaptics_rmi4_device_info rmi4_mod_info;
172 struct input_dev *input_dev;
173 struct i2c_client *i2c_client;
174 const struct synaptics_rmi4_platform_data *board;
175 struct mutex fn_list_mutex;
176 struct mutex rmi4_page_mutex;
178 unsigned int number_of_interrupt_register;
179 unsigned short fn01_ctrl_base_addr;
180 unsigned short fn01_query_base_addr;
181 unsigned short fn01_data_base_addr;
184 struct regulator *regulator;
185 wait_queue_head_t wait;
190 * synaptics_rmi4_set_page() - sets the page
191 * @pdata: pointer to synaptics_rmi4_data structure
192 * @address: set the address of the page
194 * This function is used to set the page and returns integer.
196 static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *pdata,
197 unsigned int address)
199 unsigned char txbuf[PAGE_LEN];
202 struct i2c_client *i2c = pdata->i2c_client;
204 page = ((address >> 8) & MASK_8BIT);
205 if (page != pdata->current_page) {
206 txbuf[0] = MASK_8BIT;
208 retval = i2c_master_send(i2c, txbuf, PAGE_LEN);
209 if (retval != PAGE_LEN)
210 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
212 pdata->current_page = page;
218 * synaptics_rmi4_i2c_block_read() - read the block of data
219 * @pdata: pointer to synaptics_rmi4_data structure
220 * @address: read the block of data from this offset
221 * @valp: pointer to a buffer containing the data to be read
222 * @size: number of bytes to read
224 * This function is to read the block of data and returns integer.
226 static int synaptics_rmi4_i2c_block_read(struct synaptics_rmi4_data *pdata,
227 unsigned short address,
228 unsigned char *valp, int size)
233 struct i2c_client *i2c = pdata->i2c_client;
235 mutex_lock(&(pdata->rmi4_page_mutex));
236 retval = synaptics_rmi4_set_page(pdata, address);
237 if (retval != PAGE_LEN)
239 index = address & MASK_8BIT;
241 retval = i2c_smbus_read_i2c_block_data(i2c, index, size, valp);
242 if (retval != size) {
243 if (++retry_count == MAX_RETRY_COUNT)
245 "%s:address 0x%04x size %d failed:%d\n",
246 __func__, address, size, retval);
248 synaptics_rmi4_set_page(pdata, address);
253 mutex_unlock(&(pdata->rmi4_page_mutex));
258 * synaptics_rmi4_i2c_byte_write() - write the single byte data
259 * @pdata: pointer to synaptics_rmi4_data structure
260 * @address: write the block of data from this offset
261 * @data: data to be write
263 * This function is to write the single byte data and returns integer.
265 static int synaptics_rmi4_i2c_byte_write(struct synaptics_rmi4_data *pdata,
266 unsigned short address,
269 unsigned char txbuf[2];
271 struct i2c_client *i2c = pdata->i2c_client;
273 /* Can't have anyone else changing the page behind our backs */
274 mutex_lock(&(pdata->rmi4_page_mutex));
276 retval = synaptics_rmi4_set_page(pdata, address);
277 if (retval != PAGE_LEN)
279 txbuf[0] = address & MASK_8BIT;
281 retval = i2c_master_send(pdata->i2c_client, txbuf, 2);
282 /* Add in retry on writes only in certain error return values */
284 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
289 mutex_unlock(&(pdata->rmi4_page_mutex));
294 * synpatics_rmi4_touchpad_report() - reports for the rmi4 touchpad device
295 * @pdata: pointer to synaptics_rmi4_data structure
296 * @rfi: pointer to synaptics_rmi4_fn structure
298 * This function calls to reports for the rmi4 touchpad device
300 static int synpatics_rmi4_touchpad_report(struct synaptics_rmi4_data *pdata,
301 struct synaptics_rmi4_fn *rfi)
303 /* number of touch points - fingers down in this case */
306 int fingers_supported;
307 int finger_registers;
312 unsigned short data_base_addr;
313 unsigned short data_offset;
314 unsigned char data_reg_blk_size;
315 unsigned char values[2];
316 unsigned char data[DATA_LEN];
317 int x[RMI4_NUMBER_OF_MAX_FINGERS];
318 int y[RMI4_NUMBER_OF_MAX_FINGERS];
319 int wx[RMI4_NUMBER_OF_MAX_FINGERS];
320 int wy[RMI4_NUMBER_OF_MAX_FINGERS];
321 struct i2c_client *client = pdata->i2c_client;
323 /* get 2D sensor finger data */
325 * First get the finger status field - the size of the finger status
326 * field is determined by the number of finger supporte - 2 bits per
327 * finger, so the number of registers to read is:
328 * registerCount = ceil(numberOfFingers/4).
329 * Read the required number of registers and check each 2 bit field to
330 * determine if a finger is down:
331 * 00 = finger not present,
332 * 01 = finger present and data accurate,
333 * 10 = finger present but data may not be accurate,
334 * 11 = reserved for product use.
336 fingers_supported = rfi->num_of_data_points;
337 finger_registers = (fingers_supported + 3)/4;
338 data_base_addr = rfi->fn_desc.data_base_addr;
339 retval = synaptics_rmi4_i2c_block_read(pdata, data_base_addr, values,
341 if (retval != finger_registers) {
342 dev_err(&client->dev, "%s:read status registers failed\n",
347 * For each finger present, read the proper number of registers
348 * to get absolute data.
350 data_reg_blk_size = rfi->size_of_data_register_block;
351 for (finger = 0; finger < fingers_supported; finger++) {
352 /* determine which data byte the finger status is in */
354 /* bit shift to get finger's status */
355 finger_shift = (finger % 4) * 2;
356 finger_status = (values[reg] >> finger_shift) & 3;
358 * if finger status indicates a finger is present then
359 * read the finger data and report it
361 if (finger_status == 1 || finger_status == 2) {
362 /* Read the finger data */
363 data_offset = data_base_addr +
364 ((finger * data_reg_blk_size) +
366 retval = synaptics_rmi4_i2c_block_read(pdata,
369 if (retval != data_reg_blk_size) {
370 printk(KERN_ERR "%s:read data failed\n",
375 (data[0] << 4) | (data[2] & MASK_4BIT);
378 ((data[2] >> 4) & MASK_4BIT);
380 (data[3] >> 4) & MASK_4BIT;
382 (data[3] & MASK_4BIT);
384 if (pdata->board->x_flip)
386 pdata->sensor_max_x -
388 if (pdata->board->y_flip)
390 pdata->sensor_max_y -
393 /* number of active touch points */
398 /* report to input subsystem */
400 for (finger = 0; finger < touch_count; finger++) {
401 input_report_abs(pdata->input_dev, ABS_MT_TOUCH_MAJOR,
402 max(wx[finger] , wy[finger]));
403 input_report_abs(pdata->input_dev, ABS_MT_POSITION_X,
405 input_report_abs(pdata->input_dev, ABS_MT_POSITION_Y,
407 input_mt_sync(pdata->input_dev);
410 input_mt_sync(pdata->input_dev);
412 /* sync after groups of events */
413 input_sync(pdata->input_dev);
414 /* return the number of touch points */
419 * synaptics_rmi4_report_device() - reports the rmi4 device
420 * @pdata: pointer to synaptics_rmi4_data structure
421 * @rfi: pointer to synaptics_rmi4_fn
423 * This function is used to call the report function of the rmi4 device.
425 static int synaptics_rmi4_report_device(struct synaptics_rmi4_data *pdata,
426 struct synaptics_rmi4_fn *rfi)
429 struct i2c_client *client = pdata->i2c_client;
430 static int num_error_reports;
431 if (rfi->fn_number != SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
433 if (num_error_reports < MAX_ERROR_REPORT)
434 dev_err(&client->dev, "%s:report not supported\n",
437 touch = synpatics_rmi4_touchpad_report(pdata, rfi);
441 * synaptics_rmi4_sensor_report() - reports to input subsystem
442 * @pdata: pointer to synaptics_rmi4_data structure
444 * This function is used to reads in all data sources and reports
445 * them to the input subsystem.
447 static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *pdata)
449 unsigned char intr_status[4];
450 /* number of touch points - fingers or buttons */
453 struct synaptics_rmi4_fn *rfi;
454 struct synaptics_rmi4_device_info *rmi;
455 struct i2c_client *client = pdata->i2c_client;
458 * Get the interrupt status from the function $01
459 * control register+1 to find which source(s) were interrupting
460 * so we can read the data from the source(s) (2D sensor, buttons..)
462 retval = synaptics_rmi4_i2c_block_read(pdata,
463 pdata->fn01_data_base_addr + 1,
465 pdata->number_of_interrupt_register);
466 if (retval != pdata->number_of_interrupt_register) {
467 dev_err(&client->dev,
468 "could not read interrupt status registers\n");
472 * check each function that has data sources and if the interrupt for
473 * that triggered then call that RMI4 functions report() function to
474 * gather data and report it to the input subsystem
476 rmi = &(pdata->rmi4_mod_info);
477 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
478 if (rfi->num_of_data_sources) {
479 if (intr_status[rfi->index_to_intr_reg] &
481 touch = synaptics_rmi4_report_device(pdata,
485 /* return the number of touch points */
490 * synaptics_rmi4_irq() - thread function for rmi4 attention line
492 * @data: void pointer
494 * This function is interrupt thread function. It just notifies the
495 * application layer that attention is required.
497 static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
499 struct synaptics_rmi4_data *pdata = data;
502 touch_count = synaptics_rmi4_sensor_report(pdata);
504 wait_event_timeout(pdata->wait, pdata->touch_stopped,
505 msecs_to_jiffies(1));
508 } while (!pdata->touch_stopped);
513 * synpatics_rmi4_touchpad_detect() - detects the rmi4 touchpad device
514 * @pdata: pointer to synaptics_rmi4_data structure
515 * @rfi: pointer to synaptics_rmi4_fn structure
516 * @fd: pointer to synaptics_rmi4_fn_desc structure
517 * @interruptcount: count the number of interrupts
519 * This function calls to detects the rmi4 touchpad device
521 static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data *pdata,
522 struct synaptics_rmi4_fn *rfi,
523 struct synaptics_rmi4_fn_desc *fd,
524 unsigned int interruptcount)
526 unsigned char queries[QUERY_LEN];
527 unsigned short intr_offset;
528 unsigned char abs_data_size;
529 unsigned char abs_data_blk_size;
530 unsigned char egr_0, egr_1;
531 unsigned int all_data_blk_size;
532 int has_pinch, has_flick, has_tap;
533 int has_tapandhold, has_doubletap;
534 int has_earlytap, has_press;
535 int has_palmdetect, has_rotate;
539 struct i2c_client *client = pdata->i2c_client;
541 rfi->fn_desc.query_base_addr = fd->query_base_addr;
542 rfi->fn_desc.data_base_addr = fd->data_base_addr;
543 rfi->fn_desc.intr_src_count = fd->intr_src_count;
544 rfi->fn_desc.fn_number = fd->fn_number;
545 rfi->fn_number = fd->fn_number;
546 rfi->num_of_data_sources = fd->intr_src_count;
547 rfi->fn_desc.ctrl_base_addr = fd->ctrl_base_addr;
548 rfi->fn_desc.cmd_base_addr = fd->cmd_base_addr;
551 * need to get number of fingers supported, data size, etc.
552 * to be used when getting data since the number of registers to
553 * read depends on the number of fingers supported and data size.
555 retval = synaptics_rmi4_i2c_block_read(pdata, fd->query_base_addr,
558 if (retval != sizeof(queries)) {
559 dev_err(&client->dev, "%s:read function query registers\n",
564 * 2D data sources have only 3 bits for the number of fingers
565 * supported - so the encoding is a bit weird.
567 if ((queries[1] & MASK_3BIT) <= 4)
568 /* add 1 since zero based */
569 rfi->num_of_data_points = (queries[1] & MASK_3BIT) + 1;
572 * a value of 5 is up to 10 fingers - 6 and 7 are reserved
573 * (shouldn't get these i int retval;n a normal 2D source).
575 if ((queries[1] & MASK_3BIT) == 5)
576 rfi->num_of_data_points = 10;
578 /* Need to get interrupt info for handling interrupts */
579 rfi->index_to_intr_reg = (interruptcount + 7)/8;
580 if (rfi->index_to_intr_reg != 0)
581 rfi->index_to_intr_reg -= 1;
583 * loop through interrupts for each source in fn $11
584 * and or in a bit to the interrupt mask for each.
586 intr_offset = interruptcount % 8;
588 for (i = intr_offset;
589 i < ((fd->intr_src_count & MASK_3BIT) + intr_offset); i++)
590 rfi->intr_mask |= 1 << i;
592 /* Size of just the absolute data for one finger */
593 abs_data_size = queries[5] & MASK_2BIT;
594 /* One each for X and Y, one for LSB for X & Y, one for W, one for Z */
595 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
596 rfi->size_of_data_register_block = abs_data_blk_size;
599 * need to determine the size of data to read - this depends on
600 * conditions such as whether Relative data is reported and if Gesture
607 * Get info about what EGR data is supported, whether it has
608 * Relative data supported, etc.
610 has_pinch = egr_0 & HAS_PINCH;
611 has_flick = egr_0 & HAS_FLICK;
612 has_tap = egr_0 & HAS_TAP;
613 has_earlytap = egr_0 & HAS_EARLYTAP;
614 has_press = egr_0 & HAS_PRESS;
615 has_rotate = egr_1 & HAS_ROTATE;
616 has_rel = queries[1] & HAS_RELEASE;
617 has_tapandhold = egr_0 & HAS_TAPANDHOLD;
618 has_doubletap = egr_0 & HAS_DOUBLETAP;
619 has_palmdetect = egr_1 & HAS_PALMDETECT;
622 * Size of all data including finger status, absolute data for each
623 * finger, relative data and EGR data
626 /* finger status, four fingers per register */
627 ((rfi->num_of_data_points + 3) / 4) +
628 /* absolute data, per finger times number of fingers */
629 (abs_data_blk_size * rfi->num_of_data_points) +
631 * two relative registers (if relative is being reported)
635 * F11_2D_data8 is only present if the egr_0
636 * register is non-zero.
640 * F11_2D_data9 is only present if either egr_0 or
641 * egr_1 registers are non-zero.
645 * F11_2D_data10 is only present if EGR_PINCH or EGR_FLICK of
646 * egr_0 reports as 1.
648 !!(has_pinch | has_flick) +
650 * F11_2D_data11 and F11_2D_data12 are only present if
651 * EGR_FLICK of egr_0 reports as 1.
658 * synpatics_rmi4_touchpad_config() - confiures the rmi4 touchpad device
659 * @pdata: pointer to synaptics_rmi4_data structure
660 * @rfi: pointer to synaptics_rmi4_fn structure
662 * This function calls to confiures the rmi4 touchpad device
664 int synpatics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
665 struct synaptics_rmi4_fn *rfi)
668 * For the data source - print info and do any
669 * source specific configuration.
671 unsigned char data[BUF_LEN];
673 struct i2c_client *client = pdata->i2c_client;
675 /* Get and print some info about the data source... */
676 /* To Query 2D devices we need to read from the address obtained
677 * from the function descriptor stored in the RMI function info.
679 retval = synaptics_rmi4_i2c_block_read(pdata,
680 rfi->fn_desc.query_base_addr,
682 if (retval != QUERY_LEN)
683 dev_err(&client->dev, "%s:read query registers failed\n",
686 retval = synaptics_rmi4_i2c_block_read(pdata,
687 rfi->fn_desc.ctrl_base_addr,
689 if (retval != DATA_BUF_LEN) {
690 dev_err(&client->dev,
691 "%s:read control registers failed\n",
695 /* Store these for use later*/
696 pdata->sensor_max_x = ((data[6] & MASK_8BIT) << 0) |
697 ((data[7] & MASK_4BIT) << 8);
698 pdata->sensor_max_y = ((data[8] & MASK_5BIT) << 0) |
699 ((data[9] & MASK_4BIT) << 8);
705 * synaptics_rmi4_i2c_query_device() - query the rmi4 device
706 * @pdata: pointer to synaptics_rmi4_data structure
708 * This function is used to query the rmi4 device.
710 static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
714 unsigned char std_queries[STD_QUERY_LEN];
715 unsigned char intr_count = 0;
716 int data_sources = 0;
717 unsigned int ctrl_offset;
718 struct synaptics_rmi4_fn *rfi;
719 struct synaptics_rmi4_fn_desc rmi_fd;
720 struct synaptics_rmi4_device_info *rmi;
721 struct i2c_client *client = pdata->i2c_client;
724 * init the physical drivers RMI module
725 * info list of functions
727 INIT_LIST_HEAD(&pdata->rmi4_mod_info.support_fn_list);
730 * Read the Page Descriptor Table to determine what functions
733 for (i = PDT_START_SCAN_LOCATION; i > PDT_END_SCAN_LOCATION;
734 i -= PDT_ENTRY_SIZE) {
735 retval = synaptics_rmi4_i2c_block_read(pdata, i,
736 (unsigned char *)&rmi_fd,
738 if (retval != sizeof(rmi_fd)) {
739 /* failed to read next PDT entry */
740 dev_err(&client->dev, "%s: read error\n", __func__);
744 if (rmi_fd.fn_number) {
745 switch (rmi_fd.fn_number & MASK_8BIT) {
746 case SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM:
747 pdata->fn01_query_base_addr =
748 rmi_fd.query_base_addr;
749 pdata->fn01_ctrl_base_addr =
750 rmi_fd.ctrl_base_addr;
751 pdata->fn01_data_base_addr =
752 rmi_fd.data_base_addr;
754 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM:
755 if (rmi_fd.intr_src_count) {
756 rfi = kmalloc(sizeof(*rfi),
759 dev_err(&client->dev,
760 "%s:kmalloc failed\n",
764 retval = synpatics_rmi4_touchpad_detect
775 /* interrupt count for next iteration */
776 intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
778 * We only want to add functions to the list
779 * that have data associated with them.
781 if (rfi && rmi_fd.intr_src_count) {
782 /* link this function info to the RMI module */
783 mutex_lock(&(pdata->fn_list_mutex));
784 list_add_tail(&rfi->link,
785 &pdata->rmi4_mod_info.support_fn_list);
786 mutex_unlock(&(pdata->fn_list_mutex));
790 * A zero in the function number
791 * signals the end of the PDT
793 dev_dbg(&client->dev,
794 "%s:end of PDT\n", __func__);
799 * calculate the interrupt register count - used in the
800 * ISR to read the correct number of interrupt registers
802 pdata->number_of_interrupt_register = (intr_count + 7) / 8;
804 * Function $01 will be used to query the product properties,
805 * and product ID so we had to read the PDT above first to get
806 * the Fn $01 query address and prior to filling in the product
807 * info. NOTE: Even an unflashed device will still have FN $01.
810 /* Load up the standard queries and get the RMI4 module info */
811 retval = synaptics_rmi4_i2c_block_read(pdata,
812 pdata->fn01_query_base_addr,
814 sizeof(std_queries));
815 if (retval != sizeof(std_queries)) {
816 dev_err(&client->dev, "%s:Failed reading queries\n",
821 /* Currently supported RMI version is 4.0 */
822 pdata->rmi4_mod_info.version_major = 4;
823 pdata->rmi4_mod_info.version_minor = 0;
825 * get manufacturer id, product_props, product info,
826 * date code, tester id, serial num and product id (name)
828 pdata->rmi4_mod_info.manufacturer_id = std_queries[0];
829 pdata->rmi4_mod_info.product_props = std_queries[1];
830 pdata->rmi4_mod_info.product_info[0] = std_queries[2];
831 pdata->rmi4_mod_info.product_info[1] = std_queries[3];
832 /* year - 2001-2032 */
833 pdata->rmi4_mod_info.date_code[0] = std_queries[4] & MASK_5BIT;
835 pdata->rmi4_mod_info.date_code[1] = std_queries[5] & MASK_4BIT;
837 pdata->rmi4_mod_info.date_code[2] = std_queries[6] & MASK_5BIT;
838 pdata->rmi4_mod_info.tester_id = ((std_queries[7] & MASK_7BIT) << 8) |
839 (std_queries[8] & MASK_7BIT);
840 pdata->rmi4_mod_info.serial_number =
841 ((std_queries[9] & MASK_7BIT) << 8) |
842 (std_queries[10] & MASK_7BIT);
843 memcpy(pdata->rmi4_mod_info.product_id_string, &std_queries[11], 10);
845 /* Check if this is a Synaptics device - report if not. */
846 if (pdata->rmi4_mod_info.manufacturer_id != 1)
847 dev_err(&client->dev, "%s: non-Synaptics mfg id:%d\n",
848 __func__, pdata->rmi4_mod_info.manufacturer_id);
850 list_for_each_entry(rfi, &pdata->rmi4_mod_info.support_fn_list, link)
851 data_sources += rfi->num_of_data_sources;
853 rmi = &(pdata->rmi4_mod_info);
854 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
855 if (rfi->num_of_data_sources) {
856 if (rfi->fn_number ==
857 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
858 retval = synpatics_rmi4_touchpad_config
863 dev_err(&client->dev,
864 "%s:fn_number not supported\n",
867 * Turn on interrupts for this
868 * function's data sources.
870 ctrl_offset = pdata->fn01_ctrl_base_addr + 1 +
871 rfi->index_to_intr_reg;
872 retval = synaptics_rmi4_i2c_byte_write(pdata,
884 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
885 * @i2c: i2c client structure pointer
886 * @id:i2c device id pointer
888 * This function will allocate and initialize the instance
889 * data and request the irq and set the instance data as the clients
890 * platform data then register the physical driver which will do a scan of
891 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
892 * have data sources associated with them.
894 static int __devinit synaptics_rmi4_probe
895 (struct i2c_client *client, const struct i2c_device_id *dev_id)
898 unsigned char intr_status[4];
899 struct synaptics_rmi4_data *rmi4_data;
900 const struct synaptics_rmi4_platform_data *platformdata =
901 client->dev.platform_data;
903 if (!i2c_check_functionality(client->adapter,
904 I2C_FUNC_SMBUS_BYTE_DATA)) {
905 dev_err(&client->dev, "i2c smbus byte data not supported\n");
910 dev_err(&client->dev, "%s: no platform data\n", __func__);
914 /* Allocate and initialize the instance data for this client */
915 rmi4_data = kzalloc(sizeof(struct synaptics_rmi4_data) * 2,
918 dev_err(&client->dev, "%s: no memory allocated\n", __func__);
922 rmi4_data->input_dev = input_allocate_device();
923 if (rmi4_data->input_dev == NULL) {
924 dev_err(&client->dev, "%s:input device alloc failed\n",
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);
935 goto err_get_regulator;
937 retval = regulator_enable(rmi4_data->regulator);
939 dev_err(&client->dev, "%s:regulator enable failed\n",
941 goto err_regulator_enable;
943 init_waitqueue_head(&rmi4_data->wait);
945 * Copy i2c_client pointer into RTID's i2c_client pointer for
946 * later use in rmi4_read, rmi4_write, etc.
948 rmi4_data->i2c_client = client;
949 /* So we set the page correctly the first time */
950 rmi4_data->current_page = MASK_16BIT;
951 rmi4_data->board = platformdata;
952 rmi4_data->touch_stopped = false;
954 /* init the mutexes for maintain the lists */
955 mutex_init(&(rmi4_data->fn_list_mutex));
956 mutex_init(&(rmi4_data->rmi4_page_mutex));
959 * Register physical driver - this will call the detect function that
960 * will then scan the device and determine the supported
963 retval = synaptics_rmi4_i2c_query_device(rmi4_data);
965 dev_err(&client->dev, "%s: rmi4 query device failed\n",
970 /* Store the instance data in the i2c_client */
971 i2c_set_clientdata(client, rmi4_data);
973 /*initialize the input device parameters */
974 rmi4_data->input_dev->name = DRIVER_NAME;
975 rmi4_data->input_dev->phys = "Synaptics_Clearpad";
976 rmi4_data->input_dev->id.bustype = BUS_I2C;
977 rmi4_data->input_dev->dev.parent = &client->dev;
978 input_set_drvdata(rmi4_data->input_dev, rmi4_data);
980 /* Initialize the function handlers for rmi4 */
981 set_bit(EV_SYN, rmi4_data->input_dev->evbit);
982 set_bit(EV_KEY, rmi4_data->input_dev->evbit);
983 set_bit(EV_ABS, rmi4_data->input_dev->evbit);
985 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_X, 0,
986 rmi4_data->sensor_max_x, 0, 0);
987 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_Y, 0,
988 rmi4_data->sensor_max_y, 0, 0);
989 input_set_abs_params(rmi4_data->input_dev, ABS_MT_TOUCH_MAJOR, 0,
990 MAX_TOUCH_MAJOR, 0, 0);
992 /* Clear interrupts */
993 synaptics_rmi4_i2c_block_read(rmi4_data,
994 rmi4_data->fn01_data_base_addr + 1, intr_status,
995 rmi4_data->number_of_interrupt_register);
996 retval = request_threaded_irq(platformdata->irq_number, NULL,
998 platformdata->irq_type,
999 DRIVER_NAME, rmi4_data);
1001 dev_err(&client->dev, "%s:Unable to get attn irq %d\n",
1002 __func__, platformdata->irq_number);
1006 retval = input_register_device(rmi4_data->input_dev);
1008 dev_err(&client->dev, "%s:input register failed\n", __func__);
1015 free_irq(platformdata->irq_number, rmi4_data);
1017 regulator_disable(rmi4_data->regulator);
1018 err_regulator_enable:
1019 regulator_put(rmi4_data->regulator);
1021 input_free_device(rmi4_data->input_dev);
1022 rmi4_data->input_dev = NULL;
1029 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1030 * @client: i2c client structure pointer
1032 * This function uses to remove the i2c-client
1033 * touchscreen driver and returns integer.
1035 static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
1037 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1038 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1040 rmi4_data->touch_stopped = true;
1041 wake_up(&rmi4_data->wait);
1042 free_irq(pdata->irq_number, rmi4_data);
1043 input_unregister_device(rmi4_data->input_dev);
1044 regulator_disable(rmi4_data->regulator);
1045 regulator_put(rmi4_data->regulator);
1053 * synaptics_rmi4_suspend() - suspend the touch screen controller
1054 * @dev: pointer to device structure
1056 * This function 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 regulator_disable(rmi4_data->regulator);
1088 * synaptics_rmi4_resume() - resume the touch screen controller
1089 * @dev: pointer to device structure
1091 * This function is used to resume the touch panel
1092 * controller and returns integer.
1094 static int synaptics_rmi4_resume(struct device *dev)
1097 unsigned char intr_status;
1098 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1099 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
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 function 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 function 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");