lin
2025-01-10 9ec4e21f2f615ef95b70a249569906799e36bace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
/*
 * SPDX-License-Identifier: GPL-2.0+
 * Sunxi RTC data area ops
 *
 * (C) Copyright 2018-2020
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * wangwei <wangwei@allwinnertech.com>
 */
 
#include <common.h>
#include <errno.h>
#include <asm/io.h>
#include <rtc.h>
 
 
#define EFEX_FLAG  (0x5AA5A55A)
#define RTC_FEL_INDEX  2
#define RTC_BOOT_INDEX 6
 
 
void rtc_write_data(int index, u32 val)
{
   writel(val, SUNXI_RTC_DATA_BASE + index*4);
}
 
u32 rtc_read_data(int index)
{
   return readl(SUNXI_RTC_DATA_BASE + index*4);
}
 
void rtc_set_fel_flag(void)
{
   do {
       rtc_write_data(RTC_FEL_INDEX, EFEX_FLAG);
       asm volatile("DSB");
       asm volatile("ISB");
   } while (rtc_read_data(RTC_FEL_INDEX) != EFEX_FLAG);
}
 
u32 rtc_probe_fel_flag(void)
{
   return rtc_read_data(RTC_FEL_INDEX) == EFEX_FLAG ? 1 : 0;
}
 
void rtc_clear_fel_flag(void)
{
   do {
       rtc_write_data(RTC_FEL_INDEX, 0);
       asm volatile("DSB");
       asm volatile("ISB");
   } while (rtc_read_data(RTC_FEL_INDEX) != 0);
}
 
int rtc_set_bootmode_flag(u8 flag)
{
   do {
       rtc_write_data(RTC_BOOT_INDEX, flag);
       asm volatile("DSB");
       asm volatile("ISB");
   } while (rtc_read_data(RTC_BOOT_INDEX) != flag);
 
   return 0;
}
 
int rtc_get_bootmode_flag(void)
{
   uint boot_flag;
 
   /* operation should be same with kernel write rtc */
   boot_flag = rtc_read_data(RTC_BOOT_INDEX);
 
   return boot_flag;
}