Re: [PATCH v2] input: tablet: pegasus_notetaker: USB PM fixes

2016-07-09 Thread Martin Kepplinger
Am 2016-07-08 um 23:08 schrieb Dmitry Torokhov:
> On Tue, Jun 28, 2016 at 06:17:13PM +0200, Martin Kepplinger wrote:
>> Am 2016-06-23 um 19:18 schrieb Dmitry Torokhov:
>>> Hi Martin,
>>>
>>> On Tue, Jun 14, 2016 at 01:20:15PM +0200, Martin Kepplinger wrote:
>>>>  static int pegasus_reset_resume(struct usb_interface *intf)
>>>>  {
>>>> +  struct pegasus *pegasus = usb_get_intfdata(intf);
>>>> +
>>>> +  if (pegasus->dev->users)
>>>> +  pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE);
>>>> +
>>>>return pegasus_resume(intf);
>>>
>>> Hmm, we need to take input mutex when using pegasus->dev->users, how
>>> about the version below instead?
>>>
>>> Thanks.
>>>
>>
>> Sorry for the delay, give me a few more days to test and confirm this or
>> come up with a final patch.
> 
> Martin, did you have time to try out this version of the patch?
> 
> Thanks!
> 

This patch doesn't seem to work as is. Holidays get in the way, but you
can expect a working patch(set) next week.

   martin

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] input: tablet: pegasus_notetaker: USB PM fixes

2016-06-28 Thread Martin Kepplinger
Am 2016-06-23 um 19:18 schrieb Dmitry Torokhov:
> Hi Martin,
> 
> On Tue, Jun 14, 2016 at 01:20:15PM +0200, Martin Kepplinger wrote:
>>  static int pegasus_reset_resume(struct usb_interface *intf)
>>  {
>> +struct pegasus *pegasus = usb_get_intfdata(intf);
>> +
>> +if (pegasus->dev->users)
>> +pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE);
>> +
>>  return pegasus_resume(intf);
> 
> Hmm, we need to take input mutex when using pegasus->dev->users, how
> about the version below instead?
> 
> Thanks.
> 

Sorry for the delay, give me a few more days to test and confirm this or
come up with a final patch.

thanks
martin
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9] input: tablet: add Pegasus Notetaker tablet driver

2016-06-23 Thread Martin Kepplinger
Am 2016-06-15 um 15:01 schrieb Martin Kepplinger:
> 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.genie-online.de/genie-e-note-2/
> 
> https://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.
> 
> Signed-off-by: Martin Kepplinger <mart...@posteo.de>
> ---
> Hi Dmitry. I append this just in case you want to replace the driver you
> took.
> 

Hi Dmitry,

This finishes up the driver for now. Any objections or advice from your
side?

thanks
  martin

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9] input: tablet: add Pegasus Notetaker tablet driver

2016-06-15 Thread Martin Kepplinger
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.genie-online.de/genie-e-note-2/

https://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.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---
Hi Dmitry. I append this just in case you want to replace the driver you
took.

revision history

v9 USB PM fixes: https://www.spinics.net/lists/linux-input/msg45058.html
v8 set device mode in open(), not probe()
v7 add usb_driver power management
v6 minor cleanup (thanks Dmitry)
v5 fix various bugs (thanks Oliver and Dmitry)
v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 413 +++
 3 files changed, 429 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..0c000d8
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,413 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID0x02
+#define NOTETAKER_SET_CMD  0x80
+#define NOTETAKER_SET_MODE 0xb5
+
+#define NOTETAKER_LED_MOUSE 0x02
+#define PEN_MODE_XY 0x01
+
+#define SPECIA

[PATCH v2] input: tablet: pegasus_notetaker: USB PM fixes

2016-06-14 Thread Martin Kepplinger
 * Fix usb_autopm calls to be balanced
 * In reset_resume() we need to set the device mode
 * In suspend() we must cancel the workqueue's work

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---
Thanks Oliver, I think I got it now.

