Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/isaki-audio2]: src/sys/arch Adapt zaudio family to audio2.



details:   https://anonhg.NetBSD.org/src/rev/0fae7741c884
branches:  isaki-audio2
changeset: 450746:0fae7741c884
user:      isaki <isaki%NetBSD.org@localhost>
date:      Wed Apr 24 13:03:06 2019 +0000

description:
Adapt zaudio family to audio2.
- wm8731 and wm8750 can share zaudio_formats[].
- Drop INDEPENDENT property.  These share sample rate in play and rec.
- pxa2x0_i2s_setspeed() no longer needs to writeback sample rate.

diffstat:

 sys/arch/arm/xscale/pxa2x0_i2s.c    |   47 +----------
 sys/arch/arm/xscale/pxa2x0_i2s.h    |    5 +-
 sys/arch/zaurus/dev/wm8731_zaudio.c |  145 +----------------------------------
 sys/arch/zaurus/dev/wm8750_zaudio.c |  149 +-----------------------------------
 sys/arch/zaurus/dev/zaudio.c        |   52 +++++++++--
 sys/arch/zaurus/dev/zaudiovar.h     |    7 +-
 6 files changed, 61 insertions(+), 344 deletions(-)

diffs (truncated from 639 to 300 lines):

diff -r 5a5d5ad57e0a -r 0fae7741c884 sys/arch/arm/xscale/pxa2x0_i2s.c
--- a/sys/arch/arm/xscale/pxa2x0_i2s.c  Wed Apr 24 12:47:13 2019 +0000
+++ b/sys/arch/arm/xscale/pxa2x0_i2s.c  Wed Apr 24 13:03:06 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pxa2x0_i2s.c,v 1.12 2017/06/01 02:45:06 chs Exp $      */
+/*     $NetBSD: pxa2x0_i2s.c,v 1.12.12.1 2019/04/24 13:03:06 isaki Exp $       */
 /*     $OpenBSD: pxa2x0_i2s.c,v 1.7 2006/04/04 11:45:40 pascoe Exp $   */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pxa2x0_i2s.c,v 1.12 2017/06/01 02:45:06 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pxa2x0_i2s.c,v 1.12.12.1 2019/04/24 13:03:06 isaki Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -140,11 +140,10 @@
 }
 
 void
