All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Jonas Jensen <jonas.jensen@gmail.com>
Cc: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"arm@kernel.org" <arm@kernel.org>,
	"John Stultz" <john.stultz@linaro.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Tomasz Figa" <tomasz.figa@gmail.com>,
	"Thomas Petazzoni" <thomas.petazzoni@free-electrons.com>,
	"Arnd Bergmann" <arnd@arndb.de>
Subject: Re: [PATCH v2] ARM: clocksource: add support for MOXA ART SoCs
Date: Wed, 26 Jun 2013 21:15:54 +0200	[thread overview]
Message-ID: <CACRpkdZdmC=ur0FFxoDXAMzieutp2w4HXBDbgbeoSeVXeCgp9w@mail.gmail.com> (raw)
In-Reply-To: <1372258383-24524-1-git-send-email-jonas.jensen@gmail.com>

On Wed, Jun 26, 2013 at 4:53 PM, Jonas Jensen <jonas.jensen@gmail.com> wrote:

> This patch adds an clocksource driver for the main timer(s)
> found on MOXA ART SoCs.
>
> Changes since v2:
>
> 1. use clocksource/clockevents infrastructures
> 2. clock frequency read from system clock
>
> Applies to next-20130619
>
> Signed-off-by: Jonas Jensen <jonas.jensen@gmail.com>

This is starting to look good :-)

> +/* TIMER_CR flags:
> +   TIMEREG_CR_1_CLOCK  0: PCLK, 1: EXT1CLK
> +   TIMEREG_CR_1_INT    over flow interrupt enable bit */

/*
 * Usually we use this comment style, one star at the beginning
 * of every comment line and a closing star-slash sitting lonley
 * on a single line to close it.
 */

> +       case CLOCK_EVT_MODE_RESUME:
> +       case CLOCK_EVT_MODE_ONESHOT:
> +               u |= TIMEREG_CR_1_ENABLE;
> +               writel(u, timer_base + TIMER_CR);
> +               writel(~0, timer_base + TIMER1_LOAD);

Should you not write the load value *before* enabling the timer?

> +               pr_debug("%s: CLOCK_EVT_MODE_ONESHOT\n", __func__);
> +               break;

This looks like you're enabling a tick far ahead in the future.
For oneshot you should just trigger new events in .next_event(),
I would just disable the timer for oneshot and enable it
for each new event in .next_event() instead.

> +       case CLOCK_EVT_MODE_PERIODIC:
> +               u |= TIMEREG_CR_1_ENABLE;
> +               writel(u, timer_base + TIMER_CR);
> +               writel(clock_frequency / HZ, timer_base + TIMER1_LOAD);

Use DIV_ROUND_CLOSEST(clock_frequency, HZ)

> +               pr_debug("%s: CLOCK_EVT_MODE_PERIODIC\n", __func__);
> +               break;
> +       case CLOCK_EVT_MODE_UNUSED:
> +       case CLOCK_EVT_MODE_SHUTDOWN:
> +       default:
> +               u &= ~TIMEREG_CR_1_ENABLE;

I would do this also for Oneshot. Then enable it in
.next_event().

> +               writel(u, timer_base + TIMER_CR);
> +               break;


> +static int moxart_clkevt_next_event(unsigned long cycles,
> +       struct clock_event_device *unused)
> +{
> +       u32 alarm = readl(timer_base + TIMER1_COUNT) - cycles;
> +       writel(alarm, timer_base + TIMER1_MATCH1);

I would write TIMEREG_CR_1_ENABLE *here*. This way the
timer is only strictly triggered when an event is queued.

> +static struct irqaction moxart_timer_irq = {
> +       .name = "moxart-timer",
> +       .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,

IRQF_DISABLED is pointless, remove it. Nowadays all IRQ handlers
are called with interrupts disabled.

Why do you need IRQF_IRQPOLL? That seems like more
copy/paste luggade.

> +       clock_frequency = APB_CLK;
> +       /* it might be a good idea to have a default other than 0 for
> +          clock_frequency, should any attempt at getting a valid
> +          frequency fail, not that i see how it could, it probably could..
> +          having it APB_CLK can certainly be wrong on some hardware,
> +          why it is set again with the DT specific property: */

Seems overkill.

> +       ret = of_property_read_u32(node, "clock-frequency", &clock_frequency);
> +       if (ret)
> +               pr_err("%s: can't read clock-frequency DT property\n",
> +                       node->full_name);

I don't think it's apropriate to put clock frequencies into the device
tree node as u32:s. Please use the clock framework exclusively.
Now it's like three ways to get this frequency... what if all three
are different :-P

> +       clk = of_clk_get(node, 0);
> +       if (IS_ERR(clk))
> +               pr_err("%s: of_clk_get failed\n", __func__);

bail out here?

> +       else {
> +               clock_frequency = clk_get_rate(clk);
> +               pr_debug("%s: clk_get_rate=%u success\n", __func__,
> +                       clock_frequency);
> +       }

Then you can  remove the else clause and de-indent this.

The rest looks OK...

Yours,
Linus Walleij

WARNING: multiple messages have this Message-ID (diff)
From: linus.walleij@linaro.org (Linus Walleij)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] ARM: clocksource: add support for MOXA ART SoCs
Date: Wed, 26 Jun 2013 21:15:54 +0200	[thread overview]
Message-ID: <CACRpkdZdmC=ur0FFxoDXAMzieutp2w4HXBDbgbeoSeVXeCgp9w@mail.gmail.com> (raw)
In-Reply-To: <1372258383-24524-1-git-send-email-jonas.jensen@gmail.com>

On Wed, Jun 26, 2013 at 4:53 PM, Jonas Jensen <jonas.jensen@gmail.com> wrote:

> This patch adds an clocksource driver for the main timer(s)
> found on MOXA ART SoCs.
>
> Changes since v2:
>
> 1. use clocksource/clockevents infrastructures
> 2. clock frequency read from system clock
>
> Applies to next-20130619
>
> Signed-off-by: Jonas Jensen <jonas.jensen@gmail.com>

This is starting to look good :-)

