diff mbox series

arm: stm32mp1: Set soc_type, soc_pkg, soc_rev env variables

Message ID 20210305141852.97101-1-marex@denx.de
State Superseded
Delegated to: Patrice Chotard
Headers show
Series arm: stm32mp1: Set soc_type, soc_pkg, soc_rev env variables | expand

Commit Message

Marek Vasut March 5, 2021, 2:18 p.m. UTC
Split up get_soc_name(), clean the decoding up a bit, and set up
environment variables which contain the SoC type, package, revision.
This is useful on SoMs, where multiple SoC options are populated.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
---
 arch/arm/mach-stm32mp/cpu.c | 105 ++++++++++++++++++------------------
 1 file changed, 53 insertions(+), 52 deletions(-)

Comments

Patrice Chotard March 9, 2021, 2:31 p.m. UTC | #1
Hi Marek

On 3/5/21 3:18 PM, Marek Vasut wrote:
> Split up get_soc_name(), clean the decoding up a bit, and set up
> environment variables which contain the SoC type, package, revision.
> This is useful on SoMs, where multiple SoC options are populated.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> ---
>  arch/arm/mach-stm32mp/cpu.c | 105 ++++++++++++++++++------------------
>  1 file changed, 53 insertions(+), 52 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index 3faa4ec18a4..887db9b5b0c 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -349,89 +349,78 @@ u32 get_cpu_package(void)
>  	return get_otp(BSEC_OTP_PKG, PKG_SHIFT, PKG_MASK);
>  }
>  
> -void get_soc_name(char name[SOC_NAME_SIZE])
> +static const char * const soc_type[] = {
> +	"????",
> +	"151C", "151A", "151F", "151D",
> +	"153C", "153A", "153F", "153D",
> +	"157C", "157A", "157F", "157D"
> +};
> +
> +static const char * const soc_pkg[] = { "??", "AD", "AC", "AB", "AA" };
> +static const char * const soc_rev[] = { "?", "A", "B", "Z" };
> +
> +static void get_cpu_string_offsets(unsigned int *type, unsigned int *pkg,
> +				   unsigned int *rev)
>  {
> -	char *cpu_s, *cpu_r, *pkg;
> +	u32 cpu_type = get_cpu_type();
> +	u32 ct = cpu_type & ~(BIT(7) | BIT(0));
> +	u32 cm = ((cpu_type & BIT(7)) >> 6) | (cpu_type & BIT(0));
> +	u32 cp = get_cpu_package();
>  
> -	/* MPUs Part Numbers */
> -	switch (get_cpu_type()) {
> -	case CPU_STM32MP157Fxx:
> -		cpu_s = "157F";
> -		break;
> -	case CPU_STM32MP157Dxx:
> -		cpu_s = "157D";
> -		break;
> -	case CPU_STM32MP157Cxx:
> -		cpu_s = "157C";
> -		break;
> -	case CPU_STM32MP157Axx:
> -		cpu_s = "157A";
> -		break;
> -	case CPU_STM32MP153Fxx:
> -		cpu_s = "153F";
> -		break;
> -	case CPU_STM32MP153Dxx:
> -		cpu_s = "153D";
> +	/* Bits 0 and 7 are the ACDF, 00:C 01:A 10:F 11:D */
> +	switch (ct) {
> +	case CPU_STM32MP151Cxx:
> +		*type = cm + 1;
>  		break;
>  	case CPU_STM32MP153Cxx:
> -		cpu_s = "153C";
> -		break;
> -	case CPU_STM32MP153Axx:
> -		cpu_s = "153A";
> -		break;
> -	case CPU_STM32MP151Fxx:
> -		cpu_s = "151F";
> -		break;
> -	case CPU_STM32MP151Dxx:
> -		cpu_s = "151D";
> +		*type = cm + 5;
>  		break;
> -	case CPU_STM32MP151Cxx:
> -		cpu_s = "151C";
> -		break;
> -	case CPU_STM32MP151Axx:
> -		cpu_s = "151A";
> +	case CPU_STM32MP157Cxx:
> +		*type = cm + 9;
>  		break;
>  	default:
> -		cpu_s = "????";
> +		*type = 0;
>  		break;
>  	}
>  
>  	/* Package */
> -	switch (get_cpu_package()) {
> +	switch (cp) {
>  	case PKG_AA_LBGA448:
> -		pkg = "AA";
> -		break;
>  	case PKG_AB_LBGA354:
> -		pkg = "AB";
> -		break;
>  	case PKG_AC_TFBGA361:
> -		pkg = "AC";
> -		break;
>  	case PKG_AD_TFBGA257:
> -		pkg = "AD";
> +		*pkg = cp;
>  		break;
>  	default:
> -		pkg = "??";
> +		pkg = 0;
>  		break;
>  	}
>  
> -	/* REVISION */
> +	/* Revision */
>  	switch (get_cpu_rev()) {
>  	case CPU_REVA:
> -		cpu_r = "A";
> +		*rev = 1;
>  		break;
>  	case CPU_REVB:
> -		cpu_r = "B";
> +		*rev = 2;
>  		break;
>  	case CPU_REVZ:
> -		cpu_r = "Z";
> +		*rev = 3;
>  		break;
>  	default:
> -		cpu_r = "?";
> +		*rev = 0;
>  		break;
>  	}
> +}
> +
> +void get_soc_name(char name[SOC_NAME_SIZE])
> +{
> +	unsigned int type, pkg, rev;
>  
> -	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r);
> +	get_cpu_string_offsets(&type, &pkg, &rev);
> +
> +	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s",
> +		 soc_type[type], soc_pkg[pkg], soc_rev[rev]);
>  }
>  
>  #if defined(CONFIG_DISPLAY_CPUINFO)
> @@ -620,11 +609,23 @@ static int setup_serial_number(void)
>  	return 0;
>  }
>  
> +static void setup_soc_type_pkg_rev(void)
> +{
> +	unsigned int type, pkg, rev;
> +
> +	get_cpu_string_offsets(&type, &pkg, &rev);
> +
> +	env_set("soc_type", soc_type[type]);
> +	env_set("soc_pkg", soc_pkg[pkg]);
> +	env_set("soc_rev", soc_rev[rev]);
> +}
> +
>  int arch_misc_init(void)
>  {
>  	setup_boot_mode();
>  	setup_mac_address();
>  	setup_serial_number();
> +	setup_soc_type_pkg_rev();
>  
>  	return 0;
>  }
> 

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Thanks
Patrice
Patrick DELAUNAY March 11, 2021, 11:01 a.m. UTC | #2
Hi Marek,

