From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6BA8C4338F for ; Sun, 25 Jul 2021 23:36:47 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 437A560BD3 for ; Sun, 25 Jul 2021 23:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 437A560BD3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=yifangu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 21EBC832B0; Mon, 26 Jul 2021 01:35:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=yifangu.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id E70D383256; Mon, 26 Jul 2021 01:17:04 +0200 (CEST) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8C1718324E for ; Mon, 26 Jul 2021 01:16:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=yifangu.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=gyf304@gmail.com Received: by mail-qk1-f177.google.com with SMTP id c18so7245207qke.2 for ; Sun, 25 Jul 2021 16:16:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iz7iwvM72AsQPcJKQl8xIJA5nGa5ioUTvUj0MjeFcC8=; b=EvCqkrVcVy6VtCJtPYVAd//JwWD+C5Qrh94oM1c8uhsRMV0QOZ9/+4P9/vLOkUhJjM YltxFcx35hUWvamOchiDV+/NKmXJ3PZ3k+5Weyyuz8E34LN6Bj3DXiO6kE+hcdvMvhE2 WCWe540bUXpzsOtDmDKOSbSX/xNVPz6F96Cf/KaUEt3WeUVFMNb4SyjRoArSPr2VNPID EYOw5eb2qJsOCThDW/GWW7UKurn3zytsTqL/Q4PD4gITcjKx2y1CU4hlQ/M45D1xOwM9 hTChG7mtzw1UB0AlVEqX1QsKHgT/QbHFGgNz4x9UfYkhxFRkTOSZJ4GbluuMTyJ5LS61 gjjg== X-Gm-Message-State: AOAM532uWKbUxdXt5TnYvbhIU7YbTvVMoL3YnTzwH36a86wX6KP9IuC3 CuGZM/ZzAF3YUjfWpg3DojDOK0yfJfCahJAS X-Google-Smtp-Source: ABdhPJwX4Ot9NTCmV2s2a4ZGWRPPPy63pH+zkUx5N9IFY3BjjE8xy96VWzXZMdrfzAnkiTQ7tqNWIw== X-Received: by 2002:a05:620a:164b:: with SMTP id c11mr15102637qko.156.1627255007252; Sun, 25 Jul 2021 16:16:47 -0700 (PDT) Received: from yifangu-Virtual-Machine.mshome.net (pool-100-6-159-43.pitbpa.fios.verizon.net. [100.6.159.43]) by smtp.gmail.com with ESMTPSA id u184sm17754694qkd.53.2021.07.25.16.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jul 2021 16:16:46 -0700 (PDT) From: Yifan Gu To: u-boot@lists.denx.de Cc: Yifan Gu , Jagan Teki , Andre Przywara , Icenowy Zheng , George Hilliard Subject: [PATCH 16/27] sunxi: spi: restore bus speed and mode after reset Date: Sun, 25 Jul 2021 19:16:25 -0400 Message-Id: <20210725231636.879913-17-me@yifangu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210725231636.879913-1-me@yifangu.com> References: <20210725231636.879913-1-me@yifangu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 26 Jul 2021 01:32:10 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: George Hilliard The sunxi SPI peripheral driver resets the device completely (disabling clocks and power) when the bus is released and turns it back on when claiming. On the F1C100s (and maybe others), the peripheral resets back to default register settings, losing speed and mode settings. Restore these settings when resetting the peripheral. Signed-off-by: George Hilliard Signed-off-by: Yifan Gu --- drivers/spi/spi-sunxi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-sunxi.c b/drivers/spi/spi-sunxi.c index 4ca5d3a93a..aa392502b7 100644 --- a/drivers/spi/spi-sunxi.c +++ b/drivers/spi/spi-sunxi.c @@ -39,6 +39,10 @@ DECLARE_GLOBAL_DATA_PTR; +/* Forward declarations of some reused functions */ +static int sun4i_spi_set_speed(struct udevice *dev, uint speed); +static int sun4i_spi_set_mode(struct udevice *dev, uint mode); + /* sun4i spi registers */ #define SUN4I_RXDATA_REG 0x00 #define SUN4I_TXDATA_REG 0x04 @@ -304,7 +308,8 @@ err_ahb: static int sun4i_spi_claim_bus(struct udevice *dev) { - struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); + struct udevice *bus = dev->parent; + struct sun4i_spi_priv *priv = dev_get_priv(bus); int ret; ret = sun4i_spi_set_clock(dev->parent, true); @@ -321,6 +326,9 @@ static int sun4i_spi_claim_bus(struct udevice *dev) setbits_le32(SPI_REG(priv, SPI_TCR), SPI_BIT(priv, SPI_TCR_CS_MANUAL) | SPI_BIT(priv, SPI_TCR_CS_ACTIVE_LOW)); + sun4i_spi_set_speed(bus, priv->freq); + sun4i_spi_set_mode(bus, priv->mode); + return 0; } -- 2.25.1