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