bbc_envctrl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /* $Id: bbc_envctrl.c,v 1.4 2001/04/06 16:48:08 davem Exp $
  2. * bbc_envctrl.c: UltraSPARC-III environment control driver.
  3. *
  4. * Copyright (C) 2001 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/kthread.h>
  7. #include <linux/delay.h>
  8. #include <linux/kmod.h>
  9. #include <linux/reboot.h>
  10. #include <asm/oplib.h>
  11. #include <asm/ebus.h>
  12. #include "bbc_i2c.h"
  13. #include "max1617.h"
  14. #undef ENVCTRL_TRACE
  15. /* WARNING: Making changes to this driver is very dangerous.
  16. * If you misprogram the sensor chips they can
  17. * cut the power on you instantly.
  18. */
  19. /* Two temperature sensors exist in the SunBLADE-1000 enclosure.
  20. * Both are implemented using max1617 i2c devices. Each max1617
  21. * monitors 2 temperatures, one for one of the cpu dies and the other
  22. * for the ambient temperature.
  23. *
  24. * The max1617 is capable of being programmed with power-off
  25. * temperature values, one low limit and one high limit. These
  26. * can be controlled independently for the cpu or ambient temperature.
  27. * If a limit is violated, the power is simply shut off. The frequency
  28. * with which the max1617 does temperature sampling can be controlled
  29. * as well.
  30. *
  31. * Three fans exist inside the machine, all three are controlled with
  32. * an i2c digital to analog converter. There is a fan directed at the
  33. * two processor slots, another for the rest of the enclosure, and the
  34. * third is for the power supply. The first two fans may be speed
  35. * controlled by changing the voltage fed to them. The third fan may
  36. * only be completely off or on. The third fan is meant to only be
  37. * disabled/enabled when entering/exiting the lowest power-saving
  38. * mode of the machine.
  39. *
  40. * An environmental control kernel thread periodically monitors all
  41. * temperature sensors. Based upon the samples it will adjust the
  42. * fan speeds to try and keep the system within a certain temperature
  43. * range (the goal being to make the fans as quiet as possible without
  44. * allowing the system to get too hot).
  45. *
  46. * If the temperature begins to rise/fall outside of the acceptable
  47. * operating range, a periodic warning will be sent to the kernel log.
  48. * The fans will be put on full blast to attempt to deal with this
  49. * situation. After exceeding the acceptable operating range by a
  50. * certain threshold, the kernel thread will shut down the system.
  51. * Here, the thread is attempting to shut the machine down cleanly
  52. * before the hardware based power-off event is triggered.
  53. */
  54. /* These settings are in Celsius. We use these defaults only
  55. * if we cannot interrogate the cpu-fru SEEPROM.
  56. */
  57. struct temp_limits {
  58. s8 high_pwroff, high_shutdown, high_warn;
  59. s8 low_warn, low_shutdown, low_pwroff;
  60. };
  61. static struct temp_limits cpu_temp_limits[2] = {
  62. { 100, 85, 80, 5, -5, -10 },
  63. { 100, 85, 80, 5, -5, -10 },
  64. };
  65. static struct temp_limits amb_temp_limits[2] = {
  66. { 65, 55, 40, 5, -5, -10 },
  67. { 65, 55, 40, 5, -5, -10 },
  68. };
  69. enum fan_action { FAN_SLOWER, FAN_SAME, FAN_FASTER, FAN_FULLBLAST, FAN_STATE_MAX };
  70. struct bbc_cpu_temperature {
  71. struct bbc_cpu_temperature *next;
  72. struct bbc_i2c_client *client;
  73. int index;
  74. /* Current readings, and history. */
  75. s8 curr_cpu_temp;
  76. s8 curr_amb_temp;
  77. s8 prev_cpu_temp;
  78. s8 prev_amb_temp;
  79. s8 avg_cpu_temp;
  80. s8 avg_amb_temp;
  81. int sample_tick;
  82. enum fan_action fan_todo[2];
  83. #define FAN_AMBIENT 0
  84. #define FAN_CPU 1
  85. };
  86. struct bbc_cpu_temperature *all_bbc_temps;
  87. struct bbc_fan_control {
  88. struct bbc_fan_control *next;
  89. struct bbc_i2c_client *client;
  90. int index;
  91. int psupply_fan_on;
  92. int cpu_fan_speed;
  93. int system_fan_speed;
  94. };
  95. struct bbc_fan_control *all_bbc_fans;
  96. #define CPU_FAN_REG 0xf0
  97. #define SYS_FAN_REG 0xf2
  98. #define PSUPPLY_FAN_REG 0xf4
  99. #define FAN_SPEED_MIN 0x0c
  100. #define FAN_SPEED_MAX 0x3f
  101. #define PSUPPLY_FAN_ON 0x1f
  102. #define PSUPPLY_FAN_OFF 0x00
  103. static void set_fan_speeds(struct bbc_fan_control *fp)
  104. {
  105. /* Put temperatures into range so we don't mis-program
  106. * the hardware.
  107. */
  108. if (fp->cpu_fan_speed < FAN_SPEED_MIN)
  109. fp->cpu_fan_speed = FAN_SPEED_MIN;
  110. if (fp->cpu_fan_speed > FAN_SPEED_MAX)
  111. fp->cpu_fan_speed = FAN_SPEED_MAX;
  112. if (fp->system_fan_speed < FAN_SPEED_MIN)
  113. fp->system_fan_speed = FAN_SPEED_MIN;
  114. if (fp->system_fan_speed > FAN_SPEED_MAX)
  115. fp->system_fan_speed = FAN_SPEED_MAX;
  116. #ifdef ENVCTRL_TRACE
  117. printk("fan%d: Changed fan speed to cpu(%02x) sys(%02x)\n",
  118. fp->index,
  119. fp->cpu_fan_speed, fp->system_fan_speed);
  120. #endif
  121. bbc_i2c_writeb(fp->client, fp->cpu_fan_speed, CPU_FAN_REG);
  122. bbc_i2c_writeb(fp->client, fp->system_fan_speed, SYS_FAN_REG);
  123. bbc_i2c_writeb(fp->client,
  124. (fp->psupply_fan_on ?
  125. PSUPPLY_FAN_ON : PSUPPLY_FAN_OFF),
  126. PSUPPLY_FAN_REG);
  127. }
  128. static void get_current_temps(struct bbc_cpu_temperature *tp)
  129. {
  130. tp->prev_amb_temp = tp->curr_amb_temp;
  131. bbc_i2c_readb(tp->client,
  132. (unsigned char *) &tp->curr_amb_temp,
  133. MAX1617_AMB_TEMP);
  134. tp->prev_cpu_temp = tp->curr_cpu_temp;
  135. bbc_i2c_readb(tp->client,
  136. (unsigned char *) &tp->curr_cpu_temp,
  137. MAX1617_CPU_TEMP);
  138. #ifdef ENVCTRL_TRACE
  139. printk("temp%d: cpu(%d C) amb(%d C)\n",
  140. tp->index,
  141. (int) tp->curr_cpu_temp, (int) tp->curr_amb_temp);
  142. #endif
  143. }
  144. static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
  145. {
  146. static int shutting_down = 0;
  147. char *type = "???";
  148. s8 val = -1;
  149. if (shutting_down != 0)
  150. return;
  151. if (tp->curr_amb_temp >= amb_temp_limits[tp->index].high_shutdown ||
  152. tp->curr_amb_temp < amb_temp_limits[tp->index].low_shutdown) {
  153. type = "ambient";
  154. val = tp->curr_amb_temp;
  155. } else if (tp->curr_cpu_temp >= cpu_temp_limits[tp->index].high_shutdown ||
  156. tp->curr_cpu_temp < cpu_temp_limits[tp->index].low_shutdown) {
  157. type = "CPU";
  158. val = tp->curr_cpu_temp;
  159. }
  160. printk(KERN_CRIT "temp%d: Outside of safe %s "
  161. "operating temperature, %d C.\n",
  162. tp->index, type, val);
  163. printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
  164. shutting_down = 1;
  165. if (orderly_poweroff(true) < 0)
  166. printk(KERN_CRIT "envctrl: shutdown execution failed\n");
  167. }
  168. #define WARN_INTERVAL (30 * HZ)
  169. static void analyze_ambient_temp(struct bbc_cpu_temperature *tp, unsigned long *last_warn, int tick)
  170. {
  171. int ret = 0;
  172. if (time_after(jiffies, (*last_warn + WARN_INTERVAL))) {
  173. if (tp->curr_amb_temp >=
  174. amb_temp_limits[tp->index].high_warn) {
  175. printk(KERN_WARNING "temp%d: "
  176. "Above safe ambient operating temperature, %d C.\n",
  177. tp->index, (int) tp->curr_amb_temp);
  178. ret = 1;
  179. } else if (tp->curr_amb_temp <
  180. amb_temp_limits[tp->index].low_warn) {
  181. printk(KERN_WARNING "temp%d: "
  182. "Below safe ambient operating temperature, %d C.\n",
  183. tp->index, (int) tp->curr_amb_temp);
  184. ret = 1;
  185. }
  186. if (ret)
  187. *last_warn = jiffies;
  188. } else if (tp->curr_amb_temp >= amb_temp_limits[tp->index].high_warn ||
  189. tp->curr_amb_temp < amb_temp_limits[tp->index].low_warn)
  190. ret = 1;
  191. /* Now check the shutdown limits. */
  192. if (tp->curr_amb_temp >= amb_temp_limits[tp->index].high_shutdown ||
  193. tp->curr_amb_temp < amb_temp_limits[tp->index].low_shutdown) {
  194. do_envctrl_shutdown(tp);
  195. ret = 1;
  196. }
  197. if (ret) {
  198. tp->fan_todo[FAN_AMBIENT] = FAN_FULLBLAST;
  199. } else if ((tick & (8 - 1)) == 0) {
  200. s8 amb_goal_hi = amb_temp_limits[tp->index].high_warn - 10;
  201. s8 amb_goal_lo;
  202. amb_goal_lo = amb_goal_hi - 3;
  203. /* We do not try to avoid 'too cold' events. Basically we
  204. * only try to deal with over-heating and fan noise reduction.
  205. */
  206. if (tp->avg_amb_temp < amb_goal_hi) {
  207. if (tp->avg_amb_temp >= amb_goal_lo)
  208. tp->fan_todo[FAN_AMBIENT] = FAN_SAME;
  209. else
  210. tp->fan_todo[FAN_AMBIENT] = FAN_SLOWER;
  211. } else {
  212. tp->fan_todo[FAN_AMBIENT] = FAN_FASTER;
  213. }
  214. } else {
  215. tp->fan_todo[FAN_AMBIENT] = FAN_SAME;
  216. }
  217. }
  218. static void analyze_cpu_temp(struct bbc_cpu_temperature *tp, unsigned long *last_warn, int tick)
  219. {
  220. int ret = 0;
  221. if (time_after(jiffies, (*last_warn + WARN_INTERVAL))) {
  222. if (tp->curr_cpu_temp >=
  223. cpu_temp_limits[tp->index].high_warn) {
  224. printk(KERN_WARNING "temp%d: "
  225. "Above safe CPU operating temperature, %d C.\n",
  226. tp->index, (int) tp->curr_cpu_temp);
  227. ret = 1;
  228. } else if (tp->curr_cpu_temp <
  229. cpu_temp_limits[tp->index].low_warn) {
  230. printk(KERN_WARNING "temp%d: "
  231. "Below safe CPU operating temperature, %d C.\n",
  232. tp->index, (int) tp->curr_cpu_temp);
  233. ret = 1;
  234. }
  235. if (ret)
  236. *last_warn = jiffies;
  237. } else if (tp->curr_cpu_temp >= cpu_temp_limits[tp->index].high_warn ||
  238. tp->curr_cpu_temp < cpu_temp_limits[tp->index].low_warn)
  239. ret = 1;
  240. /* Now check the shutdown limits. */
  241. if (tp->curr_cpu_temp >= cpu_temp_limits[tp->index].high_shutdown ||
  242. tp->curr_cpu_temp < cpu_temp_limits[tp->index].low_shutdown) {
  243. do_envctrl_shutdown(tp);
  244. ret = 1;
  245. }
  246. if (ret) {
  247. tp->fan_todo[FAN_CPU] = FAN_FULLBLAST;
  248. } else if ((tick & (8 - 1)) == 0) {
  249. s8 cpu_goal_hi = cpu_temp_limits[tp->index].high_warn - 10;
  250. s8 cpu_goal_lo;
  251. cpu_goal_lo = cpu_goal_hi - 3;
  252. /* We do not try to avoid 'too cold' events. Basically we
  253. * only try to deal with over-heating and fan noise reduction.
  254. */
  255. if (tp->avg_cpu_temp < cpu_goal_hi) {
  256. if (tp->avg_cpu_temp >= cpu_goal_lo)
  257. tp->fan_todo[FAN_CPU] = FAN_SAME;
  258. else
  259. tp->fan_todo[FAN_CPU] = FAN_SLOWER;
  260. } else {
  261. tp->fan_todo[FAN_CPU] = FAN_FASTER;
  262. }
  263. } else {
  264. tp->fan_todo[FAN_CPU] = FAN_SAME;
  265. }
  266. }
  267. static void analyze_temps(struct bbc_cpu_temperature *tp, unsigned long *last_warn)
  268. {
  269. tp->avg_amb_temp = (s8)((int)((int)tp->avg_amb_temp + (int)tp->curr_amb_temp) / 2);
  270. tp->avg_cpu_temp = (s8)((int)((int)tp->avg_cpu_temp + (int)tp->curr_cpu_temp) / 2);
  271. analyze_ambient_temp(tp, last_warn, tp->sample_tick);
  272. analyze_cpu_temp(tp, last_warn, tp->sample_tick);
  273. tp->sample_tick++;
  274. }
  275. static enum fan_action prioritize_fan_action(int which_fan)
  276. {
  277. struct bbc_cpu_temperature *tp;
  278. enum fan_action decision = FAN_STATE_MAX;
  279. /* Basically, prioritize what the temperature sensors
  280. * recommend we do, and perform that action on all the
  281. * fans.
  282. */
  283. for (tp = all_bbc_temps; tp; tp = tp->next) {
  284. if (tp->fan_todo[which_fan] == FAN_FULLBLAST) {
  285. decision = FAN_FULLBLAST;
  286. break;
  287. }
  288. if (tp->fan_todo[which_fan] == FAN_SAME &&
  289. decision != FAN_FASTER)
  290. decision = FAN_SAME;
  291. else if (tp->fan_todo[which_fan] == FAN_FASTER)
  292. decision = FAN_FASTER;
  293. else if (decision != FAN_FASTER &&
  294. decision != FAN_SAME &&
  295. tp->fan_todo[which_fan] == FAN_SLOWER)
  296. decision = FAN_SLOWER;
  297. }
  298. if (decision == FAN_STATE_MAX)
  299. decision = FAN_SAME;
  300. return decision;
  301. }
  302. static int maybe_new_ambient_fan_speed(struct bbc_fan_control *fp)
  303. {
  304. enum fan_action decision = prioritize_fan_action(FAN_AMBIENT);
  305. int ret;
  306. if (decision == FAN_SAME)
  307. return 0;
  308. ret = 1;
  309. if (decision == FAN_FULLBLAST) {
  310. if (fp->system_fan_speed >= FAN_SPEED_MAX)
  311. ret = 0;
  312. else
  313. fp->system_fan_speed = FAN_SPEED_MAX;
  314. } else {
  315. if (decision == FAN_FASTER) {
  316. if (fp->system_fan_speed >= FAN_SPEED_MAX)
  317. ret = 0;
  318. else
  319. fp->system_fan_speed += 2;
  320. } else {
  321. int orig_speed = fp->system_fan_speed;
  322. if (orig_speed <= FAN_SPEED_MIN ||
  323. orig_speed <= (fp->cpu_fan_speed - 3))
  324. ret = 0;
  325. else
  326. fp->system_fan_speed -= 1;
  327. }
  328. }
  329. return ret;
  330. }
  331. static int maybe_new_cpu_fan_speed(struct bbc_fan_control *fp)
  332. {
  333. enum fan_action decision = prioritize_fan_action(FAN_CPU);
  334. int ret;
  335. if (decision == FAN_SAME)
  336. return 0;
  337. ret = 1;
  338. if (decision == FAN_FULLBLAST) {
  339. if (fp->cpu_fan_speed >= FAN_SPEED_MAX)
  340. ret = 0;
  341. else
  342. fp->cpu_fan_speed = FAN_SPEED_MAX;
  343. } else {
  344. if (decision == FAN_FASTER) {
  345. if (fp->cpu_fan_speed >= FAN_SPEED_MAX)
  346. ret = 0;
  347. else {
  348. fp->cpu_fan_speed += 2;
  349. if (fp->system_fan_speed <
  350. (fp->cpu_fan_speed - 3))
  351. fp->system_fan_speed =
  352. fp->cpu_fan_speed - 3;
  353. }
  354. } else {
  355. if (fp->cpu_fan_speed <= FAN_SPEED_MIN)
  356. ret = 0;
  357. else
  358. fp->cpu_fan_speed -= 1;
  359. }
  360. }
  361. return ret;
  362. }
  363. static void maybe_new_fan_speeds(struct bbc_fan_control *fp)
  364. {
  365. int new;
  366. new = maybe_new_ambient_fan_speed(fp);
  367. new |= maybe_new_cpu_fan_speed(fp);
  368. if (new)
  369. set_fan_speeds(fp);
  370. }
  371. static void fans_full_blast(void)
  372. {
  373. struct bbc_fan_control *fp;
  374. /* Since we will not be monitoring things anymore, put
  375. * the fans on full blast.
  376. */
  377. for (fp = all_bbc_fans; fp; fp = fp->next) {
  378. fp->cpu_fan_speed = FAN_SPEED_MAX;
  379. fp->system_fan_speed = FAN_SPEED_MAX;
  380. fp->psupply_fan_on = 1;
  381. set_fan_speeds(fp);
  382. }
  383. }
  384. #define POLL_INTERVAL (5 * 1000)
  385. static unsigned long last_warning_jiffies;
  386. static struct task_struct *kenvctrld_task;
  387. static int kenvctrld(void *__unused)
  388. {
  389. printk(KERN_INFO "bbc_envctrl: kenvctrld starting...\n");
  390. last_warning_jiffies = jiffies - WARN_INTERVAL;
  391. for (;;) {
  392. struct bbc_cpu_temperature *tp;
  393. struct bbc_fan_control *fp;
  394. msleep_interruptible(POLL_INTERVAL);
  395. if (kthread_should_stop())
  396. break;
  397. for (tp = all_bbc_temps; tp; tp = tp->next) {
  398. get_current_temps(tp);
  399. analyze_temps(tp, &last_warning_jiffies);
  400. }
  401. for (fp = all_bbc_fans; fp; fp = fp->next)
  402. maybe_new_fan_speeds(fp);
  403. }
  404. printk(KERN_INFO "bbc_envctrl: kenvctrld exiting...\n");
  405. fans_full_blast();
  406. return 0;
  407. }
  408. static void attach_one_temp(struct linux_ebus_child *echild, int temp_idx)
  409. {
  410. struct bbc_cpu_temperature *tp;
  411. tp = kzalloc(sizeof(*tp), GFP_KERNEL);
  412. if (!tp)
  413. return;
  414. tp->client = bbc_i2c_attach(echild);
  415. if (!tp->client) {
  416. kfree(tp);
  417. return;
  418. }
  419. tp->index = temp_idx;
  420. {
  421. struct bbc_cpu_temperature **tpp = &all_bbc_temps;
  422. while (*tpp)
  423. tpp = &((*tpp)->next);
  424. tp->next = NULL;
  425. *tpp = tp;
  426. }
  427. /* Tell it to convert once every 5 seconds, clear all cfg
  428. * bits.
  429. */
  430. bbc_i2c_writeb(tp->client, 0x00, MAX1617_WR_CFG_BYTE);
  431. bbc_i2c_writeb(tp->client, 0x02, MAX1617_WR_CVRATE_BYTE);
  432. /* Program the hard temperature limits into the chip. */
  433. bbc_i2c_writeb(tp->client, amb_temp_limits[tp->index].high_pwroff,
  434. MAX1617_WR_AMB_HIGHLIM);
  435. bbc_i2c_writeb(tp->client, amb_temp_limits[tp->index].low_pwroff,
  436. MAX1617_WR_AMB_LOWLIM);
  437. bbc_i2c_writeb(tp->client, cpu_temp_limits[tp->index].high_pwroff,
  438. MAX1617_WR_CPU_HIGHLIM);
  439. bbc_i2c_writeb(tp->client, cpu_temp_limits[tp->index].low_pwroff,
  440. MAX1617_WR_CPU_LOWLIM);
  441. get_current_temps(tp);
  442. tp->prev_cpu_temp = tp->avg_cpu_temp = tp->curr_cpu_temp;
  443. tp->prev_amb_temp = tp->avg_amb_temp = tp->curr_amb_temp;
  444. tp->fan_todo[FAN_AMBIENT] = FAN_SAME;
  445. tp->fan_todo[FAN_CPU] = FAN_SAME;
  446. }
  447. static void attach_one_fan(struct linux_ebus_child *echild, int fan_idx)
  448. {
  449. struct bbc_fan_control *fp;
  450. fp = kzalloc(sizeof(*fp), GFP_KERNEL);
  451. if (!fp)
  452. return;
  453. fp->client = bbc_i2c_attach(echild);
  454. if (!fp->client) {
  455. kfree(fp);
  456. return;
  457. }
  458. fp->index = fan_idx;
  459. {
  460. struct bbc_fan_control **fpp = &all_bbc_fans;
  461. while (*fpp)
  462. fpp = &((*fpp)->next);
  463. fp->next = NULL;
  464. *fpp = fp;
  465. }
  466. /* The i2c device controlling the fans is write-only.
  467. * So the only way to keep track of the current power
  468. * level fed to the fans is via software. Choose half
  469. * power for cpu/system and 'on' fo the powersupply fan
  470. * and set it now.
  471. */
  472. fp->psupply_fan_on = 1;
  473. fp->cpu_fan_speed = (FAN_SPEED_MAX - FAN_SPEED_MIN) / 2;
  474. fp->cpu_fan_speed += FAN_SPEED_MIN;
  475. fp->system_fan_speed = (FAN_SPEED_MAX - FAN_SPEED_MIN) / 2;
  476. fp->system_fan_speed += FAN_SPEED_MIN;
  477. set_fan_speeds(fp);
  478. }
  479. int bbc_envctrl_init(void)
  480. {
  481. struct linux_ebus_child *echild;
  482. int temp_index = 0;
  483. int fan_index = 0;
  484. int devidx = 0;
  485. while ((echild = bbc_i2c_getdev(devidx++)) != NULL) {
  486. if (!strcmp(echild->prom_node->name, "temperature"))
  487. attach_one_temp(echild, temp_index++);
  488. if (!strcmp(echild->prom_node->name, "fan-control"))
  489. attach_one_fan(echild, fan_index++);
  490. }
  491. if (temp_index != 0 && fan_index != 0) {
  492. kenvctrld_task = kthread_run(kenvctrld, NULL, "kenvctrld");
  493. if (IS_ERR(kenvctrld_task))
  494. return PTR_ERR(kenvctrld_task);
  495. }
  496. return 0;
  497. }
  498. static void destroy_one_temp(struct bbc_cpu_temperature *tp)
  499. {
  500. bbc_i2c_detach(tp->client);
  501. kfree(tp);
  502. }
  503. static void destroy_one_fan(struct bbc_fan_control *fp)
  504. {
  505. bbc_i2c_detach(fp->client);
  506. kfree(fp);
  507. }
  508. void bbc_envctrl_cleanup(void)
  509. {
  510. struct bbc_cpu_temperature *tp;
  511. struct bbc_fan_control *fp;
  512. kthread_stop(kenvctrld_task);
  513. tp = all_bbc_temps;
  514. while (tp != NULL) {
  515. struct bbc_cpu_temperature *next = tp->next;
  516. destroy_one_temp(tp);
  517. tp = next;
  518. }
  519. all_bbc_temps = NULL;
  520. fp = all_bbc_fans;
  521. while (fp != NULL) {
  522. struct bbc_fan_control *next = fp->next;
  523. destroy_one_fan(fp);
  524. fp = next;
  525. }
  526. all_bbc_fans = NULL;
  527. }