mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
pwm: rp1: Silently correct illegal values
Remove the need for the user to know the limitations of this PWM implementation by adjusting configuration requests to be the closest acceptable value. Add a get_state method so that the actual values can be queried. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
This commit is contained in:
@@ -101,15 +101,12 @@ static int pwm_pio_rp1_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
uint32_t new_duty_cycle;
|
||||
uint32_t new_period;
|
||||
|
||||
if (state->duty_cycle && state->duty_cycle < pwm_pio_resolution)
|
||||
return -EINVAL;
|
||||
|
||||
if (state->duty_cycle != state->period &&
|
||||
(state->period - state->duty_cycle < pwm_pio_resolution))
|
||||
return -EINVAL;
|
||||
|
||||
new_period = state->period / pwm_pio_resolution;
|
||||
new_duty_cycle = state->duty_cycle / pwm_pio_resolution;
|
||||
new_period = DIV_ROUND_CLOSEST(state->period, pwm_pio_resolution);
|
||||
if (new_period < 2)
|
||||
new_period = 2;
|
||||
new_duty_cycle = DIV_ROUND_CLOSEST(state->duty_cycle, pwm_pio_resolution);
|
||||
if (new_duty_cycle > new_period - 1)
|
||||
new_duty_cycle = new_period - 1;
|
||||
|
||||
mutex_lock(&ppwm->mutex);
|
||||
|
||||
@@ -145,8 +142,22 @@ static int pwm_pio_rp1_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pwm_pio_rp1_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
struct pwm_state *state)
|
||||
{
|
||||
struct pwm_pio_rp1 *ppwm = pwmchip_get_drvdata(chip);
|
||||
|
||||
state->enabled = ppwm->enabled;
|
||||
state->polarity = ppwm->polarity;
|
||||
state->period = ppwm->period * pwm_pio_resolution;
|
||||
state->duty_cycle = ppwm->duty_cycle * pwm_pio_resolution;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct pwm_ops pwm_pio_rp1_ops = {
|
||||
.apply = pwm_pio_rp1_apply,
|
||||
.get_state = pwm_pio_rp1_get_state,
|
||||
};
|
||||
|
||||
static int pwm_pio_rp1_probe(struct platform_device *pdev)
|
||||
|
||||
Reference in New Issue
Block a user