summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/drivers/CMakeLists.txt1
-rw-r--r--zephyr/drivers/Kconfig1
-rw-r--r--zephyr/drivers/cros_rtc/CMakeLists.txt3
-rw-r--r--zephyr/drivers/cros_rtc/Kconfig3
-rw-r--r--zephyr/dts/bindings/cros_rtc/cros-rtc.yaml12
-rw-r--r--zephyr/include/drivers/cros_rtc.h224
6 files changed, 244 insertions, 0 deletions
diff --git a/zephyr/drivers/CMakeLists.txt b/zephyr/drivers/CMakeLists.txt
index 692eb456a8..6ffa0465e2 100644
--- a/zephyr/drivers/CMakeLists.txt
+++ b/zephyr/drivers/CMakeLists.txt
@@ -5,4 +5,5 @@
add_subdirectory(cros_bbram)
add_subdirectory(cros_flash)
add_subdirectory(cros_kb_raw)
+add_subdirectory(cros_rtc)
add_subdirectory(cros_system)
diff --git a/zephyr/drivers/Kconfig b/zephyr/drivers/Kconfig
index 69f30ce2b2..0b579713cb 100644
--- a/zephyr/drivers/Kconfig
+++ b/zephyr/drivers/Kconfig
@@ -5,4 +5,5 @@
rsource "cros_bbram/Kconfig"
rsource "cros_flash/Kconfig"
rsource "cros_kb_raw/Kconfig"
+rsource "cros_rtc/Kconfig"
rsource "cros_system/Kconfig"
diff --git a/zephyr/drivers/cros_rtc/CMakeLists.txt b/zephyr/drivers/cros_rtc/CMakeLists.txt
new file mode 100644
index 0000000000..80f1d03d96
--- /dev/null
+++ b/zephyr/drivers/cros_rtc/CMakeLists.txt
@@ -0,0 +1,3 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
diff --git a/zephyr/drivers/cros_rtc/Kconfig b/zephyr/drivers/cros_rtc/Kconfig
new file mode 100644
index 0000000000..80f1d03d96
--- /dev/null
+++ b/zephyr/drivers/cros_rtc/Kconfig
@@ -0,0 +1,3 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
diff --git a/zephyr/dts/bindings/cros_rtc/cros-rtc.yaml b/zephyr/dts/bindings/cros_rtc/cros-rtc.yaml
new file mode 100644
index 0000000000..f754826404
--- /dev/null
+++ b/zephyr/dts/bindings/cros_rtc/cros-rtc.yaml
@@ -0,0 +1,12 @@
+# Copyright 2021 Google LLC
+# SPDX-License-Identifier: Apache-2.0
+
+# Common fields for Chrome OS RTC devices
+
+include: base.yaml
+
+bus: crosrtc
+
+properties:
+ label:
+ required: true
diff --git a/zephyr/include/drivers/cros_rtc.h b/zephyr/include/drivers/cros_rtc.h
new file mode 100644
index 0000000000..695aabef73
--- /dev/null
+++ b/zephyr/include/drivers/cros_rtc.h
@@ -0,0 +1,224 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * @file
+ * @brief Chrome OS-specific API for real-time clock (RTC).
+ * This exists only support the interface expected by the Chrome OS EC. It
+ * provides raw access to RTC module.
+ *
+ * This API and any drivers should be removed once we can safely move to using
+ * the Zephyr rtc API.
+ */
+
+#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_
+#define ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_
+
+#include <kernel.h>
+#include <device.h>
+
+/**
+ * @brief CROS Real-Time Clock (RTC) Driver APIs
+ * @defgroup cros_rtc_interface CROS RTC Driver APIs
+ * @ingroup io_interfaces
+ * @{
+ */
+
+/**
+ * @brief RTC alarm callback
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ */
+typedef void (*cros_rtc_alarm_callback_t)(const struct device *dev);
+
+/**
+ * @cond INTERNAL_HIDDEN
+ *
+ * cros real-time clock driver API definition and system call entry points
+ *
+ * (Internal use only.)
+ */
+typedef int (*cros_rtc_api_configure)(const struct device *dev,
+ cros_rtc_alarm_callback_t callback);
+
+typedef int (*cros_rtc_api_get_value)(const struct device *dev,
+ uint32_t *value);
+
+typedef int (*cros_rtc_api_set_value)(const struct device *dev, uint32_t value);
+
+typedef int (*cros_rtc_api_get_alarm)(const struct device *dev,
+ uint32_t *seconds,
+ uint32_t *microseconds);
+
+typedef int (*cros_rtc_api_set_alarm)(const struct device *dev,
+ uint32_t seconds, uint32_t microseconds);
+
+typedef int (*cros_rtc_api_reset_alarm)(const struct device *dev);
+
+__subsystem struct cros_rtc_driver_api {
+ cros_rtc_api_configure configure;
+ cros_rtc_api_get_value get_value;
+ cros_rtc_api_set_value set_value;
+ cros_rtc_api_get_alarm get_alarm;
+ cros_rtc_api_set_alarm set_alarm;
+ cros_rtc_api_reset_alarm reset_alarm;
+};
+
+/**
+ * @endcond
+ */
+
+/**
+ * @brief Configure real-time clock callback func.
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ * @param callback Callback func when RTC alarm issued.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ * @retval -EINVAL Not valid callback func.
+ */
+__syscall int cros_rtc_configure(const struct device *dev,
+ cros_rtc_alarm_callback_t callback);
+static inline int z_impl_cros_rtc_configure(const struct device *dev,
+ cros_rtc_alarm_callback_t callback)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->configure) {
+ return -ENOTSUP;
+ }
+
+ return api->configure(dev, callback);
+}
+
+/**
+ * @brief Get the current real-time clock value.
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ * @param value Pointer to the number of current real-time clock value.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_rtc_get_value(const struct device *dev, uint32_t *value);
+static inline int z_impl_cros_rtc_get_value(const struct device *dev,
+ uint32_t *value)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->get_value) {
+ return -ENOTSUP;
+ }
+
+ return api->get_value(dev, value);
+}
+
+/**
+ * @brief Set a desired value to real-time clock.
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ * @param value Number of desired real-time clock value.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_rtc_set_value(const struct device *dev, uint32_t value);
+static inline int z_impl_cros_rtc_set_value(const struct device *dev,
+ uint32_t value)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->set_value) {
+ return -ENOTSUP;
+ }
+
+ return api->set_value(dev, value);
+}
+
+/**
+ * @brief Get a given time when an RTC alarm interrupt issued.
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ * @param seconds Pointer to number of seconds before RTC alarm issued.
+ * @param microseconds Pointer to number of micro-secs before RTC alarm issued.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_rtc_get_alarm(const struct device *dev, uint32_t *seconds,
+ uint32_t *microseconds);
+
+static inline int z_impl_cros_rtc_get_alarm(const struct device *dev,
+ uint32_t *seconds,
+ uint32_t *microseconds)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->get_alarm) {
+ return 0;
+ }
+
+ return api->get_alarm(dev, seconds, microseconds);
+}
+
+/**
+ * @brief Set up an RTC alarm interrupt at a given time from now
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ * @param seconds Number of seconds before RTC alarm issued.
+ * @param microseconds Number of microseconds before alarm RTC issued.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_rtc_set_alarm(const struct device *dev, uint32_t seconds,
+ uint32_t microseconds);
+
+static inline int z_impl_cros_rtc_set_alarm(const struct device *dev,
+ uint32_t seconds,
+ uint32_t microseconds)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->set_alarm) {
+ return 0;
+ }
+
+ return api->set_alarm(dev, seconds, microseconds);
+}
+
+/**
+ * @brief Disable and clear the RTC alarm interrupt.
+ *
+ * @param dev Pointer to the device structure for the RTC driver instance.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_rtc_reset_alarm(const struct device *dev);
+
+static inline int z_impl_cros_rtc_reset_alarm(const struct device *dev)
+{
+ const struct cros_rtc_driver_api *api =
+ (const struct cros_rtc_driver_api *)dev->api;
+
+ if (!api->reset_alarm) {
+ return -ENOTSUP;
+ }
+
+ return api->reset_alarm(dev);
+}
+
+/**
+ * @}
+ */
+#include <syscalls/cros_rtc.h>
+#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_ */