Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/isaki-audio2]: src/sys Adapt to audio2.
details: https://anonhg.NetBSD.org/src/rev/cfb9b40b205d
branches: isaki-audio2
changeset: 455984:cfb9b40b205d
user: isaki <isaki%NetBSD.org@localhost>
date: Sun Apr 21 14:00:19 2019 +0000
description:
Adapt to audio2.
diffstat:
sys/arch/x68k/dev/vs.c | 207 +++++++---------------------
sys/arch/x68k/dev/vsvar.h | 4 +-
sys/dev/ic/msm6258.c | 330 ++++++---------------------------------------
sys/dev/ic/msm6258var.h | 16 +-
4 files changed, 117 insertions(+), 440 deletions(-)
diffs (truncated from 760 to 300 lines):
diff -r ce92a4c7d07e -r cfb9b40b205d sys/arch/x68k/dev/vs.c
--- a/sys/arch/x68k/dev/vs.c Sun Apr 21 13:05:46 2019 +0000
+++ b/sys/arch/x68k/dev/vs.c Sun Apr 21 14:00:19 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vs.c,v 1.50 2019/03/16 12:09:57 isaki Exp $ */
+/* $NetBSD: vs.c,v 1.50.2.1 2019/04/21 14:00:19 isaki Exp $ */
/*
* Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.50 2019/03/16 12:09:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.50.2.1 2019/04/21 14:00:19 isaki Exp $");
#include "audio.h"
#include "vs.h"
@@ -43,7 +43,6 @@
#include <sys/audioio.h>
#include <dev/audio_if.h>
-#include <dev/mulaw.h>
#include <machine/bus.h>
#include <machine/cpu.h>
@@ -75,11 +74,11 @@
/* MI audio layer interface */
static int vs_open(void *, int);
static void vs_close(void *);
-static int vs_query_encoding(void *, struct audio_encoding *);
-static int vs_set_params(void *, int, int, audio_params_t *,
- audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
-static int vs_init_output(void *, void *, int);
-static int vs_init_input(void *, void *, int);
+static int vs_query_format(void *, audio_format_query_t *);
+static int vs_set_format(void *, int,
+ const audio_params_t *, const audio_params_t *,
+ audio_filter_reg_t *, audio_filter_reg_t *);
+static int vs_commit_settings(void *);
static int vs_start_input(void *, void *, int, void (*)(void *), void *);
static int vs_start_output(void *, void *, int, void (*)(void *), void *);
static int vs_halt_output(void *);
@@ -99,8 +98,7 @@
/* lower functions */
static int vs_round_sr(u_long);
-static void vs_set_sr(struct vs_softc *, int);
-static inline void vs_set_po(struct vs_softc *, u_long);
+static inline void vs_set_panout(struct vs_softc *, u_long);
extern struct cfdriver vs_cd;
@@ -112,10 +110,9 @@
static const struct audio_hw_if vs_hw_if = {
.open = vs_open,
.close = vs_close,
- .query_encoding = vs_query_encoding,
- .set_params = vs_set_params,
- .init_output = vs_init_output,
- .init_input = vs_init_input,
+ .query_format = vs_query_format,
+ .set_format = vs_set_format,
+ .commit_settings = vs_commit_settings,
.start_output = vs_start_output,
.start_input = vs_start_input,
.halt_output = vs_halt_output,
@@ -137,6 +134,18 @@
"vs"
};
+static const struct audio_format vs_formats = {
+ .mode = AUMODE_PLAY | AUMODE_RECORD,
+ .encoding = AUDIO_ENCODING_ADPCM,
+ .validbits = 4,
+ .precision = 4,
+ .channels = 1,
+ .channel_mask = AUFMT_MONAURAL,
+ .frequency_type = 5,
+ .frequency = { VS_RATE_3K, VS_RATE_5K, VS_RATE_7K,
+ VS_RATE_10K, VS_RATE_15K },
+};
+
struct {
u_long rate;
u_char clk;
@@ -213,7 +222,7 @@
sc->sc_prev_vd = NULL;
sc->sc_active = 0;
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
- mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
+ mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
/* XXX */
bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
@@ -298,169 +307,84 @@
}
static int
-vs_query_encoding(void *hdl, struct audio_encoding *fp)
+vs_query_format(void *hdl, audio_format_query_t *afp)
{
- DPRINTF(1, ("vs_query_encoding\n"));
-
- if (fp->index == 0) {
- strcpy(fp->name, AudioEslinear);
- fp->encoding = AUDIO_ENCODING_SLINEAR;
- fp->precision = 8;
- fp->flags = 0;
- return 0;
- }
- if (fp->index == 1) {
- strcpy(fp->name, AudioEslinear_be);
- fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
- fp->precision = 16;
- fp->flags = 0;
- return 0;
- }
- return EINVAL;
+ return audio_query_format(&vs_formats, 1, afp);
}
static int
vs_round_sr(u_long rate)
{
int i;
- int diff;
- int nearest;
- diff = rate;
- nearest = 0;
for (i = 0; i < NUM_RATE; i++) {
- if (rate >= vs_l2r[i].rate) {
- if (rate - vs_l2r[i].rate < diff) {
- diff = rate - vs_l2r[i].rate;
- nearest = i;
- }
- } else {
- if (vs_l2r[i].rate - rate < diff) {
- diff = vs_l2r[i].rate - rate;
- nearest = i;
- }
- }
+ if (rate == vs_l2r[i].rate)
+ return i;
}
- if (diff * 100 / rate > 15)
- return -1;
- else
- return nearest;
+ return -1;
}
static int
-vs_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)
+vs_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 vs_softc *sc;
- audio_params_t hw;
- stream_filter_factory_t *pconv;
- stream_filter_factory_t *rconv;
int rate;
sc = hdl;
- DPRINTF(1, ("vs_set_params: mode=%d enc=%d rate=%d prec=%d ch=%d: ",
- setmode, play->encoding, play->sample_rate,
- play->precision, play->channels));
+ DPRINTF(1, ("%s: mode=%d %s/%dbit/%dch/%dHz: ", __func__,
+ setmode, audio_encoding_name(play->encoding),
+ play->precision, play->channels, play->sample_rate));
/* *play and *rec are identical because !AUDIO_PROP_INDEPENDENT */
- if (play->channels != 1) {
- DPRINTF(1, ("channels not matched\n"));
- return EINVAL;
- }
-
rate = vs_round_sr(play->sample_rate);
- if (rate < 0) {
- DPRINTF(1, ("rate not matched\n"));
- return EINVAL;
- }
-
- if (play->precision == 8 && play->encoding == AUDIO_ENCODING_SLINEAR) {
- pconv = msm6258_linear8_to_adpcm;
- rconv = msm6258_adpcm_to_linear8;
- } else if (play->precision == 16 &&
- play->encoding == AUDIO_ENCODING_SLINEAR_BE) {
- pconv = msm6258_slinear16_to_adpcm;
- rconv = msm6258_adpcm_to_slinear16;
- } else {
- DPRINTF(1, ("prec/enc not matched\n"));
- return EINVAL;
- }
-
+ KASSERT(rate >= 0);
sc->sc_current.rate = rate;
- /* pfil and rfil are independent even if !AUDIO_PROP_INDEPENDENT */
-
if ((setmode & AUMODE_PLAY) != 0) {
- hw = *play;
- hw.encoding = AUDIO_ENCODING_ADPCM;
- hw.precision = 4;
- hw.validbits = 4;
- pfil->prepend(pfil, pconv, &hw);
+ pfil->codec = msm6258_internal_to_adpcm;
+ pfil->context = &sc->sc_codecvar;
}
if ((setmode & AUMODE_RECORD) != 0) {
- hw = *rec;
- hw.encoding = AUDIO_ENCODING_ADPCM;
- hw.precision = 4;
- hw.validbits = 4;
- rfil->prepend(rfil, rconv, &hw);
+ rfil->codec = msm6258_adpcm_to_internal;
+ rfil->context = &sc->sc_codecvar;
}
DPRINTF(1, ("accepted\n"));
return 0;
}
-static void
-vs_set_sr(struct vs_softc *sc, int rate)
+static int
+vs_commit_settings(void *hdl)
{
+ struct vs_softc *sc;
+ int rate;
- DPRINTF(1, ("setting sample rate to %d, %d\n",
+ sc = hdl;
+ rate = sc->sc_current.rate;
+
+ DPRINTF(1, ("commit_settings: sample rate to %d, %d\n",
rate, (int)vs_l2r[rate].rate));
bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
(bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
PPI_PORTC) & 0xf0)
| vs_l2r[rate].den);
adpcm_chgclk(vs_l2r[rate].clk);
-}
-
-static inline void
-vs_set_po(struct vs_softc *sc, u_long po)
-{
- bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
- (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
- & 0xfc) | po);
-}
-
-static int
-vs_init_output(void *hdl, void *buffer, int size)
-{
- struct vs_softc *sc;
-
- DPRINTF(1, ("%s\n", __func__));
- sc = hdl;
-
- /* Set rate and pan */
- vs_set_sr(sc, sc->sc_current.rate);
- vs_set_po(sc, VS_PANOUT_LR);
return 0;
}
-static int
-vs_init_input(void *hdl, void *buffer, int size)
+static inline void
+vs_set_panout(struct vs_softc *sc, u_long po)
{
- struct vs_softc *sc;
- DPRINTF(1, ("%s\n", __func__));
- sc = hdl;
-
- /* Set rate */
- vs_set_sr(sc, sc->sc_current.rate);
-
- return 0;
+ bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
+ (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
+ & 0xfc) | po);
}
static int
@@ -501,6 +425,7 @@
(int)block - (int)KVADDR(vd), blksize);
if (sc->sc_active == 0) {
+ vs_set_panout(sc, VS_PANOUT_LR);
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
Home |
Main Index |
Thread Index |
Old Index