summaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorJordan Nien <jnien@nvidia.com>2017-11-14 04:34:22 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2018-01-09 19:51:16 -0500
commit8910c6722cdf8ebc24fe9f5e270ca8ff87275039 (patch)
tree41779f43815143f0f08997e4291ed1740db405c8 /drivers/input/touchscreen
parentcbadc34c3bc215e576604c6138a071b0236c588e (diff)
input: egalax: initial EETI touch driver.
Bug 200357614 IP audit bug: Bug 200372459 Change-Id: I7146cda32e954aab9f78eebb50d546c38465b51e Signed-off-by: EETI <touch_fae@eeti.com> Signed-off-by: Jordan Nien <jnien@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1613041 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/Kconfig13
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/exc80_ts.c1285
3 files changed, 1299 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index fb5033c8f..c5e1c6773 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -41,4 +41,17 @@ config TOUCHSCREEN_RM31080A
41 To compile this driver as a module, choose M here: the 41 To compile this driver as a module, choose M here: the
42 module will be called RAYDIUM_31080A. 42 module will be called RAYDIUM_31080A.
43 43
44config TOUCHSCREEN_EXC80
45 tristate "EGALAX_EXC80 based touchscreens"
46 depends on I2C
47 help
48 Say Y here if you have a touchscreen interface using the
49 EGALAX controller, and your board-specific initialization
50 code includes that in its table of I2C devices.
51
52 If unsure, say N (but it's safe to say "Y").
53
54 To compile this driver as a module, choose M here: the
55 module will be called EGALAX.
56
44endif 57endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 812659591..b88114db8 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_TOUCHSCREEN_NVIDIA_ATMEL_MXT) += atmel_mxt_ts_nv.o 1obj-$(CONFIG_TOUCHSCREEN_NVIDIA_ATMEL_MXT) += atmel_mxt_ts_nv.o
2obj-$(CONFIG_TOUCHSCREEN_RM31080A) += rm31080a_ts.o rm31080a_ctrl.o 2obj-$(CONFIG_TOUCHSCREEN_RM31080A) += rm31080a_ts.o rm31080a_ctrl.o
3obj-$(CONFIG_TOUCHSCREEN_LR388K7) += lr388k7_ts.o 3obj-$(CONFIG_TOUCHSCREEN_LR388K7) += lr388k7_ts.o
4obj-$(CONFIG_TOUCHSCREEN_EXC80) += exc80_ts.o \ No newline at end of file
diff --git a/drivers/input/touchscreen/exc80_ts.c b/drivers/input/touchscreen/exc80_ts.c
new file mode 100644
index 000000000..83d86ea57
--- /dev/null
+++ b/drivers/input/touchscreen/exc80_ts.c
@@ -0,0 +1,1285 @@
1/*
2 *
3 * Touch Screen I2C Driver for EETI Controller
4 *
5 * Copyright (C) 2000-2017 eGalax_eMPIA Technology Inc. All rights reserved.
6 * Copyright (c) 2017 NVIDIA CORPORATION. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#define RELEASE_DATE "2017/12/20"
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/interrupt.h>
26#include <linux/wait.h>
27#include <linux/delay.h>
28#include <linux/i2c.h>
29#include <linux/gpio.h>
30#include <linux/device.h>
31#include <linux/uaccess.h>
32#include <linux/kfifo.h>
33#include <linux/version.h>
34#include <linux/input.h>
35#include <linux/irq.h>
36#include <linux/timer.h>
37#include <linux/proc_fs.h>
38#include <linux/seq_file.h>
39#include <linux/miscdevice.h>
40#include <linux/slab.h>
41#include <linux/poll.h>
42#include <linux/input/mt.h>
43#include <linux/of_gpio.h>
44#include <linux/regulator/consumer.h>
45
46/* Global define to enable function */
47/* #define _SWITCH_XY */
48/* #define _CONVERT_Y */
49
50#define MAX_EVENTS 600
51#define MAX_I2C_LEN 64U
52#define FIFO_SIZE 8192
53#define MAX_SUPPORT_POINT 16
54#define REPORTID_VENDOR 0x03
55#define REPORTID_MTOUCH 0x06
56#define MAX_RESOLUTION 4095
57#define MAX_Z_RESOLUTION 1023
58
59/* running mode */
60#define MODE_STOP 0
61#define MODE_WORKING 1
62#define MODE_IDLE 2
63#define MODE_SUSPEND 3
64
65struct tagMTContacts {
66 unsigned char ID;
67 signed char Status;
68 unsigned short X;
69 unsigned short Y;
70 unsigned short Z;
71};
72
73struct _egalax_i2c {
74 struct workqueue_struct *ktouch_wq;
75 struct work_struct work_irq;
76 struct delayed_work delay_work_ioctl;
77 struct mutex mutex_wq;
78 struct i2c_client *client;
79 unsigned char work_state;
80 unsigned char skip_packet;
81 unsigned int ioctl_cmd;
82 int interrupt_gpio;
83 int reset_gpio;
84 wait_queue_head_t sysfs_query_queue;
85 bool sysfs_query_wait;
86 unsigned char sysfs_hook_cmd[3];
87 unsigned char sysfs_cmd_result[MAX_I2C_LEN];
88 struct regulator *regulator_hv;
89 struct regulator *regulator_5v0;
90 struct regulator *regulator_3v3;
91 struct regulator *regulator_1v8;
92};
93
94struct egalax_char_dev {
95 int OpenCnts;
96 struct kfifo DataKFiFo;
97 unsigned char *pFiFoBuf;
98 spinlock_t FiFoLock;
99 struct semaphore sem;
100 wait_queue_head_t fifo_inq;
101};
102
103static struct _egalax_i2c *p_egalax_i2c_dev;
104static struct egalax_char_dev *p_char_dev;
105static atomic_t egalax_char_available = ATOMIC_INIT(1);
106static atomic_t wait_command_ack = ATOMIC_INIT(0);
107static struct input_dev *input_dev;
108static struct tagMTContacts pContactBuf[MAX_SUPPORT_POINT];
109static unsigned char input_report_buf[MAX_I2C_LEN+2];
110static char fifo_read_buf[MAX_I2C_LEN];
111static int TotalPtsCnt, RecvPtsCnt;
112
113#define DBG_MODULE 0x00000001U
114#define DBG_CDEV 0x00000002U
115#define DBG_PROC 0x00000004U
116#define DBG_POINT 0x00000008U
117#define DBG_INT 0x00000010U
118#define DBG_I2C 0x00000020U
119#define DBG_SUSP 0x00000040U
120#define DBG_INPUT 0x00000080U
121#define DBG_CONST 0x00000100U
122#define DBG_IDLE 0x00000200U
123#define DBG_WAKEUP 0x00000400U
124#define DBG_BUTTON 0x00000800U
125static unsigned int DbgLevel = DBG_MODULE|DBG_SUSP;
126
127#define PROC_FS_NAME "egalax_dbg"
128#define PROC_FS_MAX_LEN 8
129static struct proc_dir_entry *dbgProcFile;
130
131#define EGALAX_DBG(level, fmt, args...) \
132do { if ((level & DbgLevel) > 0U) { \
133pr_debug("egalax_i2c: " fmt, ## args); } \
134} while (false)
135
136static int egalax_I2C_read(unsigned char *pBuf, unsigned short len)
137{
138 struct i2c_msg xfer;
139
140 if (pBuf == NULL)
141 return -1;
142
143 /* Read device data */
144 xfer.addr = p_egalax_i2c_dev->client->addr;
145 xfer.flags = I2C_M_RD;
146 xfer.len = len;
147 xfer.buf = pBuf;
148
149 if (i2c_transfer(p_egalax_i2c_dev->client->adapter, &xfer, 1) != 1) {
150 EGALAX_DBG(DBG_I2C, " %s: i2c transfer fail\n", __func__);
151 return -EIO;
152 }
153
154 EGALAX_DBG(DBG_I2C, " %s: i2c transfer success\n", __func__);
155
156 return 0;
157}
158
159static int egalax_I2C_write(unsigned short reg, unsigned char *pBuf,
160 unsigned short len)
161{
162 unsigned char cmdbuf[4+len];
163 struct i2c_msg xfer;
164
165 if (pBuf == NULL)
166 return -1;
167
168 cmdbuf[0] = reg & 0x00FFU;
169 cmdbuf[1] = (reg >> 8) & 0x00FFU;
170 cmdbuf[2] = (len+2) & 0x00FFU;
171 cmdbuf[3] = ((len+2) >> 8) & 0x00FFU;
172 memcpy(cmdbuf+4, pBuf, len);
173
174 /* Write data to device */
175 xfer.addr = p_egalax_i2c_dev->client->addr;
176 xfer.flags = 0;
177 xfer.len = sizeof(cmdbuf);
178 xfer.buf = cmdbuf;
179
180 if (i2c_transfer(p_egalax_i2c_dev->client->adapter, &xfer, 1) != 1) {
181 EGALAX_DBG(DBG_I2C, " %s: i2c transfer fail\n", __func__);
182 return -EIO;
183 }
184
185 EGALAX_DBG(DBG_I2C, " %s: i2c transfer success\n", __func__);
186
187 return 0;
188}
189
190static int egalax_cdev_open(struct inode *inode, struct file *filp)
191{
192 if (!atomic_dec_and_test(&egalax_char_available)) {
193 atomic_inc(&egalax_char_available);
194 return -EBUSY;
195 }
196
197 p_char_dev->OpenCnts++;
198 filp->private_data = p_char_dev;
199
200 EGALAX_DBG(DBG_CDEV, " CDev open done!\n");
201 try_module_get(THIS_MODULE);
202 return 0;
203}
204
205static int egalax_cdev_release(struct inode *inode, struct file *filp)
206{
207 struct egalax_char_dev *cdev = filp->private_data;
208
209 atomic_inc(&egalax_char_available);
210
211 cdev->OpenCnts--;
212
213 kfifo_reset(&cdev->DataKFiFo);
214
215 EGALAX_DBG(DBG_CDEV, " CDev release done!\n");
216 module_put(THIS_MODULE);
217 return 0;
218}
219
220static ssize_t egalax_cdev_read(struct file *file, char __user *buf,
221 size_t count, loff_t *offset)
222{
223 int read_cnt, ret, fifoLen;
224 struct egalax_char_dev *cdev = file->private_data;
225
226 if (down_interruptible(&cdev->sem))
227 return -ERESTARTSYS;
228
229 fifoLen = kfifo_len(&cdev->DataKFiFo);
230
231 while (fifoLen < 1) {
232 /* release the lock */
233 up(&cdev->sem);
234 if (file->f_flags & O_NONBLOCK)
235 return -EAGAIN;
236
237 if (wait_event_interruptible(cdev->fifo_inq,
238 kfifo_len(&cdev->DataKFiFo) > 0)) {
239 /* signal: tell the fs layer to handle it */
240 return -ERESTARTSYS;
241 }
242
243 if (down_interruptible(&cdev->sem))
244 return -ERESTARTSYS;
245 }
246
247 if (count > MAX_I2C_LEN)
248 count = MAX_I2C_LEN;
249
250 read_cnt = kfifo_out_locked(&cdev->DataKFiFo, fifo_read_buf, count,
251 &cdev->FiFoLock);
252
253 EGALAX_DBG(DBG_CDEV, " \"%s\" reading fifo data count=%d\n",
254 current->comm, read_cnt);
255
256 ret = copy_to_user(buf, fifo_read_buf, read_cnt) ? -EFAULT : read_cnt;
257
258 up(&cdev->sem);
259
260 return ret;
261}
262
263static ssize_t egalax_cdev_write(struct file *file, const char __user *buf,
264 size_t count, loff_t *offset)
265{
266 struct egalax_char_dev *cdev = file->private_data;
267 int ret = 0;
268 char *tmp;
269
270 if (down_interruptible(&cdev->sem))
271 return -ERESTARTSYS;
272
273 if (count > MAX_I2C_LEN)
274 count = MAX_I2C_LEN;
275
276 tmp = kzalloc(MAX_I2C_LEN, GFP_KERNEL);
277 if (tmp == NULL) {
278 up(&cdev->sem);
279 return -ENOMEM;
280 }
281
282 if (copy_from_user(tmp, buf, count)) {
283 up(&cdev->sem);
284 kfree(tmp);
285 return -EFAULT;
286 }
287
288 ret = egalax_I2C_write(0x0067, tmp, MAX_I2C_LEN);
289
290 up(&cdev->sem);
291 EGALAX_DBG(DBG_CDEV, " I2C writing %zu bytes.\n", count);
292 kfree(tmp);
293
294 return (ret == 0 ? count : -1);
295}
296
297static unsigned int egalax_cdev_poll(struct file *filp,
298 struct poll_table_struct *wait)
299{
300 struct egalax_char_dev *cdev = filp->private_data;
301 unsigned int mask = 0;
302 int fifoLen;
303
304 down(&cdev->sem);
305 poll_wait(filp, &cdev->fifo_inq, wait);
306
307 fifoLen = kfifo_len(&cdev->DataKFiFo);
308
309 if (fifoLen > 0)
310 mask |= POLLIN | POLLRDNORM;
311
312 if ((FIFO_SIZE - fifoLen) > MAX_I2C_LEN)
313 mask |= POLLOUT | POLLWRNORM;
314
315 up(&cdev->sem);
316 return mask;
317}
318
319static int egalax_proc_show(struct seq_file *seqfilp, void *v)
320{
321 seq_printf(seqfilp,
322 "EETI I2C for All Points.\nDebug Level: 0x%08X\nRelease Date: %s\n",
323 DbgLevel, RELEASE_DATE);
324
325 return 0;
326}
327
328static int egalax_proc_open(struct inode *inode, struct file *filp)
329{
330 EGALAX_DBG(DBG_PROC, " \"%s\" call proc_open\n", current->comm);
331 return single_open(filp, egalax_proc_show, NULL);
332}
333
334static ssize_t egalax_proc_write(struct file *file, const char __user *buf,
335 size_t count, loff_t *offset)
336{
337 char procfs_buffer_size = 0;
338 unsigned char procfs_buf[PROC_FS_MAX_LEN+1] = {0};
339 unsigned int newLevel = 0;
340
341 EGALAX_DBG(DBG_PROC, " \"%s\" call proc_write\n", current->comm);
342
343 procfs_buffer_size = count;
344 if (procfs_buffer_size > PROC_FS_MAX_LEN)
345 procfs_buffer_size = PROC_FS_MAX_LEN+1;
346
347 if (copy_from_user(procfs_buf, buf, procfs_buffer_size)) {
348 EGALAX_DBG(DBG_PROC, " proc_write faied at copy_from_user\n");
349 return -EFAULT;
350 }
351
352 if (!kstrtouint(procfs_buf, 16, &newLevel))
353 DbgLevel = newLevel;
354
355 EGALAX_DBG(DBG_PROC, " Switch Debug Level to 0x%08X\n", DbgLevel);
356
357 return procfs_buffer_size;
358}
359
360static bool sys_sendcmd_wait(unsigned char *bySendCmd, int nSendCmdLen,
361 unsigned char *byHookCmd, int nHookCmdLen,
362 int nTimeOut)
363{
364 int i;
365 bool bRet = true;
366
367 memset(p_egalax_i2c_dev->sysfs_cmd_result, 0,
368 sizeof(p_egalax_i2c_dev->sysfs_cmd_result));
369
370 for (i = 0; i < 3; i++) {
371 if (i < nHookCmdLen)
372 p_egalax_i2c_dev->sysfs_hook_cmd[i] = byHookCmd[i];
373 else
374 p_egalax_i2c_dev->sysfs_hook_cmd[i] = 0xFF;
375 }
376 p_egalax_i2c_dev->sysfs_query_wait = true;
377
378 if (egalax_I2C_write(0x0067, bySendCmd, nSendCmdLen) != 0) {
379 bRet = false;
380 } else {
381 wait_event_interruptible_timeout(
382 p_egalax_i2c_dev->sysfs_query_queue,
383 !p_egalax_i2c_dev->sysfs_query_wait,
384 nTimeOut);
385
386 if (p_egalax_i2c_dev->sysfs_query_wait)
387 bRet = false;
388 else
389 bRet = true;
390 }
391 p_egalax_i2c_dev->sysfs_query_wait = false;
392 return bRet;
393}
394
395#define OP_MODE_GET 0x00
396#define OP_MODE_SET 0x01
397static ssize_t sys_show_version(struct device *dev,
398 struct device_attribute *attr, char *buf)
399{
400 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
401 0x03, 0x04, 0x36, 0x91, 0x01, OP_MODE_GET};
402 bool bRet = true;
403
404 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
405 if (bRet)
406 return snprintf(buf, PAGE_SIZE, "Driver: %s FW: %s\n",
407 RELEASE_DATE, p_egalax_i2c_dev->sysfs_cmd_result+6);
408 else
409 return snprintf(buf, PAGE_SIZE, "Driver: %s FW: Invalid\n",
410 RELEASE_DATE);
411
412}
413
414static ssize_t sys_show_touchevent(struct device *dev,
415 struct device_attribute *attr, char *buf)
416{
417 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
418 0x03, 0x04, 0x36, 0x91, 0x02, OP_MODE_GET};
419 bool bRet = true;
420 int code = 0;
421
422 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
423 if (bRet) {
424 code = p_egalax_i2c_dev->sysfs_cmd_result[6];
425 code += (p_egalax_i2c_dev->sysfs_cmd_result[7]<<8);
426 code += (p_egalax_i2c_dev->sysfs_cmd_result[8]<<16);
427 code += (p_egalax_i2c_dev->sysfs_cmd_result[9]<<24);
428 return snprintf(buf, PAGE_SIZE, "0x%08X\n", code);
429 } else
430 return snprintf(buf, PAGE_SIZE, "Invalid\n");
431}
432
433static ssize_t sys_show_reportmode(struct device *dev,
434 struct device_attribute *attr, char *buf)
435{
436 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
437 0x03, 0x04, 0x36, 0x91, 0x04, OP_MODE_GET};
438 bool bRet = true;
439
440 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
441 if (bRet)
442 return snprintf(buf, PAGE_SIZE, "%02X\n",
443 p_egalax_i2c_dev->sysfs_cmd_result[6]);
444 else
445 return snprintf(buf, PAGE_SIZE, "Invalid\n");
446}
447
448#define NV_REPORTMODE_MAX 0x06
449static ssize_t sys_store_reportmode(struct device *dev,
450 struct device_attribute *attr,
451 const char *buf, size_t count)
452{
453 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
454 0x03, 0x05, 0x36, 0x91, 0x04, OP_MODE_SET};
455 bool bRet = true;
456 char mode;
457
458 if (count != 2)
459 return -EINVAL;
460
461 mode = buf[0]-'0';
462 if (mode > NV_REPORTMODE_MAX || mode < 0)
463 return -EINVAL;
464
465 SendCmdBuf[6] = mode;
466
467 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
468 if (bRet)
469 return count;
470 else
471 return -EIO;
472}
473
474static ssize_t sys_show_bypassmode(struct device *dev,
475 struct device_attribute *attr, char *buf)
476{
477 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
478 0x03, 0x04, 0x36, 0x91, 0x05, OP_MODE_GET};
479 bool bRet = true;
480
481 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
482 if (bRet)
483 return snprintf(buf, PAGE_SIZE, "%02X\n",
484 p_egalax_i2c_dev->sysfs_cmd_result[6]);
485 else
486 return snprintf(buf, PAGE_SIZE, "Invalid\n");
487}
488
489#define NV_BYPASSMODE_MAX 0x02
490static ssize_t sys_store_bypassmode(struct device *dev,
491 struct device_attribute *attr,
492 const char *buf, size_t count)
493{
494 unsigned char SendCmdBuf[MAX_I2C_LEN] = {
495 0x03, 0x05, 0x36, 0x91, 0x05, OP_MODE_SET};
496 bool bRet = true;
497 char mode;
498
499 if (count != 2)
500 return -EINVAL;
501
502 mode = buf[0]-'0';
503 if (mode > NV_BYPASSMODE_MAX || mode < 0)
504 return -EINVAL;
505
506 SendCmdBuf[6] = mode;
507
508 bRet = sys_sendcmd_wait(SendCmdBuf, MAX_I2C_LEN, SendCmdBuf+2, 3, HZ);
509 if (bRet)
510 return count;
511 else
512 return -EIO;
513}
514
515static DEVICE_ATTR(version, 0640, sys_show_version, NULL);
516static DEVICE_ATTR(touch_event, 0640, sys_show_touchevent, NULL);
517static DEVICE_ATTR(report_mode, 0640, sys_show_reportmode,
518 sys_store_reportmode);
519static DEVICE_ATTR(bypass_mode, 0640, sys_show_bypassmode,
520 sys_store_bypassmode);
521
522static struct attribute *egalax_attributes[] = {
523 &dev_attr_version.attr,
524 &dev_attr_touch_event.attr,
525 &dev_attr_report_mode.attr,
526 &dev_attr_bypass_mode.attr,
527 NULL,
528};
529
530static const struct attribute_group egalax_attr_group = {
531 .attrs = egalax_attributes,
532};
533
534#define STYLUS_MASK 0x10
535#define MAX_POINT_PER_PACKET 5U
536#define POINT_STRUCT_SIZE 10U
537static void ProcessReport(unsigned char *buf,
538 struct _egalax_i2c *p_egalax_i2c)
539{
540 unsigned char i, index = 0, cnt_down = 0, cnt_up = 0, shift = 0;
541 unsigned char status = 0;
542 unsigned short contactID = 0, x = 0, y = 0, z = 0;
543
544 if (TotalPtsCnt <= 0) {
545 if ((buf[1] == 0) || (buf[1] > MAX_SUPPORT_POINT)) {
546 EGALAX_DBG(DBG_POINT,
547 " NumsofContacts mismatch, skip packet\n");
548 return;
549 }
550
551 TotalPtsCnt = buf[1];
552 RecvPtsCnt = 0;
553 } else if (buf[1] > 0) {
554 TotalPtsCnt = 0;
555 RecvPtsCnt = 0;
556 EGALAX_DBG(DBG_POINT,
557 " NumsofContacts mismatch, skip packet\n");
558 return;
559 }
560
561 while (index < MAX_POINT_PER_PACKET) {
562 shift = index * POINT_STRUCT_SIZE + 2;
563 status = buf[shift];
564 contactID = buf[shift+1];
565 x = ((buf[shift+3]<<8) + buf[shift+2]);
566 y = ((buf[shift+5]<<8) + buf[shift+4]);
567 z = ((buf[shift+7]<<8) + buf[shift+6]);
568
569 if (contactID >= MAX_SUPPORT_POINT) {
570 TotalPtsCnt = 0;
571 RecvPtsCnt = 0;
572 EGALAX_DBG(DBG_POINT, " Get error ContactID.\n");
573 return;
574 }
575
576 EGALAX_DBG(DBG_POINT,
577 " Get Point[%d] Update: Status=%d X=%d Y=%d\n",
578 contactID, status, x, y);
579
580 #ifdef _SWITCH_XY
581 short tmp = x;
582
583 x = y;
584 y = tmp;
585 #endif
586
587 #ifdef _CONVERT_X
588 x = MAX_RESOLUTION-x;
589 #endif
590
591 #ifdef _CONVERT_Y
592 y = MAX_RESOLUTION-y;
593 #endif
594
595 pContactBuf[RecvPtsCnt].ID = contactID;
596 pContactBuf[RecvPtsCnt].Status = status;
597 pContactBuf[RecvPtsCnt].X = x;
598 pContactBuf[RecvPtsCnt].Y = y;
599 pContactBuf[RecvPtsCnt].Z = z;
600
601 RecvPtsCnt++;
602 index++;
603
604 /* Recv all points, send input report */
605 if (RecvPtsCnt == TotalPtsCnt) {
606 for (i = 0; i < RecvPtsCnt; i++) {
607 input_mt_slot(input_dev, pContactBuf[i].ID);
608 if ((pContactBuf[i].Status &
609 STYLUS_MASK) != 0) {
610 input_mt_report_slot_state(input_dev,
611 MT_TOOL_PEN,
612 ((pContactBuf[i].Status&0x01)
613 != 0));
614 } else {
615 input_mt_report_slot_state(input_dev,
616 MT_TOOL_FINGER,
617 ((pContactBuf[i].Status&0x01)
618 != 0));
619 }
620
621 if ((pContactBuf[i].Status & 0x01) != 0) {
622 input_report_abs(input_dev,
623 ABS_MT_POSITION_X,
624 pContactBuf[i].X);
625 input_report_abs(input_dev,
626 ABS_MT_POSITION_Y,
627 pContactBuf[i].Y);
628 input_report_abs(input_dev,
629 ABS_MT_PRESSURE,
630 pContactBuf[i].Z);
631 }
632
633 if ((pContactBuf[i].Status & 0x01) != 0)
634 cnt_down++;
635 else
636 cnt_up++;
637 }
638
639 input_sync(input_dev);
640 EGALAX_DBG(DBG_POINT,
641 " Input sync point data done! (Down:%d Up:%d)\n",
642 cnt_down, cnt_up);
643
644 TotalPtsCnt = 0;
645 RecvPtsCnt = 0;
646 return;
647 }
648 }
649}
650
651static struct input_dev *allocate_Input_Dev(void)
652{
653 int ret;
654 struct input_dev *pInputDev = NULL;
655
656 pInputDev = input_allocate_device();
657 if (pInputDev == NULL) {
658 EGALAX_DBG(DBG_MODULE, " Failed to allocate input device\n");
659 return NULL;
660 }
661
662 pInputDev->name = "eGalax_Touch_Screen";
663 pInputDev->phys = "I2C";
664 pInputDev->id.bustype = BUS_I2C;
665 pInputDev->id.vendor = 0x0EEF;
666 pInputDev->id.product = 0x0020;
667 pInputDev->id.version = 0x0001;
668
669 set_bit(EV_ABS, pInputDev->evbit);
670 __set_bit(INPUT_PROP_DIRECT, pInputDev->propbit);
671 input_mt_init_slots(pInputDev, MAX_SUPPORT_POINT, 0);
672 input_set_abs_params(pInputDev, ABS_MT_POSITION_X, 0,
673 MAX_RESOLUTION, 0, 0);
674 input_set_abs_params(pInputDev, ABS_MT_POSITION_Y, 0,
675 MAX_RESOLUTION, 0, 0);
676 input_set_abs_params(pInputDev, ABS_MT_PRESSURE, 0,
677 MAX_Z_RESOLUTION, 0, 0);
678 input_set_abs_params(pInputDev, ABS_MT_TOOL_TYPE, 0,
679 MT_TOOL_MAX, 0, 0);
680
681 input_set_events_per_packet(pInputDev, MAX_EVENTS);
682
683 ret = input_register_device(pInputDev);
684 if (ret) {
685 EGALAX_DBG(DBG_MODULE, " Unable to register input device.\n");
686 input_free_device(pInputDev);
687 pInputDev = NULL;
688 }
689
690 return pInputDev;
691}
692
693static int egalax_i2c_measure(struct _egalax_i2c *egalax_i2c)
694{
695 int ret = 0, frameLen = 0, loop = 3, i;
696
697 EGALAX_DBG(DBG_INT, " egalax_i2c_measure\n");
698
699 if (egalax_I2C_read(input_report_buf, MAX_I2C_LEN+2) < 0) {
700 EGALAX_DBG(DBG_I2C, " I2C read input report fail!\n");
701 return -1;
702 }
703
704 if ((DbgLevel & DBG_I2C) != 0U) {
705 char dbgmsg[(MAX_I2C_LEN+2)*4];
706
707 for (i = 0; i < (MAX_I2C_LEN+2); i++)
708 snprintf(dbgmsg+(i*4), 4, "[%02X]",
709 input_report_buf[i]);
710
711 EGALAX_DBG(DBG_I2C, " Buf=%s\n", dbgmsg);
712 }
713
714 frameLen = input_report_buf[0] + (input_report_buf[1]<<8);
715 EGALAX_DBG(DBG_I2C, " I2C read data with Len=%d\n", frameLen);
716
717 if (frameLen == 0) {
718 EGALAX_DBG(DBG_MODULE, " Device reset\n");
719 return -1;
720 }
721
722 switch (input_report_buf[2]) {
723 case REPORTID_MTOUCH:
724 if (!egalax_i2c->skip_packet &&
725 egalax_i2c->work_state == MODE_WORKING) {
726 ProcessReport(input_report_buf+2, egalax_i2c);
727 }
728 ret = 0;
729 break;
730 case REPORTID_VENDOR:
731 atomic_set(&wait_command_ack, 1);
732 EGALAX_DBG(DBG_I2C, " I2C get vendor command packet\n");
733
734 if (egalax_i2c->sysfs_query_wait &&
735 egalax_i2c->sysfs_hook_cmd[0] == input_report_buf[2+2]
736 && ((egalax_i2c->sysfs_hook_cmd[1] == 0xFF) ||
737 egalax_i2c->sysfs_hook_cmd[1] == input_report_buf[2+3])
738 && ((egalax_i2c->sysfs_hook_cmd[2] == 0xFF) ||
739 egalax_i2c->sysfs_hook_cmd[2] == input_report_buf[2+4])
740 ) {
741 memcpy(egalax_i2c->sysfs_cmd_result,
742 input_report_buf+2, input_report_buf[2+1]+2);
743 egalax_i2c->sysfs_query_wait = false;
744 wake_up_interruptible(&egalax_i2c->sysfs_query_queue);
745 break;
746 }
747
748 /* If someone reading now! put the data into the buffer! */
749 if (p_char_dev->OpenCnts > 0) {
750 loop = 3;
751 do {
752 ret = wait_event_timeout(p_char_dev->fifo_inq,
753 (kfifo_avail(&p_char_dev->DataKFiFo) >=
754 MAX_I2C_LEN), HZ);
755 } while (ret <= 0 && --loop);
756
757 /* fifo size is ready */
758 if (ret > 0) {
759 ret = kfifo_in_locked(&p_char_dev->DataKFiFo,
760 (input_report_buf+2), MAX_I2C_LEN,
761 &p_char_dev->FiFoLock);
762 wake_up_interruptible(&p_char_dev->fifo_inq);
763 } else {
764 EGALAX_DBG(DBG_CDEV,
765 " [Warning] fifo size is overflow.\n");
766 }
767 }
768
769 break;
770 default:
771 EGALAX_DBG(DBG_I2C, " I2C read error data with hedaer=%d\n",
772 input_report_buf[2]);
773 ret = -1;
774 break;
775 }
776
777 return ret;
778}
779
780static void egalax_i2c_wq_irq(struct work_struct *work)
781{
782 struct _egalax_i2c *egalax_i2c =
783 container_of(work, struct _egalax_i2c, work_irq);
784 struct i2c_client *client = egalax_i2c->client;
785
786 EGALAX_DBG(DBG_INT, " egalax_i2c_wq run\n");
787
788 /* continue recv data */
789 while (gpio_get_value(egalax_i2c->interrupt_gpio) == 0) {
790 egalax_i2c_measure(egalax_i2c);
791 schedule();
792 }
793
794 if (egalax_i2c->skip_packet > 0U)
795 egalax_i2c->skip_packet = 0U;
796
797 enable_irq(client->irq);
798
799 EGALAX_DBG(DBG_INT, " egalax_i2c_wq leave\n");
800}
801
802static irqreturn_t egalax_i2c_interrupt(int irq, void *dev_id)
803{
804 struct _egalax_i2c *egalax_i2c = (struct _egalax_i2c *)dev_id;
805
806 EGALAX_DBG(DBG_INT, " INT with irq:%d\n", irq);
807
808 disable_irq_nosync(irq);
809
810 queue_work(egalax_i2c->ktouch_wq, &egalax_i2c->work_irq);
811
812 return IRQ_HANDLED;
813}
814
815static void egalax_i2c_senduppoint(void)
816{
817 int i = 0;
818
819 EGALAX_DBG(DBG_SUSP, " %s\n", __func__);
820
821 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
822 input_mt_slot(input_dev, pContactBuf[i].ID);
823 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false);
824 pContactBuf[i].Status = 0;
825 }
826
827 input_sync(input_dev);
828 EGALAX_DBG(DBG_POINT, " Sent up point data done!\n");
829}
830
831static int egalax_power_off(void)
832{
833 int error;
834
835 gpio_direction_output(p_egalax_i2c_dev->reset_gpio, 0);
836 error = regulator_enable(p_egalax_i2c_dev->regulator_hv);
837 if (error < 0)
838 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
839 error);
840 error = regulator_enable(p_egalax_i2c_dev->regulator_5v0);
841 if (error < 0)
842 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
843 error);
844 error = regulator_enable(p_egalax_i2c_dev->regulator_3v3);
845 if (error < 0)
846 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
847 error);
848 error = regulator_enable(p_egalax_i2c_dev->regulator_1v8);
849 if (error < 0)
850 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
851 error);
852
853 return 0;
854}
855
856static int egalax_power_on(void)
857{
858 int error;
859
860 error = regulator_enable(p_egalax_i2c_dev->regulator_hv);
861 if (error < 0)
862 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
863 error);
864 error = regulator_enable(p_egalax_i2c_dev->regulator_5v0);
865 if (error < 0)
866 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
867 error);
868 error = regulator_enable(p_egalax_i2c_dev->regulator_1v8);
869 if (error < 0)
870 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
871 error);
872 error = regulator_enable(p_egalax_i2c_dev->regulator_3v3);
873 if (error < 0)
874 EGALAX_DBG(DBG_MODULE, " regulator enable failed: %d\n",
875 error);
876 usleep_range(1000, 5000);
877 gpio_direction_output(p_egalax_i2c_dev->reset_gpio, 1);
878
879 return 0;
880}
881
882static int egalax_i2c_pm_suspend(struct i2c_client *client, pm_message_t mesg)
883{
884 EGALAX_DBG(DBG_SUSP, " Enter pm_suspend state:%d\n",
885 p_egalax_i2c_dev->work_state);
886
887 if (!p_egalax_i2c_dev)
888 goto fail_suspend;
889
890 egalax_power_off();
891
892 p_egalax_i2c_dev->work_state = MODE_SUSPEND;
893
894 EGALAX_DBG(DBG_SUSP, " pm_suspend done!!\n");
895 return 0;
896
897fail_suspend:
898 EGALAX_DBG(DBG_SUSP, " pm_suspend failed!!\n");
899 return -1;
900}
901
902static int egalax_i2c_pm_resume(struct i2c_client *client)
903{
904 EGALAX_DBG(DBG_SUSP, " Enter pm_resume state:%d\n",
905 p_egalax_i2c_dev->work_state);
906
907 if (!p_egalax_i2c_dev)
908 goto fail_resume;
909
910 p_egalax_i2c_dev->work_state = MODE_WORKING;
911
912 egalax_power_on();
913
914 egalax_i2c_senduppoint();
915
916 EGALAX_DBG(DBG_SUSP, " pm_resume done!!\n");
917 return 0;
918
919fail_resume:
920 EGALAX_DBG(DBG_SUSP, " pm_resume failed!!\n");
921 return -1;
922}
923
924static int egalax_i2c_ops_suspend(struct device *dev)
925{
926 struct i2c_client *client = to_i2c_client(dev);
927 pm_message_t state;
928
929 state.event = PM_EVENT_SUSPEND;
930 EGALAX_DBG(DBG_SUSP, " %s\n", __func__);
931 return egalax_i2c_pm_suspend(client, state);
932}
933
934static int egalax_i2c_ops_resume(struct device *dev)
935{
936 struct i2c_client *client = to_i2c_client(dev);
937
938 EGALAX_DBG(DBG_SUSP, " %s\n", __func__);
939 return egalax_i2c_pm_resume(client);
940}
941
942static int request_dt(struct i2c_client *client)
943{
944 int result = 0;
945 struct device_node *devnode;
946
947 devnode = client->dev.of_node;
948 if (devnode) {
949 p_egalax_i2c_dev->interrupt_gpio = of_get_named_gpio(devnode,
950 "irq-gpio", 0);
951 p_egalax_i2c_dev->reset_gpio = of_get_named_gpio(devnode,
952 "reset-gpio", 0);
953 /* regulator */
954 p_egalax_i2c_dev->regulator_hv = devm_regulator_get(
955 &client->dev, "vdd-ts-hv");
956 if (IS_ERR(p_egalax_i2c_dev->regulator_hv)) {
957 EGALAX_DBG(DBG_MODULE,
958 "vdd-12v regulator_get failed: %ld\n",
959 PTR_ERR(p_egalax_i2c_dev->regulator_hv));
960 return -EINVAL;
961 }
962 p_egalax_i2c_dev->regulator_5v0 = devm_regulator_get(
963 &client->dev, "vdd-ts-5v0");
964 if (IS_ERR(p_egalax_i2c_dev->regulator_5v0)) {
965 EGALAX_DBG(DBG_MODULE,
966 "vdd-5v regulator_get failed: %ld\n",
967 PTR_ERR(p_egalax_i2c_dev->regulator_5v0));
968 return -EINVAL;
969 }
970
971 p_egalax_i2c_dev->regulator_3v3 = devm_regulator_get(
972 &client->dev, "vdd-ts-3v3");
973 if (IS_ERR(p_egalax_i2c_dev->regulator_3v3)) {
974 EGALAX_DBG(DBG_MODULE,
975 "vdd 3v3 regulator_get failed: %ld\n",
976 PTR_ERR(p_egalax_i2c_dev->regulator_3v3));
977 return -EINVAL;
978 }
979 p_egalax_i2c_dev->regulator_1v8 = devm_regulator_get(
980 &client->dev, "vdd-ts-1v8");
981 if (IS_ERR(p_egalax_i2c_dev->regulator_1v8)) {
982 EGALAX_DBG(DBG_MODULE,
983 "vdd 18v regulator_get failed: %ld\n",
984 PTR_ERR(p_egalax_i2c_dev->regulator_1v8));
985 return -EINVAL;
986 }
987 }
988
989 if (!gpio_is_valid(p_egalax_i2c_dev->interrupt_gpio)) {
990 EGALAX_DBG(DBG_MODULE, " gpio[%d] is not valid\n",
991 p_egalax_i2c_dev->interrupt_gpio);
992 return -EINVAL;
993 }
994 result = gpio_request(p_egalax_i2c_dev->interrupt_gpio, "irq-gpio");
995 if (result < 0) {
996 EGALAX_DBG(DBG_MODULE, " gpio_request[%d] failed: %d\n",
997 p_egalax_i2c_dev->interrupt_gpio, result);
998 return -EINVAL;
999 }
1000 gpio_direction_input(p_egalax_i2c_dev->interrupt_gpio);
1001 client->irq = gpio_to_irq(p_egalax_i2c_dev->interrupt_gpio);
1002
1003 if (!gpio_is_valid(p_egalax_i2c_dev->reset_gpio)) {
1004 EGALAX_DBG(DBG_MODULE, " gpio[%d] is not valid\n",
1005 p_egalax_i2c_dev->reset_gpio);
1006 return -EINVAL;
1007 }
1008 result = gpio_request(p_egalax_i2c_dev->reset_gpio, "rest-gpio");
1009 if (result < 0) {
1010 EGALAX_DBG(DBG_MODULE, " gpio_request[%d] failed: %d\n",
1011 p_egalax_i2c_dev->reset_gpio, result);
1012 return -EINVAL;
1013 }
1014
1015 return result;
1016}
1017
1018static SIMPLE_DEV_PM_OPS((egalax_i2c_pm_ops), (egalax_i2c_ops_suspend),
1019 (egalax_i2c_ops_resume));
1020
1021static const struct file_operations egalax_cdev_fops = {
1022 .owner = THIS_MODULE,
1023 .read = egalax_cdev_read,
1024 .write = egalax_cdev_write,
1025 .open = egalax_cdev_open,
1026 .release = egalax_cdev_release,
1027 .poll = egalax_cdev_poll,
1028};
1029
1030static struct miscdevice egalax_misc_dev = {
1031 .minor = MISC_DYNAMIC_MINOR,
1032 .name = "touch",
1033 .fops = &egalax_cdev_fops,
1034};
1035
1036static int egalax_i2c_probe(struct i2c_client *client,
1037 const struct i2c_device_id *idp)
1038{
1039 int result;
1040
1041 EGALAX_DBG(DBG_MODULE, " Start probe\n");
1042
1043 p_egalax_i2c_dev = kzalloc(sizeof(struct _egalax_i2c), GFP_KERNEL);
1044 if (!p_egalax_i2c_dev) {
1045 EGALAX_DBG(DBG_MODULE, " Request memory failed\n");
1046 result = -ENOMEM;
1047 goto fail1;
1048 }
1049 p_egalax_i2c_dev->client = client;
1050
1051 result = request_dt(client);
1052 if (result < 0) {
1053 EGALAX_DBG(DBG_MODULE, " Request DT failed\n");
1054 result = -ENODEV;
1055 goto fail1;
1056 }
1057
1058 egalax_power_on();
1059
1060 input_dev = allocate_Input_Dev();
1061 if (input_dev == NULL) {
1062 EGALAX_DBG(DBG_MODULE, " allocate_Input_Dev failed\n");
1063 result = -EINVAL;
1064 goto fail2;
1065 }
1066 EGALAX_DBG(DBG_MODULE, " Register input device done\n");
1067
1068 mutex_init(&p_egalax_i2c_dev->mutex_wq);
1069
1070 p_egalax_i2c_dev->ktouch_wq =
1071 create_singlethread_workqueue("egalax_touch_wq");
1072 INIT_WORK(&p_egalax_i2c_dev->work_irq, egalax_i2c_wq_irq);
1073
1074 i2c_set_clientdata(client, p_egalax_i2c_dev);
1075
1076 if (gpio_get_value(p_egalax_i2c_dev->interrupt_gpio))
1077 p_egalax_i2c_dev->skip_packet = 0;
1078 else
1079 p_egalax_i2c_dev->skip_packet = 1;
1080
1081 p_egalax_i2c_dev->work_state = MODE_WORKING;
1082
1083 result = request_irq(client->irq, egalax_i2c_interrupt,
1084 IRQF_TRIGGER_LOW, client->name, p_egalax_i2c_dev);
1085 if (result) {
1086 EGALAX_DBG(DBG_MODULE, " Request irq(%d) failed\n",
1087 client->irq);
1088 goto fail3;
1089 }
1090 EGALAX_DBG(DBG_MODULE, " Request irq(%d) gpio(%d) with result:%d\n",
1091 client->irq, p_egalax_i2c_dev->interrupt_gpio, result);
1092
1093 result = misc_register(&egalax_misc_dev);
1094 if (result) {
1095 EGALAX_DBG(DBG_MODULE, " misc device register failed\n");
1096 goto fail4;
1097 }
1098 result = sysfs_create_group(&egalax_misc_dev.this_device->kobj,
1099 &egalax_attr_group);
1100 if (result) {
1101 EGALAX_DBG(DBG_MODULE,
1102 " Failed to create sysfs attributes:%d\n", result);
1103 goto fail4;
1104 }
1105
1106 init_waitqueue_head(&p_egalax_i2c_dev->sysfs_query_queue);
1107 p_egalax_i2c_dev->sysfs_query_wait = false;
1108 p_egalax_i2c_dev->sysfs_hook_cmd[0] = 0xFF;
1109 p_egalax_i2c_dev->sysfs_hook_cmd[1] = 0xFF;
1110 p_egalax_i2c_dev->sysfs_hook_cmd[2] = 0xFF;
1111
1112 EGALAX_DBG(DBG_MODULE, " I2C probe done\n");
1113 return 0;
1114
1115fail4:
1116 free_irq(client->irq, p_egalax_i2c_dev);
1117fail3:
1118 i2c_set_clientdata(client, NULL);
1119 destroy_workqueue(p_egalax_i2c_dev->ktouch_wq);
1120 input_unregister_device(input_dev);
1121 input_dev = NULL;
1122fail2:
1123 gpio_free(p_egalax_i2c_dev->interrupt_gpio);
1124fail1:
1125 kfree(p_egalax_i2c_dev);
1126 p_egalax_i2c_dev = NULL;
1127
1128 EGALAX_DBG(DBG_MODULE, " I2C probe failed\n");
1129 return result;
1130}
1131
1132static int egalax_i2c_remove(struct i2c_client *client)
1133{
1134 struct _egalax_i2c *egalax_i2c = i2c_get_clientdata(client);
1135
1136 egalax_i2c->work_state = MODE_STOP;
1137
1138 cancel_work_sync(&egalax_i2c->work_irq);
1139
1140 if (client->irq) {
1141 disable_irq(client->irq);
1142 free_irq(client->irq, egalax_i2c);
1143 }
1144
1145 gpio_free(egalax_i2c->interrupt_gpio);
1146 gpio_free(egalax_i2c->reset_gpio);
1147
1148 if (egalax_i2c->ktouch_wq)
1149 destroy_workqueue(egalax_i2c->ktouch_wq);
1150
1151 if (input_dev) {
1152 EGALAX_DBG(DBG_MODULE, " Unregister input device\n");
1153 input_unregister_device(input_dev);
1154 input_dev = NULL;
1155 }
1156
1157 sysfs_remove_group(&client->dev.kobj, &egalax_attr_group);
1158
1159 i2c_set_clientdata(client, NULL);
1160 kfree(egalax_i2c);
1161 p_egalax_i2c_dev = NULL;
1162
1163 return 0;
1164}
1165
1166static const struct i2c_device_id egalax_i2c_idtable[] = {
1167 { "egalax_i2c", 0 },
1168 { }
1169};
1170
1171static const struct of_device_id egalax_i2c_dt_ids[] = {
1172 { .compatible = "eeti,exc80_ts" },
1173 { }
1174};
1175
1176MODULE_DEVICE_TABLE(i2c, egalax_i2c_idtable);
1177
1178static struct i2c_driver egalax_i2c_driver = {
1179 .driver = {
1180 .name = "egalax_i2c",
1181 .owner = THIS_MODULE,
1182 .of_match_table = egalax_i2c_dt_ids,
1183 .pm = &egalax_i2c_pm_ops,
1184 },
1185 .id_table = egalax_i2c_idtable,
1186 .probe = egalax_i2c_probe,
1187 .remove = egalax_i2c_remove,
1188};
1189
1190static const struct file_operations egalax_proc_fops = {
1191 .owner = THIS_MODULE,
1192 .open = egalax_proc_open,
1193 .read = seq_read,
1194 .write = egalax_proc_write,
1195 .llseek = seq_lseek,
1196 .release = single_release,
1197};
1198
1199static void egalax_i2c_ts_exit(void)
1200{
1201 if (p_char_dev) {
1202 kfree(p_char_dev->pFiFoBuf);
1203 kfree(p_char_dev);
1204 p_char_dev = NULL;
1205 }
1206
1207 misc_deregister(&egalax_misc_dev);
1208
1209 i2c_del_driver(&egalax_i2c_driver);
1210
1211 remove_proc_entry(PROC_FS_NAME, NULL);
1212
1213 EGALAX_DBG(DBG_MODULE, " Exit driver done!\n");
1214}
1215
1216static struct egalax_char_dev *setup_chardev(void)
1217{
1218 struct egalax_char_dev *pCharDev;
1219
1220 pCharDev = kzalloc(1*sizeof(struct egalax_char_dev), GFP_KERNEL);
1221 if (!pCharDev)
1222 goto fail_cdev;
1223
1224 spin_lock_init(&pCharDev->FiFoLock);
1225 pCharDev->pFiFoBuf = kzalloc(sizeof(unsigned char)*FIFO_SIZE,
1226 GFP_KERNEL);
1227 if (!pCharDev->pFiFoBuf)
1228 goto fail_fifobuf;
1229
1230 kfifo_init(&pCharDev->DataKFiFo, pCharDev->pFiFoBuf, FIFO_SIZE);
1231 if (!kfifo_initialized(&pCharDev->DataKFiFo))
1232 goto fail_kfifo;
1233
1234 pCharDev->OpenCnts = 0;
1235 sema_init(&pCharDev->sem, 1);
1236 init_waitqueue_head(&pCharDev->fifo_inq);
1237
1238 return pCharDev;
1239
1240fail_kfifo:
1241 kfree(pCharDev->pFiFoBuf);
1242fail_fifobuf:
1243 kfree(pCharDev);
1244fail_cdev:
1245 return NULL;
1246}
1247
1248static int egalax_i2c_ts_init(void)
1249{
1250 int result;
1251
1252 p_egalax_i2c_dev = NULL;
1253 p_char_dev = NULL;
1254 input_dev = NULL;
1255 TotalPtsCnt = 0;
1256 RecvPtsCnt = 0;
1257
1258 p_char_dev = setup_chardev();
1259 if (!p_char_dev) {
1260 result = -ENOMEM;
1261 goto fail;
1262 }
1263
1264 dbgProcFile = proc_create(PROC_FS_NAME, 0660, NULL,
1265 &egalax_proc_fops);
1266 if (dbgProcFile == NULL) {
1267 remove_proc_entry(PROC_FS_NAME, NULL);
1268 EGALAX_DBG(DBG_MODULE, " Could not initialize /proc/%s\n",
1269 PROC_FS_NAME);
1270 }
1271
1272 EGALAX_DBG(DBG_MODULE, " Driver init done!\n");
1273 return i2c_add_driver(&egalax_i2c_driver);
1274
1275fail:
1276 egalax_i2c_ts_exit();
1277 return result;
1278}
1279
1280module_init(egalax_i2c_ts_init);
1281module_exit(egalax_i2c_ts_exit);
1282
1283MODULE_AUTHOR("EETI <touch_fae@eeti.com>");
1284MODULE_DESCRIPTION("egalax all points controller i2c driver");
1285MODULE_LICENSE("GPL");