drivers: misc: therm_est: Add therm_est_subdev_get_temp function
Jinyoung Park [Thu, 21 Mar 2013 07:59:54 +0000 (16:59 +0900)]
Added therm_est_subdev_get_temp function instead of get_temp callback in
struct therm_est_subdevice in order to remove redeundancy code.

Bug 1233363
Bug 1236444

Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/211539
(cherry picked from commit 02ebe3a815127af786292d1a7d144277aa966b63)

Change-Id: If1126f9227b6821a79ed1d9718ed4cd7cea3c540
Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/215543
GVS: Gerrit_Virtual_Submit
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

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

index 1c95308..da1c74a 100644 (file)
@@ -57,6 +57,23 @@ struct therm_estimator {
 #endif
 };
 
+static int therm_est_subdev_match(struct thermal_zone_device *thz, void *data)
+{
+       return strcmp((char *)data, thz->type) == 0;
+}
+
+static int therm_est_subdev_get_temp(void *data, long *temp)
+{
+       struct thermal_zone_device *thz;
+
+       thz = thermal_zone_device_find(data, therm_est_subdev_match);
+
+       if (!thz || thz->ops->get_temp(thz, temp))
+               *temp = 25000;
+
+       return 0;
+}
+
 static void therm_est_update_limits(struct therm_estimator *est)
 {
        const int MAX_HIGH_TEMP = 128000;
@@ -105,7 +122,7 @@ static void therm_est_work_func(struct work_struct *work)
                                        therm_est_work);
 
        for (i = 0; i < est->ndevs; i++) {
-               if (est->devs[i].get_temp(est->devs[i].dev_data, &temp))
+               if (therm_est_subdev_get_temp(est->devs[i].dev_data, &temp))
                        continue;
                est->devs[i].hist[(est->ntemp % HIST_LEN)] = temp;
        }
@@ -448,7 +465,7 @@ static int therm_est_init_history(struct therm_estimator *est)
        for (i = 0; i < est->ndevs; i++) {
                dev = &est->devs[i];
 
-               if (dev->get_temp(dev->dev_data, &temp))
+               if (therm_est_subdev_get_temp(dev->dev_data, &temp))
                        return -EINVAL;
 
                for (j = 0; j < HIST_LEN; j++)
index f1ccbf0..faf1cf8 100644 (file)
@@ -27,7 +27,6 @@
 
 struct therm_est_subdevice {
        void *dev_data;
-       int (*get_temp)(void *, long *);
        long coeffs[HIST_LEN];
        long hist[HIST_LEN];
 };