ichlpcib.c revision 1.29 1 1.29 dyoung /* $NetBSD: ichlpcib.c,v 1.29 2011/04/04 20:37:55 dyoung 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.29 dyoung __KERNEL_RCSID(0, "$NetBSD: ichlpcib.c,v 1.29 2011/04/04 20:37:55 dyoung 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.20 jakllsch #include <sys/gpio.h>
51 1.1 xtraeme #include <machine/bus.h>
52 1.1 xtraeme
53 1.1 xtraeme #include <dev/pci/pcivar.h>
54 1.1 xtraeme #include <dev/pci/pcireg.h>
55 1.1 xtraeme #include <dev/pci/pcidevs.h>
56 1.1 xtraeme
57 1.20 jakllsch #include <dev/gpio/gpiovar.h>
58 1.1 xtraeme #include <dev/sysmon/sysmonvar.h>
59 1.1 xtraeme
60 1.6 jmcneill #include <dev/ic/acpipmtimer.h>
61 1.1 xtraeme #include <dev/ic/i82801lpcreg.h>
62 1.6 jmcneill #include <dev/ic/hpetreg.h>
63 1.6 jmcneill #include <dev/ic/hpetvar.h>
64 1.6 jmcneill
65 1.6 jmcneill #include "hpet.h"
66 1.12 martin #include "pcibvar.h"
67 1.20 jakllsch #include "gpio.h"
68 1.25 jakllsch #include "fwhrng.h"
69 1.20 jakllsch
70 1.20 jakllsch #define LPCIB_GPIO_NPINS 64
71 1.1 xtraeme
72 1.1 xtraeme struct lpcib_softc {
73 1.12 martin /* we call pcibattach() which assumes this starts like this: */
74 1.12 martin struct pcib_softc sc_pcib;
75 1.1 xtraeme
76 1.6 jmcneill struct pci_attach_args sc_pa;
77 1.6 jmcneill int sc_has_rcba;
78 1.6 jmcneill int sc_has_ich5_hpet;
79 1.6 jmcneill
80 1.6 jmcneill /* RCBA */
81 1.6 jmcneill bus_space_tag_t sc_rcbat;
82 1.6 jmcneill bus_space_handle_t sc_rcbah;
83 1.6 jmcneill pcireg_t sc_rcba_reg;
84 1.6 jmcneill
85 1.1 xtraeme /* Watchdog variables. */
86 1.1 xtraeme struct sysmon_wdog sc_smw;
87 1.1 xtraeme bus_space_tag_t sc_iot;
88 1.1 xtraeme bus_space_handle_t sc_ioh;
89 1.19 dyoung bus_size_t sc_iosize;
90 1.6 jmcneill
91 1.6 jmcneill #if NHPET > 0
92 1.6 jmcneill /* HPET variables. */
93 1.6 jmcneill uint32_t sc_hpet_reg;
94 1.6 jmcneill #endif
95 1.6 jmcneill
96 1.20 jakllsch #if NGPIO > 0
97 1.20 jakllsch device_t sc_gpiobus;
98 1.20 jakllsch kmutex_t sc_gpio_mtx;
99 1.20 jakllsch bus_space_tag_t sc_gpio_iot;
100 1.20 jakllsch bus_space_handle_t sc_gpio_ioh;
101 1.20 jakllsch bus_size_t sc_gpio_ios;
102 1.20 jakllsch struct gpio_chipset_tag sc_gpio_gc;
103 1.20 jakllsch gpio_pin_t sc_gpio_pins[LPCIB_GPIO_NPINS];
104 1.20 jakllsch #endif
105 1.20 jakllsch
106 1.25 jakllsch #if NFWHRNG > 0
107 1.25 jakllsch device_t sc_fwhbus;
108 1.25 jakllsch #endif
109 1.25 jakllsch
110 1.16 joerg /* Speedstep */
111 1.16 joerg pcireg_t sc_pmcon_orig;
112 1.16 joerg
113 1.1 xtraeme /* Power management */
114 1.7 drochner pcireg_t sc_pirq[2];
115 1.6 jmcneill pcireg_t sc_pmcon;
116 1.6 jmcneill pcireg_t sc_fwhsel2;
117 1.19 dyoung
118 1.19 dyoung /* Child devices */
119 1.19 dyoung device_t sc_hpetbus;
120 1.19 dyoung acpipmtimer_t sc_pmtimer;
121 1.19 dyoung pcireg_t sc_acpi_cntl;
122 1.19 dyoung
123 1.19 dyoung struct sysctllog *sc_log;
124 1.1 xtraeme };
125 1.1 xtraeme
126 1.9 xtraeme static int lpcibmatch(device_t, cfdata_t, void *);
127 1.9 xtraeme static void lpcibattach(device_t, device_t, void *);
128 1.19 dyoung static int lpcibdetach(device_t, int);
129 1.19 dyoung static void lpcibchilddet(device_t, device_t);
130 1.19 dyoung static int lpcibrescan(device_t, const char *, const int *);
131 1.24 dyoung static bool lpcib_suspend(device_t, const pmf_qual_t *);
132 1.24 dyoung static bool lpcib_resume(device_t, const pmf_qual_t *);
133 1.16 joerg static bool lpcib_shutdown(device_t, int);
134 1.1 xtraeme
135 1.9 xtraeme static void pmtimer_configure(device_t);
136 1.19 dyoung static int pmtimer_unconfigure(device_t, int);
137 1.1 xtraeme
138 1.9 xtraeme static void tcotimer_configure(device_t);
139 1.19 dyoung static int tcotimer_unconfigure(device_t, int);
140 1.1 xtraeme static int tcotimer_setmode(struct sysmon_wdog *);
141 1.1 xtraeme static int tcotimer_tickle(struct sysmon_wdog *);
142 1.1 xtraeme static void tcotimer_stop(struct lpcib_softc *);
143 1.1 xtraeme static void tcotimer_start(struct lpcib_softc *);
144 1.1 xtraeme static void tcotimer_status_reset(struct lpcib_softc *);
145 1.9 xtraeme static int tcotimer_disable_noreboot(device_t);
146 1.1 xtraeme
147 1.9 xtraeme static void speedstep_configure(device_t);
148 1.19 dyoung static void speedstep_unconfigure(device_t);
149 1.1 xtraeme static int speedstep_sysctl_helper(SYSCTLFN_ARGS);
150 1.1 xtraeme
151 1.6 jmcneill #if NHPET > 0
152 1.9 xtraeme static void lpcib_hpet_configure(device_t);
153 1.19 dyoung static int lpcib_hpet_unconfigure(device_t, int);
154 1.6 jmcneill #endif
155 1.6 jmcneill
156 1.20 jakllsch #if NGPIO > 0
157 1.20 jakllsch static void lpcib_gpio_configure(device_t);
158 1.20 jakllsch static int lpcib_gpio_unconfigure(device_t, int);
159 1.20 jakllsch static int lpcib_gpio_pin_read(void *, int);
160 1.20 jakllsch static void lpcib_gpio_pin_write(void *, int, int);
161 1.20 jakllsch static void lpcib_gpio_pin_ctl(void *, int, int);
162 1.20 jakllsch #endif
163 1.20 jakllsch
164 1.25 jakllsch #if NFWHRNG > 0
165 1.25 jakllsch static void lpcib_fwh_configure(device_t);
166 1.25 jakllsch static int lpcib_fwh_unconfigure(device_t, int);
167 1.25 jakllsch #endif
168 1.25 jakllsch
169 1.1 xtraeme struct lpcib_softc *speedstep_cookie; /* XXX */
170 1.1 xtraeme
171 1.19 dyoung CFATTACH_DECL2_NEW(ichlpcib, sizeof(struct lpcib_softc),
172 1.19 dyoung lpcibmatch, lpcibattach, lpcibdetach, NULL, lpcibrescan, lpcibchilddet);
173 1.1 xtraeme
174 1.6 jmcneill static struct lpcib_device {
175 1.6 jmcneill pcireg_t vendor, product;
176 1.6 jmcneill int has_rcba;
177 1.6 jmcneill int has_ich5_hpet;
178 1.6 jmcneill } lpcib_devices[] = {
179 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_LPC, 0, 0 },
180 1.27 jakllsch { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AB_LPC, 0, 0 },
181 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_LPC, 0, 0 },
182 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BAM_LPC, 0, 0 },
183 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_LPC, 0, 0 },
184 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CAM_LPC, 0, 0 },
185 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LPC, 0, 0 },
186 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_ISA, 0, 0 },
187 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801EB_LPC, 0, 1 },
188 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LPC, 1, 0 },
189 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LPC, 1, 0 },
190 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801G_LPC, 1, 0 },
191 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GBM_LPC, 1, 0 },
192 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GHM_LPC, 1, 0 },
193 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801H_LPC, 1, 0 },
194 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HEM_LPC, 1, 0 },
195 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HH_LPC, 1, 0 },
196 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HO_LPC, 1, 0 },
197 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801HBM_LPC, 1, 0 },
198 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IH_LPC, 1, 0 },
199 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IO_LPC, 1, 0 },
200 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IR_LPC, 1, 0 },
201 1.17 njoly { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IEM_LPC, 1, 0 },
202 1.6 jmcneill { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801IB_LPC, 1, 0 },
203 1.14 joerg { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_63XXESB_LPC, 1, 0 },
204 1.14 joerg
205 1.6 jmcneill { 0, 0, 0, 0 },
206 1.6 jmcneill };
207 1.6 jmcneill
208 1.1 xtraeme /*
209 1.1 xtraeme * Autoconf callbacks.
210 1.1 xtraeme */
211 1.1 xtraeme static int
212 1.9 xtraeme lpcibmatch(device_t parent, cfdata_t match, void *aux)
213 1.1 xtraeme {
214 1.1 xtraeme struct pci_attach_args *pa = aux;
215 1.6 jmcneill struct lpcib_device *lpcib_dev;
216 1.1 xtraeme
217 1.1 xtraeme /* We are ISA bridge, of course */
218 1.1 xtraeme if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
219 1.1 xtraeme PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
220 1.1 xtraeme return 0;
221 1.1 xtraeme
222 1.6 jmcneill for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
223 1.6 jmcneill if (PCI_VENDOR(pa->pa_id) == lpcib_dev->vendor &&
224 1.6 jmcneill PCI_PRODUCT(pa->pa_id) == lpcib_dev->product)
225 1.1 xtraeme return 10;
226 1.1 xtraeme }
227 1.1 xtraeme
228 1.1 xtraeme return 0;
229 1.1 xtraeme }
230 1.1 xtraeme
231 1.1 xtraeme static void
232 1.9 xtraeme lpcibattach(device_t parent, device_t self, void *aux)
233 1.1 xtraeme {
234 1.1 xtraeme struct pci_attach_args *pa = aux;
235 1.6 jmcneill struct lpcib_softc *sc = device_private(self);
236 1.6 jmcneill struct lpcib_device *lpcib_dev;
237 1.1 xtraeme
238 1.6 jmcneill sc->sc_pa = *pa;
239 1.6 jmcneill
240 1.6 jmcneill for (lpcib_dev = lpcib_devices; lpcib_dev->vendor; ++lpcib_dev) {
241 1.6 jmcneill if (PCI_VENDOR(pa->pa_id) != lpcib_dev->vendor ||
242 1.6 jmcneill PCI_PRODUCT(pa->pa_id) != lpcib_dev->product)
243 1.6 jmcneill continue;
244 1.6 jmcneill sc->sc_has_rcba = lpcib_dev->has_rcba;
245 1.6 jmcneill sc->sc_has_ich5_hpet = lpcib_dev->has_ich5_hpet;
246 1.6 jmcneill break;
247 1.6 jmcneill }
248 1.1 xtraeme
249 1.1 xtraeme pcibattach(parent, self, aux);
250 1.1 xtraeme
251 1.1 xtraeme /*
252 1.1 xtraeme * Part of our I/O registers are used as ACPI PM regs.
253 1.1 xtraeme * Since our ACPI subsystem accesses the I/O space directly so far,
254 1.1 xtraeme * we do not have to bother bus_space I/O map confliction.
255 1.1 xtraeme */
256 1.1 xtraeme if (pci_mapreg_map(pa, LPCIB_PCI_PMBASE, PCI_MAPREG_TYPE_IO, 0,
257 1.19 dyoung &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_iosize)) {
258 1.9 xtraeme aprint_error_dev(self, "can't map power management i/o space");
259 1.1 xtraeme return;
260 1.1 xtraeme }
261 1.1 xtraeme
262 1.16 joerg sc->sc_pmcon_orig = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
263 1.16 joerg LPCIB_PCI_GEN_PMCON_1);
264 1.16 joerg
265 1.6 jmcneill /* For ICH6 and later, always enable RCBA */
266 1.6 jmcneill if (sc->sc_has_rcba) {
267 1.6 jmcneill pcireg_t rcba;
268 1.6 jmcneill
269 1.6 jmcneill sc->sc_rcbat = sc->sc_pa.pa_memt;
270 1.6 jmcneill
271 1.12 martin rcba = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
272 1.12 martin LPCIB_RCBA);
273 1.6 jmcneill if ((rcba & LPCIB_RCBA_EN) == 0) {
274 1.9 xtraeme aprint_error_dev(self, "RCBA is not enabled");
275 1.6 jmcneill return;
276 1.6 jmcneill }
277 1.6 jmcneill rcba &= ~LPCIB_RCBA_EN;
278 1.6 jmcneill
279 1.6 jmcneill if (bus_space_map(sc->sc_rcbat, rcba, LPCIB_RCBA_SIZE, 0,
280 1.6 jmcneill &sc->sc_rcbah)) {
281 1.9 xtraeme aprint_error_dev(self, "RCBA could not be mapped");
282 1.6 jmcneill return;
283 1.6 jmcneill }
284 1.6 jmcneill }
285 1.6 jmcneill
286 1.1 xtraeme /* Set up the power management timer. */
287 1.9 xtraeme pmtimer_configure(self);
288 1.1 xtraeme
289 1.1 xtraeme /* Set up the TCO (watchdog). */
290 1.9 xtraeme tcotimer_configure(self);
291 1.1 xtraeme
292 1.1 xtraeme /* Set up SpeedStep. */
293 1.9 xtraeme speedstep_configure(self);
294 1.1 xtraeme
295 1.6 jmcneill #if NHPET > 0
296 1.6 jmcneill /* Set up HPET. */
297 1.9 xtraeme lpcib_hpet_configure(self);
298 1.6 jmcneill #endif
299 1.6 jmcneill
300 1.20 jakllsch #if NGPIO > 0
301 1.20 jakllsch /* Set up GPIO */
302 1.20 jakllsch lpcib_gpio_configure(self);
303 1.20 jakllsch #endif
304 1.20 jakllsch
305 1.25 jakllsch #if NFWHRNG > 0
306 1.25 jakllsch lpcib_fwh_configure(self);
307 1.25 jakllsch #endif
308 1.25 jakllsch
309 1.6 jmcneill /* Install power handler */
310 1.16 joerg if (!pmf_device_register1(self, lpcib_suspend, lpcib_resume,
311 1.16 joerg lpcib_shutdown))
312 1.6 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
313 1.6 jmcneill }
314 1.6 jmcneill
315 1.19 dyoung static void
316 1.19 dyoung lpcibchilddet(device_t self, device_t child)
317 1.19 dyoung {
318 1.19 dyoung struct lpcib_softc *sc = device_private(self);
319 1.19 dyoung uint32_t val;
320 1.19 dyoung
321 1.25 jakllsch #if NFWHRNG > 0
322 1.25 jakllsch if (sc->sc_fwhbus == child) {
323 1.25 jakllsch sc->sc_fwhbus = NULL;
324 1.25 jakllsch return;
325 1.25 jakllsch }
326 1.25 jakllsch #endif
327 1.21 jakllsch #if NGPIO > 0
328 1.20 jakllsch if (sc->sc_gpiobus == child) {
329 1.20 jakllsch sc->sc_gpiobus = NULL;
330 1.20 jakllsch return;
331 1.20 jakllsch }
332 1.21 jakllsch #endif
333 1.19 dyoung if (sc->sc_hpetbus != child) {
334 1.19 dyoung pcibchilddet(self, child);
335 1.19 dyoung return;
336 1.19 dyoung }
337 1.19 dyoung sc->sc_hpetbus = NULL;
338 1.19 dyoung if (sc->sc_has_ich5_hpet) {
339 1.19 dyoung val = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
340 1.19 dyoung LPCIB_PCI_GEN_CNTL);
341 1.19 dyoung switch (val & LPCIB_ICH5_HPTC_WIN_MASK) {
342 1.19 dyoung case LPCIB_ICH5_HPTC_0000:
343 1.19 dyoung case LPCIB_ICH5_HPTC_1000:
344 1.19 dyoung case LPCIB_ICH5_HPTC_2000:
345 1.19 dyoung case LPCIB_ICH5_HPTC_3000:
346 1.19 dyoung break;
347 1.19 dyoung default:
348 1.19 dyoung return;
349 1.19 dyoung }
350 1.19 dyoung val &= ~LPCIB_ICH5_HPTC_EN;
351 1.19 dyoung pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
352 1.19 dyoung LPCIB_PCI_GEN_CNTL, val);
353 1.19 dyoung } else if (sc->sc_has_rcba) {
354 1.19 dyoung val = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
355 1.19 dyoung LPCIB_RCBA_HPTC);
356 1.19 dyoung switch (val & LPCIB_RCBA_HPTC_WIN_MASK) {
357 1.19 dyoung case LPCIB_RCBA_HPTC_0000:
358 1.19 dyoung case LPCIB_RCBA_HPTC_1000:
359 1.19 dyoung case LPCIB_RCBA_HPTC_2000:
360 1.19 dyoung case LPCIB_RCBA_HPTC_3000:
361 1.19 dyoung break;
362 1.19 dyoung default:
363 1.19 dyoung return;
364 1.19 dyoung }
365 1.19 dyoung val &= ~LPCIB_RCBA_HPTC_EN;
366 1.19 dyoung bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
367 1.19 dyoung val);
368 1.19 dyoung }
369 1.19 dyoung }
370 1.19 dyoung
371 1.19 dyoung static int
372 1.19 dyoung lpcibrescan(device_t self, const char *ifattr, const int *locators)
373 1.19 dyoung {
374 1.28 christos #if NHPET > 0 || NGPIO > 0 || NFWHRNG > 0
375 1.19 dyoung struct lpcib_softc *sc = device_private(self);
376 1.20 jakllsch #endif
377 1.19 dyoung
378 1.25 jakllsch #if NFWHRNG > 0
379 1.25 jakllsch if (ifattr_match(ifattr, "fwhichbus") && sc->sc_fwhbus == NULL)
380 1.25 jakllsch lpcib_fwh_configure(self);
381 1.25 jakllsch #endif
382 1.25 jakllsch
383 1.20 jakllsch #if NHPET > 0
384 1.19 dyoung if (ifattr_match(ifattr, "hpetichbus") && sc->sc_hpetbus == NULL)
385 1.19 dyoung lpcib_hpet_configure(self);
386 1.19 dyoung #endif
387 1.19 dyoung
388 1.20 jakllsch #if NGPIO > 0
389 1.20 jakllsch if (ifattr_match(ifattr, "gpiobus") && sc->sc_gpiobus == NULL)
390 1.20 jakllsch lpcib_gpio_configure(self);
391 1.20 jakllsch #endif
392 1.20 jakllsch
393 1.19 dyoung return pcibrescan(self, ifattr, locators);
394 1.19 dyoung }
395 1.19 dyoung
396 1.19 dyoung static int
397 1.19 dyoung lpcibdetach(device_t self, int flags)
398 1.19 dyoung {
399 1.19 dyoung struct lpcib_softc *sc = device_private(self);
400 1.19 dyoung int rc;
401 1.19 dyoung
402 1.19 dyoung pmf_device_deregister(self);
403 1.19 dyoung
404 1.25 jakllsch #if NFWHRNG > 0
405 1.25 jakllsch if ((rc = lpcib_fwh_unconfigure(self, flags)) != 0)
406 1.25 jakllsch return rc;
407 1.25 jakllsch #endif
408 1.25 jakllsch
409 1.19 dyoung #if NHPET > 0
410 1.19 dyoung if ((rc = lpcib_hpet_unconfigure(self, flags)) != 0)
411 1.19 dyoung return rc;
412 1.19 dyoung #endif
413 1.19 dyoung
414 1.20 jakllsch #if NGPIO > 0
415 1.20 jakllsch if ((rc = lpcib_gpio_unconfigure(self, flags)) != 0)
416 1.20 jakllsch return rc;
417 1.20 jakllsch #endif
418 1.20 jakllsch
419 1.19 dyoung /* Set up SpeedStep. */
420 1.19 dyoung speedstep_unconfigure(self);
421 1.19 dyoung
422 1.19 dyoung if ((rc = tcotimer_unconfigure(self, flags)) != 0)
423 1.19 dyoung return rc;
424 1.19 dyoung
425 1.19 dyoung if ((rc = pmtimer_unconfigure(self, flags)) != 0)
426 1.19 dyoung return rc;
427 1.19 dyoung
428 1.19 dyoung if (sc->sc_has_rcba)
429 1.19 dyoung bus_space_unmap(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_SIZE);
430 1.19 dyoung
431 1.19 dyoung bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
432 1.19 dyoung
433 1.19 dyoung return pcibdetach(self, flags);
434 1.19 dyoung }
435 1.19 dyoung
436 1.6 jmcneill static bool
437 1.16 joerg lpcib_shutdown(device_t dv, int howto)
438 1.16 joerg {
439 1.16 joerg struct lpcib_softc *sc = device_private(dv);
440 1.16 joerg
441 1.16 joerg pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
442 1.16 joerg LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon_orig);
443 1.16 joerg
444 1.16 joerg return true;
445 1.16 joerg }
446 1.16 joerg
447 1.16 joerg static bool
448 1.24 dyoung lpcib_suspend(device_t dv, const pmf_qual_t *qual)
449 1.6 jmcneill {
450 1.6 jmcneill struct lpcib_softc *sc = device_private(dv);
451 1.12 martin pci_chipset_tag_t pc = sc->sc_pcib.sc_pc;
452 1.12 martin pcitag_t tag = sc->sc_pcib.sc_tag;
453 1.6 jmcneill
454 1.6 jmcneill /* capture PIRQ routing control registers */
455 1.6 jmcneill sc->sc_pirq[0] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQA_ROUT);
456 1.7 drochner sc->sc_pirq[1] = pci_conf_read(pc, tag, LPCIB_PCI_PIRQE_ROUT);
457 1.6 jmcneill
458 1.6 jmcneill sc->sc_pmcon = pci_conf_read(pc, tag, LPCIB_PCI_GEN_PMCON_1);
459 1.6 jmcneill sc->sc_fwhsel2 = pci_conf_read(pc, tag, LPCIB_PCI_GEN_STA);
460 1.6 jmcneill
461 1.6 jmcneill if (sc->sc_has_rcba) {
462 1.6 jmcneill sc->sc_rcba_reg = pci_conf_read(pc, tag, LPCIB_RCBA);
463 1.6 jmcneill #if NHPET > 0
464 1.6 jmcneill sc->sc_hpet_reg = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
465 1.6 jmcneill LPCIB_RCBA_HPTC);
466 1.6 jmcneill #endif
467 1.6 jmcneill } else if (sc->sc_has_ich5_hpet) {
468 1.6 jmcneill #if NHPET > 0
469 1.6 jmcneill sc->sc_hpet_reg = pci_conf_read(pc, tag, LPCIB_PCI_GEN_CNTL);
470 1.6 jmcneill #endif
471 1.6 jmcneill }
472 1.6 jmcneill
473 1.6 jmcneill return true;
474 1.6 jmcneill }
475 1.6 jmcneill
476 1.6 jmcneill static bool
477 1.24 dyoung lpcib_resume(device_t dv, const pmf_qual_t *qual)
478 1.6 jmcneill {
479 1.6 jmcneill struct lpcib_softc *sc = device_private(dv);
480 1.12 martin pci_chipset_tag_t pc = sc->sc_pcib.sc_pc;
481 1.12 martin pcitag_t tag = sc->sc_pcib.sc_tag;
482 1.6 jmcneill
483 1.6 jmcneill /* restore PIRQ routing control registers */
484 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_PIRQA_ROUT, sc->sc_pirq[0]);
485 1.7 drochner pci_conf_write(pc, tag, LPCIB_PCI_PIRQE_ROUT, sc->sc_pirq[1]);
486 1.6 jmcneill
487 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon);
488 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_STA, sc->sc_fwhsel2);
489 1.6 jmcneill
490 1.6 jmcneill if (sc->sc_has_rcba) {
491 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_RCBA, sc->sc_rcba_reg);
492 1.6 jmcneill #if NHPET > 0
493 1.6 jmcneill bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
494 1.6 jmcneill sc->sc_hpet_reg);
495 1.6 jmcneill #endif
496 1.6 jmcneill } else if (sc->sc_has_ich5_hpet) {
497 1.6 jmcneill #if NHPET > 0
498 1.6 jmcneill pci_conf_write(pc, tag, LPCIB_PCI_GEN_CNTL, sc->sc_hpet_reg);
499 1.6 jmcneill #endif
500 1.6 jmcneill }
501 1.1 xtraeme
502 1.6 jmcneill return true;
503 1.1 xtraeme }
504 1.1 xtraeme
505 1.1 xtraeme /*
506 1.1 xtraeme * Initialize the power management timer.
507 1.1 xtraeme */
508 1.1 xtraeme static void
509 1.9 xtraeme pmtimer_configure(device_t self)
510 1.1 xtraeme {
511 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
512 1.1 xtraeme pcireg_t control;
513 1.1 xtraeme
514 1.1 xtraeme /*
515 1.1 xtraeme * Check if power management I/O space is enabled and enable the ACPI_EN
516 1.1 xtraeme * bit if it's disabled.
517 1.1 xtraeme */
518 1.12 martin control = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
519 1.12 martin LPCIB_PCI_ACPI_CNTL);
520 1.19 dyoung sc->sc_acpi_cntl = control;
521 1.1 xtraeme if ((control & LPCIB_PCI_ACPI_CNTL_EN) == 0) {
522 1.1 xtraeme control |= LPCIB_PCI_ACPI_CNTL_EN;
523 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
524 1.12 martin LPCIB_PCI_ACPI_CNTL, control);
525 1.1 xtraeme }
526 1.1 xtraeme
527 1.1 xtraeme /* Attach our PM timer with the generic acpipmtimer function */
528 1.19 dyoung sc->sc_pmtimer = acpipmtimer_attach(self, sc->sc_iot, sc->sc_ioh,
529 1.1 xtraeme LPCIB_PM1_TMR, 0);
530 1.1 xtraeme }
531 1.1 xtraeme
532 1.19 dyoung static int
533 1.19 dyoung pmtimer_unconfigure(device_t self, int flags)
534 1.19 dyoung {
535 1.19 dyoung struct lpcib_softc *sc = device_private(self);
536 1.19 dyoung int rc;
537 1.19 dyoung
538 1.19 dyoung if (sc->sc_pmtimer != NULL &&
539 1.19 dyoung (rc = acpipmtimer_detach(sc->sc_pmtimer, flags)) != 0)
540 1.19 dyoung return rc;
541 1.19 dyoung
542 1.19 dyoung pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
543 1.19 dyoung LPCIB_PCI_ACPI_CNTL, sc->sc_acpi_cntl);
544 1.19 dyoung
545 1.19 dyoung return 0;
546 1.19 dyoung }
547 1.19 dyoung
548 1.1 xtraeme /*
549 1.1 xtraeme * Initialize the watchdog timer.
550 1.1 xtraeme */
551 1.1 xtraeme static void
552 1.9 xtraeme tcotimer_configure(device_t self)
553 1.1 xtraeme {
554 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
555 1.1 xtraeme uint32_t ioreg;
556 1.1 xtraeme unsigned int period;
557 1.1 xtraeme
558 1.13 yamt /* Explicitly stop the TCO timer. */
559 1.13 yamt tcotimer_stop(sc);
560 1.13 yamt
561 1.13 yamt /*
562 1.13 yamt * Enable TCO timeout SMI only if the hardware reset does not
563 1.13 yamt * work. We don't know what the SMBIOS does.
564 1.13 yamt */
565 1.13 yamt ioreg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN);
566 1.13 yamt ioreg &= ~LPCIB_SMI_EN_TCO_EN;
567 1.13 yamt
568 1.1 xtraeme /*
569 1.4 xtraeme * Clear the No Reboot (NR) bit. If this fails, enabling the TCO_EN bit
570 1.1 xtraeme * in the SMI_EN register is the last chance.
571 1.1 xtraeme */
572 1.9 xtraeme if (tcotimer_disable_noreboot(self)) {
573 1.1 xtraeme ioreg |= LPCIB_SMI_EN_TCO_EN;
574 1.13 yamt }
575 1.13 yamt if ((ioreg & LPCIB_SMI_EN_GBL_SMI_EN) != 0) {
576 1.1 xtraeme bus_space_write_4(sc->sc_iot, sc->sc_ioh, LPCIB_SMI_EN, ioreg);
577 1.1 xtraeme }
578 1.1 xtraeme
579 1.1 xtraeme /* Reset the watchdog status registers. */
580 1.1 xtraeme tcotimer_status_reset(sc);
581 1.1 xtraeme
582 1.1 xtraeme /*
583 1.1 xtraeme * Register the driver with the sysmon watchdog framework.
584 1.1 xtraeme */
585 1.9 xtraeme sc->sc_smw.smw_name = device_xname(self);
586 1.1 xtraeme sc->sc_smw.smw_cookie = sc;
587 1.1 xtraeme sc->sc_smw.smw_setmode = tcotimer_setmode;
588 1.1 xtraeme sc->sc_smw.smw_tickle = tcotimer_tickle;
589 1.6 jmcneill if (sc->sc_has_rcba)
590 1.1 xtraeme period = LPCIB_TCOTIMER2_MAX_TICK;
591 1.1 xtraeme else
592 1.1 xtraeme period = LPCIB_TCOTIMER_MAX_TICK;
593 1.1 xtraeme sc->sc_smw.smw_period = lpcib_tcotimer_tick_to_second(period);
594 1.1 xtraeme
595 1.1 xtraeme if (sysmon_wdog_register(&sc->sc_smw)) {
596 1.9 xtraeme aprint_error_dev(self, "unable to register TCO timer"
597 1.9 xtraeme "as a sysmon watchdog device.\n");
598 1.1 xtraeme return;
599 1.1 xtraeme }
600 1.1 xtraeme
601 1.9 xtraeme aprint_verbose_dev(self, "TCO (watchdog) timer configured.\n");
602 1.1 xtraeme }
603 1.1 xtraeme
604 1.19 dyoung static int
605 1.19 dyoung tcotimer_unconfigure(device_t self, int flags)
606 1.19 dyoung {
607 1.19 dyoung struct lpcib_softc *sc = device_private(self);
608 1.19 dyoung int rc;
609 1.19 dyoung
610 1.19 dyoung if ((rc = sysmon_wdog_unregister(&sc->sc_smw)) != 0) {
611 1.19 dyoung if (rc == ERESTART)
612 1.19 dyoung rc = EINTR;
613 1.19 dyoung return rc;
614 1.19 dyoung }
615 1.19 dyoung
616 1.19 dyoung /* Explicitly stop the TCO timer. */
617 1.19 dyoung tcotimer_stop(sc);
618 1.19 dyoung
619 1.19 dyoung /* XXX Set No Reboot? */
620 1.19 dyoung
621 1.19 dyoung return 0;
622 1.19 dyoung }
623 1.19 dyoung
624 1.19 dyoung
625 1.1 xtraeme /*
626 1.1 xtraeme * Sysmon watchdog callbacks.
627 1.1 xtraeme */
628 1.1 xtraeme static int
629 1.1 xtraeme tcotimer_setmode(struct sysmon_wdog *smw)
630 1.1 xtraeme {
631 1.1 xtraeme struct lpcib_softc *sc = smw->smw_cookie;
632 1.1 xtraeme unsigned int period;
633 1.1 xtraeme uint16_t ich6period = 0;
634 1.18 bouyer uint8_t ich5period = 0;
635 1.1 xtraeme
636 1.1 xtraeme if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
637 1.1 xtraeme /* Stop the TCO timer. */
638 1.1 xtraeme tcotimer_stop(sc);
639 1.1 xtraeme } else {
640 1.1 xtraeme /*
641 1.6 jmcneill * ICH6 or newer are limited to 2s min and 613s max.
642 1.1 xtraeme * ICH5 or older are limited to 4s min and 39s max.
643 1.1 xtraeme */
644 1.18 bouyer period = lpcib_tcotimer_second_to_tick(smw->smw_period);
645 1.6 jmcneill if (sc->sc_has_rcba) {
646 1.18 bouyer if (period < LPCIB_TCOTIMER2_MIN_TICK ||
647 1.18 bouyer period > LPCIB_TCOTIMER2_MAX_TICK)
648 1.6 jmcneill return EINVAL;
649 1.6 jmcneill } else {
650 1.18 bouyer if (period < LPCIB_TCOTIMER_MIN_TICK ||
651 1.18 bouyer period > LPCIB_TCOTIMER_MAX_TICK)
652 1.1 xtraeme return EINVAL;
653 1.1 xtraeme }
654 1.5 xtraeme
655 1.1 xtraeme /* Stop the TCO timer, */
656 1.1 xtraeme tcotimer_stop(sc);
657 1.1 xtraeme
658 1.1 xtraeme /* set the timeout, */
659 1.6 jmcneill if (sc->sc_has_rcba) {
660 1.1 xtraeme /* ICH6 or newer */
661 1.1 xtraeme ich6period = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
662 1.1 xtraeme LPCIB_TCO_TMR2);
663 1.1 xtraeme ich6period &= 0xfc00;
664 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh,
665 1.1 xtraeme LPCIB_TCO_TMR2, ich6period | period);
666 1.1 xtraeme } else {
667 1.1 xtraeme /* ICH5 or older */
668 1.18 bouyer ich5period = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
669 1.1 xtraeme LPCIB_TCO_TMR);
670 1.18 bouyer ich5period &= 0xc0;
671 1.1 xtraeme bus_space_write_1(sc->sc_iot, sc->sc_ioh,
672 1.18 bouyer LPCIB_TCO_TMR, ich5period | period);
673 1.1 xtraeme }
674 1.1 xtraeme
675 1.1 xtraeme /* and start/reload the timer. */
676 1.1 xtraeme tcotimer_start(sc);
677 1.1 xtraeme tcotimer_tickle(smw);
678 1.1 xtraeme }
679 1.1 xtraeme
680 1.1 xtraeme return 0;
681 1.1 xtraeme }
682 1.1 xtraeme
683 1.1 xtraeme static int
684 1.1 xtraeme tcotimer_tickle(struct sysmon_wdog *smw)
685 1.1 xtraeme {
686 1.1 xtraeme struct lpcib_softc *sc = smw->smw_cookie;
687 1.1 xtraeme
688 1.1 xtraeme /* any value is allowed */
689 1.6 jmcneill if (sc->sc_has_rcba)
690 1.6 jmcneill bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
691 1.6 jmcneill else
692 1.1 xtraeme bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_TCO_RLD, 1);
693 1.1 xtraeme
694 1.1 xtraeme return 0;
695 1.1 xtraeme }
696 1.1 xtraeme
697 1.1 xtraeme static void
698 1.1 xtraeme tcotimer_stop(struct lpcib_softc *sc)
699 1.1 xtraeme {
700 1.1 xtraeme uint16_t ioreg;
701 1.1 xtraeme
702 1.1 xtraeme ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
703 1.1 xtraeme ioreg |= LPCIB_TCO1_CNT_TCO_TMR_HLT;
704 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
705 1.1 xtraeme }
706 1.1 xtraeme
707 1.1 xtraeme static void
708 1.1 xtraeme tcotimer_start(struct lpcib_softc *sc)
709 1.1 xtraeme {
710 1.1 xtraeme uint16_t ioreg;
711 1.1 xtraeme
712 1.1 xtraeme ioreg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT);
713 1.1 xtraeme ioreg &= ~LPCIB_TCO1_CNT_TCO_TMR_HLT;
714 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_CNT, ioreg);
715 1.1 xtraeme }
716 1.1 xtraeme
717 1.1 xtraeme static void
718 1.1 xtraeme tcotimer_status_reset(struct lpcib_softc *sc)
719 1.1 xtraeme {
720 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO1_STS,
721 1.1 xtraeme LPCIB_TCO1_STS_TIMEOUT);
722 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
723 1.1 xtraeme LPCIB_TCO2_STS_BOOT_STS);
724 1.1 xtraeme bus_space_write_2(sc->sc_iot, sc->sc_ioh, LPCIB_TCO2_STS,
725 1.1 xtraeme LPCIB_TCO2_STS_SECONDS_TO_STS);
726 1.1 xtraeme }
727 1.1 xtraeme
728 1.1 xtraeme /*
729 1.4 xtraeme * Clear the No Reboot (NR) bit, this enables reboots when the timer
730 1.4 xtraeme * reaches the timeout for the second time.
731 1.1 xtraeme */
732 1.1 xtraeme static int
733 1.9 xtraeme tcotimer_disable_noreboot(device_t self)
734 1.1 xtraeme {
735 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
736 1.1 xtraeme
737 1.6 jmcneill if (sc->sc_has_rcba) {
738 1.6 jmcneill uint32_t status;
739 1.6 jmcneill
740 1.9 xtraeme status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
741 1.9 xtraeme LPCIB_GCS_OFFSET);
742 1.6 jmcneill status &= ~LPCIB_GCS_NO_REBOOT;
743 1.9 xtraeme bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah,
744 1.9 xtraeme LPCIB_GCS_OFFSET, status);
745 1.9 xtraeme status = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
746 1.9 xtraeme LPCIB_GCS_OFFSET);
747 1.6 jmcneill if (status & LPCIB_GCS_NO_REBOOT)
748 1.6 jmcneill goto error;
749 1.6 jmcneill } else {
750 1.6 jmcneill pcireg_t pcireg;
751 1.6 jmcneill
752 1.12 martin pcireg = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
753 1.1 xtraeme LPCIB_PCI_GEN_STA);
754 1.1 xtraeme if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT) {
755 1.1 xtraeme /* TCO timeout reset is disabled; try to enable it */
756 1.1 xtraeme pcireg &= ~LPCIB_PCI_GEN_STA_NO_REBOOT;
757 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
758 1.1 xtraeme LPCIB_PCI_GEN_STA, pcireg);
759 1.1 xtraeme if (pcireg & LPCIB_PCI_GEN_STA_NO_REBOOT)
760 1.1 xtraeme goto error;
761 1.1 xtraeme }
762 1.1 xtraeme }
763 1.1 xtraeme
764 1.1 xtraeme return 0;
765 1.1 xtraeme error:
766 1.9 xtraeme aprint_error_dev(self, "TCO timer reboot disabled by hardware; "
767 1.9 xtraeme "hope SMBIOS properly handles it.\n");
768 1.1 xtraeme return EINVAL;
769 1.1 xtraeme }
770 1.1 xtraeme
771 1.1 xtraeme
772 1.1 xtraeme /*
773 1.1 xtraeme * Intel ICH SpeedStep support.
774 1.1 xtraeme */
775 1.1 xtraeme #define SS_READ(sc, reg) \
776 1.1 xtraeme bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (reg))
777 1.1 xtraeme #define SS_WRITE(sc, reg, val) \
778 1.1 xtraeme bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
779 1.1 xtraeme
780 1.1 xtraeme /*
781 1.1 xtraeme * Linux driver says that SpeedStep on older chipsets cause
782 1.1 xtraeme * lockups on Dell Inspiron 8000 and 8100.
783 1.15 mrg * It should also not be enabled on systems with the 82855GM
784 1.15 mrg * Hub, which typically have an EST-enabled CPU.
785 1.1 xtraeme */
786 1.1 xtraeme static int
787 1.29 dyoung speedstep_bad_hb_check(const struct pci_attach_args *pa)
788 1.1 xtraeme {
789 1.1 xtraeme
790 1.1 xtraeme if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82815_FULL_HUB &&
791 1.1 xtraeme PCI_REVISION(pa->pa_class) < 5)
792 1.1 xtraeme return 1;
793 1.1 xtraeme
794 1.15 mrg if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82855GM_MCH)
795 1.15 mrg return 1;
796 1.15 mrg
797 1.1 xtraeme return 0;
798 1.1 xtraeme }
799 1.1 xtraeme
800 1.1 xtraeme static void
801 1.9 xtraeme speedstep_configure(device_t self)
802 1.1 xtraeme {
803 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
804 1.1 xtraeme const struct sysctlnode *node, *ssnode;
805 1.1 xtraeme int rv;
806 1.1 xtraeme
807 1.1 xtraeme /* Supported on ICH2-M, ICH3-M and ICH4-M. */
808 1.6 jmcneill if (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801DB_ISA ||
809 1.6 jmcneill PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801CAM_LPC ||
810 1.6 jmcneill (PCI_PRODUCT(sc->sc_pa.pa_id) == PCI_PRODUCT_INTEL_82801BAM_LPC &&
811 1.6 jmcneill pci_find_device(&sc->sc_pa, speedstep_bad_hb_check) == 0)) {
812 1.19 dyoung pcireg_t pmcon;
813 1.1 xtraeme
814 1.1 xtraeme /* Enable SpeedStep if it isn't already enabled. */
815 1.12 martin pmcon = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
816 1.1 xtraeme LPCIB_PCI_GEN_PMCON_1);
817 1.1 xtraeme if ((pmcon & LPCIB_PCI_GEN_PMCON_1_SS_EN) == 0)
818 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
819 1.1 xtraeme LPCIB_PCI_GEN_PMCON_1,
820 1.1 xtraeme pmcon | LPCIB_PCI_GEN_PMCON_1_SS_EN);
821 1.1 xtraeme
822 1.1 xtraeme /* Put in machdep.speedstep_state (0 for low, 1 for high). */
823 1.19 dyoung if ((rv = sysctl_createv(&sc->sc_log, 0, NULL, &node,
824 1.1 xtraeme CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
825 1.1 xtraeme NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
826 1.1 xtraeme goto err;
827 1.1 xtraeme
828 1.1 xtraeme /* CTLFLAG_ANYWRITE? kernel option like EST? */
829 1.19 dyoung if ((rv = sysctl_createv(&sc->sc_log, 0, &node, &ssnode,
830 1.1 xtraeme CTLFLAG_READWRITE, CTLTYPE_INT, "speedstep_state", NULL,
831 1.1 xtraeme speedstep_sysctl_helper, 0, NULL, 0, CTL_CREATE,
832 1.1 xtraeme CTL_EOL)) != 0)
833 1.1 xtraeme goto err;
834 1.1 xtraeme
835 1.1 xtraeme /* XXX save the sc for IO tag/handle */
836 1.1 xtraeme speedstep_cookie = sc;
837 1.9 xtraeme aprint_verbose_dev(self, "SpeedStep enabled\n");
838 1.1 xtraeme }
839 1.1 xtraeme
840 1.1 xtraeme return;
841 1.1 xtraeme
842 1.1 xtraeme err:
843 1.1 xtraeme aprint_normal("%s: sysctl_createv failed (rv = %d)\n", __func__, rv);
844 1.1 xtraeme }
845 1.1 xtraeme
846 1.19 dyoung static void
847 1.19 dyoung speedstep_unconfigure(device_t self)
848 1.19 dyoung {
849 1.19 dyoung struct lpcib_softc *sc = device_private(self);
850 1.19 dyoung
851 1.19 dyoung sysctl_teardown(&sc->sc_log);
852 1.19 dyoung pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
853 1.19 dyoung LPCIB_PCI_GEN_PMCON_1, sc->sc_pmcon_orig);
854 1.19 dyoung
855 1.19 dyoung speedstep_cookie = NULL;
856 1.19 dyoung }
857 1.19 dyoung
858 1.1 xtraeme /*
859 1.1 xtraeme * get/set the SpeedStep state: 0 == low power, 1 == high power.
860 1.1 xtraeme */
861 1.1 xtraeme static int
862 1.1 xtraeme speedstep_sysctl_helper(SYSCTLFN_ARGS)
863 1.1 xtraeme {
864 1.1 xtraeme struct sysctlnode node;
865 1.1 xtraeme struct lpcib_softc *sc = speedstep_cookie;
866 1.1 xtraeme uint8_t state, state2;
867 1.1 xtraeme int ostate, nstate, s, error = 0;
868 1.1 xtraeme
869 1.1 xtraeme /*
870 1.1 xtraeme * We do the dance with spl's to avoid being at high ipl during
871 1.1 xtraeme * sysctl_lookup() which can both copyin and copyout.
872 1.1 xtraeme */
873 1.1 xtraeme s = splserial();
874 1.1 xtraeme state = SS_READ(sc, LPCIB_PM_SS_CNTL);
875 1.1 xtraeme splx(s);
876 1.1 xtraeme if ((state & LPCIB_PM_SS_STATE_LOW) == 0)
877 1.1 xtraeme ostate = 1;
878 1.1 xtraeme else
879 1.1 xtraeme ostate = 0;
880 1.1 xtraeme nstate = ostate;
881 1.1 xtraeme
882 1.1 xtraeme node = *rnode;
883 1.1 xtraeme node.sysctl_data = &nstate;
884 1.1 xtraeme
885 1.1 xtraeme error = sysctl_lookup(SYSCTLFN_CALL(&node));
886 1.1 xtraeme if (error || newp == NULL)
887 1.1 xtraeme goto out;
888 1.1 xtraeme
889 1.1 xtraeme /* Only two states are available */
890 1.1 xtraeme if (nstate != 0 && nstate != 1) {
891 1.1 xtraeme error = EINVAL;
892 1.1 xtraeme goto out;
893 1.1 xtraeme }
894 1.1 xtraeme
895 1.1 xtraeme s = splserial();
896 1.1 xtraeme state2 = SS_READ(sc, LPCIB_PM_SS_CNTL);
897 1.1 xtraeme if ((state2 & LPCIB_PM_SS_STATE_LOW) == 0)
898 1.1 xtraeme ostate = 1;
899 1.1 xtraeme else
900 1.1 xtraeme ostate = 0;
901 1.1 xtraeme
902 1.1 xtraeme if (ostate != nstate) {
903 1.1 xtraeme uint8_t cntl;
904 1.1 xtraeme
905 1.1 xtraeme if (nstate == 0)
906 1.1 xtraeme state2 |= LPCIB_PM_SS_STATE_LOW;
907 1.1 xtraeme else
908 1.1 xtraeme state2 &= ~LPCIB_PM_SS_STATE_LOW;
909 1.1 xtraeme
910 1.1 xtraeme /*
911 1.1 xtraeme * Must disable bus master arbitration during the change.
912 1.1 xtraeme */
913 1.1 xtraeme cntl = SS_READ(sc, LPCIB_PM_CTRL);
914 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_CTRL, cntl | LPCIB_PM_SS_CNTL_ARB_DIS);
915 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_SS_CNTL, state2);
916 1.1 xtraeme SS_WRITE(sc, LPCIB_PM_CTRL, cntl);
917 1.1 xtraeme }
918 1.1 xtraeme splx(s);
919 1.1 xtraeme out:
920 1.1 xtraeme return error;
921 1.1 xtraeme }
922 1.6 jmcneill
923 1.6 jmcneill #if NHPET > 0
924 1.6 jmcneill struct lpcib_hpet_attach_arg {
925 1.6 jmcneill bus_space_tag_t hpet_mem_t;
926 1.6 jmcneill uint32_t hpet_reg;
927 1.6 jmcneill };
928 1.6 jmcneill
929 1.6 jmcneill static int
930 1.9 xtraeme lpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
931 1.6 jmcneill {
932 1.6 jmcneill struct lpcib_hpet_attach_arg *arg = aux;
933 1.6 jmcneill bus_space_tag_t tag;
934 1.6 jmcneill bus_space_handle_t handle;
935 1.6 jmcneill
936 1.6 jmcneill tag = arg->hpet_mem_t;
937 1.6 jmcneill
938 1.6 jmcneill if (bus_space_map(tag, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &handle)) {
939 1.10 cegger aprint_verbose_dev(parent, "HPET window not mapped, skipping\n");
940 1.6 jmcneill return 0;
941 1.6 jmcneill }
942 1.6 jmcneill bus_space_unmap(tag, handle, HPET_WINDOW_SIZE);
943 1.6 jmcneill
944 1.6 jmcneill return 1;
945 1.6 jmcneill }
946 1.6 jmcneill
947 1.19 dyoung static int
948 1.19 dyoung lpcib_hpet_detach(device_t self, int flags)
949 1.19 dyoung {
950 1.19 dyoung struct hpet_softc *sc = device_private(self);
951 1.19 dyoung int rc;
952 1.19 dyoung
953 1.19 dyoung if ((rc = hpet_detach(self, flags)) != 0)
954 1.19 dyoung return rc;
955 1.19 dyoung
956 1.19 dyoung bus_space_unmap(sc->sc_memt, sc->sc_memh, HPET_WINDOW_SIZE);
957 1.19 dyoung
958 1.19 dyoung return 0;
959 1.19 dyoung }
960 1.19 dyoung
961 1.6 jmcneill static void
962 1.6 jmcneill lpcib_hpet_attach(device_t parent, device_t self, void *aux)
963 1.6 jmcneill {
964 1.6 jmcneill struct hpet_softc *sc = device_private(self);
965 1.6 jmcneill struct lpcib_hpet_attach_arg *arg = aux;
966 1.6 jmcneill
967 1.6 jmcneill aprint_naive("\n");
968 1.6 jmcneill aprint_normal("\n");
969 1.6 jmcneill
970 1.6 jmcneill sc->sc_memt = arg->hpet_mem_t;
971 1.6 jmcneill
972 1.6 jmcneill if (bus_space_map(sc->sc_memt, arg->hpet_reg, HPET_WINDOW_SIZE, 0,
973 1.6 jmcneill &sc->sc_memh)) {
974 1.9 xtraeme aprint_error_dev(self,
975 1.9 xtraeme "HPET memory window could not be mapped");
976 1.6 jmcneill return;
977 1.6 jmcneill }
978 1.6 jmcneill
979 1.9 xtraeme hpet_attach_subr(self);
980 1.6 jmcneill }
981 1.6 jmcneill
982 1.9 xtraeme CFATTACH_DECL_NEW(ichlpcib_hpet, sizeof(struct hpet_softc), lpcib_hpet_match,
983 1.19 dyoung lpcib_hpet_attach, lpcib_hpet_detach, NULL);
984 1.6 jmcneill
985 1.6 jmcneill static void
986 1.9 xtraeme lpcib_hpet_configure(device_t self)
987 1.6 jmcneill {
988 1.9 xtraeme struct lpcib_softc *sc = device_private(self);
989 1.6 jmcneill struct lpcib_hpet_attach_arg arg;
990 1.6 jmcneill uint32_t hpet_reg, val;
991 1.6 jmcneill
992 1.6 jmcneill if (sc->sc_has_ich5_hpet) {
993 1.12 martin val = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
994 1.9 xtraeme LPCIB_PCI_GEN_CNTL);
995 1.6 jmcneill switch (val & LPCIB_ICH5_HPTC_WIN_MASK) {
996 1.6 jmcneill case LPCIB_ICH5_HPTC_0000:
997 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_0000_BASE;
998 1.6 jmcneill break;
999 1.6 jmcneill case LPCIB_ICH5_HPTC_1000:
1000 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_1000_BASE;
1001 1.6 jmcneill break;
1002 1.6 jmcneill case LPCIB_ICH5_HPTC_2000:
1003 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_2000_BASE;
1004 1.6 jmcneill break;
1005 1.6 jmcneill case LPCIB_ICH5_HPTC_3000:
1006 1.6 jmcneill hpet_reg = LPCIB_ICH5_HPTC_3000_BASE;
1007 1.6 jmcneill break;
1008 1.6 jmcneill default:
1009 1.6 jmcneill return;
1010 1.6 jmcneill }
1011 1.6 jmcneill val |= sc->sc_hpet_reg | LPCIB_ICH5_HPTC_EN;
1012 1.12 martin pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
1013 1.9 xtraeme LPCIB_PCI_GEN_CNTL, val);
1014 1.6 jmcneill } else if (sc->sc_has_rcba) {
1015 1.6 jmcneill val = bus_space_read_4(sc->sc_rcbat, sc->sc_rcbah,
1016 1.6 jmcneill LPCIB_RCBA_HPTC);
1017 1.6 jmcneill switch (val & LPCIB_RCBA_HPTC_WIN_MASK) {
1018 1.6 jmcneill case LPCIB_RCBA_HPTC_0000:
1019 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_0000_BASE;
1020 1.6 jmcneill break;
1021 1.6 jmcneill case LPCIB_RCBA_HPTC_1000:
1022 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_1000_BASE;
1023 1.6 jmcneill break;
1024 1.6 jmcneill case LPCIB_RCBA_HPTC_2000:
1025 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_2000_BASE;
1026 1.6 jmcneill break;
1027 1.6 jmcneill case LPCIB_RCBA_HPTC_3000:
1028 1.6 jmcneill hpet_reg = LPCIB_RCBA_HPTC_3000_BASE;
1029 1.6 jmcneill break;
1030 1.6 jmcneill default:
1031 1.6 jmcneill return;
1032 1.6 jmcneill }
1033 1.6 jmcneill val |= LPCIB_RCBA_HPTC_EN;
1034 1.6 jmcneill bus_space_write_4(sc->sc_rcbat, sc->sc_rcbah, LPCIB_RCBA_HPTC,
1035 1.6 jmcneill val);
1036 1.6 jmcneill } else {
1037 1.6 jmcneill /* No HPET here */
1038 1.6 jmcneill return;
1039 1.6 jmcneill }
1040 1.6 jmcneill
1041 1.6 jmcneill arg.hpet_mem_t = sc->sc_pa.pa_memt;
1042 1.6 jmcneill arg.hpet_reg = hpet_reg;
1043 1.6 jmcneill
1044 1.19 dyoung sc->sc_hpetbus = config_found_ia(self, "hpetichbus", &arg, NULL);
1045 1.19 dyoung }
1046 1.19 dyoung
1047 1.19 dyoung static int
1048 1.19 dyoung lpcib_hpet_unconfigure(device_t self, int flags)
1049 1.19 dyoung {
1050 1.19 dyoung struct lpcib_softc *sc = device_private(self);
1051 1.19 dyoung int rc;
1052 1.19 dyoung
1053 1.19 dyoung if (sc->sc_hpetbus != NULL &&
1054 1.19 dyoung (rc = config_detach(sc->sc_hpetbus, flags)) != 0)
1055 1.19 dyoung return rc;
1056 1.19 dyoung
1057 1.19 dyoung return 0;
1058 1.6 jmcneill }
1059 1.6 jmcneill #endif
1060 1.20 jakllsch
1061 1.20 jakllsch #if NGPIO > 0
1062 1.20 jakllsch static void
1063 1.20 jakllsch lpcib_gpio_configure(device_t self)
1064 1.20 jakllsch {
1065 1.20 jakllsch struct lpcib_softc *sc = device_private(self);
1066 1.20 jakllsch struct gpiobus_attach_args gba;
1067 1.20 jakllsch pcireg_t gpio_cntl;
1068 1.20 jakllsch uint32_t use, io, bit;
1069 1.20 jakllsch int pin, shift, base_reg, cntl_reg, reg;
1070 1.20 jakllsch
1071 1.20 jakllsch /* this implies ICH >= 6, and thus different mapreg */
1072 1.20 jakllsch if (sc->sc_has_rcba) {
1073 1.20 jakllsch base_reg = LPCIB_PCI_GPIO_BASE_ICH6;
1074 1.20 jakllsch cntl_reg = LPCIB_PCI_GPIO_CNTL_ICH6;
1075 1.20 jakllsch } else {
1076 1.20 jakllsch base_reg = LPCIB_PCI_GPIO_BASE;
1077 1.20 jakllsch cntl_reg = LPCIB_PCI_GPIO_CNTL;
1078 1.20 jakllsch }
1079 1.20 jakllsch
1080 1.20 jakllsch gpio_cntl = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
1081 1.20 jakllsch cntl_reg);
1082 1.20 jakllsch
1083 1.20 jakllsch /* Is GPIO enabled? */
1084 1.20 jakllsch if ((gpio_cntl & LPCIB_PCI_GPIO_CNTL_EN) == 0)
1085 1.20 jakllsch return;
1086 1.20 jakllsch
1087 1.20 jakllsch if (pci_mapreg_map(&sc->sc_pa, base_reg, PCI_MAPREG_TYPE_IO, 0,
1088 1.20 jakllsch &sc->sc_gpio_iot, &sc->sc_gpio_ioh,
1089 1.20 jakllsch NULL, &sc->sc_gpio_ios)) {
1090 1.20 jakllsch aprint_error_dev(self, "can't map general purpose i/o space\n");
1091 1.20 jakllsch return;
1092 1.20 jakllsch }
1093 1.20 jakllsch
1094 1.20 jakllsch mutex_init(&sc->sc_gpio_mtx, MUTEX_DEFAULT, IPL_NONE);
1095 1.20 jakllsch
1096 1.20 jakllsch for (pin = 0; pin < LPCIB_GPIO_NPINS; pin++) {
1097 1.20 jakllsch sc->sc_gpio_pins[pin].pin_num = pin;
1098 1.20 jakllsch
1099 1.20 jakllsch /* Read initial state */
1100 1.20 jakllsch reg = (pin < 32) ? LPCIB_GPIO_GPIO_USE_SEL : LPCIB_GPIO_GPIO_USE_SEL2;
1101 1.20 jakllsch use = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg);
1102 1.20 jakllsch reg = (pin < 32) ? LPCIB_GPIO_GP_IO_SEL : LPCIB_GPIO_GP_IO_SEL;
1103 1.20 jakllsch io = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, 4);
1104 1.20 jakllsch shift = pin % 32;
1105 1.20 jakllsch bit = __BIT(shift);
1106 1.20 jakllsch
1107 1.20 jakllsch if ((use & bit) != 0) {
1108 1.20 jakllsch sc->sc_gpio_pins[pin].pin_caps =
1109 1.20 jakllsch GPIO_PIN_INPUT | GPIO_PIN_OUTPUT;
1110 1.20 jakllsch if (pin < 32)
1111 1.20 jakllsch sc->sc_gpio_pins[pin].pin_caps |=
1112 1.20 jakllsch GPIO_PIN_PULSATE;
1113 1.20 jakllsch if ((io & bit) != 0)
1114 1.20 jakllsch sc->sc_gpio_pins[pin].pin_flags =
1115 1.20 jakllsch GPIO_PIN_INPUT;
1116 1.20 jakllsch else
1117 1.20 jakllsch sc->sc_gpio_pins[pin].pin_flags =
1118 1.20 jakllsch GPIO_PIN_OUTPUT;
1119 1.20 jakllsch } else
1120 1.20 jakllsch sc->sc_gpio_pins[pin].pin_caps = 0;
1121 1.20 jakllsch
1122 1.20 jakllsch if (lpcib_gpio_pin_read(sc, pin) == 0)
1123 1.20 jakllsch sc->sc_gpio_pins[pin].pin_state = GPIO_PIN_LOW;
1124 1.20 jakllsch else
1125 1.20 jakllsch sc->sc_gpio_pins[pin].pin_state = GPIO_PIN_HIGH;
1126 1.20 jakllsch
1127 1.20 jakllsch }
1128 1.20 jakllsch
1129 1.20 jakllsch /* Create controller tag */
1130 1.20 jakllsch sc->sc_gpio_gc.gp_cookie = sc;
1131 1.20 jakllsch sc->sc_gpio_gc.gp_pin_read = lpcib_gpio_pin_read;
1132 1.20 jakllsch sc->sc_gpio_gc.gp_pin_write = lpcib_gpio_pin_write;
1133 1.20 jakllsch sc->sc_gpio_gc.gp_pin_ctl = lpcib_gpio_pin_ctl;
1134 1.20 jakllsch
1135 1.20 jakllsch memset(&gba, 0, sizeof(gba));
1136 1.20 jakllsch
1137 1.20 jakllsch gba.gba_gc = &sc->sc_gpio_gc;
1138 1.20 jakllsch gba.gba_pins = sc->sc_gpio_pins;
1139 1.20 jakllsch gba.gba_npins = LPCIB_GPIO_NPINS;
1140 1.20 jakllsch
1141 1.20 jakllsch sc->sc_gpiobus = config_found_ia(self, "gpiobus", &gba, gpiobus_print);
1142 1.20 jakllsch }
1143 1.20 jakllsch
1144 1.20 jakllsch static int
1145 1.20 jakllsch lpcib_gpio_unconfigure(device_t self, int flags)
1146 1.20 jakllsch {
1147 1.20 jakllsch struct lpcib_softc *sc = device_private(self);
1148 1.20 jakllsch int rc;
1149 1.20 jakllsch
1150 1.20 jakllsch if (sc->sc_gpiobus != NULL &&
1151 1.20 jakllsch (rc = config_detach(sc->sc_gpiobus, flags)) != 0)
1152 1.20 jakllsch return rc;
1153 1.20 jakllsch
1154 1.20 jakllsch mutex_destroy(&sc->sc_gpio_mtx);
1155 1.20 jakllsch
1156 1.20 jakllsch bus_space_unmap(sc->sc_gpio_iot, sc->sc_gpio_ioh, sc->sc_gpio_ios);
1157 1.20 jakllsch
1158 1.20 jakllsch return 0;
1159 1.20 jakllsch }
1160 1.20 jakllsch
1161 1.20 jakllsch static int
1162 1.20 jakllsch lpcib_gpio_pin_read(void *arg, int pin)
1163 1.20 jakllsch {
1164 1.20 jakllsch struct lpcib_softc *sc = arg;
1165 1.20 jakllsch uint32_t data;
1166 1.20 jakllsch int reg, shift;
1167 1.20 jakllsch
1168 1.20 jakllsch reg = (pin < 32) ? LPCIB_GPIO_GP_LVL : LPCIB_GPIO_GP_LVL2;
1169 1.20 jakllsch shift = pin % 32;
1170 1.20 jakllsch
1171 1.20 jakllsch mutex_enter(&sc->sc_gpio_mtx);
1172 1.20 jakllsch data = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg);
1173 1.20 jakllsch mutex_exit(&sc->sc_gpio_mtx);
1174 1.20 jakllsch
1175 1.20 jakllsch return (__SHIFTOUT(data, __BIT(shift)) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
1176 1.20 jakllsch }
1177 1.20 jakllsch
1178 1.20 jakllsch static void
1179 1.20 jakllsch lpcib_gpio_pin_write(void *arg, int pin, int value)
1180 1.20 jakllsch {
1181 1.20 jakllsch struct lpcib_softc *sc = arg;
1182 1.20 jakllsch uint32_t data;
1183 1.20 jakllsch int reg, shift;
1184 1.20 jakllsch
1185 1.20 jakllsch reg = (pin < 32) ? LPCIB_GPIO_GP_LVL : LPCIB_GPIO_GP_LVL2;
1186 1.20 jakllsch shift = pin % 32;
1187 1.20 jakllsch
1188 1.20 jakllsch mutex_enter(&sc->sc_gpio_mtx);
1189 1.20 jakllsch
1190 1.20 jakllsch data = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg);
1191 1.20 jakllsch
1192 1.20 jakllsch if(value)
1193 1.20 jakllsch data |= __BIT(shift);
1194 1.20 jakllsch else
1195 1.20 jakllsch data &= ~__BIT(shift);
1196 1.20 jakllsch
1197 1.20 jakllsch bus_space_write_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg, data);
1198 1.20 jakllsch
1199 1.20 jakllsch mutex_exit(&sc->sc_gpio_mtx);
1200 1.20 jakllsch }
1201 1.20 jakllsch
1202 1.20 jakllsch static void
1203 1.20 jakllsch lpcib_gpio_pin_ctl(void *arg, int pin, int flags)
1204 1.20 jakllsch {
1205 1.20 jakllsch struct lpcib_softc *sc = arg;
1206 1.20 jakllsch uint32_t data;
1207 1.20 jakllsch int reg, shift;
1208 1.20 jakllsch
1209 1.20 jakllsch shift = pin % 32;
1210 1.20 jakllsch reg = (pin < 32) ? LPCIB_GPIO_GP_IO_SEL : LPCIB_GPIO_GP_IO_SEL2;
1211 1.20 jakllsch
1212 1.20 jakllsch mutex_enter(&sc->sc_gpio_mtx);
1213 1.20 jakllsch
1214 1.20 jakllsch data = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg);
1215 1.20 jakllsch
1216 1.20 jakllsch if (flags & GPIO_PIN_OUTPUT)
1217 1.20 jakllsch data &= ~__BIT(shift);
1218 1.20 jakllsch
1219 1.20 jakllsch if (flags & GPIO_PIN_INPUT)
1220 1.20 jakllsch data |= __BIT(shift);
1221 1.20 jakllsch
1222 1.20 jakllsch bus_space_write_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg, data);
1223 1.20 jakllsch
1224 1.20 jakllsch
1225 1.20 jakllsch if (pin < 32) {
1226 1.20 jakllsch reg = LPCIB_GPIO_GPO_BLINK;
1227 1.20 jakllsch data = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg);
1228 1.20 jakllsch
1229 1.20 jakllsch if (flags & GPIO_PIN_PULSATE)
1230 1.20 jakllsch data |= __BIT(shift);
1231 1.20 jakllsch else
1232 1.20 jakllsch data &= ~__BIT(shift);
1233 1.20 jakllsch
1234 1.20 jakllsch bus_space_write_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, reg, data);
1235 1.20 jakllsch }
1236 1.20 jakllsch
1237 1.20 jakllsch mutex_exit(&sc->sc_gpio_mtx);
1238 1.20 jakllsch }
1239 1.20 jakllsch #endif
1240 1.25 jakllsch
1241 1.25 jakllsch #if NFWHRNG > 0
1242 1.25 jakllsch static void
1243 1.25 jakllsch lpcib_fwh_configure(device_t self)
1244 1.25 jakllsch {
1245 1.26 jakllsch struct lpcib_softc *sc;
1246 1.26 jakllsch pcireg_t pr;
1247 1.25 jakllsch
1248 1.26 jakllsch sc = device_private(self);
1249 1.25 jakllsch
1250 1.25 jakllsch if (sc->sc_has_rcba) {
1251 1.25 jakllsch /*
1252 1.25 jakllsch * Very unlikely to find a 82802 on a ICH6 or newer.
1253 1.25 jakllsch * Also the write enable register moved at that point.
1254 1.25 jakllsch */
1255 1.25 jakllsch return;
1256 1.25 jakllsch } else {
1257 1.25 jakllsch /* Enable FWH write to identify FWH. */
1258 1.25 jakllsch pr = pci_conf_read(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
1259 1.26 jakllsch LPCIB_PCI_BIOS_CNTL);
1260 1.25 jakllsch pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
1261 1.26 jakllsch LPCIB_PCI_BIOS_CNTL, pr|LPCIB_PCI_BIOS_CNTL_BWE);
1262 1.25 jakllsch }
1263 1.25 jakllsch
1264 1.25 jakllsch sc->sc_fwhbus = config_found_ia(self, "fwhichbus", NULL, NULL);
1265 1.25 jakllsch
1266 1.26 jakllsch /* restore previous write enable setting */
1267 1.26 jakllsch pci_conf_write(sc->sc_pcib.sc_pc, sc->sc_pcib.sc_tag,
1268 1.26 jakllsch LPCIB_PCI_BIOS_CNTL, pr);
1269 1.25 jakllsch }
1270 1.25 jakllsch
1271 1.25 jakllsch static int
1272 1.25 jakllsch lpcib_fwh_unconfigure(device_t self, int flags)
1273 1.25 jakllsch {
1274 1.25 jakllsch struct lpcib_softc *sc = device_private(self);
1275 1.25 jakllsch int rc;
1276 1.25 jakllsch
1277 1.25 jakllsch if (sc->sc_fwhbus != NULL &&
1278 1.25 jakllsch (rc = config_detach(sc->sc_fwhbus, flags)) != 0)
1279 1.25 jakllsch return rc;
1280 1.25 jakllsch
1281 1.25 jakllsch return 0;
1282 1.25 jakllsch }
1283 1.25 jakllsch #endif
1284