tw68.h 5.4 KB

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