How is GPIO displayed in memory?

I recently looked at the GPIO driver for pi2, I found the user space pi2 GPIO lib (e.g. RPi.GPIO 0.5.11 from python) uses /dev/mem for BCM2708 (starts at 0x20000000, and GPIO starts at 0x200000 relative) to mmap memory area user space for GPIO processing. But I found drivers/gpio in the linux source tree, which is handled by /sys/class/gpio/* . I did not find anything like mapping I / O ports, e.g. request_io_region and __io_remap . My question is: how is the GPIO for BCM2708 displayed in memory? Is there another driver? And can I only process GPIO R & W up to /sys/class/gpio/* ?

+5
source share
2 answers

I did not find anything like mapping I / O ports, such as request_io_region and __io_remap.

ARM has no I / O port. All peripheral registers are assigned to addresses in memory.

How is GPIO for BCM2708 displayed in memory?

GPIOs are typically implemented as control register peripherals, and the GPIO in the BCM2835 RPi follows this convention. This set of control registers may have a different name; for example, Atmel refers to these registers as a peripheral parallel input / output device (PIO).

Each GPIO (or, more precisely, each pin) will be represented by one or more bits in each function of the control register. The functions of the control register include pin assignment (for example, multiplexing), setting the output to high, setting the output signal to a low level, the reading level and the level and edge control level.

IOW there is not a single bit that can be read and written, which corresponds to the GPIO. For GPIOs in a particular register there will be a bit to extract the input level. There's a bit in a different register to set the GPIO output high and a bit in another register to set the GPIO output to low.

Is there any other driver?

Yes. The pinctrl (pin control) driver is the bottom layer (i.e. closer to the HW) than the GPIO. This is the pinctrl layer, which handles pin multiplexing (i.e. whether the pin is used for a peripheral function or as a GPIO).
The pinctrl driver for SoC (e.g. drivers/pinctrl/pinctrl-bcm2835.c ) is where you find devm_ioremap_resources () (which in turn calls devm_request_mem_region () and devm_ioremap () ) for the GPIO register block.

And can I only process GPIO R & W in / sys / class / gpio / *?

Yes. sysfs is provided to access these contacts that are not tied to peripherals.

ADDITION
The GPIO sysfs interface has limited capabilities.
Apparently, there are user-space libraries for accessing additional pin attributes (for example, to enable a pull-up or drop-down resistor), which are usually located in the pinctrl driver domain . Typically, these libraries access the PIO hardware registers directly through the / dev / mem psuedo-file. Remember that these methods are not safe and may interfere with other device drivers.

+4
source

This answer may not be on all fours, as it just provides the GPIO base address for the Raspberry Pi 2 versus how.

Despite this, the Raspbian OS on the Raspberry Pi 2 provides a base address of 0x3f20,0000 .

 $ dmesg -H [ +0.000749] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000 

An example of a rough build of ARMv7 using the above base address by calling mmmap to blink the ACT LED on a raspberry Pi 2 is given in the link below.

https://github.com/InfinitelyManic/Raspberry-Pi-2

0
source

All Articles