Linux Audio

Check our new training course

Loading...
v3.1
 
  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>
 16#include <linux/mutex.h>
 17#include <asm/prom.h>
 18#include <asm/smu.h>
 19#include <asm/pmac_low_i2c.h>
 20
 21#include "windfarm.h"
 22
 23#define VERSION "0.2"
 24
 25#define DEBUG
 26
 27#ifdef DEBUG
 28#define DBG(args...)	printk(args)
 29#else
 30#define DBG(args...)	do { } while(0)
 31#endif
 32
 33/* If the cache is older than 800ms we'll refetch it */
 34#define MAX_AGE		msecs_to_jiffies(800)
 35
 36struct wf_sat {
 
 37	int			nr;
 38	atomic_t		refcnt;
 39	struct mutex		mutex;
 40	unsigned long		last_read; /* jiffies when cache last updated */
 41	u8			cache[16];
 
 42	struct i2c_client	*i2c;
 43	struct device_node	*node;
 44};
 45
 46static struct wf_sat *sats[2];
 47
 48struct wf_sat_sensor {
 49	int		index;
 50	int		index2;		/* used for power sensors */
 51	int		shift;
 52	struct wf_sat	*sat;
 53	struct wf_sensor sens;
 
 54};
 55
 56#define wf_to_sat(c)	container_of(c, struct wf_sat_sensor, sens)
 57
 58struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
 59						  unsigned int *size)
 60{
 61	struct wf_sat *sat;
 62	int err;
 63	unsigned int i, len;
 64	u8 *buf;
 65	u8 data[4];
 66
 67	/* TODO: Add the resulting partition to the device-tree */
 68
 69	if (sat_id > 1 || (sat = sats[sat_id]) == NULL)
 70		return NULL;
 71
 72	err = i2c_smbus_write_word_data(sat->i2c, 8, id << 8);
 73	if (err) {
 74		printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err);
 75		return NULL;
 76	}
 77
 78	err = i2c_smbus_read_word_data(sat->i2c, 9);
 79	if (err < 0) {
 80		printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n");
 81		return NULL;
 82	}
 83	len = err;
 84	if (len == 0) {
 85		printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id);
 86		return NULL;
 87	}
 88
 89	len = le16_to_cpu(len);
 90	len = (len + 3) & ~3;
 91	buf = kmalloc(len, GFP_KERNEL);
 92	if (buf == NULL)
 93		return NULL;
 94
 95	for (i = 0; i < len; i += 4) {
 96		err = i2c_smbus_read_i2c_block_data(sat->i2c, 0xa, 4, data);
 97		if (err < 0) {
 98			printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n",
 99			       err);
100			goto fail;
101		}
102		buf[i] = data[1];
103		buf[i+1] = data[0];
104		buf[i+2] = data[3];
105		buf[i+3] = data[2];
106	}
107#ifdef DEBUG
108	DBG(KERN_DEBUG "sat %d partition %x:", sat_id, id);
109	for (i = 0; i < len; ++i)
110		DBG(" %x", buf[i]);
111	DBG("\n");
112#endif
113
 
 
 
114	if (size)
115		*size = len;
116	return (struct smu_sdbp_header *) buf;
117
118 fail:
119	kfree(buf);
120	return NULL;
121}
122EXPORT_SYMBOL_GPL(smu_sat_get_sdb_partition);
123
124/* refresh the cache */
125static int wf_sat_read_cache(struct wf_sat *sat)
126{
127	int err;
128
129	err = i2c_smbus_read_i2c_block_data(sat->i2c, 0x3f, 16, sat->cache);
130	if (err < 0)
131		return err;
132	sat->last_read = jiffies;
 
133#ifdef LOTSA_DEBUG
134	{
135		int i;
136		DBG(KERN_DEBUG "wf_sat_get: data is");
137		for (i = 0; i < 16; ++i)
138			DBG(" %.2x", sat->cache[i]);
139		DBG("\n");
140	}
141#endif
142	return 0;
143}
144
145static int wf_sat_get(struct wf_sensor *sr, s32 *value)
146{
147	struct wf_sat_sensor *sens = wf_to_sat(sr);
148	struct wf_sat *sat = sens->sat;
149	int i, err;
150	s32 val;
151
152	if (sat->i2c == NULL)
153		return -ENODEV;
154
155	mutex_lock(&sat->mutex);
156	if (time_after(jiffies, (sat->last_read + MAX_AGE))) {
157		err = wf_sat_read_cache(sat);
158		if (err)
159			goto fail;
160	}
161
162	i = sens->index * 2;
163	val = ((sat->cache[i] << 8) + sat->cache[i+1]) << sens->shift;
164	if (sens->index2 >= 0) {
165		i = sens->index2 * 2;
166		/* 4.12 * 8.8 -> 12.20; shift right 4 to get 16.16 */
167		val = (val * ((sat->cache[i] << 8) + sat->cache[i+1])) >> 4;
168	}
169
170	*value = val;
171	err = 0;
172
173 fail:
174	mutex_unlock(&sat->mutex);
175	return err;
176}
177
178static void wf_sat_release(struct wf_sensor *sr)
 
 
 
 
 
 
 
 
 
