13 #include <linux/module.h>
14 #include <linux/i2c.h>
17 #include <linux/input.h>
20 #include <linux/slab.h>
23 #define DRIVER_NAME "synaptics_i2c"
25 #define PRODUCT_ID_LENGTH 15
26 #define REGISTER_LENGTH 8
32 #define SOFT_RESET_DELAY_MS 3
34 #define HARD_RESET_DELAY_MS 500
37 #define PAGE_SEL_REG 0xff
38 #define DEVICE_STATUS_REG 0x09
41 #define DEV_CONTROL_REG 0x0000
42 #define INTERRUPT_EN_REG 0x0001
43 #define ERR_STAT_REG 0x0002
44 #define INT_REQ_STAT_REG 0x0003
45 #define DEV_COMMAND_REG 0x0004
47 #define RMI_PROT_VER_REG 0x0200
48 #define MANUFACT_ID_REG 0x0201
49 #define PHYS_INT_VER_REG 0x0202
50 #define PROD_PROPERTY_REG 0x0203
51 #define INFO_QUERY_REG0 0x0204
52 #define INFO_QUERY_REG1 (INFO_QUERY_REG0 + 1)
53 #define INFO_QUERY_REG2 (INFO_QUERY_REG0 + 2)
54 #define INFO_QUERY_REG3 (INFO_QUERY_REG0 + 3)
56 #define PRODUCT_ID_REG0 0x0210
57 #define PRODUCT_ID_REG1 (PRODUCT_ID_REG0 + 1)
58 #define PRODUCT_ID_REG2 (PRODUCT_ID_REG0 + 2)
59 #define PRODUCT_ID_REG3 (PRODUCT_ID_REG0 + 3)
60 #define PRODUCT_ID_REG4 (PRODUCT_ID_REG0 + 4)
61 #define PRODUCT_ID_REG5 (PRODUCT_ID_REG0 + 5)
62 #define PRODUCT_ID_REG6 (PRODUCT_ID_REG0 + 6)
63 #define PRODUCT_ID_REG7 (PRODUCT_ID_REG0 + 7)
64 #define PRODUCT_ID_REG8 (PRODUCT_ID_REG0 + 8)
65 #define PRODUCT_ID_REG9 (PRODUCT_ID_REG0 + 9)
66 #define PRODUCT_ID_REG10 (PRODUCT_ID_REG0 + 10)
67 #define PRODUCT_ID_REG11 (PRODUCT_ID_REG0 + 11)
68 #define PRODUCT_ID_REG12 (PRODUCT_ID_REG0 + 12)
69 #define PRODUCT_ID_REG13 (PRODUCT_ID_REG0 + 13)
70 #define PRODUCT_ID_REG14 (PRODUCT_ID_REG0 + 14)
71 #define PRODUCT_ID_REG15 (PRODUCT_ID_REG0 + 15)
73 #define DATA_REG0 0x0400
74 #define ABS_PRESSURE_REG 0x0401
75 #define ABS_MSB_X_REG 0x0402
76 #define ABS_LSB_X_REG (ABS_MSB_X_REG + 1)
77 #define ABS_MSB_Y_REG 0x0404
78 #define ABS_LSB_Y_REG (ABS_MSB_Y_REG + 1)
79 #define REL_X_REG 0x0406
80 #define REL_Y_REG 0x0407
82 #define DEV_QUERY_REG0 0x1000
83 #define DEV_QUERY_REG1 (DEV_QUERY_REG0 + 1)
84 #define DEV_QUERY_REG2 (DEV_QUERY_REG0 + 2)
85 #define DEV_QUERY_REG3 (DEV_QUERY_REG0 + 3)
86 #define DEV_QUERY_REG4 (DEV_QUERY_REG0 + 4)
87 #define DEV_QUERY_REG5 (DEV_QUERY_REG0 + 5)
88 #define DEV_QUERY_REG6 (DEV_QUERY_REG0 + 6)
89 #define DEV_QUERY_REG7 (DEV_QUERY_REG0 + 7)
90 #define DEV_QUERY_REG8 (DEV_QUERY_REG0 + 8)
92 #define GENERAL_2D_CONTROL_REG 0x1041
93 #define SENSOR_SENSITIVITY_REG 0x1044
94 #define SENS_MAX_POS_MSB_REG 0x1046
95 #define SENS_MAX_POS_LSB_REG (SENS_MAX_POS_UPPER_REG + 1)
99 #define REPORT_RATE_1ST_BIT 6
102 #define F10_ABS_INT_ENA 0
103 #define F10_REL_INT_ENA 1
104 #define F20_INT_ENA 2
107 #define F10_ABS_INT_REQ 0
108 #define F10_REL_INT_REQ 1
109 #define F20_INT_REQ 2
111 #define STAT_CONFIGURED 6
115 #define RESET_COMMAND 0x01
116 #define REZERO_COMMAND 0x02
123 #define HAS_PALM_DETECT 1
124 #define HAS_MULTI_FING 2
125 #define HAS_SCROLLER 4
126 #define HAS_2D_SCROLL 5
129 #define NO_DECELERATION 1
130 #define REDUCE_REPORTING 3
135 #define REPORT_RATE_MSK 0xc0
136 #define SLEEP_MODE_MSK 0x07
139 #define FULL_AWAKE 0x0
140 #define NORMAL_OP 0x1
141 #define LOW_PWR_OP 0x2
142 #define VERY_LOW_PWR_OP 0x3
143 #define SENS_SLEEP 0x4
144 #define SLEEP_MOD 0x5
145 #define DEEP_SLEEP 0x6
146 #define HIBERNATE 0x7
150 #define INT_ENA_REQ_MSK 0x07
151 #define INT_ENA_ABS_MSK 0x01
152 #define INT_ENA_REL_MSK 0x02
153 #define INT_ENA_F20_MSK 0x04
156 #define CONFIGURED_MSK 0x40
157 #define ERROR_MSK 0x80
160 #define FINGER_WIDTH_MSK 0xf0
161 #define GESTURE_MSK 0x08
162 #define SENSOR_STATUS_MSK 0x07
169 #define MSB_POSITION_MSK 0x1f
174 #define NUM_EXTRA_POS_MSK 0x07
177 #define THREAD_IRQ_SLEEP_SECS 2
178 #define THREAD_IRQ_SLEEP_MSECS (THREAD_IRQ_SLEEP_SECS * MSEC_PER_SEC)
184 #define NO_DATA_THRES (MSEC_PER_SEC)
185 #define NO_DATA_SLEEP_MSECS (MSEC_PER_SEC / 4)
188 static bool no_decel = 1;
193 static bool reduce_report;
198 static bool no_filter;
208 static bool polling_req;
213 static int scan_rate = 80;
231 static inline void set_scan_rate(
struct synaptics_i2c *touch,
int scan_rate)
275 static int synaptics_i2c_config(
struct i2c_client *client)
297 control |= no_filter ? 1 <<
NO_FILTER : 0;
305 static int synaptics_i2c_reset_config(
struct i2c_client *client)
312 dev_err(&client->
dev,
"Unable to reset device\n");
315 ret = synaptics_i2c_config(client);
317 dev_err(&client->
dev,
"Unable to config device\n");
323 static int synaptics_i2c_check_error(
struct i2c_client *client)
331 ret = synaptics_i2c_reset_config(client);
336 static bool synaptics_i2c_get_input(
struct synaptics_i2c *touch)
339 int xy_delta, gesture;
344 if (synaptics_i2c_check_error(touch->
client))
349 gesture = (data >>
GESTURE) & 0x1;
358 x_delta = xy_delta & 0xff;
362 input_report_key(input,
BTN_LEFT, gesture);
365 input_report_rel(input,
REL_X, x_delta);
366 input_report_rel(input,
REL_Y, -y_delta);
369 return xy_delta || gesture;
372 static void synaptics_i2c_reschedule_work(
struct synaptics_i2c *touch,
381 spin_unlock_irqrestore(&touch->
lock, flags);
388 synaptics_i2c_reschedule_work(touch, 0);
393 static void synaptics_i2c_check_params(
struct synaptics_i2c *touch)
398 set_scan_rate(touch, scan_rate);
416 synaptics_i2c_reset_config(touch->
client);
420 static unsigned long synaptics_i2c_adjust_delay(
struct synaptics_i2c *touch,
423 unsigned long delay, nodata_count_thres;
451 synaptics_i2c_check_params(touch);
453 have_data = synaptics_i2c_get_input(touch);
454 delay = synaptics_i2c_adjust_delay(touch, have_data);
464 synaptics_i2c_reschedule_work(touch, delay);
467 static int synaptics_i2c_open(
struct input_dev *input)
472 ret = synaptics_i2c_reset_config(touch->
client);
477 synaptics_i2c_reschedule_work(touch,
483 static void synaptics_i2c_close(
struct input_dev *input)
496 static void synaptics_i2c_set_input_params(
struct synaptics_i2c *touch)
498 struct input_dev *input = touch->
input;
500 input->name = touch->
client->name;
501 input->phys = touch->
client->adapter->name;
503 input->id.version = synaptics_i2c_word_get(touch->
client,
505 input->dev.parent = &touch->
client->dev;
506 input->open = synaptics_i2c_open;
507 input->close = synaptics_i2c_close;
508 input_set_drvdata(input, touch);
531 set_scan_rate(touch, scan_rate);
544 touch = synaptics_i2c_touch_create(client);
548 ret = synaptics_i2c_reset_config(client);
555 touch->
input = input_allocate_device();
561 synaptics_i2c_set_input_params(touch);
565 "Requesting IRQ: %d\n", touch->
client->irq);
572 "IRQ request failed: %d, "
573 "falling back to polling\n", ret);
575 synaptics_i2c_reg_set(touch->
client,
582 "Using polling at rate: %d times/sec\n", scan_rate);
585 ret = input_register_device(touch->
input);
588 "Input device register failed: %d\n", ret);
592 i2c_set_clientdata(client, touch);
597 input_free_device(touch->
input);
611 input_unregister_device(touch->
input);
617 #ifdef CONFIG_PM_SLEEP
618 static int synaptics_i2c_suspend(
struct device *
dev)
631 static int synaptics_i2c_resume(
struct device *
dev)
637 ret = synaptics_i2c_reset_config(client);
641 synaptics_i2c_reschedule_work(touch,
649 synaptics_i2c_resume);
651 static const struct i2c_device_id synaptics_i2c_id_table[] = {
652 {
"synaptics_i2c", 0 },
657 static struct i2c_driver synaptics_i2c_driver = {
661 .pm = &synaptics_i2c_pm,
664 .probe = synaptics_i2c_probe,
667 .id_table = synaptics_i2c_id_table,