Twitter E-mail RSS
formats

SPI gpio expander with mcp23s08

In this application mcp23s08 is used to expand imx23 gpio’s with GPIO 97,98, …104. SPI slave select is connected on mcp23s08’s address pin A0 so chip select is done when A0 is low. Device tree file is modified as follow:

			ssp1: ssp@80034000 {
				#address-cells = <1>;
				#size-cells = <0>;
				compatible = "fsl,imx23-spi";
				pinctrl-names = "default";
				pinctrl-0 = <&spi2_pins_a>;
				status = "okay"; 
			gpio3: gpio3@0 {
					compatible = "microchip,mcp23s08";
					addr = <0>;
					base = <97>;
					reg = <0>;
					spi-max-frequency = <100000>;
					gpio-controller;
					#gpio-cells = <2>;	
				};
                        };

MCP23S08 is a 8-bit port expander with interrupt output, 2 adddress inputs for up to 4 devices on one bus.
In this code, fields are:
addr represent address occupied with mcp23s08 chip’s (0 – 1st chip, 1 – second chip …)
base address. Since imx32 has 3 banks (gpio0,…,gpio2) by 32 GPIO, base address is chosen to be 97, so extended GPIO numbers are, 97,98,..,104
gpio-controller define this node as controller.

Here are test results:

root@imx233-olinuxino-maxi:~# dmesg | grep spi
[ 1.130000] mcp23s08 spi1.0: chip[0].is_present = true

root@imx233-olinuxino-maxi:~# uname -r
3.12.0-rc2-00083-g4b97280-dirty

root@imx233-olinuxino-maxi:~# echo 97 > /sys/class/gpio/export
root@imx233-olinuxino-maxi:~# echo out > /sys/class/gpio/gpio97/direction

root@imx233-olinuxino-maxi:~# echo 0 > /sys/class/gpio/gpio97/value
root@imx233-olinuxino-maxi:~# echo 1 > /sys/class/gpio/gpio97/value

root@imx233-olinuxino-maxi:~# echo 98 > /sys/class/gpio/export
root@imx233-olinuxino-maxi:~# echo out > /sys/class/gpio/gpio98/direction

root@imx233-olinuxino-maxi:~# echo 1 > /sys/class/gpio/gpio98/value
root@imx233-olinuxino-maxi:~# echo 0 > /sys/class/gpio/gpio98/value

You can get patch to add device tree support for MCP23S08:

wget https://raw.github.com/koliqi/imx23-olinuxino/master/downloads/0001-Add-mcp23s08-SPI-gpio-expander.patch

Creative Commons License
This work by http://g-lab.ca is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License

Home imx23-olinuxino kernel 3.x SPI SPI gpio expander with mcp23s08