aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-06-09 10:11:16 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-07-19 14:22:14 -0400
commit1f5f48dde709ae6951a2f1e044c21f5641684b0a (patch)
treedbbe954326e8ed7a4436093510d8b8e5f43ddb1b /drivers/hwmon
parent17e7dc4373dfcf2a3058d307665263df29dd5fe7 (diff)
hwmon/sis5595: Use dynamic sysfs callbacks
This lets us get rid of macro-generated functions and shrinks the driver size by about 7%. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/sis5595.c184
1 files changed, 78 insertions, 106 deletions
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index c56bae3bd4c7..cf31b4ba65ed 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -56,6 +56,7 @@
56#include <linux/pci.h> 56#include <linux/pci.h>
57#include <linux/platform_device.h> 57#include <linux/platform_device.h>
58#include <linux/hwmon.h> 58#include <linux/hwmon.h>
59#include <linux/hwmon-sysfs.h>
59#include <linux/err.h> 60#include <linux/err.h>
60#include <linux/init.h> 61#include <linux/init.h>
61#include <linux/jiffies.h> 62#include <linux/jiffies.h>
@@ -204,28 +205,39 @@ static struct platform_driver sis5595_driver = {
204}; 205};
205 206
206/* 4 Voltages */ 207/* 4 Voltages */
207static ssize_t show_in(struct device *dev, char *buf, int nr) 208static ssize_t show_in(struct device *dev, struct device_attribute *da,
209 char *buf)
208{ 210{
209 struct sis5595_data *data = sis5595_update_device(dev); 211 struct sis5595_data *data = sis5595_update_device(dev);
212 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
213 int nr = attr->index;
210 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 214 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
211} 215}
212 216
213static ssize_t show_in_min(struct device *dev, char *buf, int nr) 217static ssize_t show_in_min(struct device *dev, struct device_attribute *da,
218 char *buf)
214{ 219{
215 struct sis5595_data *data = sis5595_update_device(dev); 220 struct sis5595_data *data = sis5595_update_device(dev);
221 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
222 int nr = attr->index;
216 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 223 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
217} 224}
218 225
219static ssize_t show_in_max(struct device *dev, char *buf, int nr) 226static ssize_t show_in_max(struct device *dev, struct device_attribute *da,
227 char *buf)
220{ 228{
221 struct sis5595_data *data = sis5595_update_device(dev); 229 struct sis5595_data *data = sis5595_update_device(dev);
230 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
231 int nr = attr->index;
222 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 232 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
223} 233}
224 234
225static ssize_t set_in_min(struct device *dev, const char *buf, 235static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
226 size_t count, int nr) 236 const char *buf, size_t count)
227{ 237{
228 struct sis5595_data *data = dev_get_drvdata(dev); 238 struct sis5595_data *data = dev_get_drvdata(dev);
239 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
240 int nr = attr->index;
229 unsigned long val = simple_strtoul(buf, NULL, 10); 241 unsigned long val = simple_strtoul(buf, NULL, 10);
230 242
231 mutex_lock(&data->update_lock); 243 mutex_lock(&data->update_lock);
@@ -235,10 +247,12 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
235 return count; 247 return count;
236} 248}
237 249
238static ssize_t set_in_max(struct device *dev, const char *buf, 250static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
239 size_t count, int nr) 251 const char *buf, size_t count)
240{ 252{
241 struct sis5595_data *data = dev_get_drvdata(dev); 253 struct sis5595_data *data = dev_get_drvdata(dev);
254 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
255 int nr = attr->index;
242 unsigned long val = simple_strtoul(buf, NULL, 10); 256 unsigned long val = simple_strtoul(buf, NULL, 10);
243 257
244 mutex_lock(&data->update_lock); 258 mutex_lock(&data->update_lock);
@@ -249,37 +263,12 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
249} 263}
250 264
251#define show_in_offset(offset) \ 265#define show_in_offset(offset) \
252static ssize_t \ 266static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
253 show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 267 show_in, NULL, offset); \
254{ \ 268static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
255 return show_in(dev, buf, offset); \ 269 show_in_min, set_in_min, offset); \
256} \ 270static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
257static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 271 show_in_max, set_in_max, offset);
258 show_in##offset, NULL); \
259static ssize_t \
260 show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
261{ \
262 return show_in_min(dev, buf, offset); \
263} \
264static ssize_t \
265 show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
266{ \
267 return show_in_max(dev, buf, offset); \
268} \
269static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
270 const char *buf, size_t count) \
271{ \
272 return set_in_min(dev, buf, count, offset); \
273} \
274static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
275 const char *buf, size_t count) \
276{ \
277 return set_in_max(dev, buf, count, offset); \
278} \
279static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
280 show_in##offset##_min, set_in##offset##_min); \
281static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
282 show_in##offset##_max, set_in##offset##_max);
283 272
284show_in_offset(0); 273show_in_offset(0);
285show_in_offset(1); 274show_in_offset(1);
@@ -337,24 +326,32 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
337 show_temp_hyst, set_temp_hyst); 326 show_temp_hyst, set_temp_hyst);
338 327
339/* 2 Fans */ 328/* 2 Fans */
340static ssize_t show_fan(struct device *dev, char *buf, int nr) 329static ssize_t show_fan(struct device *dev, struct device_attribute *da,
330 char *buf)
341{ 331{
342 struct sis5595_data *data = sis5595_update_device(dev); 332 struct sis5595_data *data = sis5595_update_device(dev);
333 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
334 int nr = attr->index;
343 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 335 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
344 DIV_FROM_REG(data->fan_div[nr])) ); 336 DIV_FROM_REG(data->fan_div[nr])) );
345} 337}
346 338
347static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 339static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
340 char *buf)
348{ 341{
349 struct sis5595_data *data = sis5595_update_device(dev); 342 struct sis5595_data *data = sis5595_update_device(dev);
343 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
344 int nr = attr->index;
350 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 345 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
351 DIV_FROM_REG(data->fan_div[nr])) ); 346 DIV_FROM_REG(data->fan_div[nr])) );
352} 347}
353 348
354static ssize_t set_fan_min(struct device *dev, const char *buf, 349static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
355 size_t count, int nr) 350 const char *buf, size_t count)
356{ 351{
357 struct sis5595_data *data = dev_get_drvdata(dev); 352 struct sis5595_data *data = dev_get_drvdata(dev);
353 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
354 int nr = attr->index;
358 unsigned long val = simple_strtoul(buf, NULL, 10); 355 unsigned long val = simple_strtoul(buf, NULL, 10);
359 356
360 mutex_lock(&data->update_lock); 357 mutex_lock(&data->update_lock);
@@ -364,9 +361,12 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
364 return count; 361 return count;
365} 362}
366 363
367static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 364static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
365 char *buf)
368{ 366{
369 struct sis5595_data *data = sis5595_update_device(dev); 367 struct sis5595_data *data = sis5595_update_device(dev);
368 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
369 int nr = attr->index;
370 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 370 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
371} 371}
372 372
@@ -374,10 +374,12 @@ static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
374 determined in part by the fan divisor. This follows the principle of 374 determined in part by the fan divisor. This follows the principle of
375 least surprise; the user doesn't expect the fan minimum to change just 375 least surprise; the user doesn't expect the fan minimum to change just
376 because the divisor changed. */ 376 because the divisor changed. */
377static ssize_t set_fan_div(struct device *dev, const char *buf, 377static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
378 size_t count, int nr) 378 const char *buf, size_t count)
379{ 379{
380 struct sis5595_data *data = dev_get_drvdata(dev); 380 struct sis5595_data *data = dev_get_drvdata(dev);
381 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
382 int nr = attr->index;
381 unsigned long min; 383 unsigned long min;
382 unsigned long val = simple_strtoul(buf, NULL, 10); 384 unsigned long val = simple_strtoul(buf, NULL, 10);
383 int reg; 385 int reg;
@@ -416,46 +418,16 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
416} 418}
417 419
418#define show_fan_offset(offset) \ 420#define show_fan_offset(offset) \
419static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 421static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
420{ \ 422 show_fan, NULL, offset - 1); \
421 return show_fan(dev, buf, offset - 1); \ 423static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
422} \ 424 show_fan_min, set_fan_min, offset - 1); \
423static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 425static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
424{ \ 426 show_fan_div, set_fan_div, offset - 1);
425 return show_fan_min(dev, buf, offset - 1); \
426} \
427static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
428{ \
429 return show_fan_div(dev, buf, offset - 1); \
430} \
431static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
432 const char *buf, size_t count) \
433{ \
434 return set_fan_min(dev, buf, count, offset - 1); \
435} \
436static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
437static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
438 show_fan_##offset##_min, set_fan_##offset##_min);
439 427
440show_fan_offset(1); 428show_fan_offset(1);
441show_fan_offset(2); 429show_fan_offset(2);
442 430
443static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf,
444 size_t count)
445{
446 return set_fan_div(dev, buf, count, 0) ;
447}
448
449static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf,
450 size_t count)
451{
452 return set_fan_div(dev, buf, count, 1) ;
453}
454static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
455 show_fan_1_div, set_fan_1_div);
456static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
457 show_fan_2_div, set_fan_2_div);
458
459/* Alarms */ 431/* Alarms */
460static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 432static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
461{ 433{
@@ -473,25 +445,25 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
473static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 445static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
474 446
475static struct attribute *sis5595_attributes[] = { 447static struct attribute *sis5595_attributes[] = {
476 &dev_attr_in0_input.attr, 448 &sensor_dev_attr_in0_input.dev_attr.attr,
477 &dev_attr_in0_min.attr, 449 &sensor_dev_attr_in0_min.dev_attr.attr,
478 &dev_attr_in0_max.attr, 450 &sensor_dev_attr_in0_max.dev_attr.attr,
479 &dev_attr_in1_input.attr, 451 &sensor_dev_attr_in1_input.dev_attr.attr,
480 &dev_attr_in1_min.attr, 452 &sensor_dev_attr_in1_min.dev_attr.attr,
481 &dev_attr_in1_max.attr, 453 &sensor_dev_attr_in1_max.dev_attr.attr,
482 &dev_attr_in2_input.attr, 454 &sensor_dev_attr_in2_input.dev_attr.attr,
483 &dev_attr_in2_min.attr, 455 &sensor_dev_attr_in2_min.dev_attr.attr,
484 &dev_attr_in2_max.attr, 456 &sensor_dev_attr_in2_max.dev_attr.attr,
485 &dev_attr_in3_input.attr, 457 &sensor_dev_attr_in3_input.dev_attr.attr,
486 &dev_attr_in3_min.attr, 458 &sensor_dev_attr_in3_min.dev_attr.attr,
487 &dev_attr_in3_max.attr, 459 &sensor_dev_attr_in3_max.dev_attr.attr,
488 460
489 &dev_attr_fan1_input.attr, 461 &sensor_dev_attr_fan1_input.dev_attr.attr,
490 &dev_attr_fan1_min.attr, 462 &sensor_dev_attr_fan1_min.dev_attr.attr,
491 &dev_attr_fan1_div.attr, 463 &sensor_dev_attr_fan1_div.dev_attr.attr,
492 &dev_attr_fan2_input.attr, 464 &sensor_dev_attr_fan2_input.dev_attr.attr,
493 &dev_attr_fan2_min.attr, 465 &sensor_dev_attr_fan2_min.dev_attr.attr,
494 &dev_attr_fan2_div.attr, 466 &sensor_dev_attr_fan2_div.dev_attr.attr,
495 467
496 &dev_attr_alarms.attr, 468 &dev_attr_alarms.attr,
497 &dev_attr_name.attr, 469 &dev_attr_name.attr,
@@ -503,9 +475,9 @@ static const struct attribute_group sis5595_group = {
503}; 475};
504 476
505static struct attribute *sis5595_attributes_opt[] = { 477static struct attribute *sis5595_attributes_opt[] = {
506 &dev_attr_in4_input.attr, 478 &sensor_dev_attr_in4_input.dev_attr.attr,
507 &dev_attr_in4_min.attr, 479 &sensor_dev_attr_in4_min.dev_attr.attr,
508 &dev_attr_in4_max.attr, 480 &sensor_dev_attr_in4_max.dev_attr.attr,
509 481
510 &dev_attr_temp1_input.attr, 482 &dev_attr_temp1_input.attr,
511 &dev_attr_temp1_max.attr, 483 &dev_attr_temp1_max.attr,
@@ -570,11 +542,11 @@ static int __devinit sis5595_probe(struct platform_device *pdev)
570 goto exit_free; 542 goto exit_free;
571 if (data->maxins == 4) { 543 if (data->maxins == 4) {
572 if ((err = device_create_file(&pdev->dev, 544 if ((err = device_create_file(&pdev->dev,
573 &dev_attr_in4_input)) 545 &sensor_dev_attr_in4_input.dev_attr))
574 || (err = device_create_file(&pdev->dev, 546 || (err = device_create_file(&pdev->dev,
575 &dev_attr_in4_min)) 547 &sensor_dev_attr_in4_min.dev_attr))
576 || (err = device_create_file(&pdev->dev, 548 || (err = device_create_file(&pdev->dev,
577 &dev_attr_in4_max))) 549 &sensor_dev_attr_in4_max.dev_attr)))
578 goto exit_remove_files; 550 goto exit_remove_files;
579 } else { 551 } else {
580 if ((err = device_create_file(&pdev->dev, 552 if ((err = device_create_file(&pdev->dev,