Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 ioctl system call |
| 3 | * |
| 4 | * Derived from ivtv-ioctl.c |
| 5 | * |
| 6 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
Andy Walls | 6afdeaf | 2010-05-23 18:53:35 -0300 | [diff] [blame] | 7 | * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 22 | * 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include "cx18-driver.h" |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 26 | #include "cx18-io.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 27 | #include "cx18-version.h" |
| 28 | #include "cx18-mailbox.h" |
| 29 | #include "cx18-i2c.h" |
| 30 | #include "cx18-queue.h" |
| 31 | #include "cx18-fileops.h" |
| 32 | #include "cx18-vbi.h" |
| 33 | #include "cx18-audio.h" |
| 34 | #include "cx18-video.h" |
| 35 | #include "cx18-streams.h" |
| 36 | #include "cx18-ioctl.h" |
| 37 | #include "cx18-gpio.h" |
| 38 | #include "cx18-controls.h" |
| 39 | #include "cx18-cards.h" |
| 40 | #include "cx18-av-core.h" |
| 41 | #include <media/tveeprom.h> |
| 42 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 43 | |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 44 | u16 cx18_service2vbi(int type) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 45 | { |
| 46 | switch (type) { |
| 47 | case V4L2_SLICED_TELETEXT_B: |
| 48 | return CX18_SLICED_TYPE_TELETEXT_B; |
| 49 | case V4L2_SLICED_CAPTION_525: |
| 50 | return CX18_SLICED_TYPE_CAPTION_525; |
| 51 | case V4L2_SLICED_WSS_625: |
| 52 | return CX18_SLICED_TYPE_WSS_625; |
| 53 | case V4L2_SLICED_VPS: |
| 54 | return CX18_SLICED_TYPE_VPS; |
| 55 | default: |
| 56 | return 0; |
| 57 | } |
| 58 | } |
| 59 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 60 | /* Check if VBI services are allowed on the (field, line) for the video std */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 61 | static int valid_service_line(int field, int line, int is_pal) |
| 62 | { |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 63 | return (is_pal && line >= 6 && |
| 64 | ((field == 0 && line <= 23) || (field == 1 && line <= 22))) || |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 65 | (!is_pal && line >= 10 && line < 22); |
| 66 | } |
| 67 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 68 | /* |
| 69 | * For a (field, line, std) and inbound potential set of services for that line, |
| 70 | * return the first valid service of those passed in the incoming set for that |
| 71 | * line in priority order: |
| 72 | * CC, VPS, or WSS over TELETEXT for well known lines |
| 73 | * TELETEXT, before VPS, before CC, before WSS, for other lines |
| 74 | */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 75 | static u16 select_service_from_set(int field, int line, u16 set, int is_pal) |
| 76 | { |
| 77 | u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525); |
| 78 | int i; |
| 79 | |
| 80 | set = set & valid_set; |
| 81 | if (set == 0 || !valid_service_line(field, line, is_pal)) |
| 82 | return 0; |
| 83 | if (!is_pal) { |
| 84 | if (line == 21 && (set & V4L2_SLICED_CAPTION_525)) |
| 85 | return V4L2_SLICED_CAPTION_525; |
| 86 | } else { |
| 87 | if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS)) |
| 88 | return V4L2_SLICED_VPS; |
| 89 | if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625)) |
| 90 | return V4L2_SLICED_WSS_625; |
| 91 | if (line == 23) |
| 92 | return 0; |
| 93 | } |
| 94 | for (i = 0; i < 32; i++) { |
| 95 | if ((1 << i) & set) |
| 96 | return 1 << i; |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 101 | /* |
| 102 | * Expand the service_set of *fmt into valid service_lines for the std, |
| 103 | * and clear the passed in fmt->service_set |
| 104 | */ |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 105 | void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 106 | { |
| 107 | u16 set = fmt->service_set; |
| 108 | int f, l; |
| 109 | |
| 110 | fmt->service_set = 0; |
| 111 | for (f = 0; f < 2; f++) { |
| 112 | for (l = 0; l < 24; l++) |
| 113 | fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal); |
| 114 | } |
| 115 | } |
| 116 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 117 | /* |
| 118 | * Sanitize the service_lines in *fmt per the video std, and return 1 |
| 119 | * if any service_line is left as valid after santization |
| 120 | */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 121 | static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) |
| 122 | { |
| 123 | int f, l; |
| 124 | u16 set = 0; |
| 125 | |
| 126 | for (f = 0; f < 2; f++) { |
| 127 | for (l = 0; l < 24; l++) { |
| 128 | fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal); |
| 129 | set |= fmt->service_lines[f][l]; |
| 130 | } |
| 131 | } |
| 132 | return set != 0; |
| 133 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 134 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 135 | /* Compute the service_set from the assumed valid service_lines of *fmt */ |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 136 | u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 137 | { |
| 138 | int f, l; |
| 139 | u16 set = 0; |
| 140 | |
| 141 | for (f = 0; f < 2; f++) { |
| 142 | for (l = 0; l < 24; l++) |
| 143 | set |= fmt->service_lines[f][l]; |
| 144 | } |
| 145 | return set; |
| 146 | } |
| 147 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 148 | static int cx18_g_fmt_vid_cap(struct file *file, void *fh, |
| 149 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 150 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 151 | struct cx18_open_id *id = fh2id(fh); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 152 | struct cx18 *cx = id->cx; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 153 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 154 | |
Hans Verkuil | a75b9be | 2010-12-31 10:22:52 -0300 | [diff] [blame] | 155 | pixfmt->width = cx->cxhdl.width; |
| 156 | pixfmt->height = cx->cxhdl.height; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 157 | pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 158 | pixfmt->field = V4L2_FIELD_INTERLACED; |
| 159 | pixfmt->priv = 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 160 | if (id->type == CX18_ENC_STREAM_TYPE_YUV) { |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 161 | pixfmt->pixelformat = V4L2_PIX_FMT_HM12; |
Hans Verkuil | a4a7871 | 2009-02-06 15:31:59 -0300 | [diff] [blame] | 162 | /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */ |
| 163 | pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 164 | pixfmt->bytesperline = 720; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 165 | } else { |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 166 | pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; |
| 167 | pixfmt->sizeimage = 128 * 1024; |
| 168 | pixfmt->bytesperline = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 173 | static int cx18_g_fmt_vbi_cap(struct file *file, void *fh, |
| 174 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 175 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 176 | struct cx18 *cx = fh2id(fh)->cx; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 177 | struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 178 | |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 179 | vbifmt->sampling_rate = 27000000; |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 180 | vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 181 | vbifmt->samples_per_line = vbi_active_samples - 4; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 182 | vbifmt->sample_format = V4L2_PIX_FMT_GREY; |
| 183 | vbifmt->start[0] = cx->vbi.start[0]; |
| 184 | vbifmt->start[1] = cx->vbi.start[1]; |
| 185 | vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count; |
| 186 | vbifmt->flags = 0; |
| 187 | vbifmt->reserved[0] = 0; |
| 188 | vbifmt->reserved[1] = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 192 | static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 193 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 194 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 195 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 196 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 197 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 198 | /* sane, V4L2 spec compliant, defaults */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 199 | vbifmt->reserved[0] = 0; |
| 200 | vbifmt->reserved[1] = 0; |
| 201 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
| 202 | memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines)); |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 203 | vbifmt->service_set = 0; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 204 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 205 | /* |
| 206 | * Fetch the configured service_lines and total service_set from the |
| 207 | * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in |
| 208 | * fmt->fmt.sliced under valid calling conditions |
| 209 | */ |
Hans Verkuil | add632c | 2010-03-14 12:24:15 -0300 | [diff] [blame] | 210 | if (v4l2_subdev_call(cx->sd_av, vbi, g_sliced_fmt, &fmt->fmt.sliced)) |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 211 | return -EINVAL; |
| 212 | |
| 213 | /* Ensure V4L2 spec compliant output */ |
| 214 | vbifmt->reserved[0] = 0; |
| 215 | vbifmt->reserved[1] = 0; |
| 216 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 217 | vbifmt->service_set = cx18_get_service_set(vbifmt); |
| 218 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int cx18_try_fmt_vid_cap(struct file *file, void *fh, |
| 222 | struct v4l2_format *fmt) |
| 223 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 224 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 225 | struct cx18 *cx = id->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 226 | int w = fmt->fmt.pix.width; |
| 227 | int h = fmt->fmt.pix.height; |
Hans Verkuil | a4a7871 | 2009-02-06 15:31:59 -0300 | [diff] [blame] | 228 | int min_h = 2; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 229 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 230 | w = min(w, 720); |
Hans Verkuil | a4a7871 | 2009-02-06 15:31:59 -0300 | [diff] [blame] | 231 | w = max(w, 2); |
| 232 | if (id->type == CX18_ENC_STREAM_TYPE_YUV) { |
| 233 | /* YUV height must be a multiple of 32 */ |
| 234 | h &= ~0x1f; |
| 235 | min_h = 32; |
| 236 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 237 | h = min(h, cx->is_50hz ? 576 : 480); |
Hans Verkuil | a4a7871 | 2009-02-06 15:31:59 -0300 | [diff] [blame] | 238 | h = max(h, min_h); |
| 239 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 240 | cx18_g_fmt_vid_cap(file, fh, fmt); |
| 241 | fmt->fmt.pix.width = w; |
| 242 | fmt->fmt.pix.height = h; |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int cx18_try_fmt_vbi_cap(struct file *file, void *fh, |
| 247 | struct v4l2_format *fmt) |
| 248 | { |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 249 | return cx18_g_fmt_vbi_cap(file, fh, fmt); |
| 250 | } |
| 251 | |
| 252 | static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 253 | struct v4l2_format *fmt) |
| 254 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 255 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 256 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 257 | |
| 258 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
| 259 | vbifmt->reserved[0] = 0; |
| 260 | vbifmt->reserved[1] = 0; |
| 261 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 262 | /* If given a service set, expand it validly & clear passed in set */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 263 | if (vbifmt->service_set) |
| 264 | cx18_expand_service_set(vbifmt, cx->is_50hz); |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 265 | /* Sanitize the service_lines, and compute the new set if any valid */ |
| 266 | if (check_service_set(vbifmt, cx->is_50hz)) |
| 267 | vbifmt->service_set = cx18_get_service_set(vbifmt); |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 268 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static int cx18_s_fmt_vid_cap(struct file *file, void *fh, |
| 272 | struct v4l2_format *fmt) |
| 273 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 274 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 275 | struct cx18 *cx = id->cx; |
Hans Verkuil | 9e36eab | 2010-05-08 16:37:53 -0300 | [diff] [blame] | 276 | struct v4l2_mbus_framefmt mbus_fmt; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 277 | int ret; |
Hans Verkuil | effc346 | 2008-09-06 08:24:37 -0300 | [diff] [blame] | 278 | int w, h; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 279 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 280 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 281 | if (ret) |
| 282 | return ret; |
| 283 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 284 | ret = cx18_try_fmt_vid_cap(file, fh, fmt); |
| 285 | if (ret) |
| 286 | return ret; |
Hans Verkuil | effc346 | 2008-09-06 08:24:37 -0300 | [diff] [blame] | 287 | w = fmt->fmt.pix.width; |
| 288 | h = fmt->fmt.pix.height; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 289 | |
Hans Verkuil | a75b9be | 2010-12-31 10:22:52 -0300 | [diff] [blame] | 290 | if (cx->cxhdl.width == w && cx->cxhdl.height == h) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 291 | return 0; |
| 292 | |
| 293 | if (atomic_read(&cx->ana_capturing) > 0) |
| 294 | return -EBUSY; |
| 295 | |
Hans Verkuil | a75b9be | 2010-12-31 10:22:52 -0300 | [diff] [blame] | 296 | mbus_fmt.width = cx->cxhdl.width = w; |
| 297 | mbus_fmt.height = cx->cxhdl.height = h; |
Hans Verkuil | 9e36eab | 2010-05-08 16:37:53 -0300 | [diff] [blame] | 298 | mbus_fmt.code = V4L2_MBUS_FMT_FIXED; |
| 299 | v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &mbus_fmt); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 300 | return cx18_g_fmt_vid_cap(file, fh, fmt); |
| 301 | } |
| 302 | |
| 303 | static int cx18_s_fmt_vbi_cap(struct file *file, void *fh, |
| 304 | struct v4l2_format *fmt) |
| 305 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 306 | struct cx18_open_id *id = fh2id(fh); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 307 | struct cx18 *cx = id->cx; |
| 308 | int ret; |
| 309 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 310 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 311 | if (ret) |
| 312 | return ret; |
| 313 | |
Andy Walls | dcc0ef8 | 2009-02-06 18:33:43 -0300 | [diff] [blame] | 314 | /* |
| 315 | * Changing the Encoder's Raw VBI parameters won't have any effect |
| 316 | * if any analog capture is ongoing |
| 317 | */ |
| 318 | if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 319 | return -EBUSY; |
| 320 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 321 | /* |
| 322 | * Set the digitizer registers for raw active VBI. |
| 323 | * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid |
| 324 | * calling conditions |
| 325 | */ |
Hans Verkuil | add632c | 2010-03-14 12:24:15 -0300 | [diff] [blame] | 326 | ret = v4l2_subdev_call(cx->sd_av, vbi, s_raw_fmt, &fmt->fmt.vbi); |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 327 | if (ret) |
| 328 | return ret; |
| 329 | |
| 330 | /* Store our new v4l2 (non-)sliced VBI state */ |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 331 | cx->vbi.sliced_in->service_set = 0; |
Andy Walls | dd07343 | 2008-12-12 16:24:04 -0300 | [diff] [blame] | 332 | cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 333 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 334 | return cx18_g_fmt_vbi_cap(file, fh, fmt); |
| 335 | } |
| 336 | |
| 337 | static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 338 | struct v4l2_format *fmt) |
| 339 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 340 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 341 | struct cx18 *cx = id->cx; |
| 342 | int ret; |
| 343 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 344 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 345 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 346 | if (ret) |
| 347 | return ret; |
| 348 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 349 | cx18_try_fmt_sliced_vbi_cap(file, fh, fmt); |
| 350 | |
Andy Walls | dcc0ef8 | 2009-02-06 18:33:43 -0300 | [diff] [blame] | 351 | /* |
| 352 | * Changing the Encoder's Raw VBI parameters won't have any effect |
| 353 | * if any analog capture is ongoing |
| 354 | */ |
| 355 | if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0) |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 356 | return -EBUSY; |
Andy Walls | dcc0ef8 | 2009-02-06 18:33:43 -0300 | [diff] [blame] | 357 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 358 | /* |
| 359 | * Set the service_lines requested in the digitizer/slicer registers. |
| 360 | * Note, cx18_av_vbi() wipes some "impossible" service lines in the |
| 361 | * passed in fmt->fmt.sliced under valid calling conditions |
| 362 | */ |
Hans Verkuil | add632c | 2010-03-14 12:24:15 -0300 | [diff] [blame] | 363 | ret = v4l2_subdev_call(cx->sd_av, vbi, s_sliced_fmt, &fmt->fmt.sliced); |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 364 | if (ret) |
| 365 | return ret; |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 366 | /* Store our current v4l2 sliced VBI settings */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 367 | cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 368 | memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in)); |
| 369 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static int cx18_g_chip_ident(struct file *file, void *fh, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 373 | struct v4l2_dbg_chip_ident *chip) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 374 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 375 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 376 | int err = 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 377 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 378 | chip->ident = V4L2_IDENT_NONE; |
| 379 | chip->revision = 0; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 380 | switch (chip->match.type) { |
| 381 | case V4L2_CHIP_MATCH_HOST: |
| 382 | switch (chip->match.addr) { |
| 383 | case 0: |
| 384 | chip->ident = V4L2_IDENT_CX23418; |
| 385 | chip->revision = cx18_read_reg(cx, 0xC72028); |
| 386 | break; |
| 387 | case 1: |
| 388 | /* |
| 389 | * The A/V decoder is always present, but in the rare |
| 390 | * case that the card doesn't have analog, we don't |
| 391 | * use it. We find it w/o using the cx->sd_av pointer |
| 392 | */ |
| 393 | cx18_call_hw(cx, CX18_HW_418_AV, |
| 394 | core, g_chip_ident, chip); |
| 395 | break; |
| 396 | default: |
| 397 | /* |
| 398 | * Could return ident = V4L2_IDENT_UNKNOWN if we had |
| 399 | * other host chips at higher addresses, but we don't |
| 400 | */ |
| 401 | err = -EINVAL; /* per V4L2 spec */ |
| 402 | break; |
| 403 | } |
| 404 | break; |
| 405 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
| 406 | /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */ |
| 407 | cx18_call_all(cx, core, g_chip_ident, chip); |
| 408 | break; |
| 409 | case V4L2_CHIP_MATCH_I2C_ADDR: |
| 410 | /* |
| 411 | * We could return V4L2_IDENT_UNKNOWN, but we don't do the work |
| 412 | * to look if a chip is at the address with no driver. That's a |
| 413 | * dangerous thing to do with EEPROMs anyway. |
| 414 | */ |
| 415 | cx18_call_all(cx, core, g_chip_ident, chip); |
| 416 | break; |
| 417 | default: |
| 418 | err = -EINVAL; |
| 419 | break; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 420 | } |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 421 | return err; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 422 | } |
| 423 | |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 424 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 425 | static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg) |
| 426 | { |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 427 | struct v4l2_dbg_register *regs = arg; |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 428 | |
| 429 | if (!capable(CAP_SYS_ADMIN)) |
| 430 | return -EPERM; |
| 431 | if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE) |
| 432 | return -EINVAL; |
| 433 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 434 | regs->size = 4; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 435 | if (cmd == VIDIOC_DBG_S_REGISTER) |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 436 | cx18_write_enc(cx, regs->val, regs->reg); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 437 | else |
| 438 | regs->val = cx18_read_enc(cx, regs->reg); |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 442 | static int cx18_g_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 443 | struct v4l2_dbg_register *reg) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 444 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 445 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 446 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 447 | if (v4l2_chip_match_host(®->match)) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 448 | return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 449 | /* FIXME - errors shouldn't be ignored */ |
| 450 | cx18_call_all(cx, core, g_register, reg); |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 451 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static int cx18_s_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 455 | struct v4l2_dbg_register *reg) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 456 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 457 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 458 | |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 459 | if (v4l2_chip_match_host(®->match)) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 460 | return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 461 | /* FIXME - errors shouldn't be ignored */ |
| 462 | cx18_call_all(cx, core, s_register, reg); |
Hans Verkuil | aecde8b | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 463 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 464 | } |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 465 | #endif |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 466 | |
| 467 | static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p) |
| 468 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 469 | struct cx18 *cx = file2id(file)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 470 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 471 | *p = v4l2_prio_max(&cx->prio); |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio) |
| 476 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 477 | struct cx18_open_id *id = file2id(file); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 478 | struct cx18 *cx = id->cx; |
| 479 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 480 | return v4l2_prio_change(&cx->prio, &id->prio, prio); |
| 481 | } |
| 482 | |
| 483 | static int cx18_querycap(struct file *file, void *fh, |
| 484 | struct v4l2_capability *vcap) |
| 485 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 486 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 487 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 488 | strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver)); |
| 489 | strlcpy(vcap->card, cx->card_name, sizeof(vcap->card)); |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 490 | snprintf(vcap->bus_info, sizeof(vcap->bus_info), |
| 491 | "PCI:%s", pci_name(cx->pci_dev)); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 492 | vcap->version = CX18_DRIVER_VERSION; /* version */ |
| 493 | vcap->capabilities = cx->v4l2_cap; /* capabilities */ |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin) |
| 498 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 499 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 500 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 501 | return cx18_get_audio_input(cx, vin->index, vin); |
| 502 | } |
| 503 | |
| 504 | static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin) |
| 505 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 506 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 507 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 508 | vin->index = cx->audio_input; |
| 509 | return cx18_get_audio_input(cx, vin->index, vin); |
| 510 | } |
| 511 | |
| 512 | static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout) |
| 513 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 514 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 515 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 516 | if (vout->index >= cx->nof_audio_inputs) |
| 517 | return -EINVAL; |
| 518 | cx->audio_input = vout->index; |
| 519 | cx18_audio_set_io(cx); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin) |
| 524 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 525 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 526 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 527 | /* set it to defaults from our table */ |
| 528 | return cx18_get_input(cx, vin->index, vin); |
| 529 | } |
| 530 | |
| 531 | static int cx18_cropcap(struct file *file, void *fh, |
| 532 | struct v4l2_cropcap *cropcap) |
| 533 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 534 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 535 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 536 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 537 | return -EINVAL; |
| 538 | cropcap->bounds.top = cropcap->bounds.left = 0; |
| 539 | cropcap->bounds.width = 720; |
| 540 | cropcap->bounds.height = cx->is_50hz ? 576 : 480; |
| 541 | cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10; |
| 542 | cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11; |
| 543 | cropcap->defrect = cropcap->bounds; |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 548 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 549 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 550 | struct cx18 *cx = id->cx; |
| 551 | int ret; |
| 552 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 553 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 554 | if (ret) |
| 555 | return ret; |
| 556 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 557 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 558 | return -EINVAL; |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 559 | CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n"); |
| 560 | return -EINVAL; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 564 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 565 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 566 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 567 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 568 | return -EINVAL; |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 569 | CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n"); |
| 570 | return -EINVAL; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static int cx18_enum_fmt_vid_cap(struct file *file, void *fh, |
| 574 | struct v4l2_fmtdesc *fmt) |
| 575 | { |
| 576 | static struct v4l2_fmtdesc formats[] = { |
| 577 | { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0, |
| 578 | "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 } |
| 579 | }, |
| 580 | { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED, |
| 581 | "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 } |
| 582 | } |
| 583 | }; |
| 584 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 585 | if (fmt->index > 1) |
| 586 | return -EINVAL; |
| 587 | *fmt = formats[fmt->index]; |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | static int cx18_g_input(struct file *file, void *fh, unsigned int *i) |
| 592 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 593 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 594 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 595 | *i = cx->active_input; |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | int cx18_s_input(struct file *file, void *fh, unsigned int inp) |
| 600 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 601 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 602 | struct cx18 *cx = id->cx; |
| 603 | int ret; |
| 604 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 605 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 606 | if (ret) |
| 607 | return ret; |
| 608 | |
Roel Kluin | de81c3c | 2009-07-02 16:09:25 -0300 | [diff] [blame] | 609 | if (inp >= cx->nof_inputs) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 610 | return -EINVAL; |
| 611 | |
| 612 | if (inp == cx->active_input) { |
| 613 | CX18_DEBUG_INFO("Input unchanged\n"); |
| 614 | return 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 615 | } |
| 616 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 617 | CX18_DEBUG_INFO("Changing input from %d to %d\n", |
| 618 | cx->active_input, inp); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 619 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 620 | cx->active_input = inp; |
| 621 | /* Set the audio input to whatever is appropriate for the input type. */ |
| 622 | cx->audio_input = cx->card->video_inputs[inp].audio_index; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 623 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 624 | /* prevent others from messing with the streams until |
| 625 | we're finished changing inputs. */ |
| 626 | cx18_mute(cx); |
| 627 | cx18_video_set_io(cx); |
| 628 | cx18_audio_set_io(cx); |
| 629 | cx18_unmute(cx); |
| 630 | return 0; |
| 631 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 632 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 633 | static int cx18_g_frequency(struct file *file, void *fh, |
| 634 | struct v4l2_frequency *vf) |
| 635 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 636 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 637 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 638 | if (vf->tuner != 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 639 | return -EINVAL; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 640 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 641 | cx18_call_all(cx, tuner, g_frequency, vf); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) |
| 646 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 647 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 648 | struct cx18 *cx = id->cx; |
| 649 | int ret; |
| 650 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 651 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 652 | if (ret) |
| 653 | return ret; |
| 654 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 655 | if (vf->tuner != 0) |
| 656 | return -EINVAL; |
| 657 | |
| 658 | cx18_mute(cx); |
| 659 | CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 660 | cx18_call_all(cx, tuner, s_frequency, vf); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 661 | cx18_unmute(cx); |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std) |
| 666 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 667 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 668 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 669 | *std = cx->std; |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std) |
| 674 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 675 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 676 | struct cx18 *cx = id->cx; |
| 677 | int ret; |
| 678 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 679 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 680 | if (ret) |
| 681 | return ret; |
| 682 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 683 | if ((*std & V4L2_STD_ALL) == 0) |
| 684 | return -EINVAL; |
| 685 | |
| 686 | if (*std == cx->std) |
| 687 | return 0; |
| 688 | |
| 689 | if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) || |
| 690 | atomic_read(&cx->ana_capturing) > 0) { |
| 691 | /* Switching standard would turn off the radio or mess |
| 692 | with already running streams, prevent that by |
| 693 | returning EBUSY. */ |
| 694 | return -EBUSY; |
| 695 | } |
| 696 | |
| 697 | cx->std = *std; |
| 698 | cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; |
Hans Verkuil | a75b9be | 2010-12-31 10:22:52 -0300 | [diff] [blame] | 699 | cx->is_50hz = !cx->is_60hz; |
| 700 | cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz); |
| 701 | cx->cxhdl.width = 720; |
| 702 | cx->cxhdl.height = cx->is_50hz ? 576 : 480; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 703 | cx->vbi.count = cx->is_50hz ? 18 : 12; |
| 704 | cx->vbi.start[0] = cx->is_50hz ? 6 : 10; |
| 705 | cx->vbi.start[1] = cx->is_50hz ? 318 : 273; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 706 | CX18_DEBUG_INFO("Switching standard to %llx.\n", |
| 707 | (unsigned long long) cx->std); |
| 708 | |
| 709 | /* Tuner */ |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 710 | cx18_call_all(cx, core, s_std, cx->std); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) |
| 715 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 716 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 717 | struct cx18 *cx = id->cx; |
| 718 | int ret; |
| 719 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 720 | ret = v4l2_prio_check(&cx->prio, id->prio); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 721 | if (ret) |
| 722 | return ret; |
| 723 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 724 | if (vt->index != 0) |
| 725 | return -EINVAL; |
| 726 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 727 | cx18_call_all(cx, tuner, s_tuner, vt); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) |
| 732 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 733 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 734 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 735 | if (vt->index != 0) |
| 736 | return -EINVAL; |
| 737 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 738 | cx18_call_all(cx, tuner, g_tuner, vt); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 739 | |
| 740 | if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) { |
| 741 | strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name)); |
| 742 | vt->type = V4L2_TUNER_RADIO; |
| 743 | } else { |
| 744 | strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name)); |
| 745 | vt->type = V4L2_TUNER_ANALOG_TV; |
| 746 | } |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int cx18_g_sliced_vbi_cap(struct file *file, void *fh, |
| 752 | struct v4l2_sliced_vbi_cap *cap) |
| 753 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 754 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 755 | int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525; |
| 756 | int f, l; |
| 757 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 758 | if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) |
| 759 | return -EINVAL; |
| 760 | |
| 761 | cap->service_set = 0; |
| 762 | for (f = 0; f < 2; f++) { |
| 763 | for (l = 0; l < 24; l++) { |
| 764 | if (valid_service_line(f, l, cx->is_50hz)) { |
| 765 | /* |
| 766 | * We can find all v4l2 supported vbi services |
| 767 | * for the standard, on a valid line for the std |
| 768 | */ |
| 769 | cap->service_lines[f][l] = set; |
| 770 | cap->service_set |= set; |
| 771 | } else |
| 772 | cap->service_lines[f][l] = 0; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 773 | } |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 774 | } |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame] | 775 | for (f = 0; f < 3; f++) |
| 776 | cap->reserved[f] = 0; |
| 777 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 778 | } |
| 779 | |
Andy Walls | 82acdc8 | 2009-12-31 22:09:51 -0300 | [diff] [blame] | 780 | static int _cx18_process_idx_data(struct cx18_buffer *buf, |
| 781 | struct v4l2_enc_idx *idx) |
| 782 | { |
| 783 | int consumed, remaining; |
| 784 | struct v4l2_enc_idx_entry *e_idx; |
| 785 | struct cx18_enc_idx_entry *e_buf; |
| 786 | |
| 787 | /* Frame type lookup: 1=I, 2=P, 4=B */ |
| 788 | const int mapping[8] = { |
| 789 | -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P, |
| 790 | -1, V4L2_ENC_IDX_FRAME_B, -1, -1, -1 |
| 791 | }; |
| 792 | |
| 793 | /* |
| 794 | * Assumption here is that a buf holds an integral number of |
| 795 | * struct cx18_enc_idx_entry objects and is properly aligned. |
| 796 | * This is enforced by the module options on IDX buffer sizes. |
| 797 | */ |
| 798 | remaining = buf->bytesused - buf->readpos; |
| 799 | consumed = 0; |
| 800 | e_idx = &idx->entry[idx->entries]; |
| 801 | e_buf = (struct cx18_enc_idx_entry *) &buf->buf[buf->readpos]; |
| 802 | |
| 803 | while (remaining >= sizeof(struct cx18_enc_idx_entry) && |
| 804 | idx->entries < V4L2_ENC_IDX_ENTRIES) { |
| 805 | |
| 806 | e_idx->offset = (((u64) le32_to_cpu(e_buf->offset_high)) << 32) |
| 807 | | le32_to_cpu(e_buf->offset_low); |
| 808 | |
| 809 | e_idx->pts = (((u64) (le32_to_cpu(e_buf->pts_high) & 1)) << 32) |
| 810 | | le32_to_cpu(e_buf->pts_low); |
| 811 | |
| 812 | e_idx->length = le32_to_cpu(e_buf->length); |
| 813 | |
| 814 | e_idx->flags = mapping[le32_to_cpu(e_buf->flags) & 0x7]; |
| 815 | |
| 816 | e_idx->reserved[0] = 0; |
| 817 | e_idx->reserved[1] = 0; |
| 818 | |
| 819 | idx->entries++; |
| 820 | e_idx = &idx->entry[idx->entries]; |
| 821 | e_buf++; |
| 822 | |
| 823 | remaining -= sizeof(struct cx18_enc_idx_entry); |
| 824 | consumed += sizeof(struct cx18_enc_idx_entry); |
| 825 | } |
| 826 | |
| 827 | /* Swallow any partial entries at the end, if there are any */ |
| 828 | if (remaining > 0 && remaining < sizeof(struct cx18_enc_idx_entry)) |
| 829 | consumed += remaining; |
| 830 | |
| 831 | buf->readpos += consumed; |
| 832 | return consumed; |
| 833 | } |
| 834 | |
| 835 | static int cx18_process_idx_data(struct cx18_stream *s, struct cx18_mdl *mdl, |
| 836 | struct v4l2_enc_idx *idx) |
| 837 | { |
| 838 | if (s->type != CX18_ENC_STREAM_TYPE_IDX) |
| 839 | return -EINVAL; |
| 840 | |
| 841 | if (mdl->curr_buf == NULL) |
| 842 | mdl->curr_buf = list_first_entry(&mdl->buf_list, |
| 843 | struct cx18_buffer, list); |
| 844 | |
| 845 | if (list_entry_is_past_end(mdl->curr_buf, &mdl->buf_list, list)) { |
| 846 | /* |
| 847 | * For some reason we've exhausted the buffers, but the MDL |
| 848 | * object still said some data was unread. |
| 849 | * Fix that and bail out. |
| 850 | */ |
| 851 | mdl->readpos = mdl->bytesused; |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | list_for_each_entry_from(mdl->curr_buf, &mdl->buf_list, list) { |
| 856 | |
| 857 | /* Skip any empty buffers in the MDL */ |
| 858 | if (mdl->curr_buf->readpos >= mdl->curr_buf->bytesused) |
| 859 | continue; |
| 860 | |
| 861 | mdl->readpos += _cx18_process_idx_data(mdl->curr_buf, idx); |
| 862 | |
| 863 | /* exit when MDL drained or request satisfied */ |
| 864 | if (idx->entries >= V4L2_ENC_IDX_ENTRIES || |
| 865 | mdl->curr_buf->readpos < mdl->curr_buf->bytesused || |
| 866 | mdl->readpos >= mdl->bytesused) |
| 867 | break; |
| 868 | } |
| 869 | return 0; |
| 870 | } |
| 871 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 872 | static int cx18_g_enc_index(struct file *file, void *fh, |
| 873 | struct v4l2_enc_idx *idx) |
| 874 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 875 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 82acdc8 | 2009-12-31 22:09:51 -0300 | [diff] [blame] | 876 | struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX]; |
| 877 | s32 tmp; |
| 878 | struct cx18_mdl *mdl; |
| 879 | |
| 880 | if (!cx18_stream_enabled(s)) /* Module options inhibited IDX stream */ |
| 881 | return -EINVAL; |
| 882 | |
| 883 | /* Compute the best case number of entries we can buffer */ |
| 884 | tmp = s->buffers - |
| 885 | s->bufs_per_mdl * CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN; |
| 886 | if (tmp <= 0) |
| 887 | tmp = 1; |
| 888 | tmp = tmp * s->buf_size / sizeof(struct cx18_enc_idx_entry); |
| 889 | |
| 890 | /* Fill out the header of the return structure */ |
| 891 | idx->entries = 0; |
| 892 | idx->entries_cap = tmp; |
| 893 | memset(idx->reserved, 0, sizeof(idx->reserved)); |
| 894 | |
| 895 | /* Pull IDX MDLs and buffers from q_full and populate the entries */ |
| 896 | do { |
| 897 | mdl = cx18_dequeue(s, &s->q_full); |
| 898 | if (mdl == NULL) /* No more IDX data right now */ |
| 899 | break; |
| 900 | |
| 901 | /* Extract the Index entry data from the MDL and buffers */ |
| 902 | cx18_process_idx_data(s, mdl, idx); |
| 903 | if (mdl->readpos < mdl->bytesused) { |
| 904 | /* We finished with data remaining, push the MDL back */ |
| 905 | cx18_push(s, mdl, &s->q_full); |
| 906 | break; |
| 907 | } |
| 908 | |
| 909 | /* We drained this MDL, schedule it to go to the firmware */ |
| 910 | cx18_enqueue(s, mdl, &s->q_free); |
| 911 | |
| 912 | } while (idx->entries < V4L2_ENC_IDX_ENTRIES); |
| 913 | |
| 914 | /* Tell the work handler to send free IDX MDLs to the firmware */ |
| 915 | cx18_stream_load_fw_queue(s); |
| 916 | return 0; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static int cx18_encoder_cmd(struct file *file, void *fh, |
| 920 | struct v4l2_encoder_cmd *enc) |
| 921 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 922 | struct cx18_open_id *id = fh2id(fh); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 923 | struct cx18 *cx = id->cx; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 924 | u32 h; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 925 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 926 | switch (enc->cmd) { |
| 927 | case V4L2_ENC_CMD_START: |
| 928 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); |
| 929 | enc->flags = 0; |
| 930 | return cx18_start_capture(id); |
| 931 | |
| 932 | case V4L2_ENC_CMD_STOP: |
| 933 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); |
| 934 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; |
| 935 | cx18_stop_capture(id, |
| 936 | enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END); |
| 937 | break; |
| 938 | |
| 939 | case V4L2_ENC_CMD_PAUSE: |
| 940 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); |
| 941 | enc->flags = 0; |
| 942 | if (!atomic_read(&cx->ana_capturing)) |
| 943 | return -EPERM; |
| 944 | if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) |
| 945 | return 0; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 946 | h = cx18_find_handle(cx); |
| 947 | if (h == CX18_INVALID_TASK_HANDLE) { |
| 948 | CX18_ERR("Can't find valid task handle for " |
| 949 | "V4L2_ENC_CMD_PAUSE\n"); |
| 950 | return -EBADFD; |
| 951 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 952 | cx18_mute(cx); |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 953 | cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 954 | break; |
| 955 | |
| 956 | case V4L2_ENC_CMD_RESUME: |
| 957 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); |
| 958 | enc->flags = 0; |
| 959 | if (!atomic_read(&cx->ana_capturing)) |
| 960 | return -EPERM; |
| 961 | if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) |
| 962 | return 0; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 963 | h = cx18_find_handle(cx); |
| 964 | if (h == CX18_INVALID_TASK_HANDLE) { |
| 965 | CX18_ERR("Can't find valid task handle for " |
| 966 | "V4L2_ENC_CMD_RESUME\n"); |
| 967 | return -EBADFD; |
| 968 | } |
| 969 | cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 970 | cx18_unmute(cx); |
| 971 | break; |
| 972 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 973 | default: |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 974 | CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); |
| 975 | return -EINVAL; |
| 976 | } |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static int cx18_try_encoder_cmd(struct file *file, void *fh, |
| 981 | struct v4l2_encoder_cmd *enc) |
| 982 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 983 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 984 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 985 | switch (enc->cmd) { |
| 986 | case V4L2_ENC_CMD_START: |
| 987 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); |
| 988 | enc->flags = 0; |
| 989 | break; |
| 990 | |
| 991 | case V4L2_ENC_CMD_STOP: |
| 992 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); |
| 993 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; |
| 994 | break; |
| 995 | |
| 996 | case V4L2_ENC_CMD_PAUSE: |
| 997 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); |
| 998 | enc->flags = 0; |
| 999 | break; |
| 1000 | |
| 1001 | case V4L2_ENC_CMD_RESUME: |
| 1002 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); |
| 1003 | enc->flags = 0; |
| 1004 | break; |
| 1005 | |
| 1006 | default: |
| 1007 | CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); |
| 1008 | return -EINVAL; |
| 1009 | } |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static int cx18_log_status(struct file *file, void *fh) |
| 1014 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 1015 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1016 | struct v4l2_input vidin; |
| 1017 | struct v4l2_audio audin; |
| 1018 | int i; |
| 1019 | |
Andy Walls | e0f28b6 | 2009-01-10 14:13:46 -0300 | [diff] [blame] | 1020 | CX18_INFO("================= START STATUS CARD #%d " |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1021 | "=================\n", cx->instance); |
Andy Walls | e0f28b6 | 2009-01-10 14:13:46 -0300 | [diff] [blame] | 1022 | CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1023 | if (cx->hw_flags & CX18_HW_TVEEPROM) { |
| 1024 | struct tveeprom tv; |
| 1025 | |
| 1026 | cx18_read_eeprom(cx, &tv); |
| 1027 | } |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 1028 | cx18_call_all(cx, core, log_status); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1029 | cx18_get_input(cx, cx->active_input, &vidin); |
| 1030 | cx18_get_audio_input(cx, cx->audio_input, &audin); |
| 1031 | CX18_INFO("Video Input: %s\n", vidin.name); |
| 1032 | CX18_INFO("Audio Input: %s\n", audin.name); |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 1033 | mutex_lock(&cx->gpio_lock); |
Hans Verkuil | 3d66c40 | 2008-06-21 11:19:34 -0300 | [diff] [blame] | 1034 | CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n", |
| 1035 | cx->gpio_dir, cx->gpio_val); |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 1036 | mutex_unlock(&cx->gpio_lock); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1037 | CX18_INFO("Tuner: %s\n", |
| 1038 | test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV"); |
Hans Verkuil | a75b9be | 2010-12-31 10:22:52 -0300 | [diff] [blame] | 1039 | v4l2_ctrl_handler_log_status(&cx->cxhdl.hdl, cx->v4l2_dev.name); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1040 | CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags); |
| 1041 | for (i = 0; i < CX18_MAX_STREAMS; i++) { |
| 1042 | struct cx18_stream *s = &cx->streams[i]; |
| 1043 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 1044 | if (s->video_dev == NULL || s->buffers == 0) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1045 | continue; |
| 1046 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", |
| 1047 | s->name, s->s_flags, |
Andy Walls | 52fcb3e | 2009-11-08 23:45:24 -0300 | [diff] [blame] | 1048 | atomic_read(&s->q_full.depth) * s->bufs_per_mdl * 100 |
| 1049 | / s->buffers, |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1050 | (s->buffers * s->buf_size) / 1024, s->buffers); |
| 1051 | } |
| 1052 | CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", |
| 1053 | (long long)cx->mpg_data_received, |
| 1054 | (long long)cx->vbi_data_inserted); |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1055 | CX18_INFO("================== END STATUS CARD #%d " |
| 1056 | "==================\n", cx->instance); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1057 | return 0; |
| 1058 | } |
| 1059 | |
Hans Verkuil | 99cd47bc | 2011-03-11 19:00:56 -0300 | [diff] [blame] | 1060 | static long cx18_default(struct file *file, void *fh, bool valid_prio, |
| 1061 | int cmd, void *arg) |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1062 | { |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 1063 | struct cx18 *cx = fh2id(fh)->cx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1064 | |
| 1065 | switch (cmd) { |
Andy Walls | 02fa272 | 2008-07-13 19:30:15 -0300 | [diff] [blame] | 1066 | case VIDIOC_INT_RESET: { |
| 1067 | u32 val = *(u32 *)arg; |
| 1068 | |
| 1069 | if ((val == 0) || (val & 0x01)) |
Andy Walls | eefe101 | 2009-02-21 18:42:49 -0300 | [diff] [blame] | 1070 | cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset, |
| 1071 | (u32) CX18_GPIO_RESET_Z8F0811); |
Andy Walls | 02fa272 | 2008-07-13 19:30:15 -0300 | [diff] [blame] | 1072 | break; |
| 1073 | } |
| 1074 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1075 | default: |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1076 | return -EINVAL; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1077 | } |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1081 | long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd, |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1082 | unsigned long arg) |
| 1083 | { |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 1084 | struct video_device *vfd = video_devdata(filp); |
Hans Verkuil | 0b5f265 | 2011-03-12 06:35:33 -0300 | [diff] [blame^] | 1085 | struct cx18_open_id *id = file2id(filp); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1086 | struct cx18 *cx = id->cx; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1087 | long res; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1088 | |
| 1089 | mutex_lock(&cx->serialize_lock); |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 1090 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 1091 | /* FIXME - consolidate v4l2_prio_check()'s here */ |
| 1092 | |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 1093 | if (cx18_debug & CX18_DBGFLG_IOCTL) |
| 1094 | vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG; |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1095 | res = video_ioctl2(filp, cmd, arg); |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 1096 | vfd->debug = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1097 | mutex_unlock(&cx->serialize_lock); |
| 1098 | return res; |
| 1099 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1100 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1101 | static const struct v4l2_ioctl_ops cx18_ioctl_ops = { |
| 1102 | .vidioc_querycap = cx18_querycap, |
| 1103 | .vidioc_g_priority = cx18_g_priority, |
| 1104 | .vidioc_s_priority = cx18_s_priority, |
| 1105 | .vidioc_s_audio = cx18_s_audio, |
| 1106 | .vidioc_g_audio = cx18_g_audio, |
| 1107 | .vidioc_enumaudio = cx18_enumaudio, |
| 1108 | .vidioc_enum_input = cx18_enum_input, |
| 1109 | .vidioc_cropcap = cx18_cropcap, |
| 1110 | .vidioc_s_crop = cx18_s_crop, |
| 1111 | .vidioc_g_crop = cx18_g_crop, |
| 1112 | .vidioc_g_input = cx18_g_input, |
| 1113 | .vidioc_s_input = cx18_s_input, |
| 1114 | .vidioc_g_frequency = cx18_g_frequency, |
| 1115 | .vidioc_s_frequency = cx18_s_frequency, |
| 1116 | .vidioc_s_tuner = cx18_s_tuner, |
| 1117 | .vidioc_g_tuner = cx18_g_tuner, |
| 1118 | .vidioc_g_enc_index = cx18_g_enc_index, |
| 1119 | .vidioc_g_std = cx18_g_std, |
| 1120 | .vidioc_s_std = cx18_s_std, |
| 1121 | .vidioc_log_status = cx18_log_status, |
| 1122 | .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap, |
| 1123 | .vidioc_encoder_cmd = cx18_encoder_cmd, |
| 1124 | .vidioc_try_encoder_cmd = cx18_try_encoder_cmd, |
| 1125 | .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap, |
| 1126 | .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap, |
| 1127 | .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap, |
| 1128 | .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap, |
| 1129 | .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap, |
| 1130 | .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap, |
| 1131 | .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap, |
| 1132 | .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap, |
| 1133 | .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap, |
| 1134 | .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap, |
| 1135 | .vidioc_g_chip_ident = cx18_g_chip_ident, |
| 1136 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1137 | .vidioc_g_register = cx18_g_register, |
| 1138 | .vidioc_s_register = cx18_s_register, |
| 1139 | #endif |
| 1140 | .vidioc_default = cx18_default, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1141 | }; |
| 1142 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1143 | void cx18_set_funcs(struct video_device *vdev) |
| 1144 | { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1145 | vdev->ioctl_ops = &cx18_ioctl_ops; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1146 | } |