[PATCH] gspca pac7302: add support for camera button

2010-01-28 Thread Németh Márton
From: Márton Németh 

Add support for snapshot button found on Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
diff -r 875c200a19dc linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c Sun Jan 17 07:58:51 2010 +0100
+++ b/linux/drivers/media/video/gspca/pac7302.c Sun Jan 17 13:47:50 2010 +0100
@@ -5,6 +5,8 @@
  * V4L2 by Jean-Francois Moine 
  *
  * Separated from Pixart PAC7311 library by M�rton N�meth 
+ * Camera button input handling by Márton Németh 
+ * Copyright (C) 2009-2010 Márton Németh 
  *
  * 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
@@ -68,6 +70,7 @@

 #define MODULE_NAME "pac7302"

+#include 
 #include 
 #include "gspca.h"

@@ -1164,6 +1167,37 @@
 }
 #endif

+#ifdef CONFIG_INPUT
+static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
+   u8 *data,   /* interrupt packet data */
+   int len)/* interrput packet length */
+{
+   int ret = -EINVAL;
+   u8 data0, data1;
+
+   if (len == 2) {
+   data0 = data[0];
+   data1 = data[1];
+   if ((data0 == 0x00 && data1 == 0x11) ||
+   (data0 == 0x22 && data1 == 0x33) ||
+   (data0 == 0x44 && data1 == 0x55) ||
+   (data0 == 0x66 && data1 == 0x77) ||
+   (data0 == 0x88 && data1 == 0x99) ||
+   (data0 == 0xaa && data1 == 0xbb) ||
+   (data0 == 0xcc && data1 == 0xdd) ||
+   (data0 == 0xee && data1 == 0xff)) {
+   input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
+   input_sync(gspca_dev->input_dev);
+   input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
+   input_sync(gspca_dev->input_dev);
+   ret = 0;
+   }
+   }
+
+   return ret;
+}
+#endif
+
 /* sub-driver description for pac7302 */
 static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
@@ -1180,6 +1214,9 @@
.set_register = sd_dbg_s_register,
.get_chip_ident = sd_chip_ident,
 #endif
+#ifdef CONFIG_INPUT
+   .int_pkt_scan = sd_int_pkt_scan,
+#endif
 };

 /* -- module initialisation -- */


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


[RFC, PATCH] gspca pac7302: add support for camera button

2009-11-15 Thread Németh Márton
From: Márton Németh 

Add support for snapshot button found on Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
Hi,

this is the first trial to add support for the snapshot button. This
code is working only before the streaming is started. When the streaming
is started the alternate number of the interface 0 is changed and the
interrupt URB is no longer usable. I guess the interrupt URB is to
be reconstructed every time when the alternate number is changed.

When I disconnect the device I get the following error:

uhci_hcd :00:1d.1: dma_pool_free buffer-32, f58ba168/358ba168 (bad dma)

I guess something is wrong in this patch with the cleanup routine.

Regards,

Márton Németh

---
diff -r 09c1284de47d linux/drivers/media/video/gspca/gspca.h
--- a/linux/drivers/media/video/gspca/gspca.h   Sat Nov 14 08:58:12 2009 +0100
+++ b/linux/drivers/media/video/gspca/gspca.h   Sun Nov 15 10:40:54 2009 +0100
@@ -138,6 +138,7 @@
struct module *module;  /* subdriver handling the device */
struct usb_device *dev;
struct file *capt_file; /* file doing video capture */
+   struct input_dev *input_dev;

struct cam cam; /* device information */
const struct sd_desc *sd_desc;  /* subdriver description */
@@ -147,6 +148,7 @@
 #define USB_BUF_SZ 64
__u8 *usb_buf;  /* buffer for USB exchanges */
struct urb *urb[MAX_NURBS];
+   struct urb *int_urb;

__u8 *frbuf;/* buffer for nframes */
struct gspca_frame frame[GSPCA_MAX_FRAMES];
diff -r 09c1284de47d linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c Sat Nov 14 08:58:12 2009 +0100
+++ b/linux/drivers/media/video/gspca/pac7302.c Sun Nov 15 10:40:54 2009 +0100
@@ -68,6 +68,7 @@

 #define MODULE_NAME "pac7302"

+#include 
 #include 
 #include "gspca.h"

