2010-08-19 11:40:10 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2010 Adrian Chadd
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cons.h>
|
|
|
|
#include <sys/kdb.h>
|
|
|
|
#include <sys/reboot.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <net/ethernet.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/cpu.h>
|
2011-06-26 10:07:48 +00:00
|
|
|
#include <machine/cpuregs.h>
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <machine/hwfunc.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/trap.h>
|
|
|
|
#include <machine/vmparam.h>
|
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
#include <mips/atheros/ar71xxreg.h>
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <mips/atheros/ar71xx_cpudef.h>
|
2012-04-15 22:34:22 +00:00
|
|
|
#include <mips/atheros/ar71xx_chip.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
#include <mips/atheros/ar91xxreg.h>
|
2010-08-19 11:40:10 +00:00
|
|
|
#include <mips/atheros/ar91xx_chip.h>
|
|
|
|
|
2011-06-26 10:07:48 +00:00
|
|
|
#include <mips/sentry5/s5reg.h>
|
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
static void
|
|
|
|
ar91xx_chip_detect_mem_size(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar91xx_chip_detect_sys_frequency(void)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
uint32_t pll;
|
|
|
|
uint32_t freq;
|
|
|
|
uint32_t div;
|
|
|
|
|
|
|
|
pll = ATH_READ_REG(AR91XX_PLL_REG_CPU_CONFIG);
|
|
|
|
|
|
|
|
div = ((pll >> AR91XX_PLL_DIV_SHIFT) & AR91XX_PLL_DIV_MASK);
|
|
|
|
freq = div * AR91XX_BASE_FREQ;
|
|
|
|
u_ar71xx_cpu_freq = freq;
|
|
|
|
|
|
|
|
div = ((pll >> AR91XX_DDR_DIV_SHIFT) & AR91XX_DDR_DIV_MASK) + 1;
|
|
|
|
u_ar71xx_ddr_freq = freq / div;
|
|
|
|
|
|
|
|
div = (((pll >> AR91XX_AHB_DIV_SHIFT) & AR91XX_AHB_DIV_MASK) + 1) * 2;
|
|
|
|
u_ar71xx_ahb_freq = u_ar71xx_cpu_freq / div;
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar91xx_chip_device_stop(uint32_t mask)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
|
|
|
|
ATH_WRITE_REG(AR91XX_RESET_REG_RESET_MODULE, reg | mask);
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar91xx_chip_device_start(uint32_t mask)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
|
|
|
|
ATH_WRITE_REG(AR91XX_RESET_REG_RESET_MODULE, reg & ~mask);
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ar91xx_chip_device_stopped(uint32_t mask)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = ATH_READ_REG(AR91XX_RESET_REG_RESET_MODULE);
|
|
|
|
return ((reg & mask) == mask);
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-02 04:51:43 +00:00
|
|
|
ar91xx_chip_set_pll_ge(int unit, int speed, uint32_t pll)
|
2010-08-19 11:40:10 +00:00
|
|
|
{
|
2010-08-19 16:25:15 +00:00
|
|
|
|
2011-11-27 11:15:59 +00:00
|
|
|
switch (unit) {
|
|
|
|
case 0:
|
|
|
|
ar71xx_write_pll(AR91XX_PLL_REG_ETH_CONFIG,
|
|
|
|
AR91XX_PLL_REG_ETH0_INT_CLOCK, pll,
|
|
|
|
AR91XX_ETH0_PLL_SHIFT);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ar71xx_write_pll(AR91XX_PLL_REG_ETH_CONFIG,
|
|
|
|
AR91XX_PLL_REG_ETH1_INT_CLOCK, pll,
|
|
|
|
AR91XX_ETH1_PLL_SHIFT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: invalid PLL set for arge unit: %d\n",
|
|
|
|
__func__, unit);
|
|
|
|
return;
|
2010-08-19 16:25:15 +00:00
|
|
|
}
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-27 11:15:59 +00:00
|
|
|
ar91xx_chip_ddr_flush_ge(int unit)
|
2010-08-19 11:40:10 +00:00
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2011-11-27 11:15:59 +00:00
|
|
|
switch (unit) {
|
|
|
|
case 0:
|
|
|
|
ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_GE1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: invalid DDR flush for arge unit: %d\n",
|
|
|
|
__func__, unit);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 11:13:26 +00:00
|
|
|
static void
|
|
|
|
ar91xx_chip_ddr_flush_ip2(void)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2011-04-28 11:13:26 +00:00
|
|
|
ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_WMAC);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
static uint32_t
|
|
|
|
ar91xx_chip_get_eth_pll(unsigned int mac, int speed)
|
|
|
|
{
|
2012-05-02 04:51:43 +00:00
|
|
|
uint32_t pll;
|
|
|
|
|
|
|
|
switch(speed) {
|
|
|
|
case 10:
|
|
|
|
pll = AR91XX_PLL_VAL_10;
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
pll = AR91XX_PLL_VAL_100;
|
|
|
|
break;
|
|
|
|
case 1000:
|
|
|
|
pll = AR91XX_PLL_VAL_1000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s%d: invalid speed %d\n", __func__, mac, speed);
|
|
|
|
pll = 0;
|
|
|
|
}
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2012-05-02 04:51:43 +00:00
|
|
|
return (pll);
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar91xx_chip_init_usb_peripheral(void)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:40:10 +00:00
|
|
|
ar71xx_device_stop(AR91XX_RST_RESET_MODULE_USBSUS_OVERRIDE);
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
ar71xx_device_start(RST_RESET_USB_HOST);
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
ar71xx_device_start(RST_RESET_USB_PHY);
|
|
|
|
DELAY(100);
|
2011-03-13 08:46:58 +00:00
|
|
|
|
|
|
|
/* Wireless */
|
|
|
|
ar71xx_device_stop(AR91XX_RST_RESET_MODULE_AMBA2WMAC);
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
ar71xx_device_start(AR91XX_RST_RESET_MODULE_AMBA2WMAC);
|
|
|
|
DELAY(1000);
|
2010-08-19 11:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ar71xx_cpu_def ar91xx_chip_def = {
|
2011-12-13 05:13:51 +00:00
|
|
|
&ar91xx_chip_detect_mem_size,
|
|
|
|
&ar91xx_chip_detect_sys_frequency,
|
|
|
|
&ar91xx_chip_device_stop,
|
|
|
|
&ar91xx_chip_device_start,
|
|
|
|
&ar91xx_chip_device_stopped,
|
|
|
|
&ar91xx_chip_set_pll_ge,
|
2012-04-15 22:34:22 +00:00
|
|
|
&ar71xx_chip_set_mii_speed,
|
2012-05-02 01:21:57 +00:00
|
|
|
&ar71xx_chip_set_mii_if,
|
2011-12-13 05:13:51 +00:00
|
|
|
&ar91xx_chip_ddr_flush_ge,
|
|
|
|
&ar91xx_chip_get_eth_pll,
|
|
|
|
&ar91xx_chip_ddr_flush_ip2,
|
2010-08-19 11:40:10 +00:00
|
|
|
&ar91xx_chip_init_usb_peripheral,
|
|
|
|
};
|