From patchwork Thu Dec 27 15:13:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovic Desroches X-Patchwork-Id: 10743813 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07ACF13B5 for ; Thu, 27 Dec 2018 15:14:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96D4285E5 for ; Thu, 27 Dec 2018 15:14:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB3FB286B3; Thu, 27 Dec 2018 15:14:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67ACF285E5 for ; Thu, 27 Dec 2018 15:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=s+BgHC5KjQY6p02dUj7S9+1B78esRH45VGW+U9zntHk=; b=CfKd4a8QgoVCPS P842FV0AQQXhVEPDuNMi4D7OXt757fAUyI2AKZnF08mvEvBaj3UXWILBqNAnAKgbSRHfRsGzdOEWP 2ZI6II38fL/3GY/3POanJdJMzi04MCSDTD3QXrNkhlddB/AHEpci3f9GObFaYblOuz5UCDJWcRKcw OAzc1LvLvHB71lqJmdB3SLmuvUmoFq/aH4jmxunoEZIM8yeGqHaMStQb+aqrY99BTGJCGsIuEOgEB kSTOCB5+6UbW8mGYgQGiFUwT4Ne8HIejmwnllePtdx/q1APT1Xvtp6QQpQSqDl1sLO87kPk/D4B4S TZox7LHqCK/b636jt+Sw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcXMP-0006Im-Mq; Thu, 27 Dec 2018 15:14:09 +0000 Received: from esa4.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcXLz-0005t5-3K for linux-arm-kernel@lists.infradead.org; Thu, 27 Dec 2018 15:13:47 +0000 X-IronPort-AV: E=Sophos;i="5.56,405,1539673200"; d="scan'208";a="24405601" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 27 Dec 2018 08:13:23 -0700 Received: from M43218.corp.atmel.com (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.352.0; Thu, 27 Dec 2018 08:13:47 -0700 From: Ludovic Desroches To: , Subject: [PATCH v4 0/3] i2c: at91: slave mode support Date: Thu, 27 Dec 2018 16:13:08 +0100 Message-ID: <20181227151311.20107-1-ludovic.desroches@microchip.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_071343_479513_525A34AD X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexandre.belloni@bootlin.com, wsa@the-dreams.de, me@jue.yt, linux-kernel@vger.kernel.org, Ludovic Desroches , andriy.shevchenko@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP [Ludovic Desroches: see Changes section] Based on the discussion we had on the i2c-linux list [1], I wrote a patch for AT91 hardware and tried to fulfill the Linux I2C slave interface description [2] as good as possible. This enables aforementioned hardware to act as an I2C slave that can be accessed by a remote I2C master. I have tested this patchset successfully on an ATSAMA5D27. ^ 3.3V ^ 3.3V +-----------------------+ | | +-----------------------+ | Slave: ATSAMA5D27 | +-+ +-+ | Master: ATSAMA5D35 | | with i2c-slave-eeprom | | | 100k | | 100k | with i2cset | +-------------------+-+-+ +-+ +-+ +-+-+-------------------+ | | | | | | | +------+---------|---(SDA)---+ | +------------------+---(SCL)-----+ Schematic: Connection of slave and master with 100kOhm pullup resistors. On the master the following BASH script has been used to stress the slave. root@emblinux:~# cat ./stress.sh #!/bin/bash I=0 while true do if i2cset -y -r 1 0x64 0 $I w | grep mismatch then echo "$(date): Error in transmission ${I}" fi ((I++)) if [ $I -eq 65536 ] then I=0 echo "$(date): Sent 65536 transmissions" fi done After running the script for some time I had the following output. To me this looks promising :) root@emblinux:~# ./stress.sh Thu Nov 9 13:58:45 CTE 2017: Sent 65536 transmissions Thu Nov 9 14:35:20 CTE 2017: Sent 65536 transmissions Thu Nov 9 15:12:11 CTE 2017: Sent 65536 transmissions Thu Nov 9 15:49:04 CTE 2017: Sent 65536 transmissions Thu Nov 9 16:26:00 CTE 2017: Sent 65536 transmissions Thu Nov 9 17:03:07 UTC 2017: Sent 65536 transmissions Thu Nov 9 17:40:15 UTC 2017: Sent 65536 transmissions If you have some hardware with an at91-i2c interface included at hand, I really would appreciate if you can run the test script on your hardware and test this driver. Thu Nov 9 17:40:15 UTC 2017: Sent 65536 transmissions If you have some hardware with an at91-i2c interface included at hand, I really would appreciate if you can run the test script on your hardware and test this driver. Best regards Juergen [Ludovic Desroches] Changes in v4: - rebased on next-20181224 - update Kconfig part to state that this feature is experimental. - tested quickly on a single board, SAMA5D2 Xplained, i2c-gpio as master, OK. Changes in v3: - rebase (cherry-pick was enough) - fix checkpatch errors - tests: - hangs with a SAMA5D4 (master and slave on different busses) after about 100 transfers. It's the first time I do this test. - some mismatches with a SAMA5D4 as slave and a SAMA5D2 as master I don't know if it's a regression. I don't remember having seen this behavior previously. I think it's worth taking those patches even if there are some possible bugs. It'll allow to get more people using it and so to consolidate the slave mode support. Changes in v2: - Implemented all suggestions made by Ludovic. (Thank you!) - Reworked the IRQ handler completely. Have a look in patch 3 fort further details. [1] https://marc.info/?t=150824004800001&r=1&w=1 [2] https://www.kernel.org/doc/Documentation/i2c/slave-interface Juergen Fitschen (3): i2c: at91: segregate master mode specific code from probe and init func i2c: at91: split driver into core and master file i2c: at91: added slave mode support MAINTAINERS | 3 +- drivers/i2c/busses/Kconfig | 13 + drivers/i2c/busses/Makefile | 4 + drivers/i2c/busses/i2c-at91-core.c | 380 +++++++++++++++ .../busses/{i2c-at91.c => i2c-at91-master.c} | 453 +----------------- drivers/i2c/busses/i2c-at91-slave.c | 147 ++++++ drivers/i2c/busses/i2c-at91.h | 179 +++++++ 7 files changed, 732 insertions(+), 447 deletions(-) create mode 100644 drivers/i2c/busses/i2c-at91-core.c rename drivers/i2c/busses/{i2c-at91.c => i2c-at91-master.c} (67%) create mode 100644 drivers/i2c/busses/i2c-at91-slave.c create mode 100644 drivers/i2c/busses/i2c-at91.h