1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/rtc/include/rtc-generic.h Sat May 04 01:31:54 2024 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 + * RTC (real-time clock) support for various devices.
1.6 + *
1.7 + * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/sys/types.h>
1.28 +#include <stdint.h>
1.29 +
1.30 +
1.31 +
1.32 +#ifdef __cplusplus
1.33 +
1.34 +#include <l4/devices/cpm-generic.h>
1.35 +#include <l4/devices/hw_register_block.h>
1.36 +#include <l4/devices/clocks.h>
1.37 +
1.38 +class Rtc_chip
1.39 +{
1.40 +protected:
1.41 + Cpm_chip *_cpm;
1.42 + Hw::Register_block<32> _regs;
1.43 +
1.44 + /* Utility methods. */
1.45 +
1.46 + uint32_t read_checked(unsigned reg);
1.47 + void wait();
1.48 + void write_enable();
1.49 + void _power_down();
1.50 +
1.51 + /* Device-specific methods. */
1.52 +
1.53 + virtual void _pre_power_down();
1.54 +
1.55 +public:
1.56 + explicit Rtc_chip(l4_addr_t addr, Cpm_chip *cpm);
1.57 +
1.58 + virtual enum Clock_identifiers get_clock();
1.59 +
1.60 + void disable();
1.61 +
1.62 + void enable();
1.63 +
1.64 + void alarm_disable();
1.65 +
1.66 + void alarm_enable();
1.67 +
1.68 + void wakeup_alarm_disable();
1.69 +
1.70 + void wakeup_alarm_enable();
1.71 +
1.72 + uint32_t get_seconds();
1.73 +
1.74 + void set_seconds(uint32_t seconds);
1.75 +
1.76 + uint32_t get_alarm_seconds();
1.77 +
1.78 + void set_alarm_seconds(uint32_t seconds);
1.79 +
1.80 + void set_regulator(uint32_t base, uint32_t adjustment);
1.81 +
1.82 + void hibernate();
1.83 +
1.84 + void power_down();
1.85 +};
1.86 +
1.87 +// Generic access to the RTC abstraction.
1.88 +
1.89 +Rtc_chip *new_rtc_chip(const char *name, l4_addr_t start, Cpm_chip *cpm);
1.90 +
1.91 +#endif /* __cplusplus */