diff mbox series

[v1,1/2] fu540: prci: add request and free clock handlers

Message ID 1582042404-27356-2-git-send-email-sagar.kadam@sifive.com
State Superseded
Headers show
Series display proper CPU frequency on hifive-unleashed | expand

Commit Message

Sagar Shrikant Kadam Feb. 18, 2020, 4:13 p.m. UTC
Add handlers to check if a valid clock id is used to request clock
by any driver using clk_request/clk_free API calls.

Signed-off-by: Sagar Shrikant Kadam <sagar.kadam at sifive.com>
Tested-by: Vincent Chen <vincent.chen at sifive.com>
---
 drivers/clk/sifive/fu540-prci.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Sean Anderson Feb. 21, 2020, 6:22 a.m. UTC | #1
On 2/18/20 11:13 AM, Sagar Shrikant Kadam wrote:
> +static int sifive_fu540_prci_clk_free(struct clk *clk)
> +{
> +	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
> +	      clk->id);
> +
> +	if (clk->id >= ARRAY_SIZE(__prci_init_clocks))
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +

I don't think this function is necessary, since no struct clk should be
passed to clk_free except one which was previously successfully
requested.

>  static int sifive_fu540_prci_probe(struct udevice *dev)
>  {
>  	int i, err;
> @@ -611,6 +633,8 @@ static int sifive_fu540_prci_probe(struct udevice *dev)
>  static struct clk_ops sifive_fu540_prci_ops = {
>  	.set_rate = sifive_fu540_prci_set_rate,
>  	.get_rate = sifive_fu540_prci_get_rate,
> +	.request  = sifive_fu540_prci_clk_request,
> +	.rfree	  = sifive_fu540_prci_clk_free,
>  };
>  
>  static const struct udevice_id sifive_fu540_prci_ids[] = {
>

--Sean
Sagar Shrikant Kadam Feb. 24, 2020, 11:25 a.m. UTC | #2
Hi Sean,

> -----Original Message-----
> From: Sean Anderson <seanga2 at gmail.com>
> Sent: Friday, February 21, 2020 11:53 AM
> To: Sagar Kadam <sagar.kadam at sifive.com>; u-boot at lists.denx.de
> Cc: lukma at denx.de; bmeng.cn at gmail.com; Anup.Patel at wdc.com; Paul
> Walmsley ( Sifive) <paul.walmsley at sifive.com>; Vincent Chen
> <vincent.chen at sifive.com>
> Subject: Re: [PATCH v1 1/2] fu540: prci: add request and free clock handlers
> 
> On 2/18/20 11:13 AM, Sagar Shrikant Kadam wrote:
> > +static int sifive_fu540_prci_clk_free(struct clk *clk) {
> > +	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
> > +	      clk->id);
> > +
> > +	if (clk->id >= ARRAY_SIZE(__prci_init_clocks))
> > +		return -EINVAL;
> > +
> > +	return 0;
> > +}
> > +
> 
> I don't think this function is necessary, since no struct clk should be passed to
> clk_free except one which was previously successfully requested.
> 
Thanks for suggestion.
I can drop this id check and keep the debug message as done in other similar drivers.

BR,
Sagar Kadam

> >  static int sifive_fu540_prci_probe(struct udevice *dev)  {
> >  	int i, err;
> > @@ -611,6 +633,8 @@ static int sifive_fu540_prci_probe(struct udevice
> > *dev)  static struct clk_ops sifive_fu540_prci_ops = {
> >  	.set_rate = sifive_fu540_prci_set_rate,
> >  	.get_rate = sifive_fu540_prci_get_rate,
> > +	.request  = sifive_fu540_prci_clk_request,
> > +	.rfree	  = sifive_fu540_prci_clk_free,
> >  };
> >
> >  static const struct udevice_id sifive_fu540_prci_ids[] = {
> >
> 
> --Sean
diff mbox series

Patch

diff --git a/drivers/clk/sifive/fu540-prci.c b/drivers/clk/sifive/fu540-prci.c
index 8847178..ecf29a0 100644
--- a/drivers/clk/sifive/fu540-prci.c
+++ b/drivers/clk/sifive/fu540-prci.c
@@ -580,6 +580,28 @@  static ulong sifive_fu540_prci_set_rate(struct clk *clk, ulong rate)
 	return rate;
 }
 
+static int sifive_fu540_prci_clk_request(struct clk *clk)
+{
+	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
+	      clk->id);
+
+	if (clk->id >= ARRAY_SIZE(__prci_init_clocks))
+		return -EINVAL;
+
+	return 0;
+}
+
+static int sifive_fu540_prci_clk_free(struct clk *clk)
+{
+	debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev,
+	      clk->id);
+
+	if (clk->id >= ARRAY_SIZE(__prci_init_clocks))
+		return -EINVAL;
+
+	return 0;
+}
+
 static int sifive_fu540_prci_probe(struct udevice *dev)
 {
 	int i, err;
@@ -611,6 +633,8 @@  static int sifive_fu540_prci_probe(struct udevice *dev)
 static struct clk_ops sifive_fu540_prci_ops = {
 	.set_rate = sifive_fu540_prci_set_rate,
 	.get_rate = sifive_fu540_prci_get_rate,
+	.request  = sifive_fu540_prci_clk_request,
+	.rfree	  = sifive_fu540_prci_clk_free,
 };
 
 static const struct udevice_id sifive_fu540_prci_ids[] = {