Deleted Added
full compact
mmc.c (187877) mmc.c (188044)
1/*-
2 * Copyright (c) 2006 Bernd Walter. All rights reserved.
3 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 37 unchanged lines hidden (view full) ---

46 * implication, estoppel or otherwise under any patent or other rights of the
47 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
48 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
49 * or the SD Card Association to disclose or distribute any technical
50 * information, know-how or other confidential information to any third party.
51 */
52
53#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Bernd Walter. All rights reserved.
3 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 37 unchanged lines hidden (view full) ---

46 * implication, estoppel or otherwise under any patent or other rights of the
47 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
48 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
49 * or the SD Card Association to disclose or distribute any technical
50 * information, know-how or other confidential information to any third party.
51 */
52
53#include <sys/cdefs.h>
54__FBSDID("$FreeBSD: head/sys/dev/mmc/mmc.c 187877 2009-01-28 23:18:21Z mav $");
54__FBSDID("$FreeBSD: head/sys/dev/mmc/mmc.c 188044 2009-02-03 04:28:45Z imp $");
55
56#include <sys/param.h>
57#include <sys/systm.h>
58#include <sys/kernel.h>
59#include <sys/malloc.h>
60#include <sys/lock.h>
61#include <sys/module.h>
62#include <sys/mutex.h>

--- 37 unchanged lines hidden (view full) ---

100 uint32_t sec_count; /* Card capacity in 512byte blocks */
101 uint32_t tran_speed; /* Max speed in normal mode */
102 uint32_t hs_tran_speed; /* Max speed in high speed mode */
103 uint32_t erase_sector; /* Card native erase sector size */
104};
105
106#define CMD_RETRIES 3
107
55
56#include <sys/param.h>
57#include <sys/systm.h>
58#include <sys/kernel.h>
59#include <sys/malloc.h>
60#include <sys/lock.h>
61#include <sys/module.h>
62#include <sys/mutex.h>

--- 37 unchanged lines hidden (view full) ---

100 uint32_t sec_count; /* Card capacity in 512byte blocks */
101 uint32_t tran_speed; /* Max speed in normal mode */
102 uint32_t hs_tran_speed; /* Max speed in high speed mode */
103 uint32_t erase_sector; /* Card native erase sector size */
104};
105
106#define CMD_RETRIES 3
107
108SYSCTL_NODE(_hw, OID_AUTO, mmc, CTLFLAG_RD, 0, "mmc driver");
108SYSCTL_NODE(_hw, OID_AUTO, mmc, CTLFLAG_RD, NULL, "mmc driver");
109
109
110int mmc_debug;
110static int mmc_debug;
111SYSCTL_INT(_hw_mmc, OID_AUTO, debug, CTLFLAG_RW, &mmc_debug, 0, "Debug level");
112
113/* bus entry points */
114static int mmc_probe(device_t dev);
115static int mmc_attach(device_t dev);
116static int mmc_detach(device_t dev);
117static int mmc_suspend(device_t dev);
118static int mmc_resume(device_t dev);

--- 446 unchanged lines hidden (view full) ---

565 set;
566 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
567 cmd.data = NULL;
568 err = mmc_wait_for_cmd(sc, &cmd, 0);
569 return (err);
570}
571
572static int
111SYSCTL_INT(_hw_mmc, OID_AUTO, debug, CTLFLAG_RW, &mmc_debug, 0, "Debug level");
112
113/* bus entry points */
114static int mmc_probe(device_t dev);
115static int mmc_attach(device_t dev);
116static int mmc_detach(device_t dev);
117static int mmc_suspend(device_t dev);
118static int mmc_resume(device_t dev);

--- 446 unchanged lines hidden (view full) ---

