1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/rtc/include/rtc-x1600.h Thu Nov 16 01:15:40 2023 +0100
1.3 @@ -0,0 +1,98 @@
1.4 +/*
1.5 + * RTC (real-time clock) support for the X1600.
1.6 + *
1.7 + * Copyright (C) 2023 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/hw_register_block.h>
1.35 +
1.36 +class Rtc_x1600_chip
1.37 +{
1.38 +protected:
1.39 + Hw::Register_block<32> _regs;
1.40 +
1.41 + /* Utility methods. */
1.42 +
1.43 + uint32_t read_checked(unsigned reg);
1.44 + void wait();
1.45 + void write_enable();
1.46 +
1.47 +public:
1.48 + explicit Rtc_x1600_chip(l4_addr_t addr);
1.49 +
1.50 + void disable();
1.51 +
1.52 + void enable();
1.53 +
1.54 + void alarm_disable();
1.55 +
1.56 + void alarm_enable();
1.57 +
1.58 + uint32_t get_seconds();
1.59 +
1.60 + void set_seconds(uint32_t seconds);
1.61 +
1.62 + uint32_t get_alarm_seconds();
1.63 +
1.64 + void set_alarm_seconds(uint32_t seconds);
1.65 +
1.66 + void set_regulator(uint32_t base, uint32_t adjustment);
1.67 +
1.68 + void power_down();
1.69 +};
1.70 +
1.71 +#endif /* __cplusplus */
1.72 +
1.73 +
1.74 +
1.75 +/* C language interface. */
1.76 +
1.77 +EXTERN_C_BEGIN
1.78 +
1.79 +void *x1600_rtc_init(l4_addr_t rtc_base);
1.80 +
1.81 +void x1600_rtc_disable(void *rtc);
1.82 +
1.83 +void x1600_rtc_enable(void *rtc);
1.84 +
1.85 +void x1600_rtc_alarm_disable(void *rtc);
1.86 +
1.87 +void x1600_rtc_alarm_enable(void *rtc);
1.88 +
1.89 +uint32_t x1600_rtc_get_seconds(void *rtc);
1.90 +
1.91 +void x1600_rtc_set_seconds(void *rtc, uint32_t seconds);
1.92 +
1.93 +uint32_t x1600_rtc_get_alarm_seconds(void *rtc);
1.94 +
1.95 +void x1600_rtc_set_alarm_seconds(void *rtc, uint32_t seconds);
1.96 +
1.97 +void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment);
1.98 +
1.99 +void x1600_rtc_power_down(void *rtc);
1.100 +
1.101 +EXTERN_C_END