Lines Matching refs:card
28 static int sdio_send_ocr(struct sd_card *card, uint32_t ocr) in sdio_send_ocr() argument
40 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdio_send_ocr()
50 card->num_io = (cmd.response[0] & SDIO_OCR_IO_NUMBER) in sdio_send_ocr()
52 if ((card->num_io == 0) || in sdio_send_ocr()
79 if (!card->host_props.is_spi) { in sdio_send_ocr()
81 card->ocr = cmd.response[0U]; in sdio_send_ocr()
86 static int sdio_io_rw_direct(struct sd_card *card, in sdio_io_rw_direct() argument
109 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdio_io_rw_direct()
114 if (card->host_props.is_spi) { in sdio_io_rw_direct()
124 static int sdio_io_rw_extended(struct sd_card *card, in sdio_io_rw_extended() argument
156 return sdhc_request(card->sdhc, &cmd, &data); in sdio_io_rw_extended()
178 if ((func->card->cccr_flags & SDIO_SUPPORT_MULTIBLOCK) && in sdio_io_rw_extended_helper()
184 ret = sdio_io_rw_extended(func->card, direction, in sdio_io_rw_extended_helper()
202 ret = sdio_io_rw_extended(func->card, direction, func->num, in sdio_io_rw_extended_helper()
219 static int sdio_read_cccr(struct sd_card *card) in sdio_read_cccr() argument
225 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
235 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
240 card->sd_version = (data & SDIO_CCCR_SD_SPEC_MASK) >> SDIO_CCCR_SD_SPEC_SHIFT; in sdio_read_cccr()
242 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
247 card->cccr_flags = 0; in sdio_read_cccr()
249 card->cccr_flags |= SDIO_SUPPORT_4BIT_LS_BUS; in sdio_read_cccr()
252 card->cccr_flags |= SDIO_SUPPORT_MULTIBLOCK; in sdio_read_cccr()
256 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
262 card->cccr_flags |= SDIO_SUPPORT_HS; in sdio_read_cccr()
266 (card->flags & SD_1800MV_FLAG)) { in sdio_read_cccr()
268 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
273 if (sdmmc_host_uhs(&card->host_props)) { in sdio_read_cccr()
275 card->cccr_flags |= SDIO_SUPPORT_SDR50; in sdio_read_cccr()
278 card->cccr_flags |= SDIO_SUPPORT_SDR104; in sdio_read_cccr()
281 card->cccr_flags |= SDIO_SUPPORT_DDR50; in sdio_read_cccr()
285 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cccr()
290 card->switch_caps.sd_drv_type = 0; in sdio_read_cccr()
292 card->switch_caps.sd_drv_type |= SD_DRIVER_TYPE_A; in sdio_read_cccr()
295 card->switch_caps.sd_drv_type |= SD_DRIVER_TYPE_C; in sdio_read_cccr()
298 card->switch_caps.sd_drv_type |= SD_DRIVER_TYPE_D; in sdio_read_cccr()
339 char *data = func->card->card_buffer; in sdio_read_cis()
347 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cis()
357 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cis()
371 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cis()
391 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, in sdio_read_cis()
412 static int sdio_set_bus_width(struct sd_card *card, enum sdhc_bus_width width) in sdio_set_bus_width() argument
417 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_set_bus_width()
436 ret = sdio_io_rw_direct(card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_set_bus_width()
442 card->bus_io.bus_width = width; in sdio_set_bus_width()
443 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdio_set_bus_width()
450 static inline void sdio_select_bus_speed(struct sd_card *card) in sdio_select_bus_speed() argument
452 if (card->host_props.host_caps.sdr104_support && in sdio_select_bus_speed()
453 (card->cccr_flags & SDIO_SUPPORT_SDR104)) { in sdio_select_bus_speed()
454 card->card_speed = SD_TIMING_SDR104; in sdio_select_bus_speed()
455 card->switch_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sdio_select_bus_speed()
456 } else if (card->host_props.host_caps.ddr50_support && in sdio_select_bus_speed()
457 (card->cccr_flags & SDIO_SUPPORT_DDR50)) { in sdio_select_bus_speed()
458 card->card_speed = SD_TIMING_DDR50; in sdio_select_bus_speed()
459 card->switch_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sdio_select_bus_speed()
460 } else if (card->host_props.host_caps.sdr50_support && in sdio_select_bus_speed()
461 (card->cccr_flags & SDIO_SUPPORT_SDR50)) { in sdio_select_bus_speed()
462 card->card_speed = SD_TIMING_SDR50; in sdio_select_bus_speed()
463 card->switch_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sdio_select_bus_speed()
464 } else if (card->host_props.host_caps.high_spd_support && in sdio_select_bus_speed()
465 (card->cccr_flags & SDIO_SUPPORT_HS)) { in sdio_select_bus_speed()
466 card->card_speed = SD_TIMING_HIGH_SPEED; in sdio_select_bus_speed()
467 card->switch_caps.hs_max_dtr = HS_MAX_DTR; in sdio_select_bus_speed()
469 card->card_speed = SD_TIMING_DEFAULT; in sdio_select_bus_speed()
474 static int sdio_set_bus_speed(struct sd_card *card) in sdio_set_bus_speed() argument
480 switch (card->card_speed) { in sdio_set_bus_speed()
483 bus_clock = MIN(card->host_props.f_max, card->switch_caps.uhs_max_dtr); in sdio_set_bus_speed()
488 bus_clock = MIN(card->host_props.f_max, card->switch_caps.uhs_max_dtr); in sdio_set_bus_speed()
493 bus_clock = MIN(card->host_props.f_max, card->switch_caps.uhs_max_dtr); in sdio_set_bus_speed()
498 bus_clock = MIN(card->host_props.f_max, card->switch_caps.hs_max_dtr); in sdio_set_bus_speed()
503 bus_clock = MIN(card->host_props.f_max, MHZ(25)); in sdio_set_bus_speed()
512 ret = sdio_io_rw_direct(card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_set_bus_speed()
522 ret = sdio_io_rw_direct(card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_set_bus_speed()
533 card->bus_io.timing = timing; in sdio_set_bus_speed()
534 card->bus_io.clock = bus_clock; in sdio_set_bus_speed()
535 LOG_DBG("Setting bus clock to: %d", card->bus_io.clock); in sdio_set_bus_speed()
536 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdio_set_bus_speed()
548 int sdio_card_init(struct sd_card *card) in sdio_card_init() argument
554 ret = sdio_send_ocr(card, ocr_arg); in sdio_card_init()
559 card->type = CARD_SDIO; in sdio_card_init()
561 if (card->host_props.host_caps.vol_300_support) { in sdio_card_init()
566 card->host_props.host_caps.vol_180_support) { in sdio_card_init()
570 ret = sdio_send_ocr(card, ocr_arg); in sdio_card_init()
574 if (card->ocr & SD_OCR_SWITCH_18_ACCEPT_FLAG) { in sdio_card_init()
576 card->flags |= SD_1800MV_FLAG; in sdio_card_init()
579 if (card->ocr & SD_OCR_VDD29_30FLAG) { in sdio_card_init()
580 card->flags |= SD_3000MV_FLAG; in sdio_card_init()
583 if (card->ocr & SDIO_OCR_MEM_PRESENT_FLAG) { in sdio_card_init()
584 card->flags |= SD_MEM_PRESENT_FLAG; in sdio_card_init()
592 if ((card->flags & SD_1800MV_FLAG) && in sdio_card_init()
593 (!card->host_props.is_spi) && in sdio_card_init()
594 (card->host_props.host_caps.vol_180_support) && in sdio_card_init()
596 ret = sdmmc_switch_voltage(card); in sdio_card_init()
599 card->host_props.host_caps.vol_180_support = false; in sdio_card_init()
605 card->status = CARD_ERROR; in sdio_card_init()
609 if ((card->flags & SD_MEM_PRESENT_FLAG) && in sdio_card_init()
610 ((card->flags & SD_SDHC_FLAG) == 0)) { in sdio_card_init()
612 ret = card_read_cid(card); in sdio_card_init()
618 ret = sdmmc_request_rca(card); in sdio_card_init()
625 ret = sdmmc_select_card(card); in sdio_card_init()
631 ret = sdio_read_cccr(card); in sdio_card_init()
636 card->func0.num = SDIO_FUNC_NUM_0; in sdio_card_init()
637 card->func0.card = card; in sdio_card_init()
638 ret = sdio_read_cis(&card->func0, cis_tuples, in sdio_card_init()
646 ((card->cccr_flags & SDIO_SUPPORT_HS) || in sdio_card_init()
647 (card->cccr_flags & SDIO_SUPPORT_4BIT_LS_BUS))) { in sdio_card_init()
649 ret = sdio_set_bus_width(card, SDHC_BUS_WIDTH4BIT); in sdio_card_init()
657 sdio_select_bus_speed(card); in sdio_card_init()
658 ret = sdio_set_bus_speed(card); in sdio_card_init()
662 if (card->card_speed == SD_TIMING_SDR50 || in sdio_card_init()
663 card->card_speed == SD_TIMING_SDR104) { in sdio_card_init()
665 ret = sdhc_execute_tuning(card->sdhc); in sdio_card_init()
685 int sdio_init_func(struct sd_card *card, struct sdio_func *func, in sdio_init_func() argument
690 func->card = card; in sdio_init_func()
715 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_enable_func()
721 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_enable_func()
733 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, in sdio_enable_func()
766 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_set_block_size()
792 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_byte()
796 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_byte()
801 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, func->num, reg, 0, val); in sdio_read_byte()
802 k_mutex_unlock(&func->card->lock); in sdio_read_byte()
822 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_byte()
826 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_byte()
831 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, func->num, reg, in sdio_write_byte()
833 k_mutex_unlock(&func->card->lock); in sdio_write_byte()
855 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_rw_byte()
859 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_rw_byte()
864 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, func->num, reg, in sdio_rw_byte()
866 k_mutex_unlock(&func->card->lock); in sdio_rw_byte()
889 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_fifo()
893 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_fifo()
900 k_mutex_unlock(&func->card->lock); in sdio_read_fifo()
923 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_fifo()
927 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_fifo()
934 k_mutex_unlock(&func->card->lock); in sdio_write_fifo()
957 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_blocks_fifo()
961 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_blocks_fifo()
966 ret = sdio_io_rw_extended(func->card, SDIO_IO_READ, func->num, reg, in sdio_read_blocks_fifo()
968 k_mutex_unlock(&func->card->lock); in sdio_read_blocks_fifo()
991 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_blocks_fifo()
995 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_blocks_fifo()
1000 ret = sdio_io_rw_extended(func->card, SDIO_IO_WRITE, func->num, reg, in sdio_write_blocks_fifo()
1002 k_mutex_unlock(&func->card->lock); in sdio_write_blocks_fifo()
1024 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_addr()
1028 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_addr()
1035 k_mutex_unlock(&func->card->lock); in sdio_read_addr()
1058 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_addr()
1062 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_addr()
1069 k_mutex_unlock(&func->card->lock); in sdio_write_addr()