Difference between revisions of "Application note - GPIO on fitlet2 with FC-SCG running Linux"

From fit-PC wiki
Jump to: navigation, search
(I2C GPIO extender binding and usage)   (change visibility)
 
Line 6: Line 6:
 
1. Make sure that the kernel you use supports the necessary driver.  
 
1. Make sure that the kernel you use supports the necessary driver.  
 
<br>Check the following entries in the kernel config:
 
<br>Check the following entries in the kernel config:
 
+
<pre>
CONFIG_GPIO_PCA953X=[y]
+
CONFIG_GPIO_PCA953X=[y]
CONFIG_I2C=y
+
CONFIG_I2C=y
CONFIG_I2C_CHARDEV=y
+
CONFIG_I2C_CHARDEV=y
 
+
</pre>
 
2. Make sure that the appropriate I2C bus is enabled in BIOS settings: <br>
 
2. Make sure that the appropriate I2C bus is enabled in BIOS settings: <br>
 
Chipset -> South Cluster Configuration -> LPSS Configuration LPSS I2C #[1-8] Support is set to ACPI mode or PCI mode Set LPSS I2C #[1-8] Speed is set to Standard Mode of Fast Mode
 
Chipset -> South Cluster Configuration -> LPSS Configuration LPSS I2C #[1-8] Support is set to ACPI mode or PCI mode Set LPSS I2C #[1-8] Speed is set to Standard Mode of Fast Mode
Line 16: Line 16:
  
 
3.Find the GPIO extender on an I2C bus:
 
3.Find the GPIO extender on an I2C bus:
readonly dev_func='17.2'  
+
<pre>
busnum=$(ls -l /sys/bus/i2c/devices/ | sed -ne  
+
readonly dev_func='17.2'  
"/${dev_func}\/i2c_designware/ s/^.*i2c-\([[:digit:]]\{1,2\}\)$/\1/p")  
+
busnum=$(ls -l /sys/bus/i2c/devices/ | sed -ne  
busaddr=$(i2cdetect -y -r $busnum | sed -ne  
+
"/${dev_func}\/i2c_designware/ s/^.*i2c-\([[:digit:]]\{1,2\}\)$/\1/p")  
's/^.*\(\(27\|4e\)\).*$/0x\1/Ip')  
+
busaddr=$(i2cdetect -y -r $busnum | sed -ne  
busaddr=$((busaddr))  
+
's/^.*\(\(27\|4e\)\).*$/0x\1/Ip')  
printf "Device found @ 0x%x on bus %i\n" $busaddr $busnum  
+
busaddr=$((busaddr))  
 
+
printf "Device found @ 0x%x on bus %i\n" $busaddr $busnum  
 +
</pre>
 
'''Note:''' PCA9335 chip should be found at address 0x27, whereas XRA1201 chip at 0x4e
 
'''Note:''' PCA9335 chip should be found at address 0x27, whereas XRA1201 chip at 0x4e
  
 
4. Bind the above found device to driver (superuser privileges are necessary)
 
4. Bind the above found device to driver (superuser privileges are necessary)
echo pca9535 $busaddr >/sys/bus/i2c/devices/i2c-${busnum}/new_device  
+
<pre>
 +
echo pca9535 $busaddr >/sys/bus/i2c/devices/i2c-${busnum}/new_device
 +
</pre>
 
Then check the kernel debug messages for a line like the following:
 
Then check the kernel debug messages for a line like the following:
i2c i2c-7: new_device: Instantiated device pca9535 at 0x27
+
<pre>
 
+
i2c i2c-7: new_device: Instantiated device pca9535 at 0x27
 +
</pre>
 
5. To find the appropriate GPIO, issue the command:
 
5. To find the appropriate GPIO, issue the command:
ls /sys/bus/i2c/drivers/pca953x/
+
<pre>
 +
ls /sys/bus/i2c/drivers/pca953x/
 +
</pre>
 
Then look the output for a line like:
 
Then look the output for a line like:
7-0027
+
<pre>
 +
7-0027
 +
</pre>
 
And then issue the command:
 
