powerpc/windfarm: Add useful accessors
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 18 Apr 2012 22:16:51 +0000 (22:16 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Mon, 30 Apr 2012 05:37:20 +0000 (15:37 +1000)
Makes the code more readable

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
drivers/macintosh/windfarm.h
drivers/macintosh/windfarm_pm81.c
drivers/macintosh/windfarm_pm91.c

index 3ef192a1fca084d66dcefd6eda6deea5f108b232..a9e385ee359ecfcf075d7c2e0109f09d42749a16 100644 (file)
@@ -72,6 +72,26 @@ static inline int wf_control_set_min(struct wf_control *ct)
        return ct->ops->set_value(ct, vmin);
 }
 
+static inline int wf_control_set(struct wf_control *ct, s32 val)
+{
+       return ct->ops->set_value(ct, val);
+}
+
+static inline int wf_control_get(struct wf_control *ct, s32 *val)
+{
+       return ct->ops->get_value(ct, val);
+}
+
+static inline s32 wf_control_get_min(struct wf_control *ct)
+{
+       return ct->ops->get_min(ct);
+}
+
+static inline s32 wf_control_get_max(struct wf_control *ct)
+{
+       return ct->ops->get_max(ct);
+}
+
 /*
  * Sensor objects
  */
@@ -100,6 +120,11 @@ extern struct wf_sensor * wf_find_sensor(const char *name);
 extern int wf_get_sensor(struct wf_sensor *sr);
 extern void wf_put_sensor(struct wf_sensor *sr);
 
+static inline int wf_sensor_get(struct wf_sensor *sr, s32 *val)
+{
+       return sr->ops->get_value(sr, val);
+}
+
 /* For use by clients. Note that we are a bit racy here since
  * notifier_block doesn't have a module owner field. I may fix
  * it one day ...
index fc13d0f2663bb2475ca4a97a9e43d84302a48162..990c87606be9579db02549c765a05b9ebb82ee5c 100644 (file)
@@ -302,13 +302,13 @@ static void wf_smu_create_sys_fans(void)
        pid_param.interval = WF_SMU_SYS_FANS_INTERVAL;
        pid_param.history_len = WF_SMU_SYS_FANS_HISTORY_SIZE;
        pid_param.itarget = param->itarget;
-       pid_param.min = fan_system->ops->get_min(fan_system);
-       pid_param.max = fan_system->ops->get_max(fan_system);
+       pid_param.min = wf_control_get_min(fan_system);
+       pid_param.max = wf_control_get_max(fan_system);
        if (fan_hd) {
                pid_param.min =
-                       max(pid_param.min,fan_hd->ops->get_min(fan_hd));
+                       max(pid_param.min, wf_control_get_min(fan_hd));
                pid_param.max =
-                       min(pid_param.max,fan_hd->ops->get_max(fan_hd));
+                       min(pid_param.max, wf_control_get_max(fan_hd));
        }
        wf_pid_init(&wf_smu_sys_fans->pid, &pid_param);
 
@@ -337,7 +337,7 @@ static void wf_smu_sys_fans_tick(struct wf_smu_sys_fans_state *st)
        }
        st->ticks = WF_SMU_SYS_FANS_INTERVAL;
 
-       rc = sensor_hd_temp->ops->get_value(sensor_hd_temp, &temp);
+       rc = wf_sensor_get(sensor_hd_temp, &temp);
        if (rc) {
                printk(KERN_WARNING "windfarm: HD temp sensor error %d\n",
                       rc);
@@ -373,7 +373,7 @@ static void wf_smu_sys_fans_tick(struct wf_smu_sys_fans_state *st)
        st->hd_setpoint = new_setpoint;
  readjust:
        if (fan_system && wf_smu_failure_state == 0) {
-               rc = fan_system->ops->set_value(fan_system, st->sys_setpoint);
+               rc = wf_control_set(fan_system, st->sys_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: Sys fan error %d\n",
                               rc);
@@ -381,7 +381,7 @@ static void wf_smu_sys_fans_tick(struct wf_smu_sys_fans_state *st)
                }
        }
        if (fan_hd && wf_smu_failure_state == 0) {
-               rc = fan_hd->ops->set_value(fan_hd, st->hd_setpoint);
+               rc = wf_control_set(fan_hd, st->hd_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: HD fan error %d\n",
                               rc);
@@ -447,8 +447,8 @@ static void wf_smu_create_cpu_fans(void)
        pid_param.ttarget = tmax - tdelta;
        pid_param.pmaxadj = maxpow - powadj;
 
-       pid_param.min = fan_cpu_main->ops->get_min(fan_cpu_main);
-       pid_param.max = fan_cpu_main->ops->get_max(fan_cpu_main);
+       pid_param.min = wf_control_get_min(fan_cpu_main);
+       pid_param.max = wf_control_get_max(fan_cpu_main);
 
        wf_cpu_pid_init(&wf_smu_cpu_fans->pid, &pid_param);
 
@@ -481,7 +481,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
        }
        st->ticks = WF_SMU_CPU_FANS_INTERVAL;
 
-       rc = sensor_cpu_temp->ops->get_value(sensor_cpu_temp, &temp);
+       rc = wf_sensor_get(sensor_cpu_temp, &temp);
        if (rc) {
                printk(KERN_WARNING "windfarm: CPU temp sensor error %d\n",
                       rc);
@@ -489,7 +489,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
                return;
        }
 
-       rc = sensor_cpu_power->ops->get_value(sensor_cpu_power, &power);
+       rc = wf_sensor_get(sensor_cpu_power, &power);
        if (rc) {
                printk(KERN_WARNING "windfarm: CPU power sensor error %d\n",
                       rc);
@@ -525,8 +525,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
        st->cpu_setpoint = new_setpoint;
  readjust:
        if (fan_cpu_main && wf_smu_failure_state == 0) {
-               rc = fan_cpu_main->ops->set_value(fan_cpu_main,
-                                                 st->cpu_setpoint);
+               rc = wf_control_set(fan_cpu_main, st->cpu_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: CPU main fan"
                               " error %d\n", rc);
index a9430ed4f36ce1c418f5e16ab7af4519bf60281c..e18002bcc1c39713b9c5a8a97515d53fbb4f7008 100644 (file)
@@ -192,8 +192,8 @@ static void wf_smu_create_cpu_fans(void)
        pid_param.ttarget = tmax - tdelta;
        pid_param.pmaxadj = maxpow - powadj;
 
-       pid_param.min = fan_cpu_main->ops->get_min(fan_cpu_main);
-       pid_param.max = fan_cpu_main->ops->get_max(fan_cpu_main);
+       pid_param.min = wf_control_get_min(fan_cpu_main);
+       pid_param.max = wf_control_get_max(fan_cpu_main);
 
        wf_cpu_pid_init(&wf_smu_cpu_fans->pid, &pid_param);
 
@@ -226,7 +226,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
        }
        st->ticks = WF_SMU_CPU_FANS_INTERVAL;
 
-       rc = sensor_cpu_temp->ops->get_value(sensor_cpu_temp, &temp);
+       rc = wf_sensor_get(sensor_cpu_temp, &temp);
        if (rc) {
                printk(KERN_WARNING "windfarm: CPU temp sensor error %d\n",
                       rc);
@@ -234,7 +234,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
                return;
        }
 
-       rc = sensor_cpu_power->ops->get_value(sensor_cpu_power, &power);
+       rc = wf_sensor_get(&sensor_cpu_power, &power);
        if (rc) {
                printk(KERN_WARNING "windfarm: CPU power sensor error %d\n",
                       rc);
@@ -261,8 +261,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
        st->cpu_setpoint = new_setpoint;
  readjust:
        if (fan_cpu_main && wf_smu_failure_state == 0) {
-               rc = fan_cpu_main->ops->set_value(fan_cpu_main,
-                                                 st->cpu_setpoint);
+               rc = wf_control_set(fan_cpu_main, st->cpu_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: CPU main fan"
                               " error %d\n", rc);
@@ -270,8 +269,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
                }
        }
        if (fan_cpu_second && wf_smu_failure_state == 0) {
-               rc = fan_cpu_second->ops->set_value(fan_cpu_second,
-                                                   st->cpu_setpoint);
+               rc = wf_control_set(fan_cpu_second, st->cpu_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: CPU second fan"
                               " error %d\n", rc);
@@ -279,8 +277,7 @@ static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
                }
        }
        if (fan_cpu_third && wf_smu_failure_state == 0) {
-               rc = fan_cpu_main->ops->set_value(fan_cpu_third,
-                                                 st->cpu_setpoint);
+               rc = wf_control_set(fan_cpu_third, st->cpu_setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: CPU third fan"
                               " error %d\n", rc);
@@ -312,8 +309,8 @@ static void wf_smu_create_drive_fans(void)
 
        /* Fill PID params */
        param.additive = (fan_hd->type == WF_CONTROL_RPM_FAN);
