From nobody Fri Dec 19 01:38:58 2025 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 42192C6FA82 for ; Tue, 13 Sep 2022 14:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232871AbiIMOO6 (ORCPT ); Tue, 13 Sep 2022 10:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232604AbiIMON6 (ORCPT ); Tue, 13 Sep 2022 10:13:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48F5C606BD; Tue, 13 Sep 2022 07:10:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B9B8CB80EF7; Tue, 13 Sep 2022 14:10:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35E57C433D6; Tue, 13 Sep 2022 14:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078240; bh=2e8DGinRPwln+bx/cYQ+p2GpkgxOWCvNc5B0LerR980=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=niQpdwwjEASEfLsZwzDrt7T2ChxAl64llPJ9jcfbMdWeKBGEK8jwkRL7X4+vA9Crl 1cDf3tqg5NdX+YFSEiMT3PX3Z337bAqd2xWjrYY5Nvmj8G7raO/gJzpOqHSVQh7lMw 2q1vNTwVctKgNukvD0XwXW7NRdg5poGHN/4bCJYc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Mark Brown , Sasha Levin Subject: [PATCH 5.19 064/192] spi: bitbang: Fix lsb-first Rx Date: Tue, 13 Sep 2022 16:02:50 +0200 Message-Id: <20220913140413.152339198@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Robin Murphy [ Upstream commit 46f7ac3d7892e808c9ba01c39da6bb85cda26ecd ] Shifting the recieved bit by "bits" inserts it at the top of the *currently remaining* Tx data, so we end up accumulating the whole transfer into bit 0 of the output word. Oops. For the algorithm to work as intended, we need to remember where the top of the *original* word was, and shift Rx to there. Fixes: 1847e3046c52 ("spi: gpio: Implement LSB First bitbang support") Signed-off-by: Robin Murphy Link: https://lore.kernel.org/r/28324d8622da80461cce35a82859b003d6f6c4b0.16= 59538737.git.robin.murphy@arm.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-bitbang-txrx.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-bitbang-txrx.h b/drivers/spi/spi-bitbang-txrx.h index 267342dfa7388..2dcbe166df63e 100644 --- a/drivers/spi/spi-bitbang-txrx.h +++ b/drivers/spi/spi-bitbang-txrx.h @@ -116,6 +116,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi, { /* if (cpol =3D=3D 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ =20 + u8 rxbit =3D bits - 1; u32 oldbit =3D !(word & 1); /* clock starts at inactive polarity */ for (; likely(bits); bits--) { @@ -135,7 +136,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi, /* sample LSB (from slave) on leading edge */ word >>=3D 1; if ((flags & SPI_MASTER_NO_RX) =3D=3D 0) - word |=3D getmiso(spi) << (bits - 1); + word |=3D getmiso(spi) << rxbit; setsck(spi, cpol); } return word; @@ -148,6 +149,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi, { /* if (cpol =3D=3D 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ =20 + u8 rxbit =3D bits - 1; u32 oldbit =3D !(word & 1); /* clock starts at inactive polarity */ for (; likely(bits); bits--) { @@ -168,7 +170,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi, /* sample LSB (from slave) on trailing edge */ word >>=3D 1; if ((flags & SPI_MASTER_NO_RX) =3D=3D 0) - word |=3D getmiso(spi) << (bits - 1); + word |=3D getmiso(spi) << rxbit; } return word; } --=20 2.35.1