Subject: Fwd: AC97 patch for ICH5 (native mode) & AD1985 codec
To: None <current-users@netbsd.org>
From: Lars Heidieker <lars@heidieker.de>
List: current-users
Date: 11/20/2003 10:17:11
--Boundary-00=_XaIv/dXGvzSVuLU
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

better patch format and 1 typo in other patch (sorry):
Index: ic/ac97.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/ac97.c,v
retrieving revision 1.49
diff -c -r1.49 ac97.c
*** ic/ac97.c   28 Sep 2003 22:24:09 -0000      1.49
--- ic/ac97.c   20 Nov 2003 09:13:37 -0000
***************
*** 324,330 ****
  u_int16_t ac97_get_extcaps(struct ac97_codec_if *codec_if);
  int ac97_add_port(struct ac97_softc *as, const struct ac97_source_info *src);

! static void ac97_ad1980_init(struct ac97_softc *);
  static void ac97_alc650_init(struct ac97_softc *);
  static void ac97_vt1616_init(struct ac97_softc *);

--- 324,330 ----
  u_int16_t ac97_get_extcaps(struct ac97_codec_if *codec_if);
  int ac97_add_port(struct ac97_softc *as, const struct ac97_source_info *src);

! static void ac97_ad198x_init(struct ac97_softc *);
  static void ac97_alc650_init(struct ac97_softc *);
  static void ac97_vt1616_init(struct ac97_softc *);

***************
*** 368,380 ****
        { AC97_CODEC_ID('A', 'D', 'S', 0x63),
          0xffffffff,                   "Analog Devices AD1886A" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x70),
!         0xffffffff,                   "Analog Devices AD1980", ac97_ad1980_init },
        { AC97_CODEC_ID('A', 'D', 'S', 0x72),
          0xffffffff,                   "Analog Devices AD1981A" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x74),
          0xffffffff,                   "Analog Devices AD1981B" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x75),
!         0xffffffff,                   "Analog Devices AD1985" },
        { AC97_CODEC_ID('A', 'D', 'S', 0),
          AC97_VENDOR_ID_MASK,          "Analog Devices unknown" },

--- 368,380 ----
        { AC97_CODEC_ID('A', 'D', 'S', 0x63),
          0xffffffff,                   "Analog Devices AD1886A" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x70),
!         0xffffffff,                   "Analog Devices AD1980", ac97_ad198x_init },
        { AC97_CODEC_ID('A', 'D', 'S', 0x72),
          0xffffffff,                   "Analog Devices AD1981A" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x74),
          0xffffffff,                   "Analog Devices AD1981B" },
        { AC97_CODEC_ID('A', 'D', 'S', 0x75),
!         0xffffffff,                   "Analog Devices AD1985", ac97_ad198x_init },
        { AC97_CODEC_ID('A', 'D', 'S', 0),
          AC97_VENDOR_ID_MASK,          "Analog Devices unknown" },

***************
*** 901,906 ****
--- 901,908 ----
        if (host_if->flags)
                as->host_flags = host_if->flags(host_if->arg);

+       ac97_read(as, AC97_REG_RESET, &id1);
+
        ac97_setup_defaults(as);
        ac97_read(as, AC97_REG_VENDOR_ID1, &id1);
        ac97_read(as, AC97_REG_VENDOR_ID2, &id2);
***************
*** 1501,1507 ****
  #define               AD1981_MISC_MSPLT       0x1000  /*12 */
  #define               AD1981_MISC_DACZ        0x4000  /*14 */
  static void
