Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/isaki-audio2]: src/sys/dev/pci Adapt to audio2.
details: https://anonhg.NetBSD.org/src/rev/35d98172cb04
branches: isaki-audio2
changeset: 998510:35d98172cb04
user: isaki <isaki%NetBSD.org@localhost>
date: Sun Apr 28 06:36:50 2019 +0000
description:
Adapt to audio2.
- Searching nearest frequency is unnecessary in audio2.
diffstat:
sys/dev/pci/fms.c | 214 ++++++++++++-----------------------------------------
1 files changed, 51 insertions(+), 163 deletions(-)
diffs (truncated from 302 to 300 lines):
diff -r 653175d8464e -r 35d98172cb04 sys/dev/pci/fms.c
--- a/sys/dev/pci/fms.c Sun Apr 28 05:07:00 2019 +0000
+++ b/sys/dev/pci/fms.c Sun Apr 28 06:36:50 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fms.c,v 1.45.2.1 2019/04/21 05:11:22 isaki Exp $ */
+/* $NetBSD: fms.c,v 1.45.2.2 2019/04/28 06:36:50 isaki Exp $ */
/*-
* Copyright (c) 1999, 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fms.c,v 1.45.2.1 2019/04/21 05:11:22 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fms.c,v 1.45.2.2 2019/04/28 06:36:50 isaki Exp $");
#include "mpu.h"
@@ -52,8 +52,6 @@
#include <dev/pci/pcivar.h>
#include <dev/audio_if.h>
-#include <dev/mulaw.h>
-#include <dev/auconv.h>
#include <dev/ic/ac97var.h>
#include <dev/ic/mpuvar.h>
@@ -75,10 +73,10 @@
static void fms_attach(device_t, device_t, void *);
static int fms_intr(void *);
-static int fms_query_encoding(void *, struct audio_encoding *);
-static int fms_set_params(void *, int, int, audio_params_t *,
- audio_params_t *, stream_filter_list_t *,
- stream_filter_list_t *);
+static int fms_query_format(void *, audio_format_query_t *);
+static int fms_set_format(void *, int,
+ const audio_params_t *, const audio_params_t *,
+ audio_filter_reg_t *, audio_filter_reg_t *);
static int fms_round_blocksize(void *, int, int, const audio_params_t *);
static int fms_halt_output(void *);
static int fms_halt_input(void *);
@@ -88,8 +86,6 @@
static int fms_query_devinfo(void *, mixer_devinfo_t *);
static void *fms_malloc(void *, int, size_t);
static void fms_free(void *, void *, size_t);
-static size_t fms_round_buffersize(void *, int, size_t);
-static paddr_t fms_mappage(void *, void *, off_t, int);
static int fms_get_props(void *);
static int fms_trigger_output(void *, void *, void *, int,
void (*)(void *), void *,
@@ -108,10 +104,29 @@
"fms"
};
+/*
+ * The frequency list in this format is also referred from fms_rate2index().
+ * So don't rearrange or delete entries.
+ */
+static const struct audio_format fms_formats[] = {
+ {
+ .mode = AUMODE_PLAY | AUMODE_RECORD,
+ .encoding = AUDIO_ENCODING_SLINEAR_LE,
+ .validbits = 16,
+ .precision = 16,
+ .channels = 2,
+ .channel_mask = AUFMT_STEREO,
+ .frequency_type = 11,
+ .frequency = { 5500, 8000, 9600, 11025, 16000, 19200,
+ 22050, 32000, 38400, 44100, 48000},
+ },
+};
+#define FMS_NFORMATS __arraycount(fms_formats)
+
static const struct audio_hw_if fms_hw_if = {
- .query_encoding = fms_query_encoding,
- .set_params = fms_set_params,
+ .query_format = fms_query_format,
+ .set_format = fms_set_format,
.round_blocksize = fms_round_blocksize,
.halt_output = fms_halt_output,
.halt_input = fms_halt_input,
@@ -121,8 +136,6 @@
.query_devinfo = fms_query_devinfo,
.allocm = fms_malloc,
.freem = fms_free,
- .round_buffersize = fms_round_buffersize,
- .mappage = fms_mappage,
.get_props = fms_get_props,
.trigger_output = fms_trigger_output,
.trigger_input = fms_trigger_input,
@@ -133,6 +146,7 @@
static int fms_read_codec(void *, uint8_t, uint16_t *);
static int fms_write_codec(void *, uint8_t, uint16_t);
static int fms_reset_codec(void *);
+static int fms_rate2index(u_int);
#define FM_PCM_VOLUME 0x00
#define FM_FM_VOLUME 0x02
@@ -462,145 +476,45 @@
}
static int
-fms_query_encoding(void *addr, struct audio_encoding *fp)
+fms_query_format(void *addr, audio_format_query_t *afp)
{
- switch (fp->index) {
- case 0:
- strcpy(fp->name, AudioEmulaw);
- fp->encoding = AUDIO_ENCODING_ULAW;
- fp->precision = 8;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- case 1:
- strcpy(fp->name, AudioEslinear_le);
- fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
- fp->precision = 16;
- fp->flags = 0;
- return 0;
- case 2:
- strcpy(fp->name, AudioEulinear);
- fp->encoding = AUDIO_ENCODING_ULINEAR;
- fp->precision = 8;
- fp->flags = 0;
- return 0;
- case 3:
- strcpy(fp->name, AudioEalaw);
- fp->encoding = AUDIO_ENCODING_ALAW;
- fp->precision = 8;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- case 4:
- strcpy(fp->name, AudioEulinear_le);
- fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
- fp->precision = 16;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- case 5:
- strcpy(fp->name, AudioEslinear);
- fp->encoding = AUDIO_ENCODING_SLINEAR;
- fp->precision = 8;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- case 6:
- strcpy(fp->name, AudioEulinear_be);
- fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
- fp->precision = 16;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- case 7:
- strcpy(fp->name, AudioEslinear_be);
- fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
- fp->precision = 16;
- fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
- return 0;
- default:
- return EINVAL;
- }
+ return audio_query_format(fms_formats, FMS_NFORMATS, afp);
}
-/*
- * Range below -limit- is set to -rate-
- * What a pity FM801 does not have 24000
- * 24000 -> 22050 sounds rather poor
- */
-static struct {
- int limit;
- int rate;
-} const fms_rates[11] = {
- { 6600, 5500 },
- { 8750, 8000 },
- { 10250, 9600 },
- { 13200, 11025 },
- { 17500, 16000 },
- { 20500, 19200 },
- { 26500, 22050 },
- { 35000, 32000 },
- { 41000, 38400 },
- { 46000, 44100 },
- { 48000, 48000 },
- /* anything above -> 48000 */
-};
+/* Return index number of sample_rate */
+static int
+fms_rate2index(u_int sample_rate)
+{
+ int i;
-#define FMS_NFORMATS 4
-#define FMS_FORMAT(enc, prec, ch, chmask) \
- { \
- .mode = AUMODE_PLAY | AUMODE_RECORD, \
- .encoding = (enc), \
- .validbits = (prec), \
- .precision = (prec), \
- .channels = (ch), \
- .channel_mask = (chmask), \
- .frequency_type = 11, \
- .frequency = { 5500, 8000, 9600, 11025, 16000, 19200, \
- 22050, 32000, 38400, 44100, 48000}, \
+ for (i = 0; i < fms_formats[0].frequency_type; i++) {
+ if (sample_rate == fms_formats[0].frequency[i])
+ return i;
}
-static const struct audio_format fms_formats[FMS_NFORMATS] = {
- FMS_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 16, 2, AUFMT_STEREO),
- FMS_FORMAT(AUDIO_ENCODING_SLINEAR_LE, 16, 1, AUFMT_MONAURAL),
- FMS_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 8, 2, AUFMT_STEREO),
- FMS_FORMAT(AUDIO_ENCODING_ULINEAR_LE, 8, 1, AUFMT_MONAURAL),
-};
+
+ /* NOTREACHED */
+ panic("fms_format.frequency mismatch?\n");
+}
static int
-fms_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)
+fms_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)
{
struct fms_softc *sc;
- int i, index;
sc = addr;
if (setmode & AUMODE_PLAY) {
- for (i = 0; i < 10 && play->sample_rate > fms_rates[i].limit;
- i++)
- continue;
- play->sample_rate = fms_rates[i].rate;
- index = auconv_set_converter(fms_formats, FMS_NFORMATS,
- AUMODE_PLAY, play, FALSE, pfil);
- if (index < 0)
- return EINVAL;
- sc->sc_play_reg = i << 8;
- if (fms_formats[index].channels == 2)
- sc->sc_play_reg |= FM_PLAY_STEREO;
- if (fms_formats[index].precision == 16)
- sc->sc_play_reg |= FM_PLAY_16BIT;
+ sc->sc_play_reg = fms_rate2index(play->sample_rate) << 8;
+ sc->sc_play_reg |= FM_PLAY_STEREO;
+ sc->sc_play_reg |= FM_PLAY_16BIT;
}
if (setmode & AUMODE_RECORD) {
- for (i = 0; i < 10 && rec->sample_rate > fms_rates[i].limit;
- i++)
- continue;
- rec->sample_rate = fms_rates[i].rate;
- index = auconv_set_converter(fms_formats, FMS_NFORMATS,
- AUMODE_RECORD, rec, FALSE, rfil);
- if (index < 0)
- return EINVAL;
- sc->sc_rec_reg = i << 8;
- if (fms_formats[index].channels == 2)
- sc->sc_rec_reg |= FM_REC_STEREO;
- if (fms_formats[index].precision == 16)
- sc->sc_rec_reg |= FM_REC_16BIT;
+ sc->sc_rec_reg = fms_rate2index(rec->sample_rate) << 8;
+ sc->sc_rec_reg |= FM_REC_STEREO;
+ sc->sc_rec_reg |= FM_REC_16BIT;
}
return 0;
@@ -748,32 +662,6 @@
panic("fms_free: trying to free unallocated memory");
}
-static size_t
-fms_round_buffersize(void *addr, int direction, size_t size)
-{
-
- return size;
-}
-
-static paddr_t
-fms_mappage(void *addr, void *mem, off_t off, int prot)
-{
- struct fms_softc *sc;
- struct fms_dma *p;
-
- sc = addr;
- if (off < 0)
- return -1;
-
- for (p = sc->sc_dmas; p && p->addr != mem; p = p->next)
- continue;
- if (p == NULL)
- return -1;
-
- return bus_dmamem_mmap(sc->sc_dmat, &p->seg, 1, off, prot,
- BUS_DMA_WAITOK);
-}
-
static int
Home |
Main Index |
Thread Index |
Old Index