Skip to contentSkip to conversation

Advice wanted on producing an in kernel sq905 driver

DISCUSSION Adam Baker 4 participants 8 messages Nov 17, 2008 – Nov 18, 2008 Media (V4L/DVB)

lore
Share & tools
lore

Adam Baker

author
#0 lore raw

Hi V4L readers,

There currently exists an out of kernel driver for the SQ technologies sq905 USB webcam chipset used by a number of low cost webcams. This driver has a number of issues which would count against it being included in kernel as is but I'm considering trying to create something that could be suitable. I have a number of questions on how best to proceed.

Note that this refers only to the sq905, USB ID 0x2770:0x9120 the sq905c is a substantially different chip.

(If anyone wants to check out the current driver it is at
http://sqcam.cvs.sourceforge.net/viewvc/sqcam/sqcam26/ )

First off some thoughts on how I'd like to proceed.

The chip exposes the Bayer sensor output directly to the driver so the current driver uses code borrowed from libgphoto2 to do the Bayer decode in kernel. Obviously this is wrong and now we have libv4l it should use that instead.

I don't have masses of time to work on this so I need an approach that isn't going to require writing loads of code. Considering the mess the current driver is in it is probably going to be better to make it a sub driver of gspca rather than try to re-use the existing code (which should also make life easier from a long term maintenance PoV).

Now my questions

1) What kernel should I base any patches I produce on? The obvious choice would seem to be
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6.git but it seems as if Linus's 2.6 tree is more up to date for gspca.

2) The existing driver needed to perform a gamma adjustment after performing the Bayer decode. I couldn't find anything in libv4l that obviously did that so I'm guessing it isn't needed for existing devices - should that be added to libv4l if needed and if so how should the driver indicate it is needed - could it be indicated with a new value for v4l2_colorspace?

3) The current driver needs to do some up/down and left/right flips of the data to get it in the right order to do the Bayer decode that depend on the version info the camera returns to its init sequence. Should that code remain in the driver and if not how should the driver communicate what is needed.

4) The current driver doesn't support streaming mode for V4L2 (only V4L1) and libv4l doesn't support cameras that don't support streaming so is there an easy way to test out if the camera output will work well with libv4l before starting work?

5) Is there anything else I should know before starting.

Adam Baker

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#1 lore raw

<note resend with different From address for the video4linux-list>

Quoted 2 lines · Adam Baker

Hi V4L readers,

Hi Adam,

Nice to meet you.

Quoted 1 line

There currently exists an out of kernel driver for the SQ technologies sq905 USB webcam chipset used by a number of low cost webcams. This driver has a number of issues which would count against it being included in kernel as is but I'm considering trying to create something that could be suitable.

Great, thats very good news!

Quoted 2 lines

I have a number of questions on how best to proceed.

Good, keep asking asking questions!

Quoted 8 lines

Note that this refers only to the sq905, USB ID 0x2770:0x9120 the sq905c is a substantially different chip.

(If anyone wants to check out the current driver it is at http://sqcam.cvs.sourceforge.net/viewvc/sqcam/sqcam26/ )

First off some thoughts on how I'd like to proceed.

The chip exposes the Bayer sensor output directly to the driver so the current driver uses code borrowed from libgphoto2 to do the Bayer decode in kernel. Obviously this is wrong and now we have libv4l it should use that instead.

Correct, there is nothing special you need to do for that, just pass frames with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR.. */ V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG.. */ V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG.. */ V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB.. */

Note the last 2 currently are only defined internally in libv4l and not in linux/videodev2.h as no drivers use them yet, but if you need one of them adding it to linux/videodev2.h is fine.

And then make sure your applications are either patched to use libv4l, or use the LD_PRELOAD libc wrapper (see libv4l docs).

Quoted 1 line

I don't have masses of time to work on this so I need an approach that isn't going to require writing loads of code.

Actually, the plan is to remove lots of code :)

Quoted 3 lines

