From: Andrea Merello <andrea.merello@gmail.com>
To: ulf.hansson@linaro.org, mcoquelin.stm32@gmail.com,
alexandre.torgue@st.com
Cc: linux-mmc@vger.kernel.org, Andrea Merello <andrea.merello@gmail.com>
Subject: [PATCH 4/9] mmc: mmci: add support for setting pad type via pinctrl
Date: Tue, 8 Nov 2016 14:43:40 +0100 [thread overview]
Message-ID: <1478612625-23256-5-git-send-email-andrea.merello@gmail.com> (raw)
In-Reply-To: <1478612625-23256-1-git-send-email-andrea.merello@gmail.com>
The STM32 variant hasn't the control bit to switch pads in opendrain mode.
In this case we can achive the same result by askint to the pinmux driver
to configure pins for us.
This patch make the mmci driver able to do this whenever needed.
Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
---
drivers/mmc/host/mmci.c | 52 +++++++++++++++++++++++++++++++++++++++----------
drivers/mmc/host/mmci.h | 7 +++++--
2 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 0c629e3..170c78a 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -107,6 +107,7 @@ struct variant_data {
bool qcom_dml;
bool reversed_irq_handling;
bool has_start_err;
+ bool has_pad_config;
};
static __maybe_unused struct variant_data variant_arm = {
@@ -117,6 +118,7 @@ static __maybe_unused struct variant_data variant_arm = {
.f_max = 100000000,
.reversed_irq_handling = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_arm_extended_fifo = {
@@ -126,6 +128,7 @@ static __maybe_unused struct variant_data variant_arm_extended_fifo = {
.pwrreg_powerup = MCI_PWR_UP,
.f_max = 100000000,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_arm_extended_fifo_hwfc = {
@@ -136,6 +139,7 @@ static __maybe_unused struct variant_data variant_arm_extended_fifo_hwfc = {
.pwrreg_powerup = MCI_PWR_UP,
.f_max = 100000000,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_u300 = {
@@ -152,6 +156,7 @@ static __maybe_unused struct variant_data variant_u300 = {
.pwrreg_clkgate = true,
.pwrreg_nopower = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_nomadik = {
@@ -169,6 +174,7 @@ static __maybe_unused struct variant_data variant_nomadik = {
.pwrreg_clkgate = true,
.pwrreg_nopower = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_ux500 = {
@@ -189,6 +195,7 @@ static __maybe_unused struct variant_data variant_ux500 = {
.busy_detect = true,
.pwrreg_nopower = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_ux500v2 = {
@@ -211,6 +218,7 @@ static __maybe_unused struct variant_data variant_ux500v2 = {
.busy_detect = true,
.pwrreg_nopower = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static __maybe_unused struct variant_data variant_qcom = {
@@ -230,6 +238,7 @@ static __maybe_unused struct variant_data variant_qcom = {
.qcom_fifo = true,
.qcom_dml = true,
.has_start_err = true,
+ .has_pad_config = true,
};
static int mmci_card_busy(struct mmc_host *mmc)
@@ -1317,6 +1326,8 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
u32 pwr = 0;
unsigned long flags;
int ret;
+ struct pinctrl_state *pins;
+ bool is_opendrain;
if (host->plat->ios_handler &&
host->plat->ios_handler(mmc_dev(mmc), ios))
@@ -1375,16 +1386,31 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
~MCI_ST_DATA2DIREN);
}
- if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
- if (host->hw_designer != AMBA_VENDOR_ST)
- pwr |= MCI_ROD;
- else {
- /*
- * The ST Micro variant use the ROD bit for something
- * else and only has OD (Open Drain).
- */
- pwr |= MCI_OD;
+ if (host->variant->has_pad_config) {
+ if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+ if (host->hw_designer != AMBA_VENDOR_ST) {
+ pwr |= MCI_ROD;
+ } else {
+ /*
+ * The ST Micro variant use the ROD bit for
+ * something else and only has OD (Open Drain).
+ */
+ pwr |= MCI_OD;
+ }
}
+ } else {
+ /*
+ * If the variant cannot configure the pads by its own, then we
+ * expect the pinctrl to be able to do that for us
+ */
+ is_opendrain = (ios->bus_mode == MMC_BUSMODE_OPENDRAIN);
+ pins = pinctrl_lookup_state(host->pinctrl, is_opendrain ?
+ MMCI_PINCTRL_STATE_OPENDRAIN :
+ MMCI_PINCTRL_STATE_PUSHPULL);
+ if (IS_ERR(pins))
+ dev_warn(mmc_dev(mmc), "Cannot select pin drive type via pinctrl\n");
+ else
+ pinctrl_select_state(host->pinctrl, pins);
}
/*
@@ -1492,7 +1518,6 @@ static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
if (of_get_property(np, "mmc-cap-sd-highspeed", NULL))
mmc->caps |= MMC_CAP_SD_HIGHSPEED;
-
return 0;
}
@@ -1530,6 +1555,13 @@ static struct mmci_host *mmci_probe(struct device *dev,
host = mmc_priv(mmc);
host->mmc = mmc;
+ if (!variant->has_pad_config) {
+ host->pinctrl = devm_pinctrl_get(dev);
+ if (IS_ERR(host->pinctrl)) {
+ dev_err(dev, "failed to get pinctrl");
+ goto host_free;
+ }
+ }
host->clk = devm_clk_get(dev, NULL);
if (IS_ERR(host->clk)) {
ret = PTR_ERR(host->clk);
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index a1f5e4f..d06c048 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -185,6 +185,10 @@
#define NR_SG 128
+/* pinctrl configs */
+#define MMCI_PINCTRL_STATE_PUSHPULL "default"
+#define MMCI_PINCTRL_STATE_OPENDRAIN "opendrain"
+
struct clk;
struct variant_data;
struct dma_chan;
@@ -219,7 +223,7 @@ struct mmci_host {
bool vqmmc_enabled;
struct mmci_platform_data *plat;
struct variant_data *variant;
-
+ struct pinctrl *pinctrl;
u8 hw_designer;
u8 hw_revision:4;
@@ -244,4 +248,3 @@ struct mmci_host {
#define dma_inprogress(host) (0)
#endif
};
-
--
2.7.4
next prev parent reply other threads:[~2016-11-08 13:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 13:43 [PATCH 0/9] mmc: mmci: add support for STM32 SD controller Andrea Merello
2016-11-08 13:43 ` [PATCH 1/9] mmc: mmci: don't pretend IP variants with only one IRQ to have two mask regs Andrea Merello
2016-11-08 13:43 ` [PATCH 2/9] mmc: mmci: add support for not-amba, but still compatible, variants Andrea Merello
2016-11-08 17:39 ` kbuild test robot
2016-11-08 17:41 ` kbuild test robot
2016-11-08 13:43 ` [PATCH 3/9] mmc: mmci: don't pretend all variants to have MCI_STARBITERR flag Andrea Merello
2016-11-08 13:43 ` Andrea Merello [this message]
2016-11-08 13:43 ` [PATCH 5/9] mmc: mmci: add STM32 variant Andrea Merello
2016-11-08 13:43 ` [PATCH 6/9] DT: stm32f429: add pin map for SDIO controller Andrea Merello
2016-11-10 10:51 ` Alexandre Torgue
2016-11-14 10:19 ` Andrea Merello
2016-11-08 13:43 ` [PATCH 7/9] DT: stm32f429: add node " Andrea Merello
2016-11-08 13:43 ` [PATCH 8/9] DT: stm32f469-disco: " Andrea Merello
2016-11-10 10:54 ` Alexandre Torgue
2016-11-14 10:36 ` Andrea Merello
2016-11-14 10:42 ` Alexandre Torgue
2016-11-08 13:43 ` [PATCH 9/9] Documentation: document mmci STM32 DT binding Andrea Merello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478612625-23256-5-git-send-email-andrea.merello@gmail.com \
--to=andrea.merello@gmail.com \
--cc=alexandre.torgue@st.com \
--cc=linux-mmc@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).