From patchwork Thu Apr 5 20:19:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 132889 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp6712566ljb; Thu, 5 Apr 2018 13:20:13 -0700 (PDT) X-Received: by 2002:a19:1198:: with SMTP id 24-v6mr14852372lfr.85.1522959613763; Thu, 05 Apr 2018 13:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522959613; cv=none; d=google.com; s=arc-20160816; b=ev//IHHAiEfOw+f+DARGhD3kUyfcV3k/6nZg665y6IiWYUdpElLVkO7hOWHndg+RvO 7YBz69zoy/dINO24WR4J2DowkJV0HkmagmKZOwShp719GFC1nZED+zpclc0ut9fCT2+R dtTMl+2TSUuDr1wuorWtV0O2tfiohaTCOBDMcu4/X0n15SJN2PG7C4ZLogeASQa7oiV3 90uqkVf1gnYNdBZnIO83KTPAsIpBKRla+9G1ys9Hc2RJda2N8YeYzlMf97XymMa5SQZS 5nIz4ZAK4vWkTG0dvr6XuIvs4eAp5h3/uMnbvzf6EqTqscIHc4i6091lp3b/nkAtZ1b4 COPQ== 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=sH1eBEImgofsuFHCzgFCJq8shVTDDsWWgIXJKvMm2jg=; b=AQgp8A93pWlaKkwTGKSjxCJUIFH554DFuA55Pk1XPjQp0cktyHs3lWHnx6D+wd/4uM LXP6XkC61nwniKM0YzKau+zD/tKlPiIyKwGOPTeA5G2i3PTbQpuKAotshhHE1o/ehAJg uxel1I5PWp/DE4sgYX9M7YKMnms8vaHvnXKnBrm9llzL4f8shyviPTxJ+F4ttyGpD4/i E9/Mrji4jx0zM3ezHNofGBOsByBNsaUdKk0abJD8xE+qP13wHychQK/xdwh5lyUu8mIx 3AySsVyti49hrYGesN9kD7doBZ3F7BPS8OTP6Kv5oloVd9WCqtr8dkwJjmMukDJs7ngj +f0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H5ODIljS; 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 v75-v6sor2181414lfa.72.2018.04.05.13.20.13 for (Google Transport Security); Thu, 05 Apr 2018 13:20:13 -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=H5ODIljS; 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=sH1eBEImgofsuFHCzgFCJq8shVTDDsWWgIXJKvMm2jg=; b=H5ODIljSO/9glkaBCidu7kroBOyLzL2F1gf+9OMWAXzcTNIKZrfXHyyp7yZkJ/BY5k PMS30yQjQA3t0xMGISbr9SRUFs16XGbNw5u7ooDlyeunDsiXqIgIw9GmPQ8V2dXddru0 bs/mcYhAFXV5+JY8bi21n0h5fIbQE/Ys746eA= 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=sH1eBEImgofsuFHCzgFCJq8shVTDDsWWgIXJKvMm2jg=; b=D2qJX7QjXv21r9fn5o71Ep74YDqTlo8kpebXPufD3QekK7KUY0/G6ItOzW7k2v+60y xn5dj7TfH2UJnonfUMO/Y1qqqgpuR8171OwnIXLQ+8p691sN6WEZJx+n7JXX/nMnq8OH 7WQn5jtY4ThRhBbx+jPUu6AqF4ufsPMvt/YFQ3TJCU0tELzXKzJ/lRFB9lIh43/DS0sR 2w3vDr10OZ+I2Zfbes2h9yy2DUFqKxOgZIsQh7+c8nZj8+knibk9KpPC3JVvIGYF88/a Ug+01Z4ljvxK3Ek4C3ffx86f/tBz9xEy5ReS0GkF5aQcifZRCvxOoDfzv/6S/C9BGq8L 8nEA== X-Gm-Message-State: ALQs6tBklk1hZlS2JWp5RoR9rEwRHINbMgLrKu4l4tlD9jSr7WgxPQJy hsjKV5Oa/ZkQ0700cbdp+uIrKEbe X-Google-Smtp-Source: AIpwx4/ru4j1zPiaV9oIHN6auBCCOu2sLquJQxPzeH72+bw4AvVibvVzqPHjwvj05C7ysB4OJnZJPg== X-Received: by 2002:a19:a003:: with SMTP id j3-v6mr14010614lfe.8.1522959613533; Thu, 05 Apr 2018 13:20:13 -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 h66-v6sm1687533lfi.89.2018.04.05.13.20.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 13:20:12 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Brian Norris , Shawn Lin , Doug Anderson , Hans de Goede , Quentin Schulz Subject: [PATCH 3/5] mmc: core: Export a function mmc_sw_reset() to allow soft reset of cards Date: Thu, 5 Apr 2018 22:19:52 +0200 Message-Id: <1522959594-3411-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522959594-3411-1-git-send-email-ulf.hansson@linaro.org> References: <1522959594-3411-1-git-send-email-ulf.hansson@linaro.org> It's rather common that a firmware is loaded into an SDIO func device memory, by the corresponding SDIO func driver during ->probe() time. However, to actually start running the new firmware, sometimes a soft reset (no power cycle) and a re-initialization of the card is needed. This is for example the case with the Espressif ESP8089 WiFi chips, when connected to an SDIO interface. To cope with this scenario, let's add a new exported function, mmc_sw_reset(), which may be called when a soft reset and re-initialization of the card are needed. The mmc_sw_reset() is implemented on top of a new bus ops callback, similar to how the mmc_hw_reset() has been implemented. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 24 ++++++++++++++++++++++++ drivers/mmc/core/core.h | 1 + include/linux/mmc/core.h | 1 + 3 files changed, 26 insertions(+) -- 2.7.4 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 3e17c62..7a79dc1 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2451,6 +2451,30 @@ int mmc_hw_reset(struct mmc_host *host) } EXPORT_SYMBOL(mmc_hw_reset); +int mmc_sw_reset(struct mmc_host *host) +{ + int ret; + + if (!host->card) + return -EINVAL; + + mmc_bus_get(host); + if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { + mmc_bus_put(host); + return -EOPNOTSUPP; + } + + ret = host->bus_ops->sw_reset(host); + mmc_bus_put(host); + + if (ret) + pr_warn("%s: tried to SW reset card, got error %d\n", + mmc_hostname(host), ret); + + return ret; +} +EXPORT_SYMBOL(mmc_sw_reset); + static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) { host->f_init = freq; diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 367ed11..a141ec0 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -33,6 +33,7 @@ struct mmc_bus_ops { int (*alive)(struct mmc_host *); int (*shutdown)(struct mmc_host *); int (*hw_reset)(struct mmc_host *); + int (*sw_reset)(struct mmc_host *); }; void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 9275193..134a648 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -177,6 +177,7 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries); int mmc_hw_reset(struct mmc_host *host); +int mmc_sw_reset(struct mmc_host *host); void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card); #endif /* LINUX_MMC_CORE_H */