> +/* TIMER_CR flags:
> +   TIMEREG_CR_1_CLOCK  0: PCLK, 1: EXT1CLK
> +   TIMEREG_CR_1_INT    over flow interrupt enable bit */

/*
 * Usually we use this comment style, one star at the beginning
 * of every comment line and a closing star-slash sitting lonley
 * on a single line to close it.
 */

> +       case CLOCK_EVT_MODE_RESUME:
> +       case CLOCK_EVT_MODE_ONESHOT:
> +               u |= TIMEREG_CR_1_ENABLE;
> +               writel(u, timer_base + TIMER_CR);
> +               writel(~0, timer_base + TIMER1_LOAD);

Should you not write the load value *before* enabling the timer?

> +               pr_debug("%s: CLOCK_EVT_MODE_ONESHOT\n", __func__);
> +               break;

This looks like you're enabling a tick far ahead in the future.
For oneshot you should just trigger new events in .next_event(),
I would just disable the timer for oneshot and enable it
for each new event in .next_event() instead.

> +       case CLOCK_EVT_MODE_PERIODIC:
> +               u |= TIMEREG_CR_1_ENABLE;
> +               writel(u, timer_base + TIMER_CR);
> +               writel(clock_frequency / HZ, timer_base + TIMER1_LOAD);

Use DIV_ROUND_CLOSEST(clock_frequency, HZ)

> +               pr_debug("%s: CLOCK_EVT_MODE_PERIODIC\n", __func__);
> +               break;
> +       case CLOCK_EVT_MODE_UNUSED:
> +       case CLOCK_EVT_MODE_SHUTDOWN:
> +       default:
> +               u &= ~TIMEREG_CR_1_ENABLE;

I would do this also for Oneshot. Then enable it in
.next_event().

> +               writel(u, timer_base + TIMER_CR);
> +               break;


