2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 * This test performs the system hardware monitoring.
34 * The test passes when all the following voltages and temperatures
35 * are within allowed ranges:
37 * Temperature -40 .. +85 C
38 * +5V +4.75 .. +5.25 V
39 * +5V standby +4.75 .. +5.25 V
41 * LCD backlight is not enabled if temperature values are not within
42 * allowed ranges (-30 .. + 80). The brightness of backlite can be
43 * controlled by setting "brightness" enviroment variable. Default value is 50%
45 * See the list of all parameters in the sysmon_table below
52 #if CONFIG_POST & CFG_POST_SYSMON
54 DECLARE_GLOBAL_DATA_PTR;
56 #define DEFAULT_BRIGHTNESS 50
59 extern int dspic_read(ushort reg);
61 extern void fpga_backlight_enable(int v);
63 static int sysmon_temp_invalid;
65 #define RELOC(x) if (x != NULL) x = (void *) ((ulong) (x) + gd->reloc_off)
67 typedef struct sysmon_s sysmon_t;
68 typedef struct sysmon_table_s sysmon_table_t;
70 static void sysmon_dspic_init (sysmon_t * this);
71 static int sysmon_dspic_read (sysmon_t * this, uint addr);
72 static void sysmon_backlight_disable (sysmon_table_t * this);
73 static void sysmon_backlight_enable (sysmon_table_t * this);
78 void (*init)(sysmon_t *);
79 int (*read)(sysmon_t *, uint);
82 static sysmon_t sysmon_dspic =
83 {CFG_I2C_DSPIC_IO_ADDR, sysmon_dspic_init, sysmon_dspic_read};
85 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 {"Temperature", " C", &sysmon_dspic, NULL, sysmon_backlight_disable,
116 1, 1, -32768, 32767, 0xFFFF, 0x8000-40, 0x8000+85, 0,
117 0x8000-30, 0x8000+80, 0, 0x12BC},
119 {"+ 5 V", "V", &sysmon_dspic, NULL, NULL,
120 100, 1000, -0x8000, 0x7FFF, 0xFFFF, 0x8000+4750, 0x8000+5250, 0,
121 0x8000+4750, 0x8000+5250, 0, 0x12CA},
123 {"+ 5 V standby", "V", &sysmon_dspic, NULL, sysmon_backlight_enable,
124 100, 1000, -0x8000, 0x7FFF, 0xFFFF, 0x8000+4750, 0x8000+5250, 0,
125 0x8000+4750, 0x8000+5250, 0, 0x12C6},
127 static int sysmon_table_size = sizeof(sysmon_table) / sizeof(sysmon_table[0]);
129 int sysmon_init_f (void)
133 for (l = sysmon_list; *l; l++)
139 void sysmon_reloc (void)
144 for (l = sysmon_list; *l; l++) {
150 for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++) {
151 RELOC(t->exec_before);
152 RELOC(t->exec_after);
157 static char *sysmon_unit_value (sysmon_table_t *s, uint val)
165 s->unit_min + (s->unit_max - s->unit_min) * val / s->val_mask;
172 unit_val = -unit_val;
176 p = buf + sprintf(buf, "%c%2d", sign, unit_val / s->unit_div);
179 frac = unit_val % s->unit_div;
181 frac /= (s->unit_div / s->unit_precision);
183 decimal = s->unit_precision;
187 for (decimal /= 10; decimal != 0; decimal /= 10)
188 *p++ = '0' + (frac / decimal) % 10;
189 strcpy(p, s->unit_name);
194 static void sysmon_dspic_init (sysmon_t * this)
198 static int sysmon_dspic_read (sysmon_t * this, uint addr)
200 int res = dspic_read(addr);
202 /* To fit into the table range we should add 0x8000 */
203 return (res == -1) ? -1 : (res + 0x8000);
206 static void sysmon_backlight_disable (sysmon_table_t * this)
208 if (!this->val_valid_alt)
209 sysmon_temp_invalid = 1;
212 static void sysmon_backlight_enable (sysmon_table_t * this)
217 if (!sysmon_temp_invalid) {
218 param = getenv("brightness");
219 rc = param ? simple_strtol(param, NULL, 10) : -1;
221 fpga_backlight_enable(rc);
223 fpga_backlight_enable(DEFAULT_BRIGHTNESS);
227 int sysmon_post_test (int flags)
233 for (t = sysmon_table; t < sysmon_table + sysmon_table_size; t ++) {
237 val = t->sysmon->read(t->sysmon, t->addr);
239 t->val_valid = val >= t->val_min && val <= t->val_max;
240 t->val_valid_alt = val >= t->val_min_alt && val <= t->val_max_alt;
243 t->val_valid_alt = 0;
249 if ((!t->val_valid) || (flags & POST_MANUAL)) {
250 printf("%-17s = %-10s ", t->name, sysmon_unit_value(t, val));
251 printf("allowed range");
252 printf(" %-8s ..", sysmon_unit_value(t, t->val_min));
253 printf(" %-8s", sysmon_unit_value(t, t->val_max));
254 printf(" %s\n", t->val_valid ? "OK" : "FAIL");
264 #endif /* CONFIG_POST & CFG_POST_SYSMON */
265 #endif /* CONFIG_POST */