cns21xx: add support for 3.8
[openwrt/svn-archive/archive.git] / target / linux / cns21xx / patches-3.8 / 004-arm-add-fa-time.patch
1 --- /dev/null
2 +++ b/arch/arm/plat-fa/include/plat/time.h
3 @@ -0,0 +1,20 @@
4 +/*
5 + * Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
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 +
13 +#ifndef _FA_TIME_H
14 +#define _FA_TIME_H
15 +
16 +#define FA_TIMER1 0
17 +#define FA_TIMER2 1
18 +#define FA_TIMER3 2
19 +
20 +int __init fa_timer_init(unsigned int mapbase, unsigned int irq,
21 + unsigned int timer, unsigned int freq);
22 +
23 +#endif /* _FA_TIME_H */
24 --- /dev/null
25 +++ b/arch/arm/plat-fa/time.c
26 @@ -0,0 +1,97 @@
27 +/*
28 + * Copyright (C) 2001-2006 Storlink, Corp.
29 + * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
30 + * Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
31 + *
32 + * This program is free software; you can redistribute it and/or modify
33 + * it under the terms of the GNU General Public License as published by
34 + * the Free Software Foundation; either version 2 of the License, or
35 + * (at your option) any later version.
36 + */
37 +
38 +#include <linux/init.h>
39 +#include <linux/interrupt.h>
40 +#include <linux/irq.h>
41 +#include <linux/io.h>
42 +
43 +#include <asm/mach/time.h>
44 +#include <plat/time.h>
45 +
46 +/*
47 + * Register definitions for the timers
48 + */
49 +#define TIMER_COUNT(_base, _tmr) ((_base) + 0x00 + (_tmr) * 0x10)
50 +#define TIMER_LOAD(_base, _tmr) ((_base) + 0x04 + (_tmr) * 0x10)
51 +#define TIMER_MATCH1(_base, _tmr) ((_base) + 0x08 + (_tmr) * 0x10)
52 +#define TIMER_MATCH2(_base, _tmr) ((_base) + 0x0c + (_tmr) * 0x10)
53 +
54 +#define TIMER_CR(_base) ((_base) + 0x30)
55 +#define TIMER_STATUS(_base) ((_base) + 0x34)
56 +#define TIMER_MASK(_base) ((_base) + 0x38)
57 +
58 +#define TIMER_SIZE 0x3c
59 +
60 +#define TIMER_CR_ENABLE(x) (1 << ((x) * 3))
61 +#define TIMER_CR_CLOCK(x) (1 << ((x) * 3 + 1))
62 +#define TIMER_CR_INT(x) (1 << ((x) * 3 + 2))
63 +#define TIMER_CR_DOWN(x) (1 << ((x) * 3 + 9))
64 +
65 +#define TIMER_MASK_MATCH1(x) (1 << ((x) * 3))
66 +#define TIMER_MASK_MATCH2(x) (1 << ((x) * 3 + 1))
67 +#define TIMER_MASK_OF(x) (1 << ((x) * 3 + 2))
68 +
69 +#define TIMER_MASK_ALL 0x7ff
70 +
71 +/*
72 + * IRQ handler for the timer
73 + */
74 +static irqreturn_t fa_timer_interrupt(int irq, void *dev_id)
75 +{
76 + timer_tick();
77 + return IRQ_HANDLED;
78 +}
79 +
80 +static struct irqaction fa_timer_irq = {
81 + .name = "Timer Tick",
82 + .flags = IRQF_DISABLED | IRQF_TIMER,
83 + .handler = fa_timer_interrupt,
84 +};
85 +
86 +int __init fa_timer_init(unsigned int mapbase, unsigned int irq,
87 + unsigned int timer, unsigned int freq)
88 +{
89 + void __iomem *base;
90 +
91 + base = ioremap(mapbase, TIMER_SIZE);
92 + if (!base)
93 + return -ENOMEM;
94 +
95 + /* disable timers, clear status and mask all interrupts */
96 + __raw_writel(0, TIMER_CR(base));
97 + __raw_writel(0, TIMER_STATUS(base));
98 + __raw_writel(TIMER_MASK_ALL, TIMER_MASK(base));
99 +
100 + /*
101 + * Make irqs happen for the system timer
102 + */
103 + setup_irq(irq, &fa_timer_irq);
104 +
105 + /* Setup the timer */
106 + __raw_writel(freq / HZ, TIMER_COUNT(base, timer));
107 + __raw_writel(freq / HZ, TIMER_LOAD(base, timer));
108 + __raw_writel(0, TIMER_MATCH1(base, timer));
109 + __raw_writel(0, TIMER_MATCH2(base, timer));
110 +
111 + /* Enable interrupt and start the timer */
112 + __raw_writel(TIMER_MASK_ALL & ~TIMER_MASK_OF(timer),
113 + TIMER_MASK(base));
114 +
115 + __raw_writel(TIMER_CR_ENABLE(timer) |
116 + TIMER_CR_INT(timer) |
117 + TIMER_CR_DOWN(timer),
118 + TIMER_CR(base));
119 +
120 + iounmap(base);
121 +
122 + return 0;
123 +}
124 --- a/arch/arm/plat-fa/Kconfig
125 +++ b/arch/arm/plat-fa/Kconfig
126 @@ -1,3 +1,6 @@
127 if PLAT_FA
128
129 +config PLAT_FA_TIME
130 + def_bool n
131 +
132 endif
133 --- a/arch/arm/plat-fa/Makefile
134 +++ b/arch/arm/plat-fa/Makefile
135 @@ -4,6 +4,8 @@
136
137 obj-y :=
138
139 +obj-$(CONFIG_PLAT_FA_TIME) += time.o
140 +
141 obj-m :=
142 obj-n :=
143 obj- :=