zr36120.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. zr36120.h - Zoran 36120/36125 based framegrabbers
  3. Copyright (C) 1998-1999 Pauline Middelink (middelin@polyware.nl)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef _ZR36120_H
  17. #define _ZR36120_H
  18. #ifdef __KERNEL__
  19. #include <linux/types.h>
  20. #include <linux/wait.h>
  21. #include <linux/i2c-old.h>
  22. #include <linux/videodev.h>
  23. #include <asm/io.h>
  24. /*
  25. * Debug macro's, place an x behind the ) for actual debug-compilation
  26. * E.g. #define DEBUG(x...) x
  27. */
  28. #define DEBUG(x...) /* Debug driver */
  29. #define IDEBUG(x...) /* Debug interrupt handler */
  30. #define PDEBUG 0 /* Debug PCI writes */
  31. /* defined in zr36120_i2c */
  32. extern struct i2c_bus zoran_i2c_bus_template;
  33. #define ZORAN_MAX_FBUFFERS 2
  34. #define ZORAN_MAX_FBUFFER (768*576*2)
  35. #define ZORAN_MAX_FBUFSIZE (ZORAN_MAX_FBUFFERS*ZORAN_MAX_FBUFFER)
  36. #define ZORAN_VBI_BUFFERS 2
  37. #define ZORAN_VBI_BUFSIZE (22*1024*2)
  38. struct tvcard {
  39. char* name; /* name of the cardtype */
  40. int video_inputs; /* number of channels defined in video_mux */
  41. int audio_inputs; /* number of channels defined in audio_mux */
  42. __u32 swapi2c:1, /* need to swap i2c wires SDA/SCL? */
  43. usegirq1:1, /* VSYNC at GIRQ1 instead of GIRQ0? */
  44. vsync_pos:1, /* positive VSYNC signal? */
  45. hsync_pos:1, /* positive HSYNC signal? */
  46. gpdir:8, /* General Purpose Direction register */
  47. gpval:8; /* General Purpose Value register */
  48. int video_mux[6]; /* mapping channel number to physical input */
  49. #define IS_TUNER 0x80
  50. #define IS_SVHS 0x40
  51. #define CHANNEL_MASK 0x3F
  52. int audio_mux[6]; /* mapping channel number to physical input */
  53. };
  54. #define TUNER(x) ((x)|IS_TUNER)
  55. #define SVHS(x) ((x)|IS_SVHS)
  56. struct vidinfo {
  57. struct vidinfo* next; /* next active buffer */
  58. uint kindof;
  59. #define FBUFFER_OVERLAY 0
  60. #define FBUFFER_GRAB 1
  61. #define FBUFFER_VBI 2
  62. uint status;
  63. #define FBUFFER_FREE 0
  64. #define FBUFFER_BUSY 1
  65. #define FBUFFER_DONE 2
  66. ulong fieldnr; /* # of field, not framer! */
  67. uint x,y;
  68. int w,h; /* w,h can be negative! */
  69. uint format; /* index in palette2fmt[] */
  70. uint bpp; /* lookup from palette2fmt[] */
  71. uint bpl; /* calc: width * bpp */
  72. ulong busadr; /* bus addr for DMA engine */
  73. char* memadr; /* kernel addr for making copies */
  74. ulong* overlay; /* kernel addr of overlay mask */
  75. };
  76. struct zoran
  77. {
  78. struct video_device video_dev;
  79. #define CARD_DEBUG KERN_DEBUG "%s(%lu): "
  80. #define CARD_INFO KERN_INFO "%s(%lu): "
  81. #define CARD_ERR KERN_ERR "%s(%lu): "
  82. #define CARD ztv->video_dev.name,ztv->fieldnr
  83. /* zoran chip specific details */
  84. struct i2c_bus i2c; /* i2c registration data */
  85. struct pci_dev* dev; /* ptr to PCI device */
  86. ulong zoran_adr; /* bus address of IO memory */
  87. char* zoran_mem; /* kernel address of IO memory */
  88. struct tvcard* card; /* the cardtype */
  89. uint norm; /* 0=PAL, 1=NTSC, 2=SECAM */
  90. uint tuner_freq; /* Current freq in kHz */
  91. struct video_picture picture; /* Current picture params */
  92. /* videocard details */
  93. uint swidth; /* screen width */
  94. uint sheight; /* screen height */
  95. uint depth; /* depth in bits */
  96. /* State details */
  97. char* fbuffer; /* framebuffers for mmap */
  98. struct vidinfo overinfo; /* overlay data */
  99. struct vidinfo grabinfo[ZORAN_MAX_FBUFFERS]; /* grabbing data*/
  100. wait_queue_head_t grabq; /* grabbers queue */
  101. /* VBI details */
  102. struct video_device vbi_dev;
  103. struct vidinfo readinfo[2]; /* VBI data - flip buffers */
  104. wait_queue_head_t vbiq; /* vbi queue */
  105. /* maintenance data */
  106. int have_decoder; /* did we detect a mux? */
  107. int have_tuner; /* did we detect a tuner? */
  108. int users; /* howmany video/vbi open? */
  109. int tuner_type; /* tuner type, when found */
  110. int running; /* are we rolling? */
  111. rwlock_t lock;
  112. long state; /* what is requested of us? */
  113. #define STATE_OVERLAY 0
  114. #define STATE_VBI 1
  115. struct vidinfo* workqueue; /* buffers to grab, head is active */
  116. ulong fieldnr; /* #field, ticked every VSYNC */
  117. ulong lastfieldnr; /* #field, ticked every GRAB */
  118. int vidInterlace; /* calculated */
  119. int vidXshift; /* calculated */
  120. uint vidWidth; /* calculated */
  121. uint vidHeight; /* calculated */
  122. };
  123. #define zrwrite(dat,adr) writel((dat),(char *) (ztv->zoran_mem+(adr)))
  124. #define zrread(adr) readl(ztv->zoran_mem+(adr))
  125. #if PDEBUG == 0
  126. #define zrand(dat,adr) zrwrite((dat) & zrread(adr), adr)
  127. #define zror(dat,adr) zrwrite((dat) | zrread(adr), adr)
  128. #define zraor(dat,mask,adr) zrwrite( ((dat)&~(mask)) | ((mask)&zrread(adr)), adr)
  129. #else
  130. #define zrand(dat, adr) \
  131. do { \
  132. ulong data = (dat) & zrread((adr)); \
  133. zrwrite(data, (adr)); \
  134. if (0 != (~(dat) & zrread((adr)))) \
  135. printk(KERN_DEBUG "zoran: zrand at %d(%d) detected set bits(%x)\n", __LINE__, (adr), (dat)); \
  136. } while(0)
  137. #define zror(dat, adr) \
  138. do { \
  139. ulong data = (dat) | zrread((adr)); \
  140. zrwrite(data, (adr)); \
  141. if ((dat) != ((dat) & zrread(adr))) \
  142. printk(KERN_DEBUG "zoran: zror at %d(%d) detected unset bits(%x)\n", __LINE__, (adr), (dat)); \
  143. } while(0)
  144. #define zraor(dat, mask, adr) \
  145. do { \
  146. ulong data; \
  147. if ((dat) & (mask)) \
  148. printk(KERN_DEBUG "zoran: zraor at %d(%d) detected bits(%x:%x)\n", __LINE__, (adr), (dat), (mask)); \
  149. data = ((dat)&~(mask)) | ((mask) & zrread((adr))); \
  150. zrwrite(data,(adr)); \
  151. if ( (dat) != (~(mask) & zrread((adr))) ) \
  152. printk(KERN_DEBUG "zoran: zraor at %d(%d) could not set all bits(%x:%x)\n", __LINE__, (adr), (dat), (mask)); \
  153. } while(0)
  154. #endif
  155. #endif
  156. /* zoran PCI address space */
  157. #define ZORAN_VFEH 0x000 /* Video Front End Horizontal Conf. */
  158. #define ZORAN_VFEH_HSPOL (1<<30)
  159. #define ZORAN_VFEH_HSTART (0x3FF<<10)
  160. #define ZORAN_VFEH_HEND (0x3FF<<0)
  161. #define ZORAN_VFEV 0x004 /* Video Front End Vertical Conf. */
  162. #define ZORAN_VFEV_VSPOL (1<<30)
  163. #define ZORAN_VFEV_VSTART (0x3FF<<10)
  164. #define ZORAN_VFEV_VEND (0x3FF<<0)
  165. #define ZORAN_VFEC 0x008 /* Video Front End Scaler and Pixel */
  166. #define ZORAN_VFEC_EXTFL (1<<26)
  167. #define ZORAN_VFEC_TOPFIELD (1<<25)
  168. #define ZORAN_VFEC_VCLKPOL (1<<24)
  169. #define ZORAN_VFEC_HFILTER (7<<21)
  170. #define ZORAN_VFEC_HFILTER_1 (0<<21) /* no lumi, 3-tap chromo */
  171. #define ZORAN_VFEC_HFILTER_2 (1<<21) /* 3-tap lumi, 3-tap chromo */
  172. #define ZORAN_VFEC_HFILTER_3 (2<<21) /* 4-tap lumi, 4-tap chromo */
  173. #define ZORAN_VFEC_HFILTER_4 (3<<21) /* 5-tap lumi, 4-tap chromo */
  174. #define ZORAN_VFEC_HFILTER_5 (4<<21) /* 4-tap lumi, 4-tap chromo */
  175. #define ZORAN_VFEC_DUPFLD (1<<20)
  176. #define ZORAN_VFEC_HORDCM (63<<14)
  177. #define ZORAN_VFEC_VERDCM (63<<8)
  178. #define ZORAN_VFEC_DISPMOD (1<<6)
  179. #define ZORAN_VFEC_RGB (3<<3)
  180. #define ZORAN_VFEC_RGB_YUV422 (0<<3)
  181. #define ZORAN_VFEC_RGB_RGB888 (1<<3)
  182. #define ZORAN_VFEC_RGB_RGB565 (2<<3)
  183. #define ZORAN_VFEC_RGB_RGB555 (3<<3)
  184. #define ZORAN_VFEC_ERRDIF (1<<2)
  185. #define ZORAN_VFEC_PACK24 (1<<1)
  186. #define ZORAN_VFEC_LE (1<<0)
  187. #define ZORAN_VTOP 0x00C /* Video Display "Top" */
  188. #define ZORAN_VBOT 0x010 /* Video Display "Bottom" */
  189. #define ZORAN_VSTR 0x014 /* Video Display Stride */
  190. #define ZORAN_VSTR_DISPSTRIDE (0xFFFF<<16)
  191. #define ZORAN_VSTR_VIDOVF (1<<8)
  192. #define ZORAN_VSTR_SNAPSHOT (1<<1)
  193. #define ZORAN_VSTR_GRAB (1<<0)
  194. #define ZORAN_VDC 0x018 /* Video Display Conf. */
  195. #define ZORAN_VDC_VIDEN (1<<31)
  196. #define ZORAN_VDC_MINPIX (0x1F<<25)
  197. #define ZORAN_VDC_TRICOM (1<<24)
  198. #define ZORAN_VDC_VIDWINHT (0x3FF<<12)
  199. #define ZORAN_VDC_VIDWINWID (0x3FF<<0)
  200. #define ZORAN_MTOP 0x01C /* Masking Map "Top" */
  201. #define ZORAN_MBOT 0x020 /* Masking Map "Bottom" */
  202. #define ZORAN_OCR 0x024 /* Overlay Control */
  203. #define ZORAN_OCR_OVLEN (1<<15)
  204. #define ZORAN_OCR_MASKSTRIDE (0xFF<<0)
  205. #define ZORAN_PCI 0x028 /* System, PCI and GPP Control */
  206. #define ZORAN_PCI_SOFTRESET (1<<24)
  207. #define ZORAN_PCI_WAITSTATE (3<<16)
  208. #define ZORAN_PCI_GENPURDIR (0xFF<<0)
  209. #define ZORAN_GUEST 0x02C /* GuestBus Control */
  210. #define ZORAN_CSOURCE 0x030 /* Code Source Address */
  211. #define ZORAN_CTRANS 0x034 /* Code Transfer Control */
  212. #define ZORAN_CMEM 0x038 /* Code Memory Pointer */
  213. #define ZORAN_ISR 0x03C /* Interrupt Status Register */
  214. #define ZORAN_ISR_CODE (1<<28)
  215. #define ZORAN_ISR_GIRQ0 (1<<29)
  216. #define ZORAN_ISR_GIRQ1 (1<<30)
  217. #define ZORAN_ICR 0x040 /* Interrupt Control Register */
  218. #define ZORAN_ICR_EN (1<<24)
  219. #define ZORAN_ICR_CODE (1<<28)
  220. #define ZORAN_ICR_GIRQ0 (1<<29)
  221. #define ZORAN_ICR_GIRQ1 (1<<30)
  222. #define ZORAN_I2C 0x044 /* I2C-Bus */
  223. #define ZORAN_I2C_SCL (1<<1)
  224. #define ZORAN_I2C_SDA (1<<0)
  225. #define ZORAN_POST 0x48 /* PostOffice */
  226. #define ZORAN_POST_PEN (1<<25)
  227. #define ZORAN_POST_TIME (1<<24)
  228. #define ZORAN_POST_DIR (1<<23)
  229. #define ZORAN_POST_GUESTID (3<<20)
  230. #define ZORAN_POST_GUEST (7<<16)
  231. #define ZORAN_POST_DATA (0xFF<<0)
  232. #endif