]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - post/sysmon.c
Fix mkimage -l bug with multifile images on 64bit platforms
[people/ms/u-boot.git] / post / sysmon.c
index f069caa19d217b416aa38787dcd192006919214e..f61d598244ccb025f1bbe2f7a86812cc97872d3f 100644 (file)
@@ -32,7 +32,7 @@
  * This test performs the system hardware monitoring.
  * The test passes when all the following voltages and temperatures
  * are within allowed ranges:
- * 
+ *
  * Board temperature
  * Front temperature
  * +3.3V CPU logic
@@ -40,7 +40,7 @@
  * +12V PCMCIA
  * +12V CCFL
  * +5V standby
- * 
+ *
  * CCFL is not enabled if temperature values are not within allowed ranges
  *
  * See the list off all parameters in the sysmon_table below
@@ -52,6 +52,8 @@
 
 #if CONFIG_POST & CFG_POST_SYSMON
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int sysmon_temp_invalid = 0;
 
 /* #define DEBUG */
@@ -98,6 +100,7 @@ struct sysmon_table_s
        void            (*exec_before)(sysmon_table_t *);
        void            (*exec_after)(sysmon_table_t *);
 
+       int             unit_precision;
        int             unit_div;
        int             unit_min;
        int             unit_max;
@@ -105,31 +108,34 @@ struct sysmon_table_s
        uint            val_min;
        uint            val_max;
        int             val_valid;
+       uint            val_min_alt;
+       uint            val_max_alt;
+       int             val_valid_alt;
        uint            addr;
 };
 
 static sysmon_table_t sysmon_table[] =
 {
     {"Board temperature", " C", &sysmon_lm87_sgn, NULL, sysmon_ccfl_disable,
-     1, -128, 127, 0xFF, 0x58, 0xD5, 0, 0x27},
+     1, 1, -128, 127, 0xFF, 0x58, 0xD5, 0, 0x6C, 0xC6, 0, 0x27},
 
     {"Front temperature", " C", &sysmon_lm87, NULL, sysmon_ccfl_disable,
-     100, -27316, 8984, 0xFF, 0xA4, 0xFC, 0, 0x29},
+     1, 100, -27316, 8984, 0xFF, 0xA4, 0xFC, 0, 0xB2, 0xF1, 0, 0x29},
 
     {"+3.3V CPU logic", "V", &sysmon_lm87, NULL, NULL,
-     1000, 0, 4386, 0xFF, 0xB6, 0xC9, 0, 0x22},
+     100, 1000, 0, 4386, 0xFF, 0xB6, 0xC9, 0, 0xB6, 0xC9, 0, 0x22},
 
-    {"+5V logic", "V", &sysmon_lm87, NULL, NULL,
-     1000, 0, 6630, 0xFF, 0xB6, 0xCA, 0, 0x23},
+    {"+ 5 V logic", "V", &sysmon_lm87, NULL, NULL,
+     100, 1000, 0, 6630, 0xFF, 0xB6, 0xCA, 0, 0xB6, 0xCA, 0, 0x23},
 
-    {"+12V PCMCIA", "V", &sysmon_lm87, NULL, NULL,
-     1000, 0, 15460, 0xFF, 0xBC, 0xD0, 0, 0x21},
+    {"+12 V PCMCIA", "V", &sysmon_lm87, NULL, NULL,
+     100, 1000, 0, 15460, 0xFF, 0xBC, 0xD0, 0, 0xBC, 0xD0, 0, 0x21},
 
-    {"+12V CCFL", "V", &sysmon_lm87, NULL, sysmon_ccfl_enable,
-     1000, 0, 15900, 0xFF, 0xB6, 0xCA, 0, 0x24},
+    {"+12 V CCFL", "V", &sysmon_lm87, NULL, sysmon_ccfl_enable,
+     100, 1000, 0, 15900, 0xFF, 0xB6, 0xCA, 0, 0xB6, 0xCA, 0, 0x24},
 
-    {"+5V standby", "V", &sysmon_pic, NULL, NULL,
-     1000, 0, 6040, 0xFF, 0xC8, 0xDE, 0, 0x7C},
+    {"+ 5 V standby", "V", &sysmon_pic, NULL, NULL,
+     100, 1000, 0, 6040, 0xFF, 0xC8, 0xDE, 0, 0xC8, 0xDE, 0, 0x7C},
 };
 static int sysmon_table_size = sizeof(sysmon_table) / sizeof(sysmon_table[0]);
 
@@ -146,63 +152,67 @@ int sysmon_init_f (void)
        reg |= 0x09;
        pic_write (0x60, reg);
 
-       for (l = sysmon_list; *l; l++)
-       {
+       for (l = sysmon_list; *l; l++) {
                (*l)->init(*l);
        }
-       
+
        return 0;
 }
 
 void sysmon_reloc (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        sysmon_t ** l;
        sysmon_table_t * t;
 
-       for (l = sysmon_list; *l; l++)
-       {
+       for (l = sysmon_list; *l; l++) {
                RELOC(*l);
                RELOC((*l)->init);
                RELOC((*l)->read);
        }
 
-       for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++)
-       {
+       for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++) {
                RELOC(t->exec_before);
                RELOC(t->exec_after);
                RELOC(t->sysmon);
        }
 }
 
