From patchwork Fri Jun 21 06:12:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 167361 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp312625ilk; Thu, 20 Jun 2019 23:13:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5n9YyP+Uj7PUcY/+M52VPE/ygeP5QiDJjJYW/lTOHuh81r45icvvKhxeilxYII3bMLko2 X-Received: by 2002:a17:902:8509:: with SMTP id bj9mr14422141plb.79.1561097582626; Thu, 20 Jun 2019 23:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561097582; cv=none; d=google.com; s=arc-20160816; b=kV9WCLM4HiG+Ne8LHiis8nL3ZibHk7Mu6IDa1fy5qIYX9WIiDuXa5TXv0v7Bv/T7D+ ItDKMCJsdRycX47DhR5cyGDWqkCkz1/wxJECxsgz7nHUrr8/7E2n8ZAeBd6m8Qy325OJ vPWt9E940eYd4W5TLZ0FqyyNa8KlBr6QhPFhuTy9syd0yfblAtWxPxrijkQVupV7NkLQ x9adDBac3ISGh362gdwwFvT1jPGxtLCZzaaL383ntUlNQgtwUn+mglMzxx7nT7tWmzEq i00nRseCBWwrGCWO2/Mlpbloik+TNp5OSRxdYphc4p91FYa2PVRtl6aDxnFRkxfXUHPZ 4QTw== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ImM7LoJ0g/LV9Msk8fC9rkqyN6ipnuYryn1oHdAjw90=; b=Hxm71dJA2Q9dQ9tGEa2U3f6k6VwfrWGOiDdpc2HUkZPTiRQjfnUXccOgfCOsSNARMT ZT6sDcGCGIKG2M0s3lGXqgk11UVcCMD2228G1XtFaPgRNQctbJs/gQGMI9AVFQASRq3t driGUwZXPTBDQ8UI2C6e9Vn4iWROiEr/GugIbQpFKLQ1XSAM3h5JDz1kyekHbo3XPD/U q7H9pxs5x1s0A2j1YUr3EX9Vh6g0SIXgPNE6jSOj0buYB/GU/rON4O7Yciz30JKTpiq2 Q1TiJswW/SoUrFbNgZORskDLQ9xfs6snSitrih8Lg0LEquvU3Yp+I/bR+kGEO+4pobsM Laeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IsSBjGrF; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x22si1896335pln.150.2019.06.20.23.13.02; Thu, 20 Jun 2019 23:13:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IsSBjGrF; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbfFUGNB (ORCPT + 8 others); Fri, 21 Jun 2019 02:13:01 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44412 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfFUGNA (ORCPT ); Fri, 21 Jun 2019 02:13:00 -0400 Received: by mail-pl1-f195.google.com with SMTP id t7so2453869plr.11 for ; Thu, 20 Jun 2019 23:13:00 -0700 (PDT) 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 :in-reply-to:references; bh=ImM7LoJ0g/LV9Msk8fC9rkqyN6ipnuYryn1oHdAjw90=; b=IsSBjGrF+DN7QHmXac43Ny79aaDEhysk2zRkeDW43Wox0gAQlxq2jhbf6FPNlZ0Ivg W5dXPLPd/Gl+e6zZvdKMuSxCqWPSObH8X+6Ftomh0xUVUeY9bJW8JlShqfj7hcs/Efjb WCJhUx6hG8j/IV54/quUx/94bk1d6jXYUvkajSza2zunVxXSy+NIClWkeztrxvb4bGIA M0VGYyvy930CJIehNbG1vyrmufkJ6KudfaIw/VvW8p0aT4auVM1Gfc1eLZmKefZGqdyb fWgl0VC4cT8ipH3uf17ndRAQsBWPklzGRQaHexZTkF7/F/oKNyfwQgR8BLi5BzlZwF2r ADDw== 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:in-reply-to:references; bh=ImM7LoJ0g/LV9Msk8fC9rkqyN6ipnuYryn1oHdAjw90=; b=bEieTflk1NZIKXp8NhVMwXH1O8wxZl0rnayBYdRibBFSAXiErt+rpHoUAOSnXObF2b 39+5ykKiHnAhW8+82TsHqqN2Dhd0SBqngDnghvhAsugYMUakKmiKBCfRbDEh1/o+YKQC qOzSHCwEIwdsExXJ+ktVdgXWziS7gIfTrOZ63pZYbbgvy9SWijWnQgqrv6t0qvakx5QT iVwyyU/BPDaG4+p6lLdZSwcc/CQDEPVlYoVBlTywPL7lEzWKoH/IyYGFw8BEIH5STLfX JNa8p/5jAf82rJiHBbE2uU8mc+Jo0ESYJVKfMTB0vf/29ZAxi5+e1WskHDSXzTCxIVyI IEPA== X-Gm-Message-State: APjAAAWN+dBcK/zzGMLfm15t3xRDUyjYhiioTWkp8lmRVMbjL1FAW5oG WNpW/GJouGkdtOTcLYYTVwQvjA== X-Received: by 2002:a17:902:b603:: with SMTP id b3mr69912736pls.72.1561097579911; Thu, 20 Jun 2019 23:12:59 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id x7sm1266134pfm.82.2019.06.20.23.12.57 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 23:12:59 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org, zhang.lyra@gmail.com, orsonzhai@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: baolin.wang@linaro.org, vincent.guittot@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 3/3] mmc: sdhci-sprd: Add pin control support for voltage switch Date: Fri, 21 Jun 2019 14:12:33 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org For Spreadtrum SD card voltage switching, besides regulator setting, it also need switch related pin's state to output corresponding voltage. This patch adds pin control operation to support voltage switch. Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci-sprd.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) -- 1.7.9.5 Acked-by: Adrian Hunter diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index 8b23c88..6ee340a 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,9 @@ struct sdhci_sprd_host { struct clk *clk_sdio; struct clk *clk_enable; struct clk *clk_2x_enable; + struct pinctrl *pinctrl; + struct pinctrl_state *pins_uhs; + struct pinctrl_state *pins_default; u32 base_rate; int flags; /* backup of host attribute */ u32 phy_delay[MMC_TIMING_MMC_HS400 + 2]; @@ -405,6 +409,8 @@ static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq) static int sdhci_sprd_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) { + struct sdhci_host *host = mmc_priv(mmc); + struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host); int ret; if (!IS_ERR(mmc->supply.vqmmc)) { @@ -416,6 +422,37 @@ static int sdhci_sprd_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) } } + if (IS_ERR(sprd_host->pinctrl)) + return 0; + + switch (ios->signal_voltage) { + case MMC_SIGNAL_VOLTAGE_180: + ret = pinctrl_select_state(sprd_host->pinctrl, + sprd_host->pins_uhs); + if (ret) { + pr_err("%s: failed to select uhs pin state\n", + mmc_hostname(mmc)); + return ret; + } + break; + + default: + /* fall-through */ + case MMC_SIGNAL_VOLTAGE_330: + ret = pinctrl_select_state(sprd_host->pinctrl, + sprd_host->pins_default); + if (ret) { + pr_err("%s: failed to select default pin state\n", + mmc_hostname(mmc)); + return ret; + } + break; + } + + /* Wait for 300 ~ 500 us for pin state stable */ + usleep_range(300, 500); + sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); + return 0; } @@ -504,6 +541,23 @@ static int sdhci_sprd_probe(struct platform_device *pdev) sprd_host = TO_SPRD_HOST(host); sdhci_sprd_phy_param_parse(sprd_host, pdev->dev.of_node); + sprd_host->pinctrl = devm_pinctrl_get(&pdev->dev); + if (!IS_ERR(sprd_host->pinctrl)) { + sprd_host->pins_uhs = + pinctrl_lookup_state(sprd_host->pinctrl, "state_uhs"); + if (IS_ERR(sprd_host->pins_uhs)) { + ret = PTR_ERR(sprd_host->pins_uhs); + goto pltfm_free; + } + + sprd_host->pins_default = + pinctrl_lookup_state(sprd_host->pinctrl, "default"); + if (IS_ERR(sprd_host->pins_default)) { + ret = PTR_ERR(sprd_host->pins_default); + goto pltfm_free; + } + } + clk = devm_clk_get(&pdev->dev, "sdio"); if (IS_ERR(clk)) { ret = PTR_ERR(clk);