]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
arm: mx6: make shutdown temperature configurable
authorLothar Waßmann <LW@KARO-electronics.de>
Fri, 9 Jan 2015 10:49:53 +0000 (11:49 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 9 Jan 2015 10:49:53 +0000 (11:49 +0100)
arch/arm/cpu/armv7/mx6/soc.c
arch/arm/include/asm/arch-mx6/sys_proto.h
board/karo/tx6/tx6qdl.c

index 0a9182dcc32f150673f540e5455c6faee6abecf4..8d9b141a7c60cfdf1fe85f5dc2bb81d7fe45389d 100644 (file)
 
 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;
 }
index f37cca3fe1b170241f544e89adb0bd0baea12df5..d263560a1a8c87f383858a1114f5261bfe2162a3 100644 (file)
@@ -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
index 5d2317dde43072ad72a692b91942587452499495..aac62ccd85324900a71b9cbf52db480dc7dd349e 100644 (file)
 
 #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)