devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
To: Andrew Bresticker <abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Linux-MIPS <linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>,
	Daniel Lezcano
	<daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	James Hartley
	<james.hartley-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>,
	James Hogan <james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Damien Horsley
	<Damien.Horsley-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>,
	Govindraj Raja
	<Govindraj.Raja-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 6/7] clocksource: Add Pistachio clocksource-only driver
Date: Tue, 26 May 2015 11:16:22 -0300	[thread overview]
Message-ID: <55648036.70106@imgtec.com> (raw)
In-Reply-To: <CAL1qeaEL7D6=WpyigbHWv8DEhp0XhC4acCYRkQ6Fm0Wr4HW11A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>



On 05/22/2015 01:48 PM, Andrew Bresticker wrote:
> On Thu, May 21, 2015 at 2:41 PM, Ezequiel Garcia
> <ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org> wrote:
>> The Pistachio SoC provides four general purpose timers, and allow
>> to implement a clocksource driver.
>>
>> This driver can be used as a replacement for the MIPS GIC and MIPS R4K
>> clocksources and sched clocks, which are clocked from the CPU clock.
>>
>> Given the general purpose timers are clocked from an independent clock,
>> this new clocksource driver will be useful to introduce CPUFreq support
>> for Pistachio machines.
>>
>> Signed-off-by: Govindraj Raja <Govindraj.Raja-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
>> Signed-off-by: Ezequiel Garcia <ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
> 
>> --- /dev/null
>> +++ b/drivers/clocksource/time-pistachio.c
> 
>> @@ -0,0 +1,202 @@
>> +/*
>> + * Pistachio clocksource based on general-purpose timers
>> + *
>> + * Copyright (C) 2015 Imagination Technologies
>> + *
>> + * This file is subject to the terms and conditions of the GNU General Public
>> + * License. See the file "COPYING" in the main directory of this archive
>> + * for more details.
>> + */
>> +
>> +#define pr_fmt(fmt) "%s: " fmt, __func__
>> +
>> +#include <linux/clk.h>
>> +#include <linux/clocksource.h>
>> +#include <linux/clockchips.h>
>> +#include <linux/delay.h>
>> +#include <linux/err.h>
>> +#include <linux/init.h>
>> +#include <linux/spinlock.h>
>> +#include <linux/mfd/syscon.h>
>> +#include <linux/of.h>
>> +#include <linux/of_address.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/regmap.h>
>> +#include <linux/sched_clock.h>
>> +#include <linux/time.h>
>> +
>> +/* Top level reg */
>> +#define        CR_TIMER_CTRL_CFG               0x00
>> +  #define TIMER_ME_GLOBAL              BIT(0)
>> +#define        CR_TIMER_REV                    0x10
>> +
>> +/* Timer specific registers */
>> +#define TIMER_CFG                      0x20
>> +  #define TIMER_ME_LOCAL               BIT(0)
>> +#define TIMER_RELOAD_VALUE             0x24
>> +#define TIMER_CURRENT_VALUE            0x28
>> +#define TIMER_CURRENT_OVERFLOW_VALUE   0x2C
>> +#define TIMER_IRQ_STATUS               0x30
>> +#define TIMER_IRQ_CLEAR                        0x34
>> +#define TIMER_IRQ_MASK                 0x38
> 
> nit: the spacing in these two sets of #defines is inconsistent and the
> space at the beginning of the line looks a little weird to me, maybe
> just do something like this:
> 
> #define REGISTER ...
> #define  REGISTER_FIELD ...
> 

Done.

>> +
>> +#define PERIP_TIMER_CONTROL            0x90
>> +
>> +/* Timer specific configuration Values */
>> +#define RELOAD_VALUE   0xffffffff
>> +
>> +static void __iomem *timer_base;
>> +static DEFINE_RAW_SPINLOCK(lock);
>> +
>> +static inline u32 gpt_readl(u32 offset, u32 gpt_id)
>> +{
>> +       return __raw_readl(timer_base + 0x20 * gpt_id + offset);
>> +}
>> +
>> +static inline void gpt_writel(u32 value, u32 offset, u32 gpt_id)
>> +{
>> +       __raw_writel(value, timer_base + 0x20 * gpt_id + offset);
>> +}
> 
> Why raw iomem accessors?
> 

For no good reason, it was a blind copy-paste. I'll change that to
standard accessors.

