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 cs428x families to audio2.



details:   https://anonhg.NetBSD.org/src/rev/979917dd9a6b
branches:  isaki-audio2
changeset: 450639:979917dd9a6b
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sun Apr 21 07:49:16 2019 +0000

description:
Adapt cs428x families to audio2.
- recording on cs4280 seems to have its own conversion.
  I will see it later but first make it compilable.

diffstat:

 sys/dev/pci/cs4280.c |  205 ++++++++------------------------------------------
 sys/dev/pci/cs4281.c |  171 ++++++-----------------------------------
 sys/dev/pci/cs428x.c |   27 +------
 sys/dev/pci/cs428x.h |    3 +-
 4 files changed, 66 insertions(+), 340 deletions(-)

diffs (truncated from 594 to 300 lines):

diff -r 14a89ce0c0a9 -r 979917dd9a6b sys/dev/pci/cs4280.c
--- a/sys/dev/pci/cs4280.c      Sun Apr 21 07:09:13 2019 +0000
+++ b/sys/dev/pci/cs4280.c      Sun Apr 21 07:49:16 2019 +0000
@@ -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 @@
 
 #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 @@
 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 @@
 #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 @@
        .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 @@
        "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 @@
 }
 
 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 @@
 
        /* 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;
diff -r 14a89ce0c0a9 -r 979917dd9a6b sys/dev/pci/cs4281.c
--- a/sys/dev/pci/cs4281.c      Sun Apr 21 07:09:13 2019 +0000
+++ b/sys/dev/pci/cs4281.c      Sun Apr 21 07:49:16 2019 +0000
@@ -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 @@
 #include <sys/audioio.h>
 #include <dev/audio_if.h>
 #include <dev/midi_if.h>
-#include <dev/mulaw.h>



Home | Main Index | Thread Index | Old Index