blob: abd270243ba701d2332977eea1e79f485353a4c0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
Jean Delvare7c81c602014-01-29 20:40:08 +01004 * Copyright (C) 2003-2009 Jean Delvare <jdelvare@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
7 * a sensor chip made by National Semiconductor. It reports up to four
8 * temperatures (its own plus up to three external ones) with a 1 deg
9 * resolution and a 3-4 deg accuracy. Complete datasheet can be obtained
10 * from National's website at:
11 * http://www.national.com/pf/LM/LM83.html
12 * Since the datasheet omits to give the chip stepping code, I give it
13 * here: 0x03 (at register 0xff).
14 *
Jordan Crouse43cb7eb2006-03-23 16:19:49 +010015 * Also supports the LM82 temp sensor, which is basically a stripped down
16 * model of the LM83. Datasheet is here:
17 * http://www.national.com/pf/LM/LM82.html
18 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/jiffies.h>
38#include <linux/i2c.h>
Jean Delvare10c08f82005-06-06 19:34:45 +020039#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040040#include <linux/hwmon.h>
41#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010042#include <linux/mutex.h>
Jean Delvare0e39e012006-09-24 21:16:40 +020043#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/*
46 * Addresses to scan
47 * Address is selected using 2 three-level pins, resulting in 9 possible
48 * addresses.
49 */
50
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050051static const unsigned short normal_i2c[] = {
52 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Jean Delvaree5e9f442009-12-14 21:17:27 +010054enum chips { lm83, lm82 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*
57 * The LM83 registers
58 * Manufacturer ID is 0x01 for National Semiconductor.
59 */
60
61#define LM83_REG_R_MAN_ID 0xFE
62#define LM83_REG_R_CHIP_ID 0xFF
63#define LM83_REG_R_CONFIG 0x03
64#define LM83_REG_W_CONFIG 0x09
65#define LM83_REG_R_STATUS1 0x02
66#define LM83_REG_R_STATUS2 0x35
67#define LM83_REG_R_LOCAL_TEMP 0x00
68#define LM83_REG_R_LOCAL_HIGH 0x05
69#define LM83_REG_W_LOCAL_HIGH 0x0B
70#define LM83_REG_R_REMOTE1_TEMP 0x30
71#define LM83_REG_R_REMOTE1_HIGH 0x38
72#define LM83_REG_W_REMOTE1_HIGH 0x50
73#define LM83_REG_R_REMOTE2_TEMP 0x01
74#define LM83_REG_R_REMOTE2_HIGH 0x07
75#define LM83_REG_W_REMOTE2_HIGH 0x0D
76#define LM83_REG_R_REMOTE3_TEMP 0x31
77#define LM83_REG_R_REMOTE3_HIGH 0x3A
78#define LM83_REG_W_REMOTE3_HIGH 0x52
79#define LM83_REG_R_TCRIT 0x42
80#define LM83_REG_W_TCRIT 0x5A
81
82/*
83 * Conversions and various macros
Steven Cole44bbe872005-05-03 18:21:25 -060084 * The LM83 uses signed 8-bit values with LSB = 1 degree Celsius.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86
87#define TEMP_FROM_REG(val) ((val) * 1000)
88#define TEMP_TO_REG(val) ((val) <= -128000 ? -128 : \
89 (val) >= 127000 ? 127 : \
90 (val) < 0 ? ((val) - 500) / 1000 : \
91 ((val) + 500) / 1000)
92
93static const u8 LM83_REG_R_TEMP[] = {
94 LM83_REG_R_LOCAL_TEMP,
95 LM83_REG_R_REMOTE1_TEMP,
96 LM83_REG_R_REMOTE2_TEMP,
Jean Delvare1a86c052005-06-05 21:16:39 +020097 LM83_REG_R_REMOTE3_TEMP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 LM83_REG_R_LOCAL_HIGH,
99 LM83_REG_R_REMOTE1_HIGH,
100 LM83_REG_R_REMOTE2_HIGH,
Jean Delvare1a86c052005-06-05 21:16:39 +0200101 LM83_REG_R_REMOTE3_HIGH,
102 LM83_REG_R_TCRIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105static const u8 LM83_REG_W_HIGH[] = {
106 LM83_REG_W_LOCAL_HIGH,
107 LM83_REG_W_REMOTE1_HIGH,
108 LM83_REG_W_REMOTE2_HIGH,
Jean Delvare1a86c052005-06-05 21:16:39 +0200109 LM83_REG_W_REMOTE3_HIGH,
110 LM83_REG_W_TCRIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113/*
114 * Functions declaration
115 */
116
Jean Delvare310ec792009-12-14 21:17:23 +0100117static int lm83_detect(struct i2c_client *new_client,
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200118 struct i2c_board_info *info);
119static int lm83_probe(struct i2c_client *client,
120 const struct i2c_device_id *id);
121static int lm83_remove(struct i2c_client *client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static struct lm83_data *lm83_update_device(struct device *dev);
123
124/*
125 * Driver data (common to all clients)
126 */
Frans Meulenbroeksb3789a02012-01-10 23:01:40 +0100127
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200128static const struct i2c_device_id lm83_id[] = {
129 { "lm83", lm83 },
130 { "lm82", lm82 },
131 { }
132};
133MODULE_DEVICE_TABLE(i2c, lm83_id);
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static struct i2c_driver lm83_driver = {
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200136 .class = I2C_CLASS_HWMON,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100137 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100138 .name = "lm83",
139 },
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200140 .probe = lm83_probe,
141 .remove = lm83_remove,
142 .id_table = lm83_id,
143 .detect = lm83_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +0100144 .address_list = normal_i2c,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
147/*
148 * Client data (each client gets its own)
149 */
150
151struct lm83_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700152 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100153 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 char valid; /* zero until following fields are valid */
155 unsigned long last_updated; /* in jiffies */
156
157 /* registers values */
Jean Delvare1a86c052005-06-05 21:16:39 +0200158 s8 temp[9]; /* 0..3: input 1-4,
159 4..7: high limit 1-4,
160 8 : critical limit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 u16 alarms; /* bitvector, combined */
162};
163
164/*
165 * Sysfs stuff
166 */
167
Jean Delvare1a86c052005-06-05 21:16:39 +0200168static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
169 char *buf)
170{
171 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
172 struct lm83_data *data = lm83_update_device(dev);
173 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Jean Delvare1a86c052005-06-05 21:16:39 +0200176static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
177 const char *buf, size_t count)
178{
179 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
180 struct i2c_client *client = to_i2c_client(dev);
181 struct lm83_data *data = i2c_get_clientdata(client);
Frans Meulenbroeksb3789a02012-01-10 23:01:40 +0100182 long val;
Jean Delvare1a86c052005-06-05 21:16:39 +0200183 int nr = attr->index;
Frans Meulenbroeksb3789a02012-01-10 23:01:40 +0100184 int err;
185
186 err = kstrtol(buf, 10, &val);
187 if (err < 0)
188 return err;
Jean Delvare1a86c052005-06-05 21:16:39 +0200189
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100190 mutex_lock(&data->update_lock);
Jean Delvare1a86c052005-06-05 21:16:39 +0200191 data->temp[nr] = TEMP_TO_REG(val);
192 i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4],
193 data->temp[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100194 mutex_unlock(&data->update_lock);
Jean Delvare1a86c052005-06-05 21:16:39 +0200195 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Jean Delvare1a86c052005-06-05 21:16:39 +0200198static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
199 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 struct lm83_data *data = lm83_update_device(dev);
202 return sprintf(buf, "%d\n", data->alarms);
203}
204
Jean Delvare2d457712006-09-24 20:52:15 +0200205static ssize_t show_alarm(struct device *dev, struct device_attribute
206 *devattr, char *buf)
207{
208 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
209 struct lm83_data *data = lm83_update_device(dev);
210 int bitnr = attr->index;
211
212 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
213}
214
Jean Delvare1a86c052005-06-05 21:16:39 +0200215static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
216static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
217static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
218static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
219static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp,
220 set_temp, 4);
221static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp,
222 set_temp, 5);
223static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp,
224 set_temp, 6);
225static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp,
226 set_temp, 7);
227static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, 8);
228static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp, NULL, 8);
229static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
230 set_temp, 8);
231static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8);
Jean Delvare2d457712006-09-24 20:52:15 +0200232
233/* Individual alarm files */
234static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
235static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
Jean Delvare7817a392007-06-09 10:11:16 -0400236static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2);
Jean Delvare2d457712006-09-24 20:52:15 +0200237static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4);
238static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
239static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8);
240static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
Jean Delvare7817a392007-06-09 10:11:16 -0400241static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, 10);
Jean Delvare2d457712006-09-24 20:52:15 +0200242static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12);
Jean Delvare7817a392007-06-09 10:11:16 -0400243static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 13);
Jean Delvare2d457712006-09-24 20:52:15 +0200244static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15);
245/* Raw alarm file for compatibility */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
247
Jean Delvare0e39e012006-09-24 21:16:40 +0200248static struct attribute *lm83_attributes[] = {
249 &sensor_dev_attr_temp1_input.dev_attr.attr,
250 &sensor_dev_attr_temp3_input.dev_attr.attr,
251 &sensor_dev_attr_temp1_max.dev_attr.attr,
252 &sensor_dev_attr_temp3_max.dev_attr.attr,
253 &sensor_dev_attr_temp1_crit.dev_attr.attr,
254 &sensor_dev_attr_temp3_crit.dev_attr.attr,
255
256 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
257 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -0400258 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200259 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
260 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
261 &dev_attr_alarms.attr,
262 NULL
263};
264
265static const struct attribute_group lm83_group = {
266 .attrs = lm83_attributes,
267};
268
269static struct attribute *lm83_attributes_opt[] = {
270 &sensor_dev_attr_temp2_input.dev_attr.attr,
271 &sensor_dev_attr_temp4_input.dev_attr.attr,
272 &sensor_dev_attr_temp2_max.dev_attr.attr,
273 &sensor_dev_attr_temp4_max.dev_attr.attr,
274 &sensor_dev_attr_temp2_crit.dev_attr.attr,
275 &sensor_dev_attr_temp4_crit.dev_attr.attr,
276
277 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
278 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -0400279 &sensor_dev_attr_temp4_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200280 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -0400281 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200282 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
283 NULL
284};
285
286static const struct attribute_group lm83_group_opt = {
287 .attrs = lm83_attributes_opt,
288};
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*
291 * Real code
292 */
293
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200294/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +0100295static int lm83_detect(struct i2c_client *new_client,
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200296 struct i2c_board_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200298 struct i2c_adapter *adapter = new_client->adapter;
Jean Delvareb57dc392009-12-09 20:35:52 +0100299 const char *name;
300 u8 man_id, chip_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200303 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Jean Delvareb57dc392009-12-09 20:35:52 +0100305 /* Detection */
306 if ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1) & 0xA8) ||
307 (i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2) & 0x48) ||
308 (i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) & 0x41)) {
309 dev_dbg(&adapter->dev, "LM83 detection failed at 0x%02x\n",
310 new_client->addr);
311 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313
Jean Delvareb57dc392009-12-09 20:35:52 +0100314 /* Identification */
315 man_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_MAN_ID);
316 if (man_id != 0x01) /* National Semiconductor */
317 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Jean Delvareb57dc392009-12-09 20:35:52 +0100319 chip_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_CHIP_ID);
320 switch (chip_id) {
321 case 0x03:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 name = "lm83";
Jean Delvareb57dc392009-12-09 20:35:52 +0100323 break;
324 case 0x01:
Jordan Crouse43cb7eb2006-03-23 16:19:49 +0100325 name = "lm82";
Jean Delvareb57dc392009-12-09 20:35:52 +0100326 break;
327 default:
328 /* identification failed */
329 dev_info(&adapter->dev,
330 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
331 man_id, chip_id);
332 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200335 strlcpy(info->type, name, I2C_NAME_SIZE);
336
337 return 0;
338}
339
340static int lm83_probe(struct i2c_client *new_client,
341 const struct i2c_device_id *id)
342{
343 struct lm83_data *data;
344 int err;
345
Guenter Roeckc087f732012-06-02 09:58:10 -0700346 data = devm_kzalloc(&new_client->dev, sizeof(struct lm83_data),
347 GFP_KERNEL);
348 if (!data)
349 return -ENOMEM;
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200350
351 i2c_set_clientdata(new_client, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 data->valid = 0;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100353 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /*
Jean Delvare0e39e012006-09-24 21:16:40 +0200356 * Register sysfs hooks
Jordan Crouse43cb7eb2006-03-23 16:19:49 +0100357 * The LM82 can only monitor one external diode which is
358 * at the same register as the LM83 temp3 entry - so we
359 * declare 1 and 3 common, and then 2 and 4 only for the LM83.
360 */
361
Frans Meulenbroeksb3789a02012-01-10 23:01:40 +0100362 err = sysfs_create_group(&new_client->dev.kobj, &lm83_group);
363 if (err)
Guenter Roeckc087f732012-06-02 09:58:10 -0700364 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200366 if (id->driver_data == lm83) {
Frans Meulenbroeksb3789a02012-01-10 23:01:40 +0100367 err = sysfs_create_group(&new_client->dev.kobj,
368 &lm83_group_opt);
369 if (err)
Jean Delvare0e39e012006-09-24 21:16:40 +0200370 goto exit_remove_files;
371 }
Jordan Crouse43cb7eb2006-03-23 16:19:49 +0100372
Tony Jones1beeffe2007-08-20 13:46:20 -0700373 data->hwmon_dev = hwmon_device_register(&new_client->dev);
374 if (IS_ERR(data->hwmon_dev)) {
375 err = PTR_ERR(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +0200376 goto exit_remove_files;
Jordan Crouse43cb7eb2006-03-23 16:19:49 +0100377 }
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return 0;
380
Jean Delvare0e39e012006-09-24 21:16:40 +0200381exit_remove_files:
382 sysfs_remove_group(&new_client->dev.kobj, &lm83_group);
383 sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return err;
385}
386
Jean Delvareb6aacdc2008-07-16 19:30:14 +0200387static int lm83_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400389 struct lm83_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Tony Jones1beeffe2007-08-20 13:46:20 -0700391 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +0200392 sysfs_remove_group(&client->dev.kobj, &lm83_group);
393 sysfs_remove_group(&client->dev.kobj, &lm83_group_opt);
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return 0;
396}
397
398static struct lm83_data *lm83_update_device(struct device *dev)
399{
400 struct i2c_client *client = to_i2c_client(dev);
401 struct lm83_data *data = i2c_get_clientdata(client);
402
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100403 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
406 int nr;
407
408 dev_dbg(&client->dev, "Updating lm83 data.\n");
Jean Delvare1a86c052005-06-05 21:16:39 +0200409 for (nr = 0; nr < 9; nr++) {
410 data->temp[nr] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 i2c_smbus_read_byte_data(client,
412 LM83_REG_R_TEMP[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 data->alarms =
415 i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS1)
416 + (i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS2)
417 << 8);
418
419 data->last_updated = jiffies;
420 data->valid = 1;
421 }
422
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100423 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 return data;
426}
427
Axel Linf0967ee2012-01-20 15:38:18 +0800428module_i2c_driver(lm83_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Jean Delvare7c81c602014-01-29 20:40:08 +0100430MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431MODULE_DESCRIPTION("LM83 driver");
432MODULE_LICENSE("GPL");