ar7100.c revision 1.2.12.1 1 1.1 matt /*-
2 1.1 matt * Copyright (c) 2011 The NetBSD Foundation, Inc.
3 1.1 matt * All rights reserved.
4 1.1 matt *
5 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
6 1.1 matt * by Matt Thomas of 3am Software Foundry.
7 1.1 matt *
8 1.1 matt * Redistribution and use in source and binary forms, with or without
9 1.1 matt * modification, are permitted provided that the following conditions
10 1.1 matt * are met:
11 1.1 matt * 1. Redistributions of source code must retain the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer.
13 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer in the
15 1.1 matt * documentation and/or other materials provided with the distribution.
16 1.1 matt *
17 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
28 1.1 matt */
29 1.1 matt
30 1.1 matt #include <sys/cdefs.h>
31 1.1 matt
32 1.2.12.1 jdolecek __KERNEL_RCSID(0, "$NetBSD: ar7100.c,v 1.2.12.1 2017/12/03 11:36:26 jdolecek Exp $");
33 1.1 matt
34 1.1 matt #define __INTR_PRIVATE
35 1.1 matt #include "pci.h"
36 1.2 matt #include "opt_memsize.h"
37 1.1 matt
38 1.1 matt #include <sys/param.h>
39 1.1 matt #include <sys/device.h>
40 1.2.12.1 jdolecek #include <sys/cpu.h>
41 1.1 matt
42 1.1 matt #include <prop/proplib.h>
43 1.1 matt
44 1.2.12.1 jdolecek #include <mips/cpuregs.h>
45 1.1 matt #include <mips/atheros/include/platform.h>
46 1.1 matt #include <mips/atheros/include/ar9344reg.h>
47 1.1 matt
48 1.1 matt #define AR7100_BASE_FREQ (40*1000*1000)
49 1.1 matt
50 1.1 matt static const char * const ar7100_cpu_intrnames[] = {
51 1.1 matt [AR7100_CPU_IRQ_PCI] = "irq 0 (pci)",
52 1.1 matt [ARCHIP_CPU_IRQ_USB] = "irq 1 (usb)",
53 1.1 matt [ARCHIP_CPU_IRQ_GMAC0] = "irq 2 (gmac0)",
54 1.1 matt [ARCHIP_CPU_IRQ_GMAC1] = "irq 3 (gmac1)",
55 1.1 matt [ARCHIP_CPU_IRQ_MISC] = "irq 4 (misc)",
56 1.1 matt [ARCHIP_CPU_IRQ_TIMER] = "irq 5 (timer)",
57 1.1 matt };
58 1.1 matt
59 1.1 matt static const char * const ar7100_misc_intrnames[] = {
60 1.1 matt [AR7100_MISC_IRQ_TIMER] = "irq 0 (timer)",
61 1.1 matt [AR7100_MISC_IRQ_ERROR] = "irq 1 (error)",
62 1.1 matt [AR7100_MISC_IRQ_GPIO] = "irq 2 (gpio)",
63 1.1 matt [AR7100_MISC_IRQ_UART0] = "irq 3 (uart)",
64 1.1 matt [AR7100_MISC_IRQ_WDOG] = "irq 4 (wdog)",
65 1.1 matt [AR7100_MISC_IRQ_PC] = "irq 5 (pc)",
66 1.1 matt [AR7100_MISC_IRQ_OHCI] = "irq 6 (ochi)",
67 1.1 matt [AR7100_MISC_IRQ_DMA] = "irq 7 (dma)",
68 1.1 matt };
69 1.1 matt
70 1.1 matt static const struct ipl_sr_map ar7100_ipl_sr_map = {
71 1.1 matt .sr_bits = {
72 1.1 matt [IPL_NONE] = 0,
73 1.1 matt [IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
74 1.1 matt [IPL_SOFTBIO] = MIPS_SOFT_INT_MASK_0,
75 1.1 matt [IPL_SOFTNET] = MIPS_SOFT_INT_MASK,
76 1.1 matt [IPL_SOFTSERIAL] = MIPS_SOFT_INT_MASK,
77 1.1 matt [IPL_BIO] = MIPS_SOFT_INT_MASK |
78 1.1 matt MIPS_INT_MASK_0 | /* PCI */
79 1.1 matt MIPS_INT_MASK_1, /* USB */
80 1.1 matt [IPL_NET] = MIPS_SOFT_INT_MASK |
81 1.1 matt MIPS_INT_MASK_0 | /* PCI */
82 1.1 matt MIPS_INT_MASK_1 | /* USB */
83 1.1 matt MIPS_INT_MASK_2 | /* GMAC0 */
84 1.1 matt MIPS_INT_MASK_3, /* GMAC1 */
85 1.1 matt [IPL_SERIAL] = MIPS_SOFT_INT_MASK |
86 1.1 matt MIPS_INT_MASK_0 | /* PCIE RC */
87 1.1 matt MIPS_INT_MASK_1 | /* USB */
88 1.1 matt MIPS_INT_MASK_2 | /* GMAC0 */
89 1.1 matt MIPS_INT_MASK_3 | /* GMAC1 */
90 1.1 matt MIPS_INT_MASK_4, /* MISC (UART0/1) */
91 1.1 matt
92 1.1 matt [IPL_SCHED] = MIPS_INT_MASK, /* EVERYTHING */
93 1.1 matt [IPL_DDB] = MIPS_INT_MASK, /* EVERYTHING */
94 1.1 matt [IPL_HIGH] = MIPS_INT_MASK, /* EVERYTHING */
95 1.1 matt },
96 1.1 matt };
97 1.1 matt
98 1.1 matt static void
99 1.1 matt ar7100_intr_init(void)
100 1.1 matt {
101 1.1 matt atheros_intr_init();
102 1.1 matt }
103 1.1 matt
104 1.1 matt static uint32_t
105 1.1 matt ar7100_get_memsize(void)
106 1.1 matt {
107 1.2 matt #ifdef MEMSIZE
108 1.2 matt return MEMSIZE;
109 1.2 matt #else
110 1.1 matt return 128*1024*1024;
111 1.2 matt #endif
112 1.1 matt }
113 1.1 matt
114 1.1 matt static void
115 1.1 matt ar7100_wdog_reload(uint32_t period)
116 1.1 matt {
117 1.1 matt
118 1.1 matt if (period == 0) {
119 1.1 matt PUTRESETREG(ARCHIP_RESET_WDOG_CTL, ARCHIP_WDOG_CTL_IGNORE);
120 1.1 matt PUTRESETREG(ARCHIP_RESET_WDOG_TIMER, 0);
121 1.1 matt } else {
122 1.1 matt PUTRESETREG(ARCHIP_RESET_WDOG_TIMER, period);
123 1.1 matt PUTRESETREG(ARCHIP_RESET_WDOG_CTL, ARCHIP_WDOG_CTL_RESET);
124 1.1 matt }
125 1.1 matt }
126 1.1 matt
127 1.1 matt static void
128 1.1 matt ar7100_bus_init(void)
129 1.1 matt {
130 1.1 matt printf("resetctl = %#x\n", GETRESETREG(AR7100_RESET_RESETCTL));
131 1.1 matt #if NPCI > 0 && 0
132 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_0) = 0x10000000;
133 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_1) = 0x11000000;
134 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_2) = 0x12000000;
135 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_3) = 0x13000000;
136 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_4) = 0x14000000;
137 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_5) = 0x15000000;
138 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_6) = 0x16000000;
139 1.1 matt REGVAL(ARCHIP_DDR_BASE + AR7100_PCI_WINDOW_7) = 0x07000000;
140 1.1 matt #endif
141 1.1 matt }
142 1.1 matt
143 1.1 matt static void
144 1.1 matt ar7100_reset(void)
145 1.1 matt {
146 1.1 matt PUTRESETREG(AR7100_RESET_RESETCTL, ARCHIP_RESETCTL_FULL_CHIP_RESET);
147 1.1 matt }
148 1.1 matt
149 1.1 matt static void
150 1.1 matt ar7100_get_freqs(struct arfreqs *freqs)
151 1.1 matt {
152 1.1 matt const uint32_t pll = GETPLLREG(ARCHIP_PLL_CPU_PLL_CONFIG);
153 1.1 matt const uint32_t ref_freq = AR7100_BASE_FREQ;
154 1.1 matt
155 1.1 matt const uint32_t pll_freq =
156 1.1 matt ref_freq * (__SHIFTOUT(pll, AR7100_PLL_PLL_FB) + 1);
157 1.1 matt
158 1.1 matt const uint32_t cpu_freq =
159 1.1 matt pll_freq / (__SHIFTOUT(pll, AR7100_CPU_PLL_CPU_DIV_SEL) + 1);
160 1.1 matt
161 1.1 matt const uint32_t ddr_freq =
162 1.1 matt pll_freq / (__SHIFTOUT(pll, AR7100_CPU_PLL_DDR_DIV_SEL) + 1);
163 1.1 matt
164 1.1 matt const uint32_t bus_freq =
165 1.1 matt cpu_freq / ((__SHIFTOUT(pll, AR7100_CPU_PLL_AHB_DIV) + 1) * 2);
166 1.1 matt
167 1.1 matt freqs->freq_bus = bus_freq;
168 1.1 matt freqs->freq_cpu = cpu_freq;
169 1.1 matt freqs->freq_mem = ddr_freq;
170 1.1 matt freqs->freq_pll = pll_freq;
171 1.1 matt freqs->freq_ref = ref_freq;
172 1.1 matt }
173 1.1 matt
174 1.1 matt static void
175 1.1 matt ar7100_device_register(device_t self, void *aux)
176 1.1 matt {
177 1.1 matt if (device_is_a(self, "com")) {
178 1.1 matt prop_number_t pn =
179 1.1 matt prop_number_create_unsigned_integer(atheros_get_bus_freq());
180 1.1 matt KASSERT(pn != NULL);
181 1.1 matt prop_dictionary_set(device_properties(self), "frequency", pn);
182 1.1 matt prop_object_release(pn);
183 1.1 matt }
184 1.1 matt }
185 1.1 matt
186 1.1 matt static int
187 1.1 matt ar7100_enable_device(const struct atheros_device *adv)
188 1.1 matt {
189 1.1 matt #if 0
190 1.1 matt if (adv->adv_mask && ((adv->adv_mask & info->config) == 0)) {
191 1.1 matt return -1;
192 1.1 matt }
193 1.1 matt #endif
194 1.1 matt if (adv->adv_reset) {
195 1.1 matt /* put device into reset */
196 1.1 matt PUTRESETREG(AR7100_RESET_RESETCTL,
197 1.1 matt GETRESETREG(AR7100_RESET_RESETCTL) | adv->adv_reset);
198 1.1 matt
199 1.1 matt delay(15000); /* XXX: tsleep? */
200 1.1 matt
201 1.1 matt /* take it out of reset */
202 1.1 matt PUTRESETREG(AR7100_RESET_RESETCTL,
203 1.1 matt GETRESETREG(AR7100_RESET_RESETCTL) & ~adv->adv_reset);
204 1.1 matt
205 1.1 matt delay(25);
206 1.1 matt }
207 1.1 matt if (adv->adv_enable) {
208 1.1 matt panic("%s: %s: enable not supported!", __func__, adv->adv_name);
209 1.1 matt #if 0
210 1.1 matt PUTRESETREG(AR7100_RESET_ENABLE,
211 1.1 matt GETRESETREG(AR7100_RESET_ENABLE) | adv->adv_enable);
212 1.1 matt #endif
213 1.1 matt }
214 1.1 matt return 0;
215 1.1 matt }
216 1.1 matt
217 1.1 matt static const struct atheros_device ar7100_devices[] = {
218 1.1 matt {
219 1.1 matt .adv_name = "com",
220 1.1 matt .adv_addr = AR7100_UART_BASE,
221 1.1 matt .adv_size = 0x1000,
222 1.1 matt .adv_cirq = ARCHIP_CPU_IRQ_MISC,
223 1.1 matt .adv_mirq = AR7100_MISC_IRQ_UART0,
224 1.1 matt }, {
225 1.1 matt .adv_name = "arpci",
226 1.1 matt .adv_addr = AR7100_PCI_BASE,
227 1.1 matt .adv_size = 0x2000,
228 1.1 matt .adv_cirq = AR7100_CPU_IRQ_PCI,
229 1.1 matt .adv_mirq = -1,
230 1.1 matt .adv_reset = AR7100_RESETCTL_PCI_CORE_RESET,
231 1.1 matt }, {
232 1.1 matt .adv_name = "ohci",
233 1.1 matt .adv_addr = AR7100_OHCI_BASE,
234 1.1 matt .adv_size = 0x2000,
235 1.1 matt .adv_cirq = ARCHIP_CPU_IRQ_USB,
236 1.1 matt .adv_mirq = -1,
237 1.1 matt }, {
238 1.1 matt .adv_name = "ehci",
239 1.1 matt .adv_addr = AR7100_EHCI_BASE,
240 1.1 matt .adv_size = 0x2000,
241 1.1 matt .adv_cirq = ARCHIP_CPU_IRQ_USB,
242 1.1 matt .adv_mirq = -1,
243 1.1 matt }, {
244 1.1 matt .adv_name = "age",
245 1.1 matt .adv_addr = AR7100_GMAC0_BASE,
246 1.1 matt .adv_size = 0x2000,
247 1.1 matt .adv_cirq = ARCHIP_CPU_IRQ_GMAC0,
248 1.1 matt .adv_mirq = -1,
249 1.1 matt }, {
250 1.1 matt .adv_name = "age",
251 1.1 matt .adv_addr = AR7100_GMAC1_BASE,
252 1.1 matt .adv_size = 0x2000,
253 1.1 matt .adv_cirq = ARCHIP_CPU_IRQ_GMAC1,
254 1.1 matt .adv_mirq = -1,
255 1.1 matt }, {
256 1.1 matt .adv_name = NULL,
257 1.1 matt }
258 1.1 matt };
259 1.1 matt
260 1.1 matt const struct atheros_platformsw ar7100_platformsw = {
261 1.1 matt .apsw_intrsw = &atheros_intrsw,
262 1.1 matt .apsw_intr_init = ar7100_intr_init,
263 1.1 matt .apsw_cpu_intrnames = ar7100_cpu_intrnames,
264 1.1 matt .apsw_misc_intrnames = ar7100_misc_intrnames,
265 1.1 matt .apsw_cpu_nintrs = __arraycount(ar7100_cpu_intrnames),
266 1.1 matt .apsw_misc_nintrs = __arraycount(ar7100_misc_intrnames),
267 1.1 matt .apsw_cpuirq_misc = ARCHIP_CPU_IRQ_MISC,
268 1.1 matt .apsw_ipl_sr_map = &ar7100_ipl_sr_map,
269 1.1 matt
270 1.1 matt .apsw_revision_id_addr = ARCHIP_RESET_BASE + ARCHIP_RESET_REVISION,
271 1.1 matt .apsw_uart0_base = AR7100_UART_BASE,
272 1.1 matt .apsw_misc_intstat = ARCHIP_RESET_BASE + ARCHIP_RESET_MISC_INTSTAT,
273 1.1 matt .apsw_misc_intmask = ARCHIP_RESET_BASE + ARCHIP_RESET_MISC_INTMASK,
274 1.1 matt
275 1.1 matt /*
276 1.1 matt * CPU specific routines.
277 1.1 matt */
278 1.1 matt .apsw_get_memsize = ar7100_get_memsize,
279 1.1 matt .apsw_wdog_reload = ar7100_wdog_reload,
280 1.1 matt .apsw_bus_init = ar7100_bus_init,
281 1.1 matt .apsw_reset = ar7100_reset,
282 1.1 matt
283 1.1 matt .apsw_get_freqs = ar7100_get_freqs,
284 1.1 matt .apsw_device_register = ar7100_device_register,
285 1.1 matt .apsw_enable_device = ar7100_enable_device,
286 1.1 matt .apsw_devices = ar7100_devices,
287 1.1 matt };
288