diff options
| author | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2015-03-12 08:07:31 -0400 |
|---|---|---|
| committer | Nicolas Ferre <nicolas.ferre@atmel.com> | 2015-03-16 12:03:05 -0400 |
| commit | b53cdd03222391f76e82cd0c7d040816c919ab75 (patch) | |
| tree | 442907fe49dbb8dbdf49e236643825f483336c42 /drivers/clocksource | |
| parent | bbfc97e1b1b9fb2177a9134f57506eb371638b85 (diff) | |
ARM: at91: time: move the system timer driver to drivers/clocksource
Import at91rm9200_time.c from mach-at91 as timer-atmel-st.c. Further cleanup is
required to get rid of the mach-at91 headers.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Diffstat (limited to 'drivers/clocksource')
| -rw-r--r-- | drivers/clocksource/Kconfig | 4 | ||||
| -rw-r--r-- | drivers/clocksource/Makefile | 1 | ||||
| -rw-r--r-- | drivers/clocksource/timer-atmel-st.c | 253 |
3 files changed, 258 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 68161f7a07d6..168035883afa 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig | |||
| @@ -143,6 +143,10 @@ config ATMEL_PIT | |||
| 143 | select CLKSRC_OF if OF | 143 | select CLKSRC_OF if OF |
| 144 | def_bool SOC_AT91SAM9 || SOC_SAMA5 | 144 | def_bool SOC_AT91SAM9 || SOC_SAMA5 |
| 145 | 145 | ||
| 146 | config ATMEL_ST | ||
| 147 | bool | ||
| 148 | select CLKSRC_OF | ||
| 149 | |||
| 146 | config CLKSRC_METAG_GENERIC | 150 | config CLKSRC_METAG_GENERIC |
| 147 | def_bool y if METAG | 151 | def_bool y if METAG |
| 148 | help | 152 | help |
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 752d5c70b0ef..5b85f6adb258 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | obj-$(CONFIG_CLKSRC_OF) += clksrc-of.o | 1 | obj-$(CONFIG_CLKSRC_OF) += clksrc-of.o |
| 2 | obj-$(CONFIG_ATMEL_PIT) += timer-atmel-pit.o | 2 | obj-$(CONFIG_ATMEL_PIT) += timer-atmel-pit.o |
| 3 | obj-$(CONFIG_ATMEL_ST) += timer-atmel-st.o | ||
| 3 | obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o | 4 | obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o |
| 4 | obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o | 5 | obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o |
| 5 | obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o | 6 | obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o |
diff --git a/drivers/clocksource/timer-atmel-st.c b/drivers/clocksource/timer-atmel-st.c new file mode 100644 index 000000000000..7d062ab32674 --- /dev/null +++ b/drivers/clocksource/timer-atmel-st.c | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | /* | ||
| 2 | * linux/arch/arm/mach-at91/at91rm9200_time.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2003 SAN People | ||
| 5 | * Copyright (C) 2003 ATMEL | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <linux/kernel.h> | ||
| 23 | #include <linux/interrupt.h> | ||
| 24 | #include <linux/irq.h> | ||
| 25 | #include <linux/clockchips.h> | ||
| 26 | #include <linux/export.h> | ||
| 27 | #include <linux/of.h> | ||
| 28 | #include <linux/of_address.h> | ||
| 29 | #include <linux/of_irq.h> | ||
| 30 | |||
| 31 | #include <asm/mach/time.h> | ||
| 32 | |||
| 33 | #include <mach/at91_st.h> | ||
| 34 | #include <mach/hardware.h> | ||
| 35 | |||
| 36 | static unsigned long last_crtr; | ||
| 37 | static u32 irqmask; | ||
| 38 | static struct clock_event_device clkevt; | ||
| 39 | |||
| 40 | #define RM9200_TIMER_LATCH ((AT91_SLOW_CLOCK + HZ/2) / HZ) | ||
| 41 | |||
| 42 | /* | ||
| 43 | * The ST_CRTR is updated asynchronously to the master clock ... but | ||
| 44 | * the updates as seen by the CPU don't seem to be strictly monotonic. | ||
| 45 | * Waiting until we read the same value twice avoids glitching. | ||
| 46 | */ | ||
| 47 | static inline unsigned long read_CRTR(void) | ||
| 48 | { | ||
| 49 | unsigned long x1, x2; | ||
| 50 | |||
| 51 | x1 = at91_st_read(AT91_ST_CRTR); | ||
| 52 | do { | ||
| 53 | x2 = at91_st_read(AT91_ST_CRTR); | ||
| 54 | if (x1 == x2) | ||
| 55 | break; | ||
| 56 | x1 = x2; | ||
| 57 | } while (1); | ||
| 58 | return x1; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* | ||
| 62 | * IRQ handler for the timer. | ||
| 63 | */ | ||
| 64 | static irqreturn_t at91rm9200_timer_interrupt(int irq, void *dev_id) | ||
| 65 | { | ||
| 66 | u32 sr = at91_st_read(AT91_ST_SR) & irqmask; | ||
| 67 | |||
| 68 | /* | ||
| 69 | * irqs should be disabled here, but as the irq is shared they are only | ||
| 70 | * guaranteed to be off if the timer irq is registered first. | ||
| 71 | */ | ||
| 72 | WARN_ON_ONCE(!irqs_disabled()); | ||
| 73 | |||
| 74 | /* simulate "oneshot" timer with alarm */ | ||
| 75 | if (sr & AT91_ST_ALMS) { | ||
| 76 | clkevt.event_handler(&clkevt); | ||
| 77 | return IRQ_HANDLED; | ||
| 78 | } | ||
| 79 | |||
| 80 | /* periodic mode should handle delayed ticks */ | ||
| 81 | if (sr & AT91_ST_PITS) { | ||
| 82 | u32 crtr = read_CRTR(); | ||
| 83 | |||
| 84 | while (((crtr - last_crtr) & AT91_ST_CRTV) >= RM9200_TIMER_LATCH) { | ||
| 85 | last_crtr += RM9200_TIMER_LATCH; | ||
| 86 | clkevt.event_handler(&clkevt); | ||
| 87 | } | ||
| 88 | return IRQ_HANDLED; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* this irq is shared ... */ | ||
| 92 | return IRQ_NONE; | ||
| 93 | } | ||
| 94 | |||
| 95 | static struct irqaction at91rm9200_timer_irq = { | ||
| 96 | .name = "at91_tick", | ||
| 97 | .flags = IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL, | ||
| 98 | .handler = at91rm9200_timer_interrupt, | ||
| 99 | .irq = NR_IRQS_LEGACY + AT91_ID_SYS, | ||
| 100 | }; | ||
| 101 | |||
| 102 | static cycle_t read_clk32k(struct clocksource *cs) | ||
| 103 | { | ||
| 104 | return read_CRTR(); | ||
| 105 | } | ||
| 106 | |||
| 107 | static struct clocksource clk32k = { | ||
| 108 | .name = "32k_counter", | ||
| 109 | .rating = 150, | ||
| 110 | .read = read_clk32k, | ||
| 111 | .mask = CLOCKSOURCE_MASK(20), | ||
| 112 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | ||
| 113 | }; | ||
| 114 | |||
| 115 | static void | ||
| 116 | clkevt32k_mode(enum clock_event_mode mode, struct clock_event_device *dev) | ||
| 117 | { | ||
| 118 | /* Disable and flush pending timer interrupts */ | ||
| 119 | at91_st_write(AT91_ST_IDR, AT91_ST_PITS | AT91_ST_ALMS); | ||
| 120 | at91_st_read(AT91_ST_SR); | ||
| 121 | |||
| 122 | last_crtr = read_CRTR(); | ||
| 123 | switch (mode) { | ||
| 124 | case CLOCK_EVT_MODE_PERIODIC: | ||
| 125 | /* PIT for periodic irqs; fixed rate of 1/HZ */ | ||
| 126 | irqmask = AT91_ST_PITS; | ||
| 127 | at91_st_write(AT91_ST_PIMR, RM9200_TIMER_LATCH); | ||
| 128 | break; | ||
| 129 | case CLOCK_EVT_MODE_ONESHOT: | ||
| 130 | /* ALM for oneshot irqs, set by next_event() | ||
| 131 | * before 32 seconds have passed | ||
| 132 | */ | ||
| 133 | irqmask = AT91_ST_ALMS; | ||
| 134 | at91_st_write(AT91_ST_RTAR, last_crtr); | ||
| 135 | break; | ||
| 136 | case CLOCK_EVT_MODE_SHUTDOWN: | ||
| 137 | case CLOCK_EVT_MODE_UNUSED: | ||
| 138 | case CLOCK_EVT_MODE_RESUME: | ||
| 139 | irqmask = 0; | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | at91_st_write(AT91_ST_IER, irqmask); | ||
| 143 | } | ||
| 144 | |||
| 145 | static int | ||
| 146 | clkevt32k_next_event(unsigned long delta, struct clock_event_device *dev) | ||
| 147 | { | ||
| 148 | u32 alm; | ||
| 149 | int status = 0; | ||
| 150 | |||
| 151 | BUG_ON(delta < 2); | ||
| 152 | |||
| 153 | /* The alarm IRQ uses absolute time (now+delta), not the relative | ||
| 154 | * time (delta) in our calling convention. Like all clockevents | ||
| 155 | * using such "match" hardware, we have a race to defend against. | ||
| 156 | * | ||
| 157 | * Our defense here is to have set up the clockevent device so the | ||
| 158 | * delta is at least two. That way we never end up writing RTAR | ||
| 159 | * with the value then held in CRTR ... which would mean the match | ||
