Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pc87360.c - Part of lm_sensors, Linux kernel modules |
| 3 | * for hardware monitoring |
| 4 | * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> |
| 5 | * |
| 6 | * Copied from smsc47m1.c: |
| 7 | * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.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 | * Supports the following chips: |
| 24 | * |
| 25 | * Chip #vin #fan #pwm #temp devid |
| 26 | * PC87360 - 2 2 - 0xE1 |
| 27 | * PC87363 - 2 2 - 0xE8 |
| 28 | * PC87364 - 3 3 - 0xE4 |
| 29 | * PC87365 11 3 3 2 0xE5 |
| 30 | * PC87366 11 3 3 3-4 0xE9 |
| 31 | * |
| 32 | * This driver assumes that no more than one chip is present, and one of |
| 33 | * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F). |
| 34 | */ |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/module.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/jiffies.h> |
| 40 | #include <linux/i2c.h> |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 41 | #include <linux/i2c-isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/i2c-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 43 | #include <linux/hwmon.h> |
| 44 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/io.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static u8 devid; |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 48 | static unsigned short address; |
| 49 | static unsigned short extra_isa[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static u8 confreg[4]; |
| 51 | |
| 52 | enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | static int init = 1; |
| 55 | module_param(init, int, 0); |
| 56 | MODULE_PARM_DESC(init, |
| 57 | "Chip initialization level:\n" |
| 58 | " 0: None\n" |
| 59 | "*1: Forcibly enable internal voltage and temperature channels, except in9\n" |
| 60 | " 2: Forcibly enable all voltage and temperature channels, except in9\n" |
| 61 | " 3: Forcibly enable all voltage and temperature channels, including in9"); |
| 62 | |
| 63 | /* |
| 64 | * Super-I/O registers and operations |
| 65 | */ |
| 66 | |
| 67 | #define DEV 0x07 /* Register: Logical device select */ |
| 68 | #define DEVID 0x20 /* Register: Device ID */ |
| 69 | #define ACT 0x30 /* Register: Device activation */ |
| 70 | #define BASE 0x60 /* Register: Base address */ |
| 71 | |
| 72 | #define FSCM 0x09 /* Logical device: fans */ |
| 73 | #define VLM 0x0d /* Logical device: voltages */ |
| 74 | #define TMS 0x0e /* Logical device: temperatures */ |
| 75 | static const u8 logdev[3] = { FSCM, VLM, TMS }; |
| 76 | |
| 77 | #define LD_FAN 0 |
| 78 | #define LD_IN 1 |
| 79 | #define LD_TEMP 2 |
| 80 | |
| 81 | static inline void superio_outb(int sioaddr, int reg, int val) |
| 82 | { |
| 83 | outb(reg, sioaddr); |
| 84 | outb(val, sioaddr+1); |
| 85 | } |
| 86 | |
| 87 | static inline int superio_inb(int sioaddr, int reg) |
| 88 | { |
| 89 | outb(reg, sioaddr); |
| 90 | return inb(sioaddr+1); |
| 91 | } |
| 92 | |
| 93 | static inline void superio_exit(int sioaddr) |
| 94 | { |
| 95 | outb(0x02, sioaddr); |
| 96 | outb(0x02, sioaddr+1); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Logical devices |
| 101 | */ |
| 102 | |
| 103 | #define PC87360_EXTENT 0x10 |
| 104 | #define PC87365_REG_BANK 0x09 |
| 105 | #define NO_BANK 0xff |
| 106 | |
| 107 | /* |
| 108 | * Fan registers and conversions |
| 109 | */ |
| 110 | |
| 111 | /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */ |
| 112 | #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr)) |
| 113 | #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr)) |
| 114 | #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr)) |
| 115 | #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) |
| 116 | #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) |
| 117 | |
| 118 | #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \ |
| 119 | 480000 / ((val)*(div))) |
| 120 | #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \ |
| 121 | 480000 / ((val)*(div))) |
| 122 | #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03)) |
| 123 | #define FAN_STATUS_FROM_REG(val) ((val) & 0x07) |
| 124 | |
| 125 | #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1) |
| 126 | #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1) |
| 127 | #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1) |
| 128 | |
| 129 | #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val)) |
| 130 | static inline u8 PWM_TO_REG(int val, int inv) |
| 131 | { |
| 132 | if (inv) |
| 133 | val = 255 - val; |
| 134 | if (val < 0) |
| 135 | return 0; |
| 136 | if (val > 255) |
| 137 | return 255; |
| 138 | return val; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Voltage registers and conversions |
| 143 | */ |
| 144 | |
| 145 | #define PC87365_REG_IN_CONVRATE 0x07 |
| 146 | #define PC87365_REG_IN_CONFIG 0x08 |
| 147 | #define PC87365_REG_IN 0x0B |
| 148 | #define PC87365_REG_IN_MIN 0x0D |
| 149 | #define PC87365_REG_IN_MAX 0x0C |
| 150 | #define PC87365_REG_IN_STATUS 0x0A |
| 151 | #define PC87365_REG_IN_ALARMS1 0x00 |
| 152 | #define PC87365_REG_IN_ALARMS2 0x01 |
| 153 | #define PC87365_REG_VID 0x06 |
| 154 | |
| 155 | #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256) |
| 156 | #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \ |
| 157 | (val)*256 >= (ref)*255 ? 255: \ |
| 158 | ((val) * 256 + (ref)/2) / (ref)) |
| 159 | |
| 160 | /* |
| 161 | * Temperature registers and conversions |
| 162 | */ |
| 163 | |
| 164 | #define PC87365_REG_TEMP_CONFIG 0x08 |
| 165 | #define PC87365_REG_TEMP 0x0B |
| 166 | #define PC87365_REG_TEMP_MIN 0x0D |
| 167 | #define PC87365_REG_TEMP_MAX 0x0C |
| 168 | #define PC87365_REG_TEMP_CRIT 0x0E |
| 169 | #define PC87365_REG_TEMP_STATUS 0x0A |
| 170 | #define PC87365_REG_TEMP_ALARMS 0x00 |
| 171 | |
| 172 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 173 | #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \ |
| 174 | (val) > 127000 ? 127 : \ |
| 175 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 176 | ((val) + 500) / 1000) |
| 177 | |
| 178 | /* |
| 179 | * Client data (each client gets its own) |
| 180 | */ |
| 181 | |
| 182 | struct pc87360_data { |
| 183 | struct i2c_client client; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 184 | struct class_device *class_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct semaphore lock; |
| 186 | struct semaphore update_lock; |
| 187 | char valid; /* !=0 if following fields are valid */ |
| 188 | unsigned long last_updated; /* In jiffies */ |
| 189 | |
| 190 | int address[3]; |
| 191 | |
| 192 | u8 fannr, innr, tempnr; |
| 193 | |
| 194 | u8 fan[3]; /* Register value */ |
| 195 | u8 fan_min[3]; /* Register value */ |
| 196 | u8 fan_status[3]; /* Register value */ |
| 197 | u8 pwm[3]; /* Register value */ |
| 198 | u16 fan_conf; /* Configuration register values, combined */ |
| 199 | |
| 200 | u16 in_vref; /* 1 mV/bit */ |
| 201 | u8 in[14]; /* Register value */ |
| 202 | u8 in_min[14]; /* Register value */ |
| 203 | u8 in_max[14]; /* Register value */ |
| 204 | u8 in_crit[3]; /* Register value */ |
| 205 | u8 in_status[14]; /* Register value */ |
| 206 | u16 in_alarms; /* Register values, combined, masked */ |
| 207 | u8 vid_conf; /* Configuration register value */ |
| 208 | u8 vrm; |
| 209 | u8 vid; /* Register value */ |
| 210 | |
| 211 | s8 temp[3]; /* Register value */ |
| 212 | s8 temp_min[3]; /* Register value */ |
| 213 | s8 temp_max[3]; /* Register value */ |
| 214 | s8 temp_crit[3]; /* Register value */ |
| 215 | u8 temp_status[3]; /* Register value */ |
| 216 | u8 temp_alarms; /* Register value, masked */ |
| 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * Functions declaration |
| 221 | */ |
| 222 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 223 | static int pc87360_detect(struct i2c_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | static int pc87360_detach_client(struct i2c_client *client); |
| 225 | |
| 226 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 227 | u8 reg); |
| 228 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 229 | u8 reg, u8 value); |
| 230 | static void pc87360_init_client(struct i2c_client *client, int use_thermistors); |
| 231 | static struct pc87360_data *pc87360_update_device(struct device *dev); |
| 232 | |
| 233 | /* |
| 234 | * Driver data (common to all clients) |
| 235 | */ |
| 236 | |
| 237 | static struct i2c_driver pc87360_driver = { |
| 238 | .owner = THIS_MODULE, |
| 239 | .name = "pc87360", |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 240 | .attach_adapter = pc87360_detect, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | .detach_client = pc87360_detach_client, |
| 242 | }; |
| 243 | |
| 244 | /* |
| 245 | * Sysfs stuff |
| 246 | */ |
| 247 | |
| 248 | static ssize_t set_fan_min(struct device *dev, const char *buf, |
| 249 | size_t count, int nr) |
| 250 | { |
| 251 | struct i2c_client *client = to_i2c_client(dev); |
| 252 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 253 | long fan_min = simple_strtol(buf, NULL, 10); |
| 254 | |
| 255 | down(&data->update_lock); |
| 256 | fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[nr])); |
| 257 | |
| 258 | /* If it wouldn't fit, change clock divisor */ |
| 259 | while (fan_min > 255 |
| 260 | && (data->fan_status[nr] & 0x60) != 0x60) { |
| 261 | fan_min >>= 1; |
| 262 | data->fan[nr] >>= 1; |
| 263 | data->fan_status[nr] += 0x20; |
| 264 | } |
| 265 | data->fan_min[nr] = fan_min > 255 ? 255 : fan_min; |
| 266 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(nr), |
| 267 | data->fan_min[nr]); |
| 268 | |
| 269 | /* Write new divider, preserve alarm bits */ |
| 270 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(nr), |
| 271 | data->fan_status[nr] & 0xF9); |
| 272 | up(&data->update_lock); |
| 273 | |
| 274 | return count; |
| 275 | } |
| 276 | |
| 277 | #define show_and_set_fan(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 278 | static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { \ |
| 280 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 281 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \ |
| 282 | FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \ |
| 283 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 284 | static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { \ |
| 286 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 287 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \ |
| 288 | FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \ |
| 289 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 290 | static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { \ |
| 292 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 293 | return sprintf(buf, "%u\n", \ |
| 294 | FAN_DIV_FROM_REG(data->fan_status[offset-1])); \ |
| 295 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 296 | static ssize_t show_fan##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { \ |
| 298 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 299 | return sprintf(buf, "%u\n", \ |
| 300 | FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \ |
| 301 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 302 | static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | size_t count) \ |
| 304 | { \ |
| 305 | return set_fan_min(dev, buf, count, offset-1); \ |
| 306 | } \ |
| 307 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 308 | show_fan##offset##_input, NULL); \ |
| 309 | static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \ |
| 310 | show_fan##offset##_min, set_fan##offset##_min); \ |
| 311 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \ |
| 312 | show_fan##offset##_div, NULL); \ |
| 313 | static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \ |
| 314 | show_fan##offset##_status, NULL); |
| 315 | show_and_set_fan(1) |
| 316 | show_and_set_fan(2) |
| 317 | show_and_set_fan(3) |
| 318 | |
| 319 | #define show_and_set_pwm(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 320 | static ssize_t show_pwm##offset(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { \ |
| 322 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 323 | return sprintf(buf, "%u\n", \ |
| 324 | PWM_FROM_REG(data->pwm[offset-1], \ |
| 325 | FAN_CONFIG_INVERT(data->fan_conf, \ |
| 326 | offset-1))); \ |
| 327 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 328 | static ssize_t set_pwm##offset(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | size_t count) \ |
| 330 | { \ |
| 331 | struct i2c_client *client = to_i2c_client(dev); \ |
| 332 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 333 | long val = simple_strtol(buf, NULL, 10); \ |
| 334 | \ |
| 335 | down(&data->update_lock); \ |
| 336 | data->pwm[offset-1] = PWM_TO_REG(val, \ |
| 337 | FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \ |
| 338 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \ |
| 339 | data->pwm[offset-1]); \ |
| 340 | up(&data->update_lock); \ |
| 341 | return count; \ |
| 342 | } \ |
| 343 | static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \ |
| 344 | show_pwm##offset, set_pwm##offset); |
| 345 | show_and_set_pwm(1) |
| 346 | show_and_set_pwm(2) |
| 347 | show_and_set_pwm(3) |
| 348 | |
| 349 | #define show_and_set_in(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 350 | static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { \ |
| 352 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 353 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ |
| 354 | data->in_vref)); \ |
| 355 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 356 | static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { \ |
| 358 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 359 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ |
| 360 | data->in_vref)); \ |
| 361 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 362 | static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { \ |
| 364 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 365 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ |
| 366 | data->in_vref)); \ |
| 367 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 368 | static ssize_t show_in##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { \ |
| 370 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 371 | return sprintf(buf, "%u\n", data->in_status[offset]); \ |
| 372 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 373 | static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | size_t count) \ |
| 375 | { \ |
| 376 | struct i2c_client *client = to_i2c_client(dev); \ |
| 377 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 378 | long val = simple_strtol(buf, NULL, 10); \ |
| 379 | \ |
| 380 | down(&data->update_lock); \ |
| 381 | data->in_min[offset] = IN_TO_REG(val, data->in_vref); \ |
| 382 | pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \ |
| 383 | data->in_min[offset]); \ |
| 384 | up(&data->update_lock); \ |
| 385 | return count; \ |
| 386 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 387 | static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | size_t count) \ |
| 389 | { \ |
| 390 | struct i2c_client *client = to_i2c_client(dev); \ |
| 391 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 392 | long val = simple_strtol(buf, NULL, 10); \ |
| 393 | \ |
| 394 | down(&data->update_lock); \ |
| 395 | data->in_max[offset] = IN_TO_REG(val, \ |
| 396 | data->in_vref); \ |
| 397 | pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \ |
| 398 | data->in_max[offset]); \ |
| 399 | up(&data->update_lock); \ |
| 400 | return count; \ |
| 401 | } \ |
| 402 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 403 | show_in##offset##_input, NULL); \ |
| 404 | static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ |
| 405 | show_in##offset##_min, set_in##offset##_min); \ |
| 406 | static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \ |
| 407 | show_in##offset##_max, set_in##offset##_max); \ |
| 408 | static DEVICE_ATTR(in##offset##_status, S_IRUGO, \ |
| 409 | show_in##offset##_status, NULL); |
| 410 | show_and_set_in(0) |
| 411 | show_and_set_in(1) |
| 412 | show_and_set_in(2) |
| 413 | show_and_set_in(3) |
| 414 | show_and_set_in(4) |
| 415 | show_and_set_in(5) |
| 416 | show_and_set_in(6) |
| 417 | show_and_set_in(7) |
| 418 | show_and_set_in(8) |
| 419 | show_and_set_in(9) |
| 420 | show_and_set_in(10) |
| 421 | |
| 422 | #define show_and_set_therm(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 423 | static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { \ |
| 425 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 426 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \ |
| 427 | data->in_vref)); \ |
| 428 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 429 | static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { \ |
| 431 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 432 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \ |
| 433 | data->in_vref)); \ |
| 434 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 435 | static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { \ |
| 437 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 438 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \ |
| 439 | data->in_vref)); \ |
| 440 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 441 | static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { \ |
| 443 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 444 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \ |
| 445 | data->in_vref)); \ |
| 446 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 447 | static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { \ |
| 449 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 450 | return sprintf(buf, "%u\n", data->in_status[offset+7]); \ |
| 451 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 452 | static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | size_t count) \ |
| 454 | { \ |
| 455 | struct i2c_client *client = to_i2c_client(dev); \ |
| 456 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 457 | long val = simple_strtol(buf, NULL, 10); \ |
| 458 | \ |
| 459 | down(&data->update_lock); \ |
| 460 | data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \ |
| 461 | pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \ |
| 462 | data->in_min[offset+7]); \ |
| 463 | up(&data->update_lock); \ |
| 464 | return count; \ |
| 465 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 466 | static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | size_t count) \ |
| 468 | { \ |
| 469 | struct i2c_client *client = to_i2c_client(dev); \ |
| 470 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 471 | long val = simple_strtol(buf, NULL, 10); \ |
| 472 | \ |
| 473 | down(&data->update_lock); \ |
| 474 | data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \ |
| 475 | pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \ |
| 476 | data->in_max[offset+7]); \ |
| 477 | up(&data->update_lock); \ |
| 478 | return count; \ |
| 479 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 480 | static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | size_t count) \ |
| 482 | { \ |
| 483 | struct i2c_client *client = to_i2c_client(dev); \ |
| 484 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 485 | long val = simple_strtol(buf, NULL, 10); \ |
| 486 | \ |
| 487 | down(&data->update_lock); \ |
| 488 | data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \ |
| 489 | pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \ |
| 490 | data->in_crit[offset-4]); \ |
| 491 | up(&data->update_lock); \ |
| 492 | return count; \ |
| 493 | } \ |
| 494 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 495 | show_temp##offset##_input, NULL); \ |
| 496 | static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ |
| 497 | show_temp##offset##_min, set_temp##offset##_min); \ |
| 498 | static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ |
| 499 | show_temp##offset##_max, set_temp##offset##_max); \ |
| 500 | static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ |
| 501 | show_temp##offset##_crit, set_temp##offset##_crit); \ |
| 502 | static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ |
| 503 | show_temp##offset##_status, NULL); |
| 504 | show_and_set_therm(4) |
| 505 | show_and_set_therm(5) |
| 506 | show_and_set_therm(6) |
| 507 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 508 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | struct pc87360_data *data = pc87360_update_device(dev); |
| 511 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); |
| 512 | } |
| 513 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
| 514 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 515 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
| 517 | struct pc87360_data *data = pc87360_update_device(dev); |
| 518 | return sprintf(buf, "%u\n", data->vrm); |
| 519 | } |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 520 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
| 522 | struct i2c_client *client = to_i2c_client(dev); |
| 523 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 524 | data->vrm = simple_strtoul(buf, NULL, 10); |
| 525 | return count; |
| 526 | } |
| 527 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); |
| 528 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 529 | static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
| 531 | struct pc87360_data *data = pc87360_update_device(dev); |
| 532 | return sprintf(buf, "%u\n", data->in_alarms); |
| 533 | } |
| 534 | static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL); |
| 535 | |
| 536 | #define show_and_set_temp(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 537 | static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { \ |
| 539 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 540 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ |
| 541 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 542 | static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { \ |
| 544 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 545 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ |
| 546 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 547 | static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { \ |
| 549 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 550 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ |
| 551 | }\ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 552 | static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { \ |
| 554 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 555 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \ |
| 556 | }\ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 557 | static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { \ |
| 559 | struct pc87360_data *data = pc87360_update_device(dev); \ |
| 560 | return sprintf(buf, "%d\n", data->temp_status[offset-1]); \ |
| 561 | }\ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 562 | static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | size_t count) \ |
| 564 | { \ |
| 565 | struct i2c_client *client = to_i2c_client(dev); \ |
| 566 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 567 | long val = simple_strtol(buf, NULL, 10); \ |
| 568 | \ |
| 569 | down(&data->update_lock); \ |
| 570 | data->temp_min[offset-1] = TEMP_TO_REG(val); \ |
| 571 | pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \ |
| 572 | data->temp_min[offset-1]); \ |
| 573 | up(&data->update_lock); \ |
| 574 | return count; \ |
| 575 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 576 | static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | size_t count) \ |
| 578 | { \ |
| 579 | struct i2c_client *client = to_i2c_client(dev); \ |
| 580 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 581 | long val = simple_strtol(buf, NULL, 10); \ |
| 582 | \ |
| 583 | down(&data->update_lock); \ |
| 584 | data->temp_max[offset-1] = TEMP_TO_REG(val); \ |
| 585 | pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \ |
| 586 | data->temp_max[offset-1]); \ |
| 587 | up(&data->update_lock); \ |
| 588 | return count; \ |
| 589 | } \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 590 | static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | size_t count) \ |
| 592 | { \ |
| 593 | struct i2c_client *client = to_i2c_client(dev); \ |
| 594 | struct pc87360_data *data = i2c_get_clientdata(client); \ |
| 595 | long val = simple_strtol(buf, NULL, 10); \ |
| 596 | \ |
| 597 | down(&data->update_lock); \ |
| 598 | data->temp_crit[offset-1] = TEMP_TO_REG(val); \ |
| 599 | pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \ |
| 600 | data->temp_crit[offset-1]); \ |
| 601 | up(&data->update_lock); \ |
| 602 | return count; \ |
| 603 | } \ |
| 604 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 605 | show_temp##offset##_input, NULL); \ |
| 606 | static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ |
| 607 | show_temp##offset##_min, set_temp##offset##_min); \ |
| 608 | static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ |
| 609 | show_temp##offset##_max, set_temp##offset##_max); \ |
| 610 | static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ |
| 611 | show_temp##offset##_crit, set_temp##offset##_crit); \ |
| 612 | static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ |
| 613 | show_temp##offset##_status, NULL); |
| 614 | show_and_set_temp(1) |
| 615 | show_and_set_temp(2) |
| 616 | show_and_set_temp(3) |
| 617 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 618 | static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | struct pc87360_data *data = pc87360_update_device(dev); |
| 621 | return sprintf(buf, "%u\n", data->temp_alarms); |
| 622 | } |
| 623 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); |
| 624 | |
| 625 | /* |
| 626 | * Device detection, registration and update |
| 627 | */ |
| 628 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 629 | static int pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | u16 val; |
| 632 | int i; |
| 633 | int nrdev; /* logical device count */ |
| 634 | |
| 635 | /* No superio_enter */ |
| 636 | |
| 637 | /* Identify device */ |
| 638 | val = superio_inb(sioaddr, DEVID); |
| 639 | switch (val) { |
| 640 | case 0xE1: /* PC87360 */ |
| 641 | case 0xE8: /* PC87363 */ |
| 642 | case 0xE4: /* PC87364 */ |
| 643 | nrdev = 1; |
| 644 | break; |
| 645 | case 0xE5: /* PC87365 */ |
| 646 | case 0xE9: /* PC87366 */ |
| 647 | nrdev = 3; |
| 648 | break; |
| 649 | default: |
| 650 | superio_exit(sioaddr); |
| 651 | return -ENODEV; |
| 652 | } |
| 653 | /* Remember the device id */ |
| 654 | *devid = val; |
| 655 | |
| 656 | for (i = 0; i < nrdev; i++) { |
| 657 | /* select logical device */ |
| 658 | superio_outb(sioaddr, DEV, logdev[i]); |
| 659 | |
| 660 | val = superio_inb(sioaddr, ACT); |
| 661 | if (!(val & 0x01)) { |
| 662 | printk(KERN_INFO "pc87360: Device 0x%02x not " |
| 663 | "activated\n", logdev[i]); |
| 664 | continue; |
| 665 | } |
| 666 | |
| 667 | val = (superio_inb(sioaddr, BASE) << 8) |
| 668 | | superio_inb(sioaddr, BASE + 1); |
| 669 | if (!val) { |
| 670 | printk(KERN_INFO "pc87360: Base address not set for " |
| 671 | "device 0x%02x\n", logdev[i]); |
| 672 | continue; |
| 673 | } |
| 674 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 675 | addresses[i] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | if (i==0) { /* Fans */ |
| 678 | confreg[0] = superio_inb(sioaddr, 0xF0); |
| 679 | confreg[1] = superio_inb(sioaddr, 0xF1); |
| 680 | |
| 681 | #ifdef DEBUG |
| 682 | printk(KERN_DEBUG "pc87360: Fan 1: mon=%d " |
| 683 | "ctrl=%d inv=%d\n", (confreg[0]>>2)&1, |
| 684 | (confreg[0]>>3)&1, (confreg[0]>>4)&1); |
| 685 | printk(KERN_DEBUG "pc87360: Fan 2: mon=%d " |
| 686 | "ctrl=%d inv=%d\n", (confreg[0]>>5)&1, |
| 687 | (confreg[0]>>6)&1, (confreg[0]>>7)&1); |
| 688 | printk(KERN_DEBUG "pc87360: Fan 3: mon=%d " |
| 689 | "ctrl=%d inv=%d\n", confreg[1]&1, |
| 690 | (confreg[1]>>1)&1, (confreg[1]>>2)&1); |
| 691 | #endif |
| 692 | } else if (i==1) { /* Voltages */ |
| 693 | /* Are we using thermistors? */ |
| 694 | if (*devid == 0xE9) { /* PC87366 */ |
| 695 | /* These registers are not logical-device |
| 696 | specific, just that we won't need them if |
| 697 | we don't use the VLM device */ |
| 698 | confreg[2] = superio_inb(sioaddr, 0x2B); |
| 699 | confreg[3] = superio_inb(sioaddr, 0x25); |
| 700 | |
| 701 | if (confreg[2] & 0x40) { |
| 702 | printk(KERN_INFO "pc87360: Using " |
| 703 | "thermistors for temperature " |
| 704 | "monitoring\n"); |
| 705 | } |
| 706 | if (confreg[3] & 0xE0) { |
| 707 | printk(KERN_INFO "pc87360: VID " |
| 708 | "inputs routed (mode %u)\n", |
| 709 | confreg[3] >> 5); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | superio_exit(sioaddr); |
| 716 | return 0; |
| 717 | } |
| 718 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 719 | static int pc87360_detect(struct i2c_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
| 721 | int i; |
| 722 | struct i2c_client *new_client; |
| 723 | struct pc87360_data *data; |
| 724 | int err = 0; |
| 725 | const char *name = "pc87360"; |
| 726 | int use_thermistors = 0; |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL))) |
| 729 | return -ENOMEM; |
| 730 | memset(data, 0x00, sizeof(struct pc87360_data)); |
| 731 | |
| 732 | new_client = &data->client; |
| 733 | i2c_set_clientdata(new_client, data); |
| 734 | new_client->addr = address; |
| 735 | init_MUTEX(&data->lock); |
| 736 | new_client->adapter = adapter; |
| 737 | new_client->driver = &pc87360_driver; |
| 738 | new_client->flags = 0; |
| 739 | |
| 740 | data->fannr = 2; |
| 741 | data->innr = 0; |
| 742 | data->tempnr = 0; |
| 743 | |
| 744 | switch (devid) { |
| 745 | case 0xe8: |
| 746 | name = "pc87363"; |
| 747 | break; |
| 748 | case 0xe4: |
| 749 | name = "pc87364"; |
| 750 | data->fannr = 3; |
| 751 | break; |
| 752 | case 0xe5: |
| 753 | name = "pc87365"; |
| 754 | data->fannr = extra_isa[0] ? 3 : 0; |
| 755 | data->innr = extra_isa[1] ? 11 : 0; |
| 756 | data->tempnr = extra_isa[2] ? 2 : 0; |
| 757 | break; |
| 758 | case 0xe9: |
| 759 | name = "pc87366"; |
| 760 | data->fannr = extra_isa[0] ? 3 : 0; |
| 761 | data->innr = extra_isa[1] ? 14 : 0; |
| 762 | data->tempnr = extra_isa[2] ? 3 : 0; |
| 763 | break; |
| 764 | } |
| 765 | |
| 766 | strcpy(new_client->name, name); |
| 767 | data->valid = 0; |
| 768 | init_MUTEX(&data->update_lock); |
| 769 | |
| 770 | for (i = 0; i < 3; i++) { |
| 771 | if (((data->address[i] = extra_isa[i])) |
| 772 | && !request_region(extra_isa[i], PC87360_EXTENT, |
| 773 | pc87360_driver.name)) { |
| 774 | dev_err(&new_client->dev, "Region 0x%x-0x%x already " |
| 775 | "in use!\n", extra_isa[i], |
| 776 | extra_isa[i]+PC87360_EXTENT-1); |
| 777 | for (i--; i >= 0; i--) |
| 778 | release_region(extra_isa[i], PC87360_EXTENT); |
| 779 | err = -EBUSY; |
| 780 | goto ERROR1; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | /* Retrieve the fans configuration from Super-I/O space */ |
| 785 | if (data->fannr) |
| 786 | data->fan_conf = confreg[0] | (confreg[1] << 8); |
| 787 | |
| 788 | if ((err = i2c_attach_client(new_client))) |
| 789 | goto ERROR2; |
| 790 | |
| 791 | /* Use the correct reference voltage |
| 792 | Unless both the VLM and the TMS logical devices agree to |
| 793 | use an external Vref, the internal one is used. */ |
| 794 | if (data->innr) { |
| 795 | i = pc87360_read_value(data, LD_IN, NO_BANK, |
| 796 | PC87365_REG_IN_CONFIG); |
| 797 | if (data->tempnr) { |
| 798 | i &= pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 799 | PC87365_REG_TEMP_CONFIG); |
| 800 | } |
| 801 | data->in_vref = (i&0x02) ? 3025 : 2966; |
| 802 | dev_dbg(&new_client->dev, "Using %s reference voltage\n", |
| 803 | (i&0x02) ? "external" : "internal"); |
| 804 | |
| 805 | data->vid_conf = confreg[3]; |
| 806 | data->vrm = 90; |
| 807 | } |
| 808 | |
| 809 | /* Fan clock dividers may be needed before any data is read */ |
| 810 | for (i = 0; i < data->fannr; i++) { |
| 811 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) |
| 812 | data->fan_status[i] = pc87360_read_value(data, |
| 813 | LD_FAN, NO_BANK, |
| 814 | PC87360_REG_FAN_STATUS(i)); |
| 815 | } |
| 816 | |
| 817 | if (init > 0) { |
| 818 | if (devid == 0xe9 && data->address[1]) /* PC87366 */ |
| 819 | use_thermistors = confreg[2] & 0x40; |
| 820 | |
| 821 | pc87360_init_client(new_client, use_thermistors); |
| 822 | } |
| 823 | |
| 824 | /* Register sysfs hooks */ |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 825 | data->class_dev = hwmon_device_register(&new_client->dev); |
| 826 | if (IS_ERR(data->class_dev)) { |
| 827 | err = PTR_ERR(data->class_dev); |
| 828 | goto ERROR3; |
| 829 | } |
| 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | if (data->innr) { |
| 832 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
| 833 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
| 834 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
| 835 | device_create_file(&new_client->dev, &dev_attr_in3_input); |
| 836 | device_create_file(&new_client->dev, &dev_attr_in4_input); |
| 837 | device_create_file(&new_client->dev, &dev_attr_in5_input); |
| 838 | device_create_file(&new_client->dev, &dev_attr_in6_input); |
| 839 | device_create_file(&new_client->dev, &dev_attr_in7_input); |
| 840 | device_create_file(&new_client->dev, &dev_attr_in8_input); |
| 841 | device_create_file(&new_client->dev, &dev_attr_in9_input); |
| 842 | device_create_file(&new_client->dev, &dev_attr_in10_input); |
| 843 | device_create_file(&new_client->dev, &dev_attr_in0_min); |
| 844 | device_create_file(&new_client->dev, &dev_attr_in1_min); |
| 845 | device_create_file(&new_client->dev, &dev_attr_in2_min); |
| 846 | device_create_file(&new_client->dev, &dev_attr_in3_min); |
| 847 | device_create_file(&new_client->dev, &dev_attr_in4_min); |
| 848 | device_create_file(&new_client->dev, &dev_attr_in5_min); |
| 849 | device_create_file(&new_client->dev, &dev_attr_in6_min); |
| 850 | device_create_file(&new_client->dev, &dev_attr_in7_min); |
| 851 | device_create_file(&new_client->dev, &dev_attr_in8_min); |
| 852 | device_create_file(&new_client->dev, &dev_attr_in9_min); |
| 853 | device_create_file(&new_client->dev, &dev_attr_in10_min); |
| 854 | device_create_file(&new_client->dev, &dev_attr_in0_max); |
| 855 | device_create_file(&new_client->dev, &dev_attr_in1_max); |
| 856 | device_create_file(&new_client->dev, &dev_attr_in2_max); |
| 857 | device_create_file(&new_client->dev, &dev_attr_in3_max); |
| 858 | device_create_file(&new_client->dev, &dev_attr_in4_max); |
| 859 | device_create_file(&new_client->dev, &dev_attr_in5_max); |
| 860 | device_create_file(&new_client->dev, &dev_attr_in6_max); |
| 861 | device_create_file(&new_client->dev, &dev_attr_in7_max); |
| 862 | device_create_file(&new_client->dev, &dev_attr_in8_max); |
| 863 | device_create_file(&new_client->dev, &dev_attr_in9_max); |
| 864 | device_create_file(&new_client->dev, &dev_attr_in10_max); |
| 865 | device_create_file(&new_client->dev, &dev_attr_in0_status); |
| 866 | device_create_file(&new_client->dev, &dev_attr_in1_status); |
| 867 | device_create_file(&new_client->dev, &dev_attr_in2_status); |
| 868 | device_create_file(&new_client->dev, &dev_attr_in3_status); |
| 869 | device_create_file(&new_client->dev, &dev_attr_in4_status); |
| 870 | device_create_file(&new_client->dev, &dev_attr_in5_status); |
| 871 | device_create_file(&new_client->dev, &dev_attr_in6_status); |
| 872 | device_create_file(&new_client->dev, &dev_attr_in7_status); |
| 873 | device_create_file(&new_client->dev, &dev_attr_in8_status); |
| 874 | device_create_file(&new_client->dev, &dev_attr_in9_status); |
| 875 | device_create_file(&new_client->dev, &dev_attr_in10_status); |
| 876 | |
| 877 | device_create_file(&new_client->dev, &dev_attr_cpu0_vid); |
| 878 | device_create_file(&new_client->dev, &dev_attr_vrm); |
| 879 | device_create_file(&new_client->dev, &dev_attr_alarms_in); |
| 880 | } |
| 881 | |
| 882 | if (data->tempnr) { |
| 883 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
| 884 | device_create_file(&new_client->dev, &dev_attr_temp2_input); |
| 885 | device_create_file(&new_client->dev, &dev_attr_temp1_min); |
| 886 | device_create_file(&new_client->dev, &dev_attr_temp2_min); |
| 887 | device_create_file(&new_client->dev, &dev_attr_temp1_max); |
| 888 | device_create_file(&new_client->dev, &dev_attr_temp2_max); |
| 889 | device_create_file(&new_client->dev, &dev_attr_temp1_crit); |
| 890 | device_create_file(&new_client->dev, &dev_attr_temp2_crit); |
| 891 | device_create_file(&new_client->dev, &dev_attr_temp1_status); |
| 892 | device_create_file(&new_client->dev, &dev_attr_temp2_status); |
| 893 | |
| 894 | device_create_file(&new_client->dev, &dev_attr_alarms_temp); |
| 895 | } |
| 896 | if (data->tempnr == 3) { |
| 897 | device_create_file(&new_client->dev, &dev_attr_temp3_input); |
| 898 | device_create_file(&new_client->dev, &dev_attr_temp3_min); |
| 899 | device_create_file(&new_client->dev, &dev_attr_temp3_max); |
| 900 | device_create_file(&new_client->dev, &dev_attr_temp3_crit); |
| 901 | device_create_file(&new_client->dev, &dev_attr_temp3_status); |
| 902 | } |
| 903 | if (data->innr == 14) { |
| 904 | device_create_file(&new_client->dev, &dev_attr_temp4_input); |
| 905 | device_create_file(&new_client->dev, &dev_attr_temp5_input); |
| 906 | device_create_file(&new_client->dev, &dev_attr_temp6_input); |
| 907 | device_create_file(&new_client->dev, &dev_attr_temp4_min); |
| 908 | device_create_file(&new_client->dev, &dev_attr_temp5_min); |
| 909 | device_create_file(&new_client->dev, &dev_attr_temp6_min); |
| 910 | device_create_file(&new_client->dev, &dev_attr_temp4_max); |
| 911 | device_create_file(&new_client->dev, &dev_attr_temp5_max); |
| 912 | device_create_file(&new_client->dev, &dev_attr_temp6_max); |
| 913 | device_create_file(&new_client->dev, &dev_attr_temp4_crit); |
| 914 | device_create_file(&new_client->dev, &dev_attr_temp5_crit); |
| 915 | device_create_file(&new_client->dev, &dev_attr_temp6_crit); |
| 916 | device_create_file(&new_client->dev, &dev_attr_temp4_status); |
| 917 | device_create_file(&new_client->dev, &dev_attr_temp5_status); |
| 918 | device_create_file(&new_client->dev, &dev_attr_temp6_status); |
| 919 | } |
| 920 | |
| 921 | if (data->fannr) { |
| 922 | if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) { |
| 923 | device_create_file(&new_client->dev, |
| 924 | &dev_attr_fan1_input); |
| 925 | device_create_file(&new_client->dev, |
| 926 | &dev_attr_fan1_min); |
| 927 | device_create_file(&new_client->dev, |
| 928 | &dev_attr_fan1_div); |
| 929 | device_create_file(&new_client->dev, |
| 930 | &dev_attr_fan1_status); |
| 931 | } |
| 932 | |
| 933 | if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) { |
| 934 | device_create_file(&new_client->dev, |
| 935 | &dev_attr_fan2_input); |
| 936 | device_create_file(&new_client->dev, |
| 937 | &dev_attr_fan2_min); |
| 938 | device_create_file(&new_client->dev, |
| 939 | &dev_attr_fan2_div); |
| 940 | device_create_file(&new_client->dev, |
| 941 | &dev_attr_fan2_status); |
| 942 | } |
| 943 | |
| 944 | if (FAN_CONFIG_CONTROL(data->fan_conf, 0)) |
| 945 | device_create_file(&new_client->dev, &dev_attr_pwm1); |
| 946 | if (FAN_CONFIG_CONTROL(data->fan_conf, 1)) |
| 947 | device_create_file(&new_client->dev, &dev_attr_pwm2); |
| 948 | } |
| 949 | if (data->fannr == 3) { |
| 950 | if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) { |
| 951 | device_create_file(&new_client->dev, |
| 952 | &dev_attr_fan3_input); |
| 953 | device_create_file(&new_client->dev, |
| 954 | &dev_attr_fan3_min); |
| 955 | device_create_file(&new_client->dev, |
| 956 | &dev_attr_fan3_div); |
| 957 | device_create_file(&new_client->dev, |
| 958 | &dev_attr_fan3_status); |
| 959 | } |
| 960 | |
| 961 | if (FAN_CONFIG_CONTROL(data->fan_conf, 2)) |
| 962 | device_create_file(&new_client->dev, &dev_attr_pwm3); |
| 963 | } |
| 964 | |
| 965 | return 0; |
| 966 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 967 | ERROR3: |
| 968 | i2c_detach_client(new_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | ERROR2: |
| 970 | for (i = 0; i < 3; i++) { |
| 971 | if (data->address[i]) { |
| 972 | release_region(data->address[i], PC87360_EXTENT); |
| 973 | } |
| 974 | } |
| 975 | ERROR1: |
| 976 | kfree(data); |
| 977 | return err; |
| 978 | } |
| 979 | |
| 980 | static int pc87360_detach_client(struct i2c_client *client) |
| 981 | { |
| 982 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 983 | int i; |
| 984 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 985 | hwmon_device_unregister(data->class_dev); |
| 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | if ((i = i2c_detach_client(client))) { |
| 988 | dev_err(&client->dev, "Client deregistration failed, " |
| 989 | "client not detached.\n"); |
| 990 | return i; |
| 991 | } |
| 992 | |
| 993 | for (i = 0; i < 3; i++) { |
| 994 | if (data->address[i]) { |
| 995 | release_region(data->address[i], PC87360_EXTENT); |
| 996 | } |
| 997 | } |
| 998 | kfree(data); |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | /* ldi is the logical device index |
| 1004 | bank is for voltages and temperatures only */ |
| 1005 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1006 | u8 reg) |
| 1007 | { |
| 1008 | int res; |
| 1009 | |
| 1010 | down(&(data->lock)); |
| 1011 | if (bank != NO_BANK) |
| 1012 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1013 | res = inb_p(data->address[ldi] + reg); |
| 1014 | up(&(data->lock)); |
| 1015 | |
| 1016 | return res; |
| 1017 | } |
| 1018 | |
| 1019 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1020 | u8 reg, u8 value) |
| 1021 | { |
| 1022 | down(&(data->lock)); |
| 1023 | if (bank != NO_BANK) |
| 1024 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1025 | outb_p(value, data->address[ldi] + reg); |
| 1026 | up(&(data->lock)); |
| 1027 | } |
| 1028 | |
| 1029 | static void pc87360_init_client(struct i2c_client *client, int use_thermistors) |
| 1030 | { |
| 1031 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 1032 | int i, nr; |
| 1033 | const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; |
| 1034 | const u8 init_temp[3] = { 2, 2, 1 }; |
| 1035 | u8 reg; |
| 1036 | |
| 1037 | if (init >= 2 && data->innr) { |
| 1038 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1039 | PC87365_REG_IN_CONVRATE); |
Jean Delvare | 368609c | 2005-07-29 12:15:07 -0700 | [diff] [blame] | 1040 | dev_info(&client->dev, "VLM conversion set to " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | "1s period, 160us delay\n"); |
| 1042 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1043 | PC87365_REG_IN_CONVRATE, |
| 1044 | (reg & 0xC0) | 0x11); |
| 1045 | } |
| 1046 | |
| 1047 | nr = data->innr < 11 ? data->innr : 11; |
| 1048 | for (i=0; i<nr; i++) { |
| 1049 | if (init >= init_in[i]) { |
| 1050 | /* Forcibly enable voltage channel */ |
| 1051 | reg = pc87360_read_value(data, LD_IN, i, |
| 1052 | PC87365_REG_IN_STATUS); |
| 1053 | if (!(reg & 0x01)) { |
| 1054 | dev_dbg(&client->dev, "Forcibly " |
| 1055 | "enabling in%d\n", i); |
| 1056 | pc87360_write_value(data, LD_IN, i, |
| 1057 | PC87365_REG_IN_STATUS, |
| 1058 | (reg & 0x68) | 0x87); |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /* We can't blindly trust the Super-I/O space configuration bit, |
| 1064 | most BIOS won't set it properly */ |
| 1065 | for (i=11; i<data->innr; i++) { |
| 1066 | reg = pc87360_read_value(data, LD_IN, i, |
| 1067 | PC87365_REG_TEMP_STATUS); |
| 1068 | use_thermistors = use_thermistors || (reg & 0x01); |
| 1069 | } |
| 1070 | |
| 1071 | i = use_thermistors ? 2 : 0; |
| 1072 | for (; i<data->tempnr; i++) { |
| 1073 | if (init >= init_temp[i]) { |
| 1074 | /* Forcibly enable temperature channel */ |
| 1075 | reg = pc87360_read_value(data, LD_TEMP, i, |
| 1076 | PC87365_REG_TEMP_STATUS); |
| 1077 | if (!(reg & 0x01)) { |
| 1078 | dev_dbg(&client->dev, "Forcibly " |
| 1079 | "enabling temp%d\n", i+1); |
| 1080 | pc87360_write_value(data, LD_TEMP, i, |
| 1081 | PC87365_REG_TEMP_STATUS, |
| 1082 | 0xCF); |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | if (use_thermistors) { |
| 1088 | for (i=11; i<data->innr; i++) { |
| 1089 | if (init >= init_in[i]) { |
| 1090 | /* The pin may already be used by thermal |
| 1091 | diodes */ |
| 1092 | reg = pc87360_read_value(data, LD_TEMP, |
| 1093 | (i-11)/2, PC87365_REG_TEMP_STATUS); |
| 1094 | if (reg & 0x01) { |
| 1095 | dev_dbg(&client->dev, "Skipping " |
| 1096 | "temp%d, pin already in use " |
| 1097 | "by temp%d\n", i-7, (i-11)/2); |
| 1098 | continue; |
| 1099 | } |
| 1100 | |
| 1101 | /* Forcibly enable thermistor channel */ |
| 1102 | reg = pc87360_read_value(data, LD_IN, i, |
| 1103 | PC87365_REG_IN_STATUS); |
| 1104 | if (!(reg & 0x01)) { |
| 1105 | dev_dbg(&client->dev, "Forcibly " |
| 1106 | "enabling temp%d\n", i-7); |
| 1107 | pc87360_write_value(data, LD_IN, i, |
| 1108 | PC87365_REG_TEMP_STATUS, |
| 1109 | (reg & 0x60) | 0x8F); |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | if (data->innr) { |
| 1116 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1117 | PC87365_REG_IN_CONFIG); |
| 1118 | if (reg & 0x01) { |
| 1119 | dev_dbg(&client->dev, "Forcibly " |
| 1120 | "enabling monitoring (VLM)\n"); |
| 1121 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1122 | PC87365_REG_IN_CONFIG, |
| 1123 | reg & 0xFE); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | if (data->tempnr) { |
| 1128 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 1129 | PC87365_REG_TEMP_CONFIG); |
| 1130 | if (reg & 0x01) { |
| 1131 | dev_dbg(&client->dev, "Forcibly enabling " |
| 1132 | "monitoring (TMS)\n"); |
| 1133 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
| 1134 | PC87365_REG_TEMP_CONFIG, |
| 1135 | reg & 0xFE); |
| 1136 | } |
| 1137 | |
| 1138 | if (init >= 2) { |
| 1139 | /* Chip config as documented by National Semi. */ |
| 1140 | pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); |
| 1141 | /* We voluntarily omit the bank here, in case the |
| 1142 | sequence itself matters. It shouldn't be a problem, |
| 1143 | since nobody else is supposed to access the |
| 1144 | device at that point. */ |
| 1145 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); |
| 1146 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); |
| 1147 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); |
| 1148 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xE, 0x05); |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | static void pc87360_autodiv(struct i2c_client *client, int nr) |
| 1154 | { |
| 1155 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 1156 | u8 old_min = data->fan_min[nr]; |
| 1157 | |
| 1158 | /* Increase clock divider if needed and possible */ |
| 1159 | if ((data->fan_status[nr] & 0x04) /* overflow flag */ |
| 1160 | || (data->fan[nr] >= 224)) { /* next to overflow */ |
| 1161 | if ((data->fan_status[nr] & 0x60) != 0x60) { |
| 1162 | data->fan_status[nr] += 0x20; |
| 1163 | data->fan_min[nr] >>= 1; |
| 1164 | data->fan[nr] >>= 1; |
| 1165 | dev_dbg(&client->dev, "Increasing " |
| 1166 | "clock divider to %d for fan %d\n", |
| 1167 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); |
| 1168 | } |
| 1169 | } else { |
| 1170 | /* Decrease clock divider if possible */ |
| 1171 | while (!(data->fan_min[nr] & 0x80) /* min "nails" divider */ |
| 1172 | && data->fan[nr] < 85 /* bad accuracy */ |
| 1173 | && (data->fan_status[nr] & 0x60) != 0x00) { |
| 1174 | data->fan_status[nr] -= 0x20; |
| 1175 | data->fan_min[nr] <<= 1; |
| 1176 | data->fan[nr] <<= 1; |
| 1177 | dev_dbg(&client->dev, "Decreasing " |
| 1178 | "clock divider to %d for fan %d\n", |
| 1179 | FAN_DIV_FROM_REG(data->fan_status[nr]), |
| 1180 | nr+1); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | /* Write new fan min if it changed */ |
| 1185 | if (old_min != data->fan_min[nr]) { |
| 1186 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1187 | PC87360_REG_FAN_MIN(nr), |
| 1188 | data->fan_min[nr]); |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | static struct pc87360_data *pc87360_update_device(struct device *dev) |
| 1193 | { |
| 1194 | struct i2c_client *client = to_i2c_client(dev); |
| 1195 | struct pc87360_data *data = i2c_get_clientdata(client); |
| 1196 | u8 i; |
| 1197 | |
| 1198 | down(&data->update_lock); |
| 1199 | |
| 1200 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
| 1201 | dev_dbg(&client->dev, "Data update\n"); |
| 1202 | |
| 1203 | /* Fans */ |
| 1204 | for (i = 0; i < data->fannr; i++) { |
| 1205 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { |
| 1206 | data->fan_status[i] = |
| 1207 | pc87360_read_value(data, LD_FAN, |
| 1208 | NO_BANK, PC87360_REG_FAN_STATUS(i)); |
| 1209 | data->fan[i] = pc87360_read_value(data, LD_FAN, |
| 1210 | NO_BANK, PC87360_REG_FAN(i)); |
| 1211 | data->fan_min[i] = pc87360_read_value(data, |
| 1212 | LD_FAN, NO_BANK, |
| 1213 | PC87360_REG_FAN_MIN(i)); |
| 1214 | /* Change clock divider if needed */ |
| 1215 | pc87360_autodiv(client, i); |
| 1216 | /* Clear bits and write new divider */ |
| 1217 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1218 | PC87360_REG_FAN_STATUS(i), |
| 1219 | data->fan_status[i]); |
| 1220 | } |
| 1221 | if (FAN_CONFIG_CONTROL(data->fan_conf, i)) |
| 1222 | data->pwm[i] = pc87360_read_value(data, LD_FAN, |
| 1223 | NO_BANK, PC87360_REG_PWM(i)); |
| 1224 | } |
| 1225 | |
| 1226 | /* Voltages */ |
| 1227 | for (i = 0; i < data->innr; i++) { |
| 1228 | data->in_status[i] = pc87360_read_value(data, LD_IN, i, |
| 1229 | PC87365_REG_IN_STATUS); |
| 1230 | /* Clear bits */ |
| 1231 | pc87360_write_value(data, LD_IN, i, |
| 1232 | PC87365_REG_IN_STATUS, |
| 1233 | data->in_status[i]); |
| 1234 | if ((data->in_status[i] & 0x81) == 0x81) { |
| 1235 | data->in[i] = pc87360_read_value(data, LD_IN, |
| 1236 | i, PC87365_REG_IN); |
| 1237 | } |
| 1238 | if (data->in_status[i] & 0x01) { |
| 1239 | data->in_min[i] = pc87360_read_value(data, |
| 1240 | LD_IN, i, |
| 1241 | PC87365_REG_IN_MIN); |
| 1242 | data->in_max[i] = pc87360_read_value(data, |
| 1243 | LD_IN, i, |
| 1244 | PC87365_REG_IN_MAX); |
| 1245 | if (i >= 11) |
| 1246 | data->in_crit[i-11] = |
| 1247 | pc87360_read_value(data, LD_IN, |
| 1248 | i, PC87365_REG_TEMP_CRIT); |
| 1249 | } |
| 1250 | } |
| 1251 | if (data->innr) { |
| 1252 | data->in_alarms = pc87360_read_value(data, LD_IN, |
| 1253 | NO_BANK, PC87365_REG_IN_ALARMS1) |
| 1254 | | ((pc87360_read_value(data, LD_IN, |
| 1255 | NO_BANK, PC87365_REG_IN_ALARMS2) |
| 1256 | & 0x07) << 8); |
| 1257 | data->vid = (data->vid_conf & 0xE0) ? |
| 1258 | pc87360_read_value(data, LD_IN, |
| 1259 | NO_BANK, PC87365_REG_VID) : 0x1F; |
| 1260 | } |
| 1261 | |
| 1262 | /* Temperatures */ |
| 1263 | for (i = 0; i < data->tempnr; i++) { |
| 1264 | data->temp_status[i] = pc87360_read_value(data, |
| 1265 | LD_TEMP, i, |
| 1266 | PC87365_REG_TEMP_STATUS); |
| 1267 | /* Clear bits */ |
| 1268 | pc87360_write_value(data, LD_TEMP, i, |
| 1269 | PC87365_REG_TEMP_STATUS, |
| 1270 | data->temp_status[i]); |
| 1271 | if ((data->temp_status[i] & 0x81) == 0x81) { |
| 1272 | data->temp[i] = pc87360_read_value(data, |
| 1273 | LD_TEMP, i, |
| 1274 | PC87365_REG_TEMP); |
| 1275 | } |
| 1276 | if (data->temp_status[i] & 0x01) { |
| 1277 | data->temp_min[i] = pc87360_read_value(data, |
| 1278 | LD_TEMP, i, |
| 1279 | PC87365_REG_TEMP_MIN); |
| 1280 | data->temp_max[i] = pc87360_read_value(data, |
| 1281 | LD_TEMP, i, |
| 1282 | PC87365_REG_TEMP_MAX); |
| 1283 | data->temp_crit[i] = pc87360_read_value(data, |
| 1284 | LD_TEMP, i, |
| 1285 | PC87365_REG_TEMP_CRIT); |
| 1286 | } |
| 1287 | } |
| 1288 | if (data->tempnr) { |
| 1289 | data->temp_alarms = pc87360_read_value(data, LD_TEMP, |
| 1290 | NO_BANK, PC87365_REG_TEMP_ALARMS) |
| 1291 | & 0x3F; |
| 1292 | } |
| 1293 | |
| 1294 | data->last_updated = jiffies; |
| 1295 | data->valid = 1; |
| 1296 | } |
| 1297 | |
| 1298 | up(&data->update_lock); |
| 1299 | |
| 1300 | return data; |
| 1301 | } |
| 1302 | |
| 1303 | static int __init pc87360_init(void) |
| 1304 | { |
| 1305 | int i; |
| 1306 | |
| 1307 | if (pc87360_find(0x2e, &devid, extra_isa) |
| 1308 | && pc87360_find(0x4e, &devid, extra_isa)) { |
| 1309 | printk(KERN_WARNING "pc87360: PC8736x not detected, " |
| 1310 | "module not inserted.\n"); |
| 1311 | return -ENODEV; |
| 1312 | } |
| 1313 | |
| 1314 | /* Arbitrarily pick one of the addresses */ |
| 1315 | for (i = 0; i < 3; i++) { |
| 1316 | if (extra_isa[i] != 0x0000) { |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 1317 | address = extra_isa[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame^] | 1322 | if (address == 0x0000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | printk(KERN_WARNING "pc87360: No active logical device, " |
| 1324 | "module not inserted.\n"); |
| 1325 | return -ENODEV; |
| 1326 | } |
| 1327 | |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 1328 | return i2c_isa_add_driver(&pc87360_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void __exit pc87360_exit(void) |
| 1332 | { |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 1333 | i2c_isa_del_driver(&pc87360_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 1338 | MODULE_DESCRIPTION("PC8736x hardware monitor"); |
| 1339 | MODULE_LICENSE("GPL"); |
| 1340 | |
| 1341 | module_init(pc87360_init); |
| 1342 | module_exit(pc87360_exit); |