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