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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <bootcount.h> |
| 21 | #include <asm/arch/da850_lowlevel.h> |
| 22 | #include <asm/arch/davinci_misc.h> |
| 23 | |
| 24 | void bootcount_store(ulong a) |
| 25 | { |
| 26 | struct davinci_rtc *reg = |
| 27 | (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 28 | |
| 29 | /* |
| 30 | * write RTC kick register to enable write |
| 31 | * for RTC Scratch registers. Scratch0 and 1 are |
| 32 | * used for bootcount values. |
| 33 | */ |
| 34 | writel(RTC_KICK0R_WE, ®->kick0r); |
| 35 | writel(RTC_KICK1R_WE, ®->kick1r); |
| 36 | raw_bootcount_store(®->scratch0, a); |
| 37 | raw_bootcount_store(®->scratch1, BOOTCOUNT_MAGIC); |
| 38 | } |
| 39 | |
| 40 | ulong bootcount_load(void) |
| 41 | { |
| 42 | struct davinci_rtc *reg = |
| 43 | (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 44 | |
| 45 | if (raw_bootcount_load(®->scratch1) != BOOTCOUNT_MAGIC) |
| 46 | return 0; |
| 47 | else |
| 48 | return raw_bootcount_load(®->scratch0); |
| 49 | } |