From owner-freebsd-multimedia@FreeBSD.ORG Sun Jan 11 23:00:13 2009 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 015FE106566B for ; Sun, 11 Jan 2009 23:00:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from cmail.optima.ua (cmail.optima.ua [195.248.191.121]) by mx1.freebsd.org (Postfix) with ESMTP id 175E78FC0A for ; Sun, 11 Jan 2009 23:00:11 +0000 (UTC) (envelope-from mav@FreeBSD.org) X-Spam-Flag: SKIP X-Spam-Yversion: Spamooborona-2.1.0 Received: from [212.86.226.226] (account mav@alkar.net HELO mavbook.mavhome.dp.ua) by cmail.optima.ua (CommuniGate Pro SMTP 5.2.9) with ESMTPSA id 231372454; Mon, 12 Jan 2009 01:00:11 +0200 Message-ID: <496A79FE.7030401@FreeBSD.org> Date: Mon, 12 Jan 2009 01:00:14 +0200 From: Alexander Motin User-Agent: Thunderbird 2.0.0.17 (X11/20081029) MIME-Version: 1.0 To: Kostik Belousov References: <20090110121731.GK93900@deviant.kiev.zoral.com.ua> <1231690984.00059064.1231680002@10.7.7.3> <1231705384.00059149.1231693204@10.7.7.3> <1231708987.00059188.1231698001@10.7.7.3> In-Reply-To: <1231708987.00059188.1231698001@10.7.7.3> Content-Type: multipart/mixed; boundary="------------020204050401020203050802" Cc: freebsd-multimedia@freebsd.org Subject: Re: New snd_hda and driver initialization X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Jan 2009 23:00:13 -0000 This is a multi-part message in MIME format. --------------020204050401020203050802 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Kostik Belousov wrote: > On Sun, Jan 11, 2009 at 06:50:40PM +0200, Alexander Motin wrote: >> Torfinn Ingolfsen wrote: >>> On Sat, 10 Jan 2009 14:17:31 +0200 >>> Kostik Belousov wrote: >>> >>>> New driver works as good as old or better on my workstation and >>>> laptop, but on both machines it causes a quite loud croak when >>>> loaded. >>> FWIW, I also noticed this on my machines. >> What does is sounds like? Whistle of acoustic loop from speaker to mic? >> Single click of turned-on amplifier or output getting out of Hi-Z state? >> Something other? How long is this sound? Can you reproduce that sound by >> changing volume levels and recording source? > > Most likely, it sounds as a turned-on amplifier, but consider this > a guess. The most precise description is the croak, it takes less then > a second. > > My laptop has ICH7M and Realtek ALC883 codec, workstation is ICH10 and > ALC888. One of my systems, based on AD1988A cadec, had several loud clicks on boot, so I have tried to investigate the case. I have found that there are 3 loud clicks with noise between them: - first click was on codec initialization, when driver sets all amplifiers to 0dB state and enables output. I have found that the main click reason is incorrectly grounded mic and speaker codec input pins. Every (un)muting of them or even level change caused a loud clicks and noise. - second click - on mixer initialization, when mixer assigns it's default levels for speaker and mix controls. - third - when /etc/rc.d/mixer script restored mixer parameters saved from the previous session. So, at least in my case, I can say that it is a codec/motherboard hardware problem and all I can do is try to somehow hide it. I have made a patch (attached) to change codec initialization sequence a bit and mute all possible amplifiers initially. This mostly removed the first click. Second click can be removed by instructing OSS not to set speaker and mix levels to the default 75% by adding to loader.conf: hint.pcm.0.speaker=0 hint.pcm.0.mix=0 Third click disappeared after that by itself as my last settings had speaker and mix muted so there is no change. -- Alexander Motin --------------020204050401020203050802 Content-Type: text/plain; name="hdac.c.click.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="hdac.c.click.patch" --- hdac.c.prev 2009-01-11 22:03:38.000000000 +0200 +++ hdac.c 2009-01-12 00:23:04.000000000 +0200 @@ -6111,6 +6111,29 @@ hdac_audio_prepare_pin_ctrl(struct hdac_ } static void +hdac_audio_ctl_commit(struct hdac_devinfo *devinfo) +{ + struct hdac_audio_ctl *ctl; + int i, z; + + i = 0; + while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) { + if (ctl->enable == 0 || ctl->ossmask != 0) { + /* Mute disabled and mixer controllable controls. + * Last will be initialized by mixer_init(). + * This expected to reduce click on startup. */ + hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_ALL, 0, 0); + continue; + } + /* Init fixed controls to 0dB amplification. */ + z = ctl->offset; + if (z > ctl->step) + z = ctl->step; + hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_NONE, z, z); + } +} + +static void hdac_audio_commit(struct hdac_devinfo *devinfo) { struct hdac_softc *sc = devinfo->codec->sc; @@ -6126,11 +6149,41 @@ hdac_audio_commit(struct hdac_devinfo *d hdac_command(sc, HDA_CMD_12BIT(cad, devinfo->nid, 0x7e7, 0), cad); + /* Commit controls. */ + hdac_audio_ctl_commit(devinfo); + + /* Commit selectors, pins and EAPD. */ + for (i = 0; i < devinfo->nodecnt; i++) { + w = &devinfo->widget[i]; + if (w == NULL) + continue; + if (w->selconn == -1) + w->selconn = 0; + if (w->nconns > 0) + hdac_widget_connection_select(w, w->selconn); + if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { + hdac_command(sc, + HDA_CMD_SET_PIN_WIDGET_CTRL(cad, w->nid, + w->wclass.pin.ctrl), cad); + } + if (w->param.eapdbtl != HDAC_INVALID) { + uint32_t val; + + val = w->param.eapdbtl; + if (devinfo->function.audio.quirks & + HDA_QUIRK_EAPDINV) + val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; + hdac_command(sc, + HDA_CMD_SET_EAPD_BTL_ENABLE(cad, w->nid, + val), cad); + } + } + + /* Commit GPIOs. */ gdata = 0; gmask = 0; gdir = 0; commitgpio = 0; - numgpio = HDA_PARAM_GPIO_COUNT_NUM_GPIO( devinfo->function.audio.gpio); @@ -6185,54 +6238,6 @@ hdac_audio_commit(struct hdac_devinfo *d HDA_CMD_SET_GPIO_DATA(cad, devinfo->nid, gdata), cad); } - - for (i = 0; i < devinfo->nodecnt; i++) { - w = &devinfo->widget[i]; - if (w == NULL) - continue; - if (w->selconn == -1) - w->selconn = 0; - if (w->nconns > 0) - hdac_widget_connection_select(w, w->selconn); - if (w->type == HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) { - hdac_command(sc, - HDA_CMD_SET_PIN_WIDGET_CTRL(cad, w->nid, - w->wclass.pin.ctrl), cad); - } - if (w->param.eapdbtl != HDAC_INVALID) { - uint32_t val; - - val = w->param.eapdbtl; - if (devinfo->function.audio.quirks & - HDA_QUIRK_EAPDINV) - val ^= HDA_CMD_SET_EAPD_BTL_ENABLE_EAPD; - hdac_command(sc, - HDA_CMD_SET_EAPD_BTL_ENABLE(cad, w->nid, - val), cad); - - } - } -} - -static void -hdac_audio_ctl_commit(struct hdac_devinfo *devinfo) -{ - struct hdac_audio_ctl *ctl; - int i, z; - - i = 0; - while ((ctl = hdac_audio_ctl_each(devinfo, &i)) != NULL) { - if (ctl->enable == 0) { - /* Mute disabled controls. */ - hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_ALL, 0, 0); - continue; - } - /* Init controls to 0dB amplification. */ - z = ctl->offset; - if (z > ctl->step) - z = ctl->step; - hdac_audio_ctl_amp_set(ctl, HDA_AMP_MUTE_NONE, z, z); - } } static void @@ -7477,10 +7482,6 @@ hdac_attach2(void *arg) ); hdac_audio_commit(devinfo); HDA_BOOTHVERBOSE( - device_printf(sc->dev, "Ctls commit...\n"); - ); - hdac_audio_ctl_commit(devinfo); - HDA_BOOTHVERBOSE( device_printf(sc->dev, "HP switch init...\n"); ); hdac_hp_switch_init(devinfo); @@ -7730,10 +7731,6 @@ hdac_resume(device_t dev) ); hdac_audio_commit(devinfo); HDA_BOOTHVERBOSE( - device_printf(dev, "Ctls commit...\n"); - ); - hdac_audio_ctl_commit(devinfo); - HDA_BOOTHVERBOSE( device_printf(dev, "HP switch init...\n"); ); hdac_hp_switch_init(devinfo); --------------020204050401020203050802--