diff options
author | Philippe Mathieu-Daudé <f4bug@amsat.org> | 2018-02-08 13:48:09 -0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-02-13 16:15:08 +0100 |
commit | 0034ebe6ee3151e5c54fd13c6f441429bd2cdadf (patch) | |
tree | 2da682a7258b0b1796426a485ea1429e2803fb66 /hw | |
parent | 238cd93567253e0126fbd0c0c3bc75aa43e46a5d (diff) |
sdhci: implement UHS-I voltage switch
[based on a patch from Alistair Francis <alistair.francis@xilinx.com>
from qemu/xilinx tag xilinx-v2015.2]
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Message-Id: <20180208164818.7961-22-f4bug@amsat.org>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/sd/core.c | 13 | ||||
-rw-r--r-- | hw/sd/sd.c | 13 | ||||
-rw-r--r-- | hw/sd/sdhci.c | 12 | ||||
-rw-r--r-- | hw/sd/trace-events | 1 |
4 files changed, 38 insertions, 1 deletions
diff --git a/hw/sd/core.c b/hw/sd/core.c index 498284f109..6d198ea775 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -41,6 +41,19 @@ static SDState *get_card(SDBus *sdbus) return SD_CARD(kid->child); } +void sdbus_set_voltage(SDBus *sdbus, uint16_t millivolts) +{ + SDState *card = get_card(sdbus); + + trace_sdbus_set_voltage(sdbus_name(sdbus), millivolts); + if (card) { + SDCardClass *sc = SD_CARD_GET_CLASS(card); + + assert(sc->set_voltage); + sc->set_voltage(card, millivolts); + } +} + int sdbus_do_command(SDBus *sdbus, SDRequest *req, uint8_t *response) { SDState *card = get_card(sdbus); diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 73e405a04f..a8d7a522c0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -128,6 +128,18 @@ struct SDState { bool enable; }; +static void sd_set_voltage(SDState *sd, uint16_t millivolts) +{ + switch (millivolts) { + case 3001 ... 3600: /* SD_VOLTAGE_3_3V */ + case 2001 ... 3000: /* SD_VOLTAGE_3_0V */ + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "SD card voltage not supported: %.3fV", + millivolts / 1000.f); + } +} + static void sd_set_mode(SDState *sd) { switch (sd->state) { @@ -1926,6 +1938,7 @@ static void sd_class_init(ObjectClass *klass, void *data) dc->reset = sd_reset; dc->bus_type = TYPE_SD_BUS; + sc->set_voltage = sd_set_voltage; sc->do_command = sd_do_command; sc->write_data = sd_write_data; sc->read_data = sd_read_data; diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 2712b8218a..5ca82cf301 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1255,7 +1255,16 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) sdhci_update_irq(s); break; case SDHC_ACMD12ERRSTS: - MASKED_WRITE(s->acmd12errsts, mask, value); + MASKED_WRITE(s->acmd12errsts, mask, value & UINT16_MAX); + if (s->uhs_mode >= UHS_I) { + MASKED_WRITE(s->hostctl2, mask >> 16, value >> 16); + + if (FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, V18_ENA)) { + sdbus_set_voltage(&s->sdbus, SD_VOLTAGE_1_8V); + } else { + sdbus_set_voltage(&s->sdbus, SD_VOLTAGE_3_3V); + } + } break; case SDHC_CAPAB: @@ -1310,6 +1319,7 @@ static void sdhci_init_readonly_registers(SDHCIState *s, Error **errp) #define DEFINE_SDHCI_COMMON_PROPERTIES(_state) \ DEFINE_PROP_UINT8("sd-spec-version", _state, sd_spec_version, 2), \ + DEFINE_PROP_UINT8("uhs", _state, uhs_mode, UHS_NOT_SUPPORTED), \ \ /* Capabilities registers provide information on supported * features of this specific host controller implementation */ \ diff --git a/hw/sd/trace-events b/hw/sd/trace-events index ea2746c8b7..84d2f398b1 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -4,6 +4,7 @@ sdbus_command(const char *bus_name, uint8_t cmd, uint32_t arg, uint8_t crc) "@%s CMD%02d arg 0x%08x crc 0x%02x" sdbus_read(const char *bus_name, uint8_t value) "@%s value 0x%02x" sdbus_write(const char *bus_name, uint8_t value) "@%s value 0x%02x" +sdbus_set_voltage(const char *bus_name, uint16_t millivolts) "@%s %u (mV)" # hw/sd/sdhci.c sdhci_set_inserted(const char *level) "card state changed: %s" |