Commit 2289711c authored by Boris Brezillon's avatar Boris Brezillon Committed by Thierry Reding

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: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: default avatarKamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent dd0b38b7
...@@ -40,15 +40,18 @@ struct pwm_fan_ctx { ...@@ -40,15 +40,18 @@ struct pwm_fan_ctx {
static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
{ {
struct pwm_args pargs;
unsigned long duty; unsigned long duty;
int ret = 0; int ret = 0;
pwm_get_args(ctx->pwm, &pargs);
mutex_lock(&ctx->lock); mutex_lock(&ctx->lock);
if (ctx->pwm_value == pwm) if (ctx->pwm_value == pwm)
goto exit_set_pwm_err; goto exit_set_pwm_err;
duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); duty = DIV_ROUND_UP(pwm * (pargs.period - 1), MAX_PWM);
ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); ret = pwm_config(ctx->pwm, duty, pargs.period);
if (ret) if (ret)
goto exit_set_pwm_err; goto exit_set_pwm_err;
...@@ -215,6 +218,7 @@ static int pwm_fan_probe(struct platform_device *pdev) ...@@ -215,6 +218,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
{ {
struct thermal_cooling_device *cdev; struct thermal_cooling_device *cdev;
struct pwm_fan_ctx *ctx; struct pwm_fan_ctx *ctx;
struct pwm_args pargs;
struct device *hwmon; struct device *hwmon;
int duty_cycle; int duty_cycle;
int ret; int ret;
...@@ -233,11 +237,19 @@ static int pwm_fan_probe(struct platform_device *pdev) ...@@ -233,11 +237,19 @@ static int pwm_fan_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ctx); platform_set_drvdata(pdev, ctx);
/*
* FIXME: pwm_apply_args() should be removed when switching to the
* atomic PWM API.
*/
pwm_apply_args(ctx->pwm);
/* Set duty cycle to maximum allowed */ /* Set duty cycle to maximum allowed */
duty_cycle = ctx->pwm->period - 1; pwm_get_args(ctx->pwm, &pargs);
duty_cycle = pargs.period - 1;
ctx->pwm_value = MAX_PWM; ctx->pwm_value = MAX_PWM;
ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); ret = pwm_config(ctx->pwm, duty_cycle, pargs.period);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to configure PWM\n"); dev_err(&pdev->dev, "Failed to configure PWM\n");
return ret; return ret;
...@@ -303,14 +315,16 @@ static int pwm_fan_suspend(struct device *dev) ...@@ -303,14 +315,16 @@ static int pwm_fan_suspend(struct device *dev)
static int pwm_fan_resume(struct device *dev) static int pwm_fan_resume(struct device *dev)
{ {
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
struct pwm_args pargs;
unsigned long duty; unsigned long duty;
int ret; int ret;
if (ctx->pwm_value == 0) if (ctx->pwm_value == 0)
return 0; return 0;
duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); pwm_get_args(ctx->pwm, &pargs);
ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); duty = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), MAX_PWM);
ret = pwm_config(ctx->pwm, duty, pargs.period);
if (ret) if (ret)
return ret; return ret;
return pwm_enable(ctx->pwm); return pwm_enable(ctx->pwm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment