therm_adt746x: Convert to a new-style i2c driver
[pandora-kernel.git] / drivers / macintosh / therm_adt746x.c
1 /*
2  * Device driver for the i2c thermostat found on the iBook G4, Albook G4
3  *
4  * Copyright (C) 2003, 2004 Colin Leroy, Rasmus Rohde, Benjamin Herrenschmidt
5  *
6  * Documentation from
7  * http://www.analog.com/UploadedFiles/Data_Sheets/115254175ADT7467_pra.pdf
8  * http://www.analog.com/UploadedFiles/Data_Sheets/3686221171167ADT7460_b.pdf
9  *
10  */
11
12 #include <linux/types.h>
13 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/delay.h>
17 #include <linux/sched.h>
18 #include <linux/i2c.h>
19 #include <linux/slab.h>
20 #include <linux/init.h>
21 #include <linux/spinlock.h>
22 #include <linux/wait.h>
23 #include <linux/suspend.h>
24 #include <linux/kthread.h>
25 #include <linux/moduleparam.h>
26 #include <linux/freezer.h>
27 #include <linux/of_platform.h>
28
29 #include <asm/prom.h>
30 #include <asm/machdep.h>
31 #include <asm/io.h>
32 #include <asm/system.h>
33 #include <asm/sections.h>
34
35 #undef DEBUG
36
37 #define CONFIG_REG   0x40
38 #define MANUAL_MASK  0xe0
39 #define AUTO_MASK    0x20
40
41 static u8 TEMP_REG[3]    = {0x26, 0x25, 0x27}; /* local, sensor1, sensor2 */
42 static u8 LIMIT_REG[3]   = {0x6b, 0x6a, 0x6c}; /* local, sensor1, sensor2 */
43 static u8 MANUAL_MODE[2] = {0x5c, 0x5d};       
44 static u8 REM_CONTROL[2] = {0x00, 0x40};
45 static u8 FAN_SPEED[2]   = {0x28, 0x2a};
46 static u8 FAN_SPD_SET[2] = {0x30, 0x31};
47
48 static u8 default_limits_local[3] = {70, 50, 70};    /* local, sensor1, sensor2 */
49 static u8 default_limits_chip[3] = {80, 65, 80};    /* local, sensor1, sensor2 */
50 static const char *sensor_location[3];
51
52 static int limit_adjust;
53 static int fan_speed = -1;
54 static int verbose;
55
56 MODULE_AUTHOR("Colin Leroy <colin@colino.net>");
57 MODULE_DESCRIPTION("Driver for ADT746x thermostat in iBook G4 and "
58                    "Powerbook G4 Alu");
59 MODULE_LICENSE("GPL");
60
61 module_param(limit_adjust, int, 0644);
62 MODULE_PARM_DESC(limit_adjust,"Adjust maximum temperatures (50 sensor1, 70 sensor2) "
63                  "by N degrees.");
64
65 module_param(fan_speed, int, 0644);
66 MODULE_PARM_DESC(fan_speed,"Specify starting fan speed (0-255) "
67                  "(default 64)");
68
69 module_param(verbose, bool, 0);
70 MODULE_PARM_DESC(verbose,"Verbose log operations "
71                  "(default 0)");
72
73 struct thermostat {
74         struct i2c_client       *clt;
75         u8                      temps[3];
76         u8                      cached_temp[3];
77         u8                      initial_limits[3];
78         u8                      limits[3];
79         int                     last_speed[2];
80         int                     last_var[2];
81 };
82
83 static enum {ADT7460, ADT7467} therm_type;
84 static int therm_bus, therm_address;
85 static struct of_device * of_dev;
86 static struct thermostat* thermostat;
87 static struct task_struct *thread_therm = NULL;
88
89 static void write_both_fan_speed(struct thermostat *th, int speed);
90 static void write_fan_speed(struct thermostat *th, int speed, int fan);
91
92 static int
93 write_reg(struct thermostat* th, int reg, u8 data)
94 {
95         u8 tmp[2];
96         int rc;
97         
98         tmp[0] = reg;
99         tmp[1] = data;
100         rc = i2c_master_send(th->clt, (const char *)tmp, 2);
101         if (rc < 0)
102                 return rc;
103         if (rc != 2)
104                 return -ENODEV;
105         return 0;
106 }
107
108 static int
109 read_reg(struct thermostat* th, int reg)
110 {
111         u8 reg_addr, data;
112         int rc;
113
114         reg_addr = (u8)reg;
115         rc = i2c_master_send(th->clt, &reg_addr, 1);
116         if (rc < 0)
117                 return rc;
118         if (rc != 1)
119                 return -ENODEV;
120         rc = i2c_master_recv(th->clt, (char *)&data, 1);
121         if (rc < 0)
122                 return rc;
123         return data;
124 }
125
126 static int
127 attach_thermostat(struct i2c_adapter *adapter)
128 {
129         unsigned long bus_no;
130         struct i2c_board_info info;
131         struct i2c_client *client;
132
133         if (strncmp(adapter->name, "uni-n", 5))
134                 return -ENODEV;
135         bus_no = simple_strtoul(adapter->name + 6, NULL, 10);
136         if (bus_no != therm_bus)
137                 return -ENODEV;
138
139         memset(&info, 0, sizeof(struct i2c_board_info));
140         strlcpy(info.type, "therm_adt746x", I2C_NAME_SIZE);
141         info.addr = therm_address;
142         client = i2c_new_device(adapter, &info);
143         if (!client)
144                 return -ENODEV;
145
146         /*
147          * Let i2c-core delete that device on driver removal.
148          * This is safe because i2c-core holds the core_lock mutex for us.
149          */
150         list_add_tail(&client->detected, &client->driver->clients);
151         return 0;
152 }
153
154 static int
155 remove_thermostat(struct i2c_client *client)
156 {
157         struct thermostat *th = i2c_get_clientdata(client);
158         int i;
159         
160         if (thread_therm != NULL) {
161                 kthread_stop(thread_therm);
162         }
163
164         printk(KERN_INFO "adt746x: Putting max temperatures back from "
165                          "%d, %d, %d to %d, %d, %d\n",
166                 th->limits[0], th->limits[1], th->limits[2],
167                 th->initial_limits[0], th->initial_limits[1],
168                 th->initial_limits[2]);
169
170         for (i = 0; i < 3; i++)
171                 write_reg(th, LIMIT_REG[i], th->initial_limits[i]);
172
173         write_both_fan_speed(th, -1);
174
175         thermostat = NULL;
176
177         kfree(th);
178
179         return 0;
180 }
181
182 static int read_fan_speed(struct thermostat *th, u8 addr)
183 {
184         u8 tmp[2];
185         u16 res;
186         
187         /* should start with low byte */
188         tmp[1] = read_reg(th, addr);
189         tmp[0] = read_reg(th, addr + 1);
190         
191         res = tmp[1] + (tmp[0] << 8);
192         /* "a value of 0xffff means that the fan has stopped" */
193         return (res == 0xffff ? 0 : (90000*60)/res);
194 }
195
196 static void write_both_fan_speed(struct thermostat *th, int speed)
197 {
198         write_fan_speed(th, speed, 0);
199         if (therm_type == ADT7460)
200                 write_fan_speed(th, speed, 1);
201 }
202
203 static void write_fan_speed(struct thermostat *th, int speed, int fan)
204 {
205         u8 manual;
206         
207         if (speed > 0xff) 
208                 speed = 0xff;
209         else if (speed < -1) 
210                 speed = 0;
211         
212         if (therm_type == ADT7467 && fan == 1)
213                 return;
214         
215         if (th->last_speed[fan] != speed) {
216                 if (verbose) {
217                         if (speed == -1)
218                                 printk(KERN_DEBUG "adt746x: Setting speed to automatic "
219                                         "for %s fan.\n", sensor_location[fan+1]);
220                         else
221                                 printk(KERN_DEBUG "adt746x: Setting speed to %d "
222                                         "for %s fan.\n", speed, sensor_location[fan+1]);
223                 }
224         } else
225                 return;
226         
227         if (speed >= 0) {
228                 manual = read_reg(th, MANUAL_MODE[fan]);
229                 write_reg(th, MANUAL_MODE[fan], manual|MANUAL_MASK);
230                 write_reg(th, FAN_SPD_SET[fan], speed);
231         } else {
232                 /* back to automatic */
233                 if(therm_type == ADT7460) {
234                         manual = read_reg(th,
235                                 MANUAL_MODE[fan]) & (~MANUAL_MASK);
236
237                         write_reg(th,
238                                 MANUAL_MODE[fan], manual|REM_CONTROL[fan]);
239                 } else {
240                         manual = read_reg(th, MANUAL_MODE[fan]);
241                         write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK));
242                 }
243         }
244         
245         th->last_speed[fan] = speed;                    
246 }
247
248 static void read_sensors(struct thermostat *th)
249 {
250         int i = 0;
251
252         for (i = 0; i < 3; i++)
253                 th->temps[i]  = read_reg(th, TEMP_REG[i]);
254 }
255
256 #ifdef DEBUG
257 static void display_stats(struct thermostat *th)
258 {
259         if (th->temps[0] != th->cached_temp[0]
260         ||  th->temps[1] != th->cached_temp[1]
261         ||  th->temps[2] != th->cached_temp[2]) {
262                 printk(KERN_INFO "adt746x: Temperature infos:"
263                                  " thermostats: %d,%d,%d;"
264                                  " limits: %d,%d,%d;"
265                                  " fan speed: %d RPM\n",
266                                  th->temps[0], th->temps[1], th->temps[2],
267                                  th->limits[0],  th->limits[1],  th->limits[2],
268                                  read_fan_speed(th, FAN_SPEED[0]));
269         }
270         th->cached_temp[0] = th->temps[0];
271         th->cached_temp[1] = th->temps[1];
272         th->cached_temp[2] = th->temps[2];
273 }
274 #endif
275
276 static void update_fans_speed (struct thermostat *th)
277 {
278         int lastvar = 0; /* last variation, for iBook */
279         int i = 0;
280
281         /* we don't care about local sensor, so we start at sensor 1 */
282         for (i = 1; i < 3; i++) {
283                 int started = 0;
284                 int fan_number = (therm_type == ADT7460 && i == 2);
285                 int var = th->temps[i] - th->limits[i];
286
287                 if (var > -1) {
288                         int step = (255 - fan_speed) / 7;
289                         int new_speed = 0;
290
291                         /* hysteresis : change fan speed only if variation is
292                          * more than two degrees */
293                         if (abs(var - th->last_var[fan_number]) < 2)
294                                 continue;
295
296                         started = 1;
297                         new_speed = fan_speed + ((var-1)*step);
298
299                         if (new_speed < fan_speed)
300                                 new_speed = fan_speed;
301                         if (new_speed > 255)
302                                 new_speed = 255;
303
304                         if (verbose)
305                                 printk(KERN_DEBUG "adt746x: Setting fans speed to %d "
306                                                  "(limit exceeded by %d on %s) \n",
307                                                 new_speed, var,
308                                                 sensor_location[fan_number+1]);
309                         write_both_fan_speed(th, new_speed);
310                         th->last_var[fan_number] = var;
311                 } else if (var < -2) {
312                         /* don't stop fan if sensor2 is cold and sensor1 is not
313                          * so cold (lastvar >= -1) */
314                         if (i == 2 && lastvar < -1) {
315                                 if (th->last_speed[fan_number] != 0)
316                                         if (verbose)
317                                                 printk(KERN_DEBUG "adt746x: Stopping "
318                                                         "fans.\n");
319                                 write_both_fan_speed(th, 0);
320                         }
321                 }
322
323                 lastvar = var;
324
325                 if (started)
326                         return; /* we don't want to re-stop the fan
327                                 * if sensor1 is heating and sensor2 is not */
328         }
329 }
330
331 static int monitor_task(void *arg)
332 {
333         struct thermostat* th = arg;
334
335         set_freezable();
336         while(!kthread_should_stop()) {
337                 try_to_freeze();
338                 msleep_interruptible(2000);
339
340 #ifndef DEBUG
341                 if (fan_speed != -1)
342                         read_sensors(th);
343 #else
344                 read_sensors(th);
345 #endif          
346
347                 if (fan_speed != -1)
348                         update_fans_speed(th);
349
350 #ifdef DEBUG
351                 display_stats(th);
352 #endif
353
354         }
355
356         return 0;
357 }
358
359 static void set_limit(struct thermostat *th, int i)
360 {
361                 /* Set sensor1 limit higher to avoid powerdowns */
362                 th->limits[i] = default_limits_chip[i] + limit_adjust;
363                 write_reg(th, LIMIT_REG[i], th->limits[i]);
364                 
365                 /* set our limits to normal */
366                 th->limits[i] = default_limits_local[i] + limit_adjust;
367 }
368
369 static int probe_thermostat(struct i2c_client *client,
370                             const struct i2c_device_id *id)
371 {
372         struct thermostat* th;
373         int rc;
374         int i;
375
376         if (thermostat)
377                 return 0;
378
379         th = kzalloc(sizeof(struct thermostat), GFP_KERNEL);
380         if (!th)
381                 return -ENOMEM;
382
383         i2c_set_clientdata(client, th);
384         th->clt = client;
385
386         rc = read_reg(th, 0);
387         if (rc < 0) {
388                 dev_err(&client->dev, "Thermostat failed to read config!\n");
389                 kfree(th);
390                 return -ENODEV;
391         }
392
393         /* force manual control to start the fan quieter */
394         if (fan_speed == -1)
395                 fan_speed = 64;
396         
397         if(therm_type == ADT7460) {
398                 printk(KERN_INFO "adt746x: ADT7460 initializing\n");
399                 /* The 7460 needs to be started explicitly */
400                 write_reg(th, CONFIG_REG, 1);
401         } else
402                 printk(KERN_INFO "adt746x: ADT7467 initializing\n");
403
404         for (i = 0; i < 3; i++) {
405                 th->initial_limits[i] = read_reg(th, LIMIT_REG[i]);
406                 set_limit(th, i);
407         }
408
409         printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d"
410                          " to %d, %d, %d\n",
411                          th->initial_limits[0], th->initial_limits[1],
412                          th->initial_limits[2], th->limits[0], th->limits[1],
413                          th->limits[2]);
414
415         thermostat = th;
416
417         /* be sure to really write fan speed the first time */
418         th->last_speed[0] = -2;
419         th->last_speed[1] = -2;
420         th->last_var[0] = -80;
421         th->last_var[1] = -80;
422
423         if (fan_speed != -1) {
424                 /* manual mode, stop fans */
425                 write_both_fan_speed(th, 0);
426         } else {
427                 /* automatic mode */
428                 write_both_fan_speed(th, -1);
429         }
430         
431         thread_therm = kthread_run(monitor_task, th, "kfand");
432
433         if (thread_therm == ERR_PTR(-ENOMEM)) {
434                 printk(KERN_INFO "adt746x: Kthread creation failed\n");
435                 thread_therm = NULL;
436                 return -ENOMEM;
437         }
438
439         return 0;
440 }
441
442 static const struct i2c_device_id therm_adt746x_id[] = {
443         { "therm_adt746x", 0 },
444         { }
445 };
446
447 static struct i2c_driver thermostat_driver = {
448         .driver = {
449                 .name   = "therm_adt746x",
450         },
451         .attach_adapter = attach_thermostat,
452         .probe = probe_thermostat,
453         .remove = remove_thermostat,
454         .id_table = therm_adt746x_id,
455 };
456
457 /* 
458  * Now, unfortunately, sysfs doesn't give us a nice void * we could
459  * pass around to the attribute functions, so we don't really have
460  * choice but implement a bunch of them...
461  *
462  * FIXME, it does now...
463  */
464 #define BUILD_SHOW_FUNC_INT(name, data)                         \
465 static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf)        \
466 {                                                               \
467         return sprintf(buf, "%d\n", data);                      \
468 }
469
470 #define BUILD_SHOW_FUNC_STR(name, data)                         \
471 static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf)       \
472 {                                                               \
473         return sprintf(buf, "%s\n", data);                      \
474 }
475
476 #define BUILD_SHOW_FUNC_FAN(name, data)                         \
477 static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf)       \
478 {                                                               \
479         return sprintf(buf, "%d (%d rpm)\n",                    \
480                 thermostat->last_speed[data],                   \
481                 read_fan_speed(thermostat, FAN_SPEED[data])     \
482                 );                                              \
483 }
484
485 #define BUILD_STORE_FUNC_DEG(name, data)                        \
486 static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
487 {                                                               \
488         int val;                                                \
489         int i;                                                  \
490         val = simple_strtol(buf, NULL, 10);                     \
491         printk(KERN_INFO "Adjusting limits by %d degrees\n", val);      \
492         limit_adjust = val;                                     \
493         for (i=0; i < 3; i++)                                   \
494                 set_limit(thermostat, i);                       \
495         return n;                                               \
496 }
497
498 #define BUILD_STORE_FUNC_INT(name, data)                        \
499 static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
500 {                                                               \
501         int val;                                                \
502         val = simple_strtol(buf, NULL, 10);                     \
503         if (val < 0 || val > 255)                               \
504                 return -EINVAL;                                 \
505         printk(KERN_INFO "Setting specified fan speed to %d\n", val);   \
506         data = val;                                             \
507         return n;                                               \
508 }
509
510 BUILD_SHOW_FUNC_INT(sensor1_temperature,         (read_reg(thermostat, TEMP_REG[1])))
511 BUILD_SHOW_FUNC_INT(sensor2_temperature,         (read_reg(thermostat, TEMP_REG[2])))
512 BUILD_SHOW_FUNC_INT(sensor1_limit,               thermostat->limits[1])
513 BUILD_SHOW_FUNC_INT(sensor2_limit,               thermostat->limits[2])
514 BUILD_SHOW_FUNC_STR(sensor1_location,            sensor_location[1])
515 BUILD_SHOW_FUNC_STR(sensor2_location,            sensor_location[2])
516
517 BUILD_SHOW_FUNC_INT(specified_fan_speed, fan_speed)
518 BUILD_SHOW_FUNC_FAN(sensor1_fan_speed,   0)
519 BUILD_SHOW_FUNC_FAN(sensor2_fan_speed,   1)
520
521 BUILD_STORE_FUNC_INT(specified_fan_speed,fan_speed)
522 BUILD_SHOW_FUNC_INT(limit_adjust,        limit_adjust)
523 BUILD_STORE_FUNC_DEG(limit_adjust,       thermostat)
524                 
525 static DEVICE_ATTR(sensor1_temperature, S_IRUGO,
526                    show_sensor1_temperature,NULL);
527 static DEVICE_ATTR(sensor2_temperature, S_IRUGO,
528                    show_sensor2_temperature,NULL);
529 static DEVICE_ATTR(sensor1_limit, S_IRUGO,
530                    show_sensor1_limit,  NULL);
531 static DEVICE_ATTR(sensor2_limit, S_IRUGO,
532                    show_sensor2_limit,  NULL);
533 static DEVICE_ATTR(sensor1_location, S_IRUGO,
534                    show_sensor1_location, NULL);
535 static DEVICE_ATTR(sensor2_location, S_IRUGO,
536                    show_sensor2_location, NULL);
537
538 static DEVICE_ATTR(specified_fan_speed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
539                    show_specified_fan_speed,store_specified_fan_speed);
540
541 static DEVICE_ATTR(sensor1_fan_speed,   S_IRUGO,
542                    show_sensor1_fan_speed,      NULL);
543 static DEVICE_ATTR(sensor2_fan_speed,   S_IRUGO,
544                    show_sensor2_fan_speed,      NULL);
545
546 static DEVICE_ATTR(limit_adjust,        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
547                    show_limit_adjust,   store_limit_adjust);
548
549
550 static int __init
551 thermostat_init(void)
552 {
553         struct device_node* np;
554         const u32 *prop;
555         int i = 0, offset = 0;
556         int err;
557
558         np = of_find_node_by_name(NULL, "fan");
559         if (!np)
560                 return -ENODEV;
561         if (of_device_is_compatible(np, "adt7460"))
562                 therm_type = ADT7460;
563         else if (of_device_is_compatible(np, "adt7467"))
564                 therm_type = ADT7467;
565         else {
566                 of_node_put(np);
567                 return -ENODEV;
568         }
569
570         prop = of_get_property(np, "hwsensor-params-version", NULL);
571         printk(KERN_INFO "adt746x: version %d (%ssupported)\n", *prop,
572                          (*prop == 1)?"":"un");
573         if (*prop != 1) {
574                 of_node_put(np);
575                 return -ENODEV;
576         }
577
578         prop = of_get_property(np, "reg", NULL);
579         if (!prop) {
580                 of_node_put(np);
581                 return -ENODEV;
582         }
583
584         /* look for bus either by path or using "reg" */
585         if (strstr(np->full_name, "/i2c-bus@") != NULL) {
586                 const char *tmp_bus = (strstr(np->full_name, "/i2c-bus@") + 9);
587                 therm_bus = tmp_bus[0]-'0';
588         } else {
589                 therm_bus = ((*prop) >> 8) & 0x0f;
590         }
591
592         therm_address = ((*prop) & 0xff) >> 1;
593
594         printk(KERN_INFO "adt746x: Thermostat bus: %d, address: 0x%02x, "
595                          "limit_adjust: %d, fan_speed: %d\n",
596                          therm_bus, therm_address, limit_adjust, fan_speed);
597
598         if (of_get_property(np, "hwsensor-location", NULL)) {
599                 for (i = 0; i < 3; i++) {
600                         sensor_location[i] = of_get_property(np,
601                                         "hwsensor-location", NULL) + offset;
602
603                         if (sensor_location[i] == NULL)
604                                 sensor_location[i] = "";
605
606                         printk(KERN_INFO "sensor %d: %s\n", i, sensor_location[i]);
607                         offset += strlen(sensor_location[i]) + 1;
608                 }
609         } else {
610                 sensor_location[0] = "?";
611                 sensor_location[1] = "?";
612                 sensor_location[2] = "?";
613         }
614
615         of_dev = of_platform_device_create(np, "temperatures", NULL);
616         of_node_put(np);
617
618         if (of_dev == NULL) {
619                 printk(KERN_ERR "Can't register temperatures device !\n");
620                 return -ENODEV;
621         }
622
623         err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature);
624         err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature);
625         err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit);
626         err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_limit);
627         err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_location);
628         err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_location);
629         err |= device_create_file(&of_dev->dev, &dev_attr_limit_adjust);
630         err |= device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed);
631         err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
632         if(therm_type == ADT7460)
633                 err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed);
634         if (err)
635                 printk(KERN_WARNING
636                         "Failed to create tempertaure attribute file(s).\n");
637
638 #ifndef CONFIG_I2C_POWERMAC
639         request_module("i2c-powermac");
640 #endif
641
642         return i2c_add_driver(&thermostat_driver);
643 }
644
645 static void __exit
646 thermostat_exit(void)
647 {
648         if (of_dev) {
649                 device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature);
650                 device_remove_file(&of_dev->dev, &dev_attr_sensor2_temperature);
651                 device_remove_file(&of_dev->dev, &dev_attr_sensor1_limit);
652                 device_remove_file(&of_dev->dev, &dev_attr_sensor2_limit);
653                 device_remove_file(&of_dev->dev, &dev_attr_sensor1_location);
654                 device_remove_file(&of_dev->dev, &dev_attr_sensor2_location);
655                 device_remove_file(&of_dev->dev, &dev_attr_limit_adjust);
656                 device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed);
657                 device_remove_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
658
659                 if(therm_type == ADT7460)
660                         device_remove_file(&of_dev->dev,
661                                            &dev_attr_sensor2_fan_speed);
662
663                 of_device_unregister(of_dev);
664         }
665         i2c_del_driver(&thermostat_driver);
666 }
667
668 module_init(thermostat_init);
669 module_exit(thermostat_exit);