drivers: thermal: adding internal fan reg flag
Terry Wang [Wed, 18 Mar 2015 07:58:24 +0000 (07:58 +0000)]
Adding internal fan regulator status flag.

bug 200069439

Change-Id: Ibcbc6e45ca15d553b03d06ccddc648e06cc19cce
Signed-off-by: Terry Wang <terwang@nvidia.com>
Reviewed-on: http://git-master/r/720437
Reviewed-on: http://git-master/r/718917
Reviewed-by: Aaron Huang <aaronh@nvidia.com>
Reviewed-by: Anshul Jain (SW) <anshulj@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>

drivers/thermal/pwm_fan.c

index 78a6d5d..b7fc266 100644 (file)
@@ -71,6 +71,7 @@ struct fan_dev_data {
        int pwm_id;
        const char *name;
        struct regulator *fan_reg;
+       bool is_fan_reg_enabled;
 };
 
 #ifdef CONFIG_DEBUG_FS
@@ -502,23 +503,27 @@ static void fan_ramping_work_func(struct work_struct *work)
                next_pwm = max(0, next_pwm);
        }
 
-       if ((next_pwm != 0) && !(regulator_is_enabled(fan_data->fan_reg))) {
+       if ((next_pwm != 0) && !(fan_data->is_fan_reg_enabled)) {
                err = regulator_enable(fan_data->fan_reg);
                if (err < 0)
                        dev_err(fan_data->dev,
                                " Coudn't enable vdd-fan\n");
-               else
+               else {
                        dev_info(fan_data->dev,
                                " Enabled vdd-fan\n");
+                       fan_data->is_fan_reg_enabled = true;
+               }
        }
-       if ((next_pwm == 0) && (regulator_is_enabled(fan_data->fan_reg))) {
+       if ((next_pwm == 0) && (fan_data->is_fan_reg_enabled)) {
                err = regulator_disable(fan_data->fan_reg);
                if (err < 0)
                        dev_err(fan_data->dev,
                                " Couldn't disable vdd-fan\n");
-               else
+               else {
                        dev_info(fan_data->dev,
                                " Disabled vdd-fan\n");
+                       fan_data->is_fan_reg_enabled = false;
+               }
        }
 
        set_pwm_duty_cycle(next_pwm, fan_data);
@@ -1026,9 +1031,16 @@ static int pwm_fan_suspend(struct platform_device *pdev, pm_message_t state)
 
        gpio_direction_output(fan_data->pwm_gpio, 1);
 
-       err = regulator_disable(fan_data->fan_reg);
-       if (err < 0)
-               dev_err(&pdev->dev, "Not able to disable Fan regulator\n");
+       if (fan_data->is_fan_reg_enabled) {
+               err = regulator_disable(fan_data->fan_reg);
+               if (err < 0)
+                       dev_err(&pdev->dev, "Not able to disable Fan regulator\n");
+               else {
+                       dev_info(fan_data->dev,
+                               " Disabled vdd-fan\n");
+                       fan_data->is_fan_reg_enabled = false;
+               }
+       }
        /*Stop thermal control*/
        fan_data->fan_temp_control_flag = 0;
        mutex_unlock(&fan_data->fan_state_lock);