Skip to content

Commit 134d9e5

Browse files
jamin-aspeedlegoater
authored andcommitted
hw/sd/sdhci: Introduce a new Write Protected pin inverted property
The Write Protect pin of SDHCI model is default active low to match the SDHCI spec. So, write enable the bit 19 should be 1 and write protected the bit 19 should be 0 at the Present State Register (0x24). However, some boards are design Write Protected pin active high. In other words, write enable the bit 19 should be 0 and write protected the bit 19 should be 1 at the Present State Register (0x24). To support it, introduces a new "wp-inverted" property and set it false by default. Signed-off-by: Jamin Lin <[email protected]> Acked-by: Cédric Le Goater <[email protected]> Acked-by: Philippe Mathieu-Daudé <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Cédric Le Goater <[email protected]>
1 parent 8a139ae commit 134d9e5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

hw/sd/sdhci.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ static void sdhci_set_readonly(DeviceState *dev, bool level)
274274
{
275275
SDHCIState *s = (SDHCIState *)dev;
276276

277+
if (s->wp_inverted) {
278+
level = !level;
279+
}
280+
277281
if (level) {
278282
s->prnsts &= ~SDHC_WRITE_PROTECT;
279283
} else {
@@ -1555,6 +1559,8 @@ static const Property sdhci_sysbus_properties[] = {
15551559
false),
15561560
DEFINE_PROP_LINK("dma", SDHCIState,
15571561
dma_mr, TYPE_MEMORY_REGION, MemoryRegion *),
1562+
DEFINE_PROP_BOOL("wp-inverted", SDHCIState,
1563+
wp_inverted, false),
15581564
};
15591565

15601566
static void sdhci_sysbus_init(Object *obj)

include/hw/sd/sdhci.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ struct SDHCIState {
100100
uint8_t sd_spec_version;
101101
uint8_t uhs_mode;
102102
uint8_t vendor; /* For vendor specific functionality */
103+
/*
104+
* Write Protect pin default active low for detecting SD card
105+
* to be protected. Set wp_inverted to invert the signal.
106+
*/
107+
bool wp_inverted;
103108
};
104109
typedef struct SDHCIState SDHCIState;
105110

0 commit comments

Comments
 (0)