2 * Allwinner Real Time Clock emulation
4 * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef HW_MISC_ALLWINNER_RTC_H
21 #define HW_MISC_ALLWINNER_RTC_H
23 #include "qom/object.h"
24 #include "hw/sysbus.h"
31 /** Highest register address used by RTC device */
32 #define AW_RTC_REGS_MAXADDR (0x200)
34 /** Total number of known registers */
35 #define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
44 /** Generic Allwinner RTC device (abstract) */
45 #define TYPE_AW_RTC "allwinner-rtc"
47 /** Allwinner RTC sun4i family (A10, A12) */
48 #define TYPE_AW_RTC_SUN4I TYPE_AW_RTC "-sun4i"
50 /** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */
51 #define TYPE_AW_RTC_SUN6I TYPE_AW_RTC "-sun6i"
53 /** Allwinner RTC sun7i family (A20) */
54 #define TYPE_AW_RTC_SUN7I TYPE_AW_RTC "-sun7i"
64 OBJECT_CHECK(AwRtcState, (obj), TYPE_AW_RTC)
65 #define AW_RTC_CLASS(klass) \
66 OBJECT_CLASS_CHECK(AwRtcClass, (klass), TYPE_AW_RTC)
67 #define AW_RTC_GET_CLASS(obj) \
68 OBJECT_GET_CLASS(AwRtcClass, (obj), TYPE_AW_RTC)
73 * Allwinner RTC per-object instance state.
75 typedef struct AwRtcState
{
77 SysBusDevice parent_obj
;
81 * Actual year represented by the device when year counter is zero
83 * Can be overridden by the user using the corresponding 'base-year'
84 * property. The base year used by the target OS driver can vary, for
85 * example the Linux driver for sun6i uses 1970 while NetBSD uses 2000.
89 /** Maps I/O registers in physical memory */
92 /** Array of hardware registers */
93 uint32_t regs
[AW_RTC_REGS_NUM
];
98 * Allwinner RTC class-level struct.
100 * This struct is filled by each sunxi device specific code
101 * such that the generic code can use this struct to support
104 typedef struct AwRtcClass
{
106 SysBusDeviceClass parent_class
;
109 /** Defines device specific register map */
110 const uint8_t *regmap
;
112 /** Size of the regmap in bytes */
116 * Read device specific register
118 * @offset: register offset to read
119 * @return true if register read successful, false otherwise
121 bool (*read
)(AwRtcState
*s
, uint32_t offset
);
124 * Write device specific register
126 * @offset: register offset to write
127 * @data: value to set in register
128 * @return true if register write successful, false otherwise
130 bool (*write
)(AwRtcState
*s
, uint32_t offset
, uint32_t data
);
134 #endif /* HW_MISC_ALLWINNER_RTC_H */