GPIO Access on I-Pi SMARC LEC-ALNAccess I2C GPIO Expander SX1509The SX1509 I2C GPIO expander, connected to the ADLINK I2C bus, can be accessed exclusively through the ADLINK SEMA DRIVERS. ADLINK SEMA Drivers Installation on UbuntuPlease follow the steps below to load the SEMA EC drivers. sudo apt install build-essential git hexer i2c-tools sudo apt-get install uuid-dev git clone https://github.com/ADLINK/sema-linux.git -b sema-eccd sema-linux sudo makesudo make install sudo modprobe -a adl-ec adl-ec-boardinfo adl-ec-vm adl-ec-wdt adl-ec-hwmon adl-ec-nvmem adl-ec-bklight adl-ec-i2c adl-ec-gpio adl-ec-nvmem-sec sudo i2cdetect -l This above command will display all the available i2c buses. Now find at which i2c bus the ADLINK BMC I2C adapter bus 2 is present. sudo i2cdetect -y 18 (Since ADLINK BMC I2C adapter bus 2 is at i2c-18) Running the above command we find slave address 3e,3f , which confirms the presence of SX1509 GPIO Expander. After loading the kernel driver, configure the SX1509 GPIO driver by executing the following command. sudo su echo sx1509q 0x3e > /sys/bus/i2c/devices/i2c-18/new_device (18 is the i2c bus SEMA(BMC) and SX1509 connected) echo sx1509q 0x3f > /sys/bus/i2c/devices/i2c-18/new_device (18 is the i2c bus SEMA(BMC) and SX1509 connected) Note: Here, i2c-18 is used since SMBus is located at bus 18. 0x3e , 0x3f are the GPIO device slave address. Please refer to the screenshot above to find the i2c bus number and GPIO device address. 1) GPIO ACCESS1.1) Using libgpiod toolNow Install libgpiod tools, sudo apt updatesudo apt install gpiod libgpiod2 Then use gpiodetect command to display the GPIO chips present on your system and the number of lines they expose. gpiodetect From above output it is found that sx1509 is detected as gpiochip2 and gpiochip3 . Now to view the current state of GPIOs that are managed by the Linux kernel ,run the below command. cat /sys/kernel/debug/gpio Use gpioset to modify GPIO pin’s value . NOTE: Refer Table 1.3 attached at the end for more detail about Carrier Pin,Line Number,etc. To modify value to high gpioset gpiochip2 X=1 (Here X indicates line number) To modify value to low gpioset gpiochip2 X=0 Example: For line 0 For High:gpioset gpiochip2 0=1For low:gpioset gpiochip2 0=0 To verify , you can use gpioget gpioget gpiochip2 X (Here X indicates line number) Similarly to modify line 1 ‘s value. gpioset gpiochip2 1=1 1.2) Using SysfsTo export the GPIO pins in SX1509 , use below command cd /sys/class/gpio echo 639 > export NOTE: Here 639 (line 0) is exported and used since gpio639 is the base number as displayed by cat /sys/kernel/debug/gpio command Now to read the direction and value of the pin use the below command cd gpio639cat directioncat value Now to modify the direction to Output , use the below command echo out > direction Replace out with in for changing direction to input Similarly to modify the value to High echo 1 > value Replace 1 with 0 for changing value to Low Similarly to modify Line2 of GPIO , repeat the above steps for gpio640 , Refer to below table for more details. NOTE : PIN7 on CN1001 header is connected to pull up resistor , So it stays high by default and cannot be modified either by using libgpiod or sysfs. Table 1.3(E_GPIO) Line Number GPIO Number to Export CN1001 (Carrier PIN) 0 639 29 1 640 31 2 641 32 3 642 33 4 643 35 5 644 36 6 645 37 7 646 38 8 647 40 (S_GPIO) Line Number GPIO Number to Export CN1001 (Carrier PIN 8 630 11 7 629 12 9 631 13 10 632 15 11 633 16 12 634 18 13 635 22