And then issue the command:
ls /sys/class/gpio/gpiochip*/device -l
+
<pre>
 +
ls /sys/class/gpio/gpiochip*/device -l
 +
</pre>
 
Afterwards, look at the output for a line like the following:
 
Afterwards, look at the output for a line like the following:
/sys/class/gpio/gpiochip251/device -> ../../../7-0027
+
<pre>
 +
/sys/class/gpio/gpiochip251/device -> ../../../7-0027
 +
</pre>
  
 
The bus number and address has to be the same in both cases (7 and 27 in the example).  
 
The bus number and address has to be the same in both cases (7 and 27 in the example).  
Line 45: Line 57:
 
6. The GPIO found may be operated over sysfs interface in the following way:  
 
6. The GPIO found may be operated over sysfs interface in the following way:  
 
issue the commands:
 
issue the commands:
export n=251 # desired GPIO number
+
<pre>
echo $n >/sys/class/gpio/export
+
export n=251 # desired GPIO number
echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out
+
echo $n >/sys/class/gpio/export
cat /sys/class/gpio/gpio$n/value # read the input value
+
echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out
echo 1 > /sys/class/gpio/gpio$n/value # write a value for output
+
cat /sys/class/gpio/gpio$n/value # read the input value
 
+
echo 1 > /sys/class/gpio/gpio$n/value # write a value for output
 +
</pre>
  
 
[[category: fitlet2]]
 
[[category: fitlet2]]

Latest revision as of 14:35, 5 March 2019

  • This application note applies to fitlet2 with FC-SCG FACET-Card running Linux.
  • It provides an example of how to use the supported I2C GPIO extender feature of FC-SCG under Linux.

I2C GPIO extender binding and usage

1. Make sure that the kernel you use supports the necessary driver.
Check the following entries in the kernel config:

CONFIG_GPIO_PCA953X=[y]
CONFIG_I2C=y
CONFIG_I2C_CHARDEV=y

2. Make sure that the appropriate I2C bus is enabled in BIOS settings:
Chipset -> South Cluster Configuration -> LPSS Configuration LPSS I2C #[1-8] Support is set to ACPI mode or PCI mode Set LPSS I2C #[1-8] Speed is set to Standard Mode of Fast Mode
NOTE: It’s strongly recommended that all buses are enabled in the range of 1-7

3.Find the GPIO extender on an I2C bus:

readonly dev_func='17.2' 
busnum=$(ls -l /sys/bus/i2c/devices/ | sed -ne 
"/${dev_func}\/i2c_designware/ s/^.*i2c-\([[:digit:]]\{1,2\}\)$/\1/p") 
busaddr=$(i2cdetect -y -r $busnum | sed -ne 
's/^.*\(\(27\|4e\)\).*$/0x\1/Ip') 
busaddr=$((busaddr)) 
printf "Device found @ 0x%x on bus %i\n" $busaddr $busnum 

Note: PCA9335 chip should be found at address 0x27, whereas XRA1201 chip at 0x4e

4. Bind the above found device to driver (superuser privileges are necessary)

echo pca9535 $busaddr >/sys/bus/i2c/devices/i2c-${busnum}/new_device

Then check the kernel debug messages for a line like the following:

i2c i2c-7: new_device: Instantiated device pca9535 at 0x27

5. To find the appropriate GPIO, issue the command:

ls /sys/bus/i2c/drivers/pca953x/

Then look the output for a line like:

7-0027

And then issue the command:

ls /sys/class/gpio/gpiochip*/device -l

Afterwards, look at the output for a line like the following:

/sys/class/gpio/gpiochip251/device -> ../../../7-0027

The bus number and address has to be the same in both cases (7 and 27 in the example). Hence, the gpiochip251 is to be sought; the individual GPIO line number are from 251 to 251+15

6. The GPIO found may be operated over sysfs interface in the following way: issue the commands:

export n=251 # desired GPIO number
echo $n >/sys/class/gpio/export
echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out
cat /sys/class/gpio/gpio$n/value # read the input value
echo 1 > /sys/class/gpio/gpio$n/value # write a value for output