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> |
| 6 | * Based on Steven Toth <stoth@linuxtv.org> cx23885 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. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 28 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 29 | #include "cx25821-video.h" |
| 30 | |
| 31 | MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 32 | MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 33 | MODULE_LICENSE("GPL"); |
| 34 | |
Mauro Carvalho Chehab | 53e712d | 2009-09-13 11:39:12 -0300 | [diff] [blame] | 35 | static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 36 | |
| 37 | module_param_array(video_nr, int, NULL, 0444); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 38 | |
| 39 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 41 | static unsigned int video_debug = VIDEO_DEBUG; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 42 | module_param(video_debug, int, 0644); |
| 43 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
| 44 | |
| 45 | static unsigned int irq_debug; |
| 46 | module_param(irq_debug, int, 0644); |
| 47 | MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); |
| 48 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 49 | static unsigned int vid_limit = 16; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 50 | module_param(vid_limit, int, 0644); |
| 51 | MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); |
| 52 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 53 | #define FORMAT_FLAGS_PACKED 0x01 |
| 54 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 55 | static const struct cx25821_fmt formats[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 56 | { |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 57 | .name = "4:1:1, packed, Y41P", |
| 58 | .fourcc = V4L2_PIX_FMT_Y41P, |
| 59 | .depth = 12, |
| 60 | .flags = FORMAT_FLAGS_PACKED, |
| 61 | }, { |
| 62 | .name = "4:2:2, packed, YUYV", |
| 63 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 64 | .depth = 16, |
| 65 | .flags = FORMAT_FLAGS_PACKED, |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 66 | }, |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 67 | }; |
| 68 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 69 | 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] | 70 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 71 | unsigned int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 72 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 73 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 74 | if (formats[i].fourcc == fourcc) |
| 75 | return formats + i; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 76 | return NULL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 77 | } |
| 78 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 79 | void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, |
| 80 | u32 count) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 81 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 82 | struct cx25821_buffer *buf; |
| 83 | int bc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 84 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 85 | for (bc = 0;; bc++) { |
| 86 | if (list_empty(&q->active)) { |
| 87 | dprintk(1, "bc=%d (=0: active empty)\n", bc); |
| 88 | break; |
| 89 | } |
| 90 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 91 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 92 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 93 | |
| 94 | /* count comes from the hw and it is 16bit wide -- |
| 95 | * this trick handles wrap-arounds correctly for |
| 96 | * up to 32767 buffers in flight... */ |
Leonid V. Fedorenchik | e313e1f | 2011-09-16 14:15:13 +0800 | [diff] [blame] | 97 | if ((s16) (count - buf->count) < 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 98 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 99 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 100 | v4l2_get_timestamp(&buf->vb.ts); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 101 | buf->vb.state = VIDEOBUF_DONE; |
| 102 | list_del(&buf->vb.queue); |
| 103 | wake_up(&buf->vb.done); |
| 104 | } |
| 105 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 106 | if (list_empty(&q->active)) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 107 | del_timer(&q->timeout); |
| 108 | else |
| 109 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 110 | if (bc != 1) |
Leonid V. Fedorenchik | 692cfb9 | 2011-09-16 14:14:36 +0800 | [diff] [blame] | 111 | pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 112 | } |
| 113 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 114 | int cx25821_start_video_dma(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 115 | struct cx25821_dmaqueue *q, |
| 116 | struct cx25821_buffer *buf, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 117 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 118 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 119 | int tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 120 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 121 | /* setup fifo + format */ |
| 122 | cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 123 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 124 | /* reset counter */ |
| 125 | cx_write(channel->gpcnt_ctl, 3); |
| 126 | q->count = 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 127 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 128 | /* enable irq */ |
| 129 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); |
| 130 | cx_set(channel->int_msk, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 131 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 132 | /* start dma */ |
| 133 | cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 134 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 135 | /* make sure upstream setting if any is reversed */ |
| 136 | tmp = cx_read(VID_CH_MODE_SEL); |
| 137 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 138 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 139 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 140 | } |
| 141 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 142 | static int cx25821_restart_video_queue(struct cx25821_dev *dev, |
| 143 | struct cx25821_dmaqueue *q, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 144 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 145 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 146 | struct cx25821_buffer *buf, *prev; |
| 147 | struct list_head *item; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 148 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 149 | if (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 150 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 151 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 152 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 153 | cx25821_start_video_dma(dev, q, buf, channel); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 154 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 155 | list_for_each(item, &q->active) { |
| 156 | buf = list_entry(item, struct cx25821_buffer, vb.queue); |
| 157 | buf->count = q->count++; |
| 158 | } |
| 159 | |
| 160 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 161 | return 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 162 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 163 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 164 | prev = NULL; |
| 165 | for (;;) { |
| 166 | if (list_empty(&q->queued)) |
| 167 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 168 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 169 | buf = list_entry(q->queued.next, struct cx25821_buffer, |
| 170 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 171 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 172 | if (NULL == prev) { |
| 173 | list_move_tail(&buf->vb.queue, &q->active); |
| 174 | cx25821_start_video_dma(dev, q, buf, channel); |
| 175 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 176 | buf->count = q->count++; |
| 177 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 178 | } else if (prev->vb.width == buf->vb.width && |
| 179 | prev->vb.height == buf->vb.height && |
| 180 | prev->fmt == buf->fmt) { |
| 181 | list_move_tail(&buf->vb.queue, &q->active); |
| 182 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 183 | buf->count = q->count++; |
| 184 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 185 | prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 186 | } else { |
| 187 | return 0; |
| 188 | } |
| 189 | prev = buf; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 190 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 191 | } |
| 192 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 193 | static void cx25821_vid_timeout(unsigned long data) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 194 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 195 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; |
| 196 | struct cx25821_dev *dev = timeout_data->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 197 | const struct sram_channel *channel = timeout_data->channel; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 198 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 199 | struct cx25821_buffer *buf; |
| 200 | unsigned long flags; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 201 | |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 202 | /* cx25821_sram_channel_dump(dev, channel); */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 203 | cx_clear(channel->dma_ctl, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 204 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 205 | spin_lock_irqsave(&dev->slock, flags); |
| 206 | while (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 207 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 208 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 209 | list_del(&buf->vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 210 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 211 | buf->vb.state = VIDEOBUF_ERROR; |
| 212 | wake_up(&buf->vb.done); |
| 213 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 214 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 215 | cx25821_restart_video_queue(dev, q, channel); |
| 216 | spin_unlock_irqrestore(&dev->slock, flags); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) |
| 220 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 221 | u32 count = 0; |
| 222 | int handled = 0; |
| 223 | u32 mask; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 224 | const struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 225 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 226 | mask = cx_read(channel->int_msk); |
| 227 | if (0 == (status & mask)) |
| 228 | return handled; |
| 229 | |
| 230 | cx_write(channel->int_stat, status); |
| 231 | |
| 232 | /* risc op code error */ |
| 233 | if (status & (1 << 16)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 234 | pr_warn("%s, %s: video risc op code error\n", |
| 235 | dev->name, channel->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 236 | cx_clear(channel->dma_ctl, 0x11); |
| 237 | cx25821_sram_channel_dump(dev, channel); |
| 238 | } |
| 239 | |
| 240 | /* risc1 y */ |
| 241 | if (status & FLD_VID_DST_RISC1) { |
| 242 | spin_lock(&dev->slock); |
| 243 | count = cx_read(channel->gpcnt); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 244 | cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq, |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 245 | count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 246 | spin_unlock(&dev->slock); |
| 247 | handled++; |
| 248 | } |
| 249 | |
| 250 | /* risc2 y */ |
| 251 | if (status & 0x10) { |
| 252 | dprintk(2, "stopper video\n"); |
| 253 | spin_lock(&dev->slock); |
Leonid V. Fedorenchik | 788d0f3 | 2011-09-16 14:14:39 +0800 | [diff] [blame] | 254 | cx25821_restart_video_queue(dev, |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 255 | &dev->channels[channel->i].dma_vidq, channel); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 256 | spin_unlock(&dev->slock); |
| 257 | handled++; |
| 258 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 259 | return handled; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 260 | } |
| 261 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 262 | static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 263 | unsigned int *size) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 264 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 265 | struct cx25821_channel *chan = q->priv_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 266 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 267 | *size = chan->fmt->depth * chan->width * chan->height >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 268 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 269 | if (0 == *count) |
| 270 | *count = 32; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 271 | |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 272 | if (*size * *count > vid_limit * 1024 * 1024) |
| 273 | *count = (vid_limit * 1024 * 1024) / *size; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 274 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 275 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 276 | } |
| 277 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 278 | static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 279 | enum v4l2_field field) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 280 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 281 | struct cx25821_channel *chan = q->priv_data; |
| 282 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 283 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 284 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 285 | int rc, init_buffer = 0; |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 286 | u32 line0_offset; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 287 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
| 288 | int bpl_local = LINE_SIZE_D1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 289 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 290 | BUG_ON(NULL == chan->fmt); |
| 291 | if (chan->width < 48 || chan->width > 720 || |
| 292 | chan->height < 32 || chan->height > 576) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 293 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 294 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 295 | buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 296 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 297 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 298 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 299 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 300 | if (buf->fmt != chan->fmt || |
| 301 | buf->vb.width != chan->width || |
| 302 | buf->vb.height != chan->height || buf->vb.field != field) { |
| 303 | buf->fmt = chan->fmt; |
| 304 | buf->vb.width = chan->width; |
| 305 | buf->vb.height = chan->height; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 306 | buf->vb.field = field; |
| 307 | init_buffer = 1; |
| 308 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 309 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 310 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 311 | init_buffer = 1; |
| 312 | rc = videobuf_iolock(q, &buf->vb, NULL); |
| 313 | if (0 != rc) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 314 | printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 315 | goto fail; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 316 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 317 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 318 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 319 | dprintk(1, "init_buffer=%d\n", init_buffer); |
| 320 | |
| 321 | if (init_buffer) { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 322 | if (chan->pixel_formats == PIXEL_FRMT_411) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 323 | buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; |
| 324 | else |
| 325 | buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); |
| 326 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 327 | if (chan->pixel_formats == PIXEL_FRMT_411) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 328 | bpl_local = buf->bpl; |
| 329 | } else { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 330 | bpl_local = buf->bpl; /* Default */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 331 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 332 | if (chan->use_cif_resolution) { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 333 | if (dev->tvnorm & V4L2_STD_625_50) |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 334 | bpl_local = 352 << 1; |
| 335 | else |
| 336 | bpl_local = chan->cif_width << 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 337 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 338 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 339 | |
| 340 | switch (buf->vb.field) { |
| 341 | case V4L2_FIELD_TOP: |
| 342 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 343 | dma->sglist, 0, UNSET, |
| 344 | buf->bpl, 0, buf->vb.height); |
| 345 | break; |
| 346 | case V4L2_FIELD_BOTTOM: |
| 347 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 348 | dma->sglist, UNSET, 0, |
| 349 | buf->bpl, 0, buf->vb.height); |
| 350 | break; |
| 351 | case V4L2_FIELD_INTERLACED: |
| 352 | /* All other formats are top field first */ |
| 353 | line0_offset = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 354 | dprintk(1, "top field first\n"); |
| 355 | |
| 356 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 357 | dma->sglist, line0_offset, |
| 358 | bpl_local, bpl_local, bpl_local, |
| 359 | buf->vb.height >> 1); |
| 360 | break; |
| 361 | case V4L2_FIELD_SEQ_TB: |
| 362 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 363 | dma->sglist, |
| 364 | 0, buf->bpl * (buf->vb.height >> 1), |
| 365 | buf->bpl, 0, buf->vb.height >> 1); |
| 366 | break; |
| 367 | case V4L2_FIELD_SEQ_BT: |
| 368 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 369 | dma->sglist, |
| 370 | buf->bpl * (buf->vb.height >> 1), 0, |
| 371 | buf->bpl, 0, buf->vb.height >> 1); |
| 372 | break; |
| 373 | default: |
| 374 | BUG(); |
| 375 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 376 | } |
| 377 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 378 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 379 | buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth, |
| 380 | chan->fmt->name, (unsigned long)buf->risc.dma); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 381 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 382 | buf->vb.state = VIDEOBUF_PREPARED; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 383 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 384 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 385 | |
Leonid V. Fedorenchik | 2748f26 | 2011-09-16 14:14:34 +0800 | [diff] [blame] | 386 | fail: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 387 | cx25821_free_buffer(q, buf); |
| 388 | return rc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 389 | } |
| 390 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 391 | static void cx25821_buffer_release(struct videobuf_queue *q, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 392 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 393 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 394 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 395 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 396 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 397 | cx25821_free_buffer(q, buf); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 398 | } |
| 399 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 400 | static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 401 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 402 | struct cx25821_channel *chan = video_drvdata(file); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 403 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 404 | return videobuf_mmap_mapper(&chan->vidq, vma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 405 | } |
| 406 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 407 | |
| 408 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 409 | { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 410 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 411 | container_of(vb, struct cx25821_buffer, vb); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 412 | struct cx25821_buffer *prev; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 413 | struct cx25821_channel *chan = vq->priv_data; |
| 414 | struct cx25821_dev *dev = chan->dev; |
| 415 | struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 416 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 417 | /* add jump to stopper */ |
| 418 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 419 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 420 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 421 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 422 | dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 423 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 424 | if (!list_empty(&q->queued)) { |
| 425 | list_add_tail(&buf->vb.queue, &q->queued); |
| 426 | buf->vb.state = VIDEOBUF_QUEUED; |
| 427 | dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, |
| 428 | buf->vb.i); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 429 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 430 | } else if (list_empty(&q->active)) { |
| 431 | list_add_tail(&buf->vb.queue, &q->active); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 432 | cx25821_start_video_dma(dev, q, buf, chan->sram_channels); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 433 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 434 | buf->count = q->count++; |
| 435 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 436 | dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", |
| 437 | buf, buf->vb.i, buf->count, q->count); |
| 438 | } else { |
| 439 | prev = list_entry(q->active.prev, struct cx25821_buffer, |
| 440 | vb.queue); |
| 441 | if (prev->vb.width == buf->vb.width |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 442 | && prev->vb.height == buf->vb.height |
| 443 | && prev->fmt == buf->fmt) { |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 444 | list_add_tail(&buf->vb.queue, &q->active); |
| 445 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 446 | buf->count = q->count++; |
| 447 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 448 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 449 | /* 64 bit bits 63-32 */ |
| 450 | prev->risc.jmp[2] = cpu_to_le32(0); |
| 451 | dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", |
| 452 | buf, buf->vb.i, buf->count); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 453 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 454 | } else { |
| 455 | list_add_tail(&buf->vb.queue, &q->queued); |
| 456 | buf->vb.state = VIDEOBUF_QUEUED; |
| 457 | dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, |
| 458 | buf->vb.i); |
| 459 | } |
| 460 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 461 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 462 | if (list_empty(&q->active)) |
| 463 | dprintk(2, "active queue empty!\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static struct videobuf_queue_ops cx25821_video_qops = { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 467 | .buf_setup = cx25821_buffer_setup, |
| 468 | .buf_prepare = cx25821_buffer_prepare, |
| 469 | .buf_queue = buffer_queue, |
| 470 | .buf_release = cx25821_buffer_release, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 471 | }; |
| 472 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 473 | static ssize_t video_read(struct file *file, char __user * data, size_t count, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 474 | loff_t *ppos) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 475 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 476 | struct v4l2_fh *fh = file->private_data; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 477 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 478 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 479 | int err = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 480 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 481 | if (mutex_lock_interruptible(&dev->lock)) |
| 482 | return -ERESTARTSYS; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 483 | if (chan->streaming_fh && chan->streaming_fh != fh) { |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 484 | err = -EBUSY; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 485 | goto unlock; |
| 486 | } |
| 487 | chan->streaming_fh = fh; |
| 488 | |
| 489 | err = videobuf_read_one(&chan->vidq, data, count, ppos, |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 490 | file->f_flags & O_NONBLOCK); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 491 | unlock: |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 492 | mutex_unlock(&dev->lock); |
| 493 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static unsigned int video_poll(struct file *file, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 497 | struct poll_table_struct *wait) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 498 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 499 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 500 | unsigned long req_events = poll_requested_events(wait); |
| 501 | unsigned int res = v4l2_ctrl_poll(file, wait); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 502 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 503 | if (req_events & (POLLIN | POLLRDNORM)) |
| 504 | res |= videobuf_poll_stream(file, &chan->vidq, wait); |
| 505 | return res; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 506 | |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 507 | /* This doesn't belong in poll(). This can be done |
| 508 | * much better with vb2. We keep this code here as a |
| 509 | * reminder. |
| 510 | if ((res & POLLIN) && buf->vb.state == VIDEOBUF_DONE) { |
| 511 | struct cx25821_dev *dev = chan->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 512 | |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 513 | if (dev && chan->use_cif_resolution) { |
| 514 | u8 cam_id = *((char *)buf->vb.baddr + 3); |
| 515 | memcpy((char *)buf->vb.baddr, |
| 516 | (char *)buf->vb.baddr + (chan->width * 2), |
| 517 | (chan->width * 2)); |
| 518 | *((char *)buf->vb.baddr + 3) = cam_id; |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 519 | } |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 520 | } |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 521 | */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | static int video_release(struct file *file) |
| 525 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 526 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 527 | struct v4l2_fh *fh = file->private_data; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 528 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 529 | const struct sram_channel *sram_ch = |
| 530 | dev->channels[0].sram_channels; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 531 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 532 | mutex_lock(&dev->lock); |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 533 | /* stop the risc engine and fifo */ |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 534 | cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 535 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 536 | /* stop video capture */ |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 537 | if (chan->streaming_fh == fh) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 538 | videobuf_queue_cancel(&chan->vidq); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 539 | chan->streaming_fh = NULL; |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 540 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 541 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 542 | if (chan->vidq.read_buf) { |
| 543 | cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf); |
| 544 | kfree(chan->vidq.read_buf); |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 545 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 546 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 547 | videobuf_mmap_free(&chan->vidq); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 548 | mutex_unlock(&dev->lock); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 549 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 550 | return v4l2_fh_release(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 551 | } |
| 552 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 553 | /* VIDEO IOCTLS */ |
| 554 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 555 | struct v4l2_format *f) |
| 556 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 557 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 558 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 559 | f->fmt.pix.width = chan->width; |
| 560 | f->fmt.pix.height = chan->height; |
| 561 | f->fmt.pix.field = chan->vidq.field; |
| 562 | f->fmt.pix.pixelformat = chan->fmt->fourcc; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 563 | f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; |
| 564 | f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; |
| 565 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 566 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 572 | struct v4l2_format *f) |
| 573 | { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 574 | struct cx25821_channel *chan = video_drvdata(file); |
| 575 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 576 | const struct cx25821_fmt *fmt; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 577 | enum v4l2_field field = f->fmt.pix.field; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 578 | unsigned int maxw, maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 579 | unsigned w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 580 | |
| 581 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 582 | if (NULL == fmt) |
| 583 | return -EINVAL; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 584 | maxw = 720; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 585 | maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 586 | |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 587 | w = f->fmt.pix.width; |
| 588 | if (field != V4L2_FIELD_BOTTOM) |
| 589 | field = V4L2_FIELD_TOP; |
| 590 | if (w < 352) { |
| 591 | w = 176; |
| 592 | f->fmt.pix.height = maxh / 4; |
| 593 | } else if (w < 720) { |
| 594 | w = 352; |
| 595 | f->fmt.pix.height = maxh / 2; |
| 596 | } else { |
| 597 | w = 720; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 598 | f->fmt.pix.height = maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 599 | field = V4L2_FIELD_INTERLACED; |
| 600 | } |
| 601 | f->fmt.pix.field = field; |
| 602 | f->fmt.pix.width = w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 603 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 604 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 605 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 606 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 607 | |
| 608 | return 0; |
| 609 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 610 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 611 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 612 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 613 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 614 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 615 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 616 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 617 | if (chan->streaming_fh && chan->streaming_fh != priv) |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 618 | return -EBUSY; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 619 | chan->streaming_fh = priv; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 620 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 621 | return videobuf_streamon(&chan->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 625 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 626 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 627 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 628 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 629 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 630 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 631 | if (chan->streaming_fh && chan->streaming_fh != priv) |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 632 | return -EBUSY; |
| 633 | if (chan->streaming_fh == NULL) |
| 634 | return 0; |
| 635 | |
| 636 | chan->streaming_fh = NULL; |
| 637 | return videobuf_streamoff(&chan->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | 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] | 641 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 642 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 643 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 644 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 645 | int pix_format = PIXEL_FRMT_422; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 646 | int err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 647 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 648 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 649 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 650 | if (0 != err) |
| 651 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 652 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 653 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 654 | chan->vidq.field = f->fmt.pix.field; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 655 | chan->width = f->fmt.pix.width; |
| 656 | chan->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 657 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 658 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 659 | pix_format = PIXEL_FRMT_411; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 660 | else |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 661 | pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 662 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 663 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 664 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 665 | /* check if cif resolution */ |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 666 | if (chan->width == 320 || chan->width == 352) |
| 667 | chan->use_cif_resolution = 1; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 668 | else |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 669 | chan->use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 670 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 671 | chan->cif_width = chan->width; |
| 672 | medusa_set_resolution(dev, chan->width, SRAM_CH00); |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 673 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 677 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 678 | int ret_val = 0; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 679 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 680 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 681 | ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK); |
| 682 | p->sequence = chan->dma_vidq.count; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 683 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 684 | return ret_val; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static int vidioc_log_status(struct file *file, void *priv) |
| 688 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 689 | struct cx25821_channel *chan = video_drvdata(file); |
| 690 | struct cx25821_dev *dev = chan->dev; |
| 691 | const struct sram_channel *sram_ch = chan->sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 692 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 693 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 694 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 695 | pr_info("Video input 0 is %s\n", |
| 696 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 697 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 698 | } |
| 699 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 700 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 701 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 702 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 703 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 704 | struct cx25821_channel *chan = video_drvdata(file); |
| 705 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 706 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 707 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 708 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 709 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 710 | strcpy(cap->driver, "cx25821"); |
| 711 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 712 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 713 | if (chan->id >= VID_CHANNEL_NUM) |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 714 | cap->device_caps = cap_output; |
| 715 | else |
| 716 | cap->device_caps = cap_input; |
| 717 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 718 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 719 | } |
| 720 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 721 | static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 722 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 723 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 724 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 725 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 726 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 727 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 728 | f->pixelformat = formats[f->index].fourcc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 729 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 730 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 731 | } |
| 732 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 733 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 734 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 735 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 736 | struct cx25821_channel *chan = video_drvdata(file); |
| 737 | |
| 738 | return videobuf_reqbufs(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 739 | } |
| 740 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 741 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 742 | struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 743 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 744 | struct cx25821_channel *chan = video_drvdata(file); |
| 745 | |
| 746 | return videobuf_querybuf(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 747 | } |
| 748 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 749 | static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 750 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 751 | struct cx25821_channel *chan = video_drvdata(file); |
| 752 | |
| 753 | return videobuf_qbuf(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 754 | } |
| 755 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 756 | 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] | 757 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 758 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 759 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 760 | *tvnorms = chan->dev->tvnorm; |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 764 | int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 765 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 766 | struct cx25821_channel *chan = video_drvdata(file); |
| 767 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 768 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 769 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 770 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 771 | |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 772 | dev->tvnorm = tvnorms; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 773 | chan->width = 720; |
| 774 | chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 775 | |
| 776 | medusa_set_videostandard(dev); |
| 777 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 778 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 779 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 780 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 781 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 782 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 783 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 784 | if (i->index) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 785 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 786 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 787 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 788 | i->std = CX25821_NORMS; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 789 | strcpy(i->name, "Composite"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 790 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 791 | } |
| 792 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 793 | 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] | 794 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 795 | *i = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 796 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 797 | } |
| 798 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 799 | 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] | 800 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 801 | return i ? -EINVAL : 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 802 | } |
| 803 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 804 | static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 805 | { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 806 | struct cx25821_channel *chan = |
| 807 | container_of(ctrl->handler, struct cx25821_channel, hdl); |
| 808 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 809 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 810 | switch (ctrl->id) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 811 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 812 | medusa_set_brightness(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 813 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 814 | case V4L2_CID_HUE: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 815 | medusa_set_hue(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 816 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 817 | case V4L2_CID_CONTRAST: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 818 | medusa_set_contrast(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 819 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 820 | case V4L2_CID_SATURATION: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 821 | medusa_set_saturation(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 822 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 823 | default: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 824 | return -EINVAL; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 825 | } |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 826 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 827 | } |
| 828 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 829 | static int cx25821_vidioc_enum_output(struct file *file, void *priv, |
| 830 | struct v4l2_output *o) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 831 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 832 | if (o->index) |
| 833 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 834 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 835 | o->type = V4L2_INPUT_TYPE_CAMERA; |
| 836 | o->std = CX25821_NORMS; |
| 837 | strcpy(o->name, "Composite"); |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 838 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 839 | } |
| 840 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 841 | 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] | 842 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 843 | *o = 0; |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 844 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 845 | } |
| 846 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 847 | 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] | 848 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 849 | return o ? -EINVAL : 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 850 | } |
| 851 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 852 | static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { |
| 853 | .s_ctrl = cx25821_s_ctrl, |
| 854 | }; |
| 855 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 856 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 857 | .owner = THIS_MODULE, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 858 | .open = v4l2_fh_open, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 859 | .release = video_release, |
| 860 | .read = video_read, |
| 861 | .poll = video_poll, |
| 862 | .mmap = cx25821_video_mmap, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 863 | .unlocked_ioctl = video_ioctl2, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 864 | }; |
| 865 | |
| 866 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 867 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 868 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 869 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 870 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 871 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 872 | .vidioc_reqbufs = cx25821_vidioc_reqbufs, |
| 873 | .vidioc_querybuf = cx25821_vidioc_querybuf, |
| 874 | .vidioc_qbuf = cx25821_vidioc_qbuf, |
| 875 | .vidioc_dqbuf = vidioc_dqbuf, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 876 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 877 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 878 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 879 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 880 | .vidioc_s_input = cx25821_vidioc_s_input, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 881 | .vidioc_streamon = vidioc_streamon, |
| 882 | .vidioc_streamoff = vidioc_streamoff, |
| 883 | .vidioc_log_status = vidioc_log_status, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 884 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 885 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 886 | }; |
| 887 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 888 | static const struct video_device cx25821_video_device = { |
| 889 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 890 | .fops = &video_fops, |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 891 | .release = video_device_release_empty, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 892 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 893 | .ioctl_ops = &video_ioctl_ops, |
| 894 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 895 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 896 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 897 | static const struct v4l2_file_operations video_out_fops = { |
| 898 | .owner = THIS_MODULE, |
| 899 | .open = v4l2_fh_open, |
| 900 | .release = v4l2_fh_release, |
| 901 | .unlocked_ioctl = video_ioctl2, |
| 902 | }; |
| 903 | |
| 904 | static const struct v4l2_ioctl_ops video_out_ioctl_ops = { |
| 905 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 906 | .vidioc_g_std = cx25821_vidioc_g_std, |
| 907 | .vidioc_s_std = cx25821_vidioc_s_std, |
| 908 | .vidioc_enum_output = cx25821_vidioc_enum_output, |
| 909 | .vidioc_g_output = cx25821_vidioc_g_output, |
| 910 | .vidioc_s_output = cx25821_vidioc_s_output, |
| 911 | .vidioc_log_status = vidioc_log_status, |
| 912 | }; |
| 913 | |
| 914 | static const struct video_device cx25821_video_out_device = { |
| 915 | .name = "cx25821-video", |
| 916 | .fops = &video_out_fops, |
| 917 | .release = video_device_release_empty, |
| 918 | .minor = -1, |
| 919 | .ioctl_ops = &video_out_ioctl_ops, |
| 920 | .tvnorms = CX25821_NORMS, |
| 921 | }; |
| 922 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 923 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 924 | { |
| 925 | cx_clear(PCI_INT_MSK, 1); |
| 926 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 927 | if (video_is_registered(&dev->channels[chan_num].vdev)) { |
| 928 | video_unregister_device(&dev->channels[chan_num].vdev); |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 929 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 930 | |
| 931 | btcx_riscmem_free(dev->pci, |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 932 | &dev->channels[chan_num].dma_vidq.stopper); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 933 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | int cx25821_video_register(struct cx25821_dev *dev) |
| 937 | { |
| 938 | int err; |
| 939 | int i; |
| 940 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 941 | /* initial device configuration */ |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 942 | dev->tvnorm = V4L2_STD_NTSC_M; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 943 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 944 | spin_lock_init(&dev->slock); |
| 945 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 946 | for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 947 | struct cx25821_channel *chan = &dev->channels[i]; |
| 948 | struct video_device *vdev = &chan->vdev; |
| 949 | struct v4l2_ctrl_handler *hdl = &chan->hdl; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 950 | bool is_output = i > SRAM_CH08; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 951 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 952 | if (i == SRAM_CH08) /* audio channel */ |
| 953 | continue; |
| 954 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 955 | if (!is_output) { |
| 956 | v4l2_ctrl_handler_init(hdl, 4); |
| 957 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 958 | V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); |
| 959 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 960 | V4L2_CID_CONTRAST, 0, 10000, 1, 5000); |
| 961 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 962 | V4L2_CID_SATURATION, 0, 10000, 1, 5000); |
| 963 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 964 | V4L2_CID_HUE, 0, 10000, 1, 5000); |
| 965 | if (hdl->error) { |
| 966 | err = hdl->error; |
| 967 | goto fail_unreg; |
| 968 | } |
| 969 | err = v4l2_ctrl_handler_setup(hdl); |
| 970 | if (err) |
| 971 | goto fail_unreg; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 972 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 973 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 974 | cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper, |
| 975 | chan->sram_channels->dma_ctl, 0x11, 0); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 976 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 977 | chan->sram_channels = &cx25821_sram_channels[i]; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 978 | chan->width = 720; |
| 979 | if (dev->tvnorm & V4L2_STD_625_50) |
| 980 | chan->height = 576; |
| 981 | else |
| 982 | chan->height = 480; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 983 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 984 | if (chan->pixel_formats == PIXEL_FRMT_411) |
| 985 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); |
| 986 | else |
| 987 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 988 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 989 | cx_write(chan->sram_channels->int_stat, 0xffffffff); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 990 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 991 | INIT_LIST_HEAD(&chan->dma_vidq.active); |
| 992 | INIT_LIST_HEAD(&chan->dma_vidq.queued); |
| 993 | |
| 994 | chan->timeout_data.dev = dev; |
| 995 | chan->timeout_data.channel = &cx25821_sram_channels[i]; |
| 996 | chan->dma_vidq.timeout.function = cx25821_vid_timeout; |
| 997 | chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data; |
| 998 | init_timer(&chan->dma_vidq.timeout); |
| 999 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 1000 | if (!is_output) |
| 1001 | videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev, |
| 1002 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 1003 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), |
| 1004 | chan, &dev->lock); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1005 | |
| 1006 | /* register v4l devices */ |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 1007 | *vdev = is_output ? cx25821_video_out_device : cx25821_video_device; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1008 | vdev->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame^] | 1009 | if (!is_output) |
| 1010 | vdev->ctrl_handler = hdl; |
| 1011 | else |
| 1012 | vdev->vfl_dir = VFL_DIR_TX; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1013 | vdev->lock = &dev->lock; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1014 | set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags); |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1015 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1016 | video_set_drvdata(vdev, chan); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1017 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1018 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1019 | video_nr[dev->nr]); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1020 | |
| 1021 | if (err < 0) |
| 1022 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | /* set PCI interrupt */ |
| 1026 | cx_set(PCI_INT_MSK, 0xff); |
| 1027 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1028 | return 0; |
| 1029 | |
| 1030 | fail_unreg: |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1031 | while (i >= 0) |
| 1032 | cx25821_video_unregister(dev, i--); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1033 | return err; |
| 1034 | } |