mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Shiyan <shc_work@mail.ru>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shawn Guo <shawn.guo@linaro.org>,
	Sascha Hauer <kernel@pengutronix.de>,
	Alexander Shiyan <shc_work@mail.ru>
Subject: [PATCH 2/3] w1: mxc_w1: Add warning for base frequency calculation
Date: Fri, 29 Nov 2013 15:39:29 +0400	[thread overview]
Message-ID: <1385725170-31515-2-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1385725170-31515-1-git-send-email-shc_work@mail.ru>

Base frequency should be as close as possible to 1 MHz. This patch
adds warnings when clock is unreliable, according to i.MX datasheet.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/w1/masters/mxc_w1.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
index 5de3ca9..953168c 100644
--- a/drivers/w1/masters/mxc_w1.c
+++ b/drivers/w1/masters/mxc_w1.c
@@ -105,6 +105,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
 static int mxc_w1_probe(struct platform_device *pdev)
 {
 	struct mxc_w1_device *mdev;
+	unsigned long clkrate;
 	struct resource *res;
 	unsigned int clkdiv;
 	int err = 0;
@@ -118,7 +119,16 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
-	clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
+	clkrate = clk_get_rate(mdev->clk);
+	if (clkrate < 10000000)
+		dev_warn(&pdev->dev,
+			 "Low clock frequency causes improper function\n");
+
+	clkdiv = DIV_ROUND_CLOSEST(clkrate, 1000000);
+	clkrate /= clkdiv;
+	if ((clkrate < 980000) || (clkrate > 1020000))
+		dev_warn(&pdev->dev,
+			 "Incorrect time base frequency %lu Hz\n", clkrate);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mdev->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -126,7 +136,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 		return PTR_ERR(mdev->regs);
 
 	clk_prepare_enable(mdev->clk);
-	__raw_writeb(clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER);
+	__raw_writeb(clkdiv - 1, mdev->regs + MXC_W1_TIME_DIVIDER);
 
 	mdev->bus_master.data = mdev;
 	mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
-- 
1.8.3.2


  reply	other threads:[~2013-11-29 11:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-29 11:39 [PATCH 1/3] w1: mxc_w1: Remove unused field "clkdiv" from private structure Alexander Shiyan
2013-11-29 11:39 ` Alexander Shiyan [this message]
2013-11-29 11:39 ` [PATCH 3/3] w1: mxc_w1: Check the clk_prepare_enable() return value Alexander Shiyan
2013-11-29 11:46 ` [PATCH 1/3] w1: mxc_w1: Remove unused field "clkdiv" from private structure Marc Kleine-Budde
2013-11-29 11:56   ` Alexander Shiyan
2013-11-29 12:02     ` Marc Kleine-Budde
2013-11-30 22:51 ` Evgeniy Polyakov

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=1385725170-31515-2-git-send-email-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=zbr@ioremap.net \
    /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

all inboxes | Powered by JetHome®