Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Windfarm PowerMac thermal control. SMU "satellite" controller sensors. |
| 3 | * |
| 4 | * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org> |
| 5 | * |
| 6 | * Released under the terms of the GNU GPL v2. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/i2c.h> |
Daniel Walker | 56783c5 | 2008-05-03 06:34:02 +1000 | [diff] [blame] | 16 | #include <linux/mutex.h> |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 17 | #include <asm/prom.h> |
| 18 | #include <asm/smu.h> |
| 19 | #include <asm/pmac_low_i2c.h> |
| 20 | |
| 21 | #include "windfarm.h" |
| 22 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 23 | #define VERSION "1.0" |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 24 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 25 | /* If the cache is older than 800ms we'll refetch it */ |
| 26 | #define MAX_AGE msecs_to_jiffies(800) |
| 27 | |
| 28 | struct wf_sat { |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 29 | struct kref ref; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 30 | int nr; |
Daniel Walker | 56783c5 | 2008-05-03 06:34:02 +1000 | [diff] [blame] | 31 | struct mutex mutex; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 32 | unsigned long last_read; /* jiffies when cache last updated */ |
| 33 | u8 cache[16]; |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 34 | struct list_head sensors; |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 35 | struct i2c_client *i2c; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 36 | struct device_node *node; |
| 37 | }; |
| 38 | |
| 39 | static struct wf_sat *sats[2]; |
| 40 | |
| 41 | struct wf_sat_sensor { |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 42 | struct list_head link; |
| 43 | int index; |
| 44 | int index2; /* used for power sensors */ |
| 45 | int shift; |
| 46 | struct wf_sat *sat; |
| 47 | struct wf_sensor sens; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | #define wf_to_sat(c) container_of(c, struct wf_sat_sensor, sens) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 51 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 52 | struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id, |
| 53 | unsigned int *size) |
| 54 | { |
| 55 | struct wf_sat *sat; |
| 56 | int err; |
| 57 | unsigned int i, len; |
| 58 | u8 *buf; |
| 59 | u8 data[4]; |
| 60 | |
| 61 | /* TODO: Add the resulting partition to the device-tree */ |
| 62 | |
| 63 | if (sat_id > 1 || (sat = sats[sat_id]) == NULL) |
| 64 | return NULL; |
| 65 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 66 | err = i2c_smbus_write_word_data(sat->i2c, 8, id << 8); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 67 | if (err) { |
| 68 | printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err); |
| 69 | return NULL; |
| 70 | } |
| 71 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 72 | err = i2c_smbus_read_word_data(sat->i2c, 9); |
roel kluin | 2fd091f | 2008-11-29 01:17:27 +0000 | [diff] [blame] | 73 | if (err < 0) { |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 74 | printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n"); |
| 75 | return NULL; |
| 76 | } |
roel kluin | 2fd091f | 2008-11-29 01:17:27 +0000 | [diff] [blame] | 77 | len = err; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 78 | if (len == 0) { |
| 79 | printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id); |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | len = le16_to_cpu(len); |
| 84 | len = (len + 3) & ~3; |
| 85 | buf = kmalloc(len, GFP_KERNEL); |
| 86 | if (buf == NULL) |
| 87 | return NULL; |
| 88 | |
| 89 | for (i = 0; i < len; i += 4) { |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 90 | err = i2c_smbus_read_i2c_block_data(sat->i2c, 0xa, 4, data); |
Jean Delvare | 4b2643d | 2007-07-12 14:12:29 +0200 | [diff] [blame] | 91 | if (err < 0) { |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 92 | printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n", |
| 93 | err); |
| 94 | goto fail; |
| 95 | } |
| 96 | buf[i] = data[1]; |
| 97 | buf[i+1] = data[0]; |
| 98 | buf[i+2] = data[3]; |
| 99 | buf[i+3] = data[2]; |
| 100 | } |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 101 | |
Benjamin Herrenschmidt | fc0c8b3 | 2018-10-15 11:18:49 +1100 | [diff] [blame] | 102 | printk(KERN_DEBUG "sat %d partition %x:", sat_id, id); |
| 103 | print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, |
| 104 | 16, 1, buf, len, false); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 105 | if (size) |
| 106 | *size = len; |
| 107 | return (struct smu_sdbp_header *) buf; |
| 108 | |
| 109 | fail: |
| 110 | kfree(buf); |
| 111 | return NULL; |
| 112 | } |
Johannes Berg | 9127dd1 | 2006-02-17 13:52:54 -0800 | [diff] [blame] | 113 | EXPORT_SYMBOL_GPL(smu_sat_get_sdb_partition); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 114 | |
| 115 | /* refresh the cache */ |
| 116 | static int wf_sat_read_cache(struct wf_sat *sat) |
| 117 | { |
| 118 | int err; |
| 119 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 120 | err = i2c_smbus_read_i2c_block_data(sat->i2c, 0x3f, 16, sat->cache); |
Jean Delvare | 4b2643d | 2007-07-12 14:12:29 +0200 | [diff] [blame] | 121 | if (err < 0) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 122 | return err; |
| 123 | sat->last_read = jiffies; |
Benjamin Herrenschmidt | fc0c8b3 | 2018-10-15 11:18:49 +1100 | [diff] [blame] | 124 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 125 | #ifdef LOTSA_DEBUG |
| 126 | { |
| 127 | int i; |
Benjamin Herrenschmidt | fc0c8b3 | 2018-10-15 11:18:49 +1100 | [diff] [blame] | 128 | printk(KERN_DEBUG "wf_sat_get: data is"); |
| 129 | print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, |
| 130 | 16, 1, sat->cache, 16, false); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 131 | } |
| 132 | #endif |
| 133 | return 0; |
| 134 | } |
| 135 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 136 | static int wf_sat_sensor_get(struct wf_sensor *sr, s32 *value) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 137 | { |
| 138 | struct wf_sat_sensor *sens = wf_to_sat(sr); |
| 139 | struct wf_sat *sat = sens->sat; |
| 140 | int i, err; |
| 141 | s32 val; |
| 142 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 143 | if (sat->i2c == NULL) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 144 | return -ENODEV; |
| 145 | |
Daniel Walker | 56783c5 | 2008-05-03 06:34:02 +1000 | [diff] [blame] | 146 | mutex_lock(&sat->mutex); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 147 | if (time_after(jiffies, (sat->last_read + MAX_AGE))) { |
| 148 | err = wf_sat_read_cache(sat); |
| 149 | if (err) |
| 150 | goto fail; |
| 151 | } |
| 152 | |
| 153 | i = sens->index * 2; |
| 154 | val = ((sat->cache[i] << 8) + sat->cache[i+1]) << sens->shift; |
| 155 | if (sens->index2 >= 0) { |
| 156 | i = sens->index2 * 2; |
| 157 | /* 4.12 * 8.8 -> 12.20; shift right 4 to get 16.16 */ |
| 158 | val = (val * ((sat->cache[i] << 8) + sat->cache[i+1])) >> 4; |
| 159 | } |
| 160 | |
| 161 | *value = val; |
| 162 | err = 0; |
| 163 | |
| 164 | fail: |
Daniel Walker | 56783c5 | 2008-05-03 06:34:02 +1000 | [diff] [blame] | 165 | mutex_unlock(&sat->mutex); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 166 | return err; |
| 167 | } |
| 168 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 169 | static void wf_sat_release(struct kref *ref) |
| 170 | { |
| 171 | struct wf_sat *sat = container_of(ref, struct wf_sat, ref); |
| 172 | |
| 173 | if (sat->nr >= 0) |
| 174 | sats[sat->nr] = NULL; |
| 175 | kfree(sat); |
| 176 | } |
| 177 | |
| 178 | static void wf_sat_sensor_release(struct wf_sensor *sr) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 179 | { |
| 180 | struct wf_sat_sensor *sens = wf_to_sat(sr); |
| 181 | struct wf_sat *sat = sens->sat; |
| 182 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 183 | kfree(sens); |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 184 | kref_put(&sat->ref, wf_sat_release); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 185 | } |
| 186 | |
Julia Lawall | de854e5 | 2017-08-02 23:01:45 +0200 | [diff] [blame] | 187 | static const struct wf_sensor_ops wf_sat_ops = { |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 188 | .get_value = wf_sat_sensor_get, |
| 189 | .release = wf_sat_sensor_release, |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 190 | .owner = THIS_MODULE, |
| 191 | }; |
| 192 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 193 | static int wf_sat_probe(struct i2c_client *client, |
| 194 | const struct i2c_device_id *id) |
| 195 | { |
Benjamin Herrenschmidt | 9525a08 | 2012-05-08 13:28:37 +1000 | [diff] [blame] | 196 | struct device_node *dev = client->dev.of_node; |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 197 | struct wf_sat *sat; |
| 198 | struct wf_sat_sensor *sens; |
| 199 | const u32 *reg; |
Rob Herring | bf82d37 | 2018-11-16 16:11:01 -0600 | [diff] [blame] | 200 | const char *loc; |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 201 | u8 chip, core; |
| 202 | struct device_node *child; |
| 203 | int shift, cpu, index; |
| 204 | char *name; |
| 205 | int vsens[2], isens[2]; |
| 206 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 207 | sat = kzalloc(sizeof(struct wf_sat), GFP_KERNEL); |
| 208 | if (sat == NULL) |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 209 | return -ENOMEM; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 210 | sat->nr = -1; |
| 211 | sat->node = of_node_get(dev); |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 212 | kref_init(&sat->ref); |
Daniel Walker | 56783c5 | 2008-05-03 06:34:02 +1000 | [diff] [blame] | 213 | mutex_init(&sat->mutex); |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 214 | sat->i2c = client; |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 215 | INIT_LIST_HEAD(&sat->sensors); |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 216 | i2c_set_clientdata(client, sat); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 217 | |
| 218 | vsens[0] = vsens[1] = -1; |
| 219 | isens[0] = isens[1] = -1; |
| 220 | child = NULL; |
| 221 | while ((child = of_get_next_child(dev, child)) != NULL) { |
Stephen Rothwell | 01b2726 | 2007-04-27 13:41:15 +1000 | [diff] [blame] | 222 | reg = of_get_property(child, "reg", NULL); |
Stephen Rothwell | 01b2726 | 2007-04-27 13:41:15 +1000 | [diff] [blame] | 223 | loc = of_get_property(child, "location", NULL); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 224 | if (reg == NULL || loc == NULL) |
| 225 | continue; |
| 226 | |
| 227 | /* the cooked sensors are between 0x30 and 0x37 */ |
| 228 | if (*reg < 0x30 || *reg > 0x37) |
| 229 | continue; |
| 230 | index = *reg - 0x30; |
| 231 | |
| 232 | /* expect location to be CPU [AB][01] ... */ |
| 233 | if (strncmp(loc, "CPU ", 4) != 0) |
| 234 | continue; |
| 235 | chip = loc[4] - 'A'; |
| 236 | core = loc[5] - '0'; |
| 237 | if (chip > 1 || core > 1) { |
| 238 | printk(KERN_ERR "wf_sat_create: don't understand " |
Rob Herring | b6a945a | 2017-07-18 16:43:12 -0500 | [diff] [blame] | 239 | "location %s for %pOF\n", loc, child); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 240 | continue; |
| 241 | } |
| 242 | cpu = 2 * chip + core; |
| 243 | if (sat->nr < 0) |
| 244 | sat->nr = chip; |
| 245 | else if (sat->nr != chip) { |
| 246 | printk(KERN_ERR "wf_sat_create: can't cope with " |
| 247 | "multiple CPU chips on one SAT (%s)\n", loc); |
| 248 | continue; |
| 249 | } |
| 250 | |
Rob Herring | bf82d37 | 2018-11-16 16:11:01 -0600 | [diff] [blame] | 251 | if (of_node_is_type(child, "voltage-sensor")) { |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 252 | name = "cpu-voltage"; |
| 253 | shift = 4; |
| 254 | vsens[core] = index; |
Rob Herring | bf82d37 | 2018-11-16 16:11:01 -0600 | [diff] [blame] | 255 | } else if (of_node_is_type(child, "current-sensor")) { |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 256 | name = "cpu-current"; |
| 257 | shift = 8; |
| 258 | isens[core] = index; |
Rob Herring | bf82d37 | 2018-11-16 16:11:01 -0600 | [diff] [blame] | 259 | } else if (of_node_is_type(child, "temp-sensor")) { |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 260 | name = "cpu-temp"; |
| 261 | shift = 10; |
| 262 | } else |
| 263 | continue; /* hmmm shouldn't happen */ |
| 264 | |
| 265 | /* the +16 is enough for "cpu-voltage-n" */ |
| 266 | sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL); |
| 267 | if (sens == NULL) { |
| 268 | printk(KERN_ERR "wf_sat_create: couldn't create " |
| 269 | "%s sensor %d (no memory)\n", name, cpu); |
| 270 | continue; |
| 271 | } |
| 272 | sens->index = index; |
| 273 | sens->index2 = -1; |
| 274 | sens->shift = shift; |
| 275 | sens->sat = sat; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 276 | sens->sens.ops = &wf_sat_ops; |
| 277 | sens->sens.name = (char *) (sens + 1); |
Stephen Rothwell | 43671cc | 2012-05-02 20:19:43 +0000 | [diff] [blame] | 278 | snprintf((char *)sens->sens.name, 16, "%s-%d", name, cpu); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 279 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 280 | if (wf_register_sensor(&sens->sens)) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 281 | kfree(sens); |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 282 | else { |
| 283 | list_add(&sens->link, &sat->sensors); |
| 284 | kref_get(&sat->ref); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | /* make the power sensors */ |
| 289 | for (core = 0; core < 2; ++core) { |
| 290 | if (vsens[core] < 0 || isens[core] < 0) |
| 291 | continue; |
| 292 | cpu = 2 * sat->nr + core; |
| 293 | sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL); |
| 294 | if (sens == NULL) { |
| 295 | printk(KERN_ERR "wf_sat_create: couldn't create power " |
| 296 | "sensor %d (no memory)\n", cpu); |
| 297 | continue; |
| 298 | } |
| 299 | sens->index = vsens[core]; |
| 300 | sens->index2 = isens[core]; |
| 301 | sens->shift = 0; |
| 302 | sens->sat = sat; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 303 | sens->sens.ops = &wf_sat_ops; |
| 304 | sens->sens.name = (char *) (sens + 1); |
Stephen Rothwell | 43671cc | 2012-05-02 20:19:43 +0000 | [diff] [blame] | 305 | snprintf((char *)sens->sens.name, 16, "cpu-power-%d", cpu); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 306 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 307 | if (wf_register_sensor(&sens->sens)) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 308 | kfree(sens); |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 309 | else { |
| 310 | list_add(&sens->link, &sat->sensors); |
| 311 | kref_get(&sat->ref); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | if (sat->nr >= 0) |
| 316 | sats[sat->nr] = sat; |
| 317 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 318 | return 0; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 319 | } |
| 320 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 321 | static int wf_sat_remove(struct i2c_client *client) |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 322 | { |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 323 | struct wf_sat *sat = i2c_get_clientdata(client); |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 324 | struct wf_sat_sensor *sens; |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 325 | |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 326 | /* release sensors */ |
| 327 | while(!list_empty(&sat->sensors)) { |
| 328 | sens = list_first_entry(&sat->sensors, |
| 329 | struct wf_sat_sensor, link); |
| 330 | list_del(&sens->link); |
| 331 | wf_unregister_sensor(&sens->sens); |
| 332 | } |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 333 | sat->i2c = NULL; |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 334 | kref_put(&sat->ref, wf_sat_release); |
| 335 | |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 336 | return 0; |
| 337 | } |
| 338 | |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 339 | static const struct i2c_device_id wf_sat_id[] = { |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 340 | { "MAC,smu-sat", 0 }, |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 341 | { } |
| 342 | }; |
Benjamin Herrenschmidt | e326b30 | 2012-04-18 22:16:46 +0000 | [diff] [blame] | 343 | MODULE_DEVICE_TABLE(i2c, wf_sat_id); |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 344 | |
| 345 | static struct i2c_driver wf_sat_driver = { |
| 346 | .driver = { |
| 347 | .name = "wf_smu_sat", |
| 348 | }, |
Jean Delvare | 351ca3e | 2009-06-15 18:01:51 +0200 | [diff] [blame] | 349 | .probe = wf_sat_probe, |
| 350 | .remove = wf_sat_remove, |
| 351 | .id_table = wf_sat_id, |
| 352 | }; |
| 353 | |
Wei Yongjun | f7fb862 | 2012-10-08 03:00:04 +0000 | [diff] [blame] | 354 | module_i2c_driver(wf_sat_driver); |
Benjamin Herrenschmidt | ac171c4 | 2006-02-08 16:42:51 +1100 | [diff] [blame] | 355 | |
| 356 | MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>"); |
| 357 | MODULE_DESCRIPTION("SMU satellite sensors for PowerMac thermal control"); |
| 358 | MODULE_LICENSE("GPL"); |