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