]> Pileus Git - ~andy/linux/blob - arch/mips/bcm63xx/reset.c
Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus
[~andy/linux] / arch / mips / bcm63xx / reset.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
7  */
8
9 #include <linux/module.h>
10 #include <linux/mutex.h>
11 #include <linux/err.h>
12 #include <linux/clk.h>
13 #include <linux/delay.h>
14 #include <bcm63xx_cpu.h>
15 #include <bcm63xx_io.h>
16 #include <bcm63xx_regs.h>
17 #include <bcm63xx_reset.h>
18
19 #define __GEN_RESET_BITS_TABLE(__cpu)                                   \
20         [BCM63XX_RESET_SPI]             = BCM## __cpu ##_RESET_SPI,     \
21         [BCM63XX_RESET_ENET]            = BCM## __cpu ##_RESET_ENET,    \
22         [BCM63XX_RESET_USBH]            = BCM## __cpu ##_RESET_USBH,    \
23         [BCM63XX_RESET_USBD]            = BCM## __cpu ##_RESET_USBD,    \
24         [BCM63XX_RESET_DSL]             = BCM## __cpu ##_RESET_DSL,     \
25         [BCM63XX_RESET_SAR]             = BCM## __cpu ##_RESET_SAR,     \
26         [BCM63XX_RESET_EPHY]            = BCM## __cpu ##_RESET_EPHY,    \
27         [BCM63XX_RESET_ENETSW]          = BCM## __cpu ##_RESET_ENETSW,  \
28         [BCM63XX_RESET_PCM]             = BCM## __cpu ##_RESET_PCM,     \
29         [BCM63XX_RESET_MPI]             = BCM## __cpu ##_RESET_MPI,     \
30         [BCM63XX_RESET_PCIE]            = BCM## __cpu ##_RESET_PCIE,    \
31         [BCM63XX_RESET_PCIE_EXT]        = BCM## __cpu ##_RESET_PCIE_EXT,
32
33 #define BCM6328_RESET_SPI       SOFTRESET_6328_SPI_MASK
34 #define BCM6328_RESET_ENET      0
35 #define BCM6328_RESET_USBH      SOFTRESET_6328_USBH_MASK
36 #define BCM6328_RESET_USBD      SOFTRESET_6328_USBS_MASK
37 #define BCM6328_RESET_DSL       0
38 #define BCM6328_RESET_SAR       SOFTRESET_6328_SAR_MASK
39 #define BCM6328_RESET_EPHY      SOFTRESET_6328_EPHY_MASK
40 #define BCM6328_RESET_ENETSW    SOFTRESET_6328_ENETSW_MASK
41 #define BCM6328_RESET_PCM       SOFTRESET_6328_PCM_MASK
42 #define BCM6328_RESET_MPI       0
43 #define BCM6328_RESET_PCIE      \
44                                 (SOFTRESET_6328_PCIE_MASK |             \
45                                  SOFTRESET_6328_PCIE_CORE_MASK |        \
46                                  SOFTRESET_6328_PCIE_HARD_MASK)
47 #define BCM6328_RESET_PCIE_EXT  SOFTRESET_6328_PCIE_EXT_MASK
48
49 #define BCM6338_RESET_SPI       SOFTRESET_6338_SPI_MASK
50 #define BCM6338_RESET_ENET      SOFTRESET_6338_ENET_MASK
51 #define BCM6338_RESET_USBH      SOFTRESET_6338_USBH_MASK
52 #define BCM6338_RESET_USBD      SOFTRESET_6338_USBS_MASK
53 #define BCM6338_RESET_DSL       SOFTRESET_6338_ADSL_MASK
54 #define BCM6338_RESET_SAR       SOFTRESET_6338_SAR_MASK
55 #define BCM6338_RESET_EPHY      0
56 #define BCM6338_RESET_ENETSW    0
57 #define BCM6338_RESET_PCM       0
58 #define BCM6338_RESET_MPI       0
59 #define BCM6338_RESET_PCIE      0
60 #define BCM6338_RESET_PCIE_EXT  0
61
62 #define BCM6348_RESET_SPI       SOFTRESET_6348_SPI_MASK
63 #define BCM6348_RESET_ENET      SOFTRESET_6348_ENET_MASK
64 #define BCM6348_RESET_USBH      SOFTRESET_6348_USBH_MASK
65 #define BCM6348_RESET_USBD      SOFTRESET_6348_USBS_MASK
66 #define BCM6348_RESET_DSL       SOFTRESET_6348_ADSL_MASK
67 #define BCM6348_RESET_SAR       SOFTRESET_6348_SAR_MASK
68 #define BCM6348_RESET_EPHY      0
69 #define BCM6348_RESET_ENETSW    0
70 #define BCM6348_RESET_PCM       0
71 #define BCM6348_RESET_MPI       0
72 #define BCM6348_RESET_PCIE      0
73 #define BCM6348_RESET_PCIE_EXT  0
74
75 #define BCM6358_RESET_SPI       SOFTRESET_6358_SPI_MASK
76 #define BCM6358_RESET_ENET      SOFTRESET_6358_ENET_MASK
77 #define BCM6358_RESET_USBH      SOFTRESET_6358_USBH_MASK
78 #define BCM6358_RESET_USBD      0
79 #define BCM6358_RESET_DSL       SOFTRESET_6358_ADSL_MASK
80 #define BCM6358_RESET_SAR       SOFTRESET_6358_SAR_MASK
81 #define BCM6358_RESET_EPHY      SOFTRESET_6358_EPHY_MASK
82 #define BCM6358_RESET_ENETSW    0
83 #define BCM6358_RESET_PCM       SOFTRESET_6358_PCM_MASK
84 #define BCM6358_RESET_MPI       SOFTRESET_6358_MPI_MASK
85 #define BCM6358_RESET_PCIE      0
86 #define BCM6358_RESET_PCIE_EXT  0
87
88 #define BCM6362_RESET_SPI       SOFTRESET_6362_SPI_MASK
89 #define BCM6362_RESET_ENET      0
90 #define BCM6362_RESET_USBH      SOFTRESET_6362_USBH_MASK
91 #define BCM6362_RESET_USBD      SOFTRESET_6362_USBS_MASK
92 #define BCM6362_RESET_DSL       0
93 #define BCM6362_RESET_SAR       SOFTRESET_6362_SAR_MASK
94 #define BCM6362_RESET_EPHY      SOFTRESET_6362_EPHY_MASK
95 #define BCM6362_RESET_ENETSW    SOFTRESET_6362_ENETSW_MASK
96 #define BCM6362_RESET_PCM       SOFTRESET_6362_PCM_MASK
97 #define BCM6362_RESET_MPI       0
98 #define BCM6362_RESET_PCIE      (SOFTRESET_6362_PCIE_MASK | \
99                                  SOFTRESET_6362_PCIE_CORE_MASK)
100 #define BCM6362_RESET_PCIE_EXT  SOFTRESET_6362_PCIE_EXT_MASK
101
102 #define BCM6368_RESET_SPI       SOFTRESET_6368_SPI_MASK
103 #define BCM6368_RESET_ENET      0
104 #define BCM6368_RESET_USBH      SOFTRESET_6368_USBH_MASK
105 #define BCM6368_RESET_USBD      SOFTRESET_6368_USBS_MASK
106 #define BCM6368_RESET_DSL       0
107 #define BCM6368_RESET_SAR       SOFTRESET_6368_SAR_MASK
108 #define BCM6368_RESET_EPHY      SOFTRESET_6368_EPHY_MASK
109 #define BCM6368_RESET_ENETSW    0
110 #define BCM6368_RESET_PCM       SOFTRESET_6368_PCM_MASK
111 #define BCM6368_RESET_MPI       SOFTRESET_6368_MPI_MASK
112 #define BCM6368_RESET_PCIE      0
113 #define BCM6368_RESET_PCIE_EXT  0
114
115 #ifdef BCMCPU_RUNTIME_DETECT
116
117 /*
118  * core reset bits
119  */
120 static const u32 bcm6328_reset_bits[] = {
121         __GEN_RESET_BITS_TABLE(6328)
122 };
123
124 static const u32 bcm6338_reset_bits[] = {
125         __GEN_RESET_BITS_TABLE(6338)
126 };
127
128 static const u32 bcm6348_reset_bits[] = {
129         __GEN_RESET_BITS_TABLE(6348)
130 };
131
132 static const u32 bcm6358_reset_bits[] = {
133         __GEN_RESET_BITS_TABLE(6358)
134 };
135
136 static const u32 bcm6362_reset_bits[] = {
137         __GEN_RESET_BITS_TABLE(6362)
138 };
139
140 static const u32 bcm6368_reset_bits[] = {
141         __GEN_RESET_BITS_TABLE(6368)
142 };
143
144 const u32 *bcm63xx_reset_bits;
145 static int reset_reg;
146
147 static int __init bcm63xx_reset_bits_init(void)
148 {
149         if (BCMCPU_IS_6328()) {
150                 reset_reg = PERF_SOFTRESET_6328_REG;
151                 bcm63xx_reset_bits = bcm6328_reset_bits;
152         } else if (BCMCPU_IS_6338()) {
153                 reset_reg = PERF_SOFTRESET_REG;
154                 bcm63xx_reset_bits = bcm6338_reset_bits;
155         } else if (BCMCPU_IS_6348()) {
156                 reset_reg = PERF_SOFTRESET_REG;
157                 bcm63xx_reset_bits = bcm6348_reset_bits;
158         } else if (BCMCPU_IS_6358()) {
159                 reset_reg = PERF_SOFTRESET_6358_REG;
160                 bcm63xx_reset_bits = bcm6358_reset_bits;
161         } else if (BCMCPU_IS_6362()) {
162                 reset_reg = PERF_SOFTRESET_6362_REG;
163                 bcm63xx_reset_bits = bcm6362_reset_bits;
164         } else if (BCMCPU_IS_6368()) {
165                 reset_reg = PERF_SOFTRESET_6368_REG;
166                 bcm63xx_reset_bits = bcm6368_reset_bits;
167         }
168
169         return 0;
170 }
171 #else
172
173 #ifdef CONFIG_BCM63XX_CPU_6328
174 static const u32 bcm63xx_reset_bits[] = {
175         __GEN_RESET_BITS_TABLE(6328)
176 };
177 #define reset_reg PERF_SOFTRESET_6328_REG
178 #endif
179
180 #ifdef CONFIG_BCM63XX_CPU_6338
181 static const u32 bcm63xx_reset_bits[] = {
182         __GEN_RESET_BITS_TABLE(6338)
183 };
184 #define reset_reg PERF_SOFTRESET_REG
185 #endif
186
187 #ifdef CONFIG_BCM63XX_CPU_6345
188 static const u32 bcm63xx_reset_bits[] = { };
189 #define reset_reg 0
190 #endif
191
192 #ifdef CONFIG_BCM63XX_CPU_6348
193 static const u32 bcm63xx_reset_bits[] = {
194         __GEN_RESET_BITS_TABLE(6348)
195 };
196 #define reset_reg PERF_SOFTRESET_REG
197 #endif
198
199 #ifdef CONFIG_BCM63XX_CPU_6358
200 static const u32 bcm63xx_reset_bits[] = {
201         __GEN_RESET_BITS_TABLE(6358)
202 };
203 #define reset_reg PERF_SOFTRESET_6358_REG
204 #endif
205
206 #ifdef CONFIG_BCM63XX_CPU_6362
207 static const u32 bcm63xx_reset_bits[] = {
208         __GEN_RESET_BITS_TABLE(6362)
209 };
210 #define reset_reg PERF_SOFTRESET_6362_REG
211 #endif
212
213 #ifdef CONFIG_BCM63XX_CPU_6368
214 static const u32 bcm63xx_reset_bits[] = {
215         __GEN_RESET_BITS_TABLE(6368)
216 };
217 #define reset_reg PERF_SOFTRESET_6368_REG
218 #endif
219
220 static int __init bcm63xx_reset_bits_init(void) { return 0; }
221 #endif
222
223 static DEFINE_SPINLOCK(reset_mutex);
224
225 static void __bcm63xx_core_set_reset(u32 mask, int enable)
226 {
227         unsigned long flags;
228         u32 val;
229
230         if (!mask)
231                 return;
232
233         spin_lock_irqsave(&reset_mutex, flags);
234         val = bcm_perf_readl(reset_reg);
235
236         if (enable)
237                 val &= ~mask;
238         else
239                 val |= mask;
240
241         bcm_perf_writel(val, reset_reg);
242         spin_unlock_irqrestore(&reset_mutex, flags);
243 }
244
245 void bcm63xx_core_set_reset(enum bcm63xx_core_reset core, int reset)
246 {
247         __bcm63xx_core_set_reset(bcm63xx_reset_bits[core], reset);
248 }
249 EXPORT_SYMBOL(bcm63xx_core_set_reset);
250
251 postcore_initcall(bcm63xx_reset_bits_init);