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