therm_adt746x.c 17 KB

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