PERFORCE change 166473 for review
Ulf Lilleengen
lulf at FreeBSD.org
Thu Jul 23 20:40:11 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166473
Change 166473 by lulf at lulf_nobby on 2009/07/23 20:40:06
- Set the clock frequency correctly. Makes the device accept commands,
but it still fails to probe the card correctly.
Affected files ...
.. //depot/projects/avr32/src/sys/dev/mmc/atmel_mci.c#6 edit
.. //depot/projects/avr32/src/sys/dev/mmc/mmc.c#6 edit
Differences ...
==== //depot/projects/avr32/src/sys/dev/mmc/atmel_mci.c#6 (text+ko) ====
@@ -138,8 +138,8 @@
WR4(sc, MCI_CR, MCI_CR_MCIEN); /* Enable controller */
WR4(sc, MCI_IDR, 0xffffffff); /* Turn off interrupts */
- WR4(sc, MCI_DTOR, MCI_DTOR_DTOMUL_1M | 1);
- WR4(sc, MCI_MR, 0x834a); // XXX GROSS HACK FROM LINUX
+// WR4(sc, MCI_DTOR, MCI_DTOR_DTOMUL_1M | 1);
+// WR4(sc, MCI_MR, 0x834a); // XXX GROSS HACK FROM LINUX
WR4(sc, MCI_SDCR, 0); /* SLOT A, 1 bit bus */
}
@@ -200,8 +200,9 @@
goto out;
}
mci_clockfreq = devclk_get_rate(dev);
- sc->host.f_min = 375000; //XXX
- sc->host.f_max = mci_clockfreq / 2; /* Typically 65 MHz (XXX: too much?) */
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+ sc->host.f_min = DIV_ROUND_UP(mci_clockfreq, 512);
+ sc->host.f_max = mci_clockfreq / 2;
sc->host.host_ocr = MMC_OCR_320_330 | MMC_OCR_330_340;
if (sc->wire4)
sc->host.caps = MMC_CAP_4_BIT_DATA;
@@ -299,10 +300,19 @@
clkdiv = 0;
} else {
WR4(sc, MCI_CR, MCI_CR_MCIEN);
+
if ((mci_clockfreq % (ios->clock * 2)) == 0)
clkdiv = ((mci_clockfreq / ios->clock) / 2) - 1;
else
clkdiv = (mci_clockfreq / ios->clock) / 2;
+
+/*
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+ clkdiv = DIV_ROUND_UP(mci_clockfreq, 2 * host->f_min) - 1;
+ if (clkdiv > 255) {
+ printf("ATMEL MCI: clock too slow\n");
+ clkdiv = 255;
+ }*/
}
if (ios->bus_width == bus_width_4)
WR4(sc, MCI_SDCR, RD4(sc, MCI_SDCR) | MCI_SDCR_SDCBUS);
@@ -404,7 +414,7 @@
ier = MCI_SR_TXBUFE;
}
}
-// printf("CMDR %x ARGR %x with data\n", cmdr, cmd->arg);
+ printf("CMDR %x ARGR %x with data\n", cmdr, cmd->arg);
WR4(sc, MCI_ARGR, cmd->arg);
if (cmdr & MCI_CMDR_TRCMD_START) {
if (cmdr & MCI_CMDR_TRDIR) {
@@ -429,12 +439,12 @@
// assert locked
if (!(sc->flags & CMD_STARTED)) {
sc->flags |= CMD_STARTED;
-// printf("Starting CMD\n");
+ printf("Starting CMD\n");
atmel_mci_start_cmd(sc, req->cmd);
return;
}
if (!(sc->flags & STOP_STARTED) && req->stop) {
-// printf("Starting Stop\n");
+ printf("Starting Stop\n");
sc->flags |= STOP_STARTED;
atmel_mci_start_cmd(sc, req->stop);
return;
@@ -540,7 +550,7 @@
ATMEL_MCI_LOCK(sc);
sr = RD4(sc, MCI_SR) & RD4(sc, MCI_IMR);
-// printf("i 0x%x\n", sr);
+ printf("i 0x%x\n", sr);
cmd = sc->curcmd;
if (sr & MCI_SR_ERROR) {
// Ignore CRC errors on CMD2 and ACMD47, per relevant standards
@@ -562,40 +572,40 @@
}
} else {
if (sr & MCI_SR_TXBUFE) {
-// printf("TXBUFE\n");
+ printf("TXBUFE\n");
atmel_mci_xmit_done(sc);
}
if (sr & MCI_SR_RXBUFF) {
-// printf("RXBUFF\n");
+ printf("RXBUFF\n");
WR4(sc, MCI_IDR, MCI_SR_RXBUFF);
WR4(sc, MCI_IER, MCI_SR_CMDRDY);
}
if (sr & MCI_SR_ENDTX) {
-// printf("ENDTX\n");
+ printf("ENDTX\n");
}
if (sr & MCI_SR_ENDRX) {
-// printf("ENDRX\n");
+ printf("ENDRX\n");
atmel_mci_read_done(sc);
}
if (sr & MCI_SR_NOTBUSY) {
-// printf("NOTBUSY\n");
+ printf("NOTBUSY\n");
WR4(sc, MCI_IDR, MCI_SR_NOTBUSY);
WR4(sc, MCI_IER, MCI_SR_CMDRDY);
}
if (sr & MCI_SR_DTIP) {
-// printf("Data transfer in progress\n");
+ printf("Data transfer in progress\n");
}
if (sr & MCI_SR_BLKE) {
-// printf("Block transfer end\n");
+ printf("Block transfer end\n");
}
if (sr & MCI_SR_TXRDY) {
-// printf("Ready to transmit\n");
+ printf("Ready to transmit\n");
}
if (sr & MCI_SR_RXRDY) {
-// printf("Ready to receive\n");
+ printf("Ready to receive\n");
}
if (sr & MCI_SR_CMDRDY) {
-// printf("Command ready\n");
+ printf("Command ready\n");
done = 1;
cmd->error = MMC_ERR_NONE;
}
@@ -606,7 +616,7 @@
for (i = 0; i < ((cmd->flags & MMC_RSP_136) ? 4 : 1);
i++) {
cmd->resp[i] = RD4(sc, MCI_RSPR + i * 4);
-// printf("RSPR[%d] = %x\n", i, cmd->resp[i]);
+ printf("RSPR[%d] = %x\n", i, cmd->resp[i]);
}
}
atmel_mci_start(sc);
==== //depot/projects/avr32/src/sys/dev/mmc/mmc.c#6 (text+ko) ====
@@ -107,7 +107,7 @@
SYSCTL_NODE(_hw, OID_AUTO, mmc, CTLFLAG_RD, NULL, "mmc driver");
-static int mmc_debug;
+static int mmc_debug = 4;
SYSCTL_INT(_hw_mmc, OID_AUTO, debug, CTLFLAG_RW, &mmc_debug, 0, "Debug level");
/* bus entry points */
@@ -453,8 +453,9 @@
if (err != MMC_ERR_NONE)
break;
if ((cmd.resp[0] & MMC_OCR_CARD_BUSY) ||
- (ocr & MMC_OCR_VOLTAGE) == 0)
+ (ocr & MMC_OCR_VOLTAGE) == 0) {
break;
+ }
err = MMC_ERR_TIMEOUT;
mmc_ms_delay(10);
}
@@ -1304,7 +1305,7 @@
{
uint32_t ocr;
device_t dev;
- int err;
+ int err, err2;
dev = sc->dev;
if (mmcbr_get_power_mode(dev) != power_on) {
@@ -1320,10 +1321,12 @@
err = mmc_send_if_cond(sc, 1);
if ((bootverbose || mmc_debug) && err == 0)
device_printf(sc->dev, "SD 2.0 interface conditions: OK\n");
- if (mmc_send_app_op_cond(sc, err ? 0 : MMC_OCR_CCS, &ocr) !=
- MMC_ERR_NONE) {
- if (bootverbose || mmc_debug)
+ err2 = mmc_send_app_op_cond(sc, err ? 0 : MMC_OCR_CCS, &ocr);
+ if (err2 != MMC_ERR_NONE) {
+ if (bootverbose || mmc_debug) {
+ device_printf(sc->dev, "ERR: %d, err2: %d, ocr: 0x%x\n", err, err2, ocr);
device_printf(sc->dev, "SD probe: failed\n");
+ }
/*
* Failed, try MMC
*/
More information about the p4-projects
mailing list