Lines Matching refs: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);
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);
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()
115 if (card->host_props.host_caps.vol_180_support) { in mmc_card_init()
118 if (card->host_props.host_caps.vol_330_support || in mmc_card_init()
119 card->host_props.host_caps.vol_300_support) { in mmc_card_init()
128 ret = mmc_send_op_cond(card, ocr_arg); in mmc_card_init()
135 ret = card_read_cid(card); in mmc_card_init()
141 ret = mmc_set_rca(card); in mmc_card_init()
148 ret = mmc_read_csd(card, &card_csd); in mmc_card_init()
157 ret = mmc_set_max_freq(card, &card_csd); in mmc_card_init()
163 ret = sdmmc_select_card(card); in mmc_card_init()
169 ret = mmc_set_bus_width(card); in mmc_card_init()
175 ret = mmc_read_ext_csd(card, &card_ext_csd); in mmc_card_init()
181 ret = mmc_set_timing(card, &card_ext_csd); in mmc_card_init()
187 ret = mmc_set_cache(card, &card_ext_csd); in mmc_card_init()
195 static int mmc_send_op_cond(struct sd_card *card, int ocr) in mmc_send_op_cond() argument
209 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_send_op_cond()
218 card->type = CARD_MMC; in mmc_send_op_cond()
230 card->flags |= SD_1800MV_FLAG; in mmc_send_op_cond()
233 card->flags |= SD_3000MV_FLAG; in mmc_send_op_cond()
237 if (card->host_props.host_caps.vol_180_support && (card->flags & SD_1800MV_FLAG)) { in mmc_send_op_cond()
238 card->bus_io.signal_voltage = SD_VOL_1_8_V; in mmc_send_op_cond()
239 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_send_op_cond()
246 card->card_voltage = SD_VOL_1_8_V; in mmc_send_op_cond()
252 card->flags |= SD_HIGH_CAPACITY_FLAG; in mmc_send_op_cond()
258 static int mmc_set_rca(struct sd_card *card) in mmc_set_rca() argument
268 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_rca()
277 card->relative_addr = CONFIG_MMC_RCA; in mmc_set_rca()
282 static int mmc_read_csd(struct sd_card *card, struct sd_csd *card_csd) in mmc_read_csd() argument
292 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_read_csd()
341 static inline int mmc_set_max_freq(struct sd_card *card, struct sd_csd *card_csd) in mmc_set_max_freq() argument
349 card->bus_io.clock = 26000000U; in mmc_set_max_freq()
350 card->bus_io.timing = SDHC_TIMING_LEGACY; in mmc_set_max_freq()
354 card->bus_io.clock = 20000000U; in mmc_set_max_freq()
355 card->bus_io.timing = SDHC_TIMING_LEGACY; in mmc_set_max_freq()
361 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_max_freq()
370 static int mmc_set_bus_width(struct sd_card *card) in mmc_set_bus_width() argument
375 if (card->host_props.host_caps.bus_8_bit_support && card->bus_width == 8) { in mmc_set_bus_width()
377 card->bus_io.bus_width = SDHC_BUS_WIDTH8BIT; in mmc_set_bus_width()
378 } else if (card->host_props.host_caps.bus_4_bit_support && card->bus_width >= 4) { in mmc_set_bus_width()
380 card->bus_io.bus_width = SDHC_BUS_WIDTH4BIT; in mmc_set_bus_width()
390 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_bus_width()
391 sdmmc_wait_ready(card); in mmc_set_bus_width()
398 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_bus_width()
407 static int mmc_set_hs_timing(struct sd_card *card) in mmc_set_hs_timing() argument
417 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_hs_timing()
422 sdmmc_wait_ready(card); in mmc_set_hs_timing()
425 card->bus_io.clock = MMC_CLOCK_52MHZ; in mmc_set_hs_timing()
426 card->bus_io.timing = SDHC_TIMING_HS; in mmc_set_hs_timing()
428 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_hs_timing()
436 static int mmc_set_power_class_HS200(struct sd_card *card, struct mmc_ext_csd *ext) in mmc_set_power_class_HS200() argument
445 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_power_class_HS200()
446 sdmmc_wait_ready(card); in mmc_set_power_class_HS200()
450 static int mmc_set_timing(struct sd_card *card, struct mmc_ext_csd *ext) in mmc_set_timing() argument
457 (card->host_props.host_caps.hs200_support) && in mmc_set_timing()
458 (card->bus_io.signal_voltage == SD_VOL_1_8_V) && in mmc_set_timing()
459 (card->bus_io.bus_width >= SDHC_BUS_WIDTH4BIT)) { in mmc_set_timing()
460 ret = mmc_set_hs_timing(card); in mmc_set_timing()
465 card->bus_io.clock = MMC_CLOCK_HS200; in mmc_set_timing()
466 card->bus_io.timing = SDHC_TIMING_HS200; in mmc_set_timing()
468 return mmc_set_hs_timing(card); in mmc_set_timing()
480 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
485 ret = sdmmc_wait_ready(card); in mmc_set_timing()
489 card->card_speed = ((cmd.arg & 0xFF << 8) >> 8); in mmc_set_timing()
492 if (card->card_speed == MMC_HS200_TIMING) { in mmc_set_timing()
493 ret = mmc_set_power_class_HS200(card, ext); in mmc_set_timing()
500 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_timing()
506 if (card->card_speed == MMC_HS200_TIMING) { in mmc_set_timing()
507 ret = sdhc_execute_tuning(card->sdhc); in mmc_set_timing()
516 (card->host_props.host_caps.hs400_support) && in mmc_set_timing()
517 (card->bus_io.bus_width == SDHC_BUS_WIDTH8BIT)) { in mmc_set_timing()
519 ret = mmc_set_hs_timing(card); in mmc_set_timing()
529 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
530 sdmmc_wait_ready(card); in mmc_set_timing()
540 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_timing()
545 ret = sdmmc_wait_ready(card); in mmc_set_timing()
550 card->bus_io.clock = MMC_CLOCK_HS400; in mmc_set_timing()
551 card->bus_io.timing = SDHC_TIMING_HS400; in mmc_set_timing()
552 ret = sdhc_set_io(card->sdhc, &card->bus_io); in mmc_set_timing()
556 card->card_speed = ((cmd.arg & 0xFF << 8) >> 8); in mmc_set_timing()
561 static int mmc_read_ext_csd(struct sd_card *card, struct mmc_ext_csd *card_ext_csd) in mmc_read_ext_csd() argument
574 data.data = card->card_buffer; in mmc_read_ext_csd()
577 ret = sdhc_request(card->sdhc, &cmd, &data); in mmc_read_ext_csd()
583 mmc_decode_ext_csd(card_ext_csd, card->card_buffer); in mmc_read_ext_csd()
584 card->block_count = card_ext_csd->sec_count; in mmc_read_ext_csd()
585 card->block_size = SDMMC_DEFAULT_BLOCK_SIZE; in mmc_read_ext_csd()
587 LOG_INF("Card block count is %d, block size is %d", card->block_count, card->block_size); in mmc_read_ext_csd()
614 static int mmc_set_cache(struct sd_card *card, struct mmc_ext_csd *card_ext_csd) in mmc_set_cache() argument
628 ret = sdhc_request(card->sdhc, &cmd, NULL); in mmc_set_cache()
633 ret = sdmmc_wait_ready(card); in mmc_set_cache()