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