179{
180	struct wf_sat_sensor *sens = wf_to_sat(sr);
181	struct wf_sat *sat = sens->sat;
182
183	if (atomic_dec_and_test(&sat->refcnt)) {
184		if (sat->nr >= 0)
185			sats[sat->nr] = NULL;
186		kfree(sat);
187	}
188	kfree(sens);
 
189}
190
191static struct wf_sensor_ops wf_sat_ops = {
192	.get_value	= wf_sat_get,
193	.release	= wf_sat_release,
194	.owner		= THIS_MODULE,
195};
196
197static struct i2c_driver wf_sat_driver;
198
199static void wf_sat_create(struct i2c_adapter *adapter, struct device_node *dev)
200{
201	struct i2c_board_info info;
202	struct i2c_client *client;
203	const u32 *reg;
204	u8 addr;
205
206	reg = of_get_property(dev, "reg", NULL);
207	if (reg == NULL)
208		return;
209	addr = *reg;
210	DBG(KERN_DEBUG "wf_sat: creating sat at address %x\n", addr);
211
212	memset(&info, 0, sizeof(struct i2c_board_info));
213	info.addr = (addr >> 1) & 0x7f;
214	info.platform_data = dev;
215	strlcpy(info.type, "wf_sat", I2C_NAME_SIZE);
216
217	client = i2c_new_device(adapter, &info);
218	if (client == NULL) {
219		printk(KERN_ERR "windfarm: failed to attach smu-sat to i2c\n");
220		return;
221	}
222
223	/*
224	 * Let i2c-core delete that device on driver removal.
225	 * This is safe because i2c-core holds the core_lock mutex for us.
226	 */
227	list_add_tail(&client->detected, &wf_sat_driver.clients);
228}
229
230static int wf_sat_probe(struct i2c_client *client,
231			const struct i2c_device_id *id)
232{
233	struct device_node *dev = client->dev.platform_data;
234	struct wf_sat *sat;
235	struct wf_sat_sensor *sens;
236	const u32 *reg;
237	const char *loc, *type;
238	u8 chip, core;
239	struct device_node *child;
240	int shift, cpu, index;
241	char *name;
242	int vsens[2], isens[2];
243
244	sat = kzalloc(sizeof(struct wf_sat), GFP_KERNEL);
245	if (sat == NULL)
246		return -ENOMEM;
247	sat->nr = -1;
248	sat->node = of_node_get(dev);
249	atomic_set(&sat->refcnt, 0);
250	mutex_init(&sat->mutex);
251	sat->i2c = client;
 
252	i2c_set_clientdata(client, sat);
253
254	vsens[0] = vsens[1] = -1;
255	isens[0] = isens[1] = -1;
256	child = NULL;
257	while ((child = of_get_next_child(dev, child)) != NULL) {
258		reg = of_get_property(child, "reg", NULL);
259		type = of_get_property(child, "device_type", NULL);
260		loc = of_get_property(child, "location", NULL);
261		if (reg == NULL || loc == NULL)
262			continue;
263
264		/* the cooked sensors are between 0x30 and 0x37 */
265		if (*reg < 0x30 || *reg > 0x37)
266			continue;
267		index = *reg - 0x30;
268
269		/* expect location to be CPU [AB][01] ... */
270		if (strncmp(loc, "CPU ", 4) != 0)
271			continue;
272		chip = loc[4] - 'A';
273		core = loc[5] - '0';
274		if (chip > 1 || core > 1) {
275			printk(KERN_ERR "wf_sat_create: don't understand "
276			       "location %s for %s\n", loc, child->full_name);
277			continue;
278		}
279		cpu = 2 * chip + core;
280		if (sat->nr < 0)
281			sat->nr = chip;
282		else if (sat->nr != chip) {
283			printk(KERN_ERR "wf_sat_create: can't cope with "
284			       "multiple CPU chips on one SAT (%s)\n", loc);
285			continue;
286		}
287
288		if (strcmp(type, "voltage-sensor") == 0) {
289			name = "cpu-voltage";
290			shift = 4;
291			vsens[core] = index;
292		} else if (strcmp(type, "current-sensor") == 0) {
293			name = "cpu-current";
294			shift = 8;
295			isens[core] = index;
296		} else if (strcmp(type, "temp-sensor") == 0) {
297			name = "cpu-temp";
298			shift = 10;
299		} else
300			continue;	/* hmmm shouldn't happen */
301
302		/* the +16 is enough for "cpu-voltage-n" */
303		sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
304		if (sens == NULL) {
305			printk(KERN_ERR "wf_sat_create: couldn't create "
306			       "%s sensor %d (no memory)\n", name, cpu);
307			continue;
308		}
309		sens->index = index;
310		sens->index2 = -1;
311		sens->shift = shift;
312		sens->sat = sat;
313		atomic_inc(&sat->refcnt);
314		sens->sens.ops = &wf_sat_ops;
315		sens->sens.name = (char *) (sens + 1);
316		snprintf(sens->sens.name, 16, "%s-%d", name, cpu);
317
318		if (wf_register_sensor(&sens->sens)) {
319			atomic_dec(&sat->refcnt);
320			kfree(sens);
 
 
 
321		}
322	}
323
324	/* make the power sensors */
325	for (core = 0; core < 2; ++core) {
326		if (vsens[core] < 0 || isens[core] < 0)
327			continue;
328		cpu = 2 * sat->nr + core;
329		sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
330		if (sens == NULL) {
331			printk(KERN_ERR "wf_sat_create: couldn't create power "
332			       "sensor %d (no memory)\n", cpu);
333			continue;
334		}
335		sens->index = vsens[core];
336		sens->index2 = isens[core];
337		sens->shift = 0;
338		sens->sat = sat;
339		atomic_inc(&sat->refcnt);
340		sens->sens.ops = &wf_sat_ops;
341		sens->sens.name = (char *) (sens + 1);
342		snprintf(sens->sens.name, 16, "cpu-power-%d", cpu);
343
344		if (wf_register_sensor(&sens->sens)) {
345			atomic_dec(&sat->refcnt);
346			kfree(sens);
 
 
 
347		}
348	}
349
350	if (sat->nr >= 0)
351		sats[sat->nr] = sat;
352
353	return 0;
354}
355
356static int wf_sat_attach(struct i2c_adapter *adapter)
357{
358	struct device_node *busnode, *dev = NULL;
359	struct pmac_i2c_bus *bus;
360
361	bus = pmac_i2c_adapter_to_bus(adapter);
362	if (bus == NULL)
363		return -ENODEV;
364	busnode = pmac_i2c_get_bus_node(bus);
365
366	while ((dev = of_get_next_child(busnode, dev)) != NULL)
367		if (of_device_is_compatible(dev, "smu-sat"))
368			wf_sat_create(adapter, dev);
369	return 0;
370}
371
372static int wf_sat_remove(struct i2c_client *client)
373{
374	struct wf_sat *sat = i2c_get_clientdata(client);
 
375
376	/* XXX TODO */
377
 
 
 
 
 
378	sat->i2c = NULL;
 
 
379	return 0;
380}
381
382static const struct i2c_device_id wf_sat_id[] = {
383	{ "wf_sat", 0 },
384	{ }
385};
 
