windfarm_rm31.c 18 KB

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