| 1 | /* |
|---|
| 2 | lm87.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> |
|---|
| 5 | Philip Edelbrock <phil@netroedge.com> |
|---|
| 6 | Stephen Rousset <stephen.rousset@rocketlogix.com> |
|---|
| 7 | Dan Eaton <dan.eaton@rocketlogix.com> |
|---|
| 8 | |
|---|
| 9 | This program is free software; you can redistribute it and/or modify |
|---|
| 10 | it under the terms of the GNU General Public License as published by |
|---|
| 11 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | (at your option) any later version. |
|---|
| 13 | |
|---|
| 14 | This program is distributed in the hope that it will be useful, |
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | GNU General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU General Public License |
|---|
| 20 | along with this program; if not, write to the Free Software |
|---|
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | #include <linux/version.h> |
|---|
| 26 | #include <linux/module.h> |
|---|
| 27 | #include <linux/malloc.h> |
|---|
| 28 | #include <linux/proc_fs.h> |
|---|
| 29 | #include <linux/ioport.h> |
|---|
| 30 | #include <linux/sysctl.h> |
|---|
| 31 | #include <asm/errno.h> |
|---|
| 32 | #include <asm/io.h> |
|---|
| 33 | #include <linux/types.h> |
|---|
| 34 | #include <linux/i2c.h> |
|---|
| 35 | #include "version.h" |
|---|
| 36 | #include "i2c-isa.h" |
|---|
| 37 | #include "sensors.h" |
|---|
| 38 | #include <linux/init.h> |
|---|
| 39 | |
|---|
| 40 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)) || \ |
|---|
| 41 | (LINUX_VERSION_CODE == KERNEL_VERSION(2,3,0)) |
|---|
| 42 | #define init_MUTEX(s) do { *(s) = MUTEX; } while(0) |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13) |
|---|
| 46 | #define THIS_MODULE NULL |
|---|
| 47 | #endif |
|---|
| 48 | |
|---|
| 49 | /* Addresses to scan */ |
|---|
| 50 | static unsigned short normal_i2c[] = { SENSORS_I2C_END }; |
|---|
| 51 | static unsigned short normal_i2c_range[] = { 0x2c, 0x2f, SENSORS_I2C_END }; |
|---|
| 52 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 53 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 54 | |
|---|
| 55 | /* Insmod parameters */ |
|---|
| 56 | SENSORS_INSMOD_1(lm87); |
|---|
| 57 | |
|---|
| 58 | /* The following is the calculation for the register offset |
|---|
| 59 | * for the monitored items minimum and maximum locations. |
|---|
| 60 | */ |
|---|
| 61 | #define LM87_REG_IN_MAX(nr) (0x2b + (nr) * 2) |
|---|
| 62 | #define LM87_REG_IN_MIN(nr) (0x2c + (nr) * 2) |
|---|
| 63 | #define LM87_REG_IN(nr) (0x20 + (nr)) |
|---|
| 64 | |
|---|
| 65 | #define AIN1 0 |
|---|
| 66 | #define VCCP1 1 |
|---|
| 67 | #define VCCP2 5 |
|---|
| 68 | |
|---|
| 69 | /* Initial limits */ |
|---|
| 70 | |
|---|
| 71 | /* |
|---|
| 72 | * LM87 register definition |
|---|
| 73 | * |
|---|
| 74 | */ |
|---|
| 75 | |
|---|
| 76 | /* The LM87 registers */ |
|---|
| 77 | #define LM87_INT_TEMP_HI_LIMIT_LOCKABLE 0x13 |
|---|
| 78 | #define LM87_EXT_TEMP_HI_LIMIT_LOCKABLE 0x14 |
|---|
| 79 | #define LM87_REG_TEST 0x15 |
|---|
| 80 | #define LM87_REG_CHANNEL_MODE 0x16 |
|---|
| 81 | #define LM87_REG_INT_TEMP_HI_LIMIT 0x17 |
|---|
| 82 | #define LM87_REG_EXT_TEMP_HI_LIMIT 0x18 |
|---|
| 83 | #define LM87_REG_ANALOG_OUT 0x19 |
|---|
| 84 | |
|---|
| 85 | /* These are all read-only */ |
|---|
| 86 | #define LM87_REG_2_5V_EXT_TEMP_2 0x20 /* front ambient for us */ |
|---|
| 87 | #define LM87_REG_VCCP1 0x21 /* CPU core voltage */ |
|---|
| 88 | #define LM87_REG_3_3V 0x22 |
|---|
| 89 | #define LM87_REG_5V 0x23 |
|---|
| 90 | #define LM87_REG_12V 0x24 |
|---|
| 91 | #define LM87_REG_VCCP2 0x25 |
|---|
| 92 | #define LM87_REG_EXT_TEMP_1 0x26 /* CPU temp for us */ |
|---|
| 93 | #define LM87_REG_INT_TEMP 0x27 /* LM87 temp. */ |
|---|
| 94 | #define LM87_REG_FAN1_AIN1 0x28 /* this is AIN: 2.5V monitored */ |
|---|
| 95 | #define LM87_REG_FAN2_AIN2 0x29 |
|---|
| 96 | |
|---|
| 97 | /* These are read/write */ |
|---|
| 98 | #define LM87_REG_2_5V_EXT_TEMP_2_HIGH 0x2B |
|---|
| 99 | #define LM87_REG_2_5V_EXT_TEMP_2_LOW 0x2C |
|---|
| 100 | #define LM87_REG_VCCP1_HIGH 0x2D |
|---|
| 101 | #define LM87_REG_VCCP1_LOW 0x2E |
|---|
| 102 | #define LM87_REG_3_3V_HIGH 0x2F |
|---|
| 103 | #define LM87_REG_3_3V_LOW 0x30 |
|---|
| 104 | #define LM87_REG_5V_HIGH 0x31 |
|---|
| 105 | #define LM87_REG_5V_LOW 0x32 |
|---|
| 106 | #define LM87_REG_12V_HIGH 0x33 |
|---|
| 107 | #define LM87_REG_12V_LOW 0x34 |
|---|
| 108 | #define LM87_REG_VCCP2_HIGH 0x35 |
|---|
| 109 | #define LM87_REG_VCCP2_LOW 0x36 |
|---|
| 110 | #define LM87_REG_EXT_TEMP_1_HIGH 0x37 |
|---|
| 111 | #define LM87_REG_EXT_TEMP_1_LOW 0x38 |
|---|
| 112 | #define LM87_REG_INT_TEMP_HIGH 0x39 |
|---|
| 113 | #define LM87_REG_INT_TEMP_LOW 0x3A |
|---|
| 114 | #define LM87_REG_FAN1_AIN1_LIMIT 0x3B /* 2.5V high limit */ |
|---|
| 115 | #define LM87_REG_FAN2_AIN2_LIMIT 0x3C |
|---|
| 116 | #define LM87_REG_COMPANY_ID 0x3E |
|---|
| 117 | #define LM87_REG_DIE_REV 0x3F |
|---|
| 118 | |
|---|
| 119 | #define LM87_REG_CONFIG 0x40 |
|---|
| 120 | #define LM87_REG_INT1_STAT 0x41 |
|---|
| 121 | #define LM87_REG_INT2_STAT 0x42 |
|---|
| 122 | #define LM87_REG_INT1_MASK 0x43 |
|---|
| 123 | #define LM87_REG_INT2_MASK 0x44 |
|---|
| 124 | #define LM87_REG_CHASSIS_CLEAR 0x46 |
|---|
| 125 | #define LM87_REG_VID_FAN_DIV 0x47 |
|---|
| 126 | #define LM87_REG_VID4 0x49 |
|---|
| 127 | #define LM87_REG_CONFIG_2 0x4A |
|---|
| 128 | #define LM87_REG_INTRPT_STATUS_1_MIRROR 0x4C |
|---|
| 129 | #define LM87_REG_INTRPT_STATUS_2_MIRROR 0x4D |
|---|
| 130 | #define LM87_REG_SMBALERT_NUM_ENABLE 0x80 |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | /* Conversions. Rounding and limit checking is only done on the TO_REG |
|---|
| 135 | variants. Note that you should be a bit careful with which arguments |
|---|
| 136 | these macros are called: arguments may be evaluated more than once. |
|---|
| 137 | Fixing this is just not worth it. */ |
|---|
| 138 | #define IN_TO_REG(val,nr) (SENSORS_LIMIT(((val) & 0xff),0,255)) |
|---|
| 139 | #define IN_FROM_REG(val,nr) (val) |
|---|
| 140 | |
|---|
| 141 | extern inline u8 FAN_TO_REG(long rpm, int div) |
|---|
| 142 | { |
|---|
| 143 | if (rpm == 0) |
|---|
| 144 | return 255; |
|---|
| 145 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
|---|
| 146 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
|---|
| 147 | 254); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | #define FAN_FROM_REG(val,div) ((val)==0?-1:\ |
|---|
| 151 | (val)==255?0:1350000/((div)*(val))) |
|---|
| 152 | |
|---|
| 153 | #define TEMP_FROM_REG(temp) (temp * 10) |
|---|
| 154 | |
|---|
| 155 | #define TEMP_LIMIT_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) |
|---|
| 156 | |
|---|
| 157 | #define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT(((val)<0?(((val)-5)/10):\ |
|---|
| 158 | ((val)+5)/10),0,255) |
|---|
| 159 | #if 0 |
|---|
| 160 | #define TEMP_FROM_REG(temp) \ |
|---|
| 161 | ((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \ |
|---|
| 162 | ((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \ |
|---|
| 163 | |
|---|
| 164 | #define TEMP_LIMIT_FROM_REG(val) (val) |
|---|
| 165 | |
|---|
| 166 | #define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val),0,255) |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | #define ALARMS_FROM_REG(val) (val) |
|---|
| 171 | |
|---|
| 172 | #define DIV_FROM_REG(val) (1 << (val)) |
|---|
| 173 | #define DIV_TO_REG(val) ((val)==1?0:((val)==8?3:((val)==4?2:1))) |
|---|
| 174 | |
|---|
| 175 | #define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\ |
|---|
| 176 | 205-(val)*5) |
|---|
| 177 | |
|---|
| 178 | #define LM87_INIT_IN_0 190 |
|---|
| 179 | #define LM87_INIT_IN_1 190 |
|---|
| 180 | #define LM87_INIT_IN_2 190 |
|---|
| 181 | #define LM87_INIT_IN_3 190 |
|---|
| 182 | #define LM87_INIT_IN_4 190 |
|---|
| 183 | #define LM87_INIT_IN_5 190 |
|---|
| 184 | |
|---|
| 185 | #define LM87_INIT_IN_PERCENTAGE 10 |
|---|
| 186 | |
|---|
| 187 | /********* 2.5V monitoring limits **********/ |
|---|
| 188 | #define LM87_INIT_IN_MIN_0 \ |
|---|
| 189 | (LM87_INIT_IN_0 - ((LM87_INIT_IN_0 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 190 | #define LM87_INIT_IN_MAX_0 \ |
|---|
| 191 | (LM87_INIT_IN_0 + ((LM87_INIT_IN_0 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 192 | |
|---|
| 193 | /********* Vccp1 monitoring limits **********/ |
|---|
| 194 | #define LM87_INIT_IN_MIN_1 \ |
|---|
| 195 | (LM87_INIT_IN_1 - ((LM87_INIT_IN_1 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 196 | #define LM87_INIT_IN_MAX_1 \ |
|---|
| 197 | (LM87_INIT_IN_1 + ((LM87_INIT_IN_1 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 198 | |
|---|
| 199 | /********* 3.3V monitoring limits **********/ |
|---|
| 200 | #define LM87_INIT_IN_MIN_2 \ |
|---|
| 201 | (LM87_INIT_IN_2 - ((LM87_INIT_IN_2 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 202 | #define LM87_INIT_IN_MAX_2 \ |
|---|
| 203 | (LM87_INIT_IN_2 + ((LM87_INIT_IN_2 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 204 | |
|---|
| 205 | /********* 5V monitoring limits **********/ |
|---|
| 206 | #define LM87_INIT_IN_MIN_3 \ |
|---|
| 207 | (LM87_INIT_IN_3 - ((LM87_INIT_IN_3 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 208 | #define LM87_INIT_IN_MAX_3 \ |
|---|
| 209 | (LM87_INIT_IN_3 + ((LM87_INIT_IN_3 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 210 | |
|---|
| 211 | /********* 12V monitoring limits **********/ |
|---|
| 212 | #define LM87_INIT_IN_MIN_4 \ |
|---|
| 213 | (LM87_INIT_IN_4 - ((LM87_INIT_IN_4 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 214 | #define LM87_INIT_IN_MAX_4 \ |
|---|
| 215 | (LM87_INIT_IN_4 + ((LM87_INIT_IN_4 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 216 | |
|---|
| 217 | /********* Vccp2 monitoring limits **********/ |
|---|
| 218 | #define LM87_INIT_IN_MIN_5 \ |
|---|
| 219 | (LM87_INIT_IN_5 - ((LM87_INIT_IN_5 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 220 | #define LM87_INIT_IN_MAX_5 \ |
|---|
| 221 | (LM87_INIT_IN_5 + ((LM87_INIT_IN_5 * LM87_INIT_IN_PERCENTAGE) / 100)) |
|---|
| 222 | |
|---|
| 223 | #define LM87_INIT_FAN_MIN 3000 |
|---|
| 224 | |
|---|
| 225 | #define LM87_INIT_EXT_TEMP_MAX 600 |
|---|
| 226 | #define LM87_INIT_EXT_TEMP_MIN 50 |
|---|
| 227 | #define LM87_INIT_INT_TEMP_MAX 600 |
|---|
| 228 | #define LM87_INIT_INT_TEMP_MIN 50 |
|---|
| 229 | |
|---|
| 230 | #ifdef MODULE |
|---|
| 231 | extern int init_module(void); |
|---|
| 232 | extern int cleanup_module(void); |
|---|
| 233 | #endif /* MODULE */ |
|---|
| 234 | |
|---|
| 235 | /* For each registered LM87, we need to keep some data in memory. That |
|---|
| 236 | data is pointed to by LM87_list[NR]->data. The structure itself is |
|---|
| 237 | dynamically allocated, at the same time when a new LM87 client is |
|---|
| 238 | allocated. */ |
|---|
| 239 | struct lm87_data { |
|---|
| 240 | int sysctl_id; |
|---|
| 241 | enum chips type; |
|---|
| 242 | |
|---|
| 243 | struct semaphore update_lock; |
|---|
| 244 | char valid; /* !=0 if following fields are valid */ |
|---|
| 245 | unsigned long last_updated; /* In jiffies */ |
|---|
| 246 | |
|---|
| 247 | u8 in[6]; /* Register value */ |
|---|
| 248 | u8 in_max[6]; /* Register value */ |
|---|
| 249 | u8 in_min[6]; /* Register value */ |
|---|
| 250 | u8 fan[2]; /* Register value */ |
|---|
| 251 | u8 fan_min[2]; /* Register value */ |
|---|
| 252 | u8 fan_div[2]; /* Register encoding, shifted right */ |
|---|
| 253 | int front_amb_temp; /* Temp, shifted right */ |
|---|
| 254 | int cpu_temp; /* Temp, shifted right */ |
|---|
| 255 | int int_temp; /* Temp, shifted right */ |
|---|
| 256 | u8 cpu_temp_max; /* Register value */ |
|---|
| 257 | u8 cpu_temp_min; /* Register value */ |
|---|
| 258 | u8 front_amb_temp_max; /* Register value */ |
|---|
| 259 | u8 front_amb_temp_min; /* Register value */ |
|---|
| 260 | u8 int_temp_max; /* Register value */ |
|---|
| 261 | u8 int_temp_min; /* Register value */ |
|---|
| 262 | u16 alarms; /* Register encoding, combined */ |
|---|
| 263 | u8 analog_out; /* Register value */ |
|---|
| 264 | u8 vid; /* Register value combined */ |
|---|
| 265 | }; |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | #ifdef MODULE |
|---|
| 269 | static |
|---|
| 270 | #else |
|---|
| 271 | extern |
|---|
| 272 | #endif |
|---|
| 273 | int __init sensors_lm87_init(void); |
|---|
| 274 | static int __init lm87_cleanup(void); |
|---|
| 275 | |
|---|
| 276 | static int lm87_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 277 | static int lm87_detect(struct i2c_adapter *adapter, int address, |
|---|
| 278 | unsigned short flags, int kind); |
|---|
| 279 | static int lm87_detach_client(struct i2c_client *client); |
|---|
| 280 | static int lm87_command(struct i2c_client *client, unsigned int cmd, |
|---|
| 281 | void *arg); |
|---|
| 282 | static void lm87_inc_use(struct i2c_client *client); |
|---|
| 283 | static void lm87_dec_use(struct i2c_client *client); |
|---|
| 284 | |
|---|
| 285 | static int lm87_read_value(struct i2c_client *client, u8 register); |
|---|
| 286 | static int lm87_write_value(struct i2c_client *client, u8 register, |
|---|
| 287 | u8 value); |
|---|
| 288 | static void lm87_update_client(struct i2c_client *client); |
|---|
| 289 | static void lm87_init_client(struct i2c_client *client); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | static void lm87_in(struct i2c_client *client, int operation, |
|---|
| 293 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 294 | static void lm87_fan(struct i2c_client *client, int operation, |
|---|
| 295 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 296 | static void lm87_temp(struct i2c_client *client, int operation, |
|---|
| 297 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 298 | static void lm87_alarms(struct i2c_client *client, int operation, |
|---|
| 299 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 300 | static void lm87_fan_div(struct i2c_client *client, int operation, |
|---|
| 301 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 302 | static void lm87_analog_out(struct i2c_client *client, int operation, |
|---|
| 303 | int ctl_name, int *nrels_mag, |
|---|
| 304 | long *results); |
|---|
| 305 | static void lm87_vid(struct i2c_client *client, int operation, |
|---|
| 306 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 307 | |
|---|
| 308 | /* I choose here for semi-static LM87 allocation. Complete dynamic |
|---|
| 309 | allocation could also be used; the code needed for this would probably |
|---|
| 310 | take more memory than the datastructure takes now. */ |
|---|
| 311 | static int lm87_id = 0; |
|---|
| 312 | |
|---|
| 313 | static struct i2c_driver lm87_driver = { |
|---|
| 314 | /* name */ "LM87 sensor driver", |
|---|
| 315 | /* id */ I2C_DRIVERID_LM87, |
|---|
| 316 | /* flags */ I2C_DF_NOTIFY, |
|---|
| 317 | /* attach_adapter */ &lm87_attach_adapter, |
|---|
| 318 | /* detach_client */ &lm87_detach_client, |
|---|
| 319 | /* command */ &lm87_command, |
|---|
| 320 | /* inc_use */ &lm87_inc_use, |
|---|
| 321 | /* dec_use */ &lm87_dec_use |
|---|
| 322 | }; |
|---|
| 323 | |
|---|
| 324 | /* Used by lm87_init/cleanup */ |
|---|
| 325 | static int __initdata lm87_initialized = 0; |
|---|
| 326 | |
|---|
| 327 | /* The /proc/sys entries */ |
|---|
| 328 | /* These files are created for each detected LM87. This is just a template; |
|---|
| 329 | though at first sight, you might think we could use a statically |
|---|
| 330 | allocated list, we need some way to get back to the parent - which |
|---|
| 331 | is done through one of the 'extra' fields which are initialized |
|---|
| 332 | when a new copy is allocated. */ |
|---|
| 333 | |
|---|
| 334 | static ctl_table lm87_dir_table_template[] = { |
|---|
| 335 | {LM87_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 336 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 337 | {LM87_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 338 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 339 | {LM87_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 340 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 341 | {LM87_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 342 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 343 | {LM87_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 344 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 345 | {LM87_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 346 | &sensors_sysctl_real, NULL, &lm87_in}, |
|---|
| 347 | {LM87_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 348 | &sensors_sysctl_real, NULL, &lm87_fan}, |
|---|
| 349 | {LM87_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 350 | &sensors_sysctl_real, NULL, &lm87_fan}, |
|---|
| 351 | {LM87_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 352 | &sensors_sysctl_real, NULL, &lm87_temp}, |
|---|
| 353 | {LM87_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, |
|---|
| 354 | &sensors_sysctl_real, NULL, &lm87_temp}, |
|---|
| 355 | {LM87_SYSCTL_TEMP3, "temp3", NULL, |
|---|
| 356 | 0, 0644, NULL, &sensors_proc_real, |
|---|
| 357 | &sensors_sysctl_real, NULL, &lm87_temp}, |
|---|
| 358 | {LM87_SYSCTL_FAN_DIV, "fan_div", NULL, |
|---|
| 359 | 0, 0644, NULL, &sensors_proc_real, |
|---|
| 360 | &sensors_sysctl_real, NULL, &lm87_fan_div}, |
|---|
| 361 | {LM87_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, |
|---|
| 362 | &sensors_sysctl_real, NULL, &lm87_alarms}, |
|---|
| 363 | {LM87_SYSCTL_ANALOG_OUT, "analog_out", NULL, |
|---|
| 364 | 0, 0644, NULL, &sensors_proc_real, |
|---|
| 365 | &sensors_sysctl_real, NULL, &lm87_analog_out}, |
|---|
| 366 | {LM87_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, |
|---|
| 367 | &sensors_sysctl_real, NULL, &lm87_vid}, |
|---|
| 368 | {0} |
|---|
| 369 | }; |
|---|
| 370 | |
|---|
| 371 | int lm87_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 372 | { |
|---|
| 373 | int error; |
|---|
| 374 | struct i2c_client_address_data lm87_client_data; |
|---|
| 375 | |
|---|
| 376 | lm87_client_data.normal_i2c = addr_data.normal_i2c; |
|---|
| 377 | lm87_client_data.normal_i2c_range = addr_data.normal_i2c_range; |
|---|
| 378 | lm87_client_data.probe = addr_data.probe; |
|---|
| 379 | lm87_client_data.probe_range = addr_data.probe_range; |
|---|
| 380 | lm87_client_data.ignore = addr_data.ignore; |
|---|
| 381 | lm87_client_data.ignore_range = addr_data.ignore_range; |
|---|
| 382 | lm87_client_data.force = addr_data.forces->force; |
|---|
| 383 | |
|---|
| 384 | error = i2c_probe(adapter, &lm87_client_data, lm87_detect); |
|---|
| 385 | sensors_detect(adapter, &addr_data, lm87_detect); |
|---|
| 386 | |
|---|
| 387 | return error; |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | static int lm87_detect(struct i2c_adapter *adapter, int address, |
|---|
| 391 | unsigned short flags, int kind) |
|---|
| 392 | { |
|---|
| 393 | int i; |
|---|
| 394 | struct i2c_client *new_client; |
|---|
| 395 | struct lm87_data *data; |
|---|
| 396 | int err = 0; |
|---|
| 397 | const char *type_name = ""; |
|---|
| 398 | const char *client_name = ""; |
|---|
| 399 | |
|---|
| 400 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
|---|
| 401 | goto ERROR0; |
|---|
| 402 | |
|---|
| 403 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 404 | client structure, even though we cannot fill it completely yet. |
|---|
| 405 | But it allows us to access LM87_{read,write}_value. */ |
|---|
| 406 | |
|---|
| 407 | if (!(new_client = kmalloc(sizeof(struct i2c_client) + |
|---|
| 408 | sizeof(struct lm87_data), |
|---|
| 409 | GFP_KERNEL))) { |
|---|
| 410 | err = -ENOMEM; |
|---|
| 411 | goto ERROR0; |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | data = (struct lm87_data *) (new_client + 1); |
|---|
| 415 | new_client->addr = address; |
|---|
| 416 | new_client->data = data; |
|---|
| 417 | new_client->adapter = adapter; |
|---|
| 418 | new_client->driver = &lm87_driver; |
|---|
| 419 | new_client->flags = 0; |
|---|
| 420 | |
|---|
| 421 | /* Now, we do the remaining detection. */ |
|---|
| 422 | |
|---|
| 423 | if (kind < 0) { |
|---|
| 424 | if (((lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80) |
|---|
| 425 | != 0x00) || |
|---|
| 426 | (lm87_read_value(new_client, LM87_REG_COMPANY_ID) != 0x02)) |
|---|
| 427 | goto ERROR1; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | /* Fill in the remaining client fields and put into the global list */ |
|---|
| 431 | type_name = "lm87"; |
|---|
| 432 | client_name = "LM87 chip"; |
|---|
| 433 | strcpy(new_client->name, client_name); |
|---|
| 434 | data->type = kind; |
|---|
| 435 | |
|---|
| 436 | new_client->id = lm87_id++; |
|---|
| 437 | data->valid = 0; |
|---|
| 438 | init_MUTEX(&data->update_lock); |
|---|
| 439 | |
|---|
| 440 | /* Tell the I2C layer a new client has arrived */ |
|---|
| 441 | if ((err = i2c_attach_client(new_client))) |
|---|
| 442 | goto ERROR3; |
|---|
| 443 | |
|---|
| 444 | /* Register a new directory entry with module sensors */ |
|---|
| 445 | if ((i = sensors_register_entry(new_client, |
|---|
| 446 | type_name, |
|---|
| 447 | lm87_dir_table_template, |
|---|
| 448 | THIS_MODULE)) < 0) { |
|---|
| 449 | err = i; |
|---|
| 450 | goto ERROR4; |
|---|
| 451 | } |
|---|
| 452 | data->sysctl_id = i; |
|---|
| 453 | |
|---|
| 454 | /* Initialize the LM87 chip */ |
|---|
| 455 | lm87_init_client(new_client); |
|---|
| 456 | return 0; |
|---|
| 457 | |
|---|
| 458 | /* OK, this is not exactly good programming practice, usually. But it is |
|---|
| 459 | very code-efficient in this case. */ |
|---|
| 460 | |
|---|
| 461 | ERROR4: |
|---|
| 462 | i2c_detach_client(new_client); |
|---|
| 463 | ERROR3: |
|---|
| 464 | ERROR1: |
|---|
| 465 | kfree(new_client); |
|---|
| 466 | ERROR0: |
|---|
| 467 | return err; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | int lm87_detach_client(struct i2c_client *client) |
|---|
| 471 | { |
|---|
| 472 | int err; |
|---|
| 473 | |
|---|
| 474 | sensors_deregister_entry(((struct lm87_data *) (client->data))-> |
|---|
| 475 | sysctl_id); |
|---|
| 476 | |
|---|
| 477 | if ((err = i2c_detach_client(client))) { |
|---|
| 478 | printk |
|---|
| 479 | ("lm87.o: Client deregistration failed, client not detached.\n"); |
|---|
| 480 | return err; |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | kfree(client); |
|---|
| 484 | |
|---|
| 485 | return 0; |
|---|
| 486 | |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | /* No commands defined yet */ |
|---|
| 490 | int lm87_command(struct i2c_client *client, unsigned int cmd, void *arg) |
|---|
| 491 | { |
|---|
| 492 | return 0; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | void lm87_inc_use(struct i2c_client *client) |
|---|
| 496 | { |
|---|
| 497 | #ifdef MODULE |
|---|
| 498 | MOD_INC_USE_COUNT; |
|---|
| 499 | #endif |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | void lm87_dec_use(struct i2c_client *client) |
|---|
| 503 | { |
|---|
| 504 | #ifdef MODULE |
|---|
| 505 | MOD_DEC_USE_COUNT; |
|---|
| 506 | #endif |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | int lm87_read_value(struct i2c_client *client, u8 reg) |
|---|
| 510 | { |
|---|
| 511 | return 0xFF & i2c_smbus_read_byte_data(client, reg); |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | int lm87_write_value(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 515 | { |
|---|
| 516 | return i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | /* Called when we have found a new LM87. It should set limits, etc. */ |
|---|
| 520 | void lm87_init_client(struct i2c_client *client) |
|---|
| 521 | { |
|---|
| 522 | /* Reset all except Watchdog values and last conversion values |
|---|
| 523 | This sets fan-divs to 2, among others. This makes most other |
|---|
| 524 | initializations unnecessary */ |
|---|
| 525 | lm87_write_value(client, LM87_REG_CONFIG, 0x80); |
|---|
| 526 | |
|---|
| 527 | /* Setup Channel Mode register for configuration of monitoring |
|---|
| 528 | * bit 0 - Configures Fan 1/AIN 1 input (1 = AIN) |
|---|
| 529 | * bit 2 - Configures 2.5V/D2 input (1 = 2nd Therm.) |
|---|
| 530 | */ |
|---|
| 531 | lm87_write_value(client, LM87_REG_CHANNEL_MODE, 0x05); |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | lm87_write_value(client, LM87_REG_IN_MIN(1), |
|---|
| 535 | IN_TO_REG(LM87_INIT_IN_MIN_1, 1)); |
|---|
| 536 | lm87_write_value(client, LM87_REG_IN_MAX(1), |
|---|
| 537 | IN_TO_REG(LM87_INIT_IN_MAX_1, 1)); |
|---|
| 538 | lm87_write_value(client, LM87_REG_IN_MIN(2), |
|---|
| 539 | IN_TO_REG(LM87_INIT_IN_MIN_2, 2)); |
|---|
| 540 | lm87_write_value(client, LM87_REG_IN_MAX(2), |
|---|
| 541 | IN_TO_REG(LM87_INIT_IN_MAX_2, 2)); |
|---|
| 542 | lm87_write_value(client, LM87_REG_IN_MIN(3), |
|---|
| 543 | IN_TO_REG(LM87_INIT_IN_MIN_3, 3)); |
|---|
| 544 | lm87_write_value(client, LM87_REG_IN_MAX(3), |
|---|
| 545 | IN_TO_REG(LM87_INIT_IN_MAX_3, 3)); |
|---|
| 546 | lm87_write_value(client, LM87_REG_IN_MIN(4), |
|---|
| 547 | IN_TO_REG(LM87_INIT_IN_MIN_4, 4)); |
|---|
| 548 | lm87_write_value(client, LM87_REG_IN_MAX(4), |
|---|
| 549 | IN_TO_REG(LM87_INIT_IN_MAX_4, 4)); |
|---|
| 550 | lm87_write_value(client, LM87_REG_IN_MIN(5), |
|---|
| 551 | IN_TO_REG(LM87_INIT_IN_MIN_5, 5)); |
|---|
| 552 | lm87_write_value(client, LM87_REG_IN_MAX(5), |
|---|
| 553 | IN_TO_REG(LM87_INIT_IN_MAX_5, 5)); |
|---|
| 554 | |
|---|
| 555 | lm87_write_value(client, LM87_REG_EXT_TEMP_1_HIGH, |
|---|
| 556 | TEMP_LIMIT_TO_REG(LM87_INIT_EXT_TEMP_MAX)); |
|---|
| 557 | lm87_write_value(client, LM87_REG_EXT_TEMP_1_LOW, |
|---|
| 558 | TEMP_LIMIT_TO_REG(LM87_INIT_EXT_TEMP_MIN)); |
|---|
| 559 | lm87_write_value(client, LM87_REG_2_5V_EXT_TEMP_2_HIGH, |
|---|
| 560 | TEMP_LIMIT_TO_REG(LM87_INIT_EXT_TEMP_MAX)); |
|---|
| 561 | lm87_write_value(client, LM87_REG_2_5V_EXT_TEMP_2_LOW, |
|---|
| 562 | TEMP_LIMIT_TO_REG(LM87_INIT_EXT_TEMP_MIN)); |
|---|
| 563 | lm87_write_value(client, LM87_REG_INT_TEMP_HIGH, |
|---|
| 564 | TEMP_LIMIT_TO_REG(LM87_INIT_INT_TEMP_MAX)); |
|---|
| 565 | lm87_write_value(client, LM87_REG_INT_TEMP_LOW, |
|---|
| 566 | TEMP_LIMIT_TO_REG(LM87_INIT_INT_TEMP_MIN)); |
|---|
| 567 | |
|---|
| 568 | lm87_write_value(client, LM87_REG_FAN1_AIN1_LIMIT, |
|---|
| 569 | IN_TO_REG(LM87_INIT_IN_MAX_0, 0)); |
|---|
| 570 | |
|---|
| 571 | lm87_write_value(client, LM87_REG_FAN2_AIN2_LIMIT, |
|---|
| 572 | FAN_TO_REG(LM87_INIT_FAN_MIN, 2)); |
|---|
| 573 | |
|---|
| 574 | /* Start monitoring */ |
|---|
| 575 | lm87_write_value(client, LM87_REG_CONFIG, 0x01); |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | void lm87_update_client(struct i2c_client *client) |
|---|
| 579 | { |
|---|
| 580 | struct lm87_data *data = client->data; |
|---|
| 581 | u8 i; |
|---|
| 582 | |
|---|
| 583 | down(&data->update_lock); |
|---|
| 584 | |
|---|
| 585 | if ((jiffies - data->last_updated > HZ) || /* 1 sec cache */ |
|---|
| 586 | (jiffies < data->last_updated) || |
|---|
| 587 | !data->valid) { |
|---|
| 588 | |
|---|
| 589 | #ifdef DEBUG |
|---|
| 590 | printk("Starting LM87 update\n"); |
|---|
| 591 | #endif |
|---|
| 592 | for (i = 0; i <= 5; i++) { |
|---|
| 593 | /* Since we are using AIN 1 as our 2.5V monitoring, need to |
|---|
| 594 | * accomodate with a hardcode |
|---|
| 595 | * register address and we only get |
|---|
| 596 | * to look at one threshold. |
|---|
| 597 | */ |
|---|
| 598 | if (i == 0) { |
|---|
| 599 | data->in[i] = |
|---|
| 600 | lm87_read_value(client, LM87_REG_FAN1_AIN1); |
|---|
| 601 | data->in_min[i] = 0; |
|---|
| 602 | data->in_max[i] = |
|---|
| 603 | lm87_read_value(client, LM87_REG_FAN1_AIN1_LIMIT); |
|---|
| 604 | } |
|---|
| 605 | else { |
|---|
| 606 | data->in[i] = |
|---|
| 607 | lm87_read_value(client, LM87_REG_IN(i)); |
|---|
| 608 | data->in_min[i] = |
|---|
| 609 | lm87_read_value(client, |
|---|
| 610 | LM87_REG_IN_MIN(i)); |
|---|
| 611 | data->in_max[i] = |
|---|
| 612 | lm87_read_value(client, |
|---|
| 613 | LM87_REG_IN_MAX(i)); |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | data->fan[0] = |
|---|
| 618 | lm87_read_value(client, LM87_REG_FAN1_AIN1); |
|---|
| 619 | data->fan_min[0] = |
|---|
| 620 | lm87_read_value(client, LM87_REG_FAN1_AIN1_LIMIT); |
|---|
| 621 | data->fan[1] = |
|---|
| 622 | lm87_read_value(client, LM87_REG_FAN2_AIN2); |
|---|
| 623 | data->fan_min[1] = |
|---|
| 624 | lm87_read_value(client, LM87_REG_FAN2_AIN2_LIMIT); |
|---|
| 625 | |
|---|
| 626 | data->front_amb_temp = |
|---|
| 627 | lm87_read_value(client, LM87_REG_2_5V_EXT_TEMP_2); |
|---|
| 628 | data->cpu_temp = |
|---|
| 629 | lm87_read_value(client, LM87_REG_EXT_TEMP_1); |
|---|
| 630 | data->int_temp = |
|---|
| 631 | lm87_read_value(client, LM87_REG_INT_TEMP); |
|---|
| 632 | |
|---|
| 633 | data->front_amb_temp_max = |
|---|
| 634 | lm87_read_value(client, LM87_REG_2_5V_EXT_TEMP_2_HIGH); |
|---|
| 635 | data->front_amb_temp_min = |
|---|
| 636 | lm87_read_value(client, LM87_REG_2_5V_EXT_TEMP_2_LOW); |
|---|
| 637 | |
|---|
| 638 | data->cpu_temp_max = |
|---|
| 639 | lm87_read_value(client, LM87_REG_EXT_TEMP_1_HIGH); |
|---|
| 640 | data->cpu_temp_min = |
|---|
| 641 | lm87_read_value(client, LM87_REG_EXT_TEMP_1_LOW); |
|---|
| 642 | |
|---|
| 643 | data->int_temp_max = |
|---|
| 644 | lm87_read_value(client, LM87_REG_INT_TEMP_HIGH); |
|---|
| 645 | data->int_temp_min = |
|---|
| 646 | lm87_read_value(client, LM87_REG_INT_TEMP_LOW); |
|---|
| 647 | |
|---|
| 648 | i = lm87_read_value(client, LM87_REG_VID_FAN_DIV); |
|---|
| 649 | data->fan_div[0] = (i >> 4) & 0x03; |
|---|
| 650 | data->fan_div[1] = (i >> 6) & 0x03; |
|---|
| 651 | data->vid = i & 0x0f; |
|---|
| 652 | data->vid |= |
|---|
| 653 | (lm87_read_value(client, LM87_REG_VID4) & 0x01) |
|---|
| 654 | << 4; |
|---|
| 655 | |
|---|
| 656 | data->alarms = |
|---|
| 657 | lm87_read_value(client, |
|---|
| 658 | LM87_REG_INT1_STAT) + |
|---|
| 659 | (lm87_read_value(client, LM87_REG_INT2_STAT) << |
|---|
| 660 | 8); |
|---|
| 661 | data->analog_out = |
|---|
| 662 | lm87_read_value(client, LM87_REG_ANALOG_OUT); |
|---|
| 663 | data->last_updated = jiffies; |
|---|
| 664 | data->valid = 1; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | up(&data->update_lock); |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | /* The next few functions are the call-back functions of the /proc/sys and |
|---|
| 672 | sysctl files. Which function is used is defined in the ctl_table in |
|---|
| 673 | the extra1 field. |
|---|
| 674 | Each function must return the magnitude (power of 10 to divide the date |
|---|
| 675 | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
|---|
| 676 | put a maximum of *nrels elements in results reflecting the data of this |
|---|
| 677 | file, and set *nrels to the number it actually put in it, if operation== |
|---|
| 678 | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
|---|
| 679 | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
|---|
| 680 | Note that on SENSORS_PROC_REAL_READ, I do not check whether results is |
|---|
| 681 | large enough (by checking the incoming value of *nrels). This is not very |
|---|
| 682 | good practice, but as long as you put less than about 5 values in results, |
|---|
| 683 | you can assume it is large enough. */ |
|---|
| 684 | void lm87_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 685 | int *nrels_mag, long *results) |
|---|
| 686 | { |
|---|
| 687 | |
|---|
| 688 | /************************************************************ |
|---|
| 689 | * These values represent 2.5V, Vccp1, 3.3V, 5V, 12V & Vccp2 |
|---|
| 690 | * The 2.5V is 50% sampled for our application, so check |
|---|
| 691 | * against 1.25V value. |
|---|
| 692 | ************************************************************/ |
|---|
| 693 | int scales[6] = { 260, 200, 344, 520, 1250, 260 }; |
|---|
| 694 | |
|---|
| 695 | struct lm87_data *data = client->data; |
|---|
| 696 | int nr = ctl_name - LM87_SYSCTL_IN0; |
|---|
| 697 | |
|---|
| 698 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 699 | *nrels_mag = 2; |
|---|
| 700 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 701 | lm87_update_client(client); |
|---|
| 702 | |
|---|
| 703 | results[0] = |
|---|
| 704 | IN_FROM_REG(data->in_min[nr], nr) * scales[nr] / 192; |
|---|
| 705 | results[1] = |
|---|
| 706 | IN_FROM_REG(data->in_max[nr], nr) * scales[nr] / 192; |
|---|
| 707 | |
|---|
| 708 | if (nr == AIN1) { |
|---|
| 709 | results[2] = ((data->in[nr] * 10) * 98) / 1000; |
|---|
| 710 | } |
|---|
| 711 | else if (nr == VCCP1 || nr == VCCP2) { |
|---|
| 712 | results[2] = ((data->in[nr] * 10) * 141) / 1000; |
|---|
| 713 | } |
|---|
| 714 | else { |
|---|
| 715 | results[2] = |
|---|
| 716 | IN_FROM_REG(data->in[nr], nr) * scales[nr] / 192; |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| 719 | *nrels_mag = 3; |
|---|
| 720 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 721 | if (*nrels_mag >= 1) { |
|---|
| 722 | data->in_min[nr] = |
|---|
| 723 | IN_TO_REG((results[0] * 192) / scales[nr], nr); |
|---|
| 724 | lm87_write_value(client, LM87_REG_IN_MIN(nr), |
|---|
| 725 | data->in_min[nr]); |
|---|
| 726 | } |
|---|
| 727 | if (*nrels_mag >= 2) { |
|---|
| 728 | data->in_max[nr] = |
|---|
| 729 | IN_TO_REG((results[1] * 192) / scales[nr], nr); |
|---|
| 730 | lm87_write_value(client, LM87_REG_IN_MAX(nr), |
|---|
| 731 | data->in_max[nr]); |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | void lm87_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 737 | int *nrels_mag, long *results) |
|---|
| 738 | { |
|---|
| 739 | struct lm87_data *data = client->data; |
|---|
| 740 | int nr = ctl_name - LM87_SYSCTL_FAN1 + 1; |
|---|
| 741 | |
|---|
| 742 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 743 | *nrels_mag = 0; |
|---|
| 744 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 745 | lm87_update_client(client); |
|---|
| 746 | results[0] = FAN_FROM_REG(data->fan_min[nr-1], |
|---|
| 747 | DIV_FROM_REG(data->fan_div[nr-1])); |
|---|
| 748 | results[1] = FAN_FROM_REG(data->fan[nr-1], |
|---|
| 749 | DIV_FROM_REG(data->fan_div[nr-1])); |
|---|
| 750 | *nrels_mag = 2; |
|---|
| 751 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 752 | if (*nrels_mag >= 0) { |
|---|
| 753 | data->fan_min[nr-1] = FAN_TO_REG(results[0], |
|---|
| 754 | DIV_FROM_REG |
|---|
| 755 | (data->fan_div[nr-1])); |
|---|
| 756 | lm87_write_value(client, LM87_REG_FAN2_AIN2_LIMIT, |
|---|
| 757 | data->fan_min[nr-1]); |
|---|
| 758 | } |
|---|
| 759 | } |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | void lm87_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 764 | int *nrels_mag, long *results) |
|---|
| 765 | { |
|---|
| 766 | struct lm87_data *data = client->data; |
|---|
| 767 | |
|---|
| 768 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 769 | *nrels_mag = 1; |
|---|
| 770 | else if (operation == SENSORS_PROC_REAL_READ) |
|---|
| 771 | { |
|---|
| 772 | lm87_update_client(client); |
|---|
| 773 | |
|---|
| 774 | /* find out which temp. is being requested */ |
|---|
| 775 | if (ctl_name == LM87_SYSCTL_TEMP3) |
|---|
| 776 | { |
|---|
| 777 | results[0] = TEMP_LIMIT_FROM_REG(data->front_amb_temp_max); |
|---|
| 778 | results[1] = TEMP_LIMIT_FROM_REG(data->front_amb_temp_min); |
|---|
| 779 | results[2] = TEMP_FROM_REG(data->front_amb_temp); |
|---|
| 780 | } |
|---|
| 781 | else if(ctl_name == LM87_SYSCTL_TEMP2) |
|---|
| 782 | { |
|---|
| 783 | results[0] = TEMP_LIMIT_FROM_REG(data->cpu_temp_max); |
|---|
| 784 | results[1] = TEMP_LIMIT_FROM_REG(data->cpu_temp_min); |
|---|
| 785 | results[2] = TEMP_FROM_REG(data->cpu_temp); |
|---|
| 786 | } |
|---|
| 787 | else if(ctl_name == LM87_SYSCTL_TEMP1) |
|---|
| 788 | { |
|---|
| 789 | results[0] = TEMP_LIMIT_FROM_REG(data->int_temp_max); |
|---|
| 790 | results[1] = TEMP_LIMIT_FROM_REG(data->int_temp_min); |
|---|
| 791 | results[2] = TEMP_FROM_REG(data->int_temp); |
|---|
| 792 | } |
|---|
| 793 | *nrels_mag = 3; |
|---|
| 794 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 795 | if (*nrels_mag >= 1) { |
|---|
| 796 | if (ctl_name == LM87_SYSCTL_TEMP3) { |
|---|
| 797 | data->front_amb_temp_max = |
|---|
| 798 | TEMP_LIMIT_TO_REG(results[0]); |
|---|
| 799 | lm87_write_value(client, LM87_REG_2_5V_EXT_TEMP_2_HIGH, |
|---|
| 800 | data->front_amb_temp_max); |
|---|
| 801 | } |
|---|
| 802 | if (ctl_name == LM87_SYSCTL_TEMP2) { |
|---|
| 803 | data->cpu_temp_max = TEMP_LIMIT_TO_REG(results[0]); |
|---|
| 804 | lm87_write_value(client, LM87_REG_EXT_TEMP_1_HIGH, |
|---|
| 805 | data->int_temp_max); |
|---|
| 806 | } |
|---|
| 807 | if (ctl_name == LM87_SYSCTL_TEMP1) { |
|---|
| 808 | data->int_temp_max = TEMP_LIMIT_TO_REG(results[0]); |
|---|
| 809 | lm87_write_value(client, LM87_REG_INT_TEMP_HIGH, |
|---|
| 810 | data->int_temp_max); |
|---|
| 811 | } |
|---|
| 812 | } |
|---|
| 813 | if (*nrels_mag >= 2) { |
|---|
| 814 | if (ctl_name == LM87_SYSCTL_TEMP3) { |
|---|
| 815 | data->front_amb_temp_min = |
|---|
| 816 | TEMP_LIMIT_TO_REG(results[0]); |
|---|
| 817 | lm87_write_value(client, LM87_REG_2_5V_EXT_TEMP_2_LOW, |
|---|
| 818 | data->front_amb_temp_min); |
|---|
| 819 | } |
|---|
| 820 | if (ctl_name == LM87_SYSCTL_TEMP2) { |
|---|
| 821 | data->cpu_temp_min = TEMP_LIMIT_TO_REG(results[0]); |
|---|
| 822 | lm87_write_value(client, LM87_REG_EXT_TEMP_1_LOW, |
|---|
| 823 | data->int_temp_min); |
|---|
| 824 | } |
|---|
| 825 | if (ctl_name == LM87_SYSCTL_TEMP1) { |
|---|
| 826 | data->int_temp_min = TEMP_LIMIT_TO_REG(results[1]); |
|---|
| 827 | lm87_write_value(client, LM87_REG_INT_TEMP_LOW, |
|---|
| 828 | data->int_temp_min); |
|---|
| 829 | } |
|---|
| 830 | } |
|---|
| 831 | } |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | void lm87_alarms(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 835 | int *nrels_mag, long *results) |
|---|
| 836 | { |
|---|
| 837 | struct lm87_data *data = client->data; |
|---|
| 838 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 839 | *nrels_mag = 0; |
|---|
| 840 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 841 | lm87_update_client(client); |
|---|
| 842 | results[0] = ALARMS_FROM_REG(data->alarms); |
|---|
| 843 | *nrels_mag = 1; |
|---|
| 844 | } |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | void lm87_fan_div(struct i2c_client *client, int operation, |
|---|
| 848 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 849 | { |
|---|
| 850 | struct lm87_data *data = client->data; |
|---|
| 851 | int old; |
|---|
| 852 | |
|---|
| 853 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 854 | *nrels_mag = 0; |
|---|
| 855 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 856 | lm87_update_client(client); |
|---|
| 857 | results[0] = DIV_FROM_REG(data->fan_div[0]); |
|---|
| 858 | results[1] = DIV_FROM_REG(data->fan_div[1]); |
|---|
| 859 | *nrels_mag = 2; |
|---|
| 860 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 861 | old = lm87_read_value(client, LM87_REG_VID_FAN_DIV); |
|---|
| 862 | if (*nrels_mag >= 2) { |
|---|
| 863 | data->fan_div[1] = DIV_TO_REG(results[1]); |
|---|
| 864 | old = (old & 0x3f) | (data->fan_div[1] << 6); |
|---|
| 865 | } |
|---|
| 866 | if (*nrels_mag >= 1) { |
|---|
| 867 | data->fan_div[0] = DIV_TO_REG(results[0]); |
|---|
| 868 | old = (old & 0xcf) | (data->fan_div[0] << 4); |
|---|
| 869 | lm87_write_value(client, LM87_REG_VID_FAN_DIV, old); |
|---|
| 870 | } |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | void lm87_analog_out(struct i2c_client *client, int operation, |
|---|
| 875 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 876 | { |
|---|
| 877 | struct lm87_data *data = client->data; |
|---|
| 878 | |
|---|
| 879 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 880 | *nrels_mag = 0; |
|---|
| 881 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 882 | lm87_update_client(client); |
|---|
| 883 | results[0] = data->analog_out; |
|---|
| 884 | *nrels_mag = 1; |
|---|
| 885 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 886 | if (*nrels_mag >= 1) { |
|---|
| 887 | data->analog_out = results[0]; |
|---|
| 888 | lm87_write_value(client, LM87_REG_ANALOG_OUT, |
|---|
| 889 | data->analog_out); |
|---|
| 890 | } |
|---|
| 891 | } |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | void lm87_vid(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 895 | int *nrels_mag, long *results) |
|---|
| 896 | { |
|---|
| 897 | struct lm87_data *data = client->data; |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 901 | *nrels_mag = 2; |
|---|
| 902 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 903 | lm87_update_client(client); |
|---|
| 904 | results[0] = VID_FROM_REG(data->vid); |
|---|
| 905 | *nrels_mag = 1; |
|---|
| 906 | } |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | int __init sensors_lm87_init(void) |
|---|
| 910 | { |
|---|
| 911 | int res; |
|---|
| 912 | |
|---|
| 913 | printk("lm87.o version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 914 | lm87_initialized = 0; |
|---|
| 915 | |
|---|
| 916 | if ((res = i2c_add_driver(&lm87_driver))) { |
|---|
| 917 | printk |
|---|
| 918 | ("lm87.o: Driver registration failed, module not inserted.\n"); |
|---|
| 919 | lm87_cleanup(); |
|---|
| 920 | return res; |
|---|
| 921 | } |
|---|
| 922 | lm87_initialized++; |
|---|
| 923 | return 0; |
|---|
| 924 | } |
|---|
| 925 | |
|---|
| 926 | int __init lm87_cleanup(void) |
|---|
| 927 | { |
|---|
| 928 | int res; |
|---|
| 929 | |
|---|
| 930 | if (lm87_initialized >= 1) { |
|---|
| 931 | if ((res = i2c_del_driver(&lm87_driver))) { |
|---|
| 932 | printk |
|---|
| 933 | ("lm87.o: Driver deregistration failed, module not removed.\n"); |
|---|
| 934 | return res; |
|---|
| 935 | } |
|---|
| 936 | lm87_initialized--; |
|---|
| 937 | } |
|---|
| 938 | return 0; |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | EXPORT_NO_SYMBOLS; |
|---|
| 942 | |
|---|
| 943 | #ifdef MODULE |
|---|
| 944 | |
|---|
| 945 | MODULE_AUTHOR |
|---|
| 946 | ("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, |
|---|
| 947 | and Stephen Rousset <stephen.rousset@rocketlogix.com>"); |
|---|
| 948 | |
|---|
| 949 | MODULE_DESCRIPTION("lm87 driver"); |
|---|
| 950 | |
|---|
| 951 | int init_module(void) |
|---|
| 952 | { |
|---|
| 953 | return sensors_lm87_init(); |
|---|
| 954 | } |
|---|
| 955 | |
|---|
| 956 | int cleanup_module(void) |
|---|
| 957 | { |
|---|
| 958 | return lm87_cleanup(); |
|---|
| 959 | } |
|---|
| 960 | |
|---|
| 961 | #endif /* MODULE */ |
|---|