ARM: tegra: add speedo identification for T20/T30
Subsystems (3)
cover ARM: tegra: add speedo identification for T20/T30
This patch series adds speedo identification functionality for tegra T20 and T30. It reads speedo value from fuse and chooses CPU and core process ID by checking speedo corner tables.
Danny Huang (2):
ARM: tegra: Add speedo-based process identification
ARM: tegra: T30 speedo-based identification
arch/arm/mach-tegra/Makefile | 2 + arch/arm/mach-tegra/fuse.c | 35 +++-- arch/arm/mach-tegra/fuse.h | 16 ++ arch/arm/mach-tegra/tegra20_speedo.c | 102 ++++++++++++ arch/arm/mach-tegra/tegra30_speedo.c | 290 +++++++++++++++++++++++++++++++++++ 5 files changed, 433 insertions(+), 12 deletions(-) create mode 100644 arch/arm/mach-tegra/tegra20_speedo.c create mode 100644 arch/arm/mach-tegra/tegra30_speedo.c
Signature · 1 line
1.8.0
PATCH 1/2 ARM: tegra: Add speedo-based process identification
Detect CPU and core process ID by checking speedo corner tables. This can provide a more accurate process ID.
--- arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/fuse.c | 13 ++--- arch/arm/mach-tegra/fuse.h | 8 +++ arch/arm/mach-tegra/tegra20_speedo.c | 102 +++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 arch/arm/mach-tegra/tegra20_speedo.c
arch/arm/mach-tegra/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_CPU_IDLE) += sleep.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_clocks.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_clocks_data.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra2_emc.o +obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_speedo.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += sleep-t20.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks_data.o
arch/arm/mach-tegra/fuse.c +5 -8
@@ -35,6 +35,7 @@ int tegra_sku_id;int tegra_cpu_process_id;int tegra_core_process_id;int tegra_chip_id; +int tegra_soc_speedo_id;enum tegra_revision tegra_revision;/* The BCT to use at boot is specified by board straps that can be read
@@ -62,7 +63,7 @@ static inline u32 tegra_fuse_readl(unsigned long offset)return tegra_apb_readl (TEGRA_FUSE_BASE + offset); } -static inline bool get_spare_fuse (int bit) +unsigned int tegra_spare_fuse (int bit) {return tegra_fuse_readl (FUSE_SPARE_BIT + bit *4 ); }
@@ -78,7 +79,7 @@ static enum tegra_revision tegra_get_revision(u32 id)return TEGRA_REVISION_A02 ;case 3 :if (tegra_chip_id ==TEGRA20 && - (get_spare_fuse (18 ) ||get_spare_fuse (19 ))) + (tegra_spare_fuse (18 ) ||tegra_spare_fuse (19 )))return TEGRA_REVISION_A03p;else return TEGRA_REVISION_A03 ;
@@ -100,12 +101,6 @@ void tegra_init_fuse(void) reg =tegra_fuse_readl (FUSE_SKU_INFO ); tegra_sku_id = reg &0xFF ; - reg =tegra_fuse_readl (FUSE_SPARE_BIT ); - tegra_cpu_process_id = (reg >>6 ) &3 ; - - reg =tegra_fuse_readl (FUSE_SPARE_BIT ); - tegra_core_process_id = (reg >>12 ) &3 ; - reg =tegra_apb_readl (TEGRA_APB_MISC_BASE +STRAP_OPT ); tegra_bct_strapping = (reg &RAM_ID_MASK ) >>RAM_CODE_SHIFT ;
@@ -114,6 +109,8 @@ void tegra_init_fuse(void) tegra_revision =tegra_get_revision (id); +tegra20_init_speedo_data (); + pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n", tegra_revision_name[tegra_revision], tegra_sku_id, tegra_cpu_process_id,
arch/arm/mach-tegra/fuse.h +8 -0
@@ -42,11 +42,19 @@ extern int tegra_sku_id;extern int tegra_cpu_process_id;extern int tegra_core_process_id;extern int tegra_chip_id; +extern int tegra_soc_speedo_id;extern enum tegra_revision tegra_revision;extern int tegra_bct_strapping;unsigned long long tegra_chip_uid (void );void tegra_init_fuse (void ); +unsigned int tegra_spare_fuse (int bit); + +#ifdef CONFIG_ARCH_TEGRA_2x_SOC +void tegra20_init_speedo_data (void ); +#else +static inline void tegra20_init_speedo_data (void ) {} +#endif #endif
arch/arm/mach-tegra/tegra20_speedo.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 2/2 ARM: tegra: T30 speedo-based identification
In reply to Danny HuangThis patch adds speedo-based identification support for T30.
--- arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/fuse.c | 26 +++- arch/arm/mach-tegra/fuse.h | 8 + arch/arm/mach-tegra/tegra30_speedo.c | 290 +++++++++++++++++++++++++++++++++++ 4 files changed, 319 insertions(+), 6 deletions(-) create mode 100644 arch/arm/mach-tegra/tegra30_speedo.c
arch/arm/mach-tegra/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra20_speedo.o obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += sleep-t20.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_clocks_data.o +obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += tegra30_speedo.o obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += sleep-t30.o obj-$(CONFIG_SMP) += platsmp.o headsmp.o obj-$(CONFIG_SMP) += reset.o
arch/arm/mach-tegra/fuse.c +20 -6
@@ -29,12 +29,17 @@#define FUSE_UID_LOW 0x108#define FUSE_UID_HIGH 0x10c#define FUSE_SKU_INFO 0x110 -#define FUSE_SPARE_BIT 0x200 + +#define TEGRA20_FUSE_SPARE_BIT 0x200 +#define TEGRA30_FUSE_SPARE_BIT 0x244 + +static int tegra_fuse_spare_bit;int tegra_sku_id;int tegra_cpu_process_id;int tegra_core_process_id;int tegra_chip_id; +int tegra_cpu_speedo_id;int tegra_soc_speedo_id;enum tegra_revision tegra_revision;
@@ -58,14 +63,14 @@ static const char *tegra_revision_name[TEGRA_REVISION_MAX] = { [TEGRA_REVISION_A04] = "A04", }; -static inline u32 tegra_fuse_readl (unsigned long offset) +u32 tegra_fuse_readl (unsigned long offset) {return tegra_apb_readl (TEGRA_FUSE_BASE + offset); }unsigned int tegra_spare_fuse (int bit) { -return tegra_fuse_readl (FUSE_SPARE_BIT + bit *4 ); +return tegra_fuse_readl (tegra_fuse_spare_bit + bit *4 ); }static enum tegra_revision tegra_get_revision (u32 id)
@@ -107,9 +112,18 @@ void tegra_init_fuse(void) id =readl_relaxed (IO_ADDRESS (TEGRA_APB_MISC_BASE ) +0x804 ); tegra_chip_id = (id >>8 ) &0xff ; - tegra_revision =tegra_get_revision (id); - -tegra20_init_speedo_data (); +switch (tegra_chip_id) { +case TEGRA20 : + tegra_fuse_spare_bit =TEGRA20_FUSE_SPARE_BIT ; + tegra_revision =tegra_get_revision (id); +tegra20_init_speedo_data (); +break ; +case TEGRA30 : + tegra_fuse_spare_bit =TEGRA30_FUSE_SPARE_BIT ; + tegra_revision =tegra_get_revision (id); +tegra30_init_speedo_data (); +break ; + } pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n", tegra_revision_name[tegra_revision],
arch/arm/mach-tegra/fuse.h +8 -0
@@ -42,6 +42,7 @@ extern int tegra_sku_id;extern int tegra_cpu_process_id;extern int tegra_core_process_id;extern int tegra_chip_id; +extern int tegra_cpu_speedo_id;extern int tegra_soc_speedo_id;extern enum tegra_revision tegra_revision;
@@ -50,6 +51,7 @@ extern int tegra_bct_strapping;unsigned long long tegra_chip_uid (void );void tegra_init_fuse (void );unsigned int tegra_spare_fuse (int bit); +u32 tegra_fuse_readl (unsigned long offset);#ifdef CONFIG_ARCH_TEGRA_2x_SOCvoid tegra20_init_speedo_data (void );
@@ -57,4 +59,10 @@ void tegra20_init_speedo_data(void);static inline void tegra20_init_speedo_data (void ) {}#endif +#ifdef CONFIG_ARCH_TEGRA_3x_SOC +void tegra30_init_speedo_data (void ); +#else +static inline void tegra30_init_speedo_data (void ) {} +#endif +#endif
arch/arm/mach-tegra/tegra30_speedo.c new file +290 -0
290 lines not on this page · raw message
Signature · 1 line
1.8.0
Re: [PATCH 1/2] ARM: tegra: Add speedo-based process identification
In reply to Danny Huangarch/arm/mach-tegra/fuse.c void tegra_init_fuse(void) · line 112
Quoted 10 lines · Danny Huang
Detect CPU and core process ID by checking speedo corner tables. This can provide a more accurate process ID.
arch/arm/mach-tegra/fuse.c +1
-0@@ -114,6 +109,8 @@ void tegra_init_fuse(void) tegra_revision =tegra_get_revision (id); +tegra20_init_speedo_data ();
This code executes on both Tegra20 and Tegra30. Calling a Tegra20-specific function unconditionally isn't correct. This is important because if someone does "git bisect" across this patch, patch 1 might be applied, but patch 2 not.
I think you need to add the switch statement from patch 2 here rather than later in patch 2. Also, I think you need to keep the following chunk of code in the Tegra30 case, and only remove it completely in patch 2
- reg = tegra_fuse_readl(FUSE_SPARE_BIT);
- tegra_cpu_process_id = (reg >> 6) & 3;
-
- reg = tegra_fuse_readl(FUSE_SPARE_BIT);
- tegra_core_process_id = (reg >> 12) & 3;
Quoted 19 lines
arch/arm/mach-tegra/tegra20_speedo.c +17
-0+static const u32 cpu_process_speedos[][PROCESS_CORNERS_NUM ] = { + {315 ,366 ,420 ,UINT_MAX }, + {303 ,368 ,419 ,UINT_MAX }, + {316 ,331 ,383 ,UINT_MAX }, +}; + +static const u32 core_process_speedos[][PROCESS_CORNERS_NUM ] = { + {165 ,195 ,224 ,UINT_MAX }, + {165 ,195 ,224 ,UINT_MAX }, + {165 ,195 ,224 ,UINT_MAX }, +}; + +void tegra20_init_speedo_data (void ) +{ +u32 reg; +u32 val; +int i;
arch/arm/mach-tegra/tegra20_speedo.c line 69
Quoted 10 lines
arch/arm/mach-tegra/tegra20_speedo.c +10
-0+ +if (SPEEDO_ID_SELECT_0 (tegra_revision)) + tegra_soc_speedo_id =0 ; +else if (SPEEDO_ID_SELECT_1 (tegra_sku_id)) + tegra_soc_speedo_id =1 ; +else + tegra_soc_speedo_id =2 ; + +WARN_ON (tegra_soc_speedo_id >=ARRAY_SIZE (cpu_process_speedos)); +WARN_ON (tegra_soc_speedo_id >=ARRAY_SIZE (core_process_speedos));
Can this be a BUILD_BUG_ON() instead;
#define SPEEDO_ID_0 0
#define SPEEDO_ID_1 1
#define SPEEDO_ID_2 2
#define SPEEDO_ID_COUNT (SPEEDO_ID_2 + 1) BUILD_BUG_ON(ARRAY_SIZE(cpu_process_speedos) == SPEEDO_ID_COUNT) BUILD_BUG_ON(ARRAY_SIZE(core_process_speedos) == SPEEDO_ID_COUNT)
and use those #defines in the assignments to tegra_soc_speedod_id above, rather than literals?
Or even just the following without the BUILD_BUG_ONs:
arch/arm/mach-tegra/tegra20_speedo.c line 75
Quoted 7 lines
static const u32 core_process_speedos[SPEEDO_ID_COUNT][PROCESS_CORNERS_NUM] = {
arch/arm/mach-tegra/tegra20_speedo.c +5
-0+ val =0 ; +for (i =CPU_SPEEDO_MSBIT ; i >=CPU_SPEEDO_LSBIT ; i--) { + reg =tegra_spare_fuse (i) | +tegra_spare_fuse (i +CPU_SPEEDO_REDUND_OFFS ); + val = (val <<1 ) | (reg &0x1 );
Out of curiosity, why did the prototype of tegra_spare_fuse() change from returning a bool to an int, if only bit 0 is going to be used?
Re: [PATCH 2/2] ARM: tegra: T30 speedo-based identification
In reply to Danny Huangarch/arm/mach-tegra/fuse.c line 36
Quoted 10 lines · Danny Huang
This patch adds speedo-based identification support for T30.
arch/arm/mach-tegra/fuse.c +5
-1-#define FUSE_SPARE_BIT 0x200 + +#define TEGRA20_FUSE_SPARE_BIT 0x200 +#define TEGRA30_FUSE_SPARE_BIT 0x244 + +static int tegra_fuse_spare_bit;
Can all the spare bit rework, and also prototype changes for tegra_fuse_readl() and tegra_spare_fuse() be pulled out into a separate patch at the start of the series?
Quoted 1 line
+int
tegra_cpu_speedo_id;
Does Tegra20 not have a separate cpu_speedo_id? Should this variable be added in patch 1 and appropriately initialized for Tegra20? If it's Tegra30-specific, or Tegra30-and-later, a comment to that effect would be useful. Is there a way to ensure that Tegra20-specific code doesn't use that variable if it's not applicable?
Quoted 9 lines
arch/arm/mach-tegra/fuse.c +2
-3@@ -107,9 +112,18 @@ void tegra_init_fuse(void) id =readl_relaxed (IO_ADDRESS (TEGRA_APB_MISC_BASE ) +0x804 ); tegra_chip_id = (id >>8 ) &0xff ; - tegra_revision =tegra_get_revision (id); - -tegra20_init_speedo_data (); +switch (tegra_chip_id) { +case TEGRA20 :
arch/arm/mach-tegra/fuse.c void tegra_init_fuse(void) · line 126
Quoted 10 lines
arch/arm/mach-tegra/fuse.c +10
-0+ tegra_fuse_spare_bit =TEGRA20_FUSE_SPARE_BIT ; + tegra_revision =tegra_get_revision (id); +tegra20_init_speedo_data (); +break ; +case TEGRA30 : + tegra_fuse_spare_bit =TEGRA30_FUSE_SPARE_BIT ; + tegra_revision =tegra_get_revision (id); +tegra30_init_speedo_data (); +break ; + }
I think there, I'd prefer to see:
switch (tegra_chip_id) {
case TEGRA20:
tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT; break; case TEGRA30: tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT; break; }
tegra_revision = tegra_get_revision(id);
switch (tegra_chip_id) {
case TEGRA20:
tegra20_init_speedo_data(); break; case TEGRA30: tegra30_init_speedo_data(); break; }
... to avoid duplicating the tegra_get_revision() call.
If this ends up needing a lot of separate switch statements in sequence, you can always put the SoC-specific data into a struct, and do:
struct tegra_fuse_soc_data *sd = ...;sd->set_spare_fuse_bit();tegra_revision = tegra_get_revision(id);sd->init_speedo_data();
although I don't think the complexity requires that yet.
arch/arm/mach-tegra/tegra30_speedo.c
Quoted 1 line
arch/arm/mach-tegra/tegra30_speedo.c +0
-0
(similar comments apply here as for the table/array size checking in patch 1)
arch/arm/mach-tegra/tegra30_speedo.c line 69
Quoted 2 lines
arch/arm/mach-tegra/tegra30_speedo.c +2
-0+static int threshold_index; +static int package_id;
Do those need to be globals? Can they simply be passed between the appropriate functions?
arch/arm/mach-tegra/tegra30_speedo.c line 78
Quoted 3 lines
arch/arm/mach-tegra/tegra30_speedo.c +2
-0+static void fuse_speedo_calib(u32 *speedo_g, u32 *speedo_lp) + WARN_ON(!speedo_g || !speedo_lp);
That hardly seems worth checking since this function is called from one specific place later in this file...
Quoted 12 lines
arch/arm/mach-tegra/tegra30_speedo.c +12
-0+static void rev_sku_to_speedo_ids (int rev,int sku) +{ +switch (rev) { +case TEGRA_REVISION_A01 : + tegra_cpu_speedo_id =0 ; + tegra_soc_speedo_id =0 ; + threshold_index =0 ; +break ; +case TEGRA_REVISION_A02 : +case TEGRA_REVISION_A03 : +switch (sku) { +case 0x87 :
...
arch/arm/mach-tegra/tegra30_speedo.c line 140
Quoted 7 lines
arch/arm/mach-tegra/tegra30_speedo.c +7
-0+default : +pr_err ("Tegra3 Rev-A02: Reserved pkg: %d\n" , + package_id); +BUG (); +break ; + } +break ;
Why BUG() there, but not:
arch/arm/mach-tegra/tegra30_speedo.c line 227
Quoted 9 lines
arch/arm/mach-tegra/tegra30_speedo.c +9
-0+default : +pr_err ("Tegra3: Unknown SKU %d\n" , sku); + tegra_cpu_speedo_id =0 ; + tegra_soc_speedo_id =0 ; + threshold_index =0 ; +break ; + } +break ; +default :
... but do here:
Quoted 12 lines
arch/arm/mach-tegra/tegra30_speedo.c +10
-0+BUG (); +break ; + } +} +void tegra30_init_speedo_data (void ) + for (i = 0; i < CPU_PROCESS_CORNERS_NUM; i++) { +if (cpu_speedo_val < + cpu_process_speedos[threshold_index][i]) { +break ; + }
arch/arm/mach-tegra/tegra30_speedo.c line 265
Quoted 10 lines
arch/arm/mach-tegra/tegra30_speedo.c +10
-0+ } + tegra_cpu_process_id = i -1 ; + +if (tegra_cpu_process_id ==-1 ) { +pr_err ("****************************************************" ); +pr_err ("****************************************************" ); +pr_err ("* tegra3_speedo: CPU speedo value %3d out of range *" , + cpu_speedo_val); +pr_err ("****************************************************" ); +pr_err ("****************************************************" );
Just drop the lines of ***, and the * around the text in the middle pr_err() too.
arch/arm/mach-tegra/tegra30_speedo.c
Quoted 2 lines
arch/arm/mach-tegra/tegra30_speedo.c +2
-0+ + tegra_cpu_speedo_id =1 ;
Shouldn't that fix the out-of-range tegra_cpu_process_id value?
This and the previous comment apply to the following calculation of tegra_core_process_id too.