> +static int moxart_clkevt_next_event(unsigned long cycles,
> +       struct clock_event_device *unused)
> +{
> +       u32 alarm = readl(timer_base + TIMER1_COUNT) - cycles;
> +       writel(alarm, timer_base + TIMER1_MATCH1);

I would write TIMEREG_CR_1_ENABLE *here*. This way the
timer is only strictly triggered when an event is queued.

> +static struct irqaction moxart_timer_irq = {
> +       .name = "moxart-timer",
> +       .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,

IRQF_DISABLED is pointless, remove it. Nowadays all IRQ handlers
are called with interrupts disabled.

Why do you need IRQF_IRQPOLL? That seems like more
copy/paste luggade.

> +       clock_frequency = APB_CLK;
> +       /* it might be a good idea to have a default other than 0 for
> +          clock_frequency, should any attempt at getting a valid
> +          frequency fail, not that i see how it could, it probably could..
> +          having it APB_CLK can certainly be wrong on some hardware,
> +          why it is set again with the DT specific property: */

Seems overkill.

> +       ret = of_property_read_u32(node, "clock-frequency", &clock_frequency);
> +       if (ret)
> +               pr_err("%s: can't read clock-frequency DT property\n",
> +                       node->full_name);

I don't think it's apropriate to put clock frequencies into the device
tree node as u32:s. Please use the clock framework exclusively.
Now it's like three ways to get this frequency... what if all three
are different :-P

> +       clk = of_clk_get(node, 0);
> +       if (IS_ERR(clk))
> +               pr_err("%s: of_clk_get failed\n", __func__);

bail out here?

> +       else {
> +               clock_frequency = clk_get_rate(clk);
> +               pr_debug("%s: clk_get_rate=%u success\n", __func__,
> +                       clock_frequency);
> +       }

Then you can  remove the else clause and de-indent this.

The rest looks OK...

Yours,
Linus Walleij

  parent reply	other threads:[~2013-06-26 19:15 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 10:00 [PATCH] ARM: clocksource: add support for MOXA ART SoCs Jonas Jensen
2013-06-18 10:00 ` Jonas Jensen
2013-06-18 15:14 ` Thomas Petazzoni
2013-06-18 15:14   ` Thomas Petazzoni
2013-06-18 15:28 ` Arnd Bergmann
2013-06-18 15:28   ` Arnd Bergmann
2013-06-26 14:53 ` [PATCH v2] " Jonas Jensen
2013-06-26 14:53   ` Jonas Jensen
2013-06-26 14:59   ` Jonas Jensen
2013-06-26 14:59     ` Jonas Jensen
2013-06-26 16:10   ` Uwe Kleine-König
2013-06-26 16:10     ` Uwe Kleine-König
2013-06-26 19:15   ` Linus Walleij [this message]
2013-06-26 19:15     ` Linus Walleij
2013-06-27 11:23   ` [PATCH v3] " Jonas Jensen
2013-06-27 11:23     ` Jonas Jensen
2013-06-28 13:34     ` Thomas Gleixner
2013-06-28 13:34       ` Thomas Gleixner
2013-07-01 14:02     ` [PATCH v4] " Jonas Jensen
2013-07-01 14:02       ` Jonas Jensen
2013-07-01 17:55       ` Thomas Gleixner
2013-07-01 17:55         ` Thomas Gleixner
2013-07-02 20:19       ` Linus Walleij
2013-07-02 20:19         ` Linus Walleij
2013-07-04 12:19       ` [PATCH v5] " Jonas Jensen
2013-07-04 12:19         ` Jonas Jensen
2013-07-04 21:42         ` Thomas Gleixner
2013-07-04 21:42           ` Thomas Gleixner
2013-07-05 10:05           ` Jonas Jensen
2013-07-05 10:05             ` Jonas Jensen
2013-07-05 10:21             ` Thomas Gleixner
2013-07-05 10:21               ` Thomas Gleixner
2013-07-05 11:48               ` Jonas Jensen
2013-07-05 11:48                 ` Jonas Jensen
2013-07-05 10:04         ` [PATCH v6] " Jonas Jensen
2013-07-05 10:04           ` Jonas Jensen
2013-07-05 11:46           ` [PATCH v7] " Jonas Jensen
2013-07-05 11:46             ` Jonas Jensen
2013-07-16 13:52             ` Daniel Lezcano
2013-07-16 13:52               ` Daniel Lezcano
2013-07-16 14:44             ` [PATCH v8] " Jonas Jensen
2013-07-16 14:44               ` Jonas Jensen
2013-07-16 15:01               ` Daniel Lezcano
2013-07-16 15:01                 ` Daniel Lezcano
2013-07-17  8:14                 ` Jonas Jensen
2013-07-17  8:14                   ` Jonas Jensen
2013-07-17 12:13                   ` Daniel Lezcano
2013-07-17 12:13                     ` Daniel Lezcano
2013-07-17  8:04               ` [PATCH v9] " Jonas Jensen
2013-07-17  8:04                 ` Jonas Jensen
2013-07-19 11:12                 ` [PATCH] ARM: clocksource: moxart: documentation: update device tree bindings document Jonas Jensen
2013-07-19 11:12                   ` Jonas Jensen
2013-07-19 12:16                   ` Daniel Lezcano
2013-07-19 12:16                     ` Daniel Lezcano
2013-07-19 12:50                     ` Jonas Jensen
2013-07-19 12:50                       ` Jonas Jensen
2013-07-20 20:45                 ` [PATCH v9] ARM: clocksource: add support for MOXA ART SoCs Linus Walleij
2013-07-20 20:45                   ` Linus Walleij
2013-07-20 21:34                   ` Daniel Lezcano
2013-07-20 21:34                     ` Daniel Lezcano
2013-07-26 14:03                     ` [PATCH] ARM: clocksource: moxart: add bitops.h include Jonas Jensen
2013-07-26 14:03                       ` Jonas Jensen

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='CACRpkdZdmC=ur0FFxoDXAMzieutp2w4HXBDbgbeoSeVXeCgp9w@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=arm@kernel.org \
    --cc=arnd@arndb.de \
    --cc=john.stultz@linaro.org \
    --cc=jonas.jensen@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=tomasz.figa@gmail.com \
    --cc=u.kleine-koenig@pengutronix.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.