From: Tuomas Tynkkynen <tuomas@tuxera.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] mmc: sunxi: Support cd-inverted DT property
Date: Mon, 18 Dec 2017 22:09:41 +0200 [thread overview]
Message-ID: <20171218200942.23586-1-tuomas@tuxera.com> (raw)
Commit 8620f384098b ("dm: sunxi: Linksprite_pcDuino3: Correct polarity
of MMC card detect") claims that the Pcduino3 device tree has an
incorrect polarity for the card detect pin, but the actual problem is
that unlike the Linux MMC driver, the U-Boot driver isn't respecting the
cd-invert property (see Documentation/devicetree/bindings/mmc/mmc.txt)
which tells that the card detect signal level should be inverted.
Fix this properly by adding support for the cd-inverted property while
reverting the original commit at the same time. While at it, I noticed
the driver always enables pullups for the card detect line, which is not
right if the card detect GPIO is active-high, so fix that as well.
Signed-off-by: Tuomas Tynkkynen <tuomas@tuxera.com>
---
arch/arm/dts/sun7i-a20-pcduino3.dts | 2 +-
drivers/mmc/sunxi_mmc.c | 12 ++++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/arm/dts/sun7i-a20-pcduino3.dts b/arch/arm/dts/sun7i-a20-pcduino3.dts
index 37b1e0ee9b..1a8b39be1d 100644
--- a/arch/arm/dts/sun7i-a20-pcduino3.dts
+++ b/arch/arm/dts/sun7i-a20-pcduino3.dts
@@ -164,7 +164,7 @@
pinctrl-0 = <&mmc0_pins_a>, <&mmc0_cd_pin_reference_design>;
vmmc-supply = <®_vcc3v3>;
bus-width = <4>;
- cd-gpios = <&pio 7 1 GPIO_ACTIVE_LOW>; /* PH1 */
+ cd-gpios = <&pio 7 1 GPIO_ACTIVE_HIGH>; /* PH1 */
cd-inverted;
status = "okay";
};
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index 4edb4be46c..7cc7303570 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -30,6 +30,7 @@ struct sunxi_mmc_priv {
uint32_t *mclkreg;
unsigned fatal_err;
struct gpio_desc cd_gpio; /* Change Detect GPIO */
+ int cd_inverted;
struct sunxi_mmc *reg;
struct mmc_config cfg;
};
@@ -545,7 +546,7 @@ static int sunxi_mmc_getcd(struct udevice *dev)
struct sunxi_mmc_priv *priv = dev_get_priv(dev);
if (dm_gpio_is_valid(&priv->cd_gpio))
- return dm_gpio_get_value(&priv->cd_gpio);
+ return dm_gpio_get_value(&priv->cd_gpio) ^ priv->cd_inverted;
return 1;
}
@@ -606,8 +607,15 @@ static int sunxi_mmc_probe(struct udevice *dev)
if (!gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
GPIOD_IS_IN)) {
int cd_pin = gpio_get_number(&priv->cd_gpio);
+ int cd_state = priv->cd_gpio.flags & GPIOD_ACTIVE_LOW ? 0 : 1;
- sunxi_gpio_set_pull(cd_pin, SUNXI_GPIO_PULL_UP);
+ priv->cd_inverted = dev_read_bool(dev, "cd-inverted");
+ cd_state ^= priv->cd_inverted;
+
+ if (cd_state)
+ sunxi_gpio_set_pull(cd_pin, SUNXI_GPIO_PULL_DOWN);
+ else
+ sunxi_gpio_set_pull(cd_pin, SUNXI_GPIO_PULL_UP);
}
upriv->mmc = &plat->mmc;
--
2.15.0
next reply other threads:[~2017-12-18 20:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 20:09 Tuomas Tynkkynen [this message]
2017-12-18 20:09 ` [U-Boot] [PATCH 2/2] ARM: sunxi: Enable DM MMC+SATA for the PcDuino3 Nano board Tuomas Tynkkynen
2017-12-20 12:26 ` Maxime Ripard
2017-12-20 13:37 ` Tuomas Tynkkynen
2017-12-21 12:59 ` Maxime Ripard
2017-12-20 12:26 ` [U-Boot] [PATCH 1/2] mmc: sunxi: Support cd-inverted DT property Maxime Ripard
2017-12-20 13:34 ` Tuomas Tynkkynen
2017-12-21 13:09 ` Maxime Ripard
2017-12-21 14:09 ` Tuomas Tynkkynen
2017-12-21 15:49 ` Maxime Ripard
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=20171218200942.23586-1-tuomas@tuxera.com \
--to=tuomas@tuxera.com \
--cc=u-boot@lists.denx.de \
/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