天秤惡魔
unread,Aug 7, 2011, 10:43:40 AM8/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android-x86
This driver works fine on Intel OakTrail Android-x86 2.3.
Add
kernel/arch/x86/configs
CONFIG_HID_ILITEK=y
Put hid-ilitek.c in /kernel/drivers/hid sorce code as fellow.
Add
obj-$(CONFIG_HID_ILITEK) += hid-ilitek.o
in /kernel/drivers/hid/Makefile
Add
config HID_ILITEK
tristate "ILITEK2105 dual touch panel"
depends on USB_HID
---help---
Support for ILITEK 2105 dual touch panel.
in /kernel/drivers/hid/Kconfig
/*
* 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.
*/
hid-ilitek.c
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <linux/proc_fs.h>
#include <linux/usb.h>
#include "usbhid/usbhid.h"
#include "hid-ids.h"
MODULE_DESCRIPTION("ILITEK dual-touch panel driver");
MODULE_LICENSE("GPL");
struct ilitek_data {
__u16 x, y, z;
__u8 id;
__s8 oldest; /* id of the oldest finger in previous
frame */
bool valid; /* valid finger data, or just
placeholder? */
bool first; /* is this the first finger in this
frame? */
__s8 firstid; /* id of the first finger in the frame
*/
__u16 firstx, firsty; /* (x, y) of the first finger in the
frame */
};
static int ilitek_input_mapping(struct hid_device *hdev, struct
hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
switch (usage->hid & HID_USAGE_PAGE) {
case HID_UP_GENDESK:
switch (usage->hid) {
case HID_GD_X:
hid_map_usage(hi, usage, bit, max,
EV_ABS, ABS_MT_POSITION_X);
input_set_abs_params(hi->input,
ABS_MT_POSITION_X,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
/* touchscreen emulation */
input_set_abs_params(hi->input, ABS_X,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
return 1;
case HID_GD_Y:
hid_map_usage(hi, usage, bit, max,
EV_ABS, ABS_MT_POSITION_Y);
input_set_abs_params(hi->input,
ABS_MT_POSITION_Y,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
/* touchscreen emulation */
input_set_abs_params(hi->input, ABS_Y,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
return 1;
}
return 0;
case HID_UP_DIGITIZER:
switch (usage->hid) {
case HID_DG_TIPSWITCH:
/* touchscreen emulation */
hid_map_usage(hi, usage, bit, max, EV_KEY,
BTN_TOUCH);
input_set_capability(hi->input, EV_KEY,
BTN_TOUCH);
return 1;
case HID_DG_INRANGE:
case HID_DG_CONFIDENCE:
case HID_DG_CONTACTMAX:
case HID_DG_CONTACTCOUNT:
return -1;
case HID_DG_CONTACTID:
hid_map_usage(hi, usage, bit, max,
EV_ABS, ABS_MT_TRACKING_ID);
return 1;
case HID_DG_TIPPRESSURE:
hid_map_usage(hi, usage, bit, max,
EV_ABS, ABS_MT_PRESSURE);
input_set_abs_params(hi->input,
ABS_MT_PRESSURE,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
/* touchscreen emulation */
input_set_abs_params(hi->input, ABS_PRESSURE,
field-
>logical_minimum,
field-
>logical_maximum, 0, 0);
return 1;
}
return 0;
}
return 0;
}
static int ilitek_input_mapped(struct hid_device *hdev, struct
hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
if (usage->type == EV_KEY || usage->type == EV_ABS)
clear_bit(usage->code, *bit);
return 0;
}
/*
* this function is called when a whole finger has been parsed,
* so that it can decide what to send to the input layer.
*/
static void ilitek_filter_event(struct ilitek_data *td,
struct input_dev *input)
{
td->first = !td->first; /* touchscreen emulation */
if (!td->valid) {
/*
* touchscreen emulation: if this is the second finger
and
* the first was valid, the first was the oldest; if
the
* first was not valid and there was a valid finger in
the
* previous frame, this is a release.
*/
if (td->first) {
td->firstid = -1;
} else if (td->firstid >= 0) {
input_event(input, EV_ABS, ABS_X, td->firstx);
input_event(input, EV_ABS, ABS_Y, td->firsty);
input_event(input, EV_ABS, ABS_PRESSURE, td-
>z);
td->oldest = td->firstid;
} else if (td->oldest >= 0) {
input_event(input, EV_KEY, BTN_TOUCH, 0);
td->oldest = -1;
}
return;
}
input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
input_event(input, EV_ABS, ABS_MT_PRESSURE, td->z);
input_mt_sync(input);
/*
* touchscreen emulation: if there was no touching finger
previously,
* emit touch event
*/
if (td->oldest < 0) {
input_event(input, EV_KEY, BTN_TOUCH, 1);
td->oldest = td->id;
}
/*
* touchscreen emulation: if this is the first finger, wait
for the
* second; the oldest is then the second if it was the oldest
already
* or if there was no first, the first otherwise.
*/
if (td->first) {
td->firstx = td->x;
td->firsty = td->y;
td->firstid = td->id;
} else {
int x, y, oldest;
if (td->id == td->oldest || td->firstid < 0) {
x = td->x;
y = td->y;
oldest = td->id;
} else {
x = td->firstx;
y = td->firsty;
oldest = td->firstid;
}
input_event(input, EV_ABS, ABS_X, x);
input_event(input, EV_ABS, ABS_Y, y);
td->oldest = oldest;
}
}
static int ilitek_event(struct hid_device *hid, struct hid_field
*field,
struct hid_usage *usage, __s32 value)
{
struct ilitek_data *sd = hid_get_drvdata(hid);
if (hid->claimed & HID_CLAIMED_INPUT) {
struct input_dev *input = field->hidinput->input;
switch (usage->hid) {
case HID_DG_INRANGE:
break;
case HID_GD_X:
sd->x = value;
break;
case HID_GD_Y:
sd->y = value;
ilitek_filter_event(sd, input);
break;
case HID_DG_CONTACTID:
sd->id = value;
break;
case HID_DG_CONFIDENCE:
break;
case HID_DG_TIPSWITCH:
sd->valid = value;
break;
case HID_DG_TIPPRESSURE:
sd->z = value;
break;
default:
/* fallback to the generic hidinput handling
*/
return 0;
}
}
/* we have handled the hidinput part, now remains hiddev */
if (hid->claimed & HID_CLAIMED_HIDDEV && hid-
>hiddev_hid_event)
hid->hiddev_hid_event(hid, field, usage, value);
return 1;
}
static int ilitek_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
int ret;
struct ilitek_data *sd;
struct hid_report *report;
sd = kmalloc(sizeof(struct ilitek_data), GFP_KERNEL);
if (!sd) {
dev_err(&hdev->dev, "cannot allocate Stantum data\n");
return -ENOMEM;
}
hid_set_drvdata(hdev, sd);
sd->first = false;
sd->oldest = -1;
sd->valid = false;
ret = hid_parse(hdev);
if (!ret)
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
report= hdev-
>report_enum[HID_FEATURE_REPORT].report_id_hash[5];
if(report){
report->field[0]->value[0]=2;
usbhid_submit_report(hdev,report,USB_DIR_OUT);
}
if (ret)
kfree(sd);
return ret;
}
static void ilitek_remove(struct hid_device *hdev)
{
hid_hw_stop(hdev);
kfree(hid_get_drvdata(hdev));
hid_set_drvdata(hdev, NULL);
}
static const struct hid_device_id ilitek_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK,
USB_DEVICE_ID_ILITEK_MT) },
{ }
};
MODULE_DEVICE_TABLE(hid, ilitek_devices);
static const struct hid_usage_id ilitek_grabbed_usages[] = {
{ 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 ilitek_driver = {
.name = "ilitek",
.id_table = ilitek_devices,
.probe = ilitek_probe,
.remove = ilitek_remove,
.input_mapping = ilitek_input_mapping,
.input_mapped = ilitek_input_mapped,
.usage_table = ilitek_grabbed_usages,
.event = ilitek_event,
};
static int __init ilitek_init(void)
{
return hid_register_driver(&ilitek_driver);
}
static void __exit ilitek_exit(void)
{
hid_unregister_driver(&ilitek_driver);
}
module_init(ilitek_init);
module_exit(ilitek_exit);