Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
Tom Rini | 084240b | 2013-11-08 13:53:14 -0500 | [diff] [blame] | 5 | * 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 Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <bootcount.h> |
Tom Rini | 56424eb | 2013-08-28 09:00:28 -0400 | [diff] [blame] | 13 | #include <asm/davinci_rtc.h> |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 14 | |
| 15 | void 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, ®->kick0r); |
| 26 | writel(RTC_KICK1R_WE, ®->kick1r); |
Tom Rini | f929133 | 2013-08-28 09:00:29 -0400 | [diff] [blame] | 27 | raw_bootcount_store(®->scratch2, |
| 28 | (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff)); |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | ulong bootcount_load(void) |
| 32 | { |
Tom Rini | f929133 | 2013-08-28 09:00:29 -0400 | [diff] [blame] | 33 | unsigned long val; |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 34 | struct davinci_rtc *reg = |
| 35 | (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 36 | |
Tom Rini | f929133 | 2013-08-28 09:00:29 -0400 | [diff] [blame] | 37 | val = raw_bootcount_load(®->scratch2); |
| 38 | if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 39 | return 0; |
| 40 | else |
Tom Rini | f929133 | 2013-08-28 09:00:29 -0400 | [diff] [blame] | 41 | return val & 0x0000ffff; |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 42 | } |