Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions drivers/mfd/mfd_npm2100.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
#include <zephyr/drivers/gpio/gpio_utils.h>
#include <zephyr/drivers/mfd/npm2100.h>

#define EVENTS_SET 0x00U
#define EVENTS_CLR 0x05U
#define INTEN_SET 0x0AU
#define GPIO_CONFIG 0x80U
#define GPIO_USAGE 0x83U
#define TIMER_TASKS_START 0xB0U
#define TIMER_CONFIG 0xB3U
#define TIMER_TARGET 0xB4U
#define TIMER_STATUS 0xB7U
#define SHPHLD_WAKEUP 0xC1U
#define SHPHLD_SHPHLD 0xC2U
#define HIBERNATE_TASKS_HIBER 0xC8U
#define RESET_TASKS_RESET 0xD0U
#define RESET_BUTTON 0xD2U
#define RESET_PIN 0xD3U
#define RESET_WRITESTICKY 0xDBU
#define RESET_STROBESTICKY 0xDCU
#define EVENTS_SET 0x00U
#define EVENTS_CLR 0x05U
#define INTEN_SET 0x0AU
#define GPIO_CONFIG 0x80U
#define GPIO_USAGE 0x83U
#define TIMER_TASKS_START 0xB0U
#define TIMER_CONFIG 0xB3U
#define TIMER_TARGET 0xB4U
#define TIMER_STATUS 0xB7U
#define SHPHLD_WAKEUP 0xC1U
#define SHPHLD_SHPHLD 0xC2U
#define HIBERNATE_TASKS_HIBER 0xC8U
#define HIBERNATE_TASKS_HIBERPT 0xC9U
#define RESET_TASKS_RESET 0xD0U
#define RESET_BUTTON 0xD2U
#define RESET_PIN 0xD3U
#define RESET_WRITESTICKY 0xDBU
#define RESET_STROBESTICKY 0xDCU

#define SHPHLD_RESISTOR_MASK 0x03U
#define SHPHLD_RESISTOR_PULLUP 0x00U
Expand Down Expand Up @@ -218,7 +219,7 @@ static int config_shphold(const struct device *dev)
}

reg = config->shiphold_hibernate_wakeup ? WAKEUP_HIBERNATE_PIN : WAKEUP_HIBERNATE_NOPIN;
if ((config->shiphold_flags & GPIO_ACTIVE_HIGH) != 0U) {
if ((config->shiphold_flags & GPIO_ACTIVE_LOW) == 0U) {
reg |= WAKEUP_EDGE_RISING;
}

Expand Down Expand Up @@ -337,7 +338,7 @@ int mfd_npm2100_reset(const struct device *dev)
return i2c_reg_write_byte_dt(&config->i2c, RESET_TASKS_RESET, 1U);
}

int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms)
int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms, bool pass_through)
{
const struct mfd_npm2100_config *config = dev->config;
int ret;
Expand All @@ -354,18 +355,8 @@ int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms)
}
}

/* Ensure shiphold button is enabled so that wakeup will work */
ret = i2c_reg_write_byte_dt(&config->i2c, RESET_WRITESTICKY, 0);
if (ret < 0) {
return ret;
}

ret = i2c_reg_write_byte_dt(&config->i2c, RESET_STROBESTICKY, 1U);
if (ret < 0) {
return ret;
}

return i2c_reg_write_byte_dt(&config->i2c, HIBERNATE_TASKS_HIBER, 1U);
return i2c_reg_write_byte_dt(
&config->i2c, pass_through ? HIBERNATE_TASKS_HIBERPT : HIBERNATE_TASKS_HIBER, 1U);
}

int mfd_npm2100_add_callback(const struct device *dev, struct gpio_callback *callback)
Expand Down
12 changes: 0 additions & 12 deletions drivers/regulator/regulator_npm2100.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,18 +642,6 @@ static int regulator_npm2100_ship_mode(const struct device *dev)
{
const struct regulator_npm2100_pconfig *pconfig = dev->config;

/* Ensure shiphold button is enabled so that wakeup will work */
int ret = i2c_reg_write_byte_dt(&pconfig->i2c, RESET_WRITESTICKY, 0);

if (ret < 0) {
return ret;
}

ret = i2c_reg_write_byte_dt(&pconfig->i2c, RESET_STROBESTICKY, 1U);
if (ret < 0) {
return ret;
}

return i2c_reg_write_byte_dt(&pconfig->i2c, SHIP_TASK_SHIP, 1U);
}

Expand Down
5 changes: 4 additions & 1 deletion include/zephyr/drivers/mfd/npm2100.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ int mfd_npm2100_reset(const struct device *dev);
* @brief npm2100 hibernate
*
* Enters low power state, and wakes after specified time or "shphld" pin signal.
* Pass-through mode can be used when the battery voltage is high enough to supply the pmic directly
* without boosting. This lowers the power consumption of the pmic when hibernate mode is active.
*
* @param dev npm2100 mfd device
* @param time_ms timer value in ms. Set to 0 to disable timer.
* @param pass_through set to use pass-through hibernate mode.
* @retval 0 If successful
* @retval -EINVAL if time value is too large
* @retval -EBUSY if the timer is already in use.
* @retval -errno In case of any bus error (see i2c_write_dt())
*/
int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms);
int mfd_npm2100_hibernate(const struct device *dev, uint32_t time_ms, bool pass_through);

/**
* @brief Add npm2100 event callback
Expand Down