-static char * sysmon_unit_value (sysmon_table_t * s, uint val)
+static char *sysmon_unit_value (sysmon_table_t *s, uint val)
 {
        static char buf[32];
        int unit_val =
            s->unit_min + (s->unit_max - s->unit_min) * val / s->val_mask;
-       char * p;
+       char *p, sign;
        int dec, frac;
 
-       sprintf(buf, "%+d", unit_val / s->unit_div);
-       
-       frac = (unit_val > 0 ? unit_val : -unit_val) % s->unit_div;
-       p = buf + strlen(buf);
-       
-       dec = s->unit_div;
-       
-       if (dec != 1)
-       {
+       if (val == -1) {
+               return "I/O ERROR";
+       }
+
+       if (unit_val < 0) {
+               sign = '-';
+               unit_val = -unit_val;
+       } else {
+               sign = '+';
+       }
+
+       p = buf + sprintf(buf, "%c%2d", sign, unit_val / s->unit_div);
+
+
+       frac = unit_val % s->unit_div;
+
+       frac /= (s->unit_div / s->unit_precision);
+
+       dec = s->unit_precision;
+
+       if (dec != 1) {
                *p++ = '.';
        }
-       
-       for (dec /= 10; dec != 0; dec /= 10)
-       {
-               *p++ = '0' + frac / dec % 10;
+       for (dec /= 10; dec != 0; dec /= 10) {
+               *p++ = '0' + (frac / dec) % 10;
        }
-       
        strcpy(p, s->unit_name);
-       
+
        return buf;
 }
 
@@ -212,24 +222,21 @@ static void sysmon_lm87_init (sysmon_t * this)
 
        /* Detect LM87 chip */
        if (i2c_read(this->chip, 0x40, 1, &val, 1) || (val & 0x80) != 0 ||
-           i2c_read(this->chip, 0x3E, 1, &val, 1) || val != 0x02)
-       {
+           i2c_read(this->chip, 0x3E, 1, &val, 1) || val != 0x02) {
                printf("Error: LM87 not found at 0x%02X\n", this->chip);
                return;
        }
-       
+
        /* Configure pins 5,6 as AIN */
        val = 0x03;
-       if (i2c_write(this->chip, 0x16, 1, &val, 1))
-       {
+       if (i2c_write(this->chip, 0x16, 1, &val, 1)) {
                printf("Error: can't write LM87 config register\n");
                return;
        }
 
        /* Start monitoring */
        val = 0x01;
-       if (i2c_write(this->chip, 0x40, 1, &val, 1))
-       {
+       if (i2c_write(this->chip, 0x40, 1, &val, 1)) {
                printf("Error: can't write LM87 config register\n");
                return;
        }
@@ -256,8 +263,7 @@ static uint sysmon_i2c_read_sgn (sysmon_t * this, uint addr)
 
 static void sysmon_ccfl_disable (sysmon_table_t * this)
 {
-       if (!this->val_valid)
-       {
+       if (!this->val_valid_alt) {
                sysmon_temp_invalid = 1;
        }
 }
@@ -266,18 +272,15 @@ static void sysmon_ccfl_enable (sysmon_table_t * this)
 {
        ulong reg;
 
-       if (!sysmon_temp_invalid)
-       {
+       if (!sysmon_temp_invalid) {
                reg = pic_read  (0x60);
-               reg |= 0x02;
+               reg |= 0x06;
                pic_write (0x60, reg);
        }
 }
 
 int sysmon_post_test (int flags)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        int res = 0;
        sysmon_table_t * t;
        uint val;
@@ -285,31 +288,30 @@ int sysmon_post_test (int flags)
        /*
         * The A/D conversion on the LM87 sensor takes 300 ms.
         */
-       if (! conversion_done)
-       {
+       if (! conversion_done) {
                while (post_time_ms(gd->post_init_f_time) < 300) WATCHDOG_RESET ();
                conversion_done = 1;
        }
 
-       for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++)
-       {
-               if (t->exec_before)
-               {
+       for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++) {
+               if (t->exec_before) {
                        t->exec_before(t);
                }
 
                val = t->sysmon->read(t->sysmon, t->addr);
-               t->val_valid = val >= t->val_min && val <= t->val_max;
+               if (val != -1) {
+                       t->val_valid = val >= t->val_min && val <= t->val_max;
+                       t->val_valid_alt = val >= t->val_min_alt && val <= t->val_max_alt;
+               } else {
+                       t->val_valid = 0;
+                       t->val_valid_alt = 0;
+               }
 
-               if (t->exec_after)
-               {
+               if (t->exec_after) {
                        t->exec_after(t);
                }
 
-#ifndef DEBUG
-               if (!t->val_valid)
-#endif
-               {
+               if ((!t->val_valid) || (flags & POST_MANUAL)) {
                        printf("%-17s = %-10s ", t->name, sysmon_unit_value(t, val));
                        printf("allowed range");
                        printf(" %-8s ..", sysmon_unit_value(t, t->val_min));
@@ -317,8 +319,7 @@ int sysmon_post_test (int flags)
                        printf("     %s\n", t->val_valid ? "OK" : "FAIL");
                }
 
-               if (!t->val_valid)
-               {
+               if (!t->val_valid) {
                        res = -1;
                }
        }