Dmitry, again, do you want to have a new version of the whole driver
instead of this?


 drivers/input/tablet/pegasus_notetaker.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
index 83aa583..0c000d8 100644
--- a/drivers/input/tablet/pegasus_notetaker.c
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -211,14 +211,9 @@ static int pegasus_open(struct input_dev *dev)
 static void pegasus_close(struct input_dev *dev)
 {
struct pegasus *pegasus = input_get_drvdata(dev);
-   int autopm_error;
 
-   autopm_error = usb_autopm_get_interface(pegasus->intf);
usb_kill_urb(pegasus->irq);
cancel_work_sync(>init);
-
-   if (!autopm_error)
-   usb_autopm_put_interface(pegasus->intf);
 }
 
 static int pegasus_probe(struct usb_interface *intf,
@@ -364,6 +359,7 @@ static int pegasus_suspend(struct usb_interface *intf, 
pm_message_t message)
 
mutex_lock(>dev->mutex);
usb_kill_urb(pegasus->irq);
+   cancel_work_sync(>init);
mutex_unlock(>dev->mutex);
 
return 0;
@@ -384,6 +380,11 @@ static int pegasus_resume(struct usb_interface *intf)
 
 static int pegasus_reset_resume(struct usb_interface *intf)
 {
+   struct pegasus *pegasus = usb_get_intfdata(intf);
+
+   if (pegasus->dev->users)
+   pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE);
+
return pegasus_resume(intf);
 }
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] input: tablet: pegasus_notetaker: USB PM fixes

2016-06-13 Thread Martin Kepplinger
In close() we only need usb_autopm_put_interface(), in reset_resume()
we need to set the device mode, and in suspend(), we must cancel
the workqueue's work.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---
Thanks Oliver for these changes. For me, everything works as before.

Dmitry, do you want a new version of the whole thing instead of this
fix?

thanks
  martin

 drivers/input/tablet/pegasus_notetaker.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
index 83aa583..0c339e7 100644
--- a/drivers/input/tablet/pegasus_notetaker.c
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -211,14 +211,11 @@ static int pegasus_open(struct input_dev *dev)
 static void pegasus_close(struct input_dev *dev)
 {
struct pegasus *pegasus = input_get_drvdata(dev);
-   int autopm_error;
 
-   autopm_error = usb_autopm_get_interface(pegasus->intf);
usb_kill_urb(pegasus->irq);
cancel_work_sync(>init);
 
-   if (!autopm_error)
-   usb_autopm_put_interface(pegasus->intf);
+   usb_autopm_put_interface(pegasus->intf);
 }
 
 static int pegasus_probe(struct usb_interface *intf,
@@ -364,6 +361,7 @@ static int pegasus_suspend(struct usb_interface *intf, 
pm_message_t message)
 
mutex_lock(>dev->mutex);
usb_kill_urb(pegasus->irq);
+   cancel_work_sync(>init);
mutex_unlock(>dev->mutex);
 
return 0;
@@ -384,6 +382,11 @@ static int pegasus_resume(struct usb_interface *intf)
 
 static int pegasus_reset_resume(struct usb_interface *intf)
 {
+   struct pegasus *pegasus = usb_get_intfdata(intf);
+
+   if (pegasus->dev->users)
+   pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE);
+
return pegasus_resume(intf);
 }
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7] input: tablet: add Pegasus Notetaker tablet driver

2016-06-10 Thread Martin Kepplinger
Am 2016-06-09 um 17:00 schrieb Oliver Neukum:
> On Wed, 2016-06-01 at 14:55 +0200, Martin Kepplinger wrote:
> 
>> It's *really* fun to use as an input tablet though! So let's support this
>> for everybody.
> 
> Nice job, but a few issues are left. I'll comment in the code.
> 

Hi Oliver,

Thanks for reviewing again. I'll change PM a little.

   martin

