diff mbox series

[U-Boot,v3,06/11] dm: clk: Define clk_get_parent() for clk operations

Message ID 20190425102953.5348-7-lukma@denx.de
State Changes Requested
Delegated to: Tom Rini
Headers show
Series clk: Port Linux common clock framework [CCF] to U-boot (tag: 5.0-rc3) | expand

Commit Message

Lukasz Majewski April 25, 2019, 10:29 a.m. UTC
This commit adds the clk_get_parent() function, which is responsible
for getting the parent's struct clock pointer.

U-boot's DM support for getting parent is different (the parent
relationship is in udevice) than the one in common clock framework (CCF)
in Linux. To obtain the pointer to struct clk of parent the
pdev->driver_data field is read.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---

Changes in v3:
- New patch

 drivers/clk/clk-uclass.c | 15 +++++++++++++++
 include/clk.h            |  9 +++++++++
 2 files changed, 24 insertions(+)

Comments

Peng Fan April 26, 2019, 2:31 a.m. UTC | #1
> Subject: [PATCH v3 06/11] dm: clk: Define clk_get_parent() for clk operations
> 
> This commit adds the clk_get_parent() function, which is responsible for
> getting the parent's struct clock pointer.
> 
> U-boot's DM support for getting parent is different (the parent relationship is
> in udevice) than the one in common clock framework (CCF) in Linux. To obtain
> the pointer to struct clk of parent the
> pdev->driver_data field is read.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> 
> ---
> 
> Changes in v3:
> - New patch
> 
>  drivers/clk/clk-uclass.c | 15 +++++++++++++++
>  include/clk.h            |  9 +++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index
> 844b87cc33..7ebe4e79fe 100644
> --- a/drivers/clk/clk-uclass.c
> +++ b/drivers/clk/clk-uclass.c
> @@ -340,6 +340,21 @@ ulong clk_get_rate(struct clk *clk)
>  	return ops->get_rate(clk);
>  }
> 
> +struct clk *clk_get_parent(struct clk *clk) {
> +	struct udevice *pdev;
> +	struct clk *pclk;
> +
> +	debug("%s(clk=%p)\n", __func__, clk);
> +
> +	pdev = dev_get_parent(clk->dev);
> +	pclk = (struct clk *)dev_get_driver_data(pdev);
> +	if (!pclk)
> +		return ERR_PTR(-ENODEV);
> +
> +	return pclk;
> +}
> +
>  ulong clk_set_rate(struct clk *clk, ulong rate)  {
>  	const struct clk_ops *ops = clk_dev_ops(clk->dev); diff --git
> a/include/clk.h b/include/clk.h index f29ba02da1..b44ee3b158 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -240,6 +240,15 @@ int clk_free(struct clk *clk);  ulong
> clk_get_rate(struct clk *clk);
> 
>  /**
> + * clk_get_parent() - Get current clock's parent.
> + *
> + * @clk:	A clock struct that was previously successfully requested by
> + *		clk_request/get_by_*().
> + * @return pointer to parent's struct clk, or error code passed as
> +pointer  */ struct clk *clk_get_parent(struct clk *clk);
> +
> +/**
>   * clk_set_rate() - Set current clock rate.
>   *
>   * @clk:	A clock struct that was previously successfully requested by
> --

Reviewed-by: Peng Fan <peng.fan@nxp.com>

> 2.11.0
diff mbox series

Patch

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 844b87cc33..7ebe4e79fe 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -340,6 +340,21 @@  ulong clk_get_rate(struct clk *clk)
 	return ops->get_rate(clk);
 }
 
+struct clk *clk_get_parent(struct clk *clk)
+{
+	struct udevice *pdev;
+	struct clk *pclk;
+
+	debug("%s(clk=%p)\n", __func__, clk);
+
+	pdev = dev_get_parent(clk->dev);
+	pclk = (struct clk *)dev_get_driver_data(pdev);
+	if (!pclk)
+		return ERR_PTR(-ENODEV);
+
+	return pclk;
+}
+
 ulong clk_set_rate(struct clk *clk, ulong rate)
 {
 	const struct clk_ops *ops = clk_dev_ops(clk->dev);
diff --git a/include/clk.h b/include/clk.h
index f29ba02da1..b44ee3b158 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -240,6 +240,15 @@  int clk_free(struct clk *clk);
 ulong clk_get_rate(struct clk *clk);
 
 /**
+ * clk_get_parent() - Get current clock's parent.
+ *
+ * @clk:	A clock struct that was previously successfully requested by
+ *		clk_request/get_by_*().
+ * @return pointer to parent's struct clk, or error code passed as pointer
+ */
+struct clk *clk_get_parent(struct clk *clk);
+
+/**
  * clk_set_rate() - Set current clock rate.
  *
  * @clk:	A clock struct that was previously successfully requested by