therm_adt746x.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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/wait.h>
  22. #include <linux/suspend.h>
  23. #include <linux/kthread.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/freezer.h>
  26. #include <linux/of_platform.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. #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];
  45. static int limit_adjust;
  46. static int fan_speed = -1;
  47. static int verbose;
  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. set_freezable();
  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 = kzalloc(sizeof(struct thermostat), GFP_KERNEL);
  315. if (!th)
  316. return -ENOMEM;
  317. th->clt.addr = addr;
  318. th->clt.adapter = adapter;
  319. th->clt.driver = &thermostat_driver;
  320. strcpy(th->clt.name, "thermostat");
  321. rc = read_reg(th, 0);
  322. if (rc < 0) {
  323. printk(KERN_ERR "adt746x: Thermostat failed to read config "
  324. "from bus %d !\n",
  325. busno);
  326. kfree(th);
  327. return -ENODEV;
  328. }
  329. /* force manual control to start the fan quieter */
  330. if (fan_speed == -1)
  331. fan_speed = 64;
  332. if(therm_type == ADT7460) {
  333. printk(KERN_INFO "adt746x: ADT7460 initializing\n");
  334. /* The 7460 needs to be started explicitly */
  335. write_reg(th, CONFIG_REG, 1);
  336. } else
  337. printk(KERN_INFO "adt746x: ADT7467 initializing\n");
  338. for (i = 0; i < 3; i++) {
  339. th->initial_limits[i] = read_reg(th, LIMIT_REG[i]);
  340. set_limit(th, i);
  341. }
  342. printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d"
  343. " to %d, %d, %d\n",
  344. th->initial_limits[0], th->initial_limits[1],
  345. th->initial_limits[2], th->limits[0], th->limits[1],
  346. th->limits[2]);
  347. thermostat = th;
  348. if (i2c_attach_client(&th->clt)) {
  349. printk(KERN_INFO "adt746x: Thermostat failed to attach "
  350. "client !\n");
  351. thermostat = NULL;
  352. kfree(th);
  353. return -ENODEV;
  354. }
  355. /* be sure to really write fan speed the first time */
  356. th->last_speed[0] = -2;
  357. th->last_speed[1] = -2;
  358. th->last_var[0] = -80;
  359. th->last_var[1] = -80;
  360. if (fan_speed != -1) {
  361. /* manual mode, stop fans */
  362. write_both_fan_speed(th, 0);
  363. } else {
  364. /* automatic mode */
  365. write_both_fan_speed(th, -1);
  366. }
  367. thread_therm = kthread_run(monitor_task, th, "kfand");
  368. if (thread_therm == ERR_PTR(-ENOMEM)) {
  369. printk(KERN_INFO "adt746x: Kthread creation failed\n");
  370. thread_therm = NULL;
  371. return -ENOMEM;
  372. }
  373. return 0;
  374. }
  375. /*
  376. * Now, unfortunately, sysfs doesn't give us a nice void * we could
  377. * pass around to the attribute functions, so we don't really have
  378. * choice but implement a bunch of them...
  379. *
  380. * FIXME, it does now...
  381. */
  382. #define BUILD_SHOW_FUNC_INT(name, data) \
  383. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  384. { \
  385. return sprintf(buf, "%d\n", data); \
  386. }
  387. #define BUILD_SHOW_FUNC_STR(name, data) \
  388. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  389. { \
  390. return sprintf(buf, "%s\n", data); \
  391. }
  392. #define BUILD_SHOW_FUNC_FAN(name, data) \
  393. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  394. { \
  395. return sprintf(buf, "%d (%d rpm)\n", \
  396. thermostat->last_speed[data], \
  397. read_fan_speed(thermostat, FAN_SPEED[data]) \
  398. ); \
  399. }
  400. #define BUILD_STORE_FUNC_DEG(name, data) \
  401. static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
  402. { \
  403. int val; \
  404. int i; \
  405. val = simple_strtol(buf, NULL, 10); \
  406. printk(KERN_INFO "Adjusting limits by %d degrees\n", val); \
  407. limit_adjust = val; \
  408. for (i=0; i < 3; i++) \
  409. set_limit(thermostat, i); \
  410. return n; \
  411. }
  412. #define BUILD_STORE_FUNC_INT(name, data) \
  413. static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
  414. { \
  415. u32 val; \
  416. val = simple_strtoul(buf, NULL, 10); \
  417. if (val < 0 || val > 255) \
  418. return -EINVAL; \
  419. printk(KERN_INFO "Setting specified fan speed to %d\n", val); \
  420. data = val; \
  421. return n; \
  422. }
  423. BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(thermostat, TEMP_REG[1])))
  424. BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(thermostat, TEMP_REG[2])))
  425. BUILD_SHOW_FUNC_INT(sensor1_limit, thermostat->limits[1])
  426. BUILD_SHOW_FUNC_INT(sensor2_limit, thermostat->limits[2])
  427. BUILD_SHOW_FUNC_STR(sensor1_location, sensor_location[1])
  428. BUILD_SHOW_FUNC_STR(sensor2_location, sensor_location[2])
  429. BUILD_SHOW_FUNC_INT(specified_fan_speed, fan_speed)
  430. BUILD_SHOW_FUNC_FAN(sensor1_fan_speed, 0)
  431. BUILD_SHOW_FUNC_FAN(sensor2_fan_speed, 1)
  432. BUILD_STORE_FUNC_INT(specified_fan_speed,fan_speed)
  433. BUILD_SHOW_FUNC_INT(limit_adjust, limit_adjust)
  434. BUILD_STORE_FUNC_DEG(limit_adjust, thermostat)
  435. static DEVICE_ATTR(sensor1_temperature, S_IRUGO,
  436. show_sensor1_temperature,NULL);
  437. static DEVICE_ATTR(sensor2_temperature, S_IRUGO,
  438. show_sensor2_temperature,NULL);
  439. static DEVICE_ATTR(sensor1_limit, S_IRUGO,
  440. show_sensor1_limit, NULL);
  441. static DEVICE_ATTR(sensor2_limit, S_IRUGO,
  442. show_sensor2_limit, NULL);
  443. static DEVICE_ATTR(sensor1_location, S_IRUGO,
  444. show_sensor1_location, NULL);
  445. static DEVICE_ATTR(sensor2_location, S_IRUGO,
  446. show_sensor2_location, NULL);
  447. static DEVICE_ATTR(specified_fan_speed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
  448. show_specified_fan_speed,store_specified_fan_speed);
  449. static DEVICE_ATTR(sensor1_fan_speed, S_IRUGO,
  450. show_sensor1_fan_speed, NULL);
  451. static DEVICE_ATTR(sensor2_fan_speed, S_IRUGO,
  452. show_sensor2_fan_speed, NULL);
  453. static DEVICE_ATTR(limit_adjust, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
  454. show_limit_adjust, store_limit_adjust);
  455. static int __init
  456. thermostat_init(void)
  457. {
  458. struct device_node* np;
  459. const u32 *prop;
  460. int i = 0, offset = 0;
  461. int err;
  462. np = of_find_node_by_name(NULL, "fan");
  463. if (!np)
  464. return -ENODEV;
  465. if (of_device_is_compatible(np, "adt7460"))
  466. therm_type = ADT7460;
  467. else if (of_device_is_compatible(np, "adt7467"))
  468. therm_type = ADT7467;
  469. else {
  470. of_node_put(np);
  471. return -ENODEV;
  472. }
  473. prop = of_get_property(np, "hwsensor-params-version", NULL);
  474. printk(KERN_INFO "adt746x: version %d (%ssupported)\n", *prop,
  475. (*prop == 1)?"":"un");
  476. if (*prop != 1) {
  477. of_node_put(np);
  478. return -ENODEV;
  479. }
  480. prop = of_get_property(np, "reg", NULL);
  481. if (!prop) {
  482. of_node_put(np);
  483. return -ENODEV;
  484. }
  485. /* look for bus either by path or using "reg" */
  486. if (strstr(np->full_name, "/i2c-bus@") != NULL) {
  487. const char *tmp_bus = (strstr(np->full_name, "/i2c-bus@") + 9);
  488. therm_bus = tmp_bus[0]-'0';
  489. } else {
  490. therm_bus = ((*prop) >> 8) & 0x0f;
  491. }
  492. therm_address = ((*prop) & 0xff) >> 1;
  493. printk(KERN_INFO "adt746x: Thermostat bus: %d, address: 0x%02x, "
  494. "limit_adjust: %d, fan_speed: %d\n",
  495. therm_bus, therm_address, limit_adjust, fan_speed);
  496. if (of_get_property(np, "hwsensor-location", NULL)) {
  497. for (i = 0; i < 3; i++) {
  498. sensor_location[i] = of_get_property(np,
  499. "hwsensor-location", NULL) + offset;
  500. if (sensor_location[i] == NULL)
  501. sensor_location[i] = "";
  502. printk(KERN_INFO "sensor %d: %s\n", i, sensor_location[i]);
  503. offset += strlen(sensor_location[i]) + 1;
  504. }
  505. } else {
  506. sensor_location[0] = "?";
  507. sensor_location[1] = "?";
  508. sensor_location[2] = "?";
  509. }
  510. of_dev = of_platform_device_create(np, "temperatures", NULL);
  511. if (of_dev == NULL) {
  512. printk(KERN_ERR "Can't register temperatures device !\n");
  513. of_node_put(np);
  514. return -ENODEV;
  515. }
  516. err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature);
  517. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature);
  518. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit);
  519. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_limit);
  520. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_location);
  521. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_location);
  522. err |= device_create_file(&of_dev->dev, &dev_attr_limit_adjust);
  523. err |= device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed);
  524. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
  525. if(therm_type == ADT7460)
  526. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed);
  527. if (err)
  528. printk(KERN_WARNING
  529. "Failed to create tempertaure attribute file(s).\n");
  530. #ifndef CONFIG_I2C_POWERMAC
  531. request_module("i2c-powermac");
  532. #endif
  533. return i2c_add_driver(&thermostat_driver);
  534. }
  535. static void __exit
  536. thermostat_exit(void)
  537. {
  538. if (of_dev) {
  539. device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature);
  540. device_remove_file(&of_dev->dev, &dev_attr_sensor2_temperature);
  541. device_remove_file(&of_dev->dev, &dev_attr_sensor1_limit);
  542. device_remove_file(&of_dev->dev, &dev_attr_sensor2_limit);
  543. device_remove_file(&of_dev->dev, &dev_attr_sensor1_location);
  544. device_remove_file(&of_dev->dev, &dev_attr_sensor2_location);
  545. device_remove_file(&of_dev->dev, &dev_attr_limit_adjust);
  546. device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed);
  547. device_remove_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
  548. if(therm_type == ADT7460)
  549. device_remove_file(&of_dev->dev,
  550. &dev_attr_sensor2_fan_speed);
  551. of_device_unregister(of_dev);
  552. }
  553. i2c_del_driver(&thermostat_driver);
  554. }
  555. module_init(thermostat_init);
  556. module_exit(thermostat_exit);