X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/c4d54fb8919c019077cf8afc8b5e8a6e407a9f36..bedf02f2fd081428a8a79bed6500c7301174de71:/target/linux/adm5120-2.6/files/arch/mips/adm5120/adm5120_info.c diff --git a/target/linux/adm5120-2.6/files/arch/mips/adm5120/adm5120_info.c b/target/linux/adm5120-2.6/files/arch/mips/adm5120/adm5120_info.c index 85e0df622..17d82faaf 100644 --- a/target/linux/adm5120-2.6/files/arch/mips/adm5120/adm5120_info.c +++ b/target/linux/adm5120-2.6/files/arch/mips/adm5120/adm5120_info.c @@ -1,121 +1,93 @@ /* - * Copyright (C) 2007 OpenWrt.org - * Copyright (C) Gabor Juhos - * - * 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. + * $Id$ + * + * Copyright (C) 2007 OpenWrt.org + * Copyright (C) 2007 Gabor Juhos + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * */ #include -#include #include #include #include #include -#include -#include +#include +#include +#include -/* boot loaders specific definitions */ -#define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */ +unsigned int adm5120_product_code; +unsigned int adm5120_revision; +unsigned int adm5120_package; +unsigned int adm5120_nand_boot; +unsigned long adm5120_speed; - -struct adm5120_info adm5120_info = { - .cpu_speed = CPU_SPEED_175, - .cpu_package = CPU_PACKAGE_PQFP, - .boot_loader = BOOT_LOADER_UNKNOWN, - .board_type = BOARD_TYPE_UNKNOWN -}; - -static char *boot_loader_names[BOOT_LOADER_LAST+1] = { - [BOOT_LOADER_UNKNOWN] = "Unknown", - [BOOT_LOADER_CFE] = "CFE", - [BOOT_LOADER_UBOOT] = "U-Boot", - [BOOT_LOADER_MYLOADER] = "MyLoader" -}; +#define SWITCH_READ(r) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r)) +#define SWITCH_WRITE(r,v) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))=(v) /* - * Boot loader detection routines + * CPU settings detection */ -static int __init detect_cfe(void) -{ - /* - * This method only works, when we are booted directly from the CFE. - */ - uint32_t cfe_handle = (uint32_t) fw_arg0; - uint32_t cfe_a1_val = (uint32_t) fw_arg1; - uint32_t cfe_entry = (uint32_t) fw_arg2; - uint32_t cfe_seal = (uint32_t) fw_arg3; - - /* Check for CFE by finding the CFE magic number */ - if (cfe_seal != CFE_EPTSEAL) { - /* We are not booted from CFE */ - return 0; - } - - /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */ - if (cfe_a1_val != 0) { - return 0; - } - - /* The cfe_handle, and the cfe_entry must be kernel mode addresses */ - if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0)) { - return 0; - } - - return 1; -} - -static int __init detect_uboot(void) -{ - /* FIXME: not yet implemented */ - return 0; -} +#define CODE_GET_PC(c) ((c) & CODE_PC_MASK) +#define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK) +#define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK) +#define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK) +#define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0) -static int __init detect_myloader(void) +void adm5120_ndelay(u32 ns) { - struct mylo_system_params *sysp; - struct mylo_board_params *boardp; - struct mylo_partition_table *parts; + u32 t; - sysp = (struct mylo_system_params *)(MYLO_MIPS_SYS_PARAMS); - boardp = (struct mylo_board_params *)(MYLO_MIPS_BOARD_PARAMS); - parts = (struct mylo_partition_table *)(MYLO_MIPS_PARTITIONS); + SWITCH_WRITE(SWITCH_REG_TIMER, TIMER_PERIOD_DEFAULT); + SWITCH_WRITE(SWITCH_REG_TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM)); - /* Check for some magic numbers */ - if ((sysp->magic != MYLO_MAGIC_SYS_PARAMS) || - (boardp->magic != MYLO_MAGIC_BOARD_PARAMS) || - (parts->magic != MYLO_MAGIC_PARTITIONS)) - return 0; + t = (ns+640) / 640; + t &= TIMER_PERIOD_MASK; + SWITCH_WRITE(SWITCH_REG_TIMER, t | TIMER_TE); - return 1; -} + /* wait until the timer expires */ + do { + t = SWITCH_READ(SWITCH_REG_TIMER_INT); + } while ((t & TIMER_INT_TOS) == 0); -static int __init detect_bootloader(void) -{ - if (detect_cfe()) - return BOOT_LOADER_CFE; - - if (detect_uboot()) - return BOOT_LOADER_UBOOT; - - if (detect_myloader()) - return BOOT_LOADER_MYLOADER; - - return BOOT_LOADER_UNKNOWN; -} - -void __init adm5120_info_show(void) -{ - printk("adm5120: boot loader is %s\n", boot_loader_names[adm5120_info.boot_loader]); + /* leave the timer disabled */ + SWITCH_WRITE(SWITCH_REG_TIMER, TIMER_PERIOD_DEFAULT); + SWITCH_WRITE(SWITCH_REG_TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM)); } -void __init adm5120_info_init(void) +void __init adm5120_soc_init(void) { - adm5120_info.boot_loader = detect_bootloader(); - - adm5120_info_show(); + u32 code; + u32 clks; + + code = SWITCH_READ(SWITCH_REG_CODE); + + adm5120_product_code = CODE_GET_PC(code); + adm5120_revision = CODE_GET_REV(code); + adm5120_package = (CODE_GET_PK(code) == CODE_PK_BGA) ? + ADM5120_PACKAGE_BGA : ADM5120_PACKAGE_PQFP; + adm5120_nand_boot = CODE_GET_NAB(code); + + clks = CODE_GET_CLKS(code); + adm5120_speed = ADM5120_SPEED_175; + if (clks & 1) + adm5120_speed += 25000000; + if (clks & 2) + adm5120_speed += 50000000; }