tw68.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * tw68 driver common header file
  3. *
  4. * Much of this code is derived from the cx88 and sa7134 drivers, which
  5. * were in turn derived from the bt87x driver. The original work was by
  6. * Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
  7. * Hans Verkuil, Andy Walls and many others. Their work is gratefully
  8. * acknowledged. Full credit goes to them - any problems within this code
  9. * are mine.
  10. *
  11. * Copyright (C) 2009 William M. Brack
  12. *
  13. * Refactored and updated to the latest v4l core frameworks:
  14. *
  15. * Copyright (C) 2014 Hans Verkuil <hverkuil@xs4all.nl>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. */
  27. #include <linux/pci.h>
  28. #include <linux/videodev2.h>
  29. #include <linux/notifier.h>
  30. #include <linux/delay.h>
  31. #include <linux/mutex.h>
  32. #include <linux/io.h>
  33. #include <media/v4l2-common.h>
  34. #include <media/v4l2-ioctl.h>
  35. #include <media/v4l2-ctrls.h>
  36. #include <media/v4l2-device.h>
  37. #include <media/videobuf2-v4l2.h>
  38. #include <media/videobuf2-dma-sg.h>
  39. #include "tw68-reg.h"
  40. #define UNSET (-1U)
  41. #define TW68_NORMS ( \
  42. V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM | \
  43. V4L2_STD_PAL_M | V4L2_STD_PAL_Nc | V4L2_STD_PAL_60)
  44. #define TW68_VID_INTS (TW68_FFERR | TW68_PABORT | TW68_DMAPERR | \
  45. TW68_FFOF | TW68_DMAPI)
  46. /* TW6800 chips have trouble with these, so we don't set them for that chip */
  47. #define TW68_VID_INTSX (TW68_FDMIS | TW68_HLOCK | TW68_VLOCK)
  48. #define TW68_I2C_INTS (TW68_SBERR | TW68_SBDONE | TW68_SBERR2 | \
  49. TW68_SBDONE2)
  50. enum tw68_decoder_type {
  51. TW6800,
  52. TW6801,
  53. TW6804,
  54. TWXXXX,
  55. };
  56. /* ----------------------------------------------------------- */
  57. /* static data */
  58. struct tw68_tvnorm {
  59. char *name;
  60. v4l2_std_id id;
  61. /* video decoder */
  62. u32 sync_control;
  63. u32 luma_control;
  64. u32 chroma_ctrl1;
  65. u32 chroma_gain;
  66. u32 chroma_ctrl2;
  67. u32 vgate_misc;
  68. /* video scaler */
  69. u32 h_delay;
  70. u32 h_delay0; /* for TW6800 */
  71. u32 h_start;
  72. u32 h_stop;
  73. u32 v_delay;
  74. u32 video_v_start;
  75. u32 video_v_stop;
  76. u32 vbi_v_start_0;
  77. u32 vbi_v_stop_0;
  78. u32 vbi_v_start_1;
  79. /* Techwell specific */
  80. u32 format;
  81. };
  82. struct tw68_format {
  83. char *name;
  84. u32 fourcc;
  85. u32 depth;
  86. u32 twformat;
  87. };
  88. /* ----------------------------------------------------------- */
  89. /* card configuration */
  90. #define TW68_BOARD_NOAUTO UNSET
  91. #define TW68_BOARD_UNKNOWN 0
  92. #define TW68_BOARD_GENERIC_6802 1
  93. #define TW68_MAXBOARDS 16
  94. #define TW68_INPUT_MAX 4
  95. /* ----------------------------------------------------------- */
  96. /* device / file handle status */
  97. #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
  98. struct tw68_dev; /* forward delclaration */
  99. /* buffer for one video/vbi/ts frame */
  100. struct tw68_buf {
  101. struct vb2_v4l2_buffer vb;
  102. struct list_head list;
  103. unsigned int size;
  104. __le32 *cpu;
  105. __le32 *jmp;
  106. dma_addr_t dma;
  107. };
  108. struct tw68_fmt {
  109. char *name;
  110. u32 fourcc; /* v4l2 format id */
  111. int depth;
  112. int flags;
  113. u32 twformat;
  114. };
  115. /* global device status */
  116. struct tw68_dev {
  117. struct mutex lock;
  118. spinlock_t slock;
  119. u16 instance;
  120. struct v4l2_device v4l2_dev;
  121. /* various device info */
  122. enum tw68_decoder_type vdecoder;
  123. struct video_device vdev;
  124. struct v4l2_ctrl_handler hdl;
  125. /* pci i/o */
  126. char *name;
  127. struct pci_dev *pci;
  128. unsigned char pci_rev, pci_lat;
  129. u32 __iomem *lmmio;
  130. u8 __iomem *bmmio;
  131. u32 pci_irqmask;
  132. /* The irq mask to be used will depend upon the chip type */
  133. u32 board_virqmask;
  134. /* video capture */
  135. const struct tw68_format *fmt;
  136. unsigned width, height;
  137. unsigned seqnr;
  138. unsigned field;
  139. struct vb2_queue vidq;
  140. struct list_head active;
  141. void *alloc_ctx;
  142. /* various v4l controls */
  143. const struct tw68_tvnorm *tvnorm; /* video */
  144. int input;
  145. };
  146. /* ----------------------------------------------------------- */
  147. #define tw_readl(reg) readl(dev->lmmio + ((reg) >> 2))
  148. #define tw_readb(reg) readb(dev->bmmio + (reg))
  149. #define tw_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
  150. #define tw_writeb(reg, value) writeb((value), dev->bmmio + (reg))
  151. #define tw_andorl(reg, mask, value) \
  152. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  153. ((value) & (mask)), dev->lmmio+((reg)>>2))
  154. #define tw_andorb(reg, mask, value) \
  155. writeb((readb(dev->bmmio + (reg)) & ~(mask)) |\
  156. ((value) & (mask)), dev->bmmio+(reg))
  157. #define tw_setl(reg, bit) tw_andorl((reg), (bit), (bit))
  158. #define tw_setb(reg, bit) tw_andorb((reg), (bit), (bit))
  159. #define tw_clearl(reg, bit) \
  160. writel((readl(dev->lmmio + ((reg) >> 2)) & ~(bit)), \
  161. dev->lmmio + ((reg) >> 2))
  162. #define tw_clearb(reg, bit) \
  163. writeb((readb(dev->bmmio+(reg)) & ~(bit)), \
  164. dev->bmmio + (reg))
  165. #define tw_wait(us) { udelay(us); }
  166. /* ----------------------------------------------------------- */
  167. /* tw68-video.c */
  168. void tw68_set_tvnorm_hw(struct tw68_dev *dev);
  169. int tw68_video_init1(struct tw68_dev *dev);
  170. int tw68_video_init2(struct tw68_dev *dev, int video_nr);
  171. void tw68_irq_video_done(struct tw68_dev *dev, unsigned long status);
  172. int tw68_video_start_dma(struct tw68_dev *dev, struct tw68_buf *buf);
  173. /* ----------------------------------------------------------- */
  174. /* tw68-risc.c */
  175. int tw68_risc_buffer(struct pci_dev *pci, struct tw68_buf *buf,
  176. struct scatterlist *sglist, unsigned int top_offset,
  177. unsigned int bottom_offset, unsigned int bpl,
  178. unsigned int padding, unsigned int lines);