>> +static cycle_t clocksource_read_cycles(struct clocksource *cs)
>> +{
>> +       u32 counter, overflw;
>> +       unsigned long flags;
>> +
>> +       raw_spin_lock_irqsave(&lock, flags);
>> +       overflw = gpt_readl(TIMER_CURRENT_OVERFLOW_VALUE, 0);
>> +       counter = gpt_readl(TIMER_CURRENT_VALUE, 0);
>> +       raw_spin_unlock_irqrestore(&lock, flags);
>> +
>> +       return ~(cycle_t)counter;
>> +}
>> +
>> +static u64 notrace pistachio_read_sched_clock(void)
>> +{
>> +       return clocksource_read_cycles(NULL);
>> +}
>> +
>> +static void pistachio_clksrc_enable(int timeridx)
>> +{
>> +       u32 val;
>> +
>> +       /* Disable GPT local before loading reload value */
>> +       val = gpt_readl(TIMER_CFG, timeridx);
>> +       val &= ~TIMER_ME_LOCAL;
>> +       gpt_writel(val, TIMER_CFG, timeridx);
>> +
>> +       gpt_writel(RELOAD_VALUE, TIMER_RELOAD_VALUE, timeridx);
>> +
>> +       val = gpt_readl(TIMER_CFG, timeridx);
>> +       val |= TIMER_ME_LOCAL;
>> +       gpt_writel(val, TIMER_CFG, timeridx);
>> +}
>> +
>> +static void pistachio_clksrc_disable(int timeridx)
>> +{
>> +       u32 val;
>> +
>> +       /* Disable GPT local */
>> +       val = gpt_readl(TIMER_CFG, timeridx);
>> +       val &= ~TIMER_ME_LOCAL;
>> +       gpt_writel(val, TIMER_CFG, timeridx);
>> +}
>> +
>> +static int clocksource_enable(struct clocksource *cs)
>> +{
>> +       pistachio_clksrc_enable(0);
>> +       return 0;
>> +}
>> +
>> +static void clocksource_disable(struct clocksource *cs)
>> +{
>> +       pistachio_clksrc_disable(0);
>> +}
>> +
>> +/* Desirable clock source for pistachio platform */
>> +static struct clocksource clocksource_gpt = {
>> +       .name           = "gptimer",
>> +       .rating         = 300,
>> +       .enable         = clocksource_enable,
>> +       .disable        = clocksource_disable,
>> +       .read           = clocksource_read_cycles,
> 
> nit: these names are rather generic sounding, maybe add a "pistachio" prefix?
> 

Sure.

>> +       .mask           = CLOCKSOURCE_MASK(32),
>> +       .flags          = CLOCK_SOURCE_IS_CONTINUOUS |
>> +                         CLOCK_SOURCE_SUSPEND_NONSTOP,
>> +};
>> +
>> +static void __init pistachio_clksrc_of_init(struct device_node *node)
>> +{
>> +       struct clk *sys_clk, *fast_clk;
>> +       struct regmap *periph_regs;
>> +       unsigned long rate;
>> +       int ret;
>> +
>> +       timer_base = of_iomap(node, 0);
>> +       if (!timer_base) {
>> +               pr_err("cannot iomap\n");
>> +               return;
>> +       }
>> +
>> +       /*
>> +        * We need early syscon or late clocksource probe for this to work.
>> +        */
> 
> I don't think this is true... if the syscon hasn't probed yet, then
> syscon_regmap_lookup_by_phandle will probe it for us.
> 

Ah, that comment is a left over from early experiments.

>> +       periph_regs = syscon_regmap_lookup_by_phandle(node, "img,cr-periph");
>> +       if (IS_ERR(periph_regs)) {
>> +               pr_err("cannot get peripheral regmap (%lu)\n",
>> +                      PTR_ERR(periph_regs));
>> +               return;
>> +       }
>> +
>> +       /* Switch to using the fast counter clock */
>> +       ret = regmap_update_bits(periph_regs, PERIP_TIMER_CONTROL,
>> +                                0xf, 0x0);
>> +       if (ret)
>> +               return;
>> +
>> +       sys_clk = of_clk_get_by_name(node, "sys");
>> +       if (IS_ERR(sys_clk)) {
>> +               pr_err("clock get failed (%lu)\n", PTR_ERR(sys_clk));
>> +               return;
>> +       }
>> +
>> +       fast_clk = of_clk_get_by_name(node, "fast");
>> +       if (IS_ERR(fast_clk)) {
>> +               pr_err("clock get failed (%lu)\n", PTR_ERR(fast_clk));
>> +               return;
>> +       }
>> +
>> +       ret = clk_prepare_enable(sys_clk);
>> +       if (ret < 0) {
>> +               pr_err("failed to enable clock (%d)\n", ret);
>> +               return;
>> +       }
>> +
>> +       ret = clk_prepare_enable(fast_clk);
>> +       if (ret < 0) {
>> +               pr_err("failed to enable clock (%d)\n", ret);
>> +               clk_disable_unprepare(sys_clk);
>> +               return;
>> +       }
>> +
>> +       rate = clk_get_rate(fast_clk);
>> +
>> +       /* Disable irq's for clocksource usage */
>> +       gpt_writel(0, TIMER_IRQ_MASK, 0);
>> +       gpt_writel(0, TIMER_IRQ_MASK, 1);
>> +       gpt_writel(0, TIMER_IRQ_MASK, 2);
>> +       gpt_writel(0, TIMER_IRQ_MASK, 3);
>> +
>> +       /* Enable timer block */
>> +       __raw_writel(TIMER_ME_GLOBAL, timer_base);
>> +
>> +       sched_clock_register(pistachio_read_sched_clock, 32, rate);
>> +       clocksource_register_hz(&clocksource_gpt, rate);
>> +}
>> +
>> +static const struct of_device_id pistachio_clksrc_of_match[] __initconst = {
>> +       { .compatible = "img,pistachio-gptimer" },
>> +       { },
>> +};
> 
> This table doesn't appear to be used anywhere.
> 

