From patchwork Tue Nov 13 10:22:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680213 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 41CA913BB for ; Tue, 13 Nov 2018 10:23:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 315C929C08 for ; Tue, 13 Nov 2018 10:23:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2590929C0D; Tue, 13 Nov 2018 10:23:51 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 D0A6E29C08 for ; Tue, 13 Nov 2018 10:23:50 +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:References:In-Reply-To: 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: List-Owner; bh=Qddy9SaHGqAg7ZFJNtk4h0WxoE8wj5+eMFdT2mGCtgE=; b=jOIhdtHS1hj9sn 9qKVGkPLJX4PK6mRXtNZ3rSOJZfdLmd8oz4jvmhMtxFavJhfr/XJyKq5KgW8/hh6oj2wNvV8/fbsY ULJfWB4WV0CGKIoEKFdBOEKCr275N3C5nZwQM+ofKQ8nn4g27zv4QV455lO2lNpfhEGc774Z98xQu XfMTzqlaqjixSdniR9mQ9FLi3mgcwxn5/pp9RWib4VqP9mWEIrMpB++l6nUBwjmI5+FtmT8NVZsqx 6GyZpD6QCW8+OdKMcKewrWMj6cfjYPF1G1JKfZiewvO1ZaTnmWRUIWgkzYylg+vKV05f8xMQ2vuG6 mepuXkm7AERU4IPDiYhg==; 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 1gMVrH-0003M5-PS; Tue, 13 Nov 2018 10:23:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqn-0002vW-8H for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=w6m4d+X3g7DjlVyf3mB0uvBeZPQwEj3nclp941m81oo=; b=mWlKESJOCX89ew12IqugvSJUQv D/Mo9VAkT6gQG31aON4FvHTrJJRRh4g5deIlFnqMNu76A3KwkFatErdD3rkQ8Sk+87i+BhVv0GLBI 0Zeyrq2v60/rv5mx50xHmP6i/v63y0KbQryXNzQpvuaoO8cWPRo5M8Vj/KJFtkqaZGEDBAwJ3BH0S LnJKbxjzvMZw21Je2lz3mqPN5bF+/yVVk0ScAnWIwy8gvPlBKEo4JyCyiCLjgbL003e3bnrenaM3S Y9B6II+7eI83RjAUidYCrkFfqAEF/Dq6VEIV4+IqDds/Qiow/WM5rULDZAbilXauDOKpinNss3H8f dovBdcRg==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqh-00065F-14 for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:15 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id E747AC677D; Tue, 13 Nov 2018 11:22:55 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id cACt9Lv0UZny; Tue, 13 Nov 2018 11:22:44 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 4B0D1C6B33; Tue, 13 Nov 2018 11:22:43 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qrSZnMXZyikr; Tue, 13 Nov 2018 11:22:41 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id D4988C677D; Tue, 13 Nov 2018 11:22:40 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 1/6] spi: pxa2xx: dt-bindings: Add spi-slave property Date: Tue, 13 Nov 2018 11:22:23 +0100 Message-Id: <20181113102228.820214-2-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_102311_709805_5692CCC6 X-CRM114-Status: GOOD ( 10.23 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 This is used to indicate that the chip attached to this controller is a SPI master. Signed-off-by: Lubomir Rintel Reviewed-by: Rob Herring Acked-by: Pavel Machek Reviewed-by: Geert Uytterhoeven --- Changes since v2: - Updated the subject line to conform with subsystem customs Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt index 0335a9bd2e8a..89b2832283e3 100644 --- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt +++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt @@ -11,6 +11,7 @@ Required properties: Optional properties: - cs-gpios: list of GPIO chip selects. See the SPI bus bindings, Documentation/devicetree/bindings/spi/spi-bus.txt +- spi-slave: Empty property indicating the SPI controller is used in slave mode. Child nodes represent devices on the SPI bus See ../spi/spi-bus.txt From patchwork Tue Nov 13 10:22:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680215 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 9462913B5 for ; Tue, 13 Nov 2018 10:24:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 815F629C5B for ; Tue, 13 Nov 2018 10:24:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7580F29C6D; Tue, 13 Nov 2018 10:24:14 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 E56C029C5B for ; Tue, 13 Nov 2018 10:24:13 +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:References:In-Reply-To: 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: List-Owner; bh=CUhJgvyaUqEblfhVhPc/IiWLdIsR3qEesgIg3w5YP8g=; b=cyssu+KFozEsed dfDMg5ohh9OKZVXeDmEn1CQVRf6buqpIz+HeAyv9bGD5DDDaMGoHH8qMmPkgZUj9Y45aCL0cwqjDE jlq4EMj2eZAUPWjzeO/NCk9cPuS1uYxMnSx6HGm/KQYLsMijumHr/sYMKpaDDwXvi+oaDuuwoQTwb GJ0Uo/UQHamgmlWdeNMMSt4FSvDjzFx78QtH5wMmtHAxT/IsZry4XSsIqxWpZumMWJ7XDhYOAEGBZ cYvarIHFsf1DRQoGxq/p01yxrXy0y7MdbPuqb/rKg/SDXkSsgHxhqDhcZffs+Unhiu/zB9kcRi/gD 8PzPdUVewoN/sNxCetzg==; 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 1gMVrY-0003f7-4E; Tue, 13 Nov 2018 10:24:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqn-0002vX-9m for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jraHQ8BJMlW7ZqvKNK2kXJUV6TICbe7Bt2MI9dpugUs=; b=jDYE0UMiwdCsICftP5eWvfsEtC RC27Kgx58DctXphHi/kwhHm0FUxxkgr03gMm4O8ktAvpYZ+wWkCajjgtBir0mcoYW5/fPm/vT/rLB JMVZhNIvynp+sY9/3Js/FsKu+s3MD8YKVTg/2rHknL9MFf+t9zyLKdnnqDFb4kcqVLu8OdqNtw52p gCj6HsGAcDP2QDzDW3BWxam1DpyCGwZ9aYpYYvordRKmwtPnnAOmXeg72y2S0KWKAyzCNy+wzOkCQ 48fQkdVFh1YGdwZgxCCOGj99Wy5su0hXGcooj3pMLKX4N9wLioegg04xhfG4Gkh4fMbNjYoV6qxn5 1bR0G0rA==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqh-00065W-HV for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:15 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D0BB9C6B30; Tue, 13 Nov 2018 11:23:01 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id H8x7nBaP2HEV; Tue, 13 Nov 2018 11:22:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 159DFC677C; Tue, 13 Nov 2018 11:22:45 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id V23aKxyqXD7u; Tue, 13 Nov 2018 11:22:41 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 28E5BC6B1F; Tue, 13 Nov 2018 11:22:41 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 2/6] spi: Deal with slaves that return from transfer_one() unfinished Date: Tue, 13 Nov 2018 11:22:24 +0100 Message-Id: <20181113102228.820214-3-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_102311_932683_A7A20558 X-CRM114-Status: GOOD ( 15.83 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 Some drivers, such as spi-pxa2xx return from the transfer_one callback immediately, idicating that the transfer will be finished asynchronously. Normally, spi_transfer_one_message() synchronously waits for the transfer to finish with wait_for_completion_timeout(). For slaves, we don't want the transaction to time out as it can complete in a long time in future. Use wait_for_completion_interruptible() instead. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek Reviewed-by: Geert Uytterhoeven --- Changed since v2: - Corrected the spi_transfer_wait() return value handling to avoid early bail out without the necessary cleanup (thanks Geert Uytterhoeven) drivers/spi/spi.c | 62 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6ca59406b0b7..498d3b9bf3ae 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1037,6 +1037,42 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) return __spi_map_msg(ctlr, msg); } +static int spi_transfer_wait(struct spi_controller *ctlr, + struct spi_message *msg, + struct spi_transfer *xfer) +{ + struct spi_statistics *statm = &ctlr->statistics; + struct spi_statistics *stats = &msg->spi->statistics; + unsigned long long ms = 1; + + if (spi_controller_is_slave(ctlr)) { + if (wait_for_completion_interruptible(&ctlr->xfer_completion)) { + dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n"); + return -EINTR; + } + } else { + ms = 8LL * 1000LL * xfer->len; + do_div(ms, xfer->speed_hz); + ms += ms + 200; /* some tolerance */ + + if (ms > UINT_MAX) + ms = UINT_MAX; + + ms = wait_for_completion_timeout(&ctlr->xfer_completion, + msecs_to_jiffies(ms)); + + if (ms == 0) { + SPI_STATISTICS_INCREMENT_FIELD(statm, timedout); + SPI_STATISTICS_INCREMENT_FIELD(stats, timedout); + dev_err(&msg->spi->dev, + "SPI transfer timed out\n"); + return -ETIMEDOUT; + } + } + + return 0; +} + /* * spi_transfer_one_message - Default implementation of transfer_one_message() * @@ -1050,7 +1086,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, struct spi_transfer *xfer; bool keep_cs = false; int ret = 0; - unsigned long long ms = 1; struct spi_statistics *statm = &ctlr->statistics; struct spi_statistics *stats = &msg->spi->statistics; @@ -1079,28 +1114,9 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, goto out; } - if (ret > 0) { - ret = 0; - ms = 8LL * 1000LL * xfer->len; - do_div(ms, xfer->speed_hz); - ms += ms + 200; /* some tolerance */ - - if (ms > UINT_MAX) - ms = UINT_MAX; - - ms = wait_for_completion_timeout(&ctlr->xfer_completion, - msecs_to_jiffies(ms)); - } - - if (ms == 0) { - SPI_STATISTICS_INCREMENT_FIELD(statm, - timedout); - SPI_STATISTICS_INCREMENT_FIELD(stats, - timedout); - dev_err(&msg->spi->dev, - "SPI transfer timed out\n"); - msg->status = -ETIMEDOUT; - } + ret = spi_transfer_wait(ctlr, msg, xfer); + if (ret < 0) + msg->status = ret; } else { if (xfer->len) dev_err(&msg->spi->dev, From patchwork Tue Nov 13 10:22:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680211 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 C3D8913B5 for ; Tue, 13 Nov 2018 10:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B13E429C08 for ; Tue, 13 Nov 2018 10:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A51CC29C0D; Tue, 13 Nov 2018 10:23:49 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 1C15F29C08 for ; Tue, 13 Nov 2018 10:23:49 +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:References:In-Reply-To: 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: List-Owner; bh=x2Po8bBaU13Dck1jlntkUEJiNCA86qIV8JBP0nE9N1M=; b=QHNB1GjKck/bOz 7Wi7W5nesWfi4Zzp3rLw4t6pC8IruaQ0FjIUz2gmQXZeYCTFg9x5qxhNKHiuvzhleSKxfR8CXPyJ2 l7FxCs6puhhZp4IVLTZOT+VUaNbtStAXbJ0YcaarfrGWxrm7PjfGNZ1fJ90nhEacTyCTgr+miu7NC yTlQ9V+3aBUqbI+nkSspdA8/keLcw2IRfSJ/TjvBtNBXbaskrlehn14eiRHZ5Xqj9RIhTj0Sx+xG7 48fiKy2dJwxKag7A0kdnnK2J5m+tZg7Ni7S48ERkZjLtKLMBrTM3zUULRNBHh8BxKZy5xOUv35p3d x1xehGo194v2k7Yo4cgA==; 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 1gMVqx-00030v-9s; Tue, 13 Nov 2018 10:23:27 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqm-0002un-3k for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9fcituMrL8y/poOzR1KeDbnz8bT7WztH7HELVkaPQmQ=; b=fa5EwBrj8gRQGED/rQ/Ss5vQ2Q k6Fvp1IsMDZJ59jSvjJnqSH0Sq+5qS+cWF7dI1jqCZTDupChL33iY6HSSX8jw+jtZcob+xdOwEtbA VwpZHrOE95TNLDtXLA12aYuUD7J8MWXoX0lx0i/6VD+ieqhNLtccuk3oxFcHOuG9BfGApXAlV2UfK qPyacotCKnT6rqBg03g0wGRaylPN9uj+sScbcMa/6aHOk2yLoObu063QTQeALQ3o+9iRYM0Zy5qxy sj2Ld80v3c+O0EHD2PDqlCtimZJ73CjinBktUeSdHM/zFNH3cpsD1kFQxfo0TMLNFhPoEFAobBDWw iQozKWLw==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqg-000664-W3 for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:13 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id F1CFDC677C; Tue, 13 Nov 2018 11:23:03 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id x7MvGT_M0XLy; Tue, 13 Nov 2018 11:22:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 64B5AC6B61; Tue, 13 Nov 2018 11:22:45 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id re-KJ90Waj78; Tue, 13 Nov 2018 11:22:42 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 7132EC6AF3; Tue, 13 Nov 2018 11:22:41 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 3/6] spi: pxa2xx: Add slave mode support Date: Tue, 13 Nov 2018 11:22:25 +0100 Message-Id: <20181113102228.820214-4-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_102311_718211_CEE3D447 X-CRM114-Status: GOOD ( 17.93 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 Tested on an OLPC XO-1.75 machine, where the Embedded Controller happens to be a SPI master. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek --- drivers/spi/spi-pxa2xx.c | 81 +++++++++++++++++++++++++++++++--- include/linux/spi/pxa2xx_spi.h | 1 + 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 612cc49db28f..54ae77f1227c 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -626,6 +626,11 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) return IRQ_HANDLED; } + if (irq_status & SSSR_TUR) { + int_error_stop(drv_data, "interrupt_transfer: fifo underrun"); + return IRQ_HANDLED; + } + if (irq_status & SSSR_TINT) { pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT); if (drv_data->read(drv_data)) { @@ -1073,6 +1078,11 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, pxa2xx_spi_write(drv_data, SSTO, chip->timeout); } + if (spi_controller_is_slave(master)) { + while (drv_data->write(drv_data)) + ; + } + /* * Release the data by enabling service requests and interrupts, * without changing any mode bits @@ -1082,6 +1092,27 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, return 1; } +static int pxa2xx_spi_slave_abort(struct spi_master *master) +{ + struct driver_data *drv_data = spi_controller_get_devdata(master); + + /* Stop and reset SSP */ + write_SSSR_CS(drv_data, drv_data->clear_sr); + reset_sccr1(drv_data); + if (!pxa25x_ssp_comp(drv_data)) + pxa2xx_spi_write(drv_data, SSTO, 0); + pxa2xx_spi_flush(drv_data); + pxa2xx_spi_write(drv_data, SSCR0, + pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE); + + dev_dbg(&drv_data->pdev->dev, "transfer aborted\n"); + + drv_data->master->cur_msg->status = -EINTR; + spi_finalize_current_transfer(drv_data->master); + + return 0; +} + static void pxa2xx_spi_handle_err(struct spi_controller *master, struct spi_message *msg) { @@ -1209,9 +1240,14 @@ static int setup(struct spi_device *spi) rx_thres = config->rx_threshold; break; default: - tx_thres = TX_THRESH_DFLT; tx_hi_thres = 0; - rx_thres = RX_THRESH_DFLT; + if (spi_controller_is_slave(drv_data->master)) { + tx_thres = 1; + rx_thres = 2; + } else { + tx_thres = TX_THRESH_DFLT; + rx_thres = RX_THRESH_DFLT; + } break; } @@ -1255,6 +1291,12 @@ static int setup(struct spi_device *spi) if (chip_info->enable_loopback) chip->cr1 = SSCR1_LBM; } + if (spi_controller_is_slave(drv_data->master)) { + chip->cr1 |= SSCR1_SCFR; + chip->cr1 |= SSCR1_SCLKDIR; + chip->cr1 |= SSCR1_SFRMDIR; + chip->cr1 |= SSCR1_SPH; + } chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres); chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) @@ -1494,6 +1536,13 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev) } #endif +#if CONFIG_OF + if (of_id) { + pdata->is_slave = of_property_read_bool(pdev->dev.of_node, + "spi-slave"); + } +#endif + ssp->clk = devm_clk_get(&pdev->dev, NULL); ssp->irq = platform_get_irq(pdev, 0); ssp->type = type; @@ -1559,7 +1608,11 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) return -ENODEV; } - master = spi_alloc_master(dev, sizeof(struct driver_data)); + if (platform_info->is_slave) + master = spi_alloc_slave(dev, sizeof(struct driver_data)); + else + master = spi_alloc_master(dev, sizeof(struct driver_data)); + if (!master) { dev_err(&pdev->dev, "cannot alloc spi_master\n"); pxa_ssp_free(ssp); @@ -1581,6 +1634,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) master->setup = setup; master->set_cs = pxa2xx_spi_set_cs; master->transfer_one = pxa2xx_spi_transfer_one; + master->slave_abort = pxa2xx_spi_slave_abort; master->handle_err = pxa2xx_spi_handle_err; master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; @@ -1610,7 +1664,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE; drv_data->dma_cr1 = DEFAULT_DMA_CR1; drv_data->clear_sr = SSSR_ROR | SSSR_TINT; - drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR; + drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS + | SSSR_ROR | SSSR_TUR; } status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), @@ -1658,10 +1713,22 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) pxa2xx_spi_write(drv_data, SSCR0, tmp); break; default: - tmp = SSCR1_RxTresh(RX_THRESH_DFLT) | - SSCR1_TxTresh(TX_THRESH_DFLT); + + if (spi_controller_is_slave(master)) { + tmp = SSCR1_SCFR | + SSCR1_SCLKDIR | + SSCR1_SFRMDIR | + SSCR1_RxTresh(2) | + SSCR1_TxTresh(1) | + SSCR1_SPH; + } else { + tmp = SSCR1_RxTresh(RX_THRESH_DFLT) | + SSCR1_TxTresh(TX_THRESH_DFLT); + } pxa2xx_spi_write(drv_data, SSCR1, tmp); - tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8); + tmp = SSCR0_Motorola | SSCR0_DataSize(8); + if (!spi_controller_is_slave(master)) + tmp |= SSCR0_SCR(2); pxa2xx_spi_write(drv_data, SSCR0, tmp); break; } diff --git a/include/linux/spi/pxa2xx_spi.h b/include/linux/spi/pxa2xx_spi.h index 9ec4c147abbc..b0674e330ef6 100644 --- a/include/linux/spi/pxa2xx_spi.h +++ b/include/linux/spi/pxa2xx_spi.h @@ -25,6 +25,7 @@ struct dma_chan; struct pxa2xx_spi_master { u16 num_chipselect; u8 enable_dma; + bool is_slave; /* DMA engine specific config */ bool (*dma_filter)(struct dma_chan *chan, void *param); From patchwork Tue Nov 13 10:22:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680217 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 02ACA13B5 for ; Tue, 13 Nov 2018 10:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4F7C29C69 for ; Tue, 13 Nov 2018 10:24:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE8FC29C6E; Tue, 13 Nov 2018 10:24:27 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 75C6129C69 for ; Tue, 13 Nov 2018 10:24:27 +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:References:In-Reply-To: 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: List-Owner; bh=tCiBKOM0wCESvaPDn4He8INMtOtLyVu27lSas1G20LA=; b=pa+kTSjoBqNK+d 5/EqRLrysRU1+FGbkFNQEhrmvk9yytRMtJ7F6OjfscBjxZ5TzeFQ9txjgBs2TDMq4E3vrcEA84S7H On8LGCUQ5NIEOD+okGNyRQw7tgGMwem2YkYbF5NFD1YQOBKIG+KbFGYAP7qMmDF3LhC2CfxxAKmqF eJoiTB40M6oCVG8walMwnO+TlML8Y0yiKiBkH2ggZVD5eAnghKF8dWDbzetWkPRdzwnF5I05/FnXX PXRFKORym29IfWCMjUGFx41WeBoJEh6b3zJGoJTGyrvYID+rdT0sRj+3Ff8AL3N3T3D2mHvNYr08D 56tXhAU3WtIu3+7YiaxQ==; 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 1gMVrq-0003w1-S4; Tue, 13 Nov 2018 10:24:22 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqq-0002xN-Pf for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bWCyPvN0hKe0ceK9NmjRvGTZspO6lO2snQGpy3LyrWY=; b=NpmSmCgnCImVF3BR/UMGDcx2EI eC9BEiI8f6fhDPI5A8Huf/A7a3+sxb568QCtgIBYpzTqBip2Xnchl6Lrh8dc0PprENeSG8iLoJNAX w1GoE9yYxcKSPkUBZVPG5YGIqXnr1Mwtr6hVb/pXZNYGFJgT8ERuXi/GJCSqcGayMb1n5b6lyS7G3 4Dlv56ntT1OM662qTei7youwmdHttYefWlZRRUzImuufk3zFWy5ZjxoJwcAGrvlHLuRZup3KvwKgX DnG/fT5OqZ3Ja8WvT24nAdM9t4WgBMV+c3AmU7wKpswGEww1EJaePnPiN3GLvHuUEeOd+RqCOpaig M2OJoT8A==; Received: from shell.v3.sk ([90.176.6.54]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqn-0003BR-JJ for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:18 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 5778CC6B2B; Tue, 13 Nov 2018 11:22:58 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Acdg_hKNJEBN; Tue, 13 Nov 2018 11:22:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D28B7C6B20; Tue, 13 Nov 2018 11:22:45 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id a9zPvshygPKE; Tue, 13 Nov 2018 11:22:42 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id B8AA9C6B22; Tue, 13 Nov 2018 11:22:41 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 4/6] spi: pxa2xx: dt-bindings: Add ready GPIO signal Date: Tue, 13 Nov 2018 11:22:26 +0100 Message-Id: <20181113102228.820214-5-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_052317_774058_71FD8ADB X-CRM114-Status: GOOD ( 10.67 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 This this is used to let the SPI master know that our FIFO is filled and we're ready to service a transfer. Only useful in slave mode. A signal like this is used by an embedded controller on a OLPC XO 1.75 machine, that happens to be a SPI master. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek Reviewed-by: Geert Uytterhoeven --- Changes since v2: - s/ready-gpio/ready-gpios/ - Updated the subject line to conform with subsystem customs Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt index 89b2832283e3..e30e0c2a4bce 100644 --- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt +++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt @@ -12,6 +12,8 @@ Optional properties: - cs-gpios: list of GPIO chip selects. See the SPI bus bindings, Documentation/devicetree/bindings/spi/spi-bus.txt - spi-slave: Empty property indicating the SPI controller is used in slave mode. +- ready-gpios: GPIO used to signal a SPI master that the FIFO is filled + and we're ready to service a transfer. Only useful in slave mode. Child nodes represent devices on the SPI bus See ../spi/spi-bus.txt From patchwork Tue Nov 13 10:22:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680221 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 C115413B5 for ; Tue, 13 Nov 2018 10:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADD5E29C5B for ; Tue, 13 Nov 2018 10:25:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A033229C6D; Tue, 13 Nov 2018 10:25:11 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 2995029C5B for ; Tue, 13 Nov 2018 10:25:11 +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:References:In-Reply-To: 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: List-Owner; bh=XYE/UEW7k4N++6IKk0vLCMu0XEkY6+v26kIYn80nbeY=; b=luPjYAq++vTc0G hxGgqhf+gKeRNGIPJcwXFWyAms39n59/htTEJsLYTFmOWIJVuP6ThfZqLF4oJfouC9s7MUCLJOW0A k0bptMK7yT85KQ7kkMJ6LYts/eJDmlilC5H/0QxH4/MiAxGexdJ8cH3JBBoElhNoyceg11vKPBfQH V9nUhse3qSgGm50hT2CCATXt4sOl92J2/8zIQwQils3uaGA/6yXz3ETj7TQcAFPWCQCVdZsDdnNhC 6SvmZ6Eoee88z1Xx5G6UCM/yFYf8E0WcfFecAHBhe72ZjlXjvFhc6Q4JF63D8nnnrIX3KSn/zkJth rEbpAdkyleWZn8p462GQ==; 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 1gMVsR-0004Rm-Pr; Tue, 13 Nov 2018 10:24:59 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqx-00033H-Kz for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Tv6QIM0JzfZYDKcA1nHyH9CVTOCyyBDGNw0gS6vQyN8=; b=FtcYyhIN5E//tnZ/wUfm5id3i2 znOSjKZgB+vfDqaviBlmth1PnkeI4cWEmyO2eLjVAyJqCUy+IwwFx8ZxCXkJqRBzU3XxkiuiY9dJq SPBWDUKk7cW506Ubjzh5fcANXK5ybtIh0QaOt25xZW4t058p+mS+jv8rnn5PUGThxpE4Rw0hocmhk qHDt8Q8PEEdQalMCsuF9x08Z4muRjBqTleVHt4P+3fF+YpIEgUwrS5rRLIEuz1CyvsOfn0zyDRVOA HRlGw3M5MrUeBrqC/Uy2r1nmfYx4cbQLQoWbfBQGnsyVS3xMLiaa+RWMo8sQd6bbZn+1iG0+GrSh0 jflTYBpw==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqu-000684-JX for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:26 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 884F9C6B32; Tue, 13 Nov 2018 11:23:08 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id BFl_KRM1NhgE; Tue, 13 Nov 2018 11:22:55 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id AFD9DC6AF3; Tue, 13 Nov 2018 11:22:47 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Kr3S2njupcVL; Tue, 13 Nov 2018 11:22:44 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 0D7F4C6B2B; Tue, 13 Nov 2018 11:22:42 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 5/6] spi: pxa2xx: Add ready signal Date: Tue, 13 Nov 2018 11:22:27 +0100 Message-Id: <20181113102228.820214-6-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_102324_746720_8BACC771 X-CRM114-Status: GOOD ( 17.67 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 Strobe a GPIO line when the slave TX FIFO is filled. This is how the Embedded Controller on an OLPC XO-1.75 machine, that happens to be a SPI master, learns that it can initiate a transaction. Signed-off-by: Lubomir Rintel Tested-by: Pavel Machek Reviewed-by: Geert Uytterhoeven --- Changes since v2 - Avoid an useless delay if there's no ready GPIO - Remove useless (int)PTR_ERR(...) casts from pxa2xx_spi_probe() (thanks to Geert Uytterhoeven) drivers/spi/spi-pxa2xx.c | 16 +++++++++++++++- drivers/spi/spi-pxa2xx.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 54ae77f1227c..7e5aab0af501 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -1081,6 +1081,11 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, if (spi_controller_is_slave(master)) { while (drv_data->write(drv_data)) ; + if (drv_data->gpiod_ready) { + gpiod_set_value(drv_data->gpiod_ready, 1); + udelay(1); + gpiod_set_value(drv_data->gpiod_ready, 0); + } } /* @@ -1778,7 +1783,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) if (PTR_ERR(gpiod) == -ENOENT) continue; - status = (int)PTR_ERR(gpiod); + status = PTR_ERR(gpiod); goto out_error_clock_enabled; } else { drv_data->cs_gpiods[i] = gpiod; @@ -1786,6 +1791,15 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) } } + if (platform_info->is_slave) { + drv_data->gpiod_ready = devm_gpiod_get_optional(dev, + "ready", GPIOD_OUT_LOW); + if (IS_ERR(drv_data->gpiod_ready)) { + status = PTR_ERR(drv_data->gpiod_ready); + goto out_error_clock_enabled; + } + } + pm_runtime_set_autosuspend_delay(&pdev->dev, 50); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_active(&pdev->dev); diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h index 513c53aaeab2..4e324da66ef7 100644 --- a/drivers/spi/spi-pxa2xx.h +++ b/drivers/spi/spi-pxa2xx.h @@ -64,6 +64,9 @@ struct driver_data { /* GPIOs for chip selects */ struct gpio_desc **cs_gpiods; + + /* Optional slave FIFO ready signal */ + struct gpio_desc *gpiod_ready; }; struct chip_data { From patchwork Tue Nov 13 10:22:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680219 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 A2F6313B5 for ; Tue, 13 Nov 2018 10:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F14829C5B for ; Tue, 13 Nov 2018 10:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 836A029C6D; Tue, 13 Nov 2018 10:24:44 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 6C55429C5B for ; Tue, 13 Nov 2018 10:24:43 +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:References:In-Reply-To: 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: List-Owner; bh=15Hy4hT+AhtgHiTl48L1FhtsY8QXoh9wbc+UbZpIKLc=; b=Ry+IEbHFnlQohf QGfiGQsFfhHiwJsXmsc5tpaKz4RU7y4IXhQgHudpcz3Ax/YQygMe0uyii2BYUUp1QJqgje4MAm7RJ N9HB5z6kaReACdwjO2ZNGeYte5hNOyfv+AyRm/78wZ0OYvoTJ+FePSl2+uOQamJObszYBXq2jINCV vS3uwVXD89+M+kCSGp22u5QsnfPNlFJF9ZpPdFJLoUhKEbSZrxrD6Fxl6D6iTkoD0TynceK9JYret PbE33hv3EQrFS9o2ormCGjf6AQg7rolc+iy/NffYUJZX+b+kEhpTgO/9rR+Rs/hQ/X+sKhMvYP9+/ P4kAzbPSZRpPTndkmxSw==; 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 1gMVs8-0004C7-Uy; Tue, 13 Nov 2018 10:24:40 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqq-0002xM-Ph for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DThYgUxpKkBeEzyjQKVWBAEg7D9mM6j6uaBzIgLOSrg=; b=szLzcDLy2rgja88aXGcFw3JJ+B 7uN8lBSGFyj1ZsIwY2czy37bnTP9FNCXIIUracD2QndYIB7P43tuJqkpZ7q1E6eFrvkERZ01G/c+z uea83V8rLT/ffZRibzZPFflN2T/BctH9lv87lqsQNWU1YDekCgRgShVmu+nHgz1qFk0bOGpr7OXoN uyGuo0QevA2xujDxeis+MN25Wau4HJ//OqRefsJ3w6vjUsLZ/2tziSLQPlVplT9YOfBKaAA92j6OX PbXdNszlqqTHex8/B/tWueWN+3rHHjccvvgmYPCNoH69ZBYDuNtKKPbLWmUCuqN7T0uMJ2aboGKVs 0UATbctg==; Received: from shell.v3.sk ([90.176.6.54]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqn-0003Bz-Hy for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:18 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 9CD04C6B20; Tue, 13 Nov 2018 11:23:07 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id e9yinJyvnevU; Tue, 13 Nov 2018 11:22:55 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 43AD9C6B1F; Tue, 13 Nov 2018 11:22:48 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 10wfXwgnolqz; Tue, 13 Nov 2018 11:22:44 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 5CACFC6B30; Tue, 13 Nov 2018 11:22:42 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 6/6] spi: pxa2xx: Deal with the leftover garbage in TXFIFO Date: Tue, 13 Nov 2018 11:22:28 +0100 Message-Id: <20181113102228.820214-7-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_052317_742465_6F26E6FB X-CRM114-Status: GOOD ( 13.65 ) 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: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack 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 There doesn't seem to be a way to empty TXFIFO on MMP2. The datasheet is super-secret and the method described in Armada 16x manual won't work: "The TXFIFO and RXFIFO are cleared to 0b0 when the SSPx port is reset or disabled (by writing a 0b0 to the field in the SSP Control Register 0)." # devmem 0xd4037008 # read SSSR 0x0000F204 # devmem 0xd4037000 32 0x07 # SSE off in SSCR0 # devmem 0xd4037000 32 0x87 # SSE on # devmem 0xd4037008 0x0000F204 ^ TXFIFO level is still 2. Sigh. The OLPC 1.75 boot firmware leaves two bytes in the TXFIFO. Those are basically throwaway bytes used in response to the messages from the EC. The OLPC kernel copes with this by power-cycling the hardware. Perhaps the firmware should do this instead. Other than that, there's not much we can do other than complain loudly until the garbage gets drained and discard the actual data... For the OLPC EC this will work just fine and pushing more data to TXFIFO would break further transactions. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek --- Changes since v1: - Fixed a commit message typo (spotted by James Cameron) drivers/spi/spi-pxa2xx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 7e5aab0af501..29e6025f104c 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -1078,6 +1078,20 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, pxa2xx_spi_write(drv_data, SSTO, chip->timeout); } + if (drv_data->ssp_type == MMP2_SSP) { + u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR) + & SSSR_TFL_MASK) >> 8; + + if (tx_level) { + /* On MMP2, flipping SSE doesn't to empty TXFIFO. */ + dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n", + tx_level); + if (tx_level > transfer->len) + tx_level = transfer->len; + drv_data->tx += tx_level; + } + } + if (spi_controller_is_slave(master)) { while (drv_data->write(drv_data)) ;