/*
*
* Touch Screen USB Driver for EETI Controller
*
* Copyright (C) 2000-2018 eGalax_eMPIA Technology Inc. All rights reserved.
* Copyright (c) 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/04/27"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
#include <linux/uaccess.h>
#include <linux/kfifo.h>
#include <linux/version.h>
#include <linux/input.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/platform_device.h>
#include <linux/of_gpio.h>
#include <linux/regulator/consumer.h>
#define EETI_USB_DEVICE_ID 0x0EEF
#define EETI_USB_PRODUCT_ID 0xCC01
#define EETI_USB_BL_PRODUCT_ID 0x79FD
#define MAX_EVENTS 600
#define MAX_USB_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
struct tag_mt_contacts {
unsigned char id;
signed char status;
unsigned short x;
unsigned short y;
unsigned short z;
};
struct _egalax_usb {
unsigned char *data;
dma_addr_t data_dma;
unsigned char *buffer;
int buf_len;
struct urb *irq;
struct usb_device *udev;
struct usb_interface *interface;
unsigned char work_state;
unsigned char down_cnt;
char phys[128];
wait_queue_head_t sysfs_query_queue;
bool sysfs_query_wait;
unsigned char sysfs_hook_cmd[3];
unsigned char sysfs_cmd_result[MAX_USB_LEN];
};
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_usb *p_egalax_usb_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 char fifo_read_buf[MAX_USB_LEN];
static int total_pts_cnt, recv_pts_cnt;
static bool misc_registered;
static bool sysfs_created;
/* DT for platform */
int g_reset_gpio;
bool g_enable_high;
struct regulator *g_regulator_hv;
struct regulator *g_regulator_5v0;
struct regulator *g_regulator_3v3;
struct regulator *g_regulator_1v8;
bool g_flip_x;
bool g_flip_y;
#define DBG_MODULE 0x00000001U
#define DBG_CDEV 0x00000002U
#define DBG_PROC 0x00000004U
#define DBG_POINT 0x00000008U
#define DBG_INT 0x00000010U
#define DBG_USB 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 *p_dbg_proc_file;
#define EGALAX_DBG(level, fmt, args...) \
do { if ((level & dbg_level) > 0U) { \
pr_debug("egalax_usb: " fmt, ## args); } \
} while (false)
#define EETI_HID_SET_REPORT_VALUE 0x203
static int send_usb_data(struct _egalax_usb *egalax_usb, unsigned char *buf,
int len)
{
int ret;
struct usb_interface *intf = egalax_usb->interface;
ret = usb_control_msg(egalax_usb->udev,
usb_sndctrlpipe(egalax_usb->udev, 0),
HID_REQ_SET_REPORT,
USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
EETI_HID_SET_REPORT_VALUE,
intf->cur_altsetting->desc.bInterfaceNumber,
buf, len, USB_CTRL_SET_TIMEOUT);
if (ret < 0) {
EGALAX_DBG(DBG_MODULE,
"Can't send data to device with err:%d\n", ret);
}
return ret;
}
static void run_fw_init(struct _egalax_usb *egalax_usb)
{
unsigned char *buf;
char retry = 3, ret = 0;
buf = kzalloc(3, GFP_NOIO);
if (buf == NULL) {
EGALAX_DBG(DBG_MODULE, " Can't alloc buffer to do FW init\n");
return;
}
while (retry--) {
buf[0] = 0x05; buf[1] = 0x02; buf[2] = 0
|