I know that is not exactly the answer you are looking for, but there is a way to do it in user space, if you want to avoid to program a kernel module for your application.
This is an example for GPIO access in Raspberry Pi3:
#define RASPBERRY_PI_PERI_BASE 0x3F000000
#define GPIO_BASE (RASPBERRY_PI_PERI_BASE + 0x200000) // GPIO controller
#define BLOCK_SIZE (4*1024)
static volatile uint32_t *gpio = NULL;
int GPIO_init(void) {
int fd;
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) return -1; // printf("Failed to open /dev/mem, try checking permissions.\n");
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);
if ((int32_t)gpio == -1) return -1; // printf("Failed mmap (GPIO): %s\n", strerror (errno));
return 0;
}
Now you have a simply pointer variable *gpio that links to the hardware's memory address. You do it mapping "mem" device on memory, that exists for you "for free" :-)
Regards.