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