| .. | .. |
|---|
| 24 | 24 | #include <linux/regmap.h> |
|---|
| 25 | 25 | #include <linux/swab.h> |
|---|
| 26 | 26 | #include <linux/types.h> |
|---|
| 27 | +#include <linux/units.h> |
|---|
| 27 | 28 | |
|---|
| 28 | 29 | #include "i2c-designware-core.h" |
|---|
| 29 | 30 | |
|---|
| .. | .. |
|---|
| 347 | 348 | * |
|---|
| 348 | 349 | * If your hardware is free from tHD;STA issue, try this one. |
|---|
| 349 | 350 | */ |
|---|
| 350 | | - return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset; |
|---|
| 351 | + return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * tSYMBOL, MICRO) - |
|---|
| 352 | + 8 + offset; |
|---|
| 351 | 353 | else |
|---|
| 352 | 354 | /* |
|---|
| 353 | 355 | * Conditional expression: |
|---|
| .. | .. |
|---|
| 363 | 365 | * The reason why we need to take into account "tf" here, |
|---|
| 364 | 366 | * is the same as described in i2c_dw_scl_lcnt(). |
|---|
| 365 | 367 | */ |
|---|
| 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; |
|---|
| 368 | 370 | } |
|---|
| 369 | 371 | |
|---|
| 370 | 372 | u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) |
|---|
| .. | .. |
|---|
| 380 | 382 | * account the fall time of SCL signal (tf). Default tf value |
|---|
| 381 | 383 | * should be 0.3 us, for safety. |
|---|
| 382 | 384 | */ |
|---|
| 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; |
|---|
| 384 | 387 | } |
|---|
| 385 | 388 | |
|---|
| 386 | 389 | int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev) |
|---|