All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 03/17] dm: clk: Define clk_get_parent_rate() for clk operations
Date: Thu, 31 Jan 2019 12:14:08 +0100	[thread overview]
Message-ID: <20190131121408.3e347d08@jawa> (raw)
In-Reply-To: <CAPnjgZ1=h13i7R7ktNKLpNXpq8GeXtaM8T4ixdrSJ0aaWU7gTA@mail.gmail.com>

Hi Simon,

> +Stephen
> 
> Hi Lukasz,
> 
> On Thu, 31 Jan 2019 at 02:04, Lukasz Majewski <lukma@denx.de> wrote:
> >
> > This commit adds the clk_get_parent_rate() function, which is
> > responsible for getting the rate of parent clock.
> > Unfortunately, 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 alleviate this problem - the clk_get_parent_rate() function has
> > been introduced to clk-uclass.c.
> >
> > As written in the in-code comment - some clocks do not set clk->id
> > (and require it to be set to 0) and hence the standard
> > ckl_{request|get_rate| free} API is used.
> >
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > ---
> >
> > Changes in v2: None
> >
> >  drivers/clk/clk-uclass.c | 41
> > +++++++++++++++++++++++++++++++++++++++++ include/clk.h
> > |  9 +++++++++ 2 files changed, 50 insertions(+)  
> 
> Can we please call this from test/dm/clk.c?

Ok.