> 
>> +static void pegasus_close(struct input_dev *dev)
>> +{
>> +struct pegasus *pegasus = input_get_drvdata(dev);
>> +int autopm_error;
>> +
>> +autopm_error = usb_autopm_get_interface(pegasus->intf);
> 
> There is no need for this.
> 
>> +usb_kill_urb(pegasus->irq);
>> +cancel_work_sync(>init);
>> +
>> +if (!autopm_error)
>> +usb_autopm_put_interface(pegasus->intf);
>> +}
>> +
>> +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;
>> +
>> +/* Sanity check that the device has an endpoint */
>> +if (intf->altsetting[0].desc.bNumEndpoints < 1) {
>> +dev_err(>dev, "Invalid number of endpoints\n");
>> +return -EINVAL;
>> +}
>> +endpoint = >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->intf = intf;
>> +
>> +pegasus->data = usb_alloc_coherent(dev, endpoint->wMaxPacketSize,
>> +   GFP_KERNEL, >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_dma;
>> +}
>> +
>> +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));
>> +
>> +INIT_WORK(>init, pegasus_init);
>> +
>> +usb_set_intfdata(intf, pegasus);
>> +
>> +input_dev->name = pegasus->name;
>> +input_dev->phys = pegasus->phys;
>> +usb_to_input_id(dev, _dev->id);
>> +input_dev->dev.parent = >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->abs

[PATCH v8] input: tablet: add Pegasus Notetaker tablet driver

2016-06-02 Thread Martin Kepplinger
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.genie-online.de/genie-e-note-2/

https://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.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---

This only includes Dmitry's suggestions to v7. Thanks a lot for your
improvements! Tested again and I'm fine with this.

revision history

v8 set device mode in open(), not probe()
v7 add usb_driver power management
v6 minor cleanup (thanks Dmitry)
v5 fix various bugs (thanks Oliver and Dmitry)
v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 412 +++
 3 files changed, 428 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..83aa583
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,412 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID0x02
+#define NOTETAKER_SET_CMD  0x80
+#define NOTETAKER_SET_MODE 0xb5
+
+#define NOTETAKER_LED_MOUSE 0x02
+#define PEN_MODE_XY 0x01
+
+#define SPECIAL_COMMAND

[PATCH v7] input: tablet: add Pegasus Notetaker tablet driver

2016-06-01 Thread Martin Kepplinger
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.genie-online.de/genie-e-note-2/

https://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.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---

I thought about PM again and I think this is how it's supposed to be, and
how it's done in many other usb input drivers.

I'm running it and don't have any problems. It feels more finished now.

Any objections? thanks!

revision history

v7 add usb_driver power management
v6 minor cleanup (thanks Dmitry)
v5 fix various bugs (thanks Oliver and Dmitry)
v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 412 +++
 3 files changed, 428 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..f403494
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,412 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID0x02
+#define NOTETAKER_SET_CMD  0x80
+#define NOTETAKER_SET_MODE 0xb5
+
+#define NOTETAKER_LED_MOUSE

Re: [PATCH v6] input: tablet: add Pegasus Notetaker tablet driver

2016-05-31 Thread Martin Kepplinger
Am 2016-05-29 um 08:59 schrieb Martin Kepplinger:
> This adds a driver for the Pegasus Notetaker Pen. When connected,
> this uses the Pen as an input tablet.
> 

Please wait for v7, before you consider merging this. thanks!

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5] input: tablet: add Pegasus Notetaker tablet driver

2016-05-28 Thread Martin Kepplinger
Hi Dmitry,

Thanks again for your help! Only one comment below...

Am 2016-05-27 um 23:59 schrieb Dmitry Torokhov:
> Hi Martin,
> 

