Subject: Re: kern/32485
To: None <port-i386-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: =?ISO-8859-1?Q?St=E9phane_Witzmann?= <stephane.witzmann@gmail.com>
List: netbsd-bugs
Date: 01/09/2006 16:35:02
The following reply was made to PR port-i386/32485; it has been noted by GNATS.

From: =?ISO-8859-1?Q?St=E9phane_Witzmann?= <stephane.witzmann@gmail.com>
To: gnats-bugs@netbsd.org
Cc: stlist@gmail.com
Subject: Re: kern/32485
Date: Mon, 9 Jan 2006 17:32:40 +0100

 Based on src/sys/dev/pci/azalia.c rev 1.15
 
 Here is the modified function that wrote the "AZALIA DEBUG" lines.
 
 static int
 azalia_mixer_init(codec_t *this)
 {
 =09/*
 =09 * pin=09=09"<color>%2.2x"
 =09 * audio output=09"dac%2.2x"
 =09 * audio input=09"adc%2.2x"
 =09 * mixer=09"mixer%2.2x"
 =09 * selector=09"sel%2.2x"
 =09 */
 =09mixer_item_t *m;
 =09int nadcs;
 =09int err, i, j;
 
 =09nadcs =3D 0;
 =09this->maxmixers =3D 10;
 =09this->nmixers =3D 0;
 =09this->mixers =3D malloc(sizeof(mixer_item_t) * this->maxmixers,
 =09    M_DEVBUF, M_ZERO | M_NOWAIT);
 =09if (this->mixers =3D=3D NULL) {
 =09=09aprint_error("%s: out of memory in %s\n", XNAME(this->az),
 =09=09    __func__);
 =09=09return ENOMEM;
 =09}
 
 =09/* register classes */
 #define AZ_CLASS_INPUT=090
 #define AZ_CLASS_OUTPUT=091
 #define AZ_CLASS_RECORD=092
 =09m =3D &this->mixers[AZ_CLASS_INPUT];
 =09m->devinfo.index =3D AZ_CLASS_INPUT;
 =09printf("AZALIA DEBUG 1\n");
 =09strlcpy(m->devinfo.label.name, AudioCinputs,
 =09    sizeof(m->devinfo.label.name));
 =09m->devinfo.type =3D AUDIO_MIXER_CLASS;
 =09m->devinfo.mixer_class =3D AZ_CLASS_INPUT;
 =09m->devinfo.next =3D AUDIO_MIXER_LAST;
 =09m->devinfo.prev =3D AUDIO_MIXER_LAST;
 =09m->nid =3D 0;
 
 =09m =3D &this->mixers[AZ_CLASS_OUTPUT];
 =09m->devinfo.index =3D AZ_CLASS_OUTPUT;
 =09printf("AZALIA DEBUG 2\n");
 =09strlcpy(m->devinfo.label.name, AudioCoutputs,
 =09    sizeof(m->devinfo.label.name));
 =09m->devinfo.type =3D AUDIO_MIXER_CLASS;
 =09m->devinfo.mixer_class =3D AZ_CLASS_OUTPUT;
 =09m->devinfo.next =3D AUDIO_MIXER_LAST;
 =09m->devinfo.prev =3D AUDIO_MIXER_LAST;
 =09m->nid =3D 0;
 
 =09m =3D &this->mixers[AZ_CLASS_RECORD];
 =09m->devinfo.index =3D AZ_CLASS_RECORD;
 =09printf("AZALIA DEBUG 3\n");
 =09strlcpy(m->devinfo.label.name, AudioCrecord,
 =09    sizeof(m->devinfo.label.name));
 =09m->devinfo.type =3D AUDIO_MIXER_CLASS;
 =09m->devinfo.mixer_class =3D AZ_CLASS_RECORD;
 =09m->devinfo.next =3D AUDIO_MIXER_LAST;
 =09m->devinfo.prev =3D AUDIO_MIXER_LAST;
 =09m->nid =3D 0;
 
 =09this->nmixers =3D AZ_CLASS_RECORD + 1;
 
 #define MIXER_REG_PROLOG=09\
 =09mixer_devinfo_t *d; \
 =09err =3D azalia_mixer_ensure_capacity(this, this->nmixers + 1); \
 =09if (err) \
 =09=09return err; \
 =09m =3D &this->mixers[this->nmixers]; \
 =09d =3D &m->devinfo; \
 =09d->index =3D this->nmixers; \
 =09m->nid =3D i
 
 =09FOR_EACH_WIDGET(this, i) {
 =09=09const widget_t *w;
 
 =09=09w =3D &this->w[i];
 
 =09=09if (w->type =3D=3D COP_AWTYPE_AUDIO_INPUT)
 =09=09=09nadcs++;
 
 =09=09/* selector */
 =09=09if (w->type !=3D COP_AWTYPE_AUDIO_MIXER && w->nconnections >=3D 2) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09    "%s.source", w->name);
 =09=09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09=09if (w->type =3D=3D COP_AWTYPE_AUDIO_MIXER)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_RECORD;
 =09=09=09else if (w->type =3D=3D COP_AWTYPE_AUDIO_SELECTOR)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09=09else
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_CONNLIST;
 =09=09=09for (j =3D 0; j < w->nconnections && j < 32; j++) {
 =09=09=09=09d->un.e.member[j].ord =3D j;
 =09=09=09=09printf("AZALIA DEBUG 4\n");
 =09=09=09=09strlcpy(d->un.e.member[j].label.name,
 =09=09=09=09    this->w[w->connections[j]].name,
 =09=09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09}
 =09=09=09d->un.e.num_mem =3D j;
 =09=09=09this->nmixers++;
 =09=09}
 
 =09=09/* output mute */
 =09=09if (w->widgetcap & COP_AWCAP_OUTAMP &&
 =09=09    w->outamp_cap & COP_AMPCAP_MUTE) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09    "%s.mute", w->name);
 =09=09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09=09if (w->type =3D=3D COP_AWTYPE_AUDIO_MIXER)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else if (w->type =3D=3D COP_AWTYPE_AUDIO_SELECTOR)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else
 =09=09=09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_OUTAMP;
 =09=09=09d->un.e.num_mem =3D 2;
 =09=09=09d->un.e.member[0].ord =3D 0;
 =09=09=09printf("AZALIA DEBUG 5\n");
 =09=09=09strlcpy(d->un.e.member[0].label.name, AudioNoff,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09d->un.e.member[1].ord =3D 1;
 =09=09=09printf("AZALIA DEBUG 6\n");
 =09=09=09strlcpy(d->un.e.member[1].label.name, AudioNon,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09this->nmixers++;
 =09=09}
 
 =09=09/* output gain */
 =09=09if (w->widgetcap & COP_AWCAP_OUTAMP
 =09=09    && COP_AMPCAP_NUMSTEPS(w->outamp_cap)) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09    "%s", w->name);
 =09=09=09d->type =3D AUDIO_MIXER_VALUE;
 =09=09=09if (w->type =3D=3D COP_AWTYPE_AUDIO_MIXER)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else if (w->type =3D=3D COP_AWTYPE_AUDIO_SELECTOR)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX)
 =09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09else
 =09=09=09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_OUTAMP;
 =09=09=09d->un.v.num_channels =3D w->widgetcap & COP_AWCAP_STEREO
 =09=09=09    ? 2 : 1;
 #ifdef MAX_VOLUME_255
 =09=09=09d->un.v.units.name[0] =3D 0;
 =09=09=09d->un.v.delta =3D AUDIO_MAX_GAIN /
 =09=09=09    COP_AMPCAP_NUMSTEPS(w->outamp_cap);
 #else
 =09=09=09snprintf(d->un.v.units.name, sizeof(d->un.v.units.name),
 =09=09=09    "0.25x%ddB", COP_AMPCAP_STEPSIZE(w->outamp_cap)+1);
 =09=09=09d->un.v.delta =3D 1;
 #endif
 =09=09=09this->nmixers++;
 =09=09}
 
 =09=09/* input mute */
 =09=09if (w->widgetcap & COP_AWCAP_INAMP &&
 =09=09    w->inamp_cap & COP_AMPCAP_MUTE) {
 =09=09=09for (j =3D 0; j < w->nconnections; j++) {
 =09=09=09=09MIXER_REG_PROLOG;
 =09=09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09=09    "%s.%s.mute", w->name,
 =09=09=09=09    this->w[w->connections[j]].name);
 =09=09=09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09=09=09if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX)
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09=09else if (w->type =3D=3D COP_AWTYPE_AUDIO_INPUT)
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_RECORD;
 =09=09=09=09else
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09=09m->target =3D j;
 =09=09=09=09d->un.e.num_mem =3D 2;
 =09=09=09=09d->un.e.member[0].ord =3D 0;
 =09=09=09=09printf("AZALIA DEBUG 7\n");
 =09=09=09=09strlcpy(d->un.e.member[0].label.name,
 =09=09=09=09    AudioNoff, MAX_AUDIO_DEV_LEN);
 =09=09=09=09d->un.e.member[1].ord =3D 1;
 =09=09=09=09printf("AZALIA DEBUG 8\n");
 =09=09=09=09strlcpy(d->un.e.member[1].label.name,
 =09=09=09=09    AudioNon, MAX_AUDIO_DEV_LEN);
 =09=09=09=09this->nmixers++;
 =09=09=09}
 =09=09}
 
 =09=09/* input gain */
 =09=09if (w->widgetcap & COP_AWCAP_INAMP
 =09=09    && COP_AMPCAP_NUMSTEPS(w->inamp_cap)) {
 =09=09=09for (j =3D 0; j < w->nconnections; j++) {
 =09=09=09=09MIXER_REG_PROLOG;
 =09=09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09=09    "%s.%s", w->name,
 =09=09=09=09    this->w[w->connections[j]].name);
 =09=09=09=09d->type =3D AUDIO_MIXER_VALUE;
 =09=09=09=09if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX)
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09=09else if (w->type =3D=3D COP_AWTYPE_AUDIO_INPUT)
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_RECORD;
 =09=09=09=09else
 =09=09=09=09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09=09m->target =3D j;
 =09=09=09=09d->un.v.num_channels =3D
 =09=09=09=09    w->widgetcap & COP_AWCAP_STEREO ? 2 : 1;
 #ifdef MAX_VOLUME_255
 =09=09=09=09d->un.v.units.name[0] =3D 0;
 =09=09=09=09d->un.v.delta =3D AUDIO_MAX_GAIN /
 =09=09=09=09    COP_AMPCAP_NUMSTEPS(w->inamp_cap);
 #else
 =09=09=09=09snprintf(d->un.v.units.name,
 =09=09=09=09    sizeof(d->un.v.units.name), "0.25x%ddB",
 =09=09=09=09    COP_AMPCAP_STEPSIZE(w->inamp_cap)+1);
 =09=09=09=09d->un.v.delta =3D 1;
 #endif
 =09=09=09=09this->nmixers++;
 =09=09=09}
 =09=09}
 
 =09=09/* pin direction */
 =09=09if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX &&
 =09=09    w->d.pin.cap & COP_PINCAP_OUTPUT &&
 =09=09    w->d.pin.cap & COP_PINCAP_INPUT) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09    "%s.dir", w->name);
 =09=09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_PINDIR;
 =09=09=09d->un.e.num_mem =3D 2;
 =09=09=09d->un.e.member[0].ord =3D 0;
 =09=09=09printf("AZALIA DEBUG 9\n");
 =09=09=09strlcpy(d->un.e.member[0].label.name, AudioNinput,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09d->un.e.member[1].ord =3D 1;
 =09=09=09printf("AZALIA DEBUG 10\n");
 =09=09=09strlcpy(d->un.e.member[1].label.name, AudioNoutput,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09this->nmixers++;
 =09=09}
 
 =09=09/* pin headphone-boost */
 =09=09if (w->type =3D=3D COP_AWTYPE_PIN_COMPLEX &&
 =09=09    w->d.pin.cap & COP_PINCAP_HEADPHONE) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09snprintf(d->label.name, sizeof(d->label.name),
 =09=09=09    "%s.boost", w->name);
 =09=09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_PINBOOST;
 =09=09=09d->un.e.num_mem =3D 2;
 =09=09=09d->un.e.member[0].ord =3D 0;
 =09=09=09printf("AZALIA DEBUG 11\n");
 =09=09=09strlcpy(d->un.e.member[0].label.name, AudioNoff,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09d->un.e.member[1].ord =3D 1;
 =09=09=09printf("AZALIA DEBUG 12\n");
 =09=09=09strlcpy(d->un.e.member[1].label.name, AudioNon,
 =09=09=09    MAX_AUDIO_DEV_LEN);
 =09=09=09this->nmixers++;
 =09=09}
 
 =09=09/* volume knob */
 =09=09if (w->type =3D=3D COP_AWTYPE_VOLUME_KNOB &&
 =09=09    w->d.volume.cap & COP_VKCAP_DELTA) {
 =09=09=09MIXER_REG_PROLOG;
 =09=09=09printf("AZALIA DEBUG 13\n");
 =09=09=09strlcpy(d->label.name, w->name, sizeof(d->label.name));
 =09=09=09d->type =3D AUDIO_MIXER_VALUE;
 =09=09=09d->mixer_class =3D AZ_CLASS_OUTPUT;
 =09=09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09=09m->target =3D MI_TARGET_VOLUME;
 =09=09=09d->un.v.num_channels =3D 1;
 =09=09=09d->un.v.units.name[0] =3D 0;
 #ifdef MAX_VOLUME_255
 =09=09=09d->un.v.delta =3D AUDIO_MAX_GAIN /
 =09=09=09    COP_VKCAP_NUMSTEPS(w->d.volume.cap);
 #else
 =09=09=09d->un.v.delta =3D 1;
 #endif
 =09=09=09this->nmixers++;
 =09=09}
 =09}
 
 =09/* if the codec has multiple DAC groups, create "inputs.usingdac" */
 =09if (this->ndacgroups > 1) {
 =09=09MIXER_REG_PROLOG;
 =09=09printf("AZALIA DEBUG 14\n");
 =09=09strlcpy(d->label.name, "usingdac", sizeof(d->label.name));
 =09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09d->mixer_class =3D AZ_CLASS_INPUT;
 =09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09m->target =3D MI_TARGET_DAC;
 =09=09for (i =3D 0; i < this->ndacgroups && i < 32; i++) {
 =09=09=09d->un.e.member[i].ord =3D i;
 =09=09=09for (j =3D 0; j < this->dacgroups[i].nconv; j++) {
 =09=09=09=09if (j * 2 >=3D MAX_AUDIO_DEV_LEN)
 =09=09=09=09=09break;
 =09=09=09=09snprintf(d->un.e.member[i].label.name + j*2,
 =09=09=09=09    MAX_AUDIO_DEV_LEN - j*2, "%2.2x",
 =09=09=09=09    this->dacgroups[i].conv[j]);
 =09=09=09}
 =09=09}
 =09=09d->un.e.num_mem =3D i;
 =09=09this->nmixers++;
 =09}
 
 =09/* if the codec has multiple ADCs, create "record.usingadc" */
 =09if (this->nadcs > 1) {
 =09=09MIXER_REG_PROLOG;
 =09=09printf("AZALIA DEBUG 15\n");
 =09=09strlcpy(d->label.name, "usingadc", sizeof(d->label.name));
 =09=09d->type =3D AUDIO_MIXER_ENUM;
 =09=09d->mixer_class =3D AZ_CLASS_RECORD;
 =09=09d->next =3D AUDIO_MIXER_LAST;
 =09=09d->prev =3D AUDIO_MIXER_LAST;
 =09=09m->target =3D MI_TARGET_ADC;
 =09=09for (i =3D 0; i < this->nadcs && i < 32; i++) {
 =09=09=09d->un.e.member[i].ord =3D i;
 =09=09=09printf("AZALIA DEBUG 16\n");
 =09=09=09strlcpy(d->un.e.member[i].label.name,
 =09=09=09    this->w[this->adcs[i]].name, MAX_AUDIO_DEV_LEN);
 =09=09}
 =09=09d->un.e.num_mem =3D i;
 =09=09this->nmixers++;
 =09}
 
 =09/* unmute all */
 =09for (i =3D 0; i < this->nmixers; i++) {
 =09=09mixer_ctrl_t mc;
 
 =09=09if (!IS_MI_TARGET_INAMP(this->mixers[i].target) &&
 =09=09    this->mixers[i].target !=3D MI_TARGET_OUTAMP)
 =09=09=09continue;
 =09=09if (this->mixers[i].devinfo.type !=3D AUDIO_MIXER_ENUM)
 =09=09=09continue;
 =09=09mc.dev =3D i;
 =09=09mc.type =3D AUDIO_MIXER_ENUM;
 =09=09mc.un.ord =3D 0;
 =09=09azalia_mixer_set(this, &mc);
 =09}
 
 =09/*
 =09 * for bidirectional pins,
 =09 * green=3Dfront, orange=3Dsurround, gray=3Dc/lfe, black=3Dside --> outp=
 ut
 =09 * blue=3Dline-in, pink=3Dmic-in --> input
 =09 */
 =09for (i =3D 0; i < this->nmixers; i++) {
 =09=09mixer_ctrl_t mc;
 
 =09=09if (this->mixers[i].target !=3D MI_TARGET_PINDIR)
 =09=09=09continue;
 =09=09mc.dev =3D i;
 =09=09mc.type =3D AUDIO_MIXER_ENUM;
 =09=09switch (this->w[this->mixers[i].nid].d.pin.color) {
 =09=09case CORB_CD_GREEN:
 =09=09case CORB_CD_ORANGE:
 =09=09case CORB_CD_GRAY:
 =09=09case CORB_CD_BLACK:
 =09=09=09mc.un.ord =3D 1;
 =09=09=09break;
 =09=09default:
 =09=09=09mc.un.ord =3D 0;
 =09=09}
 =09=09azalia_mixer_set(this, &mc);
 =09}
 
 =09/* set unextreme volume */
 =09for (i =3D 0; i < this->nmixers; i++) {
 =09=09mixer_ctrl_t mc;
 
 =09=09if (!IS_MI_TARGET_INAMP(this->mixers[i].target) &&
 =09=09    this->mixers[i].target !=3D MI_TARGET_OUTAMP &&
 =09=09    this->mixers[i].target !=3D MI_TARGET_VOLUME)
 =09=09=09continue;
 =09=09if (this->mixers[i].devinfo.type !=3D AUDIO_MIXER_VALUE)
 =09=09=09continue;
 =09=09mc.dev =3D i;
 =09=09mc.type =3D AUDIO_MIXER_VALUE;
 =09=09mc.un.value.num_channels =3D 1;
 =09=09mc.un.value.level[0] =3D AUDIO_MAX_GAIN / 2;
 =09=09if (this->mixers[i].target !=3D MI_TARGET_VOLUME &&
 =09=09    this->w[this->mixers[i].nid].widgetcap & COP_AWCAP_STEREO) {
 =09=09=09mc.un.value.num_channels =3D 2;
 =09=09=09mc.un.value.level[1] =3D AUDIO_MAX_GAIN / 2;
 =09=09}
 =09=09azalia_mixer_set(this, &mc);
 =09}
 
 =09return 0;
 }