From 24c098b6c2ac89a9a979a4cdf166c7cd1a254ab3 Mon Sep 17 00:00:00 2001 From: schulz Date: Sun, 17 Mar 2019 12:01:17 +0000 Subject: [PATCH] wait after sending a command git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@55846 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/devs/sdcard/sdcard_bus.c | 44 ++++++++++++++++++++++++++++++--------- rom/devs/sdcard/sdcard_ioops.c | 8 +++++++ rom/devs/sdcard/sdcard_mmcunit.c | 9 +++++--- rom/devs/sdcard/sdcard_sdscunit.c | 4 ++-- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/rom/devs/sdcard/sdcard_bus.c b/rom/devs/sdcard/sdcard_bus.c index 2a6fa5cc04..4ecfd2eb50 100644 --- a/rom/devs/sdcard/sdcard_bus.c +++ b/rom/devs/sdcard/sdcard_bus.c @@ -65,7 +65,7 @@ BOOL FNAME_SDCBUS(StartUnit)(struct sdcard_Unit *sdcUnit) sdcard_Udelay(1000); - if ((FNAME_SDCBUS(SendCmd)(sdcStartTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcStartTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) { if (FNAME_SDCUNIT(WaitStatus)(10000, sdcUnit) == -1) { @@ -81,7 +81,7 @@ BOOL FNAME_SDCBUS(StartUnit)(struct sdcard_Unit *sdcUnit) sdcStartTags[1].ti_Data = 1 << sdcUnit->sdcu_Bus->sdcb_SectorShift; sdcStartTags[2].ti_Data = MMC_RSP_R1; sdcStartTags[3].ti_Data = 0; - if ((FNAME_SDCBUS(SendCmd)(sdcStartTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcStartTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) { D(bug("[SDCard%02ld] %s: Blocklen set to %d\n", sdcUnit->sdcu_UnitNum, __PRETTY_FUNCTION__, sdcStartTags[1].ti_Data)); } @@ -133,7 +133,7 @@ ULONG FNAME_SDCUNIT(WaitStatus)(ULONG timeout, struct sdcard_Unit *sdcUnit) DFUNCS(bug("[SDCard%02ld] %s()\n", sdcUnit->sdcu_UnitNum, __PRETTY_FUNCTION__)); do { - if (FNAME_SDCBUS(SendCmd)(sdcStatusTags, sdcUnit->sdcu_Bus) != -1) + if ((FNAME_SDCBUS(SendCmd)(sdcStatusTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1) ) { if ((sdcStatusTags[3].ti_Data & MMC_STATUS_RDY_FOR_DATA) && (sdcStatusTags[3].ti_Data & MMC_STATUS_STATE_MASK) != MMC_STATUS_STATE_PRG) @@ -184,7 +184,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[0].ti_Data = MMC_CMD_GO_IDLE_STATE; sdcRegTags[1].ti_Data = 0; sdcRegTags[2].ti_Data = MMC_RSP_NONE; - if (FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) == -1) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) == -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) == -1)) { D(bug("[SDBus%02u] %s: Error: Card failed to go idle!\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__)); return FALSE; @@ -197,7 +197,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[2].ti_Data = MMC_RSP_R7; D(bug("[SDBus%02u] %s: Querying Interface conditions [%08x] ...\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdcRegTags[1].ti_Data)); - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) != -1)) { D(bug("[SDBus%02u] %s: Query Response = %08x\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdcRegTags[3].ti_Data)); D(bug("[SDBus%02u] %s: SD2.0 Compliant Card .. publishing high-capacity support\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__)); @@ -214,7 +214,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[1].ti_Data = 0; sdcRegTags[2].ti_Data = MMC_RSP_R1; - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) == -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) == -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) == -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) == -1)) { D(bug("[SDBus%02u] %s: App Command Failed\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__)); return FALSE; @@ -227,7 +227,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[2].ti_Data = MMC_RSP_R3; D(bug("[SDBus%02u] %s: Querying Operating conditions [%08x] ...\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdcRegTags[1].ti_Data)); - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) != -1)) { D(bug("[SDBus%02u] %s: Query Response = %08x\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdcRegTags[3].ti_Data)); sdcard_Udelay(1000); @@ -269,7 +269,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[1].ti_Data = 0; sdcRegTags[2].ti_Data = MMC_RSP_R2; sdcRegTags[3].ti_Data = (IPTR)sdcRsp136; - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) != -1)) { if (sdcRegTags[3].ti_Data) { @@ -289,7 +289,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[1].ti_Data = 0; sdcRegTags[2].ti_Data = MMC_RSP_R6; sdcRegTags[3].ti_Data = 0; - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) != -1)) { if ((sdcUnit = AllocVecPooled(LIBBASE->sdcard_MemPool, sizeof(struct sdcard_Unit))) != NULL) { @@ -310,7 +310,7 @@ BOOL FNAME_SDCBUS(RegisterUnit)(struct sdcard_Bus *bus) sdcRegTags[2].ti_Data = MMC_RSP_R2; sdcRegTags[3].ti_Data = (IPTR)sdcRsp136; D(bug("[SDBus%02u] %s: Querying Card Specific Data [%08x] ...\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdcRegTags[1].ti_Data)); - if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcRegTags, bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, bus) != -1)) { if (FNAME_SDCUNIT(WaitStatus)(10000, sdcUnit) == -1) { @@ -543,6 +543,13 @@ void FNAME_SDCBUS(SetPowerLevel)(ULONG supportedlvls, BOOL lowest, struct sdcard } } +#undef DFUNCS +#define DFUNCS(x) /*x*/ +#undef DTRANS +#define DTRANS(x) /*x*/ +#undef D +#define D(x) /*x*/ + ULONG FNAME_SDCBUS(SendCmd)(struct TagItem *CmdTags, struct sdcard_Bus *bus) { UWORD sdCommand = (UWORD)GetTagData(SDCARD_TAG_CMD, 0, CmdTags); @@ -562,6 +569,8 @@ ULONG FNAME_SDCBUS(SendCmd)(struct TagItem *CmdTags, struct sdcard_Bus *bus) sdDataFlags = GetTagData(SDCARD_TAG_DATAFLAGS, 0, CmdTags); }; +bug("SendCmd(%d,%d)\n", sdCommand, sdDataLen); + /* Dont wait for DATA inihibit for stop commands */ if (sdCommand != MMC_CMD_STOP_TRANSMISSION) sdcInhibitMask |= SDHCI_PS_DATA_INHIBIT; @@ -645,11 +654,21 @@ ULONG FNAME_SDCBUS(SendCmd)(struct TagItem *CmdTags, struct sdcard_Bus *bus) bus->sdcb_IOWriteWord(SDHCI_COMMAND, SDHCI_MAKE_CMD(sdCommand, sdCommandFlags), bus); } +//bug("Delay01Delay02\n"); + D(bug("[SDBus%02u] %s: CMD %02d Sent\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__, sdCommand)); return retVal; } +#undef DFUNCS +#define DFUNCS(x) /* */ +#undef DTRANS +#define DTRANS(x) /* */ +#undef D +#define D(x) /* */ + + ULONG FNAME_SDCBUS(FinishCmd)(struct TagItem *CmdTags, struct sdcard_Bus *bus) { struct TagItem *Response = NULL; @@ -856,6 +875,9 @@ ULONG FNAME_SDCBUS(Rsp136Unpack)(ULONG *buf, ULONG offset, const ULONG len) /********** BUS IRQ HANDLER **************/ +#undef DIRQ +#define DIRQ(x) x + void FNAME_SDCBUS(BusIRQ)(struct sdcard_Bus *bus, void *_unused) { BOOL error = FALSE; @@ -952,6 +974,8 @@ void FNAME_SDCBUS(BusIRQ)(struct sdcard_Bus *bus, void *_unused) DIRQ(bug("[SDBus%02u] %s: Done.\n", bus->sdcb_BusNum, __PRETTY_FUNCTION__)); } +#undef DIRQ +#define DIRQ(x) /* x */ /********** BUS MANAGEMENT TASK **************/ void FNAME_SDCBUS(BusTask)(struct sdcard_Bus *bus) diff --git a/rom/devs/sdcard/sdcard_ioops.c b/rom/devs/sdcard/sdcard_ioops.c index d535c6443d..c85939e37c 100644 --- a/rom/devs/sdcard/sdcard_ioops.c +++ b/rom/devs/sdcard/sdcard_ioops.c @@ -159,6 +159,10 @@ BYTE FNAME_SDCIO(ReadSector32)(struct sdcard_Unit *unit, ULONG block, { bug("[SDCard%02ld] %s: Failed to terminate Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__); } + if (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 100000, unit->sdcu_Bus) == -1) + { + bug("[SDCard%02ld] %s: Failed to ACK termination of Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__); + } } *act = sdcReadTags[5].ti_Data; } @@ -243,6 +247,10 @@ BYTE FNAME_SDCIO(ReadSector64)(struct sdcard_Unit *unit, UQUAD block, { bug("[SDCard%02ld] %s: Failed to terminate Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__); } + if (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 100000, unit->sdcu_Bus) == -1) + { + bug("[SDCard%02ld] %s: Failed to ACK termination of Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__); + } } *act = sdcReadTags[5].ti_Data; } diff --git a/rom/devs/sdcard/sdcard_mmcunit.c b/rom/devs/sdcard/sdcard_mmcunit.c index e49d0657a7..888b578fa9 100644 --- a/rom/devs/sdcard/sdcard_mmcunit.c +++ b/rom/devs/sdcard/sdcard_mmcunit.c @@ -30,8 +30,11 @@ ULONG FNAME_SDCUNIT(MMCSwitch)(UBYTE offset, UBYTE value, struct sdcard_Unit *sd if ((retVal = FNAME_SDCBUS(SendCmd)(sdcSwitchTags, sdcUnit->sdcu_Bus)) != -1) { - /* Wait for units ready status */ - FNAME_SDCUNIT(WaitStatus)(1000, sdcUnit); + if ((retVal = FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus)) != -1) + { + /* Wait for units ready status */ + FNAME_SDCUNIT(WaitStatus)(1000, sdcUnit); + } } return retVal; } @@ -75,7 +78,7 @@ ULONG FNAME_SDCUNIT(MMCChangeFrequency)(struct sdcard_Unit *sdcUnit) return -1; } - if ((FNAME_SDCBUS(SendCmd)(sdcChFreqTags, sdcUnit->sdcu_Bus) != -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcChFreqTags, sdcUnit->sdcu_Bus) != -1) && (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) != -1)) { if (sdcRespBuf[0xB9]) { diff --git a/rom/devs/sdcard/sdcard_sdscunit.c b/rom/devs/sdcard/sdcard_sdscunit.c index 32b55baee9..35fd2f8232 100644 --- a/rom/devs/sdcard/sdcard_sdscunit.c +++ b/rom/devs/sdcard/sdcard_sdscunit.c @@ -36,7 +36,7 @@ ULONG FNAME_SDCUNIT(SDSCSwitch)(BOOL test, int group, UBYTE value, APTR buf, str if ((retVal = FNAME_SDCBUS(SendCmd)(sdcSwitchTags, sdcUnit->sdcu_Bus)) != -1) { - retVal = FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, sdcUnit->sdcu_Bus); + retVal = FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus); } return retVal; } @@ -68,7 +68,7 @@ ULONG FNAME_SDCUNIT(SDSCChangeFrequency)(struct sdcard_Unit *sdcUnit) sdcChFreqTags[2].ti_Data = MMC_RSP_R1; sdcChFreqTags[4].ti_Tag = TAG_DONE; - if ((FNAME_SDCBUS(SendCmd)(sdcChFreqTags, sdcUnit->sdcu_Bus) == -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT, 1000, sdcUnit->sdcu_Bus) == -1)) + if ((FNAME_SDCBUS(SendCmd)(sdcChFreqTags, sdcUnit->sdcu_Bus) == -1) || (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 1000, sdcUnit->sdcu_Bus) == -1)) { D(bug("[SDCard%02ld] %s: App Command Failed\n", sdcUnit->sdcu_UnitNum, __PRETTY_FUNCTION__)); return -1; -- 2.11.4.GIT