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