aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamin Lin <jamin_lin@aspeedtech.com>2024-11-14 17:48:38 +0800
committerCédric Le Goater <clg@redhat.com>2025-01-27 09:38:15 +0100
commit134d9e5c0c4ae2fe64817a185730ec8b7835d573 (patch)
treedee7d5d95eee454fc5e697dcc1d058b48f901764
parent8a139ae719616d85d835528a35f41eb23bfa54c7 (diff)
downloadqemu-134d9e5c0c4ae2fe64817a185730ec8b7835d573.zip
qemu-134d9e5c0c4ae2fe64817a185730ec8b7835d573.tar.gz
qemu-134d9e5c0c4ae2fe64817a185730ec8b7835d573.tar.bz2
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 <jamin_lin@aspeedtech.com> Acked-by: Cédric Le Goater <clg@redhat.com> Acked-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/r/20241114094839.4128404-3-jamin_lin@aspeedtech.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
-rw-r--r--hw/sd/sdhci.c6
-rw-r--r--include/hw/sd/sdhci.h5
2 files changed, 11 insertions, 0 deletions
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 318587f..99dd4a4 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -274,6 +274,10 @@ static void sdhci_set_readonly(DeviceState *dev, bool level)
{
SDHCIState *s = (SDHCIState *)dev;
+ if (s->wp_inverted) {
+ level = !level;
+ }
+
if (level) {
s->prnsts &= ~SDHC_WRITE_PROTECT;
} else {
@@ -1555,6 +1559,8 @@ static const Property sdhci_sysbus_properties[] = {
false),
DEFINE_PROP_LINK("dma", SDHCIState,
dma_mr, TYPE_MEMORY_REGION, MemoryRegion *),
+ DEFINE_PROP_BOOL("wp-inverted", SDHCIState,
+ wp_inverted, false),
};
static void sdhci_sysbus_init(Object *obj)
diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h
index 6cd2822..38c08e2 100644
--- a/include/hw/sd/sdhci.h
+++ b/include/hw/sd/sdhci.h
@@ -100,6 +100,11 @@ struct SDHCIState {
uint8_t sd_spec_version;
uint8_t uhs_mode;
uint8_t vendor; /* For vendor specific functionality */
+ /*
+ * Write Protect pin default active low for detecting SD card
+ * to be protected. Set wp_inverted to invert the signal.
+ */
+ bool wp_inverted;
};
typedef struct SDHCIState SDHCIState;