Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
v3.1
  1#include <linux/kernel.h>
  2#include <linux/slab.h>
  3#include <linux/module.h>
  4#include <linux/init.h>
  5#include <linux/usb/input.h>
  6#include <asm/unaligned.h>
  7
  8/*
  9 * Version Information
 10 * v0.0.1 - Original, extremely basic version, 2.4.xx only
 11 * v0.0.2 - Updated, works with 2.5.62 and 2.4.20;
 12 *           - added pressure-threshold modules param code from
 13 *              Alex Perry <alex.perry@ieee.org>
 14 */
 15
 16#define DRIVER_VERSION "v0.0.2"
 17#define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>"
 18#define DRIVER_DESC "USB KB Gear JamStudio Tablet driver"
 19#define DRIVER_LICENSE "GPL"
 20
 21MODULE_AUTHOR(DRIVER_AUTHOR);
 22MODULE_DESCRIPTION(DRIVER_DESC);
 23MODULE_LICENSE(DRIVER_LICENSE);
 24
 25#define USB_VENDOR_ID_KBGEAR	0x084e
 26
 27static int kb_pressure_click = 0x10;
 28module_param(kb_pressure_click, int, 0);
 29MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks");
 30
 31struct kbtab {
 32	unsigned char *data;
 33	dma_addr_t data_dma;
 34	struct input_dev *dev;
 35	struct usb_device *usbdev;
 
 36	struct urb *irq;
 37	char phys[32];
 38};
 39
 40static void kbtab_irq(struct urb *urb)
 41{
 42	struct kbtab *kbtab = urb->context;
 43	unsigned char *data = kbtab->data;
 44	struct input_dev *dev = kbtab->dev;
 45	int pressure;
 46	int retval;
 47
 48	switch (urb->status) {
 49	case 0:
 50		/* success */
 51		break;
 52	case -ECONNRESET:
 53	case -ENOENT:
 54	case -ESHUTDOWN:
 55		/* this urb is terminated, clean up */
 56		dbg("%s - urb shutting down with status: %d", __func__, urb->status);
 
 
 57		return;
 58	default:
 59		dbg("%s - nonzero urb status received: %d", __func__, urb->status);
 
 
 60		goto exit;
 61	}
 62
 63
 64	input_report_key(dev, BTN_TOOL_PEN, 1);
 65
 66	input_report_abs(dev, ABS_X, get_unaligned_le16(&data[1]));
 67	input_report_abs(dev, ABS_Y, get_unaligned_le16(&data[3]));
 68
 69	/*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
 70	input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
 71
 72	pressure = data[5];
 73	if (kb_pressure_click == -1)
 74		input_report_abs(dev, ABS_PRESSURE, pressure);
 75	else
 76		input_report_key(dev, BTN_LEFT, pressure > kb_pressure_click ? 1 : 0);
 77
 78	input_sync(dev);
 79
 80 exit:
 81	retval = usb_submit_urb(urb, GFP_ATOMIC);
 82	if (retval)
 83		err("%s - usb_submit_urb failed with result %d",
 84		     __func__, retval);
 
 85}
 86
 87static struct usb_device_id kbtab_ids[] = {
 88	{ USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 },
 89	{ }
 90};
 91
 92MODULE_DEVICE_TABLE(usb, kbtab_ids);
 93
 94static int kbtab_open(struct input_dev *dev)
 95{
 96	struct kbtab *kbtab = input_get_drvdata(dev);
 97
 98	kbtab->irq->dev = kbtab->usbdev;
 99	if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
100		return -EIO;
101
102	return 0;
103}
104
105static void kbtab_close(struct input_dev *dev)
106{
107	struct kbtab *kbtab = input_get_drvdata(dev);
108
109	usb_kill_urb(kbtab->irq);
110}
111
112static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
113{
114	struct usb_device *dev = interface_to_usbdev(intf);
115	struct usb_endpoint_descriptor *endpoint;
116	struct kbtab *kbtab;
117	struct input_dev *input_dev;
118	int error = -ENOMEM;
119
120	kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
121	input_dev = input_allocate_device();
122	if (!kbtab || !input_dev)
123		goto fail1;
124
125	kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma);
126	if (!kbtab->data)
127		goto fail1;
128
129	kbtab->irq = usb_alloc_urb(0, GFP_KERNEL);
130	if (!kbtab->irq)
131		goto fail2;
132
133	kbtab->usbdev = dev;
 
134	kbtab->dev = input_dev;
135
136	usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys));
137	strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys));
138
139	input_dev->name = "KB Gear Tablet";
140	input_dev->phys = kbtab->phys;
141	usb_to_input_id(dev, &input_dev->id);
142	input_dev->dev.parent = &intf->dev;
143
144	input_set_drvdata(input_dev, kbtab);
145
146	input_dev->open = kbtab_open;
147	input_dev->close = kbtab_close;
148
149	input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
150	input_dev->keybit[BIT_WORD(BTN_LEFT)] |=
151		BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
152	input_dev->keybit[BIT_WORD(BTN_DIGI)] |=
153		BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH);
154	input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
155	input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0);
156	input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0);
157
158	endpoint = &intf->cur_altsetting->endpoint[0].desc;
159
160	usb_fill_int_urb(kbtab->irq, dev,
161			 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
162			 kbtab->data, 8,
163			 kbtab_irq, kbtab, endpoint->bInterval);
164	kbtab->irq->transfer_dma = kbtab->data_dma;
165	kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
166
167	error = input_register_device(kbtab->dev);
168	if (error)
169		goto fail3;
170
171	usb_set_intfdata(intf, kbtab);
172
173	return 0;
174
175 fail3:	usb_free_urb(kbtab->irq);
176 fail2:	usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma);
177 fail1:	input_free_device(input_dev);
178	kfree(kbtab);
179	return error;
180}
181
182static void kbtab_disconnect(struct usb_interface *intf)
183{
184	struct kbtab *kbtab = usb_get_intfdata(intf);
185
186	usb_set_intfdata(intf, NULL);
187
188	input_unregister_device(kbtab->dev);
189	usb_free_urb(kbtab->irq);
190	usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma);
191	kfree(kbtab);
192}
193
194static struct usb_driver kbtab_driver = {
195	.name =		"kbtab",
196	.probe =	kbtab_probe,
197	.disconnect =	kbtab_disconnect,
198	.id_table =	kbtab_ids,
199};
200
201static int __init kbtab_init(void)
202{
203	int retval;
204	retval = usb_register(&kbtab_driver);
205	if (retval)
206		goto out;
207	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
208	       DRIVER_DESC "\n");
209out:
210	return retval;
211}
212
213static void __exit kbtab_exit(void)
214{
215	usb_deregister(&kbtab_driver);
216}
217
218module_init(kbtab_init);
219module_exit(kbtab_exit);
v3.5.6
  1#include <linux/kernel.h>
  2#include <linux/slab.h>
  3#include <linux/module.h>
  4#include <linux/init.h>
  5#include <linux/usb/input.h>
  6#include <asm/unaligned.h>
  7
  8/*
  9 * Version Information
 10 * v0.0.1 - Original, extremely basic version, 2.4.xx only
 11 * v0.0.2 - Updated, works with 2.5.62 and 2.4.20;
 12 *           - added pressure-threshold modules param code from
 13 *              Alex Perry <alex.perry@ieee.org>
 14 */
 15
 16#define DRIVER_VERSION "v0.0.2"
 17#define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>"
 18#define DRIVER_DESC "USB KB Gear JamStudio Tablet driver"
 19#define DRIVER_LICENSE "GPL"
 20
 21MODULE_AUTHOR(DRIVER_AUTHOR);
 22MODULE_DESCRIPTION(DRIVER_DESC);
 23MODULE_LICENSE(DRIVER_LICENSE);
 24
 25#define USB_VENDOR_ID_KBGEAR	0x084e
 26
 27static int kb_pressure_click = 0x10;
 28module_param(kb_pressure_click, int, 0);
 29MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks");
 30
 31struct kbtab {
 32	unsigned char *data;
 33	dma_addr_t data_dma;
 34	struct input_dev *dev;
 35	struct usb_device *usbdev;
 36	struct usb_interface *intf;
 37	struct urb *irq;
 38	char phys[32];
 39};
 40
 41static void kbtab_irq(struct urb *urb)
 42{
 43	struct kbtab *kbtab = urb->context;
 44	unsigned char *data = kbtab->data;
 45	struct input_dev *dev = kbtab->dev;
 46	int pressure;
 47	int retval;
 48
 49	switch (urb->status) {
 50	case 0:
 51		/* success */
 52		break;
 53	case -ECONNRESET:
 54	case -ENOENT:
 55	case -ESHUTDOWN:
 56		/* this urb is terminated, clean up */
 57		dev_dbg(&kbtab->intf->dev,
 58			"%s - urb shutting down with status: %d\n",
 59			__func__, urb->status);
 60		return;
 61	default:
 62		dev_dbg(&kbtab->intf->dev,
 63			"%s - nonzero urb status received: %d\n",
 64			__func__, urb->status);
 65		goto exit;
 66	}
 67
 68
 69	input_report_key(dev, BTN_TOOL_PEN, 1);
 70
 71	input_report_abs(dev, ABS_X, get_unaligned_le16(&data[1]));
 72	input_report_abs(dev, ABS_Y, get_unaligned_le16(&data[3]));
 73
 74	/*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
 75	input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
 76
 77	pressure = data[5];
 78	if (kb_pressure_click == -1)
 79		input_report_abs(dev, ABS_PRESSURE, pressure);
 80	else
 81		input_report_key(dev, BTN_LEFT, pressure > kb_pressure_click ? 1 : 0);
 82
 83	input_sync(dev);
 84
 85 exit:
 86	retval = usb_submit_urb(urb, GFP_ATOMIC);
 87	if (retval)
 88		dev_err(&kbtab->intf->dev,
 89			"%s - usb_submit_urb failed with result %d\n",
 90			__func__, retval);
 91}
 92
 93static struct usb_device_id kbtab_ids[] = {
 94	{ USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 },
 95	{ }
 96};
 97
 98MODULE_DEVICE_TABLE(usb, kbtab_ids);
 99
100static int kbtab_open(struct input_dev *dev)
101{
102	struct kbtab *kbtab = input_get_drvdata(dev);
103
104	kbtab->irq->dev = kbtab->usbdev;
105	if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
106		return -EIO;
107
108	return 0;
109}
110
111static void kbtab_close(struct input_dev *dev)
112{
113	struct kbtab *kbtab = input_get_drvdata(dev);
114
115	usb_kill_urb(kbtab->irq);
116}
117
118static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
119{
120	struct usb_device *dev = interface_to_usbdev(intf);
121	struct usb_endpoint_descriptor *endpoint;
122	struct kbtab *kbtab;
123	struct input_dev *input_dev;
124	int error = -ENOMEM;
125
126	kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
127	input_dev = input_allocate_device();
128	if (!kbtab || !input_dev)
129		goto fail1;
130
131	kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma);
132	if (!kbtab->data)
133		goto fail1;
134
135	kbtab->irq = usb_alloc_urb(0, GFP_KERNEL);
136	if (!kbtab->irq)
137		goto fail2;
138
139	kbtab->usbdev = dev;
140	kbtab->intf = intf;
141	kbtab->dev = input_dev;
142
143	usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys));
144	strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys));
145
146	input_dev->name = "KB Gear Tablet";
147	input_dev->phys = kbtab->phys;
148	usb_to_input_id(dev, &input_dev->id);
149	input_dev->dev.parent = &intf->dev;
150
151	input_set_drvdata(input_dev, kbtab);
152
153	input_dev->open = kbtab_open;
154	input_dev->close = kbtab_close;
155
156	input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
157	input_dev->keybit[BIT_WORD(BTN_LEFT)] |=
158		BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
159	input_dev->keybit[BIT_WORD(BTN_DIGI)] |=
160		BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH);
161	input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
162	input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0);
163	input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0);
164
165	endpoint = &intf->cur_altsetting->endpoint[0].desc;
166
167	usb_fill_int_urb(kbtab->irq, dev,
168			 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
169			 kbtab->data, 8,
170			 kbtab_irq, kbtab, endpoint->bInterval);
171	kbtab->irq->transfer_dma = kbtab->data_dma;
172	kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
173
174	error = input_register_device(kbtab->dev);
175	if (error)
176		goto fail3;
177
178	usb_set_intfdata(intf, kbtab);
179
180	return 0;
181
182 fail3:	usb_free_urb(kbtab->irq);
183 fail2:	usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma);
184 fail1:	input_free_device(input_dev);
185	kfree(kbtab);
186	return error;
187}
188
189static void kbtab_disconnect(struct usb_interface *intf)
190{
191	struct kbtab *kbtab = usb_get_intfdata(intf);
192
193	usb_set_intfdata(intf, NULL);
194
195	input_unregister_device(kbtab->dev);
196	usb_free_urb(kbtab->irq);
197	usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma);
198	kfree(kbtab);
199}
200
201static struct usb_driver kbtab_driver = {
202	.name =		"kbtab",
203	.probe =	kbtab_probe,
204	.disconnect =	kbtab_disconnect,
205	.id_table =	kbtab_ids,
206};
207
208module_usb_driver(kbtab_driver);