Index: arch/arm/broadcom/bcm2835_gpio.c =================================================================== RCS file: /home/netbsd/src/sys/arch/arm/broadcom/bcm2835_gpio.c,v retrieving revision 1.7 diff -p -u -r1.7 bcm2835_gpio.c --- arch/arm/broadcom/bcm2835_gpio.c 19 May 2018 14:02:10 -0000 1.7 +++ arch/arm/broadcom/bcm2835_gpio.c 28 Jul 2018 14:51:25 -0000 @@ -94,6 +94,8 @@ struct bcmgpio_softc { device_t sc_dev; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; + bus_addr_t sc_addr; + bus_size_t sc_size; struct gpio_chipset_tag sc_gpio_gc; kmutex_t sc_lock; @@ -113,6 +115,7 @@ struct bcmgpio_pin { static int bcmgpio_match(device_t, cfdata_t, void *); static void bcmgpio_attach(device_t, device_t, void *); +static paddr_t bcm2835gpio_gpio_mmap(void *, off_t, int); static int bcm2835gpio_gpio_pin_read(void *, int); static void bcm2835gpio_gpio_pin_write(void *, int, int); static void bcm2835gpio_gpio_pin_ctl(void *, int, int); @@ -248,15 +251,13 @@ bcmgpio_attach(device_t parent, device_t struct bcmgpio_softc * const sc = device_private(self); struct fdt_attach_args * const faa = aux; struct gpiobus_attach_args gba; - bus_addr_t addr; - bus_size_t size; u_int func; int error; int pin; int bank; const int phandle = faa->faa_phandle; - if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { + if (fdtbus_get_reg(phandle, 0, &sc->sc_addr, &sc->sc_size) != 0) { aprint_error(": couldn't get registers\n"); return; } @@ -267,7 +268,8 @@ bcmgpio_attach(device_t parent, device_t aprint_normal(": GPIO controller\n"); sc->sc_iot = faa->faa_bst; - error = bus_space_map(sc->sc_iot, addr, size, 0, &sc->sc_ioh); + error = bus_space_map(sc->sc_iot, sc->sc_addr, sc->sc_size, 0, + &sc->sc_ioh); if (error) { aprint_error_dev(self, "couldn't map registers\n"); return; @@ -352,6 +354,7 @@ bcmgpio_attach(device_t parent, device_t /* create controller tag */ sc->sc_gpio_gc.gp_cookie = sc; + sc->sc_gpio_gc.gp_gc_mmap = bcm2835gpio_gpio_mmap; sc->sc_gpio_gc.gp_pin_read = bcm2835gpio_gpio_pin_read; sc->sc_gpio_gc.gp_pin_write = bcm2835gpio_gpio_pin_write; sc->sc_gpio_gc.gp_pin_ctl = bcm2835gpio_gpio_pin_ctl; @@ -687,6 +690,18 @@ bcmgpio_fdt_intrstr(device_t dev, u_int } /* GPIO support functions */ +static paddr_t +bcm2835gpio_gpio_mmap(void *arg, off_t off, int prot) +{ + struct bcmgpio_softc *sc = arg; + + if (off < 0 || off >= sc->sc_size) + return (paddr_t)-1; + + return bus_space_mmap(sc->sc_iot, sc->sc_addr, off, prot, + BUS_SPACE_MAP_LINEAR); +} + static int bcm2835gpio_gpio_pin_read(void *arg, int pin) { Index: dev/gpio/gpio.c =================================================================== RCS file: /home/netbsd/src/sys/dev/gpio/gpio.c,v retrieving revision 1.61 diff -p -u -r1.61 gpio.c --- dev/gpio/gpio.c 19 May 2018 13:59:06 -0000 1.61 +++ dev/gpio/gpio.c 28 Jul 2018 10:47:12 -0000 @@ -99,6 +99,7 @@ dev_type_open(gpioopen); dev_type_close(gpioclose); dev_type_ioctl(gpioioctl); dev_type_ioctl(gpioioctl_locked); +dev_type_mmap(gpiommap); const struct cdevsw gpio_cdevsw = { .d_open = gpioopen, @@ -109,7 +110,7 @@ const struct cdevsw gpio_cdevsw = { .d_stop = nostop, .d_tty = notty, .d_poll = nopoll, - .d_mmap = nommap, + .d_mmap = gpiommap, .d_kqfilter = nokqfilter, .d_discard = nodiscard, .d_flag = D_OTHER | D_MPSAFE @@ -659,6 +660,15 @@ gpio_pinbyname(struct gpio_softc *sc, ch return -1; } +paddr_t +gpiommap(dev_t dev, off_t off, int prot) +{ + struct gpio_softc *sc; + + sc = device_lookup_private(&gpio_cd, minor(dev)); + return gpiobus_mmap(sc->sc_gc, off, prot); +} + int gpioioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) { Index: dev/gpio/gpiovar.h =================================================================== RCS file: /home/netbsd/src/sys/dev/gpio/gpiovar.h,v retrieving revision 1.18 diff -p -u -r1.18 gpiovar.h --- dev/gpio/gpiovar.h 19 May 2018 13:59:06 -0000 1.18 +++ dev/gpio/gpiovar.h 28 Jul 2018 10:09:19 -0000 @@ -28,6 +28,7 @@ typedef struct gpio_chipset_tag { int (*gp_gc_open)(void *, device_t); void (*gp_gc_close)(void *, device_t); + paddr_t (*gp_gc_mmap)(void *, off_t, int); int (*gp_pin_read)(void *, int); void (*gp_pin_write)(void *, int, int); void (*gp_pin_ctl)(void *, int, int); @@ -64,6 +65,9 @@ int gpiobus_print(void *, const char *); ((gc)->gp_gc_open ? ((gc)->gp_gc_open((gc)->gp_cookie, dev)) : 0) #define gpiobus_close(gc, dev) \ ((gc)->gp_gc_close ? ((gc)->gp_gc_close((gc)->gp_cookie, dev)), 1 : 0) +#define gpiobus_mmap(gc, off, prot) \ + ((gc)->gp_gc_mmap ? ((gc)->gp_gc_mmap((gc)->gp_cookie, off, prot)) : \ + (paddr_t)-1) #define gpiobus_pin_read(gc, pin) \ ((gc)->gp_pin_read((gc)->gp_cookie, (pin))) #define gpiobus_pin_write(gc, pin, value) \