1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12#pragma once
13
14#include <platsupport/io.h>
15#include <platsupport/plat/acpi/acpi.h>
16
17typedef struct rtc_time_date {
18    unsigned int second;
19    unsigned int minute;
20    unsigned int hour;
21    unsigned int day;
22    unsigned int month;
23    unsigned int year;
24} rtc_time_date_t;
25
26/* Retrieve the current time from the RTC. This can be passed a pre calculated
27 * century register, or 0 if the century should be 'guessed'. Century guessing
28 * works by having compiled in the current year at build time and using that
29 * to guess what the century most likely is. Should work for ~99 years.
30 * Recommended that a wrapper is used that retrieves century_register from ACPI
31 *
32 * @param io_port_ops io port operations for accessing the CMOS RTC
33 * @param century_register Offset of the century register in the CMOS, or 0 if doesn't exist
34 * @param time_date time and date structure to fill in
35 * @return returns 0 on success
36 */
37int rtc_get_time_date_reg(ps_io_port_ops_t *io_port_ops, unsigned int century_reg, rtc_time_date_t *time_date);
38
39/* Retrieves the century register from the ACPI tables. You can then use this
40 * to pass to the rtc_get_time_date_century function without needing to keep
41 * acpi tables around
42 *
43 * @param acpi acpi tables for detecting century register
44 * @return returns century register offset, or 0 if not found
45 */
46unsigned int rtc_get_century_register(acpi_t *acpi);
47
48/* Retrieve the current time from the RTC. This is the 'nicest', does everything
49 * for you function. But has dependency on ACPI
50 *
51 * @param io_port_ops io port operations for accessing the CMOS RTC
52 * @param acpi acpi tables for detecting century register
53 * @param time_date time and date structure to fill in
54 * @return returns 0 on success
55 */
56static inline int rtc_get_time_date(ps_io_port_ops_t *io_port_ops, acpi_t *acpi, rtc_time_date_t *time_date)
57{
58    return rtc_get_time_date_reg(io_port_ops, rtc_get_century_register(acpi), time_date);
59}
60
61