diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-14 16:42:20 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:24 -0400 |
commit | 02fe2fd949daf7906dba4d7a795c5eed79bfc24f (patch) | |
tree | 26370d83d0314b87f4f686823295ee212a91e36f /drivers | |
parent | f445a9af939a6989e356a25ca97ea691d98bc336 (diff) |
hwmon: (lm77) Fix checkpatch issues
Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: trailing whitespace
WARNING: line over 80 characters
WARNING: please, no space before tabs
WARNING: simple_strtol is obsolete, use kstrtol instead
WARNING: simple_strtoul is obsolete, use kstrtoul instead
Modify multi-line comments to follow Documentation/CodingStyle.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/lm77.c | 159 |
1 files changed, 95 insertions, 64 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 7cd516f888cc..0fca8613e7d8 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -1,29 +1,29 @@ | |||
1 | /* | 1 | /* |
2 | lm77.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm77.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | * monitoring |
4 | 4 | * | |
5 | Copyright (c) 2004 Andras BALI <drewie@freemail.hu> | 5 | * Copyright (c) 2004 Andras BALI <drewie@freemail.hu> |
6 | 6 | * | |
7 | Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77 | 7 | * Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77 |
8 | is a temperature sensor and thermal window comparator with 0.5 deg | 8 | * is a temperature sensor and thermal window comparator with 0.5 deg |
9 | resolution made by National Semiconductor. Complete datasheet can be | 9 | * resolution made by National Semiconductor. Complete datasheet can be |
10 | obtained at their site: | 10 | * obtained at their site: |
11 | http://www.national.com/pf/LM/LM77.html | 11 | * http://www.national.com/pf/LM/LM77.html |
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 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
@@ -49,7 +49,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, | |||
49 | 49 | ||
50 | /* Each client has this additional data */ | 50 | /* Each client has this additional data */ |
51 | struct lm77_data { | 51 | struct lm77_data { |
52 | struct device *hwmon_dev; | 52 | struct device *hwmon_dev; |
53 | struct mutex update_lock; | 53 | struct mutex update_lock; |
54 | char valid; | 54 | char valid; |
55 | unsigned long last_updated; /* In jiffies */ | 55 | unsigned long last_updated; /* In jiffies */ |
@@ -95,8 +95,10 @@ static struct i2c_driver lm77_driver = { | |||
95 | #define LM77_TEMP_MIN (-55000) | 95 | #define LM77_TEMP_MIN (-55000) |
96 | #define LM77_TEMP_MAX 125000 | 96 | #define LM77_TEMP_MAX 125000 |
97 | 97 | ||
98 | /* In the temperature registers, the low 3 bits are not part of the | 98 | /* |
99 | temperature values; they are the status bits. */ | 99 | * In the temperature registers, the low 3 bits are not part of the |
100 | * temperature values; they are the status bits. | ||
101 | */ | ||
100 | static inline s16 LM77_TEMP_TO_REG(int temp) | 102 | static inline s16 LM77_TEMP_TO_REG(int temp) |
101 | { | 103 | { |
102 | int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); | 104 | int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); |
@@ -112,7 +114,9 @@ static inline int LM77_TEMP_FROM_REG(s16 reg) | |||
112 | 114 | ||
113 | /* read routines for temperature limits */ | 115 | /* read routines for temperature limits */ |
114 | #define show(value) \ | 116 | #define show(value) \ |
115 | static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ | 117 | static ssize_t show_##value(struct device *dev, \ |
118 | struct device_attribute *attr, \ | ||
119 | char *buf) \ | ||
116 | { \ | 120 | { \ |
117 | struct lm77_data *data = lm77_update_device(dev); \ | 121 | struct lm77_data *data = lm77_update_device(dev); \ |
118 | return sprintf(buf, "%d\n", data->value); \ | 122 | return sprintf(buf, "%d\n", data->value); \ |
@@ -124,17 +128,20 @@ show(temp_min); | |||
124 | show(temp_max); | 128 | show(temp_max); |
125 | 129 | ||
126 | /* read routines for hysteresis values */ | 130 | /* read routines for hysteresis values */ |
127 | static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 131 | static ssize_t show_temp_crit_hyst(struct device *dev, |
132 | struct device_attribute *attr, char *buf) | ||
128 | { | 133 | { |
129 | struct lm77_data *data = lm77_update_device(dev); | 134 | struct lm77_data *data = lm77_update_device(dev); |
130 | return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst); | 135 | return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst); |
131 | } | 136 | } |
132 | static ssize_t show_temp_min_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 137 | static ssize_t show_temp_min_hyst(struct device *dev, |
138 | struct device_attribute *attr, char *buf) | ||
133 | { | 139 | { |
134 | struct lm77_data *data = lm77_update_device(dev); | 140 | struct lm77_data *data = lm77_update_device(dev); |
135 | return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst); | 141 | return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst); |
136 | } | 142 | } |
137 | static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 143 | static ssize_t show_temp_max_hyst(struct device *dev, |
144 | struct device_attribute *attr, char *buf) | ||
138 | { | 145 | { |
139 | struct lm77_data *data = lm77_update_device(dev); | 146 | struct lm77_data *data = lm77_update_device(dev); |
140 | return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst); | 147 | return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst); |
@@ -142,29 +149,42 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *a | |||
142 | 149 | ||
143 | /* write routines */ | 150 | /* write routines */ |
144 | #define set(value, reg) \ | 151 | #define set(value, reg) \ |
145 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | 152 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \ |
146 | { \ | 153 | const char *buf, size_t count) \ |
147 | struct i2c_client *client = to_i2c_client(dev); \ | 154 | { \ |
148 | struct lm77_data *data = i2c_get_clientdata(client); \ | 155 | struct i2c_client *client = to_i2c_client(dev); \ |
149 | long val = simple_strtol(buf, NULL, 10); \ | 156 | struct lm77_data *data = i2c_get_clientdata(client); \ |
150 | \ | 157 | long val; \ |
151 | mutex_lock(&data->update_lock); \ | 158 | int err = kstrtol(buf, 10, &val); \ |
152 | data->value = val; \ | 159 | if (err) \ |
153 | lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ | 160 | return err; \ |
154 | mutex_unlock(&data->update_lock); \ | 161 | \ |
155 | return count; \ | 162 | mutex_lock(&data->update_lock); \ |
163 | data->value = val; \ | ||
164 | lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ | ||
165 | mutex_unlock(&data->update_lock); \ | ||
166 | return count; \ | ||
156 | } | 167 | } |
157 | 168 | ||
158 | set(temp_min, LM77_REG_TEMP_MIN); | 169 | set(temp_min, LM77_REG_TEMP_MIN); |
159 | set(temp_max, LM77_REG_TEMP_MAX); | 170 | set(temp_max, LM77_REG_TEMP_MAX); |
160 | 171 | ||
161 | /* hysteresis is stored as a relative value on the chip, so it has to be | 172 | /* |
162 | converted first */ | 173 | * hysteresis is stored as a relative value on the chip, so it has to be |
163 | static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 174 | * converted first |
175 | */ | ||
176 | static ssize_t set_temp_crit_hyst(struct device *dev, | ||
177 | struct device_attribute *attr, | ||
178 | const char *buf, size_t count) | ||
164 | { | 179 | { |
165 | struct i2c_client *client = to_i2c_client(dev); | 180 | struct i2c_client *client = to_i2c_client(dev); |
166 | struct lm77_data *data = i2c_get_clientdata(client); | 181 | struct lm77_data *data = i2c_get_clientdata(client); |
167 | unsigned long val = simple_strtoul(buf, NULL, 10); | 182 | unsigned long val; |
183 | int err; | ||
184 | |||
185 | err = kstrtoul(buf, 10, &val); | ||
186 | if (err) | ||
187 | return err; | ||
168 | 188 | ||
169 | mutex_lock(&data->update_lock); | 189 | mutex_lock(&data->update_lock); |
170 | data->temp_hyst = data->temp_crit - val; | 190 | data->temp_hyst = data->temp_crit - val; |
@@ -175,13 +195,19 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a | |||
175 | } | 195 | } |
176 | 196 | ||
177 | /* preserve hysteresis when setting T_crit */ | 197 | /* preserve hysteresis when setting T_crit */ |
178 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 198 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, |
199 | const char *buf, size_t count) | ||
179 | { | 200 | { |
180 | struct i2c_client *client = to_i2c_client(dev); | 201 | struct i2c_client *client = to_i2c_client(dev); |
181 | struct lm77_data *data = i2c_get_clientdata(client); | 202 | struct lm77_data *data = i2c_get_clientdata(client); |
182 | long val = simple_strtoul(buf, NULL, 10); | ||
183 | int oldcrithyst; | 203 | int oldcrithyst; |
184 | 204 | unsigned long val; | |
205 | int err; | ||
206 | |||
207 | err = kstrtoul(buf, 10, &val); | ||
208 | if (err) | ||
209 | return err; | ||
210 | |||
185 | mutex_lock(&data->update_lock); | 211 | mutex_lock(&data->update_lock); |
186 | oldcrithyst = data->temp_crit - data->temp_hyst; | 212 | oldcrithyst = data->temp_crit - data->temp_hyst; |
187 | data->temp_crit = val; | 213 | data->temp_crit = val; |
@@ -251,17 +277,19 @@ static int lm77_detect(struct i2c_client *new_client, | |||
251 | I2C_FUNC_SMBUS_WORD_DATA)) | 277 | I2C_FUNC_SMBUS_WORD_DATA)) |
252 | return -ENODEV; | 278 | return -ENODEV; |
253 | 279 | ||
254 | /* Here comes the remaining detection. Since the LM77 has no | 280 | /* |
255 | register dedicated to identification, we have to rely on the | 281 | * Here comes the remaining detection. Since the LM77 has no |
256 | following tricks: | 282 | * register dedicated to identification, we have to rely on the |
257 | 283 | * following tricks: | |
258 | 1. the high 4 bits represent the sign and thus they should | 284 | * |
259 | always be the same | 285 | * 1. the high 4 bits represent the sign and thus they should |
260 | 2. the high 3 bits are unused in the configuration register | 286 | * always be the same |
261 | 3. addresses 0x06 and 0x07 return the last read value | 287 | * 2. the high 3 bits are unused in the configuration register |
262 | 4. registers cycling over 8-address boundaries | 288 | * 3. addresses 0x06 and 0x07 return the last read value |
263 | 289 | * 4. registers cycling over 8-address boundaries | |
264 | Word-sized registers are high-byte first. */ | 290 | * |
291 | * Word-sized registers are high-byte first. | ||
292 | */ | ||
265 | 293 | ||
266 | /* addresses cycling */ | 294 | /* addresses cycling */ |
267 | cur = i2c_smbus_read_word_data(new_client, 0); | 295 | cur = i2c_smbus_read_word_data(new_client, 0); |
@@ -330,7 +358,8 @@ static int lm77_probe(struct i2c_client *new_client, | |||
330 | lm77_init_client(new_client); | 358 | lm77_init_client(new_client); |
331 | 359 | ||
332 | /* Register sysfs hooks */ | 360 | /* Register sysfs hooks */ |
333 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) | 361 | err = sysfs_create_group(&new_client->dev.kobj, &lm77_group); |
362 | if (err) | ||
334 | goto exit_free; | 363 | goto exit_free; |
335 | 364 | ||
336 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 365 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
@@ -358,8 +387,10 @@ static int lm77_remove(struct i2c_client *client) | |||
358 | return 0; | 387 | return 0; |
359 | } | 388 | } |
360 | 389 | ||
361 | /* All registers are word-sized, except for the configuration register. | 390 | /* |
362 | The LM77 uses the high-byte first convention. */ | 391 | * All registers are word-sized, except for the configuration register. |
392 | * The LM77 uses the high-byte first convention. | ||
393 | */ | ||
363 | static u16 lm77_read_value(struct i2c_client *client, u8 reg) | 394 | static u16 lm77_read_value(struct i2c_client *client, u8 reg) |
364 | { | 395 | { |
365 | if (reg == LM77_REG_CONF) | 396 | if (reg == LM77_REG_CONF) |