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 <linux/input/mt.h>
35 #include "synaptics_i2c_rmi4.h"
37 /* TODO: for multiple device support will need a per-device mutex */
38 #define DRIVER_NAME "synaptics_rmi4_i2c"
40 #define MAX_ERROR_REPORT 6
41 #define MAX_TOUCH_MAJOR 15
42 #define MAX_RETRY_COUNT 5
43 #define STD_QUERY_LEN 21
45 #define DATA_BUF_LEN 32
50 #define HAS_PALMDETECT 0x01
51 #define HAS_ROTATE 0x02
52 #define HAS_TAPANDHOLD 0x02
53 #define HAS_DOUBLETAP 0x04
54 #define HAS_EARLYTAP 0x08
55 #define HAS_RELEASE 0x08
56 #define HAS_FLICK 0x10
57 #define HAS_PRESS 0x20
58 #define HAS_PINCH 0x40
60 #define MASK_16BIT 0xFFFF
61 #define MASK_8BIT 0xFF
62 #define MASK_7BIT 0x7F
63 #define MASK_5BIT 0x1F
64 #define MASK_4BIT 0x0F
65 #define MASK_3BIT 0x07
66 #define MASK_2BIT 0x03
67 #define TOUCHPAD_CTRL_INTR 0x8
68 #define PDT_START_SCAN_LOCATION (0x00E9)
69 #define PDT_END_SCAN_LOCATION (0x000A)
70 #define PDT_ENTRY_SIZE (0x0006)
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
167 * @fingers_supported: maximum supported fingers
169 * This structure gives the device data information.
171 struct synaptics_rmi4_data {
172 struct synaptics_rmi4_device_info rmi4_mod_info;
173 struct input_dev *input_dev;
174 struct i2c_client *i2c_client;
175 const struct synaptics_rmi4_platform_data *board;
176 struct mutex fn_list_mutex;
177 struct mutex rmi4_page_mutex;
179 unsigned int number_of_interrupt_register;
180 unsigned short fn01_ctrl_base_addr;
181 unsigned short fn01_query_base_addr;
182 unsigned short fn01_data_base_addr;
185 struct regulator *regulator;
186 wait_queue_head_t wait;
188 unsigned char fingers_supported;
192 * synaptics_rmi4_set_page() - sets the page
193 * @pdata: pointer to synaptics_rmi4_data structure
194 * @address: set the address of the page
196 * This function is used to set the page and returns integer.
198 static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *pdata,
199 unsigned int address)
201 unsigned char txbuf[PAGE_LEN];
204 struct i2c_client *i2c = pdata->i2c_client;
206 page = ((address >> 8) & MASK_8BIT);
207 if (page != pdata->current_page) {
208 txbuf[0] = MASK_8BIT;
210 retval = i2c_master_send(i2c, txbuf, PAGE_LEN);
211 if (retval != PAGE_LEN)
212 dev_err(&i2c->dev, "failed:%d\n", retval);
214 pdata->current_page = page;
220 * synaptics_rmi4_i2c_block_read() - read the block of data
221 * @pdata: pointer to synaptics_rmi4_data structure
222 * @address: read the block of data from this offset
223 * @valp: pointer to a buffer containing the data to be read
224 * @size: number of bytes to read
226 * This function is to read the block of data and returns integer.
228 static int synaptics_rmi4_i2c_block_read(struct synaptics_rmi4_data *pdata,
229 unsigned short address,
230 unsigned char *valp, int size)
235 struct i2c_client *i2c = pdata->i2c_client;
237 mutex_lock(&(pdata->rmi4_page_mutex));
238 retval = synaptics_rmi4_set_page(pdata, address);
239 if (retval != PAGE_LEN)
241 index = address & MASK_8BIT;
243 retval = i2c_smbus_read_i2c_block_data(i2c, index, size, valp);
244 if (retval != size) {
245 if (++retry_count == MAX_RETRY_COUNT)
247 "%s:address 0x%04x size %d failed:%d\n",
248 __func__, address, size, retval);
250 synaptics_rmi4_set_page(pdata, address);
255 mutex_unlock(&(pdata->rmi4_page_mutex));
260 * synaptics_rmi4_i2c_byte_write() - write the single byte data
261 * @pdata: pointer to synaptics_rmi4_data structure
262 * @address: write the block of data from this offset
263 * @data: data to be write
265 * This function is to write the single byte data and returns integer.
267 static int synaptics_rmi4_i2c_byte_write(struct synaptics_rmi4_data *pdata,
268 unsigned short address,
271 unsigned char txbuf[2];
273 struct i2c_client *i2c = pdata->i2c_client;
275 /* Can't have anyone else changing the page behind our backs */
276 mutex_lock(&(pdata->rmi4_page_mutex));
278 retval = synaptics_rmi4_set_page(pdata, address);
279 if (retval != PAGE_LEN)
281 txbuf[0] = address & MASK_8BIT;
283 retval = i2c_master_send(pdata->i2c_client, txbuf, 2);
284 /* Add in retry on writes only in certain error return values */
286 dev_err(&i2c->dev, "failed:%d\n", retval);
291 mutex_unlock(&(pdata->rmi4_page_mutex));
296 * synpatics_rmi4_touchpad_report() - reports for the rmi4 touchpad device
297 * @pdata: pointer to synaptics_rmi4_data structure
298 * @rfi: pointer to synaptics_rmi4_fn structure
300 * This function calls to reports for the rmi4 touchpad device
302 static int synpatics_rmi4_touchpad_report(struct synaptics_rmi4_data *pdata,
303 struct synaptics_rmi4_fn *rfi)
305 /* number of touch points - fingers down in this case */
308 int finger_registers;
315 unsigned short data_base_addr;
316 unsigned short data_offset;
317 unsigned char data_reg_blk_size;
318 unsigned char values[2];
319 unsigned char data[DATA_LEN];
320 unsigned char fingers_supported = pdata->fingers_supported;
321 struct i2c_client *client = pdata->i2c_client;
322 struct input_dev *input_dev = pdata->input_dev;
324 /* get 2D sensor finger data */
326 * First get the finger status field - the size of the finger status
327 * field is determined by the number of finger supporte - 2 bits per
328 * finger, so the number of registers to read is:
329 * registerCount = ceil(numberOfFingers/4).
330 * Read the required number of registers and check each 2 bit field to
331 * determine if a finger is down:
332 * 00 = finger not present,
333 * 01 = finger present and data accurate,
334 * 10 = finger present but data may not be accurate,
335 * 11 = reserved for product use.
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 input_mt_slot(input_dev, finger);
362 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
366 /* Read the finger data */
367 data_offset = data_base_addr +
368 ((finger * data_reg_blk_size) +
370 retval = synaptics_rmi4_i2c_block_read(pdata,
373 if (retval != data_reg_blk_size) {
374 dev_err(&client->dev, "%s:read data failed\n",
378 x = (data[0] << 4) | (data[2] & MASK_4BIT);
379 y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
380 wy = (data[3] >> 4) & MASK_4BIT;
381 wx = (data[3] & MASK_4BIT);
383 if (pdata->board->x_flip)
384 x = pdata->sensor_max_x - x;
385 if (pdata->board->y_flip)
386 y = pdata->sensor_max_y - y;
388 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
390 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
391 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
393 /* number of active touch points */
398 /* sync after groups of events */
399 input_mt_sync_frame(input_dev);
400 input_sync(input_dev);
401 /* return the number of touch points */
406 * synaptics_rmi4_report_device() - reports the rmi4 device
407 * @pdata: pointer to synaptics_rmi4_data structure
408 * @rfi: pointer to synaptics_rmi4_fn
410 * This function is used to call the report function of the rmi4 device.
412 static int synaptics_rmi4_report_device(struct synaptics_rmi4_data *pdata,
413 struct synaptics_rmi4_fn *rfi)
416 struct i2c_client *client = pdata->i2c_client;
417 static int num_error_reports;
419 if (rfi->fn_number != SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
421 if (num_error_reports < MAX_ERROR_REPORT)
422 dev_err(&client->dev, "%s:report not supported\n",
425 touch = synpatics_rmi4_touchpad_report(pdata, rfi);
429 * synaptics_rmi4_sensor_report() - reports to input subsystem
430 * @pdata: pointer to synaptics_rmi4_data structure
432 * This function is used to reads in all data sources and reports
433 * them to the input subsystem.
435 static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *pdata)
437 unsigned char intr_status[4];
438 /* number of touch points - fingers or buttons */
441 struct synaptics_rmi4_fn *rfi;
442 struct synaptics_rmi4_device_info *rmi;
443 struct i2c_client *client = pdata->i2c_client;
446 * Get the interrupt status from the function $01
447 * control register+1 to find which source(s) were interrupting
448 * so we can read the data from the source(s) (2D sensor, buttons..)
450 retval = synaptics_rmi4_i2c_block_read(pdata,
451 pdata->fn01_data_base_addr + 1,
453 pdata->number_of_interrupt_register);
454 if (retval != pdata->number_of_interrupt_register) {
455 dev_err(&client->dev,
456 "could not read interrupt status registers\n");
460 * check each function that has data sources and if the interrupt for
461 * that triggered then call that RMI4 functions report() function to
462 * gather data and report it to the input subsystem
464 rmi = &(pdata->rmi4_mod_info);
465 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
466 if (rfi->num_of_data_sources) {
467 if (intr_status[rfi->index_to_intr_reg] &
469 touch = synaptics_rmi4_report_device(pdata,
473 /* return the number of touch points */
478 * synaptics_rmi4_irq() - thread function for rmi4 attention line
480 * @data: void pointer
482 * This function is interrupt thread function. It just notifies the
483 * application layer that attention is required.
485 static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
487 struct synaptics_rmi4_data *pdata = data;
491 touch_count = synaptics_rmi4_sensor_report(pdata);
493 wait_event_timeout(pdata->wait, pdata->touch_stopped,
494 msecs_to_jiffies(1));
497 } while (!pdata->touch_stopped);
502 * synpatics_rmi4_touchpad_detect() - detects the rmi4 touchpad device
503 * @pdata: pointer to synaptics_rmi4_data structure
504 * @rfi: pointer to synaptics_rmi4_fn structure
505 * @fd: pointer to synaptics_rmi4_fn_desc structure
506 * @interruptcount: count the number of interrupts
508 * This function calls to detects the rmi4 touchpad device
510 static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data *pdata,
511 struct synaptics_rmi4_fn *rfi,
512 struct synaptics_rmi4_fn_desc *fd,
513 unsigned int interruptcount)
515 unsigned char queries[QUERY_LEN];
516 unsigned short intr_offset;
517 unsigned char abs_data_size;
518 unsigned char abs_data_blk_size;
519 unsigned char egr_0, egr_1;
520 unsigned int all_data_blk_size;
521 int has_pinch, has_flick, has_tap;
522 int has_tapandhold, has_doubletap;
523 int has_earlytap, has_press;
524 int has_palmdetect, has_rotate;
528 struct i2c_client *client = pdata->i2c_client;
530 rfi->fn_desc.query_base_addr = fd->query_base_addr;
531 rfi->fn_desc.data_base_addr = fd->data_base_addr;
532 rfi->fn_desc.intr_src_count = fd->intr_src_count;
533 rfi->fn_desc.fn_number = fd->fn_number;
534 rfi->fn_number = fd->fn_number;
535 rfi->num_of_data_sources = fd->intr_src_count;
536 rfi->fn_desc.ctrl_base_addr = fd->ctrl_base_addr;
537 rfi->fn_desc.cmd_base_addr = fd->cmd_base_addr;
540 * need to get number of fingers supported, data size, etc.
541 * to be used when getting data since the number of registers to
542 * read depends on the number of fingers supported and data size.
544 retval = synaptics_rmi4_i2c_block_read(pdata, fd->query_base_addr,
547 if (retval != sizeof(queries)) {
548 dev_err(&client->dev, "%s:read function query registers\n",
553 * 2D data sources have only 3 bits for the number of fingers
554 * supported - so the encoding is a bit weird.
556 if ((queries[1] & MASK_3BIT) <= 4)
557 /* add 1 since zero based */
558 rfi->num_of_data_points = (queries[1] & MASK_3BIT) + 1;
561 * a value of 5 is up to 10 fingers - 6 and 7 are reserved
562 * (shouldn't get these i int retval;n a normal 2D source).
564 if ((queries[1] & MASK_3BIT) == 5)
565 rfi->num_of_data_points = 10;
567 pdata->fingers_supported = rfi->num_of_data_points;
568 /* Need to get interrupt info for handling interrupts */
569 rfi->index_to_intr_reg = (interruptcount + 7)/8;
570 if (rfi->index_to_intr_reg != 0)
571 rfi->index_to_intr_reg -= 1;
573 * loop through interrupts for each source in fn $11
574 * and or in a bit to the interrupt mask for each.
576 intr_offset = interruptcount % 8;
578 for (i = intr_offset;
579 i < ((fd->intr_src_count & MASK_3BIT) + intr_offset); i++)
580 rfi->intr_mask |= 1 << i;
582 /* Size of just the absolute data for one finger */
583 abs_data_size = queries[5] & MASK_2BIT;
584 /* One each for X and Y, one for LSB for X & Y, one for W, one for Z */
585 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
586 rfi->size_of_data_register_block = abs_data_blk_size;
589 * need to determine the size of data to read - this depends on
590 * conditions such as whether Relative data is reported and if Gesture
597 * Get info about what EGR data is supported, whether it has
598 * Relative data supported, etc.
600 has_pinch = egr_0 & HAS_PINCH;
601 has_flick = egr_0 & HAS_FLICK;
602 has_tap = egr_0 & HAS_TAP;
603 has_earlytap = egr_0 & HAS_EARLYTAP;
604 has_press = egr_0 & HAS_PRESS;
605 has_rotate = egr_1 & HAS_ROTATE;
606 has_rel = queries[1] & HAS_RELEASE;
607 has_tapandhold = egr_0 & HAS_TAPANDHOLD;
608 has_doubletap = egr_0 & HAS_DOUBLETAP;
609 has_palmdetect = egr_1 & HAS_PALMDETECT;
612 * Size of all data including finger status, absolute data for each
613 * finger, relative data and EGR data
616 /* finger status, four fingers per register */
617 ((rfi->num_of_data_points + 3) / 4) +
618 /* absolute data, per finger times number of fingers */
619 (abs_data_blk_size * rfi->num_of_data_points) +
621 * two relative registers (if relative is being reported)
625 * F11_2D_data8 is only present if the egr_0
626 * register is non-zero.
630 * F11_2D_data9 is only present if either egr_0 or
631 * egr_1 registers are non-zero.
635 * F11_2D_data10 is only present if EGR_PINCH or EGR_FLICK of
636 * egr_0 reports as 1.
638 !!(has_pinch | has_flick) +
640 * F11_2D_data11 and F11_2D_data12 are only present if
641 * EGR_FLICK of egr_0 reports as 1.
648 * synaptics_rmi4_touchpad_config() - configures the rmi4 touchpad device
649 * @pdata: pointer to synaptics_rmi4_data structure
650 * @rfi: pointer to synaptics_rmi4_fn structure
652 * This function calls to configures the rmi4 touchpad device
654 static int synaptics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
655 struct synaptics_rmi4_fn *rfi)
658 * For the data source - print info and do any
659 * source specific configuration.
661 unsigned char data[BUF_LEN];
663 struct i2c_client *client = pdata->i2c_client;
665 /* Get and print some info about the data source... */
666 /* To Query 2D devices we need to read from the address obtained
667 * from the function descriptor stored in the RMI function info.
669 retval = synaptics_rmi4_i2c_block_read(pdata,
670 rfi->fn_desc.query_base_addr,
672 if (retval != QUERY_LEN)
673 dev_err(&client->dev, "%s:read query registers failed\n",
676 retval = synaptics_rmi4_i2c_block_read(pdata,
677 rfi->fn_desc.ctrl_base_addr,
679 if (retval != DATA_BUF_LEN) {
680 dev_err(&client->dev,
681 "%s:read control registers failed\n",
685 /* Store these for use later*/
686 pdata->sensor_max_x = ((data[6] & MASK_8BIT) << 0) |
687 ((data[7] & MASK_4BIT) << 8);
688 pdata->sensor_max_y = ((data[8] & MASK_5BIT) << 0) |
689 ((data[9] & MASK_4BIT) << 8);
695 * synaptics_rmi4_i2c_query_device() - query the rmi4 device
696 * @pdata: pointer to synaptics_rmi4_data structure
698 * This function is used to query the rmi4 device.
700 static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
704 unsigned char std_queries[STD_QUERY_LEN];
705 unsigned char intr_count = 0;
706 int data_sources = 0;
707 unsigned int ctrl_offset;
708 struct synaptics_rmi4_fn *rfi;
709 struct synaptics_rmi4_fn_desc rmi_fd;
710 struct synaptics_rmi4_device_info *rmi;
711 struct i2c_client *client = pdata->i2c_client;
714 * init the physical drivers RMI module
715 * info list of functions
717 INIT_LIST_HEAD(&pdata->rmi4_mod_info.support_fn_list);
720 * Read the Page Descriptor Table to determine what functions
723 for (i = PDT_START_SCAN_LOCATION; i > PDT_END_SCAN_LOCATION;
724 i -= PDT_ENTRY_SIZE) {
725 retval = synaptics_rmi4_i2c_block_read(pdata, i,
726 (unsigned char *)&rmi_fd,
728 if (retval != sizeof(rmi_fd)) {
729 /* failed to read next PDT entry */
730 dev_err(&client->dev, "%s: read error\n", __func__);
734 if (rmi_fd.fn_number) {
735 switch (rmi_fd.fn_number & MASK_8BIT) {
736 case SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM:
737 pdata->fn01_query_base_addr =
738 rmi_fd.query_base_addr;
739 pdata->fn01_ctrl_base_addr =
740 rmi_fd.ctrl_base_addr;
741 pdata->fn01_data_base_addr =
742 rmi_fd.data_base_addr;
744 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM:
745 if (rmi_fd.intr_src_count) {
746 rfi = kmalloc(sizeof(*rfi),
750 retval = synpatics_rmi4_touchpad_detect
761 /* interrupt count for next iteration */
762 intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
764 * We only want to add functions to the list
765 * that have data associated with them.
767 if (rfi && rmi_fd.intr_src_count) {
768 /* link this function info to the RMI module */
769 mutex_lock(&(pdata->fn_list_mutex));
770 list_add_tail(&rfi->link,
771 &pdata->rmi4_mod_info.support_fn_list);
772 mutex_unlock(&(pdata->fn_list_mutex));
776 * A zero in the function number
777 * signals the end of the PDT
779 dev_dbg(&client->dev,
780 "%s:end of PDT\n", __func__);
785 * calculate the interrupt register count - used in the
786 * ISR to read the correct number of interrupt registers
788 pdata->number_of_interrupt_register = (intr_count + 7) / 8;
790 * Function $01 will be used to query the product properties,
791 * and product ID so we had to read the PDT above first to get
792 * the Fn $01 query address and prior to filling in the product
793 * info. NOTE: Even an unflashed device will still have FN $01.
796 /* Load up the standard queries and get the RMI4 module info */
797 retval = synaptics_rmi4_i2c_block_read(pdata,
798 pdata->fn01_query_base_addr,
800 sizeof(std_queries));
801 if (retval != sizeof(std_queries)) {
802 dev_err(&client->dev, "%s:Failed reading queries\n",
807 /* Currently supported RMI version is 4.0 */
808 pdata->rmi4_mod_info.version_major = 4;
809 pdata->rmi4_mod_info.version_minor = 0;
811 * get manufacturer id, product_props, product info,
812 * date code, tester id, serial num and product id (name)
814 pdata->rmi4_mod_info.manufacturer_id = std_queries[0];
815 pdata->rmi4_mod_info.product_props = std_queries[1];
816 pdata->rmi4_mod_info.product_info[0] = std_queries[2];
817 pdata->rmi4_mod_info.product_info[1] = std_queries[3];
818 /* year - 2001-2032 */
819 pdata->rmi4_mod_info.date_code[0] = std_queries[4] & MASK_5BIT;
821 pdata->rmi4_mod_info.date_code[1] = std_queries[5] & MASK_4BIT;
823 pdata->rmi4_mod_info.date_code[2] = std_queries[6] & MASK_5BIT;
824 pdata->rmi4_mod_info.tester_id = ((std_queries[7] & MASK_7BIT) << 8) |
825 (std_queries[8] & MASK_7BIT);
826 pdata->rmi4_mod_info.serial_number =
827 ((std_queries[9] & MASK_7BIT) << 8) |
828 (std_queries[10] & MASK_7BIT);
829 memcpy(pdata->rmi4_mod_info.product_id_string, &std_queries[11], 10);
831 /* Check if this is a Synaptics device - report if not. */
832 if (pdata->rmi4_mod_info.manufacturer_id != 1)
833 dev_err(&client->dev, "non-Synaptics mfg id:%d\n",
834 pdata->rmi4_mod_info.manufacturer_id);
836 list_for_each_entry(rfi, &pdata->rmi4_mod_info.support_fn_list, link)
837 data_sources += rfi->num_of_data_sources;
839 rmi = &(pdata->rmi4_mod_info);
840 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
841 if (rfi->num_of_data_sources) {
842 if (rfi->fn_number ==
843 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
844 retval = synaptics_rmi4_touchpad_config
849 dev_err(&client->dev,
850 "%s:fn_number not supported\n",
853 * Turn on interrupts for this
854 * function's data sources.
856 ctrl_offset = pdata->fn01_ctrl_base_addr + 1 +
857 rfi->index_to_intr_reg;
858 retval = synaptics_rmi4_i2c_byte_write(pdata,
870 * Descriptor structure.
871 * Describes the number of i2c devices on the bus that speak RMI.
873 static struct synaptics_rmi4_platform_data synaptics_rmi4_platformdata = {
874 .irq_type = (IRQF_TRIGGER_FALLING | IRQF_SHARED),
880 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
881 * @i2c: i2c client structure pointer
882 * @id:i2c device id pointer
884 * This function will allocate and initialize the instance
885 * data and request the irq and set the instance data as the clients
886 * platform data then register the physical driver which will do a scan of
887 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
888 * have data sources associated with them.
890 static int synaptics_rmi4_probe
891 (struct i2c_client *client, const struct i2c_device_id *dev_id)
894 unsigned char intr_status[4];
895 struct synaptics_rmi4_data *rmi4_data;
896 const struct synaptics_rmi4_platform_data *platformdata =
897 client->dev.platform_data;
899 if (!i2c_check_functionality(client->adapter,
900 I2C_FUNC_SMBUS_BYTE_DATA)) {
901 dev_err(&client->dev, "i2c smbus byte data not supported\n");
906 platformdata = &synaptics_rmi4_platformdata;
908 /* Allocate and initialize the instance data for this client */
909 rmi4_data = kcalloc(2, sizeof(struct synaptics_rmi4_data),
914 rmi4_data->input_dev = input_allocate_device();
915 if (rmi4_data->input_dev == NULL) {
920 rmi4_data->regulator = regulator_get(&client->dev, "vdd");
921 if (IS_ERR(rmi4_data->regulator)) {
922 dev_err(&client->dev, "%s:get regulator failed\n",
924 retval = PTR_ERR(rmi4_data->regulator);
925 goto err_get_regulator;
927 retval = regulator_enable(rmi4_data->regulator);
929 dev_err(&client->dev, "%s:regulator enable failed\n",
931 goto err_regulator_enable;
933 init_waitqueue_head(&rmi4_data->wait);
935 * Copy i2c_client pointer into RTID's i2c_client pointer for
936 * later use in rmi4_read, rmi4_write, etc.
938 rmi4_data->i2c_client = client;
939 /* So we set the page correctly the first time */
940 rmi4_data->current_page = MASK_16BIT;
941 rmi4_data->board = platformdata;
942 rmi4_data->touch_stopped = false;
944 /* init the mutexes for maintain the lists */
945 mutex_init(&(rmi4_data->fn_list_mutex));
946 mutex_init(&(rmi4_data->rmi4_page_mutex));
949 * Register physical driver - this will call the detect function that
950 * will then scan the device and determine the supported
953 retval = synaptics_rmi4_i2c_query_device(rmi4_data);
955 dev_err(&client->dev, "%s: rmi4 query device failed\n",
960 /* Store the instance data in the i2c_client */
961 i2c_set_clientdata(client, rmi4_data);
963 /*initialize the input device parameters */
964 rmi4_data->input_dev->name = DRIVER_NAME;
965 rmi4_data->input_dev->phys = "Synaptics_Clearpad";
966 rmi4_data->input_dev->id.bustype = BUS_I2C;
967 rmi4_data->input_dev->dev.parent = &client->dev;
968 input_set_drvdata(rmi4_data->input_dev, rmi4_data);
970 /* Initialize the function handlers for rmi4 */
971 set_bit(EV_SYN, rmi4_data->input_dev->evbit);
972 set_bit(EV_KEY, rmi4_data->input_dev->evbit);
973 set_bit(EV_ABS, rmi4_data->input_dev->evbit);
975 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_X, 0,
976 rmi4_data->sensor_max_x, 0, 0);
977 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_Y, 0,
978 rmi4_data->sensor_max_y, 0, 0);
979 input_set_abs_params(rmi4_data->input_dev, ABS_MT_TOUCH_MAJOR, 0,
980 MAX_TOUCH_MAJOR, 0, 0);
981 input_mt_init_slots(rmi4_data->input_dev,
982 rmi4_data->fingers_supported, 0);
984 /* Clear interrupts */
985 synaptics_rmi4_i2c_block_read(rmi4_data,
986 rmi4_data->fn01_data_base_addr + 1, intr_status,
987 rmi4_data->number_of_interrupt_register);
988 retval = request_threaded_irq(client->irq, NULL,
990 platformdata->irq_type,
991 DRIVER_NAME, rmi4_data);
993 dev_err(&client->dev, "Unable to get attn irq %d\n",
998 retval = input_register_device(rmi4_data->input_dev);
1000 dev_err(&client->dev, "%s:input register failed\n", __func__);
1007 free_irq(client->irq, rmi4_data);
1009 regulator_disable(rmi4_data->regulator);
1010 err_regulator_enable:
1011 regulator_put(rmi4_data->regulator);
1013 input_free_device(rmi4_data->input_dev);
1014 rmi4_data->input_dev = NULL;
1021 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1022 * @client: i2c client structure pointer
1024 * This function uses to remove the i2c-client
1025 * touchscreen driver and returns integer.
1027 static int synaptics_rmi4_remove(struct i2c_client *client)
1029 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1031 rmi4_data->touch_stopped = true;
1032 wake_up(&rmi4_data->wait);
1033 free_irq(client->irq, rmi4_data);
1034 input_unregister_device(rmi4_data->input_dev);
1035 regulator_disable(rmi4_data->regulator);
1036 regulator_put(rmi4_data->regulator);
1044 * synaptics_rmi4_suspend() - suspend the touch screen controller
1045 * @dev: pointer to device structure
1047 * This function is used to suspend the
1048 * touch panel controller and returns integer
1050 static int synaptics_rmi4_suspend(struct device *dev)
1052 /* Touch sleep mode */
1054 unsigned char intr_status;
1055 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1057 rmi4_data->touch_stopped = true;
1058 disable_irq(rmi4_data->i2c_client->irq);
1060 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1061 rmi4_data->fn01_data_base_addr + 1,
1063 rmi4_data->number_of_interrupt_register);
1067 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1068 rmi4_data->fn01_ctrl_base_addr + 1,
1069 (intr_status & ~TOUCHPAD_CTRL_INTR));
1073 regulator_disable(rmi4_data->regulator);
1078 * synaptics_rmi4_resume() - resume the touch screen controller
1079 * @dev: pointer to device structure
1081 * This function is used to resume the touch panel
1082 * controller and returns integer.
1084 static int synaptics_rmi4_resume(struct device *dev)
1087 unsigned char intr_status;
1088 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1090 retval = regulator_enable(rmi4_data->regulator);
1092 dev_err(dev, "Regulator enable failed (%d)\n", retval);
1096 enable_irq(rmi4_data->i2c_client->irq);
1097 rmi4_data->touch_stopped = false;
1099 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1100 rmi4_data->fn01_data_base_addr + 1,
1102 rmi4_data->number_of_interrupt_register);
1106 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1107 rmi4_data->fn01_ctrl_base_addr + 1,
1108 (intr_status | TOUCHPAD_CTRL_INTR));
1117 static SIMPLE_DEV_PM_OPS(synaptics_rmi4_dev_pm_ops, synaptics_rmi4_suspend,
1118 synaptics_rmi4_resume);
1120 static const struct i2c_device_id synaptics_rmi4_id_table[] = {
1124 MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
1126 static struct i2c_driver synaptics_rmi4_driver = {
1128 .name = DRIVER_NAME,
1129 .pm = &synaptics_rmi4_dev_pm_ops,
1131 .probe = synaptics_rmi4_probe,
1132 .remove = synaptics_rmi4_remove,
1133 .id_table = synaptics_rmi4_id_table,
1136 module_i2c_driver(synaptics_rmi4_driver);
1138 MODULE_LICENSE("GPL v2");
1139 MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
1140 MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
1141 MODULE_ALIAS("i2c:synaptics_rmi4_ts");