diff options
-rw-r--r-- | drivers/hwmon/f75375s.c | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index 95cbfb3a7077..92b939b274b7 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * Datasheets available at: | 6 | * Datasheets available at: |
7 | * | 7 | * |
8 | * f75375: | 8 | * f75375: |
9 | * http://www.fintek.com.tw/files/productfiles/F75375_V026P.pdf | 9 | * http://www.fintek.com.tw/files/productfiles/F75375_V026P.pdf |
10 | * | 10 | * |
11 | * f75373: | 11 | * f75373: |
12 | * http://www.fintek.com.tw/files/productfiles/F75373_V025P.pdf | 12 | * http://www.fintek.com.tw/files/productfiles/F75373_V025P.pdf |
@@ -146,8 +146,8 @@ static inline int f75375_read8(struct i2c_client *client, u8 reg) | |||
146 | /* in most cases, should be called while holding update_lock */ | 146 | /* in most cases, should be called while holding update_lock */ |
147 | static inline u16 f75375_read16(struct i2c_client *client, u8 reg) | 147 | static inline u16 f75375_read16(struct i2c_client *client, u8 reg) |
148 | { | 148 | { |
149 | return ((i2c_smbus_read_byte_data(client, reg) << 8) | 149 | return (i2c_smbus_read_byte_data(client, reg) << 8) |
150 | | i2c_smbus_read_byte_data(client, reg + 1)); | 150 | | i2c_smbus_read_byte_data(client, reg + 1); |
151 | } | 151 | } |
152 | 152 | ||
153 | static inline void f75375_write8(struct i2c_client *client, u8 reg, | 153 | static inline void f75375_write8(struct i2c_client *client, u8 reg, |
@@ -226,14 +226,14 @@ static inline u16 rpm_from_reg(u16 reg) | |||
226 | { | 226 | { |
227 | if (reg == 0 || reg == 0xffff) | 227 | if (reg == 0 || reg == 0xffff) |
228 | return 0; | 228 | return 0; |
229 | return (1500000 / reg); | 229 | return 1500000 / reg; |
230 | } | 230 | } |
231 | 231 | ||
232 | static inline u16 rpm_to_reg(int rpm) | 232 | static inline u16 rpm_to_reg(int rpm) |
233 | { | 233 | { |
234 | if (rpm < 367 || rpm > 0xffff) | 234 | if (rpm < 367 || rpm > 0xffff) |
235 | return 0xffff; | 235 | return 0xffff; |
236 | return (1500000 / rpm); | 236 | return 1500000 / rpm; |
237 | } | 237 | } |
238 | 238 | ||
239 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 239 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
@@ -242,7 +242,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
242 | int nr = to_sensor_dev_attr(attr)->index; | 242 | int nr = to_sensor_dev_attr(attr)->index; |
243 | struct i2c_client *client = to_i2c_client(dev); | 243 | struct i2c_client *client = to_i2c_client(dev); |
244 | struct f75375_data *data = i2c_get_clientdata(client); | 244 | struct f75375_data *data = i2c_get_clientdata(client); |
245 | int val = simple_strtoul(buf, NULL, 10); | 245 | unsigned long val; |
246 | int err; | ||
247 | |||
248 | err = kstrtoul(buf, 10, &val); | ||
249 | if (err < 0) | ||
250 | return err; | ||
246 | 251 | ||
247 | mutex_lock(&data->update_lock); | 252 | mutex_lock(&data->update_lock); |
248 | data->fan_min[nr] = rpm_to_reg(val); | 253 | data->fan_min[nr] = rpm_to_reg(val); |
@@ -257,7 +262,12 @@ static ssize_t set_fan_exp(struct device *dev, struct device_attribute *attr, | |||
257 | int nr = to_sensor_dev_attr(attr)->index; | 262 | int nr = to_sensor_dev_attr(attr)->index; |
258 | struct i2c_client *client = to_i2c_client(dev); | 263 | struct i2c_client *client = to_i2c_client(dev); |
259 | struct f75375_data *data = i2c_get_clientdata(client); | 264 | struct f75375_data *data = i2c_get_clientdata(client); |
260 | int val = simple_strtoul(buf, NULL, 10); | 265 | unsigned long val; |
266 | int err; | ||
267 | |||
268 | err = kstrtoul(buf, 10, &val); | ||
269 | if (err < 0) | ||
270 | return err; | ||
261 | 271 | ||
262 | mutex_lock(&data->update_lock); | 272 | mutex_lock(&data->update_lock); |
263 | data->fan_exp[nr] = rpm_to_reg(val); | 273 | data->fan_exp[nr] = rpm_to_reg(val); |
@@ -272,7 +282,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
272 | int nr = to_sensor_dev_attr(attr)->index; | 282 | int nr = to_sensor_dev_attr(attr)->index; |
273 | struct i2c_client *client = to_i2c_client(dev); | 283 | struct i2c_client *client = to_i2c_client(dev); |
274 | struct f75375_data *data = i2c_get_clientdata(client); | 284 | struct f75375_data *data = i2c_get_clientdata(client); |
275 | int val = simple_strtoul(buf, NULL, 10); | 285 | unsigned long val; |
286 | int err; | ||
287 | |||
288 | err = kstrtoul(buf, 10, &val); | ||
289 | if (err < 0) | ||
290 | return err; | ||
276 | 291 | ||
277 | mutex_lock(&data->update_lock); | 292 | mutex_lock(&data->update_lock); |
278 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); | 293 | data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); |
@@ -327,8 +342,12 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, | |||
327 | int nr = to_sensor_dev_attr(attr)->index; | 342 | int nr = to_sensor_dev_attr(attr)->index; |
328 | struct i2c_client *client = to_i2c_client(dev); | 343 | struct i2c_client *client = to_i2c_client(dev); |
329 | struct f75375_data *data = i2c_get_clientdata(client); | 344 | struct f75375_data *data = i2c_get_clientdata(client); |
330 | int val = simple_strtoul(buf, NULL, 10); | 345 | unsigned long val; |
331 | int err = 0; | 346 | int err; |
347 | |||
348 | err = kstrtoul(buf, 10, &val); | ||
349 | if (err < 0) | ||
350 | return err; | ||
332 | 351 | ||
333 | mutex_lock(&data->update_lock); | 352 | mutex_lock(&data->update_lock); |
334 | err = set_pwm_enable_direct(client, nr, val); | 353 | err = set_pwm_enable_direct(client, nr, val); |
@@ -342,8 +361,13 @@ static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *attr, | |||
342 | int nr = to_sensor_dev_attr(attr)->index; | 361 | int nr = to_sensor_dev_attr(attr)->index; |
343 | struct i2c_client *client = to_i2c_client(dev); | 362 | struct i2c_client *client = to_i2c_client(dev); |
344 | struct f75375_data *data = i2c_get_clientdata(client); | 363 | struct f75375_data *data = i2c_get_clientdata(client); |
345 | int val = simple_strtoul(buf, NULL, 10); | 364 | unsigned long val; |
346 | u8 conf = 0; | 365 | int err; |
366 | u8 conf; | ||
367 | |||
368 | err = kstrtoul(buf, 10, &val); | ||
369 | if (err < 0) | ||
370 | return err; | ||
347 | 371 | ||
348 | if (!(val == 0 || val == 1)) | 372 | if (!(val == 0 || val == 1)) |
349 | return -EINVAL; | 373 | return -EINVAL; |
@@ -410,7 +434,13 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
410 | int nr = to_sensor_dev_attr(attr)->index; | 434 | int nr = to_sensor_dev_attr(attr)->index; |
411 | struct i2c_client *client = to_i2c_client(dev); | 435 | struct i2c_client *client = to_i2c_client(dev); |
412 | struct f75375_data *data = i2c_get_clientdata(client); | 436 | struct f75375_data *data = i2c_get_clientdata(client); |
413 | int val = simple_strtoul(buf, NULL, 10); | 437 | unsigned long val; |
438 | int err; | ||
439 | |||
440 | err = kstrtoul(buf, 10, &val); | ||
441 | if (err < 0) | ||
442 | return err; | ||
443 | |||
414 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); | 444 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); |
415 | mutex_lock(&data->update_lock); | 445 | mutex_lock(&data->update_lock); |
416 | data->in_max[nr] = val; | 446 | data->in_max[nr] = val; |
@@ -425,7 +455,13 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
425 | int nr = to_sensor_dev_attr(attr)->index; | 455 | int nr = to_sensor_dev_attr(attr)->index; |
426 | struct i2c_client *client = to_i2c_client(dev); | 456 | struct i2c_client *client = to_i2c_client(dev); |
427 | struct f75375_data *data = i2c_get_clientdata(client); | 457 | struct f75375_data *data = i2c_get_clientdata(client); |
428 | int val = simple_strtoul(buf, NULL, 10); | 458 | unsigned long val; |
459 | int err; | ||
460 | |||
461 | err = kstrtoul(buf, 10, &val); | ||
462 | if (err < 0) | ||
463 | return err; | ||
464 | |||
429 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); | 465 | val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff); |
430 | mutex_lock(&data->update_lock); | 466 | mutex_lock(&data->update_lock); |
431 | data->in_min[nr] = val; | 467 | data->in_min[nr] = val; |
@@ -466,7 +502,13 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
466 | int nr = to_sensor_dev_attr(attr)->index; | 502 | int nr = to_sensor_dev_attr(attr)->index; |
467 | struct i2c_client *client = to_i2c_client(dev); | 503 | struct i2c_client *client = to_i2c_client(dev); |
468 | struct f75375_data *data = i2c_get_clientdata(client); | 504 | struct f75375_data *data = i2c_get_clientdata(client); |
469 | int val = simple_strtol(buf, NULL, 10); | 505 | unsigned long val; |
506 | int err; | ||
507 | |||
508 | err = kstrtoul(buf, 10, &val); | ||
509 | if (err < 0) | ||
510 | return err; | ||
511 | |||
470 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); | 512 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); |
471 | mutex_lock(&data->update_lock); | 513 | mutex_lock(&data->update_lock); |
472 | data->temp_high[nr] = val; | 514 | data->temp_high[nr] = val; |
@@ -481,7 +523,13 @@ static ssize_t set_temp_max_hyst(struct device *dev, | |||
481 | int nr = to_sensor_dev_attr(attr)->index; | 523 | int nr = to_sensor_dev_attr(attr)->index; |
482 | struct i2c_client *client = to_i2c_client(dev); | 524 | struct i2c_client *client = to_i2c_client(dev); |
483 | struct f75375_data *data = i2c_get_clientdata(client); | 525 | struct f75375_data *data = i2c_get_clientdata(client); |
484 | int val = simple_strtol(buf, NULL, 10); | 526 | unsigned long val; |
527 | int err; | ||
528 | |||
529 | err = kstrtoul(buf, 10, &val); | ||
530 | if (err < 0) | ||
531 | return err; | ||
532 | |||
485 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); | 533 | val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127); |
486 | mutex_lock(&data->update_lock); | 534 | mutex_lock(&data->update_lock); |
487 | data->temp_max_hyst[nr] = val; | 535 | data->temp_max_hyst[nr] = val; |
@@ -624,14 +672,16 @@ static int f75375_probe(struct i2c_client *client, | |||
624 | if (!i2c_check_functionality(client->adapter, | 672 | if (!i2c_check_functionality(client->adapter, |
625 | I2C_FUNC_SMBUS_BYTE_DATA)) | 673 | I2C_FUNC_SMBUS_BYTE_DATA)) |
626 | return -EIO; | 674 | return -EIO; |
627 | if (!(data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL))) | 675 | data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL); |
676 | if (!data) | ||
628 | return -ENOMEM; | 677 | return -ENOMEM; |
629 | 678 | ||
630 | i2c_set_clientdata(client, data); | 679 | i2c_set_clientdata(client, data); |
631 | mutex_init(&data->update_lock); | 680 | mutex_init(&data->update_lock); |
632 | data->kind = id->driver_data; | 681 | data->kind = id->driver_data; |
633 | 682 | ||
634 | if ((err = sysfs_create_group(&client->dev.kobj, &f75375_group))) | 683 | err = sysfs_create_group(&client->dev.kobj, &f75375_group); |
684 | if (err) | ||
635 | goto exit_free; | 685 | goto exit_free; |
636 | 686 | ||
637 | if (data->kind == f75375) { | 687 | if (data->kind == f75375) { |