Skip to content

Commit 87d2844

Browse files
fouwengLee Jones
authored andcommitted
mfd: rtsx: Do retry when DMA transfer error
The request should be resent when DMA transfer error occurred. For rts5227, the clock rate needs to be reduced when error occurred. Signed-off-by: Steven Feng <steven_feng@realsil.com.cn> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 9b79ff1 commit 87d2844

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎drivers/mfd/rtsx_pcr.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/platform_device.h>
3131
#include <linux/mfd/core.h>
3232
#include <linux/mfd/rtsx_pci.h>
33+
#include <linux/mmc/card.h>
3334
#include <asm/unaligned.h>
3435

3536
#include "rtsx_pcr.h"
@@ -452,8 +453,12 @@ int rtsx_pci_dma_transfer(struct rtsx_pcr *pcr, struct scatterlist *sglist,
452453
}
453454

454455
spin_lock_irqsave(&pcr->lock, flags);
455-
if (pcr->trans_result == TRANS_RESULT_FAIL)
456-
err = -EINVAL;
456+
if (pcr->trans_result == TRANS_RESULT_FAIL) {
457+
err = -EILSEQ;
458+
if (pcr->dma_error_count < RTS_MAX_TIMES_FREQ_REDUCTION)
459+
pcr->dma_error_count++;
460+
}
461+
457462
else if (pcr->trans_result == TRANS_NO_DEVICE)
458463
err = -ENODEV;
459464
spin_unlock_irqrestore(&pcr->lock, flags);
@@ -659,6 +664,13 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
659664
if (err < 0)
660665
return err;
661666

667+
/* Reduce card clock by 20MHz each time a DMA transfer error occurs */
668+
if (card_clock == UHS_SDR104_MAX_DTR &&
669+
pcr->dma_error_count &&
670+
PCI_PID(pcr) == RTS5227_DEVICE_ID)
671+
card_clock = UHS_SDR104_MAX_DTR -
672+
(pcr->dma_error_count * 20000000);
673+
662674
card_clock /= 1000000;
663675
pcr_dbg(pcr, "Switch card clock to %dMHz\n", card_clock);
664676

@@ -894,6 +906,7 @@ static irqreturn_t rtsx_pci_isr(int irq, void *dev_id)
894906
pcr->card_removed |= SD_EXIST;
895907
pcr->card_inserted &= ~SD_EXIST;
896908
}
909+
pcr->dma_error_count = 0;
897910
}
898911

899912
if (int_reg & MS_INT) {

‎include/linux/mfd/rtsx_pci.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,9 @@
850850

851851
#define rtsx_pci_init_cmd(pcr) ((pcr)->ci = 0)
852852

853+
#define RTS5227_DEVICE_ID 0x5227
854+
#define RTS_MAX_TIMES_FREQ_REDUCTION 8
855+
853856
struct rtsx_pcr;
854857

855858
struct pcr_handle {
@@ -957,6 +960,8 @@ struct rtsx_pcr {
957960

958961
int num_slots;
959962
struct rtsx_slot *slots;
963+
964+
u8 dma_error_count;
960965
};
961966

962967
#define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))

0 commit comments

Comments
 (0)