Skip to content

Commit 385bb1c

Browse files
prabhakarladWolfram Sang
authored andcommitted
i2c: riic: Use predefined macro and simplify clock tick calculation
Replace the hardcoded `1000000000` with the predefined `NSEC_PER_SEC` macro for clarity. Simplify the code by introducing a `ns_per_tick` variable to store `NSEC_PER_SEC / rate`, reducing redundancy and improving readability. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 9ae0e7f commit 385bb1c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/i2c/busses/i2c-riic.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <linux/platform_device.h>
4747
#include <linux/pm_runtime.h>
4848
#include <linux/reset.h>
49+
#include <linux/time.h>
4950

5051
#define ICCR1_ICE BIT(7)
5152
#define ICCR1_IICRST BIT(6)
@@ -313,6 +314,7 @@ static int riic_init_hw(struct riic_dev *riic)
313314
{
314315
int ret;
315316
unsigned long rate;
317+
unsigned long ns_per_tick;
316318
int total_ticks, cks, brl, brh;
317319
struct i2c_timings *t = &riic->i2c_t;
318320
struct device *dev = riic->adapter.dev.parent;
@@ -376,8 +378,9 @@ static int riic_init_hw(struct riic_dev *riic)
376378
* Remove clock ticks for rise and fall times. Convert ns to clock
377379
* ticks.
378380
*/
379-
brl -= t->scl_fall_ns / (1000000000 / rate);
380-
brh -= t->scl_rise_ns / (1000000000 / rate);
381+
ns_per_tick = NSEC_PER_SEC / rate;
382+
brl -= t->scl_fall_ns / ns_per_tick;
383+
brh -= t->scl_rise_ns / ns_per_tick;
381384

382385
/* Adjust for min register values for when SCLE=1 and NFE=1 */
383386
if (brl < 1)
@@ -387,8 +390,7 @@ static int riic_init_hw(struct riic_dev *riic)
387390

388391
pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n",
389392
rate / total_ticks, ((brl + 3) * 100) / (brl + brh + 6),
390-
t->scl_fall_ns / (1000000000 / rate),
391-
t->scl_rise_ns / (1000000000 / rate), cks, brl, brh);
393+
t->scl_fall_ns / ns_per_tick, t->scl_rise_ns / ns_per_tick, cks, brl, brh);
392394

393395
ret = pm_runtime_resume_and_get(dev);
394396
if (ret)

0 commit comments

Comments
 (0)