From patchwork Mon Jul 15 16:42:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 169013 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4635515ilk; Mon, 15 Jul 2019 09:42:35 -0700 (PDT) X-Received: by 2002:a05:651c:87:: with SMTP id 7mr7366893ljq.184.1563208955219; Mon, 15 Jul 2019 09:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563208955; cv=none; d=google.com; s=arc-20160816; b=JdNnItEB0wdNuJvVU8trX5etSJVQ6YM6tFFXQ5dIsKpv/nNOuxV/3vK7Pr08wMOQzR CSb7at430LUqcTu0BFEBbr214Eu7JDi/0yeyXCrj7Fazag+x3NdMHeAhgu1+kfGG2Kgl eEmnzE9fP1JVeimVjCBQoupur9N36V05Zfc+8u1zBRdEwBp2Bjd/orbozysvVOuDQg0w QKbohv8pm7/TesGrLccWECL1cfXm7/NKyhNKZ4LxTTTomighvIIQgNCgtHt9kSPextKq p2f5Tq+Iwq2pK14SD6a87IJ3TQeAtBfRTKdREojg3uEb2HQC8jAXpyrd3uKfZISsM0/4 7CFA== 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=Dp5F9BRn6xjrJQrJavuPjkm0wkNhqKMjc1pUUm8YKQI=; b=PZJPuSTKEnacFhNGkFOMLtS2ch3jGPCnGSqGdmpPsQzuGtaQXdb/Fi8/DBnonrTCnf GzV0HGjnLv0wp5DUD1WFL/YJ5hE87ezjpV+M2pEZIg/bZVTdofCruSGSgfLav2VhB3JM uJNVSuyNaWRWyjxeJ/LOdg1K0XI80zlkCu5lbRM9BUwa7tIRcM1rZ5PB67vtNBzi9jR2 lI2sc5jLBW0vA87a6d0yE4T5h1Ptp/TeJKvv8yjmnTx+Dk5BzfqvZsQVbc2gcg7Ys45U 9JqlSRw/RyIgGfJutrbqvm7oPAM7K43VTNkKyH8e26UUNqQocabJFxl30I1eu0mfoAIN KXsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QWMzKFma; 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 b143sor4331186lfd.43.2019.07.15.09.42.35 for (Google Transport Security); Mon, 15 Jul 2019 09:42:35 -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=QWMzKFma; 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=Dp5F9BRn6xjrJQrJavuPjkm0wkNhqKMjc1pUUm8YKQI=; b=QWMzKFmameXZURZ1ASykm+hB9PEaUS9hRkNFBRzPeRFOAdV+17GmLneT/JQfKIAEkH RSOI35ZVaerr7dafTC1ZKshPt360PQweoaC7Vm+L9796/2Xz5oyXeerJbpz8KmNMGzTY 6VFR0mFzkpPr0tIDRVa40up+XiaJQpBdlSUqpPf/nMyQVUU6VeJws6VAeuzliq3rI5OG UsmlHA/uBlKBoAlxc0dcfbn22vAJXMNRxR8TwUtbjWEBDik+lCqTkBFusk6BWv6naNGE zOL/BAiBj+4x62944j136/A3NFcmHM2V+VUuVvc3EFPhc1Jdx4ouH3cHZnefjYtZKAyX /tzQ== 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=Dp5F9BRn6xjrJQrJavuPjkm0wkNhqKMjc1pUUm8YKQI=; b=kW/p7zD2XTrTqRo8Cb2SJg7qu5+O73ZU/ujaiDe0fiEX6YStjfAIDiI7mQ6Seg12YW pee+OEqrnb9j1XhOYd/6v/CkiZo/yDeka0O6ULoAxobF5aur4ixmwumjUR839XSN8mck /8m2ZJOAD+nEcuH0snoDIgn6vjWwar2Vk1ku6kidpPfCWAOtKy5VsmCW67yoRKU6KpIN kSJDCkmMk7wUIlvGYP0eHTPzMT8nQ0UK+hgTvkQK2iTY5m9HTiTdX5BW/7cBtG1t3LLp LYqqhskHjWNwotaZQ0LH459Yhaix3NivAXa9yhabLKRYxnhAGeaYVg0130iHqvv1FC0D yndw== X-Gm-Message-State: APjAAAWQ5cjajTs+oqExZUL1wk8ZfM2KRKbma4kq9+X1He5ucH9Zr9Yc FehqQe0YSY8lqqbQdz9nPB3I0EIl X-Google-Smtp-Source: APXvYqzuzD2TZI8BeubLbcQrscbda2jI2V57z+gir3IBFP8/ZI/a562T8OygrX9VBTcKTTbMcLb60Q== X-Received: by 2002:a19:5d53:: with SMTP id p19mr9545054lfj.109.1563208954852; Mon, 15 Jul 2019 09:42:34 -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 m17sm3248782lji.16.2019.07.15.09.42.33 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 09:42:34 -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 2/2] mmc: mmci: Clarify comments in the code about busy detection Date: Mon, 15 Jul 2019 18:42:30 +0200 Message-Id: <20190715164230.27348-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. Signed-off-by: Ulf Hansson --- drivers/mmc/host/mmci.c | 43 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) -- 2.17.1 Reviewed-by: Linus Walleij diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 5f35afc4dbf9..94e7ba368cca 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1222,19 +1222,30 @@ 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. + */ if (host->busy_status && (status & host->variant->busy_detect_flag)) return; /* * Before unmasking for the busy end IRQ, confirm that the - * command was sent successfully. + * command was sent successfully. To keep track of having a + * command in-progress, while waiting for busy signaling to end, + * store the status in host->busy_status. + * + * Note that, since the HW seems to be triggering an IRQ on both + * edges while monitoring DAT0 for busy completion, but the same + * status bit in MMCISTATUS is used to monitor both 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. */ if (!host->busy_status && !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) && @@ -1248,19 +1259,17 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, 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 status 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) { @@ -1506,14 +1515,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)