[PATCH] powerpc: Fix old g5 issues with windfarm

Some of the windfarm sensor modules can initialize on old machines that
don't have full windfarm support like non-dual core desktop G5s.
Unfortunately, by doing so, they would trigger a bug in their matching
algorithm causing them to attach to the wrong bus, thus triggering
issues with the i2c core and breaking the thermal driver.

This patch fixes the probing issue (so that they will work when a
windfarm port is done to these machines) and also prevents for now
windfarm to load at all on these machines that still use therm_pm72 to
avoid wasting resources.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by Benjamin Herrenschmidt and committed by Paul Mackerras b55fafc5 0c2aca88

+57 -17
+7
drivers/macintosh/windfarm_core.c
··· 35 35 #include <linux/platform_device.h> 36 36 #include <linux/mutex.h> 37 37 38 + #include <asm/prom.h> 39 + 38 40 #include "windfarm.h" 39 41 40 42 #define VERSION "0.2" ··· 467 465 { 468 466 DBG("wf: core loaded\n"); 469 467 468 + /* Don't register on old machines that use therm_pm72 for now */ 469 + if (machine_is_compatible("PowerMac7,2") || 470 + machine_is_compatible("PowerMac7,3") || 471 + machine_is_compatible("RackMac3,1")) 472 + return -ENODEV; 470 473 platform_device_register(&wf_platform_device); 471 474 return 0; 472 475 }
+8
drivers/macintosh/windfarm_cpufreq_clamp.c
··· 8 8 #include <linux/wait.h> 9 9 #include <linux/cpufreq.h> 10 10 11 + #include <asm/prom.h> 12 + 11 13 #include "windfarm.h" 12 14 13 15 #define VERSION "0.3" ··· 75 73 static int __init wf_cpufreq_clamp_init(void) 76 74 { 77 75 struct wf_control *clamp; 76 + 77 + /* Don't register on old machines that use therm_pm72 for now */ 78 + if (machine_is_compatible("PowerMac7,2") || 79 + machine_is_compatible("PowerMac7,3") || 80 + machine_is_compatible("RackMac3,1")) 81 + return -ENODEV; 78 82 79 83 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL); 80 84 if (clamp == NULL)
+23 -9
drivers/macintosh/windfarm_lm75_sensor.c
··· 25 25 26 26 #include "windfarm.h" 27 27 28 - #define VERSION "0.1" 28 + #define VERSION "0.2" 29 29 30 30 #undef DEBUG 31 31 ··· 113 113 const char *loc) 114 114 { 115 115 struct wf_lm75_sensor *lm; 116 + int rc; 116 117 117 118 DBG("wf_lm75: creating %s device at address 0x%02x\n", 118 119 ds1775 ? "ds1775" : "lm75", addr); ··· 140 139 lm->i2c.driver = &wf_lm75_driver; 141 140 strncpy(lm->i2c.name, lm->sens.name, I2C_NAME_SIZE-1); 142 141 143 - if (i2c_attach_client(&lm->i2c)) { 144 - printk(KERN_ERR "windfarm: failed to attach %s %s to i2c\n", 145 - ds1775 ? "ds1775" : "lm75", lm->i2c.name); 142 + rc = i2c_attach_client(&lm->i2c); 143 + if (rc) { 144 + printk(KERN_ERR "windfarm: failed to attach %s %s to i2c," 145 + " err %d\n", ds1775 ? "ds1775" : "lm75", 146 + lm->i2c.name, rc); 146 147 goto fail; 147 148 } 148 149 ··· 178 175 (dev = of_get_next_child(busnode, dev)) != NULL;) { 179 176 const char *loc = 180 177 get_property(dev, "hwsensor-location", NULL); 181 - u32 *reg = (u32 *)get_property(dev, "reg", NULL); 182 - DBG(" dev: %s... (loc: %p, reg: %p)\n", dev->name, loc, reg); 183 - if (loc == NULL || reg == NULL) 178 + u8 addr; 179 + 180 + /* We must re-match the adapter in order to properly check 181 + * the channel on multibus setups 182 + */ 183 + if (!pmac_i2c_match_adapter(dev, adapter)) 184 + continue; 185 + addr = pmac_i2c_get_dev_addr(dev); 186 + if (loc == NULL || addr == 0) 184 187 continue; 185 188 /* real lm75 */ 186 189 if (device_is_compatible(dev, "lm75")) 187 - wf_lm75_create(adapter, *reg, 0, loc); 190 + wf_lm75_create(adapter, addr, 0, loc); 188 191 /* ds1775 (compatible, better resolution */ 189 192 else if (device_is_compatible(dev, "ds1775")) 190 - wf_lm75_create(adapter, *reg, 1, loc); 193 + wf_lm75_create(adapter, addr, 1, loc); 191 194 } 192 195 return 0; 193 196 } ··· 215 206 216 207 static int __init wf_lm75_sensor_init(void) 217 208 { 209 + /* Don't register on old machines that use therm_pm72 for now */ 210 + if (machine_is_compatible("PowerMac7,2") || 211 + machine_is_compatible("PowerMac7,3") || 212 + machine_is_compatible("RackMac3,1")) 213 + return -ENODEV; 218 214 return i2c_add_driver(&wf_lm75_driver); 219 215 } 220 216
+18 -7
drivers/macintosh/windfarm_max6690_sensor.c
··· 17 17 18 18 #include "windfarm.h" 19 19 20 - #define VERSION "0.1" 20 + #define VERSION "0.2" 21 21 22 22 /* This currently only exports the external temperature sensor, 23 23 since that's all the control loops need. */ ··· 81 81 static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr) 82 82 { 83 83 struct wf_6690_sensor *max; 84 - char *name = "u4-temp"; 84 + char *name = "backside-temp"; 85 85 86 86 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL); 87 87 if (max == NULL) { ··· 118 118 struct device_node *busnode, *dev = NULL; 119 119 struct pmac_i2c_bus *bus; 120 120 const char *loc; 121 - u32 *reg; 122 121 123 122 bus = pmac_i2c_adapter_to_bus(adapter); 124 123 if (bus == NULL) ··· 125 126 busnode = pmac_i2c_get_bus_node(bus); 126 127 127 128 while ((dev = of_get_next_child(busnode, dev)) != NULL) { 129 + u8 addr; 130 + 131 + /* We must re-match the adapter in order to properly check 132 + * the channel on multibus setups 133 + */ 134 + if (!pmac_i2c_match_adapter(dev, adapter)) 135 + continue; 128 136 if (!device_is_compatible(dev, "max6690")) 129 137 continue; 138 + addr = pmac_i2c_get_dev_addr(dev); 130 139 loc = get_property(dev, "hwsensor-location", NULL); 131 - reg = (u32 *) get_property(dev, "reg", NULL); 132 - if (!loc || !reg) 140 + if (loc == NULL || addr == 0) 133 141 continue; 134 - printk("found max6690, loc=%s reg=%x\n", loc, *reg); 142 + printk("found max6690, loc=%s addr=0x%02x\n", loc, addr); 135 143 if (strcmp(loc, "BACKSIDE")) 136 144 continue; 137 - wf_max6690_create(adapter, *reg); 145 + wf_max6690_create(adapter, addr); 138 146 } 139 147 140 148 return 0; ··· 159 153 160 154 static int __init wf_max6690_sensor_init(void) 161 155 { 156 + /* Don't register on old machines that use therm_pm72 for now */ 157 + if (machine_is_compatible("PowerMac7,2") || 158 + machine_is_compatible("PowerMac7,3") || 159 + machine_is_compatible("RackMac3,1")) 160 + return -ENODEV; 162 161 return i2c_add_driver(&wf_max6690_driver); 163 162 } 164 163
+1 -1
drivers/macintosh/windfarm_pm112.c
··· 613 613 } else if (!strcmp(sr->name, "slots-power")) { 614 614 if (slots_power == NULL && wf_get_sensor(sr) == 0) 615 615 slots_power = sr; 616 - } else if (!strcmp(sr->name, "u4-temp")) { 616 + } else if (!strcmp(sr->name, "backside-temp")) { 617 617 if (u4_temp == NULL && wf_get_sensor(sr) == 0) 618 618 u4_temp = sr; 619 619 } else