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