therm_adt746x.c 17 KB

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