Changes

Jump to: navigation, search
* This application note applies to fitlet2 supports I2C GPIO extender if configured with the [http://fit-pc.com/wiki/index.php/Fitlet2_FACET_Cards#FC-SCG FC-SCG FACET]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 I2C GPIO extender binding and usage==
1. Make sure that the kernel you use supports the necessary driver.
<br>Check the following entries in the kernel config:
<pre>
CONFIG_GPIO_PCA953X=[y]
CONFIG_I2C=y
CONFIG_I2C_CHARDEV=y
</pre>
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
<br>'''NOTE:''' It’s strongly recommended that all buses are enabled in the range of 1-7
CONFIG_GPIO_PCA953X=[y] CONFIG_I2C=y CONFIG_I2C_CHARDEV=y 23. Make sure that Find the appropriate GPIO extender on an I2C bus is enabled in BIOS settings:Chipset -<pre> South Cluster Configuration -> LPSS Configurationreadonly dev_func='17.2''LPSS I2C #[1busnum=$(ls -8]''' Support is set to '''ACPI mode or PCI model /sys/bus/i2c/devices/ | sed -ne Set LPSS I2C #"/${dev_func}\/i2c_designware/ s/^.*i2c-\([[:digit:]]\{1,2\}\)$/\1/p") busaddr=$(i2cdetect -8] Speed''' is set to '''Standard Mode''' of '''Fast Mode'y -r $busnum | sed -ne 's/^.*\(\(27\|4e\)\).*$/0x\1/Ip') busaddr=$((busaddr)) printf "Device found @ 0x%x on bus %i\n" $busaddr $busnum </pre>'''NOTENote:''' 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:
4. Bind the above found device to driver (superuser privileges are necessary)
<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:
<pre>
i2c i2c-7: new_device: Instantiated device pca9535 at 0x27
</pre>
5. To find the appropriate GPIO, issue the command:
<pre>
ls /sys/bus/i2c/drivers/pca953x/
</pre>
Then look the output for a line like:
<pre>
7-0027
</pre>
And then issue the command:
<pre>
ls /sys/class/gpio/gpiochip*/device -l
</pre>
Afterwards, look at the output for a line like the following:
<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).
Hence, the gpiochip251 is to be sought; the individual GPIO line number are from 251 to 251+15
56. To find The GPIO found may be operated over sysfs interface in the appropriate GPIO following way: issue the commandcommands:<pre> ls export n=251 # desired GPIO numberecho $n >/sys/busclass/i2c/drivers/pca953xgpio/export and look the output for a line like this: '''7-0027''' and then issue the command:  ls echo out >/sys/class/gpio/gpiochip*gpio$n/direction # desired direction in/device -lout and look the output for a line like this:  cat /sys/class/gpio/gpiochip251gpio$n/device -value # read the input valueecho 1 > ../..sys/..class/gpio/'''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 in the following way:gpio$n/value # write a value for output<b/pre>issue the commands:
export n=251 # desired GPIO number[[category: fitlet2]] echo $n >/sys/class/gpio/export[[category: software]] echo out >/sys/class/gpio/gpio$n/direction # desired direction in/out[[category: Extension boards]] cat /sys/class/gpio/gpio$n/value # read the input value echo 1 > /sys/class/gpio/gpio$n/value # write a value for output[[category: application notes]]
1,586
edits