aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/gl518sm.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-14 16:32:55 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:22 -0400
commit228f8e0c60e96f16ae7739b62187622d566022a9 (patch)
tree93120a8ef7e8fe8fd33ab608480775afe93e1a52 /drivers/hwmon/gl518sm.c
parentc8de83624c33b2f5dc6ba497477fc2019b547949 (diff)
hwmon: (gl518sm) Fix checkpatch issues
Fixed: ERROR: do not use assignment in if condition ERROR: space required after that ',' (ctx:VxV) ERROR: spaces required around that '?' (ctx:VxE) ERROR: spaces required around that '<' (ctx:VxV) ERROR: spaces required around that '==' (ctx:VxV) ERROR: spaces required around that ':' (ctx:VxV) ERROR: spaces required around that '?' (ctx:VxV) ERROR: trailing statements should be on next line WARNING: line over 80 characters 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/hwmon/gl518sm.c')
-rw-r--r--drivers/hwmon/gl518sm.c102
1 files changed, 70 insertions, 32 deletions
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 89b8c0a4aca4..764a083ac7a7 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -83,11 +83,12 @@ enum chips { gl518sm_r00, gl518sm_r80 };
83 83
84#define RAW_FROM_REG(val) val 84#define RAW_FROM_REG(val) val
85 85
86#define BOOL_FROM_REG(val) ((val)?0:1) 86#define BOOL_FROM_REG(val) ((val) ? 0 : 1)
87#define BOOL_TO_REG(val) ((val)?0:1) 87#define BOOL_TO_REG(val) ((val) ? 0 : 1)
88 88
89#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0? \ 89#define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \
90 (val)-500:(val)+500)/1000)+119),0,255)) 90 (val) - 500 : \
91 (val) + 500) / 1000) + 119), 0, 255)
91#define TEMP_FROM_REG(val) (((val) - 119) * 1000) 92#define TEMP_FROM_REG(val) (((val) - 119) * 1000)
92 93
93static inline u8 FAN_TO_REG(long rpm, int div) 94static inline u8 FAN_TO_REG(long rpm, int div)
@@ -98,13 +99,13 @@ static inline u8 FAN_TO_REG(long rpm, int div)
98 rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div; 99 rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div;
99 return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255); 100 return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
100} 101}
101#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val)*(div)))) 102#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div))))
102 103
103#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 104#define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255)
104#define IN_FROM_REG(val) ((val)*19) 105#define IN_FROM_REG(val) ((val) * 19)
105 106
106#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 107#define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255)
107#define VDD_FROM_REG(val) (((val)*95+2)/4) 108#define VDD_FROM_REG(val) (((val) * 95 + 2) / 4)
108 109
109#define DIV_FROM_REG(val) (1 << (val)) 110#define DIV_FROM_REG(val) (1 << (val))
110 111
@@ -169,7 +170,8 @@ static struct i2c_driver gl518_driver = {
169 */ 170 */
170 171
171#define show(type, suffix, value) \ 172#define show(type, suffix, value) \
172static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 173static ssize_t show_##suffix(struct device *dev, \
174 struct device_attribute *attr, char *buf) \
173{ \ 175{ \
174 struct gl518_data *data = gl518_update_device(dev); \ 176 struct gl518_data *data = gl518_update_device(dev); \
175 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ 177 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
@@ -222,12 +224,16 @@ static ssize_t show_fan_div(struct device *dev,
222} 224}
223 225
224#define set(type, suffix, value, reg) \ 226#define set(type, suffix, value, reg) \
225static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 227static ssize_t set_##suffix(struct device *dev, \
226 size_t count) \ 228 struct device_attribute *attr, \
229 const char *buf, size_t count) \
227{ \ 230{ \
228 struct i2c_client *client = to_i2c_client(dev); \ 231 struct i2c_client *client = to_i2c_client(dev); \
229 struct gl518_data *data = i2c_get_clientdata(client); \ 232 struct gl518_data *data = i2c_get_clientdata(client); \
230 long val = simple_strtol(buf, NULL, 10); \ 233 long val; \
234 int err = kstrtol(buf, 10, &val); \
235 if (err) \
236 return err; \
231 \ 237 \
232 mutex_lock(&data->update_lock); \ 238 mutex_lock(&data->update_lock); \
233 data->value = type##_TO_REG(val); \ 239 data->value = type##_TO_REG(val); \
@@ -237,13 +243,17 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
237} 243}
238 244
239#define set_bits(type, suffix, value, reg, mask, shift) \ 245#define set_bits(type, suffix, value, reg, mask, shift) \
240static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 246static ssize_t set_##suffix(struct device *dev, \
241 size_t count) \ 247 struct device_attribute *attr, \
248 const char *buf, size_t count) \
242{ \ 249{ \
243 struct i2c_client *client = to_i2c_client(dev); \ 250 struct i2c_client *client = to_i2c_client(dev); \
244 struct gl518_data *data = i2c_get_clientdata(client); \ 251 struct gl518_data *data = i2c_get_clientdata(client); \
245 int regvalue; \ 252 int regvalue; \
246 unsigned long val = simple_strtoul(buf, NULL, 10); \ 253 unsigned long val; \
254 int err = kstrtoul(buf, 10, &val); \
255 if (err) \
256 return err; \
247 \ 257 \
248 mutex_lock(&data->update_lock); \ 258 mutex_lock(&data->update_lock); \
249 regvalue = gl518_read_value(client, reg); \ 259 regvalue = gl518_read_value(client, reg); \
@@ -280,7 +290,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
280 struct gl518_data *data = i2c_get_clientdata(client); 290 struct gl518_data *data = i2c_get_clientdata(client);
281 int nr = to_sensor_dev_attr(attr)->index; 291 int nr = to_sensor_dev_attr(attr)->index;
282 int regvalue; 292 int regvalue;
283 unsigned long val = simple_strtoul(buf, NULL, 10); 293 unsigned long val;
294 int err;
295
296 err = kstrtoul(buf, 10, &val);
297 if (err)
298 return err;
284 299
285 mutex_lock(&data->update_lock); 300 mutex_lock(&data->update_lock);
286 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 301 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
@@ -308,13 +323,26 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
308 struct gl518_data *data = i2c_get_clientdata(client); 323 struct gl518_data *data = i2c_get_clientdata(client);
309 int nr = to_sensor_dev_attr(attr)->index; 324 int nr = to_sensor_dev_attr(attr)->index;
310 int regvalue; 325 int regvalue;
311 unsigned long val = simple_strtoul(buf, NULL, 10); 326 unsigned long val;
327 int err;
328
329 err = kstrtoul(buf, 10, &val);
330 if (err)
331 return err;
312 332
313 switch (val) { 333 switch (val) {
314 case 1: val = 0; break; 334 case 1:
315 case 2: val = 1; break; 335 val = 0;
316 case 4: val = 2; break; 336 break;
317 case 8: val = 3; break; 337 case 2:
338 val = 1;
339 break;
340 case 4:
341 val = 2;
342 break;
343 case 8:
344 val = 3;
345 break;
318 default: 346 default:
319 dev_err(dev, "Invalid fan clock divider %lu, choose one " 347 dev_err(dev, "Invalid fan clock divider %lu, choose one "
320 "of 1, 2, 4 or 8\n", val); 348 "of 1, 2, 4 or 8\n", val);
@@ -395,8 +423,12 @@ static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
395 struct gl518_data *data = i2c_get_clientdata(client); 423 struct gl518_data *data = i2c_get_clientdata(client);
396 int bitnr = to_sensor_dev_attr(attr)->index; 424 int bitnr = to_sensor_dev_attr(attr)->index;
397 unsigned long bit; 425 unsigned long bit;
426 int err;
427
428 err = kstrtoul(buf, 10, &bit);
429 if (err)
430 return err;
398 431
399 bit = simple_strtoul(buf, NULL, 10);
400 if (bit & ~1) 432 if (bit & ~1)
401 return -EINVAL; 433 return -EINVAL;
402 434
@@ -528,12 +560,14 @@ static int gl518_probe(struct i2c_client *client,
528 gl518_init_client(client); 560 gl518_init_client(client);
529 561
530 /* Register sysfs hooks */ 562 /* Register sysfs hooks */
531 if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) 563 err = sysfs_create_group(&client->dev.kobj, &gl518_group);
564 if (err)
532 goto exit_free; 565 goto exit_free;
533 if (data->type == gl518sm_r80) 566 if (data->type == gl518sm_r80) {
534 if ((err = sysfs_create_group(&client->dev.kobj, 567 err = sysfs_create_group(&client->dev.kobj, &gl518_group_r80);
535 &gl518_group_r80))) 568 if (err)
536 goto exit_remove_files; 569 goto exit_remove_files;
570 }
537 571
538 data->hwmon_dev = hwmon_device_register(&client->dev); 572 data->hwmon_dev = hwmon_device_register(&client->dev);
539 if (IS_ERR(data->hwmon_dev)) { 573 if (IS_ERR(data->hwmon_dev)) {
@@ -554,8 +588,10 @@ exit:
554} 588}
555 589
556 590
557/* Called when we have found a new GL518SM. 591/*
558 Note that we preserve D4:NoFan2 and D2:beep_enable. */ 592 * Called when we have found a new GL518SM.
593 * Note that we preserve D4:NoFan2 and D2:beep_enable.
594 */
559static void gl518_init_client(struct i2c_client *client) 595static void gl518_init_client(struct i2c_client *client)
560{ 596{
561 /* Make sure we leave D7:Reset untouched */ 597 /* Make sure we leave D7:Reset untouched */
@@ -585,9 +621,11 @@ static int gl518_remove(struct i2c_client *client)
585 return 0; 621 return 0;
586} 622}
587 623
588/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 624/*
589 GL518 uses a high-byte first convention, which is exactly opposite to 625 * Registers 0x07 to 0x0c are word-sized, others are byte-sized
590 the SMBus standard. */ 626 * GL518 uses a high-byte first convention, which is exactly opposite to
627 * the SMBus standard.
628 */
591static int gl518_read_value(struct i2c_client *client, u8 reg) 629static int gl518_read_value(struct i2c_client *client, u8 reg)
592{ 630{
593 if ((reg >= 0x07) && (reg <= 0x0c)) 631 if ((reg >= 0x07) && (reg <= 0x0c))