allwinner: Detect and output current SoC
authorAndre Przywara <[email protected]>
Thu, 21 Jun 2018 23:47:08 +0000 (00:47 +0100)
committerAndre Przywara <[email protected]>
Thu, 28 Jun 2018 22:51:36 +0000 (23:51 +0100)
So far we already support booting on two different SoCs, and we will
shortly add a third, so add some code to determine the current SoC type.
This can be later used to runtime detect certain properties.

Also print the SoC name to the console, to give valuable debug information.

Signed-off-by: Andre Przywara <[email protected]>
plat/allwinner/common/sunxi_bl31_setup.c
plat/allwinner/common/sunxi_common.c
plat/allwinner/common/sunxi_private.h

index f5f91e3186ba8a39ad8861196d9b34e8bc79d559..e910ee5491816e4bae4565aadf024aafbf1e8f8e 100644 (file)
@@ -64,6 +64,22 @@ void bl31_plat_arch_setup(void)
 
 void bl31_platform_setup(void)
 {
+       const char *soc_name;
+       uint16_t soc_id = sunxi_read_soc_id();
+
+       switch (soc_id) {
+       case 0x1689:
+               soc_name = "A64/H64/R18";
+               break;
+       case 0x1718:
+               soc_name = "H5";
+               break;
+       default:
+               soc_name = "unknown";
+               break;
+       }
+       NOTICE("BL31: Detected Allwinner %s SoC (%04x)\n", soc_name, soc_id);
+
        generic_delay_timer_init();
 
        /* Configure the interrupt controller */
index 9069a17d2d1d62c9d5b8359638bc88fb4dcb3855..fc9bf20978fa1b588e5ac22d6dda6f499c7d166d 100644 (file)
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include <mmio.h>
 #include <platform.h>
 #include <platform_def.h>
 #include <sunxi_def.h>
@@ -54,3 +55,19 @@ void sunxi_configure_mmu_el3(int flags)
 
        enable_mmu_el3(0);
 }
+
+#define SRAM_VER_REG (SUNXI_SYSCON_BASE + 0x24)
+uint16_t sunxi_read_soc_id(void)
+{
+       uint32_t reg = mmio_read_32(SRAM_VER_REG);
+
+       /* Set bit 15 to prepare for the SOCID read. */
+       mmio_write_32(SRAM_VER_REG, reg | BIT(15));
+
+       reg = mmio_read_32(SRAM_VER_REG);
+
+       /* deactivate the SOCID access again */
+       mmio_write_32(SRAM_VER_REG, reg & ~BIT(15));
+
+       return reg >> 16;
+}
index b9f0fb41c24bae4210c2ef5cd783a26ef78f495b..e45f494ed289be00b5f22a0fbae05e23b5c0da15 100644 (file)
@@ -12,6 +12,7 @@ void sunxi_cpu_off(unsigned int cluster, unsigned int core);
 void sunxi_cpu_on(unsigned int cluster, unsigned int core);
 void sunxi_disable_secondary_cpus(unsigned int primary_cpu);
 
+uint16_t sunxi_read_soc_id(void);
 void sunxi_security_setup(void);
 
 #endif /* __SUNXI_PRIVATE_H__ */