Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX25821 PCIe bridge |
| 3 | * |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 4 | * Copyright (C) 2009 Conexant Systems Inc. |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 5 | * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 6 | * Based on Steven Toth <stoth@linuxtv.org> cx25821 driver |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 7 | * Parts adapted/taken from Eduardo Moscoso Rubino |
| 8 | * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com> |
| 9 | * |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * |
| 20 | * GNU General Public License for more details. |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 21 | */ |
| 22 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 25 | #include "cx25821-video.h" |
| 26 | |
| 27 | MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 28 | MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Mauro Carvalho Chehab | 53e712d | 2009-09-13 11:39:12 -0300 | [diff] [blame] | 31 | static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 32 | |
| 33 | module_param_array(video_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 34 | |
| 35 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 36 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 37 | static unsigned int video_debug = VIDEO_DEBUG; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 38 | module_param(video_debug, int, 0644); |
| 39 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
| 40 | |
| 41 | static unsigned int irq_debug; |
| 42 | module_param(irq_debug, int, 0644); |
| 43 | MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); |
| 44 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 45 | #define FORMAT_FLAGS_PACKED 0x01 |
| 46 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 47 | static const struct cx25821_fmt formats[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 48 | { |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 49 | .name = "4:1:1, packed, Y41P", |
| 50 | .fourcc = V4L2_PIX_FMT_Y41P, |
| 51 | .depth = 12, |
| 52 | .flags = FORMAT_FLAGS_PACKED, |
| 53 | }, { |
| 54 | .name = "4:2:2, packed, YUYV", |
| 55 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 56 | .depth = 16, |
| 57 | .flags = FORMAT_FLAGS_PACKED, |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 58 | }, |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 59 | }; |
| 60 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 61 | static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 62 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 63 | unsigned int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 64 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 65 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 66 | if (formats[i].fourcc == fourcc) |
| 67 | return formats + i; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 68 | return NULL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 69 | } |
| 70 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 71 | int cx25821_start_video_dma(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 72 | struct cx25821_dmaqueue *q, |
| 73 | struct cx25821_buffer *buf, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 74 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 75 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 76 | int tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 77 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 78 | /* setup fifo + format */ |
| 79 | cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 80 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 81 | /* reset counter */ |
| 82 | cx_write(channel->gpcnt_ctl, 3); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 83 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 84 | /* enable irq */ |
| 85 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); |
| 86 | cx_set(channel->int_msk, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 87 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 88 | /* start dma */ |
| 89 | cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 90 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 91 | /* make sure upstream setting if any is reversed */ |
| 92 | tmp = cx_read(VID_CH_MODE_SEL); |
| 93 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 94 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 95 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 96 | } |
| 97 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 98 | int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) |
| 99 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 100 | int handled = 0; |
| 101 | u32 mask; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 102 | const struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 103 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 104 | mask = cx_read(channel->int_msk); |
| 105 | if (0 == (status & mask)) |
| 106 | return handled; |
| 107 | |
| 108 | cx_write(channel->int_stat, status); |
| 109 | |
| 110 | /* risc op code error */ |
| 111 | if (status & (1 << 16)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 112 | pr_warn("%s, %s: video risc op code error\n", |
| 113 | dev->name, channel->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 114 | cx_clear(channel->dma_ctl, 0x11); |
| 115 | cx25821_sram_channel_dump(dev, channel); |
| 116 | } |
| 117 | |
| 118 | /* risc1 y */ |
| 119 | if (status & FLD_VID_DST_RISC1) { |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 120 | struct cx25821_dmaqueue *dmaq = |
| 121 | &dev->channels[channel->i].dma_vidq; |
| 122 | struct cx25821_buffer *buf; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 123 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 124 | spin_lock(&dev->slock); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 125 | if (!list_empty(&dmaq->active)) { |
| 126 | buf = list_entry(dmaq->active.next, |
| 127 | struct cx25821_buffer, queue); |
| 128 | |
Junghak Sung | d6dd645 | 2015-11-03 08:16:37 -0200 | [diff] [blame] | 129 | buf->vb.vb2_buf.timestamp = ktime_get_ns(); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 130 | buf->vb.sequence = dmaq->count++; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 131 | list_del(&buf->queue); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 132 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 133 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 134 | spin_unlock(&dev->slock); |
| 135 | handled++; |
| 136 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 137 | return handled; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 138 | } |
| 139 | |
Hans Verkuil | df9ecb0c | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 140 | static int cx25821_queue_setup(struct vb2_queue *q, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 141 | unsigned int *num_buffers, unsigned int *num_planes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 142 | unsigned int sizes[], struct device *alloc_devs[]) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 143 | { |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 144 | struct cx25821_channel *chan = q->drv_priv; |
Hans Verkuil | 11c8a2d | 2014-12-12 10:27:59 -0300 | [diff] [blame] | 145 | unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3; |
| 146 | |
Hans Verkuil | df9ecb0c | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 147 | if (*num_planes) |
| 148 | return sizes[0] < size ? -EINVAL : 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 149 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 150 | *num_planes = 1; |
Hans Verkuil | df9ecb0c | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 151 | sizes[0] = size; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 152 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 153 | } |
| 154 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 155 | static int cx25821_buffer_prepare(struct vb2_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 156 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 157 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 158 | struct cx25821_channel *chan = vb->vb2_queue->drv_priv; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 159 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 160 | struct cx25821_buffer *buf = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 161 | container_of(vbuf, struct cx25821_buffer, vb); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 162 | struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 163 | u32 line0_offset; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 164 | int bpl_local = LINE_SIZE_D1; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 165 | int ret; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 166 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 167 | if (chan->pixel_formats == PIXEL_FRMT_411) |
| 168 | buf->bpl = (chan->fmt->depth * chan->width) >> 3; |
| 169 | else |
| 170 | buf->bpl = (chan->fmt->depth >> 3) * chan->width; |
| 171 | |
| 172 | if (vb2_plane_size(vb, 0) < chan->height * buf->bpl) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 173 | return -EINVAL; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 174 | vb2_set_plane_payload(vb, 0, chan->height * buf->bpl); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 175 | buf->vb.field = chan->field; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 176 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 177 | if (chan->pixel_formats == PIXEL_FRMT_411) { |
| 178 | bpl_local = buf->bpl; |
| 179 | } else { |
| 180 | bpl_local = buf->bpl; /* Default */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 181 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 182 | if (chan->use_cif_resolution) { |
| 183 | if (dev->tvnorm & V4L2_STD_625_50) |
| 184 | bpl_local = 352 << 1; |
| 185 | else |
| 186 | bpl_local = chan->cif_width << 1; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 187 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 188 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 189 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 190 | switch (chan->field) { |
| 191 | case V4L2_FIELD_TOP: |
| 192 | ret = cx25821_risc_buffer(dev->pci, &buf->risc, |
| 193 | sgt->sgl, 0, UNSET, |
| 194 | buf->bpl, 0, chan->height); |
| 195 | break; |
| 196 | case V4L2_FIELD_BOTTOM: |
| 197 | ret = cx25821_risc_buffer(dev->pci, &buf->risc, |
| 198 | sgt->sgl, UNSET, 0, |
| 199 | buf->bpl, 0, chan->height); |
| 200 | break; |
| 201 | case V4L2_FIELD_INTERLACED: |
| 202 | /* All other formats are top field first */ |
| 203 | line0_offset = 0; |
| 204 | dprintk(1, "top field first\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 205 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 206 | ret = cx25821_risc_buffer(dev->pci, &buf->risc, |
| 207 | sgt->sgl, line0_offset, |
| 208 | bpl_local, bpl_local, bpl_local, |
| 209 | chan->height >> 1); |
| 210 | break; |
| 211 | case V4L2_FIELD_SEQ_TB: |
| 212 | ret = cx25821_risc_buffer(dev->pci, &buf->risc, |
| 213 | sgt->sgl, |
| 214 | 0, buf->bpl * (chan->height >> 1), |
| 215 | buf->bpl, 0, chan->height >> 1); |
| 216 | break; |
| 217 | case V4L2_FIELD_SEQ_BT: |
| 218 | ret = cx25821_risc_buffer(dev->pci, &buf->risc, |
| 219 | sgt->sgl, |
| 220 | buf->bpl * (chan->height >> 1), 0, |
| 221 | buf->bpl, 0, chan->height >> 1); |
| 222 | break; |
| 223 | default: |
| 224 | WARN_ON(1); |
| 225 | ret = -EINVAL; |
| 226 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 227 | } |
| 228 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 229 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 230 | buf, buf->vb.vb2_buf.index, chan->width, chan->height, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 231 | chan->fmt->depth, chan->fmt->name, |
| 232 | (unsigned long)buf->risc.dma); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 233 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 234 | return ret; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 235 | } |
| 236 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 237 | static void cx25821_buffer_finish(struct vb2_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 238 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 239 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 240 | struct cx25821_buffer *buf = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 241 | container_of(vbuf, struct cx25821_buffer, vb); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 242 | struct cx25821_channel *chan = vb->vb2_queue->drv_priv; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 243 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 244 | |
| 245 | cx25821_free_buffer(dev, buf); |
| 246 | } |
| 247 | |
| 248 | static void cx25821_buffer_queue(struct vb2_buffer *vb) |
| 249 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 250 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 251 | struct cx25821_buffer *buf = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 252 | container_of(vbuf, struct cx25821_buffer, vb); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 253 | struct cx25821_channel *chan = vb->vb2_queue->drv_priv; |
| 254 | struct cx25821_dev *dev = chan->dev; |
| 255 | struct cx25821_buffer *prev; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 256 | struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 257 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 258 | buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 12); |
| 259 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); |
| 260 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 12); |
| 261 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 262 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 263 | if (list_empty(&q->active)) { |
| 264 | list_add_tail(&buf->queue, &q->active); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 265 | } else { |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 266 | buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 267 | prev = list_entry(q->active.prev, struct cx25821_buffer, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 268 | queue); |
| 269 | list_add_tail(&buf->queue, &q->active); |
| 270 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 271 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 272 | } |
| 273 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 274 | static int cx25821_start_streaming(struct vb2_queue *q, unsigned int count) |
| 275 | { |
| 276 | struct cx25821_channel *chan = q->drv_priv; |
| 277 | struct cx25821_dev *dev = chan->dev; |
| 278 | struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq; |
| 279 | struct cx25821_buffer *buf = list_entry(dmaq->active.next, |
| 280 | struct cx25821_buffer, queue); |
| 281 | |
| 282 | dmaq->count = 0; |
| 283 | cx25821_start_video_dma(dev, dmaq, buf, chan->sram_channels); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static void cx25821_stop_streaming(struct vb2_queue *q) |
| 288 | { |
| 289 | struct cx25821_channel *chan = q->drv_priv; |
| 290 | struct cx25821_dev *dev = chan->dev; |
| 291 | struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq; |
| 292 | unsigned long flags; |
| 293 | |
| 294 | cx_write(chan->sram_channels->dma_ctl, 0); /* FIFO and RISC disable */ |
| 295 | spin_lock_irqsave(&dev->slock, flags); |
| 296 | while (!list_empty(&dmaq->active)) { |
| 297 | struct cx25821_buffer *buf = list_entry(dmaq->active.next, |
| 298 | struct cx25821_buffer, queue); |
| 299 | |
| 300 | list_del(&buf->queue); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 301 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 302 | } |
| 303 | spin_unlock_irqrestore(&dev->slock, flags); |
| 304 | } |
| 305 | |
Julia Lawall | 10accd2 | 2016-09-08 20:59:18 -0300 | [diff] [blame] | 306 | static const struct vb2_ops cx25821_video_qops = { |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 307 | .queue_setup = cx25821_queue_setup, |
| 308 | .buf_prepare = cx25821_buffer_prepare, |
| 309 | .buf_finish = cx25821_buffer_finish, |
| 310 | .buf_queue = cx25821_buffer_queue, |
| 311 | .wait_prepare = vb2_ops_wait_prepare, |
| 312 | .wait_finish = vb2_ops_wait_finish, |
| 313 | .start_streaming = cx25821_start_streaming, |
| 314 | .stop_streaming = cx25821_stop_streaming, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 315 | }; |
| 316 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 317 | /* VIDEO IOCTLS */ |
Hans Verkuil | 4c1d0f7 | 2013-04-14 07:13:02 -0300 | [diff] [blame] | 318 | |
| 319 | static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 320 | struct v4l2_fmtdesc *f) |
| 321 | { |
| 322 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 323 | return -EINVAL; |
| 324 | |
| 325 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 326 | f->pixelformat = formats[f->index].fourcc; |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 331 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 332 | struct v4l2_format *f) |
| 333 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 334 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 335 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 336 | f->fmt.pix.width = chan->width; |
| 337 | f->fmt.pix.height = chan->height; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 338 | f->fmt.pix.field = chan->field; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 339 | f->fmt.pix.pixelformat = chan->fmt->fourcc; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 340 | f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; |
| 341 | f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; |
| 342 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 348 | struct v4l2_format *f) |
| 349 | { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 350 | struct cx25821_channel *chan = video_drvdata(file); |
| 351 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 352 | const struct cx25821_fmt *fmt; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 353 | enum v4l2_field field = f->fmt.pix.field; |
Mauro Carvalho Chehab | 66f9317 | 2013-04-25 15:46:36 -0300 | [diff] [blame] | 354 | unsigned int maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 355 | unsigned w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 356 | |
| 357 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 358 | if (NULL == fmt) |
| 359 | return -EINVAL; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 360 | maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 361 | |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 362 | w = f->fmt.pix.width; |
| 363 | if (field != V4L2_FIELD_BOTTOM) |
| 364 | field = V4L2_FIELD_TOP; |
| 365 | if (w < 352) { |
| 366 | w = 176; |
| 367 | f->fmt.pix.height = maxh / 4; |
| 368 | } else if (w < 720) { |
| 369 | w = 352; |
| 370 | f->fmt.pix.height = maxh / 2; |
| 371 | } else { |
| 372 | w = 720; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 373 | f->fmt.pix.height = maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 374 | field = V4L2_FIELD_INTERLACED; |
| 375 | } |
| 376 | f->fmt.pix.field = field; |
| 377 | f->fmt.pix.width = w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 378 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 379 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 380 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 381 | |
| 382 | return 0; |
| 383 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 384 | |
| 385 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 386 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 387 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 388 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 389 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 390 | int pix_format = PIXEL_FRMT_422; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 391 | int err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 392 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 393 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 394 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 395 | if (0 != err) |
| 396 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 397 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 398 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 399 | chan->field = f->fmt.pix.field; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 400 | chan->width = f->fmt.pix.width; |
| 401 | chan->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 402 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 403 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 404 | pix_format = PIXEL_FRMT_411; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 405 | else |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 406 | pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 407 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 408 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 409 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 410 | /* check if cif resolution */ |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 411 | if (chan->width == 320 || chan->width == 352) |
| 412 | chan->use_cif_resolution = 1; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 413 | else |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 414 | chan->use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 415 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 416 | chan->cif_width = chan->width; |
| 417 | medusa_set_resolution(dev, chan->width, SRAM_CH00); |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 418 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 419 | } |
| 420 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 421 | static int vidioc_log_status(struct file *file, void *priv) |
| 422 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 423 | struct cx25821_channel *chan = video_drvdata(file); |
| 424 | struct cx25821_dev *dev = chan->dev; |
| 425 | const struct sram_channel *sram_ch = chan->sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 426 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 427 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 428 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 429 | pr_info("Video input 0 is %s\n", |
| 430 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 431 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 432 | } |
| 433 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 434 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 435 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 436 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 437 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 438 | struct cx25821_channel *chan = video_drvdata(file); |
| 439 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 440 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 441 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
Hans Verkuil | 0df13d9 | 2013-04-14 07:14:42 -0300 | [diff] [blame] | 442 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 443 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 444 | strcpy(cap->driver, "cx25821"); |
| 445 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 446 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 447 | if (chan->id >= VID_CHANNEL_NUM) |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 448 | cap->device_caps = cap_output; |
| 449 | else |
| 450 | cap->device_caps = cap_input; |
Hans Verkuil | 0df13d9 | 2013-04-14 07:14:42 -0300 | [diff] [blame] | 451 | cap->capabilities = cap_input | cap_output | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 452 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 453 | } |
| 454 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 455 | static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms) |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 456 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 457 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 458 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 459 | *tvnorms = chan->dev->tvnorm; |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Mauro Carvalho Chehab | a3f17af | 2013-04-25 15:49:33 -0300 | [diff] [blame] | 463 | static int cx25821_vidioc_s_std(struct file *file, void *priv, |
| 464 | v4l2_std_id tvnorms) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 465 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 466 | struct cx25821_channel *chan = video_drvdata(file); |
| 467 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 468 | |
Hans Verkuil | 314527acb | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 469 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 470 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 471 | |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 472 | dev->tvnorm = tvnorms; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 473 | chan->width = 720; |
| 474 | chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 475 | |
| 476 | medusa_set_videostandard(dev); |
| 477 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 478 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 479 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 480 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 481 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 482 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 483 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 484 | if (i->index) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 485 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 486 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 487 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 488 | i->std = CX25821_NORMS; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 489 | strcpy(i->name, "Composite"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 490 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 491 | } |
| 492 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 493 | static int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 494 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 495 | *i = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 496 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 497 | } |
| 498 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 499 | static int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 500 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 501 | return i ? -EINVAL : 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 502 | } |
| 503 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 504 | static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 505 | { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 506 | struct cx25821_channel *chan = |
| 507 | container_of(ctrl->handler, struct cx25821_channel, hdl); |
| 508 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 509 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 510 | switch (ctrl->id) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 511 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 512 | medusa_set_brightness(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 513 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 514 | case V4L2_CID_HUE: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 515 | medusa_set_hue(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 516 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 517 | case V4L2_CID_CONTRAST: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 518 | medusa_set_contrast(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 519 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 520 | case V4L2_CID_SATURATION: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 521 | medusa_set_saturation(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 522 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 523 | default: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 524 | return -EINVAL; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 525 | } |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 526 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 527 | } |
| 528 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 529 | static int cx25821_vidioc_enum_output(struct file *file, void *priv, |
| 530 | struct v4l2_output *o) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 531 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 532 | if (o->index) |
| 533 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 534 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 535 | o->type = V4L2_INPUT_TYPE_CAMERA; |
| 536 | o->std = CX25821_NORMS; |
| 537 | strcpy(o->name, "Composite"); |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 538 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 539 | } |
| 540 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 541 | static int cx25821_vidioc_g_output(struct file *file, void *priv, unsigned int *o) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 542 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 543 | *o = 0; |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 544 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 545 | } |
| 546 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 547 | static int cx25821_vidioc_s_output(struct file *file, void *priv, unsigned int o) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 548 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 549 | return o ? -EINVAL : 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 550 | } |
| 551 | |
Hans Verkuil | e90878a | 2013-04-14 11:40:26 -0300 | [diff] [blame] | 552 | static int cx25821_vidioc_try_fmt_vid_out(struct file *file, void *priv, |
| 553 | struct v4l2_format *f) |
| 554 | { |
| 555 | struct cx25821_channel *chan = video_drvdata(file); |
| 556 | struct cx25821_dev *dev = chan->dev; |
| 557 | const struct cx25821_fmt *fmt; |
| 558 | |
| 559 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 560 | if (NULL == fmt) |
| 561 | return -EINVAL; |
| 562 | f->fmt.pix.width = 720; |
| 563 | f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
| 564 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 565 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 566 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 567 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Hans Verkuil | e90878a | 2013-04-14 11:40:26 -0300 | [diff] [blame] | 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static int vidioc_s_fmt_vid_out(struct file *file, void *priv, |
| 572 | struct v4l2_format *f) |
| 573 | { |
| 574 | struct cx25821_channel *chan = video_drvdata(file); |
| 575 | int err; |
| 576 | |
| 577 | err = cx25821_vidioc_try_fmt_vid_out(file, priv, f); |
| 578 | |
| 579 | if (0 != err) |
| 580 | return err; |
| 581 | |
| 582 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 583 | chan->field = f->fmt.pix.field; |
Hans Verkuil | e90878a | 2013-04-14 11:40:26 -0300 | [diff] [blame] | 584 | chan->width = f->fmt.pix.width; |
| 585 | chan->height = f->fmt.pix.height; |
| 586 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 587 | chan->pixel_formats = PIXEL_FRMT_411; |
| 588 | else |
| 589 | chan->pixel_formats = PIXEL_FRMT_422; |
| 590 | return 0; |
| 591 | } |
| 592 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 593 | static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { |
| 594 | .s_ctrl = cx25821_s_ctrl, |
| 595 | }; |
| 596 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 597 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 598 | .owner = THIS_MODULE, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 599 | .open = v4l2_fh_open, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 600 | .release = vb2_fop_release, |
| 601 | .read = vb2_fop_read, |
| 602 | .poll = vb2_fop_poll, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 603 | .unlocked_ioctl = video_ioctl2, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 604 | .mmap = vb2_fop_mmap, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 608 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 609 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 610 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 611 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 612 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 613 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 614 | .vidioc_prepare_buf = vb2_ioctl_prepare_buf, |
Hans Verkuil | 11c8a2d | 2014-12-12 10:27:59 -0300 | [diff] [blame] | 615 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 616 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 617 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 618 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 619 | .vidioc_streamon = vb2_ioctl_streamon, |
| 620 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 621 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 622 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 623 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 624 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 625 | .vidioc_s_input = cx25821_vidioc_s_input, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 626 | .vidioc_log_status = vidioc_log_status, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 627 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 628 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 629 | }; |
| 630 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 631 | static const struct video_device cx25821_video_device = { |
| 632 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 633 | .fops = &video_fops, |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 634 | .release = video_device_release_empty, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 635 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 636 | .ioctl_ops = &video_ioctl_ops, |
| 637 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 638 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 639 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 640 | static const struct v4l2_file_operations video_out_fops = { |
| 641 | .owner = THIS_MODULE, |
| 642 | .open = v4l2_fh_open, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 643 | .release = vb2_fop_release, |
| 644 | .write = vb2_fop_write, |
| 645 | .poll = vb2_fop_poll, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 646 | .unlocked_ioctl = video_ioctl2, |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 647 | .mmap = vb2_fop_mmap, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | static const struct v4l2_ioctl_ops video_out_ioctl_ops = { |
| 651 | .vidioc_querycap = cx25821_vidioc_querycap, |
Hans Verkuil | e90878a | 2013-04-14 11:40:26 -0300 | [diff] [blame] | 652 | .vidioc_enum_fmt_vid_out = cx25821_vidioc_enum_fmt_vid_cap, |
| 653 | .vidioc_g_fmt_vid_out = cx25821_vidioc_g_fmt_vid_cap, |
| 654 | .vidioc_try_fmt_vid_out = cx25821_vidioc_try_fmt_vid_out, |
| 655 | .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 656 | .vidioc_g_std = cx25821_vidioc_g_std, |
| 657 | .vidioc_s_std = cx25821_vidioc_s_std, |
| 658 | .vidioc_enum_output = cx25821_vidioc_enum_output, |
| 659 | .vidioc_g_output = cx25821_vidioc_g_output, |
| 660 | .vidioc_s_output = cx25821_vidioc_s_output, |
| 661 | .vidioc_log_status = vidioc_log_status, |
| 662 | }; |
| 663 | |
| 664 | static const struct video_device cx25821_video_out_device = { |
| 665 | .name = "cx25821-video", |
| 666 | .fops = &video_out_fops, |
| 667 | .release = video_device_release_empty, |
| 668 | .minor = -1, |
| 669 | .ioctl_ops = &video_out_ioctl_ops, |
| 670 | .tvnorms = CX25821_NORMS, |
| 671 | }; |
| 672 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 673 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 674 | { |
| 675 | cx_clear(PCI_INT_MSK, 1); |
| 676 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 677 | if (video_is_registered(&dev->channels[chan_num].vdev)) { |
| 678 | video_unregister_device(&dev->channels[chan_num].vdev); |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 679 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 680 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | int cx25821_video_register(struct cx25821_dev *dev) |
| 684 | { |
| 685 | int err; |
| 686 | int i; |
| 687 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 688 | /* initial device configuration */ |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 689 | dev->tvnorm = V4L2_STD_NTSC_M; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 690 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 691 | spin_lock_init(&dev->slock); |
| 692 | |
Hans Verkuil | b6f21dc | 2014-12-12 10:28:00 -0300 | [diff] [blame] | 693 | for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; ++i) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 694 | struct cx25821_channel *chan = &dev->channels[i]; |
| 695 | struct video_device *vdev = &chan->vdev; |
| 696 | struct v4l2_ctrl_handler *hdl = &chan->hdl; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 697 | struct vb2_queue *q; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 698 | bool is_output = i > SRAM_CH08; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 699 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 700 | if (i == SRAM_CH08) /* audio channel */ |
| 701 | continue; |
| 702 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 703 | if (!is_output) { |
| 704 | v4l2_ctrl_handler_init(hdl, 4); |
| 705 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 706 | V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); |
| 707 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 708 | V4L2_CID_CONTRAST, 0, 10000, 1, 5000); |
| 709 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 710 | V4L2_CID_SATURATION, 0, 10000, 1, 5000); |
| 711 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 712 | V4L2_CID_HUE, 0, 10000, 1, 5000); |
| 713 | if (hdl->error) { |
| 714 | err = hdl->error; |
| 715 | goto fail_unreg; |
| 716 | } |
| 717 | err = v4l2_ctrl_handler_setup(hdl); |
| 718 | if (err) |
| 719 | goto fail_unreg; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 720 | } else { |
| 721 | chan->out = &dev->vid_out_data[i - SRAM_CH09]; |
| 722 | chan->out->chan = chan; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 723 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 724 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 725 | chan->sram_channels = &cx25821_sram_channels[i]; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 726 | chan->width = 720; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 727 | chan->field = V4L2_FIELD_INTERLACED; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 728 | if (dev->tvnorm & V4L2_STD_625_50) |
| 729 | chan->height = 576; |
| 730 | else |
| 731 | chan->height = 480; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 732 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 733 | if (chan->pixel_formats == PIXEL_FRMT_411) |
| 734 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); |
| 735 | else |
| 736 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 737 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 738 | cx_write(chan->sram_channels->int_stat, 0xffffffff); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 739 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 740 | INIT_LIST_HEAD(&chan->dma_vidq.active); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 741 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 742 | q = &chan->vidq; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 743 | |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 744 | q->type = is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT : |
| 745 | V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 746 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 747 | q->io_modes |= is_output ? VB2_WRITE : VB2_READ; |
| 748 | q->gfp_flags = GFP_DMA32; |
| 749 | q->min_buffers_needed = 2; |
| 750 | q->drv_priv = chan; |
| 751 | q->buf_struct_size = sizeof(struct cx25821_buffer); |
| 752 | q->ops = &cx25821_video_qops; |
| 753 | q->mem_ops = &vb2_dma_sg_memops; |
| 754 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 755 | q->lock = &dev->lock; |
Hans Verkuil | 2bc46b3 | 2016-02-15 12:37:15 -0200 | [diff] [blame] | 756 | q->dev = &dev->pci->dev; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 757 | |
| 758 | if (!is_output) { |
| 759 | err = vb2_queue_init(q); |
| 760 | if (err < 0) |
| 761 | goto fail_unreg; |
| 762 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 763 | |
| 764 | /* register v4l devices */ |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 765 | *vdev = is_output ? cx25821_video_out_device : cx25821_video_device; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 766 | vdev->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 767 | if (!is_output) |
| 768 | vdev->ctrl_handler = hdl; |
| 769 | else |
| 770 | vdev->vfl_dir = VFL_DIR_TX; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 771 | vdev->lock = &dev->lock; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 772 | vdev->queue = q; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 773 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 774 | video_set_drvdata(vdev, chan); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 775 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 776 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 777 | video_nr[dev->nr]); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 778 | |
| 779 | if (err < 0) |
| 780 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* set PCI interrupt */ |
| 784 | cx_set(PCI_INT_MSK, 0xff); |
| 785 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 786 | return 0; |
| 787 | |
| 788 | fail_unreg: |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 789 | while (i >= 0) |
| 790 | cx25821_video_unregister(dev, i--); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 791 | return err; |
| 792 | } |