! ac97_ad1980_init(struct ac97_softc *as)
  {
        int i;
        unsigned short misc;
--- 1503,1509 ----
  #define               AD1981_MISC_MSPLT       0x1000  /*12 */
  #define               AD1981_MISC_DACZ        0x4000  /*14 */
  static void
! ac97_ad198x_init(struct ac97_softc *as)
  {
        int i;
        unsigned short misc;

Index: pci/auich.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auich.c,v
retrieving revision 1.54
diff -c -r1.54 auich.c
*** pci/auich.c 6 Nov 2003 07:13:33 -0000       1.54
--- pci/auich.c 20 Nov 2003 09:13:42 -0000
***************
*** 418,437 ****
             && d->product == PCI_PRODUCT_INTEL_82801DB_AC)
            || (d->vendor == PCI_VENDOR_INTEL
                && d->product == PCI_PRODUCT_INTEL_82801EB_AC)) {
!               v = pci_conf_read(pa->pa_pc, pa->pa_tag, ICH_CFG);
!               pci_conf_write(pa->pa_pc, pa->pa_tag, ICH_CFG, v | ICH_CFG_IOSE);
!       }
!       if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO, 0,
!                          &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
!               aprint_error("%s: can't map codec i/o space\n",
!                   sc->sc_dev.dv_xname);
!               return;
!       }
!       if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO, 0,
!                          &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
!               aprint_error("%s: can't map device i/o space\n",
!                   sc->sc_dev.dv_xname);
!               return;
        }
        sc->dmat = pa->pa_dmat;

--- 418,448 ----
             && d->product == PCI_PRODUCT_INTEL_82801DB_AC)
            || (d->vendor == PCI_VENDOR_INTEL
                && d->product == PCI_PRODUCT_INTEL_82801EB_AC)) {
!               if (pci_mapreg_map(pa, ICH_MMBAR, PCI_MAPREG_TYPE_MEM, 0,
!                                  &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
!                       aprint_error("%s: can't map codec i/o space\n",
!                           sc->sc_dev.dv_xname);
!                       return;
!               }
!               if (pci_mapreg_map(pa, ICH_MBBAR, PCI_MAPREG_TYPE_MEM, 0,
!                               &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
!                       aprint_error("%s: can't map device i/o space\n",
!                       sc->sc_dev.dv_xname);
!                       return;
!               }
!       } else {
!               if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO, 0,
!                                  &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
!                       aprint_error("%s: can't map codec i/o space\n",
!                           sc->sc_dev.dv_xname);
!                       return;
!               }
!               if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO, 0,
!                               &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
!                       aprint_error("%s: can't map device i/o space\n",
!                       sc->sc_dev.dv_xname);
!                       return;
!               }
        }
        sc->dmat = pa->pa_dmat;

Index: pci/auichreg.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auichreg.h,v
retrieving revision 1.6
diff -c -r1.6 auichreg.h
*** pci/auichreg.h      30 Oct 2003 19:33:51 -0000      1.6
--- pci/auichreg.h      20 Nov 2003 09:13:42 -0000
***************
*** 43,48 ****
--- 43,50 ----
  #define       ICH_NAMBAR      0x10
  /* 12.1.11 NABMBAR - native audio bus mastering base address register */
  #define       ICH_NABMBAR     0x14
+ #define ICH_MMBAR     0x18
+ #define ICH_MBBAR     0x1c
  #define ICH_CFG               0x41
  #define               ICH_CFG_IOSE    0x01

--Boundary-00=_XaIv/dXGvzSVuLU
Content-Type: message/rfc822;
  name="forwarded message"
Content-Transfer-Encoding: 7bit
Content-Description: Lars Heidieker <lars@heidieker.de>: AC97 patch for ICH5 (native mode) & AD1985 codec

	by p15139955.pureserver.info (Postfix) with SMTP id 3075B31405A
	for <lars@cubeportal.de>; Thu, 20 Nov 2003 10:06:06 +0100 (CET)
  by mail.netbsd.org with SMTP; 20 Nov 2003 09:05:23 -0000
	by p15139955.pureserver.info (Postfix) with ESMTP id 6AAAD31405A
	for <current-users@netbsd.org>; Thu, 20 Nov 2003 10:05:21 +0100 (CET)
