Re: [PATCH 3/5] pwm: adp5585: Clamp on/off counters to the 16 bit register range

From: shao.mingyin

Date: Fri Nov 06 2026 - 11:50:11 EST


> Should on be clamped to 0xffff before subtracting it to compute off?

The period loss is real, but clamping on before computing off is not
correct here: it turns high duty-cycle requests into 50%.

The period is on + off and both counters are limited to 0xffff ticks.
When on saturates, the current code keeps the requested off time, so the
output stays close to the requested duty and only the period is
shortened:

period 131070 us, duty 131070 us (100%):
current: on=65535 off=0 -> 65535 us, 100%
proposed: on=65535 off=65535 -> 131070 us, 50%

period 131070 us, duty 131000 us (99.947%):
current: on=65535 off=70 -> 65605 us, 99.893%
proposed: on=65535 off=65535 -> 131070 us, 50%

Above 50% duty, keeping the off phase is much closer to the request than
keeping the period; 100% is a flat line where the period has no meaning.
The pwm_apply_debug() "best available period" warning is a heuristic and
does not justify a 50% duty error.

I'll keep the current ordering. I can add a comment explaining why on is
clamped after off if that helps.