>> +static void pegasus_parse_packet(struct pegasus *pegasus)
>> +{
>> +unsigned char *data = pegasus->data;
>> +struct input_dev *dev = pegasus->dev;
>> +u16 x, y;
>> +
>> +switch (data[0]) {
>> +case SPECIAL_COMMAND:
>> +/* device button pressed */
>> +if (data[1] == BUTTON_PRESSED)
>> +schedule_work(>init);
>> +
>> +break;
>> +/* xy data */
>> +case BATTERY_LOW:
>> +dev_warn_once(>dev, "Pen battery low\n");
>> +case BATTERY_NO_REPORT:
>> +case BATTERY_GOOD:
>> +x = le16_to_cpup((__le16 *)[2]);
>> +y = le16_to_cpup((__le16 *)[4]);
>> +
>> +/* ignore pen up events */
>> +if (x == 0 && y == 0)
> 
> Why are we ignoring pen-up events? I'd at least send
> EV_KEY/BTN_TOOL_PEN/0 and maybe the rest of BTN* events.

I tried a few things, but I found them not to be useful in our case. To
the contrary, they seem to happen at random (or wrongly) too. They seem
to be there to seperate lines in drawings or whatever, but I'm not sure
exactly when they are valuable.

As an input device I get the best user experience when we ignore them. I
don't want them to break "clicking" or the like.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5] input: tablet: add Pegasus Notetaker tablet driver

2016-05-27 Thread Martin Kepplinger
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.genie-online.de/genie-e-note-2/

https://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.

There's no way to disable the device. When the pen is out of range, we just
don't get any URBs and don't do anything.
Like all other mouses or input tablets, we don't use runtime PM.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---

This is *exactly* v5 again, only with updated commit message third-party
links that broke in the meantime.

Again, all is tested and should apply to any recent tree. If not, please
just complain.

revision history

v5 fix various bugs (thanks Oliver and Dmitry)
v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 361 +++
 3 files changed, 377 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..e211601
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,361 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID0x02
+#define NOTETAKER_SET_CMD

[PATCH v5] input: tablet: add Pegasus Notetaker tablet driver

2016-05-27 Thread Martin Kepplinger
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.

There's no way to disable the device. When the pen is out of range, we just
don't get any URBs and don't do anything.
Like all other mouses or input tablets, we don't use runtime PM.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---

Thanks for reviewing! Dmitry's and Oliver's changes to v4 made it even
smaller now. All is tested again and should apply to any recent tree.
If not, please just complain.

revision history

v5 fix various bugs (thanks Oliver and Dmitry)
v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 361 +++
 3 files changed, 377 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..e211601
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,361 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID   

Re: [PATCH v4] input: tablet: add Pegasus Notetaker tablet driver

2016-05-26 Thread Martin Kepplinger
Am 2016-05-26 um 02:29 schrieb Dmitry Torokhov:
> Hi Martin,
> 
> On Wed, May 25, 2016 at 09:44:34AM +0200, Martin Kepplinger wrote:
>> 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.
>>
>> There's no way to disable the device. When the pen is out of range, we just
>> don't get any URBs and don't do anything.
>> Like all other mouses or input tablets, we don't use runtime PM.
>>
>> Signed-off-by: Martin Kepplinger <mart...@posteo.de>
>> ---
>>
>> Thanks for having a look. Any more suggestions on this?
>>
>> revision history
>> 
>> v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
>> v3 fix reporting low pen battery and add USB list to CC
>> v2 minor cleanup (remove unnecessary variables)
>> v1 initial release
>>

Hi Dmitry,

thanks for the excellent review! All your suggestions seem valuable so
far and I'll prepare a new version for you.

>> +
>> +static int pegasus_open(struct input_dev *dev)
>> +{
>> +struct pegasus *pegasus = input_get_drvdata(dev);
>> +
>> +pegasus->irq->dev = pegasus->usbdev;
> 
> Is this assignment really needed?
> 

If we set URB_NO_TRANSFER_DMA_MAP and use transfer_dma, yes.


thanks again,

  martin
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] input: tablet: add Pegasus Notetaker tablet driver

2016-05-25 Thread Martin Kepplinger
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.

There's no way to disable the device. When the pen is out of range, we just
don't get any URBs and don't do anything.
Like all other mouses or input tablets, we don't use runtime PM.

Signed-off-by: Martin Kepplinger <mart...@posteo.de>
---

Thanks for having a look. Any more suggestions on this?

revision history

v4 use normal work queue instead of a kernel thread (thanks to Oliver Neukum)
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 | 373 +++
 3 files changed, 389 insertions(+)
 create mode 100644 drivers/input/tablet/pegasus_notetaker.c

diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 623bb9e..a2b9f97 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -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
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
index 2e13010..200fc4e 100644
--- a/drivers/input/tablet/Makefile
+++ b/drivers/input/tablet/Makefile
@@ -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
diff --git a/drivers/input/tablet/pegasus_notetaker.c 
b/drivers/input/tablet/pegasus_notetaker.c
new file mode 100644
index 000..b7bf585
--- /dev/null
+++ b/drivers/input/tablet/pegasus_notetaker.c
@@ -0,0 +1,373 @@
+/*
+ * Pegasus Mobile Notetaker Pen input tablet driver
+ *
+ * Copyright (c) 2016 Martin Kepplinger <mart...@posteo.de>
+ */
+
+/*
+ * request packet (control endpoint):
+ * |-|
+ * | Report ID | Nr of bytes | command   |
+ * | (1 byte)  | (1 byte)| (n bytes) |
+ * |-|
+ * | 0x02  | n   |   |
+ * |-|
+ *
+ * data packet after set xy mode command, 0x80 0xb5 0x02 0x01
+ * and pen is in range:
+ *
+ * bytebyte name   value (bits)
+ * 
+ * 0   status  0 1 0 0 0 0 X X
+ * 1   color   0 0 0 0 H 0 S T
+ * 2   X low
+ * 3   X high
+ * 4   Y low
+ * 5   Y high
+ *
+ * X X battery state:
+ * no state reported   0x00
+ * battery low 0x01
+ * battery good0x02
+ *
+ * H   Hovering
+ * S   Switch 1 (pen button)
+ * T   Tip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* USB HID defines */
+#define USB_REQ_GET_REPORT 0x01
+#define USB_REQ_SET_REPORT 0x09
+
+#define USB_VENDOR_ID_PEGASUSTECH  0x0e20
+#define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100  0x0101
+
+/* device specific defines */
+#define NOTETAKER_REPORT_ID0x02
+#define NOTETAKER_SET_CMD  0x80
+#define NOTETAKER_SET_MODE 0xb5
+
+#define NOTETAKER_LED_MOUSE 0x02
+#define PEN_MODE_XY   

Re: [PATCH v3] input: tablet: add Pegasus Notetaker tablet driver

2016-05-23 Thread Martin Kepplinger
Am 2016-05-23 um 15:00 schrieb Oliver Neukum:
> On Mon, 2016-05-23 at 14:43 +0200, Martin Kepplinger wrote:
>> Am 2016-05-23 um 14:26 schrieb Oliver Neukum:
>>> On Mon, 2016-05-23 at 13:39 +0200, Martin Kepplinger wrote:
>>>
>>>> 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.
>>
>>>
>>> 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.
> 
> 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

You're right. I'll definitely change this.

> 
>>> 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

> 
>   Regards
>   Oliver
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] input: tablet: add Pegasus Notetaker tablet driver

2016-05-23 Thread Martin Kepplinger
Am 2016-05-23 um 14:26 schrieb Oliver Neukum:
> On Mon, 2016-05-23 at 13:39 +0200, Martin Kepplinger wrote:
> 
>> 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.

> 
> 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.

> 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

> 
>   Regards
>   Oliver
> 
>> +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 = >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, >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, _dev->id);
>> +input_dev->dev.parent = >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_POINTE