Home | History | Annotate | Line # | Download | only in broadcom
bcm53xx_board.c revision 1.2
      1  1.2  matt /*	$NetBSD: bcm53xx_board.c,v 1.2 2012/09/07 11:52:30 matt 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.1  matt 
     33  1.1  matt #define	_ARM32_BUS_DMA_PRIVATE
     34  1.1  matt 
     35  1.1  matt #include <sys/cdefs.h>
     36  1.1  matt 
     37  1.2  matt __KERNEL_RCSID(1, "$NetBSD: bcm53xx_board.c,v 1.2 2012/09/07 11:52:30 matt Exp $");
     38  1.1  matt 
     39  1.1  matt #include <sys/param.h>
     40  1.1  matt #include <sys/bus.h>
     41  1.1  matt #include <sys/cpu.h>
     42  1.1  matt #include <sys/device.h>
     43  1.1  matt 
     44  1.1  matt #include <prop/proplib.h>
     45  1.1  matt 
     46  1.1  matt #define CRU_PRIVATE
     47  1.1  matt #define DDR_PRIVATE
     48  1.1  matt #define DMU_PRIVATE
     49  1.1  matt #define ARMCORE_PRIVATE
     50  1.1  matt 
     51  1.1  matt #include <arm/cortex/a9tmr_var.h>
     52  1.2  matt #include <arm/cortex/pl310_var.h>
     53  1.1  matt #include <arm/mainbus/mainbus.h>
     54  1.1  matt 
     55  1.1  matt #include <arm/broadcom/bcm53xx_reg.h>
     56  1.1  matt #include <arm/broadcom/bcm53xx_var.h>
     57  1.1  matt 
     58  1.1  matt bus_space_tag_t bcm53xx_ioreg_bst = &bcmgen_bs_tag;
     59  1.1  matt bus_space_handle_t bcm53xx_ioreg_bsh;
     60  1.1  matt bus_space_tag_t bcm53xx_armcore_bst = &bcmgen_bs_tag;
     61  1.1  matt bus_space_handle_t bcm53xx_armcore_bsh;
     62  1.1  matt 
     63  1.1  matt static struct cpu_softc cpu_softc;
     64  1.1  matt static struct bcm53xx_clock_info clk_info;
     65  1.1  matt 
     66  1.1  matt struct arm32_bus_dma_tag bcm53xx_dma_tag = {
     67  1.2  matt 	._dmamap_create = _bus_dmamap_create,
     68  1.2  matt 	._dmamap_destroy = _bus_dmamap_destroy,
     69  1.2  matt 	._dmamap_load = _bus_dmamap_load,
     70  1.2  matt 	._dmamap_load_mbuf = _bus_dmamap_load_mbuf,
     71  1.2  matt 	._dmamap_load_uio = _bus_dmamap_load_uio,
     72  1.2  matt 	._dmamap_load_raw = _bus_dmamap_load_raw,
     73  1.2  matt 	._dmamap_unload = _bus_dmamap_unload,
     74  1.2  matt 	._dmamap_sync_pre = _bus_dmamap_sync,
     75  1.2  matt 	._dmamap_sync_post = NULL,
     76  1.2  matt 	._dmamem_alloc = _bus_dmamem_alloc,
     77  1.2  matt 	._dmamem_free = _bus_dmamem_free,
     78  1.2  matt 	._dmamem_map = _bus_dmamem_map,
     79  1.2  matt 	._dmamem_unmap = _bus_dmamem_unmap,
     80  1.2  matt 	._dmamem_mmap = _bus_dmamem_mmap
     81  1.1  matt };
     82  1.1  matt 
     83  1.1  matt #ifdef BCM53XX_CONSOLE_EARLY
     84  1.1  matt #include <dev/ic/ns16550reg.h>
     85  1.1  matt #include <dev/ic/comreg.h>
     86  1.1  matt #include <dev/cons.h>
     87  1.1  matt 
     88  1.1  matt static vaddr_t com_base;
     89  1.1  matt 
     90  1.1  matt static inline uint32_t
     91  1.1  matt uart_read(bus_size_t o)
     92  1.1  matt {
     93  1.1  matt 	return *(volatile uint8_t *)(com_base + o);
     94  1.1  matt }
     95  1.1  matt 
     96  1.1  matt static inline void
     97  1.1  matt uart_write(bus_size_t o, uint32_t v)
     98  1.1  matt {
     99  1.1  matt 	*(volatile uint8_t *)(com_base + o) = v;
    100  1.1  matt }
    101  1.1  matt 
    102  1.1  matt static int
    103  1.1  matt bcm53xx_cngetc(dev_t dv)
    104  1.1  matt {
    105  1.1  matt         if ((uart_read(com_lsr) & LSR_RXRDY) == 0)
    106  1.1  matt 		return -1;
    107  1.1  matt 
    108  1.1  matt 	return uart_read(com_data) & 0xff;
    109  1.1  matt }
    110  1.1  matt 
    111  1.1  matt static void
    112  1.1  matt bcm53xx_cnputc(dev_t dv, int c)
    113  1.1  matt {
    114  1.1  matt 	int timo = 150000;
    115  1.1  matt 
    116  1.1  matt         while ((uart_read(com_lsr) & LSR_TXRDY) == 0 && --timo > 0)
    117  1.1  matt 		;
    118  1.1  matt 
    119  1.1  matt 	uart_write(com_data, c);
    120  1.1  matt 
    121  1.1  matt 	timo = 150000;
    122  1.1  matt         while ((uart_read(com_lsr) & LSR_TSRE) == 0 && --timo > 0)
    123  1.1  matt 		;
    124  1.1  matt }
    125  1.1  matt 
    126  1.1  matt static struct consdev bcm53xx_earlycons = {
    127  1.1  matt 	.cn_putc = bcm53xx_cnputc,
    128  1.1  matt 	.cn_getc = bcm53xx_cngetc,
    129  1.1  matt 	.cn_pollc = nullcnpollc,
    130  1.1  matt };
    131  1.1  matt #endif /* BCM53XX_CONSOLE_EARLY */
    132  1.1  matt 
    133  1.1  matt psize_t
    134  1.1  matt bcm53xx_memprobe(void)
    135  1.1  matt {
    136  1.1  matt 	bus_space_tag_t bst = bcm53xx_ioreg_bst;
    137  1.1  matt 	bus_space_handle_t bsh = bcm53xx_ioreg_bsh;
    138  1.1  matt 
    139  1.1  matt 	/*
    140  1.1  matt 	 * First, let's read the magic DDR registers!
    141  1.1  matt 	 */
    142  1.1  matt 	const uint32_t v01 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_01);
    143  1.1  matt 	const uint32_t v82 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_82);
    144  1.1  matt 	const uint32_t v86 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_86);
    145  1.1  matt 	const uint32_t v87 = bus_space_read_4(bst, bsh, DDR_BASE + DDR_CTL_87);
    146  1.1  matt 
    147  1.1  matt 	/*
    148  1.1  matt 	 * Calculate chip parameters
    149  1.1  matt 	 * */
    150  1.1  matt 	const u_int rows = __SHIFTOUT(v01, CTL_01_MAX_ROW)
    151  1.1  matt 	    - __SHIFTOUT(v82, CTL_82_ROW_DIFF);
    152  1.1  matt 	const u_int cols = __SHIFTOUT(v01, CTL_01_MAX_COL)
    153  1.1  matt 	    - __SHIFTOUT(v82, CTL_82_COL_DIFF);
    154  1.1  matt 	const u_int banks_log2 = 3 - __SHIFTOUT(v82, CTL_82_BANK_DIFF);
    155  1.1  matt 
    156  1.1  matt 	/*
    157  1.1  matt 	 * For each chip select, increase the chip count if if is enabled.
    158  1.1  matt 	 */
    159  1.1  matt 	const u_int max_chips = __SHIFTOUT(v01, CTL_01_MAX_CHIP_SEL);
    160  1.1  matt 	u_int cs_map = __SHIFTOUT(v86, CTL_86_CS_MAP);
    161  1.1  matt 	u_int chips = 0;
    162  1.1  matt 
    163  1.1  matt 	for (u_int i = 0; cs_map != 0 && i < max_chips; i++, cs_map >>= 1) {
    164  1.1  matt 		chips += (cs_map & 1);
    165  1.1  matt 	}
    166  1.1  matt 
    167  1.1  matt 	/* get log2(ddr width) */
    168  1.1  matt 
    169  1.1  matt 	const u_int ddr_width_log2 = (v87 & CTL_87_REDUC) ? 1 : 2;
    170  1.1  matt 
    171  1.1  matt 	/*
    172  1.1  matt 	 * Let's add up all the things that contribute to the size of a chip.
    173  1.1  matt 	 */
    174  1.1  matt 	const u_int chip_size_log2 = cols + rows + banks_log2 + ddr_width_log2;
    175  1.1  matt 
    176  1.1  matt 	/*
    177  1.1  matt 	 * Now our memory size is simply the number of chip shifted by the
    178  1.1  matt 	 * log2(chip_size).
    179  1.1  matt 	 */
    180  1.1  matt 	return (psize_t) chips << chip_size_log2;
    181  1.1  matt }
    182  1.1  matt 
    183  1.1  matt static inline uint32_t
    184  1.1  matt bcm53xx_freq_calc(struct bcm53xx_clock_info *clk,
    185  1.1  matt 	uint32_t pdiv, uint32_t ndiv_int, uint32_t ndiv_frac)
    186  1.1  matt {
    187  1.1  matt 	if (ndiv_frac == 0 && pdiv == 1)
    188  1.1  matt 		return ndiv_int * clk->clk_ref;
    189  1.1  matt 
    190  1.1  matt 	uint64_t freq64 = ((uint64_t)ndiv_int << 30) + ndiv_frac;
    191  1.1  matt 	freq64 *= clk->clk_ref;
    192  1.1  matt 	if (pdiv > 1)
    193  1.1  matt 		freq64 /= pdiv;
    194  1.1  matt 	return (uint32_t) (freq64 >> 30);
    195  1.1  matt }
    196  1.1  matt 
    197  1.1  matt static uint32_t
    198  1.1  matt bcm53xx_value_wrap(uint32_t value, uint32_t mask)
    199  1.1  matt {
    200  1.1  matt 	/*
    201  1.1  matt 	 * n is n except when n is 0 then n = mask + 1.
    202  1.1  matt 	 */
    203  1.1  matt 	return ((__SHIFTOUT(value, mask) - 1) &  __SHIFTOUT(mask, mask)) + 1;
    204  1.1  matt }
    205  1.1  matt 
    206  1.1  matt static void
    207  1.1  matt bcm53xx_genpll_clock_init(struct bcm53xx_clock_info *clk, uint32_t control5,
    208  1.1  matt 	uint32_t control6, uint32_t control7)
    209  1.1  matt {
    210  1.1  matt 	const uint32_t pdiv = bcm53xx_value_wrap(control6,
    211  1.1  matt 	    GENPLL_CONTROL6_PDIV);
    212  1.1  matt 	const uint32_t ndiv_int = bcm53xx_value_wrap(control5,
    213  1.1  matt 	    GENPLL_CONTROL5_NDIV_INT);
    214  1.1  matt 	const uint32_t ndiv_frac = __SHIFTOUT(control5,
    215  1.1  matt 	    GENPLL_CONTROL5_NDIV_FRAC);
    216  1.1  matt 
    217  1.1  matt 	clk->clk_genpll = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac);
    218  1.1  matt 
    219  1.1  matt 	const uint32_t ch0_mdiv = bcm53xx_value_wrap(control6,
    220  1.1  matt 	    GENPLL_CONTROL6_CH0_MDIV);
    221  1.1  matt 	const uint32_t ch1_mdiv = bcm53xx_value_wrap(control6,
    222  1.1  matt 	    GENPLL_CONTROL6_CH1_MDIV);
    223  1.1  matt 	const uint32_t ch2_mdiv = bcm53xx_value_wrap(control6,
    224  1.1  matt 	    GENPLL_CONTROL6_CH2_MDIV);
    225  1.1  matt 	const uint32_t ch3_mdiv = bcm53xx_value_wrap(control7,
    226  1.1  matt 	    GENPLL_CONTROL7_CH3_MDIV);
    227  1.1  matt 
    228  1.1  matt 	clk->clk_mac = clk->clk_genpll / ch0_mdiv;	// GENPLL CH0
    229  1.1  matt 	clk->clk_robo = clk->clk_genpll / ch1_mdiv;	// GENPLL CH1
    230  1.1  matt 	clk->clk_usb2 = clk->clk_genpll / ch2_mdiv;	// GENPLL CH2
    231  1.1  matt 	clk->clk_iproc = clk->clk_genpll / ch3_mdiv;	// GENPLL CH3
    232  1.1  matt }
    233  1.1  matt 
    234  1.1  matt static void
    235  1.1  matt bcm53xx_lcpll_clock_init(struct bcm53xx_clock_info *clk, uint32_t control1,
    236  1.1  matt 	uint32_t control2)
    237  1.1  matt {
    238  1.1  matt 	const uint32_t pdiv = bcm53xx_value_wrap(control1,
    239  1.1  matt 	    LCPLL_CONTROL1_PDIV);
    240  1.1  matt 	const uint32_t ndiv_int = bcm53xx_value_wrap(control1,
    241  1.1  matt 	    LCPLL_CONTROL1_NDIV_INT);
    242  1.1  matt 	const uint32_t ndiv_frac = __SHIFTOUT(control1,
    243  1.1  matt 	    LCPLL_CONTROL1_NDIV_FRAC);
    244  1.1  matt 
    245  1.1  matt 	clk->clk_lcpll = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac);
    246  1.1  matt 
    247  1.1  matt 	const uint32_t ch0_mdiv = bcm53xx_value_wrap(control2,
    248  1.1  matt 	    LCPLL_CONTROL2_CH0_MDIV);
    249  1.1  matt 	const uint32_t ch1_mdiv = bcm53xx_value_wrap(control2,
    250  1.1  matt 	    LCPLL_CONTROL2_CH1_MDIV);
    251  1.1  matt 	const uint32_t ch2_mdiv = bcm53xx_value_wrap(control2,
    252  1.1  matt 	    LCPLL_CONTROL2_CH2_MDIV);
    253  1.1  matt 	const uint32_t ch3_mdiv = bcm53xx_value_wrap(control2,
    254  1.1  matt 	    LCPLL_CONTROL2_CH3_MDIV);
    255  1.1  matt 
    256  1.1  matt 	clk->clk_pcie_ref = clk->clk_lcpll / ch0_mdiv;	// LCPLL CH0
    257  1.1  matt 	clk->clk_sdio = clk->clk_lcpll / ch1_mdiv;	// LCPLL CH1
    258  1.1  matt 	clk->clk_ddr_ref = clk->clk_lcpll / ch2_mdiv;	// LCPLL CH2
    259  1.1  matt 	clk->clk_axi = clk->clk_lcpll / ch3_mdiv;	// LCPLL CH3
    260  1.1  matt }
    261  1.1  matt 
    262  1.1  matt static void
    263  1.1  matt bcm53xx_usb_clock_init(struct bcm53xx_clock_info *clk, uint32_t usb2_control)
    264  1.1  matt {
    265  1.1  matt 	const uint32_t pdiv = bcm53xx_value_wrap(usb2_control,
    266  1.1  matt 	    USB2_CONTROL_PDIV);
    267  1.1  matt 	const uint32_t ndiv = bcm53xx_value_wrap(usb2_control,
    268  1.1  matt 	    USB2_CONTROL_NDIV_INT);
    269  1.1  matt 
    270  1.1  matt 	uint32_t usb_ref = (clk->clk_usb2 / pdiv) * ndiv;
    271  1.1  matt 	if (usb_ref != USB2_REF_CLK) {
    272  1.1  matt 		/*
    273  1.1  matt 		 * USB Reference Clock isn't 1.92GHz.  So we need to modify
    274  1.1  matt 		 * USB2_CONTROL to produce it.
    275  1.1  matt 		 */
    276  1.1  matt 		uint32_t new_ndiv = (USB2_REF_CLK / clk->clk_usb2) * pdiv;
    277  1.1  matt 		usb2_control &= ~USB2_CONTROL_NDIV_INT;
    278  1.1  matt 		usb2_control |= __SHIFTIN(new_ndiv, USB2_CONTROL_NDIV_INT);
    279  1.1  matt 
    280  1.1  matt 		// Allow Clocks to be modified
    281  1.1  matt 		bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
    282  1.1  matt 		    CRU_BASE + CRU_CLKSET_KEY, CRU_CLKSET_KEY_MAGIC);
    283  1.1  matt 
    284  1.1  matt 		// Update USB2 clock generator
    285  1.1  matt 		bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
    286  1.1  matt 		    CRU_BASE + CRU_USB2_CONTROL, usb2_control);
    287  1.1  matt 
    288  1.1  matt 		// Prevent Clock modification
    289  1.1  matt 		bus_space_write_4(bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh,
    290  1.1  matt 		    CRU_BASE + CRU_CLKSET_KEY, 0);
    291  1.1  matt 
    292  1.1  matt 		usb_ref = (clk->clk_usb2 / pdiv) * new_ndiv;
    293  1.1  matt 	}
    294  1.1  matt 
    295  1.1  matt 	clk->clk_usb_ref = usb_ref;
    296  1.1  matt }
    297  1.1  matt 
    298  1.1  matt 
    299  1.1  matt static void
    300  1.1  matt bcm53xx_clock_init(struct bcm53xx_clock_info *clk)
    301  1.1  matt {
    302  1.1  matt 	clk->clk_ref = BCM53XX_REF_CLK;
    303  1.1  matt 	clk->clk_sys = 8*clk->clk_ref;
    304  1.1  matt }
    305  1.1  matt 
    306  1.1  matt /*
    307  1.1  matt  * F(ddr) = ((1 / pdiv) * ndiv * CH2) / (post_div * 2)
    308  1.1  matt  */
    309  1.1  matt static void
    310  1.1  matt bcm53xx_get_ddr_freq(struct bcm53xx_clock_info *clk, uint32_t pll_status,
    311  1.1  matt     uint32_t pll_dividers)
    312  1.1  matt {
    313  1.1  matt 	const bool clocking_4x = (pll_status & PLL_STATUS_CLOCKING_4X) != 0;
    314  1.1  matt 	u_int post_div = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_POST_DIV);
    315  1.1  matt 	u_int pdiv = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_PDIV);
    316  1.1  matt 	u_int ndiv = __SHIFTOUT(pll_dividers, PLL_DIVIDERS_NDIV);
    317  1.1  matt 
    318  1.1  matt 	pdiv = ((pdiv - (clocking_4x ? 1 : 5)) & 7) + 1;
    319  1.1  matt 
    320  1.1  matt 	clk->clk_ddr_mhz = __SHIFTOUT(pll_status, PLL_STATUS_MHZ);
    321  1.1  matt 	clk->clk_ddr = (clk->clk_ddr_ref / pdiv) * ndiv / (2 + post_div);
    322  1.1  matt }
    323  1.1  matt 
    324  1.1  matt /*
    325  1.1  matt  * CPU_CLK = (1 / pdiv) * (ndiv_int + (ndiv_frac / 0x40000000)) x F(ref)
    326  1.1  matt  */
    327  1.1  matt static void
    328  1.1  matt bcm53xx_get_cpu_freq(struct bcm53xx_clock_info *clk,
    329  1.1  matt 	uint32_t pllarma, uint32_t pllarmb, uint32_t policy)
    330  1.1  matt {
    331  1.1  matt 	policy = __SHIFTOUT(policy, CLK_POLICY_FREQ_POLICY2);
    332  1.1  matt 
    333  1.1  matt 	if (policy == CLK_POLICY_REF_CLK) {
    334  1.1  matt 		clk->clk_cpu = clk->clk_ref;
    335  1.1  matt 		clk->clk_apb = clk->clk_cpu;
    336  1.1  matt 		return;
    337  1.1  matt 	}
    338  1.1  matt 
    339  1.1  matt 	if (policy == CLK_POLICY_SYS_CLK) {
    340  1.1  matt 		clk->clk_cpu = clk->clk_sys;
    341  1.1  matt 		clk->clk_apb = clk->clk_cpu / 4;
    342  1.1  matt 		return;
    343  1.1  matt 	}
    344  1.1  matt 
    345  1.1  matt 	const u_int pdiv = bcm53xx_value_wrap(pllarma, CLK_PLLARMA_PDIV);
    346  1.1  matt 	const u_int ndiv_int = bcm53xx_value_wrap(pllarma, CLK_PLLARMA_NDIV_INT);
    347  1.1  matt 	const u_int ndiv_frac = __SHIFTOUT(pllarmb, CLK_PLLARMB_NDIV_FRAC);
    348  1.1  matt 	// const u_int apb_clk_div = __SHIFTOUT(apb_clk_div, CLK_APB_DIV_VALUE)+1;
    349  1.1  matt 
    350  1.1  matt 	const u_int cpu_div = (policy == CLK_POLICY_ARM_PLL_CH0) ? 4 : 2;
    351  1.1  matt 
    352  1.1  matt 	clk->clk_cpu = bcm53xx_freq_calc(clk, pdiv, ndiv_int, ndiv_frac) / cpu_div;
    353  1.1  matt 	clk->clk_apb = clk->clk_cpu / 4;
    354  1.1  matt }
    355  1.1  matt 
    356  1.1  matt struct bcm53xx_chip_state {
    357  1.1  matt 	uint32_t bcs_lcpll_control1;
    358  1.1  matt 	uint32_t bcs_lcpll_control2;
    359  1.1  matt 
    360  1.1  matt 	uint32_t bcs_genpll_control5;
    361  1.1  matt 	uint32_t bcs_genpll_control6;
    362  1.1  matt 	uint32_t bcs_genpll_control7;
    363  1.1  matt 
    364  1.1  matt 	uint32_t bcs_usb2_control;
    365  1.1  matt 
    366  1.1  matt 	uint32_t bcs_ddr_phy_ctl_pll_status;
    367  1.1  matt 	uint32_t bcs_ddr_phy_ctl_pll_dividers;
    368  1.1  matt 
    369  1.1  matt 	uint32_t bcs_armcore_clk_policy;
    370  1.1  matt 	uint32_t bcs_armcore_clk_pllarma;
    371  1.1  matt 	uint32_t bcs_armcore_clk_pllarmb;
    372  1.1  matt };
    373  1.1  matt 
    374  1.1  matt static void
    375  1.1  matt bcm53xx_get_chip_ioreg_state(struct bcm53xx_chip_state *bcs,
    376  1.1  matt 	bus_space_tag_t bst, bus_space_handle_t bsh)
    377  1.1  matt {
    378  1.1  matt 	bcs->bcs_lcpll_control1 = bus_space_read_4(bst, bsh,
    379  1.1  matt 	    DMU_BASE + DMU_LCPLL_CONTROL1);
    380  1.1  matt 	bcs->bcs_lcpll_control2 = bus_space_read_4(bst, bsh,
    381  1.1  matt 	    DMU_BASE + DMU_LCPLL_CONTROL2);
    382  1.1  matt 
    383  1.1  matt 	bcs->bcs_genpll_control5 = bus_space_read_4(bst, bsh,
    384  1.1  matt 	    CRU_BASE + CRU_GENPLL_CONTROL5);
    385  1.1  matt 	bcs->bcs_genpll_control6 = bus_space_read_4(bst, bsh,
    386  1.1  matt 	    CRU_BASE + CRU_GENPLL_CONTROL6);
    387  1.1  matt 	bcs->bcs_genpll_control7 = bus_space_read_4(bst, bsh,
    388  1.1  matt 	    CRU_BASE + CRU_GENPLL_CONTROL7);
    389  1.1  matt 
    390  1.1  matt 	bcs->bcs_usb2_control = bus_space_read_4(bst, bsh,
    391  1.1  matt 	    CRU_BASE + CRU_USB2_CONTROL);
    392  1.1  matt 
    393  1.1  matt 	bcs->bcs_ddr_phy_ctl_pll_status = bus_space_read_4(bst, bsh,
    394  1.1  matt 	    DDR_BASE + DDR_PHY_CTL_PLL_STATUS);
    395  1.1  matt 	bcs->bcs_ddr_phy_ctl_pll_dividers = bus_space_read_4(bst, bsh,
    396  1.1  matt 	    DDR_BASE + DDR_PHY_CTL_PLL_DIVIDERS);
    397  1.1  matt }
    398  1.1  matt 
    399  1.1  matt static void
    400  1.1  matt bcm53xx_get_chip_armcore_state(struct bcm53xx_chip_state *bcs,
    401  1.1  matt 	bus_space_tag_t bst, bus_space_handle_t bsh)
    402  1.1  matt {
    403  1.1  matt 	bcs->bcs_armcore_clk_policy = bus_space_read_4(bst, bsh,
    404  1.1  matt 	    ARMCORE_CLK_POLICY_FREQ);
    405  1.1  matt 	bcs->bcs_armcore_clk_pllarma = bus_space_read_4(bst, bsh,
    406  1.1  matt 	    ARMCORE_CLK_PLLARMA);
    407  1.1  matt 	bcs->bcs_armcore_clk_pllarmb = bus_space_read_4(bst, bsh,
    408  1.1  matt 	    ARMCORE_CLK_PLLARMB);
    409  1.1  matt }
    410  1.1  matt 
    411  1.1  matt void
    412  1.1  matt bcm53xx_cpu_softc_init(struct cpu_info *ci)
    413  1.1  matt {
    414  1.1  matt 	struct cpu_softc * const cpu = ci->ci_softc;
    415  1.1  matt 
    416  1.1  matt 	cpu->cpu_ioreg_bst = bcm53xx_ioreg_bst;
    417  1.1  matt 	cpu->cpu_ioreg_bsh = bcm53xx_ioreg_bsh;
    418  1.1  matt 
    419  1.1  matt 	cpu->cpu_armcore_bst = bcm53xx_armcore_bst;
    420  1.1  matt 	cpu->cpu_armcore_bsh = bcm53xx_armcore_bsh;
    421  1.1  matt }
    422  1.1  matt 
    423  1.1  matt void
    424  1.1  matt bcm53xx_print_clocks(void)
    425  1.1  matt {
    426  1.1  matt #if defined(VERBOSE_ARM_INIT)
    427  1.1  matt 	printf("ref clk =	%u (%#x)\n", clk_info.clk_ref, clk_info.clk_ref);
    428  1.1  matt 	printf("sys clk =	%u (%#x)\n", clk_info.clk_sys, clk_info.clk_sys);
    429  1.1  matt 	printf("lcpll clk =	%u (%#x)\n", clk_info.clk_lcpll, clk_info.clk_lcpll);
    430  1.1  matt 	printf("pcie ref clk =	%u (%#x) [CH0]\n", clk_info.clk_pcie_ref, clk_info.clk_pcie_ref);
    431  1.1  matt 	printf("sdio clk =	%u (%#x) [CH1]\n", clk_info.clk_sdio, clk_info.clk_sdio);
    432  1.1  matt 	printf("ddr ref clk =	%u (%#x) [CH2]\n", clk_info.clk_ddr_ref, clk_info.clk_ddr_ref);
    433  1.1  matt 	printf("axi clk =	%u (%#x) [CH3]\n", clk_info.clk_axi, clk_info.clk_axi);
    434  1.1  matt 	printf("genpll clk =	%u (%#x)\n", clk_info.clk_genpll, clk_info.clk_genpll);
    435  1.1  matt 	printf("mac clk =	%u (%#x) [CH0]\n", clk_info.clk_mac, clk_info.clk_mac);
    436  1.1  matt 	printf("robo clk =	%u (%#x) [CH1]\n", clk_info.clk_robo, clk_info.clk_robo);
    437  1.1  matt 	printf("usb2 clk =	%u (%#x) [CH2]\n", clk_info.clk_usb2, clk_info.clk_usb2);
    438  1.1  matt 	printf("iproc clk =	%u (%#x) [CH3]\n", clk_info.clk_iproc, clk_info.clk_iproc);
    439  1.1  matt 	printf("ddr clk =	%u (%#x)\n", clk_info.clk_ddr, clk_info.clk_ddr);
    440  1.1  matt 	printf("ddr mhz =	%u (%#x)\n", clk_info.clk_ddr_mhz, clk_info.clk_ddr_mhz);
    441  1.1  matt 	printf("cpu clk =	%u (%#x)\n", clk_info.clk_cpu, clk_info.clk_cpu);
    442  1.1  matt 	printf("apb clk =	%u (%#x)\n", clk_info.clk_apb, clk_info.clk_apb);
    443  1.1  matt 	printf("usb ref clk =	%u (%#x)\n", clk_info.clk_usb_ref, clk_info.clk_usb_ref);
    444  1.1  matt #endif
    445  1.1  matt }
    446  1.1  matt 
    447  1.1  matt void
    448  1.1  matt bcm53xx_bootstrap(vaddr_t iobase)
    449  1.1  matt {
    450  1.1  matt 	struct bcm53xx_chip_state bcs;
    451  1.1  matt 	int error;
    452  1.1  matt 
    453  1.1  matt #ifdef BCM53XX_CONSOLE_EARLY
    454  1.1  matt 	com_base = iobase + CCA_UART0_BASE;
    455  1.1  matt 	cn_tab = &bcm53xx_earlycons;
    456  1.1  matt #endif
    457  1.1  matt 
    458  1.1  matt 	bcm53xx_ioreg_bsh = (bus_space_handle_t) iobase;
    459  1.1  matt 	error = bus_space_map(bcm53xx_ioreg_bst, BCM53XX_IOREG_PBASE,
    460  1.1  matt 	    BCM53XX_IOREG_SIZE, 0, &bcm53xx_ioreg_bsh);
    461  1.1  matt 	if (error)
    462  1.1  matt 		panic("%s: failed to map BCM53xx %s registers: %d",
    463  1.1  matt 		    __func__, "io", error);
    464  1.1  matt 
    465  1.1  matt 	bcm53xx_armcore_bsh = (bus_space_handle_t) iobase + BCM53XX_IOREG_SIZE;
    466  1.1  matt 	error = bus_space_map(bcm53xx_armcore_bst, BCM53XX_ARMCORE_PBASE,
    467  1.1  matt 	    BCM53XX_ARMCORE_SIZE, 0, &bcm53xx_armcore_bsh);
    468  1.1  matt 	if (error)
    469  1.1  matt 		panic("%s: failed to map BCM53xx %s registers: %d",
    470  1.1  matt 		    __func__, "armcore", error);
    471  1.1  matt 
    472  1.1  matt 	curcpu()->ci_softc = &cpu_softc;
    473  1.1  matt 
    474  1.1  matt 	bcm53xx_get_chip_ioreg_state(&bcs, bcm53xx_ioreg_bst, bcm53xx_ioreg_bsh);
    475  1.1  matt 	bcm53xx_get_chip_armcore_state(&bcs, bcm53xx_armcore_bst, bcm53xx_armcore_bsh);
    476  1.1  matt 
    477  1.1  matt 	struct bcm53xx_clock_info * const clk = &clk_info;
    478  1.1  matt 
    479  1.1  matt 	bcm53xx_clock_init(clk);
    480  1.1  matt 	bcm53xx_lcpll_clock_init(clk, bcs.bcs_lcpll_control1,
    481  1.1  matt 	    bcs.bcs_lcpll_control2);
    482  1.1  matt 	bcm53xx_genpll_clock_init(clk, bcs.bcs_genpll_control5,
    483  1.1  matt 	    bcs.bcs_genpll_control6, bcs.bcs_genpll_control7);
    484  1.1  matt 	bcm53xx_usb_clock_init(clk, bcs.bcs_usb2_control);
    485  1.1  matt 	bcm53xx_get_ddr_freq(clk, bcs.bcs_ddr_phy_ctl_pll_status,
    486  1.1  matt 	    bcs.bcs_ddr_phy_ctl_pll_dividers);
    487  1.1  matt 	bcm53xx_get_cpu_freq(clk, bcs.bcs_armcore_clk_pllarma,
    488  1.1  matt 	    bcs.bcs_armcore_clk_pllarmb, bcs.bcs_armcore_clk_policy);
    489  1.1  matt 
    490  1.1  matt 	curcpu()->ci_data.cpu_cc_freq = clk->clk_cpu;
    491  1.2  matt 
    492  1.2  matt 	arml2cc_init(bcm53xx_armcore_bst, bcm53xx_armcore_bsh, ARMCORE_L2C_BASE);
    493  1.1  matt }
    494  1.1  matt 
    495  1.1  matt #ifdef MULTIPROCESSOR
    496  1.1  matt void
    497  1.1  matt bcm53xx_cpu_hatch(struct cpu_info *ci)
    498  1.1  matt {
    499  1.1  matt 	a9tmr_init_cpu_clock(ci);
    500  1.1  matt }
    501  1.1  matt #endif
    502  1.1  matt 
    503  1.1  matt void
    504  1.1  matt bcm53xx_device_register(device_t self, void *aux)
    505  1.1  matt {
    506  1.1  matt 	prop_dictionary_t dict = device_properties(self);
    507  1.1  matt 
    508  1.1  matt 	if (device_is_a(self, "armperiph")
    509  1.1  matt 	    && device_is_a(device_parent(self), "mainbus")) {
    510  1.1  matt 		/*
    511  1.1  matt 		 * XXX KLUDGE ALERT XXX
    512  1.1  matt 		 * The iot mainbus supplies is completely wrong since it scales
    513  1.1  matt 		 * addresses by 2.  The simpliest remedy is to replace with our
    514  1.1  matt 		 * bus space used for the armcore regisers (which armperiph uses).
    515  1.1  matt 		 */
    516  1.1  matt 		struct mainbus_attach_args * const mb = aux;
    517  1.1  matt 		mb->mb_iot = bcm53xx_armcore_bst;
    518  1.1  matt 		return;
    519  1.1  matt 	}
    520  1.1  matt 
    521  1.1  matt 	/*
    522  1.1  matt 	 * We need to tell the A9 Global/Watchdog Timer
    523  1.1  matt 	 * what frequency it runs at.
    524  1.1  matt 	 */
    525  1.1  matt 	if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) {
    526  1.1  matt 		/*
    527  1.1  matt 		 * This clock always runs at (arm_clk div 2) and only goes
    528  1.1  matt 		 * to timers that are part of the A9 MP core subsystem.
    529  1.1  matt 		 */
    530  1.1  matt                 prop_dictionary_set_uint32(dict, "frequency",
    531  1.1  matt 		    clk_info.clk_cpu / 2);
    532  1.1  matt 		return;
    533  1.1  matt 	}
    534  1.1  matt }
    535