therm_pm72.c 62 KB

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