cx88-vbi.c 6.3 KB

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