[U-Boot] [PATCH v4 07/13] dm: clk: Define clk_get_parent() for clk operations

Peng Fan peng.fan at nxp.com
Fri May 17 05:46:57 UTC 2019



> -----Original Message-----
> From: Lukasz Majewski [mailto:lukma at denx.de]
> Sent: 2019年5月17日 6:11
> To: Stefano Babic <sbabic at denx.de>; Fabio Estevam <festevam at gmail.com>;
> Marek Vasut <marex at denx.de>; Simon Glass <sjg at chromium.org>; Tom Rini
> <trini at konsulko.com>; u-boot at lists.denx.de; Jagan Teki
> <jagan at amarulasolutions.com>; Peng Fan <peng.fan at nxp.com>; Marcel
> Ziswiler <marcel.ziswiler at toradex.com>; Adam Ford <aford173 at gmail.com>
> Cc: Lukasz Majewski <lukma at denx.de>; Neil Armstrong
> <narmstrong at baylibre.com>; Philipp Tomsich
> <philipp.tomsich at theobroma-systems.com>; Andreas Dannenberg
> <dannenberg at ti.com>; Fabrice Gasnier <fabrice.gasnier at st.com>; Liviu
> Dudau <Liviu.Dudau at foss.arm.com>
> Subject: [PATCH v4 07/13] 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 at denx.de>
> 
> ---
> 
> Changes in v4: None
> 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
> 79b3b0494c..1a726dafaa 100644
> --- a/drivers/clk/clk-uclass.c
> +++ b/drivers/clk/clk-uclass.c
> @@ -379,6 +379,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);

This has a trick is that force driver_data to struct clk *,
and this requires all clk wrappers needs take clk
as the first element in the wrapper structure.
So better add a comment here. Then it is fine to me, and

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

> +	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 89dc64bfaf..0873b1e507 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -259,6 +259,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
> --
> 2.11.0



More information about the U-Boot mailing list