]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
misc: nct1008: talk to nct1008 only when powered
authorSang-Hun Lee <sanlee@nvidia.com>
Mon, 13 May 2013 17:06:00 +0000 (10:06 -0700)
committerDan Willemsen <dwillemsen@nvidia.com>
Sat, 14 Sep 2013 20:15:32 +0000 (13:15 -0700)
Problem description:
 - nct1008_suspend powers off nct1008
 - nct1008_suspend does stop the workqueue and irq, but
   if there is a kernel thread which would trigger
   nct1008_read_reg or nct1008_write_reg, nct1008 would
   still be accessed after it is powered off

Fix description:
 - Rename the existing flag shutdown_complete to nct_disabled
 - Update the value of nct_disabled when powering nct1008 on and off

Bug 1288427

Change-Id: Id885794eb39a71025ad9f5c3615156c19039d13f
Signed-off-by: Sang-Hun Lee <sanlee@nvidia.com>
Reviewed-on: http://git-master/r/228011
(cherry picked from commit 08eed1ddbacece2f1c8b4fba633c01c0f87ba2cd)
Reviewed-on: http://git-master/r/231294
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bitan Biswas <bbiswas@nvidia.com>
drivers/misc/nct1008.c

index d698bec953fbb99e3cf2458db2559aa42a1e089a..7c157a7cf713de1dca65eeaf0b37be764269c1f7 100644 (file)
@@ -95,7 +95,7 @@ struct nct1008_data {
        long current_hi_limit;
        int conv_period_ms;
        long etemp;
-       int shutdown_complete;
+       int nct_disabled;
        int stop_workqueue;
        struct thermal_zone_device *nct_int;
        struct thermal_zone_device *nct_ext;
@@ -120,7 +120,7 @@ static int nct1008_write_reg(struct i2c_client *client, u8 reg, u16 value)
        struct nct1008_data *data = i2c_get_clientdata(client);
 
        mutex_lock(&data->mutex);
-       if (data && data->shutdown_complete) {
+       if (data && data->nct_disabled) {
                mutex_unlock(&data->mutex);
                return -ENODEV;
        }
@@ -139,7 +139,7 @@ static int nct1008_read_reg(struct i2c_client *client, u8 reg)
        int ret = 0;
        struct nct1008_data *data = i2c_get_clientdata(client);
        mutex_lock(&data->mutex);
-       if (data && data->shutdown_complete) {
+       if (data && data->nct_disabled) {
                mutex_unlock(&data->mutex);
                return -ENODEV;
        }
@@ -894,6 +894,7 @@ static irqreturn_t nct1008_irq(int irq, void *dev_id)
 static void nct1008_power_control(struct nct1008_data *data, bool is_enable)
 {
        int ret;
+       mutex_lock(&data->mutex);
        if (!data->nct_reg) {
                data->nct_reg = regulator_get(&data->client->dev, "vdd");
                if (IS_ERR_OR_NULL(data->nct_reg)) {
@@ -906,6 +907,7 @@ static void nct1008_power_control(struct nct1008_data *data, bool is_enable)
                                        "getting the regulator handle for"
                                        " vdd\n", PTR_ERR(data->nct_reg));
                        data->nct_reg = NULL;
+                       mutex_unlock(&data->mutex);
                        return;
                }
        }
@@ -925,6 +927,8 @@ static void nct1008_power_control(struct nct1008_data *data, bool is_enable)
                dev_info(&data->client->dev, "success in %s rail vdd_nct%s\n",
                        (is_enable) ? "enabling" : "disabling",
                        (data->chip == NCT72) ? "72" : "1008");
+       data->nct_disabled = !is_enable;
+       mutex_unlock(&data->mutex);
 }
 
 static int nct1008_configure_sensor(struct nct1008_data *data)
@@ -1232,7 +1236,7 @@ static void nct1008_shutdown(struct i2c_client *client)
                disable_irq(client->irq);
 
        mutex_lock(&data->mutex);
-       data->shutdown_complete = 1;
+       data->nct_disabled = 1;
        mutex_unlock(&data->mutex);
 }