windfarm_rm31.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Windfarm PowerMac thermal control.
  3. * Control loops for RackMack3,1 (Xserve G5)
  4. *
  5. * Copyright (C) 2012 Benjamin Herrenschmidt, IBM Corp.
  6. *
  7. * Use and redistribute under the terms of the GNU GPL v2.
  8. */
  9. #include <linux/types.h>
  10. #include <linux/errno.h>
  11. #include <linux/kernel.h>
  12. #include <linux/device.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/reboot.h>
  15. #include <asm/prom.h>
  16. #include <asm/smu.h>
  17. #include "windfarm.h"
  18. #include "windfarm_pid.h"
  19. #include "windfarm_mpu.h"
  20. #define VERSION "1.0"
  21. #undef DEBUG
  22. #undef LOTSA_DEBUG
  23. #ifdef DEBUG
  24. #define DBG(args...) printk(args)
  25. #else
  26. #define DBG(args...) do { } while(0)
  27. #endif
  28. #ifdef LOTSA_DEBUG
  29. #define DBG_LOTS(args...) printk(args)
  30. #else
  31. #define DBG_LOTS(args...) do { } while(0)
  32. #endif
  33. /* define this to force CPU overtemp to 60 degree, useful for testing
  34. * the overtemp code
  35. */
  36. #undef HACKED_OVERTEMP
  37. /* We currently only handle 2 chips */
  38. #define NR_CHIPS 2
  39. #define NR_CPU_FANS 3 * NR_CHIPS
  40. /* Controls and sensors */
  41. static struct wf_sensor *sens_cpu_temp[NR_CHIPS];
  42. static struct wf_sensor *sens_cpu_volts[NR_CHIPS];
  43. static struct wf_sensor *sens_cpu_amps[NR_CHIPS];
  44. static struct wf_sensor *backside_temp;
  45. static struct wf_sensor *slots_temp;
  46. static struct wf_sensor *dimms_temp;
  47. static struct wf_control *cpu_fans[NR_CHIPS][3];
  48. static struct wf_control *backside_fan;
  49. static struct wf_control *slots_fan;
  50. static struct wf_control *cpufreq_clamp;
  51. /* We keep a temperature history for average calculation of 180s */
  52. #define CPU_TEMP_HIST_SIZE 180
  53. /* PID loop state */
  54. static const struct mpu_data *cpu_mpu_data[NR_CHIPS];
  55. static struct wf_cpu_pid_state cpu_pid[NR_CHIPS];
  56. static u32 cpu_thist[CPU_TEMP_HIST_SIZE];
  57. static int cpu_thist_pt;
  58. static s64 cpu_thist_total;
  59. static s32 cpu_all_tmax = 100 << 16;
  60. static struct wf_pid_state backside_pid;
  61. static int backside_tick;
  62. static struct wf_pid_state slots_pid;
  63. static int slots_tick;
  64. static int slots_speed;
  65. static struct wf_pid_state dimms_pid;
  66. static int dimms_output_clamp;
  67. static int nr_chips;
  68. static bool have_all_controls;
  69. static bool have_all_sensors;
  70. static bool started;
  71. static int failure_state;
  72. #define FAILURE_SENSOR 1
  73. #define FAILURE_FAN 2
  74. #define FAILURE_PERM 4
  75. #define FAILURE_LOW_OVERTEMP 8
  76. #define FAILURE_HIGH_OVERTEMP 16
  77. /* Overtemp values */
  78. #define LOW_OVER_AVERAGE 0
  79. #define LOW_OVER_IMMEDIATE (10 << 16)
  80. #define LOW_OVER_CLEAR ((-10) << 16)
  81. #define HIGH_OVER_IMMEDIATE (14 << 16)
  82. #define HIGH_OVER_AVERAGE (10 << 16)
  83. #define HIGH_OVER_IMMEDIATE (14 << 16)
  84. static void cpu_max_all_fans(void)
  85. {
  86. int i;
  87. /* We max all CPU fans in case of a sensor error. We also do the
  88. * cpufreq clamping now, even if it's supposedly done later by the
  89. * generic code anyway, we do it earlier here to react faster
  90. */
  91. if (cpufreq_clamp)
  92. wf_control_set_max(cpufreq_clamp);
  93. for (i = 0; i < nr_chips; i++) {
  94. if (cpu_fans[i][0])
  95. wf_control_set_max(cpu_fans[i][0]);
  96. if (cpu_fans[i][1])
  97. wf_control_set_max(cpu_fans[i][1]);
  98. if (cpu_fans[i][2])
  99. wf_control_set_max(cpu_fans[i][2]);
  100. }
  101. }
  102. static int cpu_check_overtemp(s32 temp)
  103. {
  104. int new_state = 0;
  105. s32 t_avg, t_old;
  106. static bool first = true;
  107. /* First check for immediate overtemps */
  108. if (temp >= (cpu_all_tmax + LOW_OVER_IMMEDIATE)) {
  109. new_state |= FAILURE_LOW_OVERTEMP;
  110. if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
  111. printk(KERN_ERR "windfarm: Overtemp due to immediate CPU"
  112. " temperature !\n");
  113. }
  114. if (temp >= (cpu_all_tmax + HIGH_OVER_IMMEDIATE)) {
  115. new_state |= FAILURE_HIGH_OVERTEMP;
  116. if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
  117. printk(KERN_ERR "windfarm: Critical overtemp due to"
  118. " immediate CPU temperature !\n");
  119. }
  120. /*
  121. * The first time around, initialize the array with the first
  122. * temperature reading
  123. */
  124. if (first) {
  125. int i;
  126. cpu_thist_total = 0;
  127. for (i = 0; i < CPU_TEMP_HIST_SIZE; i++) {
  128. cpu_thist[i] = temp;
  129. cpu_thist_total += temp;
  130. }
  131. first = false;
  132. }
  133. /*
  134. * We calculate a history of max temperatures and use that for the
  135. * overtemp management
  136. */
  137. t_old = cpu_thist[cpu_thist_pt];
  138. cpu_thist[cpu_thist_pt] = temp;
  139. cpu_thist_pt = (cpu_thist_pt + 1) % CPU_TEMP_HIST_SIZE;
  140. cpu_thist_total -= t_old;
  141. cpu_thist_total += temp;
  142. t_avg = cpu_thist_total / CPU_TEMP_HIST_SIZE;
  143. DBG_LOTS(" t_avg = %d.%03d (out: %d.%03d, in: %d.%03d)\n",
  144. FIX32TOPRINT(t_avg), FIX32TOPRINT(t_old), FIX32TOPRINT(temp));
  145. /* Now check for average overtemps */
  146. if (t_avg >= (cpu_all_tmax + LOW_OVER_AVERAGE)) {
  147. new_state |= FAILURE_LOW_OVERTEMP;
  148. if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
  149. printk(KERN_ERR "windfarm: Overtemp due to average CPU"
  150. " temperature !\n");
  151. }
  152. if (t_avg >= (cpu_all_tmax + HIGH_OVER_AVERAGE)) {
  153. new_state |= FAILURE_HIGH_OVERTEMP;
  154. if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
  155. printk(KERN_ERR "windfarm: Critical overtemp due to"
  156. " average CPU temperature !\n");
  157. }
  158. /* Now handle overtemp conditions. We don't currently use the windfarm
  159. * overtemp handling core as it's not fully suited to the needs of those
  160. * new machine. This will be fixed later.
  161. */
  162. if (new_state) {
  163. /* High overtemp -> immediate shutdown */
  164. if (new_state & FAILURE_HIGH_OVERTEMP)
  165. machine_power_off();
  166. if ((failure_state & new_state) != new_state)
  167. cpu_max_all_fans();
  168. failure_state |= new_state;
  169. } else if ((failure_state & FAILURE_LOW_OVERTEMP) &&
  170. (temp < (cpu_all_tmax + LOW_OVER_CLEAR))) {
  171. printk(KERN_ERR "windfarm: Overtemp condition cleared !\n");
  172. failure_state &= ~FAILURE_LOW_OVERTEMP;
  173. }
  174. return failure_state & (FAILURE_LOW_OVERTEMP | FAILURE_HIGH_OVERTEMP);
  175. }
  176. static int read_one_cpu_vals(int cpu, s32 *temp, s32 *power)
  177. {
  178. s32 dtemp, volts, amps;
  179. int rc;
  180. /* Get diode temperature */
  181. rc = wf_sensor_get(sens_cpu_temp[cpu], &dtemp);
  182. if (rc) {
  183. DBG(" CPU%d: temp reading error !\n", cpu);
  184. return -EIO;
  185. }
  186. DBG_LOTS(" CPU%d: temp = %d.%03d\n", cpu, FIX32TOPRINT((dtemp)));
  187. *temp = dtemp;
  188. /* Get voltage */
  189. rc = wf_sensor_get(sens_cpu_volts[cpu], &volts);
  190. if (rc) {
  191. DBG(" CPU%d, volts reading error !\n", cpu);
  192. return -EIO;
  193. }
  194. DBG_LOTS(" CPU%d: volts = %d.%03d\n", cpu, FIX32TOPRINT((volts)));
  195. /* Get current */
  196. rc = wf_sensor_get(sens_cpu_amps[cpu], &amps);
  197. if (rc) {
  198. DBG(" CPU%d, current reading error !\n", cpu);
  199. return -EIO;
  200. }
  201. DBG_LOTS(" CPU%d: amps = %d.%03d\n", cpu, FIX32TOPRINT((amps)));
  202. /* Calculate power */
  203. /* Scale voltage and current raw sensor values according to fixed scales
  204. * obtained in Darwin and calculate power from I and V
  205. */
  206. *power = (((u64)volts) * ((u64)amps)) >> 16;
  207. DBG_LOTS(" CPU%d: power = %d.%03d\n", cpu, FIX32TOPRINT((*power)));
  208. return 0;
  209. }
  210. static void cpu_fans_tick(void)
  211. {
  212. int err, cpu, i;
  213. s32 speed, temp, power, t_max = 0;
  214. DBG_LOTS("* cpu fans_tick_split()\n");
  215. for (cpu = 0; cpu < nr_chips; ++cpu) {
  216. struct wf_cpu_pid_state *sp = &cpu_pid[cpu];
  217. /* Read current speed */
  218. wf_control_get(cpu_fans[cpu][0], &sp->target);
  219. err = read_one_cpu_vals(cpu, &temp, &power);
  220. if (err) {
  221. failure_state |= FAILURE_SENSOR;
  222. cpu_max_all_fans();
  223. return;
  224. }
  225. /* Keep track of highest temp */
  226. t_max = max(t_max, temp);
  227. /* Handle possible overtemps */
  228. if (cpu_check_overtemp(t_max))
  229. return;
  230. /* Run PID */
  231. wf_cpu_pid_run(sp, power, temp);
  232. DBG_LOTS(" CPU%d: target = %d RPM\n", cpu, sp->target);
  233. /* Apply DIMMs clamp */
  234. speed = max(sp->target, dimms_output_clamp);
  235. /* Apply result to all cpu fans */
  236. for (i = 0; i < 3; i++) {
  237. err = wf_control_set(cpu_fans[cpu][i], speed);
  238. if (err) {
  239. pr_warning("wf_rm31: Fan %s reports error %d\n",
  240. cpu_fans[cpu][i]->name, err);
  241. failure_state |= FAILURE_FAN;
  242. }
  243. }
  244. }
  245. }
  246. /* Implementation... */
  247. static int cpu_setup_pid(int cpu)
  248. {
  249. struct wf_cpu_pid_param pid;
  250. const struct mpu_data *mpu = cpu_mpu_data[cpu];
  251. s32 tmax, ttarget, ptarget;
  252. int fmin, fmax, hsize;
  253. /* Get PID params from the appropriate MPU EEPROM */
  254. tmax = mpu->tmax << 16;
  255. ttarget = mpu->ttarget << 16;
  256. ptarget = ((s32)(mpu->pmaxh - mpu->padjmax)) << 16;
  257. DBG("wf_72: CPU%d ttarget = %d.%03d, tmax = %d.%03d\n",
  258. cpu, FIX32TOPRINT(ttarget), FIX32TOPRINT(tmax));
  259. /* We keep a global tmax for overtemp calculations */
  260. if (tmax < cpu_all_tmax)
  261. cpu_all_tmax = tmax;
  262. /* Set PID min/max by using the rear fan min/max */
  263. fmin = wf_control_get_min(cpu_fans[cpu][0]);
  264. fmax = wf_control_get_max(cpu_fans[cpu][0]);
  265. DBG("wf_72: CPU%d max RPM range = [%d..%d]\n", cpu, fmin, fmax);
  266. /* History size */
  267. hsize = min_t(int, mpu->tguardband, WF_PID_MAX_HISTORY);
  268. DBG("wf_72: CPU%d history size = %d\n", cpu, hsize);
  269. /* Initialize PID loop */
  270. pid.interval = 1; /* seconds */
  271. pid.history_len = hsize;
  272. pid.gd = mpu->pid_gd;
  273. pid.gp = mpu->pid_gp;
  274. pid.gr = mpu->pid_gr;
  275. pid.tmax = tmax;
  276. pid.ttarget = ttarget;
  277. pid.pmaxadj = ptarget;
  278. pid.min = fmin;
  279. pid.max = fmax;
  280. wf_cpu_pid_init(&cpu_pid[cpu], &pid);
  281. cpu_pid[cpu].target = 4000;
  282. return 0;
  283. }
  284. /* Backside/U3 fan */
  285. static struct wf_pid_param backside_param = {
  286. .interval = 1,
  287. .history_len = 2,
  288. .gd = 0x00500000,
  289. .gp = 0x0004cccc,
  290. .gr = 0,
  291. .itarget = 70 << 16,
  292. .additive = 0,
  293. .min = 20,
  294. .max = 100,
  295. };
  296. /* DIMMs temperature (clamp the backside fan) */
  297. static struct wf_pid_param dimms_param = {
  298. .interval = 1,
  299. .history_len = 20,
  300. .gd = 0,
  301. .gp = 0,
  302. .gr = 0x06553600,
  303. .itarget = 50 << 16,
  304. .additive = 0,
  305. .min = 4000,
  306. .max = 14000,
  307. };
  308. static void backside_fan_tick(void)
  309. {
  310. s32 temp, dtemp;
  311. int speed, dspeed, fan_min;
  312. int err;
  313. if (!backside_fan || !backside_temp || !dimms_temp || !backside_tick)
  314. return;
  315. if (--backside_tick > 0)
  316. return;
  317. backside_tick = backside_pid.param.interval;
  318. DBG_LOTS("* backside fans tick\n");
  319. /* Update fan speed from actual fans */
  320. err = wf_control_get(backside_fan, &speed);
  321. if (!err)
  322. backside_pid.target = speed;
  323. err = wf_sensor_get(backside_temp, &temp);
  324. if (err) {
  325. printk(KERN_WARNING "windfarm: U3 temp sensor error %d\n",
  326. err);
  327. failure_state |= FAILURE_SENSOR;
  328. wf_control_set_max(backside_fan);
  329. return;
  330. }
  331. speed = wf_pid_run(&backside_pid, temp);
  332. DBG_LOTS("backside PID temp=%d.%.3d speed=%d\n",
  333. FIX32TOPRINT(temp), speed);
  334. err = wf_sensor_get(dimms_temp, &dtemp);
  335. if (err) {
  336. printk(KERN_WARNING "windfarm: DIMMs temp sensor error %d\n",
  337. err);
  338. failure_state |= FAILURE_SENSOR;
  339. wf_control_set_max(backside_fan);
  340. return;
  341. }
  342. dspeed = wf_pid_run(&dimms_pid, dtemp);
  343. dimms_output_clamp = dspeed;
  344. fan_min = (dspeed * 100) / 14000;
  345. fan_min = max(fan_min, backside_param.min);
  346. speed = max(speed, fan_min);
  347. err = wf_control_set(backside_fan, speed);
  348. if (err) {
  349. printk(KERN_WARNING "windfarm: backside fan error %d\n", err);
  350. failure_state |= FAILURE_FAN;
  351. }
  352. }
  353. static void backside_setup_pid(void)
  354. {
  355. /* first time initialize things */
  356. s32 fmin = wf_control_get_min(backside_fan);
  357. s32 fmax = wf_control_get_max(backside_fan);
  358. struct wf_pid_param param;
  359. param = backside_param;
  360. param.min = max(param.min, fmin);
  361. param.max = min(param.max, fmax);
  362. wf_pid_init(&backside_pid, &param);
  363. param = dimms_param;
  364. wf_pid_init(&dimms_pid, &param);
  365. backside_tick = 1;
  366. pr_info("wf_rm31: Backside control loop started.\n");
  367. }
  368. /* Slots fan */
  369. static const struct wf_pid_param slots_param = {
  370. .interval = 1,
  371. .history_len = 20,
  372. .gd = 0,
  373. .gp = 0,
  374. .gr = 0x00100000,
  375. .itarget = 3200000,
  376. .additive = 0,
  377. .min = 20,
  378. .max = 100,
  379. };
  380. static void slots_fan_tick(void)
  381. {
  382. s32 temp;
  383. int speed;
  384. int err;
  385. if (!slots_fan || !slots_temp || !slots_tick)
  386. return;
  387. if (--slots_tick > 0)
  388. return;
  389. slots_tick = slots_pid.param.interval;
  390. DBG_LOTS("* slots fans tick\n");
  391. err = wf_sensor_get(slots_temp, &temp);
  392. if (err) {
  393. pr_warning("wf_rm31: slots temp sensor error %d\n", err);
  394. failure_state |= FAILURE_SENSOR;
  395. wf_control_set_max(slots_fan);
  396. return;
  397. }
  398. speed = wf_pid_run(&slots_pid, temp);
  399. DBG_LOTS("slots PID temp=%d.%.3d speed=%d\n",
  400. FIX32TOPRINT(temp), speed);
  401. slots_speed = speed;
  402. err = wf_control_set(slots_fan, speed);
  403. if (err) {
  404. printk(KERN_WARNING "windfarm: slots bay fan error %d\n", err);
  405. failure_state |= FAILURE_FAN;
  406. }
  407. }
  408. static void slots_setup_pid(void)
  409. {
  410. /* first time initialize things */
  411. s32 fmin = wf_control_get_min(slots_fan);
  412. s32 fmax = wf_control_get_max(slots_fan);
  413. struct wf_pid_param param = slots_param;
  414. param.min = max(param.min, fmin);
  415. param.max = min(param.max, fmax);
  416. wf_pid_init(&slots_pid, &param);
  417. slots_tick = 1;
  418. pr_info("wf_rm31: Slots control loop started.\n");
  419. }
  420. static void set_fail_state(void)
  421. {
  422. cpu_max_all_fans();
  423. if (backside_fan)
  424. wf_control_set_max(backside_fan);
  425. if (slots_fan)
  426. wf_control_set_max(slots_fan);
  427. }
  428. static void rm31_tick(void)
  429. {
  430. int i, last_failure;
  431. if (!started) {
  432. started = 1;
  433. printk(KERN_INFO "windfarm: CPUs control loops started.\n");
  434. for (i = 0; i < nr_chips; ++i) {
  435. if (cpu_setup_pid(i) < 0) {
  436. failure_state = FAILURE_PERM;
  437. set_fail_state();
  438. break;
  439. }
  440. }
  441. DBG_LOTS("cpu_all_tmax=%d.%03d\n", FIX32TOPRINT(cpu_all_tmax));
  442. backside_setup_pid();
  443. slots_setup_pid();
  444. #ifdef HACKED_OVERTEMP
  445. cpu_all_tmax = 60 << 16;
  446. #endif
  447. }
  448. /* Permanent failure, bail out */
  449. if (failure_state & FAILURE_PERM)
  450. return;
  451. /*
  452. * Clear all failure bits except low overtemp which will be eventually
  453. * cleared by the control loop itself
  454. */
  455. last_failure = failure_state;
  456. failure_state &= FAILURE_LOW_OVERTEMP;
  457. backside_fan_tick();
  458. slots_fan_tick();
  459. /* We do CPUs last because they can be clamped high by
  460. * DIMM temperature
  461. */
  462. cpu_fans_tick();
  463. DBG_LOTS(" last_failure: 0x%x, failure_state: %x\n",
  464. last_failure, failure_state);
  465. /* Check for failures. Any failure causes cpufreq clamping */
  466. if (failure_state && last_failure == 0 && cpufreq_clamp)
  467. wf_control_set_max(cpufreq_clamp);
  468. if (failure_state == 0 && last_failure && cpufreq_clamp)
  469. wf_control_set_min(cpufreq_clamp);
  470. /* That's it for now, we might want to deal with other failures
  471. * differently in the future though
  472. */
  473. }
  474. static void rm31_new_control(struct wf_control *ct)
  475. {
  476. bool all_controls;
  477. if (!strcmp(ct->name, "cpu-fan-a-0"))
  478. cpu_fans[0][0] = ct;
  479. else if (!strcmp(ct->name, "cpu-fan-b-0"))
  480. cpu_fans[0][1] = ct;
  481. else if (!strcmp(ct->name, "cpu-fan-c-0"))
  482. cpu_fans[0][2] = ct;
  483. else if (!strcmp(ct->name, "cpu-fan-a-1"))
  484. cpu_fans[1][0] = ct;
  485. else if (!strcmp(ct->name, "cpu-fan-b-1"))
  486. cpu_fans[1][1] = ct;
  487. else if (!strcmp(ct->name, "cpu-fan-c-1"))
  488. cpu_fans[1][2] = ct;
  489. else if (!strcmp(ct->name, "backside-fan"))
  490. backside_fan = ct;
  491. else if (!strcmp(ct->name, "slots-fan"))
  492. slots_fan = ct;
  493. else if (!strcmp(ct->name, "cpufreq-clamp"))
  494. cpufreq_clamp = ct;
  495. all_controls =
  496. cpu_fans[0][0] &&
  497. cpu_fans[0][1] &&
  498. cpu_fans[0][2] &&
  499. backside_fan &&
  500. slots_fan;
  501. if (nr_chips > 1)
  502. all_controls &=
  503. cpu_fans[1][0] &&
  504. cpu_fans[1][1] &&
  505. cpu_fans[1][2];
  506. have_all_controls = all_controls;
  507. }
  508. static void rm31_new_sensor(struct wf_sensor *sr)
  509. {
  510. bool all_sensors;
  511. if (!strcmp(sr->name, "cpu-diode-temp-0"))
  512. sens_cpu_temp[0] = sr;
  513. else if (!strcmp(sr->name, "cpu-diode-temp-1"))
  514. sens_cpu_temp[1] = sr;
  515. else if (!strcmp(sr->name, "cpu-voltage-0"))
  516. sens_cpu_volts[0] = sr;
  517. else if (!strcmp(sr->name, "cpu-voltage-1"))
  518. sens_cpu_volts[1] = sr;
  519. else if (!strcmp(sr->name, "cpu-current-0"))
  520. sens_cpu_amps[0] = sr;
  521. else if (!strcmp(sr->name, "cpu-current-1"))
  522. sens_cpu_amps[1] = sr;
  523. else if (!strcmp(sr->name, "backside-temp"))
  524. backside_temp = sr;
  525. else if (!strcmp(sr->name, "slots-temp"))
  526. slots_temp = sr;
  527. else if (!strcmp(sr->name, "dimms-temp"))
  528. dimms_temp = sr;
  529. all_sensors =
  530. sens_cpu_temp[0] &&
  531. sens_cpu_volts[0] &&
  532. sens_cpu_amps[0] &&
  533. backside_temp &&
  534. slots_temp &&
  535. dimms_temp;
  536. if (nr_chips > 1)
  537. all_sensors &=
  538. sens_cpu_temp[1] &&
  539. sens_cpu_volts[1] &&
  540. sens_cpu_amps[1];
  541. have_all_sensors = all_sensors;
  542. }
  543. static int rm31_wf_notify(struct notifier_block *self,
  544. unsigned long event, void *data)
  545. {
  546. switch (event) {
  547. case WF_EVENT_NEW_SENSOR:
  548. rm31_new_sensor(data);
  549. break;
  550. case WF_EVENT_NEW_CONTROL:
  551. rm31_new_control(data);
  552. break;
  553. case WF_EVENT_TICK:
  554. if (have_all_controls && have_all_sensors)
  555. rm31_tick();
  556. }
  557. return 0;
  558. }
  559. static struct notifier_block rm31_events = {
  560. .notifier_call = rm31_wf_notify,
  561. };
  562. static int wf_rm31_probe(struct platform_device *dev)
  563. {
  564. wf_register_client(&rm31_events);
  565. return 0;
  566. }
  567. static int wf_rm31_remove(struct platform_device *dev)
  568. {
  569. wf_unregister_client(&rm31_events);
  570. /* should release all sensors and controls */
  571. return 0;
  572. }
  573. static struct platform_driver wf_rm31_driver = {
  574. .probe = wf_rm31_probe,
  575. .remove = wf_rm31_remove,
  576. .driver = {
  577. .name = "windfarm",
  578. .owner = THIS_MODULE,
  579. },
  580. };
  581. static int __init wf_rm31_init(void)
  582. {
  583. struct device_node *cpu;
  584. int i;
  585. if (!of_machine_is_compatible("RackMac3,1"))
  586. return -ENODEV;
  587. /* Count the number of CPU cores */
  588. nr_chips = 0;
  589. for_each_node_by_type(cpu, "cpu")
  590. ++nr_chips;
  591. if (nr_chips > NR_CHIPS)
  592. nr_chips = NR_CHIPS;
  593. pr_info("windfarm: Initializing for desktop G5 with %d chips\n",
  594. nr_chips);
  595. /* Get MPU data for each CPU */
  596. for (i = 0; i < nr_chips; i++) {
  597. cpu_mpu_data[i] = wf_get_mpu(i);
  598. if (!cpu_mpu_data[i]) {
  599. pr_err("wf_rm31: Failed to find MPU data for CPU %d\n", i);
  600. return -ENXIO;
  601. }
  602. }
  603. #ifdef MODULE
  604. request_module("windfarm_fcu_controls");
  605. request_module("windfarm_lm75_sensor");
  606. request_module("windfarm_lm87_sensor");
  607. request_module("windfarm_ad7417_sensor");
  608. request_module("windfarm_max6690_sensor");
  609. request_module("windfarm_cpufreq_clamp");
  610. #endif /* MODULE */
  611. platform_driver_register(&wf_rm31_driver);
  612. return 0;
  613. }
  614. static void __exit wf_rm31_exit(void)
  615. {
  616. platform_driver_unregister(&wf_rm31_driver);
  617. }
  618. module_init(wf_rm31_init);
  619. module_exit(wf_rm31_exit);
  620. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  621. MODULE_DESCRIPTION("Thermal control for Xserve G5");
  622. MODULE_LICENSE("GPL");
  623. MODULE_ALIAS("platform:windfarm");