1 /* 2 * RTC (real-time clock) support for the X1600. 3 * 4 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (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, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/hw_register_block.h> 32 33 class Rtc_x1600_chip 34 { 35 protected: 36 Hw::Register_block<32> _regs; 37 38 /* Utility methods. */ 39 40 uint32_t read_checked(unsigned reg); 41 void wait(); 42 void write_enable(); 43 44 public: 45 explicit Rtc_x1600_chip(l4_addr_t addr); 46 47 void disable(); 48 49 void enable(); 50 51 void alarm_disable(); 52 53 void alarm_enable(); 54 55 void wakeup_alarm_disable(); 56 57 void wakeup_alarm_enable(); 58 59 uint32_t get_seconds(); 60 61 void set_seconds(uint32_t seconds); 62 63 uint32_t get_alarm_seconds(); 64 65 void set_alarm_seconds(uint32_t seconds); 66 67 void set_regulator(uint32_t base, uint32_t adjustment); 68 69 void hibernate(); 70 71 void power_down(); 72 }; 73 74 #endif /* __cplusplus */ 75 76 77 78 /* C language interface. */ 79 80 EXTERN_C_BEGIN 81 82 void *x1600_rtc_init(l4_addr_t rtc_base); 83 84 void x1600_rtc_disable(void *rtc); 85 86 void x1600_rtc_enable(void *rtc); 87 88 void x1600_rtc_alarm_disable(void *rtc); 89 90 void x1600_rtc_alarm_enable(void *rtc); 91 92 void x1600_rtc_wakeup_alarm_disable(void *rtc); 93 94 void x1600_rtc_wakeup_alarm_enable(void *rtc); 95 96 uint32_t x1600_rtc_get_seconds(void *rtc); 97 98 void x1600_rtc_set_seconds(void *rtc, uint32_t seconds); 99 100 uint32_t x1600_rtc_get_alarm_seconds(void *rtc); 101 102 void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds); 103 104 void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment); 105 106 void x1600_rtc_hibernate(void *rtc); 107 108 void x1600_rtc_power_down(void *rtc); 109 110 EXTERN_C_END