On 3/5/21 3:18 PM, Marek Vasut wrote:
> Split up get_soc_name(), clean the decoding up a bit, and set up
> environment variables which contain the SoC type, package, revision.
> This is useful on SoMs, where multiple SoC options are populated.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> ---
>   arch/arm/mach-stm32mp/cpu.c | 105 ++++++++++++++++++------------------
>   1 file changed, 53 insertions(+), 52 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index 3faa4ec18a4..887db9b5b0c 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -349,89 +349,78 @@ u32 get_cpu_package(void)
>   	return get_otp(BSEC_OTP_PKG, PKG_SHIFT, PKG_MASK);
>   }
>   
> -void get_soc_name(char name[SOC_NAME_SIZE])
> +static const char * const soc_type[] = {
> +	"????",
> +	"151C", "151A", "151F", "151D",
> +	"153C", "153A", "153F", "153D",
> +	"157C", "157A", "157F", "157D"
> +};
> +
> +static const char * const soc_pkg[] = { "??", "AD", "AC", "AB", "AA" };
> +static const char * const soc_rev[] = { "?", "A", "B", "Z" };
> +
> +static void get_cpu_string_offsets(unsigned int *type, unsigned int *pkg,
> +				   unsigned int *rev)
>   {
> -	char *cpu_s, *cpu_r, *pkg;
> +	u32 cpu_type = get_cpu_type();
> +	u32 ct = cpu_type & ~(BIT(7) | BIT(0));
> +	u32 cm = ((cpu_type & BIT(7)) >> 6) | (cpu_type & BIT(0));
> +	u32 cp = get_cpu_package();
>   
> -	/* MPUs Part Numbers */
> -	switch (get_cpu_type()) {
> -	case CPU_STM32MP157Fxx:
> -		cpu_s = "157F";
> -		break;
> -	case CPU_STM32MP157Dxx:
> -		cpu_s = "157D";
> -		break;
> -	case CPU_STM32MP157Cxx:
> -		cpu_s = "157C";
> -		break;
> -	case CPU_STM32MP157Axx:
> -		cpu_s = "157A";
> -		break;
> -	case CPU_STM32MP153Fxx:
> -		cpu_s = "153F";
> -		break;
> -	case CPU_STM32MP153Dxx:
> -		cpu_s = "153D";
> +	/* Bits 0 and 7 are the ACDF, 00:C 01:A 10:F 11:D */
> +	switch (ct) {
> +	case CPU_STM32MP151Cxx:
> +		*type = cm + 1;
>   		break;
>   	case CPU_STM32MP153Cxx:
> -		cpu_s = "153C";
> -		break;
> -	case CPU_STM32MP153Axx:
> -		cpu_s = "153A";
> -		break;
> -	case CPU_STM32MP151Fxx:
> -		cpu_s = "151F";
> -		break;
> -	case CPU_STM32MP151Dxx:
> -		cpu_s = "151D";
> +		*type = cm + 5;
>   		break;
> -	case CPU_STM32MP151Cxx:
> -		cpu_s = "151C";
> -		break;
> -	case CPU_STM32MP151Axx:
> -		cpu_s = "151A";
> +	case CPU_STM32MP157Cxx:
> +		*type = cm + 9;
>   		break;
>   	default:
> -		cpu_s = "????";
> +		*type = 0;
>   		break;
>   	}
>   
>   	/* Package */
> -	switch (get_cpu_package()) {
> +	switch (cp) {
>   	case PKG_AA_LBGA448:
> -		pkg = "AA";
> -		break;
>   	case PKG_AB_LBGA354:
> -		pkg = "AB";
> -		break;
>   	case PKG_AC_TFBGA361:
> -		pkg = "AC";
> -		break;
>   	case PKG_AD_TFBGA257:
> -		pkg = "AD";
> +		*pkg = cp;
>   		break;
>   	default:

./include/dt-bindings/pinctrl/stm32-pinfunc.h:37:

#define STM32MP_PKG_AA    0x1
#define STM32MP_PKG_AB    0x2
#define STM32MP_PKG_AC    0x4
#define STM32MP_PKG_AD    0x8

So it can't be used as index in array  in the next part of the patch

=> soc_pkg[pkg]

need to parse a array ?

static const struct {
	const u8 value;
	char *;
} static const char * const soc_pkg[] =
	{ { 0, "??"},
           { STM32MP_PKG_AA, "AA" },
	  { STM32MP_PKG_AB, "AB" },
	  { STM32MP_PKG_AC, "AC" },
	  { STM32MP_PKG_AD, "AD" }};

> -		pkg = "??";
> +		pkg = 0;
>   		break;
>   	}
>   
> -	/* REVISION */
> +	/* Revision */
>   	switch (get_cpu_rev()) {
>   	case CPU_REVA:
> -		cpu_r = "A";
> +		*rev = 1;
>   		break;
>   	case CPU_REVB:
> -		cpu_r = "B";
> +		*rev = 2;
>   		break;
>   	case CPU_REVZ:
> -		cpu_r = "Z";
> +		*rev = 3;


For information rev = 2.1 => "Z"  for STM32MP15 in STMicrolectonics 
naming rules

normally

v1 => "A"

v2 => "B"

v3 => "C"


"Z" => first minor revision of the chip vX.1

"Y" => second minor revision of the chip => vX.2 or vY.1

It is a nightmare to have coherent naming rule, but I propose to use a 
numericale value in  "soc_rev"

	/* Revision */
  	switch (get_cpu_rev()) {
  	case CPU_REVA:
		*rev = 10;
  		break;
  	case CPU_REVB:
		*rev = 20;
  		break;
  	case CPU_REVZ:
		*rev = 21;
		break;

	printf("%d") in env variable => "soc_rev"

or

           value = get_cup_rev();

	*rev_value = (value & 0xF000 > 24) * 10 + (value & 0xF);

and  search in array for associated string to display the associated character
(only required to respect the STMicrolectronic nomenclature as request by our Marketing)

static const struct {
	const u8 value;
	char *;
} static const char * const soc_rev[] =
	{ { 0, "?"},
           { 10, "A" },
	  { 20, "B" },
	  { 21, "Z" }; /* revZ for v2.1 on STM32MP15 */


other solution: parsing an array

static const struct {
	const u32 value;
	char *;
} static const char * const soc_rev[] =
	{ { 0, "?"},
           { CPU_REVA, "A" },
	  { CPU_REVB, "B" },
	  { CPU_REVZ, "Z" }; /* revZ for v2.1 on STM32MP15 */


>   		break;
>   	default:
> -		cpu_r = "?";
> +		*rev = 0;
>   		break;
>   	}
> +}
> +
> +void get_soc_name(char name[SOC_NAME_SIZE])
> +{
> +	unsigned int type, pkg, rev;
>   
> -	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r);
> +	get_cpu_string_offsets(&type, &pkg, &rev);
> +
> +	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s",
> +		 soc_type[type], soc_pkg[pkg], soc_rev[rev]);
>   }
>   
>   #if defined(CONFIG_DISPLAY_CPUINFO)
> @@ -620,11 +609,23 @@ static int setup_serial_number(void)
>   	return 0;
>   }
>   
> +static void setup_soc_type_pkg_rev(void)
> +{
> +	unsigned int type, pkg, rev;
> +
> +	get_cpu_string_offsets(&type, &pkg, &rev);
> +
> +	env_set("soc_type", soc_type[type]);
> +	env_set("soc_pkg", soc_pkg[pkg]);
> +	env_set("soc_rev", soc_rev[rev]);
> +}
> +
>   int arch_misc_init(void)
>   {
>   	setup_boot_mode();
>   	setup_mac_address();
>   	setup_serial_number();
> +	setup_soc_type_pkg_rev();
>   
>   	return 0;
>   }


FYI:  I plan to move this part in UCLASS_SOC, to prepare new SOC 
introduction

         I hopes that will solve also this issues => soc_get_revision / 
soc_get_machine

         even if package is missing in soc_uclass....


Patrick
diff mbox series

Patch

diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index 3faa4ec18a4..887db9b5b0c 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -349,89 +349,78 @@  u32 get_cpu_package(void)
 	return get_otp(BSEC_OTP_PKG, PKG_SHIFT, PKG_MASK);
 }
 
-void get_soc_name(char name[SOC_NAME_SIZE])
+static const char * const soc_type[] = {
+	"????",
+	"151C", "151A", "151F", "151D",
+	"153C", "153A", "153F", "153D",
+	"157C", "157A", "157F", "157D"
+};
+
+static const char * const soc_pkg[] = { "??", "AD", "AC", "AB", "AA" };
+static const char * const soc_rev[] = { "?", "A", "B", "Z" };
+
+static void get_cpu_string_offsets(unsigned int *type, unsigned int *pkg,
+				   unsigned int *rev)
 {
-	char *cpu_s, *cpu_r, *pkg;
+	u32 cpu_type = get_cpu_type();
+	u32 ct = cpu_type & ~(BIT(7) | BIT(0));
+	u32 cm = ((cpu_type & BIT(7)) >> 6) | (cpu_type & BIT(0));
+	u32 cp = get_cpu_package();
 
-	/* MPUs Part Numbers */
-	switch (get_cpu_type()) {
-	case CPU_STM32MP157Fxx:
-		cpu_s = "157F";
-		break;
-	case CPU_STM32MP157Dxx:
-		cpu_s = "157D";
-		break;
-	case CPU_STM32MP157Cxx:
-		cpu_s = "157C";
-		break;
-	case CPU_STM32MP157Axx:
-		cpu_s = "157A";
-		break;
-	case CPU_STM32MP153Fxx:
-		cpu_s = "153F";
-		break;
-	case CPU_STM32MP153Dxx:
-		cpu_s = "153D";
+	/* Bits 0 and 7 are the ACDF, 00:C 01:A 10:F 11:D */
+	switch (ct) {
+	case CPU_STM32MP151Cxx:
+		*type = cm + 1;
 		break;
 	case CPU_STM32MP153Cxx:
-		cpu_s = "153C";
-		break;
-	case CPU_STM32MP153Axx:
-		cpu_s = "153A";
-		break;
-	case CPU_STM32MP151Fxx:
-		cpu_s = "151F";
-		break;
-	case CPU_STM32MP151Dxx:
-		cpu_s = "151D";
+		*type = cm + 5;
 		break;
-	case CPU_STM32MP151Cxx:
-		cpu_s = "151C";
-		break;
-	case CPU_STM32MP151Axx:
-		cpu_s = "151A";
+	case CPU_STM32MP157Cxx:
+		*type = cm + 9;
 		break;
 	default:
-		cpu_s = "????";
+		*type = 0;
 		break;
 	}
 
 	/* Package */
-	switch (get_cpu_package()) {
+	switch (cp) {
 	case PKG_AA_LBGA448:
-		pkg = "AA";
-		break;
 	case PKG_AB_LBGA354:
-		pkg = "AB";
-		break;
 	case PKG_AC_TFBGA361:
-		pkg = "AC";
-		break;
 	case PKG_AD_TFBGA257:
-		pkg = "AD";
+		*pkg = cp;
 		break;
 	default:
-		pkg = "??";
+		pkg = 0;
 		break;
 	}
 
-	/* REVISION */
+	/* Revision */
 	switch (get_cpu_rev()) {
 	case CPU_REVA:
-		cpu_r = "A";
+		*rev = 1;
 		break;
 	case CPU_REVB:
-		cpu_r = "B";
+		*rev = 2;
 		break;
 	case CPU_REVZ:
-		cpu_r = "Z";
+		*rev = 3;
 		break;
 	default:
-		cpu_r = "?";
+		*rev = 0;
 		break;
 	}
+}
+
+void get_soc_name(char name[SOC_NAME_SIZE])
+{
+	unsigned int type, pkg, rev;
 
-	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r);
+	get_cpu_string_offsets(&type, &pkg, &rev);
+
+	snprintf(name, SOC_NAME_SIZE, "STM32MP%s%s Rev.%s",
+		 soc_type[type], soc_pkg[pkg], soc_rev[rev]);
 }
 
 #if defined(CONFIG_DISPLAY_CPUINFO)
@@ -620,11 +609,23 @@  static int setup_serial_number(void)
 	return 0;
 }
 
+static void setup_soc_type_pkg_rev(void)
+{
+	unsigned int type, pkg, rev;
+
+	get_cpu_string_offsets(&type, &pkg, &rev);
+
+	env_set("soc_type", soc_type[type]);
+	env_set("soc_pkg", soc_pkg[pkg]);
+	env_set("soc_rev", soc_rev[rev]);
+}
+
 int arch_misc_init(void)
 {
 	setup_boot_mode();
 	setup_mac_address();
 	setup_serial_number();
+	setup_soc_type_pkg_rev();
 
 	return 0;
 }