paul@237 | 1 | /* |
paul@237 | 2 | * RTC (real-time clock) support for the X1600. |
paul@237 | 3 | * |
paul@237 | 4 | * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> |
paul@237 | 5 | * |
paul@237 | 6 | * This program is free software; you can redistribute it and/or |
paul@237 | 7 | * modify it under the terms of the GNU General Public License as |
paul@237 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@237 | 9 | * the License, or (at your option) any later version. |
paul@237 | 10 | * |
paul@237 | 11 | * This program is distributed in the hope that it will be useful, |
paul@237 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@237 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@237 | 14 | * GNU General Public License for more details. |
paul@237 | 15 | * |
paul@237 | 16 | * You should have received a copy of the GNU General Public License |
paul@237 | 17 | * along with this program; if not, write to the Free Software |
paul@237 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@237 | 19 | * Boston, MA 02110-1301, USA |
paul@237 | 20 | */ |
paul@237 | 21 | |
paul@237 | 22 | #pragma once |
paul@237 | 23 | |
paul@237 | 24 | #include <l4/sys/types.h> |
paul@237 | 25 | #include <stdint.h> |
paul@237 | 26 | |
paul@237 | 27 | |
paul@237 | 28 | |
paul@237 | 29 | #ifdef __cplusplus |
paul@237 | 30 | |
paul@240 | 31 | #include <l4/devices/cpm-x1600.h> |
paul@237 | 32 | #include <l4/devices/hw_register_block.h> |
paul@237 | 33 | |
paul@237 | 34 | class Rtc_x1600_chip |
paul@237 | 35 | { |
paul@237 | 36 | protected: |
paul@240 | 37 | /* Only use the CPM for the X1600, not other chips. */ |
paul@240 | 38 | |
paul@240 | 39 | Cpm_x1600_chip *_cpm; |
paul@237 | 40 | Hw::Register_block<32> _regs; |
paul@237 | 41 | |
paul@237 | 42 | /* Utility methods. */ |
paul@237 | 43 | |
paul@237 | 44 | uint32_t read_checked(unsigned reg); |
paul@237 | 45 | void wait(); |
paul@237 | 46 | void write_enable(); |
paul@242 | 47 | void _power_down(); |
paul@237 | 48 | |
paul@237 | 49 | public: |
paul@240 | 50 | explicit Rtc_x1600_chip(l4_addr_t addr, Cpm_x1600_chip *cpm = NULL); |
paul@237 | 51 | |
paul@237 | 52 | void disable(); |
paul@237 | 53 | |
paul@237 | 54 | void enable(); |
paul@237 | 55 | |
paul@237 | 56 | void alarm_disable(); |
paul@237 | 57 | |
paul@237 | 58 | void alarm_enable(); |
paul@237 | 59 | |
paul@238 | 60 | void wakeup_alarm_disable(); |
paul@238 | 61 | |
paul@238 | 62 | void wakeup_alarm_enable(); |
paul@238 | 63 | |
paul@237 | 64 | uint32_t get_seconds(); |
paul@237 | 65 | |
paul@237 | 66 | void set_seconds(uint32_t seconds); |
paul@237 | 67 | |
paul@237 | 68 | uint32_t get_alarm_seconds(); |
paul@237 | 69 | |
paul@237 | 70 | void set_alarm_seconds(uint32_t seconds); |
paul@237 | 71 | |
paul@237 | 72 | void set_regulator(uint32_t base, uint32_t adjustment); |
paul@237 | 73 | |
paul@238 | 74 | void hibernate(); |
paul@238 | 75 | |
paul@237 | 76 | void power_down(); |
paul@237 | 77 | }; |
paul@237 | 78 | |
paul@237 | 79 | #endif /* __cplusplus */ |
paul@237 | 80 | |
paul@237 | 81 | |
paul@237 | 82 | |
paul@237 | 83 | /* C language interface. */ |
paul@237 | 84 | |
paul@237 | 85 | EXTERN_C_BEGIN |
paul@237 | 86 | |
paul@240 | 87 | void *x1600_rtc_init(l4_addr_t rtc_base, void *cpm); |
paul@237 | 88 | |
paul@237 | 89 | void x1600_rtc_disable(void *rtc); |
paul@237 | 90 | |
paul@237 | 91 | void x1600_rtc_enable(void *rtc); |
paul@237 | 92 | |
paul@237 | 93 | void x1600_rtc_alarm_disable(void *rtc); |
paul@237 | 94 | |
paul@237 | 95 | void x1600_rtc_alarm_enable(void *rtc); |
paul@237 | 96 | |
paul@238 | 97 | void x1600_rtc_wakeup_alarm_disable(void *rtc); |
paul@238 | 98 | |
paul@238 | 99 | void x1600_rtc_wakeup_alarm_enable(void *rtc); |
paul@238 | 100 | |
paul@237 | 101 | uint32_t x1600_rtc_get_seconds(void *rtc); |
paul@237 | 102 | |
paul@237 | 103 | void x1600_rtc_set_seconds(void *rtc, uint32_t seconds); |
paul@237 | 104 | |
paul@237 | 105 | uint32_t x1600_rtc_get_alarm_seconds(void *rtc); |
paul@237 | 106 | |
paul@237 | 107 | void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds); |
paul@237 | 108 | |
paul@237 | 109 | void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment); |
paul@237 | 110 | |
paul@238 | 111 | void x1600_rtc_hibernate(void *rtc); |
paul@238 | 112 | |
paul@237 | 113 | void x1600_rtc_power_down(void *rtc); |
paul@237 | 114 | |
paul@237 | 115 | EXTERN_C_END |