From patchwork Wed Feb 9 10:00:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yun Zhou X-Patchwork-Id: 541334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F9BBC433EF for ; Wed, 9 Feb 2022 12:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbiBIMDo (ORCPT ); Wed, 9 Feb 2022 07:03:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232076AbiBIMDQ (ORCPT ); Wed, 9 Feb 2022 07:03:16 -0500 X-Greylist: delayed 3611 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 09 Feb 2022 03:42:44 PST Received: from mail1.wrs.com (unknown-3-146.windriver.com [147.11.3.146]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BFE4C0364A2; Wed, 9 Feb 2022 03:42:44 -0800 (PST) Received: from ala-exchng01.corp.ad.wrs.com (ala-exchng01.corp.ad.wrs.com [147.11.82.252]) by mail1.wrs.com (8.15.2/8.15.2) with ESMTPS id 219A0iO4024427 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 9 Feb 2022 02:00:44 -0800 Received: from ala-exchng01.corp.ad.wrs.com (147.11.82.252) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 9 Feb 2022 02:00:44 -0800 Received: from pek-lpd-ccm3.wrs.com (128.224.156.163) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server id 15.1.2242.12 via Frontend Transport; Wed, 9 Feb 2022 02:00:42 -0800 From: Yun Zhou To: , CC: , , Subject: [PATCH] spi: disable chipselect after complete transfer Date: Wed, 9 Feb 2022 18:00:42 +0800 Message-ID: <20220209100042.22941-1-yun.zhou@windriver.com> X-Mailer: git-send-email 2.26.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org If there are 2 slaves or more on a spi bus, e.g. A and B, we processed a transfer to A, the CS will be selected for A whose 'last_cs_enable' will be recorded to true at the same time. Then we processed a transfer to B, the CS will be switched to B. And then if we transmit data to A again, it will not enable CS back to A because 'last_cs_enable' is true. In addition, if CS is not disabled, Some controllers in automatic transmission state will receive unpredictable data, such as Cadence SPI controller. Signed-off-by: Yun Zhou --- drivers/spi/spi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index fdd530b150a7..ebbba0b08186 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1417,7 +1417,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, struct spi_message *msg) { struct spi_transfer *xfer; - bool keep_cs = false; int ret = 0; struct spi_statistics *statm = &ctlr->statistics; struct spi_statistics *stats = &msg->spi->statistics; @@ -1486,10 +1485,8 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, spi_transfer_delay_exec(xfer); if (xfer->cs_change) { - if (list_is_last(&xfer->transfer_list, + if (!list_is_last(&xfer->transfer_list, &msg->transfers)) { - keep_cs = true; - } else { spi_set_cs(msg->spi, false, false); _spi_transfer_cs_change_delay(msg, xfer); spi_set_cs(msg->spi, true, false); @@ -1500,8 +1497,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, } out: - if (ret != 0 || !keep_cs) - spi_set_cs(msg->spi, false, false); + spi_set_cs(msg->spi, false, false); if (msg->status == -EINPROGRESS) msg->status = ret;