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/cpm-x1600.h> 32 #include <l4/devices/hw_register_block.h> 33 34 class Rtc_x1600_chip 35 { 36 protected: 37 /* Only use the CPM for the X1600, not other chips. */ 38 39 Cpm_x1600_chip *_cpm; 40 Hw::Register_block<32> _regs; 41 42 /* Utility methods. */ 43 44 uint32_t read_checked(unsigned reg); 45 void wait(); 46 void write_enable(); 47 48 public: 49 explicit Rtc_x1600_chip(l4_addr_t addr, Cpm_x1600_chip *cpm = NULL); 50 51 void disable(); 52 53 void enable(); 54 55 void alarm_disable(); 56 57 void alarm_enable(); 58 59 void wakeup_alarm_disable(); 60 61 void wakeup_alarm_enable(); 62 63 uint32_t get_seconds(); 64 65 void set_seconds(uint32_t seconds); 66 67 uint32_t get_alarm_seconds(); 68 69 void set_alarm_seconds(uint32_t seconds); 70 71 void set_regulator(uint32_t base, uint32_t adjustment); 72 73 void hibernate(); 74 75 void power_down(); 76 }; 77 78 #endif /* __cplusplus */ 79 80 81 82 /* C language interface. */ 83 84 EXTERN_C_BEGIN 85 86 void *x1600_rtc_init(l4_addr_t rtc_base, void *cpm); 87 88 void x1600_rtc_disable(void *rtc); 89 90 void x1600_rtc_enable(void *rtc); 91 92 void x1600_rtc_alarm_disable(void *rtc); 93 94 void x1600_rtc_alarm_enable(void *rtc); 95 96 void x1600_rtc_wakeup_alarm_disable(void *rtc); 97 98 void x1600_rtc_wakeup_alarm_enable(void *rtc); 99 100 uint32_t x1600_rtc_get_seconds(void *rtc); 101 102 void x1600_rtc_set_seconds(void *rtc, uint32_t seconds); 103 104 uint32_t x1600_rtc_get_alarm_seconds(void *rtc); 105 106 void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds); 107 108 void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment); 109 110 void x1600_rtc_hibernate(void *rtc); 111 112 void x1600_rtc_power_down(void *rtc); 113 114 EXTERN_C_END