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 |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 40 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 41 | #include <linux/hwmon.h> |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 42 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 43 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 44 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 45 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/io.h> |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static u8 devid; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 49 | static struct platform_device *pdev; |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 50 | static unsigned short extra_isa[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static u8 confreg[4]; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | static int init = 1; |
| 54 | module_param(init, int, 0); |
| 55 | MODULE_PARM_DESC(init, |
| 56 | "Chip initialization level:\n" |
| 57 | " 0: None\n" |
| 58 | "*1: Forcibly enable internal voltage and temperature channels, except in9\n" |
| 59 | " 2: Forcibly enable all voltage and temperature channels, except in9\n" |
| 60 | " 3: Forcibly enable all voltage and temperature channels, including in9"); |
| 61 | |
| 62 | /* |
| 63 | * Super-I/O registers and operations |
| 64 | */ |
| 65 | |
| 66 | #define DEV 0x07 /* Register: Logical device select */ |
| 67 | #define DEVID 0x20 /* Register: Device ID */ |
| 68 | #define ACT 0x30 /* Register: Device activation */ |
| 69 | #define BASE 0x60 /* Register: Base address */ |
| 70 | |
| 71 | #define FSCM 0x09 /* Logical device: fans */ |
| 72 | #define VLM 0x0d /* Logical device: voltages */ |
| 73 | #define TMS 0x0e /* Logical device: temperatures */ |
| 74 | static const u8 logdev[3] = { FSCM, VLM, TMS }; |
| 75 | |
| 76 | #define LD_FAN 0 |
| 77 | #define LD_IN 1 |
| 78 | #define LD_TEMP 2 |
| 79 | |
| 80 | static inline void superio_outb(int sioaddr, int reg, int val) |
| 81 | { |
| 82 | outb(reg, sioaddr); |
| 83 | outb(val, sioaddr+1); |
| 84 | } |
| 85 | |
| 86 | static inline int superio_inb(int sioaddr, int reg) |
| 87 | { |
| 88 | outb(reg, sioaddr); |
| 89 | return inb(sioaddr+1); |
| 90 | } |
| 91 | |
| 92 | static inline void superio_exit(int sioaddr) |
| 93 | { |
| 94 | outb(0x02, sioaddr); |
| 95 | outb(0x02, sioaddr+1); |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Logical devices |
| 100 | */ |
| 101 | |
| 102 | #define PC87360_EXTENT 0x10 |
| 103 | #define PC87365_REG_BANK 0x09 |
| 104 | #define NO_BANK 0xff |
| 105 | |
| 106 | /* |
| 107 | * Fan registers and conversions |
| 108 | */ |
| 109 | |
| 110 | /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */ |
| 111 | #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr)) |
| 112 | #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr)) |
| 113 | #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr)) |
| 114 | #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) |
| 115 | #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) |
| 116 | |
| 117 | #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \ |
| 118 | 480000 / ((val)*(div))) |
| 119 | #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \ |
| 120 | 480000 / ((val)*(div))) |
| 121 | #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03)) |
| 122 | #define FAN_STATUS_FROM_REG(val) ((val) & 0x07) |
| 123 | |
| 124 | #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1) |
| 125 | #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1) |
| 126 | #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1) |
| 127 | |
| 128 | #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val)) |
| 129 | static inline u8 PWM_TO_REG(int val, int inv) |
| 130 | { |
| 131 | if (inv) |
| 132 | val = 255 - val; |
| 133 | if (val < 0) |
| 134 | return 0; |
| 135 | if (val > 255) |
| 136 | return 255; |
| 137 | return val; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Voltage registers and conversions |
| 142 | */ |
| 143 | |
| 144 | #define PC87365_REG_IN_CONVRATE 0x07 |
| 145 | #define PC87365_REG_IN_CONFIG 0x08 |
| 146 | #define PC87365_REG_IN 0x0B |
| 147 | #define PC87365_REG_IN_MIN 0x0D |
| 148 | #define PC87365_REG_IN_MAX 0x0C |
| 149 | #define PC87365_REG_IN_STATUS 0x0A |
| 150 | #define PC87365_REG_IN_ALARMS1 0x00 |
| 151 | #define PC87365_REG_IN_ALARMS2 0x01 |
| 152 | #define PC87365_REG_VID 0x06 |
| 153 | |
| 154 | #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256) |
| 155 | #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \ |
| 156 | (val)*256 >= (ref)*255 ? 255: \ |
| 157 | ((val) * 256 + (ref)/2) / (ref)) |
| 158 | |
| 159 | /* |
| 160 | * Temperature registers and conversions |
| 161 | */ |
| 162 | |
| 163 | #define PC87365_REG_TEMP_CONFIG 0x08 |
| 164 | #define PC87365_REG_TEMP 0x0B |
| 165 | #define PC87365_REG_TEMP_MIN 0x0D |
| 166 | #define PC87365_REG_TEMP_MAX 0x0C |
| 167 | #define PC87365_REG_TEMP_CRIT 0x0E |
| 168 | #define PC87365_REG_TEMP_STATUS 0x0A |
| 169 | #define PC87365_REG_TEMP_ALARMS 0x00 |
| 170 | |
| 171 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 172 | #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \ |
| 173 | (val) > 127000 ? 127 : \ |
| 174 | (val) < 0 ? ((val) - 500) / 1000 : \ |
| 175 | ((val) + 500) / 1000) |
| 176 | |
| 177 | /* |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 178 | * Device data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
| 180 | |
| 181 | struct pc87360_data { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 182 | const char *name; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 183 | struct class_device *class_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 184 | struct mutex lock; |
| 185 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | char valid; /* !=0 if following fields are valid */ |
| 187 | unsigned long last_updated; /* In jiffies */ |
| 188 | |
| 189 | int address[3]; |
| 190 | |
| 191 | u8 fannr, innr, tempnr; |
| 192 | |
| 193 | u8 fan[3]; /* Register value */ |
| 194 | u8 fan_min[3]; /* Register value */ |
| 195 | u8 fan_status[3]; /* Register value */ |
| 196 | u8 pwm[3]; /* Register value */ |
| 197 | u16 fan_conf; /* Configuration register values, combined */ |
| 198 | |
| 199 | u16 in_vref; /* 1 mV/bit */ |
| 200 | u8 in[14]; /* Register value */ |
| 201 | u8 in_min[14]; /* Register value */ |
| 202 | u8 in_max[14]; /* Register value */ |
| 203 | u8 in_crit[3]; /* Register value */ |
| 204 | u8 in_status[14]; /* Register value */ |
| 205 | u16 in_alarms; /* Register values, combined, masked */ |
| 206 | u8 vid_conf; /* Configuration register value */ |
| 207 | u8 vrm; |
| 208 | u8 vid; /* Register value */ |
| 209 | |
| 210 | s8 temp[3]; /* Register value */ |
| 211 | s8 temp_min[3]; /* Register value */ |
| 212 | s8 temp_max[3]; /* Register value */ |
| 213 | s8 temp_crit[3]; /* Register value */ |
| 214 | u8 temp_status[3]; /* Register value */ |
| 215 | u8 temp_alarms; /* Register value, masked */ |
| 216 | }; |
| 217 | |
| 218 | /* |
| 219 | * Functions declaration |
| 220 | */ |
| 221 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 222 | static int pc87360_probe(struct platform_device *pdev); |
| 223 | static int pc87360_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 226 | u8 reg); |
| 227 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 228 | u8 reg, u8 value); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 229 | static void pc87360_init_device(struct platform_device *pdev, |
| 230 | int use_thermistors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static struct pc87360_data *pc87360_update_device(struct device *dev); |
| 232 | |
| 233 | /* |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 234 | * Driver data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | */ |
| 236 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 237 | static struct platform_driver pc87360_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 238 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 239 | .owner = THIS_MODULE, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 240 | .name = "pc87360", |
| 241 | }, |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 242 | .probe = pc87360_probe, |
| 243 | .remove = __devexit_p(pc87360_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | /* |
| 247 | * Sysfs stuff |
| 248 | */ |
| 249 | |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 250 | static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) |
| 251 | { |
| 252 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 253 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 254 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], |
| 255 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 256 | } |
| 257 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 258 | { |
| 259 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 260 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 261 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], |
| 262 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 263 | } |
| 264 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) |
| 265 | { |
| 266 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 267 | struct pc87360_data *data = pc87360_update_device(dev); |
| 268 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 269 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 270 | } |
| 271 | static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) |
| 272 | { |
| 273 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 274 | struct pc87360_data *data = pc87360_update_device(dev); |
| 275 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 276 | FAN_STATUS_FROM_REG(data->fan_status[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 277 | } |
| 278 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 279 | size_t count) |
| 280 | { |
| 281 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 282 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 283 | long fan_min = simple_strtol(buf, NULL, 10); |
| 284 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 285 | mutex_lock(&data->update_lock); |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 286 | fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); |
| 287 | |
| 288 | /* If it wouldn't fit, change clock divisor */ |
| 289 | while (fan_min > 255 |
| 290 | && (data->fan_status[attr->index] & 0x60) != 0x60) { |
| 291 | fan_min >>= 1; |
| 292 | data->fan[attr->index] >>= 1; |
| 293 | data->fan_status[attr->index] += 0x20; |
| 294 | } |
| 295 | data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; |
| 296 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index), |
| 297 | data->fan_min[attr->index]); |
| 298 | |
| 299 | /* Write new divider, preserve alarm bits */ |
| 300 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), |
| 301 | data->fan_status[attr->index] & 0xF9); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 302 | mutex_unlock(&data->update_lock); |
Jim Cromie | 11be27e | 2005-09-02 23:05:07 +0200 | [diff] [blame] | 303 | |
| 304 | return count; |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 307 | static struct sensor_device_attribute fan_input[] = { |
| 308 | SENSOR_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0), |
| 309 | SENSOR_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1), |
| 310 | SENSOR_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2), |
| 311 | }; |
| 312 | static struct sensor_device_attribute fan_status[] = { |
| 313 | SENSOR_ATTR(fan1_status, S_IRUGO, show_fan_status, NULL, 0), |
| 314 | SENSOR_ATTR(fan2_status, S_IRUGO, show_fan_status, NULL, 1), |
| 315 | SENSOR_ATTR(fan3_status, S_IRUGO, show_fan_status, NULL, 2), |
| 316 | }; |
| 317 | static struct sensor_device_attribute fan_div[] = { |
| 318 | SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0), |
| 319 | SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1), |
| 320 | SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2), |
| 321 | }; |
| 322 | static struct sensor_device_attribute fan_min[] = { |
| 323 | SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 0), |
| 324 | SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 1), |
| 325 | SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), |
| 326 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 328 | #define FAN_UNIT_ATTRS(X) \ |
| 329 | &fan_input[X].dev_attr.attr, \ |
| 330 | &fan_status[X].dev_attr.attr, \ |
| 331 | &fan_div[X].dev_attr.attr, \ |
| 332 | &fan_min[X].dev_attr.attr |
| 333 | |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 334 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) |
| 335 | { |
| 336 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 337 | struct pc87360_data *data = pc87360_update_device(dev); |
| 338 | return sprintf(buf, "%u\n", |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 339 | PWM_FROM_REG(data->pwm[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 340 | FAN_CONFIG_INVERT(data->fan_conf, |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 341 | attr->index))); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 342 | } |
| 343 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 344 | size_t count) |
| 345 | { |
| 346 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 347 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 348 | long val = simple_strtol(buf, NULL, 10); |
| 349 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 350 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 351 | data->pwm[attr->index] = PWM_TO_REG(val, |
| 352 | FAN_CONFIG_INVERT(data->fan_conf, attr->index)); |
| 353 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index), |
| 354 | data->pwm[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 355 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 356 | return count; |
| 357 | } |
| 358 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 359 | static struct sensor_device_attribute pwm[] = { |
| 360 | SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0), |
| 361 | SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1), |
| 362 | SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), |
| 363 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 365 | static struct attribute * pc8736x_fan_attr_array[] = { |
| 366 | FAN_UNIT_ATTRS(0), |
| 367 | FAN_UNIT_ATTRS(1), |
| 368 | FAN_UNIT_ATTRS(2), |
| 369 | &pwm[0].dev_attr.attr, |
| 370 | &pwm[1].dev_attr.attr, |
| 371 | &pwm[2].dev_attr.attr, |
| 372 | NULL |
| 373 | }; |
| 374 | static const struct attribute_group pc8736x_fan_group = { |
| 375 | .attrs = pc8736x_fan_attr_array, |
| 376 | }; |
| 377 | |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 378 | static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) |
| 379 | { |
| 380 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 381 | struct pc87360_data *data = pc87360_update_device(dev); |
| 382 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
| 383 | data->in_vref)); |
| 384 | } |
| 385 | static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 386 | { |
| 387 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 388 | struct pc87360_data *data = pc87360_update_device(dev); |
| 389 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
| 390 | data->in_vref)); |
| 391 | } |
| 392 | static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) |
| 393 | { |
| 394 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 395 | struct pc87360_data *data = pc87360_update_device(dev); |
| 396 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
| 397 | data->in_vref)); |
| 398 | } |
| 399 | static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) |
| 400 | { |
| 401 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 402 | struct pc87360_data *data = pc87360_update_device(dev); |
| 403 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
| 404 | } |
| 405 | static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 406 | size_t count) |
| 407 | { |
| 408 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 409 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 410 | long val = simple_strtol(buf, NULL, 10); |
| 411 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 412 | mutex_lock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 413 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
| 414 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN, |
| 415 | data->in_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 416 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 417 | return count; |
| 418 | } |
| 419 | static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 420 | size_t count) |
| 421 | { |
| 422 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 423 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 424 | long val = simple_strtol(buf, NULL, 10); |
| 425 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 426 | mutex_lock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 427 | data->in_max[attr->index] = IN_TO_REG(val, |
| 428 | data->in_vref); |
| 429 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX, |
| 430 | data->in_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 431 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 432 | return count; |
| 433 | } |
| 434 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 435 | static struct sensor_device_attribute in_input[] = { |
| 436 | SENSOR_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0), |
| 437 | SENSOR_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1), |
| 438 | SENSOR_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2), |
| 439 | SENSOR_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3), |
| 440 | SENSOR_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4), |
| 441 | SENSOR_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5), |
| 442 | SENSOR_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6), |
| 443 | SENSOR_ATTR(in7_input, S_IRUGO, show_in_input, NULL, 7), |
| 444 | SENSOR_ATTR(in8_input, S_IRUGO, show_in_input, NULL, 8), |
| 445 | SENSOR_ATTR(in9_input, S_IRUGO, show_in_input, NULL, 9), |
| 446 | SENSOR_ATTR(in10_input, S_IRUGO, show_in_input, NULL, 10), |
| 447 | }; |
| 448 | static struct sensor_device_attribute in_status[] = { |
| 449 | SENSOR_ATTR(in0_status, S_IRUGO, show_in_status, NULL, 0), |
| 450 | SENSOR_ATTR(in1_status, S_IRUGO, show_in_status, NULL, 1), |
| 451 | SENSOR_ATTR(in2_status, S_IRUGO, show_in_status, NULL, 2), |
| 452 | SENSOR_ATTR(in3_status, S_IRUGO, show_in_status, NULL, 3), |
| 453 | SENSOR_ATTR(in4_status, S_IRUGO, show_in_status, NULL, 4), |
| 454 | SENSOR_ATTR(in5_status, S_IRUGO, show_in_status, NULL, 5), |
| 455 | SENSOR_ATTR(in6_status, S_IRUGO, show_in_status, NULL, 6), |
| 456 | SENSOR_ATTR(in7_status, S_IRUGO, show_in_status, NULL, 7), |
| 457 | SENSOR_ATTR(in8_status, S_IRUGO, show_in_status, NULL, 8), |
| 458 | SENSOR_ATTR(in9_status, S_IRUGO, show_in_status, NULL, 9), |
| 459 | SENSOR_ATTR(in10_status, S_IRUGO, show_in_status, NULL, 10), |
| 460 | }; |
| 461 | static struct sensor_device_attribute in_min[] = { |
| 462 | SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 0), |
| 463 | SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 1), |
| 464 | SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 2), |
| 465 | SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 3), |
| 466 | SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 4), |
| 467 | SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 5), |
| 468 | SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 6), |
| 469 | SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 7), |
| 470 | SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 8), |
| 471 | SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 9), |
| 472 | SENSOR_ATTR(in10_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 10), |
| 473 | }; |
| 474 | static struct sensor_device_attribute in_max[] = { |
| 475 | SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 0), |
| 476 | SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 1), |
| 477 | SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 2), |
| 478 | SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 3), |
| 479 | SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 4), |
| 480 | SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 5), |
| 481 | SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 6), |
| 482 | SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 7), |
| 483 | SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 8), |
| 484 | SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 9), |
| 485 | SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10), |
| 486 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 488 | #define VIN_UNIT_ATTRS(X) \ |
| 489 | &in_input[X].dev_attr.attr, \ |
| 490 | &in_status[X].dev_attr.attr, \ |
| 491 | &in_min[X].dev_attr.attr, \ |
| 492 | &in_max[X].dev_attr.attr |
| 493 | |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 494 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
| 495 | { |
| 496 | struct pc87360_data *data = pc87360_update_device(dev); |
| 497 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); |
| 498 | } |
| 499 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
| 500 | |
| 501 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) |
| 502 | { |
| 503 | struct pc87360_data *data = pc87360_update_device(dev); |
| 504 | return sprintf(buf, "%u\n", data->vrm); |
| 505 | } |
| 506 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 507 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 508 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | 44646c1 | 2006-09-24 21:01:56 +0200 | [diff] [blame] | 509 | data->vrm = simple_strtoul(buf, NULL, 10); |
| 510 | return count; |
| 511 | } |
| 512 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); |
| 513 | |
| 514 | static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
| 515 | { |
| 516 | struct pc87360_data *data = pc87360_update_device(dev); |
| 517 | return sprintf(buf, "%u\n", data->in_alarms); |
| 518 | } |
| 519 | static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL); |
| 520 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 521 | static struct attribute *pc8736x_vin_attr_array[] = { |
| 522 | VIN_UNIT_ATTRS(0), |
| 523 | VIN_UNIT_ATTRS(1), |
| 524 | VIN_UNIT_ATTRS(2), |
| 525 | VIN_UNIT_ATTRS(3), |
| 526 | VIN_UNIT_ATTRS(4), |
| 527 | VIN_UNIT_ATTRS(5), |
| 528 | VIN_UNIT_ATTRS(6), |
| 529 | VIN_UNIT_ATTRS(7), |
| 530 | VIN_UNIT_ATTRS(8), |
| 531 | VIN_UNIT_ATTRS(9), |
| 532 | VIN_UNIT_ATTRS(10), |
| 533 | &dev_attr_cpu0_vid.attr, |
| 534 | &dev_attr_vrm.attr, |
| 535 | &dev_attr_alarms_in.attr, |
| 536 | NULL |
| 537 | }; |
| 538 | static const struct attribute_group pc8736x_vin_group = { |
| 539 | .attrs = pc8736x_vin_attr_array, |
| 540 | }; |
| 541 | |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 542 | static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) |
| 543 | { |
| 544 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 545 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 546 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 547 | data->in_vref)); |
| 548 | } |
| 549 | static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 550 | { |
| 551 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 552 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 553 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 554 | data->in_vref)); |
| 555 | } |
| 556 | static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) |
| 557 | { |
| 558 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 559 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 560 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 561 | data->in_vref)); |
| 562 | } |
| 563 | static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) |
| 564 | { |
| 565 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 566 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 567 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 568 | data->in_vref)); |
| 569 | } |
| 570 | static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) |
| 571 | { |
| 572 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 573 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 574 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 575 | } |
| 576 | static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 577 | size_t count) |
| 578 | { |
| 579 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 580 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 581 | long val = simple_strtol(buf, NULL, 10); |
| 582 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 583 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 584 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
| 585 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN, |
| 586 | data->in_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 587 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 588 | return count; |
| 589 | } |
| 590 | static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 591 | size_t count) |
| 592 | { |
| 593 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 594 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 595 | long val = simple_strtol(buf, NULL, 10); |
| 596 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 597 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 598 | data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); |
| 599 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX, |
| 600 | data->in_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 601 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 602 | return count; |
| 603 | } |
| 604 | static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 605 | size_t count) |
| 606 | { |
| 607 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 608 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 609 | long val = simple_strtol(buf, NULL, 10); |
| 610 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 611 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 612 | data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); |
| 613 | pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT, |
| 614 | data->in_crit[attr->index-11]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 615 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 616 | return count; |
| 617 | } |
| 618 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 619 | /* the +11 term below reflects the fact that VLM units 11,12,13 are |
| 620 | used in the chip to measure voltage across the thermistors |
| 621 | */ |
| 622 | static struct sensor_device_attribute therm_input[] = { |
| 623 | SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11), |
| 624 | SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11), |
| 625 | SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11), |
| 626 | }; |
| 627 | static struct sensor_device_attribute therm_status[] = { |
| 628 | SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11), |
| 629 | SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11), |
| 630 | SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11), |
| 631 | }; |
| 632 | static struct sensor_device_attribute therm_min[] = { |
| 633 | SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, |
| 634 | show_therm_min, set_therm_min, 0+11), |
| 635 | SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, |
| 636 | show_therm_min, set_therm_min, 1+11), |
| 637 | SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, |
| 638 | show_therm_min, set_therm_min, 2+11), |
| 639 | }; |
| 640 | static struct sensor_device_attribute therm_max[] = { |
| 641 | SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, |
| 642 | show_therm_max, set_therm_max, 0+11), |
| 643 | SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, |
| 644 | show_therm_max, set_therm_max, 1+11), |
| 645 | SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, |
| 646 | show_therm_max, set_therm_max, 2+11), |
| 647 | }; |
| 648 | static struct sensor_device_attribute therm_crit[] = { |
| 649 | SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, |
| 650 | show_therm_crit, set_therm_crit, 0+11), |
| 651 | SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, |
| 652 | show_therm_crit, set_therm_crit, 1+11), |
| 653 | SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, |
| 654 | show_therm_crit, set_therm_crit, 2+11), |
| 655 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 657 | #define THERM_UNIT_ATTRS(X) \ |
| 658 | &therm_input[X].dev_attr.attr, \ |
| 659 | &therm_status[X].dev_attr.attr, \ |
| 660 | &therm_min[X].dev_attr.attr, \ |
| 661 | &therm_max[X].dev_attr.attr, \ |
| 662 | &therm_crit[X].dev_attr.attr |
| 663 | |
| 664 | static struct attribute * pc8736x_therm_attr_array[] = { |
| 665 | THERM_UNIT_ATTRS(0), |
| 666 | THERM_UNIT_ATTRS(1), |
| 667 | THERM_UNIT_ATTRS(2), |
| 668 | NULL |
| 669 | }; |
| 670 | static const struct attribute_group pc8736x_therm_group = { |
| 671 | .attrs = pc8736x_therm_attr_array, |
| 672 | }; |
| 673 | |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 674 | static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) |
| 675 | { |
| 676 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 677 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 678 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 679 | } |
| 680 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 681 | { |
| 682 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 683 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 684 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 685 | } |
| 686 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) |
| 687 | { |
| 688 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 689 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 690 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 691 | } |
| 692 | static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) |
| 693 | { |
| 694 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 695 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 696 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 697 | } |
| 698 | static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) |
| 699 | { |
| 700 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 701 | struct pc87360_data *data = pc87360_update_device(dev); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 702 | return sprintf(buf, "%d\n", data->temp_status[attr->index]); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 703 | } |
| 704 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 705 | size_t count) |
| 706 | { |
| 707 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 708 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 709 | long val = simple_strtol(buf, NULL, 10); |
| 710 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 711 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 712 | data->temp_min[attr->index] = TEMP_TO_REG(val); |
| 713 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN, |
| 714 | data->temp_min[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 715 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 716 | return count; |
| 717 | } |
| 718 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 719 | size_t count) |
| 720 | { |
| 721 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 722 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 723 | long val = simple_strtol(buf, NULL, 10); |
| 724 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 725 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 726 | data->temp_max[attr->index] = TEMP_TO_REG(val); |
| 727 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX, |
| 728 | data->temp_max[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 729 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 730 | return count; |
| 731 | } |
| 732 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, |
| 733 | size_t count) |
| 734 | { |
| 735 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 736 | struct pc87360_data *data = dev_get_drvdata(dev); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 737 | long val = simple_strtol(buf, NULL, 10); |
| 738 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 739 | mutex_lock(&data->update_lock); |
Jim Cromie | 694fa05 | 2005-09-02 22:57:52 +0200 | [diff] [blame] | 740 | data->temp_crit[attr->index] = TEMP_TO_REG(val); |
| 741 | pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT, |
| 742 | data->temp_crit[attr->index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 743 | mutex_unlock(&data->update_lock); |
Jim Cromie | f0986bd | 2005-09-02 22:52:43 +0200 | [diff] [blame] | 744 | return count; |
| 745 | } |
| 746 | |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 747 | static struct sensor_device_attribute temp_input[] = { |
| 748 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0), |
| 749 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1), |
| 750 | SENSOR_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2), |
| 751 | }; |
| 752 | static struct sensor_device_attribute temp_status[] = { |
| 753 | SENSOR_ATTR(temp1_status, S_IRUGO, show_temp_status, NULL, 0), |
| 754 | SENSOR_ATTR(temp2_status, S_IRUGO, show_temp_status, NULL, 1), |
| 755 | SENSOR_ATTR(temp3_status, S_IRUGO, show_temp_status, NULL, 2), |
| 756 | }; |
| 757 | static struct sensor_device_attribute temp_min[] = { |
| 758 | SENSOR_ATTR(temp1_min, S_IRUGO | S_IWUSR, |
| 759 | show_temp_min, set_temp_min, 0), |
| 760 | SENSOR_ATTR(temp2_min, S_IRUGO | S_IWUSR, |
| 761 | show_temp_min, set_temp_min, 1), |
| 762 | SENSOR_ATTR(temp3_min, S_IRUGO | S_IWUSR, |
| 763 | show_temp_min, set_temp_min, 2), |
| 764 | }; |
| 765 | static struct sensor_device_attribute temp_max[] = { |
| 766 | SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, |
| 767 | show_temp_max, set_temp_max, 0), |
| 768 | SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, |
| 769 | show_temp_max, set_temp_max, 1), |
| 770 | SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, |
| 771 | show_temp_max, set_temp_max, 2), |
| 772 | }; |
| 773 | static struct sensor_device_attribute temp_crit[] = { |
| 774 | SENSOR_ATTR(temp1_crit, S_IRUGO | S_IWUSR, |
| 775 | show_temp_crit, set_temp_crit, 0), |
| 776 | SENSOR_ATTR(temp2_crit, S_IRUGO | S_IWUSR, |
| 777 | show_temp_crit, set_temp_crit, 1), |
| 778 | SENSOR_ATTR(temp3_crit, S_IRUGO | S_IWUSR, |
| 779 | show_temp_crit, set_temp_crit, 2), |
| 780 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 782 | 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] | 783 | { |
| 784 | struct pc87360_data *data = pc87360_update_device(dev); |
| 785 | return sprintf(buf, "%u\n", data->temp_alarms); |
| 786 | } |
| 787 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); |
| 788 | |
Jim Cromie | 941c5c0 | 2006-09-24 21:02:44 +0200 | [diff] [blame] | 789 | #define TEMP_UNIT_ATTRS(X) \ |
| 790 | &temp_input[X].dev_attr.attr, \ |
| 791 | &temp_status[X].dev_attr.attr, \ |
| 792 | &temp_min[X].dev_attr.attr, \ |
| 793 | &temp_max[X].dev_attr.attr, \ |
| 794 | &temp_crit[X].dev_attr.attr |
| 795 | |
| 796 | static struct attribute * pc8736x_temp_attr_array[] = { |
| 797 | TEMP_UNIT_ATTRS(0), |
| 798 | TEMP_UNIT_ATTRS(1), |
| 799 | TEMP_UNIT_ATTRS(2), |
| 800 | /* include the few miscellaneous atts here */ |
| 801 | &dev_attr_alarms_temp.attr, |
| 802 | NULL |
| 803 | }; |
| 804 | static const struct attribute_group pc8736x_temp_group = { |
| 805 | .attrs = pc8736x_temp_attr_array, |
| 806 | }; |
| 807 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 808 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 809 | *devattr, char *buf) |
| 810 | { |
| 811 | struct pc87360_data *data = dev_get_drvdata(dev); |
| 812 | return sprintf(buf, "%s\n", data->name); |
| 813 | } |
| 814 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | /* |
| 817 | * Device detection, registration and update |
| 818 | */ |
| 819 | |
Jean Delvare | e6cfb3a | 2005-07-27 21:32:02 +0200 | [diff] [blame] | 820 | static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
| 822 | u16 val; |
| 823 | int i; |
| 824 | int nrdev; /* logical device count */ |
| 825 | |
| 826 | /* No superio_enter */ |
| 827 | |
| 828 | /* Identify device */ |
| 829 | val = superio_inb(sioaddr, DEVID); |
| 830 | switch (val) { |
| 831 | case 0xE1: /* PC87360 */ |
| 832 | case 0xE8: /* PC87363 */ |
| 833 | case 0xE4: /* PC87364 */ |
| 834 | nrdev = 1; |
| 835 | break; |
| 836 | case 0xE5: /* PC87365 */ |
| 837 | case 0xE9: /* PC87366 */ |
| 838 | nrdev = 3; |
| 839 | break; |
| 840 | default: |
| 841 | superio_exit(sioaddr); |
| 842 | return -ENODEV; |
| 843 | } |
| 844 | /* Remember the device id */ |
| 845 | *devid = val; |
| 846 | |
| 847 | for (i = 0; i < nrdev; i++) { |
| 848 | /* select logical device */ |
| 849 | superio_outb(sioaddr, DEV, logdev[i]); |
| 850 | |
| 851 | val = superio_inb(sioaddr, ACT); |
| 852 | if (!(val & 0x01)) { |
| 853 | printk(KERN_INFO "pc87360: Device 0x%02x not " |
| 854 | "activated\n", logdev[i]); |
| 855 | continue; |
| 856 | } |
| 857 | |
| 858 | val = (superio_inb(sioaddr, BASE) << 8) |
| 859 | | superio_inb(sioaddr, BASE + 1); |
| 860 | if (!val) { |
| 861 | printk(KERN_INFO "pc87360: Base address not set for " |
| 862 | "device 0x%02x\n", logdev[i]); |
| 863 | continue; |
| 864 | } |
| 865 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 866 | addresses[i] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | if (i==0) { /* Fans */ |
| 869 | confreg[0] = superio_inb(sioaddr, 0xF0); |
| 870 | confreg[1] = superio_inb(sioaddr, 0xF1); |
| 871 | |
| 872 | #ifdef DEBUG |
| 873 | printk(KERN_DEBUG "pc87360: Fan 1: mon=%d " |
| 874 | "ctrl=%d inv=%d\n", (confreg[0]>>2)&1, |
| 875 | (confreg[0]>>3)&1, (confreg[0]>>4)&1); |
| 876 | printk(KERN_DEBUG "pc87360: Fan 2: mon=%d " |
| 877 | "ctrl=%d inv=%d\n", (confreg[0]>>5)&1, |
| 878 | (confreg[0]>>6)&1, (confreg[0]>>7)&1); |
| 879 | printk(KERN_DEBUG "pc87360: Fan 3: mon=%d " |
| 880 | "ctrl=%d inv=%d\n", confreg[1]&1, |
| 881 | (confreg[1]>>1)&1, (confreg[1]>>2)&1); |
| 882 | #endif |
| 883 | } else if (i==1) { /* Voltages */ |
| 884 | /* Are we using thermistors? */ |
| 885 | if (*devid == 0xE9) { /* PC87366 */ |
| 886 | /* These registers are not logical-device |
| 887 | specific, just that we won't need them if |
| 888 | we don't use the VLM device */ |
| 889 | confreg[2] = superio_inb(sioaddr, 0x2B); |
| 890 | confreg[3] = superio_inb(sioaddr, 0x25); |
| 891 | |
| 892 | if (confreg[2] & 0x40) { |
| 893 | printk(KERN_INFO "pc87360: Using " |
| 894 | "thermistors for temperature " |
| 895 | "monitoring\n"); |
| 896 | } |
| 897 | if (confreg[3] & 0xE0) { |
| 898 | printk(KERN_INFO "pc87360: VID " |
| 899 | "inputs routed (mode %u)\n", |
| 900 | confreg[3] >> 5); |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | superio_exit(sioaddr); |
| 907 | return 0; |
| 908 | } |
| 909 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 910 | static int __devinit pc87360_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { |
| 912 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | struct pc87360_data *data; |
| 914 | int err = 0; |
| 915 | const char *name = "pc87360"; |
| 916 | int use_thermistors = 0; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 917 | struct device *dev = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 919 | if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | data->fannr = 2; |
| 923 | data->innr = 0; |
| 924 | data->tempnr = 0; |
| 925 | |
| 926 | switch (devid) { |
| 927 | case 0xe8: |
| 928 | name = "pc87363"; |
| 929 | break; |
| 930 | case 0xe4: |
| 931 | name = "pc87364"; |
| 932 | data->fannr = 3; |
| 933 | break; |
| 934 | case 0xe5: |
| 935 | name = "pc87365"; |
| 936 | data->fannr = extra_isa[0] ? 3 : 0; |
| 937 | data->innr = extra_isa[1] ? 11 : 0; |
| 938 | data->tempnr = extra_isa[2] ? 2 : 0; |
| 939 | break; |
| 940 | case 0xe9: |
| 941 | name = "pc87366"; |
| 942 | data->fannr = extra_isa[0] ? 3 : 0; |
| 943 | data->innr = extra_isa[1] ? 14 : 0; |
| 944 | data->tempnr = extra_isa[2] ? 3 : 0; |
| 945 | break; |
| 946 | } |
| 947 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 948 | data->name = name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | data->valid = 0; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 950 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 951 | mutex_init(&data->update_lock); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 952 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | for (i = 0; i < 3; i++) { |
| 955 | if (((data->address[i] = extra_isa[i])) |
| 956 | && !request_region(extra_isa[i], PC87360_EXTENT, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 957 | pc87360_driver.driver.name)) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 958 | dev_err(dev, "Region 0x%x-0x%x already " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | "in use!\n", extra_isa[i], |
| 960 | extra_isa[i]+PC87360_EXTENT-1); |
| 961 | for (i--; i >= 0; i--) |
| 962 | release_region(extra_isa[i], PC87360_EXTENT); |
| 963 | err = -EBUSY; |
| 964 | goto ERROR1; |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | /* Retrieve the fans configuration from Super-I/O space */ |
| 969 | if (data->fannr) |
| 970 | data->fan_conf = confreg[0] | (confreg[1] << 8); |
| 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | /* Use the correct reference voltage |
| 973 | Unless both the VLM and the TMS logical devices agree to |
| 974 | use an external Vref, the internal one is used. */ |
| 975 | if (data->innr) { |
| 976 | i = pc87360_read_value(data, LD_IN, NO_BANK, |
| 977 | PC87365_REG_IN_CONFIG); |
| 978 | if (data->tempnr) { |
| 979 | i &= pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 980 | PC87365_REG_TEMP_CONFIG); |
| 981 | } |
| 982 | data->in_vref = (i&0x02) ? 3025 : 2966; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 983 | dev_dbg(dev, "Using %s reference voltage\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | (i&0x02) ? "external" : "internal"); |
| 985 | |
| 986 | data->vid_conf = confreg[3]; |
Jim Cromie | 3d7f9a8 | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 987 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* Fan clock dividers may be needed before any data is read */ |
| 991 | for (i = 0; i < data->fannr; i++) { |
| 992 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) |
| 993 | data->fan_status[i] = pc87360_read_value(data, |
| 994 | LD_FAN, NO_BANK, |
| 995 | PC87360_REG_FAN_STATUS(i)); |
| 996 | } |
| 997 | |
| 998 | if (init > 0) { |
| 999 | if (devid == 0xe9 && data->address[1]) /* PC87366 */ |
| 1000 | use_thermistors = confreg[2] & 0x40; |
| 1001 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1002 | pc87360_init_device(pdev, use_thermistors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1005 | /* Register all-or-nothing sysfs groups */ |
| 1006 | |
| 1007 | if (data->innr && |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1008 | (err = sysfs_create_group(&dev->kobj, |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1009 | &pc8736x_vin_group))) |
| 1010 | goto ERROR3; |
| 1011 | |
| 1012 | if (data->innr == 14 && |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1013 | (err = sysfs_create_group(&dev->kobj, |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1014 | &pc8736x_therm_group))) |
| 1015 | goto ERROR3; |
| 1016 | |
| 1017 | /* create device attr-files for varying sysfs groups */ |
| 1018 | |
| 1019 | if (data->tempnr) { |
| 1020 | for (i = 0; i < data->tempnr; i++) { |
| 1021 | if ((err = device_create_file(dev, |
| 1022 | &temp_input[i].dev_attr)) |
| 1023 | || (err = device_create_file(dev, |
| 1024 | &temp_min[i].dev_attr)) |
| 1025 | || (err = device_create_file(dev, |
| 1026 | &temp_max[i].dev_attr)) |
| 1027 | || (err = device_create_file(dev, |
| 1028 | &temp_crit[i].dev_attr)) |
| 1029 | || (err = device_create_file(dev, |
| 1030 | &temp_status[i].dev_attr))) |
| 1031 | goto ERROR3; |
| 1032 | } |
| 1033 | if ((err = device_create_file(dev, &dev_attr_alarms_temp))) |
| 1034 | goto ERROR3; |
| 1035 | } |
| 1036 | |
| 1037 | for (i = 0; i < data->fannr; i++) { |
| 1038 | if (FAN_CONFIG_MONITOR(data->fan_conf, i) |
| 1039 | && ((err = device_create_file(dev, |
| 1040 | &fan_input[i].dev_attr)) |
| 1041 | || (err = device_create_file(dev, |
| 1042 | &fan_min[i].dev_attr)) |
| 1043 | || (err = device_create_file(dev, |
| 1044 | &fan_div[i].dev_attr)) |
| 1045 | || (err = device_create_file(dev, |
| 1046 | &fan_status[i].dev_attr)))) |
| 1047 | goto ERROR3; |
| 1048 | |
| 1049 | if (FAN_CONFIG_CONTROL(data->fan_conf, i) |
| 1050 | && (err = device_create_file(dev, &pwm[i].dev_attr))) |
| 1051 | goto ERROR3; |
| 1052 | } |
| 1053 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1054 | if ((err = device_create_file(dev, &dev_attr_name))) |
| 1055 | goto ERROR3; |
| 1056 | |
| 1057 | data->class_dev = hwmon_device_register(dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1058 | if (IS_ERR(data->class_dev)) { |
| 1059 | err = PTR_ERR(data->class_dev); |
| 1060 | goto ERROR3; |
| 1061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | return 0; |
| 1063 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1064 | ERROR3: |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1065 | device_remove_file(dev, &dev_attr_name); |
Jim Cromie | f3722d5b | 2006-09-24 21:03:25 +0200 | [diff] [blame] | 1066 | /* can still remove groups whose members were added individually */ |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1067 | sysfs_remove_group(&dev->kobj, &pc8736x_temp_group); |
| 1068 | sysfs_remove_group(&dev->kobj, &pc8736x_fan_group); |
| 1069 | sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); |
| 1070 | sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | for (i = 0; i < 3; i++) { |
| 1072 | if (data->address[i]) { |
| 1073 | release_region(data->address[i], PC87360_EXTENT); |
| 1074 | } |
| 1075 | } |
| 1076 | ERROR1: |
| 1077 | kfree(data); |
| 1078 | return err; |
| 1079 | } |
| 1080 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1081 | static int __devexit pc87360_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1083 | struct pc87360_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | int i; |
| 1085 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1086 | hwmon_device_unregister(data->class_dev); |
| 1087 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1088 | device_remove_file(&pdev->dev, &dev_attr_name); |
| 1089 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group); |
| 1090 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group); |
| 1091 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group); |
| 1092 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
| 1094 | for (i = 0; i < 3; i++) { |
| 1095 | if (data->address[i]) { |
| 1096 | release_region(data->address[i], PC87360_EXTENT); |
| 1097 | } |
| 1098 | } |
| 1099 | kfree(data); |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | /* ldi is the logical device index |
| 1105 | bank is for voltages and temperatures only */ |
| 1106 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1107 | u8 reg) |
| 1108 | { |
| 1109 | int res; |
| 1110 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1111 | mutex_lock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | if (bank != NO_BANK) |
| 1113 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1114 | res = inb_p(data->address[ldi] + reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1115 | mutex_unlock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | return res; |
| 1118 | } |
| 1119 | |
| 1120 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
| 1121 | u8 reg, u8 value) |
| 1122 | { |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1123 | mutex_lock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | if (bank != NO_BANK) |
| 1125 | outb_p(bank, data->address[ldi] + PC87365_REG_BANK); |
| 1126 | outb_p(value, data->address[ldi] + reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1127 | mutex_unlock(&(data->lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1130 | static void pc87360_init_device(struct platform_device *pdev, |
| 1131 | int use_thermistors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1133 | struct pc87360_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | int i, nr; |
| 1135 | const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; |
| 1136 | const u8 init_temp[3] = { 2, 2, 1 }; |
| 1137 | u8 reg; |
| 1138 | |
| 1139 | if (init >= 2 && data->innr) { |
| 1140 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1141 | PC87365_REG_IN_CONVRATE); |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1142 | dev_info(&pdev->dev, "VLM conversion set to " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | "1s period, 160us delay\n"); |
| 1144 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1145 | PC87365_REG_IN_CONVRATE, |
| 1146 | (reg & 0xC0) | 0x11); |
| 1147 | } |
| 1148 | |
| 1149 | nr = data->innr < 11 ? data->innr : 11; |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1150 | for (i = 0; i < nr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | if (init >= init_in[i]) { |
| 1152 | /* Forcibly enable voltage channel */ |
| 1153 | reg = pc87360_read_value(data, LD_IN, i, |
| 1154 | PC87365_REG_IN_STATUS); |
| 1155 | if (!(reg & 0x01)) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1156 | dev_dbg(&pdev->dev, "Forcibly " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | "enabling in%d\n", i); |
| 1158 | pc87360_write_value(data, LD_IN, i, |
| 1159 | PC87365_REG_IN_STATUS, |
| 1160 | (reg & 0x68) | 0x87); |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | /* We can't blindly trust the Super-I/O space configuration bit, |
| 1166 | most BIOS won't set it properly */ |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1167 | for (i = 11; i < data->innr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | reg = pc87360_read_value(data, LD_IN, i, |
| 1169 | PC87365_REG_TEMP_STATUS); |
| 1170 | use_thermistors = use_thermistors || (reg & 0x01); |
| 1171 | } |
| 1172 | |
| 1173 | i = use_thermistors ? 2 : 0; |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1174 | for (; i < data->tempnr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | if (init >= init_temp[i]) { |
| 1176 | /* Forcibly enable temperature channel */ |
| 1177 | reg = pc87360_read_value(data, LD_TEMP, i, |
| 1178 | PC87365_REG_TEMP_STATUS); |
| 1179 | if (!(reg & 0x01)) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1180 | dev_dbg(&pdev->dev, "Forcibly " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | "enabling temp%d\n", i+1); |
| 1182 | pc87360_write_value(data, LD_TEMP, i, |
| 1183 | PC87365_REG_TEMP_STATUS, |
| 1184 | 0xCF); |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | if (use_thermistors) { |
Jim Cromie | dedc6a7 | 2006-01-09 23:24:41 +0100 | [diff] [blame] | 1190 | for (i = 11; i < data->innr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | if (init >= init_in[i]) { |
| 1192 | /* The pin may already be used by thermal |
| 1193 | diodes */ |
| 1194 | reg = pc87360_read_value(data, LD_TEMP, |
| 1195 | (i-11)/2, PC87365_REG_TEMP_STATUS); |
| 1196 | if (reg & 0x01) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1197 | dev_dbg(&pdev->dev, "Skipping " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | "temp%d, pin already in use " |
| 1199 | "by temp%d\n", i-7, (i-11)/2); |
| 1200 | continue; |
| 1201 | } |
| 1202 | |
| 1203 | /* Forcibly enable thermistor channel */ |
| 1204 | reg = pc87360_read_value(data, LD_IN, i, |
| 1205 | PC87365_REG_IN_STATUS); |
| 1206 | if (!(reg & 0x01)) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1207 | dev_dbg(&pdev->dev, "Forcibly " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | "enabling temp%d\n", i-7); |
| 1209 | pc87360_write_value(data, LD_IN, i, |
| 1210 | PC87365_REG_TEMP_STATUS, |
| 1211 | (reg & 0x60) | 0x8F); |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (data->innr) { |
| 1218 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
| 1219 | PC87365_REG_IN_CONFIG); |
| 1220 | if (reg & 0x01) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1221 | dev_dbg(&pdev->dev, "Forcibly " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | "enabling monitoring (VLM)\n"); |
| 1223 | pc87360_write_value(data, LD_IN, NO_BANK, |
| 1224 | PC87365_REG_IN_CONFIG, |
| 1225 | reg & 0xFE); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | if (data->tempnr) { |
| 1230 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, |
| 1231 | PC87365_REG_TEMP_CONFIG); |
| 1232 | if (reg & 0x01) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1233 | dev_dbg(&pdev->dev, "Forcibly enabling " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | "monitoring (TMS)\n"); |
| 1235 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
| 1236 | PC87365_REG_TEMP_CONFIG, |
| 1237 | reg & 0xFE); |
| 1238 | } |
| 1239 | |
| 1240 | if (init >= 2) { |
| 1241 | /* Chip config as documented by National Semi. */ |
| 1242 | pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); |
| 1243 | /* We voluntarily omit the bank here, in case the |
| 1244 | sequence itself matters. It shouldn't be a problem, |
| 1245 | since nobody else is supposed to access the |
| 1246 | device at that point. */ |
| 1247 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); |
| 1248 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); |
| 1249 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); |
| 1250 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xE, 0x05); |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1255 | static void pc87360_autodiv(struct device *dev, int nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1257 | struct pc87360_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | u8 old_min = data->fan_min[nr]; |
| 1259 | |
| 1260 | /* Increase clock divider if needed and possible */ |
| 1261 | if ((data->fan_status[nr] & 0x04) /* overflow flag */ |
| 1262 | || (data->fan[nr] >= 224)) { /* next to overflow */ |
| 1263 | if ((data->fan_status[nr] & 0x60) != 0x60) { |
| 1264 | data->fan_status[nr] += 0x20; |
| 1265 | data->fan_min[nr] >>= 1; |
| 1266 | data->fan[nr] >>= 1; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1267 | dev_dbg(dev, "Increasing " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | "clock divider to %d for fan %d\n", |
| 1269 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); |
| 1270 | } |
| 1271 | } else { |
| 1272 | /* Decrease clock divider if possible */ |
| 1273 | while (!(data->fan_min[nr] & 0x80) /* min "nails" divider */ |
| 1274 | && data->fan[nr] < 85 /* bad accuracy */ |
| 1275 | && (data->fan_status[nr] & 0x60) != 0x00) { |
| 1276 | data->fan_status[nr] -= 0x20; |
| 1277 | data->fan_min[nr] <<= 1; |
| 1278 | data->fan[nr] <<= 1; |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1279 | dev_dbg(dev, "Decreasing " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | "clock divider to %d for fan %d\n", |
| 1281 | FAN_DIV_FROM_REG(data->fan_status[nr]), |
| 1282 | nr+1); |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | /* Write new fan min if it changed */ |
| 1287 | if (old_min != data->fan_min[nr]) { |
| 1288 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1289 | PC87360_REG_FAN_MIN(nr), |
| 1290 | data->fan_min[nr]); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | static struct pc87360_data *pc87360_update_device(struct device *dev) |
| 1295 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1296 | struct pc87360_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | u8 i; |
| 1298 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1299 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1302 | dev_dbg(dev, "Data update\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | /* Fans */ |
| 1305 | for (i = 0; i < data->fannr; i++) { |
| 1306 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { |
| 1307 | data->fan_status[i] = |
| 1308 | pc87360_read_value(data, LD_FAN, |
| 1309 | NO_BANK, PC87360_REG_FAN_STATUS(i)); |
| 1310 | data->fan[i] = pc87360_read_value(data, LD_FAN, |
| 1311 | NO_BANK, PC87360_REG_FAN(i)); |
| 1312 | data->fan_min[i] = pc87360_read_value(data, |
| 1313 | LD_FAN, NO_BANK, |
| 1314 | PC87360_REG_FAN_MIN(i)); |
| 1315 | /* Change clock divider if needed */ |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1316 | pc87360_autodiv(dev, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | /* Clear bits and write new divider */ |
| 1318 | pc87360_write_value(data, LD_FAN, NO_BANK, |
| 1319 | PC87360_REG_FAN_STATUS(i), |
| 1320 | data->fan_status[i]); |
| 1321 | } |
| 1322 | if (FAN_CONFIG_CONTROL(data->fan_conf, i)) |
| 1323 | data->pwm[i] = pc87360_read_value(data, LD_FAN, |
| 1324 | NO_BANK, PC87360_REG_PWM(i)); |
| 1325 | } |
| 1326 | |
| 1327 | /* Voltages */ |
| 1328 | for (i = 0; i < data->innr; i++) { |
| 1329 | data->in_status[i] = pc87360_read_value(data, LD_IN, i, |
| 1330 | PC87365_REG_IN_STATUS); |
| 1331 | /* Clear bits */ |
| 1332 | pc87360_write_value(data, LD_IN, i, |
| 1333 | PC87365_REG_IN_STATUS, |
| 1334 | data->in_status[i]); |
| 1335 | if ((data->in_status[i] & 0x81) == 0x81) { |
| 1336 | data->in[i] = pc87360_read_value(data, LD_IN, |
| 1337 | i, PC87365_REG_IN); |
| 1338 | } |
| 1339 | if (data->in_status[i] & 0x01) { |
| 1340 | data->in_min[i] = pc87360_read_value(data, |
| 1341 | LD_IN, i, |
| 1342 | PC87365_REG_IN_MIN); |
| 1343 | data->in_max[i] = pc87360_read_value(data, |
| 1344 | LD_IN, i, |
| 1345 | PC87365_REG_IN_MAX); |
| 1346 | if (i >= 11) |
| 1347 | data->in_crit[i-11] = |
| 1348 | pc87360_read_value(data, LD_IN, |
| 1349 | i, PC87365_REG_TEMP_CRIT); |
| 1350 | } |
| 1351 | } |
| 1352 | if (data->innr) { |
| 1353 | data->in_alarms = pc87360_read_value(data, LD_IN, |
| 1354 | NO_BANK, PC87365_REG_IN_ALARMS1) |
| 1355 | | ((pc87360_read_value(data, LD_IN, |
| 1356 | NO_BANK, PC87365_REG_IN_ALARMS2) |
| 1357 | & 0x07) << 8); |
| 1358 | data->vid = (data->vid_conf & 0xE0) ? |
| 1359 | pc87360_read_value(data, LD_IN, |
| 1360 | NO_BANK, PC87365_REG_VID) : 0x1F; |
| 1361 | } |
| 1362 | |
| 1363 | /* Temperatures */ |
| 1364 | for (i = 0; i < data->tempnr; i++) { |
| 1365 | data->temp_status[i] = pc87360_read_value(data, |
| 1366 | LD_TEMP, i, |
| 1367 | PC87365_REG_TEMP_STATUS); |
| 1368 | /* Clear bits */ |
| 1369 | pc87360_write_value(data, LD_TEMP, i, |
| 1370 | PC87365_REG_TEMP_STATUS, |
| 1371 | data->temp_status[i]); |
| 1372 | if ((data->temp_status[i] & 0x81) == 0x81) { |
| 1373 | data->temp[i] = pc87360_read_value(data, |
| 1374 | LD_TEMP, i, |
| 1375 | PC87365_REG_TEMP); |
| 1376 | } |
| 1377 | if (data->temp_status[i] & 0x01) { |
| 1378 | data->temp_min[i] = pc87360_read_value(data, |
| 1379 | LD_TEMP, i, |
| 1380 | PC87365_REG_TEMP_MIN); |
| 1381 | data->temp_max[i] = pc87360_read_value(data, |
| 1382 | LD_TEMP, i, |
| 1383 | PC87365_REG_TEMP_MAX); |
| 1384 | data->temp_crit[i] = pc87360_read_value(data, |
| 1385 | LD_TEMP, i, |
| 1386 | PC87365_REG_TEMP_CRIT); |
| 1387 | } |
| 1388 | } |
| 1389 | if (data->tempnr) { |
| 1390 | data->temp_alarms = pc87360_read_value(data, LD_TEMP, |
| 1391 | NO_BANK, PC87365_REG_TEMP_ALARMS) |
| 1392 | & 0x3F; |
| 1393 | } |
| 1394 | |
| 1395 | data->last_updated = jiffies; |
| 1396 | data->valid = 1; |
| 1397 | } |
| 1398 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1399 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
| 1401 | return data; |
| 1402 | } |
| 1403 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1404 | static int __init pc87360_device_add(unsigned short address) |
| 1405 | { |
| 1406 | struct resource res = { |
| 1407 | .name = "pc87360", |
| 1408 | .flags = IORESOURCE_IO, |
| 1409 | }; |
| 1410 | int err, i; |
| 1411 | |
| 1412 | pdev = platform_device_alloc("pc87360", address); |
| 1413 | if (!pdev) { |
| 1414 | err = -ENOMEM; |
| 1415 | printk(KERN_ERR "pc87360: Device allocation failed\n"); |
| 1416 | goto exit; |
| 1417 | } |
| 1418 | |
| 1419 | for (i = 0; i < 3; i++) { |
| 1420 | if (!extra_isa[i]) |
| 1421 | continue; |
| 1422 | res.start = extra_isa[i]; |
| 1423 | res.end = extra_isa[i] + PC87360_EXTENT - 1; |
| 1424 | err = platform_device_add_resources(pdev, &res, 1); |
| 1425 | if (err) { |
| 1426 | printk(KERN_ERR "pc87360: Device resource[%d] " |
| 1427 | "addition failed (%d)\n", i, err); |
| 1428 | goto exit_device_put; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | err = platform_device_add(pdev); |
| 1433 | if (err) { |
| 1434 | printk(KERN_ERR "pc87360: Device addition failed (%d)\n", |
| 1435 | err); |
| 1436 | goto exit_device_put; |
| 1437 | } |
| 1438 | |
| 1439 | return 0; |
| 1440 | |
| 1441 | exit_device_put: |
| 1442 | platform_device_put(pdev); |
| 1443 | exit: |
| 1444 | return err; |
| 1445 | } |
| 1446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | static int __init pc87360_init(void) |
| 1448 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1449 | int err, i; |
| 1450 | unsigned short address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
| 1452 | if (pc87360_find(0x2e, &devid, extra_isa) |
| 1453 | && pc87360_find(0x4e, &devid, extra_isa)) { |
| 1454 | printk(KERN_WARNING "pc87360: PC8736x not detected, " |
| 1455 | "module not inserted.\n"); |
| 1456 | return -ENODEV; |
| 1457 | } |
| 1458 | |
| 1459 | /* Arbitrarily pick one of the addresses */ |
| 1460 | for (i = 0; i < 3; i++) { |
| 1461 | if (extra_isa[i] != 0x0000) { |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1462 | address = extra_isa[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | break; |
| 1464 | } |
| 1465 | } |
| 1466 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1467 | if (address == 0x0000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | printk(KERN_WARNING "pc87360: No active logical device, " |
| 1469 | "module not inserted.\n"); |
| 1470 | return -ENODEV; |
| 1471 | } |
| 1472 | |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1473 | err = platform_driver_register(&pc87360_driver); |
| 1474 | if (err) |
| 1475 | goto exit; |
| 1476 | |
| 1477 | /* Sets global pdev as a side effect */ |
| 1478 | err = pc87360_device_add(address); |
| 1479 | if (err) |
| 1480 | goto exit_driver; |
| 1481 | |
| 1482 | return 0; |
| 1483 | |
| 1484 | exit_driver: |
| 1485 | platform_driver_unregister(&pc87360_driver); |
| 1486 | exit: |
| 1487 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | static void __exit pc87360_exit(void) |
| 1491 | { |
Jean Delvare | f641b58 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1492 | platform_device_unregister(pdev); |
| 1493 | platform_driver_unregister(&pc87360_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 1498 | MODULE_DESCRIPTION("PC8736x hardware monitor"); |
| 1499 | MODULE_LICENSE("GPL"); |
| 1500 | |
| 1501 | module_init(pc87360_init); |
| 1502 | module_exit(pc87360_exit); |