therm_adt746x.c 17 KB

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