Message ID | 20190516221042.3583-10-lukma@denx.de |
---|---|
State | Awaiting Upstream |
Delegated to: | Stefano Babic |
Headers | show |
Series | clk: Port Linux common clock framework[CCF] to U-boot (tag: 5.0-rc3) | expand |
> Subject: [PATCH v4 09/13] dm: clk: Define clk_get_by_id() for clk operations > > This commit adds the clk_get_by_id() function, which is responsible for getting > the udevice with matching clk->id. Such approach allows re-usage of inherit > DM list relationship for the same class (UCLASS_CLK). > As a result - we don't need any other external list - it is just enough to look for > UCLASS_CLK related udevices. > > Signed-off-by: Lukasz Majewski <lukma@denx.de> > > --- > > Changes in v4: None > Changes in v3: > - Replace -ENODEV with -ENOENT > - Use **clkp instead of **c > > drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ > include/clk.h | 11 +++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index > ea43871112..6f054396e3 100644 > --- a/drivers/clk/clk-uclass.c > +++ b/drivers/clk/clk-uclass.c > @@ -490,6 +490,28 @@ int clk_disable_bulk(struct clk_bulk *bulk) > return 0; > } > > +int clk_get_by_id(ulong id, struct clk **clkp) { > + struct udevice *dev; > + struct uclass *uc; > + int ret; > + > + ret = uclass_get(UCLASS_CLK, &uc); > + if (ret) > + return ret; > + > + uclass_foreach_dev(dev, uc) { > + struct clk *clk = (struct clk *)dev_get_driver_data(dev); > + > + if (clk && clk->id == id) { > + *clkp = clk; > + return 0; > + } > + } > + > + return -ENOENT; > +} > + > UCLASS_DRIVER(clk) = { > .id = UCLASS_CLK, > .name = "clk", > diff --git a/include/clk.h b/include/clk.h index 955699eb18..32ac2386ed > 100644 > --- a/include/clk.h > +++ b/include/clk.h > @@ -345,4 +345,15 @@ static inline bool clk_valid(struct clk *clk) { > return !!clk->dev; > } > + > +/** > + * clk_get_by_id() - Get the clock by its ID > + * > + * @id: The clock ID to search for > + * > + * @clkp: A pointer to clock struct that has been found among added > clocks > + * to UCLASS_CLK > + * @return zero on success, or -ENOENT on error */ int > +clk_get_by_id(ulong id, struct clk **clkp); Reviewed-by: Peng Fan <peng.fan@nxp.com> > #endif > -- > 2.11.0
Hi Lukasz, On Thu, 16 May 2019 at 16:11, Lukasz Majewski <lukma@denx.de> wrote: > > This commit adds the clk_get_by_id() function, which is responsible > for getting the udevice with matching clk->id. Such approach allows > re-usage of inherit DM list relationship for the same class (UCLASS_CLK). > As a result - we don't need any other external list - it is just enough > to look for UCLASS_CLK related udevices. > > Signed-off-by: Lukasz Majewski <lukma@denx.de> > > --- > > Changes in v4: None > Changes in v3: > - Replace -ENODEV with -ENOENT > - Use **clkp instead of **c > > drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ > include/clk.h | 11 +++++++++++ > 2 files changed, 33 insertions(+) Again this new function needs a test. I'll stop commenting now :-) Regards, Simon
Hi Simon, > Hi Lukasz, > > On Thu, 16 May 2019 at 16:11, Lukasz Majewski <lukma@denx.de> wrote: > > > > This commit adds the clk_get_by_id() function, which is responsible > > for getting the udevice with matching clk->id. Such approach allows > > re-usage of inherit DM list relationship for the same class > > (UCLASS_CLK). As a result - we don't need any other external list - > > it is just enough to look for UCLASS_CLK related udevices. > > > > Signed-off-by: Lukasz Majewski <lukma@denx.de> > > > > --- > > > > Changes in v4: None > > Changes in v3: > > - Replace -ENODEV with -ENOENT > > - Use **clkp instead of **c > > > > drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ > > include/clk.h | 11 +++++++++++ > > 2 files changed, 33 insertions(+) > > Again this new function needs a test. I'll stop commenting now :-) > Please find corresponding test: http://patchwork.ozlabs.org/patch/1100769/ > Regards, > Simon Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
On 17/05/19 00:10, Lukasz Majewski wrote: > This commit adds the clk_get_by_id() function, which is responsible > for getting the udevice with matching clk->id. Such approach allows > re-usage of inherit DM list relationship for the same class (UCLASS_CLK). > As a result - we don't need any other external list - it is just enough > to look for UCLASS_CLK related udevices. > > Signed-off-by: Lukasz Majewski <lukma@denx.de> > > --- > > Changes in v4: None > Changes in v3: > - Replace -ENODEV with -ENOENT > - Use **clkp instead of **c > > drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ > include/clk.h | 11 +++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c > index ea43871112..6f054396e3 100644 > --- a/drivers/clk/clk-uclass.c > +++ b/drivers/clk/clk-uclass.c > @@ -490,6 +490,28 @@ int clk_disable_bulk(struct clk_bulk *bulk) > return 0; > } > > +int clk_get_by_id(ulong id, struct clk **clkp) > +{ > + struct udevice *dev; > + struct uclass *uc; > + int ret; > + > + ret = uclass_get(UCLASS_CLK, &uc); > + if (ret) > + return ret; > + > + uclass_foreach_dev(dev, uc) { > + struct clk *clk = (struct clk *)dev_get_driver_data(dev); > + > + if (clk && clk->id == id) { > + *clkp = clk; > + return 0; > + } > + } > + > + return -ENOENT; > +} > + > UCLASS_DRIVER(clk) = { > .id = UCLASS_CLK, > .name = "clk", > diff --git a/include/clk.h b/include/clk.h > index 955699eb18..32ac2386ed 100644 > --- a/include/clk.h > +++ b/include/clk.h > @@ -345,4 +345,15 @@ static inline bool clk_valid(struct clk *clk) > { > return !!clk->dev; > } > + > +/** > + * clk_get_by_id() - Get the clock by its ID > + * > + * @id: The clock ID to search for > + * > + * @clkp: A pointer to clock struct that has been found among added clocks > + * to UCLASS_CLK > + * @return zero on success, or -ENOENT on error > + */ > +int clk_get_by_id(ulong id, struct clk **clkp); > #endif > Reviewed-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
> This commit adds the clk_get_by_id() function, which is responsible > for getting the udevice with matching clk->id. Such approach allows > re-usage of inherit DM list relationship for the same class (UCLASS_CLK). > As a result - we don't need any other external list - it is just enough > to look for UCLASS_CLK related udevices. > Signed-off-by: Lukasz Majewski <lukma@denx.de> > Reviewed-by: Peng Fan <peng.fan@nxp.com> > Reviewed-by: Stefano Babic <sbabic@denx.de> Applied to u-boot-imx, master, thanks ! Best regards, Stefano Babic
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ea43871112..6f054396e3 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -490,6 +490,28 @@ int clk_disable_bulk(struct clk_bulk *bulk) return 0; } +int clk_get_by_id(ulong id, struct clk **clkp) +{ + struct udevice *dev; + struct uclass *uc; + int ret; + + ret = uclass_get(UCLASS_CLK, &uc); + if (ret) + return ret; + + uclass_foreach_dev(dev, uc) { + struct clk *clk = (struct clk *)dev_get_driver_data(dev); + + if (clk && clk->id == id) { + *clkp = clk; + return 0; + } + } + + return -ENOENT; +} + UCLASS_DRIVER(clk) = { .id = UCLASS_CLK, .name = "clk", diff --git a/include/clk.h b/include/clk.h index 955699eb18..32ac2386ed 100644 --- a/include/clk.h +++ b/include/clk.h @@ -345,4 +345,15 @@ static inline bool clk_valid(struct clk *clk) { return !!clk->dev; } + +/** + * clk_get_by_id() - Get the clock by its ID + * + * @id: The clock ID to search for + * + * @clkp: A pointer to clock struct that has been found among added clocks + * to UCLASS_CLK + * @return zero on success, or -ENOENT on error + */ +int clk_get_by_id(ulong id, struct clk **clkp); #endif
This commit adds the clk_get_by_id() function, which is responsible for getting the udevice with matching clk->id. Such approach allows re-usage of inherit DM list relationship for the same class (UCLASS_CLK). As a result - we don't need any other external list - it is just enough to look for UCLASS_CLK related udevices. Signed-off-by: Lukasz Majewski <lukma@denx.de> --- Changes in v4: None Changes in v3: - Replace -ENODEV with -ENOENT - Use **clkp instead of **c drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++ include/clk.h | 11 +++++++++++ 2 files changed, 33 insertions(+)