@@ -1220,6 +1221,50 @@
 }
 #endif

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
+static void int_irq(struct urb *urb, struct pt_regs *regs)
+#else
+static void int_irq(struct urb *urb)
+#endif
+{
+   struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
+   int ret;
+   int i;
+   __u8 data0, data1;
+
+   printk(KERN_DEBUG "int_irq()\n");
+   printk(KERN_DEBUG "urb->status: %i\n", urb->status);
+   if (urb->status == 0) {
+   printk(KERN_DEBUG "urb->actual_length: %u\n", 
urb->actual_length);
+   for (i = 0; i < urb->actual_length; i++) {
+   printk(KERN_DEBUG "urb->transfer_buffer[%i]=0x%x\n",
+   i, ((__u8*)urb->transfer_buffer)[i]);
+   }
+   if (urb->actual_length == 2) {
+   data0 = ((__u8*)urb->transfer_buffer)[0];
+   data1 = ((__u8*)urb->transfer_buffer)[1];
+   if ((data0 == 0x00 && data1 == 0x11) ||
+   (data0 == 0x22 && data1 == 0x33) ||
+   (data0 == 0x44 && data1 == 0x55) ||
+   (data0 == 0x66 && data1 == 0x77) ||
+   (data0 == 0x88 && data1 == 0x99) ||
+   (data0 == 0xaa && data1 == 0xbb) ||
+   (data0 == 0xcc && data1 == 0xdd) ||
+   (data0 == 0xee && data1 == 0xff)) {
+   input_report_key(gspca_dev->input_dev, 
KEY_CAMERA, 1);
+   input_sync(gspca_dev->input_dev);
+   input_report_key(gspca_dev->input_dev, 
KEY_CAMERA, 0);
+   input_sync(gspca_dev->input_dev);
+   } else
+   printk(KERN_DEBUG "Unknown packet received\n");
+   }
+   ret = usb_submit_urb(urb, GFP_ATOMIC);
+   printk(KERN_DEBUG "resubmit urb: %i\n", ret);
+   }
+
+}
+
+
 /* sub-driver description for pac7302 */
 static struct sd_desc sd_desc = {
.name = MODULE_NAME,
@@ -1254,19 +1299,132 @@
 };
 MODULE_DEVICE_TABLE(usb, device_table);

+static int init_camera_input(struct gspca_dev *gspca_dev, const struct 
usb_device_id *id)
+{
+   struct input_dev *input_dev;
+   int err;
+
+   printk(KERN_DEBUG "allocating input device\n");
+   input_dev = input_allocate_device();
+   if (!input_dev)
+   return -ENOMEM;
+
+   //input_dev->name = "Camera capture button";
+   //input_dev->phys = "camera";
+   input_dev->id.bustype = BUS_USB;
+   input_dev->id.vendor = id->idVendor;
+   input_dev->id.product = id->idProduct;
+   input_dev->id.version = id->bcdDevice_hi;
+   //input_dev->id.version = id->bcdDevice_lo;
+
+   input_dev->evbit[0] = BIT_MASK(EV_KEY);
+   input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
+   //input_dev->dev.parent = ;
+
+   printk(KERN_DEBUG "registering inp

Re: [PATCH] gspca pac7302: add support for camera button

2010-01-28 Thread Németh Márton
Hello Jean-Francois,

thank you for accepting this patch and for the previous suggestions which made 
it possible
to reach the current state of this patchset. Also thanks for correcting the 
character
encoding in my name.

Regards,

Márton Németh

Németh Márton írta:
> From: Márton Németh 
> 
> Add support for snapshot button found on Labtec Webcam 2200.
> 
> Signed-off-by: Márton Németh 
> ---
> diff -r 875c200a19dc linux/drivers/media/video/gspca/pac7302.c
> --- a/linux/drivers/media/video/gspca/pac7302.c   Sun Jan 17 07:58:51 
> 2010 +0100
> +++ b/linux/drivers/media/video/gspca/pac7302.c   Sun Jan 17 13:47:50 
> 2010 +0100
> @@ -5,6 +5,8 @@
>   * V4L2 by Jean-Francois Moine 
>   *
>   * Separated from Pixart PAC7311 library by M�rton N�meth 
> + * Camera button input handling by Márton Németh 
> + * Copyright (C) 2009-2010 Márton Németh 
>   *
>   * 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
> @@ -68,6 +70,7 @@
> 
>  #define MODULE_NAME "pac7302"
> 
> +#include 
>  #include 
>  #include "gspca.h"
> 
> @@ -1164,6 +1167,37 @@
>  }
>  #endif
> 
> +#ifdef CONFIG_INPUT
> +static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
> + u8 *data,   /* interrupt packet data */
> + int len)/* interrput packet length */
> +{
> + int ret = -EINVAL;
> + u8 data0, data1;
> +
> + if (len == 2) {
> + data0 = data[0];
> + data1 = data[1];
> + if ((data0 == 0x00 && data1 == 0x11) ||
> + (data0 == 0x22 && data1 == 0x33) ||
> + (data0 == 0x44 && data1 == 0x55) ||
> + (data0 == 0x66 && data1 == 0x77) ||
> + (data0 == 0x88 && data1 == 0x99) ||
> + (data0 == 0xaa && data1 == 0xbb) ||
> + (data0 == 0xcc && data1 == 0xdd) ||
> + (data0 == 0xee && data1 == 0xff)) {
> + input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
> + input_sync(gspca_dev->input_dev);
> + input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
> + input_sync(gspca_dev->input_dev);
> + ret = 0;
> + }
> + }
> +
> + return ret;
> +}
> +#endif
> +
>  /* sub-driver description for pac7302 */
>  static const struct sd_desc sd_desc = {
>   .name = MODULE_NAME,
> @@ -1180,6 +1214,9 @@
>   .set_register = sd_dbg_s_register,
>   .get_chip_ident = sd_chip_ident,
>  #endif
> +#ifdef CONFIG_INPUT
> + .int_pkt_scan = sd_int_pkt_scan,
> +#endif
>  };
> 
>  /* -- module initialisation -- */
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

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


