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