565 set;
566 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
567 cmd.data = NULL;
568 err = mmc_wait_for_cmd(sc, &cmd, 0);
569 return (err);
570}
571
572static int
573mmc_sd_switch(struct mmc_softc *sc, uint8_t mode, uint8_t grp, uint8_t value, uint8_t *res)
573mmc_sd_switch(struct mmc_softc *sc, uint8_t mode, uint8_t grp, uint8_t value,
574 uint8_t *res)
574{
575 int err;
576 struct mmc_command cmd;
577 struct mmc_data data;
578
579 memset(&cmd, 0, sizeof(struct mmc_command));
580 memset(&data, 0, sizeof(struct mmc_data));
575{
576 int err;
577 struct mmc_command cmd;
578 struct mmc_data data;
579
580 memset(&cmd, 0, sizeof(struct mmc_command));
581 memset(&data, 0, sizeof(struct mmc_data));
581
582 memset(res, 0, 64);
582 memset(res, 0, 64);
583
583 cmd.opcode = SD_SWITCH_FUNC;
584 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
584 cmd.opcode = SD_SWITCH_FUNC;
585 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
585 cmd.arg = mode << 31;
586 cmd.arg = mode << 31; /* 0 - check, 1 - set */
586 cmd.arg |= 0x00FFFFFF;
587 cmd.arg &= ~(0xF << (grp * 4));
588 cmd.arg |= value << (grp * 4);
589 cmd.data = &data;
590
591 data.data = res;
592 data.len = 64;
593 data.flags = MMC_DATA_READ;

--- 57 unchanged lines hidden (view full) ---

651 break;
652 case bus_timing_hs:
653 value = 1;
654 break;
655 default:
656 return (MMC_ERR_INVALID);
657 }
658 if (mmcbr_get_mode(sc->dev) == mode_sd)
587 cmd.arg |= 0x00FFFFFF;
588 cmd.arg &= ~(0xF << (grp * 4));
589 cmd.arg |= value << (grp * 4);
590 cmd.data = &data;
591
592 data.data = res;
593 data.len = 64;
594 data.flags = MMC_DATA_READ;

--- 57 unchanged lines hidden (view full) ---

652 break;
653 case bus_timing_hs:
654 value = 1;
655 break;
656 default:
657 return (MMC_ERR_INVALID);
658 }
659 if (mmcbr_get_mode(sc->dev) == mode_sd)
659 err = mmc_sd_switch(sc, 1, 0, value, switch_res);
660 err = mmc_sd_switch(sc, SD_SWITCH_MODE_SET, SD_SWITCH_GROUP1,
661 value, switch_res);
660 else
661 err = mmc_switch(sc, EXT_CSD_CMD_SET_NORMAL,
662 EXT_CSD_HS_TIMING, value);
663 return (err);
664}
665
666static int
667mmc_test_bus_width(struct mmc_softc *sc)

--- 471 unchanged lines hidden (view full) ---

1139 M_WAITOK | M_ZERO);
1140 if (!ivar)
1141 return;
1142 memcpy(ivar->raw_cid, raw_cid, sizeof(raw_cid));
1143 }
1144 if (mmcbr_get_ro(sc->dev))
1145 ivar->read_only = 1;
1146 ivar->bus_width = bus_width_1;
662 else
663 err = mmc_switch(sc, EXT_CSD_CMD_SET_NORMAL,
664 EXT_CSD_HS_TIMING, value);
665 return (err);
666}
667
668static int
669mmc_test_bus_width(struct mmc_softc *sc)

--- 471 unchanged lines hidden (view full) ---

