mmap a GPIO?

I’m trying to get the GPIO_CTL register for GPIO17_HEADER40, ie pin 22 on the 40 pin header,ie gpio417 in sysfs, ie GPIO3_PQ.01. I calculated its physical address as 0x02231000. However when I try and mmap it, I always see “0”, and writing to it has no effect. I tried using sysfs to modify the GPIO and read back using my code below, but it doesn’t work. Not sure what I am doing wrong. Also note the Xavier Technical Reference manual doesn’t seem to specify the GPIO__ENABLE_CONFIG as the Parker TRM did, so I assume it is the same 8 bits as Parker TRM 8.30.9. Please help!

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>

// Base address GPIO_CTL2_GPIO1
#define GPIO_ADDR 0x02231000
#define GPIO_SZ 1

void main() {
    int fd = open("/dev/mem", O_RDWR);
    if (fd < 0) {
        printf("Couldn't open /dev/mem!\n");
    uint8_t* gpio_reg = mmap(NULL, GPIO_SZ, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_ADDR);
    printf("Read from %p:0x%.8X value: %x\n", gpio_reg, GPIO_ADDR, *gpio_reg);
    *gpio_reg = 0xff;
    printf("Read from %p:0x%.8X value: %x\n", gpio_reg, GPIO_ADDR, *gpio_reg);
    // Changes between runs but my GPIO doesn't flip (confirmed on scope)

How about probing the signal? Does it reflect your sysfs controlling?

Yes, if I use sysfs I can verify the signal with my probe.

I think I may have GPIO_ADDR wrong in my code above - or maybe GPIO_SZ? I tried my best to match it to the TRM but again, I could not find the actual GPIO register definitions anywhere in the Xavier TRM… am I missing something?

I can verify that the GPIO flips when I use sysfs, using my scope. However, nothing changes in the region I have mmap’d. Therefore, I must have the registers wrong… can someone please explain the mapping to me, and also point out where I can find the actual register definitions?

Could you take a look at kernel/t18x/drivers/gpio/gpio-tegra186.c to figure out the address?

Hi jrestifo,

Is this still an issue to support or you have found the cause?