Lines Matching +full:sc +full:- +full:resource
1 /*-
36 #include <sys/resource.h>
42 #include <machine/resource.h>
55 #define GPIO_LOCK(sc) mtx_lock(&(sc)->sc_mtx) argument
56 #define GPIO_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) argument
57 #define GPIO_LOCK_INIT(sc) \ argument
58 mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->dev), \
60 #define GPIO_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
66 struct resource *out_res; /* Memory resource */
67 struct resource *in_res;
73 struct mpc85xx_gpio_softc *sc; in mpc85xx_gpio_get_bus() local
75 sc = device_get_softc(dev); in mpc85xx_gpio_get_bus()
77 return (sc->busdev); in mpc85xx_gpio_get_bus()
110 name[GPIOMAXNAME-1] = '\0'; in mpc85xx_gpio_pin_getname()
119 struct mpc85xx_gpio_softc *sc = device_get_softc(dev); in mpc85xx_gpio_pin_set() local
126 GPIO_LOCK(sc); in mpc85xx_gpio_pin_set()
127 pinbit = 31 - pin; in mpc85xx_gpio_pin_set()
129 outvals = bus_read_4(sc->out_res, 0); in mpc85xx_gpio_pin_set()
132 bus_write_4(sc->out_res, 0, outvals); in mpc85xx_gpio_pin_set()
134 GPIO_UNLOCK(sc); in mpc85xx_gpio_pin_set()
143 struct mpc85xx_gpio_softc *sc = device_get_softc(dev); in mpc85xx_gpio_pin_get() local
148 *value = (bus_read_4(sc->in_res, 0) >> (31 - pin)) & 1; in mpc85xx_gpio_pin_get()
157 struct mpc85xx_gpio_softc *sc = device_get_softc(dev); in mpc85xx_gpio_pin_toggle() local
163 GPIO_LOCK(sc); in mpc85xx_gpio_pin_toggle()
165 val = bus_read_4(sc->out_res, 0); in mpc85xx_gpio_pin_toggle()
166 val ^= (1 << (31 - pin)); in mpc85xx_gpio_pin_toggle()
167 bus_write_4(sc->out_res, 0, val); in mpc85xx_gpio_pin_toggle()
169 GPIO_UNLOCK(sc); in mpc85xx_gpio_pin_toggle()
203 struct mpc85xx_gpio_softc *sc = device_get_softc(dev); in mpc85xx_gpio_attach() local
206 sc->dev = dev; in mpc85xx_gpio_attach()
208 GPIO_LOCK_INIT(sc); in mpc85xx_gpio_attach()
212 sc->out_res = bus_alloc_resource_any(dev, in mpc85xx_gpio_attach()
214 if (sc->out_res == NULL) { in mpc85xx_gpio_attach()
221 sc->in_res = bus_alloc_resource_any(dev, in mpc85xx_gpio_attach()
223 if (sc->in_res == NULL) { in mpc85xx_gpio_attach()
231 sc->busdev = gpiobus_add_bus(dev); in mpc85xx_gpio_attach()
232 if (sc->busdev == NULL) { in mpc85xx_gpio_attach()
244 struct mpc85xx_gpio_softc *sc = device_get_softc(dev); in mpc85xx_gpio_detach() local
248 if (sc->out_res != NULL) { in mpc85xx_gpio_detach()
249 /* Release output port resource. */ in mpc85xx_gpio_detach()
251 rman_get_rid(sc->out_res), sc->out_res); in mpc85xx_gpio_detach()
254 if (sc->in_res != NULL) { in mpc85xx_gpio_detach()
255 /* Release input port resource. */ in mpc85xx_gpio_detach()
257 rman_get_rid(sc->in_res), sc->in_res); in mpc85xx_gpio_detach()
260 GPIO_LOCK_DESTROY(sc); in mpc85xx_gpio_detach()