Lines Matching +full:num +full:- +full:transfer +full:- +full:bits

2  * Copyright 2022-2023 NXP
4 * SPDX-License-Identifier: Apache-2.0
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()
59 return -ENOTSUP; in sdio_send_ocr()
76 return -ETIMEDOUT; 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()
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()
156 return sdhc_request(card->sdhc, &cmd, &data); in sdio_io_rw_extended()
160 * Helper for extended r/w. Splits the transfer into the minimum possible
174 if (func->num > SDIO_MAX_IO_NUMS) { in sdio_io_rw_extended_helper()
175 return -EINVAL; in sdio_io_rw_extended_helper()
178 if ((func->card->cccr_flags & SDIO_SUPPORT_MULTIBLOCK) && in sdio_io_rw_extended_helper()
179 ((len > func->block_size))) { in sdio_io_rw_extended_helper()
181 while (remaining >= func->block_size) { in sdio_io_rw_extended_helper()
182 blocks = remaining / func->block_size; in sdio_io_rw_extended_helper()
183 size = blocks * func->block_size; in sdio_io_rw_extended_helper()
184 ret = sdio_io_rw_extended(func->card, direction, in sdio_io_rw_extended_helper()
185 func->num, reg_addr, increment, buf, blocks, in sdio_io_rw_extended_helper()
186 func->block_size); in sdio_io_rw_extended_helper()
191 remaining -= size; in sdio_io_rw_extended_helper()
200 size = MIN(remaining, func->cis.max_blk_size); in sdio_io_rw_extended_helper()
202 ret = sdio_io_rw_extended(func->card, direction, func->num, in sdio_io_rw_extended_helper()
207 remaining -= size; in sdio_io_rw_extended_helper()
240 card->sd_version = (data & SDIO_CCCR_SD_SPEC_MASK) >> SDIO_CCCR_SD_SPEC_SHIFT; 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()
262 card->cccr_flags |= SDIO_SUPPORT_HS; in sdio_read_cccr()
266 (card->flags & SD_1800MV_FLAG)) { 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()
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()
309 cis->manf_id = data[0] | ((uint16_t)data[1] << 8); in sdio_decode_cis()
310 cis->manf_code = data[2] | ((uint16_t)data[3] << 8); in sdio_decode_cis()
313 cis->func_id = data[0]; in sdio_decode_cis()
317 cis->max_blk_size = data[1] | ((uint16_t)data[2] << 8); in sdio_decode_cis()
318 cis->max_speed = data[3]; in sdio_decode_cis()
320 cis->max_blk_size = data[12] | ((uint16_t)data[13] << 8); in sdio_decode_cis()
321 cis->rdy_timeout = data[28] | ((uint16_t)data[29] << 8); in sdio_decode_cis()
339 char *data = func->card->card_buffer; in sdio_read_cis()
340 uint32_t cis_ptr = 0, num = 0; in sdio_read_cis() local
344 memset(&func->cis, 0, sizeof(struct sdio_cis)); in sdio_read_cis()
347 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_read_cis()
348 SDIO_FBR_BASE(func->num) + SDIO_FBR_CIS + i, 0, data); 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()
397 num++; in sdio_read_cis()
400 sdio_decode_cis(&func->cis, func->num, data, in sdio_read_cis()
406 } while (num < tuple_count); in sdio_read_cis()
407 LOG_DBG("SDIO CIS max block size for func %d: %d", func->num, in sdio_read_cis()
408 func->cis.max_blk_size); in sdio_read_cis()
434 return -ENOTSUP; 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()
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()
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()
527 } while (((speed_reg & target_speed) != target_speed) && retries-- > 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()
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()
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()
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()
622 /* Move the card to transfer state (with CMD7) to run 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()
648 /* Raise bus width to 4 bits */ in sdio_card_init()
653 LOG_DBG("Raised card bus width to 4 bits"); 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()
681 * @param num: function number to initialize
683 * @retval -EIO: I/O error
686 enum sdio_func_num num) in sdio_init_func() argument
689 func->num = num; in sdio_init_func()
690 func->card = card; in sdio_init_func()
691 func->block_size = 0; in sdio_init_func()
705 * @retval -ETIMEDOUT: card I/O timed out
706 * @retval -EIO: I/O error
715 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, SDIO_FUNC_NUM_0, in sdio_enable_func()
720 reg |= BIT(func->num); in sdio_enable_func()
721 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_enable_func()
727 if (func->cis.rdy_timeout) { in sdio_enable_func()
732 sd_delay(((uint32_t)func->cis.rdy_timeout) * 10U); in sdio_enable_func()
733 ret = sdio_io_rw_direct(func->card, SDIO_IO_READ, in sdio_enable_func()
738 if (reg & BIT(func->num)) { in sdio_enable_func()
741 } while (retries-- != 0); in sdio_enable_func()
742 return -ETIMEDOUT; in sdio_enable_func()
753 * @retval -EINVAL: unsupported/invalid block size
754 * @retval -EIO: I/O error
761 if (func->cis.max_blk_size < bsize) { in sdio_set_block_size()
762 return -EINVAL; in sdio_set_block_size()
766 ret = sdio_io_rw_direct(func->card, SDIO_IO_WRITE, SDIO_FUNC_NUM_0, in sdio_set_block_size()
767 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLK_SIZE + i, reg, NULL); in sdio_set_block_size()
772 func->block_size = bsize; in sdio_set_block_size()
784 * @retval -EBUSY: card is busy with another request
785 * @retval -ETIMEDOUT: card read timed out
786 * @retval -EIO: I/O error
792 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_byte()
794 return -ENOTSUP; in sdio_read_byte()
796 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_byte()
799 return -EBUSY; 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()
814 * @retval -EBUSY: card is busy with another request
815 * @retval -ETIMEDOUT: card write timed out
816 * @retval -EIO: I/O error
822 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_byte()
824 return -ENOTSUP; in sdio_write_byte()
826 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_byte()
829 return -EBUSY; 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()
846 * @retval -EBUSY: card is busy with another request
847 * @retval -ETIMEDOUT: card write timed out
848 * @retval -EIO: I/O error
855 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_rw_byte()
857 return -ENOTSUP; in sdio_rw_byte()
859 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_rw_byte()
862 return -EBUSY; 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()
880 * @retval -EBUSY: card is busy with another request
881 * @retval -ETIMEDOUT: card read timed out
882 * @retval -EIO: I/O error
889 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_fifo()
891 return -ENOTSUP; in sdio_read_fifo()
893 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_fifo()
896 return -EBUSY; in sdio_read_fifo()
900 k_mutex_unlock(&func->card->lock); in sdio_read_fifo()
914 * @retval -EBUSY: card is busy with another request
915 * @retval -ETIMEDOUT: card write timed out
916 * @retval -EIO: I/O error
923 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_fifo()
925 return -ENOTSUP; in sdio_write_fifo()
927 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_fifo()
930 return -EBUSY; in sdio_write_fifo()
934 k_mutex_unlock(&func->card->lock); in sdio_write_fifo()
948 * @retval -EBUSY: card is busy with another request
949 * @retval -ETIMEDOUT: card read timed out
950 * @retval -EIO: I/O error
957 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_blocks_fifo()
959 return -ENOTSUP; in sdio_read_blocks_fifo()
961 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_blocks_fifo()
964 return -EBUSY; in sdio_read_blocks_fifo()
966 ret = sdio_io_rw_extended(func->card, SDIO_IO_READ, func->num, reg, in sdio_read_blocks_fifo()
967 false, data, blocks, func->block_size); in sdio_read_blocks_fifo()
968 k_mutex_unlock(&func->card->lock); in sdio_read_blocks_fifo()
982 * @retval -EBUSY: card is busy with another request
983 * @retval -ETIMEDOUT: card write timed out
984 * @retval -EIO: I/O error
991 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_blocks_fifo()
993 return -ENOTSUP; in sdio_write_blocks_fifo()
995 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_blocks_fifo()
998 return -EBUSY; in sdio_write_blocks_fifo()
1000 ret = sdio_io_rw_extended(func->card, SDIO_IO_WRITE, func->num, reg, in sdio_write_blocks_fifo()
1001 false, data, blocks, func->block_size); in sdio_write_blocks_fifo()
1002 k_mutex_unlock(&func->card->lock); in sdio_write_blocks_fifo()
1015 * @retval -EBUSY: card is busy with another request
1016 * @retval -ETIMEDOUT: card read timed out
1017 * @retval -EIO: I/O error
1024 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_read_addr()
1026 return -ENOTSUP; in sdio_read_addr()
1028 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_read_addr()
1031 return -EBUSY; in sdio_read_addr()
1035 k_mutex_unlock(&func->card->lock); in sdio_read_addr()
1049 * @retval -EBUSY: card is busy with another request
1050 * @retval -ETIMEDOUT: card write timed out
1051 * @retval -EIO: I/O error
1058 if ((func->card->type != CARD_SDIO) && (func->card->type != CARD_COMBO)) { in sdio_write_addr()
1060 return -ENOTSUP; in sdio_write_addr()
1062 ret = k_mutex_lock(&func->card->lock, K_MSEC(CONFIG_SD_DATA_TIMEOUT)); in sdio_write_addr()
1065 return -EBUSY; in sdio_write_addr()
1069 k_mutex_unlock(&func->card->lock); in sdio_write_addr()