Skip to contentSkip to conversation

rockchip: rk3036: Move rockchip_get_cru() out of the driver

PATCH New Simon Glass 2 participants 9 messages Oct 2, 2016 – Oct 15, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 rockchip: rk3036: Move rockchip_get_cru() out of the driver

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip clock drivers.

---

Changes in v2: None

 arch/arm/include/asm/arch-rockchip/cru_rk3036.h |  6 +++++
 arch/arm/mach-rockchip/rk3036/Makefile          |  2 ++
 arch/arm/mach-rockchip/rk3036/clk_rk3036.c      | 33 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk_rk3036.c               | 24 +-----------------
 4 files changed, 42 insertions(+), 23 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/rk3036/clk_rk3036.c
arch/arm/include/asm/arch-rockchip/cru_rk3036.h +6 -0
index 7ecc8ee..aaef4b9 100644
@@ -24,6 +24,12 @@
 #define PERI_HCLK_HZ	148500000
 #define PERI_PCLK_HZ	74250000
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3036_clk_priv {
+	struct rk3036_cru *cru;
+	ulong rate;
+};
+
 struct rk3036_cru {
 	struct rk3036_pll {
 		unsigned int con0;
arch/arm/mach-rockchip/rk3036/Makefile +2 -0
index 916a7a4..20d28f7 100644
@@ -4,6 +4,8 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
+obj-y += clk_rk3036.o
+
 ifndef CONFIG_SPL_BUILD
 obj-y += syscon_rk3036.o
 endif
arch/arm/mach-rockchip/rk3036/clk_rk3036.c new file +33 -0
new file mode 100644
index 0000000..6a06afb
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <syscon.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3036.h>
+
+int rockchip_get_clk(struct udevice **devp)
+{
+	return uclass_get_device_by_driver(UCLASS_CLK,
+			DM_GET_DRIVER(rockchip_rk3036_cru), devp);
+}
+
+void *rockchip_get_cru(void)
+{
+	struct rk3036_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3036.c +1 -23
index 8899b0c..7e3bf96 100644
@@ -19,11 +19,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct rk3036_clk_priv {
-	struct rk3036_cru *cru;
-	ulong rate;
-};
-
 enum {
 	VCO_MAX_HZ	= 2400U * 1000000,
 	VCO_MIN_HZ	= 600 * 1000000,
@@ -49,23 +44,6 @@ enum {
 static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 3, 1);
 static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2, 1);
 
-void *rockchip_get_cru(void)
-{
-	struct udevice *dev;
-	fdt_addr_t addr;
-	int ret;
-
-	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	addr = dev_get_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
-		return ERR_PTR(-EINVAL);
-
-	return (void *)addr;
-}
-
 static int rkclk_set_pll(struct rk3036_cru *cru, enum rk_clk_id clk_id,
 			 const struct pll_div *div)
 {
@@ -371,7 +349,7 @@ static const struct udevice_id rk3036_clk_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(clk_rk3036) = {
+U_BOOT_DRIVER(rockchip_rk3036_cru) = {
 	.name		= "clk_rk3036",
 	.id		= UCLASS_CLK,
 	.of_match	= rk3036_clk_ids,
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw

PATCH v2 2/3 rockchip: rk3399: Move rockchip_get_cru() out of the driver

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip clock drivers.

---

Changes in v2: None

 arch/arm/include/asm/arch-rockchip/cru_rk3399.h |  6 +++++
 arch/arm/mach-rockchip/rk3399/Makefile          |  1 +
 arch/arm/mach-rockchip/rk3399/clk_rk3399.c      | 33 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk_rk3399.c               | 24 +-----------------
 4 files changed, 41 insertions(+), 23 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/rk3399/clk_rk3399.c
arch/arm/include/asm/arch-rockchip/cru_rk3399.h +6 -0
index 6776e48..98fba2b 100644
@@ -9,6 +9,12 @@
 
 #include <common.h>
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3399_clk_priv {
+	struct rk3399_cru *cru;
+	ulong rate;
+};
+
 struct rk3399_pmucru {
 	u32 ppll_con[6];
 	u32 reserved[0x1a];
arch/arm/mach-rockchip/rk3399/Makefile +1 -0
index 607f9c9..98ebeac 100644
@@ -4,5 +4,6 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
+obj-y += clk_rk3399.o
 obj-y += rk3399.o
 obj-y += syscon_rk3399.o
arch/arm/mach-rockchip/rk3399/clk_rk3399.c new file +33 -0
new file mode 100644
index 0000000..7663591
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <syscon.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3399.h>
+
+int rockchip_get_clk(struct udevice **devp)
+{
+	return uclass_get_device_by_driver(UCLASS_CLK,
+			DM_GET_DRIVER(rockchip_rk3399_pmuclk), devp);
+}
+
+void *rockchip_get_cru(void)
+{
+	struct rk3399_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3399.c +1 -23
index ea0ce2a..2e87e4b 100644
@@ -18,11 +18,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct rk3399_clk_priv {
-	struct rk3399_cru *cru;
-	ulong rate;
-};
-
 struct rk3399_pmuclk_priv {
 	struct rk3399_pmucru *pmucru;
 };
@@ -780,23 +775,6 @@ static struct clk_ops rk3399_clk_ops = {
 	.set_rate = rk3399_clk_set_rate,
 };
 
-void *rockchip_get_cru(void)
-{
-	struct udevice *dev;
-	fdt_addr_t *addr;
-	int ret;
-
-	ret = uclass_get_device_by_name(UCLASS_CLK, "clk_rk3399", &dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	addr = dev_get_addr_ptr(dev);
-	if ((fdt_addr_t)addr == FDT_ADDR_T_NONE)
-		return ERR_PTR(-EINVAL);
-
-	return addr;
-}
-
 static int rk3399_clk_probe(struct udevice *dev)
 {
 	struct rk3399_clk_priv *priv = dev_get_priv(dev);
@@ -990,7 +968,7 @@ static const struct udevice_id rk3399_pmuclk_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pmuclk_rk3399) = {
+U_BOOT_DRIVER(rockchip_rk3399_pmuclk) = {
 	.name		= "pmuclk_rk3399",
 	.id		= UCLASS_CLK,
 	.of_match	= rk3399_pmuclk_ids,
Signature · 1 line
2.8.0.rc3.226.g39d4020
#2 lore raw

PATCH v2 2/3 rockchip: rk3399: Move rockchip_get_cru() out of the driver

Hi Simon,

Quoted 126 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip clock drivers.

---

Changes in v2: None

  arch/arm/include/asm/arch-rockchip/cru_rk3399.h |  6 +++++
  arch/arm/mach-rockchip/rk3399/Makefile          |  1 +
  arch/arm/mach-rockchip/rk3399/clk_rk3399.c      | 33 +++++++++++++++++++++++++
  drivers/clk/rockchip/clk_rk3399.c               | 24 +-----------------
  4 files changed, 41 insertions(+), 23 deletions(-)

create mode 100644 arch/arm/mach-rockchip/rk3399/clk_rk3399.c

arch/arm/include/asm/arch-rockchip/cru_rk3399.h +6 -0
index 6776e48..98fba2b 100644
@@ -9,6 +9,12 @@
 
  #include <common.h>
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3399_clk_priv {
+	struct rk3399_cru *cru;
+	ulong rate;
+};
+
  struct rk3399_pmucru {
  	u32 ppll_con[6];
  	u32 reserved[0x1a];
arch/arm/mach-rockchip/rk3399/Makefile +1 -0
index 607f9c9..98ebeac 100644
@@ -4,5 +4,6 @@
  # SPDX-License-Identifier:     GPL-2.0+
  #
 
+obj-y += clk_rk3399.o
  obj-y += rk3399.o
  obj-y += syscon_rk3399.o
arch/arm/mach-rockchip/rk3399/clk_rk3399.c new file +33 -0
new file mode 100644
index 0000000..7663591
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <syscon.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3399.h>
+
+int rockchip_get_clk(struct udevice **devp)
+{
+	return uclass_get_device_by_driver(UCLASS_CLK,
+			DM_GET_DRIVER(rockchip_rk3399_pmuclk), devp);
+}
+
+void *rockchip_get_cru(void)
+{
+	struct rk3399_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3399.c +0 -22
index ea0ce2a..2e87e4b 100644
@@ -18,11 +18,6 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-struct rk3399_clk_priv {
-	struct rk3399_cru *cru;
-	ulong rate;
-};
-
  struct rk3399_pmuclk_priv {
  	struct rk3399_pmucru *pmucru;
  };
@@ -780,23 +775,6 @@ static struct clk_ops rk3399_clk_ops = {
  	.set_rate = rk3399_clk_set_rate,
  };
 
-void *rockchip_get_cru(void)
-{
-	struct udevice *dev;
-	fdt_addr_t *addr;
-	int ret;
-
-	ret = uclass_get_device_by_name(UCLASS_CLK, "clk_rk3399", &dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	addr = dev_get_addr_ptr(dev);
-	if ((fdt_addr_t)addr == FDT_ADDR_T_NONE)
-		return ERR_PTR(-EINVAL);
-
-	return addr;
-}
-
  static int rk3399_clk_probe(struct udevice *dev)
  {
  	struct rk3399_clk_priv *priv = dev_get_priv(dev);

drivers/clk/rockchip/clk_rk3399.c static const struct udevice_id rk3399_pmuclk_ids[] = { · line 974

Quoted 8 lines
drivers/clk/rockchip/clk_rk3399.c +1 -1
@@ -990,7 +968,7 @@ static const struct udevice_id rk3399_pmuclk_ids[] = {
  	{ }
  };
 
-U_BOOT_DRIVER(pmuclk_rk3399) = {
+U_BOOT_DRIVER(rockchip_rk3399_pmuclk) = {
  	.name		= "pmuclk_rk3399",
  	.id		= UCLASS_CLK,
  	.of_match	= rk3399_pmuclk_ids,

Thanks,
- Kever

#3 lore raw

PATCH v2 2/3 rockchip: rk3399: Move rockchip_get_cru() out of the driver

Quoted 25 lines · Kever Yang

Hi Simon,

Quoted 21 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip
clock drivers.

---

Changes in v2: None

  arch/arm/include/asm/arch-rockchip/cru_rk3399.h |  6 +++++
  arch/arm/mach-rockchip/rk3399/Makefile          |  1 +
  arch/arm/mach-rockchip/rk3399/clk_rk3399.c      | 33
+++++++++++++++++++++++++
  drivers/clk/rockchip/clk_rk3399.c               | 24 +-----------------
  4 files changed, 41 insertions(+), 23 deletions(-)

create mode 100644 arch/arm/mach-rockchip/rk3399/clk_rk3399.c

[...]

Quoted 1 line

Applied to u-boot-rockchip

#4 lore raw

PATCH v2 3/3 rockchip: rk3288: Move rockchip_get_cru() out of the driver

In reply to Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

---

Changes in v2:
- Rebase to mainline and fix resulting build error
- Add a similar change for rk3036 and rk3399

 arch/arm/include/asm/arch-rockchip/cru_rk3288.h |  7 +++++++
 arch/arm/mach-rockchip/rk3288/clk_rk3288.c      | 16 ++++++++++++++++
 drivers/clk/rockchip/clk_rk3288.c               | 21 ---------------------
 3 files changed, 23 insertions(+), 21 deletions(-)
arch/arm/include/asm/arch-rockchip/cru_rk3288.h +7 -0
index 8a8ca9c..d575f4a 100644
@@ -25,6 +25,13 @@
 #define PERI_HCLK_HZ	148500000
 #define PERI_PCLK_HZ	74250000
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3288_clk_priv {
+	struct rk3288_grf *grf;
+	struct rk3288_cru *cru;
+	ulong rate;
+};
+
 struct rk3288_cru {
 	struct rk3288_pll {
 		u32 con0;
arch/arm/mach-rockchip/rk3288/clk_rk3288.c +16 -0
index 2099e34..a45b923 100644
@@ -9,9 +9,25 @@
 #include <dm.h>
 #include <syscon.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3288.h>
 
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
 			DM_GET_DRIVER(rockchip_rk3288_cru), devp);
 }
+
+void *rockchip_get_cru(void)
+{
+	struct rk3288_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3288.c +0 -21
index bd71a96..ed97e87 100644
@@ -30,12 +30,6 @@ struct rk3288_clk_plat {
 #endif
 };
 
-struct rk3288_clk_priv {
-	struct rk3288_grf *grf;
-	struct rk3288_cru *cru;
-	ulong rate;
-};
-
 struct pll_div {
 	u32 nr;
 	u32 nf;
@@ -140,21 +134,6 @@ static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 1);
 static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2);
 static const struct pll_div cpll_init_cfg = PLL_DIVISORS(CPLL_HZ, 1, 2);
 
-void *rockchip_get_cru(void)
-{
-	struct rk3288_clk_priv *priv;
-	struct udevice *dev;
-	int ret;
-
-	ret = rockchip_get_clk(&dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	priv = dev_get_priv(dev);
-
-	return priv->cru;
-}
-
 static int rkclk_set_pll(struct rk3288_cru *cru, enum rk_clk_id clk_id,
 			 const struct pll_div *div)
 {
Signature · 1 line
2.8.0.rc3.226.g39d4020
#5 lore raw

PATCH v2 3/3 rockchip: rk3288: Move rockchip_get_cru() out of the driver

Hi Simon,

Quoted 92 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

---

Changes in v2:
- Rebase to mainline and fix resulting build error
- Add a similar change for rk3036 and rk3399

  arch/arm/include/asm/arch-rockchip/cru_rk3288.h |  7 +++++++
  arch/arm/mach-rockchip/rk3288/clk_rk3288.c      | 16 ++++++++++++++++
  drivers/clk/rockchip/clk_rk3288.c               | 21 ---------------------
  3 files changed, 23 insertions(+), 21 deletions(-)
arch/arm/include/asm/arch-rockchip/cru_rk3288.h +7 -0
index 8a8ca9c..d575f4a 100644
@@ -25,6 +25,13 @@
  #define PERI_HCLK_HZ	148500000
  #define PERI_PCLK_HZ	74250000
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3288_clk_priv {
+	struct rk3288_grf *grf;
+	struct rk3288_cru *cru;
+	ulong rate;
+};
+
  struct rk3288_cru {
  	struct rk3288_pll {
  		u32 con0;
arch/arm/mach-rockchip/rk3288/clk_rk3288.c +16 -0
index 2099e34..a45b923 100644
@@ -9,9 +9,25 @@
  #include <dm.h>
  #include <syscon.h>
  #include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3288.h>
 
  int rockchip_get_clk(struct udevice **devp)
  {
  	return uclass_get_device_by_driver(UCLASS_CLK,
  			DM_GET_DRIVER(rockchip_rk3288_cru), devp);
  }
+
+void *rockchip_get_cru(void)
+{
+	struct rk3288_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3288.c +0 -14
index bd71a96..ed97e87 100644
@@ -30,12 +30,6 @@ struct rk3288_clk_plat {
  #endif
  };
 
-struct rk3288_clk_priv {
-	struct rk3288_grf *grf;
-	struct rk3288_cru *cru;
-	ulong rate;
-};
-
  struct pll_div {
  	u32 nr;
  	u32 nf;
@@ -140,21 +134,6 @@ static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 1);
  static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2);
  static const struct pll_div cpll_init_cfg = PLL_DIVISORS(CPLL_HZ, 1, 2);
 
-void *rockchip_get_cru(void)
-{
-	struct rk3288_clk_priv *priv;
-	struct udevice *dev;
-	int ret;
-
-	ret = rockchip_get_clk(&dev);
-	if (ret)

drivers/clk/rockchip/clk_rk3288.c static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 1); · line 139

Quoted 10 lines
drivers/clk/rockchip/clk_rk3288.c +0 -7
-		return ERR_PTR(ret);
-
-	priv = dev_get_priv(dev);
-
-	return priv->cru;
-}
-
  static int rkclk_set_pll(struct rk3288_cru *cru, enum rk_clk_id clk_id,
  			 const struct pll_div *div)
  {

Thanks,
- Kever

#6 lore raw

PATCH v2 3/3 rockchip: rk3288: Move rockchip_get_cru() out of the driver

Quoted 20 lines · Kever Yang

Hi Simon,

Quoted 16 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

---

Changes in v2:
- Rebase to mainline and fix resulting build error
- Add a similar change for rk3036 and rk3399

  arch/arm/include/asm/arch-rockchip/cru_rk3288.h |  7 +++++++
  arch/arm/mach-rockchip/rk3288/clk_rk3288.c      | 16 ++++++++++++++++
  drivers/clk/rockchip/clk_rk3288.c               | 21
---------------------
  3 files changed, 23 insertions(+), 21 deletions(-)

[...]

Quoted 7 lines

Thanks,
- Kever

Applied to u-boot-rockchip

#7 lore raw

PATCH v2 1/3 rockchip: rk3036: Move rockchip_get_cru() out of the driver

In reply to Simon Glass

Hi Simon,

Quoted 128 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip clock drivers.

---

Changes in v2: None

  arch/arm/include/asm/arch-rockchip/cru_rk3036.h |  6 +++++
  arch/arm/mach-rockchip/rk3036/Makefile          |  2 ++
  arch/arm/mach-rockchip/rk3036/clk_rk3036.c      | 33 +++++++++++++++++++++++++
  drivers/clk/rockchip/clk_rk3036.c               | 24 +-----------------
  4 files changed, 42 insertions(+), 23 deletions(-)

create mode 100644 arch/arm/mach-rockchip/rk3036/clk_rk3036.c

arch/arm/include/asm/arch-rockchip/cru_rk3036.h +6 -0
index 7ecc8ee..aaef4b9 100644
@@ -24,6 +24,12 @@
  #define PERI_HCLK_HZ	148500000
  #define PERI_PCLK_HZ	74250000
 
+/* Private data for the clock driver - used by rockchip_get_cru() */
+struct rk3036_clk_priv {
+	struct rk3036_cru *cru;
+	ulong rate;
+};
+
  struct rk3036_cru {
  	struct rk3036_pll {
  		unsigned int con0;
arch/arm/mach-rockchip/rk3036/Makefile +2 -0
index 916a7a4..20d28f7 100644
@@ -4,6 +4,8 @@
  # SPDX-License-Identifier:     GPL-2.0+
  #
 
+obj-y += clk_rk3036.o
+
  ifndef CONFIG_SPL_BUILD
  obj-y += syscon_rk3036.o
  endif
arch/arm/mach-rockchip/rk3036/clk_rk3036.c new file +33 -0
new file mode 100644
index 0000000..6a06afb
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 Google, Inc
+ * Written by Simon Glass <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <syscon.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/cru_rk3036.h>
+
+int rockchip_get_clk(struct udevice **devp)
+{
+	return uclass_get_device_by_driver(UCLASS_CLK,
+			DM_GET_DRIVER(rockchip_rk3036_cru), devp);
+}
+
+void *rockchip_get_cru(void)
+{
+	struct rk3036_clk_priv *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = rockchip_get_clk(&dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	priv = dev_get_priv(dev);
+
+	return priv->cru;
+}
drivers/clk/rockchip/clk_rk3036.c +0 -22
index 8899b0c..7e3bf96 100644
@@ -19,11 +19,6 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-struct rk3036_clk_priv {
-	struct rk3036_cru *cru;
-	ulong rate;
-};
-
  enum {
  	VCO_MAX_HZ	= 2400U * 1000000,
  	VCO_MIN_HZ	= 600 * 1000000,
@@ -49,23 +44,6 @@ enum {
  static const struct pll_div apll_init_cfg = PLL_DIVISORS(APLL_HZ, 1, 3, 1);
  static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2, 1);
 
-void *rockchip_get_cru(void)
-{
-	struct udevice *dev;
-	fdt_addr_t addr;
-	int ret;
-
-	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	addr = dev_get_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
-		return ERR_PTR(-EINVAL);
-
-	return (void *)addr;
-}
-
  static int rkclk_set_pll(struct rk3036_cru *cru, enum rk_clk_id clk_id,
  			 const struct pll_div *div)
  {

drivers/clk/rockchip/clk_rk3036.c static const struct udevice_id rk3036_clk_ids[] = { · line 355

Quoted 8 lines
drivers/clk/rockchip/clk_rk3036.c +1 -1
@@ -371,7 +349,7 @@ static const struct udevice_id rk3036_clk_ids[] = {
  	{ }
  };
 
-U_BOOT_DRIVER(clk_rk3036) = {
+U_BOOT_DRIVER(rockchip_rk3036_cru) = {
  	.name		= "clk_rk3036",
  	.id		= UCLASS_CLK,
  	.of_match	= rk3036_clk_ids,

Thanks,
- Kever

#8 lore raw

PATCH v2 1/3 rockchip: rk3036: Move rockchip_get_cru() out of the driver

Quoted 25 lines · Kever Yang

Hi Simon,

Quoted 21 lines · Simon Glass

This function is called from outside the driver. It should be placed into common SoC code. Move it.

Also rename the driver symbol to be more consistent with the other rockchip
clock drivers.

---

Changes in v2: None

  arch/arm/include/asm/arch-rockchip/cru_rk3036.h |  6 +++++
  arch/arm/mach-rockchip/rk3036/Makefile          |  2 ++
  arch/arm/mach-rockchip/rk3036/clk_rk3036.c      | 33
+++++++++++++++++++++++++
  drivers/clk/rockchip/clk_rk3036.c               | 24 +-----------------
  4 files changed, 42 insertions(+), 23 deletions(-)

create mode 100644 arch/arm/mach-rockchip/rk3036/clk_rk3036.c

[..]

Quoted 5 lines

Thanks,
- Kever

Applied to u-boot-rockchip