PageRenderTime 88ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/media/video/saa7134/saa7134-vbi.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 255 lines | 177 code | 42 blank | 36 comment | 19 complexity | 307b4e655ecf67d902f71f3e0d4104b5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. *
  3. * device driver for philips saa7134 based TV cards
  4. * video4linux video interface
  5. *
  6. * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include "saa7134-reg.h"
  27. #include "saa7134.h"
  28. /* ------------------------------------------------------------------ */
  29. static unsigned int vbi_debug;
  30. module_param(vbi_debug, int, 0644);
  31. MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
  32. static unsigned int vbibufs = 4;
  33. module_param(vbibufs, int, 0444);
  34. MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
  35. #define dprintk(fmt, arg...) if (vbi_debug) \
  36. printk(KERN_DEBUG "%s/vbi: " fmt, dev->name , ## arg)
  37. /* ------------------------------------------------------------------ */
  38. #define VBI_LINE_COUNT 16
  39. #define VBI_LINE_LENGTH 2048
  40. #define VBI_SCALE 0x200
  41. static void task_init(struct saa7134_dev *dev, struct saa7134_buf *buf,
  42. int task)
  43. {
  44. struct saa7134_tvnorm *norm = dev->tvnorm;
  45. /* setup video scaler */
  46. saa_writeb(SAA7134_VBI_H_START1(task), norm->h_start & 0xff);
  47. saa_writeb(SAA7134_VBI_H_START2(task), norm->h_start >> 8);
  48. saa_writeb(SAA7134_VBI_H_STOP1(task), norm->h_stop & 0xff);
  49. saa_writeb(SAA7134_VBI_H_STOP2(task), norm->h_stop >> 8);
  50. saa_writeb(SAA7134_VBI_V_START1(task), norm->vbi_v_start_0 & 0xff);
  51. saa_writeb(SAA7134_VBI_V_START2(task), norm->vbi_v_start_0 >> 8);
  52. saa_writeb(SAA7134_VBI_V_STOP1(task), norm->vbi_v_stop_0 & 0xff);
  53. saa_writeb(SAA7134_VBI_V_STOP2(task), norm->vbi_v_stop_0 >> 8);
  54. saa_writeb(SAA7134_VBI_H_SCALE_INC1(task), VBI_SCALE & 0xff);
  55. saa_writeb(SAA7134_VBI_H_SCALE_INC2(task), VBI_SCALE >> 8);
  56. saa_writeb(SAA7134_VBI_PHASE_OFFSET_LUMA(task), 0x00);
  57. saa_writeb(SAA7134_VBI_PHASE_OFFSET_CHROMA(task), 0x00);
  58. saa_writeb(SAA7134_VBI_H_LEN1(task), buf->vb.width & 0xff);
  59. saa_writeb(SAA7134_VBI_H_LEN2(task), buf->vb.width >> 8);
  60. saa_writeb(SAA7134_VBI_V_LEN1(task), buf->vb.height & 0xff);
  61. saa_writeb(SAA7134_VBI_V_LEN2(task), buf->vb.height >> 8);
  62. saa_andorb(SAA7134_DATA_PATH(task), 0xc0, 0x00);
  63. }
  64. /* ------------------------------------------------------------------ */
  65. static int buffer_activate(struct saa7134_dev *dev,
  66. struct saa7134_buf *buf,
  67. struct saa7134_buf *next)
  68. {
  69. unsigned long control,base;
  70. dprintk("buffer_activate [%p]\n",buf);
  71. buf->vb.state = VIDEOBUF_ACTIVE;
  72. buf->top_seen = 0;
  73. task_init(dev,buf,TASK_A);
  74. task_init(dev,buf,TASK_B);
  75. saa_writeb(SAA7134_OFMT_DATA_A, 0x06);
  76. saa_writeb(SAA7134_OFMT_DATA_B, 0x06);
  77. /* DMA: setup channel 2+3 (= VBI Task A+B) */
  78. base = saa7134_buffer_base(buf);
  79. control = SAA7134_RS_CONTROL_BURST_16 |
  80. SAA7134_RS_CONTROL_ME |
  81. (buf->pt->dma >> 12);
  82. saa_writel(SAA7134_RS_BA1(2),base);
  83. saa_writel(SAA7134_RS_BA2(2),base + buf->vb.size/2);
  84. saa_writel(SAA7134_RS_PITCH(2),buf->vb.width);
  85. saa_writel(SAA7134_RS_CONTROL(2),control);
  86. saa_writel(SAA7134_RS_BA1(3),base);
  87. saa_writel(SAA7134_RS_BA2(3),base + buf->vb.size/2);
  88. saa_writel(SAA7134_RS_PITCH(3),buf->vb.width);
  89. saa_writel(SAA7134_RS_CONTROL(3),control);
  90. /* start DMA */
  91. saa7134_set_dmabits(dev);
  92. mod_timer(&dev->vbi_q.timeout, jiffies+BUFFER_TIMEOUT);
  93. return 0;
  94. }
  95. static int buffer_prepare(struct videobuf_queue *q,
  96. struct videobuf_buffer *vb,
  97. enum v4l2_field field)
  98. {
  99. struct saa7134_fh *fh = q->priv_data;
  100. struct saa7134_dev *dev = fh->dev;
  101. struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
  102. struct saa7134_tvnorm *norm = dev->tvnorm;
  103. unsigned int lines, llength, size;
  104. int err;
  105. lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
  106. if (lines > VBI_LINE_COUNT)
  107. lines = VBI_LINE_COUNT;
  108. llength = VBI_LINE_LENGTH;
  109. size = lines * llength * 2;
  110. if (0 != buf->vb.baddr && buf->vb.bsize < size)
  111. return -EINVAL;
  112. if (buf->vb.size != size)
  113. saa7134_dma_free(q,buf);
  114. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  115. struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
  116. buf->vb.width = llength;
  117. buf->vb.height = lines;
  118. buf->vb.size = size;
  119. buf->pt = &fh->pt_vbi;
  120. err = videobuf_iolock(q,&buf->vb,NULL);
  121. if (err)
  122. goto oops;
  123. err = saa7134_pgtable_build(dev->pci,buf->pt,
  124. dma->sglist,
  125. dma->sglen,
  126. saa7134_buffer_startpage(buf));
  127. if (err)
  128. goto oops;
  129. }
  130. buf->vb.state = VIDEOBUF_PREPARED;
  131. buf->activate = buffer_activate;
  132. buf->vb.field = field;
  133. return 0;
  134. oops:
  135. saa7134_dma_free(q,buf);
  136. return err;
  137. }
  138. static int
  139. buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
  140. {
  141. struct saa7134_fh *fh = q->priv_data;
  142. struct saa7134_dev *dev = fh->dev;
  143. int llength,lines;
  144. lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1;
  145. llength = VBI_LINE_LENGTH;
  146. *size = lines * llength * 2;
  147. if (0 == *count)
  148. *count = vbibufs;
  149. *count = saa7134_buffer_count(*size,*count);
  150. return 0;
  151. }
  152. static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  153. {
  154. struct saa7134_fh *fh = q->priv_data;
  155. struct saa7134_dev *dev = fh->dev;
  156. struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
  157. saa7134_buffer_queue(dev,&dev->vbi_q,buf);
  158. }
  159. static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
  160. {
  161. struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
  162. saa7134_dma_free(q,buf);
  163. }
  164. struct videobuf_queue_ops saa7134_vbi_qops = {
  165. .buf_setup = buffer_setup,
  166. .buf_prepare = buffer_prepare,
  167. .buf_queue = buffer_queue,
  168. .buf_release = buffer_release,
  169. };
  170. /* ------------------------------------------------------------------ */
  171. int saa7134_vbi_init1(struct saa7134_dev *dev)
  172. {
  173. INIT_LIST_HEAD(&dev->vbi_q.queue);
  174. init_timer(&dev->vbi_q.timeout);
  175. dev->vbi_q.timeout.function = saa7134_buffer_timeout;
  176. dev->vbi_q.timeout.data = (unsigned long)(&dev->vbi_q);
  177. dev->vbi_q.dev = dev;
  178. if (vbibufs < 2)
  179. vbibufs = 2;
  180. if (vbibufs > VIDEO_MAX_FRAME)
  181. vbibufs = VIDEO_MAX_FRAME;
  182. return 0;
  183. }
  184. int saa7134_vbi_fini(struct saa7134_dev *dev)
  185. {
  186. /* nothing */
  187. return 0;
  188. }
  189. void saa7134_irq_vbi_done(struct saa7134_dev *dev, unsigned long status)
  190. {
  191. spin_lock(&dev->slock);
  192. if (dev->vbi_q.curr) {
  193. dev->vbi_fieldcount++;
  194. /* make sure we have seen both fields */
  195. if ((status & 0x10) == 0x00) {
  196. dev->vbi_q.curr->top_seen = 1;
  197. goto done;
  198. }
  199. if (!dev->vbi_q.curr->top_seen)
  200. goto done;
  201. dev->vbi_q.curr->vb.field_count = dev->vbi_fieldcount;
  202. saa7134_buffer_finish(dev,&dev->vbi_q,VIDEOBUF_DONE);
  203. }
  204. saa7134_buffer_next(dev,&dev->vbi_q);
  205. done:
  206. spin_unlock(&dev->slock);
  207. }
  208. /* ----------------------------------------------------------- */
  209. /*
  210. * Local variables:
  211. * c-basic-offset: 8
  212. * End:
  213. */