Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
aa12c7e7 85a5ffbd

+22 -5
+22 -5
drivers/pwm/core.c
··· 2638 2638 2639 2639 for (i = 0; i < chip->npwm; i++) { 2640 2640 struct pwm_device *pwm = &chip->pwms[i]; 2641 - struct pwm_state state, hwstate; 2641 + struct pwm_state state; 2642 + int err; 2642 2643 2643 2644 pwm_get_state(pwm, &state); 2644 - pwm_get_state_hw(pwm, &hwstate); 2645 2645 2646 2646 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); 2647 2647 ··· 2657 2657 seq_puts(s, ", usage_power"); 2658 2658 seq_puts(s, "\n"); 2659 2659 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 + } 2663 2680 2664 2681 seq_puts(s, "\n"); 2665 2682 }