Deleted Added
full compact
bktr_card.c (138938) bktr_card.c (139563)
1/*-
2 * 1. Redistributions of source code must retain the
3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Amancio Hasty and
17 * Roger Hardiman
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * 1. Redistributions of source code must retain the
3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Amancio Hasty and
17 * Roger Hardiman
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/bktr/bktr_card.c 138936 2004-12-16 23:37:41Z julian $");
35__FBSDID("$FreeBSD: head/sys/dev/bktr/bktr_card.c 139563 2005-01-02 04:47:36Z julian $");
36
37/*
38 * This is part of the Driver for Video Capture Cards (Frame grabbers)
39 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
40 * chipset.
41 * Copyright Roger Hardiman and Amancio Hasty.
42 *
43 * bktr_card : This deals with identifying TV cards.
44 * trying to find the card make and model of card.
45 * trying to find the type of tuner fitted.
46 * reading the configuration EEPROM.
47 * locating i2c devices.
48 */
49
50#include "opt_bktr.h" /* Include any kernel config options */
51
52#include <sys/param.h>
53#include <sys/systm.h>
54#include <sys/vnode.h>
55
56#ifdef __FreeBSD__
57
58#if (__FreeBSD_version < 500000)
59#include <machine/clock.h> /* for DELAY */
60#include <pci/pcivar.h>
61#else
62#include <dev/pci/pcivar.h>
63#endif
64
65#if (__FreeBSD_version >=300000)
66#include <machine/bus_memio.h> /* for bus space */
67#include <machine/bus.h>
68#include <sys/bus.h>
69#endif
70#endif
71
72#ifdef __NetBSD__
73#include <dev/ic/bt8xx.h> /* NetBSD location for .h files */
74#include <dev/pci/bktr/bktr_reg.h>
75#include <dev/pci/bktr/bktr_core.h>
76#include <dev/pci/bktr/bktr_tuner.h>
77#include <dev/pci/bktr/bktr_card.h>
78#include <dev/pci/bktr/bktr_audio.h>
79#else
80#include <dev/bktr/ioctl_meteor.h>
81#include <dev/bktr/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
82#include <dev/bktr/bktr_reg.h>
83#include <dev/bktr/bktr_core.h>
84#include <dev/bktr/bktr_tuner.h>
85#include <dev/bktr/bktr_card.h>
86#include <dev/bktr/bktr_audio.h>
87#endif
88
89/* Include the PCI Vendor definitions */
90#ifdef __NetBSD__
91#include <dev/pci/pcidevs.h>
92#include <dev/pci/pcireg.h>
93#endif
94
95/* Various defines */
96#define HAUP_REMOTE_INT_WADDR 0x30
97#define HAUP_REMOTE_INT_RADDR 0x31
98
99#define HAUP_REMOTE_EXT_WADDR 0x34
100#define HAUP_REMOTE_EXT_RADDR 0x35
101
102/* address of BTSC/SAP decoder chip */
103#define TDA9850_WADDR 0xb6
104#define TDA9850_RADDR 0xb7
105
106/* address of MSP3400C chip */
107#define MSP3400C_WADDR 0x80
108#define MSP3400C_RADDR 0x81
109
110/* address of DPL3518A chip */
111#define DPL3518A_WADDR 0x84
112#define DPL3518A_RADDR 0x85
113
114/* EEProm (128 * 8) on an STB card */
115#define X24C01_WADDR 0xae
116#define X24C01_RADDR 0xaf
117
118
119/* EEProm (256 * 8) on a Hauppauge card */
120/* and on most BT878s cards to store the sub-system vendor id */
121#define PFC8582_WADDR 0xa0
122#define PFC8582_RADDR 0xa1
123
124#if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
125#define DEFAULT_TUNER PHILIPS_PALI
126#else
127#define DEFAULT_TUNER PHILIPS_NTSC
128#endif
129
130
131
132
133/*
134 * the data for each type of card
135 *
136 * Note:
137 * these entried MUST be kept in the order defined by the CARD_XXX defines!
138 */
139static const struct CARDTYPE cards[] = {
140
141 { CARD_UNKNOWN, /* the card id */
142 "Unknown", /* the 'name' */
143 NULL, /* the tuner */
144 0, /* the tuner i2c address */
145 0, /* dbx unknown */
146 0,
147 0,
148 0, /* EEProm unknown */
149 0, /* EEProm unknown */
150 { 0, 0, 0, 0, 0 },
151 0 }, /* GPIO mask */
152
153 { CARD_MIRO, /* the card id */
154 "Pinnacle/Miro TV", /* the 'name' */
155 NULL, /* the tuner */
156 0, /* the tuner i2c address */
157 0, /* dbx unknown */
158 0,
159 0,
160 0, /* EEProm unknown */
161 0, /* size unknown */
162 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
163 0x0f }, /* GPIO mask */
164
165 { CARD_HAUPPAUGE, /* the card id */
166 "Hauppauge WinCast/TV", /* the 'name' */
167 NULL, /* the tuner */
168 0, /* the tuner i2c address */
169 0, /* dbx is optional */
170 0,
171 0,
172 PFC8582_WADDR, /* EEProm type */
173 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
174 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
175 0x0f }, /* GPIO mask */
176
177 { CARD_STB, /* the card id */
178 "STB TV/PCI", /* the 'name' */
179 NULL, /* the tuner */
180 0, /* the tuner i2c address */
181 0, /* dbx is optional */
182 0,
183 0,
184 X24C01_WADDR, /* EEProm type */
185 (u_char)(128 / EEPROMBLOCKSIZE), /* 128 bytes */
186 { 0x00, 0x01, 0x02, 0x02, 1 }, /* audio MUX values */
187 0x0f }, /* GPIO mask */
188
189 { CARD_INTEL, /* the card id */
190 "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */
191 NULL, /* the tuner */
192 0, /* the tuner i2c address */
193 0,
194 0,
195 0,
196 0,
197 0,
198 { 0, 0, 0, 0, 0 }, /* audio MUX values */
199 0x00 }, /* GPIO mask */
200
201 { CARD_IMS_TURBO, /* the card id */
202 "IMS TV Turbo", /* the 'name' */
203 NULL, /* the tuner */
204 0, /* the tuner i2c address */
205 0, /* dbx is optional */
206 0,
207 0,
208 PFC8582_WADDR, /* EEProm type */
209 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
210 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
211 0x0f }, /* GPIO mask */
212
213 { CARD_AVER_MEDIA, /* the card id */
214 "AVer Media TV/FM", /* the 'name' */
215 NULL, /* the tuner */
216 0, /* the tuner i2c address */
217 0, /* dbx is optional */
218 0,
219 0,
220 0, /* EEProm type */
221 0, /* EEProm size */
222 { 0x0c, 0x08, 0x04, 0x00, 1 }, /* audio MUX values */
223 0x1f }, /* GPIO mask */
224
225 { CARD_OSPREY, /* the card id */
226 "MMAC Osprey", /* the 'name' */
227 NULL, /* the tuner */
228 0, /* the tuner i2c address */
229 0, /* dbx is optional */
230 0,
231 0,
232 PFC8582_WADDR, /* EEProm type */
233 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
234 { 0x00, 0x00, 0x00, 0x00, 0 }, /* audio MUX values */
235 0 }, /* GPIO mask */
236
237 { CARD_NEC_PK, /* the card id */
238 "NEC PK-UG-X017", /* the 'name' */
239 NULL, /* the tuner */
240 0, /* the tuner i2c address */
241 0, /* dbx is optional */
242 0,
243 0,
244 0, /* EEProm type */
245 0, /* EEProm size */
246 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
247 0x0f }, /* GPIO mask */
248
249 { CARD_IO_BCTV2, /* the card id */
250 "I/O DATA GV-BCTV2/PCI", /* the 'name' */
251 NULL, /* the tuner */
252 0, /* the tuner i2c address */
253 0, /* dbx is optional */
254 0,
255 0,
256 0, /* EEProm type */
257 0, /* EEProm size */
258 { 0x00, 0x00, 0x00, 0x00, 1 }, /* Has special MUX handler */
259 0x0f }, /* GPIO mask */
260
261 { CARD_FLYVIDEO, /* the card id */
262 "FlyVideo", /* the 'name' */
263 NULL, /* the tuner */
264 0, /* the tuner i2c address */
265 0, /* dbx is optional */
266 0, /* msp34xx is optional */
267 0, /* dpl3518a is optional */
268 0xac, /* EEProm type */
269 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
270 { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */
271 0x8dff00 }, /* GPIO mask */
272
273 { CARD_ZOLTRIX, /* the card id */
274 "Zoltrix", /* the 'name' */
275 NULL, /* the tuner */
276 0, /* the tuner i2c address */
277 0, /* dbx is optional */
278 0, /* msp34xx is optional */
279 0, /* dpl3518a is optional */
280 0, /* EEProm type */
281 0, /* EEProm size */
282 { 0x04, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
283 0x0f }, /* GPIO mask */
284
285 { CARD_KISS, /* the card id */
286 "KISS TV/FM PCI", /* the 'name' */
287 NULL, /* the tuner */
288 0, /* the tuner i2c address */
289 0, /* dbx is optional */
290 0, /* msp34xx is optional */
291 0, /* dpl3518a is optional */
292 0, /* EEProm type */
293 0, /* EEProm size */
294 { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */
295 0x0f }, /* GPIO mask */
296
297 { CARD_VIDEO_HIGHWAY_XTREME, /* the card id */
298 "Video Highway Xtreme", /* the 'name' */
299 NULL, /* the tuner */
300 0,
301 0,
302 0,
303 0,
304 0, /* EEProm type */
305 0, /* EEProm size */
306 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
307 0x0f }, /* GPIO mask */
308
309 { CARD_ASKEY_DYNALINK_MAGIC_TVIEW, /* the card id */
310 "Askey/Dynalink Magic TView", /* the 'name' */
311 NULL, /* the tuner */
312 0,
313 0,
314 0,
315 0,
316 0, /* EEProm type */
317 0, /* EEProm size */
318 { 0x400, 0xE00, 0x400, 0xC00, 1 }, /* audio MUX values */
319 0xE00 }, /* GPIO mask */
320
321 { CARD_LEADTEK, /* the card id */
322 "Leadtek Winfast TV 2000", /* the 'name' */
323 NULL, /* the tuner */
324 0,
325 0,
326 0,
327 0,
328 0, /* EEProm type */
329 0, /* EEProm size */
330 /* Tuner, Extern, Intern, Mute, Enabled */
331 { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */
332 0xfff000 }, /* GPIO mask */
333
334 { CARD_TERRATVPLUS, /* the card id */
335 "TerraTVplus", /* the 'name' */
336 NULL, /* the tuner */
337 0,
338 0,
339 0,
340 0,
341 0, /* EEProm type */
342 0, /* EEProm size */
343 { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/
344 0x70000 }, /* GPIO mask */
345
346 { CARD_IO_BCTV3, /* the card id */
347 "I/O DATA GV-BCTV3/PCI", /* the 'name' */
348 NULL, /* the tuner */
349 0, /* the tuner i2c address */
350 0, /* dbx is optional */
351 0,
352 0,
353 0, /* EEProm type */
354 0, /* EEProm size */
355 /* Tuner, Extern, Intern, Mute, Enabled */
356 { 0x10000, 0, 0x10000, 0, 1 }, /* audio MUX values */
357 0x10f00 }, /* GPIO mask */
358
359 { CARD_AOPEN_VA1000, /* the card id */
360 "AOpen VA1000", /* the 'name' */
361 NULL, /* the tuner */
362 0, /* the tuner i2c address */
363 0, /* dbx is optional */
364 0,
365 0,
366 0, /* EEProm unknown */
367 0, /* size unknown */
368 { 0x02, 0x00, 0x00, 0x00, 1 }, /* audio MUX values */
369 0x18e0 }, /* GPIO mask */
370
371 { CARD_PINNACLE_PCTV_RAVE, /* the card id */
372 "Pinnacle PCTV Rave", /* the 'name' */
373 NULL, /* the tuner */
374 0, /* the tuner i2c address */
375 0, /* dbx unknown */
376 0,
377 0,
378 0, /* EEProm unknown */
379 0, /* size unknown */
380 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
381 0x03000F }, /* GPIO mask */
382
36
37/*
38 * This is part of the Driver for Video Capture Cards (Frame grabbers)
39 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
40 * chipset.
41 * Copyright Roger Hardiman and Amancio Hasty.
42 *
43 * bktr_card : This deals with identifying TV cards.
44 * trying to find the card make and model of card.
45 * trying to find the type of tuner fitted.
46 * reading the configuration EEPROM.
47 * locating i2c devices.
48 */
49
50#include "opt_bktr.h" /* Include any kernel config options */
51
52#include <sys/param.h>
53#include <sys/systm.h>
54#include <sys/vnode.h>
55
56#ifdef __FreeBSD__
57
58#if (__FreeBSD_version < 500000)
59#include <machine/clock.h> /* for DELAY */
60#include <pci/pcivar.h>
61#else
62#include <dev/pci/pcivar.h>
63#endif
64
65#if (__FreeBSD_version >=300000)
66#include <machine/bus_memio.h> /* for bus space */
67#include <machine/bus.h>
68#include <sys/bus.h>
69#endif
70#endif
71
72#ifdef __NetBSD__
73#include <dev/ic/bt8xx.h> /* NetBSD location for .h files */
74#include <dev/pci/bktr/bktr_reg.h>
75#include <dev/pci/bktr/bktr_core.h>
76#include <dev/pci/bktr/bktr_tuner.h>
77#include <dev/pci/bktr/bktr_card.h>
78#include <dev/pci/bktr/bktr_audio.h>
79#else
80#include <dev/bktr/ioctl_meteor.h>
81#include <dev/bktr/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
82#include <dev/bktr/bktr_reg.h>
83#include <dev/bktr/bktr_core.h>
84#include <dev/bktr/bktr_tuner.h>
85#include <dev/bktr/bktr_card.h>
86#include <dev/bktr/bktr_audio.h>
87#endif
88
89/* Include the PCI Vendor definitions */
90#ifdef __NetBSD__
91#include <dev/pci/pcidevs.h>
92#include <dev/pci/pcireg.h>
93#endif
94
95/* Various defines */
96#define HAUP_REMOTE_INT_WADDR 0x30
97#define HAUP_REMOTE_INT_RADDR 0x31
98
99#define HAUP_REMOTE_EXT_WADDR 0x34
100#define HAUP_REMOTE_EXT_RADDR 0x35
101
102/* address of BTSC/SAP decoder chip */
103#define TDA9850_WADDR 0xb6
104#define TDA9850_RADDR 0xb7
105
106/* address of MSP3400C chip */
107#define MSP3400C_WADDR 0x80
108#define MSP3400C_RADDR 0x81
109
110/* address of DPL3518A chip */
111#define DPL3518A_WADDR 0x84
112#define DPL3518A_RADDR 0x85
113
114/* EEProm (128 * 8) on an STB card */
115#define X24C01_WADDR 0xae
116#define X24C01_RADDR 0xaf
117
118
119/* EEProm (256 * 8) on a Hauppauge card */
120/* and on most BT878s cards to store the sub-system vendor id */
121#define PFC8582_WADDR 0xa0
122#define PFC8582_RADDR 0xa1
123
124#if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
125#define DEFAULT_TUNER PHILIPS_PALI
126#else
127#define DEFAULT_TUNER PHILIPS_NTSC
128#endif
129
130
131
132
133/*
134 * the data for each type of card
135 *
136 * Note:
137 * these entried MUST be kept in the order defined by the CARD_XXX defines!
138 */
139static const struct CARDTYPE cards[] = {
140
141 { CARD_UNKNOWN, /* the card id */
142 "Unknown", /* the 'name' */
143 NULL, /* the tuner */
144 0, /* the tuner i2c address */
145 0, /* dbx unknown */
146 0,
147 0,
148 0, /* EEProm unknown */
149 0, /* EEProm unknown */
150 { 0, 0, 0, 0, 0 },
151 0 }, /* GPIO mask */
152
153 { CARD_MIRO, /* the card id */
154 "Pinnacle/Miro TV", /* the 'name' */
155 NULL, /* the tuner */
156 0, /* the tuner i2c address */
157 0, /* dbx unknown */
158 0,
159 0,
160 0, /* EEProm unknown */
161 0, /* size unknown */
162 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
163 0x0f }, /* GPIO mask */
164
165 { CARD_HAUPPAUGE, /* the card id */
166 "Hauppauge WinCast/TV", /* the 'name' */
167 NULL, /* the tuner */
168 0, /* the tuner i2c address */
169 0, /* dbx is optional */
170 0,
171 0,
172 PFC8582_WADDR, /* EEProm type */
173 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
174 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
175 0x0f }, /* GPIO mask */
176
177 { CARD_STB, /* the card id */
178 "STB TV/PCI", /* the 'name' */
179 NULL, /* the tuner */
180 0, /* the tuner i2c address */
181 0, /* dbx is optional */
182 0,
183 0,
184 X24C01_WADDR, /* EEProm type */
185 (u_char)(128 / EEPROMBLOCKSIZE), /* 128 bytes */
186 { 0x00, 0x01, 0x02, 0x02, 1 }, /* audio MUX values */
187 0x0f }, /* GPIO mask */
188
189 { CARD_INTEL, /* the card id */
190 "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */
191 NULL, /* the tuner */
192 0, /* the tuner i2c address */
193 0,
194 0,
195 0,
196 0,
197 0,
198 { 0, 0, 0, 0, 0 }, /* audio MUX values */
199 0x00 }, /* GPIO mask */
200
201 { CARD_IMS_TURBO, /* the card id */
202 "IMS TV Turbo", /* the 'name' */
203 NULL, /* the tuner */
204 0, /* the tuner i2c address */
205 0, /* dbx is optional */
206 0,
207 0,
208 PFC8582_WADDR, /* EEProm type */
209 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
210 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
211 0x0f }, /* GPIO mask */
212
213 { CARD_AVER_MEDIA, /* the card id */
214 "AVer Media TV/FM", /* the 'name' */
215 NULL, /* the tuner */
216 0, /* the tuner i2c address */
217 0, /* dbx is optional */
218 0,
219 0,
220 0, /* EEProm type */
221 0, /* EEProm size */
222 { 0x0c, 0x08, 0x04, 0x00, 1 }, /* audio MUX values */
223 0x1f }, /* GPIO mask */
224
225 { CARD_OSPREY, /* the card id */
226 "MMAC Osprey", /* the 'name' */
227 NULL, /* the tuner */
228 0, /* the tuner i2c address */
229 0, /* dbx is optional */
230 0,
231 0,
232 PFC8582_WADDR, /* EEProm type */
233 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
234 { 0x00, 0x00, 0x00, 0x00, 0 }, /* audio MUX values */
235 0 }, /* GPIO mask */
236
237 { CARD_NEC_PK, /* the card id */
238 "NEC PK-UG-X017", /* the 'name' */
239 NULL, /* the tuner */
240 0, /* the tuner i2c address */
241 0, /* dbx is optional */
242 0,
243 0,
244 0, /* EEProm type */
245 0, /* EEProm size */
246 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
247 0x0f }, /* GPIO mask */
248
249 { CARD_IO_BCTV2, /* the card id */
250 "I/O DATA GV-BCTV2/PCI", /* the 'name' */
251 NULL, /* the tuner */
252 0, /* the tuner i2c address */
253 0, /* dbx is optional */
254 0,
255 0,
256 0, /* EEProm type */
257 0, /* EEProm size */
258 { 0x00, 0x00, 0x00, 0x00, 1 }, /* Has special MUX handler */
259 0x0f }, /* GPIO mask */
260
261 { CARD_FLYVIDEO, /* the card id */
262 "FlyVideo", /* the 'name' */
263 NULL, /* the tuner */
264 0, /* the tuner i2c address */
265 0, /* dbx is optional */
266 0, /* msp34xx is optional */
267 0, /* dpl3518a is optional */
268 0xac, /* EEProm type */
269 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
270 { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */
271 0x8dff00 }, /* GPIO mask */
272
273 { CARD_ZOLTRIX, /* the card id */
274 "Zoltrix", /* the 'name' */
275 NULL, /* the tuner */
276 0, /* the tuner i2c address */
277 0, /* dbx is optional */
278 0, /* msp34xx is optional */
279 0, /* dpl3518a is optional */
280 0, /* EEProm type */
281 0, /* EEProm size */
282 { 0x04, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
283 0x0f }, /* GPIO mask */
284
285 { CARD_KISS, /* the card id */
286 "KISS TV/FM PCI", /* the 'name' */
287 NULL, /* the tuner */
288 0, /* the tuner i2c address */
289 0, /* dbx is optional */
290 0, /* msp34xx is optional */
291 0, /* dpl3518a is optional */
292 0, /* EEProm type */
293 0, /* EEProm size */
294 { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */
295 0x0f }, /* GPIO mask */
296
297 { CARD_VIDEO_HIGHWAY_XTREME, /* the card id */
298 "Video Highway Xtreme", /* the 'name' */
299 NULL, /* the tuner */
300 0,
301 0,
302 0,
303 0,
304 0, /* EEProm type */
305 0, /* EEProm size */
306 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
307 0x0f }, /* GPIO mask */
308
309 { CARD_ASKEY_DYNALINK_MAGIC_TVIEW, /* the card id */
310 "Askey/Dynalink Magic TView", /* the 'name' */
311 NULL, /* the tuner */
312 0,
313 0,
314 0,
315 0,
316 0, /* EEProm type */
317 0, /* EEProm size */
318 { 0x400, 0xE00, 0x400, 0xC00, 1 }, /* audio MUX values */
319 0xE00 }, /* GPIO mask */
320
321 { CARD_LEADTEK, /* the card id */
322 "Leadtek Winfast TV 2000", /* the 'name' */
323 NULL, /* the tuner */
324 0,
325 0,
326 0,
327 0,
328 0, /* EEProm type */
329 0, /* EEProm size */
330 /* Tuner, Extern, Intern, Mute, Enabled */
331 { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */
332 0xfff000 }, /* GPIO mask */
333
334 { CARD_TERRATVPLUS, /* the card id */
335 "TerraTVplus", /* the 'name' */
336 NULL, /* the tuner */
337 0,
338 0,
339 0,
340 0,
341 0, /* EEProm type */
342 0, /* EEProm size */
343 { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/
344 0x70000 }, /* GPIO mask */
345
346 { CARD_IO_BCTV3, /* the card id */
347 "I/O DATA GV-BCTV3/PCI", /* the 'name' */
348 NULL, /* the tuner */
349 0, /* the tuner i2c address */
350 0, /* dbx is optional */
351 0,
352 0,
353 0, /* EEProm type */
354 0, /* EEProm size */
355 /* Tuner, Extern, Intern, Mute, Enabled */
356 { 0x10000, 0, 0x10000, 0, 1 }, /* audio MUX values */
357 0x10f00 }, /* GPIO mask */
358
359 { CARD_AOPEN_VA1000, /* the card id */
360 "AOpen VA1000", /* the 'name' */
361 NULL, /* the tuner */
362 0, /* the tuner i2c address */
363 0, /* dbx is optional */
364 0,
365 0,
366 0, /* EEProm unknown */
367 0, /* size unknown */
368 { 0x02, 0x00, 0x00, 0x00, 1 }, /* audio MUX values */
369 0x18e0 }, /* GPIO mask */
370
371 { CARD_PINNACLE_PCTV_RAVE, /* the card id */
372 "Pinnacle PCTV Rave", /* the 'name' */
373 NULL, /* the tuner */
374 0, /* the tuner i2c address */
375 0, /* dbx unknown */
376 0,
377 0,
378 0, /* EEProm unknown */
379 0, /* size unknown */
380 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
381 0x03000F }, /* GPIO mask */
382
383 { CARD_PIXELVIEW_PLAYTV_PAK, /* the card id */
384 "PixelView PlayTV Pak", /* the 'name' */
385 NULL, /* the tuner */
386 0, /* the tuner i2c address */
387 0, /* dbx is optional */
388 0,
389 0,
390 PFC8582_WADDR, /* EEProm type */
391 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
392 { 0x20000, 0x80000, 0, 0xa8000, 1 }, /* audio MUX values */
393 0xAA0000 }, /* GPIO mask */
394
383};
384
385struct bt848_card_sig bt848_card_signature[1]= {
386 /* IMS TURBO TV : card 5 */
387 { 5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}}
388
389
390};
391
392
393/*
394 * Write to the configuration EEPROM on the card.
395 * This is dangerous and will mess up your card. Therefore it is not
396 * implemented.
397 */
398int
399writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
400{
401 return( -1 );
402}
403
404/*
405 * Read the contents of the configuration EEPROM on the card.
406 * (This is not fitted to all makes of card. All Hauppauge cards have them
407 * and so do newer Bt878 based cards.
408 */
409int
410readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
411{
412 int x;
413 int addr;
414 int max;
415 int byte;
416
417 /* get the address of the EEProm */
418 addr = (int)(bktr->card.eepromAddr & 0xff);
419 if ( addr == 0 )
420 return( -1 );
421
422 max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE);
423 if ( (offset + count) > max )
424 return( -1 );
425
426 /* set the start address */
427 if ( i2cWrite( bktr, addr, offset, -1 ) == -1 )
428 return( -1 );
429
430 /* the read cycle */
431 for ( x = 0; x < count; ++x ) {
432 if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 )
433 return( -1 );
434 data[ x ] = byte;
435 }
436
437 return( 0 );
438}
439
440
441#define ABSENT (-1)
442
443/*
444 * get a signature of the card
445 * read all 128 possible i2c read addresses from 0x01 thru 0xff
446 * build a bit array with a 1 bit for each i2c device that responds
447 *
448 * XXX FIXME: use offset & count args
449 */
450int
451signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig )
452{
453 int x;
454
455 for ( x = 0; x < 16; ++x )
456 sig[ x ] = 0;
457
458 for ( x = 0; x < count; ++x ) {
459 if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) {
460 sig[ x / 8 ] |= (1 << (x % 8) );
461 }
462 }
463
464 return( 0 );
465}
466
467
468/*
469 * check_for_i2c_devices.
470 * Some BT848 cards have no tuner and no additional i2c devices
471 * eg stereo decoder. These are used for video conferencing or capture from
472 * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card).
473 *
474 * Determine if there are any i2c devices present. There are none present if
475 * a) reading from all 128 devices returns ABSENT (-1) for each one
476 * (eg VideoLogic Captivator PCI with BT848)
477 * b) reading from all 128 devices returns 0 for each one
478 * (eg VideoLogic Captivator PCI rev. 2F with BT848A)
479 */
480static int check_for_i2c_devices( bktr_ptr_t bktr ){
481 int x, temp_read;
482 int i2c_all_0 = 1;
483 int i2c_all_absent = 1;
484 for ( x = 0; x < 128; ++x ) {
485 temp_read = i2cRead( bktr, (2 * x) + 1 );
486 if (temp_read != 0) i2c_all_0 = 0;
487 if (temp_read != ABSENT) i2c_all_absent = 0;
488 }
489
490 if ((i2c_all_0) || (i2c_all_absent)) return 0;
491 else return 1;
492}
493
494
495/*
496 * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2,
497 * 0xc4 or 0xc6, settable by links on the tuner.
498 * Determine the actual address used on the TV card by probing read addresses.
499 */
500static int locate_tuner_address( bktr_ptr_t bktr) {
501 if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0;
502 if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2;
503 if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4;
504 if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6;
505 return -1; /* no tuner found */
506}
507
508
509/*
510 * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses
511 * where EEPROMs are usually found.
512 * On some cards, the EEPROM appears in several locations, but all in the
513 * range 0xa0 to 0xae.
514 */
515static int locate_eeprom_address( bktr_ptr_t bktr) {
516 if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0;
517 if (i2cRead( bktr, 0xac) != ABSENT) return 0xac;
518 if (i2cRead( bktr, 0xae) != ABSENT) return 0xae;
519 return -1; /* no eeprom found */
520}
521
522
523/*
524 * determine the card brand/model
525 * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and
526 * BKTR_OVERRIDE_MSP can be used to select a specific device,
527 * regardless of the autodetection and i2c device checks.
528 *
529 * The scheme used for probing cards faces these problems:
530 * It is impossible to work out which type of tuner is actually fitted,
531 * (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips)
532 * It is impossible to determine what audio-mux hardware is connected.
533 * It is impossible to determine if there is extra hardware connected to the
534 * GPIO pins (eg radio chips or MSP34xx reset logic)
535 *
536 * However some makes of card (eg Hauppauge) come with a configuration eeprom
537 * which tells us the make of the card. Most eeproms also tell us the
538 * tuner type and other features of the the cards.
539 *
540 * The current probe code works as follows
541 * A) If the card uses a Bt878/879:
542 * 1) Read the sub-system vendor id from the configuration EEPROM.
543 * Select the required tuner, audio mux arrangement and any other
544 * onboard features. If this fails, move to step B.
545 * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879:
546 * 1) Look for I2C devices. If there are none fitted, it is an Intel or
547 * VideoLogic cards.
548 * 2) Look for a configuration EEPROM.
549 * 2a) If there is one at I2C address 0xa0 it may be
550 * a Hauppauge or an Osprey. Check the EEPROM contents to determine which
551 * one it is. For Hauppauge, select the tuner type and audio hardware.
552 * 2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card.
553 * We still have to guess on the tuner type.
554 *
555 * C) If we do not know the card type from (A) or (B), guess at the tuner
556 * type based on the I2C address of the tuner.
557 *
558 * D) After determining the Tuner Type, we probe the i2c bus for other
559 * devices at known locations, eg IR-Remote Control, MSP34xx and TDA
560 * stereo chips.
561 */
562
563
564/*
565 * These are the sub-system vendor ID codes stored in the
566 * configuration EEPROM used on Bt878/879 cards. They should match the
567 * number assigned to the company by the PCI Special Interest Group
568 */
569#ifndef __NetBSD__
570#define PCI_VENDOR_HAUPPAUGE 0x0070
571#define PCI_VENDOR_AVERMEDIA 0x1461
572#define PCI_VENDOR_STB 0x10B4
573#define PCI_VENDOR_ASKEY 0x144F
574#endif
575/* Following not confirmed with http://members.hyperlink.net.au/~chart,
576 so not added to NetBSD's pcidevs */
577#define PCI_VENDOR_LEADTEK_ALT 0x6606
578#define PCI_VENDOR_LEADTEK_ALT_2 0x6607
579#define PCI_VENDOR_LEADTEK_ALT_3 0x107d
580#define PCI_VENDOR_FLYVIDEO 0x1851
581#define PCI_VENDOR_FLYVIDEO_2 0x1852
582#define PCI_VENDOR_PINNACLE_ALT 0xBD11
583#define PCI_VENDOR_IODATA 0x10fc
584#define PCI_VENDOR_PINNACLE_NEW 0x11BD
585
586#define MODEL_IODATA_GV_BCTV3_PCI 0x4020
587
588void
589probeCard( bktr_ptr_t bktr, int verbose, int unit )
590{
591 int card, i,j, card_found;
592 int status;
593 u_char probe_signature[128], *probe_temp;
594 int any_i2c_devices;
595 u_char eeprom[256];
596 int tuner_i2c_address = -1;
597 int eeprom_i2c_address = -1;
598
599 /* Select all GPIO bits as inputs */
600 OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
601 if (bootverbose)
602 printf("%s: GPIO is 0x%08x\n", bktr_name(bktr),
603 INL(bktr, BKTR_GPIO_DATA));
604
605#ifdef HAUPPAUGE_MSP_RESET
606 /* Reset the MSP34xx audio chip. This resolves bootup card
607 * detection problems with old Bt848 based Hauppauge cards with
608 * MSP34xx stereo audio chips. This must be user enabled because
609 * at this point the probe function does not know the card type. */
610 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
611 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
612 DELAY(2500); /* wait 2.5ms */
613 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
614 DELAY(2500); /* wait 2.5ms */
615 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
616 DELAY(2500); /* wait 2.5ms */
617#endif
618
619 /* Check for the presence of i2c devices */
620 any_i2c_devices = check_for_i2c_devices( bktr );
621
622
623 /* Check for a user specified override on the card selection */
624#if defined( BKTR_OVERRIDE_CARD )
625 bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ];
626 goto checkEEPROM;
627#endif
628 if (bktr->bt848_card != -1 ) {
629 bktr->card = cards[ (card = bktr->bt848_card) ];
630 goto checkEEPROM;
631 }
632
633
634 /* No override, so try and determine the make of the card */
635
636 /* On BT878/879 cards, read the sub-system vendor id */
637 /* This identifies the manufacturer of the card and the model */
638 /* In theory this can be read from PCI registers but this does not */
639 /* appear to work on the FlyVideo 98. Hauppauge also warned that */
640 /* the PCI registers are sometimes not loaded correctly. */
641 /* Therefore, I will read the sub-system vendor ID from the EEPROM */
642 /* (just like the Bt878 does during power up initialisation) */
643
644 if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) {
645 /* Try and locate the EEPROM */
646 eeprom_i2c_address = locate_eeprom_address( bktr );
647 if (eeprom_i2c_address != -1) {
648
649 unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */
650 unsigned int subsystem_id; /* board model number */
651 unsigned int byte_252, byte_253, byte_254, byte_255;
652
653 bktr->card = cards[ (card = CARD_UNKNOWN) ];
654 bktr->card.eepromAddr = eeprom_i2c_address;
655 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
656
657 readEEProm(bktr, 0, 256, (u_char *) &eeprom );
658 byte_252 = (unsigned int)eeprom[252];
659 byte_253 = (unsigned int)eeprom[253];
660 byte_254 = (unsigned int)eeprom[254];
661 byte_255 = (unsigned int)eeprom[255];
662
663 subsystem_id = (byte_252 << 8) | byte_253;
664 subsystem_vendor_id = (byte_254 << 8) | byte_255;
665
666 if ( bootverbose )
667 printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr),
668 subsystem_vendor_id, subsystem_id);
669
670 if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) {
671 bktr->card = cards[ (card = CARD_AVER_MEDIA) ];
672 bktr->card.eepromAddr = eeprom_i2c_address;
673 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
674 goto checkTuner;
675 }
676
677 if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) {
678 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
679 bktr->card.eepromAddr = eeprom_i2c_address;
680 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
681 goto checkTuner;
682 }
683
684 if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO)
685 || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) {
686 bktr->card = cards[ (card = CARD_FLYVIDEO) ];
687 bktr->card.eepromAddr = eeprom_i2c_address;
688 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
689 goto checkTuner;
690 }
691
692 if (subsystem_vendor_id == PCI_VENDOR_STB) {
693 bktr->card = cards[ (card = CARD_STB) ];
694 bktr->card.eepromAddr = eeprom_i2c_address;
695 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
696 goto checkTuner;
697 }
698
699 if (subsystem_vendor_id == PCI_VENDOR_ASKEY) {
700 bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ];
701 bktr->card.eepromAddr = eeprom_i2c_address;
702 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
703 goto checkTuner;
704 }
705
706 if ((subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT)
707 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_2)
708 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_3)) {
709 bktr->card = cards[ (card = CARD_LEADTEK) ];
710 bktr->card.eepromAddr = eeprom_i2c_address;
711 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
712 goto checkTuner;
713 }
714
715 if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT) {
716 bktr->card = cards[ (card = CARD_MIRO) ];
717 bktr->card.eepromAddr = eeprom_i2c_address;
718 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
719 goto checkTuner;
720 }
721
722 if (subsystem_vendor_id == 0x10fc &&
723 subsystem_id == 0x4020) {
724 bktr->card = cards[ (card = CARD_IO_BCTV3) ];
725 bktr->card.eepromAddr = eeprom_i2c_address;
726 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
727 goto checkTuner;
728 }
729
730 if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_NEW) {
731 bktr->card = cards[ (card = CARD_PINNACLE_PCTV_RAVE) ];
732 bktr->card.eepromAddr = eeprom_i2c_address;
733 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
734
735 TDA9887_init(bktr, 0);
736
737 /* look for a tuner */
738 tuner_i2c_address = locate_tuner_address( bktr );
739 printf( "%s: tuner @ %#x\n", bktr_name(bktr), tuner_i2c_address );
740 select_tuner( bktr, TUNER_MT2032 );
741
742 goto checkDBX;
743 }
744
745 /* Vendor is unknown. We will use the standard probe code */
746 /* which may not give best results */
747 printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n",
748 bktr_name(bktr), subsystem_vendor_id, subsystem_id);
749 }
750 else
751 {
752 printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n",
753 bktr_name(bktr));
754 }
755 } /* end of bt878/bt879 card detection code */
756
757 /* If we get to this point, we must have a Bt848/848A/849A card */
758 /* or a Bt878/879 with an unknown subsystem vendor id */
759 /* Try and determine the make of card by clever i2c probing */
760
761 /* Check for i2c devices. If none, move on */
762 if (!any_i2c_devices) {
763 bktr->card = cards[ (card = CARD_INTEL) ];
764 bktr->card.eepromAddr = 0;
765 bktr->card.eepromSize = 0;
766 goto checkTuner;
767 }
768
769 /* Look for Hauppauge, STB and Osprey cards by the presence */
770 /* of an EEPROM */
771 /* Note: Bt878 based cards also use EEPROMs so we can only do this */
772 /* test on BT848/848A and 849A based cards. */
773 if ((bktr->id==BROOKTREE_848) ||
774 (bktr->id==BROOKTREE_848A) ||
775 (bktr->id==BROOKTREE_849A)) {
776
777 /* At i2c address 0xa0, look for Hauppauge and Osprey cards */
778 if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) {
779
780 /* Read the eeprom contents */
781 bktr->card = cards[ (card = CARD_UNKNOWN) ];
782 bktr->card.eepromAddr = PFC8582_WADDR;
783 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
784 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
785
786 /* For Hauppauge, check the EEPROM begins with 0x84 */
787 if (eeprom[0] == 0x84) {
788 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
789 bktr->card.eepromAddr = PFC8582_WADDR;
790 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
791 goto checkTuner;
792 }
793
794 /* For Osprey, check the EEPROM begins with "MMAC" */
795 if ( (eeprom[0] == 'M') &&(eeprom[1] == 'M')
796 &&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) {
797 bktr->card = cards[ (card = CARD_OSPREY) ];
798 bktr->card.eepromAddr = PFC8582_WADDR;
799 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
800 goto checkTuner;
801 }
802 printf("%s: Warning: Unknown card type. EEPROM data not recognised\n",
803 bktr_name(bktr));
804 printf("%s: %x %x %x %x\n", bktr_name(bktr),
805 eeprom[0],eeprom[1],eeprom[2],eeprom[3]);
806 }
807
808 /* look for an STB card */
809 if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) {
810 bktr->card = cards[ (card = CARD_STB) ];
811 bktr->card.eepromAddr = X24C01_WADDR;
812 bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE);
813 goto checkTuner;
814 }
815
816 }
817
818 signCard( bktr, 1, 128, (u_char *) &probe_signature );
819
820 if (bootverbose) {
821 printf("%s: card signature: ", bktr_name(bktr));
822 for (j = 0; j < Bt848_MAX_SIGN; j++) {
823 printf(" %02x ", probe_signature[j]);
824 }
825 printf("\n\n");
826 }
827 for (i = 0;
828 i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig);
829 i++ ) {
830
831 card_found = 1;
832 probe_temp = (u_char *) &bt848_card_signature[i].signature;
833
834 for (j = 0; j < Bt848_MAX_SIGN; j++) {
835 if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) {
836 card_found = 0;
837 break;
838 }
839
840 }
841 if (card_found) {
842 bktr->card = cards[ card = bt848_card_signature[i].card];
843 eeprom_i2c_address = locate_eeprom_address( bktr );
844 if (eeprom_i2c_address != -1) {
845 bktr->card.eepromAddr = eeprom_i2c_address;
846 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
847 } else {
848 bktr->card.eepromAddr = 0;
849 bktr->card.eepromSize = 0;
850 }
851 tuner_i2c_address = locate_tuner_address( bktr );
852 select_tuner( bktr, bt848_card_signature[i].tuner );
853 goto checkDBX;
854 }
855 }
856
857 /* We do not know the card type. Default to Miro */
858 bktr->card = cards[ (card = CARD_MIRO) ];
859
860
861checkEEPROM:
862 /* look for a configuration eeprom */
863 eeprom_i2c_address = locate_eeprom_address( bktr );
864 if (eeprom_i2c_address != -1) {
865 bktr->card.eepromAddr = eeprom_i2c_address;
866 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
867 } else {
868 bktr->card.eepromAddr = 0;
869 bktr->card.eepromSize = 0;
870 }
871
872
873checkTuner:
874
875 /* look for a tuner */
876 tuner_i2c_address = locate_tuner_address( bktr );
877 if ( tuner_i2c_address == -1 ) {
878 select_tuner( bktr, NO_TUNER );
879 goto checkDBX;
880 }
881
882#if defined( BKTR_OVERRIDE_TUNER )
883 select_tuner( bktr, BKTR_OVERRIDE_TUNER );
884 goto checkDBX;
885#endif
886 if (bktr->bt848_tuner != -1 ) {
887 select_tuner( bktr, bktr->bt848_tuner & 0xff );
888 goto checkDBX;
889 }
890
891 /* Check for i2c devices */
892 if (!any_i2c_devices) {
893 select_tuner( bktr, NO_TUNER );
894 goto checkDBX;
895 }
896
897 /* differentiate type of tuner */
898
899 switch (card) {
900 case CARD_MIRO:
901 switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) {
902 case 0: select_tuner( bktr, TEMIC_PAL ); break;
903 case 1: select_tuner( bktr, PHILIPS_PAL ); break;
904 case 2: select_tuner( bktr, PHILIPS_NTSC ); break;
905 case 3: select_tuner( bktr, PHILIPS_SECAM ); break;
906 case 4: select_tuner( bktr, NO_TUNER ); break;
907 case 5: select_tuner( bktr, PHILIPS_PALI ); break;
908 case 6: select_tuner( bktr, TEMIC_NTSC ); break;
909 case 7: select_tuner( bktr, TEMIC_PALI ); break;
910 }
911 goto checkDBX;
912 break;
913
914 case CARD_HAUPPAUGE:
915 /* Hauppauge kindly supplied the following Tuner Table */
916 /* FIXME: I think the tuners the driver selects for types */
917 /* 0x08 and 0x15 may be incorrect but no one has complained. */
918 /* Old Temic tuners had their own API, but newer Temic tuners */
919 /* have the same API as Philips tuners */
920 /*
921 ID Tuner Model Format We select Format
922 0x00 NONE
923 0x01 EXTERNAL
924 0x02 OTHER
925 0x03 Philips FI1216 BG
926 0x04 Philips FI1216MF BGLL' PHILIPS_SECAM
927 0x05 Philips FI1236 MN PHILIPS_NTSC
928 0x06 Philips FI1246 I PHILIPS_PALI
929 0x07 Philips FI1256 DK
930 0x08 Philips FI1216 MK2 BG PHILIPS_PALI
931 0x09 Philips FI1216MF MK2 BGLL' PHILIPS_SECAM
932 0x0a Philips FI1236 MK2 MN PHILIPS_NTSC
933 0x0b Philips FI1246 MK2 I PHILIPS_PALI
934 0x0c Philips FI1256 MK2 DK
935 0x0d Temic 4032FY5 NTSC TEMIC_NTSC
936 0x0e Temic 4002FH5 BG TEMIC_PAL
937 0x0f Temic 4062FY5 I TEMIC_PALI
938 0x10 Philips FR1216 MK2 BG
939 0x11 Philips FR1216MF MK2 BGLL' PHILIPS_FR1236_SECAM
940 0x12 Philips FR1236 MK2 MN PHILIPS_FR1236_NTSC
941 0x13 Philips FR1246 MK2 I
942 0x14 Philips FR1256 MK2 DK
943 0x15 Philips FM1216 BG PHILIPS_FR1216_PAL
944 0x16 Philips FM1216MF BGLL' PHILIPS_FR1236_SECAM
945 0x17 Philips FM1236 MN PHILIPS_FR1236_NTSC
946 0x18 Philips FM1246 I
947 0x19 Philips FM1256 DK
948 0x1a Temic 4036FY5 MN (FI1236 MK2 clone) PHILIPS_NTSC
949 0x1b Samsung TCPN9082D MN
950 0x1c Samsung TCPM9092P Pal BG/I/DK
951 0x1d Temic 4006FH5 BG PHILIPS_PALI
952 0x1e Samsung TCPN9085D MN/Radio
953 0x1f Samsung TCPB9085P Pal BG/I/DK / Radio
954 0x20 Samsung TCPL9091P Pal BG & Secam L/L'
955 0x21 Temic 4039FY5 NTSC Radio
956 0x22 Philips FQ1216ME Pal BGIDK & Secam L/L'
957 0x23 Temic 4066FY5 Pal I (FI1246 MK2 clone) PHILIPS_PALI
958 0x24 Philips TD1536 MN/ATSCDigital
959 0x25 Philips TD1536D MN/ATSCDigital DUAL INPUT
960 0x26 Philips FMR1236 M/N FM(no demod)
961 0x27 Philips FI1256MP B/G, D/K
962 0x28 Samsung TCPQ9091P BG/I/DK, L/L'
963 0x29 Temic 4006FN5 BG/I/DK
964 0x2a Temic 4009FR5 BG FM PHILIPS_FR1216_PAL
965 0x2b Temic 4046FM5 B/G, I, D/K, L/L'
966 0x2c Temic 4009FN5 B/G, I, D/K, FM (no demod)
967 0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT
968 */
969
970
971 /* Determine the model number from the eeprom */
972 if (bktr->card.eepromAddr != 0) {
973 /* eeprom data block structure */
974 unsigned char *block_1, *block_2, *block_3, *block_4;
975 int block_1_data_size, block_2_data_size, block_3_data_size;
976 int block_1_total_size, block_2_total_size, block_3_total_size;
977 int block_4_header_size;
978
979 unsigned int model,revision;
980 unsigned char tuner_code;
981 unsigned char no_audio_mux;
982
983 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
984
985 /* LOCATE THE EEPROM DATA BLOCKS */
986 block_1 = &eeprom[0];
987 block_1_data_size = (block_1[2] << 8 | block_1[1]);
988 block_1_total_size = block_1_data_size + 3; /* Header bytes */
989
990 block_2 = &eeprom[block_1_total_size];
991 block_2_data_size = (block_2[2] << 8 | block_2[1]);
992 block_2_total_size = block_2_data_size + 3; /* Header bytes */
993
994 block_3 = &eeprom[block_1_total_size + block_2_total_size];
995 block_3_data_size = (block_3[0] &0x07);
996 block_3_total_size = block_3_data_size + 1; /* Header size */
997
998 block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size];
999 block_4_header_size = 1;
1000
1001 model = (block_1[12] << 8 | block_1[11]);
1002 revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]);
1003
1004 tuner_code = block_1[9];
1005
1006 no_audio_mux = ((block_3[3] >> 7) &0x01);
1007
1008 if (no_audio_mux) bktr->audio_mux_present = 0;
1009
1010 if (verbose)
1011 printf("%s: Hauppauge Model %d %c%c%c%c\n",
1012 bktr_name(bktr),
1013 model,
1014 ((revision >> 18) & 0x3f) + 32,
1015 ((revision >> 12) & 0x3f) + 32,
1016 ((revision >> 6) & 0x3f) + 32,
1017 ((revision >> 0) & 0x3f) + 32 );
1018
1019 /* Determine the tuner type from the eeprom */
1020
1021 switch (tuner_code) {
1022
1023 case 0x5:
1024 case 0x0a:
1025 case 0x1a:
1026 select_tuner( bktr, PHILIPS_NTSC );
1027 goto checkDBX;
1028
1029 case 0x4:
1030 case 0x9:
1031 select_tuner( bktr, PHILIPS_SECAM );
1032 goto checkDBX;
1033
1034 case 0x11:
1035 case 0x16:
1036 select_tuner( bktr, PHILIPS_FR1236_SECAM );
1037 goto checkDBX;
1038
1039 case 0x12:
1040 case 0x17:
1041 case 0x21:
1042 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1043 goto checkDBX;
1044
1045 case 0x6:
1046 case 0x8:
1047 case 0xb:
1048 case 0x1d:
1049 case 0x23:
1050 select_tuner( bktr, PHILIPS_PALI );
1051 goto checkDBX;
1052
1053 case 0xd:
1054 select_tuner( bktr, TEMIC_NTSC );
1055 goto checkDBX;
1056
1057 case 0xe:
1058 select_tuner( bktr, TEMIC_PAL );
1059 goto checkDBX;
1060
1061 case 0xf:
1062 select_tuner( bktr, TEMIC_PALI );
1063 goto checkDBX;
1064
1065 case 0x15:
1066 select_tuner( bktr, PHILIPS_FR1216_PAL );
1067 goto checkDBX;
1068
1069 case 0x2a:
1070 bktr->msp_use_mono_source = 1;
1071 select_tuner( bktr, PHILIPS_FR1216_PAL );
1072 goto checkDBX;
1073
1074 default :
1075 printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n",
1076 bktr_name(bktr), tuner_code);
1077 }
1078 }
1079 break;
1080
1081
1082 case CARD_AVER_MEDIA:
1083 /* AVerMedia kindly supplied some details of their EEPROM contents
1084 * which allow us to auto select the Tuner Type.
1085 * Only the newer AVerMedia cards actually have an EEPROM.
1086 */
1087 if (bktr->card.eepromAddr != 0) {
1088
1089 u_char tuner_make; /* Eg Philips, Temic */
1090 u_char tuner_tv_fm; /* TV or TV with FM Radio */
1091 u_char tuner_format; /* Eg NTSC, PAL, SECAM */
1092 int tuner;
1093
1094 int tuner_0_table[] = {
1095 PHILIPS_NTSC, PHILIPS_PAL,
1096 PHILIPS_PAL, PHILIPS_PAL,
1097 PHILIPS_PAL, PHILIPS_PAL,
1098 PHILIPS_SECAM, PHILIPS_SECAM,
1099 PHILIPS_SECAM, PHILIPS_PAL};
1100
1101 int tuner_0_fm_table[] = {
1102 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL,
1103 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1104 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1105 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
1106 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
1107
1108 int tuner_1_table[] = {
1109 TEMIC_NTSC, TEMIC_PAL, TEMIC_PAL,
1110 TEMIC_PAL, TEMIC_PAL, TEMIC_PAL,
1111 TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM,
1112 TEMIC_PAL};
1113
1114
1115 /* Extract information from the EEPROM data */
1116 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
1117
1118 tuner_make = (eeprom[0x41] & 0x7);
1119 tuner_tv_fm = (eeprom[0x41] & 0x18) >> 3;
1120 tuner_format = (eeprom[0x42] & 0xf0) >> 4;
1121
1122 /* Treat tuner make 0 (Philips) and make 2 (LG) the same */
1123 if ( ((tuner_make == 0) || (tuner_make == 2))
1124 && (tuner_format <= 9) && (tuner_tv_fm == 0) ) {
1125 tuner = tuner_0_table[tuner_format];
1126 select_tuner( bktr, tuner );
1127 goto checkDBX;
1128 }
1129
1130 if ( ((tuner_make == 0) || (tuner_make == 2))
1131 && (tuner_format <= 9) && (tuner_tv_fm == 1) ) {
1132 tuner = tuner_0_fm_table[tuner_format];
1133 select_tuner( bktr, tuner );
1134 goto checkDBX;
1135 }
1136
1137 if ( (tuner_make == 1) && (tuner_format <= 9) ) {
1138 tuner = tuner_1_table[tuner_format];
1139 select_tuner( bktr, tuner );
1140 goto checkDBX;
1141 }
1142
1143 printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n",
1144 bktr_name(bktr), tuner_make, tuner_format);
1145 }
1146 break;
1147
1148 case CARD_LEADTEK:
1149#if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
1150 select_tuner( bktr, PHILIPS_FR1216_PAL );
1151#else
1152 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1153#endif
1154 goto checkDBX;
1155 break;
1156
1157 case CARD_IO_BCTV3:
1158 select_tuner( bktr, ALPS_TSCH5 ); /* ALPS_TSCH6, in fact. */
1159 goto checkDBX;
1160 break;
1161
1162 } /* end switch(card) */
1163
1164
1165 /* At this point, a goto checkDBX has not occured */
1166 /* We have not been able to select a Tuner */
1167 /* Some cards make use of the tuner address to */
1168 /* identify the make/model of tuner */
1169
1170 /* At address 0xc0/0xc1 we often find a TEMIC NTSC */
1171 if ( i2cRead( bktr, 0xc1 ) != ABSENT ) {
1172 select_tuner( bktr, TEMIC_NTSC );
1173 goto checkDBX;
1174 }
1175
1176 /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */
1177 if ( i2cRead( bktr, 0xc7 ) != ABSENT ) {
1178 select_tuner( bktr, PHILIPS_NTSC );
1179 goto checkDBX;
1180 }
1181
1182 /* Address 0xc2/0xc3 is default (or common address) for several */
1183 /* tuners and we cannot tell which is which. */
1184 /* And for all other tuner i2c addresses, select the default */
1185 select_tuner( bktr, DEFAULT_TUNER );
1186
1187
1188checkDBX:
1189#if defined( BKTR_OVERRIDE_DBX )
1190 bktr->card.dbx = BKTR_OVERRIDE_DBX;
1191 goto checkMSP;
1192#endif
1193 /* Check for i2c devices */
1194 if (!any_i2c_devices) {
1195 goto checkMSP;
1196 }
1197
1198 /* probe for BTSC (dbx) chip */
1199 if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT )
1200 bktr->card.dbx = 1;
1201
1202checkMSP:
1203 /* If this is a Hauppauge Bt878 card, we need to enable the
1204 * MSP 34xx audio chip.
1205 * If this is a Hauppauge Bt848 card, reset the MSP device.
1206 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown
1207 * resistor holds the device in reset until we set GPIO pin 5.
1208 */
1209
1210 /* Optionally skip the MSP reset. This is handy if you initialise the
1211 * MSP audio in another operating system (eg Windows) first and then
1212 * do a soft reboot.
1213 */
1214
1215#ifndef BKTR_NO_MSP_RESET
1216 if (card == CARD_HAUPPAUGE) {
1217 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
1218 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1219 DELAY(2500); /* wait 2.5ms */
1220 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
1221 DELAY(2500); /* wait 2.5ms */
1222 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1223 DELAY(2500); /* wait 2.5ms */
1224 }
1225#endif
1226
1227#if defined( BKTR_OVERRIDE_MSP )
1228 bktr->card.msp3400c = BKTR_OVERRIDE_MSP;
1229 goto checkMSPEnd;
1230#endif
1231
1232 /* Check for i2c devices */
1233 if (!any_i2c_devices) {
1234 goto checkMSPEnd;
1235 }
1236
1237 if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) {
1238 bktr->card.msp3400c = 1;
1239 }
1240
1241checkMSPEnd:
1242
1243 if (bktr->card.msp3400c) {
1244 bktr->msp_addr = MSP3400C_WADDR;
1245 msp_read_id( bktr );
1246 printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr),
1247 bktr->msp_version_string,
1248 bktr->msp_addr);
1249
1250 }
1251
1252/* Check for Dolby Surround Sound DPL3518A sound chip */
1253 if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) {
1254 bktr->card.dpl3518a = 1;
1255 }
1256
1257 if (bktr->card.dpl3518a) {
1258 bktr->dpl_addr = DPL3518A_WADDR;
1259 dpl_read_id( bktr );
1260 printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr),
1261 bktr->dpl_version_string,
1262 bktr->dpl_addr);
1263 }
1264
1265/* Start of Check Remote */
1266 /* Check for the Hauppauge IR Remote Control */
1267 /* If there is an external unit, the internal will be ignored */
1268
1269 bktr->remote_control = 0; /* initial value */
1270
1271 if (any_i2c_devices) {
1272 if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT )
1273 {
1274 bktr->remote_control = 1;
1275 bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR;
1276 }
1277 else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT )
1278 {
1279 bktr->remote_control = 1;
1280 bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR;
1281 }
1282
1283 }
1284 /* If a remote control is found, poll it 5 times to turn off the LED */
1285 if (bktr->remote_control) {
1286 int i;
1287 for (i=0; i<5; i++)
1288 i2cRead( bktr, bktr->remote_control_addr );
1289 }
1290/* End of Check Remote */
1291
1292#if defined( BKTR_USE_PLL )
1293 bktr->xtal_pll_mode = BT848_USE_PLL;
1294 goto checkPLLEnd;
1295#endif
1296 /* Default is to use XTALS and not PLL mode */
1297 bktr->xtal_pll_mode = BT848_USE_XTALS;
1298
1299 /* Enable PLL mode for OSPREY users */
1300 if (card == CARD_OSPREY)
1301 bktr->xtal_pll_mode = BT848_USE_PLL;
1302
1303 /* Enable PLL mode for Video Highway Xtreme users */
1304 if (card == CARD_VIDEO_HIGHWAY_XTREME)
1305 bktr->xtal_pll_mode = BT848_USE_PLL;
1306
1307
1308 /* Most (perhaps all) Bt878 cards need to be switched to PLL mode */
1309 /* as they only fit the NTSC crystal to their cards */
1310 /* Default to enabling PLL mode for all Bt878/879 cards */
1311
1312 if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
1313 bktr->xtal_pll_mode = BT848_USE_PLL;
1314
1315
1316#if defined( BKTR_USE_PLL )
1317checkPLLEnd:
1318#endif
1319
1320
1321 bktr->card.tuner_pllAddr = tuner_i2c_address;
1322
1323 if ( verbose ) {
1324 printf( "%s: %s", bktr_name(bktr), bktr->card.name );
1325 if ( bktr->card.tuner )
1326 printf( ", %s tuner", bktr->card.tuner->name );
1327 if ( bktr->card.dbx )
1328 printf( ", dbx stereo" );
1329 if ( bktr->card.msp3400c )
1330 printf( ", msp3400c stereo" );
1331 if ( bktr->card.dpl3518a )
1332 printf( ", dpl3518a dolby" );
1333 if ( bktr->remote_control )
1334 printf( ", remote control" );
1335 printf( ".\n" );
1336 }
1337}
1338
1339#undef ABSENT
395};
396
397struct bt848_card_sig bt848_card_signature[1]= {
398 /* IMS TURBO TV : card 5 */
399 { 5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}}
400
401
402};
403
404
405/*
406 * Write to the configuration EEPROM on the card.
407 * This is dangerous and will mess up your card. Therefore it is not
408 * implemented.
409 */
410int
411writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
412{
413 return( -1 );
414}
415
416/*
417 * Read the contents of the configuration EEPROM on the card.
418 * (This is not fitted to all makes of card. All Hauppauge cards have them
419 * and so do newer Bt878 based cards.
420 */
421int
422readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
423{
424 int x;
425 int addr;
426 int max;
427 int byte;
428
429 /* get the address of the EEProm */
430 addr = (int)(bktr->card.eepromAddr & 0xff);
431 if ( addr == 0 )
432 return( -1 );
433
434 max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE);
435 if ( (offset + count) > max )
436 return( -1 );
437
438 /* set the start address */
439 if ( i2cWrite( bktr, addr, offset, -1 ) == -1 )
440 return( -1 );
441
442 /* the read cycle */
443 for ( x = 0; x < count; ++x ) {
444 if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 )
445 return( -1 );
446 data[ x ] = byte;
447 }
448
449 return( 0 );
450}
451
452
453#define ABSENT (-1)
454
455/*
456 * get a signature of the card
457 * read all 128 possible i2c read addresses from 0x01 thru 0xff
458 * build a bit array with a 1 bit for each i2c device that responds
459 *
460 * XXX FIXME: use offset & count args
461 */
462int
463signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig )
464{
465 int x;
466
467 for ( x = 0; x < 16; ++x )
468 sig[ x ] = 0;
469
470 for ( x = 0; x < count; ++x ) {
471 if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) {
472 sig[ x / 8 ] |= (1 << (x % 8) );
473 }
474 }
475
476 return( 0 );
477}
478
479
480/*
481 * check_for_i2c_devices.
482 * Some BT848 cards have no tuner and no additional i2c devices
483 * eg stereo decoder. These are used for video conferencing or capture from
484 * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card).
485 *
486 * Determine if there are any i2c devices present. There are none present if
487 * a) reading from all 128 devices returns ABSENT (-1) for each one
488 * (eg VideoLogic Captivator PCI with BT848)
489 * b) reading from all 128 devices returns 0 for each one
490 * (eg VideoLogic Captivator PCI rev. 2F with BT848A)
491 */
492static int check_for_i2c_devices( bktr_ptr_t bktr ){
493 int x, temp_read;
494 int i2c_all_0 = 1;
495 int i2c_all_absent = 1;
496 for ( x = 0; x < 128; ++x ) {
497 temp_read = i2cRead( bktr, (2 * x) + 1 );
498 if (temp_read != 0) i2c_all_0 = 0;
499 if (temp_read != ABSENT) i2c_all_absent = 0;
500 }
501
502 if ((i2c_all_0) || (i2c_all_absent)) return 0;
503 else return 1;
504}
505
506
507/*
508 * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2,
509 * 0xc4 or 0xc6, settable by links on the tuner.
510 * Determine the actual address used on the TV card by probing read addresses.
511 */
512static int locate_tuner_address( bktr_ptr_t bktr) {
513 if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0;
514 if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2;
515 if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4;
516 if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6;
517 return -1; /* no tuner found */
518}
519
520
521/*
522 * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses
523 * where EEPROMs are usually found.
524 * On some cards, the EEPROM appears in several locations, but all in the
525 * range 0xa0 to 0xae.
526 */
527static int locate_eeprom_address( bktr_ptr_t bktr) {
528 if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0;
529 if (i2cRead( bktr, 0xac) != ABSENT) return 0xac;
530 if (i2cRead( bktr, 0xae) != ABSENT) return 0xae;
531 return -1; /* no eeprom found */
532}
533
534
535/*
536 * determine the card brand/model
537 * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and
538 * BKTR_OVERRIDE_MSP can be used to select a specific device,
539 * regardless of the autodetection and i2c device checks.
540 *
541 * The scheme used for probing cards faces these problems:
542 * It is impossible to work out which type of tuner is actually fitted,
543 * (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips)
544 * It is impossible to determine what audio-mux hardware is connected.
545 * It is impossible to determine if there is extra hardware connected to the
546 * GPIO pins (eg radio chips or MSP34xx reset logic)
547 *
548 * However some makes of card (eg Hauppauge) come with a configuration eeprom
549 * which tells us the make of the card. Most eeproms also tell us the
550 * tuner type and other features of the the cards.
551 *
552 * The current probe code works as follows
553 * A) If the card uses a Bt878/879:
554 * 1) Read the sub-system vendor id from the configuration EEPROM.
555 * Select the required tuner, audio mux arrangement and any other
556 * onboard features. If this fails, move to step B.
557 * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879:
558 * 1) Look for I2C devices. If there are none fitted, it is an Intel or
559 * VideoLogic cards.
560 * 2) Look for a configuration EEPROM.
561 * 2a) If there is one at I2C address 0xa0 it may be
562 * a Hauppauge or an Osprey. Check the EEPROM contents to determine which
563 * one it is. For Hauppauge, select the tuner type and audio hardware.
564 * 2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card.
565 * We still have to guess on the tuner type.
566 *
567 * C) If we do not know the card type from (A) or (B), guess at the tuner
568 * type based on the I2C address of the tuner.
569 *
570 * D) After determining the Tuner Type, we probe the i2c bus for other
571 * devices at known locations, eg IR-Remote Control, MSP34xx and TDA
572 * stereo chips.
573 */
574
575
576/*
577 * These are the sub-system vendor ID codes stored in the
578 * configuration EEPROM used on Bt878/879 cards. They should match the
579 * number assigned to the company by the PCI Special Interest Group
580 */
581#ifndef __NetBSD__
582#define PCI_VENDOR_HAUPPAUGE 0x0070
583#define PCI_VENDOR_AVERMEDIA 0x1461
584#define PCI_VENDOR_STB 0x10B4
585#define PCI_VENDOR_ASKEY 0x144F
586#endif
587/* Following not confirmed with http://members.hyperlink.net.au/~chart,
588 so not added to NetBSD's pcidevs */
589#define PCI_VENDOR_LEADTEK_ALT 0x6606
590#define PCI_VENDOR_LEADTEK_ALT_2 0x6607
591#define PCI_VENDOR_LEADTEK_ALT_3 0x107d
592#define PCI_VENDOR_FLYVIDEO 0x1851
593#define PCI_VENDOR_FLYVIDEO_2 0x1852
594#define PCI_VENDOR_PINNACLE_ALT 0xBD11
595#define PCI_VENDOR_IODATA 0x10fc
596#define PCI_VENDOR_PINNACLE_NEW 0x11BD
597
598#define MODEL_IODATA_GV_BCTV3_PCI 0x4020
599
600void
601probeCard( bktr_ptr_t bktr, int verbose, int unit )
602{
603 int card, i,j, card_found;
604 int status;
605 u_char probe_signature[128], *probe_temp;
606 int any_i2c_devices;
607 u_char eeprom[256];
608 int tuner_i2c_address = -1;
609 int eeprom_i2c_address = -1;
610
611 /* Select all GPIO bits as inputs */
612 OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
613 if (bootverbose)
614 printf("%s: GPIO is 0x%08x\n", bktr_name(bktr),
615 INL(bktr, BKTR_GPIO_DATA));
616
617#ifdef HAUPPAUGE_MSP_RESET
618 /* Reset the MSP34xx audio chip. This resolves bootup card
619 * detection problems with old Bt848 based Hauppauge cards with
620 * MSP34xx stereo audio chips. This must be user enabled because
621 * at this point the probe function does not know the card type. */
622 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
623 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
624 DELAY(2500); /* wait 2.5ms */
625 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
626 DELAY(2500); /* wait 2.5ms */
627 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
628 DELAY(2500); /* wait 2.5ms */
629#endif
630
631 /* Check for the presence of i2c devices */
632 any_i2c_devices = check_for_i2c_devices( bktr );
633
634
635 /* Check for a user specified override on the card selection */
636#if defined( BKTR_OVERRIDE_CARD )
637 bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ];
638 goto checkEEPROM;
639#endif
640 if (bktr->bt848_card != -1 ) {
641 bktr->card = cards[ (card = bktr->bt848_card) ];
642 goto checkEEPROM;
643 }
644
645
646 /* No override, so try and determine the make of the card */
647
648 /* On BT878/879 cards, read the sub-system vendor id */
649 /* This identifies the manufacturer of the card and the model */
650 /* In theory this can be read from PCI registers but this does not */
651 /* appear to work on the FlyVideo 98. Hauppauge also warned that */
652 /* the PCI registers are sometimes not loaded correctly. */
653 /* Therefore, I will read the sub-system vendor ID from the EEPROM */
654 /* (just like the Bt878 does during power up initialisation) */
655
656 if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) {
657 /* Try and locate the EEPROM */
658 eeprom_i2c_address = locate_eeprom_address( bktr );
659 if (eeprom_i2c_address != -1) {
660
661 unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */
662 unsigned int subsystem_id; /* board model number */
663 unsigned int byte_252, byte_253, byte_254, byte_255;
664
665 bktr->card = cards[ (card = CARD_UNKNOWN) ];
666 bktr->card.eepromAddr = eeprom_i2c_address;
667 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
668
669 readEEProm(bktr, 0, 256, (u_char *) &eeprom );
670 byte_252 = (unsigned int)eeprom[252];
671 byte_253 = (unsigned int)eeprom[253];
672 byte_254 = (unsigned int)eeprom[254];
673 byte_255 = (unsigned int)eeprom[255];
674
675 subsystem_id = (byte_252 << 8) | byte_253;
676 subsystem_vendor_id = (byte_254 << 8) | byte_255;
677
678 if ( bootverbose )
679 printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr),
680 subsystem_vendor_id, subsystem_id);
681
682 if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) {
683 bktr->card = cards[ (card = CARD_AVER_MEDIA) ];
684 bktr->card.eepromAddr = eeprom_i2c_address;
685 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
686 goto checkTuner;
687 }
688
689 if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) {
690 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
691 bktr->card.eepromAddr = eeprom_i2c_address;
692 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
693 goto checkTuner;
694 }
695
696 if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO)
697 || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) {
698 bktr->card = cards[ (card = CARD_FLYVIDEO) ];
699 bktr->card.eepromAddr = eeprom_i2c_address;
700 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
701 goto checkTuner;
702 }
703
704 if (subsystem_vendor_id == PCI_VENDOR_STB) {
705 bktr->card = cards[ (card = CARD_STB) ];
706 bktr->card.eepromAddr = eeprom_i2c_address;
707 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
708 goto checkTuner;
709 }
710
711 if (subsystem_vendor_id == PCI_VENDOR_ASKEY) {
712 bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ];
713 bktr->card.eepromAddr = eeprom_i2c_address;
714 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
715 goto checkTuner;
716 }
717
718 if ((subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT)
719 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_2)
720 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_3)) {
721 bktr->card = cards[ (card = CARD_LEADTEK) ];
722 bktr->card.eepromAddr = eeprom_i2c_address;
723 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
724 goto checkTuner;
725 }
726
727 if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT) {
728 bktr->card = cards[ (card = CARD_MIRO) ];
729 bktr->card.eepromAddr = eeprom_i2c_address;
730 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
731 goto checkTuner;
732 }
733
734 if (subsystem_vendor_id == 0x10fc &&
735 subsystem_id == 0x4020) {
736 bktr->card = cards[ (card = CARD_IO_BCTV3) ];
737 bktr->card.eepromAddr = eeprom_i2c_address;
738 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
739 goto checkTuner;
740 }
741
742 if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_NEW) {
743 bktr->card = cards[ (card = CARD_PINNACLE_PCTV_RAVE) ];
744 bktr->card.eepromAddr = eeprom_i2c_address;
745 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
746
747 TDA9887_init(bktr, 0);
748
749 /* look for a tuner */
750 tuner_i2c_address = locate_tuner_address( bktr );
751 printf( "%s: tuner @ %#x\n", bktr_name(bktr), tuner_i2c_address );
752 select_tuner( bktr, TUNER_MT2032 );
753
754 goto checkDBX;
755 }
756
757 /* Vendor is unknown. We will use the standard probe code */
758 /* which may not give best results */
759 printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n",
760 bktr_name(bktr), subsystem_vendor_id, subsystem_id);
761 }
762 else
763 {
764 printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n",
765 bktr_name(bktr));
766 }
767 } /* end of bt878/bt879 card detection code */
768
769 /* If we get to this point, we must have a Bt848/848A/849A card */
770 /* or a Bt878/879 with an unknown subsystem vendor id */
771 /* Try and determine the make of card by clever i2c probing */
772
773 /* Check for i2c devices. If none, move on */
774 if (!any_i2c_devices) {
775 bktr->card = cards[ (card = CARD_INTEL) ];
776 bktr->card.eepromAddr = 0;
777 bktr->card.eepromSize = 0;
778 goto checkTuner;
779 }
780
781 /* Look for Hauppauge, STB and Osprey cards by the presence */
782 /* of an EEPROM */
783 /* Note: Bt878 based cards also use EEPROMs so we can only do this */
784 /* test on BT848/848A and 849A based cards. */
785 if ((bktr->id==BROOKTREE_848) ||
786 (bktr->id==BROOKTREE_848A) ||
787 (bktr->id==BROOKTREE_849A)) {
788
789 /* At i2c address 0xa0, look for Hauppauge and Osprey cards */
790 if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) {
791
792 /* Read the eeprom contents */
793 bktr->card = cards[ (card = CARD_UNKNOWN) ];
794 bktr->card.eepromAddr = PFC8582_WADDR;
795 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
796 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
797
798 /* For Hauppauge, check the EEPROM begins with 0x84 */
799 if (eeprom[0] == 0x84) {
800 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
801 bktr->card.eepromAddr = PFC8582_WADDR;
802 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
803 goto checkTuner;
804 }
805
806 /* For Osprey, check the EEPROM begins with "MMAC" */
807 if ( (eeprom[0] == 'M') &&(eeprom[1] == 'M')
808 &&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) {
809 bktr->card = cards[ (card = CARD_OSPREY) ];
810 bktr->card.eepromAddr = PFC8582_WADDR;
811 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
812 goto checkTuner;
813 }
814 printf("%s: Warning: Unknown card type. EEPROM data not recognised\n",
815 bktr_name(bktr));
816 printf("%s: %x %x %x %x\n", bktr_name(bktr),
817 eeprom[0],eeprom[1],eeprom[2],eeprom[3]);
818 }
819
820 /* look for an STB card */
821 if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) {
822 bktr->card = cards[ (card = CARD_STB) ];
823 bktr->card.eepromAddr = X24C01_WADDR;
824 bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE);
825 goto checkTuner;
826 }
827
828 }
829
830 signCard( bktr, 1, 128, (u_char *) &probe_signature );
831
832 if (bootverbose) {
833 printf("%s: card signature: ", bktr_name(bktr));
834 for (j = 0; j < Bt848_MAX_SIGN; j++) {
835 printf(" %02x ", probe_signature[j]);
836 }
837 printf("\n\n");
838 }
839 for (i = 0;
840 i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig);
841 i++ ) {
842
843 card_found = 1;
844 probe_temp = (u_char *) &bt848_card_signature[i].signature;
845
846 for (j = 0; j < Bt848_MAX_SIGN; j++) {
847 if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) {
848 card_found = 0;
849 break;
850 }
851
852 }
853 if (card_found) {
854 bktr->card = cards[ card = bt848_card_signature[i].card];
855 eeprom_i2c_address = locate_eeprom_address( bktr );
856 if (eeprom_i2c_address != -1) {
857 bktr->card.eepromAddr = eeprom_i2c_address;
858 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
859 } else {
860 bktr->card.eepromAddr = 0;
861 bktr->card.eepromSize = 0;
862 }
863 tuner_i2c_address = locate_tuner_address( bktr );
864 select_tuner( bktr, bt848_card_signature[i].tuner );
865 goto checkDBX;
866 }
867 }
868
869 /* We do not know the card type. Default to Miro */
870 bktr->card = cards[ (card = CARD_MIRO) ];
871
872
873checkEEPROM:
874 /* look for a configuration eeprom */
875 eeprom_i2c_address = locate_eeprom_address( bktr );
876 if (eeprom_i2c_address != -1) {
877 bktr->card.eepromAddr = eeprom_i2c_address;
878 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
879 } else {
880 bktr->card.eepromAddr = 0;
881 bktr->card.eepromSize = 0;
882 }
883
884
885checkTuner:
886
887 /* look for a tuner */
888 tuner_i2c_address = locate_tuner_address( bktr );
889 if ( tuner_i2c_address == -1 ) {
890 select_tuner( bktr, NO_TUNER );
891 goto checkDBX;
892 }
893
894#if defined( BKTR_OVERRIDE_TUNER )
895 select_tuner( bktr, BKTR_OVERRIDE_TUNER );
896 goto checkDBX;
897#endif
898 if (bktr->bt848_tuner != -1 ) {
899 select_tuner( bktr, bktr->bt848_tuner & 0xff );
900 goto checkDBX;
901 }
902
903 /* Check for i2c devices */
904 if (!any_i2c_devices) {
905 select_tuner( bktr, NO_TUNER );
906 goto checkDBX;
907 }
908
909 /* differentiate type of tuner */
910
911 switch (card) {
912 case CARD_MIRO:
913 switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) {
914 case 0: select_tuner( bktr, TEMIC_PAL ); break;
915 case 1: select_tuner( bktr, PHILIPS_PAL ); break;
916 case 2: select_tuner( bktr, PHILIPS_NTSC ); break;
917 case 3: select_tuner( bktr, PHILIPS_SECAM ); break;
918 case 4: select_tuner( bktr, NO_TUNER ); break;
919 case 5: select_tuner( bktr, PHILIPS_PALI ); break;
920 case 6: select_tuner( bktr, TEMIC_NTSC ); break;
921 case 7: select_tuner( bktr, TEMIC_PALI ); break;
922 }
923 goto checkDBX;
924 break;
925
926 case CARD_HAUPPAUGE:
927 /* Hauppauge kindly supplied the following Tuner Table */
928 /* FIXME: I think the tuners the driver selects for types */
929 /* 0x08 and 0x15 may be incorrect but no one has complained. */
930 /* Old Temic tuners had their own API, but newer Temic tuners */
931 /* have the same API as Philips tuners */
932 /*
933 ID Tuner Model Format We select Format
934 0x00 NONE
935 0x01 EXTERNAL
936 0x02 OTHER
937 0x03 Philips FI1216 BG
938 0x04 Philips FI1216MF BGLL' PHILIPS_SECAM
939 0x05 Philips FI1236 MN PHILIPS_NTSC
940 0x06 Philips FI1246 I PHILIPS_PALI
941 0x07 Philips FI1256 DK
942 0x08 Philips FI1216 MK2 BG PHILIPS_PALI
943 0x09 Philips FI1216MF MK2 BGLL' PHILIPS_SECAM
944 0x0a Philips FI1236 MK2 MN PHILIPS_NTSC
945 0x0b Philips FI1246 MK2 I PHILIPS_PALI
946 0x0c Philips FI1256 MK2 DK
947 0x0d Temic 4032FY5 NTSC TEMIC_NTSC
948 0x0e Temic 4002FH5 BG TEMIC_PAL
949 0x0f Temic 4062FY5 I TEMIC_PALI
950 0x10 Philips FR1216 MK2 BG
951 0x11 Philips FR1216MF MK2 BGLL' PHILIPS_FR1236_SECAM
952 0x12 Philips FR1236 MK2 MN PHILIPS_FR1236_NTSC
953 0x13 Philips FR1246 MK2 I
954 0x14 Philips FR1256 MK2 DK
955 0x15 Philips FM1216 BG PHILIPS_FR1216_PAL
956 0x16 Philips FM1216MF BGLL' PHILIPS_FR1236_SECAM
957 0x17 Philips FM1236 MN PHILIPS_FR1236_NTSC
958 0x18 Philips FM1246 I
959 0x19 Philips FM1256 DK
960 0x1a Temic 4036FY5 MN (FI1236 MK2 clone) PHILIPS_NTSC
961 0x1b Samsung TCPN9082D MN
962 0x1c Samsung TCPM9092P Pal BG/I/DK
963 0x1d Temic 4006FH5 BG PHILIPS_PALI
964 0x1e Samsung TCPN9085D MN/Radio
965 0x1f Samsung TCPB9085P Pal BG/I/DK / Radio
966 0x20 Samsung TCPL9091P Pal BG & Secam L/L'
967 0x21 Temic 4039FY5 NTSC Radio
968 0x22 Philips FQ1216ME Pal BGIDK & Secam L/L'
969 0x23 Temic 4066FY5 Pal I (FI1246 MK2 clone) PHILIPS_PALI
970 0x24 Philips TD1536 MN/ATSCDigital
971 0x25 Philips TD1536D MN/ATSCDigital DUAL INPUT
972 0x26 Philips FMR1236 M/N FM(no demod)
973 0x27 Philips FI1256MP B/G, D/K
974 0x28 Samsung TCPQ9091P BG/I/DK, L/L'
975 0x29 Temic 4006FN5 BG/I/DK
976 0x2a Temic 4009FR5 BG FM PHILIPS_FR1216_PAL
977 0x2b Temic 4046FM5 B/G, I, D/K, L/L'
978 0x2c Temic 4009FN5 B/G, I, D/K, FM (no demod)
979 0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT
980 */
981
982
983 /* Determine the model number from the eeprom */
984 if (bktr->card.eepromAddr != 0) {
985 /* eeprom data block structure */
986 unsigned char *block_1, *block_2, *block_3, *block_4;
987 int block_1_data_size, block_2_data_size, block_3_data_size;
988 int block_1_total_size, block_2_total_size, block_3_total_size;
989 int block_4_header_size;
990
991 unsigned int model,revision;
992 unsigned char tuner_code;
993 unsigned char no_audio_mux;
994
995 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
996
997 /* LOCATE THE EEPROM DATA BLOCKS */
998 block_1 = &eeprom[0];
999 block_1_data_size = (block_1[2] << 8 | block_1[1]);
1000 block_1_total_size = block_1_data_size + 3; /* Header bytes */
1001
1002 block_2 = &eeprom[block_1_total_size];
1003 block_2_data_size = (block_2[2] << 8 | block_2[1]);
1004 block_2_total_size = block_2_data_size + 3; /* Header bytes */
1005
1006 block_3 = &eeprom[block_1_total_size + block_2_total_size];
1007 block_3_data_size = (block_3[0] &0x07);
1008 block_3_total_size = block_3_data_size + 1; /* Header size */
1009
1010 block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size];
1011 block_4_header_size = 1;
1012
1013 model = (block_1[12] << 8 | block_1[11]);
1014 revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]);
1015
1016 tuner_code = block_1[9];
1017
1018 no_audio_mux = ((block_3[3] >> 7) &0x01);
1019
1020 if (no_audio_mux) bktr->audio_mux_present = 0;
1021
1022 if (verbose)
1023 printf("%s: Hauppauge Model %d %c%c%c%c\n",
1024 bktr_name(bktr),
1025 model,
1026 ((revision >> 18) & 0x3f) + 32,
1027 ((revision >> 12) & 0x3f) + 32,
1028 ((revision >> 6) & 0x3f) + 32,
1029 ((revision >> 0) & 0x3f) + 32 );
1030
1031 /* Determine the tuner type from the eeprom */
1032
1033 switch (tuner_code) {
1034
1035 case 0x5:
1036 case 0x0a:
1037 case 0x1a:
1038 select_tuner( bktr, PHILIPS_NTSC );
1039 goto checkDBX;
1040
1041 case 0x4:
1042 case 0x9:
1043 select_tuner( bktr, PHILIPS_SECAM );
1044 goto checkDBX;
1045
1046 case 0x11:
1047 case 0x16:
1048 select_tuner( bktr, PHILIPS_FR1236_SECAM );
1049 goto checkDBX;
1050
1051 case 0x12:
1052 case 0x17:
1053 case 0x21:
1054 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1055 goto checkDBX;
1056
1057 case 0x6:
1058 case 0x8:
1059 case 0xb:
1060 case 0x1d:
1061 case 0x23:
1062 select_tuner( bktr, PHILIPS_PALI );
1063 goto checkDBX;
1064
1065 case 0xd:
1066 select_tuner( bktr, TEMIC_NTSC );
1067 goto checkDBX;
1068
1069 case 0xe:
1070 select_tuner( bktr, TEMIC_PAL );
1071 goto checkDBX;
1072
1073 case 0xf:
1074 select_tuner( bktr, TEMIC_PALI );
1075 goto checkDBX;
1076
1077 case 0x15:
1078 select_tuner( bktr, PHILIPS_FR1216_PAL );
1079 goto checkDBX;
1080
1081 case 0x2a:
1082 bktr->msp_use_mono_source = 1;
1083 select_tuner( bktr, PHILIPS_FR1216_PAL );
1084 goto checkDBX;
1085
1086 default :
1087 printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n",
1088 bktr_name(bktr), tuner_code);
1089 }
1090 }
1091 break;
1092
1093
1094 case CARD_AVER_MEDIA:
1095 /* AVerMedia kindly supplied some details of their EEPROM contents
1096 * which allow us to auto select the Tuner Type.
1097 * Only the newer AVerMedia cards actually have an EEPROM.
1098 */
1099 if (bktr->card.eepromAddr != 0) {
1100
1101 u_char tuner_make; /* Eg Philips, Temic */
1102 u_char tuner_tv_fm; /* TV or TV with FM Radio */
1103 u_char tuner_format; /* Eg NTSC, PAL, SECAM */
1104 int tuner;
1105
1106 int tuner_0_table[] = {
1107 PHILIPS_NTSC, PHILIPS_PAL,
1108 PHILIPS_PAL, PHILIPS_PAL,
1109 PHILIPS_PAL, PHILIPS_PAL,
1110 PHILIPS_SECAM, PHILIPS_SECAM,
1111 PHILIPS_SECAM, PHILIPS_PAL};
1112
1113 int tuner_0_fm_table[] = {
1114 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL,
1115 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1116 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1117 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
1118 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
1119
1120 int tuner_1_table[] = {
1121 TEMIC_NTSC, TEMIC_PAL, TEMIC_PAL,
1122 TEMIC_PAL, TEMIC_PAL, TEMIC_PAL,
1123 TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM,
1124 TEMIC_PAL};
1125
1126
1127 /* Extract information from the EEPROM data */
1128 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
1129
1130 tuner_make = (eeprom[0x41] & 0x7);
1131 tuner_tv_fm = (eeprom[0x41] & 0x18) >> 3;
1132 tuner_format = (eeprom[0x42] & 0xf0) >> 4;
1133
1134 /* Treat tuner make 0 (Philips) and make 2 (LG) the same */
1135 if ( ((tuner_make == 0) || (tuner_make == 2))
1136 && (tuner_format <= 9) && (tuner_tv_fm == 0) ) {
1137 tuner = tuner_0_table[tuner_format];
1138 select_tuner( bktr, tuner );
1139 goto checkDBX;
1140 }
1141
1142 if ( ((tuner_make == 0) || (tuner_make == 2))
1143 && (tuner_format <= 9) && (tuner_tv_fm == 1) ) {
1144 tuner = tuner_0_fm_table[tuner_format];
1145 select_tuner( bktr, tuner );
1146 goto checkDBX;
1147 }
1148
1149 if ( (tuner_make == 1) && (tuner_format <= 9) ) {
1150 tuner = tuner_1_table[tuner_format];
1151 select_tuner( bktr, tuner );
1152 goto checkDBX;
1153 }
1154
1155 printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n",
1156 bktr_name(bktr), tuner_make, tuner_format);
1157 }
1158 break;
1159
1160 case CARD_LEADTEK:
1161#if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
1162 select_tuner( bktr, PHILIPS_FR1216_PAL );
1163#else
1164 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1165#endif
1166 goto checkDBX;
1167 break;
1168
1169 case CARD_IO_BCTV3:
1170 select_tuner( bktr, ALPS_TSCH5 ); /* ALPS_TSCH6, in fact. */
1171 goto checkDBX;
1172 break;
1173
1174 } /* end switch(card) */
1175
1176
1177 /* At this point, a goto checkDBX has not occured */
1178 /* We have not been able to select a Tuner */
1179 /* Some cards make use of the tuner address to */
1180 /* identify the make/model of tuner */
1181
1182 /* At address 0xc0/0xc1 we often find a TEMIC NTSC */
1183 if ( i2cRead( bktr, 0xc1 ) != ABSENT ) {
1184 select_tuner( bktr, TEMIC_NTSC );
1185 goto checkDBX;
1186 }
1187
1188 /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */
1189 if ( i2cRead( bktr, 0xc7 ) != ABSENT ) {
1190 select_tuner( bktr, PHILIPS_NTSC );
1191 goto checkDBX;
1192 }
1193
1194 /* Address 0xc2/0xc3 is default (or common address) for several */
1195 /* tuners and we cannot tell which is which. */
1196 /* And for all other tuner i2c addresses, select the default */
1197 select_tuner( bktr, DEFAULT_TUNER );
1198
1199
1200checkDBX:
1201#if defined( BKTR_OVERRIDE_DBX )
1202 bktr->card.dbx = BKTR_OVERRIDE_DBX;
1203 goto checkMSP;
1204#endif
1205 /* Check for i2c devices */
1206 if (!any_i2c_devices) {
1207 goto checkMSP;
1208 }
1209
1210 /* probe for BTSC (dbx) chip */
1211 if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT )
1212 bktr->card.dbx = 1;
1213
1214checkMSP:
1215 /* If this is a Hauppauge Bt878 card, we need to enable the
1216 * MSP 34xx audio chip.
1217 * If this is a Hauppauge Bt848 card, reset the MSP device.
1218 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown
1219 * resistor holds the device in reset until we set GPIO pin 5.
1220 */
1221
1222 /* Optionally skip the MSP reset. This is handy if you initialise the
1223 * MSP audio in another operating system (eg Windows) first and then
1224 * do a soft reboot.
1225 */
1226
1227#ifndef BKTR_NO_MSP_RESET
1228 if (card == CARD_HAUPPAUGE) {
1229 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
1230 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1231 DELAY(2500); /* wait 2.5ms */
1232 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
1233 DELAY(2500); /* wait 2.5ms */
1234 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1235 DELAY(2500); /* wait 2.5ms */
1236 }
1237#endif
1238
1239#if defined( BKTR_OVERRIDE_MSP )
1240 bktr->card.msp3400c = BKTR_OVERRIDE_MSP;
1241 goto checkMSPEnd;
1242#endif
1243
1244 /* Check for i2c devices */
1245 if (!any_i2c_devices) {
1246 goto checkMSPEnd;
1247 }
1248
1249 if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) {
1250 bktr->card.msp3400c = 1;
1251 }
1252
1253checkMSPEnd:
1254
1255 if (bktr->card.msp3400c) {
1256 bktr->msp_addr = MSP3400C_WADDR;
1257 msp_read_id( bktr );
1258 printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr),
1259 bktr->msp_version_string,
1260 bktr->msp_addr);
1261
1262 }
1263
1264/* Check for Dolby Surround Sound DPL3518A sound chip */
1265 if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) {
1266 bktr->card.dpl3518a = 1;
1267 }
1268
1269 if (bktr->card.dpl3518a) {
1270 bktr->dpl_addr = DPL3518A_WADDR;
1271 dpl_read_id( bktr );
1272 printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr),
1273 bktr->dpl_version_string,
1274 bktr->dpl_addr);
1275 }
1276
1277/* Start of Check Remote */
1278 /* Check for the Hauppauge IR Remote Control */
1279 /* If there is an external unit, the internal will be ignored */
1280
1281 bktr->remote_control = 0; /* initial value */
1282
1283 if (any_i2c_devices) {
1284 if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT )
1285 {
1286 bktr->remote_control = 1;
1287 bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR;
1288 }
1289 else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT )
1290 {
1291 bktr->remote_control = 1;
1292 bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR;
1293 }
1294
1295 }
1296 /* If a remote control is found, poll it 5 times to turn off the LED */
1297 if (bktr->remote_control) {
1298 int i;
1299 for (i=0; i<5; i++)
1300 i2cRead( bktr, bktr->remote_control_addr );
1301 }
1302/* End of Check Remote */
1303
1304#if defined( BKTR_USE_PLL )
1305 bktr->xtal_pll_mode = BT848_USE_PLL;
1306 goto checkPLLEnd;
1307#endif
1308 /* Default is to use XTALS and not PLL mode */
1309 bktr->xtal_pll_mode = BT848_USE_XTALS;
1310
1311 /* Enable PLL mode for OSPREY users */
1312 if (card == CARD_OSPREY)
1313 bktr->xtal_pll_mode = BT848_USE_PLL;
1314
1315 /* Enable PLL mode for Video Highway Xtreme users */
1316 if (card == CARD_VIDEO_HIGHWAY_XTREME)
1317 bktr->xtal_pll_mode = BT848_USE_PLL;
1318
1319
1320 /* Most (perhaps all) Bt878 cards need to be switched to PLL mode */
1321 /* as they only fit the NTSC crystal to their cards */
1322 /* Default to enabling PLL mode for all Bt878/879 cards */
1323
1324 if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
1325 bktr->xtal_pll_mode = BT848_USE_PLL;
1326
1327
1328#if defined( BKTR_USE_PLL )
1329checkPLLEnd:
1330#endif
1331
1332
1333 bktr->card.tuner_pllAddr = tuner_i2c_address;
1334
1335 if ( verbose ) {
1336 printf( "%s: %s", bktr_name(bktr), bktr->card.name );
1337 if ( bktr->card.tuner )
1338 printf( ", %s tuner", bktr->card.tuner->name );
1339 if ( bktr->card.dbx )
1340 printf( ", dbx stereo" );
1341 if ( bktr->card.msp3400c )
1342 printf( ", msp3400c stereo" );
1343 if ( bktr->card.dpl3518a )
1344 printf( ", dpl3518a dolby" );
1345 if ( bktr->remote_control )
1346 printf( ", remote control" );
1347 printf( ".\n" );
1348 }
1349}
1350
1351#undef ABSENT