Message ID | 20250103091900.428729-9-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive) |
---|---|
State | Under Review |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | i2c: riic: driver cleanup and improvements | expand |
On Fri, Jan 3, 2025 at 10:19 AM Prabhakar <prabhakar.csengg@gmail.com> wrote: > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > 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> > --- > v3->v4 > - Switched to use NSEC_PER_SEC instead of NANO > - Updated the commit message > - Dropped the RB/TB tags Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Gr{oetje,eeting}s, Geert
> +#include <vdso/time64.h>
Hmmm, what about using 'linux/time.h' instead and relying that it does
the right thing?
Nice cleanup otherwise!
On Thu, Jan 09, 2025 at 10:41:04AM +0100, Wolfram Sang wrote: > > > +#include <vdso/time64.h> > > Hmmm, what about using 'linux/time.h' instead and relying that it does > the right thing? > > Nice cleanup otherwise! Besides: Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c index eff1efd381dd..042933a2a985 100644 --- a/drivers/i2c/busses/i2c-riic.c +++ b/drivers/i2c/busses/i2c-riic.c @@ -47,6 +47,7 @@ #include <linux/pm_runtime.h> #include <linux/reset.h> #include <vdso/bits.h> +#include <vdso/time64.h> #define ICCR1_ICE BIT(7) #define ICCR1_IICRST BIT(6) @@ -314,6 +315,7 @@ static int riic_init_hw(struct riic_dev *riic) { int ret; unsigned long rate; + unsigned long ns_per_tick; int total_ticks, cks, brl, brh; struct i2c_timings *t = &riic->i2c_t; struct device *dev = riic->adapter.dev.parent; @@ -377,8 +379,9 @@ static int riic_init_hw(struct riic_dev *riic) * Remove clock ticks for rise and fall times. Convert ns to clock * ticks. */ - brl -= t->scl_fall_ns / (1000000000 / rate); - brh -= t->scl_rise_ns / (1000000000 / rate); + ns_per_tick = NSEC_PER_SEC / rate; + brl -= t->scl_fall_ns / ns_per_tick; + brh -= t->scl_rise_ns / ns_per_tick; /* Adjust for min register values for when SCLE=1 and NFE=1 */ if (brl < 1) @@ -388,8 +391,7 @@ static int riic_init_hw(struct riic_dev *riic) pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n", rate / total_ticks, ((brl + 3) * 100) / (brl + brh + 6), - t->scl_fall_ns / (1000000000 / rate), - t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); + t->scl_fall_ns / ns_per_tick, t->scl_rise_ns / ns_per_tick, cks, brl, brh); ret = pm_runtime_resume_and_get(dev); if (ret)