From e97174705337e55327ce6454e626e31e323e70c6 Mon Sep 17 00:00:00 2001 From: Mulin Chao Date: Wed, 31 Mar 2021 22:17:22 -0700 Subject: zephyr: Add chip info API in cros_system driver Add the following chip_info API in cros_system driver for getting the chip information: 1. cros_system_chip_vendor() 2. cros_system_chip_name() 3. cros_system_chip_revision() BUG=none BRANCH=none TEST=build & boot ec on volteer Signed-off-by: Mulin Chao Signed-off-by: Wealian Liao Change-Id: I06718ff26f9cbee26cc9dbdcbbd02a0cc901d397 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2807477 Reviewed-by: Simon Glass Reviewed-by: Keith Short Reviewed-by: Jack Rosenthal Commit-Queue: Jack Rosenthal --- zephyr/include/drivers/cros_system.h | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/zephyr/include/drivers/cros_system.h b/zephyr/include/drivers/cros_system.h index 9010be2829..fcd3ef3b6a 100644 --- a/zephyr/include/drivers/cros_system.h +++ b/zephyr/include/drivers/cros_system.h @@ -61,11 +61,35 @@ typedef int (*cros_system_hibernate_api)(const struct device *dev, uint32_t seconds, uint32_t microseconds); +/** + * @typedef cros_system_chip_vendor_api + * @brief Callback API for getting the chip vendor. + * See cros_system_chip_vendor() for argument descriptions + */ +typedef const char *(*cros_system_chip_vendor_api)(const struct device *dev); + +/** + * @typedef cros_system_chip_name_api + * @brief Callback API for getting the chip name. + * See cros_system_chip_name() for argument descriptions + */ +typedef const char *(*cros_system_chip_name_api)(const struct device *dev); + +/** + * @typedef cros_system_chip_revision_api + * @brief Callback API for getting the chip revision. + * See cros_system_chip_revision() for argument descriptions + */ +typedef const char *(*cros_system_chip_revision_api)(const struct device *dev); + /** @brief Driver API structure. */ __subsystem struct cros_system_driver_api { cros_system_get_reset_cause_api get_reset_cause; cros_system_soc_reset_api soc_reset; cros_system_hibernate_api hibernate; + cros_system_chip_vendor_api chip_vendor; + cros_system_chip_name_api chip_name; + cros_system_chip_revision_api chip_revision; }; /** @@ -139,6 +163,71 @@ static inline int z_impl_cros_system_hibernate(const struct device *dev, return api->hibernate(dev, seconds, microseconds); } +/** + * @brief Get the chip vendor. + * + * @param dev Pointer to the device structure for the driver instance. + * @retval Chip vendor string if successful. + * @retval Null string if failure. + */ +__syscall const char *cros_system_chip_vendor(const struct device *dev); + +static inline const char * +z_impl_cros_system_chip_vendor(const struct device *dev) +{ + const struct cros_system_driver_api *api = + (const struct cros_system_driver_api *)dev->api; + + if (!api->chip_vendor) { + return ""; + } + + return api->chip_vendor(dev); +} + +/** + * @brief Get the chip name. + * + * @param dev Pointer to the device structure for the driver instance. + * @retval Chip name string if successful. + * @retval Null string if failure. + */ +__syscall const char *cros_system_chip_name(const struct device *dev); + +static inline const char *z_impl_cros_system_chip_name(const struct device *dev) +{ + const struct cros_system_driver_api *api = + (const struct cros_system_driver_api *)dev->api; + + if (!api->chip_name) { + return ""; + } + + return api->chip_name(dev); +} + +/** + * @brief Get the chip revision. + * + * @param dev Pointer to the device structure for the driver instance. + * @retval Chip revision string if successful. + * @retval Null string if failure. + */ +__syscall const char *cros_system_chip_revision(const struct device *dev); + +static inline const char * +z_impl_cros_system_chip_revision(const struct device *dev) +{ + const struct cros_system_driver_api *api = + (const struct cros_system_driver_api *)dev->api; + + if (!api->chip_revision) { + return ""; + } + + return api->chip_revision(dev); +} + /** * @} */ -- cgit v1.2.1