From: Troy Kisky <troy.kisky@boundarydevices.com>
To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com
Cc: gary.bisson@boundarydevices.com, linux-rtc@vger.kernel.org,
Troy Kisky <troy.kisky@boundarydevices.com>
Subject: [PATCH v1 2/5] rtc: m41t80: fix m41t80_sqw_round_rate return value
Date: Thu, 2 Nov 2017 18:58:13 -0700 [thread overview]
Message-ID: <20171103015816.16972-2-troy.kisky@boundarydevices.com> (raw)
In-Reply-To: <20171103015816.16972-1-troy.kisky@boundarydevices.com>
Previously it was returning the best of
32768, 8192, 1024, 64, 2, 0
Now, best of
32768, 8192, 4096, 2048, 1024, 512, 256, 128,
64, 32, 16, 8, 4, 2, 1, 0
Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
---
drivers/rtc/rtc-m41t80.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 8f5843169dc2..42fc735a5446 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -468,18 +468,13 @@ static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *prate)
{
- int i, freq = M41T80_SQW_MAX_FREQ;
-
- if (freq <= rate)
- return freq;
-
- for (i = 2; i <= ilog2(M41T80_SQW_MAX_FREQ); i++) {
- freq /= 1 << i;
- if (freq <= rate)
- return freq;
- }
-
- return 0;
+ if (rate >= M41T80_SQW_MAX_FREQ)
+ return M41T80_SQW_MAX_FREQ;
+ if (rate >= M41T80_SQW_MAX_FREQ / 4)
+ return M41T80_SQW_MAX_FREQ / 4;
+ if (!rate)
+ return 0;
+ return 1 << ilog2(rate);
}
static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
--
2.11.0
next prev parent reply other threads:[~2017-11-03 2:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-03 1:58 [PATCH v1 1/5] rtc: m41t80: m41t80_sqw_set_rate should return 0 on success Troy Kisky
2017-11-03 1:58 ` Troy Kisky [this message]
2017-11-03 1:58 ` [PATCH v1 3/5] rtc: m41t80: avoid i2c read in m41t80_sqw_recalc_rate Troy Kisky
2017-11-03 1:58 ` [PATCH v1 4/5] rtc: m41t80: avoid i2c read in m41t80_sqw_is_prepared Troy Kisky
2017-11-03 1:58 ` [PATCH v1 5/5] rtc: m41t80: remove unneeded checks from m41t80_sqw_set_rate Troy Kisky
2017-11-08 2:13 ` [PATCH v1 1/5] rtc: m41t80: m41t80_sqw_set_rate should return 0 on success Alexandre Belloni
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=20171103015816.16972-2-troy.kisky@boundarydevices.com \
--to=troy.kisky@boundarydevices.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@free-electrons.com \
--cc=gary.bisson@boundarydevices.com \
--cc=linux-rtc@vger.kernel.org \
/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