Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Lad Prabhakar and committed by
Wolfram Sang
385bb1c2 9ae0e7f7

+6 -4
+6 -4
drivers/i2c/busses/i2c-riic.c
··· 46 46 #include <linux/platform_device.h> 47 47 #include <linux/pm_runtime.h> 48 48 #include <linux/reset.h> 49 + #include <linux/time.h> 49 50 50 51 #define ICCR1_ICE BIT(7) 51 52 #define ICCR1_IICRST BIT(6) ··· 314 313 { 315 314 int ret; 316 315 unsigned long rate; 316 + unsigned long ns_per_tick; 317 317 int total_ticks, cks, brl, brh; 318 318 struct i2c_timings *t = &riic->i2c_t; 319 319 struct device *dev = riic->adapter.dev.parent; ··· 378 376 * Remove clock ticks for rise and fall times. Convert ns to clock 379 377 * ticks. 380 378 */ 381 - brl -= t->scl_fall_ns / (1000000000 / rate); 382 - brh -= t->scl_rise_ns / (1000000000 / rate); 379 + ns_per_tick = NSEC_PER_SEC / rate; 380 + brl -= t->scl_fall_ns / ns_per_tick; 381 + brh -= t->scl_rise_ns / ns_per_tick; 383 382 384 383 /* Adjust for min register values for when SCLE=1 and NFE=1 */ 385 384 if (brl < 1) ··· 390 387 391 388 pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n", 392 389 rate / total_ticks, ((brl + 3) * 100) / (brl + brh + 6), 393 - t->scl_fall_ns / (1000000000 / rate), 394 - t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); 390 + t->scl_fall_ns / ns_per_tick, t->scl_rise_ns / ns_per_tick, cks, brl, brh); 395 391 396 392 ret = pm_runtime_resume_and_get(dev); 397 393 if (ret)