// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2017-2025 Loongson Technology Corporation Limited. * * Loongson PWM driver * * For Loongson's PWM IP block documentation please refer Chapter 11 of * Reference Manual: https://loongson.github.io/LoongArch-Documentation/Loongson-7A1000-usermanual-EN.pdf * * Author: Juxin Gao <gaojuxin@loongson.cn> * Further cleanup and restructuring by: * Binbin Zhou <zhoubinbin@loongson.cn> * * Limitations: * - If both DUTY and PERIOD are set to 0, the output is a constant low signal. * - When disabled the output is driven to 0 independent of the configured * polarity. * - If the register is reconfigured while PWM is running, it does not complete * the currently running period. * - Disabling the PWM stops the output immediately (without waiting for current * period to complete first).
*/
val = pwm_loongson_readl(ddata, LOONGSON_PWM_REG_CTRL);
if (polarity == PWM_POLARITY_INVERSED) /* Duty cycle defines LOW period of PWM */
val |= LOONGSON_PWM_CTRL_REG_INVERT; else /* Duty cycle defines HIGH period of PWM */
val &= ~LOONGSON_PWM_CTRL_REG_INVERT;
ddata->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(ddata->base)) return PTR_ERR(ddata->base);
ddata->clk = devm_clk_get_optional_enabled(dev, NULL); if (IS_ERR(ddata->clk)) return dev_err_probe(dev, PTR_ERR(ddata->clk), "Failed to get pwm clock\n"); if (ddata->clk) {
ret = devm_clk_rate_exclusive_get(dev, ddata->clk); if (ret) return dev_err_probe(dev, ret, "Failed to get exclusive rate\n");
ddata->clk_rate = clk_get_rate(ddata->clk); if (!ddata->clk_rate) return dev_err_probe(dev, -EINVAL, "Failed to get frequency\n");
} else {
ddata->clk_rate = LOONGSON_PWM_FREQ_DEFAULT;
}
/* This check is done to prevent an overflow in .apply */ if (ddata->clk_rate > NSEC_PER_SEC) return dev_err_probe(dev, -EINVAL, "PWM clock out of range\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.