Set up PCF8574 IO expander drivers on BeagleBone

I have 3 PCF8574A IO expanders connected to my i2c-1 line for BeagleBone Black. After I enable i2c-1 line overlay I see them at addresses 0x38, 0x39, 0x3A

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: 20 – -- – -- – -- – -- – -- – -- – -- –
30: – -- – -- – -- – -- 38 39 3a – -- – -- –
40: – -- – -- – -- – -- UU – -- – -- – -- –
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

Now I can do
echo pcf8574 0x38 > /sys/class/i2c-adapter/i2c-1/new_device and the device shows up under /sys/bus/i2c/device/1-0038/. I wrote a quick c function that connects to the i2c-1 at one of the addresses and set the pin as INPUT/OUTPUTS and read/write values. So all is great but I was told that there are drivers for pcf8574 that can be used to map it to /sys/class/gpio which makes using it easier. Where are these drivers and how do I use them? I found thm here (https://elixir.bootlin.com/linux/v2.6.25/source/drivers/i2c/chips/pcf8574.c). How do I get them onto my board and do I need to map anything for IO expander to GPIO?

So apparently it is a pretty simple process.:

  1. map the address at i2c-1 either manually or using overlay. I used manually for now:

echo pcf8574 0x39 > /sys/class/i2c-adapter/i2c-1/new_device

now when we do dmesg | tail we sould see the following:

[ 7249.401502] pcf857x 1-0039: probed
[ 7249.401581] i2c i2c-1: new_device: Instantiated device pcf8574 at 0x39

Also it will show with the following command:

cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/44e07000.gpio, gpio:
gpio-6 ( |cd ) in hi IRQ
gpio-12 ( |P9_20 ) in lo
gpio-13 ( |P9_19 ) in lo

GPIOs 32-63, platform/4804c000.gpio, gpio:
gpio-53 ( |? ) out lo
gpio-54 ( |? ) out lo
gpio-55 ( |? ) out lo
gpio-56 ( |? ) out lo
gpio-59 ( |clk_mcasp0 ) out lo

GPIOs 64-95, platform/481ac000.gpio, gpio:

GPIOs 96-127, platform/481ae000.gpio, gpio:

GPIOs 496-503, i2c/1-0039, pcf8574, can sleep: <===

GPIOs 504-511, i2c/1-0038, pcf8574, can sleep:

It should also appear as U now:

i2cdetect -y -r 1

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- UU UU 3a – -- – -- –
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- 76 –

  1. Set up the gpio needed:

echo 497 > /sys/class/gpio/export

then cd into it and we should be able to do usual gpio stuff in there