cx88-vbi.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. */
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include "cx88.h"
  7. static unsigned int vbibufs = 4;
  8. module_param(vbibufs,int,0644);
  9. MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
  10. static unsigned int vbi_debug;
  11. module_param(vbi_debug,int,0644);
  12. MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
  13. #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
  14. printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
  15. /* ------------------------------------------------------------------ */
  16. int cx8800_vbi_fmt (struct file *file, void *priv,
  17. struct v4l2_format *f)
  18. {
  19. struct cx8800_fh *fh = priv;
  20. struct cx8800_dev *dev = fh->dev;
  21. f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
  22. f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  23. f->fmt.vbi.offset = 244;
  24. f->fmt.vbi.count[0] = VBI_LINE_COUNT;
  25. f->fmt.vbi.count[1] = VBI_LINE_COUNT;
  26. if (dev->core->tvnorm & V4L2_STD_525_60) {
  27. /* ntsc */
  28. f->fmt.vbi.sampling_rate = 28636363;
  29. f->fmt.vbi.start[0] = 10;
  30. f->fmt.vbi.start[1] = 273;
  31. } else if (dev->core->tvnorm & V4L2_STD_625_50) {
  32. /* pal */
  33. f->fmt.vbi.sampling_rate = 35468950;
  34. f->fmt.vbi.start[0] = 7 -1;
  35. f->fmt.vbi.start[1] = 319 -1;
  36. }
  37. return 0;
  38. }
  39. static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
  40. struct cx88_dmaqueue *q,
  41. struct cx88_buffer *buf)
  42. {
  43. struct cx88_core *core = dev->core;
  44. /* setup fifo + format */
  45. cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24],
  46. buf->vb.width, buf->risc.dma);
  47. cx_write(MO_VBOS_CONTROL, ( (1 << 18) | // comb filter delay fixup
  48. (1 << 15) | // enable vbi capture
  49. (1 << 11) ));
  50. /* reset counter */
  51. cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET);
  52. q->count = 1;
  53. /* enable irqs */
  54. cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
  55. cx_set(MO_VID_INTMSK, 0x0f0088);
  56. /* enable capture */
  57. cx_set(VID_CAPTURE_CONTROL,0x18);
  58. /* start dma */
  59. cx_set(MO_DEV_CNTRL2, (1<<5));
  60. cx_set(MO_VID_DMACNTRL, 0x88);
  61. return 0;
  62. }
  63. int cx8800_stop_vbi_dma(struct cx8800_dev *dev)
  64. {
  65. struct cx88_core *core = dev->core;
  66. /* stop dma */
  67. cx_clear(MO_VID_DMACNTRL, 0x88);
  68. /* disable capture */
  69. cx_clear(VID_CAPTURE_CONTROL,0x18);
  70. /* disable irqs */
  71. cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
  72. cx_clear(MO_VID_INTMSK, 0x0f0088);
  73. return 0;
  74. }
  75. int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
  76. struct cx88_dmaqueue *q)
  77. {
  78. struct cx88_buffer *buf;
  79. if (list_empty(&q->active))
  80. return 0;
  81. buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
  82. dprintk(2,"restart_queue [%p/%d]: restart dma\n",
  83. buf, buf->vb.i);
  84. cx8800_start_vbi_dma(dev, q, buf);
  85. list_for_each_entry(buf, &q->active, vb.queue)
  86. buf->count = q->count++;
  87. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  88. return 0;
  89. }
  90. void cx8800_vbi_timeout(unsigned long data)
  91. {
  92. struct cx8800_dev *dev = (struct cx8800_dev*)data;
  93. struct cx88_core *core = dev->core;
  94. struct cx88_dmaqueue *q = &dev->vbiq;
  95. struct cx88_buffer *buf;
  96. unsigned long flags;
  97. cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH24]);
  98. cx_clear(MO_VID_DMACNTRL, 0x88);
  99. cx_clear(VID_CAPTURE_CONTROL, 0x18);
  100. spin_lock_irqsave(&dev->slock,flags);
  101. while (!list_empty(&q->active)) {
  102. buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
  103. list_del(&buf->vb.queue);
  104. buf->vb.state = VIDEOBUF_ERROR;
  105. wake_up(&buf->vb.done);
  106. printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name,
  107. buf, buf->vb.i, (unsigned long)buf->risc.dma);
  108. }
  109. cx8800_restart_vbi_queue(dev,q);
  110. spin_unlock_irqrestore(&dev->slock,flags);
  111. }
  112. /* ------------------------------------------------------------------ */
  113. static int
  114. vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
  115. {
  116. *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
  117. if (0 == *count)
  118. *count = vbibufs;
  119. if (*count < 2)
  120. *count = 2;
  121. if (*count > 32)
  122. *count = 32;
  123. return 0;
  124. }
  125. static int
  126. vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
  127. enum v4l2_field field)
  128. {
  129. struct cx8800_fh *fh = q->priv_data;
  130. struct cx8800_dev *dev = fh->dev;
  131. struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
  132. unsigned int size;
  133. int rc;
  134. size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
  135. if (0 != buf->vb.baddr && buf->vb.bsize < size)
  136. return -EINVAL;
  137. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  138. struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
  139. buf->vb.width = VBI_LINE_LENGTH;
  140. buf->vb.height = VBI_LINE_COUNT;
  141. buf->vb.size = size;
  142. buf->vb.field = V4L2_FIELD_SEQ_TB;
  143. if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
  144. goto fail;
  145. cx88_risc_buffer(dev->pci, &buf->risc,
  146. dma->sglist,
  147. 0, buf->vb.width * buf->vb.height,
  148. buf->vb.width, 0,
  149. buf->vb.height);
  150. }
  151. buf->vb.state = VIDEOBUF_PREPARED;
  152. return 0;
  153. fail:
  154. cx88_free_buffer(q,buf);
  155. return rc;
  156. }
  157. static void
  158. vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  159. {
  160. struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
  161. struct cx88_buffer *prev;
  162. struct cx8800_fh *fh = vq->priv_data;
  163. struct cx8800_dev *dev = fh->dev;
  164. struct cx88_dmaqueue *q = &dev->vbiq;
  165. /* add jump to stopper */
  166. buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
  167. buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
  168. if (list_empty(&q->active)) {
  169. list_add_tail(&buf->vb.queue,&q->active);
  170. cx8800_start_vbi_dma(dev, q, buf);
  171. buf->vb.state = VIDEOBUF_ACTIVE;
  172. buf->count = q->count++;
  173. mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
  174. dprintk(2,"[%p/%d] vbi_queue - first active\n",
  175. buf, buf->vb.i);
  176. } else {
  177. prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
  178. list_add_tail(&buf->vb.queue,&q->active);
  179. buf->vb.state = VIDEOBUF_ACTIVE;
  180. buf->count = q->count++;
  181. prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  182. dprintk(2,"[%p/%d] buffer_queue - append to active\n",
  183. buf, buf->vb.i);
  184. }
  185. }
  186. static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  187. {
  188. struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
  189. cx88_free_buffer(q,buf);
  190. }
  191. const struct videobuf_queue_ops cx8800_vbi_qops = {
  192. .buf_setup = vbi_setup,
  193. .buf_prepare = vbi_prepare,
  194. .buf_queue = vbi_queue,
  195. .buf_release = vbi_release,
  196. };
  197. /* ------------------------------------------------------------------ */
  198. /*
  199. * Local variables:
  200. * c-basic-offset: 8
  201. * End:
  202. */