| @@ -1,34 +1,34 @@ | | | @@ -1,34 +1,34 @@ |
1 | /* $NetBSD: gpioow.c,v 1.10 2009/08/07 08:15:52 mbalmer Exp $ */ | | 1 | /* $NetBSD: gpioow.c,v 1.11 2009/08/08 10:38:17 mbalmer Exp $ */ |
2 | /* $OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ | | 2 | /* $OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org> | | 5 | * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org> |
6 | * | | 6 | * |
7 | * Permission to use, copy, modify, and distribute this software for any | | 7 | * Permission to use, copy, modify, and distribute this software for any |
8 | * purpose with or without fee is hereby granted, provided that the above | | 8 | * purpose with or without fee is hereby granted, provided that the above |
9 | * copyright notice and this permission notice appear in all copies. | | 9 | * copyright notice and this permission notice appear in all copies. |
10 | * | | 10 | * |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | | 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | | 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | | 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
18 | */ | | 18 | */ |
19 | | | 19 | |
20 | #include <sys/cdefs.h> | | 20 | #include <sys/cdefs.h> |
21 | __KERNEL_RCSID(0, "$NetBSD: gpioow.c,v 1.10 2009/08/07 08:15:52 mbalmer Exp $"); | | 21 | __KERNEL_RCSID(0, "$NetBSD: gpioow.c,v 1.11 2009/08/08 10:38:17 mbalmer Exp $"); |
22 | | | 22 | |
23 | /* | | 23 | /* |
24 | * 1-Wire bus bit-banging through GPIO pin. | | 24 | * 1-Wire bus bit-banging through GPIO pin. |
25 | */ | | 25 | */ |
26 | | | 26 | |
27 | #include <sys/param.h> | | 27 | #include <sys/param.h> |
28 | #include <sys/systm.h> | | 28 | #include <sys/systm.h> |
29 | #include <sys/device.h> | | 29 | #include <sys/device.h> |
30 | #include <sys/gpio.h> | | 30 | #include <sys/gpio.h> |
31 | | | 31 | |
32 | #include <dev/gpio/gpiovar.h> | | 32 | #include <dev/gpio/gpiovar.h> |
33 | | | 33 | |
34 | #include <dev/onewire/onewirevar.h> | | 34 | #include <dev/onewire/onewirevar.h> |
| @@ -136,43 +136,48 @@ gpioow_attach(device_t parent, device_t | | | @@ -136,43 +136,48 @@ gpioow_attach(device_t parent, device_t |
136 | gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, GPIOOW_PIN_DATA, sc->sc_data); | | 136 | gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, GPIOOW_PIN_DATA, sc->sc_data); |
137 | | | 137 | |
138 | aprint_normal("\n"); | | 138 | aprint_normal("\n"); |
139 | | | 139 | |
140 | /* Attach 1-Wire bus */ | | 140 | /* Attach 1-Wire bus */ |
141 | sc->sc_ow_bus.bus_cookie = sc; | | 141 | sc->sc_ow_bus.bus_cookie = sc; |
142 | sc->sc_ow_bus.bus_reset = gpioow_ow_reset; | | 142 | sc->sc_ow_bus.bus_reset = gpioow_ow_reset; |
143 | sc->sc_ow_bus.bus_bit = gpioow_ow_bit; | | 143 | sc->sc_ow_bus.bus_bit = gpioow_ow_bit; |
144 | | | 144 | |
145 | memset(&oba, 0, sizeof(oba)); | | 145 | memset(&oba, 0, sizeof(oba)); |
146 | oba.oba_bus = &sc->sc_ow_bus; | | 146 | oba.oba_bus = &sc->sc_ow_bus; |
147 | sc->sc_ow_dev = config_found(self, &oba, onewirebus_print); | | 147 | sc->sc_ow_dev = config_found(self, &oba, onewirebus_print); |
148 | | | 148 | |
| | | 149 | if (!pmf_device_register(self, NULL, NULL)) |
| | | 150 | aprint_error("%s: could not establish power handler\n", |
| | | 151 | device_xname(self)); |
149 | return; | | 152 | return; |
150 | | | 153 | |
151 | fail: | | 154 | fail: |
152 | gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); | | 155 | gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); |
153 | } | | 156 | } |
154 | | | 157 | |
155 | int | | 158 | int |
156 | gpioow_detach(device_t self, int flags) | | 159 | gpioow_detach(device_t self, int flags) |
157 | { | | 160 | { |
158 | struct gpioow_softc *sc = device_private(self); | | 161 | struct gpioow_softc *sc = device_private(self); |
159 | int rv = 0; | | 162 | int rv = 0; |
160 | | | 163 | |
161 | gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); | | | |
162 | | | | |
163 | if (sc->sc_ow_dev != NULL) | | 164 | if (sc->sc_ow_dev != NULL) |
164 | rv = config_detach(sc->sc_ow_dev, flags); | | 165 | rv = config_detach(sc->sc_ow_dev, flags); |
165 | | | 166 | |
| | | 167 | if (!rv) { |
| | | 168 | gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); |
| | | 169 | pmf_device_deregister(self); |
| | | 170 | } |
166 | return rv; | | 171 | return rv; |
167 | } | | 172 | } |
168 | | | 173 | |
169 | int | | 174 | int |
170 | gpioow_activate(device_t self, enum devact act) | | 175 | gpioow_activate(device_t self, enum devact act) |
171 | { | | 176 | { |
172 | struct gpioow_softc *sc = device_private(self); | | 177 | struct gpioow_softc *sc = device_private(self); |
173 | int rv = 0; | | 178 | int rv = 0; |
174 | | | 179 | |
175 | switch (act) { | | 180 | switch (act) { |
176 | case DVACT_ACTIVATE: | | 181 | case DVACT_ACTIVATE: |
177 | return EOPNOTSUPP; | | 182 | return EOPNOTSUPP; |
178 | case DVACT_DEACTIVATE: | | 183 | case DVACT_DEACTIVATE: |