Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/zephyr/drivers/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ extern "C" {
* requested, but this operation is inherently unsafe.
*/
#define DISK_IOCTL_CTRL_DEINIT 7
/* Get Card identification (CID) register value.
* Passed buffer must be four 32-bit integer long to hold CID register value
* read from the card.
*/
#define DISK_IOCTL_GET_CARD_CID 8

/**
* @brief Possible return bitmasks for disk_status()
Expand Down
5 changes: 3 additions & 2 deletions subsys/sd/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ int mmc_card_init(struct sd_card *card)
{
int ret = 0;
uint32_t ocr_arg = 0U;
/* Keep CSDs on stack for reduced RAM usage */
/* Keep CSDs/CID on stack for reduced RAM usage */
struct sd_csd card_csd = {0};
struct mmc_ext_csd card_ext_csd = {0};
uint32_t cid[4] = {0};

/* SPI is not supported for MMC */
if (card->host_props.is_spi) {
Expand Down Expand Up @@ -132,7 +133,7 @@ int mmc_card_init(struct sd_card *card)
}

/* CMD2 */
ret = card_read_cid(card);
ret = card_read_cid(card, cid);
if (ret) {
return ret;
}
Expand Down
6 changes: 4 additions & 2 deletions subsys/sd/sd_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,8 @@ int sdmmc_read_csd(struct sd_card *card)
}

/* Reads card identification register, and decodes it */
int card_read_cid(struct sd_card *card)
int card_read_cid(struct sd_card *card, uint32_t *cid)
{
uint32_t cid[4];
int ret;
#if defined(CONFIG_SDMMC_STACK) || defined(CONFIG_SDIO_STACK)
/* Keep CID on stack for reduced RAM usage */
Expand Down Expand Up @@ -805,6 +804,9 @@ int card_ioctl(struct sd_card *card, uint8_t cmd, void *buf)
card->bus_io.power_mode = SDHC_POWER_OFF;
ret = sdhc_set_io(card->sdhc, &card->bus_io);
break;
case DISK_IOCTL_GET_CARD_CID:
ret = card_read_cid(card, buf);
break;
default:
ret = -ENOTSUP;
}
Expand Down
2 changes: 1 addition & 1 deletion subsys/sd/sd_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int sdmmc_switch_voltage(struct sd_card *card);
/*
* Reads card identification register, and decodes it
*/
int card_read_cid(struct sd_card *card);
int card_read_cid(struct sd_card *card, uint32_t *cid);

/*
* Read card specific data register
Expand Down
3 changes: 2 additions & 1 deletion subsys/sd/sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ int sdio_card_init(struct sd_card *card)
{
int ret;
uint32_t ocr_arg = 0U;
uint32_t cid[4] = {0};

/* Probe card with SDIO OCR CM5 */
ret = sdio_send_ocr(card, ocr_arg);
Expand Down Expand Up @@ -609,7 +610,7 @@ int sdio_card_init(struct sd_card *card)
if ((card->flags & SD_MEM_PRESENT_FLAG) &&
((card->flags & SD_SDHC_FLAG) == 0)) {
/* We must send CMD2 to get card cid */
ret = card_read_cid(card);
ret = card_read_cid(card, cid);
if (ret) {
return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion subsys/sd/sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ int sdmmc_card_init(struct sd_card *card)
{
int ret;
uint32_t ocr_arg = 0U;
uint32_t cid[4] = {0};

/* First send a probing OCR */
if (IS_ENABLED(CONFIG_SDHC_SUPPORTS_SPI_MODE) && card->host_props.is_spi) {
Expand Down Expand Up @@ -695,7 +696,7 @@ int sdmmc_card_init(struct sd_card *card)
}
}
/* Read the card's CID (card identification register) */
ret = card_read_cid(card);
ret = card_read_cid(card, cid);
if (ret) {
return ret;
}
Expand Down