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