therm_adt746x.c 18 KB

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