cx88-vbi.c 6.3 KB

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