-       param.min = fan_hd->ops->get_min(fan_hd);
-       param.max = fan_hd->ops->get_max(fan_hd);
+       param.min = wf_control_get_min(fan_hd);
+       param.max = wf_control_get_max(fan_hd);
        wf_pid_init(&wf_smu_drive_fans->pid, &param);
 
        DBG("wf: Drive Fan control initialized.\n");
@@ -338,7 +335,7 @@ static void wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state *st)
        }
        st->ticks = st->pid.param.interval;
 
-       rc = sensor_hd_temp->ops->get_value(sensor_hd_temp, &temp);
+       rc = wf_sensor_get(sensor_hd_temp, &temp);
        if (rc) {
                printk(KERN_WARNING "windfarm: HD temp sensor error %d\n",
                       rc);
@@ -361,7 +358,7 @@ static void wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state *st)
        st->setpoint = new_setpoint;
  readjust:
        if (fan_hd && wf_smu_failure_state == 0) {
-               rc = fan_hd->ops->set_value(fan_hd, st->setpoint);
+               rc = wf_control_set(fan_hd, st->setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: HD fan error %d\n",
                               rc);
@@ -393,8 +390,8 @@ static void wf_smu_create_slots_fans(void)
 
        /* Fill PID params */
        param.additive = (fan_slots->type == WF_CONTROL_RPM_FAN);
-       param.min = fan_slots->ops->get_min(fan_slots);
-       param.max = fan_slots->ops->get_max(fan_slots);
+       param.min = wf_control_get_min(fan_slots);
+       param.max = wf_control_get_max(fan_slots);
        wf_pid_init(&wf_smu_slots_fans->pid, &param);
 
        DBG("wf: Slots Fan control initialized.\n");
@@ -419,7 +416,7 @@ static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
        }
        st->ticks = st->pid.param.interval;
 
-       rc = sensor_slots_power->ops->get_value(sensor_slots_power, &power);
+       rc = wf_sensor_get(sensor_slots_power, &power);
        if (rc) {
                printk(KERN_WARNING "windfarm: Slots power sensor error %d\n",
                       rc);
@@ -444,7 +441,7 @@ static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
        st->setpoint = new_setpoint;
  readjust:
        if (fan_slots && wf_smu_failure_state == 0) {
-               rc = fan_slots->ops->set_value(fan_slots, st->setpoint);
+               rc = wf_control_set(fan_slots, st->setpoint);
                if (rc) {
                        printk(KERN_WARNING "windfarm: Slots fan error %d\n",
                               rc);