Lines Matching full:card
45 #define MMC_REL_ADR_ARG (card->relative_addr << 16U)
55 inline int mmc_write_blocks(struct sd_card *card, const uint8_t *wbuf, uint32_t start_block, in mmc_write_blocks() argument
58 return card_write_blocks(card, wbuf, start_block, num_blocks); in mmc_write_blocks()
61 inline int mmc_read_blocks(struct sd_card *card, uint8_t *rbuf, uint32_t start_block, in mmc_read_blocks() argument
64 return card_read_blocks(card, rbuf, start_block, num_blocks); in mmc_read_blocks()
67 inline int mmc_ioctl(struct sd_card *card, uint8_t cmd, void *buf) in mmc_ioctl() argument
69 return card_ioctl(card, cmd, buf); in mmc_ioctl()
73 static int mmc_send_op_cond(struct sd_card *card, int ocr);
76 static int mmc_set_rca(struct sd_card *card);
79 static int mmc_read_csd(struct sd_card *card, struct sd_csd *card_csd);
83 static int mmc_read_ext_csd(struct sd_card *card, struct mmc_ext_csd *card_ext_csd);
87 static inline int mmc_set_max_freq(struct sd_card *card, struct sd_csd *card_csd);
90 static int mmc_set_bus_width(struct sd_card *card);
92 /* Sets card to the fastest timing mode (using CMD6) and SDHC to max frequency */
93 static int mmc_set_timing(struct sd_card *card, struct mmc_ext_csd *card_ext_csd);
96 static int mmc_set_cache(struct sd_card *card, struct mmc_ext_csd *card_ext_csd);
99 * Initialize MMC card for use with subsystem
101 int mmc_card_init(struct sd_card *card) in mmc_card_init() argument
110 if (card->host_props.is_spi) { in mmc_card_init()
114 /* Probe to see if card is an MMC card */ in mmc_card_init()
115 ret = mmc_send_op_cond(card, ocr_arg); in mmc_card_init()
119 /* Card is MMC card if no error in mmc_card_init()
122 card->type = CARD_MMC; in mmc_card_init()
125 if (card->host_props.host_caps.vol_180_support) { in mmc_card_init()
128 if (card->host_props.host_caps.vol_330_support || in mmc_card_init()
129 card->host_props.host_caps.vol_300_support) { in mmc_card_init()
138 ret = mmc_send_op_cond(card, ocr_arg); in mmc_card_init()
140 LOG_ERR("Failed to query card OCR"); in mmc_card_init()
145 ret = card_read_cid(card); in mmc_card_init()
151 ret = mmc_set_rca(card); in mmc_card_init()
153 LOG_ERR("Failed on sending RCA to card"); in mmc_card_init()
158 ret = mmc_read_csd(card, &card_csd); in mmc_card_init()
167 ret = mmc_set_max_freq(card, &card_csd); in mmc_card_init()
173 ret = sdmmc_select_card(card); in mmc_card_init()
179 ret = mmc_set_bus_width(card); in mmc_card_init()
185 ret = mmc_read_ext_csd(card, &card_ext_csd); in mmc_card_init()
191 ret = mmc_set_timing(card, &card_ext_csd); in mmc_card_init()
197 ret = mmc_set_cache(card, &card_ext_csd); in mmc_card_init()
205 static int mmc_send_op_cond(struct sd_card *card, int ocr) in mmc_send_op_cond() argument
219 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_send_op_cond()
232 LOG_ERR("Card never left busy state"); in mmc_send_op_cond()
238 card->flags |= SD_1800MV_FLAG; in mmc_send_op_cond()
241 card->flags |= SD_3000MV_FLAG; in mmc_send_op_cond()
245 if (card->host_props.host_caps.vol_180_support && (card->flags & SD_1800MV_FLAG)) { in mmc_send_op_cond()
246 card->bus_io.signal_voltage = SD_VOL_1_8_V; in mmc_send_op_cond()
247 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_send_op_cond()
254 card->card_voltage = SD_VOL_1_8_V; in mmc_send_op_cond()
255 LOG_INF("Card switched to 1.8V signaling"); in mmc_send_op_cond()
260 card->flags |= SD_HIGH_CAPACITY_FLAG; in mmc_send_op_cond()
266 static int mmc_set_rca(struct sd_card *card) in mmc_set_rca() argument
276 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_rca()
285 card->relative_addr = CONFIG_MMC_RCA; in mmc_set_rca()
290 static int mmc_read_csd(struct sd_card *card, struct sd_csd *card_csd) in mmc_read_csd() argument
300 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_read_csd()
349 static inline int mmc_set_max_freq(struct sd_card *card, struct sd_csd *card_csd) in mmc_set_max_freq() argument
357 card->bus_io.clock = 26000000U; in mmc_set_max_freq()
358 card->bus_io.timing = SDHC_TIMING_LEGACY; in mmc_set_max_freq()
362 card->bus_io.clock = 20000000U; in mmc_set_max_freq()
363 card->bus_io.timing = SDHC_TIMING_LEGACY; in mmc_set_max_freq()
369 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_max_freq()
378 static int mmc_set_bus_width(struct sd_card *card) in mmc_set_bus_width() argument
383 if (card->host_props.host_caps.bus_8_bit_support && card->bus_width == 8) { in mmc_set_bus_width()
385 card->bus_io.bus_width = SDHC_BUS_WIDTH8BIT; in mmc_set_bus_width()
386 } else if (card->host_props.host_caps.bus_4_bit_support && card->bus_width >= 4) { in mmc_set_bus_width()
388 card->bus_io.bus_width = SDHC_BUS_WIDTH4BIT; in mmc_set_bus_width()
394 /* Set Card Bus Width */ in mmc_set_bus_width()
398 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_bus_width()
399 sdmmc_wait_ready(card); in mmc_set_bus_width()
401 LOG_ERR("Setting card data bus width failed: %d", ret); in mmc_set_bus_width()
406 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_bus_width()
415 static int mmc_set_hs_timing(struct sd_card *card) in mmc_set_hs_timing() argument
420 /* Change Card Timing Mode */ in mmc_set_hs_timing()
425 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_hs_timing()
430 sdmmc_wait_ready(card); in mmc_set_hs_timing()
433 card->bus_io.clock = MMC_CLOCK_52MHZ; in mmc_set_hs_timing()
434 card->bus_io.timing = SDHC_TIMING_HS; in mmc_set_hs_timing()
436 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_hs_timing()
444 static int mmc_set_power_class_HS200(struct sd_card *card, struct mmc_ext_csd *ext) in mmc_set_power_class_HS200() argument
453 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_power_class_HS200()
454 sdmmc_wait_ready(card); in mmc_set_power_class_HS200()
458 static int mmc_set_timing(struct sd_card *card, struct mmc_ext_csd *ext) in mmc_set_timing() argument
465 (card->host_props.host_caps.hs200_support) && in mmc_set_timing()
466 (card->bus_io.signal_voltage == SD_VOL_1_8_V) && in mmc_set_timing()
467 (card->bus_io.bus_width >= SDHC_BUS_WIDTH4BIT)) { in mmc_set_timing()
468 ret = mmc_set_hs_timing(card); in mmc_set_timing()
473 card->bus_io.clock = MMC_CLOCK_HS200; in mmc_set_timing()
474 card->bus_io.timing = SDHC_TIMING_HS200; in mmc_set_timing()
476 return mmc_set_hs_timing(card); in mmc_set_timing()
478 /* Nothing to do, card is already configured for this */ in mmc_set_timing()
484 /* Set card timing mode */ in mmc_set_timing()
488 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
493 ret = sdmmc_wait_ready(card); in mmc_set_timing()
497 card->card_speed = ((cmd.arg & 0xFF << 8) >> 8); in mmc_set_timing()
500 if (card->card_speed == MMC_HS200_TIMING) { in mmc_set_timing()
501 ret = mmc_set_power_class_HS200(card, ext); in mmc_set_timing()
508 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_timing()
514 if (card->card_speed == MMC_HS200_TIMING) { in mmc_set_timing()
515 ret = sdhc_execute_tuning(card->sdhc); in mmc_set_timing()
524 (card->host_props.host_caps.hs400_support) && in mmc_set_timing()
525 (card->bus_io.bus_width == SDHC_BUS_WIDTH8BIT)) { in mmc_set_timing()
527 ret = mmc_set_hs_timing(card); in mmc_set_timing()
537 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
538 sdmmc_wait_ready(card); in mmc_set_timing()
543 /* Set card timing mode to HS400 */ in mmc_set_timing()
548 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
550 LOG_DBG("Error setting card to HS400 bus timing: %d", ret); in mmc_set_timing()
553 ret = sdmmc_wait_ready(card); in mmc_set_timing()
558 card->bus_io.clock = MMC_CLOCK_HS400; in mmc_set_timing()
559 card->bus_io.timing = SDHC_TIMING_HS400; in mmc_set_timing()
560 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_timing()
564 card->card_speed = ((cmd.arg & 0xFF << 8) >> 8); in mmc_set_timing()
569 static int mmc_read_ext_csd(struct sd_card *card, struct mmc_ext_csd *card_ext_csd) in mmc_read_ext_csd() argument
582 data.data = card->card_buffer; in mmc_read_ext_csd()
585 ret = sdhc_request(card->sdhc, &cmd, &data); in mmc_read_ext_csd()
591 mmc_decode_ext_csd(card_ext_csd, card->card_buffer); in mmc_read_ext_csd()
592 card->block_count = card_ext_csd->sec_count; in mmc_read_ext_csd()
593 card->block_size = SDMMC_DEFAULT_BLOCK_SIZE; in mmc_read_ext_csd()
595 LOG_INF("Card block count is %d, block size is %d", card->block_count, card->block_size); in mmc_read_ext_csd()
622 static int mmc_set_cache(struct sd_card *card, struct mmc_ext_csd *card_ext_csd) in mmc_set_cache() argument
636 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_cache()
638 LOG_DBG("Error turning on card cache: %d", ret); in mmc_set_cache()
641 ret = sdmmc_wait_ready(card); in mmc_set_cache()