Merge branch 'for-linus' of git://neil.brown.name/md
[safe/jmp/linux-2.6] / drivers / macintosh / windfarm_max6690_sensor.c
index 5b9ad6c..e207a90 100644 (file)
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
-#include <linux/i2c-dev.h>
 #include <asm/prom.h>
 #include <asm/pmac_low_i2c.h>
 
 #include "windfarm.h"
 
-#define VERSION "0.1"
+#define VERSION "0.2"
 
 /* This currently only exports the external temperature sensor,
    since that's all the control loops need. */
@@ -78,18 +77,28 @@ static struct wf_sensor_ops wf_max6690_ops = {
        .owner          = THIS_MODULE,
 };
 
-static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr)
+static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr,
+                             const char *loc)
 {
        struct wf_6690_sensor *max;
-       char *name = "u4-temp";
+       char *name;
 
        max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
        if (max == NULL) {
                printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor %s: "
-                      "no memory\n", name);
+                      "no memory\n", loc);
                return;
        }
 
+       if (!strcmp(loc, "BACKSIDE"))
+               name = "backside-temp";
+       else if (!strcmp(loc, "NB Ambient"))
+               name = "north-bridge-temp";
+       else if (!strcmp(loc, "GPU Ambient"))
+               name = "gpu-temp";
+       else
+               goto fail;
+
        max->sens.ops = &wf_max6690_ops;
        max->sens.name = name;
        max->i2c.addr = addr >> 1;
@@ -118,7 +127,6 @@ static int wf_max6690_attach(struct i2c_adapter *adapter)
        struct device_node *busnode, *dev = NULL;
        struct pmac_i2c_bus *bus;
        const char *loc;
-       u32 *reg;
 
        bus = pmac_i2c_adapter_to_bus(adapter);
        if (bus == NULL)
@@ -126,16 +134,21 @@ static int wf_max6690_attach(struct i2c_adapter *adapter)
        busnode = pmac_i2c_get_bus_node(bus);
 
        while ((dev = of_get_next_child(busnode, dev)) != NULL) {
-               if (!device_is_compatible(dev, "max6690"))
+               u8 addr;
+
+               /* We must re-match the adapter in order to properly check
+                * the channel on multibus setups
+                */
+               if (!pmac_i2c_match_adapter(dev, adapter))
                        continue;
-               loc = get_property(dev, "hwsensor-location", NULL);
-               reg = (u32 *) get_property(dev, "reg", NULL);
-               if (!loc || !reg)
+               if (!of_device_is_compatible(dev, "max6690"))
                        continue;
-               printk("found max6690, loc=%s reg=%x\n", loc, *reg);
-               if (strcmp(loc, "BACKSIDE"))
+               addr = pmac_i2c_get_dev_addr(dev);
+               loc = of_get_property(dev, "hwsensor-location", NULL);
+               if (loc == NULL || addr == 0)
                        continue;
-               wf_max6690_create(adapter, *reg);
+               printk("found max6690, loc=%s addr=0x%02x\n", loc, addr);
+               wf_max6690_create(adapter, addr, loc);
        }
 
        return 0;
@@ -153,6 +166,11 @@ static int wf_max6690_detach(struct i2c_client *client)
 
 static int __init wf_max6690_sensor_init(void)
 {
+       /* Don't register on old machines that use therm_pm72 for now */
+       if (machine_is_compatible("PowerMac7,2") ||
+           machine_is_compatible("PowerMac7,3") ||
+           machine_is_compatible("RackMac3,1"))
+               return -ENODEV;
        return i2c_add_driver(&wf_max6690_driver);
 }