| 1 | /* |
|---|
| 2 | maxilife.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 1999-2000 Fons Rademakers <Fons.Rademakers@cern.ch> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | /* The is the driver for the HP MaxiLife Health monitoring system |
|---|
| 22 | as used in the line of HP Kayak Workstation PC's. |
|---|
| 23 | |
|---|
| 24 | The driver supports the following MaxiLife firmware versions: |
|---|
| 25 | |
|---|
| 26 | 0) HP KAYAK XU/XAs (Dual Pentium II Slot 1, Deschutes/Klamath) |
|---|
| 27 | 1) HP KAYAK XU (Dual Xeon [Slot 2] 400/450 Mhz) |
|---|
| 28 | 2) HP KAYAK XA (Pentium II Slot 1, monoprocessor) |
|---|
| 29 | |
|---|
| 30 | Currently firmware auto detection is not implemented. To use the |
|---|
| 31 | driver load it with the correct option for you Kayak. For example: |
|---|
| 32 | |
|---|
| 33 | insmod maxilife.o maxi_version=0 | 1 | 2 |
|---|
| 34 | |
|---|
| 35 | maxi_version=0 is the default |
|---|
| 36 | |
|---|
| 37 | This version of MaxiLife is called MaxiLife'98 and has been |
|---|
| 38 | succeeded by MaxiLife'99, see below. |
|---|
| 39 | |
|---|
| 40 | The new version of the driver also supports MaxiLife NBA (New BIOS |
|---|
| 41 | Architecture). This new MaxiLife controller provides a much cleaner |
|---|
| 42 | machine independent abstraction layer to the MaxiLife controller. |
|---|
| 43 | Instead of accessing directly registers (different for each revision) |
|---|
| 44 | one now accesses the sensors via unique mailbox tokens that do not |
|---|
| 45 | change between revisions. Also the quantities are already in physical |
|---|
| 46 | units (degrees, rpms, voltages, etc.) and don't need special conversion |
|---|
| 47 | formulas. This new MaxiLife is available on the new 2000 machines, |
|---|
| 48 | like the Kayak XU800 and XM600. This hardware is also autodetected. |
|---|
| 49 | */ |
|---|
| 50 | |
|---|
| 51 | static const char *version_str = "2.00 29/2/2000 Fons Rademakers"; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | #include <linux/module.h> |
|---|
| 55 | #include <linux/slab.h> |
|---|
| 56 | #include <linux/i2c.h> |
|---|
| 57 | #include <linux/i2c-proc.h> |
|---|
| 58 | #include <linux/init.h> |
|---|
| 59 | #include "version.h" |
|---|
| 60 | |
|---|
| 61 | MODULE_LICENSE("GPL"); |
|---|
| 62 | |
|---|
| 63 | #undef AUTODETECT /* try to autodetect MaxiLife version */ |
|---|
| 64 | /*#define AUTODETECT*/ |
|---|
| 65 | #define NOWRITE /* don't allow writing to MaxiLife registers */ |
|---|
| 66 | |
|---|
| 67 | #ifdef AUTODETECT |
|---|
| 68 | #include <linux/vmalloc.h> |
|---|
| 69 | #include <linux/ctype.h> |
|---|
| 70 | #endif |
|---|
| 71 | |
|---|
| 72 | /* Addresses to scan */ |
|---|
| 73 | static unsigned short normal_i2c[] = { SENSORS_I2C_END }; |
|---|
| 74 | static unsigned short normal_i2c_range[] = { 0x10, 0x14, SENSORS_I2C_END }; |
|---|
| 75 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 76 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 77 | |
|---|
| 78 | /* Insmod parameters */ |
|---|
| 79 | SENSORS_INSMOD_1(maxilife); |
|---|
| 80 | |
|---|
| 81 | /* Macro definitions */ |
|---|
| 82 | #define LOW(MyWord) ((u8) (MyWord)) |
|---|
| 83 | #define HIGH(MyWord) ((u8) (((u16)(MyWord) >> 8) & 0xFF)) |
|---|
| 84 | |
|---|
| 85 | /*----------------- MaxiLife'98 registers and conversion formulas ------------*/ |
|---|
| 86 | #define MAXI_REG_TEMP(nr) (0x60 + (nr)) |
|---|
| 87 | |
|---|
| 88 | #define MAXI_REG_FAN(nr) (0x65 + (nr)) |
|---|
| 89 | #define MAXI_REG_FAN_MIN(nr) ((nr)==0 ? 0xb3 : (nr)==1 ? 0xb3 : 0xab) |
|---|
| 90 | #define MAXI_REG_FAN_MINAS(nr) ((nr)==0 ? 0xb3 : (nr)==1 ? 0xab : 0xb3) |
|---|
| 91 | #define MAXI_REG_FAN_SPEED(nr) ((nr)==0 ? 0xe4 : (nr)==1 ? 0xe5 : 0xe9) |
|---|
| 92 | |
|---|
| 93 | #define MAXI_REG_PLL 0xb9 |
|---|
| 94 | #define MAXI_REG_PLL_MIN 0xba |
|---|
| 95 | #define MAXI_REG_PLL_MAX 0xbb |
|---|
| 96 | |
|---|
| 97 | #define MAXI_REG_VID(nr) ((nr)==0 ? 0xd1 : (nr)==1 ? 0xd9 : \ |
|---|
| 98 | (nr)==2 ? 0xd4 : 0xc5) |
|---|
| 99 | #define MAXI_REG_VID_MIN(nr) MAXI_REG_VID(nr)+1 |
|---|
| 100 | #define MAXI_REG_VID_MAX(nr) MAXI_REG_VID(nr)+2 |
|---|
| 101 | |
|---|
| 102 | #define MAXI_REG_DIAG_RT1 0x2c |
|---|
| 103 | #define MAXI_REG_DIAG_RT2 0x2d |
|---|
| 104 | |
|---|
| 105 | #define MAXI_REG_BIOS_CTRL 0x2a |
|---|
| 106 | |
|---|
| 107 | /* Conversions. Rounding and limit checking is only done on the TO_REG |
|---|
| 108 | variants. Note that you should be a bit careful with which arguments |
|---|
| 109 | these macros are called: arguments may be evaluated more than once. |
|---|
| 110 | Fixing this is just not worth it. */ |
|---|
| 111 | |
|---|
| 112 | /* 0xfe: fan off, 0xff: stopped (alarm) */ |
|---|
| 113 | /* 19531 / val * 60 == 1171860 / val */ |
|---|
| 114 | #define FAN_FROM_REG(val) ((val)==0xfe ? 0 : (val)==0xff ? -1 : \ |
|---|
| 115 | (val)==0x00 ? -1 : (1171860 / (val))) |
|---|
| 116 | |
|---|
| 117 | static inline u8 FAN_TO_REG(long rpm) |
|---|
| 118 | { |
|---|
| 119 | if (rpm == 0) |
|---|
| 120 | return 255; |
|---|
| 121 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
|---|
| 122 | return SENSORS_LIMIT((1171860 + rpm / 2) / (rpm), 1, 254); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | #define TEMP_FROM_REG(val) ((val) * 5) |
|---|
| 126 | #define TEMP_TO_REG(val) (SENSORS_LIMIT((val+2) / 5),0,0xff) |
|---|
| 127 | #define PLL_FROM_REG(val) (((val) * 1000) / 32) |
|---|
| 128 | #define PLL_TO_REG(val) (SENSORS_LIMIT((((val) * 32 + 500) / 1000),\ |
|---|
| 129 | 0,0xff)) |
|---|
| 130 | #define VID_FROM_REG(val) ((val) ? (((val) * 27390) / 256) + 3208 : 0) |
|---|
| 131 | #define VID_TO_REG(val) (SENSORS_LIMIT((((val) - 3208) * 256) / 27390, \ |
|---|
| 132 | 0,255)) |
|---|
| 133 | #define ALARMS_FROM_REG(val) (val) |
|---|
| 134 | |
|---|
| 135 | /*----------------- MaxiLife'99 mailbox and token definitions ----------------*/ |
|---|
| 136 | /* MaxiLife mailbox data register map */ |
|---|
| 137 | #define MAXI_REG_MBX_STATUS 0x5a |
|---|
| 138 | #define MAXI_REG_MBX_CMD 0x5b |
|---|
| 139 | #define MAXI_REG_MBX_TOKEN_H 0x5c |
|---|
| 140 | #define MAXI_REG_MBX_TOKEN_L 0x5d |
|---|
| 141 | #define MAXI_REG_MBX_DATA 0x60 |
|---|
| 142 | |
|---|
| 143 | /* Mailbox status register definition */ |
|---|
| 144 | #define MAXI_STAT_IDLE 0xff |
|---|
| 145 | #define MAXI_STAT_OK 0x00 |
|---|
| 146 | #define MAXI_STAT_BUSY 0x0b |
|---|
| 147 | /* other values not used */ |
|---|
| 148 | |
|---|
| 149 | /* Mailbox command register opcodes */ |
|---|
| 150 | #define MAXI_CMD_READ 0x02 |
|---|
| 151 | #define MAXI_CMD_WRITE 0x03 |
|---|
| 152 | /* other values not used */ |
|---|
| 153 | |
|---|
| 154 | /* MaxiLife NBA Hardware monitoring tokens */ |
|---|
| 155 | |
|---|
| 156 | /* Alarm tokens (0x1xxx) */ |
|---|
| 157 | #define MAXI_TOK_ALARM(nr) (0x1000 + (nr)) |
|---|
| 158 | #define MAXI_TOK_ALARM_EVENT 0x1000 |
|---|
| 159 | #define MAXI_TOK_ALARM_FAN 0x1001 |
|---|
| 160 | #define MAXI_TOK_ALARM_TEMP 0x1002 |
|---|
| 161 | #define MAXI_TOK_ALARM_VID 0x1003 /* voltages */ |
|---|
| 162 | #define MAXI_TOK_ALARM_AVID 0x1004 /* additional voltages */ |
|---|
| 163 | #define MAXI_TOK_ALARM_PWR 0x1101 /* power supply glitch */ |
|---|
| 164 | |
|---|
| 165 | /* Fan status tokens (0x20xx) */ |
|---|
| 166 | #define MAXI_TOK_FAN(nr) (0x2000 + (nr)) |
|---|
| 167 | #define MAXI_TOK_FAN_CPU 0x2000 |
|---|
| 168 | #define MAXI_TOK_FAN_PCI 0x2001 |
|---|
| 169 | #define MAXI_TOK_FAN_HDD 0x2002 /* hard disk bay fan */ |
|---|
| 170 | #define MAXI_TOK_FAN_SINK 0x2003 /* heatsink */ |
|---|
| 171 | |
|---|
| 172 | /* Temperature status tokens (0x21xx) */ |
|---|
| 173 | #define MAXI_TOK_TEMP(nr) (0x2100 + (nr)) |
|---|
| 174 | #define MAXI_TOK_TEMP_CPU1 0x2100 |
|---|
| 175 | #define MAXI_TOK_TEMP_CPU2 0x2101 |
|---|
| 176 | #define MAXI_TOK_TEMP_PCI 0x2102 /* PCI/ambient temp */ |
|---|
| 177 | #define MAXI_TOK_TEMP_HDD 0x2103 /* hard disk bay temp */ |
|---|
| 178 | #define MAXI_TOK_TEMP_MEM 0x2104 /* mother board temp */ |
|---|
| 179 | #define MAXI_TOK_TEMP_CPU 0x2105 /* CPU reference temp */ |
|---|
| 180 | |
|---|
| 181 | /* Voltage status tokens (0x22xx) */ |
|---|
| 182 | #define MAXI_TOK_VID(nr) (0x2200 + (nr)) |
|---|
| 183 | #define MAXI_TOK_VID_12 0x2200 /* +12 volt */ |
|---|
| 184 | #define MAXI_TOK_VID_CPU1 0x2201 /* cpu 1 voltage */ |
|---|
| 185 | #define MAXI_TOK_VID_CPU2 0x2202 /* cpu 2 voltage */ |
|---|
| 186 | #define MAXI_TOK_VID_L2 0x2203 /* level 2 cache voltage */ |
|---|
| 187 | #define MAXI_TOK_VID_M12 0x2204 /* -12 volt */ |
|---|
| 188 | |
|---|
| 189 | /* Additive voltage status tokens (0x23xx) */ |
|---|
| 190 | #define MAXI_TOK_AVID(nr) (0x2300 + (nr)) |
|---|
| 191 | #define MAXI_TOK_AVID_15 0x2300 /* 1.5 volt */ |
|---|
| 192 | #define MAXI_TOK_AVID_18 0x2301 /* 1.8 volt */ |
|---|
| 193 | #define MAXI_TOK_AVID_25 0x2302 /* 2.5 volt */ |
|---|
| 194 | #define MAXI_TOK_AVID_33 0x2303 /* 3.3 volt */ |
|---|
| 195 | #define MAXI_TOK_AVID_5 0x2304 /* 5 volt */ |
|---|
| 196 | #define MAXI_TOK_AVID_M5 0x2305 /* -5 volt */ |
|---|
| 197 | #define MAXI_TOK_AVID_BAT 0x2306 /* battery voltage */ |
|---|
| 198 | |
|---|
| 199 | /* Threshold tokens (0x3xxx) */ |
|---|
| 200 | #define MAXI_TOK_MIN(token) ((token) + 0x1000) |
|---|
| 201 | #define MAXI_TOK_MAX(token) ((token) + 0x1800) |
|---|
| 202 | |
|---|
| 203 | /* LCD Panel (0x4xxx) */ |
|---|
| 204 | #define MAXI_TOK_LCD(nr) (0x4000 + (nr)) |
|---|
| 205 | #define MAXI_TOK_LCD_LINE1 0x4000 |
|---|
| 206 | #define MAXI_TOK_LCD_LINE2 0x4001 |
|---|
| 207 | #define MAXI_TOK_LCD_LINE3 0x4002 |
|---|
| 208 | #define MAXI_TOK_LCD_LINE4 0x4003 |
|---|
| 209 | |
|---|
| 210 | /* 0xfe: fan off, 0xff: stopped (alarm) */ |
|---|
| 211 | /* or not available */ |
|---|
| 212 | #define FAN99_FROM_REG(val) ((val)==0xfe ? 0 : (val)==0xff ? -1 : ((val)*39)) |
|---|
| 213 | |
|---|
| 214 | /* when no CPU2 temp is 127 (0x7f) */ |
|---|
| 215 | #define TEMP99_FROM_REG(val) ((val)==0x7f ? -1 : (val)==0xff ? -1 : (val)) |
|---|
| 216 | |
|---|
| 217 | #define VID99_FROM_REG(nr,val) ((val)==0xff ? 0 : \ |
|---|
| 218 | (nr)==1 ? ((val) * 608) : \ |
|---|
| 219 | (nr)==2 ? ((val) * 160) : \ |
|---|
| 220 | (nr)==3 ? ((val) * 160) : \ |
|---|
| 221 | (nr)==4 ? (val) /* no formula spcified */ : \ |
|---|
| 222 | (nr)==5 ? ((val) * 823 - 149140) : 0) |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | /* The following product codenames apply: |
|---|
| 226 | Cristal/Geronimo: HP KAYAK XU/XAs |
|---|
| 227 | (Dual Pentium II Slot 1, Deschutes/Klamath) |
|---|
| 228 | Cognac: HP KAYAK XU (Dual Xeon [Slot 2] 400/450 Mhz) |
|---|
| 229 | Ashaki: HP KAYAK XA (Pentium II Slot 1, monoprocessor) |
|---|
| 230 | NBA: New BIOS Architecture, Kayak XU800, XM600, ... */ |
|---|
| 231 | |
|---|
| 232 | enum maxi_type { cristal, cognac, ashaki, nba }; |
|---|
| 233 | enum sensor_type { fan, temp, vid, pll, lcd, alarm }; |
|---|
| 234 | |
|---|
| 235 | /* For each registered MaxiLife controller, we need to keep some data in |
|---|
| 236 | memory. That data is pointed to by maxi_list[NR]->data. The structure |
|---|
| 237 | itself is dynamically allocated, at the same time when a new MaxiLife |
|---|
| 238 | client is allocated. We assume MaxiLife will only be present on the |
|---|
| 239 | SMBus and not on the ISA bus. */ |
|---|
| 240 | struct maxi_data { |
|---|
| 241 | struct i2c_client client; |
|---|
| 242 | int sysctl_id; |
|---|
| 243 | enum maxi_type type; |
|---|
| 244 | |
|---|
| 245 | struct semaphore update_lock; |
|---|
| 246 | char valid; /* !=0 if following fields are valid */ |
|---|
| 247 | unsigned long last_updated; /* In jiffies */ |
|---|
| 248 | |
|---|
| 249 | u8 fan[4]; /* Register value */ |
|---|
| 250 | u8 fan_min[4]; /* Register value */ |
|---|
| 251 | u8 fan_speed[4]; /* Register value */ |
|---|
| 252 | u8 fan_div[4]; /* Static value */ |
|---|
| 253 | u8 temp[6]; /* Register value */ |
|---|
| 254 | u8 temp_max[6]; /* Static value */ |
|---|
| 255 | u8 temp_hyst[6]; /* Static value */ |
|---|
| 256 | u8 pll; /* Register value */ |
|---|
| 257 | u8 pll_min; /* Register value */ |
|---|
| 258 | u8 pll_max; /* register value */ |
|---|
| 259 | u8 vid[5]; /* Register value */ |
|---|
| 260 | u8 vid_min[5]; /* Register value */ |
|---|
| 261 | u8 vid_max[5]; /* Register value */ |
|---|
| 262 | u8 lcd[4][17]; /* Four LCD lines */ |
|---|
| 263 | u16 alarms; /* Register encoding, combined */ |
|---|
| 264 | }; |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | static int maxi_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 268 | static int maxi_detect(struct i2c_adapter *adapter, int address, |
|---|
| 269 | unsigned short flags, int kind); |
|---|
| 270 | static int maxi_detach_client(struct i2c_client *client); |
|---|
| 271 | |
|---|
| 272 | static int maxi_read_value(struct i2c_client *client, u8 register); |
|---|
| 273 | static int maxi_read_token(struct i2c_client *client, u16 token); |
|---|
| 274 | #ifndef NOWRITE |
|---|
| 275 | static int maxi_write_value(struct i2c_client *client, u8 register, |
|---|
| 276 | u8 value); |
|---|
| 277 | #endif |
|---|
| 278 | static int maxi_write_token_loop(struct i2c_client *client, u16 token, |
|---|
| 279 | u8 len, u8 * values); |
|---|
| 280 | |
|---|
| 281 | static void maxi_update_client(struct i2c_client *client); |
|---|
| 282 | static void maxi99_update_client(struct i2c_client *client, |
|---|
| 283 | enum sensor_type sensor, int which); |
|---|
| 284 | static void maxi_init_client(struct i2c_client *client); |
|---|
| 285 | |
|---|
| 286 | static void maxi_fan(struct i2c_client *client, int operation, |
|---|
| 287 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 288 | static void maxi99_fan(struct i2c_client *client, int operation, |
|---|
| 289 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 290 | static void maxi_temp(struct i2c_client *client, int operation, |
|---|
| 291 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 292 | static void maxi99_temp(struct i2c_client *client, int operation, |
|---|
| 293 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 294 | static void maxi_pll(struct i2c_client *client, int operation, |
|---|
| 295 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 296 | static void maxi_vid(struct i2c_client *client, int operation, |
|---|
| 297 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 298 | static void maxi99_vid(struct i2c_client *client, int operation, |
|---|
| 299 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 300 | static void maxi_lcd(struct i2c_client *client, int operation, |
|---|
| 301 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 302 | static void maxi_alarms(struct i2c_client *client, int operation, |
|---|
| 303 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 304 | |
|---|
| 305 | /* The driver. I choose to use type i2c_driver, as at is identical to |
|---|
| 306 | the smbus_driver. */ |
|---|
| 307 | static struct i2c_driver maxi_driver = { |
|---|
| 308 | .name = "HP MaxiLife driver", |
|---|
| 309 | .id = I2C_DRIVERID_MAXILIFE, |
|---|
| 310 | .flags = I2C_DF_NOTIFY, |
|---|
| 311 | .attach_adapter = maxi_attach_adapter, |
|---|
| 312 | .detach_client = maxi_detach_client, |
|---|
| 313 | }; |
|---|
| 314 | |
|---|
| 315 | /* Default firmware version. Use module option "maxi_version" |
|---|
| 316 | to set desired version. Auto detect is not yet working */ |
|---|
| 317 | static int maxi_version = cristal; |
|---|
| 318 | |
|---|
| 319 | /* The /proc/sys entries */ |
|---|
| 320 | |
|---|
| 321 | /* -- SENSORS SYSCTL START -- */ |
|---|
| 322 | #define MAXI_SYSCTL_FAN1 1101 /* Rotations/min */ |
|---|
| 323 | #define MAXI_SYSCTL_FAN2 1102 /* Rotations/min */ |
|---|
| 324 | #define MAXI_SYSCTL_FAN3 1103 /* Rotations/min */ |
|---|
| 325 | #define MAXI_SYSCTL_FAN4 1104 /* Rotations/min */ |
|---|
| 326 | #define MAXI_SYSCTL_TEMP1 1201 /* Degrees Celcius */ |
|---|
| 327 | #define MAXI_SYSCTL_TEMP2 1202 /* Degrees Celcius */ |
|---|
| 328 | #define MAXI_SYSCTL_TEMP3 1203 /* Degrees Celcius */ |
|---|
| 329 | #define MAXI_SYSCTL_TEMP4 1204 /* Degrees Celcius */ |
|---|
| 330 | #define MAXI_SYSCTL_TEMP5 1205 /* Degrees Celcius */ |
|---|
| 331 | #define MAXI_SYSCTL_TEMP6 1206 /* Degrees Celcius */ |
|---|
| 332 | #define MAXI_SYSCTL_PLL 1301 /* MHz */ |
|---|
| 333 | #define MAXI_SYSCTL_VID1 1401 /* Volts / 6.337, for nba just Volts */ |
|---|
| 334 | #define MAXI_SYSCTL_VID2 1402 /* Volts */ |
|---|
| 335 | #define MAXI_SYSCTL_VID3 1403 /* Volts */ |
|---|
| 336 | #define MAXI_SYSCTL_VID4 1404 /* Volts */ |
|---|
| 337 | #define MAXI_SYSCTL_VID5 1405 /* Volts */ |
|---|
| 338 | #define MAXI_SYSCTL_LCD1 1501 /* Line 1 of LCD */ |
|---|
| 339 | #define MAXI_SYSCTL_LCD2 1502 /* Line 2 of LCD */ |
|---|
| 340 | #define MAXI_SYSCTL_LCD3 1503 /* Line 3 of LCD */ |
|---|
| 341 | #define MAXI_SYSCTL_LCD4 1504 /* Line 4 of LCD */ |
|---|
| 342 | #define MAXI_SYSCTL_ALARMS 2001 /* Bitvector (see below) */ |
|---|
| 343 | |
|---|
| 344 | #define MAXI_ALARM_VID4 0x0001 |
|---|
| 345 | #define MAXI_ALARM_TEMP2 0x0002 |
|---|
| 346 | #define MAXI_ALARM_VID1 0x0004 |
|---|
| 347 | #define MAXI_ALARM_VID2 0x0008 |
|---|
| 348 | #define MAXI_ALARM_VID3 0x0010 |
|---|
| 349 | #define MAXI_ALARM_PLL 0x0080 |
|---|
| 350 | #define MAXI_ALARM_TEMP4 0x0100 |
|---|
| 351 | #define MAXI_ALARM_TEMP5 0x0200 |
|---|
| 352 | #define MAXI_ALARM_FAN1 0x1000 |
|---|
| 353 | #define MAXI_ALARM_FAN2 0x2000 |
|---|
| 354 | #define MAXI_ALARM_FAN3 0x4000 |
|---|
| 355 | |
|---|
| 356 | #define MAXI_ALARM_FAN 0x0100 /* To be used with MaxiLife'99 */ |
|---|
| 357 | #define MAXI_ALARM_VID 0x0200 /* The MSB specifies which sensor */ |
|---|
| 358 | #define MAXI_ALARM_TEMP 0x0400 /* in the alarm group failed, i.e.: */ |
|---|
| 359 | #define MAXI_ALARM_VADD 0x0800 /* 0x0402 = TEMP2 failed = CPU2 temp */ |
|---|
| 360 | |
|---|
| 361 | /* -- SENSORS SYSCTL END -- */ |
|---|
| 362 | |
|---|
| 363 | /* These files are created for each detected MaxiLife processor. |
|---|
| 364 | This is just a template; though at first sight, you might think we |
|---|
| 365 | could use a statically allocated list, we need some way to get back |
|---|
| 366 | to the parent - which is done through one of the 'extra' fields |
|---|
| 367 | which are initialized when a new copy is allocated. */ |
|---|
| 368 | static ctl_table maxi_dir_table_template[] = { |
|---|
| 369 | {MAXI_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 370 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 371 | {MAXI_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 372 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 373 | {MAXI_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 374 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 375 | {MAXI_SYSCTL_FAN4, "fan4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 376 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 377 | {MAXI_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 378 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 379 | {MAXI_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 380 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 381 | {MAXI_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 382 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 383 | {MAXI_SYSCTL_TEMP4, "temp4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 384 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 385 | {MAXI_SYSCTL_TEMP5, "temp5", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 386 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 387 | {MAXI_SYSCTL_TEMP6, "temp6", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 388 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 389 | {MAXI_SYSCTL_PLL, "pll", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 390 | &i2c_sysctl_real, NULL, &maxi_pll}, |
|---|
| 391 | {MAXI_SYSCTL_VID1, "vid1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 392 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 393 | {MAXI_SYSCTL_VID2, "vid2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 394 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 395 | {MAXI_SYSCTL_VID3, "vid3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 396 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 397 | {MAXI_SYSCTL_VID4, "vid4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 398 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 399 | {MAXI_SYSCTL_VID5, "vid5", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 400 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 401 | {MAXI_SYSCTL_LCD1, "lcd1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 402 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 403 | {MAXI_SYSCTL_LCD2, "lcd2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 404 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 405 | {MAXI_SYSCTL_LCD3, "lcd3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 406 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 407 | {MAXI_SYSCTL_LCD4, "lcd4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 408 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 409 | {MAXI_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 410 | &i2c_sysctl_real, NULL, &maxi_alarms}, |
|---|
| 411 | {0} |
|---|
| 412 | }; |
|---|
| 413 | |
|---|
| 414 | /* This function is called when: |
|---|
| 415 | - maxi_driver is inserted (when this module is loaded), for each |
|---|
| 416 | available adapter |
|---|
| 417 | - when a new adapter is inserted (and maxi_driver is still present) */ |
|---|
| 418 | static int maxi_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 419 | { |
|---|
| 420 | return i2c_detect(adapter, &addr_data, maxi_detect); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | /* This function is called by i2c_detect */ |
|---|
| 424 | int maxi_detect(struct i2c_adapter *adapter, int address, |
|---|
| 425 | unsigned short flags, int kind) |
|---|
| 426 | { |
|---|
| 427 | struct i2c_client *new_client; |
|---|
| 428 | struct maxi_data *data; |
|---|
| 429 | enum maxi_type type = 0; |
|---|
| 430 | int i, j, err = 0; |
|---|
| 431 | const char *type_name = NULL, *client_name = NULL; |
|---|
| 432 | |
|---|
| 433 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
|---|
| 434 | goto ERROR0; |
|---|
| 435 | |
|---|
| 436 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 437 | client structure, even though we cannot fill it completely yet. |
|---|
| 438 | But it allows us to access maxi_{read,write}_value. */ |
|---|
| 439 | if (!(data = kmalloc(sizeof(struct maxi_data), GFP_KERNEL))) { |
|---|
| 440 | err = -ENOMEM; |
|---|
| 441 | goto ERROR0; |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | /* Fill the new client structure with data */ |
|---|
| 445 | new_client = &data->client; |
|---|
| 446 | new_client->addr = address; |
|---|
| 447 | new_client->data = data; |
|---|
| 448 | new_client->adapter = adapter; |
|---|
| 449 | new_client->driver = &maxi_driver; |
|---|
| 450 | new_client->flags = 0; |
|---|
| 451 | |
|---|
| 452 | /* Now we do the remaining detection. */ |
|---|
| 453 | if (kind < 0) { |
|---|
| 454 | if (i2c_smbus_read_byte_data |
|---|
| 455 | (new_client, MAXI_REG_MBX_STATUS) < 0) |
|---|
| 456 | goto ERROR2; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | /* Determine the chip type - only one kind supported */ |
|---|
| 460 | if (kind <= 0) |
|---|
| 461 | kind = maxilife; |
|---|
| 462 | |
|---|
| 463 | if (kind == maxilife) { |
|---|
| 464 | /* Detect if the machine has a MaxiLife NBA controller. |
|---|
| 465 | The right way to perform this check is to do a read/modify/write |
|---|
| 466 | on register MbxStatus (5A): |
|---|
| 467 | - Read 5A (value 0 for non-NBA firmware, FF (MbxIdle on NBA-firmware) |
|---|
| 468 | - Write 55 on 5A, then read back 5A |
|---|
| 469 | Non-NBA firmware: value is 55 (reg 5A is a standard writable reg) |
|---|
| 470 | NBA firmaware: value is FF (write-protect on MbxStatus active) */ |
|---|
| 471 | int stat; |
|---|
| 472 | i2c_smbus_write_byte_data(new_client, MAXI_REG_MBX_STATUS, |
|---|
| 473 | 0x55); |
|---|
| 474 | stat = |
|---|
| 475 | i2c_smbus_read_byte_data(new_client, |
|---|
| 476 | MAXI_REG_MBX_STATUS); |
|---|
| 477 | |
|---|
| 478 | /*if (stat == MAXI_STAT_IDLE || stat == MAXI_STAT_OK) */ |
|---|
| 479 | if (stat != 0x55) |
|---|
| 480 | maxi_version = nba; |
|---|
| 481 | #ifdef AUTODETECT |
|---|
| 482 | else { |
|---|
| 483 | /* The right way to get the platform info is to read the firmware |
|---|
| 484 | revision from serial EEPROM (addr=0x54), at offset 0x0045. |
|---|
| 485 | This is a string as: |
|---|
| 486 | "CG 00.04" -> Cristal [XU] / Geronimo [XAs] |
|---|
| 487 | "CO 00.03" -> Cognac [XU] |
|---|
| 488 | "AS 00.01" -> Ashaki [XA] */ |
|---|
| 489 | #if 0 |
|---|
| 490 | int biosctl; |
|---|
| 491 | biosctl = |
|---|
| 492 | i2c_smbus_read_byte_data(new_client, |
|---|
| 493 | MAXI_REG_BIOS_CTRL); |
|---|
| 494 | i2c_smbus_write_byte_data(new_client, |
|---|
| 495 | MAXI_REG_BIOS_CTRL, |
|---|
| 496 | biosctl | 4); |
|---|
| 497 | err = eeprom_read_byte_data(adapter, 0x54, 0x45); |
|---|
| 498 | i2c_smbus_write_byte_data(new_client, |
|---|
| 499 | MAXI_REG_BIOS_CTRL, |
|---|
| 500 | biosctl); |
|---|
| 501 | #endif |
|---|
| 502 | int i; |
|---|
| 503 | char *biosmem, *bm; |
|---|
| 504 | bm = biosmem = ioremap(0xe0000, 0x20000); |
|---|
| 505 | if (biosmem) { |
|---|
| 506 | printk("begin of bios search\n"); |
|---|
| 507 | for (i = 0; i < 0x20000; i++) { |
|---|
| 508 | if (*bm == 'C') { |
|---|
| 509 | char *s = bm; |
|---|
| 510 | while (s && isprint(*s)) { |
|---|
| 511 | printk("%c", *s); |
|---|
| 512 | s++; |
|---|
| 513 | } |
|---|
| 514 | printk("\n"); |
|---|
| 515 | if (!strncmp |
|---|
| 516 | (bm, "CG 00.04", 8)) { |
|---|
| 517 | maxi_version = |
|---|
| 518 | cristal; |
|---|
| 519 | printk |
|---|
| 520 | ("maxilife: found MaxiLife Rev CG 00.04\n"); |
|---|
| 521 | break; |
|---|
| 522 | } |
|---|
| 523 | if (!strncmp |
|---|
| 524 | (bm, "CO 00.03", 8)) { |
|---|
| 525 | maxi_version = |
|---|
| 526 | cognac; |
|---|
| 527 | printk |
|---|
| 528 | ("maxilife: found MaxiLife Rev CO 00.03\n"); |
|---|
| 529 | break; |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | if (*bm == 'A' && *(bm + 1) == 'S') { |
|---|
| 533 | char *s = bm; |
|---|
| 534 | while (s && isprint(*s)) { |
|---|
| 535 | printk("%c", *s); |
|---|
| 536 | s++; |
|---|
| 537 | } |
|---|
| 538 | printk("\n"); |
|---|
| 539 | if (!strncmp |
|---|
| 540 | (bm, "AS 00.01", 8)) { |
|---|
| 541 | maxi_version = |
|---|
| 542 | ashaki; |
|---|
| 543 | printk |
|---|
| 544 | ("maxilife: found MaxiLife Rev AS 00.01\n"); |
|---|
| 545 | break; |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | bm++; |
|---|
| 549 | } |
|---|
| 550 | printk("end of bios search\n"); |
|---|
| 551 | } else |
|---|
| 552 | printk("could not map bios memory\n"); |
|---|
| 553 | } |
|---|
| 554 | #endif |
|---|
| 555 | |
|---|
| 556 | if (maxi_version == cristal) { |
|---|
| 557 | type = cristal; |
|---|
| 558 | type_name = "maxilife-cg"; |
|---|
| 559 | client_name = "HP MaxiLife Rev CG 00.04"; |
|---|
| 560 | printk |
|---|
| 561 | ("maxilife: HP KAYAK XU/XAs (Dual Pentium II Slot 1)\n"); |
|---|
| 562 | } else if (maxi_version == cognac) { |
|---|
| 563 | type = cognac; |
|---|
| 564 | type_name = "maxilife-co"; |
|---|
| 565 | client_name = "HP MaxiLife Rev CO 00.03"; |
|---|
| 566 | printk |
|---|
| 567 | ("maxilife: HP KAYAK XU (Dual Xeon Slot 2 400/450 Mhz)\n"); |
|---|
| 568 | } else if (maxi_version == ashaki) { |
|---|
| 569 | type = ashaki; |
|---|
| 570 | type_name = "maxilife-as"; |
|---|
| 571 | client_name = "HP MaxiLife Rev AS 00.01"; |
|---|
| 572 | printk |
|---|
| 573 | ("maxilife: HP KAYAK XA (Pentium II Slot 1, monoprocessor)\n"); |
|---|
| 574 | } else if (maxi_version == nba) { |
|---|
| 575 | type = nba; |
|---|
| 576 | type_name = "maxilife-nba"; |
|---|
| 577 | client_name = "HP MaxiLife NBA"; |
|---|
| 578 | printk("maxilife: HP KAYAK XU800/XM600\n"); |
|---|
| 579 | } else { |
|---|
| 580 | #ifdef AUTODETECT |
|---|
| 581 | printk |
|---|
| 582 | ("maxilife: Warning: probed non-maxilife chip?!? (%x)\n", |
|---|
| 583 | err); |
|---|
| 584 | #else |
|---|
| 585 | printk |
|---|
| 586 | ("maxilife: Error: specified wrong maxi_version (%d)\n", |
|---|
| 587 | maxi_version); |
|---|
| 588 | #endif |
|---|
| 589 | goto ERROR2; |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | /* Fill in the remaining client fields and put it into the global list */ |
|---|
| 594 | strcpy(new_client->name, client_name); |
|---|
| 595 | ((struct maxi_data *) (new_client->data))->type = type; |
|---|
| 596 | |
|---|
| 597 | for (i = 0; i < 4; i++) |
|---|
| 598 | for (j = 0; j < 17; j++) |
|---|
| 599 | ((struct maxi_data *) (new_client->data))-> |
|---|
| 600 | lcd[i][j] = (u8) 0; |
|---|
| 601 | |
|---|
| 602 | data->valid = 0; |
|---|
| 603 | init_MUTEX(&data->update_lock); |
|---|
| 604 | |
|---|
| 605 | /* Tell i2c-core that a new client has arrived */ |
|---|
| 606 | if ((err = i2c_attach_client(new_client))) |
|---|
| 607 | goto ERROR2; |
|---|
| 608 | |
|---|
| 609 | /* Register a new directory entry with module sensors */ |
|---|
| 610 | if ((err = i2c_register_entry(new_client, type_name, |
|---|
| 611 | maxi_dir_table_template, |
|---|
| 612 | THIS_MODULE)) < 0) |
|---|
| 613 | goto ERROR4; |
|---|
| 614 | data->sysctl_id = err; |
|---|
| 615 | |
|---|
| 616 | /* Initialize the MaxiLife chip */ |
|---|
| 617 | maxi_init_client(new_client); |
|---|
| 618 | return 0; |
|---|
| 619 | |
|---|
| 620 | /* OK, this is not exactly good programming practice, usually. |
|---|
| 621 | But it is very code-efficient in this case. */ |
|---|
| 622 | ERROR4: |
|---|
| 623 | i2c_detach_client(new_client); |
|---|
| 624 | ERROR2: |
|---|
| 625 | kfree(data); |
|---|
| 626 | ERROR0: |
|---|
| 627 | return err; |
|---|
| 628 | } |
|---|
| 629 | |
|---|
| 630 | /* This function is called whenever a client should be removed: |
|---|
| 631 | - maxi_driver is removed (when this module is unloaded) |
|---|
| 632 | - when an adapter is removed which has a maxi client (and maxi_driver |
|---|
| 633 | is still present). */ |
|---|
| 634 | static int maxi_detach_client(struct i2c_client *client) |
|---|
| 635 | { |
|---|
| 636 | int err; |
|---|
| 637 | |
|---|
| 638 | i2c_deregister_entry(((struct maxi_data *) (client->data))-> |
|---|
| 639 | sysctl_id); |
|---|
| 640 | |
|---|
| 641 | if ((err = i2c_detach_client(client))) { |
|---|
| 642 | printk |
|---|
| 643 | ("maxilife: Client deregistration failed, client not detached.\n"); |
|---|
| 644 | return err; |
|---|
| 645 | } |
|---|
| 646 | kfree(client->data); |
|---|
| 647 | return 0; |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | /* Read byte from specified register (-1 in case of error, value otherwise). */ |
|---|
| 651 | static int maxi_read_value(struct i2c_client *client, u8 reg) |
|---|
| 652 | { |
|---|
| 653 | return i2c_smbus_read_byte_data(client, reg); |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | /* Read the byte value for a MaxiLife token (-1 in case of error, value otherwise */ |
|---|
| 657 | static int maxi_read_token(struct i2c_client *client, u16 token) |
|---|
| 658 | { |
|---|
| 659 | u8 lowToken, highToken; |
|---|
| 660 | int error, value; |
|---|
| 661 | |
|---|
| 662 | lowToken = LOW(token); |
|---|
| 663 | highToken = HIGH(token); |
|---|
| 664 | |
|---|
| 665 | /* Set mailbox status register to idle state. */ |
|---|
| 666 | error = |
|---|
| 667 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 668 | MAXI_STAT_IDLE); |
|---|
| 669 | if (error < 0) |
|---|
| 670 | return error; |
|---|
| 671 | |
|---|
| 672 | /* Check for mailbox idle state. */ |
|---|
| 673 | error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 674 | if (error != MAXI_STAT_IDLE) |
|---|
| 675 | return -1; |
|---|
| 676 | |
|---|
| 677 | /* Write the most significant byte of the token we want to read. */ |
|---|
| 678 | error = |
|---|
| 679 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H, |
|---|
| 680 | highToken); |
|---|
| 681 | if (error < 0) |
|---|
| 682 | return error; |
|---|
| 683 | |
|---|
| 684 | /* Write the least significant byte of the token we want to read. */ |
|---|
| 685 | error = |
|---|
| 686 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L, |
|---|
| 687 | lowToken); |
|---|
| 688 | if (error < 0) |
|---|
| 689 | return error; |
|---|
| 690 | |
|---|
| 691 | /* Write the read token opcode to the mailbox. */ |
|---|
| 692 | error = |
|---|
| 693 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD, |
|---|
| 694 | MAXI_CMD_READ); |
|---|
| 695 | if (error < 0) |
|---|
| 696 | return error; |
|---|
| 697 | |
|---|
| 698 | /* Check for transaction completion */ |
|---|
| 699 | do { |
|---|
| 700 | error = |
|---|
| 701 | i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 702 | } while (error == MAXI_STAT_BUSY); |
|---|
| 703 | if (error != MAXI_STAT_OK) |
|---|
| 704 | return -1; |
|---|
| 705 | |
|---|
| 706 | /* Read the value of the token. */ |
|---|
| 707 | value = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_DATA); |
|---|
| 708 | if (value == -1) |
|---|
| 709 | return -1; |
|---|
| 710 | |
|---|
| 711 | /* set mailbox status to idle to complete transaction. */ |
|---|
| 712 | error = |
|---|
| 713 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 714 | MAXI_STAT_IDLE); |
|---|
| 715 | if (error < 0) |
|---|
| 716 | return error; |
|---|
| 717 | |
|---|
| 718 | return value; |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | #ifndef NOWRITE |
|---|
| 722 | /* Write byte to specified register (-1 in case of error, 0 otherwise). */ |
|---|
| 723 | static int maxi_write_value(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 724 | { |
|---|
| 725 | return i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 726 | } |
|---|
| 727 | #endif |
|---|
| 728 | |
|---|
| 729 | /* Write a set of len byte values to MaxiLife token (-1 in case of error, 0 otherwise). */ |
|---|
| 730 | int maxi_write_token_loop(struct i2c_client *client, u16 token, u8 len, |
|---|
| 731 | u8 * values) |
|---|
| 732 | { |
|---|
| 733 | u8 lowToken, highToken, bCounter; |
|---|
| 734 | int error; |
|---|
| 735 | |
|---|
| 736 | lowToken = LOW(token); |
|---|
| 737 | highToken = HIGH(token); |
|---|
| 738 | |
|---|
| 739 | /* Set mailbox status register to idle state. */ |
|---|
| 740 | error = |
|---|
| 741 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 742 | MAXI_STAT_IDLE); |
|---|
| 743 | if (error < 0) |
|---|
| 744 | return error; |
|---|
| 745 | |
|---|
| 746 | /* Check for mailbox idle state. */ |
|---|
| 747 | error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 748 | if (error != MAXI_STAT_IDLE) |
|---|
| 749 | return -1; |
|---|
| 750 | |
|---|
| 751 | for (bCounter = 0; (bCounter < len && bCounter < 32); bCounter++) { |
|---|
| 752 | error = |
|---|
| 753 | i2c_smbus_write_byte_data(client, |
|---|
| 754 | (u8) (MAXI_REG_MBX_DATA + |
|---|
| 755 | bCounter), |
|---|
| 756 | values[bCounter]); |
|---|
| 757 | if (error < 0) |
|---|
| 758 | return error; |
|---|
| 759 | } |
|---|
| 760 | |
|---|
| 761 | /* Write the most significant byte of the token we want to read. */ |
|---|
| 762 | error = |
|---|
| 763 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H, |
|---|
| 764 | highToken); |
|---|
| 765 | if (error < 0) |
|---|
| 766 | return error; |
|---|
| 767 | |
|---|
| 768 | /* Write the least significant byte of the token we want to read. */ |
|---|
| 769 | error = |
|---|
| 770 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L, |
|---|
| 771 | lowToken); |
|---|
| 772 | if (error < 0) |
|---|
| 773 | return error; |
|---|
| 774 | |
|---|
| 775 | /* Write the write token opcode to the mailbox. */ |
|---|
| 776 | error = |
|---|
| 777 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD, |
|---|
| 778 | MAXI_CMD_WRITE); |
|---|
| 779 | if (error < 0) |
|---|
| 780 | return error; |
|---|
| 781 | |
|---|
| 782 | /* Check for transaction completion */ |
|---|
| 783 | do { |
|---|
| 784 | error = |
|---|
| 785 | i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 786 | } while (error == MAXI_STAT_BUSY); |
|---|
| 787 | if (error != MAXI_STAT_OK) |
|---|
| 788 | return -1; |
|---|
| 789 | |
|---|
| 790 | /* set mailbox status to idle to complete transaction. */ |
|---|
| 791 | return i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 792 | MAXI_STAT_IDLE); |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | /* Called when we have found a new MaxiLife. It should set limits, etc. */ |
|---|
| 796 | static void maxi_init_client(struct i2c_client *client) |
|---|
| 797 | { |
|---|
| 798 | struct maxi_data *data = client->data; |
|---|
| 799 | |
|---|
| 800 | if (data->type == nba) { |
|---|
| 801 | strcpy(data->lcd[2], " Linux MaxiLife"); |
|---|
| 802 | maxi_write_token_loop(client, MAXI_TOK_LCD(2), |
|---|
| 803 | strlen(data->lcd[2]) + 1, |
|---|
| 804 | data->lcd[2]); |
|---|
| 805 | } |
|---|
| 806 | } |
|---|
| 807 | |
|---|
| 808 | static void maxi_update_client(struct i2c_client *client) |
|---|
| 809 | { |
|---|
| 810 | struct maxi_data *data = client->data; |
|---|
| 811 | int i; |
|---|
| 812 | |
|---|
| 813 | if (data->type == nba) { |
|---|
| 814 | printk |
|---|
| 815 | ("maxi_update_client should never be called by nba\n"); |
|---|
| 816 | return; |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | down(&data->update_lock); |
|---|
| 820 | |
|---|
| 821 | if ((jiffies - data->last_updated > HZ + HZ / 2) || |
|---|
| 822 | (jiffies < data->last_updated) || !data->valid) { |
|---|
| 823 | |
|---|
| 824 | #ifdef DEBUG |
|---|
| 825 | printk("maxilife: Starting MaxiLife update\n"); |
|---|
| 826 | #endif |
|---|
| 827 | for (i = 0; i < 5; i++) |
|---|
| 828 | data->temp[i] = |
|---|
| 829 | maxi_read_value(client, MAXI_REG_TEMP(i)); |
|---|
| 830 | switch (data->type) { |
|---|
| 831 | case cristal: |
|---|
| 832 | data->temp[0] = 0; /* not valid */ |
|---|
| 833 | data->temp_max[0] = 0; |
|---|
| 834 | data->temp_hyst[0] = 0; |
|---|
| 835 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 836 | data->temp_hyst[1] = 100; |
|---|
| 837 | data->temp_max[2] = 120; /* max BX chipset temp */ |
|---|
| 838 | data->temp_hyst[2] = 110; |
|---|
| 839 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 840 | data->temp_hyst[3] = 90; |
|---|
| 841 | data->temp_max[4] = 120; /* max CPU temp */ |
|---|
| 842 | data->temp_hyst[4] = 110; |
|---|
| 843 | break; |
|---|
| 844 | |
|---|
| 845 | case cognac: |
|---|
| 846 | data->temp_max[0] = 120; /* max CPU1 temp */ |
|---|
| 847 | data->temp_hyst[0] = 110; |
|---|
| 848 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 849 | data->temp_hyst[1] = 100; |
|---|
| 850 | data->temp_max[2] = 120; /* max CPU2 temp */ |
|---|
| 851 | data->temp_hyst[2] = 110; |
|---|
| 852 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 853 | data->temp_hyst[3] = 90; |
|---|
| 854 | data->temp_max[4] = 120; /* max reference CPU temp */ |
|---|
| 855 | data->temp_hyst[4] = 110; |
|---|
| 856 | break; |
|---|
| 857 | |
|---|
| 858 | case ashaki: |
|---|
| 859 | data->temp[0] = 0; /* not valid */ |
|---|
| 860 | data->temp_max[0] = 0; |
|---|
| 861 | data->temp_hyst[0] = 0; |
|---|
| 862 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 863 | data->temp_hyst[1] = 100; |
|---|
| 864 | data->temp[2] = 0; /* not valid */ |
|---|
| 865 | data->temp_max[2] = 0; |
|---|
| 866 | data->temp_hyst[2] = 0; |
|---|
| 867 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 868 | data->temp_hyst[3] = 90; |
|---|
| 869 | data->temp_max[4] = 120; /* max CPU temp */ |
|---|
| 870 | data->temp_hyst[4] = 110; |
|---|
| 871 | break; |
|---|
| 872 | |
|---|
| 873 | default: |
|---|
| 874 | printk("maxilife: Unknown MaxiLife chip\n"); |
|---|
| 875 | } |
|---|
| 876 | data->temp[5] = 0; /* only used by MaxiLife'99 */ |
|---|
| 877 | data->temp_max[5] = 0; |
|---|
| 878 | data->temp_hyst[5] = 0; |
|---|
| 879 | |
|---|
| 880 | for (i = 0; i < 3; i++) { |
|---|
| 881 | data->fan[i] = |
|---|
| 882 | maxi_read_value(client, MAXI_REG_FAN(i)); |
|---|
| 883 | data->fan_speed[i] = |
|---|
| 884 | maxi_read_value(client, MAXI_REG_FAN_SPEED(i)); |
|---|
| 885 | data->fan_div[i] = 4; |
|---|
| 886 | if (data->type == ashaki) |
|---|
| 887 | data->fan_min[i] = |
|---|
| 888 | maxi_read_value(client, |
|---|
| 889 | MAXI_REG_FAN_MINAS(i)); |
|---|
| 890 | else |
|---|
| 891 | data->fan_min[i] = |
|---|
| 892 | maxi_read_value(client, |
|---|
| 893 | MAXI_REG_FAN_MIN(i)); |
|---|
| 894 | } |
|---|
| 895 | data->fan[3] = 0xff; /* only used by MaxiLife'99 */ |
|---|
| 896 | data->fan_speed[3] = 0; |
|---|
| 897 | data->fan_div[3] = 4; /* avoid possible /0 */ |
|---|
| 898 | data->fan_min[3] = 0; |
|---|
| 899 | |
|---|
| 900 | data->pll = maxi_read_value(client, MAXI_REG_PLL); |
|---|
| 901 | data->pll_min = maxi_read_value(client, MAXI_REG_PLL_MIN); |
|---|
| 902 | data->pll_max = maxi_read_value(client, MAXI_REG_PLL_MAX); |
|---|
| 903 | |
|---|
| 904 | for (i = 0; i < 4; i++) { |
|---|
| 905 | data->vid[i] = |
|---|
| 906 | maxi_read_value(client, MAXI_REG_VID(i)); |
|---|
| 907 | data->vid_min[i] = |
|---|
| 908 | maxi_read_value(client, MAXI_REG_VID_MIN(i)); |
|---|
| 909 | data->vid_max[i] = |
|---|
| 910 | maxi_read_value(client, MAXI_REG_VID_MAX(i)); |
|---|
| 911 | } |
|---|
| 912 | switch (data->type) { |
|---|
| 913 | case cristal: |
|---|
| 914 | data->vid[3] = 0; /* no voltage cache L2 */ |
|---|
| 915 | data->vid_min[3] = 0; |
|---|
| 916 | data->vid_max[3] = 0; |
|---|
| 917 | break; |
|---|
| 918 | |
|---|
| 919 | case cognac: |
|---|
| 920 | break; |
|---|
| 921 | |
|---|
| 922 | case ashaki: |
|---|
| 923 | data->vid[1] = 0; /* no voltage CPU 2 */ |
|---|
| 924 | data->vid_min[1] = 0; |
|---|
| 925 | data->vid_max[1] = 0; |
|---|
| 926 | data->vid[3] = 0; /* no voltage cache L2 */ |
|---|
| 927 | data->vid_min[3] = 0; |
|---|
| 928 | data->vid_max[3] = 0; |
|---|
| 929 | break; |
|---|
| 930 | |
|---|
| 931 | default: |
|---|
| 932 | printk("maxilife: Unknown MaxiLife chip\n"); |
|---|
| 933 | } |
|---|
| 934 | data->vid[4] = 0; /* only used by MaxliLife'99 */ |
|---|
| 935 | data->vid_min[4] = 0; |
|---|
| 936 | data->vid_max[4] = 0; |
|---|
| 937 | |
|---|
| 938 | data->alarms = maxi_read_value(client, MAXI_REG_DIAG_RT1) + |
|---|
| 939 | (maxi_read_value(client, MAXI_REG_DIAG_RT2) << 8); |
|---|
| 940 | |
|---|
| 941 | data->last_updated = jiffies; |
|---|
| 942 | data->valid = 1; |
|---|
| 943 | } |
|---|
| 944 | |
|---|
| 945 | up(&data->update_lock); |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | void maxi99_update_client(struct i2c_client *client, |
|---|
| 949 | enum sensor_type sensor, int which) |
|---|
| 950 | { |
|---|
| 951 | static unsigned long last_updated[6][6]; /* sensor, which */ |
|---|
| 952 | struct maxi_data *data = client->data; |
|---|
| 953 | |
|---|
| 954 | down(&data->update_lock); |
|---|
| 955 | |
|---|
| 956 | /*maxi_write_token_loop(client, MAXI_TOK_LCD_LINE3, 13, "Linux 2.2.13"); */ |
|---|
| 957 | |
|---|
| 958 | if ((jiffies - last_updated[sensor][which] > 2 * HZ) || |
|---|
| 959 | (jiffies < last_updated[sensor][which] |
|---|
| 960 | || !last_updated[sensor][which])) { |
|---|
| 961 | |
|---|
| 962 | int tmp, i; |
|---|
| 963 | |
|---|
| 964 | switch (sensor) { |
|---|
| 965 | case fan: |
|---|
| 966 | for (i = 0; i < 4; i++) { |
|---|
| 967 | if (i == which) { |
|---|
| 968 | tmp = |
|---|
| 969 | maxi_read_token(client, |
|---|
| 970 | MAXI_TOK_FAN |
|---|
| 971 | (i)); |
|---|
| 972 | data->fan[i] = |
|---|
| 973 | maxi_read_token(client, |
|---|
| 974 | MAXI_TOK_FAN |
|---|
| 975 | (i)); |
|---|
| 976 | data->fan_speed[i] = |
|---|
| 977 | maxi_read_token(client, |
|---|
| 978 | MAXI_TOK_MAX |
|---|
| 979 | (MAXI_TOK_FAN |
|---|
| 980 | (i))); |
|---|
| 981 | data->fan_div[i] = 1; |
|---|
| 982 | data->fan_min[i] = 0; |
|---|
| 983 | } |
|---|
| 984 | } |
|---|
| 985 | break; |
|---|
| 986 | |
|---|
| 987 | case temp: |
|---|
| 988 | for (i = 0; i < 6; i++) { |
|---|
| 989 | if (i == which) { |
|---|
| 990 | data->temp[i] = |
|---|
| 991 | maxi_read_token(client, |
|---|
| 992 | MAXI_TOK_TEMP |
|---|
| 993 | (i)); |
|---|
| 994 | data->temp_max[i] = |
|---|
| 995 | maxi_read_token(client, |
|---|
| 996 | MAXI_TOK_MAX |
|---|
| 997 | (MAXI_TOK_TEMP |
|---|
| 998 | (i))); |
|---|
| 999 | data->temp_hyst[i] = |
|---|
| 1000 | data->temp_max[i] - 5; |
|---|
| 1001 | } |
|---|
| 1002 | } |
|---|
| 1003 | break; |
|---|
| 1004 | |
|---|
| 1005 | case vid: |
|---|
| 1006 | for (i = 0; i < 5; i++) { |
|---|
| 1007 | if (i == which) { |
|---|
| 1008 | data->vid[i] = |
|---|
| 1009 | maxi_read_token(client, |
|---|
| 1010 | MAXI_TOK_VID |
|---|
| 1011 | (i)); |
|---|
| 1012 | data->vid_min[i] = |
|---|
| 1013 | maxi_read_token(client, |
|---|
| 1014 | MAXI_TOK_MIN |
|---|
| 1015 | (MAXI_TOK_VID |
|---|
| 1016 | (i))); |
|---|
| 1017 | data->vid_max[i] = |
|---|
| 1018 | maxi_read_token(client, |
|---|
| 1019 | MAXI_TOK_MAX |
|---|
| 1020 | (MAXI_TOK_VID |
|---|
| 1021 | (i))); |
|---|
| 1022 | } |
|---|
| 1023 | } |
|---|
| 1024 | break; |
|---|
| 1025 | |
|---|
| 1026 | case pll: |
|---|
| 1027 | data->pll = 0; |
|---|
| 1028 | data->pll_min = 0; |
|---|
| 1029 | data->pll_max = 0; |
|---|
| 1030 | break; |
|---|
| 1031 | |
|---|
| 1032 | case alarm: |
|---|
| 1033 | data->alarms = |
|---|
| 1034 | (maxi_read_token(client, MAXI_TOK_ALARM_EVENT) |
|---|
| 1035 | << 8); |
|---|
| 1036 | if (data->alarms) |
|---|
| 1037 | data->alarms += |
|---|
| 1038 | data->alarms == |
|---|
| 1039 | (1 << 8) ? maxi_read_token(client, |
|---|
| 1040 | MAXI_TOK_ALARM_FAN) |
|---|
| 1041 | : data->alarms == |
|---|
| 1042 | (2 << 8) ? maxi_read_token(client, |
|---|
| 1043 | MAXI_TOK_ALARM_VID) |
|---|
| 1044 | : data->alarms == |
|---|
| 1045 | (4 << 8) ? maxi_read_token(client, |
|---|
| 1046 | MAXI_TOK_ALARM_TEMP) |
|---|
| 1047 | : data->alarms == |
|---|
| 1048 | (8 << 8) ? maxi_read_token(client, |
|---|
| 1049 | MAXI_TOK_ALARM_FAN) |
|---|
| 1050 | : 0; |
|---|
| 1051 | break; |
|---|
| 1052 | |
|---|
| 1053 | default: |
|---|
| 1054 | printk("maxilife: Unknown sensor type\n"); |
|---|
| 1055 | } |
|---|
| 1056 | |
|---|
| 1057 | last_updated[sensor][which] = jiffies; |
|---|
| 1058 | data->valid = 1; |
|---|
| 1059 | } |
|---|
| 1060 | |
|---|
| 1061 | up(&data->update_lock); |
|---|
| 1062 | } |
|---|
| 1063 | |
|---|
| 1064 | /* The next few functions are the call-back functions of the /proc/sys and |
|---|
| 1065 | sysctl files. Which function is used is defined in the ctl_table in |
|---|
| 1066 | the extra1 field. |
|---|
| 1067 | Each function must return the magnitude (power of 10 to divide the data |
|---|
| 1068 | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
|---|
| 1069 | put a maximum of *nrels elements in results reflecting the data of this |
|---|
| 1070 | file, and set *nrels to the number it actually put in it, if operation== |
|---|
| 1071 | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
|---|
| 1072 | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
|---|
| 1073 | Note that on SENSORS_PROC_REAL_READ, I do not check whether results is |
|---|
| 1074 | large enough (by checking the incoming value of *nrels). This is not very |
|---|
| 1075 | good practice, but as long as you put less than about 5 values in results, |
|---|
| 1076 | you can assume it is large enough. */ |
|---|
| 1077 | void maxi_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1078 | int *nrels_mag, long *results) |
|---|
| 1079 | { |
|---|
| 1080 | struct maxi_data *data = client->data; |
|---|
| 1081 | int nr; |
|---|
| 1082 | |
|---|
| 1083 | if (data->type == nba) { |
|---|
| 1084 | maxi99_fan(client, operation, ctl_name, nrels_mag, |
|---|
| 1085 | results); |
|---|
| 1086 | return; |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; |
|---|
| 1090 | |
|---|
| 1091 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1092 | *nrels_mag = 0; |
|---|
| 1093 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1094 | maxi_update_client(client); |
|---|
| 1095 | results[0] = FAN_FROM_REG(data->fan_min[nr - 1]); |
|---|
| 1096 | results[1] = data->fan_div[nr - 1]; |
|---|
| 1097 | results[2] = FAN_FROM_REG(data->fan[nr - 1]); |
|---|
| 1098 | *nrels_mag = 3; |
|---|
| 1099 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1100 | #ifndef NOWRITE |
|---|
| 1101 | if (*nrels_mag >= 1) { |
|---|
| 1102 | data->fan_min[nr - 1] = FAN_TO_REG(results[0]); |
|---|
| 1103 | maxi_write_value(client, MAXI_REG_FAN_MIN(nr), |
|---|
| 1104 | data->fan_min[nr - 1]); |
|---|
| 1105 | } |
|---|
| 1106 | #endif |
|---|
| 1107 | } |
|---|
| 1108 | } |
|---|
| 1109 | |
|---|
| 1110 | void maxi99_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1111 | int *nrels_mag, long *results) |
|---|
| 1112 | { |
|---|
| 1113 | struct maxi_data *data = client->data; |
|---|
| 1114 | int nr; |
|---|
| 1115 | |
|---|
| 1116 | nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; |
|---|
| 1117 | |
|---|
| 1118 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1119 | *nrels_mag = 0; |
|---|
| 1120 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1121 | maxi99_update_client(client, fan, nr - 1); |
|---|
| 1122 | results[0] = FAN99_FROM_REG(data->fan_min[nr - 1]); /* min rpm */ |
|---|
| 1123 | results[1] = data->fan_div[nr - 1]; /* divisor */ |
|---|
| 1124 | results[2] = FAN99_FROM_REG(data->fan[nr - 1]); /* rpm */ |
|---|
| 1125 | *nrels_mag = 3; |
|---|
| 1126 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1127 | #ifndef NOWRITE |
|---|
| 1128 | /* still to do */ |
|---|
| 1129 | if (*nrels_mag >= 1) { |
|---|
| 1130 | data->fan_min[nr - 1] = FAN_TO_REG(results[0]); |
|---|
| 1131 | maxi_write_value(client, MAXI_REG_FAN_MIN(nr), |
|---|
| 1132 | data->fan_min[nr - 1]); |
|---|
| 1133 | } |
|---|
| 1134 | #endif |
|---|
| 1135 | } |
|---|
| 1136 | } |
|---|
| 1137 | |
|---|
| 1138 | void maxi_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1139 | int *nrels_mag, long *results) |
|---|
| 1140 | { |
|---|
| 1141 | struct maxi_data *data = client->data; |
|---|
| 1142 | int nr; |
|---|
| 1143 | |
|---|
| 1144 | if (data->type == nba) { |
|---|
| 1145 | maxi99_temp(client, operation, ctl_name, nrels_mag, |
|---|
| 1146 | results); |
|---|
| 1147 | return; |
|---|
| 1148 | } |
|---|
| 1149 | |
|---|
| 1150 | nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; |
|---|
| 1151 | |
|---|
| 1152 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1153 | *nrels_mag = 1; |
|---|
| 1154 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1155 | maxi_update_client(client); |
|---|
| 1156 | results[0] = TEMP_FROM_REG(data->temp_max[nr - 1]); |
|---|
| 1157 | results[1] = TEMP_FROM_REG(data->temp_hyst[nr - 1]); |
|---|
| 1158 | results[2] = TEMP_FROM_REG(data->temp[nr - 1]); |
|---|
| 1159 | *nrels_mag = 3; |
|---|
| 1160 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1161 | /* temperature range can not be changed */ |
|---|
| 1162 | } |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | void maxi99_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1166 | int *nrels_mag, long *results) |
|---|
| 1167 | { |
|---|
| 1168 | struct maxi_data *data = client->data; |
|---|
| 1169 | int nr; |
|---|
| 1170 | |
|---|
| 1171 | nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; |
|---|
| 1172 | |
|---|
| 1173 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1174 | *nrels_mag = 0; |
|---|
| 1175 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1176 | maxi99_update_client(client, temp, nr - 1); |
|---|
| 1177 | results[0] = TEMP99_FROM_REG(data->temp_max[nr - 1]); |
|---|
| 1178 | results[1] = TEMP99_FROM_REG(data->temp_hyst[nr - 1]); |
|---|
| 1179 | results[2] = TEMP99_FROM_REG(data->temp[nr - 1]); |
|---|
| 1180 | *nrels_mag = 3; |
|---|
| 1181 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1182 | /* temperature range can not be changed */ |
|---|
| 1183 | } |
|---|
| 1184 | } |
|---|
| 1185 | |
|---|
| 1186 | void maxi_pll(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1187 | int *nrels_mag, long *results) |
|---|
| 1188 | { |
|---|
| 1189 | struct maxi_data *data = client->data; |
|---|
| 1190 | |
|---|
| 1191 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1192 | *nrels_mag = 2; |
|---|
| 1193 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1194 | if (data->type == nba) |
|---|
| 1195 | maxi99_update_client(client, pll, 0); |
|---|
| 1196 | else |
|---|
| 1197 | maxi_update_client(client); |
|---|
| 1198 | results[0] = PLL_FROM_REG(data->pll_min); |
|---|
| 1199 | results[1] = PLL_FROM_REG(data->pll_max); |
|---|
| 1200 | results[2] = PLL_FROM_REG(data->pll); |
|---|
| 1201 | *nrels_mag = 3; |
|---|
| 1202 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1203 | #ifndef NOWRITE |
|---|
| 1204 | if (*nrels_mag >= 1) { |
|---|
| 1205 | data->pll_min = PLL_TO_REG(results[0]); |
|---|
| 1206 | maxi_write_value(client, MAXI_REG_PLL_MIN, |
|---|
| 1207 | data->pll_min); |
|---|
| 1208 | } |
|---|
| 1209 | if (*nrels_mag >= 2) { |
|---|
| 1210 | data->pll_max = PLL_TO_REG(results[1]); |
|---|
| 1211 | maxi_write_value(client, MAXI_REG_PLL_MAX, |
|---|
| 1212 | data->pll_max); |
|---|
| 1213 | } |
|---|
| 1214 | #endif |
|---|
| 1215 | } |
|---|
| 1216 | } |
|---|
| 1217 | |
|---|
| 1218 | void maxi_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1219 | int *nrels_mag, long *results) |
|---|
| 1220 | { |
|---|
| 1221 | struct maxi_data *data = client->data; |
|---|
| 1222 | int nr; |
|---|
| 1223 | |
|---|
| 1224 | if (data->type == nba) { |
|---|
| 1225 | maxi99_vid(client, operation, ctl_name, nrels_mag, |
|---|
| 1226 | results); |
|---|
| 1227 | return; |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | nr = ctl_name - MAXI_SYSCTL_VID1 + 1; |
|---|
| 1231 | |
|---|
| 1232 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1233 | *nrels_mag = 4; |
|---|
| 1234 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1235 | maxi_update_client(client); |
|---|
| 1236 | results[0] = VID_FROM_REG(data->vid_min[nr - 1]); |
|---|
| 1237 | results[1] = VID_FROM_REG(data->vid_max[nr - 1]); |
|---|
| 1238 | results[2] = VID_FROM_REG(data->vid[nr - 1]); |
|---|
| 1239 | *nrels_mag = 3; |
|---|
| 1240 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1241 | #ifndef NOWRITE |
|---|
| 1242 | if (*nrels_mag >= 1) { |
|---|
| 1243 | data->vid_min[nr - 1] = VID_TO_REG(results[0]); |
|---|
| 1244 | maxi_write_value(client, MAXI_REG_VID_MIN(nr), |
|---|
| 1245 | data->vid_min[nr - 1]); |
|---|
| 1246 | } |
|---|
| 1247 | if (*nrels_mag >= 2) { |
|---|
| 1248 | data->vid_max[nr - 1] = VID_TO_REG(results[1]); |
|---|
| 1249 | maxi_write_value(client, MAXI_REG_VID_MAX(nr), |
|---|
| 1250 | data->vid_max[nr - 1]); |
|---|
| 1251 | } |
|---|
| 1252 | #endif |
|---|
| 1253 | } |
|---|
| 1254 | } |
|---|
| 1255 | |
|---|
| 1256 | void maxi99_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1257 | int *nrels_mag, long *results) |
|---|
| 1258 | { |
|---|
| 1259 | struct maxi_data *data = client->data; |
|---|
| 1260 | int nr = ctl_name - MAXI_SYSCTL_VID1 + 1; |
|---|
| 1261 | |
|---|
| 1262 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1263 | *nrels_mag = 4; |
|---|
| 1264 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1265 | maxi99_update_client(client, vid, nr - 1); |
|---|
| 1266 | results[0] = VID99_FROM_REG(nr, data->vid_min[nr - 1]); |
|---|
| 1267 | results[1] = VID99_FROM_REG(nr, data->vid_max[nr - 1]); |
|---|
| 1268 | results[2] = VID99_FROM_REG(nr, data->vid[nr - 1]); |
|---|
| 1269 | *nrels_mag = 3; |
|---|
| 1270 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1271 | #ifndef NOWRITE |
|---|
| 1272 | /* still to do */ |
|---|
| 1273 | if (*nrels_mag >= 1) { |
|---|
| 1274 | data->vid_min[nr - 1] = VID_TO_REG(results[0]); |
|---|
| 1275 | maxi_write_value(client, MAXI_REG_VID_MIN(nr), |
|---|
| 1276 | data->vid_min[nr - 1]); |
|---|
| 1277 | } |
|---|
| 1278 | if (*nrels_mag >= 2) { |
|---|
| 1279 | data->vid_max[nr - 1] = VID_TO_REG(results[1]); |
|---|
| 1280 | maxi_write_value(client, MAXI_REG_VID_MAX(nr), |
|---|
| 1281 | data->vid_max[nr - 1]); |
|---|
| 1282 | } |
|---|
| 1283 | #endif |
|---|
| 1284 | } |
|---|
| 1285 | } |
|---|
| 1286 | |
|---|
| 1287 | void maxi_lcd(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1288 | int *nrels_mag, long *results) |
|---|
| 1289 | { |
|---|
| 1290 | /* Allows writing and reading from LCD display */ |
|---|
| 1291 | |
|---|
| 1292 | struct maxi_data *data = client->data; |
|---|
| 1293 | int nr; |
|---|
| 1294 | |
|---|
| 1295 | if (data->type != nba) |
|---|
| 1296 | return; |
|---|
| 1297 | |
|---|
| 1298 | nr = ctl_name - MAXI_SYSCTL_LCD1 + 1; |
|---|
| 1299 | |
|---|
| 1300 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1301 | *nrels_mag = 0; |
|---|
| 1302 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1303 | results[0] = *((long *) &data->lcd[nr - 1][0]); |
|---|
| 1304 | results[1] = *((long *) &data->lcd[nr - 1][4]); |
|---|
| 1305 | results[2] = *((long *) &data->lcd[nr - 1][8]); |
|---|
| 1306 | results[3] = *((long *) &data->lcd[nr - 1][12]); |
|---|
| 1307 | *nrels_mag = 4; |
|---|
| 1308 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1309 | /* |
|---|
| 1310 | Writing a string to line 3 of the LCD can be done like: |
|---|
| 1311 | echo -n "Linux MaxiLife" | od -A n -l > \ |
|---|
| 1312 | /proc/sys/dev/sensors/maxilife-nba-i2c-0-14/lcd3 |
|---|
| 1313 | */ |
|---|
| 1314 | if (*nrels_mag >= 1) |
|---|
| 1315 | *((long *) &data->lcd[nr - 1][0]) = results[0]; |
|---|
| 1316 | if (*nrels_mag >= 2) |
|---|
| 1317 | *((long *) &data->lcd[nr - 1][4]) = results[1]; |
|---|
| 1318 | if (*nrels_mag >= 3) |
|---|
| 1319 | *((long *) &data->lcd[nr - 1][8]) = results[2]; |
|---|
| 1320 | if (*nrels_mag >= 4) |
|---|
| 1321 | *((long *) &data->lcd[nr - 1][12]) = results[3]; |
|---|
| 1322 | maxi_write_token_loop(client, MAXI_TOK_LCD(nr - 1), |
|---|
| 1323 | strlen(data->lcd[nr - 1]) + 1, |
|---|
| 1324 | data->lcd[nr - 1]); |
|---|
| 1325 | #if 0 |
|---|
| 1326 | if (*nrels_mag >= 1) |
|---|
| 1327 | printk("nr=%d, result[0] = %.4s\n", nr, |
|---|
| 1328 | (char *) &results[0]); |
|---|
| 1329 | if (*nrels_mag >= 2) |
|---|
| 1330 | printk("nr=%d, result[1] = %.4s\n", nr, |
|---|
| 1331 | (char *) &results[1]); |
|---|
| 1332 | if (*nrels_mag >= 3) |
|---|
| 1333 | printk("nr=%d, result[2] = %.4s\n", nr, |
|---|
| 1334 | (char *) &results[2]); |
|---|
| 1335 | if (*nrels_mag >= 4) |
|---|
| 1336 | printk("nr=%d, result[3] = %.4s\n", nr, |
|---|
| 1337 | (char *) &results[3]); |
|---|
| 1338 | #endif |
|---|
| 1339 | } |
|---|
| 1340 | |
|---|
| 1341 | } |
|---|
| 1342 | |
|---|
| 1343 | void maxi_alarms(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1344 | int *nrels_mag, long *results) |
|---|
| 1345 | { |
|---|
| 1346 | struct maxi_data *data = client->data; |
|---|
| 1347 | |
|---|
| 1348 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1349 | *nrels_mag = 0; |
|---|
| 1350 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1351 | if (data->type == nba) |
|---|
| 1352 | maxi99_update_client(client, alarm, 0); |
|---|
| 1353 | else |
|---|
| 1354 | maxi_update_client(client); |
|---|
| 1355 | results[0] = ALARMS_FROM_REG(data->alarms); |
|---|
| 1356 | *nrels_mag = 1; |
|---|
| 1357 | } |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | static int __init sm_maxilife_init(void) |
|---|
| 1361 | { |
|---|
| 1362 | printk("maxilife: Version %s (lm_sensors %s (%s))\n", version_str, |
|---|
| 1363 | LM_VERSION, LM_DATE); |
|---|
| 1364 | return i2c_add_driver(&maxi_driver); |
|---|
| 1365 | } |
|---|
| 1366 | |
|---|
| 1367 | static void __exit sm_maxilife_exit(void) |
|---|
| 1368 | { |
|---|
| 1369 | i2c_del_driver(&maxi_driver); |
|---|
| 1370 | } |
|---|
| 1371 | |
|---|
| 1372 | |
|---|
| 1373 | |
|---|
| 1374 | MODULE_AUTHOR("Fons Rademakers <Fons.Rademakers@cern.ch>"); |
|---|
| 1375 | MODULE_DESCRIPTION("HP MaxiLife driver"); |
|---|
| 1376 | MODULE_PARM(maxi_version, "i"); |
|---|
| 1377 | MODULE_PARM_DESC(maxi_version, "MaxiLife firmware version"); |
|---|
| 1378 | |
|---|
| 1379 | module_init(sm_maxilife_init); |
|---|
| 1380 | module_exit(sm_maxilife_exit); |
|---|