aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2015-04-16 15:43:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:03:55 -0400
commitcdb1dc3f1ca5c5899e5fa186afe20390bd8c00dc (patch)
tree3f5f68cd7ecb9b1b1d8e47c62681f2c5c30b277b
parent0f3721c51ec5643e00f07dd3bbc5712c72fc62b2 (diff)
hwmon: (w83795) use find_closest_descending() in pwm_freq_to_reg()
Replace the loop iterating over pwm_freq_cksel0 with a call to find_closest_descending(). Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/hwmon/w83795.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 21894131190f..49276bbdac3d 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/util_macros.h>
38 39
39/* Addresses to scan */ 40/* Addresses to scan */
40static const unsigned short normal_i2c[] = { 41static const unsigned short normal_i2c[] = {
@@ -308,11 +309,8 @@ static u8 pwm_freq_to_reg(unsigned long val, u16 clkin)
308 unsigned long best0, best1; 309 unsigned long best0, best1;
309 310
310 /* Best fit for cksel = 0 */ 311 /* Best fit for cksel = 0 */
311 for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { 312 reg0 = find_closest_descending(val, pwm_freq_cksel0,
312 if (val > (pwm_freq_cksel0[reg0] + 313 ARRAY_SIZE(pwm_freq_cksel0));
313 pwm_freq_cksel0[reg0 + 1]) / 2)
314 break;
315 }
316 if (val < 375) /* cksel = 1 can't beat this */ 314 if (val < 375) /* cksel = 1 can't beat this */
317 return reg0; 315 return reg0;
318 best0 = pwm_freq_cksel0[reg0]; 316 best0 = pwm_freq_cksel0[reg0];