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