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