Skip to content

Commit 2b28054

Browse files
arndbAndi Shyti
authored andcommitted
i2c: mlxbf: avoid 64-bit division
The 64-bit division in mlxbf_i2c_get_ticks() causes link failures when compile-testing on 32-bit machines: ERROR: modpost: "__udivdi3" [drivers/i2c/busses/i2c-mlxbf.ko] undefined! Change this to a div_u64(), which should replace the constant division with a a multiply/shift combination in the mlxbf_i2c_get_ticks(). The frequency calculation functions require a slow library call but should be used much rarer. Fixes: 0538590 ("i2c: mlxbf: Allow build with COMPILE_TEST") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20250520152600.1975628-1-arnd@kernel.org Signed-off-by: Andi Shyti <andi@smida.it>
1 parent 3b7d8d1 commit 2b28054

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/i2c/busses/i2c-mlxbf.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ static u32 mlxbf_i2c_get_ticks(struct mlxbf_i2c_priv *priv, u64 nanoseconds,
10831083
* Frequency
10841084
*/
10851085
frequency = priv->frequency;
1086-
ticks = (nanoseconds * frequency) / MLXBF_I2C_FREQUENCY_1GHZ;
1086+
ticks = div_u64(nanoseconds * frequency, MLXBF_I2C_FREQUENCY_1GHZ);
10871087
/*
10881088
* The number of ticks is rounded down and if minimum is equal to 1
10891089
* then add one tick.
@@ -1460,9 +1460,8 @@ static u64 mlxbf_i2c_calculate_freq_from_tyu(struct mlxbf_i2c_resource *corepll_
14601460
* and PadFrequency, respectively.
14611461
*/
14621462
core_frequency = MLXBF_I2C_PLL_IN_FREQ * (++core_f);
1463-
core_frequency /= (++core_r) * (++core_od);
14641463

1465-
return core_frequency;
1464+
return div_u64(core_frequency, (++core_r) * (++core_od));
14661465
}
14671466

14681467
static u64 mlxbf_i2c_calculate_freq_from_yu(struct mlxbf_i2c_resource *corepll_res)
@@ -1491,9 +1490,8 @@ static u64 mlxbf_i2c_calculate_freq_from_yu(struct mlxbf_i2c_resource *corepll_r
14911490
* and PadFrequency, respectively.
14921491
*/
14931492
corepll_frequency = (MLXBF_I2C_PLL_IN_FREQ * core_f) / MLNXBF_I2C_COREPLL_CONST;
1494-
corepll_frequency /= (++core_r) * (++core_od);
14951493

1496-
return corepll_frequency;
1494+
return div_u64(corepll_frequency, (++core_r) * (++core_od));
14971495
}
14981496

14991497
static int mlxbf_i2c_calculate_corepll_freq(struct platform_device *pdev,

0 commit comments

Comments
 (0)