Bug Summary

File:dev/pci/bktr/bktr_card.c
Warning:line 998, column 10
Value stored to 'block_4_header_size' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

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