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