-pxa2x0_i2s_setspeed(struct pxa2x0_i2s_softc *sc, u_int *argp)
+pxa2x0_i2s_setspeed(struct pxa2x0_i2s_softc *sc, u_int arg)
 {
        /*
         * The available speeds are in the following table.
-        * Keep the speeds in increasing order.
         */
        static const struct speed_struct {
                int     speed;
@@ -158,7 +157,6 @@
                {48000, SADIV_3_058MHz},
        };
        const int n = (int)__arraycount(speed_table);
-       u_int arg = (u_int)*argp;
        int selected = -1;
        int i;
 
@@ -167,25 +165,11 @@
        if (arg > speed_table[n - 1].speed)
                selected = n - 1;
 
-       for (i = 1; selected == -1 && i < n; i++) {
+       for (i = 0; selected == -1 && i < n; i++) {
                if (speed_table[i].speed == arg)
                        selected = i;
-               else if (speed_table[i].speed > arg) {
-                       int diff1, diff2;
-
-                       diff1 = arg - speed_table[i - 1].speed;
-                       diff2 = speed_table[i].speed - arg;
-                       if (diff1 < diff2)
-                               selected = i - 1;
-                       else
-                               selected = i;
-               }
        }
-
-       if (selected == -1)
-               selected = 0;
-
-       *argp = speed_table[selected].speed;
+       KASSERT(selected != -1);
 
        sc->sc_sadiv = speed_table[selected].div;
        bus_space_write_4(sc->sc_iot, sc->sc_ioh, I2S_SADIV, sc->sc_sadiv);
@@ -275,27 +259,6 @@
        panic("pxa2x0_i2s_freem: trying to free unallocated memory");
 }
 
-paddr_t
-pxa2x0_i2s_mappage(void *hdl, void *mem, off_t off, int prot)
-{
-       struct pxa2x0_i2s_softc *sc = hdl;
-       struct pxa2x0_i2s_dma *p;
-
-       if (off < 0)
-               return -1;
-
-       for (p = sc->sc_dmas; p && p->addr != mem; p = p->next)
-               continue;
-       if (p == NULL)
-               return -1;
-
-       if (off > p->size)
-               return -1;
-
-       return bus_dmamem_mmap(sc->sc_dmat, p->segs, p->nsegs, off, prot,
-           BUS_DMA_WAITOK);
-}
-
 int
 pxa2x0_i2s_round_blocksize(void *hdl, int bs, int mode,
     const struct audio_params *param)
diff -r 5a5d5ad57e0a -r 0fae7741c884 sys/arch/arm/xscale/pxa2x0_i2s.h
--- a/sys/arch/arm/xscale/pxa2x0_i2s.h  Wed Apr 24 12:47:13 2019 +0000
+++ b/sys/arch/arm/xscale/pxa2x0_i2s.h  Wed Apr 24 13:03:06 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pxa2x0_i2s.h,v 1.5 2012/11/12 18:00:38 skrll Exp $     */
+/*     $NetBSD: pxa2x0_i2s.h,v 1.5.40.1 2019/04/24 13:03:06 isaki Exp $        */
 /*     $OpenBSD: pxa2x0_i2s.h,v 1.3 2006/04/04 11:45:40 pascoe Exp $   */
 
 /*
@@ -59,11 +59,10 @@
 void   pxa2x0_i2s_close(struct pxa2x0_i2s_softc *);
 void   pxa2x0_i2s_write(struct pxa2x0_i2s_softc *, uint32_t);
 
-void   pxa2x0_i2s_setspeed(struct pxa2x0_i2s_softc *, u_int *);
+void   pxa2x0_i2s_setspeed(struct pxa2x0_i2s_softc *, u_int);
 
 void * pxa2x0_i2s_allocm(void *, int, size_t);
 void   pxa2x0_i2s_freem(void  *, void *, size_t);
-paddr_t        pxa2x0_i2s_mappage(void *, void *, off_t, int);
 int    pxa2x0_i2s_round_blocksize(void *, int, int, const struct audio_params *);
 size_t pxa2x0_i2s_round_buffersize(void *, int, size_t);
 int    pxa2x0_i2s_halt_output(void *);
diff -r 5a5d5ad57e0a -r 0fae7741c884 sys/arch/zaurus/dev/wm8731_zaudio.c
--- a/sys/arch/zaurus/dev/wm8731_zaudio.c       Wed Apr 24 12:47:13 2019 +0000
+++ b/sys/arch/zaurus/dev/wm8731_zaudio.c       Wed Apr 24 13:03:06 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wm8731_zaudio.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $        */
+/*     $NetBSD: wm8731_zaudio.c,v 1.2.4.1 2019/04/24 13:03:06 isaki Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include "opt_zaudio.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wm8731_zaudio.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wm8731_zaudio.c,v 1.2.4.1 2019/04/24 13:03:06 isaki Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,8 +52,6 @@
 #include <sys/bus.h>
 
 #include <dev/audio_if.h>
-#include <dev/mulaw.h>
-#include <dev/auconv.h>
 
 #include <dev/i2c/i2cvar.h>
 
@@ -92,21 +90,6 @@
        "wm"
 };
 
-static const struct audio_format wm8731_formats[] = {
-       {
-               .driver_data    = NULL,
-               .mode           = AUMODE_PLAY | AUMODE_RECORD,
-               .encoding       = AUDIO_ENCODING_SLINEAR_LE,
-               .validbits      = 16,
-               .precision      = 16,
-               .channels       = 2,
-               .channel_mask   = AUFMT_STEREO,
-               .frequency_type = 0,
-               .frequency      = { 4000, 48000 }
-       }
-};
-static const int wm8731_nformats = (int)__arraycount(wm8731_formats);
-
 static void wm8731_init(struct zaudio_softc *);
 static int wm8731_jack_intr(void *);
 static void wm8731_jack(void *);
@@ -115,9 +98,6 @@
 static void wm8731_update_mutes(struct zaudio_softc *, int);
 static void wm8731_play_setup(struct zaudio_softc *);
 /*static*/ void wm8731_record_setup(struct zaudio_softc *);
-static int wm8731_query_encoding(void *, struct audio_encoding *);
-static int wm8731_set_params(void *, int, int, audio_params_t *,
-    audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
 static int wm8731_start_output(void *, void *, int, void (*)(void *), void *);
 static int wm8731_start_input(void *, void *, int, void (*)(void *), void *);
 static int wm8731_halt_output(void *);
@@ -131,8 +111,8 @@
        .open                   = zaudio_open,
        .close                  = zaudio_close,
        .drain                  = NULL,
-       .query_encoding         = wm8731_query_encoding,
-       .set_params             = wm8731_set_params,
+       .query_format           = zaudio_query_format,
+       .set_format             = zaudio_set_format,
        .round_blocksize        = zaudio_round_blocksize,
        .commit_settings        = NULL,
        .init_output            = NULL,
@@ -150,7 +130,6 @@
        .allocm                 = zaudio_allocm,
        .freem                  = zaudio_freem,
        .round_buffersize       = zaudio_round_buffersize,
-       .mappage                = zaudio_mappage,
        .get_props              = zaudio_get_props,
        .trigger_output         = NULL,
        .trigger_input          = NULL,
@@ -614,122 +593,6 @@
 }
 
 static int
-wm8731_query_encoding(void *hdl, struct audio_encoding *aep)
-{
-
-       switch (aep->index) {
-       case 0:
-               strlcpy(aep->name, AudioEulinear, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_ULINEAR;
-               aep->precision = 8;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 1:
-               strlcpy(aep->name, AudioEmulaw, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_ULAW;
-               aep->precision = 8;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 2:
-               strlcpy(aep->name, AudioEalaw, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_ALAW;
-               aep->precision = 8;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 3:
-               strlcpy(aep->name, AudioEslinear, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_SLINEAR;
-               aep->precision = 8;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 4:
-               strlcpy(aep->name, AudioEslinear_le, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_SLINEAR_LE;
-               aep->precision = 16;
-               aep->flags = 0;
-               break;
-
-       case 5:
-               strlcpy(aep->name, AudioEulinear_le, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_ULINEAR_LE;
-               aep->precision = 16;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 6:
-               strlcpy(aep->name, AudioEslinear_be, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_SLINEAR_BE;
-               aep->precision = 16;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       case 7:
-               strlcpy(aep->name, AudioEulinear_be, sizeof(aep->name));
-               aep->encoding = AUDIO_ENCODING_ULINEAR_BE;
-               aep->precision = 16;
-               aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
-               break;
-
-       default:
-               return EINVAL;
-       }
-
-       return 0;
-}
-
-static int
-wm8731_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)
-{
-       struct zaudio_softc *sc = hdl;
-       struct audio_params *p;
-       stream_filter_list_t *fil;
-       int mode, i;
-
-       if (play->sample_rate != rec->sample_rate &&
-           usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
-               if (setmode == AUMODE_PLAY) {
-                       rec->sample_rate = play->sample_rate;
-                       setmode |= AUMODE_RECORD;
-               } else if (setmode == AUMODE_RECORD) {
-                       play->sample_rate = rec->sample_rate;
-                       setmode |= AUMODE_PLAY;
-               } else
-                       return EINVAL;
-       }
-
-       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->sample_rate < 4000 || p->sample_rate > 48000 ||
-                   (p->precision != 8 && p->precision != 16) ||
-                   (p->channels != 1 && p->channels != 2))
-                       return EINVAL;
-
-               fil = (mode == AUMODE_PLAY) ? pfil : rfil;



Home | Main Index | Thread Index | Old Index