hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-designware-common.c
....@@ -24,6 +24,7 @@
2424 #include <linux/regmap.h>
2525 #include <linux/swab.h>
2626 #include <linux/types.h>
27
+#include <linux/units.h>
2728
2829 #include "i2c-designware-core.h"
2930
....@@ -347,7 +348,8 @@
347348 *
348349 * If your hardware is free from tHD;STA issue, try this one.
349350 */
350
- return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset;
351
+ return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * tSYMBOL, MICRO) -
352
+ 8 + offset;
351353 else
352354 /*
353355 * Conditional expression:
....@@ -363,8 +365,8 @@
363365 * The reason why we need to take into account "tf" here,
364366 * is the same as described in i2c_dw_scl_lcnt().
365367 */
366
- return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000
367
- - 3 + offset;
368
+ return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tSYMBOL + tf), MICRO) -
369
+ 3 + offset;
368370 }
369371
370372 u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
....@@ -380,7 +382,8 @@
380382 * account the fall time of SCL signal (tf). Default tf value
381383 * should be 0.3 us, for safety.
382384 */
383
- return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
385
+ return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tLOW + tf), MICRO) -
386
+ 1 + offset;
384387 }
385388
386389 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)