• Uwe Kleine-König's avatar
    pwm: Allow pwm state transitions from an invalid state · 9dd42d01
    Uwe Kleine-König authored
    While driving a PWM via the sysfs API it's hard to determine the right
    order of writes to the pseudo files "period" and "duty_cycle":
    
    If you want to go from duty_cycle/period = 50/100 to 150/300 you have to
    write period first (because 150/100 is invalid). If however you start at
    400/500 the duty_cycle must be configured first. The rule that works is:
    If you increase period write period first, otherwise write duty_cycle
    first. A complication however is that it's usually sensible to configure
    the polarity before both period and duty_cycle. This can only be done if
    the current state's duty_cycle and period configuration isn't bogus
    though. It is still worse (but I think only theoretic) if you have a PWM
    that only supports inverted polarity and you start with period = 0 and
    polarity = normal. Then you can change neither period (because polarity
    = normal is refused) nor polarity (because there is still period = 0).
    
    To simplify the corner cases for userspace, let invalid target states
    pass if the current state is invalid already.
    Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@baylibre.com>
    Link: https://lore.kernel.org/r/20240628103519.105020-2-u.kleine-koenig@baylibre.comSigned-off-by: default avatarUwe Kleine-König <ukleinek@kernel.org>
    9dd42d01
core.c 40 KB