10044c42eSStefan Roese /* 20044c42eSStefan Roese * (C) Copyright 2011 30044c42eSStefan Roese * Heiko Schocher, DENX Software Engineering, hs@denx.de. 40044c42eSStefan Roese * 5*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 60044c42eSStefan Roese */ 70044c42eSStefan Roese 80044c42eSStefan Roese #include <bootcount.h> 90044c42eSStefan Roese #include <asm/arch/da850_lowlevel.h> 100044c42eSStefan Roese #include <asm/arch/davinci_misc.h> 110044c42eSStefan Roese 120044c42eSStefan Roese void bootcount_store(ulong a) 130044c42eSStefan Roese { 140044c42eSStefan Roese struct davinci_rtc *reg = 150044c42eSStefan Roese (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; 160044c42eSStefan Roese 170044c42eSStefan Roese /* 180044c42eSStefan Roese * write RTC kick register to enable write 190044c42eSStefan Roese * for RTC Scratch registers. Scratch0 and 1 are 200044c42eSStefan Roese * used for bootcount values. 210044c42eSStefan Roese */ 220044c42eSStefan Roese writel(RTC_KICK0R_WE, ®->kick0r); 230044c42eSStefan Roese writel(RTC_KICK1R_WE, ®->kick1r); 240044c42eSStefan Roese raw_bootcount_store(®->scratch0, a); 250044c42eSStefan Roese raw_bootcount_store(®->scratch1, BOOTCOUNT_MAGIC); 260044c42eSStefan Roese } 270044c42eSStefan Roese 280044c42eSStefan Roese ulong bootcount_load(void) 290044c42eSStefan Roese { 300044c42eSStefan Roese struct davinci_rtc *reg = 310044c42eSStefan Roese (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR; 320044c42eSStefan Roese 330044c42eSStefan Roese if (raw_bootcount_load(®->scratch1) != BOOTCOUNT_MAGIC) 340044c42eSStefan Roese return 0; 350044c42eSStefan Roese else 360044c42eSStefan Roese return raw_bootcount_load(®->scratch0); 370044c42eSStefan Roese } 38