Module Name: src Committed By: isaki Date: Sun Apr 21 07:49:16 UTC 2019
Modified Files: src/sys/dev/pci [isaki-audio2]: cs4280.c cs4281.c cs428x.c cs428x.h Log Message: Adapt cs428x families to audio2. - recording on cs4280 seems to have its own conversion. I will see it later but first make it compilable. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.71.2.1 src/sys/dev/pci/cs4280.c cvs rdiff -u -r1.54 -r1.54.2.1 src/sys/dev/pci/cs4281.c cvs rdiff -u -r1.18 -r1.18.14.1 src/sys/dev/pci/cs428x.c cvs rdiff -u -r1.16 -r1.16.42.1 src/sys/dev/pci/cs428x.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/cs4280.c diff -u src/sys/dev/pci/cs4280.c:1.71 src/sys/dev/pci/cs4280.c:1.71.2.1 --- src/sys/dev/pci/cs4280.c:1.71 Sat Mar 16 12:09:58 2019 +++ src/sys/dev/pci/cs4280.c Sun Apr 21 07:49:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cs4280.c,v 1.71 2019/03/16 12:09:58 isaki Exp $ */ +/* $NetBSD: cs4280.c,v 1.71.2.1 2019/04/21 07:49:16 isaki Exp $ */ /* * Copyright (c) 1999, 2000 Tatoku Ogaito. All rights reserved. @@ -52,7 +52,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.71 2019/03/16 12:09:58 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.71.2.1 2019/04/21 07:49:16 isaki Exp $"); #include "midi.h" @@ -70,8 +70,6 @@ __KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1 #include <dev/audio_if.h> #include <dev/midi_if.h> -#include <dev/mulaw.h> -#include <dev/auconv.h> #include <dev/ic/ac97reg.h> #include <dev/ic/ac97var.h> @@ -90,10 +88,10 @@ __KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1 static int cs4280_match(device_t, cfdata_t, void *); static void cs4280_attach(device_t, device_t, void *); static int cs4280_intr(void *); -static int cs4280_query_encoding(void *, struct audio_encoding *); -static int cs4280_set_params(void *, int, int, audio_params_t *, - audio_params_t *, stream_filter_list_t *, - stream_filter_list_t *); +static int cs4280_query_format(void *, audio_format_query_t *); +static int cs4280_set_format(void *, int, + const audio_params_t *, const audio_params_t *, + audio_filter_reg_t *, audio_filter_reg_t *); static int cs4280_halt_output(void *); static int cs4280_halt_input(void *); static int cs4280_getdev(void *, struct audio_device *); @@ -159,8 +157,8 @@ static const struct cs4280_card_t cs4280 #define CS4280_CARDS_SIZE (sizeof(cs4280_cards)/sizeof(cs4280_cards[0])) static const struct audio_hw_if cs4280_hw_if = { - .query_encoding = cs4280_query_encoding, - .set_params = cs4280_set_params, + .query_format = cs4280_query_format, + .set_format = cs4280_set_format, .round_blocksize = cs428x_round_blocksize, .halt_output = cs4280_halt_output, .halt_input = cs4280_halt_input, @@ -171,7 +169,6 @@ static const struct audio_hw_if cs4280_h .allocm = cs428x_malloc, .freem = cs428x_free, .round_buffersize = cs428x_round_buffersize, - .mappage = cs428x_mappage, .get_props = cs428x_get_props, .trigger_output = cs4280_trigger_output, .trigger_input = cs4280_trigger_input, @@ -205,6 +202,26 @@ static struct audio_device cs4280_device "cs4280" }; +/* + * XXX recording must be 16bit stereo and sample rate range from + * 11025Hz to 48000Hz. However, it looks like to work with 8000Hz, + * although data sheets say lower limit is 11025Hz. + * XXX The combination of available formats is complicated, so I use + * a common format only. Please fix it if not suitable. + */ +static const struct audio_format cs4280_formats[] = { + { + .mode = AUMODE_PLAY | AUMODE_RECORD, + .encoding = AUDIO_ENCODING_SLINEAR_LE, + .validbits = 16, + .precision = 16, + .channels = 2, + .channel_mask = AUFMT_STEREO, + .frequency_type = 0, + .frequency = { 8000, 48000 }, + } +}; +#define CS4280_NFORMATS __arraycount(cs4280_formats) static int cs4280_match(device_t parent, cfdata_t match, void *aux) @@ -550,161 +567,20 @@ cs4280_intr(void *p) } static int -cs4280_query_encoding(void *addr, struct audio_encoding *fp) +cs4280_query_format(void *addr, audio_format_query_t *afp) { - switch (fp->index) { - case 0: - strcpy(fp->name, AudioEulinear); - fp->encoding = AUDIO_ENCODING_ULINEAR; - fp->precision = 8; - fp->flags = 0; - break; - case 1: - strcpy(fp->name, AudioEmulaw); - fp->encoding = AUDIO_ENCODING_ULAW; - fp->precision = 8; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 2: - strcpy(fp->name, AudioEalaw); - fp->encoding = AUDIO_ENCODING_ALAW; - fp->precision = 8; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 3: - strcpy(fp->name, AudioEslinear); - fp->encoding = AUDIO_ENCODING_SLINEAR; - fp->precision = 8; - fp->flags = 0; - break; - case 4: - strcpy(fp->name, AudioEslinear_le); - fp->encoding = AUDIO_ENCODING_SLINEAR_LE; - fp->precision = 16; - fp->flags = 0; - break; - case 5: - strcpy(fp->name, AudioEulinear_le); - fp->encoding = AUDIO_ENCODING_ULINEAR_LE; - fp->precision = 16; - fp->flags = 0; - break; - case 6: - strcpy(fp->name, AudioEslinear_be); - fp->encoding = AUDIO_ENCODING_SLINEAR_BE; - fp->precision = 16; - fp->flags = 0; - break; - case 7: - strcpy(fp->name, AudioEulinear_be); - fp->encoding = AUDIO_ENCODING_ULINEAR_BE; - fp->precision = 16; - fp->flags = 0; - break; - default: - return EINVAL; - } - return 0; + + return audio_query_format(cs4280_formats, CS4280_NFORMATS, afp); } static int -cs4280_set_params(void *addr, int setmode, int usemode, - audio_params_t *play, audio_params_t *rec, stream_filter_list_t *pfil, - stream_filter_list_t *rfil) +cs4280_set_format(void *addr, int setmode, + const audio_params_t *play, const audio_params_t *rec, + audio_filter_reg_t *pfil, audio_filter_reg_t *rfil) { - audio_params_t hw; struct cs428x_softc *sc; - struct audio_params *p; - stream_filter_list_t *fil; - int mode; sc = addr; - for (mode = AUMODE_RECORD; mode != -1; - mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1 ) { - if ((setmode & mode) == 0) - continue; - - p = mode == AUMODE_PLAY ? play : rec; - - if (p == play) { - DPRINTFN(5,("play: sample=%d precision=%d channels=%d\n", - p->sample_rate, p->precision, p->channels)); - /* play back data format may be 8- or 16-bit and - * either stereo or mono. - * playback rate may range from 8000Hz to 48000Hz - */ - if (p->sample_rate < 8000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2) ) { - return EINVAL; - } - } else { - DPRINTFN(5,("rec: sample=%d precision=%d channels=%d\n", - p->sample_rate, p->precision, p->channels)); - /* capture data format must be 16bit stereo - * and sample rate range from 11025Hz to 48000Hz. - * - * XXX: it looks like to work with 8000Hz, - * although data sheets say lower limit is - * 11025 Hz. - */ - - if (p->sample_rate < 8000 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2) ) { - return EINVAL; - } - } - fil = mode == AUMODE_PLAY ? pfil : rfil; - hw = *p; - hw.encoding = AUDIO_ENCODING_SLINEAR_LE; - - /* capturing data is slinear */ - switch (p->encoding) { - case AUDIO_ENCODING_SLINEAR_BE: - if (mode == AUMODE_RECORD && p->precision == 16) { - fil->append(fil, swap_bytes, &hw); - } - break; - case AUDIO_ENCODING_SLINEAR_LE: - break; - case AUDIO_ENCODING_ULINEAR_BE: - if (mode == AUMODE_RECORD) { - fil->append(fil, p->precision == 16 - ? swap_bytes_change_sign16 - : change_sign8, &hw); - } - break; - case AUDIO_ENCODING_ULINEAR_LE: - if (mode == AUMODE_RECORD) { - fil->append(fil, p->precision == 16 - ? change_sign16 : change_sign8, - &hw); - } - break; - case AUDIO_ENCODING_ULAW: - if (mode == AUMODE_PLAY) { - hw.precision = 16; - hw.validbits = 16; - fil->append(fil, mulaw_to_linear16, &hw); - } else { - fil->append(fil, linear8_to_mulaw, &hw); - } - break; - case AUDIO_ENCODING_ALAW: - if (mode == AUMODE_PLAY) { - hw.precision = 16; - hw.validbits = 16; - fil->append(fil, alaw_to_linear16, &hw); - } else { - fil->append(fil, linear8_to_alaw, &hw); - } - break; - default: - return EINVAL; - } - } - /* set sample rate */ cs4280_set_dac_rate(sc, play->sample_rate); cs4280_set_adc_rate(sc, rec->sample_rate); @@ -815,19 +691,8 @@ cs4280_trigger_output(void *addr, void * /* set PFIE */ pfie = BA1READ4(sc, CS4280_PFIE) & ~PFIE_MASK; - - if (param->precision == 8) - pfie |= PFIE_8BIT; - if (param->channels == 1) - pfie |= PFIE_MONO; - - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_SLINEAR_BE) + if (param->encoding == AUDIO_ENCODING_SLINEAR_BE) pfie |= PFIE_SWAPPED; - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_ULINEAR_LE) - pfie |= PFIE_UNSIGNED; - BA1WRITE4(sc, CS4280_PFIE, pfie | PFIE_PI_ENABLE); sc->sc_prate = param->sample_rate; Index: src/sys/dev/pci/cs4281.c diff -u src/sys/dev/pci/cs4281.c:1.54 src/sys/dev/pci/cs4281.c:1.54.2.1 --- src/sys/dev/pci/cs4281.c:1.54 Sat Mar 16 12:09:58 2019 +++ src/sys/dev/pci/cs4281.c Sun Apr 21 07:49:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cs4281.c,v 1.54 2019/03/16 12:09:58 isaki Exp $ */ +/* $NetBSD: cs4281.c,v 1.54.2.1 2019/04/21 07:49:16 isaki Exp $ */ /* * Copyright (c) 2000 Tatoku Ogaito. All rights reserved. @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1.54 2019/03/16 12:09:58 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1.54.2.1 2019/04/21 07:49:16 isaki Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -61,8 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1 #include <sys/audioio.h> #include <dev/audio_if.h> #include <dev/midi_if.h> -#include <dev/mulaw.h> -#include <dev/auconv.h> #include <dev/ic/ac97reg.h> #include <dev/ic/ac97var.h> @@ -83,10 +81,10 @@ __KERNEL_RCSID(0, "$NetBSD: cs4281.c,v 1 static int cs4281_match(device_t, cfdata_t, void *); static void cs4281_attach(device_t, device_t, void *); static int cs4281_intr(void *); -static int cs4281_query_encoding(void *, struct audio_encoding *); -static int cs4281_set_params(void *, int, int, audio_params_t *, - audio_params_t *, stream_filter_list_t *, - stream_filter_list_t *); +static int cs4281_query_format(void *, audio_format_query_t *); +static int cs4281_set_format(void *, int, + const audio_params_t *, const audio_params_t *, + audio_filter_reg_t *, audio_filter_reg_t *); static int cs4281_halt_output(void *); static int cs4281_halt_input(void *); static int cs4281_getdev(void *, struct audio_device *); @@ -110,8 +108,8 @@ static bool cs4281_suspend(device_t, con static bool cs4281_resume(device_t, const pmf_qual_t *); static const struct audio_hw_if cs4281_hw_if = { - .query_encoding = cs4281_query_encoding, - .set_params = cs4281_set_params, + .query_format = cs4281_query_format, + .set_format = cs4281_set_format, .round_blocksize = cs428x_round_blocksize, .halt_output = cs4281_halt_output, .halt_input = cs4281_halt_input, @@ -122,7 +120,6 @@ static const struct audio_hw_if cs4281_h .allocm = cs428x_malloc, .freem = cs428x_free, .round_buffersize = cs428x_round_buffersize, - .mappage = cs428x_mappage, .get_props = cs428x_get_props, .trigger_output = cs4281_trigger_output, .trigger_input = cs4281_trigger_input, @@ -156,6 +153,19 @@ static struct audio_device cs4281_device "cs4281" }; +static const struct audio_format cs4281_formats[] = { + { + .mode = AUMODE_PLAY | AUMODE_RECORD, + .encoding = AUDIO_ENCODING_SLINEAR_NE, + .validbits = 16, + .precision = 16, + .channels = 2, + .channel_mask = AUFMT_STEREO, + .frequency_type = 6, + .frequency = { 8000, 11025, 16000, 22050, 44100, 48000 }, + }, +}; +#define CS4281_NFORMATS __arraycount(cs4281_formats) static int cs4281_match(device_t parent, cfdata_t match, void *aux) @@ -384,129 +394,20 @@ cs4281_intr(void *p) } static int -cs4281_query_encoding(void *addr, struct audio_encoding *fp) +cs4281_query_format(void *addr, audio_format_query_t *afp) { - switch (fp->index) { - case 0: - strcpy(fp->name, AudioEulinear); - fp->encoding = AUDIO_ENCODING_ULINEAR; - fp->precision = 8; - fp->flags = 0; - break; - case 1: - strcpy(fp->name, AudioEmulaw); - fp->encoding = AUDIO_ENCODING_ULAW; - fp->precision = 8; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 2: - strcpy(fp->name, AudioEalaw); - fp->encoding = AUDIO_ENCODING_ALAW; - fp->precision = 8; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 3: - strcpy(fp->name, AudioEslinear); - fp->encoding = AUDIO_ENCODING_SLINEAR; - fp->precision = 8; - fp->flags = 0; - break; - case 4: - strcpy(fp->name, AudioEslinear_le); - fp->encoding = AUDIO_ENCODING_SLINEAR_LE; - fp->precision = 16; - fp->flags = 0; - break; - case 5: - strcpy(fp->name, AudioEulinear_le); - fp->encoding = AUDIO_ENCODING_ULINEAR_LE; - fp->precision = 16; - fp->flags = 0; - break; - case 6: - strcpy(fp->name, AudioEslinear_be); - fp->encoding = AUDIO_ENCODING_SLINEAR_BE; - fp->precision = 16; - fp->flags = 0; - break; - case 7: - strcpy(fp->name, AudioEulinear_be); - fp->encoding = AUDIO_ENCODING_ULINEAR_BE; - fp->precision = 16; - fp->flags = 0; - break; - default: - return EINVAL; - } - return 0; + return audio_query_format(cs4281_formats, CS4281_NFORMATS, afp); } static int -cs4281_set_params(void *addr, int setmode, int usemode, - audio_params_t *play, audio_params_t *rec, stream_filter_list_t *pfil, - stream_filter_list_t *rfil) +cs4281_set_format(void *addr, int setmode, + const audio_params_t *play, const audio_params_t *rec, + audio_filter_reg_t *pfil, audio_filter_reg_t *rfil) { - audio_params_t hw; struct cs428x_softc *sc; - audio_params_t *p; - stream_filter_list_t *fil; - int mode; sc = addr; - for (mode = AUMODE_RECORD; mode != -1; - mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) { - if ((setmode & mode) == 0) - continue; - - p = mode == AUMODE_PLAY ? play : rec; - - if (p == play) { - DPRINTFN(5, - ("play: sample=%u precision=%u channels=%u\n", - p->sample_rate, p->precision, p->channels)); - if (p->sample_rate < 6023 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) { - return EINVAL; - } - } else { - DPRINTFN(5, - ("rec: sample=%u precision=%u channels=%u\n", - p->sample_rate, p->precision, p->channels)); - if (p->sample_rate < 6023 || p->sample_rate > 48000 || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) { - return EINVAL; - } - } - hw = *p; - fil = mode == AUMODE_PLAY ? pfil : rfil; - - switch (p->encoding) { - case AUDIO_ENCODING_SLINEAR_BE: - break; - case AUDIO_ENCODING_SLINEAR_LE: - break; - case AUDIO_ENCODING_ULINEAR_BE: - break; - case AUDIO_ENCODING_ULINEAR_LE: - break; - case AUDIO_ENCODING_ULAW: - hw.encoding = AUDIO_ENCODING_SLINEAR_LE; - fil->append(fil, mode == AUMODE_PLAY ? mulaw_to_linear8 - : linear8_to_mulaw, &hw); - break; - case AUDIO_ENCODING_ALAW: - hw.encoding = AUDIO_ENCODING_SLINEAR_LE; - fil->append(fil, mode == AUMODE_PLAY ? alaw_to_linear8 - : linear8_to_alaw, &hw); - break; - default: - return EINVAL; - } - } - /* set sample rate */ cs4281_set_dac_rate(sc, play->sample_rate); cs4281_set_adc_rate(sc, rec->sample_rate); @@ -607,16 +508,8 @@ cs4281_trigger_output(void *addr, void * /* set playback format */ fmt = BA0READ4(sc, CS4281_DMR0) & ~DMRn_FMTMSK; - if (param->precision == 8) - fmt |= DMRn_SIZE8; - if (param->channels == 1) - fmt |= DMRn_MONO; - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_SLINEAR_BE) + if (param->encoding == AUDIO_ENCODING_SLINEAR_BE) fmt |= DMRn_BEND; - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_ULINEAR_LE) - fmt |= DMRn_USIGN; BA0WRITE4(sc, CS4281_DMR0, fmt); /* set sample rate */ @@ -695,16 +588,8 @@ cs4281_trigger_input(void *addr, void *s /* set recording format */ fmt = BA0READ4(sc, CS4281_DMR1) & ~DMRn_FMTMSK; - if (param->precision == 8) - fmt |= DMRn_SIZE8; - if (param->channels == 1) - fmt |= DMRn_MONO; - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_SLINEAR_BE) + if (param->encoding == AUDIO_ENCODING_SLINEAR_BE) fmt |= DMRn_BEND; - if (param->encoding == AUDIO_ENCODING_ULINEAR_BE || - param->encoding == AUDIO_ENCODING_ULINEAR_LE) - fmt |= DMRn_USIGN; BA0WRITE4(sc, CS4281_DMR1, fmt); /* set sample rate */ Index: src/sys/dev/pci/cs428x.c diff -u src/sys/dev/pci/cs428x.c:1.18 src/sys/dev/pci/cs428x.c:1.18.14.1 --- src/sys/dev/pci/cs428x.c:1.18 Thu Jun 1 02:45:11 2017 +++ src/sys/dev/pci/cs428x.c Sun Apr 21 07:49:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cs428x.c,v 1.18 2017/06/01 02:45:11 chs Exp $ */ +/* $NetBSD: cs428x.c,v 1.18.14.1 2019/04/21 07:49:16 isaki Exp $ */ /* * Copyright (c) 2000 Tatoku Ogaito. All rights reserved. @@ -33,7 +33,7 @@ /* Common functions for CS4280 and CS4281 */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cs428x.c,v 1.18 2017/06/01 02:45:11 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cs428x.c,v 1.18.14.1 2019/04/21 07:49:16 isaki Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -165,29 +165,6 @@ cs428x_round_buffersize(void *addr, int return size; } -paddr_t -cs428x_mappage(void *addr, void *mem, off_t off, int prot) -{ - struct cs428x_softc *sc; - struct cs428x_dma *p; - - sc = addr; - - if (off < 0) - return -1; - - for (p = sc->sc_dmas; p && BUFADDR(p) != mem; p = p->next) - continue; - - if (p == NULL) { - DPRINTF(("cs428x_mappage: bad buffer address\n")); - return -1; - } - - return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs, - off, prot, BUS_DMA_WAITOK)); -} - int cs428x_get_props(void *addr) { Index: src/sys/dev/pci/cs428x.h diff -u src/sys/dev/pci/cs428x.h:1.16 src/sys/dev/pci/cs428x.h:1.16.42.1 --- src/sys/dev/pci/cs428x.h:1.16 Sat Oct 27 17:18:31 2012 +++ src/sys/dev/pci/cs428x.h Sun Apr 21 07:49:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cs428x.h,v 1.16 2012/10/27 17:18:31 chs Exp $ */ +/* $NetBSD: cs428x.h,v 1.16.42.1 2019/04/21 07:49:16 isaki Exp $ */ /* * Copyright (c) 2000 Tatoku Ogaito. All rights reserved. @@ -184,7 +184,6 @@ int cs428x_query_devinfo(void *, mixer_ void *cs428x_malloc(void *, int, size_t); size_t cs428x_round_buffersize(void *, int, size_t); void cs428x_free(void *, void *, size_t); -paddr_t cs428x_mappage(void *, void *, off_t, int); void cs428x_get_locks(void *, kmutex_t **, kmutex_t **); /* internal functions */