Home | History | Annotate | Line # | Download | only in pci
ichlpcib.c revision 1.11
      1  1.11    martin /*	$NetBSD: ichlpcib.c,v 1.11 2008/04/28 20:23:40 martin Exp $	*/
      2   1.1   xtraeme 
      3   1.1   xtraeme /*-
      4   1.1   xtraeme  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5   1.1   xtraeme  * All rights reserved.
      6   1.1   xtraeme  *
      7   1.1   xtraeme  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   xtraeme  * by Minoura Makoto and Matthew R. Green.
      9   1.1   xtraeme  *
     10   1.1   xtraeme  * Redistribution and use in source and binary forms, with or without
     11   1.1   xtraeme  * modification, are permitted provided that the following conditions
     12   1.1   xtraeme  * are met:
     13   1.1   xtraeme  * 1. Redistributions of source code must retain the above copyright
     14   1.1   xtraeme  *    notice, this list of conditions and the following disclaimer.
     15   1.1   xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   xtraeme  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   xtraeme  *    documentation and/or other materials provided with the distribution.
     18   1.1   xtraeme  *
     19   1.1   xtraeme  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   xtraeme  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   xtraeme  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1   xtraeme  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1   xtraeme  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   xtraeme  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   xtraeme  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   xtraeme  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   xtraeme  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   xtraeme  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   xtraeme  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   xtraeme  */
     31   1.1   xtraeme 
     32   1.1   xtraeme /*
     33   1.1   xtraeme  * Intel I/O Controller Hub (ICHn) LPC Interface Bridge driver
     34   1.1   xtraeme  *
     35   1.1   xtraeme  *  LPC Interface Bridge is basically a pcib (PCI-ISA Bridge), but has
     36   1.1   xtraeme  *  some power management and monitoring functions.
     37   1.1   xtraeme  *  Currently we support the watchdog timer, SpeedStep (on some systems)
     38   1.1   xtraeme  *  and the power management timer.
     39   1.1   xtraeme  */
     40   1.1   xtraeme 
     41   1.1   xtraeme #include <sys/cdefs.h>
     42  1.11    martin __KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.11 2008/04/28 20:23:40 martin Exp $");
     43   1.1   xtraeme 
     44   1.1   xtraeme #include <sys/types.h>
     45   1.1   xtraeme #include <sys/param.h>
     46   1.1   xtraeme #include <sys/systm.h>
     47   1.1   xtraeme #include <sys/device.h>
     48   1.1   xtraeme #include <sys/sysctl.h>
     49   1.6  jmcneill #include <sys/timetc.h>
     50   1.1   xtraeme #include <machine/bus.h>
     51   1.1   xtraeme 
     52   1.1   xtraeme #include <dev/pci/pcivar.h>
     53   1.1   xtraeme #include <dev/pci/pcireg.h>
     54   1.1   xtraeme #include <dev/pci/pcidevs.h>
     55   1.1   xtraeme 
     56   1.1   xtraeme #include <dev/sysmon/sysmonvar.h>
     57   1.1   xtraeme 
     58   1.6  jmcneill #include <dev/ic/acpipmtimer.h>
     59   1.1   xtraeme #include <dev/ic/i82801lpcreg.h>
     60   1.6  jmcneill #include <dev/ic/hpetreg.h>
     61   1.6  jmcneill #include <dev/ic/hpetvar.h>
     62   1.6  jmcneill 
     63   1.6  jmcneill #include "hpet.h"
     64   1.1   xtraeme 
     65   1.1   xtraeme struct lpcib_softc {
     66   1.1   xtraeme 	pci_chipset_tag_t	sc_pc;
     67   1.1   xtraeme 	pcitag_t		sc_pcitag;
     68   1.1   xtraeme 
     69   1.6  jmcneill 	struct pci_attach_args	sc_pa;
     70   1.6  jmcneill 	int			sc_has_rcba;
     71   1.6  jmcneill 	int			sc_has_ich5_hpet;
     72   1.6  jmcneill 
     73   1.6  jmcneill 	/* RCBA */
     74   1.6  jmcneill 	bus_space_tag_t		sc_rcbat;
     75   1.6  jmcneill 	bus_space_handle_t	sc_rcbah;
     76   1.6  jmcneill 	pcireg_t		sc_rcba_reg;
     77   1.6  jmcneill 
     78   1.1   xtraeme 	/* Watchdog variables. */
     79   1.1   xtraeme 	struct sysmon_wdog	sc_smw;
     80   1.1   xtraeme 	bus_space_tag_t		sc_iot;
     81   1.1   xtraeme 	bus_space_handle_t	sc_ioh;
     82   1.6  jmcneill 
     83   1.6  jmcneill #if NHPET > 0
     84   1.6  jmcneill 	/* HPET variables. */
     85   1.6  jmcneill 	uint32_t		sc_hpet_reg;
     86   1.6  jmcneill #endif
     87   1.6  jmcneill 
     88   1.1   xtraeme 	/* Power management */
     89   1.7  drochner 	pcireg_t		sc_pirq[2];
     90   1.6  jmcneill 	pcireg_t		sc_pmcon;
     91   1.6  jmcneill 	pcireg_t		sc_fwhsel2;
     92   1.1   xtraeme };
     93   1.1   xtraeme 
     94   1.9   xtraeme static int lpcibmatch(device_t, cfdata_t, void *);
     95   1.9   xtraeme static void lpcibattach(device_t, device_t, void *);
     96   1.8    dyoung static bool lpcib_suspend(device_t PMF_FN_PROTO);
     97   1.8    dyoung static bool lpcib_resume(device_t PMF_FN_PROTO);
     98   1.1   xtraeme 
     99   1.9   xtraeme static void pmtimer_configure(device_t);
    100   1.1   xtraeme 
    101   1.9   xtraeme static void tcotimer_configure(device_t);
    102   1.1   xtraeme static int tcotimer_setmode(struct sysmon_wdog *);
    103   1.1   xtraeme static int tcotimer_tickle(struct sysmon_wdog *);
    104   1.1   xtraeme static void tcotimer_stop(struct lpcib_softc *);
    105   1.1   xtraeme static void tcotimer_start(struct lpcib_softc *);
    106   1.1   xtraeme static void tcotimer_status_reset(struct lpcib_softc *);
    107   1.9   xtraeme static int  tcotimer_disable_noreboot(device_t);
    108   1.1   xtraeme 
    109   1.9   xtraeme static void speedstep_configure(device_t);
    110   1.1   xtraeme static int speedstep_sysctl_helper(SYSCTLFN_ARGS);
    111   1.1   xtraeme 
    112   1.6  jmcneill #if NHPET > 0
    113   1.9   xtraeme static void lpcib_hpet_configure(device_t);
    114   1.6  jmcneill #endif
    115   1.6  jmcneill 
    116   1.1   xtraeme struct lpcib_softc *speedstep_cookie;	/* XXX */
    117   1.1   xtraeme 
    118   1.1   xtraeme /* Defined in arch/.../pci/pcib.c. */
    119   1.9   xtraeme extern void pcibattach(device_t, device_t, void *);
    120   1.1   xtraeme 
    121   1.9   xtraeme CFATTACH_DECL_NEW(ichlpcib, sizeof(struct lpcib_softc),
    122   1.1   xtraeme     lpcibmatch, lpcibattach, NULL, NULL);
    123   1.1   xtraeme 
    124   1.6  jmcneill static struct lpcib_device {
    125   1.6  jmcneill 	pcireg_t vendor, product;
    126   1.6  jmcneill 	int has_rcba;
    127   1.6  jmcneill 	int has_ich5_hpet;
    128   1.6  jmcneill } lpcib_devices[] = {
    129   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_LPC, 0, 0 },
    130   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_LPC, 0, 0 },
    131   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BAM_LPC, 0, 0 },
    132   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_LPC, 0, 0 },
    133   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CAM_LPC, 0, 0 },
    134   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LPC, 0, 0 },
    135   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_ISA, 0, 0 },
    136   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801EB_LPC, 0, 1 },
    137   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LPC, 1, 0 },
    138   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LPC, 1, 0 },
    139   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801G_LPC, 1, 0 },
    140   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GBM_LPC, 1, 0 },
    141   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GHM_LPC, 1, 0 },
    142   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801H_LPC, 1, 0 },
    143   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HEM_LPC, 1, 0 },
    144   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HH_LPC, 1, 0 },
    145   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HO_LPC, 1, 0 },
    146   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HBM_LPC, 1, 0 },
    147   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IH_LPC, 1, 0 },
    148   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IO_LPC, 1, 0 },
    149   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IR_LPC, 1, 0 },
    150   1.6  jmcneill 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IB_LPC, 1, 0 },
    151   1.6  jmcneill 	{ 0, 0, 0, 0 },
    152   1.6  jmcneill };
    153   1.6  jmcneill 
    154   1.1   xtraeme /*
    155   1.1   xtraeme  * Autoconf callbacks.
    156   1.1   xtraeme  */
    157   1.1   xtraeme static int
    158   1.9   xtraeme lpcibmatch(device_t parent, cfdata_t match, void *aux)
    159   1.1   xtraeme {
    160   1.1   xtraeme 	struct pci_attach_args *pa = aux;
    161   1.6  jmcneill 	struct lpcib_device *lpcib_dev;
    162   1.1   xtraeme 
    163   1.1   xtraeme 	/* We are ISA bridge, of course */
    164   1.1   xtraeme 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
    165   1.1   xtraeme 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
    166   1.1   xtraeme 		return 0;
    167   1.1   xtraeme 
    168   1.6  jmcneill 	for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
    169   1.6  jmcneill 		if (PCI_VENDOR(pa->pa_id) == lpcib_dev->vendor &&
    170   1.6  jmcneill 		    PCI_PRODUCT(pa->pa_id) == lpcib_dev->product)
    171   1.1   xtraeme 			return 10;
    172   1.1   xtraeme 	}
    173   1.1   xtraeme 
    174   1.1   xtraeme 	return 0;
    175   1.1   xtraeme }
    176   1.1   xtraeme 
    177   1.1   xtraeme static void
    178   1.9   xtraeme lpcibattach(device_t parent, device_t self, void *aux)
    179   1.1   xtraeme {
    180   1.1   xtraeme 	struct pci_attach_args *pa = aux;
    181   1.6  jmcneill 	struct lpcib_softc *sc = device_private(self);
    182   1.6  jmcneill 	struct lpcib_device *lpcib_dev;
    183   1.1   xtraeme 
    184   1.1   xtraeme 	sc->sc_pc = pa->pa_pc;
    185   1.1   xtraeme 	sc->sc_pcitag = pa->pa_tag;
    186   1.6  jmcneill 	sc->sc_pa = *pa;
    187   1.6  jmcneill 
    188   1.6  jmcneill 	for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
    189   1.6  jmcneill 		if (PCI_VENDOR(pa->pa_id) != lpcib_dev->vendor ||
    190   1.6  jmcneill 		    PCI_PRODUCT(pa->pa_id) != lpcib_dev->product)
    191   1.6  jmcneill 			continue;
    192   1.6  jmcneill 		sc->sc_has_rcba = lpcib_dev->has_rcba;
    193   1.6  jmcneill 		sc->sc_has_ich5_hpet = lpcib_dev->has_ich5_hpet;
    194   1.6  jmcneill 		break;
    195   1.6  jmcneill 	}
    196   1.1   xtraeme 
    197   1.1   xtraeme 	pcibattach(parent, self, aux);
    198   1.1   xtraeme 
    199   1.1   xtraeme 	/*
    200   1.1   xtraeme 	 * Part of our I/O registers are used as ACPI PM regs.
    201   1.1   xtraeme 	 * Since our ACPI subsystem accesses the I/O space directly so far,
    202   1.1   xtraeme 	 * we do not have to bother bus_space I/O map confliction.
    203   1.1   xtraeme 	 */
    204   1.1   xtraeme 	if (pci_mapreg_map(pa, LPCIB_PCI_PMBASE, PCI_MAPREG_TYPE_IO, 0,
    205   1.1   xtraeme 			   &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    206   1.9   xtraeme 		aprint_error_dev(self, "can't map power management i/o space");
    207   1.1   xtraeme 		return;
    208   1.1   xtraeme 	}
    209   1.1   xtraeme 
    210   1.6  jmcneill 	/* For ICH6 and later, always enable RCBA */
    211   1.6  jmcneill 	if (sc->sc_has_rcba) {
    212   1.6  jmcneill 		pcireg_t rcba;
    213   1.6  jmcneill 
    214   1.6  jmcneill 		sc->sc_rcbat = sc->sc_pa.pa_memt;
    215   1.6  jmcneill 
    216   1.6  jmcneill 		rcba = pci_conf_read(sc->sc_pc, sc->sc_pcitag, LPCIB_RCBA);
    217   1.6  jmcneill 		if ((rcba & LPCIB_RCBA_EN) == 0) {
    218   1.9   xtraeme 			aprint_error_dev(self, "RCBA is not enabled");
    219   1.6  jmcneill 			return;
    220   1.6  jmcneill 		}
    221   1.6  jmcneill 		rcba &= ~LPCIB_RCBA_EN;
    222   1.6  jmcneill 
    223   1.6  jmcneill 		if (bus_space_map(sc->sc_rcbat, rcba, LPCIB_RCBA_SIZE, 0,
    224   1.6  jmcneill 				  &sc->sc_rcbah)) {
    225   1.9   xtraeme 			aprint_error_dev(self, "RCBA could not be mapped");
    226   1.6  jmcneill 			return;
    227   1.6  jmcneill 		}
    228   1.6  jmcneill 	}
    229   1.6  jmcneill 
    230   1.1   xtraeme 	/* Set up the power management timer. */
    231   1.9   xtraeme 	pmtimer_configure(self);
    232   1.1   xtraeme 
    233   1.1   xtraeme 	/* Set up the TCO (watchdog). */
    234   1.9   xtraeme 	tcotimer_configure(self);
    235   1.1   xtraeme 
    236   1.1   xtraeme 	/* Set up SpeedStep. */
    237   1.9   xtraeme 	speedstep_configure(self);
    238   1.1   xtraeme 
    239   1.6  jmcneill #if NHPET > 0
    240   1.6  jmcneill 	/* Set up HPET. */
    241   1.9   xtraeme 	lpcib_hpet_configure(self);
    242   1.6  jmcneill #endif
    243   1.6  jmcneill 
    244   1.6  jmcneill 	/* Install power handler */
    245   1.6  jmcneill 	if (!pmf_device_register(self, lpcib_suspend, lpcib_resume))
    246   1.6  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    247   1.6  jmcneill }
    248   1.6  jmcneill 
    249   1.6  jmcneill static bool
    250   1.8    dyoung lpcib_suspend(device_t dv PMF_FN_ARGS)
    251   1.6  jmcneill {
    252   1.6  jmcneill 	struct lpcib_softc *sc = device_private(dv);
    253   1.6  jmcneill 	pci_chipset_tag_t pc = sc->sc_pc;
    254   1.6  jmcneill 	pcitag_t tag = sc->sc_pcitag;
    255   1.6  jmcneill 
    256   1.6  jmcneill 	/* capture PIRQ routing control registers */
    257   1.6  jmcneill 	sc->sc_pirq[0] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQA_ROUT);
    258   1.7  drochner 	sc->sc_pirq[1] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQE_ROUT);
    259   1.6  jmcneill 
    260   1.6  jmcneill 	sc->sc_pmcon = pci_conf_read(pc, tag, LPCIB_PCI_GEN_PMCON_1);
    261   1.6  jmcneill 	sc->sc_fwhsel2 = pci_conf_read(pc, tag, LPCIB_PCI_GEN_STA);
    262   1.6  jmcneill 
    263   1.6  jmcneill 	if (sc->sc_has_rcba) {
    264   1.6  jmcneill 		sc->sc_rcba_reg = pci_conf_read(pc, tag, LPCIB_RCBA);
    265   1.6  jmcneill #if NHPET > 0
    266   1.6  jmcneill 		sc->sc_hpet_reg = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    267   1.6  jmcneill 		    LPCIB_RCBA_HPTC);
    268   1.6  jmcneill #endif
    269   1.6  jmcneill 	} else if (sc->sc_has_ich5_hpet) {
    270   1.6  jmcneill #if NHPET > 0
    271   1.6  jmcneill 		sc->sc_hpet_reg = pci_conf_read(pc, tag, LPCIB_PCI_GEN_CNTL);
    272   1.6  jmcneill #endif
    273   1.6  jmcneill 	}
    274   1.6  jmcneill 
    275   1.6  jmcneill 	return true;
    276   1.6  jmcneill }
    277   1.6  jmcneill 
    278   1.6  jmcneill static bool
    279   1.8    dyoung lpcib_resume(device_t dv PMF_FN_ARGS)
    280   1.6  jmcneill {
    281   1.6  jmcneill 	struct lpcib_softc *sc = device_private(dv);
    282   1.6  jmcneill 	pci_chipset_tag_t pc = sc->sc_pc;
    283   1.6  jmcneill 	pcitag_t tag = sc->sc_pcitag;
    284   1.6  jmcneill 
    285   1.6  jmcneill 	/* restore PIRQ routing control registers */
    286   1.6  jmcneill 	pci_conf_write(pc, tag, LPCIB_PCI_PIRQA_ROUT, sc->sc_pirq[0]);
    287   1.7  drochner 	pci_conf_write(pc, tag, LPCIB_PCI_PIRQE_ROUT, sc->sc_pirq[1]);
    288   1.6  jmcneill 
    289   1.6  jmcneill 	pci_conf_write(pc, tag, LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon);
    290   1.6  jmcneill 	pci_conf_write(pc, tag, LPCIB_PCI_GEN_STA, sc->sc_fwhsel2);
    291   1.6  jmcneill 
    292   1.6  jmcneill 	if (sc->sc_has_rcba) {
    293   1.6  jmcneill 		pci_conf_write(pc, tag, LPCIB_RCBA, sc->sc_rcba_reg);
    294   1.6  jmcneill #if NHPET > 0
    295   1.6  jmcneill 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
    296   1.6  jmcneill 		    sc->sc_hpet_reg);
    297   1.6  jmcneill #endif
    298   1.6  jmcneill 	} else if (sc->sc_has_ich5_hpet) {
    299   1.6  jmcneill #if NHPET > 0
    300   1.6  jmcneill 		pci_conf_write(pc, tag, LPCIB_PCI_GEN_CNTL, sc->sc_hpet_reg);
    301   1.6  jmcneill #endif
    302   1.6  jmcneill 	}
    303   1.1   xtraeme 
    304   1.6  jmcneill 	return true;
    305   1.1   xtraeme }
    306   1.1   xtraeme 
    307   1.1   xtraeme /*
    308   1.1   xtraeme  * Initialize the power management timer.
    309   1.1   xtraeme  */
    310   1.1   xtraeme static void
    311   1.9   xtraeme pmtimer_configure(device_t self)
    312   1.1   xtraeme {
    313   1.9   xtraeme 	struct lpcib_softc *sc = device_private(self);
    314   1.1   xtraeme 	pcireg_t control;
    315   1.1   xtraeme 
    316   1.1   xtraeme 	/*
    317   1.1   xtraeme 	 * Check if power management I/O space is enabled and enable the ACPI_EN
    318   1.1   xtraeme 	 * bit if it's disabled.
    319   1.1   xtraeme 	 */
    320   1.6  jmcneill 	control = pci_conf_read(sc->sc_pc, sc->sc_pcitag, LPCIB_PCI_ACPI_CNTL);
    321   1.1   xtraeme 	if ((control & LPCIB_PCI_ACPI_CNTL_EN) == 0) {
    322   1.1   xtraeme 		control |= LPCIB_PCI_ACPI_CNTL_EN;
    323   1.6  jmcneill 		pci_conf_write(sc->sc_pc, sc->sc_pcitag, LPCIB_PCI_ACPI_CNTL,
    324   1.1   xtraeme 		    control);
    325   1.1   xtraeme 	}
    326   1.1   xtraeme 
    327   1.1   xtraeme 	/* Attach our PM timer with the generic acpipmtimer function */
    328   1.9   xtraeme 	acpipmtimer_attach(self, sc->sc_iot, sc->sc_ioh,
    329   1.1   xtraeme 	    LPCIB_PM1_TMR, 0);
    330   1.1   xtraeme }
    331   1.1   xtraeme 
    332   1.1   xtraeme /*
    333   1.1   xtraeme  * Initialize the watchdog timer.
    334   1.1   xtraeme  */
    335   1.1   xtraeme static void
    336   1.9   xtraeme tcotimer_configure(device_t self)
    337   1.1   xtraeme {
    338   1.9   xtraeme 	struct lpcib_softc *sc = device_private(self);
    339   1.1   xtraeme 	uint32_t ioreg;
    340   1.1   xtraeme 	unsigned int period;
    341   1.1   xtraeme 
    342   1.1   xtraeme 	/*
    343   1.4   xtraeme 	 * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
    344   1.1   xtraeme 	 * in the SMI_EN register is the last chance.
    345   1.1   xtraeme 	 */
    346   1.9   xtraeme 	if (tcotimer_disable_noreboot(self)) {
    347   1.1   xtraeme 		ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
    348   1.1   xtraeme 		ioreg |= LPCIB_SMI_EN_TCO_EN;
    349   1.1   xtraeme 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
    350   1.1   xtraeme 	}
    351   1.1   xtraeme 
    352   1.1   xtraeme 	/* Reset the watchdog status registers. */
    353   1.1   xtraeme 	tcotimer_status_reset(sc);
    354   1.1   xtraeme 
    355   1.1   xtraeme 	/* Explicitly stop the TCO timer. */
    356   1.1   xtraeme 	tcotimer_stop(sc);
    357   1.1   xtraeme 
    358   1.1   xtraeme 	/*
    359   1.1   xtraeme 	 * Register the driver with the sysmon watchdog framework.
    360   1.1   xtraeme 	 */
    361   1.9   xtraeme 	sc->sc_smw.smw_name = device_xname(self);
    362   1.1   xtraeme 	sc->sc_smw.smw_cookie = sc;
    363   1.1   xtraeme 	sc->sc_smw.smw_setmode = tcotimer_setmode;
    364   1.1   xtraeme 	sc->sc_smw.smw_tickle = tcotimer_tickle;
    365   1.6  jmcneill 	if (sc->sc_has_rcba)
    366   1.1   xtraeme 		period = LPCIB_TCOTIMER2_MAX_TICK;
    367   1.1   xtraeme 	else
    368   1.1   xtraeme 		period = LPCIB_TCOTIMER_MAX_TICK;
    369   1.1   xtraeme 	sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(period);
    370   1.1   xtraeme 
    371   1.1   xtraeme 	if (sysmon_wdog_register(&sc->sc_smw)) {
    372   1.9   xtraeme 		aprint_error_dev(self, "unable to register TCO timer"
    373   1.9   xtraeme 		       "as a sysmon watchdog device.\n");
    374   1.1   xtraeme 		return;
    375   1.1   xtraeme 	}
    376   1.1   xtraeme 
    377   1.9   xtraeme 	aprint_verbose_dev(self, "TCO (watchdog) timer configured.\n");
    378   1.1   xtraeme }
    379   1.1   xtraeme 
    380   1.1   xtraeme /*
    381   1.1   xtraeme  * Sysmon watchdog callbacks.
    382   1.1   xtraeme  */
    383   1.1   xtraeme static int
    384   1.1   xtraeme tcotimer_setmode(struct sysmon_wdog *smw)
    385   1.1   xtraeme {
    386   1.1   xtraeme 	struct lpcib_softc *sc = smw->smw_cookie;
    387   1.1   xtraeme 	unsigned int period;
    388   1.1   xtraeme 	uint16_t ich6period = 0;
    389   1.1   xtraeme 
    390   1.1   xtraeme 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    391   1.1   xtraeme 		/* Stop the TCO timer. */
    392   1.1   xtraeme 		tcotimer_stop(sc);
    393   1.1   xtraeme 	} else {
    394   1.1   xtraeme 		/*
    395   1.6  jmcneill 		 * ICH6 or newer are limited to 2s min and 613s max.
    396   1.1   xtraeme 		 * ICH5 or older are limited to 4s min and 39s max.
    397   1.1   xtraeme 		 */
    398   1.6  jmcneill 		if (sc->sc_has_rcba) {
    399   1.6  jmcneill 			if (smw->smw_period < LPCIB_TCOTIMER2_MIN_TICK ||
    400   1.6  jmcneill 			    smw->smw_period > LPCIB_TCOTIMER2_MAX_TICK)
    401   1.6  jmcneill 				return EINVAL;
    402   1.6  jmcneill 		} else {
    403   1.5   xtraeme 			if (smw->smw_period < LPCIB_TCOTIMER_MIN_TICK ||
    404   1.5   xtraeme 			    smw->smw_period > LPCIB_TCOTIMER_MAX_TICK)
    405   1.1   xtraeme 				return EINVAL;
    406   1.1   xtraeme 		}
    407   1.5   xtraeme 		period = lpcib_tcotimer_second_to_tick(smw->smw_period);
    408   1.5   xtraeme 
    409   1.1   xtraeme 		/* Stop the TCO timer, */
    410   1.1   xtraeme 		tcotimer_stop(sc);
    411   1.1   xtraeme 
    412   1.1   xtraeme 		/* set the timeout, */
    413   1.6  jmcneill 		if (sc->sc_has_rcba) {
    414   1.1   xtraeme 			/* ICH6 or newer */
    415   1.1   xtraeme 			ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    416   1.1   xtraeme 						      LPCIB_TCO_TMR2);
    417   1.1   xtraeme 			ich6period &= 0xfc00;
    418   1.1   xtraeme 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    419   1.1   xtraeme 					  LPCIB_TCO_TMR2, ich6period | period);
    420   1.1   xtraeme 		} else {
    421   1.1   xtraeme 			/* ICH5 or older */
    422   1.1   xtraeme 			period |= bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    423   1.1   xtraeme 						   LPCIB_TCO_TMR);
    424   1.1   xtraeme 			period &= 0xc0;
    425   1.1   xtraeme 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    426   1.1   xtraeme 					  LPCIB_TCO_TMR, period);
    427   1.1   xtraeme 		}
    428   1.1   xtraeme 
    429   1.1   xtraeme 		/* and start/reload the timer. */
    430   1.1   xtraeme 		tcotimer_start(sc);
    431   1.1   xtraeme 		tcotimer_tickle(smw);
    432   1.1   xtraeme 	}
    433   1.1   xtraeme 
    434   1.1   xtraeme 	return 0;
    435   1.1   xtraeme }
    436   1.1   xtraeme 
    437   1.1   xtraeme static int
    438   1.1   xtraeme tcotimer_tickle(struct sysmon_wdog *smw)
    439   1.1   xtraeme {
    440   1.1   xtraeme 	struct lpcib_softc *sc = smw->smw_cookie;
    441   1.1   xtraeme 
    442   1.1   xtraeme 	/* any value is allowed */
    443   1.6  jmcneill 	if (sc->sc_has_rcba)
    444   1.6  jmcneill 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    445   1.6  jmcneill 	else
    446   1.1   xtraeme 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
    447   1.1   xtraeme 
    448   1.1   xtraeme 	return 0;
    449   1.1   xtraeme }
    450   1.1   xtraeme 
    451   1.1   xtraeme static void
    452   1.1   xtraeme tcotimer_stop(struct lpcib_softc *sc)
    453   1.1   xtraeme {
    454   1.1   xtraeme 	uint16_t ioreg;
    455   1.1   xtraeme 
    456   1.1   xtraeme 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    457   1.1   xtraeme 	ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
    458   1.1   xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    459   1.1   xtraeme }
    460   1.1   xtraeme 
    461   1.1   xtraeme static void
    462   1.1   xtraeme tcotimer_start(struct lpcib_softc *sc)
    463   1.1   xtraeme {
    464   1.1   xtraeme 	uint16_t ioreg;
    465   1.1   xtraeme 
    466   1.1   xtraeme 	ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
    467   1.1   xtraeme 	ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
    468   1.1   xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
    469   1.1   xtraeme }
    470   1.1   xtraeme 
    471   1.1   xtraeme static void
    472   1.1   xtraeme tcotimer_status_reset(struct lpcib_softc *sc)
    473   1.1   xtraeme {
    474   1.1   xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
    475   1.1   xtraeme 			  LPCIB_TCO1_STS_TIMEOUT);
    476   1.1   xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    477   1.1   xtraeme 			  LPCIB_TCO2_STS_BOOT_STS);
    478   1.1   xtraeme 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
    479   1.1   xtraeme 			  LPCIB_TCO2_STS_SECONDS_TO_STS);
    480   1.1   xtraeme }
    481   1.1   xtraeme 
    482   1.1   xtraeme /*
    483   1.4   xtraeme  * Clear the No Reboot (NR) bit, this enables reboots when the timer
    484   1.4   xtraeme  * reaches the timeout for the second time.
    485   1.1   xtraeme  */
    486   1.1   xtraeme static int
    487   1.9   xtraeme tcotimer_disable_noreboot(device_t self)
    488   1.1   xtraeme {
    489   1.9   xtraeme 	struct lpcib_softc *sc = device_private(self);
    490   1.1   xtraeme 
    491   1.6  jmcneill 	if (sc->sc_has_rcba) {
    492   1.6  jmcneill 		uint32_t status;
    493   1.6  jmcneill 
    494   1.9   xtraeme 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    495   1.9   xtraeme 		    LPCIB_GCS_OFFSET);
    496   1.6  jmcneill 		status &= ~LPCIB_GCS_NO_REBOOT;
    497   1.9   xtraeme 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah,
    498   1.9   xtraeme 		    LPCIB_GCS_OFFSET, status);
    499   1.9   xtraeme 		status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    500   1.9   xtraeme 		    LPCIB_GCS_OFFSET);
    501   1.6  jmcneill 		if (status & LPCIB_GCS_NO_REBOOT)
    502   1.6  jmcneill 			goto error;
    503   1.6  jmcneill 	} else {
    504   1.6  jmcneill 		pcireg_t pcireg;
    505   1.6  jmcneill 
    506   1.1   xtraeme 		pcireg = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    507   1.1   xtraeme 				       LPCIB_PCI_GEN_STA);
    508   1.1   xtraeme 		if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
    509   1.1   xtraeme 			/* TCO timeout reset is disabled; try to enable it */
    510   1.1   xtraeme 			pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
    511   1.1   xtraeme 			pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    512   1.1   xtraeme 				       LPCIB_PCI_GEN_STA, pcireg);
    513   1.1   xtraeme 			if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
    514   1.1   xtraeme 				goto error;
    515   1.1   xtraeme 		}
    516   1.1   xtraeme 	}
    517   1.1   xtraeme 
    518   1.1   xtraeme 	return 0;
    519   1.1   xtraeme error:
    520   1.9   xtraeme 	aprint_error_dev(self, "TCO timer reboot disabled by hardware; "
    521   1.9   xtraeme 	    "hope SMBIOS properly handles it.\n");
    522   1.1   xtraeme 	return EINVAL;
    523   1.1   xtraeme }
    524   1.1   xtraeme 
    525   1.1   xtraeme 
    526   1.1   xtraeme /*
    527   1.1   xtraeme  * Intel ICH SpeedStep support.
    528   1.1   xtraeme  */
    529   1.1   xtraeme #define SS_READ(sc, reg) \
    530   1.1   xtraeme 	bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
    531   1.1   xtraeme #define SS_WRITE(sc, reg, val) \
    532   1.1   xtraeme 	bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
    533   1.1   xtraeme 
    534   1.1   xtraeme /*
    535   1.1   xtraeme  * Linux driver says that SpeedStep on older chipsets cause
    536   1.1   xtraeme  * lockups on Dell Inspiron 8000 and 8100.
    537   1.1   xtraeme  */
    538   1.1   xtraeme static int
    539   1.1   xtraeme speedstep_bad_hb_check(struct pci_attach_args *pa)
    540   1.1   xtraeme {
    541   1.1   xtraeme 
    542   1.1   xtraeme 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82815_FULL_HUB &&
    543   1.1   xtraeme 	    PCI_REVISION(pa->pa_class) < 5)
    544   1.1   xtraeme 		return 1;
    545   1.1   xtraeme 
    546   1.1   xtraeme 	return 0;
    547   1.1   xtraeme }
    548   1.1   xtraeme 
    549   1.1   xtraeme static void
    550   1.9   xtraeme speedstep_configure(device_t self)
    551   1.1   xtraeme {
    552   1.9   xtraeme 	struct lpcib_softc *sc = device_private(self);
    553   1.1   xtraeme 	const struct sysctlnode	*node, *ssnode;
    554   1.1   xtraeme 	int rv;
    555   1.1   xtraeme 
    556   1.1   xtraeme 	/* Supported on ICH2-M, ICH3-M and ICH4-M.  */
    557   1.6  jmcneill 	if (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801DB_ISA ||
    558   1.6  jmcneill 	    PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801CAM_LPC ||
    559   1.6  jmcneill 	    (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801BAM_LPC &&
    560   1.6  jmcneill 	     pci_find_device(&sc->sc_pa, speedstep_bad_hb_check) == 0)) {
    561   1.1   xtraeme 		uint8_t pmcon;
    562   1.1   xtraeme 
    563   1.1   xtraeme 		/* Enable SpeedStep if it isn't already enabled. */
    564   1.6  jmcneill 		pmcon = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    565   1.1   xtraeme 				      LPCIB_PCI_GEN_PMCON_1);
    566   1.1   xtraeme 		if ((pmcon & LPCIB_PCI_GEN_PMCON_1_SS_EN) == 0)
    567   1.6  jmcneill 			pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    568   1.1   xtraeme 				       LPCIB_PCI_GEN_PMCON_1,
    569   1.1   xtraeme 				       pmcon | LPCIB_PCI_GEN_PMCON_1_SS_EN);
    570   1.1   xtraeme 
    571   1.1   xtraeme 		/* Put in machdep.speedstep_state (0 for low, 1 for high). */
    572   1.1   xtraeme 		if ((rv = sysctl_createv(NULL, 0, NULL, &node,
    573   1.1   xtraeme 		    CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
    574   1.1   xtraeme 		    NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
    575   1.1   xtraeme 			goto err;
    576   1.1   xtraeme 
    577   1.1   xtraeme 		/* CTLFLAG_ANYWRITE? kernel option like EST? */
    578   1.1   xtraeme 		if ((rv = sysctl_createv(NULL, 0, &node, &ssnode,
    579   1.1   xtraeme 		    CTLFLAG_READWRITE, CTLTYPE_INT, "speedstep_state", NULL,
    580   1.1   xtraeme 		    speedstep_sysctl_helper, 0, NULL, 0, CTL_CREATE,
    581   1.1   xtraeme 		    CTL_EOL)) != 0)
    582   1.1   xtraeme 			goto err;
    583   1.1   xtraeme 
    584   1.1   xtraeme 		/* XXX save the sc for IO tag/handle */
    585   1.1   xtraeme 		speedstep_cookie = sc;
    586   1.9   xtraeme 		aprint_verbose_dev(self, "SpeedStep enabled\n");
    587   1.1   xtraeme 	}
    588   1.1   xtraeme 
    589   1.1   xtraeme 	return;
    590   1.1   xtraeme 
    591   1.1   xtraeme err:
    592   1.1   xtraeme 	aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__, rv);
    593   1.1   xtraeme }
    594   1.1   xtraeme 
    595   1.1   xtraeme /*
    596   1.1   xtraeme  * get/set the SpeedStep state: 0 == low power, 1 == high power.
    597   1.1   xtraeme  */
    598   1.1   xtraeme static int
    599   1.1   xtraeme speedstep_sysctl_helper(SYSCTLFN_ARGS)
    600   1.1   xtraeme {
    601   1.1   xtraeme 	struct sysctlnode	node;
    602   1.1   xtraeme 	struct lpcib_softc 	*sc = speedstep_cookie;
    603   1.1   xtraeme 	uint8_t			state, state2;
    604   1.1   xtraeme 	int			ostate, nstate, s, error = 0;
    605   1.1   xtraeme 
    606   1.1   xtraeme 	/*
    607   1.1   xtraeme 	 * We do the dance with spl's to avoid being at high ipl during
    608   1.1   xtraeme 	 * sysctl_lookup() which can both copyin and copyout.
    609   1.1   xtraeme 	 */
    610   1.1   xtraeme 	s = splserial();
    611   1.1   xtraeme 	state = SS_READ(sc, LPCIB_PM_SS_CNTL);
    612   1.1   xtraeme 	splx(s);
    613   1.1   xtraeme 	if ((state & LPCIB_PM_SS_STATE_LOW) == 0)
    614   1.1   xtraeme 		ostate = 1;
    615   1.1   xtraeme 	else
    616   1.1   xtraeme 		ostate = 0;
    617   1.1   xtraeme 	nstate = ostate;
    618   1.1   xtraeme 
    619   1.1   xtraeme 	node = *rnode;
    620   1.1   xtraeme 	node.sysctl_data = &nstate;
    621   1.1   xtraeme 
    622   1.1   xtraeme 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    623   1.1   xtraeme 	if (error || newp == NULL)
    624   1.1   xtraeme 		goto out;
    625   1.1   xtraeme 
    626   1.1   xtraeme 	/* Only two states are available */
    627   1.1   xtraeme 	if (nstate != 0 && nstate != 1) {
    628   1.1   xtraeme 		error = EINVAL;
    629   1.1   xtraeme 		goto out;
    630   1.1   xtraeme 	}
    631   1.1   xtraeme 
    632   1.1   xtraeme 	s = splserial();
    633   1.1   xtraeme 	state2 = SS_READ(sc, LPCIB_PM_SS_CNTL);
    634   1.1   xtraeme 	if ((state2 & LPCIB_PM_SS_STATE_LOW) == 0)
    635   1.1   xtraeme 		ostate = 1;
    636   1.1   xtraeme 	else
    637   1.1   xtraeme 		ostate = 0;
    638   1.1   xtraeme 
    639   1.1   xtraeme 	if (ostate != nstate) {
    640   1.1   xtraeme 		uint8_t cntl;
    641   1.1   xtraeme 
    642   1.1   xtraeme 		if (nstate == 0)
    643   1.1   xtraeme 			state2 |= LPCIB_PM_SS_STATE_LOW;
    644   1.1   xtraeme 		else
    645   1.1   xtraeme 			state2 &= ~LPCIB_PM_SS_STATE_LOW;
    646   1.1   xtraeme 
    647   1.1   xtraeme 		/*
    648   1.1   xtraeme 		 * Must disable bus master arbitration during the change.
    649   1.1   xtraeme 		 */
    650   1.1   xtraeme 		cntl = SS_READ(sc, LPCIB_PM_CTRL);
    651   1.1   xtraeme 		SS_WRITE(sc, LPCIB_PM_CTRL, cntl | LPCIB_PM_SS_CNTL_ARB_DIS);
    652   1.1   xtraeme 		SS_WRITE(sc, LPCIB_PM_SS_CNTL, state2);
    653   1.1   xtraeme 		SS_WRITE(sc, LPCIB_PM_CTRL, cntl);
    654   1.1   xtraeme 	}
    655   1.1   xtraeme 	splx(s);
    656   1.1   xtraeme out:
    657   1.1   xtraeme 	return error;
    658   1.1   xtraeme }
    659   1.6  jmcneill 
    660   1.6  jmcneill #if NHPET > 0
    661   1.6  jmcneill struct lpcib_hpet_attach_arg {
    662   1.6  jmcneill 	bus_space_tag_t hpet_mem_t;
    663   1.6  jmcneill 	uint32_t hpet_reg;
    664   1.6  jmcneill };
    665   1.6  jmcneill 
    666   1.6  jmcneill static int
    667   1.9   xtraeme lpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
    668   1.6  jmcneill {
    669   1.6  jmcneill 	struct lpcib_hpet_attach_arg *arg = aux;
    670   1.6  jmcneill 	bus_space_tag_t tag;
    671   1.6  jmcneill 	bus_space_handle_t handle;
    672   1.6  jmcneill 
    673   1.6  jmcneill 	tag = arg->hpet_mem_t;
    674   1.6  jmcneill 
    675   1.6  jmcneill 	if (bus_space_map(tag, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &handle)) {
    676  1.10    cegger 		aprint_verbose_dev(parent, "HPET window not mapped, skipping\n");
    677   1.6  jmcneill 		return 0;
    678   1.6  jmcneill 	}
    679   1.6  jmcneill 	bus_space_unmap(tag, handle, HPET_WINDOW_SIZE);
    680   1.6  jmcneill 
    681   1.6  jmcneill 	return 1;
    682   1.6  jmcneill }
    683   1.6  jmcneill 
    684   1.6  jmcneill static void
    685   1.6  jmcneill lpcib_hpet_attach(device_t parent, device_t self, void *aux)
    686   1.6  jmcneill {
    687   1.6  jmcneill 	struct hpet_softc *sc = device_private(self);
    688   1.6  jmcneill 	struct lpcib_hpet_attach_arg *arg = aux;
    689   1.6  jmcneill 
    690   1.6  jmcneill 	aprint_naive("\n");
    691   1.6  jmcneill 	aprint_normal("\n");
    692   1.6  jmcneill 
    693   1.6  jmcneill 	sc->sc_memt = arg->hpet_mem_t;
    694   1.6  jmcneill 
    695   1.6  jmcneill 	if (bus_space_map(sc->sc_memt, arg->hpet_reg, HPET_WINDOW_SIZE, 0,
    696   1.6  jmcneill 			  &sc->sc_memh)) {
    697   1.9   xtraeme 		aprint_error_dev(self,
    698   1.9   xtraeme 		    "HPET memory window could not be mapped");
    699   1.6  jmcneill 		return;
    700   1.6  jmcneill 	}
    701   1.6  jmcneill 
    702   1.9   xtraeme 	hpet_attach_subr(self);
    703   1.6  jmcneill }
    704   1.6  jmcneill 
    705   1.9   xtraeme CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc), lpcib_hpet_match,
    706   1.6  jmcneill     lpcib_hpet_attach, NULL, NULL);
    707   1.6  jmcneill 
    708   1.6  jmcneill static void
    709   1.9   xtraeme lpcib_hpet_configure(device_t self)
    710   1.6  jmcneill {
    711   1.9   xtraeme 	struct lpcib_softc *sc = device_private(self);
    712   1.6  jmcneill 	struct lpcib_hpet_attach_arg arg;
    713   1.6  jmcneill 	uint32_t hpet_reg, val;
    714   1.6  jmcneill 
    715   1.6  jmcneill 	if (sc->sc_has_ich5_hpet) {
    716   1.9   xtraeme 		val = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
    717   1.9   xtraeme 		    LPCIB_PCI_GEN_CNTL);
    718   1.6  jmcneill 		switch (val & LPCIB_ICH5_HPTC_WIN_MASK) {
    719   1.6  jmcneill 		case LPCIB_ICH5_HPTC_0000:
    720   1.6  jmcneill 			hpet_reg = LPCIB_ICH5_HPTC_0000_BASE;
    721   1.6  jmcneill 			break;
    722   1.6  jmcneill 		case LPCIB_ICH5_HPTC_1000:
    723   1.6  jmcneill 			hpet_reg = LPCIB_ICH5_HPTC_1000_BASE;
    724   1.6  jmcneill 			break;
    725   1.6  jmcneill 		case LPCIB_ICH5_HPTC_2000:
    726   1.6  jmcneill 			hpet_reg = LPCIB_ICH5_HPTC_2000_BASE;
    727   1.6  jmcneill 			break;
    728   1.6  jmcneill 		case LPCIB_ICH5_HPTC_3000:
    729   1.6  jmcneill 			hpet_reg = LPCIB_ICH5_HPTC_3000_BASE;
    730   1.6  jmcneill 			break;
    731   1.6  jmcneill 		default:
    732   1.6  jmcneill 			return;
    733   1.6  jmcneill 		}
    734   1.6  jmcneill 		val |= sc->sc_hpet_reg | LPCIB_ICH5_HPTC_EN;
    735   1.9   xtraeme 		pci_conf_write(sc->sc_pc, sc->sc_pcitag,
    736   1.9   xtraeme 		    LPCIB_PCI_GEN_CNTL, val);
    737   1.6  jmcneill 	} else if (sc->sc_has_rcba) {
    738   1.6  jmcneill 		val = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
    739   1.6  jmcneill 		    LPCIB_RCBA_HPTC);
    740   1.6  jmcneill 		switch (val & LPCIB_RCBA_HPTC_WIN_MASK) {
    741   1.6  jmcneill 		case LPCIB_RCBA_HPTC_0000:
    742   1.6  jmcneill 			hpet_reg = LPCIB_RCBA_HPTC_0000_BASE;
    743   1.6  jmcneill 			break;
    744   1.6  jmcneill 		case LPCIB_RCBA_HPTC_1000:
    745   1.6  jmcneill 			hpet_reg = LPCIB_RCBA_HPTC_1000_BASE;
    746   1.6  jmcneill 			break;
    747   1.6  jmcneill 		case LPCIB_RCBA_HPTC_2000:
    748   1.6  jmcneill 			hpet_reg = LPCIB_RCBA_HPTC_2000_BASE;
    749   1.6  jmcneill 			break;
    750   1.6  jmcneill 		case LPCIB_RCBA_HPTC_3000:
    751   1.6  jmcneill 			hpet_reg = LPCIB_RCBA_HPTC_3000_BASE;
    752   1.6  jmcneill 			break;
    753   1.6  jmcneill 		default:
    754   1.6  jmcneill 			return;
    755   1.6  jmcneill 		}
    756   1.6  jmcneill 		val |= LPCIB_RCBA_HPTC_EN;
    757   1.6  jmcneill 		bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
    758   1.6  jmcneill 		    val);
    759   1.6  jmcneill 	} else {
    760   1.6  jmcneill 		/* No HPET here */
    761   1.6  jmcneill 		return;
    762   1.6  jmcneill 	}
    763   1.6  jmcneill 
    764   1.6  jmcneill 	arg.hpet_mem_t = sc->sc_pa.pa_memt;
    765   1.6  jmcneill 	arg.hpet_reg = hpet_reg;
    766   1.6  jmcneill 
    767   1.9   xtraeme 	config_found_ia(self, "hpetichbus", &arg, NULL);
    768   1.6  jmcneill }
    769   1.6  jmcneill #endif
    770