dm: clk: Add a way to find a clock by its driver
Subsystems (5)
PATCH 1/4 dm: clk: Add a way to find a clock by its driver
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison.
---
drivers/core/uclass.c | 20 ++++++++++++++++++++ include/dm/device.h | 4 ++++ include/dm/uclass.h | 17 +++++++++++++++++ 3 files changed, 41 insertions(+)
drivers/core/uclass.c +20 -0
@@ -311,6 +311,26 @@ static int uclass_find_device_by_phandle(enum uclass_id id, }#endif +int uclass_get_device_by_driver (enum uclass_id id, +const struct driver *find_drv, +struct udevice **devp) +{ +struct udevice *dev; +struct uclass *uc; +int ret; + + ret =uclass_get (id, &uc); +if (ret) +return ret; + +list_for_each_entry (dev, &uc->dev_head, uclass_node) { +if (dev->driver == find_drv) +return uclass_get_device_tail (dev,0 , devp); + } + +return -ENODEV ; +} +int uclass_get_device_tail (struct udevice *dev,int ret,struct udevice **devp) {
include/dm/device.h +4 -0
@@ -207,6 +207,10 @@ struct driver {#define U_BOOT_DRIVER (__name) \ ll_entry_declare(struct driver, __name, driver) +/* Get a pointer to a given driver */ +#define DM_GET_DRIVER (__name) \ + ll_entry_get(struct driver, __name, driver) +/** * dev_get_platdata() - Get the platform data for a device *
include/dm/uclass.h +17 -0
@@ -194,6 +194,23 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, const char *name, struct udevice **devp);/** +* uclass_get_device_by_driver() - Get a uclass device for a driver +* +* This searches the devices in the uclass for one that uses the given +* driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is +* the driver name - as used in U_BOOT_DRIVER(name). +* +* The device is probed to activate it ready for use. +* +* @id: ID to look up +* @drv: Driver to look for +* @devp: Returns pointer to the first device with that driver +* @return 0 if OK, -ve on error +*/ +int uclass_get_device_by_driver (enum uclass_id id,const struct driver *drv, +struct udevice **devp); + +/** * uclass_first_device() - Get the first device in a uclass * * The device returned is probed if necessary, and ready for use
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 1/4 dm: clk: Add a way to find a clock by its driver
Quoted 5 lines · Simon Glass
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
drivers/core/uclass.c | 20 ++++++++++++++++++++ include/dm/device.h | 4 ++++ include/dm/uclass.h | 17 +++++++++++++++++ 3 files changed, 41 insertions(+)
Applied to u-boot-rockchip.
PATCH 2/4 rockchip: Add a way to obtain the main clock device
In reply to Simon GlassOn Rockchip SoCs we typically have a main clock device that uses the Soc clock driver. There is also a fixed clock for the oscillator. Add a function to obtain the core clock.
---
arch/arm/include/asm/arch-rockchip/clock.h | 2 ++ arch/arm/mach-rockchip/rk3288/Makefile | 1 + arch/arm/mach-rockchip/rk3288/clk_rk3288.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 arch/arm/mach-rockchip/rk3288/clk_rk3288.c
arch/arm/include/asm/arch-rockchip/clock.h +2 -0
@@ -67,4 +67,6 @@ struct rk3288_grf;void rkclk_configure_cpu (struct rk3288_cru *cru,struct rk3288_grf *grf); +int rockchip_get_clk (struct udevice **devp); +#endif
arch/arm/mach-rockchip/rk3288/Makefile +1 -0
@@ -4,6 +4,7 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-y += clk_rk3288.o obj-y += reset_rk3288.o obj-y += sdram_rk3288.o obj-y += syscon_rk3288.o
arch/arm/mach-rockchip/rk3288/clk_rk3288.c new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Copyright (C) 2015 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> + +int rockchip_get_clk (struct udevice **devp) +{ +return uclass_get_device_by_driver (UCLASS_CLK , +DM_GET_DRIVER (rockchip_rk3288_cru), devp); +}
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 2/4 rockchip: Add a way to obtain the main clock device
Quoted 4 lines · Simon Glass
On Rockchip SoCs we typically have a main clock device that uses the Soc clock driver. There is also a fixed clock for the oscillator. Add a function to obtain the core clock.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
arch/arm/include/asm/arch-rockchip/clock.h | 2 ++ arch/arm/mach-rockchip/rk3288/Makefile | 1 + arch/arm/mach-rockchip/rk3288/clk_rk3288.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 arch/arm/mach-rockchip/rk3288/clk_rk3288.c
I'm bringing this in now as it fixes a clock bug and I am out most of this week. But if there are comments I can address them later.
Applied to u-boot-rockchip
PATCH 3/4 rockchip: Use rockchip_get_clk() to obtain the SoC clock
In reply to Simon GlassThe current code picks the first available clock. In U-Boot proper this is the oscillator device, not the SoC clock device. As a result the HDMI display does not work.
Fix this by calling rockchip_get_clk() instead.
---
arch/arm/mach-rockchip/board.c | 2 +- arch/arm/mach-rockchip/rk3288-board-spl.c | 2 +- arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 2 +- drivers/clk/clk_rk3288.c | 2 +- drivers/video/rockchip/rk_vop.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/board.c +1 -1
@@ -178,7 +178,7 @@ static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc,int ret, i;struct udevice *dev; - ret =uclass_get_device (UCLASS_CLK ,0 , &dev); + ret =rockchip_get_clk (&dev);if (ret) {printf ("clk-uclass not found\n" );return 0 ;
arch/arm/mach-rockchip/rk3288-board-spl.c +1 -1
@@ -187,7 +187,7 @@ void board_init_f(ulong dummy)rockchip_timer_init ();configure_l2ctlr (); - ret =uclass_get_device (UCLASS_CLK ,0 , &dev); + ret =rockchip_get_clk (&dev);if (ret) {debug ("CLK init failed: %d\n" , ret);return ;
arch/arm/mach-rockchip/rk3288/sdram_rk3288.c +1 -1
@@ -923,7 +923,7 @@ static int rk3288_dmc_probe(struct udevice *dev) priv->chan[1 ].pctl =regmap_get_range (plat->map,2 ); priv->chan[1 ].publ =regmap_get_range (plat->map,3 );#endif - ret =uclass_get_device (UCLASS_CLK ,0 , &dev_clk); + ret =rockchip_get_clk (&dev_clk);if (ret)return ret; priv->ddr_clk.id =CLK_DDR ;
drivers/clk/clk_rk3288.c +1 -1
@@ -145,7 +145,7 @@ void *rockchip_get_cru(void)struct udevice *dev;int ret; - ret =uclass_get_device (UCLASS_CLK ,0 , &dev); + ret =rockchip_get_clk (&dev);if (ret)return ERR_PTR (ret);
drivers/video/rockchip/rk_vop.c +1 -1
@@ -238,7 +238,7 @@ int rk_display_init(struct udevice *dev, ulong fbbase,return ret; } - ret =uclass_get_device (UCLASS_CLK ,0 , &dev_clk); + ret =rockchip_get_clk (&dev_clk);if (!ret) { clk.id =DCLK_VOP0 + remote_vop_id; ret =clk_request (dev_clk, &clk);
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 3/4 rockchip: Use rockchip_get_clk() to obtain the SoC clock
Quoted 8 lines · On Sun, 17 Jul 2016 15:23:17 -0600 Simon Glass sjg at chromium.org wrote:
The current code picks the first available clock. In U-Boot proper this is the oscillator device, not the SoC clock device. As a result the HDMI display does not work.
Fix this by calling
rockchip_get_clk()instead.Fixes 135aa950 (clk: convert API to match reset/mailbox style)Signed-off-by Simon Glass <[email protected]>
PATCH 3/4 rockchip: Use rockchip_get_clk() to obtain the SoC clock
Quoted 7 lines · Anatolij Gustschin
Quoted 4 lines · On Sun, 17 Jul 2016 15:23:17 -0600 Simon Glass sjg at chromium.org wrote:
The current code picks the first available clock. In U-Boot proper this is the oscillator device, not the SoC clock device. As a result the HDMI display does not work.
Quoted 6 lines
Quoted 4 lines
Fix this by calling
rockchip_get_clk()instead.Fixes 135aa950 (clk: convert API to match reset/mailbox style)Signed-off-by Simon Glass <[email protected]>
Applied to u-boot-rockchip
PATCH 4/4 rockchip: rk3288: Move rockchip_get_cru() out of the driver
In reply to Simon GlassThis function is called from outside the driver. It should be placed into common SoC code. Move it.
The same could be done for rk3036 but is not attempted here.
---
arch/arm/mach-rockchip/rk3288/clk_rk3288.c | 15 +++++++++++++++ drivers/clk/clk_rk3288.c | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)
arch/arm/mach-rockchip/rk3288/clk_rk3288.c +15 -0
@@ -15,3 +15,18 @@ 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/clk_rk3288.c +0 -15
@@ -139,21 +139,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
PATCH 1/4 dm: clk: Add a way to find a clock by its driver
In reply to Simon GlassQuoted 4 lines · Simon Glass
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison.
The code looks plausible, but the commit subject and description imply this has something to do with clocks, whereas it doesn't; it seems to be a generic/core DM function.
PATCH 1/4 dm: clk: Add a way to find a clock by its driver
Hi Stephen,
Quoted 11 lines · Stephen Warren
Quoted 5 lines · Simon Glass
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison.
The code looks plausible, but the commit subject and description imply this has something to do with clocks, whereas it doesn't; it seems to be a generic/core DM function.
Yes you are correct. I updated the commit subject when I applied it:
c57f806 dm: core: Add a way to find a device by its driver
Regards,
Simon