blob: f55f6adf5e5ff77de90dcee8160a4853e58437b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Creation Date: <2003/03/14 20:54:13 samuel>
3 * Time-stamp: <2004/03/20 14:20:59 samuel>
4 *
5 * <therm_windtunnel.c>
6 *
7 * The G4 "windtunnel" has a single fan controlled by an
8 * ADM1030 fan controller and a DS1775 thermostat.
9 *
10 * The fan controller is equipped with a temperature sensor
11 * which measures the case temperature. The DS1775 sensor
12 * measures the CPU temperature. This driver tunes the
13 * behavior of the fan. It is based upon empirical observations
14 * of the 'AppleFan' driver under Mac OS X.
15 *
16 * WARNING: This driver has only been testen on Apple's
17 * 1.25 MHz Dual G4 (March 03). It is tuned for a CPU
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020018 * temperature around 57 C.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 *
20 * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
21 *
22 * Loosely based upon 'thermostat.c' written by Benjamin Herrenschmidt
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation
27 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/types.h>
31#include <linux/module.h>
32#include <linux/errno.h>
33#include <linux/kernel.h>
34#include <linux/delay.h>
35#include <linux/sched.h>
36#include <linux/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/init.h>
Paul Mackerras98f67402007-12-13 15:57:45 +110038#include <linux/kthread.h>
Stephen Rothwellad9e05a2008-05-23 16:27:02 +100039#include <linux/of_platform.h>
Benjamin Herrenschmidt7eebde72006-11-11 17:24:59 +110040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/prom.h>
42#include <asm/machdep.h>
43#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/sections.h>
Jeff Mahoney5e655772005-07-06 15:44:41 -040045#include <asm/macio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Lucas De Marchi25985ed2011-03-30 22:57:33 -030047#define LOG_TEMP 0 /* continuously log temperature */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static struct {
50 volatile int running;
Paul Mackerras98f67402007-12-13 15:57:45 +110051 struct task_struct *poll_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Daniel Walker1baaeea2008-06-10 09:26:08 +100053 struct mutex lock;
Grant Likely2dc11582010-08-06 09:25:50 -060054 struct platform_device *of_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 struct i2c_client *thermostat;
57 struct i2c_client *fan;
58
59 int overheat_temp; /* 100% fan at this temp */
60 int overheat_hyst;
61 int temp;
62 int casetemp;
63 int fan_level; /* active fan_table setting */
64
65 int downind;
66 int upind;
67
68 int r0, r1, r20, r23, r25; /* saved register */
69} x;
70
71#define T(x,y) (((x)<<8) | (y)*0x100/10 )
72
73static struct {
74 int fan_down_setting;
75 int temp;
76 int fan_up_setting;
77} fan_table[] = {
78 { 11, T(0,0), 11 }, /* min fan */
79 { 11, T(55,0), 11 },
80 { 6, T(55,3), 11 },
81 { 7, T(56,0), 11 },
82 { 8, T(57,0), 8 },
83 { 7, T(58,3), 7 },
84 { 6, T(58,8), 6 },
85 { 5, T(59,2), 5 },
86 { 4, T(59,6), 4 },
87 { 3, T(59,9), 3 },
88 { 2, T(60,1), 2 },
89 { 1, 0xfffff, 1 } /* on fire */
90};
91
92static void
93print_temp( const char *s, int temp )
94{
95 printk("%s%d.%d C", s ? s : "", temp>>8, (temp & 255)*10/256 );
96}
97
98static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -040099show_cpu_temperature( struct device *dev, struct device_attribute *attr, char *buf )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 return sprintf(buf, "%d.%d\n", x.temp>>8, (x.temp & 255)*10/256 );
102}
103
104static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400105show_case_temperature( struct device *dev, struct device_attribute *attr, char *buf )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 return sprintf(buf, "%d.%d\n", x.casetemp>>8, (x.casetemp & 255)*10/256 );
108}
109
110static DEVICE_ATTR(cpu_temperature, S_IRUGO, show_cpu_temperature, NULL );
111static DEVICE_ATTR(case_temperature, S_IRUGO, show_case_temperature, NULL );
112
113
114
115/************************************************************************/
116/* controller thread */
117/************************************************************************/
118
119static int
120write_reg( struct i2c_client *cl, int reg, int data, int len )
121{
122 u8 tmp[3];
123
124 if( len < 1 || len > 2 || data < 0 )
125 return -EINVAL;
126
127 tmp[0] = reg;
128 tmp[1] = (len == 1) ? data : (data >> 8);
129 tmp[2] = data;
130 len++;
131
132 if( i2c_master_send(cl, tmp, len) != len )
133 return -ENODEV;
134 return 0;
135}
136
137static int
138read_reg( struct i2c_client *cl, int reg, int len )
139{
140 u8 buf[2];
141
142 if( len != 1 && len != 2 )
143 return -EINVAL;
144 buf[0] = reg;
145 if( i2c_master_send(cl, buf, 1) != 1 )
146 return -ENODEV;
147 if( i2c_master_recv(cl, buf, len) != len )
148 return -ENODEV;
149 return (len == 2)? ((unsigned int)buf[0] << 8) | buf[1] : buf[0];
150}
151
152static void
153tune_fan( int fan_setting )
154{
155 int val = (fan_setting << 3) | 7;
156
157 /* write_reg( x.fan, 0x24, val, 1 ); */
158 write_reg( x.fan, 0x25, val, 1 );
159 write_reg( x.fan, 0x20, 0, 1 );
160 print_temp("CPU-temp: ", x.temp );
161 if( x.casetemp )
162 print_temp(", Case: ", x.casetemp );
163 printk(", Fan: %d (tuned %+d)\n", 11-fan_setting, x.fan_level-fan_setting );
164
165 x.fan_level = fan_setting;
166}
167
168static void
169poll_temp( void )
170{
171 int temp, i, level, casetemp;
172
173 temp = read_reg( x.thermostat, 0, 2 );
174
175 /* this actually occurs when the computer is loaded */
176 if( temp < 0 )
177 return;
178
179 casetemp = read_reg(x.fan, 0x0b, 1) << 8;
180 casetemp |= (read_reg(x.fan, 0x06, 1) & 0x7) << 5;
181
182 if( LOG_TEMP && x.temp != temp ) {
183 print_temp("CPU-temp: ", temp );
184 print_temp(", Case: ", casetemp );
185 printk(", Fan: %d\n", 11-x.fan_level );
186 }
187 x.temp = temp;
188 x.casetemp = casetemp;
189
190 level = -1;
191 for( i=0; (temp & 0xffff) > fan_table[i].temp ; i++ )
192 ;
193 if( i < x.downind )
194 level = fan_table[i].fan_down_setting;
195 x.downind = i;
196
197 for( i=0; (temp & 0xffff) >= fan_table[i+1].temp ; i++ )
198 ;
199 if( x.upind < i )
200 level = fan_table[i].fan_up_setting;
201 x.upind = i;
202
203 if( level >= 0 )
204 tune_fan( level );
205}
206
207
208static void
209setup_hardware( void )
210{
211 int val;
Stephen Rothwell98894df2008-01-03 15:15:28 +1100212 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* save registers (if we unload the module) */
215 x.r0 = read_reg( x.fan, 0x00, 1 );
216 x.r1 = read_reg( x.fan, 0x01, 1 );
217 x.r20 = read_reg( x.fan, 0x20, 1 );
218 x.r23 = read_reg( x.fan, 0x23, 1 );
219 x.r25 = read_reg( x.fan, 0x25, 1 );
220
221 /* improve measurement resolution (convergence time 1.5s) */
222 if( (val=read_reg(x.thermostat, 1, 1)) >= 0 ) {
223 val |= 0x60;
224 if( write_reg( x.thermostat, 1, val, 1 ) )
225 printk("Failed writing config register\n");
226 }
227 /* disable interrupts and TAC input */
228 write_reg( x.fan, 0x01, 0x01, 1 );
229 /* enable filter */
230 write_reg( x.fan, 0x23, 0x91, 1 );
231 /* remote temp. controls fan */
232 write_reg( x.fan, 0x00, 0x95, 1 );
233
234 /* The thermostat (which besides measureing temperature controls
235 * has a THERM output which puts the fan on 100%) is usually
236 * set to kick in at 80 C (chip default). We reduce this a bit
237 * to be on the safe side (OSX doesn't)...
238 */
239 if( x.overheat_temp == (80 << 8) ) {
Lyonel Vincentb8e4a7d2009-08-30 08:54:20 +0000240 x.overheat_temp = 75 << 8;
241 x.overheat_hyst = 70 << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 write_reg( x.thermostat, 2, x.overheat_hyst, 2 );
243 write_reg( x.thermostat, 3, x.overheat_temp, 2 );
244
245 print_temp("Reducing overheating limit to ", x.overheat_temp );
246 print_temp(" (Hyst: ", x.overheat_hyst );
247 printk(")\n");
248 }
249
250 /* set an initial fan setting */
251 x.downind = 0xffff;
252 x.upind = -1;
253 /* tune_fan( fan_up_table[x.upind].fan_setting ); */
254
Stephen Rothwell98894df2008-01-03 15:15:28 +1100255 err = device_create_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
256 err |= device_create_file( &x.of_dev->dev, &dev_attr_case_temperature );
257 if (err)
258 printk(KERN_WARNING
259 "Failed to create temperature attribute file(s).\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
262static void
263restore_regs( void )
264{
265 device_remove_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
266 device_remove_file( &x.of_dev->dev, &dev_attr_case_temperature );
267
268 write_reg( x.fan, 0x01, x.r1, 1 );
269 write_reg( x.fan, 0x20, x.r20, 1 );
270 write_reg( x.fan, 0x23, x.r23, 1 );
271 write_reg( x.fan, 0x25, x.r25, 1 );
272 write_reg( x.fan, 0x00, x.r0, 1 );
273}
274
Paul Mackerras98f67402007-12-13 15:57:45 +1100275static int control_loop(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Daniel Walker1baaeea2008-06-10 09:26:08 +1000277 mutex_lock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 setup_hardware();
Daniel Walker1baaeea2008-06-10 09:26:08 +1000279 mutex_unlock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Paul Mackerras98f67402007-12-13 15:57:45 +1100281 for (;;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 msleep_interruptible(8000);
Paul Mackerras98f67402007-12-13 15:57:45 +1100283 if (kthread_should_stop())
284 break;
285
Daniel Walker1baaeea2008-06-10 09:26:08 +1000286 mutex_lock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 poll_temp();
Daniel Walker1baaeea2008-06-10 09:26:08 +1000288 mutex_unlock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290
Daniel Walker1baaeea2008-06-10 09:26:08 +1000291 mutex_lock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 restore_regs();
Daniel Walker1baaeea2008-06-10 09:26:08 +1000293 mutex_unlock(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Paul Mackerras98f67402007-12-13 15:57:45 +1100295 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298
299/************************************************************************/
300/* i2c probing and setup */
301/************************************************************************/
302
Wolfram Sang38b17af2020-02-25 15:12:29 +0100303static void do_attach(struct i2c_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Wolfram Sang38b17af2020-02-25 15:12:29 +0100305 struct i2c_board_info info = { };
306 struct device_node *np;
307
Jean Delvare036533e2009-06-15 18:01:52 +0200308 /* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */
309 static const unsigned short scan_ds1775[] = {
310 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
311 I2C_CLIENT_END
312 };
313 static const unsigned short scan_adm1030[] = {
314 0x2c, 0x2d, 0x2e, 0x2f,
315 I2C_CLIENT_END
316 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Wolfram Sang38b17af2020-02-25 15:12:29 +0100318 if (x.running || strncmp(adapter->name, "uni-n", 5))
319 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Wolfram Sang38b17af2020-02-25 15:12:29 +0100321 np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,ds1775");
322 if (np) {
323 of_node_put(np);
324 } else {
325 strlcpy(info.type, "MAC,ds1775", I2C_NAME_SIZE);
Wolfram Sang624d1be2020-02-10 18:04:01 +0100326 i2c_new_scanned_device(adapter, &info, scan_ds1775, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
Wolfram Sang38b17af2020-02-25 15:12:29 +0100328
329 np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,adm1030");
330 if (np) {
331 of_node_put(np);
332 } else {
333 strlcpy(info.type, "MAC,adm1030", I2C_NAME_SIZE);
Wolfram Sang624d1be2020-02-10 18:04:01 +0100334 i2c_new_scanned_device(adapter, &info, scan_adm1030, NULL);
Wolfram Sang38b17af2020-02-25 15:12:29 +0100335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338static int
Jean Delvare036533e2009-06-15 18:01:52 +0200339do_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Jean Delvare036533e2009-06-15 18:01:52 +0200341 if (x.running) {
342 x.running = 0;
343 kthread_stop(x.poll_task);
344 x.poll_task = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
Jean Delvare036533e2009-06-15 18:01:52 +0200346 if (client == x.thermostat)
347 x.thermostat = NULL;
348 else if (client == x.fan)
349 x.fan = NULL;
350 else
351 printk(KERN_ERR "g4fan: bad client\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Jean Delvare036533e2009-06-15 18:01:52 +0200353 return 0;
354}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356static int
357attach_fan( struct i2c_client *cl )
358{
359 if( x.fan )
360 goto out;
361
362 /* check that this is an ADM1030 */
363 if( read_reg(cl, 0x3d, 1) != 0x30 || read_reg(cl, 0x3e, 1) != 0x41 )
364 goto out;
365 printk("ADM1030 fan controller [@%02x]\n", cl->addr );
366
Jean Delvare036533e2009-06-15 18:01:52 +0200367 x.fan = cl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return 0;
370}
371
372static int
373attach_thermostat( struct i2c_client *cl )
374{
375 int hyst_temp, os_temp, temp;
376
377 if( x.thermostat )
378 goto out;
379
380 if( (temp=read_reg(cl, 0, 2)) < 0 )
381 goto out;
382
383 /* temperature sanity check */
384 if( temp < 0x1600 || temp > 0x3c00 )
385 goto out;
386 hyst_temp = read_reg(cl, 2, 2);
387 os_temp = read_reg(cl, 3, 2);
388 if( hyst_temp < 0 || os_temp < 0 )
389 goto out;
390
391 printk("DS1775 digital thermometer [@%02x]\n", cl->addr );
392 print_temp("Temp: ", temp );
393 print_temp(" Hyst: ", hyst_temp );
394 print_temp(" OS: ", os_temp );
395 printk("\n");
396
397 x.temp = temp;
398 x.overheat_temp = os_temp;
399 x.overheat_hyst = hyst_temp;
Jean Delvare036533e2009-06-15 18:01:52 +0200400 x.thermostat = cl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return 0;
403}
404
Jean Delvare036533e2009-06-15 18:01:52 +0200405enum chip { ds1775, adm1030 };
406
407static const struct i2c_device_id therm_windtunnel_id[] = {
Wolfram Sang38b17af2020-02-25 15:12:29 +0100408 { "MAC,ds1775", ds1775 },
409 { "MAC,adm1030", adm1030 },
Jean Delvare036533e2009-06-15 18:01:52 +0200410 { }
411};
Javier Martinez Canillascb0eefc2015-07-30 18:18:30 +0200412MODULE_DEVICE_TABLE(i2c, therm_windtunnel_id);
Jean Delvare036533e2009-06-15 18:01:52 +0200413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414static int
Jean Delvare036533e2009-06-15 18:01:52 +0200415do_probe(struct i2c_client *cl, const struct i2c_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Jean Delvare036533e2009-06-15 18:01:52 +0200417 struct i2c_adapter *adapter = cl->adapter;
Wolfram Sang38b17af2020-02-25 15:12:29 +0100418 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 if( !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA
421 | I2C_FUNC_SMBUS_WRITE_BYTE) )
422 return 0;
423
Jean Delvare036533e2009-06-15 18:01:52 +0200424 switch (id->driver_data) {
425 case adm1030:
Wolfram Sang38b17af2020-02-25 15:12:29 +0100426 ret = attach_fan(cl);
427 break;
Jean Delvare036533e2009-06-15 18:01:52 +0200428 case ds1775:
Wolfram Sang38b17af2020-02-25 15:12:29 +0100429 ret = attach_thermostat(cl);
430 break;
Jean Delvare036533e2009-06-15 18:01:52 +0200431 }
Wolfram Sang38b17af2020-02-25 15:12:29 +0100432
433 if (!x.running && x.thermostat && x.fan) {
434 x.running = 1;
435 x.poll_task = kthread_run(control_loop, NULL, "g4fand");
436 }
437
438 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
Jean Delvare036533e2009-06-15 18:01:52 +0200441static struct i2c_driver g4fan_driver = {
442 .driver = {
443 .name = "therm_windtunnel",
444 },
Jean Delvare036533e2009-06-15 18:01:52 +0200445 .probe = do_probe,
446 .remove = do_remove,
447 .id_table = therm_windtunnel_id,
448};
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/************************************************************************/
452/* initialization / cleanup */
453/************************************************************************/
454
Grant Likely00006122011-02-22 19:59:54 -0700455static int therm_of_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Wolfram Sang3e7bed52018-08-21 17:02:39 +0200457 struct i2c_adapter *adap;
458 int ret, i = 0;
459
460 adap = i2c_get_adapter(0);
461 if (!adap)
462 return -EPROBE_DEFER;
463
464 ret = i2c_add_driver(&g4fan_driver);
465 if (ret) {
466 i2c_put_adapter(adap);
467 return ret;
468 }
469
470 /* We assume Macs have consecutive I2C bus numbers starting at 0 */
471 while (adap) {
472 do_attach(adap);
473 if (x.running)
474 return 0;
475 i2c_put_adapter(adap);
476 adap = i2c_get_adapter(++i);
477 }
478
479 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
482static int
Grant Likely2dc11582010-08-06 09:25:50 -0600483therm_of_remove( struct platform_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Jean Delvareb3e82092007-05-01 23:26:32 +0200485 i2c_del_driver( &g4fan_driver );
486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
Márton Németh46759a72010-01-10 01:43:14 +0000489static const struct of_device_id therm_of_match[] = {{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .name = "fan",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 .compatible = "adm1030"
492 }, {}
493};
Javier Martinez Canillasa1a42b72015-07-30 18:18:47 +0200494MODULE_DEVICE_TABLE(of, therm_of_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Grant Likely00006122011-02-22 19:59:54 -0700496static struct platform_driver therm_of_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700497 .driver = {
498 .name = "temperature",
Grant Likely40182942010-04-13 16:13:02 -0700499 .of_match_table = therm_of_match,
500 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .probe = therm_of_probe,
502 .remove = therm_of_remove,
503};
504
505struct apple_thermal_info {
506 u8 id; /* implementation ID */
507 u8 fan_count; /* number of fans */
508 u8 thermostat_count; /* number of thermostats */
509 u8 unused;
510};
511
512static int __init
513g4fan_init( void )
514{
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000515 const struct apple_thermal_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 struct device_node *np;
517
Daniel Walker1baaeea2008-06-10 09:26:08 +1000518 mutex_init(&x.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 if( !(np=of_find_node_by_name(NULL, "power-mgt")) )
521 return -ENODEV;
Stephen Rothwell01b27262007-04-27 13:41:15 +1000522 info = of_get_property(np, "thermal-info", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 of_node_put(np);
524
Grant Likely71a157e2010-02-01 21:34:14 -0700525 if( !info || !of_machine_is_compatible("PowerMac3,6") )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return -ENODEV;
527
528 if( info->id != 3 ) {
529 printk(KERN_ERR "therm_windtunnel: unsupported thermal design %d\n", info->id );
530 return -ENODEV;
531 }
532 if( !(np=of_find_node_by_name(NULL, "fan")) )
533 return -ENODEV;
Benjamin Herrenschmidt0365ba72005-09-22 21:44:06 -0700534 x.of_dev = of_platform_device_create(np, "temperature", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 of_node_put( np );
536
537 if( !x.of_dev ) {
538 printk(KERN_ERR "Can't register fan controller!\n");
539 return -ENODEV;
540 }
541
Grant Likely00006122011-02-22 19:59:54 -0700542 platform_driver_register( &therm_of_driver );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return 0;
544}
545
546static void __exit
547g4fan_exit( void )
548{
Grant Likely00006122011-02-22 19:59:54 -0700549 platform_driver_unregister( &therm_of_driver );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 if( x.of_dev )
552 of_device_unregister( x.of_dev );
553}
554
555module_init(g4fan_init);
556module_exit(g4fan_exit);
557
558MODULE_AUTHOR("Samuel Rydh <samuel@ibrium.se>");
559MODULE_DESCRIPTION("Apple G4 (windtunnel) fan controller");
560MODULE_LICENSE("GPL");