Skip to content

Commit 8a83a76

Browse files
committed
i2c: busses: i2c-designware-master: make sure it links for ARM
Uue the proper math APIs for doing u64 division on 32bit architectures. Signed-off-by: Nuno Sá <nuno.sa@analog.com>
1 parent 102df26 commit 8a83a76

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/i2c/busses/i2c-designware-master.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/i2c.h>
2020
#include <linux/interrupt.h>
2121
#include <linux/io.h>
22+
#include <linux/math64.h>
2223
#include <linux/module.h>
2324
#include <linux/pinctrl/consumer.h>
2425
#include <linux/pm_runtime.h>
@@ -60,10 +61,10 @@ static void clock_calc(struct dw_i2c_dev *dev, u32 *hcnt, u32 *lcnt)
6061
(wanted_khz <= 400) ?
6162
linear_interpolate(wanted_khz, 100, 400, 4000, 600) :
6263
linear_interpolate(wanted_khz, 400, 1000, 600, 260);
63-
u32 high_cycles = (u32)(((u64)clk_khz * min_high_ns + 999999) / 1000000) + 1;
64-
u32 extra_high_cycles = (u32)((u64)clk_khz * t->scl_fall_ns / 1000000);
65-
u32 extra_low_cycles = (u32)((u64)clk_khz * t->scl_rise_ns / 1000000);
66-
u32 period = ((u64)clk_khz + wanted_khz - 1) / wanted_khz;
64+
u32 high_cycles = div_u64((u64)clk_khz * min_high_ns + 999999, 1000000) + 1;
65+
u32 extra_high_cycles = div_u64((u64)clk_khz * t->scl_fall_ns, 1000000);
66+
u32 extra_low_cycles = div_u64((u64)clk_khz * t->scl_rise_ns, 1000000);
67+
u32 period = div_u64((u64)clk_khz + wanted_khz - 1, wanted_khz);
6768

6869
*hcnt = u16_clamp(high_cycles - extra_high_cycles);
6970
*lcnt = u16_clamp(period - high_cycles - extra_low_cycles);

0 commit comments

Comments
 (0)