therm_adt746x.c 17 KB

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