1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_NPM2100_H_ 7 #define ZEPHYR_INCLUDE_DRIVERS_MFD_NPM2100_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** 14 * @defgroup mdf_interface_npm2100 MFD NPM2100 Interface 15 * @ingroup mfd_interfaces 16 * @{ 17 */ 18 19 #include <stddef.h> 20 #include <stdint.h> 21 22 #include <zephyr/device.h> 23 #include <zephyr/drivers/gpio.h> 24 25 enum mfd_npm2100_event { 26 NPM2100_EVENT_SYS_DIETEMP_WARN, 27 NPM2100_EVENT_SYS_SHIPHOLD_FALL, 28 NPM2100_EVENT_SYS_SHIPHOLD_RISE, 29 NPM2100_EVENT_SYS_PGRESET_FALL, 30 NPM2100_EVENT_SYS_PGRESET_RISE, 31 NPM2100_EVENT_SYS_TIMER_EXPIRY, 32 NPM2100_EVENT_ADC_VBAT_READY, 33 NPM2100_EVENT_ADC_DIETEMP_READY, 34 NPM2100_EVENT_ADC_DROOP_DETECT, 35 NPM2100_EVENT_ADC_VOUT_READY, 36 NPM2100_EVENT_GPIO0_FALL, 37 NPM2100_EVENT_GPIO0_RISE, 38 NPM2100_EVENT_GPIO1_FALL, 39 NPM2100_EVENT_GPIO1_RISE, 40 NPM2100_EVENT_BOOST_VBAT_WARN, 41 NPM2100_EVENT_BOOST_VOUT_MIN, 42 NPM2100_EVENT_BOOST_VOUT_WARN, 43 NPM2100_EVENT_BOOST_VOUT_DPS, 44 NPM2100_EVENT_BOOST_VOUT_OK, 45 NPM2100_EVENT_LDOSW_OCP, 46 NPM2100_EVENT_LDOSW_VINTFAIL, 47 NPM2100_EVENT_MAX 48 }; 49 50 enum mfd_npm2100_timer_mode { 51 NPM2100_TIMER_MODE_GENERAL_PURPOSE, 52 NPM2100_TIMER_MODE_WDT_RESET, 53 NPM2100_TIMER_MODE_WDT_POWER_CYCLE, 54 NPM2100_TIMER_MODE_WAKEUP, 55 }; 56 57 /** 58 * @brief Write npm2100 timer register 59 * 60 * The timer tick resolution is 1/64 seconds. 61 * This function does not start the timer (see mfd_npm2100_start_timer()). 62 * 63 * @param dev npm2100 mfd device 64 * @param time_ms timer value in ms 65 * @param mode timer mode 66 * @retval 0 If successful 67 * @retval -EINVAL if time value is too large 68 * @retval -errno In case of any bus error (see i2c_write_dt()) 69 */ 70 int mfd_npm2100_set_timer(const struct device *dev, uint32_t time_ms, 71 enum mfd_npm2100_timer_mode mode); 72 73 /** 74 * @brief Start npm2100 timer 75 * 76 * @param dev npm2100 mfd device 77 * @retval 0 If successful 78 * @retval -errno In case of any bus error (see i2c_write_dt()) 79 */ 80 int mfd_npm2100_start_timer(const struct device *dev); 81 82 /** 83 * @brief npm2100 full power reset 84 * 85 * @param dev npm2100 mfd device 86 * @retval 0 If successful 87 * @retval -errno In case of any bus error (see i2c_write_dt()) 88 */ 89 int mfd_npm2100_reset(const struct device *dev); 90 91 /** 92 * @brief npm2100 hibernate 93 * 94 * Enters low power state, and wakes after specified time or "shphld" pin signal. 95 * 96 * @param dev npm2100 mfd device 97 * @param time_ms timer value in ms. Set to 0 to disable timer. 98 * @retval 0 If successful 99 * @retval -EINVAL if time value is too large 100 * @retval -EBUSY if the timer is already in use. 101 * @retval -errno In case of any bus error (see i2c_write_dt()) 102 */ 103 int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms); 104 105 /** 106 * @brief Add npm2100 event callback 107 * 108 * @param dev npm2100 mfd device 109 * @param callback callback 110 * @return 0 on success, -errno on failure 111 */ 112 int mfd_npm2100_add_callback(const struct device *dev, struct gpio_callback *callback); 113 114 /** 115 * @brief Remove npm2100 event callback 116 * 117 * @param dev npm2100 mfd device 118 * @param callback callback 119 * @return 0 on success, -errno on failure 120 */ 121 int mfd_npm2100_remove_callback(const struct device *dev, struct gpio_callback *callback); 122 123 /** @} */ 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_NPM2100_H_ */ 130