Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <bootcount.h> |
Tom Rini | 155d424 | 2013-08-28 09:00:28 -0400 | [diff] [blame] | 9 | #include <asm/davinci_rtc.h> |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 10 | |
| 11 | void bootcount_store(ulong a) |
| 12 | { |
| 13 | struct davinci_rtc *reg = |
| 14 | (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 15 | |
| 16 | /* |
| 17 | * write RTC kick register to enable write |
| 18 | * for RTC Scratch registers. Scratch0 and 1 are |
| 19 | * used for bootcount values. |
| 20 | */ |
| 21 | writel(RTC_KICK0R_WE, ®->kick0r); |
| 22 | writel(RTC_KICK1R_WE, ®->kick1r); |
Tom Rini | 22ee397 | 2013-08-28 09:00:29 -0400 | [diff] [blame^] | 23 | raw_bootcount_store(®->scratch2, |
| 24 | (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff)); |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | ulong bootcount_load(void) |
| 28 | { |
Tom Rini | 22ee397 | 2013-08-28 09:00:29 -0400 | [diff] [blame^] | 29 | unsigned long val; |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 30 | struct davinci_rtc *reg = |
| 31 | (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 32 | |
Tom Rini | 22ee397 | 2013-08-28 09:00:29 -0400 | [diff] [blame^] | 33 | val = raw_bootcount_load(®->scratch2); |
| 34 | if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 35 | return 0; |
| 36 | else |
Tom Rini | 22ee397 | 2013-08-28 09:00:29 -0400 | [diff] [blame^] | 37 | return val & 0x0000ffff; |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 38 | } |