Skip to content

Commit a70aaa6

Browse files
dianderscjb
authored andcommitted
mmc: dw_mmc: Add "disable-wp" device tree property
The "disable-wp" property is used to specify that a given SD card slot doesn't have a concept of write protect. This eliminates the need for special case code for SD slots that should never be write protected (like a micro SD slot or a dev board). The dw_mmc driver is special in needing to specify "disable-wp" because the lack of a "wp-gpios" property means to use the special purpose write protect line. On some other mmc devices the lack of "wp-gpios" means that write protect should be disabled. Signed-off-by: Doug Anderson <dianders@chromium.org> Acked-by: Seungwon Jeon <tgih.jun@samsung.com> Acked-by: Will Newton <will.newton@imgtec.com> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent c148e9f commit a70aaa6

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ Required Properties:
2626
* bus-width: as documented in mmc core bindings.
2727

2828
* wp-gpios: specifies the write protect gpio line. The format of the
29-
gpio specifier depends on the gpio controller. If the write-protect
30-
line is not available, this property is optional.
29+
gpio specifier depends on the gpio controller. If a GPIO is not used
30+
for write-protect, this property is optional.
31+
32+
* disable-wp: If the wp-gpios property isn't present then (by default)
33+
we'd assume that the write protect is hooked up directly to the
34+
controller's special purpose write protect line (accessible via
35+
the WRTPRT register). However, it's possible that we simply don't
36+
want write protect. In that case specify 'disable-wp'.
37+
NOTE: This property is not required for slots known to always
38+
connect to eMMC or SDIO cards.
3139

3240
Optional properties:
3341

‎drivers/mmc/host/dw_mmc.c‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct idmac_desc {
7474
* struct dw_mci_slot - MMC slot state
7575
* @mmc: The mmc_host representing this slot.
7676
* @host: The MMC controller this slot is using.
77+
* @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
7778
* @ctype: Card type for this slot.
7879
* @mrq: mmc_request currently being processed or waiting to be
7980
* processed, or NULL when the slot is idle.
@@ -88,6 +89,8 @@ struct dw_mci_slot {
8889
struct mmc_host *mmc;
8990
struct dw_mci *host;
9091

92+
int quirks;
93+
9194
u32 ctype;
9295

9396
struct mmc_request *mrq;
@@ -825,7 +828,13 @@ static int dw_mci_get_ro(struct mmc_host *mmc)
825828
struct dw_mci_board *brd = slot->host->pdata;
826829

827830
/* Use platform get_ro function, else try on board write protect */
828-
if (brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT)
831+
832+
/*
833+
* NOTE: DW_MCI_QUIRK_NO_WRITE_PROTECT will be removed in a future
834+
* patch in the series once reference to it is removed.
835+
*/
836+
if ((brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) ||
837+
(slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT))
829838
read_only = 0;
830839
else if (brd->get_ro)
831840
read_only = brd->get_ro(slot->id);
@@ -1785,6 +1794,30 @@ static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
17851794
return NULL;
17861795
}
17871796

1797+
static struct dw_mci_of_slot_quirks {
1798+
char *quirk;
1799+
int id;
1800+
} of_slot_quirks[] = {
1801+
{
1802+
.quirk = "disable-wp",
1803+
.id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT,
1804+
},
1805+
};
1806+
1807+
static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1808+
{
1809+
struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1810+
int quirks = 0;
1811+
int idx;
1812+
1813+
/* get quirks */
1814+
for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++)
1815+
if (of_get_property(np, of_slot_quirks[idx].quirk, NULL))
1816+
quirks |= of_slot_quirks[idx].id;
1817+
1818+
return quirks;
1819+
}
1820+
17881821
/* find out bus-width for a given slot */
17891822
static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
17901823
{
@@ -1800,6 +1833,10 @@ static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
18001833
return bus_wd;
18011834
}
18021835
#else /* CONFIG_OF */
1836+
static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1837+
{
1838+
return 0;
1839+
}
18031840
static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
18041841
{
18051842
return 1;
@@ -1828,6 +1865,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
18281865
slot->host = host;
18291866
host->slot[id] = slot;
18301867

1868+
slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
1869+
18311870
mmc->ops = &dw_mci_ops;
18321871
mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
18331872
mmc->f_max = host->bus_hz;

‎include/linux/mmc/dw_mmc.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,18 @@ struct dw_mci_dma_ops {
209209
#define DW_MCI_QUIRK_HIGHSPEED BIT(2)
210210
/* Unreliable card detection */
211211
#define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
212+
212213
/* Write Protect detection not available */
214+
/*
215+
* NOTE: DW_MCI_QUIRK_NO_WRITE_PROTECT will be removed in a future
216+
* patch in the series once reference to it is removed.
217+
*/
213218
#define DW_MCI_QUIRK_NO_WRITE_PROTECT BIT(4)
214219

220+
/* Slot level quirks */
221+
/* This slot has no write protect */
222+
#define DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT BIT(0)
223+
215224
struct dma_pdata;
216225

217226
struct block_settings {

0 commit comments

Comments
 (0)