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