bktr_core.c (51658) | bktr_core.c (51694) |
---|---|
1/* $FreeBSD: head/sys/dev/bktr/bktr_core.c 51658 1999-09-25 18:24:47Z phk $ */ 2/* BT848 Driver for Brooktree's Bt848, Bt848A, Bt849A, Bt878, Bt879 based cards. 3 The Brooktree BT848 Driver driver is based upon Mark Tinguely and | 1/* $FreeBSD: head/sys/dev/bktr/bktr_core.c 51694 1999-09-26 22:06:20Z roger $ */ 2 3/* 4 * This is part of the Driver for Video Capture Cards (Frame grabbers) 5 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 6 * chipset. 7 * Copyright Roger Hardiman and Amancio Hasty. 8 * 9 * bktr_core : This deals with the Bt848/849/878/879 PCI Frame Grabber, 10 * Handles all the open, close, ioctl and read userland calls. 11 * Sets the Bt848 registers and generates RISC pograms. 12 * Controls the i2c bus and GPIO interface. 13 * Contains the interface to the kernel. 14 * (eg probe/attach and open/close/ioctl) 15 * 16 */ 17 18 /* 19 The Brooktree BT848 Driver driver is based upon Mark Tinguely and |
4 Jim Lowe's driver for the Matrox Meteor PCI card . The 5 Philips SAA 7116 and SAA 7196 are very different chipsets than | 20 Jim Lowe's driver for the Matrox Meteor PCI card . The 21 Philips SAA 7116 and SAA 7196 are very different chipsets than |
6 the BT848. For starters, the BT848 is a one chipset solution and 7 it incorporates a RISC engine to control the DMA transfers -- 8 that is it the actual dma process is control by a program which 9 resides in the hosts memory also the register definitions between 10 the Philips chipsets and the Bt848 are very different. | 22 the BT848. |
11 12 The original copyright notice by Mark and Jim is included mostly 13 to honor their fantastic work in the Matrox Meteor driver! 14 | 23 24 The original copyright notice by Mark and Jim is included mostly 25 to honor their fantastic work in the Matrox Meteor driver! 26 |
15 Enjoy, 16 Amancio 17 | |
18 */ 19 20/* 21 * 1. Redistributions of source code must retain the | 27 */ 28 29/* 30 * 1. Redistributions of source code must retain the |
22 * Copyright (c) 1997 Amancio Hasty | 31 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman |
23 * All rights reserved. 24 * 25 * Redistribution and use in source and binary forms, with or without 26 * modification, are permitted provided that the following conditions 27 * are met: 28 * 1. Redistributions of source code must retain the above copyright 29 * notice, this list of conditions and the following disclaimer. 30 * 2. Redistributions in binary form must reproduce the above copyright 31 * notice, this list of conditions and the following disclaimer in the 32 * documentation and/or other materials provided with the distribution. 33 * 3. All advertising materials mentioning features or use of this software 34 * must display the following acknowledgement: | 32 * All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. All advertising materials mentioning features or use of this software 43 * must display the following acknowledgement: |
35 * This product includes software developed by Amancio Hasty | 44 * This product includes software developed by Amancio Hasty and 45 * Roger Hardiman |
36 * 4. The name of the author may not be used to endorse or promote products 37 * derived from this software without specific prior written permission. 38 * 39 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 40 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 41 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 42 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 43 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES --- 35 unchanged lines hidden (view full) --- 79 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 80 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 82 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 83 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 84 * POSSIBILITY OF SUCH DAMAGE. 85 */ 86 | 46 * 4. The name of the author may not be used to endorse or promote products 47 * derived from this software without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 51 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 52 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 53 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES --- 35 unchanged lines hidden (view full) --- 89 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 90 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 92 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 93 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 94 * POSSIBILITY OF SUCH DAMAGE. 95 */ 96 |
87/* Change History: 88Note: These version numbers represent the authors own numbering. 89They are unrelated to Revision Control numbering of FreeBSD or any other system. 901.0 1/24/97 First Alpha release | |
91 | 97 |
921.1 2/20/97 Added video ioctl so we can do PCI To PCI 93 data transfers. This is for capturing data 94 directly to a vga frame buffer which has 95 a linear frame buffer. Minor code clean-up. 96 971.3 2/23/97 Fixed system lock-up reported by 98 Randall Hopper <rhh@ct.picker.com>. This 99 problem seems somehow to be exhibited only 100 in his system. I changed the setting of 101 INT_MASK for CAP_CONTINUOUS to be exactly 102 the same as CAP_SINGLE apparently setting 103 bit 23 cleared the system lock up. 104 version 1.1 of the driver has been reported 105 to work with STB's WinTv, Hauppage's Wincast/Tv 106 and last but not least with the Intel Smart 107 Video Recorder. 108 1091.4 3/9/97 fsmp@freefall.org 110 Merged code to support tuners on STB and WinCast 111 cards. 112 Modifications to the contrast and chroma ioctls. 113 Textual cleanup. 114 1151.5 3/15/97 fsmp@freefall.org 116 new bt848 specific versions of hue/bright/ 117 contrast/satu/satv. 118 Amancio's patch to fix "screen freeze" problem. 119 1201.6 3/19/97 fsmp@freefall.org 121 new table-driven frequency lookup. 122 removed disable_intr()/enable_intr() calls from i2c. 123 misc. cleanup. 124 1251.7 3/19/97 fsmp@freefall.org 126 added audio support submitted by: 127 Michael Petry <petry@netwolf.NetMasters.com> 128 1291.8 3/20/97 fsmp@freefall.org 130 extended audio support. 131 card auto-detection. 132 major cleanup, order of routines, declarations, etc. 133 1341.9 3/22/97 fsmp@freefall.org 135 merged in Amancio's minor unit for tuner control 136 mods. 137 misc. cleanup, especially in the _intr routine. 138 made AUDIO_SUPPORT mainline code. 139 1401.10 3/23/97 fsmp@freefall.org 141 added polled hardware i2c routines, 142 removed all existing software i2c routines. 143 created software i2cProbe() routine. 144 Randall Hopper's fixes of BT848_GHUE & BT848_GBRIG. 145 eeprom support. 146 1471.11 3/24/97 fsmp@freefall.org 148 Louis Mamakos's new bt848 struct. 149 1501.12 3/25/97 fsmp@freefall.org 151 japanese freq table from Naohiro Shichijo. 152 new table structs for tuner lookups. 153 major scrub for "magic numbers". 154 1551.13 3/28/97 fsmp@freefall.org 156 1st PAL support. 157 MAGIC_[1-4] demarcates magic #s needing PAL work. 158 AFC code submitted by Richard Tobin 159 <richard@cogsci.ed.ac.uk>. 160 1611.14 3/29/97 richard@cogsci.ed.ac.uk 162 PAL support: magic numbers moved into 163 format_params structure. 164 Revised AFC interface. 165 fixed DMA_PROG_ALLOC size misdefinition. 166 1671.15 4/18/97 John-Mark Gurney <gurney_j@resnet.uoregon.edu> 168 Added [SR]RGBMASKs ioctl for byte swapping. 169 1701.16 4/20/97 Randall Hopper <rhh@ct.picker.com> 171 Generalized RGBMASK ioctls for general pixel 172 format setting [SG]ACTPIXFMT, and added query API 173 to return driver-supported pix fmts GSUPPIXFMT. 174 1751.17 4/21/97 hasty@rah.star-gate.com 176 Clipping support added. 177 1781.18 4/23/97 Clean up after failed CAP_SINGLEs where bt 179 interrupt isn't delivered, and fixed fixing 180 CAP_SINGLEs that for ODD_ONLY fields. 1811.19 9/8/97 improved yuv support , cleaned up weurope 182 channel table, incorporated cleanup work from 183 Luigi, fixed pci interface bug due to a 184 change in the pci interface which disables 185 interrupts from a PCI device by default, 186 Added Luigi's, ioctl's BT848_SLNOTCH, 187 BT848_GLNOTCH (set luma notch and get luma not) 1881.20 10/5/97 Keith Sklower <sklower@CS.Berkeley.EDU> submitted 189 a patch to fix compilation of the BSDI's PCI 190 interface. 191 Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp> 192 Submitted a patch for Japanese cable channels 193 Joao Carlos Mendes Luis jonny@gta.ufrj.br 194 Submitted general ioctl to set video broadcast 195 formats (PAL, NTSC, etc..) previously we depended 196 on the Bt848 auto video detect feature. 1971.21 10/24/97 Randall Hopper <rhh@ct.picker.com> 198 Fix temporal decimation, disable it when 199 doing CAP_SINGLEs, and in dual-field capture, don't 200 capture fields for different frames 2011.22 11/08/97 Randall Hopper <rhh@ct.picker.com> 202 Fixes for packed 24bpp - FIFO alignment 2031.23 11/17/97 Amancio <hasty@star-gate.com> 204 Added yuv support mpeg encoding 2051.24 12/27/97 Jonathan Hanna <pangolin@rogers.wave.ca> 206 Patch to support Philips FR1236MK2 tuner 2071.25 02/02/98 Takeshi Ohashi 208 <ohashi@atohasi.mickey.ai.kyutech.ac.jp> submitted 209 code to support bktr_read . 210 Flemming Jacobsen <fj@schizo.dk.tfs.com> 211 submitted code to support radio available with in 212 some bt848 based cards;additionally, wrote code to 213 correctly recognized his bt848 card. 214 Roger Hardiman <roger@cs.strath.ac.uk> submitted 215 various fixes to smooth out the microcode and made 216 all modes consistent. 2171.26 Moved Luigi's I2CWR ioctl from the video_ioctl 218 section to the tuner_ioctl section 219 Changed Major device from 79 to 92 and reserved 220 our Major device number -- hasty@star-gate.com 2211.27 Last batch of patches for radio support from 222 Flemming Jacobsen <fj@trw.nl>. 223 Added B849 PCI ID submitted by: 224 Tomi Vainio <tomppa@fidata.fi> 2251.28 Frank Nobis <fn@Radio-do.de> added tuner support 226 for the German Phillips PAL tuner and 227 additional channels for german cable tv. 2281.29 Roger Hardiman <roger@cs.strath.ac.uk> 229 Revised autodetection code to correctly handle both 230 old and new VideoLogic Captivator PCI cards. 231 Added tsleep of 2 seconds to initialistion code 232 for PAL users.Corrected clock selection code on 233 format change. 2341.30 Bring back Frank Nobis <fn@Radio-do.de>'s opt_bktr.h 235 2361.31 Randall Hopper <rhh@ct.picker.com> 237 submitted ioctl to clear the video buffer 238 prior to starting video capture 239 Amancio : clean up yuv12 so that it does not 240 affect rgb capture. Basically, fxtv after 241 capturing in yuv12 mode , switching to rgb 242 would cause the video capture to be too bright. 2431.32 disable inverse gamma function for rgb and yuv 244 capture. fixed meteor brightness ioctl it now 245 converts the brightness value from unsigned to 246 signed. 2471.33 added sysctl: hw.bt848.tuner, hw.bt848.reverse_mute, 248 hw.bt848.card 249 card takes a value from 0 to bt848_max_card 250 tuner takes a value from 0 to bt848_max_tuner 251 reverse_mute : 0 no effect, 1 reverse tuner 252 mute function some tuners are wired reversed :( 2531.34 reverse mute function for ims turbo card 254 2551.35 Roger Hardiman <roger@cs.strath.ac.uk> 256 options BROOKTREE_SYSTEM_DEFAULT=BROOKTREE_PAL 257 in the kernel config file makes the driver's 258 video_open() function select PAL rather than NTSC. 259 This fixed all the hangs on my Dual Crystal card 260 when using a PAL video signal. As a result, you 261 can loose the tsleep (of 2 seconds - now 0.25!!) 262 which I previously added. (Unless someone else 263 wanted the 0.25 second tsleep). 264 2651.36 added bt848.format sysctl variable. 266 1 denotes NTSC , 0 denotes PAL 267 2681.37 added support for Bt878 and improved Hauppauge's 269 bt848 tuner recognition 2701.38 Further improvements on Hauppauge's rely on 271 eeprom[9] to determine the tuner type 8) 272 273 AVerMedia card type added <sos@freebsd.org> 274 2751.39 08/05/98 Roger Hardiman <roger@cs.strath.ac.uk> 276 Updated Hauppauge detection code for Tuner ID 0x0a 277 for newer NTSC WinCastTV 404 with Bt878 chipset. 278 Tidied up PAL default in video_open() 279 2801.49 10 August 1998 Roger Hardiman <roger@cs.strath.ac.uk> 281 Added Capture Area ioctl - BT848[SG]CAPAREA. 282 Normally the full 640x480 (768x576 PAL) image 283 is grabbed. This ioctl allows a smaller area 284 from anywhere within the video image to be 285 grabbed, eg a 400x300 image from (50,10). 286 See restrictions in BT848SCAPAREA. 287 2881.50 31 August 1998 Roger Hardiman <roger@cs.strath.ac.uk> 289 Renamed BT848[SG]CAPAREA to BT848_[SG]CAPAREA. 290 Added PR kern/7177 for SECAM Video Highway Xtreme 291 with single crystal PLL configuration 292 submitted by Vsevolod Lobko <seva@alex-ua.com>. 293 In kernel configuration file add 294 options OVERRIDE_CARD=2 295 options OVERRIDE_TUNER=11 296 options BKTR_USE_PLL 297 2981.51 31 August 1998 Roger Hardiman <roger@cs.strath.ac.uk> 299 Fixed bug in Miro Tuner detection. Missing Goto. 300 Removed Hauppauge EEPROM 0x10 detection as I think 301 0x10 should be a PAL tuner, not NTSC. 302 Reinstated some Tuner Guesswork code from 1.27 303 3041.52 3 Sep 1998 Roger Hardiman <roger@cs.strath.ac.uk> 305 Submitted patch by Vsevolod Lobko <seva@alex-ua.com> 306 to correct SECAM B-Delay and add XUSSR channel set. 307 3081.53 9 Sep 1998 Roger Hardiman <roger@cs.strath.ac.uk> 309 Changed METEORSINPUT for Hauppauge cards with bt878. 310 Submitted by Fred Templin <templin@erg.sri.com> 311 Also fixed video_open defines and 878 support. 312 3131.54 18 Sep 1998 Roger Hardiman <roger@cs.strath.ac.uk> 314 Changed tuner code to autodetect tuner i2c address. 315 Addresses were incorrectly hardcoded. 316 3171.55 21 Sep 1998 Roger Hardiman <roger@cs.strath.ac.uk> 318 Hauppauge Tech Support confirmed all Hauppauge 878 319 PAL/SECAM boards will use PLL mode. 320 Added to card probe. Thanks to Ken and Fred. 321 3221.56 21 Jan 1999 Roger Hardiman <roger@cs.strath.ac.uk> 323 Added detection of Hauppauge IR remote control. 324 and MSP34xx Audio chip. Fixed i2c read error. 325 Hauppauge supplied details of new Tuner Types. 326 Danny Braniss <danny@cs.huji.ac.il> submitted Bt878 327 AverMedia detection with PCI subsystem vendor id. 328 3291.57 26 Jan 1999 Roger Hardiman <roger@cs.strath.ac.uk> 330 Support for MSP3410D / MSP3415D Stereo/Mono audio 331 using the audio format Auto Detection Mode. 332 Nicolas Souchu <nsouch@freebsd.org> ported the 333 msp_read/write/reset functions to smbus/iicbus. 334 METEOR_INPUT_DEV2 now selects a composite camera on 335 the SVIDEO port for Johan Larsson<gozer@ludd.luth.se> 336 For true SVIDEO, use METEOR_INPUT_DEV_SVIDEO 337 3381.58 8 Feb 1999 Roger Hardiman <roger@cs.strath.ac.uk> 339 Added check to bktr_mmap from OpenBSD driver. 340 Improved MSP34xx reset for bt848 Hauppauge boards. 341 Added detection for Bt848a. 342 Vsevolod Lobko<seva@sevasoft.alex-ua.com> added 343 more XUSSR channels. 344 3451.59 9 Feb 1999 Added ioctl REMOTE_GETKEY for Hauppauge Infra-Red 346 Remote Control. Submitted by Roger Hardiman. 347 Added ioctl TVTUNER_GETCHANSET and 348 BT848_GPIO_SET_EN,BT848_GPIO_SET_DATA (and GETs) 349 Submitted by Vsevolod Lobko <seva@alex-ua.com> 350 3511.60 23 Feb 1999 Roger Hardiman <roger@freebsd.org> 352 Corrected Mute on Hauppauge Radio cards. 353 Autodetect MMAC Osprey by looking for "MMAC" in the EEPROM. 354 Added for Jan Schmidt <mmedia@rz.uni-greifswald.de> 355 Added ALPS Tuner Type from Hiroki Mori <mori@infocity.co.jp> 356 3571.61 29 Apr 1999 Roger Hardiman <roger@freebsd.org> 358 Fix row=0/columns=0 bug. From Randal Hopper<aa8vb@ipass.net> 359 Add option to block the reset of the MSP34xx audio chip by 360 adding options BKTR_NO_MSP_RESET to the kernel config file. 361 This is usefull if you run another operating system 362 first to initialise the audio chip, then do a soft reboot. 363 Added for Yuri Gindin <yuri@xpert.com> 364 3651.62 29 Apr 1999 Added new cards: NEC PK-UG-X017 and I/O DATA GV-BCTV2/PCI 366 Added new tuner: ALPS_TSBH1 (plus FM Radio for ALPS_TSCH5) 367 Added support for BCTV audio mux. 368 All submitted by Hiroki Mori <mori@infocity.co.jp> 369 3701.63 29 Apr 1999 Roger Hardiman <roger@freebsd.org> 371 Added initial code for VBI capture based on work by 372 Hiroki Mori <mori@infocity.co.jp> and reworked by myself. 373 This allows software decoding of teletext, intercast and 374 subtitles via /dev/vbi. 375 3761.64 7 May 1999 Roger Hardiman <roger@freebsd.org> 377 Support LifeView FlyVideo 98 cards. Use EEPROM for card 378 autodetection. Use bttv's audio mux values. 379 Thanks to Paul Reece <paul@fastlane.net.au>, 380 Ivan Brawley <brawley@internode.com.au> and 381 Gilad Rom <rom_glsa@ein-hashofet.co.il> 382 Automatically locate the EEPROM i2c address and read the 383 subsystem_vendor_id from EEPROM and not the PCI registers. 384 Add NSMBUS checks around smbus/iicbus i2c bus code 385 making it easier to compile the driver under 2.2.x. 386 Add GPIO mask for the audio mux to each card type. 387 Add CARD_ZOLTRIX and CARD_KISS from mailing list searches. 388 3891.65 18 May 1999 Roger Hardiman <roger@freebsd.org> 390 Change Intel GPIO mask to stop turning the Intel Camera off 391 Fixed tuner selection on Hauppauge card with tuner 0x0a 392 Replaced none tuner with no tuner for Theo de Raadt. 393 Ivan Brawley <brawley@internode.com.au> added 394 the Australian channel frequencies. 395 3961.66 19 May 1999 Ivan Brawley <brawley@internode.com.au> added better 397 Australian channel frequencies. 398 3991.67 23 May 1999 Roger Hardiman <roger@freebsd.org> 400 Added rgb_vbi_prog() to capture VBI data and video at the 401 same time. To capture VBI data, /dev/vbi must be opened 402 before starting video capture. 403 4041.68 25 May 1999 Roger Hardiman <roger@freebsd.org> 405 Due to differences in PCI bus implementations from various 406 motherboard chipset manufactuers, the Bt878/Bt879 has 3 407 PCI bus compatibility modes. These are 408 NORMAL PCI 2.1 for proper PCI 2.1 compatible chipsets. 409 INTEL 430 FX for the Intel 430 FX chipset. 410 SIS VIA CHIPSET for certain SiS and VIA chipsets. 411 Older Intel and non-Intel chipsets may also benefit from 412 either 430_FX or SIS/VIA mode. 413 414 NORMAL PCI mode is enabled by default. 415 For INTEL 430 FX mode, add this to your kenel config: 416 options "BKTR_430_FX_MODE" 417 For SiS / VIA mode, add this to your kernel config: 418 options "BKTR_SIS_VIA_MODE" 419 420 Using quotes in these options is not needed in FreeBSD 4.x. 421 422 Note. Newer VIA chipsets should be fully PCI 2.1 compatible 423 and should work fine in the Default mode. 424 425 Also rename 849 to 849A, the correct name for the chip. 426 4271.69 12 June 1999 Roger Hardiman <roger@freebsd.org> 428 Updates for FreeBSD 4.x device driver interface. 429 BSDI code removed. Will be restored later. 430 4311.70 12 July 1999 Roger Hardiman <roger@freebsd.org> 432 Reorganise OS device dependant parts (based on a port to 433 linux by Brad Parker). 434 Make the driver compile on FreeBSD 2.2.x systems again. 435 Change number of VBI lines from 16 to 12 for NTSC formats. 436 Changes to probeCard() for better eeprom identification. 437 Added STB Bt878 card identification. 438 Add Hauppauge model identification to probeCard(). 439 Added TDA9850 initialisation code taken from Linux bttv. 440 Juha.Nurmela@quicknet.inet.fi found/fixed bug in VBI_SLEEP. 441 Matt Brown <matt@dqc.org> added MSP3430G DBX initialisation. 442 4431.71 30 Aug 1999 Roger Hardiman <roger@freebsd.org> 444 Small cleanup of OS dependant code. Remove NPCI usage. 445 Fix bug in AVerMedia detection. 446 Update VBI support for the AleVT Teletext package. Parts 447 from Juha Nurmela's driver <Juha.Nurmela@quicknet.inet.fi> 448 Add support for Hauppauge 627 and Temic 4006 submitted 449 by Maurice Castro <maurice@atum.castro.aus.net> 450 Tom Jansen <tom@unhooked.net> added BSDi support again. 451 4521.72 31 Aug 1999 Juha Nurmela <Juha.Nurmela@quicknet.inet.fi> 453 Clear cap_ctl register when restarting the RISC program. 454 This fixes the freezes experienced when changing changes. 455 4561.73 10 Sep 1999 Roger Hardiman <roger@freebsd.org> 457 Add Hauppauge tuner #6 for Brian Somers <brian@freebsd.org> 458 Add card type for Aimslabs Video Highway Xtreme for 459 Ladislav Kostal <kostal@pefstud.uniag.sk> 460 Added select() code (for VBI) for the 2.2.x driver 461 tested by Steve Richards <steve@richsoft.demon.co.uk> 462 4631.74 17 Sep 1999 Roger Hardiman <roger@freebsd.org> 464 Fix bug where FM radio stations were offset after using FXTV 465 AVerMedia tuner type autodetection added for cards with 466 a configuration EEPROM (currently their Bt878 range) 467 Thanks to Frank at AVerMedia for providing the information. 468 Tested by David La Croix <dlacroix@cowpie.acm.vt.edu> 469 Tidy up some tuner code and Hauppauge detection code. 470 New NetBSD code from Bernd Ernesti<bernd@arresum.inka.de> 471*/ 472 | |
473#ifdef __FreeBSD__ 474#include "bktr.h" 475#include "opt_bktr.h" 476#include "opt_devfs.h" 477#endif /* __FreeBSD__ */ 478 479#if defined(__NetBSD__) || defined(__OpenBSD__) 480#include "bktr.h" --- 5 unchanged lines hidden (view full) --- 486 || (defined(__bsdi__)) \ 487 || (defined(__OpenBSD__)) \ 488 || (defined(__NetBSD__)) \ 489 ) 490 491#include <sys/param.h> 492#include <sys/systm.h> 493#include <sys/conf.h> | 98#ifdef __FreeBSD__ 99#include "bktr.h" 100#include "opt_bktr.h" 101#include "opt_devfs.h" 102#endif /* __FreeBSD__ */ 103 104#if defined(__NetBSD__) || defined(__OpenBSD__) 105#include "bktr.h" --- 5 unchanged lines hidden (view full) --- 111 || (defined(__bsdi__)) \ 112 || (defined(__OpenBSD__)) \ 113 || (defined(__NetBSD__)) \ 114 ) 115 116#include <sys/param.h> 117#include <sys/systm.h> 118#include <sys/conf.h> |
494#include <sys/uio.h> | |
495#include <sys/kernel.h> 496#include <sys/signalvar.h> | 119#include <sys/kernel.h> 120#include <sys/signalvar.h> |
497#include <sys/mman.h> 498#include <sys/select.h> | |
499#include <sys/vnode.h> 500 501#include <vm/vm.h> 502#include <vm/vm_kern.h> 503#include <vm/pmap.h> 504#include <vm/vm_extern.h> 505 506/*******************/ 507/* *** FreeBSD *** */ 508/*******************/ 509#ifdef __FreeBSD__ 510 | 121#include <sys/vnode.h> 122 123#include <vm/vm.h> 124#include <vm/vm_kern.h> 125#include <vm/pmap.h> 126#include <vm/vm_extern.h> 127 128/*******************/ 129/* *** FreeBSD *** */ 130/*******************/ 131#ifdef __FreeBSD__ 132 |
511/* __FreeBSD_version is not defined on 2.2.x systems */ 512#ifndef __FreeBSD_version 513#define __FreeBSD_version 228000 514#endif 515 516#if (__FreeBSD_version >= 300000) 517#include <sys/poll.h> 518#endif 519 520/* Read NSMBUS on FreeBSD 3.1 or later */ 521#if (__FreeBSD_version >= 310000) 522#include "smbus.h" 523#else 524#define NSMBUS 0 525#endif 526 527#if (__FreeBSD_version < 400000) 528#ifdef DEVFS 529#include <sys/devfsext.h> 530#endif /* DEVFS */ 531#endif 532 | |
533#if (__FreeBSD_version >=400000) || (NSMBUS > 0) 534#include <sys/bus.h> /* used by smbus and newbus */ 535#endif 536 | 133#if (__FreeBSD_version >=400000) || (NSMBUS > 0) 134#include <sys/bus.h> /* used by smbus and newbus */ 135#endif 136 |
537#if (__FreeBSD_version >=400000) 538#include <machine/bus.h> /* used by newbus */ 539#include <sys/rman.h> /* used by newbus */ 540#include <machine/resource.h> /* used by newbus */ 541#endif 542 | |
543#include <machine/clock.h> /* for DELAY */ 544#include <pci/pcivar.h> | 137#include <machine/clock.h> /* for DELAY */ 138#include <pci/pcivar.h> |
545#include <pci/pcireg.h> | |
546 547#include <machine/ioctl_meteor.h> 548#include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ 549#include <dev/bktr/bktr_reg.h> | 139 140#include <machine/ioctl_meteor.h> 141#include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ 142#include <dev/bktr/bktr_reg.h> |
143#include <dev/bktr/bktr_tuner.h> 144#include <dev/bktr/bktr_card.h> 145#include <dev/bktr/bktr_audio.h> 146#include <dev/bktr/bktr_core.h> 147#include <dev/bktr/bktr_os.h> |
|
550 551#if (NSMBUS > 0) 552#include <dev/bktr/bktr_i2c.h> 553#include <dev/smbus/smbconf.h> 554#include <dev/iicbus/iiconf.h> 555#include "smbus_if.h" 556#include "iicbus_if.h" 557#endif 558 | 148 149#if (NSMBUS > 0) 150#include <dev/bktr/bktr_i2c.h> 151#include <dev/smbus/smbconf.h> 152#include <dev/iicbus/iiconf.h> 153#include "smbus_if.h" 154#include "iicbus_if.h" 155#endif 156 |
559#include <sys/sysctl.h> 560static int bt848_card = -1; 561static int bt848_tuner = -1; 562static int bt848_reverse_mute = -1; 563static int bt848_format = -1; | |
564 | 157 |
565SYSCTL_NODE(_hw, OID_AUTO, bt848, CTLFLAG_RW, 0, "Bt848 Driver mgmt"); 566SYSCTL_INT(_hw_bt848, OID_AUTO, card, CTLFLAG_RW, &bt848_card, -1, ""); 567SYSCTL_INT(_hw_bt848, OID_AUTO, tuner, CTLFLAG_RW, &bt848_tuner, -1, ""); 568SYSCTL_INT(_hw_bt848, OID_AUTO, reverse_mute, CTLFLAG_RW, &bt848_reverse_mute, -1, ""); 569SYSCTL_INT(_hw_bt848, OID_AUTO, format, CTLFLAG_RW, &bt848_format, -1, ""); 570 571#if (__FreeBSD_version >= 300000) 572typedef u_long ioctl_cmd_t; 573#endif 574 | |
575#if (__FreeBSD__ == 2) | 158#if (__FreeBSD__ == 2) |
576typedef int ioctl_cmd_t; | |
577typedef unsigned int uintptr_t; | 159typedef unsigned int uintptr_t; |
578#define PCIR_REVID PCI_CLASS_REG | |
579#endif 580#endif /* __FreeBSD__ */ 581 582 583/****************/ 584/* *** BSDI *** */ 585/****************/ 586#ifdef __bsdi__ --- 52 unchanged lines hidden (view full) --- 639#define VBI_DATA_SIZE (VBI_LINE_SIZE * MAX_VBI_LINES * 2) 640#define VBI_BUFFER_SIZE (VBI_DATA_SIZE * VBI_BUFFER_ITEMS) 641 642 643/* Defines for fields */ 644#define ODD_F 0x01 645#define EVEN_F 0x02 646 | 160#endif 161#endif /* __FreeBSD__ */ 162 163 164/****************/ 165/* *** BSDI *** */ 166/****************/ 167#ifdef __bsdi__ --- 52 unchanged lines hidden (view full) --- 220#define VBI_DATA_SIZE (VBI_LINE_SIZE * MAX_VBI_LINES * 2) 221#define VBI_BUFFER_SIZE (VBI_DATA_SIZE * VBI_BUFFER_ITEMS) 222 223 224/* Defines for fields */ 225#define ODD_F 0x01 226#define EVEN_F 0x02 227 |
647/* 648 * Defines for userland processes blocked in this driver 649 * For /dev/bktr[n] use memory address of bktr structure 650 * For /dev/vbi[n] use memory address of bktr structure + 1 651 * this is ok as the bktr structure is > 1 byte 652 */ 653#define BKTR_SLEEP ((caddr_t)bktr ) 654#define VBI_SLEEP ((caddr_t)bktr + 1) | |
655 656/* | 228 229/* |
657 * This is for start-up convenience only, NOT mandatory. 658 */ 659#if !defined( DEFAULT_CHNLSET ) 660#define DEFAULT_CHNLSET CHNLSET_WEUROPE 661#endif 662 663/* | |
664 * Parameters describing size of transmitted image. 665 */ 666 667static struct format_params format_params[] = { 668/* # define BT848_IFORM_F_AUTO (0x0) - don't matter. */ 669 { 525, 26, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_AUTO, 670 12, 1600 }, 671/* # define BT848_IFORM_F_NTSCM (0x1) */ --- 78 unchanged lines hidden (view full) --- 750#define METEOR_PIXFMT_TABLE_SIZE ( sizeof(meteor_pixfmt_table) / \ 751 sizeof(meteor_pixfmt_table[0]) ) 752 753 754#define BSWAP (BT848_COLOR_CTL_BSWAP_ODD | BT848_COLOR_CTL_BSWAP_EVEN) 755#define WSWAP (BT848_COLOR_CTL_WSWAP_ODD | BT848_COLOR_CTL_WSWAP_EVEN) 756 757 | 230 * Parameters describing size of transmitted image. 231 */ 232 233static struct format_params format_params[] = { 234/* # define BT848_IFORM_F_AUTO (0x0) - don't matter. */ 235 { 525, 26, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_AUTO, 236 12, 1600 }, 237/* # define BT848_IFORM_F_NTSCM (0x1) */ --- 78 unchanged lines hidden (view full) --- 316#define METEOR_PIXFMT_TABLE_SIZE ( sizeof(meteor_pixfmt_table) / \ 317 sizeof(meteor_pixfmt_table[0]) ) 318 319 320#define BSWAP (BT848_COLOR_CTL_BSWAP_ODD | BT848_COLOR_CTL_BSWAP_EVEN) 321#define WSWAP (BT848_COLOR_CTL_WSWAP_ODD | BT848_COLOR_CTL_WSWAP_EVEN) 322 323 |
758/* experimental code for Automatic Frequency Control */ 759#define TUNER_AFC 760#define TEST_TUNER_AFC_NOT | |
761 | 324 |
762#if defined( TUNER_AFC ) 763#define AFC_DELAY 10000 /* 10 millisend delay */ 764#define AFC_BITS 0x07 765#define AFC_FREQ_MINUS_125 0x00 766#define AFC_FREQ_MINUS_62 0x01 767#define AFC_FREQ_CENTERED 0x02 768#define AFC_FREQ_PLUS_62 0x03 769#define AFC_FREQ_PLUS_125 0x04 770#define AFC_MAX_STEP (5 * FREQFACTOR) /* no more than 5 MHz */ 771#endif /* TUNER_AFC */ 772 773/* 774 * i2c things: 775 */ 776 777#define TSA552x_CB_MSB (0x80) 778#define TSA552x_CB_CP (1<<6) 779#define TSA552x_CB_T2 (1<<5) 780#define TSA552x_CB_T1 (1<<4) 781#define TSA552x_CB_T0 (1<<3) 782#define TSA552x_CB_RSA (1<<2) 783#define TSA552x_CB_RSB (1<<1) 784#define TSA552x_CB_OS (1<<0) 785#define TSA552x_RADIO (TSA552x_CB_MSB | \ 786 TSA552x_CB_T0) 787 788/* Add RADIO_OFFSET to the "frequency" to indicate that we want to tune */ 789/* the radio (if present) not the TV tuner. */ 790/* 20000 is equivalent to 20000MHz/16 = 1.25GHz - this area is unused. */ 791#define RADIO_OFFSET 20000 792 793/* address(s) of the Hauppauge Infra-Red Remote Control adapter */ 794#define HAUP_REMOTE_INT_WADDR 0x30 795#define HAUP_REMOTE_INT_RADDR 0x31 796 797#define HAUP_REMOTE_EXT_WADDR 0x34 798#define HAUP_REMOTE_EXT_RADDR 0x35 799 800/* address of BTSC/SAP decoder chip */ 801#define TDA9850_WADDR 0xb6 802#define TDA9850_RADDR 0xb7 803 804/* address of MSP3400C chip */ 805#define MSP3400C_WADDR 0x80 806#define MSP3400C_RADDR 0x81 807 808 809/* EEProm (128 * 8) on an STB card */ 810#define X24C01_WADDR 0xae 811#define X24C01_RADDR 0xaf 812 813 814/* EEProm (256 * 8) on a Hauppauge card */ 815/* and on most BT878s cards to store the sub-system vendor id */ 816#define PFC8582_WADDR 0xa0 817#define PFC8582_RADDR 0xa1 818 819 820/* registers in the TDA9850 BTSC/dbx chip */ 821#define CON1ADDR 0x04 822#define CON2ADDR 0x05 823#define CON3ADDR 0x06 824#define CON4ADDR 0x07 825#define ALI1ADDR 0x08 826#define ALI2ADDR 0x09 827#define ALI3ADDR 0x0a 828 829 830/* raise the charge pump voltage for fast tuning */ 831#define TSA552x_FCONTROL (TSA552x_CB_MSB | \ 832 TSA552x_CB_CP | \ 833 TSA552x_CB_T0 | \ 834 TSA552x_CB_RSA | \ 835 TSA552x_CB_RSB) 836 837/* lower the charge pump voltage for better residual oscillator FM */ 838#define TSA552x_SCONTROL (TSA552x_CB_MSB | \ 839 TSA552x_CB_T0 | \ 840 TSA552x_CB_RSA | \ 841 TSA552x_CB_RSB) 842 843/* The control value for the ALPS TSCH5 Tuner */ 844#define TSCH5_FCONTROL 0x82 845#define TSCH5_RADIO 0x86 846 847/* The control value for the ALPS TSBH1 Tuner */ 848#define TSBH1_FCONTROL 0xce 849 850 | |
851/* sync detect threshold */ 852#if 0 853#define SYNC_LEVEL (BT848_ADC_RESERVED | \ 854 BT848_ADC_CRUSH) /* threshold ~125 mV */ 855#else 856#define SYNC_LEVEL (BT848_ADC_RESERVED | \ 857 BT848_ADC_SYNC_T) /* threshold ~75 mV */ 858#endif 859 860 | 325/* sync detect threshold */ 326#if 0 327#define SYNC_LEVEL (BT848_ADC_RESERVED | \ 328 BT848_ADC_CRUSH) /* threshold ~125 mV */ 329#else 330#define SYNC_LEVEL (BT848_ADC_RESERVED | \ 331 BT848_ADC_SYNC_T) /* threshold ~75 mV */ 332#endif 333 334 |
861/* 862 * the data for each type of tuner 863 * 864 * if probeCard() fails to detect the proper tuner on boot you can 865 * override it by setting the following define to the tuner present: 866 * 867#define OVERRIDE_TUNER <tuner type> 868 * 869 * where <tuner type> is one of the following tuner defines. 870 */ | |
871 | 335 |
872/* indexes into tuners[] */ 873#define NO_TUNER 0 874#define TEMIC_NTSC 1 875#define TEMIC_PAL 2 876#define TEMIC_SECAM 3 877#define PHILIPS_NTSC 4 878#define PHILIPS_PAL 5 879#define PHILIPS_SECAM 6 880#define TEMIC_PALI 7 881#define PHILIPS_PALI 8 882#define PHILIPS_FR1236_NTSC 9 /* These have FM Radio support */ 883#define PHILIPS_FR1216_PAL 10 /* These have FM Radio support */ 884#define PHILIPS_FR1236_SECAM 11 /* These have FM Radio support */ 885#define ALPS_TSCH5 12 886#define ALPS_TSBH1 13 887#define Bt848_MAX_TUNER 14 | |
888 | 336 |
889/* If we do not know the tuner type, make a guess based on the 890 video format 891*/ 892#if BROOKTREE_SYSTEM_DEFAULT == BROOKTREE_PAL 893#define DEFAULT_TUNER PHILIPS_PALI 894#else 895#define DEFAULT_TUNER PHILIPS_NTSC 896#endif 897 898/* XXX FIXME: this list is incomplete */ 899 900/* input types */ 901#define TTYPE_XXX 0 902#define TTYPE_NTSC 1 903#define TTYPE_NTSC_J 2 904#define TTYPE_PAL 3 905#define TTYPE_PAL_M 4 906#define TTYPE_PAL_N 5 907#define TTYPE_SECAM 6 908 909/** 910struct TUNER { 911 char* name; 912 u_char type; 913 u_char pllControl; 914 u_char bandLimits[ 2 ]; 915 u_char bandAddrs[ 3 ]; 916}; 917 */ 918static const struct TUNER tuners[] = { 919/* XXX FIXME: fill in the band-switch crosspoints */ 920 /* NO_TUNER */ 921 { "<no>", /* the 'name' */ 922 TTYPE_XXX, /* input type */ 923 { 0x00, /* control byte for Tuner PLL */ 924 0x00, 925 0x00, 926 0x00 }, 927 { 0x00, 0x00 }, /* band-switch crosspoints */ 928 { 0x00, 0x00, 0x00,0x00} }, /* the band-switch values */ 929 930 /* TEMIC_NTSC */ 931 { "Temic NTSC", /* the 'name' */ 932 TTYPE_NTSC, /* input type */ 933 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 934 TSA552x_SCONTROL, 935 TSA552x_SCONTROL, 936 0x00 }, 937 { 0x00, 0x00 }, /* band-switch crosspoints */ 938 { 0x02, 0x04, 0x01, 0x00 } }, /* the band-switch values */ 939 940 /* TEMIC_PAL */ 941 { "Temic PAL", /* the 'name' */ 942 TTYPE_PAL, /* input type */ 943 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 944 TSA552x_SCONTROL, 945 TSA552x_SCONTROL, 946 0x00 }, 947 { 0x00, 0x00 }, /* band-switch crosspoints */ 948 { 0x02, 0x04, 0x01, 0x00 } }, /* the band-switch values */ 949 950 /* TEMIC_SECAM */ 951 { "Temic SECAM", /* the 'name' */ 952 TTYPE_SECAM, /* input type */ 953 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 954 TSA552x_SCONTROL, 955 TSA552x_SCONTROL, 956 0x00 }, 957 { 0x00, 0x00 }, /* band-switch crosspoints */ 958 { 0x02, 0x04, 0x01,0x00 } }, /* the band-switch values */ 959 960 /* PHILIPS_NTSC */ 961 { "Philips NTSC", /* the 'name' */ 962 TTYPE_NTSC, /* input type */ 963 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 964 TSA552x_SCONTROL, 965 TSA552x_SCONTROL, 966 0x00 }, 967 { 0x00, 0x00 }, /* band-switch crosspoints */ 968 { 0xa0, 0x90, 0x30, 0x00 } }, /* the band-switch values */ 969 970 /* PHILIPS_PAL */ 971 { "Philips PAL", /* the 'name' */ 972 TTYPE_PAL, /* input type */ 973 { TSA552x_FCONTROL, /* control byte for Tuner PLL */ 974 TSA552x_FCONTROL, 975 TSA552x_FCONTROL, 976 TSA552x_RADIO }, 977 { 0x00, 0x00 }, /* band-switch crosspoints */ 978 { 0xa0, 0x90, 0x30, 0xa4 } }, /* the band-switch values */ 979 980 /* PHILIPS_SECAM */ 981 { "Philips SECAM", /* the 'name' */ 982 TTYPE_SECAM, /* input type */ 983 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 984 TSA552x_SCONTROL, 985 TSA552x_SCONTROL, 986 TSA552x_RADIO }, 987 { 0x00, 0x00 }, /* band-switch crosspoints */ 988 { 0xa0, 0x90, 0x30,0xa4 } }, /* the band-switch values */ 989 990 /* TEMIC_PAL I */ 991 { "Temic PAL I", /* the 'name' */ 992 TTYPE_PAL, /* input type */ 993 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 994 TSA552x_SCONTROL, 995 TSA552x_SCONTROL, 996 0x00 }, 997 { 0x00, 0x00 }, /* band-switch crosspoints */ 998 { 0x02, 0x04, 0x01,0x00 } }, /* the band-switch values */ 999 1000 /* PHILIPS_PALI */ 1001 { "Philips PAL I", /* the 'name' */ 1002 TTYPE_PAL, /* input type */ 1003 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 1004 TSA552x_SCONTROL, 1005 TSA552x_SCONTROL, 1006 0x00 }, 1007 { 0x00, 0x00 }, /* band-switch crosspoints */ 1008 { 0xa0, 0x90, 0x30,0x00 } }, /* the band-switch values */ 1009 1010 /* PHILIPS_FR1236_NTSC */ 1011 { "Philips FR1236 NTSC FM", /* the 'name' */ 1012 TTYPE_NTSC, /* input type */ 1013 { TSA552x_SCONTROL, /* control byte for Tuner PLL */ 1014 TSA552x_SCONTROL, 1015 TSA552x_SCONTROL, 1016 TSA552x_RADIO }, 1017 { 0x00, 0x00 }, /* band-switch crosspoints */ 1018 { 0xa0, 0x90, 0x30, 0xa4 } }, /* the band-switch values */ 1019 1020 /* PHILIPS_FR1216_PAL */ 1021 { "Philips FR1216 PAL FM" , /* the 'name' */ 1022 TTYPE_PAL, /* input type */ 1023 { TSA552x_FCONTROL, /* control byte for Tuner PLL */ 1024 TSA552x_FCONTROL, 1025 TSA552x_FCONTROL, 1026 TSA552x_RADIO }, 1027 { 0x00, 0x00 }, /* band-switch crosspoints */ 1028 { 0xa0, 0x90, 0x30, 0xa4 } }, /* the band-switch values */ 1029 1030 /* PHILIPS_FR1236_SECAM */ 1031 { "Philips FR1236 SECAM FM", /* the 'name' */ 1032 TTYPE_SECAM, /* input type */ 1033 { TSA552x_FCONTROL, /* control byte for Tuner PLL */ 1034 TSA552x_FCONTROL, 1035 TSA552x_FCONTROL, 1036 TSA552x_RADIO }, 1037 { 0x00, 0x00 }, /* band-switch crosspoints */ 1038 { 0xa0, 0x90, 0x30, 0xa4 } }, /* the band-switch values */ 1039 1040 /* ALPS TSCH5 NTSC */ 1041 { "ALPS TSCH5 NTSC FM", /* the 'name' */ 1042 TTYPE_NTSC, /* input type */ 1043 { TSCH5_FCONTROL, /* control byte for Tuner PLL */ 1044 TSCH5_FCONTROL, 1045 TSCH5_FCONTROL, 1046 TSCH5_RADIO }, 1047 { 0x00, 0x00 }, /* band-switch crosspoints */ 1048 { 0x14, 0x12, 0x11, 0x04 } }, /* the band-switch values */ 1049 1050 /* ALPS TSBH1 NTSC */ 1051 { "ALPS TSBH1 NTSC", /* the 'name' */ 1052 TTYPE_NTSC, /* input type */ 1053 { TSBH1_FCONTROL, /* control byte for Tuner PLL */ 1054 TSBH1_FCONTROL, 1055 TSBH1_FCONTROL, 1056 0x00 }, 1057 { 0x00, 0x00 }, /* band-switch crosspoints */ 1058 { 0x01, 0x02, 0x08, 0x00 } } /* the band-switch values */ 1059}; 1060 1061/****************************************************************************** 1062 * card probe 1063 */ 1064 1065 1066/* 1067 * the recognized cards, used as indexes of several tables. 1068 * 1069 * if probeCard() fails to detect the proper card on boot you can 1070 * override it by setting the following define to the card you are using: 1071 * 1072#define OVERRIDE_CARD <card type> 1073 * 1074 * where <card type> is one of the following card defines. 1075 */ 1076#define CARD_UNKNOWN 0 1077#define CARD_MIRO 1 1078#define CARD_HAUPPAUGE 2 1079#define CARD_STB 3 1080#define CARD_INTEL 4 1081#define CARD_IMS_TURBO 5 1082#define CARD_AVER_MEDIA 6 1083#define CARD_OSPREY 7 1084#define CARD_NEC_PK 8 1085#define CARD_IO_GV 9 1086#define CARD_FLYVIDEO 10 1087#define CARD_ZOLTRIX 11 1088#define CARD_KISS 12 1089#define CARD_VIDEO_HIGHWAY_XTREME 13 1090#define Bt848_MAX_CARD 14 1091 1092/* 1093 * the data for each type of card 1094 * 1095 * Note: 1096 * these entried MUST be kept in the order defined by the CARD_XXX defines! 1097 */ 1098static const struct CARDTYPE cards[] = { 1099 1100 { CARD_UNKNOWN, /* the card id */ 1101 "Unknown", /* the 'name' */ 1102 NULL, /* the tuner */ 1103 0, /* the tuner i2c address */ 1104 0, /* dbx unknown */ 1105 0, 1106 0, /* EEProm unknown */ 1107 0, /* EEProm unknown */ 1108 { 0, 0, 0, 0, 0 }, 1109 0 }, /* GPIO mask */ 1110 1111 { CARD_MIRO, /* the card id */ 1112 "Miro TV", /* the 'name' */ 1113 NULL, /* the tuner */ 1114 0, /* the tuner i2c address */ 1115 0, /* dbx unknown */ 1116 0, 1117 0, /* EEProm unknown */ 1118 0, /* size unknown */ 1119 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */ 1120 0x0f }, /* GPIO mask */ 1121 1122 { CARD_HAUPPAUGE, /* the card id */ 1123 "Hauppauge WinCast/TV", /* the 'name' */ 1124 NULL, /* the tuner */ 1125 0, /* the tuner i2c address */ 1126 0, /* dbx is optional */ 1127 0, 1128 PFC8582_WADDR, /* EEProm type */ 1129 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ 1130 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */ 1131 0x0f }, /* GPIO mask */ 1132 1133 { CARD_STB, /* the card id */ 1134 "STB TV/PCI", /* the 'name' */ 1135 NULL, /* the tuner */ 1136 0, /* the tuner i2c address */ 1137 0, /* dbx is optional */ 1138 0, 1139 X24C01_WADDR, /* EEProm type */ 1140 (u_char)(128 / EEPROMBLOCKSIZE), /* 128 bytes */ 1141 { 0x00, 0x01, 0x02, 0x02, 1 }, /* audio MUX values */ 1142 0x0f }, /* GPIO mask */ 1143 1144 { CARD_INTEL, /* the card id */ 1145 "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */ 1146 NULL, /* the tuner */ 1147 0, /* the tuner i2c address */ 1148 0, 1149 0, 1150 0, 1151 0, 1152 { 0, 0, 0, 0, 0 }, /* audio MUX values */ 1153 0x00 }, /* GPIO mask */ 1154 1155 { CARD_IMS_TURBO, /* the card id */ 1156 "IMS TV Turbo", /* the 'name' */ 1157 NULL, /* the tuner */ 1158 0, /* the tuner i2c address */ 1159 0, /* dbx is optional */ 1160 0, 1161 PFC8582_WADDR, /* EEProm type */ 1162 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ 1163 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */ 1164 0x0f }, /* GPIO mask */ 1165 1166 { CARD_AVER_MEDIA, /* the card id */ 1167 "AVer Media TV/FM", /* the 'name' */ 1168 NULL, /* the tuner */ 1169 0, /* the tuner i2c address */ 1170 0, /* dbx is optional */ 1171 0, 1172 0, /* EEProm type */ 1173 0, /* EEProm size */ 1174 { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */ 1175 0x0f }, /* GPIO mask */ 1176 1177 { CARD_OSPREY, /* the card id */ 1178 "MMAC Osprey", /* the 'name' */ 1179 NULL, /* the tuner */ 1180 0, /* the tuner i2c address */ 1181 0, /* dbx is optional */ 1182 0, 1183 PFC8582_WADDR, /* EEProm type */ 1184 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ 1185 { 0x00, 0x00, 0x00, 0x00, 0 }, /* audio MUX values */ 1186 0 }, /* GPIO mask */ 1187 1188 { CARD_NEC_PK, /* the card id */ 1189 "NEC PK-UG-X017", /* the 'name' */ 1190 NULL, /* the tuner */ 1191 0, /* the tuner i2c address */ 1192 0, /* dbx is optional */ 1193 0, 1194 0, /* EEProm type */ 1195 0, /* EEProm size */ 1196 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */ 1197 0x0f }, /* GPIO mask */ 1198 1199 { CARD_IO_GV, /* the card id */ 1200 "I/O DATA GV-BCTV2/PCI", /* the 'name' */ 1201 NULL, /* the tuner */ 1202 0, /* the tuner i2c address */ 1203 0, /* dbx is optional */ 1204 0, 1205 0, /* EEProm type */ 1206 0, /* EEProm size */ 1207 { 0x00, 0x00, 0x00, 0x00, 1 }, /* Has special MUX handler */ 1208 0x0f }, /* GPIO mask */ 1209 1210 { CARD_FLYVIDEO, /* the card id */ 1211 "FlyVideo", /* the 'name' */ 1212 NULL, /* the tuner */ 1213 0, /* the tuner i2c address */ 1214 0, /* dbx is optional */ 1215 0, /* msp34xx is optional */ 1216 0xac, /* EEProm type */ 1217 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ 1218 { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */ 1219 0x8dff00 }, /* GPIO mask */ 1220 1221 { CARD_ZOLTRIX, /* the card id */ 1222 "Zoltrix", /* the 'name' */ 1223 NULL, /* the tuner */ 1224 0, /* the tuner i2c address */ 1225 0, /* dbx is optional */ 1226 0, /* msp34xx is optional */ 1227 0, /* EEProm type */ 1228 0, /* EEProm size */ 1229 { 0x04, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */ 1230 0x0f }, /* GPIO mask */ 1231 1232 { CARD_KISS, /* the card id */ 1233 "KISS TV/FM PCI", /* the 'name' */ 1234 NULL, /* the tuner */ 1235 0, /* the tuner i2c address */ 1236 0, /* dbx is optional */ 1237 0, /* msp34xx is optional */ 1238 0, /* EEProm type */ 1239 0, /* EEProm size */ 1240 { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */ 1241 0x0f }, /* GPIO mask */ 1242 1243 { CARD_VIDEO_HIGHWAY_XTREME, /* the card id */ 1244 "Video Highway Xtreme", /* the 'name' */ 1245 NULL, /* the tuner */ 1246 0, /* the tuner i2c address */ 1247 0, /* dbx is optional */ 1248 0, 1249 0, /* EEProm type */ 1250 0, /* EEProm size */ 1251 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */ 1252 0x0f }, /* GPIO mask */ 1253 1254}; 1255 1256struct bt848_card_sig bt848_card_signature[1]= { 1257 /* IMS TURBO TV : card 5 */ 1258 { 5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}} 1259 1260 1261}; 1262 1263 | |
1264/* debug utility for holding previous INT_STAT contents */ 1265#define STATUS_SUM 1266static u_long status_sum = 0; 1267 1268/* 1269 * defines to make certain bit-fiddles understandable 1270 */ 1271#define FIFO_ENABLED BT848_DMA_CTL_FIFO_EN --- 7 unchanged lines hidden (view full) --- 1279 1280#define BIT_SEVEN_HIGH (1<<7) 1281#define BIT_EIGHT_HIGH (1<<8) 1282 1283#define I2C_BITS (BT848_INT_RACK | BT848_INT_I2CDONE) 1284#define TDEC_BITS (BT848_INT_FDSR | BT848_INT_FBUS) 1285 1286 | 337/* debug utility for holding previous INT_STAT contents */ 338#define STATUS_SUM 339static u_long status_sum = 0; 340 341/* 342 * defines to make certain bit-fiddles understandable 343 */ 344#define FIFO_ENABLED BT848_DMA_CTL_FIFO_EN --- 7 unchanged lines hidden (view full) --- 352 353#define BIT_SEVEN_HIGH (1<<7) 354#define BIT_EIGHT_HIGH (1<<8) 355 356#define I2C_BITS (BT848_INT_RACK | BT848_INT_I2CDONE) 357#define TDEC_BITS (BT848_INT_FDSR | BT848_INT_FBUS) 358 359 |
1287/* 1288 * misc. support routines. 1289 */ 1290static int signCard( bktr_ptr_t bktr, int offset, 1291 int count, u_char* sig ); 1292static void probeCard( bktr_ptr_t bktr, int verbose, int unit); | |
1293 | 360 |
1294static void common_bktr_attach( bktr_ptr_t bktr, int unit, 1295 u_long pci_id, u_int rev ); 1296 1297/**************************************************/ 1298/* *** Memory Allocation is still OS specific *** */ 1299/**************************************************/ 1300#if (defined(__FreeBSD__) || defined(__bsdi__)) 1301static vm_offset_t get_bktr_mem( int unit, unsigned size ); 1302#endif 1303 1304#if (defined(__NetBSD__) || defined(__OpenBSD__)) 1305static vm_offset_t get_bktr_mem(bktr_ptr_t, bus_dmamap_t *, unsigned size); 1306static void free_bktr_mem(bktr_ptr_t, bus_dmamap_t, vm_offset_t); 1307#endif 1308 1309 | |
1310static int oformat_meteor_to_bt( u_long format ); 1311 1312static u_int pixfmt_swap_flags( int pixfmt ); 1313 1314/* 1315 * bt848 RISC programming routines. 1316 */ 1317#ifdef BT848_DUMP --- 12 unchanged lines hidden (view full) --- 1330 int rows, int interlace ); 1331static void build_dma_prog( bktr_ptr_t bktr, char i_flag ); 1332 1333static bool_t getline(bktr_reg_t *, int); 1334static bool_t notclipped(bktr_reg_t * , int , int); 1335static bool_t split(bktr_reg_t *, volatile u_long **, int, u_long, int, 1336 volatile u_char ** , int ); 1337 | 361static int oformat_meteor_to_bt( u_long format ); 362 363static u_int pixfmt_swap_flags( int pixfmt ); 364 365/* 366 * bt848 RISC programming routines. 367 */ 368#ifdef BT848_DUMP --- 12 unchanged lines hidden (view full) --- 381 int rows, int interlace ); 382static void build_dma_prog( bktr_ptr_t bktr, char i_flag ); 383 384static bool_t getline(bktr_reg_t *, int); 385static bool_t notclipped(bktr_reg_t * , int , int); 386static bool_t split(bktr_reg_t *, volatile u_long **, int, u_long, int, 387 volatile u_char ** , int ); 388 |
1338/* 1339 * video & video capture specific routines. 1340 */ 1341static int video_open( bktr_ptr_t bktr ); 1342static int video_close( bktr_ptr_t bktr ); 1343static int video_read( bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio ); 1344static int video_ioctl( bktr_ptr_t bktr, int unit, 1345 int cmd, caddr_t arg, struct proc* pr ); 1346 | |
1347static void start_capture( bktr_ptr_t bktr, unsigned type ); 1348static void set_fps( bktr_ptr_t bktr, u_short fps ); 1349 1350 | 389static void start_capture( bktr_ptr_t bktr, unsigned type ); 390static void set_fps( bktr_ptr_t bktr, u_short fps ); 391 392 |
1351/* 1352 * tuner specific functions. 1353 */ 1354static int tuner_open( bktr_ptr_t bktr ); 1355static int tuner_close( bktr_ptr_t bktr ); 1356static int tuner_ioctl( bktr_ptr_t bktr, int unit, 1357 int cmd, caddr_t arg, struct proc* pr ); 1358static int tuner_getchnlset( struct bktr_chnlset *chnlset ); | |
1359 | 393 |
1360static int tv_channel( bktr_ptr_t bktr, int channel ); 1361static int tv_freq( bktr_ptr_t bktr, int frequency ); 1362#if defined( TUNER_AFC ) 1363static int do_afc( bktr_ptr_t bktr, int addr, int frequency ); 1364#endif /* TUNER_AFC */ 1365 | |
1366/* | 394/* |
1367 * vbi specific functions. 1368 */ 1369static int vbi_open( bktr_ptr_t bktr ); 1370static int vbi_close( bktr_ptr_t bktr ); 1371static int vbi_read( bktr_ptr_t bktr, struct uio *uio, int ioflag ); 1372 1373/* 1374 * audio specific functions. 1375 */ 1376static int set_audio( bktr_ptr_t bktr, int mode ); 1377static void temp_mute( bktr_ptr_t bktr, int flag ); 1378 1379static void init_BTSC( bktr_ptr_t bktr ); 1380static int set_BTSC( bktr_ptr_t bktr, int control ); 1381 1382static void msp_autodetect( bktr_ptr_t bktr ); 1383static void msp_read_id( bktr_ptr_t bktr, int unit ); 1384static void msp_reset( bktr_ptr_t bktr ); 1385static unsigned int msp_read(bktr_ptr_t bktr, unsigned char dev, 1386 unsigned int addr); 1387static void msp_write( bktr_ptr_t bktr, unsigned char dev, 1388 unsigned int addr, unsigned int data); 1389 1390/* | |
1391 * Remote Control Functions 1392 */ 1393static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote); 1394 1395 1396/* 1397 * ioctls common to both video & tuner. 1398 */ 1399static int common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, 1400 int cmd, caddr_t arg ); 1401 1402 | 395 * Remote Control Functions 396 */ 397static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote); 398 399 400/* 401 * ioctls common to both video & tuner. 402 */ 403static int common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, 404 int cmd, caddr_t arg ); 405 406 |
1403/* 1404 * i2c primitives 1405 */ 1406static int i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ); 1407static int i2cRead( bktr_ptr_t bktr, int addr ); 1408static int writeEEProm( bktr_ptr_t bktr, int offset, int count, 1409 u_char* data ); 1410static int readEEProm( bktr_ptr_t bktr, int offset, int count, 1411 u_char* data ); 1412 | |
1413#if ((!defined(__FreeBSD__)) || (NSMBUS == 0) ) 1414/* 1415 * i2c primatives for low level control of i2c bus. Added for MSP34xx control 1416 */ 1417static void i2c_start( bktr_ptr_t bktr); 1418static void i2c_stop( bktr_ptr_t bktr); 1419static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data); 1420static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ); 1421#endif 1422 | 407#if ((!defined(__FreeBSD__)) || (NSMBUS == 0) ) 408/* 409 * i2c primatives for low level control of i2c bus. Added for MSP34xx control 410 */ 411static void i2c_start( bktr_ptr_t bktr); 412static void i2c_stop( bktr_ptr_t bktr); 413static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data); 414static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ); 415#endif 416 |
1423/* 1424 * CARD_GV_BCTV specific functions. 1425 */ 1426static void set_bctv_audio( bktr_ptr_t bktr ); 1427static void bctv_gpio_write( bktr_ptr_t bktr, int port, int val ); 1428/*static int bctv_gpio_read( bktr_ptr_t bktr, int port );*/ /* Not used */ | |
1429 1430 1431/* 1432 * the common attach code, used by all OS versions. 1433 */ | 417 418 419/* 420 * the common attach code, used by all OS versions. 421 */ |
1434static void | 422void |
1435common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev ) 1436{ 1437 bt848_ptr_t bt848; 1438 vm_offset_t buf; 1439 1440 bt848 = bktr->base; 1441 1442/***************************************/ --- 83 unchanged lines hidden (view full) --- 1526 bktr->clr_on_start = FALSE; 1527 1528 /* defaults for the tuner section of the card */ 1529 bktr->tflags = TUNER_INITALIZED; 1530 bktr->tuner.frequency = 0; 1531 bktr->tuner.channel = 0; 1532 bktr->tuner.chnlset = DEFAULT_CHNLSET; 1533 bktr->tuner.afc = 0; | 423common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev ) 424{ 425 bt848_ptr_t bt848; 426 vm_offset_t buf; 427 428 bt848 = bktr->base; 429 430/***************************************/ --- 83 unchanged lines hidden (view full) --- 514 bktr->clr_on_start = FALSE; 515 516 /* defaults for the tuner section of the card */ 517 bktr->tflags = TUNER_INITALIZED; 518 bktr->tuner.frequency = 0; 519 bktr->tuner.channel = 0; 520 bktr->tuner.chnlset = DEFAULT_CHNLSET; 521 bktr->tuner.afc = 0; |
1534 bktr->tuner.radio_mode = 0; | 522 bktr->tuner.radio_mode = 0; |
1535 bktr->audio_mux_select = 0; 1536 bktr->audio_mute_state = FALSE; 1537 bktr->bt848_card = -1; 1538 bktr->bt848_tuner = -1; 1539 bktr->reverse_mute = -1; 1540 1541 probeCard( bktr, TRUE, unit ); 1542 | 523 bktr->audio_mux_select = 0; 524 bktr->audio_mute_state = FALSE; 525 bktr->bt848_card = -1; 526 bktr->bt848_tuner = -1; 527 bktr->reverse_mute = -1; 528 529 probeCard( bktr, TRUE, unit ); 530 |
1543 /* If there is an MSP Audio device, reset it and display the model */ 1544 if (bktr->card.msp3400c)msp_reset(bktr); 1545 if (bktr->card.msp3400c)msp_read_id(bktr, unit); | 531 /* Initialise any MSP34xx or TDA98xx audio chips */ 532 init_audio_devices( bktr ); |
1546 1547} 1548 1549 1550/* Copy the vbi lines from 'vbidata' into the circular buffer, 'vbibuffer'. 1551 * The circular buffer holds 'n' fixed size data blocks. 1552 * vbisize is the number of bytes in the circular buffer 1553 * vbiread is the point we reading data out of the circular buffer --- 8 unchanged lines hidden (view full) --- 1562 1563 /* Copy the VBI data into the next free slot in the buffer. */ 1564 /* 'dest' is the point in vbibuffer where we want to insert new data */ 1565 dest = (unsigned char *)bktr->vbibuffer + bktr->vbiinsert; 1566 memcpy(dest, (unsigned char*)bktr->vbidata, VBI_DATA_SIZE); 1567 1568 /* Write the VBI sequence number to the end of the vbi data */ 1569 /* This is used by the AleVT teletext program */ | 533 534} 535 536 537/* Copy the vbi lines from 'vbidata' into the circular buffer, 'vbibuffer'. 538 * The circular buffer holds 'n' fixed size data blocks. 539 * vbisize is the number of bytes in the circular buffer 540 * vbiread is the point we reading data out of the circular buffer --- 8 unchanged lines hidden (view full) --- 549 550 /* Copy the VBI data into the next free slot in the buffer. */ 551 /* 'dest' is the point in vbibuffer where we want to insert new data */ 552 dest = (unsigned char *)bktr->vbibuffer + bktr->vbiinsert; 553 memcpy(dest, (unsigned char*)bktr->vbidata, VBI_DATA_SIZE); 554 555 /* Write the VBI sequence number to the end of the vbi data */ 556 /* This is used by the AleVT teletext program */ |
1570 seq_dest = (unsigned int *)((unsigned char *)bktr->vbibuffer + bktr->vbiinsert | 557 seq_dest = (unsigned int *)((unsigned char *)bktr->vbibuffer 558 + bktr->vbiinsert |
1571 + (VBI_DATA_SIZE - sizeof(bktr->vbi_sequence_number))); 1572 *seq_dest = bktr->vbi_sequence_number; 1573 1574 /* And increase the VBI sequence number */ 1575 /* This can wrap around */ 1576 bktr->vbi_sequence_number++; 1577 1578 --- 9 unchanged lines hidden (view full) --- 1588 1589 1590/* 1591 * the common interrupt handler. 1592 * Returns a 0 or 1 depending on whether the interrupt has handled. 1593 * In the OS specific section, bktr_intr() is defined which calls this 1594 * common interrupt handler. 1595 */ | 559 + (VBI_DATA_SIZE - sizeof(bktr->vbi_sequence_number))); 560 *seq_dest = bktr->vbi_sequence_number; 561 562 /* And increase the VBI sequence number */ 563 /* This can wrap around */ 564 bktr->vbi_sequence_number++; 565 566 --- 9 unchanged lines hidden (view full) --- 576 577 578/* 579 * the common interrupt handler. 580 * Returns a 0 or 1 depending on whether the interrupt has handled. 581 * In the OS specific section, bktr_intr() is defined which calls this 582 * common interrupt handler. 583 */ |
1596static int | 584int |
1597common_bktr_intr( void *arg ) 1598{ 1599 bktr_ptr_t bktr; 1600 bt848_ptr_t bt848; 1601 u_long bktr_status; 1602 u_char dstatus; 1603 u_long field; 1604 u_long w_field; --- 257 unchanged lines hidden (view full) --- 1862} 1863 1864 1865 1866 1867/* 1868 * 1869 */ | 585common_bktr_intr( void *arg ) 586{ 587 bktr_ptr_t bktr; 588 bt848_ptr_t bt848; 589 u_long bktr_status; 590 u_char dstatus; 591 u_long field; 592 u_long w_field; --- 257 unchanged lines hidden (view full) --- 850} 851 852 853 854 855/* 856 * 857 */ |
1870static int | 858extern int bt848_format; /* used to set the default format, PAL or NTSC */ 859int |
1871video_open( bktr_ptr_t bktr ) 1872{ 1873 bt848_ptr_t bt848; 1874 int frame_rate, video_format=0; 1875 1876 if (bktr->flags & METEOR_OPEN) /* device is busy */ 1877 return( EBUSY ); 1878 --- 93 unchanged lines hidden (view full) --- 1972 bktr->capture_area_enabled = FALSE; 1973 1974 bt848->int_mask = BT848_INT_MYSTERYBIT; /* if you take this out triton 1975 based motherboards will 1976 operate unreliably */ 1977 return( 0 ); 1978} 1979 | 860video_open( bktr_ptr_t bktr ) 861{ 862 bt848_ptr_t bt848; 863 int frame_rate, video_format=0; 864 865 if (bktr->flags & METEOR_OPEN) /* device is busy */ 866 return( EBUSY ); 867 --- 93 unchanged lines hidden (view full) --- 961 bktr->capture_area_enabled = FALSE; 962 963 bt848->int_mask = BT848_INT_MYSTERYBIT; /* if you take this out triton 964 based motherboards will 965 operate unreliably */ 966 return( 0 ); 967} 968 |
1980static int | 969int |
1981vbi_open( bktr_ptr_t bktr ) 1982{ 1983 if (bktr->vbiflags & VBI_OPEN) /* device is busy */ 1984 return( EBUSY ); 1985 1986 bktr->vbiflags |= VBI_OPEN; 1987 1988 /* reset the VBI circular buffer pointers and clear the buffers */ --- 7 unchanged lines hidden (view full) --- 1996 bzero((caddr_t) bktr->vbidata, VBI_DATA_SIZE); 1997 1998 return( 0 ); 1999} 2000 2001/* 2002 * 2003 */ | 970vbi_open( bktr_ptr_t bktr ) 971{ 972 if (bktr->vbiflags & VBI_OPEN) /* device is busy */ 973 return( EBUSY ); 974 975 bktr->vbiflags |= VBI_OPEN; 976 977 /* reset the VBI circular buffer pointers and clear the buffers */ --- 7 unchanged lines hidden (view full) --- 985 bzero((caddr_t) bktr->vbidata, VBI_DATA_SIZE); 986 987 return( 0 ); 988} 989 990/* 991 * 992 */ |
2004static int | 993int |
2005tuner_open( bktr_ptr_t bktr ) 2006{ 2007 if ( !(bktr->tflags & TUNER_INITALIZED) ) /* device not found */ 2008 return( ENXIO ); 2009 2010 if ( bktr->tflags & TUNER_OPEN ) /* already open */ 2011 return( 0 ); 2012 2013 bktr->tflags |= TUNER_OPEN; 2014 bktr->tuner.frequency = 0; 2015 bktr->tuner.channel = 0; 2016 bktr->tuner.chnlset = DEFAULT_CHNLSET; 2017 bktr->tuner.afc = 0; | 994tuner_open( bktr_ptr_t bktr ) 995{ 996 if ( !(bktr->tflags & TUNER_INITALIZED) ) /* device not found */ 997 return( ENXIO ); 998 999 if ( bktr->tflags & TUNER_OPEN ) /* already open */ 1000 return( 0 ); 1001 1002 bktr->tflags |= TUNER_OPEN; 1003 bktr->tuner.frequency = 0; 1004 bktr->tuner.channel = 0; 1005 bktr->tuner.chnlset = DEFAULT_CHNLSET; 1006 bktr->tuner.afc = 0; |
2018 bktr->tuner.radio_mode = 0; | 1007 bktr->tuner.radio_mode = 0; |
2019 2020 /* enable drivers on the GPIO port that control the MUXes */ 2021 bktr->base->gpio_out_en |= bktr->card.gpio_mux_bits; 2022 2023 /* unmute the audio stream */ 2024 set_audio( bktr, AUDIO_UNMUTE ); 2025 | 1008 1009 /* enable drivers on the GPIO port that control the MUXes */ 1010 bktr->base->gpio_out_en |= bktr->card.gpio_mux_bits; 1011 1012 /* unmute the audio stream */ 1013 set_audio( bktr, AUDIO_UNMUTE ); 1014 |
2026 /* enable stereo if appropriate on TDA audio chip */ 2027 if ( bktr->card.dbx ) 2028 init_BTSC( bktr ); 2029 2030 /* reset the MSP34xx stereo audio chip */ 2031 if ( bktr->card.msp3400c ) 2032 msp_reset( bktr ); | 1015 /* Initialise any audio chips, eg MSP34xx or TDA98xx */ 1016 init_audio_devices( bktr ); |
2033 2034 return( 0 ); 2035} 2036 2037 2038 2039 2040/* 2041 * 2042 */ | 1017 1018 return( 0 ); 1019} 1020 1021 1022 1023 1024/* 1025 * 1026 */ |
2043static int | 1027int |
2044video_close( bktr_ptr_t bktr ) 2045{ 2046 bt848_ptr_t bt848; 2047 2048 bktr->flags &= ~(METEOR_OPEN | 2049 METEOR_SINGLE | 2050 METEOR_CAP_MASK | 2051 METEOR_WANT_MASK); --- 13 unchanged lines hidden (view full) --- 2065 return( 0 ); 2066} 2067 2068 2069/* 2070 * tuner close handle, 2071 * place holder for tuner specific operations on a close. 2072 */ | 1028video_close( bktr_ptr_t bktr ) 1029{ 1030 bt848_ptr_t bt848; 1031 1032 bktr->flags &= ~(METEOR_OPEN | 1033 METEOR_SINGLE | 1034 METEOR_CAP_MASK | 1035 METEOR_WANT_MASK); --- 13 unchanged lines hidden (view full) --- 1049 return( 0 ); 1050} 1051 1052 1053/* 1054 * tuner close handle, 1055 * place holder for tuner specific operations on a close. 1056 */ |
2073static int | 1057int |
2074tuner_close( bktr_ptr_t bktr ) 2075{ 2076 bktr->tflags &= ~TUNER_OPEN; 2077 2078 /* mute the audio by switching the mux */ 2079 set_audio( bktr, AUDIO_MUTE ); 2080 2081 /* disable drivers on the GPIO port that control the MUXes */ 2082 bktr->base->gpio_out_en = bktr->base->gpio_out_en & ~bktr->card.gpio_mux_bits; 2083 2084 return( 0 ); 2085} 2086 | 1058tuner_close( bktr_ptr_t bktr ) 1059{ 1060 bktr->tflags &= ~TUNER_OPEN; 1061 1062 /* mute the audio by switching the mux */ 1063 set_audio( bktr, AUDIO_MUTE ); 1064 1065 /* disable drivers on the GPIO port that control the MUXes */ 1066 bktr->base->gpio_out_en = bktr->base->gpio_out_en & ~bktr->card.gpio_mux_bits; 1067 1068 return( 0 ); 1069} 1070 |
2087static int | 1071int |
2088vbi_close( bktr_ptr_t bktr ) 2089{ 2090 2091 bktr->vbiflags &= ~VBI_OPEN; 2092 2093 return( 0 ); 2094} 2095 2096/* 2097 * 2098 */ | 1072vbi_close( bktr_ptr_t bktr ) 1073{ 1074 1075 bktr->vbiflags &= ~VBI_OPEN; 1076 1077 return( 0 ); 1078} 1079 1080/* 1081 * 1082 */ |
2099static int | 1083int |
2100video_read(bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio) 2101{ 2102 bt848_ptr_t bt848; 2103 int status; 2104 int count; 2105 2106 2107 bt848 = bktr->base; --- 40 unchanged lines hidden (view full) --- 2148 2149/* 2150 * Read VBI data from the vbi circular buffer 2151 * The buffer holds vbi data blocks which are the same size 2152 * vbiinsert is the position we will insert the next item into the buffer 2153 * vbistart is the actual position in the buffer we want to read from 2154 * vbisize is the exact number of bytes in the buffer left to read 2155 */ | 1084video_read(bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio) 1085{ 1086 bt848_ptr_t bt848; 1087 int status; 1088 int count; 1089 1090 1091 bt848 = bktr->base; --- 40 unchanged lines hidden (view full) --- 1132 1133/* 1134 * Read VBI data from the vbi circular buffer 1135 * The buffer holds vbi data blocks which are the same size 1136 * vbiinsert is the position we will insert the next item into the buffer 1137 * vbistart is the actual position in the buffer we want to read from 1138 * vbisize is the exact number of bytes in the buffer left to read 1139 */ |
2156static int | 1140int |
2157vbi_read(bktr_ptr_t bktr, struct uio *uio, int ioflag) 2158{ 2159 int readsize, readsize2; 2160 int status; 2161 2162 2163 while(bktr->vbisize == 0) { 2164 if (ioflag & IO_NDELAY) { --- 30 unchanged lines hidden (view full) --- 2195 2196 /* Update the number of bytes left to read */ 2197 bktr->vbisize -= readsize; 2198 2199 /* Update vbistart */ 2200 bktr->vbistart += readsize; 2201 bktr->vbistart = bktr->vbistart % VBI_BUFFER_SIZE; /* wrap around if needed */ 2202 | 1141vbi_read(bktr_ptr_t bktr, struct uio *uio, int ioflag) 1142{ 1143 int readsize, readsize2; 1144 int status; 1145 1146 1147 while(bktr->vbisize == 0) { 1148 if (ioflag & IO_NDELAY) { --- 30 unchanged lines hidden (view full) --- 1179 1180 /* Update the number of bytes left to read */ 1181 bktr->vbisize -= readsize; 1182 1183 /* Update vbistart */ 1184 bktr->vbistart += readsize; 1185 bktr->vbistart = bktr->vbistart % VBI_BUFFER_SIZE; /* wrap around if needed */ 1186 |
2203return( status ); | 1187 return( status ); |
2204 2205} 2206 2207 2208 2209/* 2210 * video ioctls 2211 */ | 1188 1189} 1190 1191 1192 1193/* 1194 * video ioctls 1195 */ |
2212static int | 1196int |
2213video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) 2214{ 2215 bt848_ptr_t bt848; 2216 volatile u_char c_temp; 2217 unsigned int temp; 2218 unsigned int temp_iform; 2219 unsigned int error; 2220 struct meteor_geomet *geo; --- 587 unchanged lines hidden (view full) --- 2808 } 2809 2810 return( 0 ); 2811} 2812 2813/* 2814 * tuner ioctls 2815 */ | 1197video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) 1198{ 1199 bt848_ptr_t bt848; 1200 volatile u_char c_temp; 1201 unsigned int temp; 1202 unsigned int temp_iform; 1203 unsigned int error; 1204 struct meteor_geomet *geo; --- 587 unchanged lines hidden (view full) --- 1792 } 1793 1794 return( 0 ); 1795} 1796 1797/* 1798 * tuner ioctls 1799 */ |
2816static int | 1800int |
2817tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) 2818{ 2819 bt848_ptr_t bt848; 2820 int tmp_int; 2821 unsigned int temp, temp1; 2822 int offset; 2823 int count; 2824 u_char *buf; --- 22 unchanged lines hidden (view full) --- 2847 *(int *)arg = bktr->tuner.afc; 2848 /* XXX Perhaps use another bit to indicate AFC success? */ 2849 break; 2850#endif /* TUNER_AFC */ 2851 2852 case TVTUNER_SETCHNL: 2853 temp_mute( bktr, TRUE ); 2854 temp = tv_channel( bktr, (int)*(unsigned long *)arg ); | 1801tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) 1802{ 1803 bt848_ptr_t bt848; 1804 int tmp_int; 1805 unsigned int temp, temp1; 1806 int offset; 1807 int count; 1808 u_char *buf; --- 22 unchanged lines hidden (view full) --- 1831 *(int *)arg = bktr->tuner.afc; 1832 /* XXX Perhaps use another bit to indicate AFC success? */ 1833 break; 1834#endif /* TUNER_AFC */ 1835 1836 case TVTUNER_SETCHNL: 1837 temp_mute( bktr, TRUE ); 1838 temp = tv_channel( bktr, (int)*(unsigned long *)arg ); |
2855 temp_mute( bktr, FALSE ); 2856 if ( temp < 0 ) | 1839 if ( temp < 0 ) { 1840 temp_mute( bktr, FALSE ); |
2857 return( EINVAL ); | 1841 return( EINVAL ); |
1842 } |
|
2858 *(unsigned long *)arg = temp; 2859 2860 /* after every channel change, we must restart the MSP34xx */ 2861 /* audio chip to reselect NICAM STEREO or MONO audio */ 2862 if ( bktr->card.msp3400c ) 2863 msp_autodetect( bktr ); | 1843 *(unsigned long *)arg = temp; 1844 1845 /* after every channel change, we must restart the MSP34xx */ 1846 /* audio chip to reselect NICAM STEREO or MONO audio */ 1847 if ( bktr->card.msp3400c ) 1848 msp_autodetect( bktr ); |
1849 1850 temp_mute( bktr, FALSE ); |
|
2864 break; 2865 2866 case TVTUNER_GETCHNL: 2867 *(unsigned long *)arg = bktr->tuner.channel; 2868 break; 2869 2870 case TVTUNER_SETTYPE: 2871 temp = *(unsigned long *)arg; 2872 if ( (temp < CHNLSET_MIN) || (temp > CHNLSET_MAX) ) 2873 return( EINVAL ); 2874 bktr->tuner.chnlset = temp; 2875 break; 2876 2877 case TVTUNER_GETTYPE: 2878 *(unsigned long *)arg = bktr->tuner.chnlset; 2879 break; 2880 2881 case TVTUNER_GETSTATUS: | 1851 break; 1852 1853 case TVTUNER_GETCHNL: 1854 *(unsigned long *)arg = bktr->tuner.channel; 1855 break; 1856 1857 case TVTUNER_SETTYPE: 1858 temp = *(unsigned long *)arg; 1859 if ( (temp < CHNLSET_MIN) || (temp > CHNLSET_MAX) ) 1860 return( EINVAL ); 1861 bktr->tuner.chnlset = temp; 1862 break; 1863 1864 case TVTUNER_GETTYPE: 1865 *(unsigned long *)arg = bktr->tuner.chnlset; 1866 break; 1867 1868 case TVTUNER_GETSTATUS: |
2882 temp = i2cRead( bktr, bktr->card.tuner_pllAddr + 1 ); | 1869 temp = get_tuner_status( bktr ); |
2883 *(unsigned long *)arg = temp & 0xff; 2884 break; 2885 2886 case TVTUNER_SETFREQ: 2887 temp_mute( bktr, TRUE ); | 1870 *(unsigned long *)arg = temp & 0xff; 1871 break; 1872 1873 case TVTUNER_SETFREQ: 1874 temp_mute( bktr, TRUE ); |
2888 temp = tv_freq( bktr, (int)*(unsigned long *)arg ); | 1875 temp = tv_freq( bktr, (int)*(unsigned long *)arg, TV_FREQUENCY); |
2889 temp_mute( bktr, FALSE ); | 1876 temp_mute( bktr, FALSE ); |
2890 if ( temp < 0 ) | 1877 if ( temp < 0 ) { 1878 temp_mute( bktr, FALSE ); |
2891 return( EINVAL ); | 1879 return( EINVAL ); |
1880 } |
|
2892 *(unsigned long *)arg = temp; 2893 2894 /* after every channel change, we must restart the MSP34xx */ 2895 /* audio chip to reselect NICAM STEREO or MONO audio */ 2896 if ( bktr->card.msp3400c ) 2897 msp_autodetect( bktr ); | 1881 *(unsigned long *)arg = temp; 1882 1883 /* after every channel change, we must restart the MSP34xx */ 1884 /* audio chip to reselect NICAM STEREO or MONO audio */ 1885 if ( bktr->card.msp3400c ) 1886 msp_autodetect( bktr ); |
1887 1888 temp_mute( bktr, FALSE ); |
|
2898 break; 2899 2900 case TVTUNER_GETFREQ: 2901 *(unsigned long *)arg = bktr->tuner.frequency; 2902 break; 2903 2904 case TVTUNER_GETCHNLSET: 2905 return tuner_getchnlset((struct bktr_chnlset *)arg); --- 222 unchanged lines hidden (view full) --- 3128 *(unsigned char *)arg = bktr->tuner.radio_mode; 3129 break; 3130 3131 case RADIO_SETMODE: 3132 bktr->tuner.radio_mode = *(unsigned char *)arg; 3133 break; 3134 3135 case RADIO_GETFREQ: | 1889 break; 1890 1891 case TVTUNER_GETFREQ: 1892 *(unsigned long *)arg = bktr->tuner.frequency; 1893 break; 1894 1895 case TVTUNER_GETCHNLSET: 1896 return tuner_getchnlset((struct bktr_chnlset *)arg); --- 222 unchanged lines hidden (view full) --- 2119 *(unsigned char *)arg = bktr->tuner.radio_mode; 2120 break; 2121 2122 case RADIO_SETMODE: 2123 bktr->tuner.radio_mode = *(unsigned char *)arg; 2124 break; 2125 2126 case RADIO_GETFREQ: |
3136 *(unsigned long *)arg = (bktr->tuner.frequency+407)*5; | 2127 *(unsigned long *)arg = bktr->tuner.frequency; |
3137 break; 3138 3139 case RADIO_SETFREQ: 3140 /* The argument to this ioctl is NOT freq*16. It is 3141 ** freq*100. 3142 */ 3143 | 2128 break; 2129 2130 case RADIO_SETFREQ: 2131 /* The argument to this ioctl is NOT freq*16. It is 2132 ** freq*100. 2133 */ 2134 |
3144 /* The radio in my stereo and the linear regression function 3145 ** in my HP48 have reached the conclusion that in order to 3146 ** set the radio tuner of the FM1216 to f MHz, the value to 3147 ** enter into the Tuner PLL is: f*20-407 3148 ** If anyone has the exact values from the spec. sheet 3149 ** please forward them -- fj@login.dknet.dk 3150 */ | 2135 temp=(int)*(unsigned long *)arg; |
3151 | 2136 |
3152 if(bktr->bt848_tuner == ALPS_TSCH5) { 3153 temp=((int)*(unsigned long *)arg + 4125) * 32; 3154 temp=temp/100 + (temp%100 >= 50 ? 1 : 0) +RADIO_OFFSET; 3155 } else { 3156 temp=(int)*(unsigned long *)arg/5-407 +RADIO_OFFSET; 3157 } 3158 | |
3159#ifdef BKTR_RADIO_DEBUG 3160 printf("bktr%d: arg=%d temp=%d\n",unit,(int)*(unsigned long *)arg,temp); 3161#endif 3162 3163#ifndef BKTR_RADIO_NOFREQCHECK 3164 /* According to the spec. sheet the band: 87.5MHz-108MHz */ 3165 /* is supported. */ | 2137#ifdef BKTR_RADIO_DEBUG 2138 printf("bktr%d: arg=%d temp=%d\n",unit,(int)*(unsigned long *)arg,temp); 2139#endif 2140 2141#ifndef BKTR_RADIO_NOFREQCHECK 2142 /* According to the spec. sheet the band: 87.5MHz-108MHz */ 2143 /* is supported. */ |
3166 if(temp<1343+RADIO_OFFSET || temp>1753+RADIO_OFFSET) { | 2144 if(temp<8750 || temp>10800) { |
3167 printf("bktr%d: Radio frequency out of range\n",unit); 3168 return(EINVAL); 3169 } 3170#endif 3171 temp_mute( bktr, TRUE ); | 2145 printf("bktr%d: Radio frequency out of range\n",unit); 2146 return(EINVAL); 2147 } 2148#endif 2149 temp_mute( bktr, TRUE ); |
3172 temp = tv_freq( bktr, temp ); | 2150 temp = tv_freq( bktr, temp, FM_RADIO_FREQUENCY ); |
3173 temp_mute( bktr, FALSE ); 3174#ifdef BKTR_RADIO_DEBUG 3175 if(temp) 3176 printf("bktr%d: tv_freq returned: %d\n",unit,temp); 3177#endif 3178 if ( temp < 0 ) 3179 return( EINVAL ); 3180 *(unsigned long *)arg = temp; 3181 break; | 2151 temp_mute( bktr, FALSE ); 2152#ifdef BKTR_RADIO_DEBUG 2153 if(temp) 2154 printf("bktr%d: tv_freq returned: %d\n",unit,temp); 2155#endif 2156 if ( temp < 0 ) 2157 return( EINVAL ); 2158 *(unsigned long *)arg = temp; 2159 break; |
3182 /* Luigi's I2CWR ioctl */ | 2160 2161 /* Luigi's I2CWR ioctl */ |
3183 case BT848_I2CWR: 3184 par = *(u_long *)arg; 3185 write = (par >> 24) & 0xff ; 3186 i2c_addr = (par >> 16) & 0xff ; 3187 i2c_port = (par >> 8) & 0xff ; 3188 data = (par) & 0xff ; 3189 3190 if (write) { --- 413 unchanged lines hidden (view full) --- 3604 */ 3605static void 3606rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace ) 3607{ 3608 int i; 3609 bt848_ptr_t bt848; 3610 volatile u_long target_buffer, buffer, target,width; 3611 volatile u_long pitch; | 2162 case BT848_I2CWR: 2163 par = *(u_long *)arg; 2164 write = (par >> 24) & 0xff ; 2165 i2c_addr = (par >> 16) & 0xff ; 2166 i2c_port = (par >> 8) & 0xff ; 2167 data = (par) & 0xff ; 2168 2169 if (write) { --- 413 unchanged lines hidden (view full) --- 2583 */ 2584static void 2585rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace ) 2586{ 2587 int i; 2588 bt848_ptr_t bt848; 2589 volatile u_long target_buffer, buffer, target,width; 2590 volatile u_long pitch; |
3612 volatile u_long *dma_prog; /* DMA prog is an array of | 2591 volatile u_long *dma_prog; /* DMA prog is an array of |
3613 32 bit RISC instructions */ 3614 volatile u_long *loop_point; 3615 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; 3616 u_int Bpp = pf_int->public.Bpp; 3617 unsigned int vbisamples; /* VBI samples per line */ 3618 unsigned int vbilines; /* VBI lines per field */ 3619 unsigned int num_dwords; /* DWORDS per line */ 3620 --- 1084 unchanged lines hidden (view full) --- 4705 BT848_DATA_CTL_I2CSDA) 4706 4707/* Select between old i2c code and new iicbus / smbus code */ 4708#if (defined(__FreeBSD__) && (NSMBUS > 0)) 4709 4710/* 4711 * The hardware interface is actually SMB commands 4712 */ | 2592 32 bit RISC instructions */ 2593 volatile u_long *loop_point; 2594 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; 2595 u_int Bpp = pf_int->public.Bpp; 2596 unsigned int vbisamples; /* VBI samples per line */ 2597 unsigned int vbilines; /* VBI lines per field */ 2598 unsigned int num_dwords; /* DWORDS per line */ 2599 --- 1084 unchanged lines hidden (view full) --- 3684 BT848_DATA_CTL_I2CSDA) 3685 3686/* Select between old i2c code and new iicbus / smbus code */ 3687#if (defined(__FreeBSD__) && (NSMBUS > 0)) 3688 3689/* 3690 * The hardware interface is actually SMB commands 3691 */ |
4713static int | 3692int |
4714i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) 4715{ 4716 char cmd; 4717 4718 if (bktr->id == BROOKTREE_848 || 4719 bktr->id == BROOKTREE_848A || 4720 bktr->id == BROOKTREE_849A) 4721 cmd = I2C_COMMAND; --- 9 unchanged lines hidden (view full) --- 4731 (char)(byte1 & 0xff))) 4732 return (-1); 4733 } 4734 4735 /* return OK */ 4736 return( 0 ); 4737} 4738 | 3693i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) 3694{ 3695 char cmd; 3696 3697 if (bktr->id == BROOKTREE_848 || 3698 bktr->id == BROOKTREE_848A || 3699 bktr->id == BROOKTREE_849A) 3700 cmd = I2C_COMMAND; --- 9 unchanged lines hidden (view full) --- 3710 (char)(byte1 & 0xff))) 3711 return (-1); 3712 } 3713 3714 /* return OK */ 3715 return( 0 ); 3716} 3717 |
4739static int | 3718int |
4740i2cRead( bktr_ptr_t bktr, int addr ) 4741{ 4742 char result; 4743 char cmd; 4744 4745 if (bktr->id == BROOKTREE_848 || 4746 bktr->id == BROOKTREE_848A || 4747 bktr->id == BROOKTREE_849A) --- 9 unchanged lines hidden (view full) --- 4757 4758#define IICBUS(bktr) ((bktr)->i2c_sc.iicbus) 4759 4760/* The MSP34xx Audio chip require i2c bus writes of up to 5 bytes which the */ 4761/* bt848 automated i2c bus controller cannot handle */ 4762/* Therefore we need low level control of the i2c bus hardware */ 4763 4764/* Write to the MSP registers */ | 3719i2cRead( bktr_ptr_t bktr, int addr ) 3720{ 3721 char result; 3722 char cmd; 3723 3724 if (bktr->id == BROOKTREE_848 || 3725 bktr->id == BROOKTREE_848A || 3726 bktr->id == BROOKTREE_849A) --- 9 unchanged lines hidden (view full) --- 3736 3737#define IICBUS(bktr) ((bktr)->i2c_sc.iicbus) 3738 3739/* The MSP34xx Audio chip require i2c bus writes of up to 5 bytes which the */ 3740/* bt848 automated i2c bus controller cannot handle */ 3741/* Therefore we need low level control of the i2c bus hardware */ 3742 3743/* Write to the MSP registers */ |
4765static void | 3744void |
4766msp_write(bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data) 4767{ 4768 unsigned char addr_l, addr_h, data_h, data_l ; 4769 4770 addr_h = (addr >>8) & 0xff; 4771 addr_l = addr & 0xff; 4772 data_h = (data >>8) & 0xff; 4773 data_l = data & 0xff; 4774 | 3745msp_write(bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data) 3746{ 3747 unsigned char addr_l, addr_h, data_h, data_l ; 3748 3749 addr_h = (addr >>8) & 0xff; 3750 addr_l = addr & 0xff; 3751 data_h = (data >>8) & 0xff; 3752 data_l = data & 0xff; 3753 |
4775 iicbus_start(IICBUS(bktr), MSP3400C_WADDR, 0 /* no timeout? */); | 3754 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */); |
4776 4777 iicbus_write_byte(IICBUS(bktr), dev, 0); 4778 iicbus_write_byte(IICBUS(bktr), addr_h, 0); 4779 iicbus_write_byte(IICBUS(bktr), addr_l, 0); 4780 iicbus_write_byte(IICBUS(bktr), data_h, 0); 4781 iicbus_write_byte(IICBUS(bktr), data_l, 0); 4782 4783 iicbus_stop(IICBUS(bktr)); 4784 4785 return; 4786} 4787 4788/* Write to the MSP registers */ | 3755 3756 iicbus_write_byte(IICBUS(bktr), dev, 0); 3757 iicbus_write_byte(IICBUS(bktr), addr_h, 0); 3758 iicbus_write_byte(IICBUS(bktr), addr_l, 0); 3759 iicbus_write_byte(IICBUS(bktr), data_h, 0); 3760 iicbus_write_byte(IICBUS(bktr), data_l, 0); 3761 3762 iicbus_stop(IICBUS(bktr)); 3763 3764 return; 3765} 3766 3767/* Write to the MSP registers */ |
4789static unsigned int | 3768unsigned int |
4790msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr) 4791{ 4792 unsigned int data; 4793 unsigned char addr_l, addr_h, dev_r; 4794 int read; 4795 u_char data_read[2]; 4796 4797 addr_h = (addr >>8) & 0xff; 4798 addr_l = addr & 0xff; 4799 dev_r = dev+1; 4800 4801 /* XXX errors ignored */ | 3769msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr) 3770{ 3771 unsigned int data; 3772 unsigned char addr_l, addr_h, dev_r; 3773 int read; 3774 u_char data_read[2]; 3775 3776 addr_h = (addr >>8) & 0xff; 3777 addr_l = addr & 0xff; 3778 dev_r = dev+1; 3779 3780 /* XXX errors ignored */ |
4802 iicbus_start(IICBUS(bktr), MSP3400C_WADDR, 0 /* no timeout? */); | 3781 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */); |
4803 4804 iicbus_write_byte(IICBUS(bktr), dev_r, 0); 4805 iicbus_write_byte(IICBUS(bktr), addr_h, 0); 4806 iicbus_write_byte(IICBUS(bktr), addr_l, 0); 4807 | 3782 3783 iicbus_write_byte(IICBUS(bktr), dev_r, 0); 3784 iicbus_write_byte(IICBUS(bktr), addr_h, 0); 3785 iicbus_write_byte(IICBUS(bktr), addr_l, 0); 3786 |
4808 iicbus_repeated_start(IICBUS(bktr), MSP3400C_RADDR, 0 /* no timeout? */); | 3787 iicbus_repeated_start(IICBUS(bktr), bktr->msp_addr +1, 0 /* no timeout? */); |
4809 iicbus_read(IICBUS(bktr), data_read, 2, &read, IIC_LAST_READ, 0); 4810 iicbus_stop(IICBUS(bktr)); 4811 4812 data = (data_read[0]<<8) | data_read[1]; 4813 4814 return (data); 4815} 4816 4817/* Reset the MSP chip */ 4818/* The user can block the reset (which is handy if you initialise the 4819 * MSP audio in another operating system first (eg in Windows) 4820 */ | 3788 iicbus_read(IICBUS(bktr), data_read, 2, &read, IIC_LAST_READ, 0); 3789 iicbus_stop(IICBUS(bktr)); 3790 3791 data = (data_read[0]<<8) | data_read[1]; 3792 3793 return (data); 3794} 3795 3796/* Reset the MSP chip */ 3797/* The user can block the reset (which is handy if you initialise the 3798 * MSP audio in another operating system first (eg in Windows) 3799 */ |
4821static void | 3800void |
4822msp_reset( bktr_ptr_t bktr ) 4823{ 4824 4825#ifndef BKTR_NO_MSP_RESET 4826 /* put into reset mode */ | 3801msp_reset( bktr_ptr_t bktr ) 3802{ 3803 3804#ifndef BKTR_NO_MSP_RESET 3805 /* put into reset mode */ |
4827 iicbus_start(IICBUS(bktr), MSP3400C_WADDR, 0 /* no timeout? */); | 3806 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */); |
4828 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 4829 iicbus_write_byte(IICBUS(bktr), 0x80, 0); 4830 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 4831 iicbus_stop(IICBUS(bktr)); 4832 4833 /* put back to operational mode */ | 3807 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 3808 iicbus_write_byte(IICBUS(bktr), 0x80, 0); 3809 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 3810 iicbus_stop(IICBUS(bktr)); 3811 3812 /* put back to operational mode */ |
4834 iicbus_start(IICBUS(bktr), MSP3400C_WADDR, 0 /* no timeout? */); | 3813 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */); |
4835 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 4836 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 4837 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 4838 iicbus_stop(IICBUS(bktr)); 4839#endif 4840 return; 4841} 4842 --- 8 unchanged lines hidden (view full) --- 4851 return; 4852} 4853 4854#else /* defined(__FreeBSD__) && (NSMBUS > 0) */ 4855 4856/* 4857 * Program the i2c bus directly 4858 */ | 3814 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 3815 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 3816 iicbus_write_byte(IICBUS(bktr), 0x00, 0); 3817 iicbus_stop(IICBUS(bktr)); 3818#endif 3819 return; 3820} 3821 --- 8 unchanged lines hidden (view full) --- 3830 return; 3831} 3832 3833#else /* defined(__FreeBSD__) && (NSMBUS > 0) */ 3834 3835/* 3836 * Program the i2c bus directly 3837 */ |
4859static int | 3838int |
4860i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) 4861{ 4862 u_long x; 4863 u_long data; 4864 bt848_ptr_t bt848; 4865 4866 bt848 = bktr->base; 4867 --- 29 unchanged lines hidden (view full) --- 4897 /* return OK */ 4898 return( 0 ); 4899} 4900 4901 4902/* 4903 * 4904 */ | 3839i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) 3840{ 3841 u_long x; 3842 u_long data; 3843 bt848_ptr_t bt848; 3844 3845 bt848 = bktr->base; 3846 --- 29 unchanged lines hidden (view full) --- 3876 /* return OK */ 3877 return( 0 ); 3878} 3879 3880 3881/* 3882 * 3883 */ |
4905static int | 3884int |
4906i2cRead( bktr_ptr_t bktr, int addr ) 4907{ 4908 u_long x; 4909 bt848_ptr_t bt848; 4910 4911 bt848 = bktr->base; 4912 4913 /* clear status bits */ --- 122 unchanged lines hidden (view full) --- 5036 } 5037 5038 *data=byte; 5039 return 0; 5040} 5041#undef BITD 5042 5043/* Write to the MSP registers */ | 3885i2cRead( bktr_ptr_t bktr, int addr ) 3886{ 3887 u_long x; 3888 bt848_ptr_t bt848; 3889 3890 bt848 = bktr->base; 3891 3892 /* clear status bits */ --- 122 unchanged lines hidden (view full) --- 4015 } 4016 4017 *data=byte; 4018 return 0; 4019} 4020#undef BITD 4021 4022/* Write to the MSP registers */ |
5044static void msp_write( bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data){ 5045 unsigned int msp_w_addr = MSP3400C_WADDR; | 4023void msp_write( bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data){ 4024 unsigned int msp_w_addr = bktr->msp_addr; |
5046 unsigned char addr_l, addr_h, data_h, data_l ; 5047 addr_h = (addr >>8) & 0xff; 5048 addr_l = addr & 0xff; 5049 data_h = (data >>8) & 0xff; 5050 data_l = data & 0xff; 5051 5052 i2c_start(bktr); 5053 i2c_write_byte(bktr, msp_w_addr); 5054 i2c_write_byte(bktr, dev); 5055 i2c_write_byte(bktr, addr_h); 5056 i2c_write_byte(bktr, addr_l); 5057 i2c_write_byte(bktr, data_h); 5058 i2c_write_byte(bktr, data_l); 5059 i2c_stop(bktr); 5060} 5061 5062/* Write to the MSP registers */ | 4025 unsigned char addr_l, addr_h, data_h, data_l ; 4026 addr_h = (addr >>8) & 0xff; 4027 addr_l = addr & 0xff; 4028 data_h = (data >>8) & 0xff; 4029 data_l = data & 0xff; 4030 4031 i2c_start(bktr); 4032 i2c_write_byte(bktr, msp_w_addr); 4033 i2c_write_byte(bktr, dev); 4034 i2c_write_byte(bktr, addr_h); 4035 i2c_write_byte(bktr, addr_l); 4036 i2c_write_byte(bktr, data_h); 4037 i2c_write_byte(bktr, data_l); 4038 i2c_stop(bktr); 4039} 4040 4041/* Write to the MSP registers */ |
5063static unsigned int msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr){ | 4042unsigned int msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr){ |
5064 unsigned int data; 5065 unsigned char addr_l, addr_h, data_1, data_2, dev_r ; 5066 addr_h = (addr >>8) & 0xff; 5067 addr_l = addr & 0xff; 5068 dev_r = dev+1; 5069 5070 i2c_start(bktr); | 4043 unsigned int data; 4044 unsigned char addr_l, addr_h, data_1, data_2, dev_r ; 4045 addr_h = (addr >>8) & 0xff; 4046 addr_l = addr & 0xff; 4047 dev_r = dev+1; 4048 4049 i2c_start(bktr); |
5071 i2c_write_byte(bktr,MSP3400C_WADDR); | 4050 i2c_write_byte(bktr,bktr->msp_addr); |
5072 i2c_write_byte(bktr,dev_r); 5073 i2c_write_byte(bktr,addr_h); 5074 i2c_write_byte(bktr,addr_l); 5075 5076 i2c_start(bktr); | 4051 i2c_write_byte(bktr,dev_r); 4052 i2c_write_byte(bktr,addr_h); 4053 i2c_write_byte(bktr,addr_l); 4054 4055 i2c_start(bktr); |
5077 i2c_write_byte(bktr,MSP3400C_RADDR); | 4056 i2c_write_byte(bktr,bktr->msp_addr+1); |
5078 i2c_read_byte(bktr,&data_1, 0); 5079 i2c_read_byte(bktr,&data_2, 1); 5080 i2c_stop(bktr); 5081 data = (data_1<<8) | data_2; 5082 return data; 5083} 5084 5085/* Reset the MSP chip */ 5086/* The user can block the reset (which is handy if you initialise the 5087 * MSP audio in another operating system first (eg in Windows) 5088 */ | 4057 i2c_read_byte(bktr,&data_1, 0); 4058 i2c_read_byte(bktr,&data_2, 1); 4059 i2c_stop(bktr); 4060 data = (data_1<<8) | data_2; 4061 return data; 4062} 4063 4064/* Reset the MSP chip */ 4065/* The user can block the reset (which is handy if you initialise the 4066 * MSP audio in another operating system first (eg in Windows) 4067 */ |
5089static void msp_reset( bktr_ptr_t bktr ) { | 4068void msp_reset( bktr_ptr_t bktr ) { |
5090 5091#ifndef BKTR_NO_MSP_RESET 5092 /* put into reset mode */ 5093 i2c_start(bktr); | 4069 4070#ifndef BKTR_NO_MSP_RESET 4071 /* put into reset mode */ 4072 i2c_start(bktr); |
5094 i2c_write_byte(bktr, MSP3400C_WADDR); | 4073 i2c_write_byte(bktr, bktr->msp_addr); |
5095 i2c_write_byte(bktr, 0x00); 5096 i2c_write_byte(bktr, 0x80); 5097 i2c_write_byte(bktr, 0x00); 5098 i2c_stop(bktr); 5099 5100 /* put back to operational mode */ 5101 i2c_start(bktr); | 4074 i2c_write_byte(bktr, 0x00); 4075 i2c_write_byte(bktr, 0x80); 4076 i2c_write_byte(bktr, 0x00); 4077 i2c_stop(bktr); 4078 4079 /* put back to operational mode */ 4080 i2c_start(bktr); |
5102 i2c_write_byte(bktr, MSP3400C_WADDR); | 4081 i2c_write_byte(bktr, bktr->msp_addr); |
5103 i2c_write_byte(bktr, 0x00); 5104 i2c_write_byte(bktr, 0x00); 5105 i2c_write_byte(bktr, 0x00); 5106 i2c_stop(bktr); 5107#endif 5108 return; 5109 5110} --- 81 unchanged lines hidden (view full) --- 5192 return( status ); 5193} 5194#undef EXTRA_START 5195#undef BITD 5196 5197#endif /* I2C_SOFTWARE_PROBE */ 5198 5199 | 4082 i2c_write_byte(bktr, 0x00); 4083 i2c_write_byte(bktr, 0x00); 4084 i2c_write_byte(bktr, 0x00); 4085 i2c_stop(bktr); 4086#endif 4087 return; 4088 4089} --- 81 unchanged lines hidden (view full) --- 4171 return( status ); 4172} 4173#undef EXTRA_START 4174#undef BITD 4175 4176#endif /* I2C_SOFTWARE_PROBE */ 4177 4178 |
5200/* 5201 * 5202 */ 5203static int 5204writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ) 5205{ 5206 return( -1 ); 5207} 5208 5209 5210/* 5211 * 5212 */ 5213static int 5214readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ) 5215{ 5216 int x; 5217 int addr; 5218 int max; 5219 int byte; 5220 5221 /* get the address of the EEProm */ 5222 addr = (int)(bktr->card.eepromAddr & 0xff); 5223 if ( addr == 0 ) 5224 return( -1 ); 5225 5226 max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE); 5227 if ( (offset + count) > max ) 5228 return( -1 ); 5229 5230 /* set the start address */ 5231 if ( i2cWrite( bktr, addr, offset, -1 ) == -1 ) 5232 return( -1 ); 5233 5234 /* the read cycle */ 5235 for ( x = 0; x < count; ++x ) { 5236 if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 ) 5237 return( -1 ); 5238 data[ x ] = byte; 5239 } 5240 5241 return( 0 ); 5242} 5243 | |
5244#define ABSENT (-1) 5245 | 4179#define ABSENT (-1) 4180 |
5246/* 5247 * get a signature of the card 5248 * read all 128 possible i2c read addresses from 0x01 thru 0xff 5249 * build a bit array with a 1 bit for each i2c device that responds 5250 * 5251 * XXX FIXME: use offset & count args 5252 */ 5253static int 5254signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig ) 5255{ 5256 int x; 5257 5258 for ( x = 0; x < 16; ++x ) 5259 sig[ x ] = 0; 5260 5261 for ( x = 0; x < count; ++x ) { 5262 if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) { 5263 sig[ x / 8 ] |= (1 << (x % 8) ); 5264 } 5265 } 5266 5267 return( 0 ); 5268} 5269 5270/* 5271 * any_i2c_devices. 5272 * Some BT848/BT848A cards have no tuner and no additional i2c devices 5273 * eg stereo decoder. These are used for video conferencing or capture from 5274 * a video camera. (VideoLogic Captivator PCI, Intel SmartCapture card). 5275 * 5276 * Determine if there are any i2c devices present. There are none present if 5277 * a) reading from all 128 devices returns ABSENT (-1) for each one 5278 * (eg VideoLogic Captivator PCI with BT848) 5279 * b) reading from all 128 devices returns 0 for each one 5280 * (eg VideoLogic Captivator PCI rev. 2F with BT848A) 5281 */ 5282static int check_for_i2c_devices( bktr_ptr_t bktr ){ 5283 int x, temp_read; 5284 int i2c_all_0 = 1; 5285 int i2c_all_absent = 1; 5286 for ( x = 0; x < 128; ++x ) { 5287 temp_read = i2cRead( bktr, (2 * x) + 1 ); 5288 if (temp_read != 0) i2c_all_0 = 0; 5289 if (temp_read != ABSENT) i2c_all_absent = 0; 5290 } 5291 5292 if ((i2c_all_0) || (i2c_all_absent)) return 0; 5293 else return 1; 5294} 5295 5296/* 5297 * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2, 5298 * 0xc4 or 0xc6, settable by links on the tuner 5299 * Determine the actual address used on the TV card by probing read addresses 5300 */ 5301static int locate_tuner_address( bktr_ptr_t bktr) { 5302 if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0; 5303 if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2; 5304 if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4; 5305 if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6; 5306 return -1; /* no tuner found */ 5307} 5308 5309/* 5310 * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses 5311 * where EEPROMs are usually found. 5312 */ 5313static int locate_eeprom_address( bktr_ptr_t bktr) { 5314 if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0; 5315 if (i2cRead( bktr, 0xac) != ABSENT) return 0xac; 5316 if (i2cRead( bktr, 0xae) != ABSENT) return 0xae; 5317 return -1; /* no eeprom found */ 5318} 5319 5320/* 5321 * determine the card brand/model 5322 * OVERRIDE_CARD, OVERRIDE_TUNER, OVERRIDE_DBX and OVERRIDE_MSP 5323 * can be used to select a specific device, regardless of the 5324 * autodetection and i2c device checks. 5325 * 5326 * The scheme used for probing cards has one major drawback: 5327 * on bt848/849 based cards, it is impossible to work out which type 5328 * of tuner is actually fitted, or if there is extra hardware on board 5329 * connected to GPIO pins (eg radio chips or MSP34xx reset logic) 5330 * The driver cannot tell if the Tuner is PAL,NTSC, Temic or Philips. 5331 * 5332 * All Hauppauge cards have a configuration eeprom which tells us the 5333 * tuner type and other features of the their cards. 5334 * Also, Bt878 based cards (certainly Hauppauge and AverMedia) should support 5335 * sub-system vendor id, identifying the make and model of the card. 5336 * 5337 * The current probe code works as follows 5338 * 1) Check if it is a BT878. If so, read the sub-system vendor id. 5339 * Select the required tuner and other onboard features. 5340 * 2) If it is a BT848, 848A or 849A, continue on: 5341 * 3) Some cards have no I2C devices. Check if the i2c bus is empty 5342 * and if so, our detection job is nearly over. 5343 * 4) Check I2C address 0xa0. If present this will be a Hauppauge card 5344 * or an Osprey card. The Hauppauge EEPROM can determine on board tuner 5345 * type and other features. 5346 * 4) Check I2C address 0xa8. If present this is a STB card. 5347 * Still have to guess on the tuner type. 5348 * 5) Otherwise we are in the dark. Miro cards have the tuner type 5349 * hard-coded on the GPIO pins, but we do not actually know if we have 5350 * a Miro card. 5351 * Some older makes of card put Philips tuners and Temic tuners at 5352 * different I2C addresses, so an i2c bus probe can help, but it is 5353 * really just a guess. 5354 * 5355 * 6) After determining the Tuner Type, we probe the i2c bus for other 5356 * devices at known locations, eg IR-Remote Control, MSP34xx and TDA 5357 * stereo chips. 5358 */ 5359 5360#define VENDOR_AVER_MEDIA 0x1461 5361#define VENDOR_HAUPPAUGE 0x0070 5362#define VENDOR_FLYVIDEO 0x1851 5363#define VENDOR_STB 0x10B4 5364 5365static void 5366probeCard( bktr_ptr_t bktr, int verbose, int unit ) 5367{ 5368 int card, i,j, card_found; 5369 int status; 5370 bt848_ptr_t bt848; 5371 u_char probe_signature[128], *probe_temp; 5372 int any_i2c_devices; 5373 u_char eeprom[256]; 5374 int tuner_i2c_address = -1; 5375 int eeprom_i2c_address = -1; 5376 5377 bt848 = bktr->base; 5378 5379 /* Select all GPIO bits as inputs */ 5380 bt848->gpio_out_en = 0; 5381 if (bootverbose) 5382 printf("bktr: GPIO is 0x%08x\n", bt848->gpio_data); 5383 5384#ifdef HAUPPAUGE_MSP_RESET 5385 /* Reset the MSP34xx audio chip. This resolves bootup card 5386 * detection problems with old Bt848 based Hauppauge cards with 5387 * MSP34xx stereo audio chips. This must be user enabled because 5388 * at this point the probe function does not know the card type. */ 5389 bt848->gpio_out_en = bt848->gpio_out_en | (1<<5); 5390 bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ 5391 DELAY(2500); /* wait 2.5ms */ 5392 bt848->gpio_data = bt848->gpio_data & ~(1<<5); /* write '0' */ 5393 DELAY(2500); /* wait 2.5ms */ 5394 bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ 5395 DELAY(2500); /* wait 2.5ms */ 5396#endif 5397 5398 /* Check for the presence of i2c devices */ 5399 any_i2c_devices = check_for_i2c_devices( bktr ); 5400 5401 5402 /* Check for a user specified override on the card selection */ 5403#if defined( OVERRIDE_CARD ) 5404 bktr->card = cards[ (card = OVERRIDE_CARD) ]; 5405 goto checkEEPROM; 5406#endif 5407 if (bktr->bt848_card != -1 ) { 5408 bktr->card = cards[ (card = bktr->bt848_card) ]; 5409 goto checkEEPROM; 5410 } 5411 5412 5413 /* No override, so try and determine the make of the card */ 5414 5415 /* On BT878/879 cards, read the sub-system vendor id */ 5416 /* This identifies the manufacturer of the card and the model */ 5417 /* In theory this can be read from PCI registers but this does not */ 5418 /* appear to work on the FlyVideo 98. Hauppauge also warned that */ 5419 /* the PCI registers are sometimes not loaded correctly. */ 5420 /* Therefore, I will read the sub-system vendor ID from the EEPROM */ 5421 /* (just like the Bt878 does during power up initialisation) */ 5422 5423 if (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) { 5424 5425 /* Try and locate the EEPROM */ 5426 eeprom_i2c_address = locate_eeprom_address( bktr ); 5427 if (eeprom_i2c_address != -1) { 5428 5429 unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */ 5430 unsigned int subsystem_id; /* board model number */ 5431 unsigned int byte_252, byte_253, byte_254, byte_255; 5432 5433 bktr->card = cards[ (card = CARD_UNKNOWN) ]; 5434 bktr->card.eepromAddr = eeprom_i2c_address; 5435 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5436 5437 readEEProm(bktr, 0, 256, (u_char *) &eeprom ); 5438 byte_252 = (unsigned int)eeprom[252]; 5439 byte_253 = (unsigned int)eeprom[253]; 5440 byte_254 = (unsigned int)eeprom[254]; 5441 byte_255 = (unsigned int)eeprom[255]; 5442 5443 subsystem_id = (byte_252 << 8) | byte_253; 5444 subsystem_vendor_id = (byte_254 << 8) | byte_255; 5445 5446 if ( bootverbose ) 5447 printf("subsytem 0x%04x 0x%04x\n",subsystem_vendor_id, 5448 subsystem_id); 5449 5450 if (subsystem_vendor_id == VENDOR_AVER_MEDIA) { 5451 bktr->card = cards[ (card = CARD_AVER_MEDIA) ]; 5452 bktr->card.eepromAddr = eeprom_i2c_address; 5453 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5454 goto checkTuner; 5455 } 5456 5457 if (subsystem_vendor_id == VENDOR_HAUPPAUGE) { 5458 bktr->card = cards[ (card = CARD_HAUPPAUGE) ]; 5459 bktr->card.eepromAddr = eeprom_i2c_address; 5460 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5461 goto checkTuner; 5462 } 5463 5464 if (subsystem_vendor_id == VENDOR_FLYVIDEO) { 5465 bktr->card = cards[ (card = CARD_FLYVIDEO) ]; 5466 bktr->card.eepromAddr = eeprom_i2c_address; 5467 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5468 goto checkTuner; 5469 } 5470 5471 if (subsystem_vendor_id == VENDOR_STB) { 5472 bktr->card = cards[ (card = CARD_STB) ]; 5473 bktr->card.eepromAddr = eeprom_i2c_address; 5474 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5475 goto checkTuner; 5476 } 5477 5478 /* Vendor is unknown. We will use the standard probe code */ 5479 /* which may not give best results */ 5480 printf("Warning - card vendor 0x%04x (model 0x%04x) unknown. This may cause poor performance\n",subsystem_vendor_id,subsystem_id); 5481 } 5482 else 5483 { 5484 printf("Warning - card has no configuration EEPROM. Cannot determine card make. This may cause poor performance\n"); 5485 } 5486 } /* end of bt878/bt879 card detection code */ 5487 5488 /* If we get to this point, we must have a Bt848/848A/849A card */ 5489 /* or a Bt878/879 with an unknown subsystem vendor id */ 5490 /* Try and determine the make of card by clever i2c probing */ 5491 5492 /* Check for i2c devices. If none, move on */ 5493 if (!any_i2c_devices) { 5494 bktr->card = cards[ (card = CARD_INTEL) ]; 5495 bktr->card.eepromAddr = 0; 5496 bktr->card.eepromSize = 0; 5497 goto checkTuner; 5498 } 5499 5500 5501 /* Look for Hauppauge, STB and Osprey cards by the presence */ 5502 /* of an EEPROM */ 5503 /* Note: Bt878 based cards also use EEPROMs so we can only do this */ 5504 /* test on BT848/848A and 849A based cards. */ 5505 if ((bktr->id==BROOKTREE_848) || 5506 (bktr->id==BROOKTREE_848A) || 5507 (bktr->id==BROOKTREE_849A)) { 5508 5509 /* At i2c address 0xa0, look for Hauppauge and Osprey cards */ 5510 if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) { 5511 5512 /* Read the eeprom contents */ 5513 bktr->card = cards[ (card = CARD_UNKNOWN) ]; 5514 bktr->card.eepromAddr = PFC8582_WADDR; 5515 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5516 readEEProm(bktr, 0, 128, (u_char *) &eeprom ); 5517 5518 /* For Hauppauge, check the EEPROM begins with 0x84 */ 5519 if (eeprom[0] == 0x84) { 5520 bktr->card = cards[ (card = CARD_HAUPPAUGE) ]; 5521 bktr->card.eepromAddr = PFC8582_WADDR; 5522 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5523 goto checkTuner; 5524 } 5525 5526 /* For Osprey, check the EEPROM begins with "MMAC" */ 5527 if ( (eeprom[0] == 'M') &&(eeprom[1] == 'M') 5528 &&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) { 5529 bktr->card = cards[ (card = CARD_OSPREY) ]; 5530 bktr->card.eepromAddr = PFC8582_WADDR; 5531 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5532 goto checkTuner; 5533 } 5534 printf("Warning: Unknown card type. EEPROM data not recognised\n"); 5535 printf("%x %x %x %x\n",eeprom[0],eeprom[1],eeprom[2],eeprom[3]); 5536 } 5537 5538 /* look for an STB card */ 5539 if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) { 5540 bktr->card = cards[ (card = CARD_STB) ]; 5541 bktr->card.eepromAddr = X24C01_WADDR; 5542 bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE); 5543 goto checkTuner; 5544 } 5545 5546 } 5547 5548 signCard( bktr, 1, 128, (u_char *) &probe_signature ); 5549 5550 if (bootverbose) { 5551 printf("card signature \n"); 5552 for (j = 0; j < Bt848_MAX_SIGN; j++) { 5553 printf(" %02x ", probe_signature[j]); 5554 } 5555 printf("\n\n"); 5556 } 5557 for (i = 0; 5558 i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig); 5559 i++ ) { 5560 5561 card_found = 1; 5562 probe_temp = (u_char *) &bt848_card_signature[i].signature; 5563 5564 for (j = 0; j < Bt848_MAX_SIGN; j++) { 5565 if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) { 5566 card_found = 0; 5567 break; 5568 } 5569 5570 } 5571 if (card_found) { 5572 bktr->card = cards[ card = bt848_card_signature[i].card]; 5573 bktr->card.tuner = &tuners[ bt848_card_signature[i].tuner]; 5574 eeprom_i2c_address = locate_eeprom_address( bktr ); 5575 if (eeprom_i2c_address != -1) { 5576 bktr->card.eepromAddr = eeprom_i2c_address; 5577 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5578 } else { 5579 bktr->card.eepromAddr = 0; 5580 bktr->card.eepromSize = 0; 5581 } 5582 goto checkDBX; 5583 } 5584 } 5585 5586 /* We do not know the card type. Default to Miro */ 5587 bktr->card = cards[ (card = CARD_MIRO) ]; 5588 5589 5590checkEEPROM: 5591 /* look for a configuration eeprom */ 5592 eeprom_i2c_address = locate_eeprom_address( bktr ); 5593 if (eeprom_i2c_address != -1) { 5594 bktr->card.eepromAddr = eeprom_i2c_address; 5595 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); 5596 } else { 5597 bktr->card.eepromAddr = 0; 5598 bktr->card.eepromSize = 0; 5599 } 5600 5601 5602checkTuner: 5603 5604 /* look for a tuner */ 5605 tuner_i2c_address = locate_tuner_address( bktr ); 5606 if ( tuner_i2c_address == -1 ) { 5607 bktr->card.tuner = &tuners[ NO_TUNER ]; 5608 goto checkDBX; 5609 } 5610 5611#if defined( OVERRIDE_TUNER ) 5612 bktr->card.tuner = &tuners[ OVERRIDE_TUNER ]; 5613 goto checkDBX; 5614#endif 5615 if (bktr->bt848_tuner != -1 ) { 5616 bktr->card.tuner = &tuners[ bktr->bt848_tuner & 0xff ]; 5617 goto checkDBX; 5618 } 5619 5620 /* Check for i2c devices */ 5621 if (!any_i2c_devices) { 5622 bktr->card.tuner = &tuners[ NO_TUNER ]; 5623 goto checkDBX; 5624 } 5625 5626 /* differentiate type of tuner */ 5627 5628 switch (card) { 5629 case CARD_MIRO: 5630 switch (((bt848->gpio_data >> 10)-1)&7) { 5631 case 0: bktr->card.tuner = &tuners[ TEMIC_PAL ]; break; 5632 case 1: bktr->card.tuner = &tuners[ PHILIPS_PAL ]; break; 5633 case 2: bktr->card.tuner = &tuners[ PHILIPS_NTSC ]; break; 5634 case 3: bktr->card.tuner = &tuners[ PHILIPS_SECAM ]; break; 5635 case 4: bktr->card.tuner = &tuners[ NO_TUNER ]; break; 5636 case 5: bktr->card.tuner = &tuners[ PHILIPS_PALI ]; break; 5637 case 6: bktr->card.tuner = &tuners[ TEMIC_NTSC ]; break; 5638 case 7: bktr->card.tuner = &tuners[ TEMIC_PALI ]; break; 5639 } 5640 goto checkDBX; 5641 break; 5642 5643 case CARD_HAUPPAUGE: 5644 /* Hauppauge kindly supplied the following Tuner Table */ 5645 /* FIXME: I think the tuners the driver selects for types */ 5646 /* 0x08 and 0x15 may be incorrect but no one has complained. */ 5647 /* 5648 ID Tuner Model Format We select Format 5649 0 NONE 5650 1 EXTERNAL 5651 2 OTHER 5652 3 Philips FI1216 BG 5653 4 Philips FI1216MF BGLL' 5654 5 Philips FI1236 MN PHILIPS_NTSC 5655 6 Philips FI1246 I PHILIPS_PALI 5656 7 Philips FI1256 DK 5657 8 Philips FI1216 MK2 BG PHILIPS_PALI 5658 9 Philips FI1216MF MK2 BGLL' 5659 a Philips FI1236 MK2 MN PHILIPS_NTSC 5660 b Philips FI1246 MK2 I PHILIPS_PALI 5661 c Philips FI1256 MK2 DK 5662 d Temic 4032FY5 NTSC TEMIC_NTSC 5663 e Temic 4002FH5 BG TEMIC_PAL 5664 f Temic 4062FY5 I TEMIC_PALI 5665 10 Philips FR1216 MK2 BG 5666 11 Philips FR1216MF MK2 BGLL' 5667 12 Philips FR1236 MK2 MN PHILIPS_FR1236_NTSC 5668 13 Philips FR1246 MK2 I 5669 14 Philips FR1256 MK2 DK 5670 15 Philips FM1216 BG PHILIPS_FR1216_PAL 5671 16 Philips FM1216MF BGLL' 5672 17 Philips FM1236 MN PHILIPS_FR1236_NTSC 5673 18 Philips FM1246 I 5674 19 Philips FM1256 DK 5675 1a Temic 4036FY5 MN - FI1236 MK2 clone 5676 1b Samsung TCPN9082D MN 5677 1c Samsung TCPM9092P Pal BG/I/DK 5678 1d Temic 4006FH5 BG PHILIPS_PALI clone 5679 1e Samsung TCPN9085D MN/Radio 5680 1f Samsung TCPB9085P Pal BG/I/DK / Radio 5681 20 Samsung TCPL9091P Pal BG & Secam L/L' 5682 21 Temic 4039FY5 NTSC Radio 5683 5684 */ 5685 5686 if (bktr->card.eepromAddr != 0) { 5687 u_char tuner_code; 5688 u_int model; 5689 u_int revision; 5690 5691 readEEProm(bktr, 0, 128, (u_char *) &eeprom ); 5692 5693 5694 /* Determine the model number from the eeprom */ 5695 model = (eeprom[12] << 8 | eeprom[11]); 5696 revision = (eeprom[15] << 16 | eeprom[14] << 8 | eeprom[13]); 5697 if (verbose) 5698 printf("bktr%d: Hauppauge Model %d %c%c%c%c\n", 5699 unit, 5700 model, 5701 ((revision >> 18) & 0x3f) + 32, 5702 ((revision >> 12) & 0x3f) + 32, 5703 ((revision >> 6) & 0x3f) + 32, 5704 ((revision >> 0) & 0x3f) + 32 ); 5705 5706 /* Determine the tuner type from the eeprom */ 5707 tuner_code = eeprom[9]; 5708 switch (tuner_code) { 5709 5710 case 0x5: 5711 case 0x0a: 5712 case 0x1a: 5713 bktr->card.tuner = &tuners[ PHILIPS_NTSC ]; 5714 goto checkDBX; 5715 5716 case 0x12: 5717 case 0x17: 5718 bktr->card.tuner = &tuners[ PHILIPS_FR1236_NTSC ]; 5719 goto checkDBX; 5720 5721 case 0x6: 5722 case 0x8: 5723 case 0xb: 5724 case 0x1d: 5725 bktr->card.tuner = &tuners[ PHILIPS_PALI ]; 5726 goto checkDBX; 5727 5728 case 0xd: 5729 bktr->card.tuner = &tuners[ TEMIC_NTSC ]; 5730 goto checkDBX; 5731 5732 case 0xe: 5733 bktr->card.tuner = &tuners[ TEMIC_PAL]; 5734 goto checkDBX; 5735 5736 case 0xf: 5737 bktr->card.tuner = &tuners[ TEMIC_PALI ]; 5738 goto checkDBX; 5739 5740 case 0x15: 5741 bktr->card.tuner = &tuners[ PHILIPS_FR1216_PAL]; 5742 goto checkDBX; 5743 5744 default : 5745 printf("Warning - Unknown Hauppauge Tuner 0x%x\n",tuner_code); 5746 } 5747 } 5748 break; 5749 5750 case CARD_AVER_MEDIA: 5751 /* AVerMedia kindly supplied some details of their EEPROM contents 5752 * which allow us to auto select the Tuner Type. 5753 * Only the newer AVerMedia cards actually have an EEPROM. 5754 */ 5755 if (bktr->card.eepromAddr != 0) { 5756 5757 u_char tuner_make; /* Eg Philips, Temic */ 5758 u_char tuner_tv_fm; /* TV or TV with FM Radio */ 5759 u_char tuner_format; /* Eg NTSC, PAL, SECAM */ 5760 int tuner; 5761 5762 int tuner_0_table[] = { 5763 PHILIPS_NTSC, PHILIPS_PAL, 5764 PHILIPS_PAL, PHILIPS_PAL, 5765 PHILIPS_PAL, PHILIPS_PAL, 5766 PHILIPS_SECAM, PHILIPS_SECAM, 5767 PHILIPS_SECAM, PHILIPS_PAL}; 5768 5769 int tuner_0_fm_table[] = { 5770 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL, 5771 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, 5772 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, 5773 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM, 5774 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL}; 5775 5776 int tuner_1_table[] = { 5777 TEMIC_NTSC, TEMIC_PAL, TEMIC_PAL, 5778 TEMIC_PAL, TEMIC_PAL, TEMIC_PAL, 5779 TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM, 5780 TEMIC_PAL}; 5781 5782 5783 /* Extract information from the EEPROM data */ 5784 readEEProm(bktr, 0, 128, (u_char *) &eeprom ); 5785 tuner_make = (eeprom[0x41] & 0x7); 5786 tuner_tv_fm = (eeprom[0x41] & 0x18) >> 3; 5787 tuner_format = (eeprom[0x42] & 0xf0) >> 4; 5788 5789 /* Treat tuner makes 0 (Philips) and 2 (LG) the same */ 5790 if ( ((tuner_make == 0) || (tuner_make == 2)) 5791 && (tuner_format <= 9) && (tuner_tv_fm == 0) ) { 5792 tuner = tuner_0_table[tuner_format]; 5793 bktr->card.tuner = &tuners[ tuner ]; 5794 goto checkDBX; 5795 } 5796 5797 if ( ((tuner_make == 0) || (tuner_make == 2)) 5798 && (tuner_format <= 9) && (tuner_tv_fm == 1) ) { 5799 tuner = tuner_0_fm_table[tuner_format]; 5800 bktr->card.tuner = &tuners[ tuner ]; 5801 goto checkDBX; 5802 } 5803 5804 if ( (tuner_make == 1) && (tuner_format <= 9) ) { 5805 tuner = tuner_1_table[tuner_format]; 5806 bktr->card.tuner = &tuners[ tuner ]; 5807 goto checkDBX; 5808 } 5809 5810 printf("Warning - Unknown AVerMedia Tuner Make %d Format %d\n", 5811 tuner_make, tuner_format); 5812 } 5813 break; 5814 5815 } /* end switch(card) */ 5816 5817 /* At this point, a goto checkDBX has not occured */ 5818 /* We have not been able to select a Tuner */ 5819 /* Some cards make use of the tuner address to */ 5820 /* identify the make/model of tuner */ 5821 5822 /* At address 0xc0/0xc1 we often find a TEMIC NTSC */ 5823 if ( i2cRead( bktr, 0xc1 ) != ABSENT ) { 5824 bktr->card.tuner = &tuners[ TEMIC_NTSC ]; 5825 goto checkDBX; 5826 } 5827 5828 /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */ 5829 if ( i2cRead( bktr, 0xc7 ) != ABSENT ) { 5830 bktr->card.tuner = &tuners[ PHILIPS_NTSC ]; 5831 goto checkDBX; 5832 } 5833 5834 /* Address 0xc2/0xc3 is default (or common address) for several */ 5835 /* tuners and we cannot tell which is which. */ 5836 /* And for all other tuner i2c addresses, select the default */ 5837 bktr->card.tuner = &tuners[ DEFAULT_TUNER ]; 5838 5839 5840checkDBX: 5841#if defined( OVERRIDE_DBX ) 5842 bktr->card.dbx = OVERRIDE_DBX; 5843 goto checkMSP; 5844#endif 5845 /* Check for i2c devices */ 5846 if (!any_i2c_devices) { 5847 goto checkMSP; 5848 } 5849 5850 /* probe for BTSC (dbx) chip */ 5851 if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT ) 5852 bktr->card.dbx = 1; 5853 5854checkMSP: 5855 /* If this is a Hauppauge Bt878 card, we need to enable the 5856 * MSP 34xx audio chip. 5857 * If this is a Hauppauge Bt848 card, reset the MSP device. 5858 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown 5859 * resistor holds the device in reset until we set GPIO pin 5. 5860 */ 5861 5862 /* Optionally skip the MSP reset. This is handy if you initialise the 5863 * MSP audio in another operating system (eg Windows) first and then 5864 * do a soft reboot. 5865 */ 5866 5867#ifndef BKTR_NO_MSP_RESET 5868 if (card == CARD_HAUPPAUGE) { 5869 bt848->gpio_out_en = bt848->gpio_out_en | (1<<5); 5870 bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ 5871 DELAY(2500); /* wait 2.5ms */ 5872 bt848->gpio_data = bt848->gpio_data & ~(1<<5); /* write '0' */ 5873 DELAY(2500); /* wait 2.5ms */ 5874 bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ 5875 DELAY(2500); /* wait 2.5ms */ 5876 } 5877#endif 5878 5879#if defined( OVERRIDE_MSP ) 5880 bktr->card.msp3400c = OVERRIDE_MSP; 5881 goto checkMSPEnd; 5882#endif 5883 5884 /* Check for i2c devices */ 5885 if (!any_i2c_devices) { 5886 goto checkMSPEnd; 5887 } 5888 5889 if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) 5890 bktr->card.msp3400c = 1; 5891 5892checkMSPEnd: 5893 5894/* Start of Check Remote */ 5895 /* Check for the Hauppauge IR Remote Control */ 5896 /* If there is an external unit, the internal will be ignored */ 5897 5898 bktr->remote_control = 0; /* initial value */ 5899 5900 if (any_i2c_devices) { 5901 if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT ) 5902 { 5903 bktr->remote_control = 1; 5904 bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR; 5905 } 5906 else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT ) 5907 { 5908 bktr->remote_control = 1; 5909 bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR; 5910 } 5911 5912 } 5913 /* If a remote control is found, poll it 5 times to turn off the LED */ 5914 if (bktr->remote_control) { 5915 int i; 5916 for (i=0; i<5; i++) 5917 i2cRead( bktr, bktr->remote_control_addr ); 5918 } 5919/* End of Check Remote */ 5920 5921#if defined( BKTR_USE_PLL ) 5922 bktr->xtal_pll_mode = BT848_USE_PLL; 5923 goto checkPLLEnd; 5924#endif 5925 /* Default is to use XTALS and not PLL mode */ 5926 bktr->xtal_pll_mode = BT848_USE_XTALS; 5927 5928 /* Enable PLL mode for PAL/SECAM users on Hauppauge 878 cards */ 5929 if ((card == CARD_HAUPPAUGE) && 5930 (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) 5931 bktr->xtal_pll_mode = BT848_USE_PLL; 5932 5933 5934 /* Enable PLL mode for OSPREY users */ 5935 if (card == CARD_OSPREY) 5936 bktr->xtal_pll_mode = BT848_USE_PLL; 5937 5938 /* Enable PLL mode for PAL/SECAM users on FlyVideo 878 cards */ 5939 if ((card == CARD_FLYVIDEO) && 5940 (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) 5941 bktr->xtal_pll_mode = BT848_USE_PLL; 5942 5943 /* Enable PLL mode for Video Highway Xtreme users */ 5944 if (card == CARD_VIDEO_HIGHWAY_XTREME) 5945 bktr->xtal_pll_mode = BT848_USE_PLL; 5946 5947#if defined( BKTR_USE_PLL ) 5948checkPLLEnd: 5949#endif 5950 5951 5952 bktr->card.tuner_pllAddr = tuner_i2c_address; 5953 5954 if ( verbose ) { 5955 printf( "%s", bktr->card.name ); 5956 if ( bktr->card.tuner ) 5957 printf( ", %s tuner", bktr->card.tuner->name ); 5958 if ( bktr->card.dbx ) 5959 printf( ", dbx stereo" ); 5960 if ( bktr->card.msp3400c ) 5961 printf( ", msp3400c stereo" ); 5962 if ( bktr->remote_control ) 5963 printf( ", remote control" ); 5964 printf( ".\n" ); 5965 } 5966} 5967#undef ABSENT 5968 5969 5970/****************************************************************************** 5971 * tuner specific routines: 5972 */ 5973 5974 5975/* scaling factor for frequencies expressed as ints */ 5976#define FREQFACTOR 16 5977 5978/* 5979 * Format: 5980 * entry 0: MAX legal channel 5981 * entry 1: IF frequency 5982 * expressed as fi{mHz} * 16, 5983 * eg 45.75mHz == 45.75 * 16 = 732 5984 * entry 2: [place holder/future] 5985 * entry 3: base of channel record 0 5986 * entry 3 + (x*3): base of channel record 'x' 5987 * entry LAST: NULL channel entry marking end of records 5988 * 5989 * Record: 5990 * int 0: base channel 5991 * int 1: frequency of base channel, 5992 * expressed as fb{mHz} * 16, 5993 * int 2: offset frequency between channels, 5994 * expressed as fo{mHz} * 16, 5995 */ 5996 5997/* 5998 * North American Broadcast Channels: 5999 * 6000 * 2: 55.25 mHz - 4: 67.25 mHz 6001 * 5: 77.25 mHz - 6: 83.25 mHz 6002 * 7: 175.25 mHz - 13: 211.25 mHz 6003 * 14: 471.25 mHz - 83: 885.25 mHz 6004 * 6005 * IF freq: 45.75 mHz 6006 */ 6007#define OFFSET 6.00 6008static int nabcst[] = { 6009 83, (int)( 45.75 * FREQFACTOR), 0, 6010 14, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6011 7, (int)(175.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6012 5, (int)( 77.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6013 2, (int)( 55.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6014 0 6015}; 6016#undef OFFSET 6017 6018/* 6019 * North American Cable Channels, IRC: 6020 * 6021 * 2: 55.25 mHz - 4: 67.25 mHz 6022 * 5: 77.25 mHz - 6: 83.25 mHz 6023 * 7: 175.25 mHz - 13: 211.25 mHz 6024 * 14: 121.25 mHz - 22: 169.25 mHz 6025 * 23: 217.25 mHz - 94: 643.25 mHz 6026 * 95: 91.25 mHz - 99: 115.25 mHz 6027 * 6028 * IF freq: 45.75 mHz 6029 */ 6030#define OFFSET 6.00 6031static int irccable[] = { 6032 99, (int)( 45.75 * FREQFACTOR), 0, 6033 95, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6034 23, (int)(217.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6035 14, (int)(121.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6036 7, (int)(175.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6037 5, (int)( 77.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6038 2, (int)( 55.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6039 0 6040}; 6041#undef OFFSET 6042 6043/* 6044 * North American Cable Channels, HRC: 6045 * 6046 * 2: 54 mHz - 4: 66 mHz 6047 * 5: 78 mHz - 6: 84 mHz 6048 * 7: 174 mHz - 13: 210 mHz 6049 * 14: 120 mHz - 22: 168 mHz 6050 * 23: 216 mHz - 94: 642 mHz 6051 * 95: 90 mHz - 99: 114 mHz 6052 * 6053 * IF freq: 45.75 mHz 6054 */ 6055#define OFFSET 6.00 6056static int hrccable[] = { 6057 99, (int)( 45.75 * FREQFACTOR), 0, 6058 95, (int)( 90.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6059 23, (int)(216.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6060 14, (int)(120.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6061 7, (int)(174.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6062 5, (int)( 78.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6063 2, (int)( 54.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6064 0 6065}; 6066#undef OFFSET 6067 6068/* 6069 * Western European broadcast channels: 6070 * 6071 * (there are others that appear to vary between countries - rmt) 6072 * 6073 * here's the table Philips provides: 6074 * caution, some of the offsets don't compute... 6075 * 6076 * 1 4525 700 N21 6077 * 6078 * 2 4825 700 E2 6079 * 3 5525 700 E3 6080 * 4 6225 700 E4 6081 * 6082 * 5 17525 700 E5 6083 * 6 18225 700 E6 6084 * 7 18925 700 E7 6085 * 8 19625 700 E8 6086 * 9 20325 700 E9 6087 * 10 21025 700 E10 6088 * 11 21725 700 E11 6089 * 12 22425 700 E12 6090 * 6091 * 13 5375 700 ITA 6092 * 14 6225 700 ITB 6093 * 6094 * 15 8225 700 ITC 6095 * 6096 * 16 17525 700 ITD 6097 * 17 18325 700 ITE 6098 * 6099 * 18 19225 700 ITF 6100 * 19 20125 700 ITG 6101 * 20 21025 700 ITH 6102 * 6103 * 21 47125 800 E21 6104 * 22 47925 800 E22 6105 * 23 48725 800 E23 6106 * 24 49525 800 E24 6107 * 25 50325 800 E25 6108 * 26 51125 800 E26 6109 * 27 51925 800 E27 6110 * 28 52725 800 E28 6111 * 29 53525 800 E29 6112 * 30 54325 800 E30 6113 * 31 55125 800 E31 6114 * 32 55925 800 E32 6115 * 33 56725 800 E33 6116 * 34 57525 800 E34 6117 * 35 58325 800 E35 6118 * 36 59125 800 E36 6119 * 37 59925 800 E37 6120 * 38 60725 800 E38 6121 * 39 61525 800 E39 6122 * 40 62325 800 E40 6123 * 41 63125 800 E41 6124 * 42 63925 800 E42 6125 * 43 64725 800 E43 6126 * 44 65525 800 E44 6127 * 45 66325 800 E45 6128 * 46 67125 800 E46 6129 * 47 67925 800 E47 6130 * 48 68725 800 E48 6131 * 49 69525 800 E49 6132 * 50 70325 800 E50 6133 * 51 71125 800 E51 6134 * 52 71925 800 E52 6135 * 53 72725 800 E53 6136 * 54 73525 800 E54 6137 * 55 74325 800 E55 6138 * 56 75125 800 E56 6139 * 57 75925 800 E57 6140 * 58 76725 800 E58 6141 * 59 77525 800 E59 6142 * 60 78325 800 E60 6143 * 61 79125 800 E61 6144 * 62 79925 800 E62 6145 * 63 80725 800 E63 6146 * 64 81525 800 E64 6147 * 65 82325 800 E65 6148 * 66 83125 800 E66 6149 * 67 83925 800 E67 6150 * 68 84725 800 E68 6151 * 69 85525 800 E69 6152 * 6153 * 70 4575 800 IA 6154 * 71 5375 800 IB 6155 * 72 6175 800 IC 6156 * 6157 * 74 6925 700 S01 6158 * 75 7625 700 S02 6159 * 76 8325 700 S03 6160 * 6161 * 80 10525 700 S1 6162 * 81 11225 700 S2 6163 * 82 11925 700 S3 6164 * 83 12625 700 S4 6165 * 84 13325 700 S5 6166 * 85 14025 700 S6 6167 * 86 14725 700 S7 6168 * 87 15425 700 S8 6169 * 88 16125 700 S9 6170 * 89 16825 700 S10 6171 * 90 23125 700 S11 6172 * 91 23825 700 S12 6173 * 92 24525 700 S13 6174 * 93 25225 700 S14 6175 * 94 25925 700 S15 6176 * 95 26625 700 S16 6177 * 96 27325 700 S17 6178 * 97 28025 700 S18 6179 * 98 28725 700 S19 6180 * 99 29425 700 S20 6181 * 6182 * 6183 * Channels S21 - S41 are taken from 6184 * http://gemma.apple.com:80/dev/technotes/tn/tn1012.html 6185 * 6186 * 100 30325 800 S21 6187 * 101 31125 800 S22 6188 * 102 31925 800 S23 6189 * 103 32725 800 S24 6190 * 104 33525 800 S25 6191 * 105 34325 800 S26 6192 * 106 35125 800 S27 6193 * 107 35925 800 S28 6194 * 108 36725 800 S29 6195 * 109 37525 800 S30 6196 * 110 38325 800 S31 6197 * 111 39125 800 S32 6198 * 112 39925 800 S33 6199 * 113 40725 800 S34 6200 * 114 41525 800 S35 6201 * 115 42325 800 S36 6202 * 116 43125 800 S37 6203 * 117 43925 800 S38 6204 * 118 44725 800 S39 6205 * 119 45525 800 S40 6206 * 120 46325 800 S41 6207 * 6208 * 121 3890 000 IFFREQ 6209 * 6210 */ 6211static int weurope[] = { 6212 121, (int)( 38.90 * FREQFACTOR), 0, 6213 100, (int)(303.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6214 90, (int)(231.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 6215 80, (int)(105.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 6216 74, (int)( 69.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 6217 21, (int)(471.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6218 17, (int)(183.25 * FREQFACTOR), (int)(9.00 * FREQFACTOR), 6219 16, (int)(175.25 * FREQFACTOR), (int)(9.00 * FREQFACTOR), 6220 15, (int)(82.25 * FREQFACTOR), (int)(8.50 * FREQFACTOR), 6221 13, (int)(53.75 * FREQFACTOR), (int)(8.50 * FREQFACTOR), 6222 5, (int)(175.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 6223 2, (int)(48.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 6224 0 6225}; 6226 6227/* 6228 * Japanese Broadcast Channels: 6229 * 6230 * 1: 91.25MHz - 3: 103.25MHz 6231 * 4: 171.25MHz - 7: 189.25MHz 6232 * 8: 193.25MHz - 12: 217.25MHz (VHF) 6233 * 13: 471.25MHz - 62: 765.25MHz (UHF) 6234 * 6235 * IF freq: 45.75 mHz 6236 * OR 6237 * IF freq: 58.75 mHz 6238 */ 6239#define OFFSET 6.00 6240#define IF_FREQ 45.75 6241static int jpnbcst[] = { 6242 62, (int)(IF_FREQ * FREQFACTOR), 0, 6243 13, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6244 8, (int)(193.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6245 4, (int)(171.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6246 1, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6247 0 6248}; 6249#undef IF_FREQ 6250#undef OFFSET 6251 6252/* 6253 * Japanese Cable Channels: 6254 * 6255 * 1: 91.25MHz - 3: 103.25MHz 6256 * 4: 171.25MHz - 7: 189.25MHz 6257 * 8: 193.25MHz - 12: 217.25MHz 6258 * 13: 109.25MHz - 21: 157.25MHz 6259 * 22: 165.25MHz 6260 * 23: 223.25MHz - 63: 463.25MHz 6261 * 6262 * IF freq: 45.75 mHz 6263 */ 6264#define OFFSET 6.00 6265#define IF_FREQ 45.75 6266static int jpncable[] = { 6267 63, (int)(IF_FREQ * FREQFACTOR), 0, 6268 23, (int)(223.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6269 22, (int)(165.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6270 13, (int)(109.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6271 8, (int)(193.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6272 4, (int)(171.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6273 1, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6274 0 6275}; 6276#undef IF_FREQ 6277#undef OFFSET 6278 6279/* 6280 * xUSSR Broadcast Channels: 6281 * 6282 * 1: 49.75MHz - 2: 59.25MHz 6283 * 3: 77.25MHz - 5: 93.25MHz 6284 * 6: 175.25MHz - 12: 223.25MHz 6285 * 13-20 - not exist 6286 * 21: 471.25MHz - 34: 575.25MHz 6287 * 35: 583.25MHz - 69: 855.25MHz 6288 * 6289 * Cable channels 6290 * 6291 * 70: 111.25MHz - 77: 167.25MHz 6292 * 78: 231.25MHz -107: 463.25MHz 6293 * 6294 * IF freq: 38.90 MHz 6295 */ 6296#define IF_FREQ 38.90 6297static int xussr[] = { 6298 107, (int)(IF_FREQ * FREQFACTOR), 0, 6299 78, (int)(231.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6300 70, (int)(111.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6301 35, (int)(583.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6302 21, (int)(471.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6303 6, (int)(175.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6304 3, (int)( 77.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6305 1, (int)( 49.75 * FREQFACTOR), (int)(9.50 * FREQFACTOR), 6306 0 6307}; 6308#undef IF_FREQ 6309 6310/* 6311 * Australian broadcast channels 6312 */ 6313#define OFFSET 7.00 6314static int australia[] = { 6315 83, (int)( 45.00 * FREQFACTOR), 0, 6316 28, (int)(520.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6317 14, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6318 11, (int)(214.50 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6319 10, (int)(201.50 * FREQFACTOR), (int)( 13.00 * FREQFACTOR), 6320 7, (int)(174.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6321 3, (int)( 85.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6322 2, (int)( 56.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6323 0 6324}; 6325#undef OFFSET 6326 6327static struct { 6328 int *ptr; 6329 char name[BT848_MAX_CHNLSET_NAME_LEN]; 6330} freqTable[] = { 6331 {NULL, ""}, 6332 {nabcst, "nabcst"}, 6333 {irccable, "cableirc"}, 6334 {hrccable, "cablehrc"}, 6335 {weurope, "weurope"}, 6336 {jpnbcst, "jpnbcst"}, 6337 {jpncable, "jpncable"}, 6338 {xussr, "xussr"}, 6339 {australia, "australia"}, 6340 6341}; 6342 6343#define TBL_CHNL freqTable[ bktr->tuner.chnlset ].ptr[ x ] 6344#define TBL_BASE_FREQ freqTable[ bktr->tuner.chnlset ].ptr[ x + 1 ] 6345#define TBL_OFFSET freqTable[ bktr->tuner.chnlset ].ptr[ x + 2 ] 6346static int 6347frequency_lookup( bktr_ptr_t bktr, int channel ) 6348{ 6349 int x; 6350 6351 /* check for "> MAX channel" */ 6352 x = 0; 6353 if ( channel > TBL_CHNL ) 6354 return( -1 ); 6355 6356 /* search the table for data */ 6357 for ( x = 3; TBL_CHNL; x += 3 ) { 6358 if ( channel >= TBL_CHNL ) { 6359 return( TBL_BASE_FREQ + 6360 ((channel - TBL_CHNL) * TBL_OFFSET) ); 6361 } 6362 } 6363 6364 /* not found, must be below the MIN channel */ 6365 return( -1 ); 6366} 6367#undef TBL_OFFSET 6368#undef TBL_BASE_FREQ 6369#undef TBL_CHNL 6370 6371 6372#define TBL_IF freqTable[ bktr->tuner.chnlset ].ptr[ 1 ] 6373/* 6374 * set the frequency of the tuner 6375 */ 6376static int 6377tv_freq( bktr_ptr_t bktr, int frequency ) 6378{ 6379 const struct TUNER* tuner; 6380 u_char addr; 6381 u_char control; 6382 u_char band; 6383 int N; 6384 6385 tuner = bktr->card.tuner; 6386 if ( tuner == NULL ) 6387 return( -1 ); 6388 6389 /* 6390 * select the band based on frequency 6391 * XXX FIXME: get the cross-over points from the tuner struct 6392 */ 6393 if ( frequency < (160 * FREQFACTOR) ) 6394 N = 0; 6395 else if ( frequency < (454 * FREQFACTOR) ) 6396 N = 1; 6397 else 6398 N = 2; 6399 6400 if(frequency > RADIO_OFFSET) { 6401 N=3; 6402 frequency -= RADIO_OFFSET; 6403 } 6404 6405 /* set the address of the PLL */ 6406 addr = bktr->card.tuner_pllAddr; 6407 control = tuner->pllControl[ N ]; 6408 band = tuner->bandAddrs[ N ]; 6409 if(!(band && control)) /* Don't try to set un- */ 6410 return(-1); /* supported modes. */ 6411 6412 if(N==3) 6413 band |= bktr->tuner.radio_mode; 6414 6415 /* 6416 * N = 16 * { fRF(pc) + fIF(pc) } 6417 * where: 6418 * pc is picture carrier, fRF & fIF are in mHz 6419 * 6420 * frequency was passed in as mHz * 16 6421 */ 6422#if defined( TEST_TUNER_AFC ) 6423 if ( bktr->tuner.afc ) 6424 frequency -= 4; 6425#endif 6426 6427 if(bktr->bt848_tuner == ALPS_TSCH5 && N == 3) /* for FM frequency */ 6428 N = frequency; 6429 else 6430 N = frequency + TBL_IF; 6431 6432 if ( frequency > bktr->tuner.frequency ) { 6433 i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); 6434 i2cWrite( bktr, addr, control, band ); 6435 } 6436 else { 6437 i2cWrite( bktr, addr, control, band ); 6438 i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); 6439 } 6440 6441#if defined( TUNER_AFC ) 6442 if ( bktr->tuner.afc == TRUE ) { 6443 if ( (N = do_afc( bktr, addr, N )) < 0 ) { 6444 /* AFC failed, restore requested frequency */ 6445 N = frequency + TBL_IF; 6446 i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); 6447 } 6448 else 6449 frequency = N - TBL_IF; 6450 } 6451#endif /* TUNER_AFC */ 6452 6453 /* update frequency */ 6454 bktr->tuner.frequency = frequency; 6455 6456 return( 0 ); 6457} 6458 6459#if defined( TUNER_AFC ) 6460/* 6461 * 6462 */ 6463static int 6464do_afc( bktr_ptr_t bktr, int addr, int frequency ) 6465{ 6466 int step; 6467 int status; 6468 int origFrequency; 6469 6470 origFrequency = frequency; 6471 6472 /* wait for first setting to take effect */ 6473 tsleep( BKTR_SLEEP, PZERO, "tuning", hz/8 ); 6474 6475 if ( (status = i2cRead( bktr, addr + 1 )) < 0 ) 6476 return( -1 ); 6477 6478#if defined( TEST_TUNER_AFC ) 6479 printf( "\nOriginal freq: %d, status: 0x%02x\n", frequency, status ); 6480#endif 6481 for ( step = 0; step < AFC_MAX_STEP; ++step ) { 6482 if ( (status = i2cRead( bktr, addr + 1 )) < 0 ) 6483 goto fubar; 6484 if ( !(status & 0x40) ) { 6485#if defined( TEST_TUNER_AFC ) 6486 printf( "no lock!\n" ); 6487#endif 6488 goto fubar; 6489 } 6490 6491 switch( status & AFC_BITS ) { 6492 case AFC_FREQ_CENTERED: 6493#if defined( TEST_TUNER_AFC ) 6494 printf( "Centered, freq: %d, status: 0x%02x\n", frequency, status ); 6495#endif 6496 return( frequency ); 6497 6498 case AFC_FREQ_MINUS_125: 6499 case AFC_FREQ_MINUS_62: 6500#if defined( TEST_TUNER_AFC ) 6501 printf( "Low, freq: %d, status: 0x%02x\n", frequency, status ); 6502#endif 6503 --frequency; 6504 break; 6505 6506 case AFC_FREQ_PLUS_62: 6507 case AFC_FREQ_PLUS_125: 6508#if defined( TEST_TUNER_AFC ) 6509 printf( "Hi, freq: %d, status: 0x%02x\n", frequency, status ); 6510#endif 6511 ++frequency; 6512 break; 6513 } 6514 6515 i2cWrite( bktr, addr, 6516 (frequency>>8) & 0x7f, frequency & 0xff ); 6517 DELAY( AFC_DELAY ); 6518 } 6519 6520 fubar: 6521 i2cWrite( bktr, addr, 6522 (origFrequency>>8) & 0x7f, origFrequency & 0xff ); 6523 6524 return( -1 ); 6525} 6526#endif /* TUNER_AFC */ 6527#undef TBL_IF 6528 6529 6530/* 6531 * set the channel of the tuner 6532 */ 6533static int 6534tv_channel( bktr_ptr_t bktr, int channel ) 6535{ 6536 int frequency; 6537 6538 /* calculate the frequency according to tuner type */ 6539 if ( (frequency = frequency_lookup( bktr, channel )) < 0 ) 6540 return( -1 ); 6541 6542 /* set the new frequency */ 6543 if ( tv_freq( bktr, frequency ) < 0 ) 6544 return( -1 ); 6545 6546 /* OK to update records */ 6547 return( (bktr->tuner.channel = channel) ); 6548} 6549 6550/* 6551 * get channelset name 6552 */ 6553static int 6554tuner_getchnlset(struct bktr_chnlset *chnlset) 6555{ 6556 if (( chnlset->index < CHNLSET_MIN ) || 6557 ( chnlset->index > CHNLSET_MAX )) 6558 return( EINVAL ); 6559 6560 memcpy(&chnlset->name, &freqTable[chnlset->index].name, 6561 BT848_MAX_CHNLSET_NAME_LEN); 6562 6563 chnlset->max_channel=freqTable[chnlset->index].ptr[0]; 6564 return( 0 ); 6565} 6566/****************************************************************************** 6567 * audio specific routines: 6568 */ 6569 6570 6571/* 6572 * 6573 */ 6574#define AUDIOMUX_DISCOVER_NOT 6575static int 6576set_audio( bktr_ptr_t bktr, int cmd ) 6577{ 6578 bt848_ptr_t bt848; 6579 u_long temp; 6580 volatile u_char idx; 6581 6582#if defined( AUDIOMUX_DISCOVER ) 6583 if ( cmd >= 200 ) 6584 cmd -= 200; 6585 else 6586#endif /* AUDIOMUX_DISCOVER */ 6587 6588 /* check for existance of audio MUXes */ 6589 if ( !bktr->card.audiomuxs[ 4 ] ) 6590 return( -1 ); 6591 6592 switch (cmd) { 6593 case AUDIO_TUNER: 6594#ifdef BKTR_REVERSEMUTE 6595 bktr->audio_mux_select = 3; 6596#else 6597 bktr->audio_mux_select = 0; 6598#endif 6599 6600 if (bktr->reverse_mute ) 6601 bktr->audio_mux_select = 0; 6602 else 6603 bktr->audio_mux_select = 3; 6604 6605 break; 6606 case AUDIO_EXTERN: 6607 bktr->audio_mux_select = 1; 6608 break; 6609 case AUDIO_INTERN: 6610 bktr->audio_mux_select = 2; 6611 break; 6612 case AUDIO_MUTE: 6613 bktr->audio_mute_state = TRUE; /* set mute */ 6614 break; 6615 case AUDIO_UNMUTE: 6616 bktr->audio_mute_state = FALSE; /* clear mute */ 6617 break; 6618 default: 6619 printf("bktr: audio cmd error %02x\n", cmd); 6620 return( -1 ); 6621 } 6622 6623 6624 /* Most cards have a simple audio multiplexer to select the 6625 * audio source. The I/O_GV card has a more advanced multiplexer 6626 * and requires special handling. 6627 */ 6628 if ( bktr->bt848_card == CARD_IO_GV ) { 6629 set_bctv_audio( bktr ); 6630 return( 0 ); 6631 } 6632 6633 /* Proceed with the simpler audio multiplexer code for the majority 6634 * of Bt848 cards. 6635 */ 6636 6637 bt848 = bktr->base; 6638 6639 /* 6640 * Leave the upper bits of the GPIO port alone in case they control 6641 * something like the dbx or teletext chips. This doesn't guarantee 6642 * success, but follows the rule of least astonishment. 6643 */ 6644 6645 if ( bktr->audio_mute_state == TRUE ) { 6646#ifdef BKTR_REVERSEMUTE 6647 idx = 0; 6648#else 6649 idx = 3; 6650#endif 6651 6652 if (bktr->reverse_mute ) 6653 idx = 3; 6654 else 6655 idx = 0; 6656 6657 } 6658 else 6659 idx = bktr->audio_mux_select; 6660 6661 temp = bt848->gpio_data & ~bktr->card.gpio_mux_bits; 6662 bt848->gpio_data = 6663#if defined( AUDIOMUX_DISCOVER ) 6664 bt848->gpio_data = temp | (cmd & 0xff); 6665 printf("cmd: %d audio mux %x temp %x \n", cmd,bktr->card.audiomuxs[ idx ], temp ); 6666#else 6667 temp | bktr->card.audiomuxs[ idx ]; 6668#endif /* AUDIOMUX_DISCOVER */ 6669 6670 return( 0 ); 6671} 6672 6673 6674/* 6675 * 6676 */ 6677static void 6678temp_mute( bktr_ptr_t bktr, int flag ) 6679{ 6680 static int muteState = FALSE; 6681 6682 if ( flag == TRUE ) { 6683 muteState = bktr->audio_mute_state; 6684 set_audio( bktr, AUDIO_MUTE ); /* prevent 'click' */ 6685 } 6686 else { 6687 tsleep( BKTR_SLEEP, PZERO, "tuning", hz/8 ); 6688 if ( muteState == FALSE ) 6689 set_audio( bktr, AUDIO_UNMUTE ); 6690 } 6691} 6692 6693 6694/* 6695 * initialise the dbx chip 6696 * taken from the Linux bttv driver TDA9850 initialisation code 6697 */ 6698static void 6699init_BTSC( bktr_ptr_t bktr ) 6700{ 6701 i2cWrite(bktr, TDA9850_WADDR, CON1ADDR, 0x08); /* noise threshold st */ 6702 i2cWrite(bktr, TDA9850_WADDR, CON2ADDR, 0x08); /* noise threshold sap */ 6703 i2cWrite(bktr, TDA9850_WADDR, CON3ADDR, 0x40); /* stereo mode */ 6704 i2cWrite(bktr, TDA9850_WADDR, CON4ADDR, 0x07); /* 0 dB input gain? */ 6705 i2cWrite(bktr, TDA9850_WADDR, ALI1ADDR, 0x10); /* wideband alignment? */ 6706 i2cWrite(bktr, TDA9850_WADDR, ALI2ADDR, 0x10); /* spectral alignment? */ 6707 i2cWrite(bktr, TDA9850_WADDR, ALI3ADDR, 0x03); 6708} 6709 6710/* 6711 * setup the dbx chip 6712 * XXX FIXME: alot of work to be done here, this merely unmutes it. 6713 */ 6714static int 6715set_BTSC( bktr_ptr_t bktr, int control ) 6716{ 6717 return( i2cWrite( bktr, TDA9850_WADDR, CON3ADDR, control ) ); 6718} 6719 6720/* 6721 * CARD_GV_BCTV specific functions. 6722 */ 6723 6724#define BCTV_AUDIO_MAIN 0x10 /* main audio program */ 6725#define BCTV_AUDIO_SUB 0x20 /* sub audio program */ 6726#define BCTV_AUDIO_BOTH 0x30 /* main(L) + sub(R) program */ 6727 6728#define BCTV_GPIO_REG0 1 6729#define BCTV_GPIO_REG1 3 6730 6731#define BCTV_GR0_AUDIO_MODE 3 6732#define BCTV_GR0_AUDIO_MAIN 0 /* main program */ 6733#define BCTV_GR0_AUDIO_SUB 3 /* sub program */ 6734#define BCTV_GR0_AUDIO_BOTH 1 /* main(L) + sub(R) */ 6735#define BCTV_GR0_AUDIO_MUTE 4 /* audio mute */ 6736#define BCTV_GR0_AUDIO_MONO 8 /* force mono */ 6737 6738static void 6739set_bctv_audio( bktr_ptr_t bktr ) 6740{ 6741 int data; 6742 6743 switch (bktr->audio_mux_select) { 6744 case 1: /* external */ 6745 case 2: /* internal */ 6746 bctv_gpio_write(bktr, BCTV_GPIO_REG1, 0); 6747 break; 6748 default: /* tuner */ 6749 bctv_gpio_write(bktr, BCTV_GPIO_REG1, 1); 6750 break; 6751 } 6752/* switch (bktr->audio_sap_select) { */ 6753 switch (BCTV_AUDIO_BOTH) { 6754 case BCTV_AUDIO_SUB: 6755 data = BCTV_GR0_AUDIO_SUB; 6756 break; 6757 case BCTV_AUDIO_BOTH: 6758 data = BCTV_GR0_AUDIO_BOTH; 6759 break; 6760 case BCTV_AUDIO_MAIN: 6761 default: 6762 data = BCTV_GR0_AUDIO_MAIN; 6763 break; 6764 } 6765 if (bktr->audio_mute_state == TRUE) 6766 data |= BCTV_GR0_AUDIO_MUTE; 6767 6768 bctv_gpio_write(bktr, BCTV_GPIO_REG0, data); 6769 6770 return; 6771} 6772 6773/* gpio_data bit assignment */ 6774#define BCTV_GPIO_ADDR_MASK 0x000300 6775#define BCTV_GPIO_WE 0x000400 6776#define BCTV_GPIO_OE 0x000800 6777#define BCTV_GPIO_VAL_MASK 0x00f000 6778 6779#define BCTV_GPIO_PORT_MASK 3 6780#define BCTV_GPIO_ADDR_SHIFT 8 6781#define BCTV_GPIO_VAL_SHIFT 12 6782 6783/* gpio_out_en value for read/write */ 6784#define BCTV_GPIO_OUT_RMASK 0x000f00 6785#define BCTV_GPIO_OUT_WMASK 0x00ff00 6786 6787#define BCTV_BITS 100 6788 6789static void 6790bctv_gpio_write( bktr_ptr_t bktr, int port, int val ) 6791{ 6792 bt848_ptr_t bt848 = bktr->base; 6793 u_long data, outbits; 6794 6795 port &= BCTV_GPIO_PORT_MASK; 6796 switch (port) { 6797 case 1: 6798 case 3: 6799 data = ((val << BCTV_GPIO_VAL_SHIFT) & BCTV_GPIO_VAL_MASK) | 6800 ((port << BCTV_GPIO_ADDR_SHIFT) & BCTV_GPIO_ADDR_MASK) | 6801 BCTV_GPIO_WE | BCTV_GPIO_OE; 6802 outbits = BCTV_GPIO_OUT_WMASK; 6803 break; 6804 default: 6805 return; 6806 } 6807 bt848->gpio_out_en = 0; 6808 bt848->gpio_data = data; 6809 bt848->gpio_out_en = outbits; 6810 DELAY(BCTV_BITS); 6811 bt848->gpio_data = data & ~BCTV_GPIO_WE; 6812 DELAY(BCTV_BITS); 6813 bt848->gpio_data = data; 6814 DELAY(BCTV_BITS); 6815 bt848->gpio_data = ~0; 6816 bt848->gpio_out_en = 0; 6817} 6818 6819/* Not yet used 6820static int 6821bctv_gpio_read( bktr_ptr_t bktr, int port ) 6822{ 6823 bt848_ptr_t bt848 = bktr->base; 6824 u_long data, outbits, ret; 6825 6826 port &= BCTV_GPIO_PORT_MASK; 6827 switch (port) { 6828 case 1: 6829 case 3: 6830 data = ((port << BCTV_GPIO_ADDR_SHIFT) & BCTV_GPIO_ADDR_MASK) | 6831 BCTV_GPIO_WE | BCTV_GPIO_OE; 6832 outbits = BCTV_GPIO_OUT_RMASK; 6833 break; 6834 default: 6835 return( -1 ); 6836 } 6837 bt848->gpio_out_en = 0; 6838 bt848->gpio_data = data; 6839 bt848->gpio_out_en = outbits; 6840 DELAY(BCTV_BITS); 6841 bt848->gpio_data = data & ~BCTV_GPIO_OE; 6842 DELAY(BCTV_BITS); 6843 ret = bt848->gpio_data; 6844 DELAY(BCTV_BITS); 6845 bt848->gpio_data = data; 6846 DELAY(BCTV_BITS); 6847 bt848->gpio_data = ~0; 6848 bt848->gpio_out_en = 0; 6849 return( (ret & BCTV_GPIO_VAL_MASK) >> BCTV_GPIO_VAL_SHIFT ); 6850} 6851*/ 6852 6853/* 6854 * setup the MSP34xx Stereo Audio Chip 6855 * This uses the Auto Configuration Option on MSP3410D and MSP3415D chips 6856 * and DBX mode selection for MSP3430G chips. 6857 * For MSP3400C support, the full programming sequence is required and is 6858 * not yet supported. 6859 */ 6860 6861/* Read the MSP version string */ 6862static void msp_read_id( bktr_ptr_t bktr, int unit ){ 6863 int rev1=0, rev2=0; 6864 rev1 = msp_read(bktr, 0x12, 0x001e); 6865 rev2 = msp_read(bktr, 0x12, 0x001f); 6866 6867 sprintf(bktr->msp_version_string, "34%02d%c-%c%d", 6868 (rev2>>8)&0xff, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f); 6869 6870 printf("bktr%d: Detected a MSP%s\n",unit,bktr->msp_version_string); 6871} 6872 6873 6874/* Configure the MSP chip to Auto-detect the audio format */ 6875static void msp_autodetect( bktr_ptr_t bktr ) { 6876 6877 if (strncmp("3430G", bktr->msp_version_string, 5) == 0){ 6878 6879 /* For MSP3430G - countries with mono and DBX stereo */ 6880 msp_write(bktr, 0x10, 0x0030,0x2003);/* Enable Auto format detection */ 6881 msp_write(bktr, 0x10, 0x0020,0x0020);/* Standard Select Reg. = BTSC-Stereo*/ 6882 msp_write(bktr, 0x12, 0x000E,0x2403);/* darned if I know */ 6883 msp_write(bktr, 0x12, 0x0008,0x0320);/* Source select = (St or A) */ 6884 /* & Ch. Matrix = St */ 6885 msp_write(bktr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ 6886 6887 } else { 6888 6889 /* For MSP3410 / 3415 - countries with mono, FM stereo and NICAM */ 6890 msp_write(bktr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ 6891 msp_write(bktr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */ 6892 msp_write(bktr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */ 6893 } 6894 6895 /* uncomment the following line to enable the MSP34xx 1Khz Tone Generator */ 6896 /* turn your speaker volume down low before trying this */ 6897 /* msp_write(bktr, 0x12, 0x0014, 0x7f40); */ 6898} 6899 6900 6901 6902/* 6903 * 6904 * Operating System Dependant Parts 6905 * This section contains OS Dependant code like 6906 * probe and attach and the cdev open/close/read/mmap interface 6907 * 6908 */ 6909 6910/****************************/ 6911/* *** FreeBSD 4.x code *** */ 6912/****************************/ 6913#if (__FreeBSD_version >= 400000) 6914 6915static int bktr_probe( device_t dev ); 6916static int bktr_attach( device_t dev ); 6917static int bktr_detach( device_t dev ); 6918static int bktr_shutdown( device_t dev ); 6919static void bktr_intr(void *arg) { common_bktr_intr(arg); } 6920 6921static device_method_t bktr_methods[] = { 6922 /* Device interface */ 6923 DEVMETHOD(device_probe, bktr_probe), 6924 DEVMETHOD(device_attach, bktr_attach), 6925 DEVMETHOD(device_detach, bktr_detach), 6926 DEVMETHOD(device_shutdown, bktr_shutdown), 6927 6928 { 0, 0 } 6929}; 6930 6931static driver_t bktr_driver = { 6932 "bktr", 6933 bktr_methods, 6934 sizeof(struct bktr_softc), 6935}; 6936 6937static devclass_t bktr_devclass; 6938 6939static d_open_t bktr_open; 6940static d_close_t bktr_close; 6941static d_read_t bktr_read; 6942static d_write_t bktr_write; 6943static d_ioctl_t bktr_ioctl; 6944static d_mmap_t bktr_mmap; 6945static d_poll_t bktr_poll; 6946 6947#define CDEV_MAJOR 92 6948static struct cdevsw bktr_cdevsw = { 6949 /* open */ bktr_open, 6950 /* close */ bktr_close, 6951 /* read */ bktr_read, 6952 /* write */ bktr_write, 6953 /* ioctl */ bktr_ioctl, 6954 /* poll */ bktr_poll, 6955 /* mmap */ bktr_mmap, 6956 /* strategy */ nostrategy, 6957 /* name */ "bktr", 6958 /* maj */ CDEV_MAJOR, 6959 /* dump */ nodump, 6960 /* psize */ nopsize, 6961 /* flags */ 0, 6962 /* bmaj */ -1 6963}; 6964 6965DEV_DRIVER_MODULE(bktr, pci, bktr_driver, bktr_devclass, bktr_cdevsw, 0, 0); 6966 6967 6968/* 6969 * the boot time probe routine. 6970 */ 6971static int 6972bktr_probe( device_t dev ) 6973{ 6974 unsigned int type = pci_get_devid(dev); 6975 unsigned int rev = pci_get_revid(dev); 6976 static int once; 6977 6978 if (!once++) 6979 cdevsw_add(&bktr_cdevsw); 6980 6981 switch (type) { 6982 case BROOKTREE_848_PCI_ID: 6983 if (rev == 0x12) device_set_desc(dev, "BrookTree 848A"); 6984 else device_set_desc(dev, "BrookTree 848"); 6985 return 0; 6986 case BROOKTREE_849_PCI_ID: 6987 device_set_desc(dev, "BrookTree 849A"); 6988 return 0; 6989 case BROOKTREE_878_PCI_ID: 6990 device_set_desc(dev, "BrookTree 878"); 6991 return 0; 6992 case BROOKTREE_879_PCI_ID: 6993 device_set_desc(dev, "BrookTree 879"); 6994 return 0; 6995 }; 6996 6997 return ENXIO; 6998} 6999 7000 7001/* 7002 * the attach routine. 7003 */ 7004static int 7005bktr_attach( device_t dev ) 7006{ 7007 bt848_ptr_t bt848; 7008 u_long latency; 7009 u_long fun; 7010 u_long val; 7011 unsigned int rev; 7012 unsigned int unit; 7013 int error = 0; 7014 int rid; 7015#ifdef BROOKTREE_IRQ 7016 u_long old_irq, new_irq; 7017#endif 7018 7019 struct bktr_softc *bktr = device_get_softc(dev); 7020 7021 unit = device_get_unit(dev); 7022 7023 /* 7024 * Enable bus mastering and Memory Mapped device 7025 */ 7026 val = pci_read_config(dev, PCIR_COMMAND, 4); 7027 val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN); 7028 pci_write_config(dev, PCIR_COMMAND, val, 4); 7029 7030 /* 7031 * Map control/status registers. 7032 */ 7033 rid = PCI_MAP_REG_START; 7034 bktr->res_mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 7035 0, ~0, 1, RF_ACTIVE); 7036 7037 if (!bktr->res_mem) { 7038 device_printf(dev, "could not map memory\n"); 7039 error = ENXIO; 7040 goto fail; 7041 } 7042 bktr->base = rman_get_virtual(bktr->res_mem); /* XXX use bus_space */ 7043 7044 /* 7045 * Disable the brooktree device 7046 */ 7047 bt848 = bktr->base; 7048 bt848->int_mask = ALL_INTS_DISABLED; 7049 bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; 7050 7051 7052#ifdef BROOKTREE_IRQ /* from the configuration file */ 7053 old_irq = pci_conf_read(tag, PCI_INTERRUPT_REG); 7054 pci_conf_write(tag, PCI_INTERRUPT_REG, BROOKTREE_IRQ); 7055 new_irq = pci_conf_read(tag, PCI_INTERRUPT_REG); 7056 printf("bktr%d: attach: irq changed from %d to %d\n", 7057 unit, (old_irq & 0xff), (new_irq & 0xff)); 7058#endif 7059 7060 /* 7061 * Allocate our interrupt. 7062 */ 7063 rid = 0; 7064 bktr->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 7065 RF_SHAREABLE | RF_ACTIVE); 7066 if (bktr->res_irq == NULL) { 7067 device_printf(dev, "could not map interrupt\n"); 7068 error = ENXIO; 7069 goto fail; 7070 } 7071 7072 error = bus_setup_intr(dev, bktr->res_irq, INTR_TYPE_NET, 7073 bktr_intr, bktr, &bktr->res_ih); 7074 if (error) { 7075 device_printf(dev, "could not setup irq\n"); 7076 goto fail; 7077 7078 } 7079 7080 7081 /* Update the Device Control Register */ 7082 /* on Bt878 and Bt879 cards */ 7083 fun = pci_read_config( dev, 0x40, 2); 7084 fun = fun | 1; /* Enable writes to the sub-system vendor ID */ 7085 7086#if defined( BKTR_430_FX_MODE ) 7087 if (bootverbose) printf("Using 430 FX chipset compatibilty mode\n"); 7088 fun = fun | 2; /* Enable Intel 430 FX compatibility mode */ 7089#endif 7090 7091#if defined( BKTR_SIS_VIA_MODE ) 7092 if (bootverbose) printf("Using SiS/VIA chipset compatibilty mode\n"); 7093 fun = fun | 4; /* Enable SiS/VIA compatibility mode (usefull for 7094 OPTi chipset motherboards too */ 7095#endif 7096 pci_write_config(dev, 0x40, fun, 2); 7097 7098 7099 /* XXX call bt848_i2c dependent attach() routine */ 7100#if (NSMBUS > 0) 7101 if (bt848_i2c_attach(unit, bktr->base, &bktr->i2c_sc)) 7102 printf("bktr%d: i2c_attach: can't attach\n", unit); 7103#endif 7104 7105 7106/* 7107 * PCI latency timer. 32 is a good value for 4 bus mastering slots, if 7108 * you have more than four, then 16 would probably be a better value. 7109 */ 7110#ifndef BROOKTREE_DEF_LATENCY_VALUE 7111#define BROOKTREE_DEF_LATENCY_VALUE 10 7112#endif 7113 latency = pci_read_config(dev, PCI_LATENCY_TIMER, 4); 7114 latency = (latency >> 8) & 0xff; 7115 if ( bootverbose ) { 7116 if (latency) 7117 printf("brooktree%d: PCI bus latency is", unit); 7118 else 7119 printf("brooktree%d: PCI bus latency was 0 changing to", 7120 unit); 7121 } 7122 if ( !latency ) { 7123 latency = BROOKTREE_DEF_LATENCY_VALUE; 7124 pci_write_config(dev, PCI_LATENCY_TIMER, latency<<8, 4); 7125 } 7126 if ( bootverbose ) { 7127 printf(" %d.\n", (int) latency); 7128 } 7129 7130 /* read the pci device id and revision id */ 7131 fun = pci_get_devid(dev); 7132 rev = pci_get_revid(dev); 7133 7134 /* call the common attach code */ 7135 common_bktr_attach( bktr, unit, fun, rev ); 7136 7137 make_dev(&bktr_cdevsw, unit, 0, 0, 0444, "bktr%d", unit); 7138 make_dev(&bktr_cdevsw, unit+16, 0, 0, 0444, "tuner%d", unit); 7139 make_dev(&bktr_cdevsw, unit+32, 0, 0, 0444, "vbi%d", unit); 7140 7141 return 0; 7142 7143fail: 7144 return error; 7145 7146} 7147 7148/* 7149 * the detach routine. 7150 */ 7151static int 7152bktr_detach( device_t dev ) 7153{ 7154 struct bktr_softc *bktr = device_get_softc(dev); 7155 bt848_ptr_t bt848; 7156 7157 /* Disable the brooktree device */ 7158 bt848 = bktr->base; 7159 bt848->int_mask = ALL_INTS_DISABLED; 7160 bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; 7161 7162 /* FIXME - Free memory for RISC programs, grab buffer, vbi buffers */ 7163 7164 /* 7165 * Deallocate resources. 7166 */ 7167 bus_teardown_intr(dev, bktr->res_irq, bktr->res_ih); 7168 bus_release_resource(dev, SYS_RES_IRQ, 0, bktr->res_irq); 7169 bus_release_resource(dev, SYS_RES_MEMORY, PCI_MAP_REG_START, bktr->res_mem); 7170 7171 return 0; 7172} 7173 7174/* 7175 * the shutdown routine. 7176 */ 7177static int 7178bktr_shutdown( device_t dev ) 7179{ 7180 struct bktr_softc *bktr = device_get_softc(dev); 7181 bt848_ptr_t bt848; 7182 7183 /* Disable the brooktree device */ 7184 bt848 = bktr->base; 7185 bt848->int_mask = ALL_INTS_DISABLED; 7186 bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; 7187 7188 return 0; 7189} 7190 7191 7192/* 7193 * Special Memory Allocation 7194 */ 7195static vm_offset_t 7196get_bktr_mem( int unit, unsigned size ) 7197{ 7198 vm_offset_t addr = 0; 7199 7200 addr = vm_page_alloc_contig(size, 0, 0xffffffff, 1<<24); 7201 if (addr == 0) 7202 addr = vm_page_alloc_contig(size, 0, 0xffffffff, PAGE_SIZE); 7203 if (addr == 0) { 7204 printf("bktr%d: Unable to allocate %d bytes of memory.\n", 7205 unit, size); 7206 } 7207 7208 return( addr ); 7209} 7210 7211 7212/*--------------------------------------------------------- 7213** 7214** BrookTree 848 character device driver routines 7215** 7216**--------------------------------------------------------- 7217*/ 7218 7219#define VIDEO_DEV 0x00 7220#define TUNER_DEV 0x01 7221#define VBI_DEV 0x02 7222 7223#define UNIT(x) ((x) & 0x0f) 7224#define FUNCTION(x) (x >> 4) 7225 7226/* 7227 * 7228 */ 7229int 7230bktr_open( dev_t dev, int flags, int fmt, struct proc *p ) 7231{ 7232 bktr_ptr_t bktr; 7233 int unit; 7234 int result; 7235 7236 unit = UNIT( minor(dev) ); 7237 7238 /* Get the device data */ 7239 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7240 if (bktr == NULL) { 7241 /* the device is no longer valid/functioning */ 7242 return (ENXIO); 7243 } 7244 7245 if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */ 7246 return( ENXIO ); 7247 7248 /* Record that the device is now busy */ 7249 device_busy(devclass_get_device(bktr_devclass, unit)); 7250 7251 7252 if (bt848_card != -1) { 7253 if ((bt848_card >> 8 == unit ) && 7254 ( (bt848_card & 0xff) < Bt848_MAX_CARD )) { 7255 if ( bktr->bt848_card != (bt848_card & 0xff) ) { 7256 bktr->bt848_card = (bt848_card & 0xff); 7257 probeCard(bktr, FALSE, unit); 7258 } 7259 } 7260 } 7261 7262 if (bt848_tuner != -1) { 7263 if ((bt848_tuner >> 8 == unit ) && 7264 ( (bt848_tuner & 0xff) < Bt848_MAX_TUNER )) { 7265 if ( bktr->bt848_tuner != (bt848_tuner & 0xff) ) { 7266 bktr->bt848_tuner = (bt848_tuner & 0xff); 7267 probeCard(bktr, FALSE, unit); 7268 } 7269 } 7270 } 7271 7272 if (bt848_reverse_mute != -1) { 7273 if (((bt848_reverse_mute >> 8) == unit ) && 7274 ((bt848_reverse_mute & 0xff) < Bt848_MAX_TUNER) ) { 7275 bktr->reverse_mute = bt848_reverse_mute & 0xff; 7276 bt848_reverse_mute = -1; 7277 } 7278 } 7279 7280 switch ( FUNCTION( minor(dev) ) ) { 7281 case VIDEO_DEV: 7282 result = video_open( bktr ); 7283 break; 7284 case TUNER_DEV: 7285 result = tuner_open( bktr ); 7286 break; 7287 case VBI_DEV: 7288 result = vbi_open( bktr ); 7289 break; 7290 default: 7291 result = ENXIO; 7292 break; 7293 } 7294 7295 /* If there was an error opening the device, undo the busy status */ 7296 if (result != 0) 7297 device_unbusy(devclass_get_device(bktr_devclass, unit)); 7298 return( result ); 7299} 7300 7301 7302/* 7303 * 7304 */ 7305int 7306bktr_close( dev_t dev, int flags, int fmt, struct proc *p ) 7307{ 7308 bktr_ptr_t bktr; 7309 int unit; 7310 int result; 7311 7312 unit = UNIT( minor(dev) ); 7313 7314 /* Get the device data */ 7315 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7316 if (bktr == NULL) { 7317 /* the device is no longer valid/functioning */ 7318 return (ENXIO); 7319 } 7320 7321 switch ( FUNCTION( minor(dev) ) ) { 7322 case VIDEO_DEV: 7323 result = video_close( bktr ); 7324 break; 7325 case TUNER_DEV: 7326 result = tuner_close( bktr ); 7327 break; 7328 case VBI_DEV: 7329 result = vbi_close( bktr ); 7330 break; 7331 default: 7332 return (ENXIO); 7333 break; 7334 } 7335 7336 device_unbusy(devclass_get_device(bktr_devclass, unit)); 7337 return( result ); 7338} 7339 7340 7341/* 7342 * 7343 */ 7344int 7345bktr_read( dev_t dev, struct uio *uio, int ioflag ) 7346{ 7347 bktr_ptr_t bktr; 7348 int unit; 7349 7350 unit = UNIT(minor(dev)); 7351 7352 /* Get the device data */ 7353 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7354 if (bktr == NULL) { 7355 /* the device is no longer valid/functioning */ 7356 return (ENXIO); 7357 } 7358 7359 switch ( FUNCTION( minor(dev) ) ) { 7360 case VIDEO_DEV: 7361 return( video_read( bktr, unit, dev, uio ) ); 7362 case VBI_DEV: 7363 return( vbi_read( bktr, uio, ioflag ) ); 7364 } 7365 return( ENXIO ); 7366} 7367 7368 7369/* 7370 * 7371 */ 7372int 7373bktr_write( dev_t dev, struct uio *uio, int ioflag ) 7374{ 7375 return( EINVAL ); /* XXX or ENXIO ? */ 7376} 7377 7378 7379/* 7380 * 7381 */ 7382int 7383bktr_ioctl( dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct proc* pr ) 7384{ 7385 bktr_ptr_t bktr; 7386 int unit; 7387 7388 unit = UNIT(minor(dev)); 7389 7390 /* Get the device data */ 7391 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7392 if (bktr == NULL) { 7393 /* the device is no longer valid/functioning */ 7394 return (ENXIO); 7395 } 7396 7397 if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */ 7398 return( ENOMEM ); 7399 7400 switch ( FUNCTION( minor(dev) ) ) { 7401 case VIDEO_DEV: 7402 return( video_ioctl( bktr, unit, cmd, arg, pr ) ); 7403 case TUNER_DEV: 7404 return( tuner_ioctl( bktr, unit, cmd, arg, pr ) ); 7405 } 7406 7407 return( ENXIO ); 7408} 7409 7410 7411/* 7412 * 7413 */ 7414int 7415bktr_mmap( dev_t dev, vm_offset_t offset, int nprot ) 7416{ 7417 int unit; 7418 bktr_ptr_t bktr; 7419 7420 unit = UNIT(minor(dev)); 7421 7422 if (FUNCTION(minor(dev)) > 0) /* only allow mmap on /dev/bktr[n] */ 7423 return( -1 ); 7424 7425 /* Get the device data */ 7426 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7427 if (bktr == NULL) { 7428 /* the device is no longer valid/functioning */ 7429 return (ENXIO); 7430 } 7431 7432 if (nprot & PROT_EXEC) 7433 return( -1 ); 7434 7435 if (offset < 0) 7436 return( -1 ); 7437 7438 if (offset >= bktr->alloc_pages * PAGE_SIZE) 7439 return( -1 ); 7440 7441 return( i386_btop(vtophys(bktr->bigbuf) + offset) ); 7442} 7443 7444int bktr_poll( dev_t dev, int events, struct proc *p) 7445{ 7446 int unit; 7447 bktr_ptr_t bktr; 7448 int revents = 0; 7449 7450 unit = UNIT(minor(dev)); 7451 7452 /* Get the device data */ 7453 bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit); 7454 if (bktr == NULL) { 7455 /* the device is no longer valid/functioning */ 7456 return (ENXIO); 7457 } 7458 7459 disable_intr(); 7460 7461 if (events & (POLLIN | POLLRDNORM)) { 7462 7463 switch ( FUNCTION( minor(dev) ) ) { 7464 case VBI_DEV: 7465 if(bktr->vbisize == 0) 7466 selrecord(p, &bktr->vbi_select); 7467 else 7468 revents |= events & (POLLIN | POLLRDNORM); 7469 break; 7470 } 7471 } 7472 7473 enable_intr(); 7474 7475 return (revents); 7476} 7477 7478#endif /* FreeBSD 4.x specific kernel interface routines */ 7479 7480 7481/**********************************/ 7482/* *** FreeBSD 2.2.x and 3.x *** */ 7483/**********************************/ 7484 7485#if ((__FreeBSD__ == 2) || (__FreeBSD__ == 3)) 7486#endif /* FreeBSD 2.2.x and 3.x specific kernel interface routines */ 7487 7488 7489/*****************/ 7490/* *** BSDI *** */ 7491/*****************/ 7492 7493#if defined(__bsdi__) 7494#endif /* __bsdi__ BSDI specific kernel interface routines */ 7495 7496 7497/*****************************/ 7498/* *** OpenBSD / NetBSD *** */ 7499/*****************************/ 7500#if defined(__NetBSD__) || defined(__OpenBSD__) 7501#endif /* __NetBSD__ || __OpenBSD__ */ 7502 7503 7504 | |
7505#endif /* FreeBSD, BSDI, NetBSD, OpenBSD */ 7506 | 4181#endif /* FreeBSD, BSDI, NetBSD, OpenBSD */ 4182 |
7507 7508/* Local Variables: */ 7509/* mode: C */ 7510/* c-indent-level: 8 */ 7511/* c-brace-offset: -8 */ 7512/* c-argdecl-indent: 8 */ 7513/* c-label-offset: -8 */ 7514/* c-continued-statement-offset: 8 */ 7515/* c-tab-always-indent: nil */ 7516/* tab-width: 8 */ 7517/* End: */ | |