28 #include <linux/input.h>
29 #include <linux/slab.h>
30 #include <linux/i2c.h>
33 #include <linux/module.h>
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)
210 dev_err(&i2c->
dev,
"%s:failed:%d\n", __func__, retval);
228 unsigned char *valp,
int size)
236 retval = synaptics_rmi4_set_page(pdata, address);
242 if (retval != size) {
245 "%s:address 0x%04x size %d failed:%d\n",
246 __func__, address, size, retval);
248 synaptics_rmi4_set_page(pdata, address);
266 unsigned short address,
269 unsigned char txbuf[2];
276 retval = synaptics_rmi4_set_page(pdata, address);
284 dev_err(&i2c->
dev,
"%s:failed:%d\n", __func__, retval);
306 int fingers_supported;
307 int finger_registers;
312 unsigned short data_base_addr;
314 unsigned char data_reg_blk_size;
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",
351 for (finger = 0; finger < fingers_supported; finger++) {
355 finger_shift = (finger % 4) * 2;
356 finger_status = (values[
reg] >> finger_shift) & 3;
361 if (finger_status == 1 || finger_status == 2) {
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) {
380 (data[3] >> 4) & MASK_4BIT;
384 if (pdata->
board->x_flip)
388 if (pdata->
board->y_flip)
400 for (finger = 0; finger < touch_count; finger++) {
402 max(wx[finger] , wy[finger]));
430 static int num_error_reports;
434 dev_err(&client->
dev,
"%s:report not supported\n",
437 touch = synpatics_rmi4_touchpad_report(pdata, rfi);
449 unsigned char intr_status[4];
462 retval = synaptics_rmi4_i2c_block_read(pdata,
468 "could not read interrupt status registers\n");
481 touch = synaptics_rmi4_report_device(pdata,
502 touch_count = synaptics_rmi4_sensor_report(pdata);
524 unsigned int interruptcount)
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;
558 if (retval !=
sizeof(queries)) {
559 dev_err(&client->
dev,
"%s:read function query registers\n",
575 if ((queries[1] & MASK_3BIT) == 5)
586 intr_offset = interruptcount % 8;
588 for (i = intr_offset;
595 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
648 !!(has_pinch | has_flick) +
679 retval = synaptics_rmi4_i2c_block_read(pdata,
683 dev_err(&client->
dev,
"%s:read query registers failed\n",
686 retval = synaptics_rmi4_i2c_block_read(pdata,
691 "%s:read control registers failed\n",
715 unsigned char intr_count = 0;
716 int data_sources = 0;
717 unsigned int ctrl_offset;
735 retval = synaptics_rmi4_i2c_block_read(pdata, i,
736 (
unsigned char *)&rmi_fd,
738 if (retval !=
sizeof(rmi_fd)) {
740 dev_err(&client->
dev,
"%s: read error\n", __func__);
744 if (rmi_fd.fn_number) {
745 switch (rmi_fd.fn_number & MASK_8BIT) {
748 rmi_fd.query_base_addr;
750 rmi_fd.ctrl_base_addr;
752 rmi_fd.data_base_addr;
755 if (rmi_fd.intr_src_count) {
760 "%s:kmalloc failed\n",
764 retval = synpatics_rmi4_touchpad_detect
776 intr_count += (rmi_fd.intr_src_count &
MASK_3BIT);
781 if (rfi && rmi_fd.intr_src_count) {
794 "%s:end of PDT\n", __func__);
811 retval = synaptics_rmi4_i2c_block_read(pdata,
814 sizeof(std_queries));
815 if (retval !=
sizeof(std_queries)) {
816 dev_err(&client->
dev,
"%s:Failed reading queries\n",
847 dev_err(&client->
dev,
"%s: non-Synaptics mfg id:%d\n",
851 data_sources += rfi->num_of_data_sources;
864 "%s:fn_number not supported\n",
872 retval = synaptics_rmi4_i2c_byte_write(pdata,
894 static int __devinit synaptics_rmi4_probe
898 unsigned char intr_status[4];
901 client->
dev.platform_data;
903 if (!i2c_check_functionality(client->
adapter,
905 dev_err(&client->
dev,
"i2c smbus byte data not supported\n");
910 dev_err(&client->
dev,
"%s: no platform data\n", __func__);
918 dev_err(&client->
dev,
"%s: no memory allocated\n", __func__);
922 rmi4_data->
input_dev = input_allocate_device();
924 dev_err(&client->
dev,
"%s:input device alloc failed\n",
932 dev_err(&client->
dev,
"%s:get regulator failed\n",
935 goto err_get_regulator;
939 dev_err(&client->
dev,
"%s:regulator enable failed\n",
941 goto err_regulator_enable;
951 rmi4_data->
board = platformdata;
963 retval = synaptics_rmi4_i2c_query_device(rmi4_data);
965 dev_err(&client->
dev,
"%s: rmi4 query device failed\n",
971 i2c_set_clientdata(client, rmi4_data);
975 rmi4_data->
input_dev->phys =
"Synaptics_Clearpad";
978 input_set_drvdata(rmi4_data->
input_dev, rmi4_data);
993 synaptics_rmi4_i2c_block_read(rmi4_data,
1001 dev_err(&client->
dev,
"%s:Unable to get attn irq %d\n",
1006 retval = input_register_device(rmi4_data->
input_dev);
1008 dev_err(&client->
dev,
"%s:input register failed\n", __func__);
1018 err_regulator_enable:
1021 input_free_device(rmi4_data->
input_dev);
1043 input_unregister_device(rmi4_data->
input_dev);
1059 static int synaptics_rmi4_suspend(
struct device *
dev)
1063 unsigned char intr_status;
1070 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1077 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1094 static int synaptics_rmi4_resume(
struct device *dev)
1097 unsigned char intr_status;
1106 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1113 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
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[] = {
1134 static struct i2c_driver synaptics_rmi4_driver = {
1139 .pm = &synaptics_rmi4_dev_pm_ops,
1142 .probe = synaptics_rmi4_probe,
1144 .id_table = synaptics_rmi4_id_table,
1152 static int __init synaptics_rmi4_init(
void)
1154 return i2c_add_driver(&synaptics_rmi4_driver);
1162 static void __exit synaptics_rmi4_exit(
void)