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