hwmon: (pwm-fan) Switch to new atomic PWM API
Switch pwm-fan driver to new atomic PWM API. Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
ccc9b8263d
commit
677252a185
|
@ -40,31 +40,22 @@ 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 period;
|
||||||
unsigned long duty;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
struct pwm_state state = { };
|
||||||
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 * (pargs.period - 1), MAX_PWM);
|
pwm_init_state(ctx->pwm, &state);
|
||||||
ret = pwm_config(ctx->pwm, duty, pargs.period);
|
period = ctx->pwm->args.period;
|
||||||
if (ret)
|
state.duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);
|
||||||
goto exit_set_pwm_err;
|
state.enabled = pwm ? true : false;
|
||||||
|
|
||||||
if (pwm == 0)
|
ret = pwm_apply_state(ctx->pwm, &state);
|
||||||
pwm_disable(ctx->pwm);
|
if (!ret)
|
||||||
|
ctx->pwm_value = pwm;
|
||||||
if (ctx->pwm_value == 0) {
|
|
||||||
ret = pwm_enable(ctx->pwm);
|
|
||||||
if (ret)
|
|
||||||
goto exit_set_pwm_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->pwm_value = pwm;
|
|
||||||
exit_set_pwm_err:
|
exit_set_pwm_err:
|
||||||
mutex_unlock(&ctx->lock);
|
mutex_unlock(&ctx->lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -218,10 +209,9 @@ 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 ret;
|
int ret;
|
||||||
|
struct pwm_state state = { };
|
||||||
|
|
||||||
ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
|
ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
|
@ -237,37 +227,25 @@ 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 */
|
|
||||||
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, pargs.period);
|
/* Set duty cycle to maximum allowed and enable PWM output */
|
||||||
|
pwm_init_state(ctx->pwm, &state);
|
||||||
|
state.duty_cycle = ctx->pwm->args.period - 1;
|
||||||
|
state.enabled = true;
|
||||||
|
|
||||||
|
ret = pwm_apply_state(ctx->pwm, &state);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enbale PWM output */
|
|
||||||
ret = pwm_enable(ctx->pwm);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(&pdev->dev, "Failed to enable PWM\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
|
hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
|
||||||
ctx, pwm_fan_groups);
|
ctx, pwm_fan_groups);
|
||||||
if (IS_ERR(hwmon)) {
|
if (IS_ERR(hwmon)) {
|
||||||
dev_err(&pdev->dev, "Failed to register hwmon device\n");
|
dev_err(&pdev->dev, "Failed to register hwmon device\n");
|
||||||
pwm_disable(ctx->pwm);
|
ret = PTR_ERR(hwmon);
|
||||||
return PTR_ERR(hwmon);
|
goto err_pwm_disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
|
ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
|
||||||
|
@ -282,14 +260,20 @@ static int pwm_fan_probe(struct platform_device *pdev)
|
||||||
if (IS_ERR(cdev)) {
|
if (IS_ERR(cdev)) {
|
||||||
dev_err(&pdev->dev,
|
dev_err(&pdev->dev,
|
||||||
"Failed to register pwm-fan as cooling device");
|
"Failed to register pwm-fan as cooling device");
|
||||||
pwm_disable(ctx->pwm);
|
ret = PTR_ERR(cdev);
|
||||||
return PTR_ERR(cdev);
|
goto err_pwm_disable;
|
||||||
}
|
}
|
||||||
ctx->cdev = cdev;
|
ctx->cdev = cdev;
|
||||||
thermal_cdev_update(cdev);
|
thermal_cdev_update(cdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_pwm_disable:
|
||||||
|
state.enabled = false;
|
||||||
|
pwm_apply_state(ctx->pwm, &state);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pwm_fan_remove(struct platform_device *pdev)
|
static int pwm_fan_remove(struct platform_device *pdev)
|
||||||
|
|
Loading…
Reference in New Issue