// SPDX-License-Identifier: GPL-2.0 /* * Clock based PWM controller * * Copyright (c) 2021 Nikita Travkin <nikita@trvn.ru> * * This is an "adapter" driver that allows PWM consumers to use * system clocks with duty cycle control as PWM outputs. * * Limitations: * - Due to the fact that exact behavior depends on the underlying * clock driver, various limitations are possible. * - Underlying clock may not be able to give 0% or 100% duty cycle * (constant off or on), exact behavior will depend on the clock. * - When the PWM is disabled, the clock will be disabled as well, * line state will depend on the clock. * - The clk API doesn't expose the necessary calls to implement * .get_state().
*/
if (!state->enabled) { if (pwm->state.enabled) {
clk_disable(pcchip->clk);
pcchip->clk_enabled = false;
} return 0;
} elseif (!pwm->state.enabled) {
ret = clk_enable(pcchip->clk); if (ret) return ret;
pcchip->clk_enabled = true;
}
/* * We have to enable the clk before setting the rate and duty_cycle, * that however results in a window where the clk is on with a * (potentially) different setting. Also setting period and duty_cycle * are two separate calls, so that probably isn't atomic either.
*/
rate = DIV64_U64_ROUND_UP(NSEC_PER_SEC, period);
ret = clk_set_rate(pcchip->clk, rate); if (ret) return ret;
if (state->polarity == PWM_POLARITY_INVERSED)
duty_cycle = period - duty_cycle;
pcchip->clk = devm_clk_get_prepared(&pdev->dev, NULL); if (IS_ERR(pcchip->clk)) return dev_err_probe(&pdev->dev, PTR_ERR(pcchip->clk), "Failed to get clock\n");
chip->ops = &pwm_clk_ops;
ret = pwmchip_add(chip); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "Failed to add pwm chip\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.