i2c: designware: Use DIV_ROUND_CLOSEST() macro
[ Upstream commit c045214a0f31dd5d6be716ed2f119b57b6c5d3a2 ] Instead of open-coding DIV_ROUND_CLOSEST() and similar use the macros directly. While at it, replace numbers with predefined SI metric prefixes. No functional change intended. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@kernel.org> Stable-dep-of: c8c37bc51451 ("i2c: designware: use casting of u64 in clock multiplication to avoid overflow") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
8ebc2efcb6
commit
8949ef3a7a
@@ -24,6 +24,7 @@
|
|||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/swab.h>
|
#include <linux/swab.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <linux/units.h>
|
||||||
|
|
||||||
#include "i2c-designware-core.h"
|
#include "i2c-designware-core.h"
|
||||||
|
|
||||||
@@ -347,7 +348,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
|
|||||||
*
|
*
|
||||||
* If your hardware is free from tHD;STA issue, try this one.
|
* If your hardware is free from tHD;STA issue, try this one.
|
||||||
*/
|
*/
|
||||||
return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset;
|
return DIV_ROUND_CLOSEST(ic_clk * tSYMBOL, MICRO) - 8 + offset;
|
||||||
else
|
else
|
||||||
/*
|
/*
|
||||||
* Conditional expression:
|
* Conditional expression:
|
||||||
@@ -363,8 +364,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
|
|||||||
* The reason why we need to take into account "tf" here,
|
* The reason why we need to take into account "tf" here,
|
||||||
* is the same as described in i2c_dw_scl_lcnt().
|
* is the same as described in i2c_dw_scl_lcnt().
|
||||||
*/
|
*/
|
||||||
return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000
|
return DIV_ROUND_CLOSEST(ic_clk * (tSYMBOL + tf), MICRO) - 3 + offset;
|
||||||
- 3 + offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
|
u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
|
||||||
@@ -380,7 +380,7 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
|
|||||||
* account the fall time of SCL signal (tf). Default tf value
|
* account the fall time of SCL signal (tf). Default tf value
|
||||||
* should be 0.3 us, for safety.
|
* should be 0.3 us, for safety.
|
||||||
*/
|
*/
|
||||||
return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
|
return DIV_ROUND_CLOSEST(ic_clk * (tLOW + tf), MICRO) - 1 + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)
|
int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)
|
||||||
|
@@ -32,12 +32,13 @@
|
|||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/suspend.h>
|
#include <linux/suspend.h>
|
||||||
|
#include <linux/units.h>
|
||||||
|
|
||||||
#include "i2c-designware-core.h"
|
#include "i2c-designware-core.h"
|
||||||
|
|
||||||
static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
|
static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
|
||||||
{
|
{
|
||||||
return clk_get_rate(dev->clk)/1000;
|
return clk_get_rate(dev->clk) / KILO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI
|
#ifdef CONFIG_ACPI
|
||||||
@@ -284,7 +285,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
if (!dev->sda_hold_time && t->sda_hold_ns)
|
if (!dev->sda_hold_time && t->sda_hold_ns)
|
||||||
dev->sda_hold_time =
|
dev->sda_hold_time =
|
||||||
div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
|
DIV_S64_ROUND_CLOSEST(clk_khz * t->sda_hold_ns, MICRO);
|
||||||
}
|
}
|
||||||
|
|
||||||
adap = &dev->adapter;
|
adap = &dev->adapter;
|
||||||
|
Reference in New Issue
Block a user