diff options
-rwxr-xr-x | sys/dev/bktr/CHANGELOG.TXT | 32 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_audio.c | 169 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_card.c | 69 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_card.h | 3 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_core.c | 927 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_core.h | 4 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_i2c.c | 63 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_i2c.h | 2 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_os.c | 583 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_reg.h | 95 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_tuner.c | 25 |
11 files changed, 1334 insertions, 638 deletions
diff --git a/sys/dev/bktr/CHANGELOG.TXT b/sys/dev/bktr/CHANGELOG.TXT index ffa7dbd..0fe5fb7 100755 --- a/sys/dev/bktr/CHANGELOG.TXT +++ b/sys/dev/bktr/CHANGELOG.TXT @@ -442,10 +442,34 @@ 2.07 24 Jan 2000 Update i2c code to build on FreeBSD 3.x and 4.x machines. Added GPIO audio values for the Askey/Dynalink TV card - taken from postings on the V4L mailing list. + taken from postings on the V4L mailing list. Update Australian Channel Set. Submitted by - John Birrell <jb@cimlogic.com.au> + John Birrell <jb@cimlogic.com.au> Add new Channel Set for France. Submitted by - Daniel Dagneaux <dagneaux@lure.u-psud.fr> - + Daniel Dagneaux <dagneaux@lure.u-psud.fr> + +2.08 6 Mar 2000 Reinstate rgb_vbi_prog as the default RISC program for + PAL video. This does not want to work for NTSC, which will + continue to use the rgb_prog RISC program. + Add support for cable channels above channel 100. + Submitted by Scott Presnell <srp@zgi.com> + New MSP3410/3415 setup code submitted by + Frank Nobis<fn@radio-do.de>. This is experimental and is + enabled by setting the sysctl, hw.bt848.slow_msp_audio to 1 + before starting FXTV (or before opening /dev/bktrN) + +2.09 20 Mar 2000 Thomas Klausner <wiz@danbala.ifoer.tuwien.ac.at> submitted + patches to include the NetBSD and OpenBSD support from driver + 1.74 into the new 2.xx driver. NetBSD is tested. OpenBSD is + untested. + Also fixed coding error in bktr_audio.c spotted by Thomas. + Change xxx_ioctl functions to use ioctl_cmd_t for the cmd + parameter. Found by looking at OpenBSDs change logs. + Delete PROT_EXEC from OpenBSD (as per OpenBSD cvs logs). + +2.10 4 Apr 2000 Convert to using bus_space() to access the Bt848/878 registers + rather than using a memory mapped structure. This makes the + driver portable to other architectures, like Alpha and PPC. + This was done by Thomas Klausner <wiz@netbsd.org> and + myself Roger Hardiman <roger@freebsd.org> diff --git a/sys/dev/bktr/bktr_audio.c b/sys/dev/bktr/bktr_audio.c index a33dd4c..bee8a32 100644 --- a/sys/dev/bktr/bktr_audio.c +++ b/sys/dev/bktr/bktr_audio.c @@ -50,13 +50,29 @@ #include <sys/systm.h> #include <sys/kernel.h> #include <sys/vnode.h> +#ifdef __NetBSD__ +#include <sys/proc.h> +static int bootverbose = 1; +#endif +#ifdef __FreeBSD__ #include <machine/clock.h> /* for DELAY */ - #include <pci/pcivar.h> +#endif + +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* for bus space */ +#include <machine/bus.h> +#include <sys/bus.h> +#endif -#include <machine/ioctl_meteor.h> +#ifdef __NetBSD__ +#include <dev/ic/ioctl_meteor.h> /* NetBSD location of .h files */ +#include <dev/ic/ioctl_bt848.h> +#else +#include <machine/ioctl_meteor.h> /* Traditional location of .h files */ #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ +#endif #include <dev/bktr/bktr_reg.h> #include <dev/bktr/bktr_core.h> #include <dev/bktr/bktr_tuner.h> @@ -101,7 +117,6 @@ void init_audio_devices( bktr_ptr_t bktr ) { int set_audio( bktr_ptr_t bktr, int cmd ) { - bt848_ptr_t bt848; u_long temp; volatile u_char idx; @@ -160,8 +175,6 @@ set_audio( bktr_ptr_t bktr, int cmd ) * of Bt848 cards. */ - bt848 = bktr->base; - /* * Leave the upper bits of the GPIO port alone in case they control * something like the dbx or teletext chips. This doesn't guarantee @@ -184,13 +197,12 @@ set_audio( bktr_ptr_t bktr, int cmd ) else idx = bktr->audio_mux_select; - temp = bt848->gpio_data & ~bktr->card.gpio_mux_bits; - bt848->gpio_data = + temp = INL(bktr, BKTR_GPIO_DATA) & ~bktr->card.gpio_mux_bits; #if defined( AUDIOMUX_DISCOVER ) - bt848->gpio_data = temp | (cmd & 0xff); - printf("cmd: %d audio mux %x temp %x \n", cmd,bktr->card.audiomuxs[ idx ], temp ); + OUTL(bktr, BKTR_GPIO_DATA, temp | (cmd & 0xff)); + printf("cmd: %d audio mux %x temp %x \n", cmd,bktr->card.audiomuxs[ idx ], temp ); #else - temp | bktr->card.audiomuxs[ idx ]; + OUTL(bktr, BKTR_GPIO_DATA, temp | bktr->card.audiomuxs[ idx ]); #endif /* AUDIOMUX_DISCOVER */ return( 0 ); @@ -328,7 +340,6 @@ set_bctv_audio( bktr_ptr_t bktr ) void bctv_gpio_write( bktr_ptr_t bktr, int port, int val ) { - bt848_ptr_t bt848 = bktr->base; u_long data, outbits; port &= BCTV_GPIO_PORT_MASK; @@ -343,23 +354,22 @@ bctv_gpio_write( bktr_ptr_t bktr, int port, int val ) default: return; } - bt848->gpio_out_en = 0; - bt848->gpio_data = data; - bt848->gpio_out_en = outbits; + OUTL(bktr, BKTR_GPIO_OUT_EN, 0); + OUTL(bktr, BKTR_GPIO_DATA, data); + OUTL(bktr, BKTR_GPIO_OUT_EN, outbits); DELAY(BCTV_BITS); - bt848->gpio_data = data & ~BCTV_GPIO_WE; + OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV_GPIO_WE); DELAY(BCTV_BITS); - bt848->gpio_data = data; + OUTL(bktr, BKTR_GPIO_DATA, data); DELAY(BCTV_BITS); - bt848->gpio_data = ~0; - bt848->gpio_out_en = 0; + OUTL(bktr, BKTR_GPIO_DATA, ~0); + OUTL(bktr, BKTR_GPIO_OUT_EN, 0); } /* Not yet used int bctv_gpio_read( bktr_ptr_t bktr, int port ) { - bt848_ptr_t bt848 = bktr->base; u_long data, outbits, ret; port &= BCTV_GPIO_PORT_MASK; @@ -373,18 +383,18 @@ bctv_gpio_read( bktr_ptr_t bktr, int port ) default: return( -1 ); } - bt848->gpio_out_en = 0; - bt848->gpio_data = data; - bt848->gpio_out_en = outbits; + OUTL(bktr, BKTR_GPIO_OUT_EN, 0); + OUTL(bktr, BKTR_GPIO_DATA, data); + OUTL(bktr, BKTR_GPIO_OUT_EN, outbits); DELAY(BCTV_BITS); - bt848->gpio_data = data & ~BCTV_GPIO_OE; + OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV_GPIO_OE); DELAY(BCTV_BITS); - ret = bt848->gpio_data; + ret = INL(bktr, BKTR_GPIO_DATA); DELAY(BCTV_BITS); - bt848->gpio_data = data; + OUTL(bktr, BKTR_GPIO_DATA, data); DELAY(BCTV_BITS); - bt848->gpio_data = ~0; - bt848->gpio_out_en = 0; + OUTL(bktr, BKTR_GPIO_DATA, ~0); + OUTL(bktr, BKTR_GPIO_OUT_EN, 0); return( (ret & BCTV_GPIO_VAL_MASK) >> BCTV_GPIO_VAL_SHIFT ); } */ @@ -409,28 +419,121 @@ void msp_read_id( bktr_ptr_t bktr ){ } -/* Configure the MSP chip to Auto-detect the audio format */ +/* Configure the MSP chip to Auto-detect the audio format. + * For the MSP3430G, we use fast autodetect mode + * For the MSP3410/3415 there are two schemes for this + * a) Fast autodetection - the chip is put into autodetect mode, and the function + * returns immediatly. This works in most cases and is the Default Mode. + * b) Slow mode. The function sets the MSP3410/3415 chip, then waits for feedback from + * the chip and re-programs it if needed. + */ void msp_autodetect( bktr_ptr_t bktr ) { + int auto_detect, loops; + int stereo; + printf("MSP autodetect\n"); + /* MSP3430G - countries with mono and DBX stereo */ if (strncmp("3430G", bktr->msp_version_string, 5) == 0){ - /* For MSP3430G - countries with mono and DBX stereo */ msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0030,0x2003);/* Enable Auto format detection */ msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0020);/* Standard Select Reg. = BTSC-Stereo*/ msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000E,0x2403);/* darned if I know */ msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0320);/* Source select = (St or A) */ - /* & Ch. Matrix = St */ + /* & Ch. Matrix = St */ msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ + } - } else { - /* For MSP3410 / 3415 - countries with mono, stereo using 2 FM channels - and NICAM */ + /* MSP3410/MSP3415 - countries with mono, stereo using 2 FM channels and NICAM */ + /* FAST sound scheme */ + if ( (strncmp("3430G", bktr->msp_version_string, 5) != 0) + && (bktr->slow_msp_audio == 0) ){ + if(bootverbose)printf("inside fast MSP autodetect code\n"); msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */ msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */ } + + /* MSP3410/MSP3415 - European Countries where the fast MSP3410/3415 programming fails */ + /* SLOW sound scheme */ + if ( (strncmp("3430G", bktr->msp_version_string, 5) != 0) + && (bktr->slow_msp_audio == 1) ){ + if (bootverbose)printf("inside slow MSP autodetect code\n"); + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ + msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */ + + /* wait for 0.5s max for terrestrial sound autodetection */ + loops = 10; + do { + DELAY(100000); + auto_detect = msp_dpl_read(bktr, bktr->msp_addr, 0x10, 0x007e); + loops++; + } while (auto_detect > 0xff && loops < 50); + if (bootverbose)printf ("Result of autodetect after %dms: %d\n", loops*10, auto_detect); + + /* Now set the audio baseband processing */ + switch (auto_detect) { + case 0: /* no TV sound standard detected */ + break; + case 2: /* M Dual FM */ + break; + case 3: /* B/G Dual FM; German stereo */ + /* Read the stereo detection value from DSP reg 0x0018 */ + DELAY(20000); + stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); + if (bootverbose)printf ("Stereo reg 0x18 a: %d\n", stereo); + DELAY(20000); + stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); + if (bootverbose)printf ("Stereo reg 0x18 b: %d\n", stereo); + DELAY(20000); + stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); + if (bootverbose)printf ("Stereo reg 0x18 c: %d\n", stereo); + if (stereo > 0x0100 && stereo < 0x8000) { /* Seems to be stereo */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker set stereo*/ + /* + set spatial effect strength to 50% enlargement + set spatial effect mode b, stereo basewidth enlargment only + */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f28); + } else if (stereo > 0x8000) { /* bilingual mode */ + if (bootverbose) printf ("Bilingual mode detected\n"); + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0000);/* Loudspeaker */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x0000);/* all spatial effects off */ + } else { /* must be mono */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0030);/* Loudspeaker */ + /* + set spatial effect strength to 50% enlargement + set spatial effect mode a, stereo basewidth enlargment + and pseudo stereo effect with automatic high-pass filter + */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f08); + } +#if 0 + /* The reset value for Channel matrix mode is FM/AM and SOUNDA/LEFT */ + /* We would like STEREO instead val: 0x0020 */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0009,0x0020);/* Headphone */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000a,0x0020);/* SCART1 */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0041,0x0020);/* SCART2 */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000b,0x0020);/* I2S */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000c,0x0020);/* Quasi-Peak Detector Source */ + msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000e,0x0001); +#endif + break; + case 8: /* B/G FM NICAM */ + msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */ + break; + case 9: /* L_AM NICAM or D/K*/ + case 10: /* i-FM NICAM */ + break; + default: + if (bootverbose) printf ("Unkown autodetection result value: %d\n", auto_detect); + } + + } + + /* uncomment the following line to enable the MSP34xx 1Khz Tone Generator */ /* turn your speaker volume down low before trying this */ /* msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0014, 0x7f40); */ diff --git a/sys/dev/bktr/bktr_card.c b/sys/dev/bktr/bktr_card.c index 9996203..7b80be0 100644 --- a/sys/dev/bktr/bktr_card.c +++ b/sys/dev/bktr/bktr_card.c @@ -47,24 +47,40 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "opt_bktr.h" +#include "opt_bktr.h" /* Include any kernel config options */ #include <sys/param.h> #include <sys/systm.h> #include <sys/vnode.h> +#ifdef __FreeBSD__ #include <machine/clock.h> /* for DELAY */ - #include <pci/pcivar.h> +#endif -#include <machine/ioctl_meteor.h> +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* for bus space */ +#include <machine/bus.h> +#include <sys/bus.h> +#endif + +#ifdef __NetBSD__ +#include <dev/ic/ioctl_meteor.h> /* NetBSD location for .h files */ +#include <dev/ic/ioctl_bt848.h> +#else +#include <machine/ioctl_meteor.h> /* Traditional location for .h files */ #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ +#endif #include <dev/bktr/bktr_reg.h> #include <dev/bktr/bktr_core.h> #include <dev/bktr/bktr_tuner.h> #include <dev/bktr/bktr_card.h> #include <dev/bktr/bktr_audio.h> +#ifdef __NetBSD__ +static int bootverbose = 1; +#endif + /* Various defines */ #define HAUP_REMOTE_INT_WADDR 0x30 #define HAUP_REMOTE_INT_RADDR 0x31 @@ -301,9 +317,20 @@ static const struct CARDTYPE cards[] = { 0, /* EEProm type */ 0, /* EEProm size */ /* Tuner, Extern, Intern, Mute, Enabled */ - { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */ + { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */ 0xfff000 }, /* GPIO mask */ + { CARD_TERRATVPLUS, /* the card id */ + "TerraTVplus", /* the 'name' */ + NULL, /* the tuner */ + 0, + 0, + 0, + 0, + 0, /* EEProm type */ + 0, /* EEProm size */ + { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/ + 0x70000 }, /* GPIO mask */ }; @@ -504,7 +531,6 @@ probeCard( bktr_ptr_t bktr, int verbose, int unit ) { int card, i,j, card_found; int status; - bt848_ptr_t bt848; u_char probe_signature[128], *probe_temp; int any_i2c_devices; u_char eeprom[256]; @@ -512,24 +538,22 @@ probeCard( bktr_ptr_t bktr, int verbose, int unit ) int tuner_i2c_address = -1; int eeprom_i2c_address = -1; - bt848 = bktr->base; - /* Select all GPIO bits as inputs */ - bt848->gpio_out_en = 0; + OUTL(bktr, BKTR_GPIO_OUT_EN, 0); if (bootverbose) - printf("bktr: GPIO is 0x%08x\n", bt848->gpio_data); + printf("bktr: GPIO is 0x%08x\n", INL(bktr, BKTR_GPIO_DATA)); #ifdef HAUPPAUGE_MSP_RESET /* Reset the MSP34xx audio chip. This resolves bootup card * detection problems with old Bt848 based Hauppauge cards with * MSP34xx stereo audio chips. This must be user enabled because * at this point the probe function does not know the card type. */ - bt848->gpio_out_en = bt848->gpio_out_en | (1<<5); - bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ + OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5)); + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ - bt848->gpio_data = bt848->gpio_data & ~(1<<5); /* write '0' */ + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */ DELAY(2500); /* wait 2.5ms */ - bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ #endif @@ -581,8 +605,8 @@ probeCard( bktr_ptr_t bktr, int verbose, int unit ) subsystem_vendor_id = (byte_254 << 8) | byte_255; if ( bootverbose ) - printf("subsytem 0x%04x 0x%04x\n",subsystem_vendor_id, - subsystem_id); + printf("subsystem 0x%04x 0x%04x\n", + subsystem_vendor_id, subsystem_id); if (subsystem_vendor_id == VENDOR_AVER_MEDIA) { bktr->card = cards[ (card = CARD_AVER_MEDIA) ]; @@ -778,7 +802,7 @@ checkTuner: switch (card) { case CARD_MIRO: - switch (((bt848->gpio_data >> 10)-1)&7) { + switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) { case 0: select_tuner( bktr, TEMIC_PAL ); break; case 1: select_tuner( bktr, PHILIPS_PAL ); break; case 2: select_tuner( bktr, PHILIPS_NTSC ); break; @@ -974,6 +998,7 @@ checkTuner: tuner_make, tuner_format); } break; + case CARD_LEADTEK: #if BROOKTREE_SYSTEM_DEFAULT == BROOKTREE_PAL select_tuner( bktr, PHILIPS_FR1216_PAL ); @@ -1038,12 +1063,12 @@ checkMSP: #ifndef BKTR_NO_MSP_RESET if (card == CARD_HAUPPAUGE) { - bt848->gpio_out_en = bt848->gpio_out_en | (1<<5); - bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ + OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5)); + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ - bt848->gpio_data = bt848->gpio_data & ~(1<<5); /* write '0' */ + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */ DELAY(2500); /* wait 2.5ms */ - bt848->gpio_data = bt848->gpio_data | (1<<5); /* write '1' */ + OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ } #endif @@ -1080,12 +1105,10 @@ checkMSPEnd: if (bktr->card.dpl3518a) { bktr->dpl_addr = DPL3518A_WADDR; -/* dpl_read_id( bktr ); + dpl_read_id( bktr ); printf("bktr%d: Detected a DPL%s at 0x%x\n", unit, bktr->dpl_version_string, bktr->dpl_addr); -*/ - } /* Start of Check Remote */ diff --git a/sys/dev/bktr/bktr_card.h b/sys/dev/bktr/bktr_card.h index 208c4dc..abebb45 100644 --- a/sys/dev/bktr/bktr_card.h +++ b/sys/dev/bktr/bktr_card.h @@ -75,7 +75,8 @@ #define CARD_VIDEO_HIGHWAY_XTREME 13 #define CARD_ASKEY_DYNALINK_MAGIC_TVIEW 14 #define CARD_LEADTEK 15 -#define Bt848_MAX_CARD 16 +#define CARD_TERRATVPLUS 16 +#define Bt848_MAX_CARD 17 int signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig ); diff --git a/sys/dev/bktr/bktr_core.c b/sys/dev/bktr/bktr_core.c index e55e6f2..b25f86b 100644 --- a/sys/dev/bktr/bktr_core.c +++ b/sys/dev/bktr/bktr_core.c @@ -94,18 +94,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "opt_bktr.h" /* Include any kernel config options */ #ifdef __FreeBSD__ #include "bktr.h" -#include "opt_bktr.h" #include "opt_devfs.h" #endif /* __FreeBSD__ */ -#if defined(__NetBSD__) || defined(__OpenBSD__) -#include "bktr.h" -#include "pci.h" -#endif /* __NetBSD__ || __OpenBSD__ */ - #if ( \ (defined(__FreeBSD__) && (NBKTR > 0)) \ || (defined(__bsdi__)) \ @@ -137,14 +132,20 @@ #include <machine/clock.h> /* for DELAY */ #include <pci/pcivar.h> +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* for bus space */ +#include <machine/bus.h> +#include <sys/bus.h> +#endif + #include <machine/ioctl_meteor.h> #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ #include <dev/bktr/bktr_reg.h> #include <dev/bktr/bktr_tuner.h> #include <dev/bktr/bktr_card.h> #include <dev/bktr/bktr_audio.h> -#include <dev/bktr/bktr_core.h> #include <dev/bktr/bktr_os.h> +#include <dev/bktr/bktr_core.h> #if (NSMBUS > 0) #include <dev/bktr/bktr_i2c.h> @@ -172,6 +173,21 @@ typedef unsigned int uintptr_t; /* *** OpenBSD/NetBSD *** */ /**************************/ #if defined(__NetBSD__) || defined(__OpenBSD__) + +#include <sys/inttypes.h> /* uintptr_t */ +#include <dev/ic/ioctl_meteor.h> +#include <dev/ic/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ +#include <dev/bktr/bktr_reg.h> +#include <dev/bktr/bktr_tuner.h> +#include <dev/bktr/bktr_card.h> +#include <dev/bktr/bktr_audio.h> +#include <dev/bktr/bktr_core.h> +#include <dev/bktr/bktr_os.h> + +static int bootverbose = 1; + +static int bt848_format = -1; + #endif /* __NetBSD__ || __OpenBSD__ */ @@ -366,7 +382,7 @@ static u_int pixfmt_swap_flags( int pixfmt ); * bt848 RISC programming routines. */ #ifdef BT848_DUMP -static int dump_bt848( bt848_ptr_t bt848 ); +static int dump_bt848( bktr_ptr_t bktr ); #endif static void yuvpack_prog( bktr_ptr_t bktr, char i_flag, int cols, @@ -400,13 +416,12 @@ static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote); /* * ioctls common to both video & tuner. */ -static int common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, - int cmd, caddr_t arg ); +static int common_ioctl( bktr_ptr_t bktr, ioctl_cmd_t cmd, caddr_t arg ); #if ((!defined(__FreeBSD__)) || (NSMBUS == 0) ) /* - * i2c primatives for low level control of i2c bus. Added for MSP34xx control + * i2c primitives for low level control of i2c bus. Added for MSP34xx control */ static void i2c_start( bktr_ptr_t bktr); static void i2c_stop( bktr_ptr_t bktr); @@ -422,11 +437,8 @@ static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ); void common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev ) { - bt848_ptr_t bt848; vm_offset_t buf; - bt848 = bktr->base; - /***************************************/ /* *** OS Specific memory routines *** */ /***************************************/ @@ -525,6 +537,7 @@ common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev ) bktr->bt848_card = -1; bktr->bt848_tuner = -1; bktr->reverse_mute = -1; + bktr->slow_msp_audio = 0; probeCard( bktr, TRUE, unit ); @@ -585,7 +598,6 @@ int common_bktr_intr( void *arg ) { bktr_ptr_t bktr; - bt848_ptr_t bt848; u_long bktr_status; u_char dstatus; u_long field; @@ -593,30 +605,29 @@ common_bktr_intr( void *arg ) u_long req_field; bktr = (bktr_ptr_t) arg; - bt848 = bktr->base; /* * check to see if any interrupts are unmasked on this device. If * none are, then we likely got here by way of being on a PCI shared * interrupt dispatch list. */ - if (bt848->int_mask == ALL_INTS_DISABLED) + if (INL(bktr, BKTR_INT_MASK) == ALL_INTS_DISABLED) return 0; /* bail out now, before we do something we shouldn't */ if (!(bktr->flags & METEOR_OPEN)) { - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; - bt848->int_mask = ALL_INTS_DISABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); /* return; ?? */ } /* record and clear the INTerrupt status bits */ - bktr_status = bt848->int_stat; - bt848->int_stat = bktr_status & ~I2C_BITS; /* don't touch i2c */ + bktr_status = INL(bktr, BKTR_INT_STAT); + OUTL(bktr, BKTR_INT_STAT, bktr_status & ~I2C_BITS); /* don't touch i2c */ /* record and clear the device status register */ - dstatus = bt848->dstatus; - bt848->dstatus = 0x00; + dstatus = INB(bktr, BKTR_DSTATUS); + OUTB(bktr, BKTR_DSTATUS, 0x00); #if defined( STATUS_SUM ) /* add any new device status or INTerrupt status bits */ @@ -624,7 +635,7 @@ common_bktr_intr( void *arg ) status_sum |= ((dstatus & (BT848_DSTATUS_COF|BT848_DSTATUS_LOF)) << 6); #endif /* STATUS_SUM */ /* printf( " STATUS %x %x %x \n", - dstatus, bktr_status, bt848->risc_count ); + dstatus, bktr_status, INL(bktr, BKTR_RISC_COUNT) ); */ @@ -637,18 +648,18 @@ common_bktr_intr( void *arg ) BT848_INT_PPERR | BT848_INT_RIPERR | BT848_INT_PABORT | BT848_INT_OCERR | BT848_INT_SCERR) ) != 0) - || ((bt848->tdec == 0) && (bktr_status & TDEC_BITS)) ) { + || ((INB(bktr, BKTR_TDEC) == 0) && (bktr_status & TDEC_BITS)) ) { - u_short tdec_save = bt848->tdec; + u_short tdec_save = INB(bktr, BKTR_TDEC); - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; - bt848->cap_ctl = CAPTURE_OFF; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF); - bt848->int_mask = ALL_INTS_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); - /* Reset temporal decimation ctr */ - bt848->tdec = 0; - bt848->tdec = tdec_save; + /* Reset temporal decimation counter */ + OUTB(bktr, BKTR_TDEC, 0); + OUTB(bktr, BKTR_TDEC, tdec_save); /* Reset to no-fields captured state */ if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) { @@ -665,16 +676,16 @@ common_bktr_intr( void *arg ) } } - bt848->risc_strt_add = vtophys(bktr->dma_prog); - bt848->gpio_dma_ctl = FIFO_ENABLED; - bt848->gpio_dma_ctl = bktr->capcontrol; + OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog)); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol); - bt848->int_mask = BT848_INT_MYSTERYBIT | - BT848_INT_RISCI | - BT848_INT_VSYNC | - BT848_INT_FMTCHG; + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT | + BT848_INT_RISCI | + BT848_INT_VSYNC | + BT848_INT_FMTCHG); - bt848->cap_ctl = bktr->bktr_cap_ctl; + OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl); return 1; } @@ -684,9 +695,9 @@ common_bktr_intr( void *arg ) /** printf( "intr status %x %x %x\n", - bktr_status, dstatus, bt848->risc_count ); + bktr_status, dstatus, INL(bktr, BKTR_RISC_COUNT) ); */ - + /* * Disable future interrupts if a capture mode is not selected. @@ -694,7 +705,7 @@ common_bktr_intr( void *arg ) * changing capture modes, otherwise it shouldn't happen. */ if (!(bktr->flags & METEOR_CAP_MASK)) - bt848->cap_ctl = CAPTURE_OFF; + OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF); /* Determine which field generated this interrupt */ @@ -706,7 +717,9 @@ common_bktr_intr( void *arg ) * both Odd and Even VBI data is captured. Therefore we do this * in the Even field interrupt handler. */ - if ((bktr->vbiflags & VBI_CAPTURE)&&(field==EVEN_F)) { + if ( (bktr->vbiflags & VBI_CAPTURE) + &&(bktr->vbiflags & VBI_OPEN) + &&(field==EVEN_F)) { /* Put VBI data into circular buffer */ vbidecode(bktr); @@ -801,10 +814,10 @@ common_bktr_intr( void *arg ) if (bktr->flags & METEOR_SINGLE) { /* stop dma */ - bt848->int_mask = ALL_INTS_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); /* disable risc, leave fifo running */ - bt848->gpio_dma_ctl = FIFO_ENABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); wakeup(BKTR_SLEEP); } @@ -859,7 +872,6 @@ extern int bt848_format; /* used to set the default format, PAL or NTSC */ int video_open( bktr_ptr_t bktr ) { - bt848_ptr_t bt848; int frame_rate, video_format=0; if (bktr->flags & METEOR_OPEN) /* device is busy */ @@ -867,17 +879,15 @@ video_open( bktr_ptr_t bktr ) bktr->flags |= METEOR_OPEN; - bt848 = bktr->base; - #ifdef BT848_DUMP dump_bt848( bt848 ); #endif bktr->clr_on_start = FALSE; - bt848->dstatus = 0x00; /* clear device status reg. */ + OUTB(bktr, BKTR_DSTATUS, 0x00); /* clear device status reg. */ - bt848->adc = SYNC_LEVEL; + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); #if BROOKTREE_SYSTEM_DEFAULT == BROOKTREE_PAL video_format = 0; @@ -892,56 +902,52 @@ video_open( bktr_ptr_t bktr ) video_format = 1; if (video_format == 1 ) { - bt848->iform = BT848_IFORM_F_NTSCM; + OUTB(bktr, BKTR_IFORM, BT848_IFORM_F_NTSCM); bktr->format_params = BT848_IFORM_F_NTSCM; } else { - bt848->iform = BT848_IFORM_F_PALBDGHI; + OUTB(bktr, BKTR_IFORM, BT848_IFORM_F_PALBDGHI); bktr->format_params = BT848_IFORM_F_PALBDGHI; } - bt848->iform |= format_params[bktr->format_params].iform_xtsel; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | format_params[bktr->format_params].iform_xtsel); /* work around for new Hauppauge 878 cards */ if ((bktr->card.card_id == CARD_HAUPPAUGE) && (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) - bt848->iform |= BT848_IFORM_M_MUX3; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3); else - bt848->iform |= BT848_IFORM_M_MUX1; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1); - bt848->adelay = format_params[bktr->format_params].adelay; - bt848->bdelay = format_params[bktr->format_params].bdelay; + OUTL(bktr, BKTR_ADELAY, format_params[bktr->format_params].adelay); + OUTB(bktr, BKTR_BDELAY, format_params[bktr->format_params].bdelay); frame_rate = format_params[bktr->format_params].frame_rate; /* enable PLL mode using 28Mhz crystal for PAL/SECAM users */ if (bktr->xtal_pll_mode == BT848_USE_PLL) { - bt848->tgctrl=0; - bt848->pll_f_lo=0xf9; - bt848->pll_f_hi=0xdc; - bt848->pll_f_xci=0x8e; + OUTB(bktr, BKTR_TGCTRL, 0); + OUTB(bktr, BKTR_PLL_F_LO, 0xf9); + OUTB(bktr, BKTR_PLL_F_HI, 0xdc); + OUTB(bktr, BKTR_PLL_F_XCI, 0x8e); } bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV0; bktr->max_clip_node = 0; - bt848->color_ctl_gamma = 1; - bt848->color_ctl_rgb_ded = 1; - bt848->color_ctl_color_bars = 0; - bt848->color_ctl_ext_frmrate = 0; - bt848->color_ctl_swap = 0; + OUTB(bktr, BKTR_COLOR_CTL, BT848_COLOR_CTL_GAMMA | BT848_COLOR_CTL_RGB_DED); - bt848->e_hscale_lo = 170; - bt848->o_hscale_lo = 170; + OUTB(bktr, BKTR_E_HSCALE_LO, 170); + OUTB(bktr, BKTR_O_HSCALE_LO, 170); - bt848->e_delay_lo = 0x72; - bt848->o_delay_lo = 0x72; - bt848->e_scloop = 0; - bt848->o_scloop = 0; + OUTB(bktr, BKTR_E_DELAY_LO, 0x72); + OUTB(bktr, BKTR_O_DELAY_LO, 0x72); + OUTB(bktr, BKTR_E_SCLOOP, 0); + OUTB(bktr, BKTR_O_SCLOOP, 0); - bt848->vbi_pack_size = 0; - bt848->vbi_pack_del = 0; + OUTB(bktr, BKTR_VBI_PACK_SIZE, 0); + OUTB(bktr, BKTR_VBI_PACK_DEL, 0); bktr->fifo_errors = 0; bktr->dma_errors = 0; @@ -960,7 +966,7 @@ video_open( bktr_ptr_t bktr ) bktr->capture_area_enabled = FALSE; - bt848->int_mask = BT848_INT_MYSTERYBIT; /* if you take this out triton + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT); /* if you take this out triton based motherboards will operate unreliably */ return( 0 ); @@ -1007,7 +1013,7 @@ tuner_open( bktr_ptr_t bktr ) bktr->tuner.radio_mode = 0; /* enable drivers on the GPIO port that control the MUXes */ - bktr->base->gpio_out_en |= bktr->card.gpio_mux_bits; + OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | bktr->card.gpio_mux_bits); /* unmute the audio stream */ set_audio( bktr, AUDIO_UNMUTE ); @@ -1027,24 +1033,21 @@ tuner_open( bktr_ptr_t bktr ) int video_close( bktr_ptr_t bktr ) { - bt848_ptr_t bt848; - bktr->flags &= ~(METEOR_OPEN | METEOR_SINGLE | METEOR_CAP_MASK | METEOR_WANT_MASK); - bt848 = bktr->base; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; - bt848->cap_ctl = CAPTURE_OFF; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF); bktr->dma_prog_loaded = FALSE; - bt848->tdec = 0; - bt848->int_mask = ALL_INTS_DISABLED; + OUTB(bktr, BKTR_TDEC, 0); + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); /** FIXME: is 0xf magic, wouldn't 0x00 work ??? */ - bt848->sreset = 0xf; - bt848->int_stat = ALL_INTS_CLEARED; + OUTL(bktr, BKTR_SRESET, 0xf); + OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED); return( 0 ); } @@ -1063,7 +1066,7 @@ tuner_close( bktr_ptr_t bktr ) set_audio( bktr, AUDIO_MUTE ); /* disable drivers on the GPIO port that control the MUXes */ - bktr->base->gpio_out_en = bktr->base->gpio_out_en & ~bktr->card.gpio_mux_bits; + OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) & ~bktr->card.gpio_mux_bits); return( 0 ); } @@ -1083,20 +1086,17 @@ vbi_close( bktr_ptr_t bktr ) int video_read(bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio) { - bt848_ptr_t bt848; int status; int count; - bt848 = bktr->base; - if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */ return( ENOMEM ); if (bktr->flags & METEOR_CAP_MASK) return( EIO ); /* already capturing */ - bt848->cap_ctl = bktr->bktr_cap_ctl; + OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl); count = bktr->rows * bktr->cols * @@ -1110,13 +1110,13 @@ video_read(bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio) /* capture one frame */ start_capture(bktr, METEOR_SINGLE); /* wait for capture to complete */ - bt848->int_stat = ALL_INTS_CLEARED; - bt848->gpio_dma_ctl = FIFO_ENABLED; - bt848->gpio_dma_ctl = bktr->capcontrol; - bt848->int_mask = BT848_INT_MYSTERYBIT | - BT848_INT_RISCI | - BT848_INT_VSYNC | - BT848_INT_FMTCHG; + OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol); + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT | + BT848_INT_RISCI | + BT848_INT_VSYNC | + BT848_INT_FMTCHG); status = tsleep(BKTR_SLEEP, BKTRPRI, "captur", 0); @@ -1194,9 +1194,8 @@ vbi_read(bktr_ptr_t bktr, struct uio *uio, int ioflag) * video ioctls */ int -video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) +video_ioctl( bktr_ptr_t bktr, int unit, ioctl_cmd_t cmd, caddr_t arg, struct proc* pr ) { - bt848_ptr_t bt848; volatile u_char c_temp; unsigned int temp; unsigned int temp_iform; @@ -1209,8 +1208,6 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) int i; char char_temp; - bt848 = bktr->base; - switch ( cmd ) { case BT848SCLIP: /* set clip region */ @@ -1272,7 +1269,7 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) break; case METEORSTATUS: /* get Bt848 status */ - c_temp = bt848->dstatus; + c_temp = INB(bktr, BKTR_DSTATUS); temp = 0; if (!(c_temp & 0x40)) temp |= METEOR_STATUS_HCLK; if (!(c_temp & 0x10)) temp |= METEOR_STATUS_FIDT; @@ -1281,10 +1278,10 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848SFMT: /* set input format */ temp = *(unsigned long*)arg & BT848_IFORM_FORMAT; - temp_iform = bt848->iform; + temp_iform = INB(bktr, BKTR_IFORM); temp_iform &= ~BT848_IFORM_FORMAT; temp_iform &= ~BT848_IFORM_XTSEL; - bt848->iform = (temp_iform | temp | format_params[temp].iform_xtsel); + OUTB(bktr, BKTR_IFORM, (temp_iform | temp | format_params[temp].iform_xtsel)); switch( temp ) { case BT848_IFORM_F_AUTO: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | @@ -1295,8 +1292,8 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_IFORM_F_NTSCJ: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | METEOR_NTSC; - bt848->adelay = format_params[temp].adelay; - bt848->bdelay = format_params[temp].bdelay; + OUTL(bktr, BKTR_ADELAY, format_params[temp].adelay); + OUTB(bktr, BKTR_BDELAY, format_params[temp].bdelay); bktr->format_params = temp; break; @@ -1307,8 +1304,8 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_IFORM_F_PALM: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | METEOR_PAL; - bt848->adelay = format_params[temp].adelay; - bt848->bdelay = format_params[temp].bdelay; + OUTL(bktr, BKTR_ADELAY, format_params[temp].adelay); + OUTB(bktr, BKTR_BDELAY, format_params[temp].bdelay); bktr->format_params = temp; break; @@ -1317,7 +1314,7 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) break; case METEORSFMT: /* set input format */ - temp_iform = bt848->iform; + temp_iform = INB(bktr, BKTR_IFORM); temp_iform &= ~BT848_IFORM_FORMAT; temp_iform &= ~BT848_IFORM_XTSEL; switch(*(unsigned long *)arg & METEOR_FORM_MASK ) { @@ -1325,28 +1322,28 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case METEOR_FMT_NTSC: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | METEOR_NTSC; - bt848->iform = temp_iform | BT848_IFORM_F_NTSCM | - format_params[BT848_IFORM_F_NTSCM].iform_xtsel; - bt848->adelay = format_params[BT848_IFORM_F_NTSCM].adelay; - bt848->bdelay = format_params[BT848_IFORM_F_NTSCM].bdelay; + OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_NTSCM | + format_params[BT848_IFORM_F_NTSCM].iform_xtsel); + OUTL(bktr, BKTR_ADELAY, format_params[BT848_IFORM_F_NTSCM].adelay); + OUTB(bktr, BKTR_BDELAY, format_params[BT848_IFORM_F_NTSCM].bdelay); bktr->format_params = BT848_IFORM_F_NTSCM; break; case METEOR_FMT_PAL: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | METEOR_PAL; - bt848->iform = temp_iform | BT848_IFORM_F_PALBDGHI | - format_params[BT848_IFORM_F_PALBDGHI].iform_xtsel; - bt848->adelay = format_params[BT848_IFORM_F_PALBDGHI].adelay; - bt848->bdelay = format_params[BT848_IFORM_F_PALBDGHI].bdelay; + OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_PALBDGHI | + format_params[BT848_IFORM_F_PALBDGHI].iform_xtsel); + OUTL(bktr, BKTR_ADELAY, format_params[BT848_IFORM_F_PALBDGHI].adelay); + OUTB(bktr, BKTR_BDELAY, format_params[BT848_IFORM_F_PALBDGHI].bdelay); bktr->format_params = BT848_IFORM_F_PALBDGHI; break; case METEOR_FMT_AUTOMODE: bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) | METEOR_AUTOMODE; - bt848->iform = temp_iform | BT848_IFORM_F_AUTO | - format_params[BT848_IFORM_F_AUTO].iform_xtsel; + OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_AUTO | + format_params[BT848_IFORM_F_AUTO].iform_xtsel); break; default: @@ -1361,7 +1358,7 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848GFMT: /* get input format */ - *(u_long *)arg = bt848->iform & BT848_IFORM_FORMAT; + *(u_long *)arg = INB(bktr, BKTR_IFORM) & BT848_IFORM_FORMAT; break; case METEORSCOUNT: /* (re)set error counts */ @@ -1407,44 +1404,48 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) break; case METEORSHUE: /* set hue */ - bt848->hue = (*(u_char *) arg) & 0xff; + OUTB(bktr, BKTR_HUE, (*(u_char *) arg) & 0xff); break; case METEORGHUE: /* get hue */ - *(u_char *)arg = bt848->hue; + *(u_char *)arg = INB(bktr, BKTR_HUE); break; case METEORSBRIG: /* set brightness */ char_temp = ( *(u_char *)arg & 0xff) - 128; - bt848->bright = char_temp; + OUTB(bktr, BKTR_BRIGHT, char_temp); break; case METEORGBRIG: /* get brightness */ - *(u_char *)arg = bt848->bright; + *(u_char *)arg = INB(bktr, BKTR_BRIGHT); break; case METEORSCSAT: /* set chroma saturation */ temp = (int)*(u_char *)arg; - bt848->sat_u_lo = bt848->sat_v_lo = (temp << 1) & 0xff; - - bt848->e_control &= ~(BT848_E_CONTROL_SAT_U_MSB | - BT848_E_CONTROL_SAT_V_MSB); - bt848->o_control &= ~(BT848_O_CONTROL_SAT_U_MSB | - BT848_O_CONTROL_SAT_V_MSB); + OUTB(bktr, BKTR_SAT_U_LO, (temp << 1) & 0xff); + OUTB(bktr, BKTR_SAT_V_LO, (temp << 1) & 0xff); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) + & ~(BT848_E_CONTROL_SAT_U_MSB + | BT848_E_CONTROL_SAT_V_MSB)); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) + & ~(BT848_O_CONTROL_SAT_U_MSB | + BT848_O_CONTROL_SAT_V_MSB)); if ( temp & BIT_SEVEN_HIGH ) { - bt848->e_control |= (BT848_E_CONTROL_SAT_U_MSB | - BT848_E_CONTROL_SAT_V_MSB); - bt848->o_control |= (BT848_O_CONTROL_SAT_U_MSB | - BT848_O_CONTROL_SAT_V_MSB); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) + | (BT848_E_CONTROL_SAT_U_MSB + | BT848_E_CONTROL_SAT_V_MSB)); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) + | (BT848_O_CONTROL_SAT_U_MSB + | BT848_O_CONTROL_SAT_V_MSB)); } break; case METEORGCSAT: /* get chroma saturation */ - temp = (bt848->sat_v_lo >> 1) & 0xff; - if ( bt848->e_control & BT848_E_CONTROL_SAT_V_MSB ) + temp = (INB(bktr, BKTR_SAT_V_LO) >> 1) & 0xff; + if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB ) temp |= BIT_SEVEN_HIGH; *(u_char *)arg = (u_char)temp; break; @@ -1452,24 +1453,24 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case METEORSCONT: /* set contrast */ temp = (int)*(u_char *)arg & 0xff; temp <<= 1; - bt848->contrast_lo = temp & 0xff; - bt848->e_control &= ~BT848_E_CONTROL_CON_MSB; - bt848->o_control &= ~BT848_O_CONTROL_CON_MSB; - bt848->e_control |= - ((temp & 0x100) >> 6 ) & BT848_E_CONTROL_CON_MSB; - bt848->o_control |= - ((temp & 0x100) >> 6 ) & BT848_O_CONTROL_CON_MSB; + OUTB(bktr, BKTR_CONTRAST_LO, temp & 0xff); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_CON_MSB); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_CON_MSB); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | + (((temp & 0x100) >> 6 ) & BT848_E_CONTROL_CON_MSB)); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | + (((temp & 0x100) >> 6 ) & BT848_O_CONTROL_CON_MSB)); break; case METEORGCONT: /* get contrast */ - temp = (int)bt848->contrast_lo & 0xff; - temp |= ((int)bt848->o_control & 0x04) << 6; + temp = (int)INB(bktr, BKTR_CONTRAST_LO) & 0xff; + temp |= ((int)INB(bktr, BKTR_O_CONTROL) & 0x04) << 6; *(u_char *)arg = (u_char)((temp >> 1) & 0xff); break; case BT848SCBUF: /* set Clear-Buffer-on-start flag */ - bktr->clr_on_start = (*(int *)arg != 0); - break; + bktr->clr_on_start = (*(int *)arg != 0); + break; case BT848GCBUF: /* get Clear-Buffer-on-start flag */ *(int *)arg = (int) bktr->clr_on_start; @@ -1504,29 +1505,29 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) start_capture(bktr, METEOR_SINGLE); /* wait for capture to complete */ - bt848->int_stat = ALL_INTS_CLEARED; - bt848->gpio_dma_ctl = FIFO_ENABLED; - bt848->gpio_dma_ctl = bktr->capcontrol; + OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol); - bt848->int_mask = BT848_INT_MYSTERYBIT | - BT848_INT_RISCI | - BT848_INT_VSYNC | - BT848_INT_FMTCHG; + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT | + BT848_INT_RISCI | + BT848_INT_VSYNC | + BT848_INT_FMTCHG); - bt848->cap_ctl = bktr->bktr_cap_ctl; + OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl); error = tsleep(BKTR_SLEEP, BKTRPRI, "captur", hz); if (error && (error != ERESTART)) { /* Here if we didn't get complete frame */ #ifdef DIAGNOSTIC printf( "bktr%d: ioctl: tsleep error %d %x\n", - unit, error, bt848->risc_count); + unit, error, INL(bktr, BKTR_RISC_COUNT)); #endif /* stop dma */ - bt848->int_mask = ALL_INTS_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); /* disable risc, leave fifo running */ - bt848->gpio_dma_ctl = FIFO_ENABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); } bktr->flags &= ~(METEOR_SINGLE|METEOR_WANT_MASK); @@ -1542,16 +1543,18 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) start_capture(bktr, METEOR_CONTIN); - bt848->int_stat = bt848->int_stat; - bt848->gpio_dma_ctl = FIFO_ENABLED; - bt848->gpio_dma_ctl = bktr->capcontrol; - bt848->cap_ctl = bktr->bktr_cap_ctl; + /* Clear the interrypt status register */ + OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT)); + + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol); + OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl); - bt848->int_mask = BT848_INT_MYSTERYBIT | - BT848_INT_RISCI | - BT848_INT_VSYNC | - BT848_INT_FMTCHG; + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT | + BT848_INT_RISCI | + BT848_INT_VSYNC | + BT848_INT_FMTCHG); #ifdef BT848_DUMP dump_bt848( bt848 ); #endif @@ -1560,9 +1563,9 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case METEOR_CAP_STOP_CONT: if (bktr->flags & METEOR_CONTIN) { /* turn off capture */ - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; - bt848->cap_ctl = CAPTURE_OFF; - bt848->int_mask = ALL_INTS_DISABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF); + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); bktr->flags &= ~(METEOR_CONTIN | METEOR_WANT_MASK); @@ -1635,9 +1638,9 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) return( error ); bktr->dma_prog_loaded = FALSE; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); - bt848->int_mask = ALL_INTS_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); if ((temp=(geo->rows * geo->columns * geo->frames * 2))) { if (geo->oformat & METEOR_GEO_RGB24) temp = temp * 2; @@ -1727,12 +1730,12 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) } start_capture(bktr, METEOR_CONTIN); - bt848->int_stat = bt848->int_stat; - bt848->gpio_dma_ctl = FIFO_ENABLED; - bt848->gpio_dma_ctl = bktr->capcontrol; - bt848->int_mask = BT848_INT_MYSTERYBIT | - BT848_INT_VSYNC | - BT848_INT_FMTCHG; + OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT)); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol); + OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT | + BT848_INT_VSYNC | + BT848_INT_FMTCHG); } } break; @@ -1788,7 +1791,7 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) break; default: - return common_ioctl( bktr, bt848, cmd, arg ); + return common_ioctl( bktr, cmd, arg ); } return( 0 ); @@ -1798,9 +1801,8 @@ video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) * tuner ioctls */ int -tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) +tuner_ioctl( bktr_ptr_t bktr, int unit, ioctl_cmd_t cmd, caddr_t arg, struct proc* pr ) { - bt848_ptr_t bt848; int tmp_int; unsigned int temp, temp1; int offset; @@ -1812,8 +1814,6 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) int i2c_port; u_long data; - bt848 = bktr->base; - switch ( cmd ) { case REMOTE_GETKEY: @@ -1910,28 +1910,28 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) /* hue is a 2's compliment number, -90' to +89.3' in 0.7' steps */ case BT848_SHUE: /* set hue */ - bt848->hue = (u_char)(*(int*)arg & 0xff); + OUTB(bktr, BKTR_HUE, (u_char)(*(int*)arg & 0xff)); break; case BT848_GHUE: /* get hue */ - *(int*)arg = (signed char)(bt848->hue & 0xff); + *(int*)arg = (signed char)(INB(bktr, BKTR_HUE) & 0xff); break; /* brightness is a 2's compliment #, -50 to +%49.6% in 0.39% steps */ case BT848_SBRIG: /* set brightness */ - bt848->bright = (u_char)(*(int *)arg & 0xff); + OUTB(bktr, BKTR_BRIGHT, (u_char)(*(int *)arg & 0xff)); break; case BT848_GBRIG: /* get brightness */ - *(int *)arg = (signed char)(bt848->bright & 0xff); + *(int *)arg = (signed char)(INB(bktr, BKTR_BRIGHT) & 0xff); break; /* */ case BT848_SCSAT: /* set chroma saturation */ tmp_int = *(int*)arg; - temp = bt848->e_control; - temp1 = bt848->o_control; + temp = INB(bktr, BKTR_E_CONTROL); + temp1 = INB(bktr, BKTR_O_CONTROL); if ( tmp_int & BIT_EIGHT_HIGH ) { temp |= (BT848_E_CONTROL_SAT_U_MSB | BT848_E_CONTROL_SAT_V_MSB); @@ -1945,15 +1945,15 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) BT848_O_CONTROL_SAT_V_MSB); } - bt848->sat_u_lo = (u_char)(tmp_int & 0xff); - bt848->sat_v_lo = (u_char)(tmp_int & 0xff); - bt848->e_control = temp; - bt848->o_control = temp1; + OUTB(bktr, BKTR_SAT_U_LO, (u_char)(tmp_int & 0xff)); + OUTB(bktr, BKTR_SAT_V_LO, (u_char)(tmp_int & 0xff)); + OUTB(bktr, BKTR_E_CONTROL, temp); + OUTB(bktr, BKTR_O_CONTROL, temp1); break; case BT848_GCSAT: /* get chroma saturation */ - tmp_int = (int)(bt848->sat_v_lo & 0xff); - if ( bt848->e_control & BT848_E_CONTROL_SAT_V_MSB ) + tmp_int = (int)(INB(bktr, BKTR_SAT_V_LO) & 0xff); + if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB ) tmp_int |= BIT_EIGHT_HIGH; *(int*)arg = tmp_int; break; @@ -1962,8 +1962,8 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_SVSAT: /* set chroma V saturation */ tmp_int = *(int*)arg; - temp = bt848->e_control; - temp1 = bt848->o_control; + temp = INB(bktr, BKTR_E_CONTROL); + temp1 = INB(bktr, BKTR_O_CONTROL); if ( tmp_int & BIT_EIGHT_HIGH) { temp |= BT848_E_CONTROL_SAT_V_MSB; temp1 |= BT848_O_CONTROL_SAT_V_MSB; @@ -1973,14 +1973,14 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) temp1 &= ~BT848_O_CONTROL_SAT_V_MSB; } - bt848->sat_v_lo = (u_char)(tmp_int & 0xff); - bt848->e_control = temp; - bt848->o_control = temp1; + OUTB(bktr, BKTR_SAT_V_LO, (u_char)(tmp_int & 0xff)); + OUTB(bktr, BKTR_E_CONTROL, temp); + OUTB(bktr, BKTR_O_CONTROL, temp1); break; case BT848_GVSAT: /* get chroma V saturation */ - tmp_int = (int)bt848->sat_v_lo & 0xff; - if ( bt848->e_control & BT848_E_CONTROL_SAT_V_MSB ) + tmp_int = (int)INB(bktr, BKTR_SAT_V_LO) & 0xff; + if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB ) tmp_int |= BIT_EIGHT_HIGH; *(int*)arg = tmp_int; break; @@ -1989,8 +1989,8 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_SUSAT: /* set chroma U saturation */ tmp_int = *(int*)arg; - temp = bt848->e_control; - temp1 = bt848->o_control; + temp = INB(bktr, BKTR_E_CONTROL); + temp1 = INB(bktr, BKTR_O_CONTROL); if ( tmp_int & BIT_EIGHT_HIGH ) { temp |= BT848_E_CONTROL_SAT_U_MSB; temp1 |= BT848_O_CONTROL_SAT_U_MSB; @@ -2000,14 +2000,14 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) temp1 &= ~BT848_O_CONTROL_SAT_U_MSB; } - bt848->sat_u_lo = (u_char)(tmp_int & 0xff); - bt848->e_control = temp; - bt848->o_control = temp1; + OUTB(bktr, BKTR_SAT_U_LO, (u_char)(tmp_int & 0xff)); + OUTB(bktr, BKTR_E_CONTROL, temp); + OUTB(bktr, BKTR_O_CONTROL, temp1); break; case BT848_GUSAT: /* get chroma U saturation */ - tmp_int = (int)bt848->sat_u_lo & 0xff; - if ( bt848->e_control & BT848_E_CONTROL_SAT_U_MSB ) + tmp_int = (int)INB(bktr, BKTR_SAT_U_LO) & 0xff; + if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_U_MSB ) tmp_int |= BIT_EIGHT_HIGH; *(int*)arg = tmp_int; break; @@ -2016,14 +2016,14 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_SLNOTCH: /* set luma notch */ tmp_int = (*(int *)arg & 0x7) << 5 ; - bt848->e_control &= ~0xe0 ; - bt848->o_control &= ~0xe0 ; - bt848->e_control |= tmp_int ; - bt848->o_control |= tmp_int ; + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~0xe0); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~0xe0); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | tmp_int); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | tmp_int); break; case BT848_GLNOTCH: /* get luma notch */ - *(int *)arg = (int) ( (bt848->e_control & 0xe0) >> 5) ; + *(int *)arg = (int) ( (INB(bktr, BKTR_E_CONTROL) & 0xe0) >> 5) ; break; @@ -2031,8 +2031,8 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) case BT848_SCONT: /* set contrast */ tmp_int = *(int*)arg; - temp = bt848->e_control; - temp1 = bt848->o_control; + temp = INB(bktr, BKTR_E_CONTROL); + temp1 = INB(bktr, BKTR_O_CONTROL); if ( tmp_int & BIT_EIGHT_HIGH ) { temp |= BT848_E_CONTROL_CON_MSB; temp1 |= BT848_O_CONTROL_CON_MSB; @@ -2042,14 +2042,14 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) temp1 &= ~BT848_O_CONTROL_CON_MSB; } - bt848->contrast_lo = (u_char)(tmp_int & 0xff); - bt848->e_control = temp; - bt848->o_control = temp1; + OUTB(bktr, BKTR_CONTRAST_LO, (u_char)(tmp_int & 0xff)); + OUTB(bktr, BKTR_E_CONTROL, temp); + OUTB(bktr, BKTR_O_CONTROL, temp1); break; case BT848_GCONT: /* get contrast */ - tmp_int = (int)bt848->contrast_lo & 0xff; - if ( bt848->e_control & BT848_E_CONTROL_CON_MSB ) + tmp_int = (int)INB(bktr, BKTR_CONTRAST_LO) & 0xff; + if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_CON_MSB ) tmp_int |= BIT_EIGHT_HIGH; *(int*)arg = tmp_int; break; @@ -2059,11 +2059,11 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) /* using the arg to store the on/off state so */ /* there's only one ioctl() needed to turn cbars on/off */ case BT848_SCBARS: /* set colorbar output */ - bt848->color_ctl_color_bars = 1; + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_COLOR_BARS); break; case BT848_CCBARS: /* clear colorbar output */ - bt848->color_ctl_color_bars = 0; + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) & ~(BT848_COLOR_CTL_COLOR_BARS)); break; case BT848_GAUDIO: /* get audio channel */ @@ -2105,19 +2105,19 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) /* Ioctl's for direct gpio access */ #ifdef BKTR_GPIO_ACCESS case BT848_GPIO_GET_EN: - *(int*)arg = bt848->gpio_out_en; + *(int*)arg = INL(bktr, BKTR_GPIO_OUT_EN); break; case BT848_GPIO_SET_EN: - bt848->gpio_out_en = *(int*)arg; + OUTL(bktr, BKTR_GPIO_OUT_EN, *(int*)arg); break; case BT848_GPIO_GET_DATA: - *(int*)arg = bt848->gpio_data; + *(int*)arg = INL(bktr, BKTR_GPIO_DATA); break; case BT848_GPIO_SET_DATA: - bt848->gpio_data = *(int*)arg; + OUTL(bktr, BKTR_GPIO_DATA, *(int*)arg); break; #endif /* BKTR_GPIO_ACCESS */ @@ -2184,7 +2184,7 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) default: - return common_ioctl( bktr, bt848, cmd, arg ); + return common_ioctl( bktr, cmd, arg ); } return( 0 ); @@ -2195,7 +2195,7 @@ tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr ) * common ioctls */ int -common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) +common_ioctl( bktr_ptr_t bktr, ioctl_cmd_t cmd, caddr_t arg ) { int pixfmt; unsigned int temp; @@ -2220,18 +2220,19 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) /* METEOR_INPUT_DEV_RCA: */ bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV0; - bt848->iform &= ~BT848_IFORM_MUXSEL; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) + & ~BT848_IFORM_MUXSEL); /* work around for new Hauppauge 878 cards */ if ((bktr->card.card_id == CARD_HAUPPAUGE) && (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) - bt848->iform |= BT848_IFORM_M_MUX3; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3); else - bt848->iform |= BT848_IFORM_M_MUX1; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1); - bt848->e_control &= ~BT848_E_CONTROL_COMP; - bt848->o_control &= ~BT848_O_CONTROL_COMP; + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP); set_audio( bktr, AUDIO_EXTERN ); break; @@ -2239,10 +2240,10 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) case METEOR_INPUT_DEV1: bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV1; - bt848->iform &= ~BT848_IFORM_MUXSEL; - bt848->iform |= BT848_IFORM_M_MUX0; - bt848->e_control &= ~BT848_E_CONTROL_COMP; - bt848->o_control &= ~BT848_O_CONTROL_COMP; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL); + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX0); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP); set_audio( bktr, AUDIO_TUNER ); break; @@ -2250,10 +2251,10 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) case METEOR_INPUT_DEV2: bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV2; - bt848->iform &= ~BT848_IFORM_MUXSEL; - bt848->iform |= BT848_IFORM_M_MUX2; - bt848->e_control &= ~BT848_E_CONTROL_COMP; - bt848->o_control &= ~BT848_O_CONTROL_COMP; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL); + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX2); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_O_CONTROL_COMP); set_audio( bktr, AUDIO_EXTERN ); break; @@ -2261,10 +2262,10 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) case METEOR_INPUT_DEV_SVIDEO: bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV_SVIDEO; - bt848->iform &= ~BT848_IFORM_MUXSEL; - bt848->iform |= BT848_IFORM_M_MUX2; - bt848->e_control |= BT848_E_CONTROL_COMP; - bt848->o_control |= BT848_O_CONTROL_COMP; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL); + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX2); + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | BT848_E_CONTROL_COMP); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | BT848_O_CONTROL_COMP); set_audio( bktr, AUDIO_EXTERN ); break; @@ -2275,18 +2276,18 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) (bktr->id == BROOKTREE_879) ) { bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV3; - bt848->iform &= ~BT848_IFORM_MUXSEL; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL); /* work around for new Hauppauge 878 cards */ if ((bktr->card.card_id == CARD_HAUPPAUGE) && (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) - bt848->iform |= BT848_IFORM_M_MUX1; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1); else - bt848->iform |= BT848_IFORM_M_MUX3; + OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3); - bt848->e_control &= ~BT848_E_CONTROL_COMP; - bt848->o_control &= ~BT848_O_CONTROL_COMP; + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP); + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP); set_audio( bktr, AUDIO_EXTERN ); break; @@ -2307,7 +2308,8 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) return( EINVAL ); bktr->pixfmt = *(int *)arg; - bt848->color_ctl_swap = pixfmt_swap_flags( bktr->pixfmt ); + OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0) + | pixfmt_swap_flags( bktr->pixfmt )); bktr->pixfmt_compat = FALSE; break; @@ -2359,9 +2361,8 @@ common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848, int cmd, caddr_t arg ) */ #ifdef BT848_DEBUG static int -dump_bt848( bt848_ptr_t bt848 ) +dump_bt848( bktr_ptr_t bktr ) { - volatile u_char *bt848r = (u_char *)bt848; int r[60]={ 4, 8, 0xc, 0x8c, 0x10, 0x90, 0x14, 0x94, 0x18, 0x98, 0x1c, 0x9c, 0x20, 0xa0, 0x24, 0xa4, @@ -2374,15 +2375,15 @@ dump_bt848( bt848_ptr_t bt848 ) for (i = 0; i < 40; i+=4) { printf(" Reg:value : \t%x:%x \t%x:%x \t %x:%x \t %x:%x\n", - r[i], bt848r[r[i]], - r[i+1], bt848r[r[i+1]], - r[i+2], bt848r[r[i+2]], - r[i+3], bt848r[r[i+3]]); + r[i], INL(bktr, r[i]), + r[i+1], INL(bktr, r[i+1]), + r[i+2], INL(bktr, r[i+2]), + r[i+3], INL(bktr, r[i+3]])); } - printf(" INT STAT %x \n", bt848->int_stat); - printf(" Reg INT_MASK %x \n", bt848->int_mask); - printf(" Reg GPIO_DMA_CTL %x \n", bt848->gpio_dma_ctl); + printf(" INT STAT %x \n", INL(bktr, BKTR_INT_STAT)); + printf(" Reg INT_MASK %x \n", INL(bktr, BKTR_INT_MASK)); + printf(" Reg GPIO_DMA_CTL %x \n", INW(bktr, BKTR_GPIO_DMA_CTL)); return( 0 ); } @@ -2593,7 +2594,6 @@ static void rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace ) { int i; - bt848_ptr_t bt848; volatile u_long target_buffer, buffer, target,width; volatile u_long pitch; volatile u_long *dma_prog; /* DMA prog is an array of @@ -2609,31 +2609,28 @@ rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace ) vbilines = format_params[bktr->format_params].vbi_num_lines; num_dwords = vbisamples/4; - bt848 = bktr->base; - - bt848->color_fmt = pf_int->color_fmt; - bt848->adc = SYNC_LEVEL; - bt848->vbi_pack_size = ((num_dwords)) & 0xff; - bt848->vbi_pack_del = ((num_dwords)>> 8) & 0x01; /* no hdelay */ - /* no ext frame */ + OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt); + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); + OUTB(bktr, BKTR_VBI_PACK_SIZE, ((num_dwords)) & 0xff); + OUTB(bktr, BKTR_VBI_PACK_DEL, ((num_dwords)>> 8) & 0x01); /* no hdelay */ + /* no ext frame */ - bt848->oform = 0x00; + OUTB(bktr, BKTR_OFORM, 0x00); - bt848->e_vscale_hi |= 0x40; /* set chroma comb */ - bt848->o_vscale_hi |= 0x40; - bt848->e_vscale_hi &= ~0x80; /* clear Ycomb */ - bt848->o_vscale_hi &= ~0x80; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x40); /* set chroma comb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x40); + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80); /* disable gamma correction removal */ - bt848->color_ctl_gamma = 1; - + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA); if (cols > 385 ) { - bt848->e_vtc = 0; - bt848->o_vtc = 0; + OUTB(bktr, BKTR_E_VTC, 0); + OUTB(bktr, BKTR_O_VTC, 0); } else { - bt848->e_vtc = 1; - bt848->o_vtc = 1; + OUTB(bktr, BKTR_E_VTC, 1); + OUTB(bktr, BKTR_O_VTC, 1); } bktr->capcontrol = 3 << 2 | 3; @@ -2779,37 +2776,33 @@ static void rgb_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace ) { int i; - bt848_ptr_t bt848; volatile u_long target_buffer, buffer, target,width; volatile u_long pitch; volatile u_long *dma_prog; struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; u_int Bpp = pf_int->public.Bpp; - bt848 = bktr->base; - - bt848->color_fmt = pf_int->color_fmt; - bt848->vbi_pack_size = 0; - bt848->vbi_pack_del = 0; - bt848->adc = SYNC_LEVEL; + OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt); + OUTB(bktr, BKTR_VBI_PACK_SIZE, 0); + OUTB(bktr, BKTR_VBI_PACK_DEL, 0); + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); - bt848->oform = 0x00; + OUTB(bktr, BKTR_OFORM, 0x00); - bt848->e_vscale_hi |= 0x40; /* set chroma comb */ - bt848->o_vscale_hi |= 0x40; - bt848->e_vscale_hi &= ~0x80; /* clear Ycomb */ - bt848->o_vscale_hi &= ~0x80; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x40); /* set chroma comb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x40); + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80); /* disable gamma correction removal */ - bt848->color_ctl_gamma = 1; - + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA); if (cols > 385 ) { - bt848->e_vtc = 0; - bt848->o_vtc = 0; + OUTB(bktr, BKTR_E_VTC, 0); + OUTB(bktr, BKTR_O_VTC, 0); } else { - bt848->e_vtc = 1; - bt848->o_vtc = 1; + OUTB(bktr, BKTR_E_VTC, 1); + OUTB(bktr, BKTR_O_VTC, 1); } bktr->capcontrol = 3 << 2 | 3; @@ -2949,21 +2942,17 @@ yuvpack_prog( bktr_ptr_t bktr, char i_flag, volatile unsigned int inst; volatile unsigned int inst3; volatile u_long target_buffer, buffer; - bt848_ptr_t bt848; volatile u_long *dma_prog; struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; int b; - bt848 = bktr->base; - - bt848->color_fmt = pf_int->color_fmt; + OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt); - bt848->e_scloop |= BT848_E_SCLOOP_CAGC; /* enable chroma comb */ - bt848->o_scloop |= BT848_O_SCLOOP_CAGC; + OUTB(bktr, BKTR_E_SCLOOP, INB(bktr, BKTR_E_SCLOOP) | BT848_E_SCLOOP_CAGC); /* enable chroma comb */ + OUTB(bktr, BKTR_O_SCLOOP, INB(bktr, BKTR_O_SCLOOP) | BT848_O_SCLOOP_CAGC); - bt848->color_ctl_rgb_ded = 1; - bt848->color_ctl_gamma = 1; - bt848->adc = SYNC_LEVEL; + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_RGB_DED | BT848_COLOR_CTL_GAMMA); + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); bktr->capcontrol = 1 << 6 | 1 << 4 | 1 << 2 | 3; bktr->capcontrol = 3 << 2 | 3; @@ -3067,34 +3056,31 @@ yuv422_prog( bktr_ptr_t bktr, char i_flag, int i; volatile unsigned int inst; volatile u_long target_buffer, t1, buffer; - bt848_ptr_t bt848; volatile u_long *dma_prog; struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; - bt848 = bktr->base; - - bt848->color_fmt = pf_int->color_fmt; + OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt); dma_prog = (u_long *) bktr->dma_prog; bktr->capcontrol = 1 << 6 | 1 << 4 | 3; - bt848->adc = SYNC_LEVEL; - bt848->oform = 0x00; + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); + OUTB(bktr, BKTR_OFORM, 0x00); - bt848->e_control |= BT848_E_CONTROL_LDEC; /* disable luma decimation */ - bt848->o_control |= BT848_O_CONTROL_LDEC; + OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | BT848_E_CONTROL_LDEC); /* disable luma decimation */ + OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | BT848_O_CONTROL_LDEC); - bt848->e_scloop |= BT848_O_SCLOOP_CAGC; /* chroma agc enable */ - bt848->o_scloop |= BT848_O_SCLOOP_CAGC; + OUTB(bktr, BKTR_E_SCLOOP, INB(bktr, BKTR_E_SCLOOP) | BT848_E_SCLOOP_CAGC); /* chroma agc enable */ + OUTB(bktr, BKTR_O_SCLOOP, INB(bktr, BKTR_O_SCLOOP) | BT848_O_SCLOOP_CAGC); - bt848->e_vscale_hi &= ~0x80; /* clear Ycomb */ - bt848->o_vscale_hi &= ~0x80; - bt848->e_vscale_hi |= 0x40; /* set chroma comb */ - bt848->o_vscale_hi |= 0x40; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80); + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | ~0x40); /* set chroma comb */ + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | ~0x40); /* disable gamma correction removal */ - bt848->color_ctl_gamma = 1; + OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA); /* Construct Write */ inst = OP_WRITE123 | OP_SOL | OP_EOL | (cols); @@ -3184,20 +3170,17 @@ yuv12_prog( bktr_ptr_t bktr, char i_flag, volatile unsigned int inst; volatile unsigned int inst1; volatile u_long target_buffer, t1, buffer; - bt848_ptr_t bt848; volatile u_long *dma_prog; struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ]; - bt848 = bktr->base; - - bt848->color_fmt = pf_int->color_fmt; + OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt); dma_prog = (u_long *) bktr->dma_prog; bktr->capcontrol = 1 << 6 | 1 << 4 | 3; - bt848->adc = SYNC_LEVEL; - bt848->oform = 0x0; + OUTB(bktr, BKTR_ADC, SYNC_LEVEL); + OUTB(bktr, BKTR_OFORM, 0x0); /* Construct Write */ inst = OP_WRITE123 | OP_SOL | OP_EOL | (cols); @@ -3294,7 +3277,6 @@ static void build_dma_prog( bktr_ptr_t bktr, char i_flag ) { int rows, cols, interlace; - bt848_ptr_t bt848; int tmp_int; unsigned int temp; struct format_params *fp; @@ -3302,12 +3284,11 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) fp = &format_params[bktr->format_params]; - - bt848 = bktr->base; - bt848->int_mask = ALL_INTS_DISABLED; + + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); /* disable FIFO & RISC, leave other bits alone */ - bt848->gpio_dma_ctl &= ~FIFO_RISC_ENABLED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, INW(bktr, BKTR_GPIO_DMA_CTL) & ~FIFO_RISC_ENABLED); /* set video parameters */ if (bktr->capture_area_enabled) @@ -3317,21 +3298,21 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) temp = ((quad_t ) fp->htotal* (quad_t) fp->scaled_hactive * 4096 / fp->scaled_htotal / bktr->cols) - 4096; - /* printf("HSCALE value is %d\n",temp); */ - bt848->e_hscale_lo = temp & 0xff; - bt848->o_hscale_lo = temp & 0xff; - bt848->e_hscale_hi = (temp >> 8) & 0xff; - bt848->o_hscale_hi = (temp >> 8) & 0xff; + /* printf("HSCALE value is %d\n",temp); */ + OUTB(bktr, BKTR_E_HSCALE_LO, temp & 0xff); + OUTB(bktr, BKTR_O_HSCALE_LO, temp & 0xff); + OUTB(bktr, BKTR_E_HSCALE_HI, (temp >> 8) & 0xff); + OUTB(bktr, BKTR_O_HSCALE_HI, (temp >> 8) & 0xff); /* horizontal active */ temp = bktr->cols; /* printf("HACTIVE value is %d\n",temp); */ - bt848->e_hactive_lo = temp & 0xff; - bt848->o_hactive_lo = temp & 0xff; - bt848->e_crop &= ~0x3; - bt848->o_crop &= ~0x3; - bt848->e_crop |= (temp >> 8) & 0x3; - bt848->o_crop |= (temp >> 8) & 0x3; + OUTB(bktr, BKTR_E_HACTIVE_LO, temp & 0xff); + OUTB(bktr, BKTR_O_HACTIVE_LO, temp & 0xff); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0x3); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0x3); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 8) & 0x3)); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 8) & 0x3)); /* horizontal delay */ if (bktr->capture_area_enabled) @@ -3343,12 +3324,12 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) temp = temp & 0x3fe; /* printf("HDELAY value is %d\n",temp); */ - bt848->e_delay_lo = temp & 0xff; - bt848->o_delay_lo = temp & 0xff; - bt848->e_crop &= ~0xc; - bt848->o_crop &= ~0xc; - bt848->e_crop |= (temp >> 6) & 0xc; - bt848->o_crop |= (temp >> 6) & 0xc; + OUTB(bktr, BKTR_E_DELAY_LO, temp & 0xff); + OUTB(bktr, BKTR_O_DELAY_LO, temp & 0xff); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0xc); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0xc); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 6) & 0xc)); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 6) & 0xc)); /* vertical scale */ @@ -3374,26 +3355,26 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) tmp_int &= 0x1fff; /* printf("VSCALE value is %d\n",tmp_int); */ - bt848->e_vscale_lo = tmp_int & 0xff; - bt848->o_vscale_lo = tmp_int & 0xff; - bt848->e_vscale_hi &= ~0x1f; - bt848->o_vscale_hi &= ~0x1f; - bt848->e_vscale_hi |= (tmp_int >> 8) & 0x1f; - bt848->o_vscale_hi |= (tmp_int >> 8) & 0x1f; + OUTB(bktr, BKTR_E_VSCALE_LO, tmp_int & 0xff); + OUTB(bktr, BKTR_O_VSCALE_LO, tmp_int & 0xff); + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x1f); + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x1f); + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | ((tmp_int >> 8) & 0x1f)); + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | ((tmp_int >> 8) & 0x1f)); + - /* vertical active */ if (bktr->capture_area_enabled) temp = bktr->capture_area_y_size; else temp = fp->vactive; /* printf("VACTIVE is %d\n",temp); */ - bt848->e_crop &= ~0x30; - bt848->e_crop |= (temp >> 4) & 0x30; - bt848->e_vactive_lo = temp & 0xff; - bt848->o_crop &= ~0x30; - bt848->o_crop |= (temp >> 4) & 0x30; - bt848->o_vactive_lo = temp & 0xff; + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0x30); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 4) & 0x30)); + OUTB(bktr, BKTR_E_VACTIVE_LO, temp & 0xff); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0x30); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 4) & 0x30)); + OUTB(bktr, BKTR_O_VACTIVE_LO, temp & 0xff); /* vertical delay */ if (bktr->capture_area_enabled) @@ -3401,20 +3382,20 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) else temp = fp->vdelay; /* printf("VDELAY is %d\n",temp); */ - bt848->e_crop &= ~0xC0; - bt848->e_crop |= (temp >> 2) & 0xC0; - bt848->e_vdelay_lo = temp & 0xff; - bt848->o_crop &= ~0xC0; - bt848->o_crop |= (temp >> 2) & 0xC0; - bt848->o_vdelay_lo = temp & 0xff; + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0xC0); + OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 2) & 0xC0)); + OUTB(bktr, BKTR_E_VDELAY_LO, temp & 0xff); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0xC0); + OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 2) & 0xC0)); + OUTB(bktr, BKTR_O_VDELAY_LO, temp & 0xff); /* end of video params */ if ((bktr->xtal_pll_mode == BT848_USE_PLL) && (fp->iform_xtsel==BT848_IFORM_X_XT1)) { - bt848->tgctrl=8; /* Select PLL mode */ + OUTB(bktr, BKTR_TGCTRL, BT848_TGCTRL_TGCKI_PLL); /* Select PLL mode */ } else { - bt848->tgctrl=0; /* Select Normal xtal 0/xtal 1 mode */ + OUTB(bktr, BKTR_TGCTRL, BT848_TGCTRL_TGCKI_XTAL); /* Select Normal xtal 0/xtal 1 mode */ } /* capture control */ @@ -3422,68 +3403,71 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) case 1: bktr->bktr_cap_ctl = (BT848_CAP_CTL_DITH_FRAME | BT848_CAP_CTL_EVEN); - bt848->e_vscale_hi &= ~0x20; - bt848->o_vscale_hi &= ~0x20; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x20); + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x20); interlace = 1; break; case 2: bktr->bktr_cap_ctl = (BT848_CAP_CTL_DITH_FRAME | BT848_CAP_CTL_ODD); - bt848->e_vscale_hi &= ~0x20; - bt848->o_vscale_hi &= ~0x20; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x20); + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x20); interlace = 1; break; default: bktr->bktr_cap_ctl = (BT848_CAP_CTL_DITH_FRAME | BT848_CAP_CTL_EVEN | BT848_CAP_CTL_ODD); - bt848->e_vscale_hi |= 0x20; - bt848->o_vscale_hi |= 0x20; + OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x20); + OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x20); interlace = 2; break; } - bt848->risc_strt_add = vtophys(bktr->dma_prog); + OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog)); rows = bktr->rows; cols = bktr->cols; bktr->vbiflags &= ~VBI_CAPTURE; /* default - no vbi capture */ - /* If /dev/vbi is already open, then use the rgb_vbi RISC program */ - if ( (pf_int->public.type == METEOR_PIXTYPE_RGB) - &&(bktr->vbiflags & VBI_OPEN) ) { - if (i_flag==1) bktr->bktr_cap_ctl |= BT848_CAP_CTL_VBI_EVEN; - if (i_flag==2) bktr->bktr_cap_ctl |= BT848_CAP_CTL_VBI_ODD; - if (i_flag==3) bktr->bktr_cap_ctl |= - BT848_CAP_CTL_VBI_EVEN | BT848_CAP_CTL_VBI_ODD; - bktr->bktr_cap_ctl |= + /* RGB Grabs. If /dev/vbi is already open, or we are a PAL/SECAM */ + /* user, then use the rgb_vbi RISC program. */ + /* Otherwise, use the normal rgb RISC program */ + if (pf_int->public.type == METEOR_PIXTYPE_RGB) { + if ( (bktr->vbiflags & VBI_OPEN) + ||(bktr->format_params == BT848_IFORM_F_PALBDGHI) + ||(bktr->format_params == BT848_IFORM_F_SECAM) + ){ + bktr->bktr_cap_ctl |= BT848_CAP_CTL_VBI_EVEN | BT848_CAP_CTL_VBI_ODD; - bktr->vbiflags |= VBI_CAPTURE; - rgb_vbi_prog(bktr, i_flag, cols, rows, interlace); - return; - } - - if ( pf_int->public.type == METEOR_PIXTYPE_RGB ) { - rgb_prog(bktr, i_flag, cols, rows, interlace); - return; + bktr->vbiflags |= VBI_CAPTURE; + rgb_vbi_prog(bktr, i_flag, cols, rows, interlace); + return; + } else { + rgb_prog(bktr, i_flag, cols, rows, interlace); + return; + } } if ( pf_int->public.type == METEOR_PIXTYPE_YUV ) { yuv422_prog(bktr, i_flag, cols, rows, interlace); - bt848->color_ctl_swap = pixfmt_swap_flags( bktr->pixfmt ); + OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0) + | pixfmt_swap_flags( bktr->pixfmt )); return; } if ( pf_int->public.type == METEOR_PIXTYPE_YUV_PACKED ) { yuvpack_prog(bktr, i_flag, cols, rows, interlace); - bt848->color_ctl_swap = pixfmt_swap_flags( bktr->pixfmt ); + OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0) + | pixfmt_swap_flags( bktr->pixfmt )); return; } if ( pf_int->public.type == METEOR_PIXTYPE_YUV_12 ) { yuv12_prog(bktr, i_flag, cols, rows, interlace); - bt848->color_ctl_swap = pixfmt_swap_flags( bktr->pixfmt ); + OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0) + | pixfmt_swap_flags( bktr->pixfmt )); return; } return; @@ -3501,7 +3485,6 @@ build_dma_prog( bktr_ptr_t bktr, char i_flag ) static void start_capture( bktr_ptr_t bktr, unsigned type ) { - bt848_ptr_t bt848; u_char i_flag; struct format_params *fp; @@ -3514,10 +3497,8 @@ start_capture( bktr_ptr_t bktr, unsigned type ) pixfmt_table[ bktr->pixfmt ].public.Bpp); } - bt848 = bktr->base; - - bt848->dstatus = 0; - bt848->int_stat = bt848->int_stat; + OUTB(bktr, BKTR_DSTATUS, 0); + OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT)); bktr->flags |= type; bktr->flags &= ~METEOR_WANT_MASK; @@ -3552,7 +3533,7 @@ start_capture( bktr_ptr_t bktr, unsigned type ) } - bt848->risc_strt_add = vtophys(bktr->dma_prog); + OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog)); } @@ -3563,14 +3544,11 @@ start_capture( bktr_ptr_t bktr, unsigned type ) static void set_fps( bktr_ptr_t bktr, u_short fps ) { - bt848_ptr_t bt848; struct format_params *fp; int i_flag; fp = &format_params[bktr->format_params]; - bt848 = bktr->base; - switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) { case METEOR_ONLY_EVEN_FIELDS: bktr->flags |= METEOR_WANT_EVEN; @@ -3586,16 +3564,16 @@ set_fps( bktr_ptr_t bktr, u_short fps ) break; } - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; - bt848->int_stat = ALL_INTS_CLEARED; + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED); bktr->fps = fps; - bt848->tdec = 0; + OUTB(bktr, BKTR_TDEC, 0); if (fps < fp->frame_rate) - bt848->tdec = i_flag*(fp->frame_rate - fps) & 0x3f; + OUTB(bktr, BKTR_TDEC, i_flag*(fp->frame_rate - fps) & 0x3f); else - bt848->tdec = 0; + OUTB(bktr, BKTR_TDEC, 0); return; } @@ -3848,12 +3826,9 @@ i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) { u_long x; u_long data; - bt848_ptr_t bt848; - - bt848 = bktr->base; /* clear status bits */ - bt848->int_stat = (BT848_INT_RACK | BT848_INT_I2CDONE); + OUTL(bktr, BKTR_INT_STAT, BT848_INT_RACK | BT848_INT_I2CDONE); /* build the command datum */ if (bktr->id == BROOKTREE_848 || @@ -3869,16 +3844,16 @@ i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 ) } /* write the address and data */ - bt848->i2c_data_ctl = data; + OUTL(bktr, BKTR_I2C_DATA_CTL, data); /* wait for completion */ for ( x = 0x7fffffff; x; --x ) { /* safety valve */ - if ( bt848->int_stat & BT848_INT_I2CDONE ) + if ( INL(bktr, BKTR_INT_STAT) & BT848_INT_I2CDONE ) break; } /* check for ACK */ - if ( !x || !(bt848->int_stat & BT848_INT_RACK) ) + if ( !x || !(INL(bktr, BKTR_INT_STAT) & BT848_INT_RACK) ) return( -1 ); /* return OK */ @@ -3893,12 +3868,9 @@ int i2cRead( bktr_ptr_t bktr, int addr ) { u_long x; - bt848_ptr_t bt848; - - bt848 = bktr->base; /* clear status bits */ - bt848->int_stat = (BT848_INT_RACK | BT848_INT_I2CDONE); + OUTL(bktr, BKTR_INT_STAT, BT848_INT_RACK | BT848_INT_I2CDONE); /* write the READ address */ /* The Bt878 and Bt879 differed on the treatment of i2c commands */ @@ -3906,23 +3878,23 @@ i2cRead( bktr_ptr_t bktr, int addr ) if (bktr->id == BROOKTREE_848 || bktr->id == BROOKTREE_848A || bktr->id == BROOKTREE_849A) { - bt848->i2c_data_ctl = ((addr & 0xff) << 24) | I2C_COMMAND; + OUTL(bktr, BKTR_I2C_DATA_CTL, ((addr & 0xff) << 24) | I2C_COMMAND); } else { - bt848->i2c_data_ctl = ((addr & 0xff) << 24) | I2C_COMMAND_878; + OUTL(bktr, BKTR_I2C_DATA_CTL, ((addr & 0xff) << 24) | I2C_COMMAND_878); } /* wait for completion */ for ( x = 0x7fffffff; x; --x ) { /* safety valve */ - if ( bt848->int_stat & BT848_INT_I2CDONE ) + if ( INL(bktr, BKTR_INT_STAT) & BT848_INT_I2CDONE ) break; } /* check for ACK */ - if ( !x || !(bt848->int_stat & BT848_INT_RACK) ) + if ( !x || !(INL(bktr, BKTR_INT_STAT) & BT848_INT_RACK) ) return( -1 ); /* it was a read */ - return( (bt848->i2c_data_ctl >> 8) & 0xff ); + return( (INL(bktr, BKTR_I2C_DATA_CTL) >> 8) & 0xff ); } /* The MSP34xx Audio chip require i2c bus writes of up to 5 bytes which the */ @@ -3933,55 +3905,47 @@ i2cRead( bktr_ptr_t bktr, int addr ) #define BITD 40 static void i2c_start( bktr_ptr_t bktr) { - bt848_ptr_t bt848; - bt848 = bktr->base; - - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* release data */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* release clock */ - bt848->i2c_data_ctl = 2; DELAY( BITD ); /* lower data */ - bt848->i2c_data_ctl = 0; DELAY( BITD ); /* lower clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* lower data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock */ } static void i2c_stop( bktr_ptr_t bktr) { - bt848_ptr_t bt848; - bt848 = bktr->base; - - bt848->i2c_data_ctl = 0; DELAY( BITD ); /* lower clock & data */ - bt848->i2c_data_ctl = 2; DELAY( BITD ); /* release clock */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* release data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock & data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release data */ } static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data) { int x; int status; - bt848_ptr_t bt848; - bt848 = bktr->base; /* write out the byte */ for ( x = 7; x >= 0; --x ) { if ( data & (1<<x) ) { - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* assert HI data */ - bt848->i2c_data_ctl = 3; + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ } else { - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* assert LO data */ - bt848->i2c_data_ctl = 2; + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* release clock */ } } /* look for an ACK */ - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* float data */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* strobe clock */ - status = bt848->i2c_data_ctl & 1; /* read the ACK bit */ - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* float data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ + status = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the ACK bit */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ return( status ); } @@ -3990,35 +3954,33 @@ static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ) { int x; int bit; int byte = 0; - bt848_ptr_t bt848; - bt848 = bktr->base; /* read in the byte */ - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* float data */ for ( x = 7; x >= 0; --x ) { - bt848->i2c_data_ctl = 3; + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ - bit = bt848->i2c_data_ctl & 1; /* read the data bit */ + bit = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the data bit */ if ( bit ) byte |= (1<<x); - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ } /* After reading the byte, send an ACK */ /* (unless that was the last byte, for which we send a NAK */ if (last) { /* send NAK - same a writing a 1 */ - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* set data bit */ - bt848->i2c_data_ctl = 3; + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ } else { /* send ACK - same as writing a 0 */ - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* set data bit */ - bt848->i2c_data_ctl = 2; + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* release clock */ } @@ -4134,48 +4096,45 @@ static int i2cProbe( bktr_ptr_t bktr, int addr ) { int x, status; - bt848_ptr_t bt848; - - bt848 = bktr->base; /* the START */ #if defined( EXTRA_START ) - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* release data */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release clock */ #endif /* EXTRA_START */ - bt848->i2c_data_ctl = 2; DELAY( BITD ); /* lower data */ - bt848->i2c_data_ctl = 0; DELAY( BITD ); /* lower clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* lower data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock */ /* write addr */ for ( x = 7; x >= 0; --x ) { if ( addr & (1<<x) ) { - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* assert HI data */ - bt848->i2c_data_ctl = 3; + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 1; + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ } else { - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0 ; DELAY( BITD ); /* assert LO data */ - bt848->i2c_data_ctl = 2; + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* strobe clock */ - bt848->i2c_data_ctl = 0; + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* release clock */ } } /* look for an ACK */ - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* float data */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* strobe clock */ - status = bt848->i2c_data_ctl & 1; /* read the ACK bit */ - bt848->i2c_data_ctl = 1; DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* float data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */ + status = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the ACK bit */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */ /* the STOP */ - bt848->i2c_data_ctl = 0; DELAY( BITD ); /* lower clock & data */ - bt848->i2c_data_ctl = 2; DELAY( BITD ); /* release clock */ - bt848->i2c_data_ctl = 3; DELAY( BITD ); /* release data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock & data */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* release clock */ + OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release data */ return( status ); } diff --git a/sys/dev/bktr/bktr_core.h b/sys/dev/bktr/bktr_core.h index 2af509a..790d718 100644 --- a/sys/dev/bktr/bktr_core.h +++ b/sys/dev/bktr/bktr_core.h @@ -79,13 +79,13 @@ int video_open( bktr_ptr_t bktr ); int video_close( bktr_ptr_t bktr ); int video_read( bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio ); int video_ioctl( bktr_ptr_t bktr, int unit, - int cmd, caddr_t arg, struct proc* pr ); + ioctl_cmd_t cmd, caddr_t arg, struct proc* pr ); int tuner_open( bktr_ptr_t bktr ); int tuner_close( bktr_ptr_t bktr ); int tuner_ioctl( bktr_ptr_t bktr, int unit, - int cmd, caddr_t arg, struct proc* pr ); + ioctl_cmd_t cmd, caddr_t arg, struct proc* pr ); int vbi_open( bktr_ptr_t bktr ); int vbi_close( bktr_ptr_t bktr ); diff --git a/sys/dev/bktr/bktr_i2c.c b/sys/dev/bktr/bktr_i2c.c index 039d008..2021f9e 100644 --- a/sys/dev/bktr/bktr_i2c.c +++ b/sys/dev/bktr/bktr_i2c.c @@ -48,6 +48,12 @@ #include <machine/clock.h> +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* for bus space */ +#include <machine/bus.h> +#include <sys/bus.h> +#endif + #include <pci/pcivar.h> #include <pci/pcireg.h> #include <machine/ioctl_meteor.h> @@ -73,7 +79,8 @@ static int bti2c_debug = 0; struct bti2c_softc { - bt848_ptr_t base; + bus_space_tag_t memt; /* Bus space register access */ + bus_space_handle_t memh; /* Bus space register access */ int iic_owned; /* 1 if we own the iicbus */ int smb_owned; /* 1 if we own the smbbus */ @@ -83,7 +90,8 @@ struct bti2c_softc { }; struct bt_data { - bt848_ptr_t base; + bus_space_tag_t memt; + bus_space_handle_t memh; }; struct bt_data btdata[NBKTR]; @@ -144,16 +152,17 @@ static driver_t bti2c_driver = { #endif /* - * Call this to pass the base address of the bktr device to the + * Call this to pass the address of the bktr device to the * bti2c_i2c layer and initialize all the I2C bus architecture */ int -bt848_i2c_attach(int unit, bt848_ptr_t base, struct bktr_i2c_softc *i2c_sc) +bt848_i2c_attach(int unit, struct bktr_softc * bktr, struct bktr_i2c_softc *i2c_sc) { device_t interface; device_t bitbang; - btdata[unit].base = base; + btdata[unit].memh = bktr->memh; + btdata[unit].memt = bktr->memt; /* XXX add the I2C interface to the root_bus until pcibus is ready */ #if (__FreeBSD_version < 400000) @@ -205,7 +214,8 @@ bti2c_attach(device_t dev) /* XXX should use ivars with pcibus or pcibus methods to access * onboard memory */ - sc->base = btdata[device_get_unit(dev)].base; + sc->memh = btdata[device_get_unit(dev)].memh; + sc->memt = btdata[device_get_unit(dev)].memt; return (0); } @@ -297,11 +307,8 @@ static void bti2c_iic_setlines(device_t dev, int ctrl, int data) { struct bti2c_softc *sc = (struct bti2c_softc *)device_get_softc(dev); - bt848_ptr_t bti2c; - bti2c = sc->base; - - bti2c->i2c_data_ctl = (ctrl << 1) | data; + OUTL(sc, BKTR_I2C_DATA_CTL, (ctrl << 1) | data);; DELAY(I2C_DELAY); return; @@ -311,36 +318,33 @@ static int bti2c_iic_getdataline(device_t dev) { struct bti2c_softc *sc = (struct bti2c_softc *)device_get_softc(dev); - bt848_ptr_t bti2c; - - bti2c = sc->base; - return (bti2c->i2c_data_ctl & 0x1); + return ( INL(sc,BKTR_I2C_DATA_CTL) & 0x1); } static int -bti2c_write(bt848_ptr_t bti2c, u_long data) +bti2c_write(struct bti2c_softc* bti2c_sc, u_long data) { u_long x; /* clear status bits */ - bti2c->int_stat = (BT848_INT_RACK | BT848_INT_I2CDONE); + OUTL(bti2c_sc, BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE)); BTI2C_DEBUG(printf("w%lx", data)); /* write the address and data */ - bti2c->i2c_data_ctl = data; + OUTL(bti2c_sc, BKTR_I2C_DATA_CTL, data); /* wait for completion */ for ( x = 0x7fffffff; x; --x ) { /* safety valve */ - if ( bti2c->int_stat & BT848_INT_I2CDONE ) + if ( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_I2CDONE ) break; } /* check for ACK */ - if ( !x || !(bti2c->int_stat & BT848_INT_RACK) ) { + if ( !x || !( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_RACK) ) { BTI2C_DEBUG(printf("%c%c", (!x)?'+':'-', - (!(bti2c->int_stat & BT848_INT_RACK))?'+':'-')); + (!( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-')); return (SMB_ENOACK); } BTI2C_DEBUG(printf("+")); @@ -357,7 +361,7 @@ bti2c_smb_writeb(device_t dev, u_char slave, char cmd, char byte) data = ((slave & 0xff) << 24) | ((byte & 0xff) << 16) | (u_char)cmd; - return (bti2c_write(sc->base, data)); + return (bti2c_write(sc, data)); } /* @@ -377,7 +381,7 @@ bti2c_smb_writew(device_t dev, u_char slave, char cmd, short word) data = ((slave & 0xff) << 24) | ((low & 0xff) << 16) | ((high & 0xff) << 8) | BT848_DATA_CTL_I2CW3B | (u_char)cmd; - return (bti2c_write(sc->base, data)); + return (bti2c_write(sc, data)); } /* @@ -387,32 +391,29 @@ static int bti2c_smb_readb(device_t dev, u_char slave, char cmd, char *byte) { struct bti2c_softc *sc = (struct bti2c_softc *)device_get_softc(dev); - bt848_ptr_t bti2c; u_long x; - bti2c = sc->base; - /* clear status bits */ - bti2c->int_stat = (BT848_INT_RACK | BT848_INT_I2CDONE); + OUTL(sc,BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE)); - bti2c->i2c_data_ctl = ((slave & 0xff) << 24) | (u_char)cmd; + OUTL(sc,BKTR_I2C_DATA_CTL, ((slave & 0xff) << 24) | (u_char)cmd);; BTI2C_DEBUG(printf("r%lx/", (u_long)(((slave & 0xff) << 24) | (u_char)cmd))); /* wait for completion */ for ( x = 0x7fffffff; x; --x ) { /* safety valve */ - if ( bti2c->int_stat & BT848_INT_I2CDONE ) + if ( INL(sc,BKTR_INT_STAT) & BT848_INT_I2CDONE ) break; } /* check for ACK */ - if ( !x || !(bti2c->int_stat & BT848_INT_RACK) ) { + if ( !x || !(INL(sc,BKTR_INT_STAT) & BT848_INT_RACK) ) { BTI2C_DEBUG(printf("r%c%c", (!x)?'+':'-', - (!(bti2c->int_stat & BT848_INT_RACK))?'+':'-')); + (!( INL(sc,BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-')); return (SMB_ENOACK); } - *byte = (char)((bti2c->i2c_data_ctl >> 8) & 0xff); + *byte = (char)((INL(sc,BKTR_I2C_DATA_CTL) >> 8) & 0xff); BTI2C_DEBUG(printf("r%x+", *byte)); return (0); diff --git a/sys/dev/bktr/bktr_i2c.h b/sys/dev/bktr/bktr_i2c.h index 075e988..f687e4c 100644 --- a/sys/dev/bktr/bktr_i2c.h +++ b/sys/dev/bktr/bktr_i2c.h @@ -29,6 +29,6 @@ #ifndef _BT848_I2C_H #define _BT848_I2C_H -extern int bt848_i2c_attach(int, bt848_ptr_t, struct bktr_i2c_softc *); +extern int bt848_i2c_attach(int, struct bktr_softc *bktr, struct bktr_i2c_softc *); #endif diff --git a/sys/dev/bktr/bktr_os.c b/sys/dev/bktr/bktr_os.c index af7948c..12d0c29 100644 --- a/sys/dev/bktr/bktr_os.c +++ b/sys/dev/bktr/bktr_os.c @@ -50,14 +50,10 @@ #ifdef __FreeBSD__ #include "bktr.h" -#include "opt_bktr.h" #include "opt_devfs.h" #endif /* __FreeBSD__ */ -#if defined(__NetBSD__) || defined(__OpenBSD__) -#include "bktr.h" -#include "pci.h" -#endif /* __NetBSD__ || __OpenBSD__ */ +#include "opt_bktr.h" /* include any kernel config options */ #define FIFO_RISC_DISABLED 0 #define ALL_INTS_DISABLED 0 @@ -93,18 +89,30 @@ #include <sys/bus.h> /* used by smbus and newbus */ #endif +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* used by bus space */ +#include <machine/bus.h> /* used by bus space and newbus */ +#include <sys/bus.h> +#endif + #if (__FreeBSD_version >=400000) -#include <machine/bus.h> /* used by newbus */ #include <sys/rman.h> /* used by newbus */ #include <machine/resource.h> /* used by newbus */ #endif + #include <machine/clock.h> /* for DELAY */ #include <pci/pcivar.h> #include <pci/pcireg.h> +#endif +#ifdef __NetBSD__ +#include <dev/ic/ioctl_meteor.h> /* NetBSD location for .h files */ +#include <dev/ic/ioctl_bt848.h> +#else /* Traditional location for .h files */ #include <machine/ioctl_meteor.h> #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ +#endif #include <dev/bktr/bktr_reg.h> #include <dev/bktr/bktr_tuner.h> #include <dev/bktr/bktr_card.h> @@ -112,6 +120,7 @@ #include <dev/bktr/bktr_core.h> #include <dev/bktr/bktr_os.h> +#if defined(__FreeBSD__) #if (NSMBUS > 0) #include <dev/bktr/bktr_i2c.h> #endif @@ -121,22 +130,19 @@ int bt848_card = -1; int bt848_tuner = -1; int bt848_reverse_mute = -1; int bt848_format = -1; +int bt848_slow_msp_audio = -1; SYSCTL_NODE(_hw, OID_AUTO, bt848, CTLFLAG_RW, 0, "Bt848 Driver mgmt"); SYSCTL_INT(_hw_bt848, OID_AUTO, card, CTLFLAG_RW, &bt848_card, -1, ""); SYSCTL_INT(_hw_bt848, OID_AUTO, tuner, CTLFLAG_RW, &bt848_tuner, -1, ""); SYSCTL_INT(_hw_bt848, OID_AUTO, reverse_mute, CTLFLAG_RW, &bt848_reverse_mute, -1, ""); SYSCTL_INT(_hw_bt848, OID_AUTO, format, CTLFLAG_RW, &bt848_format, -1, ""); - -#if (__FreeBSD_version >= 300000) - typedef u_long ioctl_cmd_t; +SYSCTL_INT(_hw_bt848, OID_AUTO, slow_msp_audio, CTLFLAG_RW, &bt848_slow_msp_audio, -1, ""); #endif #if (__FreeBSD__ == 2) -typedef int ioctl_cmd_t; #define PCIR_REVID PCI_CLASS_REG #endif -#endif /* __FreeBSD__ */ /****************/ @@ -150,6 +156,21 @@ typedef int ioctl_cmd_t; /* *** OpenBSD/NetBSD *** */ /**************************/ #if defined(__NetBSD__) || defined(__OpenBSD__) +#include <sys/device.h> +#include <dev/pci/pcivar.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> + +static int bootverbose = 1; + + +#define BKTR_DEBUG +#ifdef BKTR_DEBUG +int bktr_debug = 0; +#define DPR(x) (bktr_debug ? printf x : 0) +#else +#define DPR(x) +#endif #endif /* __NetBSD__ || __OpenBSD__ */ @@ -247,7 +268,6 @@ bktr_probe( device_t dev ) static int bktr_attach( device_t dev ) { - bt848_ptr_t bt848; u_long latency; u_long fun; u_long val; @@ -282,14 +302,15 @@ bktr_attach( device_t dev ) error = ENXIO; goto fail; } - bktr->base = rman_get_virtual(bktr->res_mem); /* XXX use bus_space */ + bktr->memt = rman_get_bustag(bktr->res_mem); + bktr->memh = rman_get_bushandle(bktr->res_mem); + /* * Disable the brooktree device */ - bt848 = bktr->base; - bt848->int_mask = ALL_INTS_DISABLED; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); #ifdef BROOKTREE_IRQ /* from the configuration file */ @@ -341,7 +362,7 @@ bktr_attach( device_t dev ) /* XXX call bt848_i2c dependent attach() routine */ #if (NSMBUS > 0) - if (bt848_i2c_attach(unit, bktr->base, &bktr->i2c_sc)) + if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc)) printf("bktr%d: i2c_attach: can't attach\n", unit); #endif @@ -395,12 +416,10 @@ static int bktr_detach( device_t dev ) { struct bktr_softc *bktr = device_get_softc(dev); - bt848_ptr_t bt848; /* Disable the brooktree device */ - bt848 = bktr->base; - bt848->int_mask = ALL_INTS_DISABLED; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); /* FIXME - Free memory for RISC programs, grab buffer, vbi buffers */ @@ -421,12 +440,10 @@ static int bktr_shutdown( device_t dev ) { struct bktr_softc *bktr = device_get_softc(dev); - bt848_ptr_t bt848; /* Disable the brooktree device */ - bt848 = bktr->base; - bt848->int_mask = ALL_INTS_DISABLED; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); return 0; } @@ -513,10 +530,14 @@ bktr_open( dev_t dev, int flags, int fmt, struct proc *p ) } if (bt848_reverse_mute != -1) { - if (((bt848_reverse_mute >> 8) == unit ) && - ((bt848_reverse_mute & 0xff) < Bt848_MAX_TUNER) ) { + if ((bt848_reverse_mute >> 8) == unit ) { bktr->reverse_mute = bt848_reverse_mute & 0xff; - bt848_reverse_mute = -1; + } + } + + if (bt848_slow_msp_audio != -1) { + if ((bt848_slow_msp_audio >> 8) == unit ) { + bktr->slow_msp_audio = (bt848_slow_msp_audio & 0xff); } } @@ -806,10 +827,10 @@ static void bktr_attach( pcici_t tag, int unit ) { bktr_ptr_t bktr; - bt848_ptr_t bt848; u_long latency; u_long fun; unsigned int rev; + unsigned long base; #ifdef BROOKTREE_IRQ u_long old_irq, new_irq; #endif @@ -837,15 +858,18 @@ bktr_attach( pcici_t tag, int unit ) /* * Map control/status registers */ - pci_map_mem( tag, PCI_MAP_REG_START, (vm_offset_t *) &bktr->base, + pci_map_mem( tag, PCI_MAP_REG_START, (vm_offset_t *) &base, &bktr->phys_base ); +#if (__FreeBSD_version >= 300000) + bktr->memt = I386_BUS_SPACE_MEM; /* XXX should use proper bus space */ + bktr->memh = (bus_space_handle_t)base; /* XXX functions here */ +#endif /* * Disable the brooktree device */ - bt848 = bktr->base; - bt848->int_mask = ALL_INTS_DISABLED; - bt848->gpio_dma_ctl = FIFO_RISC_DISABLED; + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); #ifdef BROOKTREE_IRQ /* from the configuration file */ old_irq = pci_conf_read(tag, PCI_INTERRUPT_REG); @@ -881,7 +905,7 @@ bktr_attach( pcici_t tag, int unit ) /* XXX call bt848_i2c dependent attach() routine */ #if (NSMBUS > 0) - if (bt848_i2c_attach(unit, bktr->base, &bktr->i2c_sc)) + if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc)) printf("bktr%d: i2c_attach: can't attach\n", unit); #endif @@ -1005,13 +1029,16 @@ bktr_open( dev_t dev, int flags, int fmt, struct proc *p ) } if (bt848_reverse_mute != -1) { - if (((bt848_reverse_mute >> 8) == unit ) && - ((bt848_reverse_mute & 0xff) < Bt848_MAX_TUNER) ) { + if ((bt848_reverse_mute >> 8) == unit ) { bktr->reverse_mute = bt848_reverse_mute & 0xff; - bt848_reverse_mute = -1; } } + if (bt848_slow_msp_audio != -1) { + if ((bt848_slow_msp_audio >> 8) == unit ) { + bktr->slow_msp_audio = (bt848_slow_msp_audio & 0xff); + } + } switch ( FUNCTION( minor(dev) ) ) { case VIDEO_DEV: @@ -1192,5 +1219,485 @@ int bktr_poll( dev_t dev, int events, struct proc *p) /* *** OpenBSD / NetBSD *** */ /*****************************/ #if defined(__NetBSD__) || defined(__OpenBSD__) -#endif /* __NetBSD__ || __OpenBSD__ */ + +#define IPL_VIDEO IPL_BIO /* XXX */ + +static int bktr_intr(void *arg) { return common_bktr_intr(arg); } + +#define bktr_open bktropen +#define bktr_close bktrclose +#define bktr_read bktrread +#define bktr_write bktrwrite +#define bktr_ioctl bktrioctl +#define bktr_mmap bktrmmap + +int bktr_open __P((dev_t, int, int, struct proc *)); +int bktr_close __P((dev_t, int, int, struct proc *)); +int bktr_read __P((dev_t, struct uio *, int)); +int bktr_write __P((dev_t, struct uio *, int)); +int bktr_ioctl __P((dev_t, ioctl_cmd_t, caddr_t, int, struct proc*)); +int bktr_mmap __P((dev_t, vm_offset_t, int)); + +vm_offset_t vm_page_alloc_contig(vm_offset_t, vm_offset_t, + vm_offset_t, vm_offset_t); + +#if defined(__BROKEN_INDIRECT_CONFIG) || defined(__OpenBSD__) +static int bktr_probe __P((struct device *, void *, void *)); +#else +static int bktr_probe __P((struct device *, struct cfdata *, void *)); +#endif +static void bktr_attach __P((struct device *, struct device *, void *)); + +struct cfattach bktr_ca = { + sizeof(struct bktr_softc), bktr_probe, bktr_attach +}; + +#if defined(__NetBSD__) +extern struct cfdriver bktr_cd; +#else +struct cfdriver bktr_cd = { + NULL, "bktr", DV_DULL +}; +#endif + +int bktr_probe(parent, match, aux) + struct device *parent; +#if defined(__BROKEN_INDIRECT_CONFIG) || defined(__OpenBSD__) + void *match; +#else + struct cfdata *match; +#endif + void *aux; +{ + struct pci_attach_args *pa = aux; + + if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_BROOKTREE && + (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT848 || + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT849 || + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT878 || + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT879)) + return 1; + + return 0; +} + + +/* + * the attach routine. + */ +static void +bktr_attach __P((struct device *parent, struct device *self, void *aux)) +{ + bktr_ptr_t bktr; + u_long latency; + u_long fun; + unsigned int rev; + +#if defined(__OpenBSD__) + struct pci_attach_args *pa = aux; + pci_chipset_tag_t pc = pa->pa_pc; + + pci_intr_handle_t ih; + const char *intrstr; + int retval; + int unit; + + bktr = (bktr_ptr_t)self; + unit = bktr->bktr_dev.dv_unit; + + bktr->pc = pa->pa_pc; + bktr->tag = pa->pa_tag; + bktr->dmat = pa->pa_dmat; + + /* + * map memory + */ + bktr->memt = pa->pa_memt; + retval = pci_mem_find(pc, pa->pa_tag, PCI_MAPREG_START, + &bktr->phys_base, &bktr->obmemsz, NULL); + if (!retval) + retval = bus_space_map(pa->pa_memt, bktr->phys_base, + bktr->obmemsz, 0, &bktr->memh); + if (retval) { + printf(": couldn't map memory\n"); + return; + } + + + /* + * map interrupt + */ + if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, + pa->pa_intrline, &ih)) { + printf(": couldn't map interrupt\n"); + return; + } + intrstr = pci_intr_string(pa->pa_pc, ih); + + bktr->ih = pci_intr_establish(pa->pa_pc, ih, IPL_VIDEO, + bktr_intr, bktr, bktr->bktr_dev.dv_xname); + if (bktr->ih == NULL) { + printf(": couldn't establish interrupt"); + if (intrstr != NULL) + printf(" at %s", intrstr); + printf("\n"); + return; + } + + if (intrstr != NULL) + printf(": %s\n", intrstr); +#endif /* __OpenBSD__ */ + +#if defined(__NetBSD__) + struct pci_attach_args *pa = aux; + pci_intr_handle_t ih; + const char *intrstr; + int retval; + int unit; + + bktr = (bktr_ptr_t)self; + unit = bktr->bktr_dev.dv_unit; + bktr->dmat = pa->pa_dmat; + + printf("\n"); + + /* + * map memory + */ + retval = pci_mapreg_map(pa, PCI_MAPREG_START, + PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, + &bktr->memt, &bktr->memh, &bktr->phys_base, + &bktr->obmemsz); + DPR(("pci_mapreg_map: memt %x, memh %x, base %x, size %x\n", + bktr->memt, (u_int)bktr->memh, + (u_int)bktr->phys_base, (u_int)bktr->obmemsz)); + if (retval) { + printf("%s: couldn't map memory\n", bktr->bktr_dev.dv_xname); + return; + } + + /* + * Disable the brooktree device + */ + OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED); + OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED); + + /* + * map interrupt + */ + if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, + pa->pa_intrline, &ih)) { + printf("%s: couldn't map interrupt\n", bktr->bktr_dev.dv_xname); + return; + } + intrstr = pci_intr_string(pa->pa_pc, ih); + bktr->ih = pci_intr_establish(pa->pa_pc, ih, IPL_VIDEO, + bktr_intr, bktr); + if (bktr->ih == NULL) { + printf("%s: couldn't establish interrupt", + bktr->bktr_dev.dv_xname); + if (intrstr != NULL) + printf(" at %s", intrstr); + printf("\n"); + return; + } + if (intrstr != NULL) + printf("%s: interrupting at %s\n", bktr->bktr_dev.dv_xname, + intrstr); +#endif /* __NetBSD__ */ + +/* + * PCI latency timer. 32 is a good value for 4 bus mastering slots, if + * you have more than four, then 16 would probably be a better value. + */ +#ifndef BROOKTREE_DEF_LATENCY_VALUE +#define BROOKTREE_DEF_LATENCY_VALUE 10 +#endif + latency = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_LATENCY_TIMER); + latency = (latency >> 8) & 0xff; + + if ( !latency ) { + if ( bootverbose ) { + printf("%s: PCI bus latency was 0 changing to %d", + bktr->bktr_dev.dv_xname, + BROOKTREE_DEF_LATENCY_VALUE); + } + latency = BROOKTREE_DEF_LATENCY_VALUE; + pci_conf_write(pa->pa_pc, pa->pa_tag, + PCI_LATENCY_TIMER, latency<<8); + } + + + /* Enabled Bus Master and Memory Mapping */ + fun = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, fun | 2); + fun = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, fun | 4); + + /* read the pci id and determine the card type */ + fun = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_ID_REG); + rev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0x000000ff; + + common_bktr_attach( bktr, unit, fun, rev ); +} + + +/* + * Special Memory Allocation + */ +vm_offset_t +get_bktr_mem(bktr, dmapp, size) + bktr_ptr_t bktr; + bus_dmamap_t *dmapp; + unsigned int size; +{ + bus_dma_tag_t dmat = bktr->dmat; + bus_dma_segment_t seg; + bus_size_t align; + int rseg; + caddr_t kva; + + /* + * Allocate a DMA area + */ + align = 1 << 24; + if (bus_dmamem_alloc(dmat, size, align, 0, &seg, 1, + &rseg, BUS_DMA_NOWAIT)) { + align = PAGE_SIZE; + if (bus_dmamem_alloc(dmat, size, align, 0, &seg, 1, + &rseg, BUS_DMA_NOWAIT)) { + printf("bktr%d: Unable to dmamem_alloc of %d bytes\n", + bktr->bktr_dev.dv_unit, size); + return 0; + } + } + if (bus_dmamem_map(dmat, &seg, rseg, size, + &kva, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) { + printf("bktr%d: Unable to dmamem_map of %d bytes\n", + bktr->bktr_dev.dv_unit, size); + bus_dmamem_free(dmat, &seg, rseg); + return 0; + } +#ifdef __OpenBSD__ + bktr->dm_mapsize = size; +#endif + /* + * Create and locd the DMA map for the DMA area + */ + if (bus_dmamap_create(dmat, size, 1, size, 0, BUS_DMA_NOWAIT, dmapp)) { + printf("bktr%d: Unable to dmamap_create of %d bytes\n", + bktr->bktr_dev.dv_unit, size); + bus_dmamem_unmap(dmat, kva, size); + bus_dmamem_free(dmat, &seg, rseg); + return 0; + } + if (bus_dmamap_load(dmat, *dmapp, kva, size, NULL, BUS_DMA_NOWAIT)) { + printf("bktr%d: Unable to dmamap_load of %d bytes\n", + bktr->bktr_dev.dv_unit, size); + bus_dmamem_unmap(dmat, kva, size); + bus_dmamem_free(dmat, &seg, rseg); + bus_dmamap_destroy(dmat, *dmapp); + return 0; + } + return (vm_offset_t)kva; +} + +void +free_bktr_mem(bktr, dmap, kva) + bktr_ptr_t bktr; + bus_dmamap_t dmap; + vm_offset_t kva; +{ + bus_dma_tag_t dmat = bktr->dmat; + +#ifdef __NetBSD__ + bus_dmamem_unmap(dmat, (caddr_t)kva, dmap->dm_mapsize); +#else + bus_dmamem_unmap(dmat, (caddr_t)kva, bktr->dm_mapsize); +#endif + bus_dmamem_free(dmat, dmap->dm_segs, 1); + bus_dmamap_destroy(dmat, dmap); +} + + +/*--------------------------------------------------------- +** +** BrookTree 848 character device driver routines +** +**--------------------------------------------------------- +*/ + + +#define VIDEO_DEV 0x00 +#define TUNER_DEV 0x01 +#define VBI_DEV 0x02 + +#define UNIT(x) ((x) & 0x0f) +#define FUNCTION(x) ((x >> 4) & 0x0f) + +/* + * + */ +int +bktr_open( dev_t dev, int flags, int fmt, struct proc *p ) +{ + bktr_ptr_t bktr; + int unit; + + unit = UNIT( minor(dev) ); + + /* unit out of range */ + if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL)) + return( ENXIO ); + + bktr = bktr_cd.cd_devs[unit]; + + + if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */ + return( ENXIO ); + + switch ( FUNCTION( minor(dev) ) ) { + case VIDEO_DEV: + return( video_open( bktr ) ); + case TUNER_DEV: + return( tuner_open( bktr ) ); + case VBI_DEV: + return( vbi_open( bktr ) ); + } + + return( ENXIO ); +} + + +/* + * + */ +int +bktr_close( dev_t dev, int flags, int fmt, struct proc *p ) +{ + bktr_ptr_t bktr; + int unit; + + unit = UNIT( minor(dev) ); + + /* unit out of range */ + if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL)) + return( ENXIO ); + + bktr = bktr_cd.cd_devs[unit]; + + switch ( FUNCTION( minor(dev) ) ) { + case VIDEO_DEV: + return( video_close( bktr ) ); + case TUNER_DEV: + return( tuner_close( bktr ) ); + case VBI_DEV: + return( vbi_close( bktr ) ); + } + + return( ENXIO ); +} + +/* + * + */ +int +bktr_read( dev_t dev, struct uio *uio, int ioflag ) +{ + bktr_ptr_t bktr; + int unit; + + unit = UNIT(minor(dev)); + + /* unit out of range */ + if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL)) + return( ENXIO ); + + bktr = bktr_cd.cd_devs[unit]; + + switch ( FUNCTION( minor(dev) ) ) { + case VIDEO_DEV: + return( video_read( bktr, unit, dev, uio ) ); + case VBI_DEV: + return( vbi_read( bktr, uio, ioflag ) ); + } + + return( ENXIO ); +} + + +/* + * + */ +int +bktr_write( dev_t dev, struct uio *uio, int ioflag ) +{ + /* operation not supported */ + return( EOPNOTSUPP ); +} + +/* + * + */ +int +bktr_ioctl( dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct proc* pr ) +{ + bktr_ptr_t bktr; + int unit; + + unit = UNIT(minor(dev)); + + /* unit out of range */ + if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL)) + return( ENXIO ); + + bktr = bktr_cd.cd_devs[unit]; + + if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */ + return( ENOMEM ); + + switch ( FUNCTION( minor(dev) ) ) { + case VIDEO_DEV: + return( video_ioctl( bktr, unit, cmd, arg, pr ) ); + case TUNER_DEV: + return( tuner_ioctl( bktr, unit, cmd, arg, pr ) ); + } + + return( ENXIO ); +} + +/* + * + */ +int +bktr_mmap( dev_t dev, vm_offset_t offset, int nprot ) +{ + int unit; + bktr_ptr_t bktr; + + unit = UNIT(minor(dev)); + + /* unit out of range */ + if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL)) + return( -1 ); + if (FUNCTION(minor(dev)) > 0) + return( -1 ); + + bktr = bktr_cd.cd_devs[unit]; + + if (offset < 0) + return( -1 ); + + if (offset >= bktr->alloc_pages * PAGE_SIZE) + return( -1 ); + +#ifdef __NetBSD__ + return (bus_dmamem_mmap(bktr->dmat, bktr->dm_mem->dm_segs, 1, + offset, nprot, BUS_DMA_WAITOK)); +#else + return( i386_btop(vtophys(bktr->bigbuf) + offset) ); +#endif +} + +#endif /* __NetBSD__ || __OpenBSD__ */ diff --git a/sys/dev/bktr/bktr_reg.h b/sys/dev/bktr/bktr_reg.h index d77c771..31fd356 100644 --- a/sys/dev/bktr/bktr_reg.h +++ b/sys/dev/bktr/bktr_reg.h @@ -35,12 +35,20 @@ */ #ifdef __FreeBSD__ -#if (__FreeBSD_version >= 310000) -#include <sys/bus.h> -#include "smbus.h" +# if (__FreeBSD_version >= 310000) +# include <sys/bus.h> +# include "smbus.h" +# else +# define NSMBUS 0 /* FreeBSD before 3.1 does not have SMBUS */ +# endif #else -#define NSMBUS 0 +# define NSMBUS 0 /* Non FreeBSD systems do not have SMBUS */ #endif + +#ifdef __NetBSD__ +#include <machine/bus.h> /* struct device */ +#include <sys/device.h> +#include <sys/select.h> /* struct selinfo */ #endif #ifndef PCI_LATENCY_TIMER @@ -172,7 +180,7 @@ struct bt848_registers { #define BT848_O_CONTROL_CON_MSB (1<<2) #define BT848_O_CONTROL_SAT_U_MSB (1<<1) #define BT848_O_CONTROL_SAT_V_MSB (1<<0) - u_char fillter1[16]; + u_char fillter4[16]; BTBYTE (o_scloop); /* c0, c1,c2,c3 */ #define BT848_O_SCLOOP_RSVD1 (1<<7) #define BT848_O_SCLOOP_CAGC (1<<6) @@ -197,6 +205,10 @@ struct bt848_registers { bregister_t color_ctl_rgb_ded :1; bregister_t color_ctl_color_bars :1; bregister_t color_ctl_ext_frmrate :1; +#define BT848_COLOR_CTL_GAMMA (1<<4) +#define BT848_COLOR_CTL_RGB_DED (1<<5) +#define BT848_COLOR_CTL_COLOR_BARS (1<<6) +#define BT848_COLOR_CTL_EXT_FRMRATE (1<<7) int :24; /* d9,da,db */ BTBYTE (cap_ctl); /* dc, dd,de,df */ #define BT848_CAP_CTL_DITH_FRAME (1<<4) @@ -270,17 +282,12 @@ struct bt848_registers { BTLONG (gpio_data); /* 200, 201,202,203 */ /* really 24 bits */ }; -typedef volatile struct bt848_registers* bt848_ptr_t; - - -#if 0 -/* force people to be aware of the new struct */ #define BKTR_DSTATUS 0x000 #define BKTR_IFORM 0x004 #define BKTR_TDEC 0x008 -#define BKTR_EVEN_CROP 0x00C -#define BKTR_ODD_CROP 0x08C +#define BKTR_E_CROP 0x00C +#define BKTR_O_CROP 0x08C #define BKTR_E_VDELAY_LO 0x010 #define BKTR_O_VDELAY_LO 0x090 #define BKTR_E_VACTIVE_LO 0x014 @@ -327,9 +334,11 @@ typedef volatile struct bt848_registers* bt848_ptr_t; #define BKTR_GPIO_OUT_EN 0x118 #define BKTR_GPIO_REG_INP 0x11C #define BKTR_GPIO_DATA 0x200 -#define BKTR_I2C_CONTROL 0x110 - -#endif /* 0 */ +#define BKTR_I2C_DATA_CTL 0x110 +#define BKTR_TGCTRL 0x084 +#define BKTR_PLL_F_LO 0x0F0 +#define BKTR_PLL_F_HI 0x0F4 +#define BKTR_PLL_F_XCI 0x0F8 /* * device support for onboard tv tuners @@ -400,6 +409,31 @@ struct bktr_i2c_softc { }; #endif + +/* Bt848/878 register access + * The registers can either be access via a memory mapped structure + * or accessed via bus_space. + * bus_0pace access allows cross platform support, where as the + * memory mapped structure method only works on 32 bit processors + * with the right type of endianness. + */ +#if defined(__NetBSD__) || ( defined(__FreeBSD__) && (__FreeBSD_version >=300000) ) +#define INB(bktr,offset) bus_space_read_1((bktr)->memt,(bktr)->memh,(offset)) +#define INW(bktr,offset) bus_space_read_2((bktr)->memt,(bktr)->memh,(offset)) +#define INL(bktr,offset) bus_space_read_4((bktr)->memt,(bktr)->memh,(offset)) +#define OUTB(bktr,offset,value) bus_space_write_1((bktr)->memt,(bktr)->memh,(offset),(value)) +#define OUTW(bktr,offset,value) bus_space_write_2((bktr)->memt,(bktr)->memh,(offset),(value)) +#define OUTL(bktr,offset,value) bus_space_write_4((bktr)->memt,(bktr)->memh,(offset),(value)) +#else +#define INB(bktr,offset) *(volatile unsigned char*) ((int)((bktr)->memh)+(offset)) +#define INW(bktr,offset) *(volatile unsigned short*)((int)((bktr)->memh)+(offset)) +#define INL(bktr,offset) *(volatile unsigned int*) ((int)((bktr)->memh)+(offset)) +#define OUTB(bktr,offset,value) *(volatile unsigned char*) ((int)((bktr)->memh)+(offset)) = (value) +#define OUTW(bktr,offset,value) *(volatile unsigned short*)((int)((bktr)->memh)+(offset)) = (value) +#define OUTL(bktr,offset,value) *(volatile unsigned int*) ((int)((bktr)->memh)+(offset)) = (value) +#endif + + typedef struct bktr_clip bktr_clip_t; /* @@ -468,13 +502,17 @@ struct bktr_softc { struct resource *res_irq; /* 4.x resource descriptor for interrupt */ void *res_ih; /* 4.x newbus interrupt handler cookie */ #endif + #if (__FreeBSD_version >= 310000) + bus_space_tag_t memt; /* Bus space register access functions */ + bus_space_handle_t memh; /* Bus space register access functions */ + bus_size_t obmemsz;/* Size of card (bytes) */ + #endif #if (NSMBUS > 0) struct bktr_i2c_softc i2c_sc; /* bt848_i2c device */ #endif #endif /* the following definitions are common over all platforms */ - bt848_ptr_t base; /* Bt848 register physical address */ vm_offset_t bigbuf; /* buffer that holds the captured image */ int alloc_pages; /* number of pages in bigbuf */ @@ -585,7 +623,7 @@ struct bktr_softc { int yclip2; int max_clip_node; bktr_clip_t clip_list[100]; - int reverse_mute; + int reverse_mute; /* Swap the GPIO values for Mute and TV Audio */ int bt848_tuner; int bt848_card; u_long id; @@ -598,6 +636,8 @@ struct bktr_softc { int msp_addr; /* MSP i2c address */ char dpl_version_string[9]; /* DPL version string 35xxx-xx */ int dpl_addr; /* DPL i2c address */ + int slow_msp_audio; /* 0 = use fast MSP3410/3415 programming sequence */ + /* 1 = use slow MSP3410/3415 programming sequence */ }; @@ -611,3 +651,24 @@ struct bt848_card_sig { int tuner; u_char signature[Bt848_MAX_SIGN]; }; + + +/***********************************************************/ +/* ioctl_cmd_t int on old versions, u_long on new versions */ +/***********************************************************/ + +#if (__FreeBSD__ == 2) +typedef int ioctl_cmd_t; +#endif + +#if defined(__FreeBSD__) +#if (__FreeBSD_version >= 300000) +typedef u_long ioctl_cmd_t; +#endif +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) +typedef u_long ioctl_cmd_t; +#endif + + diff --git a/sys/dev/bktr/bktr_tuner.c b/sys/dev/bktr/bktr_tuner.c index 290975d..c63798c 100644 --- a/sys/dev/bktr/bktr_tuner.c +++ b/sys/dev/bktr/bktr_tuner.c @@ -49,13 +49,28 @@ #include <sys/systm.h> #include <sys/kernel.h> #include <sys/vnode.h> +#ifdef __NetBSD__ +#include <sys/proc.h> +#endif +#ifdef __FreeBSD__ #include <machine/clock.h> /* for DELAY */ - #include <pci/pcivar.h> +#endif -#include <machine/ioctl_meteor.h> +#if (__FreeBSD_version >=300000) +#include <machine/bus_memio.h> /* for bus space */ +#include <machine/bus.h> +#include <sys/bus.h> +#endif + +#ifdef __NetBSD__ +#include <dev/ic/ioctl_meteor.h> /* NetBSD .h file location */ +#include <dev/ic/ioctl_bt848.h> +#else +#include <machine/ioctl_meteor.h> /* Traditional .h file location */ #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */ +#endif #include <dev/bktr/bktr_reg.h> #include <dev/bktr/bktr_tuner.h> #include <dev/bktr/bktr_card.h> @@ -317,7 +332,8 @@ static int nabcst[] = { */ #define OFFSET 6.00 static int irccable[] = { - 99, (int)( 45.75 * FREQFACTOR), 0, + 116, (int)( 45.75 * FREQFACTOR), 0, + 100, (int)(649.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 95, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 23, (int)(217.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 14, (int)(121.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), @@ -342,7 +358,8 @@ static int irccable[] = { */ #define OFFSET 6.00 static int hrccable[] = { - 99, (int)( 45.75 * FREQFACTOR), 0, + 116, (int)( 45.75 * FREQFACTOR), 0, + 100, (int)(648.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 95, (int)( 90.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 23, (int)(216.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 14, (int)(120.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), |