Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2 | cx231xx-video.c - driver for Conexant Cx23100/101/102 |
| 3 | USB video capture devices |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 4 | |
| 5 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 6 | Based on em28xx driver |
| 7 | Based on cx23885 driver |
| 8 | Based on cx88 driver |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/bitmap.h> |
| 30 | #include <linux/usb.h> |
| 31 | #include <linux/i2c.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/mm.h> |
| 34 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 36 | |
| 37 | #include <media/v4l2-common.h> |
| 38 | #include <media/v4l2-ioctl.h> |
| 39 | #include <media/v4l2-chip-ident.h> |
| 40 | #include <media/msp3400.h> |
| 41 | #include <media/tuner.h> |
| 42 | |
| 43 | #include "dvb_frontend.h" |
| 44 | |
| 45 | #include "cx231xx.h" |
| 46 | #include "cx231xx-vbi.h" |
| 47 | |
Mauro Carvalho Chehab | 818fdf3 | 2009-03-13 07:41:58 -0300 | [diff] [blame] | 48 | #define CX231XX_VERSION_CODE KERNEL_VERSION(0, 0, 1) |
| 49 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 50 | #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>" |
| 51 | #define DRIVER_DESC "Conexant cx231xx based USB video device driver" |
| 52 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 53 | #define cx231xx_videodbg(fmt, arg...) do {\ |
| 54 | if (video_debug) \ |
| 55 | printk(KERN_INFO "%s %s :"fmt, \ |
| 56 | dev->name, __func__ , ##arg); } while (0) |
| 57 | |
| 58 | static unsigned int isoc_debug; |
| 59 | module_param(isoc_debug, int, 0644); |
| 60 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); |
| 61 | |
| 62 | #define cx231xx_isocdbg(fmt, arg...) \ |
| 63 | do {\ |
| 64 | if (isoc_debug) { \ |
| 65 | printk(KERN_INFO "%s %s :"fmt, \ |
| 66 | dev->name, __func__ , ##arg); \ |
| 67 | } \ |
| 68 | } while (0) |
| 69 | |
| 70 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 71 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 72 | MODULE_LICENSE("GPL"); |
| 73 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 74 | static unsigned int card[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; |
| 75 | static unsigned int video_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; |
| 76 | static unsigned int vbi_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; |
| 77 | static unsigned int radio_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; |
| 78 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 79 | module_param_array(card, int, NULL, 0444); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 80 | module_param_array(video_nr, int, NULL, 0444); |
| 81 | module_param_array(vbi_nr, int, NULL, 0444); |
| 82 | module_param_array(radio_nr, int, NULL, 0444); |
| 83 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 84 | MODULE_PARM_DESC(card, "card type"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 85 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 86 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 87 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
| 88 | |
| 89 | static unsigned int video_debug; |
| 90 | module_param(video_debug, int, 0644); |
| 91 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
| 92 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 93 | /* supported video standards */ |
| 94 | static struct cx231xx_fmt format[] = { |
| 95 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 96 | .name = "16bpp YUY2, 4:2:2, packed", |
| 97 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 98 | .depth = 16, |
| 99 | .reg = 0, |
| 100 | }, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 101 | }; |
| 102 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 103 | /* supported controls */ |
| 104 | /* Common to all boards */ |
| 105 | |
| 106 | /* ------------------------------------------------------------------- */ |
| 107 | |
| 108 | static const struct v4l2_queryctrl no_ctl = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 109 | .name = "42", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 110 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 111 | }; |
| 112 | |
| 113 | static struct cx231xx_ctrl cx231xx_ctls[] = { |
| 114 | /* --- video --- */ |
| 115 | { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 116 | .v = { |
| 117 | .id = V4L2_CID_BRIGHTNESS, |
| 118 | .name = "Brightness", |
| 119 | .minimum = 0x00, |
| 120 | .maximum = 0xff, |
| 121 | .step = 1, |
| 122 | .default_value = 0x7f, |
| 123 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 124 | }, |
| 125 | .off = 128, |
| 126 | .reg = LUMA_CTRL, |
| 127 | .mask = 0x00ff, |
| 128 | .shift = 0, |
| 129 | }, { |
| 130 | .v = { |
| 131 | .id = V4L2_CID_CONTRAST, |
| 132 | .name = "Contrast", |
| 133 | .minimum = 0, |
| 134 | .maximum = 0xff, |
| 135 | .step = 1, |
| 136 | .default_value = 0x3f, |
| 137 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 138 | }, |
| 139 | .off = 0, |
| 140 | .reg = LUMA_CTRL, |
| 141 | .mask = 0xff00, |
| 142 | .shift = 8, |
| 143 | }, { |
| 144 | .v = { |
| 145 | .id = V4L2_CID_HUE, |
| 146 | .name = "Hue", |
| 147 | .minimum = 0, |
| 148 | .maximum = 0xff, |
| 149 | .step = 1, |
| 150 | .default_value = 0x7f, |
| 151 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 152 | }, |
| 153 | .off = 128, |
| 154 | .reg = CHROMA_CTRL, |
| 155 | .mask = 0xff0000, |
| 156 | .shift = 16, |
| 157 | }, { |
| 158 | /* strictly, this only describes only U saturation. |
| 159 | * V saturation is handled specially through code. |
| 160 | */ |
| 161 | .v = { |
| 162 | .id = V4L2_CID_SATURATION, |
| 163 | .name = "Saturation", |
| 164 | .minimum = 0, |
| 165 | .maximum = 0xff, |
| 166 | .step = 1, |
| 167 | .default_value = 0x7f, |
| 168 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 169 | }, |
| 170 | .off = 0, |
| 171 | .reg = CHROMA_CTRL, |
| 172 | .mask = 0x00ff, |
| 173 | .shift = 0, |
| 174 | }, { |
| 175 | /* --- audio --- */ |
| 176 | .v = { |
| 177 | .id = V4L2_CID_AUDIO_MUTE, |
| 178 | .name = "Mute", |
| 179 | .minimum = 0, |
| 180 | .maximum = 1, |
| 181 | .default_value = 1, |
| 182 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 183 | }, |
| 184 | .reg = PATH1_CTL1, |
| 185 | .mask = (0x1f << 24), |
| 186 | .shift = 24, |
| 187 | }, { |
| 188 | .v = { |
| 189 | .id = V4L2_CID_AUDIO_VOLUME, |
| 190 | .name = "Volume", |
| 191 | .minimum = 0, |
| 192 | .maximum = 0x3f, |
| 193 | .step = 1, |
| 194 | .default_value = 0x3f, |
| 195 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 196 | }, |
| 197 | .reg = PATH1_VOL_CTL, |
| 198 | .mask = 0xff, |
| 199 | .shift = 0, |
| 200 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 201 | }; |
| 202 | static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls); |
| 203 | |
| 204 | static const u32 cx231xx_user_ctrls[] = { |
| 205 | V4L2_CID_USER_CLASS, |
| 206 | V4L2_CID_BRIGHTNESS, |
| 207 | V4L2_CID_CONTRAST, |
| 208 | V4L2_CID_SATURATION, |
| 209 | V4L2_CID_HUE, |
| 210 | V4L2_CID_AUDIO_VOLUME, |
| 211 | #if 0 |
| 212 | V4L2_CID_AUDIO_BALANCE, |
| 213 | #endif |
| 214 | V4L2_CID_AUDIO_MUTE, |
| 215 | 0 |
| 216 | }; |
| 217 | |
| 218 | static const u32 *ctrl_classes[] = { |
| 219 | cx231xx_user_ctrls, |
| 220 | NULL |
| 221 | }; |
| 222 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 223 | /* ------------------------------------------------------------------ |
| 224 | Video buffer and parser functions |
| 225 | ------------------------------------------------------------------*/ |
| 226 | |
| 227 | /* |
| 228 | * Announces that a buffer were filled and request the next |
| 229 | */ |
| 230 | static inline void buffer_filled(struct cx231xx *dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 231 | struct cx231xx_dmaqueue *dma_q, |
| 232 | struct cx231xx_buffer *buf) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 233 | { |
| 234 | /* Advice that buffer was filled */ |
| 235 | cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 236 | buf->vb.state = VIDEOBUF_DONE; |
| 237 | buf->vb.field_count++; |
| 238 | do_gettimeofday(&buf->vb.ts); |
| 239 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 240 | if (dev->USE_ISO) |
| 241 | dev->video_mode.isoc_ctl.buf = NULL; |
| 242 | else |
| 243 | dev->video_mode.bulk_ctl.buf = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 244 | |
| 245 | list_del(&buf->vb.queue); |
| 246 | wake_up(&buf->vb.done); |
| 247 | } |
| 248 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 249 | static inline void print_err_status(struct cx231xx *dev, int packet, int status) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 250 | { |
| 251 | char *errmsg = "Unknown"; |
| 252 | |
| 253 | switch (status) { |
| 254 | case -ENOENT: |
| 255 | errmsg = "unlinked synchronuously"; |
| 256 | break; |
| 257 | case -ECONNRESET: |
| 258 | errmsg = "unlinked asynchronuously"; |
| 259 | break; |
| 260 | case -ENOSR: |
| 261 | errmsg = "Buffer error (overrun)"; |
| 262 | break; |
| 263 | case -EPIPE: |
| 264 | errmsg = "Stalled (device not responding)"; |
| 265 | break; |
| 266 | case -EOVERFLOW: |
| 267 | errmsg = "Babble (bad cable?)"; |
| 268 | break; |
| 269 | case -EPROTO: |
| 270 | errmsg = "Bit-stuff error (bad cable?)"; |
| 271 | break; |
| 272 | case -EILSEQ: |
| 273 | errmsg = "CRC/Timeout (could be anything)"; |
| 274 | break; |
| 275 | case -ETIME: |
| 276 | errmsg = "Device does not respond"; |
| 277 | break; |
| 278 | } |
| 279 | if (packet < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 280 | cx231xx_isocdbg("URB status %d [%s].\n", status, errmsg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 281 | } else { |
| 282 | cx231xx_isocdbg("URB packet %d, status %d [%s].\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 283 | packet, status, errmsg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * video-buf generic routine to get the next available buffer |
| 289 | */ |
| 290 | static inline void get_next_buf(struct cx231xx_dmaqueue *dma_q, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 291 | struct cx231xx_buffer **buf) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 292 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 293 | struct cx231xx_video_mode *vmode = |
| 294 | container_of(dma_q, struct cx231xx_video_mode, vidq); |
| 295 | struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 296 | |
| 297 | char *outp; |
| 298 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 299 | if (list_empty(&dma_q->active)) { |
| 300 | cx231xx_isocdbg("No active queue to serve\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 301 | if (dev->USE_ISO) |
| 302 | dev->video_mode.isoc_ctl.buf = NULL; |
| 303 | else |
| 304 | dev->video_mode.bulk_ctl.buf = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 305 | *buf = NULL; |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* Get the next buffer */ |
| 310 | *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue); |
| 311 | |
| 312 | /* Cleans up buffer - Usefull for testing for frame/URB loss */ |
| 313 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 314 | memset(outp, 0, (*buf)->vb.size); |
| 315 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 316 | if (dev->USE_ISO) |
| 317 | dev->video_mode.isoc_ctl.buf = *buf; |
| 318 | else |
| 319 | dev->video_mode.bulk_ctl.buf = *buf; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 320 | |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Controls the isoc copy of each urb packet |
| 326 | */ |
| 327 | static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb) |
| 328 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 329 | struct cx231xx_buffer *buf; |
| 330 | struct cx231xx_dmaqueue *dma_q = urb->context; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 331 | unsigned char *outp = NULL; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 332 | int i, rc = 1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 333 | unsigned char *p_buffer; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 334 | u32 bytes_parsed = 0, buffer_size = 0; |
| 335 | u8 sav_eav = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 336 | |
| 337 | if (!dev) |
| 338 | return 0; |
| 339 | |
| 340 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 341 | return 0; |
| 342 | |
| 343 | if (urb->status < 0) { |
| 344 | print_err_status(dev, -1, urb->status); |
| 345 | if (urb->status == -ENOENT) |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | buf = dev->video_mode.isoc_ctl.buf; |
| 350 | if (buf != NULL) |
| 351 | outp = videobuf_to_vmalloc(&buf->vb); |
| 352 | |
| 353 | for (i = 0; i < urb->number_of_packets; i++) { |
| 354 | int status = urb->iso_frame_desc[i].status; |
| 355 | |
| 356 | if (status < 0) { |
| 357 | print_err_status(dev, i, status); |
| 358 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 359 | continue; |
| 360 | } |
| 361 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 362 | if (urb->iso_frame_desc[i].actual_length <= 0) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 363 | /* cx231xx_isocdbg("packet %d is empty",i); - spammy */ |
| 364 | continue; |
| 365 | } |
| 366 | if (urb->iso_frame_desc[i].actual_length > |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 367 | dev->video_mode.max_pkt_size) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 368 | cx231xx_isocdbg("packet bigger than packet size"); |
| 369 | continue; |
| 370 | } |
| 371 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 372 | /* get buffer pointer and length */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 373 | p_buffer = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 374 | buffer_size = urb->iso_frame_desc[i].actual_length; |
| 375 | bytes_parsed = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 376 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 377 | if (dma_q->is_partial_line) { |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 378 | /* Handle the case of a partial line */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 379 | sav_eav = dma_q->last_sav; |
| 380 | } else { |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 381 | /* Check for a SAV/EAV overlapping |
| 382 | the buffer boundary */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 383 | sav_eav = |
| 384 | cx231xx_find_boundary_SAV_EAV(p_buffer, |
| 385 | dma_q->partial_buf, |
| 386 | &bytes_parsed); |
| 387 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 388 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 389 | sav_eav &= 0xF0; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 390 | /* Get the first line if we have some portion of an SAV/EAV from |
| 391 | the last buffer or a partial line */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 392 | if (sav_eav) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 393 | bytes_parsed += cx231xx_get_video_line(dev, dma_q, |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 394 | sav_eav, /* SAV/EAV */ |
| 395 | p_buffer + bytes_parsed, /* p_buffer */ |
| 396 | buffer_size - bytes_parsed);/* buf size */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 397 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 398 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 399 | /* Now parse data that is completely in this buffer */ |
| 400 | /* dma_q->is_partial_line = 0; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 401 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 402 | while (bytes_parsed < buffer_size) { |
| 403 | u32 bytes_used = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 404 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 405 | sav_eav = cx231xx_find_next_SAV_EAV( |
| 406 | p_buffer + bytes_parsed, /* p_buffer */ |
| 407 | buffer_size - bytes_parsed, /* buf size */ |
| 408 | &bytes_used);/* bytes used to get SAV/EAV */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 409 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 410 | bytes_parsed += bytes_used; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 411 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 412 | sav_eav &= 0xF0; |
| 413 | if (sav_eav && (bytes_parsed < buffer_size)) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 414 | bytes_parsed += cx231xx_get_video_line(dev, |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 415 | dma_q, sav_eav, /* SAV/EAV */ |
| 416 | p_buffer + bytes_parsed,/* p_buffer */ |
| 417 | buffer_size - bytes_parsed);/*buf size*/ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 418 | } |
| 419 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 420 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 421 | /* Save the last four bytes of the buffer so we can check the |
| 422 | buffer boundary condition next time */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 423 | memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4); |
| 424 | bytes_parsed = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 425 | |
| 426 | } |
| 427 | return rc; |
| 428 | } |
| 429 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 430 | static inline int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb) |
| 431 | { |
| 432 | struct cx231xx_buffer *buf; |
| 433 | struct cx231xx_dmaqueue *dma_q = urb->context; |
| 434 | unsigned char *outp = NULL; |
| 435 | int rc = 1; |
| 436 | unsigned char *p_buffer; |
| 437 | u32 bytes_parsed = 0, buffer_size = 0; |
| 438 | u8 sav_eav = 0; |
| 439 | |
| 440 | if (!dev) |
| 441 | return 0; |
| 442 | |
| 443 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 444 | return 0; |
| 445 | |
| 446 | if (urb->status < 0) { |
| 447 | print_err_status(dev, -1, urb->status); |
| 448 | if (urb->status == -ENOENT) |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | buf = dev->video_mode.bulk_ctl.buf; |
| 453 | if (buf != NULL) |
| 454 | outp = videobuf_to_vmalloc(&buf->vb); |
| 455 | |
| 456 | if (1) { |
| 457 | |
| 458 | /* get buffer pointer and length */ |
| 459 | p_buffer = urb->transfer_buffer; |
| 460 | buffer_size = urb->actual_length; |
| 461 | bytes_parsed = 0; |
| 462 | |
| 463 | if (dma_q->is_partial_line) { |
| 464 | /* Handle the case of a partial line */ |
| 465 | sav_eav = dma_q->last_sav; |
| 466 | } else { |
| 467 | /* Check for a SAV/EAV overlapping |
| 468 | the buffer boundary */ |
| 469 | sav_eav = |
| 470 | cx231xx_find_boundary_SAV_EAV(p_buffer, |
| 471 | dma_q->partial_buf, |
| 472 | &bytes_parsed); |
| 473 | } |
| 474 | |
| 475 | sav_eav &= 0xF0; |
| 476 | /* Get the first line if we have some portion of an SAV/EAV from |
| 477 | the last buffer or a partial line */ |
| 478 | if (sav_eav) { |
| 479 | bytes_parsed += cx231xx_get_video_line(dev, dma_q, |
| 480 | sav_eav, /* SAV/EAV */ |
| 481 | p_buffer + bytes_parsed, /* p_buffer */ |
| 482 | buffer_size - bytes_parsed);/* buf size */ |
| 483 | } |
| 484 | |
| 485 | /* Now parse data that is completely in this buffer */ |
| 486 | /* dma_q->is_partial_line = 0; */ |
| 487 | |
| 488 | while (bytes_parsed < buffer_size) { |
| 489 | u32 bytes_used = 0; |
| 490 | |
| 491 | sav_eav = cx231xx_find_next_SAV_EAV( |
| 492 | p_buffer + bytes_parsed, /* p_buffer */ |
| 493 | buffer_size - bytes_parsed, /* buf size */ |
| 494 | &bytes_used);/* bytes used to get SAV/EAV */ |
| 495 | |
| 496 | bytes_parsed += bytes_used; |
| 497 | |
| 498 | sav_eav &= 0xF0; |
| 499 | if (sav_eav && (bytes_parsed < buffer_size)) { |
| 500 | bytes_parsed += cx231xx_get_video_line(dev, |
| 501 | dma_q, sav_eav, /* SAV/EAV */ |
| 502 | p_buffer + bytes_parsed,/* p_buffer */ |
| 503 | buffer_size - bytes_parsed);/*buf size*/ |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* Save the last four bytes of the buffer so we can check the |
| 508 | buffer boundary condition next time */ |
| 509 | memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4); |
| 510 | bytes_parsed = 0; |
| 511 | |
| 512 | } |
| 513 | return rc; |
| 514 | } |
| 515 | |
| 516 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 517 | u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf, |
| 518 | u32 *p_bytes_used) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 519 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 520 | u32 bytes_used; |
| 521 | u8 boundary_bytes[8]; |
| 522 | u8 sav_eav = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 523 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 524 | *p_bytes_used = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 525 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 526 | /* Create an array of the last 4 bytes of the last buffer and the first |
| 527 | 4 bytes of the current buffer. */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 528 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 529 | memcpy(boundary_bytes, partial_buf, 4); |
| 530 | memcpy(boundary_bytes + 4, p_buffer, 4); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 531 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 532 | /* Check for the SAV/EAV in the boundary buffer */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 533 | sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8, |
| 534 | &bytes_used); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 535 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 536 | if (sav_eav) { |
| 537 | /* found a boundary SAV/EAV. Updates the bytes used to reflect |
| 538 | only those used in the new buffer */ |
| 539 | *p_bytes_used = bytes_used - 4; |
| 540 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 541 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 542 | return sav_eav; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 543 | } |
| 544 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 545 | u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 546 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 547 | u32 i; |
| 548 | u8 sav_eav = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 549 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 550 | /* |
| 551 | * Don't search if the buffer size is less than 4. It causes a page |
| 552 | * fault since buffer_size - 4 evaluates to a large number in that |
| 553 | * case. |
| 554 | */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 555 | if (buffer_size < 4) { |
| 556 | *p_bytes_used = buffer_size; |
| 557 | return 0; |
| 558 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 559 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 560 | for (i = 0; i < (buffer_size - 3); i++) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 561 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 562 | if ((p_buffer[i] == 0xFF) && |
| 563 | (p_buffer[i + 1] == 0x00) && (p_buffer[i + 2] == 0x00)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 564 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 565 | *p_bytes_used = i + 4; |
| 566 | sav_eav = p_buffer[i + 3]; |
| 567 | return sav_eav; |
| 568 | } |
| 569 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 570 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 571 | *p_bytes_used = buffer_size; |
| 572 | return 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 573 | } |
| 574 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 575 | u32 cx231xx_get_video_line(struct cx231xx *dev, |
| 576 | struct cx231xx_dmaqueue *dma_q, u8 sav_eav, |
| 577 | u8 *p_buffer, u32 buffer_size) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 578 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 579 | u32 bytes_copied = 0; |
| 580 | int current_field = -1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 581 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 582 | switch (sav_eav) { |
| 583 | case SAV_ACTIVE_VIDEO_FIELD1: |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 584 | /* looking for skipped line which occurred in PAL 720x480 mode. |
| 585 | In this case, there will be no active data contained |
| 586 | between the SAV and EAV */ |
| 587 | if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && |
| 588 | (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && |
| 589 | ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || |
| 590 | (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || |
| 591 | (p_buffer[3] == EAV_VBLANK_FIELD1) || |
| 592 | (p_buffer[3] == EAV_VBLANK_FIELD2))) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 593 | return bytes_copied; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 594 | current_field = 1; |
| 595 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 596 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 597 | case SAV_ACTIVE_VIDEO_FIELD2: |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 598 | /* looking for skipped line which occurred in PAL 720x480 mode. |
| 599 | In this case, there will be no active data contained between |
| 600 | the SAV and EAV */ |
| 601 | if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && |
| 602 | (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && |
| 603 | ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || |
| 604 | (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || |
| 605 | (p_buffer[3] == EAV_VBLANK_FIELD1) || |
| 606 | (p_buffer[3] == EAV_VBLANK_FIELD2))) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 607 | return bytes_copied; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 608 | current_field = 2; |
| 609 | break; |
| 610 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 611 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 612 | dma_q->last_sav = sav_eav; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 613 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 614 | bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer, |
| 615 | buffer_size, current_field); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 616 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 617 | return bytes_copied; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 618 | } |
| 619 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 620 | u32 cx231xx_copy_video_line(struct cx231xx *dev, |
| 621 | struct cx231xx_dmaqueue *dma_q, u8 *p_line, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 622 | u32 length, int field_number) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 623 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 624 | u32 bytes_to_copy; |
| 625 | struct cx231xx_buffer *buf; |
| 626 | u32 _line_size = dev->width * 2; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 627 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 628 | if (dma_q->current_field != field_number) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 629 | cx231xx_reset_video_buffer(dev, dma_q); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 630 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 631 | /* get the buffer pointer */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 632 | if (dev->USE_ISO) |
| 633 | buf = dev->video_mode.isoc_ctl.buf; |
| 634 | else |
| 635 | buf = dev->video_mode.bulk_ctl.buf; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 636 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 637 | /* Remember the field number for next time */ |
| 638 | dma_q->current_field = field_number; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 639 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 640 | bytes_to_copy = dma_q->bytes_left_in_line; |
| 641 | if (bytes_to_copy > length) |
| 642 | bytes_to_copy = length; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 643 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 644 | if (dma_q->lines_completed >= dma_q->lines_per_field) { |
| 645 | dma_q->bytes_left_in_line -= bytes_to_copy; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 646 | dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ? |
| 647 | 0 : 1; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 648 | return 0; |
| 649 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 650 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 651 | dma_q->is_partial_line = 1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 652 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 653 | /* If we don't have a buffer, just return the number of bytes we would |
| 654 | have copied if we had a buffer. */ |
| 655 | if (!buf) { |
| 656 | dma_q->bytes_left_in_line -= bytes_to_copy; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 657 | dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) |
| 658 | ? 0 : 1; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 659 | return bytes_to_copy; |
| 660 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 661 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 662 | /* copy the data to video buffer */ |
| 663 | cx231xx_do_copy(dev, dma_q, p_line, bytes_to_copy); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 664 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 665 | dma_q->pos += bytes_to_copy; |
| 666 | dma_q->bytes_left_in_line -= bytes_to_copy; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 667 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 668 | if (dma_q->bytes_left_in_line == 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 669 | dma_q->bytes_left_in_line = _line_size; |
| 670 | dma_q->lines_completed++; |
| 671 | dma_q->is_partial_line = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 672 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 673 | if (cx231xx_is_buffer_done(dev, dma_q) && buf) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 674 | buffer_filled(dev, dma_q, buf); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 675 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 676 | dma_q->pos = 0; |
| 677 | buf = NULL; |
| 678 | dma_q->lines_completed = 0; |
| 679 | } |
| 680 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 681 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 682 | return bytes_to_copy; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 683 | } |
| 684 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 685 | void cx231xx_reset_video_buffer(struct cx231xx *dev, |
| 686 | struct cx231xx_dmaqueue *dma_q) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 687 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 688 | struct cx231xx_buffer *buf; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 689 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 690 | /* handle the switch from field 1 to field 2 */ |
| 691 | if (dma_q->current_field == 1) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 692 | if (dma_q->lines_completed >= dma_q->lines_per_field) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 693 | dma_q->field1_done = 1; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 694 | else |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 695 | dma_q->field1_done = 0; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 696 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 697 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 698 | if (dev->USE_ISO) |
| 699 | buf = dev->video_mode.isoc_ctl.buf; |
| 700 | else |
| 701 | buf = dev->video_mode.bulk_ctl.buf; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 702 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 703 | if (buf == NULL) { |
| 704 | u8 *outp = NULL; |
| 705 | /* first try to get the buffer */ |
| 706 | get_next_buf(dma_q, &buf); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 707 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 708 | if (buf) |
| 709 | outp = videobuf_to_vmalloc(&buf->vb); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 710 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 711 | dma_q->pos = 0; |
| 712 | dma_q->field1_done = 0; |
| 713 | dma_q->current_field = -1; |
| 714 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 715 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 716 | /* reset the counters */ |
| 717 | dma_q->bytes_left_in_line = dev->width << 1; |
| 718 | dma_q->lines_completed = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 722 | u8 *p_buffer, u32 bytes_to_copy) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 723 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 724 | u8 *p_out_buffer = NULL; |
| 725 | u32 current_line_bytes_copied = 0; |
| 726 | struct cx231xx_buffer *buf; |
| 727 | u32 _line_size = dev->width << 1; |
| 728 | void *startwrite; |
| 729 | int offset, lencopy; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 730 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 731 | if (dev->USE_ISO) |
| 732 | buf = dev->video_mode.isoc_ctl.buf; |
| 733 | else |
| 734 | buf = dev->video_mode.bulk_ctl.buf; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 735 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 736 | if (buf == NULL) |
| 737 | return -1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 738 | |
| 739 | p_out_buffer = videobuf_to_vmalloc(&buf->vb); |
| 740 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 741 | current_line_bytes_copied = _line_size - dma_q->bytes_left_in_line; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 742 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 743 | /* Offset field 2 one line from the top of the buffer */ |
| 744 | offset = (dma_q->current_field == 1) ? 0 : _line_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 745 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 746 | /* Offset for field 2 */ |
| 747 | startwrite = p_out_buffer + offset; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 748 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 749 | /* lines already completed in the current field */ |
| 750 | startwrite += (dma_q->lines_completed * _line_size * 2); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 751 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 752 | /* bytes already completed in the current line */ |
| 753 | startwrite += current_line_bytes_copied; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 754 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 755 | lencopy = dma_q->bytes_left_in_line > bytes_to_copy ? |
| 756 | bytes_to_copy : dma_q->bytes_left_in_line; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 757 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 758 | if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size)) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 759 | return 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 760 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 761 | /* The below copies the UYVY data straight into video buffer */ |
| 762 | cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 763 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 764 | return 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 765 | } |
| 766 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 767 | void cx231xx_swab(u16 *from, u16 *to, u16 len) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 768 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 769 | u16 i; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 770 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 771 | if (len <= 0) |
| 772 | return; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 773 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 774 | for (i = 0; i < len / 2; i++) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 775 | to[i] = (from[i] << 8) | (from[i] >> 8); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 776 | } |
| 777 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 778 | u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 779 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 780 | u8 buffer_complete = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 781 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 782 | /* Dual field stream */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 783 | buffer_complete = ((dma_q->current_field == 2) && |
| 784 | (dma_q->lines_completed >= dma_q->lines_per_field) && |
| 785 | dma_q->field1_done); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 786 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 787 | return buffer_complete; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 788 | } |
| 789 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 790 | /* ------------------------------------------------------------------ |
| 791 | Videobuf operations |
| 792 | ------------------------------------------------------------------*/ |
| 793 | |
| 794 | static int |
| 795 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) |
| 796 | { |
| 797 | struct cx231xx_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 798 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 799 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 800 | *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 801 | if (0 == *count) |
| 802 | *count = CX231XX_DEF_BUF; |
| 803 | |
| 804 | if (*count < CX231XX_MIN_BUF) |
| 805 | *count = CX231XX_MIN_BUF; |
| 806 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | /* This is called *without* dev->slock held; please keep it that way */ |
| 811 | static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf) |
| 812 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 813 | struct cx231xx_fh *fh = vq->priv_data; |
| 814 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 815 | unsigned long flags = 0; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 816 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 817 | if (in_interrupt()) |
| 818 | BUG(); |
| 819 | |
| 820 | /* We used to wait for the buffer to finish here, but this didn't work |
| 821 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 822 | videobuf_queue_cancel marked it as finished for us. |
| 823 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 824 | |
| 825 | This should be safe; by the time we get here, the buffer isn't |
| 826 | queued anymore. If we ever start marking the buffers as |
| 827 | VIDEOBUF_ACTIVE, it won't be, though. |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 828 | */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 829 | spin_lock_irqsave(&dev->video_mode.slock, flags); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 830 | if (dev->USE_ISO) { |
| 831 | if (dev->video_mode.isoc_ctl.buf == buf) |
| 832 | dev->video_mode.isoc_ctl.buf = NULL; |
| 833 | } else { |
| 834 | if (dev->video_mode.bulk_ctl.buf == buf) |
| 835 | dev->video_mode.bulk_ctl.buf = NULL; |
| 836 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 837 | spin_unlock_irqrestore(&dev->video_mode.slock, flags); |
| 838 | |
| 839 | videobuf_vmalloc_free(&buf->vb); |
| 840 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 841 | } |
| 842 | |
| 843 | static int |
| 844 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 845 | enum v4l2_field field) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 846 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 847 | struct cx231xx_fh *fh = vq->priv_data; |
| 848 | struct cx231xx_buffer *buf = |
| 849 | container_of(vb, struct cx231xx_buffer, vb); |
| 850 | struct cx231xx *dev = fh->dev; |
| 851 | int rc = 0, urb_init = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 852 | |
| 853 | /* The only currently supported format is 16 bits/pixel */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 854 | buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth |
| 855 | + 7) >> 3; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 856 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 857 | return -EINVAL; |
| 858 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 859 | buf->vb.width = dev->width; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 860 | buf->vb.height = dev->height; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 861 | buf->vb.field = field; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 862 | |
| 863 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 864 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 865 | if (rc < 0) |
| 866 | goto fail; |
| 867 | } |
| 868 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 869 | if (dev->USE_ISO) { |
| 870 | if (!dev->video_mode.isoc_ctl.num_bufs) |
| 871 | urb_init = 1; |
| 872 | } else { |
| 873 | if (!dev->video_mode.bulk_ctl.num_bufs) |
| 874 | urb_init = 1; |
| 875 | } |
| 876 | /*cx231xx_info("urb_init=%d dev->video_mode.max_pkt_size=%d\n", |
| 877 | urb_init, dev->video_mode.max_pkt_size);*/ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 878 | if (urb_init) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 879 | dev->mode_tv = 0; |
| 880 | if (dev->USE_ISO) |
| 881 | rc = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 882 | CX231XX_NUM_BUFS, |
| 883 | dev->video_mode.max_pkt_size, |
| 884 | cx231xx_isoc_copy); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 885 | else |
| 886 | rc = cx231xx_init_bulk(dev, CX231XX_NUM_PACKETS, |
| 887 | CX231XX_NUM_BUFS, |
| 888 | dev->video_mode.max_pkt_size, |
| 889 | cx231xx_bulk_copy); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 890 | if (rc < 0) |
| 891 | goto fail; |
| 892 | } |
| 893 | |
| 894 | buf->vb.state = VIDEOBUF_PREPARED; |
| 895 | return 0; |
| 896 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 897 | fail: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 898 | free_buffer(vq, buf); |
| 899 | return rc; |
| 900 | } |
| 901 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 902 | static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 903 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 904 | struct cx231xx_buffer *buf = |
| 905 | container_of(vb, struct cx231xx_buffer, vb); |
| 906 | struct cx231xx_fh *fh = vq->priv_data; |
| 907 | struct cx231xx *dev = fh->dev; |
| 908 | struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 909 | |
| 910 | buf->vb.state = VIDEOBUF_QUEUED; |
| 911 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 912 | |
| 913 | } |
| 914 | |
| 915 | static void buffer_release(struct videobuf_queue *vq, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 916 | struct videobuf_buffer *vb) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 917 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 918 | struct cx231xx_buffer *buf = |
| 919 | container_of(vb, struct cx231xx_buffer, vb); |
| 920 | struct cx231xx_fh *fh = vq->priv_data; |
| 921 | struct cx231xx *dev = (struct cx231xx *)fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 922 | |
| 923 | cx231xx_isocdbg("cx231xx: called buffer_release\n"); |
| 924 | |
| 925 | free_buffer(vq, buf); |
| 926 | } |
| 927 | |
| 928 | static struct videobuf_queue_ops cx231xx_video_qops = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 929 | .buf_setup = buffer_setup, |
| 930 | .buf_prepare = buffer_prepare, |
| 931 | .buf_queue = buffer_queue, |
| 932 | .buf_release = buffer_release, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 933 | }; |
| 934 | |
| 935 | /********************* v4l2 interface **************************************/ |
| 936 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 937 | void video_mux(struct cx231xx *dev, int index) |
| 938 | { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 939 | dev->video_input = index; |
| 940 | dev->ctl_ainput = INPUT(index)->amux; |
| 941 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 942 | cx231xx_set_video_input_mux(dev, index); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 943 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 944 | cx25840_call(dev, video, s_routing, INPUT(index)->vmux, 0, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 945 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 946 | cx231xx_set_audio_input(dev, dev->ctl_ainput); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 947 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 948 | cx231xx_info("video_mux : %d\n", index); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 949 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 950 | /* do mode control overrides if required */ |
| 951 | cx231xx_do_mode_ctrl_overrides(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /* Usage lock check functions */ |
| 955 | static int res_get(struct cx231xx_fh *fh) |
| 956 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 957 | struct cx231xx *dev = fh->dev; |
| 958 | int rc = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 959 | |
| 960 | /* This instance already has stream_on */ |
| 961 | if (fh->stream_on) |
| 962 | return rc; |
| 963 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 964 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 965 | if (dev->stream_on) |
| 966 | return -EBUSY; |
| 967 | dev->stream_on = 1; |
| 968 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
| 969 | if (dev->vbi_stream_on) |
| 970 | return -EBUSY; |
| 971 | dev->vbi_stream_on = 1; |
| 972 | } else |
| 973 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 974 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 975 | fh->stream_on = 1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 976 | |
| 977 | return rc; |
| 978 | } |
| 979 | |
| 980 | static int res_check(struct cx231xx_fh *fh) |
| 981 | { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 982 | return fh->stream_on; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static void res_free(struct cx231xx_fh *fh) |
| 986 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 987 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 988 | |
| 989 | fh->stream_on = 0; |
| 990 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 991 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 992 | dev->stream_on = 0; |
| 993 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 994 | dev->vbi_stream_on = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static int check_dev(struct cx231xx *dev) |
| 998 | { |
| 999 | if (dev->state & DEV_DISCONNECTED) { |
| 1000 | cx231xx_errdev("v4l2 ioctl: device not present\n"); |
| 1001 | return -ENODEV; |
| 1002 | } |
| 1003 | |
| 1004 | if (dev->state & DEV_MISCONFIGURED) { |
| 1005 | cx231xx_errdev("v4l2 ioctl: device is misconfigured; " |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1006 | "close and open it again\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1007 | return -EIO; |
| 1008 | } |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1012 | /* ------------------------------------------------------------------ |
| 1013 | IOCTL vidioc handling |
| 1014 | ------------------------------------------------------------------*/ |
| 1015 | |
| 1016 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1017 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1018 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1019 | struct cx231xx_fh *fh = priv; |
| 1020 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1021 | |
| 1022 | mutex_lock(&dev->lock); |
| 1023 | |
| 1024 | f->fmt.pix.width = dev->width; |
| 1025 | f->fmt.pix.height = dev->height; |
Joe Perches | 1ebcad7 | 2009-07-02 15:57:09 -0300 | [diff] [blame] | 1026 | f->fmt.pix.pixelformat = dev->format->fourcc; |
| 1027 | f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1028 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1029 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1030 | |
| 1031 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1032 | |
| 1033 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1034 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc) |
| 1039 | { |
| 1040 | unsigned int i; |
| 1041 | |
| 1042 | for (i = 0; i < ARRAY_SIZE(format); i++) |
| 1043 | if (format[i].fourcc == fourcc) |
| 1044 | return &format[i]; |
| 1045 | |
| 1046 | return NULL; |
| 1047 | } |
| 1048 | |
| 1049 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1050 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1051 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1052 | struct cx231xx_fh *fh = priv; |
| 1053 | struct cx231xx *dev = fh->dev; |
Trent Piepho | 9bd0e8d | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1054 | unsigned int width = f->fmt.pix.width; |
| 1055 | unsigned int height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1056 | unsigned int maxw = norm_maxw(dev); |
| 1057 | unsigned int maxh = norm_maxh(dev); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1058 | struct cx231xx_fmt *fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1059 | |
| 1060 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1061 | if (!fmt) { |
| 1062 | cx231xx_videodbg("Fourcc format (%08x) invalid.\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1063 | f->fmt.pix.pixelformat); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1064 | return -EINVAL; |
| 1065 | } |
| 1066 | |
| 1067 | /* width must even because of the YUYV format |
| 1068 | height must be even because of interlacing */ |
Trent Piepho | 9bd0e8d | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1069 | v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1070 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1071 | f->fmt.pix.width = width; |
| 1072 | f->fmt.pix.height = height; |
| 1073 | f->fmt.pix.pixelformat = fmt->fourcc; |
| 1074 | f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; |
| 1075 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; |
| 1076 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1077 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1083 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1084 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1085 | struct cx231xx_fh *fh = priv; |
| 1086 | struct cx231xx *dev = fh->dev; |
| 1087 | int rc; |
| 1088 | struct cx231xx_fmt *fmt; |
Hans Verkuil | 112cb4a | 2010-05-09 10:11:01 -0300 | [diff] [blame] | 1089 | struct v4l2_mbus_framefmt mbus_fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1090 | |
| 1091 | rc = check_dev(dev); |
| 1092 | if (rc < 0) |
| 1093 | return rc; |
| 1094 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1095 | mutex_lock(&dev->lock); |
| 1096 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1097 | vidioc_try_fmt_vid_cap(file, priv, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1098 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1099 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1100 | if (!fmt) { |
| 1101 | rc = -EINVAL; |
| 1102 | goto out; |
| 1103 | } |
| 1104 | |
| 1105 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 1106 | cx231xx_errdev("%s queue busy\n", __func__); |
| 1107 | rc = -EBUSY; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
| 1111 | if (dev->stream_on && !fh->stream_on) { |
| 1112 | cx231xx_errdev("%s device in use by another fh\n", __func__); |
| 1113 | rc = -EBUSY; |
| 1114 | goto out; |
| 1115 | } |
| 1116 | |
| 1117 | /* set new image size */ |
| 1118 | dev->width = f->fmt.pix.width; |
| 1119 | dev->height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1120 | dev->format = fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1121 | |
Hans Verkuil | 112cb4a | 2010-05-09 10:11:01 -0300 | [diff] [blame] | 1122 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 1123 | call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 1124 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1125 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1126 | out: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1127 | mutex_unlock(&dev->lock); |
| 1128 | return rc; |
| 1129 | } |
| 1130 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1131 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1132 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1133 | struct cx231xx_fh *fh = priv; |
| 1134 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1135 | |
| 1136 | *id = dev->norm; |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1140 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1141 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1142 | struct cx231xx_fh *fh = priv; |
| 1143 | struct cx231xx *dev = fh->dev; |
Devin Heitmueller | 435b4f7 | 2010-07-09 13:29:31 -0300 | [diff] [blame] | 1144 | struct v4l2_mbus_framefmt mbus_fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1145 | struct v4l2_format f; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1146 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1147 | |
| 1148 | rc = check_dev(dev); |
| 1149 | if (rc < 0) |
| 1150 | return rc; |
| 1151 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1152 | cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1153 | |
| 1154 | mutex_lock(&dev->lock); |
| 1155 | dev->norm = *norm; |
| 1156 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1157 | /* Adjusts width/height, if needed */ |
| 1158 | f.fmt.pix.width = dev->width; |
| 1159 | f.fmt.pix.height = dev->height; |
| 1160 | vidioc_try_fmt_vid_cap(file, priv, &f); |
| 1161 | |
Devin Heitmueller | 435b4f7 | 2010-07-09 13:29:31 -0300 | [diff] [blame] | 1162 | call_all(dev, core, s_std, dev->norm); |
| 1163 | |
| 1164 | /* We need to reset basic properties in the decoder related to |
| 1165 | resolution (since a standard change effects things like the number |
| 1166 | of lines in VACT, etc) */ |
| 1167 | v4l2_fill_mbus_format(&mbus_fmt, &f.fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 1168 | call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 1169 | v4l2_fill_pix_format(&f.fmt.pix, &mbus_fmt); |
| 1170 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1171 | /* set new image size */ |
| 1172 | dev->width = f.fmt.pix.width; |
| 1173 | dev->height = f.fmt.pix.height; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1174 | |
| 1175 | mutex_unlock(&dev->lock); |
| 1176 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1177 | /* do mode control overrides */ |
| 1178 | cx231xx_do_mode_ctrl_overrides(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | static const char *iname[] = { |
| 1184 | [CX231XX_VMUX_COMPOSITE1] = "Composite1", |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1185 | [CX231XX_VMUX_SVIDEO] = "S-Video", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1186 | [CX231XX_VMUX_TELEVISION] = "Television", |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1187 | [CX231XX_VMUX_CABLE] = "Cable TV", |
| 1188 | [CX231XX_VMUX_DVB] = "DVB", |
| 1189 | [CX231XX_VMUX_DEBUG] = "for debug only", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1190 | }; |
| 1191 | |
| 1192 | static int vidioc_enum_input(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1193 | struct v4l2_input *i) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1194 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1195 | struct cx231xx_fh *fh = priv; |
| 1196 | struct cx231xx *dev = fh->dev; |
| 1197 | unsigned int n; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1198 | |
| 1199 | n = i->index; |
| 1200 | if (n >= MAX_CX231XX_INPUT) |
| 1201 | return -EINVAL; |
| 1202 | if (0 == INPUT(n)->type) |
| 1203 | return -EINVAL; |
| 1204 | |
| 1205 | i->index = n; |
| 1206 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1207 | |
| 1208 | strcpy(i->name, iname[INPUT(n)->type]); |
| 1209 | |
| 1210 | if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) || |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1211 | (CX231XX_VMUX_CABLE == INPUT(n)->type)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1212 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1213 | |
| 1214 | i->std = dev->vdev->tvnorms; |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1220 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1221 | struct cx231xx_fh *fh = priv; |
| 1222 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1223 | |
| 1224 | *i = dev->video_input; |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 1230 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1231 | struct cx231xx_fh *fh = priv; |
| 1232 | struct cx231xx *dev = fh->dev; |
| 1233 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1234 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1235 | dev->mode_tv = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1236 | rc = check_dev(dev); |
| 1237 | if (rc < 0) |
| 1238 | return rc; |
| 1239 | |
| 1240 | if (i >= MAX_CX231XX_INPUT) |
| 1241 | return -EINVAL; |
| 1242 | if (0 == INPUT(i)->type) |
| 1243 | return -EINVAL; |
| 1244 | |
| 1245 | mutex_lock(&dev->lock); |
| 1246 | |
| 1247 | video_mux(dev, i); |
| 1248 | |
Devin Heitmueller | c09d669 | 2010-07-12 16:50:30 -0300 | [diff] [blame^] | 1249 | if (INPUT(i)->type == CX231XX_VMUX_TELEVISION || |
| 1250 | INPUT(i)->type == CX231XX_VMUX_CABLE) { |
| 1251 | /* There's a tuner, so reset the standard and put it on the |
| 1252 | last known frequency (since it was probably powered down |
| 1253 | until now */ |
| 1254 | call_all(dev, core, s_std, dev->norm); |
| 1255 | } |
| 1256 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1257 | mutex_unlock(&dev->lock); |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1262 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1263 | struct cx231xx_fh *fh = priv; |
| 1264 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1265 | |
| 1266 | switch (a->index) { |
| 1267 | case CX231XX_AMUX_VIDEO: |
| 1268 | strcpy(a->name, "Television"); |
| 1269 | break; |
| 1270 | case CX231XX_AMUX_LINE_IN: |
| 1271 | strcpy(a->name, "Line In"); |
| 1272 | break; |
| 1273 | default: |
| 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
| 1277 | a->index = dev->ctl_ainput; |
| 1278 | a->capability = V4L2_AUDCAP_STEREO; |
| 1279 | |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1284 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1285 | struct cx231xx_fh *fh = priv; |
| 1286 | struct cx231xx *dev = fh->dev; |
| 1287 | int status = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1288 | |
| 1289 | /* Doesn't allow manual routing */ |
| 1290 | if (a->index != dev->ctl_ainput) |
| 1291 | return -EINVAL; |
| 1292 | |
| 1293 | dev->ctl_ainput = INPUT(a->index)->amux; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1294 | status = cx231xx_set_audio_input(dev, dev->ctl_ainput); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1295 | |
| 1296 | return status; |
| 1297 | } |
| 1298 | |
| 1299 | static int vidioc_queryctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1300 | struct v4l2_queryctrl *qc) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1301 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1302 | struct cx231xx_fh *fh = priv; |
| 1303 | struct cx231xx *dev = fh->dev; |
| 1304 | int id = qc->id; |
| 1305 | int i; |
| 1306 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1307 | |
| 1308 | rc = check_dev(dev); |
| 1309 | if (rc < 0) |
| 1310 | return rc; |
| 1311 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1312 | qc->id = v4l2_ctrl_next(ctrl_classes, qc->id); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1313 | if (unlikely(qc->id == 0)) |
| 1314 | return -EINVAL; |
| 1315 | |
| 1316 | memset(qc, 0, sizeof(*qc)); |
| 1317 | |
| 1318 | qc->id = id; |
| 1319 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1320 | if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1321 | return -EINVAL; |
| 1322 | |
| 1323 | for (i = 0; i < CX231XX_CTLS; i++) |
| 1324 | if (cx231xx_ctls[i].v.id == qc->id) |
| 1325 | break; |
| 1326 | |
| 1327 | if (i == CX231XX_CTLS) { |
| 1328 | *qc = no_ctl; |
| 1329 | return 0; |
| 1330 | } |
| 1331 | *qc = cx231xx_ctls[i].v; |
| 1332 | |
| 1333 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1334 | call_all(dev, core, queryctrl, qc); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1335 | mutex_unlock(&dev->lock); |
| 1336 | |
| 1337 | if (qc->type) |
| 1338 | return 0; |
| 1339 | else |
| 1340 | return -EINVAL; |
| 1341 | } |
| 1342 | |
| 1343 | static int vidioc_g_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1344 | struct v4l2_control *ctrl) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1345 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1346 | struct cx231xx_fh *fh = priv; |
| 1347 | struct cx231xx *dev = fh->dev; |
| 1348 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1349 | |
| 1350 | rc = check_dev(dev); |
| 1351 | if (rc < 0) |
| 1352 | return rc; |
| 1353 | |
| 1354 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1355 | call_all(dev, core, g_ctrl, ctrl); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1356 | mutex_unlock(&dev->lock); |
| 1357 | return rc; |
| 1358 | } |
| 1359 | |
| 1360 | static int vidioc_s_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1361 | struct v4l2_control *ctrl) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1362 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1363 | struct cx231xx_fh *fh = priv; |
| 1364 | struct cx231xx *dev = fh->dev; |
| 1365 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1366 | |
| 1367 | rc = check_dev(dev); |
| 1368 | if (rc < 0) |
| 1369 | return rc; |
| 1370 | |
| 1371 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1372 | call_all(dev, core, s_ctrl, ctrl); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1373 | mutex_unlock(&dev->lock); |
| 1374 | return rc; |
| 1375 | } |
| 1376 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1377 | static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1378 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1379 | struct cx231xx_fh *fh = priv; |
| 1380 | struct cx231xx *dev = fh->dev; |
| 1381 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1382 | |
| 1383 | rc = check_dev(dev); |
| 1384 | if (rc < 0) |
| 1385 | return rc; |
| 1386 | |
| 1387 | if (0 != t->index) |
| 1388 | return -EINVAL; |
| 1389 | |
| 1390 | strcpy(t->name, "Tuner"); |
| 1391 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1392 | t->type = V4L2_TUNER_ANALOG_TV; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1393 | t->capability = V4L2_TUNER_CAP_NORM; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1394 | t->rangehigh = 0xffffffffUL; |
| 1395 | t->signal = 0xffff; /* LOCKED */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1396 | |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1400 | static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1401 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1402 | struct cx231xx_fh *fh = priv; |
| 1403 | struct cx231xx *dev = fh->dev; |
| 1404 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1405 | |
| 1406 | rc = check_dev(dev); |
| 1407 | if (rc < 0) |
| 1408 | return rc; |
| 1409 | |
| 1410 | if (0 != t->index) |
| 1411 | return -EINVAL; |
| 1412 | #if 0 |
| 1413 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1414 | call_all(dev, tuner, s_tuner, t); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1415 | mutex_unlock(&dev->lock); |
| 1416 | #endif |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | static int vidioc_g_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1421 | struct v4l2_frequency *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1422 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1423 | struct cx231xx_fh *fh = priv; |
| 1424 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1425 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1426 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1427 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1428 | f->frequency = dev->ctl_freq; |
| 1429 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1430 | call_all(dev, tuner, g_frequency, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1431 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1432 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
| 1437 | static int vidioc_s_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1438 | struct v4l2_frequency *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1439 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1440 | struct cx231xx_fh *fh = priv; |
| 1441 | struct cx231xx *dev = fh->dev; |
| 1442 | int rc; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1443 | u32 if_frequency = 5400000; |
| 1444 | |
| 1445 | cx231xx_info("Enter vidioc_s_frequency()f->frequency=%d;f->type=%d\n", |
| 1446 | f->frequency, f->type); |
| 1447 | /*cx231xx_info("f->type: 1-radio 2-analogTV 3-digitalTV\n");*/ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1448 | |
| 1449 | rc = check_dev(dev); |
| 1450 | if (rc < 0) |
| 1451 | return rc; |
| 1452 | |
| 1453 | if (0 != f->tuner) |
| 1454 | return -EINVAL; |
| 1455 | |
| 1456 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1457 | return -EINVAL; |
| 1458 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
| 1459 | return -EINVAL; |
| 1460 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1461 | /* set pre channel change settings in DIF first */ |
| 1462 | rc = cx231xx_tuner_pre_channel_change(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1463 | |
| 1464 | mutex_lock(&dev->lock); |
| 1465 | |
| 1466 | dev->ctl_freq = f->frequency; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1467 | call_all(dev, tuner, s_frequency, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1468 | |
| 1469 | mutex_unlock(&dev->lock); |
| 1470 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1471 | /* set post channel change settings in DIF first */ |
| 1472 | rc = cx231xx_tuner_post_channel_change(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1473 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1474 | if (dev->tuner_type == TUNER_NXP_TDA18271) { |
| 1475 | if (dev->norm & (V4L2_STD_MN | V4L2_STD_NTSC_443)) |
| 1476 | if_frequency = 5400000; /*5.4MHz */ |
| 1477 | else if (dev->norm & V4L2_STD_B) |
| 1478 | if_frequency = 6000000; /*6.0MHz */ |
| 1479 | else if (dev->norm & (V4L2_STD_PAL_DK | V4L2_STD_SECAM_DK)) |
| 1480 | if_frequency = 6900000; /*6.9MHz */ |
| 1481 | else if (dev->norm & V4L2_STD_GH) |
| 1482 | if_frequency = 7100000; /*7.1MHz */ |
| 1483 | else if (dev->norm & V4L2_STD_PAL_I) |
| 1484 | if_frequency = 7250000; /*7.25MHz */ |
| 1485 | else if (dev->norm & V4L2_STD_SECAM_L) |
| 1486 | if_frequency = 6900000; /*6.9MHz */ |
| 1487 | else if (dev->norm & V4L2_STD_SECAM_LC) |
| 1488 | if_frequency = 1250000; /*1.25MHz */ |
| 1489 | |
| 1490 | cx231xx_info("if_frequency is set to %d\n", if_frequency); |
| 1491 | cx231xx_set_Colibri_For_LowIF(dev, if_frequency, 1, 1); |
| 1492 | |
| 1493 | update_HH_register_after_set_DIF(dev); |
| 1494 | } |
| 1495 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1496 | cx231xx_info("Set New FREQUENCY to %d\n", f->frequency); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1497 | |
| 1498 | return rc; |
| 1499 | } |
| 1500 | |
| 1501 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1502 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1503 | /* |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 1504 | -R, --list-registers=type=<host/i2cdrv/i2caddr>, |
| 1505 | chip=<chip>[,min=<addr>,max=<addr>] |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1506 | dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER] |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 1507 | -r, --set-register=type=<host/i2cdrv/i2caddr>, |
| 1508 | chip=<chip>,reg=<addr>,val=<val> |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1509 | set the register [VIDIOC_DBG_S_REGISTER] |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1510 | |
| 1511 | if type == host, then <chip> is the hosts chip ID (default 0) |
| 1512 | if type == i2cdrv (default), then <chip> is the I2C driver name or ID |
| 1513 | if type == i2caddr, then <chip> is the 7-bit I2C address |
| 1514 | */ |
| 1515 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1516 | static int vidioc_g_register(struct file *file, void *priv, |
| 1517 | struct v4l2_dbg_register *reg) |
| 1518 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1519 | struct cx231xx_fh *fh = priv; |
| 1520 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1521 | int ret = 0; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1522 | u8 value[4] = { 0, 0, 0, 0 }; |
| 1523 | u32 data = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1524 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1525 | switch (reg->match.type) { |
| 1526 | case V4L2_CHIP_MATCH_HOST: |
| 1527 | switch (reg->match.addr) { |
| 1528 | case 0: /* Cx231xx - internal registers */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1529 | ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, |
| 1530 | (u16)reg->reg, value, 4); |
| 1531 | reg->val = value[0] | value[1] << 8 | |
| 1532 | value[2] << 16 | value[3] << 24; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1533 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1534 | case 1: /* AFE - read byte */ |
| 1535 | ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1536 | (u16)reg->reg, 2, &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1537 | reg->val = le32_to_cpu(data & 0xff); |
| 1538 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1539 | case 14: /* AFE - read dword */ |
| 1540 | ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1541 | (u16)reg->reg, 2, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1542 | reg->val = le32_to_cpu(data); |
| 1543 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1544 | case 2: /* Video Block - read byte */ |
| 1545 | ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1546 | (u16)reg->reg, 2, &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1547 | reg->val = le32_to_cpu(data & 0xff); |
| 1548 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1549 | case 24: /* Video Block - read dword */ |
| 1550 | ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1551 | (u16)reg->reg, 2, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1552 | reg->val = le32_to_cpu(data); |
| 1553 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1554 | case 3: /* I2S block - read byte */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1555 | ret = cx231xx_read_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1556 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1557 | (u16)reg->reg, 1, |
| 1558 | &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1559 | reg->val = le32_to_cpu(data & 0xff); |
| 1560 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1561 | case 34: /* I2S Block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1562 | ret = |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1563 | cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1564 | (u16)reg->reg, 1, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1565 | reg->val = le32_to_cpu(data); |
| 1566 | break; |
| 1567 | } |
| 1568 | return ret < 0 ? ret : 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1569 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1570 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1571 | call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1572 | return 0; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1573 | case V4L2_CHIP_MATCH_I2C_ADDR:/*for register debug*/ |
| 1574 | switch (reg->match.addr) { |
| 1575 | case 0: /* Cx231xx - internal registers */ |
| 1576 | ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, |
| 1577 | (u16)reg->reg, value, 4); |
| 1578 | reg->val = value[0] | value[1] << 8 | |
| 1579 | value[2] << 16 | value[3] << 24; |
| 1580 | |
| 1581 | break; |
| 1582 | case 0x600:/* AFE - read byte */ |
| 1583 | ret = cx231xx_read_i2c_master(dev, AFE_DEVICE_ADDRESS, |
| 1584 | (u16)reg->reg, 2, |
| 1585 | &data, 1 , 0); |
| 1586 | reg->val = le32_to_cpu(data & 0xff); |
| 1587 | break; |
| 1588 | |
| 1589 | case 0x880:/* Video Block - read byte */ |
| 1590 | if (reg->reg < 0x0b) { |
| 1591 | ret = cx231xx_read_i2c_master(dev, |
| 1592 | VID_BLK_I2C_ADDRESS, |
| 1593 | (u16)reg->reg, 2, |
| 1594 | &data, 1 , 0); |
| 1595 | reg->val = le32_to_cpu(data & 0xff); |
| 1596 | } else { |
| 1597 | ret = cx231xx_read_i2c_master(dev, |
| 1598 | VID_BLK_I2C_ADDRESS, |
| 1599 | (u16)reg->reg, 2, |
| 1600 | &data, 4 , 0); |
| 1601 | reg->val = le32_to_cpu(data); |
| 1602 | } |
| 1603 | break; |
| 1604 | case 0x980: |
| 1605 | ret = cx231xx_read_i2c_master(dev, |
| 1606 | I2S_BLK_DEVICE_ADDRESS, |
| 1607 | (u16)reg->reg, 1, |
| 1608 | &data, 1 , 0); |
| 1609 | reg->val = le32_to_cpu(data & 0xff); |
| 1610 | break; |
| 1611 | case 0x400: |
| 1612 | ret = |
| 1613 | cx231xx_read_i2c_master(dev, 0x40, |
| 1614 | (u16)reg->reg, 1, |
| 1615 | &data, 1 , 0); |
| 1616 | reg->val = le32_to_cpu(data & 0xff); |
| 1617 | break; |
| 1618 | case 0xc01: |
| 1619 | ret = |
| 1620 | cx231xx_read_i2c_master(dev, 0xc0, |
| 1621 | (u16)reg->reg, 2, |
| 1622 | &data, 38, 1); |
| 1623 | reg->val = le32_to_cpu(data); |
| 1624 | break; |
| 1625 | case 0x022: |
| 1626 | ret = |
| 1627 | cx231xx_read_i2c_master(dev, 0x02, |
| 1628 | (u16)reg->reg, 1, |
| 1629 | &data, 1, 2); |
| 1630 | reg->val = le32_to_cpu(data & 0xff); |
| 1631 | break; |
| 1632 | case 0x322: |
| 1633 | ret = cx231xx_read_i2c_master(dev, |
| 1634 | 0x32, |
| 1635 | (u16)reg->reg, 1, |
| 1636 | &data, 4 , 2); |
| 1637 | reg->val = le32_to_cpu(data); |
| 1638 | break; |
| 1639 | case 0x342: |
| 1640 | ret = cx231xx_read_i2c_master(dev, |
| 1641 | 0x34, |
| 1642 | (u16)reg->reg, 1, |
| 1643 | &data, 4 , 2); |
| 1644 | reg->val = le32_to_cpu(data); |
| 1645 | break; |
| 1646 | |
| 1647 | default: |
| 1648 | cx231xx_info("no match device address!!\n"); |
| 1649 | break; |
| 1650 | } |
| 1651 | return ret < 0 ? ret : 0; |
| 1652 | /*return -EINVAL;*/ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1653 | default: |
| 1654 | if (!v4l2_chip_match_host(®->match)) |
| 1655 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1656 | } |
| 1657 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1658 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1659 | call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1660 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1661 | |
| 1662 | return ret; |
| 1663 | } |
| 1664 | |
| 1665 | static int vidioc_s_register(struct file *file, void *priv, |
| 1666 | struct v4l2_dbg_register *reg) |
| 1667 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1668 | struct cx231xx_fh *fh = priv; |
| 1669 | struct cx231xx *dev = fh->dev; |
| 1670 | int ret = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1671 | __le64 buf; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1672 | u32 value; |
| 1673 | u8 data[4] = { 0, 0, 0, 0 }; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1674 | |
| 1675 | buf = cpu_to_le64(reg->val); |
| 1676 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1677 | switch (reg->match.type) { |
| 1678 | case V4L2_CHIP_MATCH_HOST: |
| 1679 | { |
| 1680 | value = (u32) buf & 0xffffffff; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1681 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1682 | switch (reg->match.addr) { |
| 1683 | case 0: /* cx231xx internal registers */ |
| 1684 | data[0] = (u8) value; |
| 1685 | data[1] = (u8) (value >> 8); |
| 1686 | data[2] = (u8) (value >> 16); |
| 1687 | data[3] = (u8) (value >> 24); |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1688 | ret = cx231xx_write_ctrl_reg(dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1689 | VRT_SET_REGISTER, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1690 | (u16)reg->reg, data, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1691 | 4); |
| 1692 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1693 | case 1: /* AFE - read byte */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1694 | ret = cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1695 | AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1696 | (u16)reg->reg, 2, |
| 1697 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1698 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1699 | case 14: /* AFE - read dword */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1700 | ret = cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1701 | AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1702 | (u16)reg->reg, 2, |
| 1703 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1704 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1705 | case 2: /* Video Block - read byte */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1706 | ret = |
| 1707 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1708 | VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1709 | (u16)reg->reg, 2, |
| 1710 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1711 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1712 | case 24: /* Video Block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1713 | ret = |
| 1714 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1715 | VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1716 | (u16)reg->reg, 2, |
| 1717 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1718 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1719 | case 3: /* I2S block - read byte */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1720 | ret = |
| 1721 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1722 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1723 | (u16)reg->reg, 1, |
| 1724 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1725 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1726 | case 34: /* I2S block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1727 | ret = |
| 1728 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1729 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1730 | (u16)reg->reg, 1, |
| 1731 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | } |
| 1735 | return ret < 0 ? ret : 0; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1736 | case V4L2_CHIP_MATCH_I2C_ADDR: |
| 1737 | { |
| 1738 | value = (u32) buf & 0xffffffff; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1739 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1740 | switch (reg->match.addr) { |
| 1741 | case 0:/*cx231xx internal registers*/ |
| 1742 | data[0] = (u8) value; |
| 1743 | data[1] = (u8) (value >> 8); |
| 1744 | data[2] = (u8) (value >> 16); |
| 1745 | data[3] = (u8) (value >> 24); |
| 1746 | ret = cx231xx_write_ctrl_reg(dev, |
| 1747 | VRT_SET_REGISTER, |
| 1748 | (u16)reg->reg, data, |
| 1749 | 4); |
| 1750 | break; |
| 1751 | case 0x600:/* AFE - read byte */ |
| 1752 | ret = cx231xx_write_i2c_master(dev, |
| 1753 | AFE_DEVICE_ADDRESS, |
| 1754 | (u16)reg->reg, 2, |
| 1755 | value, 1 , 0); |
| 1756 | break; |
| 1757 | |
| 1758 | case 0x880:/* Video Block - read byte */ |
| 1759 | if (reg->reg < 0x0b) |
| 1760 | cx231xx_write_i2c_master(dev, |
| 1761 | VID_BLK_I2C_ADDRESS, |
| 1762 | (u16)reg->reg, 2, |
| 1763 | value, 1, 0); |
| 1764 | else |
| 1765 | cx231xx_write_i2c_master(dev, |
| 1766 | VID_BLK_I2C_ADDRESS, |
| 1767 | (u16)reg->reg, 2, |
| 1768 | value, 4, 0); |
| 1769 | break; |
| 1770 | case 0x980: |
| 1771 | ret = |
| 1772 | cx231xx_write_i2c_master(dev, |
| 1773 | I2S_BLK_DEVICE_ADDRESS, |
| 1774 | (u16)reg->reg, 1, |
| 1775 | value, 1, 0); |
| 1776 | break; |
| 1777 | case 0x400: |
| 1778 | ret = |
| 1779 | cx231xx_write_i2c_master(dev, |
| 1780 | 0x40, |
| 1781 | (u16)reg->reg, 1, |
| 1782 | value, 1, 0); |
| 1783 | break; |
| 1784 | case 0xc01: |
| 1785 | ret = |
| 1786 | cx231xx_write_i2c_master(dev, |
| 1787 | 0xc0, |
| 1788 | (u16)reg->reg, 1, |
| 1789 | value, 1, 1); |
| 1790 | break; |
| 1791 | |
| 1792 | case 0x022: |
| 1793 | ret = |
| 1794 | cx231xx_write_i2c_master(dev, |
| 1795 | 0x02, |
| 1796 | (u16)reg->reg, 1, |
| 1797 | value, 1, 2); |
| 1798 | case 0x322: |
| 1799 | ret = |
| 1800 | cx231xx_write_i2c_master(dev, |
| 1801 | 0x32, |
| 1802 | (u16)reg->reg, 1, |
| 1803 | value, 4, 2); |
| 1804 | break; |
| 1805 | |
| 1806 | case 0x342: |
| 1807 | ret = |
| 1808 | cx231xx_write_i2c_master(dev, |
| 1809 | 0x34, |
| 1810 | (u16)reg->reg, 1, |
| 1811 | value, 4, 2); |
| 1812 | break; |
| 1813 | default: |
| 1814 | cx231xx_info("no match device address, " |
| 1815 | "the value is %x\n", reg->match.addr); |
| 1816 | break; |
| 1817 | |
| 1818 | } |
| 1819 | |
| 1820 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1821 | default: |
| 1822 | break; |
| 1823 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1824 | |
| 1825 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1826 | call_all(dev, core, s_register, reg); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1827 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1828 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1829 | return ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1830 | } |
| 1831 | #endif |
| 1832 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1833 | static int vidioc_cropcap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1834 | struct v4l2_cropcap *cc) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1835 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1836 | struct cx231xx_fh *fh = priv; |
| 1837 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1838 | |
| 1839 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1840 | return -EINVAL; |
| 1841 | |
| 1842 | cc->bounds.left = 0; |
| 1843 | cc->bounds.top = 0; |
| 1844 | cc->bounds.width = dev->width; |
| 1845 | cc->bounds.height = dev->height; |
| 1846 | cc->defrect = cc->bounds; |
| 1847 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1848 | cc->pixelaspect.denominator = 59; |
| 1849 | |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | static int vidioc_streamon(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1854 | enum v4l2_buf_type type) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1855 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1856 | struct cx231xx_fh *fh = priv; |
| 1857 | struct cx231xx *dev = fh->dev; |
| 1858 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1859 | |
| 1860 | rc = check_dev(dev); |
| 1861 | if (rc < 0) |
| 1862 | return rc; |
| 1863 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1864 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1865 | rc = res_get(fh); |
| 1866 | |
| 1867 | if (likely(rc >= 0)) |
| 1868 | rc = videobuf_streamon(&fh->vb_vidq); |
| 1869 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1870 | call_all(dev, video, s_stream, 1); |
| 1871 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1872 | mutex_unlock(&dev->lock); |
| 1873 | |
| 1874 | return rc; |
| 1875 | } |
| 1876 | |
| 1877 | static int vidioc_streamoff(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1878 | enum v4l2_buf_type type) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1879 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1880 | struct cx231xx_fh *fh = priv; |
| 1881 | struct cx231xx *dev = fh->dev; |
| 1882 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1883 | |
| 1884 | rc = check_dev(dev); |
| 1885 | if (rc < 0) |
| 1886 | return rc; |
| 1887 | |
Mauro Carvalho Chehab | 92fcbd3 | 2009-03-21 22:16:34 -0300 | [diff] [blame] | 1888 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1889 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1890 | return -EINVAL; |
| 1891 | if (type != fh->type) |
| 1892 | return -EINVAL; |
| 1893 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1894 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1895 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1896 | cx25840_call(dev, video, s_stream, 0); |
| 1897 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1898 | videobuf_streamoff(&fh->vb_vidq); |
| 1899 | res_free(fh); |
| 1900 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1901 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1902 | |
| 1903 | return 0; |
| 1904 | } |
| 1905 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1906 | static int vidioc_querycap(struct file *file, void *priv, |
| 1907 | struct v4l2_capability *cap) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1908 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1909 | struct cx231xx_fh *fh = priv; |
| 1910 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1911 | |
| 1912 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); |
| 1913 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); |
Mauro Carvalho Chehab | 2c6beca | 2009-03-22 08:53:36 -0300 | [diff] [blame] | 1914 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1915 | |
| 1916 | cap->version = CX231XX_VERSION_CODE; |
| 1917 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1918 | cap->capabilities = V4L2_CAP_VBI_CAPTURE | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1919 | #if 0 |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 1920 | V4L2_CAP_SLICED_VBI_CAPTURE | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1921 | #endif |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 1922 | V4L2_CAP_VIDEO_CAPTURE | |
| 1923 | V4L2_CAP_AUDIO | |
| 1924 | V4L2_CAP_READWRITE | |
| 1925 | V4L2_CAP_STREAMING; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1926 | |
| 1927 | if (dev->tuner_type != TUNER_ABSENT) |
| 1928 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1929 | |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1933 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 1934 | struct v4l2_fmtdesc *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1935 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1936 | if (unlikely(f->index >= ARRAY_SIZE(format))) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1937 | return -EINVAL; |
| 1938 | |
| 1939 | strlcpy(f->description, format[f->index].name, sizeof(f->description)); |
| 1940 | f->pixelformat = format[f->index].fourcc; |
| 1941 | |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
| 1945 | /* Sliced VBI ioctls */ |
| 1946 | static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1947 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1948 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1949 | struct cx231xx_fh *fh = priv; |
| 1950 | struct cx231xx *dev = fh->dev; |
| 1951 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1952 | |
| 1953 | rc = check_dev(dev); |
| 1954 | if (rc < 0) |
| 1955 | return rc; |
| 1956 | |
| 1957 | mutex_lock(&dev->lock); |
| 1958 | |
| 1959 | f->fmt.sliced.service_set = 0; |
| 1960 | |
Hans Verkuil | 7e87ddb | 2010-03-14 12:31:08 -0300 | [diff] [blame] | 1961 | call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1962 | |
| 1963 | if (f->fmt.sliced.service_set == 0) |
| 1964 | rc = -EINVAL; |
| 1965 | |
| 1966 | mutex_unlock(&dev->lock); |
| 1967 | return rc; |
| 1968 | } |
| 1969 | |
| 1970 | static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1971 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1972 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1973 | struct cx231xx_fh *fh = priv; |
| 1974 | struct cx231xx *dev = fh->dev; |
| 1975 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1976 | |
| 1977 | rc = check_dev(dev); |
| 1978 | if (rc < 0) |
| 1979 | return rc; |
| 1980 | |
| 1981 | mutex_lock(&dev->lock); |
Hans Verkuil | 7e87ddb | 2010-03-14 12:31:08 -0300 | [diff] [blame] | 1982 | call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1983 | mutex_unlock(&dev->lock); |
| 1984 | |
| 1985 | if (f->fmt.sliced.service_set == 0) |
| 1986 | return -EINVAL; |
| 1987 | |
| 1988 | return 0; |
| 1989 | } |
| 1990 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1991 | /* RAW VBI ioctls */ |
| 1992 | |
| 1993 | static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1994 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1995 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1996 | struct cx231xx_fh *fh = priv; |
| 1997 | struct cx231xx *dev = fh->dev; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 1998 | f->fmt.vbi.sampling_rate = 6750000 * 4; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1999 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
| 2000 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 2001 | f->fmt.vbi.offset = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2002 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2003 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2004 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2005 | PAL_VBI_LINES : NTSC_VBI_LINES; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2006 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2007 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2008 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
| 2009 | |
| 2010 | return 0; |
| 2011 | |
| 2012 | } |
| 2013 | |
| 2014 | static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2015 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2016 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2017 | struct cx231xx_fh *fh = priv; |
| 2018 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2019 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2020 | if (dev->vbi_stream_on && !fh->stream_on) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2021 | cx231xx_errdev("%s device in use by another fh\n", __func__); |
| 2022 | return -EBUSY; |
| 2023 | } |
| 2024 | |
| 2025 | f->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 2026 | f->fmt.vbi.sampling_rate = 6750000 * 4; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2027 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
| 2028 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 2029 | f->fmt.vbi.offset = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2030 | f->fmt.vbi.flags = 0; |
| 2031 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2032 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2033 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2034 | PAL_VBI_LINES : NTSC_VBI_LINES; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2035 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2036 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2037 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
| 2038 | |
| 2039 | return 0; |
| 2040 | |
| 2041 | } |
| 2042 | |
| 2043 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 2044 | struct v4l2_requestbuffers *rb) |
| 2045 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2046 | struct cx231xx_fh *fh = priv; |
| 2047 | struct cx231xx *dev = fh->dev; |
| 2048 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2049 | |
| 2050 | rc = check_dev(dev); |
| 2051 | if (rc < 0) |
| 2052 | return rc; |
| 2053 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2054 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2055 | } |
| 2056 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2057 | static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2058 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2059 | struct cx231xx_fh *fh = priv; |
| 2060 | struct cx231xx *dev = fh->dev; |
| 2061 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2062 | |
| 2063 | rc = check_dev(dev); |
| 2064 | if (rc < 0) |
| 2065 | return rc; |
| 2066 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2067 | return videobuf_querybuf(&fh->vb_vidq, b); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 2071 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2072 | struct cx231xx_fh *fh = priv; |
| 2073 | struct cx231xx *dev = fh->dev; |
| 2074 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2075 | |
| 2076 | rc = check_dev(dev); |
| 2077 | if (rc < 0) |
| 2078 | return rc; |
| 2079 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2080 | return videobuf_qbuf(&fh->vb_vidq, b); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 2084 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2085 | struct cx231xx_fh *fh = priv; |
| 2086 | struct cx231xx *dev = fh->dev; |
| 2087 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2088 | |
| 2089 | rc = check_dev(dev); |
| 2090 | if (rc < 0) |
| 2091 | return rc; |
| 2092 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2093 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 2097 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
| 2098 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2099 | struct cx231xx_fh *fh = priv; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2100 | |
| 2101 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
| 2102 | } |
| 2103 | #endif |
| 2104 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2105 | /* ----------------------------------------------------------- */ |
| 2106 | /* RADIO ESPECIFIC IOCTLS */ |
| 2107 | /* ----------------------------------------------------------- */ |
| 2108 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2109 | static int radio_querycap(struct file *file, void *priv, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2110 | struct v4l2_capability *cap) |
| 2111 | { |
| 2112 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2113 | |
| 2114 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); |
| 2115 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); |
| 2116 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
| 2117 | |
| 2118 | cap->version = CX231XX_VERSION_CODE; |
| 2119 | cap->capabilities = V4L2_CAP_TUNER; |
| 2120 | return 0; |
| 2121 | } |
| 2122 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2123 | static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2124 | { |
| 2125 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2126 | |
| 2127 | if (unlikely(t->index > 0)) |
| 2128 | return -EINVAL; |
| 2129 | |
| 2130 | strcpy(t->name, "Radio"); |
| 2131 | t->type = V4L2_TUNER_RADIO; |
| 2132 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2133 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2134 | call_all(dev, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2135 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2136 | |
| 2137 | return 0; |
| 2138 | } |
| 2139 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2140 | static int radio_enum_input(struct file *file, void *priv, struct v4l2_input *i) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2141 | { |
| 2142 | if (i->index != 0) |
| 2143 | return -EINVAL; |
| 2144 | strcpy(i->name, "Radio"); |
| 2145 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 2146 | |
| 2147 | return 0; |
| 2148 | } |
| 2149 | |
| 2150 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 2151 | { |
| 2152 | if (unlikely(a->index)) |
| 2153 | return -EINVAL; |
| 2154 | |
| 2155 | strcpy(a->name, "Radio"); |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2159 | static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2160 | { |
| 2161 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2162 | |
| 2163 | if (0 != t->index) |
| 2164 | return -EINVAL; |
| 2165 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2166 | mutex_lock(&dev->lock); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2167 | call_all(dev, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2168 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2169 | |
| 2170 | return 0; |
| 2171 | } |
| 2172 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2173 | static int radio_s_audio(struct file *file, void *fh, struct v4l2_audio *a) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2174 | { |
| 2175 | return 0; |
| 2176 | } |
| 2177 | |
| 2178 | static int radio_s_input(struct file *file, void *fh, unsigned int i) |
| 2179 | { |
| 2180 | return 0; |
| 2181 | } |
| 2182 | |
| 2183 | static int radio_queryctrl(struct file *file, void *priv, |
| 2184 | struct v4l2_queryctrl *c) |
| 2185 | { |
| 2186 | int i; |
| 2187 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2188 | if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2189 | return -EINVAL; |
| 2190 | if (c->id == V4L2_CID_AUDIO_MUTE) { |
Dan Carpenter | 8e47567 | 2010-04-02 08:30:10 -0300 | [diff] [blame] | 2191 | for (i = 0; i < CX231XX_CTLS; i++) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2192 | if (cx231xx_ctls[i].v.id == c->id) |
| 2193 | break; |
Dan Carpenter | 8e47567 | 2010-04-02 08:30:10 -0300 | [diff] [blame] | 2194 | } |
| 2195 | if (i == CX231XX_CTLS) |
| 2196 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2197 | *c = cx231xx_ctls[i].v; |
| 2198 | } else |
| 2199 | *c = no_ctl; |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | /* |
| 2204 | * cx231xx_v4l2_open() |
| 2205 | * inits the device and starts isoc transfer |
| 2206 | */ |
| 2207 | static int cx231xx_v4l2_open(struct file *filp) |
| 2208 | { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2209 | int errCode = 0, radio = 0; |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2210 | struct video_device *vdev = video_devdata(filp); |
| 2211 | struct cx231xx *dev = video_drvdata(filp); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2212 | struct cx231xx_fh *fh; |
| 2213 | enum v4l2_buf_type fh_type = 0; |
| 2214 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2215 | switch (vdev->vfl_type) { |
| 2216 | case VFL_TYPE_GRABBER: |
| 2217 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 2218 | break; |
| 2219 | case VFL_TYPE_VBI: |
| 2220 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 2221 | break; |
| 2222 | case VFL_TYPE_RADIO: |
| 2223 | radio = 1; |
| 2224 | break; |
| 2225 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2226 | |
| 2227 | mutex_lock(&dev->lock); |
| 2228 | |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 2229 | cx231xx_videodbg("open dev=%s type=%s users=%d\n", |
| 2230 | video_device_node_name(vdev), v4l2_type_names[fh_type], |
| 2231 | dev->users); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2232 | |
| 2233 | #if 0 |
| 2234 | errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 2235 | if (errCode < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2236 | cx231xx_errdev |
| 2237 | ("Device locked on digital mode. Can't open analog\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2238 | mutex_unlock(&dev->lock); |
| 2239 | return -EBUSY; |
| 2240 | } |
| 2241 | #endif |
| 2242 | |
| 2243 | fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL); |
| 2244 | if (!fh) { |
| 2245 | cx231xx_errdev("cx231xx-video.c: Out of memory?!\n"); |
| 2246 | mutex_unlock(&dev->lock); |
| 2247 | return -ENOMEM; |
| 2248 | } |
| 2249 | fh->dev = dev; |
| 2250 | fh->radio = radio; |
| 2251 | fh->type = fh_type; |
| 2252 | filp->private_data = fh; |
| 2253 | |
| 2254 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
| 2255 | dev->width = norm_maxw(dev); |
| 2256 | dev->height = norm_maxh(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2257 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2258 | /* Power up in Analog TV mode */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2259 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) |
| 2260 | cx231xx_set_power_mode(dev, |
| 2261 | POLARIS_AVMODE_ENXTERNAL_AV); |
| 2262 | else |
| 2263 | cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2264 | |
| 2265 | #if 0 |
| 2266 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 2267 | #endif |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2268 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2269 | /* set video alternate setting */ |
| 2270 | cx231xx_set_video_alternate(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2271 | |
| 2272 | /* Needed, since GPIO might have disabled power of |
| 2273 | some i2c device */ |
| 2274 | cx231xx_config_i2c(dev); |
| 2275 | |
| 2276 | /* device needs to be initialized before isoc transfer */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2277 | dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2278 | |
| 2279 | } |
| 2280 | if (fh->radio) { |
| 2281 | cx231xx_videodbg("video_open: setting radio device\n"); |
| 2282 | |
| 2283 | /* cx231xx_start_radio(dev); */ |
| 2284 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2285 | call_all(dev, tuner, s_radio); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | dev->users++; |
| 2289 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2290 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 2291 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, |
| 2292 | NULL, &dev->video_mode.slock, |
| 2293 | fh->type, V4L2_FIELD_INTERLACED, |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 2294 | sizeof(struct cx231xx_buffer), |
| 2295 | fh, NULL); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2296 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2297 | /* Set the required alternate setting VBI interface works in |
| 2298 | Bulk mode only */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2299 | if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER) |
| 2300 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2301 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2302 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, |
| 2303 | NULL, &dev->vbi_mode.slock, |
| 2304 | fh->type, V4L2_FIELD_SEQ_TB, |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 2305 | sizeof(struct cx231xx_buffer), |
| 2306 | fh, NULL); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2307 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2308 | |
| 2309 | mutex_unlock(&dev->lock); |
| 2310 | |
| 2311 | return errCode; |
| 2312 | } |
| 2313 | |
| 2314 | /* |
| 2315 | * cx231xx_realease_resources() |
| 2316 | * unregisters the v4l2,i2c and usb devices |
| 2317 | * called when the device gets disconected or at module unload |
| 2318 | */ |
| 2319 | void cx231xx_release_analog_resources(struct cx231xx *dev) |
| 2320 | { |
| 2321 | |
| 2322 | /*FIXME: I2C IR should be disconnected */ |
| 2323 | |
| 2324 | if (dev->radio_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2325 | if (video_is_registered(dev->radio_dev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2326 | video_unregister_device(dev->radio_dev); |
| 2327 | else |
| 2328 | video_device_release(dev->radio_dev); |
| 2329 | dev->radio_dev = NULL; |
| 2330 | } |
| 2331 | if (dev->vbi_dev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2332 | cx231xx_info("V4L2 device %s deregistered\n", |
| 2333 | video_device_node_name(dev->vbi_dev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2334 | if (video_is_registered(dev->vbi_dev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2335 | video_unregister_device(dev->vbi_dev); |
| 2336 | else |
| 2337 | video_device_release(dev->vbi_dev); |
| 2338 | dev->vbi_dev = NULL; |
| 2339 | } |
| 2340 | if (dev->vdev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2341 | cx231xx_info("V4L2 device %s deregistered\n", |
| 2342 | video_device_node_name(dev->vdev)); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2343 | |
| 2344 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) |
| 2345 | cx231xx_417_unregister(dev); |
| 2346 | |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2347 | if (video_is_registered(dev->vdev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2348 | video_unregister_device(dev->vdev); |
| 2349 | else |
| 2350 | video_device_release(dev->vdev); |
| 2351 | dev->vdev = NULL; |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | /* |
| 2356 | * cx231xx_v4l2_close() |
| 2357 | * stops streaming and deallocates all resources allocated by the v4l2 |
| 2358 | * calls and ioctls |
| 2359 | */ |
| 2360 | static int cx231xx_v4l2_close(struct file *filp) |
| 2361 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2362 | struct cx231xx_fh *fh = filp->private_data; |
| 2363 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2364 | |
| 2365 | cx231xx_videodbg("users=%d\n", dev->users); |
| 2366 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2367 | mutex_lock(&dev->lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2368 | cx231xx_videodbg("users=%d\n", dev->users); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2369 | if (res_check(fh)) |
| 2370 | res_free(fh); |
| 2371 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2372 | /*To workaround error number=-71 on EP0 for VideoGrabber, |
| 2373 | need exclude following.*/ |
| 2374 | if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER) |
| 2375 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
| 2376 | videobuf_stop(&fh->vb_vidq); |
| 2377 | videobuf_mmap_free(&fh->vb_vidq); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2378 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2379 | /* the device is already disconnect, |
| 2380 | free the remaining resources */ |
| 2381 | if (dev->state & DEV_DISCONNECTED) { |
| 2382 | if (atomic_read(&dev->devlist_count) > 0) { |
| 2383 | cx231xx_release_resources(dev); |
| 2384 | mutex_unlock(&dev->lock); |
| 2385 | kfree(dev); |
| 2386 | dev = NULL; |
| 2387 | return 0; |
| 2388 | } |
| 2389 | mutex_unlock(&dev->lock); |
| 2390 | return 0; |
| 2391 | } |
| 2392 | |
| 2393 | /* do this before setting alternate! */ |
| 2394 | cx231xx_uninit_vbi_isoc(dev); |
| 2395 | |
| 2396 | /* set alternate 0 */ |
| 2397 | if (!dev->vbi_or_sliced_cc_mode) |
| 2398 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
| 2399 | else |
| 2400 | cx231xx_set_alt_setting(dev, INDEX_HANC, 0); |
| 2401 | |
| 2402 | kfree(fh); |
| 2403 | dev->users--; |
| 2404 | wake_up_interruptible_nr(&dev->open, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2405 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2406 | return 0; |
| 2407 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2408 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2409 | if (dev->users == 1) { |
| 2410 | videobuf_stop(&fh->vb_vidq); |
| 2411 | videobuf_mmap_free(&fh->vb_vidq); |
| 2412 | |
| 2413 | /* the device is already disconnect, |
| 2414 | free the remaining resources */ |
| 2415 | if (dev->state & DEV_DISCONNECTED) { |
| 2416 | cx231xx_release_resources(dev); |
| 2417 | mutex_unlock(&dev->lock); |
| 2418 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2419 | dev = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2420 | return 0; |
| 2421 | } |
| 2422 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2423 | /* Save some power by putting tuner to sleep */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 2424 | call_all(dev, core, s_power, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2425 | |
| 2426 | /* do this before setting alternate! */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2427 | if (dev->USE_ISO) |
| 2428 | cx231xx_uninit_isoc(dev); |
| 2429 | else |
| 2430 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2431 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 2432 | |
| 2433 | /* set alternate 0 */ |
| 2434 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); |
| 2435 | } |
| 2436 | kfree(fh); |
| 2437 | dev->users--; |
| 2438 | wake_up_interruptible_nr(&dev->open, 1); |
| 2439 | mutex_unlock(&dev->lock); |
| 2440 | return 0; |
| 2441 | } |
| 2442 | |
| 2443 | /* |
| 2444 | * cx231xx_v4l2_read() |
| 2445 | * will allocate buffers when called for the first time |
| 2446 | */ |
| 2447 | static ssize_t |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2448 | cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count, |
| 2449 | loff_t *pos) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2450 | { |
| 2451 | struct cx231xx_fh *fh = filp->private_data; |
| 2452 | struct cx231xx *dev = fh->dev; |
| 2453 | int rc; |
| 2454 | |
| 2455 | rc = check_dev(dev); |
| 2456 | if (rc < 0) |
| 2457 | return rc; |
| 2458 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2459 | if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) || |
| 2460 | (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2461 | mutex_lock(&dev->lock); |
| 2462 | rc = res_get(fh); |
| 2463 | mutex_unlock(&dev->lock); |
| 2464 | |
| 2465 | if (unlikely(rc < 0)) |
| 2466 | return rc; |
| 2467 | |
| 2468 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2469 | filp->f_flags & O_NONBLOCK); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2470 | } |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
| 2474 | /* |
| 2475 | * cx231xx_v4l2_poll() |
| 2476 | * will allocate buffers when called for the first time |
| 2477 | */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2478 | static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2479 | { |
| 2480 | struct cx231xx_fh *fh = filp->private_data; |
| 2481 | struct cx231xx *dev = fh->dev; |
| 2482 | int rc; |
| 2483 | |
| 2484 | rc = check_dev(dev); |
| 2485 | if (rc < 0) |
| 2486 | return rc; |
| 2487 | |
| 2488 | mutex_lock(&dev->lock); |
| 2489 | rc = res_get(fh); |
| 2490 | mutex_unlock(&dev->lock); |
| 2491 | |
| 2492 | if (unlikely(rc < 0)) |
| 2493 | return POLLERR; |
| 2494 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2495 | if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) || |
| 2496 | (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) |
| 2497 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
| 2498 | else |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2499 | return POLLERR; |
| 2500 | } |
| 2501 | |
| 2502 | /* |
| 2503 | * cx231xx_v4l2_mmap() |
| 2504 | */ |
| 2505 | static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) |
| 2506 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2507 | struct cx231xx_fh *fh = filp->private_data; |
| 2508 | struct cx231xx *dev = fh->dev; |
| 2509 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2510 | |
| 2511 | rc = check_dev(dev); |
| 2512 | if (rc < 0) |
| 2513 | return rc; |
| 2514 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2515 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2516 | rc = res_get(fh); |
| 2517 | mutex_unlock(&dev->lock); |
| 2518 | |
| 2519 | if (unlikely(rc < 0)) |
| 2520 | return rc; |
| 2521 | |
| 2522 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
| 2523 | |
| 2524 | cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2525 | (unsigned long)vma->vm_start, |
| 2526 | (unsigned long)vma->vm_end - |
| 2527 | (unsigned long)vma->vm_start, rc); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2528 | |
| 2529 | return rc; |
| 2530 | } |
| 2531 | |
| 2532 | static const struct v4l2_file_operations cx231xx_v4l_fops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2533 | .owner = THIS_MODULE, |
| 2534 | .open = cx231xx_v4l2_open, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2535 | .release = cx231xx_v4l2_close, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2536 | .read = cx231xx_v4l2_read, |
| 2537 | .poll = cx231xx_v4l2_poll, |
| 2538 | .mmap = cx231xx_v4l2_mmap, |
| 2539 | .ioctl = video_ioctl2, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2540 | }; |
| 2541 | |
| 2542 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2543 | .vidioc_querycap = vidioc_querycap, |
| 2544 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 2545 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 2546 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 2547 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 2548 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
| 2549 | .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, |
| 2550 | .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, |
| 2551 | .vidioc_g_audio = vidioc_g_audio, |
| 2552 | .vidioc_s_audio = vidioc_s_audio, |
| 2553 | .vidioc_cropcap = vidioc_cropcap, |
| 2554 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2555 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2556 | .vidioc_reqbufs = vidioc_reqbufs, |
| 2557 | .vidioc_querybuf = vidioc_querybuf, |
| 2558 | .vidioc_qbuf = vidioc_qbuf, |
| 2559 | .vidioc_dqbuf = vidioc_dqbuf, |
| 2560 | .vidioc_s_std = vidioc_s_std, |
| 2561 | .vidioc_g_std = vidioc_g_std, |
| 2562 | .vidioc_enum_input = vidioc_enum_input, |
| 2563 | .vidioc_g_input = vidioc_g_input, |
| 2564 | .vidioc_s_input = vidioc_s_input, |
| 2565 | .vidioc_queryctrl = vidioc_queryctrl, |
| 2566 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2567 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2568 | .vidioc_streamon = vidioc_streamon, |
| 2569 | .vidioc_streamoff = vidioc_streamoff, |
| 2570 | .vidioc_g_tuner = vidioc_g_tuner, |
| 2571 | .vidioc_s_tuner = vidioc_s_tuner, |
| 2572 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2573 | .vidioc_s_frequency = vidioc_s_frequency, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2574 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2575 | .vidioc_g_register = vidioc_g_register, |
| 2576 | .vidioc_s_register = vidioc_s_register, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2577 | #endif |
| 2578 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2579 | .vidiocgmbuf = vidiocgmbuf, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2580 | #endif |
| 2581 | }; |
| 2582 | |
| 2583 | static struct video_device cx231xx_vbi_template; |
| 2584 | |
| 2585 | static const struct video_device cx231xx_video_template = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2586 | .fops = &cx231xx_v4l_fops, |
| 2587 | .release = video_device_release, |
| 2588 | .ioctl_ops = &video_ioctl_ops, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2589 | .tvnorms = V4L2_STD_ALL, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2590 | .current_norm = V4L2_STD_PAL, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | static const struct v4l2_file_operations radio_fops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2594 | .owner = THIS_MODULE, |
| 2595 | .open = cx231xx_v4l2_open, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2596 | .release = cx231xx_v4l2_close, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2597 | .ioctl = video_ioctl2, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2598 | }; |
| 2599 | |
| 2600 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2601 | .vidioc_querycap = radio_querycap, |
| 2602 | .vidioc_g_tuner = radio_g_tuner, |
| 2603 | .vidioc_enum_input = radio_enum_input, |
| 2604 | .vidioc_g_audio = radio_g_audio, |
| 2605 | .vidioc_s_tuner = radio_s_tuner, |
| 2606 | .vidioc_s_audio = radio_s_audio, |
| 2607 | .vidioc_s_input = radio_s_input, |
| 2608 | .vidioc_queryctrl = radio_queryctrl, |
| 2609 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2610 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2611 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2612 | .vidioc_s_frequency = vidioc_s_frequency, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2613 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2614 | .vidioc_g_register = vidioc_g_register, |
| 2615 | .vidioc_s_register = vidioc_s_register, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2616 | #endif |
| 2617 | }; |
| 2618 | |
| 2619 | static struct video_device cx231xx_radio_template = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2620 | .name = "cx231xx-radio", |
| 2621 | .fops = &radio_fops, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2622 | .ioctl_ops = &radio_ioctl_ops, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2623 | }; |
| 2624 | |
| 2625 | /******************************** usb interface ******************************/ |
| 2626 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 2627 | static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, |
| 2628 | const struct video_device |
| 2629 | *template, const char *type_name) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2630 | { |
| 2631 | struct video_device *vfd; |
| 2632 | |
| 2633 | vfd = video_device_alloc(); |
| 2634 | if (NULL == vfd) |
| 2635 | return NULL; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2636 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2637 | *vfd = *template; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2638 | vfd->v4l2_dev = &dev->v4l2_dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2639 | vfd->release = video_device_release; |
| 2640 | vfd->debug = video_debug; |
| 2641 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2642 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2643 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2644 | video_set_drvdata(vfd, dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2645 | return vfd; |
| 2646 | } |
| 2647 | |
| 2648 | int cx231xx_register_analog_devices(struct cx231xx *dev) |
| 2649 | { |
| 2650 | int ret; |
| 2651 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2652 | cx231xx_info("%s: v4l2 driver version %d.%d.%d\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2653 | dev->name, |
| 2654 | (CX231XX_VERSION_CODE >> 16) & 0xff, |
| 2655 | (CX231XX_VERSION_CODE >> 8) & 0xff, |
| 2656 | CX231XX_VERSION_CODE & 0xff); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2657 | |
| 2658 | /* set default norm */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2659 | /*dev->norm = cx231xx_video_template.current_norm; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2660 | dev->width = norm_maxw(dev); |
| 2661 | dev->height = norm_maxh(dev); |
| 2662 | dev->interlaced = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2663 | |
| 2664 | /* Analog specific initialization */ |
| 2665 | dev->format = &format[0]; |
Devin Heitmueller | 6e6a2ba | 2010-07-12 15:34:57 -0300 | [diff] [blame] | 2666 | |
| 2667 | /* Set the initial input */ |
| 2668 | video_mux(dev, dev->video_input); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2669 | |
| 2670 | /* Audio defaults */ |
| 2671 | dev->mute = 1; |
| 2672 | dev->volume = 0x1f; |
| 2673 | |
| 2674 | /* enable vbi capturing */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2675 | /* write code here... */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2676 | |
| 2677 | /* allocate and fill video video_device struct */ |
| 2678 | dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video"); |
| 2679 | if (!dev->vdev) { |
| 2680 | cx231xx_errdev("cannot allocate video_device.\n"); |
| 2681 | return -ENODEV; |
| 2682 | } |
| 2683 | |
| 2684 | /* register v4l2 video video_device */ |
| 2685 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2686 | video_nr[dev->devno]); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2687 | if (ret) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2688 | cx231xx_errdev("unable to register video device (error=%i).\n", |
| 2689 | ret); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2690 | return ret; |
| 2691 | } |
| 2692 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2693 | cx231xx_info("%s/0: registered device %s [v4l2]\n", |
| 2694 | dev->name, video_device_node_name(dev->vdev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2695 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2696 | /* Initialize VBI template */ |
| 2697 | memcpy(&cx231xx_vbi_template, &cx231xx_video_template, |
| 2698 | sizeof(cx231xx_vbi_template)); |
| 2699 | strcpy(cx231xx_vbi_template.name, "cx231xx-vbi"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2700 | |
| 2701 | /* Allocate and fill vbi video_device struct */ |
| 2702 | dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi"); |
| 2703 | |
| 2704 | /* register v4l2 vbi video_device */ |
| 2705 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2706 | vbi_nr[dev->devno]); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2707 | if (ret < 0) { |
| 2708 | cx231xx_errdev("unable to register vbi device\n"); |
| 2709 | return ret; |
| 2710 | } |
| 2711 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2712 | cx231xx_info("%s/0: registered device %s\n", |
| 2713 | dev->name, video_device_node_name(dev->vbi_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2714 | |
| 2715 | if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2716 | dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template, |
| 2717 | "radio"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2718 | if (!dev->radio_dev) { |
| 2719 | cx231xx_errdev("cannot allocate video_device.\n"); |
| 2720 | return -ENODEV; |
| 2721 | } |
| 2722 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, |
| 2723 | radio_nr[dev->devno]); |
| 2724 | if (ret < 0) { |
| 2725 | cx231xx_errdev("can't register radio device\n"); |
| 2726 | return ret; |
| 2727 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2728 | cx231xx_info("Registered radio device as %s\n", |
| 2729 | video_device_node_name(dev->radio_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2730 | } |
| 2731 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2732 | cx231xx_info("V4L2 device registered as %s and %s\n", |
| 2733 | video_device_node_name(dev->vdev), |
| 2734 | video_device_node_name(dev->vbi_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2735 | |
| 2736 | return 0; |
| 2737 | } |