Considering the mess the current
driver is in it is probably going to be better to make it a sub driver of gspca rather than try to re-use the existing code (which should also make life easier from a long term maintenance PoV).

Yes please make it a subdriver of gspca, then all you need to lift from the current driver are the chip specific initalization sequences, and the isoc frame parsing for detecting the beginning and ending of frames.

Quoted 3 lines

Now my questions

1) What kernel should I base any patches I produce on? The obvious choice would seem to be git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6.git but it seems as if Linus's 2.6 tree is more up to date for gspca.

Please use:
http://linuxtv.org/hg/~jfrancois/gspca/

Note that like al v4l-dvb trees this is a standalone tree, not a complete kernel, assuming you've got the headers installed for your current kernel you can just do make menuconfig, make, make install from this tree (from the main dir, not from the linux subdir) to update your current kernels video4linux modules to the latest, then add your own driver and rince repeat :)

Quoted 1 line

2) The existing driver needed to perform a gamma adjustment after performing the Bayer decode. I couldn't find anything in libv4l that obviously did that so I'm guessing it isn't needed for existing devices - should that be added to libv4l if needed and if so how should the driver indicate it is needed - could it be indicated with a new value for v4l2_colorspace?

Hmm interesting for now lets ignore this and first get it up and running without this, and the revisit this. I'm asking for this because gamma correction might be interesting for other cams too, so I would like to see a generic solution for this, which will take some design work, etc.

Quoted 2 lines

3) The current driver needs to do some up/down and left/right flips of the data to get it in the right order to do the Bayer decode that depend on the version info the camera returns to its init sequence. Should that code remain in the driver and if not how should the driver communicate what is needed.

It should communicate what is needed all possible bayer orders are covered by the 4 formats I gave above, and libv4l knows how to handle all 4 of them, for the defines of the last 2 see libv4lconvert/libv4lconvert-priv.h

Quoted 1 line

4) The current driver doesn't support streaming mode for V4L2 (only V4L1) and libv4l doesn't support cameras that don't support streaming so is there an easy way to test out if the camera output will work well with libv4l before starting work?

This should not be a problem. gspca now can work with both bulk and isochronyous usb transfers using cams, although your cam most likely is an isoc one (bulk mode cams are rare).

Quoted 1 line

5) Is there anything else I should know before starting.

Not that I know, go for it!

Regards,

Hans

p.s.

In case it isn't clear I'm the author of libv4l and a contributer to gspca, as said before: go for it and keep asking questions!

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#2 lore raw

2008/11/18 Hans de Goede <[email protected]>:

Quoted 46 lines

<note resend with different From address for the video4linux-list>

Quoted 3 lines · Adam Baker

Hi V4L readers,

Hi Adam,

Nice to meet you.

Quoted 4 lines

There currently exists an out of kernel driver for the SQ technologies sq905 USB webcam chipset used by a number of low cost webcams. This driver has a number of issues which would count against it being included in kernel as is but I'm considering trying to create something that could be suitable.

Great, thats very good news!

Quoted 2 lines

I have a number of questions on how best to proceed.

Good, keep asking asking questions!

Quoted 6 lines

Note that this refers only to the sq905, USB ID 0x2770:0x9120 the sq905c is a substantially different chip.

(If anyone wants to check out the current driver it is at
http://sqcam.cvs.sourceforge.net/viewvc/sqcam/sqcam26/ )

Quoted 7 lines

First off some thoughts on how I'd like to proceed.

The chip exposes the Bayer sensor output directly to the driver so the current driver uses code borrowed from libgphoto2 to do the Bayer decode in kernel. Obviously this is wrong and now we have libv4l it should use that instead.

Correct, there is nothing special you need to do for that, just pass frames with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR.. */
V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG.. */
V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG.. */ V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB.. */

Quoted 3 lines

Note the last 2 currently are only defined internally in libv4l and not in linux/videodev2.h as no drivers use them yet, but if you need one of them adding it to linux/videodev2.h is fine.

I'm currently developing a driver where I need the two lower ones in order to get a correct bayer decoding.
Would it possible to add them into the linux/videodev2.h?

I can send a patch tonight if required.

Thanks,
Erik

Quoted 84 lines

And then make sure your applications are either patched to use libv4l, or use
the LD_PRELOAD libc wrapper (see libv4l docs).

Quoted 2 lines

I don't have masses of time to work on this so I need an approach that isn't going to require writing loads of code.

Actually, the plan is to remove lots of code :)

