devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Anson.Huang@nxp.com, tglx@linutronix.de, robh+dt@kernel.org,
	mark.rutland@arm.com, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, leonard.crestez@nxp.com,
	viresh.kumar@linaro.org, daniel.baluta@nxp.com, ping.bai@nxp.com,
	l.stach@pengutronix.de, abel.vesa@nxp.com,
	andrew.smirnov@gmail.com, ccaione@baylibre.com, angus@akkea.ca,
	agx@sigxcpu.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: Linux-imx@nxp.com
Subject: Re: [PATCH V3 1/5] clocksource: timer-of: Support getting clock frequency from DT
Date: Mon, 1 Jul 2019 10:58:21 +0200	[thread overview]
Message-ID: <17a7bde4-e5e0-a746-52a5-1075ce263152@linaro.org> (raw)
In-Reply-To: <20190628033041.8513-1-Anson.Huang@nxp.com>


Hi Anson,

thanks for taking care of adding the clock-frequency handling in the
timer-of.

On 28/06/2019 05:30, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> More and more platforms use platform driver model for clock driver,
> so the clock driver is NOT ready during timer initialization phase,
> it will cause timer initialization failed.
> 
> To support those platforms with upper scenario, introducing a new
> flag TIMER_OF_CLOCK_FREQUENCY which is mutually exclusive with
> TIMER_OF_CLOCK flag to support getting timer clock frequency from
> DT, then of_clk operations can be skipped.
> 
> User needs to select either TIMER_OF_CLOCK_FREQUENCY or TIMER_OF_CLOCK
> flag if want to use timer-of driver to initialize the clock rate,
> and the corresponding clock name or property name needs to be specified.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
> New patch:
> 	- Add new flag of TIMER_OF_CLOCK_FREQUENCY, mutually exclusive with TIMER_OF_CLOCK, to support
> 	  getting clock frequency from DT directly;
> 	- Add prop_name to of_timer_clk structure, if using TIMER_OF_CLOCK_FREQUENCY flag, user needs
> 	  to pass the property name for timer-of driver to get clock frequency from DT, this is to avoid
> 	  the couple of timer-of driver and DT, so timer-of driver does NOT use a fixed property name.
> ---
>  drivers/clocksource/timer-of.c | 23 +++++++++++++++++++++++
>  drivers/clocksource/timer-of.h |  8 +++++---
>  2 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c
> index 8054228..c91a8b6 100644
> --- a/drivers/clocksource/timer-of.c
> +++ b/drivers/clocksource/timer-of.c
> @@ -161,6 +161,21 @@ static __init int timer_of_base_init(struct device_node *np,
>  	return 0;
>  }
>  
> +static __init int timer_of_clk_frequency_init(struct device_node *np,
> +					      struct of_timer_clk *of_clk)
> +{
> +	int ret;
> +	u32 rate;
> +
> +	ret = of_property_read_u32(np, of_clk->prop_name, &rate);
> +	if (!ret) {
> +		of_clk->rate = rate;
> +		of_clk->period = DIV_ROUND_UP(rate, HZ);
> +	}
> +
> +	return ret;
> +}
> +
>  int __init timer_of_init(struct device_node *np, struct timer_of *to)
>  {
>  	int ret = -EINVAL;
> @@ -178,6 +193,11 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to)
>  		if (ret)
>  			goto out_fail;
>  		flags |= TIMER_OF_CLOCK;
> +	} else if (to->flags & TIMER_OF_CLOCK_FREQUENCY) {
> +		ret = timer_of_clk_frequency_init(np, &to->of_clk);
> +		if (ret)
> +			goto out_fail;
> +		flags |= TIMER_OF_CLOCK_FREQUENCY;
>  	}

/* Pre-condition */

if (to->flags & (TIMER_OF_CLOCK | TIMER_OF_CLOCK_FREQUENCY))
	return -EINVAL;

[ ... ]

if (to->flags & TIMER_OF_CLOCK) {
}

if (to->flags & TIMER_OF_CLOCK_FREQUENCY) {
}

>  	if (to->flags & TIMER_OF_IRQ) {
> @@ -201,6 +221,9 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to)
>  	if (flags & TIMER_OF_CLOCK)
>  		timer_of_clk_exit(&to->of_clk);
>  
> +	if (flags & TIMER_OF_CLOCK_FREQUENCY)
> +		to->of_clk.rate = 0;
> +
>  	if (flags & TIMER_OF_BASE)
>  		timer_of_base_exit(&to->of_base);
>  	return ret;
> diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h
> index a5478f3..f1a083e 100644
> --- a/drivers/clocksource/timer-of.h
> +++ b/drivers/clocksource/timer-of.h
> @@ -4,9 +4,10 @@
>  
>  #include <linux/clockchips.h>
>  
> -#define TIMER_OF_BASE	0x1
> -#define TIMER_OF_CLOCK	0x2
> -#define TIMER_OF_IRQ	0x4
> +#define TIMER_OF_BASE			0x1
> +#define TIMER_OF_CLOCK			0x2
> +#define TIMER_OF_IRQ			0x4
> +#define TIMER_OF_CLOCK_FREQUENCY	0x8
>  
>  struct of_timer_irq {
>  	int irq;
> @@ -26,6 +27,7 @@ struct of_timer_base {
>  struct of_timer_clk {
>  	struct clk *clk;
>  	const char *name;
> +	const char *prop_name;

For the moment, keep it hardcoded with "clock-frequency" directly in the
function.

>  	int index;
>  	unsigned long rate;
>  	unsigned long period;
> 


-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

  parent reply	other threads:[~2019-07-01  8:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28  3:30 [PATCH V3 1/5] clocksource: timer-of: Support getting clock frequency from DT Anson.Huang
2019-06-28  3:30 ` [PATCH V3 2/5] clocksource/drivers/sysctr: Add clock-frequency property Anson.Huang
2019-06-28  3:30 ` [PATCH V3 3/5] clocksource: imx-sysctr: Make timer work with clock driver using platform driver model Anson.Huang
2019-06-28  3:30 ` [PATCH V3 4/5] arm64: dts: imx8mq: Add system counter node Anson.Huang
2019-06-28  3:30 ` [PATCH V3 5/5] arm64: dts: imx8mm: " Anson.Huang
2019-07-01  8:58 ` Daniel Lezcano [this message]
2019-07-01  9:04   ` [PATCH V3 1/5] clocksource: timer-of: Support getting clock frequency from DT Anson Huang
2019-07-01  9:04   ` Anson Huang

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=17a7bde4-e5e0-a746-52a5-1075ce263152@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=Anson.Huang@nxp.com \
    --cc=Linux-imx@nxp.com \
    --cc=abel.vesa@nxp.com \
    --cc=agx@sigxcpu.org \
    --cc=andrew.smirnov@gmail.com \
    --cc=angus@akkea.ca \
    --cc=ccaione@baylibre.com \
    --cc=daniel.baluta@nxp.com \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=l.stach@pengutronix.de \
    --cc=leonard.crestez@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ping.bai@nxp.com \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).