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