2 * Copyright (c) 2010 Adrian Chadd
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
39 #include <sys/reboot.h>
42 #include <vm/vm_page.h>
44 #include <net/ethernet.h>
46 #include <machine/clock.h>
47 #include <machine/cpu.h>
48 #include <machine/cpuregs.h>
49 #include <machine/hwfunc.h>
50 #include <machine/md_var.h>
51 #include <machine/trap.h>
52 #include <machine/vmparam.h>
54 #include <mips/atheros/ar71xxreg.h>
55 #include <mips/atheros/ar71xx_cpudef.h>
56 #include <mips/atheros/ar71xx_chip.h>
57 #include <mips/atheros/ar91xxreg.h>
58 #include <mips/atheros/ar91xx_chip.h>
60 #include <mips/sentry5/s5reg.h>
63 ar91xx_chip_detect_mem_size(void)
68 ar91xx_chip_detect_sys_frequency(void)
74 u_ar71xx_refclk = AR91XX_BASE_FREQ;
76 pll = ATH_READ_REG(AR91XX_PLL_REG_CPU_CONFIG);
78 div = ((pll >> AR91XX_PLL_DIV_SHIFT) & AR91XX_PLL_DIV_MASK);
79 freq = div * AR91XX_BASE_FREQ;
80 u_ar71xx_cpu_freq = freq;
82 div = ((pll >> AR91XX_DDR_DIV_SHIFT) & AR91XX_DDR_DIV_MASK) + 1;
83 u_ar71xx_ddr_freq = freq / div;
85 div = (((pll >> AR91XX_AHB_DIV_SHIFT) & AR91XX_AHB_DIV_MASK) + 1) * 2;
86 u_ar71xx_ahb_freq = u_ar71xx_cpu_freq / div;
87 u_ar71xx_uart_freq = u_ar71xx_cpu_freq / div;
88 u_ar71xx_wdt_freq = u_ar71xx_cpu_freq / div;
92 ar91xx_chip_device_stop(uint32_t mask)
96 reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
97 ATH_WRITE_REG(AR91XX_RESET_REG_RESET_MODULE, reg | mask);
101 ar91xx_chip_device_start(uint32_t mask)
105 reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
106 ATH_WRITE_REG(AR91XX_RESET_REG_RESET_MODULE, reg & ~mask);
110 ar91xx_chip_device_stopped(uint32_t mask)
114 reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
115 return ((reg & mask) == mask);
119 ar91xx_chip_set_pll_ge(int unit, int speed, uint32_t pll)
124 ar71xx_write_pll(AR91XX_PLL_REG_ETH_CONFIG,
125 AR91XX_PLL_REG_ETH0_INT_CLOCK, pll,
126 AR91XX_ETH0_PLL_SHIFT);
129 ar71xx_write_pll(AR91XX_PLL_REG_ETH_CONFIG,
130 AR91XX_PLL_REG_ETH1_INT_CLOCK, pll,
131 AR91XX_ETH1_PLL_SHIFT);
134 printf("%s: invalid PLL set for arge unit: %d\n",
141 ar91xx_chip_ddr_flush_ge(int unit)
146 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0);
149 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1);
152 printf("%s: invalid DDR flush for arge unit: %d\n",
159 ar91xx_chip_ddr_flush_ip2(void)
162 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_WMAC);
167 ar91xx_chip_get_eth_pll(unsigned int mac, int speed)
173 pll = AR91XX_PLL_VAL_10;
176 pll = AR91XX_PLL_VAL_100;
179 pll = AR91XX_PLL_VAL_1000;
182 printf("%s%d: invalid speed %d\n", __func__, mac, speed);
190 ar91xx_chip_init_usb_peripheral(void)
193 ar71xx_device_stop(AR91XX_RST_RESET_MODULE_USBSUS_OVERRIDE);
196 ar71xx_device_start(RST_RESET_USB_HOST);
199 ar71xx_device_start(RST_RESET_USB_PHY);
203 ar71xx_device_stop(AR91XX_RST_RESET_MODULE_AMBA2WMAC);
206 ar71xx_device_start(AR91XX_RST_RESET_MODULE_AMBA2WMAC);
210 struct ar71xx_cpu_def ar91xx_chip_def = {
211 &ar91xx_chip_detect_mem_size,
212 &ar91xx_chip_detect_sys_frequency,
213 &ar91xx_chip_device_stop,
214 &ar91xx_chip_device_start,
215 &ar91xx_chip_device_stopped,
216 &ar91xx_chip_set_pll_ge,
217 &ar71xx_chip_set_mii_speed,
218 &ar71xx_chip_set_mii_if,
219 &ar91xx_chip_ddr_flush_ge,
220 &ar91xx_chip_get_eth_pll,
221 &ar91xx_chip_ddr_flush_ip2,
222 &ar91xx_chip_init_usb_peripheral,