From: Lars Heidieker <lars@heidieker.de>
To: current-users@netbsd.org
Subject: AC97 patch for ICH5 (native mode) & AD1985 codec
Date: Thu, 20 Nov 2003 10:02:26 +0100
User-Agent: KMail/1.5.4
MIME-Version: 1.0
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200311201002.26915.lars@heidieker.de>
Sender: current-users-owner@NetBSD.org

Hi,

the AD1985 codec has the configuration as the AD1980 in terms of swapped 
sourround and lineout.
The ICH5 (at least on Intels PEARL Boards) must be driven in native mode. If 
not you end with the message "could not map codec io space".
I have inserted "ac97_read(as, AC97_REG_RESET, &id1);" in ac97.c that is just 
to make sure the codec is ready after the reset otherwise the read of the 
codec id failed (at least on my board)

Index: ic/ac97.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/ac97.c,v
retrieving revision 1.49
diff -r1.49 ac97.c
327c327
< static void ac97_ad1980_init(struct ac97_softc *);
---
> static void ac97_ad198x_init(struct ac97_softc *);
371c371
<         0xffffffff,                   "Analog Devices AD1980", 
ac97_ad1980_ini
t },
---
>         0xffffffff,                   "Analog Devices AD1980", 
ac97_ad198x_ini
t },
377c377
<         0xffffffff,                   "Analog Devices AD1985" },
---
>         0xffffffff,                   "Analog Devices AD1985", 
ac97_ad198x_ini
t },
899c899
<       host_if->write(host_if->arg, AC97_REG_RESET, 0);
---
>       host_if->write(host_if->arg, AC97_REG_POWER, 0);
903a904,905
>       ac97_read(as, AC97_REG_RESET, &id1);
>
1504c1506
< ac97_ad1980_init(struct ac97_softc *as)
---
> ac97_ad198x_init(struct ac97_softc *as)

Index: pci/auich.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auich.c,v
retrieving revision 1.54
diff -r1.54 auich.c
421,434c421,445
<               v = pci_conf_read(pa->pa_pc, pa->pa_tag, ICH_CFG);
<               pci_conf_write(pa->pa_pc, pa->pa_tag, ICH_CFG, v | 
ICH_CFG_IOSE);
<       }
<       if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO, 0,
<                          &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
<               aprint_error("%s: can't map codec i/o space\n",
<                   sc->sc_dev.dv_xname);
<               return;
<       }
<       if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO, 0,
<                          &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
<               aprint_error("%s: can't map device i/o space\n",
<                   sc->sc_dev.dv_xname);
<               return;
---
>               if (pci_mapreg_map(pa, ICH_MMBAR, PCI_MAPREG_TYPE_MEM, 0,
>                                  &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
>                       aprint_error("%s: can't map codec i/o space\n",
>                           sc->sc_dev.dv_xname);
>                       return;
>               }
>               if (pci_mapreg_map(pa, ICH_MBBAR, PCI_MAPREG_TYPE_MEM, 0,
>                               &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
>                       aprint_error("%s: can't map device i/o space\n",
>                       sc->sc_dev.dv_xname);
>                       return;
>               }
>       } else {
>               if (pci_mapreg_map(pa, ICH_NAMBAR, PCI_MAPREG_TYPE_IO, 0,
>                                  &sc->iot, &sc->mix_ioh, NULL, &mix_size)) {
>                       aprint_error("%s: can't map codec i/o space\n",
>                           sc->sc_dev.dv_xname);
>                       return;
>               }
>               if (pci_mapreg_map(pa, ICH_NABMBAR, PCI_MAPREG_TYPE_IO, 0,
>                               &sc->iot, &sc->aud_ioh, NULL, &aud_size)) {
>                       aprint_error("%s: can't map device i/o space\n",
>                       sc->sc_dev.dv_xname);
>                       return;
>               }
Index: pci/auichreg.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auichreg.h,v
retrieving revision 1.6
diff -r1.6 auichreg.h
45a46,47
> #define ICH_MMBAR     0x18
> #define ICH_MBBAR     0x1c



--Boundary-00=_XaIv/dXGvzSVuLU--