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