[PATCH V2 12/24] usb/gspca/pac7311.c: use IS_ENABLED() macro

2013-01-19 Thread Peter Senna Tschudin
replace:
 #if defined(CONFIG_INPUT) || \
 defined(CONFIG_INPUT_MODULE)
with:
 #if IS_ENABLED(CONFIG_INPUT)

This change was made for: CONFIG_INPUT

Reported-by: Mauro Carvalho Chehab 
Signed-off-by: Peter Senna Tschudin 
---
Changes from V1:
   Updated subject

 drivers/media/usb/gspca/pac7311.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/gspca/pac7311.c 
b/drivers/media/usb/gspca/pac7311.c
index ba3558d..a12dfbf 100644
--- a/drivers/media/usb/gspca/pac7311.c
+++ b/drivers/media/usb/gspca/pac7311.c
@@ -621,7 +621,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
 }
 
-#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
+#if IS_ENABLED(CONFIG_INPUT)
 static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
u8 *data,   /* interrupt packet data */
int len)/* interrupt packet length */
@@ -661,7 +661,7 @@ static const struct sd_desc sd_desc = {
.stopN = sd_stopN,
.pkt_scan = sd_pkt_scan,
.dq_callback = do_autogain,
-#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
+#if IS_ENABLED(CONFIG_INPUT)
.int_pkt_scan = sd_int_pkt_scan,
 #endif
 };
-- 
1.7.11.7

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

2011-10-20 Thread Németh Márton
Lars Noschinski wrote:
> * Németh Márton  [11-10-18 22:14]:
>> Hi Lars,
>>
>> Lars Noschinski wrote:
>>> I'm using a webcam (Philipps SPC500NC) which identifies itself as
>>>
>>> 093a:2603 Pixart Imaging, Inc. PAC7312 Camera
>>>
>>> and is sort-of supported by the gspca_pac7311 module. "sort-of" because
>>> the image alternates quickly between having a red tint or a green tint
>>> (using the gspac driver from kernel 3.0.0, but this problem is present
>>> since at least 2.6.31).
>> The most important source code for your webcam is 
>> drivers/media/video/gspca/pac7311.c .
>> You can see it online at 
>> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/media/video/gspca/pac7311.c
>>  .
>>
>>> If I remove and re-plugin the camera a few times (on average around 3
>>> times), the colors are stable.
>> When you plug and remove the webcam and the colors are wrong, do you get any
>> message in the "dmesg"?
> 
> I get the same messages; sometimes the order of the messages output by
> uhci_hcd ehci_hcd differs, but this seems to be unrelated to working/not
> working.
> 
>> Once the colors are stable and you unplug and replug the webcam, what 
>> happens then?
>> Is there again around 3 times when the webcam is not working properly?
> 
> I now did a longer series of unplug&replug: Over the time, status
> "stable colors" seemed to get more probable. After a while, it only
> falls back to alternating colors, when I unplug it for a longer time
> (say 10 seconds). Might be a hardware problem?

You might want to try the same webcam on different USB port to exclude the
connector problem on the computer. I don't know if you have the possibility
to try the webcam on a completly different computer also.

>>> Then a second issue becomes apparent:
>>> There is almost no saturation in the image. Toying around with Contrast,
>>> Gamma, Exposure or Gain does not help. What _does_ help is the Vflip
>>> switch: If I enable it, the image is flipped vertically (as expected),
>>> but also the color become a lot better.
>> Is there any difference when you use the "Mirror" control? What about the
>> combination of the "Vflip" and "Mirror" controls?
> 
> "Vflip" and ("Vflip" and "Mirror") change color; "Mirror" alone does
> not.
> 
>> What about the "Auto Gain" setting? Is it enabled or disabled in your case?
> 
> Auto Gain is enabled; but colors also change if it is disabled
>>> Is there something I can do to debug/fix this problem?
>> You can try testing the webcam with different resolutions. The webcam
>> supports 160x120, 320x240 and 640x480 resolutions based on the source code.
>> You can try the different resolutions for example with "cheese"
>> ( http://projects.gnome.org/cheese/ ) or any of your favorite V4L2 program.
> 
> This does not seem to make a difference; except that 160x120 is listed,
> but does not seem to be available. guvcview tells me:
> 
> Checking video mode 640x480@32bpp : OK 
> setting new resolution (320 x 240)
> checking format: 859981650
> Checking video mode 320x240@32bpp : OK 
> setting new resolution (160 x 120)
> checking format: 859981650
> Checking video mode 160x120@32bpp : OK 
> ioctl (-1067952623) retried 4 times - giving up: Die Ressource ist zur Zeit 
> nicht verfügbar)
> VIDIOC_DQBUF - Unable to dequeue buffer : Die Ressource ist zur Zeit nicht 
> verfügbar
> Error grabbing image 
> (the last message is then repeated, till i change the resolution)
> 
> [Also, since I switched to 160x120, cheese crashes with a segfault,
> without giving me the possibility to switch back and I cannot find the
> config file.]

You can try running cheese using the command line "strace -f cheese" to see 
what was the last
system call before the crash. If you have the debug symbols installed for 
cheese then you
can also try running "gdb cheese". Once you get the (gdb) prompt enter the 
command "run".
Switch to 160x120 resolution. When cheese crashes you should get (gdb) prompt 
again. Execute
"bt" (backtrace) and send the result.

>> You can load the usbmon kernel module and use Wireshark to log the USB 
>> communication
>> between your computer and the webcam starting with plug-in. You can compare
>> the communication when the webcam starts to work correctly with the one when
>> the webcam doesn't work as expected.
> 
> I'll try to do this later this week.
> 
> Greetings,
>   Lars Noschinski
> 
> 

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

2011-10-20 Thread Lars Noschinski
* Németh Márton  [11-10-18 22:14]:
> Hi Lars,
> 
> Lars Noschinski wrote:
> > I'm using a webcam (Philipps SPC500NC) which identifies itself as
> > 
> > 093a:2603 Pixart Imaging, Inc. PAC7312 Camera
> > 
> > and is sort-of supported by the gspca_pac7311 module. "sort-of" because
> > the image alternates quickly between having a red tint or a green tint
> > (using the gspac driver from kernel 3.0.0, but this problem is present
> > since at least 2.6.31).
> 
> The most important source code for your webcam is 
> drivers/media/video/gspca/pac7311.c .
> You can see it online at 
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/media/video/gspca/pac7311.c
>  .
> 
> > If I remove and re-plugin the camera a few times (on average around 3
> > times), the colors are stable.
> 
> When you plug and remove the webcam and the colors are wrong, do you get any
> message in the "dmesg"?

I get the same messages; sometimes the order of the messages output by
uhci_hcd ehci_hcd differs, but this seems to be unrelated to working/not
working.

> Once the colors are stable and you unplug and replug the webcam, what happens 
> then?
> Is there again around 3 times when the webcam is not working properly?

I now did a longer series of unplug&replug: Over the time, status
"stable colors" seemed to get more probable. After a while, it only
falls back to alternating colors, when I unplug it for a longer time
(say 10 seconds). Might be a hardware problem?

> > Then a second issue becomes apparent:
> > There is almost no saturation in the image. Toying around with Contrast,
> > Gamma, Exposure or Gain does not help. What _does_ help is the Vflip
> > switch: If I enable it, the image is flipped vertically (as expected),
> > but also the color become a lot better.
> 
> Is there any difference when you use the "Mirror" control? What about the
> combination of the "Vflip" and "Mirror" controls?

"Vflip" and ("Vflip" and "Mirror") change color; "Mirror" alone does
not.

> What about the "Auto Gain" setting? Is it enabled or disabled in your case?

Auto Gain is enabled; but colors also change if it is disabled
> 
> > Is there something I can do to debug/fix this problem?
> 
> You can try testing the webcam with different resolutions. The webcam
> supports 160x120, 320x240 and 640x480 resolutions based on the source code.
> You can try the different resolutions for example with "cheese"
> ( http://projects.gnome.org/cheese/ ) or any of your favorite V4L2 program.

This does not seem to make a difference; except that 160x120 is listed,
but does not seem to be available. guvcview tells me:

Checking video mode 640x480@32bpp : OK 
setting new resolution (320 x 240)
checking format: 859981650
Checking video mode 320x240@32bpp : OK 
setting new resolution (160 x 120)
checking format: 859981650
Checking video mode 160x120@32bpp : OK 
ioctl (-1067952623) retried 4 times - giving up: Die Ressource ist zur Zeit 
nicht verfügbar)
VIDIOC_DQBUF - Unable to dequeue buffer : Die Ressource ist zur Zeit nicht 
verfügbar
Error grabbing image 
(the last message is then repeated, till i change the resolution)

[Also, since I switched to 160x120, cheese crashes with a segfault,
without giving me the possibility to switch back and I cannot find the
config file.]

> You can load the usbmon kernel module and use Wireshark to log the USB 
> communication
> between your computer and the webcam starting with plug-in. You can compare
> the communication when the webcam starts to work correctly with the one when
> the webcam doesn't work as expected.

I'll try to do this later this week.

Greetings,
  Lars Noschinski
--
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: pac7311

2011-10-18 Thread Németh Márton
Hi Lars,

Lars Noschinski wrote:
> I'm using a webcam (Philipps SPC500NC) which identifies itself as
> 
> 093a:2603 Pixart Imaging, Inc. PAC7312 Camera
> 
> and is sort-of supported by the gspca_pac7311 module. "sort-of" because
> the image alternates quickly between having a red tint or a green tint
> (using the gspac driver from kernel 3.0.0, but this problem is present
> since at least 2.6.31).

The most important source code for your webcam is 
drivers/media/video/gspca/pac7311.c .
You can see it online at 
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/media/video/gspca/pac7311.c
 .

> If I remove and re-plugin the camera a few times (on average around 3
> times), the colors are stable.

When you plug and remove the webcam and the colors are wrong, do you get any
message in the "dmesg"?

Once the colors are stable and you unplug and replug the webcam, what happens 
then?
Is there again around 3 times when the webcam is not working properly?

> Then a second issue becomes apparent:
> There is almost no saturation in the image. Toying around with Contrast,
> Gamma, Exposure or Gain does not help. What _does_ help is the Vflip
> switch: If I enable it, the image is flipped vertically (as expected),
> but also the color become a lot better.

Is there any difference when you use the "Mirror" control? What about the
combination of the "Vflip" and "Mirror" controls?

What about the "Auto Gain" setting? Is it enabled or disabled in your case?

> Is there something I can do to debug/fix this problem?

You can try testing the webcam with different resolutions. The webcam
supports 160x120, 320x240 and 640x480 resolutions based on the source code.
You can try the different resolutions for example with "cheese"
( http://projects.gnome.org/cheese/ ) or any of your favorite V4L2 program.

You can load the usbmon kernel module and use Wireshark to log the USB 
communication
between your computer and the webcam starting with plug-in. You can compare
the communication when the webcam starts to work correctly with the one when
the webcam doesn't work as expected.

Regards,

Márton Németh
--
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


pac7311

2011-10-16 Thread Lars Noschinski
Hello,

I'm using a webcam (Philipps SPC500NC) which identifies itself as

093a:2603 Pixart Imaging, Inc. PAC7312 Camera

and is sort-of supported by the gspca_pac7311 module. "sort-of" because
the image alternates quickly between having a red tint or a green tint
(using the gspac driver from kernel 3.0.0, but this problem is present
since at least 2.6.31).

If I remove and re-plugin the camera a few times (on average around 3
times), the colors are stable. Then a second issue becomes apparent:
There is almost no saturation in the image. Toying around with Contrast,
Gamma, Exposure or Gain does not help. What _does_ help is the Vflip
switch: If I enable it, the image is flipped vertically (as expected),
but also the color become a lot better.

Is there something I can do to debug/fix this problem?
--
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


[PATCH] gspca pac7311: stop sending URBs on first error

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

It is no use to continue sending URBs if one of them already
failed.

Signed-off-by: Márton Németh 
---
The patch is based on 13335:3fd924da7091 from 
http://linuxtv.org/hg/~jfrancois/gspca/ .
---
diff -r 3fd924da7091 linux/drivers/media/video/gspca/pac7311.c
--- a/linux/drivers/media/video/gspca/pac7311.c Sun Nov 08 08:41:28 2009 +0100
+++ b/linux/drivers/media/video/gspca/pac7311.c Sun Nov 08 23:14:13 2009 +0100
@@ -590,16 +590,27 @@

 static void sd_stopN(struct gspca_dev *gspca_dev)
 {
-   reg_w(gspca_dev, 0xff, 0x04);
-   reg_w(gspca_dev, 0x27, 0x80);
-   reg_w(gspca_dev, 0x28, 0xca);
-   reg_w(gspca_dev, 0x29, 0x53);
-   reg_w(gspca_dev, 0x2a, 0x0e);
-   reg_w(gspca_dev, 0xff, 0x01);
-   reg_w(gspca_dev, 0x3e, 0x20);
-   reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
-   reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
-   reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
+   int ret;
+
+   ret = reg_w(gspca_dev, 0xff, 0x04);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x27, 0x80);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x28, 0xca);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x29, 0x53);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x2a, 0x0e);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0xff, 0x01);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x3e, 0x20);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, 
Bit_6=LED */
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, 
Bit_6=LED */
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, 
Bit_6=LED */
 }

 /* called on streamoff with alt 0 and on disconnect for 7311 */
--
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


[PATCH 1/2] gspca pac7302/pac7311: propagate error to higher level software

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

The usb_control_msg() can fail any time. Only continue writing
sequence if there was no error with the previous write. If there
was any problem stop sending URBs and propagate the error to the
gspca_main.

Only the pac7302 driver was tested with Labtec Webcam 2200
(USB ID 093a:2626) because of lack of hardware for pac7311.

Signed-off-by: Márton Németh 
---
The patch is based on the 13327:19c0469c02c3 of http://linuxtv.org/hg/v4l-dvb/ .
This patch replaces http://linuxtv.org/hg/~jfrancois/v4l-dvb/rev/2dc5e25b76c1
and http://linuxtv.org/hg/~jfrancois/v4l-dvb/rev/43be85676a49 . In addition to
those patches this patch also updates sd_stopN() function in pac7311.
---
diff -r 19c0469c02c3 linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c Sat Nov 07 15:51:01 2009 -0200
+++ b/linux/drivers/media/video/gspca/pac7302.c Sun Nov 08 11:54:26 2009 +0100
@@ -331,7 +331,7 @@
0x00
 };

-static void reg_w_buf(struct gspca_dev *gspca_dev,
+static int reg_w_buf(struct gspca_dev *gspca_dev,
  __u8 index,
  const char *buffer, int len)
 {
@@ -349,6 +349,7 @@
PDEBUG(D_ERR, "reg_w_buf(): "
"Failed to write registers to index 0x%x, error %i",
index, ret);
+   return ret;
 }

 #if 0 /* not used */
@@ -373,7 +374,7 @@
 }
 #endif