Left over from same experiments.

>> +CLOCKSOURCE_OF_DECLARE(pistachio_gptimer, "img,pistachio-gptimer",
>> +                      pistachio_clksrc_of_init);
>> --
>> 2.3.3
>>

Thanks for the review!
-- 
Ezequiel
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-05-26 14:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21 21:37 [PATCH 0/7] Clocksource changes for Pistachio CPUFreq Ezequiel Garcia
2015-05-21 21:37 ` [PATCH 2/7] clocksource: mips-gic: Add missing error returns checks Ezequiel Garcia
     [not found]   ` <1432244260-14908-3-git-send-email-ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-21 22:18     ` Andrew Bresticker
     [not found] ` <1432244260-14908-1-git-send-email-ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-21 21:37   ` [PATCH 1/7] clocksource: mips-gic: Enable the clock before using it Ezequiel Garcia
     [not found]     ` <1432244260-14908-2-git-send-email-ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-21 22:17       ` Andrew Bresticker
2015-05-21 21:37   ` [PATCH 3/7] clocksource: mips-gic: Split clocksource and clockevent initialization Ezequiel Garcia
2015-05-21 22:24     ` Andrew Bresticker
     [not found]       ` <CAL1qeaFkzpH+nGqRPOuY-L62jP8NgZWP0WxKTYKXZDpe1sSojg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-21 22:25         ` Ezequiel Garcia
     [not found]           ` <555E5B5C.9050807-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-22 16:53             ` Andrew Bresticker
2015-05-21 21:37   ` [PATCH 4/7] clocksource: mips-gic: Update clockevent frequency on clock rate changes Ezequiel Garcia
     [not found]     ` <1432244260-14908-5-git-send-email-ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-21 22:32       ` Andrew Bresticker
     [not found]         ` <CAL1qeaEzKh6H8HBCULJWM4yMnSQGexWmV0rrnYMViMpuzKWyLg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-21 22:30           ` Ezequiel Garcia
2015-05-21 21:41   ` [PATCH 6/7] clocksource: Add Pistachio clocksource-only driver Ezequiel Garcia
2015-05-21 22:00     ` Thomas Gleixner
2015-05-21 22:02       ` Ezequiel Garcia
     [not found]         ` <555E55F4.2060500-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-21 22:09           ` Thomas Gleixner
2015-05-22 16:48     ` Andrew Bresticker
     [not found]       ` <CAL1qeaEL7D6=WpyigbHWv8DEhp0XhC4acCYRkQ6Fm0Wr4HW11A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-26 14:16         ` Ezequiel Garcia [this message]
2015-05-21 21:41 ` [PATCH 5/7] clocksource: Add Pistachio SoC general purpose timer binding document Ezequiel Garcia
2015-05-21 23:41   ` Andrew Bresticker
2015-05-21 21:43 ` [PATCH 7/7] mips: pistachio: Allow to enable the external timer based clocksource Ezequiel Garcia
     [not found]   ` <1432244618-15548-1-git-send-email-ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2015-05-22 16:50     ` Andrew Bresticker
2015-05-22 16:58       ` James Hartley
2015-05-22 18:08         ` Ezequiel Garcia

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=55648036.70106@imgtec.com \
    --to=ezequiel.garcia-1axoqhu6uovqt0dzr+alfa@public.gmane.org \
    --cc=Damien.Horsley-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=Govindraj.Raja-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=james.hartley-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.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).