> 
> >
> > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
> > index 6d7a514006..f1640dda67 100644
> > --- a/drivers/clk/clk-uclass.c
> > +++ b/drivers/clk/clk-uclass.c
> > @@ -340,6 +340,47 @@ ulong clk_get_rate(struct clk *clk)
> >         return ops->get_rate(clk);
> >  }
> >
> > +ulong clk_get_parent_rate(struct clk *clk)
> > +{
> > +       const struct clk_ops *ops;
> > +       struct udevice *pdev;
> > +       struct clk pclk;
> > +       ulong rate;
> > +       int ret;
> > +
> > +       debug("%s(clk=%p)\n", __func__, clk);
> > +
> > +       pdev = clk->dev->parent;  
> 
> dev_get_parent(clk->dev)

Yes, correct.

> 
> > +       if (!pdev)
> > +               return -ENODEV;  
> 
> Not needed, all devices have parents except the root, which is not in
> UCLASS_CLK

Ok.

> 
> > +
> > +       ops = clk_dev_ops(pdev);
> > +       if (!ops->get_rate)
> > +               return -ENOSYS;
> > +
> > +       /*
> > +        * We do use memset, clk_{request|get_rate|free}
> > +        * as there are clocks - like the "fixed" ones, which
> > +        * doesn't posses the clk wrapper struct (just added to
> > +        * UCLASS_CLK) and explicitly check if clk->id = 0.
> > +        *
> > +        * In fact the "clock" resources (like ops, description)
> > +        * are accessed via udevice structure (pdev - parent's one)
> > +        */
> > +  
> 
> drop blank line. Also is that comment wrapped to use the full number
> of columns?

I will refactor the comment.

> 
> Also, this seems like a bug that should be fixed?

Yes, this seems strange to me:

The main structure passed in the clock API in U-boot is struct clk *clk
pointer.

However, the fixed clocks (clk_fixed_rate.c) require the clk->id to be
set to 0. This is strange as imposes in practice passing new, memset'ed
to 0 clk structure pointer. Moreover, they doesn't have corresponding
struct clk definition and exists only linked in UCLASS_CLK.

The pattern to get clock rate:

memset(clk, 0, sizeof(clk);
clk_request(pdev, clk)  --> clk->dev = pdev [*]; (this is _the_ defacto
						clock assignment)
clk_get_rate(clk)
clk_free(clk)

is also used in socfpga [1] and 'clk dump' command and IMHO is wrong
(but I cannot understand why it was done in that way - we _shall_ pass
pointer to struct clk, not rely on udevices - like in [*]).

Such approach causes the passed clk pointer to be useless as it is NULL
when we call clk_get_rate() recursively.
And for this reason the struct clk *clk pointer is stored in
driver_data for udevice.


[1] - arch/arm/mach-socfpga/clock_manager_arria10.c

> 
> > +       memset(&pclk, 0, sizeof(pclk));
> > +       ret = clk_request(pdev, &pclk);
> > +       if (ret) {
> > +               printf("%s: pclk: %s request failed!\n", __func__,
> > pdev->name);
> > +               return ret;
> > +       }
> > +
> > +       rate = clk_get_rate(&pclk);
> > +       clk_free(&pclk);
> > +
> > +       return rate;
> > +}
> > +
> >  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 f6fbcc6634..8224295ec3 100644
> > --- a/include/clk.h
> > +++ b/include/clk.h
> > @@ -238,6 +238,15 @@ int clk_free(struct clk *clk);
> >  ulong clk_get_rate(struct clk *clk);
> >
> >  /**
> > + * clk_get_parent_rate() - Get parent of current clock rate.
> > + *
> > + * @clk:       A clock struct that was previously successfully
> > requested by
> > + *             clk_request/get_by_*().
> > + * @return clock rate in Hz, or -ve error code.
> > + */
> > +ulong clk_get_parent_rate(struct clk *clk);
> > +
> > +/**
> >   * clk_set_rate() - Set current clock rate.
> >   *
> >   * @clk:       A clock struct that was previously successfully
> > requested by --
> > 2.11.0
> >  
> 
> 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 at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190131/3ffb682d/attachment.sig>

  reply	other threads:[~2019-01-31 11:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-31  9:03 [U-Boot] [PATCH v2 00/17] imx: dm: Update mccmon6 board to only use DM/DTS in u-boot proper Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 01/17] dm: Fix documentation entry as there is no UCLASS_CLOCK uclass Lukasz Majewski
2019-01-31 10:04   ` Simon Glass
2019-01-31  9:03 ` [U-Boot] [PATCH v2 02/17] cmd: Do not show frequency for clocks which .get_rate() return error Lukasz Majewski
2019-01-31 10:04   ` Simon Glass
2019-01-31  9:03 ` [U-Boot] [PATCH v2 03/17] dm: clk: Define clk_get_parent_rate() for clk operations Lukasz Majewski
2019-01-31 10:05   ` Simon Glass
2019-01-31 11:14     ` Lukasz Majewski [this message]
2019-01-31  9:03 ` [U-Boot] [PATCH v2 04/17] dm: clk: Define clk_get_by_id() " Lukasz Majewski
2019-01-31 10:05   ` Simon Glass
2019-01-31 10:51     ` Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 05/17] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3) Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 06/17] ARM: imx: cosmetic: Remove not needed comment from the mccmon6.h file Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 07/17] ARM: imx: config: Disable support for USB on MCCMON6 Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 08/17] net: imx: Add support for waiting some time after FEC gpio reset Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 09/17] spi: imx: Add support for 'per' clock enabling via driver model Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 10/17] ARM: imx: Covnert mccmon6 to use DM/DTS in the u-boot proper Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 11/17] ARM: imx: Decouple mccmon6's SPL and u-boot proper code Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 12/17] ARM: imx: Disable 1Gbps support on MCCMON6's KSZ9031 PHY Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 13/17] Kconfig: Make CMD_SPL_NAND_OFS only available when proper memory is used Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 14/17] Kconfig: cosmetic: Update description of CMD_SPL_NAND_OFS Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 15/17] Kconfig: Add CMD_SPL_NOR_OFS config for falcon boot argument offset Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 16/17] doc: Update parallel NOR flash related information in README.falcon Lukasz Majewski
2019-01-31  9:03 ` [U-Boot] [PATCH v2 17/17] imx: Convert mccmon6 to use fitImage instead of uImage+DTB Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190131121408.3e347d08@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.