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 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 114 | static int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 115 | { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 116 | dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", |
| 117 | __func__, (unsigned int)norm, v4l2_norm_to_name(norm)); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 118 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 119 | dev->tvnorm = norm; |
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 | /* Tell the internal A/V decoder */ |
| 122 | cx25821_call_all(dev, core, s_std, norm); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 123 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 124 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 125 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 126 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 127 | static int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 128 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 129 | struct v4l2_routing route; |
| 130 | memset(&route, 0, sizeof(route)); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 131 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 132 | dprintk(1, "%s(): video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 133 | __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0, |
| 134 | INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3); |
| 135 | dev->input = input; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 136 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 137 | route.input = INPUT(input)->vmux; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 138 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 139 | /* Tell the internal A/V decoder */ |
| 140 | cx25821_call_all(dev, video, s_routing, INPUT(input)->vmux, 0, 0); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 141 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 142 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | int cx25821_start_video_dma(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 146 | struct cx25821_dmaqueue *q, |
| 147 | struct cx25821_buffer *buf, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 148 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 149 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 150 | int tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 151 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 152 | /* setup fifo + format */ |
| 153 | cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); |
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 | /* reset counter */ |
| 156 | cx_write(channel->gpcnt_ctl, 3); |
| 157 | q->count = 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 158 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 159 | /* enable irq */ |
| 160 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); |
| 161 | cx_set(channel->int_msk, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 162 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 163 | /* start dma */ |
| 164 | cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 165 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 166 | /* make sure upstream setting if any is reversed */ |
| 167 | tmp = cx_read(VID_CH_MODE_SEL); |
| 168 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 170 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 171 | } |
| 172 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 173 | static int cx25821_restart_video_queue(struct cx25821_dev *dev, |
| 174 | struct cx25821_dmaqueue *q, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 175 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 176 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 177 | struct cx25821_buffer *buf, *prev; |
| 178 | struct list_head *item; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 179 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 180 | if (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 181 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 182 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 183 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 184 | cx25821_start_video_dma(dev, q, buf, channel); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 185 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 186 | list_for_each(item, &q->active) { |
| 187 | buf = list_entry(item, struct cx25821_buffer, vb.queue); |
| 188 | buf->count = q->count++; |
| 189 | } |
| 190 | |
| 191 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 192 | return 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 193 | } |
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 | prev = NULL; |
| 196 | for (;;) { |
| 197 | if (list_empty(&q->queued)) |
| 198 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 199 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 200 | buf = list_entry(q->queued.next, struct cx25821_buffer, |
| 201 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 202 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 203 | if (NULL == prev) { |
| 204 | list_move_tail(&buf->vb.queue, &q->active); |
| 205 | cx25821_start_video_dma(dev, q, buf, channel); |
| 206 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 207 | buf->count = q->count++; |
| 208 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 209 | } else if (prev->vb.width == buf->vb.width && |
| 210 | prev->vb.height == buf->vb.height && |
| 211 | prev->fmt == buf->fmt) { |
| 212 | list_move_tail(&buf->vb.queue, &q->active); |
| 213 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 214 | buf->count = q->count++; |
| 215 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 216 | prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 217 | } else { |
| 218 | return 0; |
| 219 | } |
| 220 | prev = buf; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 221 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 222 | } |
| 223 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 224 | static void cx25821_vid_timeout(unsigned long data) |
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 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; |
| 227 | struct cx25821_dev *dev = timeout_data->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 228 | const struct sram_channel *channel = timeout_data->channel; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 229 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 230 | struct cx25821_buffer *buf; |
| 231 | unsigned long flags; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 232 | |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 233 | /* cx25821_sram_channel_dump(dev, channel); */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 234 | cx_clear(channel->dma_ctl, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 235 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 236 | spin_lock_irqsave(&dev->slock, flags); |
| 237 | while (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 238 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 239 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 240 | list_del(&buf->vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 241 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 242 | buf->vb.state = VIDEOBUF_ERROR; |
| 243 | wake_up(&buf->vb.done); |
| 244 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 245 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 246 | cx25821_restart_video_queue(dev, q, channel); |
| 247 | spin_unlock_irqrestore(&dev->slock, flags); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) |
| 251 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 252 | u32 count = 0; |
| 253 | int handled = 0; |
| 254 | u32 mask; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 255 | const struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 256 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 257 | mask = cx_read(channel->int_msk); |
| 258 | if (0 == (status & mask)) |
| 259 | return handled; |
| 260 | |
| 261 | cx_write(channel->int_stat, status); |
| 262 | |
| 263 | /* risc op code error */ |
| 264 | if (status & (1 << 16)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 265 | pr_warn("%s, %s: video risc op code error\n", |
| 266 | dev->name, channel->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 267 | cx_clear(channel->dma_ctl, 0x11); |
| 268 | cx25821_sram_channel_dump(dev, channel); |
| 269 | } |
| 270 | |
| 271 | /* risc1 y */ |
| 272 | if (status & FLD_VID_DST_RISC1) { |
| 273 | spin_lock(&dev->slock); |
| 274 | count = cx_read(channel->gpcnt); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 275 | cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq, |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 276 | count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 277 | spin_unlock(&dev->slock); |
| 278 | handled++; |
| 279 | } |
| 280 | |
| 281 | /* risc2 y */ |
| 282 | if (status & 0x10) { |
| 283 | dprintk(2, "stopper video\n"); |
| 284 | spin_lock(&dev->slock); |
Leonid V. Fedorenchik | 788d0f3 | 2011-09-16 14:14:39 +0800 | [diff] [blame] | 285 | cx25821_restart_video_queue(dev, |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 286 | &dev->channels[channel->i].dma_vidq, channel); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 287 | spin_unlock(&dev->slock); |
| 288 | handled++; |
| 289 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 290 | return handled; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 291 | } |
| 292 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 293 | 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] | 294 | unsigned int *size) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 295 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 296 | struct cx25821_channel *chan = q->priv_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 297 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 298 | *size = chan->fmt->depth * chan->width * chan->height >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 299 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 300 | if (0 == *count) |
| 301 | *count = 32; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 302 | |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 303 | if (*size * *count > vid_limit * 1024 * 1024) |
| 304 | *count = (vid_limit * 1024 * 1024) / *size; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 305 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 306 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 307 | } |
| 308 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 309 | 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] | 310 | enum v4l2_field field) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 311 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 312 | struct cx25821_channel *chan = q->priv_data; |
| 313 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 314 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 315 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 316 | int rc, init_buffer = 0; |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 317 | u32 line0_offset; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 318 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
| 319 | int bpl_local = LINE_SIZE_D1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 320 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 321 | BUG_ON(NULL == chan->fmt); |
| 322 | if (chan->width < 48 || chan->width > 720 || |
| 323 | chan->height < 32 || chan->height > 576) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 324 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 325 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 326 | buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 327 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 328 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 329 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 330 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 331 | if (buf->fmt != chan->fmt || |
| 332 | buf->vb.width != chan->width || |
| 333 | buf->vb.height != chan->height || buf->vb.field != field) { |
| 334 | buf->fmt = chan->fmt; |
| 335 | buf->vb.width = chan->width; |
| 336 | buf->vb.height = chan->height; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 337 | buf->vb.field = field; |
| 338 | init_buffer = 1; |
| 339 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 340 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 341 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 342 | init_buffer = 1; |
| 343 | rc = videobuf_iolock(q, &buf->vb, NULL); |
| 344 | if (0 != rc) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 345 | printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 346 | goto fail; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 347 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 348 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 349 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 350 | dprintk(1, "init_buffer=%d\n", init_buffer); |
| 351 | |
| 352 | if (init_buffer) { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 353 | if (chan->pixel_formats == PIXEL_FRMT_411) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 354 | buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; |
| 355 | else |
| 356 | buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); |
| 357 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 358 | if (chan->pixel_formats == PIXEL_FRMT_411) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 359 | bpl_local = buf->bpl; |
| 360 | } else { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 361 | bpl_local = buf->bpl; /* Default */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 362 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 363 | if (chan->use_cif_resolution) { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 364 | if (dev->tvnorm & V4L2_STD_625_50) |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 365 | bpl_local = 352 << 1; |
| 366 | else |
| 367 | bpl_local = chan->cif_width << 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 368 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 369 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 370 | |
| 371 | switch (buf->vb.field) { |
| 372 | case V4L2_FIELD_TOP: |
| 373 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 374 | dma->sglist, 0, UNSET, |
| 375 | buf->bpl, 0, buf->vb.height); |
| 376 | break; |
| 377 | case V4L2_FIELD_BOTTOM: |
| 378 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 379 | dma->sglist, UNSET, 0, |
| 380 | buf->bpl, 0, buf->vb.height); |
| 381 | break; |
| 382 | case V4L2_FIELD_INTERLACED: |
| 383 | /* All other formats are top field first */ |
| 384 | line0_offset = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 385 | dprintk(1, "top field first\n"); |
| 386 | |
| 387 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 388 | dma->sglist, line0_offset, |
| 389 | bpl_local, bpl_local, bpl_local, |
| 390 | buf->vb.height >> 1); |
| 391 | break; |
| 392 | case V4L2_FIELD_SEQ_TB: |
| 393 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 394 | dma->sglist, |
| 395 | 0, buf->bpl * (buf->vb.height >> 1), |
| 396 | buf->bpl, 0, buf->vb.height >> 1); |
| 397 | break; |
| 398 | case V4L2_FIELD_SEQ_BT: |
| 399 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 400 | dma->sglist, |
| 401 | buf->bpl * (buf->vb.height >> 1), 0, |
| 402 | buf->bpl, 0, buf->vb.height >> 1); |
| 403 | break; |
| 404 | default: |
| 405 | BUG(); |
| 406 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 407 | } |
| 408 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 409 | 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] | 410 | buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth, |
| 411 | chan->fmt->name, (unsigned long)buf->risc.dma); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 412 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 413 | buf->vb.state = VIDEOBUF_PREPARED; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 415 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 416 | |
Leonid V. Fedorenchik | 2748f26 | 2011-09-16 14:14:34 +0800 | [diff] [blame] | 417 | fail: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 418 | cx25821_free_buffer(q, buf); |
| 419 | return rc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 420 | } |
| 421 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 422 | static void cx25821_buffer_release(struct videobuf_queue *q, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 423 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 424 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 425 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 426 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 427 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 428 | cx25821_free_buffer(q, buf); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 429 | } |
| 430 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 431 | 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] | 432 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 433 | struct cx25821_channel *chan = video_drvdata(file); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 434 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 435 | return videobuf_mmap_mapper(&chan->vidq, vma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 436 | } |
| 437 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 438 | |
| 439 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 440 | { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 441 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 442 | container_of(vb, struct cx25821_buffer, vb); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 443 | struct cx25821_buffer *prev; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 444 | struct cx25821_channel *chan = vq->priv_data; |
| 445 | struct cx25821_dev *dev = chan->dev; |
| 446 | struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 447 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 448 | /* add jump to stopper */ |
| 449 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 450 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 451 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 452 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 453 | dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 454 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 455 | if (!list_empty(&q->queued)) { |
| 456 | list_add_tail(&buf->vb.queue, &q->queued); |
| 457 | buf->vb.state = VIDEOBUF_QUEUED; |
| 458 | dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, |
| 459 | buf->vb.i); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 460 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 461 | } else if (list_empty(&q->active)) { |
| 462 | list_add_tail(&buf->vb.queue, &q->active); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 463 | cx25821_start_video_dma(dev, q, buf, chan->sram_channels); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 464 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 465 | buf->count = q->count++; |
| 466 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 467 | dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", |
| 468 | buf, buf->vb.i, buf->count, q->count); |
| 469 | } else { |
| 470 | prev = list_entry(q->active.prev, struct cx25821_buffer, |
| 471 | vb.queue); |
| 472 | if (prev->vb.width == buf->vb.width |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 473 | && prev->vb.height == buf->vb.height |
| 474 | && prev->fmt == buf->fmt) { |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 475 | list_add_tail(&buf->vb.queue, &q->active); |
| 476 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 477 | buf->count = q->count++; |
| 478 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 479 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 480 | /* 64 bit bits 63-32 */ |
| 481 | prev->risc.jmp[2] = cpu_to_le32(0); |
| 482 | dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", |
| 483 | buf, buf->vb.i, buf->count); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 484 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 485 | } else { |
| 486 | list_add_tail(&buf->vb.queue, &q->queued); |
| 487 | buf->vb.state = VIDEOBUF_QUEUED; |
| 488 | dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, |
| 489 | buf->vb.i); |
| 490 | } |
| 491 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 492 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 493 | if (list_empty(&q->active)) |
| 494 | dprintk(2, "active queue empty!\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static struct videobuf_queue_ops cx25821_video_qops = { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 498 | .buf_setup = cx25821_buffer_setup, |
| 499 | .buf_prepare = cx25821_buffer_prepare, |
| 500 | .buf_queue = buffer_queue, |
| 501 | .buf_release = cx25821_buffer_release, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 502 | }; |
| 503 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 504 | 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] | 505 | loff_t *ppos) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 506 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 507 | struct v4l2_fh *fh = file->private_data; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 508 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 509 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 510 | int err = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 511 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 512 | if (mutex_lock_interruptible(&dev->lock)) |
| 513 | return -ERESTARTSYS; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 514 | if (chan->streaming_fh && chan->streaming_fh != fh) { |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 515 | err = -EBUSY; |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 516 | goto unlock; |
| 517 | } |
| 518 | chan->streaming_fh = fh; |
| 519 | |
| 520 | err = videobuf_read_one(&chan->vidq, data, count, ppos, |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 521 | file->f_flags & O_NONBLOCK); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 522 | unlock: |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 523 | mutex_unlock(&dev->lock); |
| 524 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | static unsigned int video_poll(struct file *file, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 528 | struct poll_table_struct *wait) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 529 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 530 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 531 | unsigned long req_events = poll_requested_events(wait); |
| 532 | unsigned int res = v4l2_ctrl_poll(file, wait); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 533 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 534 | if (req_events & (POLLIN | POLLRDNORM)) |
| 535 | res |= videobuf_poll_stream(file, &chan->vidq, wait); |
| 536 | return res; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 537 | |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 538 | /* This doesn't belong in poll(). This can be done |
| 539 | * much better with vb2. We keep this code here as a |
| 540 | * reminder. |
| 541 | if ((res & POLLIN) && buf->vb.state == VIDEOBUF_DONE) { |
| 542 | struct cx25821_dev *dev = chan->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 543 | |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 544 | if (dev && chan->use_cif_resolution) { |
| 545 | u8 cam_id = *((char *)buf->vb.baddr + 3); |
| 546 | memcpy((char *)buf->vb.baddr, |
| 547 | (char *)buf->vb.baddr + (chan->width * 2), |
| 548 | (chan->width * 2)); |
| 549 | *((char *)buf->vb.baddr + 3) = cam_id; |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 550 | } |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 551 | } |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 552 | */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static int video_release(struct file *file) |
| 556 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 557 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 558 | struct v4l2_fh *fh = file->private_data; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 559 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 560 | const struct sram_channel *sram_ch = |
| 561 | dev->channels[0].sram_channels; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 562 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 563 | mutex_lock(&dev->lock); |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 564 | /* stop the risc engine and fifo */ |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 565 | cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 566 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 567 | /* stop video capture */ |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 568 | if (chan->streaming_fh == fh) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 569 | videobuf_queue_cancel(&chan->vidq); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 570 | chan->streaming_fh = NULL; |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 571 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 572 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 573 | if (chan->vidq.read_buf) { |
| 574 | cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf); |
| 575 | kfree(chan->vidq.read_buf); |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 576 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 577 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 578 | videobuf_mmap_free(&chan->vidq); |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 579 | mutex_unlock(&dev->lock); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 580 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 581 | return v4l2_fh_release(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 582 | } |
| 583 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 584 | /* VIDEO IOCTLS */ |
| 585 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 586 | struct v4l2_format *f) |
| 587 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 588 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 589 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 590 | f->fmt.pix.width = chan->width; |
| 591 | f->fmt.pix.height = chan->height; |
| 592 | f->fmt.pix.field = chan->vidq.field; |
| 593 | f->fmt.pix.pixelformat = chan->fmt->fourcc; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 594 | f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; |
| 595 | f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; |
| 596 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 597 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 603 | struct v4l2_format *f) |
| 604 | { |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 605 | struct cx25821_channel *chan = video_drvdata(file); |
| 606 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 607 | const struct cx25821_fmt *fmt; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 608 | enum v4l2_field field = f->fmt.pix.field; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 609 | unsigned int maxw, maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 610 | unsigned w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 611 | |
| 612 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 613 | if (NULL == fmt) |
| 614 | return -EINVAL; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 615 | maxw = 720; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 616 | maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 617 | |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 618 | w = f->fmt.pix.width; |
| 619 | if (field != V4L2_FIELD_BOTTOM) |
| 620 | field = V4L2_FIELD_TOP; |
| 621 | if (w < 352) { |
| 622 | w = 176; |
| 623 | f->fmt.pix.height = maxh / 4; |
| 624 | } else if (w < 720) { |
| 625 | w = 352; |
| 626 | f->fmt.pix.height = maxh / 2; |
| 627 | } else { |
| 628 | w = 720; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 629 | f->fmt.pix.height = maxh; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 630 | field = V4L2_FIELD_INTERLACED; |
| 631 | } |
| 632 | f->fmt.pix.field = field; |
| 633 | f->fmt.pix.width = w; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 634 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 635 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 636 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 637 | f->fmt.pix.priv = 0; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 638 | |
| 639 | return 0; |
| 640 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 641 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 642 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 643 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 644 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 645 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 646 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 647 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 648 | if (chan->streaming_fh && chan->streaming_fh != priv) |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 649 | return -EBUSY; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 650 | chan->streaming_fh = priv; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 651 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 652 | return videobuf_streamon(&chan->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 656 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 657 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 658 | |
Hans Verkuil | 11f095a | 2013-04-14 11:54:56 -0300 | [diff] [blame] | 659 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 660 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 661 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 662 | if (chan->streaming_fh && chan->streaming_fh != priv) |
Hans Verkuil | 84293f0 | 2013-04-14 11:56:39 -0300 | [diff] [blame] | 663 | return -EBUSY; |
| 664 | if (chan->streaming_fh == NULL) |
| 665 | return 0; |
| 666 | |
| 667 | chan->streaming_fh = NULL; |
| 668 | return videobuf_streamoff(&chan->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | 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] | 672 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 673 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 674 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 675 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 676 | struct v4l2_mbus_framefmt mbus_fmt; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 677 | int err; |
| 678 | int pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 679 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 680 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 681 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 682 | if (0 != err) |
| 683 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 684 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 685 | chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 686 | chan->vidq.field = f->fmt.pix.field; |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 687 | chan->width = f->fmt.pix.width; |
| 688 | chan->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 689 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 690 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 691 | pix_format = PIXEL_FRMT_411; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 692 | else |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 693 | pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 694 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 695 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 696 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 697 | /* check if cif resolution */ |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 698 | if (chan->width == 320 || chan->width == 352) |
| 699 | chan->use_cif_resolution = 1; |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 700 | else |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 701 | chan->use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 702 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 703 | chan->cif_width = chan->width; |
| 704 | medusa_set_resolution(dev, chan->width, SRAM_CH00); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 705 | |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 706 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 707 | cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 708 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 709 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 713 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 714 | int ret_val = 0; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 715 | struct cx25821_channel *chan = video_drvdata(file); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 716 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 717 | ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK); |
| 718 | p->sequence = chan->dma_vidq.count; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 719 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 720 | return ret_val; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static int vidioc_log_status(struct file *file, void *priv) |
| 724 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 725 | struct cx25821_channel *chan = video_drvdata(file); |
| 726 | struct cx25821_dev *dev = chan->dev; |
| 727 | const struct sram_channel *sram_ch = chan->sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 728 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 729 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 730 | cx25821_call_all(dev, core, log_status); |
| 731 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 732 | pr_info("Video input 0 is %s\n", |
| 733 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 734 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 735 | } |
| 736 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 737 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 738 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 739 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 740 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 741 | struct cx25821_channel *chan = video_drvdata(file); |
| 742 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 743 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 744 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 745 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 746 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 747 | strcpy(cap->driver, "cx25821"); |
| 748 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 749 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 750 | if (chan->id >= VID_CHANNEL_NUM) |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 751 | cap->device_caps = cap_output; |
| 752 | else |
| 753 | cap->device_caps = cap_input; |
| 754 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 755 | return 0; |
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_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 759 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 760 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 761 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 762 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 763 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 764 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 765 | f->pixelformat = formats[f->index].fourcc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 766 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 767 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 768 | } |
| 769 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 770 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 771 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 772 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 773 | struct cx25821_channel *chan = video_drvdata(file); |
| 774 | |
| 775 | return videobuf_reqbufs(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 776 | } |
| 777 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 778 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 779 | struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 780 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 781 | struct cx25821_channel *chan = video_drvdata(file); |
| 782 | |
| 783 | return videobuf_querybuf(&chan->vidq, p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 784 | } |
| 785 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 786 | 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] | 787 | { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 788 | struct cx25821_channel *chan = video_drvdata(file); |
| 789 | |
| 790 | return videobuf_qbuf(&chan->vidq, p); |
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_std(struct file *file, void *priv, v4l2_std_id *tvnorms) |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 794 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 795 | struct cx25821_channel *chan = video_drvdata(file); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 796 | |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 797 | *tvnorms = chan->dev->tvnorm; |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 801 | 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] | 802 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 803 | struct cx25821_channel *chan = video_drvdata(file); |
| 804 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 805 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 806 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 807 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 808 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 809 | cx25821_set_tvnorm(dev, tvnorms); |
Hans Verkuil | 988f7b8 | 2013-04-13 13:06:00 -0300 | [diff] [blame^] | 810 | chan->width = 720; |
| 811 | chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 812 | |
| 813 | medusa_set_videostandard(dev); |
| 814 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 815 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 816 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 817 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 818 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 819 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 820 | { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 821 | static const char * const iname[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 822 | [CX25821_VMUX_COMPOSITE] = "Composite", |
| 823 | [CX25821_VMUX_SVIDEO] = "S-Video", |
| 824 | [CX25821_VMUX_DEBUG] = "for debug only", |
| 825 | }; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 826 | struct cx25821_channel *chan = video_drvdata(file); |
| 827 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 828 | unsigned int n; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 829 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 830 | n = i->index; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 831 | if (n >= CX25821_NR_INPUT) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 832 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 833 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 834 | if (0 == INPUT(n)->type) |
| 835 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 836 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 837 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 838 | strcpy(i->name, iname[INPUT(n)->type]); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 839 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 840 | i->std = CX25821_NORMS; |
| 841 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 842 | } |
| 843 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 844 | 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] | 845 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 846 | struct cx25821_channel *chan = video_drvdata(file); |
| 847 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 848 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 849 | *i = dev->input; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 850 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 851 | } |
| 852 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 853 | 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] | 854 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 855 | struct cx25821_channel *chan = video_drvdata(file); |
| 856 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 857 | |
Hans Verkuil | 6b1dce2 | 2013-04-13 07:39:19 -0300 | [diff] [blame] | 858 | if (i >= CX25821_NR_INPUT || INPUT(i)->type == 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 859 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 860 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 861 | cx25821_video_mux(dev, i); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 862 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 863 | } |
| 864 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 865 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 866 | int cx25821_vidioc_g_register(struct file *file, void *fh, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 867 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 868 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 869 | struct cx25821_channel *chan = video_drvdata(file); |
| 870 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 871 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 872 | if (!v4l2_chip_match_host(®->match)) |
| 873 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 874 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 875 | cx25821_call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 876 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 877 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 878 | } |
| 879 | |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 880 | int cx25821_vidioc_s_register(struct file *file, void *fh, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 881 | const struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 882 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 883 | struct cx25821_channel *chan = video_drvdata(file); |
| 884 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 885 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 886 | if (!v4l2_chip_match_host(®->match)) |
| 887 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 888 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 889 | cx25821_call_all(dev, core, s_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 890 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 891 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | #endif |
| 895 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 896 | static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 897 | { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 898 | struct cx25821_channel *chan = |
| 899 | container_of(ctrl->handler, struct cx25821_channel, hdl); |
| 900 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 901 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 902 | switch (ctrl->id) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 903 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 904 | medusa_set_brightness(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 905 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 906 | case V4L2_CID_HUE: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 907 | medusa_set_hue(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 908 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 909 | case V4L2_CID_CONTRAST: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 910 | medusa_set_contrast(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 911 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 912 | case V4L2_CID_SATURATION: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 913 | medusa_set_saturation(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 914 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 915 | default: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 916 | return -EINVAL; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 917 | } |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 918 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 919 | } |
| 920 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 921 | static long video_ioctl_upstream9(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 922 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 923 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 924 | struct cx25821_channel *chan = video_drvdata(file); |
| 925 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 926 | int command = 0; |
| 927 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 928 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 929 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 930 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 931 | if (!data_from_user) { |
| 932 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 933 | return 0; |
| 934 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 935 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 936 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 937 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 938 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 939 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 940 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 941 | dev->input_filename = data_from_user->input_filename; |
| 942 | dev->input_audiofilename = data_from_user->input_filename; |
| 943 | dev->vid_stdname = data_from_user->vid_stdname; |
| 944 | dev->pixel_format = data_from_user->pixel_format; |
| 945 | dev->channel_select = data_from_user->channel_select; |
| 946 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 947 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 948 | switch (command) { |
| 949 | case UPSTREAM_START_VIDEO: |
| 950 | cx25821_start_upstream_video_ch1(dev, data_from_user); |
| 951 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 952 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 953 | case UPSTREAM_STOP_VIDEO: |
| 954 | cx25821_stop_upstream_video_ch1(dev); |
| 955 | break; |
| 956 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 957 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 958 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static long video_ioctl_upstream10(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 962 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 963 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 964 | struct cx25821_channel *chan = video_drvdata(file); |
| 965 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 966 | int command = 0; |
| 967 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 968 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 969 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 970 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 971 | if (!data_from_user) { |
| 972 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 973 | return 0; |
| 974 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 975 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 976 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 977 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 978 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 979 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 980 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 981 | dev->input_filename_ch2 = data_from_user->input_filename; |
| 982 | dev->input_audiofilename = data_from_user->input_filename; |
| 983 | dev->vid_stdname_ch2 = data_from_user->vid_stdname; |
| 984 | dev->pixel_format_ch2 = data_from_user->pixel_format; |
| 985 | dev->channel_select_ch2 = data_from_user->channel_select; |
| 986 | dev->command_ch2 = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 987 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 988 | switch (command) { |
| 989 | case UPSTREAM_START_VIDEO: |
| 990 | cx25821_start_upstream_video_ch2(dev, data_from_user); |
| 991 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 992 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 993 | case UPSTREAM_STOP_VIDEO: |
| 994 | cx25821_stop_upstream_video_ch2(dev); |
| 995 | break; |
| 996 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 997 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 998 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static long video_ioctl_upstream11(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1002 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1003 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1004 | struct cx25821_channel *chan = video_drvdata(file); |
| 1005 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1006 | int command = 0; |
| 1007 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1008 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1009 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1010 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1011 | if (!data_from_user) { |
| 1012 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1013 | return 0; |
| 1014 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1015 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1016 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1017 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1018 | if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) |
| 1019 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1020 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1021 | dev->input_filename = data_from_user->input_filename; |
| 1022 | dev->input_audiofilename = data_from_user->input_filename; |
| 1023 | dev->vid_stdname = data_from_user->vid_stdname; |
| 1024 | dev->pixel_format = data_from_user->pixel_format; |
| 1025 | dev->channel_select = data_from_user->channel_select; |
| 1026 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1027 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1028 | switch (command) { |
| 1029 | case UPSTREAM_START_AUDIO: |
| 1030 | cx25821_start_upstream_audio(dev, data_from_user); |
| 1031 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1032 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1033 | case UPSTREAM_STOP_AUDIO: |
| 1034 | cx25821_stop_upstream_audio(dev); |
| 1035 | break; |
| 1036 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1037 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1038 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static long video_ioctl_set(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1042 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1043 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1044 | struct cx25821_channel *chan = video_drvdata(file); |
| 1045 | struct cx25821_dev *dev = chan->dev; |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1046 | struct downstream_user_struct *data_from_user; |
| 1047 | int command; |
| 1048 | int width = 720; |
Leonid V. Fedorenchik | 4a33b6f | 2011-10-22 01:43:52 -0300 | [diff] [blame] | 1049 | int selected_channel = 0; |
| 1050 | int pix_format = 0; |
| 1051 | int i = 0; |
| 1052 | int cif_enable = 0; |
| 1053 | int cif_width = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1054 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1055 | data_from_user = (struct downstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1056 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1057 | if (!data_from_user) { |
| 1058 | pr_err("%s(): User data is INVALID. Returning\n", __func__); |
| 1059 | return 0; |
| 1060 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1061 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1062 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1063 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1064 | if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1065 | && command != ENABLE_CIF_RESOLUTION && command != REG_READ |
| 1066 | && command != REG_WRITE && command != MEDUSA_READ |
| 1067 | && command != MEDUSA_WRITE) { |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1070 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1071 | switch (command) { |
| 1072 | case SET_VIDEO_STD: |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1073 | if (!strcmp(data_from_user->vid_stdname, "PAL")) |
| 1074 | dev->tvnorm = V4L2_STD_PAL_BG; |
| 1075 | else |
| 1076 | dev->tvnorm = V4L2_STD_NTSC_M; |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1077 | medusa_set_videostandard(dev); |
| 1078 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1079 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1080 | case SET_PIXEL_FORMAT: |
| 1081 | selected_channel = data_from_user->decoder_select; |
| 1082 | pix_format = data_from_user->pixel_format; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1083 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1084 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1085 | selected_channel -= 4; |
| 1086 | selected_channel = selected_channel % 8; |
| 1087 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1088 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1089 | if (selected_channel >= 0) |
| 1090 | cx25821_set_pixel_format(dev, selected_channel, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1091 | pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1092 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1093 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1094 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1095 | case ENABLE_CIF_RESOLUTION: |
| 1096 | selected_channel = data_from_user->decoder_select; |
| 1097 | cif_enable = data_from_user->cif_resolution_enable; |
| 1098 | cif_width = data_from_user->cif_width; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1099 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1100 | if (cif_enable) { |
| 1101 | if (dev->tvnorm & V4L2_STD_PAL_BG |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1102 | || dev->tvnorm & V4L2_STD_PAL_DK) { |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1103 | width = 352; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1104 | } else { |
| 1105 | width = cif_width; |
| 1106 | if (cif_width != 320 && cif_width != 352) |
| 1107 | width = 320; |
| 1108 | } |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1109 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1110 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1111 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1112 | selected_channel -= 4; |
| 1113 | selected_channel = selected_channel % 8; |
| 1114 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1115 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1116 | if (selected_channel <= 7 && selected_channel >= 0) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 1117 | dev->channels[selected_channel].use_cif_resolution = |
| 1118 | cif_enable; |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1119 | dev->channels[selected_channel].cif_width = width; |
| 1120 | } else { |
| 1121 | for (i = 0; i < VID_CHANNEL_NUM; i++) { |
| 1122 | dev->channels[i].use_cif_resolution = |
| 1123 | cif_enable; |
| 1124 | dev->channels[i].cif_width = width; |
| 1125 | } |
| 1126 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1127 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1128 | medusa_set_resolution(dev, width, selected_channel); |
| 1129 | break; |
| 1130 | case REG_READ: |
| 1131 | data_from_user->reg_data = cx_read(data_from_user->reg_address); |
| 1132 | break; |
| 1133 | case REG_WRITE: |
| 1134 | cx_write(data_from_user->reg_address, data_from_user->reg_data); |
| 1135 | break; |
| 1136 | case MEDUSA_READ: |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 1137 | cx25821_i2c_read(&dev->i2c_bus[0], |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1138 | (u16) data_from_user->reg_address, |
| 1139 | &data_from_user->reg_data); |
| 1140 | break; |
| 1141 | case MEDUSA_WRITE: |
| 1142 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 1143 | (u16) data_from_user->reg_address, |
| 1144 | data_from_user->reg_data); |
| 1145 | break; |
| 1146 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1147 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1148 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | static long cx25821_video_ioctl(struct file *file, |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1152 | unsigned int cmd, unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1153 | { |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1154 | struct cx25821_channel *chan = video_drvdata(file); |
Leonid V. Fedorenchik | 1316b63 | 2011-10-22 01:43:50 -0300 | [diff] [blame] | 1155 | int ret = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1156 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1157 | /* check to see if it's the video upstream */ |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1158 | if (chan->id == SRAM_CH09) { |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1159 | ret = video_ioctl_upstream9(file, cmd, arg); |
| 1160 | return ret; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1161 | } else if (chan->id == SRAM_CH10) { |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1162 | ret = video_ioctl_upstream10(file, cmd, arg); |
| 1163 | return ret; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1164 | } else if (chan->id == SRAM_CH11) { |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1165 | ret = video_ioctl_upstream11(file, cmd, arg); |
| 1166 | ret = video_ioctl_set(file, cmd, arg); |
| 1167 | return ret; |
| 1168 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1169 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1170 | return video_ioctl2(file, cmd, arg); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1171 | } |
| 1172 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 1173 | static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { |
| 1174 | .s_ctrl = cx25821_s_ctrl, |
| 1175 | }; |
| 1176 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1177 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1178 | .owner = THIS_MODULE, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1179 | .open = v4l2_fh_open, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1180 | .release = video_release, |
| 1181 | .read = video_read, |
| 1182 | .poll = video_poll, |
| 1183 | .mmap = cx25821_video_mmap, |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1184 | .unlocked_ioctl = cx25821_video_ioctl, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1185 | }; |
| 1186 | |
| 1187 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1188 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 1189 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 1190 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 1191 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 1192 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1193 | .vidioc_reqbufs = cx25821_vidioc_reqbufs, |
| 1194 | .vidioc_querybuf = cx25821_vidioc_querybuf, |
| 1195 | .vidioc_qbuf = cx25821_vidioc_qbuf, |
| 1196 | .vidioc_dqbuf = vidioc_dqbuf, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1197 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1198 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1199 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 1200 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 1201 | .vidioc_s_input = cx25821_vidioc_s_input, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1202 | .vidioc_streamon = vidioc_streamon, |
| 1203 | .vidioc_streamoff = vidioc_streamoff, |
| 1204 | .vidioc_log_status = vidioc_log_status, |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1205 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1206 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1207 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1208 | .vidioc_g_register = cx25821_vidioc_g_register, |
| 1209 | .vidioc_s_register = cx25821_vidioc_s_register, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1210 | #endif |
| 1211 | }; |
| 1212 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1213 | static const struct video_device cx25821_video_device = { |
| 1214 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1215 | .fops = &video_fops, |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1216 | .release = video_device_release_empty, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1217 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1218 | .ioctl_ops = &video_ioctl_ops, |
| 1219 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1220 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1221 | |
| 1222 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 1223 | { |
| 1224 | cx_clear(PCI_INT_MSK, 1); |
| 1225 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1226 | if (video_is_registered(&dev->channels[chan_num].vdev)) { |
| 1227 | video_unregister_device(&dev->channels[chan_num].vdev); |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 1228 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1229 | |
| 1230 | btcx_riscmem_free(dev->pci, |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1231 | &dev->channels[chan_num].dma_vidq.stopper); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1232 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | int cx25821_video_register(struct cx25821_dev *dev) |
| 1236 | { |
| 1237 | int err; |
| 1238 | int i; |
| 1239 | |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1240 | /* initial device configuration */ |
| 1241 | dev->tvnorm = V4L2_STD_NTSC_M, |
| 1242 | cx25821_set_tvnorm(dev, dev->tvnorm); |
| 1243 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1244 | spin_lock_init(&dev->slock); |
| 1245 | |
| 1246 | for (i = 0; i < VID_CHANNEL_NUM; ++i) { |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1247 | struct cx25821_channel *chan = &dev->channels[i]; |
| 1248 | struct video_device *vdev = &chan->vdev; |
| 1249 | struct v4l2_ctrl_handler *hdl = &chan->hdl; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1250 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1251 | if (i == SRAM_CH08) /* audio channel */ |
| 1252 | continue; |
| 1253 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 1254 | v4l2_ctrl_handler_init(hdl, 4); |
| 1255 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1256 | V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); |
| 1257 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1258 | V4L2_CID_CONTRAST, 0, 10000, 1, 5000); |
| 1259 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1260 | V4L2_CID_SATURATION, 0, 10000, 1, 5000); |
| 1261 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1262 | V4L2_CID_HUE, 0, 10000, 1, 5000); |
| 1263 | if (hdl->error) { |
| 1264 | err = hdl->error; |
| 1265 | goto fail_unreg; |
| 1266 | } |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1267 | err = v4l2_ctrl_handler_setup(hdl); |
| 1268 | if (err) |
| 1269 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1270 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1271 | cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper, |
| 1272 | chan->sram_channels->dma_ctl, 0x11, 0); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1273 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1274 | chan->sram_channels = &cx25821_sram_channels[i]; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1275 | chan->width = 720; |
| 1276 | if (dev->tvnorm & V4L2_STD_625_50) |
| 1277 | chan->height = 576; |
| 1278 | else |
| 1279 | chan->height = 480; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1280 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1281 | if (chan->pixel_formats == PIXEL_FRMT_411) |
| 1282 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P); |
| 1283 | else |
| 1284 | chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1285 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1286 | cx_write(chan->sram_channels->int_stat, 0xffffffff); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1287 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1288 | INIT_LIST_HEAD(&chan->dma_vidq.active); |
| 1289 | INIT_LIST_HEAD(&chan->dma_vidq.queued); |
| 1290 | |
| 1291 | chan->timeout_data.dev = dev; |
| 1292 | chan->timeout_data.channel = &cx25821_sram_channels[i]; |
| 1293 | chan->dma_vidq.timeout.function = cx25821_vid_timeout; |
| 1294 | chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data; |
| 1295 | init_timer(&chan->dma_vidq.timeout); |
| 1296 | |
| 1297 | videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev, |
| 1298 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 1299 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), |
| 1300 | chan, &dev->lock); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1301 | |
| 1302 | /* register v4l devices */ |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1303 | *vdev = cx25821_video_device; |
| 1304 | vdev->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 1305 | vdev->ctrl_handler = hdl; |
Hans Verkuil | be178cb | 2013-04-14 11:53:35 -0300 | [diff] [blame] | 1306 | vdev->lock = &dev->lock; |
Hans Verkuil | 8d125c5 | 2013-04-14 11:57:18 -0300 | [diff] [blame] | 1307 | set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags); |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1308 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 1309 | video_set_drvdata(vdev, chan); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1310 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1311 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1312 | video_nr[dev->nr]); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1313 | |
| 1314 | if (err < 0) |
| 1315 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /* set PCI interrupt */ |
| 1319 | cx_set(PCI_INT_MSK, 0xff); |
| 1320 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1321 | return 0; |
| 1322 | |
| 1323 | fail_unreg: |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1324 | while (i >= 0) |
| 1325 | cx25821_video_unregister(dev, i--); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1326 | return err; |
| 1327 | } |