Skip to contentSkip to conversation

SD and SDHCI Fixes

PATCH Superseded [email protected] 2 participants 8 messages May 21, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover SD and SDHCI Fixes

From: Peter Crosthwaite <[email protected]>

Fixes found in SD and SDHCI found doing some corner case testing.

Peter Crosthwaite (5):
sd/sd.c: Fix "inquiry" ACMD41
sd/sdhci.c: Only reset data_count on new commands sd/sdhci: Fix Buffer Write Ready interrupt sd/sdhci.c: Fix bdata_read DPRINT message sd/sdhci:ADMA: fix interrupt

 hw/sd/sd.c    |  1 +
 hw/sd/sdhci.c | 28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 14 deletions(-)
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
#1 lore raw

PATCH 1/5 sd/sd.c: Fix "inquiry" ACMD41

From: Peter Crosthwaite <[email protected]>

the SD command ACMD41 can be used in a read only mode to query device state without doing the SD card initialisation. This is valid even which the device is already initialised. Fix the command to be responsive when in the ready state accordingly.

---

 hw/sd/sd.c | 1 +
 1 file changed, 1 insertion(+)
hw/sd/sd.c +1 -0
index 2e0ef3e..89bfb7a 100644
@@ -1277,6 +1277,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
         }
         switch (sd->state) {
         case sd_idle_state:
+        case sd_ready_state:
             /* We accept any voltage.  10000 V is nothing.  */
             if (req.arg)
                 sd->state = sd_ready_state;
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
Reviewed-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH arm-devs v1 1/5] sd/sd.c: Fix "inquiry" ACMD41

Quoted 8 lines · On 21 May 2013 07:50, <[email protected]> wrote:

From: Peter Crosthwaite <[email protected]>

the SD command ACMD41 can be used in a read only mode to query device state without doing the SD card initialisation. This is valid even which the device is already initialised. Fix the command to be responsive when in the ready state accordingly.

-- PMM

#3 lore raw

PATCH 2/5 sd/sdhci.c: Only reset data_count on new commands

In reply to [email protected]

From: Peter Crosthwaite <[email protected]>

The data_count variable was being reset on every transfer, including DMA transfer resumptions. This is incorrect, it should only be set on a new command.

Manifests as a bug when using ADMA and there is a timer delay between ADMA frames where the fifo is left in a non empty state.

---

 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +1 -1
index 91dc9b0..0a84540 100644
@@ -260,6 +260,7 @@ static void sdhci_send_command(SDHCIState *s)
     sdhci_update_irq(s);
 
     if (s->blksize && (s->cmdreg & SDHC_CMD_DATA_PRESENT)) {
+        s->data_count = 0;
         sdhci_do_data_transfer(s);
     }
 }
