blob: 6326957d7b044f8eff93ef69b834d7ee8880fda1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese0044c422012-08-16 17:55:41 +00002/*
3 * (C) Copyright 2011
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 *
Tom Riniabcaa6e2013-11-08 13:53:14 -05006 * A bootcount driver for the RTC IP block found on many TI platforms.
7 * This requires the RTC clocks, etc, to be enabled prior to use and
8 * not all boards with this IP block on it will have the RTC in use.
Stefan Roese0044c422012-08-16 17:55:41 +00009 */
10
11#include <bootcount.h>
Tom Rini155d4242013-08-28 09:00:28 -040012#include <asm/davinci_rtc.h>
Stefan Roese0044c422012-08-16 17:55:41 +000013
14void bootcount_store(ulong a)
15{
16 struct davinci_rtc *reg =
17 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
18
19 /*
Tomas Melinbac91702017-08-03 09:16:54 +030020 * write RTC kick registers to enable write
21 * for RTC Scratch registers. Scratch register 2 is
22 * used for bootcount value.
Stefan Roese0044c422012-08-16 17:55:41 +000023 */
24 writel(RTC_KICK0R_WE, &reg->kick0r);
25 writel(RTC_KICK1R_WE, &reg->kick1r);
Tom Rini22ee3972013-08-28 09:00:29 -040026 raw_bootcount_store(&reg->scratch2,
Marek Vasut758694f2018-10-11 00:13:54 +020027 (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff));
Stefan Roese0044c422012-08-16 17:55:41 +000028}
29
30ulong bootcount_load(void)
31{
Tom Rini22ee3972013-08-28 09:00:29 -040032 unsigned long val;
Stefan Roese0044c422012-08-16 17:55:41 +000033 struct davinci_rtc *reg =
34 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
35
Tom Rini22ee3972013-08-28 09:00:29 -040036 val = raw_bootcount_load(&reg->scratch2);
Marek Vasut758694f2018-10-11 00:13:54 +020037 if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roese0044c422012-08-16 17:55:41 +000038 return 0;
39 else
Tom Rini22ee3972013-08-28 09:00:29 -040040 return val & 0x0000ffff;
Stefan Roese0044c422012-08-16 17:55:41 +000041}