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