UPSTREAM: regulator: pwm: Use pwm_get_args() where appropriate
authorBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 14 Apr 2016 19:17:27 +0000 (21:17 +0200)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 6 Mar 2017 10:28:40 +0000 (18:28 +0800)
The PWM framework has clarified the concept of reference PWM config (the
platform dependent config retrieved from the DT or the PWM lookup table)
and real PWM state.

Use pwm_get_args() when the PWM user wants to retrieve this reference
config and not the current state.

This is part of the rework allowing the PWM framework to support
hardware readout and expose real PWM state even when the PWM has just
been requested (before the user calls pwm_config/enable/disable()).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from 8c12ad8e916ee0477f7a0a0f00b0a87b9a21ebf7)

Conflicts:
drivers/regulator/pwm-regulator.c

Change-Id: Id7fb1d823db7a0be207de4f0393e6c86df143335
Signed-off-by: David Wu <david.wu@rock-chips.com>
drivers/regulator/pwm-regulator.c

index 8e928f23279b6ddfef96c288b01b364e51d77b12..fafa3488e960520752b44b482864401925a22a6f 100644 (file)
@@ -59,16 +59,16 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
                                         unsigned selector)
 {
        struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
-       unsigned int pwm_reg_period;
+       struct pwm_args pargs;
        int dutycycle;
        int ret;
 
-       pwm_reg_period = pwm_get_period(drvdata->pwm);
+       pwm_get_args(drvdata->pwm, &pargs);
 
-       dutycycle = (pwm_reg_period *
+       dutycycle = (pargs.period *
                    drvdata->duty_cycle_table[selector].dutycycle) / 100;
 
-       ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period);
+       ret = pwm_config(drvdata->pwm, dutycycle, pargs.period);
        if (ret) {
                dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
                return ret;
@@ -126,7 +126,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
 {
        struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
        unsigned int ramp_delay = rdev->constraints->ramp_delay;
-       unsigned int period = pwm_get_period(drvdata->pwm);
+       struct pwm_args pargs;
        unsigned int req_diff = min_uV - rdev->constraints->min_uV;
        unsigned int diff;
        unsigned int duty_pulse;
@@ -134,6 +134,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
        u32 rem;
        int ret;
 
+       pwm_get_args(drvdata->pwm, &pargs);
        diff = rdev->constraints->max_uV - rdev->constraints->min_uV;
 
        /* First try to find out if we get the iduty cycle time which is
@@ -143,16 +144,16 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
         * to get output voltage nearer to requested value as there is no
         * calculation loss.
         */
-       req_period = req_diff * period;
+       req_period = req_diff * pargs.period;
        div_u64_rem(req_period, diff, &rem);
        if (!rem) {
                do_div(req_period, diff);
                duty_pulse = (unsigned int)req_period;
        } else {
-               duty_pulse = (period / 100) * ((req_diff * 100) / diff);
+               duty_pulse = (pargs.period / 100) * ((req_diff * 100) / diff);
        }
 
-       ret = pwm_config(drvdata->pwm, duty_pulse, period);
+       ret = pwm_config(drvdata->pwm, duty_pulse, pargs.period);
        if (ret) {
                dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
                return ret;
@@ -289,6 +290,12 @@ static int pwm_regulator_probe(struct platform_device *pdev)
                return ret;
        }
 
+       /*
+        * FIXME: pwm_apply_args() should be removed when switching to the
+        * atomic PWM API.
+        */
+       pwm_apply_args(drvdata->pwm);
+
        regulator = devm_regulator_register(&pdev->dev,
                                            &drvdata->desc, &config);
        if (IS_ERR(regulator)) {