Lines Matching refs:card
22 static inline int sd_idle(struct sd_card *card) in sd_idle() argument
32 return sdhc_request(card->sdhc, &cmd, NULL); in sd_idle()
41 static int sd_send_interface_condition(struct sd_card *card) in sd_send_interface_condition() argument
48 ret = sd_idle(card); in sd_send_interface_condition()
60 ret = sdhc_request(card->sdhc, &cmd, NULL); in sd_send_interface_condition()
66 if (card->host_props.is_spi) { in sd_send_interface_condition()
81 card->flags |= SD_SDHC_FLAG; in sd_send_interface_condition()
86 static int sd_enable_crc(struct sd_card *card) in sd_enable_crc() argument
91 __ASSERT_NO_MSG(card->host_props.is_spi); in sd_enable_crc()
97 return sdhc_request(card->sdhc, &cmd, NULL); in sd_enable_crc()
101 static int sd_common_init(struct sd_card *card) in sd_common_init() argument
106 ret = sd_retry(sd_send_interface_condition, card, CONFIG_SD_RETRY_COUNT); in sd_common_init()
109 return sd_idle(card); in sd_common_init()
114 if (card->host_props.is_spi && in sd_common_init()
117 ret = sd_enable_crc(card); in sd_common_init()
122 static int sd_init_io(struct sd_card *card) in sd_init_io() argument
124 struct sdhc_io *bus_io = &card->bus_io; in sd_init_io()
125 struct sdhc_host_props *host_props = &card->host_props; in sd_init_io()
154 ret = sdhc_set_io(card->sdhc, bus_io); in sd_init_io()
159 sd_delay(card->host_props.power_delay); in sd_init_io()
161 ret = sdhc_set_io(card->sdhc, bus_io); in sd_init_io()
167 card->card_voltage = voltage; in sd_init_io()
169 card->flags = 0U; in sd_init_io()
171 sd_delay(card->host_props.power_delay); in sd_init_io()
174 ret = sdhc_set_io(card->sdhc, bus_io); in sd_init_io()
185 static int sd_command_init(struct sd_card *card) in sd_command_init() argument
202 ret = sd_common_init(card); in sd_command_init()
209 if (!sdio_card_init(card)) { in sd_command_init()
215 if (!sdmmc_card_init(card)) { in sd_command_init()
220 ret = sd_idle(card); in sd_command_init()
225 if (!mmc_card_init(card)) { in sd_command_init()
234 int sd_init(const struct device *sdhc_dev, struct sd_card *card) in sd_init() argument
241 card->sdhc = sdhc_dev; in sd_init()
242 ret = sdhc_get_host_props(card->sdhc, &card->host_props); in sd_init()
249 ret = k_mutex_init(&card->lock); in sd_init()
254 ret = k_mutex_lock(&card->lock, K_MSEC(CONFIG_SD_INIT_TIMEOUT)); in sd_init()
261 ret = sd_init_io(card); in sd_init()
263 k_mutex_unlock(&card->lock); in sd_init()
278 ret = sd_command_init(card); in sd_init()
281 card->status = CARD_ERROR; in sd_init()
283 ret = sd_init_io(card); in sd_init()
286 k_mutex_unlock(&card->lock); in sd_init()
289 ret = sd_command_init(card); in sd_init()
292 k_mutex_unlock(&card->lock); in sd_init()
297 k_mutex_unlock(&card->lock); in sd_init()
298 card->status = CARD_ERROR; in sd_init()
302 card->status = CARD_INITIALIZED; in sd_init()
304 ret = k_mutex_unlock(&card->lock); in sd_init()