Re: [RFC, PATCH] gspca pac7302: add support for camera button

2009-11-15 Thread Hans de Goede

Hi,

Thanks for working on this! I think it would be great if we could
get support for camera buttons in general into gspca.

I've not looked closely at your code yet, have you looked at
the camera button code in the gspca sn9c20x.c driver? Also I would really
like to see as much of the button handling code as possible go into
the gspca core. AFAIK many many camera's use an usb interrupt ep for this, so
I would like to see the setting up and cleanup of this interrupt ep be in
the core (as said before see the sn9c20x driver for another driver which
does such things).

Regards,

Hans


On 11/15/2009 09:47 AM, Németh Márton wrote:

From: Márton Németh

Add support for snapshot button found on Labtec Webcam 2200.

Signed-off-by: Márton Németh
---
Hi,

this is the first trial to add support for the snapshot button. This
code is working only before the streaming is started. When the streaming
is started the alternate number of the interface 0 is changed and the
interrupt URB is no longer usable. I guess the interrupt URB is to
be reconstructed every time when the alternate number is changed.

When I disconnect the device I get the following error:

uhci_hcd :00:1d.1: dma_pool_free buffer-32, f58ba168/358ba168 (bad dma)

I guess something is wrong in this patch with the cleanup routine.

Regards,

Márton Németh

---
diff -r 09c1284de47d linux/drivers/media/video/gspca/gspca.h
--- a/linux/drivers/media/video/gspca/gspca.h   Sat Nov 14 08:58:12 2009 +0100
+++ b/linux/drivers/media/video/gspca/gspca.h   Sun Nov 15 10:40:54 2009 +0100
@@ -138,6 +138,7 @@
struct module *module;  /* subdriver handling the device */
struct usb_device *dev;
struct file *capt_file; /* file doing video capture */
+   struct input_dev *input_dev;

struct cam cam; /* device information */
const struct sd_desc *sd_desc;  /* subdriver description */
@@ -147,6 +148,7 @@
  #define USB_BUF_SZ 64
__u8 *usb_buf;  /* buffer for USB exchanges */
struct urb *urb[MAX_NURBS];
+   struct urb *int_urb;

__u8 *frbuf;/* buffer for nframes */
struct gspca_frame frame[GSPCA_MAX_FRAMES];
diff -r 09c1284de47d linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c Sat Nov 14 08:58:12 2009 +0100
+++ b/linux/drivers/media/video/gspca/pac7302.c Sun Nov 15 10:40:54 2009 +0100
@@ -68,6 +68,7 @@

  #define MODULE_NAME "pac7302"

+#include
  #include
  #include "gspca.h"

@@ -1220,6 +1221,50 @@
  }
  #endif

