Skip to content

Commit 37134f5

Browse files
AlessandroLuokartben
authored andcommitted
drivers: i2c: ambiq: optimize ambiq i2c device pm
This commit optimizes the device pm for ambiq i2c driver by adding pinctrl sleep/resume. Signed-off-by: Hao Luo <hluo@ambiq.com>
1 parent fe63225 commit 37134f5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

drivers/i2c/i2c_ambiq.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,30 @@ static DEVICE_API(i2c, i2c_ambiq_driver_api) = {
428428
#ifdef CONFIG_PM_DEVICE
429429
static int i2c_ambiq_pm_action(const struct device *dev, enum pm_device_action action)
430430
{
431+
const struct i2c_ambiq_config *config = dev->config;
431432
struct i2c_ambiq_data *data = dev->data;
432-
uint32_t ret;
433+
int ret;
433434
am_hal_sysctrl_power_state_e status;
434435

435436
switch (action) {
436437
case PM_DEVICE_ACTION_RESUME:
438+
/* Move pins to active/default state */
439+
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
440+
if (ret < 0) {
441+
LOG_ERR("I2C pinctrl setup failed (%d)", ret);
442+
return ret;
443+
}
437444
status = AM_HAL_SYSCTRL_WAKE;
438445
break;
439446
case PM_DEVICE_ACTION_SUSPEND:
447+
/* Move pins to sleep state */
448+
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_SLEEP);
449+
if (ret == -ENOENT) {
450+
/* Warn but don't block suspend */
451+
LOG_WRN("I2C pinctrl sleep state not available ");
452+
} else if (ret < 0) {
453+
return ret;
454+
}
440455
status = AM_HAL_SYSCTRL_DEEPSLEEP;
441456
break;
442457
default:

0 commit comments

Comments
 (0)