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 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");