+#if LINUX_VERSION_CODE<  KERNEL_VERSION(2, 6, 19)
+static void int_irq(struct urb *urb, struct pt_regs *regs)
+#else
+static void int_irq(struct urb *urb)
+#endif
+{
+   struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
+   int ret;
+   int i;
+   __u8 data0, data1;
+
+   printk(KERN_DEBUG "int_irq()\n");
+   printk(KERN_DEBUG "urb->status: %i\n", urb->status);
+   if (urb->status == 0) {
+   printk(KERN_DEBUG "urb->actual_length: %u\n", 
urb->actual_length);
+   for (i = 0; i<  urb->actual_length; i++) {
+   printk(KERN_DEBUG "urb->transfer_buffer[%i]=0x%x\n",
+   i, ((__u8*)urb->transfer_buffer)[i]);
+   }
+   if (urb->actual_length == 2) {
+   data0 = ((__u8*)urb->transfer_buffer)[0];
+   data1 = ((__u8*)urb->transfer_buffer)[1];
+   if ((data0 == 0x00&&  data1 == 0x11) ||
+   (data0 == 0x22&&  data1 == 0x33) ||
+   (data0 == 0x44&&  data1 == 0x55) ||
+   (data0 == 0x66&&  data1 == 0x77) ||
+   (data0 == 0x88&&  data1 == 0x99) ||
+   (data0 == 0xaa&&  data1 == 0xbb) ||
+   (data0 == 0xcc&&  data1 == 0xdd) ||
+   (data0 == 0xee&&  data1 == 0xff)) {
+   input_report_key(gspca_dev->input_dev, 
KEY_CAMERA, 1);
+   input_sync(gspca_dev->input_dev);
+   input_report_key(gspca_dev->input_dev, 
KEY_CAMERA, 0);
+   input_sync(gspca_dev->input_dev);
+   } else
+   printk(KERN_DEBUG "Unknown packet received\n");
+   }
+   ret = usb_submit_urb(urb, GFP_ATOMIC);
+   printk(KERN_DEBUG "resubmit urb: %i\n", ret);
+   }
+
+}
+
+
  /* sub-driver description for pac7302 */
  static struct sd_desc sd_desc = {
.name = MODULE_NAME,
@@ -1254,19 +1299,132 @@
  };
  MODULE_DEVICE_TABLE(usb, device_table);

