From 779283f2b6ab5152ffdaad38293fc438bb4b7b64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lothar=20Wa=C3=9Fmann?= Date: Fri, 9 Jan 2015 11:49:53 +0100 Subject: [PATCH] arm: mx6: make shutdown temperature configurable --- arch/arm/cpu/armv7/mx6/soc.c | 64 +++++++++++++++-------- arch/arm/include/asm/arch-mx6/sys_proto.h | 3 ++ board/karo/tx6/tx6qdl.c | 42 +++++++++++---- 3 files changed, 78 insertions(+), 31 deletions(-) diff --git a/arch/arm/cpu/armv7/mx6/soc.c b/arch/arm/cpu/armv7/mx6/soc.c index 0a9182dcc3..8d9b141a7c 100644 --- a/arch/arm/cpu/armv7/mx6/soc.c +++ b/arch/arm/cpu/armv7/mx6/soc.c @@ -24,9 +24,23 @@ DECLARE_GLOBAL_DATA_PTR; -#define TEMPERATURE_MIN -40 +#ifdef CONFIG_MX6_TEMPERATURE_MIN +#define TEMPERATURE_MIN CONFIG_MX6_TEMPERATURE_MIN +#else +#define TEMPERATURE_MIN (-40) +#endif +#ifdef CONFIG_MX6_TEMPERATURE_HOT +#define TEMPERATURE_HOT CONFIG_MX6_TEMPERATURE_HOT +#else #define TEMPERATURE_HOT 80 +#endif +#ifdef CONFIG_MX6_TEMPERATURE_MAX +#define TEMPERATURE_MAX CONFIG_MX6_TEMPERATURE_MAX +#else #define TEMPERATURE_MAX 125 +#endif +#define TEMP_AVG_COUNT 5 +#define TEMP_WARN_THRESHOLD 5 #define REG_VALUE_TO_CEL(ratio, raw) ((raw_n40c - raw) * 100 / ratio - 40) #define __data __attribute__((section(".data"))) @@ -188,7 +202,8 @@ int read_cpu_temperature(void) raw_n40c = raw_25c + (13 * ratio) / 20; /* now we only using single measure, every time we measure - the temperature, we will power on/down the anadig module*/ + * the temperature, we will power on/off the anadig module + */ writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, &anatop->tempsense0_clr); writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set); @@ -231,36 +246,43 @@ int read_cpu_temperature(void) int check_cpu_temperature(int boot) { static int __data max_temp; - int boot_limit = TEMPERATURE_HOT; + int boot_limit = getenv_ulong("max_boot_temp", 10, TEMPERATURE_HOT); int tmp = read_cpu_temperature(); + bool first = true; if (tmp < TEMPERATURE_MIN || tmp > TEMPERATURE_MAX) { printf("Temperature: can't get valid data!\n"); return tmp; } - while (tmp >= boot_limit) { - if (boot) { - printf("CPU is %d C, too hot to boot, waiting...\n", - tmp); - udelay(5000000); - tmp = read_cpu_temperature(); - boot_limit = TEMPERATURE_HOT - 1; - } else { - printf("CPU is %d C, too hot, resetting...\n", - tmp); - udelay(1000000); + if (!boot) { + if (tmp > boot_limit) { + printf("CPU is %d C, too hot, resetting...\n", tmp); + udelay(100000); reset_cpu(0); } - } - - if (boot) { + if (tmp > max_temp) { + if (tmp > boot_limit - TEMP_WARN_THRESHOLD) + printf("WARNING: CPU temperature %d C\n", tmp); + max_temp = tmp; + } + } else { printf("Temperature: %d C, calibration data 0x%x\n", tmp, thermal_calib); - } else if (tmp > max_temp) { - if (tmp > TEMPERATURE_HOT - 5) - printf("WARNING: CPU temperature %d C\n", tmp); - max_temp = tmp; + while (tmp >= boot_limit) { + if (first) { + printf("CPU is %d C, too hot to boot, waiting...\n", + tmp); + first = false; + } + if (ctrlc()) + break; + udelay(50000); + tmp = read_cpu_temperature(); + if (tmp > boot_limit - TEMP_WARN_THRESHOLD && tmp != max_temp) + printf("WARNING: CPU temperature %d C\n", tmp); + max_temp = tmp; + } } return tmp; } diff --git a/arch/arm/include/asm/arch-mx6/sys_proto.h b/arch/arm/include/asm/arch-mx6/sys_proto.h index f37cca3fe1..d263560a1a 100644 --- a/arch/arm/include/asm/arch-mx6/sys_proto.h +++ b/arch/arm/include/asm/arch-mx6/sys_proto.h @@ -43,4 +43,7 @@ int mxs_wait_mask_set(struct mxs_register_32 *reg, int mxs_wait_mask_clr(struct mxs_register_32 *reg, uint32_t mask, unsigned int timeout); + +int read_cpu_temperature(void); +int check_cpu_temperature(int boot); #endif diff --git a/board/karo/tx6/tx6qdl.c b/board/karo/tx6/tx6qdl.c index 5d2317dde4..aac62ccd85 100644 --- a/board/karo/tx6/tx6qdl.c +++ b/board/karo/tx6/tx6qdl.c @@ -50,9 +50,16 @@ #define TX6_RESET_OUT_GPIO IMX_GPIO_NR(7, 12) -#define TEMPERATURE_MIN -40 +#ifdef CONFIG_MX6_TEMPERATURE_MIN +#define TEMPERATURE_MIN CONFIG_MX6_TEMPERATURE_MIN +#else +#define TEMPERATURE_MIN (-40) +#endif +#ifdef CONFIG_MX6_TEMPERATURE_HOT +#define TEMPERATURE_HOT CONFIG_MX6_TEMPERATURE_HOT +#else #define TEMPERATURE_HOT 80 -#define TEMPERATURE_MAX 125 +#endif DECLARE_GLOBAL_DATA_PTR; @@ -194,9 +201,6 @@ static void print_reset_cause(void) printf("\n"); } -int read_cpu_temperature(void); -int check_cpu_temperature(int boot); - static const char *tx6_mod_suffix; static void tx6qdl_print_cpuinfo(void) @@ -230,7 +234,9 @@ static void tx6qdl_print_cpuinfo(void) mxc_get_clock(MXC_ARM_CLK) / 1000000); print_reset_cause(); +#ifdef CONFIG_MX6_TEMPERATURE_HOT check_cpu_temperature(1); +#endif } int board_early_init_f(void) @@ -241,6 +247,12 @@ int board_early_init_f(void) return 0; } +#ifndef CONFIG_MX6_TEMPERATURE_HOT +static bool tx6_temp_check_enabled = true; +#else +#define tx6_temp_check_enabled 0 +#endif + int board_init(void) { int ret; @@ -250,6 +262,9 @@ int board_init(void) gd->bd->bi_arch_number = -1; if (ctrlc()) { +#ifndef CONFIG_MX6_TEMPERATURE_HOT + tx6_temp_check_enabled = false; +#endif printf("CTRL-C detected; Skipping PMIC setup\n"); return 1; } @@ -453,10 +468,13 @@ enum { LED_STATE_ON, }; -static inline int calc_blink_rate(int tmp) +static inline int calc_blink_rate(void) { + if (!tx6_temp_check_enabled) + return CONFIG_SYS_HZ; + return CONFIG_SYS_HZ + CONFIG_SYS_HZ / 10 - - (tmp - TEMPERATURE_MIN) * CONFIG_SYS_HZ / + (check_cpu_temperature(0) - TEMPERATURE_MIN) * CONFIG_SYS_HZ / (TEMPERATURE_HOT - TEMPERATURE_MIN); } @@ -470,10 +488,10 @@ void show_activity(int arg) last = get_timer(0); gpio_set_value(TX6_LED_GPIO, 1); led_state = LED_STATE_ON; - blink_rate = calc_blink_rate(check_cpu_temperature(0)); + blink_rate = calc_blink_rate(); } else { if (get_timer(last) > blink_rate) { - blink_rate = calc_blink_rate(check_cpu_temperature(0)); + blink_rate = calc_blink_rate(); last = get_timer_masked(); if (led_state == LED_STATE_ON) { gpio_set_value(TX6_LED_GPIO, 0); @@ -1092,8 +1110,12 @@ int board_late_init(void) int ret = 0; const char *baseboard; + if (tx6_temp_check_enabled) + check_cpu_temperature(1); + tx6qdl_set_cpu_clock(); - karo_fdt_move_fdt(); + if (!had_ctrlc()) + karo_fdt_move_fdt(); baseboard = getenv("baseboard"); if (!baseboard) -- 2.39.2