All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chin-Ting Kuo <chin-ting_kuo@aspeedtech.com>
To: <chiawei_wang@aspeedtech.com>, <lukma@denx.de>,
	<seanga2@gmail.com>, <ryan_chen@aspeedtech.com>,
	<BMC-SW@aspeedtech.com>, <jagan@amarulasolutions.com>,
	<vigneshr@ti.com>, <clg@kaod.org>, <u-boot@lists.denx.de>,
	<p.yadav@ti.com>
Subject: [v4 01/12] clk: aspeed: Get HCLK frequency support
Date: Tue, 24 May 2022 13:56:39 +0800	[thread overview]
Message-ID: <20220524055650.1115899-2-chin-ting_kuo@aspeedtech.com> (raw)
In-Reply-To: <20220524055650.1115899-1-chin-ting_kuo@aspeedtech.com>

User can get correct HCLK frequency during driver probe stage
by adding the following configuration in the device tree.
"clocks = <&scu ASPEED_CLK_AHB>".

Signed-off-by: Chin-Ting Kuo <chin-ting_kuo@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
---
v3: Get AHB bus clock frequency from the function parameter.

 drivers/clk/aspeed/clk_ast2500.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/clk/aspeed/clk_ast2500.c b/drivers/clk/aspeed/clk_ast2500.c
index a1b4496ca2..d99964fcd7 100644
--- a/drivers/clk/aspeed/clk_ast2500.c
+++ b/drivers/clk/aspeed/clk_ast2500.c
@@ -29,6 +29,12 @@
 
 #define D2PLL_DEFAULT_RATE	(250 * 1000 * 1000)
 
+/*
+ * AXI/AHB clock selection, taken from Aspeed SDK
+ */
+#define SCU_HWSTRAP_AXIAHB_DIV_SHIFT    9
+#define SCU_HWSTRAP_AXIAHB_DIV_MASK     (0x7 << SCU_HWSTRAP_AXIAHB_DIV_SHIFT)
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /*
@@ -85,6 +91,20 @@ static ulong ast2500_get_clkin(struct ast2500_scu *scu)
 			? 25 * 1000 * 1000 : 24 * 1000 * 1000;
 }
 
+static u32 ast2500_get_hclk(ulong clkin, struct ast2500_scu *scu)
+{
+	u32 hpll_reg = readl(&scu->h_pll_param);
+	ulong axi_div = 2;
+	u32 rate;
+	ulong ahb_div = 1 + ((readl(&scu->hwstrap)
+			      & SCU_HWSTRAP_AXIAHB_DIV_MASK)
+			     >> SCU_HWSTRAP_AXIAHB_DIV_SHIFT);
+
+	rate = ast2500_get_hpll_rate(clkin, hpll_reg);
+
+	return (rate / axi_div / ahb_div);
+}
+
 /**
  * Get current rate or uart clock
  *
@@ -146,6 +166,9 @@ static ulong ast2500_clk_get_rate(struct clk *clk)
 			rate = rate / apb_div;
 		}
 		break;
+	case ASPEED_CLK_AHB:
+		rate = ast2500_get_hclk(clkin, priv->scu);
+		break;
 	case ASPEED_CLK_SDIO:
 		{
 			ulong apb_div = 4 + 4 * ((readl(&priv->scu->clk_sel1)
-- 
2.25.1


  reply	other threads:[~2022-05-24  5:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24  5:56 [v4 00/12] Add ASPEED SPI controller driver Chin-Ting Kuo
2022-05-24  5:56 ` Chin-Ting Kuo [this message]
2022-05-24  5:56 ` [v4 02/12] pinctrl: aspeed: FWSPICS1 and SPI1CS1 pin support Chin-Ting Kuo
2022-05-24  5:56 ` [v4 03/12] spi: aspeed: Add ASPEED SPI controller driver Chin-Ting Kuo
2022-07-01  9:28   ` Cédric Le Goater
2022-07-03  8:47     ` Chin-Ting Kuo
2022-07-04 15:24       ` Cédric Le Goater
2022-07-06 11:06         ` Chin-Ting Kuo
2022-07-07  5:36   ` Joel Stanley
2022-07-08  5:42     ` Chin-Ting Kuo
2022-07-08  8:52       ` Cédric Le Goater
2022-07-11  6:51         ` Chin-Ting Kuo
2022-05-24  5:56 ` [v4 04/12] configs: aspeed: Enable SPI flash features Chin-Ting Kuo
2022-07-01  9:28   ` Cédric Le Goater
2022-07-01 11:50     ` Cédric Le Goater
2022-07-03  9:00       ` Chin-Ting Kuo
2022-07-04  8:01         ` Cédric Le Goater
2022-05-24  5:56 ` [v4 05/12] MAINTAINERS: Add ASPEED SPI driver file Chin-Ting Kuo
2022-07-01 11:52   ` Jagan Teki
2022-08-11  5:20     ` Chin-Ting Kuo
2022-05-24  5:56 ` [v4 06/12] arm: dts: aspeed: Update SPI flash node settings Chin-Ting Kuo
2022-07-01  9:42   ` Cédric Le Goater
2022-07-03  8:54     ` Chin-Ting Kuo
2022-05-24  5:56 ` [v4 07/12] spi-mem: Add dirmap API from Linux Chin-Ting Kuo
2022-07-01  9:36   ` Cédric Le Goater
2022-07-03  8:49     ` Chin-Ting Kuo
2022-07-01 12:04   ` Jagan Teki
2022-08-11  5:19     ` Chin-Ting Kuo
2022-05-24  5:56 ` [v4 08/12] mtd: spi-nor: Use spi-mem dirmap API Chin-Ting Kuo
2022-05-24  5:56 ` [v4 09/12] spi: aspeed: SPI dirmap read support Chin-Ting Kuo
2022-05-24  5:56 ` [v4 10/12] configs: aspeed: Enable CONFIG_SPI_DIRMAP Chin-Ting Kuo
2022-05-24  5:56 ` [v4 11/12] mtd: spi-nor-ids: Add Winbond W25Q512JV ID Chin-Ting Kuo
2022-07-01  9:43   ` Cédric Le Goater
2022-05-24  5:56 ` [v4 12/12] spi: aspeed: Fix bug when SPI_NOR_4B_OPCODES flag is set Chin-Ting Kuo
2022-07-01  9:44   ` Cédric Le Goater
2022-07-03  8:56     ` Chin-Ting Kuo
2022-06-26  4:56 ` [v4 00/12] Add ASPEED SPI controller driver Chin-Ting Kuo
2022-06-26 16:15   ` Cédric Le Goater
2022-06-27  1:41     ` Chin-Ting Kuo
2022-07-01 11:57 ` Jagan Teki
2022-08-11  5:25   ` Chin-Ting Kuo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220524055650.1115899-2-chin-ting_kuo@aspeedtech.com \
    --to=chin-ting_kuo@aspeedtech.com \
    --cc=BMC-SW@aspeedtech.com \
    --cc=chiawei_wang@aspeedtech.com \
    --cc=clg@kaod.org \
    --cc=jagan@amarulasolutions.com \
    --cc=lukma@denx.de \
    --cc=p.yadav@ti.com \
    --cc=ryan_chen@aspeedtech.com \
    --cc=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.