Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lm87.c |
| 3 | * |
| 4 | * Copyright (C) 2000 Frodo Looijaard <frodol@dds.nl> |
| 5 | * Philip Edelbrock <phil@netroedge.com> |
| 6 | * Stephen Rousset <stephen.rousset@rocketlogix.com> |
| 7 | * Dan Eaton <dan.eaton@rocketlogix.com> |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 8 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Original port to Linux 2.6 by Jeff Oliver. |
| 11 | * |
| 12 | * The LM87 is a sensor chip made by National Semiconductor. It monitors up |
| 13 | * to 8 voltages (including its own power source), up to three temperatures |
| 14 | * (its own plus up to two external ones) and up to two fans. The default |
| 15 | * configuration is 6 voltages, two temperatures and two fans (see below). |
| 16 | * Voltages are scaled internally with ratios such that the nominal value of |
| 17 | * each voltage correspond to a register value of 192 (which means a |
| 18 | * resolution of about 0.5% of the nominal value). Temperature values are |
| 19 | * reported with a 1 deg resolution and a 3-4 deg accuracy. Complete |
| 20 | * datasheet can be obtained from National's website at: |
| 21 | * http://www.national.com/pf/LM/LM87.html |
| 22 | * |
| 23 | * Some functions share pins, so not all functions are available at the same |
Ben Hutchings | 47064d6 | 2008-10-17 17:51:12 +0200 | [diff] [blame] | 24 | * time. Which are depends on the hardware setup. This driver normally |
| 25 | * assumes that firmware configured the chip correctly. Where this is not |
| 26 | * the case, platform code must set the I2C client's platform_data to point |
| 27 | * to a u8 value to be written to the channel register. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * For reference, here is the list of exclusive functions: |
| 29 | * - in0+in5 (default) or temp3 |
| 30 | * - fan1 (default) or in6 |
| 31 | * - fan2 (default) or in7 |
| 32 | * - VID lines (default) or IRQ lines (not handled by this driver) |
| 33 | * |
| 34 | * The LM87 additionally features an analog output, supposedly usable to |
| 35 | * control the speed of a fan. All new chips use pulse width modulation |
| 36 | * instead. The LM87 is the only hardware monitoring chipset I know of |
| 37 | * which uses amplitude modulation. Be careful when using this feature. |
| 38 | * |
Jean Delvare | c7fa373 | 2007-10-09 15:22:22 +0200 | [diff] [blame] | 39 | * This driver also supports the ADM1024, a sensor chip made by Analog |
| 40 | * Devices. That chip is fully compatible with the LM87. Complete |
| 41 | * datasheet can be obtained from Analog's website at: |
| 42 | * http://www.analog.com/en/prod/0,2877,ADM1024,00.html |
| 43 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * This program is free software; you can redistribute it and/or modify |
| 45 | * it under the terms of the GNU General Public License as published by |
| 46 | * the Free Software Foundation; either version 2 of the License, or |
| 47 | * (at your option) any later version. |
| 48 | * |
| 49 | * This program is distributed in the hope that it will be useful, |
| 50 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 51 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 52 | * GNU General Public License for more details. |
| 53 | * |
| 54 | * You should have received a copy of the GNU General Public License |
| 55 | * along with this program; if not, write to the Free Software |
| 56 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 57 | */ |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <linux/module.h> |
| 60 | #include <linux/init.h> |
| 61 | #include <linux/slab.h> |
| 62 | #include <linux/jiffies.h> |
| 63 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 64 | #include <linux/hwmon.h> |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 65 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 66 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 67 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 68 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * Addresses to scan |
| 72 | * LM87 has three possible addresses: 0x2c, 0x2d and 0x2e. |
| 73 | */ |
| 74 | |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 75 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Jean Delvare | e5e9f44 | 2009-12-14 21:17:27 +0100 | [diff] [blame^] | 77 | enum chips { lm87, adm1024 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * The LM87 registers |
| 81 | */ |
| 82 | |
| 83 | /* nr in 0..5 */ |
| 84 | #define LM87_REG_IN(nr) (0x20 + (nr)) |
| 85 | #define LM87_REG_IN_MAX(nr) (0x2B + (nr) * 2) |
| 86 | #define LM87_REG_IN_MIN(nr) (0x2C + (nr) * 2) |
| 87 | /* nr in 0..1 */ |
| 88 | #define LM87_REG_AIN(nr) (0x28 + (nr)) |
| 89 | #define LM87_REG_AIN_MIN(nr) (0x1A + (nr)) |
| 90 | #define LM87_REG_AIN_MAX(nr) (0x3B + (nr)) |
| 91 | |
| 92 | static u8 LM87_REG_TEMP[3] = { 0x27, 0x26, 0x20 }; |
| 93 | static u8 LM87_REG_TEMP_HIGH[3] = { 0x39, 0x37, 0x2B }; |
| 94 | static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C }; |
| 95 | |
| 96 | #define LM87_REG_TEMP_HW_INT_LOCK 0x13 |
| 97 | #define LM87_REG_TEMP_HW_EXT_LOCK 0x14 |
| 98 | #define LM87_REG_TEMP_HW_INT 0x17 |
| 99 | #define LM87_REG_TEMP_HW_EXT 0x18 |
| 100 | |
| 101 | /* nr in 0..1 */ |
| 102 | #define LM87_REG_FAN(nr) (0x28 + (nr)) |
| 103 | #define LM87_REG_FAN_MIN(nr) (0x3B + (nr)) |
| 104 | #define LM87_REG_AOUT 0x19 |
| 105 | |
| 106 | #define LM87_REG_CONFIG 0x40 |
| 107 | #define LM87_REG_CHANNEL_MODE 0x16 |
| 108 | #define LM87_REG_VID_FAN_DIV 0x47 |
| 109 | #define LM87_REG_VID4 0x49 |
| 110 | |
| 111 | #define LM87_REG_ALARMS1 0x41 |
| 112 | #define LM87_REG_ALARMS2 0x42 |
| 113 | |
| 114 | #define LM87_REG_COMPANY_ID 0x3E |
| 115 | #define LM87_REG_REVISION 0x3F |
| 116 | |
| 117 | /* |
| 118 | * Conversions and various macros |
| 119 | * The LM87 uses signed 8-bit values for temperatures. |
| 120 | */ |
| 121 | |
| 122 | #define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) |
| 123 | #define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ |
| 124 | (val) * 192 >= (scale) * 255 ? 255 : \ |
| 125 | ((val) * 192 + (scale)/2) / (scale)) |
| 126 | |
| 127 | #define TEMP_FROM_REG(reg) ((reg) * 1000) |
| 128 | #define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \ |
| 129 | (val) >= 126500 ? 127 : \ |
| 130 | (((val) < 0 ? (val)-500 : (val)+500) / 1000)) |
| 131 | |
| 132 | #define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \ |
Jean Delvare | b965d4b | 2007-09-26 22:16:56 +0200 | [diff] [blame] | 133 | (1350000 + (reg)*(div) / 2) / ((reg)*(div))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \ |
| 135 | (1350000 + (val)*(div) / 2) / ((val)*(div))) |
| 136 | |
| 137 | #define FAN_DIV_FROM_REG(reg) (1 << (reg)) |
| 138 | |
| 139 | /* analog out is 9.80mV/LSB */ |
| 140 | #define AOUT_FROM_REG(reg) (((reg) * 98 + 5) / 10) |
| 141 | #define AOUT_TO_REG(val) ((val) <= 0 ? 0 : \ |
| 142 | (val) >= 2500 ? 255 : \ |
| 143 | ((val) * 10 + 49) / 98) |
| 144 | |
| 145 | /* nr in 0..1 */ |
| 146 | #define CHAN_NO_FAN(nr) (1 << (nr)) |
| 147 | #define CHAN_TEMP3 (1 << 2) |
| 148 | #define CHAN_VCC_5V (1 << 3) |
Jean Delvare | 889af3d | 2007-10-08 22:48:10 +0200 | [diff] [blame] | 149 | #define CHAN_NO_VID (1 << 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * Functions declaration |
| 153 | */ |
| 154 | |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 155 | static int lm87_probe(struct i2c_client *client, |
| 156 | const struct i2c_device_id *id); |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 157 | static int lm87_detect(struct i2c_client *new_client, |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 158 | struct i2c_board_info *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static void lm87_init_client(struct i2c_client *client); |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 160 | static int lm87_remove(struct i2c_client *client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static struct lm87_data *lm87_update_device(struct device *dev); |
| 162 | |
| 163 | /* |
| 164 | * Driver data (common to all clients) |
| 165 | */ |
| 166 | |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 167 | static const struct i2c_device_id lm87_id[] = { |
| 168 | { "lm87", lm87 }, |
| 169 | { "adm1024", adm1024 }, |
| 170 | { } |
| 171 | }; |
| 172 | MODULE_DEVICE_TABLE(i2c, lm87_id); |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | static struct i2c_driver lm87_driver = { |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 175 | .class = I2C_CLASS_HWMON, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 176 | .driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 177 | .name = "lm87", |
| 178 | }, |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 179 | .probe = lm87_probe, |
| 180 | .remove = lm87_remove, |
| 181 | .id_table = lm87_id, |
| 182 | .detect = lm87_detect, |
Jean Delvare | c3813d6 | 2009-12-14 21:17:25 +0100 | [diff] [blame] | 183 | .address_list = normal_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | /* |
| 187 | * Client data (each client gets its own) |
| 188 | */ |
| 189 | |
| 190 | struct lm87_data { |
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 update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | char valid; /* zero until following fields are valid */ |
| 194 | unsigned long last_updated; /* In jiffies */ |
| 195 | |
| 196 | u8 channel; /* register value */ |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 197 | u8 config; /* original register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | u8 in[8]; /* register value */ |
| 200 | u8 in_max[8]; /* register value */ |
| 201 | u8 in_min[8]; /* register value */ |
| 202 | u16 in_scale[8]; |
| 203 | |
| 204 | s8 temp[3]; /* register value */ |
| 205 | s8 temp_high[3]; /* register value */ |
| 206 | s8 temp_low[3]; /* register value */ |
| 207 | s8 temp_crit_int; /* min of two register values */ |
| 208 | s8 temp_crit_ext; /* min of two register values */ |
| 209 | |
| 210 | u8 fan[2]; /* register value */ |
| 211 | u8 fan_min[2]; /* register value */ |
| 212 | u8 fan_div[2]; /* register value, shifted right */ |
| 213 | u8 aout; /* register value */ |
| 214 | |
| 215 | u16 alarms; /* register values, combined */ |
| 216 | u8 vid; /* register values, combined */ |
| 217 | u8 vrm; |
| 218 | }; |
| 219 | |
| 220 | /* |
| 221 | * Sysfs stuff |
| 222 | */ |
| 223 | |
| 224 | static inline int lm87_read_value(struct i2c_client *client, u8 reg) |
| 225 | { |
| 226 | return i2c_smbus_read_byte_data(client, reg); |
| 227 | } |
| 228 | |
| 229 | static inline int lm87_write_value(struct i2c_client *client, u8 reg, u8 value) |
| 230 | { |
| 231 | return i2c_smbus_write_byte_data(client, reg, value); |
| 232 | } |
| 233 | |
| 234 | #define show_in(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 235 | static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { \ |
| 237 | struct lm87_data *data = lm87_update_device(dev); \ |
| 238 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ |
| 239 | data->in_scale[offset])); \ |
| 240 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 241 | static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { \ |
| 243 | struct lm87_data *data = lm87_update_device(dev); \ |
| 244 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ |
| 245 | data->in_scale[offset])); \ |
| 246 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 247 | static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { \ |
| 249 | struct lm87_data *data = lm87_update_device(dev); \ |
| 250 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ |
| 251 | data->in_scale[offset])); \ |
| 252 | } \ |
| 253 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 254 | show_in##offset##_input, NULL); |
| 255 | show_in(0); |
| 256 | show_in(1); |
| 257 | show_in(2); |
| 258 | show_in(3); |
| 259 | show_in(4); |
| 260 | show_in(5); |
| 261 | show_in(6); |
| 262 | show_in(7); |
| 263 | |
| 264 | static void set_in_min(struct device *dev, const char *buf, int nr) |
| 265 | { |
| 266 | struct i2c_client *client = to_i2c_client(dev); |
| 267 | struct lm87_data *data = i2c_get_clientdata(client); |
| 268 | long val = simple_strtol(buf, NULL, 10); |
| 269 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 270 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]); |
| 272 | lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) : |
| 273 | LM87_REG_AIN_MIN(nr-6), data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 274 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void set_in_max(struct device *dev, const char *buf, int nr) |
| 278 | { |
| 279 | struct i2c_client *client = to_i2c_client(dev); |
| 280 | struct lm87_data *data = i2c_get_clientdata(client); |
| 281 | long val = simple_strtol(buf, NULL, 10); |
| 282 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 283 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]); |
| 285 | lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) : |
| 286 | LM87_REG_AIN_MAX(nr-6), data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 287 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | #define set_in(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 291 | static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | const char *buf, size_t count) \ |
| 293 | { \ |
| 294 | set_in_min(dev, buf, offset); \ |
| 295 | return count; \ |
| 296 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 297 | static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | const char *buf, size_t count) \ |
| 299 | { \ |
| 300 | set_in_max(dev, buf, offset); \ |
| 301 | return count; \ |
| 302 | } \ |
| 303 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 304 | show_in##offset##_min, set_in##offset##_min); \ |
| 305 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 306 | show_in##offset##_max, set_in##offset##_max); |
| 307 | set_in(0); |
| 308 | set_in(1); |
| 309 | set_in(2); |
| 310 | set_in(3); |
| 311 | set_in(4); |
| 312 | set_in(5); |
| 313 | set_in(6); |
| 314 | set_in(7); |
| 315 | |
| 316 | #define show_temp(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 317 | static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { \ |
| 319 | struct lm87_data *data = lm87_update_device(dev); \ |
| 320 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ |
| 321 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 322 | static ssize_t show_temp##offset##_low(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { \ |
| 324 | struct lm87_data *data = lm87_update_device(dev); \ |
| 325 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[offset-1])); \ |
| 326 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 327 | static ssize_t show_temp##offset##_high(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { \ |
| 329 | struct lm87_data *data = lm87_update_device(dev); \ |
| 330 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[offset-1])); \ |
| 331 | }\ |
| 332 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 333 | show_temp##offset##_input, NULL); |
| 334 | show_temp(1); |
| 335 | show_temp(2); |
| 336 | show_temp(3); |
| 337 | |
| 338 | static void set_temp_low(struct device *dev, const char *buf, int nr) |
| 339 | { |
| 340 | struct i2c_client *client = to_i2c_client(dev); |
| 341 | struct lm87_data *data = i2c_get_clientdata(client); |
| 342 | long val = simple_strtol(buf, NULL, 10); |
| 343 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 344 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | data->temp_low[nr] = TEMP_TO_REG(val); |
| 346 | lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 347 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void set_temp_high(struct device *dev, const char *buf, int nr) |
| 351 | { |
| 352 | struct i2c_client *client = to_i2c_client(dev); |
| 353 | struct lm87_data *data = i2c_get_clientdata(client); |
| 354 | long val = simple_strtol(buf, NULL, 10); |
| 355 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 356 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | data->temp_high[nr] = TEMP_TO_REG(val); |
| 358 | lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 359 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | #define set_temp(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 363 | static ssize_t set_temp##offset##_low(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | const char *buf, size_t count) \ |
| 365 | { \ |
| 366 | set_temp_low(dev, buf, offset-1); \ |
| 367 | return count; \ |
| 368 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 369 | static ssize_t set_temp##offset##_high(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | const char *buf, size_t count) \ |
| 371 | { \ |
| 372 | set_temp_high(dev, buf, offset-1); \ |
| 373 | return count; \ |
| 374 | } \ |
| 375 | static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 376 | show_temp##offset##_high, set_temp##offset##_high); \ |
| 377 | static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 378 | show_temp##offset##_low, set_temp##offset##_low); |
| 379 | set_temp(1); |
| 380 | set_temp(2); |
| 381 | set_temp(3); |
| 382 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 383 | static ssize_t show_temp_crit_int(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
| 385 | struct lm87_data *data = lm87_update_device(dev); |
| 386 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int)); |
| 387 | } |
| 388 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 389 | static ssize_t show_temp_crit_ext(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | struct lm87_data *data = lm87_update_device(dev); |
| 392 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext)); |
| 393 | } |
| 394 | |
| 395 | static DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit_int, NULL); |
| 396 | static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit_ext, NULL); |
| 397 | static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL); |
| 398 | |
| 399 | #define show_fan(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 400 | static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { \ |
| 402 | struct lm87_data *data = lm87_update_device(dev); \ |
| 403 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[offset-1], \ |
| 404 | FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ |
| 405 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 406 | static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { \ |
| 408 | struct lm87_data *data = lm87_update_device(dev); \ |
| 409 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[offset-1], \ |
| 410 | FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ |
| 411 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 412 | static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { \ |
| 414 | struct lm87_data *data = lm87_update_device(dev); \ |
| 415 | return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[offset-1])); \ |
| 416 | } \ |
| 417 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 418 | show_fan##offset##_input, NULL); |
| 419 | show_fan(1); |
| 420 | show_fan(2); |
| 421 | |
| 422 | static void set_fan_min(struct device *dev, const char *buf, int nr) |
| 423 | { |
| 424 | struct i2c_client *client = to_i2c_client(dev); |
| 425 | struct lm87_data *data = i2c_get_clientdata(client); |
| 426 | long val = simple_strtol(buf, NULL, 10); |
| 427 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 428 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | data->fan_min[nr] = FAN_TO_REG(val, |
| 430 | FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 431 | lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 432 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* Note: we save and restore the fan minimum here, because its value is |
| 436 | determined in part by the fan clock divider. This follows the principle |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 437 | of least surprise; the user doesn't expect the fan minimum to change just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | because the divider changed. */ |
| 439 | static ssize_t set_fan_div(struct device *dev, const char *buf, |
| 440 | size_t count, int nr) |
| 441 | { |
| 442 | struct i2c_client *client = to_i2c_client(dev); |
| 443 | struct lm87_data *data = i2c_get_clientdata(client); |
| 444 | long val = simple_strtol(buf, NULL, 10); |
| 445 | unsigned long min; |
| 446 | u8 reg; |
| 447 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 448 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | min = FAN_FROM_REG(data->fan_min[nr], |
| 450 | FAN_DIV_FROM_REG(data->fan_div[nr])); |
| 451 | |
| 452 | switch (val) { |
| 453 | case 1: data->fan_div[nr] = 0; break; |
| 454 | case 2: data->fan_div[nr] = 1; break; |
| 455 | case 4: data->fan_div[nr] = 2; break; |
| 456 | case 8: data->fan_div[nr] = 3; break; |
| 457 | default: |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 458 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | reg = lm87_read_value(client, LM87_REG_VID_FAN_DIV); |
| 463 | switch (nr) { |
| 464 | case 0: |
| 465 | reg = (reg & 0xCF) | (data->fan_div[0] << 4); |
| 466 | break; |
| 467 | case 1: |
| 468 | reg = (reg & 0x3F) | (data->fan_div[1] << 6); |
| 469 | break; |
| 470 | } |
| 471 | lm87_write_value(client, LM87_REG_VID_FAN_DIV, reg); |
| 472 | |
| 473 | data->fan_min[nr] = FAN_TO_REG(min, val); |
| 474 | lm87_write_value(client, LM87_REG_FAN_MIN(nr), |
| 475 | data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 476 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | return count; |
| 479 | } |
| 480 | |
| 481 | #define set_fan(offset) \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 482 | static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | size_t count) \ |
| 484 | { \ |
| 485 | set_fan_min(dev, buf, offset-1); \ |
| 486 | return count; \ |
| 487 | } \ |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 488 | static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | size_t count) \ |
| 490 | { \ |
| 491 | return set_fan_div(dev, buf, count, offset-1); \ |
| 492 | } \ |
| 493 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 494 | show_fan##offset##_min, set_fan##offset##_min); \ |
| 495 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 496 | show_fan##offset##_div, set_fan##offset##_div); |
| 497 | set_fan(1); |
| 498 | set_fan(2); |
| 499 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 500 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
| 502 | struct lm87_data *data = lm87_update_device(dev); |
| 503 | return sprintf(buf, "%d\n", data->alarms); |
| 504 | } |
| 505 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
| 506 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 507 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
| 509 | struct lm87_data *data = lm87_update_device(dev); |
| 510 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); |
| 511 | } |
| 512 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
| 513 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 514 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 516 | struct lm87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return sprintf(buf, "%d\n", data->vrm); |
| 518 | } |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 519 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Jean Delvare | 8f74efe | 2007-12-01 11:25:33 +0100 | [diff] [blame] | 521 | struct lm87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | data->vrm = simple_strtoul(buf, NULL, 10); |
| 523 | return count; |
| 524 | } |
| 525 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); |
| 526 | |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 527 | static ssize_t show_aout(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | struct lm87_data *data = lm87_update_device(dev); |
| 530 | return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); |
| 531 | } |
Yani Ioannou | 8627f9b | 2005-05-17 06:42:03 -0400 | [diff] [blame] | 532 | static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
| 534 | struct i2c_client *client = to_i2c_client(dev); |
| 535 | struct lm87_data *data = i2c_get_clientdata(client); |
| 536 | long val = simple_strtol(buf, NULL, 10); |
| 537 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 538 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | data->aout = AOUT_TO_REG(val); |
| 540 | lm87_write_value(client, LM87_REG_AOUT, data->aout); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 541 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | return count; |
| 543 | } |
| 544 | static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); |
| 545 | |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 546 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 547 | char *buf) |
| 548 | { |
| 549 | struct lm87_data *data = lm87_update_device(dev); |
| 550 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 551 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 552 | } |
| 553 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 554 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 555 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 556 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 557 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 558 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 559 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 560 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7); |
| 561 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 562 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 563 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 564 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 565 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); |
| 566 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 14); |
| 567 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15); |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /* |
| 570 | * Real code |
| 571 | */ |
| 572 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 573 | static struct attribute *lm87_attributes[] = { |
| 574 | &dev_attr_in1_input.attr, |
| 575 | &dev_attr_in1_min.attr, |
| 576 | &dev_attr_in1_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 577 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 578 | &dev_attr_in2_input.attr, |
| 579 | &dev_attr_in2_min.attr, |
| 580 | &dev_attr_in2_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 581 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 582 | &dev_attr_in3_input.attr, |
| 583 | &dev_attr_in3_min.attr, |
| 584 | &dev_attr_in3_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 585 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 586 | &dev_attr_in4_input.attr, |
| 587 | &dev_attr_in4_min.attr, |
| 588 | &dev_attr_in4_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 589 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 590 | |
| 591 | &dev_attr_temp1_input.attr, |
| 592 | &dev_attr_temp1_max.attr, |
| 593 | &dev_attr_temp1_min.attr, |
| 594 | &dev_attr_temp1_crit.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 595 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 596 | &dev_attr_temp2_input.attr, |
| 597 | &dev_attr_temp2_max.attr, |
| 598 | &dev_attr_temp2_min.attr, |
| 599 | &dev_attr_temp2_crit.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 600 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 601 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 602 | |
| 603 | &dev_attr_alarms.attr, |
| 604 | &dev_attr_aout_output.attr, |
| 605 | |
| 606 | NULL |
| 607 | }; |
| 608 | |
| 609 | static const struct attribute_group lm87_group = { |
| 610 | .attrs = lm87_attributes, |
| 611 | }; |
| 612 | |
| 613 | static struct attribute *lm87_attributes_opt[] = { |
| 614 | &dev_attr_in6_input.attr, |
| 615 | &dev_attr_in6_min.attr, |
| 616 | &dev_attr_in6_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 617 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 618 | |
| 619 | &dev_attr_fan1_input.attr, |
| 620 | &dev_attr_fan1_min.attr, |
| 621 | &dev_attr_fan1_div.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 622 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 623 | |
| 624 | &dev_attr_in7_input.attr, |
| 625 | &dev_attr_in7_min.attr, |
| 626 | &dev_attr_in7_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 627 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 628 | |
| 629 | &dev_attr_fan2_input.attr, |
| 630 | &dev_attr_fan2_min.attr, |
| 631 | &dev_attr_fan2_div.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 632 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 633 | |
| 634 | &dev_attr_temp3_input.attr, |
| 635 | &dev_attr_temp3_max.attr, |
| 636 | &dev_attr_temp3_min.attr, |
| 637 | &dev_attr_temp3_crit.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 638 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
| 639 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 640 | |
| 641 | &dev_attr_in0_input.attr, |
| 642 | &dev_attr_in0_min.attr, |
| 643 | &dev_attr_in0_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 644 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 645 | &dev_attr_in5_input.attr, |
| 646 | &dev_attr_in5_min.attr, |
| 647 | &dev_attr_in5_max.attr, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 648 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 649 | |
| 650 | &dev_attr_cpu0_vid.attr, |
| 651 | &dev_attr_vrm.attr, |
| 652 | |
| 653 | NULL |
| 654 | }; |
| 655 | |
| 656 | static const struct attribute_group lm87_group_opt = { |
| 657 | .attrs = lm87_attributes_opt, |
| 658 | }; |
| 659 | |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 660 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | 310ec79 | 2009-12-14 21:17:23 +0100 | [diff] [blame] | 661 | static int lm87_detect(struct i2c_client *new_client, |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 662 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | { |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 664 | struct i2c_adapter *adapter = new_client->adapter; |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 665 | const char *name; |
| 666 | u8 cid, rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 669 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 671 | if (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80) |
| 672 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | /* Now, we do the remaining detection. */ |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 675 | cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); |
| 676 | rev = lm87_read_value(new_client, LM87_REG_REVISION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 678 | if (cid == 0x02 /* National Semiconductor */ |
| 679 | && (rev >= 0x01 && rev <= 0x08)) |
| 680 | name = "lm87"; |
| 681 | else if (cid == 0x41 /* Analog Devices */ |
| 682 | && (rev & 0xf0) == 0x10) |
| 683 | name = "adm1024"; |
| 684 | else { |
| 685 | dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n", |
| 686 | new_client->addr); |
| 687 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Jean Delvare | 52df644 | 2009-12-09 20:35:57 +0100 | [diff] [blame] | 690 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static int lm87_probe(struct i2c_client *new_client, |
| 696 | const struct i2c_device_id *id) |
| 697 | { |
| 698 | struct lm87_data *data; |
| 699 | int err; |
| 700 | |
| 701 | data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL); |
| 702 | if (!data) { |
| 703 | err = -ENOMEM; |
| 704 | goto exit; |
| 705 | } |
| 706 | |
| 707 | i2c_set_clientdata(new_client, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | data->valid = 0; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 709 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | /* Initialize the LM87 chip */ |
| 712 | lm87_init_client(new_client); |
| 713 | |
| 714 | data->in_scale[0] = 2500; |
| 715 | data->in_scale[1] = 2700; |
| 716 | data->in_scale[2] = (data->channel & CHAN_VCC_5V) ? 5000 : 3300; |
| 717 | data->in_scale[3] = 5000; |
| 718 | data->in_scale[4] = 12000; |
| 719 | data->in_scale[5] = 2700; |
| 720 | data->in_scale[6] = 1875; |
| 721 | data->in_scale[7] = 1875; |
| 722 | |
| 723 | /* Register sysfs hooks */ |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 724 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 725 | goto exit_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
| 727 | if (data->channel & CHAN_NO_FAN(0)) { |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 728 | if ((err = device_create_file(&new_client->dev, |
| 729 | &dev_attr_in6_input)) |
| 730 | || (err = device_create_file(&new_client->dev, |
| 731 | &dev_attr_in6_min)) |
| 732 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 733 | &dev_attr_in6_max)) |
| 734 | || (err = device_create_file(&new_client->dev, |
| 735 | &sensor_dev_attr_in6_alarm.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 736 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } else { |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 738 | if ((err = device_create_file(&new_client->dev, |
| 739 | &dev_attr_fan1_input)) |
| 740 | || (err = device_create_file(&new_client->dev, |
| 741 | &dev_attr_fan1_min)) |
| 742 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 743 | &dev_attr_fan1_div)) |
| 744 | || (err = device_create_file(&new_client->dev, |
| 745 | &sensor_dev_attr_fan1_alarm.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 746 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 749 | if (data->channel & CHAN_NO_FAN(1)) { |
| 750 | if ((err = device_create_file(&new_client->dev, |
| 751 | &dev_attr_in7_input)) |
| 752 | || (err = device_create_file(&new_client->dev, |
| 753 | &dev_attr_in7_min)) |
| 754 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 755 | &dev_attr_in7_max)) |
| 756 | || (err = device_create_file(&new_client->dev, |
| 757 | &sensor_dev_attr_in7_alarm.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 758 | goto exit_remove; |
| 759 | } else { |
| 760 | if ((err = device_create_file(&new_client->dev, |
| 761 | &dev_attr_fan2_input)) |
| 762 | || (err = device_create_file(&new_client->dev, |
| 763 | &dev_attr_fan2_min)) |
| 764 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 765 | &dev_attr_fan2_div)) |
| 766 | || (err = device_create_file(&new_client->dev, |
| 767 | &sensor_dev_attr_fan2_alarm.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 768 | goto exit_remove; |
| 769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | if (data->channel & CHAN_TEMP3) { |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 772 | if ((err = device_create_file(&new_client->dev, |
| 773 | &dev_attr_temp3_input)) |
| 774 | || (err = device_create_file(&new_client->dev, |
| 775 | &dev_attr_temp3_max)) |
| 776 | || (err = device_create_file(&new_client->dev, |
| 777 | &dev_attr_temp3_min)) |
| 778 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 779 | &dev_attr_temp3_crit)) |
| 780 | || (err = device_create_file(&new_client->dev, |
| 781 | &sensor_dev_attr_temp3_alarm.dev_attr)) |
| 782 | || (err = device_create_file(&new_client->dev, |
| 783 | &sensor_dev_attr_temp3_fault.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 784 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } else { |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 786 | if ((err = device_create_file(&new_client->dev, |
| 787 | &dev_attr_in0_input)) |
| 788 | || (err = device_create_file(&new_client->dev, |
| 789 | &dev_attr_in0_min)) |
| 790 | || (err = device_create_file(&new_client->dev, |
| 791 | &dev_attr_in0_max)) |
| 792 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 793 | &sensor_dev_attr_in0_alarm.dev_attr)) |
| 794 | || (err = device_create_file(&new_client->dev, |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 795 | &dev_attr_in5_input)) |
| 796 | || (err = device_create_file(&new_client->dev, |
| 797 | &dev_attr_in5_min)) |
| 798 | || (err = device_create_file(&new_client->dev, |
Jean Delvare | c2803b9 | 2007-09-26 23:39:01 +0200 | [diff] [blame] | 799 | &dev_attr_in5_max)) |
| 800 | || (err = device_create_file(&new_client->dev, |
| 801 | &sensor_dev_attr_in5_alarm.dev_attr))) |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 802 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (!(data->channel & CHAN_NO_VID)) { |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 806 | data->vrm = vid_which_vrm(); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 807 | if ((err = device_create_file(&new_client->dev, |
| 808 | &dev_attr_cpu0_vid)) |
| 809 | || (err = device_create_file(&new_client->dev, |
| 810 | &dev_attr_vrm))) |
| 811 | goto exit_remove; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 814 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
| 815 | if (IS_ERR(data->hwmon_dev)) { |
| 816 | err = PTR_ERR(data->hwmon_dev); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 817 | goto exit_remove; |
| 818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
| 820 | return 0; |
| 821 | |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 822 | exit_remove: |
| 823 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group); |
| 824 | sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | exit_free: |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 826 | lm87_write_value(new_client, LM87_REG_CONFIG, data->config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | kfree(data); |
| 828 | exit: |
| 829 | return err; |
| 830 | } |
| 831 | |
| 832 | static void lm87_init_client(struct i2c_client *client) |
| 833 | { |
| 834 | struct lm87_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Ben Hutchings | 47064d6 | 2008-10-17 17:51:12 +0200 | [diff] [blame] | 836 | if (client->dev.platform_data) { |
| 837 | data->channel = *(u8 *)client->dev.platform_data; |
| 838 | lm87_write_value(client, |
| 839 | LM87_REG_CHANNEL_MODE, data->channel); |
| 840 | } else { |
| 841 | data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE); |
| 842 | } |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 843 | data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 845 | if (!(data->config & 0x01)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | int i; |
| 847 | |
| 848 | /* Limits are left uninitialized after power-up */ |
| 849 | for (i = 1; i < 6; i++) { |
| 850 | lm87_write_value(client, LM87_REG_IN_MIN(i), 0x00); |
| 851 | lm87_write_value(client, LM87_REG_IN_MAX(i), 0xFF); |
| 852 | } |
| 853 | for (i = 0; i < 2; i++) { |
| 854 | lm87_write_value(client, LM87_REG_TEMP_HIGH[i], 0x7F); |
| 855 | lm87_write_value(client, LM87_REG_TEMP_LOW[i], 0x00); |
| 856 | lm87_write_value(client, LM87_REG_AIN_MIN(i), 0x00); |
| 857 | lm87_write_value(client, LM87_REG_AIN_MAX(i), 0xFF); |
| 858 | } |
| 859 | if (data->channel & CHAN_TEMP3) { |
| 860 | lm87_write_value(client, LM87_REG_TEMP_HIGH[2], 0x7F); |
| 861 | lm87_write_value(client, LM87_REG_TEMP_LOW[2], 0x00); |
| 862 | } else { |
| 863 | lm87_write_value(client, LM87_REG_IN_MIN(0), 0x00); |
| 864 | lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF); |
| 865 | } |
| 866 | } |
Ben Hutchings | 49ae6cc | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 867 | |
| 868 | /* Make sure Start is set and INT#_Clear is clear */ |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 869 | if ((data->config & 0x09) != 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | lm87_write_value(client, LM87_REG_CONFIG, |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 871 | (data->config & 0x77) | 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Jean Delvare | a888420 | 2008-07-16 19:30:14 +0200 | [diff] [blame] | 874 | static int lm87_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 876 | struct lm87_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 878 | hwmon_device_unregister(data->hwmon_dev); |
Mark M. Hoffman | 0501a38 | 2006-09-24 21:14:35 +0200 | [diff] [blame] | 879 | sysfs_remove_group(&client->dev.kobj, &lm87_group); |
| 880 | sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 881 | |
Ben Hutchings | d2cac80 | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 882 | lm87_write_value(client, LM87_REG_CONFIG, data->config); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 883 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static struct lm87_data *lm87_update_device(struct device *dev) |
| 888 | { |
| 889 | struct i2c_client *client = to_i2c_client(dev); |
| 890 | struct lm87_data *data = i2c_get_clientdata(client); |
| 891 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 892 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
| 895 | int i, j; |
| 896 | |
| 897 | dev_dbg(&client->dev, "Updating data.\n"); |
| 898 | |
| 899 | i = (data->channel & CHAN_TEMP3) ? 1 : 0; |
| 900 | j = (data->channel & CHAN_TEMP3) ? 5 : 6; |
| 901 | for (; i < j; i++) { |
| 902 | data->in[i] = lm87_read_value(client, |
| 903 | LM87_REG_IN(i)); |
| 904 | data->in_min[i] = lm87_read_value(client, |
| 905 | LM87_REG_IN_MIN(i)); |
| 906 | data->in_max[i] = lm87_read_value(client, |
| 907 | LM87_REG_IN_MAX(i)); |
| 908 | } |
| 909 | |
| 910 | for (i = 0; i < 2; i++) { |
| 911 | if (data->channel & CHAN_NO_FAN(i)) { |
| 912 | data->in[6+i] = lm87_read_value(client, |
| 913 | LM87_REG_AIN(i)); |
| 914 | data->in_max[6+i] = lm87_read_value(client, |
| 915 | LM87_REG_AIN_MAX(i)); |
| 916 | data->in_min[6+i] = lm87_read_value(client, |
| 917 | LM87_REG_AIN_MIN(i)); |
| 918 | |
| 919 | } else { |
| 920 | data->fan[i] = lm87_read_value(client, |
| 921 | LM87_REG_FAN(i)); |
| 922 | data->fan_min[i] = lm87_read_value(client, |
| 923 | LM87_REG_FAN_MIN(i)); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | j = (data->channel & CHAN_TEMP3) ? 3 : 2; |
| 928 | for (i = 0 ; i < j; i++) { |
| 929 | data->temp[i] = lm87_read_value(client, |
| 930 | LM87_REG_TEMP[i]); |
| 931 | data->temp_high[i] = lm87_read_value(client, |
| 932 | LM87_REG_TEMP_HIGH[i]); |
| 933 | data->temp_low[i] = lm87_read_value(client, |
| 934 | LM87_REG_TEMP_LOW[i]); |
| 935 | } |
| 936 | |
| 937 | i = lm87_read_value(client, LM87_REG_TEMP_HW_INT_LOCK); |
| 938 | j = lm87_read_value(client, LM87_REG_TEMP_HW_INT); |
| 939 | data->temp_crit_int = min(i, j); |
| 940 | |
| 941 | i = lm87_read_value(client, LM87_REG_TEMP_HW_EXT_LOCK); |
| 942 | j = lm87_read_value(client, LM87_REG_TEMP_HW_EXT); |
| 943 | data->temp_crit_ext = min(i, j); |
| 944 | |
| 945 | i = lm87_read_value(client, LM87_REG_VID_FAN_DIV); |
| 946 | data->fan_div[0] = (i >> 4) & 0x03; |
| 947 | data->fan_div[1] = (i >> 6) & 0x03; |
| 948 | data->vid = (i & 0x0F) |
| 949 | | (lm87_read_value(client, LM87_REG_VID4) & 0x01) |
| 950 | << 4; |
| 951 | |
| 952 | data->alarms = lm87_read_value(client, LM87_REG_ALARMS1) |
| 953 | | (lm87_read_value(client, LM87_REG_ALARMS2) |
| 954 | << 8); |
| 955 | data->aout = lm87_read_value(client, LM87_REG_AOUT); |
| 956 | |
| 957 | data->last_updated = jiffies; |
| 958 | data->valid = 1; |
| 959 | } |
| 960 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 961 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
| 963 | return data; |
| 964 | } |
| 965 | |
| 966 | static int __init sensors_lm87_init(void) |
| 967 | { |
| 968 | return i2c_add_driver(&lm87_driver); |
| 969 | } |
| 970 | |
| 971 | static void __exit sensors_lm87_exit(void) |
| 972 | { |
| 973 | i2c_del_driver(&lm87_driver); |
| 974 | } |
| 975 | |
| 976 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org> and others"); |
| 977 | MODULE_DESCRIPTION("LM87 driver"); |
| 978 | MODULE_LICENSE("GPL"); |
| 979 | |
| 980 | module_init(sensors_lm87_init); |
| 981 | module_exit(sensors_lm87_exit); |