1 /* $NetBSD: ichlpcib.c,v 1.22 2010/01/08 00:09:45 dyoung Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Minoura Makoto and Matthew R. Green.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Intel I/O Controller Hub (ICHn) LPC Interface Bridge driver
35 * LPC Interface Bridge is basically a pcib (PCI-ISA Bridge), but has
36 * some power management and monitoring functions.
37 * Currently we support the watchdog timer, SpeedStep (on some systems)
38 * and the power management timer.
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.22 2010/01/08 00:09:45 dyoung Exp $");
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/sysctl.h>
49 #include <sys/timetc.h>
51 #include <machine/bus.h>
53 #include <dev/pci/pcivar.h>
54 #include <dev/pci/pcireg.h>
55 #include <dev/pci/pcidevs.h>
57 #include <dev/gpio/gpiovar.h>
58 #include <dev/sysmon/sysmonvar.h>
60 #include <dev/ic/acpipmtimer.h>
61 #include <dev/ic/i82801lpcreg.h>
62 #include <dev/ic/hpetreg.h>
63 #include <dev/ic/hpetvar.h>
69 #define LPCIB_GPIO_NPINS 64
72 /* we call pcibattach() which assumes this starts like this: */
73 struct pcib_softc sc_pcib
;
75 struct pci_attach_args sc_pa
;
80 bus_space_tag_t sc_rcbat
;
81 bus_space_handle_t sc_rcbah
;
84 /* Watchdog variables. */
85 struct sysmon_wdog sc_smw
;
86 bus_space_tag_t sc_iot
;
87 bus_space_handle_t sc_ioh
;
98 bus_space_tag_t sc_gpio_iot
;
99 bus_space_handle_t sc_gpio_ioh
;
100 bus_size_t sc_gpio_ios
;
101 struct gpio_chipset_tag sc_gpio_gc
;
102 gpio_pin_t sc_gpio_pins
[LPCIB_GPIO_NPINS
];
106 pcireg_t sc_pmcon_orig
;
108 /* Power management */
115 acpipmtimer_t sc_pmtimer
;
116 pcireg_t sc_acpi_cntl
;
118 struct sysctllog
*sc_log
;
121 static int lpcibmatch(device_t
, cfdata_t
, void *);
122 static void lpcibattach(device_t
, device_t
, void *);
123 static int lpcibdetach(device_t
, int);
124 static void lpcibchilddet(device_t
, device_t
);
125 static int lpcibrescan(device_t
, const char *, const int *);
126 static bool lpcib_suspend(device_t
, pmf_qual_t
);
127 static bool lpcib_resume(device_t
, pmf_qual_t
);
128 static bool lpcib_shutdown(device_t
, int);
130 static void pmtimer_configure(device_t
);
131 static int pmtimer_unconfigure(device_t
, int);
133 static void tcotimer_configure(device_t
);
134 static int tcotimer_unconfigure(device_t
, int);
135 static int tcotimer_setmode(struct sysmon_wdog
*);
136 static int tcotimer_tickle(struct sysmon_wdog
*);
137 static void tcotimer_stop(struct lpcib_softc
*);
138 static void tcotimer_start(struct lpcib_softc
*);
139 static void tcotimer_status_reset(struct lpcib_softc
*);
140 static int tcotimer_disable_noreboot(device_t
);
142 static void speedstep_configure(device_t
);
143 static void speedstep_unconfigure(device_t
);
144 static int speedstep_sysctl_helper(SYSCTLFN_ARGS
);
147 static void lpcib_hpet_configure(device_t
);
148 static int lpcib_hpet_unconfigure(device_t
, int);
152 static void lpcib_gpio_configure(device_t
);
153 static int lpcib_gpio_unconfigure(device_t
, int);
154 static int lpcib_gpio_pin_read(void *, int);
155 static void lpcib_gpio_pin_write(void *, int, int);
156 static void lpcib_gpio_pin_ctl(void *, int, int);
159 struct lpcib_softc
*speedstep_cookie
; /* XXX */
161 CFATTACH_DECL2_NEW(ichlpcib
, sizeof(struct lpcib_softc
),
162 lpcibmatch
, lpcibattach
, lpcibdetach
, NULL
, lpcibrescan
, lpcibchilddet
);
164 static struct lpcib_device
{
165 pcireg_t vendor
, product
;
168 } lpcib_devices
[] = {
169 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801AA_LPC
, 0, 0 },
170 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801BA_LPC
, 0, 0 },
171 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801BAM_LPC
, 0, 0 },
172 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801CA_LPC
, 0, 0 },
173 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801CAM_LPC
, 0, 0 },
174 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801DB_LPC
, 0, 0 },
175 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801DB_ISA
, 0, 0 },
176 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801EB_LPC
, 0, 1 },
177 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801FB_LPC
, 1, 0 },
178 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801FBM_LPC
, 1, 0 },
179 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801G_LPC
, 1, 0 },
180 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801GBM_LPC
, 1, 0 },
181 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801GHM_LPC
, 1, 0 },
182 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801H_LPC
, 1, 0 },
183 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801HEM_LPC
, 1, 0 },
184 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801HH_LPC
, 1, 0 },
185 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801HO_LPC
, 1, 0 },
186 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801HBM_LPC
, 1, 0 },
187 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801IH_LPC
, 1, 0 },
188 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801IO_LPC
, 1, 0 },
189 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801IR_LPC
, 1, 0 },
190 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801IEM_LPC
, 1, 0 },
191 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_82801IB_LPC
, 1, 0 },
192 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_63XXESB_LPC
, 1, 0 },
198 * Autoconf callbacks.
201 lpcibmatch(device_t parent
, cfdata_t match
, void *aux
)
203 struct pci_attach_args
*pa
= aux
;
204 struct lpcib_device
*lpcib_dev
;
206 /* We are ISA bridge, of course */
207 if (PCI_CLASS(pa
->pa_class
) != PCI_CLASS_BRIDGE
||
208 PCI_SUBCLASS(pa
->pa_class
) != PCI_SUBCLASS_BRIDGE_ISA
)
211 for (lpcib_dev
= lpcib_devices
; lpcib_dev
->vendor
; ++lpcib_dev
) {
212 if (PCI_VENDOR(pa
->pa_id
) == lpcib_dev
->vendor
&&
213 PCI_PRODUCT(pa
->pa_id
) == lpcib_dev
->product
)
221 lpcibattach(device_t parent
, device_t self
, void *aux
)
223 struct pci_attach_args
*pa
= aux
;
224 struct lpcib_softc
*sc
= device_private(self
);
225 struct lpcib_device
*lpcib_dev
;
229 for (lpcib_dev
= lpcib_devices
; lpcib_dev
->vendor
; ++lpcib_dev
) {
230 if (PCI_VENDOR(pa
->pa_id
) != lpcib_dev
->vendor
||
231 PCI_PRODUCT(pa
->pa_id
) != lpcib_dev
->product
)
233 sc
->sc_has_rcba
= lpcib_dev
->has_rcba
;
234 sc
->sc_has_ich5_hpet
= lpcib_dev
->has_ich5_hpet
;
238 pcibattach(parent
, self
, aux
);
241 * Part of our I/O registers are used as ACPI PM regs.
242 * Since our ACPI subsystem accesses the I/O space directly so far,
243 * we do not have to bother bus_space I/O map confliction.
245 if (pci_mapreg_map(pa
, LPCIB_PCI_PMBASE
, PCI_MAPREG_TYPE_IO
, 0,
246 &sc
->sc_iot
, &sc
->sc_ioh
, NULL
, &sc
->sc_iosize
)) {
247 aprint_error_dev(self
, "can't map power management i/o space");
251 sc
->sc_pmcon_orig
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
252 LPCIB_PCI_GEN_PMCON_1
);
254 /* For ICH6 and later, always enable RCBA */
255 if (sc
->sc_has_rcba
) {
258 sc
->sc_rcbat
= sc
->sc_pa
.pa_memt
;
260 rcba
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
262 if ((rcba
& LPCIB_RCBA_EN
) == 0) {
263 aprint_error_dev(self
, "RCBA is not enabled");
266 rcba
&= ~LPCIB_RCBA_EN
;
268 if (bus_space_map(sc
->sc_rcbat
, rcba
, LPCIB_RCBA_SIZE
, 0,
270 aprint_error_dev(self
, "RCBA could not be mapped");
275 /* Set up the power management timer. */
276 pmtimer_configure(self
);
278 /* Set up the TCO (watchdog). */
279 tcotimer_configure(self
);
281 /* Set up SpeedStep. */
282 speedstep_configure(self
);
286 lpcib_hpet_configure(self
);
291 lpcib_gpio_configure(self
);
294 /* Install power handler */
295 if (!pmf_device_register1(self
, lpcib_suspend
, lpcib_resume
,
297 aprint_error_dev(self
, "couldn't establish power handler\n");
301 lpcibchilddet(device_t self
, device_t child
)
303 struct lpcib_softc
*sc
= device_private(self
);
307 if (sc
->sc_gpiobus
== child
) {
308 sc
->sc_gpiobus
= NULL
;
312 if (sc
->sc_hpetbus
!= child
) {
313 pcibchilddet(self
, child
);
316 sc
->sc_hpetbus
= NULL
;
317 if (sc
->sc_has_ich5_hpet
) {
318 val
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
320 switch (val
& LPCIB_ICH5_HPTC_WIN_MASK
) {
321 case LPCIB_ICH5_HPTC_0000
:
322 case LPCIB_ICH5_HPTC_1000
:
323 case LPCIB_ICH5_HPTC_2000
:
324 case LPCIB_ICH5_HPTC_3000
:
329 val
&= ~LPCIB_ICH5_HPTC_EN
;
330 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
331 LPCIB_PCI_GEN_CNTL
, val
);
332 } else if (sc
->sc_has_rcba
) {
333 val
= bus_space_read_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
335 switch (val
& LPCIB_RCBA_HPTC_WIN_MASK
) {
336 case LPCIB_RCBA_HPTC_0000
:
337 case LPCIB_RCBA_HPTC_1000
:
338 case LPCIB_RCBA_HPTC_2000
:
339 case LPCIB_RCBA_HPTC_3000
:
344 val
&= ~LPCIB_RCBA_HPTC_EN
;
345 bus_space_write_4(sc
->sc_rcbat
, sc
->sc_rcbah
, LPCIB_RCBA_HPTC
,
351 lpcibrescan(device_t self
, const char *ifattr
, const int *locators
)
353 #if NHPET > 0 || NGPIO > 0
354 struct lpcib_softc
*sc
= device_private(self
);
358 if (ifattr_match(ifattr
, "hpetichbus") && sc
->sc_hpetbus
== NULL
)
359 lpcib_hpet_configure(self
);
363 if (ifattr_match(ifattr
, "gpiobus") && sc
->sc_gpiobus
== NULL
)
364 lpcib_gpio_configure(self
);
367 return pcibrescan(self
, ifattr
, locators
);
371 lpcibdetach(device_t self
, int flags
)
373 struct lpcib_softc
*sc
= device_private(self
);
376 pmf_device_deregister(self
);
379 if ((rc
= lpcib_hpet_unconfigure(self
, flags
)) != 0)
384 if ((rc
= lpcib_gpio_unconfigure(self
, flags
)) != 0)
388 /* Set up SpeedStep. */
389 speedstep_unconfigure(self
);
391 if ((rc
= tcotimer_unconfigure(self
, flags
)) != 0)
394 if ((rc
= pmtimer_unconfigure(self
, flags
)) != 0)
398 bus_space_unmap(sc
->sc_rcbat
, sc
->sc_rcbah
, LPCIB_RCBA_SIZE
);
400 bus_space_unmap(sc
->sc_iot
, sc
->sc_ioh
, sc
->sc_iosize
);
402 return pcibdetach(self
, flags
);
406 lpcib_shutdown(device_t dv
, int howto
)
408 struct lpcib_softc
*sc
= device_private(dv
);
410 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
411 LPCIB_PCI_GEN_PMCON_1
, sc
->sc_pmcon_orig
);
417 lpcib_suspend(device_t dv
, pmf_qual_t qual
)
419 struct lpcib_softc
*sc
= device_private(dv
);
420 pci_chipset_tag_t pc
= sc
->sc_pcib
.sc_pc
;
421 pcitag_t tag
= sc
->sc_pcib
.sc_tag
;
423 /* capture PIRQ routing control registers */
424 sc
->sc_pirq
[0] = pci_conf_read(pc
, tag
, LPCIB_PCI_PIRQA_ROUT
);
425 sc
->sc_pirq
[1] = pci_conf_read(pc
, tag
, LPCIB_PCI_PIRQE_ROUT
);
427 sc
->sc_pmcon
= pci_conf_read(pc
, tag
, LPCIB_PCI_GEN_PMCON_1
);
428 sc
->sc_fwhsel2
= pci_conf_read(pc
, tag
, LPCIB_PCI_GEN_STA
);
430 if (sc
->sc_has_rcba
) {
431 sc
->sc_rcba_reg
= pci_conf_read(pc
, tag
, LPCIB_RCBA
);
433 sc
->sc_hpet_reg
= bus_space_read_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
436 } else if (sc
->sc_has_ich5_hpet
) {
438 sc
->sc_hpet_reg
= pci_conf_read(pc
, tag
, LPCIB_PCI_GEN_CNTL
);
446 lpcib_resume(device_t dv
, pmf_qual_t qual
)
448 struct lpcib_softc
*sc
= device_private(dv
);
449 pci_chipset_tag_t pc
= sc
->sc_pcib
.sc_pc
;
450 pcitag_t tag
= sc
->sc_pcib
.sc_tag
;
452 /* restore PIRQ routing control registers */
453 pci_conf_write(pc
, tag
, LPCIB_PCI_PIRQA_ROUT
, sc
->sc_pirq
[0]);
454 pci_conf_write(pc
, tag
, LPCIB_PCI_PIRQE_ROUT
, sc
->sc_pirq
[1]);
456 pci_conf_write(pc
, tag
, LPCIB_PCI_GEN_PMCON_1
, sc
->sc_pmcon
);
457 pci_conf_write(pc
, tag
, LPCIB_PCI_GEN_STA
, sc
->sc_fwhsel2
);
459 if (sc
->sc_has_rcba
) {
460 pci_conf_write(pc
, tag
, LPCIB_RCBA
, sc
->sc_rcba_reg
);
462 bus_space_write_4(sc
->sc_rcbat
, sc
->sc_rcbah
, LPCIB_RCBA_HPTC
,
465 } else if (sc
->sc_has_ich5_hpet
) {
467 pci_conf_write(pc
, tag
, LPCIB_PCI_GEN_CNTL
, sc
->sc_hpet_reg
);
475 * Initialize the power management timer.
478 pmtimer_configure(device_t self
)
480 struct lpcib_softc
*sc
= device_private(self
);
484 * Check if power management I/O space is enabled and enable the ACPI_EN
485 * bit if it's disabled.
487 control
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
488 LPCIB_PCI_ACPI_CNTL
);
489 sc
->sc_acpi_cntl
= control
;
490 if ((control
& LPCIB_PCI_ACPI_CNTL_EN
) == 0) {
491 control
|= LPCIB_PCI_ACPI_CNTL_EN
;
492 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
493 LPCIB_PCI_ACPI_CNTL
, control
);
496 /* Attach our PM timer with the generic acpipmtimer function */
497 sc
->sc_pmtimer
= acpipmtimer_attach(self
, sc
->sc_iot
, sc
->sc_ioh
,
502 pmtimer_unconfigure(device_t self
, int flags
)
504 struct lpcib_softc
*sc
= device_private(self
);
507 if (sc
->sc_pmtimer
!= NULL
&&
508 (rc
= acpipmtimer_detach(sc
->sc_pmtimer
, flags
)) != 0)
511 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
512 LPCIB_PCI_ACPI_CNTL
, sc
->sc_acpi_cntl
);
518 * Initialize the watchdog timer.
521 tcotimer_configure(device_t self
)
523 struct lpcib_softc
*sc
= device_private(self
);
527 /* Explicitly stop the TCO timer. */
531 * Enable TCO timeout SMI only if the hardware reset does not
532 * work. We don't know what the SMBIOS does.
534 ioreg
= bus_space_read_4(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_SMI_EN
);
535 ioreg
&= ~LPCIB_SMI_EN_TCO_EN
;
538 * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
539 * in the SMI_EN register is the last chance.
541 if (tcotimer_disable_noreboot(self
)) {
542 ioreg
|= LPCIB_SMI_EN_TCO_EN
;
544 if ((ioreg
& LPCIB_SMI_EN_GBL_SMI_EN
) != 0) {
545 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_SMI_EN
, ioreg
);
548 /* Reset the watchdog status registers. */
549 tcotimer_status_reset(sc
);
552 * Register the driver with the sysmon watchdog framework.
554 sc
->sc_smw
.smw_name
= device_xname(self
);
555 sc
->sc_smw
.smw_cookie
= sc
;
556 sc
->sc_smw
.smw_setmode
= tcotimer_setmode
;
557 sc
->sc_smw
.smw_tickle
= tcotimer_tickle
;
559 period
= LPCIB_TCOTIMER2_MAX_TICK
;
561 period
= LPCIB_TCOTIMER_MAX_TICK
;
562 sc
->sc_smw
.smw_period
= lpcib_tcotimer_tick_to_second(period
);
564 if (sysmon_wdog_register(&sc
->sc_smw
)) {
565 aprint_error_dev(self
, "unable to register TCO timer"
566 "as a sysmon watchdog device.\n");
570 aprint_verbose_dev(self
, "TCO (watchdog) timer configured.\n");
574 tcotimer_unconfigure(device_t self
, int flags
)
576 struct lpcib_softc
*sc
= device_private(self
);
579 if ((rc
= sysmon_wdog_unregister(&sc
->sc_smw
)) != 0) {
585 /* Explicitly stop the TCO timer. */
588 /* XXX Set No Reboot? */
595 * Sysmon watchdog callbacks.
598 tcotimer_setmode(struct sysmon_wdog
*smw
)
600 struct lpcib_softc
*sc
= smw
->smw_cookie
;
602 uint16_t ich6period
= 0;
603 uint8_t ich5period
= 0;
605 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
606 /* Stop the TCO timer. */
610 * ICH6 or newer are limited to 2s min and 613s max.
611 * ICH5 or older are limited to 4s min and 39s max.
613 period
= lpcib_tcotimer_second_to_tick(smw
->smw_period
);
614 if (sc
->sc_has_rcba
) {
615 if (period
< LPCIB_TCOTIMER2_MIN_TICK
||
616 period
> LPCIB_TCOTIMER2_MAX_TICK
)
619 if (period
< LPCIB_TCOTIMER_MIN_TICK
||
620 period
> LPCIB_TCOTIMER_MAX_TICK
)
624 /* Stop the TCO timer, */
627 /* set the timeout, */
628 if (sc
->sc_has_rcba
) {
630 ich6period
= bus_space_read_2(sc
->sc_iot
, sc
->sc_ioh
,
632 ich6period
&= 0xfc00;
633 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
,
634 LPCIB_TCO_TMR2
, ich6period
| period
);
637 ich5period
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
,
640 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
,
641 LPCIB_TCO_TMR
, ich5period
| period
);
644 /* and start/reload the timer. */
646 tcotimer_tickle(smw
);
653 tcotimer_tickle(struct sysmon_wdog
*smw
)
655 struct lpcib_softc
*sc
= smw
->smw_cookie
;
657 /* any value is allowed */
659 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO_RLD
, 1);
661 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO_RLD
, 1);
667 tcotimer_stop(struct lpcib_softc
*sc
)
671 ioreg
= bus_space_read_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO1_CNT
);
672 ioreg
|= LPCIB_TCO1_CNT_TCO_TMR_HLT
;
673 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO1_CNT
, ioreg
);
677 tcotimer_start(struct lpcib_softc
*sc
)
681 ioreg
= bus_space_read_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO1_CNT
);
682 ioreg
&= ~LPCIB_TCO1_CNT_TCO_TMR_HLT
;
683 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO1_CNT
, ioreg
);
687 tcotimer_status_reset(struct lpcib_softc
*sc
)
689 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO1_STS
,
690 LPCIB_TCO1_STS_TIMEOUT
);
691 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO2_STS
,
692 LPCIB_TCO2_STS_BOOT_STS
);
693 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, LPCIB_TCO2_STS
,
694 LPCIB_TCO2_STS_SECONDS_TO_STS
);
698 * Clear the No Reboot (NR) bit, this enables reboots when the timer
699 * reaches the timeout for the second time.
702 tcotimer_disable_noreboot(device_t self
)
704 struct lpcib_softc
*sc
= device_private(self
);
706 if (sc
->sc_has_rcba
) {
709 status
= bus_space_read_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
711 status
&= ~LPCIB_GCS_NO_REBOOT
;
712 bus_space_write_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
713 LPCIB_GCS_OFFSET
, status
);
714 status
= bus_space_read_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
716 if (status
& LPCIB_GCS_NO_REBOOT
)
721 pcireg
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
723 if (pcireg
& LPCIB_PCI_GEN_STA_NO_REBOOT
) {
724 /* TCO timeout reset is disabled; try to enable it */
725 pcireg
&= ~LPCIB_PCI_GEN_STA_NO_REBOOT
;
726 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
727 LPCIB_PCI_GEN_STA
, pcireg
);
728 if (pcireg
& LPCIB_PCI_GEN_STA_NO_REBOOT
)
735 aprint_error_dev(self
, "TCO timer reboot disabled by hardware; "
736 "hope SMBIOS properly handles it.\n");
742 * Intel ICH SpeedStep support.
744 #define SS_READ(sc, reg) \
745 bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
746 #define SS_WRITE(sc, reg, val) \
747 bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
750 * Linux driver says that SpeedStep on older chipsets cause
751 * lockups on Dell Inspiron 8000 and 8100.
752 * It should also not be enabled on systems with the 82855GM
753 * Hub, which typically have an EST-enabled CPU.
756 speedstep_bad_hb_check(struct pci_attach_args
*pa
)
759 if (PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_INTEL_82815_FULL_HUB
&&
760 PCI_REVISION(pa
->pa_class
) < 5)
763 if (PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_INTEL_82855GM_MCH
)
770 speedstep_configure(device_t self
)
772 struct lpcib_softc
*sc
= device_private(self
);
773 const struct sysctlnode
*node
, *ssnode
;
776 /* Supported on ICH2-M, ICH3-M and ICH4-M. */
777 if (PCI_PRODUCT(sc
->sc_pa
.pa_id
) == PCI_PRODUCT_INTEL_82801DB_ISA
||
778 PCI_PRODUCT(sc
->sc_pa
.pa_id
) == PCI_PRODUCT_INTEL_82801CAM_LPC
||
779 (PCI_PRODUCT(sc
->sc_pa
.pa_id
) == PCI_PRODUCT_INTEL_82801BAM_LPC
&&
780 pci_find_device(&sc
->sc_pa
, speedstep_bad_hb_check
) == 0)) {
783 /* Enable SpeedStep if it isn't already enabled. */
784 pmcon
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
785 LPCIB_PCI_GEN_PMCON_1
);
786 if ((pmcon
& LPCIB_PCI_GEN_PMCON_1_SS_EN
) == 0)
787 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
788 LPCIB_PCI_GEN_PMCON_1
,
789 pmcon
| LPCIB_PCI_GEN_PMCON_1_SS_EN
);
791 /* Put in machdep.speedstep_state (0 for low, 1 for high). */
792 if ((rv
= sysctl_createv(&sc
->sc_log
, 0, NULL
, &node
,
793 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "machdep", NULL
,
794 NULL
, 0, NULL
, 0, CTL_MACHDEP
, CTL_EOL
)) != 0)
797 /* CTLFLAG_ANYWRITE? kernel option like EST? */
798 if ((rv
= sysctl_createv(&sc
->sc_log
, 0, &node
, &ssnode
,
799 CTLFLAG_READWRITE
, CTLTYPE_INT
, "speedstep_state", NULL
,
800 speedstep_sysctl_helper
, 0, NULL
, 0, CTL_CREATE
,
804 /* XXX save the sc for IO tag/handle */
805 speedstep_cookie
= sc
;
806 aprint_verbose_dev(self
, "SpeedStep enabled\n");
812 aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__
, rv
);
816 speedstep_unconfigure(device_t self
)
818 struct lpcib_softc
*sc
= device_private(self
);
820 sysctl_teardown(&sc
->sc_log
);
821 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
822 LPCIB_PCI_GEN_PMCON_1
, sc
->sc_pmcon_orig
);
824 speedstep_cookie
= NULL
;
828 * get/set the SpeedStep state: 0 == low power, 1 == high power.
831 speedstep_sysctl_helper(SYSCTLFN_ARGS
)
833 struct sysctlnode node
;
834 struct lpcib_softc
*sc
= speedstep_cookie
;
835 uint8_t state
, state2
;
836 int ostate
, nstate
, s
, error
= 0;
839 * We do the dance with spl's to avoid being at high ipl during
840 * sysctl_lookup() which can both copyin and copyout.
843 state
= SS_READ(sc
, LPCIB_PM_SS_CNTL
);
845 if ((state
& LPCIB_PM_SS_STATE_LOW
) == 0)
852 node
.sysctl_data
= &nstate
;
854 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
855 if (error
|| newp
== NULL
)
858 /* Only two states are available */
859 if (nstate
!= 0 && nstate
!= 1) {
865 state2
= SS_READ(sc
, LPCIB_PM_SS_CNTL
);
866 if ((state2
& LPCIB_PM_SS_STATE_LOW
) == 0)
871 if (ostate
!= nstate
) {
875 state2
|= LPCIB_PM_SS_STATE_LOW
;
877 state2
&= ~LPCIB_PM_SS_STATE_LOW
;
880 * Must disable bus master arbitration during the change.
882 cntl
= SS_READ(sc
, LPCIB_PM_CTRL
);
883 SS_WRITE(sc
, LPCIB_PM_CTRL
, cntl
| LPCIB_PM_SS_CNTL_ARB_DIS
);
884 SS_WRITE(sc
, LPCIB_PM_SS_CNTL
, state2
);
885 SS_WRITE(sc
, LPCIB_PM_CTRL
, cntl
);
893 struct lpcib_hpet_attach_arg
{
894 bus_space_tag_t hpet_mem_t
;
899 lpcib_hpet_match(device_t parent
, cfdata_t match
, void *aux
)
901 struct lpcib_hpet_attach_arg
*arg
= aux
;
903 bus_space_handle_t handle
;
905 tag
= arg
->hpet_mem_t
;
907 if (bus_space_map(tag
, arg
->hpet_reg
, HPET_WINDOW_SIZE
, 0, &handle
)) {
908 aprint_verbose_dev(parent
, "HPET window not mapped, skipping\n");
911 bus_space_unmap(tag
, handle
, HPET_WINDOW_SIZE
);
917 lpcib_hpet_detach(device_t self
, int flags
)
919 struct hpet_softc
*sc
= device_private(self
);
922 if ((rc
= hpet_detach(self
, flags
)) != 0)
925 bus_space_unmap(sc
->sc_memt
, sc
->sc_memh
, HPET_WINDOW_SIZE
);
931 lpcib_hpet_attach(device_t parent
, device_t self
, void *aux
)
933 struct hpet_softc
*sc
= device_private(self
);
934 struct lpcib_hpet_attach_arg
*arg
= aux
;
939 sc
->sc_memt
= arg
->hpet_mem_t
;
941 if (bus_space_map(sc
->sc_memt
, arg
->hpet_reg
, HPET_WINDOW_SIZE
, 0,
943 aprint_error_dev(self
,
944 "HPET memory window could not be mapped");
948 hpet_attach_subr(self
);
951 CFATTACH_DECL_NEW(ichlpcib_hpet
, sizeof(struct hpet_softc
), lpcib_hpet_match
,
952 lpcib_hpet_attach
, lpcib_hpet_detach
, NULL
);
955 lpcib_hpet_configure(device_t self
)
957 struct lpcib_softc
*sc
= device_private(self
);
958 struct lpcib_hpet_attach_arg arg
;
959 uint32_t hpet_reg
, val
;
961 if (sc
->sc_has_ich5_hpet
) {
962 val
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
964 switch (val
& LPCIB_ICH5_HPTC_WIN_MASK
) {
965 case LPCIB_ICH5_HPTC_0000
:
966 hpet_reg
= LPCIB_ICH5_HPTC_0000_BASE
;
968 case LPCIB_ICH5_HPTC_1000
:
969 hpet_reg
= LPCIB_ICH5_HPTC_1000_BASE
;
971 case LPCIB_ICH5_HPTC_2000
:
972 hpet_reg
= LPCIB_ICH5_HPTC_2000_BASE
;
974 case LPCIB_ICH5_HPTC_3000
:
975 hpet_reg
= LPCIB_ICH5_HPTC_3000_BASE
;
980 val
|= sc
->sc_hpet_reg
| LPCIB_ICH5_HPTC_EN
;
981 pci_conf_write(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
982 LPCIB_PCI_GEN_CNTL
, val
);
983 } else if (sc
->sc_has_rcba
) {
984 val
= bus_space_read_4(sc
->sc_rcbat
, sc
->sc_rcbah
,
986 switch (val
& LPCIB_RCBA_HPTC_WIN_MASK
) {
987 case LPCIB_RCBA_HPTC_0000
:
988 hpet_reg
= LPCIB_RCBA_HPTC_0000_BASE
;
990 case LPCIB_RCBA_HPTC_1000
:
991 hpet_reg
= LPCIB_RCBA_HPTC_1000_BASE
;
993 case LPCIB_RCBA_HPTC_2000
:
994 hpet_reg
= LPCIB_RCBA_HPTC_2000_BASE
;
996 case LPCIB_RCBA_HPTC_3000
:
997 hpet_reg
= LPCIB_RCBA_HPTC_3000_BASE
;
1002 val
|= LPCIB_RCBA_HPTC_EN
;
1003 bus_space_write_4(sc
->sc_rcbat
, sc
->sc_rcbah
, LPCIB_RCBA_HPTC
,
1010 arg
.hpet_mem_t
= sc
->sc_pa
.pa_memt
;
1011 arg
.hpet_reg
= hpet_reg
;
1013 sc
->sc_hpetbus
= config_found_ia(self
, "hpetichbus", &arg
, NULL
);
1017 lpcib_hpet_unconfigure(device_t self
, int flags
)
1019 struct lpcib_softc
*sc
= device_private(self
);
1022 if (sc
->sc_hpetbus
!= NULL
&&
1023 (rc
= config_detach(sc
->sc_hpetbus
, flags
)) != 0)
1032 lpcib_gpio_configure(device_t self
)
1034 struct lpcib_softc
*sc
= device_private(self
);
1035 struct gpiobus_attach_args gba
;
1037 uint32_t use
, io
, bit
;
1038 int pin
, shift
, base_reg
, cntl_reg
, reg
;
1040 /* this implies ICH >= 6, and thus different mapreg */
1041 if (sc
->sc_has_rcba
) {
1042 base_reg
= LPCIB_PCI_GPIO_BASE_ICH6
;
1043 cntl_reg
= LPCIB_PCI_GPIO_CNTL_ICH6
;
1045 base_reg
= LPCIB_PCI_GPIO_BASE
;
1046 cntl_reg
= LPCIB_PCI_GPIO_CNTL
;
1049 gpio_cntl
= pci_conf_read(sc
->sc_pcib
.sc_pc
, sc
->sc_pcib
.sc_tag
,
1052 /* Is GPIO enabled? */
1053 if ((gpio_cntl
& LPCIB_PCI_GPIO_CNTL_EN
) == 0)
1056 if (pci_mapreg_map(&sc
->sc_pa
, base_reg
, PCI_MAPREG_TYPE_IO
, 0,
1057 &sc
->sc_gpio_iot
, &sc
->sc_gpio_ioh
,
1058 NULL
, &sc
->sc_gpio_ios
)) {
1059 aprint_error_dev(self
, "can't map general purpose i/o space\n");
1063 mutex_init(&sc
->sc_gpio_mtx
, MUTEX_DEFAULT
, IPL_NONE
);
1065 for (pin
= 0; pin
< LPCIB_GPIO_NPINS
; pin
++) {
1066 sc
->sc_gpio_pins
[pin
].pin_num
= pin
;
1068 /* Read initial state */
1069 reg
= (pin
< 32) ? LPCIB_GPIO_GPIO_USE_SEL
: LPCIB_GPIO_GPIO_USE_SEL2
;
1070 use
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
);
1071 reg
= (pin
< 32) ? LPCIB_GPIO_GP_IO_SEL
: LPCIB_GPIO_GP_IO_SEL
;
1072 io
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, 4);
1076 if ((use
& bit
) != 0) {
1077 sc
->sc_gpio_pins
[pin
].pin_caps
=
1078 GPIO_PIN_INPUT
| GPIO_PIN_OUTPUT
;
1080 sc
->sc_gpio_pins
[pin
].pin_caps
|=
1082 if ((io
& bit
) != 0)
1083 sc
->sc_gpio_pins
[pin
].pin_flags
=
1086 sc
->sc_gpio_pins
[pin
].pin_flags
=
1089 sc
->sc_gpio_pins
[pin
].pin_caps
= 0;
1091 if (lpcib_gpio_pin_read(sc
, pin
) == 0)
1092 sc
->sc_gpio_pins
[pin
].pin_state
= GPIO_PIN_LOW
;
1094 sc
->sc_gpio_pins
[pin
].pin_state
= GPIO_PIN_HIGH
;
1098 /* Create controller tag */
1099 sc
->sc_gpio_gc
.gp_cookie
= sc
;
1100 sc
->sc_gpio_gc
.gp_pin_read
= lpcib_gpio_pin_read
;
1101 sc
->sc_gpio_gc
.gp_pin_write
= lpcib_gpio_pin_write
;
1102 sc
->sc_gpio_gc
.gp_pin_ctl
= lpcib_gpio_pin_ctl
;
1104 memset(&gba
, 0, sizeof(gba
));
1106 gba
.gba_gc
= &sc
->sc_gpio_gc
;
1107 gba
.gba_pins
= sc
->sc_gpio_pins
;
1108 gba
.gba_npins
= LPCIB_GPIO_NPINS
;
1110 sc
->sc_gpiobus
= config_found_ia(self
, "gpiobus", &gba
, gpiobus_print
);
1114 lpcib_gpio_unconfigure(device_t self
, int flags
)
1116 struct lpcib_softc
*sc
= device_private(self
);
1119 if (sc
->sc_gpiobus
!= NULL
&&
1120 (rc
= config_detach(sc
->sc_gpiobus
, flags
)) != 0)
1123 mutex_destroy(&sc
->sc_gpio_mtx
);
1125 bus_space_unmap(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, sc
->sc_gpio_ios
);
1131 lpcib_gpio_pin_read(void *arg
, int pin
)
1133 struct lpcib_softc
*sc
= arg
;
1137 reg
= (pin
< 32) ? LPCIB_GPIO_GP_LVL
: LPCIB_GPIO_GP_LVL2
;
1140 mutex_enter(&sc
->sc_gpio_mtx
);
1141 data
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
);
1142 mutex_exit(&sc
->sc_gpio_mtx
);
1144 return (__SHIFTOUT(data
, __BIT(shift
)) ? GPIO_PIN_HIGH
: GPIO_PIN_LOW
);
1148 lpcib_gpio_pin_write(void *arg
, int pin
, int value
)
1150 struct lpcib_softc
*sc
= arg
;
1154 reg
= (pin
< 32) ? LPCIB_GPIO_GP_LVL
: LPCIB_GPIO_GP_LVL2
;
1157 mutex_enter(&sc
->sc_gpio_mtx
);
1159 data
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
);
1162 data
|= __BIT(shift
);
1164 data
&= ~__BIT(shift
);
1166 bus_space_write_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
, data
);
1168 mutex_exit(&sc
->sc_gpio_mtx
);
1172 lpcib_gpio_pin_ctl(void *arg
, int pin
, int flags
)
1174 struct lpcib_softc
*sc
= arg
;
1179 reg
= (pin
< 32) ? LPCIB_GPIO_GP_IO_SEL
: LPCIB_GPIO_GP_IO_SEL2
;
1181 mutex_enter(&sc
->sc_gpio_mtx
);
1183 data
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
);
1185 if (flags
& GPIO_PIN_OUTPUT
)
1186 data
&= ~__BIT(shift
);
1188 if (flags
& GPIO_PIN_INPUT
)
1189 data
|= __BIT(shift
);
1191 bus_space_write_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
, data
);
1195 reg
= LPCIB_GPIO_GPO_BLINK
;
1196 data
= bus_space_read_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
);
1198 if (flags
& GPIO_PIN_PULSATE
)
1199 data
|= __BIT(shift
);
1201 data
&= ~__BIT(shift
);
1203 bus_space_write_4(sc
->sc_gpio_iot
, sc
->sc_gpio_ioh
, reg
, data
);
1206 mutex_exit(&sc
->sc_gpio_mtx
);