blob: 76b65975cefca34f83bce765857aad42c9c4a892 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Bill Hunter, Wave 7 Optics, williamhunter@mediaone.net
4 * and
5 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
6 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00008 */
9
10#include <common.h>
11#include <config.h>
12#include <rtc.h>
13#include "errors.h"
14#include "dtt.h"
15
Stefan Roesef2302d42008-08-06 14:05:38 +020016/* for LM75 DTT POST test */
17#define DTT_READ_TEMP 0x0
18#define DTT_CONFIG 0x1
19#define DTT_TEMP_HYST 0x2
20#define DTT_TEMP_SET 0x3
21
wdenkc6097192002-11-03 00:24:07 +000022#if defined(CONFIG_RTC_M48T35A)
23void rtctest(void)
24{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 volatile uchar *tchar = (uchar*)(CONFIG_SYS_NVRAM_BASE_ADDR + CONFIG_SYS_NVRAM_SIZE - 9);
wdenkc6097192002-11-03 00:24:07 +000026 struct rtc_time tmp;
27
28 /* set up led code for RTC tests */
29 log_stat(ERR_RTCG);
30
31 /*
32 * Do RTC battery test. The first write after power up
33 * fails if battery is low.
34 */
35 *tchar = 0xaa;
36 if ((*tchar ^ 0xaa) != 0x0) log_warn(ERR_RTCBAT);
37 *tchar = 0x55; /* Reset test address */
38
39 /*
40 * Now lets check the validity of the values in the RTC.
41 */
42 rtc_get(&tmp);
43 if ((tmp.tm_sec < 0) | (tmp.tm_sec > 59) |
44 (tmp.tm_min < 0) | (tmp.tm_min > 59) |
45 (tmp.tm_hour < 0) | (tmp.tm_hour > 23) |
46 (tmp.tm_mday < 1 ) | (tmp.tm_mday > 31) |
47 (tmp.tm_mon < 1 ) | (tmp.tm_mon > 12) |
48 (tmp.tm_year < 2000) | (tmp.tm_year > 2500) |
49 (tmp.tm_wday < 1 ) | (tmp.tm_wday > 7)) {
50 log_warn(ERR_RTCTIM);
51 rtc_reset();
52 }
53
54 /*
55 * Now lets do a check to see if the NV RAM is there.
56 */
57 *tchar = 0xaa;
58 if ((*tchar ^ 0xaa) != 0x0) log_err(ERR_RTCVAL);
59 *tchar = 0x55; /* Reset test address */
60
61} /* rtctest() */
62#endif /* CONFIG_RTC_M48T35A */
63
64
65#ifdef CONFIG_DTT_LM75
66int dtt_test(int sensor)
67{
68 short temp, trip, hyst;
69
70 /* get values */
71 temp = dtt_read(sensor, DTT_READ_TEMP) / 256;
72 trip = dtt_read(sensor, DTT_TEMP_SET) / 256;
73 hyst = dtt_read(sensor, DTT_TEMP_HYST) / 256;
74
75 /* check values */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076 if ((hyst != (CONFIG_SYS_DTT_MAX_TEMP - CONFIG_SYS_DTT_HYSTERESIS)) ||
77 (trip != CONFIG_SYS_DTT_MAX_TEMP) ||
78 (temp < CONFIG_SYS_DTT_LOW_TEMP) || (temp > CONFIG_SYS_DTT_MAX_TEMP))
wdenkc6097192002-11-03 00:24:07 +000079 return 1;
80
81 return 0;
82} /* dtt_test() */
83#endif /* CONFIG_DTT_LM75 */
84
85/*****************************************/
86
87void post2(void)
88{
89#if defined(CONFIG_RTC_M48T35A)
90 rtctest();
91#endif /* CONFIG_RTC_M48T35A */
92
93#ifdef CONFIG_DTT_LM75
94 log_stat(ERR_TempG);
95 if(dtt_test(2) != 0) log_warn(ERR_Ttest0);
96 if(dtt_test(4) != 0) log_warn(ERR_Ttest1);
97#endif /* CONFIG_DTT_LM75 */
98} /* post2() */