therm_adt746x.c 18 KB

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