Lines Matching +full:current +full:- +full:limit

4  * SPDX-License-Identifier: Apache-2.0
26 scr->flags = 0U; in sdmmc_decode_scr()
27 scr->scr_structure = (uint8_t)((raw_scr[0U] & 0xF0000000U) >> 28U); in sdmmc_decode_scr()
28 scr->sd_spec = (uint8_t)((raw_scr[0U] & 0xF000000U) >> 24U); in sdmmc_decode_scr()
30 scr->flags |= SD_SCR_DATA_STATUS_AFTER_ERASE; in sdmmc_decode_scr()
32 scr->sd_sec = (uint8_t)((raw_scr[0U] & 0x700000U) >> 20U); in sdmmc_decode_scr()
33 scr->sd_width = (uint8_t)((raw_scr[0U] & 0xF0000U) >> 16U); in sdmmc_decode_scr()
35 scr->flags |= SD_SCR_SPEC3; in sdmmc_decode_scr()
37 scr->sd_ext_sec = (uint8_t)((raw_scr[0U] & 0x7800U) >> 10U); in sdmmc_decode_scr()
38 scr->cmd_support = (uint8_t)(raw_scr[0U] & 0x3U); in sdmmc_decode_scr()
39 scr->rsvd = raw_scr[1U]; in sdmmc_decode_scr()
41 switch (scr->sd_spec) { in sdmmc_decode_scr()
50 if (scr->flags & SD_SCR_SPEC3) { in sdmmc_decode_scr()
79 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_spi_send_ocr()
86 card->ocr = cmd.response[1]; in sdmmc_spi_send_ocr()
87 if (card->ocr == 0) { in sdmmc_spi_send_ocr()
89 return -ENOTSUP; in sdmmc_spi_send_ocr()
115 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_send_ocr()
128 if (card->host_props.is_spi) { in sdmmc_send_ocr()
142 return -ETIMEDOUT; in sdmmc_send_ocr()
145 if (!card->host_props.is_spi) { in sdmmc_send_ocr()
147 card->ocr = cmd.response[0U]; in sdmmc_send_ocr()
161 uint32_t *scr = (uint32_t *)card->card_buffer; in sdmmc_read_scr()
164 ret = sdmmc_app_command(card, card->relative_addr); in sdmmc_read_scr()
180 ret = sdhc_request(card->sdhc, &cmd, &data); in sdmmc_read_scr()
188 sdmmc_decode_scr(&card_scr, raw_scr, &card->sd_version); in sdmmc_read_scr()
189 LOG_DBG("SD reports specification version %d", card->sd_version); in sdmmc_read_scr()
192 card->flags |= SD_4BITS_WIDTH; in sdmmc_read_scr()
196 card->flags |= SD_SPEED_CLASS_CONTROL_FLAG; in sdmmc_read_scr()
200 card->flags |= SD_CMD23_FLAG; in sdmmc_read_scr()
215 return sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_set_blocklen()
232 ret = sdmmc_app_command(card, card->relative_addr); in sdmmc_set_bus_width()
248 return -ENOTSUP; in sdmmc_set_bus_width()
251 ret = sdhc_request(card->sdhc, &cmd, NULL); in sdmmc_set_bus_width()
262 card->bus_io.bus_width = width; in sdmmc_set_bus_width()
263 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_set_bus_width()
272 * See table 4-32 in SD physical specification for argument details.
275 * blocks should be left as 0xF (no effect on current function)
295 return sdhc_request(card->sdhc, &cmd, &data); in sdmmc_switch()
303 if (card->sd_version < SD_SPEC_VER1_1) { in sdmmc_read_switch()
309 status = card->card_buffer; in sdmmc_read_switch()
320 * See table 4-11 and 4.3.10.4 of physical layer specification for in sdmmc_read_switch()
322 * read bits 400-408. in sdmmc_read_switch()
327 card->switch_caps.hs_max_dtr = HS_MAX_DTR; in sdmmc_read_switch()
329 if (card->sd_version >= SD_SPEC_VER3_0) { in sdmmc_read_switch()
330 card->switch_caps.bus_speed = status[13]; in sdmmc_read_switch()
331 card->switch_caps.sd_drv_type = status[9]; in sdmmc_read_switch()
332 card->switch_caps.sd_current_limit = status[7]; in sdmmc_read_switch()
341 * selection is defined using values 0x0-0xF. in sdmmc_select_bus_speed()
343 if (card->host_props.host_caps.sdr104_support && in sdmmc_select_bus_speed()
344 (card->switch_caps.bus_speed & UHS_SDR104_BUS_SPEED) && in sdmmc_select_bus_speed()
345 (card->host_props.f_max >= SD_CLOCK_208MHZ)) { in sdmmc_select_bus_speed()
346 card->card_speed = SD_TIMING_SDR104; in sdmmc_select_bus_speed()
347 } else if (card->host_props.host_caps.ddr50_support && in sdmmc_select_bus_speed()
348 (card->switch_caps.bus_speed & UHS_DDR50_BUS_SPEED) && in sdmmc_select_bus_speed()
349 (card->host_props.f_max >= SD_CLOCK_50MHZ)) { in sdmmc_select_bus_speed()
350 card->card_speed = SD_TIMING_DDR50; in sdmmc_select_bus_speed()
351 } else if (card->host_props.host_caps.sdr50_support && in sdmmc_select_bus_speed()
352 (card->switch_caps.bus_speed & UHS_SDR50_BUS_SPEED) && in sdmmc_select_bus_speed()
353 (card->host_props.f_max >= SD_CLOCK_100MHZ)) { in sdmmc_select_bus_speed()
354 card->card_speed = SD_TIMING_SDR50; in sdmmc_select_bus_speed()
355 } else if (card->host_props.host_caps.high_spd_support && in sdmmc_select_bus_speed()
356 (card->switch_caps.bus_speed & UHS_SDR12_BUS_SPEED) && in sdmmc_select_bus_speed()
357 (card->host_props.f_max >= SD_CLOCK_25MHZ)) { in sdmmc_select_bus_speed()
358 card->card_speed = SD_TIMING_SDR12; in sdmmc_select_bus_speed()
366 uint8_t *status = card->card_buffer; in sdmmc_select_driver_type()
370 * since it should result in lower current consumption if supported. in sdmmc_select_driver_type()
372 if (card->host_props.host_caps.drv_type_c_support && in sdmmc_select_driver_type()
373 (card->switch_caps.sd_drv_type & SD_DRIVER_TYPE_C)) { in sdmmc_select_driver_type()
374 card->bus_io.driver_type = SD_DRIVER_TYPE_C; in sdmmc_select_driver_type()
378 (find_msb_set(SD_DRIVER_TYPE_C) - 1), status); in sdmmc_select_driver_type()
383 /* Sets current limit for SD card */
387 int max_current = -1; in sdmmc_set_current_limit()
388 uint8_t *status = card->card_buffer; in sdmmc_set_current_limit()
390 if ((card->card_speed != SD_TIMING_SDR50) && in sdmmc_set_current_limit()
391 (card->card_speed != SD_TIMING_SDR104) && in sdmmc_set_current_limit()
392 (card->card_speed != SD_TIMING_DDR50)) { in sdmmc_set_current_limit()
393 return 0; /* Cannot set current limit */ in sdmmc_set_current_limit()
394 } else if (card->host_props.max_current_180 >= 800 && in sdmmc_set_current_limit()
395 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_800MA)) { in sdmmc_set_current_limit()
397 } else if (card->host_props.max_current_180 >= 600 && in sdmmc_set_current_limit()
398 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_600MA)) { in sdmmc_set_current_limit()
400 } else if (card->host_props.max_current_180 >= 400 && in sdmmc_set_current_limit()
401 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_400MA)) { in sdmmc_set_current_limit()
403 } else if (card->host_props.max_current_180 >= 200 && in sdmmc_set_current_limit()
404 (card->switch_caps.sd_current_limit & SD_MAX_CURRENT_200MA)) { in sdmmc_set_current_limit()
407 if (max_current != -1) { in sdmmc_set_current_limit()
408 LOG_DBG("Changing SD current limit: %d", max_current); in sdmmc_set_current_limit()
409 /* Switch SD current */ in sdmmc_set_current_limit()
413 LOG_DBG("Failed to set SD current limit"); in sdmmc_set_current_limit()
417 /* Status response indicates card did not select request limit */ in sdmmc_set_current_limit()
418 LOG_WRN("Card did not accept current limit"); in sdmmc_set_current_limit()
429 uint8_t *status = card->card_buffer; in sdmmc_set_bus_speed()
431 switch (card->card_speed) { in sdmmc_set_bus_speed()
434 card->switch_caps.uhs_max_dtr = SD_CLOCK_208MHZ; in sdmmc_set_bus_speed()
438 card->switch_caps.uhs_max_dtr = SD_CLOCK_50MHZ; in sdmmc_set_bus_speed()
442 card->switch_caps.uhs_max_dtr = SD_CLOCK_100MHZ; in sdmmc_set_bus_speed()
446 card->switch_caps.uhs_max_dtr = SD_CLOCK_50MHZ; in sdmmc_set_bus_speed()
450 card->switch_caps.uhs_max_dtr = SD_CLOCK_25MHZ; in sdmmc_set_bus_speed()
460 card->card_speed, status); in sdmmc_set_bus_speed()
465 if ((status[16] & 0xF) != card->card_speed) { in sdmmc_set_bus_speed()
469 card->bus_io.timing = timing; in sdmmc_set_bus_speed()
470 card->bus_io.clock = card->switch_caps.uhs_max_dtr; in sdmmc_set_bus_speed()
471 LOG_DBG("Setting bus clock to: %d", card->bus_io.clock); in sdmmc_set_bus_speed()
472 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_set_bus_speed()
482 * Init UHS capable SD card. Follows figure 3-16 in physical layer specification.
505 LOG_DBG("Failed to set card current limit"); in sdmmc_init_uhs()
514 if (card->card_speed == SD_TIMING_SDR50 || in sdmmc_init_uhs()
515 card->card_speed == SD_TIMING_SDR104 || in sdmmc_init_uhs()
516 card->card_speed == SD_TIMING_DDR50) { in sdmmc_init_uhs()
518 ret = sdhc_execute_tuning(card->sdhc); in sdmmc_init_uhs()
531 if ((!card->host_props.host_caps.high_spd_support) || in sdmmc_init_hs()
532 (card->sd_version < SD_SPEC_VER1_1) || in sdmmc_init_hs()
533 (card->switch_caps.hs_max_dtr == 0)) { in sdmmc_init_hs()
537 card->card_speed = SD_TIMING_SDR25; in sdmmc_init_hs()
543 if (card->flags & SD_4BITS_WIDTH) { in sdmmc_init_hs()
564 if (card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_SPI_MODE)) { in sdmmc_card_init()
571 return -ENOTSUP; in sdmmc_card_init()
577 card->type = CARD_SDMMC; in sdmmc_card_init()
579 if (card->flags & SD_SDHC_FLAG) { in sdmmc_card_init()
582 if (card->host_props.host_caps.vol_180_support) { in sdmmc_card_init()
591 if (card->host_props.host_caps.vol_300_support) { in sdmmc_card_init()
607 if (card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_SPI_MODE)) { in sdmmc_card_init()
615 if (card->ocr & SD_OCR_CARD_CAP_FLAG) { in sdmmc_card_init()
616 card->flags |= SD_HIGH_CAPACITY_FLAG; in sdmmc_card_init()
618 if (card->ocr & SD_OCR_SWITCH_18_ACCEPT_FLAG) { in sdmmc_card_init()
620 card->flags |= SD_1800MV_FLAG; in sdmmc_card_init()
623 if (card->ocr & SD_OCR_VDD29_30FLAG) { in sdmmc_card_init()
624 card->flags |= SD_3000MV_FLAG; in sdmmc_card_init()
631 if ((card->flags & SD_1800MV_FLAG) && in sdmmc_card_init()
632 (card->host_props.host_caps.vol_180_support) && in sdmmc_card_init()
633 (!card->host_props.is_spi) && in sdmmc_card_init()
638 card->host_props.host_caps.vol_180_support = false; in sdmmc_card_init()
644 card->status = CARD_ERROR; in sdmmc_card_init()
653 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
668 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
679 if (card->host_props.f_max < SD_CLOCK_25MHZ) { in sdmmc_card_init()
681 card->host_props.f_max); in sdmmc_card_init()
682 card->bus_io.clock = card->host_props.f_max; in sdmmc_card_init()
684 card->bus_io.clock = SD_CLOCK_25MHZ; in sdmmc_card_init()
686 ret = sdhc_set_io(card->sdhc, &card->bus_io); in sdmmc_card_init()
699 if (!card->host_props.is_spi && IS_ENABLED(CONFIG_SDHC_SUPPORTS_NATIVE_MODE)) { in sdmmc_card_init()
706 if ((card->flags & SD_1800MV_FLAG) && in sdmmc_card_init()
707 sdmmc_host_uhs(&card->host_props) && in sdmmc_card_init()
708 !(card->host_props.is_spi) && in sdmmc_card_init()
715 if ((card->flags & SD_HIGH_CAPACITY_FLAG) == 0) { in sdmmc_card_init()
722 card->block_size = 512; in sdmmc_card_init()