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 | 1ed9dcc | 2008-11-22 01:37:34 -0300 | [diff] [blame] | 7 | * Copyright (C) 2008 Andy Walls <awalls@radix.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> |
| 43 | #include <linux/i2c-id.h> |
| 44 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 45 | static int cx18_vbi_streaming(struct cx18 *cx) |
| 46 | { |
| 47 | struct cx18_stream *s_vbi = &cx->streams[CX18_ENC_STREAM_TYPE_VBI]; |
| 48 | return (s_vbi->handle != CX18_INVALID_TASK_HANDLE) && |
| 49 | test_bit(CX18_F_S_STREAMING, &s_vbi->s_flags); |
| 50 | } |
| 51 | |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 52 | u16 cx18_service2vbi(int type) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 53 | { |
| 54 | switch (type) { |
| 55 | case V4L2_SLICED_TELETEXT_B: |
| 56 | return CX18_SLICED_TYPE_TELETEXT_B; |
| 57 | case V4L2_SLICED_CAPTION_525: |
| 58 | return CX18_SLICED_TYPE_CAPTION_525; |
| 59 | case V4L2_SLICED_WSS_625: |
| 60 | return CX18_SLICED_TYPE_WSS_625; |
| 61 | case V4L2_SLICED_VPS: |
| 62 | return CX18_SLICED_TYPE_VPS; |
| 63 | default: |
| 64 | return 0; |
| 65 | } |
| 66 | } |
| 67 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 68 | /* 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] | 69 | static int valid_service_line(int field, int line, int is_pal) |
| 70 | { |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 71 | return (is_pal && line >= 6 && |
| 72 | ((field == 0 && line <= 23) || (field == 1 && line <= 22))) || |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 73 | (!is_pal && line >= 10 && line < 22); |
| 74 | } |
| 75 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 76 | /* |
| 77 | * For a (field, line, std) and inbound potential set of services for that line, |
| 78 | * return the first valid service of those passed in the incoming set for that |
| 79 | * line in priority order: |
| 80 | * CC, VPS, or WSS over TELETEXT for well known lines |
| 81 | * TELETEXT, before VPS, before CC, before WSS, for other lines |
| 82 | */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 83 | static u16 select_service_from_set(int field, int line, u16 set, int is_pal) |
| 84 | { |
| 85 | u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525); |
| 86 | int i; |
| 87 | |
| 88 | set = set & valid_set; |
| 89 | if (set == 0 || !valid_service_line(field, line, is_pal)) |
| 90 | return 0; |
| 91 | if (!is_pal) { |
| 92 | if (line == 21 && (set & V4L2_SLICED_CAPTION_525)) |
| 93 | return V4L2_SLICED_CAPTION_525; |
| 94 | } else { |
| 95 | if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS)) |
| 96 | return V4L2_SLICED_VPS; |
| 97 | if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625)) |
| 98 | return V4L2_SLICED_WSS_625; |
| 99 | if (line == 23) |
| 100 | return 0; |
| 101 | } |
| 102 | for (i = 0; i < 32; i++) { |
| 103 | if ((1 << i) & set) |
| 104 | return 1 << i; |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 109 | /* |
| 110 | * Expand the service_set of *fmt into valid service_lines for the std, |
| 111 | * and clear the passed in fmt->service_set |
| 112 | */ |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 113 | 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] | 114 | { |
| 115 | u16 set = fmt->service_set; |
| 116 | int f, l; |
| 117 | |
| 118 | fmt->service_set = 0; |
| 119 | for (f = 0; f < 2; f++) { |
| 120 | for (l = 0; l < 24; l++) |
| 121 | fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal); |
| 122 | } |
| 123 | } |
| 124 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 125 | /* |
| 126 | * Sanitize the service_lines in *fmt per the video std, and return 1 |
| 127 | * if any service_line is left as valid after santization |
| 128 | */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 129 | static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) |
| 130 | { |
| 131 | int f, l; |
| 132 | u16 set = 0; |
| 133 | |
| 134 | for (f = 0; f < 2; f++) { |
| 135 | for (l = 0; l < 24; l++) { |
| 136 | fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal); |
| 137 | set |= fmt->service_lines[f][l]; |
| 138 | } |
| 139 | } |
| 140 | return set != 0; |
| 141 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 142 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 143 | /* 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] | 144 | u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 145 | { |
| 146 | int f, l; |
| 147 | u16 set = 0; |
| 148 | |
| 149 | for (f = 0; f < 2; f++) { |
| 150 | for (l = 0; l < 24; l++) |
| 151 | set |= fmt->service_lines[f][l]; |
| 152 | } |
| 153 | return set; |
| 154 | } |
| 155 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 156 | static int cx18_g_fmt_vid_cap(struct file *file, void *fh, |
| 157 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 158 | { |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 159 | struct cx18_open_id *id = fh; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 160 | struct cx18 *cx = id->cx; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 161 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 162 | |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 163 | pixfmt->width = cx->params.width; |
| 164 | pixfmt->height = cx->params.height; |
| 165 | pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 166 | pixfmt->field = V4L2_FIELD_INTERLACED; |
| 167 | pixfmt->priv = 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 168 | if (id->type == CX18_ENC_STREAM_TYPE_YUV) { |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 169 | pixfmt->pixelformat = V4L2_PIX_FMT_HM12; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 170 | /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 171 | pixfmt->sizeimage = |
| 172 | pixfmt->height * pixfmt->width + |
| 173 | pixfmt->height * (pixfmt->width / 2); |
| 174 | pixfmt->bytesperline = 720; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 175 | } else { |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 176 | pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; |
| 177 | pixfmt->sizeimage = 128 * 1024; |
| 178 | pixfmt->bytesperline = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 179 | } |
| 180 | return 0; |
| 181 | } |
| 182 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 183 | static int cx18_g_fmt_vbi_cap(struct file *file, void *fh, |
| 184 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 185 | { |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 186 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 187 | struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 188 | |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 189 | vbifmt->sampling_rate = 27000000; |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 190 | vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 191 | vbifmt->samples_per_line = vbi_active_samples - 4; |
Hans Verkuil | 0b5a30e | 2008-06-21 09:22:19 -0300 | [diff] [blame] | 192 | vbifmt->sample_format = V4L2_PIX_FMT_GREY; |
| 193 | vbifmt->start[0] = cx->vbi.start[0]; |
| 194 | vbifmt->start[1] = cx->vbi.start[1]; |
| 195 | vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count; |
| 196 | vbifmt->flags = 0; |
| 197 | vbifmt->reserved[0] = 0; |
| 198 | vbifmt->reserved[1] = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 202 | static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 203 | struct v4l2_format *fmt) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 204 | { |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 205 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 206 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 207 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 208 | /* sane, V4L2 spec compliant, defaults */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 209 | vbifmt->reserved[0] = 0; |
| 210 | vbifmt->reserved[1] = 0; |
| 211 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
| 212 | memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines)); |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 213 | vbifmt->service_set = 0; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 214 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 215 | /* |
| 216 | * Fetch the configured service_lines and total service_set from the |
| 217 | * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in |
| 218 | * fmt->fmt.sliced under valid calling conditions |
| 219 | */ |
| 220 | if (cx18_av_cmd(cx, VIDIOC_G_FMT, fmt)) |
| 221 | return -EINVAL; |
| 222 | |
| 223 | /* Ensure V4L2 spec compliant output */ |
| 224 | vbifmt->reserved[0] = 0; |
| 225 | vbifmt->reserved[1] = 0; |
| 226 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 227 | vbifmt->service_set = cx18_get_service_set(vbifmt); |
| 228 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static int cx18_try_fmt_vid_cap(struct file *file, void *fh, |
| 232 | struct v4l2_format *fmt) |
| 233 | { |
| 234 | struct cx18_open_id *id = fh; |
| 235 | struct cx18 *cx = id->cx; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 236 | int w = fmt->fmt.pix.width; |
| 237 | int h = fmt->fmt.pix.height; |
| 238 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 239 | w = min(w, 720); |
| 240 | w = max(w, 1); |
| 241 | h = min(h, cx->is_50hz ? 576 : 480); |
| 242 | h = max(h, 2); |
| 243 | cx18_g_fmt_vid_cap(file, fh, fmt); |
| 244 | fmt->fmt.pix.width = w; |
| 245 | fmt->fmt.pix.height = h; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int cx18_try_fmt_vbi_cap(struct file *file, void *fh, |
| 250 | struct v4l2_format *fmt) |
| 251 | { |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 252 | return cx18_g_fmt_vbi_cap(file, fh, fmt); |
| 253 | } |
| 254 | |
| 255 | static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 256 | struct v4l2_format *fmt) |
| 257 | { |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 258 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 259 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 260 | |
| 261 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
| 262 | vbifmt->reserved[0] = 0; |
| 263 | vbifmt->reserved[1] = 0; |
| 264 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 265 | /* If given a service set, expand it validly & clear passed in set */ |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 266 | if (vbifmt->service_set) |
| 267 | cx18_expand_service_set(vbifmt, cx->is_50hz); |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 268 | /* Sanitize the service_lines, and compute the new set if any valid */ |
| 269 | if (check_service_set(vbifmt, cx->is_50hz)) |
| 270 | vbifmt->service_set = cx18_get_service_set(vbifmt); |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 271 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int cx18_s_fmt_vid_cap(struct file *file, void *fh, |
| 275 | struct v4l2_format *fmt) |
| 276 | { |
| 277 | struct cx18_open_id *id = fh; |
| 278 | struct cx18 *cx = id->cx; |
| 279 | int ret; |
Hans Verkuil | effc346 | 2008-09-06 08:24:37 -0300 | [diff] [blame] | 280 | int w, h; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 281 | |
| 282 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 283 | if (ret) |
| 284 | return ret; |
| 285 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 286 | ret = cx18_try_fmt_vid_cap(file, fh, fmt); |
| 287 | if (ret) |
| 288 | return ret; |
Hans Verkuil | effc346 | 2008-09-06 08:24:37 -0300 | [diff] [blame] | 289 | w = fmt->fmt.pix.width; |
| 290 | h = fmt->fmt.pix.height; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 291 | |
| 292 | if (cx->params.width == w && cx->params.height == h) |
| 293 | return 0; |
| 294 | |
| 295 | if (atomic_read(&cx->ana_capturing) > 0) |
| 296 | return -EBUSY; |
| 297 | |
| 298 | cx->params.width = w; |
| 299 | cx->params.height = h; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 300 | cx18_av_cmd(cx, VIDIOC_S_FMT, fmt); |
| 301 | return cx18_g_fmt_vid_cap(file, fh, fmt); |
| 302 | } |
| 303 | |
| 304 | static int cx18_s_fmt_vbi_cap(struct file *file, void *fh, |
| 305 | struct v4l2_format *fmt) |
| 306 | { |
| 307 | struct cx18_open_id *id = fh; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 308 | struct cx18 *cx = id->cx; |
| 309 | int ret; |
| 310 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 311 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 312 | if (ret) |
| 313 | return ret; |
| 314 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 315 | if (!cx18_raw_vbi(cx) && cx18_vbi_streaming(cx)) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 316 | return -EBUSY; |
| 317 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 318 | /* |
| 319 | * Set the digitizer registers for raw active VBI. |
| 320 | * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid |
| 321 | * calling conditions |
| 322 | */ |
| 323 | ret = cx18_av_cmd(cx, VIDIOC_S_FMT, fmt); |
| 324 | if (ret) |
| 325 | return ret; |
| 326 | |
| 327 | /* Store our new v4l2 (non-)sliced VBI state */ |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 328 | cx->vbi.sliced_in->service_set = 0; |
Andy Walls | dd07343 | 2008-12-12 16:24:04 -0300 | [diff] [blame] | 329 | cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 330 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 331 | return cx18_g_fmt_vbi_cap(file, fh, fmt); |
| 332 | } |
| 333 | |
| 334 | static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh, |
| 335 | struct v4l2_format *fmt) |
| 336 | { |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 337 | struct cx18_open_id *id = fh; |
| 338 | struct cx18 *cx = id->cx; |
| 339 | int ret; |
| 340 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; |
| 341 | |
| 342 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 343 | if (ret) |
| 344 | return ret; |
| 345 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 346 | cx18_try_fmt_sliced_vbi_cap(file, fh, fmt); |
| 347 | |
| 348 | if (cx18_raw_vbi(cx) && cx18_vbi_streaming(cx)) |
| 349 | return -EBUSY; |
| 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 | */ |
| 355 | ret = cx18_av_cmd(cx, VIDIOC_S_FMT, fmt); |
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 | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static int cx18_g_chip_ident(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 365 | struct v4l2_dbg_chip_ident *chip) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 366 | { |
| 367 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 368 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 369 | chip->ident = V4L2_IDENT_NONE; |
| 370 | chip->revision = 0; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 371 | if (v4l2_chip_match_host(&chip->match)) { |
| 372 | chip->ident = V4L2_IDENT_CX23418; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 373 | return 0; |
| 374 | } |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 375 | cx18_call_i2c_clients(cx, VIDIOC_DBG_G_CHIP_IDENT, chip); |
| 376 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 377 | } |
| 378 | |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 379 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 380 | static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg) |
| 381 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 382 | struct v4l2_dbg_register *regs = arg; |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 383 | unsigned long flags; |
| 384 | |
| 385 | if (!capable(CAP_SYS_ADMIN)) |
| 386 | return -EPERM; |
| 387 | if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | spin_lock_irqsave(&cx18_cards_lock, flags); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 391 | regs->size = 4; |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 392 | if (cmd == VIDIOC_DBG_G_REGISTER) |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 393 | regs->val = cx18_read_enc(cx, regs->reg); |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 394 | else |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 395 | cx18_write_enc(cx, regs->val, regs->reg); |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 396 | spin_unlock_irqrestore(&cx18_cards_lock, flags); |
| 397 | return 0; |
| 398 | } |
| 399 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 400 | static int cx18_g_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 401 | struct v4l2_dbg_register *reg) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 402 | { |
| 403 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 404 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 405 | if (v4l2_chip_match_host(®->match)) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 406 | return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 407 | cx18_call_i2c_clients(cx, VIDIOC_DBG_G_REGISTER, reg); |
| 408 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static int cx18_s_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 412 | struct v4l2_dbg_register *reg) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 413 | { |
| 414 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 415 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 416 | if (v4l2_chip_match_host(®->match)) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 417 | return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg); |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 418 | cx18_call_i2c_clients(cx, VIDIOC_DBG_S_REGISTER, reg); |
| 419 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 420 | } |
Hans Verkuil | 36ecd49 | 2008-06-25 06:00:17 -0300 | [diff] [blame] | 421 | #endif |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 422 | |
| 423 | static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p) |
| 424 | { |
| 425 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 426 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 427 | *p = v4l2_prio_max(&cx->prio); |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio) |
| 432 | { |
| 433 | struct cx18_open_id *id = fh; |
| 434 | struct cx18 *cx = id->cx; |
| 435 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 436 | return v4l2_prio_change(&cx->prio, &id->prio, prio); |
| 437 | } |
| 438 | |
| 439 | static int cx18_querycap(struct file *file, void *fh, |
| 440 | struct v4l2_capability *vcap) |
| 441 | { |
| 442 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 443 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 444 | strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver)); |
| 445 | strlcpy(vcap->card, cx->card_name, sizeof(vcap->card)); |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 446 | snprintf(vcap->bus_info, sizeof(vcap->bus_info), |
| 447 | "PCI:%s", pci_name(cx->pci_dev)); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 448 | vcap->version = CX18_DRIVER_VERSION; /* version */ |
| 449 | vcap->capabilities = cx->v4l2_cap; /* capabilities */ |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin) |
| 454 | { |
| 455 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 456 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 457 | return cx18_get_audio_input(cx, vin->index, vin); |
| 458 | } |
| 459 | |
| 460 | static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin) |
| 461 | { |
| 462 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 463 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 464 | vin->index = cx->audio_input; |
| 465 | return cx18_get_audio_input(cx, vin->index, vin); |
| 466 | } |
| 467 | |
| 468 | static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout) |
| 469 | { |
| 470 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 471 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 472 | if (vout->index >= cx->nof_audio_inputs) |
| 473 | return -EINVAL; |
| 474 | cx->audio_input = vout->index; |
| 475 | cx18_audio_set_io(cx); |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin) |
| 480 | { |
| 481 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 482 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 483 | /* set it to defaults from our table */ |
| 484 | return cx18_get_input(cx, vin->index, vin); |
| 485 | } |
| 486 | |
| 487 | static int cx18_cropcap(struct file *file, void *fh, |
| 488 | struct v4l2_cropcap *cropcap) |
| 489 | { |
| 490 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 491 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 492 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 493 | return -EINVAL; |
| 494 | cropcap->bounds.top = cropcap->bounds.left = 0; |
| 495 | cropcap->bounds.width = 720; |
| 496 | cropcap->bounds.height = cx->is_50hz ? 576 : 480; |
| 497 | cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10; |
| 498 | cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11; |
| 499 | cropcap->defrect = cropcap->bounds; |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 504 | { |
| 505 | struct cx18_open_id *id = fh; |
| 506 | struct cx18 *cx = id->cx; |
| 507 | int ret; |
| 508 | |
| 509 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 510 | if (ret) |
| 511 | return ret; |
| 512 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 513 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 514 | return -EINVAL; |
| 515 | return cx18_av_cmd(cx, VIDIOC_S_CROP, crop); |
| 516 | } |
| 517 | |
| 518 | static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 519 | { |
| 520 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 521 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 522 | if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 523 | return -EINVAL; |
| 524 | return cx18_av_cmd(cx, VIDIOC_G_CROP, crop); |
| 525 | } |
| 526 | |
| 527 | static int cx18_enum_fmt_vid_cap(struct file *file, void *fh, |
| 528 | struct v4l2_fmtdesc *fmt) |
| 529 | { |
| 530 | static struct v4l2_fmtdesc formats[] = { |
| 531 | { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0, |
| 532 | "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 } |
| 533 | }, |
| 534 | { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED, |
| 535 | "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 } |
| 536 | } |
| 537 | }; |
| 538 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 539 | if (fmt->index > 1) |
| 540 | return -EINVAL; |
| 541 | *fmt = formats[fmt->index]; |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int cx18_g_input(struct file *file, void *fh, unsigned int *i) |
| 546 | { |
| 547 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 548 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 549 | *i = cx->active_input; |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | int cx18_s_input(struct file *file, void *fh, unsigned int inp) |
| 554 | { |
| 555 | struct cx18_open_id *id = fh; |
| 556 | struct cx18 *cx = id->cx; |
| 557 | int ret; |
| 558 | |
| 559 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 560 | if (ret) |
| 561 | return ret; |
| 562 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 563 | if (inp < 0 || inp >= cx->nof_inputs) |
| 564 | return -EINVAL; |
| 565 | |
| 566 | if (inp == cx->active_input) { |
| 567 | CX18_DEBUG_INFO("Input unchanged\n"); |
| 568 | return 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 569 | } |
| 570 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 571 | CX18_DEBUG_INFO("Changing input from %d to %d\n", |
| 572 | cx->active_input, inp); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 573 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 574 | cx->active_input = inp; |
| 575 | /* Set the audio input to whatever is appropriate for the input type. */ |
| 576 | cx->audio_input = cx->card->video_inputs[inp].audio_index; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 577 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 578 | /* prevent others from messing with the streams until |
| 579 | we're finished changing inputs. */ |
| 580 | cx18_mute(cx); |
| 581 | cx18_video_set_io(cx); |
| 582 | cx18_audio_set_io(cx); |
| 583 | cx18_unmute(cx); |
| 584 | return 0; |
| 585 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 586 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 587 | static int cx18_g_frequency(struct file *file, void *fh, |
| 588 | struct v4l2_frequency *vf) |
| 589 | { |
| 590 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 591 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 592 | if (vf->tuner != 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 593 | return -EINVAL; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 594 | |
| 595 | cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf); |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) |
| 600 | { |
| 601 | struct cx18_open_id *id = fh; |
| 602 | struct cx18 *cx = id->cx; |
| 603 | int ret; |
| 604 | |
| 605 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 606 | if (ret) |
| 607 | return ret; |
| 608 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 609 | if (vf->tuner != 0) |
| 610 | return -EINVAL; |
| 611 | |
| 612 | cx18_mute(cx); |
| 613 | CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency); |
| 614 | cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf); |
| 615 | cx18_unmute(cx); |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std) |
| 620 | { |
| 621 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 622 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 623 | *std = cx->std; |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std) |
| 628 | { |
| 629 | struct cx18_open_id *id = fh; |
| 630 | struct cx18 *cx = id->cx; |
| 631 | int ret; |
| 632 | |
| 633 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 634 | if (ret) |
| 635 | return ret; |
| 636 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 637 | if ((*std & V4L2_STD_ALL) == 0) |
| 638 | return -EINVAL; |
| 639 | |
| 640 | if (*std == cx->std) |
| 641 | return 0; |
| 642 | |
| 643 | if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) || |
| 644 | atomic_read(&cx->ana_capturing) > 0) { |
| 645 | /* Switching standard would turn off the radio or mess |
| 646 | with already running streams, prevent that by |
| 647 | returning EBUSY. */ |
| 648 | return -EBUSY; |
| 649 | } |
| 650 | |
| 651 | cx->std = *std; |
| 652 | cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; |
| 653 | cx->params.is_50hz = cx->is_50hz = !cx->is_60hz; |
| 654 | cx->params.width = 720; |
| 655 | cx->params.height = cx->is_50hz ? 576 : 480; |
| 656 | cx->vbi.count = cx->is_50hz ? 18 : 12; |
| 657 | cx->vbi.start[0] = cx->is_50hz ? 6 : 10; |
| 658 | cx->vbi.start[1] = cx->is_50hz ? 318 : 273; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 659 | CX18_DEBUG_INFO("Switching standard to %llx.\n", |
| 660 | (unsigned long long) cx->std); |
| 661 | |
| 662 | /* Tuner */ |
| 663 | cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std); |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) |
| 668 | { |
| 669 | struct cx18_open_id *id = fh; |
| 670 | struct cx18 *cx = id->cx; |
| 671 | int ret; |
| 672 | |
| 673 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 674 | if (ret) |
| 675 | return ret; |
| 676 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 677 | if (vt->index != 0) |
| 678 | return -EINVAL; |
| 679 | |
| 680 | /* Setting tuner can only set audio mode */ |
| 681 | cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt); |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) |
| 687 | { |
| 688 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 689 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 690 | if (vt->index != 0) |
| 691 | return -EINVAL; |
| 692 | |
| 693 | cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt); |
| 694 | |
| 695 | if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) { |
| 696 | strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name)); |
| 697 | vt->type = V4L2_TUNER_RADIO; |
| 698 | } else { |
| 699 | strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name)); |
| 700 | vt->type = V4L2_TUNER_ANALOG_TV; |
| 701 | } |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int cx18_g_sliced_vbi_cap(struct file *file, void *fh, |
| 707 | struct v4l2_sliced_vbi_cap *cap) |
| 708 | { |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 709 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 710 | int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525; |
| 711 | int f, l; |
| 712 | |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 713 | if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) |
| 714 | return -EINVAL; |
| 715 | |
| 716 | cap->service_set = 0; |
| 717 | for (f = 0; f < 2; f++) { |
| 718 | for (l = 0; l < 24; l++) { |
| 719 | if (valid_service_line(f, l, cx->is_50hz)) { |
| 720 | /* |
| 721 | * We can find all v4l2 supported vbi services |
| 722 | * for the standard, on a valid line for the std |
| 723 | */ |
| 724 | cap->service_lines[f][l] = set; |
| 725 | cap->service_set |= set; |
| 726 | } else |
| 727 | cap->service_lines[f][l] = 0; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 728 | } |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 729 | } |
Andy Walls | c199408 | 2009-02-05 22:37:49 -0300 | [diff] [blame^] | 730 | for (f = 0; f < 3; f++) |
| 731 | cap->reserved[f] = 0; |
| 732 | return 0; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static int cx18_g_enc_index(struct file *file, void *fh, |
| 736 | struct v4l2_enc_idx *idx) |
| 737 | { |
| 738 | return -EINVAL; |
| 739 | } |
| 740 | |
| 741 | static int cx18_encoder_cmd(struct file *file, void *fh, |
| 742 | struct v4l2_encoder_cmd *enc) |
| 743 | { |
| 744 | struct cx18_open_id *id = fh; |
| 745 | struct cx18 *cx = id->cx; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 746 | u32 h; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 747 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 748 | switch (enc->cmd) { |
| 749 | case V4L2_ENC_CMD_START: |
| 750 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); |
| 751 | enc->flags = 0; |
| 752 | return cx18_start_capture(id); |
| 753 | |
| 754 | case V4L2_ENC_CMD_STOP: |
| 755 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); |
| 756 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; |
| 757 | cx18_stop_capture(id, |
| 758 | enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END); |
| 759 | break; |
| 760 | |
| 761 | case V4L2_ENC_CMD_PAUSE: |
| 762 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); |
| 763 | enc->flags = 0; |
| 764 | if (!atomic_read(&cx->ana_capturing)) |
| 765 | return -EPERM; |
| 766 | if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) |
| 767 | return 0; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 768 | h = cx18_find_handle(cx); |
| 769 | if (h == CX18_INVALID_TASK_HANDLE) { |
| 770 | CX18_ERR("Can't find valid task handle for " |
| 771 | "V4L2_ENC_CMD_PAUSE\n"); |
| 772 | return -EBADFD; |
| 773 | } |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 774 | cx18_mute(cx); |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 775 | cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case V4L2_ENC_CMD_RESUME: |
| 779 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); |
| 780 | enc->flags = 0; |
| 781 | if (!atomic_read(&cx->ana_capturing)) |
| 782 | return -EPERM; |
| 783 | if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) |
| 784 | return 0; |
Andy Walls | d3c5e70 | 2008-08-23 16:42:29 -0300 | [diff] [blame] | 785 | h = cx18_find_handle(cx); |
| 786 | if (h == CX18_INVALID_TASK_HANDLE) { |
| 787 | CX18_ERR("Can't find valid task handle for " |
| 788 | "V4L2_ENC_CMD_RESUME\n"); |
| 789 | return -EBADFD; |
| 790 | } |
| 791 | cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 792 | cx18_unmute(cx); |
| 793 | break; |
| 794 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 795 | default: |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 796 | CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int cx18_try_encoder_cmd(struct file *file, void *fh, |
| 803 | struct v4l2_encoder_cmd *enc) |
| 804 | { |
| 805 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 806 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 807 | switch (enc->cmd) { |
| 808 | case V4L2_ENC_CMD_START: |
| 809 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); |
| 810 | enc->flags = 0; |
| 811 | break; |
| 812 | |
| 813 | case V4L2_ENC_CMD_STOP: |
| 814 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); |
| 815 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; |
| 816 | break; |
| 817 | |
| 818 | case V4L2_ENC_CMD_PAUSE: |
| 819 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); |
| 820 | enc->flags = 0; |
| 821 | break; |
| 822 | |
| 823 | case V4L2_ENC_CMD_RESUME: |
| 824 | CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); |
| 825 | enc->flags = 0; |
| 826 | break; |
| 827 | |
| 828 | default: |
| 829 | CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static int cx18_log_status(struct file *file, void *fh) |
| 836 | { |
| 837 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 838 | struct v4l2_input vidin; |
| 839 | struct v4l2_audio audin; |
| 840 | int i; |
| 841 | |
Andy Walls | e0f28b6 | 2009-01-10 14:13:46 -0300 | [diff] [blame] | 842 | CX18_INFO("================= START STATUS CARD #%d " |
| 843 | "=================\n", cx->num); |
| 844 | CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 845 | if (cx->hw_flags & CX18_HW_TVEEPROM) { |
| 846 | struct tveeprom tv; |
| 847 | |
| 848 | cx18_read_eeprom(cx, &tv); |
| 849 | } |
| 850 | cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL); |
| 851 | cx18_get_input(cx, cx->active_input, &vidin); |
| 852 | cx18_get_audio_input(cx, cx->audio_input, &audin); |
| 853 | CX18_INFO("Video Input: %s\n", vidin.name); |
| 854 | CX18_INFO("Audio Input: %s\n", audin.name); |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 855 | mutex_lock(&cx->gpio_lock); |
Hans Verkuil | 3d66c40 | 2008-06-21 11:19:34 -0300 | [diff] [blame] | 856 | CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n", |
| 857 | cx->gpio_dir, cx->gpio_val); |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 858 | mutex_unlock(&cx->gpio_lock); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 859 | CX18_INFO("Tuner: %s\n", |
| 860 | test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV"); |
| 861 | cx2341x_log_status(&cx->params, cx->name); |
| 862 | CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags); |
| 863 | for (i = 0; i < CX18_MAX_STREAMS; i++) { |
| 864 | struct cx18_stream *s = &cx->streams[i]; |
| 865 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 866 | if (s->video_dev == NULL || s->buffers == 0) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 867 | continue; |
| 868 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", |
| 869 | s->name, s->s_flags, |
Andy Walls | 66c2a6b | 2008-12-08 23:02:45 -0300 | [diff] [blame] | 870 | atomic_read(&s->q_full.buffers) * 100 / s->buffers, |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 871 | (s->buffers * s->buf_size) / 1024, s->buffers); |
| 872 | } |
| 873 | CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", |
| 874 | (long long)cx->mpg_data_received, |
| 875 | (long long)cx->vbi_data_inserted); |
| 876 | CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num); |
| 877 | return 0; |
| 878 | } |
| 879 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 880 | static long cx18_default(struct file *file, void *fh, int cmd, void *arg) |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 881 | { |
| 882 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
| 883 | |
| 884 | switch (cmd) { |
| 885 | case VIDIOC_INT_S_AUDIO_ROUTING: { |
| 886 | struct v4l2_routing *route = arg; |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 887 | |
| 888 | CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n", |
| 889 | route->input, route->output); |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 890 | cx18_audio_set_route(cx, route); |
| 891 | break; |
| 892 | } |
Andy Walls | 02fa272 | 2008-07-13 19:30:15 -0300 | [diff] [blame] | 893 | |
| 894 | case VIDIOC_INT_RESET: { |
| 895 | u32 val = *(u32 *)arg; |
| 896 | |
| 897 | if ((val == 0) || (val & 0x01)) |
| 898 | cx18_reset_ir_gpio(&cx->i2c_algo_cb_data[0]); |
| 899 | break; |
| 900 | } |
| 901 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 902 | default: |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 903 | return -EINVAL; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 904 | } |
| 905 | return 0; |
| 906 | } |
| 907 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 908 | long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd, |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 909 | unsigned long arg) |
| 910 | { |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 911 | struct video_device *vfd = video_devdata(filp); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 912 | struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data; |
| 913 | struct cx18 *cx = id->cx; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 914 | long res; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 915 | |
| 916 | mutex_lock(&cx->serialize_lock); |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 917 | |
| 918 | if (cx18_debug & CX18_DBGFLG_IOCTL) |
| 919 | vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG; |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 920 | res = video_ioctl2(filp, cmd, arg); |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 921 | vfd->debug = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 922 | mutex_unlock(&cx->serialize_lock); |
| 923 | return res; |
| 924 | } |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 925 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 926 | static const struct v4l2_ioctl_ops cx18_ioctl_ops = { |
| 927 | .vidioc_querycap = cx18_querycap, |
| 928 | .vidioc_g_priority = cx18_g_priority, |
| 929 | .vidioc_s_priority = cx18_s_priority, |
| 930 | .vidioc_s_audio = cx18_s_audio, |
| 931 | .vidioc_g_audio = cx18_g_audio, |
| 932 | .vidioc_enumaudio = cx18_enumaudio, |
| 933 | .vidioc_enum_input = cx18_enum_input, |
| 934 | .vidioc_cropcap = cx18_cropcap, |
| 935 | .vidioc_s_crop = cx18_s_crop, |
| 936 | .vidioc_g_crop = cx18_g_crop, |
| 937 | .vidioc_g_input = cx18_g_input, |
| 938 | .vidioc_s_input = cx18_s_input, |
| 939 | .vidioc_g_frequency = cx18_g_frequency, |
| 940 | .vidioc_s_frequency = cx18_s_frequency, |
| 941 | .vidioc_s_tuner = cx18_s_tuner, |
| 942 | .vidioc_g_tuner = cx18_g_tuner, |
| 943 | .vidioc_g_enc_index = cx18_g_enc_index, |
| 944 | .vidioc_g_std = cx18_g_std, |
| 945 | .vidioc_s_std = cx18_s_std, |
| 946 | .vidioc_log_status = cx18_log_status, |
| 947 | .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap, |
| 948 | .vidioc_encoder_cmd = cx18_encoder_cmd, |
| 949 | .vidioc_try_encoder_cmd = cx18_try_encoder_cmd, |
| 950 | .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap, |
| 951 | .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap, |
| 952 | .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap, |
| 953 | .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap, |
| 954 | .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap, |
| 955 | .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap, |
| 956 | .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap, |
| 957 | .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap, |
| 958 | .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap, |
| 959 | .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap, |
| 960 | .vidioc_g_chip_ident = cx18_g_chip_ident, |
| 961 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 962 | .vidioc_g_register = cx18_g_register, |
| 963 | .vidioc_s_register = cx18_s_register, |
| 964 | #endif |
| 965 | .vidioc_default = cx18_default, |
| 966 | .vidioc_queryctrl = cx18_queryctrl, |
| 967 | .vidioc_querymenu = cx18_querymenu, |
| 968 | .vidioc_g_ext_ctrls = cx18_g_ext_ctrls, |
| 969 | .vidioc_s_ext_ctrls = cx18_s_ext_ctrls, |
| 970 | .vidioc_try_ext_ctrls = cx18_try_ext_ctrls, |
| 971 | }; |
| 972 | |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 973 | void cx18_set_funcs(struct video_device *vdev) |
| 974 | { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 975 | vdev->ioctl_ops = &cx18_ioctl_ops; |
Andy Walls | 3b6fe58f | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 976 | } |