+static int init_camera_input(struct gspca_dev *gspca_dev, const struct 
usb_device_id *id)
+{
+   struct input_dev *input_dev;
+   int err;
+
+   printk(KERN_DEBUG "allocating input

Re: [RFC, PATCH] gspca pac7302: add support for camera button

2009-11-15 Thread Németh Márton
Hi,
Hans de Goede wrote:
> Hi,
> 
> Thanks for working on this! I think it would be great if we could
> get support for camera buttons in general into gspca.
> 
> I've not looked closely at your code yet, have you looked at
> the camera button code in the gspca sn9c20x.c driver? Also I would really

As you proposed I had a look on sn9c20x. It seems that sn9c20x uses register 
read
via USB control message. The pac7302 uses interrupt endpoint. So it looks like
quite different to me. Currently I see the common point in the connection
to input subsystem only.

> like to see as much of the button handling code as possible go into
> the gspca core. AFAIK many many camera's use an usb interrupt ep for this, so
> I would like to see the setting up and cleanup of this interrupt ep be in
> the core (as said before see the sn9c20x driver for another driver which
> does such things).

Unfortunately I do not know how the USB descriptors of other webcams look like.
I have access to two webcams which are handled by gspca:

 1. Labtec Webcam 2200 (USB ID 093a:2626):

Interface Number: 0
Name: (none)
Alternate Number: 0
Class: ff(vend.)
Sub Class: ff
Protocol: ff
Number of Endpoints: 6

[...]

Endpoint Address: 83
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 2
Interval: 50ms

This endpoint handles the capture button.

 2. Trust 610 LCD pow...@m Zoom (USB ID 06d6:0031)

Interface Number: 1
Name: (none)
Alternate Number: 0
Class: ff(vend.)
Sub Class: 00
Protocol: 00
Number of Endpoints: 3

[...]

Endpoint Address: 84
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 1
Interval: 1ms

I don't know what this interrupt endpoint is useful for.

Comparing these two endpoints shows the common and different points:
Common: interface class, endpoint direction, endpoint type.
Different: interface number, sub class, protocol, endpoint address, max
   packet size, interval.

Maybe the second example is not a good one because I don't know whether
the interrupt endpoint is used for buttons or not.

Do you have access to webcams equipped with button? Could you please
send the device descriptor (lsusb -v) about these devices in order
the common points can be identified for interrupt endpoints?

Regards,

Márton Németh

> On 11/15/2009 09:47 AM, Németh Márton wrote:
>> From: Márton Németh
>>
>> Add support for snapshot button found on Labtec Webcam 2200.
>>
>> Signed-off-by: Márton Németh
>> ---
>> Hi,
>>
>> this is the first trial to add support for the snapshot button. This
>> code is working only before the streaming is started. When the streaming
>> is started the alternate number of the interface 0 is changed and the
>> interrupt URB is no longer usable. I guess the interrupt URB is to
>> be reconstructed every time when the alternate number is changed.
>>
>> When I disconnect the device I get the following error:
>>
>> uhci_hcd :00:1d.1: dma_pool_free buffer-32, f58ba168/358ba168 (bad dma)
>>
>> I guess something is wrong in this patch with the cleanup routine.
>>
>> Regards,
>>
>>  Márton Németh
>>
>> ---
>> diff -r 09c1284de47d linux/drivers/media/video/gspca/gspca.h
>> --- a/linux/drivers/media/video/gspca/gspca.hSat Nov 14 08:58:12 
>> 2009 +0100
>> +++ b/linux/drivers/media/video/gspca/gspca.hSun Nov 15 10:40:54 
>> 2009 +0100
>> @@ -138,6 +138,7 @@
>>  struct module *module;  /* subdriver handling the device */
>>  struct usb_device *dev;
>>  struct file *capt_file; /* file doing video capture */
>> +struct input_dev *input_dev;
>>
>>  struct cam cam; /* device information */
>>  const struct sd_desc *sd_desc;  /* subdriver description */
>> @@ -147,6 +148,7 @@
>>   #define USB_BUF_SZ 64
>>  __u8 *usb_buf;  /* buffer for USB exchanges */
>>  struct urb *urb[MAX_NURBS];
>> +struct urb *int_urb;
>>
>>  __u8 *frbuf;/* buffer for nframes */
>>  struct gspca_frame frame[GSPCA_MAX_FRAMES];
>> diff -r 09c1284de47d linux/drivers/media/video/gspca/pac7302.c
>> --- a/linux/drivers/media/video/gspca/pac7302.c  Sat Nov 14 08:58:12 
>> 2009 +0100
>> +++ b/linux/drivers/media/video/gspca/pac7302.c  Sun Nov 15 10:40:54 
>> 2009 +0100
>> @@ -68,6 +68,7 @@
>>
>>   #define MODULE_NAME "pac7302"
>>
>> +#include
>>   #include
>>   #include "gspca.h"
>>
>> @@ -1220,6 +1221,50 @@
>>   }
>>   #endif
>>
>> +#

Re: [RFC, PATCH] gspca pac7302: add support for camera button

2009-11-16 Thread Hans de Goede

Hi,

On 11/16/2009 07:58 AM, Németh Márton wrote:

Hi,
Hans de Goede wrote:

Hi,

Thanks for working on this! I think it would be great if we could
get support for camera buttons in general into gspca.

I've not looked closely at your code yet, have you looked at
the camera button code in the gspca sn9c20x.c driver? Also I would really


As you proposed I had a look on sn9c20x. It seems that sn9c20x uses register 
read
via USB control message. The pac7302 uses interrupt endpoint. So it looks like
quite different to me. Currently I see the common point in the connection
to input subsystem only.



Ah you are right, oops, most camera's use an interrupt end point so I assumed
sn9c20x would be the same, my bad.


like to see as much of the button handling code as possible go into
the gspca core. AFAIK many many camera's use an usb interrupt ep for this, so
I would like to see the setting up and cleanup of this interrupt ep be in
the core (as said before see the sn9c20x driver for another driver which
does such things).


Unfortunately I do not know how the USB descriptors of other webcams look like.
I have access to two webcams which are handled by gspca:



No problem, just put all the input code in pac7302.c for now, we will abstract 
it
later when we add support for the button on other camera's too.




Comparing these two endpoints shows the common and different points:
Common: interface class, endpoint direction, endpoint type.
Different: interface number, sub class, protocol, endpoint address, max
packet size, interval.

Maybe the second example is not a good one because I don't know whether
the interrupt endpoint is used for buttons or not.

Do you have access to webcams equipped with button? Could you please
send the device descriptor (lsusb -v) about these devices in order
the common points can be identified for interrupt endpoints?



As the author/maintainer of quite a few drivers and libv4l author I have
build up quite a test camera collection, I'll send you the lsusb -v output
of a few in a private mail. But as said before, for now I think you can just put
the input code inside pac7302.c, then later on we can try to abstract it.

Regards,

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