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 = "8 bpp, gray", |
| 58 | .fourcc = V4L2_PIX_FMT_GREY, |
| 59 | .depth = 8, |
| 60 | .flags = FORMAT_FLAGS_PACKED, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 61 | }, { |
Mauro Carvalho Chehab | d7d9338 | 2010-03-24 14:23:25 -0300 | [diff] [blame] | 62 | .name = "4:1:1, packed, Y41P", |
| 63 | .fourcc = V4L2_PIX_FMT_Y41P, |
| 64 | .depth = 12, |
| 65 | .flags = FORMAT_FLAGS_PACKED, |
| 66 | }, { |
| 67 | .name = "4:2:2, packed, YUYV", |
| 68 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 69 | .depth = 16, |
| 70 | .flags = FORMAT_FLAGS_PACKED, |
| 71 | }, { |
| 72 | .name = "4:2:2, packed, UYVY", |
| 73 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 74 | .depth = 16, |
| 75 | .flags = FORMAT_FLAGS_PACKED, |
| 76 | }, { |
| 77 | .name = "4:2:0, YUV", |
| 78 | .fourcc = V4L2_PIX_FMT_YUV420, |
| 79 | .depth = 12, |
| 80 | .flags = FORMAT_FLAGS_PACKED, |
| 81 | }, |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 82 | }; |
| 83 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 84 | 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] | 85 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 86 | unsigned int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 87 | |
Leonid V. Fedorenchik | e313e1f | 2011-09-16 14:15:13 +0800 | [diff] [blame] | 88 | if (fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 89 | return formats + 1; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 90 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 91 | for (i = 0; i < ARRAY_SIZE(formats); i++) |
| 92 | if (formats[i].fourcc == fourcc) |
| 93 | return formats + i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 94 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 95 | pr_err("%s(0x%08x) NOT FOUND\n", __func__, fourcc); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 96 | return NULL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 97 | } |
| 98 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 99 | void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, |
| 100 | u32 count) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 101 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 102 | struct cx25821_buffer *buf; |
| 103 | int bc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 104 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 105 | for (bc = 0;; bc++) { |
| 106 | if (list_empty(&q->active)) { |
| 107 | dprintk(1, "bc=%d (=0: active empty)\n", bc); |
| 108 | break; |
| 109 | } |
| 110 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 111 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 112 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 113 | |
| 114 | /* count comes from the hw and it is 16bit wide -- |
| 115 | * this trick handles wrap-arounds correctly for |
| 116 | * up to 32767 buffers in flight... */ |
Leonid V. Fedorenchik | e313e1f | 2011-09-16 14:15:13 +0800 | [diff] [blame] | 117 | if ((s16) (count - buf->count) < 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 118 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 119 | |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 120 | v4l2_get_timestamp(&buf->vb.ts); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 121 | buf->vb.state = VIDEOBUF_DONE; |
| 122 | list_del(&buf->vb.queue); |
| 123 | wake_up(&buf->vb.done); |
| 124 | } |
| 125 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 126 | if (list_empty(&q->active)) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 127 | del_timer(&q->timeout); |
| 128 | else |
| 129 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 130 | if (bc != 1) |
Leonid V. Fedorenchik | 692cfb9 | 2011-09-16 14:14:36 +0800 | [diff] [blame] | 131 | 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] | 132 | } |
| 133 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 134 | 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] | 135 | { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 136 | dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", |
| 137 | __func__, (unsigned int)norm, v4l2_norm_to_name(norm)); |
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 | dev->tvnorm = norm; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 140 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 141 | /* Tell the internal A/V decoder */ |
| 142 | cx25821_call_all(dev, core, s_std, norm); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 144 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 145 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 146 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 147 | /* |
| 148 | static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl) |
| 149 | { |
Leonid V. Fedorenchik | c2c311f | 2011-09-16 14:14:37 +0800 | [diff] [blame] | 150 | int i; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 151 | |
Leonid V. Fedorenchik | c2c311f | 2011-09-16 14:14:37 +0800 | [diff] [blame] | 152 | if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1) |
| 153 | return -EINVAL; |
| 154 | for (i = 0; i < CX25821_CTLS; i++) |
| 155 | if (cx25821_ctls[i].v.id == qctrl->id) |
| 156 | break; |
| 157 | if (i == CX25821_CTLS) { |
| 158 | *qctrl = no_ctl; |
| 159 | return 0; |
| 160 | } |
| 161 | *qctrl = cx25821_ctls[i].v; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 162 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 163 | } |
| 164 | */ |
| 165 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 166 | /* resource management */ |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 167 | int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, |
| 168 | unsigned int bit) |
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 | dprintk(1, "%s()\n", __func__); |
| 171 | if (fh->resources & bit) |
| 172 | /* have it already allocated */ |
| 173 | return 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 174 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 175 | /* is it free? */ |
| 176 | mutex_lock(&dev->lock); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 177 | if (dev->channels[fh->channel_id].resources & bit) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 178 | /* no, someone else uses it */ |
| 179 | mutex_unlock(&dev->lock); |
| 180 | return 0; |
| 181 | } |
| 182 | /* it's free, grab it */ |
| 183 | fh->resources |= bit; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 184 | dev->channels[fh->channel_id].resources |= bit; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 185 | dprintk(1, "res: get %d\n", bit); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 186 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 187 | return 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 188 | } |
| 189 | |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 190 | int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 191 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 192 | return fh->resources & bit; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 195 | int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 196 | { |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 197 | return fh->dev->channels[fh->channel_id].resources & bit; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 198 | } |
| 199 | |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 200 | void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, |
| 201 | unsigned int bits) |
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 | BUG_ON((fh->resources & bits) != bits); |
| 204 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 205 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 206 | mutex_lock(&dev->lock); |
| 207 | fh->resources &= ~bits; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 208 | dev->channels[fh->channel_id].resources &= ~bits; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 209 | dprintk(1, "res: put %d\n", bits); |
| 210 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 211 | } |
| 212 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 213 | 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] | 214 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 215 | struct v4l2_routing route; |
| 216 | memset(&route, 0, sizeof(route)); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 217 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 218 | 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] | 219 | __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0, |
| 220 | INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3); |
| 221 | dev->input = input; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 222 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 223 | route.input = INPUT(input)->vmux; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 224 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 225 | /* Tell the internal A/V decoder */ |
| 226 | 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] | 227 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 228 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | int cx25821_start_video_dma(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 232 | struct cx25821_dmaqueue *q, |
| 233 | struct cx25821_buffer *buf, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 234 | const struct sram_channel *channel) |
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 | int tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 238 | /* setup fifo + format */ |
| 239 | cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 240 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 241 | /* reset counter */ |
| 242 | cx_write(channel->gpcnt_ctl, 3); |
| 243 | q->count = 1; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 244 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 245 | /* enable irq */ |
| 246 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); |
| 247 | cx_set(channel->int_msk, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 248 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 249 | /* start dma */ |
| 250 | cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 252 | /* make sure upstream setting if any is reversed */ |
| 253 | tmp = cx_read(VID_CH_MODE_SEL); |
| 254 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 256 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 257 | } |
| 258 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 259 | static int cx25821_restart_video_queue(struct cx25821_dev *dev, |
| 260 | struct cx25821_dmaqueue *q, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 261 | const struct sram_channel *channel) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 262 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 263 | struct cx25821_buffer *buf, *prev; |
| 264 | struct list_head *item; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 265 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 266 | if (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 267 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 268 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 269 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 270 | cx25821_start_video_dma(dev, q, buf, channel); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 272 | list_for_each(item, &q->active) { |
| 273 | buf = list_entry(item, struct cx25821_buffer, vb.queue); |
| 274 | buf->count = q->count++; |
| 275 | } |
| 276 | |
| 277 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 278 | return 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 279 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 280 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 281 | prev = NULL; |
| 282 | for (;;) { |
| 283 | if (list_empty(&q->queued)) |
| 284 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 285 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 286 | buf = list_entry(q->queued.next, struct cx25821_buffer, |
| 287 | vb.queue); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 288 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 289 | if (NULL == prev) { |
| 290 | list_move_tail(&buf->vb.queue, &q->active); |
| 291 | cx25821_start_video_dma(dev, q, buf, channel); |
| 292 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 293 | buf->count = q->count++; |
| 294 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 295 | } else if (prev->vb.width == buf->vb.width && |
| 296 | prev->vb.height == buf->vb.height && |
| 297 | prev->fmt == buf->fmt) { |
| 298 | list_move_tail(&buf->vb.queue, &q->active); |
| 299 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 300 | buf->count = q->count++; |
| 301 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 302 | prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 303 | } else { |
| 304 | return 0; |
| 305 | } |
| 306 | prev = buf; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 307 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 308 | } |
| 309 | |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 310 | static void cx25821_vid_timeout(unsigned long data) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 311 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 312 | struct cx25821_data *timeout_data = (struct cx25821_data *)data; |
| 313 | struct cx25821_dev *dev = timeout_data->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 314 | const struct sram_channel *channel = timeout_data->channel; |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 315 | struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 316 | struct cx25821_buffer *buf; |
| 317 | unsigned long flags; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 318 | |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 319 | /* cx25821_sram_channel_dump(dev, channel); */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 320 | cx_clear(channel->dma_ctl, 0x11); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 321 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 322 | spin_lock_irqsave(&dev->slock, flags); |
| 323 | while (!list_empty(&q->active)) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 324 | buf = list_entry(q->active.next, struct cx25821_buffer, |
| 325 | vb.queue); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 326 | list_del(&buf->vb.queue); |
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 | buf->vb.state = VIDEOBUF_ERROR; |
| 329 | wake_up(&buf->vb.done); |
| 330 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 331 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 332 | cx25821_restart_video_queue(dev, q, channel); |
| 333 | spin_unlock_irqrestore(&dev->slock, flags); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) |
| 337 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 338 | u32 count = 0; |
| 339 | int handled = 0; |
| 340 | u32 mask; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 341 | const struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 342 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 343 | mask = cx_read(channel->int_msk); |
| 344 | if (0 == (status & mask)) |
| 345 | return handled; |
| 346 | |
| 347 | cx_write(channel->int_stat, status); |
| 348 | |
| 349 | /* risc op code error */ |
| 350 | if (status & (1 << 16)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 351 | pr_warn("%s, %s: video risc op code error\n", |
| 352 | dev->name, channel->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 353 | cx_clear(channel->dma_ctl, 0x11); |
| 354 | cx25821_sram_channel_dump(dev, channel); |
| 355 | } |
| 356 | |
| 357 | /* risc1 y */ |
| 358 | if (status & FLD_VID_DST_RISC1) { |
| 359 | spin_lock(&dev->slock); |
| 360 | count = cx_read(channel->gpcnt); |
Leonid V. Fedorenchik | 69dfe45 | 2011-09-16 14:14:38 +0800 | [diff] [blame] | 361 | cx25821_video_wakeup(dev, &dev->channels[channel->i].vidq, |
| 362 | count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 363 | spin_unlock(&dev->slock); |
| 364 | handled++; |
| 365 | } |
| 366 | |
| 367 | /* risc2 y */ |
| 368 | if (status & 0x10) { |
| 369 | dprintk(2, "stopper video\n"); |
| 370 | spin_lock(&dev->slock); |
Leonid V. Fedorenchik | 788d0f3 | 2011-09-16 14:14:39 +0800 | [diff] [blame] | 371 | cx25821_restart_video_queue(dev, |
| 372 | &dev->channels[channel->i].vidq, channel); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 373 | spin_unlock(&dev->slock); |
| 374 | handled++; |
| 375 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 376 | return handled; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 377 | } |
| 378 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 379 | 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] | 380 | unsigned int *size) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 381 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 382 | struct cx25821_fh *fh = q->priv_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 383 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 384 | *size = fh->fmt->depth * fh->width * fh->height >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 385 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 386 | if (0 == *count) |
| 387 | *count = 32; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 388 | |
Andreas Bombe | dab7e31 | 2010-03-21 16:02:45 -0300 | [diff] [blame] | 389 | if (*size * *count > vid_limit * 1024 * 1024) |
| 390 | *count = (vid_limit * 1024 * 1024) / *size; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 391 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 392 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 393 | } |
| 394 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 395 | 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] | 396 | enum v4l2_field field) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 397 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 398 | struct cx25821_fh *fh = q->priv_data; |
| 399 | struct cx25821_dev *dev = fh->dev; |
| 400 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 401 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 402 | int rc, init_buffer = 0; |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 403 | u32 line0_offset; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 404 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
| 405 | int bpl_local = LINE_SIZE_D1; |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 406 | int channel_opened = fh->channel_id; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 407 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 408 | BUG_ON(NULL == fh->fmt); |
| 409 | if (fh->width < 48 || fh->width > 720 || |
| 410 | fh->height < 32 || fh->height > 576) |
| 411 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 412 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 413 | buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 415 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 416 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 417 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 418 | if (buf->fmt != fh->fmt || |
| 419 | buf->vb.width != fh->width || |
| 420 | buf->vb.height != fh->height || buf->vb.field != field) { |
| 421 | buf->fmt = fh->fmt; |
| 422 | buf->vb.width = fh->width; |
| 423 | buf->vb.height = fh->height; |
| 424 | buf->vb.field = field; |
| 425 | init_buffer = 1; |
| 426 | } |
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 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 429 | init_buffer = 1; |
| 430 | rc = videobuf_iolock(q, &buf->vb, NULL); |
| 431 | if (0 != rc) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 432 | printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 433 | goto fail; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 434 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 435 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 436 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 437 | dprintk(1, "init_buffer=%d\n", init_buffer); |
| 438 | |
| 439 | if (init_buffer) { |
| 440 | |
| 441 | channel_opened = dev->channel_opened; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 442 | if (channel_opened < 0 || channel_opened > 7) |
| 443 | channel_opened = 7; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 444 | |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 445 | if (dev->channels[channel_opened].pixel_formats == |
| 446 | PIXEL_FRMT_411) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 447 | buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; |
| 448 | else |
| 449 | buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); |
| 450 | |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 451 | if (dev->channels[channel_opened].pixel_formats == |
| 452 | PIXEL_FRMT_411) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 453 | bpl_local = buf->bpl; |
| 454 | } else { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 455 | bpl_local = buf->bpl; /* Default */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 456 | |
| 457 | if (channel_opened >= 0 && channel_opened <= 7) { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 458 | if (dev->channels[channel_opened] |
| 459 | .use_cif_resolution) { |
Leonid V. Fedorenchik | cd52b2c | 2011-10-22 01:43:53 -0300 | [diff] [blame] | 460 | if (dev->tvnorm & V4L2_STD_PAL_BG || |
| 461 | dev->tvnorm & V4L2_STD_PAL_DK) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 462 | bpl_local = 352 << 1; |
| 463 | else |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 464 | bpl_local = dev->channels[ |
| 465 | channel_opened]. |
| 466 | cif_width << 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 467 | } |
| 468 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 469 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 470 | |
| 471 | switch (buf->vb.field) { |
| 472 | case V4L2_FIELD_TOP: |
| 473 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 474 | dma->sglist, 0, UNSET, |
| 475 | buf->bpl, 0, buf->vb.height); |
| 476 | break; |
| 477 | case V4L2_FIELD_BOTTOM: |
| 478 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 479 | dma->sglist, UNSET, 0, |
| 480 | buf->bpl, 0, buf->vb.height); |
| 481 | break; |
| 482 | case V4L2_FIELD_INTERLACED: |
| 483 | /* All other formats are top field first */ |
| 484 | line0_offset = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 485 | dprintk(1, "top field first\n"); |
| 486 | |
| 487 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 488 | dma->sglist, line0_offset, |
| 489 | bpl_local, bpl_local, bpl_local, |
| 490 | buf->vb.height >> 1); |
| 491 | break; |
| 492 | case V4L2_FIELD_SEQ_TB: |
| 493 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 494 | dma->sglist, |
| 495 | 0, buf->bpl * (buf->vb.height >> 1), |
| 496 | buf->bpl, 0, buf->vb.height >> 1); |
| 497 | break; |
| 498 | case V4L2_FIELD_SEQ_BT: |
| 499 | cx25821_risc_buffer(dev->pci, &buf->risc, |
| 500 | dma->sglist, |
| 501 | buf->bpl * (buf->vb.height >> 1), 0, |
| 502 | buf->bpl, 0, buf->vb.height >> 1); |
| 503 | break; |
| 504 | default: |
| 505 | BUG(); |
| 506 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 507 | } |
| 508 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 509 | dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", |
| 510 | buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, |
| 511 | fh->fmt->name, (unsigned long)buf->risc.dma); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 512 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 513 | buf->vb.state = VIDEOBUF_PREPARED; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 514 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 515 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 516 | |
Leonid V. Fedorenchik | 2748f26 | 2011-09-16 14:14:34 +0800 | [diff] [blame] | 517 | fail: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 518 | cx25821_free_buffer(q, buf); |
| 519 | return rc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 520 | } |
| 521 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 522 | static void cx25821_buffer_release(struct videobuf_queue *q, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 523 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 524 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 525 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 526 | container_of(vb, struct cx25821_buffer, vb); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 527 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 528 | cx25821_free_buffer(q, buf); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 529 | } |
| 530 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 531 | static struct videobuf_queue *get_queue(struct cx25821_fh *fh) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 532 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 533 | switch (fh->type) { |
| 534 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 535 | return &fh->vidq; |
| 536 | default: |
| 537 | BUG(); |
| 538 | return NULL; |
| 539 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 540 | } |
| 541 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 542 | static int cx25821_get_resource(struct cx25821_fh *fh, int resource) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 543 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 544 | switch (fh->type) { |
| 545 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 546 | return resource; |
| 547 | default: |
| 548 | BUG(); |
| 549 | return 0; |
| 550 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 551 | } |
| 552 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 553 | 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] | 554 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 555 | struct cx25821_fh *fh = file->private_data; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 556 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 557 | return videobuf_mmap_mapper(get_queue(fh), vma); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 558 | } |
| 559 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 560 | |
| 561 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 562 | { |
Leonid V. Fedorenchik | 8e4ac07 | 2011-09-16 14:14:43 +0800 | [diff] [blame] | 563 | struct cx25821_buffer *buf = |
Leonid V. Fedorenchik | f253981 | 2011-10-22 01:43:54 -0300 | [diff] [blame] | 564 | container_of(vb, struct cx25821_buffer, vb); |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 565 | struct cx25821_buffer *prev; |
| 566 | struct cx25821_fh *fh = vq->priv_data; |
| 567 | struct cx25821_dev *dev = fh->dev; |
| 568 | struct cx25821_dmaqueue *q = &dev->channels[fh->channel_id].vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 569 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 570 | /* add jump to stopper */ |
| 571 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 572 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 573 | buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 574 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 575 | dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 576 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 577 | if (!list_empty(&q->queued)) { |
| 578 | list_add_tail(&buf->vb.queue, &q->queued); |
| 579 | buf->vb.state = VIDEOBUF_QUEUED; |
| 580 | dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, |
| 581 | buf->vb.i); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 582 | |
Leonid V. Fedorenchik | e6cf66c | 2011-09-16 14:14:44 +0800 | [diff] [blame] | 583 | } else if (list_empty(&q->active)) { |
| 584 | list_add_tail(&buf->vb.queue, &q->active); |
| 585 | cx25821_start_video_dma(dev, q, buf, |
| 586 | dev->channels[fh->channel_id].sram_channels); |
| 587 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 588 | buf->count = q->count++; |
| 589 | mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); |
| 590 | dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n", |
| 591 | buf, buf->vb.i, buf->count, q->count); |
| 592 | } else { |
| 593 | prev = list_entry(q->active.prev, struct cx25821_buffer, |
| 594 | vb.queue); |
| 595 | if (prev->vb.width == buf->vb.width |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 596 | && prev->vb.height == buf->vb.height |
| 597 | && prev->fmt == buf->fmt) { |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 598 | list_add_tail(&buf->vb.queue, &q->active); |
| 599 | buf->vb.state = VIDEOBUF_ACTIVE; |
| 600 | buf->count = q->count++; |
| 601 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 602 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 603 | /* 64 bit bits 63-32 */ |
| 604 | prev->risc.jmp[2] = cpu_to_le32(0); |
| 605 | dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n", |
| 606 | buf, buf->vb.i, buf->count); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 607 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 608 | } else { |
| 609 | list_add_tail(&buf->vb.queue, &q->queued); |
| 610 | buf->vb.state = VIDEOBUF_QUEUED; |
| 611 | dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf, |
| 612 | buf->vb.i); |
| 613 | } |
| 614 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 615 | |
Leonid V. Fedorenchik | 8ebbda4 | 2011-09-16 14:14:45 +0800 | [diff] [blame] | 616 | if (list_empty(&q->active)) |
| 617 | dprintk(2, "active queue empty!\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static struct videobuf_queue_ops cx25821_video_qops = { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 621 | .buf_setup = cx25821_buffer_setup, |
| 622 | .buf_prepare = cx25821_buffer_prepare, |
| 623 | .buf_queue = buffer_queue, |
| 624 | .buf_release = cx25821_buffer_release, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 625 | }; |
| 626 | |
| 627 | static int video_open(struct file *file) |
| 628 | { |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 629 | struct video_device *vdev = video_devdata(file); |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 630 | struct cx25821_dev *dev = video_drvdata(file); |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 631 | struct cx25821_fh *fh; |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 632 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 633 | u32 pix_format; |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 634 | int ch_id; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 635 | |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 636 | dprintk(1, "open dev=%s type=%s\n", video_device_node_name(vdev), |
| 637 | v4l2_type_names[type]); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 638 | |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 639 | for (ch_id = 0; ch_id < MAX_VID_CHANNEL_NUM - 1; ch_id++) |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 640 | if (&dev->channels[ch_id].vdev == vdev) |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | /* Can't happen */ |
| 644 | if (ch_id >= MAX_VID_CHANNEL_NUM - 1) |
| 645 | return -ENODEV; |
| 646 | |
Leonid V. Fedorenchik | fb5f2c8 | 2011-09-16 14:14:46 +0800 | [diff] [blame] | 647 | /* allocate + initialize per filehandle data */ |
| 648 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
| 649 | if (NULL == fh) |
| 650 | return -ENOMEM; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 651 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 652 | file->private_data = fh; |
| 653 | fh->dev = dev; |
| 654 | fh->type = type; |
| 655 | fh->width = 720; |
| 656 | fh->channel_id = ch_id; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 657 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 658 | if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) |
| 659 | fh->height = 576; |
| 660 | else |
| 661 | fh->height = 480; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 662 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 663 | dev->channel_opened = fh->channel_id; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 664 | if (dev->channels[ch_id].pixel_formats == PIXEL_FRMT_411) |
| 665 | pix_format = V4L2_PIX_FMT_Y41P; |
| 666 | else |
| 667 | pix_format = V4L2_PIX_FMT_YUYV; |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 668 | fh->fmt = cx25821_format_by_fourcc(pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 669 | |
Leonid V. Fedorenchik | 0bf42c9 | 2011-09-16 14:14:48 +0800 | [diff] [blame] | 670 | v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 671 | |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 672 | videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops, &dev->pci->dev, |
| 673 | &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 674 | V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), |
| 675 | fh, NULL); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 676 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 677 | dprintk(1, "post videobuf_queue_init()\n"); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 678 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 679 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | 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] | 683 | loff_t *ppos) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 684 | { |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 685 | struct cx25821_fh *fh = file->private_data; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 686 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 687 | switch (fh->type) { |
| 688 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 689 | if (cx25821_res_locked(fh, RESOURCE_VIDEO0)) |
| 690 | return -EBUSY; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 691 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 692 | return videobuf_read_one(&fh->vidq, data, count, ppos, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 693 | file->f_flags & O_NONBLOCK); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 694 | |
Leonid V. Fedorenchik | 20e8a36 | 2011-09-16 14:14:49 +0800 | [diff] [blame] | 695 | default: |
| 696 | BUG(); |
| 697 | return 0; |
| 698 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static unsigned int video_poll(struct file *file, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 702 | struct poll_table_struct *wait) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 703 | { |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 704 | struct cx25821_fh *fh = file->private_data; |
| 705 | struct cx25821_buffer *buf; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 706 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 707 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
| 708 | /* streaming capture */ |
| 709 | if (list_empty(&fh->vidq.stream)) |
| 710 | return POLLERR; |
| 711 | buf = list_entry(fh->vidq.stream.next, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 712 | struct cx25821_buffer, vb.stream); |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 713 | } else { |
| 714 | /* read() capture */ |
| 715 | buf = (struct cx25821_buffer *)fh->vidq.read_buf; |
| 716 | if (NULL == buf) |
| 717 | return POLLERR; |
| 718 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 719 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 720 | poll_wait(file, &buf->vb.done, wait); |
| 721 | if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) { |
| 722 | if (buf->vb.state == VIDEOBUF_DONE) { |
| 723 | struct cx25821_dev *dev = fh->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 724 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 725 | if (dev && dev->channels[fh->channel_id] |
| 726 | .use_cif_resolution) { |
| 727 | u8 cam_id = *((char *)buf->vb.baddr + 3); |
| 728 | memcpy((char *)buf->vb.baddr, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 729 | (char *)buf->vb.baddr + (fh->width * 2), |
| 730 | (fh->width * 2)); |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 731 | *((char *)buf->vb.baddr + 3) = cam_id; |
| 732 | } |
| 733 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 734 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 735 | return POLLIN | POLLRDNORM; |
| 736 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 737 | |
Leonid V. Fedorenchik | 55c37c0 | 2011-09-16 14:14:50 +0800 | [diff] [blame] | 738 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static int video_release(struct file *file) |
| 742 | { |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 743 | struct cx25821_fh *fh = file->private_data; |
| 744 | struct cx25821_dev *dev = fh->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 745 | const struct sram_channel *sram_ch = |
| 746 | dev->channels[0].sram_channels; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 747 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 748 | /* stop the risc engine and fifo */ |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 749 | cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */ |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 750 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 751 | /* stop video capture */ |
| 752 | if (cx25821_res_check(fh, RESOURCE_VIDEO0)) { |
| 753 | videobuf_queue_cancel(&fh->vidq); |
| 754 | cx25821_res_free(dev, fh, RESOURCE_VIDEO0); |
| 755 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 756 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 757 | if (fh->vidq.read_buf) { |
| 758 | cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf); |
| 759 | kfree(fh->vidq.read_buf); |
| 760 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 761 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 762 | videobuf_mmap_free(&fh->vidq); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 763 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 764 | v4l2_prio_close(&dev->channels[fh->channel_id].prio, fh->prio); |
| 765 | file->private_data = NULL; |
| 766 | kfree(fh); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 767 | |
Leonid V. Fedorenchik | 21377cd | 2011-09-16 14:14:51 +0800 | [diff] [blame] | 768 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 769 | } |
| 770 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 771 | /* VIDEO IOCTLS */ |
| 772 | static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 773 | struct v4l2_format *f) |
| 774 | { |
| 775 | struct cx25821_fh *fh = priv; |
| 776 | |
| 777 | f->fmt.pix.width = fh->width; |
| 778 | f->fmt.pix.height = fh->height; |
| 779 | f->fmt.pix.field = fh->vidq.field; |
| 780 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 781 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 782 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 788 | struct v4l2_format *f) |
| 789 | { |
| 790 | const struct cx25821_fmt *fmt; |
| 791 | enum v4l2_field field; |
| 792 | unsigned int maxw, maxh; |
| 793 | |
| 794 | fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 795 | if (NULL == fmt) |
| 796 | return -EINVAL; |
| 797 | |
| 798 | field = f->fmt.pix.field; |
| 799 | maxw = 720; |
| 800 | maxh = 576; |
| 801 | |
| 802 | if (V4L2_FIELD_ANY == field) { |
| 803 | if (f->fmt.pix.height > maxh / 2) |
| 804 | field = V4L2_FIELD_INTERLACED; |
| 805 | else |
| 806 | field = V4L2_FIELD_TOP; |
| 807 | } |
| 808 | |
| 809 | switch (field) { |
| 810 | case V4L2_FIELD_TOP: |
| 811 | case V4L2_FIELD_BOTTOM: |
| 812 | maxh = maxh / 2; |
| 813 | break; |
| 814 | case V4L2_FIELD_INTERLACED: |
| 815 | break; |
| 816 | default: |
| 817 | return -EINVAL; |
| 818 | } |
| 819 | |
| 820 | f->fmt.pix.field = field; |
| 821 | if (f->fmt.pix.height < 32) |
| 822 | f->fmt.pix.height = 32; |
| 823 | if (f->fmt.pix.height > maxh) |
| 824 | f->fmt.pix.height = maxh; |
| 825 | if (f->fmt.pix.width < 48) |
| 826 | f->fmt.pix.width = 48; |
| 827 | if (f->fmt.pix.width > maxw) |
| 828 | f->fmt.pix.width = maxw; |
| 829 | f->fmt.pix.width &= ~0x03; |
| 830 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 831 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 832 | |
| 833 | return 0; |
| 834 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 835 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 836 | { |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 837 | struct cx25821_fh *fh = priv; |
| 838 | struct cx25821_dev *dev = fh->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 839 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 840 | if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) |
| 841 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 842 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 843 | if (unlikely(i != fh->type)) |
| 844 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 845 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 846 | if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, |
| 847 | RESOURCE_VIDEO0)))) |
| 848 | return -EBUSY; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 849 | |
Leonid V. Fedorenchik | 3f3d9e4 | 2011-09-16 14:14:52 +0800 | [diff] [blame] | 850 | return videobuf_streamon(get_queue(fh)); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 854 | { |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 855 | struct cx25821_fh *fh = priv; |
| 856 | struct cx25821_dev *dev = fh->dev; |
| 857 | int err, res; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 858 | |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 859 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 860 | return -EINVAL; |
| 861 | if (i != fh->type) |
| 862 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 863 | |
Leonid V. Fedorenchik | eda59eb | 2011-09-16 14:14:53 +0800 | [diff] [blame] | 864 | res = cx25821_get_resource(fh, RESOURCE_VIDEO0); |
| 865 | err = videobuf_streamoff(get_queue(fh)); |
| 866 | if (err < 0) |
| 867 | return err; |
| 868 | cx25821_res_free(dev, fh, res); |
| 869 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 870 | } |
| 871 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 872 | static int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm) |
| 873 | { |
| 874 | if (tvnorm == V4L2_STD_PAL_BG) { |
| 875 | if (width == 352 || width == 720) |
| 876 | return 1; |
| 877 | else |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | if (tvnorm == V4L2_STD_NTSC_M) { |
| 882 | if (width == 320 || width == 352 || width == 720) |
| 883 | return 1; |
| 884 | else |
| 885 | return 0; |
| 886 | } |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | static int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm) |
| 891 | { |
| 892 | if (tvnorm == V4L2_STD_PAL_BG) { |
| 893 | if (height == 576 || height == 288) |
| 894 | return 1; |
| 895 | else |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | if (tvnorm == V4L2_STD_NTSC_M) { |
| 900 | if (height == 480 || height == 240) |
| 901 | return 1; |
| 902 | else |
| 903 | return 0; |
| 904 | } |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 909 | 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] | 910 | struct v4l2_format *f) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 911 | { |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 912 | struct cx25821_fh *fh = priv; |
| 913 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 914 | struct v4l2_mbus_framefmt mbus_fmt; |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 915 | int err; |
| 916 | int pix_format = PIXEL_FRMT_422; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 917 | |
Leonid V. Fedorenchik | a39bea3 | 2011-09-16 14:14:54 +0800 | [diff] [blame] | 918 | if (fh) { |
| 919 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 920 | fh->prio); |
| 921 | if (0 != err) |
| 922 | return err; |
| 923 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 924 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 925 | dprintk(2, "%s()\n", __func__); |
| 926 | err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 927 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 928 | if (0 != err) |
| 929 | return err; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 930 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 931 | fh->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); |
| 932 | fh->vidq.field = f->fmt.pix.field; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 933 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 934 | /* check if width and height is valid based on set standard */ |
| 935 | if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) |
| 936 | fh->width = f->fmt.pix.width; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 937 | |
Leonid V. Fedorenchik | 255c040 | 2011-09-16 14:14:55 +0800 | [diff] [blame] | 938 | if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) |
| 939 | fh->height = f->fmt.pix.height; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 940 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 941 | if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) |
| 942 | pix_format = PIXEL_FRMT_411; |
| 943 | else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) |
| 944 | pix_format = PIXEL_FRMT_422; |
| 945 | else |
| 946 | return -EINVAL; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 947 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 948 | cx25821_set_pixel_format(dev, SRAM_CH00, pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 949 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 950 | /* check if cif resolution */ |
| 951 | if (fh->width == 320 || fh->width == 352) |
| 952 | dev->channels[fh->channel_id].use_cif_resolution = 1; |
| 953 | else |
| 954 | dev->channels[fh->channel_id].use_cif_resolution = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 955 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 956 | dev->channels[fh->channel_id].cif_width = fh->width; |
| 957 | medusa_set_resolution(dev, fh->width, SRAM_CH00); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 958 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 959 | dprintk(2, "%s(): width=%d height=%d field=%d\n", __func__, fh->width, |
| 960 | fh->height, fh->vidq.field); |
Hans Verkuil | c5e76a6 | 2010-08-06 16:18:23 -0300 | [diff] [blame] | 961 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 962 | cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 963 | |
Leonid V. Fedorenchik | 6678762 | 2011-09-16 14:14:56 +0800 | [diff] [blame] | 964 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 968 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 969 | int ret_val = 0; |
| 970 | struct cx25821_fh *fh = priv; |
| 971 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 972 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 973 | ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 974 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 975 | p->sequence = dev->channels[fh->channel_id].vidq.count; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 976 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 977 | return ret_val; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static int vidioc_log_status(struct file *file, void *priv) |
| 981 | { |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 982 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 983 | struct cx25821_fh *fh = priv; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 984 | const struct sram_channel *sram_ch = |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 985 | dev->channels[fh->channel_id].sram_channels; |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 986 | u32 tmp = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 987 | |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 988 | cx25821_call_all(dev, core, log_status); |
| 989 | tmp = cx_read(sram_ch->dma_ctl); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 990 | pr_info("Video input 0 is %s\n", |
| 991 | (tmp & 0x11) ? "streaming" : "stopped"); |
Leonid V. Fedorenchik | 02859b6 | 2011-09-16 14:14:57 +0800 | [diff] [blame] | 992 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 993 | } |
| 994 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 995 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 996 | static int cx25821_vidioc_querycap(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 997 | struct v4l2_capability *cap) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 998 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 999 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 1000 | struct cx25821_fh *fh = priv; |
| 1001 | const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE | |
| 1002 | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
| 1003 | const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1004 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1005 | strcpy(cap->driver, "cx25821"); |
| 1006 | strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card)); |
| 1007 | sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); |
Hans Verkuil | 3dd473c | 2013-04-13 06:06:18 -0300 | [diff] [blame] | 1008 | if (fh->channel_id >= VID_CHANNEL_NUM) |
| 1009 | cap->device_caps = cap_output; |
| 1010 | else |
| 1011 | cap->device_caps = cap_input; |
| 1012 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1013 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1014 | } |
| 1015 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1016 | 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] | 1017 | struct v4l2_fmtdesc *f) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1018 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1019 | if (unlikely(f->index >= ARRAY_SIZE(formats))) |
| 1020 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1021 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1022 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 1023 | f->pixelformat = formats[f->index].fourcc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1024 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1025 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1026 | } |
| 1027 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1028 | static int cx25821_vidioc_reqbufs(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1029 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1030 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1031 | struct cx25821_fh *fh = priv; |
| 1032 | return videobuf_reqbufs(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1033 | } |
| 1034 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1035 | static int cx25821_vidioc_querybuf(struct file *file, void *priv, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1036 | struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1037 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1038 | struct cx25821_fh *fh = priv; |
| 1039 | return videobuf_querybuf(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1040 | } |
| 1041 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1042 | 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] | 1043 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1044 | struct cx25821_fh *fh = priv; |
| 1045 | return videobuf_qbuf(get_queue(fh), p); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1046 | } |
| 1047 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1048 | static int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1049 | { |
| 1050 | struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1051 | struct cx25821_fh *fh = f; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1052 | |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1053 | *p = v4l2_prio_max(&dev->channels[fh->channel_id].prio); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1058 | static int cx25821_vidioc_s_priority(struct file *file, void *f, |
Leonid V. Fedorenchik | c1e6e24 | 2011-09-16 14:14:35 +0800 | [diff] [blame] | 1059 | enum v4l2_priority prio) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1060 | { |
| 1061 | struct cx25821_fh *fh = f; |
| 1062 | struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; |
| 1063 | |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1064 | return v4l2_prio_change(&dev->channels[fh->channel_id].prio, &fh->prio, |
| 1065 | prio); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1066 | } |
| 1067 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1068 | 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] | 1069 | { |
| 1070 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1071 | |
| 1072 | *tvnorms = dev->tvnorm; |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1076 | 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] | 1077 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1078 | struct cx25821_fh *fh = priv; |
| 1079 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1080 | int err; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1081 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1082 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1083 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1084 | if (fh) { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1085 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1086 | fh->prio); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1087 | if (0 != err) |
| 1088 | return err; |
| 1089 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1090 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1091 | if (dev->tvnorm == tvnorms) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1092 | return 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1093 | |
| 1094 | mutex_lock(&dev->lock); |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1095 | cx25821_set_tvnorm(dev, tvnorms); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1096 | mutex_unlock(&dev->lock); |
| 1097 | |
| 1098 | medusa_set_videostandard(dev); |
| 1099 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1100 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1101 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1102 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1103 | static int cx25821_vidioc_enum_input(struct file *file, void *priv, |
| 1104 | struct v4l2_input *i) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1105 | { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1106 | static const char * const iname[] = { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1107 | [CX25821_VMUX_COMPOSITE] = "Composite", |
| 1108 | [CX25821_VMUX_SVIDEO] = "S-Video", |
| 1109 | [CX25821_VMUX_DEBUG] = "for debug only", |
| 1110 | }; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1111 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1112 | unsigned int n; |
| 1113 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1114 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1115 | n = i->index; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1116 | if (n >= CX25821_NR_INPUT) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1117 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1118 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1119 | if (0 == INPUT(n)->type) |
| 1120 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1121 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1122 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1123 | strcpy(i->name, iname[INPUT(n)->type]); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1124 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1125 | i->std = CX25821_NORMS; |
| 1126 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1127 | } |
| 1128 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1129 | 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] | 1130 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1131 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 1132 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1133 | *i = dev->input; |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1134 | dprintk(1, "%s(): returns %d\n", __func__, *i); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1135 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1136 | } |
| 1137 | |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 1138 | 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] | 1139 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1140 | struct cx25821_fh *fh = priv; |
| 1141 | struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; |
| 1142 | int err; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1143 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1144 | dprintk(1, "%s(%d)\n", __func__, i); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1145 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1146 | if (fh) { |
Leonid V. Fedorenchik | 70e7f14 | 2011-09-16 14:14:59 +0800 | [diff] [blame] | 1147 | err = v4l2_prio_check(&dev->channels[fh->channel_id].prio, |
| 1148 | fh->prio); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1149 | if (0 != err) |
| 1150 | return err; |
| 1151 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1152 | |
Hans Verkuil | 6b1dce2 | 2013-04-13 07:39:19 -0300 | [diff] [blame] | 1153 | if (i >= CX25821_NR_INPUT || INPUT(i)->type == 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1154 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1155 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1156 | mutex_lock(&dev->lock); |
| 1157 | cx25821_video_mux(dev, i); |
| 1158 | mutex_unlock(&dev->lock); |
| 1159 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1160 | } |
| 1161 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1162 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 1163 | int cx25821_vidioc_g_register(struct file *file, void *fh, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1164 | struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1165 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1166 | struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1167 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1168 | if (!v4l2_chip_match_host(®->match)) |
| 1169 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1170 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1171 | cx25821_call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1172 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1173 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1174 | } |
| 1175 | |
Mauro Carvalho Chehab | f2466d6 | 2010-03-24 16:33:40 -0300 | [diff] [blame] | 1176 | int cx25821_vidioc_s_register(struct file *file, void *fh, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1177 | const struct v4l2_dbg_register *reg) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1178 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1179 | struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1180 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1181 | if (!v4l2_chip_match_host(®->match)) |
| 1182 | return -EINVAL; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1183 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1184 | cx25821_call_all(dev, core, s_register, reg); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1185 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1186 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | #endif |
| 1190 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1191 | static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1192 | { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1193 | struct cx25821_channel *chan = |
| 1194 | container_of(ctrl->handler, struct cx25821_channel, hdl); |
| 1195 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1196 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1197 | switch (ctrl->id) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1198 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1199 | medusa_set_brightness(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1200 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1201 | case V4L2_CID_HUE: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1202 | medusa_set_hue(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1203 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1204 | case V4L2_CID_CONTRAST: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1205 | medusa_set_contrast(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1206 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1207 | case V4L2_CID_SATURATION: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1208 | medusa_set_saturation(dev, ctrl->val, chan->id); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1209 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1210 | default: |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1211 | return -EINVAL; |
Joe Perches | 95cd17c | 2011-04-10 14:31:35 -0700 | [diff] [blame] | 1212 | } |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1213 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1214 | } |
| 1215 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1216 | static long video_ioctl_upstream9(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1217 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1218 | { |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1219 | struct cx25821_fh *fh = file->private_data; |
| 1220 | struct cx25821_dev *dev = fh->dev; |
| 1221 | int command = 0; |
| 1222 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1223 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1224 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1225 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1226 | if (!data_from_user) { |
| 1227 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1228 | return 0; |
| 1229 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1230 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1231 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1232 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1233 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 1234 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1235 | |
Leonid V. Fedorenchik | 75965b8 | 2011-09-16 14:15:02 +0800 | [diff] [blame] | 1236 | dev->input_filename = data_from_user->input_filename; |
| 1237 | dev->input_audiofilename = data_from_user->input_filename; |
| 1238 | dev->vid_stdname = data_from_user->vid_stdname; |
| 1239 | dev->pixel_format = data_from_user->pixel_format; |
| 1240 | dev->channel_select = data_from_user->channel_select; |
| 1241 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1242 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1243 | switch (command) { |
| 1244 | case UPSTREAM_START_VIDEO: |
| 1245 | cx25821_start_upstream_video_ch1(dev, data_from_user); |
| 1246 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1247 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1248 | case UPSTREAM_STOP_VIDEO: |
| 1249 | cx25821_stop_upstream_video_ch1(dev); |
| 1250 | break; |
| 1251 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1252 | |
Leonid V. Fedorenchik | 6f87cc6 | 2011-09-16 14:15:03 +0800 | [diff] [blame] | 1253 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | static long video_ioctl_upstream10(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1257 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1258 | { |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1259 | struct cx25821_fh *fh = file->private_data; |
| 1260 | struct cx25821_dev *dev = fh->dev; |
| 1261 | int command = 0; |
| 1262 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1263 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1264 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1265 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1266 | if (!data_from_user) { |
| 1267 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1268 | return 0; |
| 1269 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1270 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1271 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1272 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1273 | if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) |
| 1274 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1275 | |
Leonid V. Fedorenchik | 43be382 | 2011-09-16 14:15:04 +0800 | [diff] [blame] | 1276 | dev->input_filename_ch2 = data_from_user->input_filename; |
| 1277 | dev->input_audiofilename = data_from_user->input_filename; |
| 1278 | dev->vid_stdname_ch2 = data_from_user->vid_stdname; |
| 1279 | dev->pixel_format_ch2 = data_from_user->pixel_format; |
| 1280 | dev->channel_select_ch2 = data_from_user->channel_select; |
| 1281 | dev->command_ch2 = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1282 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1283 | switch (command) { |
| 1284 | case UPSTREAM_START_VIDEO: |
| 1285 | cx25821_start_upstream_video_ch2(dev, data_from_user); |
| 1286 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1287 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1288 | case UPSTREAM_STOP_VIDEO: |
| 1289 | cx25821_stop_upstream_video_ch2(dev); |
| 1290 | break; |
| 1291 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1292 | |
Leonid V. Fedorenchik | f9ef6be | 2011-09-16 14:15:05 +0800 | [diff] [blame] | 1293 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | static long video_ioctl_upstream11(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1297 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1298 | { |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1299 | struct cx25821_fh *fh = file->private_data; |
| 1300 | struct cx25821_dev *dev = fh->dev; |
| 1301 | int command = 0; |
| 1302 | struct upstream_user_struct *data_from_user; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1303 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1304 | data_from_user = (struct upstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1305 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1306 | if (!data_from_user) { |
| 1307 | pr_err("%s(): Upstream data is INVALID. Returning\n", __func__); |
| 1308 | return 0; |
| 1309 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1310 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1311 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1312 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1313 | if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) |
| 1314 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1315 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1316 | dev->input_filename = data_from_user->input_filename; |
| 1317 | dev->input_audiofilename = data_from_user->input_filename; |
| 1318 | dev->vid_stdname = data_from_user->vid_stdname; |
| 1319 | dev->pixel_format = data_from_user->pixel_format; |
| 1320 | dev->channel_select = data_from_user->channel_select; |
| 1321 | dev->command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1322 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1323 | switch (command) { |
| 1324 | case UPSTREAM_START_AUDIO: |
| 1325 | cx25821_start_upstream_audio(dev, data_from_user); |
| 1326 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1327 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1328 | case UPSTREAM_STOP_AUDIO: |
| 1329 | cx25821_stop_upstream_audio(dev); |
| 1330 | break; |
| 1331 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1332 | |
Leonid V. Fedorenchik | 5e64401 | 2011-09-16 14:15:06 +0800 | [diff] [blame] | 1333 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | static long video_ioctl_set(struct file *file, unsigned int cmd, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1337 | unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1338 | { |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1339 | struct cx25821_fh *fh = file->private_data; |
| 1340 | struct cx25821_dev *dev = fh->dev; |
| 1341 | struct downstream_user_struct *data_from_user; |
| 1342 | int command; |
| 1343 | int width = 720; |
Leonid V. Fedorenchik | 4a33b6f | 2011-10-22 01:43:52 -0300 | [diff] [blame] | 1344 | int selected_channel = 0; |
| 1345 | int pix_format = 0; |
| 1346 | int i = 0; |
| 1347 | int cif_enable = 0; |
| 1348 | int cif_width = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1349 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1350 | data_from_user = (struct downstream_user_struct *)arg; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1351 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 1352 | if (!data_from_user) { |
| 1353 | pr_err("%s(): User data is INVALID. Returning\n", __func__); |
| 1354 | return 0; |
| 1355 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1356 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1357 | command = data_from_user->command; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1358 | |
Leonid V. Fedorenchik | 16a81ef | 2011-09-16 14:15:07 +0800 | [diff] [blame] | 1359 | if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1360 | && command != ENABLE_CIF_RESOLUTION && command != REG_READ |
| 1361 | && command != REG_WRITE && command != MEDUSA_READ |
| 1362 | && command != MEDUSA_WRITE) { |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1363 | return 0; |
| 1364 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1365 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1366 | switch (command) { |
| 1367 | case SET_VIDEO_STD: |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1368 | if (!strcmp(data_from_user->vid_stdname, "PAL")) |
| 1369 | dev->tvnorm = V4L2_STD_PAL_BG; |
| 1370 | else |
| 1371 | dev->tvnorm = V4L2_STD_NTSC_M; |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1372 | medusa_set_videostandard(dev); |
| 1373 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1374 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1375 | case SET_PIXEL_FORMAT: |
| 1376 | selected_channel = data_from_user->decoder_select; |
| 1377 | pix_format = data_from_user->pixel_format; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1378 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1379 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1380 | selected_channel -= 4; |
| 1381 | selected_channel = selected_channel % 8; |
| 1382 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1383 | |
Leonid V. Fedorenchik | 12fe746 | 2011-09-16 14:15:08 +0800 | [diff] [blame] | 1384 | if (selected_channel >= 0) |
| 1385 | cx25821_set_pixel_format(dev, selected_channel, |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 1386 | pix_format); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1387 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1388 | break; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1389 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1390 | case ENABLE_CIF_RESOLUTION: |
| 1391 | selected_channel = data_from_user->decoder_select; |
| 1392 | cif_enable = data_from_user->cif_resolution_enable; |
| 1393 | cif_width = data_from_user->cif_width; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1394 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1395 | if (cif_enable) { |
| 1396 | if (dev->tvnorm & V4L2_STD_PAL_BG |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1397 | || dev->tvnorm & V4L2_STD_PAL_DK) { |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1398 | width = 352; |
Leonid V. Fedorenchik | 3038f63 | 2011-09-16 14:15:14 +0800 | [diff] [blame] | 1399 | } else { |
| 1400 | width = cif_width; |
| 1401 | if (cif_width != 320 && cif_width != 352) |
| 1402 | width = 320; |
| 1403 | } |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1404 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1405 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1406 | if (!(selected_channel <= 7 && selected_channel >= 0)) { |
| 1407 | selected_channel -= 4; |
| 1408 | selected_channel = selected_channel % 8; |
| 1409 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1410 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1411 | if (selected_channel <= 7 && selected_channel >= 0) { |
Leonid V. Fedorenchik | 0abfefb | 2011-10-22 01:43:55 -0300 | [diff] [blame] | 1412 | dev->channels[selected_channel].use_cif_resolution = |
| 1413 | cif_enable; |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1414 | dev->channels[selected_channel].cif_width = width; |
| 1415 | } else { |
| 1416 | for (i = 0; i < VID_CHANNEL_NUM; i++) { |
| 1417 | dev->channels[i].use_cif_resolution = |
| 1418 | cif_enable; |
| 1419 | dev->channels[i].cif_width = width; |
| 1420 | } |
| 1421 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1422 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1423 | medusa_set_resolution(dev, width, selected_channel); |
| 1424 | break; |
| 1425 | case REG_READ: |
| 1426 | data_from_user->reg_data = cx_read(data_from_user->reg_address); |
| 1427 | break; |
| 1428 | case REG_WRITE: |
| 1429 | cx_write(data_from_user->reg_address, data_from_user->reg_data); |
| 1430 | break; |
| 1431 | case MEDUSA_READ: |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 1432 | cx25821_i2c_read(&dev->i2c_bus[0], |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1433 | (u16) data_from_user->reg_address, |
| 1434 | &data_from_user->reg_data); |
| 1435 | break; |
| 1436 | case MEDUSA_WRITE: |
| 1437 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 1438 | (u16) data_from_user->reg_address, |
| 1439 | data_from_user->reg_data); |
| 1440 | break; |
| 1441 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1442 | |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1443 | return 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | static long cx25821_video_ioctl(struct file *file, |
Leonid V. Fedorenchik | 2a51749 | 2011-09-16 14:15:09 +0800 | [diff] [blame] | 1447 | unsigned int cmd, unsigned long arg) |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1448 | { |
Leonid V. Fedorenchik | 1316b63 | 2011-10-22 01:43:50 -0300 | [diff] [blame] | 1449 | int ret = 0; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1450 | |
Leonid V. Fedorenchik | 1316b63 | 2011-10-22 01:43:50 -0300 | [diff] [blame] | 1451 | struct cx25821_fh *fh = file->private_data; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1452 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1453 | /* check to see if it's the video upstream */ |
| 1454 | if (fh->channel_id == SRAM_CH09) { |
| 1455 | ret = video_ioctl_upstream9(file, cmd, arg); |
| 1456 | return ret; |
| 1457 | } else if (fh->channel_id == SRAM_CH10) { |
| 1458 | ret = video_ioctl_upstream10(file, cmd, arg); |
| 1459 | return ret; |
| 1460 | } else if (fh->channel_id == SRAM_CH11) { |
| 1461 | ret = video_ioctl_upstream11(file, cmd, arg); |
| 1462 | ret = video_ioctl_set(file, cmd, arg); |
| 1463 | return ret; |
| 1464 | } |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1465 | |
Leonid V. Fedorenchik | d2a167c | 2011-09-16 14:15:10 +0800 | [diff] [blame] | 1466 | return video_ioctl2(file, cmd, arg); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1467 | } |
| 1468 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1469 | static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { |
| 1470 | .s_ctrl = cx25821_s_ctrl, |
| 1471 | }; |
| 1472 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1473 | static const struct v4l2_file_operations video_fops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1474 | .owner = THIS_MODULE, |
| 1475 | .open = video_open, |
| 1476 | .release = video_release, |
| 1477 | .read = video_read, |
| 1478 | .poll = video_poll, |
| 1479 | .mmap = cx25821_video_mmap, |
| 1480 | .ioctl = cx25821_video_ioctl, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1484 | .vidioc_querycap = cx25821_vidioc_querycap, |
| 1485 | .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap, |
| 1486 | .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, |
| 1487 | .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, |
| 1488 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1489 | .vidioc_reqbufs = cx25821_vidioc_reqbufs, |
| 1490 | .vidioc_querybuf = cx25821_vidioc_querybuf, |
| 1491 | .vidioc_qbuf = cx25821_vidioc_qbuf, |
| 1492 | .vidioc_dqbuf = vidioc_dqbuf, |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1493 | .vidioc_g_std = cx25821_vidioc_g_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1494 | .vidioc_s_std = cx25821_vidioc_s_std, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1495 | .vidioc_enum_input = cx25821_vidioc_enum_input, |
| 1496 | .vidioc_g_input = cx25821_vidioc_g_input, |
| 1497 | .vidioc_s_input = cx25821_vidioc_s_input, |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1498 | .vidioc_streamon = vidioc_streamon, |
| 1499 | .vidioc_streamoff = vidioc_streamoff, |
| 1500 | .vidioc_log_status = vidioc_log_status, |
| 1501 | .vidioc_g_priority = cx25821_vidioc_g_priority, |
| 1502 | .vidioc_s_priority = cx25821_vidioc_s_priority, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1503 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Leonid V. Fedorenchik | fa7ce1f | 2011-09-16 14:15:11 +0800 | [diff] [blame] | 1504 | .vidioc_g_register = cx25821_vidioc_g_register, |
| 1505 | .vidioc_s_register = cx25821_vidioc_s_register, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1506 | #endif |
| 1507 | }; |
| 1508 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1509 | static const struct video_device cx25821_video_device = { |
| 1510 | .name = "cx25821-video", |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1511 | .fops = &video_fops, |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1512 | .release = video_device_release_empty, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1513 | .minor = -1, |
Leonid V. Fedorenchik | 527db49 | 2011-09-16 14:15:12 +0800 | [diff] [blame] | 1514 | .ioctl_ops = &video_ioctl_ops, |
| 1515 | .tvnorms = CX25821_NORMS, |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 1516 | }; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1517 | |
| 1518 | void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) |
| 1519 | { |
| 1520 | cx_clear(PCI_INT_MSK, 1); |
| 1521 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1522 | if (video_is_registered(&dev->channels[chan_num].vdev)) { |
| 1523 | video_unregister_device(&dev->channels[chan_num].vdev); |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1524 | v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1525 | |
| 1526 | btcx_riscmem_free(dev->pci, |
| 1527 | &dev->channels[chan_num].vidq.stopper); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1528 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | int cx25821_video_register(struct cx25821_dev *dev) |
| 1532 | { |
| 1533 | int err; |
| 1534 | int i; |
| 1535 | |
| 1536 | spin_lock_init(&dev->slock); |
| 1537 | |
| 1538 | for (i = 0; i < VID_CHANNEL_NUM; ++i) { |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1539 | struct video_device *vdev = &dev->channels[i].vdev; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1540 | struct v4l2_ctrl_handler *hdl = &dev->channels[i].hdl; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1541 | |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1542 | if (i == SRAM_CH08) /* audio channel */ |
| 1543 | continue; |
| 1544 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1545 | v4l2_ctrl_handler_init(hdl, 4); |
| 1546 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1547 | V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200); |
| 1548 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1549 | V4L2_CID_CONTRAST, 0, 10000, 1, 5000); |
| 1550 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1551 | V4L2_CID_SATURATION, 0, 10000, 1, 5000); |
| 1552 | v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops, |
| 1553 | V4L2_CID_HUE, 0, 10000, 1, 5000); |
| 1554 | if (hdl->error) { |
| 1555 | err = hdl->error; |
| 1556 | goto fail_unreg; |
| 1557 | } |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1558 | |
| 1559 | cx25821_risc_stopper(dev->pci, &dev->channels[i].vidq.stopper, |
| 1560 | dev->channels[i].sram_channels->dma_ctl, 0x11, 0); |
| 1561 | |
| 1562 | dev->channels[i].sram_channels = &cx25821_sram_channels[i]; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1563 | dev->channels[i].resources = 0; |
| 1564 | |
| 1565 | cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff); |
| 1566 | |
| 1567 | INIT_LIST_HEAD(&dev->channels[i].vidq.active); |
| 1568 | INIT_LIST_HEAD(&dev->channels[i].vidq.queued); |
| 1569 | |
| 1570 | dev->channels[i].timeout_data.dev = dev; |
| 1571 | dev->channels[i].timeout_data.channel = |
| 1572 | &cx25821_sram_channels[i]; |
| 1573 | dev->channels[i].vidq.timeout.function = cx25821_vid_timeout; |
| 1574 | dev->channels[i].vidq.timeout.data = |
| 1575 | (unsigned long)&dev->channels[i].timeout_data; |
| 1576 | init_timer(&dev->channels[i].vidq.timeout); |
| 1577 | |
| 1578 | /* register v4l devices */ |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1579 | *vdev = cx25821_video_device; |
| 1580 | vdev->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame^] | 1581 | vdev->ctrl_handler = hdl; |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1582 | snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); |
| 1583 | video_set_drvdata(vdev, dev); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1584 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1585 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1586 | video_nr[dev->nr]); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1587 | |
| 1588 | if (err < 0) |
| 1589 | goto fail_unreg; |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /* set PCI interrupt */ |
| 1593 | cx_set(PCI_INT_MSK, 0xff); |
| 1594 | |
| 1595 | /* initial device configuration */ |
| 1596 | mutex_lock(&dev->lock); |
Hans Verkuil | 18c73af | 2013-04-13 05:50:18 -0300 | [diff] [blame] | 1597 | dev->tvnorm = V4L2_STD_NTSC_M, |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1598 | cx25821_set_tvnorm(dev, dev->tvnorm); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1599 | mutex_unlock(&dev->lock); |
| 1600 | |
| 1601 | return 0; |
| 1602 | |
| 1603 | fail_unreg: |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 1604 | while (i >= 0) |
| 1605 | cx25821_video_unregister(dev, i--); |
Hans Verkuil | ffd3c23 | 2013-04-13 05:30:48 -0300 | [diff] [blame] | 1606 | return err; |
| 1607 | } |