[U-Boot] [PATCH v2 46/55] rockchip: clk: Move all DT decoding to ofdata_to_platdata()

Simon Glass sjg at chromium.org
Mon Jun 13 07:33:27 CEST 2016


It is more correct to avoid touching the device tree in the probe() method.
Update the driver to work this way. Also add an error check on grf since if
that fails then we should not use it.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 drivers/clk/clk_rk3288.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk_rk3288.c b/drivers/clk/clk_rk3288.c
index d88893c..8a62b3d 100644
--- a/drivers/clk/clk_rk3288.c
+++ b/drivers/clk/clk_rk3288.c
@@ -835,6 +835,17 @@ static struct clk_ops rk3288_clk_ops = {
 	.get_periph_rate = rk3288_get_periph_rate,
 };
 
+static int rk3288_clk_ofdata_to_platdata(struct udevice *dev)
+{
+	struct rk3288_clk_plat *plat = dev_get_platdata(dev);
+	struct rk3288_clk_priv *priv = dev_get_priv(dev);
+
+	if (plat->clk_id == CLK_OSC)
+		priv->cru = (struct rk3288_cru *)dev_get_addr(dev);
+
+	return 0;
+}
+
 static int rk3288_clk_probe(struct udevice *dev)
 {
 	struct rk3288_clk_plat *plat = dev_get_platdata(dev);
@@ -847,8 +858,9 @@ static int rk3288_clk_probe(struct udevice *dev)
 		priv->grf = parent_priv->grf;
 		return 0;
 	}
-	priv->cru = (struct rk3288_cru *)dev_get_addr(dev);
 	priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
+	if (IS_ERR(priv->grf))
+		return PTR_ERR(priv->grf);
 #ifdef CONFIG_SPL_BUILD
 	rkclk_init(priv->cru, priv->grf);
 #endif
@@ -867,14 +879,11 @@ static const char *const clk_name[CLK_COUNT] = {
 
 static int rk3288_clk_bind(struct udevice *dev)
 {
-	struct rk3288_clk_plat *plat = dev_get_platdata(dev);
 	int pll, ret;
 
 	/* We only need to set up the root clock */
-	if (dev->of_offset == -1) {
-		plat->clk_id = CLK_OSC;
+	if (device_get_uclass_id(dev_get_parent(dev)) == UCLASS_CLK)
 		return 0;
-	}
 
 	/* Create devices for P main clocks */
 	for (pll = 1; pll < CLK_COUNT; pll++) {
@@ -911,5 +920,6 @@ U_BOOT_DRIVER(clk_rk3288) = {
 	.platdata_auto_alloc_size = sizeof(struct rk3288_clk_plat),
 	.ops		= &rk3288_clk_ops,
 	.bind		= rk3288_clk_bind,
+	.ofdata_to_platdata	= rk3288_clk_ofdata_to_platdata,
 	.probe		= rk3288_clk_probe,
 };
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list