therm_pm72.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #ifndef __THERM_PMAC_7_2_H__
  2. #define __THERM_PMAC_7_2_H__
  3. typedef unsigned short fu16;
  4. typedef int fs32;
  5. typedef short fs16;
  6. struct mpu_data
  7. {
  8. u8 signature; /* 0x00 - EEPROM sig. */
  9. u8 bytes_used; /* 0x01 - Bytes used in eeprom (160 ?) */
  10. u8 size; /* 0x02 - EEPROM size (256 ?) */
  11. u8 version; /* 0x03 - EEPROM version */
  12. u32 data_revision; /* 0x04 - Dataset revision */
  13. u8 processor_bin_code[3]; /* 0x08 - Processor BIN code */
  14. u8 bin_code_expansion; /* 0x0b - ??? (padding ?) */
  15. u8 processor_num; /* 0x0c - Number of CPUs on this MPU */
  16. u8 input_mul_bus_div; /* 0x0d - Clock input multiplier/bus divider */
  17. u8 reserved1[2]; /* 0x0e - */
  18. u32 input_clk_freq_high; /* 0x10 - Input clock frequency high */
  19. u8 cpu_nb_target_cycles; /* 0x14 - ??? */
  20. u8 cpu_statlat; /* 0x15 - ??? */
  21. u8 cpu_snooplat; /* 0x16 - ??? */
  22. u8 cpu_snoopacc; /* 0x17 - ??? */
  23. u8 nb_paamwin; /* 0x18 - ??? */
  24. u8 nb_statlat; /* 0x19 - ??? */
  25. u8 nb_snooplat; /* 0x1a - ??? */
  26. u8 nb_snoopwin; /* 0x1b - ??? */
  27. u8 api_bus_mode; /* 0x1c - ??? */
  28. u8 reserved2[3]; /* 0x1d - */
  29. u32 input_clk_freq_low; /* 0x20 - Input clock frequency low */
  30. u8 processor_card_slot; /* 0x24 - Processor card slot number */
  31. u8 reserved3[2]; /* 0x25 - */
  32. u8 padjmax; /* 0x27 - Max power adjustment (Not in OF!) */
  33. u8 ttarget; /* 0x28 - Target temperature */
  34. u8 tmax; /* 0x29 - Max temperature */
  35. u8 pmaxh; /* 0x2a - Max power */
  36. u8 tguardband; /* 0x2b - Guardband temp ??? Hist. len in OSX */
  37. fs32 pid_gp; /* 0x2c - PID proportional gain */
  38. fs32 pid_gr; /* 0x30 - PID reset gain */
  39. fs32 pid_gd; /* 0x34 - PID derivative gain */
  40. fu16 voph; /* 0x38 - Vop High */
  41. fu16 vopl; /* 0x3a - Vop Low */
  42. fs16 nactual_die; /* 0x3c - nActual Die */
  43. fs16 nactual_heatsink; /* 0x3e - nActual Heatsink */
  44. fs16 nactual_system; /* 0x40 - nActual System */
  45. u16 calibration_flags; /* 0x42 - Calibration flags */
  46. fu16 mdiode; /* 0x44 - Diode M value (scaling factor) */
  47. fs16 bdiode; /* 0x46 - Diode B value (offset) */
  48. fs32 theta_heat_sink; /* 0x48 - Theta heat sink */
  49. u16 rminn_intake_fan; /* 0x4c - Intake fan min RPM */
  50. u16 rmaxn_intake_fan; /* 0x4e - Intake fan max RPM */
  51. u16 rminn_exhaust_fan; /* 0x50 - Exhaust fan min RPM */
  52. u16 rmaxn_exhaust_fan; /* 0x52 - Exhaust fan max RPM */
  53. u8 processor_part_num[8]; /* 0x54 - Processor part number XX pumps min/max */
  54. u32 processor_lot_num; /* 0x5c - Processor lot number */
  55. u8 orig_card_sernum[0x10]; /* 0x60 - Card original serial number */
  56. u8 curr_card_sernum[0x10]; /* 0x70 - Card current serial number */
  57. u8 mlb_sernum[0x18]; /* 0x80 - MLB serial number */
  58. u32 checksum1; /* 0x98 - */
  59. u32 checksum2; /* 0x9c - */
  60. }; /* Total size = 0xa0 */
  61. /* Display a 16.16 fixed point value */
  62. #define FIX32TOPRINT(f) ((f) >> 16),((((f) & 0xffff) * 1000) >> 16)
  63. /*
  64. * Maximum number of seconds to be in critical state (after a
  65. * normal shutdown attempt). If the machine isn't down after
  66. * this counter elapses, we force an immediate machine power
  67. * off.
  68. */
  69. #define MAX_CRITICAL_STATE 30
  70. static char * critical_overtemp_path = "/sbin/critical_overtemp";
  71. /*
  72. * This option is "weird" :) Basically, if you define this to 1
  73. * the control loop for the RPMs fans (not PWMs) will apply the
  74. * correction factor obtained from the PID to the _actual_ RPM
  75. * speed read from the FCU.
  76. * If you define the below constant to 0, then it will be
  77. * applied to the setpoint RPM speed, that is basically the
  78. * speed we proviously "asked" for.
  79. *
  80. * I'm not sure which of these Apple's algorithm is supposed
  81. * to use
  82. */
  83. #define RPM_PID_USE_ACTUAL_SPEED 0
  84. /*
  85. * i2c IDs. Currently, we hard code those and assume that
  86. * the FCU is on U3 bus 1 while all sensors are on U3 bus
  87. * 0. This appear to be safe enough for this first version
  88. * of the driver, though I would accept any clean patch
  89. * doing a better use of the device-tree without turning the
  90. * while i2c registration mechanism into a racy mess
  91. *
  92. * Note: Xserve changed this. We have some bits on the K2 bus,
  93. * which I arbitrarily set to 0x200. Ultimately, we really want
  94. * too lookup these in the device-tree though
  95. */
  96. #define FAN_CTRLER_ID 0x15e
  97. #define SUPPLY_MONITOR_ID 0x58
  98. #define SUPPLY_MONITORB_ID 0x5a
  99. #define DRIVES_DALLAS_ID 0x94
  100. #define BACKSIDE_MAX_ID 0x98
  101. #define XSERVE_DIMMS_LM87 0x25a
  102. #define XSERVE_SLOTS_LM75 0x290
  103. /*
  104. * Some MAX6690, DS1775, LM87 register definitions
  105. */
  106. #define MAX6690_INT_TEMP 0
  107. #define MAX6690_EXT_TEMP 1
  108. #define DS1775_TEMP 0
  109. #define LM87_INT_TEMP 0x27
  110. /*
  111. * Scaling factors for the AD7417 ADC converters (except
  112. * for the CPU diode which is obtained from the EEPROM).
  113. * Those values are obtained from the property list of
  114. * the darwin driver
  115. */
  116. #define ADC_12V_CURRENT_SCALE 0x0320 /* _AD2 */
  117. #define ADC_CPU_VOLTAGE_SCALE 0x00a0 /* _AD3 */
  118. #define ADC_CPU_CURRENT_SCALE 0x1f40 /* _AD4 */
  119. /*
  120. * PID factors for the U3/Backside fan control loop. We have 2 sets
  121. * of values here, one set for U3 and one set for U3H
  122. */
  123. #define BACKSIDE_FAN_PWM_DEFAULT_ID 1
  124. #define BACKSIDE_FAN_PWM_INDEX 0
  125. #define BACKSIDE_PID_U3_G_d 0x02800000
  126. #define BACKSIDE_PID_U3H_G_d 0x01400000
  127. #define BACKSIDE_PID_RACK_G_d 0x00500000
  128. #define BACKSIDE_PID_G_p 0x00500000
  129. #define BACKSIDE_PID_RACK_G_p 0x0004cccc
  130. #define BACKSIDE_PID_G_r 0x00000000
  131. #define BACKSIDE_PID_U3_INPUT_TARGET 0x00410000
  132. #define BACKSIDE_PID_U3H_INPUT_TARGET 0x004b0000
  133. #define BACKSIDE_PID_RACK_INPUT_TARGET 0x00460000
  134. #define BACKSIDE_PID_INTERVAL 5
  135. #define BACKSIDE_PID_RACK_INTERVAL 1
  136. #define BACKSIDE_PID_OUTPUT_MAX 100
  137. #define BACKSIDE_PID_U3_OUTPUT_MIN 20
  138. #define BACKSIDE_PID_U3H_OUTPUT_MIN 20
  139. #define BACKSIDE_PID_HISTORY_SIZE 2
  140. struct basckside_pid_params
  141. {
  142. s32 G_d;
  143. s32 G_p;
  144. s32 G_r;
  145. s32 input_target;
  146. s32 output_min;
  147. s32 output_max;
  148. s32 interval;
  149. int additive;
  150. };
  151. struct backside_pid_state
  152. {
  153. int ticks;
  154. struct i2c_client * monitor;
  155. s32 sample_history[BACKSIDE_PID_HISTORY_SIZE];
  156. s32 error_history[BACKSIDE_PID_HISTORY_SIZE];
  157. int cur_sample;
  158. s32 last_temp;
  159. int pwm;
  160. int first;
  161. };
  162. /*
  163. * PID factors for the Drive Bay fan control loop
  164. */
  165. #define DRIVES_FAN_RPM_DEFAULT_ID 2
  166. #define DRIVES_FAN_RPM_INDEX 1
  167. #define DRIVES_PID_G_d 0x01e00000
  168. #define DRIVES_PID_G_p 0x00500000
  169. #define DRIVES_PID_G_r 0x00000000
  170. #define DRIVES_PID_INPUT_TARGET 0x00280000
  171. #define DRIVES_PID_INTERVAL 5
  172. #define DRIVES_PID_OUTPUT_MAX 4000
  173. #define DRIVES_PID_OUTPUT_MIN 300
  174. #define DRIVES_PID_HISTORY_SIZE 2
  175. struct drives_pid_state
  176. {
  177. int ticks;
  178. struct i2c_client * monitor;
  179. s32 sample_history[BACKSIDE_PID_HISTORY_SIZE];
  180. s32 error_history[BACKSIDE_PID_HISTORY_SIZE];
  181. int cur_sample;
  182. s32 last_temp;
  183. int rpm;
  184. int first;
  185. };
  186. #define SLOTS_FAN_PWM_DEFAULT_ID 2
  187. #define SLOTS_FAN_PWM_INDEX 2
  188. #define SLOTS_FAN_DEFAULT_PWM 40 /* Do better here ! */
  189. /*
  190. * PID factors for the Xserve DIMM control loop
  191. */
  192. #define DIMM_PID_G_d 0
  193. #define DIMM_PID_G_p 0
  194. #define DIMM_PID_G_r 0x06553600
  195. #define DIMM_PID_INPUT_TARGET 3276800
  196. #define DIMM_PID_INTERVAL 1
  197. #define DIMM_PID_OUTPUT_MAX 14000
  198. #define DIMM_PID_OUTPUT_MIN 4000
  199. #define DIMM_PID_HISTORY_SIZE 20
  200. struct dimm_pid_state
  201. {
  202. int ticks;
  203. struct i2c_client * monitor;
  204. s32 sample_history[DIMM_PID_HISTORY_SIZE];
  205. s32 error_history[DIMM_PID_HISTORY_SIZE];
  206. int cur_sample;
  207. s32 last_temp;
  208. int first;
  209. int output;
  210. };
  211. /*
  212. * PID factors for the Xserve Slots control loop
  213. */
  214. #define SLOTS_PID_G_d 0
  215. #define SLOTS_PID_G_p 0
  216. #define SLOTS_PID_G_r 0x00100000
  217. #define SLOTS_PID_INPUT_TARGET 3200000
  218. #define SLOTS_PID_INTERVAL 1
  219. #define SLOTS_PID_OUTPUT_MAX 100
  220. #define SLOTS_PID_OUTPUT_MIN 20
  221. #define SLOTS_PID_HISTORY_SIZE 20
  222. struct slots_pid_state
  223. {
  224. int ticks;
  225. struct i2c_client * monitor;
  226. s32 sample_history[SLOTS_PID_HISTORY_SIZE];
  227. s32 error_history[SLOTS_PID_HISTORY_SIZE];
  228. int cur_sample;
  229. s32 last_temp;
  230. int first;
  231. int pwm;
  232. };
  233. /* Desktops */
  234. #define CPUA_INTAKE_FAN_RPM_DEFAULT_ID 3
  235. #define CPUA_EXHAUST_FAN_RPM_DEFAULT_ID 4
  236. #define CPUB_INTAKE_FAN_RPM_DEFAULT_ID 5
  237. #define CPUB_EXHAUST_FAN_RPM_DEFAULT_ID 6
  238. #define CPUA_INTAKE_FAN_RPM_INDEX 3
  239. #define CPUA_EXHAUST_FAN_RPM_INDEX 4
  240. #define CPUB_INTAKE_FAN_RPM_INDEX 5
  241. #define CPUB_EXHAUST_FAN_RPM_INDEX 6
  242. #define CPU_INTAKE_SCALE 0x0000f852
  243. #define CPU_TEMP_HISTORY_SIZE 2
  244. #define CPU_POWER_HISTORY_SIZE 10
  245. #define CPU_PID_INTERVAL 1
  246. #define CPU_MAX_OVERTEMP 90
  247. #define CPUA_PUMP_RPM_INDEX 7
  248. #define CPUB_PUMP_RPM_INDEX 8
  249. #define CPU_PUMP_OUTPUT_MAX 3200
  250. #define CPU_PUMP_OUTPUT_MIN 1250
  251. /* Xserve */
  252. #define CPU_A1_FAN_RPM_INDEX 9
  253. #define CPU_A2_FAN_RPM_INDEX 10
  254. #define CPU_A3_FAN_RPM_INDEX 11
  255. #define CPU_B1_FAN_RPM_INDEX 12
  256. #define CPU_B2_FAN_RPM_INDEX 13
  257. #define CPU_B3_FAN_RPM_INDEX 14
  258. struct cpu_pid_state
  259. {
  260. int index;
  261. struct i2c_client * monitor;
  262. struct mpu_data mpu;
  263. int overtemp;
  264. s32 temp_history[CPU_TEMP_HISTORY_SIZE];
  265. int cur_temp;
  266. s32 power_history[CPU_POWER_HISTORY_SIZE];
  267. s32 error_history[CPU_POWER_HISTORY_SIZE];
  268. int cur_power;
  269. int count_power;
  270. int rpm;
  271. int intake_rpm;
  272. s32 voltage;
  273. s32 current_a;
  274. s32 last_temp;
  275. s32 last_power;
  276. int first;
  277. u8 adc_config;
  278. s32 pump_min;
  279. s32 pump_max;
  280. };
  281. /* Tickle FCU every 10 seconds */
  282. #define FCU_TICKLE_TICKS 10
  283. /*
  284. * Driver state
  285. */
  286. enum {
  287. state_detached,
  288. state_attaching,
  289. state_attached,
  290. state_detaching,
  291. };
  292. #endif /* __THERM_PMAC_7_2_H__ */