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