/*
*
* Touch Screen I2C Driver for EETI Controller
*
* Copyright (C) 2000-2017 eGalax_eMPIA Technology Inc. All rights reserved.
* Copyright (c) 2017-2018 NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#define RELEASE_DATE "2018/05/18"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <linux/kfifo.h>
#include <linux/version.h>
#include <linux/input.h>
#include <linux/irq.h>
#include <linux/timer.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/poll.h>
#include <linux/input/mt.h>
#include <linux/of_gpio.h>
#include <linux/regulator/consumer.h>
/* Global define to enable function */
/* #define _SWITCH_XY */
/* #define _CONVERT_Y */
#define MAX_EVENTS 600
#define MAX_I2C_LEN 64U
#define FIFO_SIZE 8192
#define MAX_SUPPORT_POINT 16
#define REPORTID_VENDOR 0x03
#define REPORTID_MTOUCH 0x06
#define MAX_RESOLUTION 4095
#define MAX_Z_RESOLUTION 1023
/* running mode */
#define MODE_STOP 0
#define MODE_WORKING 1
#define MODE_IDLE 2
#define MODE_SUSPEND 3
struct tag_mt_contacts {
unsigned char id;
signed char status;
unsigned short x;
unsigned short y;
unsigned short z;
};
struct _egalax_i2c {
struct workqueue_struct *ktouch_wq;
struct work_struct work_irq;
struct delayed_work delay_work_ioctl;
struct mutex mutex_wq;
struct i2c_client *client;
unsigned char work_state;
bool is_disabled;
unsigned char skip_packet;
unsigned int ioctl_cmd;
int interrupt_gpio;
int reset_gpio;
bool enable_high;
wait_queue_head_t sysfs_query_queue;
bool sysfs_query_wait;
unsigned char sysfs_hook_cmd[3];
unsigned char sysfs_cmd_result[MAX_I2C_LEN];
struct regulator *regulator_hv;
struct regulator *regulator_5v0;
struct regulator *regulator_3v3;
struct regulator *regulator_1v8;
bool flip_x;
bool flip_y;
};
struct egalax_char_dev {
int open_cnts;
struct kfifo data_kfifo;
unsigned char *p_fifo_buf;
spinlock_t fifo_lock;
struct semaphore sem;
wait_queue_head_t fifo_inq;
};
static struct _egalax_i2c *p_egalax_i2c_dev;
static struct egalax_char_dev *p_char_dev;
static atomic_t egalax_char_available = ATOMIC_INIT(1);
static atomic_t wait_command_ack = ATOMIC_INIT(0);
static struct input_dev *input_dev;
static struct tag_mt_contacts p_contact_buf[MAX_SUPPORT_POINT];
static unsigned char input_report_buf[MAX_I2C_LEN+2];
static char fifo_read_buf[MAX_I2C_LEN];
static int total_pts_cnt, recv_pts_cnt;
#define DBG_MODULE 0x00000001U
#define DBG_CDEV 0x00000002U
#define DBG_PROC 0x00000004U
#define DBG_POINT 0x00000008U
#define DBG_INT 0x00000010U
#define DBG_I2C 0x00000020U
#define DBG_SUSP 0x00000040U
#define DBG_INPUT 0x00000080U
#define DBG_CONST 0x00000100U
#define DBG_IDLE 0x00000200U
#define DBG_WAKEUP 0x00000400U
#define DBG_BUTTON 0x00000800U
static unsigned int dbg_level = DBG_MODULE|DBG_SUSP;
#define PROC_FS_NAME "egalax_dbg"
#define PROC_FS_MAX_LEN 8
static struct proc_dir_entry *dbg_proc_file;
#define EGALAX_DBG(level, fmt, args...) \
do { if ((level & dbg_level) > 0U) { \
pr_debug("egalax_i2c: " fmt, ## args); } \
} while (false)
static int egalax_i2c_read(unsigned char *p_buf, unsigned short len)
{
struct i2c_msg xfer;
if (p_buf == NULL)
return -1;
/* Read device data */
xfer.addr = p_egalax_i2c_dev->client->addr;
xfer.flags = I2C_M_RD;
xfer.len = len;
xfer.buf = p_buf;
if (i2c_transfer(p_egalax_i2c_dev->client->adapter, &xfer, 1) != 1) {
EGALAX_DBG(DBG_I2C, " %s: i2c transfer fail\n", __func__);
return -EIO;
}
EGALAX_DBG(DBG_I2C, " %s: i2c transfer success\n", __func__);
return 0;
}
static int egalax_i2c_write(unsigned short reg, unsigned char *p_buf,
|