From patchwork Fri Oct 6 06:14:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 822238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7fZB3XZdz9t4R for ; Fri, 6 Oct 2017 17:17:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JJn2u1g7"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y7fZB0D3xzDql4 for ; Fri, 6 Oct 2017 17:17:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JJn2u1g7"; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4010:c07::22b; helo=mail-lf0-x22b.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JJn2u1g7"; dkim-atps=neutral Received: from mail-lf0-x22b.google.com (mail-lf0-x22b.google.com [IPv6:2a00:1450:4010:c07::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3y7fVW4TcbzDql7 for ; Fri, 6 Oct 2017 17:14:27 +1100 (AEDT) Received: by mail-lf0-x22b.google.com with SMTP id q132so19213902lfe.5 for ; Thu, 05 Oct 2017 23:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=96LKDeLx0UqUrXFu64hyLyc2WTy8CA3XA74IwvxMPn4=; b=JJn2u1g7aKMTWXgLPM/GjKD8Ypnk3HHFRwD864KiiGP0QucOJJZEBGXzrbbgiwLQ2l w+/13gijnbL7vJJhujxkDvp1AFnOT6cNj6X+OzJ0pTiMKdPq01PbCy46sIXrCfDvL0uT bRBALwsB+/8DfX/G0m0G334jZmKG2we6UbaZuUpL6gvNSb9N4c+g01mvv5hERmDLUA0F 5s9UVwZRvjFO98sPNMILSlRaj0CaTbs7TJpFsMQE8Q2NrG/dpG1scayUnI9WXHip24L4 3sPeOHUAM6NYJED6j91Xp95rV7t6gbqIcbvh8KwBAaE7EbF/LaCzoqdvrxn/YCfSNt+k 1DkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=96LKDeLx0UqUrXFu64hyLyc2WTy8CA3XA74IwvxMPn4=; b=Zw9VyJWAXDqXdSY4JBfZDqtUNHMIjZZnc79KiwwFqRfhoLq0ygZDu2XPC1qQ4HDHG/ QMXvjFPJeMYnWtenL1GtjfgJPWye+2ithmb2wL82POZVeh/JBIH2xXj+fLpYHhTjq+ID e49v0sV8Kl3AiEm5ovlhGYGAWUgn2M9yrTSbUH7WDll2dyRaBk6VOx7h/WlYXWjMf1Kh lpORfjyOMsVOotPCKWcyVbGB2EIh96XCDTZg99lPkJZE6mm4icJmuWXf+/NQT9g2HKFi A2LN0JT/6ds2mvE5/X+NjNp+2hhUTe4MJ7dv0i7NhmL11zRkCGSHsdExJeDOQvCJFO7f SQHQ== X-Gm-Message-State: AMCzsaXU3A5K/FgL2L/o6AJs/x/4zL9qD8bZFvhwLQiNDHuO8css5VHR tZQLflhYDtoyxG/LlzPLndvjbAY1Qbmh0YqD+dsemq6m X-Google-Smtp-Source: AOwi7QCejRTRTyo4J86x+iSB3+rfnHuQT+WtGjm+h7NudLM9p/EEbaG2QlE8WR0+VxiwDZcizeHDcNLl4Igo9W0K2VM= X-Received: by 10.25.23.38 with SMTP id n38mr380793lfi.104.1507270463756; Thu, 05 Oct 2017 23:14:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.195.6 with HTTP; Thu, 5 Oct 2017 23:14:02 -0700 (PDT) From: Joel Stanley Date: Fri, 6 Oct 2017 15:44:02 +0930 X-Google-Sender-Auth: wRmkb4Ox6DgRI_eoVffZWL1xu7s Message-ID: Subject: Linux i2c slave EEPROM To: OpenBMC Maillist X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" 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 From cf899ada48e0d2dcdcec2b65bb72a612083736eb Mon Sep 17 00:00:00 2001 From: Joel Stanley 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 --- 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