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