therm_pm72.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  1. /*
  2. * Device driver for the thermostats & fan controller of the
  3. * Apple G5 "PowerMac7,2" desktop machines.
  4. *
  5. * (c) Copyright IBM Corp. 2003-2004
  6. *
  7. * Maintained by: Benjamin Herrenschmidt
  8. * <benh@kernel.crashing.org>
  9. *
  10. *
  11. * The algorithm used is the PID control algorithm, used the same
  12. * way the published Darwin code does, using the same values that
  13. * are present in the Darwin 7.0 snapshot property lists.
  14. *
  15. * As far as the CPUs control loops are concerned, I use the
  16. * calibration & PID constants provided by the EEPROM,
  17. * I do _not_ embed any value from the property lists, as the ones
  18. * provided by Darwin 7.0 seem to always have an older version that
  19. * what I've seen on the actual computers.
  20. * It would be interesting to verify that though. Darwin has a
  21. * version code of 1.0.0d11 for all control loops it seems, while
  22. * so far, the machines EEPROMs contain a dataset versioned 1.0.0f
  23. *
  24. * Darwin doesn't provide source to all parts, some missing
  25. * bits like the AppleFCU driver or the actual scale of some
  26. * of the values returned by sensors had to be "guessed" some
  27. * way... or based on what Open Firmware does.
  28. *
  29. * I didn't yet figure out how to get the slots power consumption
  30. * out of the FCU, so that part has not been implemented yet and
  31. * the slots fan is set to a fixed 50% PWM, hoping this value is
  32. * safe enough ...
  33. *
  34. * Note: I have observed strange oscillations of the CPU control
  35. * loop on a dual G5 here. When idle, the CPU exhaust fan tend to
  36. * oscillates slowly (over several minutes) between the minimum
  37. * of 300RPMs and approx. 1000 RPMs. I don't know what is causing
  38. * this, it could be some incorrect constant or an error in the
  39. * way I ported the algorithm, or it could be just normal. I
  40. * don't have full understanding on the way Apple tweaked the PID
  41. * algorithm for the CPU control, it is definitely not a standard
  42. * implementation...
  43. *
  44. * TODO: - Check MPU structure version/signature
  45. * - Add things like /sbin/overtemp for non-critical
  46. * overtemp conditions so userland can take some policy
  47. * decisions, like slewing down CPUs
  48. * - Deal with fan and i2c failures in a better way
  49. * - Maybe do a generic PID based on params used for
  50. * U3 and Drives ? Definitely need to factor code a bit
  51. * bettter... also make sensor detection more robust using
  52. * the device-tree to probe for them
  53. * - Figure out how to get the slots consumption and set the
  54. * slots fan accordingly
  55. *
  56. * History:
  57. *
  58. * Nov. 13, 2003 : 0.5
  59. * - First release
  60. *
  61. * Nov. 14, 2003 : 0.6
  62. * - Read fan speed from FCU, low level fan routines now deal
  63. * with errors & check fan status, though higher level don't
  64. * do much.
  65. * - Move a bunch of definitions to .h file
  66. *
  67. * Nov. 18, 2003 : 0.7
  68. * - Fix build on ppc64 kernel
  69. * - Move back statics definitions to .c file
  70. * - Avoid calling schedule_timeout with a negative number
  71. *
  72. * Dec. 18, 2003 : 0.8
  73. * - Fix typo when reading back fan speed on 2 CPU machines
  74. *
  75. * Mar. 11, 2004 : 0.9
  76. * - Rework code accessing the ADC chips, make it more robust and
  77. * closer to the chip spec. Also make sure it is configured properly,
  78. * I've seen yet unexplained cases where on startup, I would have stale
  79. * values in the configuration register
  80. * - Switch back to use of target fan speed for PID, thus lowering
  81. * pressure on i2c
  82. *
  83. * Oct. 20, 2004 : 1.1
  84. * - Add device-tree lookup for fan IDs, should detect liquid cooling
  85. * pumps when present
  86. * - Enable driver for PowerMac7,3 machines
  87. * - Split the U3/Backside cooling on U3 & U3H versions as Darwin does
  88. * - Add new CPU cooling algorithm for machines with liquid cooling
  89. * - Workaround for some PowerMac7,3 with empty "fan" node in the devtree
  90. * - Fix a signed/unsigned compare issue in some PID loops
  91. *
  92. * Mar. 10, 2005 : 1.2
  93. * - Add basic support for Xserve G5
  94. * - Retreive pumps min/max from EEPROM image in device-tree (broken)
  95. * - Use min/max macros here or there
  96. * - Latest darwin updated U3H min fan speed to 20% PWM
  97. *
  98. * July. 06, 2006 : 1.3
  99. * - Fix setting of RPM fans on Xserve G5 (they were going too fast)
  100. * - Add missing slots fan control loop for Xserve G5
  101. * - Lower fixed slots fan speed from 50% to 40% on desktop G5s. We
  102. * still can't properly implement the control loop for these, so let's
  103. * reduce the noise a little bit, it appears that 40% still gives us
  104. * a pretty good air flow
  105. * - Add code to "tickle" the FCU regulary so it doesn't think that
  106. * we are gone while in fact, the machine just didn't need any fan
  107. * speed change lately
  108. *
  109. */
  110. #include <linux/types.h>
  111. #include <linux/module.h>
  112. #include <linux/errno.h>
  113. #include <linux/kernel.h>
  114. #include <linux/delay.h>
  115. #include <linux/sched.h>
  116. #include <linux/slab.h>
  117. #include <linux/init.h>
  118. #include <linux/spinlock.h>
  119. #include <linux/wait.h>
  120. #include <linux/reboot.h>
  121. #include <linux/kmod.h>
  122. #include <linux/i2c.h>
  123. #include <linux/kthread.h>
  124. #include <linux/mutex.h>
  125. #include <linux/of_device.h>
  126. #include <linux/of_platform.h>
  127. #include <asm/prom.h>
  128. #include <asm/machdep.h>
  129. #include <asm/io.h>
  130. #include <asm/system.h>
  131. #include <asm/sections.h>
  132. #include <asm/macio.h>
  133. #include "therm_pm72.h"
  134. #define VERSION "1.3"
  135. #undef DEBUG
  136. #ifdef DEBUG
  137. #define DBG(args...) printk(args)
  138. #else
  139. #define DBG(args...) do { } while(0)
  140. #endif
  141. /*
  142. * Driver statics
  143. */
  144. static struct of_device * of_dev;
  145. static struct i2c_adapter * u3_0;
  146. static struct i2c_adapter * u3_1;
  147. static struct i2c_adapter * k2;
  148. static struct i2c_client * fcu;
  149. static struct cpu_pid_state cpu_state[2];
  150. static struct basckside_pid_params backside_params;
  151. static struct backside_pid_state backside_state;
  152. static struct drives_pid_state drives_state;
  153. static struct dimm_pid_state dimms_state;
  154. static struct slots_pid_state slots_state;
  155. static int state;
  156. static int cpu_count;
  157. static int cpu_pid_type;
  158. static struct task_struct *ctrl_task;
  159. static struct completion ctrl_complete;
  160. static int critical_state;
  161. static int rackmac;
  162. static s32 dimm_output_clamp;
  163. static int fcu_rpm_shift;
  164. static int fcu_tickle_ticks;
  165. static DEFINE_MUTEX(driver_lock);
  166. /*
  167. * We have 3 types of CPU PID control. One is "split" old style control
  168. * for intake & exhaust fans, the other is "combined" control for both
  169. * CPUs that also deals with the pumps when present. To be "compatible"
  170. * with OS X at this point, we only use "COMBINED" on the machines that
  171. * are identified as having the pumps (though that identification is at
  172. * least dodgy). Ultimately, we could probably switch completely to this
  173. * algorithm provided we hack it to deal with the UP case
  174. */
  175. #define CPU_PID_TYPE_SPLIT 0
  176. #define CPU_PID_TYPE_COMBINED 1
  177. #define CPU_PID_TYPE_RACKMAC 2
  178. /*
  179. * This table describes all fans in the FCU. The "id" and "type" values
  180. * are defaults valid for all earlier machines. Newer machines will
  181. * eventually override the table content based on the device-tree
  182. */
  183. struct fcu_fan_table
  184. {
  185. char* loc; /* location code */
  186. int type; /* 0 = rpm, 1 = pwm, 2 = pump */
  187. int id; /* id or -1 */
  188. };
  189. #define FCU_FAN_RPM 0
  190. #define FCU_FAN_PWM 1
  191. #define FCU_FAN_ABSENT_ID -1
  192. #define FCU_FAN_COUNT ARRAY_SIZE(fcu_fans)
  193. struct fcu_fan_table fcu_fans[] = {
  194. [BACKSIDE_FAN_PWM_INDEX] = {
  195. .loc = "BACKSIDE,SYS CTRLR FAN",
  196. .type = FCU_FAN_PWM,
  197. .id = BACKSIDE_FAN_PWM_DEFAULT_ID,
  198. },
  199. [DRIVES_FAN_RPM_INDEX] = {
  200. .loc = "DRIVE BAY",
  201. .type = FCU_FAN_RPM,
  202. .id = DRIVES_FAN_RPM_DEFAULT_ID,
  203. },
  204. [SLOTS_FAN_PWM_INDEX] = {
  205. .loc = "SLOT,PCI FAN",
  206. .type = FCU_FAN_PWM,
  207. .id = SLOTS_FAN_PWM_DEFAULT_ID,
  208. },
  209. [CPUA_INTAKE_FAN_RPM_INDEX] = {
  210. .loc = "CPU A INTAKE",
  211. .type = FCU_FAN_RPM,
  212. .id = CPUA_INTAKE_FAN_RPM_DEFAULT_ID,
  213. },
  214. [CPUA_EXHAUST_FAN_RPM_INDEX] = {
  215. .loc = "CPU A EXHAUST",
  216. .type = FCU_FAN_RPM,
  217. .id = CPUA_EXHAUST_FAN_RPM_DEFAULT_ID,
  218. },
  219. [CPUB_INTAKE_FAN_RPM_INDEX] = {
  220. .loc = "CPU B INTAKE",
  221. .type = FCU_FAN_RPM,
  222. .id = CPUB_INTAKE_FAN_RPM_DEFAULT_ID,
  223. },
  224. [CPUB_EXHAUST_FAN_RPM_INDEX] = {
  225. .loc = "CPU B EXHAUST",
  226. .type = FCU_FAN_RPM,
  227. .id = CPUB_EXHAUST_FAN_RPM_DEFAULT_ID,
  228. },
  229. /* pumps aren't present by default, have to be looked up in the
  230. * device-tree
  231. */
  232. [CPUA_PUMP_RPM_INDEX] = {
  233. .loc = "CPU A PUMP",
  234. .type = FCU_FAN_RPM,
  235. .id = FCU_FAN_ABSENT_ID,
  236. },
  237. [CPUB_PUMP_RPM_INDEX] = {
  238. .loc = "CPU B PUMP",
  239. .type = FCU_FAN_RPM,
  240. .id = FCU_FAN_ABSENT_ID,
  241. },
  242. /* Xserve fans */
  243. [CPU_A1_FAN_RPM_INDEX] = {
  244. .loc = "CPU A 1",
  245. .type = FCU_FAN_RPM,
  246. .id = FCU_FAN_ABSENT_ID,
  247. },
  248. [CPU_A2_FAN_RPM_INDEX] = {
  249. .loc = "CPU A 2",
  250. .type = FCU_FAN_RPM,
  251. .id = FCU_FAN_ABSENT_ID,
  252. },
  253. [CPU_A3_FAN_RPM_INDEX] = {
  254. .loc = "CPU A 3",
  255. .type = FCU_FAN_RPM,
  256. .id = FCU_FAN_ABSENT_ID,
  257. },
  258. [CPU_B1_FAN_RPM_INDEX] = {
  259. .loc = "CPU B 1",
  260. .type = FCU_FAN_RPM,
  261. .id = FCU_FAN_ABSENT_ID,
  262. },
  263. [CPU_B2_FAN_RPM_INDEX] = {
  264. .loc = "CPU B 2",
  265. .type = FCU_FAN_RPM,
  266. .id = FCU_FAN_ABSENT_ID,
  267. },
  268. [CPU_B3_FAN_RPM_INDEX] = {
  269. .loc = "CPU B 3",
  270. .type = FCU_FAN_RPM,
  271. .id = FCU_FAN_ABSENT_ID,
  272. },
  273. };
  274. /*
  275. * Utility function to create an i2c_client structure and
  276. * attach it to one of u3 adapters
  277. */
  278. static struct i2c_client *attach_i2c_chip(int id, const char *name)
  279. {
  280. struct i2c_client *clt;
  281. struct i2c_adapter *adap;
  282. struct i2c_board_info info;
  283. if (id & 0x200)
  284. adap = k2;
  285. else if (id & 0x100)
  286. adap = u3_1;
  287. else
  288. adap = u3_0;
  289. if (adap == NULL)
  290. return NULL;
  291. memset(&info, 0, sizeof(struct i2c_board_info));
  292. info.addr = (id >> 1) & 0x7f;
  293. strlcpy(info.type, "therm_pm72", I2C_NAME_SIZE);
  294. clt = i2c_new_device(adap, &info);
  295. if (!clt) {
  296. printk(KERN_ERR "therm_pm72: Failed to attach to i2c ID 0x%x\n", id);
  297. return NULL;
  298. }
  299. /*
  300. * Let i2c-core delete that device on driver removal.
  301. * This is safe because i2c-core holds the core_lock mutex for us.
  302. */
  303. list_add_tail(&clt->detected, &clt->driver->clients);
  304. return clt;
  305. }
  306. /*
  307. * Here are the i2c chip access wrappers
  308. */
  309. static void initialize_adc(struct cpu_pid_state *state)
  310. {
  311. int rc;
  312. u8 buf[2];
  313. /* Read ADC the configuration register and cache it. We
  314. * also make sure Config2 contains proper values, I've seen
  315. * cases where we got stale grabage in there, thus preventing
  316. * proper reading of conv. values
  317. */
  318. /* Clear Config2 */
  319. buf[0] = 5;
  320. buf[1] = 0;
  321. i2c_master_send(state->monitor, buf, 2);
  322. /* Read & cache Config1 */
  323. buf[0] = 1;
  324. rc = i2c_master_send(state->monitor, buf, 1);
  325. if (rc > 0) {
  326. rc = i2c_master_recv(state->monitor, buf, 1);
  327. if (rc > 0) {
  328. state->adc_config = buf[0];
  329. DBG("ADC config reg: %02x\n", state->adc_config);
  330. /* Disable shutdown mode */
  331. state->adc_config &= 0xfe;
  332. buf[0] = 1;
  333. buf[1] = state->adc_config;
  334. rc = i2c_master_send(state->monitor, buf, 2);
  335. }
  336. }
  337. if (rc <= 0)
  338. printk(KERN_ERR "therm_pm72: Error reading ADC config"
  339. " register !\n");
  340. }
  341. static int read_smon_adc(struct cpu_pid_state *state, int chan)
  342. {
  343. int rc, data, tries = 0;
  344. u8 buf[2];
  345. for (;;) {
  346. /* Set channel */
  347. buf[0] = 1;
  348. buf[1] = (state->adc_config & 0x1f) | (chan << 5);
  349. rc = i2c_master_send(state->monitor, buf, 2);
  350. if (rc <= 0)
  351. goto error;
  352. /* Wait for convertion */
  353. msleep(1);
  354. /* Switch to data register */
  355. buf[0] = 4;
  356. rc = i2c_master_send(state->monitor, buf, 1);
  357. if (rc <= 0)
  358. goto error;
  359. /* Read result */
  360. rc = i2c_master_recv(state->monitor, buf, 2);
  361. if (rc < 0)
  362. goto error;
  363. data = ((u16)buf[0]) << 8 | (u16)buf[1];
  364. return data >> 6;
  365. error:
  366. DBG("Error reading ADC, retrying...\n");
  367. if (++tries > 10) {
  368. printk(KERN_ERR "therm_pm72: Error reading ADC !\n");
  369. return -1;
  370. }
  371. msleep(10);
  372. }
  373. }
  374. static int read_lm87_reg(struct i2c_client * chip, int reg)
  375. {
  376. int rc, tries = 0;
  377. u8 buf;
  378. for (;;) {
  379. /* Set address */
  380. buf = (u8)reg;
  381. rc = i2c_master_send(chip, &buf, 1);
  382. if (rc <= 0)
  383. goto error;
  384. rc = i2c_master_recv(chip, &buf, 1);
  385. if (rc <= 0)
  386. goto error;
  387. return (int)buf;
  388. error:
  389. DBG("Error reading LM87, retrying...\n");
  390. if (++tries > 10) {
  391. printk(KERN_ERR "therm_pm72: Error reading LM87 !\n");
  392. return -1;
  393. }
  394. msleep(10);
  395. }
  396. }
  397. static int fan_read_reg(int reg, unsigned char *buf, int nb)
  398. {
  399. int tries, nr, nw;
  400. buf[0] = reg;
  401. tries = 0;
  402. for (;;) {
  403. nw = i2c_master_send(fcu, buf, 1);
  404. if (nw > 0 || (nw < 0 && nw != -EIO) || tries >= 100)
  405. break;
  406. msleep(10);
  407. ++tries;
  408. }
  409. if (nw <= 0) {
  410. printk(KERN_ERR "Failure writing address to FCU: %d", nw);
  411. return -EIO;
  412. }
  413. tries = 0;
  414. for (;;) {
  415. nr = i2c_master_recv(fcu, buf, nb);
  416. if (nr > 0 || (nr < 0 && nr != ENODEV) || tries >= 100)
  417. break;
  418. msleep(10);
  419. ++tries;
  420. }
  421. if (nr <= 0)
  422. printk(KERN_ERR "Failure reading data from FCU: %d", nw);
  423. return nr;
  424. }
  425. static int fan_write_reg(int reg, const unsigned char *ptr, int nb)
  426. {
  427. int tries, nw;
  428. unsigned char buf[16];
  429. buf[0] = reg;
  430. memcpy(buf+1, ptr, nb);
  431. ++nb;
  432. tries = 0;
  433. for (;;) {
  434. nw = i2c_master_send(fcu, buf, nb);
  435. if (nw > 0 || (nw < 0 && nw != EIO) || tries >= 100)
  436. break;
  437. msleep(10);
  438. ++tries;
  439. }
  440. if (nw < 0)
  441. printk(KERN_ERR "Failure writing to FCU: %d", nw);
  442. return nw;
  443. }
  444. static int start_fcu(void)
  445. {
  446. unsigned char buf = 0xff;
  447. int rc;
  448. rc = fan_write_reg(0xe, &buf, 1);
  449. if (rc < 0)
  450. return -EIO;
  451. rc = fan_write_reg(0x2e, &buf, 1);
  452. if (rc < 0)
  453. return -EIO;
  454. rc = fan_read_reg(0, &buf, 1);
  455. if (rc < 0)
  456. return -EIO;
  457. fcu_rpm_shift = (buf == 1) ? 2 : 3;
  458. printk(KERN_DEBUG "FCU Initialized, RPM fan shift is %d\n",
  459. fcu_rpm_shift);
  460. return 0;
  461. }
  462. static int set_rpm_fan(int fan_index, int rpm)
  463. {
  464. unsigned char buf[2];
  465. int rc, id, min, max;
  466. if (fcu_fans[fan_index].type != FCU_FAN_RPM)
  467. return -EINVAL;
  468. id = fcu_fans[fan_index].id;
  469. if (id == FCU_FAN_ABSENT_ID)
  470. return -EINVAL;
  471. min = 2400 >> fcu_rpm_shift;
  472. max = 56000 >> fcu_rpm_shift;
  473. if (rpm < min)
  474. rpm = min;
  475. else if (rpm > max)
  476. rpm = max;
  477. buf[0] = rpm >> (8 - fcu_rpm_shift);
  478. buf[1] = rpm << fcu_rpm_shift;
  479. rc = fan_write_reg(0x10 + (id * 2), buf, 2);
  480. if (rc < 0)
  481. return -EIO;
  482. return 0;
  483. }
  484. static int get_rpm_fan(int fan_index, int programmed)
  485. {
  486. unsigned char failure;
  487. unsigned char active;
  488. unsigned char buf[2];
  489. int rc, id, reg_base;
  490. if (fcu_fans[fan_index].type != FCU_FAN_RPM)
  491. return -EINVAL;
  492. id = fcu_fans[fan_index].id;
  493. if (id == FCU_FAN_ABSENT_ID)
  494. return -EINVAL;
  495. rc = fan_read_reg(0xb, &failure, 1);
  496. if (rc != 1)
  497. return -EIO;
  498. if ((failure & (1 << id)) != 0)
  499. return -EFAULT;
  500. rc = fan_read_reg(0xd, &active, 1);
  501. if (rc != 1)
  502. return -EIO;
  503. if ((active & (1 << id)) == 0)
  504. return -ENXIO;
  505. /* Programmed value or real current speed */
  506. reg_base = programmed ? 0x10 : 0x11;
  507. rc = fan_read_reg(reg_base + (id * 2), buf, 2);
  508. if (rc != 2)
  509. return -EIO;
  510. return (buf[0] << (8 - fcu_rpm_shift)) | buf[1] >> fcu_rpm_shift;
  511. }
  512. static int set_pwm_fan(int fan_index, int pwm)
  513. {
  514. unsigned char buf[2];
  515. int rc, id;
  516. if (fcu_fans[fan_index].type != FCU_FAN_PWM)
  517. return -EINVAL;
  518. id = fcu_fans[fan_index].id;
  519. if (id == FCU_FAN_ABSENT_ID)
  520. return -EINVAL;
  521. if (pwm < 10)
  522. pwm = 10;
  523. else if (pwm > 100)
  524. pwm = 100;
  525. pwm = (pwm * 2559) / 1000;
  526. buf[0] = pwm;
  527. rc = fan_write_reg(0x30 + (id * 2), buf, 1);
  528. if (rc < 0)
  529. return rc;
  530. return 0;
  531. }
  532. static int get_pwm_fan(int fan_index)
  533. {
  534. unsigned char failure;
  535. unsigned char active;
  536. unsigned char buf[2];
  537. int rc, id;
  538. if (fcu_fans[fan_index].type != FCU_FAN_PWM)
  539. return -EINVAL;
  540. id = fcu_fans[fan_index].id;
  541. if (id == FCU_FAN_ABSENT_ID)
  542. return -EINVAL;
  543. rc = fan_read_reg(0x2b, &failure, 1);
  544. if (rc != 1)
  545. return -EIO;
  546. if ((failure & (1 << id)) != 0)
  547. return -EFAULT;
  548. rc = fan_read_reg(0x2d, &active, 1);
  549. if (rc != 1)
  550. return -EIO;
  551. if ((active & (1 << id)) == 0)
  552. return -ENXIO;
  553. /* Programmed value or real current speed */
  554. rc = fan_read_reg(0x30 + (id * 2), buf, 1);
  555. if (rc != 1)
  556. return -EIO;
  557. return (buf[0] * 1000) / 2559;
  558. }
  559. static void tickle_fcu(void)
  560. {
  561. int pwm;
  562. pwm = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
  563. DBG("FCU Tickle, slots fan is: %d\n", pwm);
  564. if (pwm < 0)
  565. pwm = 100;
  566. if (!rackmac) {
  567. pwm = SLOTS_FAN_DEFAULT_PWM;
  568. } else if (pwm < SLOTS_PID_OUTPUT_MIN)
  569. pwm = SLOTS_PID_OUTPUT_MIN;
  570. /* That is hopefully enough to make the FCU happy */
  571. set_pwm_fan(SLOTS_FAN_PWM_INDEX, pwm);
  572. }
  573. /*
  574. * Utility routine to read the CPU calibration EEPROM data
  575. * from the device-tree
  576. */
  577. static int read_eeprom(int cpu, struct mpu_data *out)
  578. {
  579. struct device_node *np;
  580. char nodename[64];
  581. const u8 *data;
  582. int len;
  583. /* prom.c routine for finding a node by path is a bit brain dead
  584. * and requires exact @xxx unit numbers. This is a bit ugly but
  585. * will work for these machines
  586. */
  587. sprintf(nodename, "/u3@0,f8000000/i2c@f8001000/cpuid@a%d", cpu ? 2 : 0);
  588. np = of_find_node_by_path(nodename);
  589. if (np == NULL) {
  590. printk(KERN_ERR "therm_pm72: Failed to retrieve cpuid node from device-tree\n");
  591. return -ENODEV;
  592. }
  593. data = of_get_property(np, "cpuid", &len);
  594. if (data == NULL) {
  595. printk(KERN_ERR "therm_pm72: Failed to retrieve cpuid property from device-tree\n");
  596. of_node_put(np);
  597. return -ENODEV;
  598. }
  599. memcpy(out, data, sizeof(struct mpu_data));
  600. of_node_put(np);
  601. return 0;
  602. }
  603. static void fetch_cpu_pumps_minmax(void)
  604. {
  605. struct cpu_pid_state *state0 = &cpu_state[0];
  606. struct cpu_pid_state *state1 = &cpu_state[1];
  607. u16 pump_min = 0, pump_max = 0xffff;
  608. u16 tmp[4];
  609. /* Try to fetch pumps min/max infos from eeprom */
  610. memcpy(&tmp, &state0->mpu.processor_part_num, 8);
  611. if (tmp[0] != 0xffff && tmp[1] != 0xffff) {
  612. pump_min = max(pump_min, tmp[0]);
  613. pump_max = min(pump_max, tmp[1]);
  614. }
  615. if (tmp[2] != 0xffff && tmp[3] != 0xffff) {
  616. pump_min = max(pump_min, tmp[2]);
  617. pump_max = min(pump_max, tmp[3]);
  618. }
  619. /* Double check the values, this _IS_ needed as the EEPROM on
  620. * some dual 2.5Ghz G5s seem, at least, to have both min & max
  621. * same to the same value ... (grrrr)
  622. */
  623. if (pump_min == pump_max || pump_min == 0 || pump_max == 0xffff) {
  624. pump_min = CPU_PUMP_OUTPUT_MIN;
  625. pump_max = CPU_PUMP_OUTPUT_MAX;
  626. }
  627. state0->pump_min = state1->pump_min = pump_min;
  628. state0->pump_max = state1->pump_max = pump_max;
  629. }
  630. /*
  631. * Now, unfortunately, sysfs doesn't give us a nice void * we could
  632. * pass around to the attribute functions, so we don't really have
  633. * choice but implement a bunch of them...
  634. *
  635. * That sucks a bit, we take the lock because FIX32TOPRINT evaluates
  636. * the input twice... I accept patches :)
  637. */
  638. #define BUILD_SHOW_FUNC_FIX(name, data) \
  639. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  640. { \
  641. ssize_t r; \
  642. mutex_lock(&driver_lock); \
  643. r = sprintf(buf, "%d.%03d", FIX32TOPRINT(data)); \
  644. mutex_unlock(&driver_lock); \
  645. return r; \
  646. }
  647. #define BUILD_SHOW_FUNC_INT(name, data) \
  648. static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  649. { \
  650. return sprintf(buf, "%d", data); \
  651. }
  652. BUILD_SHOW_FUNC_FIX(cpu0_temperature, cpu_state[0].last_temp)
  653. BUILD_SHOW_FUNC_FIX(cpu0_voltage, cpu_state[0].voltage)
  654. BUILD_SHOW_FUNC_FIX(cpu0_current, cpu_state[0].current_a)
  655. BUILD_SHOW_FUNC_INT(cpu0_exhaust_fan_rpm, cpu_state[0].rpm)
  656. BUILD_SHOW_FUNC_INT(cpu0_intake_fan_rpm, cpu_state[0].intake_rpm)
  657. BUILD_SHOW_FUNC_FIX(cpu1_temperature, cpu_state[1].last_temp)
  658. BUILD_SHOW_FUNC_FIX(cpu1_voltage, cpu_state[1].voltage)
  659. BUILD_SHOW_FUNC_FIX(cpu1_current, cpu_state[1].current_a)
  660. BUILD_SHOW_FUNC_INT(cpu1_exhaust_fan_rpm, cpu_state[1].rpm)
  661. BUILD_SHOW_FUNC_INT(cpu1_intake_fan_rpm, cpu_state[1].intake_rpm)
  662. BUILD_SHOW_FUNC_FIX(backside_temperature, backside_state.last_temp)
  663. BUILD_SHOW_FUNC_INT(backside_fan_pwm, backside_state.pwm)
  664. BUILD_SHOW_FUNC_FIX(drives_temperature, drives_state.last_temp)
  665. BUILD_SHOW_FUNC_INT(drives_fan_rpm, drives_state.rpm)
  666. BUILD_SHOW_FUNC_FIX(slots_temperature, slots_state.last_temp)
  667. BUILD_SHOW_FUNC_INT(slots_fan_pwm, slots_state.pwm)
  668. BUILD_SHOW_FUNC_FIX(dimms_temperature, dimms_state.last_temp)
  669. static DEVICE_ATTR(cpu0_temperature,S_IRUGO,show_cpu0_temperature,NULL);
  670. static DEVICE_ATTR(cpu0_voltage,S_IRUGO,show_cpu0_voltage,NULL);
  671. static DEVICE_ATTR(cpu0_current,S_IRUGO,show_cpu0_current,NULL);
  672. static DEVICE_ATTR(cpu0_exhaust_fan_rpm,S_IRUGO,show_cpu0_exhaust_fan_rpm,NULL);
  673. static DEVICE_ATTR(cpu0_intake_fan_rpm,S_IRUGO,show_cpu0_intake_fan_rpm,NULL);
  674. static DEVICE_ATTR(cpu1_temperature,S_IRUGO,show_cpu1_temperature,NULL);
  675. static DEVICE_ATTR(cpu1_voltage,S_IRUGO,show_cpu1_voltage,NULL);
  676. static DEVICE_ATTR(cpu1_current,S_IRUGO,show_cpu1_current,NULL);
  677. static DEVICE_ATTR(cpu1_exhaust_fan_rpm,S_IRUGO,show_cpu1_exhaust_fan_rpm,NULL);
  678. static DEVICE_ATTR(cpu1_intake_fan_rpm,S_IRUGO,show_cpu1_intake_fan_rpm,NULL);
  679. static DEVICE_ATTR(backside_temperature,S_IRUGO,show_backside_temperature,NULL);
  680. static DEVICE_ATTR(backside_fan_pwm,S_IRUGO,show_backside_fan_pwm,NULL);
  681. static DEVICE_ATTR(drives_temperature,S_IRUGO,show_drives_temperature,NULL);
  682. static DEVICE_ATTR(drives_fan_rpm,S_IRUGO,show_drives_fan_rpm,NULL);
  683. static DEVICE_ATTR(slots_temperature,S_IRUGO,show_slots_temperature,NULL);
  684. static DEVICE_ATTR(slots_fan_pwm,S_IRUGO,show_slots_fan_pwm,NULL);
  685. static DEVICE_ATTR(dimms_temperature,S_IRUGO,show_dimms_temperature,NULL);
  686. /*
  687. * CPUs fans control loop
  688. */
  689. static int do_read_one_cpu_values(struct cpu_pid_state *state, s32 *temp, s32 *power)
  690. {
  691. s32 ltemp, volts, amps;
  692. int index, rc = 0;
  693. /* Default (in case of error) */
  694. *temp = state->cur_temp;
  695. *power = state->cur_power;
  696. if (cpu_pid_type == CPU_PID_TYPE_RACKMAC)
  697. index = (state->index == 0) ?
  698. CPU_A1_FAN_RPM_INDEX : CPU_B1_FAN_RPM_INDEX;
  699. else
  700. index = (state->index == 0) ?
  701. CPUA_EXHAUST_FAN_RPM_INDEX : CPUB_EXHAUST_FAN_RPM_INDEX;
  702. /* Read current fan status */
  703. rc = get_rpm_fan(index, !RPM_PID_USE_ACTUAL_SPEED);
  704. if (rc < 0) {
  705. /* XXX What do we do now ? Nothing for now, keep old value, but
  706. * return error upstream
  707. */
  708. DBG(" cpu %d, fan reading error !\n", state->index);
  709. } else {
  710. state->rpm = rc;
  711. DBG(" cpu %d, exhaust RPM: %d\n", state->index, state->rpm);
  712. }
  713. /* Get some sensor readings and scale it */
  714. ltemp = read_smon_adc(state, 1);
  715. if (ltemp == -1) {
  716. /* XXX What do we do now ? */
  717. state->overtemp++;
  718. if (rc == 0)
  719. rc = -EIO;
  720. DBG(" cpu %d, temp reading error !\n", state->index);
  721. } else {
  722. /* Fixup temperature according to diode calibration
  723. */
  724. DBG(" cpu %d, temp raw: %04x, m_diode: %04x, b_diode: %04x\n",
  725. state->index,
  726. ltemp, state->mpu.mdiode, state->mpu.bdiode);
  727. *temp = ((s32)ltemp * (s32)state->mpu.mdiode + ((s32)state->mpu.bdiode << 12)) >> 2;
  728. state->last_temp = *temp;
  729. DBG(" temp: %d.%03d\n", FIX32TOPRINT((*temp)));
  730. }
  731. /*
  732. * Read voltage & current and calculate power
  733. */
  734. volts = read_smon_adc(state, 3);
  735. amps = read_smon_adc(state, 4);
  736. /* Scale voltage and current raw sensor values according to fixed scales
  737. * obtained in Darwin and calculate power from I and V
  738. */
  739. volts *= ADC_CPU_VOLTAGE_SCALE;
  740. amps *= ADC_CPU_CURRENT_SCALE;
  741. *power = (((u64)volts) * ((u64)amps)) >> 16;
  742. state->voltage = volts;
  743. state->current_a = amps;
  744. state->last_power = *power;
  745. DBG(" cpu %d, current: %d.%03d, voltage: %d.%03d, power: %d.%03d W\n",
  746. state->index, FIX32TOPRINT(state->current_a),
  747. FIX32TOPRINT(state->voltage), FIX32TOPRINT(*power));
  748. return 0;
  749. }
  750. static void do_cpu_pid(struct cpu_pid_state *state, s32 temp, s32 power)
  751. {
  752. s32 power_target, integral, derivative, proportional, adj_in_target, sval;
  753. s64 integ_p, deriv_p, prop_p, sum;
  754. int i;
  755. /* Calculate power target value (could be done once for all)
  756. * and convert to a 16.16 fp number
  757. */
  758. power_target = ((u32)(state->mpu.pmaxh - state->mpu.padjmax)) << 16;
  759. DBG(" power target: %d.%03d, error: %d.%03d\n",
  760. FIX32TOPRINT(power_target), FIX32TOPRINT(power_target - power));
  761. /* Store temperature and power in history array */
  762. state->cur_temp = (state->cur_temp + 1) % CPU_TEMP_HISTORY_SIZE;
  763. state->temp_history[state->cur_temp] = temp;
  764. state->cur_power = (state->cur_power + 1) % state->count_power;
  765. state->power_history[state->cur_power] = power;
  766. state->error_history[state->cur_power] = power_target - power;
  767. /* If first loop, fill the history table */
  768. if (state->first) {
  769. for (i = 0; i < (state->count_power - 1); i++) {
  770. state->cur_power = (state->cur_power + 1) % state->count_power;
  771. state->power_history[state->cur_power] = power;
  772. state->error_history[state->cur_power] = power_target - power;
  773. }
  774. for (i = 0; i < (CPU_TEMP_HISTORY_SIZE - 1); i++) {
  775. state->cur_temp = (state->cur_temp + 1) % CPU_TEMP_HISTORY_SIZE;
  776. state->temp_history[state->cur_temp] = temp;
  777. }
  778. state->first = 0;
  779. }
  780. /* Calculate the integral term normally based on the "power" values */
  781. sum = 0;
  782. integral = 0;
  783. for (i = 0; i < state->count_power; i++)
  784. integral += state->error_history[i];
  785. integral *= CPU_PID_INTERVAL;
  786. DBG(" integral: %08x\n", integral);
  787. /* Calculate the adjusted input (sense value).
  788. * G_r is 12.20
  789. * integ is 16.16
  790. * so the result is 28.36
  791. *
  792. * input target is mpu.ttarget, input max is mpu.tmax
  793. */
  794. integ_p = ((s64)state->mpu.pid_gr) * (s64)integral;
  795. DBG(" integ_p: %d\n", (int)(integ_p >> 36));
  796. sval = (state->mpu.tmax << 16) - ((integ_p >> 20) & 0xffffffff);
  797. adj_in_target = (state->mpu.ttarget << 16);
  798. if (adj_in_target > sval)
  799. adj_in_target = sval;
  800. DBG(" adj_in_target: %d.%03d, ttarget: %d\n", FIX32TOPRINT(adj_in_target),
  801. state->mpu.ttarget);
  802. /* Calculate the derivative term */
  803. derivative = state->temp_history[state->cur_temp] -
  804. state->temp_history[(state->cur_temp + CPU_TEMP_HISTORY_SIZE - 1)
  805. % CPU_TEMP_HISTORY_SIZE];
  806. derivative /= CPU_PID_INTERVAL;
  807. deriv_p = ((s64)state->mpu.pid_gd) * (s64)derivative;
  808. DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
  809. sum += deriv_p;
  810. /* Calculate the proportional term */
  811. proportional = temp - adj_in_target;
  812. prop_p = ((s64)state->mpu.pid_gp) * (s64)proportional;
  813. DBG(" prop_p: %d\n", (int)(prop_p >> 36));
  814. sum += prop_p;
  815. /* Scale sum */
  816. sum >>= 36;
  817. DBG(" sum: %d\n", (int)sum);
  818. state->rpm += (s32)sum;
  819. }
  820. static void do_monitor_cpu_combined(void)
  821. {
  822. struct cpu_pid_state *state0 = &cpu_state[0];
  823. struct cpu_pid_state *state1 = &cpu_state[1];
  824. s32 temp0, power0, temp1, power1;
  825. s32 temp_combi, power_combi;
  826. int rc, intake, pump;
  827. rc = do_read_one_cpu_values(state0, &temp0, &power0);
  828. if (rc < 0) {
  829. /* XXX What do we do now ? */
  830. }
  831. state1->overtemp = 0;
  832. rc = do_read_one_cpu_values(state1, &temp1, &power1);
  833. if (rc < 0) {
  834. /* XXX What do we do now ? */
  835. }
  836. if (state1->overtemp)
  837. state0->overtemp++;
  838. temp_combi = max(temp0, temp1);
  839. power_combi = max(power0, power1);
  840. /* Check tmax, increment overtemp if we are there. At tmax+8, we go
  841. * full blown immediately and try to trigger a shutdown
  842. */
  843. if (temp_combi >= ((state0->mpu.tmax + 8) << 16)) {
  844. printk(KERN_WARNING "Warning ! Temperature way above maximum (%d) !\n",
  845. temp_combi >> 16);
  846. state0->overtemp += CPU_MAX_OVERTEMP / 4;
  847. } else if (temp_combi > (state0->mpu.tmax << 16))
  848. state0->overtemp++;
  849. else
  850. state0->overtemp = 0;
  851. if (state0->overtemp >= CPU_MAX_OVERTEMP)
  852. critical_state = 1;
  853. if (state0->overtemp > 0) {
  854. state0->rpm = state0->mpu.rmaxn_exhaust_fan;
  855. state0->intake_rpm = intake = state0->mpu.rmaxn_intake_fan;
  856. pump = state0->pump_max;
  857. goto do_set_fans;
  858. }
  859. /* Do the PID */
  860. do_cpu_pid(state0, temp_combi, power_combi);
  861. /* Range check */
  862. state0->rpm = max(state0->rpm, (int)state0->mpu.rminn_exhaust_fan);
  863. state0->rpm = min(state0->rpm, (int)state0->mpu.rmaxn_exhaust_fan);
  864. /* Calculate intake fan speed */
  865. intake = (state0->rpm * CPU_INTAKE_SCALE) >> 16;
  866. intake = max(intake, (int)state0->mpu.rminn_intake_fan);
  867. intake = min(intake, (int)state0->mpu.rmaxn_intake_fan);
  868. state0->intake_rpm = intake;
  869. /* Calculate pump speed */
  870. pump = (state0->rpm * state0->pump_max) /
  871. state0->mpu.rmaxn_exhaust_fan;
  872. pump = min(pump, state0->pump_max);
  873. pump = max(pump, state0->pump_min);
  874. do_set_fans:
  875. /* We copy values from state 0 to state 1 for /sysfs */
  876. state1->rpm = state0->rpm;
  877. state1->intake_rpm = state0->intake_rpm;
  878. DBG("** CPU %d RPM: %d Ex, %d, Pump: %d, In, overtemp: %d\n",
  879. state1->index, (int)state1->rpm, intake, pump, state1->overtemp);
  880. /* We should check for errors, shouldn't we ? But then, what
  881. * do we do once the error occurs ? For FCU notified fan
  882. * failures (-EFAULT) we probably want to notify userland
  883. * some way...
  884. */
  885. set_rpm_fan(CPUA_INTAKE_FAN_RPM_INDEX, intake);
  886. set_rpm_fan(CPUA_EXHAUST_FAN_RPM_INDEX, state0->rpm);
  887. set_rpm_fan(CPUB_INTAKE_FAN_RPM_INDEX, intake);
  888. set_rpm_fan(CPUB_EXHAUST_FAN_RPM_INDEX, state0->rpm);
  889. if (fcu_fans[CPUA_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID)
  890. set_rpm_fan(CPUA_PUMP_RPM_INDEX, pump);
  891. if (fcu_fans[CPUB_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID)
  892. set_rpm_fan(CPUB_PUMP_RPM_INDEX, pump);
  893. }
  894. static void do_monitor_cpu_split(struct cpu_pid_state *state)
  895. {
  896. s32 temp, power;
  897. int rc, intake;
  898. /* Read current fan status */
  899. rc = do_read_one_cpu_values(state, &temp, &power);
  900. if (rc < 0) {
  901. /* XXX What do we do now ? */
  902. }
  903. /* Check tmax, increment overtemp if we are there. At tmax+8, we go
  904. * full blown immediately and try to trigger a shutdown
  905. */
  906. if (temp >= ((state->mpu.tmax + 8) << 16)) {
  907. printk(KERN_WARNING "Warning ! CPU %d temperature way above maximum"
  908. " (%d) !\n",
  909. state->index, temp >> 16);
  910. state->overtemp += CPU_MAX_OVERTEMP / 4;
  911. } else if (temp > (state->mpu.tmax << 16))
  912. state->overtemp++;
  913. else
  914. state->overtemp = 0;
  915. if (state->overtemp >= CPU_MAX_OVERTEMP)
  916. critical_state = 1;
  917. if (state->overtemp > 0) {
  918. state->rpm = state->mpu.rmaxn_exhaust_fan;
  919. state->intake_rpm = intake = state->mpu.rmaxn_intake_fan;
  920. goto do_set_fans;
  921. }
  922. /* Do the PID */
  923. do_cpu_pid(state, temp, power);
  924. /* Range check */
  925. state->rpm = max(state->rpm, (int)state->mpu.rminn_exhaust_fan);
  926. state->rpm = min(state->rpm, (int)state->mpu.rmaxn_exhaust_fan);
  927. /* Calculate intake fan */
  928. intake = (state->rpm * CPU_INTAKE_SCALE) >> 16;
  929. intake = max(intake, (int)state->mpu.rminn_intake_fan);
  930. intake = min(intake, (int)state->mpu.rmaxn_intake_fan);
  931. state->intake_rpm = intake;
  932. do_set_fans:
  933. DBG("** CPU %d RPM: %d Ex, %d In, overtemp: %d\n",
  934. state->index, (int)state->rpm, intake, state->overtemp);
  935. /* We should check for errors, shouldn't we ? But then, what
  936. * do we do once the error occurs ? For FCU notified fan
  937. * failures (-EFAULT) we probably want to notify userland
  938. * some way...
  939. */
  940. if (state->index == 0) {
  941. set_rpm_fan(CPUA_INTAKE_FAN_RPM_INDEX, intake);
  942. set_rpm_fan(CPUA_EXHAUST_FAN_RPM_INDEX, state->rpm);
  943. } else {
  944. set_rpm_fan(CPUB_INTAKE_FAN_RPM_INDEX, intake);
  945. set_rpm_fan(CPUB_EXHAUST_FAN_RPM_INDEX, state->rpm);
  946. }
  947. }
  948. static void do_monitor_cpu_rack(struct cpu_pid_state *state)
  949. {
  950. s32 temp, power, fan_min;
  951. int rc;
  952. /* Read current fan status */
  953. rc = do_read_one_cpu_values(state, &temp, &power);
  954. if (rc < 0) {
  955. /* XXX What do we do now ? */
  956. }
  957. /* Check tmax, increment overtemp if we are there. At tmax+8, we go
  958. * full blown immediately and try to trigger a shutdown
  959. */
  960. if (temp >= ((state->mpu.tmax + 8) << 16)) {
  961. printk(KERN_WARNING "Warning ! CPU %d temperature way above maximum"
  962. " (%d) !\n",
  963. state->index, temp >> 16);
  964. state->overtemp = CPU_MAX_OVERTEMP / 4;
  965. } else if (temp > (state->mpu.tmax << 16))
  966. state->overtemp++;
  967. else
  968. state->overtemp = 0;
  969. if (state->overtemp >= CPU_MAX_OVERTEMP)
  970. critical_state = 1;
  971. if (state->overtemp > 0) {
  972. state->rpm = state->intake_rpm = state->mpu.rmaxn_intake_fan;
  973. goto do_set_fans;
  974. }
  975. /* Do the PID */
  976. do_cpu_pid(state, temp, power);
  977. /* Check clamp from dimms */
  978. fan_min = dimm_output_clamp;
  979. fan_min = max(fan_min, (int)state->mpu.rminn_intake_fan);
  980. DBG(" CPU min mpu = %d, min dimm = %d\n",
  981. state->mpu.rminn_intake_fan, dimm_output_clamp);
  982. state->rpm = max(state->rpm, (int)fan_min);
  983. state->rpm = min(state->rpm, (int)state->mpu.rmaxn_intake_fan);
  984. state->intake_rpm = state->rpm;
  985. do_set_fans:
  986. DBG("** CPU %d RPM: %d overtemp: %d\n",
  987. state->index, (int)state->rpm, state->overtemp);
  988. /* We should check for errors, shouldn't we ? But then, what
  989. * do we do once the error occurs ? For FCU notified fan
  990. * failures (-EFAULT) we probably want to notify userland
  991. * some way...
  992. */
  993. if (state->index == 0) {
  994. set_rpm_fan(CPU_A1_FAN_RPM_INDEX, state->rpm);
  995. set_rpm_fan(CPU_A2_FAN_RPM_INDEX, state->rpm);
  996. set_rpm_fan(CPU_A3_FAN_RPM_INDEX, state->rpm);
  997. } else {
  998. set_rpm_fan(CPU_B1_FAN_RPM_INDEX, state->rpm);
  999. set_rpm_fan(CPU_B2_FAN_RPM_INDEX, state->rpm);
  1000. set_rpm_fan(CPU_B3_FAN_RPM_INDEX, state->rpm);
  1001. }
  1002. }
  1003. /*
  1004. * Initialize the state structure for one CPU control loop
  1005. */
  1006. static int init_cpu_state(struct cpu_pid_state *state, int index)
  1007. {
  1008. int err;
  1009. state->index = index;
  1010. state->first = 1;
  1011. state->rpm = (cpu_pid_type == CPU_PID_TYPE_RACKMAC) ? 4000 : 1000;
  1012. state->overtemp = 0;
  1013. state->adc_config = 0x00;
  1014. if (index == 0)
  1015. state->monitor = attach_i2c_chip(SUPPLY_MONITOR_ID, "CPU0_monitor");
  1016. else if (index == 1)
  1017. state->monitor = attach_i2c_chip(SUPPLY_MONITORB_ID, "CPU1_monitor");
  1018. if (state->monitor == NULL)
  1019. goto fail;
  1020. if (read_eeprom(index, &state->mpu))
  1021. goto fail;
  1022. state->count_power = state->mpu.tguardband;
  1023. if (state->count_power > CPU_POWER_HISTORY_SIZE) {
  1024. printk(KERN_WARNING "Warning ! too many power history slots\n");
  1025. state->count_power = CPU_POWER_HISTORY_SIZE;
  1026. }
  1027. DBG("CPU %d Using %d power history entries\n", index, state->count_power);
  1028. if (index == 0) {
  1029. err = device_create_file(&of_dev->dev, &dev_attr_cpu0_temperature);
  1030. err |= device_create_file(&of_dev->dev, &dev_attr_cpu0_voltage);
  1031. err |= device_create_file(&of_dev->dev, &dev_attr_cpu0_current);
  1032. err |= device_create_file(&of_dev->dev, &dev_attr_cpu0_exhaust_fan_rpm);
  1033. err |= device_create_file(&of_dev->dev, &dev_attr_cpu0_intake_fan_rpm);
  1034. } else {
  1035. err = device_create_file(&of_dev->dev, &dev_attr_cpu1_temperature);
  1036. err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_voltage);
  1037. err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_current);
  1038. err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_exhaust_fan_rpm);
  1039. err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_intake_fan_rpm);
  1040. }
  1041. if (err)
  1042. printk(KERN_WARNING "Failed to create some of the atribute"
  1043. "files for CPU %d\n", index);
  1044. return 0;
  1045. fail:
  1046. state->monitor = NULL;
  1047. return -ENODEV;
  1048. }
  1049. /*
  1050. * Dispose of the state data for one CPU control loop
  1051. */
  1052. static void dispose_cpu_state(struct cpu_pid_state *state)
  1053. {
  1054. if (state->monitor == NULL)
  1055. return;
  1056. if (state->index == 0) {
  1057. device_remove_file(&of_dev->dev, &dev_attr_cpu0_temperature);
  1058. device_remove_file(&of_dev->dev, &dev_attr_cpu0_voltage);
  1059. device_remove_file(&of_dev->dev, &dev_attr_cpu0_current);
  1060. device_remove_file(&of_dev->dev, &dev_attr_cpu0_exhaust_fan_rpm);
  1061. device_remove_file(&of_dev->dev, &dev_attr_cpu0_intake_fan_rpm);
  1062. } else {
  1063. device_remove_file(&of_dev->dev, &dev_attr_cpu1_temperature);
  1064. device_remove_file(&of_dev->dev, &dev_attr_cpu1_voltage);
  1065. device_remove_file(&of_dev->dev, &dev_attr_cpu1_current);
  1066. device_remove_file(&of_dev->dev, &dev_attr_cpu1_exhaust_fan_rpm);
  1067. device_remove_file(&of_dev->dev, &dev_attr_cpu1_intake_fan_rpm);
  1068. }
  1069. state->monitor = NULL;
  1070. }
  1071. /*
  1072. * Motherboard backside & U3 heatsink fan control loop
  1073. */
  1074. static void do_monitor_backside(struct backside_pid_state *state)
  1075. {
  1076. s32 temp, integral, derivative, fan_min;
  1077. s64 integ_p, deriv_p, prop_p, sum;
  1078. int i, rc;
  1079. if (--state->ticks != 0)
  1080. return;
  1081. state->ticks = backside_params.interval;
  1082. DBG("backside:\n");
  1083. /* Check fan status */
  1084. rc = get_pwm_fan(BACKSIDE_FAN_PWM_INDEX);
  1085. if (rc < 0) {
  1086. printk(KERN_WARNING "Error %d reading backside fan !\n", rc);
  1087. /* XXX What do we do now ? */
  1088. } else
  1089. state->pwm = rc;
  1090. DBG(" current pwm: %d\n", state->pwm);
  1091. /* Get some sensor readings */
  1092. temp = i2c_smbus_read_byte_data(state->monitor, MAX6690_EXT_TEMP) << 16;
  1093. state->last_temp = temp;
  1094. DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
  1095. FIX32TOPRINT(backside_params.input_target));
  1096. /* Store temperature and error in history array */
  1097. state->cur_sample = (state->cur_sample + 1) % BACKSIDE_PID_HISTORY_SIZE;
  1098. state->sample_history[state->cur_sample] = temp;
  1099. state->error_history[state->cur_sample] = temp - backside_params.input_target;
  1100. /* If first loop, fill the history table */
  1101. if (state->first) {
  1102. for (i = 0; i < (BACKSIDE_PID_HISTORY_SIZE - 1); i++) {
  1103. state->cur_sample = (state->cur_sample + 1) %
  1104. BACKSIDE_PID_HISTORY_SIZE;
  1105. state->sample_history[state->cur_sample] = temp;
  1106. state->error_history[state->cur_sample] =
  1107. temp - backside_params.input_target;
  1108. }
  1109. state->first = 0;
  1110. }
  1111. /* Calculate the integral term */
  1112. sum = 0;
  1113. integral = 0;
  1114. for (i = 0; i < BACKSIDE_PID_HISTORY_SIZE; i++)
  1115. integral += state->error_history[i];
  1116. integral *= backside_params.interval;
  1117. DBG(" integral: %08x\n", integral);
  1118. integ_p = ((s64)backside_params.G_r) * (s64)integral;
  1119. DBG(" integ_p: %d\n", (int)(integ_p >> 36));
  1120. sum += integ_p;
  1121. /* Calculate the derivative term */
  1122. derivative = state->error_history[state->cur_sample] -
  1123. state->error_history[(state->cur_sample + BACKSIDE_PID_HISTORY_SIZE - 1)
  1124. % BACKSIDE_PID_HISTORY_SIZE];
  1125. derivative /= backside_params.interval;
  1126. deriv_p = ((s64)backside_params.G_d) * (s64)derivative;
  1127. DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
  1128. sum += deriv_p;
  1129. /* Calculate the proportional term */
  1130. prop_p = ((s64)backside_params.G_p) * (s64)(state->error_history[state->cur_sample]);
  1131. DBG(" prop_p: %d\n", (int)(prop_p >> 36));
  1132. sum += prop_p;
  1133. /* Scale sum */
  1134. sum >>= 36;
  1135. DBG(" sum: %d\n", (int)sum);
  1136. if (backside_params.additive)
  1137. state->pwm += (s32)sum;
  1138. else
  1139. state->pwm = sum;
  1140. /* Check for clamp */
  1141. fan_min = (dimm_output_clamp * 100) / 14000;
  1142. fan_min = max(fan_min, backside_params.output_min);
  1143. state->pwm = max(state->pwm, fan_min);
  1144. state->pwm = min(state->pwm, backside_params.output_max);
  1145. DBG("** BACKSIDE PWM: %d\n", (int)state->pwm);
  1146. set_pwm_fan(BACKSIDE_FAN_PWM_INDEX, state->pwm);
  1147. }
  1148. /*
  1149. * Initialize the state structure for the backside fan control loop
  1150. */
  1151. static int init_backside_state(struct backside_pid_state *state)
  1152. {
  1153. struct device_node *u3;
  1154. int u3h = 1; /* conservative by default */
  1155. int err;
  1156. /*
  1157. * There are different PID params for machines with U3 and machines
  1158. * with U3H, pick the right ones now
  1159. */
  1160. u3 = of_find_node_by_path("/u3@0,f8000000");
  1161. if (u3 != NULL) {
  1162. const u32 *vers = of_get_property(u3, "device-rev", NULL);
  1163. if (vers)
  1164. if (((*vers) & 0x3f) < 0x34)
  1165. u3h = 0;
  1166. of_node_put(u3);
  1167. }
  1168. if (rackmac) {
  1169. backside_params.G_d = BACKSIDE_PID_RACK_G_d;
  1170. backside_params.input_target = BACKSIDE_PID_RACK_INPUT_TARGET;
  1171. backside_params.output_min = BACKSIDE_PID_U3H_OUTPUT_MIN;
  1172. backside_params.interval = BACKSIDE_PID_RACK_INTERVAL;
  1173. backside_params.G_p = BACKSIDE_PID_RACK_G_p;
  1174. backside_params.G_r = BACKSIDE_PID_G_r;
  1175. backside_params.output_max = BACKSIDE_PID_OUTPUT_MAX;
  1176. backside_params.additive = 0;
  1177. } else if (u3h) {
  1178. backside_params.G_d = BACKSIDE_PID_U3H_G_d;
  1179. backside_params.input_target = BACKSIDE_PID_U3H_INPUT_TARGET;
  1180. backside_params.output_min = BACKSIDE_PID_U3H_OUTPUT_MIN;
  1181. backside_params.interval = BACKSIDE_PID_INTERVAL;
  1182. backside_params.G_p = BACKSIDE_PID_G_p;
  1183. backside_params.G_r = BACKSIDE_PID_G_r;
  1184. backside_params.output_max = BACKSIDE_PID_OUTPUT_MAX;
  1185. backside_params.additive = 1;
  1186. } else {
  1187. backside_params.G_d = BACKSIDE_PID_U3_G_d;
  1188. backside_params.input_target = BACKSIDE_PID_U3_INPUT_TARGET;
  1189. backside_params.output_min = BACKSIDE_PID_U3_OUTPUT_MIN;
  1190. backside_params.interval = BACKSIDE_PID_INTERVAL;
  1191. backside_params.G_p = BACKSIDE_PID_G_p;
  1192. backside_params.G_r = BACKSIDE_PID_G_r;
  1193. backside_params.output_max = BACKSIDE_PID_OUTPUT_MAX;
  1194. backside_params.additive = 1;
  1195. }
  1196. state->ticks = 1;
  1197. state->first = 1;
  1198. state->pwm = 50;
  1199. state->monitor = attach_i2c_chip(BACKSIDE_MAX_ID, "backside_temp");
  1200. if (state->monitor == NULL)
  1201. return -ENODEV;
  1202. err = device_create_file(&of_dev->dev, &dev_attr_backside_temperature);
  1203. err |= device_create_file(&of_dev->dev, &dev_attr_backside_fan_pwm);
  1204. if (err)
  1205. printk(KERN_WARNING "Failed to create attribute file(s)"
  1206. " for backside fan\n");
  1207. return 0;
  1208. }
  1209. /*
  1210. * Dispose of the state data for the backside control loop
  1211. */
  1212. static void dispose_backside_state(struct backside_pid_state *state)
  1213. {
  1214. if (state->monitor == NULL)
  1215. return;
  1216. device_remove_file(&of_dev->dev, &dev_attr_backside_temperature);
  1217. device_remove_file(&of_dev->dev, &dev_attr_backside_fan_pwm);
  1218. state->monitor = NULL;
  1219. }
  1220. /*
  1221. * Drives bay fan control loop
  1222. */
  1223. static void do_monitor_drives(struct drives_pid_state *state)
  1224. {
  1225. s32 temp, integral, derivative;
  1226. s64 integ_p, deriv_p, prop_p, sum;
  1227. int i, rc;
  1228. if (--state->ticks != 0)
  1229. return;
  1230. state->ticks = DRIVES_PID_INTERVAL;
  1231. DBG("drives:\n");
  1232. /* Check fan status */
  1233. rc = get_rpm_fan(DRIVES_FAN_RPM_INDEX, !RPM_PID_USE_ACTUAL_SPEED);
  1234. if (rc < 0) {
  1235. printk(KERN_WARNING "Error %d reading drives fan !\n", rc);
  1236. /* XXX What do we do now ? */
  1237. } else
  1238. state->rpm = rc;
  1239. DBG(" current rpm: %d\n", state->rpm);
  1240. /* Get some sensor readings */
  1241. temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
  1242. DS1775_TEMP)) << 8;
  1243. state->last_temp = temp;
  1244. DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
  1245. FIX32TOPRINT(DRIVES_PID_INPUT_TARGET));
  1246. /* Store temperature and error in history array */
  1247. state->cur_sample = (state->cur_sample + 1) % DRIVES_PID_HISTORY_SIZE;
  1248. state->sample_history[state->cur_sample] = temp;
  1249. state->error_history[state->cur_sample] = temp - DRIVES_PID_INPUT_TARGET;
  1250. /* If first loop, fill the history table */
  1251. if (state->first) {
  1252. for (i = 0; i < (DRIVES_PID_HISTORY_SIZE - 1); i++) {
  1253. state->cur_sample = (state->cur_sample + 1) %
  1254. DRIVES_PID_HISTORY_SIZE;
  1255. state->sample_history[state->cur_sample] = temp;
  1256. state->error_history[state->cur_sample] =
  1257. temp - DRIVES_PID_INPUT_TARGET;
  1258. }
  1259. state->first = 0;
  1260. }
  1261. /* Calculate the integral term */
  1262. sum = 0;
  1263. integral = 0;
  1264. for (i = 0; i < DRIVES_PID_HISTORY_SIZE; i++)
  1265. integral += state->error_history[i];
  1266. integral *= DRIVES_PID_INTERVAL;
  1267. DBG(" integral: %08x\n", integral);
  1268. integ_p = ((s64)DRIVES_PID_G_r) * (s64)integral;
  1269. DBG(" integ_p: %d\n", (int)(integ_p >> 36));
  1270. sum += integ_p;
  1271. /* Calculate the derivative term */
  1272. derivative = state->error_history[state->cur_sample] -
  1273. state->error_history[(state->cur_sample + DRIVES_PID_HISTORY_SIZE - 1)
  1274. % DRIVES_PID_HISTORY_SIZE];
  1275. derivative /= DRIVES_PID_INTERVAL;
  1276. deriv_p = ((s64)DRIVES_PID_G_d) * (s64)derivative;
  1277. DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
  1278. sum += deriv_p;
  1279. /* Calculate the proportional term */
  1280. prop_p = ((s64)DRIVES_PID_G_p) * (s64)(state->error_history[state->cur_sample]);
  1281. DBG(" prop_p: %d\n", (int)(prop_p >> 36));
  1282. sum += prop_p;
  1283. /* Scale sum */
  1284. sum >>= 36;
  1285. DBG(" sum: %d\n", (int)sum);
  1286. state->rpm += (s32)sum;
  1287. state->rpm = max(state->rpm, DRIVES_PID_OUTPUT_MIN);
  1288. state->rpm = min(state->rpm, DRIVES_PID_OUTPUT_MAX);
  1289. DBG("** DRIVES RPM: %d\n", (int)state->rpm);
  1290. set_rpm_fan(DRIVES_FAN_RPM_INDEX, state->rpm);
  1291. }
  1292. /*
  1293. * Initialize the state structure for the drives bay fan control loop
  1294. */
  1295. static int init_drives_state(struct drives_pid_state *state)
  1296. {
  1297. int err;
  1298. state->ticks = 1;
  1299. state->first = 1;
  1300. state->rpm = 1000;
  1301. state->monitor = attach_i2c_chip(DRIVES_DALLAS_ID, "drives_temp");
  1302. if (state->monitor == NULL)
  1303. return -ENODEV;
  1304. err = device_create_file(&of_dev->dev, &dev_attr_drives_temperature);
  1305. err |= device_create_file(&of_dev->dev, &dev_attr_drives_fan_rpm);
  1306. if (err)
  1307. printk(KERN_WARNING "Failed to create attribute file(s)"
  1308. " for drives bay fan\n");
  1309. return 0;
  1310. }
  1311. /*
  1312. * Dispose of the state data for the drives control loop
  1313. */
  1314. static void dispose_drives_state(struct drives_pid_state *state)
  1315. {
  1316. if (state->monitor == NULL)
  1317. return;
  1318. device_remove_file(&of_dev->dev, &dev_attr_drives_temperature);
  1319. device_remove_file(&of_dev->dev, &dev_attr_drives_fan_rpm);
  1320. state->monitor = NULL;
  1321. }
  1322. /*
  1323. * DIMMs temp control loop
  1324. */
  1325. static void do_monitor_dimms(struct dimm_pid_state *state)
  1326. {
  1327. s32 temp, integral, derivative, fan_min;
  1328. s64 integ_p, deriv_p, prop_p, sum;
  1329. int i;
  1330. if (--state->ticks != 0)
  1331. return;
  1332. state->ticks = DIMM_PID_INTERVAL;
  1333. DBG("DIMM:\n");
  1334. DBG(" current value: %d\n", state->output);
  1335. temp = read_lm87_reg(state->monitor, LM87_INT_TEMP);
  1336. if (temp < 0)
  1337. return;
  1338. temp <<= 16;
  1339. state->last_temp = temp;
  1340. DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
  1341. FIX32TOPRINT(DIMM_PID_INPUT_TARGET));
  1342. /* Store temperature and error in history array */
  1343. state->cur_sample = (state->cur_sample + 1) % DIMM_PID_HISTORY_SIZE;
  1344. state->sample_history[state->cur_sample] = temp;
  1345. state->error_history[state->cur_sample] = temp - DIMM_PID_INPUT_TARGET;
  1346. /* If first loop, fill the history table */
  1347. if (state->first) {
  1348. for (i = 0; i < (DIMM_PID_HISTORY_SIZE - 1); i++) {
  1349. state->cur_sample = (state->cur_sample + 1) %
  1350. DIMM_PID_HISTORY_SIZE;
  1351. state->sample_history[state->cur_sample] = temp;
  1352. state->error_history[state->cur_sample] =
  1353. temp - DIMM_PID_INPUT_TARGET;
  1354. }
  1355. state->first = 0;
  1356. }
  1357. /* Calculate the integral term */
  1358. sum = 0;
  1359. integral = 0;
  1360. for (i = 0; i < DIMM_PID_HISTORY_SIZE; i++)
  1361. integral += state->error_history[i];
  1362. integral *= DIMM_PID_INTERVAL;
  1363. DBG(" integral: %08x\n", integral);
  1364. integ_p = ((s64)DIMM_PID_G_r) * (s64)integral;
  1365. DBG(" integ_p: %d\n", (int)(integ_p >> 36));
  1366. sum += integ_p;
  1367. /* Calculate the derivative term */
  1368. derivative = state->error_history[state->cur_sample] -
  1369. state->error_history[(state->cur_sample + DIMM_PID_HISTORY_SIZE - 1)
  1370. % DIMM_PID_HISTORY_SIZE];
  1371. derivative /= DIMM_PID_INTERVAL;
  1372. deriv_p = ((s64)DIMM_PID_G_d) * (s64)derivative;
  1373. DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
  1374. sum += deriv_p;
  1375. /* Calculate the proportional term */
  1376. prop_p = ((s64)DIMM_PID_G_p) * (s64)(state->error_history[state->cur_sample]);
  1377. DBG(" prop_p: %d\n", (int)(prop_p >> 36));
  1378. sum += prop_p;
  1379. /* Scale sum */
  1380. sum >>= 36;
  1381. DBG(" sum: %d\n", (int)sum);
  1382. state->output = (s32)sum;
  1383. state->output = max(state->output, DIMM_PID_OUTPUT_MIN);
  1384. state->output = min(state->output, DIMM_PID_OUTPUT_MAX);
  1385. dimm_output_clamp = state->output;
  1386. DBG("** DIMM clamp value: %d\n", (int)state->output);
  1387. /* Backside PID is only every 5 seconds, force backside fan clamping now */
  1388. fan_min = (dimm_output_clamp * 100) / 14000;
  1389. fan_min = max(fan_min, backside_params.output_min);
  1390. if (backside_state.pwm < fan_min) {
  1391. backside_state.pwm = fan_min;
  1392. DBG(" -> applying clamp to backside fan now: %d !\n", fan_min);
  1393. set_pwm_fan(BACKSIDE_FAN_PWM_INDEX, fan_min);
  1394. }
  1395. }
  1396. /*
  1397. * Initialize the state structure for the DIMM temp control loop
  1398. */
  1399. static int init_dimms_state(struct dimm_pid_state *state)
  1400. {
  1401. state->ticks = 1;
  1402. state->first = 1;
  1403. state->output = 4000;
  1404. state->monitor = attach_i2c_chip(XSERVE_DIMMS_LM87, "dimms_temp");
  1405. if (state->monitor == NULL)
  1406. return -ENODEV;
  1407. if (device_create_file(&of_dev->dev, &dev_attr_dimms_temperature))
  1408. printk(KERN_WARNING "Failed to create attribute file"
  1409. " for DIMM temperature\n");
  1410. return 0;
  1411. }
  1412. /*
  1413. * Dispose of the state data for the DIMM control loop
  1414. */
  1415. static void dispose_dimms_state(struct dimm_pid_state *state)
  1416. {
  1417. if (state->monitor == NULL)
  1418. return;
  1419. device_remove_file(&of_dev->dev, &dev_attr_dimms_temperature);
  1420. state->monitor = NULL;
  1421. }
  1422. /*
  1423. * Slots fan control loop
  1424. */
  1425. static void do_monitor_slots(struct slots_pid_state *state)
  1426. {
  1427. s32 temp, integral, derivative;
  1428. s64 integ_p, deriv_p, prop_p, sum;
  1429. int i, rc;
  1430. if (--state->ticks != 0)
  1431. return;
  1432. state->ticks = SLOTS_PID_INTERVAL;
  1433. DBG("slots:\n");
  1434. /* Check fan status */
  1435. rc = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
  1436. if (rc < 0) {
  1437. printk(KERN_WARNING "Error %d reading slots fan !\n", rc);
  1438. /* XXX What do we do now ? */
  1439. } else
  1440. state->pwm = rc;
  1441. DBG(" current pwm: %d\n", state->pwm);
  1442. /* Get some sensor readings */
  1443. temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
  1444. DS1775_TEMP)) << 8;
  1445. state->last_temp = temp;
  1446. DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
  1447. FIX32TOPRINT(SLOTS_PID_INPUT_TARGET));
  1448. /* Store temperature and error in history array */
  1449. state->cur_sample = (state->cur_sample + 1) % SLOTS_PID_HISTORY_SIZE;
  1450. state->sample_history[state->cur_sample] = temp;
  1451. state->error_history[state->cur_sample] = temp - SLOTS_PID_INPUT_TARGET;
  1452. /* If first loop, fill the history table */
  1453. if (state->first) {
  1454. for (i = 0; i < (SLOTS_PID_HISTORY_SIZE - 1); i++) {
  1455. state->cur_sample = (state->cur_sample + 1) %
  1456. SLOTS_PID_HISTORY_SIZE;
  1457. state->sample_history[state->cur_sample] = temp;
  1458. state->error_history[state->cur_sample] =
  1459. temp - SLOTS_PID_INPUT_TARGET;
  1460. }
  1461. state->first = 0;
  1462. }
  1463. /* Calculate the integral term */
  1464. sum = 0;
  1465. integral = 0;
  1466. for (i = 0; i < SLOTS_PID_HISTORY_SIZE; i++)
  1467. integral += state->error_history[i];
  1468. integral *= SLOTS_PID_INTERVAL;
  1469. DBG(" integral: %08x\n", integral);
  1470. integ_p = ((s64)SLOTS_PID_G_r) * (s64)integral;
  1471. DBG(" integ_p: %d\n", (int)(integ_p >> 36));
  1472. sum += integ_p;
  1473. /* Calculate the derivative term */
  1474. derivative = state->error_history[state->cur_sample] -
  1475. state->error_history[(state->cur_sample + SLOTS_PID_HISTORY_SIZE - 1)
  1476. % SLOTS_PID_HISTORY_SIZE];
  1477. derivative /= SLOTS_PID_INTERVAL;
  1478. deriv_p = ((s64)SLOTS_PID_G_d) * (s64)derivative;
  1479. DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
  1480. sum += deriv_p;
  1481. /* Calculate the proportional term */
  1482. prop_p = ((s64)SLOTS_PID_G_p) * (s64)(state->error_history[state->cur_sample]);
  1483. DBG(" prop_p: %d\n", (int)(prop_p >> 36));
  1484. sum += prop_p;
  1485. /* Scale sum */
  1486. sum >>= 36;
  1487. DBG(" sum: %d\n", (int)sum);
  1488. state->pwm = (s32)sum;
  1489. state->pwm = max(state->pwm, SLOTS_PID_OUTPUT_MIN);
  1490. state->pwm = min(state->pwm, SLOTS_PID_OUTPUT_MAX);
  1491. DBG("** DRIVES PWM: %d\n", (int)state->pwm);
  1492. set_pwm_fan(SLOTS_FAN_PWM_INDEX, state->pwm);
  1493. }
  1494. /*
  1495. * Initialize the state structure for the slots bay fan control loop
  1496. */
  1497. static int init_slots_state(struct slots_pid_state *state)
  1498. {
  1499. int err;
  1500. state->ticks = 1;
  1501. state->first = 1;
  1502. state->pwm = 50;
  1503. state->monitor = attach_i2c_chip(XSERVE_SLOTS_LM75, "slots_temp");
  1504. if (state->monitor == NULL)
  1505. return -ENODEV;
  1506. err = device_create_file(&of_dev->dev, &dev_attr_slots_temperature);
  1507. err |= device_create_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
  1508. if (err)
  1509. printk(KERN_WARNING "Failed to create attribute file(s)"
  1510. " for slots bay fan\n");
  1511. return 0;
  1512. }
  1513. /*
  1514. * Dispose of the state data for the slots control loop
  1515. */
  1516. static void dispose_slots_state(struct slots_pid_state *state)
  1517. {
  1518. if (state->monitor == NULL)
  1519. return;
  1520. device_remove_file(&of_dev->dev, &dev_attr_slots_temperature);
  1521. device_remove_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
  1522. state->monitor = NULL;
  1523. }
  1524. static int call_critical_overtemp(void)
  1525. {
  1526. char *argv[] = { critical_overtemp_path, NULL };
  1527. static char *envp[] = { "HOME=/",
  1528. "TERM=linux",
  1529. "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
  1530. NULL };
  1531. return call_usermodehelper(critical_overtemp_path,
  1532. argv, envp, UMH_WAIT_EXEC);
  1533. }
  1534. /*
  1535. * Here's the kernel thread that calls the various control loops
  1536. */
  1537. static int main_control_loop(void *x)
  1538. {
  1539. DBG("main_control_loop started\n");
  1540. mutex_lock(&driver_lock);
  1541. if (start_fcu() < 0) {
  1542. printk(KERN_ERR "kfand: failed to start FCU\n");
  1543. mutex_unlock(&driver_lock);
  1544. goto out;
  1545. }
  1546. /* Set the PCI fan once for now on non-RackMac */
  1547. if (!rackmac)
  1548. set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM);
  1549. /* Initialize ADCs */
  1550. initialize_adc(&cpu_state[0]);
  1551. if (cpu_state[1].monitor != NULL)
  1552. initialize_adc(&cpu_state[1]);
  1553. fcu_tickle_ticks = FCU_TICKLE_TICKS;
  1554. mutex_unlock(&driver_lock);
  1555. while (state == state_attached) {
  1556. unsigned long elapsed, start;
  1557. start = jiffies;
  1558. mutex_lock(&driver_lock);
  1559. /* Tickle the FCU just in case */
  1560. if (--fcu_tickle_ticks < 0) {
  1561. fcu_tickle_ticks = FCU_TICKLE_TICKS;
  1562. tickle_fcu();
  1563. }
  1564. /* First, we always calculate the new DIMMs state on an Xserve */
  1565. if (rackmac)
  1566. do_monitor_dimms(&dimms_state);
  1567. /* Then, the CPUs */
  1568. if (cpu_pid_type == CPU_PID_TYPE_COMBINED)
  1569. do_monitor_cpu_combined();
  1570. else if (cpu_pid_type == CPU_PID_TYPE_RACKMAC) {
  1571. do_monitor_cpu_rack(&cpu_state[0]);
  1572. if (cpu_state[1].monitor != NULL)
  1573. do_monitor_cpu_rack(&cpu_state[1]);
  1574. // better deal with UP
  1575. } else {
  1576. do_monitor_cpu_split(&cpu_state[0]);
  1577. if (cpu_state[1].monitor != NULL)
  1578. do_monitor_cpu_split(&cpu_state[1]);
  1579. // better deal with UP
  1580. }
  1581. /* Then, the rest */
  1582. do_monitor_backside(&backside_state);
  1583. if (rackmac)
  1584. do_monitor_slots(&slots_state);
  1585. else
  1586. do_monitor_drives(&drives_state);
  1587. mutex_unlock(&driver_lock);
  1588. if (critical_state == 1) {
  1589. printk(KERN_WARNING "Temperature control detected a critical condition\n");
  1590. printk(KERN_WARNING "Attempting to shut down...\n");
  1591. if (call_critical_overtemp()) {
  1592. printk(KERN_WARNING "Can't call %s, power off now!\n",
  1593. critical_overtemp_path);
  1594. machine_power_off();
  1595. }
  1596. }
  1597. if (critical_state > 0)
  1598. critical_state++;
  1599. if (critical_state > MAX_CRITICAL_STATE) {
  1600. printk(KERN_WARNING "Shutdown timed out, power off now !\n");
  1601. machine_power_off();
  1602. }
  1603. // FIXME: Deal with signals
  1604. elapsed = jiffies - start;
  1605. if (elapsed < HZ)
  1606. schedule_timeout_interruptible(HZ - elapsed);
  1607. }
  1608. out:
  1609. DBG("main_control_loop ended\n");
  1610. ctrl_task = 0;
  1611. complete_and_exit(&ctrl_complete, 0);
  1612. }
  1613. /*
  1614. * Dispose the control loops when tearing down
  1615. */
  1616. static void dispose_control_loops(void)
  1617. {
  1618. dispose_cpu_state(&cpu_state[0]);
  1619. dispose_cpu_state(&cpu_state[1]);
  1620. dispose_backside_state(&backside_state);
  1621. dispose_drives_state(&drives_state);
  1622. dispose_slots_state(&slots_state);
  1623. dispose_dimms_state(&dimms_state);
  1624. }
  1625. /*
  1626. * Create the control loops. U3-0 i2c bus is up, so we can now
  1627. * get to the various sensors
  1628. */
  1629. static int create_control_loops(void)
  1630. {
  1631. struct device_node *np;
  1632. /* Count CPUs from the device-tree, we don't care how many are
  1633. * actually used by Linux
  1634. */
  1635. cpu_count = 0;
  1636. for (np = NULL; NULL != (np = of_find_node_by_type(np, "cpu"));)
  1637. cpu_count++;
  1638. DBG("counted %d CPUs in the device-tree\n", cpu_count);
  1639. /* Decide the type of PID algorithm to use based on the presence of
  1640. * the pumps, though that may not be the best way, that is good enough
  1641. * for now
  1642. */
  1643. if (rackmac)
  1644. cpu_pid_type = CPU_PID_TYPE_RACKMAC;
  1645. else if (machine_is_compatible("PowerMac7,3")
  1646. && (cpu_count > 1)
  1647. && fcu_fans[CPUA_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID
  1648. && fcu_fans[CPUB_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID) {
  1649. printk(KERN_INFO "Liquid cooling pumps detected, using new algorithm !\n");
  1650. cpu_pid_type = CPU_PID_TYPE_COMBINED;
  1651. } else
  1652. cpu_pid_type = CPU_PID_TYPE_SPLIT;
  1653. /* Create control loops for everything. If any fail, everything
  1654. * fails
  1655. */
  1656. if (init_cpu_state(&cpu_state[0], 0))
  1657. goto fail;
  1658. if (cpu_pid_type == CPU_PID_TYPE_COMBINED)
  1659. fetch_cpu_pumps_minmax();
  1660. if (cpu_count > 1 && init_cpu_state(&cpu_state[1], 1))
  1661. goto fail;
  1662. if (init_backside_state(&backside_state))
  1663. goto fail;
  1664. if (rackmac && init_dimms_state(&dimms_state))
  1665. goto fail;
  1666. if (rackmac && init_slots_state(&slots_state))
  1667. goto fail;
  1668. if (!rackmac && init_drives_state(&drives_state))
  1669. goto fail;
  1670. DBG("all control loops up !\n");
  1671. return 0;
  1672. fail:
  1673. DBG("failure creating control loops, disposing\n");
  1674. dispose_control_loops();
  1675. return -ENODEV;
  1676. }
  1677. /*
  1678. * Start the control loops after everything is up, that is create
  1679. * the thread that will make them run
  1680. */
  1681. static void start_control_loops(void)
  1682. {
  1683. init_completion(&ctrl_complete);
  1684. ctrl_task = kthread_run(main_control_loop, NULL, "kfand");
  1685. }
  1686. /*
  1687. * Stop the control loops when tearing down
  1688. */
  1689. static void stop_control_loops(void)
  1690. {
  1691. if (ctrl_task)
  1692. wait_for_completion(&ctrl_complete);
  1693. }
  1694. /*
  1695. * Attach to the i2c FCU after detecting U3-1 bus
  1696. */
  1697. static int attach_fcu(void)
  1698. {
  1699. fcu = attach_i2c_chip(FAN_CTRLER_ID, "fcu");
  1700. if (fcu == NULL)
  1701. return -ENODEV;
  1702. DBG("FCU attached\n");
  1703. return 0;
  1704. }
  1705. /*
  1706. * Detach from the i2c FCU when tearing down
  1707. */
  1708. static void detach_fcu(void)
  1709. {
  1710. fcu = NULL;
  1711. }
  1712. /*
  1713. * Attach to the i2c controller. We probe the various chips based
  1714. * on the device-tree nodes and build everything for the driver to
  1715. * run, we then kick the driver monitoring thread
  1716. */
  1717. static int therm_pm72_attach(struct i2c_adapter *adapter)
  1718. {
  1719. mutex_lock(&driver_lock);
  1720. /* Check state */
  1721. if (state == state_detached)
  1722. state = state_attaching;
  1723. if (state != state_attaching) {
  1724. mutex_unlock(&driver_lock);
  1725. return 0;
  1726. }
  1727. /* Check if we are looking for one of these */
  1728. if (u3_0 == NULL && !strcmp(adapter->name, "u3 0")) {
  1729. u3_0 = adapter;
  1730. DBG("found U3-0\n");
  1731. if (k2 || !rackmac)
  1732. if (create_control_loops())
  1733. u3_0 = NULL;
  1734. } else if (u3_1 == NULL && !strcmp(adapter->name, "u3 1")) {
  1735. u3_1 = adapter;
  1736. DBG("found U3-1, attaching FCU\n");
  1737. if (attach_fcu())
  1738. u3_1 = NULL;
  1739. } else if (k2 == NULL && !strcmp(adapter->name, "mac-io 0")) {
  1740. k2 = adapter;
  1741. DBG("Found K2\n");
  1742. if (u3_0 && rackmac)
  1743. if (create_control_loops())
  1744. k2 = NULL;
  1745. }
  1746. /* We got all we need, start control loops */
  1747. if (u3_0 != NULL && u3_1 != NULL && (k2 || !rackmac)) {
  1748. DBG("everything up, starting control loops\n");
  1749. state = state_attached;
  1750. start_control_loops();
  1751. }
  1752. mutex_unlock(&driver_lock);
  1753. return 0;
  1754. }
  1755. static int therm_pm72_probe(struct i2c_client *client,
  1756. const struct i2c_device_id *id)
  1757. {
  1758. /* Always succeed, the real work was done in therm_pm72_attach() */
  1759. return 0;
  1760. }
  1761. /*
  1762. * Called when any of the devices which participates into thermal management
  1763. * is going away.
  1764. */
  1765. static int therm_pm72_remove(struct i2c_client *client)
  1766. {
  1767. struct i2c_adapter *adapter = client->adapter;
  1768. mutex_lock(&driver_lock);
  1769. if (state != state_detached)
  1770. state = state_detaching;
  1771. /* Stop control loops if any */
  1772. DBG("stopping control loops\n");
  1773. mutex_unlock(&driver_lock);
  1774. stop_control_loops();
  1775. mutex_lock(&driver_lock);
  1776. if (u3_0 != NULL && !strcmp(adapter->name, "u3 0")) {
  1777. DBG("lost U3-0, disposing control loops\n");
  1778. dispose_control_loops();
  1779. u3_0 = NULL;
  1780. }
  1781. if (u3_1 != NULL && !strcmp(adapter->name, "u3 1")) {
  1782. DBG("lost U3-1, detaching FCU\n");
  1783. detach_fcu();
  1784. u3_1 = NULL;
  1785. }
  1786. if (u3_0 == NULL && u3_1 == NULL)
  1787. state = state_detached;
  1788. mutex_unlock(&driver_lock);
  1789. return 0;
  1790. }
  1791. /*
  1792. * i2c_driver structure to attach to the host i2c controller
  1793. */
  1794. static const struct i2c_device_id therm_pm72_id[] = {
  1795. /*
  1796. * Fake device name, thermal management is done by several
  1797. * chips but we don't need to differentiate between them at
  1798. * this point.
  1799. */
  1800. { "therm_pm72", 0 },
  1801. { }
  1802. };
  1803. static struct i2c_driver therm_pm72_driver = {
  1804. .driver = {
  1805. .name = "therm_pm72",
  1806. },
  1807. .attach_adapter = therm_pm72_attach,
  1808. .probe = therm_pm72_probe,
  1809. .remove = therm_pm72_remove,
  1810. .id_table = therm_pm72_id,
  1811. };
  1812. static int fan_check_loc_match(const char *loc, int fan)
  1813. {
  1814. char tmp[64];
  1815. char *c, *e;
  1816. strlcpy(tmp, fcu_fans[fan].loc, 64);
  1817. c = tmp;
  1818. for (;;) {
  1819. e = strchr(c, ',');
  1820. if (e)
  1821. *e = 0;
  1822. if (strcmp(loc, c) == 0)
  1823. return 1;
  1824. if (e == NULL)
  1825. break;
  1826. c = e + 1;
  1827. }
  1828. return 0;
  1829. }
  1830. static void fcu_lookup_fans(struct device_node *fcu_node)
  1831. {
  1832. struct device_node *np = NULL;
  1833. int i;
  1834. /* The table is filled by default with values that are suitable
  1835. * for the old machines without device-tree informations. We scan
  1836. * the device-tree and override those values with whatever is
  1837. * there
  1838. */
  1839. DBG("Looking up FCU controls in device-tree...\n");
  1840. while ((np = of_get_next_child(fcu_node, np)) != NULL) {
  1841. int type = -1;
  1842. const char *loc;
  1843. const u32 *reg;
  1844. DBG(" control: %s, type: %s\n", np->name, np->type);
  1845. /* Detect control type */
  1846. if (!strcmp(np->type, "fan-rpm-control") ||
  1847. !strcmp(np->type, "fan-rpm"))
  1848. type = FCU_FAN_RPM;
  1849. if (!strcmp(np->type, "fan-pwm-control") ||
  1850. !strcmp(np->type, "fan-pwm"))
  1851. type = FCU_FAN_PWM;
  1852. /* Only care about fans for now */
  1853. if (type == -1)
  1854. continue;
  1855. /* Lookup for a matching location */
  1856. loc = of_get_property(np, "location", NULL);
  1857. reg = of_get_property(np, "reg", NULL);
  1858. if (loc == NULL || reg == NULL)
  1859. continue;
  1860. DBG(" matching location: %s, reg: 0x%08x\n", loc, *reg);
  1861. for (i = 0; i < FCU_FAN_COUNT; i++) {
  1862. int fan_id;
  1863. if (!fan_check_loc_match(loc, i))
  1864. continue;
  1865. DBG(" location match, index: %d\n", i);
  1866. fcu_fans[i].id = FCU_FAN_ABSENT_ID;
  1867. if (type != fcu_fans[i].type) {
  1868. printk(KERN_WARNING "therm_pm72: Fan type mismatch "
  1869. "in device-tree for %s\n", np->full_name);
  1870. break;
  1871. }
  1872. if (type == FCU_FAN_RPM)
  1873. fan_id = ((*reg) - 0x10) / 2;
  1874. else
  1875. fan_id = ((*reg) - 0x30) / 2;
  1876. if (fan_id > 7) {
  1877. printk(KERN_WARNING "therm_pm72: Can't parse "
  1878. "fan ID in device-tree for %s\n", np->full_name);
  1879. break;
  1880. }
  1881. DBG(" fan id -> %d, type -> %d\n", fan_id, type);
  1882. fcu_fans[i].id = fan_id;
  1883. }
  1884. }
  1885. /* Now dump the array */
  1886. printk(KERN_INFO "Detected fan controls:\n");
  1887. for (i = 0; i < FCU_FAN_COUNT; i++) {
  1888. if (fcu_fans[i].id == FCU_FAN_ABSENT_ID)
  1889. continue;
  1890. printk(KERN_INFO " %d: %s fan, id %d, location: %s\n", i,
  1891. fcu_fans[i].type == FCU_FAN_RPM ? "RPM" : "PWM",
  1892. fcu_fans[i].id, fcu_fans[i].loc);
  1893. }
  1894. }
  1895. static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
  1896. {
  1897. state = state_detached;
  1898. /* Lookup the fans in the device tree */
  1899. fcu_lookup_fans(dev->node);
  1900. /* Add the driver */
  1901. return i2c_add_driver(&therm_pm72_driver);
  1902. }
  1903. static int fcu_of_remove(struct of_device* dev)
  1904. {
  1905. i2c_del_driver(&therm_pm72_driver);
  1906. return 0;
  1907. }
  1908. static struct of_device_id fcu_match[] =
  1909. {
  1910. {
  1911. .type = "fcu",
  1912. },
  1913. {},
  1914. };
  1915. static struct of_platform_driver fcu_of_platform_driver =
  1916. {
  1917. .name = "temperature",
  1918. .match_table = fcu_match,
  1919. .probe = fcu_of_probe,
  1920. .remove = fcu_of_remove
  1921. };
  1922. /*
  1923. * Check machine type, attach to i2c controller
  1924. */
  1925. static int __init therm_pm72_init(void)
  1926. {
  1927. struct device_node *np;
  1928. rackmac = machine_is_compatible("RackMac3,1");
  1929. if (!machine_is_compatible("PowerMac7,2") &&
  1930. !machine_is_compatible("PowerMac7,3") &&
  1931. !rackmac)
  1932. return -ENODEV;
  1933. printk(KERN_INFO "PowerMac G5 Thermal control driver %s\n", VERSION);
  1934. np = of_find_node_by_type(NULL, "fcu");
  1935. if (np == NULL) {
  1936. /* Some machines have strangely broken device-tree */
  1937. np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
  1938. if (np == NULL) {
  1939. printk(KERN_ERR "Can't find FCU in device-tree !\n");
  1940. return -ENODEV;
  1941. }
  1942. }
  1943. of_dev = of_platform_device_create(np, "temperature", NULL);
  1944. if (of_dev == NULL) {
  1945. printk(KERN_ERR "Can't register FCU platform device !\n");
  1946. return -ENODEV;
  1947. }
  1948. of_register_platform_driver(&fcu_of_platform_driver);
  1949. return 0;
  1950. }
  1951. static void __exit therm_pm72_exit(void)
  1952. {
  1953. of_unregister_platform_driver(&fcu_of_platform_driver);
  1954. if (of_dev)
  1955. of_device_unregister(of_dev);
  1956. }
  1957. module_init(therm_pm72_init);
  1958. module_exit(therm_pm72_exit);
  1959. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  1960. MODULE_DESCRIPTION("Driver for Apple's PowerMac G5 thermal control");
  1961. MODULE_LICENSE("GPL");