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