blob: 94a10ecd24dfcbe8782d5155af488b96e79d6edd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
Jean Delvare1f448092008-04-29 14:03:37 +02004 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
Jean Delvare8a0795d2008-10-17 17:51:14 +02008 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/jiffies.h>
31#include <linux/i2c.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040032#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020033#include <linux/hwmon-vid.h>
Jean Delvareb353a482007-07-05 20:36:12 +020034#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040035#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010036#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/* Addresses to scan */
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050039static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* Insmod parameters */
Jean Delvaref4b50262005-07-31 21:49:03 +020042I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* The LM85 registers */
45
46#define LM85_REG_IN(nr) (0x20 + (nr))
47#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
48#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
49
50#define LM85_REG_TEMP(nr) (0x25 + (nr))
51#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
52#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
53
54/* Fan speeds are LSB, MSB (2 bytes) */
Jean Delvare1f448092008-04-29 14:03:37 +020055#define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
56#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define LM85_REG_PWM(nr) (0x30 + (nr))
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define LM85_REG_COMPANY 0x3e
61#define LM85_REG_VERSTEP 0x3f
62/* These are the recognized values for the above regs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define LM85_COMPANY_NATIONAL 0x01
64#define LM85_COMPANY_ANALOG_DEV 0x41
Jean Delvare1f448092008-04-29 14:03:37 +020065#define LM85_COMPANY_SMSC 0x5c
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define LM85_VERSTEP_VMASK 0xf0
67#define LM85_VERSTEP_GENERIC 0x60
68#define LM85_VERSTEP_LM85C 0x60
69#define LM85_VERSTEP_LM85B 0x62
70#define LM85_VERSTEP_ADM1027 0x60
71#define LM85_VERSTEP_ADT7463 0x62
72#define LM85_VERSTEP_ADT7463C 0x6A
73#define LM85_VERSTEP_EMC6D100_A0 0x60
74#define LM85_VERSTEP_EMC6D100_A1 0x61
75#define LM85_VERSTEP_EMC6D102 0x65
76
77#define LM85_REG_CONFIG 0x40
78
79#define LM85_REG_ALARM1 0x41
80#define LM85_REG_ALARM2 0x42
81
82#define LM85_REG_VID 0x43
83
84/* Automated FAN control */
85#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
86#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
87#define LM85_REG_AFAN_SPIKE1 0x62
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
89#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
90#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
91#define LM85_REG_AFAN_HYST1 0x6d
92#define LM85_REG_AFAN_HYST2 0x6e
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define ADM1027_REG_EXTEND_ADC1 0x76
95#define ADM1027_REG_EXTEND_ADC2 0x77
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#define EMC6D100_REG_ALARM3 0x7d
98/* IN5, IN6 and IN7 */
Jean Delvare1f448092008-04-29 14:03:37 +020099#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
100#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
101#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define EMC6D102_REG_EXTEND_ADC1 0x85
103#define EMC6D102_REG_EXTEND_ADC2 0x86
104#define EMC6D102_REG_EXTEND_ADC3 0x87
105#define EMC6D102_REG_EXTEND_ADC4 0x88
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Jean Delvare1f448092008-04-29 14:03:37 +0200108/* Conversions. Rounding and limit checking is only done on the TO_REG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 variants. Note that you should be a bit careful with which arguments
110 these macros are called: arguments may be evaluated more than once.
111 */
112
113/* IN are scaled acording to built-in resistors */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400114static const int lm85_scaling[] = { /* .001 Volts */
Jean Delvare1f448092008-04-29 14:03:37 +0200115 2500, 2250, 3300, 5000, 12000,
116 3300, 1500, 1800 /*EMC6D100*/
117};
118#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Jean Delvare1f448092008-04-29 14:03:37 +0200120#define INS_TO_REG(n, val) \
121 SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Jean Delvare1f448092008-04-29 14:03:37 +0200123#define INSEXT_FROM_REG(n, val, ext) \
Jean Delvare5a4d3ef2007-07-05 20:38:32 +0200124 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Jean Delvare1f448092008-04-29 14:03:37 +0200126#define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* FAN speed is measured using 90kHz clock */
Jean Delvare63f281a2007-07-05 20:39:40 +0200129static inline u16 FAN_TO_REG(unsigned long val)
130{
131 if (!val)
132 return 0xffff;
133 return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
134}
Jean Delvare1f448092008-04-29 14:03:37 +0200135#define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
136 5400000 / (val))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138/* Temperature is reported in .001 degC increments */
139#define TEMP_TO_REG(val) \
Jean Delvare1f448092008-04-29 14:03:37 +0200140 SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
141#define TEMPEXT_FROM_REG(val, ext) \
Jean Delvare5a4d3ef2007-07-05 20:38:32 +0200142 SCALE(((val) << 4) + (ext), 16, 1000)
143#define TEMP_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Jean Delvare1f448092008-04-29 14:03:37 +0200145#define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define PWM_FROM_REG(val) (val)
147
148
149/* ZONEs have the following parameters:
150 * Limit (low) temp, 1. degC
151 * Hysteresis (below limit), 1. degC (0-15)
152 * Range of speed control, .1 degC (2-80)
153 * Critical (high) temp, 1. degC
154 *
155 * FAN PWMs have the following parameters:
156 * Reference Zone, 1, 2, 3, etc.
157 * Spinup time, .05 sec
158 * PWM value at limit/low temp, 1 count
159 * PWM Frequency, 1. Hz
160 * PWM is Min or OFF below limit, flag
161 * Invert PWM output, flag
162 *
163 * Some chips filter the temp, others the fan.
164 * Filter constant (or disabled) .1 seconds
165 */
166
167/* These are the zone temperature range encodings in .001 degree C */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400168static const int lm85_range_map[] = {
Jean Delvare1f448092008-04-29 14:03:37 +0200169 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
170 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
171};
172
173static int RANGE_TO_REG(int range)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 int i;
176
Jean Delvared38b1492008-04-03 10:40:39 +0200177 /* Find the closest match */
Jean Delvare1b92ada2008-10-17 17:51:14 +0200178 for (i = 0; i < 15; ++i) {
179 if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
180 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
Jean Delvared38b1492008-04-03 10:40:39 +0200182
Jean Delvare1b92ada2008-10-17 17:51:14 +0200183 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
Jean Delvare1f448092008-04-29 14:03:37 +0200185#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* These are the PWM frequency encodings */
Jean Delvare34e7dc62008-10-17 17:51:13 +0200188static const int lm85_freq_map[8] = { /* 1 Hz */
Jean Delvare8a0795d2008-10-17 17:51:14 +0200189 10, 15, 23, 30, 38, 47, 61, 94
190};
191static const int adm1027_freq_map[8] = { /* 1 Hz */
192 11, 15, 22, 29, 35, 44, 59, 88
Jean Delvare1f448092008-04-29 14:03:37 +0200193};
194
Jean Delvare8a0795d2008-10-17 17:51:14 +0200195static int FREQ_TO_REG(const int *map, int freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
197 int i;
198
Jean Delvare86010c92008-10-17 17:51:13 +0200199 /* Find the closest match */
Jean Delvare1f448092008-04-29 14:03:37 +0200200 for (i = 0; i < 7; ++i)
Jean Delvare8a0795d2008-10-17 17:51:14 +0200201 if (freq <= (map[i] + map[i + 1]) / 2)
Jean Delvare1f448092008-04-29 14:03:37 +0200202 break;
Jean Delvaree89e22b2008-06-25 08:47:35 -0400203 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
Jean Delvare8a0795d2008-10-17 17:51:14 +0200205
206static int FREQ_FROM_REG(const int *map, u8 reg)
207{
208 return map[reg & 0x07];
209}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/* Since we can't use strings, I'm abusing these numbers
212 * to stand in for the following meanings:
213 * 1 -- PWM responds to Zone 1
214 * 2 -- PWM responds to Zone 2
215 * 3 -- PWM responds to Zone 3
216 * 23 -- PWM responds to the higher temp of Zone 2 or 3
217 * 123 -- PWM responds to highest of Zone 1, 2, or 3
218 * 0 -- PWM is always at 0% (ie, off)
219 * -1 -- PWM is always at 100%
220 * -2 -- PWM responds to manual control
221 */
222
Jean Delvaree89e22b2008-06-25 08:47:35 -0400223static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
224#define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Jean Delvare1f448092008-04-29 14:03:37 +0200226static int ZONE_TO_REG(int zone)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 int i;
229
Jean Delvare1f448092008-04-29 14:03:37 +0200230 for (i = 0; i <= 7; ++i)
231 if (zone == lm85_zone_map[i])
232 break;
233 if (i > 7) /* Not found. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 i = 3; /* Always 100% */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400235 return i << 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
Jean Delvare1f448092008-04-29 14:03:37 +0200238#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
239#define HYST_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/* Chip sampling rates
242 *
243 * Some sensors are not updated more frequently than once per second
244 * so it doesn't make sense to read them more often than that.
245 * We cache the results and return the saved data if the driver
246 * is called again before a second has elapsed.
247 *
248 * Also, there is significant configuration data for this chip
249 * given the automatic PWM fan control that is possible. There
250 * are about 47 bytes of config data to only 22 bytes of actual
251 * readings. So, we keep the config data up to date in the cache
252 * when it is written and only sample it once every 1 *minute*
253 */
254#define LM85_DATA_INTERVAL (HZ + HZ / 2)
255#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* LM85 can automatically adjust fan speeds based on temperature
258 * This structure encapsulates an entire Zone config. There are
259 * three zones (one for each temperature input) on the lm85
260 */
261struct lm85_zone {
262 s8 limit; /* Low temp limit */
263 u8 hyst; /* Low limit hysteresis. (0-15) */
264 u8 range; /* Temp range, encoded */
265 s8 critical; /* "All fans ON" temp limit */
Jean Delvare1f448092008-04-29 14:03:37 +0200266 u8 off_desired; /* Actual "off" temperature specified. Preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 * to prevent "drift" as other autofan control
268 * values change.
269 */
Jean Delvare1f448092008-04-29 14:03:37 +0200270 u8 max_desired; /* Actual "max" temperature specified. Preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 * to prevent "drift" as other autofan control
272 * values change.
273 */
274};
275
276struct lm85_autofan {
277 u8 config; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 u8 min_pwm; /* Minimum PWM value, encoded */
279 u8 min_off; /* Min PWM or OFF below "limit", flag */
280};
281
Jean Delvareed6bafb2007-02-14 21:15:03 +0100282/* For each registered chip, we need to keep some data in memory.
283 The structure is dynamically allocated. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284struct lm85_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700285 struct device *hwmon_dev;
Jean Delvare8a0795d2008-10-17 17:51:14 +0200286 const int *freq_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 enum chips type;
288
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100289 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 int valid; /* !=0 if following fields are valid */
291 unsigned long last_reading; /* In jiffies */
292 unsigned long last_config; /* In jiffies */
293
294 u8 in[8]; /* Register value */
295 u8 in_max[8]; /* Register value */
296 u8 in_min[8]; /* Register value */
297 s8 temp[3]; /* Register value */
298 s8 temp_min[3]; /* Register value */
299 s8 temp_max[3]; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 u16 fan[4]; /* Register value */
301 u16 fan_min[4]; /* Register value */
302 u8 pwm[3]; /* Register value */
Jean Delvare34e7dc62008-10-17 17:51:13 +0200303 u8 pwm_freq[3]; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 u8 temp_ext[3]; /* Decoded values */
305 u8 in_ext[8]; /* Decoded values */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 u8 vid; /* Register value */
307 u8 vrm; /* VRM version */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 u32 alarms; /* Register encoding, combined */
309 struct lm85_autofan autofan[3];
310 struct lm85_zone zone[3];
311};
312
Jean Delvare67712d02008-10-17 17:51:14 +0200313static int lm85_detect(struct i2c_client *client, int kind,
314 struct i2c_board_info *info);
315static int lm85_probe(struct i2c_client *client,
316 const struct i2c_device_id *id);
317static int lm85_remove(struct i2c_client *client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Darren Jenkinsf6c27fc2006-02-27 23:14:58 +0100319static int lm85_read_value(struct i2c_client *client, u8 reg);
Jean Delvaree89e22b2008-06-25 08:47:35 -0400320static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static struct lm85_data *lm85_update_device(struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323
Jean Delvare67712d02008-10-17 17:51:14 +0200324static const struct i2c_device_id lm85_id[] = {
325 { "adm1027", adm1027 },
326 { "adt7463", adt7463 },
327 { "lm85", any_chip },
328 { "lm85b", lm85b },
329 { "lm85c", lm85c },
330 { "emc6d100", emc6d100 },
331 { "emc6d101", emc6d100 },
332 { "emc6d102", emc6d102 },
333 { }
334};
335MODULE_DEVICE_TABLE(i2c, lm85_id);
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337static struct i2c_driver lm85_driver = {
Jean Delvare67712d02008-10-17 17:51:14 +0200338 .class = I2C_CLASS_HWMON,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100339 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100340 .name = "lm85",
341 },
Jean Delvare67712d02008-10-17 17:51:14 +0200342 .probe = lm85_probe,
343 .remove = lm85_remove,
344 .id_table = lm85_id,
345 .detect = lm85_detect,
346 .address_data = &addr_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347};
348
349
350/* 4 Fans */
Jean Delvareb353a482007-07-05 20:36:12 +0200351static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
352 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Jean Delvareb353a482007-07-05 20:36:12 +0200354 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200356 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
Jean Delvareb353a482007-07-05 20:36:12 +0200358
359static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
360 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Jean Delvareb353a482007-07-05 20:36:12 +0200362 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200364 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
Jean Delvareb353a482007-07-05 20:36:12 +0200366
367static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
368 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Jean Delvareb353a482007-07-05 20:36:12 +0200370 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct i2c_client *client = to_i2c_client(dev);
372 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare63f281a2007-07-05 20:39:40 +0200373 unsigned long val = simple_strtoul(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100375 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 data->fan_min[nr] = FAN_TO_REG(val);
377 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100378 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return count;
380}
381
382#define show_fan_offset(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200383static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
384 show_fan, NULL, offset - 1); \
385static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
386 show_fan_min, set_fan_min, offset - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388show_fan_offset(1);
389show_fan_offset(2);
390show_fan_offset(3);
391show_fan_offset(4);
392
393/* vid, vrm, alarms */
394
Jean Delvare1f448092008-04-29 14:03:37 +0200395static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
396 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
398 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare9c516ef2005-11-26 20:07:54 +0100399 int vid;
400
401 if (data->type == adt7463 && (data->vid & 0x80)) {
402 /* 6-pin VID (VRM 10) */
403 vid = vid_from_reg(data->vid & 0x3f, data->vrm);
404 } else {
405 /* 5-pin VID (VRM 9) */
406 vid = vid_from_reg(data->vid & 0x1f, data->vrm);
407 }
408
409 return sprintf(buf, "%d\n", vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
412static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
413
Jean Delvare1f448092008-04-29 14:03:37 +0200414static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
415 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Jean Delvare90d66192007-10-08 18:24:35 +0200417 struct lm85_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return sprintf(buf, "%ld\n", (long) data->vrm);
419}
420
Jean Delvare1f448092008-04-29 14:03:37 +0200421static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
422 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Jean Delvare8f74efe2007-12-01 11:25:33 +0100424 struct lm85_data *data = dev_get_drvdata(dev);
425 data->vrm = simple_strtoul(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return count;
427}
428
429static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
430
Jean Delvare1f448092008-04-29 14:03:37 +0200431static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
432 *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
434 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200435 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
438static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
439
Jean Delvarebf76e9d2007-07-05 20:37:58 +0200440static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
441 char *buf)
442{
443 int nr = to_sensor_dev_attr(attr)->index;
444 struct lm85_data *data = lm85_update_device(dev);
445 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
446}
447
448static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
449static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
450static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
451static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
452static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
453static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
454static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
455static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
456static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
457static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
458static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
459static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
460static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
461static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
462static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
463static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
464static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/* pwm */
467
Jean Delvareb353a482007-07-05 20:36:12 +0200468static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
469 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Jean Delvareb353a482007-07-05 20:36:12 +0200471 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200473 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
Jean Delvareb353a482007-07-05 20:36:12 +0200475
476static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
477 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Jean Delvareb353a482007-07-05 20:36:12 +0200479 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 struct i2c_client *client = to_i2c_client(dev);
481 struct lm85_data *data = i2c_get_clientdata(client);
482 long val = simple_strtol(buf, NULL, 10);
483
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100484 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 data->pwm[nr] = PWM_TO_REG(val);
486 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100487 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return count;
489}
Jean Delvareb353a482007-07-05 20:36:12 +0200490
491static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
492 *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Jean Delvareb353a482007-07-05 20:36:12 +0200494 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare4b4df952007-12-03 23:23:21 +0100496 int pwm_zone, enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
Jean Delvare4b4df952007-12-03 23:23:21 +0100499 switch (pwm_zone) {
500 case -1: /* PWM is always at 100% */
501 enable = 0;
502 break;
503 case 0: /* PWM is always at 0% */
504 case -2: /* PWM responds to manual control */
505 enable = 1;
506 break;
507 default: /* PWM in automatic mode */
508 enable = 2;
509 }
510 return sprintf(buf, "%d\n", enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Jean Delvare455f7912007-12-03 23:28:42 +0100513static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
514 *attr, const char *buf, size_t count)
515{
516 int nr = to_sensor_dev_attr(attr)->index;
517 struct i2c_client *client = to_i2c_client(dev);
518 struct lm85_data *data = i2c_get_clientdata(client);
519 long val = simple_strtol(buf, NULL, 10);
520 u8 config;
521
522 switch (val) {
523 case 0:
524 config = 3;
525 break;
526 case 1:
527 config = 7;
528 break;
529 case 2:
530 /* Here we have to choose arbitrarily one of the 5 possible
531 configurations; I go for the safest */
532 config = 6;
533 break;
534 default:
535 return -EINVAL;
536 }
537
538 mutex_lock(&data->update_lock);
539 data->autofan[nr].config = lm85_read_value(client,
540 LM85_REG_AFAN_CONFIG(nr));
541 data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
542 | (config << 5);
543 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
544 data->autofan[nr].config);
545 mutex_unlock(&data->update_lock);
546 return count;
547}
548
Jean Delvare34e7dc62008-10-17 17:51:13 +0200549static ssize_t show_pwm_freq(struct device *dev,
550 struct device_attribute *attr, char *buf)
551{
552 int nr = to_sensor_dev_attr(attr)->index;
553 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare8a0795d2008-10-17 17:51:14 +0200554 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
555 data->pwm_freq[nr]));
Jean Delvare34e7dc62008-10-17 17:51:13 +0200556}
557
558static ssize_t set_pwm_freq(struct device *dev,
559 struct device_attribute *attr, const char *buf, size_t count)
560{
561 int nr = to_sensor_dev_attr(attr)->index;
562 struct i2c_client *client = to_i2c_client(dev);
563 struct lm85_data *data = i2c_get_clientdata(client);
564 long val = simple_strtol(buf, NULL, 10);
565
566 mutex_lock(&data->update_lock);
Jean Delvare8a0795d2008-10-17 17:51:14 +0200567 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
Jean Delvare34e7dc62008-10-17 17:51:13 +0200568 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
569 (data->zone[nr].range << 4)
570 | data->pwm_freq[nr]);
571 mutex_unlock(&data->update_lock);
572 return count;
573}
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#define show_pwm_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200576static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
577 show_pwm, set_pwm, offset - 1); \
Jean Delvare455f7912007-12-03 23:28:42 +0100578static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
Jean Delvare34e7dc62008-10-17 17:51:13 +0200579 show_pwm_enable, set_pwm_enable, offset - 1); \
580static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
581 show_pwm_freq, set_pwm_freq, offset - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583show_pwm_reg(1);
584show_pwm_reg(2);
585show_pwm_reg(3);
586
587/* Voltages */
588
Jean Delvareb353a482007-07-05 20:36:12 +0200589static ssize_t show_in(struct device *dev, struct device_attribute *attr,
590 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Jean Delvareb353a482007-07-05 20:36:12 +0200592 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200594 return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
595 data->in_ext[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
Jean Delvareb353a482007-07-05 20:36:12 +0200597
Jean Delvare1f448092008-04-29 14:03:37 +0200598static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
Jean Delvareb353a482007-07-05 20:36:12 +0200599 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Jean Delvareb353a482007-07-05 20:36:12 +0200601 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200603 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
Jean Delvareb353a482007-07-05 20:36:12 +0200605
606static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
607 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Jean Delvareb353a482007-07-05 20:36:12 +0200609 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 struct i2c_client *client = to_i2c_client(dev);
611 struct lm85_data *data = i2c_get_clientdata(client);
612 long val = simple_strtol(buf, NULL, 10);
613
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100614 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 data->in_min[nr] = INS_TO_REG(nr, val);
616 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100617 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return count;
619}
Jean Delvareb353a482007-07-05 20:36:12 +0200620
621static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
622 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Jean Delvareb353a482007-07-05 20:36:12 +0200624 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200626 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
Jean Delvareb353a482007-07-05 20:36:12 +0200628
629static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
630 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Jean Delvareb353a482007-07-05 20:36:12 +0200632 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 struct i2c_client *client = to_i2c_client(dev);
634 struct lm85_data *data = i2c_get_clientdata(client);
635 long val = simple_strtol(buf, NULL, 10);
636
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100637 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 data->in_max[nr] = INS_TO_REG(nr, val);
639 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100640 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return count;
642}
Jean Delvareb353a482007-07-05 20:36:12 +0200643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#define show_in_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200645static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
646 show_in, NULL, offset); \
647static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
648 show_in_min, set_in_min, offset); \
649static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
650 show_in_max, set_in_max, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652show_in_reg(0);
653show_in_reg(1);
654show_in_reg(2);
655show_in_reg(3);
656show_in_reg(4);
Jean Delvare6b9aad22007-07-05 20:37:21 +0200657show_in_reg(5);
658show_in_reg(6);
659show_in_reg(7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661/* Temps */
662
Jean Delvareb353a482007-07-05 20:36:12 +0200663static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
664 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Jean Delvareb353a482007-07-05 20:36:12 +0200666 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200668 return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
669 data->temp_ext[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
Jean Delvareb353a482007-07-05 20:36:12 +0200671
672static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
673 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Jean Delvareb353a482007-07-05 20:36:12 +0200675 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200677 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
Jean Delvareb353a482007-07-05 20:36:12 +0200679
680static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
681 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Jean Delvareb353a482007-07-05 20:36:12 +0200683 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 struct i2c_client *client = to_i2c_client(dev);
685 struct lm85_data *data = i2c_get_clientdata(client);
686 long val = simple_strtol(buf, NULL, 10);
687
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100688 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 data->temp_min[nr] = TEMP_TO_REG(val);
690 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100691 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 return count;
693}
Jean Delvareb353a482007-07-05 20:36:12 +0200694
695static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
696 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Jean Delvareb353a482007-07-05 20:36:12 +0200698 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200700 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
Jean Delvareb353a482007-07-05 20:36:12 +0200702
703static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
704 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Jean Delvareb353a482007-07-05 20:36:12 +0200706 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 struct i2c_client *client = to_i2c_client(dev);
708 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare1f448092008-04-29 14:03:37 +0200709 long val = simple_strtol(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100711 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 data->temp_max[nr] = TEMP_TO_REG(val);
713 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100714 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return count;
716}
Jean Delvareb353a482007-07-05 20:36:12 +0200717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#define show_temp_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200719static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
720 show_temp, NULL, offset - 1); \
721static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
722 show_temp_min, set_temp_min, offset - 1); \
723static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
724 show_temp_max, set_temp_max, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726show_temp_reg(1);
727show_temp_reg(2);
728show_temp_reg(3);
729
730
731/* Automatic PWM control */
732
Jean Delvareb353a482007-07-05 20:36:12 +0200733static ssize_t show_pwm_auto_channels(struct device *dev,
734 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Jean Delvareb353a482007-07-05 20:36:12 +0200736 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200738 return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
Jean Delvareb353a482007-07-05 20:36:12 +0200740
741static ssize_t set_pwm_auto_channels(struct device *dev,
742 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
Jean Delvareb353a482007-07-05 20:36:12 +0200744 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 struct i2c_client *client = to_i2c_client(dev);
746 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare1f448092008-04-29 14:03:37 +0200747 long val = simple_strtol(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100749 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
Jean Delvare1f448092008-04-29 14:03:37 +0200751 | ZONE_TO_REG(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
753 data->autofan[nr].config);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100754 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 return count;
756}
Jean Delvareb353a482007-07-05 20:36:12 +0200757
758static ssize_t show_pwm_auto_pwm_min(struct device *dev,
759 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760{
Jean Delvareb353a482007-07-05 20:36:12 +0200761 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200763 return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
Jean Delvareb353a482007-07-05 20:36:12 +0200765
766static ssize_t set_pwm_auto_pwm_min(struct device *dev,
767 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Jean Delvareb353a482007-07-05 20:36:12 +0200769 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 struct i2c_client *client = to_i2c_client(dev);
771 struct lm85_data *data = i2c_get_clientdata(client);
772 long val = simple_strtol(buf, NULL, 10);
773
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100774 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 data->autofan[nr].min_pwm = PWM_TO_REG(val);
776 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
777 data->autofan[nr].min_pwm);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100778 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return count;
780}
Jean Delvareb353a482007-07-05 20:36:12 +0200781
782static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
783 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Jean Delvareb353a482007-07-05 20:36:12 +0200785 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200787 return sprintf(buf, "%d\n", data->autofan[nr].min_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788}
Jean Delvareb353a482007-07-05 20:36:12 +0200789
790static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
791 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
Jean Delvareb353a482007-07-05 20:36:12 +0200793 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 struct i2c_client *client = to_i2c_client(dev);
795 struct lm85_data *data = i2c_get_clientdata(client);
796 long val = simple_strtol(buf, NULL, 10);
Jean Delvare7133e562008-04-12 19:56:35 +0200797 u8 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100799 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 data->autofan[nr].min_off = val;
Jean Delvare7133e562008-04-12 19:56:35 +0200801 tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
802 tmp &= ~(0x20 << nr);
803 if (data->autofan[nr].min_off)
804 tmp |= 0x20 << nr;
805 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100806 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 return count;
808}
Jean Delvareb353a482007-07-05 20:36:12 +0200809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810#define pwm_auto(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200811static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
812 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
813 set_pwm_auto_channels, offset - 1); \
814static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
815 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
816 set_pwm_auto_pwm_min, offset - 1); \
817static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
818 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
Jean Delvare34e7dc62008-10-17 17:51:13 +0200819 set_pwm_auto_pwm_minctl, offset - 1)
Jean Delvareb353a482007-07-05 20:36:12 +0200820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821pwm_auto(1);
822pwm_auto(2);
823pwm_auto(3);
824
825/* Temperature settings for automatic PWM control */
826
Jean Delvareb353a482007-07-05 20:36:12 +0200827static ssize_t show_temp_auto_temp_off(struct device *dev,
828 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Jean Delvareb353a482007-07-05 20:36:12 +0200830 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200832 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 HYST_FROM_REG(data->zone[nr].hyst));
834}
Jean Delvareb353a482007-07-05 20:36:12 +0200835
836static ssize_t set_temp_auto_temp_off(struct device *dev,
837 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Jean Delvareb353a482007-07-05 20:36:12 +0200839 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 struct i2c_client *client = to_i2c_client(dev);
841 struct lm85_data *data = i2c_get_clientdata(client);
842 int min;
843 long val = simple_strtol(buf, NULL, 10);
844
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100845 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 min = TEMP_FROM_REG(data->zone[nr].limit);
847 data->zone[nr].off_desired = TEMP_TO_REG(val);
848 data->zone[nr].hyst = HYST_TO_REG(min - val);
Jean Delvare1f448092008-04-29 14:03:37 +0200849 if (nr == 0 || nr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 lm85_write_value(client, LM85_REG_AFAN_HYST1,
851 (data->zone[0].hyst << 4)
Jean Delvare1f448092008-04-29 14:03:37 +0200852 | data->zone[1].hyst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 } else {
854 lm85_write_value(client, LM85_REG_AFAN_HYST2,
Jean Delvare1f448092008-04-29 14:03:37 +0200855 (data->zone[2].hyst << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100857 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 return count;
859}
Jean Delvareb353a482007-07-05 20:36:12 +0200860
861static ssize_t show_temp_auto_temp_min(struct device *dev,
862 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Jean Delvareb353a482007-07-05 20:36:12 +0200864 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200866 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
Jean Delvareb353a482007-07-05 20:36:12 +0200868
869static ssize_t set_temp_auto_temp_min(struct device *dev,
870 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
Jean Delvareb353a482007-07-05 20:36:12 +0200872 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 struct i2c_client *client = to_i2c_client(dev);
874 struct lm85_data *data = i2c_get_clientdata(client);
875 long val = simple_strtol(buf, NULL, 10);
876
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100877 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 data->zone[nr].limit = TEMP_TO_REG(val);
879 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
880 data->zone[nr].limit);
881
882/* Update temp_auto_max and temp_auto_range */
883 data->zone[nr].range = RANGE_TO_REG(
884 TEMP_FROM_REG(data->zone[nr].max_desired) -
885 TEMP_FROM_REG(data->zone[nr].limit));
886 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
887 ((data->zone[nr].range & 0x0f) << 4)
Jean Delvare34e7dc62008-10-17 17:51:13 +0200888 | (data->pwm_freq[nr] & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890/* Update temp_auto_hyst and temp_auto_off */
891 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
892 data->zone[nr].limit) - TEMP_FROM_REG(
893 data->zone[nr].off_desired));
Jean Delvare1f448092008-04-29 14:03:37 +0200894 if (nr == 0 || nr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 lm85_write_value(client, LM85_REG_AFAN_HYST1,
896 (data->zone[0].hyst << 4)
Jean Delvare1f448092008-04-29 14:03:37 +0200897 | data->zone[1].hyst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 } else {
899 lm85_write_value(client, LM85_REG_AFAN_HYST2,
Jean Delvare1f448092008-04-29 14:03:37 +0200900 (data->zone[2].hyst << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100902 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return count;
904}
Jean Delvareb353a482007-07-05 20:36:12 +0200905
906static ssize_t show_temp_auto_temp_max(struct device *dev,
907 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Jean Delvareb353a482007-07-05 20:36:12 +0200909 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200911 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 RANGE_FROM_REG(data->zone[nr].range));
913}
Jean Delvareb353a482007-07-05 20:36:12 +0200914
915static ssize_t set_temp_auto_temp_max(struct device *dev,
916 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Jean Delvareb353a482007-07-05 20:36:12 +0200918 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 struct i2c_client *client = to_i2c_client(dev);
920 struct lm85_data *data = i2c_get_clientdata(client);
921 int min;
922 long val = simple_strtol(buf, NULL, 10);
923
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100924 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 min = TEMP_FROM_REG(data->zone[nr].limit);
926 data->zone[nr].max_desired = TEMP_TO_REG(val);
927 data->zone[nr].range = RANGE_TO_REG(
928 val - min);
929 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
930 ((data->zone[nr].range & 0x0f) << 4)
Jean Delvare34e7dc62008-10-17 17:51:13 +0200931 | (data->pwm_freq[nr] & 0x07));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100932 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return count;
934}
Jean Delvareb353a482007-07-05 20:36:12 +0200935
936static ssize_t show_temp_auto_temp_crit(struct device *dev,
937 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Jean Delvareb353a482007-07-05 20:36:12 +0200939 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200941 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
Jean Delvareb353a482007-07-05 20:36:12 +0200943
944static ssize_t set_temp_auto_temp_crit(struct device *dev,
Jean Delvare1f448092008-04-29 14:03:37 +0200945 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Jean Delvareb353a482007-07-05 20:36:12 +0200947 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 struct i2c_client *client = to_i2c_client(dev);
949 struct lm85_data *data = i2c_get_clientdata(client);
950 long val = simple_strtol(buf, NULL, 10);
951
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100952 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 data->zone[nr].critical = TEMP_TO_REG(val);
954 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
955 data->zone[nr].critical);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100956 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 return count;
958}
Jean Delvareb353a482007-07-05 20:36:12 +0200959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960#define temp_auto(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200961static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
962 S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
963 set_temp_auto_temp_off, offset - 1); \
964static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
965 S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
966 set_temp_auto_temp_min, offset - 1); \
967static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
968 S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
969 set_temp_auto_temp_max, offset - 1); \
970static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
971 S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
972 set_temp_auto_temp_crit, offset - 1);
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974temp_auto(1);
975temp_auto(2);
976temp_auto(3);
977
Mark M. Hoffman0501a382006-09-24 21:14:35 +0200978static struct attribute *lm85_attributes[] = {
Jean Delvareb353a482007-07-05 20:36:12 +0200979 &sensor_dev_attr_fan1_input.dev_attr.attr,
980 &sensor_dev_attr_fan2_input.dev_attr.attr,
981 &sensor_dev_attr_fan3_input.dev_attr.attr,
982 &sensor_dev_attr_fan4_input.dev_attr.attr,
983 &sensor_dev_attr_fan1_min.dev_attr.attr,
984 &sensor_dev_attr_fan2_min.dev_attr.attr,
985 &sensor_dev_attr_fan3_min.dev_attr.attr,
986 &sensor_dev_attr_fan4_min.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +0200987 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
988 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
989 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
990 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +0200991
992 &sensor_dev_attr_pwm1.dev_attr.attr,
993 &sensor_dev_attr_pwm2.dev_attr.attr,
994 &sensor_dev_attr_pwm3.dev_attr.attr,
995 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
996 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
997 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
Jean Delvare34e7dc62008-10-17 17:51:13 +0200998 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
999 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1000 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001001
1002 &sensor_dev_attr_in0_input.dev_attr.attr,
1003 &sensor_dev_attr_in1_input.dev_attr.attr,
1004 &sensor_dev_attr_in2_input.dev_attr.attr,
1005 &sensor_dev_attr_in3_input.dev_attr.attr,
1006 &sensor_dev_attr_in0_min.dev_attr.attr,
1007 &sensor_dev_attr_in1_min.dev_attr.attr,
1008 &sensor_dev_attr_in2_min.dev_attr.attr,
1009 &sensor_dev_attr_in3_min.dev_attr.attr,
1010 &sensor_dev_attr_in0_max.dev_attr.attr,
1011 &sensor_dev_attr_in1_max.dev_attr.attr,
1012 &sensor_dev_attr_in2_max.dev_attr.attr,
1013 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001014 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1015 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1016 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1017 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001018
1019 &sensor_dev_attr_temp1_input.dev_attr.attr,
1020 &sensor_dev_attr_temp2_input.dev_attr.attr,
1021 &sensor_dev_attr_temp3_input.dev_attr.attr,
1022 &sensor_dev_attr_temp1_min.dev_attr.attr,
1023 &sensor_dev_attr_temp2_min.dev_attr.attr,
1024 &sensor_dev_attr_temp3_min.dev_attr.attr,
1025 &sensor_dev_attr_temp1_max.dev_attr.attr,
1026 &sensor_dev_attr_temp2_max.dev_attr.attr,
1027 &sensor_dev_attr_temp3_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001028 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1029 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1030 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1031 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1032 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001033
1034 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
1035 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
1036 &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
1037 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1038 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1039 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1040 &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
1041 &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
1042 &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001043
1044 &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
1045 &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
1046 &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
1047 &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
1048 &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
1049 &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
1050 &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
1051 &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
1052 &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
1053 &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
1054 &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
1055 &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
1056
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001057 &dev_attr_vrm.attr,
1058 &dev_attr_cpu0_vid.attr,
1059 &dev_attr_alarms.attr,
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001060 NULL
1061};
1062
1063static const struct attribute_group lm85_group = {
1064 .attrs = lm85_attributes,
1065};
1066
Jean Delvare6b9aad22007-07-05 20:37:21 +02001067static struct attribute *lm85_attributes_in4[] = {
Jean Delvareb353a482007-07-05 20:36:12 +02001068 &sensor_dev_attr_in4_input.dev_attr.attr,
1069 &sensor_dev_attr_in4_min.dev_attr.attr,
1070 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001071 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001072 NULL
1073};
1074
Jean Delvare6b9aad22007-07-05 20:37:21 +02001075static const struct attribute_group lm85_group_in4 = {
1076 .attrs = lm85_attributes_in4,
1077};
1078
1079static struct attribute *lm85_attributes_in567[] = {
1080 &sensor_dev_attr_in5_input.dev_attr.attr,
1081 &sensor_dev_attr_in6_input.dev_attr.attr,
1082 &sensor_dev_attr_in7_input.dev_attr.attr,
1083 &sensor_dev_attr_in5_min.dev_attr.attr,
1084 &sensor_dev_attr_in6_min.dev_attr.attr,
1085 &sensor_dev_attr_in7_min.dev_attr.attr,
1086 &sensor_dev_attr_in5_max.dev_attr.attr,
1087 &sensor_dev_attr_in6_max.dev_attr.attr,
1088 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001089 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1090 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1091 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001092 NULL
1093};
1094
1095static const struct attribute_group lm85_group_in567 = {
1096 .attrs = lm85_attributes_in567,
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001097};
1098
Jean Delvare5f44759472008-06-25 09:10:30 -04001099static void lm85_init_client(struct i2c_client *client)
1100{
1101 int value;
1102
1103 /* Start monitoring if needed */
1104 value = lm85_read_value(client, LM85_REG_CONFIG);
1105 if (!(value & 0x01)) {
1106 dev_info(&client->dev, "Starting monitoring\n");
1107 lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
1108 }
1109
1110 /* Warn about unusual configuration bits */
1111 if (value & 0x02)
1112 dev_warn(&client->dev, "Device configuration is locked\n");
1113 if (!(value & 0x04))
1114 dev_warn(&client->dev, "Device is not ready\n");
1115}
1116
Jean Delvare67712d02008-10-17 17:51:14 +02001117/* Return 0 if detection is successful, -ENODEV otherwise */
1118static int lm85_detect(struct i2c_client *client, int kind,
1119 struct i2c_board_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Jean Delvare67712d02008-10-17 17:51:14 +02001121 struct i2c_adapter *adapter = client->adapter;
1122 int address = client->addr;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001123 const char *type_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jean Delvaree89e22b2008-06-25 08:47:35 -04001125 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /* We need to be able to do byte I/O */
Jean Delvare67712d02008-10-17 17:51:14 +02001127 return -ENODEV;
Jean Delvare1f448092008-04-29 14:03:37 +02001128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001130 /* If auto-detecting, determine the chip type */
1131 if (kind < 0) {
1132 int company = lm85_read_value(client, LM85_REG_COMPANY);
1133 int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001135 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1136 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1137 address, company, verstep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001139 /* All supported chips have the version in common */
1140 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
1141 dev_dbg(&adapter->dev, "Autodetection failed: "
1142 "unsupported version\n");
Jean Delvare67712d02008-10-17 17:51:14 +02001143 return -ENODEV;
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001144 }
1145 kind = any_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001147 /* Now, refine the detection */
1148 if (company == LM85_COMPANY_NATIONAL) {
1149 switch (verstep) {
1150 case LM85_VERSTEP_LM85C:
1151 kind = lm85c;
1152 break;
1153 case LM85_VERSTEP_LM85B:
1154 kind = lm85b;
1155 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001157 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1158 switch (verstep) {
1159 case LM85_VERSTEP_ADM1027:
1160 kind = adm1027;
1161 break;
1162 case LM85_VERSTEP_ADT7463:
1163 case LM85_VERSTEP_ADT7463C:
1164 kind = adt7463;
1165 break;
1166 }
1167 } else if (company == LM85_COMPANY_SMSC) {
1168 switch (verstep) {
1169 case LM85_VERSTEP_EMC6D100_A0:
1170 case LM85_VERSTEP_EMC6D100_A1:
1171 /* Note: we can't tell a '100 from a '101 */
1172 kind = emc6d100;
1173 break;
1174 case LM85_VERSTEP_EMC6D102:
1175 kind = emc6d102;
1176 break;
1177 }
1178 } else {
1179 dev_dbg(&adapter->dev, "Autodetection failed: "
1180 "unknown vendor\n");
Jean Delvare67712d02008-10-17 17:51:14 +02001181 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 }
1183 }
1184
Jean Delvaree89e22b2008-06-25 08:47:35 -04001185 switch (kind) {
1186 case lm85b:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 type_name = "lm85b";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001188 break;
1189 case lm85c:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 type_name = "lm85c";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001191 break;
1192 case adm1027:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 type_name = "adm1027";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001194 break;
1195 case adt7463:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 type_name = "adt7463";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001197 break;
1198 case emc6d100:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 type_name = "emc6d100";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001200 break;
1201 case emc6d102:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 type_name = "emc6d102";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001203 break;
1204 default:
1205 type_name = "lm85";
1206 }
Jean Delvare67712d02008-10-17 17:51:14 +02001207 strlcpy(info->type, type_name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Jean Delvare67712d02008-10-17 17:51:14 +02001209 return 0;
1210}
1211
1212static int lm85_probe(struct i2c_client *client,
1213 const struct i2c_device_id *id)
1214{
1215 struct lm85_data *data;
1216 int err;
1217
1218 data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
1219 if (!data)
1220 return -ENOMEM;
1221
1222 i2c_set_clientdata(client, data);
1223 data->type = id->driver_data;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001224 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Jean Delvare67712d02008-10-17 17:51:14 +02001226 /* Fill in the chip specific driver values */
1227 switch (data->type) {
1228 case adm1027:
1229 case adt7463:
1230 case emc6d100:
1231 case emc6d102:
1232 data->freq_map = adm1027_freq_map;
1233 break;
1234 default:
1235 data->freq_map = lm85_freq_map;
1236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 /* Set the VRM version */
Jean Delvare303760b2005-07-31 21:52:01 +02001239 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 /* Initialize the LM85 chip */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001242 lm85_init_client(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /* Register sysfs hooks */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001245 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1246 if (err)
Jean Delvare67712d02008-10-17 17:51:14 +02001247 goto ERROR1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Jean Delvare9c516ef2005-11-26 20:07:54 +01001249 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1250 as a sixth digital VID input rather than an analog input. */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001251 data->vid = lm85_read_value(client, LM85_REG_VID);
Jean Delvare67712d02008-10-17 17:51:14 +02001252 if (!(data->type == adt7463 && (data->vid & 0x80)))
Jean Delvaree89e22b2008-06-25 08:47:35 -04001253 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001254 &lm85_group_in4)))
1255 goto ERROR3;
1256
1257 /* The EMC6D100 has 3 additional voltage inputs */
Jean Delvare67712d02008-10-17 17:51:14 +02001258 if (data->type == emc6d100)
Jean Delvaree89e22b2008-06-25 08:47:35 -04001259 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001260 &lm85_group_in567)))
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001261 goto ERROR3;
1262
Jean Delvaree89e22b2008-06-25 08:47:35 -04001263 data->hwmon_dev = hwmon_device_register(&client->dev);
Tony Jones1beeffe2007-08-20 13:46:20 -07001264 if (IS_ERR(data->hwmon_dev)) {
1265 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001266 goto ERROR3;
Jean Delvare9c516ef2005-11-26 20:07:54 +01001267 }
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return 0;
1270
1271 /* Error out and cleanup code */
Jean Delvare1f448092008-04-29 14:03:37 +02001272 ERROR3:
Jean Delvaree89e22b2008-06-25 08:47:35 -04001273 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1274 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
Jean Delvare67712d02008-10-17 17:51:14 +02001275 if (data->type == emc6d100)
Jean Delvaree89e22b2008-06-25 08:47:35 -04001276 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
Jean Delvare1f448092008-04-29 14:03:37 +02001277 ERROR1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 return err;
1280}
1281
Jean Delvare67712d02008-10-17 17:51:14 +02001282static int lm85_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001284 struct lm85_data *data = i2c_get_clientdata(client);
Tony Jones1beeffe2007-08-20 13:46:20 -07001285 hwmon_device_unregister(data->hwmon_dev);
Mark M. Hoffman0501a382006-09-24 21:14:35 +02001286 sysfs_remove_group(&client->dev.kobj, &lm85_group);
Jean Delvare6b9aad22007-07-05 20:37:21 +02001287 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1288 if (data->type == emc6d100)
1289 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001290 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 return 0;
1292}
1293
1294
Ben Dooksd8d20612005-10-26 21:05:46 +02001295static int lm85_read_value(struct i2c_client *client, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
1297 int res;
1298
1299 /* What size location is it? */
Jean Delvare1f448092008-04-29 14:03:37 +02001300 switch (reg) {
1301 case LM85_REG_FAN(0): /* Read WORD data */
1302 case LM85_REG_FAN(1):
1303 case LM85_REG_FAN(2):
1304 case LM85_REG_FAN(3):
1305 case LM85_REG_FAN_MIN(0):
1306 case LM85_REG_FAN_MIN(1):
1307 case LM85_REG_FAN_MIN(2):
1308 case LM85_REG_FAN_MIN(3):
1309 case LM85_REG_ALARM1: /* Read both bytes at once */
1310 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
1311 res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
1312 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 default: /* Read BYTE data */
1314 res = i2c_smbus_read_byte_data(client, reg);
Jean Delvare1f448092008-04-29 14:03:37 +02001315 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 }
1317
Jean Delvare1f448092008-04-29 14:03:37 +02001318 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Jean Delvaree89e22b2008-06-25 08:47:35 -04001321static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Jean Delvare1f448092008-04-29 14:03:37 +02001323 switch (reg) {
1324 case LM85_REG_FAN(0): /* Write WORD data */
1325 case LM85_REG_FAN(1):
1326 case LM85_REG_FAN(2):
1327 case LM85_REG_FAN(3):
1328 case LM85_REG_FAN_MIN(0):
1329 case LM85_REG_FAN_MIN(1):
1330 case LM85_REG_FAN_MIN(2):
1331 case LM85_REG_FAN_MIN(3):
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 /* NOTE: ALARM is read only, so not included here */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001333 i2c_smbus_write_byte_data(client, reg, value & 0xff);
1334 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
Jean Delvare1f448092008-04-29 14:03:37 +02001335 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 default: /* Write BYTE data */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001337 i2c_smbus_write_byte_data(client, reg, value);
Jean Delvare1f448092008-04-29 14:03:37 +02001338 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342static struct lm85_data *lm85_update_device(struct device *dev)
1343{
1344 struct i2c_client *client = to_i2c_client(dev);
1345 struct lm85_data *data = i2c_get_clientdata(client);
1346 int i;
1347
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001348 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Delvare1f448092008-04-29 14:03:37 +02001350 if (!data->valid ||
1351 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 /* Things that change quickly */
1353 dev_dbg(&client->dev, "Reading sensor values\n");
Jean Delvare1f448092008-04-29 14:03:37 +02001354
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 /* Have to read extended bits first to "freeze" the
1356 * more significant bits that are read later.
Jean Delvare5a4d3ef2007-07-05 20:38:32 +02001357 * There are 2 additional resolution bits per channel and we
1358 * have room for 4, so we shift them to the left.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 */
Jean Delvare1f448092008-04-29 14:03:37 +02001360 if (data->type == adm1027 || data->type == adt7463) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 int ext1 = lm85_read_value(client,
1362 ADM1027_REG_EXTEND_ADC1);
1363 int ext2 = lm85_read_value(client,
1364 ADM1027_REG_EXTEND_ADC2);
1365 int val = (ext1 << 8) + ext2;
1366
Jean Delvare1f448092008-04-29 14:03:37 +02001367 for (i = 0; i <= 4; i++)
1368 data->in_ext[i] =
1369 ((val >> (i * 2)) & 0x03) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Jean Delvare1f448092008-04-29 14:03:37 +02001371 for (i = 0; i <= 2; i++)
1372 data->temp_ext[i] =
1373 (val >> ((i + 4) * 2)) & 0x0c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
1375
Jean Delvare9c516ef2005-11-26 20:07:54 +01001376 data->vid = lm85_read_value(client, LM85_REG_VID);
1377
1378 for (i = 0; i <= 3; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 data->in[i] =
1380 lm85_read_value(client, LM85_REG_IN(i));
Jean Delvaree89e22b2008-06-25 08:47:35 -04001381 data->fan[i] =
1382 lm85_read_value(client, LM85_REG_FAN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
1384
Jean Delvare9c516ef2005-11-26 20:07:54 +01001385 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1386 data->in[4] = lm85_read_value(client,
1387 LM85_REG_IN(4));
1388 }
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 for (i = 0; i <= 2; ++i) {
1391 data->temp[i] =
1392 lm85_read_value(client, LM85_REG_TEMP(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 data->pwm[i] =
1394 lm85_read_value(client, LM85_REG_PWM(i));
1395 }
1396
1397 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1398
Jean Delvaredd1ac532008-05-01 08:47:33 +02001399 if (data->type == emc6d100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 /* Three more voltage sensors */
1401 for (i = 5; i <= 7; ++i) {
Jean Delvare1f448092008-04-29 14:03:37 +02001402 data->in[i] = lm85_read_value(client,
1403 EMC6D100_REG_IN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405 /* More alarm bits */
Jean Delvare1f448092008-04-29 14:03:37 +02001406 data->alarms |= lm85_read_value(client,
1407 EMC6D100_REG_ALARM3) << 16;
1408 } else if (data->type == emc6d102) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 /* Have to read LSB bits after the MSB ones because
1410 the reading of the MSB bits has frozen the
1411 LSBs (backward from the ADM1027).
1412 */
1413 int ext1 = lm85_read_value(client,
1414 EMC6D102_REG_EXTEND_ADC1);
1415 int ext2 = lm85_read_value(client,
1416 EMC6D102_REG_EXTEND_ADC2);
1417 int ext3 = lm85_read_value(client,
1418 EMC6D102_REG_EXTEND_ADC3);
1419 int ext4 = lm85_read_value(client,
1420 EMC6D102_REG_EXTEND_ADC4);
1421 data->in_ext[0] = ext3 & 0x0f;
1422 data->in_ext[1] = ext4 & 0x0f;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001423 data->in_ext[2] = ext4 >> 4;
1424 data->in_ext[3] = ext3 >> 4;
1425 data->in_ext[4] = ext2 >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 data->temp_ext[0] = ext1 & 0x0f;
1428 data->temp_ext[1] = ext2 & 0x0f;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001429 data->temp_ext[2] = ext1 >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431
Jean Delvare1f448092008-04-29 14:03:37 +02001432 data->last_reading = jiffies;
1433 } /* last_reading */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Jean Delvare1f448092008-04-29 14:03:37 +02001435 if (!data->valid ||
1436 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 /* Things that don't change often */
1438 dev_dbg(&client->dev, "Reading config values\n");
1439
Jean Delvare9c516ef2005-11-26 20:07:54 +01001440 for (i = 0; i <= 3; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 data->in_min[i] =
1442 lm85_read_value(client, LM85_REG_IN_MIN(i));
1443 data->in_max[i] =
1444 lm85_read_value(client, LM85_REG_IN_MAX(i));
Jean Delvaree89e22b2008-06-25 08:47:35 -04001445 data->fan_min[i] =
1446 lm85_read_value(client, LM85_REG_FAN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 }
1448
Jean Delvare9c516ef2005-11-26 20:07:54 +01001449 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1450 data->in_min[4] = lm85_read_value(client,
1451 LM85_REG_IN_MIN(4));
1452 data->in_max[4] = lm85_read_value(client,
1453 LM85_REG_IN_MAX(4));
1454 }
1455
Jean Delvare1f448092008-04-29 14:03:37 +02001456 if (data->type == emc6d100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 for (i = 5; i <= 7; ++i) {
Jean Delvare1f448092008-04-29 14:03:37 +02001458 data->in_min[i] = lm85_read_value(client,
1459 EMC6D100_REG_IN_MIN(i));
1460 data->in_max[i] = lm85_read_value(client,
1461 EMC6D100_REG_IN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
1463 }
1464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 for (i = 0; i <= 2; ++i) {
Jean Delvaree89e22b2008-06-25 08:47:35 -04001466 int val;
1467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 data->temp_min[i] =
1469 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1470 data->temp_max[i] =
1471 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 data->autofan[i].config =
1474 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1475 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
Jean Delvare34e7dc62008-10-17 17:51:13 +02001476 data->pwm_freq[i] = val & 0x07;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001477 data->zone[i].range = val >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 data->autofan[i].min_pwm =
1479 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1480 data->zone[i].limit =
1481 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
1482 data->zone[i].critical =
1483 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
1484 }
1485
1486 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
Jean Delvare1f448092008-04-29 14:03:37 +02001487 data->autofan[0].min_off = (i & 0x20) != 0;
1488 data->autofan[1].min_off = (i & 0x40) != 0;
1489 data->autofan[2].min_off = (i & 0x80) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
Jean Delvaree89e22b2008-06-25 08:47:35 -04001492 data->zone[0].hyst = i >> 4;
Jean Delvare1f448092008-04-29 14:03:37 +02001493 data->zone[1].hyst = i & 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
Jean Delvaree89e22b2008-06-25 08:47:35 -04001496 data->zone[2].hyst = i >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 data->last_config = jiffies;
Jean Delvare1f448092008-04-29 14:03:37 +02001499 } /* last_config */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 data->valid = 1;
1502
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001503 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 return data;
1506}
1507
1508
1509static int __init sm_lm85_init(void)
1510{
1511 return i2c_add_driver(&lm85_driver);
1512}
1513
Jean Delvare1f448092008-04-29 14:03:37 +02001514static void __exit sm_lm85_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 i2c_del_driver(&lm85_driver);
1517}
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519MODULE_LICENSE("GPL");
Jean Delvare1f448092008-04-29 14:03:37 +02001520MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1521 "Margit Schubert-While <margitsw@t-online.de>, "
Jean Delvaree89e22b2008-06-25 08:47:35 -04001522 "Justin Thiessen <jthiessen@penguincomputing.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1524
1525module_init(sm_lm85_init);
1526module_exit(sm_lm85_exit);