From patchwork Thu May 31 09:40:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137346 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6373749lji; Thu, 31 May 2018 02:40:57 -0700 (PDT) X-Received: by 2002:a19:1329:: with SMTP id j41-v6mr3772681lfi.141.1527759657592; Thu, 31 May 2018 02:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527759657; cv=none; d=google.com; s=arc-20160816; b=wjX+w/hllqqje53uaARqqQW4914XVmpZwLF9WdSjIAjRSOB7hZNIU+CV0gYQZlBdKD YftmoOJiiuZeYEvqJ4+hWeVJX6rgpqWLm0DGw5di2MW/Eid0xpuNkliaVTtpxPgBGIPQ 6G6Rrw/l/rR/crXspVJYvhTryG12pCEsGolUcoAbjZGg5jgKfvBKPNqCLjVf0vDjCf4j /yfDyQEauIgLCDPQhY/T+6EblqAcbqizlOO1u7zGp6zsKRvNF2UkElrerQcSZEoC6AAt J4NEXVGcpaYIxmTPnvg1c7Vj15W+29PM+m7x5dbJj6qUS2i0Yv/l/Sglw+gcqJHAekfA mVbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QdA4eLivmm4GmqhEv/vJyACJVRc4XAMEwA1ofpsDyDI=; b=WkS1q9u1/LeTFStWE7lr400+5Z1qUJkUYqyV7LN4h+DVRNii5pce5h1No5xMtBJSTz 4xsh6tyIQCELdxlXiQ7jjjKMWqFKHuN9RnD6IAFtFgVDci+/+tHiKsoeO69UZTgU1Tq8 Z+TiOSOARX1jLg9nNJxEmaXMiDtAuUsmUgf2xq0j56SdnDBRqx341GRdJKjlpMqFYqGu NgGnoAlfXbZcC65BlCTATYGxgcKQNAIM7c3Jw5WxNCDp9H/Q0HW5x5xjNkPesZ2wb9dR Yxk9yav9ybDGwTYZqGvOlVyY3fbTMrq/WpoJWdmXYulfrjTdRJiCWIuCyrzIuDhOsibh Wf+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HYzHgEqc; 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 r18-v6sor2861535lja.40.2018.05.31.02.40.57 for (Google Transport Security); Thu, 31 May 2018 02:40:57 -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=HYzHgEqc; 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:in-reply-to:references; bh=QdA4eLivmm4GmqhEv/vJyACJVRc4XAMEwA1ofpsDyDI=; b=HYzHgEqc7z+L12QeqR68eC3TYvRhJl/jYTPbNPC82dlMSrBEiEhfGOlntkOqiKXlLY n9ENuKuH61pCW+NQhFZTRspY7ymNmhQtw2uI6pPTvrs97n+H+j3kLuc+m0dcZDbQAeGK +OlLV+H6gUby78bYRZjnd2GfNZO6m7Ud1KGkM= 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:in-reply-to :references; bh=QdA4eLivmm4GmqhEv/vJyACJVRc4XAMEwA1ofpsDyDI=; b=aRk4EfJdtm4vUR4h75G26tNE0dXIGYYMixzm72L/48oqBviKomGbFygeGi6VHYz9Ks r2jFdg/NrL0KPaXgxfQQrI9+YIFXzsPN82J2HsjMB6JQu4niJxb7iBD67RKwwcpitk9u OUav3gGOoyKfbxnzH4bv8sdyR/rUmirVEo5cmFhw3gDNudJvf81O5TH8cXpilwG0wlLE rWDy0BBIeXz/4C59IG0J/MMcPSCoDyEGeyZkAJEcvTvBskQfIkxRaw4MIHJZ++CDQT7a wv/NFpDy6AyFe6Lue7q3pF1Q0b6GpLZUiGafBsQXFhXa0PYbjYGJzspX157oahodpRcv e32g== X-Gm-Message-State: ALKqPwcT/KlKfA9f9FM/4D6qV/4PUzBXI6Ud0Ry3P+vB4t/T34QTUaB6 R64lVNlCSsaLENpQR8DDcoDnK3oF X-Google-Smtp-Source: ADUXVKKpIDeEsl9TnBnL6uZR1F51TJO79WvKlvKUWHJFzwR/K3zHabawQqbMarsUDSq0eGufsLeIrA== X-Received: by 2002:a2e:3e0c:: with SMTP id l12-v6mr4942906lja.23.1527759657414; Thu, 31 May 2018 02:40:57 -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 y12-v6sm7496302lji.34.2018.05.31.02.40.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 02:40:56 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Kai-Heng Feng Cc: michal.pecio@gmail.com, Ritesh Raj Sarraf , Bauer Chen , Alan Stern Subject: [PATCH 4/4] mmc: rtsx_usb_sdmmc: Re-work card detection/removal support Date: Thu, 31 May 2018 11:40:41 +0200 Message-Id: <20180531094041.27902-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531094041.27902-1-ulf.hansson@linaro.org> References: <20180531094041.27902-1-ulf.hansson@linaro.org> The rtsx USB parent device, has logic to detect when a card is inserted into the card slot. Although, the logic can't detect when a card is removed. This makes things a bit tricky, which is why the current method is simply to turn on MMC_CAP_NEEDS_POLL during probe. Using MMC_CAP_NEEDS_POLL means lots of energy being wasted, as the mmc host becomes runtime resumed frequently by the mmc core, while it polls for new cards being inserted. To address this problem, let's start relying on that the rtsx USB driver runtime resumes its child device, which is the rtsx_usb_sdmmc device, when it detects that a new card being inserted. This means dropping MMC_CAP_NEEDS_POLL from being set during probe. Instead let's implement a ->runtime_resume() callback to schedule a detect work and to set MMC_CAP_NEEDS_POLL. In this way, polling is enabled as long as there is card inserted, thus we can rely on the mmc core to detect also when the card becomes removed. Furthermore, to avoid polling forever after a card has been removed, let's implement a ->runtime_suspend() callback and make it clear MMC_CAP_NEEDS_POLL. Signed-off-by: Ulf Hansson --- drivers/mmc/host/rtsx_usb_sdmmc.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) -- 2.17.0 diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c index ca0ab8eb30c3..91eb3b32d068 100644 --- a/drivers/mmc/host/rtsx_usb_sdmmc.c +++ b/drivers/mmc/host/rtsx_usb_sdmmc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1324,7 +1325,7 @@ static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host) mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 | - MMC_CAP_NEEDS_POLL | MMC_CAP_ERASE | MMC_CAP_SYNC_RUNTIME_PM; + MMC_CAP_ERASE | MMC_CAP_SYNC_RUNTIME_PM; mmc->caps2 = MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_FULL_PWR_CYCLE | MMC_CAP2_NO_SDIO; @@ -1429,6 +1430,30 @@ static int rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int rtsx_usb_sdmmc_runtime_suspend(struct device *dev) +{ + struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev); + + host->mmc->caps &= ~MMC_CAP_NEEDS_POLL; + return 0; +} + +static int rtsx_usb_sdmmc_runtime_resume(struct device *dev) +{ + struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev); + + host->mmc->caps |= MMC_CAP_NEEDS_POLL; + mmc_detect_change(host->mmc, 0); + return 0; +} +#endif + +static const struct dev_pm_ops rtsx_usb_sdmmc_dev_pm_ops = { + SET_RUNTIME_PM_OPS(rtsx_usb_sdmmc_runtime_suspend, + rtsx_usb_sdmmc_runtime_resume, NULL) +}; + static const struct platform_device_id rtsx_usb_sdmmc_ids[] = { { .name = "rtsx_usb_sdmmc", @@ -1444,6 +1469,7 @@ static struct platform_driver rtsx_usb_sdmmc_driver = { .id_table = rtsx_usb_sdmmc_ids, .driver = { .name = "rtsx_usb_sdmmc", + .pm = &rtsx_usb_sdmmc_dev_pm_ops, }, }; module_platform_driver(rtsx_usb_sdmmc_driver);