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_duty_cycle;
|
||||||
uint32_t new_period;
|
uint32_t new_period;
|
||||||
|
|
||||||
if (state->duty_cycle && state->duty_cycle < pwm_pio_resolution)
|
new_period = DIV_ROUND_CLOSEST(state->period, pwm_pio_resolution);
|
||||||
return -EINVAL;
|
if (new_period < 2)
|
||||||
|
new_period = 2;
|
||||||
if (state->duty_cycle != state->period &&
|
new_duty_cycle = DIV_ROUND_CLOSEST(state->duty_cycle, pwm_pio_resolution);
|
||||||
(state->period - state->duty_cycle < pwm_pio_resolution))
|
if (new_duty_cycle > new_period - 1)
|
||||||
return -EINVAL;
|
new_duty_cycle = new_period - 1;
|
||||||
|
|
||||||
new_period = state->period / pwm_pio_resolution;
|
|
||||||
new_duty_cycle = state->duty_cycle / pwm_pio_resolution;
|
|
||||||
|
|
||||||
mutex_lock(&ppwm->mutex);
|
mutex_lock(&ppwm->mutex);
|
||||||
|
|
||||||
@@ -145,8 +142,22 @@ static int pwm_pio_rp1_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
|||||||
return 0;
|
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 = {
|
static const struct pwm_ops pwm_pio_rp1_ops = {
|
||||||
.apply = pwm_pio_rp1_apply,
|
.apply = pwm_pio_rp1_apply,
|
||||||
|
.get_state = pwm_pio_rp1_get_state,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int pwm_pio_rp1_probe(struct platform_device *pdev)
|
static int pwm_pio_rp1_probe(struct platform_device *pdev)
|
||||||
|
|||||||
Reference in New Issue
Block a user