diff options
author | Iker Perez del Palomar Sustatxa <iker.perez@codethink.co.uk> | 2019-08-08 04:02:46 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2019-09-03 15:47:17 -0400 |
commit | 4b5be3c1738076284a1fb5aecbe3c960c6d9bb71 (patch) | |
tree | 00ee460bfd0069244192a4a08b6f2632eac62ba9 /drivers/hwmon | |
parent | 7f1a300f8abd11593f61c21a550c30144046124d (diff) |
hwmon: (lm75) Modularize lm75_write and make hwmon_chip writable
* Create two separate functions to write into hwmon_temp and hwmon_chip.
* Call the functions from lm75_write.
* Make hwm_chip writable if the chip supports more than one sample time.
Signed-off-by: Iker Perez del Palomar Sustatxa <iker.perez@codethink.co.uk>
Link: https://lore.kernel.org/r/20190808080246.8371-5-iker.perez@codethink.co.uk
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm75.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 34f90ea1e401..f68ef9d451ab 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/of_device.h> | 16 | #include <linux/of_device.h> |
17 | #include <linux/of.h> | 17 | #include <linux/of.h> |
18 | #include <linux/regmap.h> | 18 | #include <linux/regmap.h> |
19 | #include <linux/util_macros.h> | ||
19 | #include "lm75.h" | 20 | #include "lm75.h" |
20 | 21 | ||
21 | /* | 22 | /* |
@@ -325,16 +326,12 @@ static int lm75_read(struct device *dev, enum hwmon_sensor_types type, | |||
325 | return 0; | 326 | return 0; |
326 | } | 327 | } |
327 | 328 | ||
328 | static int lm75_write(struct device *dev, enum hwmon_sensor_types type, | 329 | static int lm75_write_temp(struct device *dev, u32 attr, long temp) |
329 | u32 attr, int channel, long temp) | ||
330 | { | 330 | { |
331 | struct lm75_data *data = dev_get_drvdata(dev); | 331 | struct lm75_data *data = dev_get_drvdata(dev); |
332 | u8 resolution; | 332 | u8 resolution; |
333 | int reg; | 333 | int reg; |
334 | 334 | ||
335 | if (type != hwmon_temp) | ||
336 | return -EINVAL; | ||
337 | |||
338 | switch (attr) { | 335 | switch (attr) { |
339 | case hwmon_temp_max: | 336 | case hwmon_temp_max: |
340 | reg = LM75_REG_MAX; | 337 | reg = LM75_REG_MAX; |
@@ -362,13 +359,58 @@ static int lm75_write(struct device *dev, enum hwmon_sensor_types type, | |||
362 | return regmap_write(data->regmap, reg, (u16)temp); | 359 | return regmap_write(data->regmap, reg, (u16)temp); |
363 | } | 360 | } |
364 | 361 | ||
362 | static int lm75_write_chip(struct device *dev, u32 attr, long val) | ||
363 | { | ||
364 | struct lm75_data *data = dev_get_drvdata(dev); | ||
365 | u8 index; | ||
366 | s32 err; | ||
367 | |||
368 | switch (attr) { | ||
369 | case hwmon_chip_update_interval: | ||
370 | index = find_closest(val, data->params->sample_times, | ||
371 | (int)data->params->num_sample_times); | ||
372 | |||
373 | err = lm75_write_config(data, | ||
374 | data->params->sample_set_masks[index], | ||
375 | data->params->sample_clr_mask); | ||
376 | if (err) | ||
377 | return err; | ||
378 | data->sample_time = data->params->sample_times[index]; | ||
379 | |||
380 | if (data->params->resolutions) | ||
381 | data->resolution = data->params->resolutions[index]; | ||
382 | break; | ||
383 | default: | ||
384 | return -EINVAL; | ||
385 | } | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static int lm75_write(struct device *dev, enum hwmon_sensor_types type, | ||
390 | u32 attr, int channel, long val) | ||
391 | { | ||
392 | switch (type) { | ||
393 | case hwmon_chip: | ||
394 | return lm75_write_chip(dev, attr, val); | ||
395 | case hwmon_temp: | ||
396 | return lm75_write_temp(dev, attr, val); | ||
397 | default: | ||
398 | return -EINVAL; | ||
399 | } | ||
400 | return 0; | ||
401 | } | ||
402 | |||
365 | static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type, | 403 | static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type, |
366 | u32 attr, int channel) | 404 | u32 attr, int channel) |
367 | { | 405 | { |
406 | const struct lm75_data *config_data = data; | ||
407 | |||
368 | switch (type) { | 408 | switch (type) { |
369 | case hwmon_chip: | 409 | case hwmon_chip: |
370 | switch (attr) { | 410 | switch (attr) { |
371 | case hwmon_chip_update_interval: | 411 | case hwmon_chip_update_interval: |
412 | if (config_data->params->num_sample_times > 1) | ||
413 | return 0644; | ||
372 | return 0444; | 414 | return 0444; |
373 | } | 415 | } |
374 | break; | 416 | break; |