From: yong.mao@mediatek.com (Yong Mao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1] mmc: mediatek: Fixed bug where clock frequency could be set wrong
Date: Fri, 24 Feb 2017 16:22:07 +0800 [thread overview]
Message-ID: <1487924527-22584-2-git-send-email-yong.mao@mediatek.com> (raw)
In-Reply-To: <1487924527-22584-1-git-send-email-yong.mao@mediatek.com>
From: yong mao <yong.mao@mediatek.com>
This patch can fix two issues:
Issue 1:
The maximum value of clock divider is 0xff.
Because the type of div is u32, div may be larger than max_div.
In this case, we should use max_div to set the clock frequency.
Issue 2:
In previous code, we can not set the correct clock frequency when
div equals 0xff.
Signed-off-by: Yong Mao <yong.mao@mediatek.com>
Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
---
drivers/mmc/host/mtk-sd.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index 07f3236..3174445 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -540,6 +540,7 @@ static void msdc_set_mclk(struct msdc_host *host, unsigned char timing, u32 hz)
u32 mode;
u32 flags;
u32 div;
+ u32 max_div;
u32 sclk;
if (!hz) {
@@ -590,8 +591,18 @@ static void msdc_set_mclk(struct msdc_host *host, unsigned char timing, u32 hz)
sclk = (host->src_clk_freq >> 2) / div;
}
}
+
+ /**
+ * The maximum value of div is 0xff.
+ * Check if the div is larger than max_div.
+ */
+ max_div = 0xff;
+ if (div > max_div) {
+ div = max_div;
+ sclk = (host->src_clk_freq >> 2) / div;
+ }
sdr_set_field(host->base + MSDC_CFG, MSDC_CFG_CKMOD | MSDC_CFG_CKDIV,
- (mode << 8) | (div % 0xff));
+ (mode << 8) | div);
sdr_set_bits(host->base + MSDC_CFG, MSDC_CFG_CKPDN);
while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB))
cpu_relax();
--
1.7.9.5
next prev parent reply other threads:[~2017-02-24 8:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 8:22 [PATCH v1] Fixed bug where clock frequency could be set wrong Yong Mao
2017-02-24 8:22 ` Yong Mao [this message]
2017-02-24 8:52 ` [PATCH v1] mmc: mediatek: " Daniel Kurtz
2017-02-24 9:38 ` Yong Mao
2017-02-28 6:56 ` Daniel Kurtz
2017-03-01 9:56 ` Yong Mao
2017-03-02 12:20 ` Daniel Kurtz
2017-03-04 6:44 ` Yong Mao
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=1487924527-22584-2-git-send-email-yong.mao@mediatek.com \
--to=yong.mao@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).