Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2827435yba; Mon, 15 Apr 2019 21:50:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmgtXizSjznDsWXz7Lt+aUCxNpZs3DkGRRmMP/TCojt4P/RqOTiyjbUDv5J4fc5CNtDjZ/ X-Received: by 2002:a17:902:102a:: with SMTP id b39mr44988448pla.188.1555390218921; Mon, 15 Apr 2019 21:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555390218; cv=none; d=google.com; s=arc-20160816; b=jmE91G4yh3DQoTrZof6cxU5eUZnwM32+fFTO9PpD/uyY5FppwhZ3yTpUn/K+5fbXZ7 MYAhVsDBdrBUG3PtgnmAQALO9VeeE/uwN9rbfGVnIeGMZYgmKnDLn+YjweA8vzTinttk wLxuNikD5qDS3nwYVZuL3qufitTdhV3oBOTbKPkZbQT41FwSaJfvopH+HvpRAqXvJoZI pIDbSpUiB26WaBLo34bU49zeXLzkH+b9DwC+792xDFtNi6PtskiOtsNuSQiRqawBdxjZ GHTLBIN7I7jLzdTw54IcM5/ZVWnpNxLOTPdA7O73t+S3220tap1qyFYsM39za48HeVOx WNuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=kIEOBC34VXgRwAAOr7/x08piEOuq8wWbYCpOQFnpLhQ=; b=04eVkf92qY5y+zdbajngP0DGQI05fUa4HqfgP/KiBa7TQR7cFjzXoadlFGlDPGQBXy DyMJ2SWaHEv4VG4DWv/YeellfDsF4KXx7aTv3dtRWoR7Rr1Dypzyeftdl4+0WdrIrer4 7OcQRk7PV0KG7SuxuL0NBznJps1vLyNXboLRydmMtaI04MKRzwZxCv+Y6TzJevHYn6qf anJ4dWjwWxKXBnSZqyAWs2kkllJ5JmG/bF5SC5FbtbGlE8LLOP/rDnLYLNdHyGUiEiSW vHNMYs9g2Zv9Sg772co3TNc4opYr7Jfe4P1BhUNqGZ2Ho0iB8+HgQsw63iZ8LKpJJ7sf soMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 cv9si51298660plb.371.2019.04.15.21.50.03; Mon, 15 Apr 2019 21:50:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727125AbfDPEsh (ORCPT + 99 others); Tue, 16 Apr 2019 00:48:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:59614 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725819AbfDPEsh (ORCPT ); Tue, 16 Apr 2019 00:48:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E29BEAF40; Tue, 16 Apr 2019 04:48:35 +0000 (UTC) From: NeilBrown To: Ulf Hansson , Chaotian Jing Date: Tue, 16 Apr 2019 14:47:29 +1000 Subject: [PATCH 5/5] mmc: mtk-sd: enable internal write-protect logic. Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, thirtythreeforty@gmail.com Message-ID: <155539004934.25108.642381572389480964.stgit@noble.brown> In-Reply-To: <155538933003.25108.3338569916935462285.stgit@noble.brown> References: <155538933003.25108.3338569916935462285.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mtk-sd silicon has integrated write-protect detection logic. If the sdhci isn't marked no-write-protect and doesn't have a ro-gpio configured, assume the internal wp logic should be used. Signed-off-by: NeilBrown --- drivers/mmc/host/mtk-sd.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index 341cf5f03429..d63d6b62f49a 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -433,6 +433,7 @@ struct msdc_host { /* cmd response sample selection for HS400 */ bool hs400_mode; /* current eMMC will run at hs400 mode */ bool internal_cd; /* Use internal card-detect logic */ + bool internal_ro; /* Use internal write-protect logic */ struct msdc_save_para save_para; /* used when gate HCLK */ struct msdc_tune_para def_tune_para; /* default tune setting */ struct msdc_tune_para saved_tune_para; /* tune result of CMD21/CMD19 */ @@ -2119,12 +2120,30 @@ static int msdc_get_cd(struct mmc_host *mmc) return !val; } +static int msdc_get_ro(struct mmc_host *mmc) +{ + struct msdc_host *host = mmc_priv(mmc); + int val; + + if (mmc->caps2 & MMC_CAP2_NO_WRITE_PROTECT) + return 0; + + if (!host->internal_ro) + return mmc_gpio_get_ro(mmc); + + val = readl(host->base + MSDC_PS) & MSDC_PS_WP; + if (mmc->caps2 & MMC_CAP2_RO_ACTIVE_HIGH) + return !!val; + else + return !val; +} + static const struct mmc_host_ops mt_msdc_ops = { .post_req = msdc_post_req, .pre_req = msdc_pre_req, .request = msdc_ops_request, .set_ios = msdc_ops_set_ios, - .get_ro = mmc_gpio_get_ro, + .get_ro = msdc_get_ro, .get_cd = msdc_get_cd, .enable_sdio_irq = msdc_enable_sdio_irq, .ack_sdio_irq = msdc_ack_sdio_irq, @@ -2256,6 +2275,15 @@ static int msdc_drv_probe(struct platform_device *pdev) host->internal_cd = true; } + if (!(mmc->caps2 & MMC_CAP2_NO_WRITE_PROTECT) && + !mmc_can_gpio_ro(mmc)) { + /* + * Has write-protect but no GPIO declared, so + * use internal functionality. + */ + host->internal_ro = true; + } + msdc_of_property_parse(pdev, host); host->dev = &pdev->dev;