1 /* 2 * RTC (real-time clock) support for various devices. 3 * 4 * Copyright (C) 2023, 2024 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-generic.h> 32 #include <l4/devices/hw_register_block.h> 33 #include <l4/devices/clocks.h> 34 35 class Rtc_chip 36 { 37 protected: 38 Cpm_chip *_cpm; 39 Hw::Register_block<32> _regs; 40 41 /* Utility methods. */ 42 43 uint32_t read_checked(unsigned reg); 44 void wait(); 45 void write_enable(); 46 void _power_down(); 47 48 /* Device-specific methods. */ 49 50 virtual void _pre_power_down(); 51 52 public: 53 explicit Rtc_chip(l4_addr_t addr, Cpm_chip *cpm); 54 55 virtual enum Clock_identifiers get_clock(); 56 57 void disable(); 58 59 void enable(); 60 61 void alarm_disable(); 62 63 void alarm_enable(); 64 65 void wakeup_alarm_disable(); 66 67 void wakeup_alarm_enable(); 68 69 uint32_t get_seconds(); 70 71 void set_seconds(uint32_t seconds); 72 73 uint32_t get_alarm_seconds(); 74 75 void set_alarm_seconds(uint32_t seconds); 76 77 void set_regulator(uint32_t base, uint32_t adjustment); 78 79 void hibernate(); 80 81 void power_down(); 82 }; 83 84 // Generic access to the RTC abstraction. 85 86 Rtc_chip *new_rtc_chip(const char *name, l4_addr_t start, Cpm_chip *cpm); 87 88 #endif /* __cplusplus */