diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-05-28 04:19:54 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-05-28 04:19:54 +0000 |
commit | 2a98051bbfed88ae0fee77862ed31af2c01683bd (patch) | |
tree | 6d6cec7ef23f372c11031712ead3c1edae9d14fb /sys | |
parent | 938bcf4e70ceb3ddfd9bfdfb2a52bf6326763b8f (diff) |
fix the fms attachment printfs and move out the radio parts to the fmsradio.c; from jumbo@ and some fixes from mickey@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/pci/fms.c | 74 | ||||
-rw-r--r-- | sys/dev/pci/fmsradio.c | 354 | ||||
-rw-r--r-- | sys/dev/pci/fmsradio.h | 59 | ||||
-rw-r--r-- | sys/dev/pci/fmsreg.h | 18 | ||||
-rw-r--r-- | sys/dev/pci/fmsvar.h | 10 |
5 files changed, 243 insertions, 272 deletions
diff --git a/sys/dev/pci/fms.c b/sys/dev/pci/fms.c index ad3af60b850..5f94f403462 100644 --- a/sys/dev/pci/fms.c +++ b/sys/dev/pci/fms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fms.c,v 1.9 2002/05/06 16:37:43 mickey Exp $ */ +/* $OpenBSD: fms.c,v 1.10 2002/05/28 04:19:53 mickey Exp $ */ /* $NetBSD: fms.c,v 1.5.4.1 2000/06/30 16:27:50 simonb Exp $ */ /*- @@ -61,11 +61,6 @@ #include <dev/auconv.h> #include <dev/ic/ac97.h> -#if NRADIO > 0 -#include <sys/radioio.h> -#include <dev/radio_if.h> -#include <dev/pci/fmsradio.h> -#endif /* NRADIO > 0 */ #if 0 #include <dev/ic/mpuvar.h> #endif @@ -154,17 +149,6 @@ struct audio_hw_if fms_hw_if = { fms_trigger_input }; -#if NRADIO > 0 -struct radio_hw_if fmsradio_hw_if = { - NULL, /* open */ - NULL, /* close */ - fmsradio_get_info, - fmsradio_set_info, - fmsradio_search -}; -#endif /* NRADIO > 0 */ - - int fms_attach_codec(void *, struct ac97_codec_if *); int fms_read_codec(void *, u_int8_t, u_int16_t *); int fms_write_codec(void *, u_int8_t, u_int16_t); @@ -199,18 +183,36 @@ fms_attach(parent, self, aux) struct pci_attach_args *pa = aux; struct fms_softc *sc = (struct fms_softc *) self; struct audio_attach_args aa; - const char *intrstr = NULL; pci_chipset_tag_t pc = pa->pa_pc; pcitag_t pt = pa->pa_tag; pci_intr_handle_t ih; + const char *intrstr; + u_int16_t k1; int i; - u_int16_t k1; + if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot, + &sc->sc_ioh, &sc->sc_ioaddr, &sc->sc_iosize, 0)) { + printf(": can't map i/o space\n"); + return; + } - printf(": Forte Media FM-801\n"); + if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0x30, 2, + &sc->sc_mpu_ioh)) { + printf(": can't get mpu subregion handle\n"); + bus_space_unmap(sc->sc_ioh, sc->sc_ioaddr, sc->sc_iosize); + return; + } + + if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0x68, 4, + &sc->sc_opl_ioh)) { + printf(": can't get opl subregion handle\n"); + bus_space_unmap(sc->sc_ioh, sc->sc_ioaddr, sc->sc_iosize); + return; + } if (pci_intr_map(pa, &ih)) { - printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); + printf(": couldn't map interrupt\n"); + bus_space_unmap(sc->sc_ioh, sc->sc_ioaddr, sc->sc_iosize); return; } intrstr = pci_intr_string(pc, ih); @@ -218,30 +220,17 @@ fms_attach(parent, self, aux) sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, fms_intr, sc, sc->sc_dev.dv_xname); if (sc->sc_ih == NULL) { - printf("%s: couldn't establish interrupt",sc->sc_dev.dv_xname); + printf(": couldn't establish interrupt"); if (intrstr != NULL) printf(" at %s", intrstr); printf("\n"); + bus_space_unmap(sc->sc_ioh, sc->sc_ioaddr, sc->sc_iosize); return; } - sc->sc_dmat = pa->pa_dmat; - - printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); - - if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot, - &sc->sc_ioh, &sc->sc_ioaddr, &sc->sc_iosize, 0)) { - printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname); - return; - } - - if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0x30, 2, - &sc->sc_mpu_ioh)) - panic("fms_attach: can't get mpu subregion handle"); + printf(": %s\n", intrstr); - if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0x68, 4, - &sc->sc_opl_ioh)) - panic("fms_attach: can't get opl subregion handle"); + sc->sc_dmat = pa->pa_dmat; /* Disable legacy audio (SBPro compatibility) */ pci_conf_write(pc, pt, 0x40, 0); @@ -269,14 +258,7 @@ fms_attach(parent, self, aux) FM_INTSTATUS_VOL); #if NRADIO > 0 - sc->radio.tea.iot = sc->sc_iot; - sc->radio.tea.ioh = sc->sc_ioh; - sc->radio.tea.offset = FM_IO_CTL; - sc->radio.tea.flags = sc->sc_dev.dv_cfdata->cf_flags; - - fmsradio_attach(&sc->radio, sc->sc_dev.dv_xname); - /* /dev/radio will attach anyway */ - radio_attach_mi(&fmsradio_hw_if, sc, &sc->sc_dev); + fmsradio_attach(sc); #endif /* NRADIO > 0 */ sc->host_if.arg = sc; diff --git a/sys/dev/pci/fmsradio.c b/sys/dev/pci/fmsradio.c index f7a818d5e12..c22146220fb 100644 --- a/sys/dev/pci/fmsradio.c +++ b/sys/dev/pci/fmsradio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmsradio.c,v 1.2 2002/05/09 14:52:28 mickey Exp $ */ +/* $OpenBSD: fmsradio.c,v 1.3 2002/05/28 04:19:53 mickey Exp $ */ /* * Copyright (c) 2002 Vladimir Popov <jumbo@narod.ru> @@ -31,13 +31,12 @@ /* Currently supported tuners: * o SoundForte RadioLink SF64-PCR PCI Radio Card * o SoundForte Quad X-treme SF256-PCP-R PCI Sound Card with FM Radio - * o SoundForte Theatre X-treme 5.1 SF256-PCS PCI Sound Card with FM Radio + * o SoundForte Theatre X-treme 5.1 SF256-PCS-R PCI Sound Card with FM Radio */ -#include "radio.h" - #include <sys/param.h> #include <sys/systm.h> +#include <sys/malloc.h> #include <sys/device.h> #include <sys/errno.h> #include <sys/ioctl.h> @@ -54,7 +53,7 @@ #include <dev/radio_if.h> #include <dev/ic/ac97.h> -#include <dev/pci/fmsradio.h> + #include <dev/pci/fmsreg.h> #include <dev/pci/fmsvar.h> @@ -64,7 +63,6 @@ #define TUNER_SF256PCPR 1 #define TUNER_SF64PCR 2 #define TUNER_SF256PCS 3 -#define TUNER_NOT_ATTACHED 0xFFFF #define SF64PCR_CAPS RADIO_CAPS_DETECT_STEREO | \ RADIO_CAPS_DETECT_SIGNAL | \ @@ -83,96 +81,134 @@ RADIO_CAPS_HW_AFC | \ RADIO_CAPS_LOCK_SENSITIVITY -#define PCR_WREN_ON (0 << 1) -#define PCR_WREN_OFF (1 << 1) -#define PCR_CLOCK_ON (1 << 0) -#define PCR_CLOCK_OFF (0 << 0) -#define PCR_DATA_ON (1 << 2) -#define PCR_DATA_OFF (0 << 2) +#define PCR_WREN_ON 0 +#define PCR_WREN_OFF FM_IO_PIN1 +#define PCR_CLOCK_ON FM_IO_PIN0 +#define PCR_CLOCK_OFF 0 +#define PCR_DATA_ON FM_IO_PIN2 +#define PCR_DATA_OFF 0 #define PCR_SIGNAL 0x80 #define PCR_STEREO 0x80 #define PCR_INFO_SIGNAL (1 << 24) #define PCR_INFO_STEREO (1 << 25) -#define PCPR_WREN_ON (0 << 2) -#define PCPR_WREN_OFF (1 << 2) -#define PCPR_CLOCK_ON (1 << 0) -#define PCPR_CLOCK_OFF (0 << 0) -#define PCPR_DATA_ON (1 << 1) -#define PCPR_DATA_OFF (0 << 1) +#define PCPR_WREN_ON 0 +#define PCPR_WREN_OFF FM_IO_PIN2 +#define PCPR_CLOCK_ON FM_IO_PIN0 +#define PCPR_CLOCK_OFF 0 +#define PCPR_DATA_ON FM_IO_PIN1 +#define PCPR_DATA_OFF 0 -#define PCS_WREN_ON (0 << 2) -#define PCS_WREN_OFF (1 << 2) -#define PCS_CLOCK_ON (1 << 3) -#define PCS_CLOCK_OFF (0 << 3) -#define PCS_DATA_ON (1 << 1) -#define PCS_DATA_OFF (0 << 1) +#define PCS_WREN_ON 0 +#define PCS_WREN_OFF FM_IO_PIN2 +#define PCS_CLOCK_ON FM_IO_PIN3 +#define PCS_CLOCK_OFF 0 +#define PCS_DATA_ON FM_IO_PIN1 +#define PCS_DATA_OFF 0 /* * Function prototypes */ -void fmsradio_set_mute(struct fmsradio_if *); +void fmsradio_set_mute(struct fms_softc *); void sf64pcr_init(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf64pcr_rset(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf64pcr_write_bit(bus_space_tag_t, bus_space_handle_t, bus_size_t, int); u_int32_t sf64pcr_hw_read(bus_space_tag_t, bus_space_handle_t, bus_size_t); -int sf64pcr_probe(struct fmsradio_if *); +int sf64pcr_probe(struct fms_softc *); void sf256pcpr_init(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf256pcpr_rset(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf256pcpr_write_bit(bus_space_tag_t, bus_space_handle_t, bus_size_t, int); u_int32_t sf256pcpr_hw_read(bus_space_tag_t, bus_space_handle_t, bus_size_t); -int sf256pcpr_probe(struct fmsradio_if *); +int sf256pcpr_probe(struct fms_softc *); void sf256pcs_init(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf256pcs_rset(bus_space_tag_t, bus_space_handle_t, bus_size_t, u_int32_t); void sf256pcs_write_bit(bus_space_tag_t, bus_space_handle_t, bus_size_t, int); u_int32_t sf256pcs_hw_read(bus_space_tag_t, bus_space_handle_t, bus_size_t); -int sf256pcs_probe(struct fmsradio_if *); +int sf256pcs_probe(struct fms_softc *); + +int fmsradio_get_info(void *, struct radio_info *); +int fmsradio_set_info(void *, struct radio_info *); +int fmsradio_search(void *, int); + +struct radio_hw_if fmsradio_hw_if = { + NULL, /* open */ + NULL, /* close */ + fmsradio_get_info, + fmsradio_set_info, + fmsradio_search +}; + +struct fmsradio_if { + int type; /* Card type */ + + int mute; + u_int8_t vol; + u_int32_t freq; + u_int32_t stereo; + u_int32_t lock; + + struct tea5757_t tea; +}; int -fmsradio_attach(struct fmsradio_if *sc, char *devname) +fmsradio_attach(struct fms_softc *sc) { - sc->vol = 0; - sc->mute = 0; - sc->freq = MIN_FM_FREQ; - sc->stereo = TEA5757_STEREO; - sc->lock = TEA5757_S030; - - sc->card = TUNER_UNKNOWN; - if ((sc->card = sf64pcr_probe(sc)) == TUNER_SF64PCR) - printf("%s: SF64-PCR FM Radio\n", devname); - else if ((sc->card = sf256pcpr_probe(sc)) == TUNER_SF256PCPR) - printf("%s: SF256-PCP-R FM Radio\n", devname); - else if ((sc->card = sf256pcs_probe(sc)) == TUNER_SF256PCS) - printf("%s: SF256-PCS FM Radio\n", devname); - else { - sc->card = TUNER_NOT_ATTACHED; - return 0; + struct fmsradio_if *r; + + r = malloc(sizeof(struct fmsradio_if), M_DEVBUF, M_NOWAIT); + if (r == NULL) { + printf("%s: cannot allocate memory for FM tuner config\n", + sc->sc_dev.dv_xname); + return TUNER_UNKNOWN; } - fmsradio_set_mute(sc); + r->tea.iot = sc->sc_iot; + r->tea.ioh = sc->sc_ioh; + r->tea.offset = FM_IO_CTL; + r->tea.flags = sc->sc_dev.dv_cfdata->cf_flags; + r->vol = 0; + r->mute = 0; + r->freq = MIN_FM_FREQ; + r->stereo = TEA5757_STEREO; + r->lock = TEA5757_S030; + + r->type = TUNER_UNKNOWN; + if ((r->type = sf64pcr_probe(sc)) == TUNER_SF64PCR) + printf("%s: SF64-PCR FM Radio\n", sc->sc_dev.dv_xname); + else if ((r->type = sf256pcpr_probe(sc)) == TUNER_SF256PCPR) + printf("%s: SF256-PCP-R FM Radio\n", sc->sc_dev.dv_xname); + else if ((r->type = sf256pcs_probe(sc)) == TUNER_SF256PCS) + printf("%s: SF256-PCS-R FM Radio\n", sc->sc_dev.dv_xname); + else + return TUNER_UNKNOWN; - return sc->card; + fmsradio_set_mute(sc); + radio_attach_mi(&fmsradio_hw_if, sc, &sc->sc_dev); + return r->type; } /* SF256-PCS specific routines */ int -sf256pcs_probe(struct fmsradio_if *sc) +sf256pcs_probe(struct fms_softc *sc) { + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; u_int32_t freq; - sc->tea.init = sf256pcs_init; - sc->tea.rset = sf256pcs_rset; - sc->tea.write_bit = sf256pcs_write_bit; - sc->tea.read = sf256pcs_hw_read; - - tea5757_set_freq(&sc->tea, sc->stereo, sc->lock, sc->freq); - freq = sf256pcs_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); - if (tea5757_decode_freq(freq, sc->tea.flags & TEA5757_TEA5759) - != sc->freq) + radio->tea.init = sf256pcs_init; + radio->tea.rset = sf256pcs_rset; + radio->tea.write_bit = sf256pcs_write_bit; + radio->tea.read = sf256pcs_hw_read; + + tea5757_set_freq(&radio->tea, radio->stereo, + radio->lock, radio->freq); + freq = tea5757_decode_freq(sf256pcs_hw_read(radio->tea.iot, + radio->tea.ioh, radio->tea.offset), + radio->tea.flags & TEA5757_TEA5759); + if (freq != radio->freq) return TUNER_UNKNOWN; return TUNER_SF256PCS; @@ -184,10 +220,10 @@ sf256pcs_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset) u_int32_t res = 0ul; u_int16_t i, d; - d = FM_IO_GPIO | PCS_WREN_OFF; + d = FM_IO_GPIO(FM_IO_PIN1 | FM_IO_PIN2 | FM_IO_PIN3) | PCS_WREN_OFF; /* Now read data in */ - d |= FM_IO_GPIO1_IN | PCS_DATA_ON; + d |= FM_IO_GPIO_IN(PCS_DATA_ON) | PCS_DATA_ON; bus_space_write_2(iot, ioh, offset, d | PCS_CLOCK_OFF); @@ -197,19 +233,21 @@ sf256pcs_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset) res <<= 1; bus_space_write_2(iot, ioh, offset, d | PCS_CLOCK_ON); bus_space_write_2(iot, ioh, offset, d | PCS_CLOCK_OFF); - res |= bus_space_read_2(iot, ioh, offset) & PCS_DATA_ON ? 1 : 0; + res |= bus_space_read_2(iot, ioh, offset) & + PCS_DATA_ON ? 1 : 0; } return (res & (TEA5757_DATA | TEA5757_FREQ)); } void -sf256pcs_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, - int bit) +sf256pcs_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t off, int bit) { u_int16_t data, wren; - wren = FM_IO_GPIO | FM_IO_GPIO2_IN | PCS_WREN_ON; + wren = FM_IO_GPIO(FM_IO_PIN1 | FM_IO_PIN2 | FM_IO_PIN3); + wren |= PCS_WREN_ON; data = bit ? PCPR_DATA_ON : PCS_DATA_OFF; bus_space_write_2(iot, ioh, off, PCS_CLOCK_OFF | wren | data); @@ -218,10 +256,10 @@ sf256pcs_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, } void -sf256pcs_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf256pcs_init(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { - d = FM_IO_GPIO | FM_IO_GPIO1_IN; + d = FM_IO_GPIO(FM_IO_PIN1 | FM_IO_PIN2 | FM_IO_PIN3); d |= PCS_WREN_ON | PCS_DATA_OFF | PCS_CLOCK_OFF; bus_space_write_2(iot, ioh, offset, d); @@ -229,10 +267,10 @@ sf256pcs_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, } void -sf256pcs_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf256pcs_rset(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { - d = FM_IO_GPIO | FM_IO_GPIO1_IN; + d = FM_IO_GPIO(FM_IO_PIN1 | FM_IO_PIN2 | FM_IO_PIN3); d |= PCS_WREN_OFF | PCS_DATA_OFF | PCS_CLOCK_OFF; bus_space_write_2(iot, ioh, offset, d); @@ -241,35 +279,38 @@ sf256pcs_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, /* SF256-PCP-R specific routines */ int -sf256pcpr_probe(struct fmsradio_if *sc) +sf256pcpr_probe(struct fms_softc *sc) { + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; u_int32_t freq; - sc->tea.init = sf256pcpr_init; - sc->tea.rset = sf256pcpr_rset; - sc->tea.write_bit = sf256pcpr_write_bit; - sc->tea.read = sf256pcpr_hw_read; - - tea5757_set_freq(&sc->tea, sc->stereo, sc->lock, sc->freq); - freq = sf256pcpr_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); - if (tea5757_decode_freq(freq, sc->tea.flags & TEA5757_TEA5759) - != sc->freq) + radio->tea.init = sf256pcpr_init; + radio->tea.rset = sf256pcpr_rset; + radio->tea.write_bit = sf256pcpr_write_bit; + radio->tea.read = sf256pcpr_hw_read; + + tea5757_set_freq(&radio->tea, radio->stereo, + radio->lock, radio->freq); + freq = tea5757_decode_freq(sf256pcpr_hw_read(radio->tea.iot, + radio->tea.ioh, radio->tea.offset), + radio->tea.flags & TEA5757_TEA5759); + if (freq != radio->freq) return TUNER_UNKNOWN; return TUNER_SF256PCPR; } u_int32_t -sf256pcpr_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset) +sf256pcpr_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset) { u_int32_t res = 0ul; u_int16_t i, d; - d = FM_IO_GPIO; - d |= FM_IO_GPIO3_IN | PCPR_WREN_OFF; + d = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(PCPR_DATA_ON | FM_IO_PIN3); /* Now read data in */ - d |= FM_IO_GPIO1_IN | PCPR_DATA_ON; + d |= PCPR_WREN_OFF | PCPR_DATA_ON; bus_space_write_2(iot, ioh, offset, d | PCPR_CLOCK_OFF); @@ -279,19 +320,20 @@ sf256pcpr_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset res <<= 1; bus_space_write_2(iot, ioh, offset, d | PCPR_CLOCK_ON); bus_space_write_2(iot, ioh, offset, d | PCPR_CLOCK_OFF); - res |= bus_space_read_2(iot, ioh, offset) & PCPR_DATA_ON ? 1 : 0; + res |= bus_space_read_2(iot, ioh, offset) & + PCPR_DATA_ON ? 1 : 0; } return (res & (TEA5757_DATA | TEA5757_FREQ)); } void -sf256pcpr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, - int bit) +sf256pcpr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t off, int bit) { u_int16_t data, wren; - wren = FM_IO_GPIO | FM_IO_GPIO3_IN | PCPR_WREN_ON; + wren = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3) | PCPR_WREN_ON; data = bit ? PCPR_DATA_ON : PCPR_DATA_OFF; bus_space_write_2(iot, ioh, off, PCPR_CLOCK_OFF | wren | data); @@ -300,10 +342,10 @@ sf256pcpr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, } void -sf256pcpr_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf256pcpr_init(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { - d = FM_IO_GPIO | FM_IO_GPIO3_IN; + d = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3); d |= PCPR_WREN_ON | PCPR_DATA_OFF | PCPR_CLOCK_OFF; bus_space_write_2(iot, ioh, offset, d); @@ -311,10 +353,10 @@ sf256pcpr_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, } void -sf256pcpr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf256pcpr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { - d = FM_IO_GPIO | FM_IO_GPIO3_IN; + d = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3); d |= PCPR_WREN_OFF | PCPR_DATA_OFF | PCPR_CLOCK_OFF; bus_space_write_2(iot, ioh, offset, d); @@ -323,19 +365,22 @@ sf256pcpr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, /* SF64-PCR specific routines */ int -sf64pcr_probe(struct fmsradio_if *sc) +sf64pcr_probe(struct fms_softc *sc) { + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; u_int32_t freq; - sc->tea.init = sf64pcr_init; - sc->tea.rset = sf64pcr_rset; - sc->tea.write_bit = sf64pcr_write_bit; - sc->tea.read = sf64pcr_hw_read; - - tea5757_set_freq(&sc->tea, sc->stereo, sc->lock, sc->freq); - freq = sf64pcr_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); - if (tea5757_decode_freq(freq, sc->tea.flags & TEA5757_TEA5759) - != sc->freq) + radio->tea.init = sf64pcr_init; + radio->tea.rset = sf64pcr_rset; + radio->tea.write_bit = sf64pcr_write_bit; + radio->tea.read = sf64pcr_hw_read; + + tea5757_set_freq(&radio->tea, radio->stereo, + radio->lock, radio->freq); + freq = tea5757_decode_freq(sf64pcr_hw_read(radio->tea.iot, + radio->tea.ioh, radio->tea.offset), + radio->tea.flags & TEA5757_TEA5759); + if (freq != radio->freq) return TUNER_UNKNOWN; return TUNER_SF64PCR; @@ -347,11 +392,10 @@ sf64pcr_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset) u_int32_t res = 0ul; u_int16_t d, i, ind = 0; - d = FM_IO_GPIO; - d |= FM_IO_GPIO3_IN | PCR_WREN_OFF; + d = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(PCR_DATA_ON | FM_IO_PIN3); /* Now read data in */ - d |= FM_IO_GPIO2_IN | PCR_DATA_ON; + d |= PCR_WREN_OFF | PCR_DATA_ON; bus_space_write_2(iot, ioh, offset, d | PCR_CLOCK_OFF); DELAY(4); @@ -385,12 +429,12 @@ sf64pcr_hw_read(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset) } void -sf64pcr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, - int bit) +sf64pcr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t off, int bit) { u_int16_t data, wren; - wren = FM_IO_GPIO | FM_IO_GPIO3_IN | PCR_WREN_ON; + wren = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3) | PCR_WREN_ON; data = bit ? PCR_DATA_ON : PCR_DATA_OFF; bus_space_write_2(iot, ioh, off, PCR_CLOCK_OFF | wren | data); @@ -402,10 +446,10 @@ sf64pcr_write_bit(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, } void -sf64pcr_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf64pcr_init(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { - d = FM_IO_GPIO | FM_IO_GPIO3_IN; + d = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3); d |= PCR_WREN_ON | PCR_DATA_ON | PCR_CLOCK_OFF; bus_space_write_2(iot, ioh, offset, d); @@ -413,8 +457,8 @@ sf64pcr_init(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, } void -sf64pcr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, - u_int32_t d) +sf64pcr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, + bus_size_t offset, u_int32_t d) { /* Do nothing */ return; @@ -426,62 +470,67 @@ sf64pcr_rset(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t offset, * Mute/unmute */ void -fmsradio_set_mute(struct fmsradio_if *sc) +fmsradio_set_mute(struct fms_softc *sc) { + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; u_int16_t v, mute, unmute; - mute = unmute = FM_IO_GPIO; - switch (sc->card) { + switch (radio->type) { case TUNER_SF256PCS: - mute |= FM_IO_GPIO1_IN; - unmute |= FM_IO_GPIO1_IN | FM_IO_GPIO2; + mute = FM_IO_GPIO(FM_IO_PIN1 | FM_IO_PIN2 | FM_IO_PIN3); + unmute = mute | PCS_WREN_OFF; break; case TUNER_SF256PCPR: - mute |= FM_IO_GPIO3_IN; - unmute |= FM_IO_GPIO3_IN | FM_IO_GPIO2; + mute = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3); + unmute = mute | PCPR_WREN_OFF; break; case TUNER_SF64PCR: - mute |= FM_IO_GPIO3_IN; - unmute |= FM_IO_GPIO3_IN | FM_IO_GPIO1; + mute = FM_IO_GPIO_ALL | FM_IO_GPIO_IN(FM_IO_PIN3); + unmute = mute | PCR_WREN_OFF; break; default: return; } - v = (sc->mute || !sc->vol) ? mute : unmute; - bus_space_write_2(sc->tea.iot, sc->tea.ioh, sc->tea.offset, v); + v = (radio->mute || !radio->vol) ? mute : unmute; + bus_space_write_2(radio->tea.iot, radio->tea.ioh, + radio->tea.offset, v); DELAY(64); - bus_space_write_2(sc->tea.iot, sc->tea.ioh, sc->tea.offset, v); + bus_space_write_2(radio->tea.iot, radio->tea.ioh, + radio->tea.offset, v); } int fmsradio_get_info(void *v, struct radio_info *ri) { - struct fms_softc *fms_sc = v; - struct fmsradio_if *sc = &fms_sc->radio; + struct fms_softc *sc = v; + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; u_int32_t buf; - if (sc->card == TUNER_NOT_ATTACHED) + if (radio->type == TUNER_UNKNOWN) return (ENXIO); - ri->mute = sc->mute; - ri->volume = sc->vol ? 255 : 0; - ri->stereo = sc->stereo == TEA5757_STEREO ? 1 : 0; - ri->lock = tea5757_decode_lock(sc->lock); + ri->mute = radio->mute; + ri->volume = radio->vol ? 255 : 0; + ri->stereo = radio->stereo == TEA5757_STEREO ? 1 : 0; + ri->lock = tea5757_decode_lock(radio->lock); - switch (sc->card) { + switch (radio->type) { case TUNER_SF256PCS: ri->caps = SF256PCS_CAPS; - buf = sf256pcs_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); + buf = sf256pcs_hw_read(radio->tea.iot, radio->tea.ioh, + radio->tea.offset); ri->info = 0; /* UNSUPPORTED */ break; case TUNER_SF256PCPR: ri->caps = SF256PCPR_CAPS; - buf = sf256pcpr_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); + buf = sf256pcpr_hw_read(radio->tea.iot, radio->tea.ioh, + radio->tea.offset); ri->info = 0; /* UNSUPPORTED */ break; case TUNER_SF64PCR: ri->caps = SF64PCR_CAPS; - buf = sf64pcr_hw_read(sc->tea.iot, sc->tea.ioh, sc->tea.offset); + buf = sf64pcr_hw_read(radio->tea.iot, radio->tea.ioh, + radio->tea.offset); ri->info = buf & PCR_INFO_SIGNAL ? 0 : RADIO_INFO_SIGNAL; ri->info |= buf & PCR_INFO_STEREO ? 0 : RADIO_INFO_STEREO; break; @@ -489,8 +538,8 @@ fmsradio_get_info(void *v, struct radio_info *ri) break; } - ri->freq = sc->freq = tea5757_decode_freq(buf, - sc->tea.flags & TEA5757_TEA5759); + ri->freq = radio->freq = tea5757_decode_freq(buf, + sc->sc_dev.dv_cfdata->cf_flags & TEA5757_TEA5759); fmsradio_set_mute(sc); @@ -503,18 +552,18 @@ fmsradio_get_info(void *v, struct radio_info *ri) int fmsradio_set_info(void *v, struct radio_info *ri) { - struct fms_softc *fms_sc = v; - struct fmsradio_if *sc = &fms_sc->radio; + struct fms_softc *sc = v; + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; - if (sc->card == TUNER_NOT_ATTACHED) + if (radio->type == TUNER_UNKNOWN) return (ENXIO); - sc->mute = ri->mute ? 1 : 0; - sc->vol = ri->volume ? 255 : 0; - sc->stereo = ri->stereo ? TEA5757_STEREO: TEA5757_MONO; - sc->lock = tea5757_encode_lock(ri->lock); - ri->freq = sc->freq = tea5757_set_freq(&sc->tea, - sc->lock, sc->stereo, ri->freq); + radio->mute = ri->mute ? 1 : 0; + radio->vol = ri->volume ? 255 : 0; + radio->stereo = ri->stereo ? TEA5757_STEREO: TEA5757_MONO; + radio->lock = tea5757_encode_lock(ri->lock); + ri->freq = radio->freq = tea5757_set_freq(&radio->tea, + radio->lock, radio->stereo, ri->freq); fmsradio_set_mute(sc); return (0); @@ -523,13 +572,14 @@ fmsradio_set_info(void *v, struct radio_info *ri) int fmsradio_search(void *v, int f) { - struct fms_softc *fms_sc = v; - struct fmsradio_if *sc = &fms_sc->radio; + struct fms_softc *sc = v; + struct fmsradio_if *radio = (struct fmsradio_if *)sc->radio; - if (sc->card == TUNER_NOT_ATTACHED) + if (radio->type == TUNER_UNKNOWN) return (ENXIO); - tea5757_search(&sc->tea, sc->lock, sc->stereo, f); + tea5757_search(&radio->tea, radio->lock, + radio->stereo, f); fmsradio_set_mute(sc); return (0); diff --git a/sys/dev/pci/fmsradio.h b/sys/dev/pci/fmsradio.h deleted file mode 100644 index dc09c5d976d..00000000000 --- a/sys/dev/pci/fmsradio.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: fmsradio.h,v 1.1 2002/05/06 16:37:43 mickey Exp $ */ - -/* - * Copyright (c) 2002 Vladimir Popov <jumbo@narod.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* Device Driver for FM801-based FM Tuners */ - -/* Currently supported tuners: - * o MediaForte SoundForte SF64-PCR PCI Radio Card - * o MediaForte SoundForte SF256-PCP-R PCI Sound Card with FM tuner - */ - -#ifndef _FMS_RADIO_H_ -#define _FMS_RADIO_H_ - -#include <dev/ic/tea5757.h> - -struct fmsradio_if { - int card; /* Card type */ - - int mute; - u_int8_t vol; - u_int32_t freq; - u_int32_t stereo; - u_int32_t lock; - - struct tea5757_t tea; -}; - -int fmsradio_attach(struct fmsradio_if *, char *); - -int fmsradio_get_info(void *, struct radio_info *); -int fmsradio_set_info(void *, struct radio_info *); -int fmsradio_search(void *, int); - -#endif /* _FMS_RADIO_H_ */ diff --git a/sys/dev/pci/fmsreg.h b/sys/dev/pci/fmsreg.h index 6e56e6ac247..3f167972224 100644 --- a/sys/dev/pci/fmsreg.h +++ b/sys/dev/pci/fmsreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fmsreg.h,v 1.1 2002/05/06 16:37:43 mickey Exp $ */ +/* $OpenBSD: fmsreg.h,v 1.2 2002/05/28 04:19:53 mickey Exp $ */ /* $NetBSD: fms.c,v 1.5.4.1 2000/06/30 16:27:50 simonb Exp $ */ /*- @@ -88,15 +88,13 @@ #define FM_CODEC_DATA 0x2c #define FM_IO_CTL 0x52 -#define FM_IO_GPIO 0xf000 -#define FM_IO_GPIO0 0x0001 -#define FM_IO_GPIO1 0x0002 -#define FM_IO_GPIO2 0x0004 -#define FM_IO_GPIO3 0x0008 -#define FM_IO_GPIO0_IN 0x0100 /* 1 - input; 0 - output */ -#define FM_IO_GPIO1_IN 0x0200 -#define FM_IO_GPIO2_IN 0x0400 -#define FM_IO_GPIO3_IN 0x0800 +#define FM_IO_GPIO(x) ((x) << 12) +#define FM_IO_GPIO_ALL FM_IO_GPIO(0xf) +#define FM_IO_GPIO_IN(x) ((x) << 8) +#define FM_IO_PIN0 0x0001 +#define FM_IO_PIN1 0x0002 +#define FM_IO_PIN2 0x0004 +#define FM_IO_PIN3 0x0008 #define FM_CARD_CTL 0x54 diff --git a/sys/dev/pci/fmsvar.h b/sys/dev/pci/fmsvar.h index 5bdd53c0eeb..aacfb2b2985 100644 --- a/sys/dev/pci/fmsvar.h +++ b/sys/dev/pci/fmsvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fmsvar.h,v 1.3 2002/05/06 16:37:43 mickey Exp $ */ +/* $OpenBSD: fmsvar.h,v 1.4 2002/05/28 04:19:53 mickey Exp $ */ /* $NetBSD: fmsvar.h,v 1.1 1999/11/01 21:54:12 augustss Exp $ */ /*- @@ -56,13 +56,11 @@ struct fms_softc { bus_space_handle_t sc_mpu_ioh; struct device * sc_mpu_dev; + void *radio; + struct ac97_codec_if *codec_if; struct ac97_host_if host_if; -#if NRADIO > 0 - struct fmsradio_if radio; -#endif - struct fms_dma *sc_dmas; void (*sc_pintr)(void *); @@ -80,4 +78,6 @@ struct fms_softc { u_int16_t sc_rec_reg; }; +int fmsradio_attach(struct fms_softc *); + #endif |