Skip to content

Commit

Permalink
drivers: i2c: stm32wl: fix i2c stm32wl power managment.
Browse files Browse the repository at this point in the history
Fixes the power managment of the i2c driver for the stm32wl (#[37414]).
Initialisation parameters for the stm32wl were lost when going out of
power mode STOP2 leaving the i2c driver in a unitialize state.
Re-initialising i2c timing when pm device resume solves the issue.

Signed-off-by: MartDur <martin.durietz@gmail.com>
  • Loading branch information
Martdur authored and MartinD committed May 16, 2024
1 parent 59212c1 commit bcf2830
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions drivers/i2c/i2c_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,42 @@ static int i2c_stm32_init(const struct device *dev)
return 0;
}

#if defined(CONFIG_SOC_SERIES_STM32WLX)
static int i2c_stm32_reinit_timing(const struct device *dev)
{
int ret;

Check warning on line 432 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:432 please, no spaces at the start of a line
const struct i2c_stm32_config *cfg = dev->config;

Check warning on line 433 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:433 please, no spaces at the start of a line
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);

Check warning on line 434 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:434 please, no spaces at the start of a line
uint32_t i2c_clock = 0U;

Check warning on line 435 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:435 please, no spaces at the start of a line

Check failure on line 436 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2c/i2c_ll_stm32.c:436 trailing whitespace

Check warning on line 436 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:436 please, no spaces at the start of a line
if (IS_ENABLED(STM32_I2C_DOMAIN_CLOCK_SUPPORT) && (cfg->pclk_len > 1)) {

Check warning on line 437 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:437 please, no spaces at the start of a line
if (clock_control_get_rate(clk, (clock_control_subsys_t)&cfg->pclken[1],

Check failure on line 438 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:438 code indent should use tabs where possible

Check warning on line 438 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:438 please, no spaces at the start of a line

Check warning on line 438 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:438 suspect code indent for conditional statements (8, 12)
&i2c_clock) < 0) {

Check failure on line 439 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:439 code indent should use tabs where possible

Check warning on line 439 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:439 please, no spaces at the start of a line
LOG_ERR("Failed call clock_control_get_rate(pclken[1])");

Check failure on line 440 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:440 code indent should use tabs where possible

Check warning on line 440 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2c/i2c_ll_stm32.c:440 please, no spaces at the start of a line
return -EIO;

Check failure on line 441 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:441 code indent should use tabs where possible
}

Check failure on line 442 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:442 code indent should use tabs where possible
} else {
if (clock_control_get_rate(clk, (clock_control_subsys_t)&cfg->pclken[0],

Check failure on line 444 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:444 code indent should use tabs where possible
&i2c_clock) < 0) {

Check failure on line 445 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:445 code indent should use tabs where possible
LOG_ERR("Failed call clock_control_get_rate(pclken[0])");

Check failure on line 446 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:446 code indent should use tabs where possible
return -EIO;

Check failure on line 447 in drivers/i2c/i2c_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2c/i2c_ll_stm32.c:447 code indent should use tabs where possible
}
}

#ifdef CONFIG_PM_DEVICE_RUNTIME
ret = clock_control_on(clk, (clock_control_subsys_t)&cfg->pclken[0]);
if (ret < 0) {
LOG_ERR("failure Enabling I2C clock");
return ret;
}
#endif

ret = stm32_i2c_configure_timing(dev, i2c_clock);

return ret;
}
#endif

#ifdef CONFIG_PM_DEVICE

static int i2c_stm32_pm_action(const struct device *dev, enum pm_device_action action)
Expand All @@ -435,6 +471,9 @@ static int i2c_stm32_pm_action(const struct device *dev, enum pm_device_action a
switch (action) {
case PM_DEVICE_ACTION_RESUME:
err = i2c_stm32_activate(dev);
#if defined(CONFIG_SOC_SERIES_STM32WLX)
i2c_stm32_reinit_timing(dev);
#endif
break;
case PM_DEVICE_ACTION_SUSPEND:
err = i2c_stm32_suspend(dev);
Expand Down

0 comments on commit bcf2830

Please sign in to comment.