Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 2 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <media/saa7146_vv.h> |
Hans Verkuil | 1b8dac1 | 2009-02-07 11:18:05 -0300 | [diff] [blame] | 4 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame^] | 5 | #include <media/v4l2-event.h> |
| 6 | #include <media/v4l2-ctrls.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 7 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | static int max_memory = 32; |
| 10 | |
| 11 | module_param(max_memory, int, 0644); |
| 12 | MODULE_PARM_DESC(max_memory, "maximum memory usage for capture buffers (default: 32Mb)"); |
| 13 | |
| 14 | #define IS_CAPTURE_ACTIVE(fh) \ |
| 15 | (((vv->video_status & STATUS_CAPTURE) != 0) && (vv->video_fh == fh)) |
| 16 | |
| 17 | #define IS_OVERLAY_ACTIVE(fh) \ |
| 18 | (((vv->video_status & STATUS_OVERLAY) != 0) && (vv->video_fh == fh)) |
| 19 | |
| 20 | /* format descriptions for capture and preview */ |
| 21 | static struct saa7146_format formats[] = { |
| 22 | { |
| 23 | .name = "RGB-8 (3-3-2)", |
| 24 | .pixelformat = V4L2_PIX_FMT_RGB332, |
| 25 | .trans = RGB08_COMPOSED, |
| 26 | .depth = 8, |
| 27 | .flags = 0, |
| 28 | }, { |
| 29 | .name = "RGB-16 (5/B-6/G-5/R)", |
| 30 | .pixelformat = V4L2_PIX_FMT_RGB565, |
| 31 | .trans = RGB16_COMPOSED, |
| 32 | .depth = 16, |
| 33 | .flags = 0, |
| 34 | }, { |
| 35 | .name = "RGB-24 (B-G-R)", |
| 36 | .pixelformat = V4L2_PIX_FMT_BGR24, |
| 37 | .trans = RGB24_COMPOSED, |
| 38 | .depth = 24, |
| 39 | .flags = 0, |
| 40 | }, { |
| 41 | .name = "RGB-32 (B-G-R)", |
| 42 | .pixelformat = V4L2_PIX_FMT_BGR32, |
| 43 | .trans = RGB32_COMPOSED, |
| 44 | .depth = 32, |
| 45 | .flags = 0, |
| 46 | }, { |
| 47 | .name = "RGB-32 (R-G-B)", |
| 48 | .pixelformat = V4L2_PIX_FMT_RGB32, |
| 49 | .trans = RGB32_COMPOSED, |
| 50 | .depth = 32, |
| 51 | .flags = 0, |
| 52 | .swap = 0x2, |
| 53 | }, { |
| 54 | .name = "Greyscale-8", |
| 55 | .pixelformat = V4L2_PIX_FMT_GREY, |
| 56 | .trans = Y8, |
| 57 | .depth = 8, |
| 58 | .flags = 0, |
| 59 | }, { |
| 60 | .name = "YUV 4:2:2 planar (Y-Cb-Cr)", |
| 61 | .pixelformat = V4L2_PIX_FMT_YUV422P, |
| 62 | .trans = YUV422_DECOMPOSED, |
| 63 | .depth = 16, |
| 64 | .flags = FORMAT_BYTE_SWAP|FORMAT_IS_PLANAR, |
| 65 | }, { |
| 66 | .name = "YVU 4:2:0 planar (Y-Cb-Cr)", |
| 67 | .pixelformat = V4L2_PIX_FMT_YVU420, |
| 68 | .trans = YUV420_DECOMPOSED, |
| 69 | .depth = 12, |
| 70 | .flags = FORMAT_BYTE_SWAP|FORMAT_IS_PLANAR, |
| 71 | }, { |
| 72 | .name = "YUV 4:2:0 planar (Y-Cb-Cr)", |
| 73 | .pixelformat = V4L2_PIX_FMT_YUV420, |
| 74 | .trans = YUV420_DECOMPOSED, |
| 75 | .depth = 12, |
| 76 | .flags = FORMAT_IS_PLANAR, |
| 77 | }, { |
| 78 | .name = "YUV 4:2:2 (U-Y-V-Y)", |
| 79 | .pixelformat = V4L2_PIX_FMT_UYVY, |
| 80 | .trans = YUV422_COMPOSED, |
| 81 | .depth = 16, |
| 82 | .flags = 0, |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | /* unfortunately, the saa7146 contains a bug which prevents it from doing on-the-fly byte swaps. |
| 87 | due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped |
| 88 | (like V4L2_PIX_FMT_YUYV) ... 8-( */ |
| 89 | |
| 90 | static int NUM_FORMATS = sizeof(formats)/sizeof(struct saa7146_format); |
| 91 | |
Mauro Carvalho Chehab | a757ee2 | 2010-12-02 01:57:03 -0200 | [diff] [blame] | 92 | struct saa7146_format* saa7146_format_by_fourcc(struct saa7146_dev *dev, int fourcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | int i, j = NUM_FORMATS; |
| 95 | |
| 96 | for (i = 0; i < j; i++) { |
| 97 | if (formats[i].pixelformat == fourcc) { |
| 98 | return formats+i; |
| 99 | } |
| 100 | } |
| 101 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 102 | DEB_D("unknown pixelformat:'%4.4s'\n", (char *)&fourcc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | return NULL; |
| 104 | } |
| 105 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 106 | static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | int saa7146_start_preview(struct saa7146_fh *fh) |
| 109 | { |
| 110 | struct saa7146_dev *dev = fh->dev; |
| 111 | struct saa7146_vv *vv = dev->vv_data; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 112 | struct v4l2_format fmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | int ret = 0, err = 0; |
| 114 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 115 | DEB_EE("dev:%p, fh:%p\n", dev, fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 117 | /* check if we have overlay information */ |
| 118 | if (vv->ov.fh == NULL) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 119 | DEB_D("no overlay data available. try S_FMT first.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return -EAGAIN; |
| 121 | } |
| 122 | |
| 123 | /* check if streaming capture is running */ |
| 124 | if (IS_CAPTURE_ACTIVE(fh) != 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 125 | DEB_D("streaming capture is active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return -EBUSY; |
| 127 | } |
| 128 | |
| 129 | /* check if overlay is running */ |
| 130 | if (IS_OVERLAY_ACTIVE(fh) != 0) { |
| 131 | if (vv->video_fh == fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 132 | DEB_D("overlay is already active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return 0; |
| 134 | } |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 135 | DEB_D("overlay is already active in another open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return -EBUSY; |
| 137 | } |
| 138 | |
| 139 | if (0 == saa7146_res_get(fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP)) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 140 | DEB_D("cannot get necessary overlay resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return -EBUSY; |
| 142 | } |
| 143 | |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 144 | fmt.fmt.win = vv->ov.win; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 145 | err = vidioc_try_fmt_vid_overlay(NULL, fh, &fmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if (0 != err) { |
| 147 | saa7146_res_free(vv->video_fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP); |
| 148 | return -EBUSY; |
| 149 | } |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 150 | vv->ov.win = fmt.fmt.win; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 152 | DEB_D("%dx%d+%d+%d %s field=%s\n", |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 153 | vv->ov.win.w.width, vv->ov.win.w.height, |
| 154 | vv->ov.win.w.left, vv->ov.win.w.top, |
| 155 | vv->ov_fmt->name, v4l2_field_names[vv->ov.win.field]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | if (0 != (ret = saa7146_enable_overlay(fh))) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 158 | DEB_D("enabling overlay failed: %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | saa7146_res_free(vv->video_fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP); |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | vv->video_status = STATUS_OVERLAY; |
| 164 | vv->video_fh = fh; |
| 165 | |
| 166 | return 0; |
| 167 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 168 | EXPORT_SYMBOL_GPL(saa7146_start_preview); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | int saa7146_stop_preview(struct saa7146_fh *fh) |
| 171 | { |
| 172 | struct saa7146_dev *dev = fh->dev; |
| 173 | struct saa7146_vv *vv = dev->vv_data; |
| 174 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 175 | DEB_EE("dev:%p, fh:%p\n", dev, fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* check if streaming capture is running */ |
| 178 | if (IS_CAPTURE_ACTIVE(fh) != 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 179 | DEB_D("streaming capture is active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return -EBUSY; |
| 181 | } |
| 182 | |
| 183 | /* check if overlay is running at all */ |
| 184 | if ((vv->video_status & STATUS_OVERLAY) == 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 185 | DEB_D("no active overlay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | if (vv->video_fh != fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 190 | DEB_D("overlay is active, but in another open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return -EBUSY; |
| 192 | } |
| 193 | |
| 194 | vv->video_status = 0; |
| 195 | vv->video_fh = NULL; |
| 196 | |
| 197 | saa7146_disable_overlay(fh); |
| 198 | |
| 199 | saa7146_res_free(fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP); |
| 200 | |
| 201 | return 0; |
| 202 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 203 | EXPORT_SYMBOL_GPL(saa7146_stop_preview); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /********************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* common pagetable functions */ |
| 207 | |
| 208 | static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *buf) |
| 209 | { |
| 210 | struct pci_dev *pci = dev->pci; |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 211 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
| 212 | struct scatterlist *list = dma->sglist; |
| 213 | int length = dma->sglen; |
Mauro Carvalho Chehab | a757ee2 | 2010-12-02 01:57:03 -0200 | [diff] [blame] | 214 | struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 216 | DEB_EE("dev:%p, buf:%p, sg_len:%d\n", dev, buf, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | if( 0 != IS_PLANAR(sfmt->trans)) { |
| 219 | struct saa7146_pgtable *pt1 = &buf->pt[0]; |
| 220 | struct saa7146_pgtable *pt2 = &buf->pt[1]; |
| 221 | struct saa7146_pgtable *pt3 = &buf->pt[2]; |
Al Viro | a36ef6b | 2008-06-22 14:19:19 -0300 | [diff] [blame] | 222 | __le32 *ptr1, *ptr2, *ptr3; |
| 223 | __le32 fill; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | int size = buf->fmt->width*buf->fmt->height; |
| 226 | int i,p,m1,m2,m3,o1,o2; |
| 227 | |
| 228 | switch( sfmt->depth ) { |
| 229 | case 12: { |
| 230 | /* create some offsets inside the page table */ |
| 231 | m1 = ((size+PAGE_SIZE)/PAGE_SIZE)-1; |
| 232 | m2 = ((size+(size/4)+PAGE_SIZE)/PAGE_SIZE)-1; |
| 233 | m3 = ((size+(size/2)+PAGE_SIZE)/PAGE_SIZE)-1; |
| 234 | o1 = size%PAGE_SIZE; |
| 235 | o2 = (size+(size/4))%PAGE_SIZE; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 236 | DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n", |
| 237 | size, m1, m2, m3, o1, o2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | case 16: { |
| 241 | /* create some offsets inside the page table */ |
| 242 | m1 = ((size+PAGE_SIZE)/PAGE_SIZE)-1; |
| 243 | m2 = ((size+(size/2)+PAGE_SIZE)/PAGE_SIZE)-1; |
| 244 | m3 = ((2*size+PAGE_SIZE)/PAGE_SIZE)-1; |
| 245 | o1 = size%PAGE_SIZE; |
| 246 | o2 = (size+(size/2))%PAGE_SIZE; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 247 | DEB_CAP("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n", |
| 248 | size, m1, m2, m3, o1, o2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | default: { |
| 252 | return -1; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | ptr1 = pt1->cpu; |
| 257 | ptr2 = pt2->cpu; |
| 258 | ptr3 = pt3->cpu; |
| 259 | |
| 260 | /* walk all pages, copy all page addresses to ptr1 */ |
| 261 | for (i = 0; i < length; i++, list++) { |
| 262 | for (p = 0; p * 4096 < list->length; p++, ptr1++) { |
| 263 | *ptr1 = cpu_to_le32(sg_dma_address(list) - list->offset); |
| 264 | } |
| 265 | } |
| 266 | /* |
| 267 | ptr1 = pt1->cpu; |
| 268 | for(j=0;j<40;j++) { |
| 269 | printk("ptr1 %d: 0x%08x\n",j,ptr1[j]); |
| 270 | } |
| 271 | */ |
| 272 | |
| 273 | /* if we have a user buffer, the first page may not be |
| 274 | aligned to a page boundary. */ |
Hans Verkuil | 429e908 | 2008-07-27 14:08:54 -0300 | [diff] [blame] | 275 | pt1->offset = dma->sglist->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | pt2->offset = pt1->offset+o1; |
| 277 | pt3->offset = pt1->offset+o2; |
| 278 | |
| 279 | /* create video-dma2 page table */ |
| 280 | ptr1 = pt1->cpu; |
| 281 | for(i = m1; i <= m2 ; i++, ptr2++) { |
| 282 | *ptr2 = ptr1[i]; |
| 283 | } |
| 284 | fill = *(ptr2-1); |
| 285 | for(;i<1024;i++,ptr2++) { |
| 286 | *ptr2 = fill; |
| 287 | } |
| 288 | /* create video-dma3 page table */ |
| 289 | ptr1 = pt1->cpu; |
| 290 | for(i = m2; i <= m3; i++,ptr3++) { |
| 291 | *ptr3 = ptr1[i]; |
| 292 | } |
| 293 | fill = *(ptr3-1); |
| 294 | for(;i<1024;i++,ptr3++) { |
| 295 | *ptr3 = fill; |
| 296 | } |
| 297 | /* finally: finish up video-dma1 page table */ |
| 298 | ptr1 = pt1->cpu+m1; |
| 299 | fill = pt1->cpu[m1]; |
| 300 | for(i=m1;i<1024;i++,ptr1++) { |
| 301 | *ptr1 = fill; |
| 302 | } |
| 303 | /* |
| 304 | ptr1 = pt1->cpu; |
| 305 | ptr2 = pt2->cpu; |
| 306 | ptr3 = pt3->cpu; |
| 307 | for(j=0;j<40;j++) { |
| 308 | printk("ptr1 %d: 0x%08x\n",j,ptr1[j]); |
| 309 | } |
| 310 | for(j=0;j<40;j++) { |
| 311 | printk("ptr2 %d: 0x%08x\n",j,ptr2[j]); |
| 312 | } |
| 313 | for(j=0;j<40;j++) { |
| 314 | printk("ptr3 %d: 0x%08x\n",j,ptr3[j]); |
| 315 | } |
| 316 | */ |
| 317 | } else { |
| 318 | struct saa7146_pgtable *pt = &buf->pt[0]; |
| 319 | return saa7146_pgtable_build_single(pci, pt, list, length); |
| 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | |
| 326 | /********************************************************************************/ |
| 327 | /* file operations */ |
| 328 | |
| 329 | static int video_begin(struct saa7146_fh *fh) |
| 330 | { |
| 331 | struct saa7146_dev *dev = fh->dev; |
| 332 | struct saa7146_vv *vv = dev->vv_data; |
| 333 | struct saa7146_format *fmt = NULL; |
| 334 | unsigned int resource; |
| 335 | int ret = 0, err = 0; |
| 336 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 337 | DEB_EE("dev:%p, fh:%p\n", dev, fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | if ((vv->video_status & STATUS_CAPTURE) != 0) { |
| 340 | if (vv->video_fh == fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 341 | DEB_S("already capturing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | return 0; |
| 343 | } |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 344 | DEB_S("already capturing in another open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return -EBUSY; |
| 346 | } |
| 347 | |
| 348 | if ((vv->video_status & STATUS_OVERLAY) != 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 349 | DEB_S("warning: suspending overlay video for streaming capture\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | vv->ov_suspend = vv->video_fh; |
| 351 | err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */ |
| 352 | if (0 != err) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 353 | DEB_D("suspending video failed. aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return err; |
| 355 | } |
| 356 | } |
| 357 | |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 358 | fmt = saa7146_format_by_fourcc(dev, vv->video_fmt.pixelformat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /* we need to have a valid format set here */ |
| 360 | BUG_ON(NULL == fmt); |
| 361 | |
| 362 | if (0 != (fmt->flags & FORMAT_IS_PLANAR)) { |
| 363 | resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS; |
| 364 | } else { |
| 365 | resource = RESOURCE_DMA1_HPS; |
| 366 | } |
| 367 | |
| 368 | ret = saa7146_res_get(fh, resource); |
| 369 | if (0 == ret) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 370 | DEB_S("cannot get capture resource %d\n", resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (vv->ov_suspend != NULL) { |
| 372 | saa7146_start_preview(vv->ov_suspend); |
| 373 | vv->ov_suspend = NULL; |
| 374 | } |
| 375 | return -EBUSY; |
| 376 | } |
| 377 | |
| 378 | /* clear out beginning of streaming bit (rps register 0)*/ |
| 379 | saa7146_write(dev, MC2, MASK_27 ); |
| 380 | |
| 381 | /* enable rps0 irqs */ |
| 382 | SAA7146_IER_ENABLE(dev, MASK_27); |
| 383 | |
| 384 | vv->video_fh = fh; |
| 385 | vv->video_status = STATUS_CAPTURE; |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int video_end(struct saa7146_fh *fh, struct file *file) |
| 391 | { |
| 392 | struct saa7146_dev *dev = fh->dev; |
| 393 | struct saa7146_vv *vv = dev->vv_data; |
| 394 | struct saa7146_format *fmt = NULL; |
| 395 | unsigned long flags; |
| 396 | unsigned int resource; |
| 397 | u32 dmas = 0; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 398 | DEB_EE("dev:%p, fh:%p\n", dev, fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 401 | DEB_S("not capturing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | if (vv->video_fh != fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 406 | DEB_S("capturing, but in another open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return -EBUSY; |
| 408 | } |
| 409 | |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 410 | fmt = saa7146_format_by_fourcc(dev, vv->video_fmt.pixelformat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* we need to have a valid format set here */ |
| 412 | BUG_ON(NULL == fmt); |
| 413 | |
| 414 | if (0 != (fmt->flags & FORMAT_IS_PLANAR)) { |
| 415 | resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS; |
| 416 | dmas = MASK_22 | MASK_21 | MASK_20; |
| 417 | } else { |
| 418 | resource = RESOURCE_DMA1_HPS; |
| 419 | dmas = MASK_22; |
| 420 | } |
| 421 | spin_lock_irqsave(&dev->slock,flags); |
| 422 | |
| 423 | /* disable rps0 */ |
| 424 | saa7146_write(dev, MC1, MASK_28); |
| 425 | |
| 426 | /* disable rps0 irqs */ |
| 427 | SAA7146_IER_DISABLE(dev, MASK_27); |
| 428 | |
| 429 | /* shut down all used video dma transfers */ |
| 430 | saa7146_write(dev, MC1, dmas); |
| 431 | |
| 432 | spin_unlock_irqrestore(&dev->slock, flags); |
| 433 | |
| 434 | vv->video_fh = NULL; |
| 435 | vv->video_status = 0; |
| 436 | |
| 437 | saa7146_res_free(fh, resource); |
| 438 | |
| 439 | if (vv->ov_suspend != NULL) { |
| 440 | saa7146_start_preview(vv->ov_suspend); |
| 441 | vv->ov_suspend = NULL; |
| 442 | } |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 447 | static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 449 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 450 | |
| 451 | strcpy((char *)cap->driver, "saa7146 v4l2"); |
| 452 | strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card)); |
| 453 | sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci)); |
| 454 | cap->version = SAA7146_VERSION_CODE; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 455 | cap->device_caps = |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 456 | V4L2_CAP_VIDEO_CAPTURE | |
| 457 | V4L2_CAP_VIDEO_OVERLAY | |
| 458 | V4L2_CAP_READWRITE | |
| 459 | V4L2_CAP_STREAMING; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 460 | cap->device_caps |= dev->ext_vv_data->capabilities; |
| 461 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static int vidioc_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb) |
| 466 | { |
| 467 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | struct saa7146_vv *vv = dev->vv_data; |
| 469 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 470 | *fb = vv->ov_fb; |
| 471 | fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 472 | fb->flags = V4L2_FBUF_FLAG_PRIMARY; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 473 | return 0; |
| 474 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 476 | static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb) |
| 477 | { |
| 478 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 479 | struct saa7146_vv *vv = dev->vv_data; |
| 480 | struct saa7146_format *fmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 482 | DEB_EE("VIDIOC_S_FBUF\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 484 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) |
| 485 | return -EPERM; |
| 486 | |
| 487 | /* check args */ |
Mauro Carvalho Chehab | a757ee2 | 2010-12-02 01:57:03 -0200 | [diff] [blame] | 488 | fmt = saa7146_format_by_fourcc(dev, fb->fmt.pixelformat); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 489 | if (NULL == fmt) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | /* planar formats are not allowed for overlay video, clipping and video dma would clash */ |
| 493 | if (fmt->flags & FORMAT_IS_PLANAR) |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 494 | DEB_S("planar pixelformat '%4.4s' not allowed for overlay\n", |
| 495 | (char *)&fmt->pixelformat); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 496 | |
| 497 | /* check if overlay is running */ |
| 498 | if (IS_OVERLAY_ACTIVE(fh) != 0) { |
| 499 | if (vv->video_fh != fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 500 | DEB_D("refusing to change framebuffer informations while overlay is active in another open\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 501 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 505 | /* ok, accept it */ |
| 506 | vv->ov_fb = *fb; |
| 507 | vv->ov_fmt = fmt; |
Michael Hunold | 84a1d9c | 2010-03-13 11:45:46 -0300 | [diff] [blame] | 508 | |
| 509 | if (vv->ov_fb.fmt.bytesperline < vv->ov_fb.fmt.width) { |
| 510 | vv->ov_fb.fmt.bytesperline = vv->ov_fb.fmt.width * fmt->depth / 8; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 511 | DEB_D("setting bytesperline to %d\n", vv->ov_fb.fmt.bytesperline); |
Michael Hunold | 84a1d9c | 2010-03-13 11:45:46 -0300 | [diff] [blame] | 512 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f) |
| 517 | { |
| 518 | if (f->index >= NUM_FORMATS) |
| 519 | return -EINVAL; |
| 520 | strlcpy((char *)f->description, formats[f->index].name, |
| 521 | sizeof(f->description)); |
| 522 | f->pixelformat = formats[f->index].pixelformat; |
| 523 | return 0; |
| 524 | } |
| 525 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 526 | int saa7146_s_ctrl(struct v4l2_ctrl *ctrl) |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 527 | { |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 528 | struct saa7146_dev *dev = container_of(ctrl->handler, |
| 529 | struct saa7146_dev, ctrl_handler); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 530 | struct saa7146_vv *vv = dev->vv_data; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 531 | u32 val; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 532 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 533 | switch (ctrl->id) { |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 534 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 535 | val = saa7146_read(dev, BCS_CTRL); |
| 536 | val &= 0x00ffffff; |
| 537 | val |= (ctrl->val << 24); |
| 538 | saa7146_write(dev, BCS_CTRL, val); |
| 539 | saa7146_write(dev, MC2, MASK_22 | MASK_06); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | break; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 541 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 542 | case V4L2_CID_CONTRAST: |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 543 | val = saa7146_read(dev, BCS_CTRL); |
| 544 | val &= 0xff00ffff; |
| 545 | val |= (ctrl->val << 16); |
| 546 | saa7146_write(dev, BCS_CTRL, val); |
| 547 | saa7146_write(dev, MC2, MASK_22 | MASK_06); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | break; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 549 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 550 | case V4L2_CID_SATURATION: |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 551 | val = saa7146_read(dev, BCS_CTRL); |
| 552 | val &= 0xffffff00; |
| 553 | val |= (ctrl->val << 0); |
| 554 | saa7146_write(dev, BCS_CTRL, val); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 555 | saa7146_write(dev, MC2, MASK_22 | MASK_06); |
| 556 | break; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 557 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 558 | case V4L2_CID_HFLIP: |
| 559 | /* fixme: we can support changing VFLIP and HFLIP here... */ |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 560 | if ((vv->video_status & STATUS_CAPTURE)) |
Hans Verkuil | 5a5b964 | 2009-02-07 11:25:05 -0300 | [diff] [blame] | 561 | return -EBUSY; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 562 | vv->hflip = ctrl->val; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 563 | break; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 564 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 565 | case V4L2_CID_VFLIP: |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 566 | if ((vv->video_status & STATUS_CAPTURE)) |
Hans Verkuil | 5a5b964 | 2009-02-07 11:25:05 -0300 | [diff] [blame] | 567 | return -EBUSY; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 568 | vv->vflip = ctrl->val; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 569 | break; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 570 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 571 | default: |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 572 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 575 | if ((vv->video_status & STATUS_OVERLAY) != 0) { /* CHECK: && (vv->video_fh == fh)) */ |
| 576 | struct saa7146_fh *fh = vv->video_fh; |
| 577 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 578 | saa7146_stop_preview(fh); |
| 579 | saa7146_start_preview(fh); |
| 580 | } |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int vidioc_g_parm(struct file *file, void *fh, |
| 585 | struct v4l2_streamparm *parm) |
| 586 | { |
Trent Piepho | 717167e | 2009-03-04 01:21:03 -0300 | [diff] [blame] | 587 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 588 | struct saa7146_vv *vv = dev->vv_data; |
| 589 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 590 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 591 | return -EINVAL; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 592 | parm->parm.capture.readbuffers = 1; |
Trent Piepho | 717167e | 2009-03-04 01:21:03 -0300 | [diff] [blame] | 593 | v4l2_video_std_frame_period(vv->standard->id, |
| 594 | &parm->parm.capture.timeperframe); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) |
| 599 | { |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 600 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 601 | struct saa7146_vv *vv = dev->vv_data; |
| 602 | |
| 603 | f->fmt.pix = vv->video_fmt; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f) |
| 608 | { |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 609 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 610 | struct saa7146_vv *vv = dev->vv_data; |
| 611 | |
| 612 | f->fmt.win = vv->ov.win; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static int vidioc_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f) |
| 617 | { |
Hans Verkuil | fca3469 | 2012-05-01 11:28:20 -0300 | [diff] [blame] | 618 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 619 | struct saa7146_vv *vv = dev->vv_data; |
| 620 | |
| 621 | f->fmt.vbi = vv->vbi_fmt; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) |
| 626 | { |
| 627 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 628 | struct saa7146_vv *vv = dev->vv_data; |
| 629 | struct saa7146_format *fmt; |
| 630 | enum v4l2_field field; |
| 631 | int maxw, maxh; |
| 632 | int calc_bpl; |
| 633 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 634 | DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 635 | |
Mauro Carvalho Chehab | a757ee2 | 2010-12-02 01:57:03 -0200 | [diff] [blame] | 636 | fmt = saa7146_format_by_fourcc(dev, f->fmt.pix.pixelformat); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 637 | if (NULL == fmt) |
| 638 | return -EINVAL; |
| 639 | |
| 640 | field = f->fmt.pix.field; |
| 641 | maxw = vv->standard->h_max_out; |
| 642 | maxh = vv->standard->v_max_out; |
| 643 | |
| 644 | if (V4L2_FIELD_ANY == field) { |
| 645 | field = (f->fmt.pix.height > maxh / 2) |
| 646 | ? V4L2_FIELD_INTERLACED |
| 647 | : V4L2_FIELD_BOTTOM; |
| 648 | } |
| 649 | switch (field) { |
| 650 | case V4L2_FIELD_ALTERNATE: |
| 651 | vv->last_field = V4L2_FIELD_TOP; |
| 652 | maxh = maxh / 2; |
| 653 | break; |
| 654 | case V4L2_FIELD_TOP: |
| 655 | case V4L2_FIELD_BOTTOM: |
| 656 | vv->last_field = V4L2_FIELD_INTERLACED; |
| 657 | maxh = maxh / 2; |
| 658 | break; |
| 659 | case V4L2_FIELD_INTERLACED: |
| 660 | vv->last_field = V4L2_FIELD_INTERLACED; |
| 661 | break; |
| 662 | default: |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 663 | DEB_D("no known field mode '%d'\n", field); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 664 | return -EINVAL; |
| 665 | } |
| 666 | |
| 667 | f->fmt.pix.field = field; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 668 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 669 | if (f->fmt.pix.width > maxw) |
| 670 | f->fmt.pix.width = maxw; |
| 671 | if (f->fmt.pix.height > maxh) |
| 672 | f->fmt.pix.height = maxh; |
| 673 | |
| 674 | calc_bpl = (f->fmt.pix.width * fmt->depth) / 8; |
| 675 | |
| 676 | if (f->fmt.pix.bytesperline < calc_bpl) |
| 677 | f->fmt.pix.bytesperline = calc_bpl; |
| 678 | |
| 679 | if (f->fmt.pix.bytesperline > (2 * PAGE_SIZE * fmt->depth) / 8) /* arbitrary constraint */ |
| 680 | f->fmt.pix.bytesperline = calc_bpl; |
| 681 | |
| 682 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 683 | DEB_D("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n", |
| 684 | f->fmt.pix.width, f->fmt.pix.height, |
| 685 | f->fmt.pix.bytesperline, f->fmt.pix.sizeimage); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | |
| 691 | static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f) |
| 692 | { |
| 693 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 694 | struct saa7146_vv *vv = dev->vv_data; |
| 695 | struct v4l2_window *win = &f->fmt.win; |
| 696 | enum v4l2_field field; |
| 697 | int maxw, maxh; |
| 698 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 699 | DEB_EE("dev:%p\n", dev); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 700 | |
| 701 | if (NULL == vv->ov_fb.base) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 702 | DEB_D("no fb base set\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 703 | return -EINVAL; |
| 704 | } |
| 705 | if (NULL == vv->ov_fmt) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 706 | DEB_D("no fb fmt set\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 707 | return -EINVAL; |
| 708 | } |
| 709 | if (win->w.width < 48 || win->w.height < 32) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 710 | DEB_D("min width/height. (%d,%d)\n", |
| 711 | win->w.width, win->w.height); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 712 | return -EINVAL; |
| 713 | } |
| 714 | if (win->clipcount > 16) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 715 | DEB_D("clipcount too big\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 716 | return -EINVAL; |
| 717 | } |
| 718 | |
| 719 | field = win->field; |
| 720 | maxw = vv->standard->h_max_out; |
| 721 | maxh = vv->standard->v_max_out; |
| 722 | |
| 723 | if (V4L2_FIELD_ANY == field) { |
| 724 | field = (win->w.height > maxh / 2) |
| 725 | ? V4L2_FIELD_INTERLACED |
| 726 | : V4L2_FIELD_TOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 728 | switch (field) { |
| 729 | case V4L2_FIELD_TOP: |
| 730 | case V4L2_FIELD_BOTTOM: |
| 731 | case V4L2_FIELD_ALTERNATE: |
| 732 | maxh = maxh / 2; |
| 733 | break; |
| 734 | case V4L2_FIELD_INTERLACED: |
| 735 | break; |
| 736 | default: |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 737 | DEB_D("no known field mode '%d'\n", field); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 738 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 741 | win->field = field; |
| 742 | if (win->w.width > maxw) |
| 743 | win->w.width = maxw; |
| 744 | if (win->w.height > maxh) |
| 745 | win->w.height = maxh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 747 | return 0; |
| 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 750 | static int vidioc_s_fmt_vid_cap(struct file *file, void *__fh, struct v4l2_format *f) |
| 751 | { |
| 752 | struct saa7146_fh *fh = __fh; |
| 753 | struct saa7146_dev *dev = fh->dev; |
| 754 | struct saa7146_vv *vv = dev->vv_data; |
| 755 | int err; |
| 756 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 757 | DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 758 | if (IS_CAPTURE_ACTIVE(fh) != 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 759 | DEB_EE("streaming capture is active\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 760 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 762 | err = vidioc_try_fmt_vid_cap(file, fh, f); |
| 763 | if (0 != err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | return err; |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 765 | vv->video_fmt = f->fmt.pix; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 766 | DEB_EE("set to pixelformat '%4.4s'\n", |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 767 | (char *)&vv->video_fmt.pixelformat); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int vidioc_s_fmt_vid_overlay(struct file *file, void *__fh, struct v4l2_format *f) |
| 772 | { |
| 773 | struct saa7146_fh *fh = __fh; |
| 774 | struct saa7146_dev *dev = fh->dev; |
| 775 | struct saa7146_vv *vv = dev->vv_data; |
| 776 | int err; |
| 777 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 778 | DEB_EE("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev, fh); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 779 | err = vidioc_try_fmt_vid_overlay(file, fh, f); |
| 780 | if (0 != err) |
| 781 | return err; |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 782 | vv->ov.win = f->fmt.win; |
| 783 | vv->ov.nclips = f->fmt.win.clipcount; |
| 784 | if (vv->ov.nclips > 16) |
| 785 | vv->ov.nclips = 16; |
| 786 | if (copy_from_user(vv->ov.clips, f->fmt.win.clips, |
| 787 | sizeof(struct v4l2_clip) * vv->ov.nclips)) { |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 788 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 790 | |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 791 | /* vv->ov.fh is used to indicate that we have valid overlay informations, too */ |
| 792 | vv->ov.fh = fh; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 793 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 794 | /* check if our current overlay is active */ |
| 795 | if (IS_OVERLAY_ACTIVE(fh) != 0) { |
| 796 | saa7146_stop_preview(fh); |
| 797 | saa7146_start_preview(fh); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 798 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm) |
| 803 | { |
| 804 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 805 | struct saa7146_vv *vv = dev->vv_data; |
| 806 | |
| 807 | *norm = vv->standard->id; |
| 808 | return 0; |
| 809 | } |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /* the saa7146 supfhrts (used in conjunction with the saa7111a for example) |
| 812 | PAL / NTSC / SECAM. if your hardware does not (or does more) |
| 813 | -- override this function in your extension */ |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 814 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | case VIDIOC_ENUMSTD: |
| 816 | { |
| 817 | struct v4l2_standard *e = arg; |
| 818 | if (e->index < 0 ) |
| 819 | return -EINVAL; |
| 820 | if( e->index < dev->ext_vv_data->num_stds ) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 821 | DEB_EE("VIDIOC_ENUMSTD: index:%d\n", e->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | v4l2_video_std_construct(e, dev->ext_vv_data->stds[e->index].id, dev->ext_vv_data->stds[e->index].name); |
| 823 | return 0; |
| 824 | } |
| 825 | return -EINVAL; |
| 826 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 827 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 829 | static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id) |
| 830 | { |
| 831 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 832 | struct saa7146_vv *vv = dev->vv_data; |
| 833 | int found = 0; |
| 834 | int err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 836 | DEB_EE("VIDIOC_S_STD\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 838 | if ((vv->video_status & STATUS_CAPTURE) == STATUS_CAPTURE) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 839 | DEB_D("cannot change video standard while streaming capture is active\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 840 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 843 | if ((vv->video_status & STATUS_OVERLAY) != 0) { |
| 844 | vv->ov_suspend = vv->video_fh; |
| 845 | err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | if (0 != err) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 847 | DEB_D("suspending video failed. aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | return err; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 849 | } |
| 850 | } |
Brandon Philips | 49ee718 | 2007-10-05 16:26:27 -0300 | [diff] [blame] | 851 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 852 | for (i = 0; i < dev->ext_vv_data->num_stds; i++) |
| 853 | if (*id & dev->ext_vv_data->stds[i].id) |
| 854 | break; |
| 855 | if (i != dev->ext_vv_data->num_stds) { |
| 856 | vv->standard = &dev->ext_vv_data->stds[i]; |
| 857 | if (NULL != dev->ext_vv_data->std_callback) |
| 858 | dev->ext_vv_data->std_callback(dev, vv->standard); |
| 859 | found = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 861 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 862 | if (vv->ov_suspend != NULL) { |
| 863 | saa7146_start_preview(vv->ov_suspend); |
| 864 | vv->ov_suspend = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 866 | |
| 867 | if (!found) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 868 | DEB_EE("VIDIOC_S_STD: standard not found\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 869 | return -EINVAL; |
| 870 | } |
| 871 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 872 | DEB_EE("VIDIOC_S_STD: set to standard to '%s'\n", vv->standard->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | return 0; |
| 874 | } |
| 875 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 876 | static int vidioc_overlay(struct file *file, void *fh, unsigned int on) |
| 877 | { |
| 878 | int err; |
| 879 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 880 | DEB_D("VIDIOC_OVERLAY on:%d\n", on); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 881 | if (on) |
| 882 | err = saa7146_start_preview(fh); |
| 883 | else |
| 884 | err = saa7146_stop_preview(fh); |
| 885 | return err; |
| 886 | } |
| 887 | |
| 888 | static int vidioc_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffers *b) |
| 889 | { |
| 890 | struct saa7146_fh *fh = __fh; |
| 891 | |
| 892 | if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 893 | return videobuf_reqbufs(&fh->video_q, b); |
| 894 | if (b->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 895 | return videobuf_reqbufs(&fh->vbi_q, b); |
| 896 | return -EINVAL; |
| 897 | } |
| 898 | |
| 899 | static int vidioc_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
| 900 | { |
| 901 | struct saa7146_fh *fh = __fh; |
| 902 | |
| 903 | if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 904 | return videobuf_querybuf(&fh->video_q, buf); |
| 905 | if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 906 | return videobuf_querybuf(&fh->vbi_q, buf); |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | |
| 910 | static int vidioc_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
| 911 | { |
| 912 | struct saa7146_fh *fh = __fh; |
| 913 | |
| 914 | if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 915 | return videobuf_qbuf(&fh->video_q, buf); |
| 916 | if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 917 | return videobuf_qbuf(&fh->vbi_q, buf); |
| 918 | return -EINVAL; |
| 919 | } |
| 920 | |
| 921 | static int vidioc_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
| 922 | { |
| 923 | struct saa7146_fh *fh = __fh; |
| 924 | |
| 925 | if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 926 | return videobuf_dqbuf(&fh->video_q, buf, file->f_flags & O_NONBLOCK); |
| 927 | if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 928 | return videobuf_dqbuf(&fh->vbi_q, buf, file->f_flags & O_NONBLOCK); |
| 929 | return -EINVAL; |
| 930 | } |
| 931 | |
| 932 | static int vidioc_streamon(struct file *file, void *__fh, enum v4l2_buf_type type) |
| 933 | { |
| 934 | struct saa7146_fh *fh = __fh; |
| 935 | int err; |
| 936 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 937 | DEB_D("VIDIOC_STREAMON, type:%d\n", type); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 938 | |
| 939 | err = video_begin(fh); |
| 940 | if (err) |
| 941 | return err; |
| 942 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 943 | return videobuf_streamon(&fh->video_q); |
| 944 | if (type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 945 | return videobuf_streamon(&fh->vbi_q); |
| 946 | return -EINVAL; |
| 947 | } |
| 948 | |
| 949 | static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type) |
| 950 | { |
| 951 | struct saa7146_fh *fh = __fh; |
| 952 | struct saa7146_dev *dev = fh->dev; |
| 953 | struct saa7146_vv *vv = dev->vv_data; |
| 954 | int err; |
| 955 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 956 | DEB_D("VIDIOC_STREAMOFF, type:%d\n", type); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 957 | |
| 958 | /* ugly: we need to copy some checks from video_end(), |
| 959 | because videobuf_streamoff() relies on the capture running. |
| 960 | check and fix this */ |
| 961 | if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 962 | DEB_S("not capturing\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | if (vv->video_fh != fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 967 | DEB_S("capturing, but in another open\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 968 | return -EBUSY; |
| 969 | } |
| 970 | |
| 971 | err = -EINVAL; |
| 972 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 973 | err = videobuf_streamoff(&fh->video_q); |
| 974 | else if (type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 975 | err = videobuf_streamoff(&fh->vbi_q); |
| 976 | if (0 != err) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 977 | DEB_D("warning: videobuf_streamoff() failed\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 978 | video_end(fh, file); |
| 979 | } else { |
| 980 | err = video_end(fh, file); |
| 981 | } |
| 982 | return err; |
| 983 | } |
| 984 | |
Hans Verkuil | 1b8dac1 | 2009-02-07 11:18:05 -0300 | [diff] [blame] | 985 | static int vidioc_g_chip_ident(struct file *file, void *__fh, |
| 986 | struct v4l2_dbg_chip_ident *chip) |
| 987 | { |
| 988 | struct saa7146_fh *fh = __fh; |
| 989 | struct saa7146_dev *dev = fh->dev; |
| 990 | |
| 991 | chip->ident = V4L2_IDENT_NONE; |
| 992 | chip->revision = 0; |
Hans Verkuil | eae4d69 | 2009-02-07 20:15:22 -0300 | [diff] [blame] | 993 | if (chip->match.type == V4L2_CHIP_MATCH_HOST && !chip->match.addr) { |
Hans Verkuil | 1b8dac1 | 2009-02-07 11:18:05 -0300 | [diff] [blame] | 994 | chip->ident = V4L2_IDENT_SAA7146; |
| 995 | return 0; |
| 996 | } |
| 997 | return v4l2_device_call_until_err(&dev->v4l2_dev, 0, |
| 998 | core, g_chip_ident, chip); |
| 999 | } |
| 1000 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 1001 | const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = { |
| 1002 | .vidioc_querycap = vidioc_querycap, |
| 1003 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
Trent Piepho | 717167e | 2009-03-04 01:21:03 -0300 | [diff] [blame] | 1004 | .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_cap, |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 1005 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1006 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1007 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 1008 | .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay, |
| 1009 | .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay, |
| 1010 | .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay, |
| 1011 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
Hans Verkuil | 1b8dac1 | 2009-02-07 11:18:05 -0300 | [diff] [blame] | 1012 | .vidioc_g_chip_ident = vidioc_g_chip_ident, |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 1013 | |
| 1014 | .vidioc_overlay = vidioc_overlay, |
| 1015 | .vidioc_g_fbuf = vidioc_g_fbuf, |
| 1016 | .vidioc_s_fbuf = vidioc_s_fbuf, |
| 1017 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1018 | .vidioc_querybuf = vidioc_querybuf, |
| 1019 | .vidioc_qbuf = vidioc_qbuf, |
| 1020 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1021 | .vidioc_g_std = vidioc_g_std, |
| 1022 | .vidioc_s_std = vidioc_s_std, |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 1023 | .vidioc_streamon = vidioc_streamon, |
| 1024 | .vidioc_streamoff = vidioc_streamoff, |
| 1025 | .vidioc_g_parm = vidioc_g_parm, |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame^] | 1026 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1027 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 1028 | }; |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | /*********************************************************************************/ |
| 1031 | /* buffer handling functions */ |
| 1032 | |
| 1033 | static int buffer_activate (struct saa7146_dev *dev, |
| 1034 | struct saa7146_buf *buf, |
| 1035 | struct saa7146_buf *next) |
| 1036 | { |
| 1037 | struct saa7146_vv *vv = dev->vv_data; |
| 1038 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1039 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | saa7146_set_capture(dev,buf,next); |
| 1041 | |
Hans Verkuil | 9bb6019 | 2012-05-01 11:45:27 -0300 | [diff] [blame] | 1042 | mod_timer(&vv->video_dmaq.timeout, jiffies+BUFFER_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | |
Johann Friedrichs | 311c70e | 2009-10-07 04:41:37 -0300 | [diff] [blame] | 1046 | static void release_all_pagetables(struct saa7146_dev *dev, struct saa7146_buf *buf) |
| 1047 | { |
| 1048 | saa7146_pgtable_free(dev->pci, &buf->pt[0]); |
| 1049 | saa7146_pgtable_free(dev->pci, &buf->pt[1]); |
| 1050 | saa7146_pgtable_free(dev->pci, &buf->pt[2]); |
| 1051 | } |
| 1052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | static int buffer_prepare(struct videobuf_queue *q, |
| 1054 | struct videobuf_buffer *vb, enum v4l2_field field) |
| 1055 | { |
| 1056 | struct file *file = q->priv_data; |
| 1057 | struct saa7146_fh *fh = file->private_data; |
| 1058 | struct saa7146_dev *dev = fh->dev; |
| 1059 | struct saa7146_vv *vv = dev->vv_data; |
| 1060 | struct saa7146_buf *buf = (struct saa7146_buf *)vb; |
| 1061 | int size,err = 0; |
| 1062 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1063 | DEB_CAP("vbuf:%p\n", vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | /* sanity checks */ |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1066 | if (vv->video_fmt.width < 48 || |
| 1067 | vv->video_fmt.height < 32 || |
| 1068 | vv->video_fmt.width > vv->standard->h_max_out || |
| 1069 | vv->video_fmt.height > vv->standard->v_max_out) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1070 | DEB_D("w (%d) / h (%d) out of bounds\n", |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1071 | vv->video_fmt.width, vv->video_fmt.height); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | return -EINVAL; |
| 1073 | } |
| 1074 | |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1075 | size = vv->video_fmt.sizeimage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (0 != buf->vb.baddr && buf->vb.bsize < size) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1077 | DEB_D("size mismatch\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1081 | DEB_CAP("buffer_prepare [size=%dx%d,bytes=%d,fields=%s]\n", |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1082 | vv->video_fmt.width, vv->video_fmt.height, |
| 1083 | size, v4l2_field_names[vv->video_fmt.field]); |
| 1084 | if (buf->vb.width != vv->video_fmt.width || |
| 1085 | buf->vb.bytesperline != vv->video_fmt.bytesperline || |
| 1086 | buf->vb.height != vv->video_fmt.height || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | buf->vb.size != size || |
| 1088 | buf->vb.field != field || |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1089 | buf->vb.field != vv->video_fmt.field || |
| 1090 | buf->fmt != &vv->video_fmt) { |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1091 | saa7146_dma_free(dev,q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1094 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | struct saa7146_format *sfmt; |
| 1096 | |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1097 | buf->vb.bytesperline = vv->video_fmt.bytesperline; |
| 1098 | buf->vb.width = vv->video_fmt.width; |
| 1099 | buf->vb.height = vv->video_fmt.height; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | buf->vb.size = size; |
| 1101 | buf->vb.field = field; |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1102 | buf->fmt = &vv->video_fmt; |
| 1103 | buf->vb.field = vv->video_fmt.field; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Mauro Carvalho Chehab | a757ee2 | 2010-12-02 01:57:03 -0200 | [diff] [blame] | 1105 | sfmt = saa7146_format_by_fourcc(dev,buf->fmt->pixelformat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
Johann Friedrichs | 311c70e | 2009-10-07 04:41:37 -0300 | [diff] [blame] | 1107 | release_all_pagetables(dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | if( 0 != IS_PLANAR(sfmt->trans)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | saa7146_pgtable_alloc(dev->pci, &buf->pt[0]); |
| 1110 | saa7146_pgtable_alloc(dev->pci, &buf->pt[1]); |
| 1111 | saa7146_pgtable_alloc(dev->pci, &buf->pt[2]); |
| 1112 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | saa7146_pgtable_alloc(dev->pci, &buf->pt[0]); |
| 1114 | } |
| 1115 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1116 | err = videobuf_iolock(q,&buf->vb, &vv->ov_fb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | if (err) |
| 1118 | goto oops; |
| 1119 | err = saa7146_pgtable_build(dev,buf); |
| 1120 | if (err) |
| 1121 | goto oops; |
| 1122 | } |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1123 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | buf->activate = buffer_activate; |
| 1125 | |
| 1126 | return 0; |
| 1127 | |
| 1128 | oops: |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1129 | DEB_D("error out\n"); |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1130 | saa7146_dma_free(dev,q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
| 1132 | return err; |
| 1133 | } |
| 1134 | |
| 1135 | static int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) |
| 1136 | { |
| 1137 | struct file *file = q->priv_data; |
| 1138 | struct saa7146_fh *fh = file->private_data; |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1139 | struct saa7146_vv *vv = fh->dev->vv_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | if (0 == *count || *count > MAX_SAA7146_CAPTURE_BUFFERS) |
| 1142 | *count = MAX_SAA7146_CAPTURE_BUFFERS; |
| 1143 | |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 1144 | *size = vv->video_fmt.sizeimage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
| 1146 | /* check if we exceed the "max_memory" parameter */ |
| 1147 | if( (*count * *size) > (max_memory*1048576) ) { |
| 1148 | *count = (max_memory*1048576) / *size; |
| 1149 | } |
| 1150 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1151 | DEB_CAP("%d buffers, %d bytes each\n", *count, *size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1157 | { |
| 1158 | struct file *file = q->priv_data; |
| 1159 | struct saa7146_fh *fh = file->private_data; |
| 1160 | struct saa7146_dev *dev = fh->dev; |
| 1161 | struct saa7146_vv *vv = dev->vv_data; |
| 1162 | struct saa7146_buf *buf = (struct saa7146_buf *)vb; |
| 1163 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1164 | DEB_CAP("vbuf:%p\n", vb); |
Hans Verkuil | 9bb6019 | 2012-05-01 11:45:27 -0300 | [diff] [blame] | 1165 | saa7146_buffer_queue(fh->dev, &vv->video_dmaq, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 1169 | { |
| 1170 | struct file *file = q->priv_data; |
| 1171 | struct saa7146_fh *fh = file->private_data; |
| 1172 | struct saa7146_dev *dev = fh->dev; |
| 1173 | struct saa7146_buf *buf = (struct saa7146_buf *)vb; |
| 1174 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1175 | DEB_CAP("vbuf:%p\n", vb); |
Johann Friedrichs | 311c70e | 2009-10-07 04:41:37 -0300 | [diff] [blame] | 1176 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 1177 | saa7146_dma_free(dev,q,buf); |
Mauro Carvalho Chehab | ba9e9f3 | 2010-02-01 21:23:46 -0200 | [diff] [blame] | 1178 | |
| 1179 | release_all_pagetables(dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | static struct videobuf_queue_ops video_qops = { |
| 1183 | .buf_setup = buffer_setup, |
| 1184 | .buf_prepare = buffer_prepare, |
| 1185 | .buf_queue = buffer_queue, |
| 1186 | .buf_release = buffer_release, |
| 1187 | }; |
| 1188 | |
| 1189 | /********************************************************************************/ |
| 1190 | /* file operations */ |
| 1191 | |
| 1192 | static void video_init(struct saa7146_dev *dev, struct saa7146_vv *vv) |
| 1193 | { |
Hans Verkuil | 9bb6019 | 2012-05-01 11:45:27 -0300 | [diff] [blame] | 1194 | INIT_LIST_HEAD(&vv->video_dmaq.queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Hans Verkuil | 9bb6019 | 2012-05-01 11:45:27 -0300 | [diff] [blame] | 1196 | init_timer(&vv->video_dmaq.timeout); |
| 1197 | vv->video_dmaq.timeout.function = saa7146_buffer_timeout; |
| 1198 | vv->video_dmaq.timeout.data = (unsigned long)(&vv->video_dmaq); |
| 1199 | vv->video_dmaq.dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | /* set some default values */ |
| 1202 | vv->standard = &dev->ext_vv_data->stds[0]; |
| 1203 | |
| 1204 | /* FIXME: what's this? */ |
| 1205 | vv->current_hps_source = SAA7146_HPS_SOURCE_PORT_A; |
| 1206 | vv->current_hps_sync = SAA7146_HPS_SYNC_PORT_A; |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | static int video_open(struct saa7146_dev *dev, struct file *file) |
| 1211 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1212 | struct saa7146_fh *fh = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 1214 | videobuf_queue_sg_init(&fh->video_q, &video_qops, |
| 1215 | &dev->pci->dev, &dev->slock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 1217 | V4L2_FIELD_INTERLACED, |
| 1218 | sizeof(struct saa7146_buf), |
Hans Verkuil | 9af3971 | 2010-12-18 09:20:59 -0300 | [diff] [blame] | 1219 | file, &dev->v4l2_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | static void video_close(struct saa7146_dev *dev, struct file *file) |
| 1226 | { |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1227 | struct saa7146_fh *fh = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | struct saa7146_vv *vv = dev->vv_data; |
Hartmut Birr | 2970c49 | 2007-04-22 06:57:26 -0300 | [diff] [blame] | 1229 | struct videobuf_queue *q = &fh->video_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Hans Verkuil | 7b4668e | 2011-08-25 09:54:30 -0300 | [diff] [blame] | 1231 | if (IS_CAPTURE_ACTIVE(fh) != 0) |
| 1232 | video_end(fh, file); |
| 1233 | else if (IS_OVERLAY_ACTIVE(fh) != 0) |
| 1234 | saa7146_stop_preview(fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Brandon Philips | 19bc513 | 2007-11-13 20:05:38 -0300 | [diff] [blame] | 1236 | videobuf_stop(q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | /* hmm, why is this function declared void? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | |
| 1241 | static void video_irq_done(struct saa7146_dev *dev, unsigned long st) |
| 1242 | { |
| 1243 | struct saa7146_vv *vv = dev->vv_data; |
Hans Verkuil | 9bb6019 | 2012-05-01 11:45:27 -0300 | [diff] [blame] | 1244 | struct saa7146_dmaqueue *q = &vv->video_dmaq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
| 1246 | spin_lock(&dev->slock); |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1247 | DEB_CAP("called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | /* only finish the buffer if we have one... */ |
| 1250 | if( NULL != q->curr ) { |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 1251 | saa7146_buffer_finish(dev,q,VIDEOBUF_DONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | } |
| 1253 | saa7146_buffer_next(dev,q,0); |
| 1254 | |
| 1255 | spin_unlock(&dev->slock); |
| 1256 | } |
| 1257 | |
| 1258 | static ssize_t video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
| 1259 | { |
| 1260 | struct saa7146_fh *fh = file->private_data; |
| 1261 | struct saa7146_dev *dev = fh->dev; |
| 1262 | struct saa7146_vv *vv = dev->vv_data; |
| 1263 | ssize_t ret = 0; |
| 1264 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1265 | DEB_EE("called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
| 1267 | if ((vv->video_status & STATUS_CAPTURE) != 0) { |
| 1268 | /* fixme: should we allow read() captures while streaming capture? */ |
| 1269 | if (vv->video_fh == fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1270 | DEB_S("already capturing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | return -EBUSY; |
| 1272 | } |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1273 | DEB_S("already capturing in another open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | return -EBUSY; |
| 1275 | } |
| 1276 | |
| 1277 | ret = video_begin(fh); |
| 1278 | if( 0 != ret) { |
| 1279 | goto out; |
| 1280 | } |
| 1281 | |
| 1282 | ret = videobuf_read_one(&fh->video_q , data, count, ppos, |
| 1283 | file->f_flags & O_NONBLOCK); |
| 1284 | if (ret != 0) { |
| 1285 | video_end(fh, file); |
| 1286 | } else { |
| 1287 | ret = video_end(fh, file); |
| 1288 | } |
| 1289 | out: |
| 1290 | /* restart overlay if it was active before */ |
| 1291 | if (vv->ov_suspend != NULL) { |
| 1292 | saa7146_start_preview(vv->ov_suspend); |
| 1293 | vv->ov_suspend = NULL; |
| 1294 | } |
| 1295 | |
| 1296 | return ret; |
| 1297 | } |
| 1298 | |
| 1299 | struct saa7146_use_ops saa7146_video_uops = { |
| 1300 | .init = video_init, |
| 1301 | .open = video_open, |
| 1302 | .release = video_close, |
| 1303 | .irq_done = video_irq_done, |
| 1304 | .read = video_read, |
| 1305 | }; |