diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/pci/envy.c | 96 | ||||
-rw-r--r-- | sys/dev/pci/envyreg.h | 72 | ||||
-rw-r--r-- | sys/dev/pci/envyvar.h | 4 |
3 files changed, 94 insertions, 78 deletions
diff --git a/sys/dev/pci/envy.c b/sys/dev/pci/envy.c index bf7589332ac..e5b8835721c 100644 --- a/sys/dev/pci/envy.c +++ b/sys/dev/pci/envy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envy.c,v 1.22 2009/05/08 15:17:41 ratchov Exp $ */ +/* $OpenBSD: envy.c,v 1.23 2009/05/08 15:31:16 ratchov Exp $ */ /* * Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org> * @@ -24,7 +24,6 @@ * * - implement HT mixer, midi uart, spdif, init ADC/DACs for >48kHz modes * - * - rename s/ak/spi/g */ #include <sys/param.h> @@ -69,8 +68,8 @@ int envy_gpio_getdir(struct envy_softc *); void envy_gpio_setdir(struct envy_softc *, int); int envy_eeprom_gpioxxx(struct envy_softc *, int); void envy_reset(struct envy_softc *); -int envy_ak_read(struct envy_softc *, int, int); -void envy_ak_write(struct envy_softc *, int, int, int); +int envy_codec_read(struct envy_softc *, int, int); +void envy_codec_write(struct envy_softc *, int, int, int); int envy_intr(void *); int envy_lineout_getsrc(struct envy_softc *, int); @@ -102,13 +101,13 @@ int envy_set_port(void *, struct mixer_ctrl *); int envy_get_props(void *); void delta_init(struct envy_softc *); -void delta_ak_write(struct envy_softc *, int, int, int); +void delta_codec_write(struct envy_softc *, int, int, int); void julia_init(struct envy_softc *); -void julia_ak_write(struct envy_softc *, int, int, int); +void julia_codec_write(struct envy_softc *, int, int, int); void unkenvy_init(struct envy_softc *); -void unkenvy_ak_write(struct envy_softc *, int, int, int); +void unkenvy_codec_write(struct envy_softc *, int, int, int); int unkenvy_codec_ndev(struct envy_softc *); int ak4524_dac_ndev(struct envy_softc *); @@ -204,14 +203,14 @@ struct envy_card envy_cards[] = { "delta", 8, &ak4524_adc, 8, &ak4524_dac, delta_init, - delta_ak_write, + delta_codec_write, NULL }, { 0, "unkenvy", 8, &unkenvy_codec, 8, &unkenvy_codec, unkenvy_init, - unkenvy_ak_write + unkenvy_codec_write } }, envy_cards_ht[] = { { @@ -219,14 +218,14 @@ struct envy_card envy_cards[] = { "julia", 2, &unkenvy_codec, 2, &unkenvy_codec, julia_init, - julia_ak_write, + julia_codec_write, julia_eeprom }, { 0, "unkenvy", 2, &unkenvy_codec, 8, &unkenvy_codec, unkenvy_init, - unkenvy_ak_write + unkenvy_codec_write } }; @@ -241,20 +240,22 @@ delta_init(struct envy_softc *sc) int dev; for (dev = 0; dev < 4 /* XXX */; dev++) { - envy_ak_write(sc, dev, AK_RST, 0x0); + envy_codec_write(sc, dev, AK4524_RST, 0x0); delay(300); - envy_ak_write(sc, dev, AK_RST, AK_RST_AD | AK_RST_DA); - envy_ak_write(sc, dev, AK_FMT, AK_FMT_IIS24); - sc->ak[dev].reg[AK_DEEMVOL] = AK_DEEM_OFF; - sc->ak[dev].reg[AK_ADC_GAIN0] = 0x7f; - sc->ak[dev].reg[AK_ADC_GAIN1] = 0x7f; - sc->ak[dev].reg[AK_DAC_GAIN0] = 0x7f; - sc->ak[dev].reg[AK_DAC_GAIN1] = 0x7f; + envy_codec_write(sc, dev, AK4524_RST, + AK4524_RST_AD | AK4524_RST_DA); + envy_codec_write(sc, dev, AK4524_FMT, + AK4524_FMT_IIS24); + sc->ak[dev].reg[AK4524_DEEMVOL] = AK4524_DEEM_OFF; + sc->ak[dev].reg[AK4524_ADC_GAIN0] = 0x7f; + sc->ak[dev].reg[AK4524_ADC_GAIN1] = 0x7f; + sc->ak[dev].reg[AK4524_DAC_GAIN0] = 0x7f; + sc->ak[dev].reg[AK4524_DAC_GAIN1] = 0x7f; } } void -delta_ak_write(struct envy_softc *sc, int dev, int addr, int data) +delta_codec_write(struct envy_softc *sc, int dev, int addr, int data) { int bits, i, reg; @@ -290,13 +291,13 @@ delta_ak_write(struct envy_softc *sc, int dev, int addr, int data) void julia_init(struct envy_softc *sc) { - envy_ak_write(sc, 0, 0, 0); /* reset */ + envy_codec_write(sc, 0, 0, 0); /* reset */ delay(300); - envy_ak_write(sc, 0, 0, 0x87); /* i2s mode */ + envy_codec_write(sc, 0, 0, 0x87); /* i2s mode */ } void -julia_ak_write(struct envy_softc *sc, int dev, int addr, int data) +julia_codec_write(struct envy_softc *sc, int dev, int addr, int data) { #define JULIA_AK4358_ADDR 0x11 envy_i2c_write(sc, JULIA_AK4358_ADDR, addr, data); @@ -313,7 +314,7 @@ unkenvy_init(struct envy_softc *sc) } void -unkenvy_ak_write(struct envy_softc *sc, int dev, int addr, int data) +unkenvy_codec_write(struct envy_softc *sc, int dev, int addr, int data) { } @@ -372,13 +373,14 @@ ak4524_dac_get(struct envy_softc *sc, struct mixer_ctrl *ctl, int idx) ndev = sc->card->noch; if (idx < ndev) { - val = envy_ak_read(sc, idx / 2, (idx % 2) + AK_DAC_GAIN0); + val = envy_codec_read(sc, idx / 2, + (idx % 2) + AK4524_DAC_GAIN0); ctl->un.value.num_channels = 1; ctl->un.value.level[0] = 2 * val; } else { idx -= ndev; - val = envy_ak_read(sc, idx, AK_DEEMVOL); - ctl->un.ord = (val & AK_MUTE) ? 1 : 0; + val = envy_codec_read(sc, idx, AK4524_DEEMVOL); + ctl->un.ord = (val & AK4524_MUTE) ? 1 : 0; } } @@ -392,13 +394,14 @@ ak4524_dac_set(struct envy_softc *sc, struct mixer_ctrl *ctl, int idx) if (ctl->un.value.num_channels != 1) return EINVAL; val = ctl->un.value.level[0] / 2; - envy_ak_write(sc, idx / 2, (idx % 2) + AK_DAC_GAIN0, val); + envy_codec_write(sc, idx / 2, + (idx % 2) + AK4524_DAC_GAIN0, val); } else { idx -= ndev; if (ctl->un.ord >= 2) return EINVAL; - val = AK_DEEM_OFF | (ctl->un.ord ? AK_MUTE : 0); - envy_ak_write(sc, idx, AK_DEEMVOL, val); + val = AK4524_DEEM_OFF | (ctl->un.ord ? AK4524_MUTE : 0); + envy_codec_write(sc, idx, AK4524_DEEMVOL, val); } return 0; } @@ -429,7 +432,7 @@ ak4524_adc_get(struct envy_softc *sc, struct mixer_ctrl *ctl, int idx) { int val; - val = envy_ak_read(sc, idx / 2, (idx % 2) + AK_ADC_GAIN0); + val = envy_codec_read(sc, idx / 2, (idx % 2) + AK4524_ADC_GAIN0); ctl->un.value.num_channels = 1; ctl->un.value.level[0] = 2 * val; } @@ -442,7 +445,7 @@ ak4524_adc_set(struct envy_softc *sc, struct mixer_ctrl *ctl, int idx) if (ctl->un.value.num_channels != 1) return EINVAL; val = ctl->un.value.level[0] / 2; - envy_ak_write(sc, idx / 2, (idx % 2) + AK_ADC_GAIN0, val); + envy_codec_write(sc, idx / 2, (idx % 2) + AK4524_ADC_GAIN0, val); return 0; } @@ -589,16 +592,16 @@ envy_i2c_write(struct envy_softc *sc, int dev, int addr, int data) } int -envy_ak_read(struct envy_softc *sc, int dev, int addr) { +envy_codec_read(struct envy_softc *sc, int dev, int addr) { return sc->ak[dev].reg[addr]; } void -envy_ak_write(struct envy_softc *sc, int dev, int addr, int data) +envy_codec_write(struct envy_softc *sc, int dev, int addr, int data) { - DPRINTFN(2, "envy_ak_write: %d, %d, 0x%x\n", dev, addr, data); + DPRINTFN(2, "envy_codec_write: %d, %d, 0x%x\n", dev, addr, data); sc->ak[dev].reg[addr] = data; - sc->card->ak_write(sc, dev, addr, data); + sc->card->codec_write(sc, dev, addr, data); } int @@ -702,7 +705,8 @@ envy_intr(void *self) } int -envy_lineout_getsrc(struct envy_softc *sc, int out) { +envy_lineout_getsrc(struct envy_softc *sc, int out) +{ int reg, shift, src; reg = bus_space_read_2(sc->mt_iot, sc->mt_ioh, ENVY_MT_OUTSRC); @@ -724,7 +728,8 @@ envy_lineout_getsrc(struct envy_softc *sc, int out) { } void -envy_lineout_setsrc(struct envy_softc *sc, int out, int src) { +envy_lineout_setsrc(struct envy_softc *sc, int out, int src) +{ int reg, shift, mask, sel; if (src < ENVY_MIX_OUTSRC_DMA) { @@ -767,7 +772,8 @@ envy_lineout_setsrc(struct envy_softc *sc, int out, int src) { int -envy_spdout_getsrc(struct envy_softc *sc, int out) { +envy_spdout_getsrc(struct envy_softc *sc, int out) +{ int reg, src, sel; reg = bus_space_read_2(sc->mt_iot, sc->mt_ioh, ENVY_MT_SPDROUTE); @@ -789,7 +795,8 @@ envy_spdout_getsrc(struct envy_softc *sc, int out) { } void -envy_spdout_setsrc(struct envy_softc *sc, int out, int src) { +envy_spdout_setsrc(struct envy_softc *sc, int out, int src) +{ int reg, shift, mask, sel; reg = bus_space_read_2(sc->mt_iot, sc->mt_ioh, ENVY_MT_SPDROUTE); @@ -828,7 +835,8 @@ envy_spdout_setsrc(struct envy_softc *sc, int out, int src) { } void -envy_mon_getvol(struct envy_softc *sc, int idx, int ch, int *val) { +envy_mon_getvol(struct envy_softc *sc, int idx, int ch, int *val) +{ int reg; bus_space_write_2(sc->mt_iot, sc->mt_ioh, ENVY_MT_MONIDX, idx); @@ -837,7 +845,8 @@ envy_mon_getvol(struct envy_softc *sc, int idx, int ch, int *val) { } void -envy_mon_setvol(struct envy_softc *sc, int idx, int ch, int val) { +envy_mon_setvol(struct envy_softc *sc, int idx, int ch, int val) +{ int reg; bus_space_write_2(sc->mt_iot, sc->mt_ioh, ENVY_MT_MONIDX, idx); @@ -847,7 +856,8 @@ envy_mon_setvol(struct envy_softc *sc, int idx, int ch, int val) { } int -envymatch(struct device *parent, void *match, void *aux) { +envymatch(struct device *parent, void *match, void *aux) +{ return pci_matchbyid((struct pci_attach_args *)aux, envy_matchids, sizeof(envy_matchids) / sizeof(envy_matchids[0])); } diff --git a/sys/dev/pci/envyreg.h b/sys/dev/pci/envyreg.h index 6118e3a6fa9..42f8c2d33d8 100644 --- a/sys/dev/pci/envyreg.h +++ b/sys/dev/pci/envyreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: envyreg.h,v 1.6 2009/04/25 12:15:10 ratchov Exp $ */ +/* $OpenBSD: envyreg.h,v 1.7 2009/05/08 15:31:16 ratchov Exp $ */ /* * Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org> * @@ -147,38 +147,44 @@ /* * AK4524 control registers */ -#define AK_PWR 0x00 -#define AK_PWR_DA 0x01 -#define AK_PWR_AD 0x02 -#define AK_PWR_VREF 0x04 -#define AK_RST 0x01 -#define AK_RST_DA 0x01 -#define AK_RST_AD 0x02 -#define AK_FMT 0x02 -#define AK_FMT_NORM 0 -#define AK_FMT_DBL 0x01 -#define AK_FMT_QUAD 0x02 -#define AK_FMT_QAUDFILT 0x04 -#define AK_FMT_256 0 -#define AK_FMT_512 0x04 -#define AK_FMT_1024 0x08 -#define AK_FMT_384 0x10 -#define AK_FMT_768 0x14 -#define AK_FMT_LSB16 0 -#define AK_FMT_LSB20 0x20 -#define AK_FMT_MSB24 0x40 -#define AK_FMT_IIS24 0x60 -#define AK_FMT_LSB24 0x80 -#define AK_DEEMVOL 0x03 -#define AK_DEEM_44K1 0x00 -#define AK_DEEM_OFF 0x01 -#define AK_DEEM_48K 0x02 -#define AK_DEEM_32K 0x03 -#define AK_MUTE 0x80 -#define AK_ADC_GAIN0 0x04 -#define AK_ADC_GAIN1 0x05 -#define AK_DAC_GAIN0 0x06 -#define AK_DAC_GAIN1 0x07 +#define AK4524_PWR 0x00 +#define AK4524_PWR_DA 0x01 +#define AK4524_PWR_AD 0x02 +#define AK4524_PWR_VREF 0x04 +#define AK4524_RST 0x01 +#define AK4524_RST_DA 0x01 +#define AK4524_RST_AD 0x02 +#define AK4524_FMT 0x02 +#define AK4524_FMT_NORM 0 +#define AK4524_FMT_DBL 0x01 +#define AK4524_FMT_QUA 0x02 +#define AK4524_FMT_QAUDFILT 0x04 +#define AK4524_FMT_256 0 +#define AK4524_FMT_512 0x04 +#define AK4524_FMT_1024 0x08 +#define AK4524_FMT_384 0x10 +#define AK4524_FMT_768 0x14 +#define AK4524_FMT_LSB16 0 +#define AK4524_FMT_LSB20 0x20 +#define AK4524_FMT_MSB24 0x40 +#define AK4524_FMT_IIS24 0x60 +#define AK4524_FMT_LSB24 0x80 +#define AK4524_DEEMVOL 0x03 +#define AK4524_DEEM_44K1 0x00 +#define AK4524_DEEM_OFF 0x01 +#define AK4524_DEEM_48K 0x02 +#define AK4524_DEEM_32K 0x03 +#define AK4524_MUTE 0x80 +#define AK4524_ADC_GAIN0 0x04 +#define AK4524_ADC_GAIN1 0x05 +#define AK4524_DAC_GAIN0 0x06 +#define AK4524_DAC_GAIN1 0x07 + +/* + * AK4358 control registers + */ +#define AK4358_ATT(chan) ((chan) <= 5 ? 0x4 + (chan) : 0xb - 6 + (chan)) + /* * default formats diff --git a/sys/dev/pci/envyvar.h b/sys/dev/pci/envyvar.h index 5c6dc043150..cf3e44f66d3 100644 --- a/sys/dev/pci/envyvar.h +++ b/sys/dev/pci/envyvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: envyvar.h,v 1.10 2009/05/08 14:56:03 ratchov Exp $ */ +/* $OpenBSD: envyvar.h,v 1.11 2009/05/08 15:31:16 ratchov Exp $ */ /* * Copyright (c) 2007 Alexandre Ratchov <alex@caoua.org> * @@ -47,7 +47,7 @@ struct envy_card { int noch; struct envy_codec *dac; void (*init)(struct envy_softc *); - void (*ak_write)(struct envy_softc *, int, int, int); + void (*codec_write)(struct envy_softc *, int, int, int); unsigned char *eeprom; }; |