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: Formally describe the procedure used to pick a hardware waveform setting

This serves as specification for both, PWM consumers and the respective
callback for lowlevel drivers.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/d2916bfa70274961ded26b07ab6998c36b90e69a.1746010245.git.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
d041b76a 164c4ac7

+23 -1
+23 -1
drivers/pwm/core.c
··· 231 231 * 232 232 * Usually all values passed in @wf are rounded down to the nearest possible 233 233 * value (in the order period_length_ns, duty_length_ns and then 234 - * duty_offset_ns). Only if this isn't possible, a value might grow. 234 + * duty_offset_ns). Only if this isn't possible, a value might grow. See the 235 + * documentation for pwm_set_waveform_might_sleep() for a more formal 236 + * description. 235 237 * 236 238 * Returns: 0 on success, 1 if at least one value had to be rounded up or a 237 239 * negative errno. ··· 412 410 * Note that even with @exact = true, some rounding by less than 1 ns is 413 411 * possible/needed. In the above example requesting .period_length_ns = 94 and 414 412 * @exact = true, you get the hardware configured with period = 93.5 ns. 413 + * 414 + * Let C be the set of possible hardware configurations for a given PWM device, 415 + * consisting of tuples (p, d, o) where p is the period length, d is the duty 416 + * length and o the duty offset. 417 + * 418 + * The following algorithm is implemented to pick the hardware setting 419 + * (p, d, o) ∈ C for a given request (p', d', o') with @exact = false:: 420 + * 421 + * p = max( { ṗ | ∃ ḋ, ȯ : (ṗ, ḋ, ȯ) ∈ C ∧ ṗ ≤ p' } ∪ { min({ ṗ | ∃ ḋ, ȯ : (ṗ, ḋ, ȯ) ∈ C }) }) 422 + * d = max( { ḋ | ∃ ȯ : (p, ḋ, ȯ) ∈ C ∧ ḋ ≤ d' } ∪ { min({ ḋ | ∃ ȯ : (p, ḋ, ȯ) ∈ C }) }) 423 + * o = max( { ȯ | (p, d, ȯ) ∈ C ∧ ȯ ≤ o' } ∪ { min({ ȯ | (p, d, ȯ) ∈ C }) }) 424 + * 425 + * In words: The chosen period length is the maximal possible period length not 426 + * bigger than the requested period length and if that doesn't exist, the 427 + * minimal period length. The chosen duty length is the maximal possible duty 428 + * length that is compatible with the chosen period length and isn't bigger than 429 + * the requested duty length. Again if such a value doesn't exist, the minimal 430 + * duty length compatible with the chosen period is picked. After that the duty 431 + * offset compatible with the chosen period and duty length is chosen in the 432 + * same way. 415 433 * 416 434 * Returns: 0 on success, -EDOM if setting failed due to the exact waveform not 417 435 * being possible (if @exact), or a different negative errno on failure.