2008-02-04 13:10:42 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
|
|
|
|
*
|
|
|
|
* Developed for DENX Software Engineering GmbH
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
|
2008-02-04 13:10:42 +00:00
|
|
|
/* This test verifies if the reason of last reset was an abnormal voltage
|
2008-02-04 13:10:42 +00:00
|
|
|
* condition, than it performs watchdog test, measuing time required to
|
|
|
|
* trigger watchdog reset.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <post.h>
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
|
2008-02-04 13:10:42 +00:00
|
|
|
|
|
|
|
#include <watchdog.h>
|
2010-09-16 12:30:37 +00:00
|
|
|
#include <asm/ppc4xx-gpio.h>
|
2008-02-04 13:10:42 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
static uint watchdog_magic_read(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
return in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
|
|
|
|
CONFIG_SYS_WATCHDOG_MAGIC_MASK;
|
2008-02-04 13:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void watchdog_magic_write(uint value)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
out_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR, value |
|
|
|
|
(in_be32((void *)CONFIG_SYS_WATCHDOG_FLAGS_ADDR) &
|
|
|
|
~CONFIG_SYS_WATCHDOG_MAGIC_MASK));
|
2008-02-04 13:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sysmon1_post_test(int flags)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
if (gpio_read_in_bit(CONFIG_SYS_GPIO_SYSMON_STATUS) == 0) {
|
2008-04-01 13:13:03 +00:00
|
|
|
/*
|
|
|
|
* 3.1. GPIO62 is low
|
2008-02-04 13:10:42 +00:00
|
|
|
* Assuming system voltage failure.
|
|
|
|
*/
|
2010-08-19 07:38:56 +00:00
|
|
|
post_log("sysmon1 Abnormal voltage detected (GPIO62)\n");
|
|
|
|
post_log("POST sysmon1 FAILED\n");
|
2008-02-04 13:10:42 +00:00
|
|
|
return 1;
|
2010-08-19 07:38:56 +00:00
|
|
|
} else {
|
|
|
|
post_log("sysmon1 PASSED\n");
|
2008-02-04 13:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lwmon5_watchdog_post_test(int flags)
|
|
|
|
{
|
|
|
|
/* On each reset scratch register 1 should be tested,
|
|
|
|
* but first test GPIO62:
|
|
|
|
*/
|
|
|
|
if (!(flags & POST_MANUAL) && sysmon1_post_test(flags)) {
|
2008-02-04 13:10:42 +00:00
|
|
|
/* 3.1. GPIO62 is low
|
2008-02-04 13:10:42 +00:00
|
|
|
* Assuming system voltage failure.
|
|
|
|
*/
|
|
|
|
/* 3.1.1. Set scratch register 1 to 0x0000xxxx */
|
|
|
|
watchdog_magic_write(0);
|
|
|
|
/* 3.1.2. Mark test as failed due to voltage?! */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
if (watchdog_magic_read() != CONFIG_SYS_WATCHDOG_MAGIC) {
|
2008-02-04 13:10:42 +00:00
|
|
|
/* 3.2. Scratch register 1 differs from magic value 0x1248xxxx
|
2008-02-04 13:10:42 +00:00
|
|
|
* Assuming PowerOn
|
|
|
|
*/
|
|
|
|
int ints;
|
|
|
|
ulong base;
|
2008-02-04 13:10:42 +00:00
|
|
|
ulong time;
|
2008-02-04 13:10:42 +00:00
|
|
|
|
|
|
|
/* 3.2.1. Set magic value to scratch register */
|
2008-10-16 13:01:15 +00:00
|
|
|
watchdog_magic_write(CONFIG_SYS_WATCHDOG_MAGIC);
|
2008-02-04 13:10:42 +00:00
|
|
|
|
|
|
|
ints = disable_interrupts ();
|
|
|
|
/* 3.2.2. strobe watchdog once */
|
|
|
|
WATCHDOG_RESET();
|
2008-10-16 13:01:15 +00:00
|
|
|
out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, 0);
|
2008-02-04 13:10:42 +00:00
|
|
|
/* 3.2.3. save time of strobe in scratch register 2 */
|
|
|
|
base = post_time_ms (0);
|
|
|
|
|
|
|
|
/* 3.2.4. Wait for 150 ms (enough for reset to happen) */
|
|
|
|
while ((time = post_time_ms (base)) < 150)
|
2008-10-16 13:01:15 +00:00
|
|
|
out_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR, time);
|
2008-02-04 13:10:42 +00:00
|
|
|
if (ints)
|
|
|
|
enable_interrupts ();
|
|
|
|
|
2008-02-04 13:10:42 +00:00
|
|
|
/* 3.2.5. Reset didn't happen. - Set 0x0000xxxx
|
2008-02-04 13:10:42 +00:00
|
|
|
* into scratch register 1
|
|
|
|
*/
|
|
|
|
watchdog_magic_write(0);
|
|
|
|
/* 3.2.6. Mark test as failed. */
|
|
|
|
post_log("hw watchdog time : %u ms, failed ", time);
|
|
|
|
return 2;
|
2008-02-04 13:10:42 +00:00
|
|
|
} else {
|
|
|
|
/* 3.3. Scratch register matches magic value 0x1248xxxx
|
|
|
|
* Assume this is watchdog-initiated reset
|
|
|
|
*/
|
|
|
|
ulong time;
|
|
|
|
/* 3.3.1. So, the test succeed, save measured time to syslog. */
|
2008-10-16 13:01:15 +00:00
|
|
|
time = in_be32((void *)CONFIG_SYS_WATCHDOG_TIME_ADDR);
|
2010-08-19 07:38:56 +00:00
|
|
|
if (time > 90 ) { /* ms*/
|
|
|
|
post_log("hw watchdog time : %u ms, passed ", time);
|
|
|
|
/* 3.3.2. Set scratch register 1 to 0x0000xxxx */
|
|
|
|
watchdog_magic_write(0);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/*test minimum watchdogtime */
|
|
|
|
post_log("hw watchdog time : %u ms, failed ", time);
|
|
|
|
return 2;
|
|
|
|
}
|
2008-02-04 13:10:42 +00:00
|
|
|
}
|
2008-02-04 13:10:42 +00:00
|
|
|
return -1;
|
2008-03-20 21:01:38 +00:00
|
|
|
}
|
2008-02-04 13:10:42 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */
|