1 /* 2 * Real-time clock support. 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 #include "rtc-x1600.h" 23 #include "rtc-defs.h" 24 25 26 27 // Peripheral abstraction. 28 29 Rtc_x1600_chip::Rtc_x1600_chip(l4_addr_t addr, Cpm_chip *cpm) 30 : Rtc_chip(addr, cpm) 31 { 32 } 33 34 void 35 Rtc_x1600_chip::_pre_power_down() 36 { 37 /* Set CPU frequency to L2 cache frequency before powering down. This is 38 apparently necessary according to the X1600 manual. */ 39 40 if (_cpm != NULL) 41 _cpm->set_frequency(Clock_cpu, _cpm->get_frequency(Clock_l2cache)); 42 } 43 44 Rtc_chip *x1600_rtc_chip(l4_addr_t rtc_base, Cpm_chip *cpm) 45 { 46 return new Rtc_x1600_chip(rtc_base, cpm); 47 } 48 49 50 51 // C language interface functions. 52 53 void 54 *x1600_rtc_init(l4_addr_t rtc_base, void *cpm) 55 { 56 return (void *) x1600_rtc_chip(rtc_base, static_cast<Cpm_chip *>(cpm)); 57 } 58 59 enum Clock_identifiers x1600_rtc_get_clock(void *rtc) 60 { 61 return static_cast<Rtc_chip *>(rtc)->get_clock(); 62 } 63 64 void x1600_rtc_disable(void *rtc) 65 { 66 static_cast<Rtc_chip *>(rtc)->disable(); 67 } 68 69 void x1600_rtc_enable(void *rtc) 70 { 71 static_cast<Rtc_chip *>(rtc)->enable(); 72 } 73 74 void x1600_rtc_alarm_disable(void *rtc) 75 { 76 static_cast<Rtc_chip *>(rtc)->alarm_disable(); 77 } 78 79 void x1600_rtc_alarm_enable(void *rtc) 80 { 81 static_cast<Rtc_chip *>(rtc)->alarm_enable(); 82 } 83 84 uint32_t x1600_rtc_get_seconds(void *rtc) 85 { 86 return static_cast<Rtc_chip *>(rtc)->get_seconds(); 87 } 88 89 void x1600_rtc_set_seconds(void *rtc, uint32_t seconds) 90 { 91 static_cast<Rtc_chip *>(rtc)->set_seconds(seconds); 92 } 93 94 uint32_t x1600_rtc_get_alarm_seconds(void *rtc) 95 { 96 return static_cast<Rtc_chip *>(rtc)->get_alarm_seconds(); 97 } 98 99 void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds) 100 { 101 static_cast<Rtc_chip *>(rtc)->set_alarm_seconds(seconds); 102 } 103 104 void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment) 105 { 106 static_cast<Rtc_chip *>(rtc)->set_regulator(base, adjustment); 107 } 108 109 void x1600_rtc_hibernate(void *rtc) 110 { 111 static_cast<Rtc_chip *>(rtc)->hibernate(); 112 } 113 114 void x1600_rtc_power_down(void *rtc) 115 { 116 static_cast<Rtc_chip *>(rtc)->power_down(); 117 }