Skip to content

Commit 8a4fd9b

Browse files
Ayush1325kartben
authored andcommitted
drivers: cc13xx_cc26xx: pwm: Fix pm bug
- The current code will cause stall if some other subsystem (like subg) also needs to manage pm states. - So add a check to only re-enable suspend if it was disabled by PWM. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent 935c8e4 commit 8a4fd9b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/pwm/pwm_cc13xx_cc26xx_timer.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_PWM_LOG_LEVEL);
3434
#define PWM_INITIAL_DUTY 0U /* initially off */
3535

3636
struct pwm_cc13xx_cc26xx_data {
37+
bool standby_disabled;
3738
};
3839

3940
struct pwm_cc13xx_cc26xx_config {
@@ -56,14 +57,17 @@ static void write_value(const struct pwm_cc13xx_cc26xx_config *config, uint32_t
5657
}
5758

5859
static int set_period_and_pulse(const struct pwm_cc13xx_cc26xx_config *config, uint32_t period,
59-
uint32_t pulse)
60+
uint32_t pulse, struct pwm_cc13xx_cc26xx_data *data)
6061
{
6162
uint32_t match_value = pulse;
6263

6364
if (pulse == 0U) {
6465
TimerDisable(config->gpt_base, TIMER_B);
6566
#ifdef CONFIG_PM
66-
Power_releaseConstraint(PowerCC26XX_DISALLOW_STANDBY);
67+
if (data->standby_disabled) {
68+
Power_releaseConstraint(PowerCC26XX_DISALLOW_STANDBY);
69+
data->standby_disabled = false;
70+
}
6771
#endif
6872
match_value = period + 1;
6973
}
@@ -86,7 +90,10 @@ static int set_period_and_pulse(const struct pwm_cc13xx_cc26xx_config *config, u
8690

8791
if (pulse > 0U) {
8892
#ifdef CONFIG_PM
89-
Power_setConstraint(PowerCC26XX_DISALLOW_STANDBY);
93+
if (!data->standby_disabled) {
94+
Power_setConstraint(PowerCC26XX_DISALLOW_STANDBY);
95+
data->standby_disabled = true;
96+
}
9097
#endif
9198
TimerEnable(config->gpt_base, TIMER_B);
9299
}
@@ -110,7 +117,7 @@ static int set_cycles(const struct device *dev, uint32_t channel, uint32_t perio
110117
HWREG(config->gpt_base + GPT_O_CTL) |= GPT_CTL_TBPWML_NORMAL;
111118
}
112119

113-
set_period_and_pulse(config, period, pulse);
120+
set_period_and_pulse(config, period, pulse, dev->data);
114121

115122
return 0;
116123
}
@@ -223,7 +230,7 @@ static int init_pwm(const struct device *dev)
223230
HWREG(config->gpt_base + GPT_O_TBMR) = GPT_TBMR_TBAMS_PWM | GPT_TBMR_TBMRSU_TOUPDATE |
224231
GPT_TBMR_TBPWMIE_EN | GPT_TBMR_TBMR_PERIODIC;
225232

226-
set_period_and_pulse(config, PWM_INITIAL_PERIOD, PWM_INITIAL_DUTY);
233+
set_period_and_pulse(config, PWM_INITIAL_PERIOD, PWM_INITIAL_DUTY, dev->data);
227234

228235
return 0;
229236
}

0 commit comments

Comments
 (0)