| 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. It is dynamically allocated, at the same time when a new MaxiLife |
|---|
| 237 | client is allocated. We assume MaxiLife will only be present on the |
|---|
| 238 | SMBus and not on the ISA bus. */ |
|---|
| 239 | struct maxi_data { |
|---|
| 240 | struct i2c_client client; |
|---|
| 241 | int sysctl_id; |
|---|
| 242 | enum maxi_type type; |
|---|
| 243 | |
|---|
| 244 | struct semaphore update_lock; |
|---|
| 245 | char valid; /* !=0 if following fields are valid */ |
|---|
| 246 | unsigned long last_updated; /* In jiffies */ |
|---|
| 247 | |
|---|
| 248 | u8 fan[4]; /* Register value */ |
|---|
| 249 | u8 fan_min[4]; /* Register value */ |
|---|
| 250 | u8 fan_speed[4]; /* Register value */ |
|---|
| 251 | u8 fan_div[4]; /* Static value */ |
|---|
| 252 | u8 temp[6]; /* Register value */ |
|---|
| 253 | u8 temp_max[6]; /* Static value */ |
|---|
| 254 | u8 temp_hyst[6]; /* Static value */ |
|---|
| 255 | u8 pll; /* Register value */ |
|---|
| 256 | u8 pll_min; /* Register value */ |
|---|
| 257 | u8 pll_max; /* register value */ |
|---|
| 258 | u8 vid[5]; /* Register value */ |
|---|
| 259 | u8 vid_min[5]; /* Register value */ |
|---|
| 260 | u8 vid_max[5]; /* Register value */ |
|---|
| 261 | u8 lcd[4][17]; /* Four LCD lines */ |
|---|
| 262 | u16 alarms; /* Register encoding, combined */ |
|---|
| 263 | }; |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | static int maxi_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 267 | static int maxi_detect(struct i2c_adapter *adapter, int address, |
|---|
| 268 | unsigned short flags, int kind); |
|---|
| 269 | static int maxi_detach_client(struct i2c_client *client); |
|---|
| 270 | |
|---|
| 271 | static int maxi_read_value(struct i2c_client *client, u8 register); |
|---|
| 272 | static int maxi_read_token(struct i2c_client *client, u16 token); |
|---|
| 273 | #ifndef NOWRITE |
|---|
| 274 | static int maxi_write_value(struct i2c_client *client, u8 register, |
|---|
| 275 | u8 value); |
|---|
| 276 | #endif |
|---|
| 277 | static int maxi_write_token_loop(struct i2c_client *client, u16 token, |
|---|
| 278 | u8 len, u8 * values); |
|---|
| 279 | |
|---|
| 280 | static void maxi_update_client(struct i2c_client *client); |
|---|
| 281 | static void maxi99_update_client(struct i2c_client *client, |
|---|
| 282 | enum sensor_type sensor, int which); |
|---|
| 283 | static void maxi_init_client(struct i2c_client *client); |
|---|
| 284 | |
|---|
| 285 | static void maxi_fan(struct i2c_client *client, int operation, |
|---|
| 286 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 287 | static void maxi99_fan(struct i2c_client *client, int operation, |
|---|
| 288 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 289 | static void maxi_temp(struct i2c_client *client, int operation, |
|---|
| 290 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 291 | static void maxi99_temp(struct i2c_client *client, int operation, |
|---|
| 292 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 293 | static void maxi_pll(struct i2c_client *client, int operation, |
|---|
| 294 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 295 | static void maxi_vid(struct i2c_client *client, int operation, |
|---|
| 296 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 297 | static void maxi99_vid(struct i2c_client *client, int operation, |
|---|
| 298 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 299 | static void maxi_lcd(struct i2c_client *client, int operation, |
|---|
| 300 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 301 | static void maxi_alarms(struct i2c_client *client, int operation, |
|---|
| 302 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 303 | |
|---|
| 304 | /* The driver. I choose to use type i2c_driver, as at is identical to |
|---|
| 305 | the smbus_driver. */ |
|---|
| 306 | static struct i2c_driver maxi_driver = { |
|---|
| 307 | .name = "HP MaxiLife driver", |
|---|
| 308 | .id = I2C_DRIVERID_MAXILIFE, |
|---|
| 309 | .flags = I2C_DF_NOTIFY, |
|---|
| 310 | .attach_adapter = maxi_attach_adapter, |
|---|
| 311 | .detach_client = maxi_detach_client, |
|---|
| 312 | }; |
|---|
| 313 | |
|---|
| 314 | /* Default firmware version. Use module option "maxi_version" |
|---|
| 315 | to set desired version. Auto detect is not yet working */ |
|---|
| 316 | static int maxi_version = cristal; |
|---|
| 317 | |
|---|
| 318 | /* The /proc/sys entries */ |
|---|
| 319 | |
|---|
| 320 | /* -- SENSORS SYSCTL START -- */ |
|---|
| 321 | #define MAXI_SYSCTL_FAN1 1101 /* Rotations/min */ |
|---|
| 322 | #define MAXI_SYSCTL_FAN2 1102 /* Rotations/min */ |
|---|
| 323 | #define MAXI_SYSCTL_FAN3 1103 /* Rotations/min */ |
|---|
| 324 | #define MAXI_SYSCTL_FAN4 1104 /* Rotations/min */ |
|---|
| 325 | #define MAXI_SYSCTL_TEMP1 1201 /* Degrees Celsius */ |
|---|
| 326 | #define MAXI_SYSCTL_TEMP2 1202 /* Degrees Celsius */ |
|---|
| 327 | #define MAXI_SYSCTL_TEMP3 1203 /* Degrees Celsius */ |
|---|
| 328 | #define MAXI_SYSCTL_TEMP4 1204 /* Degrees Celsius */ |
|---|
| 329 | #define MAXI_SYSCTL_TEMP5 1205 /* Degrees Celsius */ |
|---|
| 330 | #define MAXI_SYSCTL_TEMP6 1206 /* Degrees Celsius */ |
|---|
| 331 | #define MAXI_SYSCTL_PLL 1301 /* MHz */ |
|---|
| 332 | #define MAXI_SYSCTL_VID1 1401 /* Volts / 6.337, for nba just Volts */ |
|---|
| 333 | #define MAXI_SYSCTL_VID2 1402 /* Volts */ |
|---|
| 334 | #define MAXI_SYSCTL_VID3 1403 /* Volts */ |
|---|
| 335 | #define MAXI_SYSCTL_VID4 1404 /* Volts */ |
|---|
| 336 | #define MAXI_SYSCTL_VID5 1405 /* Volts */ |
|---|
| 337 | #define MAXI_SYSCTL_LCD1 1501 /* Line 1 of LCD */ |
|---|
| 338 | #define MAXI_SYSCTL_LCD2 1502 /* Line 2 of LCD */ |
|---|
| 339 | #define MAXI_SYSCTL_LCD3 1503 /* Line 3 of LCD */ |
|---|
| 340 | #define MAXI_SYSCTL_LCD4 1504 /* Line 4 of LCD */ |
|---|
| 341 | #define MAXI_SYSCTL_ALARMS 2001 /* Bitvector (see below) */ |
|---|
| 342 | |
|---|
| 343 | #define MAXI_ALARM_VID4 0x0001 |
|---|
| 344 | #define MAXI_ALARM_TEMP2 0x0002 |
|---|
| 345 | #define MAXI_ALARM_VID1 0x0004 |
|---|
| 346 | #define MAXI_ALARM_VID2 0x0008 |
|---|
| 347 | #define MAXI_ALARM_VID3 0x0010 |
|---|
| 348 | #define MAXI_ALARM_PLL 0x0080 |
|---|
| 349 | #define MAXI_ALARM_TEMP4 0x0100 |
|---|
| 350 | #define MAXI_ALARM_TEMP5 0x0200 |
|---|
| 351 | #define MAXI_ALARM_FAN1 0x1000 |
|---|
| 352 | #define MAXI_ALARM_FAN2 0x2000 |
|---|
| 353 | #define MAXI_ALARM_FAN3 0x4000 |
|---|
| 354 | |
|---|
| 355 | #define MAXI_ALARM_FAN 0x0100 /* To be used with MaxiLife'99 */ |
|---|
| 356 | #define MAXI_ALARM_VID 0x0200 /* The MSB specifies which sensor */ |
|---|
| 357 | #define MAXI_ALARM_TEMP 0x0400 /* in the alarm group failed, i.e.: */ |
|---|
| 358 | #define MAXI_ALARM_VADD 0x0800 /* 0x0402 = TEMP2 failed = CPU2 temp */ |
|---|
| 359 | |
|---|
| 360 | /* -- SENSORS SYSCTL END -- */ |
|---|
| 361 | |
|---|
| 362 | /* These files are created for each detected MaxiLife processor. |
|---|
| 363 | This is just a template; though at first sight, you might think we |
|---|
| 364 | could use a statically allocated list, we need some way to get back |
|---|
| 365 | to the parent - which is done through one of the 'extra' fields |
|---|
| 366 | which are initialized when a new copy is allocated. */ |
|---|
| 367 | static ctl_table maxi_dir_table_template[] = { |
|---|
| 368 | {MAXI_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 369 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 370 | {MAXI_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 371 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 372 | {MAXI_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 373 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 374 | {MAXI_SYSCTL_FAN4, "fan4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 375 | &i2c_sysctl_real, NULL, &maxi_fan}, |
|---|
| 376 | {MAXI_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 377 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 378 | {MAXI_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 379 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 380 | {MAXI_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 381 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 382 | {MAXI_SYSCTL_TEMP4, "temp4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 383 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 384 | {MAXI_SYSCTL_TEMP5, "temp5", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 385 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 386 | {MAXI_SYSCTL_TEMP6, "temp6", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 387 | &i2c_sysctl_real, NULL, &maxi_temp}, |
|---|
| 388 | {MAXI_SYSCTL_PLL, "pll", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 389 | &i2c_sysctl_real, NULL, &maxi_pll}, |
|---|
| 390 | {MAXI_SYSCTL_VID1, "vid1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 391 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 392 | {MAXI_SYSCTL_VID2, "vid2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 393 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 394 | {MAXI_SYSCTL_VID3, "vid3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 395 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 396 | {MAXI_SYSCTL_VID4, "vid4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 397 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 398 | {MAXI_SYSCTL_VID5, "vid5", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 399 | &i2c_sysctl_real, NULL, &maxi_vid}, |
|---|
| 400 | {MAXI_SYSCTL_LCD1, "lcd1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 401 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 402 | {MAXI_SYSCTL_LCD2, "lcd2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 403 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 404 | {MAXI_SYSCTL_LCD3, "lcd3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 405 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 406 | {MAXI_SYSCTL_LCD4, "lcd4", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 407 | &i2c_sysctl_real, NULL, &maxi_lcd}, |
|---|
| 408 | {MAXI_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 409 | &i2c_sysctl_real, NULL, &maxi_alarms}, |
|---|
| 410 | {0} |
|---|
| 411 | }; |
|---|
| 412 | |
|---|
| 413 | /* This function is called when: |
|---|
| 414 | - maxi_driver is inserted (when this module is loaded), for each |
|---|
| 415 | available adapter |
|---|
| 416 | - when a new adapter is inserted (and maxi_driver is still present) */ |
|---|
| 417 | static int maxi_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 418 | { |
|---|
| 419 | return i2c_detect(adapter, &addr_data, maxi_detect); |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | /* This function is called by i2c_detect */ |
|---|
| 423 | int maxi_detect(struct i2c_adapter *adapter, int address, |
|---|
| 424 | unsigned short flags, int kind) |
|---|
| 425 | { |
|---|
| 426 | struct i2c_client *new_client; |
|---|
| 427 | struct maxi_data *data; |
|---|
| 428 | enum maxi_type type = 0; |
|---|
| 429 | int i, j, err = 0; |
|---|
| 430 | const char *type_name = NULL, *client_name = NULL; |
|---|
| 431 | |
|---|
| 432 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
|---|
| 433 | goto ERROR0; |
|---|
| 434 | |
|---|
| 435 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 436 | client structure, even though we cannot fill it completely yet. |
|---|
| 437 | But it allows us to access maxi_{read,write}_value. */ |
|---|
| 438 | if (!(data = kmalloc(sizeof(struct maxi_data), GFP_KERNEL))) { |
|---|
| 439 | err = -ENOMEM; |
|---|
| 440 | goto ERROR0; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | /* Fill the new client structure with data */ |
|---|
| 444 | new_client = &data->client; |
|---|
| 445 | new_client->addr = address; |
|---|
| 446 | new_client->data = data; |
|---|
| 447 | new_client->adapter = adapter; |
|---|
| 448 | new_client->driver = &maxi_driver; |
|---|
| 449 | new_client->flags = 0; |
|---|
| 450 | |
|---|
| 451 | /* Now we do the remaining detection. */ |
|---|
| 452 | if (kind < 0) { |
|---|
| 453 | if (i2c_smbus_read_byte_data |
|---|
| 454 | (new_client, MAXI_REG_MBX_STATUS) < 0) |
|---|
| 455 | goto ERROR2; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | /* Determine the chip type - only one kind supported */ |
|---|
| 459 | if (kind <= 0) |
|---|
| 460 | kind = maxilife; |
|---|
| 461 | |
|---|
| 462 | if (kind == maxilife) { |
|---|
| 463 | /* Detect if the machine has a MaxiLife NBA controller. |
|---|
| 464 | The right way to perform this check is to do a read/modify/write |
|---|
| 465 | on register MbxStatus (5A): |
|---|
| 466 | - Read 5A (value 0 for non-NBA firmware, FF (MbxIdle on NBA-firmware) |
|---|
| 467 | - Write 55 on 5A, then read back 5A |
|---|
| 468 | Non-NBA firmware: value is 55 (reg 5A is a standard writable reg) |
|---|
| 469 | NBA firmaware: value is FF (write-protect on MbxStatus active) */ |
|---|
| 470 | int stat; |
|---|
| 471 | i2c_smbus_write_byte_data(new_client, MAXI_REG_MBX_STATUS, |
|---|
| 472 | 0x55); |
|---|
| 473 | stat = |
|---|
| 474 | i2c_smbus_read_byte_data(new_client, |
|---|
| 475 | MAXI_REG_MBX_STATUS); |
|---|
| 476 | |
|---|
| 477 | /*if (stat == MAXI_STAT_IDLE || stat == MAXI_STAT_OK) */ |
|---|
| 478 | if (stat != 0x55) |
|---|
| 479 | maxi_version = nba; |
|---|
| 480 | #ifdef AUTODETECT |
|---|
| 481 | else { |
|---|
| 482 | /* The right way to get the platform info is to read the firmware |
|---|
| 483 | revision from serial EEPROM (addr=0x54), at offset 0x0045. |
|---|
| 484 | This is a string as: |
|---|
| 485 | "CG 00.04" -> Cristal [XU] / Geronimo [XAs] |
|---|
| 486 | "CO 00.03" -> Cognac [XU] |
|---|
| 487 | "AS 00.01" -> Ashaki [XA] */ |
|---|
| 488 | #if 0 |
|---|
| 489 | int biosctl; |
|---|
| 490 | biosctl = |
|---|
| 491 | i2c_smbus_read_byte_data(new_client, |
|---|
| 492 | MAXI_REG_BIOS_CTRL); |
|---|
| 493 | i2c_smbus_write_byte_data(new_client, |
|---|
| 494 | MAXI_REG_BIOS_CTRL, |
|---|
| 495 | biosctl | 4); |
|---|
| 496 | err = eeprom_read_byte_data(adapter, 0x54, 0x45); |
|---|
| 497 | i2c_smbus_write_byte_data(new_client, |
|---|
| 498 | MAXI_REG_BIOS_CTRL, |
|---|
| 499 | biosctl); |
|---|
| 500 | #endif |
|---|
| 501 | int i; |
|---|
| 502 | char *biosmem, *bm; |
|---|
| 503 | bm = biosmem = ioremap(0xe0000, 0x20000); |
|---|
| 504 | if (biosmem) { |
|---|
| 505 | printk("begin of bios search\n"); |
|---|
| 506 | for (i = 0; i < 0x20000; i++) { |
|---|
| 507 | if (*bm == 'C') { |
|---|
| 508 | char *s = bm; |
|---|
| 509 | while (s && isprint(*s)) { |
|---|
| 510 | printk("%c", *s); |
|---|
| 511 | s++; |
|---|
| 512 | } |
|---|
| 513 | printk("\n"); |
|---|
| 514 | if (!strncmp |
|---|
| 515 | (bm, "CG 00.04", 8)) { |
|---|
| 516 | maxi_version = |
|---|
| 517 | cristal; |
|---|
| 518 | printk |
|---|
| 519 | ("maxilife: found MaxiLife Rev CG 00.04\n"); |
|---|
| 520 | break; |
|---|
| 521 | } |
|---|
| 522 | if (!strncmp |
|---|
| 523 | (bm, "CO 00.03", 8)) { |
|---|
| 524 | maxi_version = |
|---|
| 525 | cognac; |
|---|
| 526 | printk |
|---|
| 527 | ("maxilife: found MaxiLife Rev CO 00.03\n"); |
|---|
| 528 | break; |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | if (*bm == 'A' && *(bm + 1) == 'S') { |
|---|
| 532 | char *s = bm; |
|---|
| 533 | while (s && isprint(*s)) { |
|---|
| 534 | printk("%c", *s); |
|---|
| 535 | s++; |
|---|
| 536 | } |
|---|
| 537 | printk("\n"); |
|---|
| 538 | if (!strncmp |
|---|
| 539 | (bm, "AS 00.01", 8)) { |
|---|
| 540 | maxi_version = |
|---|
| 541 | ashaki; |
|---|
| 542 | printk |
|---|
| 543 | ("maxilife: found MaxiLife Rev AS 00.01\n"); |
|---|
| 544 | break; |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | bm++; |
|---|
| 548 | } |
|---|
| 549 | printk("end of bios search\n"); |
|---|
| 550 | } else |
|---|
| 551 | printk("could not map bios memory\n"); |
|---|
| 552 | } |
|---|
| 553 | #endif |
|---|
| 554 | |
|---|
| 555 | if (maxi_version == cristal) { |
|---|
| 556 | type = cristal; |
|---|
| 557 | type_name = "maxilife-cg"; |
|---|
| 558 | client_name = "HP MaxiLife Rev CG 00.04"; |
|---|
| 559 | printk |
|---|
| 560 | ("maxilife: HP KAYAK XU/XAs (Dual Pentium II Slot 1)\n"); |
|---|
| 561 | } else if (maxi_version == cognac) { |
|---|
| 562 | type = cognac; |
|---|
| 563 | type_name = "maxilife-co"; |
|---|
| 564 | client_name = "HP MaxiLife Rev CO 00.03"; |
|---|
| 565 | printk |
|---|
| 566 | ("maxilife: HP KAYAK XU (Dual Xeon Slot 2 400/450 Mhz)\n"); |
|---|
| 567 | } else if (maxi_version == ashaki) { |
|---|
| 568 | type = ashaki; |
|---|
| 569 | type_name = "maxilife-as"; |
|---|
| 570 | client_name = "HP MaxiLife Rev AS 00.01"; |
|---|
| 571 | printk |
|---|
| 572 | ("maxilife: HP KAYAK XA (Pentium II Slot 1, monoprocessor)\n"); |
|---|
| 573 | } else if (maxi_version == nba) { |
|---|
| 574 | type = nba; |
|---|
| 575 | type_name = "maxilife-nba"; |
|---|
| 576 | client_name = "HP MaxiLife NBA"; |
|---|
| 577 | printk("maxilife: HP KAYAK XU800/XM600\n"); |
|---|
| 578 | } else { |
|---|
| 579 | #ifdef AUTODETECT |
|---|
| 580 | printk |
|---|
| 581 | ("maxilife: Warning: probed non-maxilife chip?!? (%x)\n", |
|---|
| 582 | err); |
|---|
| 583 | #else |
|---|
| 584 | printk |
|---|
| 585 | ("maxilife: Error: specified wrong maxi_version (%d)\n", |
|---|
| 586 | maxi_version); |
|---|
| 587 | #endif |
|---|
| 588 | goto ERROR2; |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | /* Fill in the remaining client fields and put it into the global list */ |
|---|
| 593 | strcpy(new_client->name, client_name); |
|---|
| 594 | ((struct maxi_data *) (new_client->data))->type = type; |
|---|
| 595 | |
|---|
| 596 | for (i = 0; i < 4; i++) |
|---|
| 597 | for (j = 0; j < 17; j++) |
|---|
| 598 | ((struct maxi_data *) (new_client->data))-> |
|---|
| 599 | lcd[i][j] = (u8) 0; |
|---|
| 600 | |
|---|
| 601 | data->valid = 0; |
|---|
| 602 | init_MUTEX(&data->update_lock); |
|---|
| 603 | |
|---|
| 604 | /* Tell i2c-core that a new client has arrived */ |
|---|
| 605 | if ((err = i2c_attach_client(new_client))) |
|---|
| 606 | goto ERROR2; |
|---|
| 607 | |
|---|
| 608 | /* Register a new directory entry with module sensors */ |
|---|
| 609 | if ((err = i2c_register_entry(new_client, type_name, |
|---|
| 610 | maxi_dir_table_template, |
|---|
| 611 | THIS_MODULE)) < 0) |
|---|
| 612 | goto ERROR4; |
|---|
| 613 | data->sysctl_id = err; |
|---|
| 614 | |
|---|
| 615 | /* Initialize the MaxiLife chip */ |
|---|
| 616 | maxi_init_client(new_client); |
|---|
| 617 | return 0; |
|---|
| 618 | |
|---|
| 619 | /* OK, this is not exactly good programming practice, usually. |
|---|
| 620 | But it is very code-efficient in this case. */ |
|---|
| 621 | ERROR4: |
|---|
| 622 | i2c_detach_client(new_client); |
|---|
| 623 | ERROR2: |
|---|
| 624 | kfree(data); |
|---|
| 625 | ERROR0: |
|---|
| 626 | return err; |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | /* This function is called whenever a client should be removed: |
|---|
| 630 | - maxi_driver is removed (when this module is unloaded) |
|---|
| 631 | - when an adapter is removed which has a maxi client (and maxi_driver |
|---|
| 632 | is still present). */ |
|---|
| 633 | static int maxi_detach_client(struct i2c_client *client) |
|---|
| 634 | { |
|---|
| 635 | int err; |
|---|
| 636 | |
|---|
| 637 | i2c_deregister_entry(((struct maxi_data *) (client->data))-> |
|---|
| 638 | sysctl_id); |
|---|
| 639 | |
|---|
| 640 | if ((err = i2c_detach_client(client))) { |
|---|
| 641 | printk |
|---|
| 642 | ("maxilife: Client deregistration failed, client not detached.\n"); |
|---|
| 643 | return err; |
|---|
| 644 | } |
|---|
| 645 | kfree(client->data); |
|---|
| 646 | return 0; |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | /* Read byte from specified register (-1 in case of error, value otherwise). */ |
|---|
| 650 | static int maxi_read_value(struct i2c_client *client, u8 reg) |
|---|
| 651 | { |
|---|
| 652 | return i2c_smbus_read_byte_data(client, reg); |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | /* Read the byte value for a MaxiLife token (-1 in case of error, value otherwise */ |
|---|
| 656 | static int maxi_read_token(struct i2c_client *client, u16 token) |
|---|
| 657 | { |
|---|
| 658 | u8 lowToken, highToken; |
|---|
| 659 | int error, value; |
|---|
| 660 | |
|---|
| 661 | lowToken = LOW(token); |
|---|
| 662 | highToken = HIGH(token); |
|---|
| 663 | |
|---|
| 664 | /* Set mailbox status register to idle state. */ |
|---|
| 665 | error = |
|---|
| 666 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 667 | MAXI_STAT_IDLE); |
|---|
| 668 | if (error < 0) |
|---|
| 669 | return error; |
|---|
| 670 | |
|---|
| 671 | /* Check for mailbox idle state. */ |
|---|
| 672 | error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 673 | if (error != MAXI_STAT_IDLE) |
|---|
| 674 | return -1; |
|---|
| 675 | |
|---|
| 676 | /* Write the most significant byte of the token we want to read. */ |
|---|
| 677 | error = |
|---|
| 678 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H, |
|---|
| 679 | highToken); |
|---|
| 680 | if (error < 0) |
|---|
| 681 | return error; |
|---|
| 682 | |
|---|
| 683 | /* Write the least significant byte of the token we want to read. */ |
|---|
| 684 | error = |
|---|
| 685 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L, |
|---|
| 686 | lowToken); |
|---|
| 687 | if (error < 0) |
|---|
| 688 | return error; |
|---|
| 689 | |
|---|
| 690 | /* Write the read token opcode to the mailbox. */ |
|---|
| 691 | error = |
|---|
| 692 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD, |
|---|
| 693 | MAXI_CMD_READ); |
|---|
| 694 | if (error < 0) |
|---|
| 695 | return error; |
|---|
| 696 | |
|---|
| 697 | /* Check for transaction completion */ |
|---|
| 698 | do { |
|---|
| 699 | error = |
|---|
| 700 | i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 701 | } while (error == MAXI_STAT_BUSY); |
|---|
| 702 | if (error != MAXI_STAT_OK) |
|---|
| 703 | return -1; |
|---|
| 704 | |
|---|
| 705 | /* Read the value of the token. */ |
|---|
| 706 | value = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_DATA); |
|---|
| 707 | if (value == -1) |
|---|
| 708 | return -1; |
|---|
| 709 | |
|---|
| 710 | /* set mailbox status to idle to complete transaction. */ |
|---|
| 711 | error = |
|---|
| 712 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 713 | MAXI_STAT_IDLE); |
|---|
| 714 | if (error < 0) |
|---|
| 715 | return error; |
|---|
| 716 | |
|---|
| 717 | return value; |
|---|
| 718 | } |
|---|
| 719 | |
|---|
| 720 | #ifndef NOWRITE |
|---|
| 721 | /* Write byte to specified register (-1 in case of error, 0 otherwise). */ |
|---|
| 722 | static int maxi_write_value(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 723 | { |
|---|
| 724 | return i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 725 | } |
|---|
| 726 | #endif |
|---|
| 727 | |
|---|
| 728 | /* Write a set of len byte values to MaxiLife token (-1 in case of error, 0 otherwise). */ |
|---|
| 729 | int maxi_write_token_loop(struct i2c_client *client, u16 token, u8 len, |
|---|
| 730 | u8 * values) |
|---|
| 731 | { |
|---|
| 732 | u8 lowToken, highToken, bCounter; |
|---|
| 733 | int error; |
|---|
| 734 | |
|---|
| 735 | lowToken = LOW(token); |
|---|
| 736 | highToken = HIGH(token); |
|---|
| 737 | |
|---|
| 738 | /* Set mailbox status register to idle state. */ |
|---|
| 739 | error = |
|---|
| 740 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 741 | MAXI_STAT_IDLE); |
|---|
| 742 | if (error < 0) |
|---|
| 743 | return error; |
|---|
| 744 | |
|---|
| 745 | /* Check for mailbox idle state. */ |
|---|
| 746 | error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 747 | if (error != MAXI_STAT_IDLE) |
|---|
| 748 | return -1; |
|---|
| 749 | |
|---|
| 750 | for (bCounter = 0; (bCounter < len && bCounter < 32); bCounter++) { |
|---|
| 751 | error = |
|---|
| 752 | i2c_smbus_write_byte_data(client, |
|---|
| 753 | (u8) (MAXI_REG_MBX_DATA + |
|---|
| 754 | bCounter), |
|---|
| 755 | values[bCounter]); |
|---|
| 756 | if (error < 0) |
|---|
| 757 | return error; |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | /* Write the most significant byte of the token we want to read. */ |
|---|
| 761 | error = |
|---|
| 762 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H, |
|---|
| 763 | highToken); |
|---|
| 764 | if (error < 0) |
|---|
| 765 | return error; |
|---|
| 766 | |
|---|
| 767 | /* Write the least significant byte of the token we want to read. */ |
|---|
| 768 | error = |
|---|
| 769 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L, |
|---|
| 770 | lowToken); |
|---|
| 771 | if (error < 0) |
|---|
| 772 | return error; |
|---|
| 773 | |
|---|
| 774 | /* Write the write token opcode to the mailbox. */ |
|---|
| 775 | error = |
|---|
| 776 | i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD, |
|---|
| 777 | MAXI_CMD_WRITE); |
|---|
| 778 | if (error < 0) |
|---|
| 779 | return error; |
|---|
| 780 | |
|---|
| 781 | /* Check for transaction completion */ |
|---|
| 782 | do { |
|---|
| 783 | error = |
|---|
| 784 | i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS); |
|---|
| 785 | } while (error == MAXI_STAT_BUSY); |
|---|
| 786 | if (error != MAXI_STAT_OK) |
|---|
| 787 | return -1; |
|---|
| 788 | |
|---|
| 789 | /* set mailbox status to idle to complete transaction. */ |
|---|
| 790 | return i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS, |
|---|
| 791 | MAXI_STAT_IDLE); |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | /* Called when we have found a new MaxiLife. */ |
|---|
| 795 | static void maxi_init_client(struct i2c_client *client) |
|---|
| 796 | { |
|---|
| 797 | struct maxi_data *data = client->data; |
|---|
| 798 | |
|---|
| 799 | if (data->type == nba) { |
|---|
| 800 | strcpy(data->lcd[2], " Linux MaxiLife"); |
|---|
| 801 | maxi_write_token_loop(client, MAXI_TOK_LCD(2), |
|---|
| 802 | strlen(data->lcd[2]) + 1, |
|---|
| 803 | data->lcd[2]); |
|---|
| 804 | } |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | static void maxi_update_client(struct i2c_client *client) |
|---|
| 808 | { |
|---|
| 809 | struct maxi_data *data = client->data; |
|---|
| 810 | int i; |
|---|
| 811 | |
|---|
| 812 | if (data->type == nba) { |
|---|
| 813 | printk |
|---|
| 814 | ("maxi_update_client should never be called by nba\n"); |
|---|
| 815 | return; |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | down(&data->update_lock); |
|---|
| 819 | |
|---|
| 820 | if ((jiffies - data->last_updated > HZ + HZ / 2) || |
|---|
| 821 | (jiffies < data->last_updated) || !data->valid) { |
|---|
| 822 | |
|---|
| 823 | #ifdef DEBUG |
|---|
| 824 | printk("maxilife: Starting MaxiLife update\n"); |
|---|
| 825 | #endif |
|---|
| 826 | for (i = 0; i < 5; i++) |
|---|
| 827 | data->temp[i] = |
|---|
| 828 | maxi_read_value(client, MAXI_REG_TEMP(i)); |
|---|
| 829 | switch (data->type) { |
|---|
| 830 | case cristal: |
|---|
| 831 | data->temp[0] = 0; /* not valid */ |
|---|
| 832 | data->temp_max[0] = 0; |
|---|
| 833 | data->temp_hyst[0] = 0; |
|---|
| 834 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 835 | data->temp_hyst[1] = 100; |
|---|
| 836 | data->temp_max[2] = 120; /* max BX chipset temp */ |
|---|
| 837 | data->temp_hyst[2] = 110; |
|---|
| 838 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 839 | data->temp_hyst[3] = 90; |
|---|
| 840 | data->temp_max[4] = 120; /* max CPU temp */ |
|---|
| 841 | data->temp_hyst[4] = 110; |
|---|
| 842 | break; |
|---|
| 843 | |
|---|
| 844 | case cognac: |
|---|
| 845 | data->temp_max[0] = 120; /* max CPU1 temp */ |
|---|
| 846 | data->temp_hyst[0] = 110; |
|---|
| 847 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 848 | data->temp_hyst[1] = 100; |
|---|
| 849 | data->temp_max[2] = 120; /* max CPU2 temp */ |
|---|
| 850 | data->temp_hyst[2] = 110; |
|---|
| 851 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 852 | data->temp_hyst[3] = 90; |
|---|
| 853 | data->temp_max[4] = 120; /* max reference CPU temp */ |
|---|
| 854 | data->temp_hyst[4] = 110; |
|---|
| 855 | break; |
|---|
| 856 | |
|---|
| 857 | case ashaki: |
|---|
| 858 | data->temp[0] = 0; /* not valid */ |
|---|
| 859 | data->temp_max[0] = 0; |
|---|
| 860 | data->temp_hyst[0] = 0; |
|---|
| 861 | data->temp_max[1] = 110; /* max PCI slot temp */ |
|---|
| 862 | data->temp_hyst[1] = 100; |
|---|
| 863 | data->temp[2] = 0; /* not valid */ |
|---|
| 864 | data->temp_max[2] = 0; |
|---|
| 865 | data->temp_hyst[2] = 0; |
|---|
| 866 | data->temp_max[3] = 100; /* max HDD temp */ |
|---|
| 867 | data->temp_hyst[3] = 90; |
|---|
| 868 | data->temp_max[4] = 120; /* max CPU temp */ |
|---|
| 869 | data->temp_hyst[4] = 110; |
|---|
| 870 | break; |
|---|
| 871 | |
|---|
| 872 | default: |
|---|
| 873 | printk("maxilife: Unknown MaxiLife chip\n"); |
|---|
| 874 | } |
|---|
| 875 | data->temp[5] = 0; /* only used by MaxiLife'99 */ |
|---|
| 876 | data->temp_max[5] = 0; |
|---|
| 877 | data->temp_hyst[5] = 0; |
|---|
| 878 | |
|---|
| 879 | for (i = 0; i < 3; i++) { |
|---|
| 880 | data->fan[i] = |
|---|
| 881 | maxi_read_value(client, MAXI_REG_FAN(i)); |
|---|
| 882 | data->fan_speed[i] = |
|---|
| 883 | maxi_read_value(client, MAXI_REG_FAN_SPEED(i)); |
|---|
| 884 | data->fan_div[i] = 4; |
|---|
| 885 | if (data->type == ashaki) |
|---|
| 886 | data->fan_min[i] = |
|---|
| 887 | maxi_read_value(client, |
|---|
| 888 | MAXI_REG_FAN_MINAS(i)); |
|---|
| 889 | else |
|---|
| 890 | data->fan_min[i] = |
|---|
| 891 | maxi_read_value(client, |
|---|
| 892 | MAXI_REG_FAN_MIN(i)); |
|---|
| 893 | } |
|---|
| 894 | data->fan[3] = 0xff; /* only used by MaxiLife'99 */ |
|---|
| 895 | data->fan_speed[3] = 0; |
|---|
| 896 | data->fan_div[3] = 4; /* avoid possible /0 */ |
|---|
| 897 | data->fan_min[3] = 0; |
|---|
| 898 | |
|---|
| 899 | data->pll = maxi_read_value(client, MAXI_REG_PLL); |
|---|
| 900 | data->pll_min = maxi_read_value(client, MAXI_REG_PLL_MIN); |
|---|
| 901 | data->pll_max = maxi_read_value(client, MAXI_REG_PLL_MAX); |
|---|
| 902 | |
|---|
| 903 | for (i = 0; i < 4; i++) { |
|---|
| 904 | data->vid[i] = |
|---|
| 905 | maxi_read_value(client, MAXI_REG_VID(i)); |
|---|
| 906 | data->vid_min[i] = |
|---|
| 907 | maxi_read_value(client, MAXI_REG_VID_MIN(i)); |
|---|
| 908 | data->vid_max[i] = |
|---|
| 909 | maxi_read_value(client, MAXI_REG_VID_MAX(i)); |
|---|
| 910 | } |
|---|
| 911 | switch (data->type) { |
|---|
| 912 | case cristal: |
|---|
| 913 | data->vid[3] = 0; /* no voltage cache L2 */ |
|---|
| 914 | data->vid_min[3] = 0; |
|---|
| 915 | data->vid_max[3] = 0; |
|---|
| 916 | break; |
|---|
| 917 | |
|---|
| 918 | case cognac: |
|---|
| 919 | break; |
|---|
| 920 | |
|---|
| 921 | case ashaki: |
|---|
| 922 | data->vid[1] = 0; /* no voltage CPU 2 */ |
|---|
| 923 | data->vid_min[1] = 0; |
|---|
| 924 | data->vid_max[1] = 0; |
|---|
| 925 | data->vid[3] = 0; /* no voltage cache L2 */ |
|---|
| 926 | data->vid_min[3] = 0; |
|---|
| 927 | data->vid_max[3] = 0; |
|---|
| 928 | break; |
|---|
| 929 | |
|---|
| 930 | default: |
|---|
| 931 | printk("maxilife: Unknown MaxiLife chip\n"); |
|---|
| 932 | } |
|---|
| 933 | data->vid[4] = 0; /* only used by MaxliLife'99 */ |
|---|
| 934 | data->vid_min[4] = 0; |
|---|
| 935 | data->vid_max[4] = 0; |
|---|
| 936 | |
|---|
| 937 | data->alarms = maxi_read_value(client, MAXI_REG_DIAG_RT1) + |
|---|
| 938 | (maxi_read_value(client, MAXI_REG_DIAG_RT2) << 8); |
|---|
| 939 | |
|---|
| 940 | data->last_updated = jiffies; |
|---|
| 941 | data->valid = 1; |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | up(&data->update_lock); |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | void maxi99_update_client(struct i2c_client *client, |
|---|
| 948 | enum sensor_type sensor, int which) |
|---|
| 949 | { |
|---|
| 950 | static unsigned long last_updated[6][6]; /* sensor, which */ |
|---|
| 951 | struct maxi_data *data = client->data; |
|---|
| 952 | |
|---|
| 953 | down(&data->update_lock); |
|---|
| 954 | |
|---|
| 955 | /*maxi_write_token_loop(client, MAXI_TOK_LCD_LINE3, 13, "Linux 2.2.13"); */ |
|---|
| 956 | |
|---|
| 957 | if ((jiffies - last_updated[sensor][which] > 2 * HZ) || |
|---|
| 958 | (jiffies < last_updated[sensor][which] |
|---|
| 959 | || !last_updated[sensor][which])) { |
|---|
| 960 | |
|---|
| 961 | int tmp, i; |
|---|
| 962 | |
|---|
| 963 | switch (sensor) { |
|---|
| 964 | case fan: |
|---|
| 965 | for (i = 0; i < 4; i++) { |
|---|
| 966 | if (i == which) { |
|---|
| 967 | tmp = |
|---|
| 968 | maxi_read_token(client, |
|---|
| 969 | MAXI_TOK_FAN |
|---|
| 970 | (i)); |
|---|
| 971 | data->fan[i] = |
|---|
| 972 | maxi_read_token(client, |
|---|
| 973 | MAXI_TOK_FAN |
|---|
| 974 | (i)); |
|---|
| 975 | data->fan_speed[i] = |
|---|
| 976 | maxi_read_token(client, |
|---|
| 977 | MAXI_TOK_MAX |
|---|
| 978 | (MAXI_TOK_FAN |
|---|
| 979 | (i))); |
|---|
| 980 | data->fan_div[i] = 1; |
|---|
| 981 | data->fan_min[i] = 0; |
|---|
| 982 | } |
|---|
| 983 | } |
|---|
| 984 | break; |
|---|
| 985 | |
|---|
| 986 | case temp: |
|---|
| 987 | for (i = 0; i < 6; i++) { |
|---|
| 988 | if (i == which) { |
|---|
| 989 | data->temp[i] = |
|---|
| 990 | maxi_read_token(client, |
|---|
| 991 | MAXI_TOK_TEMP |
|---|
| 992 | (i)); |
|---|
| 993 | data->temp_max[i] = |
|---|
| 994 | maxi_read_token(client, |
|---|
| 995 | MAXI_TOK_MAX |
|---|
| 996 | (MAXI_TOK_TEMP |
|---|
| 997 | (i))); |
|---|
| 998 | data->temp_hyst[i] = |
|---|
| 999 | data->temp_max[i] - 5; |
|---|
| 1000 | } |
|---|
| 1001 | } |
|---|
| 1002 | break; |
|---|
| 1003 | |
|---|
| 1004 | case vid: |
|---|
| 1005 | for (i = 0; i < 5; i++) { |
|---|
| 1006 | if (i == which) { |
|---|
| 1007 | data->vid[i] = |
|---|
| 1008 | maxi_read_token(client, |
|---|
| 1009 | MAXI_TOK_VID |
|---|
| 1010 | (i)); |
|---|
| 1011 | data->vid_min[i] = |
|---|
| 1012 | maxi_read_token(client, |
|---|
| 1013 | MAXI_TOK_MIN |
|---|
| 1014 | (MAXI_TOK_VID |
|---|
| 1015 | (i))); |
|---|
| 1016 | data->vid_max[i] = |
|---|
| 1017 | maxi_read_token(client, |
|---|
| 1018 | MAXI_TOK_MAX |
|---|
| 1019 | (MAXI_TOK_VID |
|---|
| 1020 | (i))); |
|---|
| 1021 | } |
|---|
| 1022 | } |
|---|
| 1023 | break; |
|---|
| 1024 | |
|---|
| 1025 | case pll: |
|---|
| 1026 | data->pll = 0; |
|---|
| 1027 | data->pll_min = 0; |
|---|
| 1028 | data->pll_max = 0; |
|---|
| 1029 | break; |
|---|
| 1030 | |
|---|
| 1031 | case alarm: |
|---|
| 1032 | data->alarms = |
|---|
| 1033 | (maxi_read_token(client, MAXI_TOK_ALARM_EVENT) |
|---|
| 1034 | << 8); |
|---|
| 1035 | if (data->alarms) |
|---|
| 1036 | data->alarms += |
|---|
| 1037 | data->alarms == |
|---|
| 1038 | (1 << 8) ? maxi_read_token(client, |
|---|
| 1039 | MAXI_TOK_ALARM_FAN) |
|---|
| 1040 | : data->alarms == |
|---|
| 1041 | (2 << 8) ? maxi_read_token(client, |
|---|
| 1042 | MAXI_TOK_ALARM_VID) |
|---|
| 1043 | : data->alarms == |
|---|
| 1044 | (4 << 8) ? maxi_read_token(client, |
|---|
| 1045 | MAXI_TOK_ALARM_TEMP) |
|---|
| 1046 | : data->alarms == |
|---|
| 1047 | (8 << 8) ? maxi_read_token(client, |
|---|
| 1048 | MAXI_TOK_ALARM_FAN) |
|---|
| 1049 | : 0; |
|---|
| 1050 | break; |
|---|
| 1051 | |
|---|
| 1052 | default: |
|---|
| 1053 | printk("maxilife: Unknown sensor type\n"); |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | last_updated[sensor][which] = jiffies; |
|---|
| 1057 | data->valid = 1; |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | up(&data->update_lock); |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | /* The next few functions are the call-back functions of the /proc/sys and |
|---|
| 1064 | sysctl files. Which function is used is defined in the ctl_table in |
|---|
| 1065 | the extra1 field. |
|---|
| 1066 | Each function must return the magnitude (power of 10 to divide the data |
|---|
| 1067 | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
|---|
| 1068 | put a maximum of *nrels elements in results reflecting the data of this |
|---|
| 1069 | file, and set *nrels to the number it actually put in it, if operation== |
|---|
| 1070 | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
|---|
| 1071 | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
|---|
| 1072 | Note that on SENSORS_PROC_REAL_READ, I do not check whether results is |
|---|
| 1073 | large enough (by checking the incoming value of *nrels). This is not very |
|---|
| 1074 | good practice, but as long as you put less than about 5 values in results, |
|---|
| 1075 | you can assume it is large enough. */ |
|---|
| 1076 | void maxi_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1077 | int *nrels_mag, long *results) |
|---|
| 1078 | { |
|---|
| 1079 | struct maxi_data *data = client->data; |
|---|
| 1080 | int nr; |
|---|
| 1081 | |
|---|
| 1082 | if (data->type == nba) { |
|---|
| 1083 | maxi99_fan(client, operation, ctl_name, nrels_mag, |
|---|
| 1084 | results); |
|---|
| 1085 | return; |
|---|
| 1086 | } |
|---|
| 1087 | |
|---|
| 1088 | nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; |
|---|
| 1089 | |
|---|
| 1090 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1091 | *nrels_mag = 0; |
|---|
| 1092 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1093 | maxi_update_client(client); |
|---|
| 1094 | results[0] = FAN_FROM_REG(data->fan_min[nr - 1]); |
|---|
| 1095 | results[1] = data->fan_div[nr - 1]; |
|---|
| 1096 | results[2] = FAN_FROM_REG(data->fan[nr - 1]); |
|---|
| 1097 | *nrels_mag = 3; |
|---|
| 1098 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1099 | #ifndef NOWRITE |
|---|
| 1100 | if (*nrels_mag >= 1) { |
|---|
| 1101 | data->fan_min[nr - 1] = FAN_TO_REG(results[0]); |
|---|
| 1102 | maxi_write_value(client, MAXI_REG_FAN_MIN(nr), |
|---|
| 1103 | data->fan_min[nr - 1]); |
|---|
| 1104 | } |
|---|
| 1105 | #endif |
|---|
| 1106 | } |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | void maxi99_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1110 | int *nrels_mag, long *results) |
|---|
| 1111 | { |
|---|
| 1112 | struct maxi_data *data = client->data; |
|---|
| 1113 | int nr; |
|---|
| 1114 | |
|---|
| 1115 | nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; |
|---|
| 1116 | |
|---|
| 1117 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1118 | *nrels_mag = 0; |
|---|
| 1119 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1120 | maxi99_update_client(client, fan, nr - 1); |
|---|
| 1121 | results[0] = FAN99_FROM_REG(data->fan_min[nr - 1]); /* min rpm */ |
|---|
| 1122 | results[1] = data->fan_div[nr - 1]; /* divisor */ |
|---|
| 1123 | results[2] = FAN99_FROM_REG(data->fan[nr - 1]); /* rpm */ |
|---|
| 1124 | *nrels_mag = 3; |
|---|
| 1125 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1126 | #ifndef NOWRITE |
|---|
| 1127 | /* still to do */ |
|---|
| 1128 | if (*nrels_mag >= 1) { |
|---|
| 1129 | data->fan_min[nr - 1] = FAN_TO_REG(results[0]); |
|---|
| 1130 | maxi_write_value(client, MAXI_REG_FAN_MIN(nr), |
|---|
| 1131 | data->fan_min[nr - 1]); |
|---|
| 1132 | } |
|---|
| 1133 | #endif |
|---|
| 1134 | } |
|---|
| 1135 | } |
|---|
| 1136 | |
|---|
| 1137 | void maxi_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1138 | int *nrels_mag, long *results) |
|---|
| 1139 | { |
|---|
| 1140 | struct maxi_data *data = client->data; |
|---|
| 1141 | int nr; |
|---|
| 1142 | |
|---|
| 1143 | if (data->type == nba) { |
|---|
| 1144 | maxi99_temp(client, operation, ctl_name, nrels_mag, |
|---|
| 1145 | results); |
|---|
| 1146 | return; |
|---|
| 1147 | } |
|---|
| 1148 | |
|---|
| 1149 | nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; |
|---|
| 1150 | |
|---|
| 1151 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1152 | *nrels_mag = 1; |
|---|
| 1153 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1154 | maxi_update_client(client); |
|---|
| 1155 | results[0] = TEMP_FROM_REG(data->temp_max[nr - 1]); |
|---|
| 1156 | results[1] = TEMP_FROM_REG(data->temp_hyst[nr - 1]); |
|---|
| 1157 | results[2] = TEMP_FROM_REG(data->temp[nr - 1]); |
|---|
| 1158 | *nrels_mag = 3; |
|---|
| 1159 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1160 | /* temperature range can not be changed */ |
|---|
| 1161 | } |
|---|
| 1162 | } |
|---|
| 1163 | |
|---|
| 1164 | void maxi99_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1165 | int *nrels_mag, long *results) |
|---|
| 1166 | { |
|---|
| 1167 | struct maxi_data *data = client->data; |
|---|
| 1168 | int nr; |
|---|
| 1169 | |
|---|
| 1170 | nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; |
|---|
| 1171 | |
|---|
| 1172 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1173 | *nrels_mag = 0; |
|---|
| 1174 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1175 | maxi99_update_client(client, temp, nr - 1); |
|---|
| 1176 | results[0] = TEMP99_FROM_REG(data->temp_max[nr - 1]); |
|---|
| 1177 | results[1] = TEMP99_FROM_REG(data->temp_hyst[nr - 1]); |
|---|
| 1178 | results[2] = TEMP99_FROM_REG(data->temp[nr - 1]); |
|---|
| 1179 | *nrels_mag = 3; |
|---|
| 1180 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1181 | /* temperature range can not be changed */ |
|---|
| 1182 | } |
|---|
| 1183 | } |
|---|
| 1184 | |
|---|
| 1185 | void maxi_pll(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1186 | int *nrels_mag, long *results) |
|---|
| 1187 | { |
|---|
| 1188 | struct maxi_data *data = client->data; |
|---|
| 1189 | |
|---|
| 1190 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1191 | *nrels_mag = 2; |
|---|
| 1192 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1193 | if (data->type == nba) |
|---|
| 1194 | maxi99_update_client(client, pll, 0); |
|---|
| 1195 | else |
|---|
| 1196 | maxi_update_client(client); |
|---|
| 1197 | results[0] = PLL_FROM_REG(data->pll_min); |
|---|
| 1198 | results[1] = PLL_FROM_REG(data->pll_max); |
|---|
| 1199 | results[2] = PLL_FROM_REG(data->pll); |
|---|
| 1200 | *nrels_mag = 3; |
|---|
| 1201 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1202 | #ifndef NOWRITE |
|---|
| 1203 | if (*nrels_mag >= 1) { |
|---|
| 1204 | data->pll_min = PLL_TO_REG(results[0]); |
|---|
| 1205 | maxi_write_value(client, MAXI_REG_PLL_MIN, |
|---|
| 1206 | data->pll_min); |
|---|
| 1207 | } |
|---|
| 1208 | if (*nrels_mag >= 2) { |
|---|
| 1209 | data->pll_max = PLL_TO_REG(results[1]); |
|---|
| 1210 | maxi_write_value(client, MAXI_REG_PLL_MAX, |
|---|
| 1211 | data->pll_max); |
|---|
| 1212 | } |
|---|
| 1213 | #endif |
|---|
| 1214 | } |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | void maxi_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1218 | int *nrels_mag, long *results) |
|---|
| 1219 | { |
|---|
| 1220 | struct maxi_data *data = client->data; |
|---|
| 1221 | int nr; |
|---|
| 1222 | |
|---|
| 1223 | if (data->type == nba) { |
|---|
| 1224 | maxi99_vid(client, operation, ctl_name, nrels_mag, |
|---|
| 1225 | results); |
|---|
| 1226 | return; |
|---|
| 1227 | } |
|---|
| 1228 | |
|---|
| 1229 | nr = ctl_name - MAXI_SYSCTL_VID1 + 1; |
|---|
| 1230 | |
|---|
| 1231 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1232 | *nrels_mag = 4; |
|---|
| 1233 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1234 | maxi_update_client(client); |
|---|
| 1235 | results[0] = VID_FROM_REG(data->vid_min[nr - 1]); |
|---|
| 1236 | results[1] = VID_FROM_REG(data->vid_max[nr - 1]); |
|---|
| 1237 | results[2] = VID_FROM_REG(data->vid[nr - 1]); |
|---|
| 1238 | *nrels_mag = 3; |
|---|
| 1239 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1240 | #ifndef NOWRITE |
|---|
| 1241 | if (*nrels_mag >= 1) { |
|---|
| 1242 | data->vid_min[nr - 1] = VID_TO_REG(results[0]); |
|---|
| 1243 | maxi_write_value(client, MAXI_REG_VID_MIN(nr), |
|---|
| 1244 | data->vid_min[nr - 1]); |
|---|
| 1245 | } |
|---|
| 1246 | if (*nrels_mag >= 2) { |
|---|
| 1247 | data->vid_max[nr - 1] = VID_TO_REG(results[1]); |
|---|
| 1248 | maxi_write_value(client, MAXI_REG_VID_MAX(nr), |
|---|
| 1249 | data->vid_max[nr - 1]); |
|---|
| 1250 | } |
|---|
| 1251 | #endif |
|---|
| 1252 | } |
|---|
| 1253 | } |
|---|
| 1254 | |
|---|
| 1255 | void maxi99_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1256 | int *nrels_mag, long *results) |
|---|
| 1257 | { |
|---|
| 1258 | struct maxi_data *data = client->data; |
|---|
| 1259 | int nr = ctl_name - MAXI_SYSCTL_VID1 + 1; |
|---|
| 1260 | |
|---|
| 1261 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1262 | *nrels_mag = 4; |
|---|
| 1263 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1264 | maxi99_update_client(client, vid, nr - 1); |
|---|
| 1265 | results[0] = VID99_FROM_REG(nr, data->vid_min[nr - 1]); |
|---|
| 1266 | results[1] = VID99_FROM_REG(nr, data->vid_max[nr - 1]); |
|---|
| 1267 | results[2] = VID99_FROM_REG(nr, data->vid[nr - 1]); |
|---|
| 1268 | *nrels_mag = 3; |
|---|
| 1269 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1270 | #ifndef NOWRITE |
|---|
| 1271 | /* still to do */ |
|---|
| 1272 | if (*nrels_mag >= 1) { |
|---|
| 1273 | data->vid_min[nr - 1] = VID_TO_REG(results[0]); |
|---|
| 1274 | maxi_write_value(client, MAXI_REG_VID_MIN(nr), |
|---|
| 1275 | data->vid_min[nr - 1]); |
|---|
| 1276 | } |
|---|
| 1277 | if (*nrels_mag >= 2) { |
|---|
| 1278 | data->vid_max[nr - 1] = VID_TO_REG(results[1]); |
|---|
| 1279 | maxi_write_value(client, MAXI_REG_VID_MAX(nr), |
|---|
| 1280 | data->vid_max[nr - 1]); |
|---|
| 1281 | } |
|---|
| 1282 | #endif |
|---|
| 1283 | } |
|---|
| 1284 | } |
|---|
| 1285 | |
|---|
| 1286 | void maxi_lcd(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1287 | int *nrels_mag, long *results) |
|---|
| 1288 | { |
|---|
| 1289 | /* Allows writing and reading from LCD display */ |
|---|
| 1290 | |
|---|
| 1291 | struct maxi_data *data = client->data; |
|---|
| 1292 | int nr; |
|---|
| 1293 | |
|---|
| 1294 | if (data->type != nba) |
|---|
| 1295 | return; |
|---|
| 1296 | |
|---|
| 1297 | nr = ctl_name - MAXI_SYSCTL_LCD1 + 1; |
|---|
| 1298 | |
|---|
| 1299 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1300 | *nrels_mag = 0; |
|---|
| 1301 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1302 | results[0] = *((long *) &data->lcd[nr - 1][0]); |
|---|
| 1303 | results[1] = *((long *) &data->lcd[nr - 1][4]); |
|---|
| 1304 | results[2] = *((long *) &data->lcd[nr - 1][8]); |
|---|
| 1305 | results[3] = *((long *) &data->lcd[nr - 1][12]); |
|---|
| 1306 | *nrels_mag = 4; |
|---|
| 1307 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 1308 | /* |
|---|
| 1309 | Writing a string to line 3 of the LCD can be done like: |
|---|
| 1310 | echo -n "Linux MaxiLife" | od -A n -l > \ |
|---|
| 1311 | /proc/sys/dev/sensors/maxilife-nba-i2c-0-14/lcd3 |
|---|
| 1312 | */ |
|---|
| 1313 | if (*nrels_mag >= 1) |
|---|
| 1314 | *((long *) &data->lcd[nr - 1][0]) = results[0]; |
|---|
| 1315 | if (*nrels_mag >= 2) |
|---|
| 1316 | *((long *) &data->lcd[nr - 1][4]) = results[1]; |
|---|
| 1317 | if (*nrels_mag >= 3) |
|---|
| 1318 | *((long *) &data->lcd[nr - 1][8]) = results[2]; |
|---|
| 1319 | if (*nrels_mag >= 4) |
|---|
| 1320 | *((long *) &data->lcd[nr - 1][12]) = results[3]; |
|---|
| 1321 | maxi_write_token_loop(client, MAXI_TOK_LCD(nr - 1), |
|---|
| 1322 | strlen(data->lcd[nr - 1]) + 1, |
|---|
| 1323 | data->lcd[nr - 1]); |
|---|
| 1324 | #if 0 |
|---|
| 1325 | if (*nrels_mag >= 1) |
|---|
| 1326 | printk("nr=%d, result[0] = %.4s\n", nr, |
|---|
| 1327 | (char *) &results[0]); |
|---|
| 1328 | if (*nrels_mag >= 2) |
|---|
| 1329 | printk("nr=%d, result[1] = %.4s\n", nr, |
|---|
| 1330 | (char *) &results[1]); |
|---|
| 1331 | if (*nrels_mag >= 3) |
|---|
| 1332 | printk("nr=%d, result[2] = %.4s\n", nr, |
|---|
| 1333 | (char *) &results[2]); |
|---|
| 1334 | if (*nrels_mag >= 4) |
|---|
| 1335 | printk("nr=%d, result[3] = %.4s\n", nr, |
|---|
| 1336 | (char *) &results[3]); |
|---|
| 1337 | #endif |
|---|
| 1338 | } |
|---|
| 1339 | |
|---|
| 1340 | } |
|---|
| 1341 | |
|---|
| 1342 | void maxi_alarms(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 1343 | int *nrels_mag, long *results) |
|---|
| 1344 | { |
|---|
| 1345 | struct maxi_data *data = client->data; |
|---|
| 1346 | |
|---|
| 1347 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 1348 | *nrels_mag = 0; |
|---|
| 1349 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 1350 | if (data->type == nba) |
|---|
| 1351 | maxi99_update_client(client, alarm, 0); |
|---|
| 1352 | else |
|---|
| 1353 | maxi_update_client(client); |
|---|
| 1354 | results[0] = ALARMS_FROM_REG(data->alarms); |
|---|
| 1355 | *nrels_mag = 1; |
|---|
| 1356 | } |
|---|
| 1357 | } |
|---|
| 1358 | |
|---|
| 1359 | static int __init sm_maxilife_init(void) |
|---|
| 1360 | { |
|---|
| 1361 | printk("maxilife: Version %s (lm_sensors %s (%s))\n", version_str, |
|---|
| 1362 | LM_VERSION, LM_DATE); |
|---|
| 1363 | return i2c_add_driver(&maxi_driver); |
|---|
| 1364 | } |
|---|
| 1365 | |
|---|
| 1366 | static void __exit sm_maxilife_exit(void) |
|---|
| 1367 | { |
|---|
| 1368 | i2c_del_driver(&maxi_driver); |
|---|
| 1369 | } |
|---|
| 1370 | |
|---|
| 1371 | |
|---|
| 1372 | |
|---|
| 1373 | MODULE_AUTHOR("Fons Rademakers <Fons.Rademakers@cern.ch>"); |
|---|
| 1374 | MODULE_DESCRIPTION("HP MaxiLife driver"); |
|---|
| 1375 | MODULE_PARM(maxi_version, "i"); |
|---|
| 1376 | MODULE_PARM_DESC(maxi_version, "MaxiLife firmware version"); |
|---|
| 1377 | |
|---|
| 1378 | module_init(sm_maxilife_init); |
|---|
| 1379 | module_exit(sm_maxilife_exit); |
|---|