diff --git a/drivers/disk/mmc_subsys.c b/drivers/disk/mmc_subsys.c index 8af8a01991e..455d56818d3 100644 --- a/drivers/disk/mmc_subsys.c +++ b/drivers/disk/mmc_subsys.c @@ -21,6 +21,7 @@ enum sd_status { struct mmc_config { const struct device *host_controller; + uint8_t bus_width; }; struct mmc_data { @@ -104,8 +105,10 @@ static struct disk_info mmc_disk = { static int disk_mmc_init(const struct device *dev) { struct mmc_data *data = dev->data; + const struct mmc_config *config = dev->config; data->status = SD_UNINIT; + data->card.bus_width = config->bus_width; mmc_disk.dev = dev; mmc_disk.name = data->name; @@ -115,6 +118,7 @@ static int disk_mmc_init(const struct device *dev) #define DISK_ACCESS_MMC_INIT(n) \ static const struct mmc_config mmc_config_##n = { \ .host_controller = DEVICE_DT_GET(DT_INST_PARENT(n)), \ + .bus_width = DT_INST_PROP(n, bus_width), \ }; \ \ static struct mmc_data mmc_data_##n = { \ diff --git a/dts/bindings/sd/zephyr,mmc-disk.yaml b/dts/bindings/sd/zephyr,mmc-disk.yaml index a5167721686..f702b341e1a 100644 --- a/dts/bindings/sd/zephyr,mmc-disk.yaml +++ b/dts/bindings/sd/zephyr,mmc-disk.yaml @@ -7,3 +7,15 @@ description: | compatible: "zephyr,mmc-disk" include: [sd-device.yaml] + +properties: + bus-width: + type: int + default: 8 + description: | + Indicates the way the MMC device is connected to the bus. + Defaults to the maximum possible number of bus lines. + enum: + - 1 + - 4 + - 8 diff --git a/include/zephyr/sd/sd.h b/include/zephyr/sd/sd.h index e73777873c5..a93aec5f012 100644 --- a/include/zephyr/sd/sd.h +++ b/include/zephyr/sd/sd.h @@ -64,6 +64,7 @@ struct sd_card { enum card_status status; /*!< Card status */ enum card_type type; /*!< Card type */ uint16_t flags; /*!< Card flags */ + uint8_t bus_width; /*!< Desired bus width */ uint8_t card_buffer[CONFIG_SD_BUFFER_SIZE] __aligned(CONFIG_SDHC_BUFFER_ALIGNMENT); /* Card internal buffer */ }; diff --git a/subsys/sd/mmc.c b/subsys/sd/mmc.c index eada1ec261f..8ea0b5746d7 100644 --- a/subsys/sd/mmc.c +++ b/subsys/sd/mmc.c @@ -380,10 +380,10 @@ static int mmc_set_bus_width(struct sd_card *card) int ret; struct sdhc_command cmd = {0}; - if (card->host_props.host_caps.bus_8_bit_support) { + if (card->host_props.host_caps.bus_8_bit_support && card->bus_width == 8) { cmd.arg = MMC_SWITCH_8_BIT_BUS_ARG; card->bus_io.bus_width = SDHC_BUS_WIDTH8BIT; - } else if (card->host_props.host_caps.bus_4_bit_support) { + } else if (card->host_props.host_caps.bus_4_bit_support && card->bus_width >= 4) { cmd.arg = MMC_SWITCH_4_BIT_BUS_ARG; card->bus_io.bus_width = SDHC_BUS_WIDTH4BIT; } else {