16 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/list.h>
23 #include <linux/bitops.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
28 #define GTCFR_STP(x) ((x) & 1 ? 1 << 5 : 1 << 1)
29 #define GTCFR_RST(x) ((x) & 1 ? 1 << 4 : 1 << 0)
31 #define GTMDR_ICLK_MASK (3 << 1)
32 #define GTMDR_ICLK_ICAS (0 << 1)
33 #define GTMDR_ICLK_ICLK (1 << 1)
34 #define GTMDR_ICLK_SLGO (2 << 1)
35 #define GTMDR_FRR (1 << 3)
36 #define GTMDR_ORI (1 << 4)
37 #define GTMDR_SPS(x) ((x) << 8)
99 gtm->
timers[
i].requested =
true;
100 spin_unlock_irq(>m->
lock);
105 spin_unlock_irq(>m->
lock);
109 return ERR_PTR(-
EBUSY);
132 spin_lock_irq(>m->
lock);
134 if (gtm->
timers[timer].requested)
141 spin_unlock_irq(>m->
lock);
157 spin_lock_irq(&tmr->
gtm->lock);
159 spin_unlock_irq(&tmr->
gtm->lock);
168 int reference_value,
bool free_run)
170 struct gtm *gtm = tmr->
gtm;
172 unsigned int prescaler;
177 int max_prescaler = 256 * 256 * 16;
181 max_prescaler /= 256;
189 if (prescaler > max_prescaler)
192 if (prescaler > max_prescaler / 16) {
197 if (prescaler <= 256) {
202 sps = prescaler / 256 - 1;
227 spin_unlock_irqrestore(>m->
lock, flags);
251 bit = fls_long(usec);
260 return gtm_set_ref_timer16(tmr, freq, usec, reload);
284 const int freq = 1000000;
293 return gtm_set_ref_timer16(tmr, freq, usec, reload);
306 struct gtm *gtm = tmr->
gtm;
307 int num = tmr - >m->
timers[0];
315 spin_unlock_irqrestore(>m->
lock, flags);
344 timers[0].
gtcfr = ®s->gtcfr1;
345 timers[0].
gtmdr = ®s->gtmdr1;
346 timers[0].
gtcnr = ®s->gtcnr1;
347 timers[0].
gtrfr = ®s->gtrfr1;
348 timers[0].
gtevr = ®s->gtevr1;
350 timers[1].
gtcfr = ®s->gtcfr1;
351 timers[1].
gtmdr = ®s->gtmdr2;
352 timers[1].
gtcnr = ®s->gtcnr2;
353 timers[1].
gtrfr = ®s->gtrfr2;
354 timers[1].
gtevr = ®s->gtevr2;
356 timers[2].
gtcfr = ®s->gtcfr2;
357 timers[2].
gtmdr = ®s->gtmdr3;
358 timers[2].
gtcnr = ®s->gtcnr3;
359 timers[2].
gtrfr = ®s->gtrfr3;
360 timers[2].
gtevr = ®s->gtevr3;
362 timers[3].
gtcfr = ®s->gtcfr2;
363 timers[3].
gtmdr = ®s->gtmdr4;
364 timers[3].
gtcnr = ®s->gtcnr4;
365 timers[3].
gtrfr = ®s->gtrfr4;
366 timers[3].
gtevr = ®s->gtevr4;
370 timers[0].
gtpsr = ®s->gtpsr1;
371 timers[1].
gtpsr = ®s->gtpsr2;
372 timers[2].
gtpsr = ®s->gtpsr3;
373 timers[3].
gtpsr = ®s->gtpsr4;
377 static int __init fsl_gtm_init(
void)
381 for_each_compatible_node(np,
NULL,
"fsl,gtm") {
389 pr_err(
"%s: unable to allocate memory\n",
397 if (!clock || size !=
sizeof(*clock)) {
409 pr_err(
"%s: not enough interrupts specified\n",
419 pr_err(
"%s: unable to iomap registers\n",
424 gtm_set_shortcuts(np, gtm->
timers, gtm->
regs);