All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jagan Teki <jagan@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 05/25] dm: mmc: sunxi: Refactor ahb gate and clock setup
Date: Mon, 16 Jul 2018 13:49:36 +0530	[thread overview]
Message-ID: <20180716081956.32434-6-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20180716081956.32434-1-jagan@amarulasolutions.com>

Existing dm code for ahb gate clock will be suitable to handle
sun4i,5i,6i and 7i U-Boot specific mmc dt nodes, which are different
from Linux in terms of clocks phandle notation.

U-Boot DT clocks phandle follow direct ahb and clock address on
node definition with specific bit position, but Linux clocks phandle
follow macros to define AHB and MMC clocks so-that the ccu driver
will set the bits accordingly.

Clocks phandle notations in U-Boot for higher Allwinner SoC start
from sun8i, sun50i are following Linux notation to sync with common
node definition along with proper clock driver handling.

So refactor the ahb gate, clock setup to handle all type of Allwinner SoCs.
Since we don't have proper CLK driver yet, this code using driver data
to differentiate require SoC specific data.

This require existing U-Boot mmc DT nodes need to sync with Linux
and the subsequent patches are doing the same.

Cc: Simon Glass <sjg@chromium.org>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 drivers/mmc/sunxi_mmc.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index 7fa1ae8b16..38171b81f3 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -569,8 +569,8 @@ static int sunxi_mmc_probe(struct udevice *dev)
 	struct sunxi_mmc_plat *plat = dev_get_platdata(dev);
 	struct sunxi_mmc_priv *priv = dev_get_priv(dev);
 	struct mmc_config *cfg = &plat->cfg;
+	struct sunxi_ccm_reg *ccm;
 	struct ofnode_phandle_args args;
-	u32 *gate_reg;
 	int bus_width, ret;
 
 	cfg->name = dev->name;
@@ -589,21 +589,38 @@ static int sunxi_mmc_probe(struct udevice *dev)
 	cfg->f_max = 52000000;
 
 	priv->reg = (void *)dev_read_addr(dev);
+	priv->mmc_no = (((uintptr_t)priv->reg / 0x1000) - 0x1C0F);
 
-	/* We don't have a sunxi clock driver so find the clock address here */
 	ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
-					  1, &args);
+					 0, &args);
 	if (ret)
 		return ret;
-	priv->mclkreg = (u32 *)ofnode_get_addr(args.node);
 
-	ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
-					  0, &args);
-	if (ret)
-		return ret;
-	gate_reg = (u32 *)ofnode_get_addr(args.node);
-	setbits_le32(gate_reg, 1 << args.args[0]);
-	priv->mmc_no = args.args[0] - 8;
+	ccm = (struct sunxi_ccm_reg *)ofnode_get_addr(args.node);
+	if (IS_ERR(ccm))
+		return PTR_ERR(ccm);
+
+	/* enable ahb gate */
+	setbits_le32(&ccm->ahb_gate0, BIT(AHB_GATE_OFFSET_MMC(priv->mmc_no)));
+
+	/* find clock reg */
+	switch (priv->mmc_no) {
+	case 0:
+		priv->mclkreg = &ccm->sd0_clk_cfg;
+		break;
+	case 1:
+		priv->mclkreg = &ccm->sd1_clk_cfg;
+		break;
+	case 2:
+		priv->mclkreg = &ccm->sd2_clk_cfg;
+		break;
+	case 3:
+		priv->mclkreg = &ccm->sd3_clk_cfg;
+		break;
+	default:
+		printf("Wrong mmc number %d\n", priv->mmc_no);
+		return -EINVAL;
+	}
 
 	ret = mmc_set_mod_clk(priv, 24000000);
 	if (ret)
-- 
2.17.1

  parent reply	other threads:[~2018-07-16  8:19 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16  8:19 [U-Boot] [PATCH 00/25] sunxi: Enable DM_MMC for U-Boot proper Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 01/25] ARM: dts: sun4i: Sync A10 MMC nodes from Linux Jagan Teki
