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>,
	Sascha Hauer <kernel@pengutronix.de>,
	Shawn Guo <shawn.guo@freescale.com>,
	Alexander Shiyan <shc_work@mail.ru>
Subject: [PATCH 4/4] w1: mxc_w1: Optimize mxc_w1_ds2_touch_bit()
Date: Thu,  8 May 2014 11:56:40 +0400	[thread overview]
Message-ID: <1399535800-19335-4-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1399535800-19335-1-git-send-email-shc_work@mail.ru>

According to the i.MX reference manual, the read/write bit operations
takes from 60 us to 120 us.
This patch optimizes mxc_w1_ds2_touch_bit() function to use proper
value for such delay. Nevertheless, a small margin for the timeout has
been added for the case if clock frequency is inaccurate.

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

diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
index 741d2bb4..da3d0f0 100644
--- a/drivers/w1/masters/mxc_w1.c
+++ b/drivers/w1/masters/mxc_w1.c
@@ -75,22 +75,25 @@ static u8 mxc_w1_ds2_reset_bus(void *data)
  */
 static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
 {
-	struct mxc_w1_device *mdev = data;
-	void __iomem *ctrl_addr = mdev->regs + MXC_W1_CONTROL;
-	unsigned int timeout_cnt = 400; /* Takes max. 120us according to
-					 * datasheet.
-					 */
+	struct mxc_w1_device *dev = data;
+	unsigned long timeout;
+
+	writeb(MXC_W1_CONTROL_WR(bit), dev->regs + MXC_W1_CONTROL);
+
+	/* Wait for read/write bit (60us, Max 120us), use 200us for sure */
+	timeout = jiffies + usecs_to_jiffies(200);
 
-	writeb(MXC_W1_CONTROL_WR(bit), ctrl_addr);
+	udelay(60);
 
-	while (timeout_cnt--) {
-		if (!(readb(ctrl_addr) & MXC_W1_CONTROL_WR(bit)))
-			break;
+	do {
+		u8 ctrl = readb(dev->regs + MXC_W1_CONTROL);
 
-		udelay(1);
-	}
+		/* RDST bit is valid after the WR1/RD bit is self-cleared */
+		if (!(ctrl & MXC_W1_CONTROL_WR(bit)))
+			return !!(ctrl & MXC_W1_CONTROL_RDST);
+	} while (time_is_after_jiffies(timeout));
 
-	return !!(readb(ctrl_addr) & MXC_W1_CONTROL_RDST);
+	return 0;
 }
 
 static int mxc_w1_probe(struct platform_device *pdev)
-- 
1.8.3.2


      parent reply	other threads:[~2014-05-08  7:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08  7:56 [PATCH 1/4] w1: mxc_w1: Fix incorrect "presence" status Alexander Shiyan
2014-05-08  7:56 ` [PATCH 2/4] w1: mxc_w1: Optimize mxc_w1_ds2_reset_bus() Alexander Shiyan
2014-05-08  7:56 ` [PATCH 3/4] w1: mxc_w1: Perform a software reset at startup Alexander Shiyan
2014-05-08  7:56 ` Alexander Shiyan [this message]

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=1399535800-19335-4-git-send-email-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawn.guo@freescale.com \
    --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®