Lines Matching +full:no +full:- +full:mmc +full:- +full:hs400
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * Group. This Simplified Specification is provided on a non-confidential
38 * Association, SD Group, SD-3C LLC or other third parties.
44 * is provided "AS-IS" without any representations or warranties of any
45 * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
47 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
48 * parties, which may result from its use. No license is granted by
50 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
51 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
53 * information, know-how or other confidential information to any third party.
69 #include <dev/mmc/bridge.h>
70 #include <dev/mmc/mmc_private.h>
71 #include <dev/mmc/mmc_subr.h>
72 #include <dev/mmc/mmcreg.h>
73 #include <dev/mmc/mmcbrvar.h>
74 #include <dev/mmc/mmcvar.h>
82 * Per-card data
91 u_char read_only; /* True when the device is read-only */
107 uint32_t quirks; /* Quirks as per mmc_quirk->quirks */
109 char card_sn_string[16];/* Formatted serial # for disk->d_ident */
134 static SYSCTL_NODE(_hw, OID_AUTO, mmc, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
135 "mmc driver");
159 #define MMC_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
160 #define MMC_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
162 mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->dev), \
163 "mmc", MTX_DEF)
164 #define MMC_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx);
165 #define MMC_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED);
166 #define MMC_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->sc_mtx, MA_NOTOWNED);
244 device_set_desc(dev, "MMC/SD bus");
254 sc->dev = dev;
258 sc->config_intrhook.ich_func = mmc_delayed_attach;
259 sc->config_intrhook.ich_arg = sc;
260 if (config_intrhook_establish(&sc->config_intrhook) != 0)
271 config_intrhook_drain(&sc->config_intrhook);
291 * We power down with the bus acquired here, mainly so that no device
292 * is selected any longer and sc->last_rca gets set to 0. Otherwise,
328 if (sc->owner)
329 panic("mmc: host bridge didn't serialize us.");
330 sc->owner = dev;
337 * unselect unless the bus code itself wants the mmc
341 rca = ivar->rca;
342 if (sc->last_rca != rca) {
348 sc->last_rca = rca;
356 * can trigger re-tuning (via a CRC error on the next
359 * we need to re-tune the host controller if devices
363 sc->child_count == 1)
369 (ivar->bus_width == bus_width_4) ? 4 :
370 (ivar->bus_width == bus_width_8) ? 8 : 1,
380 mmcbr_set_bus_width(busdev, ivar->bus_width);
390 "address %d failed to re-tune\n", rca);
398 if (sc->last_rca != 0) {
401 sc->last_rca = 0;
416 if (!sc->owner)
417 panic("mmc: releasing unowned bus.");
418 if (sc->owner != dev)
419 panic("mmc: you don't own the bus. game over.");
420 sc->owner = NULL;
438 i >= MMC_OCR_MIN_VOLTAGE_SHIFT; i--)
441 return (-1);
449 sc = (struct mmc_softc *)req->done_data;
451 req->flags |= MMC_REQ_DONE;
460 req->done = mmc_wakeup;
461 req->done_data = sc;
463 device_printf(sc->dev, "REQUEST: CMD%d arg %#x flags %#x",
464 req->cmd->opcode, req->cmd->arg, req->cmd->flags);
465 if (req->cmd->data) {
466 printf(" data %d\n", (int)req->cmd->data->len);
470 MMCBR_REQUEST(device_get_parent(sc->dev), sc->dev, req);
472 while ((req->flags & MMC_REQ_DONE) == 0)
473 msleep(req, &sc->sc_mtx, 0, "mmcreq", 0);
476 req->cmd->error != MMC_ERR_NONE)))
477 device_printf(sc->dev, "CMD%d RESULT: %d\n",
478 req->cmd->opcode, req->cmd->error);
491 KASSERT(sc->owner != NULL,
496 * Unless no device is selected or re-tuning is already ongoing,
497 * execute re-tuning if a) the bridge is requesting to do so and
498 * re-tuning hasn't been otherwise paused, or b) if a child asked
499 * to be re-tuned prior to pausing (see also mmc_retune_pause()).
501 if (__predict_false(sc->last_rca != 0 && sc->retune_ongoing == 0 &&
503 sc->retune_paused == 0) || sc->retune_needed == 1))) {
506 "Re-tuning with%s circuit reset required\n",
512 for (i = 0; i < sc->child_count; i++) {
513 ivar = device_get_ivars(sc->child_list[i]);
514 if (ivar->rca == sc->last_rca)
517 if (ivar->rca != sc->last_rca)
520 sc->retune_ongoing = 1;
522 sc->retune_ongoing = 0;
525 case MMC_ERR_FAILED: /* Re-tune error but still might work */
527 case MMC_ERR_BADCRC: /* Switch failure on HS400 recovery */
533 sc->retune_needed = 0;
550 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, retries);
568 dev = sc->dev;
578 mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
599 err = mmc_wait_for_app_cmd(sc->dev, sc->dev, 0, &cmd,
627 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
653 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
663 dev = sc->dev;
671 for (vccq = vccq_330; ; vccq--) {
688 device_t dev = sc->dev;
705 sc->retune_paused++;
708 sc->retune_paused--;
726 cmd.arg = mode << 31; /* 0 - check, 1 - set */
736 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
748 if (mmcbr_get_mode(sc->dev) == mode_sd) {
753 err = mmc_wait_for_app_cmd(sc->dev, sc->dev, ivar->rca, &cmd,
760 switch (ivar->bus_width) {
770 err = mmc_wait_for_app_cmd(sc->dev, sc->dev, ivar->rca, &cmd,
773 switch (ivar->bus_width) {
811 err = mmc_switch(sc->dev, sc->dev, ivar->rca,
813 ivar->cmd6_time, true);
828 dev = sc->dev;
830 bus_width = ivar->bus_width;
831 if (mmcbr_get_mode(dev) != mode_mmc || ivar->csd.spec_vers < 4 ||
836 ext_csd = ivar->raw_ext_csd;
876 device_printf(dev, "No power class support for VDD 0x%x\n",
891 return (mmc_switch(dev, dev, ivar->rca, EXT_CSD_CMD_SET_NORMAL,
892 EXT_CSD_POWER_CLASS, value, ivar->cmd6_time, true));
903 if (mmcbr_get_mode(sc->dev) == mode_sd) {
920 mmcbr_set_timing(sc->dev, timing);
921 mmcbr_update_ios(sc->dev);
941 err = mmc_switch(sc->dev, sc->dev, ivar->rca,
943 ivar->cmd6_time, false);
946 mmcbr_set_timing(sc->dev, timing);
947 mmcbr_update_ios(sc->dev);
948 err = mmc_switch_status(sc->dev, sc->dev, ivar->rca,
949 ivar->cmd6_time);
959 if (isset(&ivar->vccq_120, timing))
960 mmcbr_set_vccq(sc->dev, vccq_120);
961 else if (isset(&ivar->vccq_180, timing))
962 mmcbr_set_vccq(sc->dev, vccq_180);
964 mmcbr_set_vccq(sc->dev, vccq_330);
965 if (mmcbr_switch_vccq(sc->dev) != 0)
995 if (mmcbr_get_caps(sc->dev) & MMC_CAP_8_BIT_DATA) {
996 mmcbr_set_bus_width(sc->dev, bus_width_8);
997 mmcbr_update_ios(sc->dev);
999 sc->squelched++; /* Errors are expected, squelch reporting. */
1010 mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, 0);
1022 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, 0);
1023 sc->squelched--;
1025 mmcbr_set_bus_width(sc->dev, bus_width_1);
1026 mmcbr_update_ios(sc->dev);
1032 if (mmcbr_get_caps(sc->dev) & MMC_CAP_4_BIT_DATA) {
1033 mmcbr_set_bus_width(sc->dev, bus_width_4);
1034 mmcbr_update_ios(sc->dev);
1036 sc->squelched++; /* Errors are expected, squelch reporting. */
1047 mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, 0);
1059 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, 0);
1060 sc->squelched--;
1062 mmcbr_set_bus_width(sc->dev, bus_width_1);
1063 mmcbr_update_ios(sc->dev);
1074 const int i = (bit_len / 32) - (start / 32) - 1;
1079 retval |= bits[i - 1] << (32 - shift);
1080 return (retval & ((1llu << size) - 1));
1088 /* There's no version info, so we take it on faith */
1090 cid->mid = mmc_get_bits(raw_cid, 128, 120, 8);
1091 cid->oid = mmc_get_bits(raw_cid, 128, 104, 16);
1093 cid->pnm[i] = mmc_get_bits(raw_cid, 128, 96 - i * 8, 8);
1094 cid->pnm[5] = 0;
1095 cid->prv = mmc_get_bits(raw_cid, 128, 56, 8);
1096 cid->psn = mmc_get_bits(raw_cid, 128, 24, 32);
1097 cid->mdt_year = mmc_get_bits(raw_cid, 128, 12, 8) + 2000;
1098 cid->mdt_month = mmc_get_bits(raw_cid, 128, 8, 4);
1106 /* There's no version info, so we take it on faith */
1108 cid->mid = mmc_get_bits(raw_cid, 128, 120, 8);
1109 cid->oid = mmc_get_bits(raw_cid, 128, 104, 8);
1111 cid->pnm[i] = mmc_get_bits(raw_cid, 128, 96 - i * 8, 8);
1112 cid->pnm[6] = 0;
1113 cid->prv = mmc_get_bits(raw_cid, 128, 48, 8);
1114 cid->psn = mmc_get_bits(raw_cid, 128, 16, 32);
1115 cid->mdt_month = mmc_get_bits(raw_cid, 128, 12, 4);
1116 cid->mdt_year = mmc_get_bits(raw_cid, 128, 8, 4);
1118 cid->mdt_year += 2013;
1120 cid->mdt_year += 1997;
1134 * 22.5MHz/4bit/128-block
1137 * use as the disk->d_ident string.
1146 c1 = (ivar->cid.oid >> 8) & 0x0ff;
1147 c2 = ivar->cid.oid & 0x0ff;
1151 snprintf(oidstr, sizeof(oidstr), "0x%04x", ivar->cid.oid);
1152 snprintf(ivar->card_sn_string, sizeof(ivar->card_sn_string),
1153 "%08X", ivar->cid.psn);
1154 snprintf(ivar->card_id_string, sizeof(ivar->card_id_string),
1156 ivar->mode == mode_sd ? "SD" : "MMC", ivar->high_cap ? "HC" : "",
1157 ivar->cid.pnm, ivar->cid.prv >> 4, ivar->cid.prv & 0x0f,
1158 ivar->cid.psn, ivar->cid.mdt_month, ivar->cid.mdt_year,
1159 ivar->cid.mid, oidstr);
1186 csd->csd_structure = v = mmc_get_bits(raw_csd, 128, 126, 2);
1190 csd->tacc = (exp[e] * mant[m] + 9) / 10;
1191 csd->nsac = mmc_get_bits(raw_csd, 128, 104, 8) * 100;
1194 csd->tran_speed = exp[e] * 10000 * mant[m];
1195 csd->ccc = mmc_get_bits(raw_csd, 128, 84, 12);
1196 csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 128, 80, 4);
1197 csd->read_bl_partial = mmc_get_bits(raw_csd, 128, 79, 1);
1198 csd->write_blk_misalign = mmc_get_bits(raw_csd, 128, 78, 1);
1199 csd->read_blk_misalign = mmc_get_bits(raw_csd, 128, 77, 1);
1200 csd->dsr_imp = mmc_get_bits(raw_csd, 128, 76, 1);
1201 csd->vdd_r_curr_min =
1203 csd->vdd_r_curr_max =
1205 csd->vdd_w_curr_min =
1207 csd->vdd_w_curr_max =
1211 csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len;
1212 csd->erase_blk_en = mmc_get_bits(raw_csd, 128, 46, 1);
1213 csd->erase_sector = mmc_get_bits(raw_csd, 128, 39, 7) + 1;
1214 csd->wp_grp_size = mmc_get_bits(raw_csd, 128, 32, 7);
1215 csd->wp_grp_enable = mmc_get_bits(raw_csd, 128, 31, 1);
1216 csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3);
1217 csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4);
1218 csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1);
1223 csd->tacc = (exp[e] * mant[m] + 9) / 10;
1224 csd->nsac = mmc_get_bits(raw_csd, 128, 104, 8) * 100;
1227 csd->tran_speed = exp[e] * 10000 * mant[m];
1228 csd->ccc = mmc_get_bits(raw_csd, 128, 84, 12);
1229 csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 128, 80, 4);
1230 csd->read_bl_partial = mmc_get_bits(raw_csd, 128, 79, 1);
1231 csd->write_blk_misalign = mmc_get_bits(raw_csd, 128, 78, 1);
1232 csd->read_blk_misalign = mmc_get_bits(raw_csd, 128, 77, 1);
1233 csd->dsr_imp = mmc_get_bits(raw_csd, 128, 76, 1);
1234 csd->capacity = ((uint64_t)mmc_get_bits(raw_csd, 128, 48, 22) +
1236 csd->erase_blk_en = mmc_get_bits(raw_csd, 128, 46, 1);
1237 csd->erase_sector = mmc_get_bits(raw_csd, 128, 39, 7) + 1;
1238 csd->wp_grp_size = mmc_get_bits(raw_csd, 128, 32, 7);
1239 csd->wp_grp_enable = mmc_get_bits(raw_csd, 128, 31, 1);
1240 csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3);
1241 csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4);
1242 csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1);
1255 csd->csd_structure = mmc_get_bits(raw_csd, 128, 126, 2);
1256 csd->spec_vers = mmc_get_bits(raw_csd, 128, 122, 4);
1259 csd->tacc = exp[e] * mant[m] + 9 / 10;
1260 csd->nsac = mmc_get_bits(raw_csd, 128, 104, 8) * 100;
1263 csd->tran_speed = exp[e] * 10000 * mant[m];
1264 csd->ccc = mmc_get_bits(raw_csd, 128, 84, 12);
1265 csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 128, 80, 4);
1266 csd->read_bl_partial = mmc_get_bits(raw_csd, 128, 79, 1);
1267 csd->write_blk_misalign = mmc_get_bits(raw_csd, 128, 78, 1);
1268 csd->read_blk_misalign = mmc_get_bits(raw_csd, 128, 77, 1);
1269 csd->dsr_imp = mmc_get_bits(raw_csd, 128, 76, 1);
1270 csd->vdd_r_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 59, 3)];
1271 csd->vdd_r_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 56, 3)];
1272 csd->vdd_w_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 53, 3)];
1273 csd->vdd_w_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 50, 3)];
1276 csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len;
1277 csd->erase_blk_en = 0;
1278 csd->erase_sector = (mmc_get_bits(raw_csd, 128, 42, 5) + 1) *
1280 csd->wp_grp_size = mmc_get_bits(raw_csd, 128, 32, 5);
1281 csd->wp_grp_enable = mmc_get_bits(raw_csd, 128, 31, 1);
1282 csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3);
1283 csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4);
1284 csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1);
1300 scr->sda_vsn = mmc_get_bits(raw_scr, 64, 56, 4);
1301 scr->bus_widths = mmc_get_bits(raw_scr, 64, 48, 4);
1311 sd_status->bus_width = mmc_get_bits(raw_sd_status, 512, 510, 2);
1312 sd_status->secured_mode = mmc_get_bits(raw_sd_status, 512, 509, 1);
1313 sd_status->card_type = mmc_get_bits(raw_sd_status, 512, 480, 16);
1314 sd_status->prot_area = mmc_get_bits(raw_sd_status, 512, 448, 12);
1315 sd_status->speed_class = mmc_get_bits(raw_sd_status, 512, 440, 8);
1316 sd_status->perf_move = mmc_get_bits(raw_sd_status, 512, 432, 8);
1317 sd_status->au_size = mmc_get_bits(raw_sd_status, 512, 428, 4);
1318 sd_status->erase_size = mmc_get_bits(raw_sd_status, 512, 408, 16);
1319 sd_status->erase_timeout = mmc_get_bits(raw_sd_status, 512, 402, 6);
1320 sd_status->erase_offset = mmc_get_bits(raw_sd_status, 512, 400, 2);
1334 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
1350 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
1375 err = mmc_wait_for_app_cmd(sc->dev, sc->dev, rca, &cmd, CMD_RETRIES);
1401 err = mmc_wait_for_app_cmd(sc->dev, sc->dev, rca, &cmd, CMD_RETRIES);
1418 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
1433 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
1449 err = mmc_wait_for_cmd(sc->dev, sc->dev, &cmd, CMD_RETRIES);
1459 return (ivar->tran_speed);
1461 return (ivar->hs_tran_speed);
1502 return ("HS400");
1504 return ("HS400 with enhanced strobe");
1564 ivar->rca, newcard ? " added" : "");
1565 device_printf(dev, " card: %s\n", ivar->card_id_string);
1566 for (timing = bus_timing_max; timing > bus_timing_normal; timing--) {
1567 if (isset(&ivar->timings, timing))
1570 device_printf(dev, " quirks: %b\n", ivar->quirks, MMC_QUIRKS_FMT);
1572 (ivar->bus_width == bus_width_1 ? 1 :
1573 (ivar->bus_width == bus_width_4 ? 4 : 8)),
1577 ivar->sec_count, ivar->erase_sector,
1578 ivar->read_only ? ", read-only" : "");
1596 host_caps = mmcbr_get_caps(sc->dev);
1598 device_printf(sc->dev, "Probing cards\n");
1601 sc->squelched++; /* Errors are expected, squelch reporting. */
1603 sc->squelched--;
1607 device_printf(sc->dev, "Error reading CID %d\n", err);
1611 for (i = 0; i < sc->child_count; i++) {
1612 ivar = device_get_ivars(sc->child_list[i]);
1613 if (memcmp(ivar->raw_cid, raw_cid, sizeof(raw_cid)) ==
1620 device_printf(sc->dev,
1628 memcpy(ivar->raw_cid, raw_cid, sizeof(raw_cid));
1630 if (mmcbr_get_ro(sc->dev))
1631 ivar->read_only = 1;
1632 ivar->bus_width = bus_width_1;
1633 setbit(&ivar->timings, bus_timing_normal);
1634 ivar->mode = mmcbr_get_mode(sc->dev);
1635 if (ivar->mode == mode_sd) {
1636 mmc_decode_cid_sd(ivar->raw_cid, &ivar->cid);
1639 device_printf(sc->dev,
1643 ivar->rca = resp >> 16;
1645 err = mmc_send_csd(sc, ivar->rca, ivar->raw_csd);
1647 device_printf(sc->dev,
1652 device_printf(sc->dev,
1654 newcard ? "New c" : "C", ivar->raw_csd[0],
1655 ivar->raw_csd[1], ivar->raw_csd[2],
1656 ivar->raw_csd[3]);
1657 err = mmc_decode_csd_sd(ivar->raw_csd, &ivar->csd);
1659 device_printf(sc->dev, "Error decoding CSD\n");
1662 ivar->sec_count = ivar->csd.capacity / MMC_SECTOR_SIZE;
1663 if (ivar->csd.csd_structure > 0)
1664 ivar->high_cap = 1;
1665 ivar->tran_speed = ivar->csd.tran_speed;
1666 ivar->erase_sector = ivar->csd.erase_sector *
1667 ivar->csd.write_bl_len / MMC_SECTOR_SIZE;
1669 err = mmc_send_status(sc->dev, sc->dev, ivar->rca,
1672 device_printf(sc->dev,
1677 device_printf(sc->dev,
1683 err = mmc_select_card(sc, ivar->rca);
1685 device_printf(sc->dev,
1689 err = mmc_app_send_scr(sc, ivar->rca, ivar->raw_scr);
1691 device_printf(sc->dev,
1695 mmc_app_decode_scr(ivar->raw_scr, &ivar->scr);
1697 if ((ivar->scr.sda_vsn >= 1) &&
1698 (ivar->csd.ccc & (1 << 10))) {
1704 setbit(&ivar->timings, bus_timing_hs);
1705 ivar->hs_tran_speed = SD_HS_MAX;
1715 * attempt to blindly re-select them, we get timeout
1722 (void)mmc_select_card(sc, ivar->rca);
1723 (void)mmc_app_sd_status(sc, ivar->rca,
1724 ivar->raw_sd_status);
1725 mmc_app_decode_sd_status(ivar->raw_sd_status,
1726 &ivar->sd_status);
1727 if (ivar->sd_status.au_size != 0) {
1728 ivar->erase_sector =
1729 16 << ivar->sd_status.au_size;
1733 (ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4))
1734 ivar->bus_width = bus_width_4;
1738 ivar->rca = rca++;
1739 err = mmc_set_relative_addr(sc, ivar->rca);
1741 device_printf(sc->dev, "Error setting RCA %d\n", err);
1745 err = mmc_send_csd(sc, ivar->rca, ivar->raw_csd);
1747 device_printf(sc->dev, "Error getting CSD %d\n", err);
1751 device_printf(sc->dev,
1753 newcard ? "New c" : "C", ivar->raw_csd[0],
1754 ivar->raw_csd[1], ivar->raw_csd[2],
1755 ivar->raw_csd[3]);
1757 mmc_decode_csd_mmc(ivar->raw_csd, &ivar->csd);
1758 ivar->sec_count = ivar->csd.capacity / MMC_SECTOR_SIZE;
1759 ivar->tran_speed = ivar->csd.tran_speed;
1760 ivar->erase_sector = ivar->csd.erase_sector *
1761 ivar->csd.write_bl_len / MMC_SECTOR_SIZE;
1763 err = mmc_send_status(sc->dev, sc->dev, ivar->rca, &status);
1765 device_printf(sc->dev,
1770 device_printf(sc->dev,
1775 err = mmc_select_card(sc, ivar->rca);
1777 device_printf(sc->dev, "Error selecting card %d\n",
1782 rev = -1;
1783 /* Only MMC >= 4.x devices support EXT_CSD. */
1784 if (ivar->csd.spec_vers >= 4) {
1785 err = mmc_send_ext_csd(sc->dev, sc->dev,
1786 ivar->raw_ext_csd);
1788 device_printf(sc->dev,
1792 ext_csd = ivar->raw_ext_csd;
1797 ivar->sec_count = sec_count;
1798 ivar->high_cap = 1;
1801 ivar->bus_width = mmc_test_bus_width(sc);
1805 setbit(&ivar->timings, bus_timing_hs);
1806 ivar->hs_tran_speed = MMC_TYPE_HS_52_MAX;
1808 setbit(&ivar->timings, bus_timing_hs);
1809 ivar->hs_tran_speed = MMC_TYPE_HS_26_MAX;
1813 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1814 setbit(&ivar->vccq_120, bus_timing_mmc_ddr52);
1818 setbit(&ivar->timings, bus_timing_mmc_ddr52);
1819 setbit(&ivar->vccq_180, bus_timing_mmc_ddr52);
1823 setbit(&ivar->timings, bus_timing_mmc_hs200);
1824 setbit(&ivar->vccq_120, bus_timing_mmc_hs200);
1828 setbit(&ivar->timings, bus_timing_mmc_hs200);
1829 setbit(&ivar->vccq_180, bus_timing_mmc_hs200);
1833 ivar->bus_width == bus_width_8) {
1834 setbit(&ivar->timings, bus_timing_mmc_hs400);
1835 setbit(&ivar->vccq_120, bus_timing_mmc_hs400);
1839 ivar->bus_width == bus_width_8) {
1840 setbit(&ivar->timings, bus_timing_mmc_hs400);
1841 setbit(&ivar->vccq_180, bus_timing_mmc_hs400);
1847 ivar->bus_width == bus_width_8) {
1848 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1849 setbit(&ivar->vccq_120, bus_timing_mmc_hs400es);
1855 ivar->bus_width == bus_width_8) {
1856 setbit(&ivar->timings, bus_timing_mmc_hs400es);
1857 setbit(&ivar->vccq_180, bus_timing_mmc_hs400es);
1863 ivar->cmd6_time = 500 * 1000;
1865 ivar->cmd6_time = 10 *
1869 ivar->erase_sector = 1024 *
1871 err = mmc_switch(sc->dev, sc->dev, ivar->rca,
1875 ivar->cmd6_time, true);
1877 device_printf(sc->dev,
1885 mmc_decode_cid_mmc(ivar->raw_cid, &ivar->cid, rev >= 5);
1888 for (quirk = &mmc_quirks[0]; quirk->mid != 0x0; quirk++) {
1889 if ((quirk->mid == MMC_QUIRK_MID_ANY ||
1890 quirk->mid == ivar->cid.mid) &&
1891 (quirk->oid == MMC_QUIRK_OID_ANY ||
1892 quirk->oid == ivar->cid.oid) &&
1893 strncmp(quirk->pnm, ivar->cid.pnm,
1894 sizeof(ivar->cid.pnm)) == 0) {
1895 ivar->quirks = quirk->quirks;
1908 if (ivar->csd.read_bl_len != MMC_SECTOR_SIZE ||
1909 ivar->csd.write_bl_len != MMC_SECTOR_SIZE)
1915 mmc_log_card(sc->dev, ivar, newcard);
1918 child = device_add_child(sc->dev, NULL, DEVICE_UNIT_ANY);
1921 sc->child_list = realloc(sc->child_list,
1922 sizeof(device_t) * (sc->child_count + 1),
1924 sc->child_list[sc->child_count++] = child;
1926 device_printf(sc->dev, "Error adding child\n");
1934 * Not returning here when one MMC device could no be added
1940 mmcbr_get_mode(sc->dev) == mode_sd)
1951 if (sc->child_count == 0) {
1952 free(sc->child_list, M_DEVBUF);
1955 for (i = j = 0; i < sc->child_count; i++) {
1957 child = sc->child_list[j++];
1962 sc->child_list[i] = child;
1964 sc->child_list = realloc(sc->child_list, sizeof(device_t) *
1965 sc->child_count, M_DEVBUF, M_WAITOK);
1974 for (i = j = 0; i < sc->child_count; i++) {
1975 ivar = device_get_ivars(sc->child_list[i]);
1976 if (mmc_select_card(sc, ivar->rca) != MMC_ERR_NONE) {
1978 device_printf(sc->dev,
1980 ivar->rca);
1981 err = device_delete_child(sc->dev, sc->child_list[i]);
1990 if (sc->child_count == j)
1992 sc->child_count = j;
2005 for (i = j = 0; i < sc->child_count; i++) {
2006 ivar = device_get_ivars(sc->child_list[i]);
2008 device_printf(sc->dev,
2010 ivar->rca);
2011 err = device_delete_child(sc->dev, sc->child_list[i]);
2021 sc->child_count = j;
2033 dev = sc->dev;
2038 sc->squelched++; /* Errors are expected, squelch reporting. */
2043 device_printf(sc->dev, "Probing bus\n");
2047 device_printf(sc->dev,
2051 device_printf(sc->dev, "SD probe: failed\n");
2053 * Failed, try MMC
2058 device_printf(sc->dev,
2059 "MMC probe: failed\n");
2062 device_printf(sc->dev,
2063 "MMC probe: OK (OCR: 0x%08x)\n", ocr);
2065 device_printf(sc->dev, "SD probe: OK (OCR: 0x%08x)\n",
2067 sc->squelched--;
2083 device_printf(sc->dev, "Current OCR: 0x%08x\n",
2086 device_printf(sc->dev, "No compatible cards found on bus\n");
2117 bool changed, hs400;
2119 dev = sc->dev;
2124 for (i = 0; i < sc->child_count; i++) {
2125 ivar = device_get_ivars(sc->child_list[i]);
2126 if (isclr(&ivar->timings, max_timing) ||
2128 for (timing = max_timing - 1; timing >=
2129 bus_timing_normal; timing--) {
2130 if (isset(&ivar->timings, timing) &&
2154 * HS400 must be tuned in HS200 mode, so in case of HS400 we begin
2157 * switch to max_timing later. HS400ES requires no tuning and, thus,
2159 * speed mode as does HS400 (see mmc_switch_to_hs400()).
2161 hs400 = max_timing == bus_timing_mmc_hs400;
2162 timing = hs400 == true ? bus_timing_mmc_hs200 : max_timing;
2163 for (i = 0; i < sc->child_count; i++) {
2164 ivar = device_get_ivars(sc->child_list[i]);
2165 if ((ivar->timings & ~(1 << bus_timing_normal)) == 0)
2168 rca = ivar->rca;
2175 if (timing == bus_timing_mmc_hs200 || /* includes HS400 */
2184 if (timing == bus_timing_mmc_hs200) { /* includes HS400 */
2192 mmcbr_set_bus_width(dev, ivar->bus_width);
2223 mmcbr_set_bus_width(dev, ivar->bus_width);
2246 if (mmcbr_tune(dev, hs400) != 0) {
2252 if (hs400 == true && mmc_switch_to_hs400(sc, ivar, max_dtr,
2271 * Switch from HS200 to HS400 (either initially or for re-tuning) or directly
2272 * to HS400ES. This follows the sequences described in "6.6.2.3 HS400 timing
2282 dev = sc->dev;
2286 * before eventually switching to HS400/HS400ES; mmc_set_timing()
2289 mmcbr_set_clock(dev, ivar->hs_tran_speed);
2301 mmcbr_set_bus_width(dev, ivar->bus_width);
2304 /* Finally, switch to HS400/HS400ES mode. */
2314 * Switch from HS400 to HS200 (for re-tuning).
2323 dev = sc->dev;
2330 mmcbr_set_clock(dev, ivar->hs_tran_speed);
2342 mmcbr_set_bus_width(dev, ivar->bus_width);
2343 mmcbr_set_timing(sc->dev, bus_timing_hs);
2368 if (sc->retune_needed != 1 && sc->retune_paused != 0)
2375 * the devices in HS400 mode so periodic re-tuning isn't
2416 KASSERT(sc->owner != NULL,
2420 if (retune == true && sc->retune_paused == 0)
2421 sc->retune_needed = 1;
2422 sc->retune_paused++;
2434 KASSERT(sc->owner != NULL,
2437 KASSERT(sc->retune_paused != 0,
2438 ("%s: Re-tune pause count already at 0", __func__));
2440 sc->retune_paused--;
2446 device_t dev = sc->dev;
2472 *result = ivar->csd.spec_vers;
2475 *result = ivar->csd.dsr_imp;
2478 *result = ivar->sec_count;
2481 *result = ivar->rca;
2490 *result = ivar->read_only;
2493 *result = ivar->high_cap;
2496 *result = ivar->mode;
2499 *result = ivar->bus_width;
2502 *result = ivar->erase_sector;
2508 *result = ivar->cmd6_time;
2511 *result = ivar->quirks;
2514 *(char **)result = ivar->card_id_string;
2517 *(char **)result = ivar->card_sn_string;
2539 config_intrhook_disestablish(&sc->config_intrhook);
2563 /* MMC Bus interface */
2574 "mmc",
2579 MODULE_VERSION(mmc, MMC_VERSION);