Skip to content

Commit 55a6ceb

Browse files
dianderscjb
authored andcommitted
mmc: dw_mmc: Handle wp-gpios from device tree
On some SoCs (like exynos5250) you need to use an external GPIO for write protect. Add support for wp-gpios to the core dw_mmc driver since it could be useful across multiple SoCs. With this change I am able to make use of the write protect for the external SD slot on exynos5250-snow. Signed-off-by: Doug Anderson <dianders@chromium.org> Acked-by: Seungwon Jeon <tgih.jun@samsung.com> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 07b2404 commit 55a6ceb

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎drivers/mmc/host/dw_mmc.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/regulator/consumer.h>
3535
#include <linux/workqueue.h>
3636
#include <linux/of.h>
37+
#include <linux/of_gpio.h>
3738

3839
#include "dw_mmc.h"
3940

@@ -75,6 +76,7 @@ struct idmac_desc {
7576
* @mmc: The mmc_host representing this slot.
7677
* @host: The MMC controller this slot is using.
7778
* @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
79+
* @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
7880
* @ctype: Card type for this slot.
7981
* @mrq: mmc_request currently being processed or waiting to be
8082
* processed, or NULL when the slot is idle.
@@ -90,6 +92,7 @@ struct dw_mci_slot {
9092
struct dw_mci *host;
9193

9294
int quirks;
95+
int wp_gpio;
9396

9497
u32 ctype;
9598

@@ -838,6 +841,8 @@ static int dw_mci_get_ro(struct mmc_host *mmc)
838841
read_only = 0;
839842
else if (brd->get_ro)
840843
read_only = brd->get_ro(slot->id);
844+
else if (gpio_is_valid(slot->wp_gpio))
845+
read_only = gpio_get_value(slot->wp_gpio);
841846
else
842847
read_only =
843848
mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
@@ -1832,6 +1837,29 @@ static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
18321837
" as 1\n");
18331838
return bus_wd;
18341839
}
1840+
1841+
/* find the write protect gpio for a given slot; or -1 if none specified */
1842+
static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1843+
{
1844+
struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1845+
int gpio;
1846+
1847+
if (!np)
1848+
return -EINVAL;
1849+
1850+
gpio = of_get_named_gpio(np, "wp-gpios", 0);
1851+
1852+
/* Having a missing entry is valid; return silently */
1853+
if (!gpio_is_valid(gpio))
1854+
return -EINVAL;
1855+
1856+
if (devm_gpio_request(dev, gpio, "dw-mci-wp")) {
1857+
dev_warn(dev, "gpio [%d] request failed\n", gpio);
1858+
return -EINVAL;
1859+
}
1860+
1861+
return gpio;
1862+
}
18351863
#else /* CONFIG_OF */
18361864
static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
18371865
{
@@ -1845,6 +1873,10 @@ static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
18451873
{
18461874
return NULL;
18471875
}
1876+
static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1877+
{
1878+
return -EINVAL;
1879+
}
18481880
#endif /* CONFIG_OF */
18491881

18501882
static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
@@ -1962,6 +1994,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
19621994
else
19631995
clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
19641996

1997+
slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id);
1998+
19651999
mmc_add_host(mmc);
19662000

19672001
#if defined(CONFIG_DEBUG_FS)

0 commit comments

Comments
 (0)