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