23 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/videodev2.h>
42 static unsigned int vidioc_debug;
46 static bool keep_buffers;
53 .name =
"16 bpp YUY2, 4:2:2, packed",
59 static void stk1160_set_std(
struct stk1160 *
dev)
63 static struct regval std525[] = {
82 static struct regval std625[] = {
104 for (i = 0; std525[
i].
reg != 0xffff; i++)
108 for (i = 0; std625[
i].
reg != 0xffff; i++)
118 static bool stk1160_set_alternate(
struct stk1160 *dev)
120 int i, prev_alt = dev->
alt;
121 unsigned int min_pkt_size;
130 for (i = 0; i < dev->
num_alt; i++) {
146 if (dev->
alt != prev_alt) {
147 stk1160_dbg(
"minimum isoc packet size: %u (alt=%d)\n",
148 min_pkt_size, dev->
alt);
149 stk1160_dbg(
"setting alt %d with wMaxPacketSize=%u\n",
160 static int stk1160_start_streaming(
struct stk1160 *dev)
177 new_pkt_size = stk1160_set_alternate(dev);
184 if (!dev->
isoc_ctl.num_bufs || new_pkt_size) {
191 for (i = 0; i < dev->
isoc_ctl.num_bufs; i++) {
194 stk1160_err(
"cannot submit urb[%d] (%d)\n", i, rc);
224 static void stk1160_stop_hw(
struct stk1160 *dev)
243 static int stk1160_stop_streaming(
struct stk1160 *dev)
257 stk1160_stop_hw(dev);
281 static int vidioc_querycap(
struct file *
file,
284 struct stk1160 *dev = video_drvdata(file);
297 static int vidioc_enum_fmt_vid_cap(
struct file *
file,
void *
priv,
308 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *priv,
311 struct stk1160 *dev = video_drvdata(file);
316 f->
fmt.
pix.pixelformat = dev->
fmt->fourcc;
324 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *priv,
327 struct stk1160 *dev = video_drvdata(file);
336 f->
fmt.
pix.pixelformat = dev->
fmt->fourcc;
347 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
350 struct stk1160 *dev = video_drvdata(file);
356 vidioc_try_fmt_vid_cap(file, priv, f);
363 static int vidioc_querystd(
struct file *file,
void *priv,
v4l2_std_id *norm)
365 struct stk1160 *dev = video_drvdata(file);
370 static int vidioc_g_std(
struct file *file,
void *priv,
v4l2_std_id *
norm)
372 struct stk1160 *dev = video_drvdata(file);
378 static int vidioc_s_std(
struct file *file,
void *priv,
v4l2_std_id *
norm)
380 struct stk1160 *dev = video_drvdata(file);
405 stk1160_set_std(dev);
414 static int vidioc_enum_input(
struct file *file,
void *priv,
417 struct stk1160 *dev = video_drvdata(file);
433 static int vidioc_g_input(
struct file *file,
void *priv,
unsigned int *i)
435 struct stk1160 *dev = video_drvdata(file);
440 static int vidioc_s_input(
struct file *file,
void *priv,
unsigned int i)
442 struct stk1160 *dev = video_drvdata(file);
444 if (vb2_is_busy(&dev->
vb_vidq))
457 static int vidioc_g_chip_ident(
struct file *file,
void *priv,
460 switch (chip->
match.type) {
470 #ifdef CONFIG_VIDEO_ADV_DEBUG
471 static int vidioc_g_register(
struct file *file,
void *priv,
474 struct stk1160 *dev = video_drvdata(file);
478 switch (reg->
match.type) {
502 static int vidioc_s_register(
struct file *file,
void *priv,
505 struct stk1160 *dev = video_drvdata(file);
507 switch (reg->
match.type) {
553 #ifdef CONFIG_VIDEO_ADV_DEBUG
554 .vidioc_g_register = vidioc_g_register,
555 .vidioc_s_register = vidioc_s_register,
565 unsigned int *nbuffers,
unsigned int *nplanes,
566 unsigned int sizes[],
void *alloc_ctxs[])
568 struct stk1160 *dev = vb2_get_drv_priv(vq);
577 *nbuffers =
clamp_t(
unsigned int, *nbuffers,
586 __func__, *nbuffers, size);
591 static void buffer_queue(
struct vb2_buffer *vb)
608 buf->
length = vb2_plane_size(vb, 0);
622 spin_unlock_irqrestore(&dev->
buf_lock, flags);
625 static int start_streaming(
struct vb2_queue *vq,
unsigned int count)
627 struct stk1160 *dev = vb2_get_drv_priv(vq);
628 return stk1160_start_streaming(dev);
632 static int stop_streaming(
struct vb2_queue *vq)
634 struct stk1160 *dev = vb2_get_drv_priv(vq);
635 return stk1160_stop_streaming(dev);
638 static struct vb2_ops stk1160_video_qops = {
640 .buf_queue = buffer_queue,
650 .fops = &stk1160_fops,
651 .ioctl_ops = &stk1160_ioctl_ops,
671 buf, buf->
vb.v4l2_buf.index);
675 spin_unlock_irqrestore(&dev->
buf_lock, flags);
688 q->
ops = &stk1160_video_qops;
706 dev->
vdev = v4l_template;
707 dev->
vdev.debug = vidioc_debug;
727 dev->
fmt = &format[0];
728 stk1160_set_std(dev);
733 video_set_drvdata(&dev->
vdev, dev);
736 stk1160_err(
"video_register_device failed (%d)\n", rc);
741 video_device_node_name(&dev->
vdev));