From patchwork Mon Jul 22 11:13:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 169365 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7389687ilk; Mon, 22 Jul 2019 04:13:25 -0700 (PDT) X-Received: by 2002:a2e:91c5:: with SMTP id u5mr36125427ljg.65.1563794005401; Mon, 22 Jul 2019 04:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563794005; cv=none; d=google.com; s=arc-20160816; b=Ge5bbdLvTgGqYGcnFiNsdwYVB7fTZESpUrz6ZgsEDdK+oq23k/xvqpTm3KzvNrvX6N pS6gkfbLuThRw16FoHr0mS8+i9sPynOQ0KT2UmxoRm3iEvHwy/ogPu7F3axanFGSrKB2 ewgsb2L/cOhswAMLBiN8Psl7nYdJZ1A6hGXSBnloZHDNNxYMz9YRVuy9VOV5nlH+ONXG tPQJAVS3obGxoubLPX43A0S5ODbwU6hwfzyEL/fXdLzQS+VPrB/c41XSRQT5QUyXgZX/ 9yQcBSBm20eajD6rfRyKh5Ao3Kd4oMlN8I8EC4jDlAX8i7oO9nBepOo4zcbYtvoVaQQ/ dyxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=fG5xC73GGxW5G93GYyScyfvWRfK/bWju5nJg9wNvhj0=; b=rjAYL4l8mzUJUIw5EEql78/d15idmJV1HemMDub+Bq2FqAsFxGZK+QyhYPNxEDECqQ t8Geiy5pC3pNpz5PJULHutvC7VyD525G+DOG+pffj73OMKhXgF1v8G7BVbqiUFDWXCMu 6USPCWFp81x2kgWJgFzh8gVPxhnNDG95EOQPkEVSABO37hhleSVqZZpHDOMV6Ctw9vpC OP4e1msJxhYg0QPwGqCu6GUIi7ySL2ialWXi2qF2eqcVe25g85WCwOlu5kPjlxoV8BKF 1+NJeeBJr1UFH9EeKSvElh/Jj3Mka0Bygpoyw8cXcjN3sFIS6JPJmXgBs0KKXP7FO08t 6OaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hQRAVZoA; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r1sor9998863lfm.25.2019.07.22.04.13.25 for (Google Transport Security); Mon, 22 Jul 2019 04:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hQRAVZoA; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=fG5xC73GGxW5G93GYyScyfvWRfK/bWju5nJg9wNvhj0=; b=hQRAVZoA01fNr0kY3FNMK4mFMbLXNHDkQAiENNQG19awT/pJ4bkfZZZOxhzknmFckF JNVfoizAPvo4dg7eqA2rU8m+D6qBKqKD5yMzqTsxnFjNdkiqwCK/l2a6uel+K5Rq5Eli n6YyJ5GQXCMWmPQ+8WjT374l+mVLFgqpafdxxEBSeFjjCJ9IXNaQn7q7+5stllYXNY6D nH1a8HUK6DbBN0eWkzmPJ/tED9GYNwmCFhZAi4tsD1DL6OXRRWGebb8YMRRa/c+4Al+j 6YbmyeZXaie0APkca+szFO7n0y81LpOf1g3pJ53g8NzxYFIPFcZYGi2w0w9KtRnfeMcg 52mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fG5xC73GGxW5G93GYyScyfvWRfK/bWju5nJg9wNvhj0=; b=jPJe6NLpqCSUwE069C84y5lxF1HQVDhY0p/rw1ML6ClrLdpsSiNjTn/qvHmxEWkwOI iue/TqqiD0bm9BfmB6k++RYXzAMRWbxebYgYCRK22DZmIboSNFpRZqva/6h7KfJsQdAl 2cb4Kq/a/TannZX05f2lhLOZU3FkZmgUJAbhtMdc6rciJmJtnTa35qwJxzTQo7uRB6u6 ZT/El7P22SFBL/xf2461yqWi32G8FhaS7Jbd+di+pdo3dPBfMgaGTU+V7yROahBcntdD BZHVK199WyFhlDPaTPKkScSIh3Fc7Ca6S172NXNWBygeKDFvhAaxhAKwbJYh/10TMWAL BYdA== X-Gm-Message-State: APjAAAXB/ueC8DxfvbQCfip47/CyaOJpIrfxO+Rl/7sXmAb5fKefDpn6 zCgXIngM1iGiOISwkyhCNO9cwS4z X-Google-Smtp-Source: APXvYqxVBiNqYkyXndKZebCMenmpVV0KmIatd3Y/abjK9aHRBLjtprV96p7SX8xvc+bWenRy4A98yw== X-Received: by 2002:ac2:456d:: with SMTP id k13mr30805093lfm.77.1563794005029; Mon, 22 Jul 2019 04:13:25 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id v15sm5992660lfd.53.2019.07.22.04.13.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 22 Jul 2019 04:13:24 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ludovic Barre Cc: Russell King , Linus Walleij , Jean-Nicolas Graux , Ulf Hansson Subject: [PATCH V2] mmc: mmci: Clarify comments and some code for busy detection Date: Mon, 22 Jul 2019 13:13:17 +0200 Message-Id: <20190722111317.20177-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 The code dealing with busy detection is somewhat complicated. In a way to make it a bit clearer, let's try to clarify the comments in the code about it. Additionally, move the part for clearing the so called busy start IRQ, to the place where the IRQ is actually delivered. Ideally, this should make the code a bit more robust, but also a bit easier to understand. Signed-off-by: Ulf Hansson --- Changes in v2: - Squashed patch 1 and patch 2. - Keep the re-read on the status register, but explain why it's needed. - Move the clearing of the busy start IRQ at the point it's delivered. --- drivers/mmc/host/mmci.c | 63 ++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 29 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 356833a606d5..d3f876c8c292 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1222,47 +1222,58 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND))) return; - /* - * ST Micro variant: handle busy detection. - */ + /* Handle busy detection on DAT0 if the variant supports it. */ if (busy_resp && host->variant->busy_detect) { - /* We are busy with a command, return */ + /* + * If there is a command in-progress that has been successfully + * sent, then bail out if busy status is set and wait for the + * busy end IRQ. + * + * Note that, the HW triggers an IRQ on both edges while + * monitoring DAT0 for busy completion, but there is only one + * status bit in MMCISTATUS for the busy state. Therefore + * both the start and the end interrupts needs to be cleared, + * one after the other. So, clear the busy start IRQ here. + */ if (host->busy_status && - (status & host->variant->busy_detect_flag)) + (status & host->variant->busy_detect_flag)) { + writel(host->variant->busy_detect_mask, + host->base + MMCICLEAR); return; + } /* - * We were not busy, but we now got a busy response on - * something that was not an error, and we double-check - * that the special busy status bit is still set before - * proceeding. + * Before unmasking for the busy end IRQ, confirm that the + * command was sent successfully. To keep track of having a + * command in-progress, waiting for busy signaling to end, + * store the status in host->busy_status. + * + * Note that, the card may need a couple of clock cycles before + * it starts signaling busy on DAT0, hence re-read the + * MMCISTATUS register here, to allow the busy bit to be set. + * Potentially we may even need to poll the register for a + * while, to allow it to be set, but tests indicates that it + * isn't needed. */ if (!host->busy_status && !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) && (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { - /* Clear the busy start IRQ */ - writel(host->variant->busy_detect_mask, - host->base + MMCICLEAR); - - /* Unmask the busy end IRQ */ writel(readl(base + MMCIMASK0) | host->variant->busy_detect_mask, base + MMCIMASK0); - /* - * Now cache the last response status code (until - * the busy bit goes low), and return. - */ + host->busy_status = status & (MCI_CMDSENT|MCI_CMDRESPEND); return; } /* - * At this point we are not busy with a command, we have - * not received a new busy request, clear and mask the busy - * end IRQ and fall through to process the IRQ. + * If there is a command in-progress that has been successfully + * sent and the busy bit isn't set, it means we have received + * the busy end IRQ. Clear and mask the IRQ, then continue to + * process the command. */ if (host->busy_status) { @@ -1508,14 +1519,8 @@ static irqreturn_t mmci_irq(int irq, void *dev_id) } /* - * We intentionally clear the MCI_ST_CARDBUSY IRQ (if it's - * enabled) in mmci_cmd_irq() function where ST Micro busy - * detection variant is handled. Considering the HW seems to be - * triggering the IRQ on both edges while monitoring DAT0 for - * busy completion and that same status bit is used to monitor - * start and end of busy detection, special care must be taken - * to make sure that both start and end interrupts are always - * cleared one after the other. + * Busy detection is managed by mmci_cmd_irq(), including to + * clear the corresponding IRQ. */ status &= readl(host->base + MMCIMASK0); if (host->variant->busy_detect)