devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: "Li.Xiubo@freescale.com" <Li.Xiubo@freescale.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"shawn.guo@linaro.org" <shawn.guo@linaro.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Jingchang Lu <jingchang.lu@freescale.com>
Subject: Re: [PATCHv3 3/3] clocksource: Add Freescale FlexTimer Module (FTM) timer support
Date: Mon, 19 May 2014 11:08:20 +0200	[thread overview]
Message-ID: <5379CA04.2040801@linaro.org> (raw)
In-Reply-To: <0a6cb1e6380f42279a583ebf7e27dd54@BY2PR03MB505.namprd03.prod.outlook.com>

On 05/19/2014 04:26 AM, Li.Xiubo@freescale.com wrote:
>>> +#define FTM_CNTIN	0x4C
>>> +
>>> +static void __iomem *clksrc_base;
>>> +static void __iomem *clkevt_base;
>>> +static unsigned long peroidic_cyc;
>>> +static unsigned long ps;
>>> +bool big_endian;
>>> +
>>
>> Usually this is encaspulated in a structure.
>>
>> struct ftm_clock_device {
>> 	void __iomem *clksrc_base;
>> 	...
>> };
>>
>>
>>> +static inline u32 ftm_readl(void __iomem *addr)
>>> +{
>>> +	if (big_endian)
>>
>> I am not a big fan of addressing global variables in the functions, so
>> if you can pass the structure pointer around here and the other
>> functions instead that would be nice.
>>
>> Otherwise the patch sounds ok. Thanks for taking care of encapsulating
>> well the functions and commenting the code.
>>
>
> Yes, I did think so.
>
> But some callbacks like :
> + static u64 ftm_read_sched_clock(void)
> + {
> +         return ftm_readl(clksrc_base + FTM_CNT);
> + }
>
> Used by :
> + sched_clock_register(ftm_read_sched_clock,....);
>
> If they are encapsulated in a structure, and should the struct instance
> be one global instance too ? I'm doubting whether will this make sense ?

Actually, I plan in a near future to consolidate the code and factor out 
some parts with a common structure across the different drivers. So even 
if you address the base@ with the global instance but pass around the 
structure as parameter, that will be ok because that will be less 
modifications in the future. It is not a strong requirement, just put in 
place some encapsulation to make the life easier for after.

>>> +static int __init ftm_calc_closest_round_cyc(unsigned long freq)
>>> +{
>>> +	ps = 0;
>>> +
>>> +	do {
>>> +		peroidic_cyc = DIV_ROUND_CLOSEST(freq, HZ * (1 << ps++));
>>> +	} while (peroidic_cyc > 0xFFFF);
>>> +
>>> +	if (ps > 7) {
>>> +		pr_err("ftm: the max prescaler is %lu > 7\n", ps);
>>> +		return -EINVAL;
>>> +	}
>>> +
>>
>> Can you explain how this error can happen ?
>>
>
> Yes, the hardware limitation of the 'ps' is 0~7, and the counter register
> Is only using the lower 16 bits.
> If the 'freq' value is too big here, then the periodic_cyc may exceed 0xFFFF.
>
> Or should I add some comment here ?

Yes, a comment will be welcome.

Thanks
   -- Daniel

-- 
  <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


  reply	other threads:[~2014-05-19  9:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-29  2:18 [PATCHv3 0/3] clocksource: Add Freescale FlexTimer Module (FTM) timer support Xiubo Li
2014-04-29  2:18 ` [PATCHv3 1/3] clocksource: ftm: Add FlexTimer Module (FTM) Timer devicetree Documentation Xiubo Li
2014-04-29  2:18 ` [PATCHv3 2/3] ARM: dts: vf610: Add Freescale FlexTimer Module timer node Xiubo Li
2014-04-29  2:18 ` [PATCHv3 3/3] clocksource: Add Freescale FlexTimer Module (FTM) timer support Xiubo Li
2014-05-16 13:01   ` Daniel Lezcano
2014-05-19  1:55     ` Li.Xiubo
     [not found]   ` <1398737939-5334-4-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-05-16 14:31     ` Stephen Boyd
     [not found]       ` <5376212D.4080701-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-05-19  1:56         ` Li.Xiubo-KZfg59tc24xl57MIdRCFDg
2014-05-16 15:07     ` Daniel Lezcano
2014-05-19  2:26       ` Li.Xiubo
2014-05-19  9:08         ` Daniel Lezcano [this message]
2014-05-19  9:16           ` Li.Xiubo
2014-05-19  9:14 ` [PATCHv3 0/3] " Daniel Lezcano
2014-05-19  9:17   ` Li.Xiubo

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=5379CA04.2040801@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=Li.Xiubo@freescale.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jingchang.lu@freescale.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=tglx@linutronix.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 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).