386
387static struct i2c_driver wf_sat_driver = {
388	.driver = {
389		.name		= "wf_smu_sat",
390	},
391	.attach_adapter	= wf_sat_attach,
392	.probe		= wf_sat_probe,
393	.remove		= wf_sat_remove,
394	.id_table	= wf_sat_id,
395};
396
397static int __init sat_sensors_init(void)
398{
399	return i2c_add_driver(&wf_sat_driver);
400}
401
402#if 0	/* uncomment when module_exit() below is uncommented */
403static void __exit sat_sensors_exit(void)
404{
405	i2c_del_driver(&wf_sat_driver);
406}
407#endif
408
409module_init(sat_sensors_init);
410/*module_exit(sat_sensors_exit); Uncomment when cleanup is implemented */
411
412MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
413MODULE_DESCRIPTION("SMU satellite sensors for PowerMac thermal control");
414MODULE_LICENSE("GPL");
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Windfarm PowerMac thermal control.  SMU "satellite" controller sensors.
  4 *
  5 * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
 
 
  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>
 15#include <linux/mutex.h>
 16#include <asm/prom.h>
 17#include <asm/smu.h>
 18#include <asm/pmac_low_i2c.h>
 19
 20#include "windfarm.h"
 21
 22#define VERSION "1.0"
 
 
 
 
 
 
 
 
 23
 24/* If the cache is older than 800ms we'll refetch it */
 25#define MAX_AGE		msecs_to_jiffies(800)
 26
 27struct wf_sat {
 28	struct kref		ref;
 29	int			nr;
 
 30	struct mutex		mutex;
 31	unsigned long		last_read; /* jiffies when cache last updated */
 32	u8			cache[16];
 33	struct list_head	sensors;
 34	struct i2c_client	*i2c;
 35	struct device_node	*node;
 36};
 37
 38static struct wf_sat *sats[2];
 39
 40struct wf_sat_sensor {
 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;
 47};
 48
 49#define wf_to_sat(c)	container_of(c, struct wf_sat_sensor, sens)
 50
 51struct 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
 65	err = i2c_smbus_write_word_data(sat->i2c, 8, id << 8);
 66	if (err) {
 67		printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err);
 68		return NULL;
 69	}
 70
 71	err = i2c_smbus_read_word_data(sat->i2c, 9);
 72	if (err < 0) {
 73		printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n");
 74		return NULL;
 75	}
 76	len = err;
 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) {
 89		err = i2c_smbus_read_i2c_block_data(sat->i2c, 0xa, 4, data);
 90		if (err < 0) {
 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	}
 
 
 
 
 
 
100
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);
104	if (size)
105		*size = len;
106	return (struct smu_sdbp_header *) buf;
107
108 fail:
109	kfree(buf);
110	return NULL;
111}
112EXPORT_SYMBOL_GPL(smu_sat_get_sdb_partition);
113
114/* refresh the cache */
115static int wf_sat_read_cache(struct wf_sat *sat)
116{
117	int err;
118
119	err = i2c_smbus_read_i2c_block_data(sat->i2c, 0x3f, 16, sat->cache);
120	if (err < 0)
121		return err;
122	sat->last_read = jiffies;
123
124#ifdef LOTSA_DEBUG
125	{
126		int i;
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);
 
130	}
131#endif
132	return 0;
133}
134
135static int wf_sat_sensor_get(struct wf_sensor *sr, s32 *value)
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
142	if (sat->i2c == NULL)
143		return -ENODEV;
144
145	mutex_lock(&sat->mutex);
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:
164	mutex_unlock(&sat->mutex);
165	return err;
166}
167
168static 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
177static void wf_sat_sensor_release(struct wf_sensor *sr)
178{
179	struct wf_sat_sensor *sens = wf_to_sat(sr);
180	struct wf_sat *sat = sens->sat;
181
 
 
 
 
 
182	kfree(sens);
183	kref_put(&sat->ref, wf_sat_release);
184}
185
186static const struct wf_sensor_ops wf_sat_ops = {
187	.get_value	= wf_sat_sensor_get,
188	.release	= wf_sat_sensor_release,
189	.owner		= THIS_MODULE,
190};
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192static int wf_sat_probe(struct i2c_client *client,
193			const struct i2c_device_id *id)
194{
195	struct device_node *dev = client->dev.of_node;
196	struct wf_sat *sat;
197	struct wf_sat_sensor *sens;
198	const u32 *reg;
199	const char *loc;
200	u8 chip, core;
201	struct device_node *child;
202	int shift, cpu, index;
203	char *name;
204	int vsens[2], isens[2];
205
206	sat = kzalloc(sizeof(struct wf_sat), GFP_KERNEL);
207	if (sat == NULL)
208		return -ENOMEM;
209	sat->nr = -1;
210	sat->node = of_node_get(dev);
211	kref_init(&sat->ref);
212	mutex_init(&sat->mutex);
213	sat->i2c = client;
214	INIT_LIST_HEAD(&sat->sensors);
215	i2c_set_clientdata(client, sat);
216
217	vsens[0] = vsens[1] = -1;
218	isens[0] = isens[1] = -1;
219	child = NULL;
220	while ((child = of_get_next_child(dev, child)) != NULL) {
221		reg = of_get_property(child, "reg", NULL);
 
222		loc = of_get_property(child, "location", NULL);
223		if (reg == NULL || loc == NULL)
224			continue;
225
226		/* the cooked sensors are between 0x30 and 0x37 */
227		if (*reg < 0x30 || *reg > 0x37)
228			continue;
229		index = *reg - 0x30;
230
231		/* expect location to be CPU [AB][01] ... */
232		if (strncmp(loc, "CPU ", 4) != 0)
233			continue;
234		chip = loc[4] - 'A';
235		core = loc[5] - '0';
236		if (chip > 1 || core > 1) {
237			printk(KERN_ERR "wf_sat_create: don't understand "
238			       "location %s for %pOF\n", loc, child);
239			continue;
240		}
241		cpu = 2 * chip + core;
242		if (sat->nr < 0)
243			sat->nr = chip;
244		else if (sat->nr != chip) {
245			printk(KERN_ERR "wf_sat_create: can't cope with "
246			       "multiple CPU chips on one SAT (%s)\n", loc);
247			continue;
248		}
249
250		if (of_node_is_type(child, "voltage-sensor")) {
251			name = "cpu-voltage";
252			shift = 4;
253			vsens[core] = index;
254		} else if (of_node_is_type(child, "current-sensor")) {
255			name = "cpu-current";
256			shift = 8;
257			isens[core] = index;
258		} else if (of_node_is_type(child, "temp-sensor")) {
259			name = "cpu-temp";
260			shift = 10;
261		} else
262			continue;	/* hmmm shouldn't happen */
263
264		/* the +16 is enough for "cpu-voltage-n" */
265		sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
266		if (sens == NULL) {
267			printk(KERN_ERR "wf_sat_create: couldn't create "
268			       "%s sensor %d (no memory)\n", name, cpu);
269			continue;
270		}
271		sens->index = index;
272		sens->index2 = -1;
273		sens->shift = shift;
274		sens->sat = sat;
 
275		sens->sens.ops = &wf_sat_ops;
276		sens->sens.name = (char *) (sens + 1);
277		snprintf((char *)sens->sens.name, 16, "%s-%d", name, cpu);
278
279		if (wf_register_sensor(&sens->sens))
 
280			kfree(sens);
281		else {
282			list_add(&sens->link, &sat->sensors);
283			kref_get(&sat->ref);
284		}
285	}
286
287	/* make the power sensors */
288	for (core = 0; core < 2; ++core) {
289		if (vsens[core] < 0 || isens[core] < 0)
290			continue;
291		cpu = 2 * sat->nr + core;
292		sens = kzalloc(sizeof(struct wf_sat_sensor) + 16, GFP_KERNEL);
293		if (sens == NULL) {
294			printk(KERN_ERR "wf_sat_create: couldn't create power "
295			       "sensor %d (no memory)\n", cpu);
296			continue;
297		}
298		sens->index = vsens[core];
299		sens->index2 = isens[core];
300		sens->shift = 0;
301		sens->sat = sat;
 
302		sens->sens.ops = &wf_sat_ops;
303		sens->sens.name = (char *) (sens + 1);
304		snprintf((char *)sens->sens.name, 16, "cpu-power-%d", cpu);
305
306		if (wf_register_sensor(&sens->sens))
 
307			kfree(sens);
308		else {
309			list_add(&sens->link, &sat->sensors);
310			kref_get(&sat->ref);
311		}
312	}
313
314	if (sat->nr >= 0)
315		sats[sat->nr] = sat;
316
317	return 0;
318}
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320static int wf_sat_remove(struct i2c_client *client)
321{
322	struct wf_sat *sat = i2c_get_clientdata(client);
323	struct wf_sat_sensor *sens;
324
325	/* release sensors */
326	while(!list_empty(&sat->sensors)) {
327		sens = list_first_entry(&sat->sensors,
328					struct wf_sat_sensor, link);
329		list_del(&sens->link);
330		wf_unregister_sensor(&sens->sens);
331	}
332	sat->i2c = NULL;
333	kref_put(&sat->ref, wf_sat_release);
334
335	return 0;
336}
337
338static const struct i2c_device_id wf_sat_id[] = {
339	{ "MAC,smu-sat", 0 },
340	{ }
341};
342MODULE_DEVICE_TABLE(i2c, wf_sat_id);
343
344static struct i2c_driver wf_sat_driver = {
345	.driver = {
346		.name		= "wf_smu_sat",
347	},
 
348	.probe		= wf_sat_probe,
349	.remove		= wf_sat_remove,
350	.id_table	= wf_sat_id,
351};
352
353module_i2c_driver(wf_sat_driver);
 
 
 
 
 
 
 
 
 
 
 
 
 
354
355MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
356MODULE_DESCRIPTION("SMU satellite sensors for PowerMac thermal control");
357MODULE_LICENSE("GPL");