| /* |
| * 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) |
| { |
| /* Enable xLNBIAS signal on GPIO (19, 20) */ |
| ar7240_reg_wr (AR7240_GPIO_FUNC4, ((ar7240_reg_rd(AR7240_GPIO_FUNC4) & 0x00ffffff)) | 0x2f000000); |
| ar7240_reg_wr (AR7240_GPIO_FUNC5, ((ar7240_reg_rd(AR7240_GPIO_FUNC5) & 0xffffff00)) | 0x2e); |
| ar7240_reg_wr (AR7240_GPIO_OE, (ar7240_reg_rd(AR7240_GPIO_OE) & 0xffe7ffff)); |
| |
| #if 0 |
| /* Disable clock obs */ |
| ar7240_reg_wr (AR7240_GPIO_FUNC, (ar7240_reg_rd(AR7240_GPIO_FUNC) & 0xffe7e0ff)); |
| /* Enable eth Switch LEDs */ |
| #ifdef CONFIG_K31 |
| ar7240_reg_wr (AR7240_GPIO_FUNC, (ar7240_reg_rd(AR7240_GPIO_FUNC) | 0xd8)); |
| #else |
| ar7240_reg_wr (AR7240_GPIO_FUNC, (ar7240_reg_rd(AR7240_GPIO_FUNC) | 0xfa)); |
| #endif |
| #endif |
| } |
| |
| 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) |
| { |
| unsigned int type, reg32; |
| |
| type = wasp_ddr_initial_config(CFG_DDR_REFRESH_VAL); |
| |
| /* Take WMAC out of reset */ |
| reg32 = ar7240_reg_rd(AR7240_RESET); |
| reg32 = reg32 & ~AR7240_RESET_WMAC; |
| ar7240_reg_wr_nf(AR7240_RESET, reg32); |
| |
| /* Switching regulator settings */ |
| ar7240_reg_wr_nf(0x18116c40, 0x633c8176); /* AR_PHY_PMU1 */ |
| #if !defined(CONFIG_ATH_NAND_FL) |
| if (ar7240_reg_rd(AR7240_REV_ID) & 0xf) { |
| if (type == 2) { |
| // ddr1 |
| ar7240_reg_wr_nf(0x18116c44, 0x10000000); /* AR_PHY_PMU2 */ |
| } else { |
| // ddr2 & sdram |
| ar7240_reg_wr_nf(0x18116c44, 0x10380000); /* AR_PHY_PMU2 */ |
| } |
| } else { |
| ar7240_reg_wr_nf(0x18116c44, 0x10380000); /* AR_PHY_PMU2 */ |
| } |
| #endif |
| |
| wasp_usb_initial_config(); |
| |
| 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 REH132\n"); |
| #endif |
| #endif |
| #if CONFIG_AP123 |
| prmsg("U-boot AP123\n"); |
| #elif CONFIG_MI124 |
| prmsg("U-boot MI124\n"); |
| #else |
| prmsg("U-boot REH132\n"); |
| #endif |
| return 0; |
| } |