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 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1022 | f->fmt.pix.width = dev->width; |
| 1023 | f->fmt.pix.height = dev->height; |
Joe Perches | 1ebcad7 | 2009-07-02 15:57:09 -0300 | [diff] [blame] | 1024 | f->fmt.pix.pixelformat = dev->format->fourcc; |
| 1025 | f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1026 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1027 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1028 | |
| 1029 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1030 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc) |
| 1035 | { |
| 1036 | unsigned int i; |
| 1037 | |
| 1038 | for (i = 0; i < ARRAY_SIZE(format); i++) |
| 1039 | if (format[i].fourcc == fourcc) |
| 1040 | return &format[i]; |
| 1041 | |
| 1042 | return NULL; |
| 1043 | } |
| 1044 | |
| 1045 | 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] | 1046 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1047 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1048 | struct cx231xx_fh *fh = priv; |
| 1049 | struct cx231xx *dev = fh->dev; |
Trent Piepho | 9bd0e8d | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1050 | unsigned int width = f->fmt.pix.width; |
| 1051 | unsigned int height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1052 | unsigned int maxw = norm_maxw(dev); |
| 1053 | unsigned int maxh = norm_maxh(dev); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1054 | struct cx231xx_fmt *fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1055 | |
| 1056 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
| 1057 | if (!fmt) { |
| 1058 | cx231xx_videodbg("Fourcc format (%08x) invalid.\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1059 | f->fmt.pix.pixelformat); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | |
| 1063 | /* width must even because of the YUYV format |
| 1064 | height must be even because of interlacing */ |
Trent Piepho | 9bd0e8d | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1065 | 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] | 1066 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1067 | f->fmt.pix.width = width; |
| 1068 | f->fmt.pix.height = height; |
| 1069 | f->fmt.pix.pixelformat = fmt->fourcc; |
| 1070 | f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; |
| 1071 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; |
| 1072 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1073 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | 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] | 1079 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1080 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1081 | struct cx231xx_fh *fh = priv; |
| 1082 | struct cx231xx *dev = fh->dev; |
| 1083 | int rc; |
| 1084 | struct cx231xx_fmt *fmt; |
Hans Verkuil | 112cb4a | 2010-05-09 10:11:01 -0300 | [diff] [blame] | 1085 | struct v4l2_mbus_framefmt mbus_fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1086 | |
| 1087 | rc = check_dev(dev); |
| 1088 | if (rc < 0) |
| 1089 | return rc; |
| 1090 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1091 | vidioc_try_fmt_vid_cap(file, priv, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1092 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1093 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 1094 | if (!fmt) |
| 1095 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1096 | |
| 1097 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 1098 | cx231xx_errdev("%s queue busy\n", __func__); |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 1099 | return -EBUSY; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | if (dev->stream_on && !fh->stream_on) { |
| 1103 | cx231xx_errdev("%s device in use by another fh\n", __func__); |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 1104 | return -EBUSY; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /* set new image size */ |
| 1108 | dev->width = f->fmt.pix.width; |
| 1109 | dev->height = f->fmt.pix.height; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1110 | dev->format = fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1111 | |
Hans Verkuil | 112cb4a | 2010-05-09 10:11:01 -0300 | [diff] [blame] | 1112 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 1113 | call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 1114 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1115 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1116 | return rc; |
| 1117 | } |
| 1118 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1119 | 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] | 1120 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1121 | struct cx231xx_fh *fh = priv; |
| 1122 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1123 | |
| 1124 | *id = dev->norm; |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1128 | 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] | 1129 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1130 | struct cx231xx_fh *fh = priv; |
| 1131 | struct cx231xx *dev = fh->dev; |
Devin Heitmueller | 435b4f7 | 2010-07-09 13:29:31 -0300 | [diff] [blame] | 1132 | struct v4l2_mbus_framefmt mbus_fmt; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1133 | struct v4l2_format f; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1134 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1135 | |
| 1136 | rc = check_dev(dev); |
| 1137 | if (rc < 0) |
| 1138 | return rc; |
| 1139 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1140 | cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1141 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1142 | dev->norm = *norm; |
| 1143 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1144 | /* Adjusts width/height, if needed */ |
| 1145 | f.fmt.pix.width = dev->width; |
| 1146 | f.fmt.pix.height = dev->height; |
| 1147 | vidioc_try_fmt_vid_cap(file, priv, &f); |
| 1148 | |
Devin Heitmueller | 435b4f7 | 2010-07-09 13:29:31 -0300 | [diff] [blame] | 1149 | call_all(dev, core, s_std, dev->norm); |
| 1150 | |
| 1151 | /* We need to reset basic properties in the decoder related to |
| 1152 | resolution (since a standard change effects things like the number |
| 1153 | of lines in VACT, etc) */ |
| 1154 | v4l2_fill_mbus_format(&mbus_fmt, &f.fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 1155 | call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 1156 | v4l2_fill_pix_format(&f.fmt.pix, &mbus_fmt); |
| 1157 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1158 | /* set new image size */ |
| 1159 | dev->width = f.fmt.pix.width; |
| 1160 | dev->height = f.fmt.pix.height; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1161 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1162 | /* do mode control overrides */ |
| 1163 | cx231xx_do_mode_ctrl_overrides(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static const char *iname[] = { |
| 1169 | [CX231XX_VMUX_COMPOSITE1] = "Composite1", |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1170 | [CX231XX_VMUX_SVIDEO] = "S-Video", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1171 | [CX231XX_VMUX_TELEVISION] = "Television", |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1172 | [CX231XX_VMUX_CABLE] = "Cable TV", |
| 1173 | [CX231XX_VMUX_DVB] = "DVB", |
| 1174 | [CX231XX_VMUX_DEBUG] = "for debug only", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1175 | }; |
| 1176 | |
| 1177 | static int vidioc_enum_input(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1178 | struct v4l2_input *i) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1179 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1180 | struct cx231xx_fh *fh = priv; |
| 1181 | struct cx231xx *dev = fh->dev; |
| 1182 | unsigned int n; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1183 | |
| 1184 | n = i->index; |
| 1185 | if (n >= MAX_CX231XX_INPUT) |
| 1186 | return -EINVAL; |
| 1187 | if (0 == INPUT(n)->type) |
| 1188 | return -EINVAL; |
| 1189 | |
| 1190 | i->index = n; |
| 1191 | i->type = V4L2_INPUT_TYPE_CAMERA; |
| 1192 | |
| 1193 | strcpy(i->name, iname[INPUT(n)->type]); |
| 1194 | |
| 1195 | if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) || |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1196 | (CX231XX_VMUX_CABLE == INPUT(n)->type)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1197 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 1198 | |
| 1199 | i->std = dev->vdev->tvnorms; |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1205 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1206 | struct cx231xx_fh *fh = priv; |
| 1207 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1208 | |
| 1209 | *i = dev->video_input; |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 1215 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1216 | struct cx231xx_fh *fh = priv; |
| 1217 | struct cx231xx *dev = fh->dev; |
| 1218 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1219 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1220 | dev->mode_tv = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1221 | rc = check_dev(dev); |
| 1222 | if (rc < 0) |
| 1223 | return rc; |
| 1224 | |
| 1225 | if (i >= MAX_CX231XX_INPUT) |
| 1226 | return -EINVAL; |
| 1227 | if (0 == INPUT(i)->type) |
| 1228 | return -EINVAL; |
| 1229 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1230 | video_mux(dev, i); |
| 1231 | |
Devin Heitmueller | c09d669 | 2010-07-12 16:50:30 -0300 | [diff] [blame] | 1232 | if (INPUT(i)->type == CX231XX_VMUX_TELEVISION || |
| 1233 | INPUT(i)->type == CX231XX_VMUX_CABLE) { |
| 1234 | /* There's a tuner, so reset the standard and put it on the |
| 1235 | last known frequency (since it was probably powered down |
| 1236 | until now */ |
| 1237 | call_all(dev, core, s_std, dev->norm); |
| 1238 | } |
| 1239 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1244 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1245 | struct cx231xx_fh *fh = priv; |
| 1246 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1247 | |
| 1248 | switch (a->index) { |
| 1249 | case CX231XX_AMUX_VIDEO: |
| 1250 | strcpy(a->name, "Television"); |
| 1251 | break; |
| 1252 | case CX231XX_AMUX_LINE_IN: |
| 1253 | strcpy(a->name, "Line In"); |
| 1254 | break; |
| 1255 | default: |
| 1256 | return -EINVAL; |
| 1257 | } |
| 1258 | |
| 1259 | a->index = dev->ctl_ainput; |
| 1260 | a->capability = V4L2_AUDCAP_STEREO; |
| 1261 | |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1266 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1267 | struct cx231xx_fh *fh = priv; |
| 1268 | struct cx231xx *dev = fh->dev; |
| 1269 | int status = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1270 | |
| 1271 | /* Doesn't allow manual routing */ |
| 1272 | if (a->index != dev->ctl_ainput) |
| 1273 | return -EINVAL; |
| 1274 | |
| 1275 | dev->ctl_ainput = INPUT(a->index)->amux; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1276 | status = cx231xx_set_audio_input(dev, dev->ctl_ainput); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1277 | |
| 1278 | return status; |
| 1279 | } |
| 1280 | |
| 1281 | static int vidioc_queryctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1282 | struct v4l2_queryctrl *qc) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1283 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1284 | struct cx231xx_fh *fh = priv; |
| 1285 | struct cx231xx *dev = fh->dev; |
| 1286 | int id = qc->id; |
| 1287 | int i; |
| 1288 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1289 | |
| 1290 | rc = check_dev(dev); |
| 1291 | if (rc < 0) |
| 1292 | return rc; |
| 1293 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1294 | qc->id = v4l2_ctrl_next(ctrl_classes, qc->id); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1295 | if (unlikely(qc->id == 0)) |
| 1296 | return -EINVAL; |
| 1297 | |
| 1298 | memset(qc, 0, sizeof(*qc)); |
| 1299 | |
| 1300 | qc->id = id; |
| 1301 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1302 | if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | |
| 1305 | for (i = 0; i < CX231XX_CTLS; i++) |
| 1306 | if (cx231xx_ctls[i].v.id == qc->id) |
| 1307 | break; |
| 1308 | |
| 1309 | if (i == CX231XX_CTLS) { |
| 1310 | *qc = no_ctl; |
| 1311 | return 0; |
| 1312 | } |
| 1313 | *qc = cx231xx_ctls[i].v; |
| 1314 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1315 | call_all(dev, core, queryctrl, qc); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1316 | |
| 1317 | if (qc->type) |
| 1318 | return 0; |
| 1319 | else |
| 1320 | return -EINVAL; |
| 1321 | } |
| 1322 | |
| 1323 | static int vidioc_g_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1324 | struct v4l2_control *ctrl) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1325 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1326 | struct cx231xx_fh *fh = priv; |
| 1327 | struct cx231xx *dev = fh->dev; |
| 1328 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1329 | |
| 1330 | rc = check_dev(dev); |
| 1331 | if (rc < 0) |
| 1332 | return rc; |
| 1333 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1334 | call_all(dev, core, g_ctrl, ctrl); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1335 | return rc; |
| 1336 | } |
| 1337 | |
| 1338 | static int vidioc_s_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1339 | struct v4l2_control *ctrl) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1340 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1341 | struct cx231xx_fh *fh = priv; |
| 1342 | struct cx231xx *dev = fh->dev; |
| 1343 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1344 | |
| 1345 | rc = check_dev(dev); |
| 1346 | if (rc < 0) |
| 1347 | return rc; |
| 1348 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1349 | call_all(dev, core, s_ctrl, ctrl); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1350 | return rc; |
| 1351 | } |
| 1352 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1353 | 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] | 1354 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1355 | struct cx231xx_fh *fh = priv; |
| 1356 | struct cx231xx *dev = fh->dev; |
| 1357 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1358 | |
| 1359 | rc = check_dev(dev); |
| 1360 | if (rc < 0) |
| 1361 | return rc; |
| 1362 | |
| 1363 | if (0 != t->index) |
| 1364 | return -EINVAL; |
| 1365 | |
| 1366 | strcpy(t->name, "Tuner"); |
| 1367 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1368 | t->type = V4L2_TUNER_ANALOG_TV; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1369 | t->capability = V4L2_TUNER_CAP_NORM; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1370 | t->rangehigh = 0xffffffffUL; |
| 1371 | t->signal = 0xffff; /* LOCKED */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1376 | 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] | 1377 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1378 | struct cx231xx_fh *fh = priv; |
| 1379 | struct cx231xx *dev = fh->dev; |
| 1380 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1381 | |
| 1382 | rc = check_dev(dev); |
| 1383 | if (rc < 0) |
| 1384 | return rc; |
| 1385 | |
| 1386 | if (0 != t->index) |
| 1387 | return -EINVAL; |
| 1388 | #if 0 |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1389 | call_all(dev, tuner, s_tuner, t); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1390 | #endif |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | static int vidioc_g_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1395 | struct v4l2_frequency *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1396 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1397 | struct cx231xx_fh *fh = priv; |
| 1398 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1399 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1400 | f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1401 | f->frequency = dev->ctl_freq; |
| 1402 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1403 | call_all(dev, tuner, g_frequency, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1404 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1405 | return 0; |
| 1406 | } |
| 1407 | |
| 1408 | static int vidioc_s_frequency(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1409 | struct v4l2_frequency *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1410 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1411 | struct cx231xx_fh *fh = priv; |
| 1412 | struct cx231xx *dev = fh->dev; |
| 1413 | int rc; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1414 | u32 if_frequency = 5400000; |
| 1415 | |
| 1416 | cx231xx_info("Enter vidioc_s_frequency()f->frequency=%d;f->type=%d\n", |
| 1417 | f->frequency, f->type); |
| 1418 | /*cx231xx_info("f->type: 1-radio 2-analogTV 3-digitalTV\n");*/ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1419 | |
| 1420 | rc = check_dev(dev); |
| 1421 | if (rc < 0) |
| 1422 | return rc; |
| 1423 | |
| 1424 | if (0 != f->tuner) |
| 1425 | return -EINVAL; |
| 1426 | |
| 1427 | if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) |
| 1428 | return -EINVAL; |
| 1429 | if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) |
| 1430 | return -EINVAL; |
| 1431 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1432 | /* set pre channel change settings in DIF first */ |
| 1433 | rc = cx231xx_tuner_pre_channel_change(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1434 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1435 | dev->ctl_freq = f->frequency; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1436 | call_all(dev, tuner, s_frequency, f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1437 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1438 | /* set post channel change settings in DIF first */ |
| 1439 | rc = cx231xx_tuner_post_channel_change(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1440 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1441 | if (dev->tuner_type == TUNER_NXP_TDA18271) { |
| 1442 | if (dev->norm & (V4L2_STD_MN | V4L2_STD_NTSC_443)) |
| 1443 | if_frequency = 5400000; /*5.4MHz */ |
| 1444 | else if (dev->norm & V4L2_STD_B) |
| 1445 | if_frequency = 6000000; /*6.0MHz */ |
| 1446 | else if (dev->norm & (V4L2_STD_PAL_DK | V4L2_STD_SECAM_DK)) |
| 1447 | if_frequency = 6900000; /*6.9MHz */ |
| 1448 | else if (dev->norm & V4L2_STD_GH) |
| 1449 | if_frequency = 7100000; /*7.1MHz */ |
| 1450 | else if (dev->norm & V4L2_STD_PAL_I) |
| 1451 | if_frequency = 7250000; /*7.25MHz */ |
| 1452 | else if (dev->norm & V4L2_STD_SECAM_L) |
| 1453 | if_frequency = 6900000; /*6.9MHz */ |
| 1454 | else if (dev->norm & V4L2_STD_SECAM_LC) |
| 1455 | if_frequency = 1250000; /*1.25MHz */ |
| 1456 | |
| 1457 | cx231xx_info("if_frequency is set to %d\n", if_frequency); |
| 1458 | cx231xx_set_Colibri_For_LowIF(dev, if_frequency, 1, 1); |
| 1459 | |
| 1460 | update_HH_register_after_set_DIF(dev); |
| 1461 | } |
| 1462 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1463 | cx231xx_info("Set New FREQUENCY to %d\n", f->frequency); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1464 | |
| 1465 | return rc; |
| 1466 | } |
| 1467 | |
| 1468 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1469 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1470 | /* |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 1471 | -R, --list-registers=type=<host/i2cdrv/i2caddr>, |
| 1472 | chip=<chip>[,min=<addr>,max=<addr>] |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1473 | dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER] |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 1474 | -r, --set-register=type=<host/i2cdrv/i2caddr>, |
| 1475 | chip=<chip>,reg=<addr>,val=<val> |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1476 | set the register [VIDIOC_DBG_S_REGISTER] |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1477 | |
| 1478 | if type == host, then <chip> is the hosts chip ID (default 0) |
| 1479 | if type == i2cdrv (default), then <chip> is the I2C driver name or ID |
| 1480 | if type == i2caddr, then <chip> is the 7-bit I2C address |
| 1481 | */ |
| 1482 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1483 | static int vidioc_g_register(struct file *file, void *priv, |
| 1484 | struct v4l2_dbg_register *reg) |
| 1485 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1486 | struct cx231xx_fh *fh = priv; |
| 1487 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1488 | int ret = 0; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1489 | u8 value[4] = { 0, 0, 0, 0 }; |
| 1490 | u32 data = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1491 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1492 | switch (reg->match.type) { |
| 1493 | case V4L2_CHIP_MATCH_HOST: |
| 1494 | switch (reg->match.addr) { |
| 1495 | case 0: /* Cx231xx - internal registers */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1496 | ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, |
| 1497 | (u16)reg->reg, value, 4); |
| 1498 | reg->val = value[0] | value[1] << 8 | |
| 1499 | value[2] << 16 | value[3] << 24; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1500 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1501 | case 1: /* AFE - read byte */ |
| 1502 | ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1503 | (u16)reg->reg, 2, &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1504 | reg->val = le32_to_cpu(data & 0xff); |
| 1505 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1506 | case 14: /* AFE - read dword */ |
| 1507 | ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1508 | (u16)reg->reg, 2, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1509 | reg->val = le32_to_cpu(data); |
| 1510 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1511 | case 2: /* Video Block - read byte */ |
| 1512 | ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1513 | (u16)reg->reg, 2, &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1514 | reg->val = le32_to_cpu(data & 0xff); |
| 1515 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1516 | case 24: /* Video Block - read dword */ |
| 1517 | ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1518 | (u16)reg->reg, 2, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1519 | reg->val = le32_to_cpu(data); |
| 1520 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1521 | case 3: /* I2S block - read byte */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1522 | ret = cx231xx_read_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1523 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1524 | (u16)reg->reg, 1, |
| 1525 | &data, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1526 | reg->val = le32_to_cpu(data & 0xff); |
| 1527 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1528 | case 34: /* I2S Block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1529 | ret = |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1530 | cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1531 | (u16)reg->reg, 1, &data, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1532 | reg->val = le32_to_cpu(data); |
| 1533 | break; |
| 1534 | } |
| 1535 | return ret < 0 ? ret : 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1536 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1537 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1538 | call_all(dev, core, g_register, reg); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1539 | return 0; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1540 | case V4L2_CHIP_MATCH_I2C_ADDR:/*for register debug*/ |
| 1541 | switch (reg->match.addr) { |
| 1542 | case 0: /* Cx231xx - internal registers */ |
| 1543 | ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, |
| 1544 | (u16)reg->reg, value, 4); |
| 1545 | reg->val = value[0] | value[1] << 8 | |
| 1546 | value[2] << 16 | value[3] << 24; |
| 1547 | |
| 1548 | break; |
| 1549 | case 0x600:/* AFE - read byte */ |
| 1550 | ret = cx231xx_read_i2c_master(dev, AFE_DEVICE_ADDRESS, |
| 1551 | (u16)reg->reg, 2, |
| 1552 | &data, 1 , 0); |
| 1553 | reg->val = le32_to_cpu(data & 0xff); |
| 1554 | break; |
| 1555 | |
| 1556 | case 0x880:/* Video Block - read byte */ |
| 1557 | if (reg->reg < 0x0b) { |
| 1558 | ret = cx231xx_read_i2c_master(dev, |
| 1559 | VID_BLK_I2C_ADDRESS, |
| 1560 | (u16)reg->reg, 2, |
| 1561 | &data, 1 , 0); |
| 1562 | reg->val = le32_to_cpu(data & 0xff); |
| 1563 | } else { |
| 1564 | ret = cx231xx_read_i2c_master(dev, |
| 1565 | VID_BLK_I2C_ADDRESS, |
| 1566 | (u16)reg->reg, 2, |
| 1567 | &data, 4 , 0); |
| 1568 | reg->val = le32_to_cpu(data); |
| 1569 | } |
| 1570 | break; |
| 1571 | case 0x980: |
| 1572 | ret = cx231xx_read_i2c_master(dev, |
| 1573 | I2S_BLK_DEVICE_ADDRESS, |
| 1574 | (u16)reg->reg, 1, |
| 1575 | &data, 1 , 0); |
| 1576 | reg->val = le32_to_cpu(data & 0xff); |
| 1577 | break; |
| 1578 | case 0x400: |
| 1579 | ret = |
| 1580 | cx231xx_read_i2c_master(dev, 0x40, |
| 1581 | (u16)reg->reg, 1, |
| 1582 | &data, 1 , 0); |
| 1583 | reg->val = le32_to_cpu(data & 0xff); |
| 1584 | break; |
| 1585 | case 0xc01: |
| 1586 | ret = |
| 1587 | cx231xx_read_i2c_master(dev, 0xc0, |
| 1588 | (u16)reg->reg, 2, |
| 1589 | &data, 38, 1); |
| 1590 | reg->val = le32_to_cpu(data); |
| 1591 | break; |
| 1592 | case 0x022: |
| 1593 | ret = |
| 1594 | cx231xx_read_i2c_master(dev, 0x02, |
| 1595 | (u16)reg->reg, 1, |
| 1596 | &data, 1, 2); |
| 1597 | reg->val = le32_to_cpu(data & 0xff); |
| 1598 | break; |
| 1599 | case 0x322: |
| 1600 | ret = cx231xx_read_i2c_master(dev, |
| 1601 | 0x32, |
| 1602 | (u16)reg->reg, 1, |
| 1603 | &data, 4 , 2); |
| 1604 | reg->val = le32_to_cpu(data); |
| 1605 | break; |
| 1606 | case 0x342: |
| 1607 | ret = cx231xx_read_i2c_master(dev, |
| 1608 | 0x34, |
| 1609 | (u16)reg->reg, 1, |
| 1610 | &data, 4 , 2); |
| 1611 | reg->val = le32_to_cpu(data); |
| 1612 | break; |
| 1613 | |
| 1614 | default: |
| 1615 | cx231xx_info("no match device address!!\n"); |
| 1616 | break; |
| 1617 | } |
| 1618 | return ret < 0 ? ret : 0; |
| 1619 | /*return -EINVAL;*/ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1620 | default: |
| 1621 | if (!v4l2_chip_match_host(®->match)) |
| 1622 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1623 | } |
| 1624 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1625 | call_all(dev, core, g_register, reg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1626 | |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | static int vidioc_s_register(struct file *file, void *priv, |
| 1631 | struct v4l2_dbg_register *reg) |
| 1632 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1633 | struct cx231xx_fh *fh = priv; |
| 1634 | struct cx231xx *dev = fh->dev; |
| 1635 | int ret = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1636 | __le64 buf; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1637 | u32 value; |
| 1638 | u8 data[4] = { 0, 0, 0, 0 }; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1639 | |
| 1640 | buf = cpu_to_le64(reg->val); |
| 1641 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1642 | switch (reg->match.type) { |
| 1643 | case V4L2_CHIP_MATCH_HOST: |
| 1644 | { |
| 1645 | value = (u32) buf & 0xffffffff; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1646 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1647 | switch (reg->match.addr) { |
| 1648 | case 0: /* cx231xx internal registers */ |
| 1649 | data[0] = (u8) value; |
| 1650 | data[1] = (u8) (value >> 8); |
| 1651 | data[2] = (u8) (value >> 16); |
| 1652 | data[3] = (u8) (value >> 24); |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1653 | ret = cx231xx_write_ctrl_reg(dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1654 | VRT_SET_REGISTER, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1655 | (u16)reg->reg, data, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1656 | 4); |
| 1657 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1658 | case 1: /* AFE - read byte */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1659 | ret = cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1660 | AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1661 | (u16)reg->reg, 2, |
| 1662 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1663 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1664 | case 14: /* AFE - read dword */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1665 | ret = cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1666 | AFE_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1667 | (u16)reg->reg, 2, |
| 1668 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1669 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1670 | case 2: /* Video Block - read byte */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1671 | ret = |
| 1672 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1673 | VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1674 | (u16)reg->reg, 2, |
| 1675 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1676 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1677 | case 24: /* Video Block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1678 | ret = |
| 1679 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1680 | VID_BLK_I2C_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1681 | (u16)reg->reg, 2, |
| 1682 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1683 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1684 | case 3: /* I2S block - read byte */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1685 | ret = |
| 1686 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1687 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1688 | (u16)reg->reg, 1, |
| 1689 | value, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1690 | break; |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1691 | case 34: /* I2S block - read dword */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1692 | ret = |
| 1693 | cx231xx_write_i2c_data(dev, |
Sri Deevi | ecc67d1 | 2009-03-21 22:00:20 -0300 | [diff] [blame] | 1694 | I2S_BLK_DEVICE_ADDRESS, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 1695 | (u16)reg->reg, 1, |
| 1696 | value, 4); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1697 | break; |
| 1698 | } |
| 1699 | } |
| 1700 | return ret < 0 ? ret : 0; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1701 | case V4L2_CHIP_MATCH_I2C_ADDR: |
| 1702 | { |
| 1703 | value = (u32) buf & 0xffffffff; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1704 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1705 | switch (reg->match.addr) { |
| 1706 | case 0:/*cx231xx internal registers*/ |
| 1707 | data[0] = (u8) value; |
| 1708 | data[1] = (u8) (value >> 8); |
| 1709 | data[2] = (u8) (value >> 16); |
| 1710 | data[3] = (u8) (value >> 24); |
| 1711 | ret = cx231xx_write_ctrl_reg(dev, |
| 1712 | VRT_SET_REGISTER, |
| 1713 | (u16)reg->reg, data, |
| 1714 | 4); |
| 1715 | break; |
| 1716 | case 0x600:/* AFE - read byte */ |
| 1717 | ret = cx231xx_write_i2c_master(dev, |
| 1718 | AFE_DEVICE_ADDRESS, |
| 1719 | (u16)reg->reg, 2, |
| 1720 | value, 1 , 0); |
| 1721 | break; |
| 1722 | |
| 1723 | case 0x880:/* Video Block - read byte */ |
| 1724 | if (reg->reg < 0x0b) |
| 1725 | cx231xx_write_i2c_master(dev, |
| 1726 | VID_BLK_I2C_ADDRESS, |
| 1727 | (u16)reg->reg, 2, |
| 1728 | value, 1, 0); |
| 1729 | else |
| 1730 | cx231xx_write_i2c_master(dev, |
| 1731 | VID_BLK_I2C_ADDRESS, |
| 1732 | (u16)reg->reg, 2, |
| 1733 | value, 4, 0); |
| 1734 | break; |
| 1735 | case 0x980: |
| 1736 | ret = |
| 1737 | cx231xx_write_i2c_master(dev, |
| 1738 | I2S_BLK_DEVICE_ADDRESS, |
| 1739 | (u16)reg->reg, 1, |
| 1740 | value, 1, 0); |
| 1741 | break; |
| 1742 | case 0x400: |
| 1743 | ret = |
| 1744 | cx231xx_write_i2c_master(dev, |
| 1745 | 0x40, |
| 1746 | (u16)reg->reg, 1, |
| 1747 | value, 1, 0); |
| 1748 | break; |
| 1749 | case 0xc01: |
| 1750 | ret = |
| 1751 | cx231xx_write_i2c_master(dev, |
| 1752 | 0xc0, |
| 1753 | (u16)reg->reg, 1, |
| 1754 | value, 1, 1); |
| 1755 | break; |
| 1756 | |
| 1757 | case 0x022: |
| 1758 | ret = |
| 1759 | cx231xx_write_i2c_master(dev, |
| 1760 | 0x02, |
| 1761 | (u16)reg->reg, 1, |
| 1762 | value, 1, 2); |
| 1763 | case 0x322: |
| 1764 | ret = |
| 1765 | cx231xx_write_i2c_master(dev, |
| 1766 | 0x32, |
| 1767 | (u16)reg->reg, 1, |
| 1768 | value, 4, 2); |
| 1769 | break; |
| 1770 | |
| 1771 | case 0x342: |
| 1772 | ret = |
| 1773 | cx231xx_write_i2c_master(dev, |
| 1774 | 0x34, |
| 1775 | (u16)reg->reg, 1, |
| 1776 | value, 4, 2); |
| 1777 | break; |
| 1778 | default: |
| 1779 | cx231xx_info("no match device address, " |
| 1780 | "the value is %x\n", reg->match.addr); |
| 1781 | break; |
| 1782 | |
| 1783 | } |
| 1784 | |
| 1785 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1786 | default: |
| 1787 | break; |
| 1788 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1789 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1790 | call_all(dev, core, s_register, reg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1791 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1792 | return ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1793 | } |
| 1794 | #endif |
| 1795 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1796 | static int vidioc_cropcap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1797 | struct v4l2_cropcap *cc) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1798 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1799 | struct cx231xx_fh *fh = priv; |
| 1800 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1801 | |
| 1802 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1803 | return -EINVAL; |
| 1804 | |
| 1805 | cc->bounds.left = 0; |
| 1806 | cc->bounds.top = 0; |
| 1807 | cc->bounds.width = dev->width; |
| 1808 | cc->bounds.height = dev->height; |
| 1809 | cc->defrect = cc->bounds; |
| 1810 | cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ |
| 1811 | cc->pixelaspect.denominator = 59; |
| 1812 | |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
| 1816 | static int vidioc_streamon(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1817 | enum v4l2_buf_type type) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1818 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1819 | struct cx231xx_fh *fh = priv; |
| 1820 | struct cx231xx *dev = fh->dev; |
| 1821 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1822 | |
| 1823 | rc = check_dev(dev); |
| 1824 | if (rc < 0) |
| 1825 | return rc; |
| 1826 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1827 | rc = res_get(fh); |
| 1828 | |
| 1829 | if (likely(rc >= 0)) |
| 1830 | rc = videobuf_streamon(&fh->vb_vidq); |
| 1831 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1832 | call_all(dev, video, s_stream, 1); |
| 1833 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1834 | return rc; |
| 1835 | } |
| 1836 | |
| 1837 | static int vidioc_streamoff(struct file *file, void *priv, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1838 | enum v4l2_buf_type type) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1839 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1840 | struct cx231xx_fh *fh = priv; |
| 1841 | struct cx231xx *dev = fh->dev; |
| 1842 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1843 | |
| 1844 | rc = check_dev(dev); |
| 1845 | if (rc < 0) |
| 1846 | return rc; |
| 1847 | |
Mauro Carvalho Chehab | 92fcbd3 | 2009-03-21 22:16:34 -0300 | [diff] [blame] | 1848 | if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1849 | (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1850 | return -EINVAL; |
| 1851 | if (type != fh->type) |
| 1852 | return -EINVAL; |
| 1853 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1854 | cx25840_call(dev, video, s_stream, 0); |
| 1855 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1856 | videobuf_streamoff(&fh->vb_vidq); |
| 1857 | res_free(fh); |
| 1858 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1859 | return 0; |
| 1860 | } |
| 1861 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1862 | static int vidioc_querycap(struct file *file, void *priv, |
| 1863 | struct v4l2_capability *cap) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1864 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1865 | struct cx231xx_fh *fh = priv; |
| 1866 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1867 | |
| 1868 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); |
| 1869 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); |
Mauro Carvalho Chehab | 2c6beca | 2009-03-22 08:53:36 -0300 | [diff] [blame] | 1870 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1871 | |
| 1872 | cap->version = CX231XX_VERSION_CODE; |
| 1873 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1874 | cap->capabilities = V4L2_CAP_VBI_CAPTURE | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1875 | #if 0 |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 1876 | V4L2_CAP_SLICED_VBI_CAPTURE | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1877 | #endif |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 1878 | V4L2_CAP_VIDEO_CAPTURE | |
| 1879 | V4L2_CAP_AUDIO | |
| 1880 | V4L2_CAP_READWRITE | |
| 1881 | V4L2_CAP_STREAMING; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1882 | |
| 1883 | if (dev->tuner_type != TUNER_ABSENT) |
| 1884 | cap->capabilities |= V4L2_CAP_TUNER; |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1889 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 1890 | struct v4l2_fmtdesc *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1891 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1892 | if (unlikely(f->index >= ARRAY_SIZE(format))) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1893 | return -EINVAL; |
| 1894 | |
| 1895 | strlcpy(f->description, format[f->index].name, sizeof(f->description)); |
| 1896 | f->pixelformat = format[f->index].fourcc; |
| 1897 | |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
| 1901 | /* Sliced VBI ioctls */ |
| 1902 | 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] | 1903 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1904 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1905 | struct cx231xx_fh *fh = priv; |
| 1906 | struct cx231xx *dev = fh->dev; |
| 1907 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1908 | |
| 1909 | rc = check_dev(dev); |
| 1910 | if (rc < 0) |
| 1911 | return rc; |
| 1912 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1913 | f->fmt.sliced.service_set = 0; |
| 1914 | |
Hans Verkuil | 7e87ddb | 2010-03-14 12:31:08 -0300 | [diff] [blame] | 1915 | call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1916 | |
| 1917 | if (f->fmt.sliced.service_set == 0) |
| 1918 | rc = -EINVAL; |
| 1919 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1920 | return rc; |
| 1921 | } |
| 1922 | |
| 1923 | 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] | 1924 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1925 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1926 | struct cx231xx_fh *fh = priv; |
| 1927 | struct cx231xx *dev = fh->dev; |
| 1928 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1929 | |
| 1930 | rc = check_dev(dev); |
| 1931 | if (rc < 0) |
| 1932 | return rc; |
| 1933 | |
Hans Verkuil | 7e87ddb | 2010-03-14 12:31:08 -0300 | [diff] [blame] | 1934 | call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1935 | |
| 1936 | if (f->fmt.sliced.service_set == 0) |
| 1937 | return -EINVAL; |
| 1938 | |
| 1939 | return 0; |
| 1940 | } |
| 1941 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1942 | /* RAW VBI ioctls */ |
| 1943 | |
| 1944 | 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] | 1945 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1946 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1947 | struct cx231xx_fh *fh = priv; |
| 1948 | struct cx231xx *dev = fh->dev; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 1949 | f->fmt.vbi.sampling_rate = 6750000 * 4; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1950 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
| 1951 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 1952 | f->fmt.vbi.offset = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1953 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1954 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1955 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1956 | PAL_VBI_LINES : NTSC_VBI_LINES; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1957 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1958 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1959 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
| 1960 | |
| 1961 | return 0; |
| 1962 | |
| 1963 | } |
| 1964 | |
| 1965 | 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] | 1966 | struct v4l2_format *f) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1967 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1968 | struct cx231xx_fh *fh = priv; |
| 1969 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1970 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1971 | if (dev->vbi_stream_on && !fh->stream_on) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1972 | cx231xx_errdev("%s device in use by another fh\n", __func__); |
| 1973 | return -EBUSY; |
| 1974 | } |
| 1975 | |
| 1976 | f->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 1977 | f->fmt.vbi.sampling_rate = 6750000 * 4; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1978 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
| 1979 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
Devin Heitmueller | adc0356 | 2010-07-08 13:12:47 -0300 | [diff] [blame] | 1980 | f->fmt.vbi.offset = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1981 | f->fmt.vbi.flags = 0; |
| 1982 | f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1983 | PAL_VBI_START_LINE : NTSC_VBI_START_LINE; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1984 | f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1985 | PAL_VBI_LINES : NTSC_VBI_LINES; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1986 | f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1987 | PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1988 | f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; |
| 1989 | |
| 1990 | return 0; |
| 1991 | |
| 1992 | } |
| 1993 | |
| 1994 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1995 | struct v4l2_requestbuffers *rb) |
| 1996 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1997 | struct cx231xx_fh *fh = priv; |
| 1998 | struct cx231xx *dev = fh->dev; |
| 1999 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2000 | |
| 2001 | rc = check_dev(dev); |
| 2002 | if (rc < 0) |
| 2003 | return rc; |
| 2004 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2005 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2006 | } |
| 2007 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2008 | 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] | 2009 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2010 | struct cx231xx_fh *fh = priv; |
| 2011 | struct cx231xx *dev = fh->dev; |
| 2012 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2013 | |
| 2014 | rc = check_dev(dev); |
| 2015 | if (rc < 0) |
| 2016 | return rc; |
| 2017 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2018 | return videobuf_querybuf(&fh->vb_vidq, b); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 2022 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2023 | struct cx231xx_fh *fh = priv; |
| 2024 | struct cx231xx *dev = fh->dev; |
| 2025 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2026 | |
| 2027 | rc = check_dev(dev); |
| 2028 | if (rc < 0) |
| 2029 | return rc; |
| 2030 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2031 | return videobuf_qbuf(&fh->vb_vidq, b); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 2035 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2036 | struct cx231xx_fh *fh = priv; |
| 2037 | struct cx231xx *dev = fh->dev; |
| 2038 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2039 | |
| 2040 | rc = check_dev(dev); |
| 2041 | if (rc < 0) |
| 2042 | return rc; |
| 2043 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2044 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 2048 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
| 2049 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2050 | struct cx231xx_fh *fh = priv; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2051 | |
| 2052 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
| 2053 | } |
| 2054 | #endif |
| 2055 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2056 | /* ----------------------------------------------------------- */ |
| 2057 | /* RADIO ESPECIFIC IOCTLS */ |
| 2058 | /* ----------------------------------------------------------- */ |
| 2059 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2060 | static int radio_querycap(struct file *file, void *priv, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2061 | struct v4l2_capability *cap) |
| 2062 | { |
| 2063 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2064 | |
| 2065 | strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); |
| 2066 | strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); |
| 2067 | usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); |
| 2068 | |
| 2069 | cap->version = CX231XX_VERSION_CODE; |
| 2070 | cap->capabilities = V4L2_CAP_TUNER; |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2074 | 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] | 2075 | { |
| 2076 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2077 | |
| 2078 | if (unlikely(t->index > 0)) |
| 2079 | return -EINVAL; |
| 2080 | |
| 2081 | strcpy(t->name, "Radio"); |
| 2082 | t->type = V4L2_TUNER_RADIO; |
| 2083 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2084 | call_all(dev, tuner, s_tuner, t); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2085 | |
| 2086 | return 0; |
| 2087 | } |
| 2088 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2089 | 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] | 2090 | { |
| 2091 | if (i->index != 0) |
| 2092 | return -EINVAL; |
| 2093 | strcpy(i->name, "Radio"); |
| 2094 | i->type = V4L2_INPUT_TYPE_TUNER; |
| 2095 | |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 2100 | { |
| 2101 | if (unlikely(a->index)) |
| 2102 | return -EINVAL; |
| 2103 | |
| 2104 | strcpy(a->name, "Radio"); |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2108 | 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] | 2109 | { |
| 2110 | struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; |
| 2111 | |
| 2112 | if (0 != t->index) |
| 2113 | return -EINVAL; |
| 2114 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2115 | call_all(dev, tuner, s_tuner, t); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2116 | |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2120 | 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] | 2121 | { |
| 2122 | return 0; |
| 2123 | } |
| 2124 | |
| 2125 | static int radio_s_input(struct file *file, void *fh, unsigned int i) |
| 2126 | { |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | static int radio_queryctrl(struct file *file, void *priv, |
| 2131 | struct v4l2_queryctrl *c) |
| 2132 | { |
| 2133 | int i; |
| 2134 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2135 | if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2136 | return -EINVAL; |
| 2137 | if (c->id == V4L2_CID_AUDIO_MUTE) { |
Dan Carpenter | 8e47567 | 2010-04-02 08:30:10 -0300 | [diff] [blame] | 2138 | for (i = 0; i < CX231XX_CTLS; i++) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2139 | if (cx231xx_ctls[i].v.id == c->id) |
| 2140 | break; |
Dan Carpenter | 8e47567 | 2010-04-02 08:30:10 -0300 | [diff] [blame] | 2141 | } |
| 2142 | if (i == CX231XX_CTLS) |
| 2143 | return -EINVAL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2144 | *c = cx231xx_ctls[i].v; |
| 2145 | } else |
| 2146 | *c = no_ctl; |
| 2147 | return 0; |
| 2148 | } |
| 2149 | |
| 2150 | /* |
| 2151 | * cx231xx_v4l2_open() |
| 2152 | * inits the device and starts isoc transfer |
| 2153 | */ |
| 2154 | static int cx231xx_v4l2_open(struct file *filp) |
| 2155 | { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2156 | int errCode = 0, radio = 0; |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2157 | struct video_device *vdev = video_devdata(filp); |
| 2158 | struct cx231xx *dev = video_drvdata(filp); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2159 | struct cx231xx_fh *fh; |
| 2160 | enum v4l2_buf_type fh_type = 0; |
| 2161 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2162 | switch (vdev->vfl_type) { |
| 2163 | case VFL_TYPE_GRABBER: |
| 2164 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 2165 | break; |
| 2166 | case VFL_TYPE_VBI: |
| 2167 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 2168 | break; |
| 2169 | case VFL_TYPE_RADIO: |
| 2170 | radio = 1; |
| 2171 | break; |
| 2172 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2173 | |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 2174 | cx231xx_videodbg("open dev=%s type=%s users=%d\n", |
| 2175 | video_device_node_name(vdev), v4l2_type_names[fh_type], |
| 2176 | dev->users); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2177 | |
| 2178 | #if 0 |
| 2179 | errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 2180 | if (errCode < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2181 | cx231xx_errdev |
| 2182 | ("Device locked on digital mode. Can't open analog\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2183 | return -EBUSY; |
| 2184 | } |
| 2185 | #endif |
| 2186 | |
| 2187 | fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL); |
| 2188 | if (!fh) { |
| 2189 | cx231xx_errdev("cx231xx-video.c: Out of memory?!\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2190 | return -ENOMEM; |
| 2191 | } |
| 2192 | fh->dev = dev; |
| 2193 | fh->radio = radio; |
| 2194 | fh->type = fh_type; |
| 2195 | filp->private_data = fh; |
| 2196 | |
| 2197 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
| 2198 | dev->width = norm_maxw(dev); |
| 2199 | dev->height = norm_maxh(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2200 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2201 | /* Power up in Analog TV mode */ |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 2202 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER || |
| 2203 | dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2204 | cx231xx_set_power_mode(dev, |
| 2205 | POLARIS_AVMODE_ENXTERNAL_AV); |
| 2206 | else |
| 2207 | cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2208 | |
| 2209 | #if 0 |
| 2210 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 2211 | #endif |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2212 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2213 | /* set video alternate setting */ |
| 2214 | cx231xx_set_video_alternate(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2215 | |
| 2216 | /* Needed, since GPIO might have disabled power of |
| 2217 | some i2c device */ |
| 2218 | cx231xx_config_i2c(dev); |
| 2219 | |
| 2220 | /* device needs to be initialized before isoc transfer */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2221 | dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2222 | |
| 2223 | } |
| 2224 | if (fh->radio) { |
| 2225 | cx231xx_videodbg("video_open: setting radio device\n"); |
| 2226 | |
| 2227 | /* cx231xx_start_radio(dev); */ |
| 2228 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2229 | call_all(dev, tuner, s_radio); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | dev->users++; |
| 2233 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2234 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 2235 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, |
| 2236 | NULL, &dev->video_mode.slock, |
| 2237 | fh->type, V4L2_FIELD_INTERLACED, |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 2238 | sizeof(struct cx231xx_buffer), |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 2239 | fh, &dev->lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2240 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2241 | /* Set the required alternate setting VBI interface works in |
| 2242 | Bulk mode only */ |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 2243 | if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER && |
| 2244 | dev->model != CX231XX_BOARD_HAUPPAUGE_USBLIVE2) |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2245 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2246 | |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2247 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, |
| 2248 | NULL, &dev->vbi_mode.slock, |
| 2249 | fh->type, V4L2_FIELD_SEQ_TB, |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 2250 | sizeof(struct cx231xx_buffer), |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 2251 | fh, &dev->lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2252 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2253 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2254 | return errCode; |
| 2255 | } |
| 2256 | |
| 2257 | /* |
| 2258 | * cx231xx_realease_resources() |
| 2259 | * unregisters the v4l2,i2c and usb devices |
| 2260 | * called when the device gets disconected or at module unload |
| 2261 | */ |
| 2262 | void cx231xx_release_analog_resources(struct cx231xx *dev) |
| 2263 | { |
| 2264 | |
| 2265 | /*FIXME: I2C IR should be disconnected */ |
| 2266 | |
| 2267 | if (dev->radio_dev) { |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2268 | if (video_is_registered(dev->radio_dev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2269 | video_unregister_device(dev->radio_dev); |
| 2270 | else |
| 2271 | video_device_release(dev->radio_dev); |
| 2272 | dev->radio_dev = NULL; |
| 2273 | } |
| 2274 | if (dev->vbi_dev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2275 | cx231xx_info("V4L2 device %s deregistered\n", |
| 2276 | video_device_node_name(dev->vbi_dev)); |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2277 | if (video_is_registered(dev->vbi_dev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2278 | video_unregister_device(dev->vbi_dev); |
| 2279 | else |
| 2280 | video_device_release(dev->vbi_dev); |
| 2281 | dev->vbi_dev = NULL; |
| 2282 | } |
| 2283 | if (dev->vdev) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2284 | cx231xx_info("V4L2 device %s deregistered\n", |
| 2285 | video_device_node_name(dev->vdev)); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2286 | |
| 2287 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) |
| 2288 | cx231xx_417_unregister(dev); |
| 2289 | |
Laurent Pinchart | f0813b4 | 2009-11-27 13:57:30 -0300 | [diff] [blame] | 2290 | if (video_is_registered(dev->vdev)) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2291 | video_unregister_device(dev->vdev); |
| 2292 | else |
| 2293 | video_device_release(dev->vdev); |
| 2294 | dev->vdev = NULL; |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | /* |
| 2299 | * cx231xx_v4l2_close() |
| 2300 | * stops streaming and deallocates all resources allocated by the v4l2 |
| 2301 | * calls and ioctls |
| 2302 | */ |
| 2303 | static int cx231xx_v4l2_close(struct file *filp) |
| 2304 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2305 | struct cx231xx_fh *fh = filp->private_data; |
| 2306 | struct cx231xx *dev = fh->dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2307 | |
| 2308 | cx231xx_videodbg("users=%d\n", dev->users); |
| 2309 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2310 | cx231xx_videodbg("users=%d\n", dev->users); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2311 | if (res_check(fh)) |
| 2312 | res_free(fh); |
| 2313 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2314 | /*To workaround error number=-71 on EP0 for VideoGrabber, |
| 2315 | need exclude following.*/ |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 2316 | if (dev->model != CX231XX_BOARD_CNXT_VIDEO_GRABBER && |
| 2317 | dev->model != CX231XX_BOARD_HAUPPAUGE_USBLIVE2) |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2318 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
| 2319 | videobuf_stop(&fh->vb_vidq); |
| 2320 | videobuf_mmap_free(&fh->vb_vidq); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2321 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2322 | /* the device is already disconnect, |
| 2323 | free the remaining resources */ |
| 2324 | if (dev->state & DEV_DISCONNECTED) { |
| 2325 | if (atomic_read(&dev->devlist_count) > 0) { |
| 2326 | cx231xx_release_resources(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2327 | kfree(dev); |
| 2328 | dev = NULL; |
| 2329 | return 0; |
| 2330 | } |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2331 | return 0; |
| 2332 | } |
| 2333 | |
| 2334 | /* do this before setting alternate! */ |
| 2335 | cx231xx_uninit_vbi_isoc(dev); |
| 2336 | |
| 2337 | /* set alternate 0 */ |
| 2338 | if (!dev->vbi_or_sliced_cc_mode) |
| 2339 | cx231xx_set_alt_setting(dev, INDEX_VANC, 0); |
| 2340 | else |
| 2341 | cx231xx_set_alt_setting(dev, INDEX_HANC, 0); |
| 2342 | |
| 2343 | kfree(fh); |
| 2344 | dev->users--; |
| 2345 | wake_up_interruptible_nr(&dev->open, 1); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2346 | return 0; |
| 2347 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2348 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2349 | if (dev->users == 1) { |
| 2350 | videobuf_stop(&fh->vb_vidq); |
| 2351 | videobuf_mmap_free(&fh->vb_vidq); |
| 2352 | |
| 2353 | /* the device is already disconnect, |
| 2354 | free the remaining resources */ |
| 2355 | if (dev->state & DEV_DISCONNECTED) { |
| 2356 | cx231xx_release_resources(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2357 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2358 | dev = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2359 | return 0; |
| 2360 | } |
| 2361 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2362 | /* Save some power by putting tuner to sleep */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 2363 | call_all(dev, core, s_power, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2364 | |
| 2365 | /* do this before setting alternate! */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2366 | if (dev->USE_ISO) |
| 2367 | cx231xx_uninit_isoc(dev); |
| 2368 | else |
| 2369 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2370 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 2371 | |
| 2372 | /* set alternate 0 */ |
| 2373 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); |
| 2374 | } |
| 2375 | kfree(fh); |
| 2376 | dev->users--; |
| 2377 | wake_up_interruptible_nr(&dev->open, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2378 | return 0; |
| 2379 | } |
| 2380 | |
| 2381 | /* |
| 2382 | * cx231xx_v4l2_read() |
| 2383 | * will allocate buffers when called for the first time |
| 2384 | */ |
| 2385 | static ssize_t |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2386 | cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count, |
| 2387 | loff_t *pos) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2388 | { |
| 2389 | struct cx231xx_fh *fh = filp->private_data; |
| 2390 | struct cx231xx *dev = fh->dev; |
| 2391 | int rc; |
| 2392 | |
| 2393 | rc = check_dev(dev); |
| 2394 | if (rc < 0) |
| 2395 | return rc; |
| 2396 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2397 | if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) || |
| 2398 | (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2399 | rc = res_get(fh); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2400 | |
| 2401 | if (unlikely(rc < 0)) |
| 2402 | return rc; |
| 2403 | |
| 2404 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2405 | filp->f_flags & O_NONBLOCK); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2406 | } |
| 2407 | return 0; |
| 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * cx231xx_v4l2_poll() |
| 2412 | * will allocate buffers when called for the first time |
| 2413 | */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 2414 | static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2415 | { |
| 2416 | struct cx231xx_fh *fh = filp->private_data; |
| 2417 | struct cx231xx *dev = fh->dev; |
| 2418 | int rc; |
| 2419 | |
| 2420 | rc = check_dev(dev); |
| 2421 | if (rc < 0) |
| 2422 | return rc; |
| 2423 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2424 | rc = res_get(fh); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2425 | |
| 2426 | if (unlikely(rc < 0)) |
| 2427 | return POLLERR; |
| 2428 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2429 | if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) || |
| 2430 | (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) |
| 2431 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
| 2432 | else |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2433 | return POLLERR; |
| 2434 | } |
| 2435 | |
| 2436 | /* |
| 2437 | * cx231xx_v4l2_mmap() |
| 2438 | */ |
| 2439 | static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) |
| 2440 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2441 | struct cx231xx_fh *fh = filp->private_data; |
| 2442 | struct cx231xx *dev = fh->dev; |
| 2443 | int rc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2444 | |
| 2445 | rc = check_dev(dev); |
| 2446 | if (rc < 0) |
| 2447 | return rc; |
| 2448 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2449 | rc = res_get(fh); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2450 | |
| 2451 | if (unlikely(rc < 0)) |
| 2452 | return rc; |
| 2453 | |
| 2454 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
| 2455 | |
| 2456 | cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2457 | (unsigned long)vma->vm_start, |
| 2458 | (unsigned long)vma->vm_end - |
| 2459 | (unsigned long)vma->vm_start, rc); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2460 | |
| 2461 | return rc; |
| 2462 | } |
| 2463 | |
| 2464 | static const struct v4l2_file_operations cx231xx_v4l_fops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2465 | .owner = THIS_MODULE, |
| 2466 | .open = cx231xx_v4l2_open, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2467 | .release = cx231xx_v4l2_close, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2468 | .read = cx231xx_v4l2_read, |
| 2469 | .poll = cx231xx_v4l2_poll, |
| 2470 | .mmap = cx231xx_v4l2_mmap, |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 2471 | .unlocked_ioctl = video_ioctl2, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2472 | }; |
| 2473 | |
| 2474 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2475 | .vidioc_querycap = vidioc_querycap, |
| 2476 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 2477 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 2478 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 2479 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 2480 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
| 2481 | .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, |
| 2482 | .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, |
| 2483 | .vidioc_g_audio = vidioc_g_audio, |
| 2484 | .vidioc_s_audio = vidioc_s_audio, |
| 2485 | .vidioc_cropcap = vidioc_cropcap, |
| 2486 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2487 | .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] | 2488 | .vidioc_reqbufs = vidioc_reqbufs, |
| 2489 | .vidioc_querybuf = vidioc_querybuf, |
| 2490 | .vidioc_qbuf = vidioc_qbuf, |
| 2491 | .vidioc_dqbuf = vidioc_dqbuf, |
| 2492 | .vidioc_s_std = vidioc_s_std, |
| 2493 | .vidioc_g_std = vidioc_g_std, |
| 2494 | .vidioc_enum_input = vidioc_enum_input, |
| 2495 | .vidioc_g_input = vidioc_g_input, |
| 2496 | .vidioc_s_input = vidioc_s_input, |
| 2497 | .vidioc_queryctrl = vidioc_queryctrl, |
| 2498 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2499 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2500 | .vidioc_streamon = vidioc_streamon, |
| 2501 | .vidioc_streamoff = vidioc_streamoff, |
| 2502 | .vidioc_g_tuner = vidioc_g_tuner, |
| 2503 | .vidioc_s_tuner = vidioc_s_tuner, |
| 2504 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2505 | .vidioc_s_frequency = vidioc_s_frequency, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2506 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2507 | .vidioc_g_register = vidioc_g_register, |
| 2508 | .vidioc_s_register = vidioc_s_register, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2509 | #endif |
| 2510 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2511 | .vidiocgmbuf = vidiocgmbuf, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2512 | #endif |
| 2513 | }; |
| 2514 | |
| 2515 | static struct video_device cx231xx_vbi_template; |
| 2516 | |
| 2517 | static const struct video_device cx231xx_video_template = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2518 | .fops = &cx231xx_v4l_fops, |
| 2519 | .release = video_device_release, |
| 2520 | .ioctl_ops = &video_ioctl_ops, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2521 | .tvnorms = V4L2_STD_ALL, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2522 | .current_norm = V4L2_STD_PAL, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2523 | }; |
| 2524 | |
| 2525 | static const struct v4l2_file_operations radio_fops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2526 | .owner = THIS_MODULE, |
| 2527 | .open = cx231xx_v4l2_open, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2528 | .release = cx231xx_v4l2_close, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2529 | .ioctl = video_ioctl2, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2530 | }; |
| 2531 | |
| 2532 | static const struct v4l2_ioctl_ops radio_ioctl_ops = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2533 | .vidioc_querycap = radio_querycap, |
| 2534 | .vidioc_g_tuner = radio_g_tuner, |
| 2535 | .vidioc_enum_input = radio_enum_input, |
| 2536 | .vidioc_g_audio = radio_g_audio, |
| 2537 | .vidioc_s_tuner = radio_s_tuner, |
| 2538 | .vidioc_s_audio = radio_s_audio, |
| 2539 | .vidioc_s_input = radio_s_input, |
| 2540 | .vidioc_queryctrl = radio_queryctrl, |
| 2541 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2542 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2543 | .vidioc_g_frequency = vidioc_g_frequency, |
| 2544 | .vidioc_s_frequency = vidioc_s_frequency, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2545 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2546 | .vidioc_g_register = vidioc_g_register, |
| 2547 | .vidioc_s_register = vidioc_s_register, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2548 | #endif |
| 2549 | }; |
| 2550 | |
| 2551 | static struct video_device cx231xx_radio_template = { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2552 | .name = "cx231xx-radio", |
| 2553 | .fops = &radio_fops, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2554 | .ioctl_ops = &radio_ioctl_ops, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2555 | }; |
| 2556 | |
| 2557 | /******************************** usb interface ******************************/ |
| 2558 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 2559 | static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, |
| 2560 | const struct video_device |
| 2561 | *template, const char *type_name) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2562 | { |
| 2563 | struct video_device *vfd; |
| 2564 | |
| 2565 | vfd = video_device_alloc(); |
| 2566 | if (NULL == vfd) |
| 2567 | return NULL; |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2568 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2569 | *vfd = *template; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 2570 | vfd->v4l2_dev = &dev->v4l2_dev; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2571 | vfd->release = video_device_release; |
| 2572 | vfd->debug = video_debug; |
Mauro Carvalho Chehab | 643800d | 2010-10-09 13:13:35 -0300 | [diff] [blame] | 2573 | vfd->lock = &dev->lock; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2574 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2575 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2576 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2577 | video_set_drvdata(vfd, dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2578 | return vfd; |
| 2579 | } |
| 2580 | |
| 2581 | int cx231xx_register_analog_devices(struct cx231xx *dev) |
| 2582 | { |
| 2583 | int ret; |
| 2584 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2585 | cx231xx_info("%s: v4l2 driver version %d.%d.%d\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2586 | dev->name, |
| 2587 | (CX231XX_VERSION_CODE >> 16) & 0xff, |
| 2588 | (CX231XX_VERSION_CODE >> 8) & 0xff, |
| 2589 | CX231XX_VERSION_CODE & 0xff); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2590 | |
| 2591 | /* set default norm */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2592 | /*dev->norm = cx231xx_video_template.current_norm; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2593 | dev->width = norm_maxw(dev); |
| 2594 | dev->height = norm_maxh(dev); |
| 2595 | dev->interlaced = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2596 | |
| 2597 | /* Analog specific initialization */ |
| 2598 | dev->format = &format[0]; |
Devin Heitmueller | 6e6a2ba | 2010-07-12 15:34:57 -0300 | [diff] [blame] | 2599 | |
| 2600 | /* Set the initial input */ |
| 2601 | video_mux(dev, dev->video_input); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2602 | |
| 2603 | /* Audio defaults */ |
| 2604 | dev->mute = 1; |
| 2605 | dev->volume = 0x1f; |
| 2606 | |
| 2607 | /* enable vbi capturing */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2608 | /* write code here... */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2609 | |
| 2610 | /* allocate and fill video video_device struct */ |
| 2611 | dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video"); |
| 2612 | if (!dev->vdev) { |
| 2613 | cx231xx_errdev("cannot allocate video_device.\n"); |
| 2614 | return -ENODEV; |
| 2615 | } |
| 2616 | |
| 2617 | /* register v4l2 video video_device */ |
| 2618 | ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2619 | video_nr[dev->devno]); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2620 | if (ret) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2621 | cx231xx_errdev("unable to register video device (error=%i).\n", |
| 2622 | ret); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2623 | return ret; |
| 2624 | } |
| 2625 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2626 | cx231xx_info("%s/0: registered device %s [v4l2]\n", |
| 2627 | dev->name, video_device_node_name(dev->vdev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2628 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2629 | /* Initialize VBI template */ |
| 2630 | memcpy(&cx231xx_vbi_template, &cx231xx_video_template, |
| 2631 | sizeof(cx231xx_vbi_template)); |
| 2632 | strcpy(cx231xx_vbi_template.name, "cx231xx-vbi"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2633 | |
| 2634 | /* Allocate and fill vbi video_device struct */ |
| 2635 | dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi"); |
| 2636 | |
| 2637 | /* register v4l2 vbi video_device */ |
| 2638 | ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 2639 | vbi_nr[dev->devno]); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2640 | if (ret < 0) { |
| 2641 | cx231xx_errdev("unable to register vbi device\n"); |
| 2642 | return ret; |
| 2643 | } |
| 2644 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2645 | cx231xx_info("%s/0: registered device %s\n", |
| 2646 | dev->name, video_device_node_name(dev->vbi_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2647 | |
| 2648 | if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 2649 | dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template, |
| 2650 | "radio"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2651 | if (!dev->radio_dev) { |
| 2652 | cx231xx_errdev("cannot allocate video_device.\n"); |
| 2653 | return -ENODEV; |
| 2654 | } |
| 2655 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, |
| 2656 | radio_nr[dev->devno]); |
| 2657 | if (ret < 0) { |
| 2658 | cx231xx_errdev("can't register radio device\n"); |
| 2659 | return ret; |
| 2660 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2661 | cx231xx_info("Registered radio device as %s\n", |
| 2662 | video_device_node_name(dev->radio_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2663 | } |
| 2664 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2665 | cx231xx_info("V4L2 device registered as %s and %s\n", |
| 2666 | video_device_node_name(dev->vdev), |
| 2667 | video_device_node_name(dev->vbi_dev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 2668 | |
| 2669 | return 0; |
| 2670 | } |