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