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