Quoted 5 lines

Considering the mess the current
driver is in it is probably going to be better to make it a sub driver of gspca rather than try to re-use the existing code (which should also make life easier from a long term maintenance PoV).

Yes please make it a subdriver of gspca, then all you need to lift from the current driver are the chip specific initalization sequences, and the isoc frame parsing for detecting the beginning and ending of frames.

Quoted 6 lines

Now my questions

1) What kernel should I base any patches I produce on? The obvious choice would seem to be
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6.git but it seems as if Linus's 2.6 tree is more up to date for gspca.

Please use:
http://linuxtv.org/hg/~jfrancois/gspca/

Note that like al v4l-dvb trees this is a standalone tree, not a complete kernel, assuming you've got the headers installed for your current kernel you
can just do make menuconfig, make, make install from this tree (from the main
dir, not from the linux subdir) to update your current kernels video4linux modules to the latest, then add your own driver and rince repeat :)

Quoted 6 lines

2) The existing driver needed to perform a gamma adjustment after performing the Bayer decode. I couldn't find anything in libv4l that obviously did that so I'm guessing it isn't needed for existing devices - should that be added to libv4l if needed and if so how should the driver indicate it is needed - could it be indicated with a new value for v4l2_colorspace?

Hmm interesting for now lets ignore this and first get it up and running without this, and the revisit this. I'm asking for this because gamma correction might be interesting for other cams too, so I would like to see a generic solution for this, which will take some design work, etc.

Quoted 6 lines

3) The current driver needs to do some up/down and left/right flips of the data to get it in the right order to do the Bayer decode that depend on the version info the camera returns to its init sequence. Should that code remain in the driver and if not how should the driver communicate what is needed.

It should communicate what is needed all possible bayer orders are covered by
the 4 formats I gave above, and libv4l knows how to handle all 4 of them, for
the defines of the last 2 see libv4lconvert/libv4lconvert-priv.h

Quoted 4 lines

4) The current driver doesn't support streaming mode for V4L2 (only V4L1) and libv4l doesn't support cameras that don't support streaming so is there an easy way to test out if the camera output will work well with libv4l before starting work?

This should not be a problem. gspca now can work with both bulk and isochronyous usb transfers using cams, although your cam most likely is an isoc
one (bulk mode cams are rare).

Quoted 1 line

5) Is there anything else I should know before starting.

Not that I know, go for it!

Regards,

Hans

p.s.

Quoted 9 lines

In case it isn't clear I'm the author of libv4l and a contributer to gspca, as
said before: go for it and keep asking questions!

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#3 lore raw

Erik Andrén wrote:

<snip>

Quoted 13 lines
Quoted 9 lines

Correct, there is nothing special you need to do for that, just pass frames with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR.. */
V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG.. */
V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG.. */ V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB.. */

Quoted 3 lines

Note the last 2 currently are only defined internally in libv4l and not in linux/videodev2.h as no drivers use them yet, but if you need one of them adding it to linux/videodev2.h is fine.

Quoted 6 lines

I'm currently developing a driver where I need the two lower ones in order to get a correct bayer decoding.
Would it possible to add them into the linux/videodev2.h?

I can send a patch tonight if required.

It is usual for such patches to be submitted together with the driver using the new defines. Just be sure you define V4L2_PIX_FMT_SGRBG8 as v4l2_fourcc('G','R','B','G')
and
V4L2_PIX_FMT_SRGGB8 as v4l2_fourcc('R','G','G','B')

