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