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