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