[PATCH v2 09/12] clk: boston: Allow to get regmap from parent device
Jonas Karlman
jonas at kwiboo.se
Thu May 16 16:00:18 CEST 2024
Hi Jiaxun,
On 2024-05-16 13:40, Jiaxun Yang wrote:
> In upstream devicetree, clk_boston is a child of syscon node
> and there is no "regmap" property for clk_boston node.
>
> Try to check parent device first to look for syscon.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
> ---
> v2: Move syscon_get_regmap to probe
> ---
> drivers/clk/clk_boston.c | 37 +++++++++++++++++++++++++------------
> 1 file changed, 25 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/clk/clk_boston.c b/drivers/clk/clk_boston.c
> index 030ff7cc58ec..1985bb0ec334 100644
> --- a/drivers/clk/clk_boston.c
> +++ b/drivers/clk/clk_boston.c
> @@ -12,6 +12,7 @@
> #include <linux/printk.h>
>
> struct clk_boston {
> + struct udevice *syscon;
> struct regmap *regmap;
> };
>
> @@ -58,23 +59,33 @@ const struct clk_ops clk_boston_ops = {
> .get_rate = clk_boston_get_rate,
> };
>
> -static int clk_boston_of_to_plat(struct udevice *dev)
> +static int clk_boston_probe(struct udevice *dev)
> {
> struct clk_boston *state = dev_get_plat(dev);
> - struct udevice *syscon;
> - int err;
>
> - err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
> - "regmap", &syscon);
> - if (err) {
> - pr_err("unable to find syscon device\n");
> - return err;
> + state->regmap = syscon_get_regmap(state->syscon);
> + if (IS_ERR(state->regmap)) {
> + pr_err("unable to find regmap\n");
> + return PTR_ERR(state->regmap);
> }
>
> - state->regmap = syscon_get_regmap(syscon);
> - if (!state->regmap) {
> - pr_err("unable to find regmap\n");
> - return -ENODEV;
> + return 0;
> +}
> +
> +static int clk_boston_of_to_plat(struct udevice *dev)
> +{
> + struct clk_boston *state = dev_get_plat(dev);
> + int err;
> +
> + if (dev->parent && device_get_uclass_id(dev->parent) == UCLASS_SYSCON) {
> + state->syscon = dev->parent;
> + } else {
> + err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
> + "regmap", &state->syscon);
This will trigger a probe of the referenced regmap phandle. To simplify
and avoid probing devices at of_to_plat() stage, you can probably just
rename of_to_plat() to probe() and skip of_to_plat() stage completely.
Regards,
Jonas
> + if (err) {
> + pr_err("unable to find syscon device\n");
> + return err;
> + }
> }
>
> return 0;
> @@ -92,6 +103,8 @@ U_BOOT_DRIVER(clk_boston) = {
> .id = UCLASS_CLK,
> .of_match = clk_boston_match,
> .of_to_plat = clk_boston_of_to_plat,
> + .probe = clk_boston_probe,
> .plat_auto = sizeof(struct clk_boston),
> .ops = &clk_boston_ops,
> + .flags = DM_FLAG_PRE_RELOC,
> };
>
More information about the U-Boot
mailing list