drivers: misc: nct: Expose active dev interface
Joshua Primero [Wed, 24 Oct 2012 21:18:31 +0000 (14:18 -0700)]
Exposed the new active cooling device interface from new
Linux Thermal Framework API in the nct1008 driver.

bug 1059470

Change-Id: I34417984aa846499aef636d1391f88313e333cb4
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Reviewed-on: http://git-master/r/159980
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/misc/nct1008.c
include/linux/nct1008.h

index eb9013e..de58ba0 100644 (file)
@@ -95,7 +95,7 @@ struct nct1008_data {
        long etemp;
 
        struct thermal_cooling_device *passive_cdev;
-       struct thermal_cooling_device *active_cdev[NCT1008_MAX_ACTIVE];
+       struct thermal_cooling_device *active_cdev;
        struct thermal_zone_device *nct_int;
        struct thermal_zone_device *nct_ext;
 };
@@ -590,7 +590,7 @@ static void nct1008_update(struct nct1008_data *data)
                        high_temp = trip_temp;
 
                if ((trip_temp < temp) && (trip_temp > low_temp)) {
-                       cdev = count ? &data->plat_data.active[count - 1] :
+                       cdev = count ? &data->plat_data.active :
                                        &data->plat_data.passive;
                        low_temp = trip_temp - cdev->hysteresis;
                }
@@ -854,11 +854,11 @@ static int nct1008_ext_bind(struct thermal_zone_device *thz,
                                                        THERMAL_NO_LIMIT,
                                                        THERMAL_NO_LIMIT);
 
-       for (i = 0; data->active_cdev[i]; i++)
-               if (cdev == data->active_cdev[i])
-                       return thermal_zone_bind_cooling_device(thz, i+1, cdev,
-                                                       THERMAL_NO_LIMIT,
-                                                       THERMAL_NO_LIMIT);
+       if (cdev == data->active_cdev)
+               for (i = 0; i < data->plat_data.active.states[i].trip_temp; i++)
+                       thermal_zone_bind_cooling_device(thz, i+1, cdev,
+                                       data->plat_data.active.states[i].state,
+                                       data->plat_data.active.states[i].state);
 
        return 0;
 }
@@ -872,10 +872,9 @@ static int nct1008_ext_unbind(struct thermal_zone_device *thz,
        if (cdev == data->passive_cdev)
                return thermal_zone_unbind_cooling_device(thz, 0, cdev);
 
-       for (i = 0; data->active_cdev[i]; i++)
-               if (cdev == data->active_cdev[i])
-                       return thermal_zone_unbind_cooling_device(thz,
-                                                               i+1, cdev);
+       if (cdev == data->active_cdev)
+               for (i = 0; i < data->plat_data.active.states[i].trip_temp; i++)
+                       thermal_zone_unbind_cooling_device(thz, i+1, cdev);
 
        return 0;
 }
@@ -888,7 +887,7 @@ static int nct1008_ext_get_trip_temp(struct thermal_zone_device *thz,
        if (trip == 0)
                *temp = data->plat_data.passive.trip_temp;
        else
-               *temp = data->plat_data.active[trip-1].trip_temp;
+               *temp = data->plat_data.active.states[trip-1].trip_temp;
        return 0;
 }
 
@@ -900,7 +899,7 @@ static int nct1008_ext_set_trip_temp(struct thermal_zone_device *thz,
        if (trip == 0)
                data->plat_data.passive.trip_temp = temp;
        else
-               data->plat_data.active[trip-1].trip_temp = temp;
+               data->plat_data.active.states[trip-1].trip_temp = temp;
 
        nct1008_update(data);
 
@@ -1067,11 +1066,12 @@ static int __devinit nct1008_probe(struct i2c_client *client,
                num_trips++;
        }
 
-       for (i = 0; data->plat_data.active[i].create_cdev; i++) {
-               data->active_cdev[i] = data->plat_data.active[i].create_cdev(
-                               data->plat_data.active[i].cdev_data);
-               mask |= (1 << num_trips);
-               num_trips++;
+       if (data->plat_data.active.create_cdev) {
+               data->active_cdev = data->plat_data.active.create_cdev(NULL);
+               for (i = 0; data->plat_data.active.states[i].trip_temp; i++) {
+                       mask |= (1 << num_trips);
+                       num_trips++;
+               }
        }
 
        data->nct_int = thermal_zone_device_register("nct_int",
index 9eec97f..68b35f1 100644 (file)
@@ -31,6 +31,14 @@ struct nct1008_data;
 
 enum nct1008_chip { NCT1008, NCT72 };
 
+
+struct active_temp_state {
+       long trip_temp;
+       unsigned long state;
+};
+
+#define MAX_ACTIVE_TEMP_STATE 16
+
 struct nct1008_cdev {
        struct thermal_cooling_device *(*create_cdev)(void *);
        void *cdev_data;
@@ -40,10 +48,9 @@ struct nct1008_cdev {
        int tc1;
        int tc2;
        int passive_delay;
+       struct active_temp_state states[MAX_ACTIVE_TEMP_STATE];
 };
 
-#define NCT1008_MAX_ACTIVE (16)
-
 struct nct1008_platform_data {
        bool supported_hwrev;
        bool ext_range;
@@ -53,6 +60,6 @@ struct nct1008_platform_data {
        s8 shutdown_local_limit;
 
        struct nct1008_cdev passive;
-       struct nct1008_cdev active[NCT1008_MAX_ACTIVE];
+       struct nct1008_cdev active;
 };
 #endif /* _LINUX_NCT1008_H */