FreeBSD, Electronics and more
The GPIO registers on the RT305X and the RT5350 are the same, which is nice. The RT5350 just have less GPIO pins (27 max, the RT305X have 51 max).
The support of GPIO for the RT305X was basic but works, so I just added my defines for the pins, registers and masks and basic support was done.
Now I wanted more that just basic supports, ie to be able to configure gpio pins at boot etc ...
Currently on FreeBSD, mips board are hint based platform, they do not use fdt file like arm but basic description file that are passed to the kernel via the bootloaded or directly compiled in. See device.hints(5).
Some drivers (like the ar71xx_gpio one) supports some hints to configure pins, do basic pinmuxing and settings ON the pins when the driver attach. The current RT305x doesn't so I've added the support.
The Olimex board have one button (tied to
GPIO0) and two relay (controlled by
GPIO0 is always in GPIO mode, there is not alternate function, but
GPIO14 are also used by the UARTF function so we need to disable it before we can use the GPIOs. This is exactly what the function_set hints is suppose to do (for the RT5350 the content is just written to the GPIOMODE system control register). The bits controlling the UARTF function are at position 2-4 and we have to set it to b111 to set it in gpio mode.
Two other hints also exist to configure the pins at startup, they are
pinmaska bitfield where each bit is set if the corresponding pins must be configured
pinouta bitfield where each bit is set if the corresponding pins must be set to an output and the value to 1
I've added another one
pinin, it like pinout but for inputs :)
With the following section of the hint file, when the board is booted it have :
GPIO0configured as an intput
GPIO12configured as an output and the value set to 1
GPIO14configured as an output and the value set to 1
RT5350.hints: hint.gpio.0.function_set=0x1C hint.gpio.0.pinmask=0x5001 hint.gpio.0.pinon=0x5000 hint.gpio.0.pinin=0x1 # gpioctl -l pin 00: 1 pin 0<IN> pin 01: -1 <> pin 02: -1 <> pin 03: -1 <> pin 04: -1 <> pin 05: -1 <> pin 06: -1 <> pin 07: -1 <> pin 08: -1 <> pin 09: -1 <> pin 10: -1 <> pin 11: -1 <> pin 12: 1 pin 12<OUT> pin 13: -1 <> pin 14: 1 pin 14<OUT> pin 15: -1 <> pin 16: -1 <> pin 17: -1 <> pin 18: -1 <> pin 19: -1 <> pin 20: -1 <> pin 21: -1 <> pin 22: -1 <> pin 23: -1 <> pin 24: -1 <> pin 25: -1 <> pin 26: -1 <> pin 27: -1 <>
Now I can read if the button is pressed with
gpioctl 0 and toggle the states of the relays with
gpioctl -t [12|14].
See you in part 3.