aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm80.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-01-05 09:37:05 -0500
committerMark M. Hoffman <mhoffman@lightlink.com>2008-02-07 20:39:45 -0500
commitf8181762a04a3ff7878d3ec5c013bce9c771d4f7 (patch)
treedfb412ff564775da37265495e5a58c1a1674ec45 /drivers/hwmon/lm80.c
parent6cc37ee536bb90c428c8a7cde91f33ffe1fd27bd (diff)
hwmon: (lm80) De-macro the sysfs callbacks
Use standard dynamic sysfs callbacks instead of macro-generated functions. This makes the code more readable, and the binary smaller (by about 34%). As a side note, another benefit of this type of cleanup is that they shrink the build time. For example, this cleanup saves about 29% of the lm80 driver build time. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/lm80.c')
-rw-r--r--drivers/hwmon/lm80.c247
1 files changed, 112 insertions, 135 deletions
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 32dfdf38b161..612807c786e2 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -27,6 +27,7 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/err.h> 31#include <linux/err.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32 33
@@ -158,105 +159,74 @@ static struct i2c_driver lm80_driver = {
158#define show_in(suffix, value) \ 159#define show_in(suffix, value) \
159static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 160static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
160{ \ 161{ \
162 int nr = to_sensor_dev_attr(attr)->index; \
161 struct lm80_data *data = lm80_update_device(dev); \ 163 struct lm80_data *data = lm80_update_device(dev); \
162 return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \ 164 return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \
163} 165}
164show_in(min0, in_min[0]); 166show_in(min, in_min)
165show_in(min1, in_min[1]); 167show_in(max, in_max)
166show_in(min2, in_min[2]); 168show_in(input, in)
167show_in(min3, in_min[3]);
168show_in(min4, in_min[4]);
169show_in(min5, in_min[5]);
170show_in(min6, in_min[6]);
171show_in(max0, in_max[0]);
172show_in(max1, in_max[1]);
173show_in(max2, in_max[2]);
174show_in(max3, in_max[3]);
175show_in(max4, in_max[4]);
176show_in(max5, in_max[5]);
177show_in(max6, in_max[6]);
178show_in(input0, in[0]);
179show_in(input1, in[1]);
180show_in(input2, in[2]);
181show_in(input3, in[3]);
182show_in(input4, in[4]);
183show_in(input5, in[5]);
184show_in(input6, in[6]);
185 169
186#define set_in(suffix, value, reg) \ 170#define set_in(suffix, value, reg) \
187static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 171static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \
188 size_t count) \ 172 size_t count) \
189{ \ 173{ \
174 int nr = to_sensor_dev_attr(attr)->index; \
190 struct i2c_client *client = to_i2c_client(dev); \ 175 struct i2c_client *client = to_i2c_client(dev); \
191 struct lm80_data *data = i2c_get_clientdata(client); \ 176 struct lm80_data *data = i2c_get_clientdata(client); \
192 long val = simple_strtol(buf, NULL, 10); \ 177 long val = simple_strtol(buf, NULL, 10); \
193 \ 178 \
194 mutex_lock(&data->update_lock);\ 179 mutex_lock(&data->update_lock);\
195 data->value = IN_TO_REG(val); \ 180 data->value[nr] = IN_TO_REG(val); \
196 lm80_write_value(client, reg, data->value); \ 181 lm80_write_value(client, reg(nr), data->value[nr]); \
197 mutex_unlock(&data->update_lock);\ 182 mutex_unlock(&data->update_lock);\
198 return count; \ 183 return count; \
199} 184}
200set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); 185set_in(min, in_min, LM80_REG_IN_MIN)
201set_in(min1, in_min[1], LM80_REG_IN_MIN(1)); 186set_in(max, in_max, LM80_REG_IN_MAX)
202set_in(min2, in_min[2], LM80_REG_IN_MIN(2)); 187
203set_in(min3, in_min[3], LM80_REG_IN_MIN(3)); 188#define show_fan(suffix, value) \
204set_in(min4, in_min[4], LM80_REG_IN_MIN(4));
205set_in(min5, in_min[5], LM80_REG_IN_MIN(5));
206set_in(min6, in_min[6], LM80_REG_IN_MIN(6));
207set_in(max0, in_max[0], LM80_REG_IN_MAX(0));
208set_in(max1, in_max[1], LM80_REG_IN_MAX(1));
209set_in(max2, in_max[2], LM80_REG_IN_MAX(2));
210set_in(max3, in_max[3], LM80_REG_IN_MAX(3));
211set_in(max4, in_max[4], LM80_REG_IN_MAX(4));
212set_in(max5, in_max[5], LM80_REG_IN_MAX(5));
213set_in(max6, in_max[6], LM80_REG_IN_MAX(6));
214
215#define show_fan(suffix, value, div) \
216static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 189static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
217{ \ 190{ \
191 int nr = to_sensor_dev_attr(attr)->index; \
218 struct lm80_data *data = lm80_update_device(dev); \ 192 struct lm80_data *data = lm80_update_device(dev); \
219 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \ 193 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \
220 DIV_FROM_REG(data->div))); \ 194 DIV_FROM_REG(data->fan_div[nr]))); \
221} 195}
222show_fan(min1, fan_min[0], fan_div[0]); 196show_fan(min, fan_min)
223show_fan(min2, fan_min[1], fan_div[1]); 197show_fan(input, fan)
224show_fan(input1, fan[0], fan_div[0]);
225show_fan(input2, fan[1], fan_div[1]);
226 198
227#define show_fan_div(suffix, value) \ 199static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
228static ssize_t show_fan_div##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 200 char *buf)
229{ \ 201{
230 struct lm80_data *data = lm80_update_device(dev); \ 202 int nr = to_sensor_dev_attr(attr)->index;
231 return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \ 203 struct lm80_data *data = lm80_update_device(dev);
204 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
232} 205}
233show_fan_div(1, fan_div[0]);
234show_fan_div(2, fan_div[1]);
235 206
236#define set_fan(suffix, value, reg, div) \ 207static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
237static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 208 const char *buf, size_t count)
238 size_t count) \ 209{
239{ \ 210 int nr = to_sensor_dev_attr(attr)->index;
240 struct i2c_client *client = to_i2c_client(dev); \ 211 struct i2c_client *client = to_i2c_client(dev);
241 struct lm80_data *data = i2c_get_clientdata(client); \ 212 struct lm80_data *data = i2c_get_clientdata(client);
242 long val = simple_strtoul(buf, NULL, 10); \ 213 long val = simple_strtoul(buf, NULL, 10);
243 \ 214
244 mutex_lock(&data->update_lock);\ 215 mutex_lock(&data->update_lock);
245 data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ 216 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
246 lm80_write_value(client, reg, data->value); \ 217 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
247 mutex_unlock(&data->update_lock);\ 218 mutex_unlock(&data->update_lock);
248 return count; \ 219 return count;
249} 220}
250set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
251set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]);
252 221
253/* Note: we save and restore the fan minimum here, because its value is 222/* Note: we save and restore the fan minimum here, because its value is
254 determined in part by the fan divisor. This follows the principle of 223 determined in part by the fan divisor. This follows the principle of
255 least surprise; the user doesn't expect the fan minimum to change just 224 least surprise; the user doesn't expect the fan minimum to change just
256 because the divisor changed. */ 225 because the divisor changed. */
257static ssize_t set_fan_div(struct device *dev, const char *buf, 226static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
258 size_t count, int nr) 227 const char *buf, size_t count)
259{ 228{
229 int nr = to_sensor_dev_attr(attr)->index;
260 struct i2c_client *client = to_i2c_client(dev); 230 struct i2c_client *client = to_i2c_client(dev);
261 struct lm80_data *data = i2c_get_clientdata(client); 231 struct lm80_data *data = i2c_get_clientdata(client);
262 unsigned long min, val = simple_strtoul(buf, NULL, 10); 232 unsigned long min, val = simple_strtoul(buf, NULL, 10);
@@ -291,15 +261,6 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
291 return count; 261 return count;
292} 262}
293 263
294#define set_fan_div(number) \
295static ssize_t set_fan_div##number(struct device *dev, struct device_attribute *attr, const char *buf, \
296 size_t count) \
297{ \
298 return set_fan_div(dev, buf, count, number - 1); \
299}
300set_fan_div(1);
301set_fan_div(2);
302
303static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) 264static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf)
304{ 265{
305 struct lm80_data *data = lm80_update_device(dev); 266 struct lm80_data *data = lm80_update_device(dev);
@@ -343,35 +304,51 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
343 return sprintf(buf, "%u\n", data->alarms); 304 return sprintf(buf, "%u\n", data->alarms);
344} 305}
345 306
346static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0); 307static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
347static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1); 308 show_in_min, set_in_min, 0);
348static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2); 309static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
349static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3); 310 show_in_min, set_in_min, 1);
350static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4); 311static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
351static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5); 312 show_in_min, set_in_min, 2);
352static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6); 313static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
353static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0); 314 show_in_min, set_in_min, 3);
354static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1); 315static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
355static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2); 316 show_in_min, set_in_min, 4);
356static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3); 317static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
357static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4); 318 show_in_min, set_in_min, 5);
358static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5); 319static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
359static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6); 320 show_in_min, set_in_min, 6);
360static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); 321static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
361static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); 322 show_in_max, set_in_max, 0);
362static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); 323static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
363static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL); 324 show_in_max, set_in_max, 1);
364static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL); 325static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
365static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL); 326 show_in_max, set_in_max, 2);
366static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL); 327static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
367static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1, 328 show_in_max, set_in_max, 3);
368 set_fan_min1); 329static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
369static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2, 330 show_in_max, set_in_max, 4);
370 set_fan_min2); 331static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
371static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); 332 show_in_max, set_in_max, 5);
372static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); 333static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
373static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1); 334 show_in_max, set_in_max, 6);
374static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2); 335static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0);
336static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1);
337static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2);
338static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3);
339static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4);
340static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5);
341static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6);
342static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
343 show_fan_min, set_fan_min, 0);
344static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
345 show_fan_min, set_fan_min, 1);
346static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
347static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
348static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
349 show_fan_div, set_fan_div, 0);
350static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
351 show_fan_div, set_fan_div, 1);
375static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); 352static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
376static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, 353static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max,
377 set_temp_hot_max); 354 set_temp_hot_max);
@@ -395,33 +372,33 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
395} 372}
396 373
397static struct attribute *lm80_attributes[] = { 374static struct attribute *lm80_attributes[] = {
398 &dev_attr_in0_min.attr, 375 &sensor_dev_attr_in0_min.dev_attr.attr,
399 &dev_attr_in1_min.attr, 376 &sensor_dev_attr_in1_min.dev_attr.attr,
400 &dev_attr_in2_min.attr, 377 &sensor_dev_attr_in2_min.dev_attr.attr,
401 &dev_attr_in3_min.attr, 378 &sensor_dev_attr_in3_min.dev_attr.attr,
402 &dev_attr_in4_min.attr, 379 &sensor_dev_attr_in4_min.dev_attr.attr,
403 &dev_attr_in5_min.attr, 380 &sensor_dev_attr_in5_min.dev_attr.attr,
404 &dev_attr_in6_min.attr, 381 &sensor_dev_attr_in6_min.dev_attr.attr,
405 &dev_attr_in0_max.attr, 382 &sensor_dev_attr_in0_max.dev_attr.attr,
406 &dev_attr_in1_max.attr, 383 &sensor_dev_attr_in1_max.dev_attr.attr,
407 &dev_attr_in2_max.attr, 384 &sensor_dev_attr_in2_max.dev_attr.attr,
408 &dev_attr_in3_max.attr, 385 &sensor_dev_attr_in3_max.dev_attr.attr,
409 &dev_attr_in4_max.attr, 386 &sensor_dev_attr_in4_max.dev_attr.attr,
410 &dev_attr_in5_max.attr, 387 &sensor_dev_attr_in5_max.dev_attr.attr,
411 &dev_attr_in6_max.attr, 388 &sensor_dev_attr_in6_max.dev_attr.attr,
412 &dev_attr_in0_input.attr, 389 &sensor_dev_attr_in0_input.dev_attr.attr,
413 &dev_attr_in1_input.attr, 390 &sensor_dev_attr_in1_input.dev_attr.attr,
414 &dev_attr_in2_input.attr, 391 &sensor_dev_attr_in2_input.dev_attr.attr,
415 &dev_attr_in3_input.attr, 392 &sensor_dev_attr_in3_input.dev_attr.attr,
416 &dev_attr_in4_input.attr, 393 &sensor_dev_attr_in4_input.dev_attr.attr,
417 &dev_attr_in5_input.attr, 394 &sensor_dev_attr_in5_input.dev_attr.attr,
418 &dev_attr_in6_input.attr, 395 &sensor_dev_attr_in6_input.dev_attr.attr,
419 &dev_attr_fan1_min.attr, 396 &sensor_dev_attr_fan1_min.dev_attr.attr,
420 &dev_attr_fan2_min.attr, 397 &sensor_dev_attr_fan2_min.dev_attr.attr,
421 &dev_attr_fan1_input.attr, 398 &sensor_dev_attr_fan1_input.dev_attr.attr,
422 &dev_attr_fan2_input.attr, 399 &sensor_dev_attr_fan2_input.dev_attr.attr,
423 &dev_attr_fan1_div.attr, 400 &sensor_dev_attr_fan1_div.dev_attr.attr,
424 &dev_attr_fan2_div.attr, 401 &sensor_dev_attr_fan2_div.dev_attr.attr,
425 &dev_attr_temp1_input.attr, 402 &dev_attr_temp1_input.attr,
426 &dev_attr_temp1_max.attr, 403 &dev_attr_temp1_max.attr,
427 &dev_attr_temp1_max_hyst.attr, 404 &dev_attr_temp1_max_hyst.attr,