diff mbox series

Linux i2c slave EEPROM

Message ID CACPK8XePX_4SNpREUVYPHK+NfpDgM7Lh20tAsWSMKYpjTJ3r=w@mail.gmail.com
State Not Applicable, archived
Headers show
Series Linux i2c slave EEPROM | expand

Commit Message

Joel Stanley Oct. 6, 2017, 6:14 a.m. UTC
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@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@1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/eeprom
/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a100.i2c-bus/i2c-3/3-0050/eeprom

7.  Create some environment variables:
HOST=/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@1e78a000/1e78a0c0.i2c-bus/i2c-2/2-0064/eeprom
SLAVE=/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c@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
diff mbox series

Patch

From cf899ada48e0d2dcdcec2b65bb72a612083736eb Mon Sep 17 00:00:00 2001
From: Joel Stanley <joel@jms.id.au>
Date: Fri, 6 Oct 2017 15:37:18 +1030
Subject: [PATCH] ARM: dts: aspeed-evb: Enable EEPROM i2c slave

This enables I2C2 (/dev/i2c1 in Linux) and I2C3 (/dev/i2c2).

To test, do the following from userspace:

 # echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-1/new-device
 # echo 24c02 0x64 > /sys/bus/i2c/devices/i2c-2/new_device

See the documentation for more details:

 Documentation/i2c/slave-eeprom-backend
 Documentation/i2c/slave-interface

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 arch/arm/boot/dts/aspeed-ast2500-evb.dts | 8 ++++++++
 arch/arm/configs/aspeed_g5_defconfig     | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-ast2500-evb.dts b/arch/arm/boot/dts/aspeed-ast2500-evb.dts
index 0d8579d90e8d..6d34a0cd2bab 100644
--- a/arch/arm/boot/dts/aspeed-ast2500-evb.dts
+++ b/arch/arm/boot/dts/aspeed-ast2500-evb.dts
@@ -79,6 +79,14 @@ 
 	};
 };
 
+&i2c1 {
+	status = "okay";
+};
+
+&i2c2 {
+	status = "okay";
+};
+
 &i2c7 {
 	status = "okay";
 
diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index 078bdbe32ebe..50305c2533f9 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -121,6 +121,8 @@  CONFIG_I2C_MUX=y
 CONFIG_I2C_MUX_PCA9541=y
 CONFIG_I2C_MUX_PCA954x=y
 CONFIG_I2C_ASPEED=y
+CONFIG_I2C_SLAVE=y
+CONFIG_I2C_SLAVE_EEPROM=y
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_SYSFS=y
 CONFIG_GPIO_ASPEED=y
-- 
2.14.1