aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-14 16:20:00 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:21 -0400
commit8c103696fa59e1b810bf24a63304acd5ab585c12 (patch)
treee451f2c18753a4c1972f3dcfd798480cf0b753a1
parentc387e4eb245bf55695f96817d15fe90c3bc99e6b (diff)
hwmon: (asb100): Fix checkpatch issues
Fixed: ERROR: code indent should use tabs where possible ERROR: do not use assignment in if condition ERROR: space prohibited after that open parenthesis '(' ERROR: spaces required around that '<' (ctx:VxV) ERROR: spaces required around that '==' (ctx:VxV) WARNING: please, no spaces at the start of a line WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Modify multi-line comments to follow Documentation/CodingStyle. Not fixed (false positive): ERROR: Macros with multiple statements should be enclosed in a do - while loop Cc: Mark M. Hoffman <mhoffman@lightlink.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/asb100.c187
1 files changed, 117 insertions, 70 deletions
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 0f300c6b7f98..4b8814deabb1 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -1,40 +1,40 @@
1/* 1/*
2 asb100.c - Part of lm_sensors, Linux kernel modules for hardware 2 * asb100.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 4 *
5 Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com> 5 * Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
6 6 *
7 (derived from w83781d.c) 7 * (derived from w83781d.c)
8 8 *
9 Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>, 9 * Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
10 Philip Edelbrock <phil@netroedge.com>, and 10 * Philip Edelbrock <phil@netroedge.com>, and
11 Mark Studebaker <mdsxyz123@yahoo.com> 11 * Mark Studebaker <mdsxyz123@yahoo.com>
12 12 *
13 This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 16 * (at your option) any later version.
17 17 *
18 This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 21 * GNU General Public License for more details.
22 22 *
23 You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/ 26 */
27 27
28/* 28/*
29 This driver supports the hardware sensor chips: Asus ASB100 and 29 * This driver supports the hardware sensor chips: Asus ASB100 and
30 ASB100-A "BACH". 30 * ASB100-A "BACH".
31 31 *
32 ASB100-A supports pwm1, while plain ASB100 does not. There is no known 32 * ASB100-A supports pwm1, while plain ASB100 does not. There is no known
33 way for the driver to tell which one is there. 33 * way for the driver to tell which one is there.
34 34 *
35 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 35 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
36 asb100 7 3 1 4 0x31 0x0694 yes no 36 * asb100 7 3 1 4 0x31 0x0694 yes no
37*/ 37 */
38 38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 40
@@ -99,15 +99,19 @@ static const u16 asb100_reg_temp_hyst[] = {0, 0x3a, 0x153, 0x253, 0x19};
99/* bit 7 -> enable, bits 0-3 -> duty cycle */ 99/* bit 7 -> enable, bits 0-3 -> duty cycle */
100#define ASB100_REG_PWM1 0x59 100#define ASB100_REG_PWM1 0x59
101 101
102/* CONVERSIONS 102/*
103 Rounding and limit checking is only done on the TO_REG variants. */ 103 * CONVERSIONS
104 * Rounding and limit checking is only done on the TO_REG variants.
105 */
104 106
105/* These constants are a guess, consistent w/ w83781d */ 107/* These constants are a guess, consistent w/ w83781d */
106#define ASB100_IN_MIN ( 0) 108#define ASB100_IN_MIN 0
107#define ASB100_IN_MAX (4080) 109#define ASB100_IN_MAX 4080
108 110
109/* IN: 1/1000 V (0V to 4.08V) 111/*
110 REG: 16mV/bit */ 112 * IN: 1/1000 V (0V to 4.08V)
113 * REG: 16mV/bit
114 */
111static u8 IN_TO_REG(unsigned val) 115static u8 IN_TO_REG(unsigned val)
112{ 116{
113 unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX); 117 unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX);
@@ -131,19 +135,21 @@ static u8 FAN_TO_REG(long rpm, int div)
131 135
132static int FAN_FROM_REG(u8 val, int div) 136static int FAN_FROM_REG(u8 val, int div)
133{ 137{
134 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div); 138 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
135} 139}
136 140
137/* These constants are a guess, consistent w/ w83781d */ 141/* These constants are a guess, consistent w/ w83781d */
138#define ASB100_TEMP_MIN (-128000) 142#define ASB100_TEMP_MIN -128000
139#define ASB100_TEMP_MAX ( 127000) 143#define ASB100_TEMP_MAX 127000
140 144
141/* TEMP: 0.001C/bit (-128C to +127C) 145/*
142 REG: 1C/bit, two's complement */ 146 * TEMP: 0.001C/bit (-128C to +127C)
147 * REG: 1C/bit, two's complement
148 */
143static u8 TEMP_TO_REG(long temp) 149static u8 TEMP_TO_REG(long temp)
144{ 150{
145 int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX); 151 int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
146 ntemp += (ntemp<0 ? -500 : 500); 152 ntemp += (ntemp < 0 ? -500 : 500);
147 return (u8)(ntemp / 1000); 153 return (u8)(ntemp / 1000);
148} 154}
149 155
@@ -152,8 +158,10 @@ static int TEMP_FROM_REG(u8 reg)
152 return (s8)reg * 1000; 158 return (s8)reg * 1000;
153} 159}
154 160
155/* PWM: 0 - 255 per sensors documentation 161/*
156 REG: (6.25% duty cycle per bit) */ 162 * PWM: 0 - 255 per sensors documentation
163 * REG: (6.25% duty cycle per bit)
164 */
157static u8 ASB100_PWM_TO_REG(int pwm) 165static u8 ASB100_PWM_TO_REG(int pwm)
158{ 166{
159 pwm = SENSORS_LIMIT(pwm, 0, 255); 167 pwm = SENSORS_LIMIT(pwm, 0, 255);
@@ -167,16 +175,20 @@ static int ASB100_PWM_FROM_REG(u8 reg)
167 175
168#define DIV_FROM_REG(val) (1 << (val)) 176#define DIV_FROM_REG(val) (1 << (val))
169 177
170/* FAN DIV: 1, 2, 4, or 8 (defaults to 2) 178/*
171 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */ 179 * FAN DIV: 1, 2, 4, or 8 (defaults to 2)
180 * REG: 0, 1, 2, or 3 (respectively) (defaults to 1)
181 */
172static u8 DIV_TO_REG(long val) 182static u8 DIV_TO_REG(long val)
173{ 183{
174 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1; 184 return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
175} 185}
176 186
177/* For each registered client, we need to keep some data in memory. That 187/*
178 data is pointed to by client->data. The structure itself is 188 * For each registered client, we need to keep some data in memory. That
179 dynamically allocated, at the same time the client itself is allocated. */ 189 * data is pointed to by client->data. The structure itself is
190 * dynamically allocated, at the same time the client itself is allocated.
191 */
180struct asb100_data { 192struct asb100_data {
181 struct device *hwmon_dev; 193 struct device *hwmon_dev;
182 struct mutex lock; 194 struct mutex lock;
@@ -253,8 +265,10 @@ static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
253 int nr = to_sensor_dev_attr(attr)->index; \ 265 int nr = to_sensor_dev_attr(attr)->index; \
254 struct i2c_client *client = to_i2c_client(dev); \ 266 struct i2c_client *client = to_i2c_client(dev); \
255 struct asb100_data *data = i2c_get_clientdata(client); \ 267 struct asb100_data *data = i2c_get_clientdata(client); \
256 unsigned long val = simple_strtoul(buf, NULL, 10); \ 268 unsigned long val; \
257 \ 269 int err = kstrtoul(buf, 10, &val); \
270 if (err) \
271 return err; \
258 mutex_lock(&data->update_lock); \ 272 mutex_lock(&data->update_lock); \
259 data->in_##reg[nr] = IN_TO_REG(val); \ 273 data->in_##reg[nr] = IN_TO_REG(val); \
260 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ 274 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
@@ -315,7 +329,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
315 int nr = to_sensor_dev_attr(attr)->index; 329 int nr = to_sensor_dev_attr(attr)->index;
316 struct i2c_client *client = to_i2c_client(dev); 330 struct i2c_client *client = to_i2c_client(dev);
317 struct asb100_data *data = i2c_get_clientdata(client); 331 struct asb100_data *data = i2c_get_clientdata(client);
318 u32 val = simple_strtoul(buf, NULL, 10); 332 unsigned long val;
333 int err;
334
335 err = kstrtoul(buf, 10, &val);
336 if (err)
337 return err;
319 338
320 mutex_lock(&data->update_lock); 339 mutex_lock(&data->update_lock);
321 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 340 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -324,10 +343,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
324 return count; 343 return count;
325} 344}
326 345
327/* Note: we save and restore the fan minimum here, because its value is 346/*
328 determined in part by the fan divisor. This follows the principle of 347 * Note: we save and restore the fan minimum here, because its value is
329 least surprise; the user doesn't expect the fan minimum to change just 348 * determined in part by the fan divisor. This follows the principle of
330 because the divisor changed. */ 349 * least surprise; the user doesn't expect the fan minimum to change just
350 * because the divisor changed.
351 */
331static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 352static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
332 const char *buf, size_t count) 353 const char *buf, size_t count)
333{ 354{
@@ -335,8 +356,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
335 struct i2c_client *client = to_i2c_client(dev); 356 struct i2c_client *client = to_i2c_client(dev);
336 struct asb100_data *data = i2c_get_clientdata(client); 357 struct asb100_data *data = i2c_get_clientdata(client);
337 unsigned long min; 358 unsigned long min;
338 unsigned long val = simple_strtoul(buf, NULL, 10);
339 int reg; 359 int reg;
360 unsigned long val;
361 int err;
362
363 err = kstrtoul(buf, 10, &val);
364 if (err)
365 return err;
340 366
341 mutex_lock(&data->update_lock); 367 mutex_lock(&data->update_lock);
342 368
@@ -421,8 +447,10 @@ static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
421 int nr = to_sensor_dev_attr(attr)->index; \ 447 int nr = to_sensor_dev_attr(attr)->index; \
422 struct i2c_client *client = to_i2c_client(dev); \ 448 struct i2c_client *client = to_i2c_client(dev); \
423 struct asb100_data *data = i2c_get_clientdata(client); \ 449 struct asb100_data *data = i2c_get_clientdata(client); \
424 long val = simple_strtol(buf, NULL, 10); \ 450 long val; \
425 \ 451 int err = kstrtol(buf, 10, &val); \
452 if (err) \
453 return err; \
426 mutex_lock(&data->update_lock); \ 454 mutex_lock(&data->update_lock); \
427 switch (nr) { \ 455 switch (nr) { \
428 case 1: case 2: \ 456 case 1: case 2: \
@@ -476,7 +504,13 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
476 const char *buf, size_t count) 504 const char *buf, size_t count)
477{ 505{
478 struct asb100_data *data = dev_get_drvdata(dev); 506 struct asb100_data *data = dev_get_drvdata(dev);
479 data->vrm = simple_strtoul(buf, NULL, 10); 507 unsigned long val;
508 int err;
509
510 err = kstrtoul(buf, 10, &val);
511 if (err)
512 return err;
513 data->vrm = val;
480 return count; 514 return count;
481} 515}
482 516
@@ -524,7 +558,12 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
524{ 558{
525 struct i2c_client *client = to_i2c_client(dev); 559 struct i2c_client *client = to_i2c_client(dev);
526 struct asb100_data *data = i2c_get_clientdata(client); 560 struct asb100_data *data = i2c_get_clientdata(client);
527 unsigned long val = simple_strtoul(buf, NULL, 10); 561 unsigned long val;
562 int err;
563
564 err = kstrtoul(buf, 10, &val);
565 if (err)
566 return err;
528 567
529 mutex_lock(&data->update_lock); 568 mutex_lock(&data->update_lock);
530 data->pwm &= 0x80; /* keep the enable bit */ 569 data->pwm &= 0x80; /* keep the enable bit */
@@ -546,7 +585,12 @@ static ssize_t set_pwm_enable1(struct device *dev,
546{ 585{
547 struct i2c_client *client = to_i2c_client(dev); 586 struct i2c_client *client = to_i2c_client(dev);
548 struct asb100_data *data = i2c_get_clientdata(client); 587 struct asb100_data *data = i2c_get_clientdata(client);
549 unsigned long val = simple_strtoul(buf, NULL, 10); 588 unsigned long val;
589 int err;
590
591 err = kstrtoul(buf, 10, &val);
592 if (err)
593 return err;
550 594
551 mutex_lock(&data->update_lock); 595 mutex_lock(&data->update_lock);
552 data->pwm &= 0x0f; /* keep the duty cycle bits */ 596 data->pwm &= 0x0f; /* keep the duty cycle bits */
@@ -768,7 +812,8 @@ static int asb100_probe(struct i2c_client *client,
768 data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2)); 812 data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
769 813
770 /* Register sysfs hooks */ 814 /* Register sysfs hooks */
771 if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group))) 815 err = sysfs_create_group(&client->dev.kobj, &asb100_group);
816 if (err)
772 goto ERROR3; 817 goto ERROR3;
773 818
774 data->hwmon_dev = hwmon_device_register(&client->dev); 819 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -805,8 +850,10 @@ static int asb100_remove(struct i2c_client *client)
805 return 0; 850 return 0;
806} 851}
807 852
808/* The SMBus locks itself, usually, but nothing may access the chip between 853/*
809 bank switches. */ 854 * The SMBus locks itself, usually, but nothing may access the chip between
855 * bank switches.
856 */
810static int asb100_read_value(struct i2c_client *client, u16 reg) 857static int asb100_read_value(struct i2c_client *client, u16 reg)
811{ 858{
812 struct asb100_data *data = i2c_get_clientdata(client); 859 struct asb100_data *data = i2c_get_clientdata(client);