1141 M_WAITOK | M_ZERO);
1142 if (!ivar)
1143 return;
1144 memcpy(ivar->raw_cid, raw_cid, sizeof(raw_cid));
1145 }
1146 if (mmcbr_get_ro(sc->dev))
1147 ivar->read_only = 1;
1148 ivar->bus_width = bus_width_1;
1149 ivar->timing = bus_timing_normal;
1147 ivar->mode = mmcbr_get_mode(sc->dev);
1148 if (ivar->mode == mode_sd) {
1149 mmc_decode_cid_sd(ivar->raw_cid, &ivar->cid);
1150 mmc_send_relative_addr(sc, &resp);
1151 ivar->rca = resp >> 16;
1152 /* Get card CSD. */
1153 mmc_send_csd(sc, ivar->rca, ivar->raw_csd);
1154 mmc_decode_csd_sd(ivar->raw_csd, &ivar->csd);
1155 ivar->sec_count = ivar->csd.capacity / MMC_SECTOR_SIZE;
1156 if (ivar->csd.csd_structure > 0)
1157 ivar->high_cap = 1;
1158 ivar->tran_speed = ivar->csd.tran_speed;
1159 ivar->erase_sector = ivar->csd.erase_sector *
1160 ivar->csd.write_bl_len / MMC_SECTOR_SIZE;
1161 /* Get card SCR. Card must be selected to fetch it. */
1162 mmc_select_card(sc, ivar->rca);
1163 mmc_app_send_scr(sc, ivar->rca, ivar->raw_scr);
1164 mmc_app_decode_scr(ivar->raw_scr, &ivar->scr);
1150 ivar->mode = mmcbr_get_mode(sc->dev);
1151 if (ivar->mode == mode_sd) {
1152 mmc_decode_cid_sd(ivar->raw_cid, &ivar->cid);
1153 mmc_send_relative_addr(sc, &resp);
1154 ivar->rca = resp >> 16;
1155 /* Get card CSD. */
1156 mmc_send_csd(sc, ivar->rca, ivar->raw_csd);
1157 mmc_decode_csd_sd(ivar->raw_csd, &ivar->csd);
1158 ivar->sec_count = ivar->csd.capacity / MMC_SECTOR_SIZE;
1159 if (ivar->csd.csd_structure > 0)
1160 ivar->high_cap = 1;
1161 ivar->tran_speed = ivar->csd.tran_speed;
1162 ivar->erase_sector = ivar->csd.erase_sector *
1163 ivar->csd.write_bl_len / MMC_SECTOR_SIZE;
1164 /* Get card SCR. Card must be selected to fetch it. */
1165 mmc_select_card(sc, ivar->rca);
1166 mmc_app_send_scr(sc, ivar->rca, ivar->raw_scr);
1167 mmc_app_decode_scr(ivar->raw_scr, &ivar->scr);
1165 /* Get card switch capabilities. */
1166 ivar->timing = bus_timing_normal;
1168 /* Get card switch capabilities (command class 10). */
1167 if ((ivar->scr.sda_vsn >= 1) &&
1168 (ivar->csd.ccc & (1<<10))) {
1169 if ((ivar->scr.sda_vsn >= 1) &&
1170 (ivar->csd.ccc & (1<<10))) {
1169 mmc_sd_switch(sc, 0, 0, 0xF, switch_res);
1171 mmc_sd_switch(sc, SD_SWITCH_MODE_CHECK,
1172 SD_SWITCH_GROUP1, SD_SWITCH_NOCHANGE,
1173 switch_res);
1170 if (switch_res[13] & 2) {
1171 ivar->timing = bus_timing_hs;
1174 if (switch_res[13] & 2) {
1175 ivar->timing = bus_timing_hs;
1172 ivar->hs_tran_speed = 50000000;
1176 ivar->hs_tran_speed = SD_MAX_HS;
1173 }
1174 }
1175 mmc_app_sd_status(sc, ivar->rca, ivar->raw_sd_status);
1176 mmc_app_decode_sd_status(ivar->raw_sd_status,
1177 &ivar->sd_status);
1178 if (ivar->sd_status.au_size != 0) {
1179 ivar->erase_sector =
1180 16 << ivar->sd_status.au_size;

--- 35 unchanged lines hidden (view full) ---

1216 if (sec_count != 0) {
1217 ivar->sec_count = sec_count;
1218 ivar->high_cap = 1;
1219 }
1220 /* Get card speed in high speed mode. */
1221 ivar->timing = bus_timing_hs;
1222 if (ivar->raw_ext_csd[EXT_CSD_CARD_TYPE]
1223 & EXT_CSD_CARD_TYPE_52)
1177 }
1178 }
1179 mmc_app_sd_status(sc, ivar->rca, ivar->raw_sd_status);
1180 mmc_app_decode_sd_status(ivar->raw_sd_status,
1181 &ivar->sd_status);
1182 if (ivar->sd_status.au_size != 0) {
1183 ivar->erase_sector =
1184 16 << ivar->sd_status.au_size;

--- 35 unchanged lines hidden (view full) ---

1220 if (sec_count != 0) {
1221 ivar->sec_count = sec_count;
1222 ivar->high_cap = 1;
1223 }
1224 /* Get card speed in high speed mode. */
1225 ivar->timing = bus_timing_hs;
1226 if (ivar->raw_ext_csd[EXT_CSD_CARD_TYPE]
1227 & EXT_CSD_CARD_TYPE_52)
1224 ivar->hs_tran_speed = 52000000;
1228 ivar->hs_tran_speed = MMC_TYPE_52_MAX_HS;
1225 else if (ivar->raw_ext_csd[EXT_CSD_CARD_TYPE]
1226 & EXT_CSD_CARD_TYPE_26)
1229 else if (ivar->raw_ext_csd[EXT_CSD_CARD_TYPE]
1230 & EXT_CSD_CARD_TYPE_26)
1227 ivar->hs_tran_speed = 26000000;
1231 ivar->hs_tran_speed = MMC_TYPE_26_MAX_HS;
1228 else
1229 ivar->hs_tran_speed = ivar->tran_speed;
1230 /* Find max supported bus width. */
1231 ivar->bus_width = mmc_test_bus_width(sc);
1232 mmc_select_card(sc, 0);
1233 /* Handle HC erase sector size. */
1234 if (ivar->raw_ext_csd[EXT_CSD_ERASE_GRP_SIZE] != 0) {
1235 ivar->erase_sector = 1024 *

--- 283 unchanged lines hidden (view full) ---

1519static driver_t mmc_driver = {
1520 "mmc",
1521 mmc_methods,
1522 sizeof(struct mmc_softc),
1523};
1524static devclass_t mmc_devclass;
1525
1526
1232 else
1233 ivar->hs_tran_speed = ivar->tran_speed;
1234 /* Find max supported bus width. */
1235 ivar->bus_width = mmc_test_bus_width(sc);
1236 mmc_select_card(sc, 0);
1237 /* Handle HC erase sector size. */
1238 if (ivar->raw_ext_csd[EXT_CSD_ERASE_GRP_SIZE] != 0) {
1239 ivar->erase_sector = 1024 *

--- 283 unchanged lines hidden (view full) ---

1523static driver_t mmc_driver = {
1524 "mmc",
1525 mmc_methods,
1526 sizeof(struct mmc_softc),
1527};
1528static devclass_t mmc_devclass;
1529
1530
1527DRIVER_MODULE(mmc, at91_mci, mmc_driver, mmc_devclass, 0, 0);
1528DRIVER_MODULE(mmc, sdhci, mmc_driver, mmc_devclass, 0, 0);
1531DRIVER_MODULE(mmc, at91_mci, mmc_driver, mmc_devclass, NULL, NULL);
1532DRIVER_MODULE(mmc, sdhci, mmc_driver, mmc_devclass, NULL, NULL);