From patchwork Tue Jul 23 12:28:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 169529 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8813931ilk; Tue, 23 Jul 2019 05:28:13 -0700 (PDT) X-Received: by 2002:a2e:91c5:: with SMTP id u5mr39575950ljg.65.1563884893557; Tue, 23 Jul 2019 05:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563884893; cv=none; d=google.com; s=arc-20160816; b=RAiNuW1r8vVLnhqtFotbBZTrkNeLSAGX2qa1QzrmSNqqcoePMrMGEqpjuWG/Eiey/D yGeoQJhv4h5AdyziVJTzw34KrVVQHzdtykQaoAxErLBu45G99hfVABjZyTXPZA92dAGD R7Y8S5lCzKE78fYgKrrL3486MQiGia19SaqUzfXYfyQnVdLYrvy6cDgTw88dL/Gi4Wy7 2w1YM9VFVJMQLFLby26Xd5Nk3Y5/pOXxAX5kgLmzmqF6WHNHZlsAbdREo2Z5MB36crN4 8D3r1Z5/myOfZI704QYtZyJaKEoqZun9giJFVZ/KQfiDSu2GrfKRFoWLi1Er/2J8LHGz jbCA== 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=6ezilMvH/w5kf4PPHpJm8BaFG4qv6hP7m8ahOV8pd/Q=; b=iXyPP883cCARIVeJNWWez+hpqah5lfDzr57lH8DF/5mJ3qxBYJdSxyjCL3o+u8trD7 gMcVFl+KAPxgAVbyHkEd+EBmzIKD28ztP27LrLUU/iKjOn8Y7EFQwEYztR/vjmVEz8l0 g7VythTCCUeQe1wqVwZhrVCwh5RizugN2lLDbDZguml9XzUUGlTY+1PQZ/CGk/2xHs/Q iKY8zctxS2diLYtqpUOPJ6/tiYoVq45McDaw0U1oABAeWfSVZeSyEoJUzMb1fo48yo/A S5WSrfvLxFo4veH0UC00eI/521SXe1hhGKtkFC8xuy4gtePCGzJFfYKFwritHv0VleLt OBxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FiVK1evc; 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 d26sor23229154lji.22.2019.07.23.05.28.13 for (Google Transport Security); Tue, 23 Jul 2019 05:28:13 -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=FiVK1evc; 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=6ezilMvH/w5kf4PPHpJm8BaFG4qv6hP7m8ahOV8pd/Q=; b=FiVK1evcjuM8wXacVwRZvfAeYahx220WKcjBmFZTGgu4yWjhaDXvhI9/PDtqJsUgkt AzAP1PxUwYWwq7wnYTnKCKo9orOjnr8YZPlDIvu09q3L6ydUx48uv+PRz9LUrc2Ce6mo SueBcUMFdgWxEh04YY1uqRboCzmIAWcBi57BPAUjS9QPMQIpDzjhPlZM4Tf32L8L8b0f dooTbUbdwo9flHuK6wxuVch+1FvtY1P2q0DUw3JRt0xCraXn5bTiGehcCcfreG1moCBz l51VASPDyDdWAh/RQp7yh0GYbT95ugfgUGptIFuKGGrBklWTbYNg24jGQu89rbqFmx2b TBUw== 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=6ezilMvH/w5kf4PPHpJm8BaFG4qv6hP7m8ahOV8pd/Q=; b=X2Scey7cro4TOI0fXWNm4M5br0vDDb11dHiqeBuSvd7vKg5dh3JRnBhIprAsaFeoqK rYayqJp0Fy86QS0DFXV2ByeueeRPM3KSI34ENEiEnjQw4xlqC6FF1Z6mT0nPxszch1Zy u2fIFTDcsqa0I2rMzj05esrIkwdyRmWQu1U0ur2st1A1dDGRnfXRSqd2ip8GQWrXG3oj NIDFzd6AOc6funRes5H58AEWk5iGfMoZcCwOAQ+Xgoe3u6+99cJ3SeZp4YxwzplJxCl7 aO8AomOXQDNGnmwXXesn3rb9/lDBmc6jZb6Hopt+GkRCDYL0Z+6MxvJKMNJrnB7Tk9wZ R90g== X-Gm-Message-State: APjAAAWTnKe1c15I//2BcVoofDgvkMyY5BOWwYeeer7sqpkeTDZMt7pN HXpixCM/MUvES0IkoeHxsfoIdaoj X-Google-Smtp-Source: APXvYqz4w8yuR150ig5RvdNxLtFsIjwP/sIfc4ufbRFnna+PbGlDGxmtRQ7eP0XEC2EjMck5XAHWIw== X-Received: by 2002:a2e:94cb:: with SMTP id r11mr37468986ljh.212.1563884893149; Tue, 23 Jul 2019 05:28:13 -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 25sm7979971ljn.62.2019.07.23.05.28.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 05:28:12 -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 V3] mmc: mmci: Clarify comments and some code for busy detection Date: Tue, 23 Jul 2019 14:28:09 +0200 Message-Id: <20190723122809.17509-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. Finally, to improve understanding of the code and the sequence of the busy detection, move the corresponding code around a bit in mmci_cmd_irq(). Signed-off-by: Ulf Hansson --- Changes in v3: - Move some code arround to make it even more clear how the busy detection works. Updated the changelog accordingly. --- drivers/mmc/host/mmci.c | 69 ++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 32 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 356833a606d5..4c35e7609c89 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 (host->busy_status && - (status & host->variant->busy_detect_flag)) - 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, 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)) { + writel(host->variant->busy_detect_mask, + host->base + MMCICLEAR); + return; + } + + /* + * 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)