From patchwork Mon Jul 31 12:56:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 109020 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp188922qge; Mon, 31 Jul 2017 05:58:22 -0700 (PDT) X-Received: by 10.84.211.111 with SMTP id b102mr16762311pli.439.1501505902723; Mon, 31 Jul 2017 05:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501505902; cv=none; d=google.com; s=arc-20160816; b=jZJLAUnftAWx1PyghCmsu8mtUnQLjw6/7Z0skBDWi6Y7C19QbELbJlLbsZ31JQyQP+ UcbS7bQmlYJ+tDOXw7MbULsHMSdPys23tVZmNeq47Fi9A8yt9yti14wl8/lfeXawmFXM uc550pe4+i1KNSi4UplMLJUuSgLvYuHpTEescq1Vy+wnDk0lfS8Xtyr8dFek8/8OZ58i brOdNAX4I8neiEzAF4vbeYQRRH0/LwAVbPjI/FlToZu3gWHguZi3j5gpTOvw8++18p3i Nb7WcBHTHZNH2YcbYAALcMkM2VOF9+T4nfRBq3Curt/4hANE9eLESPwY5VzAP/aLj9BS CxOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=IlleBJNVGR3b4ZmWgM3aFfNVEgGNFMMLxEC3u8kMuV8=; b=ih9MsXyDgAWkM/SO3UOjGXbVv31Y3o3Ki/ZKEaUaPuOjq5qh0YrVxZj99zMUdHsqhs O+nIBNliKcjeLmXPvNs0DQn5MP2I+j+A3EBJLXCFXMbuIJITIpaT0dyF5S2Vq8zixuiW cjAWKfB/LGDldyZC5zt5mLR5kyDZ1nJg36kIJmyUJIRNjf2d9+SDW7fa4+R2Lzb4JoVQ 4VGuHfPOsxFocb9yxiZSiLMQ/PSjimECVUi5G4zFNa281xEUeqDkuIduDi8paLwNhwQp zfZbByP1b14RijBYK72otNAoVvWjb7UC7CP1aCCzAMzBMAB1E8zrB/AgkvH4ExMSrHvE 7v4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.b=gO6TrIWa; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y62si12738415plh.640.2017.07.31.05.58.22; Mon, 31 Jul 2017 05:58:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.b=gO6TrIWa; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751862AbdGaM6V (ORCPT + 6 others); Mon, 31 Jul 2017 08:58:21 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:52619 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751446AbdGaM6U (ORCPT ); Mon, 31 Jul 2017 08:58:20 -0400 X-Greylist: delayed 3480 seconds by postgrey-1.27 at vger.kernel.org; Mon, 31 Jul 2017 08:58:19 EDT Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id v6VCvU90019404; Mon, 31 Jul 2017 21:57:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com v6VCvU90019404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1501505856; bh=4nx0hltbsZl3sfcC5Ue2xkUrHVYqz8B0eDFYATdikc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gO6TrIWaZ2rFi9ejxFBdgEnEqeN960y9NbHg7Xb18LKFDA7/v/4ERAf6/le8k7lrb bgnRHN5VYEHODRjAxkrRknAgi39aXipLkZtQ89vp0TZtoFX1AJMYx9mZlOTVQ83Itq FinyPCjGQIF9fYMEoqm0/dWEYYz2KN9IYjeYL050iizClG3Ahs8ppHYE51tB0hNV4H G1vx4d00C1y9ExbqzcWqofJYGOcESaLoLELPa9Ktq+7rDvSZHccP+Aj3REdwg3HO9x JcpVrzP/XxcTPj7cnc6wvPmQSSrkq5i0bIJ4pFvwBQb4Gy6KyIXdv8lyduAXK201Gq qVwaU167U4s8g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mmc@vger.kernel.org Cc: Piotr Sroka , Adrian Hunter , Masahiro Yamada , linux-kernel@vger.kernel.org, Ulf Hansson Subject: [PATCH 3/3] mmc: sdhci-cadence: add suspend / resume support Date: Mon, 31 Jul 2017 21:56:49 +0900 Message-Id: <1501505809-393-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501505809-393-1-git-send-email-yamada.masahiro@socionext.com> References: <1501505809-393-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Currently, the probe function initializes the PHY, but PHY settings are lost during the sleep state. Restore the PHY registers when resuming. To facilitate this, split sdhci_cdns_phy_init() into the DT parse part and PHY update part so that the latter can be invoked from the resume hook. Signed-off-by: Masahiro Yamada --- drivers/mmc/host/sdhci-cadence.c | 77 +++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 9 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c index 19d5698244b5..7473766801a5 100644 --- a/drivers/mmc/host/sdhci-cadence.c +++ b/drivers/mmc/host/sdhci-cadence.c @@ -67,9 +67,16 @@ */ #define SDHCI_CDNS_MAX_TUNING_LOOP 40 +struct sdhci_cdns_phy_param { + u8 addr; + u8 data; +}; + struct sdhci_cdns_priv { void __iomem *hrs_addr; bool enhanced_strobe; + unsigned int nr_phy_params; + struct sdhci_cdns_phy_param phy_params[0]; }; struct sdhci_cdns_phy_cfg { @@ -115,9 +122,22 @@ static int sdhci_cdns_write_phy_reg(struct sdhci_cdns_priv *priv, return 0; } -static int sdhci_cdns_phy_init(struct device_node *np, - struct sdhci_cdns_priv *priv) +static unsigned int sdhci_cdns_phy_param_count(struct device_node *np) { + unsigned int count = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(sdhci_cdns_phy_cfgs); i++) + if (of_property_read_bool(np, sdhci_cdns_phy_cfgs[i].property)) + count++; + + return count; +} + +static void sdhci_cdns_phy_param_parse(struct device_node *np, + struct sdhci_cdns_priv *priv) +{ + struct sdhci_cdns_phy_param *p = priv->phy_params; u32 val; int ret, i; @@ -127,9 +147,19 @@ static int sdhci_cdns_phy_init(struct device_node *np, if (ret) continue; - ret = sdhci_cdns_write_phy_reg(priv, - sdhci_cdns_phy_cfgs[i].addr, - val); + p->addr = sdhci_cdns_phy_cfgs[i].addr; + p->data = val; + p++; + } +} + +static int sdhci_cdns_phy_init(struct sdhci_cdns_priv *priv) +{ + int ret, i; + + for (i = 0; i < priv->nr_phy_params; i++) { + ret = sdhci_cdns_write_phy_reg(priv, priv->phy_params[i].addr, + priv->phy_params[i].data); if (ret) return ret; } @@ -302,6 +332,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev) struct sdhci_pltfm_host *pltfm_host; struct sdhci_cdns_priv *priv; struct clk *clk; + size_t priv_size; + unsigned int nr_phy_params; int ret; struct device *dev = &pdev->dev; @@ -313,7 +345,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev) if (ret) return ret; - host = sdhci_pltfm_init(pdev, &sdhci_cdns_pltfm_data, sizeof(*priv)); + nr_phy_params = sdhci_cdns_phy_param_count(dev->of_node); + priv_size = sizeof(*priv) + sizeof(priv->phy_params[0]) * nr_phy_params; + host = sdhci_pltfm_init(pdev, &sdhci_cdns_pltfm_data, priv_size); if (IS_ERR(host)) { ret = PTR_ERR(host); goto disable_clk; @@ -322,7 +356,8 @@ static int sdhci_cdns_probe(struct platform_device *pdev) pltfm_host = sdhci_priv(host); pltfm_host->clk = clk; - priv = sdhci_cdns_priv(host); + priv = sdhci_pltfm_priv(pltfm_host); + priv->nr_phy_params = nr_phy_params; priv->hrs_addr = host->ioaddr; priv->enhanced_strobe = false; host->ioaddr += SDHCI_CDNS_SRS_BASE; @@ -336,7 +371,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev) if (ret) goto free; - ret = sdhci_cdns_phy_init(dev->of_node, priv); + sdhci_cdns_phy_param_parse(dev->of_node, priv); + + ret = sdhci_cdns_phy_init(priv); if (ret) goto free; @@ -353,6 +390,28 @@ static int sdhci_cdns_probe(struct platform_device *pdev) return ret; } +static int __maybe_unused sdhci_cdns_resume(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_cdns_priv *priv = sdhci_pltfm_priv(pltfm_host); + int ret; + + ret = clk_prepare_enable(pltfm_host->clk); + if (ret) + return ret; + + ret = sdhci_cdns_phy_init(priv); + if (ret) + return ret; + + return sdhci_resume_host(host); +} + +static const struct dev_pm_ops sdhci_cdns_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(sdhci_pltfm_suspend, sdhci_cdns_resume) +}; + static const struct of_device_id sdhci_cdns_match[] = { { .compatible = "socionext,uniphier-sd4hc" }, { .compatible = "cdns,sd4hc" }, @@ -363,7 +422,7 @@ MODULE_DEVICE_TABLE(of, sdhci_cdns_match); static struct platform_driver sdhci_cdns_driver = { .driver = { .name = "sdhci-cdns", - .pm = &sdhci_pltfm_pmops, + .pm = &sdhci_cdns_pm_ops, .of_match_table = sdhci_cdns_match, }, .probe = sdhci_cdns_probe,