bcm53xx_board.c revision 1.17.2.2 1 1.17.2.2 matt /* $NetBSD: bcm53xx_board.c,v 1.17.2.2 2014/02/15 16:18:36 matt Exp $ */
2 1.17.2.2 matt /*-
3 1.17.2.2 matt * Copyright (c) 2012 The NetBSD Foundation, Inc.
4 1.17.2.2 matt * All rights reserved.
5 1.17.2.2 matt *
6 1.17.2.2 matt * This code is derived from software contributed to The NetBSD Foundation
7 1.17.2.2 matt * by Matt Thomas of 3am Software Foundry.
8 1.17.2.2 matt *
9 1.17.2.2 matt * Redistribution and use in source and binary forms, with or without
10 1.17.2.2 matt * modification, are permitted provided that the following conditions
11 1.17.2.2 matt * are met:
12 1.17.2.2 matt * 1. Redistributions of source code must retain the above copyright
13 1.17.2.2 matt * notice, this list of conditions and the following disclaimer.
14 1.17.2.2 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.17.2.2 matt * notice, this list of conditions and the following disclaimer in the
16 1.17.2.2 matt * documentation and/or other materials provided with the distribution.
17 1.17.2.2 matt *
18 1.17.2.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.17.2.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.17.2.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.17.2.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.17.2.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.17.2.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.17.2.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.17.2.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.17.2.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.17.2.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.17.2.2 matt * POSSIBILITY OF SUCH DAMAGE.
29 1.17.2.2 matt */
30 1.17.2.2 matt
31 1.17.2.2 matt #include "opt_broadcom.h"
32 1.17.2.2 matt
33 1.17.2.2 matt #define _ARM32_BUS_DMA_PRIVATE
34 1.17.2.2 matt
35 1.17.2.2 matt #include <sys/cdefs.h>
36 1.17.2.2 matt
37 1.17.2.2 matt __KERNEL_RCSID(1, "$NetBSD: bcm53xx_board.c,v 1.17.2.2 2014/02/15 16:18:36 matt Exp $");
38 1.17.2.2 matt
39 1.17.2.2 matt #include <sys/param.h>
40 1.17.2.2 matt #include <sys/bus.h>
41 1.17.2.2 matt #include <sys/cpu.h>
42 1.17.2.2 matt #include <sys/device.h>
43 1.17.2.2 matt
44 1.17.2.2 matt #include <prop/proplib.h>
45 1.17.2.2 matt
46 1.17.2.2 matt #include <net/if.h>
47 1.17.2.2 matt #include <net/if_ether.h>
48 1.17.2.2 matt
49 1.17.2.2 matt #define CCA_PRIVATE
50 1.17.2.2 matt #define CRU_PRIVATE
51 1.17.2.2 matt #define DDR_PRIVATE
52 1.17.2.2 matt #define DMU_PRIVATE
53 1.17.2.2 matt #define ARMCORE_PRIVATE
54 1.17.2.2 matt #define SRAB_PRIVATE
55 1.17.2.2 matt
56 1.17.2.2 matt #include <arm/cortex/a9tmr_var.h>
57 1.17.2.2 matt #include <arm/cortex/pl310_var.h>
58 1.17.2.2 matt #include <arm/mainbus/mainbus.h>
59 1.17.2.2 matt
60 1.17.2.2 matt #include <arm/broadcom/bcm53xx_reg.h>
61 1.17.2.2 matt #include <arm/broadcom/bcm53xx_var.h>
62 1.17.2.2 matt
63 1.17.2.2 matt bus_space_tag_t bcm53xx_ioreg_bst = &bcmgen_bs_tag;
64 1.17.2.2 matt bus_space_handle_t bcm53xx_ioreg_bsh;
65 1.17.2.2 matt bus_space_tag_t bcm53xx_armcore_bst = &bcmgen_bs_tag;
66 1.17.2.2 matt bus_space_handle_t bcm53xx_armcore_bsh;
67 1.17.2.2 matt
68 1.17.2.2 matt static struct cpu_softc cpu_softc;
69 1.17.2.2 matt
70 1.17.2.2 matt struct arm32_dma_range bcm53xx_dma_ranges[] = {
71 1.17.2.2 matt #ifdef BCM5301X
72 1.17.2.2 matt [0] = {
73 1.17.2.2 matt .dr_sysbase = 0x80000000,
74 1.17.2.2 matt .dr_busbase = 0x80000000,
75 1.17.2.2 matt .dr_len = 0x10000000,
76 1.17.2.2 matt }, [1] = {
77 1.17.2.2 matt .dr_sysbase = 0x90000000,
78 1.17.2.2 matt .dr_busbase = 0x90000000,
79 1.17.2.2 matt },
80 1.17.2.2 matt #elif defined(BCM563XX)
81 1.17.2.2 matt [0] = {
82 1.17.2.2 matt .dr_sysbase = 0x60000000,
83 1.17.2.2 matt .dr_busbase = 0x60000000,
84 1.17.2.2 matt .dr_len = 0x20000000,
85 1.17.2.2 matt }, [1] = {
86 1.17.2.2 matt .dr_sysbase = 0xa0000000,
87 1.17.2.2 matt .dr_busbase = 0xa0000000,
88 1.17.2.2 matt },
89 1.17.2.2 matt #endif
90 1.17.2.2 matt };
91 1.17.2.2 matt
92 1.17.2.2 matt struct arm32_bus_dma_tag bcm53xx_dma_tag = {
93 1.17.2.2 matt ._ranges = bcm53xx_dma_ranges,
94 1.17.2.2 matt ._nranges = __arraycount(bcm53xx_dma_ranges),
95 1.17.2.2 matt _BUS_DMAMAP_FUNCS,
96 1.17.2.2 matt _BUS_DMAMEM_FUNCS,
97 1.17.2.2 matt _BUS_DMATAG_FUNCS,
98 1.17.2.2 matt };
99 1.17.2.2 matt
100 1.17.2.2 matt struct arm32_dma_range bcm53xx_coherent_dma_ranges[] = {
101 1.17.2.2 matt #ifdef BCM5301X
102 1.17.2.2 matt [0] = {
103 1.17.2.2 matt .dr_sysbase = 0x80000000,
104 1.17.2.2 matt .dr_busbase = 0x80000000,
105 1.17.2.2 matt .dr_len = 0x10000000,
106 1.17.2.2 matt .dr_flags = _BUS_DMAMAP_COHERENT,
107 1.17.2.2 matt }, [1] = {
108 1.17.2.2 matt .dr_sysbase = 0x90000000,
109 1.17.2.2 matt .dr_busbase = 0x90000000,
110 1.17.2.2 matt },
111 1.17.2.2 matt #elif defined(BCM563XX)
112 1.17.2.2 matt [0] = {
113 1.17.2.2 matt .dr_sysbase = 0x60000000,
114 1.17.2.2 matt .dr_busbase = 0x60000000,
115 1.17.2.2 matt .dr_len = 0x20000000,
116 1.17.2.2 matt .dr_flags = _BUS_DMAMAP_COHERENT,
117 1.17.2.2 matt }, [1] = {
118 1.17.2.2 matt .dr_sysbase = 0xa0000000,
119 1.17.2.2 matt .dr_busbase = 0xa0000000,
120 1.17.2.2 matt },
121 1.17.2.2 matt #endif
122 1.17.2.2 matt };
123 1.17.2.2 matt
124 1.17.2.2 matt struct arm32_bus_dma_tag bcm53xx_coherent_dma_tag = {
125 1.17.2.2 matt ._ranges = bcm53xx_coherent_dma_ranges,
126 1.17.2.2 matt ._nranges = __arraycount(bcm53xx_coherent_dma_ranges),
127 1.17.2.2 matt _BUS_DMAMAP_FUNCS,
128 1.17.2.2 matt _BUS_DMAMEM_FUNCS,
129 1.17.2.2 matt _BUS_DMATAG_FUNCS,
130 1.17.2.2 matt };
131 1.17.2.2 matt
132 1.17.2.2 matt #ifdef _ARM32_NEED_BUS_DMA_BOUNCE
133 1.17.2.2 matt struct arm32_bus_dma_tag bcm53xx_bounce_dma_tag = {
134 1.17.2.2 matt ._ranges = bcm53xx_coherent_dma_ranges,
135 1.17.2.2 matt ._nranges = 1,
136 1.17.2.2 matt _BUS_DMAMAP_FUNCS,
137 1.17.2.2 matt _BUS_DMAMEM_FUNCS,
138 1.17.2.2 matt _BUS_DMATAG_FUNCS,
139 1.17.2.2 matt };
140 1.17.2.2 matt #endif
141 1.17.2.2 matt
142 1.17.2.2 matt #ifdef BCM53XX_CONSOLE_EARLY
143 1.17.2.2 matt #include <dev/ic/ns16550reg.h>
144 1.17.2.2 matt #include <dev/ic/comreg.h>
145 1.17.2.2 matt #include <dev/cons.h>
146 1.17.2.2 matt
147 1.17.2.2 matt static vaddr_t com_base;
148 1.17.2.2 matt
149 1.17.2.2 matt static inline uint32_t
150 1.17.2.2 matt uart_read(bus_size_t o)
151 1.17.2.2 matt {
152 1.17.2.2 matt return *(volatile uint8_t *)(com_base + o);
153 1.17.2.2 matt }
154 1.17.2.2 matt
155 1.17.2.2 matt static inline void
156 1.17.2.2 matt uart_write(bus_size_t o, uint32_t v)
157 1.17.2.2 matt {
158 1.17.2.2 matt *(volatile uint8_t *)(com_base + o) = v;
159 1.17.2.2 matt }
160 1.17.2.2 matt
161 1.17.2.2 matt static int
162 1.17.2.2 matt bcm53xx_cngetc(dev_t dv)
163 1.17.2.2 matt {
164 1.17.2.2 matt if ((uart_read(com_lsr) & LSR_RXRDY) == 0)
165 1.17.2.2 matt return -1;
166 1.17.2.2 matt
167 1.17.2.2 matt return uart_read(com_data) & 0xff;
168 1.17.2.2 matt }
169 1.17.2.2 matt
170 1.17.2.2 matt static void
171 1.17.2.2 matt bcm53xx_cnputc(dev_t dv, int c)
172 1.17.2.2 matt {
173 1.17.2.2 matt int timo = 150000;
174 1.17.2.2 matt
175 1.17.2.2 matt while ((uart_read(com_lsr) & LSR_TXRDY) == 0 && --timo > 0)
176 1.17.2.2 matt ;
177 1.17.2.2 matt
178 1.17.2.2 matt uart_write(com_data, c);
179 1.17.2.2 matt
180 1.17.2.2 matt timo = 150000;
181 1.17.2.2 matt while ((uart_read(com_lsr) & LSR_TSRE) == 0 && --timo > 0)
182 1.17.2.2 matt ;
183 1.17.2.2 matt }
184 1.17.2.2 matt
185 1.17.2.2 matt static struct consdev bcm53xx_earlycons = {
186 1.17.2.2 matt .cn_putc = bcm53xx_cnputc,
187 1.17.2.2 matt .cn_getc = bcm53xx_cngetc,
188 1.17.2.2 matt .cn_pollc = nullcnpollc,
189 1.17.2.2 matt };
190 1.17.2.2 matt #endif /* BCM53XX_CONSOLE_EARLY */
191 1.17.2.2 matt
192 1.17.2.2 matt psize_t
193 1.17.2.2 matt bcm53xx_memprobe(void)
194 1.17.2.2 matt {
195 1.17.2.2 matt bus_space_tag_t bst = bcm53xx_ioreg_bst;
196 1.17.2.2 matt bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
197 1.17.2.2 matt
198 1.17.2.2 matt /*
199 1.17.2.2 matt * First, let's read the magic DDR registers!
200 1.17.2.2 matt */
201 1.17.2.2 matt const uint32_t v01 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_01);
202 1.17.2.2 matt const uint32_t v82 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_82);
203 1.17.2.2 matt const uint32_t v86 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_86);
204 1.17.2.2 matt const uint32_t v87 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_87);
205 1.17.2.2 matt
206 1.17.2.2 matt /*
207 1.17.2.2 matt * Calculate chip parameters
208 1.17.2.2 matt * */
209 1.17.2.2 matt const u_int rows = __SHIFTOUT(v01, CTL_01_MAX_ROW)
210 1.17.2.2 matt - __SHIFTOUT(v82, CTL_82_ROW_DIFF);
211 1.17.2.2 matt const u_int cols = __SHIFTOUT(v01, CTL_01_MAX_COL)
212 1.17.2.2 matt - __SHIFTOUT(v82, CTL_82_COL_DIFF);
213 1.17.2.2 matt const u_int banks_log2 = 3 - __SHIFTOUT(v82, CTL_82_BANK_DIFF);
214 1.17.2.2 matt
215 1.17.2.2 matt /*
216 1.17.2.2 matt * For each chip select, increase the chip count if if is enabled.
217 1.17.2.2 matt */
218 1.17.2.2 matt const u_int max_chips = __SHIFTOUT(v01, CTL_01_MAX_CHIP_SEL);
219 1.17.2.2 matt u_int cs_map = __SHIFTOUT(v86, CTL_86_CS_MAP);
220 1.17.2.2 matt u_int chips = 0;
221 1.17.2.2 matt
222 1.17.2.2 matt for (u_int i = 0; cs_map != 0 && i < max_chips; i++, cs_map >>= 1) {
223 1.17.2.2 matt chips += (cs_map & 1);
224 1.17.2.2 matt }
225 1.17.2.2 matt
226 1.17.2.2 matt /* get log2(ddr width) */
227 1.17.2.2 matt
228 1.17.2.2 matt const u_int ddr_width_log2 = (v87 & CTL_87_REDUC) ? 1 : 2;
229 1.17.2.2 matt
230 1.17.2.2 matt /*
231 1.17.2.2 matt * Let's add up all the things that contribute to the size of a chip.
232 1.17.2.2 matt */
233 1.17.2.2 matt const u_int chip_size_log2 = cols + rows + banks_log2 + ddr_width_log2;
234 1.17.2.2 matt
235 1.17.2.2 matt /*
236 1.17.2.2 matt * Now our memory size is simply the number of chip shifted by the
237 1.17.2.2 matt * log2(chip_size).
238 1.17.2.2 matt */
239 1.17.2.2 matt return (psize_t) chips << chip_size_log2;
240 1.17.2.2 matt }
241 1.17.2.2 matt
242 1.17.2.2 matt static inline uint32_t
243 1.17.2.2 matt bcm53xx_freq_calc(struct bcm53xx_clock_info *clk,
244 1.17.2.2 matt uint32_t pdiv, uint32_t ndiv_int, uint32_t ndiv_frac)
245 1.17.2.2 matt {
246 1.17.2.2 matt if (ndiv_frac == 0 && pdiv == 1)
247 1.17.2.2 matt return ndiv_int * clk->clk_ref;
248 1.17.2.2 matt
249 1.17.2.2 matt uint64_t freq64 = ((uint64_t)ndiv_int << 30) + ndiv_frac;
250 1.17.2.2 matt freq64 *= clk->clk_ref;
251 1.17.2.2 matt if (pdiv > 1)
252 1.17.2.2 matt freq64 /= pdiv;
253 1.17.2.2 matt return (uint32_t) (freq64 >> 30);
254 1.17.2.2 matt }
255 1.17.2.2 matt
256 1.17.2.2 matt static uint32_t
257 1.17.2.2 matt bcm53xx_value_wrap(uint32_t value, uint32_t mask)
258 1.17.2.2 matt {
259 1.17.2.2 matt /*
260 1.17.2.2 matt * n is n except when n is 0 then n = mask + 1.
261 1.17.2.2 matt */
262 1.17.2.2 matt return ((__SHIFTOUT(value, mask) - 1) & __SHIFTOUT(mask, mask)) + 1;
263 1.17.2.2 matt }
264 1.17.2.2 matt
265 1.17.2.2 matt static void
266 1.17.2.2 matt bcm53xx_genpll_clock_init(struct bcm53xx_clock_info *clk, uint32_t control5,
267 1.17.2.2 matt uint32_t control6, uint32_t control7)
268 1.17.2.2 matt {
269 1.17.2.2 matt const uint32_t pdiv = bcm53xx_value_wrap(control6,
270 1.17.2.2 matt GENPLL_CONTROL6_PDIV);
271 1.17.2.2 matt const uint32_t ndiv_int = bcm53xx_value_wrap(control5,
272 1.17.2.2 matt GENPLL_CONTROL5_NDIV_INT);
273 1.17.2.2 matt const uint32_t ndiv_frac = __SHIFTOUT(control5,
274 1.17.2.2 matt GENPLL_CONTROL5_NDIV_FRAC);
275 1.17.2.2 matt
276 1.17.2.2 matt clk->clk_genpll = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac);
277 1.17.2.2 matt
278 1.17.2.2 matt const uint32_t ch0_mdiv = bcm53xx_value_wrap(control6,
279 1.17.2.2 matt GENPLL_CONTROL6_CH0_MDIV);
280 1.17.2.2 matt const uint32_t ch1_mdiv = bcm53xx_value_wrap(control6,
281 1.17.2.2 matt GENPLL_CONTROL6_CH1_MDIV);
282 1.17.2.2 matt const uint32_t ch2_mdiv = bcm53xx_value_wrap(control6,
283 1.17.2.2 matt GENPLL_CONTROL6_CH2_MDIV);
284 1.17.2.2 matt const uint32_t ch3_mdiv = bcm53xx_value_wrap(control7,
285 1.17.2.2 matt GENPLL_CONTROL7_CH3_MDIV);
286 1.17.2.2 matt
287 1.17.2.2 matt clk->clk_mac = clk->clk_genpll / ch0_mdiv; // GENPLL CH0
288 1.17.2.2 matt clk->clk_robo = clk->clk_genpll / ch1_mdiv; // GENPLL CH1
289 1.17.2.2 matt clk->clk_usb2 = clk->clk_genpll / ch2_mdiv; // GENPLL CH2
290 1.17.2.2 matt clk->clk_iproc = clk->clk_genpll / ch3_mdiv; // GENPLL CH3
291 1.17.2.2 matt }
292 1.17.2.2 matt
293 1.17.2.2 matt static void
294 1.17.2.2 matt bcm53xx_lcpll_clock_init(struct bcm53xx_clock_info *clk, uint32_t control1,
295 1.17.2.2 matt uint32_t control2)
296 1.17.2.2 matt {
297 1.17.2.2 matt const uint32_t pdiv = bcm53xx_value_wrap(control1,
298 1.17.2.2 matt LCPLL_CONTROL1_PDIV);
299 1.17.2.2 matt const uint32_t ndiv_int = bcm53xx_value_wrap(control1,
300 1.17.2.2 matt LCPLL_CONTROL1_NDIV_INT);
301 1.17.2.2 matt const uint32_t ndiv_frac = __SHIFTOUT(control1,
302 1.17.2.2 matt LCPLL_CONTROL1_NDIV_FRAC);
303 1.17.2.2 matt
304 1.17.2.2 matt clk->clk_lcpll = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac);
305 1.17.2.2 matt
306 1.17.2.2 matt const uint32_t ch0_mdiv = bcm53xx_value_wrap(control2,
307 1.17.2.2 matt LCPLL_CONTROL2_CH0_MDIV);
308 1.17.2.2 matt const uint32_t ch1_mdiv = bcm53xx_value_wrap(control2,
309 1.17.2.2 matt LCPLL_CONTROL2_CH1_MDIV);
310 1.17.2.2 matt const uint32_t ch2_mdiv = bcm53xx_value_wrap(control2,
311 1.17.2.2 matt LCPLL_CONTROL2_CH2_MDIV);
312 1.17.2.2 matt const uint32_t ch3_mdiv = bcm53xx_value_wrap(control2,
313 1.17.2.2 matt LCPLL_CONTROL2_CH3_MDIV);
314 1.17.2.2 matt
315 1.17.2.2 matt clk->clk_pcie_ref = clk->clk_lcpll / ch0_mdiv; // LCPLL CH0
316 1.17.2.2 matt clk->clk_sdio = clk->clk_lcpll / ch1_mdiv; // LCPLL CH1
317 1.17.2.2 matt clk->clk_ddr_ref = clk->clk_lcpll / ch2_mdiv; // LCPLL CH2
318 1.17.2.2 matt clk->clk_axi = clk->clk_lcpll / ch3_mdiv; // LCPLL CH3
319 1.17.2.2 matt }
320 1.17.2.2 matt
321 1.17.2.2 matt static void
322 1.17.2.2 matt bcm53xx_usb_clock_init(struct bcm53xx_clock_info *clk, uint32_t usb2_control)
323 1.17.2.2 matt {
324 1.17.2.2 matt const uint32_t pdiv = bcm53xx_value_wrap(usb2_control,
325 1.17.2.2 matt USB2_CONTROL_PDIV);
326 1.17.2.2 matt const uint32_t ndiv = bcm53xx_value_wrap(usb2_control,
327 1.17.2.2 matt USB2_CONTROL_NDIV_INT);
328 1.17.2.2 matt
329 1.17.2.2 matt uint32_t usb_ref = (clk->clk_usb2 / pdiv) * ndiv;
330 1.17.2.2 matt if (usb_ref != USB2_REF_CLK) {
331 1.17.2.2 matt /*
332 1.17.2.2 matt * USB Reference Clock isn't 1.92GHz. So we need to modify
333 1.17.2.2 matt * USB2_CONTROL to produce it.
334 1.17.2.2 matt */
335 1.17.2.2 matt uint32_t new_ndiv = (USB2_REF_CLK / clk->clk_usb2) * pdiv;
336 1.17.2.2 matt usb2_control &= ~USB2_CONTROL_NDIV_INT;
337 1.17.2.2 matt usb2_control |= __SHIFTIN(new_ndiv, USB2_CONTROL_NDIV_INT);
338 1.17.2.2 matt
339 1.17.2.2 matt // Allow Clocks to be modified
340 1.17.2.2 matt bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
341 1.17.2.2 matt CRU_BASE + CRU_CLKSET_KEY, CRU_CLKSET_KEY_MAGIC);
342 1.17.2.2 matt
343 1.17.2.2 matt // Update USB2 clock generator
344 1.17.2.2 matt bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
345 1.17.2.2 matt CRU_BASE + CRU_USB2_CONTROL, usb2_control);
346 1.17.2.2 matt
347 1.17.2.2 matt // Prevent Clock modification
348 1.17.2.2 matt bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
349 1.17.2.2 matt CRU_BASE + CRU_CLKSET_KEY, 0);
350 1.17.2.2 matt
351 1.17.2.2 matt usb_ref = (clk->clk_usb2 / pdiv) * new_ndiv;
352 1.17.2.2 matt }
353 1.17.2.2 matt
354 1.17.2.2 matt clk->clk_usb_ref = usb_ref;
355 1.17.2.2 matt }
356 1.17.2.2 matt
357 1.17.2.2 matt
358 1.17.2.2 matt static void
359 1.17.2.2 matt bcm53xx_clock_init(struct bcm53xx_clock_info *clk)
360 1.17.2.2 matt {
361 1.17.2.2 matt clk->clk_ref = BCM53XX_REF_CLK;
362 1.17.2.2 matt clk->clk_sys = 8*clk->clk_ref;
363 1.17.2.2 matt }
364 1.17.2.2 matt
365 1.17.2.2 matt /*
366 1.17.2.2 matt * F(ddr) = ((1 / pdiv) * ndiv * CH2) / (post_div * 2)
367 1.17.2.2 matt */
368 1.17.2.2 matt static void
369 1.17.2.2 matt bcm53xx_get_ddr_freq(struct bcm53xx_clock_info *clk, uint32_t pll_status,
370 1.17.2.2 matt uint32_t pll_dividers)
371 1.17.2.2 matt {
372 1.17.2.2 matt const bool clocking_4x = (pll_status & PLL_STATUS_CLOCKING_4X) != 0;
373 1.17.2.2 matt u_int post_div = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_POST_DIV);
374 1.17.2.2 matt u_int pdiv = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_PDIV);
375 1.17.2.2 matt u_int ndiv = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_NDIV);
376 1.17.2.2 matt
377 1.17.2.2 matt pdiv = ((pdiv - (clocking_4x ? 1 : 5)) & 7) + 1;
378 1.17.2.2 matt
379 1.17.2.2 matt clk->clk_ddr_mhz = __SHIFTOUT(pll_status, PLL_STATUS_MHZ);
380 1.17.2.2 matt clk->clk_ddr = (clk->clk_ddr_ref / pdiv) * ndiv / (2 + post_div);
381 1.17.2.2 matt }
382 1.17.2.2 matt
383 1.17.2.2 matt /*
384 1.17.2.2 matt * CPU_CLK = (1 / pdiv) * (ndiv_int + (ndiv_frac / 0x40000000)) x F(ref)
385 1.17.2.2 matt */
386 1.17.2.2 matt static void
387 1.17.2.2 matt bcm53xx_get_cpu_freq(struct bcm53xx_clock_info *clk,
388 1.17.2.2 matt uint32_t pllarma, uint32_t pllarmb, uint32_t policy)
389 1.17.2.2 matt {
390 1.17.2.2 matt policy = __SHIFTOUT(policy, CLK_POLICY_FREQ_POLICY2);
391 1.17.2.2 matt
392 1.17.2.2 matt if (policy == CLK_POLICY_REF_CLK) {
393 1.17.2.2 matt clk->clk_cpu = clk->clk_ref;
394 1.17.2.2 matt clk->clk_apb = clk->clk_cpu;
395 1.17.2.2 matt return;
396 1.17.2.2 matt }
397 1.17.2.2 matt
398 1.17.2.2 matt if (policy == CLK_POLICY_SYS_CLK) {
399 1.17.2.2 matt clk->clk_cpu = clk->clk_sys;
400 1.17.2.2 matt clk->clk_apb = clk->clk_cpu / 4;
401 1.17.2.2 matt return;
402 1.17.2.2 matt }
403 1.17.2.2 matt
404 1.17.2.2 matt const u_int pdiv = bcm53xx_value_wrap(pllarma, CLK_PLLARMA_PDIV);
405 1.17.2.2 matt const u_int ndiv_int = bcm53xx_value_wrap(pllarma, CLK_PLLARMA_NDIV_INT);
406 1.17.2.2 matt const u_int ndiv_frac = __SHIFTOUT(pllarmb, CLK_PLLARMB_NDIV_FRAC);
407 1.17.2.2 matt // const u_int apb_clk_div = __SHIFTOUT(apb_clk_div, CLK_APB_DIV_VALUE)+1;
408 1.17.2.2 matt
409 1.17.2.2 matt const u_int cpu_div = (policy == CLK_POLICY_ARM_PLL_CH0) ? 4 : 2;
410 1.17.2.2 matt
411 1.17.2.2 matt clk->clk_cpu = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac) / cpu_div;
412 1.17.2.2 matt clk->clk_apb = clk->clk_cpu / 4;
413 1.17.2.2 matt }
414 1.17.2.2 matt
415 1.17.2.2 matt struct bcm53xx_chip_state {
416 1.17.2.2 matt uint32_t bcs_lcpll_control1;
417 1.17.2.2 matt uint32_t bcs_lcpll_control2;
418 1.17.2.2 matt
419 1.17.2.2 matt uint32_t bcs_genpll_control5;
420 1.17.2.2 matt uint32_t bcs_genpll_control6;
421 1.17.2.2 matt uint32_t bcs_genpll_control7;
422 1.17.2.2 matt
423 1.17.2.2 matt uint32_t bcs_usb2_control;
424 1.17.2.2 matt
425 1.17.2.2 matt uint32_t bcs_ddr_phy_ctl_pll_status;
426 1.17.2.2 matt uint32_t bcs_ddr_phy_ctl_pll_dividers;
427 1.17.2.2 matt
428 1.17.2.2 matt uint32_t bcs_armcore_clk_policy;
429 1.17.2.2 matt uint32_t bcs_armcore_clk_pllarma;
430 1.17.2.2 matt uint32_t bcs_armcore_clk_pllarmb;
431 1.17.2.2 matt };
432 1.17.2.2 matt
433 1.17.2.2 matt static void
434 1.17.2.2 matt bcm53xx_get_chip_ioreg_state(struct bcm53xx_chip_state *bcs,
435 1.17.2.2 matt bus_space_tag_t bst, bus_space_handle_t bsh)
436 1.17.2.2 matt {
437 1.17.2.2 matt bcs->bcs_lcpll_control1 = bus_space_read_4(bst, bsh,
438 1.17.2.2 matt DMU_BASE + DMU_LCPLL_CONTROL1);
439 1.17.2.2 matt bcs->bcs_lcpll_control2 = bus_space_read_4(bst, bsh,
440 1.17.2.2 matt DMU_BASE + DMU_LCPLL_CONTROL2);
441 1.17.2.2 matt
442 1.17.2.2 matt bcs->bcs_genpll_control5 = bus_space_read_4(bst, bsh,
443 1.17.2.2 matt CRU_BASE + CRU_GENPLL_CONTROL5);
444 1.17.2.2 matt bcs->bcs_genpll_control6 = bus_space_read_4(bst, bsh,
445 1.17.2.2 matt CRU_BASE + CRU_GENPLL_CONTROL6);
446 1.17.2.2 matt bcs->bcs_genpll_control7 = bus_space_read_4(bst, bsh,
447 1.17.2.2 matt CRU_BASE + CRU_GENPLL_CONTROL7);
448 1.17.2.2 matt
449 1.17.2.2 matt bcs->bcs_usb2_control = bus_space_read_4(bst, bsh,
450 1.17.2.2 matt CRU_BASE + CRU_USB2_CONTROL);
451 1.17.2.2 matt
452 1.17.2.2 matt bcs->bcs_ddr_phy_ctl_pll_status = bus_space_read_4(bst, bsh,
453 1.17.2.2 matt DDR_BASE + DDR_PHY_CTL_PLL_STATUS);
454 1.17.2.2 matt bcs->bcs_ddr_phy_ctl_pll_dividers = bus_space_read_4(bst, bsh,
455 1.17.2.2 matt DDR_BASE + DDR_PHY_CTL_PLL_DIVIDERS);
456 1.17.2.2 matt }
457 1.17.2.2 matt
458 1.17.2.2 matt static void
459 1.17.2.2 matt bcm53xx_get_chip_armcore_state(struct bcm53xx_chip_state *bcs,
460 1.17.2.2 matt bus_space_tag_t bst, bus_space_handle_t bsh)
461 1.17.2.2 matt {
462 1.17.2.2 matt bcs->bcs_armcore_clk_policy = bus_space_read_4(bst, bsh,
463 1.17.2.2 matt ARMCORE_CLK_POLICY_FREQ);
464 1.17.2.2 matt bcs->bcs_armcore_clk_pllarma = bus_space_read_4(bst, bsh,
465 1.17.2.2 matt ARMCORE_CLK_PLLARMA);
466 1.17.2.2 matt bcs->bcs_armcore_clk_pllarmb = bus_space_read_4(bst, bsh,
467 1.17.2.2 matt ARMCORE_CLK_PLLARMB);
468 1.17.2.2 matt }
469 1.17.2.2 matt
470 1.17.2.2 matt void
471 1.17.2.2 matt bcm53xx_cpu_softc_init(struct cpu_info *ci)
472 1.17.2.2 matt {
473 1.17.2.2 matt struct cpu_softc * const cpu = ci->ci_softc;
474 1.17.2.2 matt
475 1.17.2.2 matt cpu->cpu_ioreg_bst = bcm53xx_ioreg_bst;
476 1.17.2.2 matt cpu->cpu_ioreg_bsh = bcm53xx_ioreg_bsh;
477 1.17.2.2 matt
478 1.17.2.2 matt cpu->cpu_armcore_bst = bcm53xx_armcore_bst;
479 1.17.2.2 matt cpu->cpu_armcore_bsh = bcm53xx_armcore_bsh;
480 1.17.2.2 matt
481 1.17.2.2 matt const uint32_t chipid = bus_space_read_4(cpu->cpu_ioreg_bst,
482 1.17.2.2 matt cpu->cpu_ioreg_bsh, CCA_MISC_BASE + MISC_CHIPID);
483 1.17.2.2 matt
484 1.17.2.2 matt cpu->cpu_chipid = __SHIFTOUT(chipid, CHIPID_ID);
485 1.17.2.2 matt }
486 1.17.2.2 matt
487 1.17.2.2 matt void
488 1.17.2.2 matt bcm53xx_print_clocks(void)
489 1.17.2.2 matt {
490 1.17.2.2 matt #if defined(VERBOSE_INIT_ARM)
491 1.17.2.2 matt const struct bcm53xx_clock_info * const clk = &cpu_softc.cpu_clk;
492 1.17.2.2 matt printf("ref clk = %u (%#x)\n", clk->clk_ref, clk->clk_ref);
493 1.17.2.2 matt printf("sys clk = %u (%#x)\n", clk->clk_sys, clk->clk_sys);
494 1.17.2.2 matt printf("lcpll clk = %u (%#x)\n", clk->clk_lcpll, clk->clk_lcpll);
495 1.17.2.2 matt printf("pcie ref clk = %u (%#x) [CH0]\n", clk->clk_pcie_ref, clk->clk_pcie_ref);
496 1.17.2.2 matt printf("sdio clk = %u (%#x) [CH1]\n", clk->clk_sdio, clk->clk_sdio);
497 1.17.2.2 matt printf("ddr ref clk = %u (%#x) [CH2]\n", clk->clk_ddr_ref, clk->clk_ddr_ref);
498 1.17.2.2 matt printf("axi clk = %u (%#x) [CH3]\n", clk->clk_axi, clk->clk_axi);
499 1.17.2.2 matt printf("genpll clk = %u (%#x)\n", clk->clk_genpll, clk->clk_genpll);
500 1.17.2.2 matt printf("mac clk = %u (%#x) [CH0]\n", clk->clk_mac, clk->clk_mac);
501 1.17.2.2 matt printf("robo clk = %u (%#x) [CH1]\n", clk->clk_robo, clk->clk_robo);
502 1.17.2.2 matt printf("usb2 clk = %u (%#x) [CH2]\n", clk->clk_usb2, clk->clk_usb2);
503 1.17.2.2 matt printf("iproc clk = %u (%#x) [CH3]\n", clk->clk_iproc, clk->clk_iproc);
504 1.17.2.2 matt printf("ddr clk = %u (%#x)\n", clk->clk_ddr, clk->clk_ddr);
505 1.17.2.2 matt printf("ddr mhz = %u (%#x)\n", clk->clk_ddr_mhz, clk->clk_ddr_mhz);
506 1.17.2.2 matt printf("cpu clk = %u (%#x)\n", clk->clk_cpu, clk->clk_cpu);
507 1.17.2.2 matt printf("apb clk = %u (%#x)\n", clk->clk_apb, clk->clk_apb);
508 1.17.2.2 matt printf("usb ref clk = %u (%#x)\n", clk->clk_usb_ref, clk->clk_usb_ref);
509 1.17.2.2 matt #endif
510 1.17.2.2 matt }
511 1.17.2.2 matt
512 1.17.2.2 matt void
513 1.17.2.2 matt bcm53xx_bootstrap(vaddr_t iobase)
514 1.17.2.2 matt {
515 1.17.2.2 matt struct bcm53xx_chip_state bcs;
516 1.17.2.2 matt int error;
517 1.17.2.2 matt
518 1.17.2.2 matt #ifdef BCM53XX_CONSOLE_EARLY
519 1.17.2.2 matt com_base = iobase + CCA_UART0_BASE;
520 1.17.2.2 matt cn_tab = &bcm53xx_earlycons;
521 1.17.2.2 matt #endif
522 1.17.2.2 matt
523 1.17.2.2 matt bcm53xx_ioreg_bsh = (bus_space_handle_t) iobase;
524 1.17.2.2 matt error = bus_space_map(bcm53xx_ioreg_bst, BCM53XX_IOREG_PBASE,
525 1.17.2.2 matt BCM53XX_IOREG_SIZE, 0, &bcm53xx_ioreg_bsh);
526 1.17.2.2 matt if (error)
527 1.17.2.2 matt panic("%s: failed to map BCM53xx %s registers: %d",
528 1.17.2.2 matt __func__, "io", error);
529 1.17.2.2 matt
530 1.17.2.2 matt bcm53xx_armcore_bsh = (bus_space_handle_t) iobase + BCM53XX_IOREG_SIZE;
531 1.17.2.2 matt error = bus_space_map(bcm53xx_armcore_bst, BCM53XX_ARMCORE_PBASE,
532 1.17.2.2 matt BCM53XX_ARMCORE_SIZE, 0, &bcm53xx_armcore_bsh);
533 1.17.2.2 matt if (error)
534 1.17.2.2 matt panic("%s: failed to map BCM53xx %s registers: %d",
535 1.17.2.2 matt __func__, "armcore", error);
536 1.17.2.2 matt
537 1.17.2.2 matt curcpu()->ci_softc = &cpu_softc;
538 1.17.2.2 matt
539 1.17.2.2 matt bcm53xx_get_chip_ioreg_state(&bcs, bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh);
540 1.17.2.2 matt bcm53xx_get_chip_armcore_state(&bcs, bcm53xx_armcore_bst, bcm53xx_armcore_bsh);
541 1.17.2.2 matt
542 1.17.2.2 matt struct bcm53xx_clock_info * const clk = &cpu_softc.cpu_clk;
543 1.17.2.2 matt
544 1.17.2.2 matt bcm53xx_clock_init(clk);
545 1.17.2.2 matt bcm53xx_lcpll_clock_init(clk, bcs.bcs_lcpll_control1,
546 1.17.2.2 matt bcs.bcs_lcpll_control2);
547 1.17.2.2 matt bcm53xx_genpll_clock_init(clk, bcs.bcs_genpll_control5,
548 1.17.2.2 matt bcs.bcs_genpll_control6, bcs.bcs_genpll_control7);
549 1.17.2.2 matt bcm53xx_usb_clock_init(clk, bcs.bcs_usb2_control);
550 1.17.2.2 matt bcm53xx_get_ddr_freq(clk, bcs.bcs_ddr_phy_ctl_pll_status,
551 1.17.2.2 matt bcs.bcs_ddr_phy_ctl_pll_dividers);
552 1.17.2.2 matt bcm53xx_get_cpu_freq(clk, bcs.bcs_armcore_clk_pllarma,
553 1.17.2.2 matt bcs.bcs_armcore_clk_pllarmb, bcs.bcs_armcore_clk_policy);
554 1.17.2.2 matt
555 1.17.2.2 matt curcpu()->ci_data.cpu_cc_freq = clk->clk_cpu;
556 1.17.2.2 matt
557 1.17.2.2 matt arml2cc_init(bcm53xx_armcore_bst, bcm53xx_armcore_bsh,
558 1.17.2.2 matt ARMCORE_L2C_BASE);
559 1.17.2.2 matt }
560 1.17.2.2 matt
561 1.17.2.2 matt void
562 1.17.2.2 matt bcm53xx_dma_bootstrap(psize_t memsize)
563 1.17.2.2 matt {
564 1.17.2.2 matt if (memsize <= 256*1024*1024) {
565 1.17.2.2 matt bcm53xx_dma_ranges[0].dr_len = memsize;
566 1.17.2.2 matt bcm53xx_coherent_dma_ranges[0].dr_len = memsize;
567 1.17.2.2 matt bcm53xx_dma_tag._nranges = 1;
568 1.17.2.2 matt bcm53xx_coherent_dma_tag._nranges = 1;
569 1.17.2.2 matt } else {
570 1.17.2.2 matt /*
571 1.17.2.2 matt * By setting up two ranges, bus_dmamem_alloc will always
572 1.17.2.2 matt * try to allocate from range 0 first resulting in allocations
573 1.17.2.2 matt * below 256MB which for PCI and GMAC are coherent.
574 1.17.2.2 matt */
575 1.17.2.2 matt bcm53xx_dma_ranges[1].dr_len = memsize - 0x10000000;
576 1.17.2.2 matt bcm53xx_coherent_dma_ranges[1].dr_len = memsize - 0x10000000;
577 1.17.2.2 matt }
578 1.17.2.2 matt KASSERT(bcm53xx_dma_tag._ranges[0].dr_flags == 0);
579 1.17.2.2 matt KASSERT(bcm53xx_coherent_dma_tag._ranges[0].dr_flags == _BUS_DMAMAP_COHERENT);
580 1.17.2.2 matt #ifdef _ARM32_NEED_BUS_DMA_BOUNCE
581 1.17.2.2 matt KASSERT(bcm53xx_bounce_dma_tag._ranges[0].dr_flags == _BUS_DMAMAP_COHERENT);
582 1.17.2.2 matt #endif
583 1.17.2.2 matt }
584 1.17.2.2 matt
585 1.17.2.2 matt #ifdef MULTIPROCESSOR
586 1.17.2.2 matt void
587 1.17.2.2 matt bcm53xx_cpu_hatch(struct cpu_info *ci)
588 1.17.2.2 matt {
589 1.17.2.2 matt a9tmr_init_cpu_clock(ci);
590 1.17.2.2 matt }
591 1.17.2.2 matt #endif
592 1.17.2.2 matt
593 1.17.2.2 matt void
594 1.17.2.2 matt bcm53xx_device_register(device_t self, void *aux)
595 1.17.2.2 matt {
596 1.17.2.2 matt prop_dictionary_t dict = device_properties(self);
597 1.17.2.2 matt
598 1.17.2.2 matt if (device_is_a(self, "armperiph")
599 1.17.2.2 matt && device_is_a(device_parent(self), "mainbus")) {
600 1.17.2.2 matt /*
601 1.17.2.2 matt * XXX KLUDGE ALERT XXX
602 1.17.2.2 matt * The iot mainbus supplies is completely wrong since it scales
603 1.17.2.2 matt * addresses by 2. The simpliest remedy is to replace with our
604 1.17.2.2 matt * bus space used for the armcore regisers (which armperiph uses).
605 1.17.2.2 matt */
606 1.17.2.2 matt struct mainbus_attach_args * const mb = aux;
607 1.17.2.2 matt mb->mb_iot = bcm53xx_armcore_bst;
608 1.17.2.2 matt return;
609 1.17.2.2 matt }
610 1.17.2.2 matt
611 1.17.2.2 matt /*
612 1.17.2.2 matt * We need to tell the A9 Global/Watchdog Timer
613 1.17.2.2 matt * what frequency it runs at.
614 1.17.2.2 matt */
615 1.17.2.2 matt if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) {
616 1.17.2.2 matt /*
617 1.17.2.2 matt * This clock always runs at (arm_clk div 2) and only goes
618 1.17.2.2 matt * to timers that are part of the A9 MP core subsystem.
619 1.17.2.2 matt */
620 1.17.2.2 matt prop_dictionary_set_uint32(dict, "frequency",
621 1.17.2.2 matt cpu_softc.cpu_clk.clk_cpu / 2);
622 1.17.2.2 matt return;
623 1.17.2.2 matt }
624 1.17.2.2 matt
625 1.17.2.2 matt if (device_is_a(self, "bcmeth")) {
626 1.17.2.2 matt const struct bcmccb_attach_args * const ccbaa = aux;
627 1.17.2.2 matt const uint8_t enaddr[ETHER_ADDR_LEN] = {
628 1.17.2.2 matt 0x00, 0x01, 0x02, 0x03, 0x04,
629 1.17.2.2 matt 0x05 + 2 * ccbaa->ccbaa_loc.loc_port,
630 1.17.2.2 matt };
631 1.17.2.2 matt prop_data_t pd = prop_data_create_data(enaddr, ETHER_ADDR_LEN);
632 1.17.2.2 matt KASSERT(pd != NULL);
633 1.17.2.2 matt if (prop_dictionary_set(device_properties(self), "mac-address", pd) == false) {
634 1.17.2.2 matt printf("WARNING: Unable to set mac-address property for %s\n", device_xname(self));
635 1.17.2.2 matt }
636 1.17.2.2 matt prop_object_release(pd);
637 1.17.2.2 matt }
638 1.17.2.2 matt }
639 1.17.2.2 matt
640 1.17.2.2 matt static kmutex_t srab_lock __cacheline_aligned;
641 1.17.2.2 matt
642 1.17.2.2 matt void
643 1.17.2.2 matt bcm53xx_srab_init(void)
644 1.17.2.2 matt {
645 1.17.2.2 matt mutex_init(&srab_lock, MUTEX_DEFAULT, IPL_VM);
646 1.17.2.2 matt
647 1.17.2.2 matt bcm53xx_srab_write_4(0x0079, 0x90); // reset switch
648 1.17.2.2 matt for (u_int port = 0; port < 8; port++) {
649 1.17.2.2 matt /* per port control: no stp */
650 1.17.2.2 matt bcm53xx_srab_write_4(port, 0x00);
651 1.17.2.2 matt }
652 1.17.2.2 matt bcm53xx_srab_write_4(0x0008, 0x1c); // IMP port (enab UC/MC/BC)
653 1.17.2.2 matt bcm53xx_srab_write_4(0x000e, 0xbb); // IMP port force-link 1G
654 1.17.2.2 matt bcm53xx_srab_write_4(0x005d, 0x7b); // port5 force-link 1G
655 1.17.2.2 matt bcm53xx_srab_write_4(0x005f, 0x7b); // port7 force-link 1G
656 1.17.2.2 matt bcm53xx_srab_write_4(0x000b, 0x7); // management mode
657 1.17.2.2 matt bcm53xx_srab_write_4(0x0203, 0x0); // disable BRCM tag
658 1.17.2.2 matt bcm53xx_srab_write_4(0x0200, 0x80); // enable IMP=port8
659 1.17.2.2 matt }
660 1.17.2.2 matt
661 1.17.2.2 matt static inline void
662 1.17.2.2 matt bcm53xx_srab_busywait(bus_space_tag_t bst, bus_space_handle_t bsh)
663 1.17.2.2 matt {
664 1.17.2.2 matt while (bus_space_read_4(bst, bsh, SRAB_BASE + SRAB_CMDSTAT) & SRA_GORDYN) {
665 1.17.2.2 matt delay(10);
666 1.17.2.2 matt }
667 1.17.2.2 matt }
668 1.17.2.2 matt
669 1.17.2.2 matt uint32_t
670 1.17.2.2 matt bcm53xx_srab_read_4(u_int pageoffset)
671 1.17.2.2 matt {
672 1.17.2.2 matt bus_space_tag_t bst = bcm53xx_ioreg_bst;
673 1.17.2.2 matt bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
674 1.17.2.2 matt uint32_t rv;
675 1.17.2.2 matt
676 1.17.2.2 matt mutex_spin_enter(&srab_lock);
677 1.17.2.2 matt
678 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
679 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_CMDSTAT,
680 1.17.2.2 matt __SHIFTIN(pageoffset, SRA_PAGEOFFSET) | SRA_GORDYN);
681 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
682 1.17.2.2 matt rv = bus_space_read_4(bst, bsh, SRAB_BASE + SRAB_RDL);
683 1.17.2.2 matt
684 1.17.2.2 matt mutex_spin_exit(&srab_lock);
685 1.17.2.2 matt return rv;
686 1.17.2.2 matt }
687 1.17.2.2 matt
688 1.17.2.2 matt uint64_t
689 1.17.2.2 matt bcm53xx_srab_read_8(u_int pageoffset)
690 1.17.2.2 matt {
691 1.17.2.2 matt bus_space_tag_t bst = bcm53xx_ioreg_bst;
692 1.17.2.2 matt bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
693 1.17.2.2 matt uint64_t rv;
694 1.17.2.2 matt
695 1.17.2.2 matt mutex_spin_enter(&srab_lock);
696 1.17.2.2 matt
697 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
698 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_CMDSTAT,
699 1.17.2.2 matt __SHIFTIN(pageoffset, SRA_PAGEOFFSET) | SRA_GORDYN);
700 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
701 1.17.2.2 matt rv = bus_space_read_4(bst, bsh, SRAB_BASE + SRAB_RDH);
702 1.17.2.2 matt rv <<= 32;
703 1.17.2.2 matt rv |= bus_space_read_4(bst, bsh, SRAB_BASE + SRAB_RDL);
704 1.17.2.2 matt
705 1.17.2.2 matt mutex_spin_exit(&srab_lock);
706 1.17.2.2 matt return rv;
707 1.17.2.2 matt }
708 1.17.2.2 matt
709 1.17.2.2 matt void
710 1.17.2.2 matt bcm53xx_srab_write_4(u_int pageoffset, uint32_t val)
711 1.17.2.2 matt {
712 1.17.2.2 matt bus_space_tag_t bst = bcm53xx_ioreg_bst;
713 1.17.2.2 matt bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
714 1.17.2.2 matt
715 1.17.2.2 matt mutex_spin_enter(&srab_lock);
716 1.17.2.2 matt
717 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
718 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_WDL, val);
719 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_CMDSTAT,
720 1.17.2.2 matt __SHIFTIN(pageoffset, SRA_PAGEOFFSET) | SRA_WRITE | SRA_GORDYN);
721 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
722 1.17.2.2 matt
723 1.17.2.2 matt mutex_spin_exit(&srab_lock);
724 1.17.2.2 matt }
725 1.17.2.2 matt
726 1.17.2.2 matt void
727 1.17.2.2 matt bcm53xx_srab_write_8(u_int pageoffset, uint64_t val)
728 1.17.2.2 matt {
729 1.17.2.2 matt bus_space_tag_t bst = bcm53xx_ioreg_bst;
730 1.17.2.2 matt bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
731 1.17.2.2 matt
732 1.17.2.2 matt mutex_spin_enter(&srab_lock);
733 1.17.2.2 matt
734 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
735 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_WDL, val);
736 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_WDH, val >> 32);
737 1.17.2.2 matt bus_space_write_4(bst, bsh, SRAB_BASE + SRAB_CMDSTAT,
738 1.17.2.2 matt __SHIFTIN(pageoffset, SRA_PAGEOFFSET) | SRA_WRITE | SRA_GORDYN);
739 1.17.2.2 matt bcm53xx_srab_busywait(bst, bsh);
740 1.17.2.2 matt mutex_spin_exit(&srab_lock);
741 1.17.2.2 matt }
742