Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3772425pxv; Mon, 19 Jul 2021 08:24:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyWz+Y/DxjHQKrVyPjoc1Qf9f2WOrT3TjilFACRON4ZDAE+hJoPkF97Qbj+QUM7/ZxpDha X-Received: by 2002:a17:906:5f99:: with SMTP id a25mr28145334eju.101.1626708243649; Mon, 19 Jul 2021 08:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708243; cv=none; d=google.com; s=arc-20160816; b=omfl/MCKssar63OxGvkpyd+SSTnBYvtT1q7jWGqGekFC3MvoaA3VV6LmuKbdj5sEGM 9g0GVcVQ6R/QJLvuSblrL0OcwLokvkNRyUBTQ+i+rFV2BN50kxQVRvvWIV5LnePRvQth GTJUvZGKigPM43U5aK8UmDeoOgzl/z3N7Nih+Mb5Yn0HXP3Cm7Mt8qIcYnOE3Ll2ooTT 0rFwk5mKBjsr9GGUpLj0QSOil7R+x9uh9FZt3PDQ+sZb2rOOJRfi9KfD5W6UUZ42c/C2 L6TDv5jCSNXp5YjfL50LA6VYOUHWiy+dOzaiT6XBUaDOb15oW9q2HK/pT49udocgRnmI ejkQ== 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=0y/6iCld8JHVngbManvO5ro92udRw35hXqnOGoVthLY=; b=ffNb9WN7xShhcKUAZ5DZNZ25zba7EKsOte7+DD5AwwYms+ORO/8eXLO0RzBWa96y2k Fv9GkcIQUBH+/1K9LQ8Yo9k05/sXNyZ8aHgcX2nYGzP9EqJXN7rmGMZZuKPn9KgnDZ5t 7CpQmAOxipPI03ocWjlSITJFJ5pXnVIUivRGMrMWvyCsRK9WXzG35NTFwbA5ThXZZw5G jb6K1bpWljp7AhNGWXGnSTFjIz91n5nBROBeiS15C12Kox/Ry2GixCFOa1XCWfjvZvE+ 2r16oxpB4brbWv0UWl58weAe6MI9YkWCSh8dh1jM+d6SpoSF9ZlrHNZMX4ZtJHBb8Rio O/Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JNXUq3dx; 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 p25si21246360ejb.86.2021.07.19.08.23.40; Mon, 19 Jul 2021 08:24:03 -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=JNXUq3dx; 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 S1343922AbhGSOju (ORCPT + 99 others); Mon, 19 Jul 2021 10:39:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:39348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243631AbhGSO2u (ORCPT ); Mon, 19 Jul 2021 10:28:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7D8160551; Mon, 19 Jul 2021 15:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707299; bh=LWgaDsjxuJiUaMVNUtyez3baQyH7MED6hRzLbuOOj3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNXUq3dxmJjBHO13md8DlES2/EYZ3KREnYVETFYJQ1CPUvQWVD2JEIYRWAQBORsKk d432IL4e4RviBHd+daQ4pOrB+26+xIPVhzlnTfTyIPzQmy+adkboguPdXlZgJdHNfo 40p8ugt2W7OLZWXovhpjhmWuYaLFHnXfLwq4Ndtg= 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 4.9 071/245] spi: spi-sun6i: Fix chipselect/clock bug Date: Mon, 19 Jul 2021 16:50:13 +0200 Message-Id: <20210719144942.701040735@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 17068e62e792..8c3f5a00fd9e 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -251,6 +251,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) @@ -334,7 +338,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