Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2495888pxj; Mon, 10 May 2021 04:30:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2kNkfypC8K5cvAUcpAtgP9YxGt55uma1TleFr29duSjlwzbKnYiuPS6EQYh8ioBwFJxR6 X-Received: by 2002:a05:6638:120f:: with SMTP id n15mr2835691jas.56.1620646243027; Mon, 10 May 2021 04:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620646243; cv=none; d=google.com; s=arc-20160816; b=Sush6HALA6b6mNc+r8Tlsxt0gRQ4f2xgUUPh4tY2DPd/E4uRpQgB5S/dPYcpTh0D4p 2PBdDVyaC/+072vm/jm/OnKHFvtK+kNeg2ffZuMJAPcEHX0z8jC1S2OUj+QuvnjEOmqV oEBBthbIMnDnk1GunBigDfv5WpDQE8vtmLA3dLoAPf0Lhk1DVdGXj1JHCOaeWexPgS+q Vhx7VrwHTFTVOYAfFmLj2OSAjJWl/o/gHhnLRLXdFh7wjF7rP3CY/u3To9S73gqNYFBm yJ/UIkkr4TFX+uyIUo5kA0mBl+jbad0caV3cPyXFswusmbxYMmdTxB94u0OcCeVq7RAb LApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ASbgQ8PscvAS8z+TblwA6SB2+K0tyZH+PdeVbaNh6ek=; b=EHCfqz3zs135KkF9Yb2wrSrAgUHFV3ciFcL7wM5eVZlQmub3Oqy8hsSOmoIlnIvI/B A75nL3USTPXwkJagn1YFZLSz252iR5am/GJQPvtAQvB6wLYWSHcV4dE10xA6Ypgv2BjD biZijwxpdawhryZhwuwKj9flyla3Udbk8uO85wdkhJDFUxXgNJgPtdrR6s217c9SUqQZ qqGIJb7gPuFkWarvatC+sMgjlpnfPlGXTJWsO+GmyNbUioNWn0lM4747IgL4bRQuKxZK YTmH4OK5odlQwyDLJCXer0mUtu380kIbtDk8grBWjWOokeVfnNmRoMONFcL1ohAORjyH iYSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yGr/sJWB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si18657773ilv.73.2021.05.10.04.30.30; Mon, 10 May 2021 04:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yGr/sJWB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240211AbhEJL2p (ORCPT + 99 others); Mon, 10 May 2021 07:28:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234700AbhEJK4x (ORCPT ); Mon, 10 May 2021 06:56:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 288CF619B5; Mon, 10 May 2021 10:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643707; bh=wLgsYTeYI0/bP3368111EJiA4JNU8ZKsRJQkJqT3jaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yGr/sJWBtk89/GUOnujNbOyp7aGzsRQCiw95i6Kk5vROHwix+bgvzGM2Pdfvaxkn2 Qg5fTPnr6MTtudu3ozseO5rTiVRWOOzxIQrtFLewA2hyu8m4iKpWiZXlgx522/dq3T 4JzFifqdMYblTedLOubAFmWQ2LC7yvU6UftfTEMo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Bauer , Mark Brown , Sasha Levin Subject: [PATCH 5.11 124/342] spi: sync up initial chipselect state Date: Mon, 10 May 2021 12:18:34 +0200 Message-Id: <20210510102014.179799693@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Bauer [ Upstream commit d347b4aaa1a042ea528e385d9070b74c77a14321 ] When initially probing the SPI slave device, the call for disabling an SPI device without the SPI_CS_HIGH flag is not applied, as the condition for checking whether or not the state to be applied equals the one currently set evaluates to true. This however might not necessarily be the case, as the chipselect might be active. Add a force flag to spi_set_cs which allows to override this early exit condition. Set it to false everywhere except when called from spi_setup to sync up the initial CS state. Fixes commit d40f0b6f2e21 ("spi: Avoid setting the chip select if we don't need to") Signed-off-by: David Bauer Link: https://lore.kernel.org/r/20210416195956.121811-1-mail@david-bauer.net Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ccca3a7409fa..6f81a3c4c7e0 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -795,7 +795,7 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) /*-------------------------------------------------------------------------*/ -static void spi_set_cs(struct spi_device *spi, bool enable) +static void spi_set_cs(struct spi_device *spi, bool enable, bool force) { bool enable1 = enable; @@ -803,7 +803,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable) * Avoid calling into the driver (or doing delays) if the chip select * isn't actually changing from the last time this was called. */ - if ((spi->controller->last_cs_enable == enable) && + if (!force && (spi->controller->last_cs_enable == enable) && (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH))) return; @@ -1251,7 +1251,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, struct spi_statistics *statm = &ctlr->statistics; struct spi_statistics *stats = &msg->spi->statistics; - spi_set_cs(msg->spi, true); + spi_set_cs(msg->spi, true, false); SPI_STATISTICS_INCREMENT_FIELD(statm, messages); SPI_STATISTICS_INCREMENT_FIELD(stats, messages); @@ -1319,9 +1319,9 @@ fallback_pio: &msg->transfers)) { keep_cs = true; } else { - spi_set_cs(msg->spi, false); + spi_set_cs(msg->spi, false, false); _spi_transfer_cs_change_delay(msg, xfer); - spi_set_cs(msg->spi, true); + spi_set_cs(msg->spi, true, false); } } @@ -1330,7 +1330,7 @@ fallback_pio: out: if (ret != 0 || !keep_cs) - spi_set_cs(msg->spi, false); + spi_set_cs(msg->spi, false, false); if (msg->status == -EINPROGRESS) msg->status = ret; @@ -3410,11 +3410,11 @@ int spi_setup(struct spi_device *spi) */ status = 0; - spi_set_cs(spi, false); + spi_set_cs(spi, false, true); pm_runtime_mark_last_busy(spi->controller->dev.parent); pm_runtime_put_autosuspend(spi->controller->dev.parent); } else { - spi_set_cs(spi, false); + spi_set_cs(spi, false, true); } mutex_unlock(&spi->controller->io_mutex); -- 2.30.2