blob: fa87b5e7b948cc398fc413711ffea47be94a4bb4 [file] [log] [blame]
Stefan Roese033848e2012-08-16 17:55:41 +00001/*
2 * (C) Copyright 2011
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
Tom Rini084240b2013-11-08 13:53:14 -05005 * A bootcount driver for the RTC IP block found on many TI platforms.
6 * This requires the RTC clocks, etc, to be enabled prior to use and
7 * not all boards with this IP block on it will have the RTC in use.
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese033848e2012-08-16 17:55:41 +000010 */
11
12#include <bootcount.h>
Tom Rini56424eb2013-08-28 09:00:28 -040013#include <asm/davinci_rtc.h>
Stefan Roese033848e2012-08-16 17:55:41 +000014
15void bootcount_store(ulong a)
16{
17 struct davinci_rtc *reg =
18 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
19
20 /*
21 * write RTC kick register to enable write
22 * for RTC Scratch registers. Scratch0 and 1 are
23 * used for bootcount values.
24 */
25 writel(RTC_KICK0R_WE, &reg->kick0r);
26 writel(RTC_KICK1R_WE, &reg->kick1r);
Tom Rinif9291332013-08-28 09:00:29 -040027 raw_bootcount_store(&reg->scratch2,
28 (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff));
Stefan Roese033848e2012-08-16 17:55:41 +000029}
30
31ulong bootcount_load(void)
32{
Tom Rinif9291332013-08-28 09:00:29 -040033 unsigned long val;
Stefan Roese033848e2012-08-16 17:55:41 +000034 struct davinci_rtc *reg =
35 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
36
Tom Rinif9291332013-08-28 09:00:29 -040037 val = raw_bootcount_load(&reg->scratch2);
38 if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roese033848e2012-08-16 17:55:41 +000039 return 0;
40 else
Tom Rinif9291332013-08-28 09:00:29 -040041 return val & 0x0000ffff;
Stefan Roese033848e2012-08-16 17:55:41 +000042}