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 void _power_down(); 48 49 public: 50 explicit Rtc_x1600_chip(l4_addr_t addr, Cpm_x1600_chip *cpm = NULL); 51 52 void disable(); 53 54 void enable(); 55 56 void alarm_disable(); 57 58 void alarm_enable(); 59 60 void wakeup_alarm_disable(); 61 62 void wakeup_alarm_enable(); 63 64 uint32_t get_seconds(); 65 66 void set_seconds(uint32_t seconds); 67 68 uint32_t get_alarm_seconds(); 69 70 void set_alarm_seconds(uint32_t seconds); 71 72 void set_regulator(uint32_t base, uint32_t adjustment); 73 74 void hibernate(); 75 76 void power_down(); 77 }; 78 79 #endif /* __cplusplus */ 80 81 82 83 /* C language interface. */ 84 85 EXTERN_C_BEGIN 86 87 void *x1600_rtc_init(l4_addr_t rtc_base, void *cpm); 88 89 void x1600_rtc_disable(void *rtc); 90 91 void x1600_rtc_enable(void *rtc); 92 93 void x1600_rtc_alarm_disable(void *rtc); 94 95 void x1600_rtc_alarm_enable(void *rtc); 96 97 void x1600_rtc_wakeup_alarm_disable(void *rtc); 98 99 void x1600_rtc_wakeup_alarm_enable(void *rtc); 100 101 uint32_t x1600_rtc_get_seconds(void *rtc); 102 103 void x1600_rtc_set_seconds(void *rtc, uint32_t seconds); 104 105 uint32_t x1600_rtc_get_alarm_seconds(void *rtc); 106 107 void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds); 108 109 void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment); 110 111 void x1600_rtc_hibernate(void *rtc); 112 113 void x1600_rtc_power_down(void *rtc); 114 115 EXTERN_C_END