aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2016-04-14 15:17:24 -0400
committerThierry Reding <thierry.reding@gmail.com>2016-05-17 08:45:00 -0400
commit2289711c9d4d588954ff86a06685f1579bf6c446 (patch)
treee95780149a6a2ad0bc5d61486d38ff96254c941d
parentdd0b38b7ca0d8c8aadcf8a17d7c90d36ab8ab6e4 (diff)
hwmon: pwm-fan: Use pwm_get_args() where appropriate
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: Kamil Debski <k.debski@samsung.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r--drivers/hwmon/pwm-fan.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 3e23003f78b0..f9af3935b427 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -40,15 +40,18 @@ struct pwm_fan_ctx {
40 40
41static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) 41static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
42{ 42{
43 struct pwm_args pargs;
43 unsigned long duty; 44 unsigned long duty;
44 int ret = 0; 45 int ret = 0;
45 46
47 pwm_get_args(ctx->pwm, &pargs);
48
46 mutex_lock(&ctx->lock); 49 mutex_lock(&ctx->lock);
47 if (ctx->pwm_value == pwm) 50 if (ctx->pwm_value == pwm)
48 goto exit_set_pwm_err; 51 goto exit_set_pwm_err;
49 52
50 duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); 53 duty = DIV_ROUND_UP(pwm * (pargs.period - 1), MAX_PWM);
51 ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); 54 ret = pwm_config(ctx->pwm, duty, pargs.period);
52 if (ret) 55 if (ret)
53 goto exit_set_pwm_err; 56 goto exit_set_pwm_err;
54 57
@@ -215,6 +218,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
215{ 218{
216 struct thermal_cooling_device *cdev; 219 struct thermal_cooling_device *cdev;
217 struct pwm_fan_ctx *ctx; 220 struct pwm_fan_ctx *ctx;
221 struct pwm_args pargs;
218 struct device *hwmon; 222 struct device *hwmon;
219 int duty_cycle; 223 int duty_cycle;
220 int ret; 224 int ret;
@@ -233,11 +237,19 @@ static int pwm_fan_probe(struct platform_device *pdev)
233 237
234 platform_set_drvdata(pdev, ctx); 238 platform_set_drvdata(pdev, ctx);
235 239
240 /*
241 * FIXME: pwm_apply_args() should be removed when switching to the
242 * atomic PWM API.
243 */
244 pwm_apply_args(ctx->pwm);
245
236 /* Set duty cycle to maximum allowed */ 246 /* Set duty cycle to maximum allowed */
237 duty_cycle = ctx->pwm->period - 1; 247 pwm_get_args(ctx->pwm, &pargs);
248
249 duty_cycle = pargs.period - 1;
238 ctx->pwm_value = MAX_PWM; 250 ctx->pwm_value = MAX_PWM;
239 251
240 ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); 252 ret = pwm_config(ctx->pwm, duty_cycle, pargs.period);
241 if (ret) { 253 if (ret) {
242 dev_err(&pdev->dev, "Failed to configure PWM\n"); 254 dev_err(&pdev->dev, "Failed to configure PWM\n");
243 return ret; 255 return ret;
@@ -303,14 +315,16 @@ static int pwm_fan_suspend(struct device *dev)
303static int pwm_fan_resume(struct device *dev) 315static int pwm_fan_resume(struct device *dev)
304{ 316{
305 struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); 317 struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
318 struct pwm_args pargs;
306 unsigned long duty; 319 unsigned long duty;
307 int ret; 320 int ret;
308 321
309 if (ctx->pwm_value == 0) 322 if (ctx->pwm_value == 0)
310 return 0; 323 return 0;
311 324
312 duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); 325 pwm_get_args(ctx->pwm, &pargs);
313 ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); 326 duty = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), MAX_PWM);
327 ret = pwm_config(ctx->pwm, duty, pargs.period);
314 if (ret) 328 if (ret)
315 return ret; 329 return ret;
316 return pwm_enable(ctx->pwm); 330 return pwm_enable(ctx->pwm);