input: tablet: add Pegasus Notetaker tablet driver
Subsystems (2)
PATCH v3 1/1 input: tablet: add Pegasus Notetaker tablet driver
This adds a driver for the Pegasus Notetaker Pen. When connected, this uses the Pen as an input tablet.
This device was sold in various different brandings, for example
"Pegasus Mobile Notetaker M210",
"Genie e-note The Notetaker",
"Staedtler Digital ballpoint pen 990 01", "IRISnotes Express" or
"NEWLink Digital Note Taker".
Here's an example, so that you know what we are talking about:
http://www.staedtler.com/en/products/ink-writing-instruments/ballpoint-pens/digital-pen-990-01-digital-ballpoint-pen
http://pegatech.blogspot.com/ seems to be a remaining official resource.
This device can also transfer saved (offline recorded handwritten) data and there are userspace programs that do this, see https://launchpad.net/m210
(Well, alternatively there are really fast scanners out there :)
It's *really* fun to use as an input tablet though! So let's support this for everybody.
---
Any advice or objections?
I'm sure this would be used if available like this. It was a quite popular device.
I use it for quite some time and like it a lot. Only a one-line-fix is the diff from v3 to v2, https://www.spinics.net/lists/linux-input/msg44683.html
revision history
================
v3 fix reporting low pen battery and add USB list to CC v2 minor cleanup (remove unnecessary variables) v1 initial release
drivers/input/tablet/Kconfig | 15 ++ drivers/input/tablet/Makefile | 1 + drivers/input/tablet/pegasus_notetaker.c | 400 +++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+) create mode 100644 drivers/input/tablet/pegasus_notetaker.c
drivers/input/tablet/Kconfig +15 -0
@@ -73,6 +73,21 @@ config TABLET_USB_KBTAB To compile this driver as a module, choose M here: the module will be called kbtab. +config TABLET_USB_PEGASUS + tristate "Pegasus Mobile Notetaker Pen input tablet support" + depends on USB_ARCH_HAS_HCD + select USB + help + Say Y here if you want to use the Pegasus Mobile Notetaker, + also known as: + Genie e-note The Notetaker, + Staedtler Digital ballpoint pen 990 01, + IRISnotes Express or + NEWLink Digital Note Taker. + + To compile this driver as a module, choose M here: the + module will be called pegasus_notetaker. + config TABLET_SERIAL_WACOM4 tristate "Wacom protocol 4 serial tablet support" select SERIO
drivers/input/tablet/Makefile +1 -0
@@ -8,4 +8,5 @@ obj-$(CONFIG_TABLET_USB_AIPTEK) += aiptek.o obj-$(CONFIG_TABLET_USB_GTCO) += gtco.o obj-$(CONFIG_TABLET_USB_HANWANG) += hanwang.o obj-$(CONFIG_TABLET_USB_KBTAB) += kbtab.o +obj-$(CONFIG_TABLET_USB_PEGASUS) += pegasus_notetaker.o obj-$(CONFIG_TABLET_SERIAL_WACOM4) += wacom_serial4.o
drivers/input/tablet/pegasus_notetaker.c new file +400 -0
400 lines not on this page · raw message
Signature · 1 line
2.1.4
Quoted 2 lines · Martin Kepplinger
It's *really* fun to use as an input tablet though! So let's support this for everybody.
Hi,
I am afraid there are a few issues.
1. Why the kernel thread?
2. This driver has questionable power management.
Regards
Oliver
Quoted 92 lines
drivers/input/tablet/pegasus_notetaker.c new file +92
-0+static int pegasus_probe (struct usb_interface *intf, +const struct usb_device_id *id) +{ +struct usb_device *dev =interface_to_usbdev (intf); +struct usb_endpoint_descriptor *endpoint; +struct pegasus *pegasus; +struct input_dev *input_dev; +int error; +int pipe, maxp; + +/* we control interface 0 */ +if (intf->cur_altsetting->desc.bInterfaceNumber ==1 ) +return -ENODEV ; + + endpoint = &intf->cur_altsetting->endpoint[0 ].desc; + + pegasus =kzalloc (sizeof (*pegasus),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!pegasus || !input_dev) { + error = -ENOMEM ; + goto err_free_mem; + } + + pegasus->usbdev = dev; + pegasus->dev = input_dev; + + pegasus->data =usb_alloc_coherent (dev, endpoint->wMaxPacketSize, +GFP_KERNEL , &pegasus->data_dma); +if (!pegasus->data) { + error = -ENOMEM ; + goto err_free_mem; + } + + pegasus->irq =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!pegasus->irq) { + error = -ENOMEM ; + goto err_free_mem; + } + + pipe =usb_rcvintpipe (dev, endpoint->bEndpointAddress); + maxp =usb_maxpacket (dev, pipe,usb_pipeout (pipe)); + pegasus->data_len = maxp; + +usb_fill_int_urb (pegasus->irq, dev, pipe, pegasus->data, maxp, + pegasus_irq, pegasus, endpoint->bInterval); + + pegasus->irq->transfer_dma = pegasus->data_dma; + pegasus->irq->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + +if (dev->manufacturer) +strlcpy (pegasus->name, dev->manufacturer, +sizeof (pegasus->name)); + +if (dev->product) { +if (dev->manufacturer) +strlcat (pegasus->name," " ,sizeof (pegasus->name)); +strlcat (pegasus->name, dev->product,sizeof (pegasus->name)); + } + +if (!strlen (pegasus->name)) +snprintf (pegasus->name,sizeof (pegasus->name), +"USB Pegasus Device %04x:%04x" , +le16_to_cpu (dev->descriptor.idVendor), +le16_to_cpu (dev->descriptor.idProduct)); + +usb_make_path (dev, pegasus->phys,sizeof (pegasus->phys)); +strlcat (pegasus->phys,"/input0" ,sizeof (pegasus->phys)); + +usb_set_intfdata (intf, pegasus); + + input_dev->name = pegasus->name; + input_dev->phys = pegasus->phys; +usb_to_input_id (dev, &input_dev->id); + input_dev->dev.parent = &intf->dev; + +input_set_drvdata (input_dev, pegasus); + + input_dev->open = pegasus_open; + input_dev->close = pegasus_close; + +__set_bit (EV_ABS , input_dev->evbit); +__set_bit (EV_KEY , input_dev->evbit); + +__set_bit (ABS_X , input_dev->absbit); +__set_bit (ABS_Y , input_dev->absbit); + +__set_bit (BTN_TOUCH , input_dev->keybit); +__set_bit (BTN_RIGHT , input_dev->keybit); +__set_bit (BTN_TOOL_PEN , input_dev->keybit); + +__set_bit (INPUT_PROP_DIRECT , input_dev->propbit); +__set_bit (INPUT_PROP_POINTER , input_dev->propbit);
drivers/input/tablet/pegasus_notetaker.c line 343
Quoted 10 lines
drivers/input/tablet/pegasus_notetaker.c new file +10
-0+ +input_set_abs_params (input_dev,ABS_X ,-1500 ,1500 ,8 ,0 ); +input_set_abs_params (input_dev,ABS_Y ,1600 ,3000 ,8 ,0 ); + + error =input_register_device (pegasus->dev); +if (error) + goto err_free_dma; + + pegasus_thread =kthread_run (pegasus_threadf, pegasus, +"pegasus_notetaker_thread" );
Why is that needed?
Quoted 57 lines
drivers/input/tablet/pegasus_notetaker.c new file +57
-0+if (IS_ERR (pegasus_thread)) { + error = -ENOMEM ; + goto err_free_dma; + } + +return 0 ; + +err_free_dma: +usb_free_coherent (dev, pegasus->data_len, + pegasus->data, pegasus->data_dma); + +usb_free_urb (pegasus->irq); +err_free_mem: +kfree (pegasus); +usb_set_intfdata (intf,NULL ); + +return error; +} + +static void pegasus_disconnect (struct usb_interface *intf) +{ +struct pegasus *pegasus =usb_get_intfdata (intf); + +input_unregister_device (pegasus->dev); +if (pegasus_thread) { +if (kthread_stop (pegasus_thread) == -EINTR ) +dev_err (&pegasus->usbdev->dev, +"wake_up_proc was never called\n" ); + } + +usb_free_urb (pegasus->irq); +usb_free_coherent (interface_to_usbdev (intf), + pegasus->data_len, pegasus->data, + pegasus->data_dma); +kfree (pegasus); +usb_set_intfdata (intf,NULL ); +} + +static const struct usb_device_id pegasus_ids[] = { + {USB_DEVICE (USB_VENDOR_ID_PEGASUSTECH , +USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100 ) }, + { } +}; +MODULE_DEVICE_TABLE (usb, pegasus_ids); + +static struct usb_driver pegasus_driver = { + .name ="pegasus_notetaker" , + .probe = pegasus_probe, + .disconnect = pegasus_disconnect, + .id_table = pegasus_ids, +}; + +module_usb_driver (pegasus_driver); + +MODULE_AUTHOR ("Martin Kepplinger <[email protected]>" ); +MODULE_DESCRIPTION ("Pegasus Mobile Notetaker Pen tablet driver" ); +MODULE_LICENSE ("GPL" );
Am 2016-05-23 um 14:26 schrieb Oliver Neukum:
Quoted 8 lines · Martin Kepplinger
Quoted 3 lines
It's *really* fun to use as an input tablet though! So let's support this for everybody.
Hi,
I am afraid there are a few issues.
Thanks for having a look, comments below.
Quoted 2 lines
1. Why the kernel thread?
I provide switching to the xy tablet mode by pressing a button during runtime. So usb_control_msg() is called from the thread, not the interrupt routine.
We don't get in the way of any user app. If we leave that functionality out, users may have to un- and replug in the device after using userspace apps that transfer data or the like.
Quoted 1 line
2. This driver has questionable power management.
I think I do it how others do it. Suspend/resume works. Anything specific required here?
thanks!
martin
Quoted 100 lines
Regards
OliverQuoted 96 lines
drivers/input/tablet/pegasus_notetaker.c new file +96
-0+static int pegasus_probe (struct usb_interface *intf, +const struct usb_device_id *id) +{ +struct usb_device *dev =interface_to_usbdev (intf); +struct usb_endpoint_descriptor *endpoint; +struct pegasus *pegasus; +struct input_dev *input_dev; +int error; +int pipe, maxp; + +/* we control interface 0 */ +if (intf->cur_altsetting->desc.bInterfaceNumber ==1 ) +return -ENODEV ; + + endpoint = &intf->cur_altsetting->endpoint[0 ].desc; + + pegasus =kzalloc (sizeof (*pegasus),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!pegasus || !input_dev) { + error = -ENOMEM ; + goto err_free_mem; + } + + pegasus->usbdev = dev; + pegasus->dev = input_dev; + + pegasus->data =usb_alloc_coherent (dev, endpoint->wMaxPacketSize, +GFP_KERNEL , &pegasus->data_dma); +if (!pegasus->data) { + error = -ENOMEM ; + goto err_free_mem; + } + + pegasus->irq =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!pegasus->irq) { + error = -ENOMEM ; + goto err_free_mem; + } + + pipe =usb_rcvintpipe (dev, endpoint->bEndpointAddress); + maxp =usb_maxpacket (dev, pipe,usb_pipeout (pipe)); + pegasus->data_len = maxp; + +usb_fill_int_urb (pegasus->irq, dev, pipe, pegasus->data, maxp, + pegasus_irq, pegasus, endpoint->bInterval); + + pegasus->irq->transfer_dma = pegasus->data_dma; + pegasus->irq->transfer_flags |=URB_NO_TRANSFER_DMA_MAP ; + +if (dev->manufacturer) +strlcpy (pegasus->name, dev->manufacturer, +sizeof (pegasus->name)); + +if (dev->product) { +if (dev->manufacturer) +strlcat (pegasus->name," " ,sizeof (pegasus->name)); +strlcat (pegasus->name, dev->product,sizeof (pegasus->name)); + } + +if (!strlen (pegasus->name)) +snprintf (pegasus->name,sizeof (pegasus->name), +"USB Pegasus Device %04x:%04x" , +le16_to_cpu (dev->descriptor.idVendor), +le16_to_cpu (dev->descriptor.idProduct)); + +usb_make_path (dev, pegasus->phys,sizeof (pegasus->phys)); +strlcat (pegasus->phys,"/input0" ,sizeof (pegasus->phys)); + +usb_set_intfdata (intf, pegasus); + + input_dev->name = pegasus->name; + input_dev->phys = pegasus->phys; +usb_to_input_id (dev, &input_dev->id); + input_dev->dev.parent = &intf->dev; + +input_set_drvdata (input_dev, pegasus); + + input_dev->open = pegasus_open; + input_dev->close = pegasus_close; + +__set_bit (EV_ABS , input_dev->evbit); +__set_bit (EV_KEY , input_dev->evbit); + +__set_bit (ABS_X , input_dev->absbit); +__set_bit (ABS_Y , input_dev->absbit); + +__set_bit (BTN_TOUCH , input_dev->keybit); +__set_bit (BTN_RIGHT , input_dev->keybit); +__set_bit (BTN_TOOL_PEN , input_dev->keybit); + +__set_bit (INPUT_PROP_DIRECT , input_dev->propbit); +__set_bit (INPUT_PROP_POINTER , input_dev->propbit); + +input_set_abs_params (input_dev,ABS_X ,-1500 ,1500 ,8 ,0 ); +input_set_abs_params (input_dev,ABS_Y ,1600 ,3000 ,8 ,0 ); +
Quoted 8 lines
drivers/input/tablet/pegasus_notetaker.c line 343
Quoted 6 lines
drivers/input/tablet/pegasus_notetaker.c new file +6
-0+ error =input_register_device (pegasus->dev); +if (error) + goto err_free_dma; + + pegasus_thread =kthread_run (pegasus_threadf, pegasus, +"pegasus_notetaker_thread" );Why is that needed?
See comment above.
Quoted 61 lines
Quoted 58 lines
drivers/input/tablet/pegasus_notetaker.c new file +57
-0+if (IS_ERR (pegasus_thread)) { + error = -ENOMEM ; + goto err_free_dma; + } + +return 0 ; + +err_free_dma: +usb_free_coherent (dev, pegasus->data_len, + pegasus->data, pegasus->data_dma); + +usb_free_urb (pegasus->irq); +err_free_mem: +kfree (pegasus); +usb_set_intfdata (intf,NULL ); + +return error; +} + +static void pegasus_disconnect (struct usb_interface *intf) +{ +struct pegasus *pegasus =usb_get_intfdata (intf); + +input_unregister_device (pegasus->dev); +if (pegasus_thread) { +if (kthread_stop (pegasus_thread) == -EINTR ) +dev_err (&pegasus->usbdev->dev, +"wake_up_proc was never called\n" ); + } + +usb_free_urb (pegasus->irq); +usb_free_coherent (interface_to_usbdev (intf), + pegasus->data_len, pegasus->data, + pegasus->data_dma); +kfree (pegasus); +usb_set_intfdata (intf,NULL ); +} + +static const struct usb_device_id pegasus_ids[] = { + {USB_DEVICE (USB_VENDOR_ID_PEGASUSTECH , +USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100 ) }, + { } +}; +MODULE_DEVICE_TABLE (usb, pegasus_ids); + +static struct usb_driver pegasus_driver = { + .name ="pegasus_notetaker" , + .probe = pegasus_probe, + .disconnect = pegasus_disconnect, + .id_table = pegasus_ids, +}; + +module_usb_driver (pegasus_driver); + +MODULE_AUTHOR ("Martin Kepplinger <[email protected]>" ); +MODULE_DESCRIPTION ("Pegasus Mobile Notetaker Pen tablet driver" ); +MODULE_LICENSE ("GPL" );
Quoted 15 lines · Martin Kepplinger
Am 2016-05-23 um 14:26 schrieb Oliver Neukum:
Quoted 8 lines · Martin Kepplinger
Quoted 3 lines
It's *really* fun to use as an input tablet though! So let's support this for everybody.
Hi,
I am afraid there are a few issues.
Thanks for having a look, comments below.
Quoted 2 lines
1. Why the kernel thread?
Quoted 7 lines
I provide switching to the xy tablet mode by pressing a button during runtime. So
usb_control_msg()is called from the thread, not the interrupt routine.We don't get in the way of any user app. If we leave that functionality out, users may have to un- and replug in the device after using userspace apps that transfer data or the like.
The functionality is OK, but the implementation, though creative, is buggy.
a - multiple devices will fail
b - you have a race condition that will fail to wake the thread
if it is still running when the button is pressed again
Kernel threads are wasteful. Using the normal system work queue might be much easier
Quoted 4 lines
Quoted 1 line
2. This driver has questionable power management.
I think I do it how others do it. Suspend/resume works. Anything specific required here?
Runtime PM is missing.
Regards
Oliver
Am 2016-05-23 um 15:00 schrieb Oliver Neukum:
Quoted 27 lines · Martin Kepplinger
Quoted 15 lines
Am 2016-05-23 um 14:26 schrieb Oliver Neukum:
Quoted 8 lines · Martin Kepplinger
Quoted 3 lines
It's *really* fun to use as an input tablet though! So let's support this for everybody.
Hi,
I am afraid there are a few issues.
Thanks for having a look, comments below.
Quoted 2 lines
1. Why the kernel thread?
Quoted 7 lines
I provide switching to the xy tablet mode by pressing a button during runtime. So
usb_control_msg()is called from the thread, not the interrupt routine.We don't get in the way of any user app. If we leave that functionality out, users may have to un- and replug in the device after using userspace apps that transfer data or the like.
The functionality is OK, but the implementation, though creative, is buggy.
Quoted 6 lines
a - multiple devices will fail
b - you have a race condition that will fail to wake the thread
if it is still running when the button is pressed againKernel threads are wasteful. Using the normal system work queue might be much easier
You're right. I'll definitely change this.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
2. This driver has questionable power management.
I think I do it how others do it. Suspend/resume works. Anything specific required here?
Runtime PM is missing.
There is no way to turn the device off. So like any other mouse or input tablet we don't use runtime PM.
In case the Pen is out of range or off, we just don't handle URBs and do nothing.
... but I may miss something, so in this case please get back to me.
thanks
martin
Quoted 5 lines
Regards
Oliver