windfarm_pm91.c 18 KB

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