hid: Panasonic UB-T780 and UB-T880 driver
PATCH 1/1 hid: Panasonic UB-T780 and UB-T880 driver
From: Anton Chikin <[email protected]>
Panasonic Elite Panaboard UB-T* hid driver.
Removed all unnesessary comments and debug stuff. Multitouch now uses Protocol B. Still parsing by hands because of incompatible report descriptor in UB-T780.
--- drivers/hid/Kconfig | 6 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 5 + drivers/hid/hid-ubt880.c | 381 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/hid/hid-ubt880.h | 81 ++++++++++ 5 files changed, 474 insertions(+), 0 deletions(-) create mode 100644 drivers/hid/hid-ubt880.c create mode 100644 drivers/hid/hid-ubt880.h
drivers/hid/Kconfig +6 -0
@@ -324,6 +324,12 @@ config HID_ORTEK ---help--- Support for Ortek WKB-2000 wireless keyboard + mouse trackpad. +config HID_PANASONIC + tristate "Panasonic Elite Panaboards" + depends on USB_HID + ---help--- + Support for Panasonic Elite Panaboard UB-T780 and UB-T880. + config HID_PANTHERLORD tristate "Pantherlord/GreenAsia game controller" depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -73,6 +73,7 @@ obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o obj-$(CONFIG_HID_WACOM) += hid-wacom.o obj-$(CONFIG_HID_WALTOP) += hid-waltop.o +obj-$(CONFIG_HID_PANASONIC) += hid-ubt880.o obj-$(CONFIG_USB_HID) += usbhid/ obj-$(CONFIG_USB_MOUSE) += usbhid/
drivers/hid/hid-ids.h +5 -0
@@ -468,6 +468,11 @@#define USB_VENDOR_ID_ORTEK 0x05a4#define USB_DEVICE_ID_ORTEK_WKB2000 0x2000 +#define USB_VENDOR_ID_PANASONIC 0x04da +#define USB_DEVICE_ID_PANABOARD_780 0x1044 +#define USB_DEVICE_ID_PANABOARD_880 0x104d +#define USB_DEVICE_ID_PANABOARD_880_PEN 0x104e +#define USB_VENDOR_ID_PANJIT 0x134c#define USB_VENDOR_ID_PANTHERLORD 0x0810
drivers/hid/hid-ubt880.c new file +381 -0
381 lines not on this page · raw message
drivers/hid/hid-ubt880.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
1.7.1
Hi Anton,
Quoted 4 lines
Panasonic Elite Panaboard UB-T* hid driver.
Removed all unnesessary comments and debug stuff. Multitouch now uses Protocol B. Still parsing by hands because of incompatible report descriptor in UB-T780.
---
Please keep the original commit message above the "---", and add comments about changes etc below it.
Quoted 5 lines
drivers/hid/Kconfig +0
-0
drivers/hid/Kconfig config HID_ORTEK · line 332
Quoted 9 lines
drivers/hid/Kconfig +6
-0@@ -324,6 +324,12 @@ config HID_ORTEK ---help--- Support for Ortek WKB-2000 wireless keyboard + mouse trackpad. +config HID_PANASONIC + tristate "Panasonic Elite Panaboards" + depends on USB_HID + ---help--- + Support for Panasonic Elite Panaboard UB-T780 and UB-T880. +
What is the module called? Please add to the text.
drivers/hid/Makefile obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o · line 79
Quoted 12 lines
drivers/hid/Makefile +1
-0@@ -73,6 +73,7 @@ obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o obj-$(CONFIG_HID_WACOM) += hid-wacom.o obj-$(CONFIG_HID_WALTOP) += hid-waltop.o +obj-$(CONFIG_HID_PANASONIC) += hid-ubt880.o obj-$(CONFIG_USB_HID) += usbhid/ obj-$(CONFIG_USB_MOUSE) += usbhid/
This driver should really be placed in input/touchscreen/ instead, since it seems to not follow the hid standard at all. Perhaps it can even be merged into one of the existing, more generic drivers like usbtouchscreen. Even as a standalone driver, there are plenty of examples to copy from.
Quoted 5 lines
drivers/hid/Makefile +5
-0+#include <linux/device.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/usb.h> +#include <linux/fs.h>
drivers/hid/Makefile
Quoted 10 lines
drivers/hid/Makefile +10
-0+#include <linux/cdev.h> +#include "hid-ids.h" +#include "hid-ubt880.h" +#include "usbhid/usbhid.h" +/*switch_mode : Our device has two modes: mouse mode in which it is acting like mouse, producing + * absolute coordinates [0 - 4095] + * The second mode is digitizer mode, which produce two raw clock measurments from ultrasound + * recievers in the top-left corner of the board. This mode more flexible and also reports batterey + * status of digitizer pen and penID. + */
Please use kernel-style comment format
Quoted 35 lines
drivers/hid/Makefile +35
-0+static int ubt880_switch_mode(struct hid_device *hid, unsigned char mode) +{ + struct hid_report *report = NULL; + struct hid_report *report_cur = NULL; + __s32 *val = NULL; + list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) + { + if (hid->report_enum[HID_FEATURE_REPORT].numbered) + report_cur = report; + } + if (report_cur == NULL) + return -EIO; + + val = report_cur->field[0]->value; + val[0] = mode; + usbhid_submit_report(hid, report_cur, USB_DIR_OUT); + return 0; +} + +static int ubt780_switch_mode(struct hid_device *hid, unsigned char mode) +{ + struct hid_report *report = NULL; + struct hid_report *report_cur = NULL; + __s32 *val = NULL; + list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) + { + if (hid->report_enum[HID_OUTPUT_REPORT].numbered) + report_cur = report; + } + + if (report_cur == NULL) + return -EIO; + + val = report_cur->field[0]->value; + val[0] = 0x7e;
drivers/hid/Makefile
Quoted 10 lines
drivers/hid/Makefile +10
-0+ val[1] = 0x04; + val[2] = 0x4d; + val[3] = mode; + val[4] = 0x00; + val[5] = 0x0a; + val[6] = 0x00; + val[7] = 0x00; + usbhid_submit_report(hid, report_cur, USB_DIR_OUT); + return 0; +}
Please put the common code in the two functions above into a function.
drivers/hid/Makefile
Quoted 5 lines
drivers/hid/Makefile +5
-0+ +/* PenToInt : converts ultrasound clock measurements to screen coordinates.*/ +static bool ubt_pen_to_int(int *pLeft, int *pRight, struct ubt_data *drvdata) +{ + int left2, right2 , n, w_n, sqr, xx, yy;
extra spaces
drivers/hid/Makefile
Quoted 1 line
drivers/hid/Makefile +1
-0+ static int w = 1164;
const static, or define
Quoted 37 lines
drivers/hid/Makefile +37
-0+ + left2 = (*pLeft) * (*pLeft); + right2 = (*pRight) * (*pRight); + + if (left2 == 0 && right2 == 0) { + *pLeft = drvdata->xold; + *pRight = drvdata->yold; + return true; + } + + n = (right2 - left2) / (2 * w); + w_n = w-n; + + sqr = (2 * left2 - (w_n * w_n)); + + if (sqr < 0) + return false; + + xx = (w_n + int_sqrt(sqr)) / 2; + yy = xx + n; + + if (xx < 0 || yy < 0) + return false; + + *pLeft = xx; + *pRight = yy; + drvdata->xold = xx; + drvdata->yold = yy; + + return true; +} + +static void ubt880_set_input(struct input_dev *input) +{ + /* Basics */ + /*We have a key*/ + __set_bit(EV_KEY, input->evbit);
drivers/hid/Makefile
Quoted 10 lines
drivers/hid/Makefile +10
-0+ __set_bit(BTN_LEFT, input->keybit); + __set_bit(BTN_RIGHT, input->keybit); + /*two absolute axis*/ + __set_bit(EV_ABS, input->evbit); + __set_bit(ABS_X, input->absbit); + __set_bit(ABS_Y, input->absbit); + /*two absolute MT axis and tracking IDs*/ + input_set_abs_params(input, ABS_MT_POSITION_X, 0, UBT880_MAX_AXIS_X, 0, 0); + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, UBT880_MAX_AXIS_Y, 0, 0); + input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 3, 0, 0);
ABS_MT_TRACKING id should not be set - please use input_mt_init_slots() instead.
drivers/hid/Makefile
Quoted 3 lines
drivers/hid/Makefile +3
-0+ input_set_abs_params(input, ABS_X, 0, UBT880_MAX_AXIS_X, 0, 0); + input_set_abs_params(input, ABS_Y, 0, UBT880_MAX_AXIS_Y, 0, 0); + input_mt_create_slots(input, NUM_CONTACTS);
Please test against 2.6.38-rc.
Quoted 6 lines
drivers/hid/Makefile +5
-0+} +static void ubt880_report_contact(struct input_dev *input, struct ubt_mt_contact *contact) +{ + /* Contact id's are allways 1..3 so we can determine slot + * without keeping contact data in device data.
drivers/hid/Makefile
Quoted 10 lines
drivers/hid/Makefile +10
-0+ */ + input_mt_slot(input, contact->id - 1); + if (!contact->flags) { + input_report_abs(input, ABS_MT_TRACKING_ID, -1); + } else { + input_report_abs(input, ABS_MT_TRACKING_ID, contact->id); + input_report_abs(input, ABS_MT_POSITION_X, contact->x); + input_report_abs(input, ABS_MT_POSITION_Y, contact->y); + } +}
Please use input_mt_report_slot_state(). See hid/hid-multitouch.c for examples.
drivers/hid/Makefile
Quoted 8 lines
drivers/hid/Makefile +8
-0+static void ubt880_report_mt(struct input_dev *input, struct ubt_mt_contact *pack, int size) +{ + int i = 0; + /* Report MT contacts */ + if (size < 1) + return; + if (!input || !pack) + return;
Either these errors never happen, or they should be properly handled. Errorpaths are as important as the main code path.
drivers/hid/Makefile
Quoted 9 lines
drivers/hid/Makefile +9
-0+ + for (i = 0; i < size; i++) + ubt880_report_contact(input, &pack[i]); + + input_sync(input); + /* Emulate single-touch device. Only first contact is used. */ + /* Note that is already calibrated */ + ubt_report_input(input, pack[0].x, pack[0].y, pack[0].flags & 0x01, 0); +}
Sync before input report... no need to separate device outputs here.
Quoted 49 lines
drivers/hid/Makefile +49
-0+static int ubt880_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size) +{ + struct ubt_data *driver_data = hid_get_drvdata(hdev); + + struct input_dev *input = ubt880_get_input(hdev); + if (!input) + return -1; + + if (!driver_data) + return -1; + /*Save the packet for userspace processing*/ + /*Mouse mode packet*/ + switch (data[0]) { + case 0x01: { + int leftbtn, rightbtn; + struct ubt880_dgtzr *pack = (struct ubt880_dgtzr *)data; + if (driver_data->current_mode == MODE_UKN) + driver_data->current_mode = MODE_MOUSE; + leftbtn = pack->command & 0x01; + rightbtn = (pack->command & 0x02) >> 1; + ubt_report_input(input, pack->data[0], pack->data[1], leftbtn, rightbtn); + if (driver_data->current_mode != MODE_MOUSE) + ubt880_switch_mode(hdev, MODE_MOUSE); + break; + } + case 0x02: { + struct ubt780_dgtzr *pack = (struct ubt780_dgtzr *)data; + if (driver_data->current_mode == MODE_UKN) + driver_data->current_mode = MODE_DGTZR; + + if (driver_data->current_mode == MODE_MOUSE) { + driver_data->switch_mode(hdev, MODE_MOUSE); + } else if (driver_data->current_mode == MODE_DGTZR) { + unsigned short *pCoord = (unsigned short *)(&pack->data[3]); + int X = (int) pCoord[0]; + int Y = (int) pCoord[1]; + int leftBtn = pack->data[2] >> 5 & 0x01; + int rightBtn = pack->data[2] >> 4 & 0x01; + if (ubt_pen_to_int(&X, &Y, driver_data)) + ubt_report_input(input, X, Y, leftBtn, rightBtn); + } + break; + } + case 0x03: { + struct ubt_mt_packet *packet = (struct ubt_mt_packet *)data; + if (driver_data->current_mode == MODE_UKN) + driver_data->current_mode = MODE_MULTITOUCH; + + if (driver_data->current_mode == MODE_MOUSE) {
drivers/hid/Makefile
Quoted 10 lines
drivers/hid/Makefile +10
-0+ driver_data->switch_mode(hdev, MODE_MOUSE); + } else if (driver_data->current_mode == MODE_MULTITOUCH) { + ubt880_report_mt(input, (struct ubt_mt_contact *)&packet->data[1], packet->data[19]); + } + break; + } + } + + return 0; +}
Please replace with an urb completion handler in the new driver.
drivers/hid/Makefile
Quoted 5 lines
drivers/hid/Makefile +5
-0+static struct hid_device_id ubt880_devices[] = { + { HID_USB_DEVICE(0x04da, 0x104d) }, + { HID_USB_DEVICE(0x04da, 0x1044) }, + { } +};
Please use the stated defines.
Thank you.
Henrik