diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-15 00:04:18 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:05 -0400 |
commit | a318afd890ea4cf1e35543ad100704173edb4406 (patch) | |
tree | f427c585a7810ff6ba808923f63e8ef9e42d900b /drivers/hwmon/lm92.c | |
parent | 073f1e6c895f256b1d7b535a97fe0ced98ac1615 (diff) |
hwmon: (lm92) Fix checkpatch issues
Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: spaces required around that '<' (ctx:VxV)
ERROR: spaces required around that '=' (ctx:VxV)
ERROR: spaces required around that '*=' (ctx:VxV)
ERROR: trailing whitespace
WARNING: line over 80 characters
WARNING: please, no space before tabs
WARNING: please, no spaces at the start of a line
WARNING: simple_strtol is obsolete, use kstrtol instead
Modify multi-line comments to follow Documentation/CodingStyle.
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm92.c')
-rw-r--r-- | drivers/hwmon/lm92.c | 98 |
1 files changed, 62 insertions, 36 deletions
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index 92f2d4684a3c..fdc691a4028f 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -49,8 +49,10 @@ | |||
49 | #include <linux/err.h> | 49 | #include <linux/err.h> |
50 | #include <linux/mutex.h> | 50 | #include <linux/mutex.h> |
51 | 51 | ||
52 | /* The LM92 and MAX6635 have 2 two-state pins for address selection, | 52 | /* |
53 | resulting in 4 possible addresses. */ | 53 | * The LM92 and MAX6635 have 2 two-state pins for address selection, |
54 | * resulting in 4 possible addresses. | ||
55 | */ | ||
54 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, | 56 | static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, |
55 | I2C_CLIENT_END }; | 57 | I2C_CLIENT_END }; |
56 | 58 | ||
@@ -63,11 +65,13 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, | |||
63 | #define LM92_REG_TEMP_HIGH 0x05 /* 16-bit, RW */ | 65 | #define LM92_REG_TEMP_HIGH 0x05 /* 16-bit, RW */ |
64 | #define LM92_REG_MAN_ID 0x07 /* 16-bit, RO, LM92 only */ | 66 | #define LM92_REG_MAN_ID 0x07 /* 16-bit, RO, LM92 only */ |
65 | 67 | ||
66 | /* The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius, | 68 | /* |
67 | left-justified in 16-bit registers. No rounding is done, with such | 69 | * The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius, |
68 | a resolution it's just not worth it. Note that the MAX6635 doesn't | 70 | * left-justified in 16-bit registers. No rounding is done, with such |
69 | make use of the 4 lower bits for limits (i.e. effective resolution | 71 | * a resolution it's just not worth it. Note that the MAX6635 doesn't |
70 | for limits is 1 degree Celsius). */ | 72 | * make use of the 4 lower bits for limits (i.e. effective resolution |
73 | * for limits is 1 degree Celsius). | ||
74 | */ | ||
71 | static inline int TEMP_FROM_REG(s16 reg) | 75 | static inline int TEMP_FROM_REG(s16 reg) |
72 | { | 76 | { |
73 | return reg / 8 * 625 / 10; | 77 | return reg / 8 * 625 / 10; |
@@ -138,7 +142,8 @@ static struct lm92_data *lm92_update_device(struct device *dev) | |||
138 | } | 142 | } |
139 | 143 | ||
140 | #define show_temp(value) \ | 144 | #define show_temp(value) \ |
141 | static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ | 145 | static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \ |
146 | char *buf) \ | ||
142 | { \ | 147 | { \ |
143 | struct lm92_data *data = lm92_update_device(dev); \ | 148 | struct lm92_data *data = lm92_update_device(dev); \ |
144 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ | 149 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ |
@@ -149,13 +154,17 @@ show_temp(temp1_min); | |||
149 | show_temp(temp1_max); | 154 | show_temp(temp1_max); |
150 | 155 | ||
151 | #define set_temp(value, reg) \ | 156 | #define set_temp(value, reg) \ |
152 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, \ | 157 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \ |
158 | const char *buf, \ | ||
153 | size_t count) \ | 159 | size_t count) \ |
154 | { \ | 160 | { \ |
155 | struct i2c_client *client = to_i2c_client(dev); \ | 161 | struct i2c_client *client = to_i2c_client(dev); \ |
156 | struct lm92_data *data = i2c_get_clientdata(client); \ | 162 | struct lm92_data *data = i2c_get_clientdata(client); \ |
157 | long val = simple_strtol(buf, NULL, 10); \ | 163 | long val; \ |
158 | \ | 164 | int err = kstrtol(buf, 10, &val); \ |
165 | if (err) \ | ||
166 | return err; \ | ||
167 | \ | ||
159 | mutex_lock(&data->update_lock); \ | 168 | mutex_lock(&data->update_lock); \ |
160 | data->value = TEMP_TO_REG(val); \ | 169 | data->value = TEMP_TO_REG(val); \ |
161 | i2c_smbus_write_word_swapped(client, reg, data->value); \ | 170 | i2c_smbus_write_word_swapped(client, reg, data->value); \ |
@@ -166,31 +175,40 @@ set_temp(temp1_crit, LM92_REG_TEMP_CRIT); | |||
166 | set_temp(temp1_min, LM92_REG_TEMP_LOW); | 175 | set_temp(temp1_min, LM92_REG_TEMP_LOW); |
167 | set_temp(temp1_max, LM92_REG_TEMP_HIGH); | 176 | set_temp(temp1_max, LM92_REG_TEMP_HIGH); |
168 | 177 | ||
169 | static ssize_t show_temp1_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 178 | static ssize_t show_temp1_crit_hyst(struct device *dev, |
179 | struct device_attribute *attr, char *buf) | ||
170 | { | 180 | { |
171 | struct lm92_data *data = lm92_update_device(dev); | 181 | struct lm92_data *data = lm92_update_device(dev); |
172 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit) | 182 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit) |
173 | - TEMP_FROM_REG(data->temp1_hyst)); | 183 | - TEMP_FROM_REG(data->temp1_hyst)); |
174 | } | 184 | } |
175 | static ssize_t show_temp1_max_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 185 | static ssize_t show_temp1_max_hyst(struct device *dev, |
186 | struct device_attribute *attr, char *buf) | ||
176 | { | 187 | { |
177 | struct lm92_data *data = lm92_update_device(dev); | 188 | struct lm92_data *data = lm92_update_device(dev); |
178 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max) | 189 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max) |
179 | - TEMP_FROM_REG(data->temp1_hyst)); | 190 | - TEMP_FROM_REG(data->temp1_hyst)); |
180 | } | 191 | } |
181 | static ssize_t show_temp1_min_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 192 | static ssize_t show_temp1_min_hyst(struct device *dev, |
193 | struct device_attribute *attr, char *buf) | ||
182 | { | 194 | { |
183 | struct lm92_data *data = lm92_update_device(dev); | 195 | struct lm92_data *data = lm92_update_device(dev); |
184 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min) | 196 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min) |
185 | + TEMP_FROM_REG(data->temp1_hyst)); | 197 | + TEMP_FROM_REG(data->temp1_hyst)); |
186 | } | 198 | } |
187 | 199 | ||
188 | static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, | 200 | static ssize_t set_temp1_crit_hyst(struct device *dev, |
189 | size_t count) | 201 | struct device_attribute *attr, |
202 | const char *buf, size_t count) | ||
190 | { | 203 | { |
191 | struct i2c_client *client = to_i2c_client(dev); | 204 | struct i2c_client *client = to_i2c_client(dev); |
192 | struct lm92_data *data = i2c_get_clientdata(client); | 205 | struct lm92_data *data = i2c_get_clientdata(client); |
193 | long val = simple_strtol(buf, NULL, 10); | 206 | long val; |
207 | int err; | ||
208 | |||
209 | err = kstrtol(buf, 10, &val); | ||
210 | if (err) | ||
211 | return err; | ||
194 | 212 | ||
195 | mutex_lock(&data->update_lock); | 213 | mutex_lock(&data->update_lock); |
196 | data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; | 214 | data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; |
@@ -200,7 +218,8 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute * | |||
200 | return count; | 218 | return count; |
201 | } | 219 | } |
202 | 220 | ||
203 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 221 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
222 | char *buf) | ||
204 | { | 223 | { |
205 | struct lm92_data *data = lm92_update_device(dev); | 224 | struct lm92_data *data = lm92_update_device(dev); |
206 | return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input)); | 225 | return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input)); |
@@ -246,26 +265,30 @@ static void lm92_init_client(struct i2c_client *client) | |||
246 | config & 0xFE); | 265 | config & 0xFE); |
247 | } | 266 | } |
248 | 267 | ||
249 | /* The MAX6635 has no identification register, so we have to use tricks | 268 | /* |
250 | to identify it reliably. This is somewhat slow. | 269 | * The MAX6635 has no identification register, so we have to use tricks |
251 | Note that we do NOT rely on the 2 MSB of the configuration register | 270 | * to identify it reliably. This is somewhat slow. |
252 | always reading 0, as suggested by the datasheet, because it was once | 271 | * Note that we do NOT rely on the 2 MSB of the configuration register |
253 | reported not to be true. */ | 272 | * always reading 0, as suggested by the datasheet, because it was once |
273 | * reported not to be true. | ||
274 | */ | ||
254 | static int max6635_check(struct i2c_client *client) | 275 | static int max6635_check(struct i2c_client *client) |
255 | { | 276 | { |
256 | u16 temp_low, temp_high, temp_hyst, temp_crit; | 277 | u16 temp_low, temp_high, temp_hyst, temp_crit; |
257 | u8 conf; | 278 | u8 conf; |
258 | int i; | 279 | int i; |
259 | 280 | ||
260 | /* No manufacturer ID register, so a read from this address will | 281 | /* |
261 | always return the last read value. */ | 282 | * No manufacturer ID register, so a read from this address will |
283 | * always return the last read value. | ||
284 | */ | ||
262 | temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW); | 285 | temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW); |
263 | if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low) | 286 | if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low) |
264 | return 0; | 287 | return 0; |
265 | temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH); | 288 | temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH); |
266 | if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high) | 289 | if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high) |
267 | return 0; | 290 | return 0; |
268 | 291 | ||
269 | /* Limits are stored as integer values (signed, 9-bit). */ | 292 | /* Limits are stored as integer values (signed, 9-bit). */ |
270 | if ((temp_low & 0x7f00) || (temp_high & 0x7f00)) | 293 | if ((temp_low & 0x7f00) || (temp_high & 0x7f00)) |
271 | return 0; | 294 | return 0; |
@@ -274,22 +297,24 @@ static int max6635_check(struct i2c_client *client) | |||
274 | if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00)) | 297 | if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00)) |
275 | return 0; | 298 | return 0; |
276 | 299 | ||
277 | /* Registers addresses were found to cycle over 16-byte boundaries. | 300 | /* |
278 | We don't test all registers with all offsets so as to save some | 301 | * Registers addresses were found to cycle over 16-byte boundaries. |
279 | reads and time, but this should still be sufficient to dismiss | 302 | * We don't test all registers with all offsets so as to save some |
280 | non-MAX6635 chips. */ | 303 | * reads and time, but this should still be sufficient to dismiss |
304 | * non-MAX6635 chips. | ||
305 | */ | ||
281 | conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG); | 306 | conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG); |
282 | for (i=16; i<96; i*=2) { | 307 | for (i = 16; i < 96; i *= 2) { |
283 | if (temp_hyst != i2c_smbus_read_word_data(client, | 308 | if (temp_hyst != i2c_smbus_read_word_data(client, |
284 | LM92_REG_TEMP_HYST + i - 16) | 309 | LM92_REG_TEMP_HYST + i - 16) |
285 | || temp_crit != i2c_smbus_read_word_data(client, | 310 | || temp_crit != i2c_smbus_read_word_data(client, |
286 | LM92_REG_TEMP_CRIT + i) | 311 | LM92_REG_TEMP_CRIT + i) |
287 | || temp_low != i2c_smbus_read_word_data(client, | 312 | || temp_low != i2c_smbus_read_word_data(client, |
288 | LM92_REG_TEMP_LOW + i + 16) | 313 | LM92_REG_TEMP_LOW + i + 16) |
289 | || temp_high != i2c_smbus_read_word_data(client, | 314 | || temp_high != i2c_smbus_read_word_data(client, |
290 | LM92_REG_TEMP_HIGH + i + 32) | 315 | LM92_REG_TEMP_HIGH + i + 32) |
291 | || conf != i2c_smbus_read_byte_data(client, | 316 | || conf != i2c_smbus_read_byte_data(client, |
292 | LM92_REG_CONFIG + i)) | 317 | LM92_REG_CONFIG + i)) |
293 | return 0; | 318 | return 0; |
294 | } | 319 | } |
295 | 320 | ||
@@ -362,7 +387,8 @@ static int lm92_probe(struct i2c_client *new_client, | |||
362 | lm92_init_client(new_client); | 387 | lm92_init_client(new_client); |
363 | 388 | ||
364 | /* Register sysfs hooks */ | 389 | /* Register sysfs hooks */ |
365 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) | 390 | err = sysfs_create_group(&new_client->dev.kobj, &lm92_group); |
391 | if (err) | ||
366 | goto exit_free; | 392 | goto exit_free; |
367 | 393 | ||
368 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 394 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |