blob: dafa477715e327fcb324c86e51dba46e1afeb450 [file] [log] [blame]
Grant Coady40b5cda2005-04-30 21:41:29 +10001/*
2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware
Guenter Roeckc387e4e2012-01-14 13:12:38 -08003 * monitoring
Grant Coady40b5cda2005-04-30 21:41:29 +10004 *
5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl>
6 * Philip Edelbrock <phil@netroedge.com>
7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl>
Grant Coady2ca7b962006-10-08 21:57:41 +02008 * Copyright (C) 2005 Grant Coady <gcoady.lk@gmail.com> with valuable
Guenter Roeckc387e4e2012-01-14 13:12:38 -08009 * guidance from Jean Delvare
Grant Coady40b5cda2005-04-30 21:41:29 +100010 *
11 * Driver supports Analog Devices ADM9240
12 * Dallas Semiconductor DS1780
13 * National Semiconductor LM81
14 *
15 * ADM9240 is the reference, DS1780 and LM81 are register compatibles
16 *
17 * Voltage Six inputs are scaled by chip, VID also reported
18 * Temperature Chip temperature to 0.5'C, maximum and max_hysteris
19 * Fans 2 fans, low speed alarm, automatic fan clock divider
20 * Alarms 16-bit map of active alarms
21 * Analog Out 0..1250 mV output
22 *
Jean Delvare0de2b242011-01-12 21:55:09 +010023 * Chassis Intrusion: clear CI latch with 'echo 0 > intrusion0_alarm'
Grant Coady40b5cda2005-04-30 21:41:29 +100024 *
25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
26 *
27 * LM81 extended temp reading not implemented
28 *
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 */
43
44#include <linux/init.h>
45#include <linux/module.h>
46#include <linux/slab.h>
47#include <linux/i2c.h>
Grant Coadyc7461a62005-09-17 05:32:57 +100048#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040049#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020050#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040051#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010052#include <linux/mutex.h>
Jean Delvaredcd8f392012-10-10 15:25:56 +020053#include <linux/jiffies.h>
Grant Coady40b5cda2005-04-30 21:41:29 +100054
55/* Addresses to scan */
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050056static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
Grant Coady40b5cda2005-04-30 21:41:29 +100057 I2C_CLIENT_END };
58
Jean Delvaree5e9f442009-12-14 21:17:27 +010059enum chips { adm9240, ds1780, lm81 };
Grant Coady40b5cda2005-04-30 21:41:29 +100060
61/* ADM9240 registers */
62#define ADM9240_REG_MAN_ID 0x3e
63#define ADM9240_REG_DIE_REV 0x3f
64#define ADM9240_REG_CONFIG 0x40
65
66#define ADM9240_REG_IN(nr) (0x20 + (nr)) /* 0..5 */
67#define ADM9240_REG_IN_MAX(nr) (0x2b + (nr) * 2)
68#define ADM9240_REG_IN_MIN(nr) (0x2c + (nr) * 2)
69#define ADM9240_REG_FAN(nr) (0x28 + (nr)) /* 0..1 */
70#define ADM9240_REG_FAN_MIN(nr) (0x3b + (nr))
71#define ADM9240_REG_INT(nr) (0x41 + (nr))
72#define ADM9240_REG_INT_MASK(nr) (0x43 + (nr))
73#define ADM9240_REG_TEMP 0x27
Grant Coadyc7461a62005-09-17 05:32:57 +100074#define ADM9240_REG_TEMP_MAX(nr) (0x39 + (nr)) /* 0, 1 = high, hyst */
Grant Coady40b5cda2005-04-30 21:41:29 +100075#define ADM9240_REG_ANALOG_OUT 0x19
76#define ADM9240_REG_CHASSIS_CLEAR 0x46
77#define ADM9240_REG_VID_FAN_DIV 0x47
78#define ADM9240_REG_I2C_ADDR 0x48
79#define ADM9240_REG_VID4 0x49
80#define ADM9240_REG_TEMP_CONF 0x4b
81
82/* generalised scaling with integer rounding */
83static inline int SCALE(long val, int mul, int div)
84{
85 if (val < 0)
86 return (val * mul - div / 2) / div;
87 else
88 return (val * mul + div / 2) / div;
89}
90
91/* adm9240 internally scales voltage measurements */
92static const u16 nom_mv[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
93
94static inline unsigned int IN_FROM_REG(u8 reg, int n)
95{
96 return SCALE(reg, nom_mv[n], 192);
97}
98
99static inline u8 IN_TO_REG(unsigned long val, int n)
100{
101 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
102}
103
104/* temperature range: -40..125, 127 disables temperature alarm */
105static inline s8 TEMP_TO_REG(long val)
106{
107 return SENSORS_LIMIT(SCALE(val, 1, 1000), -40, 127);
108}
109
110/* two fans, each with low fan speed limit */
111static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)
112{
113 if (!reg) /* error */
114 return -1;
115
116 if (reg == 255)
117 return 0;
118
119 return SCALE(1350000, 1, reg * div);
120}
121
122/* analog out 0..1250mV */
123static inline u8 AOUT_TO_REG(unsigned long val)
124{
125 return SENSORS_LIMIT(SCALE(val, 255, 1250), 0, 255);
126}
127
128static inline unsigned int AOUT_FROM_REG(u8 reg)
129{
130 return SCALE(reg, 1250, 255);
131}
132
Jean Delvare7fae8282008-07-16 19:30:09 +0200133static int adm9240_probe(struct i2c_client *client,
134 const struct i2c_device_id *id);
Jean Delvare310ec792009-12-14 21:17:23 +0100135static int adm9240_detect(struct i2c_client *client,
Jean Delvare7fae8282008-07-16 19:30:09 +0200136 struct i2c_board_info *info);
Grant Coady40b5cda2005-04-30 21:41:29 +1000137static void adm9240_init_client(struct i2c_client *client);
Jean Delvare7fae8282008-07-16 19:30:09 +0200138static int adm9240_remove(struct i2c_client *client);
Grant Coady40b5cda2005-04-30 21:41:29 +1000139static struct adm9240_data *adm9240_update_device(struct device *dev);
140
141/* driver data */
Jean Delvare7fae8282008-07-16 19:30:09 +0200142static const struct i2c_device_id adm9240_id[] = {
143 { "adm9240", adm9240 },
144 { "ds1780", ds1780 },
145 { "lm81", lm81 },
146 { }
147};
148MODULE_DEVICE_TABLE(i2c, adm9240_id);
149
Grant Coady40b5cda2005-04-30 21:41:29 +1000150static struct i2c_driver adm9240_driver = {
Jean Delvare7fae8282008-07-16 19:30:09 +0200151 .class = I2C_CLASS_HWMON,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100152 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100153 .name = "adm9240",
154 },
Jean Delvare7fae8282008-07-16 19:30:09 +0200155 .probe = adm9240_probe,
156 .remove = adm9240_remove,
157 .id_table = adm9240_id,
158 .detect = adm9240_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +0100159 .address_list = normal_i2c,
Grant Coady40b5cda2005-04-30 21:41:29 +1000160};
161
162/* per client data */
163struct adm9240_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700164 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100165 struct mutex update_lock;
Grant Coady40b5cda2005-04-30 21:41:29 +1000166 char valid;
167 unsigned long last_updated_measure;
168 unsigned long last_updated_config;
169
170 u8 in[6]; /* ro in0_input */
171 u8 in_max[6]; /* rw in0_max */
172 u8 in_min[6]; /* rw in0_min */
173 u8 fan[2]; /* ro fan1_input */
174 u8 fan_min[2]; /* rw fan1_min */
175 u8 fan_div[2]; /* rw fan1_div, read-only accessor */
176 s16 temp; /* ro temp1_input, 9-bit sign-extended */
Grant Coadyc7461a62005-09-17 05:32:57 +1000177 s8 temp_max[2]; /* rw 0 -> temp_max, 1 -> temp_max_hyst */
Grant Coady40b5cda2005-04-30 21:41:29 +1000178 u16 alarms; /* ro alarms */
Grant Coady8e8f9282005-05-13 20:26:10 +1000179 u8 aout; /* rw aout_output */
Grant Coady40b5cda2005-04-30 21:41:29 +1000180 u8 vid; /* ro vid */
181 u8 vrm; /* -- vrm set on startup, no accessor */
182};
183
Grant Coady40b5cda2005-04-30 21:41:29 +1000184/*** sysfs accessors ***/
185
186/* temperature */
Grant Coadyc7461a62005-09-17 05:32:57 +1000187static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
188 char *buf)
189{
190 struct adm9240_data *data = adm9240_update_device(dev);
191 return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
Grant Coady40b5cda2005-04-30 21:41:29 +1000192}
193
Grant Coadyc7461a62005-09-17 05:32:57 +1000194static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
195 char *buf)
196{
197 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
198 struct adm9240_data *data = adm9240_update_device(dev);
199 return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000);
200}
Grant Coady40b5cda2005-04-30 21:41:29 +1000201
Grant Coadyc7461a62005-09-17 05:32:57 +1000202static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
203 const char *buf, size_t count)
204{
205 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
206 struct i2c_client *client = to_i2c_client(dev);
207 struct adm9240_data *data = i2c_get_clientdata(client);
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800208 long val;
209 int err;
210
211 err = kstrtol(buf, 10, &val);
212 if (err)
213 return err;
Grant Coadyc7461a62005-09-17 05:32:57 +1000214
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100215 mutex_lock(&data->update_lock);
Grant Coadyc7461a62005-09-17 05:32:57 +1000216 data->temp_max[attr->index] = TEMP_TO_REG(val);
217 i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index),
218 data->temp_max[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100219 mutex_unlock(&data->update_lock);
Grant Coadyc7461a62005-09-17 05:32:57 +1000220 return count;
221}
222
Grant Coady40b5cda2005-04-30 21:41:29 +1000223static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
Grant Coadyc7461a62005-09-17 05:32:57 +1000224static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
225 show_max, set_max, 0);
226static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
227 show_max, set_max, 1);
Grant Coady40b5cda2005-04-30 21:41:29 +1000228
229/* voltage */
Grant Coadyc7461a62005-09-17 05:32:57 +1000230static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
231 char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000232{
Grant Coadyc7461a62005-09-17 05:32:57 +1000233 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000234 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000235 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index],
236 attr->index));
Grant Coady40b5cda2005-04-30 21:41:29 +1000237}
238
Jean Delvaree415e482005-09-25 16:14:18 +0200239static ssize_t show_in_min(struct device *dev,
240 struct device_attribute *devattr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000241{
Grant Coadyc7461a62005-09-17 05:32:57 +1000242 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000243 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000244 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index],
245 attr->index));
Grant Coady40b5cda2005-04-30 21:41:29 +1000246}
247
Jean Delvaree415e482005-09-25 16:14:18 +0200248static ssize_t show_in_max(struct device *dev,
249 struct device_attribute *devattr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000250{
Grant Coadyc7461a62005-09-17 05:32:57 +1000251 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000252 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000253 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index],
254 attr->index));
Grant Coady40b5cda2005-04-30 21:41:29 +1000255}
256
Jean Delvaree415e482005-09-25 16:14:18 +0200257static ssize_t set_in_min(struct device *dev,
258 struct device_attribute *devattr,
Grant Coadyc7461a62005-09-17 05:32:57 +1000259 const char *buf, size_t count)
Grant Coady40b5cda2005-04-30 21:41:29 +1000260{
Grant Coadyc7461a62005-09-17 05:32:57 +1000261 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000262 struct i2c_client *client = to_i2c_client(dev);
263 struct adm9240_data *data = i2c_get_clientdata(client);
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800264 unsigned long val;
265 int err;
266
267 err = kstrtoul(buf, 10, &val);
268 if (err)
269 return err;
Grant Coady40b5cda2005-04-30 21:41:29 +1000270
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100271 mutex_lock(&data->update_lock);
Grant Coadyc7461a62005-09-17 05:32:57 +1000272 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
273 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index),
274 data->in_min[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100275 mutex_unlock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000276 return count;
277}
278
Jean Delvaree415e482005-09-25 16:14:18 +0200279static ssize_t set_in_max(struct device *dev,
280 struct device_attribute *devattr,
Grant Coadyc7461a62005-09-17 05:32:57 +1000281 const char *buf, size_t count)
Grant Coady40b5cda2005-04-30 21:41:29 +1000282{
Grant Coadyc7461a62005-09-17 05:32:57 +1000283 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000284 struct i2c_client *client = to_i2c_client(dev);
285 struct adm9240_data *data = i2c_get_clientdata(client);
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800286 unsigned long val;
287 int err;
288
289 err = kstrtoul(buf, 10, &val);
290 if (err)
291 return err;
Grant Coady40b5cda2005-04-30 21:41:29 +1000292
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100293 mutex_lock(&data->update_lock);
Grant Coadyc7461a62005-09-17 05:32:57 +1000294 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
295 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index),
296 data->in_max[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100297 mutex_unlock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000298 return count;
299}
300
Grant Coadyc7461a62005-09-17 05:32:57 +1000301#define vin(nr) \
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800302static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
Grant Coadyc7461a62005-09-17 05:32:57 +1000303 show_in, NULL, nr); \
304static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
305 show_in_min, set_in_min, nr); \
306static SENSOR_DEVICE_ATTR(in##nr##_max, S_IRUGO | S_IWUSR, \
307 show_in_max, set_in_max, nr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000308
Grant Coadyc7461a62005-09-17 05:32:57 +1000309vin(0);
310vin(1);
311vin(2);
312vin(3);
313vin(4);
314vin(5);
Grant Coady40b5cda2005-04-30 21:41:29 +1000315
316/* fans */
Grant Coadyc7461a62005-09-17 05:32:57 +1000317static ssize_t show_fan(struct device *dev,
318 struct device_attribute *devattr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000319{
Grant Coadyc7461a62005-09-17 05:32:57 +1000320 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000321 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000322 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index],
323 1 << data->fan_div[attr->index]));
Grant Coady40b5cda2005-04-30 21:41:29 +1000324}
325
Grant Coadyc7461a62005-09-17 05:32:57 +1000326static ssize_t show_fan_min(struct device *dev,
327 struct device_attribute *devattr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000328{
Grant Coadyc7461a62005-09-17 05:32:57 +1000329 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000330 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000331 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index],
332 1 << data->fan_div[attr->index]));
Grant Coady40b5cda2005-04-30 21:41:29 +1000333}
334
Grant Coadyc7461a62005-09-17 05:32:57 +1000335static ssize_t show_fan_div(struct device *dev,
336 struct device_attribute *devattr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000337{
Grant Coadyc7461a62005-09-17 05:32:57 +1000338 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000339 struct adm9240_data *data = adm9240_update_device(dev);
Grant Coadyc7461a62005-09-17 05:32:57 +1000340 return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]);
Grant Coady40b5cda2005-04-30 21:41:29 +1000341}
342
343/* write new fan div, callers must hold data->update_lock */
344static void adm9240_write_fan_div(struct i2c_client *client, int nr,
345 u8 fan_div)
346{
347 u8 reg, old, shift = (nr + 2) * 2;
348
Grant Coady205cf132005-09-17 05:32:55 +1000349 reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
Grant Coady40b5cda2005-04-30 21:41:29 +1000350 old = (reg >> shift) & 3;
351 reg &= ~(3 << shift);
352 reg |= (fan_div << shift);
Grant Coady205cf132005-09-17 05:32:55 +1000353 i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg);
Grant Coady40b5cda2005-04-30 21:41:29 +1000354 dev_dbg(&client->dev, "fan%d clock divider changed from %u "
355 "to %u\n", nr + 1, 1 << old, 1 << fan_div);
356}
357
Jean Delvaree415e482005-09-25 16:14:18 +0200358/*
Grant Coady40b5cda2005-04-30 21:41:29 +1000359 * set fan speed low limit:
360 *
361 * - value is zero: disable fan speed low limit alarm
362 *
363 * - value is below fan speed measurement range: enable fan speed low
364 * limit alarm to be asserted while fan speed too slow to measure
365 *
366 * - otherwise: select fan clock divider to suit fan speed low limit,
367 * measurement code may adjust registers to ensure fan speed reading
368 */
Grant Coadyc7461a62005-09-17 05:32:57 +1000369static ssize_t set_fan_min(struct device *dev,
370 struct device_attribute *devattr,
371 const char *buf, size_t count)
Grant Coady40b5cda2005-04-30 21:41:29 +1000372{
Grant Coadyc7461a62005-09-17 05:32:57 +1000373 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Grant Coady40b5cda2005-04-30 21:41:29 +1000374 struct i2c_client *client = to_i2c_client(dev);
375 struct adm9240_data *data = i2c_get_clientdata(client);
Grant Coadyc7461a62005-09-17 05:32:57 +1000376 int nr = attr->index;
Grant Coady40b5cda2005-04-30 21:41:29 +1000377 u8 new_div;
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800378 unsigned long val;
379 int err;
380
381 err = kstrtoul(buf, 10, &val);
382 if (err)
383 return err;
Grant Coady40b5cda2005-04-30 21:41:29 +1000384
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100385 mutex_lock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000386
387 if (!val) {
388 data->fan_min[nr] = 255;
389 new_div = data->fan_div[nr];
390
391 dev_dbg(&client->dev, "fan%u low limit set disabled\n",
392 nr + 1);
393
394 } else if (val < 1350000 / (8 * 254)) {
395 new_div = 3;
396 data->fan_min[nr] = 254;
397
398 dev_dbg(&client->dev, "fan%u low limit set minimum %u\n",
399 nr + 1, FAN_FROM_REG(254, 1 << new_div));
400
401 } else {
402 unsigned int new_min = 1350000 / val;
403
404 new_div = 0;
405 while (new_min > 192 && new_div < 3) {
406 new_div++;
407 new_min /= 2;
408 }
409 if (!new_min) /* keep > 0 */
410 new_min++;
411
412 data->fan_min[nr] = new_min;
413
414 dev_dbg(&client->dev, "fan%u low limit set fan speed %u\n",
415 nr + 1, FAN_FROM_REG(new_min, 1 << new_div));
416 }
417
418 if (new_div != data->fan_div[nr]) {
419 data->fan_div[nr] = new_div;
420 adm9240_write_fan_div(client, nr, new_div);
421 }
Grant Coady205cf132005-09-17 05:32:55 +1000422 i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr),
Grant Coady40b5cda2005-04-30 21:41:29 +1000423 data->fan_min[nr]);
424
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100425 mutex_unlock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000426 return count;
427}
428
Grant Coadyc7461a62005-09-17 05:32:57 +1000429#define fan(nr) \
430static SENSOR_DEVICE_ATTR(fan##nr##_input, S_IRUGO, \
431 show_fan, NULL, nr - 1); \
432static SENSOR_DEVICE_ATTR(fan##nr##_div, S_IRUGO, \
433 show_fan_div, NULL, nr - 1); \
434static SENSOR_DEVICE_ATTR(fan##nr##_min, S_IRUGO | S_IWUSR, \
435 show_fan_min, set_fan_min, nr - 1);
Grant Coady40b5cda2005-04-30 21:41:29 +1000436
Grant Coadyc7461a62005-09-17 05:32:57 +1000437fan(1);
438fan(2);
Grant Coady40b5cda2005-04-30 21:41:29 +1000439
440/* alarms */
Jean Delvaree415e482005-09-25 16:14:18 +0200441static ssize_t show_alarms(struct device *dev,
442 struct device_attribute *attr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000443{
444 struct adm9240_data *data = adm9240_update_device(dev);
445 return sprintf(buf, "%u\n", data->alarms);
446}
447static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
448
Jean Delvare360f9452008-01-06 15:49:19 +0100449static ssize_t show_alarm(struct device *dev,
450 struct device_attribute *attr, char *buf)
451{
452 int bitnr = to_sensor_dev_attr(attr)->index;
453 struct adm9240_data *data = adm9240_update_device(dev);
454 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
455}
456static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
457static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
458static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
459static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
460static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
461static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
462static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
463static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
464static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
465
Grant Coady40b5cda2005-04-30 21:41:29 +1000466/* vid */
Jean Delvaree415e482005-09-25 16:14:18 +0200467static ssize_t show_vid(struct device *dev,
468 struct device_attribute *attr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000469{
470 struct adm9240_data *data = adm9240_update_device(dev);
471 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
472}
473static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
474
475/* analog output */
Jean Delvaree415e482005-09-25 16:14:18 +0200476static ssize_t show_aout(struct device *dev,
477 struct device_attribute *attr, char *buf)
Grant Coady40b5cda2005-04-30 21:41:29 +1000478{
479 struct adm9240_data *data = adm9240_update_device(dev);
480 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
481}
482
Jean Delvaree415e482005-09-25 16:14:18 +0200483static ssize_t set_aout(struct device *dev,
484 struct device_attribute *attr,
485 const char *buf, size_t count)
Grant Coady40b5cda2005-04-30 21:41:29 +1000486{
487 struct i2c_client *client = to_i2c_client(dev);
488 struct adm9240_data *data = i2c_get_clientdata(client);
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800489 long val;
490 int err;
491
492 err = kstrtol(buf, 10, &val);
493 if (err)
494 return err;
Grant Coady40b5cda2005-04-30 21:41:29 +1000495
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100496 mutex_lock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000497 data->aout = AOUT_TO_REG(val);
Grant Coady205cf132005-09-17 05:32:55 +1000498 i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100499 mutex_unlock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000500 return count;
501}
502static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
503
Jean Delvare0de2b242011-01-12 21:55:09 +0100504static ssize_t chassis_clear(struct device *dev,
505 struct device_attribute *attr,
506 const char *buf, size_t count)
507{
508 struct i2c_client *client = to_i2c_client(dev);
509 struct adm9240_data *data = i2c_get_clientdata(client);
510 unsigned long val;
511
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100512 if (kstrtoul(buf, 10, &val) || val != 0)
Jean Delvare0de2b242011-01-12 21:55:09 +0100513 return -EINVAL;
514
515 mutex_lock(&data->update_lock);
516 i2c_smbus_write_byte_data(client, ADM9240_REG_CHASSIS_CLEAR, 0x80);
517 data->valid = 0; /* Force cache refresh */
518 mutex_unlock(&data->update_lock);
519 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
520
521 return count;
522}
523static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
524 chassis_clear, 12);
Grant Coady40b5cda2005-04-30 21:41:29 +1000525
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200526static struct attribute *adm9240_attributes[] = {
527 &sensor_dev_attr_in0_input.dev_attr.attr,
528 &sensor_dev_attr_in0_min.dev_attr.attr,
529 &sensor_dev_attr_in0_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100530 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200531 &sensor_dev_attr_in1_input.dev_attr.attr,
532 &sensor_dev_attr_in1_min.dev_attr.attr,
533 &sensor_dev_attr_in1_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100534 &sensor_dev_attr_in1_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200535 &sensor_dev_attr_in2_input.dev_attr.attr,
536 &sensor_dev_attr_in2_min.dev_attr.attr,
537 &sensor_dev_attr_in2_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100538 &sensor_dev_attr_in2_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200539 &sensor_dev_attr_in3_input.dev_attr.attr,
540 &sensor_dev_attr_in3_min.dev_attr.attr,
541 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100542 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200543 &sensor_dev_attr_in4_input.dev_attr.attr,
544 &sensor_dev_attr_in4_min.dev_attr.attr,
545 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100546 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200547 &sensor_dev_attr_in5_input.dev_attr.attr,
548 &sensor_dev_attr_in5_min.dev_attr.attr,
549 &sensor_dev_attr_in5_max.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100550 &sensor_dev_attr_in5_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200551 &dev_attr_temp1_input.attr,
552 &sensor_dev_attr_temp1_max.dev_attr.attr,
553 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100554 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200555 &sensor_dev_attr_fan1_input.dev_attr.attr,
556 &sensor_dev_attr_fan1_div.dev_attr.attr,
557 &sensor_dev_attr_fan1_min.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100558 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200559 &sensor_dev_attr_fan2_input.dev_attr.attr,
560 &sensor_dev_attr_fan2_div.dev_attr.attr,
561 &sensor_dev_attr_fan2_min.dev_attr.attr,
Jean Delvare360f9452008-01-06 15:49:19 +0100562 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200563 &dev_attr_alarms.attr,
564 &dev_attr_aout_output.attr,
Jean Delvare0de2b242011-01-12 21:55:09 +0100565 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200566 &dev_attr_cpu0_vid.attr,
567 NULL
568};
569
570static const struct attribute_group adm9240_group = {
571 .attrs = adm9240_attributes,
572};
573
Grant Coady40b5cda2005-04-30 21:41:29 +1000574
575/*** sensor chip detect and driver install ***/
576
Jean Delvare7fae8282008-07-16 19:30:09 +0200577/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +0100578static int adm9240_detect(struct i2c_client *new_client,
Jean Delvare7fae8282008-07-16 19:30:09 +0200579 struct i2c_board_info *info)
Grant Coady40b5cda2005-04-30 21:41:29 +1000580{
Jean Delvare7fae8282008-07-16 19:30:09 +0200581 struct i2c_adapter *adapter = new_client->adapter;
Grant Coady40b5cda2005-04-30 21:41:29 +1000582 const char *name = "";
Jean Delvare7fae8282008-07-16 19:30:09 +0200583 int address = new_client->addr;
Grant Coady40b5cda2005-04-30 21:41:29 +1000584 u8 man_id, die_rev;
585
586 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvare7fae8282008-07-16 19:30:09 +0200587 return -ENODEV;
Grant Coady40b5cda2005-04-30 21:41:29 +1000588
Jean Delvare52df6442009-12-09 20:35:57 +0100589 /* verify chip: reg address should match i2c address */
590 if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
591 != address) {
592 dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n",
593 address);
594 return -ENODEV;
Grant Coady40b5cda2005-04-30 21:41:29 +1000595 }
596
Jean Delvare52df6442009-12-09 20:35:57 +0100597 /* check known chip manufacturer */
598 man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID);
599 if (man_id == 0x23) {
Grant Coady40b5cda2005-04-30 21:41:29 +1000600 name = "adm9240";
Jean Delvare52df6442009-12-09 20:35:57 +0100601 } else if (man_id == 0xda) {
Grant Coady40b5cda2005-04-30 21:41:29 +1000602 name = "ds1780";
Jean Delvare52df6442009-12-09 20:35:57 +0100603 } else if (man_id == 0x01) {
Grant Coady40b5cda2005-04-30 21:41:29 +1000604 name = "lm81";
Jean Delvare52df6442009-12-09 20:35:57 +0100605 } else {
606 dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n",
607 man_id);
608 return -ENODEV;
Grant Coady40b5cda2005-04-30 21:41:29 +1000609 }
Jean Delvare52df6442009-12-09 20:35:57 +0100610
611 /* successful detect, print chip info */
612 die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV);
613 dev_info(&adapter->dev, "found %s revision %u\n",
614 man_id == 0x23 ? "ADM9240" :
615 man_id == 0xda ? "DS1780" : "LM81", die_rev);
616
Jean Delvare7fae8282008-07-16 19:30:09 +0200617 strlcpy(info->type, name, I2C_NAME_SIZE);
Grant Coady40b5cda2005-04-30 21:41:29 +1000618
Jean Delvare7fae8282008-07-16 19:30:09 +0200619 return 0;
620}
621
622static int adm9240_probe(struct i2c_client *new_client,
623 const struct i2c_device_id *id)
624{
625 struct adm9240_data *data;
626 int err;
627
Guenter Roecke5ebb772012-06-02 09:58:00 -0700628 data = devm_kzalloc(&new_client->dev, sizeof(*data), GFP_KERNEL);
629 if (!data)
630 return -ENOMEM;
Jean Delvare7fae8282008-07-16 19:30:09 +0200631
632 i2c_set_clientdata(new_client, data);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100633 mutex_init(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000634
Grant Coady40b5cda2005-04-30 21:41:29 +1000635 adm9240_init_client(new_client);
636
637 /* populate sysfs filesystem */
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800638 err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group);
639 if (err)
Guenter Roecke5ebb772012-06-02 09:58:00 -0700640 return err;
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200641
Tony Jones1beeffe2007-08-20 13:46:20 -0700642 data->hwmon_dev = hwmon_device_register(&new_client->dev);
643 if (IS_ERR(data->hwmon_dev)) {
644 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200645 goto exit_remove;
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400646 }
647
Grant Coady40b5cda2005-04-30 21:41:29 +1000648 return 0;
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400649
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200650exit_remove:
651 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
Grant Coady40b5cda2005-04-30 21:41:29 +1000652 return err;
653}
654
Jean Delvare7fae8282008-07-16 19:30:09 +0200655static int adm9240_remove(struct i2c_client *client)
Grant Coady40b5cda2005-04-30 21:41:29 +1000656{
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400657 struct adm9240_data *data = i2c_get_clientdata(client);
Grant Coady40b5cda2005-04-30 21:41:29 +1000658
Tony Jones1beeffe2007-08-20 13:46:20 -0700659 hwmon_device_unregister(data->hwmon_dev);
Mark M. Hoffman681c6f72006-09-24 21:15:35 +0200660 sysfs_remove_group(&client->dev.kobj, &adm9240_group);
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400661
Grant Coady40b5cda2005-04-30 21:41:29 +1000662 return 0;
663}
664
665static void adm9240_init_client(struct i2c_client *client)
666{
667 struct adm9240_data *data = i2c_get_clientdata(client);
Grant Coady205cf132005-09-17 05:32:55 +1000668 u8 conf = i2c_smbus_read_byte_data(client, ADM9240_REG_CONFIG);
669 u8 mode = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF) & 3;
Grant Coady40b5cda2005-04-30 21:41:29 +1000670
Jean Delvare303760b2005-07-31 21:52:01 +0200671 data->vrm = vid_which_vrm(); /* need this to report vid as mV */
Grant Coady40b5cda2005-04-30 21:41:29 +1000672
Grant Coady8e8f9282005-05-13 20:26:10 +1000673 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10,
674 data->vrm % 10);
675
Grant Coady40b5cda2005-04-30 21:41:29 +1000676 if (conf & 1) { /* measurement cycle running: report state */
677
678 dev_info(&client->dev, "status: config 0x%02x mode %u\n",
679 conf, mode);
680
681 } else { /* cold start: open limits before starting chip */
682 int i;
683
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800684 for (i = 0; i < 6; i++) {
Grant Coady205cf132005-09-17 05:32:55 +1000685 i2c_smbus_write_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000686 ADM9240_REG_IN_MIN(i), 0);
Grant Coady205cf132005-09-17 05:32:55 +1000687 i2c_smbus_write_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000688 ADM9240_REG_IN_MAX(i), 255);
689 }
Grant Coady205cf132005-09-17 05:32:55 +1000690 i2c_smbus_write_byte_data(client,
691 ADM9240_REG_FAN_MIN(0), 255);
692 i2c_smbus_write_byte_data(client,
693 ADM9240_REG_FAN_MIN(1), 255);
694 i2c_smbus_write_byte_data(client,
Grant Coadyc7461a62005-09-17 05:32:57 +1000695 ADM9240_REG_TEMP_MAX(0), 127);
Grant Coady205cf132005-09-17 05:32:55 +1000696 i2c_smbus_write_byte_data(client,
Grant Coadyc7461a62005-09-17 05:32:57 +1000697 ADM9240_REG_TEMP_MAX(1), 127);
Grant Coady40b5cda2005-04-30 21:41:29 +1000698
699 /* start measurement cycle */
Grant Coady205cf132005-09-17 05:32:55 +1000700 i2c_smbus_write_byte_data(client, ADM9240_REG_CONFIG, 1);
Grant Coady40b5cda2005-04-30 21:41:29 +1000701
702 dev_info(&client->dev, "cold start: config was 0x%02x "
703 "mode %u\n", conf, mode);
704 }
705}
706
707static struct adm9240_data *adm9240_update_device(struct device *dev)
708{
709 struct i2c_client *client = to_i2c_client(dev);
710 struct adm9240_data *data = i2c_get_clientdata(client);
711 int i;
712
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100713 mutex_lock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000714
715 /* minimum measurement cycle: 1.75 seconds */
716 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
717 || !data->valid) {
718
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800719 for (i = 0; i < 6; i++) { /* read voltages */
Grant Coady205cf132005-09-17 05:32:55 +1000720 data->in[i] = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000721 ADM9240_REG_IN(i));
722 }
Grant Coady205cf132005-09-17 05:32:55 +1000723 data->alarms = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000724 ADM9240_REG_INT(0)) |
Grant Coady205cf132005-09-17 05:32:55 +1000725 i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000726 ADM9240_REG_INT(1)) << 8;
727
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800728 /*
729 * read temperature: assume temperature changes less than
Grant Coady40b5cda2005-04-30 21:41:29 +1000730 * 0.5'C per two measurement cycles thus ignore possible
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800731 * but unlikely aliasing error on lsb reading. --Grant
732 */
Grant Coady205cf132005-09-17 05:32:55 +1000733 data->temp = ((i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000734 ADM9240_REG_TEMP) << 8) |
Grant Coady205cf132005-09-17 05:32:55 +1000735 i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000736 ADM9240_REG_TEMP_CONF)) / 128;
737
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800738 for (i = 0; i < 2; i++) { /* read fans */
Grant Coady205cf132005-09-17 05:32:55 +1000739 data->fan[i] = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000740 ADM9240_REG_FAN(i));
741
742 /* adjust fan clock divider on overflow */
743 if (data->valid && data->fan[i] == 255 &&
744 data->fan_div[i] < 3) {
745
746 adm9240_write_fan_div(client, i,
747 ++data->fan_div[i]);
748
749 /* adjust fan_min if active, but not to 0 */
750 if (data->fan_min[i] < 255 &&
751 data->fan_min[i] >= 2)
752 data->fan_min[i] /= 2;
753 }
754 }
755 data->last_updated_measure = jiffies;
756 }
757
758 /* minimum config reading cycle: 300 seconds */
759 if (time_after(jiffies, data->last_updated_config + (HZ * 300))
760 || !data->valid) {
761
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800762 for (i = 0; i < 6; i++) {
Grant Coady205cf132005-09-17 05:32:55 +1000763 data->in_min[i] = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000764 ADM9240_REG_IN_MIN(i));
Grant Coady205cf132005-09-17 05:32:55 +1000765 data->in_max[i] = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000766 ADM9240_REG_IN_MAX(i));
767 }
Guenter Roeckc387e4e2012-01-14 13:12:38 -0800768 for (i = 0; i < 2; i++) {
Grant Coady205cf132005-09-17 05:32:55 +1000769 data->fan_min[i] = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000770 ADM9240_REG_FAN_MIN(i));
771 }
Grant Coadyc7461a62005-09-17 05:32:57 +1000772 data->temp_max[0] = i2c_smbus_read_byte_data(client,
773 ADM9240_REG_TEMP_MAX(0));
774 data->temp_max[1] = i2c_smbus_read_byte_data(client,
775 ADM9240_REG_TEMP_MAX(1));
Grant Coady40b5cda2005-04-30 21:41:29 +1000776
777 /* read fan divs and 5-bit VID */
Grant Coady205cf132005-09-17 05:32:55 +1000778 i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
Grant Coady40b5cda2005-04-30 21:41:29 +1000779 data->fan_div[0] = (i >> 4) & 3;
780 data->fan_div[1] = (i >> 6) & 3;
781 data->vid = i & 0x0f;
Grant Coady205cf132005-09-17 05:32:55 +1000782 data->vid |= (i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000783 ADM9240_REG_VID4) & 1) << 4;
784 /* read analog out */
Grant Coady205cf132005-09-17 05:32:55 +1000785 data->aout = i2c_smbus_read_byte_data(client,
Grant Coady40b5cda2005-04-30 21:41:29 +1000786 ADM9240_REG_ANALOG_OUT);
787
788 data->last_updated_config = jiffies;
789 data->valid = 1;
790 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100791 mutex_unlock(&data->update_lock);
Grant Coady40b5cda2005-04-30 21:41:29 +1000792 return data;
793}
794
Axel Linf0967ee2012-01-20 15:38:18 +0800795module_i2c_driver(adm9240_driver);
Grant Coady40b5cda2005-04-30 21:41:29 +1000796
797MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, "
Grant Coady2ca7b962006-10-08 21:57:41 +0200798 "Grant Coady <gcoady.lk@gmail.com> and others");
Grant Coady40b5cda2005-04-30 21:41:29 +1000799MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver");
800MODULE_LICENSE("GPL");