diff mbox

[U-Boot,3/3] net: ravb: Add clock handling support

Message ID 20170721212035.25910-3-marek.vasut+renesas@gmail.com
State Accepted
Commit 1fea9e25faca9d72a52b7da1587b90153fde6239
Delegated to: Nobuhiro Iwamatsu
Headers show

Commit Message

Marek Vasut July 21, 2017, 9:20 p.m. UTC
Add support for enabling and disabling the clock using the clock
framework based on the content of OF instead of doing it manually
in the board file.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
---
 drivers/net/ravb.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Joe Hershberger July 27, 2017, 9:28 p.m. UTC | #1
On Fri, Jul 21, 2017 at 4:20 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
> Add support for enabling and disabling the clock using the clock
> framework based on the content of OF instead of doing it manually
> in the board file.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Nobuhiro Iwamatsu Aug. 2, 2017, 11:16 p.m. UTC | #2
Applied to rmobile branch, thanks!

2017-07-22 6:20 GMT+09:00 Marek Vasut <marek.vasut@gmail.com>:
> Add support for enabling and disabling the clock using the clock
> framework based on the content of OF instead of doing it manually
> in the board file.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
> ---
>  drivers/net/ravb.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
> index ce0eacceb6..8db127ba06 100644
> --- a/drivers/net/ravb.c
> +++ b/drivers/net/ravb.c
> @@ -10,6 +10,7 @@
>   */
>
>  #include <common.h>
> +#include <clk.h>
>  #include <dm.h>
>  #include <errno.h>
>  #include <miiphy.h>
> @@ -120,6 +121,7 @@ struct ravb_priv {
>         struct phy_device       *phydev;
>         struct mii_dev          *bus;
>         void __iomem            *iobase;
> +       struct clk              clk;
>  };
>
>  static inline void ravb_flush_dcache(u32 addr, u32 len)
> @@ -432,27 +434,38 @@ int ravb_start(struct udevice *dev)
>         struct ravb_priv *eth = dev_get_priv(dev);
>         int ret;
>
> -       ret = ravb_reset(dev);
> +       ret = clk_enable(&eth->clk);
>         if (ret)
>                 return ret;
>
> +       ret = ravb_reset(dev);
> +       if (ret)
> +               goto err;
> +
>         ravb_base_desc_init(eth);
>         ravb_tx_desc_init(eth);
>         ravb_rx_desc_init(eth);
>
>         ret = ravb_config(dev);
>         if (ret)
> -               return ret;
> +               goto err;
>
>         /* Setting the control will start the AVB-DMAC process. */
>         writel(CCC_OPC_OPERATION, eth->iobase + RAVB_REG_CCC);
>
>         return 0;
> +
> +err:
> +       clk_disable(&eth->clk);
> +       return ret;
>  }
>
>  static void ravb_stop(struct udevice *dev)
>  {
> +       struct ravb_priv *eth = dev_get_priv(dev);
> +
>         ravb_reset(dev);
> +       clk_disable(&eth->clk);
>  }
>
>  static int ravb_probe(struct udevice *dev)
> @@ -466,6 +479,10 @@ static int ravb_probe(struct udevice *dev)
>         iobase = map_physmem(pdata->iobase, 0x1000, MAP_NOCACHE);
>         eth->iobase = iobase;
>
> +       ret = clk_get_by_index(dev, 0, &eth->clk);
> +       if (ret < 0)
> +               goto err_mdio_alloc;
> +
>         mdiodev = mdio_alloc();
>         if (!mdiodev) {
>                 ret = -ENOMEM;
> --
> 2.11.0
>
diff mbox

Patch

diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index ce0eacceb6..8db127ba06 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -10,6 +10,7 @@ 
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <errno.h>
 #include <miiphy.h>
@@ -120,6 +121,7 @@  struct ravb_priv {
 	struct phy_device	*phydev;
 	struct mii_dev		*bus;
 	void __iomem		*iobase;
+	struct clk		clk;
 };
 
 static inline void ravb_flush_dcache(u32 addr, u32 len)
@@ -432,27 +434,38 @@  int ravb_start(struct udevice *dev)
 	struct ravb_priv *eth = dev_get_priv(dev);
 	int ret;
 
-	ret = ravb_reset(dev);
+	ret = clk_enable(&eth->clk);
 	if (ret)
 		return ret;
 
+	ret = ravb_reset(dev);
+	if (ret)
+		goto err;
+
 	ravb_base_desc_init(eth);
 	ravb_tx_desc_init(eth);
 	ravb_rx_desc_init(eth);
 
 	ret = ravb_config(dev);
 	if (ret)
-		return ret;
+		goto err;
 
 	/* Setting the control will start the AVB-DMAC process. */
 	writel(CCC_OPC_OPERATION, eth->iobase + RAVB_REG_CCC);
 
 	return 0;
+
+err:
+	clk_disable(&eth->clk);
+	return ret;
 }
 
 static void ravb_stop(struct udevice *dev)
 {
+	struct ravb_priv *eth = dev_get_priv(dev);
+
 	ravb_reset(dev);
+	clk_disable(&eth->clk);
 }
 
 static int ravb_probe(struct udevice *dev)
@@ -466,6 +479,10 @@  static int ravb_probe(struct udevice *dev)
 	iobase = map_physmem(pdata->iobase, 0x1000, MAP_NOCACHE);
 	eth->iobase = iobase;
 
+	ret = clk_get_by_index(dev, 0, &eth->clk);
+	if (ret < 0)
+		goto err_mdio_alloc;
+
 	mdiodev = mdio_alloc();
 	if (!mdiodev) {
 		ret = -ENOMEM;