therm_adt746x.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. #define INVERT_MASK 0x10
  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 const char *sensor_location[3];
  46. static int limit_adjust;
  47. static int fan_speed = -1;
  48. static int verbose;
  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. int pwm_inv[2];
  71. };
  72. static enum {ADT7460, ADT7467} therm_type;
  73. static int therm_bus, therm_address;
  74. static struct of_device * of_dev;
  75. static struct thermostat* thermostat;
  76. static struct task_struct *thread_therm = NULL;
  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 struct i2c_driver thermostat_driver;
  110. static int
  111. attach_thermostat(struct i2c_adapter *adapter)
  112. {
  113. unsigned long bus_no;
  114. struct i2c_board_info info;
  115. struct i2c_client *client;
  116. if (strncmp(adapter->name, "uni-n", 5))
  117. return -ENODEV;
  118. bus_no = simple_strtoul(adapter->name + 6, NULL, 10);
  119. if (bus_no != therm_bus)
  120. return -ENODEV;
  121. memset(&info, 0, sizeof(struct i2c_board_info));
  122. strlcpy(info.type, "therm_adt746x", I2C_NAME_SIZE);
  123. info.addr = therm_address;
  124. client = i2c_new_device(adapter, &info);
  125. if (!client)
  126. return -ENODEV;
  127. /*
  128. * Let i2c-core delete that device on driver removal.
  129. * This is safe because i2c-core holds the core_lock mutex for us.
  130. */
  131. list_add_tail(&client->detected, &thermostat_driver.clients);
  132. return 0;
  133. }
  134. static int
  135. remove_thermostat(struct i2c_client *client)
  136. {
  137. struct thermostat *th = i2c_get_clientdata(client);
  138. int i;
  139. if (thread_therm != NULL) {
  140. kthread_stop(thread_therm);
  141. }
  142. printk(KERN_INFO "adt746x: Putting max temperatures back from "
  143. "%d, %d, %d to %d, %d, %d\n",
  144. th->limits[0], th->limits[1], th->limits[2],
  145. th->initial_limits[0], th->initial_limits[1],
  146. th->initial_limits[2]);
  147. for (i = 0; i < 3; i++)
  148. write_reg(th, LIMIT_REG[i], th->initial_limits[i]);
  149. write_both_fan_speed(th, -1);
  150. thermostat = NULL;
  151. kfree(th);
  152. return 0;
  153. }
  154. static int read_fan_speed(struct thermostat *th, u8 addr)
  155. {
  156. u8 tmp[2];
  157. u16 res;
  158. /* should start with low byte */
  159. tmp[1] = read_reg(th, addr);
  160. tmp[0] = read_reg(th, addr + 1);
  161. res = tmp[1] + (tmp[0] << 8);
  162. /* "a value of 0xffff means that the fan has stopped" */
  163. return (res == 0xffff ? 0 : (90000*60)/res);
  164. }
  165. static void write_both_fan_speed(struct thermostat *th, int speed)
  166. {
  167. write_fan_speed(th, speed, 0);
  168. if (therm_type == ADT7460)
  169. write_fan_speed(th, speed, 1);
  170. }
  171. static void write_fan_speed(struct thermostat *th, int speed, int fan)
  172. {
  173. u8 manual;
  174. if (speed > 0xff)
  175. speed = 0xff;
  176. else if (speed < -1)
  177. speed = 0;
  178. if (therm_type == ADT7467 && fan == 1)
  179. return;
  180. if (th->last_speed[fan] != speed) {
  181. if (verbose) {
  182. if (speed == -1)
  183. printk(KERN_DEBUG "adt746x: Setting speed to automatic "
  184. "for %s fan.\n", sensor_location[fan+1]);
  185. else
  186. printk(KERN_DEBUG "adt746x: Setting speed to %d "
  187. "for %s fan.\n", speed, sensor_location[fan+1]);
  188. }
  189. } else
  190. return;
  191. if (speed >= 0) {
  192. manual = read_reg(th, MANUAL_MODE[fan]);
  193. manual &= ~INVERT_MASK;
  194. write_reg(th, MANUAL_MODE[fan],
  195. manual | MANUAL_MASK | th->pwm_inv[fan]);
  196. write_reg(th, FAN_SPD_SET[fan], speed);
  197. } else {
  198. /* back to automatic */
  199. if(therm_type == ADT7460) {
  200. manual = read_reg(th,
  201. MANUAL_MODE[fan]) & (~MANUAL_MASK);
  202. manual &= ~INVERT_MASK;
  203. manual |= th->pwm_inv[fan];
  204. write_reg(th,
  205. MANUAL_MODE[fan], manual|REM_CONTROL[fan]);
  206. } else {
  207. manual = read_reg(th, MANUAL_MODE[fan]);
  208. manual &= ~INVERT_MASK;
  209. manual |= th->pwm_inv[fan];
  210. write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK));
  211. }
  212. }
  213. th->last_speed[fan] = speed;
  214. }
  215. static void read_sensors(struct thermostat *th)
  216. {
  217. int i = 0;
  218. for (i = 0; i < 3; i++)
  219. th->temps[i] = read_reg(th, TEMP_REG[i]);
  220. }
  221. #ifdef DEBUG
  222. static void display_stats(struct thermostat *th)
  223. {
  224. if (th->temps[0] != th->cached_temp[0]
  225. || th->temps[1] != th->cached_temp[1]
  226. || th->temps[2] != th->cached_temp[2]) {
  227. printk(KERN_INFO "adt746x: Temperature infos:"
  228. " thermostats: %d,%d,%d;"
  229. " limits: %d,%d,%d;"
  230. " fan speed: %d RPM\n",
  231. th->temps[0], th->temps[1], th->temps[2],
  232. th->limits[0], th->limits[1], th->limits[2],
  233. read_fan_speed(th, FAN_SPEED[0]));
  234. }
  235. th->cached_temp[0] = th->temps[0];
  236. th->cached_temp[1] = th->temps[1];
  237. th->cached_temp[2] = th->temps[2];
  238. }
  239. #endif
  240. static void update_fans_speed (struct thermostat *th)
  241. {
  242. int lastvar = 0; /* last variation, for iBook */
  243. int i = 0;
  244. /* we don't care about local sensor, so we start at sensor 1 */
  245. for (i = 1; i < 3; i++) {
  246. int started = 0;
  247. int fan_number = (therm_type == ADT7460 && i == 2);
  248. int var = th->temps[i] - th->limits[i];
  249. if (var > -1) {
  250. int step = (255 - fan_speed) / 7;
  251. int new_speed = 0;
  252. /* hysteresis : change fan speed only if variation is
  253. * more than two degrees */
  254. if (abs(var - th->last_var[fan_number]) < 2)
  255. continue;
  256. started = 1;
  257. new_speed = fan_speed + ((var-1)*step);
  258. if (new_speed < fan_speed)
  259. new_speed = fan_speed;
  260. if (new_speed > 255)
  261. new_speed = 255;
  262. if (verbose)
  263. printk(KERN_DEBUG "adt746x: Setting fans speed to %d "
  264. "(limit exceeded by %d on %s) \n",
  265. new_speed, var,
  266. sensor_location[fan_number+1]);
  267. write_both_fan_speed(th, new_speed);
  268. th->last_var[fan_number] = var;
  269. } else if (var < -2) {
  270. /* don't stop fan if sensor2 is cold and sensor1 is not
  271. * so cold (lastvar >= -1) */
  272. if (i == 2 && lastvar < -1) {
  273. if (th->last_speed[fan_number] != 0)
  274. if (verbose)
  275. printk(KERN_DEBUG "adt746x: Stopping "
  276. "fans.\n");
  277. write_both_fan_speed(th, 0);
  278. }
  279. }
  280. lastvar = var;
  281. if (started)
  282. return; /* we don't want to re-stop the fan
  283. * if sensor1 is heating and sensor2 is not */
  284. }
  285. }
  286. static int monitor_task(void *arg)
  287. {
  288. struct thermostat* th = arg;
  289. set_freezable();
  290. while(!kthread_should_stop()) {
  291. try_to_freeze();
  292. msleep_interruptible(2000);
  293. #ifndef DEBUG
  294. if (fan_speed != -1)
  295. read_sensors(th);
  296. #else
  297. read_sensors(th);
  298. #endif
  299. if (fan_speed != -1)
  300. update_fans_speed(th);
  301. #ifdef DEBUG
  302. display_stats(th);
  303. #endif
  304. }
  305. return 0;
  306. }
  307. static void set_limit(struct thermostat *th, int i)
  308. {
  309. /* Set sensor1 limit higher to avoid powerdowns */
  310. th->limits[i] = default_limits_chip[i] + limit_adjust;
  311. write_reg(th, LIMIT_REG[i], th->limits[i]);
  312. /* set our limits to normal */
  313. th->limits[i] = default_limits_local[i] + limit_adjust;
  314. }
  315. static int probe_thermostat(struct i2c_client *client,
  316. const struct i2c_device_id *id)
  317. {
  318. struct thermostat* th;
  319. int rc;
  320. int i;
  321. if (thermostat)
  322. return 0;
  323. th = kzalloc(sizeof(struct thermostat), GFP_KERNEL);
  324. if (!th)
  325. return -ENOMEM;
  326. i2c_set_clientdata(client, th);
  327. th->clt = client;
  328. rc = read_reg(th, CONFIG_REG);
  329. if (rc < 0) {
  330. dev_err(&client->dev, "Thermostat failed to read config!\n");
  331. kfree(th);
  332. return -ENODEV;
  333. }
  334. /* force manual control to start the fan quieter */
  335. if (fan_speed == -1)
  336. fan_speed = 64;
  337. if(therm_type == ADT7460) {
  338. printk(KERN_INFO "adt746x: ADT7460 initializing\n");
  339. /* The 7460 needs to be started explicitly */
  340. write_reg(th, CONFIG_REG, 1);
  341. } else
  342. printk(KERN_INFO "adt746x: ADT7467 initializing\n");
  343. for (i = 0; i < 3; i++) {
  344. th->initial_limits[i] = read_reg(th, LIMIT_REG[i]);
  345. set_limit(th, i);
  346. }
  347. printk(KERN_INFO "adt746x: Lowering max temperatures from %d, %d, %d"
  348. " to %d, %d, %d\n",
  349. th->initial_limits[0], th->initial_limits[1],
  350. th->initial_limits[2], th->limits[0], th->limits[1],
  351. th->limits[2]);
  352. thermostat = th;
  353. /* record invert bit status because fw can corrupt it after suspend */
  354. th->pwm_inv[0] = read_reg(th, MANUAL_MODE[0]) & INVERT_MASK;
  355. th->pwm_inv[1] = read_reg(th, MANUAL_MODE[1]) & INVERT_MASK;
  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. static const struct i2c_device_id therm_adt746x_id[] = {
  377. { "therm_adt746x", 0 },
  378. { }
  379. };
  380. static struct i2c_driver thermostat_driver = {
  381. .driver = {
  382. .name = "therm_adt746x",
  383. },
  384. .attach_adapter = attach_thermostat,
  385. .probe = probe_thermostat,
  386. .remove = remove_thermostat,
  387. .id_table = therm_adt746x_id,
  388. };
  389. /*
  390. * Now, unfortunately, sysfs doesn't give us a nice void * we could
  391. * pass around to the attribute functions, so we don't really have
  392. * choice but implement a bunch of them...
  393. *
  394. * FIXME, it does now...
  395. */
  396. #define BUILD_SHOW_FUNC_INT(name, data) \
  397. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  398. { \
  399. return sprintf(buf, "%d\n", data); \
  400. }
  401. #define BUILD_SHOW_FUNC_STR(name, data) \
  402. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  403. { \
  404. return sprintf(buf, "%s\n", data); \
  405. }
  406. #define BUILD_SHOW_FUNC_FAN(name, data) \
  407. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  408. { \
  409. return sprintf(buf, "%d (%d rpm)\n", \
  410. thermostat->last_speed[data], \
  411. read_fan_speed(thermostat, FAN_SPEED[data]) \
  412. ); \
  413. }
  414. #define BUILD_STORE_FUNC_DEG(name, data) \
  415. static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
  416. { \
  417. int val; \
  418. int i; \
  419. val = simple_strtol(buf, NULL, 10); \
  420. printk(KERN_INFO "Adjusting limits by %d degrees\n", val); \
  421. limit_adjust = val; \
  422. for (i=0; i < 3; i++) \
  423. set_limit(thermostat, i); \
  424. return n; \
  425. }
  426. #define BUILD_STORE_FUNC_INT(name, data) \
  427. static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
  428. { \
  429. int val; \
  430. val = simple_strtol(buf, NULL, 10); \
  431. if (val < 0 || val > 255) \
  432. return -EINVAL; \
  433. printk(KERN_INFO "Setting specified fan speed to %d\n", val); \
  434. data = val; \
  435. return n; \
  436. }
  437. BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(thermostat, TEMP_REG[1])))
  438. BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(thermostat, TEMP_REG[2])))
  439. BUILD_SHOW_FUNC_INT(sensor1_limit, thermostat->limits[1])
  440. BUILD_SHOW_FUNC_INT(sensor2_limit, thermostat->limits[2])
  441. BUILD_SHOW_FUNC_STR(sensor1_location, sensor_location[1])
  442. BUILD_SHOW_FUNC_STR(sensor2_location, sensor_location[2])
  443. BUILD_SHOW_FUNC_INT(specified_fan_speed, fan_speed)
  444. BUILD_SHOW_FUNC_FAN(sensor1_fan_speed, 0)
  445. BUILD_SHOW_FUNC_FAN(sensor2_fan_speed, 1)
  446. BUILD_STORE_FUNC_INT(specified_fan_speed,fan_speed)
  447. BUILD_SHOW_FUNC_INT(limit_adjust, limit_adjust)
  448. BUILD_STORE_FUNC_DEG(limit_adjust, thermostat)
  449. static DEVICE_ATTR(sensor1_temperature, S_IRUGO,
  450. show_sensor1_temperature,NULL);
  451. static DEVICE_ATTR(sensor2_temperature, S_IRUGO,
  452. show_sensor2_temperature,NULL);
  453. static DEVICE_ATTR(sensor1_limit, S_IRUGO,
  454. show_sensor1_limit, NULL);
  455. static DEVICE_ATTR(sensor2_limit, S_IRUGO,
  456. show_sensor2_limit, NULL);
  457. static DEVICE_ATTR(sensor1_location, S_IRUGO,
  458. show_sensor1_location, NULL);
  459. static DEVICE_ATTR(sensor2_location, S_IRUGO,
  460. show_sensor2_location, NULL);
  461. static DEVICE_ATTR(specified_fan_speed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
  462. show_specified_fan_speed,store_specified_fan_speed);
  463. static DEVICE_ATTR(sensor1_fan_speed, S_IRUGO,
  464. show_sensor1_fan_speed, NULL);
  465. static DEVICE_ATTR(sensor2_fan_speed, S_IRUGO,
  466. show_sensor2_fan_speed, NULL);
  467. static DEVICE_ATTR(limit_adjust, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH,
  468. show_limit_adjust, store_limit_adjust);
  469. static int __init
  470. thermostat_init(void)
  471. {
  472. struct device_node* np;
  473. const u32 *prop;
  474. int i = 0, offset = 0;
  475. int err;
  476. np = of_find_node_by_name(NULL, "fan");
  477. if (!np)
  478. return -ENODEV;
  479. if (of_device_is_compatible(np, "adt7460"))
  480. therm_type = ADT7460;
  481. else if (of_device_is_compatible(np, "adt7467"))
  482. therm_type = ADT7467;
  483. else {
  484. of_node_put(np);
  485. return -ENODEV;
  486. }
  487. prop = of_get_property(np, "hwsensor-params-version", NULL);
  488. printk(KERN_INFO "adt746x: version %d (%ssupported)\n", *prop,
  489. (*prop == 1)?"":"un");
  490. if (*prop != 1) {
  491. of_node_put(np);
  492. return -ENODEV;
  493. }
  494. prop = of_get_property(np, "reg", NULL);
  495. if (!prop) {
  496. of_node_put(np);
  497. return -ENODEV;
  498. }
  499. /* look for bus either by path or using "reg" */
  500. if (strstr(np->full_name, "/i2c-bus@") != NULL) {
  501. const char *tmp_bus = (strstr(np->full_name, "/i2c-bus@") + 9);
  502. therm_bus = tmp_bus[0]-'0';
  503. } else {
  504. therm_bus = ((*prop) >> 8) & 0x0f;
  505. }
  506. therm_address = ((*prop) & 0xff) >> 1;
  507. printk(KERN_INFO "adt746x: Thermostat bus: %d, address: 0x%02x, "
  508. "limit_adjust: %d, fan_speed: %d\n",
  509. therm_bus, therm_address, limit_adjust, fan_speed);
  510. if (of_get_property(np, "hwsensor-location", NULL)) {
  511. for (i = 0; i < 3; i++) {
  512. sensor_location[i] = of_get_property(np,
  513. "hwsensor-location", NULL) + offset;
  514. if (sensor_location[i] == NULL)
  515. sensor_location[i] = "";
  516. printk(KERN_INFO "sensor %d: %s\n", i, sensor_location[i]);
  517. offset += strlen(sensor_location[i]) + 1;
  518. }
  519. } else {
  520. sensor_location[0] = "?";
  521. sensor_location[1] = "?";
  522. sensor_location[2] = "?";
  523. }
  524. of_dev = of_platform_device_create(np, "temperatures", NULL);
  525. of_node_put(np);
  526. if (of_dev == NULL) {
  527. printk(KERN_ERR "Can't register temperatures device !\n");
  528. return -ENODEV;
  529. }
  530. err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature);
  531. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature);
  532. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit);
  533. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_limit);
  534. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_location);
  535. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_location);
  536. err |= device_create_file(&of_dev->dev, &dev_attr_limit_adjust);
  537. err |= device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed);
  538. err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
  539. if(therm_type == ADT7460)
  540. err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed);
  541. if (err)
  542. printk(KERN_WARNING
  543. "Failed to create tempertaure attribute file(s).\n");
  544. #ifndef CONFIG_I2C_POWERMAC
  545. request_module("i2c-powermac");
  546. #endif
  547. return i2c_add_driver(&thermostat_driver);
  548. }
  549. static void __exit
  550. thermostat_exit(void)
  551. {
  552. if (of_dev) {
  553. device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature);
  554. device_remove_file(&of_dev->dev, &dev_attr_sensor2_temperature);
  555. device_remove_file(&of_dev->dev, &dev_attr_sensor1_limit);
  556. device_remove_file(&of_dev->dev, &dev_attr_sensor2_limit);
  557. device_remove_file(&of_dev->dev, &dev_attr_sensor1_location);
  558. device_remove_file(&of_dev->dev, &dev_attr_sensor2_location);
  559. device_remove_file(&of_dev->dev, &dev_attr_limit_adjust);
  560. device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed);
  561. device_remove_file(&of_dev->dev, &dev_attr_sensor1_fan_speed);
  562. if(therm_type == ADT7460)
  563. device_remove_file(&of_dev->dev,
  564. &dev_attr_sensor2_fan_speed);
  565. of_device_unregister(of_dev);
  566. }
  567. i2c_del_driver(&thermostat_driver);
  568. }
  569. module_init(thermostat_init);
  570. module_exit(thermostat_exit);