| 1 | /* |
|---|
| 2 | fscher.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (C) 2003, 2004 Reinhard Nissl <rnissl@gmx.de> |
|---|
| 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 | /* |
|---|
| 22 | fujitsu siemens hermes chip, |
|---|
| 23 | module based on fscpos.c |
|---|
| 24 | Copyright (C) 2000 Hermann Jung <hej@odn.de> |
|---|
| 25 | Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 26 | and Philip Edelbrock <phil@netroedge.com> |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include <linux/module.h> |
|---|
| 30 | #include <linux/slab.h> |
|---|
| 31 | #include <linux/i2c.h> |
|---|
| 32 | #include <linux/i2c-proc.h> |
|---|
| 33 | #include <linux/init.h> |
|---|
| 34 | #include "version.h" |
|---|
| 35 | |
|---|
| 36 | #ifndef I2C_DRIVERID_FSCHER |
|---|
| 37 | #define I2C_DRIVERID_FSCHER 1046 |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | /* Addresses to scan */ |
|---|
| 41 | static unsigned short normal_i2c[] = { 0x73, SENSORS_I2C_END }; |
|---|
| 42 | static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; |
|---|
| 43 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 44 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 45 | |
|---|
| 46 | /* Insmod parameters */ |
|---|
| 47 | SENSORS_INSMOD_1(fscher); |
|---|
| 48 | |
|---|
| 49 | /* The FSCHER registers */ |
|---|
| 50 | |
|---|
| 51 | /* chip identification */ |
|---|
| 52 | #define FSCHER_REG_IDENT_0 0x00 |
|---|
| 53 | #define FSCHER_REG_IDENT_1 0x01 |
|---|
| 54 | #define FSCHER_REG_IDENT_2 0x02 |
|---|
| 55 | #define FSCHER_REG_REVISION 0x03 |
|---|
| 56 | |
|---|
| 57 | /* global control and status */ |
|---|
| 58 | #define FSCHER_REG_EVENT_STATE 0x04 |
|---|
| 59 | #define FSCHER_REG_CONTROL 0x05 |
|---|
| 60 | |
|---|
| 61 | /* watchdog */ |
|---|
| 62 | #define FSCHER_REG_WDOG_PRESET 0x28 |
|---|
| 63 | #define FSCHER_REG_WDOG_STATE 0x23 |
|---|
| 64 | #define FSCHER_REG_WDOG_CONTROL 0x21 |
|---|
| 65 | |
|---|
| 66 | /* fan 0 */ |
|---|
| 67 | #define FSCHER_REG_FAN0_MIN 0x55 |
|---|
| 68 | #define FSCHER_REG_FAN0_ACT 0x0e |
|---|
| 69 | #define FSCHER_REG_FAN0_STATE 0x0d |
|---|
| 70 | #define FSCHER_REG_FAN0_RIPPLE 0x0f |
|---|
| 71 | |
|---|
| 72 | /* fan 1 */ |
|---|
| 73 | #define FSCHER_REG_FAN1_MIN 0x65 |
|---|
| 74 | #define FSCHER_REG_FAN1_ACT 0x6b |
|---|
| 75 | #define FSCHER_REG_FAN1_STATE 0x62 |
|---|
| 76 | #define FSCHER_REG_FAN1_RIPPLE 0x6f |
|---|
| 77 | |
|---|
| 78 | /* fan 2 */ |
|---|
| 79 | #define FSCHER_REG_FAN2_MIN 0xb5 |
|---|
| 80 | #define FSCHER_REG_FAN2_ACT 0xbb |
|---|
| 81 | #define FSCHER_REG_FAN2_STATE 0xb2 |
|---|
| 82 | #define FSCHER_REG_FAN2_RIPPLE 0xbf |
|---|
| 83 | |
|---|
| 84 | /* voltage supervision */ |
|---|
| 85 | #define FSCHER_REG_VOLT_12 0x45 |
|---|
| 86 | #define FSCHER_REG_VOLT_5 0x42 |
|---|
| 87 | #define FSCHER_REG_VOLT_BATT 0x48 |
|---|
| 88 | |
|---|
| 89 | /* temperatures */ |
|---|
| 90 | /* sensor 0 */ |
|---|
| 91 | #define FSCHER_REG_TEMP0_ACT 0x64 |
|---|
| 92 | #define FSCHER_REG_TEMP0_STATE 0x71 |
|---|
| 93 | |
|---|
| 94 | /* sensor 1 */ |
|---|
| 95 | #define FSCHER_REG_TEMP1_ACT 0x32 |
|---|
| 96 | #define FSCHER_REG_TEMP1_STATE 0x81 |
|---|
| 97 | |
|---|
| 98 | /* sensor 2 */ |
|---|
| 99 | #define FSCHER_REG_TEMP2_ACT 0x35 |
|---|
| 100 | #define FSCHER_REG_TEMP2_STATE 0x91 |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* Initial limits */ |
|---|
| 105 | |
|---|
| 106 | /* For each registered FSCHER, we need to keep some data in memory. That |
|---|
| 107 | data is pointed to by fscher_list[NR]->data. The structure itself is |
|---|
| 108 | dynamically allocated, at the same time when a new fscher client is |
|---|
| 109 | allocated. */ |
|---|
| 110 | struct fscher_data { |
|---|
| 111 | struct i2c_client client; |
|---|
| 112 | int sysctl_id; |
|---|
| 113 | |
|---|
| 114 | struct semaphore update_lock; |
|---|
| 115 | char valid; /* !=0 if following fields are valid */ |
|---|
| 116 | unsigned long last_updated; /* In jiffies */ |
|---|
| 117 | |
|---|
| 118 | u8 revision; /* revision of chip */ |
|---|
| 119 | u8 global_event; /* global event status */ |
|---|
| 120 | u8 global_control; /* global control register */ |
|---|
| 121 | u8 watchdog[3]; /* watchdog */ |
|---|
| 122 | u8 volt[3]; /* 12, 5, battery current */ |
|---|
| 123 | u8 temp_act[3]; /* temperature */ |
|---|
| 124 | u8 temp_status[3]; /* status of sensor */ |
|---|
| 125 | u8 fan_act[3]; /* fans revolutions per second */ |
|---|
| 126 | u8 fan_status[3]; /* fan status */ |
|---|
| 127 | u8 fan_min[3]; /* fan min value for rps */ |
|---|
| 128 | u8 fan_ripple[3]; /* divider for rps */ |
|---|
| 129 | }; |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | static int fscher_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 133 | static int fscher_detect(struct i2c_adapter *adapter, int address, |
|---|
| 134 | unsigned short flags, int kind); |
|---|
| 135 | static int fscher_detach_client(struct i2c_client *client); |
|---|
| 136 | |
|---|
| 137 | static int fscher_read_value(struct i2c_client *client, u8 register); |
|---|
| 138 | static int fscher_write_value(struct i2c_client *client, u8 register, |
|---|
| 139 | u8 value); |
|---|
| 140 | static void fscher_update_client(struct i2c_client *client); |
|---|
| 141 | static void fscher_init_client(struct i2c_client *client); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | static void fscher_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 145 | int *nrels_mag, long *results); |
|---|
| 146 | static void fscher_pwm(struct i2c_client *client, int operation, |
|---|
| 147 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 148 | static void fscher_pwm_internal(struct i2c_client *client, int operation, |
|---|
| 149 | int ctl_name, int *nrels_mag, long *results, |
|---|
| 150 | int nr, int reg_min); |
|---|
| 151 | static void fscher_fan(struct i2c_client *client, int operation, |
|---|
| 152 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 153 | static void fscher_fan_internal(struct i2c_client *client, int operation, |
|---|
| 154 | int ctl_name, int *nrels_mag, long *results, |
|---|
| 155 | int nr, int reg_state, int res_ripple); |
|---|
| 156 | static void fscher_temp(struct i2c_client *client, int operation, |
|---|
| 157 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 158 | static void fscher_volt(struct i2c_client *client, int operation, |
|---|
| 159 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 160 | static void fscher_wdog(struct i2c_client *client, int operation, |
|---|
| 161 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 162 | |
|---|
| 163 | static int fscher_id = 0; |
|---|
| 164 | |
|---|
| 165 | static struct i2c_driver fscher_driver = { |
|---|
| 166 | .name = "FSCHER sensor driver", |
|---|
| 167 | .id = I2C_DRIVERID_FSCHER, |
|---|
| 168 | .flags = I2C_DF_NOTIFY, |
|---|
| 169 | .attach_adapter = fscher_attach_adapter, |
|---|
| 170 | .detach_client = fscher_detach_client, |
|---|
| 171 | }; |
|---|
| 172 | |
|---|
| 173 | /* -- SENSORS SYSCTL START -- */ |
|---|
| 174 | #define FSCHER_SYSCTL_VOLT0 1000 /* 12 volt supply */ |
|---|
| 175 | #define FSCHER_SYSCTL_VOLT1 1001 /* 5 volt supply */ |
|---|
| 176 | #define FSCHER_SYSCTL_VOLT2 1002 /* batterie voltage */ |
|---|
| 177 | #define FSCHER_SYSCTL_FAN0 1101 /* state, ripple, actual value |
|---|
| 178 | fan 0 */ |
|---|
| 179 | #define FSCHER_SYSCTL_FAN1 1102 /* state, ripple, actual value |
|---|
| 180 | fan 1 */ |
|---|
| 181 | #define FSCHER_SYSCTL_FAN2 1103 /* state, ripple, actual value |
|---|
| 182 | fan 2 */ |
|---|
| 183 | #define FSCHER_SYSCTL_TEMP0 1201 /* state and value of sensor 0, |
|---|
| 184 | cpu die */ |
|---|
| 185 | #define FSCHER_SYSCTL_TEMP1 1202 /* state and value of sensor 1, |
|---|
| 186 | motherboard */ |
|---|
| 187 | #define FSCHER_SYSCTL_TEMP2 1203 /* state and value of sensor 2, |
|---|
| 188 | chassis */ |
|---|
| 189 | #define FSCHER_SYSCTL_PWM0 1301 /* min fan 0 */ |
|---|
| 190 | #define FSCHER_SYSCTL_PWM1 1302 /* min fan 1 */ |
|---|
| 191 | #define FSCHER_SYSCTL_PWM2 1303 /* min fan 2 */ |
|---|
| 192 | #define FSCHER_SYSCTL_REV 2000 /* revision */ |
|---|
| 193 | #define FSCHER_SYSCTL_EVENT 2001 /* global event status */ |
|---|
| 194 | #define FSCHER_SYSCTL_CONTROL 2002 /* global control byte */ |
|---|
| 195 | #define FSCHER_SYSCTL_WDOG 2003 /* watch dog preset, state and |
|---|
| 196 | control */ |
|---|
| 197 | /* -- SENSORS SYSCTL END -- */ |
|---|
| 198 | |
|---|
| 199 | /* These files are created for each detected FSCHER. This is just a template; |
|---|
| 200 | though at first sight, you might think we could use a statically |
|---|
| 201 | allocated list, we need some way to get back to the parent - which |
|---|
| 202 | is done through one of the 'extra' fields which are initialized |
|---|
| 203 | when a new copy is allocated. */ |
|---|
| 204 | static ctl_table fscher_dir_table_template[] = { |
|---|
| 205 | {FSCHER_SYSCTL_REV, "rev", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 206 | &i2c_sysctl_real, NULL, &fscher_in}, |
|---|
| 207 | {FSCHER_SYSCTL_EVENT, "alarms", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 208 | &i2c_sysctl_real, NULL, &fscher_in}, |
|---|
| 209 | {FSCHER_SYSCTL_CONTROL, "control", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 210 | &i2c_sysctl_real, NULL, &fscher_in}, |
|---|
| 211 | {FSCHER_SYSCTL_TEMP0, "temp1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 212 | &i2c_sysctl_real, NULL, &fscher_temp}, |
|---|
| 213 | {FSCHER_SYSCTL_TEMP1, "temp2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 214 | &i2c_sysctl_real, NULL, &fscher_temp}, |
|---|
| 215 | {FSCHER_SYSCTL_TEMP2, "temp3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 216 | &i2c_sysctl_real, NULL, &fscher_temp}, |
|---|
| 217 | {FSCHER_SYSCTL_VOLT0, "in0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 218 | &i2c_sysctl_real, NULL, &fscher_volt}, |
|---|
| 219 | {FSCHER_SYSCTL_VOLT1, "in1", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 220 | &i2c_sysctl_real, NULL, &fscher_volt}, |
|---|
| 221 | {FSCHER_SYSCTL_VOLT2, "in2", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 222 | &i2c_sysctl_real, NULL, &fscher_volt}, |
|---|
| 223 | {FSCHER_SYSCTL_FAN0, "fan1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 224 | &i2c_sysctl_real, NULL, &fscher_fan}, |
|---|
| 225 | {FSCHER_SYSCTL_FAN1, "fan2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 226 | &i2c_sysctl_real, NULL, &fscher_fan}, |
|---|
| 227 | {FSCHER_SYSCTL_FAN2, "fan3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 228 | &i2c_sysctl_real, NULL, &fscher_fan}, |
|---|
| 229 | {FSCHER_SYSCTL_PWM0, "pwm1", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 230 | &i2c_sysctl_real, NULL, &fscher_pwm}, |
|---|
| 231 | {FSCHER_SYSCTL_PWM1, "pwm2", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 232 | &i2c_sysctl_real, NULL, &fscher_pwm}, |
|---|
| 233 | {FSCHER_SYSCTL_PWM2, "pwm3", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 234 | &i2c_sysctl_real, NULL, &fscher_pwm}, |
|---|
| 235 | {FSCHER_SYSCTL_WDOG, "wdog", NULL, 0, 0644, NULL, &i2c_proc_real, |
|---|
| 236 | &i2c_sysctl_real, NULL, &fscher_wdog}, |
|---|
| 237 | {0} |
|---|
| 238 | }; |
|---|
| 239 | |
|---|
| 240 | static int fscher_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 241 | { |
|---|
| 242 | return i2c_detect(adapter, &addr_data, fscher_detect); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | int fscher_detect(struct i2c_adapter *adapter, int address, |
|---|
| 246 | unsigned short flags, int kind) |
|---|
| 247 | { |
|---|
| 248 | int i; |
|---|
| 249 | struct i2c_client *new_client; |
|---|
| 250 | struct fscher_data *data; |
|---|
| 251 | int err = 0; |
|---|
| 252 | const char *type_name, *client_name; |
|---|
| 253 | |
|---|
| 254 | /* Make sure we aren't probing the ISA bus!! This is just a safety |
|---|
| 255 | check at this moment; i2c_detect really won't call us. */ |
|---|
| 256 | #ifdef DEBUG |
|---|
| 257 | if (i2c_is_isa_adapter(adapter)) { |
|---|
| 258 | printk("fscher.o: fscher_detect called for an ISA bus adapter?!?\n"); |
|---|
| 259 | return 0; |
|---|
| 260 | } |
|---|
| 261 | #endif |
|---|
| 262 | |
|---|
| 263 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
|---|
| 264 | goto ERROR0; |
|---|
| 265 | |
|---|
| 266 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 267 | client structure, even though we cannot fill it completely yet. |
|---|
| 268 | But it allows us to access fscher_{read,write}_value. */ |
|---|
| 269 | if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) { |
|---|
| 270 | err = -ENOMEM; |
|---|
| 271 | goto ERROR0; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | new_client = &data->client; |
|---|
| 275 | new_client->addr = address; |
|---|
| 276 | new_client->data = data; |
|---|
| 277 | new_client->adapter = adapter; |
|---|
| 278 | new_client->driver = &fscher_driver; |
|---|
| 279 | new_client->flags = 0; |
|---|
| 280 | |
|---|
| 281 | /* Do the remaining detection unless force or force_fscher parameter */ |
|---|
| 282 | if (kind < 0) { |
|---|
| 283 | if (fscher_read_value(new_client, FSCHER_REG_IDENT_0) != 0x48) /* 'H' */ |
|---|
| 284 | goto ERROR1; |
|---|
| 285 | if (fscher_read_value(new_client, FSCHER_REG_IDENT_1) != 0x45) /* 'E' */ |
|---|
| 286 | goto ERROR1; |
|---|
| 287 | if (fscher_read_value(new_client, FSCHER_REG_IDENT_2) != 0x52) /* 'R' */ |
|---|
| 288 | goto ERROR1; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | kind = fscher; |
|---|
| 292 | |
|---|
| 293 | type_name = "fscher"; |
|---|
| 294 | client_name = "fsc hermes chip"; |
|---|
| 295 | |
|---|
| 296 | /* Fill in the remaining client fields and put it into the |
|---|
| 297 | global list */ |
|---|
| 298 | strcpy(new_client->name, client_name); |
|---|
| 299 | |
|---|
| 300 | new_client->id = fscher_id++; |
|---|
| 301 | data->valid = 0; |
|---|
| 302 | init_MUTEX(&data->update_lock); |
|---|
| 303 | |
|---|
| 304 | /* Tell the I2C layer a new client has arrived */ |
|---|
| 305 | if ((err = i2c_attach_client(new_client))) |
|---|
| 306 | goto ERROR3; |
|---|
| 307 | |
|---|
| 308 | /* Register a new directory entry with module sensors */ |
|---|
| 309 | if ((i = i2c_register_entry(new_client, type_name, |
|---|
| 310 | fscher_dir_table_template, |
|---|
| 311 | THIS_MODULE)) < 0) { |
|---|
| 312 | err = i; |
|---|
| 313 | goto ERROR4; |
|---|
| 314 | } |
|---|
| 315 | data->sysctl_id = i; |
|---|
| 316 | |
|---|
| 317 | fscher_init_client(new_client); |
|---|
| 318 | return 0; |
|---|
| 319 | |
|---|
| 320 | /* OK, this is not exactly good programming practice, usually. But it is |
|---|
| 321 | very code-efficient in this case. */ |
|---|
| 322 | ERROR4: |
|---|
| 323 | i2c_detach_client(new_client); |
|---|
| 324 | ERROR3: |
|---|
| 325 | ERROR1: |
|---|
| 326 | kfree(data); |
|---|
| 327 | ERROR0: |
|---|
| 328 | return err; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | static int fscher_detach_client(struct i2c_client *client) |
|---|
| 332 | { |
|---|
| 333 | int err; |
|---|
| 334 | |
|---|
| 335 | i2c_deregister_entry(((struct fscher_data *) (client->data))->sysctl_id); |
|---|
| 336 | |
|---|
| 337 | if ((err = i2c_detach_client(client))) { |
|---|
| 338 | printk("fscher.o: Client deregistration failed, client not detached.\n"); |
|---|
| 339 | return err; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | kfree(client->data); |
|---|
| 343 | |
|---|
| 344 | return 0; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | static int fscher_read_value(struct i2c_client *client, u8 reg) |
|---|
| 348 | { |
|---|
| 349 | #ifdef DEBUG |
|---|
| 350 | printk("fscher: read reg 0x%02x\n",reg); |
|---|
| 351 | #endif |
|---|
| 352 | return i2c_smbus_read_byte_data(client, reg); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 356 | { |
|---|
| 357 | #ifdef DEBUG |
|---|
| 358 | printk("fscher: write reg 0x%02x, val 0x%02x\n",reg, value); |
|---|
| 359 | #endif |
|---|
| 360 | return i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | /* Called when we have found a new FSCHER. It should set limits, etc. */ |
|---|
| 364 | static void fscher_init_client(struct i2c_client *client) |
|---|
| 365 | { |
|---|
| 366 | struct fscher_data *data = client->data; |
|---|
| 367 | |
|---|
| 368 | /* read revision from chip */ |
|---|
| 369 | data->revision = fscher_read_value(client,FSCHER_REG_REVISION); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | static void fscher_update_client(struct i2c_client *client) |
|---|
| 373 | { |
|---|
| 374 | struct fscher_data *data = client->data; |
|---|
| 375 | |
|---|
| 376 | down(&data->update_lock); |
|---|
| 377 | |
|---|
| 378 | if ((jiffies - data->last_updated > 2 * HZ) || |
|---|
| 379 | (jiffies < data->last_updated) || !data->valid) { |
|---|
| 380 | |
|---|
| 381 | #ifdef DEBUG |
|---|
| 382 | printk("Starting fscher update\n"); |
|---|
| 383 | #endif |
|---|
| 384 | data->temp_act[0] = fscher_read_value(client, FSCHER_REG_TEMP0_ACT); |
|---|
| 385 | data->temp_act[1] = fscher_read_value(client, FSCHER_REG_TEMP1_ACT); |
|---|
| 386 | data->temp_act[2] = fscher_read_value(client, FSCHER_REG_TEMP2_ACT); |
|---|
| 387 | data->temp_status[0] = fscher_read_value(client, FSCHER_REG_TEMP0_STATE); |
|---|
| 388 | data->temp_status[1] = fscher_read_value(client, FSCHER_REG_TEMP1_STATE); |
|---|
| 389 | data->temp_status[2] = fscher_read_value(client, FSCHER_REG_TEMP2_STATE); |
|---|
| 390 | |
|---|
| 391 | data->volt[0] = fscher_read_value(client, FSCHER_REG_VOLT_12); |
|---|
| 392 | data->volt[1] = fscher_read_value(client, FSCHER_REG_VOLT_5); |
|---|
| 393 | data->volt[2] = fscher_read_value(client, FSCHER_REG_VOLT_BATT); |
|---|
| 394 | |
|---|
| 395 | data->fan_act[0] = fscher_read_value(client, FSCHER_REG_FAN0_ACT); |
|---|
| 396 | data->fan_act[1] = fscher_read_value(client, FSCHER_REG_FAN1_ACT); |
|---|
| 397 | data->fan_act[2] = fscher_read_value(client, FSCHER_REG_FAN2_ACT); |
|---|
| 398 | data->fan_status[0] = fscher_read_value(client, FSCHER_REG_FAN0_STATE); |
|---|
| 399 | data->fan_status[1] = fscher_read_value(client, FSCHER_REG_FAN1_STATE); |
|---|
| 400 | data->fan_status[2] = fscher_read_value(client, FSCHER_REG_FAN2_STATE); |
|---|
| 401 | data->fan_min[0] = fscher_read_value(client, FSCHER_REG_FAN0_MIN); |
|---|
| 402 | data->fan_min[1] = fscher_read_value(client, FSCHER_REG_FAN1_MIN); |
|---|
| 403 | data->fan_min[2] = fscher_read_value(client, FSCHER_REG_FAN2_MIN); |
|---|
| 404 | data->fan_ripple[0] = fscher_read_value(client, FSCHER_REG_FAN0_RIPPLE); |
|---|
| 405 | data->fan_ripple[1] = fscher_read_value(client, FSCHER_REG_FAN1_RIPPLE); |
|---|
| 406 | data->fan_ripple[2] = fscher_read_value(client, FSCHER_REG_FAN2_RIPPLE); |
|---|
| 407 | |
|---|
| 408 | data->watchdog[0] = fscher_read_value(client, FSCHER_REG_WDOG_PRESET); |
|---|
| 409 | data->watchdog[1] = fscher_read_value(client, FSCHER_REG_WDOG_STATE); |
|---|
| 410 | data->watchdog[2] = fscher_read_value(client, FSCHER_REG_WDOG_CONTROL); |
|---|
| 411 | |
|---|
| 412 | data->global_event = fscher_read_value(client, FSCHER_REG_EVENT_STATE); |
|---|
| 413 | |
|---|
| 414 | data->last_updated = jiffies; |
|---|
| 415 | data->valid = 1; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | up(&data->update_lock); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | /* The next few functions are the call-back functions of the /proc/sys and |
|---|
| 423 | sysctl files. Which function is used is defined in the ctl_table in |
|---|
| 424 | the extra1 field. |
|---|
| 425 | Each function must return the magnitude (power of 10 to divide the date |
|---|
| 426 | with) if it is called with operation==SENSORS_PROC_REAL_INFO. It must |
|---|
| 427 | put a maximum of *nrels elements in results reflecting the data of this |
|---|
| 428 | file, and set *nrels to the number it actually put in it, if operation== |
|---|
| 429 | SENSORS_PROC_REAL_READ. Finally, it must get upto *nrels elements from |
|---|
| 430 | results and write them to the chip, if operations==SENSORS_PROC_REAL_WRITE. |
|---|
| 431 | Note that on SENSORS_PROC_REAL_READ, I do not check whether results is |
|---|
| 432 | large enough (by checking the incoming value of *nrels). This is not very |
|---|
| 433 | good practice, but as long as you put less than about 5 values in results, |
|---|
| 434 | you can assume it is large enough. */ |
|---|
| 435 | void fscher_in(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 436 | int *nrels_mag, long *results) |
|---|
| 437 | { |
|---|
| 438 | struct fscher_data *data = client->data; |
|---|
| 439 | |
|---|
| 440 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 441 | *nrels_mag = 0; |
|---|
| 442 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 443 | fscher_update_client(client); |
|---|
| 444 | switch(ctl_name) { |
|---|
| 445 | case FSCHER_SYSCTL_REV: |
|---|
| 446 | results[0] = data->revision ; |
|---|
| 447 | break; |
|---|
| 448 | case FSCHER_SYSCTL_EVENT: |
|---|
| 449 | /* bits 6, 5 and 2 are reserved => mask with 0x9b */ |
|---|
| 450 | results[0] = data->global_event & 0x9b; |
|---|
| 451 | break; |
|---|
| 452 | case FSCHER_SYSCTL_CONTROL: |
|---|
| 453 | results[0] = data->global_control & 0x01; |
|---|
| 454 | break; |
|---|
| 455 | default: |
|---|
| 456 | printk("fscher: ctl_name %d not supported\n", ctl_name); |
|---|
| 457 | *nrels_mag = 0; |
|---|
| 458 | return; |
|---|
| 459 | } |
|---|
| 460 | *nrels_mag = 1; |
|---|
| 461 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 462 | if((ctl_name == FSCHER_SYSCTL_CONTROL) && (*nrels_mag >= 1)) { |
|---|
| 463 | data->global_control = (results[0] & 0x01); |
|---|
| 464 | printk("fscher: writing 0x%02x to global_control\n", |
|---|
| 465 | data->global_control); |
|---|
| 466 | fscher_write_value(client,FSCHER_REG_CONTROL, |
|---|
| 467 | data->global_control); |
|---|
| 468 | } |
|---|
| 469 | else |
|---|
| 470 | printk("fscher: writing to chip not supported\n"); |
|---|
| 471 | } |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | #define TEMP_FROM_REG(val) (val-128) |
|---|
| 476 | |
|---|
| 477 | void fscher_temp(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 478 | int *nrels_mag, long *results) |
|---|
| 479 | { |
|---|
| 480 | struct fscher_data *data = client->data; |
|---|
| 481 | |
|---|
| 482 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 483 | *nrels_mag = 0; |
|---|
| 484 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 485 | fscher_update_client(client); |
|---|
| 486 | switch(ctl_name) { |
|---|
| 487 | case FSCHER_SYSCTL_TEMP0: |
|---|
| 488 | results[0] = data->temp_status[0] & 0x03; |
|---|
| 489 | results[1] = TEMP_FROM_REG(data->temp_act[0]); |
|---|
| 490 | break; |
|---|
| 491 | case FSCHER_SYSCTL_TEMP1: |
|---|
| 492 | results[0] = data->temp_status[1] & 0x03; |
|---|
| 493 | results[1] = TEMP_FROM_REG(data->temp_act[1]); |
|---|
| 494 | break; |
|---|
| 495 | case FSCHER_SYSCTL_TEMP2: |
|---|
| 496 | results[0] = data->temp_status[2] & 0x03; |
|---|
| 497 | results[1] = TEMP_FROM_REG(data->temp_act[2]); |
|---|
| 498 | break; |
|---|
| 499 | default: |
|---|
| 500 | printk("fscher: ctl_name %d not supported\n", ctl_name); |
|---|
| 501 | *nrels_mag = 0; |
|---|
| 502 | return; |
|---|
| 503 | } |
|---|
| 504 | *nrels_mag = 2; |
|---|
| 505 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 506 | if(*nrels_mag >= 1) { |
|---|
| 507 | switch(ctl_name) { |
|---|
| 508 | case FSCHER_SYSCTL_TEMP0: |
|---|
| 509 | data->temp_status[0] = (data->temp_status[0] & ~0x02) |
|---|
| 510 | | (results[0] & 0x02); |
|---|
| 511 | printk("fscher: writing value 0x%02x to temp0_status\n", |
|---|
| 512 | data->temp_status[0]); |
|---|
| 513 | fscher_write_value(client, FSCHER_REG_TEMP0_STATE, |
|---|
| 514 | data->temp_status[0] & 0x02); |
|---|
| 515 | break; |
|---|
| 516 | case FSCHER_SYSCTL_TEMP1: |
|---|
| 517 | data->temp_status[1] = (data->temp_status[1] & ~0x02) |
|---|
| 518 | | (results[0] & 0x02); |
|---|
| 519 | printk("fscher: writing value 0x%02x to temp1_status\n", |
|---|
| 520 | data->temp_status[1]); |
|---|
| 521 | fscher_write_value(client, FSCHER_REG_TEMP1_STATE, |
|---|
| 522 | data->temp_status[1] & 0x02); |
|---|
| 523 | break; |
|---|
| 524 | case FSCHER_SYSCTL_TEMP2: |
|---|
| 525 | data->temp_status[2] = (data->temp_status[2] & ~0x02) |
|---|
| 526 | | (results[0] & 0x02); |
|---|
| 527 | printk("fscher: writing value 0x%02x to temp2_status\n", |
|---|
| 528 | data->temp_status[2]); |
|---|
| 529 | fscher_write_value(client, FSCHER_REG_TEMP2_STATE, |
|---|
| 530 | data->temp_status[2] & 0x02); |
|---|
| 531 | break; |
|---|
| 532 | default: |
|---|
| 533 | printk("fscher: ctl_name %d not supported\n",ctl_name); |
|---|
| 534 | } |
|---|
| 535 | } |
|---|
| 536 | else |
|---|
| 537 | printk("fscher: writing to chip not supported\n"); |
|---|
| 538 | } |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | /* |
|---|
| 542 | * The final conversion is specified in sensors.conf, as it depends on |
|---|
| 543 | * mainboard specific values. We export the registers contents as |
|---|
| 544 | * pseudo-hundredths-of-Volts (range 0V - 2.55V). Not that it makes much |
|---|
| 545 | * sense per se, but it minimizes the conversions count and keeps the |
|---|
| 546 | * values within a usual range. |
|---|
| 547 | */ |
|---|
| 548 | void fscher_volt(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 549 | int *nrels_mag, long *results) |
|---|
| 550 | { |
|---|
| 551 | struct fscher_data *data = client->data; |
|---|
| 552 | |
|---|
| 553 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 554 | *nrels_mag = 2; |
|---|
| 555 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 556 | fscher_update_client(client); |
|---|
| 557 | switch(ctl_name) { |
|---|
| 558 | case FSCHER_SYSCTL_VOLT0: |
|---|
| 559 | results[0] = data->volt[0]; |
|---|
| 560 | break; |
|---|
| 561 | case FSCHER_SYSCTL_VOLT1: |
|---|
| 562 | results[0] = data->volt[1]; |
|---|
| 563 | break; |
|---|
| 564 | case FSCHER_SYSCTL_VOLT2: |
|---|
| 565 | results[0] = data->volt[2]; |
|---|
| 566 | break; |
|---|
| 567 | default: |
|---|
| 568 | printk("fscher: ctl_name %d not supported\n", ctl_name); |
|---|
| 569 | *nrels_mag = 0; |
|---|
| 570 | return; |
|---|
| 571 | } |
|---|
| 572 | *nrels_mag = 1; |
|---|
| 573 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 574 | printk("fscher: writing to chip not supported\n"); |
|---|
| 575 | } |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | void fscher_pwm(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 579 | int *nrels_mag, long *results) |
|---|
| 580 | { |
|---|
| 581 | |
|---|
| 582 | switch(ctl_name) { |
|---|
| 583 | case FSCHER_SYSCTL_PWM0: |
|---|
| 584 | fscher_pwm_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 585 | 0,FSCHER_REG_FAN0_MIN); |
|---|
| 586 | break; |
|---|
| 587 | case FSCHER_SYSCTL_PWM1: |
|---|
| 588 | fscher_pwm_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 589 | 1,FSCHER_REG_FAN1_MIN); |
|---|
| 590 | break; |
|---|
| 591 | case FSCHER_SYSCTL_PWM2: |
|---|
| 592 | fscher_pwm_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 593 | 2,FSCHER_REG_FAN2_MIN); |
|---|
| 594 | break; |
|---|
| 595 | default: |
|---|
| 596 | printk("fscher: illegal pwm nr %d\n",ctl_name); |
|---|
| 597 | } |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | void fscher_pwm_internal(struct i2c_client *client, int operation, |
|---|
| 601 | int ctl_name, int *nrels_mag, long *results, |
|---|
| 602 | int nr, int reg_min) |
|---|
| 603 | { |
|---|
| 604 | struct fscher_data *data = client->data; |
|---|
| 605 | |
|---|
| 606 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 607 | *nrels_mag = 0; |
|---|
| 608 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 609 | fscher_update_client(client); |
|---|
| 610 | results[0] = data->fan_min[nr]; |
|---|
| 611 | *nrels_mag = 1; |
|---|
| 612 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 613 | if(*nrels_mag >= 1) { |
|---|
| 614 | data->fan_min[nr] = results[0]; |
|---|
| 615 | printk("fscher: writing value 0x%02x to fan%d_min\n", |
|---|
| 616 | data->fan_min[nr],nr); |
|---|
| 617 | fscher_write_value(client,reg_min,data->fan_min[nr]); |
|---|
| 618 | } |
|---|
| 619 | } |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | void fscher_fan(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 623 | int *nrels_mag, long *results) |
|---|
| 624 | { |
|---|
| 625 | switch(ctl_name) { |
|---|
| 626 | case FSCHER_SYSCTL_FAN0: |
|---|
| 627 | fscher_fan_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 628 | 0,FSCHER_REG_FAN0_STATE, FSCHER_REG_FAN0_RIPPLE); |
|---|
| 629 | break; |
|---|
| 630 | case FSCHER_SYSCTL_FAN1: |
|---|
| 631 | fscher_fan_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 632 | 1,FSCHER_REG_FAN1_STATE, FSCHER_REG_FAN1_RIPPLE); |
|---|
| 633 | break; |
|---|
| 634 | case FSCHER_SYSCTL_FAN2: |
|---|
| 635 | fscher_fan_internal(client,operation,ctl_name,nrels_mag,results, |
|---|
| 636 | 2,FSCHER_REG_FAN2_STATE, FSCHER_REG_FAN2_RIPPLE); |
|---|
| 637 | break; |
|---|
| 638 | default: |
|---|
| 639 | printk("fscher: illegal fan nr %d\n",ctl_name); |
|---|
| 640 | } |
|---|
| 641 | } |
|---|
| 642 | |
|---|
| 643 | #define RPM_FROM_REG(val) (val*60) |
|---|
| 644 | |
|---|
| 645 | void fscher_fan_internal(struct i2c_client *client, int operation, |
|---|
| 646 | int ctl_name, int *nrels_mag, long *results, |
|---|
| 647 | int nr, int reg_state, int reg_ripple) |
|---|
| 648 | { |
|---|
| 649 | struct fscher_data *data = client->data; |
|---|
| 650 | |
|---|
| 651 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 652 | *nrels_mag = 0; |
|---|
| 653 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 654 | fscher_update_client(client); |
|---|
| 655 | results[0] = data->fan_status[nr] & 0x04; |
|---|
| 656 | results[1] = data->fan_ripple[nr] & 0x03; |
|---|
| 657 | results[2] = RPM_FROM_REG(data->fan_act[nr]); |
|---|
| 658 | *nrels_mag = 3; |
|---|
| 659 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 660 | if(*nrels_mag >= 1) { |
|---|
| 661 | data->fan_status[nr] = results[0] & 0x04; |
|---|
| 662 | printk("fscher: writing value 0x%02x to fan%d_status\n", |
|---|
| 663 | data->fan_status[nr],nr); |
|---|
| 664 | fscher_write_value(client,reg_state,data->fan_status[nr]); |
|---|
| 665 | } |
|---|
| 666 | if(*nrels_mag >= 2) { |
|---|
| 667 | if((results[1] & 0x03) == 0) { |
|---|
| 668 | printk("fscher: fan%d ripple 0 not allowed\n",nr); |
|---|
| 669 | return; |
|---|
| 670 | } |
|---|
| 671 | data->fan_ripple[nr] = results[1] & 0x03; |
|---|
| 672 | printk("fscher: writing value 0x%02x to fan%d_ripple\n", |
|---|
| 673 | data->fan_ripple[nr],nr); |
|---|
| 674 | fscher_write_value(client,reg_ripple,data->fan_ripple[nr]); |
|---|
| 675 | } |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | void fscher_wdog(struct i2c_client *client, int operation, int ctl_name, |
|---|
| 680 | int *nrels_mag, long *results) |
|---|
| 681 | { |
|---|
| 682 | struct fscher_data *data = client->data; |
|---|
| 683 | |
|---|
| 684 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 685 | *nrels_mag = 0; |
|---|
| 686 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 687 | fscher_update_client(client); |
|---|
| 688 | results[0] = data->watchdog[0] ; |
|---|
| 689 | results[1] = data->watchdog[1] & 0x02; |
|---|
| 690 | results[2] = data->watchdog[2] & 0xd0; |
|---|
| 691 | *nrels_mag = 3; |
|---|
| 692 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 693 | if (*nrels_mag >= 1) { |
|---|
| 694 | data->watchdog[0] = results[0] & 0xff; |
|---|
| 695 | printk("fscher: writing value 0x%02x to wdog_preset\n", |
|---|
| 696 | data->watchdog[0]); |
|---|
| 697 | fscher_write_value(client,FSCHER_REG_WDOG_PRESET,data->watchdog[0]); |
|---|
| 698 | } |
|---|
| 699 | if (*nrels_mag >= 2) { |
|---|
| 700 | data->watchdog[1] = results[1] & 0x02; |
|---|
| 701 | printk("fscher: writing value 0x%02x to wdog_state\n", |
|---|
| 702 | data->watchdog[1]); |
|---|
| 703 | fscher_write_value(client,FSCHER_REG_WDOG_STATE,data->watchdog[1]); |
|---|
| 704 | } |
|---|
| 705 | if (*nrels_mag >= 3) { |
|---|
| 706 | data->watchdog[2] = results[2] & 0xf0; |
|---|
| 707 | printk("fscher: writing value 0x%02x to wdog_control\n", |
|---|
| 708 | data->watchdog[2]); |
|---|
| 709 | fscher_write_value(client,FSCHER_REG_WDOG_CONTROL,data->watchdog[2]); |
|---|
| 710 | } |
|---|
| 711 | } |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | static int __init sm_fscher_init(void) |
|---|
| 715 | { |
|---|
| 716 | printk("fscher.o version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 717 | return i2c_add_driver(&fscher_driver); |
|---|
| 718 | } |
|---|
| 719 | |
|---|
| 720 | static void __exit sm_fscher_exit(void) |
|---|
| 721 | { |
|---|
| 722 | i2c_del_driver(&fscher_driver); |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | MODULE_AUTHOR("Reinhard Nissl <rnissl@gmx.de> based on work from Hermann" |
|---|
| 728 | " Jung <hej@odn.de>, Frodo Looijaard <frodol@dds.nl> and" |
|---|
| 729 | " Philip Edelbrock <phil@netroedge.com>"); |
|---|
| 730 | MODULE_DESCRIPTION("fujitsu siemens hermes chip driver"); |
|---|
| 731 | MODULE_LICENSE("GPL"); |
|---|
| 732 | |
|---|
| 733 | module_init(sm_fscher_init); |
|---|
| 734 | module_exit(sm_fscher_exit); |
|---|