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