mmc: add mmc and sd support for MT7622
[oweals/u-boot.git] / drivers / bootcount / bootcount.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2010-2012
4  * Stefan Roese, DENX Software Engineering, sr@denx.de.
5  */
6
7 #include <bootcount.h>
8 #include <cpu_func.h>
9 #include <linux/compiler.h>
10
11 /* Now implement the generic default functions */
12 __weak void bootcount_store(ulong a)
13 {
14         void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
15         uintptr_t flush_start = rounddown(CONFIG_SYS_BOOTCOUNT_ADDR,
16                                           CONFIG_SYS_CACHELINE_SIZE);
17         uintptr_t flush_end;
18
19 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
20         raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | a);
21
22         flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4,
23                             CONFIG_SYS_CACHELINE_SIZE);
24 #else
25         raw_bootcount_store(reg, a);
26         raw_bootcount_store(reg + 4, CONFIG_SYS_BOOTCOUNT_MAGIC);
27
28         flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 8,
29                             CONFIG_SYS_CACHELINE_SIZE);
30 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
31         flush_dcache_range(flush_start, flush_end);
32 }
33
34 __weak ulong bootcount_load(void)
35 {
36         void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
37
38 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
39         u32 tmp = raw_bootcount_load(reg);
40
41         if ((tmp & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
42                 return 0;
43         else
44                 return (tmp & 0x0000ffff);
45 #else
46         if (raw_bootcount_load(reg + 4) != CONFIG_SYS_BOOTCOUNT_MAGIC)
47                 return 0;
48         else
49                 return raw_bootcount_load(reg);
50 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
51 }