2010-08-19 11:53:55 +00:00
|
|
|
/*-
|
2017-11-27 15:07:26 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2010-08-19 11:53:55 +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:53:55 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
#include <net/ethernet.h>
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +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:53:55 +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
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
#include <mips/atheros/ar71xxreg.h>
|
|
|
|
#include <mips/atheros/ar724xreg.h>
|
|
|
|
|
|
|
|
#include <mips/atheros/ar71xx_cpudef.h>
|
2011-03-31 02:36:22 +00:00
|
|
|
#include <mips/atheros/ar71xx_setup.h>
|
2012-05-02 01:21:57 +00:00
|
|
|
#include <mips/atheros/ar71xx_chip.h>
|
2010-08-19 11:53:55 +00:00
|
|
|
#include <mips/atheros/ar724x_chip.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar724x_chip_detect_mem_size(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar724x_chip_detect_sys_frequency(void)
|
|
|
|
{
|
|
|
|
uint32_t pll;
|
|
|
|
uint32_t freq;
|
|
|
|
uint32_t div;
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2013-10-15 01:35:48 +00:00
|
|
|
u_ar71xx_mdio_freq = u_ar71xx_refclk = AR724X_BASE_FREQ;
|
2013-03-27 03:33:19 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
pll = ATH_READ_REG(AR724X_PLL_REG_CPU_CONFIG);
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
div = ((pll >> AR724X_PLL_DIV_SHIFT) & AR724X_PLL_DIV_MASK);
|
|
|
|
freq = div * AR724X_BASE_FREQ;
|
|
|
|
|
|
|
|
div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK);
|
|
|
|
freq *= div;
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
u_ar71xx_cpu_freq = freq;
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
|
|
|
|
u_ar71xx_ddr_freq = freq / div;
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
|
|
|
|
u_ar71xx_ahb_freq = u_ar71xx_cpu_freq / div;
|
2013-07-21 03:52:52 +00:00
|
|
|
u_ar71xx_wdt_freq = u_ar71xx_cpu_freq / div;
|
|
|
|
u_ar71xx_uart_freq = u_ar71xx_cpu_freq / div;
|
2010-08-19 11:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar724x_chip_device_stop(uint32_t mask)
|
|
|
|
{
|
|
|
|
uint32_t mask_inv, reg;
|
|
|
|
|
|
|
|
mask_inv = mask & AR724X_RESET_MODULE_USB_OHCI_DLL;
|
|
|
|
reg = ATH_READ_REG(AR724X_RESET_REG_RESET_MODULE);
|
|
|
|
reg |= mask;
|
|
|
|
reg &= ~mask_inv;
|
|
|
|
ATH_WRITE_REG(AR724X_RESET_REG_RESET_MODULE, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ar724x_chip_device_start(uint32_t mask)
|
|
|
|
{
|
|
|
|
uint32_t mask_inv, reg;
|
|
|
|
|
|
|
|
mask_inv = mask & AR724X_RESET_MODULE_USB_OHCI_DLL;
|
|
|
|
reg = ATH_READ_REG(AR724X_RESET_REG_RESET_MODULE);
|
|
|
|
reg &= ~mask;
|
|
|
|
reg |= mask_inv;
|
|
|
|
ATH_WRITE_REG(AR724X_RESET_REG_RESET_MODULE, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ar724x_chip_device_stopped(uint32_t mask)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = ATH_READ_REG(AR724X_RESET_REG_RESET_MODULE);
|
|
|
|
return ((reg & mask) == mask);
|
|
|
|
}
|
|
|
|
|
2012-03-17 07:25:23 +00:00
|
|
|
static void
|
|
|
|
ar724x_chip_set_mii_speed(uint32_t unit, uint32_t speed)
|
|
|
|
{
|
2012-03-17 07:29:11 +00:00
|
|
|
|
2012-03-17 07:25:23 +00:00
|
|
|
/* XXX TODO */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-02 01:21:57 +00:00
|
|
|
/*
|
|
|
|
* XXX TODO: set the PLL for arge0 only on AR7242.
|
|
|
|
* The PLL/clock requirements are different.
|
|
|
|
*
|
|
|
|
* Otherwise, it's a NULL function for AR7240, AR7241 and
|
|
|
|
* AR7242 arge1.
|
|
|
|
*/
|
2010-08-19 11:53:55 +00:00
|
|
|
static void
|
2012-05-02 04:51:43 +00:00
|
|
|
ar724x_chip_set_pll_ge(int unit, int speed, uint32_t pll)
|
2010-08-19 11:53:55 +00:00
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2011-11-27 11:15:59 +00:00
|
|
|
switch (unit) {
|
|
|
|
case 0:
|
2011-12-13 05:13:51 +00:00
|
|
|
/* XXX TODO */
|
2011-11-27 11:15:59 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-12-13 05:13:51 +00:00
|
|
|
/* XXX TODO */
|
2011-11-27 11:15:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: invalid PLL set for arge unit: %d\n",
|
|
|
|
__func__, unit);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-19 11:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-04 03:05:57 +00:00
|
|
|
ar724x_chip_ddr_flush(ar71xx_flush_ddr_id_t id)
|
2010-08-19 11:53:55 +00:00
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2015-07-04 03:05:57 +00:00
|
|
|
switch (id) {
|
|
|
|
case AR71XX_CPU_DDR_FLUSH_GE0:
|
2011-11-27 11:15:59 +00:00
|
|
|
ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE0);
|
|
|
|
break;
|
2015-07-04 03:05:57 +00:00
|
|
|
case AR71XX_CPU_DDR_FLUSH_GE1:
|
2011-11-27 11:15:59 +00:00
|
|
|
ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_GE1);
|
|
|
|
break;
|
2015-07-04 03:05:57 +00:00
|
|
|
case AR71XX_CPU_DDR_FLUSH_USB:
|
|
|
|
ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_USB);
|
|
|
|
break;
|
|
|
|
case AR71XX_CPU_DDR_FLUSH_PCIE:
|
|
|
|
ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_PCIE);
|
|
|
|
break;
|
2011-11-27 11:15:59 +00:00
|
|
|
default:
|
2015-07-04 03:05:57 +00:00
|
|
|
printf("%s: invalid DDR flush id (%d)\n", __func__, id);
|
|
|
|
break;
|
2011-11-27 11:15:59 +00:00
|
|
|
}
|
2010-08-19 11:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
ar724x_chip_get_eth_pll(unsigned int mac, int speed)
|
|
|
|
{
|
2011-12-13 05:13:51 +00:00
|
|
|
|
2012-05-02 04:51:43 +00:00
|
|
|
return (0);
|
2010-08-19 11:53:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 02:36:22 +00:00
|
|
|
static void
|
|
|
|
ar724x_chip_init_usb_peripheral(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (ar71xx_soc) {
|
2011-12-13 05:13:51 +00:00
|
|
|
case AR71XX_SOC_AR7240:
|
|
|
|
ar71xx_device_stop(AR724X_RESET_MODULE_USB_OHCI_DLL |
|
|
|
|
AR724X_RESET_USB_HOST);
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
ar71xx_device_start(AR724X_RESET_MODULE_USB_OHCI_DLL |
|
|
|
|
AR724X_RESET_USB_HOST);
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WAR for HW bug. Here it adjusts the duration
|
|
|
|
* between two SOFS.
|
|
|
|
*/
|
|
|
|
ATH_WRITE_REG(AR71XX_USB_CTRL_FLADJ,
|
|
|
|
(3 << USB_CTRL_FLADJ_A0_SHIFT));
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
break;
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
case AR71XX_SOC_AR7241:
|
|
|
|
case AR71XX_SOC_AR7242:
|
|
|
|
ar71xx_device_start(AR724X_RESET_MODULE_USB_OHCI_DLL);
|
|
|
|
DELAY(100);
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
ar71xx_device_start(AR724X_RESET_USB_HOST);
|
|
|
|
DELAY(100);
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
ar71xx_device_start(AR724X_RESET_USB_PHY);
|
|
|
|
DELAY(100);
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
break;
|
2011-03-31 02:36:22 +00:00
|
|
|
|
2011-12-13 05:13:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-03-31 02:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-19 11:53:55 +00:00
|
|
|
struct ar71xx_cpu_def ar724x_chip_def = {
|
2012-03-17 07:29:11 +00:00
|
|
|
&ar724x_chip_detect_mem_size,
|
|
|
|
&ar724x_chip_detect_sys_frequency,
|
|
|
|
&ar724x_chip_device_stop,
|
|
|
|
&ar724x_chip_device_start,
|
|
|
|
&ar724x_chip_device_stopped,
|
|
|
|
&ar724x_chip_set_pll_ge,
|
2012-03-17 07:25:23 +00:00
|
|
|
&ar724x_chip_set_mii_speed,
|
2012-05-02 01:21:57 +00:00
|
|
|
&ar71xx_chip_set_mii_if,
|
2012-03-17 07:29:11 +00:00
|
|
|
&ar724x_chip_get_eth_pll,
|
2015-07-04 03:05:57 +00:00
|
|
|
&ar724x_chip_ddr_flush,
|
2011-03-31 02:36:22 +00:00
|
|
|
&ar724x_chip_init_usb_peripheral
|
2010-08-19 11:53:55 +00:00
|
|
|
};
|