watchdog: s3c2410_wdt: Handle rounding a little better for timeout
[cascardo/linux.git] / drivers / watchdog / s3c2410_wdt.c
index 7d8fd04..8beaa17 100644 (file)
@@ -188,7 +188,7 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeou
        if (timeout < 1)
                return -EINVAL;
 
-       freq /= 128;
+       freq = DIV_ROUND_UP(freq, 128);
        count = timeout * freq;
 
        DBG("%s: count=%d, timeout=%d, freq=%lu\n",
@@ -200,21 +200,18 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeou
        */
 
        if (count >= 0x10000) {
-               for (divisor = 1; divisor <= 0x100; divisor++) {
-                       if ((count / divisor) < 0x10000)
-                               break;
-               }
+               divisor = DIV_ROUND_UP(count, 0xffff);
 
-               if ((count / divisor) >= 0x10000) {
+               if (divisor > 0x100) {
                        dev_err(wdt->dev, "timeout %d too big\n", timeout);
                        return -EINVAL;
                }
        }
 
        DBG("%s: timeout=%d, divisor=%d, count=%d (%08x)\n",
-           __func__, timeout, divisor, count, count/divisor);
+           __func__, timeout, divisor, count, DIV_ROUND_UP(count, divisor));
 
-       count /= divisor;
+       count = DIV_ROUND_UP(count, divisor);
        wdt->count = count;
 
        /* update the pre-scaler */
@@ -264,7 +261,7 @@ static irqreturn_t s3c2410wdt_irq(int irqno, void *param)
        return IRQ_HANDLED;
 }
 
-#ifdef CONFIG_CPU_FREQ
+#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
 
 static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb,
                                          unsigned long val, void *data)