xref: /netbsd/sys/dev/pci/bktr/bktr_reg.h (revision bf9ec67e)
1 /*	$NetBSD: bktr_reg.h,v 1.10 2001/09/18 18:15:53 wiz Exp $	*/
2 
3 /*
4  * FreeBSD: src/sys/dev/bktr/bktr_reg.h,v 1.42 2000/10/31 13:09:56 roger Exp
5  *
6  * Copyright (c) 1999 Roger Hardiman
7  * Copyright (c) 1998 Amancio Hasty
8  * Copyright (c) 1995 Mark Tinguely and Jim Lowe
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by Mark Tinguely and Jim Lowe
22  * 4. The name of the author may not be used to endorse or promote products
23  *    derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #ifdef __FreeBSD__
40 #  if (__FreeBSD_version >= 310000)
41 #    include "smbus.h"
42 #  else
43 #    define NSMBUS 0		/* FreeBSD before 3.1 does not have SMBUS */
44 #  endif
45 #  if (NSMBUS > 0)
46 #    define BKTR_USE_FREEBSD_SMBUS
47 #  endif
48 #endif
49 
50 #ifdef __NetBSD__
51 #include <machine/bus.h>		/* struct device */
52 #include <sys/device.h>
53 #include <sys/select.h>			/* struct selinfo */
54 #include <sys/reboot.h>			/* AB_* for bootverbose */
55 #endif
56 
57 /*
58  * The kernel options for the driver now all begin with BKTR.
59  * Support the older kernel options on FreeBSD and OpenBSD.
60  *
61  */
62 #if defined(__FreeBSD__) || defined(__OpenBSD__)
63 #if defined(BROOKTREE_ALLOC_PAGES)
64 #define BKTR_ALLOC_PAGES BROOKTREE_ALLOC_PAGES
65 #endif
66 
67 #if defined(BROOKTREE_SYSTEM_DEFAULT)
68 #define BKTR_SYSTEM_DEFAULT BROOKTREE_SYSTEM_DEFAULT
69 #endif
70 
71 #if defined(OVERRIDE_CARD)
72 #define BKTR_OVERRIDE_CARD OVERRIDE_CARD
73 #endif
74 
75 #if defined(OVERRIDE_TUNER)
76 #define BKTR_OVERRIDE_TUNER OVERRIDE_TUNER
77 #endif
78 
79 #if defined(OVERRIDE_DBX)
80 #define BKTR_OVERRIDE_DBX OVERRIDE_DBX
81 #endif
82 
83 #if defined(OVERRIDE_MSP)
84 #define BKTR_OVERRIDE_MSP OVERRIDE_MSP
85 #endif
86 
87 #endif
88 
89 
90 #ifndef PCI_LATENCY_TIMER
91 #define	PCI_LATENCY_TIMER		0x0c	/* pci timer register */
92 #endif
93 
94 /*
95  * Definitions for the Brooktree 848/878 video capture to pci interface.
96  */
97 #ifndef __NetBSD__
98 #define PCI_VENDOR_SHIFT                        0
99 #define PCI_VENDOR_MASK                         0xffff
100 #define PCI_VENDOR(id) \
101             (((id) >> PCI_VENDOR_SHIFT) & PCI_VENDOR_MASK)
102 
103 #define PCI_PRODUCT_SHIFT                       16
104 #define PCI_PRODUCT_MASK                        0xffff
105 #define PCI_PRODUCT(id) \
106             (((id) >> PCI_PRODUCT_SHIFT) & PCI_PRODUCT_MASK)
107 
108 /* PCI vendor ID */
109 #define PCI_VENDOR_BROOKTREE    0x109e                /* Brooktree */
110 /* Brooktree products */
111 #define PCI_PRODUCT_BROOKTREE_BT848     0x0350        /* Bt848 Video Capture */
112 #define PCI_PRODUCT_BROOKTREE_BT849     0x0351        /* Bt849 Video Capture */
113 #define PCI_PRODUCT_BROOKTREE_BT878     0x036e        /* Bt878 Video Capture */
114 #define PCI_PRODUCT_BROOKTREE_BT879     0x036f        /* Bt879 Video Capture */
115 #endif
116 
117 #define BROOKTREE_848                   1
118 #define BROOKTREE_848A                  2
119 #define BROOKTREE_849A                  3
120 #define BROOKTREE_878                   4
121 #define BROOKTREE_879                   5
122 
123 typedef volatile u_int 	bregister_t;
124 /*
125  * if other persuasion endian, then compiler will probably require that
126  * these next
127  * macros be reversed
128  */
129 #define	BTBYTE(what)	bregister_t  what:8; int :24
130 #define	BTWORD(what)	bregister_t  what:16; int: 16
131 #define BTLONG(what)	bregister_t  what:32
132 
133 struct bt848_registers {
134     BTBYTE (dstatus);		/* 0, 1,2,3 */
135 #define BT848_DSTATUS_PRES		(1<<7)
136 #define BT848_DSTATUS_HLOC		(1<<6)
137 #define BT848_DSTATUS_FIELD		(1<<5)
138 #define BT848_DSTATUS_NUML		(1<<4)
139 #define BT848_DSTATUS_CSEL		(1<<3)
140 #define BT848_DSTATUS_PLOCK		(1<<2)
141 #define BT848_DSTATUS_LOF		(1<<1)
142 #define BT848_DSTATUS_COF		(1<<0)
143     BTBYTE (iform);		/* 4, 5,6,7 */
144 #define BT848_IFORM_MUXSEL		(0x3<<5)
145 # define BT848_IFORM_M_MUX1		(0x03<<5)
146 # define BT848_IFORM_M_MUX0		(0x02<<5)
147 # define BT848_IFORM_M_MUX2		(0x01<<5)
148 # define BT848_IFORM_M_MUX3		(0x0)
149 # define BT848_IFORM_M_RSVD		(0x00<<5)
150 #define BT848_IFORM_XTSEL		(0x3<<3)
151 # define BT848_IFORM_X_AUTO		(0x03<<3)
152 # define BT848_IFORM_X_XT1		(0x02<<3)
153 # define BT848_IFORM_X_XT0		(0x01<<3)
154 # define BT848_IFORM_X_RSVD		(0x00<<3)
155     BTBYTE (tdec);		/* 8, 9,a,b */
156     BTBYTE (e_crop);		/* c, d,e,f */
157     BTBYTE (e_vdelay_lo);	/* 10, 11,12,13 */
158     BTBYTE (e_vactive_lo);	/* 14, 15,16,17 */
159     BTBYTE (e_delay_lo);	/* 18, 19,1a,1b */
160     BTBYTE (e_hactive_lo);	/* 1c, 1d,1e,1f */
161     BTBYTE (e_hscale_hi);	/* 20, 21,22,23 */
162     BTBYTE (e_hscale_lo);	/* 24, 25,26,27 */
163     BTBYTE (bright);		/* 28, 29,2a,2b */
164     BTBYTE (e_control);		/* 2c, 2d,2e,2f */
165 #define BT848_E_CONTROL_LNOTCH		(1<<7)
166 #define BT848_E_CONTROL_COMP		(1<<6)
167 #define BT848_E_CONTROL_LDEC		(1<<5)
168 #define BT848_E_CONTROL_CBSENSE		(1<<4)
169 #define BT848_E_CONTROL_RSVD		(1<<3)
170 #define BT848_E_CONTROL_CON_MSB		(1<<2)
171 #define BT848_E_CONTROL_SAT_U_MSB	(1<<1)
172 #define BT848_E_CONTROL_SAT_V_MSB	(1<<0)
173     BTBYTE (contrast_lo);	/* 30, 31,32,33 */
174     BTBYTE (sat_u_lo);		/* 34, 35,36,37 */
175     BTBYTE (sat_v_lo);		/* 38, 39,3a,3b */
176     BTBYTE (hue);		/* 3c, 3d,3e,3f */
177     BTBYTE (e_scloop);		/* 40, 41,42,43 */
178 #define BT848_E_SCLOOP_RSVD1		(1<<7)
179 #define BT848_E_SCLOOP_CAGC		(1<<6)
180 #define BT848_E_SCLOOP_CKILL		(1<<5)
181 #define BT848_E_SCLOOP_HFILT		(0x3<<3)
182 # define BT848_E_SCLOOP_HFILT_ICON	(0x3<<3)
183 # define BT848_E_SCLOOP_HFILT_QCIF	(0x2<<3)
184 # define BT848_E_SCLOOP_HFILT_CIF	(0x1<<3)
185 # define BT848_E_SCLOOP_HFILT_AUTO	(0x0<<3)
186 #define BT848_E_SCLOOP_RSVD0		(0x7<<0)
187     int		:32;		/* 44, 45,46,47 */
188     BTBYTE (oform);		/* 48, 49,4a,4b */
189     BTBYTE (e_vscale_hi);	/* 4c, 4d,4e,4f */
190     BTBYTE (e_vscale_lo);	/* 50, 51,52,53 */
191     BTBYTE (test);		/* 54, 55,56,57 */
192     int		:32;		/* 58, 59,5a,5b */
193     int		:32;		/* 5c, 5d,5e,5f */
194     BTLONG (adelay);		/* 60, 61,62,63 */
195     BTBYTE (bdelay);		/* 64, 65,66,67 */
196     BTBYTE (adc);		/* 68, 69,6a,6b */
197 #define BT848_ADC_RESERVED		(0x80)	/* required pattern */
198 #define BT848_ADC_SYNC_T		(1<<5)
199 #define BT848_ADC_AGC_EN		(1<<4)
200 #define BT848_ADC_CLK_SLEEP		(1<<3)
201 #define BT848_ADC_Y_SLEEP		(1<<2)
202 #define BT848_ADC_C_SLEEP		(1<<1)
203 #define BT848_ADC_CRUSH			(1<<0)
204     BTBYTE (e_vtc);		/* 6c, 6d,6e,6f */
205     int		:32;		/* 70, 71,72,73 */
206     int 	:32;		/* 74, 75,76,77 */
207     int		:32;		/* 78, 79,7a,7b */
208     BTLONG (sreset);		/* 7c, 7d,7e,7f */
209     u_char 	filler1[0x84-0x80];
210     BTBYTE (tgctrl);		/* 84, 85,86,87 */
211 #define BT848_TGCTRL_TGCKI		(3<<3)
212 #define BT848_TGCTRL_TGCKI_XTAL		(0<<3)
213 #define BT848_TGCTRL_TGCKI_PLL		(1<<3)
214 #define BT848_TGCTRL_TGCKI_GPCLK	(2<<3)
215 #define BT848_TGCTRL_TGCKI_GPCLK_I	(3<<3)
216     u_char 	filler[0x8c-0x88];
217     BTBYTE (o_crop);		/* 8c, 8d,8e,8f */
218     BTBYTE (o_vdelay_lo);	/* 90, 91,92,93 */
219     BTBYTE (o_vactive_lo);	/* 94, 95,96,97 */
220     BTBYTE (o_delay_lo);	/* 98, 99,9a,9b */
221     BTBYTE (o_hactive_lo);	/* 9c, 9d,9e,9f */
222     BTBYTE (o_hscale_hi);	/* a0, a1,a2,a3 */
223     BTBYTE (o_hscale_lo);	/* a4, a5,a6,a7 */
224     int		:32;		/* a8, a9,aa,ab */
225     BTBYTE (o_control);		/* ac, ad,ae,af */
226 #define BT848_O_CONTROL_LNOTCH		(1<<7)
227 #define BT848_O_CONTROL_COMP		(1<<6)
228 #define BT848_O_CONTROL_LDEC		(1<<5)
229 #define BT848_O_CONTROL_CBSENSE		(1<<4)
230 #define BT848_O_CONTROL_RSVD		(1<<3)
231 #define BT848_O_CONTROL_CON_MSB		(1<<2)
232 #define BT848_O_CONTROL_SAT_U_MSB	(1<<1)
233 #define BT848_O_CONTROL_SAT_V_MSB	(1<<0)
234     u_char	fillter4[16];
235     BTBYTE (o_scloop);		/* c0, c1,c2,c3 */
236 #define BT848_O_SCLOOP_RSVD1		(1<<7)
237 #define BT848_O_SCLOOP_CAGC		(1<<6)
238 #define BT848_O_SCLOOP_CKILL		(1<<5)
239 #define BT848_O_SCLOOP_HFILT		(0x3<<3)
240 #define BT848_O_SCLOOP_HFILT_ICON	(0x3<<3)
241 #define BT848_O_SCLOOP_HFILT_QCIF	(0x2<<3)
242 #define BT848_O_SCLOOP_HFILT_CIF	(0x1<<3)
243 #define BT848_O_SCLOOP_HFILT_AUTO	(0x0<<3)
244 #define BT848_O_SCLOOP_RSVD0		(0x7<<0)
245     int		:32;		/* c4, c5,c6,c7 */
246     int		:32;		/* c8, c9,ca,cb */
247     BTBYTE (o_vscale_hi);	/* cc, cd,ce,cf */
248     BTBYTE (o_vscale_lo);	/* d0, d1,d2,d3 */
249     BTBYTE (color_fmt);		/* d4, d5,d6,d7 */
250     bregister_t color_ctl_swap		:4; /* d8 */
251 #define BT848_COLOR_CTL_WSWAP_ODD	(1<<3)
252 #define BT848_COLOR_CTL_WSWAP_EVEN	(1<<2)
253 #define BT848_COLOR_CTL_BSWAP_ODD	(1<<1)
254 #define BT848_COLOR_CTL_BSWAP_EVEN	(1<<0)
255     bregister_t color_ctl_gamma		:1;
256     bregister_t color_ctl_rgb_ded	:1;
257     bregister_t color_ctl_color_bars	:1;
258     bregister_t color_ctl_ext_frmrate	:1;
259 #define BT848_COLOR_CTL_GAMMA		(1<<4)
260 #define BT848_COLOR_CTL_RGB_DED		(1<<5)
261 #define BT848_COLOR_CTL_COLOR_BARS	(1<<6)
262 #define BT848_COLOR_CTL_EXT_FRMRATE     (1<<7)
263     int		:24;		/* d9,da,db */
264     BTBYTE (cap_ctl);		/* dc, dd,de,df */
265 #define BT848_CAP_CTL_DITH_FRAME	(1<<4)
266 #define BT848_CAP_CTL_VBI_ODD		(1<<3)
267 #define BT848_CAP_CTL_VBI_EVEN		(1<<2)
268 #define BT848_CAP_CTL_ODD		(1<<1)
269 #define BT848_CAP_CTL_EVEN		(1<<0)
270     BTBYTE (vbi_pack_size);	/* e0, e1,e2,e3 */
271     BTBYTE (vbi_pack_del);	/* e4, e5,e6,e7 */
272     int		:32;		/* e8, e9,ea,eb */
273     BTBYTE (o_vtc);		/* ec, ed,ee,ef */
274     BTBYTE (pll_f_lo);		/* f0, f1,f2,f3 */
275     BTBYTE (pll_f_hi);		/* f4, f5,f6,f7 */
276     BTBYTE (pll_f_xci);		/* f8, f9,fa,fb */
277 #define BT848_PLL_F_C			(1<<6)
278 #define BT848_PLL_F_X			(1<<7)
279     u_char	filler2[0x100-0xfc];
280     BTLONG (int_stat);		/* 100, 101,102,103 */
281     BTLONG (int_mask);		/* 104, 105,106,107 */
282 #define BT848_INT_RISCS			(0xf<<28)
283 #define BT848_INT_RISC_EN		(1<<27)
284 #define BT848_INT_RACK			(1<<25)
285 #define BT848_INT_FIELD			(1<<24)
286 #define BT848_INT_MYSTERYBIT		(1<<23)
287 #define BT848_INT_SCERR			(1<<19)
288 #define BT848_INT_OCERR			(1<<18)
289 #define BT848_INT_PABORT		(1<<17)
290 #define BT848_INT_RIPERR		(1<<16)
291 #define BT848_INT_PPERR			(1<<15)
292 #define BT848_INT_FDSR			(1<<14)
293 #define BT848_INT_FTRGT			(1<<13)
294 #define BT848_INT_FBUS			(1<<12)
295 #define BT848_INT_RISCI			(1<<11)
296 #define BT848_INT_GPINT			(1<<9)
297 #define BT848_INT_I2CDONE		(1<<8)
298 #define BT848_INT_RSV1			(1<<7)
299 #define BT848_INT_RSV0			(1<<6)
300 #define BT848_INT_VPRES			(1<<5)
301 #define BT848_INT_HLOCK			(1<<4)
302 #define BT848_INT_OFLOW			(1<<3)
303 #define BT848_INT_HSYNC			(1<<2)
304 #define BT848_INT_VSYNC			(1<<1)
305 #define BT848_INT_FMTCHG		(1<<0)
306     int		:32;		/* 108, 109,10a,10b */
307     BTWORD (gpio_dma_ctl);	/* 10c, 10d,10e,10f */
308 #define BT848_DMA_CTL_PL23TP4		(0<<6)	/* planar1 trigger 4 */
309 #define BT848_DMA_CTL_PL23TP8		(1<<6)	/* planar1 trigger 8 */
310 #define BT848_DMA_CTL_PL23TP16		(2<<6)	/* planar1 trigger 16 */
311 #define BT848_DMA_CTL_PL23TP32		(3<<6)	/* planar1 trigger 32 */
312 #define BT848_DMA_CTL_PL1TP4		(0<<4)	/* planar1 trigger 4 */
313 #define BT848_DMA_CTL_PL1TP8		(1<<4)	/* planar1 trigger 8 */
314 #define BT848_DMA_CTL_PL1TP16		(2<<4)	/* planar1 trigger 16 */
315 #define BT848_DMA_CTL_PL1TP32		(3<<4)	/* planar1 trigger 32 */
316 #define BT848_DMA_CTL_PKTP4		(0<<2)	/* packed trigger 4 */
317 #define BT848_DMA_CTL_PKTP8		(1<<2)	/* packed trigger 8 */
318 #define BT848_DMA_CTL_PKTP16		(2<<2)	/* packed trigger 16 */
319 #define BT848_DMA_CTL_PKTP32		(3<<2)	/* packed trigger 32 */
320 #define BT848_DMA_CTL_RISC_EN		(1<<1)
321 #define BT848_DMA_CTL_FIFO_EN		(1<<0)
322     BTLONG (i2c_data_ctl);	/* 110, 111,112,113 */
323 #define BT848_DATA_CTL_I2CDIV		(0xf<<4)
324 #define BT848_DATA_CTL_I2CSYNC		(1<<3)
325 #define BT848_DATA_CTL_I2CW3B		(1<<2)
326 #define BT848_DATA_CTL_I2CSCL		(1<<1)
327 #define BT848_DATA_CTL_I2CSDA		(1<<0)
328     BTLONG (risc_strt_add);	/* 114, 115,116,117 */
329     BTLONG (gpio_out_en);	/* 118, 119,11a,11b */	/* really 24 bits */
330     BTLONG (gpio_reg_inp);	/* 11c, 11d,11e,11f */	/* really 24 bits */
331     BTLONG (risc_count);	/* 120, 121,122,123 */
332     u_char	filler3[0x200-0x124];
333     BTLONG (gpio_data);		/* 200, 201,202,203 */	/* really 24 bits */
334 };
335 
336 
337 #define BKTR_DSTATUS			0x000
338 #define BKTR_IFORM			0x004
339 #define BKTR_TDEC			0x008
340 #define BKTR_E_CROP			0x00C
341 #define BKTR_O_CROP			0x08C
342 #define BKTR_E_VDELAY_LO		0x010
343 #define BKTR_O_VDELAY_LO		0x090
344 #define BKTR_E_VACTIVE_LO		0x014
345 #define BKTR_O_VACTIVE_LO		0x094
346 #define BKTR_E_DELAY_LO			0x018
347 #define BKTR_O_DELAY_LO			0x098
348 #define BKTR_E_HACTIVE_LO		0x01C
349 #define BKTR_O_HACTIVE_LO		0x09C
350 #define BKTR_E_HSCALE_HI		0x020
351 #define BKTR_O_HSCALE_HI		0x0A0
352 #define BKTR_E_HSCALE_LO		0x024
353 #define BKTR_O_HSCALE_LO		0x0A4
354 #define BKTR_BRIGHT			0x028
355 #define BKTR_E_CONTROL			0x02C
356 #define BKTR_O_CONTROL			0x0AC
357 #define BKTR_CONTRAST_LO		0x030
358 #define BKTR_SAT_U_LO			0x034
359 #define BKTR_SAT_V_LO			0x038
360 #define BKTR_HUE			0x03C
361 #define BKTR_E_SCLOOP			0x040
362 #define BKTR_O_SCLOOP			0x0C0
363 #define BKTR_OFORM			0x048
364 #define BKTR_E_VSCALE_HI		0x04C
365 #define BKTR_O_VSCALE_HI		0x0CC
366 #define BKTR_E_VSCALE_LO		0x050
367 #define BKTR_O_VSCALE_LO		0x0D0
368 #define BKTR_TEST			0x054
369 #define BKTR_ADELAY			0x060
370 #define BKTR_BDELAY			0x064
371 #define BKTR_ADC			0x068
372 #define BKTR_E_VTC			0x06C
373 #define BKTR_O_VTC			0x0EC
374 #define BKTR_SRESET			0x07C
375 #define BKTR_COLOR_FMT			0x0D4
376 #define BKTR_COLOR_CTL			0x0D8
377 #define BKTR_CAP_CTL			0x0DC
378 #define BKTR_VBI_PACK_SIZE		0x0E0
379 #define BKTR_VBI_PACK_DEL		0x0E4
380 #define BKTR_INT_STAT			0x100
381 #define BKTR_INT_MASK			0x104
382 #define BKTR_RISC_COUNT			0x120
383 #define BKTR_RISC_STRT_ADD		0x114
384 #define BKTR_GPIO_DMA_CTL		0x10C
385 #define BKTR_GPIO_OUT_EN		0x118
386 #define BKTR_GPIO_REG_INP		0x11C
387 #define BKTR_GPIO_DATA			0x200
388 #define BKTR_I2C_DATA_CTL		0x110
389 #define BKTR_TGCTRL			0x084
390 #define BKTR_PLL_F_LO			0x0F0
391 #define BKTR_PLL_F_HI			0x0F4
392 #define BKTR_PLL_F_XCI			0x0F8
393 
394 /*
395  * device support for onboard tv tuners
396  */
397 
398 /* description of the LOGICAL tuner */
399 struct TVTUNER {
400 	int		frequency;
401 	u_char		chnlset;
402 	u_char		channel;
403 	u_char		band;
404 	u_char		afc;
405  	u_char		radio_mode;	/* current mode of the radio mode */
406 };
407 
408 /* description of the PHYSICAL tuner */
409 struct TUNER {
410 	char*		name;
411 	u_char		type;
412 	u_char		pllControl[4];
413 	u_char		bandLimits[ 2 ];
414 	u_char		bandAddrs[ 4 ];        /* 3 first for the 3 TV
415 					       ** bands. Last for radio
416 					       ** band (0x00=NoRadio).
417 					       */
418 
419 };
420 
421 /* description of the card */
422 #define EEPROMBLOCKSIZE		32
423 struct CARDTYPE {
424 	unsigned int		card_id;	/* card id (from #define's) */
425 	char*			name;
426 	const struct TUNER*	tuner;		/* Tuner details */
427 	u_char			tuner_pllAddr;	/* Tuner i2c address */
428 	u_char			dbx;		/* Has DBX chip? */
429 	u_char			msp3400c;	/* Has msp3400c chip? */
430 	u_char			dpl3518a;	/* Has dpl3518a chip? */
431 	u_char			eepromAddr;
432 	u_char			eepromSize;	/* bytes / EEPROMBLOCKSIZE */
433 	u_int			audiomuxs[ 5 ];	/* tuner, ext (line-in) */
434 						/* int/unused (radio) */
435 						/* mute, present */
436 	u_int			gpio_mux_bits;	/* GPIO mask for audio mux */
437 };
438 
439 struct format_params {
440   /* Total lines, lines before image, image lines */
441   int vtotal, vdelay, vactive;
442   /* Total unscaled horizontal pixels, pixels before image, image pixels */
443   int htotal, hdelay, hactive;
444   /* Scaled horizontal image pixels, Total Scaled horizontal pixels */
445   int  scaled_hactive, scaled_htotal;
446   /* frame rate . for ntsc is 30 frames per second */
447   int frame_rate;
448   /* A-delay and B-delay */
449   u_char adelay, bdelay;
450   /* Iform XTSEL value */
451   int iform_xtsel;
452   /* VBI number of lines per field, and number of samples per line */
453   int vbi_num_lines, vbi_num_samples;
454 };
455 
456 #if defined(BKTR_USE_FREEBSD_SMBUS)
457 struct bktr_i2c_softc {
458 	device_t iicbus;
459 	device_t smbus;
460 };
461 #endif
462 
463 
464 /* Bt848/878 register access
465  * The registers can either be access via a memory mapped structure
466  * or accessed via bus_space.
467  * bus_0pace access allows cross platform support, where as the
468  * memory mapped structure method only works on 32 bit processors
469  * with the right type of endianness.
470  */
471 #if defined(__NetBSD__) || ( defined(__FreeBSD__) && (__FreeBSD_version >=300000) )
472 #define INB(bktr,offset)	bus_space_read_1((bktr)->memt,(bktr)->memh,(offset))
473 #define INW(bktr,offset)	bus_space_read_2((bktr)->memt,(bktr)->memh,(offset))
474 #define INL(bktr,offset)	bus_space_read_4((bktr)->memt,(bktr)->memh,(offset))
475 #define OUTB(bktr,offset,value) bus_space_write_1((bktr)->memt,(bktr)->memh,(offset),(value))
476 #define OUTW(bktr,offset,value) bus_space_write_2((bktr)->memt,(bktr)->memh,(offset),(value))
477 #define OUTL(bktr,offset,value) bus_space_write_4((bktr)->memt,(bktr)->memh,(offset),(value))
478 #else
479 #define INB(bktr,offset)	*(volatile unsigned char*) ((int)((bktr)->memh)+(offset))
480 #define INW(bktr,offset)	*(volatile unsigned short*)((int)((bktr)->memh)+(offset))
481 #define INL(bktr,offset)	*(volatile unsigned int*)  ((int)((bktr)->memh)+(offset))
482 #define OUTB(bktr,offset,value)	*(volatile unsigned char*) ((int)((bktr)->memh)+(offset)) = (value)
483 #define OUTW(bktr,offset,value)	*(volatile unsigned short*)((int)((bktr)->memh)+(offset)) = (value)
484 #define OUTL(bktr,offset,value)	*(volatile unsigned int*)  ((int)((bktr)->memh)+(offset)) = (value)
485 #endif
486 
487 
488 typedef struct bktr_clip bktr_clip_t;
489 
490 /*
491  * BrookTree 848  info structure, one per bt848 card installed.
492  */
493 struct bktr_softc {
494 
495 #if defined (__bsdi__)
496     struct device bktr_dev;	/* base device */
497     struct isadev bktr_id;	/* ISA device */
498     struct intrhand bktr_ih;	/* interrupt vectoring */
499     #define pcici_t pci_devaddr_t
500 #endif
501 
502 #if defined(__NetBSD__)
503     struct device bktr_dev;     /* base device */
504     bus_dma_tag_t	dmat;   /* DMA tag */
505     bus_space_tag_t	memt;
506     bus_space_handle_t	memh;
507     bus_size_t		obmemsz;        /* size of en card (bytes) */
508     void		*ih;
509     bus_dmamap_t	dm_prog;
510     bus_dmamap_t	dm_oprog;
511     bus_dmamap_t	dm_mem;
512     bus_dmamap_t	dm_vbidata;
513     bus_dmamap_t	dm_vbibuffer;
514 #endif
515 
516 #if defined(__OpenBSD__)
517     struct device bktr_dev;     /* base device */
518     bus_dma_tag_t	dmat;   /* DMA tag */
519     bus_space_tag_t	memt;
520     bus_space_handle_t	memh;
521     bus_size_t		obmemsz;        /* size of en card (bytes) */
522     void		*ih;
523     bus_dmamap_t	dm_prog;
524     bus_dmamap_t	dm_oprog;
525     bus_dmamap_t	dm_mem;
526     bus_dmamap_t	dm_vbidata;
527     bus_dmamap_t	dm_vbibuffer;
528     size_t		dm_mapsize;
529     pci_chipset_tag_t	pc;	/* Opaque PCI chipset tag */
530     pcitag_t		tag;	/* PCI tag, for doing PCI commands */
531     vm_offset_t		phys_base;	/* Bt848 register physical address */
532 #endif
533 
534 #if defined (__FreeBSD__)
535     #if (__FreeBSD_version < 400000)
536     vm_offset_t     phys_base;	/* 2.x Bt848 register physical address */
537     pcici_t         tag;	/* 2.x PCI tag, for doing PCI commands */
538     #endif
539     #if (__FreeBSD_version >= 400000)
540     int             mem_rid;	/* 4.x resource id */
541     struct resource *res_mem;	/* 4.x resource descriptor for registers */
542     int             irq_rid;	/* 4.x resource id */
543     struct resource *res_irq;	/* 4.x resource descriptor for interrupt */
544     void            *res_ih;	/* 4.x newbus interrupt handler cookie */
545     dev_t           bktrdev;	/* 4.x device entry for /dev/bktrN */
546     dev_t           tunerdev;	/* 4.x device entry for /dev/tunerN */
547     dev_t           vbidev;	/* 4.x device entry for /dev/vbiN */
548     dev_t           bktrdev_alias;	/* alias /dev/bktr to /dev/bktr0 */
549     dev_t           tunerdev_alias;	/* alias /dev/tuner to /dev/tuner0 */
550     dev_t           vbidev_alias;	/* alias /dev/vbi to /dev/vbi0 */
551     #endif
552     #if (__FreeBSD_version >= 310000)
553     bus_space_tag_t	memt;	/* Bus space register access functions */
554     bus_space_handle_t	memh;	/* Bus space register access functions */
555     bus_size_t		obmemsz;/* Size of card (bytes) */
556     #endif
557     #if (NSMBUS > 0)
558       struct bktr_i2c_softc i2c_sc;	/* bt848_i2c device */
559     #endif
560     char	bktr_xname[7];	/* device name and unit number */
561 #endif
562 
563 
564     /* The following definitions are for the contiguous memory */
565 #ifdef __NetBSD__
566     vaddr_t bigbuf;          /* buffer that holds the captured image */
567     vaddr_t vbidata;         /* RISC program puts VBI data from the current frame here */
568     vaddr_t vbibuffer;       /* Circular buffer holding VBI data for the user */
569     vaddr_t dma_prog;        /* RISC prog for single and/or even field capture*/
570     vaddr_t odd_dma_prog;    /* RISC program for Odd field capture */
571 #else
572     vm_offset_t bigbuf;	     /* buffer that holds the captured image */
573     vm_offset_t vbidata;     /* RISC program puts VBI data from the current frame here */
574     vm_offset_t vbibuffer;   /* Circular buffer holding VBI data for the user */
575     vm_offset_t dma_prog;    /* RISC prog for single and/or even field capture*/
576     vm_offset_t odd_dma_prog;/* RISC program for Odd field capture */
577 #endif
578 
579 
580     /* the following definitions are common over all platforms */
581     int		alloc_pages;	/* number of pages in bigbuf */
582     int         vbiinsert;      /* Position for next write into circular buffer */
583     int         vbistart;       /* Position of last read from circular buffer */
584     int         vbisize;        /* Number of bytes in the circular buffer */
585     u_long	vbi_sequence_number;	/* sequence number for VBI */
586     int		vbi_read_blocked;	/* user process blocked on read() from /dev/vbi */
587     struct selinfo vbi_select;	/* Data used by select() on /dev/vbi */
588 
589 
590     struct proc	*proc;		/* process to receive raised signal */
591     int		signal;		/* signal to send to process */
592     int		clr_on_start;	/* clear cap buf on capture start? */
593 #define	METEOR_SIG_MODE_MASK	0xffff0000
594 #define	METEOR_SIG_FIELD_MODE	0x00010000
595 #define	METEOR_SIG_FRAME_MODE	0x00000000
596     char         dma_prog_loaded;
597     struct meteor_mem *mem;	/* used to control sync. multi-frame output */
598     u_long	synch_wait;	/* wait for free buffer before continuing */
599     short	current;	/* frame number in buffer (1-frames) */
600     short	rows;		/* number of rows in a frame */
601     short	cols;		/* number of columns in a frame */
602     int		capture_area_x_offset; /* Usually the full 640x480(NTSC) image is */
603     int		capture_area_y_offset; /* captured. The capture area allows for */
604     int		capture_area_x_size;   /* example 320x200 pixels from the centre */
605     int		capture_area_y_size;   /* of the video image to be captured. */
606     char	capture_area_enabled;  /* When TRUE use user's capture area. */
607     int		pixfmt;         /* active pixel format (idx into fmt tbl) */
608     int		pixfmt_compat;  /* Y/N - in meteor pix fmt compat mode */
609     u_long	format;		/* frame format rgb, yuv, etc.. */
610     short	frames;		/* number of frames allocated */
611     int		frame_size;	/* number of bytes in a frame */
612     u_long	fifo_errors;	/* number of fifo capture errors since open */
613     u_long	dma_errors;	/* number of DMA capture errors since open */
614     u_long	frames_captured;/* number of frames captured since open */
615     u_long	even_fields_captured; /* number of even fields captured */
616     u_long	odd_fields_captured; /* number of odd fields captured */
617     u_long	range_enable;	/* enable range checking ?? */
618     u_short     capcontrol;     /* reg 0xdc capture control */
619     u_short     bktr_cap_ctl;
620     volatile u_int	flags;
621 #define	METEOR_INITIALIZED	0x00000001
622 #define	METEOR_OPEN		0x00000002
623 #define	METEOR_MMAP		0x00000004
624 #define	METEOR_INTR		0x00000008
625 #define	METEOR_READ		0x00000010	/* XXX never gets referenced */
626 #define	METEOR_SINGLE		0x00000020	/* get single frame */
627 #define	METEOR_CONTIN		0x00000040	/* continuously get frames */
628 #define	METEOR_SYNCAP		0x00000080	/* synchronously get frames */
629 #define	METEOR_CAP_MASK		0x000000f0
630 #define	METEOR_NTSC		0x00000100
631 #define	METEOR_PAL		0x00000200
632 #define	METEOR_SECAM		0x00000400
633 #define	BROOKTREE_NTSC		0x00000100	/* used in video open() and */
634 #define	BROOKTREE_PAL		0x00000200	/* in the kernel config */
635 #define	BROOKTREE_SECAM		0x00000400	/* file */
636 #define	METEOR_AUTOMODE		0x00000800
637 #define	METEOR_FORM_MASK	0x00000f00
638 #define	METEOR_DEV0		0x00001000
639 #define	METEOR_DEV1		0x00002000
640 #define	METEOR_DEV2		0x00004000
641 #define	METEOR_DEV3		0x00008000
642 #define METEOR_DEV_SVIDEO	0x00006000
643 #define METEOR_DEV_RGB		0x0000a000
644 #define	METEOR_DEV_MASK		0x0000f000
645 #define	METEOR_RGB16		0x00010000
646 #define	METEOR_RGB24		0x00020000
647 #define	METEOR_YUV_PACKED	0x00040000
648 #define	METEOR_YUV_PLANAR	0x00080000
649 #define	METEOR_WANT_EVEN	0x00100000	/* want even frame */
650 #define	METEOR_WANT_ODD		0x00200000	/* want odd frame */
651 #define	METEOR_WANT_MASK	0x00300000
652 #define METEOR_ONLY_EVEN_FIELDS	0x01000000
653 #define METEOR_ONLY_ODD_FIELDS	0x02000000
654 #define METEOR_ONLY_FIELDS_MASK 0x03000000
655 #define METEOR_YUV_422		0x04000000
656 #define	METEOR_OUTPUT_FMT_MASK	0x040f0000
657 #define	METEOR_WANT_TS		0x08000000	/* time-stamp a frame */
658 #define METEOR_RGB		0x20000000	/* meteor rgb unit */
659 #define METEOR_FIELD_MODE	0x80000000
660     u_char	tflags;				/* Tuner flags (/dev/tuner) */
661 #define	TUNER_INITIALIZED	0x00000001
662 #define	TUNER_OPEN		0x00000002
663     u_char      vbiflags;			/* VBI flags (/dev/vbi) */
664 #define VBI_INITIALIZED         0x00000001
665 #define VBI_OPEN                0x00000002
666 #define VBI_CAPTURE             0x00000004
667     u_short	fps;		/* frames per second */
668     struct meteor_video video;
669     struct TVTUNER	tuner;
670     struct CARDTYPE	card;
671     u_char		audio_mux_select;	/* current mode of the audio */
672     u_char		audio_mute_state;	/* mute state of the audio */
673     u_char		format_params;
674     u_long              current_sol;
675     u_long              current_col;
676     int                 clip_start;
677     int                 line_length;
678     int                 last_y;
679     int                 y;
680     int                 y2;
681     int                 yclip;
682     int                 yclip2;
683     int                 max_clip_node;
684     bktr_clip_t		clip_list[100];
685     int                 reverse_mute;		/* Swap the GPIO values for Mute and TV Audio */
686     int                 bt848_tuner;
687     int                 bt848_card;
688     u_long              id;
689 #define BT848_USE_XTALS 0
690 #define BT848_USE_PLL   1
691     int			xtal_pll_mode;	/* Use XTAL or PLL mode for PAL/SECAM */
692     int			remote_control;      /* remote control detected */
693     int			remote_control_addr;   /* remote control i2c address */
694     char		msp_version_string[9]; /* MSP version string 34xxx-xx */
695     int			msp_addr;	       /* MSP i2c address */
696     char		dpl_version_string[9]; /* DPL version string 35xxx-xx */
697     int			dpl_addr;	       /* DPL i2c address */
698     int                 slow_msp_audio;	       /* 0 = use fast MSP3410/3415 programming sequence */
699 					       /* 1 = use slow MSP3410/3415 programming sequence */
700 					       /* 2 = use Tuner's Mono audio output via the MSP chip */
701     int                 msp_use_mono_source;   /* use Tuner's Mono audio output via the MSP chip */
702     int                 audio_mux_present;     /* 1 = has audio mux on GPIO lines, 0 = no audio mux */
703     int                 msp_source_selected;   /* 0 = TV source, 1 = Line In source, 2 = FM Radio Source */
704 
705 };
706 
707 typedef struct bktr_softc bktr_reg_t;
708 typedef struct bktr_softc* bktr_ptr_t;
709 
710 #define Bt848_MAX_SIGN 16
711 
712 struct bt848_card_sig {
713   int card;
714   int tuner;
715   u_char signature[Bt848_MAX_SIGN];
716 };
717 
718 
719 /***********************************************************/
720 /* ioctl_cmd_t int on old versions, u_long on new versions */
721 /***********************************************************/
722 
723 #if (__FreeBSD__ == 2)
724 typedef int ioctl_cmd_t;
725 #endif
726 
727 #if defined(__FreeBSD__)
728 #if (__FreeBSD_version >= 300000)
729 typedef u_long ioctl_cmd_t;
730 #endif
731 #endif
732 
733 #if defined(__NetBSD__) || defined(__OpenBSD__)
734 typedef u_long ioctl_cmd_t;
735 #endif
736 
737 
738