Lines Matching +full:cmd +full:- +full:dat +full:- +full:delay +full:- +full:select

1 // SPDX-License-Identifier: GPL-2.0+
13 #include <dm/device-internal.h>
35 return -ENOSYS; in mmc_wait_dat0()
41 return -1; in board_mmc_getwp()
51 if (mmc->cfg->ops->getwp) in mmc_getwp()
52 wp = mmc->cfg->ops->getwp(mmc); in mmc_getwp()
62 return -1; in board_mmc_getcd()
67 void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd) in mmmc_trace_before_send() argument
69 printf("CMD_SEND:%d\n", cmd->cmdidx); in mmmc_trace_before_send()
70 printf("\t\tARG\t\t\t 0x%08x\n", cmd->cmdarg); in mmmc_trace_before_send()
73 void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, int ret) in mmmc_trace_after_send() argument
81 switch (cmd->resp_type) { in mmmc_trace_after_send()
87 cmd->response[0]); in mmmc_trace_after_send()
91 cmd->response[0]); in mmmc_trace_after_send()
95 cmd->response[0]); in mmmc_trace_after_send()
97 cmd->response[1]); in mmmc_trace_after_send()
99 cmd->response[2]); in mmmc_trace_after_send()
101 cmd->response[3]); in mmmc_trace_after_send()
106 printf("\t\t\t\t\t%03d - ", i*4); in mmmc_trace_after_send()
107 ptr = (u8 *)&cmd->response[i]; in mmmc_trace_after_send()
110 printf("%02x ", *ptr--); in mmmc_trace_after_send()
116 cmd->response[0]); in mmmc_trace_after_send()
125 void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd) in mmc_trace_state() argument
129 status = (cmd->response[0] & MMC_STATUS_CURR_STATE) >> 9; in mmc_trace_state()
179 return mmc->legacy_speed; in mmc_mode2freq()
188 mmc->selected_mode = mode; in mmc_select_mode()
189 mmc->tran_speed = mmc_mode2freq(mmc, mode); in mmc_select_mode()
190 mmc->ddr_mode = mmc_is_mode_ddr(mode); in mmc_select_mode()
192 mmc->tran_speed / 1000000); in mmc_select_mode()
197 int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) in mmc_send_cmd() argument
201 mmmc_trace_before_send(mmc, cmd); in mmc_send_cmd()
202 ret = mmc->cfg->ops->send_cmd(mmc, cmd, data); in mmc_send_cmd()
203 mmmc_trace_after_send(mmc, cmd, ret); in mmc_send_cmd()
211 struct mmc_cmd cmd; in mmc_send_status() local
214 cmd.cmdidx = MMC_CMD_SEND_STATUS; in mmc_send_status()
215 cmd.resp_type = MMC_RSP_R1; in mmc_send_status()
217 cmd.cmdarg = mmc->rca << 16; in mmc_send_status()
220 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_send_status()
222 if ((cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) && in mmc_send_status()
223 (cmd.response[0] & MMC_STATUS_CURR_STATE) != in mmc_send_status()
227 if (cmd.response[0] & MMC_STATUS_MASK) { in mmc_send_status()
230 cmd.response[0]); in mmc_send_status()
232 return -ECOMM; in mmc_send_status()
234 } else if (--retries < 0) in mmc_send_status()
237 if (timeout-- <= 0) in mmc_send_status()
243 mmc_trace_state(mmc, &cmd); in mmc_send_status()
248 return -ETIMEDOUT; in mmc_send_status()
256 struct mmc_cmd cmd; in mmc_set_blocklen() local
259 if (mmc->ddr_mode) in mmc_set_blocklen()
262 cmd.cmdidx = MMC_CMD_SET_BLOCKLEN; in mmc_set_blocklen()
263 cmd.resp_type = MMC_RSP_R1; in mmc_set_blocklen()
264 cmd.cmdarg = len; in mmc_set_blocklen()
266 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_set_blocklen()
269 if (err && (mmc->quirks & MMC_QUIRK_RETRY_SET_BLOCKLEN)) { in mmc_set_blocklen()
276 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_set_blocklen()
279 } while (retries--); in mmc_set_blocklen()
319 struct mmc_cmd cmd; in mmc_send_tuning() local
324 if (mmc->bus_width == 8) { in mmc_send_tuning()
327 } else if (mmc->bus_width == 4) { in mmc_send_tuning()
331 return -EINVAL; in mmc_send_tuning()
336 cmd.cmdidx = opcode; in mmc_send_tuning()
337 cmd.cmdarg = 0; in mmc_send_tuning()
338 cmd.resp_type = MMC_RSP_R1; in mmc_send_tuning()
345 err = mmc_send_cmd(mmc, &cmd, &data); in mmc_send_tuning()
350 return -EIO; in mmc_send_tuning()
359 struct mmc_cmd cmd; in mmc_read_blocks() local
363 cmd.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK; in mmc_read_blocks()
365 cmd.cmdidx = MMC_CMD_READ_SINGLE_BLOCK; in mmc_read_blocks()
367 if (mmc->high_capacity) in mmc_read_blocks()
368 cmd.cmdarg = start; in mmc_read_blocks()
370 cmd.cmdarg = start * mmc->read_bl_len; in mmc_read_blocks()
372 cmd.resp_type = MMC_RSP_R1; in mmc_read_blocks()
376 data.blocksize = mmc->read_bl_len; in mmc_read_blocks()
379 if (mmc_send_cmd(mmc, &cmd, &data)) in mmc_read_blocks()
383 cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION; in mmc_read_blocks()
384 cmd.cmdarg = 0; in mmc_read_blocks()
385 cmd.resp_type = MMC_RSP_R1b; in mmc_read_blocks()
386 if (mmc_send_cmd(mmc, &cmd, NULL)) { in mmc_read_blocks()
388 pr_err("mmc fail to send stop cmd\n"); in mmc_read_blocks()
407 int dev_num = block_dev->devnum; in mmc_bread()
419 err = mmc_switch_part(mmc, block_dev->hwpart); in mmc_bread()
421 err = blk_dselect_hwpart(block_dev, block_dev->hwpart); in mmc_bread()
426 if ((start + blkcnt) > block_dev->lba) { in mmc_bread()
429 start + blkcnt, block_dev->lba); in mmc_bread()
434 if (mmc_set_blocklen(mmc, mmc->read_bl_len)) { in mmc_bread()
440 cur = (blocks_todo > mmc->cfg->b_max) ? in mmc_bread()
441 mmc->cfg->b_max : blocks_todo; in mmc_bread()
446 blocks_todo -= cur; in mmc_bread()
448 dst += cur * mmc->read_bl_len; in mmc_bread()
456 struct mmc_cmd cmd; in mmc_go_idle() local
461 cmd.cmdidx = MMC_CMD_GO_IDLE_STATE; in mmc_go_idle()
462 cmd.cmdarg = 0; in mmc_go_idle()
463 cmd.resp_type = MMC_RSP_NONE; in mmc_go_idle()
465 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_go_idle()
478 struct mmc_cmd cmd; in mmc_switch_voltage() local
488 cmd.cmdidx = SD_CMD_SWITCH_UHS18V; in mmc_switch_voltage()
489 cmd.cmdarg = 0; in mmc_switch_voltage()
490 cmd.resp_type = MMC_RSP_R1; in mmc_switch_voltage()
492 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_switch_voltage()
496 if (!mmc_host_is_spi(mmc) && (cmd.response[0] & MMC_STATUS_ERROR)) in mmc_switch_voltage()
497 return -EIO; in mmc_switch_voltage()
500 * The card should drive cmd and dat[0:3] low immediately in mmc_switch_voltage()
504 if (err == -ENOSYS) in mmc_switch_voltage()
507 return -ETIMEDOUT; in mmc_switch_voltage()
513 mmc_set_clock(mmc, mmc->clock, MMC_CLK_DISABLE); in mmc_switch_voltage()
521 mmc_set_clock(mmc, mmc->clock, MMC_CLK_ENABLE); in mmc_switch_voltage()
525 * dat[0:3] low. Wait for at least 1 ms according to spec in mmc_switch_voltage()
528 if (err == -ENOSYS) in mmc_switch_voltage()
531 return -ETIMEDOUT; in mmc_switch_voltage()
541 struct mmc_cmd cmd; in sd_send_op_cond() local
544 cmd.cmdidx = MMC_CMD_APP_CMD; in sd_send_op_cond()
545 cmd.resp_type = MMC_RSP_R1; in sd_send_op_cond()
546 cmd.cmdarg = 0; in sd_send_op_cond()
548 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_send_op_cond()
553 cmd.cmdidx = SD_CMD_APP_SEND_OP_COND; in sd_send_op_cond()
554 cmd.resp_type = MMC_RSP_R3; in sd_send_op_cond()
563 cmd.cmdarg = mmc_host_is_spi(mmc) ? 0 : in sd_send_op_cond()
564 (mmc->cfg->voltages & 0xff8000); in sd_send_op_cond()
566 if (mmc->version == SD_VERSION_2) in sd_send_op_cond()
567 cmd.cmdarg |= OCR_HCS; in sd_send_op_cond()
570 cmd.cmdarg |= OCR_S18R; in sd_send_op_cond()
572 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_send_op_cond()
577 if (cmd.response[0] & OCR_BUSY) in sd_send_op_cond()
580 if (timeout-- <= 0) in sd_send_op_cond()
581 return -EOPNOTSUPP; in sd_send_op_cond()
586 if (mmc->version != SD_VERSION_2) in sd_send_op_cond()
587 mmc->version = SD_VERSION_1_0; in sd_send_op_cond()
590 cmd.cmdidx = MMC_CMD_SPI_READ_OCR; in sd_send_op_cond()
591 cmd.resp_type = MMC_RSP_R3; in sd_send_op_cond()
592 cmd.cmdarg = 0; in sd_send_op_cond()
594 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_send_op_cond()
600 mmc->ocr = cmd.response[0]; in sd_send_op_cond()
603 if (uhs_en && !(mmc_host_is_spi(mmc)) && (cmd.response[0] & 0x41000000) in sd_send_op_cond()
611 mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS); in sd_send_op_cond()
612 mmc->rca = 0; in sd_send_op_cond()
619 struct mmc_cmd cmd; in mmc_send_op_cond_iter() local
622 cmd.cmdidx = MMC_CMD_SEND_OP_COND; in mmc_send_op_cond_iter()
623 cmd.resp_type = MMC_RSP_R3; in mmc_send_op_cond_iter()
624 cmd.cmdarg = 0; in mmc_send_op_cond_iter()
626 cmd.cmdarg = OCR_HCS | in mmc_send_op_cond_iter()
627 (mmc->cfg->voltages & in mmc_send_op_cond_iter()
628 (mmc->ocr & OCR_VOLTAGE_MASK)) | in mmc_send_op_cond_iter()
629 (mmc->ocr & OCR_ACCESS_MODE); in mmc_send_op_cond_iter()
631 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_send_op_cond_iter()
634 mmc->ocr = cmd.response[0]; in mmc_send_op_cond_iter()
652 if (mmc->ocr & OCR_BUSY) in mmc_send_op_cond()
655 mmc->op_cond_pending = 1; in mmc_send_op_cond()
661 struct mmc_cmd cmd; in mmc_complete_op_cond() local
666 mmc->op_cond_pending = 0; in mmc_complete_op_cond()
667 if (!(mmc->ocr & OCR_BUSY)) { in mmc_complete_op_cond()
676 if (mmc->ocr & OCR_BUSY) in mmc_complete_op_cond()
679 return -EOPNOTSUPP; in mmc_complete_op_cond()
685 cmd.cmdidx = MMC_CMD_SPI_READ_OCR; in mmc_complete_op_cond()
686 cmd.resp_type = MMC_RSP_R3; in mmc_complete_op_cond()
687 cmd.cmdarg = 0; in mmc_complete_op_cond()
689 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_complete_op_cond()
694 mmc->ocr = cmd.response[0]; in mmc_complete_op_cond()
697 mmc->version = MMC_VERSION_UNKNOWN; in mmc_complete_op_cond()
699 mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS); in mmc_complete_op_cond()
700 mmc->rca = 1; in mmc_complete_op_cond()
708 struct mmc_cmd cmd; in mmc_send_ext_csd() local
713 cmd.cmdidx = MMC_CMD_SEND_EXT_CSD; in mmc_send_ext_csd()
714 cmd.resp_type = MMC_RSP_R1; in mmc_send_ext_csd()
715 cmd.cmdarg = 0; in mmc_send_ext_csd()
722 err = mmc_send_cmd(mmc, &cmd, &data); in mmc_send_ext_csd()
730 struct mmc_cmd cmd; in __mmc_switch() local
735 cmd.cmdidx = MMC_CMD_SWITCH; in __mmc_switch()
736 cmd.resp_type = MMC_RSP_R1b; in __mmc_switch()
737 cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | in __mmc_switch()
742 ret = mmc_send_cmd(mmc, &cmd, NULL); in __mmc_switch()
745 retries--; in __mmc_switch()
796 return -EINVAL; in mmc_set_card_speed()
824 /* No high-speed support */ in mmc_set_card_speed()
826 return -ENOTSUPP; in mmc_set_card_speed()
834 u8 *ext_csd = mmc->ext_csd; in mmc_get_capabilities()
837 mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY); in mmc_get_capabilities()
842 /* Only version 4 supports high-speed */ in mmc_get_capabilities()
843 if (mmc->version < MMC_VERSION_4) in mmc_get_capabilities()
848 return -ENOTSUPP; in mmc_get_capabilities()
851 mmc->card_caps |= MMC_MODE_4BIT | MMC_MODE_8BIT; in mmc_get_capabilities()
854 mmc->cardtype = cardtype; in mmc_get_capabilities()
859 mmc->card_caps |= MMC_MODE_HS200; in mmc_get_capabilities()
865 mmc->card_caps |= MMC_MODE_HS400; in mmc_get_capabilities()
870 mmc->card_caps |= MMC_MODE_DDR_52MHz; in mmc_get_capabilities()
871 mmc->card_caps |= MMC_MODE_HS_52MHz; in mmc_get_capabilities()
874 mmc->card_caps |= MMC_MODE_HS; in mmc_get_capabilities()
884 mmc->capacity = mmc->capacity_user; in mmc_set_capacity()
888 mmc->capacity = mmc->capacity_boot; in mmc_set_capacity()
891 mmc->capacity = mmc->capacity_rpmb; in mmc_set_capacity()
897 mmc->capacity = mmc->capacity_gp[part_num - 4]; in mmc_set_capacity()
900 return -1; in mmc_set_capacity()
903 mmc_get_blk_desc(mmc)->lba = lldiv(mmc->capacity, mmc->read_bl_len); in mmc_set_capacity()
917 if (MMC_CAP(mmc->selected_mode) & forbidden) { in mmc_boot_part_access_chk()
919 mmc_mode_name(mmc->selected_mode), part_num); in mmc_boot_part_access_chk()
921 } else if (mmc->selected_mode != mmc->best_mode) { in mmc_boot_part_access_chk()
928 mmc->card_caps & ~forbidden); in mmc_boot_part_access_chk()
949 (mmc->part_config & ~PART_ACCESS_MASK) in mmc_switch_part()
956 if ((ret == 0) || ((ret == -ENODEV) && (part_num == 0))) { in mmc_switch_part()
958 mmc_get_blk_desc(mmc)->hwpart = part_num; in mmc_switch_part()
980 return -EINVAL; in mmc_hwpart_config()
982 if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4_41)) { in mmc_hwpart_config()
984 return -EMEDIUMTYPE; in mmc_hwpart_config()
987 if (!(mmc->part_support & PART_SUPPORT)) { in mmc_hwpart_config()
989 return -EMEDIUMTYPE; in mmc_hwpart_config()
992 if (!mmc->hc_wp_grp_size) { in mmc_hwpart_config()
994 return -EMEDIUMTYPE; in mmc_hwpart_config()
998 if (conf->user.enh_size) { in mmc_hwpart_config()
999 if (conf->user.enh_size % mmc->hc_wp_grp_size || in mmc_hwpart_config()
1000 conf->user.enh_start % mmc->hc_wp_grp_size) { in mmc_hwpart_config()
1003 return -EINVAL; in mmc_hwpart_config()
1006 enh_size_mult = conf->user.enh_size / mmc->hc_wp_grp_size; in mmc_hwpart_config()
1007 if (mmc->high_capacity) { in mmc_hwpart_config()
1008 enh_start_addr = conf->user.enh_start; in mmc_hwpart_config()
1010 enh_start_addr = (conf->user.enh_start << 9); in mmc_hwpart_config()
1019 if (conf->gp_part[pidx].size % mmc->hc_wp_grp_size) { in mmc_hwpart_config()
1022 return -EINVAL; in mmc_hwpart_config()
1024 gp_size_mult[pidx] = conf->gp_part[pidx].size / mmc->hc_wp_grp_size; in mmc_hwpart_config()
1025 if (conf->gp_part[pidx].size && conf->gp_part[pidx].enhanced) { in mmc_hwpart_config()
1031 if (part_attrs && ! (mmc->part_support & ENHNCD_SUPPORT)) { in mmc_hwpart_config()
1033 return -EMEDIUMTYPE; in mmc_hwpart_config()
1047 return -EMEDIUMTYPE; in mmc_hwpart_config()
1055 if (conf->user.wr_rel_change) { in mmc_hwpart_config()
1056 if (conf->user.wr_rel_set) in mmc_hwpart_config()
1062 if (conf->gp_part[pidx].wr_rel_change) { in mmc_hwpart_config()
1063 if (conf->gp_part[pidx].wr_rel_set) in mmc_hwpart_config()
1074 return -EMEDIUMTYPE; in mmc_hwpart_config()
1080 return -EPERM; in mmc_hwpart_config()
1086 /* Partitioning requires high-capacity size definitions */ in mmc_hwpart_config()
1096 /* update erase group size to be high-capacity */ in mmc_hwpart_config()
1097 mmc->erase_grp_size = in mmc_hwpart_config()
1134 /* The WR_REL_SET is a write-once register but shall be in mmc_hwpart_config()
1136 * write-once we can only write it when completing the in mmc_hwpart_config()
1168 if (mmc->cfg->ops->getcd) in mmc_getcd()
1169 cd = mmc->cfg->ops->getcd(mmc); in mmc_getcd()
1181 struct mmc_cmd cmd; in sd_switch() local
1185 cmd.cmdidx = SD_CMD_SWITCH_FUNC; in sd_switch()
1186 cmd.resp_type = MMC_RSP_R1; in sd_switch()
1187 cmd.cmdarg = (mode << 31) | 0xffffff; in sd_switch()
1188 cmd.cmdarg &= ~(0xf << (group * 4)); in sd_switch()
1189 cmd.cmdarg |= value << (group * 4); in sd_switch()
1196 return mmc_send_cmd(mmc, &cmd, &data); in sd_switch()
1202 struct mmc_cmd cmd; in sd_get_capabilities() local
1211 mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(SD_LEGACY); in sd_get_capabilities()
1217 cmd.cmdidx = MMC_CMD_APP_CMD; in sd_get_capabilities()
1218 cmd.resp_type = MMC_RSP_R1; in sd_get_capabilities()
1219 cmd.cmdarg = mmc->rca << 16; in sd_get_capabilities()
1221 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_get_capabilities()
1226 cmd.cmdidx = SD_CMD_APP_SEND_SCR; in sd_get_capabilities()
1227 cmd.resp_type = MMC_RSP_R1; in sd_get_capabilities()
1228 cmd.cmdarg = 0; in sd_get_capabilities()
1238 err = mmc_send_cmd(mmc, &cmd, &data); in sd_get_capabilities()
1241 if (timeout--) in sd_get_capabilities()
1247 mmc->scr[0] = __be32_to_cpu(scr[0]); in sd_get_capabilities()
1248 mmc->scr[1] = __be32_to_cpu(scr[1]); in sd_get_capabilities()
1250 switch ((mmc->scr[0] >> 24) & 0xf) { in sd_get_capabilities()
1252 mmc->version = SD_VERSION_1_0; in sd_get_capabilities()
1255 mmc->version = SD_VERSION_1_10; in sd_get_capabilities()
1258 mmc->version = SD_VERSION_2; in sd_get_capabilities()
1259 if ((mmc->scr[0] >> 15) & 0x1) in sd_get_capabilities()
1260 mmc->version = SD_VERSION_3; in sd_get_capabilities()
1263 mmc->version = SD_VERSION_1_0; in sd_get_capabilities()
1267 if (mmc->scr[0] & SD_DATA_4BIT) in sd_get_capabilities()
1268 mmc->card_caps |= MMC_MODE_4BIT; in sd_get_capabilities()
1271 if (mmc->version == SD_VERSION_1_0) in sd_get_capabilities()
1275 while (timeout--) { in sd_get_capabilities()
1282 /* The high-speed function is busy. Try again */ in sd_get_capabilities()
1287 /* If high-speed isn't supported, we return */ in sd_get_capabilities()
1289 mmc->card_caps |= MMC_CAP(SD_HS); in sd_get_capabilities()
1293 if (mmc->version < SD_VERSION_3) in sd_get_capabilities()
1298 mmc->card_caps |= MMC_CAP(UHS_SDR104); in sd_get_capabilities()
1300 mmc->card_caps |= MMC_CAP(UHS_SDR50); in sd_get_capabilities()
1302 mmc->card_caps |= MMC_CAP(UHS_SDR25); in sd_get_capabilities()
1304 mmc->card_caps |= MMC_CAP(UHS_SDR12); in sd_get_capabilities()
1306 mmc->card_caps |= MMC_CAP(UHS_DDR50); in sd_get_capabilities()
1319 /* SD version 1.00 and 1.01 does not support CMD 6 */ in sd_set_card_speed()
1320 if (mmc->version == SD_VERSION_1_0) in sd_set_card_speed()
1348 return -EINVAL; in sd_set_card_speed()
1356 return -ENOTSUPP; in sd_set_card_speed()
1364 struct mmc_cmd cmd; in sd_select_bus_width() local
1367 return -EINVAL; in sd_select_bus_width()
1369 cmd.cmdidx = MMC_CMD_APP_CMD; in sd_select_bus_width()
1370 cmd.resp_type = MMC_RSP_R1; in sd_select_bus_width()
1371 cmd.cmdarg = mmc->rca << 16; in sd_select_bus_width()
1373 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_select_bus_width()
1377 cmd.cmdidx = SD_CMD_APP_SET_BUS_WIDTH; in sd_select_bus_width()
1378 cmd.resp_type = MMC_RSP_R1; in sd_select_bus_width()
1380 cmd.cmdarg = 2; in sd_select_bus_width()
1382 cmd.cmdarg = 0; in sd_select_bus_width()
1383 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_select_bus_width()
1403 struct mmc_cmd cmd; in sd_read_ssr() local
1409 cmd.cmdidx = MMC_CMD_APP_CMD; in sd_read_ssr()
1410 cmd.resp_type = MMC_RSP_R1; in sd_read_ssr()
1411 cmd.cmdarg = mmc->rca << 16; in sd_read_ssr()
1413 err = mmc_send_cmd(mmc, &cmd, NULL); in sd_read_ssr()
1417 cmd.cmdidx = SD_CMD_APP_SD_STATUS; in sd_read_ssr()
1418 cmd.resp_type = MMC_RSP_R1; in sd_read_ssr()
1419 cmd.cmdarg = 0; in sd_read_ssr()
1427 err = mmc_send_cmd(mmc, &cmd, &data); in sd_read_ssr()
1429 if (timeout--) in sd_read_ssr()
1439 if ((au <= 9) || (mmc->version == SD_VERSION_3)) { in sd_read_ssr()
1440 mmc->ssr.au = sd_au_size[au]; in sd_read_ssr()
1446 mmc->ssr.erase_timeout = (et * 1000) / es; in sd_read_ssr()
1447 mmc->ssr.erase_offset = eo * 1000; in sd_read_ssr()
1503 return -ENOTSUPP; in mmc_execute_tuning()
1515 if (mmc->cfg->ops->set_ios) in mmc_set_ios()
1516 ret = mmc->cfg->ops->set_ios(mmc); in mmc_set_ios()
1525 if (clock > mmc->cfg->f_max) in mmc_set_clock()
1526 clock = mmc->cfg->f_max; in mmc_set_clock()
1528 if (clock < mmc->cfg->f_min) in mmc_set_clock()
1529 clock = mmc->cfg->f_min; in mmc_set_clock()
1532 mmc->clock = clock; in mmc_set_clock()
1533 mmc->clk_disable = disable; in mmc_set_clock()
1542 mmc->bus_width = width; in mmc_set_bus_width()
1589 return -EINVAL; in mmc_voltage_to_mv()
1596 if (mmc->signal_voltage == signal_voltage) in mmc_set_signal_voltage()
1599 mmc->signal_voltage = signal_voltage; in mmc_set_signal_voltage()
1656 if (caps & MMC_CAP(mwt->mode))
1664 bool uhs_en = (mmc->ocr & OCR_S18R) ? true : false; in sd_select_mode_and_width()
1672 mmc_dump_capabilities("host", mmc->host_caps); in sd_select_mode_and_width()
1676 caps = card_caps & mmc->host_caps; in sd_select_mode_and_width()
1685 if (*w & caps & mwt->widths) { in sd_select_mode_and_width()
1687 mmc_mode_name(mwt->mode), in sd_select_mode_and_width()
1689 mmc_mode2freq(mmc, mwt->mode) / 1000000); in sd_select_mode_and_width()
1698 err = sd_set_card_speed(mmc, mwt->mode); in sd_select_mode_and_width()
1703 mmc_select_mode(mmc, mwt->mode); in sd_select_mode_and_width()
1704 mmc_set_clock(mmc, mmc->tran_speed, in sd_select_mode_and_width()
1709 if (mwt->tuning && !mmc_host_is_spi(mmc)) { in sd_select_mode_and_width()
1711 mwt->tuning); in sd_select_mode_and_width()
1730 mmc_set_clock(mmc, mmc->tran_speed, in sd_select_mode_and_width()
1736 pr_err("unable to select a mode\n"); in sd_select_mode_and_width()
1737 return -ENOTSUPP; in sd_select_mode_and_width()
1748 const u8 *ext_csd = mmc->ext_csd; in mmc_read_and_compare_ext_csd()
1751 if (mmc->version < MMC_VERSION_4) in mmc_read_and_compare_ext_csd()
1771 return -EBADMSG; in mmc_read_and_compare_ext_csd()
1783 if (mmc->cardtype & (EXT_CSD_CARD_TYPE_HS200_1_8V | in mmc_set_lowest_voltage()
1786 if (mmc->cardtype & (EXT_CSD_CARD_TYPE_HS200_1_2V | in mmc_set_lowest_voltage()
1791 if (mmc->cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V) in mmc_set_lowest_voltage()
1794 if (mmc->cardtype & EXT_CSD_CARD_TYPE_DDR_1_2V) in mmc_set_lowest_voltage()
1805 best_match = 1 << (ffs(card_mask & allowed_mask) - 1); in mmc_set_lowest_voltage()
1812 return -ENOTSUPP; in mmc_set_lowest_voltage()
1859 if (caps & MMC_CAP(mwt->mode))
1885 mmc_set_clock(mmc, mmc->tran_speed, false); in mmc_select_hs400()
1907 err = mmc_set_clock(mmc, mmc->tran_speed, false); in mmc_select_hs400()
1916 return -ENOTSUPP; in mmc_select_hs400()
1924 if ((ddr == ecbv->is_ddr) && (caps & ecbv->cap))
1934 mmc_dump_capabilities("host", mmc->host_caps); in mmc_select_mode_and_width()
1938 card_caps &= mmc->host_caps; in mmc_select_mode_and_width()
1941 if (mmc->version < MMC_VERSION_4) in mmc_select_mode_and_width()
1944 if (!mmc->ext_csd) { in mmc_select_mode_and_width()
1946 return -ENOTSUPP; in mmc_select_mode_and_width()
1956 if (mmc->selected_mode == MMC_HS_200 || in mmc_select_mode_and_width()
1957 mmc->selected_mode == MMC_HS_400) in mmc_select_mode_and_width()
1961 mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE); in mmc_select_mode_and_width()
1964 for_each_supported_width(card_caps & mwt->widths, in mmc_select_mode_and_width()
1965 mmc_is_mode_ddr(mwt->mode), ecbw) { in mmc_select_mode_and_width()
1968 mmc_mode_name(mwt->mode), in mmc_select_mode_and_width()
1969 bus_width(ecbw->cap), in mmc_select_mode_and_width()
1970 mmc_mode2freq(mmc, mwt->mode) / 1000000); in mmc_select_mode_and_width()
1971 old_voltage = mmc->signal_voltage; in mmc_select_mode_and_width()
1972 err = mmc_set_lowest_voltage(mmc, mwt->mode, in mmc_select_mode_and_width()
1980 ecbw->ext_csd_bits & ~EXT_CSD_DDR_FLAG); in mmc_select_mode_and_width()
1983 mmc_set_bus_width(mmc, bus_width(ecbw->cap)); in mmc_select_mode_and_width()
1985 if (mwt->mode == MMC_HS_400) { in mmc_select_mode_and_width()
1988 printf("Select HS400 failed %d\n", err); in mmc_select_mode_and_width()
1993 err = mmc_set_card_speed(mmc, mwt->mode, false); in mmc_select_mode_and_width()
2002 if (ecbw->ext_csd_bits & EXT_CSD_DDR_FLAG) { in mmc_select_mode_and_width()
2006 ecbw->ext_csd_bits); in mmc_select_mode_and_width()
2012 mmc_select_mode(mmc, mwt->mode); in mmc_select_mode_and_width()
2013 mmc_set_clock(mmc, mmc->tran_speed, in mmc_select_mode_and_width()
2018 if (mwt->tuning) { in mmc_select_mode_and_width()
2020 mwt->tuning); in mmc_select_mode_and_width()
2043 pr_err("unable to select a mode\n"); in mmc_select_mode_and_width()
2045 return -ENOTSUPP; in mmc_select_mode_and_width()
2074 if (IS_SD(mmc) || mmc->version < MMC_VERSION_4) in mmc_startup_v4()
2077 if (!mmc->ext_csd) in mmc_startup_v4()
2085 if (!mmc->ext_csd) in mmc_startup_v4()
2086 mmc->ext_csd = ext_csd; in mmc_startup_v4()
2090 if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4)) in mmc_startup_v4()
2099 if (!mmc->ext_csd) in mmc_startup_v4()
2100 mmc->ext_csd = malloc(MMC_MAX_BLOCK_LEN); in mmc_startup_v4()
2101 if (!mmc->ext_csd) in mmc_startup_v4()
2102 return -ENOMEM; in mmc_startup_v4()
2103 memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN); in mmc_startup_v4()
2106 return -EINVAL; in mmc_startup_v4()
2108 mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]]; in mmc_startup_v4()
2110 if (mmc->version >= MMC_VERSION_4_2) { in mmc_startup_v4()
2122 mmc->capacity_user = capacity; in mmc_startup_v4()
2125 /* The partition data may be non-zero but it is only in mmc_startup_v4()
2128 * except for enabling the high-capacity group size in mmc_startup_v4()
2135 mmc->part_support = ext_csd[EXT_CSD_PARTITIONING_SUPPORT]; in mmc_startup_v4()
2138 mmc->part_config = ext_csd[EXT_CSD_PART_CONF]; in mmc_startup_v4()
2141 mmc->part_attr = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE]; in mmc_startup_v4()
2143 mmc->capacity_boot = ext_csd[EXT_CSD_BOOT_MULT] << 17; in mmc_startup_v4()
2145 mmc->capacity_rpmb = ext_csd[EXT_CSD_RPMB_MULT] << 17; in mmc_startup_v4()
2155 mmc->capacity_gp[i] = mult; in mmc_startup_v4()
2156 mmc->capacity_gp[i] *= in mmc_startup_v4()
2158 mmc->capacity_gp[i] *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; in mmc_startup_v4()
2159 mmc->capacity_gp[i] <<= 19; in mmc_startup_v4()
2164 mmc->enh_user_size = in mmc_startup_v4()
2168 mmc->enh_user_size *= ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; in mmc_startup_v4()
2169 mmc->enh_user_size *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; in mmc_startup_v4()
2170 mmc->enh_user_size <<= 19; in mmc_startup_v4()
2171 mmc->enh_user_start = in mmc_startup_v4()
2176 if (mmc->high_capacity) in mmc_startup_v4()
2177 mmc->enh_user_start <<= 9; in mmc_startup_v4()
2204 mmc->erase_grp_size = in mmc_startup_v4()
2210 * JEDEC Standard JESD84-B45, 6.2.4 in mmc_startup_v4()
2212 if (mmc->high_capacity && part_completed) { in mmc_startup_v4()
2218 mmc->capacity_user = capacity; in mmc_startup_v4()
2226 erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10; in mmc_startup_v4()
2227 erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5; in mmc_startup_v4()
2228 mmc->erase_grp_size = (erase_gsz + 1) in mmc_startup_v4()
2233 mmc->hc_wp_grp_size = 1024 in mmc_startup_v4()
2238 mmc->wr_rel_set = ext_csd[EXT_CSD_WR_REL_SET]; in mmc_startup_v4()
2242 if (mmc->ext_csd) { in mmc_startup_v4()
2244 free(mmc->ext_csd); in mmc_startup_v4()
2246 mmc->ext_csd = NULL; in mmc_startup_v4()
2256 struct mmc_cmd cmd; in mmc_startup() local
2261 cmd.cmdidx = MMC_CMD_SPI_CRC_ON_OFF; in mmc_startup()
2262 cmd.resp_type = MMC_RSP_R1; in mmc_startup()
2263 cmd.cmdarg = 1; in mmc_startup()
2264 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2271 cmd.cmdidx = mmc_host_is_spi(mmc) ? MMC_CMD_SEND_CID : in mmc_startup()
2272 MMC_CMD_ALL_SEND_CID; /* cmd not supported in spi */ in mmc_startup()
2273 cmd.resp_type = MMC_RSP_R2; in mmc_startup()
2274 cmd.cmdarg = 0; in mmc_startup()
2276 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2279 if (err && (mmc->quirks & MMC_QUIRK_RETRY_SEND_CID)) { in mmc_startup()
2286 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2289 } while (retries--); in mmc_startup()
2296 memcpy(mmc->cid, cmd.response, 16); in mmc_startup()
2303 if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */ in mmc_startup()
2304 cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR; in mmc_startup()
2305 cmd.cmdarg = mmc->rca << 16; in mmc_startup()
2306 cmd.resp_type = MMC_RSP_R6; in mmc_startup()
2308 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2314 mmc->rca = (cmd.response[0] >> 16) & 0xffff; in mmc_startup()
2317 /* Get the Card-Specific Data */ in mmc_startup()
2318 cmd.cmdidx = MMC_CMD_SEND_CSD; in mmc_startup()
2319 cmd.resp_type = MMC_RSP_R2; in mmc_startup()
2320 cmd.cmdarg = mmc->rca << 16; in mmc_startup()
2322 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2327 mmc->csd[0] = cmd.response[0]; in mmc_startup()
2328 mmc->csd[1] = cmd.response[1]; in mmc_startup()
2329 mmc->csd[2] = cmd.response[2]; in mmc_startup()
2330 mmc->csd[3] = cmd.response[3]; in mmc_startup()
2332 if (mmc->version == MMC_VERSION_UNKNOWN) { in mmc_startup()
2333 int version = (cmd.response[0] >> 26) & 0xf; in mmc_startup()
2337 mmc->version = MMC_VERSION_1_2; in mmc_startup()
2340 mmc->version = MMC_VERSION_1_4; in mmc_startup()
2343 mmc->version = MMC_VERSION_2_2; in mmc_startup()
2346 mmc->version = MMC_VERSION_3; in mmc_startup()
2349 mmc->version = MMC_VERSION_4; in mmc_startup()
2352 mmc->version = MMC_VERSION_1_2; in mmc_startup()
2358 freq = fbase[(cmd.response[0] & 0x7)]; in mmc_startup()
2359 mult = multipliers[((cmd.response[0] >> 3) & 0xf)]; in mmc_startup()
2361 mmc->legacy_speed = freq * mult; in mmc_startup()
2364 mmc->dsr_imp = ((cmd.response[1] >> 12) & 0x1); in mmc_startup()
2365 mmc->read_bl_len = 1 << ((cmd.response[1] >> 16) & 0xf); in mmc_startup()
2369 mmc->write_bl_len = mmc->read_bl_len; in mmc_startup()
2371 mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf); in mmc_startup()
2374 if (mmc->high_capacity) { in mmc_startup()
2375 csize = (mmc->csd[1] & 0x3f) << 16 in mmc_startup()
2376 | (mmc->csd[2] & 0xffff0000) >> 16; in mmc_startup()
2379 csize = (mmc->csd[1] & 0x3ff) << 2 in mmc_startup()
2380 | (mmc->csd[2] & 0xc0000000) >> 30; in mmc_startup()
2381 cmult = (mmc->csd[2] & 0x00038000) >> 15; in mmc_startup()
2384 mmc->capacity_user = (csize + 1) << (cmult + 2); in mmc_startup()
2385 mmc->capacity_user *= mmc->read_bl_len; in mmc_startup()
2386 mmc->capacity_boot = 0; in mmc_startup()
2387 mmc->capacity_rpmb = 0; in mmc_startup()
2389 mmc->capacity_gp[i] = 0; in mmc_startup()
2391 if (mmc->read_bl_len > MMC_MAX_BLOCK_LEN) in mmc_startup()
2392 mmc->read_bl_len = MMC_MAX_BLOCK_LEN; in mmc_startup()
2395 if (mmc->write_bl_len > MMC_MAX_BLOCK_LEN) in mmc_startup()
2396 mmc->write_bl_len = MMC_MAX_BLOCK_LEN; in mmc_startup()
2399 if ((mmc->dsr_imp) && (0xffffffff != mmc->dsr)) { in mmc_startup()
2400 cmd.cmdidx = MMC_CMD_SET_DSR; in mmc_startup()
2401 cmd.cmdarg = (mmc->dsr & 0xffff) << 16; in mmc_startup()
2402 cmd.resp_type = MMC_RSP_NONE; in mmc_startup()
2403 if (mmc_send_cmd(mmc, &cmd, NULL)) in mmc_startup()
2407 /* Select the card, and put it into Transfer Mode */ in mmc_startup()
2408 if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */ in mmc_startup()
2409 cmd.cmdidx = MMC_CMD_SELECT_CARD; in mmc_startup()
2410 cmd.resp_type = MMC_RSP_R1; in mmc_startup()
2411 cmd.cmdarg = mmc->rca << 16; in mmc_startup()
2412 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_startup()
2422 mmc->erase_grp_size = 1; in mmc_startup()
2424 mmc->part_config = MMCPART_NOAVAILABLE; in mmc_startup()
2430 err = mmc_set_capacity(mmc, mmc_get_blk_desc(mmc)->hwpart); in mmc_startup()
2435 mmc_set_clock(mmc, mmc->legacy_speed, false); in mmc_startup()
2443 err = sd_select_mode_and_width(mmc, mmc->card_caps); in mmc_startup()
2448 mmc_select_mode_and_width(mmc, mmc->card_caps); in mmc_startup()
2454 mmc->best_mode = mmc->selected_mode; in mmc_startup()
2457 if (mmc->ddr_mode) { in mmc_startup()
2458 mmc->read_bl_len = MMC_MAX_BLOCK_LEN; in mmc_startup()
2460 mmc->write_bl_len = MMC_MAX_BLOCK_LEN; in mmc_startup()
2466 bdesc->lun = 0; in mmc_startup()
2467 bdesc->hwpart = 0; in mmc_startup()
2468 bdesc->type = 0; in mmc_startup()
2469 bdesc->blksz = mmc->read_bl_len; in mmc_startup()
2470 bdesc->log2blksz = LOG2(bdesc->blksz); in mmc_startup()
2471 bdesc->lba = lldiv(mmc->capacity, mmc->read_bl_len); in mmc_startup()
2475 sprintf(bdesc->vendor, "Man %06x Snr %04x%04x", in mmc_startup()
2476 mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff), in mmc_startup()
2477 (mmc->cid[3] >> 16) & 0xffff); in mmc_startup()
2478 sprintf(bdesc->product, "%c%c%c%c%c%c", mmc->cid[0] & 0xff, in mmc_startup()
2479 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, in mmc_startup()
2480 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff, in mmc_startup()
2481 (mmc->cid[2] >> 24) & 0xff); in mmc_startup()
2482 sprintf(bdesc->revision, "%d.%d", (mmc->cid[2] >> 20) & 0xf, in mmc_startup()
2483 (mmc->cid[2] >> 16) & 0xf); in mmc_startup()
2485 bdesc->vendor[0] = 0; in mmc_startup()
2486 bdesc->product[0] = 0; in mmc_startup()
2487 bdesc->revision[0] = 0; in mmc_startup()
2499 struct mmc_cmd cmd; in mmc_send_if_cond() local
2502 cmd.cmdidx = SD_CMD_SEND_IF_COND; in mmc_send_if_cond()
2504 cmd.cmdarg = ((mmc->cfg->voltages & 0xff8000) != 0) << 8 | 0xaa; in mmc_send_if_cond()
2505 cmd.resp_type = MMC_RSP_R7; in mmc_send_if_cond()
2507 err = mmc_send_cmd(mmc, &cmd, NULL); in mmc_send_if_cond()
2512 if ((cmd.response[0] & 0xff) != 0xaa) in mmc_send_if_cond()
2513 return -EOPNOTSUPP; in mmc_send_if_cond()
2515 mmc->version = SD_VERSION_2; in mmc_send_if_cond()
2521 /* board-specific MMC power initializations. */
2533 ret = device_get_supply_regulator(mmc->dev, "vmmc-supply", in mmc_power_init()
2534 &mmc->vmmc_supply); in mmc_power_init()
2536 pr_debug("%s: No vmmc supply\n", mmc->dev->name); in mmc_power_init()
2538 ret = device_get_supply_regulator(mmc->dev, "vqmmc-supply", in mmc_power_init()
2539 &mmc->vqmmc_supply); in mmc_power_init()
2541 pr_debug("%s: No vqmmc supply\n", mmc->dev->name); in mmc_power_init()
2555 * - turn on Vdd (card power supply)
2556 * - configure the bus width and clock to minimal values
2577 if (mmc->vmmc_supply) { in mmc_power_on()
2578 int ret = regulator_set_enable(mmc->vmmc_supply, true); in mmc_power_on()
2593 if (mmc->vmmc_supply) { in mmc_power_off()
2594 int ret = regulator_set_enable(mmc->vmmc_supply, false); in mmc_power_off()
2613 * SD spec recommends at least 1ms of delay. Let's wait for 2ms in mmc_power_cycle()
2622 bool uhs_en = supports_uhs(mmc->cfg->host_caps); in mmc_get_op_cond()
2625 if (mmc->has_init) in mmc_get_op_cond()
2636 mmc->quirks = MMC_QUIRK_RETRY_SET_BLOCKLEN | in mmc_get_op_cond()
2649 mmc->host_caps &= ~UHS_CAPS; in mmc_get_op_cond()
2659 err = mmc->cfg->ops->init(mmc); in mmc_get_op_cond()
2663 mmc->ddr_mode = 0; in mmc_get_op_cond()
2676 mmc_get_blk_desc(mmc)->hwpart = 0; in mmc_get_op_cond()
2690 if (err == -ETIMEDOUT) { in mmc_get_op_cond()
2695 pr_err("Card did not respond to voltage select!\n"); in mmc_get_op_cond()
2697 return -EOPNOTSUPP; in mmc_get_op_cond()
2710 * all hosts are capable of 1 bit bus-width and able to use the legacy in mmc_start_init()
2713 mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(SD_LEGACY) | in mmc_start_init()
2723 no_card = no_card || (mmc->cfg->ops->init == NULL); in mmc_start_init()
2726 mmc->has_init = 0; in mmc_start_init()
2730 return -ENOMEDIUM; in mmc_start_init()
2736 mmc->init_in_progress = 1; in mmc_start_init()
2745 mmc->init_in_progress = 0; in mmc_complete_init()
2746 if (mmc->op_cond_pending) in mmc_complete_init()
2752 mmc->has_init = 0; in mmc_complete_init()
2754 mmc->has_init = 1; in mmc_complete_init()
2763 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc->dev); in mmc_init()
2765 upriv->mmc = mmc; in mmc_init()
2767 if (mmc->has_init) in mmc_init()
2772 if (!mmc->init_in_progress) in mmc_init()
2790 if (!mmc->has_init) in mmc_deinit()
2794 caps_filtered = mmc->card_caps & in mmc_deinit()
2801 caps_filtered = mmc->card_caps & in mmc_deinit()
2811 mmc->dsr = val; in mmc_set_dsr()
2815 /* CPU-specific MMC initializations */
2818 return -1; in cpu_mmc_init()
2821 /* board-specific MMC initializations. */
2824 return -1; in board_mmc_init()
2829 mmc->preinit = preinit; in mmc_set_preinit()
2850 if (ret == -ENODEV) in mmc_probe()
2856 pr_err("%s - probe failed: %d\n", dev->name, ret); in mmc_probe()
2910 return -EMEDIUMTYPE; in mmc_set_bkops_enable()