Linux i2c slave EEPROM

Joel Stanley joel at jms.id.au
Fri Oct 6 17:14:02 AEDT 2017


Hello,

Back when reviewing the upstream i2c driver I used the slave-eeprom
support in the kernel to test the slave support. I've had some
questions about this recently, so here are the steps I used on my
ast2500 EVB.

Grab a recent Linux kernel with ASPEED i2c support. I used 4.14 with
my in-progress clock driver applied, but dev-4.10 should work too.

1. Connect I2C1 and I2C2 SCL and SDA lines

The pins are on the south edge of the board, towards the south-west
corner when reading the ASPEED Technolgoy Inc silkscreen up the
correct way. A jumper should be able to reach between them.

2. Apply the attached patch to your tree

$ cd linux-aspeed
$ patch -p1 < 0001-ARM-dts-aspeed-evb-Enable-EEPROM-i2c-slave.patch

3. Build the kernel and fit image. Use your favourite FIT and initrd
or root file system.

$ cd linux-aspeed
$ make aspeed_g5_defconfig
$ make
$ mkimage -f evb.fit evb

4. Boot the 'evb' fit image on your evb

5. Bind some drivers

# echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-1/new-device
# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

# echo 24c02 0x64 > /sys/bus/i2c/devices/i2c-2/new_device
# i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

6. Find the eeprom sysfs files

# find /sys/devices/ -name slave-eeprom
/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c at 1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/slave-eeprom

And the 'host' side of the eeprom is here. The one on bus i2c-3 is the
real EEPROM; ignore it.

#  find /sys/devices -name eeprom
/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c at 1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/eeprom
/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c at 1e78a000/1e78a100.i2c-bus/i2c-3/3-0050/eeprom

7.  Create some environment variables:
HOST=/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c at 1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/eeprom
SLAVE=/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c at 1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/slave-eeprom

8. Write to one, and see it appear in the other

# echo "How about a nice game of chess?" > $SLAVE
# cat $HOST
How about a nice game of chess?
# hexdump -C $HOST
00000000  48 6f 77 20 61 62 6f 75  74 20 61 20 6e 69 63 65  |How about a nice|
00000010  20 67 61 6d 65 20 6f 66  20 63 68 65 73 73 3f 0a  | game of chess?.|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

# echo "You have no chance to survive make your time" > $HOST
# hexdump -C $SLAVE
00000000  59 6f 75 20 68 61 76 65  20 6e 6f 20 63 68 61 6e  |You have no chan|
00000010  63 65 20 74 6f 20 73 75  72 76 69 76 65 20 6d 61  |ce to survive ma|
00000020  6b 65 20 79 6f 75 72 20  74 69 6d 65 0a 00 00 00  |ke your time....|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

Cheers,

Joel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ARM-dts-aspeed-evb-Enable-EEPROM-i2c-slave.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20171006/d851b313/attachment-0001.bin>


More information about the openbmc mailing list