diff options
author | Anshul Jain <anshulj@nvidia.com> | 2013-10-22 11:59:23 -0700 |
---|---|---|
committer | Manish Tuteja <mtuteja@nvidia.com> | 2013-10-23 00:31:26 -0700 |
commit | 63e75dd42a861aeb6a10aa48703e4ecef5908916 (patch) | |
tree | 01c910af43688c383f3f65b5d0bcb23b34aeaf3e | |
parent | 1b75fee284a42f1d48b570aaed51261cff0fbcd3 (diff) |
thermal: pwm_fan: toggle gpio in suspend/resume
On suspend, this change sets the gpio high.
On suspend:
free pwm
request gpio
set gpio high
On resume:
free gpio
request pwm
set pwm
Bug 1388303
Change-Id: I6905e4217dd170801d84ec98713067e5c2a53abf
Signed-off-by: Anshul Jain <anshulj@nvidia.com>
Reviewed-on: http://git-master/r/302591
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Manish Tuteja <mtuteja@nvidia.com>
-rw-r--r-- | drivers/thermal/pwm_fan.c | 34 | ||||
-rw-r--r-- | include/linux/platform_data/pwm_fan.h | 3 |
2 files changed, 32 insertions, 5 deletions
diff --git a/drivers/thermal/pwm_fan.c b/drivers/thermal/pwm_fan.c index 40d65a28f61c..56cc54bd977d 100644 --- a/drivers/thermal/pwm_fan.c +++ b/drivers/thermal/pwm_fan.c @@ -61,6 +61,8 @@ struct fan_dev_data { int tach_irq; int tach_enabled; int fan_state_cap; + int pwm_gpio; + int pwm_id; }; #ifdef CONFIG_DEBUG_FS @@ -659,6 +661,8 @@ static int __devinit pwm_fan_probe(struct platform_device *pdev) fan_data->pwm_period = data->pwm_period; fan_data->dev = &pdev->dev; fan_data->fan_state_cap = data->state_cap; + fan_data->pwm_gpio = data->pwm_gpio; + fan_data->pwm_id = data->pwm_id; for (i = 0; i < fan_data->active_steps; i++) { fan_data->fan_rpm[i] = data->active_rpm[i]; @@ -778,6 +782,7 @@ static int __devexit pwm_fan_remove(struct platform_device *pdev) static int pwm_fan_suspend(struct platform_device *pdev, pm_message_t state) { struct fan_dev_data *fan_data = platform_get_drvdata(pdev); + int err; mutex_lock(&fan_data->fan_state_lock); dev_info(&pdev->dev, "%s, cur_pwm:%d, target_pwm:%d, cap:%d", @@ -788,7 +793,18 @@ static int pwm_fan_suspend(struct platform_device *pdev, pm_message_t state) /*Turn the fan off*/ fan_data->fan_cur_pwm = 0; fan_data->next_target_pwm = 0; + set_pwm_duty_cycle(0, fan_data); + pwm_disable(fan_data->pwm_dev); + pwm_free(fan_data->pwm_dev); + + err = gpio_request(fan_data->pwm_gpio, "pwm-fan"); + if (err < 0) { + dev_err(&pdev->dev, "%s:gpio request failed %d\n", + __func__, fan_data->pwm_gpio); + } + + gpio_direction_output(fan_data->pwm_gpio, 1); /*Stop thermal control*/ fan_data->fan_temp_control_flag = 0; @@ -802,14 +818,24 @@ static int pwm_fan_resume(struct platform_device *pdev) /*Sanity check, want to make sure fan is off when the driver resumes*/ mutex_lock(&fan_data->fan_state_lock); - set_pwm_duty_cycle(0, fan_data); - - /*Start thermal control*/ - fan_data->fan_temp_control_flag = 1; dev_info(&pdev->dev, "%s, cur_pwm:%d, target_pwm:%d, cap:%d", __func__, fan_data->fan_cur_pwm, fan_data->next_target_pwm, fan_data->fan_cap_pwm); + gpio_free(fan_data->pwm_gpio); + fan_data->pwm_dev = pwm_request(fan_data->pwm_id, dev_name(&pdev->dev)); + if (IS_ERR_OR_NULL(fan_data->pwm_dev)) { + dev_err(&pdev->dev, " %s: unable to request PWM for fan\n", + __func__); + mutex_unlock(&fan_data->fan_state_lock); + return -ENODEV; + } else { + dev_info(&pdev->dev, " %s, got pwm for fan\n", __func__); + } + + set_pwm_duty_cycle(0, fan_data); + /*Start thermal control*/ + fan_data->fan_temp_control_flag = 1; mutex_unlock(&fan_data->fan_state_lock); return 0; diff --git a/include/linux/platform_data/pwm_fan.h b/include/linux/platform_data/pwm_fan.h index 8751d6270dde..57d21c08cc63 100644 --- a/include/linux/platform_data/pwm_fan.h +++ b/include/linux/platform_data/pwm_fan.h @@ -1,7 +1,7 @@ /* * include/linux/platform_data/pwm_fan.h * - * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -34,5 +34,6 @@ struct pwm_fan_platform_data { int precision_multiplier; int tach_gpio; int state_cap; + int pwm_gpio; }; #endif |