ar71xx: add support for ar7241 and ar7242
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / ar71xx.c
1 /*
2 * AR71xx SoC routines
3 *
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/mutex.h>
16
17 #include <asm/mach-ar71xx/ar71xx.h>
18
19 static DEFINE_MUTEX(ar71xx_flash_mutex);
20
21 void __iomem *ar71xx_ddr_base;
22 EXPORT_SYMBOL_GPL(ar71xx_ddr_base);
23
24 void __iomem *ar71xx_pll_base;
25 EXPORT_SYMBOL_GPL(ar71xx_pll_base);
26
27 void __iomem *ar71xx_reset_base;
28 EXPORT_SYMBOL_GPL(ar71xx_reset_base);
29
30 void __iomem *ar71xx_gpio_base;
31 EXPORT_SYMBOL_GPL(ar71xx_gpio_base);
32
33 void __iomem *ar71xx_usb_ctrl_base;
34 EXPORT_SYMBOL_GPL(ar71xx_usb_ctrl_base);
35
36 void ar71xx_device_stop(u32 mask)
37 {
38 unsigned long flags;
39 u32 mask_inv;
40 u32 t;
41
42 switch (ar71xx_soc) {
43 case AR71XX_SOC_AR7130:
44 case AR71XX_SOC_AR7141:
45 case AR71XX_SOC_AR7161:
46 local_irq_save(flags);
47 t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
48 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t | mask);
49 local_irq_restore(flags);
50 break;
51
52 case AR71XX_SOC_AR7240:
53 case AR71XX_SOC_AR7241:
54 case AR71XX_SOC_AR7242:
55 mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
56 local_irq_save(flags);
57 t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
58 t |= mask;
59 t &= ~mask_inv;
60 ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
61 local_irq_restore(flags);
62 break;
63
64 case AR71XX_SOC_AR9130:
65 case AR71XX_SOC_AR9132:
66 local_irq_save(flags);
67 t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
68 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t | mask);
69 local_irq_restore(flags);
70 break;
71
72 default:
73 BUG();
74 }
75 }
76 EXPORT_SYMBOL_GPL(ar71xx_device_stop);
77
78 void ar71xx_device_start(u32 mask)
79 {
80 unsigned long flags;
81 u32 mask_inv;
82 u32 t;
83
84 switch (ar71xx_soc) {
85 case AR71XX_SOC_AR7130:
86 case AR71XX_SOC_AR7141:
87 case AR71XX_SOC_AR7161:
88 local_irq_save(flags);
89 t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
90 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t & ~mask);
91 local_irq_restore(flags);
92 break;
93
94 case AR71XX_SOC_AR7240:
95 case AR71XX_SOC_AR7241:
96 case AR71XX_SOC_AR7242:
97 mask_inv = mask & RESET_MODULE_USB_OHCI_DLL_7240;
98 local_irq_save(flags);
99 t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
100 t &= ~mask;
101 t |= mask_inv;
102 ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE, t);
103 local_irq_restore(flags);
104 break;
105
106 case AR71XX_SOC_AR9130:
107 case AR71XX_SOC_AR9132:
108 local_irq_save(flags);
109 t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
110 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t & ~mask);
111 local_irq_restore(flags);
112 break;
113
114 default:
115 BUG();
116 }
117 }
118 EXPORT_SYMBOL_GPL(ar71xx_device_start);
119
120 int ar71xx_device_stopped(u32 mask)
121 {
122 unsigned long flags;
123 u32 t;
124
125 switch (ar71xx_soc) {
126 case AR71XX_SOC_AR7130:
127 case AR71XX_SOC_AR7141:
128 case AR71XX_SOC_AR7161:
129 local_irq_save(flags);
130 t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
131 local_irq_restore(flags);
132 break;
133
134 case AR71XX_SOC_AR7240:
135 case AR71XX_SOC_AR7241:
136 case AR71XX_SOC_AR7242:
137 local_irq_save(flags);
138 t = ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE);
139 local_irq_restore(flags);
140 break;
141
142 case AR71XX_SOC_AR9130:
143 case AR71XX_SOC_AR9132:
144 local_irq_save(flags);
145 t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
146 local_irq_restore(flags);
147 break;
148
149 default:
150 BUG();
151 }
152
153 return ((t & mask) == mask);
154 }
155 EXPORT_SYMBOL_GPL(ar71xx_device_stopped);
156
157 void ar71xx_ddr_flush(u32 reg)
158 {
159 ar71xx_ddr_wr(reg, 1);
160 while ((ar71xx_ddr_rr(reg) & 0x1));
161
162 ar71xx_ddr_wr(reg, 1);
163 while ((ar71xx_ddr_rr(reg) & 0x1));
164 }
165 EXPORT_SYMBOL_GPL(ar71xx_ddr_flush);
166
167 void ar71xx_flash_acquire(void)
168 {
169 mutex_lock(&ar71xx_flash_mutex);
170 }
171 EXPORT_SYMBOL_GPL(ar71xx_flash_acquire);
172
173 void ar71xx_flash_release(void)
174 {
175 mutex_unlock(&ar71xx_flash_mutex);
176 }
177 EXPORT_SYMBOL_GPL(ar71xx_flash_release);