1*0044c42eSStefan Roese /* 2*0044c42eSStefan Roese * See file CREDITS for list of people who contributed to this 3*0044c42eSStefan Roese * project. 4*0044c42eSStefan Roese * 5*0044c42eSStefan Roese * This program is free software; you can redistribute it and/or 6*0044c42eSStefan Roese * modify it under the terms of the GNU General Public License as 7*0044c42eSStefan Roese * published by the Free Software Foundation; either version 2 of 8*0044c42eSStefan Roese * the License, or (at your option) any later version. 9*0044c42eSStefan Roese * 10*0044c42eSStefan Roese * This program is distributed in the hope that it will be useful, 11*0044c42eSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*0044c42eSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*0044c42eSStefan Roese * GNU General Public License for more details. 14*0044c42eSStefan Roese * 15*0044c42eSStefan Roese */ 16*0044c42eSStefan Roese 17*0044c42eSStefan Roese #include <common.h> 18*0044c42eSStefan Roese #include <asm/io.h> 19*0044c42eSStefan Roese #include <asm/arch/hardware.h> 20*0044c42eSStefan Roese #include <asm/arch/at91_gpbr.h> 21*0044c42eSStefan Roese 22*0044c42eSStefan Roese /* 23*0044c42eSStefan Roese * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register. 24*0044c42eSStefan Roese * This is done so we need to use only one of the four GPBR registers. 25*0044c42eSStefan Roese */ 26*0044c42eSStefan Roese void bootcount_store(ulong a) 27*0044c42eSStefan Roese { 28*0044c42eSStefan Roese at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; 29*0044c42eSStefan Roese 30*0044c42eSStefan Roese writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff), 31*0044c42eSStefan Roese &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]); 32*0044c42eSStefan Roese } 33*0044c42eSStefan Roese 34*0044c42eSStefan Roese ulong bootcount_load(void) 35*0044c42eSStefan Roese { 36*0044c42eSStefan Roese at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; 37*0044c42eSStefan Roese 38*0044c42eSStefan Roese ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]); 39*0044c42eSStefan Roese if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) 40*0044c42eSStefan Roese return 0; 41*0044c42eSStefan Roese else 42*0044c42eSStefan Roese return val & 0x0000ffff; 43*0044c42eSStefan Roese } 44