-static void reg_w(struct gspca_dev *gspca_dev,
+static int reg_w(struct gspca_dev *gspca_dev,
  __u8 index,
  __u8 value)
 {
@@ -390,23 +391,27 @@
PDEBUG(D_ERR, "reg_w(): "
"Failed to write register to index 0x%x, value 0x%x, error %i",
index, value, ret);
+   return ret;
 }

-static void reg_w_seq(struct gspca_dev *gspca_dev,
+static int reg_w_seq(struct gspca_dev *gspca_dev,
const __u8 *seq, int len)
 {
+   int ret = 0;
while (--len >= 0) {
-   reg_w(gspca_dev, seq[0], seq[1]);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, seq[0], seq[1]);
seq += 2;
}
+   return ret;
 }

 /* load the beginning of a page */
-static void reg_w_page(struct gspca_dev *gspca_dev,
+static int reg_w_page(struct gspca_dev *gspca_dev,
const __u8 *page, int len)
 {
int index;
-   int ret;
+   int ret = 0;

for (index = 0; index < len; index++) {
if (page[index] == SKIP)/* skip this index */
@@ -418,52 +423,61 @@
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, index, gspca_dev->usb_buf, 1,
500);
-   if (ret < 0)
+   if (ret < 0) {
PDEBUG(D_ERR, "reg_w_page(): "
"Failed to write register to index 0x%x, "
"value 0x%x, error %i",
index, page[index], ret);
+   break;
+   }
}
+   return ret;
 }

 /* output a variable sequence */
-static void reg_w_var(struct gspca_dev *gspca_dev,
+static int reg_w_var(struct gspca_dev *gspca_dev,
const __u8 *seq,
const __u8 *page3, unsigned int page3_len,
const __u8 *page4, unsigned int page4_len)
 {
int index, len;
+   int ret = 0;

for (;;) {
index = *seq++;
len = *seq++;
switch (len) {
case END_OF_SEQUENCE:
-   return;
+   return ret;
case LOAD_PAGE4:
-   reg_w_page(gspca_dev, page4, page4_len);
+   ret = reg_w_page(gspca_dev, page4, page4_len);
break;
case LOAD_PAGE3:
-   reg_w_page(gspca_dev, page3, page3_len);
+   ret = reg_w_page(gspca_dev, page3, page3_len);
break;
default:
if (len > USB_BUF_SZ) {
PDEBUG(D_ERR|D_STREAM,
"Incorrect variable sequence");
-   return;
+   return -EINVAL;
}
while (len > 0) {
if (len < 8) {
-   reg_w_buf(gspca_dev, index, seq, len);
+   ret = reg_w_buf(gspca_dev,
+   index, seq, len);
+   if (ret < 0)
+   return ret;
seq += len;
 

Re: [PATCH 3/3] gspca pac7302/pac7311: separate the two subdrivers

2009-11-07 Thread Hans de Goede

Hi Németh,

I'm getting similar reports for other (non pac73xx) model webcams with
2.6.32 on eeepc's and other computers using the uhci usb driver.

Can you try installing an older kernel (so 2.6.30) and then building
and installing the latest v4l-dvb tree (with your changes in) over that ?

I think what you are seeing here is a bug outside of the v4l subsystem,
this is just a hunch though.

Regards,

Hans



On 11/04/2009 07:20 AM, Németh Márton wrote:

Dear Jef,

although I tested my patch on my development computer together with Labtec
Webcam 2200 (gspca_pac7302 driver) it seems that the patch may cause regression
on some computers. For example I tested the gspca_pac7302 driver from
http://linuxtv.org/hg/~jfrancois/gspca/ on top of Linux kernel 2.6.32-rc5 on
an EeePC 901. I get the following error message in dmesg:

[ 4476.992201] usb 3-2: new full speed USB device using uhci_hcd and address 11
[ 4477.230485] usb 3-2: New USB device found, idVendor=093a, idProduct=2626
[ 4477.230507] usb 3-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 4477.231139] usb 3-2: configuration #1 chosen from 1 choice
[ 4477.417456] Linux video capture interface: v2.00
[ 4477.437131] gspca: main v2.7.0 registered
[ 4477.443214] gspca: probing 093a:2626
[ 4477.453491] gspca: /dev/video0 created
[ 4477.453541] gspca: probing 093a:2626
[ 4477.453549] gspca: intf != 0
[ 4477.453598] gspca: probing 093a:2626
[ 4477.453605] gspca: intf != 0
[ 4477.453755] usbcore: registered new interface driver pac7302
[ 4477.453771] pac7302: registered
[ 4489.552153] gspca: set alt 8 err -71

I bisected the problem on EeePC 901 and the changeset 13373:99c23949b411
(gspca - pac7302/pac7311: Separate the two subdrivers.) was marked as the first 
bad
commit.

On my development computer the same configuration works correctly:

[ 7872.020222] usb 3-1: new full speed USB device using uhci_hcd and address 4
[ 7872.251240] usb 3-1: configuration #1 chosen from 1 choice
[ 7872.744755] Linux video capture interface: v2.00
[ 7872.785032] gspca: main v2.7.0 registered
[ 7872.797061] gspca: probing 093a:2626
[ 7872.807577] gspca: /dev/video0 created
[ 7872.809747] usbcore: registered new interface driver pac7302
[ 7872.809798] pac7302: registered

Is the separated driver working for you?
Do you have any idea what could went wrong? Maybe some timing problem?

Regards,

Márton Németh

Németh Márton wrote:

From: Márton Németh

All PAC7311 specific functions remain in pac7311.c. All PAC7302 specific
functions are moved to pac7302.c. The USB device table is also divided into
two parts. This makes it possible to remove the sensor specific decisions
from different functions and also remove sensor infromation from the USB
device table.

The common functions are just copied to both subdrivers. These common
functions can be separated later to a common file or helper module.

Signed-off-by: Márton Németh
Cc: Thomas Kaiser
Cc: Theodore Kilgore
Cc: Kyle Guinn

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


[PATCH] gspca pac7311/pac7302: propagate error to higher level software

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

The usb_control_msg() can fail any time. Only continue writing
sequence if there was no error with the previous write. If there
was any problem stop sending URBs and propagate the error to the
gspca_main.

Only the pac7302 driver was tested with Labtec Webcam 2200
(USB ID 093a:2626) because of lack of hardware for pac7311.

Signed-off-by: Márton Németh 
---
diff -upr a/linux/drivers/media/video/gspca/pac7302.c 
b/linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c 2009-11-07 08:57:26.0 
+0100
+++ b/linux/drivers/media/video/gspca/pac7302.c 2009-11-07 09:08:16.0 
+0100
@@ -331,7 +331,7 @@ static const __u8 page3_7302[] = {
0x00
 };

-static void reg_w_buf(struct gspca_dev *gspca_dev,
+static int reg_w_buf(struct gspca_dev *gspca_dev,
  __u8 index,
  const char *buffer, int len)
 {
@@ -349,6 +349,7 @@ static void reg_w_buf(struct gspca_dev *
PDEBUG(D_ERR, "reg_w_buf(): "
"Failed to write registers to index 0x%x, error %i",
index, ret);
+   return ret;
 }

 #if 0 /* not used */
@@ -373,7 +374,7 @@ static __u8 reg_r(struct gspca_dev *gspc
 }
 #endif

-static void reg_w(struct gspca_dev *gspca_dev,
+static int reg_w(struct gspca_dev *gspca_dev,
  __u8 index,
  __u8 value)
 {
@@ -390,23 +391,27 @@ static void reg_w(struct gspca_dev *gspc
PDEBUG(D_ERR, "reg_w(): "
"Failed to write register to index 0x%x, value 0x%x, error %i",
index, value, ret);
+   return ret;
 }

-static void reg_w_seq(struct gspca_dev *gspca_dev,
+static int reg_w_seq(struct gspca_dev *gspca_dev,
const __u8 *seq, int len)
 {
+   int ret = 0;
while (--len >= 0) {
-   reg_w(gspca_dev, seq[0], seq[1]);
+   if (0 <= ret)
+   ret = reg_w(gspca_dev, seq[0], seq[1]);
seq += 2;
}
+   return ret;
 }

 /* load the beginning of a page */
-static void reg_w_page(struct gspca_dev *gspca_dev,
+static int reg_w_page(struct gspca_dev *gspca_dev,
const __u8 *page, int len)
 {
int index;
-   int ret;
+   int ret = 0;

for (index = 0; index < len; index++) {
if (page[index] == SKIP)/* skip this index */
@@ -418,52 +423,61 @@ static void reg_w_page(struct gspca_dev
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, index, gspca_dev->usb_buf, 1,
500);
-   if (ret < 0)
+   if (ret < 0) {
PDEBUG(D_ERR, "reg_w_page(): "
"Failed to write register to index 0x%x, "
"value 0x%x, error %i",
index, page[index], ret);
+   break;
+   }
}
+   return ret;
 }

 /* output a variable sequence */
-static void reg_w_var(struct gspca_dev *gspca_dev,
+static int reg_w_var(struct gspca_dev *gspca_dev,
const __u8 *seq,
const __u8 *page3, unsigned int page3_len,
const __u8 *page4, unsigned int page4_len)
 {
int index, len;
+   int ret = 0;

for (;;) {
index = *seq++;
len = *seq++;
switch (len) {
case END_OF_SEQUENCE:
-   return;
+   return ret;
case LOAD_PAGE4:
-   reg_w_page(gspca_dev, page4, page4_len);
+   ret = reg_w_page(gspca_dev, page4, page4_len);
break;
case LOAD_PAGE3:
-   reg_w_page(gspca_dev, page3, page3_len);
+   ret = reg_w_page(gspca_dev, page3, page3_len);
break;
default:
if (len > USB_BUF_SZ) {
PDEBUG(D_ERR|D_STREAM,
"Incorrect variable sequence");
-   return;
+   return -EINVAL;
}
while (len > 0) {
if (len < 8) {
-   reg_w_buf(gspca_dev, index, seq, len);
+   ret = reg_w_buf(gspca_dev,
+   index, seq, len);
+   if (ret < 0)
+   return ret;
seq += len;
break;
}
-  

Re: pac7311

2009-11-06 Thread Lars Noschinski
Hi!

* Jean-Francois Moine  [09-11-06 09:43]:
> On Fri, 6 Nov 2009 00:38:43 +0100
> Lars Noschinski  wrote:
> 
> > I'm using a webcam which identifies itself as
> > 
> > 093a:2603 Pixart Imaging, Inc. PAC7312 Camera
> > 
> > and is sort-of supported by the gspca_pac7311 module. "sort-of"
> > because the image alternates quickly between having a red tint or a
> > green tint (using the gspca driver from
> > http://linuxtv.org/hg/~jfrancois/gspca/ on a 2.6.31 kernel; occurs
> > also with plain 2.6.31).

It is Philipps SPC500NC.

> > Is there something I can do to debug/fix this problem?

First of all, 
> 
> First, which viewer do you run and does it use the v4l2 library?

I'm using ekiga which uses libpt's v4l2 support. The libpt package
depends on the libv4l package, which contains libv4l2, so it probably
uses the v4l2 library.

I could try another viewer for debugging, if this is of any use, but
ekiga is what I care about.

> Then, a bug in the pac7311 driver has been found yesterday. Did you
> get/try this last one?

Tip of my tree is 13436:f353aa2982f2, which seems to be the latest one.

After rebooting my computer this morning, the cam worked for a few
minutes without those color glitches. Then, after turning off the light
in my room and turning it on again, the image started alternating
quickly between light and dark.  I tried to get rid of it with
re-plugging the device, but this soon led to the original problem
(red/green tints). I tried another reboot, but no luck.

 - Lars.
--
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: pac7311

2009-11-05 Thread Jean-Francois Moine
On Fri, 6 Nov 2009 00:38:43 +0100
Lars Noschinski  wrote:

> I'm using a webcam which identifies itself as
> 
> 093a:2603 Pixart Imaging, Inc. PAC7312 Camera
> 
> and is sort-of supported by the gspca_pac7311 module. "sort-of"
> because the image alternates quickly between having a red tint or a
> green tint (using the gspca driver from
> http://linuxtv.org/hg/~jfrancois/gspca/ on a 2.6.31 kernel; occurs
> also with plain 2.6.31).
> 
> Is there something I can do to debug/fix this problem?

Hello Lars,

First, which viewer do you run and does it use the v4l2 library?

Then, a bug in the pac7311 driver has been found yesterday. Did you
get/try this last one?

Regards.

-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
--
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


pac7311

2009-11-05 Thread Lars Noschinski
Hello!

I'm using a webcam which identifies itself as

093a:2603 Pixart Imaging, Inc. PAC7312 Camera

and is sort-of supported by the gspca_pac7311 module. "sort-of" because
the image alternates quickly between having a red tint or a green tint
(using the gspca driver from http://linuxtv.org/hg/~jfrancois/gspca/ on
a 2.6.31 kernel; occurs also with plain 2.6.31).

Is there something I can do to debug/fix this problem?

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


[PATCH] gspca pac7302/pac7311: handle return value of usb_control_msg()

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

The function usb_control_msg() can return error any time so at least
warn the user if an error happens. No message is printed in case of
normal operation.

Signed-off-by: Márton Németh 
---
diff -r e628f4381170 linux/drivers/media/video/gspca/pac7302.c
--- a/linux/drivers/media/video/gspca/pac7302.c Mon Nov 02 14:00:48 2009 +0100
+++ b/linux/drivers/media/video/gspca/pac7302.c Wed Nov 04 23:30:53 2009 +0100
@@ -335,27 +335,40 @@
  __u8 index,
  const char *buffer, int len)
 {
+   int ret;
+
memcpy(gspca_dev->usb_buf, buffer, len);
-   usb_control_msg(gspca_dev->dev,
+   ret = usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev, 0),
1,  /* request */
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0,  /* value */
index, gspca_dev->usb_buf, len,
500);
+   if (ret < 0)
+   PDEBUG(D_ERR, "reg_w_buf(): "
+   "Failed to write registers to index 0x%x, error %i",
+   index, ret);
 }

 #if 0 /* not used */
 static __u8 reg_r(struct gspca_dev *gspca_dev,
 __u8 index)
 {
-   usb_control_msg(gspca_dev->dev,
+   int ret;
+
+   ret = usb_control_msg(gspca_dev->dev,
usb_rcvctrlpipe(gspca_dev->dev, 0),
0,  /* request */
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0,  /* value */
index, gspca_dev->usb_buf, 1,
500);
+   if (ret < 0)
+   PDEBUG(D_ERR, "reg_r(): "
+   "Failed to read register from index 0x%x, error %i",
+   index, ret);
+
return gspca_dev->usb_buf[0];
 }
 #endif
@@ -364,13 +377,19 @@
  __u8 index,
  __u8 value)
 {
+   int ret;
+
gspca_dev->usb_buf[0] = value;
-   usb_control_msg(gspca_dev->dev,
+   ret = usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev, 0),
0,  /* request */
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, index, gspca_dev->usb_buf, 1,
500);
+   if (ret < 0)
+   PDEBUG(D_ERR, "reg_w(): "
+   "Failed to write register to index 0x%x, value 0x%x, error %i",
+   index, value, ret);
 }

 static void reg_w_seq(struct gspca_dev *gspca_dev,
@@ -387,17 +406,23 @@
const __u8 *page, int len)
 {
int index;
+   int ret;

for (index = 0; index < len; index++) {
if (page[index] == SKIP)/* skip this index */
continue;
gspca_dev->usb_buf[0] = page[index];
-   usb_control_msg(gspca_dev->dev,
+   ret = usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev, 0),
0,  /* request */
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, index, gspca_dev->usb_buf, 1,
500);
+   if (ret < 0)
+   PDEBUG(D_ERR, "reg_w_page(): "
+   "Failed to write register to index 0x%x, "
+       "value 0x%x, error %i",
+   index, page[index], ret);
}
 }

diff -r e628f4381170 linux/drivers/media/video/gspca/pac7311.c
--- a/linux/drivers/media/video/gspca/pac7311.c Mon Nov 02 14:00:48 2009 +0100
+++ b/linux/drivers/media/video/gspca/pac7311.c Wed Nov 04 23:30:53 2009 +0100
@@ -263,27 +263,40 @@
  __u8 index,
  const char *buffer, int len)
 {
+   int ret;
+
memcpy(gspca_dev->usb_buf, buffer, len);
-   usb_control_msg(gspca_dev->dev,
+   ret = usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev, 0),
1,  /* request */
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0,  /* value */
index, gspca_dev->usb_buf, len,
500);
+   if (ret < 0)
+   PDEBUG(D_ERR, "reg_w_buf(): "
+   "Failed to write registers to index 0x%x, error %i",
+   index, ret);
 }

 #if 0 /* not used */
 static __u8 reg_r(struct gspca_dev *gspca_dev,
 __

Re: [PATCH 3/3] gspca pac7302/pac7311: separate the two subdrivers

2009-11-03 Thread Németh Márton
Dear Jef,

although I tested my patch on my development computer together with Labtec
Webcam 2200 (gspca_pac7302 driver) it seems that the patch may cause regression
on some computers. For example I tested the gspca_pac7302 driver from
http://linuxtv.org/hg/~jfrancois/gspca/ on top of Linux kernel 2.6.32-rc5 on
an EeePC 901. I get the following error message in dmesg:

[ 4476.992201] usb 3-2: new full speed USB device using uhci_hcd and address 11
[ 4477.230485] usb 3-2: New USB device found, idVendor=093a, idProduct=2626
[ 4477.230507] usb 3-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 4477.231139] usb 3-2: configuration #1 chosen from 1 choice
[ 4477.417456] Linux video capture interface: v2.00
[ 4477.437131] gspca: main v2.7.0 registered
[ 4477.443214] gspca: probing 093a:2626
[ 4477.453491] gspca: /dev/video0 created
[ 4477.453541] gspca: probing 093a:2626
[ 4477.453549] gspca: intf != 0
[ 4477.453598] gspca: probing 093a:2626
[ 4477.453605] gspca: intf != 0
[ 4477.453755] usbcore: registered new interface driver pac7302
[ 4477.453771] pac7302: registered
[ 4489.552153] gspca: set alt 8 err -71

I bisected the problem on EeePC 901 and the changeset 13373:99c23949b411
(gspca - pac7302/pac7311: Separate the two subdrivers.) was marked as the first 
bad
commit.

On my development computer the same configuration works correctly:

[ 7872.020222] usb 3-1: new full speed USB device using uhci_hcd and address 4
[ 7872.251240] usb 3-1: configuration #1 chosen from 1 choice
[ 7872.744755] Linux video capture interface: v2.00
[ 7872.785032] gspca: main v2.7.0 registered
[ 7872.797061] gspca: probing 093a:2626
[ 7872.807577] gspca: /dev/video0 created
[ 7872.809747] usbcore: registered new interface driver pac7302
[ 7872.809798] pac7302: registered

Is the separated driver working for you?
Do you have any idea what could went wrong? Maybe some timing problem?

Regards,

Márton Németh

Németh Márton wrote:
> From: Márton Németh 
> 
> All PAC7311 specific functions remain in pac7311.c. All PAC7302 specific
> functions are moved to pac7302.c. The USB device table is also divided into
> two parts. This makes it possible to remove the sensor specific decisions
> from different functions and also remove sensor infromation from the USB
> device table.
> 
> The common functions are just copied to both subdrivers. These common
> functions can be separated later to a common file or helper module.
> 
> Signed-off-by: Márton Németh 
> Cc: Thomas Kaiser 
> Cc: Theodore Kilgore 
> Cc: Kyle Guinn 
--
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: [PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

2009-11-02 Thread Theodore Kilgore



On Mon, 2 Nov 2009, Németh Márton wrote:


Theodore Kilgore írta:


On Mon, 2 Nov 2009, Németh Márton wrote:


Theodore Kilgore wrote:

On Sun, 1 Nov 2009, Németh Márton wrote:

Remove struct sd dependency from pac_find_sof() function implementation.
This step prepares separation of pac7302 and pac7311 specific parts of
struct sd.

[...]
But here is the point. The sn9c2028 cameras have a structure which seems
similar to the mr97310a cameras. They use a similar decompression
algorithm. They have a similar frame header. Specifically, the sn9c2028
frame header starts with the five bytes

 0xff, 0xff, 0x00, 0xc4, 0xc4

whereas the pac_common frame header starts with the five bytes

 0xff, 0xff, 0x00, 0xff, 0x96

Right now, for my own use, I have written a file sn9c2028.h which
essentially duplicates the functionality of pac_common.h and contains a
function which searches for the sn9c2028 SOF marker instead of searching
for the pac SOF marker. Is this necessarily the good, permanent solution?
I am not so sure about that.

I think the pac_find_sof() is a special case. To find a SOF sequence in
a bigger buffer in general needs to first analyze the SOF sequence for
repeated bytes. If there are repeated bytes the search have to be
continued in a different way, see the state machine currently in the
pac_common.h. To find the sn9c2028 frame header a different state machine
is needed. It might be possible to implement a search function which
can find any SOF sequence but I am afraid that this algorithm would be
too complicated because of the search string analysis.


Well, I do not really know enough about this to be able to say something
authoritative, but:

1. There is an obvious limitation on the length of the SOF marker. If it
is agreed upon that the SOF marker is 5 bytes or less, then it ought not
to be so terrible a thing to do. Namely, your state machine should accept
an input, consisting of a pointer to the proper SOF marker and use that
one instead of what is "hard wired" in your code. So, for example,

 switch (sd->sof_read) {
 case 0:
 if (m[i] == 0xff)
 sd->sof_read = 1;
 break;
 case 1:
 if (m[i] == 0xff)
 sd->sof_read = 2;
 else
 sd->sof_read = 0;
 break;
(and so on)

could read instead as

 switch (sd->sof_read) {
 case 0:
 if (m[i] == sof_marker[0])
 sd->sof_read = 1;
 break;
 case 1:
 if (m[i] == sof_marker[1])
 sd->sof_read = 2;
 else
 sd->sof_read = 0;
 break;
(and so on)


The problem would come if the SOF marker were six bytes long instead. The
way to solve that would be to figure out what is the longest SOF marker
that one wants to deal with, beforehand. I am not sure what is the
prevailing number of bytes in such an SOF marker, or the maximum number.
But it would be possible to prescribe some reasonable maximum number
and take that into account, I think.


I am afraid you missed an important point: the state machine depends on the
*contents* of the SOF marker:


From pac_common.h:


  The following state machine finds the SOF marker sequence
  0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.

  +--+
  | 0: START |<---\
  +--+<-\ |
|   \---/otherwise|
v 0xff|
  +--+ otherwise  |
  | 1|--->*
  |  |^
  +--+|
| |
v 0xff|
  +--+<-\0xff |
   /->|  |--/ |
   |  | 2|--->*
   |  |  | otherwise  ^
   |  +--+|
   || |
   |v 0x00|
   |  +--+|
   |  | 3||
   |  |  |--->*
   |  +--+ otherwise  ^
   || |
  0xff |v 0xff|
   |  +--+|
   \--| 4||
  |  |/
  +--+ otherwise
|
v 0x96
  +--+
  |  FOUND   |
  +--+

Please have a closer look of the transients 2->2 and
4->2. They heavil

Re: [PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

2009-11-02 Thread Németh Márton
Theodore Kilgore írta:
> 
> On Mon, 2 Nov 2009, Németh Márton wrote:
> 
>> Theodore Kilgore wrote:
>>> On Sun, 1 Nov 2009, Németh Márton wrote:
>>>> Remove struct sd dependency from pac_find_sof() function implementation.
>>>> This step prepares separation of pac7302 and pac7311 specific parts of
>>>> struct sd.
>>> [...]
>>> But here is the point. The sn9c2028 cameras have a structure which seems
>>> similar to the mr97310a cameras. They use a similar decompression
>>> algorithm. They have a similar frame header. Specifically, the sn9c2028
>>> frame header starts with the five bytes
>>>
>>>  0xff, 0xff, 0x00, 0xc4, 0xc4
>>>
>>> whereas the pac_common frame header starts with the five bytes
>>>
>>>  0xff, 0xff, 0x00, 0xff, 0x96
>>>
>>> Right now, for my own use, I have written a file sn9c2028.h which
>>> essentially duplicates the functionality of pac_common.h and contains a
>>> function which searches for the sn9c2028 SOF marker instead of searching
>>> for the pac SOF marker. Is this necessarily the good, permanent solution?
>>> I am not so sure about that.
>> I think the pac_find_sof() is a special case. To find a SOF sequence in
>> a bigger buffer in general needs to first analyze the SOF sequence for
>> repeated bytes. If there are repeated bytes the search have to be
>> continued in a different way, see the state machine currently in the
>> pac_common.h. To find the sn9c2028 frame header a different state machine
>> is needed. It might be possible to implement a search function which
>> can find any SOF sequence but I am afraid that this algorithm would be
>> too complicated because of the search string analysis.
> 
> Well, I do not really know enough about this to be able to say something 
> authoritative, but:
> 
> 1. There is an obvious limitation on the length of the SOF marker. If it 
> is agreed upon that the SOF marker is 5 bytes or less, then it ought not 
> to be so terrible a thing to do. Namely, your state machine should accept 
> an input, consisting of a pointer to the proper SOF marker and use that 
> one instead of what is "hard wired" in your code. So, for example,
> 
>  switch (sd->sof_read) {
>  case 0:
>  if (m[i] == 0xff)
>  sd->sof_read = 1;
>  break;
>  case 1:
>  if (m[i] == 0xff)
>  sd->sof_read = 2;
>  else
>  sd->sof_read = 0;
>  break;
>   (and so on)
> 
> could read instead as
> 
>  switch (sd->sof_read) {
>  case 0:
>  if (m[i] == sof_marker[0])
>  sd->sof_read = 1;
>  break;
>  case 1:
>  if (m[i] == sof_marker[1])
>  sd->sof_read = 2;
>  else
>  sd->sof_read = 0;
>  break;
>   (and so on)
> 
> 
> The problem would come if the SOF marker were six bytes long instead. The 
> way to solve that would be to figure out what is the longest SOF marker 
> that one wants to deal with, beforehand. I am not sure what is the 
> prevailing number of bytes in such an SOF marker, or the maximum number. 
> But it would be possible to prescribe some reasonable maximum number 
> and take that into account, I think.

I am afraid you missed an important point: the state machine depends on the
*contents* of the SOF marker:

>From pac_common.h:

   The following state machine finds the SOF marker sequence
   0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.

   +--+
   | 0: START |<---\
   +--+<-\ |
 |   \---/otherwise|
 v 0xff|
   +--+ otherwise  |
   | 1|--->*
   |  |^
   +--+|
 | |
 v 0xff|
   +--+<-\0xff |
/->|  |--/ |
|  | 2|--->*
|  |  | otherwise  ^
|  +--+|
|| |
|v 0x00

Re: [PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

2009-11-02 Thread Theodore Kilgore



On Mon, 2 Nov 2009, Németh Márton wrote:


Theodore Kilgore wrote:


On Sun, 1 Nov 2009, Németh Márton wrote:

Remove struct sd dependency from pac_find_sof() function implementation.
This step prepares separation of pac7302 and pac7311 specific parts of
struct sd.

[...]
But here is the point. The sn9c2028 cameras have a structure which seems
similar to the mr97310a cameras. They use a similar decompression
algorithm. They have a similar frame header. Specifically, the sn9c2028
frame header starts with the five bytes

 0xff, 0xff, 0x00, 0xc4, 0xc4

whereas the pac_common frame header starts with the five bytes

 0xff, 0xff, 0x00, 0xff, 0x96

Right now, for my own use, I have written a file sn9c2028.h which
essentially duplicates the functionality of pac_common.h and contains a
function which searches for the sn9c2028 SOF marker instead of searching
for the pac SOF marker. Is this necessarily the good, permanent solution?
I am not so sure about that.


I think the pac_find_sof() is a special case. To find a SOF sequence in
a bigger buffer in general needs to first analyze the SOF sequence for
repeated bytes. If there are repeated bytes the search have to be
continued in a different way, see the state machine currently in the
pac_common.h. To find the sn9c2028 frame header a different state machine
is needed. It might be possible to implement a search function which
can find any SOF sequence but I am afraid that this algorithm would be
too complicated because of the search string analysis.


Well, I do not really know enough about this to be able to say something 
authoritative, but:


1. There is an obvious limitation on the length of the SOF marker. If it 
is agreed upon that the SOF marker is 5 bytes or less, then it ought not 
to be so terrible a thing to do. Namely, your state machine should accept 
an input, consisting of a pointer to the proper SOF marker and use that 
one instead of what is "hard wired" in your code. So, for example,


switch (sd->sof_read) {
case 0:
if (m[i] == 0xff)
sd->sof_read = 1;
break;
case 1:
if (m[i] == 0xff)
sd->sof_read = 2;
else
sd->sof_read = 0;
break;
(and so on)

could read instead as

switch (sd->sof_read) {
case 0:
if (m[i] == sof_marker[0])
sd->sof_read = 1;
break;
case 1:
if (m[i] == sof_marker[1])
sd->sof_read = 2;
else
sd->sof_read = 0;
break;
(and so on)


The problem would come if the SOF marker were six bytes long instead. The 
way to solve that would be to figure out what is the longest SOF marker 
that one wants to deal with, beforehand. I am not sure what is the 
prevailing number of bytes in such an SOF marker, or the maximum number. 
But it would be possible to prescribe some reasonable maximum number 
and take that into account, I think.


2. Although it seems to me it would not be a terribly big deal to code the 
above, there is the question whether it would significantly slow the 
algorithm down to be required to go and read the variable sof_marker[]. My 
instinct is that it would cost practically nothing to do that, but I am 
not the expert on such matters, which is why I put the disclaimer at the 
top. If somebody who knows what he is talking about says this idea causes 
a speed or timing problem, then forget about it. In that case it is better 
to have another function for every camera.


Theodore Kilgore

Re: [PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

2009-11-01 Thread Németh Márton
Theodore Kilgore wrote:
> 
> On Sun, 1 Nov 2009, Németh Márton wrote:
>> Remove struct sd dependency from pac_find_sof() function implementation.
>> This step prepares separation of pac7302 and pac7311 specific parts of
>> struct sd.
> [...]
> But here is the point. The sn9c2028 cameras have a structure which seems 
> similar to the mr97310a cameras. They use a similar decompression 
> algorithm. They have a similar frame header. Specifically, the sn9c2028 
> frame header starts with the five bytes
> 
>  0xff, 0xff, 0x00, 0xc4, 0xc4
> 
> whereas the pac_common frame header starts with the five bytes
> 
>  0xff, 0xff, 0x00, 0xff, 0x96
> 
> Right now, for my own use, I have written a file sn9c2028.h which 
> essentially duplicates the functionality of pac_common.h and contains a 
> function which searches for the sn9c2028 SOF marker instead of searching 
> for the pac SOF marker. Is this necessarily the good, permanent solution? 
> I am not so sure about that.

I think the pac_find_sof() is a special case. To find a SOF sequence in
a bigger buffer in general needs to first analyze the SOF sequence for
repeated bytes. If there are repeated bytes the search have to be
continued in a different way, see the state machine currently in the
pac_common.h. To find the sn9c2028 frame header a different state machine
is needed. It might be possible to implement a search function which
can find any SOF sequence but I am afraid that this algorithm would be
too complicated because of the search string analysis.

> Perhaps when making changes it is a good time to think over the idea of 
> combining things which are in fact not very much different. After all, 
> another set of cameras might come along, too, which essentially requires 
> yet another minor variation on the same basic algorithm. Then we are 
> supposed to have three .h files with three functions which have the same 
> code and just search for slightly different strings?
> 
> I am well aware that you started out to do something different, but how 
> does this strike you?

I was also thinking about not just duplicate the code but find functions
which are similar. My thinking was that first I try to separate the
pac7302 and pac7311 subdrivers and get feedback. If this change was
accepted I would look for common functions not only in pac7302 and pac7311
but also in the gspca family of subdrivers.

My first candidate would be the low level reg_w*() and reg_r*() functions.
I haven't finished the analysis but it seems that most of the time the
usb_control_msg() parameters are the same except the request and
requesttype parameter. The request contains a number specific to the
device. The requesttype usually contains USB_RECIP_DEVICE or
USB_RECIP_INTERFACE. This means that these function can be extracted
to a common helper module or to gspca_main and introduce the request
and requesttype values somehow to struct sd_desc in gspca.h.

Regards,

Márton Németh

--
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: [PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

2009-11-01 Thread Theodore Kilgore



On Sun, 1 Nov 2009, Németh Márton wrote:


From: Márton Németh 

Remove struct sd dependency from pac_find_sof() function implementation.
This step prepares separation of pac7302 and pac7311 specific parts of
struct sd.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 




Szia Marton,

As long as these things work, I would not mind at all. But perhaps this is 
a good occasion to bring up an issue which seems to me very much related. 
It is the following:


Along with the (it seems to be never-ending) work on the mr97310a driver, 
I have been working on a driver for the sn9c2028 cameras. The driver at 
this point functions, and seems to function quite well. But it also seems 
to me that the code needs quite a bit of polishing before it is 
publicized. Since I have been very much preoccupied with finishing the 
mr97310a driver (why does the last 5% of a job sometimes take the most 
time?) this final polishing of the sn9c2028 driver has not yet occurred, 
sorry to say.


But here is the point. The sn9c2028 cameras have a structure which seems 
similar to the mr97310a cameras. They use a similar decompression 
algorithm. They have a similar frame header. Specifically, the sn9c2028 
frame header starts with the five bytes


0xff, 0xff, 0x00, 0xc4, 0xc4

whereas the pac_common frame header starts with the five bytes

0xff, 0xff, 0x00, 0xff, 0x96

Right now, for my own use, I have written a file sn9c2028.h which 
essentially duplicates the functionality of pac_common.h and contains a 
function which searches for the sn9c2028 SOF marker instead of searching 
for the pac SOF marker. Is this necessarily the good, permanent solution? 
I am not so sure about that.


Perhaps when making changes it is a good time to think over the idea of 
combining things which are in fact not very much different. After all, 
another set of cameras might come along, too, which essentially requires 
yet another minor variation on the same basic algorithm. Then we are 
supposed to have three .h files with three functions which have the same 
code and just search for slightly different strings?


I am well aware that you started out to do something different, but how 
does this strike you?



Theodore Kilgore

[PATCH 3/3] gspca pac7302/pac7311: separate the two subdrivers

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

All PAC7311 specific functions remain in pac7311.c. All PAC7302 specific
functions are moved to pac7302.c. The USB device table is also divided into
two parts. This makes it possible to remove the sensor specific decisions
from different functions and also remove sensor infromation from the USB
device table.

The common functions are just copied to both subdrivers. These common
functions can be separated later to a common file or helper module.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN c/drivers/media/video/gspca/Kconfig 
d/drivers/media/video/gspca/Kconfig
--- c/drivers/media/video/gspca/Kconfig 2009-10-30 16:12:05.0 +0100
+++ d/drivers/media/video/gspca/Kconfig 2009-11-01 06:58:14.0 +0100
@@ -104,6 +104,15 @@ config USB_GSPCA_PAC207
  To compile this driver as a module, choose M here: the
  module will be called gspca_pac207.

+config USB_GSPCA_PAC7302
+   tristate "Pixart PAC7302 USB Camera Driver"
+   depends on VIDEO_V4L2 && USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the PAC7302 chip.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_pac7302.
+
 config USB_GSPCA_PAC7311
    tristate "Pixart PAC7311 USB Camera Driver"
depends on VIDEO_V4L2 && USB_GSPCA
diff -uprN c/drivers/media/video/gspca/Makefile 
d/drivers/media/video/gspca/Makefile
--- c/drivers/media/video/gspca/Makefile2009-11-01 18:24:03.0 
+0100
+++ d/drivers/media/video/gspca/Makefile2009-11-01 06:58:14.0 
+0100
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB_GSPCA_MR97310A) += gspc
 obj-$(CONFIG_USB_GSPCA_OV519)+= gspca_ov519.o
 obj-$(CONFIG_USB_GSPCA_OV534)+= gspca_ov534.o
 obj-$(CONFIG_USB_GSPCA_PAC207)   += gspca_pac207.o
+obj-$(CONFIG_USB_GSPCA_PAC7302)  += gspca_pac7302.o
 obj-$(CONFIG_USB_GSPCA_PAC7311)  += gspca_pac7311.o
 obj-$(CONFIG_USB_GSPCA_SN9C20X)  += gspca_sn9c20x.o
 obj-$(CONFIG_USB_GSPCA_SONIXB)   += gspca_sonixb.o
@@ -38,6 +39,7 @@ gspca_mr97310a-objs := mr97310a.o
 gspca_ov519-objs:= ov519.o
 gspca_ov534-objs:= ov534.o
 gspca_pac207-objs   := pac207.o
+gspca_pac7302-objs  := pac7302.o
 gspca_pac7311-objs  := pac7311.o
 gspca_sn9c20x-objs  := sn9c20x.o
 gspca_sonixb-objs   := sonixb.o
diff -uprN c/drivers/media/video/gspca/pac7302.c 
d/drivers/media/video/gspca/pac7302.c
--- c/drivers/media/video/gspca/pac7302.c   1970-01-01 01:00:00.0 
+0100
+++ d/drivers/media/video/gspca/pac7302.c   2009-11-01 18:23:02.0 
+0100
@@ -0,0 +1,976 @@
+/*
+ * Pixart PAC7302 library
+ * Copyright (C) 2005 Thomas Kaiser tho...@kaiser-linux.li
+ *
+ * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
+ *
+ * Separated from Pixart PAC7311 library by 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* Some documentation about various registers as determined by trial and error.
+   When the register addresses differ between the 7202 and the 7311 the 2
+   different addresses are written as 7302addr/7311addr, when one of the 2
+   addresses is a - sign that register description is not valid for the
+   matching IC.
+
+   Register page 1:
+
+   Address Description
+   -/0x08  Unknown compressor related, must always be 8 except when not
+   in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 !
+   -/0x1b  Auto white balance related, bit 0 is AWB enable (inverted)
+   bits 345 seem to toggle per color gains on/off (inverted)
+   0x78Global control, bit 6 controls the LED (inverted)
+   -/0x80  JPEG compression ratio ? Best not touched
+
+   Register page 3/4:
+
+   Address Description
+   0x02Clock divider 2-63, fps =~ 60 / val. Must be a multiple 
of 3 on
+   the 7302, so one of 3, 6, 9, ..., except when between 6 and 12?
+   -/0x0f  Master gain 1-245, low value = high gain
+   0x10/-  Master gain 0-31
+   -/0x10  Another gain 0-15, limited influence (1-2x gain I guess)
+   0x21Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 
unused
+   -/0x27  Seems to toggle various gains on / off, Sett

[PATCH 2/3] gspca pac7302/pac7311: extract pac_start_frame

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

Creating the start of the frame is done in the same way for pac7302
and for pac7311. Extract this common part to the pac_start_frame()
function.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN b/drivers/media/video/gspca/pac7311.c 
c/drivers/media/video/gspca/pac7311.c
--- b/drivers/media/video/gspca/pac7311.c   2009-11-01 18:11:22.0 
+0100
+++ c/drivers/media/video/gspca/pac7311.c   2009-11-01 18:16:41.0 
+0100
@@ -816,7 +816,7 @@ static void do_autogain(struct gspca_dev
 }

 /* JPEG header, part 1 */
-static const unsigned char pac7311_jpeg_header1[] = {
+static const unsigned char pac_jpeg_header1[] = {
   0xff, 0xd8,  /* SOI: Start of Image */

   0xff, 0xc0,  /* SOF0: Start of Frame (Baseline DCT) */
@@ -827,7 +827,7 @@ static const unsigned char pac7311_jpeg_
 };

 /* JPEG header, continued */
-static const unsigned char pac7311_jpeg_header2[] = {
+static const unsigned char pac_jpeg_header2[] = {
   0x03,/* Number of image components: 3 */
   0x01, 0x21, 0x00,/* ID=1, Subsampling 1x1, Quantization table: 0 */
   0x02, 0x11, 0x01,/* ID=2, Subsampling 2x1, Quantization table: 1 */
@@ -843,6 +843,26 @@ static const unsigned char pac7311_jpeg_
   0x00 /* Successive approximation: 0 */
 };

+static void pac_start_frame(struct gspca_dev *gspca_dev,
+   struct gspca_frame *frame,
+   __u16 lines, __u16 samples_per_line)
+{
+   unsigned char tmpbuf[4];
+
+   gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
+   pac_jpeg_header1, sizeof(pac_jpeg_header1));
+
+   tmpbuf[0] = lines >> 8;
+   tmpbuf[1] = lines & 0xff;
+   tmpbuf[2] = samples_per_line >> 8;
+   tmpbuf[3] = samples_per_line & 0xff;
+
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+   tmpbuf, sizeof(tmpbuf));
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+   pac_jpeg_header2, sizeof(pac_jpeg_header2));
+}
+
 /* this function is run at interrupt level */
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
struct gspca_frame *frame,  /* target */
@@ -854,7 +874,6 @@ static void sd_pkt_scan(struct gspca_dev

sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
-   unsigned char tmpbuf[4];
int n, lum_offset, footer_length;

if (sd->sensor == SENSOR_PAC7302) {
@@ -896,23 +915,14 @@ static void sd_pkt_scan(struct gspca_dev
atomic_set(&sd->avg_lum, -1);

/* Start the new frame with the jpeg header */
-   gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
-   pac7311_jpeg_header1, sizeof(pac7311_jpeg_header1));
if (sd->sensor == SENSOR_PAC7302) {
/* The PAC7302 has the image rotated 90 degrees */
-   tmpbuf[0] = gspca_dev->width >> 8;
-   tmpbuf[1] = gspca_dev->width & 0xff;
-   tmpbuf[2] = gspca_dev->height >> 8;
-   tmpbuf[3] = gspca_dev->height & 0xff;
+   pac_start_frame(gspca_dev, frame,
+   gspca_dev->width, gspca_dev->height);
} else {
-   tmpbuf[0] = gspca_dev->height >> 8;
-   tmpbuf[1] = gspca_dev->height & 0xff;
-   tmpbuf[2] = gspca_dev->width >> 8;
-   tmpbuf[3] = gspca_dev->width & 0xff;
+   pac_start_frame(gspca_dev, frame,
+   gspca_dev->height, gspca_dev->width);
}
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame, tmpbuf, 4);
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
-   pac7311_jpeg_header2, sizeof(pac7311_jpeg_header2));
}
gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
 }
--
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: [PATCH 00/21] gspca pac7302/pac7311: separate the two drivers

2009-11-01 Thread Németh Márton
Jean-Francois Moine wrote:
> On Sun, 01 Nov 2009 00:13:10 +0100
> Németh Márton  wrote:
> 
>> the following patchset refactores the Pixart PAC7311 subdriver. The
>> current situation is that the code contains a lot of decisions
>> like this:
>>
>> if (sd->sensor == SENSOR_PAC7302) {
>> ... do this ...
>> } else {
>> ... do something else ...
>> }
>>
>> The sensor type is determined using the USB Vendor ID and Product
>> ID which means that the decisions shown are not really necessary.
>>
>> The goal of the patchset is to have a PAC7302 and a PAC7311 subdriver
>> which have the benefit that there is no decision necessary on sensor
>> type at runtime. The common functions can be extracted later but this
>> would be a different patchset.
> 
> Splitting the pac7311 subdriver is a good idea, but I don't like your
> patchset: a lot of changes (function prefixes) are nullified by the
> last patch. I'd better like only one change for the pac7302 creation
> and a second one for the interface change of pac_find_sof() in
> pac_common.h (BTW, this file could now be compiled separately).

Hello Jef,

thank you for the feedback, I'll try to send a patch set wich contains
bigger steps. I hope the separation will be not a too big step and won't
make it too difficult to bisect any possible problem I might introduce
with this change. But hope for the best and imagine the easy way when
no regression was introduced.

I am also thinking about finding the common functions which can be
compiled separately either in a helper module or to gspca_main maybe.
But first I focus on the pac7302/pac7311 separation.

Márton Németh
--
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


[PATCH 1/3] gspca pac7302/pac7311: simplify pac_find_sof

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

Remove struct sd dependency from pac_find_sof() function implementation.
This step prepares separation of pac7302 and pac7311 specific parts of
struct sd.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN a/drivers/media/video/gspca/mr97310a.c 
b/drivers/media/video/gspca/mr97310a.c
--- a/drivers/media/video/gspca/mr97310a.c  2009-11-01 06:49:29.0 
+0100
+++ b/drivers/media/video/gspca/mr97310a.c  2009-11-01 18:11:22.0 
+0100
@@ -1034,9 +1034,10 @@ static void sd_pkt_scan(struct gspca_dev
__u8 *data,   /* isoc packet */
int len)  /* iso packet length */
 {
+   struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
int n;

diff -uprN a/drivers/media/video/gspca/pac207.c 
b/drivers/media/video/gspca/pac207.c
--- a/drivers/media/video/gspca/pac207.c2009-10-30 16:12:05.0 
+0100
+++ b/drivers/media/video/gspca/pac207.c2009-11-01 18:11:22.0 
+0100
@@ -344,7 +344,7 @@ static void sd_pkt_scan(struct gspca_dev
struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
int n;

diff -uprN a/drivers/media/video/gspca/pac7311.c 
b/drivers/media/video/gspca/pac7311.c
--- a/drivers/media/video/gspca/pac7311.c   2009-11-01 06:51:38.0 
+0100
+++ b/drivers/media/video/gspca/pac7311.c   2009-11-01 18:11:22.0 
+0100
@@ -852,7 +852,7 @@ static void sd_pkt_scan(struct gspca_dev
struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
unsigned char tmpbuf[4];
int n, lum_offset, footer_length;
diff -uprN a/drivers/media/video/gspca/pac_common.h 
b/drivers/media/video/gspca/pac_common.h
--- a/drivers/media/video/gspca/pac_common.h2009-10-30 16:12:05.0 
+0100
+++ b/drivers/media/video/gspca/pac_common.h2009-11-01 18:11:22.0 
+0100
@@ -72,42 +72,41 @@ static const unsigned char pac_sof_marke
   +--+
 */

-static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev,
+static unsigned char *pac_find_sof(u8 *sof_read,
unsigned char *m, int len)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
int i;

/* Search for the SOF marker (fixed part) in the header */
for (i = 0; i < len; i++) {
-   switch (sd->sof_read) {
+   switch (*sof_read) {
case 0:
if (m[i] == 0xff)
-   sd->sof_read = 1;
+   *sof_read = 1;
break;
case 1:
if (m[i] == 0xff)
-   sd->sof_read = 2;
+   *sof_read = 2;
else
-   sd->sof_read = 0;
+   *sof_read = 0;
break;
case 2:
switch (m[i]) {
case 0x00:
-   sd->sof_read = 3;
+   *sof_read = 3;
break;
case 0xff:
/* stay in this state */
break;
default:
-   sd->sof_read = 0;
+   *sof_read = 0;
}
break;
case 3:
if (m[i] == 0xff)
-   sd->sof_read = 4;
+   *sof_read = 4;
else
-   sd->sof_read = 0;
+   *sof_read = 0;
break;
case 4:
switch (m[i]) {
@@ -117,18 +116,18 @@ static unsigned char *pac_find_sof(struc
"SOF found, bytes to analyze: %u."
" Frame starts at byte #%u",
len, i + 1);
-   sd->sof_read = 0;
+   *sof_read = 0;
return m + i + 1;
break;
case 0xff:
-   sd->sof_read = 2;
+ 

Re: [PATCH 00/21] gspca pac7302/pac7311: separate the two drivers

2009-11-01 Thread Jean-Francois Moine
On Sun, 01 Nov 2009 00:13:10 +0100
Németh Márton  wrote:

> the following patchset refactores the Pixart PAC7311 subdriver. The
> current situation is that the code contains a lot of decisions
> like this:
> 
> if (sd->sensor == SENSOR_PAC7302) {
> ... do this ...
> } else {
> ... do something else ...
> }
> 
> The sensor type is determined using the USB Vendor ID and Product
> ID which means that the decisions shown are not really necessary.
> 
> The goal of the patchset is to have a PAC7302 and a PAC7311 subdriver
> which have the benefit that there is no decision necessary on sensor
> type at runtime. The common functions can be extracted later but this
> would be a different patchset.

Hello Márton,

Splitting the pac7311 subdriver is a good idea, but I don't like your
patchset: a lot of changes (function prefixes) are nullified by the
last patch. I'd better like only one change for the pac7302 creation
and a second one for the interface change of pac_find_sof() in
pac_common.h (BTW, this file could now be compiled separately).

Regards.

-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
--
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: [PATCH 21/21] gspca pac7302/pac7311: remove prefixes

2009-10-31 Thread Németh Márton
PAC7302},
-   {USB_DEVICE(0x093a, 0x2620), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2621), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2622), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2624), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2626), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2628), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2629), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x262a), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x262c), .driver_info = SENSOR_PAC7302},
+   {USB_DEVICE(0x06f8, 0x3009)},
+   {USB_DEVICE(0x093a, 0x2620)},
+   {USB_DEVICE(0x093a, 0x2621)},
+   {USB_DEVICE(0x093a, 0x2622)},
+   {USB_DEVICE(0x093a, 0x2624)},
+   {USB_DEVICE(0x093a, 0x2626)},
+   {USB_DEVICE(0x093a, 0x2628)},
+   {USB_DEVICE(0x093a, 0x2629)},
+   {USB_DEVICE(0x093a, 0x262a)},
+   {USB_DEVICE(0x093a, 0x262c)},
{}
 };
 MODULE_DEVICE_TABLE(usb, device_table);
@@ -943,8 +941,8 @@ MODULE_DEVICE_TABLE(usb, device_table);
 static int sd_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
-   return gspca_dev_probe(intf, id, &pac7302_sd_desc,
-   sizeof(struct pac7302_sd), THIS_MODULE);
+   return gspca_dev_probe(intf, id, &sd_desc,
+   sizeof(struct sd), THIS_MODULE);
 }

 static struct usb_driver sd_driver = {
diff -uprN u/drivers/media/video/gspca/pac7311.c 
v/drivers/media/video/gspca/pac7311.c
--- u/drivers/media/video/gspca/pac7311.c   2009-11-01 07:00:21.0 
+0100
+++ v/drivers/media/video/gspca/pac7311.c   2009-11-01 07:01:47.0 
+0100
@@ -58,7 +58,7 @@ MODULE_DESCRIPTION("Pixart PAC7311");
 MODULE_LICENSE("GPL");

 /* specific webcam descriptor for pac7311 */
-struct pac7311_sd {
+struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */

unsigned char contrast;
@@ -68,8 +68,6 @@ struct pac7311_sd {
__u8 hflip;
__u8 vflip;

-#define SENSOR_PAC7311 1
-
u8 sof_read;
u8 autogain_ignore_frames;

@@ -77,20 +75,20 @@ struct pac7311_sd {
 };

 /* V4L2 controls supported by the driver */
-static int pac7311_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);

-static struct ctrl pac7311_sd_ctrls[] = {
+static struct ctrl sd_ctrls[] = {
 /* This control is for both the 7302 and the 7311 */
{
{
@@ -104,8 +102,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define CONTRAST_DEF 127
.default_value = CONTRAST_DEF,
},
-   .set = pac7311_sd_setcontrast,
-   .get = pac7311_sd_getcontrast,
+   .set = sd_setcontrast,
+   .get = sd_getcontrast,
},
 /* All controls below are for both the 7302 and the 7311 */
{
@@ -121,8 +119,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
.default_value = GAIN_DEF,
},
-   .set = pac7311_sd_setgain,
-   .get = pac7311_sd_getgain,
+   .set = sd_setgain,
+   .get = sd_getgain,
},
{
{
@@ -137,8 +135,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #

[PATCH 21/21] gspca pac7302/pac7311: remove prefixes

2009-10-31 Thread Németh Márton
PAC7302},
-   {USB_DEVICE(0x093a, 0x2621), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2622), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2624), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2626), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x2629), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x262a), .driver_info = SENSOR_PAC7302},
-   {USB_DEVICE(0x093a, 0x262c), .driver_info = SENSOR_PAC7302},
+   {USB_DEVICE(0x06f8, 0x3009)},
+   {USB_DEVICE(0x093a, 0x2620)},
+   {USB_DEVICE(0x093a, 0x2621)},
+   {USB_DEVICE(0x093a, 0x2622)},
+   {USB_DEVICE(0x093a, 0x2624)},
+   {USB_DEVICE(0x093a, 0x2626)},
+   {USB_DEVICE(0x093a, 0x2629)},
+   {USB_DEVICE(0x093a, 0x262a)},
+   {USB_DEVICE(0x093a, 0x262c)},
{}
 };
 MODULE_DEVICE_TABLE(usb, device_table);
@@ -942,8 +940,8 @@ MODULE_DEVICE_TABLE(usb, device_table);
 static int sd_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
-   return gspca_dev_probe(intf, id, &pac7302_sd_desc,
-   sizeof(struct pac7302_sd), THIS_MODULE);
+   return gspca_dev_probe(intf, id, &sd_desc,
+   sizeof(struct sd), THIS_MODULE);
 }

 static struct usb_driver sd_driver = {
diff -uprN u/drivers/media/video/gspca/pac7311.c 
v/drivers/media/video/gspca/pac7311.c
--- u/drivers/media/video/gspca/pac7311.c   2009-10-31 10:15:12.0 
+0100
+++ v/drivers/media/video/gspca/pac7311.c   2009-10-31 15:23:20.0 
+0100
@@ -58,7 +58,7 @@ MODULE_DESCRIPTION("Pixart PAC7311");
 MODULE_LICENSE("GPL");

 /* specific webcam descriptor for pac7311 */
-struct pac7311_sd {
+struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */

unsigned char contrast;
@@ -68,8 +68,6 @@ struct pac7311_sd {
__u8 hflip;
__u8 vflip;

-#define SENSOR_PAC7311 1
-
u8 sof_read;
u8 autogain_ignore_frames;

@@ -77,20 +75,20 @@ struct pac7311_sd {
 };

 /* V4L2 controls supported by the driver */
-static int pac7311_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
-static int pac7311_sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
-static int pac7311_sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);

-static struct ctrl pac7311_sd_ctrls[] = {
+static struct ctrl sd_ctrls[] = {
 /* This control is for both the 7302 and the 7311 */
{
{
@@ -104,8 +102,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define CONTRAST_DEF 127
.default_value = CONTRAST_DEF,
},
-   .set = pac7311_sd_setcontrast,
-   .get = pac7311_sd_getcontrast,
+   .set = sd_setcontrast,
+   .get = sd_getcontrast,
},
 /* All controls below are for both the 7302 and the 7311 */
{
@@ -121,8 +119,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
.default_value = GAIN_DEF,
},
-   .set = pac7311_sd_setgain,
-   .get = pac7311_sd_getgain,
+   .set = sd_setgain,
+   .get = sd_getgain,
},
{
{
@@ -137,8 +135,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
.default_value = EXPOSURE_DEF,
},
-   .set = pac7311_sd_setexposure,
-   .get = pa

[PATCH 19/21] gspca pac7302/pac7311: extract pac_start_frame

2009-10-31 Thread Németh Márton
From: Márton Németh 

Creating the start of the frame is done in the same way for pac7302
and for pac7311. Extract this common part to the pac_start_frame()
function.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN s/drivers/media/video/gspca/pac7311.c 
t/drivers/media/video/gspca/pac7311.c
--- s/drivers/media/video/gspca/pac7311.c   2009-10-31 10:21:55.0 
+0100
+++ t/drivers/media/video/gspca/pac7311.c   2009-10-31 10:20:49.0 
+0100
@@ -1028,7 +1028,7 @@ static void pac7311_do_autogain(struct g
 }

 /* JPEG header, part 1 */
-static const unsigned char pac7311_jpeg_header1[] = {
+static const unsigned char pac_jpeg_header1[] = {
   0xff, 0xd8,  /* SOI: Start of Image */

   0xff, 0xc0,  /* SOF0: Start of Frame (Baseline DCT) */
@@ -1039,7 +1039,7 @@ static const unsigned char pac7311_jpeg_
 };

 /* JPEG header, continued */
-static const unsigned char pac7311_jpeg_header2[] = {
+static const unsigned char pac_jpeg_header2[] = {
   0x03,/* Number of image components: 3 */
   0x01, 0x21, 0x00,/* ID=1, Subsampling 1x1, Quantization table: 0 */
   0x02, 0x11, 0x01,/* ID=2, Subsampling 2x1, Quantization table: 1 */
@@ -1055,6 +1055,26 @@ static const unsigned char pac7311_jpeg_
   0x00 /* Successive approximation: 0 */
 };

+static void pac_start_frame(struct gspca_dev *gspca_dev,
+   struct gspca_frame *frame,
+   __u16 lines, __u16 samples_per_line)
+{
+   unsigned char tmpbuf[4];
+
+   gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
+   pac_jpeg_header1, sizeof(pac_jpeg_header1));
+
+   tmpbuf[0] = lines >> 8;
+   tmpbuf[1] = lines & 0xff;
+   tmpbuf[2] = samples_per_line >> 8;
+   tmpbuf[3] = samples_per_line & 0xff;
+
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+   tmpbuf, sizeof(tmpbuf));
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+   pac_jpeg_header2, sizeof(pac_jpeg_header2));
+}
+
 /* this function is run at interrupt level */
 static void pac7302_sd_pkt_scan(struct gspca_dev *gspca_dev,
struct gspca_frame *frame,  /* target */
@@ -1066,7 +1086,6 @@ static void pac7302_sd_pkt_scan(struct g

sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
-   unsigned char tmpbuf[4];
int n, lum_offset, footer_length;

/* 6 bytes after the FF D9 EOF marker a number of lumination
@@ -1103,18 +1122,9 @@ static void pac7302_sd_pkt_scan(struct g
atomic_set(&sd->avg_lum, -1);

/* Start the new frame with the jpeg header */
-   gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
-   pac7311_jpeg_header1, sizeof(pac7311_jpeg_header1));
-
/* The PAC7302 has the image rotated 90 degrees */
-   tmpbuf[0] = gspca_dev->width >> 8;
-   tmpbuf[1] = gspca_dev->width & 0xff;
-   tmpbuf[2] = gspca_dev->height >> 8;
-   tmpbuf[3] = gspca_dev->height & 0xff;
-
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame, tmpbuf, 4);
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
-   pac7311_jpeg_header2, sizeof(pac7311_jpeg_header2));
+   pac_start_frame(gspca_dev, frame,
+   gspca_dev->width, gspca_dev->height);
}
gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
 }
@@ -1130,7 +1140,6 @@ static void pac7311_sd_pkt_scan(struct g

sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
-   unsigned char tmpbuf[4];
int n, lum_offset, footer_length;

/* 6 bytes after the FF D9 EOF marker a number of lumination
@@ -1167,17 +1176,8 @@ static void pac7311_sd_pkt_scan(struct g
atomic_set(&sd->avg_lum, -1);

/* Start the new frame with the jpeg header */
-   gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
-   pac7311_jpeg_header1, sizeof(pac7311_jpeg_header1));
-
-   tmpbuf[0] = gspca_dev->height >> 8;
-   tmpbuf[1] = gspca_dev->height & 0xff;
-   tmpbuf[2] = gspca_dev->width >> 8;
-   tmpbuf[3] = gspca_dev->width & 0xff;
-
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame, tmpbuf, 4);
-   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
-   pac7311_jpeg_header2, sizeof(pac7311_jpeg_header2));
+   pac_start_frame(gspca_dev, frame,
+   gspca_dev->height, gspca_dev->width);
}
gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
 }
--
To unsubscribe from this list: send the line &q

[PATCH 18/21] gspca pac7302/pac7311: generalize reg_w_var

2009-10-31 Thread Németh Márton
From: Márton Németh 

The original implementation of reg_w_var contains direct references to pac7302
and 7311 specific structures. Move these references to the parameter list.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN r/drivers/media/video/gspca/pac7311.c 
s/drivers/media/video/gspca/pac7311.c
--- r/drivers/media/video/gspca/pac7311.c   2009-10-31 09:07:56.0 
+0100
+++ s/drivers/media/video/gspca/pac7311.c   2009-10-31 10:21:55.0 
+0100
@@ -602,7 +602,9 @@ static void reg_w_page(struct gspca_dev

 /* output a variable sequence */
 static void reg_w_var(struct gspca_dev *gspca_dev,
-   const __u8 *seq)
+   const __u8 *seq,
+   const __u8 *page3, unsigned int page3_len,
+   const __u8 *page4, unsigned int page4_len)
 {
int index, len;

@@ -613,10 +615,10 @@ static void reg_w_var(struct gspca_dev *
case END_OF_SEQUENCE:
return;
case LOAD_PAGE4:
-   reg_w_page(gspca_dev, page4_7311, sizeof page4_7311);
+   reg_w_page(gspca_dev, page4, page4_len);
break;
case LOAD_PAGE3:
-   reg_w_page(gspca_dev, page3_7302, sizeof page3_7302);
+   reg_w_page(gspca_dev, page3, page3_len);
break;
default:
if (len > USB_BUF_SZ) {
@@ -874,7 +876,9 @@ static int pac7302_sd_start(struct gspca

sd->sof_read = 0;

-   reg_w_var(gspca_dev, start_7302);
+   reg_w_var(gspca_dev, start_7302,
+   page3_7302, sizeof(page3_7302),
+   NULL, 0);
pac7302_setbrightcont(gspca_dev);
pac7302_setcolors(gspca_dev);
pac7302_setgain(gspca_dev);
@@ -900,7 +904,9 @@ static int pac7311_sd_start(struct gspca

sd->sof_read = 0;

-   reg_w_var(gspca_dev, start_7311);
+   reg_w_var(gspca_dev, start_7311,
+   NULL, 0,
+   page4_7311, sizeof(page4_7311));
pac7311_setcontrast(gspca_dev);
pac7311_setgain(gspca_dev);
pac7311_setexposure(gspca_dev);
--
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


[PATCH 17/21] gspca pac7302/pac7311: separate format descriptors

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate supported format descriptors and supported resolutions.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN q/drivers/media/video/gspca/pac7311.c 
r/drivers/media/video/gspca/pac7311.c
--- q/drivers/media/video/gspca/pac7311.c   2009-10-31 08:26:17.0 
+0100
+++ r/drivers/media/video/gspca/pac7311.c   2009-10-31 09:07:56.0 
+0100
@@ -349,7 +349,15 @@ static struct ctrl pac7311_sd_ctrls[] =
},
 };

-static const struct v4l2_pix_format vga_mode[] = {
+static const struct v4l2_pix_format pac7302_vga_mode[] = {
+   {640, 480, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
+   .bytesperline = 640,
+   .sizeimage = 640 * 480 * 3 / 8 + 590,
+   .colorspace = V4L2_COLORSPACE_JPEG,
+   .priv = 0},
+};
+
+static const struct v4l2_pix_format pac7311_vga_mode[] = {
{160, 120, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
.bytesperline = 160,
.sizeimage = 160 * 120 * 3 / 8 + 590,
@@ -642,8 +650,8 @@ static int pac7302_sd_config(struct gspc
cam = &gspca_dev->cam;

PDEBUG(D_CONF, "Find Sensor PAC7302");
-   cam->cam_mode = &vga_mode[2];   /* only 640x480 */
-   cam->nmodes = 1;
+   cam->cam_mode = pac7302_vga_mode;   /* only 640x480 */
+   cam->nmodes = ARRAY_SIZE(pac7302_vga_mode);

sd->brightness = BRIGHTNESS_DEF;
sd->contrast = CONTRAST_DEF;
@@ -666,8 +674,8 @@ static int pac7311_sd_config(struct gspc
cam = &gspca_dev->cam;

PDEBUG(D_CONF, "Find Sensor PAC7311");
-   cam->cam_mode = vga_mode;
-   cam->nmodes = ARRAY_SIZE(vga_mode);
+   cam->cam_mode = pac7311_vga_mode;
+   cam->nmodes = ARRAY_SIZE(pac7311_vga_mode);

sd->contrast = CONTRAST_DEF;
sd->gain = GAIN_DEF;
--
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


[PATCH 16/21] gspca pac7302/pac7311: separate private sd

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the private struct sd where the sensor specific data is stored.
The sensor field is no longer needed because we use separate functions.
Brightness and color fields are not used in pac7311, so removed.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN p/drivers/media/video/gspca/pac7311.c 
q/drivers/media/video/gspca/pac7311.c
--- p/drivers/media/video/gspca/pac7311.c   2009-10-31 08:22:45.0 
+0100
+++ q/drivers/media/video/gspca/pac7311.c   2009-10-31 08:26:17.0 
+0100
@@ -57,8 +57,8 @@ MODULE_AUTHOR("Thomas Kaiser tho...@kais
 MODULE_DESCRIPTION("Pixart PAC7311");
 MODULE_LICENSE("GPL");

-/* specific webcam descriptor */
-struct sd {
+/* specific webcam descriptor for pac7302 */
+struct pac7302_sd {
struct gspca_dev gspca_dev; /* !! must be the first item */

unsigned char brightness;
@@ -70,7 +70,26 @@ struct sd {
__u8 hflip;
__u8 vflip;

-   __u8 sensor;
+#define SENSOR_PAC7302 0
+#define SENSOR_PAC7311 1
+
+   u8 sof_read;
+   u8 autogain_ignore_frames;
+
+   atomic_t avg_lum;
+};
+
+/* specific webcam descriptor for pac7311 */
+struct pac7311_sd {
+   struct gspca_dev gspca_dev; /* !! must be the first item */
+
+   unsigned char contrast;
+   unsigned char gain;
+   unsigned char exposure;
+   unsigned char autogain;
+   __u8 hflip;
+   __u8 vflip;
+
 #define SENSOR_PAC7302 0
 #define SENSOR_PAC7311 1

@@ -617,12 +636,11 @@ static void reg_w_var(struct gspca_dev *
 static int pac7302_sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7302_sd *sd = (struct pac7302_sd *) gspca_dev;
struct cam *cam;

cam = &gspca_dev->cam;

-   sd->sensor = id->driver_info;
PDEBUG(D_CONF, "Find Sensor PAC7302");
cam->cam_mode = &vga_mode[2];   /* only 640x480 */
cam->nmodes = 1;
@@ -642,19 +660,16 @@ static int pac7302_sd_config(struct gspc
 static int pac7311_sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7311_sd *sd = (struct pac7311_sd *) gspca_dev;
struct cam *cam;

cam = &gspca_dev->cam;

-   sd->sensor = id->driver_info;
PDEBUG(D_CONF, "Find Sensor PAC7311");
cam->cam_mode = vga_mode;
cam->nmodes = ARRAY_SIZE(vga_mode);

-   sd->brightness = BRIGHTNESS_DEF;
sd->contrast = CONTRAST_DEF;
-   sd->colors = COLOR_DEF;
sd->gain = GAIN_DEF;
sd->exposure = EXPOSURE_DEF;
sd->autogain = AUTOGAIN_DEF;
@@ -666,7 +681,7 @@ static int pac7311_sd_config(struct gspc
 /* This function is used by pac7302 only */
 static void pac7302_setbrightcont(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7302_sd *sd = (struct pac7302_sd *) gspca_dev;
int i, v;
static const __u8 max[10] =
{0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb,
@@ -693,7 +708,7 @@ static void pac7302_setbrightcont(struct
 /* This function is used by pac7311 only */
 static void pac7311_setcontrast(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7311_sd *sd = (struct pac7311_sd *) gspca_dev;

reg_w(gspca_dev, 0xff, 0x04);
reg_w(gspca_dev, 0x10, sd->contrast >> 4);
@@ -704,7 +719,7 @@ static void pac7311_setcontrast(struct g
 /* This function is used by pac7302 only */
 static void pac7302_setcolors(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7302_sd *sd = (struct pac7302_sd *) gspca_dev;
int i, v;
static const int a[9] =
{217, -212, 0, -101, 170, -67, -38, -315, 355};
@@ -725,7 +740,7 @@ static void pac7302_setcolors(struct gsp

 static void pac7302_setgain(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7302_sd *sd = (struct pac7302_sd *) gspca_dev;

reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
reg_w(gspca_dev, 0x10, sd->gain >> 3);
@@ -736,7 +751,7 @@ static void pac7302_setgain(struct gspca

 static void pac7311_setgain(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7311_sd *sd = (struct pac7311_sd *) gspca_dev;
int gain = GAIN_MAX - sd->gain;

if (gain < 1)
@@ -753,7 +768,7 @@ static void pac7311_setgain(struct gspca

 static void pac7302_setexposure(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   struct pac7302_sd *sd = (struct pac7302_sd *) gspca_dev;

[PATCH 15/21] gspca pac7302/pac7311: simplify pac_find_sof

2009-10-31 Thread Németh Márton
From: Márton Németh 

Remove struct sd dependency from pac_find_sof() function implementation,
This step prepares separation of pac7302 and pac7311 specific parts of
struct sd.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN o/drivers/media/video/gspca/mr97310a.c 
p/drivers/media/video/gspca/mr97310a.c
--- o/drivers/media/video/gspca/mr97310a.c  2009-10-31 08:11:38.0 
+0100
+++ p/drivers/media/video/gspca/mr97310a.c  2009-10-31 08:20:00.0 
+0100
@@ -957,9 +957,10 @@ static void sd_pkt_scan(struct gspca_dev
__u8 *data,   /* isoc packet */
int len)  /* iso packet length */
 {
+   struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
int n;

diff -uprN o/drivers/media/video/gspca/pac207.c 
p/drivers/media/video/gspca/pac207.c
--- o/drivers/media/video/gspca/pac207.c2009-10-23 07:07:59.0 
+0200
+++ p/drivers/media/video/gspca/pac207.c2009-10-31 08:18:59.0 
+0100
@@ -344,7 +344,7 @@ static void sd_pkt_scan(struct gspca_dev
struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
int n;

diff -uprN o/drivers/media/video/gspca/pac7311.c 
p/drivers/media/video/gspca/pac7311.c
--- o/drivers/media/video/gspca/pac7311.c   2009-10-31 07:45:27.0 
+0100
+++ p/drivers/media/video/gspca/pac7311.c   2009-10-31 08:22:45.0 
+0100
@@ -1035,7 +1035,7 @@ static void pac7302_sd_pkt_scan(struct g
struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
unsigned char tmpbuf[4];
int n, lum_offset, footer_length;
@@ -1099,7 +1099,7 @@ static void pac7311_sd_pkt_scan(struct g
struct sd *sd = (struct sd *) gspca_dev;
unsigned char *sof;

-   sof = pac_find_sof(gspca_dev, data, len);
+   sof = pac_find_sof(&sd->sof_read, data, len);
if (sof) {
unsigned char tmpbuf[4];
int n, lum_offset, footer_length;
diff -uprN o/drivers/media/video/gspca/pac_common.h 
p/drivers/media/video/gspca/pac_common.h
--- o/drivers/media/video/gspca/pac_common.h2009-10-30 16:12:05.0 
+0100
+++ p/drivers/media/video/gspca/pac_common.h2009-10-31 08:17:38.0 
+0100
@@ -72,42 +72,41 @@ static const unsigned char pac_sof_marke
   +--+
 */

-static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev,
+static unsigned char *pac_find_sof(u8 *sof_read,
unsigned char *m, int len)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
int i;

/* Search for the SOF marker (fixed part) in the header */
for (i = 0; i < len; i++) {
-   switch (sd->sof_read) {
+   switch (*sof_read) {
case 0:
if (m[i] == 0xff)
-   sd->sof_read = 1;
+   *sof_read = 1;
break;
case 1:
if (m[i] == 0xff)
-   sd->sof_read = 2;
+   *sof_read = 2;
else
-   sd->sof_read = 0;
+   *sof_read = 0;
break;
case 2:
switch (m[i]) {
case 0x00:
-   sd->sof_read = 3;
+   *sof_read = 3;
break;
case 0xff:
/* stay in this state */
break;
default:
-   sd->sof_read = 0;
+   *sof_read = 0;
}
break;
case 3:
if (m[i] == 0xff)
-   sd->sof_read = 4;
+   *sof_read = 4;
else
-   sd->sof_read = 0;
+   *sof_read = 0;
break;
case 4:
switch (m[i]) {
@@ -117,18 +116,18 @@ static unsigned char *pac_find_sof(struc
"SOF found, bytes to analyze: %u."
" Frame s

[PATCH 14/21] gspca pac7302/pac7311: separate exposure

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the exposure control. Remove the run-time
decision for PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN n/drivers/media/video/gspca/pac7311.c 
o/drivers/media/video/gspca/pac7311.c
--- n/drivers/media/video/gspca/pac7311.c   2009-10-31 07:38:45.0 
+0100
+++ o/drivers/media/video/gspca/pac7311.c   2009-10-31 07:45:27.0 
+0100
@@ -105,8 +105,10 @@ static int pac7302_sd_setgain(struct gsp
 static int pac7311_sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
 static int pac7311_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);

 static struct ctrl pac7302_sd_ctrls[] = {
 /* This control is pac7302 only */
@@ -187,8 +189,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
.default_value = EXPOSURE_DEF,
},
-   .set = sd_setexposure,
-   .get = sd_getexposure,
+   .set = pac7302_sd_setexposure,
+   .get = pac7302_sd_getexposure,
},
{
{
@@ -281,8 +283,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
.default_value = EXPOSURE_DEF,
},
-   .set = sd_setexposure,
-   .get = sd_getexposure,
+   .set = pac7311_sd_setexposure,
+   .get = pac7311_sd_getexposure,
},
{
{
@@ -749,7 +751,7 @@ static void pac7311_setgain(struct gspca
reg_w(gspca_dev, 0x11, 0x01);
 }

-static void setexposure(struct gspca_dev *gspca_dev)
+static void pac7302_setexposure(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;
__u8 reg;
@@ -763,25 +765,42 @@ static void setexposure(struct gspca_dev
else if (reg > 63)
reg = 63;

-   if (sd->sensor == SENSOR_PAC7302) {
-   /* On the pac7302 reg2 MUST be a multiple of 3, so round it to
-  the nearest multiple of 3, except when between 6 and 12? */
-   if (reg < 6 || reg > 12)
-   reg = ((reg + 1) / 3) * 3;
-   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
-   reg_w(gspca_dev, 0x02, reg);
-   } else {
-   reg_w(gspca_dev, 0xff, 0x04);   /* page 4 */
-   reg_w(gspca_dev, 0x02, reg);
-   /* Page 1 register 8 must always be 0x08 except when not in
-  640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */
-   reg_w(gspca_dev, 0xff, 0x01);
-   if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
-   reg <= 3)
-   reg_w(gspca_dev, 0x08, 0x09);
-   else
-   reg_w(gspca_dev, 0x08, 0x08);
-   }
+   /* On the pac7302 reg2 MUST be a multiple of 3, so round it to
+  the nearest multiple of 3, except when between 6 and 12? */
+   if (reg < 6 || reg > 12)
+   reg = ((reg + 1) / 3) * 3;
+   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
+   reg_w(gspca_dev, 0x02, reg);
+
+   /* load registers to sensor (Bit 0, auto clear) */
+   reg_w(gspca_dev, 0x11, 0x01);
+}
+
+static void pac7311_setexposure(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   __u8 reg;
+
+   /* register 2 of frame 3/4 contains the clock divider configuring the
+  no fps according to the formula: 60 / reg. sd->exposure is the
+  desired exposure time in ms. */
+   reg = 120 * sd->exposure / 1000;
+   if (reg < 2)
+   reg = 2;
+   else if (reg > 63)
+   reg = 63;
+
+   reg_w(gspca_dev, 0xff, 0x04);   /* page 4 */
+   reg_w(gspca_dev, 0x02, reg);
+   /* Page 1 register 8 must always be 0x08 except when not in
+  640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */
+   reg_w(gspca_dev, 0xff, 0x01);
+   if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
+   reg <= 3)
+   reg_w(gspca_dev, 0x08, 0x09);
+   else
+   reg_w(gspca_dev, 0x08, 0x08);
+
/* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01);
 }
@@ -836,7 +855,7 @@ static int pac7302_sd_start(struct gsp

[PATCH 13/21] gspca pac7302/pac7311: separate gain/autogain control

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the gain and autogain controls. Remove the run-time
decision for PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN m/drivers/media/video/gspca/pac7311.c 
n/drivers/media/video/gspca/pac7311.c
--- m/drivers/media/video/gspca/pac7311.c   2009-10-31 07:29:51.0 
+0100
+++ n/drivers/media/video/gspca/pac7311.c   2009-10-31 07:38:45.0 
+0100
@@ -89,8 +89,10 @@ static int pac7302_sd_getcontrast(struct
 static int pac7311_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
 static int pac7302_sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
 static int pac7302_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7311_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
@@ -99,8 +101,10 @@ static int pac7302_sd_setvflip(struct gs
 static int pac7311_sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
 static int pac7311_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);

@@ -167,8 +171,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
.default_value = GAIN_DEF,
},
-   .set = sd_setgain,
-   .get = sd_getgain,
+   .set = pac7302_sd_setgain,
+   .get = pac7302_sd_getgain,
},
{
{
@@ -197,8 +201,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define AUTOGAIN_DEF 1
.default_value = AUTOGAIN_DEF,
},
-   .set = sd_setautogain,
-   .get = sd_getautogain,
+   .set = pac7302_sd_setautogain,
+   .get = pac7302_sd_getautogain,
},
{
{
@@ -261,8 +265,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
.default_value = GAIN_DEF,
},
-   .set = sd_setgain,
-   .get = sd_getgain,
+   .set = pac7311_sd_setgain,
+   .get = pac7311_sd_getgain,
},
{
{
@@ -291,8 +295,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define AUTOGAIN_DEF 1
.default_value = AUTOGAIN_DEF,
},
-   .set = sd_setautogain,
-   .get = sd_getautogain,
+   .set = pac7311_sd_setautogain,
+   .get = pac7311_sd_getautogain,
},
{
{
@@ -717,23 +721,30 @@ static void pac7302_setcolors(struct gsp
PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors);
 }

-static void setgain(struct gspca_dev *gspca_dev)
+static void pac7302_setgain(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;

-   if (sd->sensor == SENSOR_PAC7302) {
-   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
-   reg_w(gspca_dev, 0x10, sd->gain >> 3);
-   } else {
-   int gain = GAIN_MAX - sd->gain;
-   if (gain < 1)
-   gain = 1;
-   else if (gain > 245)
-   gain = 245;
-   reg_w(gspca_dev, 0xff, 0x04);   /* page 4 */
-   reg_w(gspca_dev, 0x0e, 0x00);
-   reg_w(gspca_dev, 0x0f, gain);
-   }
+   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
+   reg_w(gspca_dev, 0x10, sd->gain >> 3);
+
+   /* load registers to sensor (Bit 0, auto clear) */
+   reg_w(gspca_dev, 0x11, 0x01);
+}
+
+static void pac7311_setgain(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   int gain = GAIN_MAX - sd->gain;
+
+   if (gain < 1)
+   gain = 1;
+   else if (gain > 245)

[PATCH 12/21] gspca pac7302/pac7311: separate hvflip

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the horizontal and vertical flip control. Remove the run-time
decision for PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN l/drivers/media/video/gspca/pac7311.c 
m/drivers/media/video/gspca/pac7311.c
--- l/drivers/media/video/gspca/pac7311.c   2009-10-31 07:21:22.0 
+0100
+++ m/drivers/media/video/gspca/pac7311.c   2009-10-31 07:29:51.0 
+0100
@@ -91,10 +91,14 @@ static int pac7302_sd_setcolors(struct g
 static int pac7302_sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
@@ -207,8 +211,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define HFLIP_DEF 0
.default_value = HFLIP_DEF,
},
-   .set = sd_sethflip,
-   .get = sd_gethflip,
+   .set = pac7302_sd_sethflip,
+   .get = pac7302_sd_gethflip,
},
{
{
@@ -221,8 +225,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define VFLIP_DEF 0
.default_value = VFLIP_DEF,
},
-   .set = sd_setvflip,
-   .get = sd_getvflip,
+   .set = pac7302_sd_setvflip,
+   .get = pac7302_sd_getvflip,
},
 };

@@ -301,8 +305,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define HFLIP_DEF 0
.default_value = HFLIP_DEF,
},
-   .set = sd_sethflip,
-   .get = sd_gethflip,
+   .set = pac7311_sd_sethflip,
+   .get = pac7311_sd_gethflip,
},
{
{
@@ -315,8 +319,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define VFLIP_DEF 0
.default_value = VFLIP_DEF,
},
-   .set = sd_setvflip,
-   .get = sd_getvflip,
+   .set = pac7311_sd_setvflip,
+   .get = pac7311_sd_getvflip,
},
 };

@@ -771,20 +775,25 @@ static void setexposure(struct gspca_dev
reg_w(gspca_dev, 0x11, 0x01);
 }

-static void sethvflip(struct gspca_dev *gspca_dev)
+static void pac7302_sethvflip(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;
__u8 data;

-   if (sd->sensor == SENSOR_PAC7302) {
-   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
-   data = (sd->hflip ? 0x08 : 0x00)
-   | (sd->vflip ? 0x04 : 0x00);
-   } else {
-   reg_w(gspca_dev, 0xff, 0x04);   /* page 4 */
-   data = (sd->hflip ? 0x04 : 0x00)
-   | (sd->vflip ? 0x08 : 0x00);
-   }
+   reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
+   data = (sd->hflip ? 0x08 : 0x00) | (sd->vflip ? 0x04 : 0x00);
+   reg_w(gspca_dev, 0x21, data);
+   /* load registers to sensor (Bit 0, auto clear) */
+   reg_w(gspca_dev, 0x11, 0x01);
+}
+
+static void pac7311_sethvflip(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   __u8 data;
+
+   reg_w(gspca_dev, 0xff, 0x04);   /* page 4 */
+   data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00);
reg_w(gspca_dev, 0x21, data);
/* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01);
@@ -817,7 +826,7 @@ static int pac7302_sd_start(struct gspca
pac7302_setcolors(gspca_dev);
setgain(gspca_dev);
setexposure(gspca_dev);
-   sethvflip(gspca_dev);
+   pac7302_sethvflip(gspca_dev);

/* only resolution 640x480 is supported for pac7302 */

@@ -842,7 +851,7 @@ static int pac7311_sd_start(struct gspca
pac7311_setcontrast(gspca_dev);
setgain(gspca_dev);
setexposure(gspca_dev);
-   sethvflip(gspca_dev);
+   pac7311_sethvflip(gspca_dev);

/* set correct r

[PATCH 11/21] gspca pac7302/pac7311: separate contrast control

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the contrast control. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN k/drivers/media/video/gspca/pac7311.c 
l/drivers/media/video/gspca/pac7311.c
--- k/drivers/media/video/gspca/pac7311.c   2009-10-31 07:13:44.0 
+0100
+++ l/drivers/media/video/gspca/pac7311.c   2009-10-31 07:21:22.0 
+0100
@@ -83,8 +83,10 @@ struct sd {
 /* V4L2 controls supported by the driver */
 static int pac7302_sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7311_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7311_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
 static int pac7302_sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
 static int pac7302_sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
@@ -128,8 +130,8 @@ static struct ctrl pac7302_sd_ctrls[] =
 #define CONTRAST_DEF 127
.default_value = CONTRAST_DEF,
},
-   .set = sd_setcontrast,
-   .get = sd_getcontrast,
+   .set = pac7302_sd_setcontrast,
+   .get = pac7302_sd_getcontrast,
},
 /* This control is pac7302 only */
{
@@ -238,8 +240,8 @@ static struct ctrl pac7311_sd_ctrls[] =
 #define CONTRAST_DEF 127
.default_value = CONTRAST_DEF,
},
-   .set = sd_setcontrast,
-   .get = sd_getcontrast,
+   .set = pac7311_sd_setcontrast,
+   .get = pac7311_sd_getcontrast,
},
 /* All controls below are for both the 7302 and the 7311 */
{
@@ -1130,21 +1132,37 @@ static int pac7302_sd_getbrightness(stru
return 0;
 }

-static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
+static int pac7302_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
 {
struct sd *sd = (struct sd *) gspca_dev;

sd->contrast = val;
if (gspca_dev->streaming) {
-   if (sd->sensor == SENSOR_PAC7302)
-   pac7302_setbrightcont(gspca_dev);
-   else
-   pac7311_setcontrast(gspca_dev);
+   pac7302_setbrightcont(gspca_dev);
+   }
+   return 0;
+}
+
+static int pac7311_sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+
+   sd->contrast = val;
+   if (gspca_dev->streaming) {
+   pac7311_setcontrast(gspca_dev);
}
return 0;
 }

-static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
+static int pac7302_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+
+   *val = sd->contrast;
+   return 0;
+}
+
+static int pac7311_sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
 {
struct sd *sd = (struct sd *) gspca_dev;

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


[PATCH 10/21] gspca pac7302/pac7311: separate brightness and color controls

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the controls for PAC7302 and for PAC7311. Separate the brightness
and color controls. The ctrl_dis setting is no longer necessary because the
brightness and saturation controls are only listed among PAC7302 controls.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN j/drivers/media/video/gspca/pac7311.c 
k/drivers/media/video/gspca/pac7311.c
--- j/drivers/media/video/gspca/pac7311.c   2009-10-30 18:00:55.0 
+0100
+++ k/drivers/media/video/gspca/pac7311.c   2009-10-31 07:13:44.0 
+0100
@@ -81,12 +81,12 @@ struct sd {
 };

 /* V4L2 controls supported by the driver */
-static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
-static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
-static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
+static int pac7302_sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
+static int pac7302_sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
@@ -98,9 +98,8 @@ static int sd_getgain(struct gspca_dev *
 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);

-static struct ctrl sd_ctrls[] = {
+static struct ctrl pac7302_sd_ctrls[] = {
 /* This control is pac7302 only */
-#define BRIGHTNESS_IDX 0
{
{
.id  = V4L2_CID_BRIGHTNESS,
@@ -113,8 +112,8 @@ static struct ctrl sd_ctrls[] = {
 #define BRIGHTNESS_DEF 0x10
.default_value = BRIGHTNESS_DEF,
},
-   .set = sd_setbrightness,
-   .get = sd_getbrightness,
+   .set = pac7302_sd_setbrightness,
+   .get = pac7302_sd_getbrightness,
},
 /* This control is for both the 7302 and the 7311 */
{
@@ -133,7 +132,6 @@ static struct ctrl sd_ctrls[] = {
.get = sd_getcontrast,
},
 /* This control is pac7302 only */
-#define SATURATION_IDX 2
{
{
.id  = V4L2_CID_SATURATION,
@@ -146,8 +144,102 @@ static struct ctrl sd_ctrls[] = {
 #define COLOR_DEF 127
.default_value = COLOR_DEF,
},
-   .set = sd_setcolors,
-   .get = sd_getcolors,
+   .set = pac7302_sd_setcolors,
+   .get = pac7302_sd_getcolors,
+   },
+/* All controls below are for both the 7302 and the 7311 */
+   {
+   {
+   .id  = V4L2_CID_GAIN,
+   .type= V4L2_CTRL_TYPE_INTEGER,
+   .name= "Gain",
+   .minimum = 0,
+#define GAIN_MAX 255
+   .maximum = GAIN_MAX,
+   .step= 1,
+#define GAIN_DEF 127
+#define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
+   .default_value = GAIN_DEF,
+   },
+   .set = sd_setgain,
+   .get = sd_getgain,
+   },
+   {
+   {
+   .id  = V4L2_CID_EXPOSURE,
+   .type= V4L2_CTRL_TYPE_INTEGER,
+   .name= "Exposure",
+   .minimum = 0,
+#define EXPOSURE_MAX 255
+   .maximum = EXPOSURE_MAX,
+   .step= 1,
+#define EXPOSURE_DEF  16 /*  32 ms / 30 fps */
+#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
+   .default_value = EXPOSURE_DEF,
+   },
+   .set = sd_setexposure,
+   .get = sd_getexposure,
+   },
+   {
+   {
+   .id  = V4L2_CID_AUTOGAIN,
+   .type= V4L2_CTRL_TYPE_BOOLEAN,
+   .name= "Auto Gain",
+   .minimum = 0,
+   .maximum = 1,
+   .step= 1,
+#define AUTOGAIN_DEF 1
+   .default_value = AUTOGAIN_DEF,
+   },
+   .set = sd_setautogain,
+   .get = sd_getautogain,
+   },
+   {
+   {
+   .id  = V4L2_CID_HFLIP,
+   .type= V4L2_CTRL_TYPE_BOOLEAN,
+   .name= "Mirror",
+   .minimum = 0,
+   .maximum = 1,
+   .step= 1,
+#define HFLIP_DEF 0
+   .default_value = HFLIP_DEF,
+   },
+   .set = sd_sethflip,
+   .get = sd_gethflip,
+   },
+   {
+   {
+   .id  = V4L2_CID_VFLIP,
+   .type= V4L2_CTRL_TYPE_BO

[PATCH 09/21] gspca pac7302/pac7311: separate dq_callback

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the dq_callback function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN i/drivers/media/video/gspca/pac7311.c 
j/drivers/media/video/gspca/pac7311.c
--- i/drivers/media/video/gspca/pac7311.c   2009-10-30 17:59:39.0 
+0100
+++ j/drivers/media/video/gspca/pac7311.c   2009-10-30 18:00:55.0 
+0100
@@ -820,7 +820,7 @@ static void pac7311_sd_stop0(struct gspc
 /* Include pac common sof detection functions */
 #include "pac_common.h"

-static void do_autogain(struct gspca_dev *gspca_dev)
+static void pac7302_do_autogain(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;
int avg_lum = atomic_read(&sd->avg_lum);
@@ -829,22 +829,36 @@ static void do_autogain(struct gspca_dev
if (avg_lum == -1)
return;

-   if (sd->sensor == SENSOR_PAC7302) {
-   desired_lum = 270 + sd->brightness * 4;
-   /* Hack hack, with the 7202 the first exposure step is
-  pretty large, so if we're about to make the first
-  exposure increase make the deadzone large to avoid
-  oscilating */
-   if (desired_lum > avg_lum && sd->gain == GAIN_DEF &&
-   sd->exposure > EXPOSURE_DEF &&
-   sd->exposure < 42)
-   deadzone = 90;
-   else
-   deadzone = 30;
-   } else {
-   desired_lum = 200;
-   deadzone = 20;
-   }
+   desired_lum = 270 + sd->brightness * 4;
+   /* Hack hack, with the 7202 the first exposure step is
+  pretty large, so if we're about to make the first
+  exposure increase make the deadzone large to avoid
+  oscilating */
+   if (desired_lum > avg_lum && sd->gain == GAIN_DEF &&
+   sd->exposure > EXPOSURE_DEF &&
+   sd->exposure < 42)
+   deadzone = 90;
+   else
+   deadzone = 30;
+
+   if (sd->autogain_ignore_frames > 0)
+   sd->autogain_ignore_frames--;
+   else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum,
+   deadzone, GAIN_KNEE, EXPOSURE_KNEE))
+   sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
+}
+
+static void pac7311_do_autogain(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   int avg_lum = atomic_read(&sd->avg_lum);
+   int desired_lum, deadzone;
+
+   if (avg_lum == -1)
+   return;
+
+   desired_lum = 200;
+   deadzone = 20;

if (sd->autogain_ignore_frames > 0)
sd->autogain_ignore_frames--;
@@ -1180,7 +1194,7 @@ static struct sd_desc pac7302_sd_desc =
.stopN = pac7302_sd_stopN,
.stop0 = pac7302_sd_stop0,
.pkt_scan = pac7302_sd_pkt_scan,
-   .dq_callback = do_autogain,
+   .dq_callback = pac7302_do_autogain,
 };

 /* sub-driver description for pac7311 */
@@ -1194,7 +1208,7 @@ static struct sd_desc pac7311_sd_desc =
.stopN = pac7311_sd_stopN,
.stop0 = pac7311_sd_stop0,
.pkt_scan = pac7311_sd_pkt_scan,
-   .dq_callback = do_autogain,
+   .dq_callback = pac7311_do_autogain,
 };

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


[PATCH 08/21] gspca pac7302/pac7311: separate stop0

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the stop0 function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN h/drivers/media/video/gspca/pac7311.c 
i/drivers/media/video/gspca/pac7311.c
--- h/drivers/media/video/gspca/pac7311.c   2009-10-30 18:01:57.0 
+0100
+++ i/drivers/media/video/gspca/pac7311.c   2009-10-30 17:59:39.0 
+0100
@@ -803,17 +803,18 @@ static void pac7311_sd_stopN(struct gspc
reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
 }

-/* called on streamoff with alt 0 and on disconnect */
-static void sd_stop0(struct gspca_dev *gspca_dev)
+/* called on streamoff with alt 0 and on disconnect for pac7302 */
+static void pac7302_sd_stop0(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
-
if (!gspca_dev->present)
return;
-   if (sd->sensor == SENSOR_PAC7302) {
-   reg_w(gspca_dev, 0xff, 0x01);
-   reg_w(gspca_dev, 0x78, 0x40);
-   }
+   reg_w(gspca_dev, 0xff, 0x01);
+   reg_w(gspca_dev, 0x78, 0x40);
+}
+
+/* called on streamoff with alt 0 and on disconnect for 7311 */
+static void pac7311_sd_stop0(struct gspca_dev *gspca_dev)
+{
 }

 /* Include pac common sof detection functions */
@@ -1177,7 +1178,7 @@ static struct sd_desc pac7302_sd_desc =
.init = pac7302_sd_init,
.start = pac7302_sd_start,
.stopN = pac7302_sd_stopN,
-   .stop0 = sd_stop0,
+   .stop0 = pac7302_sd_stop0,
.pkt_scan = pac7302_sd_pkt_scan,
.dq_callback = do_autogain,
 };
@@ -1191,7 +1192,7 @@ static struct sd_desc pac7311_sd_desc =
.init = pac7311_sd_init,
.start = pac7311_sd_start,
.stopN = pac7311_sd_stopN,
-   .stop0 = sd_stop0,
+   .stop0 = pac7311_sd_stop0,
.pkt_scan = pac7311_sd_pkt_scan,
.dq_callback = do_autogain,
 };
--
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


[PATCH 07/21] gspca pac7302/pac7311: separate stopN

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the stopN function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN g/drivers/media/video/gspca/pac7311.c 
h/drivers/media/video/gspca/pac7311.c
--- g/drivers/media/video/gspca/pac7311.c   2009-10-30 18:03:15.0 
+0100
+++ h/drivers/media/video/gspca/pac7311.c   2009-10-30 18:01:57.0 
+0100
@@ -782,16 +782,15 @@ static int pac7311_sd_start(struct gspca
return 0;
 }

-static void sd_stopN(struct gspca_dev *gspca_dev)
+static void pac7302_sd_stopN(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   reg_w(gspca_dev, 0xff, 0x01);
+   reg_w(gspca_dev, 0x78, 0x00);
+   reg_w(gspca_dev, 0x78, 0x00);
+}

-   if (sd->sensor == SENSOR_PAC7302) {
-   reg_w(gspca_dev, 0xff, 0x01);
-   reg_w(gspca_dev, 0x78, 0x00);
-   reg_w(gspca_dev, 0x78, 0x00);
-   return;
-   }
+static void pac7311_sd_stopN(struct gspca_dev *gspca_dev)
+{
reg_w(gspca_dev, 0xff, 0x04);
reg_w(gspca_dev, 0x27, 0x80);
reg_w(gspca_dev, 0x28, 0xca);
@@ -1177,7 +1176,7 @@ static struct sd_desc pac7302_sd_desc =
.config = pac7302_sd_config,
.init = pac7302_sd_init,
.start = pac7302_sd_start,
-   .stopN = sd_stopN,
+   .stopN = pac7302_sd_stopN,
.stop0 = sd_stop0,
.pkt_scan = pac7302_sd_pkt_scan,
.dq_callback = do_autogain,
@@ -1191,7 +1190,7 @@ static struct sd_desc pac7311_sd_desc =
.config = pac7311_sd_config,
.init = pac7311_sd_init,
.start = pac7311_sd_start,
-   .stopN = sd_stopN,
+   .stopN = pac7311_sd_stopN,
.stop0 = sd_stop0,
.pkt_scan = pac7311_sd_pkt_scan,
.dq_callback = do_autogain,
--
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


[PATCH 06/21] gspca pac7302/pac7311: separate start

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the start function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN f/drivers/media/video/gspca/pac7311.c 
g/drivers/media/video/gspca/pac7311.c
--- f/drivers/media/video/gspca/pac7311.c   2009-10-30 18:04:30.0 
+0100
+++ g/drivers/media/video/gspca/pac7311.c   2009-10-30 18:03:15.0 
+0100
@@ -714,20 +714,40 @@ static int pac7311_sd_init(struct gspca_
return 0;
 }

-static int sd_start(struct gspca_dev *gspca_dev)
+static int pac7302_sd_start(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;

sd->sof_read = 0;

-   if (sd->sensor == SENSOR_PAC7302) {
-   reg_w_var(gspca_dev, start_7302);
-   pac7302_setbrightcont(gspca_dev);
-   pac7302_setcolors(gspca_dev);
-   } else {
-   reg_w_var(gspca_dev, start_7311);
-   pac7311_setcontrast(gspca_dev);
-   }
+   reg_w_var(gspca_dev, start_7302);
+   pac7302_setbrightcont(gspca_dev);
+   pac7302_setcolors(gspca_dev);
+   setgain(gspca_dev);
+   setexposure(gspca_dev);
+   sethvflip(gspca_dev);
+
+   /* only resolution 640x480 is supported for pac7302 */
+
+   sd->sof_read = 0;
+   sd->autogain_ignore_frames = 0;
+   atomic_set(&sd->avg_lum, -1);
+
+   /* start stream */
+   reg_w(gspca_dev, 0xff, 0x01);
+   reg_w(gspca_dev, 0x78, 0x01);
+
+   return 0;
+}
+
+static int pac7311_sd_start(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+
+   sd->sof_read = 0;
+
+   reg_w_var(gspca_dev, start_7311);
+   pac7311_setcontrast(gspca_dev);
setgain(gspca_dev);
setexposure(gspca_dev);
sethvflip(gspca_dev);
@@ -745,8 +765,6 @@ static int sd_start(struct gspca_dev *gs
reg_w(gspca_dev, 0x87, 0x11);
break;
case 0: /* 640x480 */
-   if (sd->sensor == SENSOR_PAC7302)
-   break;
reg_w(gspca_dev, 0xff, 0x01);
reg_w(gspca_dev, 0x17, 0x00);
reg_w(gspca_dev, 0x87, 0x12);
@@ -759,10 +777,8 @@ static int sd_start(struct gspca_dev *gs

/* start stream */
reg_w(gspca_dev, 0xff, 0x01);
-   if (sd->sensor == SENSOR_PAC7302)
-   reg_w(gspca_dev, 0x78, 0x01);
-   else
-   reg_w(gspca_dev, 0x78, 0x05);
+   reg_w(gspca_dev, 0x78, 0x05);
+
return 0;
 }

@@ -1160,7 +1176,7 @@ static struct sd_desc pac7302_sd_desc =
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = pac7302_sd_config,
.init = pac7302_sd_init,
-   .start = sd_start,
+   .start = pac7302_sd_start,
.stopN = sd_stopN,
.stop0 = sd_stop0,
.pkt_scan = pac7302_sd_pkt_scan,
@@ -1174,7 +1190,7 @@ static struct sd_desc pac7311_sd_desc =
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = pac7311_sd_config,
.init = pac7311_sd_init,
-   .start = sd_start,
+   .start = pac7311_sd_start,
.stopN = sd_stopN,
.stop0 = sd_stop0,
.pkt_scan = pac7311_sd_pkt_scan,
--
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


[PATCH 05/21] gspca pac7302/pac7311: separate init

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the init function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN e/drivers/media/video/gspca/pac7311.c 
f/drivers/media/video/gspca/pac7311.c
--- e/drivers/media/video/gspca/pac7311.c   2009-10-30 17:27:57.0 
+0100
+++ f/drivers/media/video/gspca/pac7311.c   2009-10-30 18:04:30.0 
+0100
@@ -698,15 +698,18 @@ static void sethvflip(struct gspca_dev *
reg_w(gspca_dev, 0x11, 0x01);
 }

-/* this function is called at probe and resume time */
-static int sd_init(struct gspca_dev *gspca_dev)
+/* this function is called at probe and resume time for pac7302 */
+static int pac7302_sd_init(struct gspca_dev *gspca_dev)
 {
-   struct sd *sd = (struct sd *) gspca_dev;
+   reg_w_seq(gspca_dev, init_7302, sizeof init_7302);

-   if (sd->sensor == SENSOR_PAC7302)
-   reg_w_seq(gspca_dev, init_7302, sizeof init_7302);
-   else
-   reg_w_seq(gspca_dev, init_7311, sizeof init_7311);
+   return 0;
+}
+
+/* this function is called at probe and resume time for pac7311 */
+static int pac7311_sd_init(struct gspca_dev *gspca_dev)
+{
+   reg_w_seq(gspca_dev, init_7311, sizeof init_7311);

return 0;
 }
@@ -1156,7 +1159,7 @@ static struct sd_desc pac7302_sd_desc =
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = pac7302_sd_config,
-   .init = sd_init,
+   .init = pac7302_sd_init,
.start = sd_start,
.stopN = sd_stopN,
.stop0 = sd_stop0,
@@ -1170,7 +1173,7 @@ static struct sd_desc pac7311_sd_desc =
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = pac7311_sd_config,
-   .init = sd_init,
+   .init = pac7311_sd_init,
.start = sd_start,
.stopN = sd_stopN,
.stop0 = sd_stop0,
--
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


[PATCH 04/21] gspca pac7302/pac7311: separate config

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the config function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN d/drivers/media/video/gspca/pac7311.c 
e/drivers/media/video/gspca/pac7311.c
--- d/drivers/media/video/gspca/pac7311.c   2009-10-30 17:15:51.0 
+0100
+++ e/drivers/media/video/gspca/pac7311.c   2009-10-30 17:27:57.0 
+0100
@@ -509,8 +509,8 @@ static void reg_w_var(struct gspca_dev *
/* not reached */
 }

-/* this function is called at probe time */
-static int sd_config(struct gspca_dev *gspca_dev,
+/* this function is called at probe time for pac7302 */
+static int pac7302_sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
 {
struct sd *sd = (struct sd *) gspca_dev;
@@ -519,17 +519,36 @@ static int sd_config(struct gspca_dev *g
cam = &gspca_dev->cam;

sd->sensor = id->driver_info;
-   if (sd->sensor == SENSOR_PAC7302) {
-   PDEBUG(D_CONF, "Find Sensor PAC7302");
-   cam->cam_mode = &vga_mode[2];   /* only 640x480 */
-   cam->nmodes = 1;
-   } else {
-       PDEBUG(D_CONF, "Find Sensor PAC7311");
-   cam->cam_mode = vga_mode;
-   cam->nmodes = ARRAY_SIZE(vga_mode);
-   gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX)
-   | (1 << SATURATION_IDX);
-   }
+   PDEBUG(D_CONF, "Find Sensor PAC7302");
+   cam->cam_mode = &vga_mode[2];   /* only 640x480 */
+   cam->nmodes = 1;
+
+   sd->brightness = BRIGHTNESS_DEF;
+   sd->contrast = CONTRAST_DEF;
+   sd->colors = COLOR_DEF;
+   sd->gain = GAIN_DEF;
+   sd->exposure = EXPOSURE_DEF;
+   sd->autogain = AUTOGAIN_DEF;
+   sd->hflip = HFLIP_DEF;
+   sd->vflip = VFLIP_DEF;
+   return 0;
+}
+
+/* this function is called at probe time for pac7311 */
+static int pac7311_sd_config(struct gspca_dev *gspca_dev,
+   const struct usb_device_id *id)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   struct cam *cam;
+
+   cam = &gspca_dev->cam;
+
+   sd->sensor = id->driver_info;
+   PDEBUG(D_CONF, "Find Sensor PAC7311");
+   cam->cam_mode = vga_mode;
+   cam->nmodes = ARRAY_SIZE(vga_mode);
+   gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX)
+   | (1 << SATURATION_IDX);

sd->brightness = BRIGHTNESS_DEF;
sd->contrast = CONTRAST_DEF;
@@ -1136,7 +1155,7 @@ static struct sd_desc pac7302_sd_desc =
.name = MODULE_NAME,
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
-   .config = sd_config,
+   .config = pac7302_sd_config,
.init = sd_init,
.start = sd_start,
.stopN = sd_stopN,
@@ -1150,7 +1169,7 @@ static struct sd_desc pac7311_sd_desc =
.name = MODULE_NAME,
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
-   .config = sd_config,
+   .config = pac7311_sd_config,
.init = sd_init,
.start = sd_start,
.stopN = sd_stopN,
--
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


[PATCH 03/21] gspca pac7302/pac7311: separate pkt_scan

2009-10-31 Thread Németh Márton
From: Márton Németh 

Separate the pkt_scan function. Remove the run-time decision for
PAC7302 and PAC7311 sensors.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN c/drivers/media/video/gspca/pac7311.c 
d/drivers/media/video/gspca/pac7311.c
--- c/drivers/media/video/gspca/pac7311.c   2009-10-30 17:05:09.0 
+0100
+++ d/drivers/media/video/gspca/pac7311.c   2009-10-30 17:15:51.0 
+0100
@@ -844,7 +844,7 @@ static const unsigned char pac7311_jpeg_
 };

 /* this function is run at interrupt level */
-static void sd_pkt_scan(struct gspca_dev *gspca_dev,
+static void pac7302_sd_pkt_scan(struct gspca_dev *gspca_dev,
struct gspca_frame *frame,  /* target */
__u8 *data, /* isoc packet */
int len)/* iso packet length */
@@ -857,17 +857,12 @@ static void sd_pkt_scan(struct gspca_dev
unsigned char tmpbuf[4];
int n, lum_offset, footer_length;

-   if (sd->sensor == SENSOR_PAC7302) {
- /* 6 bytes after the FF D9 EOF marker a number of lumination
-bytes are send corresponding to different parts of the
-image, the 14th and 15th byte after the EOF seem to
-correspond to the center of the image */
- lum_offset = 61 + sizeof pac_sof_marker;
- footer_length = 74;
-   } else {
- lum_offset = 24 + sizeof pac_sof_marker;
- footer_length = 26;
-   }
+   /* 6 bytes after the FF D9 EOF marker a number of lumination
+  bytes are send corresponding to different parts of the
+  image, the 14th and 15th byte after the EOF seem to
+  correspond to the center of the image */
+   lum_offset = 61 + sizeof pac_sof_marker;
+   footer_length = 74;

/* Finish decoding current frame */
n = (sof - data) - (footer_length + sizeof pac_sof_marker);
@@ -898,18 +893,76 @@ static void sd_pkt_scan(struct gspca_dev
/* Start the new frame with the jpeg header */
gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
pac7311_jpeg_header1, sizeof(pac7311_jpeg_header1));
-   if (sd->sensor == SENSOR_PAC7302) {
-   /* The PAC7302 has the image rotated 90 degrees */
-   tmpbuf[0] = gspca_dev->width >> 8;
-   tmpbuf[1] = gspca_dev->width & 0xff;
-   tmpbuf[2] = gspca_dev->height >> 8;
-   tmpbuf[3] = gspca_dev->height & 0xff;
-   } else {
-   tmpbuf[0] = gspca_dev->height >> 8;
-   tmpbuf[1] = gspca_dev->height & 0xff;
-   tmpbuf[2] = gspca_dev->width >> 8;
-   tmpbuf[3] = gspca_dev->width & 0xff;
+
+   /* The PAC7302 has the image rotated 90 degrees */
+   tmpbuf[0] = gspca_dev->width >> 8;
+   tmpbuf[1] = gspca_dev->width & 0xff;
+   tmpbuf[2] = gspca_dev->height >> 8;
+   tmpbuf[3] = gspca_dev->height & 0xff;
+
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame, tmpbuf, 4);
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+   pac7311_jpeg_header2, sizeof(pac7311_jpeg_header2));
+   }
+   gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
+}
+
+/* this function is run at interrupt level */
+static void pac7311_sd_pkt_scan(struct gspca_dev *gspca_dev,
+   struct gspca_frame *frame,  /* target */
+   __u8 *data, /* isoc packet */
+   int len)/* iso packet length */
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   unsigned char *sof;
+
+   sof = pac_find_sof(gspca_dev, data, len);
+   if (sof) {
+   unsigned char tmpbuf[4];
+   int n, lum_offset, footer_length;
+
+   /* 6 bytes after the FF D9 EOF marker a number of lumination
+  bytes are send corresponding to different parts of the
+  image, the 14th and 15th byte after the EOF seem to
+  correspond to the center of the image */
+   lum_offset = 24 + sizeof pac_sof_marker;
+   footer_length = 26;
+
+   /* Finish decoding current frame */
+   n = (sof - data) - (footer_length + sizeof pac_sof_marker);
+   if (n < 0) {
+   frame->data_end += n;
+   n = 0;
}
+   frame = gspca_frame_add(gsp

[PATCH 02/21] gspca pac7302/pac7311: separate sd_desc

2009-10-31 Thread Németh Márton
From: Márton Németh 

Move the sensor specific decision temporary to sd_probe. Create an sd_desc
for PAC7302 and one for PAC7311.

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN b/drivers/media/video/gspca/pac7311.c 
c/drivers/media/video/gspca/pac7311.c
--- b/drivers/media/video/gspca/pac7311.c   2009-10-30 17:09:52.0 
+0100
+++ c/drivers/media/video/gspca/pac7311.c   2009-10-30 17:05:09.0 
+0100
@@ -1078,8 +1078,22 @@ static int sd_getvflip(struct gspca_dev
return 0;
 }

-/* sub-driver description */
-static struct sd_desc sd_desc = {
+/* sub-driver description for pac7302 */
+static struct sd_desc pac7302_sd_desc = {
+   .name = MODULE_NAME,
+   .ctrls = sd_ctrls,
+   .nctrls = ARRAY_SIZE(sd_ctrls),
+   .config = sd_config,
+   .init = sd_init,
+   .start = sd_start,
+   .stopN = sd_stopN,
+   .stop0 = sd_stop0,
+   .pkt_scan = sd_pkt_scan,
+   .dq_callback = do_autogain,
+};
+
+/* sub-driver description for pac7311 */
+static struct sd_desc pac7311_sd_desc = {
.name = MODULE_NAME,
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
@@ -1117,8 +1131,12 @@ MODULE_DEVICE_TABLE(usb, device_table);
 static int sd_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
-   return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
-   THIS_MODULE);
+   if (id->driver_info == SENSOR_PAC7302)
+   return gspca_dev_probe(intf, id, &pac7302_sd_desc,
+   sizeof(struct sd), THIS_MODULE);
+   else
+   return gspca_dev_probe(intf, id, &pac7311_sd_desc,
+   sizeof(struct sd), THIS_MODULE);
 }

 static struct usb_driver sd_driver = {
--
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


[PATCH 01/21] gspca pac7302/pac7311: add prefix for sensor specific functions

2009-10-31 Thread Németh Márton
From: Márton Németh 

There are some functions which are already sensor specific. Mark them
with pac7302_ or pac7311_ prefix

Signed-off-by: Márton Németh 
Cc: Thomas Kaiser 
Cc: Theodore Kilgore 
Cc: Kyle Guinn 
---
diff -uprN a/drivers/media/video/gspca/pac7311.c 
b/drivers/media/video/gspca/pac7311.c
--- a/drivers/media/video/gspca/pac7311.c   2009-10-30 16:12:05.0 
+0100
+++ b/drivers/media/video/gspca/pac7311.c   2009-10-30 17:09:52.0 
+0100
@@ -543,7 +543,7 @@ static int sd_config(struct gspca_dev *g
 }

 /* This function is used by pac7302 only */
-static void setbrightcont(struct gspca_dev *gspca_dev)
+static void pac7302_setbrightcont(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;
int i, v;
@@ -570,7 +570,7 @@ static void setbrightcont(struct gspca_d
 }

 /* This function is used by pac7311 only */
-static void setcontrast(struct gspca_dev *gspca_dev)
+static void pac7311_setcontrast(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;

@@ -581,7 +581,7 @@ static void setcontrast(struct gspca_dev
 }

 /* This function is used by pac7302 only */
-static void setcolors(struct gspca_dev *gspca_dev)
+static void pac7302_setcolors(struct gspca_dev *gspca_dev)
 {
struct sd *sd = (struct sd *) gspca_dev;
int i, v;
@@ -700,11 +700,11 @@ static int sd_start(struct gspca_dev *gs

if (sd->sensor == SENSOR_PAC7302) {
reg_w_var(gspca_dev, start_7302);
-   setbrightcont(gspca_dev);
-   setcolors(gspca_dev);
+   pac7302_setbrightcont(gspca_dev);
+   pac7302_setcolors(gspca_dev);
} else {
reg_w_var(gspca_dev, start_7311);
-   setcontrast(gspca_dev);
+   pac7311_setcontrast(gspca_dev);
}
setgain(gspca_dev);
setexposure(gspca_dev);
@@ -923,7 +923,7 @@ static int sd_setbrightness(struct gspca

sd->brightness = val;
if (gspca_dev->streaming)
-   setbrightcont(gspca_dev);
+   pac7302_setbrightcont(gspca_dev);
return 0;
 }

@@ -942,9 +942,9 @@ static int sd_setcontrast(struct gspca_d
sd->contrast = val;
if (gspca_dev->streaming) {
if (sd->sensor == SENSOR_PAC7302)
-   setbrightcont(gspca_dev);
+   pac7302_setbrightcont(gspca_dev);
else
-   setcontrast(gspca_dev);
+   pac7311_setcontrast(gspca_dev);
}
return 0;
 }
@@ -963,7 +963,7 @@ static int sd_setcolors(struct gspca_dev

sd->colors = val;
if (gspca_dev->streaming)
-   setcolors(gspca_dev);
+   pac7302_setcolors(gspca_dev);
return 0;
 }

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


[PATCH 00/21] gspca pac7302/pac7311: separate the two drivers

2009-10-31 Thread Németh Márton
Hi,

the following patchset refactores the Pixart PAC7311 subdriver. The
current situation is that the code contains a lot of decisions
like this:

if (sd->sensor == SENSOR_PAC7302) {
... do this ...
} else {
... do something else ...
}

The sensor type is determined using the USB Vendor ID and Product
ID which means that the decisions shown are not really necessary.

The goal of the patchset is to have a PAC7302 and a PAC7311 subdriver
which have the benefit that there is no decision necessary on sensor
type at runtime. The common functions can be extracted later but this
would be a different patchset.

Regards,

Márton Németh

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


[PATCH] pac7311: add comment about JPEG header

2009-10-03 Thread Németh Márton
From: Márton Németh 

Add comment about the meaning of the fixed JPEG header bytes used to
create each image.

The change was tested with Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
diff -upr e/drivers/media/video/gspca/pac7311.c 
f/drivers/media/video/gspca/pac7311.c
--- e/drivers/media/video/gspca/pac7311.c   2009-10-03 16:23:37.0 
+0200
+++ f/drivers/media/video/gspca/pac7311.c   2009-10-03 19:56:21.0 
+0200
@@ -801,13 +801,32 @@ static void do_autogain(struct gspca_dev
sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
 }

+/* JPEG header, part 1 */
 static const unsigned char pac7311_jpeg_header1[] = {
-  0xff, 0xd8, 0xff, 0xc0, 0x00, 0x11, 0x08
+  0xff, 0xd8,  /* SOI: Start of Image */
+
+  0xff, 0xc0,  /* SOF0: Start of Frame (Baseline DCT) */
+  0x00, 0x11,  /* length = 17 bytes (including this length field) */
+  0x08 /* Precision: 8 */
+  /* 2 bytes is placed here: number of image lines */
+  /* 2 bytes is placed here: samples per line */
 };

+/* JPEG header, continued */
 static const unsigned char pac7311_jpeg_header2[] = {
-  0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xda,
-  0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00
+  0x03,/* Number of image components: 3 */
+  0x01, 0x21, 0x00,/* ID=1, Subsampling 1x1, Quantization table: 0 */
+  0x02, 0x11, 0x01,/* ID=2, Subsampling 2x1, Quantization table: 1 */
+  0x03, 0x11, 0x01,/* ID=3, Subsampling 2x1, Quantization table: 1 */
+
+  0xff, 0xda,  /* SOS: Start Of Scan */
+  0x00, 0x0c,  /* length = 12 bytes (including this length field) */
+  0x03,/* number of components: 3 */
+  0x01, 0x00,  /* selector 1, table 0x00 */
+  0x02, 0x11,  /* selector 2, table 0x11 */
+  0x03, 0x11,  /* selector 3, table 0x11 */
+  0x00, 0x3f,  /* Spectral selection: 0 .. 63 */
+  0x00 /* Successive approximation: 0 */
 };

 /* this function is run at interrupt level */
--
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


[PATCH] pac7311: remove redundant register page switching

2009-10-03 Thread Németh Márton
Hi,

do you know any reason (i.e. a special device needs this) why switch to
register page 0 is done twice in the setcolors() function of pac7311?

I removed the redundant page switch and my Labtec Webcam 2200 still
behaves correctly when I change the "Saturation" control.

Regards,

Márton Németh

---
From: Márton Németh 

Remove redundant register page switching to page 0 when changing the
color control.

The change was tested with Labtec Webcam 2200 (USB ID: 093a:2626).

Signed-off-by: Márton Németh 
---
diff -upr d/drivers/media/video/gspca/pac7311.c 
e/drivers/media/video/gspca/pac7311.c
--- d/drivers/media/video/gspca/pac7311.c   2009-10-03 09:02:31.0 
+0200
+++ e/drivers/media/video/gspca/pac7311.c   2009-10-03 16:23:37.0 
+0200
@@ -579,7 +579,6 @@ static void setcolors(struct gspca_dev *
reg_w(gspca_dev, 0xff, 0x03);   /* page 3 */
reg_w(gspca_dev, 0x11, 0x01);
reg_w(gspca_dev, 0xff, 0x00);   /* page 0 */
-   reg_w(gspca_dev, 0xff, 0x00);   /* page 0 */
for (i = 0; i < 9; i++) {
v = a[i] * sd->colors / COLOR_MAX + b[i];
reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07);
--
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


[PATCH 2/3] pac7311: remove magic values for END_OF_SEQUENCE and LOAD_PAGE{3,4}

2009-10-03 Thread Németh Márton
From: Márton Németh 

Change the magic values 0, 254 and 255 to END_OF_SEQUENCE, LOAD_PAGE4 and
LOAD_PAGE3 respectively for better source code readability.

The change was tested with Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
diff -upr b/drivers/media/video/gspca/pac7311.c 
c/drivers/media/video/gspca/pac7311.c
--- b/drivers/media/video/gspca/pac7311.c   2009-10-03 08:27:36.0 
+0200
+++ c/drivers/media/video/gspca/pac7311.c   2009-10-03 08:47:30.0 
+0200
@@ -244,6 +244,10 @@ static const struct v4l2_pix_format vga_
.priv = 0},
 };

+#define LOAD_PAGE3 255
+#define LOAD_PAGE4 254
+#define END_OF_SEQUENCE0
+
 /* pac 7302 */
 static const __u8 init_7302[] = {
 /* index,value */
@@ -302,7 +306,7 @@ static const __u8 start_7302[] = {
0xff, 1,0x02,   /* page 2 */
0x22, 1,0x00,
0xff, 1,0x03,   /* page 3 */
-   0x00, 255,  /* load the page 3 */
+   0, LOAD_PAGE3,  /* load the page 3 */
0x11, 1,0x01,
0xff, 1,0x02,   /* page 2 */
0x13, 1,0x00,
@@ -313,7 +317,7 @@ static const __u8 start_7302[] = {
0x6e, 1,0x08,
0xff, 1,0x01,   /* page 1 */
0x78, 1,0x00,
-   0, 0/* end of sequence */
+   0, END_OF_SEQUENCE  /* end of sequence */
 };

 #define SKIP   0xaa
@@ -379,9 +383,9 @@ static const __u8 start_7311[] = {
0xf0, 13,   0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x20, 0x00,
0x3f, 0x00, 0x0a, 0x01, 0x00,
0xff, 1,0x04,   /* page 4 */
-   0x00, 254,  /* load the page 4 */
+   0, LOAD_PAGE4,  /* load the page 4 */
0x11, 1,0x01,
-   0, 0/* end of sequence */
+   0, END_OF_SEQUENCE  /* end of sequence */
 };

 /* page 4 - the value SKIP says skip the index - see reg_w_page() */
@@ -461,12 +465,12 @@ static void reg_w_var(struct gspca_dev *
index = *seq++;
len = *seq++;
switch (len) {
-   case 0:
+   case END_OF_SEQUENCE:
return;
-   case 254:
+   case LOAD_PAGE4:
reg_w_page(gspca_dev, page4_7311, sizeof page4_7311);
break;
-   case 255:
+   case LOAD_PAGE3:
reg_w_page(gspca_dev, page3_7302, sizeof page3_7302);
break;
default:
--
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


[PATCH 3/3] pac7311: remove magic value for USB_BUF_SZ

2009-10-03 Thread Németh Márton
From: Márton Németh 

The length check in reg_w_var() function is because the buffer contents
is copied to gspca_dev->usb_buf which has the size of USB_BUF_SZ bytes as
defined in drivers/media/video/gspca/gspca.h. Replace the number with
symbol for better readability and maintainability.

The change was tested with Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
diff -upr c/drivers/media/video/gspca/pac7311.c 
d/drivers/media/video/gspca/pac7311.c
--- c/drivers/media/video/gspca/pac7311.c   2009-10-03 08:47:30.0 
+0200
+++ d/drivers/media/video/gspca/pac7311.c   2009-10-03 09:02:31.0 
+0200
@@ -474,7 +474,7 @@ static void reg_w_var(struct gspca_dev *
reg_w_page(gspca_dev, page3_7302, sizeof page3_7302);
break;
default:
-   if (len > 64) {
+   if (len > USB_BUF_SZ) {
PDEBUG(D_ERR|D_STREAM,
"Incorrect variable sequence");
return;
--
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


[PATCH 1/3] pac7311: remove magic value for SKIP

2009-10-03 Thread Németh Márton
From: Márton Németh 

Change the magic value 0xaa to SKIP for better understandability.

The change was tested with Labtec Webcam 2200.

Signed-off-by: Márton Németh 
---
diff -upr a/drivers/media/video/gspca/pac7311.c 
b/drivers/media/video/gspca/pac7311.c
--- a/drivers/media/video/gspca/pac7311.c   2009-09-28 17:40:19.0 
+0200
+++ b/drivers/media/video/gspca/pac7311.c   2009-10-03 08:27:36.0 
+0200
@@ -316,7 +316,8 @@ static const __u8 start_7302[] = {
0, 0/* end of sequence */
 };

-/* page 3 - the value 0xaa says skip the index - see reg_w_page() */
+#define SKIP   0xaa
+/* page 3 - the value SKIP says skip the index - see reg_w_page() */
 static const __u8 page3_7302[] = {
0x90, 0x40, 0x03, 0x50, 0xc2, 0x01, 0x14, 0x16,
0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00,
@@ -383,13 +384,13 @@ static const __u8 start_7311[] = {
0, 0/* end of sequence */
 };

-/* page 4 - the value 0xaa says skip the index - see reg_w_page() */
+/* page 4 - the value SKIP says skip the index - see reg_w_page() */
 static const __u8 page4_7311[] = {
-   0xaa, 0xaa, 0x04, 0x54, 0x07, 0x2b, 0x09, 0x0f,
-   0x09, 0x00, 0xaa, 0xaa, 0x07, 0x00, 0x00, 0x62,
-   0x08, 0xaa, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x03, 0xa0, 0x01, 0xf4, 0xaa,
-   0xaa, 0x00, 0x08, 0xaa, 0x03, 0xaa, 0x00, 0x68,
+   SKIP, SKIP, 0x04, 0x54, 0x07, 0x2b, 0x09, 0x0f,
+   0x09, 0x00, SKIP, SKIP, 0x07, 0x00, 0x00, 0x62,
+   0x08, SKIP, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x03, 0xa0, 0x01, 0xf4, SKIP,
+   SKIP, 0x00, 0x08, SKIP, 0x03, SKIP, 0x00, 0x68,
0xca, 0x10, 0x06, 0x78, 0x00, 0x00, 0x00, 0x00,
0x23, 0x28, 0x04, 0x11, 0x00, 0x00
 };
@@ -438,7 +439,7 @@ static void reg_w_page(struct gspca_dev
int index;

for (index = 0; index < len; index++) {
-   if (page[index] == 0xaa)/* skip this index */
+   if (page[index] == SKIP)/* skip this index */
continue;
gspca_dev->usb_buf[0] = page[index];
usb_control_msg(gspca_dev->dev,
--
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