From: daniel.lezcano@linaro.org (Daniel Lezcano)
To: linux-snps-arc@lists.infradead.org
Subject: [PATCH v3 03/18] clocksource: Add NPS400 timers driver
Date: Fri, 4 Dec 2015 10:13:11 +0100 [thread overview]
Message-ID: <56615927.30201@linaro.org> (raw)
In-Reply-To: <1448974985-11487-4-git-send-email-noamc@ezchip.com>
On 12/01/2015 02:02 PM, Noam Camus wrote:
> From: Noam Camus <noamc at ezchip.com>
>
> Add internal tick generator which is shared by all cores.
> Each cluster of cores view it through dedicated address.
> This is used for SMP system where all CPUs synced by same
> clock source.
>
> Signed-off-by: Noam Camus <noamc at ezchip.com>
> Cc: Daniel Lezcano <daniel.lezcano at linaro.org>
> Cc: Rob Herring <robh+dt at kernel.org>
> Cc: Thomas Gleixner <tglx at linutronix.de>
> Cc: John Stultz <john.stultz at linaro.org>
> Acked-by: Vineet Gupta <vgupta at synopsys.com>
[ ... ]
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index 56bd16e..20969b0 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -46,6 +46,7 @@ obj-$(CONFIG_CLKSRC_QCOM) += qcom-timer.o
> obj-$(CONFIG_MTK_TIMER) += mtk_timer.o
> obj-$(CONFIG_CLKSRC_PISTACHIO) += time-pistachio.o
> obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
> +obj-$(CONFIG_ARC_PLAT_EZNPS) += timer-nps.o
CONFIG_CLKSRC_NPS
>
> obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
> obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
> diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c
> new file mode 100644
> index 0000000..ef8f287
> --- /dev/null
> +++ b/drivers/clocksource/timer-nps.c
> @@ -0,0 +1,63 @@
> +/*
> + * Copyright(c) 2015 EZchip Technologies.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * The full GNU General Public License is included in this distribution in
> + * the file called "COPYING".
> + */
> +
> +#include <linux/clocksource.h>
> +#include <linux/of.h>
> +#include <linux/of_fdt.h>
> +#include <plat/ctop.h>
Why do you need this header ? nps_host_reg ?
We prevent to include headers from <plat> in the drivers directory. You
should find a way to get rid of it.
> +#define NPS_MSU_TICK_LOW 0xC8
> +#define NPS_CLUSTER_OFFSET 8
> +#define NPS_CLUSTER_NUM 16
> +
> +static void *nps_msu_reg_low_addr[NPS_CLUSTER_NUM] __read_mostly;
Perhaps a small optimization...
static DEFINE_PER_CPU_READ_MOSTLY(void __iomem *, baseaddr);
static cycle_t nps_clksrc_read(struct clocksource *clksrc)
{
void __iomem *base = per_cpu(baseaddr, raw_smp_processor_id());
return (cycle_t)ioread32be(base);
}
and in the init function:
for_each_cpu(cpu) {
per_cpu(baseaddr, cpu) = nps_host_reg(cpu,
NPS_MSU_BLKID,
NPS_MSU_TICK_LOW
}
> +static cycle_t nps_clksrc_read(struct clocksource *clksrc)
> +{
> + int cluster = raw_smp_processor_id() >> NPS_CLUSTER_OFFSET;
> +
> + return (cycle_t)ioread32be(nps_msu_reg_low_addr[cluster]);
AFAICT, there is a memory barrier with ioread32be, are you really sure
we have to use it in this code path ?
> +}
> +
> +static struct clocksource nps_counter = {
> + .name = "EZnps-tick",
> + .rating = 301,
> + .read = nps_clksrc_read,
> + .mask = CLOCKSOURCE_MASK(32),
> + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
> +};
> +
> +static void __init nps_setup_clocksource(struct device_node *node)
> +{
> + struct clocksource *clksrc = &nps_counter;
> + unsigned long rate, dt_root;
> + int ret, cluster;
> +
> + for (cluster = 0; cluster < NPS_CLUSTER_NUM; cluster++)
> + nps_msu_reg_low_addr[cluster] =
> + nps_host_reg((cluster << NPS_CLUSTER_OFFSET),
> + NPS_MSU_BLKID, NPS_MSU_TICK_LOW);
> +
> + dt_root = of_get_flat_dt_root();
> + rate = (u32)of_get_flat_dt_prop(dt_root, "clock-frequency", NULL);
I don't get why this is done this way. The Kconfig option help says the
clocksource rate is 1GHz but in the DT the clock is 88MHz.
It would be cleaner to define a fixed clock and then add a phandle in
the DT.
timer_clk: timer_clk {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <123456789>;
};
timer {
compatible = "ezchip,nps400-timer";
clocks = <&timer_clk>;
}
That will result in the same code than the other drivers.
clk = of_clk_get(np, 0);
if (IS_ERR(clk)) {
pr_err("%s: invalid clock\n", np->full_name);
return;
}
rate = clk_get_rate(clk);
> + ret = clocksource_register_hz(clksrc, rate);
> + if (ret)
> + pr_err("Couldn't register clock source.\n");
> +}
> +
> +CLOCKSOURCE_OF_DECLARE(nps_400, "ezchip,nps400-timer",
> + nps_setup_clocksource);
>
--
<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
WARNING: multiple messages have this Message-ID (diff)
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Noam Camus <noamc@ezchip.com>, linux-snps-arc@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, cmetcalf@ezchip.com,
Rob Herring <robh+dt@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>
Subject: Re: [PATCH v3 03/18] clocksource: Add NPS400 timers driver
Date: Fri, 4 Dec 2015 10:13:11 +0100 [thread overview]
Message-ID: <56615927.30201@linaro.org> (raw)
In-Reply-To: <1448974985-11487-4-git-send-email-noamc@ezchip.com>
On 12/01/2015 02:02 PM, Noam Camus wrote:
> From: Noam Camus <noamc@ezchip.com>
>
> Add internal tick generator which is shared by all cores.
> Each cluster of cores view it through dedicated address.
> This is used for SMP system where all CPUs synced by same
> clock source.
>
> Signed-off-by: Noam Camus <noamc@ezchip.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: John Stultz <john.stultz@linaro.org>
> Acked-by: Vineet Gupta <vgupta@synopsys.com>
[ ... ]
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index 56bd16e..20969b0 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -46,6 +46,7 @@ obj-$(CONFIG_CLKSRC_QCOM) += qcom-timer.o
> obj-$(CONFIG_MTK_TIMER) += mtk_timer.o
> obj-$(CONFIG_CLKSRC_PISTACHIO) += time-pistachio.o
> obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
> +obj-$(CONFIG_ARC_PLAT_EZNPS) += timer-nps.o
CONFIG_CLKSRC_NPS
>
> obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
> obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
> diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c
> new file mode 100644
> index 0000000..ef8f287
> --- /dev/null
> +++ b/drivers/clocksource/timer-nps.c
> @@ -0,0 +1,63 @@
> +/*
> + * Copyright(c) 2015 EZchip Technologies.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * The full GNU General Public License is included in this distribution in
> + * the file called "COPYING".
> + */
> +
> +#include <linux/clocksource.h>
> +#include <linux/of.h>
> +#include <linux/of_fdt.h>
> +#include <plat/ctop.h>
Why do you need this header ? nps_host_reg ?
We prevent to include headers from <plat> in the drivers directory. You
should find a way to get rid of it.
> +#define NPS_MSU_TICK_LOW 0xC8
> +#define NPS_CLUSTER_OFFSET 8
> +#define NPS_CLUSTER_NUM 16
> +
> +static void *nps_msu_reg_low_addr[NPS_CLUSTER_NUM] __read_mostly;
Perhaps a small optimization...
static DEFINE_PER_CPU_READ_MOSTLY(void __iomem *, baseaddr);
static cycle_t nps_clksrc_read(struct clocksource *clksrc)
{
void __iomem *base = per_cpu(baseaddr, raw_smp_processor_id());
return (cycle_t)ioread32be(base);
}
and in the init function:
for_each_cpu(cpu) {
per_cpu(baseaddr, cpu) = nps_host_reg(cpu,
NPS_MSU_BLKID,
NPS_MSU_TICK_LOW
}
> +static cycle_t nps_clksrc_read(struct clocksource *clksrc)
> +{
> + int cluster = raw_smp_processor_id() >> NPS_CLUSTER_OFFSET;
> +
> + return (cycle_t)ioread32be(nps_msu_reg_low_addr[cluster]);
AFAICT, there is a memory barrier with ioread32be, are you really sure
we have to use it in this code path ?
> +}
> +
> +static struct clocksource nps_counter = {
> + .name = "EZnps-tick",
> + .rating = 301,
> + .read = nps_clksrc_read,
> + .mask = CLOCKSOURCE_MASK(32),
> + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
> +};
> +
> +static void __init nps_setup_clocksource(struct device_node *node)
> +{
> + struct clocksource *clksrc = &nps_counter;
> + unsigned long rate, dt_root;
> + int ret, cluster;
> +
> + for (cluster = 0; cluster < NPS_CLUSTER_NUM; cluster++)
> + nps_msu_reg_low_addr[cluster] =
> + nps_host_reg((cluster << NPS_CLUSTER_OFFSET),
> + NPS_MSU_BLKID, NPS_MSU_TICK_LOW);
> +
> + dt_root = of_get_flat_dt_root();
> + rate = (u32)of_get_flat_dt_prop(dt_root, "clock-frequency", NULL);
I don't get why this is done this way. The Kconfig option help says the
clocksource rate is 1GHz but in the DT the clock is 88MHz.
It would be cleaner to define a fixed clock and then add a phandle in
the DT.
timer_clk: timer_clk {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <123456789>;
};
timer {
compatible = "ezchip,nps400-timer";
clocks = <&timer_clk>;
}
That will result in the same code than the other drivers.
clk = of_clk_get(np, 0);
if (IS_ERR(clk)) {
pr_err("%s: invalid clock\n", np->full_name);
return;
}
rate = clk_get_rate(clk);
> + ret = clocksource_register_hz(clksrc, rate);
> + if (ret)
> + pr_err("Couldn't register clock source.\n");
> +}
> +
> +CLOCKSOURCE_OF_DECLARE(nps_400, "ezchip,nps400-timer",
> + nps_setup_clocksource);
>
--
<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
next prev parent reply other threads:[~2015-12-04 9:13 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-01 13:02 [PATCH v3 00/18] *** SUBJECT HERE *** Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 01/18] Documentation: Add EZchip vendor to binding list Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-04 8:07 ` Daniel Lezcano
2015-12-04 8:07 ` Daniel Lezcano
2015-12-04 11:46 ` Noam Camus
2015-12-04 11:46 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 02/18] ARC: [plat-eznps] define IPI_IRQ Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 03/18] clocksource: Add NPS400 timers driver Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-04 9:13 ` Daniel Lezcano [this message]
2015-12-04 9:13 ` Daniel Lezcano
2015-12-04 12:26 ` Noam Camus
2015-12-04 12:26 ` Noam Camus
2015-12-04 12:52 ` Daniel Lezcano
2015-12-04 12:52 ` Daniel Lezcano
2015-12-08 13:00 ` Noam Camus
2015-12-08 13:00 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 04/18] irqchip: add nps Internal and external irqchips Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:29 ` Marc Zyngier
2015-12-01 13:29 ` Marc Zyngier
2015-12-02 15:08 ` Noam Camus
2015-12-02 15:08 ` Noam Camus
2015-12-03 18:33 ` Marc Zyngier
2015-12-03 18:33 ` Marc Zyngier
2015-12-07 11:19 ` Noam Camus
2015-12-07 11:19 ` Noam Camus
2015-12-11 7:58 ` Vineet Gupta
2015-12-11 7:58 ` Vineet Gupta
2015-12-01 13:02 ` [PATCH v3 05/18] ARC: Set vmalloc size from configuration Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 06/18] ARC: rwlock: disable interrupts in !LLSC variant Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 07/18] ARC: rename smp operation init_irq_cpu() to init_per_cpu() Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 08/18] ARC: Mark secondary cpu online only after all HW setup is done Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 09/18] ARC: add CONFIG_CLKSRC_OF support to time_init() Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 10/18] ARC: [plat-eznps] Add eznps board defconfig and dts Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 11/18] ARC: [plat-eznps] Add eznps platform Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 12/18] ARC: [plat-eznps] Use dedicated user stack top Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 13/18] ARC: [plat-eznps] Use dedicated atomic/bitops/cmpxchg Noam Camus
2015-12-01 13:03 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 14/18] ARC: [plat-eznps] Use dedicated SMP barriers Noam Camus
2015-12-01 13:03 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 15/18] ARC: [plat-eznps] Use dedicated identity auxiliary register Noam Camus
2015-12-01 13:03 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 16/18] ARC: [plat-eznps] Use dedicated cpu_relax() Noam Camus
2015-12-01 13:03 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 17/18] ARC: [plat-eznps] Use dedicated COMMAND_LINE_SIZE Noam Camus
2015-12-01 13:03 ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 18/18] ARC: Add eznps platform to Kconfig and Makefile Noam Camus
2015-12-01 13:03 ` Noam Camus
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=56615927.30201@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=linux-snps-arc@lists.infradead.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 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.