@@ -773,7 +774,6 @@ static void sdhci_do_adma(SDHCIState *s)
 static void sdhci_data_transfer(SDHCIState *s)
 {
     SDHCIClass *k = SDHCI_GET_CLASS(s);
-    s->data_count = 0;
 
     if (s->trnmod & SDHC_TRNS_DMA) {
         switch (SDHC_DMA_TYPE(s->hostctl)) {
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
#4 lore raw

PATCH 3/5 sd/sdhci: Fix Buffer Write Ready interrupt

In reply to [email protected]

From: Peter Crosthwaite <[email protected]>

This interrupt is not risen after the last block is written to sd. It is mutually exclusive with the end of transfer conditions. Fix.

---

 hw/sd/sdhci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/sd/sdhci.c +2 -3
index 0a84540..ea510b5 100644
@@ -405,15 +405,14 @@ static void sdhci_write_block_to_card(SDHCIState *s)
 
     /* Next data can be written through BUFFER DATORT register */
     s->prnsts |= SDHC_SPACE_AVAILABLE;
-    if (s->norintstsen & SDHC_NISEN_WBUFRDY) {
-        s->norintsts |= SDHC_NIS_WBUFRDY;
-    }
 
     /* Finish transfer if that was the last block of data */
     if ((s->trnmod & SDHC_TRNS_MULTI) == 0 ||
             ((s->trnmod & SDHC_TRNS_MULTI) &&
             (s->trnmod & SDHC_TRNS_BLK_CNT_EN) && (s->blkcnt == 0))) {
         SDHCI_GET_CLASS(s)->end_data_transfer(s);
+    } else if (s->norintstsen & SDHC_NISEN_WBUFRDY) {
+        s->norintsts |= SDHC_NIS_WBUFRDY;
     }
 
     /* Generate Block Gap Event if requested and if not the last block */
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
#5 lore raw

PATCH 4/5 sd/sdhci.c: Fix bdata_read DPRINT message

In reply to [email protected]

From: Peter Crosthwaite <[email protected]>

This message was printing out the data in decimal only, which is not very friendly to the debugging developer. Add hex variant in parenthesis to make it consistent with other similar messages in this module.

---

 hw/sd/sdhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/sd/sdhci.c +2 -1
index ea510b5..15345dc 100644
@@ -880,7 +880,8 @@ static uint32_t sdhci_read(SDHCIState *s, unsigned int offset, unsigned size)
     case  SDHC_BDATA:
         if (sdhci_buff_access_is_sequential(s, offset - SDHC_BDATA)) {
             ret = SDHCI_GET_CLASS(s)->bdata_read(s, size);
-            DPRINT_L2("read %ub: addr[0x%04x] -> %u\n", size, offset, ret);
+            DPRINT_L2("read %ub: addr[0x%04x] -> %u(0x%x)\n", size, offset,
+                      ret, ret);
             return ret;
         }
         break;
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
Reviewed-by on v1 4/5
#6 lore raw

Re: [Qemu-devel] [PATCH arm-devs v1 4/5] sd/sdhci.c: Fix bdata_read DPRINT message

Quoted 8 lines · On 21 May 2013 07:52, <[email protected]> wrote:

From: Peter Crosthwaite <[email protected]>

This message was printing out the data in decimal only, which is not very friendly to the debugging developer. Add hex variant in parenthesis to make it consistent with other similar messages in this module.

-- PMM

#7 lore raw

PATCH 5/5 sd/sdhci:ADMA: fix interrupt

In reply to [email protected]

From: Peter Crosthwaite <[email protected]>

The end of transfer check was occurring and potentially returning before the interrupt flag was checked. This means the interrupt will be missed if it occurs on the last packet. Fix by checking for the interrupt before checking for the end of transfer.

---

 hw/sd/sdhci.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
hw/sd/sdhci.c +9 -9
index 15345dc..e64899c 100644
@@ -730,6 +730,15 @@ static void sdhci_do_adma(SDHCIState *s)
             break;
         }
 
+        if (dscr.attr & SDHC_ADMA_ATTR_INT) {
+            DPRINT_L1("ADMA interrupt: admasysaddr=0x%lx\n", s->admasysaddr);
+            if (s->norintstsen & SDHC_NISEN_DMA) {
+                s->norintsts |= SDHC_NIS_DMA;
+            }
+
+            sdhci_update_irq(s);
+        }
+
         /* ADMA transfer terminates if blkcnt == 0 or by END attribute */
         if (((s->trnmod & SDHC_TRNS_BLK_CNT_EN) &&
                     (s->blkcnt == 0)) || (dscr.attr & SDHC_ADMA_ATTR_END)) {
@@ -752,15 +761,6 @@ static void sdhci_do_adma(SDHCIState *s)
             return;
         }
 
-        if (dscr.attr & SDHC_ADMA_ATTR_INT) {
-            DPRINT_L1("ADMA interrupt: admasysaddr=0x%lx\n", s->admasysaddr);
-            if (s->norintstsen & SDHC_NISEN_DMA) {
-                s->norintsts |= SDHC_NIS_DMA;
-            }
-
-            sdhci_update_irq(s);
-            return;
-        }
     }
 
     /* we have unfinished business - reschedule to continue ADMA */
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty