ichlpcib.c revision 1.14.4.4 1 1.14.4.4 martin /* $NetBSD: ichlpcib.c,v 1.14.4.4 2015/01/26 13:34:03 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.14.4.4 martin __KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.14.4.4 2015/01/26 13:34:03 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.12 martin #include "pcibvar.h"
65 1.1 xtraeme
66 1.1 xtraeme struct lpcib_softc {
67 1.12 martin /* we call pcibattach() which assumes this starts like this: */
68 1.12 martin struct pcib_softc sc_pcib;
69 1.1 xtraeme
70 1.6 jmcneill struct pci_attach_args sc_pa;
71 1.6 jmcneill int sc_has_rcba;
72 1.6 jmcneill int sc_has_ich5_hpet;
73 1.6 jmcneill
74 1.6 jmcneill /* RCBA */
75 1.6 jmcneill bus_space_tag_t sc_rcbat;
76 1.6 jmcneill bus_space_handle_t sc_rcbah;
77 1.6 jmcneill pcireg_t sc_rcba_reg;
78 1.6 jmcneill
79 1.1 xtraeme /* Watchdog variables. */
80 1.1 xtraeme struct sysmon_wdog sc_smw;
81 1.1 xtraeme bus_space_tag_t sc_iot;
82 1.1 xtraeme bus_space_handle_t sc_ioh;
83 1.6 jmcneill
84 1.6 jmcneill #if NHPET > 0
85 1.6 jmcneill /* HPET variables. */
86 1.6 jmcneill uint32_t sc_hpet_reg;
87 1.6 jmcneill #endif
88 1.6 jmcneill
89 1.14.4.1 snj /* Speedstep */
90 1.14.4.1 snj pcireg_t sc_pmcon_orig;
91 1.14.4.1 snj
92 1.1 xtraeme /* Power management */
93 1.7 drochner pcireg_t sc_pirq[2];
94 1.6 jmcneill pcireg_t sc_pmcon;
95 1.6 jmcneill pcireg_t sc_fwhsel2;
96 1.1 xtraeme };
97 1.1 xtraeme
98 1.9 xtraeme static int lpcibmatch(device_t, cfdata_t, void *);
99 1.9 xtraeme static void lpcibattach(device_t, device_t, void *);
100 1.8 dyoung static bool lpcib_suspend(device_t PMF_FN_PROTO);
101 1.8 dyoung static bool lpcib_resume(device_t PMF_FN_PROTO);
102 1.14.4.1 snj static bool lpcib_shutdown(device_t, int);
103 1.1 xtraeme
104 1.9 xtraeme static void pmtimer_configure(device_t);
105 1.1 xtraeme
106 1.9 xtraeme static void tcotimer_configure(device_t);
107 1.1 xtraeme static int tcotimer_setmode(struct sysmon_wdog *);
108 1.1 xtraeme static int tcotimer_tickle(struct sysmon_wdog *);
109 1.1 xtraeme static void tcotimer_stop(struct lpcib_softc *);
110 1.1 xtraeme static void tcotimer_start(struct lpcib_softc *);
111 1.1 xtraeme static void tcotimer_status_reset(struct lpcib_softc *);
112 1.9 xtraeme static int tcotimer_disable_noreboot(device_t);
113 1.1 xtraeme
114 1.9 xtraeme static void speedstep_configure(device_t);
115 1.1 xtraeme static int speedstep_sysctl_helper(SYSCTLFN_ARGS);
116 1.1 xtraeme
117 1.6 jmcneill #if NHPET > 0
118 1.9 xtraeme static void lpcib_hpet_configure(device_t);
119 1.6 jmcneill #endif
120 1.6 jmcneill
121 1.1 xtraeme struct lpcib_softc *speedstep_cookie; /* XXX */
122 1.1 xtraeme
123 1.9 xtraeme CFATTACH_DECL_NEW(ichlpcib, sizeof(struct lpcib_softc),
124 1.1 xtraeme lpcibmatch, lpcibattach, NULL, NULL);
125 1.1 xtraeme
126 1.6 jmcneill static struct lpcib_device {
127 1.6 jmcneill pcireg_t vendor, product;
128 1.6 jmcneill int has_rcba;
129 1.6 jmcneill int has_ich5_hpet;
130 1.6 jmcneill } lpcib_devices[] = {
131 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_LPC, 0, 0 },
132 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_LPC, 0, 0 },
133 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BAM_LPC, 0, 0 },
134 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_LPC, 0, 0 },
135 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CAM_LPC, 0, 0 },
136 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LPC, 0, 0 },
137 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_ISA, 0, 0 },
138 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801EB_LPC, 0, 1 },
139 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LPC, 1, 0 },
140 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LPC, 1, 0 },
141 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801G_LPC, 1, 0 },
142 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GBM_LPC, 1, 0 },
143 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GHM_LPC, 1, 0 },
144 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801H_LPC, 1, 0 },
145 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HEM_LPC, 1, 0 },
146 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HH_LPC, 1, 0 },
147 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HO_LPC, 1, 0 },
148 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HBM_LPC, 1, 0 },
149 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IH_LPC, 1, 0 },
150 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IO_LPC, 1, 0 },
151 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IR_LPC, 1, 0 },
152 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IB_LPC, 1, 0 },
153 1.14 joerg { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_63XXESB_LPC, 1, 0 },
154 1.14 joerg
155 1.6 jmcneill { 0, 0, 0, 0 },
156 1.6 jmcneill };
157 1.6 jmcneill
158 1.1 xtraeme /*
159 1.1 xtraeme * Autoconf callbacks.
160 1.1 xtraeme */
161 1.1 xtraeme static int
162 1.9 xtraeme lpcibmatch(device_t parent, cfdata_t match, void *aux)
163 1.1 xtraeme {
164 1.1 xtraeme struct pci_attach_args *pa = aux;
165 1.6 jmcneill struct lpcib_device *lpcib_dev;
166 1.1 xtraeme
167 1.1 xtraeme /* We are ISA bridge, of course */
168 1.1 xtraeme if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
169 1.1 xtraeme PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
170 1.1 xtraeme return 0;
171 1.1 xtraeme
172 1.6 jmcneill for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
173 1.6 jmcneill if (PCI_VENDOR(pa->pa_id) == lpcib_dev->vendor &&
174 1.6 jmcneill PCI_PRODUCT(pa->pa_id) == lpcib_dev->product)
175 1.1 xtraeme return 10;
176 1.1 xtraeme }
177 1.1 xtraeme
178 1.1 xtraeme return 0;
179 1.1 xtraeme }
180 1.1 xtraeme
181 1.1 xtraeme static void
182 1.9 xtraeme lpcibattach(device_t parent, device_t self, void *aux)
183 1.1 xtraeme {
184 1.1 xtraeme struct pci_attach_args *pa = aux;
185 1.6 jmcneill struct lpcib_softc *sc = device_private(self);
186 1.6 jmcneill struct lpcib_device *lpcib_dev;
187 1.14.4.4 martin pcireg_t pmbase;
188 1.1 xtraeme
189 1.6 jmcneill sc->sc_pa = *pa;
190 1.6 jmcneill
191 1.6 jmcneill for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
192 1.6 jmcneill if (PCI_VENDOR(pa->pa_id) != lpcib_dev->vendor ||
193 1.6 jmcneill PCI_PRODUCT(pa->pa_id) != lpcib_dev->product)
194 1.6 jmcneill continue;
195 1.6 jmcneill sc->sc_has_rcba = lpcib_dev->has_rcba;
196 1.6 jmcneill sc->sc_has_ich5_hpet = lpcib_dev->has_ich5_hpet;
197 1.6 jmcneill break;
198 1.6 jmcneill }
199 1.1 xtraeme
200 1.1 xtraeme pcibattach(parent, self, aux);
201 1.1 xtraeme
202 1.1 xtraeme /*
203 1.1 xtraeme * Part of our I/O registers are used as ACPI PM regs.
204 1.1 xtraeme * Since our ACPI subsystem accesses the I/O space directly so far,
205 1.1 xtraeme * we do not have to bother bus_space I/O map confliction.
206 1.14.4.3 martin *
207 1.14.4.3 martin * The PMBASE register is alike PCI BAR but not completely compatible
208 1.14.4.3 martin * with it. The PMBASE define the base address and the type but
209 1.14.4.4 martin * not describe the size. The value of the register may be lower
210 1.14.4.4 martin * than LPCIB_PCI_PM_SIZE. It makes impossible to use
211 1.14.4.4 martin * pci_mapreg_submap() because the function does range check.
212 1.1 xtraeme */
213 1.14.4.4 martin sc->sc_iot = pa->pa_iot;
214 1.14.4.4 martin pmbase = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_PCI_PMBASE);
215 1.14.4.4 martin if (bus_space_map(sc->sc_iot, PCI_MAPREG_IO_ADDR(pmbase),
216 1.14.4.4 martin LPCIB_PCI_PM_SIZE, 0, &sc->sc_ioh) != 0) {
217 1.14.4.4 martin aprint_error_dev(self,
218 1.14.4.4 martin "can't map power management i/o space\n");
219 1.1 xtraeme return;
220 1.1 xtraeme }
221 1.1 xtraeme
222 1.14.4.1 snj sc->sc_pmcon_orig = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
223 1.14.4.1 snj LPCIB_PCI_GEN_PMCON_1);
224 1.14.4.1 snj
225 1.6 jmcneill /* For ICH6 and later, always enable RCBA */
226 1.6 jmcneill if (sc->sc_has_rcba) {
227 1.6 jmcneill pcireg_t rcba;
228 1.6 jmcneill
229 1.6 jmcneill sc->sc_rcbat = sc->sc_pa.pa_memt;
230 1.6 jmcneill
231 1.12 martin rcba = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
232 1.12 martin LPCIB_RCBA);
233 1.6 jmcneill if ((rcba & LPCIB_RCBA_EN) == 0) {
234 1.14.4.3 martin aprint_error_dev(self, "RCBA is not enabled\n");
235 1.6 jmcneill return;
236 1.6 jmcneill }
237 1.6 jmcneill rcba &= ~LPCIB_RCBA_EN;
238 1.6 jmcneill
239 1.6 jmcneill if (bus_space_map(sc->sc_rcbat, rcba, LPCIB_RCBA_SIZE, 0,
240 1.6 jmcneill &sc->sc_rcbah)) {
241 1.14.4.3 martin aprint_error_dev(self, "RCBA could not be mapped\n");
242 1.6 jmcneill return;
243 1.6 jmcneill }
244 1.6 jmcneill }
245 1.6 jmcneill
246 1.1 xtraeme /* Set up the power management timer. */
247 1.9 xtraeme pmtimer_configure(self);
248 1.1 xtraeme
249 1.1 xtraeme /* Set up the TCO (watchdog). */
250 1.9 xtraeme tcotimer_configure(self);
251 1.1 xtraeme
252 1.1 xtraeme /* Set up SpeedStep. */
253 1.9 xtraeme speedstep_configure(self);
254 1.1 xtraeme
255 1.6 jmcneill #if NHPET > 0
256 1.6 jmcneill /* Set up HPET. */
257 1.9 xtraeme lpcib_hpet_configure(self);
258 1.6 jmcneill #endif
259 1.6 jmcneill
260 1.6 jmcneill /* Install power handler */
261 1.14.4.1 snj if (!pmf_device_register1(self, lpcib_suspend, lpcib_resume,
262 1.14.4.1 snj lpcib_shutdown))
263 1.6 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
264 1.6 jmcneill }
265 1.6 jmcneill
266 1.6 jmcneill static bool
267 1.14.4.1 snj lpcib_shutdown(device_t dv, int howto)
268 1.14.4.1 snj {
269 1.14.4.1 snj struct lpcib_softc *sc = device_private(dv);
270 1.14.4.1 snj
271 1.14.4.1 snj pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
272 1.14.4.1 snj LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon_orig);
273 1.14.4.1 snj
274 1.14.4.1 snj return true;
275 1.14.4.1 snj }
276 1.14.4.1 snj
277 1.14.4.1 snj static bool
278 1.8 dyoung lpcib_suspend(device_t dv PMF_FN_ARGS)
279 1.6 jmcneill {
280 1.6 jmcneill struct lpcib_softc *sc = device_private(dv);
281 1.12 martin pci_chipset_tag_t pc = sc->sc_pcib.sc_pc;
282 1.12 martin pcitag_t tag = sc->sc_pcib.sc_tag;
283 1.6 jmcneill
284 1.6 jmcneill /* capture PIRQ routing control registers */
285 1.6 jmcneill sc->sc_pirq[0] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQA_ROUT);
286 1.7 drochner sc->sc_pirq[1] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQE_ROUT);
287 1.6 jmcneill
288 1.6 jmcneill sc->sc_pmcon = pci_conf_read(pc, tag, LPCIB_PCI_GEN_PMCON_1);
289 1.6 jmcneill sc->sc_fwhsel2 = pci_conf_read(pc, tag, LPCIB_PCI_GEN_STA);
290 1.6 jmcneill
291 1.6 jmcneill if (sc->sc_has_rcba) {
292 1.6 jmcneill sc->sc_rcba_reg = pci_conf_read(pc, tag, LPCIB_RCBA);
293 1.6 jmcneill #if NHPET > 0
294 1.6 jmcneill sc->sc_hpet_reg = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
295 1.6 jmcneill LPCIB_RCBA_HPTC);
296 1.6 jmcneill #endif
297 1.6 jmcneill } else if (sc->sc_has_ich5_hpet) {
298 1.6 jmcneill #if NHPET > 0
299 1.6 jmcneill sc->sc_hpet_reg = pci_conf_read(pc, tag, LPCIB_PCI_GEN_CNTL);
300 1.6 jmcneill #endif
301 1.6 jmcneill }
302 1.6 jmcneill
303 1.6 jmcneill return true;
304 1.6 jmcneill }
305 1.6 jmcneill
306 1.6 jmcneill static bool
307 1.8 dyoung lpcib_resume(device_t dv PMF_FN_ARGS)
308 1.6 jmcneill {
309 1.6 jmcneill struct lpcib_softc *sc = device_private(dv);
310 1.12 martin pci_chipset_tag_t pc = sc->sc_pcib.sc_pc;
311 1.12 martin pcitag_t tag = sc->sc_pcib.sc_tag;
312 1.6 jmcneill
313 1.6 jmcneill /* restore PIRQ routing control registers */
314 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_PIRQA_ROUT, sc->sc_pirq[0]);
315 1.7 drochner pci_conf_write(pc, tag, LPCIB_PCI_PIRQE_ROUT, sc->sc_pirq[1]);
316 1.6 jmcneill
317 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon);
318 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_STA, sc->sc_fwhsel2);
319 1.6 jmcneill
320 1.6 jmcneill if (sc->sc_has_rcba) {
321 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_RCBA, sc->sc_rcba_reg);
322 1.6 jmcneill #if NHPET > 0
323 1.6 jmcneill bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
324 1.6 jmcneill sc->sc_hpet_reg);
325 1.6 jmcneill #endif
326 1.6 jmcneill } else if (sc->sc_has_ich5_hpet) {
327 1.6 jmcneill #if NHPET > 0
328 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_CNTL, sc->sc_hpet_reg);
329 1.6 jmcneill #endif
330 1.6 jmcneill }
331 1.1 xtraeme
332 1.6 jmcneill return true;
333 1.1 xtraeme }
334 1.1 xtraeme
335 1.1 xtraeme /*
336 1.1 xtraeme * Initialize the power management timer.
337 1.1 xtraeme */
338 1.1 xtraeme static void
339 1.9 xtraeme pmtimer_configure(device_t self)
340 1.1 xtraeme {
341 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
342 1.1 xtraeme pcireg_t control;
343 1.1 xtraeme
344 1.1 xtraeme /*
345 1.1 xtraeme * Check if power management I/O space is enabled and enable the ACPI_EN
346 1.1 xtraeme * bit if it's disabled.
347 1.1 xtraeme */
348 1.12 martin control = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
349 1.12 martin LPCIB_PCI_ACPI_CNTL);
350 1.1 xtraeme if ((control & LPCIB_PCI_ACPI_CNTL_EN) == 0) {
351 1.1 xtraeme control |= LPCIB_PCI_ACPI_CNTL_EN;
352 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
353 1.12 martin LPCIB_PCI_ACPI_CNTL, control);
354 1.1 xtraeme }
355 1.1 xtraeme
356 1.1 xtraeme /* Attach our PM timer with the generic acpipmtimer function */
357 1.9 xtraeme acpipmtimer_attach(self, sc->sc_iot, sc->sc_ioh,
358 1.1 xtraeme LPCIB_PM1_TMR, 0);
359 1.1 xtraeme }
360 1.1 xtraeme
361 1.1 xtraeme /*
362 1.1 xtraeme * Initialize the watchdog timer.
363 1.1 xtraeme */
364 1.1 xtraeme static void
365 1.9 xtraeme tcotimer_configure(device_t self)
366 1.1 xtraeme {
367 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
368 1.1 xtraeme uint32_t ioreg;
369 1.1 xtraeme unsigned int period;
370 1.1 xtraeme
371 1.13 yamt /* Explicitly stop the TCO timer. */
372 1.13 yamt tcotimer_stop(sc);
373 1.13 yamt
374 1.13 yamt /*
375 1.13 yamt * Enable TCO timeout SMI only if the hardware reset does not
376 1.13 yamt * work. We don't know what the SMBIOS does.
377 1.13 yamt */
378 1.13 yamt ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
379 1.13 yamt ioreg &= ~LPCIB_SMI_EN_TCO_EN;
380 1.13 yamt
381 1.1 xtraeme /*
382 1.4 xtraeme * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
383 1.1 xtraeme * in the SMI_EN register is the last chance.
384 1.1 xtraeme */
385 1.9 xtraeme if (tcotimer_disable_noreboot(self)) {
386 1.1 xtraeme ioreg |= LPCIB_SMI_EN_TCO_EN;
387 1.13 yamt }
388 1.13 yamt if ((ioreg & LPCIB_SMI_EN_GBL_SMI_EN) != 0) {
389 1.1 xtraeme bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
390 1.1 xtraeme }
391 1.1 xtraeme
392 1.1 xtraeme /* Reset the watchdog status registers. */
393 1.1 xtraeme tcotimer_status_reset(sc);
394 1.1 xtraeme
395 1.1 xtraeme /*
396 1.1 xtraeme * Register the driver with the sysmon watchdog framework.
397 1.1 xtraeme */
398 1.9 xtraeme sc->sc_smw.smw_name = device_xname(self);
399 1.1 xtraeme sc->sc_smw.smw_cookie = sc;
400 1.1 xtraeme sc->sc_smw.smw_setmode = tcotimer_setmode;
401 1.1 xtraeme sc->sc_smw.smw_tickle = tcotimer_tickle;
402 1.6 jmcneill if (sc->sc_has_rcba)
403 1.1 xtraeme period = LPCIB_TCOTIMER2_MAX_TICK;
404 1.1 xtraeme else
405 1.1 xtraeme period = LPCIB_TCOTIMER_MAX_TICK;
406 1.1 xtraeme sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(period);
407 1.1 xtraeme
408 1.1 xtraeme if (sysmon_wdog_register(&sc->sc_smw)) {
409 1.9 xtraeme aprint_error_dev(self, "unable to register TCO timer"
410 1.9 xtraeme "as a sysmon watchdog device.\n");
411 1.1 xtraeme return;
412 1.1 xtraeme }
413 1.1 xtraeme
414 1.9 xtraeme aprint_verbose_dev(self, "TCO (watchdog) timer configured.\n");
415 1.1 xtraeme }
416 1.1 xtraeme
417 1.1 xtraeme /*
418 1.1 xtraeme * Sysmon watchdog callbacks.
419 1.1 xtraeme */
420 1.1 xtraeme static int
421 1.1 xtraeme tcotimer_setmode(struct sysmon_wdog *smw)
422 1.1 xtraeme {
423 1.1 xtraeme struct lpcib_softc *sc = smw->smw_cookie;
424 1.1 xtraeme unsigned int period;
425 1.1 xtraeme uint16_t ich6period = 0;
426 1.14.4.2 snj uint8_t ich5period = 0;
427 1.1 xtraeme
428 1.1 xtraeme if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
429 1.1 xtraeme /* Stop the TCO timer. */
430 1.1 xtraeme tcotimer_stop(sc);
431 1.1 xtraeme } else {
432 1.1 xtraeme /*
433 1.6 jmcneill * ICH6 or newer are limited to 2s min and 613s max.
434 1.1 xtraeme * ICH5 or older are limited to 4s min and 39s max.
435 1.1 xtraeme */
436 1.14.4.2 snj period = lpcib_tcotimer_second_to_tick(smw->smw_period);
437 1.6 jmcneill if (sc->sc_has_rcba) {
438 1.14.4.2 snj if (period < LPCIB_TCOTIMER2_MIN_TICK ||
439 1.14.4.2 snj period > LPCIB_TCOTIMER2_MAX_TICK)
440 1.6 jmcneill return EINVAL;
441 1.6 jmcneill } else {
442 1.14.4.2 snj if (period < LPCIB_TCOTIMER_MIN_TICK ||
443 1.14.4.2 snj period > LPCIB_TCOTIMER_MAX_TICK)
444 1.1 xtraeme return EINVAL;
445 1.1 xtraeme }
446 1.5 xtraeme
447 1.1 xtraeme /* Stop the TCO timer, */
448 1.1 xtraeme tcotimer_stop(sc);
449 1.1 xtraeme
450 1.1 xtraeme /* set the timeout, */
451 1.6 jmcneill if (sc->sc_has_rcba) {
452 1.1 xtraeme /* ICH6 or newer */
453 1.1 xtraeme ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
454 1.1 xtraeme LPCIB_TCO_TMR2);
455 1.1 xtraeme ich6period &= 0xfc00;
456 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh,
457 1.1 xtraeme LPCIB_TCO_TMR2, ich6period | period);
458 1.1 xtraeme } else {
459 1.1 xtraeme /* ICH5 or older */
460 1.14.4.2 snj ich5period = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
461 1.1 xtraeme LPCIB_TCO_TMR);
462 1.14.4.2 snj ich5period &= 0xc0;
463 1.1 xtraeme bus_space_write_1(sc->sc_iot, sc->sc_ioh,
464 1.14.4.2 snj LPCIB_TCO_TMR, ich5period | period);
465 1.1 xtraeme }
466 1.1 xtraeme
467 1.1 xtraeme /* and start/reload the timer. */
468 1.1 xtraeme tcotimer_start(sc);
469 1.1 xtraeme tcotimer_tickle(smw);
470 1.1 xtraeme }
471 1.1 xtraeme
472 1.1 xtraeme return 0;
473 1.1 xtraeme }
474 1.1 xtraeme
475 1.1 xtraeme static int
476 1.1 xtraeme tcotimer_tickle(struct sysmon_wdog *smw)
477 1.1 xtraeme {
478 1.1 xtraeme struct lpcib_softc *sc = smw->smw_cookie;
479 1.1 xtraeme
480 1.1 xtraeme /* any value is allowed */
481 1.6 jmcneill if (sc->sc_has_rcba)
482 1.6 jmcneill bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
483 1.6 jmcneill else
484 1.1 xtraeme bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
485 1.1 xtraeme
486 1.1 xtraeme return 0;
487 1.1 xtraeme }
488 1.1 xtraeme
489 1.1 xtraeme static void
490 1.1 xtraeme tcotimer_stop(struct lpcib_softc *sc)
491 1.1 xtraeme {
492 1.1 xtraeme uint16_t ioreg;
493 1.1 xtraeme
494 1.1 xtraeme ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
495 1.1 xtraeme ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
496 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
497 1.1 xtraeme }
498 1.1 xtraeme
499 1.1 xtraeme static void
500 1.1 xtraeme tcotimer_start(struct lpcib_softc *sc)
501 1.1 xtraeme {
502 1.1 xtraeme uint16_t ioreg;
503 1.1 xtraeme
504 1.1 xtraeme ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
505 1.1 xtraeme ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
506 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
507 1.1 xtraeme }
508 1.1 xtraeme
509 1.1 xtraeme static void
510 1.1 xtraeme tcotimer_status_reset(struct lpcib_softc *sc)
511 1.1 xtraeme {
512 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
513 1.1 xtraeme LPCIB_TCO1_STS_TIMEOUT);
514 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
515 1.1 xtraeme LPCIB_TCO2_STS_BOOT_STS);
516 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
517 1.1 xtraeme LPCIB_TCO2_STS_SECONDS_TO_STS);
518 1.1 xtraeme }
519 1.1 xtraeme
520 1.1 xtraeme /*
521 1.4 xtraeme * Clear the No Reboot (NR) bit, this enables reboots when the timer
522 1.4 xtraeme * reaches the timeout for the second time.
523 1.1 xtraeme */
524 1.1 xtraeme static int
525 1.9 xtraeme tcotimer_disable_noreboot(device_t self)
526 1.1 xtraeme {
527 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
528 1.1 xtraeme
529 1.6 jmcneill if (sc->sc_has_rcba) {
530 1.6 jmcneill uint32_t status;
531 1.6 jmcneill
532 1.9 xtraeme status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
533 1.9 xtraeme LPCIB_GCS_OFFSET);
534 1.6 jmcneill status &= ~LPCIB_GCS_NO_REBOOT;
535 1.9 xtraeme bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah,
536 1.9 xtraeme LPCIB_GCS_OFFSET, status);
537 1.9 xtraeme status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
538 1.9 xtraeme LPCIB_GCS_OFFSET);
539 1.6 jmcneill if (status & LPCIB_GCS_NO_REBOOT)
540 1.6 jmcneill goto error;
541 1.6 jmcneill } else {
542 1.6 jmcneill pcireg_t pcireg;
543 1.6 jmcneill
544 1.12 martin pcireg = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
545 1.1 xtraeme LPCIB_PCI_GEN_STA);
546 1.1 xtraeme if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
547 1.1 xtraeme /* TCO timeout reset is disabled; try to enable it */
548 1.1 xtraeme pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
549 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
550 1.1 xtraeme LPCIB_PCI_GEN_STA, pcireg);
551 1.1 xtraeme if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
552 1.1 xtraeme goto error;
553 1.1 xtraeme }
554 1.1 xtraeme }
555 1.1 xtraeme
556 1.1 xtraeme return 0;
557 1.1 xtraeme error:
558 1.9 xtraeme aprint_error_dev(self, "TCO timer reboot disabled by hardware; "
559 1.9 xtraeme "hope SMBIOS properly handles it.\n");
560 1.1 xtraeme return EINVAL;
561 1.1 xtraeme }
562 1.1 xtraeme
563 1.1 xtraeme
564 1.1 xtraeme /*
565 1.1 xtraeme * Intel ICH SpeedStep support.
566 1.1 xtraeme */
567 1.1 xtraeme #define SS_READ(sc, reg) \
568 1.1 xtraeme bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
569 1.1 xtraeme #define SS_WRITE(sc, reg, val) \
570 1.1 xtraeme bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
571 1.1 xtraeme
572 1.1 xtraeme /*
573 1.1 xtraeme * Linux driver says that SpeedStep on older chipsets cause
574 1.1 xtraeme * lockups on Dell Inspiron 8000 and 8100.
575 1.1 xtraeme */
576 1.1 xtraeme static int
577 1.1 xtraeme speedstep_bad_hb_check(struct pci_attach_args *pa)
578 1.1 xtraeme {
579 1.1 xtraeme
580 1.1 xtraeme if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82815_FULL_HUB &&
581 1.1 xtraeme PCI_REVISION(pa->pa_class) < 5)
582 1.1 xtraeme return 1;
583 1.1 xtraeme
584 1.1 xtraeme return 0;
585 1.1 xtraeme }
586 1.1 xtraeme
587 1.1 xtraeme static void
588 1.9 xtraeme speedstep_configure(device_t self)
589 1.1 xtraeme {
590 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
591 1.1 xtraeme const struct sysctlnode *node, *ssnode;
592 1.1 xtraeme int rv;
593 1.1 xtraeme
594 1.1 xtraeme /* Supported on ICH2-M, ICH3-M and ICH4-M. */
595 1.6 jmcneill if (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801DB_ISA ||
596 1.6 jmcneill PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801CAM_LPC ||
597 1.6 jmcneill (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801BAM_LPC &&
598 1.6 jmcneill pci_find_device(&sc->sc_pa, speedstep_bad_hb_check) == 0)) {
599 1.1 xtraeme uint8_t pmcon;
600 1.1 xtraeme
601 1.1 xtraeme /* Enable SpeedStep if it isn't already enabled. */
602 1.12 martin pmcon = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
603 1.1 xtraeme LPCIB_PCI_GEN_PMCON_1);
604 1.1 xtraeme if ((pmcon & LPCIB_PCI_GEN_PMCON_1_SS_EN) == 0)
605 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
606 1.1 xtraeme LPCIB_PCI_GEN_PMCON_1,
607 1.1 xtraeme pmcon | LPCIB_PCI_GEN_PMCON_1_SS_EN);
608 1.1 xtraeme
609 1.1 xtraeme /* Put in machdep.speedstep_state (0 for low, 1 for high). */
610 1.1 xtraeme if ((rv = sysctl_createv(NULL, 0, NULL, &node,
611 1.1 xtraeme CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
612 1.1 xtraeme NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
613 1.1 xtraeme goto err;
614 1.1 xtraeme
615 1.1 xtraeme /* CTLFLAG_ANYWRITE? kernel option like EST? */
616 1.1 xtraeme if ((rv = sysctl_createv(NULL, 0, &node, &ssnode,
617 1.1 xtraeme CTLFLAG_READWRITE, CTLTYPE_INT, "speedstep_state", NULL,
618 1.1 xtraeme speedstep_sysctl_helper, 0, NULL, 0, CTL_CREATE,
619 1.1 xtraeme CTL_EOL)) != 0)
620 1.1 xtraeme goto err;
621 1.1 xtraeme
622 1.1 xtraeme /* XXX save the sc for IO tag/handle */
623 1.1 xtraeme speedstep_cookie = sc;
624 1.9 xtraeme aprint_verbose_dev(self, "SpeedStep enabled\n");
625 1.1 xtraeme }
626 1.1 xtraeme
627 1.1 xtraeme return;
628 1.1 xtraeme
629 1.1 xtraeme err:
630 1.1 xtraeme aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__, rv);
631 1.1 xtraeme }
632 1.1 xtraeme
633 1.1 xtraeme /*
634 1.1 xtraeme * get/set the SpeedStep state: 0 == low power, 1 == high power.
635 1.1 xtraeme */
636 1.1 xtraeme static int
637 1.1 xtraeme speedstep_sysctl_helper(SYSCTLFN_ARGS)
638 1.1 xtraeme {
639 1.1 xtraeme struct sysctlnode node;
640 1.1 xtraeme struct lpcib_softc *sc = speedstep_cookie;
641 1.1 xtraeme uint8_t state, state2;
642 1.1 xtraeme int ostate, nstate, s, error = 0;
643 1.1 xtraeme
644 1.1 xtraeme /*
645 1.1 xtraeme * We do the dance with spl's to avoid being at high ipl during
646 1.1 xtraeme * sysctl_lookup() which can both copyin and copyout.
647 1.1 xtraeme */
648 1.1 xtraeme s = splserial();
649 1.1 xtraeme state = SS_READ(sc, LPCIB_PM_SS_CNTL);
650 1.1 xtraeme splx(s);
651 1.1 xtraeme if ((state & LPCIB_PM_SS_STATE_LOW) == 0)
652 1.1 xtraeme ostate = 1;
653 1.1 xtraeme else
654 1.1 xtraeme ostate = 0;
655 1.1 xtraeme nstate = ostate;
656 1.1 xtraeme
657 1.1 xtraeme node = *rnode;
658 1.1 xtraeme node.sysctl_data = &nstate;
659 1.1 xtraeme
660 1.1 xtraeme error = sysctl_lookup(SYSCTLFN_CALL(&node));
661 1.1 xtraeme if (error || newp == NULL)
662 1.1 xtraeme goto out;
663 1.1 xtraeme
664 1.1 xtraeme /* Only two states are available */
665 1.1 xtraeme if (nstate != 0 && nstate != 1) {
666 1.1 xtraeme error = EINVAL;
667 1.1 xtraeme goto out;
668 1.1 xtraeme }
669 1.1 xtraeme
670 1.1 xtraeme s = splserial();
671 1.1 xtraeme state2 = SS_READ(sc, LPCIB_PM_SS_CNTL);
672 1.1 xtraeme if ((state2 & LPCIB_PM_SS_STATE_LOW) == 0)
673 1.1 xtraeme ostate = 1;
674 1.1 xtraeme else
675 1.1 xtraeme ostate = 0;
676 1.1 xtraeme
677 1.1 xtraeme if (ostate != nstate) {
678 1.1 xtraeme uint8_t cntl;
679 1.1 xtraeme
680 1.1 xtraeme if (nstate == 0)
681 1.1 xtraeme state2 |= LPCIB_PM_SS_STATE_LOW;
682 1.1 xtraeme else
683 1.1 xtraeme state2 &= ~LPCIB_PM_SS_STATE_LOW;
684 1.1 xtraeme
685 1.1 xtraeme /*
686 1.1 xtraeme * Must disable bus master arbitration during the change.
687 1.1 xtraeme */
688 1.1 xtraeme cntl = SS_READ(sc, LPCIB_PM_CTRL);
689 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_CTRL, cntl | LPCIB_PM_SS_CNTL_ARB_DIS);
690 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_SS_CNTL, state2);
691 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_CTRL, cntl);
692 1.1 xtraeme }
693 1.1 xtraeme splx(s);
694 1.1 xtraeme out:
695 1.1 xtraeme return error;
696 1.1 xtraeme }
697 1.6 jmcneill
698 1.6 jmcneill #if NHPET > 0
699 1.6 jmcneill struct lpcib_hpet_attach_arg {
700 1.6 jmcneill bus_space_tag_t hpet_mem_t;
701 1.6 jmcneill uint32_t hpet_reg;
702 1.6 jmcneill };
703 1.6 jmcneill
704 1.6 jmcneill static int
705 1.9 xtraeme lpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
706 1.6 jmcneill {
707 1.6 jmcneill struct lpcib_hpet_attach_arg *arg = aux;
708 1.6 jmcneill bus_space_tag_t tag;
709 1.6 jmcneill bus_space_handle_t handle;
710 1.6 jmcneill
711 1.6 jmcneill tag = arg->hpet_mem_t;
712 1.6 jmcneill
713 1.6 jmcneill if (bus_space_map(tag, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &handle)) {
714 1.10 cegger aprint_verbose_dev(parent, "HPET window not mapped, skipping\n");
715 1.6 jmcneill return 0;
716 1.6 jmcneill }
717 1.6 jmcneill bus_space_unmap(tag, handle, HPET_WINDOW_SIZE);
718 1.6 jmcneill
719 1.6 jmcneill return 1;
720 1.6 jmcneill }
721 1.6 jmcneill
722 1.6 jmcneill static void
723 1.6 jmcneill lpcib_hpet_attach(device_t parent, device_t self, void *aux)
724 1.6 jmcneill {
725 1.6 jmcneill struct hpet_softc *sc = device_private(self);
726 1.6 jmcneill struct lpcib_hpet_attach_arg *arg = aux;
727 1.6 jmcneill
728 1.6 jmcneill aprint_naive("\n");
729 1.6 jmcneill aprint_normal("\n");
730 1.6 jmcneill
731 1.6 jmcneill sc->sc_memt = arg->hpet_mem_t;
732 1.6 jmcneill
733 1.6 jmcneill if (bus_space_map(sc->sc_memt, arg->hpet_reg, HPET_WINDOW_SIZE, 0,
734 1.6 jmcneill &sc->sc_memh)) {
735 1.9 xtraeme aprint_error_dev(self,
736 1.9 xtraeme "HPET memory window could not be mapped");
737 1.6 jmcneill return;
738 1.6 jmcneill }
739 1.6 jmcneill
740 1.9 xtraeme hpet_attach_subr(self);
741 1.6 jmcneill }
742 1.6 jmcneill
743 1.9 xtraeme CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc), lpcib_hpet_match,
744 1.6 jmcneill lpcib_hpet_attach, NULL, NULL);
745 1.6 jmcneill
746 1.6 jmcneill static void
747 1.9 xtraeme lpcib_hpet_configure(device_t self)
748 1.6 jmcneill {
749 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
750 1.6 jmcneill struct lpcib_hpet_attach_arg arg;
751 1.6 jmcneill uint32_t hpet_reg, val;
752 1.6 jmcneill
753 1.6 jmcneill if (sc->sc_has_ich5_hpet) {
754 1.12 martin val = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
755 1.9 xtraeme LPCIB_PCI_GEN_CNTL);
756 1.6 jmcneill switch (val & LPCIB_ICH5_HPTC_WIN_MASK) {
757 1.6 jmcneill case LPCIB_ICH5_HPTC_0000:
758 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_0000_BASE;
759 1.6 jmcneill break;
760 1.6 jmcneill case LPCIB_ICH5_HPTC_1000:
761 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_1000_BASE;
762 1.6 jmcneill break;
763 1.6 jmcneill case LPCIB_ICH5_HPTC_2000:
764 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_2000_BASE;
765 1.6 jmcneill break;
766 1.6 jmcneill case LPCIB_ICH5_HPTC_3000:
767 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_3000_BASE;
768 1.6 jmcneill break;
769 1.6 jmcneill default:
770 1.6 jmcneill return;
771 1.6 jmcneill }
772 1.6 jmcneill val |= sc->sc_hpet_reg | LPCIB_ICH5_HPTC_EN;
773 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
774 1.9 xtraeme LPCIB_PCI_GEN_CNTL, val);
775 1.6 jmcneill } else if (sc->sc_has_rcba) {
776 1.6 jmcneill val = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
777 1.6 jmcneill LPCIB_RCBA_HPTC);
778 1.6 jmcneill switch (val & LPCIB_RCBA_HPTC_WIN_MASK) {
779 1.6 jmcneill case LPCIB_RCBA_HPTC_0000:
780 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_0000_BASE;
781 1.6 jmcneill break;
782 1.6 jmcneill case LPCIB_RCBA_HPTC_1000:
783 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_1000_BASE;
784 1.6 jmcneill break;
785 1.6 jmcneill case LPCIB_RCBA_HPTC_2000:
786 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_2000_BASE;
787 1.6 jmcneill break;
788 1.6 jmcneill case LPCIB_RCBA_HPTC_3000:
789 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_3000_BASE;
790 1.6 jmcneill break;
791 1.6 jmcneill default:
792 1.6 jmcneill return;
793 1.6 jmcneill }
794 1.6 jmcneill val |= LPCIB_RCBA_HPTC_EN;
795 1.6 jmcneill bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
796 1.6 jmcneill val);
797 1.6 jmcneill } else {
798 1.6 jmcneill /* No HPET here */
799 1.6 jmcneill return;
800 1.6 jmcneill }
801 1.6 jmcneill
802 1.6 jmcneill arg.hpet_mem_t = sc->sc_pa.pa_memt;
803 1.6 jmcneill arg.hpet_reg = hpet_reg;
804 1.6 jmcneill
805 1.9 xtraeme config_found_ia(self, "hpetichbus", &arg, NULL);
806 1.6 jmcneill }
807 1.6 jmcneill #endif
808