Lines Matching +full:count +full:- +full:width
4 * SPDX-License-Identifier: Apache-2.0
25 scr->flags = 0U; in sdmmc_decode_scr()
26 scr->scr_structure = (uint8_t)((raw_scr[0U] & 0xF0000000U) >> 28U); in sdmmc_decode_scr()
27 scr->sd_spec = (uint8_t)((raw_scr[0U] & 0xF000000U) >> 24U); in sdmmc_decode_scr()
29 scr->flags |= SD_SCR_DATA_STATUS_AFTER_ERASE; in sdmmc_decode_scr()
31 scr->sd_sec = (uint8_t)((raw_scr[0U] & 0x700000U) >> 20U); in sdmmc_decode_scr()
32 scr->sd_width = (uint8_t)((raw_scr[0U] & 0xF0000U) >> 16U); in sdmmc_decode_scr()
34 scr->flags |= SD_SCR_SPEC3; in sdmmc_decode_scr()
36 scr->sd_ext_sec = (uint8_t)((raw_scr[0U] & 0x7800U) >> 10U); in sdmmc_decode_scr()
37 scr->cmd_support = (uint8_t)(raw_scr[0U] & 0x3U); in sdmmc_decode_scr()
38 scr->rsvd = raw_scr[1U]; in sdmmc_decode_scr()
40 switch (scr->sd_spec) { in sdmmc_decode_scr()
49 if (scr->flags & SD_SCR_SPEC3) { in sdmmc_decode_scr()
80 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_spi_send_ocr()
87 card->ocr = cmd.response[1]; in sdmmc_spi_send_ocr()
88 if (card->ocr == 0) { in sdmmc_spi_send_ocr()
90 return -ENOTSUP; in sdmmc_spi_send_ocr()
118 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_send_ocr()
131 if (card->host_props.is_spi) { in sdmmc_send_ocr()
145 return -ETIMEDOUT; in sdmmc_send_ocr()
148 if (!card->host_props.is_spi) { in sdmmc_send_ocr()
150 card->ocr = cmd.response[0U]; in sdmmc_send_ocr()
164 uint32_t *scr = (uint32_t *)card->card_buffer; in sdmmc_read_scr()
167 ret = sdmmc_app_command(card, card->relative_addr); in sdmmc_read_scr()
184 ret = sdhc_request(card->sdhc, &cmd, &data); in sdmmc_read_scr()
192 sdmmc_decode_scr(&card_scr, raw_scr, &card->sd_version); in sdmmc_read_scr()
193 LOG_DBG("SD reports specification version %d", card->sd_version); in sdmmc_read_scr()
194 /* Check card supported bus width */ in sdmmc_read_scr()
196 card->flags |= SD_4BITS_WIDTH; in sdmmc_read_scr()
200 card->flags |= SD_SPEED_CLASS_CONTROL_FLAG; in sdmmc_read_scr()
202 /* Check for set block count (CMD 23) support */ in sdmmc_read_scr()
204 card->flags |= SD_CMD23_FLAG; in sdmmc_read_scr()
220 return sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_set_blocklen()
224 * Sets bus width of host and card, following section 3.4 of
227 static int sdmmc_set_bus_width(struct sd_card *card, enum sdhc_bus_width width) in sdmmc_set_bus_width() argument
236 /* Send ACMD6 to change bus width */ in sdmmc_set_bus_width()
237 ret = sdmmc_app_command(card, card->relative_addr); in sdmmc_set_bus_width()
248 switch (width) { in sdmmc_set_bus_width()
256 return -ENOTSUP; in sdmmc_set_bus_width()
259 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_set_bus_width()
269 /* Card now has changed bus width. Change host bus width */ in sdmmc_set_bus_width()
270 card->bus_io.bus_width = width; in sdmmc_set_bus_width()
271 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_set_bus_width()
273 LOG_DBG("Could not change host bus width"); in sdmmc_set_bus_width()
280 * See table 4-32 in SD physical specification for argument details.
304 return sdhc_request(card->sdhc, &cmd, &data); in sdmmc_switch()
312 if (card->sd_version < SD_SPEC_VER1_1) { in sdmmc_read_switch()
318 status = card->card_buffer; in sdmmc_read_switch()
329 * See table 4-11 and 4.3.10.4 of physical layer specification for in sdmmc_read_switch()
331 * read bits 400-408. in sdmmc_read_switch()
337 card->switch_caps.hs_max_dtr = HS_MAX_DTR; in sdmmc_read_switch()
339 card->switch_caps.hs_max_dtr = HS_UNSUPPORTED; in sdmmc_read_switch()
343 card->switch_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sdmmc_read_switch()
345 card->switch_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sdmmc_read_switch()
347 card->switch_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sdmmc_read_switch()
349 card->switch_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; in sdmmc_read_switch()
351 card->switch_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; in sdmmc_read_switch()
353 card->switch_caps.uhs_max_dtr = UHS_UNSUPPORTED; in sdmmc_read_switch()
355 if (card->sd_version >= SD_SPEC_VER3_0) { in sdmmc_read_switch()
356 card->switch_caps.bus_speed = status[13]; in sdmmc_read_switch()
357 card->switch_caps.sd_drv_type = status[9]; in sdmmc_read_switch()
358 card->switch_caps.sd_current_limit = status[7]; in sdmmc_read_switch()
367 * selection is defined using values 0x0-0xF. in sdmmc_select_bus_speed()
369 if ((card->flags & SD_1800MV_FLAG) && sdmmc_host_uhs(&card->host_props) && in sdmmc_select_bus_speed()
370 !(card->host_props.is_spi) && IS_ENABLED(CONFIG_SD_UHS_PROTOCOL)) { in sdmmc_select_bus_speed()
372 if (card->host_props.host_caps.sdr104_support && in sdmmc_select_bus_speed()
373 (card->switch_caps.bus_speed & UHS_SDR104_BUS_SPEED)) { in sdmmc_select_bus_speed()
374 card->card_speed = SD_TIMING_SDR104; in sdmmc_select_bus_speed()
375 } else if (card->host_props.host_caps.ddr50_support && in sdmmc_select_bus_speed()
376 (card->switch_caps.bus_speed & UHS_DDR50_BUS_SPEED)) { in sdmmc_select_bus_speed()
377 card->card_speed = SD_TIMING_DDR50; in sdmmc_select_bus_speed()
378 } else if (card->host_props.host_caps.sdr50_support && in sdmmc_select_bus_speed()
379 (card->switch_caps.bus_speed & UHS_SDR50_BUS_SPEED)) { in sdmmc_select_bus_speed()
380 card->card_speed = SD_TIMING_SDR50; in sdmmc_select_bus_speed()
381 } else if (card->switch_caps.bus_speed & UHS_SDR12_BUS_SPEED) { in sdmmc_select_bus_speed()
382 card->card_speed = SD_TIMING_SDR25; in sdmmc_select_bus_speed()
384 card->card_speed = SD_TIMING_SDR12; in sdmmc_select_bus_speed()
388 if (card->host_props.host_caps.high_spd_support && in sdmmc_select_bus_speed()
389 (card->switch_caps.bus_speed & HIGH_SPEED_BUS_SPEED)) { in sdmmc_select_bus_speed()
390 card->card_speed = SD_TIMING_HIGH_SPEED; in sdmmc_select_bus_speed()
392 card->card_speed = SD_TIMING_DEFAULT; in sdmmc_select_bus_speed()
401 uint8_t *status = card->card_buffer; in sdmmc_select_driver_type()
407 if (card->host_props.host_caps.drv_type_c_support && in sdmmc_select_driver_type()
408 (card->switch_caps.sd_drv_type & SD_DRIVER_TYPE_C)) { in sdmmc_select_driver_type()
409 card->bus_io.driver_type = SD_DRIVER_TYPE_C; in sdmmc_select_driver_type()
412 (find_msb_set(SD_DRIVER_TYPE_C) - 1), status); in sdmmc_select_driver_type()
421 int max_current = -1; in sdmmc_set_current_limit()
422 uint8_t *status = card->card_buffer; in sdmmc_set_current_limit()
424 if ((card->card_speed != SD_TIMING_SDR50) && (card->card_speed != SD_TIMING_SDR104) && in sdmmc_set_current_limit()
425 (card->card_speed != SD_TIMING_DDR50)) { in sdmmc_set_current_limit()
427 } else if (card->host_props.max_current_180 >= 800 && in sdmmc_set_current_limit()
428 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_800MA)) { in sdmmc_set_current_limit()
430 } else if (card->host_props.max_current_180 >= 600 && in sdmmc_set_current_limit()
431 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_600MA)) { in sdmmc_set_current_limit()
433 } else if (card->host_props.max_current_180 >= 400 && in sdmmc_set_current_limit()
434 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_400MA)) { in sdmmc_set_current_limit()
436 } else if (card->host_props.max_current_180 >= 200 && in sdmmc_set_current_limit()
437 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_200MA)) { in sdmmc_set_current_limit()
440 if (max_current != -1) { in sdmmc_set_current_limit()
461 uint8_t *status = card->card_buffer; in sdmmc_set_bus_speed()
469 if ((card->flags & SD_1800MV_FLAG) && sdmmc_host_uhs(&card->host_props) && in sdmmc_set_bus_speed()
470 !(card->host_props.is_spi) && IS_ENABLED(CONFIG_SD_UHS_PROTOCOL)) { in sdmmc_set_bus_speed()
472 card_clock = MIN(card->host_props.f_max, card->switch_caps.uhs_max_dtr); in sdmmc_set_bus_speed()
473 switch (card->card_speed) { in sdmmc_set_bus_speed()
495 card_clock = MIN(card->host_props.f_max, card->switch_caps.hs_max_dtr); in sdmmc_set_bus_speed()
496 switch (card->card_speed) { in sdmmc_set_bus_speed()
510 ret = sdmmc_switch(card, SD_SWITCH_SET, SD_GRP_TIMING_MODE, card->card_speed, status); in sdmmc_set_bus_speed()
515 if ((status[16] & 0xF) != card->card_speed) { in sdmmc_set_bus_speed()
519 card->bus_io.timing = timing; in sdmmc_set_bus_speed()
520 card->bus_io.clock = card_clock; in sdmmc_set_bus_speed()
521 LOG_DBG("Setting bus clock to: %d", card->bus_io.clock); in sdmmc_set_bus_speed()
522 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_set_bus_speed()
532 * Init UHS capable SD card. Follows figure 3-16 in physical layer specification.
538 /* Raise bus width to 4 bits */ in sdmmc_init_uhs()
541 LOG_ERR("Failed to change card bus width to 4 bits"); in sdmmc_init_uhs()
564 if (card->card_speed == SD_TIMING_SDR50 || card->card_speed == SD_TIMING_SDR104 || in sdmmc_init_uhs()
565 card->card_speed == SD_TIMING_DDR50) { in sdmmc_init_uhs()
567 ret = sdhc_execute_tuning(card->sdhc); in sdmmc_init_uhs()
580 if ((!card->host_props.host_caps.high_spd_support) || in sdmmc_init_hs()
581 (card->sd_version < SD_SPEC_VER1_1) || in sdmmc_init_hs()
582 (card->switch_caps.hs_max_dtr == HS_UNSUPPORTED)) { in sdmmc_init_hs()
594 if (card->flags & SD_4BITS_WIDTH) { in sdmmc_init_hs()
595 /* Raise bus width to 4 bits */ in sdmmc_init_hs()
598 LOG_ERR("Failed to change card bus width to 4 bits"); in sdmmc_init_hs()
615 if (card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_SPI_MODE)) { in sdmmc_card_init()
622 return -ENOTSUP; in sdmmc_card_init()
628 card->type = CARD_SDMMC; in sdmmc_card_init()
630 if (card->flags & SD_SDHC_FLAG) { in sdmmc_card_init()
633 if (card->host_props.host_caps.vol_180_support) { in sdmmc_card_init()
642 if (card->host_props.host_caps.vol_300_support) { in sdmmc_card_init()
658 if (card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_SPI_MODE)) { in sdmmc_card_init()
666 if (card->ocr & SD_OCR_CARD_CAP_FLAG) { in sdmmc_card_init()
667 card->flags |= SD_HIGH_CAPACITY_FLAG; in sdmmc_card_init()
669 if (card->ocr & SD_OCR_SWITCH_18_ACCEPT_FLAG) { in sdmmc_card_init()
671 card->flags |= SD_1800MV_FLAG; in sdmmc_card_init()
674 if (card->ocr & SD_OCR_VDD29_30FLAG) { in sdmmc_card_init()
675 card->flags |= SD_3000MV_FLAG; in sdmmc_card_init()
682 if ((card->flags & SD_1800MV_FLAG) && (card->host_props.host_caps.vol_180_support) && in sdmmc_card_init()
683 (!card->host_props.is_spi) && IS_ENABLED(CONFIG_SD_UHS_PROTOCOL)) { in sdmmc_card_init()
687 card->host_props.host_caps.vol_180_support = false; in sdmmc_card_init()
693 card->status = CARD_ERROR; in sdmmc_card_init()
702 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
717 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
728 if (card->host_props.f_max < SD_CLOCK_25MHZ) { in sdmmc_card_init()
730 card->host_props.f_max); in sdmmc_card_init()
731 card->bus_io.clock = card->host_props.f_max; in sdmmc_card_init()
733 card->bus_io.clock = SD_CLOCK_25MHZ; in sdmmc_card_init()
735 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_card_init()
741 * to get supported bus width in sdmmc_card_init()
748 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
755 if ((card->flags & SD_1800MV_FLAG) && sdmmc_host_uhs(&card->host_props) && in sdmmc_card_init()
756 !(card->host_props.is_spi) && IS_ENABLED(CONFIG_SD_UHS_PROTOCOL)) { in sdmmc_card_init()
762 if ((card->flags & SD_HIGH_CAPACITY_FLAG) == 0) { in sdmmc_card_init()
769 card->block_size = 512; in sdmmc_card_init()