From patchwork Tue Apr 10 22:44:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 10334333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 253F0601A0 for ; Tue, 10 Apr 2018 22:44:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14D7D28536 for ; Tue, 10 Apr 2018 22:44:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09B902853A; Tue, 10 Apr 2018 22:44:54 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4B2628538 for ; Tue, 10 Apr 2018 22:44:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755796AbeDJWov (ORCPT ); Tue, 10 Apr 2018 18:44:51 -0400 Received: from mail.bootlin.com ([62.4.15.54]:34613 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756121AbeDJWoq (ORCPT ); Tue, 10 Apr 2018 18:44:46 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 687962077B; Wed, 11 Apr 2018 00:44:45 +0200 (CEST) Received: from localhost.localdomain (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 04C7A2071B; Wed, 11 Apr 2018 00:44:45 +0200 (CEST) From: Boris Brezillon To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org, Miquel Raynal , Mark Brown , linux-spi@vger.kernel.org Cc: Peter Pan , Frieder Schrempf , Vignesh R , Yogesh Gaur , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Kamal Dasu , Sourav Poddar , Maxime Chevallier Subject: [PATCH v2 03/10] spi: Add an helper to flush the message queue Date: Wed, 11 Apr 2018 00:44:32 +0200 Message-Id: <20180410224439.9260-4-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180410224439.9260-1-boris.brezillon@bootlin.com> References: <20180410224439.9260-1-boris.brezillon@bootlin.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is needed by the spi-mem logic to force all messages that have been queued before a memory operation to be sent before we start the memory operation. We do that in order to guarantee that spi-mem operations do not preempt regular SPI transfers. Signed-off-by: Boris Brezillon --- As for the spi_map/unmap_buf() I'd suggest to move the prototype definition to an internal header file. --- drivers/spi/spi.c | 16 ++++++++++++++++ include/linux/spi/spi.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 308e4c2114d8..d7e046128b3f 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1520,6 +1520,22 @@ static int spi_controller_initialize_queue(struct spi_controller *ctlr) return ret; } +/** + * spi_flush_queue - Send all pending messages in the queue from the callers' + * context + * @ctlr: controller to process queue for + * + * This should be used when one wants to ensure all pending messages have been + * sent before doing something. Is used by the spi-mem code to make sure SPI + * memory operations do not preempt regular SPI transfers that have been queued + * before the spi-mem operation. + */ +void spi_flush_queue(struct spi_controller *ctlr) +{ + if (ctlr->transfer == spi_queued_transfer) + __spi_pump_messages(ctlr, false); +} + /*-------------------------------------------------------------------------*/ #if defined(CONFIG_OF) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index de6fd95a61c5..3489fc9c0410 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -619,6 +619,8 @@ extern int spi_controller_resume(struct spi_controller *ctlr); * Helpers needed by the spi-mem logic. Should not be used outside of * spi-mem.c */ +void spi_flush_queue(struct spi_controller *ctrl); + #ifdef CONFIG_HAS_DMA int spi_map_buf(struct spi_controller *ctlr, struct device *dev, struct sg_table *sgt, void *buf, size_t len,