From owner-freebsd-multimedia Thu Jun 27 14:23:59 2002 Delivered-To: freebsd-multimedia@freebsd.org Received: from magic.adaptec.com (magic.adaptec.com [208.236.45.80]) by hub.freebsd.org (Postfix) with ESMTP id E34F737B428; Thu, 27 Jun 2002 14:23:27 -0700 (PDT) Received: from redfish.adaptec.com (redfish.adaptec.com [162.62.50.11]) by magic.adaptec.com (8.10.2+Sun/8.10.2) with ESMTP id g5RLNRE03832; Thu, 27 Jun 2002 14:23:27 -0700 (PDT) Received: from btc.btc.adaptec.com (btc.btc.adaptec.com [10.100.0.52]) by redfish.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id OAA24101; Thu, 27 Jun 2002 14:23:26 -0700 (PDT) Received: from hollin.btc.adaptec.com (hollin [10.100.253.56]) by btc.btc.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id PAA07094; Thu, 27 Jun 2002 15:23:24 -0600 (MDT) Received: from hollin.btc.adaptec.com (localhost [127.0.0.1]) by hollin.btc.adaptec.com (8.12.3/8.12.3) with ESMTP id g5RLJlrP018060; Thu, 27 Jun 2002 15:19:47 -0600 (MDT) (envelope-from scottl@hollin.btc.adaptec.com) Received: (from scottl@localhost) by hollin.btc.adaptec.com (8.12.3/8.12.3/Submit) id g5RLJldW018059; Thu, 27 Jun 2002 15:19:47 -0600 (MDT) Date: Thu, 27 Jun 2002 15:19:47 -0600 From: Scott Long To: freebsd-multimedia@freebsd.org, cg@freebsd.org, orion@freebsd.org Subject: ICH calibration under 5-CURRENT Message-ID: <20020627211947.GA18048@hollin.btc.adaptec.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline User-Agent: Mutt/1.3.28i Sender: owner-freebsd-multimedia@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline All, I noticed that with my ICH3/CS4205 sound setup, if I load the ich driver at boot or compile it into the kernel, it incorrectly sets the ac97 sample rate. However, if I load the driver *after* boot, it's correct. This is due to ich_calibrate() running before the system clock is itslef calibrated. I see that there are a few hacks and sysctl's for dealing with this, but the attached patch should settle this issue. It puts ich_calibrate() into a config_intrhook, forcing it to run after the system clock is calibrated. If there are no objections, I'd like to commit it to 5-CURRENT. I haven't looked into 4-STABLE, so comments there are welcome also. Scott --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ich.patch" Index: ich.c =================================================================== RCS file: /usr/ncvs/src/sys/dev/sound/pci/ich.c,v retrieving revision 1.21 diff -u -r1.21 ich.c --- ich.c 5 May 2002 15:37:09 -0000 1.21 +++ ich.c 27 Jun 2002 21:07:13 -0000 @@ -85,6 +85,7 @@ struct sc_chinfo ch[3]; int ac97rate; struct ich_desc *dtbl; + struct intr_config_hook intrhook; }; /* -------------------------------------------------------------------- */ @@ -455,13 +456,19 @@ /* Calibrate card (some boards are overclocked and need scaling) */ static -unsigned int ich_calibrate(struct sc_info *sc) +void ich_calibrate(void *arg) { - struct sc_chinfo *ch = &sc->ch[1]; + struct sc_info *sc; + struct sc_chinfo *ch; struct timeval t1, t2; u_int8_t ociv, nciv; u_int32_t wait_us, actual_48k_rate, bytes; + sc = (struct sc_info *)arg; + ch = &sc->ch[1]; + + config_intrhook_disestablish(&sc->intrhook); + /* * Grab audio from input for fixed interval and compare how * much we actually get with what we expect. Interval needs @@ -516,7 +523,7 @@ if (nciv == ociv) { device_printf(sc->dev, "ac97 link rate calibration timed out after %d us\n", wait_us); - return 0; + return; } actual_48k_rate = (bytes * 250000) / wait_us; @@ -534,7 +541,7 @@ printf("\n"); } - return sc->ac97rate; + return; } /* -------------------------------------------------------------------- */ @@ -708,7 +715,13 @@ pcm_setstatus(dev, status); ich_initsys(sc); - ich_calibrate(sc); + + sc->intrhook.ich_func = ich_calibrate; + sc->intrhook.ich_arg = sc; + if (config_intrhook_establish(&sc->intrhook) != 0) { + device_printf(dev, "Cannot establish calibration hook, will calibrate now\n"); + ich_calibrate(sc); + } return 0; --h31gzZEtNLTqOjlF-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-multimedia" in the body of the message