blob: ba0be2b02622743c30039ee5dfdb79a99b821367 [file] [log] [blame]
Alexandra Chin669d27c2012-12-24 15:42:30 +08001/*
2 * Synaptics RMI4 touchscreen driver
3 *
4 * Copyright (C) 2012 Synaptics Incorporated
5 *
6 * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
7 * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
Amy Maloche1a53b612013-01-18 15:25:15 -08008 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
Alexandra Chin669d27c2012-12-24 15:42:30 +08009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/i2c.h>
25#include <linux/interrupt.h>
26#include <linux/delay.h>
27#include <linux/input.h>
28#include <linux/gpio.h>
29#include <linux/regulator/consumer.h>
30#include <linux/input/synaptics_dsx.h>
Amy Malocheecfb4892013-02-06 13:30:36 -080031#include <linux/of_gpio.h>
Alexandra Chin669d27c2012-12-24 15:42:30 +080032#include "synaptics_i2c_rmi4.h"
Alexandra Chin669d27c2012-12-24 15:42:30 +080033#include <linux/input/mt.h>
Alexandra Chin669d27c2012-12-24 15:42:30 +080034
35#define DRIVER_NAME "synaptics_rmi4_i2c"
36#define INPUT_PHYS_NAME "synaptics_rmi4_i2c/input0"
Amy Maloche986863d2013-06-10 15:13:57 -070037#define DEBUGFS_DIR_NAME "ts_debug"
Alexandra Chin3a747522013-04-15 12:13:38 -070038
39#define RESET_DELAY 100
40
Alexandra Chin669d27c2012-12-24 15:42:30 +080041#define TYPE_B_PROTOCOL
Alexandra Chin669d27c2012-12-24 15:42:30 +080042
43#define NO_0D_WHILE_2D
44/*
45#define REPORT_2D_Z
46*/
47#define REPORT_2D_W
48
49#define RPT_TYPE (1 << 0)
50#define RPT_X_LSB (1 << 1)
51#define RPT_X_MSB (1 << 2)
52#define RPT_Y_LSB (1 << 3)
53#define RPT_Y_MSB (1 << 4)
54#define RPT_Z (1 << 5)
55#define RPT_WX (1 << 6)
56#define RPT_WY (1 << 7)
57#define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB)
58
59#define EXP_FN_DET_INTERVAL 1000 /* ms */
60#define POLLING_PERIOD 1 /* ms */
61#define SYN_I2C_RETRY_TIMES 10
62#define MAX_ABS_MT_TOUCH_MAJOR 15
63
64#define F01_STD_QUERY_LEN 21
65#define F01_BUID_ID_OFFSET 18
66#define F11_STD_QUERY_LEN 9
67#define F11_STD_CTRL_LEN 10
68#define F11_STD_DATA_LEN 12
69
70#define NORMAL_OPERATION (0 << 0)
71#define SENSOR_SLEEP (1 << 0)
Alexandra Chinfb798fa2013-03-26 17:15:38 -070072#define NO_SLEEP_OFF (0 << 2)
73#define NO_SLEEP_ON (1 << 2)
Alexandra Chin669d27c2012-12-24 15:42:30 +080074
Alexandra Chin3a747522013-04-15 12:13:38 -070075enum device_status {
76 STATUS_NO_ERROR = 0x00,
77 STATUS_RESET_OCCURED = 0x01,
78 STATUS_INVALID_CONFIG = 0x02,
79 STATUS_DEVICE_FAILURE = 0x03,
80 STATUS_CONFIG_CRC_FAILURE = 0x04,
81 STATUS_FIRMWARE_CRC_FAILURE = 0x05,
82 STATUS_CRC_IN_PROGRESS = 0x06
83};
84
Amy Maloche1a53b612013-01-18 15:25:15 -080085#define RMI4_VTG_MIN_UV 2700000
86#define RMI4_VTG_MAX_UV 3300000
87#define RMI4_ACTIVE_LOAD_UA 15000
88#define RMI4_LPM_LOAD_UA 10
89
90#define RMI4_I2C_VTG_MIN_UV 1800000
91#define RMI4_I2C_VTG_MAX_UV 1800000
92#define RMI4_I2C_LOAD_UA 10000
93#define RMI4_I2C_LPM_LOAD_UA 10
94
Amy Maloche946da662013-01-18 16:27:11 -080095#define RMI4_GPIO_SLEEP_LOW_US 10000
Amy Maloche1a53b612013-01-18 15:25:15 -080096
Alexandra Chin669d27c2012-12-24 15:42:30 +080097static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
98 unsigned short addr, unsigned char *data,
99 unsigned short length);
100
101static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
102 unsigned short addr, unsigned char *data,
103 unsigned short length);
104
105static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data);
106
Amy Maloche827e8b02013-02-27 15:25:14 -0800107#ifdef CONFIG_PM
108static int synaptics_rmi4_suspend(struct device *dev);
109
110static int synaptics_rmi4_resume(struct device *dev);
Amy Malochef46540d2013-02-15 17:09:43 -0800111
Alexandra Chin669d27c2012-12-24 15:42:30 +0800112static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
113 struct device_attribute *attr, char *buf);
114
115static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
116 struct device_attribute *attr, const char *buf, size_t count);
117
Amy Malochef46540d2013-02-15 17:09:43 -0800118#if defined(CONFIG_FB)
119static int fb_notifier_callback(struct notifier_block *self,
120 unsigned long event, void *data);
121#elif defined(CONFIG_HAS_EARLYSUSPEND)
Alexandra Chin669d27c2012-12-24 15:42:30 +0800122static void synaptics_rmi4_early_suspend(struct early_suspend *h);
123
124static void synaptics_rmi4_late_resume(struct early_suspend *h);
Amy Maloche827e8b02013-02-27 15:25:14 -0800125#endif
Alexandra Chin669d27c2012-12-24 15:42:30 +0800126#endif
127
128static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
129 struct device_attribute *attr, const char *buf, size_t count);
130
131static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
132 struct device_attribute *attr, char *buf);
133
134static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
135 struct device_attribute *attr, char *buf);
136
137static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
138 struct device_attribute *attr, char *buf);
139
140static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
141 struct device_attribute *attr, char *buf);
142
143static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
144 struct device_attribute *attr, const char *buf, size_t count);
145
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700146static ssize_t synaptics_rmi4_flipx_show(struct device *dev,
147 struct device_attribute *attr, char *buf);
148
149static ssize_t synaptics_rmi4_flipx_store(struct device *dev,
150 struct device_attribute *attr, const char *buf, size_t count);
151
152static ssize_t synaptics_rmi4_flipy_show(struct device *dev,
153 struct device_attribute *attr, char *buf);
154
155static ssize_t synaptics_rmi4_flipy_store(struct device *dev,
156 struct device_attribute *attr, const char *buf, size_t count);
157
158
Alexandra Chin669d27c2012-12-24 15:42:30 +0800159struct synaptics_rmi4_f01_device_status {
160 union {
161 struct {
162 unsigned char status_code:4;
163 unsigned char reserved:2;
164 unsigned char flash_prog:1;
165 unsigned char unconfigured:1;
166 } __packed;
167 unsigned char data[1];
168 };
169};
170
171struct synaptics_rmi4_f1a_query {
172 union {
173 struct {
174 unsigned char max_button_count:3;
175 unsigned char reserved:5;
176 unsigned char has_general_control:1;
177 unsigned char has_interrupt_enable:1;
178 unsigned char has_multibutton_select:1;
179 unsigned char has_tx_rx_map:1;
180 unsigned char has_perbutton_threshold:1;
181 unsigned char has_release_threshold:1;
182 unsigned char has_strongestbtn_hysteresis:1;
183 unsigned char has_filter_strength:1;
184 } __packed;
185 unsigned char data[2];
186 };
187};
188
189struct synaptics_rmi4_f1a_control_0 {
190 union {
191 struct {
192 unsigned char multibutton_report:2;
193 unsigned char filter_mode:2;
194 unsigned char reserved:4;
195 } __packed;
196 unsigned char data[1];
197 };
198};
199
200struct synaptics_rmi4_f1a_control_3_4 {
201 unsigned char transmitterbutton;
202 unsigned char receiverbutton;
203};
204
205struct synaptics_rmi4_f1a_control {
206 struct synaptics_rmi4_f1a_control_0 general_control;
207 unsigned char *button_int_enable;
208 unsigned char *multi_button;
209 struct synaptics_rmi4_f1a_control_3_4 *electrode_map;
210 unsigned char *button_threshold;
211 unsigned char button_release_threshold;
212 unsigned char strongest_button_hysteresis;
213 unsigned char filter_strength;
214};
215
216struct synaptics_rmi4_f1a_handle {
217 int button_bitmask_size;
218 unsigned char button_count;
219 unsigned char valid_button_count;
220 unsigned char *button_data_buffer;
221 unsigned char *button_map;
222 struct synaptics_rmi4_f1a_query button_query;
223 struct synaptics_rmi4_f1a_control button_control;
224};
225
226struct synaptics_rmi4_exp_fn {
227 enum exp_fn fn_type;
228 bool inserted;
229 int (*func_init)(struct synaptics_rmi4_data *rmi4_data);
230 void (*func_remove)(struct synaptics_rmi4_data *rmi4_data);
231 void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
232 unsigned char intr_mask);
233 struct list_head link;
234};
235
236static struct device_attribute attrs[] = {
Amy Malochef46540d2013-02-15 17:09:43 -0800237#ifdef CONFIG_PM
Amy Maloche8b99ec92013-06-24 17:13:42 -0700238 __ATTR(full_pm_cycle, (S_IRUGO | S_IWUSR | S_IWGRP),
Alexandra Chin669d27c2012-12-24 15:42:30 +0800239 synaptics_rmi4_full_pm_cycle_show,
240 synaptics_rmi4_full_pm_cycle_store),
241#endif
Amy Maloche8b99ec92013-06-24 17:13:42 -0700242 __ATTR(reset, S_IRUGO | S_IWUSR | S_IWGRP,
Alexandra Chin669d27c2012-12-24 15:42:30 +0800243 synaptics_rmi4_show_error,
244 synaptics_rmi4_f01_reset_store),
245 __ATTR(productinfo, S_IRUGO,
246 synaptics_rmi4_f01_productinfo_show,
247 synaptics_rmi4_store_error),
248 __ATTR(buildid, S_IRUGO,
249 synaptics_rmi4_f01_buildid_show,
250 synaptics_rmi4_store_error),
251 __ATTR(flashprog, S_IRUGO,
252 synaptics_rmi4_f01_flashprog_show,
253 synaptics_rmi4_store_error),
Amy Maloche8b99ec92013-06-24 17:13:42 -0700254 __ATTR(0dbutton, (S_IRUGO | S_IWUSR | S_IWGRP),
Alexandra Chin669d27c2012-12-24 15:42:30 +0800255 synaptics_rmi4_0dbutton_show,
256 synaptics_rmi4_0dbutton_store),
Amy Maloche8b99ec92013-06-24 17:13:42 -0700257 __ATTR(flipx, (S_IRUGO | S_IWUSR | S_IWGRP),
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700258 synaptics_rmi4_flipx_show,
259 synaptics_rmi4_flipx_store),
Amy Maloche8b99ec92013-06-24 17:13:42 -0700260 __ATTR(flipy, (S_IRUGO | S_IWUSR | S_IWGRP),
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700261 synaptics_rmi4_flipy_show,
262 synaptics_rmi4_flipy_store),
Alexandra Chin669d27c2012-12-24 15:42:30 +0800263};
264
265static bool exp_fn_inited;
266static struct mutex exp_fn_list_mutex;
267static struct list_head exp_fn_list;
Amy Malochef46540d2013-02-15 17:09:43 -0800268#ifdef CONFIG_PM
Alexandra Chin669d27c2012-12-24 15:42:30 +0800269static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
270 struct device_attribute *attr, char *buf)
271{
272 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
273
274 return snprintf(buf, PAGE_SIZE, "%u\n",
275 rmi4_data->full_pm_cycle);
276}
277
278static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
279 struct device_attribute *attr, const char *buf, size_t count)
280{
281 unsigned int input;
282 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
283
284 if (sscanf(buf, "%u", &input) != 1)
285 return -EINVAL;
286
287 rmi4_data->full_pm_cycle = input > 0 ? 1 : 0;
288
289 return count;
290}
Amy Malochef46540d2013-02-15 17:09:43 -0800291
Amy Maloche986863d2013-06-10 15:13:57 -0700292static int synaptics_rmi4_debug_suspend_set(void *_data, u64 val)
Amy Maloche5210eeb2013-06-04 16:05:27 -0700293{
Amy Maloche986863d2013-06-10 15:13:57 -0700294 struct synaptics_rmi4_data *rmi4_data = _data;
Amy Maloche5210eeb2013-06-04 16:05:27 -0700295
Amy Maloche986863d2013-06-10 15:13:57 -0700296 if (val)
297 synaptics_rmi4_suspend(&rmi4_data->input_dev->dev);
298 else
299 synaptics_rmi4_resume(&rmi4_data->input_dev->dev);
Amy Maloche5210eeb2013-06-04 16:05:27 -0700300
Amy Maloche986863d2013-06-10 15:13:57 -0700301 return 0;
Amy Maloche5210eeb2013-06-04 16:05:27 -0700302}
303
Amy Maloche986863d2013-06-10 15:13:57 -0700304static ssize_t synaptics_rmi4_debug_suspend_get(void *_data, u64 *val)
Amy Maloche5210eeb2013-06-04 16:05:27 -0700305{
Amy Maloche986863d2013-06-10 15:13:57 -0700306 struct synaptics_rmi4_data *rmi4_data = _data;
Amy Maloche5210eeb2013-06-04 16:05:27 -0700307
Amy Maloche986863d2013-06-10 15:13:57 -0700308 *val = rmi4_data->suspended;
Amy Maloche5210eeb2013-06-04 16:05:27 -0700309
Amy Maloche986863d2013-06-10 15:13:57 -0700310 return 0;
Amy Maloche5210eeb2013-06-04 16:05:27 -0700311}
312
Amy Maloche986863d2013-06-10 15:13:57 -0700313DEFINE_SIMPLE_ATTRIBUTE(debug_suspend_fops, synaptics_rmi4_debug_suspend_get,
314 synaptics_rmi4_debug_suspend_set, "%lld\n");
315
Amy Malochef46540d2013-02-15 17:09:43 -0800316#ifdef CONFIG_FB
317static void configure_sleep(struct synaptics_rmi4_data *rmi4_data)
318{
319 int retval = 0;
320
321 rmi4_data->fb_notif.notifier_call = fb_notifier_callback;
322
323 retval = fb_register_client(&rmi4_data->fb_notif);
324 if (retval)
325 dev_err(&rmi4_data->i2c_client->dev,
326 "Unable to register fb_notifier: %d\n", retval);
327 return;
328}
329#elif defined CONFIG_HAS_EARLYSUSPEND
330static void configure_sleep(struct synaptics_rmi4_data *rmi4_data)
331{
332 rmi4_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
333 rmi4_data->early_suspend.suspend = synaptics_rmi4_early_suspend;
334 rmi4_data->early_suspend.resume = synaptics_rmi4_late_resume;
335 register_early_suspend(&rmi4_data->early_suspend);
336
337 return;
338}
339#else
340static void configure_sleep(struct synaptics_rmi4_data *rmi4_data)
341{
342 return;
343}
344#endif
Alexandra Chin669d27c2012-12-24 15:42:30 +0800345#endif
346
347static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
348 struct device_attribute *attr, const char *buf, size_t count)
349{
350 int retval;
351 unsigned int reset;
352 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
353
354 if (sscanf(buf, "%u", &reset) != 1)
355 return -EINVAL;
356
357 if (reset != 1)
358 return -EINVAL;
359
360 retval = synaptics_rmi4_reset_device(rmi4_data);
361 if (retval < 0) {
362 dev_err(dev,
363 "%s: Failed to issue reset command, error = %d\n",
364 __func__, retval);
365 return retval;
366 }
367
368 return count;
369}
370
371static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
372 struct device_attribute *attr, char *buf)
373{
374 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
375
376 return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
377 (rmi4_data->rmi4_mod_info.product_info[0]),
378 (rmi4_data->rmi4_mod_info.product_info[1]));
379}
380
381static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
382 struct device_attribute *attr, char *buf)
383{
384 unsigned int build_id;
385 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
386 struct synaptics_rmi4_device_info *rmi;
387
388 rmi = &(rmi4_data->rmi4_mod_info);
389
390 build_id = (unsigned int)rmi->build_id[0] +
391 (unsigned int)rmi->build_id[1] * 0x100 +
392 (unsigned int)rmi->build_id[2] * 0x10000;
393
394 return snprintf(buf, PAGE_SIZE, "%u\n",
395 build_id);
396}
397
398static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
399 struct device_attribute *attr, char *buf)
400{
401 int retval;
402 struct synaptics_rmi4_f01_device_status device_status;
403 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
404
405 retval = synaptics_rmi4_i2c_read(rmi4_data,
406 rmi4_data->f01_data_base_addr,
407 device_status.data,
408 sizeof(device_status.data));
409 if (retval < 0) {
410 dev_err(dev,
411 "%s: Failed to read device status, error = %d\n",
412 __func__, retval);
413 return retval;
414 }
415
416 return snprintf(buf, PAGE_SIZE, "%u\n",
417 device_status.flash_prog);
418}
419
420static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
421 struct device_attribute *attr, char *buf)
422{
423 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
424
425 return snprintf(buf, PAGE_SIZE, "%u\n",
426 rmi4_data->button_0d_enabled);
427}
428
429static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
430 struct device_attribute *attr, const char *buf, size_t count)
431{
432 int retval;
433 unsigned int input;
434 unsigned char ii;
435 unsigned char intr_enable;
436 struct synaptics_rmi4_fn *fhandler;
437 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
438 struct synaptics_rmi4_device_info *rmi;
439
440 rmi = &(rmi4_data->rmi4_mod_info);
441
442 if (sscanf(buf, "%u", &input) != 1)
443 return -EINVAL;
444
445 input = input > 0 ? 1 : 0;
446
447 if (rmi4_data->button_0d_enabled == input)
448 return count;
449
Alexandra Chind5591a62013-02-07 12:59:15 -0800450 if (!list_empty(&rmi->support_fn_list)) {
451 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
452 if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
453 ii = fhandler->intr_reg_num;
Alexandra Chin669d27c2012-12-24 15:42:30 +0800454
Alexandra Chind5591a62013-02-07 12:59:15 -0800455 retval = synaptics_rmi4_i2c_read(rmi4_data,
456 rmi4_data->f01_ctrl_base_addr +
457 1 + ii,
458 &intr_enable,
459 sizeof(intr_enable));
460 if (retval < 0)
461 return retval;
Alexandra Chin669d27c2012-12-24 15:42:30 +0800462
Alexandra Chind5591a62013-02-07 12:59:15 -0800463 if (input == 1)
464 intr_enable |= fhandler->intr_mask;
465 else
466 intr_enable &= ~fhandler->intr_mask;
Alexandra Chin669d27c2012-12-24 15:42:30 +0800467
Alexandra Chind5591a62013-02-07 12:59:15 -0800468 retval = synaptics_rmi4_i2c_write(rmi4_data,
469 rmi4_data->f01_ctrl_base_addr +
470 1 + ii,
471 &intr_enable,
472 sizeof(intr_enable));
473 if (retval < 0)
474 return retval;
475 }
Alexandra Chin669d27c2012-12-24 15:42:30 +0800476 }
477 }
478
479 rmi4_data->button_0d_enabled = input;
480
481 return count;
482}
483
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700484static ssize_t synaptics_rmi4_flipx_show(struct device *dev,
485 struct device_attribute *attr, char *buf)
486{
487 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
488
489 return snprintf(buf, PAGE_SIZE, "%u\n",
490 rmi4_data->flip_x);
491}
492
493static ssize_t synaptics_rmi4_flipx_store(struct device *dev,
494 struct device_attribute *attr, const char *buf, size_t count)
495{
496 unsigned int input;
497 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
498
499 if (sscanf(buf, "%u", &input) != 1)
500 return -EINVAL;
501
502 rmi4_data->flip_x = input > 0 ? 1 : 0;
503
504 return count;
505}
506
507static ssize_t synaptics_rmi4_flipy_show(struct device *dev,
508 struct device_attribute *attr, char *buf)
509{
510 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
511
512 return snprintf(buf, PAGE_SIZE, "%u\n",
513 rmi4_data->flip_y);
514}
515
516static ssize_t synaptics_rmi4_flipy_store(struct device *dev,
517 struct device_attribute *attr, const char *buf, size_t count)
518{
519 unsigned int input;
520 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
521
522 if (sscanf(buf, "%u", &input) != 1)
523 return -EINVAL;
524
525 rmi4_data->flip_y = input > 0 ? 1 : 0;
526
527 return count;
528}
529
Alexandra Chin669d27c2012-12-24 15:42:30 +0800530 /**
531 * synaptics_rmi4_set_page()
532 *
533 * Called by synaptics_rmi4_i2c_read() and synaptics_rmi4_i2c_write().
534 *
535 * This function writes to the page select register to switch to the
536 * assigned page.
537 */
538static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *rmi4_data,
539 unsigned int address)
540{
541 int retval = 0;
542 unsigned char retry;
543 unsigned char buf[PAGE_SELECT_LEN];
544 unsigned char page;
545 struct i2c_client *i2c = rmi4_data->i2c_client;
546
547 page = ((address >> 8) & MASK_8BIT);
548 if (page != rmi4_data->current_page) {
549 buf[0] = MASK_8BIT;
550 buf[1] = page;
551 for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
552 retval = i2c_master_send(i2c, buf, PAGE_SELECT_LEN);
553 if (retval != PAGE_SELECT_LEN) {
554 dev_err(&i2c->dev,
555 "%s: I2C retry %d\n",
556 __func__, retry + 1);
557 msleep(20);
558 } else {
559 rmi4_data->current_page = page;
560 break;
561 }
562 }
563 } else
564 return PAGE_SELECT_LEN;
565 return (retval == PAGE_SELECT_LEN) ? retval : -EIO;
566}
567
568 /**
569 * synaptics_rmi4_i2c_read()
570 *
571 * Called by various functions in this driver, and also exported to
572 * other expansion Function modules such as rmi_dev.
573 *
574 * This function reads data of an arbitrary length from the sensor,
575 * starting from an assigned register address of the sensor, via I2C
576 * with a retry mechanism.
577 */
578static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
579 unsigned short addr, unsigned char *data, unsigned short length)
580{
581 int retval;
582 unsigned char retry;
583 unsigned char buf;
584 struct i2c_msg msg[] = {
585 {
586 .addr = rmi4_data->i2c_client->addr,
587 .flags = 0,
588 .len = 1,
589 .buf = &buf,
590 },
591 {
592 .addr = rmi4_data->i2c_client->addr,
593 .flags = I2C_M_RD,
594 .len = length,
595 .buf = data,
596 },
597 };
598
599 buf = addr & MASK_8BIT;
600
601 mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
602
603 retval = synaptics_rmi4_set_page(rmi4_data, addr);
604 if (retval != PAGE_SELECT_LEN)
605 goto exit;
606
607 for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
608 if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 2) == 2) {
609 retval = length;
610 break;
611 }
612 dev_err(&rmi4_data->i2c_client->dev,
613 "%s: I2C retry %d\n",
614 __func__, retry + 1);
615 msleep(20);
616 }
617
618 if (retry == SYN_I2C_RETRY_TIMES) {
619 dev_err(&rmi4_data->i2c_client->dev,
620 "%s: I2C read over retry limit\n",
621 __func__);
622 retval = -EIO;
623 }
624
625exit:
626 mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
627
628 return retval;
629}
630
631 /**
632 * synaptics_rmi4_i2c_write()
633 *
634 * Called by various functions in this driver, and also exported to
635 * other expansion Function modules such as rmi_dev.
636 *
637 * This function writes data of an arbitrary length to the sensor,
638 * starting from an assigned register address of the sensor, via I2C with
639 * a retry mechanism.
640 */
641static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
642 unsigned short addr, unsigned char *data, unsigned short length)
643{
644 int retval;
645 unsigned char retry;
646 unsigned char buf[length + 1];
647 struct i2c_msg msg[] = {
648 {
649 .addr = rmi4_data->i2c_client->addr,
650 .flags = 0,
651 .len = length + 1,
652 .buf = buf,
653 }
654 };
655
656 mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
657
658 retval = synaptics_rmi4_set_page(rmi4_data, addr);
659 if (retval != PAGE_SELECT_LEN)
660 goto exit;
661
662 buf[0] = addr & MASK_8BIT;
663 memcpy(&buf[1], &data[0], length);
664
665 for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
666 if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 1) == 1) {
667 retval = length;
668 break;
669 }
670 dev_err(&rmi4_data->i2c_client->dev,
671 "%s: I2C retry %d\n",
672 __func__, retry + 1);
673 msleep(20);
674 }
675
676 if (retry == SYN_I2C_RETRY_TIMES) {
677 dev_err(&rmi4_data->i2c_client->dev,
678 "%s: I2C write over retry limit\n",
679 __func__);
680 retval = -EIO;
681 }
682
683exit:
684 mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
685
686 return retval;
687}
688
689 /**
690 * synaptics_rmi4_f11_abs_report()
691 *
692 * Called by synaptics_rmi4_report_touch() when valid Function $11
693 * finger data has been detected.
694 *
695 * This function reads the Function $11 data registers, determines the
696 * status of each finger supported by the Function, processes any
697 * necessary coordinate manipulation, reports the finger data to
698 * the input subsystem, and returns the number of fingers detected.
699 */
700static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data,
701 struct synaptics_rmi4_fn *fhandler)
702{
703 int retval;
704 unsigned char touch_count = 0; /* number of touch points */
705 unsigned char reg_index;
706 unsigned char finger;
707 unsigned char fingers_supported;
708 unsigned char num_of_finger_status_regs;
709 unsigned char finger_shift;
710 unsigned char finger_status;
711 unsigned char data_reg_blk_size;
712 unsigned char finger_status_reg[3];
713 unsigned char data[F11_STD_DATA_LEN];
714 unsigned short data_addr;
715 unsigned short data_offset;
716 int x;
717 int y;
718 int wx;
719 int wy;
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700720 int z;
Alexandra Chin669d27c2012-12-24 15:42:30 +0800721
722 /*
723 * The number of finger status registers is determined by the
724 * maximum number of fingers supported - 2 bits per finger. So
725 * the number of finger status registers to read is:
726 * register_count = ceil(max_num_of_fingers / 4)
727 */
728 fingers_supported = fhandler->num_of_data_points;
729 num_of_finger_status_regs = (fingers_supported + 3) / 4;
730 data_addr = fhandler->full_addr.data_base;
731 data_reg_blk_size = fhandler->size_of_data_register_block;
732
733 retval = synaptics_rmi4_i2c_read(rmi4_data,
734 data_addr,
735 finger_status_reg,
736 num_of_finger_status_regs);
737 if (retval < 0)
738 return 0;
739
740 for (finger = 0; finger < fingers_supported; finger++) {
741 reg_index = finger / 4;
742 finger_shift = (finger % 4) * 2;
743 finger_status = (finger_status_reg[reg_index] >> finger_shift)
744 & MASK_2BIT;
745
746 /*
747 * Each 2-bit finger status field represents the following:
748 * 00 = finger not present
749 * 01 = finger present and data accurate
750 * 10 = finger present but data may be inaccurate
751 * 11 = reserved
752 */
753#ifdef TYPE_B_PROTOCOL
754 input_mt_slot(rmi4_data->input_dev, finger);
755 input_mt_report_slot_state(rmi4_data->input_dev,
756 MT_TOOL_FINGER, finger_status != 0);
757#endif
758
759 if (finger_status) {
760 data_offset = data_addr +
761 num_of_finger_status_regs +
762 (finger * data_reg_blk_size);
763 retval = synaptics_rmi4_i2c_read(rmi4_data,
764 data_offset,
765 data,
766 data_reg_blk_size);
767 if (retval < 0)
768 return 0;
769
770 x = (data[0] << 4) | (data[2] & MASK_4BIT);
771 y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
772 wx = (data[3] & MASK_4BIT);
773 wy = (data[3] >> 4) & MASK_4BIT;
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700774 z = data[4];
Alexandra Chin669d27c2012-12-24 15:42:30 +0800775
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700776 if (rmi4_data->flip_x)
Alexandra Chin669d27c2012-12-24 15:42:30 +0800777 x = rmi4_data->sensor_max_x - x;
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700778 if (rmi4_data->flip_y)
Alexandra Chin669d27c2012-12-24 15:42:30 +0800779 y = rmi4_data->sensor_max_y - y;
780
781 dev_dbg(&rmi4_data->i2c_client->dev,
782 "%s: Finger %d:\n"
783 "status = 0x%02x\n"
784 "x = %d\n"
785 "y = %d\n"
786 "wx = %d\n"
787 "wy = %d\n",
788 __func__, finger,
789 finger_status,
790 x, y, wx, wy);
791
Alexandra Chin669d27c2012-12-24 15:42:30 +0800792 input_report_abs(rmi4_data->input_dev,
793 ABS_MT_POSITION_X, x);
794 input_report_abs(rmi4_data->input_dev,
795 ABS_MT_POSITION_Y, y);
Alexandra Chinfb798fa2013-03-26 17:15:38 -0700796 input_report_abs(rmi4_data->input_dev,
797 ABS_MT_PRESSURE, z);
Alexandra Chind5591a62013-02-07 12:59:15 -0800798
Alexandra Chin669d27c2012-12-24 15:42:30 +0800799#ifdef REPORT_2D_W
800 input_report_abs(rmi4_data->input_dev,
801 ABS_MT_TOUCH_MAJOR, max(wx, wy));
802 input_report_abs(rmi4_data->input_dev,
803 ABS_MT_TOUCH_MINOR, min(wx, wy));
804#endif
Alexandra Chind5591a62013-02-07 12:59:15 -0800805#ifndef TYPE_B_PROTOCOL
Alexandra Chin669d27c2012-12-24 15:42:30 +0800806 input_mt_sync(rmi4_data->input_dev);
807#endif
808 touch_count++;
809 }
810 }
811
Amy Malocheecfb4892013-02-06 13:30:36 -0800812 input_report_key(rmi4_data->input_dev, BTN_TOUCH, touch_count > 0);
813 input_report_key(rmi4_data->input_dev,
814 BTN_TOOL_FINGER, touch_count > 0);
815
Alexandra Chin669d27c2012-12-24 15:42:30 +0800816#ifndef TYPE_B_PROTOCOL
817 if (!touch_count)
818 input_mt_sync(rmi4_data->input_dev);
819#else
820 /* sync after groups of events */
821 #ifdef KERNEL_ABOVE_3_7
822 input_mt_sync_frame(rmi4_data->input_dev);
823 #endif
824#endif
825
826 input_sync(rmi4_data->input_dev);
827
828 return touch_count;
829}
830
831static void synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data,
832 struct synaptics_rmi4_fn *fhandler)
833{
834 int retval;
835 unsigned char button;
836 unsigned char index;
837 unsigned char shift;
838 unsigned char status;
839 unsigned char *data;
840 unsigned short data_addr = fhandler->full_addr.data_base;
841 struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
842 static unsigned char do_once = 1;
843 static bool current_status[MAX_NUMBER_OF_BUTTONS];
844#ifdef NO_0D_WHILE_2D
845 static bool before_2d_status[MAX_NUMBER_OF_BUTTONS];
846 static bool while_2d_status[MAX_NUMBER_OF_BUTTONS];
847#endif
848
849 if (do_once) {
850 memset(current_status, 0, sizeof(current_status));
851#ifdef NO_0D_WHILE_2D
852 memset(before_2d_status, 0, sizeof(before_2d_status));
853 memset(while_2d_status, 0, sizeof(while_2d_status));
854#endif
855 do_once = 0;
856 }
857
858 retval = synaptics_rmi4_i2c_read(rmi4_data,
859 data_addr,
860 f1a->button_data_buffer,
861 f1a->button_bitmask_size);
862 if (retval < 0) {
863 dev_err(&rmi4_data->i2c_client->dev,
864 "%s: Failed to read button data registers\n",
865 __func__);
866 return;
867 }
868
869 data = f1a->button_data_buffer;
870
871 for (button = 0; button < f1a->valid_button_count; button++) {
872 index = button / 8;
873 shift = button % 8;
874 status = ((data[index] >> shift) & MASK_1BIT);
875
876 if (current_status[button] == status)
877 continue;
878 else
879 current_status[button] = status;
880
881 dev_dbg(&rmi4_data->i2c_client->dev,
882 "%s: Button %d (code %d) ->%d\n",
883 __func__, button,
884 f1a->button_map[button],
885 status);
886#ifdef NO_0D_WHILE_2D
887 if (rmi4_data->fingers_on_2d == false) {
888 if (status == 1) {
889 before_2d_status[button] = 1;
890 } else {
891 if (while_2d_status[button] == 1) {
892 while_2d_status[button] = 0;
893 continue;
894 } else {
895 before_2d_status[button] = 0;
896 }
897 }
898 input_report_key(rmi4_data->input_dev,
899 f1a->button_map[button],
900 status);
901 } else {
902 if (before_2d_status[button] == 1) {
903 before_2d_status[button] = 0;
904 input_report_key(rmi4_data->input_dev,
905 f1a->button_map[button],
906 status);
907 } else {
908 if (status == 1)
909 while_2d_status[button] = 1;
910 else
911 while_2d_status[button] = 0;
912 }
913 }
914#else
915 input_report_key(rmi4_data->input_dev,
916 f1a->button_map[button],
917 status);
918#endif
919 }
920
921 input_sync(rmi4_data->input_dev);
922
923 return;
924}
925
926 /**
927 * synaptics_rmi4_report_touch()
928 *
929 * Called by synaptics_rmi4_sensor_report().
930 *
931 * This function calls the appropriate finger data reporting function
932 * based on the function handler it receives and returns the number of
933 * fingers detected.
934 */
935static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data,
936 struct synaptics_rmi4_fn *fhandler,
937 unsigned char *touch_count)
938{
939 unsigned char touch_count_2d;
940
941 dev_dbg(&rmi4_data->i2c_client->dev,
942 "%s: Function %02x reporting\n",
943 __func__, fhandler->fn_number);
944
945 switch (fhandler->fn_number) {
946 case SYNAPTICS_RMI4_F11:
947 touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data,
948 fhandler);
949
950 *touch_count += touch_count_2d;
951
952 if (touch_count_2d)
953 rmi4_data->fingers_on_2d = true;
954 else
955 rmi4_data->fingers_on_2d = false;
956 break;
957
958 case SYNAPTICS_RMI4_F1A:
959 synaptics_rmi4_f1a_report(rmi4_data, fhandler);
960 break;
961
962 default:
963 break;
964 }
965
966 return;
967}
968
969 /**
970 * synaptics_rmi4_sensor_report()
971 *
972 * Called by synaptics_rmi4_irq().
973 *
974 * This function determines the interrupt source(s) from the sensor
975 * and calls synaptics_rmi4_report_touch() with the appropriate
976 * function handler for each function with valid data inputs.
977 */
978static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data)
979{
980 int retval;
981 unsigned char touch_count = 0;
982 unsigned char intr[MAX_INTR_REGISTERS];
983 struct synaptics_rmi4_fn *fhandler;
984 struct synaptics_rmi4_exp_fn *exp_fhandler;
985 struct synaptics_rmi4_device_info *rmi;
986
987 rmi = &(rmi4_data->rmi4_mod_info);
988
989 /*
990 * Get interrupt status information from F01 Data1 register to
991 * determine the source(s) that are flagging the interrupt.
992 */
993 retval = synaptics_rmi4_i2c_read(rmi4_data,
994 rmi4_data->f01_data_base_addr + 1,
995 intr,
996 rmi4_data->num_of_intr_regs);
997 if (retval < 0)
998 return retval;
999
1000 /*
1001 * Traverse the function handler list and service the source(s)
1002 * of the interrupt accordingly.
1003 */
Alexandra Chind5591a62013-02-07 12:59:15 -08001004 if (!list_empty(&rmi->support_fn_list)) {
1005 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
1006 if (fhandler->num_of_data_sources) {
1007 if (fhandler->intr_mask &
1008 intr[fhandler->intr_reg_num]) {
1009 synaptics_rmi4_report_touch(rmi4_data,
1010 fhandler, &touch_count);
1011 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001012 }
1013 }
1014 }
1015
1016 mutex_lock(&exp_fn_list_mutex);
1017 if (!list_empty(&exp_fn_list)) {
1018 list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
1019 if (exp_fhandler->inserted &&
1020 (exp_fhandler->func_attn != NULL))
1021 exp_fhandler->func_attn(rmi4_data, intr[0]);
1022 }
1023 }
1024 mutex_unlock(&exp_fn_list_mutex);
1025
1026 return touch_count;
1027}
1028
1029 /**
1030 * synaptics_rmi4_irq()
1031 *
1032 * Called by the kernel when an interrupt occurs (when the sensor
1033 * asserts the attention irq).
1034 *
1035 * This function is the ISR thread and handles the acquisition
1036 * and the reporting of finger data when the presence of fingers
1037 * is detected.
1038 */
1039static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
1040{
1041 struct synaptics_rmi4_data *rmi4_data = data;
1042
1043 synaptics_rmi4_sensor_report(rmi4_data);
1044
1045 return IRQ_HANDLED;
1046}
1047
Amy Malocheecfb4892013-02-06 13:30:36 -08001048static int synaptics_rmi4_parse_dt(struct device *dev,
1049 struct synaptics_rmi4_platform_data *rmi4_pdata)
1050{
1051 struct device_node *np = dev->of_node;
1052 struct property *prop;
1053 u32 temp_val, num_buttons;
1054 u32 button_map[MAX_NUMBER_OF_BUTTONS];
1055 int rc, i;
1056
1057 rmi4_pdata->i2c_pull_up = of_property_read_bool(np,
1058 "synaptics,i2c-pull-up");
Amy Malocheecfb4892013-02-06 13:30:36 -08001059 rmi4_pdata->x_flip = of_property_read_bool(np, "synaptics,x-flip");
1060 rmi4_pdata->y_flip = of_property_read_bool(np, "synaptics,y-flip");
1061
1062 rc = of_property_read_u32(np, "synaptics,panel-x", &temp_val);
1063 if (rc && (rc != -EINVAL)) {
1064 dev_err(dev, "Unable to read panel X dimension\n");
1065 return rc;
1066 } else {
1067 rmi4_pdata->panel_x = temp_val;
1068 }
1069
1070 rc = of_property_read_u32(np, "synaptics,panel-y", &temp_val);
1071 if (rc && (rc != -EINVAL)) {
1072 dev_err(dev, "Unable to read panel Y dimension\n");
1073 return rc;
1074 } else {
1075 rmi4_pdata->panel_y = temp_val;
1076 }
1077
Amy Malochecb835832013-03-26 18:06:05 -07001078 rc = of_property_read_string(np, "synaptics,fw-image-name",
1079 &rmi4_pdata->fw_image_name);
1080 if (rc && (rc != -EINVAL)) {
1081 dev_err(dev, "Unable to read fw image name\n");
1082 return rc;
1083 }
1084
Amy Malocheecfb4892013-02-06 13:30:36 -08001085 /* reset, irq gpio info */
1086 rmi4_pdata->reset_gpio = of_get_named_gpio_flags(np,
1087 "synaptics,reset-gpio", 0, &rmi4_pdata->reset_flags);
1088 rmi4_pdata->irq_gpio = of_get_named_gpio_flags(np,
1089 "synaptics,irq-gpio", 0, &rmi4_pdata->irq_flags);
1090
1091 prop = of_find_property(np, "synaptics,button-map", NULL);
1092 if (prop) {
1093 num_buttons = prop->length / sizeof(temp_val);
1094
1095 rmi4_pdata->capacitance_button_map = devm_kzalloc(dev,
1096 sizeof(*rmi4_pdata->capacitance_button_map),
1097 GFP_KERNEL);
1098 if (!rmi4_pdata->capacitance_button_map)
1099 return -ENOMEM;
1100
1101 rmi4_pdata->capacitance_button_map->map = devm_kzalloc(dev,
1102 sizeof(*rmi4_pdata->capacitance_button_map->map) *
1103 MAX_NUMBER_OF_BUTTONS, GFP_KERNEL);
1104 if (!rmi4_pdata->capacitance_button_map->map)
1105 return -ENOMEM;
1106
1107 if (num_buttons <= MAX_NUMBER_OF_BUTTONS) {
1108 rc = of_property_read_u32_array(np,
1109 "synaptics,button-map", button_map,
1110 num_buttons);
1111 if (rc) {
1112 dev_err(dev, "Unable to read key codes\n");
1113 return rc;
1114 }
1115 for (i = 0; i < num_buttons; i++)
1116 rmi4_pdata->capacitance_button_map->map[i] =
1117 button_map[i];
1118 rmi4_pdata->capacitance_button_map->nbuttons =
1119 num_buttons;
1120 } else {
1121 return -EINVAL;
1122 }
1123 }
1124 return 0;
1125}
1126
Alexandra Chin669d27c2012-12-24 15:42:30 +08001127 /**
1128 * synaptics_rmi4_irq_enable()
1129 *
1130 * Called by synaptics_rmi4_probe() and the power management functions
1131 * in this driver and also exported to other expansion Function modules
1132 * such as rmi_dev.
1133 *
1134 * This function handles the enabling and disabling of the attention
1135 * irq including the setting up of the ISR thread.
1136 */
1137static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
1138 bool enable)
1139{
1140 int retval = 0;
Amy Maloche5c7b5d52013-04-29 10:40:41 -07001141 unsigned char *intr_status;
Alexandra Chin669d27c2012-12-24 15:42:30 +08001142
1143 if (enable) {
1144 if (rmi4_data->irq_enabled)
1145 return retval;
1146
Amy Maloche5c7b5d52013-04-29 10:40:41 -07001147 intr_status = kzalloc(rmi4_data->num_of_intr_regs, GFP_KERNEL);
1148 if (!intr_status) {
1149 dev_err(&rmi4_data->i2c_client->dev,
1150 "%s: Failed to alloc memory\n",
1151 __func__);
1152 return -ENOMEM;
1153 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001154 /* Clear interrupts first */
1155 retval = synaptics_rmi4_i2c_read(rmi4_data,
1156 rmi4_data->f01_data_base_addr + 1,
Amy Maloche5c7b5d52013-04-29 10:40:41 -07001157 intr_status,
Alexandra Chin669d27c2012-12-24 15:42:30 +08001158 rmi4_data->num_of_intr_regs);
Amy Maloche5c7b5d52013-04-29 10:40:41 -07001159 kfree(intr_status);
Alexandra Chin669d27c2012-12-24 15:42:30 +08001160 if (retval < 0)
1161 return retval;
1162
Alexandra Chinfb798fa2013-03-26 17:15:38 -07001163 enable_irq(rmi4_data->irq);
Alexandra Chin669d27c2012-12-24 15:42:30 +08001164
1165 rmi4_data->irq_enabled = true;
1166 } else {
1167 if (rmi4_data->irq_enabled) {
1168 disable_irq(rmi4_data->irq);
Alexandra Chin669d27c2012-12-24 15:42:30 +08001169 rmi4_data->irq_enabled = false;
1170 }
1171 }
1172
1173 return retval;
1174}
1175
1176 /**
1177 * synaptics_rmi4_f11_init()
1178 *
1179 * Called by synaptics_rmi4_query_device().
1180 *
1181 * This funtion parses information from the Function 11 registers
1182 * and determines the number of fingers supported, x and y data ranges,
1183 * offset to the associated interrupt status register, interrupt bit
1184 * mask, and gathers finger data acquisition capabilities from the query
1185 * registers.
1186 */
1187static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data,
1188 struct synaptics_rmi4_fn *fhandler,
1189 struct synaptics_rmi4_fn_desc *fd,
1190 unsigned int intr_count)
1191{
1192 int retval;
1193 unsigned char ii;
1194 unsigned char intr_offset;
1195 unsigned char abs_data_size;
1196 unsigned char abs_data_blk_size;
1197 unsigned char query[F11_STD_QUERY_LEN];
1198 unsigned char control[F11_STD_CTRL_LEN];
1199
1200 fhandler->fn_number = fd->fn_number;
1201 fhandler->num_of_data_sources = fd->intr_src_count;
1202
1203 retval = synaptics_rmi4_i2c_read(rmi4_data,
1204 fhandler->full_addr.query_base,
1205 query,
1206 sizeof(query));
1207 if (retval < 0)
1208 return retval;
1209
1210 /* Maximum number of fingers supported */
1211 if ((query[1] & MASK_3BIT) <= 4)
1212 fhandler->num_of_data_points = (query[1] & MASK_3BIT) + 1;
1213 else if ((query[1] & MASK_3BIT) == 5)
1214 fhandler->num_of_data_points = 10;
1215
1216 rmi4_data->num_of_fingers = fhandler->num_of_data_points;
1217
1218 retval = synaptics_rmi4_i2c_read(rmi4_data,
1219 fhandler->full_addr.ctrl_base,
1220 control,
1221 sizeof(control));
1222 if (retval < 0)
1223 return retval;
1224
1225 /* Maximum x and y */
1226 rmi4_data->sensor_max_x = ((control[6] & MASK_8BIT) << 0) |
1227 ((control[7] & MASK_4BIT) << 8);
1228 rmi4_data->sensor_max_y = ((control[8] & MASK_8BIT) << 0) |
1229 ((control[9] & MASK_4BIT) << 8);
1230 dev_dbg(&rmi4_data->i2c_client->dev,
1231 "%s: Function %02x max x = %d max y = %d\n",
1232 __func__, fhandler->fn_number,
1233 rmi4_data->sensor_max_x,
1234 rmi4_data->sensor_max_y);
1235
1236 fhandler->intr_reg_num = (intr_count + 7) / 8;
1237 if (fhandler->intr_reg_num != 0)
1238 fhandler->intr_reg_num -= 1;
1239
1240 /* Set an enable bit for each data source */
1241 intr_offset = intr_count % 8;
1242 fhandler->intr_mask = 0;
1243 for (ii = intr_offset;
1244 ii < ((fd->intr_src_count & MASK_3BIT) +
1245 intr_offset);
1246 ii++)
1247 fhandler->intr_mask |= 1 << ii;
1248
1249 abs_data_size = query[5] & MASK_2BIT;
1250 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
1251 fhandler->size_of_data_register_block = abs_data_blk_size;
1252
1253 return retval;
1254}
1255
1256static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data,
1257 struct synaptics_rmi4_fn *fhandler)
1258{
1259 int retval;
1260 struct synaptics_rmi4_f1a_handle *f1a;
1261
1262 f1a = kzalloc(sizeof(*f1a), GFP_KERNEL);
1263 if (!f1a) {
1264 dev_err(&rmi4_data->i2c_client->dev,
1265 "%s: Failed to alloc mem for function handle\n",
1266 __func__);
1267 return -ENOMEM;
1268 }
1269
1270 fhandler->data = (void *)f1a;
1271
1272 retval = synaptics_rmi4_i2c_read(rmi4_data,
1273 fhandler->full_addr.query_base,
1274 f1a->button_query.data,
1275 sizeof(f1a->button_query.data));
1276 if (retval < 0) {
1277 dev_err(&rmi4_data->i2c_client->dev,
1278 "%s: Failed to read query registers\n",
1279 __func__);
1280 return retval;
1281 }
1282
1283 f1a->button_count = f1a->button_query.max_button_count + 1;
1284 f1a->button_bitmask_size = (f1a->button_count + 7) / 8;
1285
1286 f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size,
1287 sizeof(*(f1a->button_data_buffer)), GFP_KERNEL);
1288 if (!f1a->button_data_buffer) {
1289 dev_err(&rmi4_data->i2c_client->dev,
1290 "%s: Failed to alloc mem for data buffer\n",
1291 __func__);
1292 return -ENOMEM;
1293 }
1294
1295 f1a->button_map = kcalloc(f1a->button_count,
1296 sizeof(*(f1a->button_map)), GFP_KERNEL);
1297 if (!f1a->button_map) {
1298 dev_err(&rmi4_data->i2c_client->dev,
1299 "%s: Failed to alloc mem for button map\n",
1300 __func__);
1301 return -ENOMEM;
1302 }
1303
1304 return 0;
1305}
1306
1307static int synaptics_rmi4_capacitance_button_map(
1308 struct synaptics_rmi4_data *rmi4_data,
1309 struct synaptics_rmi4_fn *fhandler)
1310{
1311 unsigned char ii;
1312 struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
1313 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1314
1315 if (!pdata->capacitance_button_map) {
1316 dev_err(&rmi4_data->i2c_client->dev,
Alexandra Chind5591a62013-02-07 12:59:15 -08001317 "%s: capacitance_button_map is" \
1318 "NULL in board file\n",
Alexandra Chin669d27c2012-12-24 15:42:30 +08001319 __func__);
1320 return -ENODEV;
1321 } else if (!pdata->capacitance_button_map->map) {
1322 dev_err(&rmi4_data->i2c_client->dev,
1323 "%s: Button map is missing in board file\n",
1324 __func__);
1325 return -ENODEV;
1326 } else {
1327 if (pdata->capacitance_button_map->nbuttons !=
1328 f1a->button_count) {
1329 f1a->valid_button_count = min(f1a->button_count,
1330 pdata->capacitance_button_map->nbuttons);
1331 } else {
1332 f1a->valid_button_count = f1a->button_count;
1333 }
1334
1335 for (ii = 0; ii < f1a->valid_button_count; ii++)
1336 f1a->button_map[ii] =
1337 pdata->capacitance_button_map->map[ii];
1338 }
1339
1340 return 0;
1341}
1342
1343static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler)
1344{
1345 struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
1346
1347 if (f1a) {
1348 kfree(f1a->button_data_buffer);
1349 kfree(f1a->button_map);
1350 kfree(f1a);
1351 fhandler->data = NULL;
1352 }
1353
1354 return;
1355}
1356
1357static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data,
1358 struct synaptics_rmi4_fn *fhandler,
1359 struct synaptics_rmi4_fn_desc *fd,
1360 unsigned int intr_count)
1361{
1362 int retval;
1363 unsigned char ii;
1364 unsigned short intr_offset;
1365
1366 fhandler->fn_number = fd->fn_number;
1367 fhandler->num_of_data_sources = fd->intr_src_count;
1368
1369 fhandler->intr_reg_num = (intr_count + 7) / 8;
1370 if (fhandler->intr_reg_num != 0)
1371 fhandler->intr_reg_num -= 1;
1372
1373 /* Set an enable bit for each data source */
1374 intr_offset = intr_count % 8;
1375 fhandler->intr_mask = 0;
1376 for (ii = intr_offset;
1377 ii < ((fd->intr_src_count & MASK_3BIT) +
1378 intr_offset);
1379 ii++)
1380 fhandler->intr_mask |= 1 << ii;
1381
1382 retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler);
1383 if (retval < 0)
1384 goto error_exit;
1385
1386 retval = synaptics_rmi4_capacitance_button_map(rmi4_data, fhandler);
1387 if (retval < 0)
1388 goto error_exit;
1389
1390 rmi4_data->button_0d_enabled = 1;
1391
1392 return 0;
1393
1394error_exit:
1395 synaptics_rmi4_f1a_kfree(fhandler);
1396
1397 return retval;
1398}
1399
1400static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler,
1401 struct synaptics_rmi4_fn_desc *rmi_fd, int page_number)
1402{
Alexandra Chinfb798fa2013-03-26 17:15:38 -07001403 *fhandler = kzalloc(sizeof(**fhandler), GFP_KERNEL);
Alexandra Chin669d27c2012-12-24 15:42:30 +08001404 if (!(*fhandler))
1405 return -ENOMEM;
1406
1407 (*fhandler)->full_addr.data_base =
1408 (rmi_fd->data_base_addr |
1409 (page_number << 8));
1410 (*fhandler)->full_addr.ctrl_base =
1411 (rmi_fd->ctrl_base_addr |
1412 (page_number << 8));
1413 (*fhandler)->full_addr.cmd_base =
1414 (rmi_fd->cmd_base_addr |
1415 (page_number << 8));
1416 (*fhandler)->full_addr.query_base =
1417 (rmi_fd->query_base_addr |
1418 (page_number << 8));
Alexandra Chinfb798fa2013-03-26 17:15:38 -07001419 (*fhandler)->fn_number = rmi_fd->fn_number;
Alexandra Chin669d27c2012-12-24 15:42:30 +08001420
1421 return 0;
1422}
1423
Alexandra Chind5591a62013-02-07 12:59:15 -08001424
1425 /**
1426 * synaptics_rmi4_query_device_info()
1427 *
1428 * Called by synaptics_rmi4_query_device().
1429 *
1430 */
1431static int synaptics_rmi4_query_device_info(
1432 struct synaptics_rmi4_data *rmi4_data)
1433{
1434 int retval;
1435 unsigned char f01_query[F01_STD_QUERY_LEN];
1436 struct synaptics_rmi4_device_info *rmi = &(rmi4_data->rmi4_mod_info);
1437
1438 retval = synaptics_rmi4_i2c_read(rmi4_data,
1439 rmi4_data->f01_query_base_addr,
1440 f01_query,
1441 sizeof(f01_query));
1442 if (retval < 0)
1443 return retval;
1444
1445 /* RMI Version 4.0 currently supported */
1446 rmi->version_major = 4;
1447 rmi->version_minor = 0;
1448
1449 rmi->manufacturer_id = f01_query[0];
1450 rmi->product_props = f01_query[1];
1451 rmi->product_info[0] = f01_query[2] & MASK_7BIT;
1452 rmi->product_info[1] = f01_query[3] & MASK_7BIT;
1453 rmi->date_code[0] = f01_query[4] & MASK_5BIT;
1454 rmi->date_code[1] = f01_query[5] & MASK_4BIT;
1455 rmi->date_code[2] = f01_query[6] & MASK_5BIT;
1456 rmi->tester_id = ((f01_query[7] & MASK_7BIT) << 8) |
1457 (f01_query[8] & MASK_7BIT);
1458 rmi->serial_number = ((f01_query[9] & MASK_7BIT) << 8) |
1459 (f01_query[10] & MASK_7BIT);
1460 memcpy(rmi->product_id_string, &f01_query[11], 10);
1461
1462 if (rmi->manufacturer_id != 1) {
1463 dev_err(&rmi4_data->i2c_client->dev,
1464 "%s: Non-Synaptics device found, manufacturer ID = %d\n",
1465 __func__, rmi->manufacturer_id);
1466 }
1467
1468 retval = synaptics_rmi4_i2c_read(rmi4_data,
1469 rmi4_data->f01_query_base_addr + F01_BUID_ID_OFFSET,
1470 rmi->build_id,
1471 sizeof(rmi->build_id));
1472 if (retval < 0) {
1473 dev_err(&rmi4_data->i2c_client->dev,
1474 "%s: Failed to read firmware build id (code %d)\n",
1475 __func__, retval);
1476 return retval;
1477 }
Alexandra Chinfb798fa2013-03-26 17:15:38 -07001478 return 0;
Alexandra Chind5591a62013-02-07 12:59:15 -08001479}
1480
Alexandra Chin669d27c2012-12-24 15:42:30 +08001481 /**
1482 * synaptics_rmi4_query_device()
1483 *
1484 * Called by synaptics_rmi4_probe().
1485 *
1486 * This funtion scans the page description table, records the offsets
1487 * to the register types of Function $01, sets up the function handlers
1488 * for Function $11 and Function $12, determines the number of interrupt
1489 * sources from the sensor, adds valid Functions with data inputs to the
1490 * Function linked list, parses information from the query registers of
1491 * Function $01, and enables the interrupt sources from the valid Functions
1492 * with data inputs.
1493 */
1494static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data)
1495{
1496 int retval;
1497 unsigned char ii;
1498 unsigned char page_number;
1499 unsigned char intr_count = 0;
1500 unsigned char data_sources = 0;
Alexandra Chin669d27c2012-12-24 15:42:30 +08001501 unsigned short pdt_entry_addr;
1502 unsigned short intr_addr;
1503 struct synaptics_rmi4_f01_device_status status;
1504 struct synaptics_rmi4_fn_desc rmi_fd;
1505 struct synaptics_rmi4_fn *fhandler;
1506 struct synaptics_rmi4_device_info *rmi;
1507
1508 rmi = &(rmi4_data->rmi4_mod_info);
1509
1510 INIT_LIST_HEAD(&rmi->support_fn_list);
1511
1512 /* Scan the page description tables of the pages to service */
1513 for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
1514 for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
1515 pdt_entry_addr -= PDT_ENTRY_SIZE) {
1516 pdt_entry_addr |= (page_number << 8);
1517
1518 retval = synaptics_rmi4_i2c_read(rmi4_data,
1519 pdt_entry_addr,
1520 (unsigned char *)&rmi_fd,
1521 sizeof(rmi_fd));
1522 if (retval < 0)
1523 return retval;
1524
1525 fhandler = NULL;
1526
1527 if (rmi_fd.fn_number == 0) {
1528 dev_dbg(&rmi4_data->i2c_client->dev,
1529 "%s: Reached end of PDT\n",
1530 __func__);
1531 break;
1532 }
1533
1534 dev_dbg(&rmi4_data->i2c_client->dev,
1535 "%s: F%02x found (page %d)\n",
1536 __func__, rmi_fd.fn_number,
1537 page_number);
1538
1539 switch (rmi_fd.fn_number) {
1540 case SYNAPTICS_RMI4_F01:
1541 rmi4_data->f01_query_base_addr =
1542 rmi_fd.query_base_addr;
1543 rmi4_data->f01_ctrl_base_addr =
1544 rmi_fd.ctrl_base_addr;
1545 rmi4_data->f01_data_base_addr =
1546 rmi_fd.data_base_addr;
1547 rmi4_data->f01_cmd_base_addr =
1548 rmi_fd.cmd_base_addr;
1549
Alexandra Chind5591a62013-02-07 12:59:15 -08001550 retval =
1551 synaptics_rmi4_query_device_info(rmi4_data);
1552 if (retval < 0)
1553 return retval;
1554
Alexandra Chin669d27c2012-12-24 15:42:30 +08001555 retval = synaptics_rmi4_i2c_read(rmi4_data,
1556 rmi4_data->f01_data_base_addr,
1557 status.data,
1558 sizeof(status.data));
1559 if (retval < 0)
1560 return retval;
1561
Alexandra Chin3a747522013-04-15 12:13:38 -07001562 while (status.status_code == STATUS_CRC_IN_PROGRESS) {
1563 msleep(1);
1564 retval = synaptics_rmi4_i2c_read(rmi4_data,
1565 rmi4_data->f01_data_base_addr,
1566 status.data,
1567 sizeof(status.data));
1568 if (retval < 0)
1569 return retval;
1570 }
1571
Alexandra Chin669d27c2012-12-24 15:42:30 +08001572 if (status.flash_prog == 1) {
1573 pr_notice("%s: In flash prog mode, status = 0x%02x\n",
1574 __func__,
1575 status.status_code);
1576 goto flash_prog_mode;
1577 }
Alexandra Chind5591a62013-02-07 12:59:15 -08001578 break;
1579
Alexandra Chin669d27c2012-12-24 15:42:30 +08001580 case SYNAPTICS_RMI4_F11:
1581 if (rmi_fd.intr_src_count == 0)
1582 break;
1583
1584 retval = synaptics_rmi4_alloc_fh(&fhandler,
1585 &rmi_fd, page_number);
1586 if (retval < 0) {
1587 dev_err(&rmi4_data->i2c_client->dev,
1588 "%s: Failed to alloc for F%d\n",
1589 __func__,
1590 rmi_fd.fn_number);
1591 return retval;
1592 }
1593
1594 retval = synaptics_rmi4_f11_init(rmi4_data,
1595 fhandler, &rmi_fd, intr_count);
1596 if (retval < 0)
1597 return retval;
1598 break;
1599
1600 case SYNAPTICS_RMI4_F1A:
1601 if (rmi_fd.intr_src_count == 0)
1602 break;
1603
1604 retval = synaptics_rmi4_alloc_fh(&fhandler,
1605 &rmi_fd, page_number);
1606 if (retval < 0) {
1607 dev_err(&rmi4_data->i2c_client->dev,
1608 "%s: Failed to alloc for F%d\n",
1609 __func__,
1610 rmi_fd.fn_number);
1611 return retval;
1612 }
1613
1614 retval = synaptics_rmi4_f1a_init(rmi4_data,
1615 fhandler, &rmi_fd, intr_count);
1616 if (retval < 0)
1617 return retval;
1618 break;
1619 }
1620
1621 /* Accumulate the interrupt count */
1622 intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
1623
1624 if (fhandler && rmi_fd.intr_src_count) {
1625 list_add_tail(&fhandler->link,
1626 &rmi->support_fn_list);
1627 }
1628 }
1629 }
1630
1631flash_prog_mode:
1632 rmi4_data->num_of_intr_regs = (intr_count + 7) / 8;
1633 dev_dbg(&rmi4_data->i2c_client->dev,
1634 "%s: Number of interrupt registers = %d\n",
1635 __func__, rmi4_data->num_of_intr_regs);
1636
Alexandra Chin669d27c2012-12-24 15:42:30 +08001637 memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask));
1638
1639 /*
1640 * Map out the interrupt bit masks for the interrupt sources
1641 * from the registered function handlers.
1642 */
Alexandra Chind5591a62013-02-07 12:59:15 -08001643 if (!list_empty(&rmi->support_fn_list)) {
1644 list_for_each_entry(fhandler, &rmi->support_fn_list, link)
1645 data_sources += fhandler->num_of_data_sources;
1646 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001647 if (data_sources) {
Alexandra Chind5591a62013-02-07 12:59:15 -08001648 if (!list_empty(&rmi->support_fn_list)) {
1649 list_for_each_entry(fhandler,
1650 &rmi->support_fn_list, link) {
1651 if (fhandler->num_of_data_sources) {
1652 rmi4_data->intr_mask[fhandler->intr_reg_num] |=
1653 fhandler->intr_mask;
1654 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001655 }
1656 }
1657 }
1658
1659 /* Enable the interrupt sources */
1660 for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
1661 if (rmi4_data->intr_mask[ii] != 0x00) {
1662 dev_dbg(&rmi4_data->i2c_client->dev,
1663 "%s: Interrupt enable mask %d = 0x%02x\n",
1664 __func__, ii, rmi4_data->intr_mask[ii]);
1665 intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii;
1666 retval = synaptics_rmi4_i2c_write(rmi4_data,
1667 intr_addr,
1668 &(rmi4_data->intr_mask[ii]),
1669 sizeof(rmi4_data->intr_mask[ii]));
1670 if (retval < 0)
1671 return retval;
1672 }
1673 }
1674
1675 return 0;
1676}
1677
Alexandra Chinc556cf02013-03-19 17:46:05 -07001678static int synaptics_rmi4_reset_command(struct synaptics_rmi4_data *rmi4_data)
Alexandra Chin669d27c2012-12-24 15:42:30 +08001679{
1680 int retval;
Alexandra Chinc556cf02013-03-19 17:46:05 -07001681 int page_number;
Alexandra Chin669d27c2012-12-24 15:42:30 +08001682 unsigned char command = 0x01;
Alexandra Chinc556cf02013-03-19 17:46:05 -07001683 unsigned short pdt_entry_addr;
1684 struct synaptics_rmi4_fn_desc rmi_fd;
1685 bool done = false;
Alexandra Chin669d27c2012-12-24 15:42:30 +08001686
Alexandra Chinc556cf02013-03-19 17:46:05 -07001687 /* Scan the page description tables of the pages to service */
1688 for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
1689 for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
1690 pdt_entry_addr -= PDT_ENTRY_SIZE) {
1691 retval = synaptics_rmi4_i2c_read(rmi4_data,
1692 pdt_entry_addr,
1693 (unsigned char *)&rmi_fd,
1694 sizeof(rmi_fd));
1695 if (retval < 0)
1696 return retval;
1697
1698 if (rmi_fd.fn_number == 0)
1699 break;
1700
1701 switch (rmi_fd.fn_number) {
1702 case SYNAPTICS_RMI4_F01:
1703 rmi4_data->f01_cmd_base_addr =
1704 rmi_fd.cmd_base_addr;
1705 done = true;
1706 break;
1707 }
1708 }
1709 if (done) {
1710 dev_info(&rmi4_data->i2c_client->dev,
1711 "%s: Find F01 in page description table 0x%x\n",
1712 __func__, rmi4_data->f01_cmd_base_addr);
1713 break;
1714 }
1715 }
1716
1717 if (!done) {
1718 dev_err(&rmi4_data->i2c_client->dev,
1719 "%s: Cannot find F01 in page description table\n",
1720 __func__);
1721 return -EINVAL;
1722 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001723
1724 retval = synaptics_rmi4_i2c_write(rmi4_data,
1725 rmi4_data->f01_cmd_base_addr,
1726 &command,
1727 sizeof(command));
1728 if (retval < 0) {
1729 dev_err(&rmi4_data->i2c_client->dev,
1730 "%s: Failed to issue reset command, error = %d\n",
1731 __func__, retval);
1732 return retval;
1733 }
1734
Alexandra Chin3a747522013-04-15 12:13:38 -07001735 msleep(RESET_DELAY);
Alexandra Chinc556cf02013-03-19 17:46:05 -07001736 return retval;
1737};
1738
1739static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data)
1740{
1741 int retval;
1742 struct synaptics_rmi4_fn *fhandler;
1743 struct synaptics_rmi4_device_info *rmi;
1744
1745 rmi = &(rmi4_data->rmi4_mod_info);
1746
1747 retval = synaptics_rmi4_reset_command(rmi4_data);
1748 if (retval < 0) {
1749 dev_err(&rmi4_data->i2c_client->dev,
1750 "%s: Failed to send command reset\n",
1751 __func__);
1752 return retval;
1753 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001754
Alexandra Chind5591a62013-02-07 12:59:15 -08001755 if (!list_empty(&rmi->support_fn_list)) {
1756 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
1757 if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
1758 synaptics_rmi4_f1a_kfree(fhandler);
1759 else
1760 kfree(fhandler->data);
1761 kfree(fhandler);
1762 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001763 }
1764
1765 retval = synaptics_rmi4_query_device(rmi4_data);
1766 if (retval < 0) {
1767 dev_err(&rmi4_data->i2c_client->dev,
1768 "%s: Failed to query device\n",
1769 __func__);
1770 return retval;
1771 }
1772
1773 return 0;
1774}
1775
1776/**
1777* synaptics_rmi4_detection_work()
1778*
1779* Called by the kernel at the scheduled time.
1780*
1781* This function is a self-rearming work thread that checks for the
1782* insertion and removal of other expansion Function modules such as
1783* rmi_dev and calls their initialization and removal callback functions
1784* accordingly.
1785*/
1786static void synaptics_rmi4_detection_work(struct work_struct *work)
1787{
1788 struct synaptics_rmi4_exp_fn *exp_fhandler, *next_list_entry;
1789 struct synaptics_rmi4_data *rmi4_data =
1790 container_of(work, struct synaptics_rmi4_data,
1791 det_work.work);
1792
Alexandra Chin669d27c2012-12-24 15:42:30 +08001793 mutex_lock(&exp_fn_list_mutex);
1794 if (!list_empty(&exp_fn_list)) {
1795 list_for_each_entry_safe(exp_fhandler,
1796 next_list_entry,
1797 &exp_fn_list,
1798 link) {
1799 if ((exp_fhandler->func_init != NULL) &&
1800 (exp_fhandler->inserted == false)) {
1801 exp_fhandler->func_init(rmi4_data);
1802 exp_fhandler->inserted = true;
1803 } else if ((exp_fhandler->func_init == NULL) &&
1804 (exp_fhandler->inserted == true)) {
1805 exp_fhandler->func_remove(rmi4_data);
1806 list_del(&exp_fhandler->link);
1807 kfree(exp_fhandler);
1808 }
1809 }
1810 }
1811 mutex_unlock(&exp_fn_list_mutex);
1812
1813 return;
1814}
1815
1816/**
1817* synaptics_rmi4_new_function()
1818*
1819* Called by other expansion Function modules in their module init and
1820* module exit functions.
1821*
1822* This function is used by other expansion Function modules such as
1823* rmi_dev to register themselves with the driver by providing their
1824* initialization and removal callback function pointers so that they
1825* can be inserted or removed dynamically at module init and exit times,
1826* respectively.
1827*/
1828void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
1829 int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
1830 void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
1831 void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
1832 unsigned char intr_mask))
1833{
1834 struct synaptics_rmi4_exp_fn *exp_fhandler;
1835
1836 if (!exp_fn_inited) {
1837 mutex_init(&exp_fn_list_mutex);
1838 INIT_LIST_HEAD(&exp_fn_list);
1839 exp_fn_inited = 1;
1840 }
1841
1842 mutex_lock(&exp_fn_list_mutex);
1843 if (insert) {
1844 exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL);
1845 if (!exp_fhandler) {
1846 pr_err("%s: Failed to alloc mem for expansion function\n",
1847 __func__);
1848 goto exit;
1849 }
1850 exp_fhandler->fn_type = fn_type;
1851 exp_fhandler->func_init = func_init;
1852 exp_fhandler->func_attn = func_attn;
1853 exp_fhandler->func_remove = func_remove;
1854 exp_fhandler->inserted = false;
1855 list_add_tail(&exp_fhandler->link, &exp_fn_list);
1856 } else {
Alexandra Chind5591a62013-02-07 12:59:15 -08001857 if (!list_empty(&exp_fn_list)) {
1858 list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
1859 if (exp_fhandler->func_init == func_init) {
1860 exp_fhandler->inserted = false;
1861 exp_fhandler->func_init = NULL;
1862 exp_fhandler->func_attn = NULL;
1863 goto exit;
1864 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08001865 }
1866 }
1867 }
1868
1869exit:
1870 mutex_unlock(&exp_fn_list_mutex);
1871
1872 return;
1873}
1874EXPORT_SYMBOL(synaptics_rmi4_new_function);
1875
Amy Maloche1a53b612013-01-18 15:25:15 -08001876
1877static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA)
1878{
1879 return (regulator_count_voltages(reg) > 0) ?
1880 regulator_set_optimum_mode(reg, load_uA) : 0;
1881}
1882
1883static int synaptics_rmi4_regulator_configure(struct synaptics_rmi4_data
1884 *rmi4_data, bool on)
1885{
1886 int retval;
1887
1888 if (on == false)
1889 goto hw_shutdown;
1890
Amy Maloche836c0b02013-06-04 15:49:02 -07001891 rmi4_data->vdd = regulator_get(&rmi4_data->i2c_client->dev,
1892 "vdd");
1893 if (IS_ERR(rmi4_data->vdd)) {
1894 dev_err(&rmi4_data->i2c_client->dev,
1895 "%s: Failed to get vdd regulator\n",
1896 __func__);
1897 return PTR_ERR(rmi4_data->vdd);
1898 }
Amy Maloche1a53b612013-01-18 15:25:15 -08001899
Amy Maloche836c0b02013-06-04 15:49:02 -07001900 if (regulator_count_voltages(rmi4_data->vdd) > 0) {
1901 retval = regulator_set_voltage(rmi4_data->vdd,
1902 RMI4_VTG_MIN_UV, RMI4_VTG_MAX_UV);
1903 if (retval) {
1904 dev_err(&rmi4_data->i2c_client->dev,
1905 "regulator set_vtg failed retval =%d\n",
1906 retval);
1907 goto err_set_vtg_vdd;
Amy Maloche1a53b612013-01-18 15:25:15 -08001908 }
1909 }
1910
1911 if (rmi4_data->board->i2c_pull_up) {
1912 rmi4_data->vcc_i2c = regulator_get(&rmi4_data->i2c_client->dev,
1913 "vcc_i2c");
1914 if (IS_ERR(rmi4_data->vcc_i2c)) {
1915 dev_err(&rmi4_data->i2c_client->dev,
1916 "%s: Failed to get i2c regulator\n",
1917 __func__);
1918 retval = PTR_ERR(rmi4_data->vcc_i2c);
1919 goto err_get_vtg_i2c;
1920 }
1921
1922 if (regulator_count_voltages(rmi4_data->vcc_i2c) > 0) {
1923 retval = regulator_set_voltage(rmi4_data->vcc_i2c,
1924 RMI4_I2C_VTG_MIN_UV, RMI4_I2C_VTG_MAX_UV);
1925 if (retval) {
1926 dev_err(&rmi4_data->i2c_client->dev,
Amy Maloche827e8b02013-02-27 15:25:14 -08001927 "reg set i2c vtg failed retval =%d\n",
Amy Maloche1a53b612013-01-18 15:25:15 -08001928 retval);
1929 goto err_set_vtg_i2c;
1930 }
1931 }
1932 }
Amy Malocheecfb4892013-02-06 13:30:36 -08001933 return 0;
Amy Maloche1a53b612013-01-18 15:25:15 -08001934
1935err_set_vtg_i2c:
1936 if (rmi4_data->board->i2c_pull_up)
1937 regulator_put(rmi4_data->vcc_i2c);
1938err_get_vtg_i2c:
Amy Maloche836c0b02013-06-04 15:49:02 -07001939 if (regulator_count_voltages(rmi4_data->vdd) > 0)
1940 regulator_set_voltage(rmi4_data->vdd, 0,
1941 RMI4_VTG_MAX_UV);
Amy Maloche1a53b612013-01-18 15:25:15 -08001942err_set_vtg_vdd:
Amy Maloche836c0b02013-06-04 15:49:02 -07001943 regulator_put(rmi4_data->vdd);
Amy Maloche1a53b612013-01-18 15:25:15 -08001944 return retval;
1945
1946hw_shutdown:
Amy Maloche836c0b02013-06-04 15:49:02 -07001947 if (regulator_count_voltages(rmi4_data->vdd) > 0)
1948 regulator_set_voltage(rmi4_data->vdd, 0,
1949 RMI4_VTG_MAX_UV);
1950 regulator_put(rmi4_data->vdd);
Amy Maloche1a53b612013-01-18 15:25:15 -08001951 if (rmi4_data->board->i2c_pull_up) {
1952 if (regulator_count_voltages(rmi4_data->vcc_i2c) > 0)
1953 regulator_set_voltage(rmi4_data->vcc_i2c, 0,
1954 RMI4_I2C_VTG_MAX_UV);
1955 regulator_put(rmi4_data->vcc_i2c);
1956 }
1957 return 0;
1958};
1959
1960static int synaptics_rmi4_power_on(struct synaptics_rmi4_data *rmi4_data,
1961 bool on) {
1962 int retval;
1963
1964 if (on == false)
1965 goto power_off;
1966
Amy Maloche836c0b02013-06-04 15:49:02 -07001967 retval = reg_set_optimum_mode_check(rmi4_data->vdd,
1968 RMI4_ACTIVE_LOAD_UA);
1969 if (retval < 0) {
1970 dev_err(&rmi4_data->i2c_client->dev,
1971 "Regulator vdd set_opt failed rc=%d\n",
1972 retval);
1973 return retval;
1974 }
Amy Maloche1a53b612013-01-18 15:25:15 -08001975
Amy Maloche836c0b02013-06-04 15:49:02 -07001976 retval = regulator_enable(rmi4_data->vdd);
1977 if (retval) {
1978 dev_err(&rmi4_data->i2c_client->dev,
1979 "Regulator vdd enable failed rc=%d\n",
1980 retval);
1981 goto error_reg_en_vdd;
Amy Maloche1a53b612013-01-18 15:25:15 -08001982 }
1983
1984 if (rmi4_data->board->i2c_pull_up) {
1985 retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
1986 RMI4_I2C_LOAD_UA);
1987 if (retval < 0) {
1988 dev_err(&rmi4_data->i2c_client->dev,
1989 "Regulator vcc_i2c set_opt failed rc=%d\n",
1990 retval);
1991 goto error_reg_opt_i2c;
1992 }
1993
1994 retval = regulator_enable(rmi4_data->vcc_i2c);
1995 if (retval) {
1996 dev_err(&rmi4_data->i2c_client->dev,
1997 "Regulator vcc_i2c enable failed rc=%d\n",
1998 retval);
1999 goto error_reg_en_vcc_i2c;
2000 }
2001 }
2002 return 0;
2003
2004error_reg_en_vcc_i2c:
2005 if (rmi4_data->board->i2c_pull_up)
2006 reg_set_optimum_mode_check(rmi4_data->vdd, 0);
2007error_reg_opt_i2c:
Amy Maloche836c0b02013-06-04 15:49:02 -07002008 regulator_disable(rmi4_data->vdd);
Amy Maloche1a53b612013-01-18 15:25:15 -08002009error_reg_en_vdd:
Amy Maloche836c0b02013-06-04 15:49:02 -07002010 reg_set_optimum_mode_check(rmi4_data->vdd, 0);
Amy Maloche1a53b612013-01-18 15:25:15 -08002011 return retval;
2012
2013power_off:
Amy Maloche836c0b02013-06-04 15:49:02 -07002014 reg_set_optimum_mode_check(rmi4_data->vdd, 0);
2015 regulator_disable(rmi4_data->vdd);
Amy Maloche1a53b612013-01-18 15:25:15 -08002016 if (rmi4_data->board->i2c_pull_up) {
2017 reg_set_optimum_mode_check(rmi4_data->vcc_i2c, 0);
2018 regulator_disable(rmi4_data->vcc_i2c);
2019 }
2020 return 0;
2021}
2022
Alexandra Chin669d27c2012-12-24 15:42:30 +08002023 /**
2024 * synaptics_rmi4_probe()
2025 *
2026 * Called by the kernel when an association with an I2C device of the
2027 * same name is made (after doing i2c_add_driver).
2028 *
2029 * This funtion allocates and initializes the resources for the driver
2030 * as an input driver, turns on the power to the sensor, queries the
2031 * sensor for its supported Functions and characteristics, registers
2032 * the driver to the input subsystem, sets up the interrupt, handles
2033 * the registration of the early_suspend and late_resume functions,
2034 * and creates a work queue for detection of other expansion Function
2035 * modules.
2036 */
2037static int __devinit synaptics_rmi4_probe(struct i2c_client *client,
2038 const struct i2c_device_id *dev_id)
2039{
Amy Maloche1a53b612013-01-18 15:25:15 -08002040 int retval = 0;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002041 unsigned char ii;
2042 unsigned char attr_count;
2043 struct synaptics_rmi4_f1a_handle *f1a;
2044 struct synaptics_rmi4_fn *fhandler;
2045 struct synaptics_rmi4_data *rmi4_data;
2046 struct synaptics_rmi4_device_info *rmi;
Amy Malocheecfb4892013-02-06 13:30:36 -08002047 struct synaptics_rmi4_platform_data *platform_data =
Alexandra Chin669d27c2012-12-24 15:42:30 +08002048 client->dev.platform_data;
Amy Maloche986863d2013-06-10 15:13:57 -07002049 struct dentry *temp;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002050
2051 if (!i2c_check_functionality(client->adapter,
2052 I2C_FUNC_SMBUS_BYTE_DATA)) {
2053 dev_err(&client->dev,
2054 "%s: SMBus byte data not supported\n",
2055 __func__);
2056 return -EIO;
2057 }
2058
Amy Malocheecfb4892013-02-06 13:30:36 -08002059 if (client->dev.of_node) {
2060 platform_data = devm_kzalloc(&client->dev,
2061 sizeof(*platform_data),
2062 GFP_KERNEL);
2063 if (!platform_data) {
2064 dev_err(&client->dev, "Failed to allocate memory\n");
2065 return -ENOMEM;
2066 }
2067
2068 retval = synaptics_rmi4_parse_dt(&client->dev, platform_data);
2069 if (retval)
2070 return retval;
2071 } else {
2072 platform_data = client->dev.platform_data;
2073 }
2074
Alexandra Chin669d27c2012-12-24 15:42:30 +08002075 if (!platform_data) {
2076 dev_err(&client->dev,
2077 "%s: No platform data found\n",
2078 __func__);
2079 return -EINVAL;
2080 }
2081
2082 rmi4_data = kzalloc(sizeof(*rmi4_data) * 2, GFP_KERNEL);
2083 if (!rmi4_data) {
2084 dev_err(&client->dev,
2085 "%s: Failed to alloc mem for rmi4_data\n",
2086 __func__);
2087 return -ENOMEM;
2088 }
2089
2090 rmi = &(rmi4_data->rmi4_mod_info);
2091
2092 rmi4_data->input_dev = input_allocate_device();
2093 if (rmi4_data->input_dev == NULL) {
2094 dev_err(&client->dev,
2095 "%s: Failed to allocate input device\n",
2096 __func__);
2097 retval = -ENOMEM;
2098 goto err_input_device;
2099 }
Alexandra Chind5591a62013-02-07 12:59:15 -08002100
Alexandra Chin669d27c2012-12-24 15:42:30 +08002101 rmi4_data->i2c_client = client;
2102 rmi4_data->current_page = MASK_8BIT;
2103 rmi4_data->board = platform_data;
2104 rmi4_data->touch_stopped = false;
2105 rmi4_data->sensor_sleep = false;
2106 rmi4_data->irq_enabled = false;
Amy Malocheb494b9a2013-05-13 18:01:53 -07002107 rmi4_data->fw_updating = false;
Amy Maloche986863d2013-06-10 15:13:57 -07002108 rmi4_data->suspended = false;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002109
2110 rmi4_data->i2c_read = synaptics_rmi4_i2c_read;
2111 rmi4_data->i2c_write = synaptics_rmi4_i2c_write;
2112 rmi4_data->irq_enable = synaptics_rmi4_irq_enable;
2113 rmi4_data->reset_device = synaptics_rmi4_reset_device;
2114
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002115 rmi4_data->flip_x = rmi4_data->board->x_flip;
2116 rmi4_data->flip_y = rmi4_data->board->y_flip;
2117
Amy Malocheb494b9a2013-05-13 18:01:53 -07002118 if (rmi4_data->board->fw_image_name)
2119 snprintf(rmi4_data->fw_image_name, NAME_BUFFER_SIZE, "%s",
2120 rmi4_data->board->fw_image_name);
Amy Malochecb835832013-03-26 18:06:05 -07002121
Alexandra Chin669d27c2012-12-24 15:42:30 +08002122 rmi4_data->input_dev->name = DRIVER_NAME;
2123 rmi4_data->input_dev->phys = INPUT_PHYS_NAME;
2124 rmi4_data->input_dev->id.bustype = BUS_I2C;
Alexandra Chin5d2999d2013-02-22 15:09:29 -08002125 rmi4_data->input_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT;
2126 rmi4_data->input_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002127 rmi4_data->input_dev->dev.parent = &client->dev;
2128 input_set_drvdata(rmi4_data->input_dev, rmi4_data);
2129
2130 set_bit(EV_SYN, rmi4_data->input_dev->evbit);
2131 set_bit(EV_KEY, rmi4_data->input_dev->evbit);
2132 set_bit(EV_ABS, rmi4_data->input_dev->evbit);
Alexandra Chind5591a62013-02-07 12:59:15 -08002133 set_bit(BTN_TOUCH, rmi4_data->input_dev->keybit);
2134 set_bit(BTN_TOOL_FINGER, rmi4_data->input_dev->keybit);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002135
2136#ifdef INPUT_PROP_DIRECT
2137 set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
2138#endif
2139
Amy Maloche1a53b612013-01-18 15:25:15 -08002140 retval = synaptics_rmi4_regulator_configure(rmi4_data, true);
2141 if (retval < 0) {
2142 dev_err(&client->dev, "Failed to configure regulators\n");
Amy Maloche946da662013-01-18 16:27:11 -08002143 goto err_reg_configure;
Amy Maloche1a53b612013-01-18 15:25:15 -08002144 }
2145
2146 retval = synaptics_rmi4_power_on(rmi4_data, true);
2147 if (retval < 0) {
2148 dev_err(&client->dev, "Failed to power on\n");
Amy Maloche946da662013-01-18 16:27:11 -08002149 goto err_power_device;
Amy Maloche1a53b612013-01-18 15:25:15 -08002150 }
2151
Amy Maloche946da662013-01-18 16:27:11 -08002152 if (gpio_is_valid(platform_data->irq_gpio)) {
2153 /* configure touchscreen irq gpio */
2154 retval = gpio_request(platform_data->irq_gpio, "rmi4_irq_gpio");
2155 if (retval) {
2156 dev_err(&client->dev, "unable to request gpio [%d]\n",
2157 platform_data->irq_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002158 goto err_irq_gpio_req;
Amy Maloche946da662013-01-18 16:27:11 -08002159 }
2160 retval = gpio_direction_input(platform_data->irq_gpio);
2161 if (retval) {
2162 dev_err(&client->dev,
2163 "unable to set direction for gpio [%d]\n",
2164 platform_data->irq_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002165 goto err_irq_gpio_dir;
Amy Maloche946da662013-01-18 16:27:11 -08002166 }
2167 } else {
2168 dev_err(&client->dev, "irq gpio not provided\n");
Amy Malocheecfb4892013-02-06 13:30:36 -08002169 goto err_irq_gpio_req;
Amy Maloche946da662013-01-18 16:27:11 -08002170 }
2171
2172 if (gpio_is_valid(platform_data->reset_gpio)) {
2173 /* configure touchscreen reset out gpio */
2174 retval = gpio_request(platform_data->reset_gpio,
2175 "rmi4_reset_gpio");
2176 if (retval) {
2177 dev_err(&client->dev, "unable to request gpio [%d]\n",
2178 platform_data->reset_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002179 goto err_irq_gpio_dir;
Amy Maloche946da662013-01-18 16:27:11 -08002180 }
2181
2182 retval = gpio_direction_output(platform_data->reset_gpio, 1);
2183 if (retval) {
2184 dev_err(&client->dev,
2185 "unable to set direction for gpio [%d]\n",
2186 platform_data->reset_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002187 goto err_reset_gpio_dir;
Amy Maloche946da662013-01-18 16:27:11 -08002188 }
2189
2190 gpio_set_value(platform_data->reset_gpio, 0);
2191 usleep(RMI4_GPIO_SLEEP_LOW_US);
2192 gpio_set_value(platform_data->reset_gpio, 1);
Alexandra Chin3a747522013-04-15 12:13:38 -07002193 msleep(RESET_DELAY);
Alexandra Chinc556cf02013-03-19 17:46:05 -07002194 } else
2195 synaptics_rmi4_reset_command(rmi4_data);
Amy Maloche946da662013-01-18 16:27:11 -08002196
2197
Amy Maloche1a53b612013-01-18 15:25:15 -08002198 init_waitqueue_head(&rmi4_data->wait);
2199 mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex));
2200
2201 retval = synaptics_rmi4_query_device(rmi4_data);
2202 if (retval < 0) {
2203 dev_err(&client->dev,
2204 "%s: Failed to query device\n",
2205 __func__);
Amy Malocheecfb4892013-02-06 13:30:36 -08002206 goto err_reset_gpio_dir;
Amy Maloche1a53b612013-01-18 15:25:15 -08002207 }
2208
Amy Malocheecfb4892013-02-06 13:30:36 -08002209 input_set_abs_params(rmi4_data->input_dev,
2210 ABS_MT_POSITION_X, 0,
2211 rmi4_data->sensor_max_x, 0, 0);
2212 input_set_abs_params(rmi4_data->input_dev,
2213 ABS_MT_POSITION_Y, 0,
2214 rmi4_data->sensor_max_y, 0, 0);
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002215 input_set_abs_params(rmi4_data->input_dev,
2216 ABS_PRESSURE, 0, 255, 0, 0);
Amy Malocheecfb4892013-02-06 13:30:36 -08002217#ifdef REPORT_2D_W
2218 input_set_abs_params(rmi4_data->input_dev,
2219 ABS_MT_TOUCH_MAJOR, 0,
2220 MAX_ABS_MT_TOUCH_MAJOR, 0, 0);
2221#endif
2222
2223#ifdef TYPE_B_PROTOCOL
2224 input_mt_init_slots(rmi4_data->input_dev,
2225 rmi4_data->num_of_fingers);
2226#endif
2227
Amy Maloche1a53b612013-01-18 15:25:15 -08002228 i2c_set_clientdata(client, rmi4_data);
2229
Alexandra Chin669d27c2012-12-24 15:42:30 +08002230 f1a = NULL;
Alexandra Chind5591a62013-02-07 12:59:15 -08002231 if (!list_empty(&rmi->support_fn_list)) {
2232 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
2233 if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
2234 f1a = fhandler->data;
2235 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002236 }
2237
2238 if (f1a) {
2239 for (ii = 0; ii < f1a->valid_button_count; ii++) {
2240 set_bit(f1a->button_map[ii],
2241 rmi4_data->input_dev->keybit);
2242 input_set_capability(rmi4_data->input_dev,
2243 EV_KEY, f1a->button_map[ii]);
2244 }
2245 }
2246
2247 retval = input_register_device(rmi4_data->input_dev);
2248 if (retval) {
2249 dev_err(&client->dev,
2250 "%s: Failed to register input device\n",
2251 __func__);
2252 goto err_register_input;
2253 }
2254
Amy Malochef46540d2013-02-15 17:09:43 -08002255 configure_sleep(rmi4_data);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002256
2257 if (!exp_fn_inited) {
2258 mutex_init(&exp_fn_list_mutex);
2259 INIT_LIST_HEAD(&exp_fn_list);
2260 exp_fn_inited = 1;
2261 }
2262
2263 rmi4_data->det_workqueue =
2264 create_singlethread_workqueue("rmi_det_workqueue");
2265 INIT_DELAYED_WORK(&rmi4_data->det_work,
2266 synaptics_rmi4_detection_work);
2267 queue_delayed_work(rmi4_data->det_workqueue,
2268 &rmi4_data->det_work,
2269 msecs_to_jiffies(EXP_FN_DET_INTERVAL));
2270
Alexandra Chin669d27c2012-12-24 15:42:30 +08002271 rmi4_data->irq = gpio_to_irq(platform_data->irq_gpio);
2272
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002273 retval = request_threaded_irq(rmi4_data->irq, NULL,
2274 synaptics_rmi4_irq, platform_data->irq_flags,
2275 DRIVER_NAME, rmi4_data);
2276 rmi4_data->irq_enabled = true;
2277
Alexandra Chin669d27c2012-12-24 15:42:30 +08002278 if (retval < 0) {
2279 dev_err(&client->dev,
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002280 "%s: Failed to create irq thread\n",
Alexandra Chin669d27c2012-12-24 15:42:30 +08002281 __func__);
2282 goto err_enable_irq;
2283 }
2284
Amy Maloche986863d2013-06-10 15:13:57 -07002285 rmi4_data->dir = debugfs_create_dir(DEBUGFS_DIR_NAME, NULL);
2286 if (rmi4_data->dir == NULL || IS_ERR(rmi4_data->dir)) {
2287 dev_err(&client->dev,
2288 "%s: Failed to create debugfs directory, rc = %ld\n",
2289 __func__, PTR_ERR(rmi4_data->dir));
2290 retval = PTR_ERR(rmi4_data->dir);
2291 goto err_create_debugfs_dir;
2292 }
2293
2294 temp = debugfs_create_file("suspend", S_IRUSR | S_IWUSR, rmi4_data->dir,
2295 rmi4_data, &debug_suspend_fops);
2296 if (temp == NULL || IS_ERR(temp)) {
2297 dev_err(&client->dev,
2298 "%s: Failed to create suspend debugfs file, rc = %ld\n",
2299 __func__, PTR_ERR(temp));
2300 retval = PTR_ERR(temp);
2301 goto err_create_debugfs_file;
2302 }
2303
Alexandra Chin669d27c2012-12-24 15:42:30 +08002304 for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
Amy Maloche4d54ac42013-06-11 12:09:44 -07002305 retval = sysfs_create_file(&client->dev.kobj,
Alexandra Chin669d27c2012-12-24 15:42:30 +08002306 &attrs[attr_count].attr);
2307 if (retval < 0) {
2308 dev_err(&client->dev,
2309 "%s: Failed to create sysfs attributes\n",
2310 __func__);
2311 goto err_sysfs;
2312 }
2313 }
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002314 retval = synaptics_rmi4_irq_enable(rmi4_data, true);
2315 if (retval < 0) {
2316 dev_err(&client->dev,
2317 "%s: Failed to enable attention interrupt\n",
2318 __func__);
2319 goto err_sysfs;
2320 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002321
2322 return retval;
2323
2324err_sysfs:
2325 for (attr_count--; attr_count >= 0; attr_count--) {
2326 sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
2327 &attrs[attr_count].attr);
2328 }
Amy Maloche986863d2013-06-10 15:13:57 -07002329err_create_debugfs_file:
2330 debugfs_remove_recursive(rmi4_data->dir);
2331err_create_debugfs_dir:
2332 free_irq(rmi4_data->irq, rmi4_data);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002333err_enable_irq:
Amy Malocheecfb4892013-02-06 13:30:36 -08002334 cancel_delayed_work_sync(&rmi4_data->det_work);
2335 flush_workqueue(rmi4_data->det_workqueue);
2336 destroy_workqueue(rmi4_data->det_workqueue);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002337 input_unregister_device(rmi4_data->input_dev);
2338
2339err_register_input:
Alexandra Chind5591a62013-02-07 12:59:15 -08002340 if (!list_empty(&rmi->support_fn_list)) {
2341 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
2342 if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
2343 synaptics_rmi4_f1a_kfree(fhandler);
2344 else
2345 kfree(fhandler->data);
2346 kfree(fhandler);
2347 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002348 }
Amy Malocheecfb4892013-02-06 13:30:36 -08002349err_reset_gpio_dir:
Amy Maloche946da662013-01-18 16:27:11 -08002350 if (gpio_is_valid(platform_data->reset_gpio))
2351 gpio_free(platform_data->reset_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002352err_irq_gpio_dir:
Amy Maloche946da662013-01-18 16:27:11 -08002353 if (gpio_is_valid(platform_data->irq_gpio))
2354 gpio_free(platform_data->irq_gpio);
Amy Malocheecfb4892013-02-06 13:30:36 -08002355err_irq_gpio_req:
Amy Maloche946da662013-01-18 16:27:11 -08002356 synaptics_rmi4_power_on(rmi4_data, false);
2357err_power_device:
2358 synaptics_rmi4_regulator_configure(rmi4_data, false);
2359err_reg_configure:
Alexandra Chin669d27c2012-12-24 15:42:30 +08002360 input_free_device(rmi4_data->input_dev);
2361 rmi4_data->input_dev = NULL;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002362err_input_device:
2363 kfree(rmi4_data);
2364
2365 return retval;
2366}
2367
2368 /**
2369 * synaptics_rmi4_remove()
2370 *
2371 * Called by the kernel when the association with an I2C device of the
2372 * same name is broken (when the driver is unloaded).
2373 *
2374 * This funtion terminates the work queue, stops sensor data acquisition,
2375 * frees the interrupt, unregisters the driver from the input subsystem,
2376 * turns off the power to the sensor, and frees other allocated resources.
2377 */
2378static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
2379{
2380 unsigned char attr_count;
2381 struct synaptics_rmi4_fn *fhandler;
2382 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
2383 struct synaptics_rmi4_device_info *rmi;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002384
2385 rmi = &(rmi4_data->rmi4_mod_info);
2386
Amy Maloche986863d2013-06-10 15:13:57 -07002387 debugfs_remove_recursive(rmi4_data->dir);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002388 cancel_delayed_work_sync(&rmi4_data->det_work);
2389 flush_workqueue(rmi4_data->det_workqueue);
2390 destroy_workqueue(rmi4_data->det_workqueue);
2391
2392 rmi4_data->touch_stopped = true;
2393 wake_up(&rmi4_data->wait);
2394
Alexandra Chinfb798fa2013-03-26 17:15:38 -07002395 free_irq(rmi4_data->irq, rmi4_data);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002396
2397 for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
2398 sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
2399 &attrs[attr_count].attr);
2400 }
2401
2402 input_unregister_device(rmi4_data->input_dev);
2403
Alexandra Chind5591a62013-02-07 12:59:15 -08002404 if (!list_empty(&rmi->support_fn_list)) {
2405 list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
2406 if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
2407 synaptics_rmi4_f1a_kfree(fhandler);
2408 else
2409 kfree(fhandler->data);
2410 kfree(fhandler);
2411 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002412 }
Amy Maloche946da662013-01-18 16:27:11 -08002413
2414 if (gpio_is_valid(rmi4_data->board->reset_gpio))
2415 gpio_free(rmi4_data->board->reset_gpio);
2416 if (gpio_is_valid(rmi4_data->board->irq_gpio))
2417 gpio_free(rmi4_data->board->irq_gpio);
Alexandra Chin669d27c2012-12-24 15:42:30 +08002418
Amy Maloche1a53b612013-01-18 15:25:15 -08002419 synaptics_rmi4_power_on(rmi4_data, false);
2420 synaptics_rmi4_regulator_configure(rmi4_data, false);
2421
Alexandra Chin669d27c2012-12-24 15:42:30 +08002422 kfree(rmi4_data);
2423
2424 return 0;
2425}
2426
2427#ifdef CONFIG_PM
2428 /**
2429 * synaptics_rmi4_sensor_sleep()
2430 *
2431 * Called by synaptics_rmi4_early_suspend() and synaptics_rmi4_suspend().
2432 *
2433 * This function stops finger data acquisition and puts the sensor to sleep.
2434 */
2435static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data)
2436{
2437 int retval;
2438 unsigned char device_ctrl;
2439
2440 retval = synaptics_rmi4_i2c_read(rmi4_data,
2441 rmi4_data->f01_ctrl_base_addr,
2442 &device_ctrl,
2443 sizeof(device_ctrl));
2444 if (retval < 0) {
2445 dev_err(&(rmi4_data->input_dev->dev),
2446 "%s: Failed to enter sleep mode\n",
2447 __func__);
2448 rmi4_data->sensor_sleep = false;
2449 return;
2450 }
2451
2452 device_ctrl = (device_ctrl & ~MASK_3BIT);
2453 device_ctrl = (device_ctrl | NO_SLEEP_OFF | SENSOR_SLEEP);
2454
2455 retval = synaptics_rmi4_i2c_write(rmi4_data,
2456 rmi4_data->f01_ctrl_base_addr,
2457 &device_ctrl,
2458 sizeof(device_ctrl));
2459 if (retval < 0) {
2460 dev_err(&(rmi4_data->input_dev->dev),
2461 "%s: Failed to enter sleep mode\n",
2462 __func__);
2463 rmi4_data->sensor_sleep = false;
2464 return;
2465 } else {
2466 rmi4_data->sensor_sleep = true;
2467 }
2468
2469 return;
2470}
2471
2472 /**
2473 * synaptics_rmi4_sensor_wake()
2474 *
2475 * Called by synaptics_rmi4_resume() and synaptics_rmi4_late_resume().
2476 *
2477 * This function wakes the sensor from sleep.
2478 */
2479static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data)
2480{
2481 int retval;
2482 unsigned char device_ctrl;
2483
2484 retval = synaptics_rmi4_i2c_read(rmi4_data,
2485 rmi4_data->f01_ctrl_base_addr,
2486 &device_ctrl,
2487 sizeof(device_ctrl));
2488 if (retval < 0) {
2489 dev_err(&(rmi4_data->input_dev->dev),
2490 "%s: Failed to wake from sleep mode\n",
2491 __func__);
2492 rmi4_data->sensor_sleep = true;
2493 return;
2494 }
2495
2496 device_ctrl = (device_ctrl & ~MASK_3BIT);
2497 device_ctrl = (device_ctrl | NO_SLEEP_OFF | NORMAL_OPERATION);
2498
2499 retval = synaptics_rmi4_i2c_write(rmi4_data,
2500 rmi4_data->f01_ctrl_base_addr,
2501 &device_ctrl,
2502 sizeof(device_ctrl));
2503 if (retval < 0) {
2504 dev_err(&(rmi4_data->input_dev->dev),
2505 "%s: Failed to wake from sleep mode\n",
2506 __func__);
2507 rmi4_data->sensor_sleep = true;
2508 return;
2509 } else {
2510 rmi4_data->sensor_sleep = false;
2511 }
2512
2513 return;
2514}
2515
Amy Malochef46540d2013-02-15 17:09:43 -08002516#if defined(CONFIG_FB)
2517static int fb_notifier_callback(struct notifier_block *self,
2518 unsigned long event, void *data)
2519{
2520 struct fb_event *evdata = data;
2521 int *blank;
2522 struct synaptics_rmi4_data *rmi4_data =
2523 container_of(self, struct synaptics_rmi4_data, fb_notif);
2524
2525 if (evdata && evdata->data && event == FB_EVENT_BLANK &&
2526 rmi4_data && rmi4_data->i2c_client) {
2527 blank = evdata->data;
2528 if (*blank == FB_BLANK_UNBLANK)
2529 synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));
2530 else if (*blank == FB_BLANK_POWERDOWN)
2531 synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev));
2532 }
2533
2534 return 0;
2535}
2536#elif defined(CONFIG_HAS_EARLYSUSPEND)
Alexandra Chin669d27c2012-12-24 15:42:30 +08002537 /**
2538 * synaptics_rmi4_early_suspend()
2539 *
2540 * Called by the kernel during the early suspend phase when the system
2541 * enters suspend.
2542 *
2543 * This function calls synaptics_rmi4_sensor_sleep() to stop finger
2544 * data acquisition and put the sensor to sleep.
2545 */
2546static void synaptics_rmi4_early_suspend(struct early_suspend *h)
2547{
2548 struct synaptics_rmi4_data *rmi4_data =
2549 container_of(h, struct synaptics_rmi4_data,
2550 early_suspend);
2551
2552 rmi4_data->touch_stopped = true;
2553 wake_up(&rmi4_data->wait);
2554 synaptics_rmi4_irq_enable(rmi4_data, false);
2555 synaptics_rmi4_sensor_sleep(rmi4_data);
2556
2557 if (rmi4_data->full_pm_cycle)
2558 synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev));
2559
2560 return;
2561}
2562
2563 /**
2564 * synaptics_rmi4_late_resume()
2565 *
2566 * Called by the kernel during the late resume phase when the system
2567 * wakes up from suspend.
2568 *
2569 * This function goes through the sensor wake process if the system wakes
2570 * up from early suspend (without going into suspend).
2571 */
2572static void synaptics_rmi4_late_resume(struct early_suspend *h)
2573{
2574 struct synaptics_rmi4_data *rmi4_data =
2575 container_of(h, struct synaptics_rmi4_data,
2576 early_suspend);
2577
2578 if (rmi4_data->full_pm_cycle)
2579 synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));
2580
2581 if (rmi4_data->sensor_sleep == true) {
2582 synaptics_rmi4_sensor_wake(rmi4_data);
2583 rmi4_data->touch_stopped = false;
2584 synaptics_rmi4_irq_enable(rmi4_data, true);
2585 }
2586
2587 return;
2588}
2589#endif
2590
Amy Maloche827e8b02013-02-27 15:25:14 -08002591static int synaptics_rmi4_regulator_lpm(struct synaptics_rmi4_data *rmi4_data,
2592 bool on)
2593{
2594 int retval;
2595
2596 if (on == false)
2597 goto regulator_hpm;
2598
2599 retval = reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
2600 if (retval < 0) {
2601 dev_err(&rmi4_data->i2c_client->dev,
2602 "Regulator vcc_ana set_opt failed rc=%d\n",
2603 retval);
2604 goto fail_regulator_lpm;
2605 }
2606
2607 if (rmi4_data->board->i2c_pull_up) {
2608 retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
Amy Malochecd38a572013-05-16 10:58:32 -07002609 RMI4_I2C_LPM_LOAD_UA);
Amy Maloche827e8b02013-02-27 15:25:14 -08002610 if (retval < 0) {
2611 dev_err(&rmi4_data->i2c_client->dev,
2612 "Regulator vcc_i2c set_opt failed rc=%d\n",
2613 retval);
2614 goto fail_regulator_lpm;
2615 }
2616 }
2617
2618 return 0;
2619
2620regulator_hpm:
2621
2622 retval = reg_set_optimum_mode_check(rmi4_data->vdd,
2623 RMI4_ACTIVE_LOAD_UA);
2624 if (retval < 0) {
2625 dev_err(&rmi4_data->i2c_client->dev,
2626 "Regulator vcc_ana set_opt failed rc=%d\n",
2627 retval);
2628 goto fail_regulator_hpm;
2629 }
2630
2631 if (rmi4_data->board->i2c_pull_up) {
2632 retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
2633 RMI4_I2C_LOAD_UA);
2634 if (retval < 0) {
2635 dev_err(&rmi4_data->i2c_client->dev,
2636 "Regulator vcc_i2c set_opt failed rc=%d\n",
2637 retval);
2638 goto fail_regulator_hpm;
2639 }
2640 }
2641
2642 return 0;
2643
2644fail_regulator_lpm:
2645 reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_ACTIVE_LOAD_UA);
2646 if (rmi4_data->board->i2c_pull_up)
2647 reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
2648 RMI4_I2C_LOAD_UA);
2649
2650 return retval;
2651
2652fail_regulator_hpm:
2653 reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
2654 if (rmi4_data->board->i2c_pull_up)
2655 reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
2656 RMI4_I2C_LPM_LOAD_UA);
2657 return retval;
2658}
2659
Alexandra Chin669d27c2012-12-24 15:42:30 +08002660 /**
2661 * synaptics_rmi4_suspend()
2662 *
2663 * Called by the kernel during the suspend phase when the system
2664 * enters suspend.
2665 *
2666 * This function stops finger data acquisition and puts the sensor to
2667 * sleep (if not already done so during the early suspend phase),
2668 * disables the interrupt, and turns off the power to the sensor.
2669 */
2670static int synaptics_rmi4_suspend(struct device *dev)
2671{
2672 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
Amy Maloche827e8b02013-02-27 15:25:14 -08002673 int retval;
Alexandra Chin669d27c2012-12-24 15:42:30 +08002674
Amy Maloche986863d2013-06-10 15:13:57 -07002675 if (rmi4_data->suspended) {
2676 dev_info(dev, "Already in suspend state\n");
2677 return 0;
2678 }
2679
Amy Malocheb494b9a2013-05-13 18:01:53 -07002680 if (!rmi4_data->fw_updating) {
2681 if (!rmi4_data->sensor_sleep) {
2682 rmi4_data->touch_stopped = true;
2683 wake_up(&rmi4_data->wait);
2684 synaptics_rmi4_irq_enable(rmi4_data, false);
2685 synaptics_rmi4_sensor_sleep(rmi4_data);
2686 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002687
Amy Malocheb494b9a2013-05-13 18:01:53 -07002688 retval = synaptics_rmi4_regulator_lpm(rmi4_data, true);
2689 if (retval < 0) {
2690 dev_err(dev, "failed to enter low power mode\n");
2691 return retval;
2692 }
Amy Maloche986863d2013-06-10 15:13:57 -07002693 } else {
Amy Malocheb494b9a2013-05-13 18:01:53 -07002694 dev_err(dev,
2695 "Firmware updating, cannot go into suspend mode\n");
Amy Maloche986863d2013-06-10 15:13:57 -07002696 return 0;
2697 }
2698
2699 rmi4_data->suspended = true;
2700
Alexandra Chin669d27c2012-12-24 15:42:30 +08002701 return 0;
2702}
2703
2704 /**
2705 * synaptics_rmi4_resume()
2706 *
2707 * Called by the kernel during the resume phase when the system
2708 * wakes up from suspend.
2709 *
2710 * This function turns on the power to the sensor, wakes the sensor
2711 * from sleep, enables the interrupt, and starts finger data
2712 * acquisition.
2713 */
2714static int synaptics_rmi4_resume(struct device *dev)
2715{
2716 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
Amy Maloche827e8b02013-02-27 15:25:14 -08002717 int retval;
2718
Amy Maloche986863d2013-06-10 15:13:57 -07002719 if (!rmi4_data->suspended) {
2720 dev_info(dev, "Already in awake state\n");
2721 return 0;
2722 }
2723
Amy Maloche827e8b02013-02-27 15:25:14 -08002724 retval = synaptics_rmi4_regulator_lpm(rmi4_data, false);
2725 if (retval < 0) {
2726 dev_err(dev, "failed to enter active power mode\n");
2727 return retval;
2728 }
Alexandra Chin669d27c2012-12-24 15:42:30 +08002729
2730 synaptics_rmi4_sensor_wake(rmi4_data);
2731 rmi4_data->touch_stopped = false;
2732 synaptics_rmi4_irq_enable(rmi4_data, true);
2733
Amy Maloche986863d2013-06-10 15:13:57 -07002734 rmi4_data->suspended = false;
2735
Alexandra Chin669d27c2012-12-24 15:42:30 +08002736 return 0;
2737}
2738
Amy Malochef46540d2013-02-15 17:09:43 -08002739#if (!defined(CONFIG_FB) && !defined(CONFIG_HAS_EARLYSUSPEND))
Alexandra Chin669d27c2012-12-24 15:42:30 +08002740static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
2741 .suspend = synaptics_rmi4_suspend,
2742 .resume = synaptics_rmi4_resume,
2743};
Amy Malochef46540d2013-02-15 17:09:43 -08002744#else
2745static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
2746};
2747#endif
Alexandra Chin669d27c2012-12-24 15:42:30 +08002748#endif
2749
2750static const struct i2c_device_id synaptics_rmi4_id_table[] = {
2751 {DRIVER_NAME, 0},
2752 {},
2753};
2754MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
2755
Amy Malocheecfb4892013-02-06 13:30:36 -08002756#ifdef CONFIG_OF
2757static struct of_device_id rmi4_match_table[] = {
2758 { .compatible = "synaptics,rmi4",},
2759 { },
2760};
2761#else
2762#define rmi4_match_table NULL
2763#endif
2764
Alexandra Chin669d27c2012-12-24 15:42:30 +08002765static struct i2c_driver synaptics_rmi4_driver = {
2766 .driver = {
2767 .name = DRIVER_NAME,
2768 .owner = THIS_MODULE,
Amy Malocheecfb4892013-02-06 13:30:36 -08002769 .of_match_table = rmi4_match_table,
Alexandra Chin669d27c2012-12-24 15:42:30 +08002770#ifdef CONFIG_PM
2771 .pm = &synaptics_rmi4_dev_pm_ops,
2772#endif
2773 },
2774 .probe = synaptics_rmi4_probe,
2775 .remove = __devexit_p(synaptics_rmi4_remove),
2776 .id_table = synaptics_rmi4_id_table,
2777};
2778
2779 /**
2780 * synaptics_rmi4_init()
2781 *
2782 * Called by the kernel during do_initcalls (if built-in)
2783 * or when the driver is loaded (if a module).
2784 *
2785 * This function registers the driver to the I2C subsystem.
2786 *
2787 */
2788static int __init synaptics_rmi4_init(void)
2789{
2790 return i2c_add_driver(&synaptics_rmi4_driver);
2791}
2792
2793 /**
2794 * synaptics_rmi4_exit()
2795 *
2796 * Called by the kernel when the driver is unloaded.
2797 *
2798 * This funtion unregisters the driver from the I2C subsystem.
2799 *
2800 */
2801static void __exit synaptics_rmi4_exit(void)
2802{
2803 i2c_del_driver(&synaptics_rmi4_driver);
2804}
2805
2806module_init(synaptics_rmi4_init);
2807module_exit(synaptics_rmi4_exit);
2808
2809MODULE_AUTHOR("Synaptics, Inc.");
2810MODULE_DESCRIPTION("Synaptics RMI4 I2C Touch Driver");
2811MODULE_LICENSE("GPL v2");