saa7146_fops.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  2. #include <media/drv-intf/saa7146_vv.h>
  3. #include <linux/module.h>
  4. /****************************************************************************/
  5. /* resource management functions, shamelessly stolen from saa7134 driver */
  6. int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
  7. {
  8. struct saa7146_dev *dev = fh->dev;
  9. struct saa7146_vv *vv = dev->vv_data;
  10. if (fh->resources & bit) {
  11. DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n",
  12. bit, vv->resources);
  13. /* have it already allocated */
  14. return 1;
  15. }
  16. /* is it free? */
  17. if (vv->resources & bit) {
  18. DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n",
  19. vv->resources, bit);
  20. /* no, someone else uses it */
  21. return 0;
  22. }
  23. /* it's free, grab it */
  24. fh->resources |= bit;
  25. vv->resources |= bit;
  26. DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources);
  27. return 1;
  28. }
  29. void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
  30. {
  31. struct saa7146_dev *dev = fh->dev;
  32. struct saa7146_vv *vv = dev->vv_data;
  33. BUG_ON((fh->resources & bits) != bits);
  34. fh->resources &= ~bits;
  35. vv->resources &= ~bits;
  36. DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources);
  37. }
  38. /********************************************************************************/
  39. /* common dma functions */
  40. void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
  41. struct saa7146_buf *buf)
  42. {
  43. struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
  44. DEB_EE("dev:%p, buf:%p\n", dev, buf);
  45. BUG_ON(in_interrupt());
  46. videobuf_waiton(q, &buf->vb, 0, 0);
  47. videobuf_dma_unmap(q->dev, dma);
  48. videobuf_dma_free(dma);
  49. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  50. }
  51. /********************************************************************************/
  52. /* common buffer functions */
  53. int saa7146_buffer_queue(struct saa7146_dev *dev,
  54. struct saa7146_dmaqueue *q,
  55. struct saa7146_buf *buf)
  56. {
  57. assert_spin_locked(&dev->slock);
  58. DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf);
  59. BUG_ON(!q);
  60. if (NULL == q->curr) {
  61. q->curr = buf;
  62. DEB_D("immediately activating buffer %p\n", buf);
  63. buf->activate(dev,buf,NULL);
  64. } else {
  65. list_add_tail(&buf->vb.queue,&q->queue);
  66. buf->vb.state = VIDEOBUF_QUEUED;
  67. DEB_D("adding buffer %p to queue. (active buffer present)\n",
  68. buf);
  69. }
  70. return 0;
  71. }
  72. void saa7146_buffer_finish(struct saa7146_dev *dev,
  73. struct saa7146_dmaqueue *q,
  74. int state)
  75. {
  76. assert_spin_locked(&dev->slock);
  77. DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state);
  78. DEB_EE("q->curr:%p\n", q->curr);
  79. BUG_ON(!q->curr);
  80. /* finish current buffer */
  81. if (NULL == q->curr) {
  82. DEB_D("aiii. no current buffer\n");
  83. return;
  84. }
  85. q->curr->vb.state = state;
  86. v4l2_get_timestamp(&q->curr->vb.ts);
  87. wake_up(&q->curr->vb.done);
  88. q->curr = NULL;
  89. }
  90. void saa7146_buffer_next(struct saa7146_dev *dev,
  91. struct saa7146_dmaqueue *q, int vbi)
  92. {
  93. struct saa7146_buf *buf,*next = NULL;
  94. BUG_ON(!q);
  95. DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi);
  96. assert_spin_locked(&dev->slock);
  97. if (!list_empty(&q->queue)) {
  98. /* activate next one from queue */
  99. buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
  100. list_del(&buf->vb.queue);
  101. if (!list_empty(&q->queue))
  102. next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
  103. q->curr = buf;
  104. DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n",
  105. buf, q->queue.prev, q->queue.next);
  106. buf->activate(dev,buf,next);
  107. } else {
  108. DEB_INT("no next buffer. stopping.\n");
  109. if( 0 != vbi ) {
  110. /* turn off video-dma3 */
  111. saa7146_write(dev,MC1, MASK_20);
  112. } else {
  113. /* nothing to do -- just prevent next video-dma1 transfer
  114. by lowering the protection address */
  115. // fixme: fix this for vflip != 0
  116. saa7146_write(dev, PROT_ADDR1, 0);
  117. saa7146_write(dev, MC2, (MASK_02|MASK_18));
  118. /* write the address of the rps-program */
  119. saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
  120. /* turn on rps */
  121. saa7146_write(dev, MC1, (MASK_12 | MASK_28));
  122. /*
  123. printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
  124. printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
  125. printk("vdma%d.prot_addr: 0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1));
  126. printk("vdma%d.base_page: 0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1));
  127. printk("vdma%d.pitch: 0x%08x\n", 1,saa7146_read(dev,PITCH1));
  128. printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1));
  129. */
  130. }
  131. del_timer(&q->timeout);
  132. }
  133. }
  134. void saa7146_buffer_timeout(struct timer_list *t)
  135. {
  136. struct saa7146_dmaqueue *q = from_timer(q, t, timeout);
  137. struct saa7146_dev *dev = q->dev;
  138. unsigned long flags;
  139. DEB_EE("dev:%p, dmaq:%p\n", dev, q);
  140. spin_lock_irqsave(&dev->slock,flags);
  141. if (q->curr) {
  142. DEB_D("timeout on %p\n", q->curr);
  143. saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
  144. }
  145. /* we don't restart the transfer here like other drivers do. when
  146. a streaming capture is disabled, the timeout function will be
  147. called for the current buffer. if we activate the next buffer now,
  148. we mess up our capture logic. if a timeout occurs on another buffer,
  149. then something is seriously broken before, so no need to buffer the
  150. next capture IMHO... */
  151. /*
  152. saa7146_buffer_next(dev,q);
  153. */
  154. spin_unlock_irqrestore(&dev->slock,flags);
  155. }
  156. /********************************************************************************/
  157. /* file operations */
  158. static int fops_open(struct file *file)
  159. {
  160. struct video_device *vdev = video_devdata(file);
  161. struct saa7146_dev *dev = video_drvdata(file);
  162. struct saa7146_fh *fh = NULL;
  163. int result = 0;
  164. DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
  165. if (mutex_lock_interruptible(vdev->lock))
  166. return -ERESTARTSYS;
  167. DEB_D("using: %p\n", dev);
  168. /* check if an extension is registered */
  169. if( NULL == dev->ext ) {
  170. DEB_S("no extension registered for this device\n");
  171. result = -ENODEV;
  172. goto out;
  173. }
  174. /* allocate per open data */
  175. fh = kzalloc(sizeof(*fh),GFP_KERNEL);
  176. if (NULL == fh) {
  177. DEB_S("cannot allocate memory for per open data\n");
  178. result = -ENOMEM;
  179. goto out;
  180. }
  181. v4l2_fh_init(&fh->fh, vdev);
  182. file->private_data = &fh->fh;
  183. fh->dev = dev;
  184. if (vdev->vfl_type == VFL_TYPE_VBI) {
  185. DEB_S("initializing vbi...\n");
  186. if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
  187. result = saa7146_vbi_uops.open(dev,file);
  188. if (dev->ext_vv_data->vbi_fops.open)
  189. dev->ext_vv_data->vbi_fops.open(file);
  190. } else {
  191. DEB_S("initializing video...\n");
  192. result = saa7146_video_uops.open(dev,file);
  193. }
  194. if (0 != result) {
  195. goto out;
  196. }
  197. if( 0 == try_module_get(dev->ext->module)) {
  198. result = -EINVAL;
  199. goto out;
  200. }
  201. result = 0;
  202. v4l2_fh_add(&fh->fh);
  203. out:
  204. if (fh && result != 0) {
  205. kfree(fh);
  206. file->private_data = NULL;
  207. }
  208. mutex_unlock(vdev->lock);
  209. return result;
  210. }
  211. static int fops_release(struct file *file)
  212. {
  213. struct video_device *vdev = video_devdata(file);
  214. struct saa7146_fh *fh = file->private_data;
  215. struct saa7146_dev *dev = fh->dev;
  216. DEB_EE("file:%p\n", file);
  217. mutex_lock(vdev->lock);
  218. if (vdev->vfl_type == VFL_TYPE_VBI) {
  219. if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
  220. saa7146_vbi_uops.release(dev,file);
  221. if (dev->ext_vv_data->vbi_fops.release)
  222. dev->ext_vv_data->vbi_fops.release(file);
  223. } else {
  224. saa7146_video_uops.release(dev,file);
  225. }
  226. v4l2_fh_del(&fh->fh);
  227. v4l2_fh_exit(&fh->fh);
  228. module_put(dev->ext->module);
  229. file->private_data = NULL;
  230. kfree(fh);
  231. mutex_unlock(vdev->lock);
  232. return 0;
  233. }
  234. static int fops_mmap(struct file *file, struct vm_area_struct * vma)
  235. {
  236. struct video_device *vdev = video_devdata(file);
  237. struct saa7146_fh *fh = file->private_data;
  238. struct videobuf_queue *q;
  239. int res;
  240. switch (vdev->vfl_type) {
  241. case VFL_TYPE_GRABBER: {
  242. DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",
  243. file, vma);
  244. q = &fh->video_q;
  245. break;
  246. }
  247. case VFL_TYPE_VBI: {
  248. DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",
  249. file, vma);
  250. if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
  251. return -ENODEV;
  252. q = &fh->vbi_q;
  253. break;
  254. }
  255. default:
  256. BUG();
  257. }
  258. if (mutex_lock_interruptible(vdev->lock))
  259. return -ERESTARTSYS;
  260. res = videobuf_mmap_mapper(q, vma);
  261. mutex_unlock(vdev->lock);
  262. return res;
  263. }
  264. static __poll_t __fops_poll(struct file *file, struct poll_table_struct *wait)
  265. {
  266. struct video_device *vdev = video_devdata(file);
  267. struct saa7146_fh *fh = file->private_data;
  268. struct videobuf_buffer *buf = NULL;
  269. struct videobuf_queue *q;
  270. __poll_t res = v4l2_ctrl_poll(file, wait);
  271. DEB_EE("file:%p, poll:%p\n", file, wait);
  272. if (vdev->vfl_type == VFL_TYPE_VBI) {
  273. if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
  274. return res | EPOLLOUT | EPOLLWRNORM;
  275. if( 0 == fh->vbi_q.streaming )
  276. return res | videobuf_poll_stream(file, &fh->vbi_q, wait);
  277. q = &fh->vbi_q;
  278. } else {
  279. DEB_D("using video queue\n");
  280. q = &fh->video_q;
  281. }
  282. if (!list_empty(&q->stream))
  283. buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
  284. if (!buf) {
  285. DEB_D("buf == NULL!\n");
  286. return res | EPOLLERR;
  287. }
  288. poll_wait(file, &buf->done, wait);
  289. if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
  290. DEB_D("poll succeeded!\n");
  291. return res | EPOLLIN | EPOLLRDNORM;
  292. }
  293. DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
  294. return res;
  295. }
  296. static __poll_t fops_poll(struct file *file, struct poll_table_struct *wait)
  297. {
  298. struct video_device *vdev = video_devdata(file);
  299. __poll_t res;
  300. mutex_lock(vdev->lock);
  301. res = __fops_poll(file, wait);
  302. mutex_unlock(vdev->lock);
  303. return res;
  304. }
  305. static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  306. {
  307. struct video_device *vdev = video_devdata(file);
  308. struct saa7146_fh *fh = file->private_data;
  309. int ret;
  310. switch (vdev->vfl_type) {
  311. case VFL_TYPE_GRABBER:
  312. /*
  313. DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun",
  314. file, data, (unsigned long)count);
  315. */
  316. return saa7146_video_uops.read(file,data,count,ppos);
  317. case VFL_TYPE_VBI:
  318. /*
  319. DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n",
  320. file, data, (unsigned long)count);
  321. */
  322. if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) {
  323. if (mutex_lock_interruptible(vdev->lock))
  324. return -ERESTARTSYS;
  325. ret = saa7146_vbi_uops.read(file, data, count, ppos);
  326. mutex_unlock(vdev->lock);
  327. return ret;
  328. }
  329. return -EINVAL;
  330. default:
  331. BUG();
  332. }
  333. }
  334. static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
  335. {
  336. struct video_device *vdev = video_devdata(file);
  337. struct saa7146_fh *fh = file->private_data;
  338. int ret;
  339. switch (vdev->vfl_type) {
  340. case VFL_TYPE_GRABBER:
  341. return -EINVAL;
  342. case VFL_TYPE_VBI:
  343. if (fh->dev->ext_vv_data->vbi_fops.write) {
  344. if (mutex_lock_interruptible(vdev->lock))
  345. return -ERESTARTSYS;
  346. ret = fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
  347. mutex_unlock(vdev->lock);
  348. return ret;
  349. }
  350. return -EINVAL;
  351. default:
  352. BUG();
  353. }
  354. }
  355. static const struct v4l2_file_operations video_fops =
  356. {
  357. .owner = THIS_MODULE,
  358. .open = fops_open,
  359. .release = fops_release,
  360. .read = fops_read,
  361. .write = fops_write,
  362. .poll = fops_poll,
  363. .mmap = fops_mmap,
  364. .unlocked_ioctl = video_ioctl2,
  365. };
  366. static void vv_callback(struct saa7146_dev *dev, unsigned long status)
  367. {
  368. u32 isr = status;
  369. DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status);
  370. if (0 != (isr & (MASK_27))) {
  371. DEB_INT("irq: RPS0 (0x%08x)\n", isr);
  372. saa7146_video_uops.irq_done(dev,isr);
  373. }
  374. if (0 != (isr & (MASK_28))) {
  375. u32 mc2 = saa7146_read(dev, MC2);
  376. if( 0 != (mc2 & MASK_15)) {
  377. DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr);
  378. wake_up(&dev->vv_data->vbi_wq);
  379. saa7146_write(dev,MC2, MASK_31);
  380. return;
  381. }
  382. DEB_INT("irq: RPS1 (0x%08x)\n", isr);
  383. saa7146_vbi_uops.irq_done(dev,isr);
  384. }
  385. }
  386. static const struct v4l2_ctrl_ops saa7146_ctrl_ops = {
  387. .s_ctrl = saa7146_s_ctrl,
  388. };
  389. int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
  390. {
  391. struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
  392. struct v4l2_pix_format *fmt;
  393. struct v4l2_vbi_format *vbi;
  394. struct saa7146_vv *vv;
  395. int err;
  396. err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
  397. if (err)
  398. return err;
  399. v4l2_ctrl_handler_init(hdl, 6);
  400. v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
  401. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  402. v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
  403. V4L2_CID_CONTRAST, 0, 127, 1, 64);
  404. v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
  405. V4L2_CID_SATURATION, 0, 127, 1, 64);
  406. v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
  407. V4L2_CID_VFLIP, 0, 1, 1, 0);
  408. v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
  409. V4L2_CID_HFLIP, 0, 1, 1, 0);
  410. if (hdl->error) {
  411. err = hdl->error;
  412. v4l2_ctrl_handler_free(hdl);
  413. return err;
  414. }
  415. dev->v4l2_dev.ctrl_handler = hdl;
  416. vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
  417. if (vv == NULL) {
  418. ERR("out of memory. aborting.\n");
  419. v4l2_ctrl_handler_free(hdl);
  420. return -ENOMEM;
  421. }
  422. ext_vv->vid_ops = saa7146_video_ioctl_ops;
  423. ext_vv->vbi_ops = saa7146_vbi_ioctl_ops;
  424. ext_vv->core_ops = &saa7146_video_ioctl_ops;
  425. DEB_EE("dev:%p\n", dev);
  426. /* set default values for video parts of the saa7146 */
  427. saa7146_write(dev, BCS_CTRL, 0x80400040);
  428. /* enable video-port pins */
  429. saa7146_write(dev, MC1, (MASK_10 | MASK_26));
  430. /* save per-device extension data (one extension can
  431. handle different devices that might need different
  432. configuration data) */
  433. dev->ext_vv_data = ext_vv;
  434. vv->d_clipping.cpu_addr =
  435. pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM,
  436. &vv->d_clipping.dma_handle);
  437. if( NULL == vv->d_clipping.cpu_addr ) {
  438. ERR("out of memory. aborting.\n");
  439. kfree(vv);
  440. v4l2_ctrl_handler_free(hdl);
  441. return -1;
  442. }
  443. saa7146_video_uops.init(dev,vv);
  444. if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
  445. saa7146_vbi_uops.init(dev,vv);
  446. vv->ov_fb.fmt.width = vv->standard->h_max_out;
  447. vv->ov_fb.fmt.height = vv->standard->v_max_out;
  448. vv->ov_fb.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
  449. vv->ov_fb.fmt.bytesperline = 2 * vv->ov_fb.fmt.width;
  450. vv->ov_fb.fmt.sizeimage = vv->ov_fb.fmt.bytesperline * vv->ov_fb.fmt.height;
  451. vv->ov_fb.fmt.colorspace = V4L2_COLORSPACE_SRGB;
  452. fmt = &vv->video_fmt;
  453. fmt->width = 384;
  454. fmt->height = 288;
  455. fmt->pixelformat = V4L2_PIX_FMT_BGR24;
  456. fmt->field = V4L2_FIELD_ANY;
  457. fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
  458. fmt->bytesperline = 3 * fmt->width;
  459. fmt->sizeimage = fmt->bytesperline * fmt->height;
  460. vbi = &vv->vbi_fmt;
  461. vbi->sampling_rate = 27000000;
  462. vbi->offset = 248; /* todo */
  463. vbi->samples_per_line = 720 * 2;
  464. vbi->sample_format = V4L2_PIX_FMT_GREY;
  465. /* fixme: this only works for PAL */
  466. vbi->start[0] = 5;
  467. vbi->count[0] = 16;
  468. vbi->start[1] = 312;
  469. vbi->count[1] = 16;
  470. timer_setup(&vv->vbi_read_timeout, NULL, 0);
  471. vv->ov_fb.capability = V4L2_FBUF_CAP_LIST_CLIPPING;
  472. vv->ov_fb.flags = V4L2_FBUF_FLAG_PRIMARY;
  473. dev->vv_data = vv;
  474. dev->vv_callback = &vv_callback;
  475. return 0;
  476. }
  477. EXPORT_SYMBOL_GPL(saa7146_vv_init);
  478. int saa7146_vv_release(struct saa7146_dev* dev)
  479. {
  480. struct saa7146_vv *vv = dev->vv_data;
  481. DEB_EE("dev:%p\n", dev);
  482. v4l2_device_unregister(&dev->v4l2_dev);
  483. pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
  484. v4l2_ctrl_handler_free(&dev->ctrl_handler);
  485. kfree(vv);
  486. dev->vv_data = NULL;
  487. dev->vv_callback = NULL;
  488. return 0;
  489. }
  490. EXPORT_SYMBOL_GPL(saa7146_vv_release);
  491. int saa7146_register_device(struct video_device *vfd, struct saa7146_dev *dev,
  492. char *name, int type)
  493. {
  494. int err;
  495. int i;
  496. DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type);
  497. vfd->fops = &video_fops;
  498. if (type == VFL_TYPE_GRABBER)
  499. vfd->ioctl_ops = &dev->ext_vv_data->vid_ops;
  500. else
  501. vfd->ioctl_ops = &dev->ext_vv_data->vbi_ops;
  502. vfd->release = video_device_release_empty;
  503. vfd->lock = &dev->v4l2_lock;
  504. vfd->v4l2_dev = &dev->v4l2_dev;
  505. vfd->tvnorms = 0;
  506. for (i = 0; i < dev->ext_vv_data->num_stds; i++)
  507. vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
  508. strlcpy(vfd->name, name, sizeof(vfd->name));
  509. video_set_drvdata(vfd, dev);
  510. err = video_register_device(vfd, type, -1);
  511. if (err < 0) {
  512. ERR("cannot register v4l2 device. skipping.\n");
  513. return err;
  514. }
  515. pr_info("%s: registered device %s [v4l2]\n",
  516. dev->name, video_device_node_name(vfd));
  517. return 0;
  518. }
  519. EXPORT_SYMBOL_GPL(saa7146_register_device);
  520. int saa7146_unregister_device(struct video_device *vfd, struct saa7146_dev *dev)
  521. {
  522. DEB_EE("dev:%p\n", dev);
  523. video_unregister_device(vfd);
  524. return 0;
  525. }
  526. EXPORT_SYMBOL_GPL(saa7146_unregister_device);
  527. static int __init saa7146_vv_init_module(void)
  528. {
  529. return 0;
  530. }
  531. static void __exit saa7146_vv_cleanup_module(void)
  532. {
  533. }
  534. module_init(saa7146_vv_init_module);
  535. module_exit(saa7146_vv_cleanup_module);
  536. MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
  537. MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware");
  538. MODULE_LICENSE("GPL");