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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9D0C8C433F5 for ; Sat, 15 Jan 2022 17:44:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5AEE9834B5; Sat, 15 Jan 2022 18:44:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="UOaEi5oy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BA98983494; Sat, 15 Jan 2022 18:44:39 +0100 (CET) Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) (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 8D6A2834B5 for ; Sat, 15 Jan 2022 18:44:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2b.google.com with SMTP id u26so864619qva.7 for ; Sat, 15 Jan 2022 09:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=n/yEeRssRTIpJUPgwNNxYXE0ek4gGbPXkSY8P7NbZxk=; b=UOaEi5oyWZsDi41WxdQuAYDJUPm06Ff/tub+FSRADdSvejpVgwYh5NlE8EdjoWUeJo vvo9J5q7trCNcn7wHIWQw4Memc2LEyMTPmLb0HXw5WwO4X+dTpNdIX2pY+56gnXzBjWV XvPRSKQUoiUjdUiUXrmXl7h5SA8S/9HKWQntUtc1HSs79YkAlTsqCfAwE0sZioBviv/t zJZxC0QJdcYBtJP1SzrnF2BlSgy7Uw98IVmUy5JkcOfe9Ub/1kGaIKiuSzTZWw319fea VWsqaUVjX/IgKddVeiMr/LcK0hpaVByFvJKtoC1YRAlbBT7SJQx9GfxGxFctDoidaqP2 0e3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=n/yEeRssRTIpJUPgwNNxYXE0ek4gGbPXkSY8P7NbZxk=; b=FZmYyb4olCedYg40cr4at2+dLBCN3k02KXkXGDPWUZv5TEy2fZPnS6EQqIUfpOulJk hzyHcmjUYni+Z204FEF2Mn5xVnVsIAUzQmIn0XZtxW5X3uTCqYVti4fbKLRCc+S3rB+Z /cdtzPGUo88YacXyXDsmenzm5yQHmUHfd7/ehbhRR4/6nFd7sbYCIBxWRppew9pKC2my OU+aHCW8XoSasfB5oo/C9OY29CmgFwR2IXghvXLh2yPVZffiOA0ZzgNF2Ms2ThPefPcj Xz1Ra7wUgEW3B0gq/pehmnqw9piL2baYSx1mhqt3hs7F2Fug4FDt6S/nG73dv4MqQOvj cEoA== X-Gm-Message-State: AOAM532I+kmzmw8+4VPD86Y7RQe9gX2PdQomaybjoCfUiipXbU2PpEJY 46waGRC2/HVuqp5DGwVayZ0= X-Google-Smtp-Source: ABdhPJz3vD3HGiAxXT9QI72qW67z/GTSHVNwkt2eQ0clGgQkk6l4pWPdxqgSh1QRwi94cG0oJPne4A== X-Received: by 2002:ad4:5f0d:: with SMTP id fo13mr12567214qvb.90.1642268675499; Sat, 15 Jan 2022 09:44:35 -0800 (PST) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id v12sm5668642qkl.50.2022.01.15.09.44.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 15 Jan 2022 09:44:35 -0800 (PST) Subject: Re: [PATCH v4 2/6] clk: actions: Add SD/MMC clocks To: Amit Singh Tomar , u-boot@lists.denx.de Cc: andre.przywara@arm.com, manivannan.sadhasivam@linaro.org, joe.hershberger@ni.com, jh80.chung@samsung.com, Amit Singh Tomar References: <20211128113225.3992-1-atomar25opensource@gmail.com> <20211128113225.3992-3-atomar25opensource@gmail.com> From: Sean Anderson Message-ID: Date: Sat, 15 Jan 2022 12:44:34 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20211128113225.3992-3-atomar25opensource@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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.2 at phobos.denx.de X-Virus-Status: Clean On 11/28/21 6:32 AM, Amit Singh Tomar wrote: > From: Amit Singh Tomar > > This commit adds SD/MMC clocks, and provides .set/get_rate callbacks > for SD/MMC device present on Actions OWL S700 SoCs. > > Signed-off-by: Amit Singh Tomar > --- > Changes since v3: > * No change. > Changes since v2: > * Fixed the weird div assignment. > * Moved the clock bit for SD from header file > to driver file. > * Removed "< 0" part while comparing unsigned. > Changes since previous version: > * Removed rate *= 2 as this just overclocks. > * Separated the divide by 128 bit from divider value. > * Provided the separate routine to get sd parent rate > based on bit 9. > * Removed unnecessary initialization. > --- > drivers/clk/owl/clk_owl.c | 73 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 73 insertions(+) > > diff --git a/drivers/clk/owl/clk_owl.c b/drivers/clk/owl/clk_owl.c > index f78e5fa3f08d..678fdd5a4540 100644 > --- a/drivers/clk/owl/clk_owl.c > +++ b/drivers/clk/owl/clk_owl.c > @@ -20,6 +20,8 @@ > #include > #include > > +#define CMU_DEVCLKEN0_SD0 BIT(22) Please define this in arch/arm/include/asm/arch-owl/regs_s[79]00.h like CMU_DEVCLKEN1_ETH. > void owl_clk_init(struct owl_clk_priv *priv) > { > u32 bus_clk = 0, core_pll, dev_pll; > @@ -92,6 +94,9 @@ int owl_clk_enable(struct clk *clk) > setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH); > setbits_le32(priv->base + CMU_ETHERNETPLL, 5); > break; > + case CLK_SD0: > + setbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0); > + break; > default: > return -EINVAL; > } > @@ -121,6 +126,9 @@ int owl_clk_disable(struct clk *clk) > case CLK_ETHERNET: > clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH); > break; > + case CLK_SD0: > + clrbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0); > + break; > default: > return -EINVAL; > } > @@ -128,11 +136,72 @@ int owl_clk_disable(struct clk *clk) > return 0; > } > > +static ulong get_sd_parent_rate(struct owl_clk_priv *priv, u32 dev_index) > +{ > + ulong rate; > + u32 reg; > + > + reg = readl(priv->base + (CMU_SD0CLK + dev_index * 0x4)); > + /* Clock output of DEV/NAND_PLL > + * Range: 48M ~ 756M > + * Frequency= PLLCLK * 6 > + */ > + if (reg & 0x200) Please add a define for this bit > + rate = readl(priv->base + CMU_NANDPLL) & 0x7f; ditto for this mask > + else > + rate = readl(priv->base + CMU_DEVPLL) & 0x7f; > + > + rate *= 6000000; > + > + return rate; > +} > + > +static ulong owl_get_sd_clk_rate(struct owl_clk_priv *priv, int sd_index) > +{ > + uint div, val; > + ulong parent_rate = get_sd_parent_rate(priv, sd_index); > + > + val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4)); > + div = (val & 0x1f) + 1; ditto > + > + return (parent_rate / div); > +} > + > +static ulong owl_set_sd_clk_rate(struct owl_clk_priv *priv, ulong rate, > + int sd_index) > +{ > + uint div, val; > + ulong parent_rate = get_sd_parent_rate(priv, sd_index); > + > + if (rate == 0) > + return rate; > + > + div = (parent_rate / rate); no parentheses needed here > + > + val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4)); > + /* Bits 4..0 is used to program div value and bit 8 to enable > + * divide by 128 circuit > + */ The comment is good, but please use defines. Additionally, we are not in the net subsystem, so it should be formatted like /* * Bits 4..0 is used to program div value and bit 8 to enable * divide by 128 circuit */ > + val &= ~0x11f; > + if (div >= 128) { > + div = div / 128; > + val |= 0x100; /* enable divide by 128 circuit */ > + } > + val |= ((div - 1) & 0x1f); > + writel(val, priv->base + (CMU_SD0CLK + sd_index * 0x4)); > + > + return owl_get_sd_clk_rate(priv, 0); > +} > + > static ulong owl_clk_get_rate(struct clk *clk) > { > + struct owl_clk_priv *priv = dev_get_priv(clk->dev); > ulong rate; > > switch (clk->id) { > + case CLK_SD0: > + rate = owl_get_sd_clk_rate(priv, 0); > + break; > default: > return -ENOENT; > } > @@ -142,9 +211,13 @@ static ulong owl_clk_get_rate(struct clk *clk) > > static ulong owl_clk_set_rate(struct clk *clk, ulong rate) > { > + struct owl_clk_priv *priv = dev_get_priv(clk->dev); > ulong new_rate; > > switch (clk->id) { > + case CLK_SD0: > + new_rate = owl_set_sd_clk_rate(priv, rate, 0); > + break; > default: > return -ENOENT; > } >