When you're interested in the actual register settings the driver
chooses or interprets you want to see them also for calls that hit
corner cases.
Make sure that all calls to stm32_pwm_round_waveform_tohw() and
stm32_pwm_round_waveform_fromhw() emit the debug message about the
register settings.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
drivers/pwm/pwm-stm32.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index c6625f51a199..dca5d09d80b9 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -180,11 +180,11 @@ static int stm32_pwm_round_waveform_tohw(struct pwm_chip *chip,
wfhw->ccr = min_t(u64, ccr, wfhw->arr + 1);
+out:
dev_dbg(&chip->dev, "pwm#%u: %lld/%lld [+%lld] @%lu -> CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x\n",
pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns,
rate, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr);
-out:
clk_disable(priv->clk);
return ret;
@@ -236,17 +236,16 @@ static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip,
wf->duty_length_ns = ccr_ns;
wf->duty_offset_ns = 0;
}
-
- dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
- pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
- wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns);
-
} else {
*wf = (struct pwm_waveform){
.period_length_ns = 0,
};
}
+ dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
+ pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
+ wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns);
+
return 0;
}
--
2.47.2
Hi Uwe,
kernel test robot noticed the following build errors:
[auto build test ERROR on e48e99b6edf41c69c5528aa7ffb2daf3c59ee105]
url: https://github.com/intel-lab-lkp/linux/commits/Uwe-Kleine-K-nig/pwm-Let-pwm_set_waveform-succeed-even-if-lowlevel-driver-rounded-up/20250405-173024
base: e48e99b6edf41c69c5528aa7ffb2daf3c59ee105
patch link: https://lore.kernel.org/r/fe154e79319da5ff4159cdc71201a9d3b395e491.1743844730.git.u.kleine-koenig%40baylibre.com
patch subject: [PATCH 4/6] pwm: stm32: Emit debug output also for corner cases of the rounding callbacks
config: x86_64-buildonly-randconfig-001-20250406 (https://download.01.org/0day-ci/archive/20250406/202504061207.97zbNPvV-lkp@intel.com/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250406/202504061207.97zbNPvV-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504061207.97zbNPvV-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/pwm/pwm-stm32.c:246:60: error: use of undeclared identifier 'rate'
246 | pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
| ^
1 error generated.
vim +/rate +246 drivers/pwm/pwm-stm32.c
208
209 static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip,
210 struct pwm_device *pwm,
211 const void *_wfhw,
212 struct pwm_waveform *wf)
213 {
214 const struct stm32_pwm_waveform *wfhw = _wfhw;
215 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
216 unsigned int ch = pwm->hwpwm;
217
218 if (wfhw->ccer & TIM_CCER_CCxE(ch + 1)) {
219 unsigned long rate = clk_get_rate(priv->clk);
220 u64 ccr_ns;
221
222 /* The result doesn't overflow for rate >= 15259 */
223 wf->period_length_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1),
224 NSEC_PER_SEC, rate);
225
226 ccr_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * wfhw->ccr,
227 NSEC_PER_SEC, rate);
228
229 if (wfhw->ccer & TIM_CCER_CCxP(ch + 1)) {
230 wf->duty_length_ns =
231 stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1 - wfhw->ccr),
232 NSEC_PER_SEC, rate);
233
234 wf->duty_offset_ns = ccr_ns;
235 } else {
236 wf->duty_length_ns = ccr_ns;
237 wf->duty_offset_ns = 0;
238 }
239 } else {
240 *wf = (struct pwm_waveform){
241 .period_length_ns = 0,
242 };
243 }
244
245 dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
> 246 pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
247 wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns);
248
249 return 0;
250 }
251
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Uwe,
kernel test robot noticed the following build errors:
[auto build test ERROR on e48e99b6edf41c69c5528aa7ffb2daf3c59ee105]
url: https://github.com/intel-lab-lkp/linux/commits/Uwe-Kleine-K-nig/pwm-Let-pwm_set_waveform-succeed-even-if-lowlevel-driver-rounded-up/20250405-173024
base: e48e99b6edf41c69c5528aa7ffb2daf3c59ee105
patch link: https://lore.kernel.org/r/fe154e79319da5ff4159cdc71201a9d3b395e491.1743844730.git.u.kleine-koenig%40baylibre.com
patch subject: [PATCH 4/6] pwm: stm32: Emit debug output also for corner cases of the rounding callbacks
config: arm-randconfig-004-20250406 (https://download.01.org/0day-ci/archive/20250406/202504060517.dHXuUANs-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250406/202504060517.dHXuUANs-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504060517.dHXuUANs-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/linux/device.h:15,
from include/linux/dmaengine.h:8,
from include/linux/mfd/stm32-timers.h:11,
from drivers/pwm/pwm-stm32.c:12:
drivers/pwm/pwm-stm32.c: In function 'stm32_pwm_round_waveform_fromhw':
>> drivers/pwm/pwm-stm32.c:246:60: error: 'rate' undeclared (first use in this function)
246 | pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
| ^~~~
include/linux/dev_printk.h:139:35: note: in definition of macro 'dev_no_printk'
139 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
drivers/pwm/pwm-stm32.c:245:2: note: in expansion of macro 'dev_dbg'
245 | dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
| ^~~~~~~
drivers/pwm/pwm-stm32.c:246:60: note: each undeclared identifier is reported only once for each function it appears in
246 | pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
| ^~~~
include/linux/dev_printk.h:139:35: note: in definition of macro 'dev_no_printk'
139 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
drivers/pwm/pwm-stm32.c:245:2: note: in expansion of macro 'dev_dbg'
245 | dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
| ^~~~~~~
vim +/rate +246 drivers/pwm/pwm-stm32.c
208
209 static int stm32_pwm_round_waveform_fromhw(struct pwm_chip *chip,
210 struct pwm_device *pwm,
211 const void *_wfhw,
212 struct pwm_waveform *wf)
213 {
214 const struct stm32_pwm_waveform *wfhw = _wfhw;
215 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
216 unsigned int ch = pwm->hwpwm;
217
218 if (wfhw->ccer & TIM_CCER_CCxE(ch + 1)) {
219 unsigned long rate = clk_get_rate(priv->clk);
220 u64 ccr_ns;
221
222 /* The result doesn't overflow for rate >= 15259 */
223 wf->period_length_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1),
224 NSEC_PER_SEC, rate);
225
226 ccr_ns = stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * wfhw->ccr,
227 NSEC_PER_SEC, rate);
228
229 if (wfhw->ccer & TIM_CCER_CCxP(ch + 1)) {
230 wf->duty_length_ns =
231 stm32_pwm_mul_u64_u64_div_u64_roundup(((u64)wfhw->psc + 1) * (wfhw->arr + 1 - wfhw->ccr),
232 NSEC_PER_SEC, rate);
233
234 wf->duty_offset_ns = ccr_ns;
235 } else {
236 wf->duty_length_ns = ccr_ns;
237 wf->duty_offset_ns = 0;
238 }
239 } else {
240 *wf = (struct pwm_waveform){
241 .period_length_ns = 0,
242 };
243 }
244
245 dev_dbg(&chip->dev, "pwm#%u: CCER: %08x, PSC: %08x, ARR: %08x, CCR: %08x @%lu -> %lld/%lld [+%lld]\n",
> 246 pwm->hwpwm, wfhw->ccer, wfhw->psc, wfhw->arr, wfhw->ccr, rate,
247 wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns);
248
249 return 0;
250 }
251
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.