Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2475749pxj; Mon, 10 May 2021 04:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9LQRTFFRPrH7kxrORVkYdnjytdYb/W3sfEU+Z3EwuD5PnBZzlS/QQUFUpQaFzvXEwXryv X-Received: by 2002:aa7:c143:: with SMTP id r3mr18557850edp.329.1620644532218; Mon, 10 May 2021 04:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620644532; cv=none; d=google.com; s=arc-20160816; b=UjTMbqFB4ZIYI7hepzmaRC2EyEnsYvDBbUOSRjJlBueCJEa7G86eSxkrQl1nLgxXi8 zNO0WguzzX3M7gAOLgHo6ZAaVes+7Pbd0uEzfp8GMGQEF0U0d+HFviMYpQjnfExCQY7U 1OnnkGDewmT8j6bivc9UsMshGId6xAoFrBY62/2yce/EDu5bwpcvFPYSKNrOX6hMDXrj BpgxndlBhgqgNNLgoj4f9FGmOewF9RvRgLH56CtjXhVCuBPayKXI3RHz4dZM2WXvipyx ACP5V9DAFxBdxKaoc7+/muZZwE/CAormRx7K/IUOteofuWQtGyoYf9qWihib03zbxcDK JDEQ== 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=ZFWj7yRMTq8mo4zWco4CxTf/zSKdcKguhcOw92DLW5I=; b=fHDMAzLwHZoridBCQiaB5wXWJVivRmvu+ZkSnTIt1ZwwXOsPkS735y9bHhSrXaZ6jk 4gbRIU7A+ixP7j+1PyZjV+n+FjE8+5oI2MNWjwCgdeuP295sNLyNDM/4Rqrcjq+xspV8 wGwGxi6TIhlsDO3Ja25qOhQh9Rk8P5u/88xcEpL0FB3P0Rq09teiF5pDPNL2TmVZVjbk pyBU4Q8rcLZWBd0oyWQ6OWlFfzNQBqsgIZ+BYaBSJJdCrBkXEsdTUApMSNUoEr83Kv9N kx6aGXS2GNNhmZKVNPUNcScjqm6MOES6y2X9wZif+ffr5A+vBqWvZO8ah55EGH4vk7dM MmGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=avoVDl9i; 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 ba28si12530966edb.402.2021.05.10.04.01.45; Mon, 10 May 2021 04:02:12 -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=avoVDl9i; 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 S232753AbhEJK6V (ORCPT + 99 others); Mon, 10 May 2021 06:58:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:58270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbhEJKpY (ORCPT ); Mon, 10 May 2021 06:45:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 861E7617ED; Mon, 10 May 2021 10:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642930; bh=kkZn66uEtrWL5Vl4tdi9AGp/h8d/LWjsdeIG/LbGNL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avoVDl9i+/YGLlJWdK2W+T5r+SPpw0VBv61BwVYp4xz/z5pbCeMQAkUathUZ16Uag TttaI+wKtrgomMeNZO1Y2KXIQi+c1+3FoP2Bb2Ataw6Bh1tpRv7+mYKrtd2E6utEYo tFinyQnw++ONNHqdk6dq/9iQfy6BilNIwSjgahQc= 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.10 109/299] spi: sync up initial chipselect state Date: Mon, 10 May 2021 12:18:26 +0200 Message-Id: <20210510102008.538475522@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 4257a2d368f7..1eee8b3c1b38 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -787,7 +787,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; @@ -795,7 +795,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; @@ -1243,7 +1243,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); @@ -1311,9 +1311,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); } } @@ -1322,7 +1322,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; @@ -3400,11 +3400,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