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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Allwinner Real Time Clock emulation
*
* Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HW_MISC_ALLWINNER_RTC_H
#define HW_MISC_ALLWINNER_RTC_H
#include "qom/object.h"
#include "hw/sysbus.h"
/**
* Constants
* @{
*/
/** Highest register address used by RTC device */
#define AW_RTC_REGS_MAXADDR (0x200)
/** Total number of known registers */
#define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
/** @} */
/**
* Object model types
* @{
*/
/** Generic Allwinner RTC device (abstract) */
#define TYPE_AW_RTC "allwinner-rtc"
/** Allwinner RTC sun4i family (A10, A12) */
#define TYPE_AW_RTC_SUN4I TYPE_AW_RTC "-sun4i"
/** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */
#define TYPE_AW_RTC_SUN6I TYPE_AW_RTC "-sun6i"
/** Allwinner RTC sun7i family (A20) */
#define TYPE_AW_RTC_SUN7I TYPE_AW_RTC "-sun7i"
/** @} */
/**
* Object model macros
* @{
*/
typedef struct AwRtcClass AwRtcClass;
typedef struct AwRtcState AwRtcState;
DECLARE_OBJ_CHECKERS(AwRtcState, AwRtcClass,
AW_RTC, TYPE_AW_RTC)
/** @} */
/**
* Allwinner RTC per-object instance state.
*/
struct AwRtcState {
/*< private >*/
SysBusDevice parent_obj;
/*< public >*/
/**
* Actual year represented by the device when year counter is zero
*
* Can be overridden by the user using the corresponding 'base-year'
* property. The base year used by the target OS driver can vary, for
* example the Linux driver for sun6i uses 1970 while NetBSD uses 2000.
*/
int base_year;
/** Maps I/O registers in physical memory */
MemoryRegion iomem;
/** Array of hardware registers */
uint32_t regs[AW_RTC_REGS_NUM];
};
/**
* Allwinner RTC class-level struct.
*
* This struct is filled by each sunxi device specific code
* such that the generic code can use this struct to support
* all devices.
*/
struct AwRtcClass {
/*< private >*/
SysBusDeviceClass parent_class;
/*< public >*/
/** Defines device specific register map */
const uint8_t *regmap;
/** Size of the regmap in bytes */
size_t regmap_size;
/**
* Read device specific register
*
* @offset: register offset to read
* @return true if register read successful, false otherwise
*/
bool (*read)(AwRtcState *s, uint32_t offset);
/**
* Write device specific register
*
* @offset: register offset to write
* @data: value to set in register
* @return true if register write successful, false otherwise
*/
bool (*write)(AwRtcState *s, uint32_t offset, uint32_t data);
};
#endif /* HW_MISC_ALLWINNER_RTC_H */
|