You can try sending a patch to Mauro as preperation for your driver, but I'm not sure he will take such a patch, he did not accept it from me in the past as no drivers were using them, maybe with a driver on the horizon he will accept such a patch.

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#4 lore raw

2008/11/18 Hans de Goede <[email protected]>:

Quoted 36 lines

Erik Andrén wrote:

<snip>

Quoted 19 lines
Quoted 14 lines

Correct, there is nothing special you need to do for that, just pass frames
with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR..
*/
V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG..
*/
V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG.. */
V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB.. */

Quoted 4 lines

Note the last 2 currently are only defined internally in libv4l and not in
linux/videodev2.h as no drivers use them yet, but if you need one of them adding it to linux/videodev2.h is fine.

Quoted 6 lines

I'm currently developing a driver where I need the two lower ones in order to get a correct bayer decoding.
Would it possible to add them into the linux/videodev2.h?

I can send a patch tonight if required.

It is usual for such patches to be submitted together with the driver using the new defines. Just be sure you define
V4L2_PIX_FMT_SGRBG8 as v4l2_fourcc('G','R','B','G')
and
V4L2_PIX_FMT_SRGGB8 as v4l2_fourcc('R','G','G','B')

Quoted 5 lines

You can try sending a patch to Mauro as preperation for your driver, but I'm not sure he will take such a patch, he did not accept it from me in the past as no drivers were using them, maybe with a driver on the horizon he will accept such a patch.

I'm currently in the process of porting the old quickcam driver [1] to the gspca framework sofar I have working video using the vv6410 sensor. Next step is to get the hdcs and pb0100 sensors up to speed. The driver will be tracked in
http://linuxtv.org/hg/~eandren/gspca-stv06xx/ (nothing pushed yet)

[1] http://qce-ga.sourceforge.net/

I'll let Jean-Francoise and Mauro know when it's ready for mainline submission.

Regards,
Erik

Quoted 4 lines

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#5 lore raw
Quoted 41 lines · Erik Andrén

2008/11/18 Hans de Goede <[email protected]>:

Quoted 34 lines

Erik Andrén wrote:

<snip>

Quoted 18 lines
Quoted 14 lines

Correct, there is nothing special you need to do for that, just pass frames
with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR..
*/
V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG..
*/
V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG.. */
V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB.. */

Quoted 4 lines

Note the last 2 currently are only defined internally in libv4l and not in
linux/videodev2.h as no drivers use them yet, but if you need one of them adding it to linux/videodev2.h is fine.

Quoted 6 lines

I'm currently developing a driver where I need the two lower ones in order to get a correct bayer decoding.
Would it possible to add them into the linux/videodev2.h?

I can send a patch tonight if required.

It is usual for such patches to be submitted together with the driver using the new defines. Just be sure you define
V4L2_PIX_FMT_SGRBG8 as v4l2_fourcc('G','R','B','G')
and
V4L2_PIX_FMT_SRGGB8 as v4l2_fourcc('R','G','G','B')

Quoted 5 lines

You can try sending a patch to Mauro as preperation for your driver, but I'm not sure he will take such a patch, he did not accept it from me in the past as no drivers were using them, maybe with a driver on the horizon he will accept such a patch.

Quoted 6 lines

I'm currently in the process of porting the old quickcam driver [1] to the gspca framework sofar I have working video using the vv6410 sensor. Next step is to get the hdcs and pb0100 sensors up to speed. The driver will be tracked in
http://linuxtv.org/hg/~eandren/gspca-stv06xx/ (nothing pushed yet)

Good! and <ugh> I've been working on the same, I'm nowhere near as far as you though, can you please put a tarbal or whatever somewhere, then I can see if there is anything in my version worth salvaging to improve your driver in some points.

I've access to an pb0100 using cam.

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#6 lore raw

2008/11/18 Hans de Goede <[email protected]>:

