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 */ |
Hans Verkuil | 4c1d0f7 | 2013-04-14 07:13:02 -0300 | [diff] [blame^] | 554 | |
| 555 | static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 556 | struct v4l2_fmtdesc *f) |
| 557 | { |
| 558 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 559 | return -EINVAL; |
| 560 | |
| 561 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 562 | f->pixelformat = formats[f->index].fourcc; |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 567 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 568 | struct v4l2_format *f) |
| 569 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 570 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 571 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 572 | f->fmt.pix.width = chan->width; |
| 573 | f->fmt.pix.height = chan->height; |
| 574 | f->fmt.pix.field = chan->vidq.field; |
| 575 | f->fmt.pix.pixelformat = chan->fmt->fourcc; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 576 | f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; |
| 577 | f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; |
| 578 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 579 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 585 | struct v4l2_format *f) |
| 586 | { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 587 | struct cx25821_channel *chan = video_drvdata(file); |
| 588 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 589 | const struct cx25821_fmt *fmt; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 590 | enum v4l2_field field = f->fmt.pix.field; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 591 | unsigned int maxw, maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 592 | unsigned w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 593 | |
| 594 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 595 | if (NULL == fmt) |
| 596 | return -EINVAL; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 597 | maxw = 720; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 598 | maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 599 | |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 600 | w = f->fmt.pix.width; |
| 601 | if (field != V4L2_FIELD_BOTTOM) |
| 602 | field = V4L2_FIELD_TOP; |
| 603 | if (w < 352) { |
| 604 | w = 176; |
| 605 | f->fmt.pix.height = maxh / 4; |
| 606 | } else if (w < 720) { |
| 607 | w = 352; |
| 608 | f->fmt.pix.height = maxh / 2; |
| 609 | } else { |
| 610 | w = 720; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 611 | f->fmt.pix.height = maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 612 | field = V4L2_FIELD_INTERLACED; |
| 613 | } |
| 614 | f->fmt.pix.field = field; |
| 615 | f->fmt.pix.width = w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 616 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 617 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 618 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 619 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 620 | |
| 621 | return 0; |
| 622 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 623 | |
| 624 | 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] | 625 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 626 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 627 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 628 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 629 | int pix_format = PIXEL_FRMT_422; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 630 | int err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 631 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 632 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 633 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 634 | if (0 != err) |
| 635 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 636 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 637 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 638 | chan->vidq.field = f->fmt.pix.field; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 639 | chan->width = f->fmt.pix.width; |
| 640 | chan->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 641 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 642 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 643 | pix_format = PIXEL_FRMT_411; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 644 | else |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 645 | pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 646 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 647 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 648 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 649 | /* check if cif resolution */ |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 650 | if (chan->width == 320 || chan->width == 352) |
| 651 | chan->use_cif_resolution = 1; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 652 | else |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 653 | chan->use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 654 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 655 | chan->cif_width = chan->width; |
| 656 | medusa_set_resolution(dev, chan->width, SRAM_CH00); |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 657 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 658 | } |
| 659 | |
Hans Verkuil | 4c1d0f7 | 2013-04-14 07:13:02 -0300 | [diff] [blame^] | 660 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 661 | { |
| 662 | struct cx25821_channel *chan = video_drvdata(file); |
| 663 | |
| 664 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | if (chan->streaming_fh && chan->streaming_fh != priv) |
| 668 | return -EBUSY; |
| 669 | chan->streaming_fh = priv; |
| 670 | |
| 671 | return videobuf_streamon(&chan->vidq); |
| 672 | } |
| 673 | |
| 674 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 675 | { |
| 676 | struct cx25821_channel *chan = video_drvdata(file); |
| 677 | |
| 678 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | if (chan->streaming_fh && chan->streaming_fh != priv) |
| 682 | return -EBUSY; |
| 683 | if (chan->streaming_fh == NULL) |
| 684 | return 0; |
| 685 | |
| 686 | chan->streaming_fh = NULL; |
| 687 | return videobuf_streamoff(&chan->vidq); |
| 688 | } |
| 689 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 690 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 691 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 692 | int ret_val = 0; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 693 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 694 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 695 | ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK); |
| 696 | p->sequence = chan->dma_vidq.count; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 697 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 698 | return ret_val; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static int vidioc_log_status(struct file *file, void *priv) |
| 702 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 703 | struct cx25821_channel *chan = video_drvdata(file); |
| 704 | struct cx25821_dev *dev = chan->dev; |
| 705 | const struct sram_channel *sram_ch = chan->sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 706 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 707 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 708 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 709 | pr_info("Video input 0 is %s\n", |
| 710 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 711 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 712 | } |
| 713 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 714 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 715 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 716 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 717 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 718 | struct cx25821_channel *chan = video_drvdata(file); |
| 719 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 720 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 721 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 722 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT; |
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 | strcpy(cap->driver, "cx25821"); |
| 725 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 726 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 727 | if (chan->id >= VID_CHANNEL_NUM) |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 728 | cap->device_caps = cap_output; |
| 729 | else |
| 730 | cap->device_caps = cap_input; |
| 731 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 732 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 733 | } |
| 734 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 735 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 736 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 737 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 738 | struct cx25821_channel *chan = video_drvdata(file); |
| 739 | |
| 740 | return videobuf_reqbufs(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 741 | } |
| 742 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 743 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 744 | struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 745 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 746 | struct cx25821_channel *chan = video_drvdata(file); |
| 747 | |
| 748 | return videobuf_querybuf(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 749 | } |
| 750 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 751 | 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] | 752 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 753 | struct cx25821_channel *chan = video_drvdata(file); |
| 754 | |
| 755 | return videobuf_qbuf(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 756 | } |
| 757 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 758 | 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] | 759 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 760 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 761 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 762 | *tvnorms = chan->dev->tvnorm; |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 766 | 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] | 767 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 768 | struct cx25821_channel *chan = video_drvdata(file); |
| 769 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 770 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 771 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 772 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 773 | |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 774 | dev->tvnorm = tvnorms; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame] | 775 | chan->width = 720; |
| 776 | chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 777 | |
| 778 | medusa_set_videostandard(dev); |
| 779 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 780 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 781 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 782 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 783 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 784 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 785 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 786 | if (i->index) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 787 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 788 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 789 | i->type = V4L2_INPUT_TYPE_CAMERA; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 790 | i->std = CX25821_NORMS; |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 791 | strcpy(i->name, "Composite"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 792 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 793 | } |
| 794 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 795 | 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] | 796 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 797 | *i = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 798 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 799 | } |
| 800 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 801 | 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] | 802 | { |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 803 | return i ? -EINVAL : 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 804 | } |
| 805 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 806 | static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 807 | { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 808 | struct cx25821_channel *chan = |
| 809 | container_of(ctrl->handler, struct cx25821_channel, hdl); |
| 810 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 811 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 812 | switch (ctrl->id) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 813 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 814 | medusa_set_brightness(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 815 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 816 | case V4L2_CID_HUE: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 817 | medusa_set_hue(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 818 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 819 | case V4L2_CID_CONTRAST: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 820 | medusa_set_contrast(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 821 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 822 | case V4L2_CID_SATURATION: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 823 | medusa_set_saturation(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 824 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 825 | default: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 826 | return -EINVAL; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 827 | } |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 828 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 829 | } |
| 830 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 831 | static int cx25821_vidioc_enum_output(struct file *file, void *priv, |
| 832 | struct v4l2_output *o) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 833 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 834 | if (o->index) |
| 835 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 836 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 837 | o->type = V4L2_INPUT_TYPE_CAMERA; |
| 838 | o->std = CX25821_NORMS; |
| 839 | strcpy(o->name, "Composite"); |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 840 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 841 | } |
| 842 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 843 | 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] | 844 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 845 | *o = 0; |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 846 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 847 | } |
| 848 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 849 | 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] | 850 | { |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 851 | return o ? -EINVAL : 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 852 | } |
| 853 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 854 | static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { |
| 855 | .s_ctrl = cx25821_s_ctrl, |
| 856 | }; |
| 857 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 858 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 859 | .owner = THIS_MODULE, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 860 | .open = v4l2_fh_open, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 861 | .release = video_release, |
| 862 | .read = video_read, |
| 863 | .poll = video_poll, |
| 864 | .mmap = cx25821_video_mmap, |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 865 | .unlocked_ioctl = video_ioctl2, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 866 | }; |
| 867 | |
| 868 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 869 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 870 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 871 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 872 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 873 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 874 | .vidioc_reqbufs = cx25821_vidioc_reqbufs, |
| 875 | .vidioc_querybuf = cx25821_vidioc_querybuf, |
| 876 | .vidioc_qbuf = cx25821_vidioc_qbuf, |
| 877 | .vidioc_dqbuf = vidioc_dqbuf, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 878 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 879 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 880 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 881 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 882 | .vidioc_s_input = cx25821_vidioc_s_input, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 883 | .vidioc_streamon = vidioc_streamon, |
| 884 | .vidioc_streamoff = vidioc_streamoff, |
| 885 | .vidioc_log_status = vidioc_log_status, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 886 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 887 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 888 | }; |
| 889 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 890 | static const struct video_device cx25821_video_device = { |
| 891 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 892 | .fops = &video_fops, |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 893 | .release = video_device_release_empty, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 894 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 895 | .ioctl_ops = &video_ioctl_ops, |
| 896 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 897 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 898 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 899 | static const struct v4l2_file_operations video_out_fops = { |
| 900 | .owner = THIS_MODULE, |
| 901 | .open = v4l2_fh_open, |
| 902 | .release = v4l2_fh_release, |
| 903 | .unlocked_ioctl = video_ioctl2, |
| 904 | }; |
| 905 | |
| 906 | static const struct v4l2_ioctl_ops video_out_ioctl_ops = { |
| 907 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 908 | .vidioc_g_std = cx25821_vidioc_g_std, |
| 909 | .vidioc_s_std = cx25821_vidioc_s_std, |
| 910 | .vidioc_enum_output = cx25821_vidioc_enum_output, |
| 911 | .vidioc_g_output = cx25821_vidioc_g_output, |
| 912 | .vidioc_s_output = cx25821_vidioc_s_output, |
| 913 | .vidioc_log_status = vidioc_log_status, |
| 914 | }; |
| 915 | |
| 916 | static const struct video_device cx25821_video_out_device = { |
| 917 | .name = "cx25821-video", |
| 918 | .fops = &video_out_fops, |
| 919 | .release = video_device_release_empty, |
| 920 | .minor = -1, |
| 921 | .ioctl_ops = &video_out_ioctl_ops, |
| 922 | .tvnorms = CX25821_NORMS, |
| 923 | }; |
| 924 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 925 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 926 | { |
| 927 | cx_clear(PCI_INT_MSK, 1); |
| 928 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 929 | if (video_is_registered(&dev->channels[chan_num].vdev)) { |
| 930 | video_unregister_device(&dev->channels[chan_num].vdev); |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 931 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 932 | |
| 933 | btcx_riscmem_free(dev->pci, |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 934 | &dev->channels[chan_num].dma_vidq.stopper); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 935 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | int cx25821_video_register(struct cx25821_dev *dev) |
| 939 | { |
| 940 | int err; |
| 941 | int i; |
| 942 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 943 | /* initial device configuration */ |
Hans Verkuil | a6aa0dc | 2013-04-13 13:34:34 -0300 | [diff] [blame] | 944 | dev->tvnorm = V4L2_STD_NTSC_M; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 945 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 946 | spin_lock_init(&dev->slock); |
| 947 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 948 | for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 949 | struct cx25821_channel *chan = &dev->channels[i]; |
| 950 | struct video_device *vdev = &chan->vdev; |
| 951 | struct v4l2_ctrl_handler *hdl = &chan->hdl; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 952 | bool is_output = i > SRAM_CH08; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 953 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 954 | if (i == SRAM_CH08) /* audio channel */ |
| 955 | continue; |
| 956 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 957 | if (!is_output) { |
| 958 | v4l2_ctrl_handler_init(hdl, 4); |
| 959 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 960 | V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); |
| 961 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 962 | V4L2_CID_CONTRAST, 0, 10000, 1, 5000); |
| 963 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 964 | V4L2_CID_SATURATION, 0, 10000, 1, 5000); |
| 965 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 966 | V4L2_CID_HUE, 0, 10000, 1, 5000); |
| 967 | if (hdl->error) { |
| 968 | err = hdl->error; |
| 969 | goto fail_unreg; |
| 970 | } |
| 971 | err = v4l2_ctrl_handler_setup(hdl); |
| 972 | if (err) |
| 973 | goto fail_unreg; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 974 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 975 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 976 | cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper, |
| 977 | chan->sram_channels->dma_ctl, 0x11, 0); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 978 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 979 | chan->sram_channels = &cx25821_sram_channels[i]; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 980 | chan->width = 720; |
| 981 | if (dev->tvnorm & V4L2_STD_625_50) |
| 982 | chan->height = 576; |
| 983 | else |
| 984 | chan->height = 480; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 985 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 986 | if (chan->pixel_formats == PIXEL_FRMT_411) |
| 987 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); |
| 988 | else |
| 989 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); |
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 | cx_write(chan->sram_channels->int_stat, 0xffffffff); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 992 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 993 | INIT_LIST_HEAD(&chan->dma_vidq.active); |
| 994 | INIT_LIST_HEAD(&chan->dma_vidq.queued); |
| 995 | |
| 996 | chan->timeout_data.dev = dev; |
| 997 | chan->timeout_data.channel = &cx25821_sram_channels[i]; |
| 998 | chan->dma_vidq.timeout.function = cx25821_vid_timeout; |
| 999 | chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data; |
| 1000 | init_timer(&chan->dma_vidq.timeout); |
| 1001 | |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 1002 | if (!is_output) |
| 1003 | videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev, |
| 1004 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 1005 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), |
| 1006 | chan, &dev->lock); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1007 | |
| 1008 | /* register v4l devices */ |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 1009 | *vdev = is_output ? cx25821_video_out_device : cx25821_video_device; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1010 | vdev->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 1f19887 | 2013-04-14 12:07:13 -0300 | [diff] [blame] | 1011 | if (!is_output) |
| 1012 | vdev->ctrl_handler = hdl; |
| 1013 | else |
| 1014 | vdev->vfl_dir = VFL_DIR_TX; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1015 | vdev->lock = &dev->lock; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1016 | set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags); |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1017 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1018 | video_set_drvdata(vdev, chan); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1019 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1020 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1021 | video_nr[dev->nr]); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1022 | |
| 1023 | if (err < 0) |
| 1024 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* set PCI interrupt */ |
| 1028 | cx_set(PCI_INT_MSK, 0xff); |
| 1029 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1030 | return 0; |
| 1031 | |
| 1032 | fail_unreg: |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1033 | while (i >= 0) |
| 1034 | cx25821_video_unregister(dev, i--); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1035 | return err; |
| 1036 | } |