blob: 59e8aee0ec16dcf68d2dae5ac8959c4778e3f2d0 [file] [log] [blame]
David Brownell4d243f92008-02-22 17:28:37 -08001#include <linux/init.h>
2#include <linux/clocksource.h>
3#include <linux/clockchips.h>
4#include <linux/interrupt.h>
5#include <linux/irq.h>
6
7#include <linux/clk.h>
8#include <linux/err.h>
9#include <linux/ioport.h>
10#include <linux/io.h>
11#include <linux/platform_device.h>
Alexandre Belloni2a515e52017-05-12 20:22:51 +020012#include <linux/syscore_ops.h>
David Brownell4d243f92008-02-22 17:28:37 -080013#include <linux/atmel_tc.h>
14
15
16/*
17 * We're configured to use a specific TC block, one that's not hooked
18 * up to external hardware, to provide a time solution:
19 *
20 * - Two channels combine to create a free-running 32 bit counter
21 * with a base rate of 5+ MHz, packaged as a clocksource (with
22 * resolution better than 200 nsec).
Nicolas Ferre8e315a72012-01-19 18:44:49 +010023 * - Some chips support 32 bit counter. A single channel is used for
24 * this 32 bit free-running counter. the second channel is not used.
David Brownell4d243f92008-02-22 17:28:37 -080025 *
26 * - The third channel may be used to provide a 16-bit clockevent
27 * source, used in either periodic or oneshot mode. This runs
28 * at 32 KiHZ, and can handle delays of up to two seconds.
29 *
30 * A boot clocksource and clockevent source are also currently needed,
31 * unless the relevant platforms (ARM/AT91, AVR32/AT32) are changed so
32 * this code can be used when init_timers() is called, well before most
33 * devices are set up. (Some low end AT91 parts, which can run uClinux,
34 * have only the timers in one TC block... they currently don't support
35 * the tclib code, because of that initialization issue.)
36 *
37 * REVISIT behavior during system suspend states... we should disable
38 * all clocks and save the power. Easily done for clockevent devices,
39 * but clocksources won't necessarily get the needed notifications.
40 * For deeper system sleep states, this will be mandatory...
41 */
42
43static void __iomem *tcaddr;
Alexandre Belloni2a515e52017-05-12 20:22:51 +020044static struct
45{
46 u32 cmr;
47 u32 imr;
48 u32 rc;
49 bool clken;
50} tcb_cache[3];
51static u32 bmr_cache;
David Brownell4d243f92008-02-22 17:28:37 -080052
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010053static u64 tc_get_cycles(struct clocksource *cs)
David Brownell4d243f92008-02-22 17:28:37 -080054{
55 unsigned long flags;
56 u32 lower, upper;
57
58 raw_local_irq_save(flags);
59 do {
Alexandre Belloni6ec8be22017-06-23 17:03:31 +020060 upper = readl_relaxed(tcaddr + ATMEL_TC_REG(1, CV));
61 lower = readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV));
62 } while (upper != readl_relaxed(tcaddr + ATMEL_TC_REG(1, CV)));
David Brownell4d243f92008-02-22 17:28:37 -080063
64 raw_local_irq_restore(flags);
65 return (upper << 16) | lower;
66}
67
David Engraf7b9f1d12017-01-11 14:50:59 +010068static u64 tc_get_cycles32(struct clocksource *cs)
69{
Alexandre Belloni6ec8be22017-06-23 17:03:31 +020070 return readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV));
David Engraf7b9f1d12017-01-11 14:50:59 +010071}
72
Alexandre Belloni2a515e52017-05-12 20:22:51 +020073void tc_clksrc_suspend(struct clocksource *cs)
74{
75 int i;
76
77 for (i = 0; i < ARRAY_SIZE(tcb_cache); i++) {
78 tcb_cache[i].cmr = readl(tcaddr + ATMEL_TC_REG(i, CMR));
79 tcb_cache[i].imr = readl(tcaddr + ATMEL_TC_REG(i, IMR));
80 tcb_cache[i].rc = readl(tcaddr + ATMEL_TC_REG(i, RC));
81 tcb_cache[i].clken = !!(readl(tcaddr + ATMEL_TC_REG(i, SR)) &
82 ATMEL_TC_CLKSTA);
83 }
84
85 bmr_cache = readl(tcaddr + ATMEL_TC_BMR);
86}
87
88void tc_clksrc_resume(struct clocksource *cs)
89{
90 int i;
91
92 for (i = 0; i < ARRAY_SIZE(tcb_cache); i++) {
93 /* Restore registers for the channel, RA and RB are not used */
94 writel(tcb_cache[i].cmr, tcaddr + ATMEL_TC_REG(i, CMR));
95 writel(tcb_cache[i].rc, tcaddr + ATMEL_TC_REG(i, RC));
96 writel(0, tcaddr + ATMEL_TC_REG(i, RA));
97 writel(0, tcaddr + ATMEL_TC_REG(i, RB));
98 /* Disable all the interrupts */
99 writel(0xff, tcaddr + ATMEL_TC_REG(i, IDR));
100 /* Reenable interrupts that were enabled before suspending */
101 writel(tcb_cache[i].imr, tcaddr + ATMEL_TC_REG(i, IER));
102 /* Start the clock if it was used */
103 if (tcb_cache[i].clken)
104 writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(i, CCR));
105 }
106
107 /* Dual channel, chain channels */
108 writel(bmr_cache, tcaddr + ATMEL_TC_BMR);
109 /* Finally, trigger all the channels*/
110 writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR);
111}
112
David Brownell4d243f92008-02-22 17:28:37 -0800113static struct clocksource clksrc = {
114 .name = "tcb_clksrc",
115 .rating = 200,
116 .read = tc_get_cycles,
117 .mask = CLOCKSOURCE_MASK(32),
David Brownell4d243f92008-02-22 17:28:37 -0800118 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
Alexandre Belloni2a515e52017-05-12 20:22:51 +0200119 .suspend = tc_clksrc_suspend,
120 .resume = tc_clksrc_resume,
David Brownell4d243f92008-02-22 17:28:37 -0800121};
122
123#ifdef CONFIG_GENERIC_CLOCKEVENTS
124
125struct tc_clkevt_device {
126 struct clock_event_device clkevt;
127 struct clk *clk;
128 void __iomem *regs;
129};
130
131static struct tc_clkevt_device *to_tc_clkevt(struct clock_event_device *clkevt)
132{
133 return container_of(clkevt, struct tc_clkevt_device, clkevt);
134}
135
136/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
137 * because using one of the divided clocks would usually mean the
138 * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
139 *
140 * A divided clock could be good for high resolution timers, since
141 * 30.5 usec resolution can seem "low".
142 */
143static u32 timer_clock;
144
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530145static int tc_shutdown(struct clock_event_device *d)
David Brownell4d243f92008-02-22 17:28:37 -0800146{
147 struct tc_clkevt_device *tcd = to_tc_clkevt(d);
148 void __iomem *regs = tcd->regs;
149
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200150 writel(0xff, regs + ATMEL_TC_REG(2, IDR));
151 writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
Alexandre Bellonif02b4b72016-01-15 11:34:21 +0100152 if (!clockevent_state_detached(d))
153 clk_disable(tcd->clk);
David Brownell4d243f92008-02-22 17:28:37 -0800154
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530155 return 0;
156}
157
158static int tc_set_oneshot(struct clock_event_device *d)
159{
160 struct tc_clkevt_device *tcd = to_tc_clkevt(d);
161 void __iomem *regs = tcd->regs;
162
163 if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
164 tc_shutdown(d);
165
166 clk_enable(tcd->clk);
167
168 /* slow clock, count up to RC, then irq and stop */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200169 writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530170 ATMEL_TC_WAVESEL_UP_AUTO, regs + ATMEL_TC_REG(2, CMR));
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200171 writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530172
173 /* set_next_event() configures and starts the timer */
174 return 0;
175}
176
177static int tc_set_periodic(struct clock_event_device *d)
178{
179 struct tc_clkevt_device *tcd = to_tc_clkevt(d);
180 void __iomem *regs = tcd->regs;
181
182 if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
183 tc_shutdown(d);
David Brownell4d243f92008-02-22 17:28:37 -0800184
185 /* By not making the gentime core emulate periodic mode on top
186 * of oneshot, we get lower overhead and improved accuracy.
187 */
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530188 clk_enable(tcd->clk);
David Brownell4d243f92008-02-22 17:28:37 -0800189
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530190 /* slow clock, count up to RC, then irq and restart */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200191 writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530192 regs + ATMEL_TC_REG(2, CMR));
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200193 writel((32768 + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
David Brownell4d243f92008-02-22 17:28:37 -0800194
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530195 /* Enable clock and interrupts on RC compare */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200196 writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
David Brownell4d243f92008-02-22 17:28:37 -0800197
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530198 /* go go gadget! */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200199 writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG, regs +
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530200 ATMEL_TC_REG(2, CCR));
201 return 0;
David Brownell4d243f92008-02-22 17:28:37 -0800202}
203
204static int tc_next_event(unsigned long delta, struct clock_event_device *d)
205{
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200206 writel_relaxed(delta, tcaddr + ATMEL_TC_REG(2, RC));
David Brownell4d243f92008-02-22 17:28:37 -0800207
208 /* go go gadget! */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200209 writel_relaxed(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG,
David Brownell4d243f92008-02-22 17:28:37 -0800210 tcaddr + ATMEL_TC_REG(2, CCR));
211 return 0;
212}
213
214static struct tc_clkevt_device clkevt = {
215 .clkevt = {
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530216 .name = "tc_clkevt",
217 .features = CLOCK_EVT_FEAT_PERIODIC |
218 CLOCK_EVT_FEAT_ONESHOT,
David Brownell4d243f92008-02-22 17:28:37 -0800219 /* Should be lower than at91rm9200's system timer */
Viresh Kumarcf4541c2015-06-18 16:24:38 +0530220 .rating = 125,
221 .set_next_event = tc_next_event,
222 .set_state_shutdown = tc_shutdown,
223 .set_state_periodic = tc_set_periodic,
224 .set_state_oneshot = tc_set_oneshot,
David Brownell4d243f92008-02-22 17:28:37 -0800225 },
226};
227
228static irqreturn_t ch2_irq(int irq, void *handle)
229{
230 struct tc_clkevt_device *dev = handle;
231 unsigned int sr;
232
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200233 sr = readl_relaxed(dev->regs + ATMEL_TC_REG(2, SR));
David Brownell4d243f92008-02-22 17:28:37 -0800234 if (sr & ATMEL_TC_CPCS) {
235 dev->clkevt.event_handler(&dev->clkevt);
236 return IRQ_HANDLED;
237 }
238
239 return IRQ_NONE;
240}
241
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200242static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
David Brownell4d243f92008-02-22 17:28:37 -0800243{
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200244 int ret;
David Brownell4d243f92008-02-22 17:28:37 -0800245 struct clk *t2_clk = tc->clk[2];
246 int irq = tc->irq[2];
247
Boris Brezillon7d8d05d2015-08-16 11:23:46 +0200248 ret = clk_prepare_enable(tc->slow_clk);
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200249 if (ret)
250 return ret;
Boris Brezillon7d8d05d2015-08-16 11:23:46 +0200251
252 /* try to enable t2 clk to avoid future errors in mode change */
253 ret = clk_prepare_enable(t2_clk);
254 if (ret) {
255 clk_disable_unprepare(tc->slow_clk);
256 return ret;
257 }
258
David Janderacbf6d22014-05-08 12:06:25 +0200259 clk_disable(t2_clk);
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200260
David Brownell4d243f92008-02-22 17:28:37 -0800261 clkevt.regs = tc->regs;
262 clkevt.clk = t2_clk;
David Brownell4d243f92008-02-22 17:28:37 -0800263
264 timer_clock = clk32k_divisor_idx;
265
Rusty Russell320ab2b2008-12-13 21:20:26 +1030266 clkevt.clkevt.cpumask = cpumask_of(0);
David Brownell4d243f92008-02-22 17:28:37 -0800267
Gaƫl PORTAYd07a1ec2014-09-06 19:52:37 +0200268 ret = request_irq(irq, ch2_irq, IRQF_TIMER, "tc_clkevt", &clkevt);
269 if (ret) {
Boris Brezilloneed9fb92015-08-16 11:23:45 +0200270 clk_unprepare(t2_clk);
Boris Brezillon7d8d05d2015-08-16 11:23:46 +0200271 clk_disable_unprepare(tc->slow_clk);
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200272 return ret;
Gaƫl PORTAYd07a1ec2014-09-06 19:52:37 +0200273 }
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200274
Shawn Guo77cc9822013-01-12 11:50:06 +0000275 clockevents_config_and_register(&clkevt.clkevt, 32768, 1, 0xffff);
Voss, Nikolaus1817dc02011-01-25 15:07:29 -0800276
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200277 return ret;
David Brownell4d243f92008-02-22 17:28:37 -0800278}
279
280#else /* !CONFIG_GENERIC_CLOCKEVENTS */
281
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200282static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
David Brownell4d243f92008-02-22 17:28:37 -0800283{
284 /* NOTHING */
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200285 return 0;
David Brownell4d243f92008-02-22 17:28:37 -0800286}
287
288#endif
289
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100290static void __init tcb_setup_dual_chan(struct atmel_tc *tc, int mck_divisor_idx)
291{
292 /* channel 0: waveform mode, input mclk/8, clock TIOA0 on overflow */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200293 writel(mck_divisor_idx /* likely divide-by-8 */
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100294 | ATMEL_TC_WAVE
295 | ATMEL_TC_WAVESEL_UP /* free-run */
296 | ATMEL_TC_ACPA_SET /* TIOA0 rises at 0 */
297 | ATMEL_TC_ACPC_CLEAR, /* (duty cycle 50%) */
298 tcaddr + ATMEL_TC_REG(0, CMR));
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200299 writel(0x0000, tcaddr + ATMEL_TC_REG(0, RA));
300 writel(0x8000, tcaddr + ATMEL_TC_REG(0, RC));
301 writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */
302 writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR));
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100303
304 /* channel 1: waveform mode, input TIOA0 */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200305 writel(ATMEL_TC_XC1 /* input: TIOA0 */
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100306 | ATMEL_TC_WAVE
307 | ATMEL_TC_WAVESEL_UP, /* free-run */
308 tcaddr + ATMEL_TC_REG(1, CMR));
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200309 writel(0xff, tcaddr + ATMEL_TC_REG(1, IDR)); /* no irqs */
310 writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(1, CCR));
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100311
312 /* chain channel 0 to channel 1*/
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200313 writel(ATMEL_TC_TC1XC1S_TIOA0, tcaddr + ATMEL_TC_BMR);
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100314 /* then reset all the timers */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200315 writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR);
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100316}
317
318static void __init tcb_setup_single_chan(struct atmel_tc *tc, int mck_divisor_idx)
319{
320 /* channel 0: waveform mode, input mclk/8 */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200321 writel(mck_divisor_idx /* likely divide-by-8 */
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100322 | ATMEL_TC_WAVE
323 | ATMEL_TC_WAVESEL_UP, /* free-run */
324 tcaddr + ATMEL_TC_REG(0, CMR));
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200325 writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */
326 writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR));
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100327
328 /* then reset all the timers */
Alexandre Belloni6ec8be22017-06-23 17:03:31 +0200329 writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR);
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100330}
331
David Brownell4d243f92008-02-22 17:28:37 -0800332static int __init tcb_clksrc_init(void)
333{
334 static char bootinfo[] __initdata
335 = KERN_DEBUG "%s: tc%d at %d.%03d MHz\n";
336
337 struct platform_device *pdev;
338 struct atmel_tc *tc;
David Brownell3ee08ae2008-03-13 09:44:48 -0800339 struct clk *t0_clk;
David Brownell4d243f92008-02-22 17:28:37 -0800340 u32 rate, divided_rate = 0;
341 int best_divisor_idx = -1;
342 int clk32k_divisor_idx = -1;
343 int i;
Boris BREZILLON0e746ec2013-10-02 14:35:20 +0200344 int ret;
David Brownell4d243f92008-02-22 17:28:37 -0800345
Gaƫl PORTAY4930d242014-09-06 19:52:35 +0200346 tc = atmel_tc_alloc(CONFIG_ATMEL_TCB_CLKSRC_BLOCK);
David Brownell4d243f92008-02-22 17:28:37 -0800347 if (!tc) {
348 pr_debug("can't alloc TC for clocksource\n");
349 return -ENODEV;
350 }
351 tcaddr = tc->regs;
352 pdev = tc->pdev;
353
354 t0_clk = tc->clk[0];
Boris BREZILLON0e746ec2013-10-02 14:35:20 +0200355 ret = clk_prepare_enable(t0_clk);
356 if (ret) {
357 pr_debug("can't enable T0 clk\n");
358 goto err_free_tc;
359 }
David Brownell4d243f92008-02-22 17:28:37 -0800360
361 /* How fast will we be counting? Pick something over 5 MHz. */
362 rate = (u32) clk_get_rate(t0_clk);
363 for (i = 0; i < 5; i++) {
364 unsigned divisor = atmel_tc_divisors[i];
365 unsigned tmp;
366
367 /* remember 32 KiHz clock for later */
368 if (!divisor) {
369 clk32k_divisor_idx = i;
370 continue;
371 }
372
373 tmp = rate / divisor;
374 pr_debug("TC: %u / %-3u [%d] --> %u\n", rate, divisor, i, tmp);
375 if (best_divisor_idx > 0) {
376 if (tmp < 5 * 1000 * 1000)
377 continue;
378 }
379 divided_rate = tmp;
380 best_divisor_idx = i;
381 }
382
David Brownell4d243f92008-02-22 17:28:37 -0800383
384 printk(bootinfo, clksrc.name, CONFIG_ATMEL_TCB_CLKSRC_BLOCK,
385 divided_rate / 1000000,
386 ((divided_rate + 500000) % 1000000) / 1000);
387
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100388 if (tc->tcb_config && tc->tcb_config->counter_width == 32) {
389 /* use apropriate function to read 32 bit counter */
390 clksrc.read = tc_get_cycles32;
391 /* setup ony channel 0 */
392 tcb_setup_single_chan(tc, best_divisor_idx);
393 } else {
394 /* tclib will give us three clocks no matter what the
395 * underlying platform supports.
396 */
Boris BREZILLON0e746ec2013-10-02 14:35:20 +0200397 ret = clk_prepare_enable(tc->clk[1]);
398 if (ret) {
399 pr_debug("can't enable T1 clk\n");
400 goto err_disable_t0;
401 }
Nicolas Ferre8e315a72012-01-19 18:44:49 +0100402 /* setup both channel 0 & 1 */
403 tcb_setup_dual_chan(tc, best_divisor_idx);
404 }
David Brownell4d243f92008-02-22 17:28:37 -0800405
406 /* and away we go! */
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200407 ret = clocksource_register_hz(&clksrc, divided_rate);
408 if (ret)
409 goto err_disable_t1;
David Brownell4d243f92008-02-22 17:28:37 -0800410
411 /* channel 2: periodic and oneshot timer support */
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200412 ret = setup_clkevents(tc, clk32k_divisor_idx);
413 if (ret)
414 goto err_unregister_clksrc;
David Brownell4d243f92008-02-22 17:28:37 -0800415
416 return 0;
Boris BREZILLON0e746ec2013-10-02 14:35:20 +0200417
Boris BREZILLON5b3c11d2013-10-02 14:35:41 +0200418err_unregister_clksrc:
419 clocksource_unregister(&clksrc);
420
421err_disable_t1:
422 if (!tc->tcb_config || tc->tcb_config->counter_width != 32)
423 clk_disable_unprepare(tc->clk[1]);
424
Boris BREZILLON0e746ec2013-10-02 14:35:20 +0200425err_disable_t0:
426 clk_disable_unprepare(t0_clk);
427
428err_free_tc:
429 atmel_tc_free(tc);
430 return ret;
David Brownell4d243f92008-02-22 17:28:37 -0800431}
432arch_initcall(tcb_clksrc_init);