2018-07-16  9:30   ` Maxime Ripard
2018-07-16 10:28     ` Jagan Teki
2018-07-16 13:37       ` Maxime Ripard
2018-07-16  8:19 ` [U-Boot] [PATCH 02/25] ARM: dts: sun4i: Sync A10 board dts mmc0 node " Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 03/25] ARM: dts: sun4i: Add mmc0 node for iNet 3F Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 04/25] ARM: dts: sun4i: Add mmc0 node for iNet 3W Jagan Teki
2018-07-16  8:19 ` Jagan Teki [this message]
2018-07-16  8:19 ` [U-Boot] [PATCH 06/25] dm: mmc: sunxi: Add ahb reset0 register write Jagan Teki
2018-07-16  9:39   ` Maxime Ripard
2018-07-16  9:55     ` Jagan Teki
2018-07-16 10:02       ` Maxime Ripard
2018-07-16 10:39         ` Jagan Teki
2018-07-16 13:36           ` Maxime Ripard
2018-07-16  8:19 ` [U-Boot] [PATCH 07/25] ARM: dts: sun7i: Sync A20 MMC nodes from Linux Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 08/25] ARM: dts: sun7i: Add mmc0 node for Primo73 tablet Jagan Teki
2018-07-16  9:40   ` Maxime Ripard
2018-07-16 10:03     ` Jagan Teki
2018-07-16 10:09       ` Chen-Yu Tsai
2018-07-16  8:19 ` [U-Boot] [PATCH 09/25] ARM: dts: sun7i: Add mmc0 node for Ainol AW1 Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 10/25] ARM: dts: sun7i: Add mmc0 node for Mele M5 Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 11/25] ARM: dts: sun7i: Add mmc0 node for Toptech BD1078 Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 12/25] sunxi: A20: Enable DM_MMC Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 13/25] mmc: sunxi: Add mmc, emmc H5/A64 compatible Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 14/25] sunxi: H3_H5: Enable DM_MMC Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 15/25] sunxi: A64: " Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 16/25] ARM: dts: sun8i: Update A83T dts(i) files from Linux Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 17/25] mmc: sunxi: Add A83T emmc compatible Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 18/25] sunxi: A83T: Enable DM_MMC Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 19/25] ARM: dts: sun8i: Update R40 dts(i) files from Linux Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 20/25] sunxi: V40: Enable DM_MMC Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 21/25] fastboot: sunxi: Update fastboot mmc default device Jagan Teki
2018-07-16  9:46   ` Maxime Ripard
2018-07-16 10:12     ` Jagan Teki
2018-07-16 11:11       ` Alex Kiernan
2018-07-17 11:57         ` Maxime Ripard
2018-07-18 19:15           ` Alex Kiernan
2018-07-19 13:26             ` Maxime Ripard
2018-07-19 18:11               ` Jagan Teki
2018-07-20  7:39                 ` Maxime Ripard
2018-07-19 18:43               ` Alex Kiernan
2018-07-20  7:34                 ` Maxime Ripard
2018-07-17 11:56       ` Maxime Ripard
2018-07-16  8:19 ` [U-Boot] [PATCH 22/25] env: sunxi: Update default env fat device Jagan Teki
2018-07-16  9:47   ` Maxime Ripard
2018-07-16 10:16     ` Jagan Teki
2018-07-17 11:54       ` Maxime Ripard
2018-07-19 18:21         ` Jagan Teki
2018-07-16  8:19 ` [U-Boot] [PATCH 23/25] sunxi: Use mmc_bootdev=2 for MMC2 boot Jagan Teki
2018-07-16  9:48   ` Maxime Ripard
2018-07-16 10:21     ` Jagan Teki
2018-07-17 11:55       ` Maxime Ripard
2018-07-16  8:19 ` [U-Boot] [DO NOT MERGE PATCH 24/25] sunxi: A13/A31: Enable DM_MMC Jagan Teki
2018-07-16  8:19 ` [U-Boot] [DO NOT MERGE PATCH 25/25] sunxi: A23/A33/V3S: " Jagan Teki
2018-07-16  8:35 ` [U-Boot] [PATCH 00/25] sunxi: Enable DM_MMC for U-Boot proper Chen-Yu Tsai
2018-07-16  9:52   ` Maxime Ripard
2018-07-16 11:08     ` Andre Przywara
2018-07-16 11:42       ` Jagan Teki

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=20180716081956.32434-6-jagan@amarulasolutions.com \
    --to=jagan@amarulasolutions.com \
    --cc=u-boot@lists.denx.de \
    /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.