Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2537075pxj; Mon, 10 May 2021 05:26:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeuzhs0eUSyjGTMMh140HlmmlAqU2RCPrk57Q+3u8C4X0+2Pst6fVm2EKvWOxERcpTlKZA X-Received: by 2002:a17:906:d1ce:: with SMTP id bs14mr25756463ejb.183.1620649589011; Mon, 10 May 2021 05:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620649589; cv=none; d=google.com; s=arc-20160816; b=K43VkWEi8WzZBn2btkyc5l+8icpIPL78OtdgpFbaGy1Wu+5/78M3LHgufRQiyKNDaK iybrwrVkM6IMk+s77E8fz8ZPUs8GagvcHRVrC3JoYRZw7oa32oi1+QBSnOeMgPy3MdrR h8FRa6ijMY1JaWEPUPmq7jQ987AqKCvHLVoOucasdQmpeKoTe2Eaik/1Q5W2LCBR7hm+ HNcV/TggbbIIKSFWWTb6YR3z6Pv+CZPqAqKsEAOnG2tjhYXNIMZ800aaU4Rv1gfMQis+ bjmNtCOSyaMGi7LsScPzFGPsleKFAoEfaZOQbBEzwh2IPkD52HoGnP1iwA5lusCU97o6 AKBg== 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=xXA9k5bF6tCCXSed8c6L8hvtBPyQX6UBN3wR865Oj0Q=; b=o1/JXWx8vHR0ZtEAFg4PJdKo5JtAHIcD7v1HOguF5ohenatfqnCKa9FCYta/E16dg7 +COObrTCvZbATIsu3BJhrQrmAjSavU2QPY+XOojTOKBli4C3ygUDFGlKWa9oD9m7Ep3C E7FqwDEtFWoUi29rxpKfpqIbTQBPIkZkiSE/fOhlbmdmNlzMVx9tqetFWUT/h2/cDT/V Sw/2j0p92XdVBmv7WJEc5QOCUWrRb8PDHKSXDg4CinaCzCUWc+G2mt166hURA+UXD4An ywnJN5eP+Gwx1000LFptUkJ384qhuTXd3TPo2yZCn4oGXuJzhpDTUZfA1BvzrlqJ/U/w w8Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tfWtdr1I; 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 i12si9849975ejb.750.2021.05.10.05.26.04; Mon, 10 May 2021 05:26:29 -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=tfWtdr1I; 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 S1343567AbhEJMNy (ORCPT + 99 others); Mon, 10 May 2021 08:13:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:44342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236622AbhEJLIV (ORCPT ); Mon, 10 May 2021 07:08:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43631619C4; Mon, 10 May 2021 11:02:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644563; bh=gbsKB9B5AcoCmAoR8F168nw0lZVtjzEqPiyLdEIwu9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tfWtdr1IP4SiwRGu3Be6xtpGXpaJneW0XzXRZsP5bcHVdMejyfCsduDVor8c+V80r 53rEPQxlfRHOJBRnigEqtH+Sn6P3c2xkM3QQ1vQlQTU5AVs2v6+HOXxXZZJ+5Pos4c 8cziRJZ0GrwQp1Pu/4lCj+sRCAmXiz+TZhQokkA4= 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.12 133/384] spi: sync up initial chipselect state Date: Mon, 10 May 2021 12:18:42 +0200 Message-Id: <20210510102019.282051226@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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 b08efe88ccd6..927c2a28011f 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; @@ -1253,7 +1253,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); @@ -1321,9 +1321,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); } } @@ -1332,7 +1332,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; @@ -3423,11 +3423,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