Skip to content

Commit b2c02ff

Browse files
ukleineknunojsa
authored andcommitted
iio: adc: ad7944: Convert to use pwm_apply_state()
pwm_config() is an old API function that isn't recommended any more. This driver is a prime example for the reason: Either you need more than one function call (and so several hardware parameter calculations and several hardware modifications resulting in more glitches than usally necessary) or you have to rely on previous hardware state (here: that the PWM is enabled, because the driver doesn't ensure proper operation if the PWM happens to be disabled). Convert to pwm_apply_state() which is the designated replacement without these disadvantages. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
1 parent 3f46d92 commit b2c02ff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/iio/adc/ad7944.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static ssize_t ad7944_sampling_frequency_store(struct device *dev,
426426
{
427427
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
428428
struct ad7944_adc *adc = iio_priv(indio_dev);
429-
u64 period_ns;
429+
struct pwm_state sample_state;
430430
u32 val;
431431
int ret;
432432

@@ -440,9 +440,12 @@ static ssize_t ad7944_sampling_frequency_store(struct device *dev,
440440
if (val == 0)
441441
return -EINVAL;
442442

443-
period_ns = div_u64(NSEC_PER_SEC, val);
443+
pwm_init_state(adc->pwm, &sample_state);
444+
sample_state.period = div_u64(NSEC_PER_SEC, val);
445+
sample_state.duty_cycle = AD7944_PWM_TRIGGER_DUTY_CYCLE_NS;
446+
sample_state.enabled = true;
444447

445-
ret = pwm_config(adc->pwm, AD7944_PWM_TRIGGER_DUTY_CYCLE_NS, period_ns);
448+
ret = pwm_apply_state(adc->pwm, &sample_state);
446449
if (ret)
447450
return ret;
448451

0 commit comments

Comments
 (0)