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