clocksource: Conexant CX92755 timers support
Subsystems (3)
Baruch Siach
maintainerv3 cover clocksource: Conexant CX92755 timers support
This short series adds support for the Conexant CX92755 SoC timers. This SoC is part of the Conexant Digicolor series of SoCs.
v3:
* Split into a separate clocksource series
v2:
http://article.gmane.org/gmane.linux.kernel/1861850
http://article.gmane.org/gmane.linux.kernel/1861853
* Change the timer dt binding, so that the 'reg' property points to the first "Agent Communication" register. This should improve the chance of reusing this binding for other SoCs in this series.
* Add the CONTROL() and COUNT() macros to the timer driver to make the code clearer.
* Move arch/arm Kconfig changes from the clocksource driver patch to the base arch support patch to reduce dependency between them
v1:
http://article.gmane.org/gmane.linux.kernel/1855028
http://article.gmane.org/gmane.linux.kernel/1855025
Baruch Siach (2):
clocksource: devicetree: document Conexant Digicolor timer binding
clocksource: driver for Conexant Digicolor SoC timer
.../devicetree/bindings/timer/digicolor-timer.txt | 18 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-digicolor.c | 164 +++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/digicolor-timer.txt create mode 100644 drivers/clocksource/timer-digicolor.c
Signature · 1 line
2.1.4
Baruch Siach
maintainerPATCH v3 1/2 clocksource: devicetree: document Conexant Digicolor timer binding
--- .../devicetree/bindings/timer/digicolor-timer.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/timer/digicolor-timer.txt
Documentation/devicetree/bindings/timer/digicolor-timer.txt new file +18 -0
@@ -0,0 +1,18 @@ +Conexant Digicolor SoCs Timer Controller + +Required properties: + +- compatible : should be "cnxt,cx92755-timer" +- reg : Specifies base physical address and size of the "Agent Communication" + timer registers +- interrupts : Contains 8 interrupts, one for each timer +- clocks: phandle to the main clock + +Example: + + timer at f0000fc0 { + compatible = "cnxt,cx92755-timer"; + reg = <0xf0000fc0 0x40>; + interrupts = <19>, <31>, <34>, <35>, <52>, <53>, <54>, <55>; + clocks = <&main_clk>; + };
Signature · 1 line
2.1.4
Baruch Siach
maintainerPATCH v3 2/2 clocksource: driver for Conexant Digicolor SoC timer
In reply to Baruch SiachAdd clocksource driver to the Conexant CX92755 SoC, part of the Digicolor SoCs series. Hardware provides 8 timers, A to H. Timer A is dedicated to a future watchdog driver so we don't use it here. Use timer B for sched_clock, and timer C for clock_event.
--- drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-digicolor.c | 164 ++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 drivers/clocksource/timer-digicolor.c
drivers/clocksource/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o obj-$(CONFIG_EM_TIMER_STI) += em_sti.o obj-$(CONFIG_CLKBLD_I8253) += i8253.o obj-$(CONFIG_CLKSRC_MMIO) += mmio.o +obj-$(CONFIG_ARCH_DIGICOLOR) += timer-digicolor.o obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o obj-$(CONFIG_DW_APB_TIMER_OF) += dw_apb_timer_of.o obj-$(CONFIG_CLKSRC_NOMADIK_MTU) += nomadik-mtu.o
drivers/clocksource/timer-digicolor.c new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v3 1/2] clocksource: devicetree: document Conexant Digicolor timer binding
In reply to Baruch SiachQuoted 1 line · Baruch Siach
Signed-off-by Baruch Siach <[email protected]>
Please add a changelog and a more verbose description: see for example commit 2f2b7fb2 or 926b65e2. If there is a public documentation please add a link to it or give a quick description of how the timer behaves.
Also that will help to review the code in the timer.
Quoted 30 lines
--- .../devicetree/bindings/timer/digicolor-timer.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)create mode 100644
Documentation/devicetree/bindings/timer/digicolor-timer.txtDocumentation/devicetree/bindings/timer/digicolor-timer.txt new file +18
-0@@ -0,0 +1,18 @@ +Conexant Digicolor SoCs Timer Controller + +Required properties: + +- compatible : should be "cnxt,cx92755-timer" +- reg : Specifies base physical address and size of the "Agent Communication" + timer registers +- interrupts : Contains 8 interrupts, one for each timer +- clocks: phandle to the main clock + +Example: + + timer at f0000fc0 { + compatible = "cnxt,cx92755-timer"; + reg = <0xf0000fc0 0x40>; + interrupts = <19>, <31>, <34>, <35>, <52>, <53>, <54>, <55>; + clocks = <&main_clk>; + };
Signature · 5 lines
<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
Re: [PATCH v3 2/2] clocksource: driver for Conexant Digicolor SoC timer
In reply to Baruch SiachQuoted 30 lines · Baruch Siach
Add clocksource driver to the Conexant CX92755 SoC, part of the Digicolor SoCs series. Hardware provides 8 timers, A to H. Timer A is dedicated to a future watchdog driver so we don't use it here. Use timer B for
sched_clock, and timer C forclock_event.Signed-off-by Baruch Siach <[email protected]>--- drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-digicolor.c | 164 ++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+)create mode 100644
drivers/clocksource/timer-digicolor.cdrivers/clocksource/Makefile +1
-0@@ -10,6 +10,7 @@ obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o obj-$(CONFIG_EM_TIMER_STI) += em_sti.o obj-$(CONFIG_CLKBLD_I8253) += i8253.o obj-$(CONFIG_CLKSRC_MMIO) += mmio.o +obj-$(CONFIG_ARCH_DIGICOLOR) += timer-digicolor.o obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o obj-$(CONFIG_DW_APB_TIMER_OF) += dw_apb_timer_of.o obj-$(CONFIG_CLKSRC_NOMADIK_MTU) += nomadik-mtu.odrivers/clocksource/timer-digicolor.c new file +0
-0
drivers/clocksource/timer-digicolor.c line 9
Quoted 9 lines
drivers/clocksource/timer-digicolor.c new file +9
-0@@ -0,0 +1,164 @@ +/* +* Conexant Digicolor timer driver +* +* Author: Baruch Siach <[email protected]> +* +* Copyright (C) 2014 Paradox Innovation Ltd. +* +* Based on: +* Allwinner SoCs hstimer driver
If this is based on the Allwinnner driver, may be you can have a look at the patchset sent by Maxim to make sure your implementation is complete ?
Quoted 34 lines
drivers/clocksource/timer-digicolor.c new file +34
-0+* Copyright (C) 2013 Maxime Ripard +* +* Maxime Ripard <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +/* +* Conexant Digicolor SoCs have 8 configurable timers, named from "Timer A" to +* "Timer H". Timer A is the only one with watchdog support, so it is dedicated +* to the watchdog driver. This driver uses Timer B for sched_clock(), and +* Timer C for clockevents. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/clk.h> +#include <linux/clockchips.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/irqreturn.h> +#include <linux/sched_clock.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> + +enum { +TIMER_A , +TIMER_B , +TIMER_C , +TIMER_D , +TIMER_E ,
drivers/clocksource/timer-digicolor.c line 54
Quoted 10 lines
drivers/clocksource/timer-digicolor.c new file +10
-0+TIMER_F , +TIMER_G , + TIMER_H, +}; + +#define CONTROL (t) ((t)*8) +#define COUNT (t) ((t)*8 + 4) + +static void __iomem *timer_base; +static u32 ticks_per_jiffy;
Mind to encapsulate those global variables in a structure and use container_of to access those fields like:
?
drivers/clocksource/timer-digicolor.c line 61
Quoted 6 lines
drivers/clocksource/timer-digicolor.c new file +6
-0+static void digicolor_clkevt_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +writeb (0 , timer_base +CONTROL (TIMER_C ));
Even if that sounds overkill, please replace '0', '1' with whatever macro name (eg. TIMER_DISABLE/ENABLE).
drivers/clocksource/timer-digicolor.c line 63
Quoted 2 lines
drivers/clocksource/timer-digicolor.c new file +2
-0+writel (ticks_per_jiffy, timer_base +COUNT (TIMER_C )); +writeb (0x21 , timer_base +CONTROL (TIMER_C ));
Please replace 0x21 occurrences by a macro.
drivers/clocksource/timer-digicolor.c line 67
Quoted 4 lines
drivers/clocksource/timer-digicolor.c new file +4
-0+break ; +case CLOCK_EVT_MODE_ONESHOT : +writeb (0 , timer_base +CONTROL (TIMER_C )); +writeb (0x11 , timer_base +CONTROL (TIMER_C ));
Please replace 0x11 occurrences by a macro.
Quoted 5 lines
drivers/clocksource/timer-digicolor.c new file +5
-0+break ; +case CLOCK_EVT_MODE_UNUSED : +case CLOCK_EVT_MODE_SHUTDOWN : +default : +writeb (0 , timer_base +CONTROL (TIMER_C ));
drivers/clocksource/timer-digicolor.c line 82
Quoted 10 lines
drivers/clocksource/timer-digicolor.c new file +10
-0+break ; + } +} + +static int digicolor_clkevt_next_event (unsigned long evt, +struct clock_event_device *unused) +{ +writeb (0 , timer_base +CONTROL (TIMER_C )); +writel (evt, timer_base +COUNT (TIMER_C )); +writeb (0x11 , timer_base +CONTROL (TIMER_C ));
ditto.
Quoted 17 lines
drivers/clocksource/timer-digicolor.c new file +17
-0+return 0 ; +} + +static struct clock_event_device digicolor_clockevent = { + .name ="digicolor_tick" , + .rating =340 , + .features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT , + .set_mode = digicolor_clkevt_mode, + .set_next_event = digicolor_clkevt_next_event, +}; + + +static irqreturn_t digicolor_timer_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = (struct clock_event_device *)dev_id; + + evt->event_handler (evt);
drivers/clocksource/timer-digicolor.c line 110
Quoted 10 lines
drivers/clocksource/timer-digicolor.c new file +10
-0+ +return IRQ_HANDLED ; +} + +static struct irqaction digicolor_timer_irq = { + .name ="digicolor_timerC" , + .flags =IRQF_TIMER |IRQF_IRQPOLL , + .handler = digicolor_timer_interrupt, + .dev_id = &digicolor_clockevent, +};
The current trend is to use 'request_irq', so no such structure declaration/initialization is needed.
Quoted 23 lines
drivers/clocksource/timer-digicolor.c new file +23
-0+static u64 digicolor_timer_sched_read (void ) +{ +return ~readl (timer_base +COUNT (TIMER_B )); +} + +static void __init digicolor_timer_init (struct device_node *node) +{ +unsigned long rate; +struct clk *clk; +int ret, irq; + + timer_base =of_iomap (node,0 ); +if (!timer_base) { +pr_err ("Can't map registers" ); +return ; + } + + irq =irq_of_parse_and_map (node,TIMER_C ); +if (irq <=0 ) { +pr_err ("Can't parse IRQ" ); +return ; + } +
drivers/clocksource/timer-digicolor.c line 144
Quoted 10 lines
drivers/clocksource/timer-digicolor.c new file +10
-0+ clk =of_clk_get (node,0 ); +if (IS_ERR (clk)) { +pr_err ("Can't get timer clock" ); +return ; + } +clk_prepare_enable (clk); + rate =clk_get_rate (clk); + +writeb (0 , timer_base +CONTROL (TIMER_B )); +writel (~0 , timer_base +COUNT (TIMER_B ));
s/~0/UINT_MAX/ ?
drivers/clocksource/timer-digicolor.c line 155
Quoted 11 lines
drivers/clocksource/timer-digicolor.c new file +11
-0+writeb (1 , timer_base +CONTROL (TIMER_B )); + +sched_clock_register (digicolor_timer_sched_read,32 , rate); +clocksource_mmio_init (timer_base +COUNT (TIMER_B ), node->name, + rate,340 ,32 , clocksource_mmio_readl_down); + + ticks_per_jiffy =DIV_ROUND_UP (rate,HZ ); + + ret =setup_irq (irq, &digicolor_timer_irq); +if (ret) +pr_warn ("failed to setup timer irq %d (%d)\n" , irq, ret);
s/setup_irq/request_irq/
Quoted 10 lines
drivers/clocksource/timer-digicolor.c new file +9
-0+ + digicolor_clockevent.cpumask = cpu_possible_mask; + digicolor_clockevent.irq = irq; + +clockevents_config_and_register (&digicolor_clockevent, rate,0 , +0xffffffff ); +} +CLOCKSOURCE_OF_DECLARE (conexant_digicolor,"cnxt,cx92755-timer" , + digicolor_timer_init);
Signature · 5 lines
<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
Baruch Siach
maintainerRe: [PATCH v3 2/2] clocksource: driver for Conexant Digicolor SoC timer
Hi Daniel,
Quoted 8 lines · Daniel Lezcano
Quoted 2 lines · Baruch Siach
+ * Based on:
+ * Allwinner SoCs hstimer driverIf this is based on the Allwinnner driver, may be you can have a look at the patchset sent by Maxim to make sure your implementation is complete ?
Thanks for the tip. I'll take the applicable parts from that series.
[...]
Quoted 9 lines
drivers/clocksource/timer-digicolor.c line 54
Quoted 2 lines
drivers/clocksource/timer-digicolor.c new file +2
-0+static void __iomem *timer_base; +static u32 ticks_per_jiffy;Mind to encapsulate those global variables in a structure and use
container_ofto access those fields like:?
The trouble is that the sched_clock callback (digicolor_timer_sched_read) needs a static timer_base to find the timer counter. Do you think adding a structure is worth it only for ticks_per_jiffy?
Quoted 9 lines
drivers/clocksource/timer-digicolor.c line 61
Quoted 6 lines
drivers/clocksource/timer-digicolor.c new file +6
-0+static void digicolor_clkevt_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +writeb (0 , timer_base +CONTROL (TIMER_C ));Even if that sounds overkill, please replace '0', '1' with whatever macro name (eg. TIMER_DISABLE/ENABLE).
Will do for the entire file.
[...]
Quoted 9 lines
drivers/clocksource/timer-digicolor.c line 110
Quoted 6 lines
drivers/clocksource/timer-digicolor.c new file +6
-0+static struct irqaction digicolor_timer_irq = { + .name ="digicolor_timerC" , + .flags =IRQF_TIMER |IRQF_IRQPOLL , + .handler = digicolor_timer_interrupt, + .dev_id = &digicolor_clockevent, +};The current trend is to use '
request_irq', so no such structure declaration/initialization is needed.
Thanks. Will do.
Quoted 3 lines
drivers/clocksource/timer-digicolor.c line 144
Quoted 1 line
drivers/clocksource/timer-digicolor.c new file +1
-0+writel (~0 , timer_base +COUNT (TIMER_B ));s/~0/UINT_MAX/ ?
Ack.
Thanks for reviewing. I'll post an updated series shortly.
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -Re: [PATCH v3 2/2] clocksource: driver for Conexant Digicolor SoC timer
Quoted 22 lines · Baruch Siach
Hi Daniel,
Quoted 8 lines · Daniel Lezcano
Quoted 2 lines · Baruch Siach
+ * Based on:
+ * Allwinner SoCs hstimer driverIf this is based on the Allwinnner driver, may be you can have a look at the patchset sent by Maxim to make sure your implementation is complete ?
Thanks for the tip. I'll take the applicable parts from that series.
[...]
Quoted 6 lines
drivers/clocksource/timer-digicolor.c line 54
Quoted 2 lines
drivers/clocksource/timer-digicolor.c new file +2
-0+static void __iomem *timer_base; +static u32 ticks_per_jiffy;Mind to encapsulate those global variables in a structure and use
container_ofto access those fields like:
Quoted 7 lines
Quoted 3 lines
?
The trouble is that the
sched_clockcallback (digicolor_timer_sched_read) needs a statictimer_baseto find the timer counter. Do you think adding a structure is worth it only forticks_per_jiffy?
Well you will have to define the global variable for this structure. So you should be able to access the timer base directly. I agree it is not perfect but at least that will encapsulate the code for the clockevents side.
Quoted 26 lines
Quoted 9 lines
drivers/clocksource/timer-digicolor.c line 61
Quoted 6 lines
drivers/clocksource/timer-digicolor.c new file +6
-0+static void digicolor_clkevt_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +writeb (0 , timer_base +CONTROL (TIMER_C ));Even if that sounds overkill, please replace '0', '1' with whatever macro name (eg. TIMER_DISABLE/ENABLE).
Will do for the entire file.
[...]
Quoted 9 lines
drivers/clocksource/timer-digicolor.c line 110
Quoted 6 lines
drivers/clocksource/timer-digicolor.c new file +6
-0+static struct irqaction digicolor_timer_irq = { + .name ="digicolor_timerC" , + .flags =IRQF_TIMER |IRQF_IRQPOLL , + .handler = digicolor_timer_interrupt, + .dev_id = &digicolor_clockevent, +};The current trend is to use '
request_irq', so no such structure declaration/initialization is needed.Thanks. Will do.
Quoted 7 lines
Quoted 3 lines
drivers/clocksource/timer-digicolor.c line 144
Quoted 1 line
drivers/clocksource/timer-digicolor.c new file +1
-0+writel (~0 , timer_base +COUNT (TIMER_B ));s/~0/UINT_MAX/ ?
Ack.
Thanks for reviewing. I'll post an updated series shortly.
Ok, thanks.
-- Daniel
Signature · 5 lines
<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