3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * This test performs the system hardware monitoring.
31 * The test passes when all the following voltages and temperatures
32 * are within allowed ranges:
42 * CCFL is not enabled if temperature values are not within allowed ranges
44 * See the list off all parameters in the sysmon_table below
51 #if CONFIG_POST & CONFIG_SYS_POST_SYSMON
53 DECLARE_GLOBAL_DATA_PTR;
55 static int sysmon_temp_invalid = 0;
59 typedef struct sysmon_s sysmon_t;
60 typedef struct sysmon_table_s sysmon_table_t;
62 static void sysmon_lm87_init (sysmon_t * this);
63 static void sysmon_pic_init (sysmon_t * this);
64 static uint sysmon_i2c_read (sysmon_t * this, uint addr);
65 static uint sysmon_i2c_read_sgn (sysmon_t * this, uint addr);
66 static void sysmon_ccfl_disable (sysmon_table_t * this);
67 static void sysmon_ccfl_enable (sysmon_table_t * this);
72 void (*init)(sysmon_t *);
73 uint (*read)(sysmon_t *, uint);
76 static sysmon_t sysmon_lm87 =
77 {CONFIG_SYS_I2C_SYSMON_ADDR, sysmon_lm87_init, sysmon_i2c_read};
78 static sysmon_t sysmon_lm87_sgn =
79 {CONFIG_SYS_I2C_SYSMON_ADDR, sysmon_lm87_init, sysmon_i2c_read_sgn};
80 static sysmon_t sysmon_pic =
81 {CONFIG_SYS_I2C_PICIO_ADDR, sysmon_pic_init, sysmon_i2c_read};
83 static sysmon_t * sysmon_list[] =
96 void (*exec_before)(sysmon_table_t *);
97 void (*exec_after)(sysmon_table_t *);
113 static sysmon_table_t sysmon_table[] =
115 {"Board temperature", " C", &sysmon_lm87_sgn, NULL, sysmon_ccfl_disable,
116 1, 1, -128, 127, 0xFF, 0x58, 0xD5, 0, 0x6C, 0xC6, 0, 0x27},
118 {"Front temperature", " C", &sysmon_lm87, NULL, sysmon_ccfl_disable,
119 1, 100, -27316, 8984, 0xFF, 0xA4, 0xFC, 0, 0xB2, 0xF1, 0, 0x29},
121 {"+3.3V CPU logic", "V", &sysmon_lm87, NULL, NULL,
122 100, 1000, 0, 4386, 0xFF, 0xB6, 0xC9, 0, 0xB6, 0xC9, 0, 0x22},
124 {"+ 5 V logic", "V", &sysmon_lm87, NULL, NULL,
125 100, 1000, 0, 6630, 0xFF, 0xB6, 0xCA, 0, 0xB6, 0xCA, 0, 0x23},
127 {"+12 V PCMCIA", "V", &sysmon_lm87, NULL, NULL,
128 100, 1000, 0, 15460, 0xFF, 0xBC, 0xD0, 0, 0xBC, 0xD0, 0, 0x21},
130 {"+12 V CCFL", "V", &sysmon_lm87, NULL, sysmon_ccfl_enable,
131 100, 1000, 0, 15900, 0xFF, 0xB6, 0xCA, 0, 0xB6, 0xCA, 0, 0x24},
133 {"+ 5 V standby", "V", &sysmon_pic, NULL, NULL,
134 100, 1000, 0, 6040, 0xFF, 0xC8, 0xDE, 0, 0xC8, 0xDE, 0, 0x7C},
136 static int sysmon_table_size = sizeof(sysmon_table) / sizeof(sysmon_table[0]);
138 static int conversion_done = 0;
141 int sysmon_init_f (void)
146 /* Power on CCFL, PCMCIA */
147 reg = pic_read (0x60);
149 pic_write (0x60, reg);
151 for (l = sysmon_list; *l; l++) {
158 void sysmon_reloc (void)
160 /* Do nothing for now, sysmon_reloc() is required by the sysmon post */
163 static char *sysmon_unit_value (sysmon_table_t *s, uint val)
167 s->unit_min + (s->unit_max - s->unit_min) * val / s->val_mask;
177 unit_val = -unit_val;
182 p = buf + sprintf(buf, "%c%2d", sign, unit_val / s->unit_div);
185 frac = unit_val % s->unit_div;
187 frac /= (s->unit_div / s->unit_precision);
189 dec = s->unit_precision;
194 for (dec /= 10; dec != 0; dec /= 10) {
195 *p++ = '0' + (frac / dec) % 10;
197 strcpy(p, s->unit_name);
202 static void sysmon_lm87_init (sysmon_t * this)
206 /* Detect LM87 chip */
207 if (i2c_read(this->chip, 0x40, 1, &val, 1) || (val & 0x80) != 0 ||
208 i2c_read(this->chip, 0x3E, 1, &val, 1) || val != 0x02) {
209 printf("Error: LM87 not found at 0x%02X\n", this->chip);
213 /* Configure pins 5,6 as AIN */
215 if (i2c_write(this->chip, 0x16, 1, &val, 1)) {
216 printf("Error: can't write LM87 config register\n");
220 /* Start monitoring */
222 if (i2c_write(this->chip, 0x40, 1, &val, 1)) {
223 printf("Error: can't write LM87 config register\n");
228 static void sysmon_pic_init (sysmon_t * this)
232 static uint sysmon_i2c_read (sysmon_t * this, uint addr)
235 uint res = i2c_read(this->chip, addr, 1, &val, 1);
237 return res == 0 ? val : -1;
240 static uint sysmon_i2c_read_sgn (sysmon_t * this, uint addr)
243 return i2c_read(this->chip, addr, 1, &val, 1) == 0 ?
244 128 + (signed char)val : -1;
247 static void sysmon_ccfl_disable (sysmon_table_t * this)
249 if (!this->val_valid_alt) {
250 sysmon_temp_invalid = 1;
254 static void sysmon_ccfl_enable (sysmon_table_t * this)
258 if (!sysmon_temp_invalid) {
259 reg = pic_read (0x60);
261 pic_write (0x60, reg);
265 int sysmon_post_test (int flags)
272 * The A/D conversion on the LM87 sensor takes 300 ms.
274 if (! conversion_done) {
275 while (post_time_ms(gd->post_init_f_time) < 300) WATCHDOG_RESET ();
279 for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++) {
280 if (t->exec_before) {
284 val = t->sysmon->read(t->sysmon, t->addr);
286 t->val_valid = val >= t->val_min && val <= t->val_max;
287 t->val_valid_alt = val >= t->val_min_alt && val <= t->val_max_alt;
290 t->val_valid_alt = 0;
297 if ((!t->val_valid) || (flags & POST_MANUAL)) {
298 printf("%-17s = %-10s ", t->name, sysmon_unit_value(t, val));
299 printf("allowed range");
300 printf(" %-8s ..", sysmon_unit_value(t, t->val_min));
301 printf(" %-8s", sysmon_unit_value(t, t->val_max));
302 printf(" %s\n", t->val_valid ? "OK" : "FAIL");
313 #endif /* CONFIG_POST & CONFIG_SYS_POST_SYSMON */