]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/macintosh/windfarm_pm91.c
[POWERPC] macintosh/windfarm: Fix platform driver hotplug/coldplug
[linux-2.6-omap-h63xx.git] / drivers / macintosh / windfarm_pm91.c
index 43243cf7410b3d887802cfce731a55c7a08b7178..764c525b2117f0ac2420992063ac1efdcb512a21 100644 (file)
@@ -63,8 +63,6 @@
  */
 #undef HACKED_OVERTEMP
 
-static struct device *wf_smu_dev;
-
 /* Controls & sensors */
 static struct wf_sensor        *sensor_cpu_power;
 static struct wf_sensor        *sensor_cpu_temp;
@@ -144,7 +142,7 @@ static struct wf_smu_slots_fans_state *wf_smu_slots_fans;
 static void wf_smu_create_cpu_fans(void)
 {
        struct wf_cpu_pid_param pid_param;
-       struct smu_sdbp_header *hdr;
+       const struct smu_sdbp_header *hdr;
        struct smu_sdbp_cpupiddata *piddata;
        struct smu_sdbp_fvt *fvt;
        s32 tmax, tdelta, maxpow, powadj;
@@ -457,45 +455,6 @@ static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
 }
 
 
-/*
- * ****** Attributes ******
- *
- */
-
-#define BUILD_SHOW_FUNC_FIX(name, data)                                \
-static ssize_t show_##name(struct device *dev,                  \
-                          struct device_attribute *attr,       \
-                          char *buf)                           \
-{                                                              \
-       ssize_t r;                                              \
-       s32 val = 0;                                            \
-       data->ops->get_value(data, &val);                       \
-       r = sprintf(buf, "%d.%03d", FIX32TOPRINT(val));         \
-       return r;                                               \
-}                                                               \
-static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
-
-
-#define BUILD_SHOW_FUNC_INT(name, data)                                \
-static ssize_t show_##name(struct device *dev,                  \
-                          struct device_attribute *attr,       \
-                          char *buf)                           \
-{                                                              \
-       s32 val = 0;                                            \
-       data->ops->get_value(data, &val);                       \
-       return sprintf(buf, "%d", val);                         \
-}                                                               \
-static DEVICE_ATTR(name,S_IRUGO,show_##name, NULL);
-
-BUILD_SHOW_FUNC_INT(cpu_fan, fan_cpu_main);
-BUILD_SHOW_FUNC_INT(hd_fan, fan_hd);
-BUILD_SHOW_FUNC_INT(slots_fan, fan_slots);
-
-BUILD_SHOW_FUNC_FIX(cpu_temp, sensor_cpu_temp);
-BUILD_SHOW_FUNC_FIX(cpu_power, sensor_cpu_power);
-BUILD_SHOW_FUNC_FIX(hd_temp, sensor_hd_temp);
-BUILD_SHOW_FUNC_FIX(slots_power, sensor_slots_power);
-
 /*
  * ****** Setup / Init / Misc ... ******
  *
@@ -581,10 +540,8 @@ static void wf_smu_new_control(struct wf_control *ct)
                return;
 
        if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) {
-               if (wf_get_control(ct) == 0) {
+               if (wf_get_control(ct) == 0)
                        fan_cpu_main = ct;
-                       device_create_file(wf_smu_dev, &dev_attr_cpu_fan);
-               }
        }
 
        if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) {
@@ -603,17 +560,13 @@ static void wf_smu_new_control(struct wf_control *ct)
        }
 
        if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {
-               if (wf_get_control(ct) == 0) {
+               if (wf_get_control(ct) == 0)
                        fan_hd = ct;
-                       device_create_file(wf_smu_dev, &dev_attr_hd_fan);
-               }
        }
 
        if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) {
-               if (wf_get_control(ct) == 0) {
+               if (wf_get_control(ct) == 0)
                        fan_slots = ct;
-                       device_create_file(wf_smu_dev, &dev_attr_slots_fan);
-               }
        }
 
        if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd &&
@@ -627,31 +580,23 @@ static void wf_smu_new_sensor(struct wf_sensor *sr)
                return;
 
        if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {
-               if (wf_get_sensor(sr) == 0) {
+               if (wf_get_sensor(sr) == 0)
                        sensor_cpu_power = sr;
-                       device_create_file(wf_smu_dev, &dev_attr_cpu_power);
-               }
        }
 
        if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {
-               if (wf_get_sensor(sr) == 0) {
+               if (wf_get_sensor(sr) == 0)
                        sensor_cpu_temp = sr;
-                       device_create_file(wf_smu_dev, &dev_attr_cpu_temp);
-               }
        }
 
        if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {
-               if (wf_get_sensor(sr) == 0) {
+               if (wf_get_sensor(sr) == 0)
                        sensor_hd_temp = sr;
-                       device_create_file(wf_smu_dev, &dev_attr_hd_temp);
-               }
        }
 
        if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) {
-               if (wf_get_sensor(sr) == 0) {
+               if (wf_get_sensor(sr) == 0)
                        sensor_slots_power = sr;
-                       device_create_file(wf_smu_dev, &dev_attr_slots_power);
-               }
        }
 
        if (sensor_cpu_power && sensor_cpu_temp &&
@@ -694,16 +639,14 @@ static int wf_init_pm(void)
        return 0;
 }
 
-static int wf_smu_probe(struct device *ddev)
+static int wf_smu_probe(struct platform_device *ddev)
 {
-       wf_smu_dev = ddev;
-
        wf_register_client(&wf_smu_events);
 
        return 0;
 }
 
-static int wf_smu_remove(struct device *ddev)
+static int __devexit wf_smu_remove(struct platform_device *ddev)
 {
        wf_unregister_client(&wf_smu_events);
 
@@ -720,40 +663,26 @@ static int wf_smu_remove(struct device *ddev)
         * with that except by adding locks all over... I'll do that
         * eventually but heh, who ever rmmod this module anyway ?
         */
-       if (sensor_cpu_power) {
-               device_remove_file(wf_smu_dev, &dev_attr_cpu_power);
+       if (sensor_cpu_power)
                wf_put_sensor(sensor_cpu_power);
-       }
-       if (sensor_cpu_temp) {
-               device_remove_file(wf_smu_dev, &dev_attr_cpu_temp);
+       if (sensor_cpu_temp)
                wf_put_sensor(sensor_cpu_temp);
-       }
-       if (sensor_hd_temp) {
-               device_remove_file(wf_smu_dev, &dev_attr_hd_temp);
+       if (sensor_hd_temp)
                wf_put_sensor(sensor_hd_temp);
-       }
-       if (sensor_slots_power) {
-               device_remove_file(wf_smu_dev, &dev_attr_slots_power);
+       if (sensor_slots_power)
                wf_put_sensor(sensor_slots_power);
-       }
 
        /* Release all controls */
-       if (fan_cpu_main) {
-               device_remove_file(wf_smu_dev, &dev_attr_cpu_fan);
+       if (fan_cpu_main)
                wf_put_control(fan_cpu_main);
-       }
        if (fan_cpu_second)
                wf_put_control(fan_cpu_second);
        if (fan_cpu_third)
                wf_put_control(fan_cpu_third);
-       if (fan_hd) {
-               device_remove_file(wf_smu_dev, &dev_attr_hd_fan);
+       if (fan_hd)
                wf_put_control(fan_hd);
-       }
-       if (fan_slots) {
-               device_remove_file(wf_smu_dev, &dev_attr_slots_fan);
+       if (fan_slots)
                wf_put_control(fan_slots);
-       }
        if (cpufreq_clamp)
                wf_put_control(cpufreq_clamp);
 
@@ -765,16 +694,16 @@ static int wf_smu_remove(struct device *ddev)
        if (wf_smu_cpu_fans)
                kfree(wf_smu_cpu_fans);
 
-       wf_smu_dev = NULL;
-
        return 0;
 }
 
-static struct device_driver wf_smu_driver = {
-        .name = "windfarm",
-        .bus = &platform_bus_type,
+static struct platform_driver wf_smu_driver = {
         .probe = wf_smu_probe,
-        .remove = wf_smu_remove,
+        .remove = __devexit_p(wf_smu_remove),
+       .driver = {
+               .name = "windfarm",
+               .owner  = THIS_MODULE,
+       },
 };
 
 
@@ -790,9 +719,10 @@ static int __init wf_smu_init(void)
                request_module("windfarm_smu_controls");
                request_module("windfarm_smu_sensors");
                request_module("windfarm_lm75_sensor");
+               request_module("windfarm_cpufreq_clamp");
 
 #endif /* MODULE */
-               driver_register(&wf_smu_driver);
+               platform_driver_register(&wf_smu_driver);
        }
 
        return rc;
@@ -801,7 +731,7 @@ static int __init wf_smu_init(void)
 static void __exit wf_smu_exit(void)
 {
 
-       driver_unregister(&wf_smu_driver);
+       platform_driver_unregister(&wf_smu_driver);
 }
 
 
@@ -812,3 +742,4 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
 MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1");
 MODULE_LICENSE("GPL");
 
+MODULE_ALIAS("platform:windfarm");