From patchwork Mon Jun 4 06:30:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 137617 Delivered-To: patches@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1130878lji; Sun, 3 Jun 2018 23:30:32 -0700 (PDT) X-Received: by 2002:a19:9886:: with SMTP id a128-v6mr2170170lfe.87.1528093832852; Sun, 03 Jun 2018 23:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528093832; cv=none; d=google.com; s=arc-20160816; b=h2lNWR9MnWpxpVh8e5G3HPMLCYunSMul7anvgN5kwIkF0OabHAvGoRR/xc0gdJYo3E bGQ7Pu+PiQTmyTKBWE/aOTOY0y13eLXIJASp+B3CMX53oxx1IxYuWMbDExcoQDFQ4llU HinO0p01HQPUzJz3t4auJGrmxfjDw+YVTDk7pQFalTyx4tHYRasFob/hzTTSHLPq6FCV H1nyJo+vbeSTyYk0380BAGPslOi/wjN9VZFVtmdKzU0zLlb0VhLTeZcABK+6eIHGzosY PcybV6WluYUazN+TwlA9TdhrXu8ZYRKu1m0kOgGZVNJX+pwgjsR9gCkbjW0zet7bmzwv IahQ== 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 :arc-authentication-results; bh=uC2ZkqqPQ6i2R/3XSeZZvncMOjNr5ymw+nTiocMZg0k=; b=G2xtJQbkWuDoMGyQCsvMUXlnj8hDJppnLmdZxmxTu8b1a5R5OMqeAL9UTlsdS9PbDk 8nwHGI2uL49yibcQ/tMGT5nlnSObBbwnHRRvRBIK1cAqNjaMV05/T+dEHcvIrhhnLiQQ x1XrZZCuMfZr8A3mTmydlEs3R6t7ItRU9DsNeQAQ8mwBxeKAQS8+QIhujOXMhOhDTWLq dF+hbzlx6Ph3iF2QO+AtU4G+VWbDil53zQAyFdlIKwO/pXsIU5l9wvJJT7EBEi6Hb49t p3T/iss1bLMECmBYzhaudgb/HxLapahqOWZtAuabgVncVupzAiwZXSpV1aZMhaGH6SN7 cr7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IXvY2PgS; 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 t1-v6sor380476lfi.59.2018.06.03.23.30.32 for (Google Transport Security); Sun, 03 Jun 2018 23:30:32 -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=IXvY2PgS; 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=uC2ZkqqPQ6i2R/3XSeZZvncMOjNr5ymw+nTiocMZg0k=; b=IXvY2PgSkoQ6j/UG6VorQXuzRvltelACCdvPy5h6JTvxRtPGNAsHMSzhyXy+8em+nI OghLFndwWaNC71mdlag3QsTwtW6+vBk6fTSsoshxQ+aQyHUtBHLASj71HKd/JnLrg+P+ Hemx7MAH/07xYtAyzGdq5HhOf6ynEHNNcObEo= 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=uC2ZkqqPQ6i2R/3XSeZZvncMOjNr5ymw+nTiocMZg0k=; b=rf5NhjIzozFdo31MbxkcI/CqJEp2o/51UwNIIJ+AOhJLuBvj9+BlwDCDKhsVM/uxCS PO9avSESMe1R2RVLpuULPha4ilpSgVAoRY4Gfc3p36jDW98IE+249BHt6hRUmAqCew9+ cZP5dIW3jRtS8Hu5JtZZ7q2ZMcAQMI5q1ZjN20J1hJpnUxxeq+11FWfGbyBDEKNAtA8p 6cRIRgBU8ZcmdNo/bN8QciGSDnfButQhtsFhuPp5ot+Wuj3jsx+cKwtjCiBc+x7Rqn1z CqSxWkw3D+Mt8LXPjkDEpnqHq8P+vajjtrCvKZnxSYTPpM7gYhQ9zXDoynNH+5y77cXR rxtA== X-Gm-Message-State: ALKqPwd4O75bd7EOOyTz8bp4MjU88ejkC4Y6TgLBbMlVe9P/sFPYbMdV RXr5hK/Ug0+TUX5MolNQNbcl3lEg X-Google-Smtp-Source: ADUXVKI8seFiDP+x9PVXHHuDukT3X8mamLMNG6jr/5FfQDtpxpBu4iSAuxdzmY2fLflGIFXVyQvwBw== X-Received: by 2002:a19:f611:: with SMTP id x17-v6mr12264268lfe.116.1528093832524; Sun, 03 Jun 2018 23:30:32 -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 s18-v6sm3813171lfc.22.2018.06.03.23.30.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jun 2018 23:30:31 -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 v2 4/4] mmc: rtsx_usb_sdmmc: Re-work card detection/removal support Date: Mon, 4 Jun 2018 08:30:24 +0200 Message-Id: <20180604063024.15629-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.0 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 --- Changes in v2: - Schedule a detect work only when there seems to be a card inserted. --- drivers/mmc/host/rtsx_usb_sdmmc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 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..669c6ab021c8 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,31 @@ 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; + if (sdmmc_get_cd(host->mmc) == 1) + 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 +1470,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);