Skip to content

Commit 4919a4f

Browse files
committed
Edge: enable pwm-fan
1 parent a60fc00 commit 4919a4f

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

arch/arm64/boot/dts/rockchip/rk3399-kedge.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@
332332
clock-output-names = "xin32k";
333333
#clock-cells = <0>;
334334
};
335+
336+
fan0: pwm-fan {
337+
compatible = "pwm-fan";
338+
status = "okay";
339+
pwms = <&pwm0 0 10000000 0>; /* 100Hz */
340+
cooling-min-state = <0>;
341+
cooling-max-state = <3>;
342+
#cooling-cells = <2>;
343+
cooling-levels = <0 150 200 255>;
344+
};
335345
};
336346

337347
&dmac_bus {

arch/arm64/configs/kedge_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ CONFIG_POWER_RESET_GPIO_RESTART=y
251251
CONFIG_SYSCON_REBOOT_MODE=y
252252
CONFIG_POWER_AVS=y
253253
CONFIG_ROCKCHIP_IODOMAIN=y
254+
CONFIG_SENSORS_PWM_FAN=y
254255
CONFIG_THERMAL=y
255256
CONFIG_THERMAL_WRITABLE_TRIPS=y
256257
CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR=y

drivers/hwmon/pwm-fan.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ struct pwm_fan_ctx {
4040

4141
static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
4242
{
43+
struct pwm_args pargs;
4344
unsigned long duty;
4445
int ret = 0;
4546

47+
pwm_get_args(ctx->pwm, &pargs);
48+
4649
mutex_lock(&ctx->lock);
4750
if (ctx->pwm_value == pwm)
4851
goto exit_set_pwm_err;
4952

50-
duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM);
51-
ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
53+
duty = DIV_ROUND_UP(pwm * (pargs.period - 1), MAX_PWM);
54+
ret = pwm_config(ctx->pwm, duty, pargs.period);
5255
if (ret)
5356
goto exit_set_pwm_err;
5457

@@ -215,6 +218,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
215218
{
216219
struct thermal_cooling_device *cdev;
217220
struct pwm_fan_ctx *ctx;
221+
struct pwm_args pargs;
218222
struct device *hwmon;
219223
int duty_cycle;
220224
int ret;
@@ -233,11 +237,19 @@ static int pwm_fan_probe(struct platform_device *pdev)
233237

234238
platform_set_drvdata(pdev, ctx);
235239

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+
236246
/* 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;
238250
ctx->pwm_value = MAX_PWM;
239251

240-
ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period);
252+
ret = pwm_config(ctx->pwm, duty_cycle, pargs.period);
241253
if (ret) {
242254
dev_err(&pdev->dev, "Failed to configure PWM\n");
243255
return ret;
@@ -303,14 +315,16 @@ static int pwm_fan_suspend(struct device *dev)
303315
static int pwm_fan_resume(struct device *dev)
304316
{
305317
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
318+
struct pwm_args pargs;
306319
unsigned long duty;
307320
int ret;
308321

309322
if (ctx->pwm_value == 0)
310323
return 0;
311324

312-
duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM);
313-
ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
325+
pwm_get_args(ctx->pwm, &pargs);
326+
duty = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), MAX_PWM);
327+
ret = pwm_config(ctx->pwm, duty, pargs.period);
314328
if (ret)
315329
return ret;
316330
return pwm_enable(ctx->pwm);

0 commit comments

Comments
 (0)