There are two ways to control the GPIO pins: directly or using the GPIO Sysfs
Interface. In both cases you will need to refer to the HI3518 datasheet .
Direct Control
To control the pins using direct register writes you will need to configure the
function of the pins using the IO configuration registers (0x200F_xxxx) and
then configure the GPIO functionality.
An example of setting up the IR-cut filter pins you would use:
devmem 0x200F004C 8 0x00
devmem 0x200F0048 8 0x00
devmem 0x20180400 8 0xC0
To flip the IR-cut filter in one direction you would use:
devmem 0x20180300 32 0x40
To flip the IR-cut filter back in the other direction you would use:
devmem 0x20180300 32 0x80
GPIO Sysfs Interface
Alternatively, you can use the GPIO Sysfs interface. For the GPIO Sysfs interface to work you will need to have compiled support
into the kernel.
If this is the case, you can then interact with the GPIO pins through the
/sys/class/gpio directory.
The first thing you need to do is work out the name of the GPIO pin in the
sysfs. The GPIO sysfs interface does not use the same names as the HI3518
datasheet for the pins. In the datasheet the pins are numbered in banks of 8,
but in the sysfs they are sequentially numbered.
You will need to use the following formula to work out the pin number:
sysfs_pin_number = bank_number * 8 + pin_number
For example, the alarm pin is GPIO6_1. This means it is pin 1 of bank 6.
6 * 8 + 1 = 49
Once you know this you can interact with the pin using the standard GPIO sysfs
interface. For example, to set up the alarm pin you would use:
devmem 0x200F0084 8 0x0
echo 49 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio49/direction
You will notice the first command is using a direct write to the IO
configuration registers. I found this to be necessary even when using the sysfs
interface.
You can then read the GPIO pin state using:
cat /sys/class/gpio/gpio49/value