Detect SoC type based on device ID and board configuration data. Signed-off-by: Sergey Ryazanov <ryazanov.s.a@xxxxxxxxx> --- Changes since v1: - rename MIPS machine ar231x -> ath25 - rename dev_type -> soc_type arch/mips/ath25/ar2315.c | 22 +++++++++++++++++++++- arch/mips/ath25/ar5312.c | 22 ++++++++++++++++++++++ arch/mips/ath25/devices.c | 17 ++++++++++++++++- arch/mips/ath25/devices.h | 16 ++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/arch/mips/ath25/ar2315.c b/arch/mips/ath25/ar2315.c index d3ff812..f239035 100644 --- a/arch/mips/ath25/ar2315.c +++ b/arch/mips/ath25/ar2315.c @@ -22,6 +22,7 @@ #include <asm/time.h> #include <ar2315_regs.h> +#include <ath25_platform.h> #include <ath25.h> #include "devices.h" @@ -237,7 +238,7 @@ void __init ar2315_plat_mem_setup(void) void __init ar2315_prom_init(void) { - u32 memsize, memcfg; + u32 memsize, memcfg, devid; memcfg = ath25_read_reg(AR2315_MEM_CFG); memsize = 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_DATA_WIDTH); @@ -245,6 +246,25 @@ void __init ar2315_prom_init(void) memsize <<= 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_ROW_WIDTH); memsize <<= 3; add_memory_region(0, memsize, BOOT_MEM_RAM); + + /* Detect the hardware based on the device ID */ + devid = ath25_read_reg(AR2315_SREV) & AR2315_REV_CHIP; + switch (devid) { + case 0x91: /* Need to check */ + ath25_soc = ATH25_SOC_AR2318; + break; + case 0x90: + ath25_soc = ATH25_SOC_AR2317; + break; + case 0x87: + ath25_soc = ATH25_SOC_AR2316; + break; + case 0x86: + default: + ath25_soc = ATH25_SOC_AR2315; + break; + } + ath25_board.devid = devid; } void __init ar2315_arch_init(void) diff --git a/arch/mips/ath25/ar5312.c b/arch/mips/ath25/ar5312.c index 2d66665..faa0633 100644 --- a/arch/mips/ath25/ar5312.c +++ b/arch/mips/ath25/ar5312.c @@ -22,6 +22,7 @@ #include <asm/time.h> #include <ar5312_regs.h> +#include <ath25_platform.h> #include <ath25.h> #include "devices.h" @@ -162,10 +163,25 @@ ar5312_flash_limit = (u8 *)KSEG1ADDR(AR5312_FLASH + 0x800000); void __init ar5312_init_devices(void) { + struct ath25_boarddata *config; + ar5312_flash_init(); /* Locate board/radio config data */ ath25_find_config(ar5312_flash_limit); + config = ath25_board.config; + + /* AR2313 has CPU minor rev. 10 */ + if ((current_cpu_data.processor_id & 0xff) == 0x0a) + ath25_soc = ATH25_SOC_AR2313; + + /* AR2312 shares the same Silicon ID as AR5312 */ + else if (config->flags & BD_ISCASPER) + ath25_soc = ATH25_SOC_AR2312; + + /* Everything else is probably AR5312 or compatible */ + else + ath25_soc = ATH25_SOC_AR5312; } static void ar5312_restart(char *command) @@ -262,6 +278,7 @@ void __init ar5312_plat_mem_setup(void) void __init ar5312_prom_init(void) { u32 memsize, memcfg, bank0_ac, bank1_ac; + u32 devid; /* Detect memory size */ memcfg = ath25_read_reg(AR5312_MEM_CFG1); @@ -271,6 +288,11 @@ void __init ar5312_prom_init(void) (bank1_ac ? (1 << (bank1_ac + 1)) : 0); memsize <<= 20; add_memory_region(0, memsize, BOOT_MEM_RAM); + + devid = ath25_read_reg(AR5312_REV); + devid >>= AR5312_REV_WMAC_MIN_S; + devid &= AR5312_REV_CHIP; + ath25_board.devid = (u16)devid; } void __init ar5312_arch_init(void) diff --git a/arch/mips/ath25/devices.c b/arch/mips/ath25/devices.c index d24dbb1..6218547 100644 --- a/arch/mips/ath25/devices.c +++ b/arch/mips/ath25/devices.c @@ -9,10 +9,25 @@ #include "ar2315.h" struct ar231x_board_config ath25_board; +enum ath25_soc_type ath25_soc = ATH25_SOC_UNKNOWN; + +static const char * const soc_type_strings[] = { + [ATH25_SOC_AR5312] = "Atheros AR5312", + [ATH25_SOC_AR2312] = "Atheros AR2312", + [ATH25_SOC_AR2313] = "Atheros AR2313", + [ATH25_SOC_AR2315] = "Atheros AR2315", + [ATH25_SOC_AR2316] = "Atheros AR2316", + [ATH25_SOC_AR2317] = "Atheros AR2317", + [ATH25_SOC_AR2318] = "Atheros AR2318", + [ATH25_SOC_UNKNOWN] = "Atheros (unknown)", +}; const char *get_system_type(void) { - return "Atheros (unknown)"; + if ((ath25_soc >= ARRAY_SIZE(soc_type_strings)) || + !soc_type_strings[ath25_soc]) + return soc_type_strings[ATH25_SOC_UNKNOWN]; + return soc_type_strings[ath25_soc]; } void __init ath25_serial_setup(u32 mapbase, int irq, unsigned int uartclk) diff --git a/arch/mips/ath25/devices.h b/arch/mips/ath25/devices.h index 10f196d..8555e32 100644 --- a/arch/mips/ath25/devices.h +++ b/arch/mips/ath25/devices.h @@ -3,6 +3,22 @@ #include <linux/cpu.h> +enum ath25_soc_type { + /* handled by ar5312.c */ + ATH25_SOC_AR2312, + ATH25_SOC_AR2313, + ATH25_SOC_AR5312, + + /* handled by ar2315.c */ + ATH25_SOC_AR2315, + ATH25_SOC_AR2316, + ATH25_SOC_AR2317, + ATH25_SOC_AR2318, + + ATH25_SOC_UNKNOWN +}; + +extern enum ath25_soc_type ath25_soc; extern struct ar231x_board_config ath25_board; extern void (*ath25_irq_dispatch)(void); -- 1.8.5.5