X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=drivers%2Fmacintosh%2Fwindfarm_lm75_sensor.c;h=ab4d1b63f63e673c70f3321a837cc4f029a380c4;hb=94dfbdb3894eda2f673b70e20da2743c4a8d3968;hp=57460e46c89f2152d9df180b020a7379bf2c7f25;hpb=ed03f430cdc8c802652467e9097606fedc2c7abc;p=powerpc.git diff --git a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c index 57460e46c8..ab4d1b63f6 100644 --- a/drivers/macintosh/windfarm_lm75_sensor.c +++ b/drivers/macintosh/windfarm_lm75_sensor.c @@ -15,16 +15,16 @@ #include #include #include -#include #include #include #include #include #include +#include #include "windfarm.h" -#define VERSION "0.1" +#define VERSION "0.2" #undef DEBUG @@ -112,6 +112,7 @@ static struct wf_lm75_sensor *wf_lm75_create(struct i2c_adapter *adapter, const char *loc) { struct wf_lm75_sensor *lm; + int rc; DBG("wf_lm75: creating %s device at address 0x%02x\n", ds1775 ? "ds1775" : "lm75", addr); @@ -138,9 +139,11 @@ static struct wf_lm75_sensor *wf_lm75_create(struct i2c_adapter *adapter, lm->i2c.driver = &wf_lm75_driver; strncpy(lm->i2c.name, lm->sens.name, I2C_NAME_SIZE-1); - if (i2c_attach_client(&lm->i2c)) { - printk(KERN_ERR "windfarm: failed to attach %s %s to i2c\n", - ds1775 ? "ds1775" : "lm75", lm->i2c.name); + rc = i2c_attach_client(&lm->i2c); + if (rc) { + printk(KERN_ERR "windfarm: failed to attach %s %s to i2c," + " err %d\n", ds1775 ? "ds1775" : "lm75", + lm->i2c.name, rc); goto fail; } @@ -157,69 +160,40 @@ static struct wf_lm75_sensor *wf_lm75_create(struct i2c_adapter *adapter, static int wf_lm75_attach(struct i2c_adapter *adapter) { - u8 bus_id; - struct device_node *smu, *bus, *dev; - - /* We currently only deal with LM75's hanging off the SMU - * i2c busses. If we extend that driver to other/older - * machines, we should split this function into SMU-i2c, - * keywest-i2c, PMU-i2c, ... - */ + struct device_node *busnode, *dev; + struct pmac_i2c_bus *bus; DBG("wf_lm75: adapter %s detected\n", adapter->name); - if (strncmp(adapter->name, "smu-i2c-", 8) != 0) - return 0; - smu = of_find_node_by_type(NULL, "smu"); - if (smu == NULL) - return 0; - - /* Look for the bus in the device-tree */ - bus_id = (u8)simple_strtoul(adapter->name + 8, NULL, 16); - - DBG("wf_lm75: bus ID is %x\n", bus_id); - - /* Look for sensors subdir */ - for (bus = NULL; - (bus = of_get_next_child(smu, bus)) != NULL;) { - u32 *reg; - - if (strcmp(bus->name, "i2c")) - continue; - reg = (u32 *)get_property(bus, "reg", NULL); - if (reg == NULL) - continue; - if (bus_id == *reg) - break; - } - of_node_put(smu); - if (bus == NULL) { - printk(KERN_WARNING "windfarm: SMU i2c bus 0x%x not found" - " in device-tree !\n", bus_id); - return 0; - } + bus = pmac_i2c_adapter_to_bus(adapter); + if (bus == NULL) + return -ENODEV; + busnode = pmac_i2c_get_bus_node(bus); DBG("wf_lm75: bus found, looking for device...\n"); /* Now look for lm75(s) in there */ for (dev = NULL; - (dev = of_get_next_child(bus, dev)) != NULL;) { + (dev = of_get_next_child(busnode, dev)) != NULL;) { const char *loc = - get_property(dev, "hwsensor-location", NULL); - u32 *reg = (u32 *)get_property(dev, "reg", NULL); - DBG(" dev: %s... (loc: %p, reg: %p)\n", dev->name, loc, reg); - if (loc == NULL || reg == NULL) + of_get_property(dev, "hwsensor-location", NULL); + 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; + addr = pmac_i2c_get_dev_addr(dev); + if (loc == NULL || addr == 0) continue; /* real lm75 */ if (device_is_compatible(dev, "lm75")) - wf_lm75_create(adapter, *reg, 0, loc); + wf_lm75_create(adapter, addr, 0, loc); /* ds1775 (compatible, better resolution */ else if (device_is_compatible(dev, "ds1775")) - wf_lm75_create(adapter, *reg, 1, loc); + wf_lm75_create(adapter, addr, 1, loc); } - - of_node_put(bus); - return 0; } @@ -240,6 +214,11 @@ static int wf_lm75_detach(struct i2c_client *client) static int __init wf_lm75_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_lm75_driver); }