Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 1 | /* |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 2 | * at91sam926x_time.c - Periodic Interval Timer (PIT) for at91sam926x |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005-2006 M. Amine SAYA, ATMEL Rousset, France |
| 5 | * Revision 2005 M. Nicolas Diremdjian, ATMEL Rousset, France |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 6 | * Converted to ClockSource/ClockEvents by David Brownell. |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
Maxime Ripard | 52c3ffb | 2014-07-01 11:33:14 +0200 | [diff] [blame] | 12 | |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 13 | #define pr_fmt(fmt) "AT91: PIT: " fmt |
| 14 | |
Maxime Ripard | 52c3ffb | 2014-07-01 11:33:14 +0200 | [diff] [blame] | 15 | #include <linux/clk.h> |
| 16 | #include <linux/clockchips.h> |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/irq.h> |
| 19 | #include <linux/kernel.h> |
Jean-Christophe PLAGNIOL-VILLARD | 23fa648 | 2012-02-27 11:19:34 +0100 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_address.h> |
| 22 | #include <linux/of_irq.h> |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 23 | #include <linux/slab.h> |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 24 | |
Uwe Kleine-König | ac11a1d | 2013-11-14 10:49:19 +0100 | [diff] [blame] | 25 | #include <mach/hardware.h> |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 26 | |
Jean-Christophe PLAGNIOL-VILLARD | ffe5cd8 | 2012-10-30 08:09:09 +0800 | [diff] [blame] | 27 | #define AT91_PIT_MR 0x00 /* Mode Register */ |
Maxime Ripard | 52c3ffb | 2014-07-01 11:33:14 +0200 | [diff] [blame] | 28 | #define AT91_PIT_PITIEN BIT(25) /* Timer Interrupt Enable */ |
| 29 | #define AT91_PIT_PITEN BIT(24) /* Timer Enabled */ |
| 30 | #define AT91_PIT_PIV GENMASK(19, 0) /* Periodic Interval Value */ |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 31 | |
Jean-Christophe PLAGNIOL-VILLARD | ffe5cd8 | 2012-10-30 08:09:09 +0800 | [diff] [blame] | 32 | #define AT91_PIT_SR 0x04 /* Status Register */ |
Maxime Ripard | 52c3ffb | 2014-07-01 11:33:14 +0200 | [diff] [blame] | 33 | #define AT91_PIT_PITS BIT(0) /* Timer Status */ |
Jean-Christophe PLAGNIOL-VILLARD | ffe5cd8 | 2012-10-30 08:09:09 +0800 | [diff] [blame] | 34 | |
| 35 | #define AT91_PIT_PIVR 0x08 /* Periodic Interval Value Register */ |
| 36 | #define AT91_PIT_PIIR 0x0c /* Periodic Interval Image Register */ |
Maxime Ripard | 52c3ffb | 2014-07-01 11:33:14 +0200 | [diff] [blame] | 37 | #define AT91_PIT_PICNT GENMASK(31, 20) /* Interval Counter */ |
| 38 | #define AT91_PIT_CPIV GENMASK(19, 0) /* Inverval Value */ |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 39 | |
| 40 | #define PIT_CPIV(x) ((x) & AT91_PIT_CPIV) |
| 41 | #define PIT_PICNT(x) (((x) & AT91_PIT_PICNT) >> 20) |
| 42 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 43 | struct pit_data { |
| 44 | struct clock_event_device clkevt; |
| 45 | struct clocksource clksrc; |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 46 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 47 | void __iomem *base; |
| 48 | u32 cycle; |
| 49 | u32 cnt; |
| 50 | unsigned int irq; |
| 51 | struct clk *mck; |
| 52 | }; |
| 53 | |
| 54 | static inline struct pit_data *clksrc_to_pit_data(struct clocksource *clksrc) |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 55 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 56 | return container_of(clksrc, struct pit_data, clksrc); |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 57 | } |
| 58 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 59 | static inline struct pit_data *clkevt_to_pit_data(struct clock_event_device *clkevt) |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 60 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 61 | return container_of(clkevt, struct pit_data, clkevt); |
| 62 | } |
| 63 | |
| 64 | static inline unsigned int pit_read(void __iomem *base, unsigned int reg_offset) |
| 65 | { |
| 66 | return __raw_readl(base + reg_offset); |
| 67 | } |
| 68 | |
| 69 | static inline void pit_write(void __iomem *base, unsigned int reg_offset, unsigned long value) |
| 70 | { |
| 71 | __raw_writel(value, base + reg_offset); |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 72 | } |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 73 | |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 74 | /* |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 75 | * Clocksource: just a monotonic counter of MCK/16 cycles. |
| 76 | * We don't care whether or not PIT irqs are enabled. |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 77 | */ |
Magnus Damm | 8e19608 | 2009-04-21 12:24:00 -0700 | [diff] [blame] | 78 | static cycle_t read_pit_clk(struct clocksource *cs) |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 79 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 80 | struct pit_data *data = clksrc_to_pit_data(cs); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 81 | unsigned long flags; |
| 82 | u32 elapsed; |
| 83 | u32 t; |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 84 | |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 85 | raw_local_irq_save(flags); |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 86 | elapsed = data->cnt; |
| 87 | t = pit_read(data->base, AT91_PIT_PIIR); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 88 | raw_local_irq_restore(flags); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 89 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 90 | elapsed += PIT_PICNT(t) * data->cycle; |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 91 | elapsed += PIT_CPIV(t); |
| 92 | return elapsed; |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 95 | /* |
| 96 | * Clockevent device: interrupts every 1/HZ (== pit_cycles * MCK/16) |
| 97 | */ |
| 98 | static void |
| 99 | pit_clkevt_mode(enum clock_event_mode mode, struct clock_event_device *dev) |
| 100 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 101 | struct pit_data *data = clkevt_to_pit_data(dev); |
| 102 | |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 103 | switch (mode) { |
| 104 | case CLOCK_EVT_MODE_PERIODIC: |
Uwe Kleine-König | 501d703 | 2009-09-21 09:30:09 +0200 | [diff] [blame] | 105 | /* update clocksource counter */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 106 | data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR)); |
| 107 | pit_write(data->base, AT91_PIT_MR, |
| 108 | (data->cycle - 1) | AT91_PIT_PITEN | AT91_PIT_PITIEN); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 109 | break; |
| 110 | case CLOCK_EVT_MODE_ONESHOT: |
| 111 | BUG(); |
| 112 | /* FALLTHROUGH */ |
| 113 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 114 | case CLOCK_EVT_MODE_UNUSED: |
| 115 | /* disable irq, leaving the clocksource active */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 116 | pit_write(data->base, AT91_PIT_MR, |
| 117 | (data->cycle - 1) | AT91_PIT_PITEN); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 118 | break; |
| 119 | case CLOCK_EVT_MODE_RESUME: |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 124 | static void at91sam926x_pit_suspend(struct clock_event_device *cedev) |
| 125 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 126 | struct pit_data *data = clkevt_to_pit_data(cedev); |
| 127 | |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 128 | /* Disable timer */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 129 | pit_write(data->base, AT91_PIT_MR, 0); |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 132 | static void at91sam926x_pit_reset(struct pit_data *data) |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 133 | { |
| 134 | /* Disable timer and irqs */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 135 | pit_write(data->base, AT91_PIT_MR, 0); |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 136 | |
| 137 | /* Clear any pending interrupts, wait for PIT to stop counting */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 138 | while (PIT_CPIV(pit_read(data->base, AT91_PIT_PIVR)) != 0) |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 139 | cpu_relax(); |
| 140 | |
| 141 | /* Start PIT but don't enable IRQ */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 142 | pit_write(data->base, AT91_PIT_MR, |
| 143 | (data->cycle - 1) | AT91_PIT_PITEN); |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void at91sam926x_pit_resume(struct clock_event_device *cedev) |
| 147 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 148 | struct pit_data *data = clkevt_to_pit_data(cedev); |
| 149 | |
| 150 | at91sam926x_pit_reset(data); |
Stephen Warren | 49356ae | 2012-11-07 16:32:41 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 153 | /* |
| 154 | * IRQ handler for the timer. |
| 155 | */ |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 156 | static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id) |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 157 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 158 | struct pit_data *data = dev_id; |
| 159 | |
Uwe Kleine-König | 501d703 | 2009-09-21 09:30:09 +0200 | [diff] [blame] | 160 | /* |
| 161 | * irqs should be disabled here, but as the irq is shared they are only |
| 162 | * guaranteed to be off if the timer irq is registered first. |
| 163 | */ |
| 164 | WARN_ON_ONCE(!irqs_disabled()); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 165 | |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 166 | /* The PIT interrupt may be disabled, and is shared */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 167 | if ((data->clkevt.mode == CLOCK_EVT_MODE_PERIODIC) && |
| 168 | (pit_read(data->base, AT91_PIT_SR) & AT91_PIT_PITS)) { |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 169 | unsigned nr_ticks; |
| 170 | |
| 171 | /* Get number of ticks performed before irq, and ack it */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 172 | nr_ticks = PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR)); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 173 | do { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 174 | data->cnt += data->cycle; |
| 175 | data->clkevt.event_handler(&data->clkevt); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 176 | nr_ticks--; |
| 177 | } while (nr_ticks); |
| 178 | |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 179 | return IRQ_HANDLED; |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | return IRQ_NONE; |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 185 | /* |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 186 | * Set up both clocksource and clockevent support. |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 187 | */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 188 | static void __init at91sam926x_pit_common_init(struct pit_data *data) |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 189 | { |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 190 | unsigned long pit_rate; |
| 191 | unsigned bits; |
Nicolas Ferre | 986c265 | 2012-02-17 11:54:29 +0100 | [diff] [blame] | 192 | int ret; |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 193 | |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 194 | /* |
| 195 | * Use our actual MCK to figure out how many MCK/16 ticks per |
| 196 | * 1/HZ period (instead of a compile-time constant LATCH). |
| 197 | */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 198 | pit_rate = clk_get_rate(data->mck) / 16; |
| 199 | data->cycle = DIV_ROUND_CLOSEST(pit_rate, HZ); |
| 200 | WARN_ON(((data->cycle - 1) & ~AT91_PIT_PIV) != 0); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 201 | |
| 202 | /* Initialize and enable the timer */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 203 | at91sam926x_pit_reset(data); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Register clocksource. The high order bits of PIV are unused, |
| 207 | * so this isn't a 32-bit counter unless we get clockevent irqs. |
| 208 | */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 209 | bits = 12 /* PICNT */ + ilog2(data->cycle) /* PIV */; |
| 210 | data->clksrc.mask = CLOCKSOURCE_MASK(bits); |
| 211 | data->clksrc.name = "pit"; |
| 212 | data->clksrc.rating = 175; |
| 213 | data->clksrc.read = read_pit_clk, |
| 214 | data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS, |
| 215 | clocksource_register_hz(&data->clksrc, pit_rate); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 216 | |
| 217 | /* Set up irq handler */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 218 | ret = request_irq(data->irq, at91sam926x_pit_interrupt, |
Maxime Ripard | 7f282e0 | 2014-07-01 11:33:22 +0200 | [diff] [blame] | 219 | IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL, |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 220 | "at91_tick", data); |
Nicolas Ferre | 986c265 | 2012-02-17 11:54:29 +0100 | [diff] [blame] | 221 | if (ret) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 222 | panic(pr_fmt("Unable to setup IRQ\n")); |
Andrew Victor | ad48ce7 | 2008-04-16 20:43:49 +0100 | [diff] [blame] | 223 | |
| 224 | /* Set up and register clockevents */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 225 | data->clkevt.name = "pit"; |
| 226 | data->clkevt.features = CLOCK_EVT_FEAT_PERIODIC; |
| 227 | data->clkevt.shift = 32; |
| 228 | data->clkevt.mult = div_sc(pit_rate, NSEC_PER_SEC, data->clkevt.shift); |
| 229 | data->clkevt.rating = 100; |
| 230 | data->clkevt.cpumask = cpumask_of(0); |
| 231 | |
| 232 | data->clkevt.set_mode = pit_clkevt_mode; |
| 233 | data->clkevt.resume = at91sam926x_pit_resume; |
| 234 | data->clkevt.suspend = at91sam926x_pit_suspend; |
| 235 | clockevents_register_device(&data->clkevt); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 238 | static void __init at91sam926x_pit_dt_init(struct device_node *node) |
| 239 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 240 | struct pit_data *data; |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 241 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 242 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 243 | if (!data) |
| 244 | panic(pr_fmt("Unable to allocate memory\n")); |
| 245 | |
| 246 | data->base = of_iomap(node, 0); |
| 247 | if (!data->base) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 248 | panic(pr_fmt("Could not map PIT address\n")); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 249 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 250 | data->mck = of_clk_get(node, 0); |
| 251 | if (IS_ERR(data->mck)) |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 252 | /* Fallback on clkdev for !CCF-based boards */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 253 | data->mck = clk_get(NULL, "mck"); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 254 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 255 | if (IS_ERR(data->mck)) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 256 | panic(pr_fmt("Unable to get mck clk\n")); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 257 | |
| 258 | /* Get the interrupts property */ |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 259 | data->irq = irq_of_parse_and_map(node, 0); |
| 260 | if (!data->irq) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 261 | panic(pr_fmt("Unable to get IRQ from DT\n")); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 262 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 263 | at91sam926x_pit_common_init(data); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 264 | } |
| 265 | CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", |
| 266 | at91sam926x_pit_dt_init); |
| 267 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 268 | static void __iomem *pit_base_addr; |
| 269 | |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 270 | void __init at91sam926x_pit_init(void) |
| 271 | { |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 272 | struct pit_data *data; |
| 273 | |
| 274 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 275 | if (!data) |
| 276 | panic(pr_fmt("Unable to allocate memory\n")); |
| 277 | |
| 278 | data->base = pit_base_addr; |
| 279 | |
| 280 | data->mck = clk_get(NULL, "mck"); |
| 281 | if (IS_ERR(data->mck)) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 282 | panic(pr_fmt("Unable to get mck clk\n")); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 283 | |
Maxime Ripard | 64568d1 | 2014-07-01 11:33:23 +0200 | [diff] [blame] | 284 | data->irq = NR_IRQS_LEGACY + AT91_ID_SYS; |
| 285 | |
| 286 | at91sam926x_pit_common_init(data); |
Maxime Ripard | f807a89 | 2014-07-01 11:33:18 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 289 | void __init at91sam926x_ioremap_pit(u32 addr) |
| 290 | { |
Maxime Ripard | a7d84d7 | 2014-07-01 11:33:17 +0200 | [diff] [blame] | 291 | if (of_have_populated_dt()) |
Jean-Christophe PLAGNIOL-VILLARD | 23fa648 | 2012-02-27 11:19:34 +0100 | [diff] [blame] | 292 | return; |
Maxime Ripard | a7d84d7 | 2014-07-01 11:33:17 +0200 | [diff] [blame] | 293 | |
Jean-Christophe PLAGNIOL-VILLARD | 4ab0c599 | 2011-09-18 22:29:50 +0800 | [diff] [blame] | 294 | pit_base_addr = ioremap(addr, 16); |
| 295 | |
| 296 | if (!pit_base_addr) |
Maxime Ripard | cffbfe6 | 2014-07-01 11:33:21 +0200 | [diff] [blame] | 297 | panic(pr_fmt("Impossible to ioremap PIT\n")); |
Andrew Victor | 1a0ed73 | 2006-12-01 09:04:47 +0100 | [diff] [blame] | 298 | } |