]> git.sur5r.net Git - u-boot/commitdiff
replace DIV_ROUND with DIV_ROUND_CLOSEST
authorMasahiro Yamada <yamada.m@jp.panasonic.com>
Thu, 6 Nov 2014 18:03:26 +0000 (03:03 +0900)
committerTom Rini <trini@ti.com>
Thu, 20 Nov 2014 16:28:25 +0000 (11:28 -0500)
The Linux-compatible macro DIV_ROUND_CLOSEST is a bit more flexible
and safer than DIV_ROUND.

For example,
  foo = DIV_ROUND_CLOSEST(x, y++)
works expectedly, but
  foo = DIV_ROUND(x, y++)
does not. (y is incremented twice.)

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
arch/arm/cpu/arm926ejs/mxs/spl_power_init.c
arch/arm/cpu/armv7/omap-common/abb.c
drivers/misc/mxc_ocotp.c
lib/strmhz.c

index d25019a51ef2ab0aa58ac75b923898a885365959..1c54ab7de3bfc3726b1c823e47500a462607b1a4 100644 (file)
@@ -1002,7 +1002,8 @@ static void mxs_power_set_vddx(const struct mxs_vddx_cfg *cfg,
        uint32_t powered_by_linreg = 0;
        int adjust_up, tmp;
 
-       new_brownout = DIV_ROUND(new_target - new_brownout, cfg->step_mV);
+       new_brownout = DIV_ROUND_CLOSEST(new_target - new_brownout,
+                                        cfg->step_mV);
 
        cur_target = readl(cfg->reg);
        cur_target &= cfg->trg_mask;
index 423aeb980725c1bd700956f6cbfe50f40294e05b..a0add6643e1715a65a3e05a9b38cc7d08b809b41 100644 (file)
@@ -48,9 +48,9 @@ static void abb_setup_timings(u32 setup)
         */
 
        /* calculate SR2_WTCNT_VALUE */
-       sys_rate = DIV_ROUND(V_OSCK, 1000000);
-       clk_cycles = DIV_ROUND(OMAP_ABB_CLOCK_CYCLES * 10, sys_rate);
-       sr2_cnt = DIV_ROUND(OMAP_ABB_SETTLING_TIME * 10, clk_cycles);
+       sys_rate = DIV_ROUND_CLOSEST(V_OSCK, 1000000);
+       clk_cycles = DIV_ROUND_CLOSEST(OMAP_ABB_CLOCK_CYCLES * 10, sys_rate);
+       sr2_cnt = DIV_ROUND_CLOSEST(OMAP_ABB_SETTLING_TIME * 10, clk_cycles);
 
        setbits_le32(setup,
                     sr2_cnt << (ffs(OMAP_ABB_SETUP_SR2_WTCNT_VALUE_MASK) - 1));
index 3de1245699626aa4429dba9462ef398ef77bd63c..89737af9b73c417c61d55b5712d8c46f8b1ead4c 100644 (file)
@@ -122,8 +122,8 @@ static void set_timing(struct ocotp_regs *regs)
        relax = DIV_ROUND_UP(ipg_clk * BV_TIMING_RELAX_NS, 1000000000) - 1;
        strobe_read = DIV_ROUND_UP(ipg_clk * BV_TIMING_STROBE_READ_NS,
                                        1000000000) + 2 * (relax + 1) - 1;
-       strobe_prog = DIV_ROUND(ipg_clk * BV_TIMING_STROBE_PROG_US, 1000000) +
-                       2 * (relax + 1) - 1;
+       strobe_prog = DIV_ROUND_CLOSEST(ipg_clk * BV_TIMING_STROBE_PROG_US,
+                                               1000000) + 2 * (relax + 1) - 1;
 
        timing = BF(strobe_read, TIMING_STROBE_READ) |
                        BF(relax, TIMING_RELAX) |
index f9a17727f53b898e307a7b65853c00623f135909..5c16cc4fc7566dcfb7ff0eb6ccaed9074f5ecb4b 100644 (file)
@@ -11,11 +11,11 @@ char *strmhz (char *buf, unsigned long hz)
        long l, n;
        long m;
 
-       n = DIV_ROUND(hz, 1000) / 1000L;
+       n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L;
        l = sprintf (buf, "%ld", n);
 
        hz -= n * 1000000L;
-       m = DIV_ROUND(hz, 1000L);
+       m = DIV_ROUND_CLOSEST(hz, 1000L);
        if (m != 0)
                sprintf (buf + l, ".%03ld", m);
        return (buf);