2020-12-22 13:33:36

by Zheng Yongjun

[permalink] [raw]
Subject: [PATCH -next] i2c: busses: use DIV_ROUND_UP macro to do calculation

Don't open-code DIV_ROUND_UP() kernel macro.

Signed-off-by: Zheng Yongjun <[email protected]>
---
drivers/i2c/busses/i2c-imx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index e6f8d6e45a15..346c196cbce7 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -529,7 +529,7 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,

i2c_imx->cur_clk = i2c_clk_rate;

- div = (i2c_clk_rate + i2c_imx->bitrate - 1) / i2c_imx->bitrate;
+ div = DIV_ROUND_UP(i2c_clk_rate, i2c_imx->bitrate);
if (div < i2c_clk_div[0].div)
i = 0;
else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div)
@@ -547,8 +547,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
* This delay is used in I2C bus disable function
* to fix chip hardware bug.
*/
- i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div
- + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
+ i2c_imx->disable_delay = DIV_ROUND_UP(500000U * i2c_clk_div[i].div,
+ i2c_clk_rate / 2);

#ifdef CONFIG_I2C_DEBUG_BUS
dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n",
--
2.22.0


2020-12-22 14:12:26

by Fabio Estevam

[permalink] [raw]
Subject: Re: [PATCH -next] i2c: busses: use DIV_ROUND_UP macro to do calculation

Hi Zheng,

On Tue, Dec 22, 2020 at 10:31 AM Zheng Yongjun <[email protected]> wrote:
>
> Don't open-code DIV_ROUND_UP() kernel macro.
>
> Signed-off-by: Zheng Yongjun <[email protected]>

Reviewed-by: Fabio Estevam <[email protected]>

2020-12-22 22:27:31

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH -next] i2c: busses: use DIV_ROUND_UP macro to do calculation

On Tue, Dec 22, 2020 at 09:31:31PM +0800, Zheng Yongjun wrote:
> Don't open-code DIV_ROUND_UP() kernel macro.
>
> Signed-off-by: Zheng Yongjun <[email protected]>

LGTM,

Acked-by: Uwe Kleine-K?nig <[email protected]>

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (427.00 B)
signature.asc (499.00 B)
Download all attachments

2021-01-05 16:50:07

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH -next] i2c: busses: use DIV_ROUND_UP macro to do calculation

On Tue, Dec 22, 2020 at 09:31:31PM +0800, Zheng Yongjun wrote:
> Don't open-code DIV_ROUND_UP() kernel macro.
>
> Signed-off-by: Zheng Yongjun <[email protected]>

Applied to for-next, thanks!


Attachments:
(No filename) (209.00 B)
signature.asc (849.00 B)
Download all attachments