therm_pm72.c 62 KB

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