Skip to content

Commit aa12c7e

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Emit native configuration in /sys/kernel/debug/pwm
Currently there are two abstractions for PWM drivers. Use the waveform representation for the drivers that support it as this is more expressive and so tells more about the actual hardware state. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://patch.msgid.link/20251121104947.2652013-2-u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 85a5ffb commit aa12c7e

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

drivers/pwm/core.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,10 +2638,10 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
26382638

26392639
for (i = 0; i < chip->npwm; i++) {
26402640
struct pwm_device *pwm = &chip->pwms[i];
2641-
struct pwm_state state, hwstate;
2641+
struct pwm_state state;
2642+
int err;
26422643

26432644
pwm_get_state(pwm, &state);
2644-
pwm_get_state_hw(pwm, &hwstate);
26452645

26462646
seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
26472647

@@ -2657,9 +2657,26 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
26572657
seq_puts(s, ", usage_power");
26582658
seq_puts(s, "\n");
26592659

2660-
seq_printf(s, " actual configuration: %3sabled, %llu/%llu ns, %s polarity",
2661-
hwstate.enabled ? "en" : "dis", hwstate.duty_cycle, hwstate.period,
2662-
hwstate.polarity ? "inverse" : "normal");
2660+
if (pwmchip_supports_waveform(chip)) {
2661+
struct pwm_waveform wf;
2662+
2663+
err = pwm_get_waveform_might_sleep(pwm, &wf);
2664+
if (!err)
2665+
seq_printf(s, " actual configuration: %lld/%lld [+%lld]",
2666+
wf.duty_length_ns, wf.period_length_ns, wf.duty_offset_ns);
2667+
else
2668+
seq_printf(s, " actual configuration: read out error: %pe\n", ERR_PTR(err));
2669+
} else {
2670+
struct pwm_state hwstate;
2671+
2672+
err = pwm_get_state_hw(pwm, &hwstate);
2673+
if (!err)
2674+
seq_printf(s, " actual configuration: %3sabled, %llu/%llu ns, %s polarity",
2675+
hwstate.enabled ? "en" : "dis", hwstate.duty_cycle, hwstate.period,
2676+
hwstate.polarity ? "inverse" : "normal");
2677+
else
2678+
seq_printf(s, " actual configuration: read out error: %pe", ERR_PTR(err));
2679+
}
26632680

26642681
seq_puts(s, "\n");
26652682
}

0 commit comments

Comments
 (0)