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

From fit-PC wiki
Jump to: navigation, search
(Created page with "fitlet2 supports I2C GPIO extender if configured with the [http://fit-pc.com/wiki/index.php/Fitlet2_FACET_Cards#FC-SCG FC-SCG FACET] ==I2c gpio extender binding and usage==...")   (change visibility)
 
Line 9: Line 9:
 
  CONFIG_I2C_CHARDEV=y
 
  CONFIG_I2C_CHARDEV=y
  
Make sure that the appropriate I2C bus is enabled in BIOS settings:
+
2. Make sure that the appropriate I2C bus is enabled in BIOS settings:
 
Chipset -> South Cluster Configuration -> LPSS Configuration
 
Chipset -> South Cluster Configuration -> LPSS Configuration
LPSS I2C #[1-8] Support is set to ACPI mode or PCI mode
+
'''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
+
Set LPSS I2C #[1-8] Speed''' is set to '''Standard Mode''' of '''Fast Mode'''
  
NB: All buses must be enabled in the range 1-7, not only I2C-7
+
'''NOTE:''' All buses must be enabled in the range 1-7, not only I2C-7
  
  
Determine the type of the GPIO extender chip. Possible options are:
+
3. Determine the type of the GPIO extender chip. Possible options are:
  
  
PCA9335
+
* PCA9335
XRA1201
+
* XRA1201 For this purpose i2cdetect utility may be used:
For this purpose i2cdetect utility may be used:
+
  
 
+
i2cdetect -y -r 7
i2cdetect -y -r 7
+
  
 
PCA9335 chip should be found at address 0x27, whereas XRA1201 chip at 0x4e
 
PCA9335 chip should be found at address 0x27, whereas XRA1201 chip at 0x4e
  
  
Issue the following command (superuser privileges are necessary)
+
4. Issue the following command (superuser privileges are necessary)
  
echo pca9535 0x27> /sys/bus/i2c/devices/i2c-7/new_device
+
echo pca9535 0x27> /sys/bus/i2c/devices/i2c-7/new_device
  
 
in case  pca9535 chip found
 
in case  pca9535 chip found
Line 38: Line 36:
 
or
 
or
  
echo pca9535 0x4e> /sys/bus/i2c/devices/i2c-7/new_device
+
echo pca9535 0x4e> /sys/bus/i2c/devices/i2c-7/new_device
  
 
and check the kernel debug messages for a line like that:
 
and check the kernel debug messages for a line like that:
Line 45: Line 43:
  
  
To find the appropriate GPIO issue the command:
+
5. To find the appropriate GPIO issue the command:
  
ls /sys/bus/i2c/drivers/pca953x/
+
ls /sys/bus/i2c/drivers/pca953x/
  
 
and look the output for a line like this:
 
and look the output for a line like this:
  
7-0027
+
'''7-0027'''
  
 
and then issue the command:
 
and then issue the command:
  
ls /sys/class/gpio/gpiochip*/device -l
+
ls /sys/class/gpio/gpiochip*/device -l
  
 
and look the output for a line like this:
 
and look the output for a line like this:
  
/sys/class/gpio/gpiochip251/device -> ../../../7-0027
+
/sys/class/gpio/gpiochip251/device -> ../../../'''7-0027'''
  
 
The bus number and address have to be the same in the both cases (7 and 27 in the example).
 
The bus number and address have to be the same in the both cases (7 and 27 in the example).
Line 65: Line 63:
  
  
The found GPIO may be operated over sysfs interface this way:
+
6. The found GPIO may be operated over sysfs interface this way:
 
issue the commands:
 
issue the commands:
  
export n=251 # desired GPIO number
+
export n=251 # desired GPIO number
echo $n >/sys/class/gpio/export
+
echo $n >/sys/class/gpio/export
echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out
+
echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out
cat /sys/class/gpio/gpio$n/value # read the input value
+
cat /sys/class/gpio/gpio$n/value # read the input value
echo 1 > /sys/class/gpio/gpio$n/value # write a value for output
+
echo 1 > /sys/class/gpio/gpio$n/value # write a value for output

Revision as of 08:34, 27 September 2018

fitlet2 supports I2C GPIO extender if configured with the FC-SCG FACET

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: All buses must be enabled in the range 1-7, not only I2C-7


3. Determine the type of the GPIO extender chip. Possible options are:


  • PCA9335
  • XRA1201 For this purpose i2cdetect utility may be used:
i2cdetect -y -r 7

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


4. Issue the following command (superuser privileges are necessary)

echo pca9535 0x27> /sys/bus/i2c/devices/i2c-7/new_device

in case pca9535 chip found

or

echo pca9535 0x4e> /sys/bus/i2c/devices/i2c-7/new_device

and check the kernel debug messages for a line like that:

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/

and look the output for a line like this:

7-0027

and then issue the command:

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

and look the output for a line like this:

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

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


6. The found GPIO may be operated over sysfs interface this 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