media: Add stk1160 new driver
PATCH v3 1/1 media: Add stk1160 new driver
This driver adds support for stk1160 usb bridge as used in some video/audio usb capture devices.
It is a complete rewrite of staging/media/easycap driver and it's expected as a future replacement.
---
Hi again,
As stk1160 allows communication with an ac97 codec chip, this driver registers a control-only sound card to allow the user to access ac97 controls.
This is achieved through snd_ac97_codec/ac97_bus drivers.
I'm not sure about this approach so feedback/flames are welcome/expected.
Testing has been performed using both vlc and mplayer on a gentoo machine, including hot unplug and on-the-fly standard and input switching using two kind of devices:
* 1-cvbs video and 1-audio ac97 input,
* 4-cvbs inputs
Both of these devices reports with the same id [05e1:0408], so the driver tries to support a superset of the capabilities.
As this is my first complete driver,
the patch (obviously) intended as RFC only.
Any comments/reviews of *any* kind will be greatly appreciated.
Changes from v2:
* Added support for multiple video input device
* Added ac97 initialization
* Register an ac97 sound card (mixer control only) to access ac97 registers.
Changes from v1:
* Use media control framework
* Register video device as the last thing
* Use v4l_device release to release all resources
* Add explicit locking for file operations
* Add vb2 buffer sanity check
* Minor style cleanups
--- drivers/media/video/Kconfig | 2 + drivers/media/video/Makefile | 1 + drivers/media/video/stk1160/Kconfig | 12 + drivers/media/video/stk1160/Makefile | 6 + drivers/media/video/stk1160/stk1160-ac97.c | 152 +++++ drivers/media/video/stk1160/stk1160-core.c | 441 +++++++++++++ drivers/media/video/stk1160/stk1160-i2c.c | 302 +++++++++ drivers/media/video/stk1160/stk1160-reg.h | 93 +++ drivers/media/video/stk1160/stk1160-v4l.c | 935 +++++++++++++++++++++++++++ drivers/media/video/stk1160/stk1160-video.c | 468 ++++++++++++++ drivers/media/video/stk1160/stk1160.h | 197 ++++++ 11 files changed, 2609 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/stk1160/Kconfig create mode 100644 drivers/media/video/stk1160/Makefile create mode 100644 drivers/media/video/stk1160/stk1160-ac97.c create mode 100644 drivers/media/video/stk1160/stk1160-core.c create mode 100644 drivers/media/video/stk1160/stk1160-i2c.c create mode 100644 drivers/media/video/stk1160/stk1160-reg.h create mode 100644 drivers/media/video/stk1160/stk1160-v4l.c create mode 100644 drivers/media/video/stk1160/stk1160-video.c create mode 100644 drivers/media/video/stk1160/stk1160.h
drivers/media/video/Kconfig +2 -0
@@ -661,6 +661,8 @@ source "drivers/media/video/hdpvr/Kconfig" source "drivers/media/video/em28xx/Kconfig" +source "drivers/media/video/stk1160/Kconfig" + source "drivers/media/video/tlg2300/Kconfig" source "drivers/media/video/cx231xx/Kconfig"
drivers/media/video/Makefile +1 -0
@@ -125,6 +125,7 @@ obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o obj-$(CONFIG_STA2X11_VIP) += sta2x11_vip.o obj-$(CONFIG_VIDEO_TIMBERDALE) += timblogiw.o +obj-$(CONFIG_VIDEO_STK1160) += stk1160/ obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
drivers/media/video/stk1160/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +config VIDEO_STK1160 + tristate "STK1160 USB video capture support" + depends on VIDEO_DEV && I2C && EASYCAP!=m && EASYCAP!=y + select VIDEOBUF2_VMALLOC + select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO + select SND_AC97_CODEC + + ---help--- + This is a video4linux driver for STK1160 based video capture devices + + To compile this driver as a module, choose M here: the + module will be called stk1160
drivers/media/video/stk1160/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +stk1160-y := stk1160-core.o stk1160-v4l.o stk1160-video.o stk1160-i2c.o stk1160-ac97.o + +obj-$(CONFIG_VIDEO_STK1160) += stk1160.o + +ccflags-y += -Wall +ccflags-y += -Idrivers/media/video
drivers/media/video/stk1160/stk1160-ac97.c new file +152 -0
152 lines not on this page · raw message
drivers/media/video/stk1160/stk1160-core.c new file +441 -0
441 lines not on this page · raw message
drivers/media/video/stk1160/stk1160-i2c.c new file +302 -0
302 lines not on this page · raw message
drivers/media/video/stk1160/stk1160-reg.h new file +93 -0
93 lines not on this page · raw message
drivers/media/video/stk1160/stk1160-v4l.c new file +935 -0
935 lines not on this page · raw message
drivers/media/video/stk1160/stk1160-video.c new file +468 -0
468 lines not on this page · raw message
drivers/media/video/stk1160/stk1160.h new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Quoted 34 lines · Ezequiel Garcia
This driver adds support for stk1160 usb bridge as used in some video/audio usb capture devices.
It is a complete rewrite of staging/media/easycap driver and it's expected as a future replacement.Signed-off-by Ezequiel Garcia <[email protected]>---
Hi again,As stk1160 allows communication with an ac97 codec chip, this driver registers a control-only sound card to allow the user to access ac97 controls.
This is achieved through snd_ac97_codec/ac97_bus drivers.
I'm not sure about this approach so feedback/flames are welcome/expected.Testing has been performed using both vlc and mplayer on a gentoo machine, including hot unplug and on-the-fly standard and input switching using two kind of devices:
* 1-cvbs video and 1-audio ac97 input,
* 4-cvbs inputsBoth of these devices reports with the same id [05e1:0408], so the driver tries to support a superset of the capabilities.
As this is my first complete driver,
the patch (obviously) intended as RFC only.
Any comments/reviews of *any* kind will be greatly appreciated.Changes from v2:
* Added support for multiple video input device
* Added ac97 initialization
* Register an ac97 sound card (mixer control only) to access ac97 registers.
Quoted 7 lines
Changes from v1:
* Use media control framework
* Register video device as the last thing
* Usev4l_devicerelease to release all resources
* Add explicit locking for file operations
* Add vb2 buffer sanity check
* Minor style cleanups
$ v4l2-compliance Driver Info: Driver name : stk1160 Card type : stk1160 Bus info : usb-0000:00:13.2-2 Driver version: 3.5.0 Capabilities : 0x85000001 Video Capture Read/Write Streaming Device Capabilities Device Caps : 0x05000001 Video Capture Read/Write Streaming
Compliance test for device /dev/video0 (not using libv4l2):
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
Debug ioctls:
test VIDIOC_DBG_G_CHIP_IDENT: OK
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK
Input ioctls:
test VIDIOC_G/S_TUNER: Not Supported
test VIDIOC_G/S_FREQUENCY: Not Supported
test VIDIOC_S_HW_FREQ_SEEK: Not Supported
test VIDIOC_ENUMAUDIO: Not Supported
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: Not Supported
Inputs: 4 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: Not Supported
test VIDIOC_G/S_FREQUENCY: Not Supported
test VIDIOC_ENUMAUDOUT: Not Supported
test VIDIOC_G/S/ENUMOUTPUT: Not Supported
test VIDIOC_G/S_AUDOUT: Not Supported
Outputs: 0 Audio Outputs: 0 Modulators: 0
Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: Not Supported Standard Controls: 7 Private Controls: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK
test VIDIOC_ENUM/G/S/QUERY_DV_PRESETS: Not Supported test VIDIOC_G/S_DV_TIMINGS: Not Supported
Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: Not Supported
test VIDIOC_G_FBUF: Not Supported
test VIDIOC_G_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: Not Supported
Total: 31 Succeeded: 31 Failed: 0 Warnings: 0
Hi Ezequiel,
a few minor comments below...
Quoted 7 lines · Ezequiel Garcia
This driver adds support for stk1160 usb bridge as used in some video/audio usb capture devices.
It is a complete rewrite of staging/media/easycap driver and it's expected as a future replacement.Signed-off-by Ezequiel Garcia<[email protected]>---
[...]
Quoted 6 lines
drivers/media/video/stk1160/stk1160-core.c new file +6
-0+/* +* Read/Write stk registers +*/ +int stk1160_read_reg (struct stk1160 *dev,u16 reg,u8 *value) +{ +int ret;
drivers/media/video/stk1160/stk1160-core.c line 80
Quoted 10 lines
drivers/media/video/stk1160/stk1160-core.c new file +10
-0+ + *value =0 ; + ret =usb_control_msg (dev->udev,usb_rcvctrlpipe (dev->udev,0 ), +0x00 , +USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_DEVICE , +0x00 , + reg, + value, +sizeof (u8), +HZ );
A bit strange indentation, but it's up to you to keep it or not.
Quoted 26 lines
drivers/media/video/stk1160/stk1160-core.c new file +26
-0+if (ret<0 ) { +stk1160_err ("read failed on reg 0x%x (%d)\n" , + reg, ret); +return ret; + } + +return 0 ; +} + +int stk1160_write_reg (struct stk1160 *dev,u16 reg,u16 value) +{ +int ret; + + ret =usb_control_msg (dev->udev,usb_sndctrlpipe (dev->udev,0 ), +0x01 , +USB_DIR_OUT |USB_TYPE_VENDOR |USB_RECIP_DEVICE , + value, + reg, +NULL , +0 , +HZ ); +if (ret<0 ) { +stk1160_err ("write failed on reg 0x%x (%d)\n" , + reg, ret); +return ret; + }
drivers/media/video/stk1160/stk1160-core.c line 116
Quoted 10 lines
drivers/media/video/stk1160/stk1160-core.c new file +10
-0+ +return 0 ; +} + +/* TODO: We should break this into pieces */ +static void stk1160_reg_reset (struct stk1160 *dev) +{ +int i; + +static struct regval ctl[] = {
static const struct regval... ?
Quoted 30 lines
drivers/media/video/stk1160/stk1160-core.c new file +30
-0+ {STK1160_GCTRL+2, 0x0078}, + + {STK1160_RMCTL+1, 0x0000}, + {STK1160_RMCTL+3, 0x0002}, + + {STK1160_PLLSO, 0x0010}, + {STK1160_PLLSO+1, 0x0000}, + {STK1160_PLLSO+2, 0x0014}, + {STK1160_PLLSO+3, 0x000E}, + + {STK1160_PLLFD, 0x0046}, + +/* Timing generator setup */ + {STK1160_TIGEN, 0x0012}, + {STK1160_TICTL, 0x002D}, + {STK1160_TICTL+1, 0x0001}, + {STK1160_TICTL+2, 0x0000}, + {STK1160_TICTL+3, 0x0000}, + {STK1160_TIGEN, 0x0080}, + + {0xffff, 0xffff} + }; + +for (i =0 ; ctl[i].reg !=0xffff ; i++) +stk1160_write_reg (dev, ctl[i].reg, ctl[i].val); + +/* Set selected input from module parameter */ +switch (dev->ctl_input) { +case 0 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x98 );
drivers/media/video/stk1160/stk1160-core.c line 156
Quoted 10 lines
drivers/media/video/stk1160/stk1160-core.c new file +10
-0+break ; +case 1 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x90 ); +break ; +case 2 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x88 ); +break ; +case 3 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x80 ); +break ;
How about doing something like:
static const u8 gctrl[] = {
0x98, 0x90, 0x88, 0x80
};
if (dev->ctl_input < ARRAY_SIZE(gctrl))
stk1160_write_reg(dev, STK1160_GCTRL, gctrl[dev->ctl_input]);?
Quoted 3 lines
drivers/media/video/stk1160/stk1160-ac97.c new file +3
-0+ } +} +
...
Quoted 26 lines
drivers/media/video/stk1160/stk1160-i2c.c new file +26
-0+static int stk1160_i2c_write_reg (struct stk1160 *dev,u8 addr, +u8 reg,u8 value) +{ +int rc, timeout; +u8 flag; + +/* Set serial device address */ + rc =stk1160_write_reg (dev,STK1160_SICTL_SDA , addr); +if (rc<0 ) +return rc; + +/* Set i2c device register sub-address */ + rc =stk1160_write_reg (dev,STK1160_SBUSW_WA , reg); +if (rc<0 ) +return rc; + +/* Set i2c device register value */ + rc =stk1160_write_reg (dev,STK1160_SBUSW_WD , value); +if (rc<0 ) +return rc; + +/* Start write now */ + rc =stk1160_write_reg (dev,STK1160_SICTL ,0x01 ); +if (rc<0 ) +return rc; +
drivers/media/video/stk1160/stk1160-i2c.c line 75
Quoted 10 lines
drivers/media/video/stk1160/stk1160-i2c.c new file +10
-0+/* Wait until Write Finish bit is set */ +for (timeout =100 ; timeout>0 ; + timeout -=20 ) { +stk1160_read_reg (dev,STK1160_SICTL +1 ,&flag); +/* write done? */ +if (flag&0x04 ) +break ; + +msleep (20 ); + }
A bit strange loop, perhaps it's worth to rework it as following:
unsigned long end = jiffies + msecs_to_jiffies(timeout);
while (time_is_after_jiffies(end)) {
...
usleep_range(...);
}to better control the actual time spent on busy waiting. You may also want to create a separate function i.e.
stk1160_i2c_busy_wait(struct stk1160 *dev, u8 wait_bit_mask, unsigned int timeout) and use to avoid repeating similar pattern.
drivers/media/video/stk1160/stk1160-i2c.c line 78
Quoted 3 lines
drivers/media/video/stk1160/stk1160-i2c.c new file +3
-0+ +if (timeout ==0 ) +/* return EBUSY, or EFAULT, or what ? */
-ETIMEDOUT ?
Quoted 86 lines
drivers/media/video/stk1160/stk1160-i2c.c new file +86
-0+return -EIO ; + +return 0 ; +} + +static int stk1160_i2c_read_reg (struct stk1160 *dev,u8 addr, +u8 reg,u8 *value) +{ +int rc, timeout; +u8 flag; + +/* Set serial device address */ + rc =stk1160_write_reg (dev,STK1160_SICTL_SDA , addr); +if (rc<0 ) +return rc; + +/* Set i2c device register sub-address */ + rc =stk1160_write_reg (dev,STK1160_SBUSR_RA , reg); +if (rc<0 ) +return rc; + +/* Start read now */ + rc =stk1160_write_reg (dev,STK1160_SICTL ,0x20 ); +if (rc<0 ) +return rc; + +/* Wait until Read Finish bit is set */ +for (timeout =100 ; timeout>0 ; + timeout -=20 ) { +stk1160_read_reg (dev,STK1160_SICTL +1 ,&flag); +/* read done? */ +if (flag&0x01 ) +break ; + +msleep (20 ); + } + +if (timeout ==0 ) +/* return EBUSY, or EFAULT, or what ? */ +return -EIO ; + +stk1160_read_reg (dev,STK1160_SBUSR_RD , value); +if (rc<0 ) +return rc; + +return 0 ; +} + +/* +* stk1160_i2c_check_for_device() +* check if there is a i2c_device at the supplied address +*/ +static int stk1160_i2c_check_for_device (struct stk1160 *dev, +unsigned char addr) +{ +int rc, write_timeout; +u8 flag; + +/* Set serial device address */ + rc =stk1160_write_reg (dev,STK1160_SICTL_SDA , addr); +if (rc<0 ) +return rc; + +/* Set device sub-address, we'll chip version reg */ + rc =stk1160_write_reg (dev,STK1160_SBUSR_RA ,0x00 ); +if (rc<0 ) +return rc; + +/* Start read now */ + rc =stk1160_write_reg (dev,STK1160_SICTL ,0x20 ); +if (rc<0 ) +return rc; + +/* Wait until Read Finish bit is set */ +for (write_timeout =40 ; write_timeout>0 ; + write_timeout -=20 ) { +stk1160_read_reg (dev,STK1160_SICTL +1 ,&flag); +if (flag&0x01 ) +return 0 ; + +msleep (20 ); + } + +return -ENODEV ; +} +
...
drivers/media/video/stk1160/stk1160-reg.h line 27
Quoted 6 lines
drivers/media/video/stk1160/stk1160-reg.h new file +6
-0+ +/* GPIO Control */ +#define STK1160_GCTRL 0x000 + +/* Remote Wakup Control */ +#define STK1160_RMCTL 0x00C
Care to use lower case for all hex numbers ?
Quoted 66 lines
drivers/media/video/stk1160/stk1160-reg.h new file +66
-0+ +/* +* Decoder Control Register: +* This byte controls capture start/stop +* with bit #7 (0x?? OR 0x80 to activate). +*/ +#define STK1160_DCTRL 0x100 + +/* Capture Frame Start Position */ +#define STK116_CFSPO 0x110 +#define STK116_CFSPO_STX_L 0x110 +#define STK116_CFSPO_STX_H 0x111 +#define STK116_CFSPO_STY_L 0x112 +#define STK116_CFSPO_STY_H 0x113 + +/* Capture Frame End Position */ +#define STK116_CFEPO 0x114 +#define STK116_CFEPO_ENX_L 0x114 +#define STK116_CFEPO_ENX_H 0x115 +#define STK116_CFEPO_ENY_L 0x116 +#define STK116_CFEPO_ENY_H 0x117 + +/* Serial Interface Control */ +#define STK1160_SICTL 0x200 +#define STK1160_SICTL_CD 0x202 +#define STK1160_SICTL_SDA 0x203 + +/* Serial Bus Write */ +#define STK1160_SBUSW 0x204 +#define STK1160_SBUSW_WA 0x204 +#define STK1160_SBUSW_WD 0x205 + +/* Serial Bus Read */ +#define STK1160_SBUSR 0x208 +#define STK1160_SBUSR_RA 0x208 +#define STK1160_SBUSR_RD 0x209 + +/* Alternate Serial Inteface Control */ +#define STK1160_ASIC 0x2FC + +/* PLL Select Options */ +#define STK1160_PLLSO 0x018 + +/* PLL Frequency Divider */ +#define STK1160_PLLFD 0x01C + +/* Timing Generator */ +#define STK1160_TIGEN 0x300 + +/* Timing Control Parameter */ +#define STK1160_TICTL 0x350 + +/* AC97 Audio Control */ +#define STK1160_AC97CTL_0 0x500 +#define STK1160_AC97CTL_1 0x504 + +/* Use [0:6] bits of register 0x504 to set codec command address */ +#define STK1160_AC97_ADDR 0x504 +/* Use [16:31] bits of register 0x500 to set codec command data */ +#define STK1160_AC97_CMD 0x502 + +/* Audio I2S Interface */ +#define STK1160_I2SCTL 0x50c + +/* EEPROM Interface */ +#define STK1160_EEPROM_SZ 0x5f0
...
drivers/media/video/stk1160/stk1160-v4l.c line 374
Quoted 11 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +11
-0+static int vidioc_querybuf (struct file *file,void *priv,struct v4l2_buffer *p) +{ +struct stk1160 *dev =video_drvdata (file); +int rc; + +if (!stk1160_is_owner (dev, file)) +return -EBUSY ; + + rc =vb2_querybuf (&dev->vb_vidq, p); + +return rc;
What about dropping the local "rc" variable here ?
drivers/media/video/stk1160/stk1160-v4l.c line 387
Quoted 13 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +13
-0+} + +static int vidioc_qbuf (struct file *file,void *priv,struct v4l2_buffer *p) +{ +struct stk1160 *dev =video_drvdata (file); +int rc; + +if (!stk1160_is_owner (dev, file)) +return -EBUSY ; + + rc =vb2_qbuf (&dev->vb_vidq, p); + +return rc;
Ditto.
drivers/media/video/stk1160/stk1160-v4l.c line 400
Quoted 13 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +13
-0+} + +static int vidioc_dqbuf (struct file *file,void *priv,struct v4l2_buffer *p) +{ +struct stk1160 *dev =video_drvdata (file); +int rc; + +if (!stk1160_is_owner (dev, file)) +return -EBUSY ; + + rc =vb2_dqbuf (&dev->vb_vidq, p, file->f_flags&O_NONBLOCK ); + +return rc;
Ditto.
drivers/media/video/stk1160/stk1160-v4l.c line 413
Quoted 13 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +13
-0+} + +static int vidioc_streamon (struct file *file,void *priv,enum v4l2_buf_type i) +{ +struct stk1160 *dev =video_drvdata (file); +int rc; + +if (!stk1160_is_owner (dev, file)) +return -EBUSY ; + + rc =vb2_streamon (&dev->vb_vidq, i); + +return rc;
Ditto.
drivers/media/video/stk1160/stk1160-v4l.c line 426
Quoted 13 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +13
-0+} + +static int vidioc_streamoff (struct file *file,void *priv,enum v4l2_buf_type i) +{ +struct stk1160 *dev =video_drvdata (file); +int rc; + +if (!stk1160_is_owner (dev, file)) +return -EBUSY ; + + rc =vb2_streamoff (&dev->vb_vidq, i); + +return rc;
Ditto.
Quoted 5 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +5
-0+} + +/* +* vidioc ioctls +*/
...
Quoted 16 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +16
-0+static int vidioc_s_input (struct file *file,void *priv,unsigned int i) +{ +struct stk1160 *dev =video_drvdata (file); + +if (!stk1160_acquire_owner (dev, file)) +return -EBUSY ; + +if (i>STK1160_MAX_INPUT ) +return -EINVAL ; + + dev->ctl_input = i; + +switch (dev->ctl_input) { +case 0 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x98 ); +break ;
drivers/media/video/stk1160/stk1160-v4l.c line 627
Quoted 10 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +10
-0+case 1 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x90 ); +break ; +case 2 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x88 ); +break ; +case 3 : +stk1160_write_reg (dev,STK1160_GCTRL ,0x80 ); +break ; + }
Same block of code as in stk1160_reg_reset(). Probably it's worth to move it into separate function.
Quoted 4 lines
drivers/media/video/stk1160/stk1160-ac97.c new file +4
-0+ +return 0 ; +} +
...
Quoted 23 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +23
-0+/* +* Videobuf2 operations +*/ +static int queue_setup (struct vb2_queue *vq,const struct v4l2_format *v4l_fmt, +unsigned int *nbuffers,unsigned int *nplanes, +unsigned int sizes[],void *alloc_ctxs[]) +{ +struct stk1160 *dev =vb2_get_drv_priv (vq); +unsigned long size; + + size = dev->width * dev->height *2 ; + +/* +* Here we can change the number of buffers being requested. +* So, we set a minimum and a maximum like this: +*/ + *nbuffers = clamp_t(unsigned int, *nbuffers, +STK1160_MIN_VIDEO_BUFFERS ,STK1160_MAX_VIDEO_BUFFERS ); + +/* This means a packed colorformat */ + *nplanes =1 ; + + sizes[0 ] = size;
drivers/media/video/stk1160/stk1160-v4l.c line 784
Quoted 10 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +10
-0+ +stk1160_info ("%s: buffer count %d, each %ld bytes\n" , + __func__, *nbuffers, size); + +return 0 ; +} + +static void buffer_queue (struct vb2_buffer *vb) +{ +unsigned long flags =0 ;
No need to initialize here.
Quoted 13 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +13
-0+struct stk1160 *dev =vb2_get_drv_priv (vb->vb2_queue); +struct stk1160_buffer *buf = + container_of(vb, struct stk1160_buffer, vb); + +spin_lock_irqsave (&dev->buf_lock, flags); +if (!dev->udev) { +/* +* If the device is disconnected return the buffer to userspace +* directly. The next QBUF call will fail with -ENODEV. +*/ +vb2_buffer_done (&buf->vb,VB2_BUF_STATE_ERROR ); + }else { +
drivers/media/video/stk1160/stk1160-v4l.c line 807
Quoted 10 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +10
-0+ buf->mem =vb2_plane_vaddr (vb,0 ); + buf->length =vb2_plane_size (vb,0 ); + buf->bytesused =0 ; + buf->pos =0 ; + +/* +* If buffer length is different from expected then we return +* the buffer to userspace directly. +*/ +if (buf->length != dev->width * dev->height *2 )
It should be OK when the buffer size is larger than the amount of data the device will be writing to it. So it's better to change the condition statement to:
if (buf->length < dev->width * dev->height * 2)
drivers/media/video/stk1160/stk1160-v4l.c line 819
Quoted 12 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +12
-0+vb2_buffer_done (&buf->vb,VB2_BUF_STATE_ERROR ); + else + list_add_tail(&buf->list,&dev->avail_bufs); + + } +spin_unlock_irqrestore (&dev->buf_lock, flags); +} + +static int start_streaming (struct vb2_queue *vq,unsigned int count) +{ +struct stk1160 *dev =vb2_get_drv_priv (vq); +int rc;
Not needed ?
drivers/media/video/stk1160/stk1160-v4l.c line 830
Quoted 11 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +11
-0+ + rc =stk1160_start_streaming (dev); + +return rc; +} + +/* abort streaming and wait for last buffer */ +static int stop_streaming (struct vb2_queue *vq) +{ +struct stk1160 *dev =vb2_get_drv_priv (vq); +int rc;
?
drivers/media/video/stk1160/stk1160-v4l.c line 835
Quoted 5 lines
drivers/media/video/stk1160/stk1160-v4l.c new file +5
-0+ + rc =stk1160_stop_streaming (dev, true); + +return rc; +}
--
Regards,
Sylwester
Quoted 3 lines · Sylwester Nawrocki
Hi Ezequiel,
a few minor comments below...
Hi Sylwester,
I'm OK with every comment you made.
Except for the -ETIMEDOUT.
I'm still not 100% convinced, but I'll take your word for it.
Also, is there any other serious issue preventing us from replacing staging/easycap
with stk1160?
Thank a lot for your review,
Ezequiel.
Quoted 6 lines · Ezequiel Garcia
Hi Sylwester,
I'm OK with every comment you made.
Except for the
-ETIMEDOUT.
I'm still not 100% convinced, but I'll take your word for it.
It looked most appropriate to me, however I didn't really analyse very deeply the whole driver to see how it would have been propagated. That's just a humble suggestion.
Good luck with those works! :)
---
Regards,
Sylwester