tw68.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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-dma-sg.h>
  38. #include "tw68-reg.h"
  39. #define UNSET (-1U)
  40. /* system vendor and device ID's */
  41. #define PCI_VENDOR_ID_TECHWELL 0x1797
  42. #define PCI_DEVICE_ID_6800 0x6800
  43. #define PCI_DEVICE_ID_6801 0x6801
  44. #define PCI_DEVICE_ID_AUDIO2 0x6802
  45. #define PCI_DEVICE_ID_TS3 0x6803
  46. #define PCI_DEVICE_ID_6804 0x6804
  47. #define PCI_DEVICE_ID_AUDIO5 0x6805
  48. #define PCI_DEVICE_ID_TS6 0x6806
  49. /* tw6816 based cards */
  50. #define PCI_DEVICE_ID_6816_1 0x6810
  51. #define PCI_DEVICE_ID_6816_2 0x6811
  52. #define PCI_DEVICE_ID_6816_3 0x6812
  53. #define PCI_DEVICE_ID_6816_4 0x6813
  54. #define TW68_NORMS ( \
  55. V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM | \
  56. V4L2_STD_PAL_M | V4L2_STD_PAL_Nc | V4L2_STD_PAL_60)
  57. #define TW68_VID_INTS (TW68_FFERR | TW68_PABORT | TW68_DMAPERR | \
  58. TW68_FFOF | TW68_DMAPI)
  59. /* TW6800 chips have trouble with these, so we don't set them for that chip */
  60. #define TW68_VID_INTSX (TW68_FDMIS | TW68_HLOCK | TW68_VLOCK)
  61. #define TW68_I2C_INTS (TW68_SBERR | TW68_SBDONE | TW68_SBERR2 | \
  62. TW68_SBDONE2)
  63. enum tw68_decoder_type {
  64. TW6800,
  65. TW6801,
  66. TW6804,
  67. TWXXXX,
  68. };
  69. /* ----------------------------------------------------------- */
  70. /* static data */
  71. struct tw68_tvnorm {
  72. char *name;
  73. v4l2_std_id id;
  74. /* video decoder */
  75. u32 sync_control;
  76. u32 luma_control;
  77. u32 chroma_ctrl1;
  78. u32 chroma_gain;
  79. u32 chroma_ctrl2;
  80. u32 vgate_misc;
  81. /* video scaler */
  82. u32 h_delay;
  83. u32 h_delay0; /* for TW6800 */
  84. u32 h_start;
  85. u32 h_stop;
  86. u32 v_delay;
  87. u32 video_v_start;
  88. u32 video_v_stop;
  89. u32 vbi_v_start_0;
  90. u32 vbi_v_stop_0;
  91. u32 vbi_v_start_1;
  92. /* Techwell specific */
  93. u32 format;
  94. };
  95. struct tw68_format {
  96. char *name;
  97. u32 fourcc;
  98. u32 depth;
  99. u32 twformat;
  100. };
  101. /* ----------------------------------------------------------- */
  102. /* card configuration */
  103. #define TW68_BOARD_NOAUTO UNSET
  104. #define TW68_BOARD_UNKNOWN 0
  105. #define TW68_BOARD_GENERIC_6802 1
  106. #define TW68_MAXBOARDS 16
  107. #define TW68_INPUT_MAX 4
  108. /* ----------------------------------------------------------- */
  109. /* device / file handle status */
  110. #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
  111. struct tw68_dev; /* forward delclaration */
  112. /* buffer for one video/vbi/ts frame */
  113. struct tw68_buf {
  114. struct vb2_buffer vb;
  115. struct list_head list;
  116. unsigned int size;
  117. __le32 *cpu;
  118. __le32 *jmp;
  119. dma_addr_t dma;
  120. };
  121. struct tw68_fmt {
  122. char *name;
  123. u32 fourcc; /* v4l2 format id */
  124. int depth;
  125. int flags;
  126. u32 twformat;
  127. };
  128. /* global device status */
  129. struct tw68_dev {
  130. struct mutex lock;
  131. spinlock_t slock;
  132. u16 instance;
  133. struct v4l2_device v4l2_dev;
  134. /* various device info */
  135. enum tw68_decoder_type vdecoder;
  136. struct video_device vdev;
  137. struct v4l2_ctrl_handler hdl;
  138. /* pci i/o */
  139. char *name;
  140. struct pci_dev *pci;
  141. unsigned char pci_rev, pci_lat;
  142. u32 __iomem *lmmio;
  143. u8 __iomem *bmmio;
  144. u32 pci_irqmask;
  145. /* The irq mask to be used will depend upon the chip type */
  146. u32 board_virqmask;
  147. /* video capture */
  148. const struct tw68_format *fmt;
  149. unsigned width, height;
  150. unsigned seqnr;
  151. unsigned field;
  152. struct vb2_queue vidq;
  153. struct list_head active;
  154. void *alloc_ctx;
  155. /* various v4l controls */
  156. const struct tw68_tvnorm *tvnorm; /* video */
  157. int input;
  158. };
  159. /* ----------------------------------------------------------- */
  160. #define tw_readl(reg) readl(dev->lmmio + ((reg) >> 2))
  161. #define tw_readb(reg) readb(dev->bmmio + (reg))
  162. #define tw_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
  163. #define tw_writeb(reg, value) writeb((value), dev->bmmio + (reg))
  164. #define tw_andorl(reg, mask, value) \
  165. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  166. ((value) & (mask)), dev->lmmio+((reg)>>2))
  167. #define tw_andorb(reg, mask, value) \
  168. writeb((readb(dev->bmmio + (reg)) & ~(mask)) |\
  169. ((value) & (mask)), dev->bmmio+(reg))
  170. #define tw_setl(reg, bit) tw_andorl((reg), (bit), (bit))
  171. #define tw_setb(reg, bit) tw_andorb((reg), (bit), (bit))
  172. #define tw_clearl(reg, bit) \
  173. writel((readl(dev->lmmio + ((reg) >> 2)) & ~(bit)), \
  174. dev->lmmio + ((reg) >> 2))
  175. #define tw_clearb(reg, bit) \
  176. writeb((readb(dev->bmmio+(reg)) & ~(bit)), \
  177. dev->bmmio + (reg))
  178. #define tw_wait(us) { udelay(us); }
  179. /* ----------------------------------------------------------- */
  180. /* tw68-video.c */
  181. void tw68_set_tvnorm_hw(struct tw68_dev *dev);
  182. int tw68_video_init1(struct tw68_dev *dev);
  183. int tw68_video_init2(struct tw68_dev *dev, int video_nr);
  184. void tw68_irq_video_done(struct tw68_dev *dev, unsigned long status);
  185. int tw68_video_start_dma(struct tw68_dev *dev, struct tw68_buf *buf);
  186. /* ----------------------------------------------------------- */
  187. /* tw68-risc.c */
  188. int tw68_risc_buffer(struct pci_dev *pci, struct tw68_buf *buf,
  189. struct scatterlist *sglist, unsigned int top_offset,
  190. unsigned int bottom_offset, unsigned int bpl,
  191. unsigned int padding, unsigned int lines);