#include <linux/module.h>
#include <linux/input.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/moduleparam.h>
#include <linux/hid.h>
#include <linux/usb.h>
#include <linux/usb/ch9.h>
#include <linux/cdev.h>
#include "usbhid.h"
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/usb/input.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,8)
#include <linux/input/mt.h>
#endif
#include <linux/hiddev.h>
#include <linux/fs.h>
#define ILITEK_HID_DRIVER_NAME "ilitek_hid"
#define ILITEK_FILE_DRIVER_NAME "ilitek_hid_file"
#define ILITEK_DEBUG_LEVEL KERN_ALERT
#define ILITEK_ERROR_LEVEL KERN_ALERT
#ifndef USB_VENDOR_ID_ILITEK
#define USB_VENDOR_ID_ILITEK 0x222A
#endif
#ifndef USB_DEVICE_ID_ILITEK_MT
#define USB_DEVICE_ID_ILITEK_MT 0x0024
#endif
#define TOUCH_PROTOCOL_B
// i2c command for ilitek touch screen
#define ILITEK_TP_CMD_READ_DATA 0x10
#define ILITEK_TP_CMD_READ_SUB_DATA 0x11
#define ILITEK_TP_CMD_GET_RESOLUTION 0x20
#define ILITEK_TP_CMD_GET_KEY_INFORMATION 0x22
#define ILITEK_TP_CMD_GET_FIRMWARE_VERSION 0x40
#define ILITEK_TP_CMD_GET_PROTOCOL_VERSION 0x42
#define ILITEK_TP_CMD_CALIBRATION 0xCC
#define ILITEK_TP_CMD_CALIBRATION_STATUS 0xCD
#define ILITEK_TP_CMD_ERASE_BACKGROUND 0xCE
// define the application command
#define ILITEK_IOCTL_BASE 100
#define ILITEK_IOCTL_I2C_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 0, unsigned char*)
#define ILITEK_IOCTL_I2C_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 1, int)
#define ILITEK_IOCTL_I2C_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 2, unsigned char*)
#define ILITEK_IOCTL_I2C_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 3, int)
#define ILITEK_IOCTL_USB_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 4, unsigned char*)
#define ILITEK_IOCTL_USB_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 5, int)
#define ILITEK_IOCTL_USB_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 6, unsigned char*)
#define ILITEK_IOCTL_USB_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 7, int)
#define ILITEK_IOCTL_DRIVER_INFORMATION _IOWR(ILITEK_IOCTL_BASE, 8, int)
#define ILITEK_IOCTL_USB_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 9, int)
#define ILITEK_IOCTL_I2C_INT_FLAG _IOWR(ILITEK_IOCTL_BASE, 10, int)
#define ILITEK_IOCTL_I2C_UPDATE _IOWR(ILITEK_IOCTL_BASE, 11, int)
#define ILITEK_IOCTL_STOP_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 12, int)
#define ILITEK_IOCTL_START_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 13, int)
#define ILITEK_IOCTL_GET_INTERFANCE _IOWR(ILITEK_IOCTL_BASE, 14, int)//default setting is usb interface
#define ILITEK_IOCTL_I2C_SWITCH_IRQ _IOWR(ILITEK_IOCTL_BASE, 15, int)
#define ILITEK_IOCTL_UPDATE_FLAG _IOWR(ILITEK_IOCTL_BASE, 16, int)
#define ILITEK_IOCTL_I2C_UPDATE_FW _IOWR(ILITEK_IOCTL_BASE, 18, int)
#define ILITEK_IOCTL_USB_READ_PID _IOWR(ILITEK_IOCTL_BASE, 19, int)
#define DBG(fmt, args...) if (DBG_FLAG)printk("%s(%d): " fmt, __func__,__LINE__, ## args)
//driver information
#define DERVER_VERSION_MAJOR 3
#define DERVER_VERSION_MINOR 3
#define RELEASE_VERSION 0
#define CUSTOMER_ID 0
#define MODULE_ID 0
#define PLATFORM_ID 0
#define PLATFORM_MODULE 0
#define ENGINEER_ID 0
int driver_information[] = {DERVER_VERSION_MAJOR,DERVER_VERSION_MINOR,RELEASE_VERSION,CUSTOMER_ID,MODULE_ID,PLATFORM_ID,PLATFORM_MODULE,ENGINEER_ID};
MODULE_AUTHOR("ilitek");
MODULE_DESCRIPTION("Android driver for ilitek touch screen");
MODULE_LICENSE("GPL");
struct touch_data{
int x, y, z;
int valid;
int id;
};
struct hid_data {
struct input_dev *input_dev;
struct touch_data tp[10];
int max_x;
int max_y;
int valid_input_register;
int valid_hid_register;
int support_hid_device;
int support_touch_point;
struct hid_device *hid_dev;
volatile int disconnect;
int bootloader_mode;
unsigned int pid;
unsigned char firmware_ver[4];
unsigned char protocol_ver[4];
int ch_x;
int ch_y;
struct hid_field *field;
struct hid_report *report;
};
struct dev_data {
dev_t devno;
struct cdev cdev;
struct class *class;
};
struct ilitek_data {
struct hid_data hid;
struct dev_data dev;
};
static struct ilitek_data ilitek;
struct hiddev_list {
struct hiddev_usage_ref buffer[2048];
int head;
int tail;
unsigned flags;
struct fasync_struct *fasync;
struct hiddev *hiddev;
struct list_head node;
struct mutex thread_lock;
};
static void ilitek_input_report(struct input_dev*, struct touch_data*, int);
static int ilitek_register_input_device(struct input_dev**, int, int, int, char*);
static int ilitek_register_hid_device(struct hid_data*);
static int ilitek_init(void);
static void ilitek_exit(void);
static int ilitek_hid_set_report(unsigned char type, unsigned char id, void *buf, int size);
static int hid_input_mapping(struct hid_device*, struct hid_input*, struct hid_field*, struct hid_usage*, unsigned long**, int*);
static int hid_input_mapped(struct hid_device*, struct hid_input*, struct hid_field*, struct hid_usage*, unsigned long**bit, int*);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,8)
static void hid_feature_mapping(struct hid_device *hdev,struct hid_field *field, struct hid_usage *usage);
#endif
static int hid_event(struct hid_device*, struct hid_field*, struct hid_usage*, __s32);
static int hid_probe(struct hid_device*, const struct hid_device_id*);
static void hid_remove(struct hid_device*);
static int ilitek_file_open(struct inode*, struct file*);
static ssize_t ilitek_file_write(struct file*, const char*, size_t, loff_t*);
static int ilitek_file_close(struct inode*, struct file*);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
static long ilitek_file_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#else
static int ilitek_file_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
#endif
struct file_operations ilitek_hid_fops =
{
.write = ilitek_file_write,
.open = ilitek_file_open,
.release = ilitek_file_close,
.unlocked_ioctl = ilitek_file_ioctl,
};
static char DBG_FLAG;
static const struct hid_device_id hid_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MT) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x0006) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x0010) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x0001) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x001C) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x001F) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x0015) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, 0x0041) },
{ }
};
MODULE_DEVICE_TABLE(hid, hid_devices);
static const struct hid_usage_id hid_id[] = {
{ HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
};
static struct hid_driver hid_driver = {
.name = ILITEK_HID_DRIVER_NAME,
.id_table = hid_devices,
.probe = hid_probe,
.remove = hid_remove,
.input_mapping = hid_input_mapping,
.input_mapped = hid_input_mapped,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,8)
.feature_mapping = hid_feature_mapping,
#endif
.usage_table = hid_id,
.event = hid_event,
};
static int
ilitek_hid_set_report(
unsigned char type,
unsigned char id, void *buf, int size)
{
//printk("%s\n",__func__);
return usb_control_msg(hid_to_usb_dev(ilitek.hid.hid_dev),
usb_sndctrlpipe(hid_to_usb_dev(ilitek.hid.hid_dev), 0),
0x09, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (type << 8) + id,
0, buf, size, HZ);
}
static int
ilitek_file_open(
struct inode *inode, struct file *filp)
{
printk(ILITEK_DEBUG_LEVEL "%s\n", __func__);
return 0;
}
static ssize_t
ilitek_file_write(
struct file *filp, const char *buf, size_t count, loff_t *f_pos)
{
uint8_t buffer[128]={0};
int i;
if(count > 128){
return -1;
}
memcpy(buffer, buf, count-1);
if(strcmp(buffer, "calibrate") == 0){
if(ilitek.hid.support_hid_de
ILI2302M驱动 usb接口触摸屏驱动
需积分: 5 7 浏览量
2023-10-30
08:16:14
上传
评论
收藏 7KB RAR 举报
温柔-的-女汉子
- 粉丝: 883
- 资源: 4012