aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-12-19 16:17:00 -0500
committerJean Delvare <khali@endymion.delvare>2012-12-19 16:17:00 -0500
commit929c6a5696f5efe7f4213cf9d8b12144a0c0c650 (patch)
tree39ffc4b0703a6b680789c8775ae07208f7eb4851 /drivers
parent60ca385a530405ab501773ef4c9e222825a6cd40 (diff)
hwmon: (it87) Save voltage register values in 2-dimensional array
Reduces code size (more than 600 bytes on x86_64), and gets rid of some checkpatch errors. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/it87.c147
1 files changed, 66 insertions, 81 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 76ab1d0e42d0..79a1229d3499 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -258,9 +258,7 @@ struct it87_data {
258 unsigned long last_updated; /* In jiffies */ 258 unsigned long last_updated; /* In jiffies */
259 259
260 u16 in_scaled; /* Internal voltage sensors are scaled */ 260 u16 in_scaled; /* Internal voltage sensors are scaled */
261 u8 in[9]; /* Register value */ 261 u8 in[9][3]; /* [nr][0]=in, [1]=min, [2]=max */
262 u8 in_max[8]; /* Register value */
263 u8 in_min[8]; /* Register value */
264 u8 has_fan; /* Bitfield, fans enabled */ 262 u8 has_fan; /* Bitfield, fans enabled */
265 u16 fan[5]; /* Register values, possibly combined */ 263 u16 fan[5]; /* Register values, possibly combined */
266 u16 fan_min[5]; /* Register values, possibly combined */ 264 u16 fan_min[5]; /* Register values, possibly combined */
@@ -445,40 +443,22 @@ static struct platform_driver it87_driver = {
445}; 443};
446 444
447static ssize_t show_in(struct device *dev, struct device_attribute *attr, 445static ssize_t show_in(struct device *dev, struct device_attribute *attr,
448 char *buf) 446 char *buf)
449{
450 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
451 int nr = sensor_attr->index;
452
453 struct it87_data *data = it87_update_device(dev);
454 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr]));
455}
456
457static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
458 char *buf)
459{
460 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
461 int nr = sensor_attr->index;
462
463 struct it87_data *data = it87_update_device(dev);
464 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_min[nr]));
465}
466
467static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
468 char *buf)
469{ 447{
470 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 448 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
471 int nr = sensor_attr->index; 449 int nr = sattr->nr;
450 int index = sattr->index;
472 451
473 struct it87_data *data = it87_update_device(dev); 452 struct it87_data *data = it87_update_device(dev);
474 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_max[nr])); 453 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
475} 454}
476 455
477static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, 456static ssize_t set_in(struct device *dev, struct device_attribute *attr,
478 const char *buf, size_t count) 457 const char *buf, size_t count)
479{ 458{
480 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 459 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
481 int nr = sensor_attr->index; 460 int nr = sattr->nr;
461 int index = sattr->index;
482 462
483 struct it87_data *data = dev_get_drvdata(dev); 463 struct it87_data *data = dev_get_drvdata(dev);
484 unsigned long val; 464 unsigned long val;
@@ -487,59 +467,64 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
487 return -EINVAL; 467 return -EINVAL;
488 468
489 mutex_lock(&data->update_lock); 469 mutex_lock(&data->update_lock);
490 data->in_min[nr] = in_to_reg(data, nr, val); 470 data->in[nr][index] = in_to_reg(data, nr, val);
491 it87_write_value(data, IT87_REG_VIN_MIN(nr), 471 it87_write_value(data,
492 data->in_min[nr]); 472 index == 1 ? IT87_REG_VIN_MIN(nr)
473 : IT87_REG_VIN_MAX(nr),
474 data->in[nr][index]);
493 mutex_unlock(&data->update_lock); 475 mutex_unlock(&data->update_lock);
494 return count; 476 return count;
495} 477}
496static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
497 const char *buf, size_t count)
498{
499 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
500 int nr = sensor_attr->index;
501 478
502 struct it87_data *data = dev_get_drvdata(dev); 479static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
503 unsigned long val; 480static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
481 0, 1);
482static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
483 0, 2);
504 484
505 if (kstrtoul(buf, 10, &val) < 0) 485static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
506 return -EINVAL; 486static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
487 1, 1);
488static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
489 1, 2);
507 490
508 mutex_lock(&data->update_lock); 491static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
509 data->in_max[nr] = in_to_reg(data, nr, val); 492static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
510 it87_write_value(data, IT87_REG_VIN_MAX(nr), 493 2, 1);
511 data->in_max[nr]); 494static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
512 mutex_unlock(&data->update_lock); 495 2, 2);
513 return count;
514}
515 496
516#define show_in_offset(offset) \ 497static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
517static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 498static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
518 show_in, NULL, offset); 499 3, 1);
519 500static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
520#define limit_in_offset(offset) \ 501 3, 2);
521static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 502
522 show_in_min, set_in_min, offset); \ 503static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
523static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 504static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
524 show_in_max, set_in_max, offset); 505 4, 1);
525 506static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
526show_in_offset(0); 507 4, 2);
527limit_in_offset(0); 508
528show_in_offset(1); 509static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
529limit_in_offset(1); 510static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
530show_in_offset(2); 511 5, 1);
531limit_in_offset(2); 512static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
532show_in_offset(3); 513 5, 2);
533limit_in_offset(3); 514
534show_in_offset(4); 515static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
535limit_in_offset(4); 516static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
536show_in_offset(5); 517 6, 1);
537limit_in_offset(5); 518static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
538show_in_offset(6); 519 6, 2);
539limit_in_offset(6); 520
540show_in_offset(7); 521static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
541limit_in_offset(7); 522static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
542show_in_offset(8); 523 7, 1);
524static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
525 7, 2);
526
527static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
543 528
544/* 3 temperatures */ 529/* 3 temperatures */
545static ssize_t show_temp(struct device *dev, struct device_attribute *attr, 530static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
@@ -2361,15 +2346,15 @@ static struct it87_data *it87_update_device(struct device *dev)
2361 it87_read_value(data, IT87_REG_CONFIG) | 0x40); 2346 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
2362 } 2347 }
2363 for (i = 0; i <= 7; i++) { 2348 for (i = 0; i <= 7; i++) {
2364 data->in[i] = 2349 data->in[i][0] =
2365 it87_read_value(data, IT87_REG_VIN(i)); 2350 it87_read_value(data, IT87_REG_VIN(i));
2366 data->in_min[i] = 2351 data->in[i][1] =
2367 it87_read_value(data, IT87_REG_VIN_MIN(i)); 2352 it87_read_value(data, IT87_REG_VIN_MIN(i));
2368 data->in_max[i] = 2353 data->in[i][2] =
2369 it87_read_value(data, IT87_REG_VIN_MAX(i)); 2354 it87_read_value(data, IT87_REG_VIN_MAX(i));
2370 } 2355 }
2371 /* in8 (battery) has no limit registers */ 2356 /* in8 (battery) has no limit registers */
2372 data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); 2357 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
2373 2358
2374 for (i = 0; i < 5; i++) { 2359 for (i = 0; i < 5; i++) {
2375 /* Skip disabled fans */ 2360 /* Skip disabled fans */