From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: bst@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21
Date: Wed, 24 Mar 2021 13:22:45 +0100 [thread overview]
Message-ID: <20210324122247.10683-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210324122247.10683-1-a.fatoum@pengutronix.de>
Adding -Wtype-limits to the build correctly detects that the
first branch (mfn < 0) is never taken as mfn is unsigned.
Import the Linux v5.11 bits that correctly checks the sign of the
sign/magnitude integer. Unlike Linux, we don't need to check
whether it's an i.MX1 or i.MX21 here, because an #ifdef earlier
normalizes the value to be aligned with the i.MX27's.
This however means that a multi-image barebox wasn't and will remain
not able to properly target both <= i.MX21 and newer SoCs at the same time.
This is just build-time tested.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/clk/imx/clk-pllv1.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/imx/clk-pllv1.c b/drivers/clk/imx/clk-pllv1.c
index 283ae843a75d..36192bb2112a 100644
--- a/drivers/clk/imx/clk-pllv1.c
+++ b/drivers/clk/imx/clk-pllv1.c
@@ -12,12 +12,21 @@
#include "clk.h"
+#define MFN_BITS (10)
+#define MFN_SIGN (BIT(MFN_BITS - 1))
+#define MFN_MASK (MFN_SIGN - 1)
+
struct clk_pllv1 {
struct clk clk;
void __iomem *reg;
const char *parent;
};
+static inline bool mfn_is_negative(unsigned int mfn)
+{
+ return mfn & MFN_SIGN;
+}
+
static unsigned long clk_pllv1_recalc_rate(struct clk *clk,
unsigned long parent_rate)
{
@@ -50,7 +59,7 @@ static unsigned long clk_pllv1_recalc_rate(struct clk *clk,
ll = (unsigned long long)freq * mfn_abs;
do_div(ll, mfd + 1);
- if (mfn < 0)
+ if (mfn_is_negative(mfn))
ll = (freq * mfi) - ll;
else
ll = (freq * mfi) + ll;
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-03-24 12:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
2021-03-24 12:22 ` Ahmad Fatoum [this message]
2021-03-24 12:22 ` [PATCH 3/4] kbuild: add -Wtype-limits to compile flags Ahmad Fatoum
2021-03-24 12:22 ` [PATCH 4/4] mtd: fix possible overflow during mtd size multiplication Ahmad Fatoum
2021-03-25 12:46 ` [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210324122247.10683-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=bst@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox