aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2005-06-05 15:16:39 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-22 00:52:04 -0400
commit1a86c05121a3f56b4b928ed43f9f8ffc1376d802 (patch)
tree5ae73589d53ccadec32b90305988828f530efc04 /drivers
parent30d7394b1a3df0e7cc145a543846109babd4d53b (diff)
[PATCH] I2C: lm83 uses new sysfs callbacks
I updated the lm83 hardware monitoring driver to take benefit of Yani Ioannou's new sysfs callback capabilities. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/chips/lm83.c157
1 files changed, 77 insertions, 80 deletions
diff --git a/drivers/i2c/chips/lm83.c b/drivers/i2c/chips/lm83.c
index 442dc17cdb77..0e0eae4dceaa 100644
--- a/drivers/i2c/chips/lm83.c
+++ b/drivers/i2c/chips/lm83.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is 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 7 * a sensor chip made by National Semiconductor. It reports up to four
@@ -33,6 +33,7 @@
33#include <linux/jiffies.h> 33#include <linux/jiffies.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <linux/i2c-sensor.h> 35#include <linux/i2c-sensor.h>
36#include <linux/i2c-sysfs.h>
36 37
37/* 38/*
38 * Addresses to scan 39 * Addresses to scan
@@ -93,21 +94,20 @@ static const u8 LM83_REG_R_TEMP[] = {
93 LM83_REG_R_LOCAL_TEMP, 94 LM83_REG_R_LOCAL_TEMP,
94 LM83_REG_R_REMOTE1_TEMP, 95 LM83_REG_R_REMOTE1_TEMP,
95 LM83_REG_R_REMOTE2_TEMP, 96 LM83_REG_R_REMOTE2_TEMP,
96 LM83_REG_R_REMOTE3_TEMP 97 LM83_REG_R_REMOTE3_TEMP,
97};
98
99static const u8 LM83_REG_R_HIGH[] = {
100 LM83_REG_R_LOCAL_HIGH, 98 LM83_REG_R_LOCAL_HIGH,
101 LM83_REG_R_REMOTE1_HIGH, 99 LM83_REG_R_REMOTE1_HIGH,
102 LM83_REG_R_REMOTE2_HIGH, 100 LM83_REG_R_REMOTE2_HIGH,
103 LM83_REG_R_REMOTE3_HIGH 101 LM83_REG_R_REMOTE3_HIGH,
102 LM83_REG_R_TCRIT,
104}; 103};
105 104
106static const u8 LM83_REG_W_HIGH[] = { 105static const u8 LM83_REG_W_HIGH[] = {
107 LM83_REG_W_LOCAL_HIGH, 106 LM83_REG_W_LOCAL_HIGH,
108 LM83_REG_W_REMOTE1_HIGH, 107 LM83_REG_W_REMOTE1_HIGH,
109 LM83_REG_W_REMOTE2_HIGH, 108 LM83_REG_W_REMOTE2_HIGH,
110 LM83_REG_W_REMOTE3_HIGH 109 LM83_REG_W_REMOTE3_HIGH,
110 LM83_REG_W_TCRIT,
111}; 111};
112 112
113/* 113/*
@@ -143,9 +143,9 @@ struct lm83_data {
143 unsigned long last_updated; /* in jiffies */ 143 unsigned long last_updated; /* in jiffies */
144 144
145 /* registers values */ 145 /* registers values */
146 s8 temp_input[4]; 146 s8 temp[9]; /* 0..3: input 1-4,
147 s8 temp_high[4]; 147 4..7: high limit 1-4,
148 s8 temp_crit; 148 8 : critical limit */
149 u16 alarms; /* bitvector, combined */ 149 u16 alarms; /* bitvector, combined */
150}; 150};
151 151
@@ -153,65 +153,55 @@ struct lm83_data {
153 * Sysfs stuff 153 * Sysfs stuff
154 */ 154 */
155 155
156#define show_temp(suffix, value) \ 156static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
157static ssize_t show_temp_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 157 char *buf)
158{ \ 158{
159 struct lm83_data *data = lm83_update_device(dev); \ 159 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
160 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ 160 struct lm83_data *data = lm83_update_device(dev);
161 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
161} 162}
162show_temp(input1, temp_input[0]); 163
163show_temp(input2, temp_input[1]); 164static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
164show_temp(input3, temp_input[2]); 165 const char *buf, size_t count)
165show_temp(input4, temp_input[3]); 166{
166show_temp(high1, temp_high[0]); 167 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
167show_temp(high2, temp_high[1]); 168 struct i2c_client *client = to_i2c_client(dev);
168show_temp(high3, temp_high[2]); 169 struct lm83_data *data = i2c_get_clientdata(client);
169show_temp(high4, temp_high[3]); 170 long val = simple_strtol(buf, NULL, 10);
170show_temp(crit, temp_crit); 171 int nr = attr->index;
171 172
172#define set_temp(suffix, value, reg) \ 173 down(&data->update_lock);
173static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 174 data->temp[nr] = TEMP_TO_REG(val);
174 size_t count) \ 175 i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4],
175{ \ 176 data->temp[nr]);
176 struct i2c_client *client = to_i2c_client(dev); \ 177 up(&data->update_lock);
177 struct lm83_data *data = i2c_get_clientdata(client); \ 178 return count;
178 long val = simple_strtol(buf, NULL, 10); \
179 \
180 down(&data->update_lock); \
181 data->value = TEMP_TO_REG(val); \
182 i2c_smbus_write_byte_data(client, reg, data->value); \
183 up(&data->update_lock); \
184 return count; \
185} 179}
186set_temp(high1, temp_high[0], LM83_REG_W_LOCAL_HIGH);
187set_temp(high2, temp_high[1], LM83_REG_W_REMOTE1_HIGH);
188set_temp(high3, temp_high[2], LM83_REG_W_REMOTE2_HIGH);
189set_temp(high4, temp_high[3], LM83_REG_W_REMOTE3_HIGH);
190set_temp(crit, temp_crit, LM83_REG_W_TCRIT);
191 180
192static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 181static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
182 char *buf)
193{ 183{
194 struct lm83_data *data = lm83_update_device(dev); 184 struct lm83_data *data = lm83_update_device(dev);
195 return sprintf(buf, "%d\n", data->alarms); 185 return sprintf(buf, "%d\n", data->alarms);
196} 186}
197 187
198static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); 188static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
199static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input2, NULL); 189static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
200static DEVICE_ATTR(temp3_input, S_IRUGO, show_temp_input3, NULL); 190static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
201static DEVICE_ATTR(temp4_input, S_IRUGO, show_temp_input4, NULL); 191static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
202static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_high1, 192static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp,
203 set_temp_high1); 193 set_temp, 4);
204static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_high2, 194static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp,
205 set_temp_high2); 195 set_temp, 5);
206static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_high3, 196static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp,
207 set_temp_high3); 197 set_temp, 6);
208static DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_high4, 198static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp,
209 set_temp_high4); 199 set_temp, 7);
210static DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL); 200static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, 8);
211static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit, NULL); 201static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp, NULL, 8);
212static DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp_crit, 202static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
213 set_temp_crit); 203 set_temp, 8);
214static DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp_crit, NULL); 204static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8);
215static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 205static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
216 206
217/* 207/*
@@ -322,18 +312,30 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
322 */ 312 */
323 313
324 /* Register sysfs hooks */ 314 /* Register sysfs hooks */
325 device_create_file(&new_client->dev, &dev_attr_temp1_input); 315 device_create_file(&new_client->dev,
326 device_create_file(&new_client->dev, &dev_attr_temp2_input); 316 &sensor_dev_attr_temp1_input.dev_attr);
327 device_create_file(&new_client->dev, &dev_attr_temp3_input); 317 device_create_file(&new_client->dev,
328 device_create_file(&new_client->dev, &dev_attr_temp4_input); 318 &sensor_dev_attr_temp2_input.dev_attr);
329 device_create_file(&new_client->dev, &dev_attr_temp1_max); 319 device_create_file(&new_client->dev,
330 device_create_file(&new_client->dev, &dev_attr_temp2_max); 320 &sensor_dev_attr_temp3_input.dev_attr);
331 device_create_file(&new_client->dev, &dev_attr_temp3_max); 321 device_create_file(&new_client->dev,
332 device_create_file(&new_client->dev, &dev_attr_temp4_max); 322 &sensor_dev_attr_temp4_input.dev_attr);
333 device_create_file(&new_client->dev, &dev_attr_temp1_crit); 323 device_create_file(&new_client->dev,
334 device_create_file(&new_client->dev, &dev_attr_temp2_crit); 324 &sensor_dev_attr_temp1_max.dev_attr);
335 device_create_file(&new_client->dev, &dev_attr_temp3_crit); 325 device_create_file(&new_client->dev,
336 device_create_file(&new_client->dev, &dev_attr_temp4_crit); 326 &sensor_dev_attr_temp2_max.dev_attr);
327 device_create_file(&new_client->dev,
328 &sensor_dev_attr_temp3_max.dev_attr);
329 device_create_file(&new_client->dev,
330 &sensor_dev_attr_temp4_max.dev_attr);
331 device_create_file(&new_client->dev,
332 &sensor_dev_attr_temp1_crit.dev_attr);
333 device_create_file(&new_client->dev,
334 &sensor_dev_attr_temp2_crit.dev_attr);
335 device_create_file(&new_client->dev,
336 &sensor_dev_attr_temp3_crit.dev_attr);
337 device_create_file(&new_client->dev,
338 &sensor_dev_attr_temp4_crit.dev_attr);
337 device_create_file(&new_client->dev, &dev_attr_alarms); 339 device_create_file(&new_client->dev, &dev_attr_alarms);
338 340
339 return 0; 341 return 0;
@@ -369,16 +371,11 @@ static struct lm83_data *lm83_update_device(struct device *dev)
369 int nr; 371 int nr;
370 372
371 dev_dbg(&client->dev, "Updating lm83 data.\n"); 373 dev_dbg(&client->dev, "Updating lm83 data.\n");
372 for (nr = 0; nr < 4 ; nr++) { 374 for (nr = 0; nr < 9; nr++) {
373 data->temp_input[nr] = 375 data->temp[nr] =
374 i2c_smbus_read_byte_data(client, 376 i2c_smbus_read_byte_data(client,
375 LM83_REG_R_TEMP[nr]); 377 LM83_REG_R_TEMP[nr]);
376 data->temp_high[nr] =
377 i2c_smbus_read_byte_data(client,
378 LM83_REG_R_HIGH[nr]);
379 } 378 }
380 data->temp_crit =
381 i2c_smbus_read_byte_data(client, LM83_REG_R_TCRIT);
382 data->alarms = 379 data->alarms =
383 i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS1) 380 i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS1)
384 + (i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS2) 381 + (i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS2)