From patchwork Wed May 22 23:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 798185 Delivered-To: patch@linaro.org Received: by 2002:ab3:6414:0:b0:267:d849:ee76 with SMTP id j20csp917572lte; Wed, 22 May 2024 16:32:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV0ULX+RFDnHtJmtvLB+cBOoRaHvlVzO8S6LvGNuJ4H2sidklgl+vxxhMSc/AFtzR8x+maa9HO9gKs1RbAWaonF X-Google-Smtp-Source: AGHT+IFuaScSL0b9QYpCm9iE6vtIdFHYLaK05KBLRlBPg+sOJETWzb28XiP4Q2d5Aj+9beT1mVke X-Received: by 2002:a2e:2c0c:0:b0:2e0:9646:8512 with SMTP id 38308e7fff4ca-2e94959d2d1mr20521401fa.31.1716420774639; Wed, 22 May 2024 16:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716420774; cv=none; d=google.com; s=arc-20160816; b=0Dh6k+FjO3zZMvP7JAfPgloIsctw9Ts4EuuNB8OgDZrTVqHcrPjeYU/LtrTD3fh0BS 75YtX0f9ycSAe7uNqf7FdyH1962tUdNMnc/iB5d48c275V4AWK/p4OQ7CoyQ86U4hxWu Y3iTX9nfnUsw3ag8h6fC9nGaHg5enpDDkVFR+lvR8XB8GWKCgfQ3F/tuMg+uUAM0Gd3F Zzut7zQS0EaGuqKndxmPJso8I7V+ckF2YxuhC4ODGT4LHL0bs8m3g+IICZ7WvkkBm5Ku 6xXAwnOl1BQIIwnI3MISSMDqF+VXHLYC4EIStEAxfQXUP0ycRlaJsWO92lVM+V/yL42l VFyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nW2d4ajBUAfptcYRf7hM/6SH7SxDjRu31sqRJ6zWcGI=; fh=iB12APDNVqSb4KEVcOyNeRUpn2dlxnAefLA6qzL0Rko=; b=ZZoDPLLMrJsYxpNAH+TZOrKCyiWpK7XWhAq7+fYo0aN1LZbpr+foP5E5mp8SWzu1KW z5RZ4ujWlbFrijg+fbH21Vx/IuZStWupno/ic1in42UID+0QgmWYJDsvQGcfuyhRGP1t U0Pa1m/vvdHMtCoEofLSsfBAH56C0e3yFTaVFCNMGJzbQx3DLerCPet1SB1mvoTVzVa4 wcwB3G2T6opXCK9bGTWDf5lkvyfq+hqPfe7ZdDWWCPnjPDFoNq6bKEz10TEZuZxmeoW4 kQ1jAaQRNYfKNR8zU+KuYBkks4p1HRo5pfRqxZaznQQI8cxZFoXvUV+QGNxEMRC7Ohzr FKOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mjumja+f; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5784655f2dbsi66610a12.47.2024.05.22.16.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 16:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mjumja+f; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6008288523; Thu, 23 May 2024 01:31:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mjumja+f"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8C3EA884F1; Thu, 23 May 2024 01:31:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (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 2D5A8884E5 for ; Thu, 23 May 2024 01:31:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6f1016f41e2so2689031a34.1 for ; Wed, 22 May 2024 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716420701; x=1717025501; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nW2d4ajBUAfptcYRf7hM/6SH7SxDjRu31sqRJ6zWcGI=; b=mjumja+fbpkgOAco630YhlHtXH6VD46qLjLj7TMN5M6DceoFgL/9qH2choPYsVetf4 J6vwWdwmf4EnRKTmIjDkkboB3doOPshL70H4qFtb55HNMBz3v2YTKUGiHBEvucLptewJ TRMseomD+0OTynMqEsNumDqVoj1ehwUyp1KUqETKYHpYF6rqD8NJ+bUgW6iC4TiCxx3n xQSwOmJ8bKS5JseUSKnr7VkPBnNuQ5kRUbJSGuglcfYLQ1dFXfGSPalB0sWDVlCkQYlv 1Ud26tof9VrT9VMONpmHUn1M4Kq+Ok17oGWlhDktIZHVoMJQLoPGsd76CJdEGvaDLIrn Cf6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716420701; x=1717025501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nW2d4ajBUAfptcYRf7hM/6SH7SxDjRu31sqRJ6zWcGI=; b=bNZKTEerRqMDHGBH76rr7p5ViXOs0AUHxU3yMkzQe5oK2cIOxlb8lgMmcbgAyYuz2m jwdrfNt5FyH+bMNfPw2oIq6Gi8ovmeoVgcheimSsNX+PXShE3tO0GLASalf8TNa3EuVW uz235whZNfj1/nI1toK5ioDzmq2e/UsasGdE+pLKqm+YuyZGxRNgRNbME8ulgbAJBz8h HkxGN7BZKpEZvwadYZ7a+rBV8swDFUkqceedmH4Jt0V43+vKyRbe2ERTnO/DOfqTue3w BKNXh2rQFWFSL70XP07AuXFXGYcyNmYcDJ0Y4o2Grt+ha1C6bxPISqgc8KA7b3cSwPAE i6+A== X-Forwarded-Encrypted: i=1; AJvYcCUWzQ/oDqG9QwGzF5IquqDR21YRoCsLi+ovP4iCnt6rnKK++THmH6RaFKL42n+MRwmi9bcOgU5z2m/GPlKn2sS3ta2Odw== X-Gm-Message-State: AOJu0YxcSecxvzkf5P+oEpcfDm7T7mdQjnhXk8GphLiVw3jkj4zhZyzh M+52f/Nwz6X5h8y3tKo+v+XmlptOOGy5RvNVUrURBc0s0sZDmrbXGSni6+tSdy0= X-Received: by 2002:a9d:6f96:0:b0:6f0:594a:5d5e with SMTP id 46e09a7af769-6f6669a677dmr3336555a34.18.1716420700880; Wed, 22 May 2024 16:31:40 -0700 (PDT) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0efd5a588sm4641465a34.14.2024.05.22.16.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 16:31:40 -0700 (PDT) From: Sam Protsenko To: Tom Rini , Minkyu Kang , Peng Fan , Jaehoon Chung , Simon Glass Cc: Philipp Tomsich , Kever Yang , Eugeniy Paltsev , Peter Robinson , Jonas Karlman , Yang Xiwen , Ferass El Hafidi , Sean Anderson , u-boot@lists.denx.de, uboot-snps-arc@synopsys.com Subject: [PATCH 06/42] mmc: dw_mmc: Extract clock on/off code into a separate routine Date: Wed, 22 May 2024 18:30:59 -0500 Message-Id: <20240522233135.26835-7-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522233135.26835-1-semen.protsenko@linaro.org> References: <20240522233135.26835-1-semen.protsenko@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean Extract clock control code into a separate routine to avoid code duplication in dwmci_setup_bus(). No functional change. Signed-off-by: Sam Protsenko --- drivers/mmc/dw_mmc.c | 60 ++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index cbfb8d3b8683..40b9b034f793 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -412,11 +412,33 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, return ret; } -static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) +static int dwmci_control_clken(struct dwmci_host *host, bool on) { - u32 div, status; + const u32 val = on ? DWMCI_CLKEN_ENABLE | DWMCI_CLKEN_LOW_PWR : 0; + const u32 cmd_only_clk = DWMCI_CMD_PRV_DAT_WAIT | DWMCI_CMD_UPD_CLK; int timeout = 10000; + u32 status; + + dwmci_writel(host, DWMCI_CLKENA, val); + + /* Inform CIU */ + dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_START | cmd_only_clk); + do { + status = dwmci_readl(host, DWMCI_CMD); + if (timeout-- < 0) { + debug("%s: Timeout!\n", __func__); + return -ETIMEDOUT; + } + } while (status & DWMCI_CMD_START); + + return 0; +} + +static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) +{ + u32 div; unsigned long sclk; + int ret; if ((freq == host->clock) || (freq == 0)) return 0; @@ -439,35 +461,19 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) else div = DIV_ROUND_UP(sclk, 2 * freq); - dwmci_writel(host, DWMCI_CLKENA, 0); + /* Disable clock */ dwmci_writel(host, DWMCI_CLKSRC, 0); + ret = dwmci_control_clken(host, false); + if (ret) + return ret; + /* Set clock to desired speed */ dwmci_writel(host, DWMCI_CLKDIV, div); - dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | - DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); - do { - status = dwmci_readl(host, DWMCI_CMD); - if (timeout-- < 0) { - debug("%s: Timeout!\n", __func__); - return -ETIMEDOUT; - } - } while (status & DWMCI_CMD_START); - - dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE | - DWMCI_CLKEN_LOW_PWR); - - dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | - DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); - - timeout = 10000; - do { - status = dwmci_readl(host, DWMCI_CMD); - if (timeout-- < 0) { - debug("%s: Timeout!\n", __func__); - return -ETIMEDOUT; - } - } while (status & DWMCI_CMD_START); + /* Enable clock */ + ret = dwmci_control_clken(host, true); + if (ret) + return ret; host->clock = freq;