Lines Matching +full:duty +full:- +full:cycle
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2024 Liebherr-Electronics and Drives GmbH
5 * Reference Manual : https://www.nxp.com/docs/en/data-sheet/MC33XS2410.pdf
8 * - Supports frequencies between 0.5Hz and 2048Hz with following steps:
9 * - 0.5 Hz steps from 0.5 Hz to 32 Hz
10 * - 2 Hz steps from 2 Hz to 128 Hz
11 * - 8 Hz steps from 8 Hz to 512 Hz
12 * - 32 Hz steps from 32 Hz to 2048 Hz
13 * - Cannot generate a 0 % duty cycle.
14 * - Always produces low output if disabled.
15 * - Configuration isn't atomic. When changing polarity, duty cycle or period
42 #define MC33XS2410_PWM_CTRL3_EN(chan) BIT(4 + (chan) - 1)
45 #define MC33XS2410_PWM_FREQ(chan) (0x08 + (chan) - 1)
50 #define MC33XS2410_PWM_DC(chan) (0x0c + (chan) - 1)
73 return -EINVAL; in mc33xs2410_write_regs()
96 return -EINVAL; in mc33xs2410_read_regs()
99 for (i = 0; i < len - 1; i++) in mc33xs2410_read_regs()
108 val[i - 1] = FIELD_GET(MC33XS2410_FRAME_OUT_DATA, rx[i]); in mc33xs2410_read_regs()
150 * values as these allow more finegrained period and duty cycle in mc33xs2410_pwm_get_freq()
175 FIELD_PREP(MC33XS2410_PWM_FREQ_COUNT, count - 1); in mc33xs2410_pwm_get_freq()
184 * - 0 = 0.5Hz in mc33xs2410_pwm_get_period()
185 * - 1 = 2Hz in mc33xs2410_pwm_get_period()
186 * - 2 = 8Hz in mc33xs2410_pwm_get_period()
187 * - 3 = 32Hz in mc33xs2410_pwm_get_period()
203 * The hardware cannot generate a 0% relative duty cycle for normal and inversed
207 * to normal and the relative duty cylce must be set to 100%. The device then
215 MC33XS2410_PWM_FREQ(pwm->hwpwm + 1), in mc33xs2410_pwm_apply()
216 MC33XS2410_PWM_DC(pwm->hwpwm + 1), in mc33xs2410_pwm_apply()
226 period = min(state->period, MC33XS2410_PWM_MAX_PERIOD(0)); in mc33xs2410_pwm_apply()
228 return -EINVAL; in mc33xs2410_pwm_apply()
239 /* Duty cycle */ in mc33xs2410_pwm_apply()
240 duty_cycle = min(period, state->duty_cycle); in mc33xs2410_pwm_apply()
241 rel_dc = div64_u64(duty_cycle * 256, period) - 1; in mc33xs2410_pwm_apply()
244 else if (state->polarity == PWM_POLARITY_NORMAL) in mc33xs2410_pwm_apply()
250 mask = MC33XS2410_PWM_CTRL1_POL_INV(pwm->hwpwm + 1); in mc33xs2410_pwm_apply()
251 if (state->polarity == PWM_POLARITY_INVERSED && rel_dc >= 0) in mc33xs2410_pwm_apply()
257 mask = MC33XS2410_PWM_CTRL3_EN(pwm->hwpwm + 1); in mc33xs2410_pwm_apply()
258 if (state->enabled && in mc33xs2410_pwm_apply()
259 !(state->polarity == PWM_POLARITY_NORMAL && rel_dc < 0)) in mc33xs2410_pwm_apply()
273 MC33XS2410_PWM_FREQ(pwm->hwpwm + 1), in mc33xs2410_pwm_get_state()
274 MC33XS2410_PWM_DC(pwm->hwpwm + 1), in mc33xs2410_pwm_get_state()
286 state->period = mc33xs2410_pwm_get_period(val[0]); in mc33xs2410_pwm_get_state()
287 state->polarity = (val[2] & MC33XS2410_PWM_CTRL1_POL_INV(pwm->hwpwm + 1)) ? in mc33xs2410_pwm_get_state()
289 state->enabled = !!(val[3] & MC33XS2410_PWM_CTRL3_EN(pwm->hwpwm + 1)); in mc33xs2410_pwm_get_state()
290 state->duty_cycle = DIV_ROUND_UP_ULL((val[1] + 1) * state->period, 256); in mc33xs2410_pwm_get_state()
308 /* Wake-up time */ in mc33xs2410_reset()
316 struct device *dev = &spi->dev; in mc33xs2410_probe()
324 spi->bits_per_word = 16; in mc33xs2410_probe()
325 spi->mode |= SPI_CS_WORD; in mc33xs2410_probe()
331 chip->ops = &mc33xs2410_pwm_ops; in mc33xs2410_probe()
381 .name = "mc33xs2410-pwm",
389 MODULE_DESCRIPTION("NXP MC33XS2410 high-side switch driver");