diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-05-16 10:56:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-05-16 10:56:57 -0400 |
commit | a455eda33faafcaac1effb31d682765b14ef868c (patch) | |
tree | 9a4ca7da47300ca9081445539ff337efcead4b6b /drivers/hwmon/pwm-fan.c | |
parent | cc7ce90153e74f8266eefee9fba466faa1a2d5df (diff) | |
parent | 37bcec5d9f71bd13142a97d2196b293c9ac23823 (diff) |
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal
Pull thermal soc updates from Eduardo Valentin:
- thermal core has a new devm_* API for registering cooling devices. I
took the entire series, that is why you see changes on drivers/hwmon
in this pull (Guenter Roeck)
- rockchip thermal driver gains support to PX30 SoC (Elaine Zhang)
- the generic-adc thermal driver now considers the lookup table DT
property as optional (Jean-Francois Dagenais)
- Refactoring of tsens thermal driver (Amit Kucheria)
- Cleanups on cpu cooling driver (Daniel Lezcano)
- broadcom thermal driver dropped support to ACPI (Srinath Mannam)
- tegra thermal driver gains support to OC hw throttle and GPU throtle
(Wei Ni)
- Fixes in several thermal drivers.
* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal: (59 commits)
hwmon: (pwm-fan) Use devm_thermal_of_cooling_device_register
hwmon: (npcm750-pwm-fan) Use devm_thermal_of_cooling_device_register
hwmon: (mlxreg-fan) Use devm_thermal_of_cooling_device_register
hwmon: (gpio-fan) Use devm_thermal_of_cooling_device_register
hwmon: (aspeed-pwm-tacho) Use devm_thermal_of_cooling_device_register
thermal: rcar_gen3_thermal: Fix to show correct trip points number
thermal: rcar_thermal: update calculation formula for R-Car Gen3 SoCs
thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power
thermal: rockchip: Support the PX30 SoC in thermal driver
dt-bindings: rockchip-thermal: Support the PX30 SoC compatible
thermal: rockchip: fix up the tsadc pinctrl setting error
thermal: broadcom: Remove ACPI support
thermal: Fix build error of missing devm_ioremap_resource on UM
thermal/drivers/cpu_cooling: Remove pointless field
thermal/drivers/cpu_cooling: Add Software Package Data Exchange (SPDX)
thermal/drivers/cpu_cooling: Fixup the header and copyright
thermal/drivers/cpu_cooling: Remove pointless test in power2state()
thermal: rcar_gen3_thermal: disable interrupt in .remove
thermal: rcar_gen3_thermal: fix interrupt type
thermal: Introduce devm_thermal_of_cooling_device_register
...
Diffstat (limited to 'drivers/hwmon/pwm-fan.c')
-rw-r--r-- | drivers/hwmon/pwm-fan.c | 97 |
1 files changed, 38 insertions, 59 deletions
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index eead8afe6447..5fb2745f0226 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c | |||
@@ -273,27 +273,40 @@ static int pwm_fan_of_get_cooling_data(struct device *dev, | |||
273 | return 0; | 273 | return 0; |
274 | } | 274 | } |
275 | 275 | ||
276 | static void pwm_fan_regulator_disable(void *data) | ||
277 | { | ||
278 | regulator_disable(data); | ||
279 | } | ||
280 | |||
281 | static void pwm_fan_pwm_disable(void *__ctx) | ||
282 | { | ||
283 | struct pwm_fan_ctx *ctx = __ctx; | ||
284 | pwm_disable(ctx->pwm); | ||
285 | del_timer_sync(&ctx->rpm_timer); | ||
286 | } | ||
287 | |||
276 | static int pwm_fan_probe(struct platform_device *pdev) | 288 | static int pwm_fan_probe(struct platform_device *pdev) |
277 | { | 289 | { |
278 | struct thermal_cooling_device *cdev; | 290 | struct thermal_cooling_device *cdev; |
291 | struct device *dev = &pdev->dev; | ||
279 | struct pwm_fan_ctx *ctx; | 292 | struct pwm_fan_ctx *ctx; |
280 | struct device *hwmon; | 293 | struct device *hwmon; |
281 | int ret; | 294 | int ret; |
282 | struct pwm_state state = { }; | 295 | struct pwm_state state = { }; |
283 | u32 ppr = 2; | 296 | u32 ppr = 2; |
284 | 297 | ||
285 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); | 298 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
286 | if (!ctx) | 299 | if (!ctx) |
287 | return -ENOMEM; | 300 | return -ENOMEM; |
288 | 301 | ||
289 | mutex_init(&ctx->lock); | 302 | mutex_init(&ctx->lock); |
290 | 303 | ||
291 | ctx->pwm = devm_of_pwm_get(&pdev->dev, pdev->dev.of_node, NULL); | 304 | ctx->pwm = devm_of_pwm_get(dev, dev->of_node, NULL); |
292 | if (IS_ERR(ctx->pwm)) { | 305 | if (IS_ERR(ctx->pwm)) { |
293 | ret = PTR_ERR(ctx->pwm); | 306 | ret = PTR_ERR(ctx->pwm); |
294 | 307 | ||
295 | if (ret != -EPROBE_DEFER) | 308 | if (ret != -EPROBE_DEFER) |
296 | dev_err(&pdev->dev, "Could not get PWM: %d\n", ret); | 309 | dev_err(dev, "Could not get PWM: %d\n", ret); |
297 | 310 | ||
298 | return ret; | 311 | return ret; |
299 | } | 312 | } |
@@ -304,7 +317,7 @@ static int pwm_fan_probe(struct platform_device *pdev) | |||
304 | if (ctx->irq == -EPROBE_DEFER) | 317 | if (ctx->irq == -EPROBE_DEFER) |
305 | return ctx->irq; | 318 | return ctx->irq; |
306 | 319 | ||
307 | ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan"); | 320 | ctx->reg_en = devm_regulator_get_optional(dev, "fan"); |
308 | if (IS_ERR(ctx->reg_en)) { | 321 | if (IS_ERR(ctx->reg_en)) { |
309 | if (PTR_ERR(ctx->reg_en) != -ENODEV) | 322 | if (PTR_ERR(ctx->reg_en) != -ENODEV) |
310 | return PTR_ERR(ctx->reg_en); | 323 | return PTR_ERR(ctx->reg_en); |
@@ -313,10 +326,11 @@ static int pwm_fan_probe(struct platform_device *pdev) | |||
313 | } else { | 326 | } else { |
314 | ret = regulator_enable(ctx->reg_en); | 327 | ret = regulator_enable(ctx->reg_en); |
315 | if (ret) { | 328 | if (ret) { |
316 | dev_err(&pdev->dev, | 329 | dev_err(dev, "Failed to enable fan supply: %d\n", ret); |
317 | "Failed to enable fan supply: %d\n", ret); | ||
318 | return ret; | 330 | return ret; |
319 | } | 331 | } |
332 | devm_add_action_or_reset(dev, pwm_fan_regulator_disable, | ||
333 | ctx->reg_en); | ||
320 | } | 334 | } |
321 | 335 | ||
322 | ctx->pwm_value = MAX_PWM; | 336 | ctx->pwm_value = MAX_PWM; |
@@ -328,91 +342,57 @@ static int pwm_fan_probe(struct platform_device *pdev) | |||
328 | 342 | ||
329 | ret = pwm_apply_state(ctx->pwm, &state); | 343 | ret = pwm_apply_state(ctx->pwm, &state); |
330 | if (ret) { | 344 | if (ret) { |
331 | dev_err(&pdev->dev, "Failed to configure PWM: %d\n", ret); | 345 | dev_err(dev, "Failed to configure PWM: %d\n", ret); |
332 | goto err_reg_disable; | 346 | return ret; |
333 | } | 347 | } |
334 | |||
335 | timer_setup(&ctx->rpm_timer, sample_timer, 0); | 348 | timer_setup(&ctx->rpm_timer, sample_timer, 0); |
349 | devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx); | ||
336 | 350 | ||
337 | of_property_read_u32(pdev->dev.of_node, "pulses-per-revolution", &ppr); | 351 | of_property_read_u32(dev->of_node, "pulses-per-revolution", &ppr); |
338 | ctx->pulses_per_revolution = ppr; | 352 | ctx->pulses_per_revolution = ppr; |
339 | if (!ctx->pulses_per_revolution) { | 353 | if (!ctx->pulses_per_revolution) { |
340 | dev_err(&pdev->dev, "pulses-per-revolution can't be zero.\n"); | 354 | dev_err(dev, "pulses-per-revolution can't be zero.\n"); |
341 | ret = -EINVAL; | 355 | return -EINVAL; |
342 | goto err_pwm_disable; | ||
343 | } | 356 | } |
344 | 357 | ||
345 | if (ctx->irq > 0) { | 358 | if (ctx->irq > 0) { |
346 | ret = devm_request_irq(&pdev->dev, ctx->irq, pulse_handler, 0, | 359 | ret = devm_request_irq(dev, ctx->irq, pulse_handler, 0, |
347 | pdev->name, ctx); | 360 | pdev->name, ctx); |
348 | if (ret) { | 361 | if (ret) { |
349 | dev_err(&pdev->dev, | 362 | dev_err(dev, "Failed to request interrupt: %d\n", ret); |
350 | "Failed to request interrupt: %d\n", ret); | 363 | return ret; |
351 | goto err_pwm_disable; | ||
352 | } | 364 | } |
353 | ctx->sample_start = ktime_get(); | 365 | ctx->sample_start = ktime_get(); |
354 | mod_timer(&ctx->rpm_timer, jiffies + HZ); | 366 | mod_timer(&ctx->rpm_timer, jiffies + HZ); |
355 | } | 367 | } |
356 | 368 | ||
357 | hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", | 369 | hwmon = devm_hwmon_device_register_with_groups(dev, "pwmfan", |
358 | ctx, pwm_fan_groups); | 370 | ctx, pwm_fan_groups); |
359 | if (IS_ERR(hwmon)) { | 371 | if (IS_ERR(hwmon)) { |
360 | ret = PTR_ERR(hwmon); | 372 | dev_err(dev, "Failed to register hwmon device\n"); |
361 | dev_err(&pdev->dev, | 373 | return PTR_ERR(hwmon); |
362 | "Failed to register hwmon device: %d\n", ret); | ||
363 | goto err_del_timer; | ||
364 | } | 374 | } |
365 | 375 | ||
366 | ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx); | 376 | ret = pwm_fan_of_get_cooling_data(dev, ctx); |
367 | if (ret) | 377 | if (ret) |
368 | goto err_del_timer; | 378 | return ret; |
369 | 379 | ||
370 | ctx->pwm_fan_state = ctx->pwm_fan_max_state; | 380 | ctx->pwm_fan_state = ctx->pwm_fan_max_state; |
371 | if (IS_ENABLED(CONFIG_THERMAL)) { | 381 | if (IS_ENABLED(CONFIG_THERMAL)) { |
372 | cdev = thermal_of_cooling_device_register(pdev->dev.of_node, | 382 | cdev = devm_thermal_of_cooling_device_register(dev, |
373 | "pwm-fan", ctx, | 383 | dev->of_node, "pwm-fan", ctx, &pwm_fan_cooling_ops); |
374 | &pwm_fan_cooling_ops); | ||
375 | if (IS_ERR(cdev)) { | 384 | if (IS_ERR(cdev)) { |
376 | ret = PTR_ERR(cdev); | 385 | ret = PTR_ERR(cdev); |
377 | dev_err(&pdev->dev, | 386 | dev_err(dev, |
378 | "Failed to register pwm-fan as cooling device: %d\n", | 387 | "Failed to register pwm-fan as cooling device: %d\n", |
379 | ret); | 388 | ret); |
380 | goto err_del_timer; | 389 | return ret; |
381 | } | 390 | } |
382 | ctx->cdev = cdev; | 391 | ctx->cdev = cdev; |
383 | thermal_cdev_update(cdev); | 392 | thermal_cdev_update(cdev); |
384 | } | 393 | } |
385 | 394 | ||
386 | return 0; | 395 | return 0; |
387 | |||
388 | err_del_timer: | ||
389 | del_timer_sync(&ctx->rpm_timer); | ||
390 | |||
391 | err_pwm_disable: | ||
392 | state.enabled = false; | ||
393 | pwm_apply_state(ctx->pwm, &state); | ||
394 | |||
395 | err_reg_disable: | ||
396 | if (ctx->reg_en) | ||
397 | regulator_disable(ctx->reg_en); | ||
398 | |||
399 | return ret; | ||
400 | } | ||
401 | |||
402 | static int pwm_fan_remove(struct platform_device *pdev) | ||
403 | { | ||
404 | struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev); | ||
405 | |||
406 | thermal_cooling_device_unregister(ctx->cdev); | ||
407 | del_timer_sync(&ctx->rpm_timer); | ||
408 | |||
409 | if (ctx->pwm_value) | ||
410 | pwm_disable(ctx->pwm); | ||
411 | |||
412 | if (ctx->reg_en) | ||
413 | regulator_disable(ctx->reg_en); | ||
414 | |||
415 | return 0; | ||
416 | } | 396 | } |
417 | 397 | ||
418 | #ifdef CONFIG_PM_SLEEP | 398 | #ifdef CONFIG_PM_SLEEP |
@@ -480,7 +460,6 @@ MODULE_DEVICE_TABLE(of, of_pwm_fan_match); | |||
480 | 460 | ||
481 | static struct platform_driver pwm_fan_driver = { | 461 | static struct platform_driver pwm_fan_driver = { |
482 | .probe = pwm_fan_probe, | 462 | .probe = pwm_fan_probe, |
483 | .remove = pwm_fan_remove, | ||
484 | .driver = { | 463 | .driver = { |
485 | .name = "pwm-fan", | 464 | .name = "pwm-fan", |
486 | .pm = &pwm_fan_pm, | 465 | .pm = &pwm_fan_pm, |