blob: da3223c835f8a37de9fdce0dc5ce5102d795df56 [file] [log] [blame]
/*
* Copyright (c) 2013 Qualcomm Atheros, Inc.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <common.h>
#include <command.h>
#include <asm/mipsregs.h>
#include <asm/addrspace.h>
#include <config.h>
#include <version.h>
#include "ar7240_soc.h"
extern int wasp_ddr_initial_config(uint32_t refresh);
extern int ar7240_ddr_find_size(void);
#ifdef COMPRESSED_UBOOT
# define prmsg(...)
#else
# define prmsg printf
#endif
void
wasp_usb_initial_config(void)
{
#define unset(a) (~(a))
if ((ar7240_reg_rd(WASP_BOOTSTRAP_REG) & WASP_REF_CLK_25) == 0) {
ar7240_reg_wr_nf(AR934X_SWITCH_CLOCK_SPARE,
ar7240_reg_rd(AR934X_SWITCH_CLOCK_SPARE) |
SWITCH_CLOCK_SPARE_USB_REFCLK_FREQ_SEL_SET(2));
} else {
ar7240_reg_wr_nf(AR934X_SWITCH_CLOCK_SPARE,
ar7240_reg_rd(AR934X_SWITCH_CLOCK_SPARE) |
SWITCH_CLOCK_SPARE_USB_REFCLK_FREQ_SEL_SET(5));
}
udelay(1000);
ar7240_reg_wr(AR7240_RESET,
ar7240_reg_rd(AR7240_RESET) |
RST_RESET_USB_PHY_SUSPEND_OVERRIDE_SET(1));
udelay(1000);
ar7240_reg_wr(AR7240_RESET,
ar7240_reg_rd(AR7240_RESET) &
unset(RST_RESET_USB_PHY_RESET_SET(1)));
udelay(1000);
ar7240_reg_wr(AR7240_RESET,
ar7240_reg_rd(AR7240_RESET) &
unset(RST_RESET_USB_PHY_ARESET_SET(1)));
udelay(1000);
ar7240_reg_wr(AR7240_RESET,
ar7240_reg_rd(AR7240_RESET) &
unset(RST_RESET_USB_HOST_RESET_SET(1)));
udelay(1000);
if ((ar7240_reg_rd(AR7240_REV_ID) & 0xf) == 0) {
/* Only for WASP 1.0 */
ar7240_reg_wr(0xb8116c84 ,
ar7240_reg_rd(0xb8116c84) & unset(1<<20));
}
}
void wasp_gpio_config(void)
{
/* disable the CLK_OBS on GPIO_4 and set GPIO4 as input */
ar7240_reg_rmw_clear(GPIO_OE_ADDRESS, (1 << 4));
ar7240_reg_rmw_clear(GPIO_OUT_FUNCTION1_ADDRESS, GPIO_OUT_FUNCTION1_ENABLE_GPIO_4_MASK);
ar7240_reg_rmw_set(GPIO_OUT_FUNCTION1_ADDRESS, GPIO_OUT_FUNCTION1_ENABLE_GPIO_4_SET(0x80));
ar7240_reg_rmw_set(GPIO_OE_ADDRESS, (1 << 4));
}
void ath_set_tuning_caps(void)
{
typedef struct {
u_int8_t pad[0x28],
params_for_tuning_caps[2],
featureEnable;
} __attribute__((__packed__)) ar9300_eeprom_t;
ar9300_eeprom_t *eep = (ar9300_eeprom_t *)WLANCAL;
uint32_t val;
val = 0;
/* checking feature enable bit 6 and caldata is valid */
if ((eep->featureEnable & 0x40) && (eep->pad[0x0] != 0xff)) {
/* xtal_capin -bit 17:23 and xtag_capout -bit 24:30*/
val = (eep->params_for_tuning_caps[0] & 0x7f) << 17;
val |= (eep->params_for_tuning_caps[0] & 0x7f) << 24;
} else {
/* default when no caldata available*/
/* checking clock in bit 4 */
if (ar7240_reg_rd(RST_BOOTSTRAP_ADDRESS) & 0x10) {
val = (0x1020 << 17); /*default 0x2040 for 40Mhz clock*/
} else {
val = (0x2040 << 17); /*default 0x4080 for 25Mhz clock*/
}
}
val |= (ar7240_reg_rd(XTAL_ADDRESS) & (((1 << 17) - 1) | (1 << 31)));
ar7240_reg_wr(XTAL_ADDRESS, val);
prmsg("Setting 0xb8116290 to 0x%x\n", val);
return;
}
int
wasp_mem_config(void)
{
#ifdef CONFIG_AP123
extern void ath_ddr_tap_cal(void);
#endif
unsigned int type, reg32;
type = wasp_ddr_initial_config(CFG_DDR_REFRESH_VAL);
#ifdef CONFIG_AP123
ath_ddr_tap_cal();
#ifndef COMPRESSED_UBOOT
printf("Tap value selected = 0x%x [0x%x - 0x%x]\n",
ar7240_reg_rd(AR7240_DDR_TAP_CONTROL0),
ar7240_reg_rd(0xbd007f10), ar7240_reg_rd(0xbd007f14));
#endif
#endif
/* Take WMAC out of reset */
reg32 = ar7240_reg_rd(AR7240_RESET);
reg32 = reg32 & ~AR7240_RESET_WMAC;
ar7240_reg_wr_nf(AR7240_RESET, reg32);
#if !defined(CONFIG_ATH_NAND_BR)
/* Switching regulator settings */
ar7240_reg_wr_nf(0x18116c40, 0x633c8176); /* AR_PHY_PMU1 */
ar7240_reg_wr_nf(0x18116c44, 0x10380000); /* AR_PHY_PMU2 */
wasp_usb_initial_config();
#endif /* !defined(CONFIG_ATH_NAND_BR) */
wasp_gpio_config();
ath_set_tuning_caps(); /* Needed here not to mess with Ethernet clocks */
reg32 = ar7240_ddr_find_size();
return reg32;
}
long int initdram(int board_type)
{
return (wasp_mem_config());
}
#ifdef COMPRESSED_UBOOT
int checkboard(char *s)
#else
int checkboard(void)
#endif
{
#ifdef COMPRESSED_UBOOT
#if CONFIG_AP123
strcpy(s, "U-boot AP123\n");
#elif CONFIG_MI124
strcpy(s, "U-boot MI124\n");
#else
strcpy(s, "U-boot DB120\n");
#endif
#endif
#if CONFIG_AP123
prmsg("U-boot AP123\n");
#elif CONFIG_MI124
prmsg("U-boot MI124\n");
#else
prmsg("U-boot DB120\n");
#endif
return 0;
}