hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/pwm/pwm-stm32-lp.c
....@@ -13,6 +13,7 @@
1313 #include <linux/mfd/stm32-lptimer.h>
1414 #include <linux/module.h>
1515 #include <linux/of.h>
16
+#include <linux/pinctrl/consumer.h>
1617 #include <linux/platform_device.h>
1718 #include <linux/pwm.h>
1819
....@@ -31,7 +32,7 @@
3132 #define STM32_LPTIM_MAX_PRESCALER 128
3233
3334 static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm,
34
- struct pwm_state *state)
35
+ const struct pwm_state *state)
3536 {
3637 struct stm32_pwm_lp *priv = to_stm32_pwm_lp(chip);
3738 unsigned long long prd, div, dty;
....@@ -60,7 +61,7 @@
6061 do_div(div, NSEC_PER_SEC);
6162 if (!div) {
6263 /* Clock is too slow to achieve requested period. */
63
- dev_dbg(priv->chip.dev, "Can't reach %u ns\n", state->period);
64
+ dev_dbg(priv->chip.dev, "Can't reach %llu ns\n", state->period);
6465 return -EINVAL;
6566 }
6667
....@@ -126,7 +127,7 @@
126127
127128 /* ensure CMP & ARR registers are properly written */
128129 ret = regmap_read_poll_timeout(priv->regmap, STM32_LPTIM_ISR, val,
129
- (val & STM32_LPTIM_CMPOK_ARROK),
130
+ (val & STM32_LPTIM_CMPOK_ARROK) == STM32_LPTIM_CMPOK_ARROK,
130131 100, 1000);
131132 if (ret) {
132133 dev_err(priv->chip.dev, "ARR/CMP registers write issue\n");
....@@ -227,6 +228,29 @@
227228 return pwmchip_remove(&priv->chip);
228229 }
229230
231
+static int __maybe_unused stm32_pwm_lp_suspend(struct device *dev)
232
+{
233
+ struct stm32_pwm_lp *priv = dev_get_drvdata(dev);
234
+ struct pwm_state state;
235
+
236
+ pwm_get_state(&priv->chip.pwms[0], &state);
237
+ if (state.enabled) {
238
+ dev_err(dev, "The consumer didn't stop us (%s)\n",
239
+ priv->chip.pwms[0].label);
240
+ return -EBUSY;
241
+ }
242
+
243
+ return pinctrl_pm_select_sleep_state(dev);
244
+}
245
+
246
+static int __maybe_unused stm32_pwm_lp_resume(struct device *dev)
247
+{
248
+ return pinctrl_pm_select_default_state(dev);
249
+}
250
+
251
+static SIMPLE_DEV_PM_OPS(stm32_pwm_lp_pm_ops, stm32_pwm_lp_suspend,
252
+ stm32_pwm_lp_resume);
253
+
230254 static const struct of_device_id stm32_pwm_lp_of_match[] = {
231255 { .compatible = "st,stm32-pwm-lp", },
232256 {},
....@@ -239,6 +263,7 @@
239263 .driver = {
240264 .name = "stm32-pwm-lp",
241265 .of_match_table = of_match_ptr(stm32_pwm_lp_of_match),
266
+ .pm = &stm32_pwm_lp_pm_ops,
242267 },
243268 };
244269 module_platform_driver(stm32_pwm_lp_driver);