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