blob: c323c2b8980809600e80130a615f8811e5737a49 [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>
8
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/jiffies.h>
30#include <linux/i2c.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040031#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020032#include <linux/hwmon-vid.h>
Jean Delvareb353a482007-07-05 20:36:12 +020033#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040034#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010035#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/* Addresses to scan */
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050038static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/* Insmod parameters */
Jean Delvaref4b50262005-07-31 21:49:03 +020041I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* The LM85 registers */
44
45#define LM85_REG_IN(nr) (0x20 + (nr))
46#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
47#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
48
49#define LM85_REG_TEMP(nr) (0x25 + (nr))
50#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
51#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
52
53/* Fan speeds are LSB, MSB (2 bytes) */
Jean Delvare1f448092008-04-29 14:03:37 +020054#define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
55#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define LM85_REG_PWM(nr) (0x30 + (nr))
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define LM85_REG_COMPANY 0x3e
60#define LM85_REG_VERSTEP 0x3f
61/* These are the recognized values for the above regs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define LM85_COMPANY_NATIONAL 0x01
63#define LM85_COMPANY_ANALOG_DEV 0x41
Jean Delvare1f448092008-04-29 14:03:37 +020064#define LM85_COMPANY_SMSC 0x5c
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define LM85_VERSTEP_VMASK 0xf0
66#define LM85_VERSTEP_GENERIC 0x60
67#define LM85_VERSTEP_LM85C 0x60
68#define LM85_VERSTEP_LM85B 0x62
69#define LM85_VERSTEP_ADM1027 0x60
70#define LM85_VERSTEP_ADT7463 0x62
71#define LM85_VERSTEP_ADT7463C 0x6A
72#define LM85_VERSTEP_EMC6D100_A0 0x60
73#define LM85_VERSTEP_EMC6D100_A1 0x61
74#define LM85_VERSTEP_EMC6D102 0x65
75
76#define LM85_REG_CONFIG 0x40
77
78#define LM85_REG_ALARM1 0x41
79#define LM85_REG_ALARM2 0x42
80
81#define LM85_REG_VID 0x43
82
83/* Automated FAN control */
84#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
85#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
86#define LM85_REG_AFAN_SPIKE1 0x62
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
88#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
89#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
90#define LM85_REG_AFAN_HYST1 0x6d
91#define LM85_REG_AFAN_HYST2 0x6e
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define ADM1027_REG_EXTEND_ADC1 0x76
94#define ADM1027_REG_EXTEND_ADC2 0x77
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96#define EMC6D100_REG_ALARM3 0x7d
97/* IN5, IN6 and IN7 */
Jean Delvare1f448092008-04-29 14:03:37 +020098#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
99#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
100#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define EMC6D102_REG_EXTEND_ADC1 0x85
102#define EMC6D102_REG_EXTEND_ADC2 0x86
103#define EMC6D102_REG_EXTEND_ADC3 0x87
104#define EMC6D102_REG_EXTEND_ADC4 0x88
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Jean Delvare1f448092008-04-29 14:03:37 +0200107/* Conversions. Rounding and limit checking is only done on the TO_REG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 variants. Note that you should be a bit careful with which arguments
109 these macros are called: arguments may be evaluated more than once.
110 */
111
112/* IN are scaled acording to built-in resistors */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400113static const int lm85_scaling[] = { /* .001 Volts */
Jean Delvare1f448092008-04-29 14:03:37 +0200114 2500, 2250, 3300, 5000, 12000,
115 3300, 1500, 1800 /*EMC6D100*/
116};
117#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Jean Delvare1f448092008-04-29 14:03:37 +0200119#define INS_TO_REG(n, val) \
120 SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Jean Delvare1f448092008-04-29 14:03:37 +0200122#define INSEXT_FROM_REG(n, val, ext) \
Jean Delvare5a4d3ef2007-07-05 20:38:32 +0200123 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Jean Delvare1f448092008-04-29 14:03:37 +0200125#define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127/* FAN speed is measured using 90kHz clock */
Jean Delvare63f281a2007-07-05 20:39:40 +0200128static inline u16 FAN_TO_REG(unsigned long val)
129{
130 if (!val)
131 return 0xffff;
132 return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
133}
Jean Delvare1f448092008-04-29 14:03:37 +0200134#define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
135 5400000 / (val))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137/* Temperature is reported in .001 degC increments */
138#define TEMP_TO_REG(val) \
Jean Delvare1f448092008-04-29 14:03:37 +0200139 SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
140#define TEMPEXT_FROM_REG(val, ext) \
Jean Delvare5a4d3ef2007-07-05 20:38:32 +0200141 SCALE(((val) << 4) + (ext), 16, 1000)
142#define TEMP_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Jean Delvare1f448092008-04-29 14:03:37 +0200144#define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define PWM_FROM_REG(val) (val)
146
147
148/* ZONEs have the following parameters:
149 * Limit (low) temp, 1. degC
150 * Hysteresis (below limit), 1. degC (0-15)
151 * Range of speed control, .1 degC (2-80)
152 * Critical (high) temp, 1. degC
153 *
154 * FAN PWMs have the following parameters:
155 * Reference Zone, 1, 2, 3, etc.
156 * Spinup time, .05 sec
157 * PWM value at limit/low temp, 1 count
158 * PWM Frequency, 1. Hz
159 * PWM is Min or OFF below limit, flag
160 * Invert PWM output, flag
161 *
162 * Some chips filter the temp, others the fan.
163 * Filter constant (or disabled) .1 seconds
164 */
165
166/* These are the zone temperature range encodings in .001 degree C */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400167static const int lm85_range_map[] = {
Jean Delvare1f448092008-04-29 14:03:37 +0200168 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
169 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
170};
171
172static int RANGE_TO_REG(int range)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 int i;
175
Jean Delvared38b1492008-04-03 10:40:39 +0200176 if (range >= lm85_range_map[15])
Jean Delvare1f448092008-04-29 14:03:37 +0200177 return 15;
Jean Delvared38b1492008-04-03 10:40:39 +0200178
179 /* Find the closest match */
180 for (i = 14; i >= 0; --i) {
181 if (range >= lm85_range_map[i]) {
182 if ((lm85_range_map[i + 1] - range) <
183 (range - lm85_range_map[i]))
184 return i + 1;
185 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187 }
Jean Delvared38b1492008-04-03 10:40:39 +0200188
189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
Jean Delvare1f448092008-04-29 14:03:37 +0200191#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193/* These are the PWM frequency encodings */
Jean Delvare34e7dc62008-10-17 17:51:13 +0200194static const int lm85_freq_map[8] = { /* 1 Hz */
195 10, 15, 23, 30, 38, 47, 62, 94
Jean Delvare1f448092008-04-29 14:03:37 +0200196};
197
198static int FREQ_TO_REG(int freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 int i;
201
Jean Delvare86010c92008-10-17 17:51:13 +0200202 /* Find the closest match */
Jean Delvare1f448092008-04-29 14:03:37 +0200203 for (i = 0; i < 7; ++i)
Jean Delvare86010c92008-10-17 17:51:13 +0200204 if (freq <= (lm85_freq_map[i] + lm85_freq_map[i + 1]) / 2)
Jean Delvare1f448092008-04-29 14:03:37 +0200205 break;
Jean Delvaree89e22b2008-06-25 08:47:35 -0400206 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
Jean Delvare1f448092008-04-29 14:03:37 +0200208#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/* Since we can't use strings, I'm abusing these numbers
211 * to stand in for the following meanings:
212 * 1 -- PWM responds to Zone 1
213 * 2 -- PWM responds to Zone 2
214 * 3 -- PWM responds to Zone 3
215 * 23 -- PWM responds to the higher temp of Zone 2 or 3
216 * 123 -- PWM responds to highest of Zone 1, 2, or 3
217 * 0 -- PWM is always at 0% (ie, off)
218 * -1 -- PWM is always at 100%
219 * -2 -- PWM responds to manual control
220 */
221
Jean Delvaree89e22b2008-06-25 08:47:35 -0400222static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
223#define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Jean Delvare1f448092008-04-29 14:03:37 +0200225static int ZONE_TO_REG(int zone)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 int i;
228
Jean Delvare1f448092008-04-29 14:03:37 +0200229 for (i = 0; i <= 7; ++i)
230 if (zone == lm85_zone_map[i])
231 break;
232 if (i > 7) /* Not found. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 i = 3; /* Always 100% */
Jean Delvaree89e22b2008-06-25 08:47:35 -0400234 return i << 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
Jean Delvare1f448092008-04-29 14:03:37 +0200237#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
238#define HYST_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/* Chip sampling rates
241 *
242 * Some sensors are not updated more frequently than once per second
243 * so it doesn't make sense to read them more often than that.
244 * We cache the results and return the saved data if the driver
245 * is called again before a second has elapsed.
246 *
247 * Also, there is significant configuration data for this chip
248 * given the automatic PWM fan control that is possible. There
249 * are about 47 bytes of config data to only 22 bytes of actual
250 * readings. So, we keep the config data up to date in the cache
251 * when it is written and only sample it once every 1 *minute*
252 */
253#define LM85_DATA_INTERVAL (HZ + HZ / 2)
254#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256/* LM85 can automatically adjust fan speeds based on temperature
257 * This structure encapsulates an entire Zone config. There are
258 * three zones (one for each temperature input) on the lm85
259 */
260struct lm85_zone {
261 s8 limit; /* Low temp limit */
262 u8 hyst; /* Low limit hysteresis. (0-15) */
263 u8 range; /* Temp range, encoded */
264 s8 critical; /* "All fans ON" temp limit */
Jean Delvare1f448092008-04-29 14:03:37 +0200265 u8 off_desired; /* Actual "off" temperature specified. Preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 * to prevent "drift" as other autofan control
267 * values change.
268 */
Jean Delvare1f448092008-04-29 14:03:37 +0200269 u8 max_desired; /* Actual "max" temperature specified. Preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 * to prevent "drift" as other autofan control
271 * values change.
272 */
273};
274
275struct lm85_autofan {
276 u8 config; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 u8 min_pwm; /* Minimum PWM value, encoded */
278 u8 min_off; /* Min PWM or OFF below "limit", flag */
279};
280
Jean Delvareed6bafb2007-02-14 21:15:03 +0100281/* For each registered chip, we need to keep some data in memory.
282 The structure is dynamically allocated. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283struct lm85_data {
284 struct i2c_client client;
Tony Jones1beeffe2007-08-20 13:46:20 -0700285 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 enum chips type;
287
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100288 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 int valid; /* !=0 if following fields are valid */
290 unsigned long last_reading; /* In jiffies */
291 unsigned long last_config; /* In jiffies */
292
293 u8 in[8]; /* Register value */
294 u8 in_max[8]; /* Register value */
295 u8 in_min[8]; /* Register value */
296 s8 temp[3]; /* Register value */
297 s8 temp_min[3]; /* Register value */
298 s8 temp_max[3]; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 u16 fan[4]; /* Register value */
300 u16 fan_min[4]; /* Register value */
301 u8 pwm[3]; /* Register value */
Jean Delvare34e7dc62008-10-17 17:51:13 +0200302 u8 pwm_freq[3]; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 u8 temp_ext[3]; /* Decoded values */
304 u8 in_ext[8]; /* Decoded values */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 u8 vid; /* Register value */
306 u8 vrm; /* VRM version */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 u32 alarms; /* Register encoding, combined */
308 struct lm85_autofan autofan[3];
309 struct lm85_zone zone[3];
310};
311
312static int lm85_attach_adapter(struct i2c_adapter *adapter);
313static int lm85_detect(struct i2c_adapter *adapter, int address,
314 int kind);
315static int lm85_detach_client(struct i2c_client *client);
316
Darren Jenkinsf6c27fc2006-02-27 23:14:58 +0100317static int lm85_read_value(struct i2c_client *client, u8 reg);
Jean Delvaree89e22b2008-06-25 08:47:35 -0400318static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319static struct lm85_data *lm85_update_device(struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321
322static struct i2c_driver lm85_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100323 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100324 .name = "lm85",
325 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .attach_adapter = lm85_attach_adapter,
327 .detach_client = lm85_detach_client,
328};
329
330
331/* 4 Fans */
Jean Delvareb353a482007-07-05 20:36:12 +0200332static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
333 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Jean Delvareb353a482007-07-05 20:36:12 +0200335 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200337 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
Jean Delvareb353a482007-07-05 20:36:12 +0200339
340static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
341 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Jean Delvareb353a482007-07-05 20:36:12 +0200343 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200345 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
Jean Delvareb353a482007-07-05 20:36:12 +0200347
348static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
349 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Jean Delvareb353a482007-07-05 20:36:12 +0200351 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 struct i2c_client *client = to_i2c_client(dev);
353 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare63f281a2007-07-05 20:39:40 +0200354 unsigned long val = simple_strtoul(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100356 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 data->fan_min[nr] = FAN_TO_REG(val);
358 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100359 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return count;
361}
362
363#define show_fan_offset(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200364static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
365 show_fan, NULL, offset - 1); \
366static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
367 show_fan_min, set_fan_min, offset - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369show_fan_offset(1);
370show_fan_offset(2);
371show_fan_offset(3);
372show_fan_offset(4);
373
374/* vid, vrm, alarms */
375
Jean Delvare1f448092008-04-29 14:03:37 +0200376static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
377 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare9c516ef2005-11-26 20:07:54 +0100380 int vid;
381
382 if (data->type == adt7463 && (data->vid & 0x80)) {
383 /* 6-pin VID (VRM 10) */
384 vid = vid_from_reg(data->vid & 0x3f, data->vrm);
385 } else {
386 /* 5-pin VID (VRM 9) */
387 vid = vid_from_reg(data->vid & 0x1f, data->vrm);
388 }
389
390 return sprintf(buf, "%d\n", vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
393static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
394
Jean Delvare1f448092008-04-29 14:03:37 +0200395static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
396 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Jean Delvare90d66192007-10-08 18:24:35 +0200398 struct lm85_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return sprintf(buf, "%ld\n", (long) data->vrm);
400}
401
Jean Delvare1f448092008-04-29 14:03:37 +0200402static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
403 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Jean Delvare8f74efe2007-12-01 11:25:33 +0100405 struct lm85_data *data = dev_get_drvdata(dev);
406 data->vrm = simple_strtoul(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return count;
408}
409
410static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
411
Jean Delvare1f448092008-04-29 14:03:37 +0200412static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
413 *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
415 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200416 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
419static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
420
Jean Delvarebf76e9d2007-07-05 20:37:58 +0200421static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
422 char *buf)
423{
424 int nr = to_sensor_dev_attr(attr)->index;
425 struct lm85_data *data = lm85_update_device(dev);
426 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
427}
428
429static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
430static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
431static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
432static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
433static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
434static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
435static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
436static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
437static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
438static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
439static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
440static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
441static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
442static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
443static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
444static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
445static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447/* pwm */
448
Jean Delvareb353a482007-07-05 20:36:12 +0200449static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
450 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Jean Delvareb353a482007-07-05 20:36:12 +0200452 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200454 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
Jean Delvareb353a482007-07-05 20:36:12 +0200456
457static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
458 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Jean Delvareb353a482007-07-05 20:36:12 +0200460 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct i2c_client *client = to_i2c_client(dev);
462 struct lm85_data *data = i2c_get_clientdata(client);
463 long val = simple_strtol(buf, NULL, 10);
464
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100465 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 data->pwm[nr] = PWM_TO_REG(val);
467 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100468 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return count;
470}
Jean Delvareb353a482007-07-05 20:36:12 +0200471
472static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
473 *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Jean Delvareb353a482007-07-05 20:36:12 +0200475 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare4b4df952007-12-03 23:23:21 +0100477 int pwm_zone, enable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
Jean Delvare4b4df952007-12-03 23:23:21 +0100480 switch (pwm_zone) {
481 case -1: /* PWM is always at 100% */
482 enable = 0;
483 break;
484 case 0: /* PWM is always at 0% */
485 case -2: /* PWM responds to manual control */
486 enable = 1;
487 break;
488 default: /* PWM in automatic mode */
489 enable = 2;
490 }
491 return sprintf(buf, "%d\n", enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
Jean Delvare455f7912007-12-03 23:28:42 +0100494static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
495 *attr, const char *buf, size_t count)
496{
497 int nr = to_sensor_dev_attr(attr)->index;
498 struct i2c_client *client = to_i2c_client(dev);
499 struct lm85_data *data = i2c_get_clientdata(client);
500 long val = simple_strtol(buf, NULL, 10);
501 u8 config;
502
503 switch (val) {
504 case 0:
505 config = 3;
506 break;
507 case 1:
508 config = 7;
509 break;
510 case 2:
511 /* Here we have to choose arbitrarily one of the 5 possible
512 configurations; I go for the safest */
513 config = 6;
514 break;
515 default:
516 return -EINVAL;
517 }
518
519 mutex_lock(&data->update_lock);
520 data->autofan[nr].config = lm85_read_value(client,
521 LM85_REG_AFAN_CONFIG(nr));
522 data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
523 | (config << 5);
524 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
525 data->autofan[nr].config);
526 mutex_unlock(&data->update_lock);
527 return count;
528}
529
Jean Delvare34e7dc62008-10-17 17:51:13 +0200530static ssize_t show_pwm_freq(struct device *dev,
531 struct device_attribute *attr, char *buf)
532{
533 int nr = to_sensor_dev_attr(attr)->index;
534 struct lm85_data *data = lm85_update_device(dev);
535 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->pwm_freq[nr]));
536}
537
538static ssize_t set_pwm_freq(struct device *dev,
539 struct device_attribute *attr, const char *buf, size_t count)
540{
541 int nr = to_sensor_dev_attr(attr)->index;
542 struct i2c_client *client = to_i2c_client(dev);
543 struct lm85_data *data = i2c_get_clientdata(client);
544 long val = simple_strtol(buf, NULL, 10);
545
546 mutex_lock(&data->update_lock);
547 data->pwm_freq[nr] = FREQ_TO_REG(val);
548 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
549 (data->zone[nr].range << 4)
550 | data->pwm_freq[nr]);
551 mutex_unlock(&data->update_lock);
552 return count;
553}
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define show_pwm_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200556static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
557 show_pwm, set_pwm, offset - 1); \
Jean Delvare455f7912007-12-03 23:28:42 +0100558static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
Jean Delvare34e7dc62008-10-17 17:51:13 +0200559 show_pwm_enable, set_pwm_enable, offset - 1); \
560static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
561 show_pwm_freq, set_pwm_freq, offset - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563show_pwm_reg(1);
564show_pwm_reg(2);
565show_pwm_reg(3);
566
567/* Voltages */
568
Jean Delvareb353a482007-07-05 20:36:12 +0200569static ssize_t show_in(struct device *dev, struct device_attribute *attr,
570 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Jean Delvareb353a482007-07-05 20:36:12 +0200572 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200574 return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
575 data->in_ext[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
Jean Delvareb353a482007-07-05 20:36:12 +0200577
Jean Delvare1f448092008-04-29 14:03:37 +0200578static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
Jean Delvareb353a482007-07-05 20:36:12 +0200579 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Jean Delvareb353a482007-07-05 20:36:12 +0200581 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200583 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
Jean Delvareb353a482007-07-05 20:36:12 +0200585
586static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
587 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Jean Delvareb353a482007-07-05 20:36:12 +0200589 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 struct i2c_client *client = to_i2c_client(dev);
591 struct lm85_data *data = i2c_get_clientdata(client);
592 long val = simple_strtol(buf, NULL, 10);
593
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100594 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 data->in_min[nr] = INS_TO_REG(nr, val);
596 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100597 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return count;
599}
Jean Delvareb353a482007-07-05 20:36:12 +0200600
601static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
602 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Jean Delvareb353a482007-07-05 20:36:12 +0200604 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200606 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
Jean Delvareb353a482007-07-05 20:36:12 +0200608
609static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
610 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Jean Delvareb353a482007-07-05 20:36:12 +0200612 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 struct i2c_client *client = to_i2c_client(dev);
614 struct lm85_data *data = i2c_get_clientdata(client);
615 long val = simple_strtol(buf, NULL, 10);
616
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100617 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 data->in_max[nr] = INS_TO_REG(nr, val);
619 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100620 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return count;
622}
Jean Delvareb353a482007-07-05 20:36:12 +0200623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define show_in_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200625static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
626 show_in, NULL, offset); \
627static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
628 show_in_min, set_in_min, offset); \
629static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
630 show_in_max, set_in_max, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632show_in_reg(0);
633show_in_reg(1);
634show_in_reg(2);
635show_in_reg(3);
636show_in_reg(4);
Jean Delvare6b9aad22007-07-05 20:37:21 +0200637show_in_reg(5);
638show_in_reg(6);
639show_in_reg(7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641/* Temps */
642
Jean Delvareb353a482007-07-05 20:36:12 +0200643static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
644 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Jean Delvareb353a482007-07-05 20:36:12 +0200646 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200648 return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
649 data->temp_ext[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
Jean Delvareb353a482007-07-05 20:36:12 +0200651
652static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
653 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Jean Delvareb353a482007-07-05 20:36:12 +0200655 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200657 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Jean Delvareb353a482007-07-05 20:36:12 +0200659
660static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
661 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Jean Delvareb353a482007-07-05 20:36:12 +0200663 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 struct i2c_client *client = to_i2c_client(dev);
665 struct lm85_data *data = i2c_get_clientdata(client);
666 long val = simple_strtol(buf, NULL, 10);
667
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100668 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 data->temp_min[nr] = TEMP_TO_REG(val);
670 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100671 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return count;
673}
Jean Delvareb353a482007-07-05 20:36:12 +0200674
675static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
676 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
Jean Delvareb353a482007-07-05 20:36:12 +0200678 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200680 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
Jean Delvareb353a482007-07-05 20:36:12 +0200682
683static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
684 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
Jean Delvareb353a482007-07-05 20:36:12 +0200686 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 struct i2c_client *client = to_i2c_client(dev);
688 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare1f448092008-04-29 14:03:37 +0200689 long val = simple_strtol(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100691 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 data->temp_max[nr] = TEMP_TO_REG(val);
693 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100694 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 return count;
696}
Jean Delvareb353a482007-07-05 20:36:12 +0200697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#define show_temp_reg(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200699static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
700 show_temp, NULL, offset - 1); \
701static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
702 show_temp_min, set_temp_min, offset - 1); \
703static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
704 show_temp_max, set_temp_max, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706show_temp_reg(1);
707show_temp_reg(2);
708show_temp_reg(3);
709
710
711/* Automatic PWM control */
712
Jean Delvareb353a482007-07-05 20:36:12 +0200713static ssize_t show_pwm_auto_channels(struct device *dev,
714 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Jean Delvareb353a482007-07-05 20:36:12 +0200716 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200718 return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719}
Jean Delvareb353a482007-07-05 20:36:12 +0200720
721static ssize_t set_pwm_auto_channels(struct device *dev,
722 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Jean Delvareb353a482007-07-05 20:36:12 +0200724 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 struct i2c_client *client = to_i2c_client(dev);
726 struct lm85_data *data = i2c_get_clientdata(client);
Jean Delvare1f448092008-04-29 14:03:37 +0200727 long val = simple_strtol(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100729 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
Jean Delvare1f448092008-04-29 14:03:37 +0200731 | ZONE_TO_REG(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
733 data->autofan[nr].config);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100734 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return count;
736}
Jean Delvareb353a482007-07-05 20:36:12 +0200737
738static ssize_t show_pwm_auto_pwm_min(struct device *dev,
739 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Jean Delvareb353a482007-07-05 20:36:12 +0200741 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200743 return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
Jean Delvareb353a482007-07-05 20:36:12 +0200745
746static ssize_t set_pwm_auto_pwm_min(struct device *dev,
747 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
Jean Delvareb353a482007-07-05 20:36:12 +0200749 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 struct i2c_client *client = to_i2c_client(dev);
751 struct lm85_data *data = i2c_get_clientdata(client);
752 long val = simple_strtol(buf, NULL, 10);
753
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100754 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 data->autofan[nr].min_pwm = PWM_TO_REG(val);
756 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
757 data->autofan[nr].min_pwm);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100758 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 return count;
760}
Jean Delvareb353a482007-07-05 20:36:12 +0200761
762static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
763 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
Jean Delvareb353a482007-07-05 20:36:12 +0200765 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200767 return sprintf(buf, "%d\n", data->autofan[nr].min_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
Jean Delvareb353a482007-07-05 20:36:12 +0200769
770static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
771 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Jean Delvareb353a482007-07-05 20:36:12 +0200773 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 struct i2c_client *client = to_i2c_client(dev);
775 struct lm85_data *data = i2c_get_clientdata(client);
776 long val = simple_strtol(buf, NULL, 10);
Jean Delvare7133e562008-04-12 19:56:35 +0200777 u8 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100779 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 data->autofan[nr].min_off = val;
Jean Delvare7133e562008-04-12 19:56:35 +0200781 tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
782 tmp &= ~(0x20 << nr);
783 if (data->autofan[nr].min_off)
784 tmp |= 0x20 << nr;
785 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100786 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return count;
788}
Jean Delvareb353a482007-07-05 20:36:12 +0200789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790#define pwm_auto(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200791static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
792 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
793 set_pwm_auto_channels, offset - 1); \
794static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
795 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
796 set_pwm_auto_pwm_min, offset - 1); \
797static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
798 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
Jean Delvare34e7dc62008-10-17 17:51:13 +0200799 set_pwm_auto_pwm_minctl, offset - 1)
Jean Delvareb353a482007-07-05 20:36:12 +0200800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801pwm_auto(1);
802pwm_auto(2);
803pwm_auto(3);
804
805/* Temperature settings for automatic PWM control */
806
Jean Delvareb353a482007-07-05 20:36:12 +0200807static ssize_t show_temp_auto_temp_off(struct device *dev,
808 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Jean Delvareb353a482007-07-05 20:36:12 +0200810 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200812 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 HYST_FROM_REG(data->zone[nr].hyst));
814}
Jean Delvareb353a482007-07-05 20:36:12 +0200815
816static ssize_t set_temp_auto_temp_off(struct device *dev,
817 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Jean Delvareb353a482007-07-05 20:36:12 +0200819 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 struct i2c_client *client = to_i2c_client(dev);
821 struct lm85_data *data = i2c_get_clientdata(client);
822 int min;
823 long val = simple_strtol(buf, NULL, 10);
824
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100825 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 min = TEMP_FROM_REG(data->zone[nr].limit);
827 data->zone[nr].off_desired = TEMP_TO_REG(val);
828 data->zone[nr].hyst = HYST_TO_REG(min - val);
Jean Delvare1f448092008-04-29 14:03:37 +0200829 if (nr == 0 || nr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 lm85_write_value(client, LM85_REG_AFAN_HYST1,
831 (data->zone[0].hyst << 4)
Jean Delvare1f448092008-04-29 14:03:37 +0200832 | data->zone[1].hyst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 } else {
834 lm85_write_value(client, LM85_REG_AFAN_HYST2,
Jean Delvare1f448092008-04-29 14:03:37 +0200835 (data->zone[2].hyst << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100837 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 return count;
839}
Jean Delvareb353a482007-07-05 20:36:12 +0200840
841static ssize_t show_temp_auto_temp_min(struct device *dev,
842 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Jean Delvareb353a482007-07-05 20:36:12 +0200844 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200846 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
Jean Delvareb353a482007-07-05 20:36:12 +0200848
849static ssize_t set_temp_auto_temp_min(struct device *dev,
850 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Jean Delvareb353a482007-07-05 20:36:12 +0200852 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 struct i2c_client *client = to_i2c_client(dev);
854 struct lm85_data *data = i2c_get_clientdata(client);
855 long val = simple_strtol(buf, NULL, 10);
856
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100857 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 data->zone[nr].limit = TEMP_TO_REG(val);
859 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
860 data->zone[nr].limit);
861
862/* Update temp_auto_max and temp_auto_range */
863 data->zone[nr].range = RANGE_TO_REG(
864 TEMP_FROM_REG(data->zone[nr].max_desired) -
865 TEMP_FROM_REG(data->zone[nr].limit));
866 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
867 ((data->zone[nr].range & 0x0f) << 4)
Jean Delvare34e7dc62008-10-17 17:51:13 +0200868 | (data->pwm_freq[nr] & 0x07));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870/* Update temp_auto_hyst and temp_auto_off */
871 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
872 data->zone[nr].limit) - TEMP_FROM_REG(
873 data->zone[nr].off_desired));
Jean Delvare1f448092008-04-29 14:03:37 +0200874 if (nr == 0 || nr == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 lm85_write_value(client, LM85_REG_AFAN_HYST1,
876 (data->zone[0].hyst << 4)
Jean Delvare1f448092008-04-29 14:03:37 +0200877 | data->zone[1].hyst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 } else {
879 lm85_write_value(client, LM85_REG_AFAN_HYST2,
Jean Delvare1f448092008-04-29 14:03:37 +0200880 (data->zone[2].hyst << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100882 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 return count;
884}
Jean Delvareb353a482007-07-05 20:36:12 +0200885
886static ssize_t show_temp_auto_temp_max(struct device *dev,
887 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Jean Delvareb353a482007-07-05 20:36:12 +0200889 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200891 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 RANGE_FROM_REG(data->zone[nr].range));
893}
Jean Delvareb353a482007-07-05 20:36:12 +0200894
895static ssize_t set_temp_auto_temp_max(struct device *dev,
896 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Jean Delvareb353a482007-07-05 20:36:12 +0200898 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 struct i2c_client *client = to_i2c_client(dev);
900 struct lm85_data *data = i2c_get_clientdata(client);
901 int min;
902 long val = simple_strtol(buf, NULL, 10);
903
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100904 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 min = TEMP_FROM_REG(data->zone[nr].limit);
906 data->zone[nr].max_desired = TEMP_TO_REG(val);
907 data->zone[nr].range = RANGE_TO_REG(
908 val - min);
909 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
910 ((data->zone[nr].range & 0x0f) << 4)
Jean Delvare34e7dc62008-10-17 17:51:13 +0200911 | (data->pwm_freq[nr] & 0x07));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100912 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 return count;
914}
Jean Delvareb353a482007-07-05 20:36:12 +0200915
916static ssize_t show_temp_auto_temp_crit(struct device *dev,
917 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
Jean Delvareb353a482007-07-05 20:36:12 +0200919 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 struct lm85_data *data = lm85_update_device(dev);
Jean Delvare1f448092008-04-29 14:03:37 +0200921 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
Jean Delvareb353a482007-07-05 20:36:12 +0200923
924static ssize_t set_temp_auto_temp_crit(struct device *dev,
Jean Delvare1f448092008-04-29 14:03:37 +0200925 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Jean Delvareb353a482007-07-05 20:36:12 +0200927 int nr = to_sensor_dev_attr(attr)->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 struct i2c_client *client = to_i2c_client(dev);
929 struct lm85_data *data = i2c_get_clientdata(client);
930 long val = simple_strtol(buf, NULL, 10);
931
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100932 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 data->zone[nr].critical = TEMP_TO_REG(val);
934 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
935 data->zone[nr].critical);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100936 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 return count;
938}
Jean Delvareb353a482007-07-05 20:36:12 +0200939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940#define temp_auto(offset) \
Jean Delvareb353a482007-07-05 20:36:12 +0200941static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
942 S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
943 set_temp_auto_temp_off, offset - 1); \
944static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
945 S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
946 set_temp_auto_temp_min, offset - 1); \
947static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
948 S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
949 set_temp_auto_temp_max, offset - 1); \
950static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
951 S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
952 set_temp_auto_temp_crit, offset - 1);
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954temp_auto(1);
955temp_auto(2);
956temp_auto(3);
957
Ben Dooksd8d20612005-10-26 21:05:46 +0200958static int lm85_attach_adapter(struct i2c_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
960 if (!(adapter->class & I2C_CLASS_HWMON))
961 return 0;
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200962 return i2c_probe(adapter, &addr_data, lm85_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Mark M. Hoffman0501a3812006-09-24 21:14:35 +0200965static struct attribute *lm85_attributes[] = {
Jean Delvareb353a482007-07-05 20:36:12 +0200966 &sensor_dev_attr_fan1_input.dev_attr.attr,
967 &sensor_dev_attr_fan2_input.dev_attr.attr,
968 &sensor_dev_attr_fan3_input.dev_attr.attr,
969 &sensor_dev_attr_fan4_input.dev_attr.attr,
970 &sensor_dev_attr_fan1_min.dev_attr.attr,
971 &sensor_dev_attr_fan2_min.dev_attr.attr,
972 &sensor_dev_attr_fan3_min.dev_attr.attr,
973 &sensor_dev_attr_fan4_min.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +0200974 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
975 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
976 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
977 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +0200978
979 &sensor_dev_attr_pwm1.dev_attr.attr,
980 &sensor_dev_attr_pwm2.dev_attr.attr,
981 &sensor_dev_attr_pwm3.dev_attr.attr,
982 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
983 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
984 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
Jean Delvare34e7dc62008-10-17 17:51:13 +0200985 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
986 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
987 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +0200988
989 &sensor_dev_attr_in0_input.dev_attr.attr,
990 &sensor_dev_attr_in1_input.dev_attr.attr,
991 &sensor_dev_attr_in2_input.dev_attr.attr,
992 &sensor_dev_attr_in3_input.dev_attr.attr,
993 &sensor_dev_attr_in0_min.dev_attr.attr,
994 &sensor_dev_attr_in1_min.dev_attr.attr,
995 &sensor_dev_attr_in2_min.dev_attr.attr,
996 &sensor_dev_attr_in3_min.dev_attr.attr,
997 &sensor_dev_attr_in0_max.dev_attr.attr,
998 &sensor_dev_attr_in1_max.dev_attr.attr,
999 &sensor_dev_attr_in2_max.dev_attr.attr,
1000 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001001 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1002 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1003 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1004 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001005
1006 &sensor_dev_attr_temp1_input.dev_attr.attr,
1007 &sensor_dev_attr_temp2_input.dev_attr.attr,
1008 &sensor_dev_attr_temp3_input.dev_attr.attr,
1009 &sensor_dev_attr_temp1_min.dev_attr.attr,
1010 &sensor_dev_attr_temp2_min.dev_attr.attr,
1011 &sensor_dev_attr_temp3_min.dev_attr.attr,
1012 &sensor_dev_attr_temp1_max.dev_attr.attr,
1013 &sensor_dev_attr_temp2_max.dev_attr.attr,
1014 &sensor_dev_attr_temp3_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001015 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1016 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1017 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1018 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1019 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001020
1021 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
1022 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
1023 &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
1024 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1025 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1026 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1027 &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
1028 &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
1029 &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
Jean Delvareb353a482007-07-05 20:36:12 +02001030
1031 &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
1032 &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
1033 &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
1034 &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
1035 &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
1036 &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
1037 &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
1038 &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
1039 &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
1040 &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
1041 &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
1042 &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
1043
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001044 &dev_attr_vrm.attr,
1045 &dev_attr_cpu0_vid.attr,
1046 &dev_attr_alarms.attr,
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001047 NULL
1048};
1049
1050static const struct attribute_group lm85_group = {
1051 .attrs = lm85_attributes,
1052};
1053
Jean Delvare6b9aad22007-07-05 20:37:21 +02001054static struct attribute *lm85_attributes_in4[] = {
Jean Delvareb353a482007-07-05 20:36:12 +02001055 &sensor_dev_attr_in4_input.dev_attr.attr,
1056 &sensor_dev_attr_in4_min.dev_attr.attr,
1057 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001058 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001059 NULL
1060};
1061
Jean Delvare6b9aad22007-07-05 20:37:21 +02001062static const struct attribute_group lm85_group_in4 = {
1063 .attrs = lm85_attributes_in4,
1064};
1065
1066static struct attribute *lm85_attributes_in567[] = {
1067 &sensor_dev_attr_in5_input.dev_attr.attr,
1068 &sensor_dev_attr_in6_input.dev_attr.attr,
1069 &sensor_dev_attr_in7_input.dev_attr.attr,
1070 &sensor_dev_attr_in5_min.dev_attr.attr,
1071 &sensor_dev_attr_in6_min.dev_attr.attr,
1072 &sensor_dev_attr_in7_min.dev_attr.attr,
1073 &sensor_dev_attr_in5_max.dev_attr.attr,
1074 &sensor_dev_attr_in6_max.dev_attr.attr,
1075 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvarebf76e9d2007-07-05 20:37:58 +02001076 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1077 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1078 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001079 NULL
1080};
1081
1082static const struct attribute_group lm85_group_in567 = {
1083 .attrs = lm85_attributes_in567,
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001084};
1085
Jean Delvare5f44759472008-06-25 09:10:30 -04001086static void lm85_init_client(struct i2c_client *client)
1087{
1088 int value;
1089
1090 /* Start monitoring if needed */
1091 value = lm85_read_value(client, LM85_REG_CONFIG);
1092 if (!(value & 0x01)) {
1093 dev_info(&client->dev, "Starting monitoring\n");
1094 lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
1095 }
1096
1097 /* Warn about unusual configuration bits */
1098 if (value & 0x02)
1099 dev_warn(&client->dev, "Device configuration is locked\n");
1100 if (!(value & 0x04))
1101 dev_warn(&client->dev, "Device is not ready\n");
1102}
1103
Ben Dooksd8d20612005-10-26 21:05:46 +02001104static int lm85_detect(struct i2c_adapter *adapter, int address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 int kind)
1106{
Jean Delvaree89e22b2008-06-25 08:47:35 -04001107 struct i2c_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 struct lm85_data *data;
1109 int err = 0;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001110 const char *type_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Jean Delvaree89e22b2008-06-25 08:47:35 -04001112 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 /* We need to be able to do byte I/O */
Jean Delvare1f448092008-04-29 14:03:37 +02001114 goto ERROR0;
1115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001117 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 err = -ENOMEM;
1119 goto ERROR0;
1120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Jean Delvaree89e22b2008-06-25 08:47:35 -04001122 client = &data->client;
1123 i2c_set_clientdata(client, data);
1124 client->addr = address;
1125 client->adapter = adapter;
1126 client->driver = &lm85_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001128 /* If auto-detecting, determine the chip type */
1129 if (kind < 0) {
1130 int company = lm85_read_value(client, LM85_REG_COMPANY);
1131 int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001133 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1134 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1135 address, company, verstep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001137 /* All supported chips have the version in common */
1138 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
1139 dev_dbg(&adapter->dev, "Autodetection failed: "
1140 "unsupported version\n");
1141 goto ERROR1;
1142 }
1143 kind = any_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001145 /* Now, refine the detection */
1146 if (company == LM85_COMPANY_NATIONAL) {
1147 switch (verstep) {
1148 case LM85_VERSTEP_LM85C:
1149 kind = lm85c;
1150 break;
1151 case LM85_VERSTEP_LM85B:
1152 kind = lm85b;
1153 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
Jean Delvare69fc1fe2008-10-17 17:51:13 +02001155 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1156 switch (verstep) {
1157 case LM85_VERSTEP_ADM1027:
1158 kind = adm1027;
1159 break;
1160 case LM85_VERSTEP_ADT7463:
1161 case LM85_VERSTEP_ADT7463C:
1162 kind = adt7463;
1163 break;
1164 }
1165 } else if (company == LM85_COMPANY_SMSC) {
1166 switch (verstep) {
1167 case LM85_VERSTEP_EMC6D100_A0:
1168 case LM85_VERSTEP_EMC6D100_A1:
1169 /* Note: we can't tell a '100 from a '101 */
1170 kind = emc6d100;
1171 break;
1172 case LM85_VERSTEP_EMC6D102:
1173 kind = emc6d102;
1174 break;
1175 }
1176 } else {
1177 dev_dbg(&adapter->dev, "Autodetection failed: "
1178 "unknown vendor\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 goto ERROR1;
1180 }
1181 }
1182
1183 /* Fill in the chip specific driver values */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001184 switch (kind) {
1185 case lm85b:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 type_name = "lm85b";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001187 break;
1188 case lm85c:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 type_name = "lm85c";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001190 break;
1191 case adm1027:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 type_name = "adm1027";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001193 break;
1194 case adt7463:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 type_name = "adt7463";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001196 break;
1197 case emc6d100:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 type_name = "emc6d100";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001199 break;
1200 case emc6d102:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 type_name = "emc6d102";
Jean Delvaree89e22b2008-06-25 08:47:35 -04001202 break;
1203 default:
1204 type_name = "lm85";
1205 }
1206 strlcpy(client->name, type_name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 /* Fill in the remaining client fields */
1209 data->type = kind;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001210 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 /* Tell the I2C layer a new client has arrived */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001213 err = i2c_attach_client(client);
1214 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 goto ERROR1;
1216
1217 /* Set the VRM version */
Jean Delvare303760b2005-07-31 21:52:01 +02001218 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 /* Initialize the LM85 chip */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001221 lm85_init_client(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 /* Register sysfs hooks */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001224 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1225 if (err)
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001226 goto ERROR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Jean Delvare9c516ef2005-11-26 20:07:54 +01001228 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1229 as a sixth digital VID input rather than an analog input. */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001230 data->vid = lm85_read_value(client, LM85_REG_VID);
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001231 if (!(kind == adt7463 && (data->vid & 0x80)))
Jean Delvaree89e22b2008-06-25 08:47:35 -04001232 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001233 &lm85_group_in4)))
1234 goto ERROR3;
1235
1236 /* The EMC6D100 has 3 additional voltage inputs */
1237 if (kind == emc6d100)
Jean Delvaree89e22b2008-06-25 08:47:35 -04001238 if ((err = sysfs_create_group(&client->dev.kobj,
Jean Delvare6b9aad22007-07-05 20:37:21 +02001239 &lm85_group_in567)))
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001240 goto ERROR3;
1241
Jean Delvaree89e22b2008-06-25 08:47:35 -04001242 data->hwmon_dev = hwmon_device_register(&client->dev);
Tony Jones1beeffe2007-08-20 13:46:20 -07001243 if (IS_ERR(data->hwmon_dev)) {
1244 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001245 goto ERROR3;
Jean Delvare9c516ef2005-11-26 20:07:54 +01001246 }
1247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 return 0;
1249
1250 /* Error out and cleanup code */
Jean Delvare1f448092008-04-29 14:03:37 +02001251 ERROR3:
Jean Delvaree89e22b2008-06-25 08:47:35 -04001252 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1253 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
Jean Delvare6b9aad22007-07-05 20:37:21 +02001254 if (kind == emc6d100)
Jean Delvaree89e22b2008-06-25 08:47:35 -04001255 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
Jean Delvare1f448092008-04-29 14:03:37 +02001256 ERROR2:
Jean Delvaree89e22b2008-06-25 08:47:35 -04001257 i2c_detach_client(client);
Jean Delvare1f448092008-04-29 14:03:37 +02001258 ERROR1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 kfree(data);
Jean Delvare1f448092008-04-29 14:03:37 +02001260 ERROR0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 return err;
1262}
1263
Ben Dooksd8d20612005-10-26 21:05:46 +02001264static int lm85_detach_client(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001266 struct lm85_data *data = i2c_get_clientdata(client);
Tony Jones1beeffe2007-08-20 13:46:20 -07001267 hwmon_device_unregister(data->hwmon_dev);
Mark M. Hoffman0501a3812006-09-24 21:14:35 +02001268 sysfs_remove_group(&client->dev.kobj, &lm85_group);
Jean Delvare6b9aad22007-07-05 20:37:21 +02001269 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1270 if (data->type == emc6d100)
1271 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 i2c_detach_client(client);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001273 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 return 0;
1275}
1276
1277
Ben Dooksd8d20612005-10-26 21:05:46 +02001278static int lm85_read_value(struct i2c_client *client, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
1280 int res;
1281
1282 /* What size location is it? */
Jean Delvare1f448092008-04-29 14:03:37 +02001283 switch (reg) {
1284 case LM85_REG_FAN(0): /* Read WORD data */
1285 case LM85_REG_FAN(1):
1286 case LM85_REG_FAN(2):
1287 case LM85_REG_FAN(3):
1288 case LM85_REG_FAN_MIN(0):
1289 case LM85_REG_FAN_MIN(1):
1290 case LM85_REG_FAN_MIN(2):
1291 case LM85_REG_FAN_MIN(3):
1292 case LM85_REG_ALARM1: /* Read both bytes at once */
1293 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
1294 res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
1295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 default: /* Read BYTE data */
1297 res = i2c_smbus_read_byte_data(client, reg);
Jean Delvare1f448092008-04-29 14:03:37 +02001298 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 }
1300
Jean Delvare1f448092008-04-29 14:03:37 +02001301 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Jean Delvaree89e22b2008-06-25 08:47:35 -04001304static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Jean Delvare1f448092008-04-29 14:03:37 +02001306 switch (reg) {
1307 case LM85_REG_FAN(0): /* Write WORD data */
1308 case LM85_REG_FAN(1):
1309 case LM85_REG_FAN(2):
1310 case LM85_REG_FAN(3):
1311 case LM85_REG_FAN_MIN(0):
1312 case LM85_REG_FAN_MIN(1):
1313 case LM85_REG_FAN_MIN(2):
1314 case LM85_REG_FAN_MIN(3):
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* NOTE: ALARM is read only, so not included here */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001316 i2c_smbus_write_byte_data(client, reg, value & 0xff);
1317 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
Jean Delvare1f448092008-04-29 14:03:37 +02001318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 default: /* Write BYTE data */
Jean Delvaree89e22b2008-06-25 08:47:35 -04001320 i2c_smbus_write_byte_data(client, reg, value);
Jean Delvare1f448092008-04-29 14:03:37 +02001321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325static struct lm85_data *lm85_update_device(struct device *dev)
1326{
1327 struct i2c_client *client = to_i2c_client(dev);
1328 struct lm85_data *data = i2c_get_clientdata(client);
1329 int i;
1330
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001331 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Jean Delvare1f448092008-04-29 14:03:37 +02001333 if (!data->valid ||
1334 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 /* Things that change quickly */
1336 dev_dbg(&client->dev, "Reading sensor values\n");
Jean Delvare1f448092008-04-29 14:03:37 +02001337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 /* Have to read extended bits first to "freeze" the
1339 * more significant bits that are read later.
Jean Delvare5a4d3ef2007-07-05 20:38:32 +02001340 * There are 2 additional resolution bits per channel and we
1341 * have room for 4, so we shift them to the left.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 */
Jean Delvare1f448092008-04-29 14:03:37 +02001343 if (data->type == adm1027 || data->type == adt7463) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 int ext1 = lm85_read_value(client,
1345 ADM1027_REG_EXTEND_ADC1);
1346 int ext2 = lm85_read_value(client,
1347 ADM1027_REG_EXTEND_ADC2);
1348 int val = (ext1 << 8) + ext2;
1349
Jean Delvare1f448092008-04-29 14:03:37 +02001350 for (i = 0; i <= 4; i++)
1351 data->in_ext[i] =
1352 ((val >> (i * 2)) & 0x03) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Jean Delvare1f448092008-04-29 14:03:37 +02001354 for (i = 0; i <= 2; i++)
1355 data->temp_ext[i] =
1356 (val >> ((i + 4) * 2)) & 0x0c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358
Jean Delvare9c516ef2005-11-26 20:07:54 +01001359 data->vid = lm85_read_value(client, LM85_REG_VID);
1360
1361 for (i = 0; i <= 3; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 data->in[i] =
1363 lm85_read_value(client, LM85_REG_IN(i));
Jean Delvaree89e22b2008-06-25 08:47:35 -04001364 data->fan[i] =
1365 lm85_read_value(client, LM85_REG_FAN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
1367
Jean Delvare9c516ef2005-11-26 20:07:54 +01001368 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1369 data->in[4] = lm85_read_value(client,
1370 LM85_REG_IN(4));
1371 }
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 for (i = 0; i <= 2; ++i) {
1374 data->temp[i] =
1375 lm85_read_value(client, LM85_REG_TEMP(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 data->pwm[i] =
1377 lm85_read_value(client, LM85_REG_PWM(i));
1378 }
1379
1380 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1381
Jean Delvaredd1ac532008-05-01 08:47:33 +02001382 if (data->type == emc6d100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 /* Three more voltage sensors */
1384 for (i = 5; i <= 7; ++i) {
Jean Delvare1f448092008-04-29 14:03:37 +02001385 data->in[i] = lm85_read_value(client,
1386 EMC6D100_REG_IN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 }
1388 /* More alarm bits */
Jean Delvare1f448092008-04-29 14:03:37 +02001389 data->alarms |= lm85_read_value(client,
1390 EMC6D100_REG_ALARM3) << 16;
1391 } else if (data->type == emc6d102) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 /* Have to read LSB bits after the MSB ones because
1393 the reading of the MSB bits has frozen the
1394 LSBs (backward from the ADM1027).
1395 */
1396 int ext1 = lm85_read_value(client,
1397 EMC6D102_REG_EXTEND_ADC1);
1398 int ext2 = lm85_read_value(client,
1399 EMC6D102_REG_EXTEND_ADC2);
1400 int ext3 = lm85_read_value(client,
1401 EMC6D102_REG_EXTEND_ADC3);
1402 int ext4 = lm85_read_value(client,
1403 EMC6D102_REG_EXTEND_ADC4);
1404 data->in_ext[0] = ext3 & 0x0f;
1405 data->in_ext[1] = ext4 & 0x0f;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001406 data->in_ext[2] = ext4 >> 4;
1407 data->in_ext[3] = ext3 >> 4;
1408 data->in_ext[4] = ext2 >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 data->temp_ext[0] = ext1 & 0x0f;
1411 data->temp_ext[1] = ext2 & 0x0f;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001412 data->temp_ext[2] = ext1 >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 }
1414
Jean Delvare1f448092008-04-29 14:03:37 +02001415 data->last_reading = jiffies;
1416 } /* last_reading */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Jean Delvare1f448092008-04-29 14:03:37 +02001418 if (!data->valid ||
1419 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 /* Things that don't change often */
1421 dev_dbg(&client->dev, "Reading config values\n");
1422
Jean Delvare9c516ef2005-11-26 20:07:54 +01001423 for (i = 0; i <= 3; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 data->in_min[i] =
1425 lm85_read_value(client, LM85_REG_IN_MIN(i));
1426 data->in_max[i] =
1427 lm85_read_value(client, LM85_REG_IN_MAX(i));
Jean Delvaree89e22b2008-06-25 08:47:35 -04001428 data->fan_min[i] =
1429 lm85_read_value(client, LM85_REG_FAN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431
Jean Delvare9c516ef2005-11-26 20:07:54 +01001432 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1433 data->in_min[4] = lm85_read_value(client,
1434 LM85_REG_IN_MIN(4));
1435 data->in_max[4] = lm85_read_value(client,
1436 LM85_REG_IN_MAX(4));
1437 }
1438
Jean Delvare1f448092008-04-29 14:03:37 +02001439 if (data->type == emc6d100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 for (i = 5; i <= 7; ++i) {
Jean Delvare1f448092008-04-29 14:03:37 +02001441 data->in_min[i] = lm85_read_value(client,
1442 EMC6D100_REG_IN_MIN(i));
1443 data->in_max[i] = lm85_read_value(client,
1444 EMC6D100_REG_IN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
1446 }
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 for (i = 0; i <= 2; ++i) {
Jean Delvaree89e22b2008-06-25 08:47:35 -04001449 int val;
1450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 data->temp_min[i] =
1452 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1453 data->temp_max[i] =
1454 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 data->autofan[i].config =
1457 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1458 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
Jean Delvare34e7dc62008-10-17 17:51:13 +02001459 data->pwm_freq[i] = val & 0x07;
Jean Delvaree89e22b2008-06-25 08:47:35 -04001460 data->zone[i].range = val >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 data->autofan[i].min_pwm =
1462 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1463 data->zone[i].limit =
1464 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
1465 data->zone[i].critical =
1466 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
1467 }
1468
1469 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
Jean Delvare1f448092008-04-29 14:03:37 +02001470 data->autofan[0].min_off = (i & 0x20) != 0;
1471 data->autofan[1].min_off = (i & 0x40) != 0;
1472 data->autofan[2].min_off = (i & 0x80) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
Jean Delvaree89e22b2008-06-25 08:47:35 -04001475 data->zone[0].hyst = i >> 4;
Jean Delvare1f448092008-04-29 14:03:37 +02001476 data->zone[1].hyst = i & 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
Jean Delvaree89e22b2008-06-25 08:47:35 -04001479 data->zone[2].hyst = i >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 data->last_config = jiffies;
Jean Delvare1f448092008-04-29 14:03:37 +02001482 } /* last_config */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 data->valid = 1;
1485
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001486 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 return data;
1489}
1490
1491
1492static int __init sm_lm85_init(void)
1493{
1494 return i2c_add_driver(&lm85_driver);
1495}
1496
Jean Delvare1f448092008-04-29 14:03:37 +02001497static void __exit sm_lm85_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
1499 i2c_del_driver(&lm85_driver);
1500}
1501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502MODULE_LICENSE("GPL");
Jean Delvare1f448092008-04-29 14:03:37 +02001503MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1504 "Margit Schubert-While <margitsw@t-online.de>, "
Jean Delvaree89e22b2008-06-25 08:47:35 -04001505 "Justin Thiessen <jthiessen@penguincomputing.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1507
1508module_init(sm_lm85_init);
1509module_exit(sm_lm85_exit);