1 /* 2 * Allwinner Real Time Clock emulation 3 * 4 * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com> 5 * 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. 10 * 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. 15 * 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/>. 18 */ 19 20 #ifndef HW_MISC_ALLWINNER_RTC_H 21 #define HW_MISC_ALLWINNER_RTC_H 22 23 #include "qom/object.h" 24 #include "hw/sysbus.h" 25 26 /** 27 * Constants 28 * @{ 29 */ 30 31 /** Highest register address used by RTC device */ 32 #define AW_RTC_REGS_MAXADDR (0x200) 33 34 /** Total number of known registers */ 35 #define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t)) 36 37 /** @} */ 38 39 /** 40 * Object model types 41 * @{ 42 */ 43 44 /** Generic Allwinner RTC device (abstract) */ 45 #define TYPE_AW_RTC "allwinner-rtc" 46 47 /** Allwinner RTC sun4i family (A10, A12) */ 48 #define TYPE_AW_RTC_SUN4I TYPE_AW_RTC "-sun4i" 49 50 /** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */ 51 #define TYPE_AW_RTC_SUN6I TYPE_AW_RTC "-sun6i" 52 53 /** Allwinner RTC sun7i family (A20) */ 54 #define TYPE_AW_RTC_SUN7I TYPE_AW_RTC "-sun7i" 55 56 /** @} */ 57 58 /** 59 * Object model macros 60 * @{ 61 */ 62 63 #define AW_RTC(obj) \ 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) 69 70 /** @} */ 71 72 /** 73 * Allwinner RTC per-object instance state. 74 */ 75 typedef struct AwRtcState { 76 /*< private >*/ 77 SysBusDevice parent_obj; 78 /*< public >*/ 79 80 /** 81 * Actual year represented by the device when year counter is zero 82 * 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. 86 */ 87 int base_year; 88 89 /** Maps I/O registers in physical memory */ 90 MemoryRegion iomem; 91 92 /** Array of hardware registers */ 93 uint32_t regs[AW_RTC_REGS_NUM]; 94 95 } AwRtcState; 96 97 /** 98 * Allwinner RTC class-level struct. 99 * 100 * This struct is filled by each sunxi device specific code 101 * such that the generic code can use this struct to support 102 * all devices. 103 */ 104 typedef struct AwRtcClass { 105 /*< private >*/ 106 SysBusDeviceClass parent_class; 107 /*< public >*/ 108 109 /** Defines device specific register map */ 110 const uint8_t *regmap; 111 112 /** Size of the regmap in bytes */ 113 size_t regmap_size; 114 115 /** 116 * Read device specific register 117 * 118 * @offset: register offset to read 119 * @return true if register read successful, false otherwise 120 */ 121 bool (*read)(AwRtcState *s, uint32_t offset); 122 123 /** 124 * Write device specific register 125 * 126 * @offset: register offset to write 127 * @data: value to set in register 128 * @return true if register write successful, false otherwise 129 */ 130 bool (*write)(AwRtcState *s, uint32_t offset, uint32_t data); 131 132 } AwRtcClass; 133 134 #endif /* HW_MISC_ALLWINNER_RTC_H */ 135