Module Name: src Committed By: isaki Date: Sun Apr 28 04:45:34 UTC 2019
Modified Files: src/sys/dev/pci [isaki-audio2]: eso.c esoreg.h Log Message: Adapt to audio2. - Select a few typical frequencies which doesn't have rounding error instead of whole range. To generate a diff of this commit: cvs rdiff -u -r1.69.2.1 -r1.69.2.2 src/sys/dev/pci/eso.c cvs rdiff -u -r1.8 -r1.8.168.1 src/sys/dev/pci/esoreg.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/eso.c diff -u src/sys/dev/pci/eso.c:1.69.2.1 src/sys/dev/pci/eso.c:1.69.2.2 --- src/sys/dev/pci/eso.c:1.69.2.1 Sun Apr 21 05:11:22 2019 +++ src/sys/dev/pci/eso.c Sun Apr 28 04:45:34 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: eso.c,v 1.69.2.1 2019/04/21 05:11:22 isaki Exp $ */ +/* $NetBSD: eso.c,v 1.69.2.2 2019/04/28 04:45:34 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: eso.c,v 1.69.2.1 2019/04/21 05:11:22 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: eso.c,v 1.69.2.2 2019/04/28 04:45:34 isaki Exp $"); #include "mpu.h" @@ -80,9 +80,6 @@ __KERNEL_RCSID(0, "$NetBSD: eso.c,v 1.69 #include <sys/audioio.h> #include <dev/audio_if.h> -#include <dev/mulaw.h> -#include <dev/auconv.h> - #include <dev/ic/mpuvar.h> #include <dev/ic/i8237reg.h> #include <dev/pci/esoreg.h> @@ -131,10 +128,10 @@ CFATTACH_DECL_NEW(eso, sizeof (struct es static int eso_intr(void *); /* MI audio layer interface */ -static int eso_query_encoding(void *, struct audio_encoding *); -static int eso_set_params(void *, int, int, audio_params_t *, - audio_params_t *, stream_filter_list_t *, - stream_filter_list_t *); +static int eso_query_format(void *, audio_format_query_t *); +static int eso_set_format(void *, int, + const audio_params_t *, const audio_params_t *, + audio_filter_reg_t *, audio_filter_reg_t *); static int eso_round_blocksize(void *, int, int, const audio_params_t *); static int eso_halt_output(void *); static int eso_halt_input(void *); @@ -145,7 +142,6 @@ static int eso_query_devinfo(void *, mix static void * eso_allocm(void *, int, size_t); static void eso_freem(void *, void *, size_t); static size_t eso_round_buffersize(void *, int, size_t); -static paddr_t eso_mappage(void *, void *, off_t, int); static int eso_get_props(void *); static int eso_trigger_output(void *, void *, void *, int, void (*)(void *), void *, const audio_params_t *); @@ -154,8 +150,8 @@ static int eso_trigger_input(void *, voi static void eso_get_locks(void *, kmutex_t **, kmutex_t **); static const struct audio_hw_if eso_hw_if = { - .query_encoding = eso_query_encoding, - .set_params = eso_set_params, + .query_format = eso_query_format, + .set_format = eso_set_format, .round_blocksize = eso_round_blocksize, .halt_output = eso_halt_output, .halt_input = eso_halt_input, @@ -166,7 +162,6 @@ static const struct audio_hw_if eso_hw_i .allocm = eso_allocm, .freem = eso_freem, .round_buffersize = eso_round_buffersize, - .mappage = eso_mappage, .get_props = eso_get_props, .trigger_output = eso_trigger_output, .trigger_input = eso_trigger_input, @@ -179,28 +174,23 @@ static const char * const eso_rev2model[ "ES1946 Revision E" }; -#define ESO_NFORMATS 8 -#define ESO_FORMAT(enc, prec, ch, chmask) \ - { \ - .mode = AUMODE_PLAY | AUMODE_RECORD, \ - .encoding = (enc), \ - .validbits = (prec), \ - .precision = (prec), \ - .channels = (ch), \ - .channel_mask = (chmask), \ - .frequency_type = 0, \ - .frequency = { ESO_MINRATE, ESO_MAXRATE }, \ - } -static const struct audio_format eso_formats[ESO_NFORMATS] = { - ESO_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 16, 2, AUFMT_STEREO), - ESO_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 16, 1, AUFMT_MONAURAL), - ESO_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 16, 2, AUFMT_STEREO), - ESO_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 16, 1, AUFMT_MONAURAL), - ESO_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 8, 2, AUFMT_STEREO), - ESO_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 8, 1, AUFMT_MONAURAL), - ESO_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 8, 2, AUFMT_STEREO), - ESO_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 8, 1, AUFMT_MONAURAL), +/* + * XXX The HW actually supports more frequencies but I select a few + * typical frequencies which does not include rounding error. + */ +static const struct audio_format eso_formats[] = { + { + .mode = AUMODE_PLAY | AUMODE_RECORD, + .encoding = AUDIO_ENCODING_SLINEAR_LE, + .validbits = 16, + .precision = 16, + .channels = 2, + .channel_mask = AUFMT_STEREO, + .frequency_type = 4, + .frequency = { 8000, 22050, 44100, 48000 }, + }, }; +#define ESO_NFORMATS __arraycount(eso_formats) /* @@ -700,76 +690,21 @@ eso_reset(struct eso_softc *sc) } static int -eso_query_encoding(void *hdl, struct audio_encoding *fp) +eso_query_format(void *hdl, 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 = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 5: - strcpy(fp->name, AudioEulinear_le); - fp->encoding = AUDIO_ENCODING_ULINEAR_LE; - fp->precision = 16; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 6: - strcpy(fp->name, AudioEslinear_be); - fp->encoding = AUDIO_ENCODING_SLINEAR_BE; - fp->precision = 16; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - case 7: - strcpy(fp->name, AudioEulinear_be); - fp->encoding = AUDIO_ENCODING_ULINEAR_BE; - fp->precision = 16; - fp->flags = AUDIO_ENCODINGFLAG_EMULATED; - break; - default: - return EINVAL; - } - - return 0; + return audio_query_format(eso_formats, ESO_NFORMATS, afp); } static int -eso_set_params(void *hdl, int setmode, int usemode, - audio_params_t *play, audio_params_t *rec, stream_filter_list_t *pfil, - stream_filter_list_t *rfil) +eso_set_format(void *hdl, int setmode, + const audio_params_t *play, const audio_params_t *rec, + audio_filter_reg_t *pfil, audio_filter_reg_t *rfil) { struct eso_softc *sc; - struct audio_params *p; - stream_filter_list_t *fil; - int mode, r[2], rd[2], ar[2], clk; + const struct audio_params *p; + int mode; unsigned int srg, fltdiv; - int i; sc = hdl; for (mode = AUMODE_RECORD; mode != -1; @@ -779,38 +714,23 @@ eso_set_params(void *hdl, int setmode, i p = (mode == AUMODE_PLAY) ? play : rec; - if (p->sample_rate < ESO_MINRATE || - p->sample_rate > ESO_MAXRATE || - (p->precision != 8 && p->precision != 16) || - (p->channels != 1 && p->channels != 2)) + /* We use a few fixed rate which doesn't have rounding error. */ + switch (p->sample_rate) { + case 8000: + case 48000: + srg = (128 - ESO_CLK1 / p->sample_rate); + srg |= ESO_CLK1_SELECT; + break; + case 22050: + case 44100: + srg = (128 - ESO_CLK0 / p->sample_rate); + break; + default: + /* NOTREACHED */ return EINVAL; - - /* - * We'll compute both possible sample rate dividers and pick - * the one with the least error. - */ -#define ABS(x) ((x) < 0 ? -(x) : (x)) - r[0] = ESO_CLK0 / - (128 - (rd[0] = 128 - ESO_CLK0 / p->sample_rate)); - r[1] = ESO_CLK1 / - (128 - (rd[1] = 128 - ESO_CLK1 / p->sample_rate)); - - ar[0] = p->sample_rate - r[0]; - ar[1] = p->sample_rate - r[1]; - clk = ABS(ar[0]) > ABS(ar[1]) ? 1 : 0; - srg = rd[clk] | (clk == 1 ? ESO_CLK1_SELECT : 0x00); - + } /* Roll-off frequency of 87%, as in the ES1888 driver. */ - fltdiv = 256 - 200279L / r[clk]; - - /* Update to reflect the possibly inexact rate. */ - p->sample_rate = r[clk]; - - fil = (mode == AUMODE_PLAY) ? pfil : rfil; - i = auconv_set_converter(eso_formats, ESO_NFORMATS, - mode, p, FALSE, fil); - if (i < 0) - return EINVAL; + fltdiv = 256 - 200279L / p->sample_rate; mutex_spin_enter(&sc->sc_intr_lock); if (mode == AUMODE_RECORD) { @@ -825,8 +745,6 @@ eso_set_params(void *hdl, int setmode, i eso_write_mixreg(sc, ESO_MIXREG_A2FLTDIV, fltdiv); } mutex_spin_exit(&sc->sc_intr_lock); -#undef ABS - } return 0; @@ -1714,21 +1632,6 @@ eso_round_buffersize(void *hdl, int dire return bufsize; } -static paddr_t -eso_mappage(void *hdl, void *addr, off_t offs, int prot) -{ - struct eso_softc *sc; - struct eso_dma *ed; - - sc = hdl; - if (offs < 0) - return -1; - ed = eso_kva2dma(sc, addr); - - return bus_dmamem_mmap(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs, - offs, prot, BUS_DMA_WAITOK); -} - /* ARGSUSED */ static int eso_get_props(void *hdl) Index: src/sys/dev/pci/esoreg.h diff -u src/sys/dev/pci/esoreg.h:1.8 src/sys/dev/pci/esoreg.h:1.8.168.1 --- src/sys/dev/pci/esoreg.h:1.8 Sun Dec 11 12:22:49 2005 +++ src/sys/dev/pci/esoreg.h Sun Apr 28 04:45:34 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: esoreg.h,v 1.8 2005/12/11 12:22:49 christos Exp $ */ +/* $NetBSD: esoreg.h,v 1.8.168.1 2019/04/28 04:45:34 isaki Exp $ */ /* * Copyright (c) 1999 Klaus J. Klein @@ -231,8 +231,6 @@ * Sample rate related constants. * Note: the use of these clock sources must be explicitly enabled for Audio 1. */ -#define ESO_MINRATE 6000 -#define ESO_MAXRATE 48000 #define ESO_CLK0 793800L /* Clock source 0 frequency */ #define ESO_CLK1 768000L /* Clock source 1 frequency */ #define ESO_CLK1_SELECT 0x80 /* MSb of divider selects clock src */