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