xref: /linux/drivers/macintosh/windfarm_smu_controls.c (revision 1ad35f6e2864d9b52fe9705ede1730468c25f692)
175722d39SBenjamin Herrenschmidt /*
275722d39SBenjamin Herrenschmidt  * Windfarm PowerMac thermal control. SMU based controls
375722d39SBenjamin Herrenschmidt  *
475722d39SBenjamin Herrenschmidt  * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
575722d39SBenjamin Herrenschmidt  *                    <benh@kernel.crashing.org>
675722d39SBenjamin Herrenschmidt  *
775722d39SBenjamin Herrenschmidt  * Released under the term of the GNU GPL v2.
875722d39SBenjamin Herrenschmidt  */
975722d39SBenjamin Herrenschmidt 
1075722d39SBenjamin Herrenschmidt #include <linux/types.h>
1175722d39SBenjamin Herrenschmidt #include <linux/errno.h>
1275722d39SBenjamin Herrenschmidt #include <linux/kernel.h>
1375722d39SBenjamin Herrenschmidt #include <linux/delay.h>
1475722d39SBenjamin Herrenschmidt #include <linux/slab.h>
1575722d39SBenjamin Herrenschmidt #include <linux/init.h>
1675722d39SBenjamin Herrenschmidt #include <linux/wait.h>
17de25968cSTim Schmielau #include <linux/completion.h>
1875722d39SBenjamin Herrenschmidt #include <asm/prom.h>
1975722d39SBenjamin Herrenschmidt #include <asm/machdep.h>
2075722d39SBenjamin Herrenschmidt #include <asm/io.h>
2175722d39SBenjamin Herrenschmidt #include <asm/sections.h>
2275722d39SBenjamin Herrenschmidt #include <asm/smu.h>
2375722d39SBenjamin Herrenschmidt 
2475722d39SBenjamin Herrenschmidt #include "windfarm.h"
2575722d39SBenjamin Herrenschmidt 
26ac171c46SBenjamin Herrenschmidt #define VERSION "0.4"
2775722d39SBenjamin Herrenschmidt 
2875722d39SBenjamin Herrenschmidt #undef DEBUG
2975722d39SBenjamin Herrenschmidt 
3075722d39SBenjamin Herrenschmidt #ifdef DEBUG
3175722d39SBenjamin Herrenschmidt #define DBG(args...)	printk(args)
3275722d39SBenjamin Herrenschmidt #else
3375722d39SBenjamin Herrenschmidt #define DBG(args...)	do { } while(0)
3475722d39SBenjamin Herrenschmidt #endif
3575722d39SBenjamin Herrenschmidt 
36ac171c46SBenjamin Herrenschmidt static int smu_supports_new_fans_ops = 1;
37ac171c46SBenjamin Herrenschmidt 
3875722d39SBenjamin Herrenschmidt /*
3975722d39SBenjamin Herrenschmidt  * SMU fans control object
4075722d39SBenjamin Herrenschmidt  */
4175722d39SBenjamin Herrenschmidt 
4275722d39SBenjamin Herrenschmidt static LIST_HEAD(smu_fans);
4375722d39SBenjamin Herrenschmidt 
4475722d39SBenjamin Herrenschmidt struct smu_fan_control {
4575722d39SBenjamin Herrenschmidt 	struct list_head	link;
4675722d39SBenjamin Herrenschmidt 	int    			fan_type;	/* 0 = rpm, 1 = pwm */
4775722d39SBenjamin Herrenschmidt 	u32			reg;		/* index in SMU */
4875722d39SBenjamin Herrenschmidt 	s32			value;		/* current value */
4975722d39SBenjamin Herrenschmidt 	s32			min, max;	/* min/max values */
5075722d39SBenjamin Herrenschmidt 	struct wf_control	ctrl;
5175722d39SBenjamin Herrenschmidt };
5275722d39SBenjamin Herrenschmidt #define to_smu_fan(c) container_of(c, struct smu_fan_control, ctrl)
5375722d39SBenjamin Herrenschmidt 
5475722d39SBenjamin Herrenschmidt static int smu_set_fan(int pwm, u8 id, u16 value)
5575722d39SBenjamin Herrenschmidt {
5675722d39SBenjamin Herrenschmidt 	struct smu_cmd cmd;
5775722d39SBenjamin Herrenschmidt 	u8 buffer[16];
586e9a4738SPeter Zijlstra 	DECLARE_COMPLETION_ONSTACK(comp);
5975722d39SBenjamin Herrenschmidt 	int rc;
6075722d39SBenjamin Herrenschmidt 
6175722d39SBenjamin Herrenschmidt 	/* Fill SMU command structure */
6275722d39SBenjamin Herrenschmidt 	cmd.cmd = SMU_CMD_FAN_COMMAND;
63ac171c46SBenjamin Herrenschmidt 
64ac171c46SBenjamin Herrenschmidt 	/* The SMU has an "old" and a "new" way of setting the fan speed
65ac171c46SBenjamin Herrenschmidt 	 * Unfortunately, I found no reliable way to know which one works
66ac171c46SBenjamin Herrenschmidt 	 * on a given machine model. After some investigations it appears
67ac171c46SBenjamin Herrenschmidt 	 * that MacOS X just tries the new one, and if it fails fallbacks
68ac171c46SBenjamin Herrenschmidt 	 * to the old ones ... Ugh.
69ac171c46SBenjamin Herrenschmidt 	 */
70ac171c46SBenjamin Herrenschmidt  retry:
71ac171c46SBenjamin Herrenschmidt 	if (smu_supports_new_fans_ops) {
72ac171c46SBenjamin Herrenschmidt 		buffer[0] = 0x30;
73ac171c46SBenjamin Herrenschmidt 		buffer[1] = id;
74ac171c46SBenjamin Herrenschmidt 		*((u16 *)(&buffer[2])) = value;
75ac171c46SBenjamin Herrenschmidt 		cmd.data_len = 4;
76ac171c46SBenjamin Herrenschmidt 	} else {
77ac171c46SBenjamin Herrenschmidt 		if (id > 7)
78ac171c46SBenjamin Herrenschmidt 			return -EINVAL;
79ac171c46SBenjamin Herrenschmidt 		/* Fill argument buffer */
80ac171c46SBenjamin Herrenschmidt 		memset(buffer, 0, 16);
81ac171c46SBenjamin Herrenschmidt 		buffer[0] = pwm ? 0x10 : 0x00;
82ac171c46SBenjamin Herrenschmidt 		buffer[1] = 0x01 << id;
83ac171c46SBenjamin Herrenschmidt 		*((u16 *)&buffer[2 + id * 2]) = value;
8475722d39SBenjamin Herrenschmidt 		cmd.data_len = 14;
85ac171c46SBenjamin Herrenschmidt 	}
86ac171c46SBenjamin Herrenschmidt 
8775722d39SBenjamin Herrenschmidt 	cmd.reply_len = 16;
8875722d39SBenjamin Herrenschmidt 	cmd.data_buf = cmd.reply_buf = buffer;
8975722d39SBenjamin Herrenschmidt 	cmd.status = 0;
9075722d39SBenjamin Herrenschmidt 	cmd.done = smu_done_complete;
9175722d39SBenjamin Herrenschmidt 	cmd.misc = &comp;
9275722d39SBenjamin Herrenschmidt 
9375722d39SBenjamin Herrenschmidt 	rc = smu_queue_cmd(&cmd);
9475722d39SBenjamin Herrenschmidt 	if (rc)
9575722d39SBenjamin Herrenschmidt 		return rc;
9675722d39SBenjamin Herrenschmidt 	wait_for_completion(&comp);
97ac171c46SBenjamin Herrenschmidt 
98ac171c46SBenjamin Herrenschmidt 	/* Handle fallback (see coment above) */
99ac171c46SBenjamin Herrenschmidt 	if (cmd.status != 0 && smu_supports_new_fans_ops) {
100ac171c46SBenjamin Herrenschmidt 		printk(KERN_WARNING "windfarm: SMU failed new fan command "
101ac171c46SBenjamin Herrenschmidt 		       "falling back to old method\n");
102ac171c46SBenjamin Herrenschmidt 		smu_supports_new_fans_ops = 0;
103ac171c46SBenjamin Herrenschmidt 		goto retry;
104ac171c46SBenjamin Herrenschmidt 	}
105ac171c46SBenjamin Herrenschmidt 
10675722d39SBenjamin Herrenschmidt 	return cmd.status;
10775722d39SBenjamin Herrenschmidt }
10875722d39SBenjamin Herrenschmidt 
10975722d39SBenjamin Herrenschmidt static void smu_fan_release(struct wf_control *ct)
11075722d39SBenjamin Herrenschmidt {
11175722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct = to_smu_fan(ct);
11275722d39SBenjamin Herrenschmidt 
11375722d39SBenjamin Herrenschmidt 	kfree(fct);
11475722d39SBenjamin Herrenschmidt }
11575722d39SBenjamin Herrenschmidt 
11675722d39SBenjamin Herrenschmidt static int smu_fan_set(struct wf_control *ct, s32 value)
11775722d39SBenjamin Herrenschmidt {
11875722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct = to_smu_fan(ct);
11975722d39SBenjamin Herrenschmidt 
12075722d39SBenjamin Herrenschmidt 	if (value < fct->min)
12175722d39SBenjamin Herrenschmidt 		value = fct->min;
12275722d39SBenjamin Herrenschmidt 	if (value > fct->max)
12375722d39SBenjamin Herrenschmidt 		value = fct->max;
12475722d39SBenjamin Herrenschmidt 	fct->value = value;
12575722d39SBenjamin Herrenschmidt 
12675722d39SBenjamin Herrenschmidt 	return smu_set_fan(fct->fan_type, fct->reg, value);
12775722d39SBenjamin Herrenschmidt }
12875722d39SBenjamin Herrenschmidt 
12975722d39SBenjamin Herrenschmidt static int smu_fan_get(struct wf_control *ct, s32 *value)
13075722d39SBenjamin Herrenschmidt {
13175722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct = to_smu_fan(ct);
13275722d39SBenjamin Herrenschmidt 	*value = fct->value; /* todo: read from SMU */
13375722d39SBenjamin Herrenschmidt 	return 0;
13475722d39SBenjamin Herrenschmidt }
13575722d39SBenjamin Herrenschmidt 
13675722d39SBenjamin Herrenschmidt static s32 smu_fan_min(struct wf_control *ct)
13775722d39SBenjamin Herrenschmidt {
13875722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct = to_smu_fan(ct);
13975722d39SBenjamin Herrenschmidt 	return fct->min;
14075722d39SBenjamin Herrenschmidt }
14175722d39SBenjamin Herrenschmidt 
14275722d39SBenjamin Herrenschmidt static s32 smu_fan_max(struct wf_control *ct)
14375722d39SBenjamin Herrenschmidt {
14475722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct = to_smu_fan(ct);
14575722d39SBenjamin Herrenschmidt 	return fct->max;
14675722d39SBenjamin Herrenschmidt }
14775722d39SBenjamin Herrenschmidt 
148*1ad35f6eSBhumika Goyal static const struct wf_control_ops smu_fan_ops = {
14975722d39SBenjamin Herrenschmidt 	.set_value	= smu_fan_set,
15075722d39SBenjamin Herrenschmidt 	.get_value	= smu_fan_get,
15175722d39SBenjamin Herrenschmidt 	.get_min	= smu_fan_min,
15275722d39SBenjamin Herrenschmidt 	.get_max	= smu_fan_max,
15375722d39SBenjamin Herrenschmidt 	.release	= smu_fan_release,
15475722d39SBenjamin Herrenschmidt 	.owner		= THIS_MODULE,
15575722d39SBenjamin Herrenschmidt };
15675722d39SBenjamin Herrenschmidt 
15775722d39SBenjamin Herrenschmidt static struct smu_fan_control *smu_fan_create(struct device_node *node,
15875722d39SBenjamin Herrenschmidt 					      int pwm_fan)
15975722d39SBenjamin Herrenschmidt {
16075722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct;
161018a3d1dSJeremy Kerr 	const s32 *v;
162018a3d1dSJeremy Kerr 	const u32 *reg;
163018a3d1dSJeremy Kerr 	const char *l;
16475722d39SBenjamin Herrenschmidt 
16575722d39SBenjamin Herrenschmidt 	fct = kmalloc(sizeof(struct smu_fan_control), GFP_KERNEL);
16675722d39SBenjamin Herrenschmidt 	if (fct == NULL)
16775722d39SBenjamin Herrenschmidt 		return NULL;
16875722d39SBenjamin Herrenschmidt 	fct->ctrl.ops = &smu_fan_ops;
16901b2726dSStephen Rothwell 	l = of_get_property(node, "location", NULL);
17075722d39SBenjamin Herrenschmidt 	if (l == NULL)
17175722d39SBenjamin Herrenschmidt 		goto fail;
17275722d39SBenjamin Herrenschmidt 
17375722d39SBenjamin Herrenschmidt 	fct->fan_type = pwm_fan;
17475722d39SBenjamin Herrenschmidt 	fct->ctrl.type = pwm_fan ? WF_CONTROL_PWM_FAN : WF_CONTROL_RPM_FAN;
17575722d39SBenjamin Herrenschmidt 
17675722d39SBenjamin Herrenschmidt 	/* We use the name & location here the same way we do for SMU sensors,
17775722d39SBenjamin Herrenschmidt 	 * see the comment in windfarm_smu_sensors.c. The locations are a bit
17875722d39SBenjamin Herrenschmidt 	 * less consistent here between the iMac and the desktop models, but
17975722d39SBenjamin Herrenschmidt 	 * that is good enough for our needs for now at least.
18075722d39SBenjamin Herrenschmidt 	 *
18175722d39SBenjamin Herrenschmidt 	 * One problem though is that Apple seem to be inconsistent with case
18275722d39SBenjamin Herrenschmidt 	 * and the kernel doesn't have strcasecmp =P
18375722d39SBenjamin Herrenschmidt 	 */
18475722d39SBenjamin Herrenschmidt 
18575722d39SBenjamin Herrenschmidt 	fct->ctrl.name = NULL;
18675722d39SBenjamin Herrenschmidt 
18775722d39SBenjamin Herrenschmidt 	/* Names used on desktop models */
18875722d39SBenjamin Herrenschmidt 	if (!strcmp(l, "Rear Fan 0") || !strcmp(l, "Rear Fan") ||
189ac171c46SBenjamin Herrenschmidt 	    !strcmp(l, "Rear fan 0") || !strcmp(l, "Rear fan") ||
190ac171c46SBenjamin Herrenschmidt 	    !strcmp(l, "CPU A EXHAUST"))
19175722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-rear-fan-0";
192ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "Rear Fan 1") || !strcmp(l, "Rear fan 1") ||
193ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "CPU B EXHAUST"))
19475722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-rear-fan-1";
19575722d39SBenjamin Herrenschmidt 	else if (!strcmp(l, "Front Fan 0") || !strcmp(l, "Front Fan") ||
196ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "Front fan 0") || !strcmp(l, "Front fan") ||
197ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "CPU A INTAKE"))
19875722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-front-fan-0";
199ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "Front Fan 1") || !strcmp(l, "Front fan 1") ||
200ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "CPU B INTAKE"))
20175722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-front-fan-1";
202ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "CPU A PUMP"))
203ac171c46SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-pump-0";
204529586dcSBolko Maass 	else if (!strcmp(l, "CPU B PUMP"))
205529586dcSBolko Maass 		fct->ctrl.name = "cpu-pump-1";
206ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "Slots Fan") || !strcmp(l, "Slots fan") ||
207ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "EXPANSION SLOTS INTAKE"))
20875722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "slots-fan";
209ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "Drive Bay") || !strcmp(l, "Drive bay") ||
210ac171c46SBenjamin Herrenschmidt 		 !strcmp(l, "DRIVE BAY A INTAKE"))
21175722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "drive-bay-fan";
212ac171c46SBenjamin Herrenschmidt 	else if (!strcmp(l, "BACKSIDE"))
213ac171c46SBenjamin Herrenschmidt 		fct->ctrl.name = "backside-fan";
21475722d39SBenjamin Herrenschmidt 
21575722d39SBenjamin Herrenschmidt 	/* Names used on iMac models */
21675722d39SBenjamin Herrenschmidt 	if (!strcmp(l, "System Fan") || !strcmp(l, "System fan"))
21775722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "system-fan";
21875722d39SBenjamin Herrenschmidt 	else if (!strcmp(l, "CPU Fan") || !strcmp(l, "CPU fan"))
21975722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "cpu-fan";
22075722d39SBenjamin Herrenschmidt 	else if (!strcmp(l, "Hard Drive") || !strcmp(l, "Hard drive"))
22175722d39SBenjamin Herrenschmidt 		fct->ctrl.name = "drive-bay-fan";
22280ff974dSÉtienne Bersac 	else if (!strcmp(l, "HDD Fan")) /* seen on iMac G5 iSight */
22380ff974dSÉtienne Bersac 		fct->ctrl.name = "hard-drive-fan";
22480ff974dSÉtienne Bersac 	else if (!strcmp(l, "ODD Fan")) /* same */
22580ff974dSÉtienne Bersac 		fct->ctrl.name = "optical-drive-fan";
22675722d39SBenjamin Herrenschmidt 
22775722d39SBenjamin Herrenschmidt 	/* Unrecognized fan, bail out */
22875722d39SBenjamin Herrenschmidt 	if (fct->ctrl.name == NULL)
22975722d39SBenjamin Herrenschmidt 		goto fail;
23075722d39SBenjamin Herrenschmidt 
23175722d39SBenjamin Herrenschmidt 	/* Get min & max values*/
23201b2726dSStephen Rothwell 	v = of_get_property(node, "min-value", NULL);
23375722d39SBenjamin Herrenschmidt 	if (v == NULL)
23475722d39SBenjamin Herrenschmidt 		goto fail;
23575722d39SBenjamin Herrenschmidt 	fct->min = *v;
23601b2726dSStephen Rothwell 	v = of_get_property(node, "max-value", NULL);
23775722d39SBenjamin Herrenschmidt 	if (v == NULL)
23875722d39SBenjamin Herrenschmidt 		goto fail;
23975722d39SBenjamin Herrenschmidt 	fct->max = *v;
24075722d39SBenjamin Herrenschmidt 
24175722d39SBenjamin Herrenschmidt 	/* Get "reg" value */
24201b2726dSStephen Rothwell 	reg = of_get_property(node, "reg", NULL);
24375722d39SBenjamin Herrenschmidt 	if (reg == NULL)
24475722d39SBenjamin Herrenschmidt 		goto fail;
24575722d39SBenjamin Herrenschmidt 	fct->reg = *reg;
24675722d39SBenjamin Herrenschmidt 
24775722d39SBenjamin Herrenschmidt 	if (wf_register_control(&fct->ctrl))
24875722d39SBenjamin Herrenschmidt 		goto fail;
24975722d39SBenjamin Herrenschmidt 
25075722d39SBenjamin Herrenschmidt 	return fct;
25175722d39SBenjamin Herrenschmidt  fail:
25275722d39SBenjamin Herrenschmidt 	kfree(fct);
25375722d39SBenjamin Herrenschmidt 	return NULL;
25475722d39SBenjamin Herrenschmidt }
25575722d39SBenjamin Herrenschmidt 
25675722d39SBenjamin Herrenschmidt 
25775722d39SBenjamin Herrenschmidt static int __init smu_controls_init(void)
25875722d39SBenjamin Herrenschmidt {
25975722d39SBenjamin Herrenschmidt 	struct device_node *smu, *fans, *fan;
26075722d39SBenjamin Herrenschmidt 
26175722d39SBenjamin Herrenschmidt 	if (!smu_present())
26275722d39SBenjamin Herrenschmidt 		return -ENODEV;
26375722d39SBenjamin Herrenschmidt 
26475722d39SBenjamin Herrenschmidt 	smu = of_find_node_by_type(NULL, "smu");
26575722d39SBenjamin Herrenschmidt 	if (smu == NULL)
26675722d39SBenjamin Herrenschmidt 		return -ENODEV;
26775722d39SBenjamin Herrenschmidt 
26875722d39SBenjamin Herrenschmidt 	/* Look for RPM fans */
26975722d39SBenjamin Herrenschmidt 	for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;)
270ac171c46SBenjamin Herrenschmidt 		if (!strcmp(fans->name, "rpm-fans") ||
27155b61fecSStephen Rothwell 		    of_device_is_compatible(fans, "smu-rpm-fans"))
27275722d39SBenjamin Herrenschmidt 			break;
27375722d39SBenjamin Herrenschmidt 	for (fan = NULL;
27475722d39SBenjamin Herrenschmidt 	     fans && (fan = of_get_next_child(fans, fan)) != NULL;) {
27575722d39SBenjamin Herrenschmidt 		struct smu_fan_control *fct;
27675722d39SBenjamin Herrenschmidt 
27775722d39SBenjamin Herrenschmidt 		fct = smu_fan_create(fan, 0);
27875722d39SBenjamin Herrenschmidt 		if (fct == NULL) {
27975722d39SBenjamin Herrenschmidt 			printk(KERN_WARNING "windfarm: Failed to create SMU "
28075722d39SBenjamin Herrenschmidt 			       "RPM fan %s\n", fan->name);
28175722d39SBenjamin Herrenschmidt 			continue;
28275722d39SBenjamin Herrenschmidt 		}
28375722d39SBenjamin Herrenschmidt 		list_add(&fct->link, &smu_fans);
28475722d39SBenjamin Herrenschmidt 	}
28575722d39SBenjamin Herrenschmidt 	of_node_put(fans);
28675722d39SBenjamin Herrenschmidt 
28775722d39SBenjamin Herrenschmidt 
28875722d39SBenjamin Herrenschmidt 	/* Look for PWM fans */
28975722d39SBenjamin Herrenschmidt 	for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;)
29075722d39SBenjamin Herrenschmidt 		if (!strcmp(fans->name, "pwm-fans"))
29175722d39SBenjamin Herrenschmidt 			break;
29275722d39SBenjamin Herrenschmidt 	for (fan = NULL;
29375722d39SBenjamin Herrenschmidt 	     fans && (fan = of_get_next_child(fans, fan)) != NULL;) {
29475722d39SBenjamin Herrenschmidt 		struct smu_fan_control *fct;
29575722d39SBenjamin Herrenschmidt 
29675722d39SBenjamin Herrenschmidt 		fct = smu_fan_create(fan, 1);
29775722d39SBenjamin Herrenschmidt 		if (fct == NULL) {
29875722d39SBenjamin Herrenschmidt 			printk(KERN_WARNING "windfarm: Failed to create SMU "
29975722d39SBenjamin Herrenschmidt 			       "PWM fan %s\n", fan->name);
30075722d39SBenjamin Herrenschmidt 			continue;
30175722d39SBenjamin Herrenschmidt 		}
30275722d39SBenjamin Herrenschmidt 		list_add(&fct->link, &smu_fans);
30375722d39SBenjamin Herrenschmidt 	}
30475722d39SBenjamin Herrenschmidt 	of_node_put(fans);
30575722d39SBenjamin Herrenschmidt 	of_node_put(smu);
30675722d39SBenjamin Herrenschmidt 
30775722d39SBenjamin Herrenschmidt 	return 0;
30875722d39SBenjamin Herrenschmidt }
30975722d39SBenjamin Herrenschmidt 
31075722d39SBenjamin Herrenschmidt static void __exit smu_controls_exit(void)
31175722d39SBenjamin Herrenschmidt {
31275722d39SBenjamin Herrenschmidt 	struct smu_fan_control *fct;
31375722d39SBenjamin Herrenschmidt 
31475722d39SBenjamin Herrenschmidt 	while (!list_empty(&smu_fans)) {
31575722d39SBenjamin Herrenschmidt 		fct = list_entry(smu_fans.next, struct smu_fan_control, link);
31675722d39SBenjamin Herrenschmidt 		list_del(&fct->link);
31775722d39SBenjamin Herrenschmidt 		wf_unregister_control(&fct->ctrl);
31875722d39SBenjamin Herrenschmidt 	}
31975722d39SBenjamin Herrenschmidt }
32075722d39SBenjamin Herrenschmidt 
32175722d39SBenjamin Herrenschmidt 
32275722d39SBenjamin Herrenschmidt module_init(smu_controls_init);
32375722d39SBenjamin Herrenschmidt module_exit(smu_controls_exit);
32475722d39SBenjamin Herrenschmidt 
32575722d39SBenjamin Herrenschmidt MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
32675722d39SBenjamin Herrenschmidt MODULE_DESCRIPTION("SMU control objects for PowerMacs thermal control");
32775722d39SBenjamin Herrenschmidt MODULE_LICENSE("GPL");
32875722d39SBenjamin Herrenschmidt 
329