windfarm_pm91.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Windfarm PowerMac thermal control. SMU based 1 CPU desktop control loops
  3. *
  4. * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  5. * <benh@kernel.crashing.org>
  6. *
  7. * Released under the term of the GNU GPL v2.
  8. *
  9. * The algorithm used is the PID control algorithm, used the same
  10. * way the published Darwin code does, using the same values that
  11. * are present in the Darwin 8.2 snapshot property lists (note however
  12. * that none of the code has been re-used, it's a complete re-implementation
  13. *
  14. * The various control loops found in Darwin config file are:
  15. *
  16. * PowerMac9,1
  17. * ===========
  18. *
  19. * Has 3 control loops: CPU fans is similar to PowerMac8,1 (though it doesn't
  20. * try to play with other control loops fans). Drive bay is rather basic PID
  21. * with one sensor and one fan. Slots area is a bit different as the Darwin
  22. * driver is supposed to be capable of working in a special "AGP" mode which
  23. * involves the presence of an AGP sensor and an AGP fan (possibly on the
  24. * AGP card itself). I can't deal with that special mode as I don't have
  25. * access to those additional sensor/fans for now (though ultimately, it would
  26. * be possible to add sensor objects for them) so I'm only implementing the
  27. * basic PCI slot control loop
  28. */
  29. #include <linux/types.h>
  30. #include <linux/errno.h>
  31. #include <linux/kernel.h>
  32. #include <linux/delay.h>
  33. #include <linux/slab.h>
  34. #include <linux/init.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/wait.h>
  37. #include <linux/kmod.h>
  38. #include <linux/device.h>
  39. #include <linux/platform_device.h>
  40. #include <asm/prom.h>
  41. #include <asm/machdep.h>
  42. #include <asm/io.h>
  43. #include <asm/system.h>
  44. #include <asm/sections.h>
  45. #include <asm/smu.h>
  46. #include "windfarm.h"
  47. #include "windfarm_pid.h"
  48. #define VERSION "0.4"
  49. #undef DEBUG
  50. #ifdef DEBUG
  51. #define DBG(args...) printk(args)
  52. #else
  53. #define DBG(args...) do { } while(0)
  54. #endif
  55. /* define this to force CPU overtemp to 74 degree, useful for testing
  56. * the overtemp code
  57. */
  58. #undef HACKED_OVERTEMP
  59. /* Controls & sensors */
  60. static struct wf_sensor *sensor_cpu_power;
  61. static struct wf_sensor *sensor_cpu_temp;
  62. static struct wf_sensor *sensor_hd_temp;
  63. static struct wf_sensor *sensor_slots_power;
  64. static struct wf_control *fan_cpu_main;
  65. static struct wf_control *fan_cpu_second;
  66. static struct wf_control *fan_cpu_third;
  67. static struct wf_control *fan_hd;
  68. static struct wf_control *fan_slots;
  69. static struct wf_control *cpufreq_clamp;
  70. /* Set to kick the control loop into life */
  71. static int wf_smu_all_controls_ok, wf_smu_all_sensors_ok, wf_smu_started;
  72. /* Failure handling.. could be nicer */
  73. #define FAILURE_FAN 0x01
  74. #define FAILURE_SENSOR 0x02
  75. #define FAILURE_OVERTEMP 0x04
  76. static unsigned int wf_smu_failure_state;
  77. static int wf_smu_readjust, wf_smu_skipping;
  78. /*
  79. * ****** CPU Fans Control Loop ******
  80. *
  81. */
  82. #define WF_SMU_CPU_FANS_INTERVAL 1
  83. #define WF_SMU_CPU_FANS_MAX_HISTORY 16
  84. /* State data used by the cpu fans control loop
  85. */
  86. struct wf_smu_cpu_fans_state {
  87. int ticks;
  88. s32 cpu_setpoint;
  89. struct wf_cpu_pid_state pid;
  90. };
  91. static struct wf_smu_cpu_fans_state *wf_smu_cpu_fans;
  92. /*
  93. * ****** Drive Fan Control Loop ******
  94. *
  95. */
  96. struct wf_smu_drive_fans_state {
  97. int ticks;
  98. s32 setpoint;
  99. struct wf_pid_state pid;
  100. };
  101. static struct wf_smu_drive_fans_state *wf_smu_drive_fans;
  102. /*
  103. * ****** Slots Fan Control Loop ******
  104. *
  105. */
  106. struct wf_smu_slots_fans_state {
  107. int ticks;
  108. s32 setpoint;
  109. struct wf_pid_state pid;
  110. };
  111. static struct wf_smu_slots_fans_state *wf_smu_slots_fans;
  112. /*
  113. * ***** Implementation *****
  114. *
  115. */
  116. static void wf_smu_create_cpu_fans(void)
  117. {
  118. struct wf_cpu_pid_param pid_param;
  119. const struct smu_sdbp_header *hdr;
  120. struct smu_sdbp_cpupiddata *piddata;
  121. struct smu_sdbp_fvt *fvt;
  122. s32 tmax, tdelta, maxpow, powadj;
  123. /* First, locate the PID params in SMU SBD */
  124. hdr = smu_get_sdb_partition(SMU_SDB_CPUPIDDATA_ID, NULL);
  125. if (hdr == 0) {
  126. printk(KERN_WARNING "windfarm: CPU PID fan config not found "
  127. "max fan speed\n");
  128. goto fail;
  129. }
  130. piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
  131. /* Get the FVT params for operating point 0 (the only supported one
  132. * for now) in order to get tmax
  133. */
  134. hdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
  135. if (hdr) {
  136. fvt = (struct smu_sdbp_fvt *)&hdr[1];
  137. tmax = ((s32)fvt->maxtemp) << 16;
  138. } else
  139. tmax = 0x5e0000; /* 94 degree default */
  140. /* Alloc & initialize state */
  141. wf_smu_cpu_fans = kmalloc(sizeof(struct wf_smu_cpu_fans_state),
  142. GFP_KERNEL);
  143. if (wf_smu_cpu_fans == NULL)
  144. goto fail;
  145. wf_smu_cpu_fans->ticks = 1;
  146. /* Fill PID params */
  147. pid_param.interval = WF_SMU_CPU_FANS_INTERVAL;
  148. pid_param.history_len = piddata->history_len;
  149. if (pid_param.history_len > WF_CPU_PID_MAX_HISTORY) {
  150. printk(KERN_WARNING "windfarm: History size overflow on "
  151. "CPU control loop (%d)\n", piddata->history_len);
  152. pid_param.history_len = WF_CPU_PID_MAX_HISTORY;
  153. }
  154. pid_param.gd = piddata->gd;
  155. pid_param.gp = piddata->gp;
  156. pid_param.gr = piddata->gr / pid_param.history_len;
  157. tdelta = ((s32)piddata->target_temp_delta) << 16;
  158. maxpow = ((s32)piddata->max_power) << 16;
  159. powadj = ((s32)piddata->power_adj) << 16;
  160. pid_param.tmax = tmax;
  161. pid_param.ttarget = tmax - tdelta;
  162. pid_param.pmaxadj = maxpow - powadj;
  163. pid_param.min = fan_cpu_main->ops->get_min(fan_cpu_main);
  164. pid_param.max = fan_cpu_main->ops->get_max(fan_cpu_main);
  165. wf_cpu_pid_init(&wf_smu_cpu_fans->pid, &pid_param);
  166. DBG("wf: CPU Fan control initialized.\n");
  167. DBG(" ttarged=%d.%03d, tmax=%d.%03d, min=%d RPM, max=%d RPM\n",
  168. FIX32TOPRINT(pid_param.ttarget), FIX32TOPRINT(pid_param.tmax),
  169. pid_param.min, pid_param.max);
  170. return;
  171. fail:
  172. printk(KERN_WARNING "windfarm: CPU fan config not found\n"
  173. "for this machine model, max fan speed\n");
  174. if (cpufreq_clamp)
  175. wf_control_set_max(cpufreq_clamp);
  176. if (fan_cpu_main)
  177. wf_control_set_max(fan_cpu_main);
  178. }
  179. static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
  180. {
  181. s32 new_setpoint, temp, power;
  182. int rc;
  183. if (--st->ticks != 0) {
  184. if (wf_smu_readjust)
  185. goto readjust;
  186. return;
  187. }
  188. st->ticks = WF_SMU_CPU_FANS_INTERVAL;
  189. rc = sensor_cpu_temp->ops->get_value(sensor_cpu_temp, &temp);
  190. if (rc) {
  191. printk(KERN_WARNING "windfarm: CPU temp sensor error %d\n",
  192. rc);
  193. wf_smu_failure_state |= FAILURE_SENSOR;
  194. return;
  195. }
  196. rc = sensor_cpu_power->ops->get_value(sensor_cpu_power, &power);
  197. if (rc) {
  198. printk(KERN_WARNING "windfarm: CPU power sensor error %d\n",
  199. rc);
  200. wf_smu_failure_state |= FAILURE_SENSOR;
  201. return;
  202. }
  203. DBG("wf_smu: CPU Fans tick ! CPU temp: %d.%03d, power: %d.%03d\n",
  204. FIX32TOPRINT(temp), FIX32TOPRINT(power));
  205. #ifdef HACKED_OVERTEMP
  206. if (temp > 0x4a0000)
  207. wf_smu_failure_state |= FAILURE_OVERTEMP;
  208. #else
  209. if (temp > st->pid.param.tmax)
  210. wf_smu_failure_state |= FAILURE_OVERTEMP;
  211. #endif
  212. new_setpoint = wf_cpu_pid_run(&st->pid, power, temp);
  213. DBG("wf_smu: new_setpoint: %d RPM\n", (int)new_setpoint);
  214. if (st->cpu_setpoint == new_setpoint)
  215. return;
  216. st->cpu_setpoint = new_setpoint;
  217. readjust:
  218. if (fan_cpu_main && wf_smu_failure_state == 0) {
  219. rc = fan_cpu_main->ops->set_value(fan_cpu_main,
  220. st->cpu_setpoint);
  221. if (rc) {
  222. printk(KERN_WARNING "windfarm: CPU main fan"
  223. " error %d\n", rc);
  224. wf_smu_failure_state |= FAILURE_FAN;
  225. }
  226. }
  227. if (fan_cpu_second && wf_smu_failure_state == 0) {
  228. rc = fan_cpu_second->ops->set_value(fan_cpu_second,
  229. st->cpu_setpoint);
  230. if (rc) {
  231. printk(KERN_WARNING "windfarm: CPU second fan"
  232. " error %d\n", rc);
  233. wf_smu_failure_state |= FAILURE_FAN;
  234. }
  235. }
  236. if (fan_cpu_third && wf_smu_failure_state == 0) {
  237. rc = fan_cpu_main->ops->set_value(fan_cpu_third,
  238. st->cpu_setpoint);
  239. if (rc) {
  240. printk(KERN_WARNING "windfarm: CPU third fan"
  241. " error %d\n", rc);
  242. wf_smu_failure_state |= FAILURE_FAN;
  243. }
  244. }
  245. }
  246. static void wf_smu_create_drive_fans(void)
  247. {
  248. struct wf_pid_param param = {
  249. .interval = 5,
  250. .history_len = 2,
  251. .gd = 0x01e00000,
  252. .gp = 0x00500000,
  253. .gr = 0x00000000,
  254. .itarget = 0x00200000,
  255. };
  256. /* Alloc & initialize state */
  257. wf_smu_drive_fans = kmalloc(sizeof(struct wf_smu_drive_fans_state),
  258. GFP_KERNEL);
  259. if (wf_smu_drive_fans == NULL) {
  260. printk(KERN_WARNING "windfarm: Memory allocation error"
  261. " max fan speed\n");
  262. goto fail;
  263. }
  264. wf_smu_drive_fans->ticks = 1;
  265. /* Fill PID params */
  266. param.additive = (fan_hd->type == WF_CONTROL_RPM_FAN);
  267. param.min = fan_hd->ops->get_min(fan_hd);
  268. param.max = fan_hd->ops->get_max(fan_hd);
  269. wf_pid_init(&wf_smu_drive_fans->pid, &param);
  270. DBG("wf: Drive Fan control initialized.\n");
  271. DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n",
  272. FIX32TOPRINT(param.itarget), param.min, param.max);
  273. return;
  274. fail:
  275. if (fan_hd)
  276. wf_control_set_max(fan_hd);
  277. }
  278. static void wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state *st)
  279. {
  280. s32 new_setpoint, temp;
  281. int rc;
  282. if (--st->ticks != 0) {
  283. if (wf_smu_readjust)
  284. goto readjust;
  285. return;
  286. }
  287. st->ticks = st->pid.param.interval;
  288. rc = sensor_hd_temp->ops->get_value(sensor_hd_temp, &temp);
  289. if (rc) {
  290. printk(KERN_WARNING "windfarm: HD temp sensor error %d\n",
  291. rc);
  292. wf_smu_failure_state |= FAILURE_SENSOR;
  293. return;
  294. }
  295. DBG("wf_smu: Drive Fans tick ! HD temp: %d.%03d\n",
  296. FIX32TOPRINT(temp));
  297. if (temp > (st->pid.param.itarget + 0x50000))
  298. wf_smu_failure_state |= FAILURE_OVERTEMP;
  299. new_setpoint = wf_pid_run(&st->pid, temp);
  300. DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint);
  301. if (st->setpoint == new_setpoint)
  302. return;
  303. st->setpoint = new_setpoint;
  304. readjust:
  305. if (fan_hd && wf_smu_failure_state == 0) {
  306. rc = fan_hd->ops->set_value(fan_hd, st->setpoint);
  307. if (rc) {
  308. printk(KERN_WARNING "windfarm: HD fan error %d\n",
  309. rc);
  310. wf_smu_failure_state |= FAILURE_FAN;
  311. }
  312. }
  313. }
  314. static void wf_smu_create_slots_fans(void)
  315. {
  316. struct wf_pid_param param = {
  317. .interval = 1,
  318. .history_len = 8,
  319. .gd = 0x00000000,
  320. .gp = 0x00000000,
  321. .gr = 0x00020000,
  322. .itarget = 0x00000000
  323. };
  324. /* Alloc & initialize state */
  325. wf_smu_slots_fans = kmalloc(sizeof(struct wf_smu_slots_fans_state),
  326. GFP_KERNEL);
  327. if (wf_smu_slots_fans == NULL) {
  328. printk(KERN_WARNING "windfarm: Memory allocation error"
  329. " max fan speed\n");
  330. goto fail;
  331. }
  332. wf_smu_slots_fans->ticks = 1;
  333. /* Fill PID params */
  334. param.additive = (fan_slots->type == WF_CONTROL_RPM_FAN);
  335. param.min = fan_slots->ops->get_min(fan_slots);
  336. param.max = fan_slots->ops->get_max(fan_slots);
  337. wf_pid_init(&wf_smu_slots_fans->pid, &param);
  338. DBG("wf: Slots Fan control initialized.\n");
  339. DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n",
  340. FIX32TOPRINT(param.itarget), param.min, param.max);
  341. return;
  342. fail:
  343. if (fan_slots)
  344. wf_control_set_max(fan_slots);
  345. }
  346. static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
  347. {
  348. s32 new_setpoint, power;
  349. int rc;
  350. if (--st->ticks != 0) {
  351. if (wf_smu_readjust)
  352. goto readjust;
  353. return;
  354. }
  355. st->ticks = st->pid.param.interval;
  356. rc = sensor_slots_power->ops->get_value(sensor_slots_power, &power);
  357. if (rc) {
  358. printk(KERN_WARNING "windfarm: Slots power sensor error %d\n",
  359. rc);
  360. wf_smu_failure_state |= FAILURE_SENSOR;
  361. return;
  362. }
  363. DBG("wf_smu: Slots Fans tick ! Slots power: %d.%03d\n",
  364. FIX32TOPRINT(power));
  365. #if 0 /* Check what makes a good overtemp condition */
  366. if (power > (st->pid.param.itarget + 0x50000))
  367. wf_smu_failure_state |= FAILURE_OVERTEMP;
  368. #endif
  369. new_setpoint = wf_pid_run(&st->pid, power);
  370. DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint);
  371. if (st->setpoint == new_setpoint)
  372. return;
  373. st->setpoint = new_setpoint;
  374. readjust:
  375. if (fan_slots && wf_smu_failure_state == 0) {
  376. rc = fan_slots->ops->set_value(fan_slots, st->setpoint);
  377. if (rc) {
  378. printk(KERN_WARNING "windfarm: Slots fan error %d\n",
  379. rc);
  380. wf_smu_failure_state |= FAILURE_FAN;
  381. }
  382. }
  383. }
  384. /*
  385. * ****** Setup / Init / Misc ... ******
  386. *
  387. */
  388. static void wf_smu_tick(void)
  389. {
  390. unsigned int last_failure = wf_smu_failure_state;
  391. unsigned int new_failure;
  392. if (!wf_smu_started) {
  393. DBG("wf: creating control loops !\n");
  394. wf_smu_create_drive_fans();
  395. wf_smu_create_slots_fans();
  396. wf_smu_create_cpu_fans();
  397. wf_smu_started = 1;
  398. }
  399. /* Skipping ticks */
  400. if (wf_smu_skipping && --wf_smu_skipping)
  401. return;
  402. wf_smu_failure_state = 0;
  403. if (wf_smu_drive_fans)
  404. wf_smu_drive_fans_tick(wf_smu_drive_fans);
  405. if (wf_smu_slots_fans)
  406. wf_smu_slots_fans_tick(wf_smu_slots_fans);
  407. if (wf_smu_cpu_fans)
  408. wf_smu_cpu_fans_tick(wf_smu_cpu_fans);
  409. wf_smu_readjust = 0;
  410. new_failure = wf_smu_failure_state & ~last_failure;
  411. /* If entering failure mode, clamp cpufreq and ramp all
  412. * fans to full speed.
  413. */
  414. if (wf_smu_failure_state && !last_failure) {
  415. if (cpufreq_clamp)
  416. wf_control_set_max(cpufreq_clamp);
  417. if (fan_cpu_main)
  418. wf_control_set_max(fan_cpu_main);
  419. if (fan_cpu_second)
  420. wf_control_set_max(fan_cpu_second);
  421. if (fan_cpu_third)
  422. wf_control_set_max(fan_cpu_third);
  423. if (fan_hd)
  424. wf_control_set_max(fan_hd);
  425. if (fan_slots)
  426. wf_control_set_max(fan_slots);
  427. }
  428. /* If leaving failure mode, unclamp cpufreq and readjust
  429. * all fans on next iteration
  430. */
  431. if (!wf_smu_failure_state && last_failure) {
  432. if (cpufreq_clamp)
  433. wf_control_set_min(cpufreq_clamp);
  434. wf_smu_readjust = 1;
  435. }
  436. /* Overtemp condition detected, notify and start skipping a couple
  437. * ticks to let the temperature go down
  438. */
  439. if (new_failure & FAILURE_OVERTEMP) {
  440. wf_set_overtemp();
  441. wf_smu_skipping = 2;
  442. }
  443. /* We only clear the overtemp condition if overtemp is cleared
  444. * _and_ no other failure is present. Since a sensor error will
  445. * clear the overtemp condition (can't measure temperature) at
  446. * the control loop levels, but we don't want to keep it clear
  447. * here in this case
  448. */
  449. if (new_failure == 0 && last_failure & FAILURE_OVERTEMP)
  450. wf_clear_overtemp();
  451. }
  452. static void wf_smu_new_control(struct wf_control *ct)
  453. {
  454. if (wf_smu_all_controls_ok)
  455. return;
  456. if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) {
  457. if (wf_get_control(ct) == 0)
  458. fan_cpu_main = ct;
  459. }
  460. if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) {
  461. if (wf_get_control(ct) == 0)
  462. fan_cpu_second = ct;
  463. }
  464. if (fan_cpu_third == NULL && !strcmp(ct->name, "cpu-front-fan-0")) {
  465. if (wf_get_control(ct) == 0)
  466. fan_cpu_third = ct;
  467. }
  468. if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) {
  469. if (wf_get_control(ct) == 0)
  470. cpufreq_clamp = ct;
  471. }
  472. if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {
  473. if (wf_get_control(ct) == 0)
  474. fan_hd = ct;
  475. }
  476. if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) {
  477. if (wf_get_control(ct) == 0)
  478. fan_slots = ct;
  479. }
  480. if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd &&
  481. fan_slots && cpufreq_clamp)
  482. wf_smu_all_controls_ok = 1;
  483. }
  484. static void wf_smu_new_sensor(struct wf_sensor *sr)
  485. {
  486. if (wf_smu_all_sensors_ok)
  487. return;
  488. if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {
  489. if (wf_get_sensor(sr) == 0)
  490. sensor_cpu_power = sr;
  491. }
  492. if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {
  493. if (wf_get_sensor(sr) == 0)
  494. sensor_cpu_temp = sr;
  495. }
  496. if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {
  497. if (wf_get_sensor(sr) == 0)
  498. sensor_hd_temp = sr;
  499. }
  500. if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) {
  501. if (wf_get_sensor(sr) == 0)
  502. sensor_slots_power = sr;
  503. }
  504. if (sensor_cpu_power && sensor_cpu_temp &&
  505. sensor_hd_temp && sensor_slots_power)
  506. wf_smu_all_sensors_ok = 1;
  507. }
  508. static int wf_smu_notify(struct notifier_block *self,
  509. unsigned long event, void *data)
  510. {
  511. switch(event) {
  512. case WF_EVENT_NEW_CONTROL:
  513. DBG("wf: new control %s detected\n",
  514. ((struct wf_control *)data)->name);
  515. wf_smu_new_control(data);
  516. wf_smu_readjust = 1;
  517. break;
  518. case WF_EVENT_NEW_SENSOR:
  519. DBG("wf: new sensor %s detected\n",
  520. ((struct wf_sensor *)data)->name);
  521. wf_smu_new_sensor(data);
  522. break;
  523. case WF_EVENT_TICK:
  524. if (wf_smu_all_controls_ok && wf_smu_all_sensors_ok)
  525. wf_smu_tick();
  526. }
  527. return 0;
  528. }
  529. static struct notifier_block wf_smu_events = {
  530. .notifier_call = wf_smu_notify,
  531. };
  532. static int wf_init_pm(void)
  533. {
  534. printk(KERN_INFO "windfarm: Initializing for Desktop G5 model\n");
  535. return 0;
  536. }
  537. static int wf_smu_probe(struct platform_device *ddev)
  538. {
  539. wf_register_client(&wf_smu_events);
  540. return 0;
  541. }
  542. static int __devexit wf_smu_remove(struct platform_device *ddev)
  543. {
  544. wf_unregister_client(&wf_smu_events);
  545. /* XXX We don't have yet a guarantee that our callback isn't
  546. * in progress when returning from wf_unregister_client, so
  547. * we add an arbitrary delay. I'll have to fix that in the core
  548. */
  549. msleep(1000);
  550. /* Release all sensors */
  551. /* One more crappy race: I don't think we have any guarantee here
  552. * that the attribute callback won't race with the sensor beeing
  553. * disposed of, and I'm not 100% certain what best way to deal
  554. * with that except by adding locks all over... I'll do that
  555. * eventually but heh, who ever rmmod this module anyway ?
  556. */
  557. if (sensor_cpu_power)
  558. wf_put_sensor(sensor_cpu_power);
  559. if (sensor_cpu_temp)
  560. wf_put_sensor(sensor_cpu_temp);
  561. if (sensor_hd_temp)
  562. wf_put_sensor(sensor_hd_temp);
  563. if (sensor_slots_power)
  564. wf_put_sensor(sensor_slots_power);
  565. /* Release all controls */
  566. if (fan_cpu_main)
  567. wf_put_control(fan_cpu_main);
  568. if (fan_cpu_second)
  569. wf_put_control(fan_cpu_second);
  570. if (fan_cpu_third)
  571. wf_put_control(fan_cpu_third);
  572. if (fan_hd)
  573. wf_put_control(fan_hd);
  574. if (fan_slots)
  575. wf_put_control(fan_slots);
  576. if (cpufreq_clamp)
  577. wf_put_control(cpufreq_clamp);
  578. /* Destroy control loops state structures */
  579. kfree(wf_smu_slots_fans);
  580. kfree(wf_smu_drive_fans);
  581. kfree(wf_smu_cpu_fans);
  582. return 0;
  583. }
  584. static struct platform_driver wf_smu_driver = {
  585. .probe = wf_smu_probe,
  586. .remove = __devexit_p(wf_smu_remove),
  587. .driver = {
  588. .name = "windfarm",
  589. .owner = THIS_MODULE,
  590. },
  591. };
  592. static int __init wf_smu_init(void)
  593. {
  594. int rc = -ENODEV;
  595. if (of_machine_is_compatible("PowerMac9,1"))
  596. rc = wf_init_pm();
  597. if (rc == 0) {
  598. #ifdef MODULE
  599. request_module("windfarm_smu_controls");
  600. request_module("windfarm_smu_sensors");
  601. request_module("windfarm_lm75_sensor");
  602. request_module("windfarm_cpufreq_clamp");
  603. #endif /* MODULE */
  604. platform_driver_register(&wf_smu_driver);
  605. }
  606. return rc;
  607. }
  608. static void __exit wf_smu_exit(void)
  609. {
  610. platform_driver_unregister(&wf_smu_driver);
  611. }
  612. module_init(wf_smu_init);
  613. module_exit(wf_smu_exit);
  614. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  615. MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1");
  616. MODULE_LICENSE("GPL");
  617. MODULE_ALIAS("platform:windfarm");