1 /* $NetBSD: wbsio.c,v 1.1 2010/02/21 05:16:29 cnst Exp $ */
2 /* $OpenBSD: wbsio.c,v 1.5 2009/03/29 21:53:52 sthen Exp $ */
4 * Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * Winbond LPC Super I/O driver.
23 #include <sys/param.h>
24 #include <sys/device.h>
25 #include <sys/kernel.h>
26 #include <sys/systm.h>
28 #include <machine/bus.h>
30 #include <dev/isa/isareg.h>
31 #include <dev/isa/isavar.h>
33 /* ISA bus registers */
34 #define WBSIO_INDEX 0x00 /* Configuration Index Register */
35 #define WBSIO_DATA 0x01 /* Configuration Data Register */
37 #define WBSIO_IOSIZE 0x02 /* ISA I/O space size */
39 #define WBSIO_CONF_EN_MAGIC 0x87 /* enable configuration mode */
40 #define WBSIO_CONF_DS_MAGIC 0xaa /* disable configuration mode */
42 /* Configuration Space Registers */
43 #define WBSIO_LDN 0x07 /* Logical Device Number */
44 #define WBSIO_ID 0x20 /* Device ID */
45 #define WBSIO_REV 0x21 /* Device Revision */
47 #define WBSIO_ID_W83627HF 0x52
48 #define WBSIO_ID_W83627THF 0x82
49 #define WBSIO_ID_W83627EHF 0x88
50 #define WBSIO_ID_W83627DHG 0xa0
51 #define WBSIO_ID_W83627SF 0x59
52 #define WBSIO_ID_W83637HF 0x70
53 #define WBSIO_ID_W83697HF 0x60
55 /* Logical Device Number (LDN) Assignments */
56 #define WBSIO_LDN_HM 0x0b
58 /* Hardware Monitor Control Registers (LDN B) */
59 #define WBSIO_HM_ADDR_MSB 0x60 /* Address [15:8] */
60 #define WBSIO_HM_ADDR_LSB 0x61 /* Address [7:0] */
65 bus_space_tag_t sc_iot;
66 bus_space_handle_t sc_ioh;
69 int wbsio_probe(device_t, cfdata_t, void *);
70 void wbsio_attach(device_t, device_t, void *);
71 int wbsio_print(void *, const char *);
73 CFATTACH_DECL_NEW(wbsio, sizeof(struct wbsio_softc),
74 wbsio_probe, wbsio_attach, NULL, NULL);
77 wbsio_conf_enable(bus_space_tag_t iot, bus_space_handle_t ioh)
79 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
80 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
84 wbsio_conf_disable(bus_space_tag_t iot, bus_space_handle_t ioh)
86 bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_DS_MAGIC);
89 static __inline u_int8_t
90 wbsio_conf_read(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t index)
92 bus_space_write_1(iot, ioh, WBSIO_INDEX, index);
93 return (bus_space_read_1(iot, ioh, WBSIO_DATA));
97 wbsio_conf_write(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t index,
100 bus_space_write_1(iot, ioh, WBSIO_INDEX, index);
101 bus_space_write_1(iot, ioh, WBSIO_DATA, data);
105 wbsio_probe(device_t parent, cfdata_t match, void *aux)
107 struct isa_attach_args *ia = aux;
109 bus_space_handle_t ioh;
112 /* Must supply an address */
116 if (ISA_DIRECT_CONFIG(ia))
119 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
122 /* Match by device ID */
124 if (bus_space_map(iot, ia->ia_io[0].ir_addr, WBSIO_IOSIZE, 0, &ioh))
126 wbsio_conf_enable(iot, ioh);
127 reg = wbsio_conf_read(iot, ioh, WBSIO_ID);
128 aprint_debug("wbsio_probe: id 0x%02x\n", reg);
129 wbsio_conf_disable(iot, ioh);
130 bus_space_unmap(iot, ioh, WBSIO_IOSIZE);
132 case WBSIO_ID_W83627HF:
133 case WBSIO_ID_W83627THF:
134 case WBSIO_ID_W83627EHF:
135 case WBSIO_ID_W83627DHG:
136 case WBSIO_ID_W83637HF:
137 case WBSIO_ID_W83697HF:
139 ia->ia_io[0].ir_size = WBSIO_IOSIZE;
150 wbsio_attach(device_t parent, device_t self, void *aux)
152 struct wbsio_softc *sc = (void *)self;
153 struct isa_attach_args *ia = aux;
154 struct isa_attach_args nia;
155 const char *desc = NULL;
156 u_int8_t reg, reg0, reg1;
159 /* Map ISA I/O space */
160 sc->sc_iot = ia->ia_iot;
161 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
162 WBSIO_IOSIZE, 0, &sc->sc_ioh)) {
163 aprint_error(": can't map i/o space\n");
167 /* Enter configuration mode */
168 wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
171 reg = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID);
173 case WBSIO_ID_W83627HF:
176 case WBSIO_ID_W83627THF:
179 case WBSIO_ID_W83627EHF:
182 case WBSIO_ID_W83627DHG:
185 case WBSIO_ID_W83637HF:
188 case WBSIO_ID_W83697HF:
193 /* Read device revision */
194 reg = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV);
197 aprint_normal(": Winbond LPC Super I/O %s rev 0x%02x\n", desc, reg);
199 /* Select HM logical device */
200 wbsio_conf_write(sc->sc_iot, sc->sc_ioh, WBSIO_LDN, WBSIO_LDN_HM);
203 * The address should be 8-byte aligned, but it seems some
204 * BIOSes ignore this. They get away with it, because
205 * Apparently the hardware simply ignores the lower three
206 * bits. We do the same here.
208 reg0 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_LSB);
209 reg1 = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_HM_ADDR_MSB);
210 iobase = (reg1 << 8) | (reg0 & ~0x7);
212 /* Escape from configuration mode */
213 wbsio_conf_disable(sc->sc_iot, sc->sc_ioh);
219 nia.ia_io[0].ir_addr = iobase;
220 config_found(self, &nia, wbsio_print);
224 wbsio_print(void *aux, const char *pnp)
226 struct isa_attach_args *ia = aux;
229 aprint_normal("%s", pnp);
230 if (ia->ia_io[0].ir_size)
231 aprint_normal(" port 0x%x", ia->ia_io[0].ir_addr);
232 if (ia->ia_io[0].ir_size > 1)
233 aprint_normal("-0x%x", ia->ia_io[0].ir_addr +
234 ia->ia_io[0].ir_size - 1);