Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2709296pxv; Sun, 11 Jul 2021 23:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLOFpDdgzV1q7zlTnPiHlFjxxI/z7UDA6XaDvSX9677ys3ZMSpysvwN1DEJQ5pruMXRMvI X-Received: by 2002:a02:8241:: with SMTP id q1mr42709678jag.134.1626071138276; Sun, 11 Jul 2021 23:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071138; cv=none; d=google.com; s=arc-20160816; b=KHyw6CUYh/ygvGVVOXQSQ8Wb9grZJp4s+YWSe0OIGAXpcQSNcXmYdyJakPaHs4XTxX 6sb6w4g+O3sHywcxQJaLsv1VKWlFjeoI4lVCBK6wvgxBwTXr9hC1wpffd3ZmhjIPeCOI pG8Mtch1xgZIN2gQsg14ApuMukvx+LiBtWJKjhECBdD5b8X79npr96xJWqRrqninW4V6 y7PrM1XsBi9C1w8UZuyxetnZZOXAuqoXP9C8C1/OxijWlc4QfpFoIO2RiUZ2P/IhHZmj 8bTeKgu4NcHTkP/y/ccK417p5Lbx7Dv5b5RuVzr+LLvlRwbbXJH+C2MGAom+bXdxxQtZ 2R6A== 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=OCpShcZQpXwDMyAHg4ZfNpgzhSOPc6gq82X2TeuSbUU=; b=Sy/pQgQAX66rv6I/UHPSKGFaN3AvJ3AXRzpIA0Aw2V6etlmbV0MM2E7JughDz9anNI fWe1KGO8MWyf4NmzSg3X75hcN9sSKZMrMX43gsuWTHfe+TcD7M/WlrLDBBWpMZLOlGtE 2DFLOrakmC1VgueeakF6Ra6RYf7zAQ3c7A4+L7SsZycQ+4JuVQBM96o9UBP92UYixNiq gDlYyLFSJOiUrvq8iiebUV320Bls3SdfkoxSAWx/FTxsQzbbAGLs8YtUs8ppvBGERbzp I/nduabeh2k29BXKqsCNSqEzu5xlttplphoEqqdeOQyZVbYXCUGaqF4X2FJSwhUERTUS pWaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N6tIhb6M; 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 d1si16066653ila.19.2021.07.11.23.25.26; Sun, 11 Jul 2021 23:25:38 -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=N6tIhb6M; 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 S235326AbhGLG0b (ORCPT + 99 others); Mon, 12 Jul 2021 02:26:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234995AbhGLGY0 (ORCPT ); Mon, 12 Jul 2021 02:24:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6633061167; Mon, 12 Jul 2021 06:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070861; bh=LjeavIVDuUT8GZy4PXD7XhVGklbogZs1tTHwV88Muc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N6tIhb6MJR+xMt8frSVk9DPe4nYatpgkQdscWNdEu7N7g7qj4f3g910cKbZKJ4Vz0 9ztT2CsO2PpSXd/RLRjdqrYJBoR/OPOCiH0hopugLTiSSpu/pPW5CK38SpzVcXLwRB FyKn1LT4pA6Ro1/Mrb9OQqCkiGov8G5MI70wdDKc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mirko Vogt , Ralf Schlatterbeck , Mark Brown , Sasha Levin Subject: [PATCH 5.4 173/348] spi: spi-sun6i: Fix chipselect/clock bug Date: Mon, 12 Jul 2021 08:09:17 +0200 Message-Id: <20210712060723.846339293@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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: Mirko Vogt [ Upstream commit 0d7993b234c9fad8cb6bec6adfaa74694ba85ecb ] The current sun6i SPI implementation initializes the transfer too early, resulting in SCK going high before the transfer. When using an additional (gpio) chipselect with sun6i, the chipselect is asserted at a time when clock is high, making the SPI transfer fail. This is due to SUN6I_GBL_CTL_BUS_ENABLE being written into SUN6I_GBL_CTL_REG at an early stage. Moving that to the transfer function, hence, right before the transfer starts, mitigates that problem. Fixes: 3558fe900e8af (spi: sunxi: Add Allwinner A31 SPI controller driver) Signed-off-by: Mirko Vogt Signed-off-by: Ralf Schlatterbeck Link: https://lore.kernel.org/r/20210614144507.y3udezjfbko7eavv@runtux.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-sun6i.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 956df79035d5..3a8acd78308f 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -297,6 +297,10 @@ static int sun6i_spi_transfer_one(struct spi_master *master, } sun6i_spi_write(sspi, SUN6I_CLK_CTL_REG, reg); + /* Finally enable the bus - doing so before might raise SCK to HIGH */ + reg = sun6i_spi_read(sspi, SUN6I_GBL_CTL_REG); + reg |= SUN6I_GBL_CTL_BUS_ENABLE; + sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, reg); /* Setup the transfer now... */ if (sspi->tx_buf) @@ -405,7 +409,7 @@ static int sun6i_spi_runtime_resume(struct device *dev) } sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, - SUN6I_GBL_CTL_BUS_ENABLE | SUN6I_GBL_CTL_MASTER | SUN6I_GBL_CTL_TP); + SUN6I_GBL_CTL_MASTER | SUN6I_GBL_CTL_TP); return 0; -- 2.30.2