From patchwork Sat Apr 8 22:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13205848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B0DDC77B70 for ; Sat, 8 Apr 2023 22:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbjDHWAr (ORCPT ); Sat, 8 Apr 2023 18:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjDHWAq (ORCPT ); Sat, 8 Apr 2023 18:00:46 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581255271 for ; Sat, 8 Apr 2023 15:00:44 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id g19so45284652lfr.9 for ; Sat, 08 Apr 2023 15:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991242; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ULAzhGFOFghdBv7gibJVH7jzq8I3KmMXjSq82uGdpgg=; b=kW6IvLkJFEUd+u+C5vxTrWmTcDMtgKnnz/RA3bxulR8plM+mgPgVIHU5SFci7Ko9Xl fBqy7oBnhxibaNJYHYj3gp6rhj0oJEX68vH9AfJ+p2UIggS/o19tW6RH3Pu9cHG92tg2 HUDs4PVTqYmUPkt8M+OB7GJEYBsrd2tp+mWNa8dpMElWjAjcGke1y5STI9VOxOtdExDv m77w6XHbFkRfBmuTkFWxCrgm0LvXFiQ1+Di/lAoGEpvMGXaeR3lHvLCuUy+77HX0Qt8v /YykX9VrfN3xO+eoxqRIt42zgB+UiE8pOhk0gZ1dCBrdBYfeP/TJI1/Mu7cr2aYFBqGV c8bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991242; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ULAzhGFOFghdBv7gibJVH7jzq8I3KmMXjSq82uGdpgg=; b=A0yAysshgOf1c71Xf5sNB1w4x5Bx1mg3rKkp652HNjpSaio0DHw5dpeoJXRFCPoV9p c3eqlO2q7wsboWx24VebbIWJbwmvL4Jvu7KtWsA8GiAlPt3GKvSZyVmaFE9WGPahjjCA CmOrkIqllnqEpf0song+Ms7UmkPL0HBDpvCn+x1XqLNzXvhCHBwaz4zJlDEXmkDO8dvy A4JBI4HhmaMm4/RiwnGM745nB3oO/ArZTAcqoYcbZ93igW3wB4GBXDGOq86l/QVjbUah MD6/wAoH84gNZzHnWSrOdTaDMlv1Wk1PCWk9lqUI+bY5aglPqSvb/+0KsjFBXruSYE/5 mUUA== X-Gm-Message-State: AAQBX9f8JDkjHat3J0XwvlZqr+f5chnboDZc9GIbZE/rgydCW48hWboa D8e45uO00L/Xtb6DLTPll9XKig== X-Google-Smtp-Source: AKy350aU5KX6WtplCCVlS7xJYrXmCJUhSjgdJ2ze+/oiJOLk96JJMhDvVg5EYOc7SWhgokdXLmpXGA== X-Received: by 2002:ac2:5ddb:0:b0:4eb:44bb:faeb with SMTP id x27-20020ac25ddb000000b004eb44bbfaebmr1870019lfq.39.1680991242725; Sat, 08 Apr 2023 15:00:42 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:42 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:30 +0200 Subject: [PATCH v2 09/12] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-9-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org These four lines clearing, masking and resetting the state of the busy detect state machine is repeated five times in the code so break this out to a small helper so things are easier to read. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 76d885d7e49f..9a7f441ec9d6 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -654,6 +654,17 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) return MCI_DPSM_ENABLE | (host->data->blksz << 16); } +static void ux500_busy_clear_mask_done(struct mmci_host *host) +{ + void __iomem *base = host->base; + + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; +} + /* * ux500_busy_complete() - this will wait until the busy status * goes off, saving any status that occur in the meantime into @@ -668,11 +679,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & err_msk) { /* Stop any ongoing busy detection if an error occurs */ - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); goto out_ret_state; } @@ -715,10 +722,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) retries--; } dev_dbg(mmc_dev(host->mmc), "no busy signalling in time\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; + ux500_busy_clear_mask_done(host); break; /* @@ -740,11 +744,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); } break; @@ -756,11 +756,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); } break; @@ -775,13 +771,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) /* We should just get two IRQs for busy detect */ dev_err(mmc_dev(host->mmc), "spurious busy detect IRQ\n"); } - - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); break; case MMCI_BUSY_DONE: