From nobody Thu Nov 28 14:03:16 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19A6D1C8FB2; Tue, 1 Oct 2024 14:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727793568; cv=none; b=aTbPyQV3NvqoPkAxc3JCuWyLj/dh2ZpL8L3VugMP3px2XxDeTJPuq5bN3IS/3O+GYyPXYXJs9IWty79eveFsyL3VDkMI9Yvj1b19MK+WKExehj/ab7Wv8IRTfyFTv2J7AdQi8imsZzxVjZBaP63chZE2h5BM7pDw16AySmRhSvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727793568; c=relaxed/simple; bh=j7cEcKzext16oP7OAxC9breMWXfoaROVojla+gdYgKc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JBKUuCgN8KOWUsgDDg1e7C2dGV+nBpIP3N7ylmmNe0aKUXf6VMQ2Tooef/nyGs5gfZTHcaJAVin8EUuvUIIsTgcWMdbbr1IDZAFmzS/Gz3q9kt6MsxmxgWluIaVdgd/OFzgNKMevDn96TiqL+JSXTpPQWcfRFCEYHlZ4645d3Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rns/Cat+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rns/Cat+" Received: by smtp.kernel.org (Postfix) with ESMTPS id D5BACC4CEC7; Tue, 1 Oct 2024 14:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727793567; bh=j7cEcKzext16oP7OAxC9breMWXfoaROVojla+gdYgKc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Rns/Cat+AEOQeI7jP+6zWAml/O1enmAsX7qaQrxXji7zas0R8q7Hhrs/pGvR7v1yf uApP6dMeVZcOgDWUazNZCKswuk6WpEiKN5CPHUrOpQg0nbGoO0LJg+68vSKg0/cPjT dwYA6oB8d0OJ4nhdXmFRFAHCeA74tpIdNQMj3Ku4saVSj1kcAPLS8uKAjKo4BBex2J F+fca2XkzWmz+WlLh6mnPTXuWMWdUFS5xdcLLPdYXikXRQYAaw5qV91Y8h2kzyd2oc Qmapj1u/oqhPPAIRuszs98lKW4dceyLiJ83TqFzMkSUkub97bhRGZko9kUbf3SNJ6X DBji+piSiWtBA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C453ACEACD0; Tue, 1 Oct 2024 14:39:27 +0000 (UTC) From: =?utf-8?q?Duje_Mihanovi=C4=87_via_B4_Relay?= Date: Tue, 01 Oct 2024 16:37:31 +0200 Subject: [PATCH v13 01/12] clk: mmp: Switch to use struct u32_fract instead of custom one Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241001-pxa1908-lkml-v13-1-6b9a7f64f9ae@skole.hr> References: <20241001-pxa1908-lkml-v13-0-6b9a7f64f9ae@skole.hr> In-Reply-To: <20241001-pxa1908-lkml-v13-0-6b9a7f64f9ae@skole.hr> To: Michael Turquette , Stephen Boyd , Linus Walleij , Rob Herring , Conor Dooley , Tony Lindgren , Haojian Zhuang , =?utf-8?q?Duje_Mihanovi=C4=87?= , Lubomir Rintel , Catalin Marinas , Will Deacon , Rob Herring , Krzysztof Kozlowski Cc: phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Karel Balej , David Wronek , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10838; i=duje.mihanovic@skole.hr; s=20240706; h=from:subject:message-id; bh=aUPxtF04qTKpLPEJgHiKaCixpSaCfAFycFxZA5nFzBw=; b=owGbwMvMwCW21nBykGv/WmbG02pJDGl/OCeV5Ly+/fDZncaCu7/kA27Zek551tboHX3A7cR7a TGugoqOjlIWBjEuBlkxRZbc/47XeD+LbN2evcwAZg4rE8gQBi5OAZiIpxojw1k+gV9P2VYlme4/ bHAi8/u7J+vVZttZxgkd/MMj5jDd9SbDP8PIyK9/tnHt0rt3u61jjt+yn1v/zk/XOCznmbVOfZV zFhMA X-Developer-Key: i=duje.mihanovic@skole.hr; a=openpgp; fpr=6DFF41D60DF314B5B76BA630AD319352458FAD03 X-Endpoint-Received: by B4 Relay for duje.mihanovic@skole.hr/20240706 with auth_id=191 X-Original-From: =?utf-8?q?Duje_Mihanovi=C4=87?= Reply-To: duje.mihanovic@skole.hr From: Andy Shevchenko The struct mmp_clk_factor_tbl repeats the generic struct u32_fract. Kill the custom one and use the generic one instead. Signed-off-by: Andy Shevchenko Tested-by: Duje Mihanovi=C4=87 Reviewed-by: Linus Walleij Reviewed-by: Stephen Boyd Signed-off-by: Duje Mihanovi=C4=87 --- drivers/clk/mmp/clk-frac.c | 57 ++++++++++++++++++++----------------= ---- drivers/clk/mmp/clk-of-mmp2.c | 26 +++++++++--------- drivers/clk/mmp/clk-of-pxa168.c | 4 +-- drivers/clk/mmp/clk-of-pxa1928.c | 6 ++--- drivers/clk/mmp/clk-of-pxa910.c | 4 +-- drivers/clk/mmp/clk.h | 10 +++---- 6 files changed, 51 insertions(+), 56 deletions(-) diff --git a/drivers/clk/mmp/clk-frac.c b/drivers/clk/mmp/clk-frac.c index 1b90867b60c4b5b2582cc92b0050221330a3c003..6556f6ada2e830178b9525462f6= 84bad683db454 100644 --- a/drivers/clk/mmp/clk-frac.c +++ b/drivers/clk/mmp/clk-frac.c @@ -26,14 +26,15 @@ static long clk_factor_round_rate(struct clk_hw *hw, un= signed long drate, { struct mmp_clk_factor *factor =3D to_clk_factor(hw); u64 rate =3D 0, prev_rate; + struct u32_fract *d; int i; =20 for (i =3D 0; i < factor->ftbl_cnt; i++) { - prev_rate =3D rate; - rate =3D *prate; - rate *=3D factor->ftbl[i].den; - do_div(rate, factor->ftbl[i].num * factor->masks->factor); + d =3D &factor->ftbl[i]; =20 + prev_rate =3D rate; + rate =3D (u64)(*prate) * d->denominator; + do_div(rate, d->numerator * factor->masks->factor); if (rate > drate) break; } @@ -52,23 +53,22 @@ static unsigned long clk_factor_recalc_rate(struct clk_= hw *hw, { struct mmp_clk_factor *factor =3D to_clk_factor(hw); struct mmp_clk_factor_masks *masks =3D factor->masks; - unsigned int val, num, den; + struct u32_fract d; + unsigned int val; u64 rate; =20 val =3D readl_relaxed(factor->base); =20 /* calculate numerator */ - num =3D (val >> masks->num_shift) & masks->num_mask; + d.numerator =3D (val >> masks->num_shift) & masks->num_mask; =20 /* calculate denominator */ - den =3D (val >> masks->den_shift) & masks->den_mask; - - if (!den) + d.denominator =3D (val >> masks->den_shift) & masks->den_mask; + if (!d.denominator) return 0; =20 - rate =3D parent_rate; - rate *=3D den; - do_div(rate, num * factor->masks->factor); + rate =3D (u64)parent_rate * d.denominator; + do_div(rate, d.numerator * factor->masks->factor); =20 return rate; } @@ -82,18 +82,18 @@ static int clk_factor_set_rate(struct clk_hw *hw, unsig= ned long drate, int i; unsigned long val; unsigned long flags =3D 0; + struct u32_fract *d; u64 rate =3D 0; =20 for (i =3D 0; i < factor->ftbl_cnt; i++) { - rate =3D prate; - rate *=3D factor->ftbl[i].den; - do_div(rate, factor->ftbl[i].num * factor->masks->factor); + d =3D &factor->ftbl[i]; =20 + rate =3D (u64)prate * d->denominator; + do_div(rate, d->numerator * factor->masks->factor); if (rate > drate) break; } - if (i > 0) - i--; + d =3D i ? &factor->ftbl[i - 1] : &factor->ftbl[0]; =20 if (factor->lock) spin_lock_irqsave(factor->lock, flags); @@ -101,10 +101,10 @@ static int clk_factor_set_rate(struct clk_hw *hw, uns= igned long drate, val =3D readl_relaxed(factor->base); =20 val &=3D ~(masks->num_mask << masks->num_shift); - val |=3D (factor->ftbl[i].num & masks->num_mask) << masks->num_shift; + val |=3D (d->numerator & masks->num_mask) << masks->num_shift; =20 val &=3D ~(masks->den_mask << masks->den_shift); - val |=3D (factor->ftbl[i].den & masks->den_mask) << masks->den_shift; + val |=3D (d->denominator & masks->den_mask) << masks->den_shift; =20 writel_relaxed(val, factor->base); =20 @@ -118,7 +118,8 @@ static int clk_factor_init(struct clk_hw *hw) { struct mmp_clk_factor *factor =3D to_clk_factor(hw); struct mmp_clk_factor_masks *masks =3D factor->masks; - u32 val, num, den; + struct u32_fract d; + u32 val; int i; unsigned long flags =3D 0; =20 @@ -128,23 +129,22 @@ static int clk_factor_init(struct clk_hw *hw) val =3D readl(factor->base); =20 /* calculate numerator */ - num =3D (val >> masks->num_shift) & masks->num_mask; + d.numerator =3D (val >> masks->num_shift) & masks->num_mask; =20 /* calculate denominator */ - den =3D (val >> masks->den_shift) & masks->den_mask; + d.denominator =3D (val >> masks->den_shift) & masks->den_mask; =20 for (i =3D 0; i < factor->ftbl_cnt; i++) - if (den =3D=3D factor->ftbl[i].den && num =3D=3D factor->ftbl[i].num) + if (d.denominator =3D=3D factor->ftbl[i].denominator && + d.numerator =3D=3D factor->ftbl[i].numerator) break; =20 if (i >=3D factor->ftbl_cnt) { val &=3D ~(masks->num_mask << masks->num_shift); - val |=3D (factor->ftbl[0].num & masks->num_mask) << - masks->num_shift; + val |=3D (factor->ftbl[0].numerator & masks->num_mask) << masks->num_shi= ft; =20 val &=3D ~(masks->den_mask << masks->den_shift); - val |=3D (factor->ftbl[0].den & masks->den_mask) << - masks->den_shift; + val |=3D (factor->ftbl[0].denominator & masks->den_mask) << masks->den_s= hift; } =20 if (!(val & masks->enable_mask) || i >=3D factor->ftbl_cnt) { @@ -168,8 +168,7 @@ static const struct clk_ops clk_factor_ops =3D { struct clk *mmp_clk_register_factor(const char *name, const char *parent_n= ame, unsigned long flags, void __iomem *base, struct mmp_clk_factor_masks *masks, - struct mmp_clk_factor_tbl *ftbl, - unsigned int ftbl_cnt, spinlock_t *lock) + struct u32_fract *ftbl, unsigned int ftbl_cnt, spinlock_t *lock) { struct mmp_clk_factor *factor; struct clk_init_data init; diff --git a/drivers/clk/mmp/clk-of-mmp2.c b/drivers/clk/mmp/clk-of-mmp2.c index eaad36ee323d14ff3d0f61c917d57d1501359db1..a4f15cee630ee65bcedba3975cf= 337ff765d3b2d 100644 --- a/drivers/clk/mmp/clk-of-mmp2.c +++ b/drivers/clk/mmp/clk-of-mmp2.c @@ -143,9 +143,9 @@ static struct mmp_clk_factor_masks uart_factor_masks = =3D { .den_shift =3D 0, }; =20 -static struct mmp_clk_factor_tbl uart_factor_tbl[] =3D { - {.num =3D 8125, .den =3D 1536}, /*14.745MHZ */ - {.num =3D 3521, .den =3D 689}, /*19.23MHZ */ +static struct u32_fract uart_factor_tbl[] =3D { + { .numerator =3D 8125, .denominator =3D 1536 }, /* 14.745MHZ */ + { .numerator =3D 3521, .denominator =3D 689 }, /* 19.23MHZ */ }; =20 static struct mmp_clk_factor_masks i2s_factor_masks =3D { @@ -157,16 +157,16 @@ static struct mmp_clk_factor_masks i2s_factor_masks = =3D { .enable_mask =3D 0xd0000000, }; =20 -static struct mmp_clk_factor_tbl i2s_factor_tbl[] =3D { - {.num =3D 24868, .den =3D 511}, /* 2.0480 MHz */ - {.num =3D 28003, .den =3D 793}, /* 2.8224 MHz */ - {.num =3D 24941, .den =3D 1025}, /* 4.0960 MHz */ - {.num =3D 28003, .den =3D 1586}, /* 5.6448 MHz */ - {.num =3D 31158, .den =3D 2561}, /* 8.1920 MHz */ - {.num =3D 16288, .den =3D 1845}, /* 11.2896 MHz */ - {.num =3D 20772, .den =3D 2561}, /* 12.2880 MHz */ - {.num =3D 8144, .den =3D 1845}, /* 22.5792 MHz */ - {.num =3D 10386, .den =3D 2561}, /* 24.5760 MHz */ +static struct u32_fract i2s_factor_tbl[] =3D { + { .numerator =3D 24868, .denominator =3D 511 }, /* 2.0480 MHz */ + { .numerator =3D 28003, .denominator =3D 793 }, /* 2.8224 MHz */ + { .numerator =3D 24941, .denominator =3D 1025 }, /* 4.0960 MHz */ + { .numerator =3D 28003, .denominator =3D 1586 }, /* 5.6448 MHz */ + { .numerator =3D 31158, .denominator =3D 2561 }, /* 8.1920 MHz */ + { .numerator =3D 16288, .denominator =3D 1845 }, /* 11.2896 MHz */ + { .numerator =3D 20772, .denominator =3D 2561 }, /* 12.2880 MHz */ + { .numerator =3D 8144, .denominator =3D 1845 }, /* 22.5792 MHz */ + { .numerator =3D 10386, .denominator =3D 2561 }, /* 24.5760 MHz */ }; =20 static DEFINE_SPINLOCK(acgr_lock); diff --git a/drivers/clk/mmp/clk-of-pxa168.c b/drivers/clk/mmp/clk-of-pxa16= 8.c index c5a7ba1deaa3a1d42cd85cf462b7eed79c5d9ba1..5f250427e60d25b24208d02322a= 441d86faf346b 100644 --- a/drivers/clk/mmp/clk-of-pxa168.c +++ b/drivers/clk/mmp/clk-of-pxa168.c @@ -106,8 +106,8 @@ static struct mmp_clk_factor_masks uart_factor_masks = =3D { .den_shift =3D 0, }; =20 -static struct mmp_clk_factor_tbl uart_factor_tbl[] =3D { - {.num =3D 8125, .den =3D 1536}, /*14.745MHZ */ +static struct u32_fract uart_factor_tbl[] =3D { + { .numerator =3D 8125, .denominator =3D 1536 }, /* 14.745MHZ */ }; =20 static void pxa168_pll_init(struct pxa168_clk_unit *pxa_unit) diff --git a/drivers/clk/mmp/clk-of-pxa1928.c b/drivers/clk/mmp/clk-of-pxa1= 928.c index 9def4b5f10e910b18065647dcde2a44c43b8185d..ebb6e278eda33c551abce893051= bf52e97f898c4 100644 --- a/drivers/clk/mmp/clk-of-pxa1928.c +++ b/drivers/clk/mmp/clk-of-pxa1928.c @@ -61,9 +61,9 @@ static struct mmp_clk_factor_masks uart_factor_masks =3D { .den_shift =3D 0, }; =20 -static struct mmp_clk_factor_tbl uart_factor_tbl[] =3D { - {.num =3D 832, .den =3D 234}, /*58.5MHZ */ - {.num =3D 1, .den =3D 1}, /*26MHZ */ +static struct u32_fract uart_factor_tbl[] =3D { + { .numerator =3D 832, .denominator =3D 234 }, /* 58.5MHZ */ + { .numerator =3D 1, .denominator =3D 1 }, /* 26MHZ */ }; =20 static void pxa1928_pll_init(struct pxa1928_clk_unit *pxa_unit) diff --git a/drivers/clk/mmp/clk-of-pxa910.c b/drivers/clk/mmp/clk-of-pxa91= 0.c index 7a38c424782e619347c44b75edb1938cb7a27dc9..fe65e7bdb411fe9be93e8dd5d57= 1e1c62b12909f 100644 --- a/drivers/clk/mmp/clk-of-pxa910.c +++ b/drivers/clk/mmp/clk-of-pxa910.c @@ -86,8 +86,8 @@ static struct mmp_clk_factor_masks uart_factor_masks =3D { .den_shift =3D 0, }; =20 -static struct mmp_clk_factor_tbl uart_factor_tbl[] =3D { - {.num =3D 8125, .den =3D 1536}, /*14.745MHZ */ +static struct u32_fract uart_factor_tbl[] =3D { + { .numerator =3D 8125, .denominator =3D 1536 }, /* 14.745MHZ */ }; =20 static void pxa910_pll_init(struct pxa910_clk_unit *pxa_unit) diff --git a/drivers/clk/mmp/clk.h b/drivers/clk/mmp/clk.h index 55ac053797819e791d62e5f950779c56a957c994..c83cec169ddc5e3fcd0561cf857= f248178c25b68 100644 --- a/drivers/clk/mmp/clk.h +++ b/drivers/clk/mmp/clk.h @@ -3,6 +3,7 @@ #define __MACH_MMP_CLK_H =20 #include +#include #include #include =20 @@ -20,16 +21,11 @@ struct mmp_clk_factor_masks { unsigned int enable_mask; }; =20 -struct mmp_clk_factor_tbl { - unsigned int num; - unsigned int den; -}; - struct mmp_clk_factor { struct clk_hw hw; void __iomem *base; struct mmp_clk_factor_masks *masks; - struct mmp_clk_factor_tbl *ftbl; + struct u32_fract *ftbl; unsigned int ftbl_cnt; spinlock_t *lock; }; @@ -37,7 +33,7 @@ struct mmp_clk_factor { extern struct clk *mmp_clk_register_factor(const char *name, const char *parent_name, unsigned long flags, void __iomem *base, struct mmp_clk_factor_masks *masks, - struct mmp_clk_factor_tbl *ftbl, unsigned int ftbl_cnt, + struct u32_fract *ftbl, unsigned int ftbl_cnt, spinlock_t *lock); =20 /* Clock type "mix" */ --=20 2.46.2