Quoted 51 lines
Quoted 50 lines · Erik Andrén

2008/11/18 Hans de Goede <[email protected]>:

Quoted 47 lines

Erik Andrén wrote:

<snip>

Quoted 22 lines
Quoted 16 lines

Correct, there is nothing special you need to do for that, just pass frames
with the raw bayer data to userspace and set the pixelformat to one of:
V4L2_PIX_FMT_SBGGR8 /* v4l2_fourcc('B', 'A', '8', '1'), 8 bit BGBG.. GRGR..
*/
V4L2_PIX_FMT_SGBRG8 /* v4l2_fourcc('G', 'B', 'R', 'G'), 8 bit GBGB.. RGRG..
*/
V4L2_PIX_FMT_SGRBG8 /* v4l2_fourcc('G','R','B','G'), 8 bit GRGR.. BGBG..
*/
V4L2_PIX_FMT_SRGGB8 /* v4l2_fourcc('R','G','G','B'), 8 bit RGRG.. GBGB..
*/

Quoted 5 lines

Note the last 2 currently are only defined internally in libv4l and not in
linux/videodev2.h as no drivers use them yet, but if you need one of them
adding it to linux/videodev2.h is fine.

Quoted 6 lines

I'm currently developing a driver where I need the two lower ones in order to get a correct bayer decoding.
Would it possible to add them into the linux/videodev2.h?

I can send a patch tonight if required.

It is usual for such patches to be submitted together with the driver using
the new defines. Just be sure you define V4L2_PIX_FMT_SGRBG8 as v4l2_fourcc('G','R','B','G')
and
V4L2_PIX_FMT_SRGGB8 as v4l2_fourcc('R','G','G','B')

You can try sending a patch to Mauro as preperation for your driver, but I'm
not sure he will take such a patch, he did not accept it from me in the past
as no drivers were using them, maybe with a driver on the horizon he will accept such a patch.

Quoted 8 lines
Quoted 6 lines

I'm currently in the process of porting the old quickcam driver [1] to the gspca framework sofar I have working video using the vv6410 sensor. Next step is to get the hdcs and pb0100 sensors up to speed. The driver will be tracked in
http://linuxtv.org/hg/~eandren/gspca-stv06xx/ (nothing pushed yet)

Good! and <ugh> I've been working on the same,

I should have announced my work earlier.

I'm nowhere near as far as

Quoted 3 lines

you though, can you please put a tarbal or whatever somewhere, then I can see if there is anything in my version worth salvaging to improve your driver in some points.

I'll push what I've got tonight.

Quoted 3 lines

I've access to an pb0100 using cam.

Great, I've sofar been unable to locate anyone with this sensor. The original projected is dead and it's mailinglists are infested with spam.

Regards,
Erik

Quoted 4 lines

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#7 lore raw
In reply to Hans de Goede
Quoted 10 lines · On Tue, 18 Nov 2008 13:52:13 +0100 Hans de Goede <[email protected]> wrote:
Quoted 7 lines · Erik Andrén

I'm currently in the process of porting the old quickcam driver [1] to the gspca framework sofar I have working video using the vv6410 sensor. Next step is to get the hdcs and pb0100 sensors up to speed. The driver will be tracked in
http://linuxtv.org/hg/~eandren/gspca-stv06xx/ (nothing pushed yet)

Quoted 5 lines

Good! and <ugh> I've been working on the same, I'm nowhere near as far as you though, can you please put a tarbal or whatever somewhere, then I can see if there is anything in my version worth salvaging to improve your driver in some points.

:) I also planned to work on this after the ov534 driver, I can do some testing if needed.

Quoted 2 lines

I've access to an pb0100 using cam.

Me too, eager to have it working in mainline.

Regards,
Antonio Ospite

Signature · 7 lines
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

  Web site: http://www.studenti.unina.it/~ospite
Public key: http://www.studenti.unina.it/~ospite/aopubkey.asc

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list