Re: [PATCH 03/16] staging: m57621-mmc: delete driver from the tree.

2019-04-02 Thread Christian Lütke-Stetzkamp
On Wed, Apr 03, 2019 at 06:51:49AM +1100, NeilBrown wrote:
> People keep telling me that drivers/mmc/host/mtk-sd.c should be able to
> handle the same hardware as this driver, with a little bit of work.
> Unfortunately they haven't told me what the little bit of work involves.
> 
> Have you explored that possibility at all?  I might try to have a look
> if I can make time.

I have started to look into it, when I was working on that
driver. First sorry for me doing nothing in the last few
month. Generally the two drivers seem to be very similar, the main
difference is the code for tuning. In the staging driver. this is a
total mess. It tries to account for tuning itself, so it also tries to
account which command was executed (succesfully) before a tuning is
necessary and reexecutes it, when it was the APP_CMD. But there are
still some differences in the tuning code, that are not due to
handling it in the driver.

If have mainly understand how to remove the 'in driver handling' of
the tuning and thing I could prepare a patch for that. But the
differences in the tuning code itself, I do not understand
completely.

There are two other larger differences that I found during my
work. One is that drivers/mmc/host/mtk-sd.c has much more features,
like voltage and clock handling and some support for high speed
modes. I don't know if these features are required/useful for this
device. The other thing is the card detect handling. This driver is
doing the card detect / read only detection on its own, where the in
tree one just uses some default gpio functions there and I don't know
weather this must be changed or weather there is a gpio driver for the
mt7621.

That is all I currently remember. Hope it helps.

Christian
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 23/34] staging: mt7621-mmc: Remove unused variable from msdc_tune_request

2018-06-16 Thread Christian Lütke-Stetzkamp
The variable cmd in the function msdc_tune_request is set but never
used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e99a12002646..c5139a20e10f 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1556,12 +1556,10 @@ static int msdc_check_busy(struct mmc_host *mmc, struct 
msdc_host *host)
 static int msdc_tune_request(struct mmc_host *mmc, struct mmc_request *mrq)
 {
struct msdc_host *host = mmc_priv(mmc);
-   struct mmc_command *cmd;
struct mmc_data *data;
//u32 base = host->base;
int ret = 0, read;
 
-   cmd  = mrq->cmd;
data = mrq->cmd->data;
 
read = data->flags & MMC_DATA_READ ? 1 : 0;
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 08/34] staging: mt7621-mmc: Replace sdr_write32 with writel

2018-06-16 Thread Christian Lütke-Stetzkamp
The current code uses a macro (sdr_write32) for writing to hardware,
but it is only a writel with switched arguments, so replace it to get
nearer to upstream code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h |  1 -
 drivers/staging/mt7621-mmc/sd.c| 64 +-
 2 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 33fa59a019ec..e8e79aab52f8 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -950,7 +950,6 @@ struct msdc_host {
 #define sdr_read8(reg)readb(reg)
 #define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
-#define sdr_write32(reg, val) writel(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
 {
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 78a681a72f11..e6232f5ac6a8 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -174,7 +174,7 @@ static void msdc_reset_hw(struct msdc_host *host)
 #define msdc_clr_int() \
do {\
volatile u32 val = sdr_read32(MSDC_INT);\
-   sdr_write32(MSDC_INT, val); \
+   writel(val, MSDC_INT);  \
} while (0)
 
 #define msdc_clr_fifo() \
@@ -235,8 +235,8 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
 
 #define sdc_send_cmd(cmd, arg) \
do {\
-   sdr_write32(SDC_ARG, (arg));\
-   sdr_write32(SDC_CMD, (cmd));\
+   writel((arg), SDC_ARG); \
+   writel((cmd), SDC_CMD); \
} while (0)
 
 // can modify to read h/w register.
@@ -476,7 +476,7 @@ static void msdc_select_clksrc(struct msdc_host *host, 
unsigned char clksrc)
} else {
val &= ~0x3; val |= clksrc;
}
-   sdr_write32(MSDC_CLKSRC_REG, val);
+   writel(val, MSDC_CLKSRC_REG);
 
host->hclk = hclks[clksrc];
host->hw->clk_src = clksrc;
@@ -1044,14 +1044,14 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
case MSDC_MODE_DMA_BASIC:
BUG_ON(host->xfer_size > 65535);
BUG_ON(dma->sglen != 1);
-   sdr_write32(MSDC_DMA_SA, PHYSADDR(sg_dma_address(sg)));
+   writel(PHYSADDR(sg_dma_address(sg)), MSDC_DMA_SA);
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_LASTBUF, 1);
 //#if defined (CONFIG_RALINK_MT7620)
if (ralink_soc == MT762X_SOC_MT7620A)
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_XFERSZ, 
sg_dma_len(sg));
 //#elif defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628)
else
-   sdr_write32((void __iomem *)(RALINK_MSDC_BASE + 0xa8), 
sg_dma_len(sg));
+   writel(sg_dma_len(sg), (void __iomem 
*)(RALINK_MSDC_BASE + 0xa8));
 //#endif
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
  MSDC_BRUST_64B);
@@ -1094,7 +1094,7 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
  MSDC_BRUST_64B);
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
 
-   sdr_write32(MSDC_DMA_SA, PHYSADDR((u32)dma->gpd_addr));
+   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
break;
 
default:
@@ -1172,7 +1172,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
}
}
 
-   sdr_write32(SDC_BLK_NUM, data->blocks);
+   writel(data->blocks, SDC_BLK_NUM);
//msdc_clr_fifo();  /* no need */
 
msdc_dma_on();  /* enable DMA mode first!! */
@@ -1465,8 +1465,8 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct 
mmc_request *mrq)
cur_rxdly0 = (cur_dat0 << 24) | (cur_dat1 << 16) | (cur_dat2 << 
8) | (cur_dat3 << 0);
cur_rxdly1 = (cur_dat4 << 24) | (cur_dat5 << 16) | (cur_dat6 << 
8) | (cur_dat7 << 0);
 
-   sdr_write32(MSDC_DAT_RDDLY0, cur_rxdly0);
-   sdr_write32(MSDC_DAT_RDDLY1, cur_rxdly1);
+   writel(cur_rxdly0, MSDC_DAT_RDDLY0);
+   writel(cur_rxdly1, MSDC_DAT_RDDLY1);
 
} while (++rxdly < 32);
 
@@ -1555,7 +1555,7 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct 
mmc_request *mrq)
cur_dat3 = orig_dat3;
 
cur_rxdly0 = (cur_dat0 << 24) | (cur_dat1 << 16) | (cur_dat2 << 
8) | (cur_dat3 << 0);
-   sdr_write32(MSDC_DAT_RDDLY0, cur_rxdl

[PATCH v2 06/34] staging: mt7621-mmc: Remove unused macro msdc_txfifocnt

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_txfifocnt is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0f9cba918586..c6aced0c0a6a 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -147,7 +147,6 @@ static int msdc_rsp[] = {
7,  /* RESP_R1b */
 };
 
-#define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 20/34] staging: mt7621-mmc: Make msdc_clr_fifo a function and relax cpu

2018-06-16 Thread Christian Lütke-Stetzkamp
In the current code, msdc_clr_fifo is a macro and just busy waits for
a limited amount of time for the fifo clear to finish. That is not
correct, the programming manual hits, that the user should wait until
the bit is cleared by hardware and not a limited amount of time.

So the code is changed to a function, that also relaxes the cpu while
busy waiting.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index a506c7e19086..01a925ae662e 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -177,12 +177,14 @@ static void msdc_reset_hw(struct msdc_host *host)
writel(val, MSDC_INT);  \
} while (0)
 
-#define msdc_clr_fifo() \
-   do {\
-   int retry = 3, cnt = 1000;  \
-   sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR); \
-   msdc_retry(readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, cnt); \
-   } while (0)
+static void msdc_clr_fifo(struct msdc_host *host)
+{
+   void __iomem *base = host->base;
+
+   sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR);
+   while (readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR)
+   cpu_relax();
+}
 
 #define msdc_irq_save(val) \
do {\
@@ -554,7 +556,7 @@ static void msdc_abort_data(struct msdc_host *host)
ERR_MSG("Need to Abort.");
 
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
 
// need to check FIFO count 0 ?
@@ -945,7 +947,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
} else {
/* do basic: reset*/
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
cmd->error = msdc_tune_cmdrsp(host, cmd);
@@ -1131,7 +1133,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
}
 
writel(data->blocks, SDC_BLK_NUM);
-   //msdc_clr_fifo();  /* no need */
+   //msdc_clr_fifo(host);  /* no need */
 
msdc_dma_on();  /* enable DMA mode first!! */
init_completion(&host->xfer_done);
@@ -1165,7 +1167,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
data->error = -ETIMEDOUT;
 
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
spin_lock(&host->lock);
@@ -1868,7 +1870,7 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
if (intsts & datsts) {
/* do basic reset, or stop command will sdc_busy */
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
 
if (intsts & MSDC_INT_DATTMO) {
@@ -1917,7 +1919,7 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
IRQ_MSG("XXX CMD<%d> MSDC_INT_CMDTMO", 
cmd->opcode);
cmd->error = -ETIMEDOUT;
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
complete(&host->cmd_done);
@@ -2029,7 +2031,7 @@ static void msdc_init_hw(struct msdc_host *host)
 
/* Reset */
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
 
/* Disable card detection */
sdr_clr_bits(MSDC_PS, MSDC_PS_CDEN);
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 22/34] staging: mt7621-mmc: Remove unused macro MAX_BD_PER_GPD

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro MAX_BD_PER_GPD is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0e94bb0d5927..e99a12002646 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -91,7 +91,6 @@
 
 #define MAX_GPD_NUM (1 + 1)  /* one null gpd */
 #define MAX_BD_NUM  (1024)
-#define MAX_BD_PER_GPD  (MAX_BD_NUM)
 
 #define MAX_HW_SGMTS(MAX_BD_NUM)
 #define MAX_PHY_SGMTS   (MAX_BD_NUM)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 17/34] staging: mt7621-mmc: Remove unused field sglen from msdc_dma

2018-06-16 Thread Christian Lütke-Stetzkamp
The field sglen from struct msdc_dma is once set and never read, so
remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 2 --
 drivers/staging/mt7621-mmc/sd.c| 2 --
 2 files changed, 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index c8c5c349adf8..4b56d9a37b84 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -479,8 +479,6 @@ struct bd {
 };
 
 struct msdc_dma {
-   u32 sglen;   /* size of scatter list */
-
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
dma_addr_t gpd_addr; /* the physical address of gpd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 050c4a910aef..e1077068604d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1041,8 +1041,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
-   dma->sglen = sglen;
-
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 02/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_write8

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_write8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 7cfadb41a53d..4a69bc84bbd2 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -150,7 +150,6 @@ static int msdc_rsp[] = {
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 #define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
-#define msdc_fifo_write8(v)sdr_write8(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 #define msdc_fifo_read8()sdr_read8(MSDC_RXDATA)
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 01/34] staging: mt7621-mmc: Remove unused variable in msdc_command_resp

2018-06-16 Thread Christian Lütke-Stetzkamp
The variable resp in msdc_command_resp is once set and never read,
delete it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 648a2dd1436e..7cfadb41a53d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -886,13 +886,10 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
void __iomem *base = host->base;
u32 opcode = cmd->opcode;
//u32 rawcmd;
-   u32 resp;
u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
MSDC_INT_ACMD19_DONE;
 
-   resp = host->cmd_rsp;
-
BUG_ON(in_interrupt());
//init_completion(&host->cmd_done);
//sdr_set_bits(MSDC_INTEN, wints);
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 16/34] staging: mt7621-mmc: Remove unused field sg from msdc_dma

2018-06-16 Thread Christian Lütke-Stetzkamp
The field sg from struct msdc_dma is once set and never read, so
remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 8eb30d908f9d..c8c5c349adf8 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -480,7 +480,6 @@ struct bd {
 
 struct msdc_dma {
u32 sglen;   /* size of scatter list */
-   struct scatterlist *sg;  /* I/O scatter list */
 
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 923b0687918d..050c4a910aef 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1041,7 +1041,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
-   dma->sg = sg_cmd;
dma->sglen = sglen;
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 07/34] staging: mt7621-mmc: Remove unused macro msdc_rxfifocnt

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_rxfifocnt is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index c6aced0c0a6a..78a681a72f11 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -147,8 +147,6 @@ static int msdc_rsp[] = {
7,  /* RESP_R1b */
 };
 
-#define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
 #define msdc_retry(expr, retry, cnt) \
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 15/34] staging: mt7621-mmc: Refactor dma setup process

2018-06-16 Thread Christian Lütke-Stetzkamp
Current code uses two functions for dma setup, msdc_dma_config and
msdc_dma_setup. By now msdc_dma_setup is nearly empty and mainly calls
msdc_dma_config, so the later one can be inline into the first
one. While doing this there is also some refactoring done.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 34 +-
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 3066fa3799ac..923b0687918d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1030,18 +1030,24 @@ static u8 msdc_dma_calcs(u8 *buf, u32 len)
return 0xFF - (u8)sum;
 }
 
-/* gpd bd setup + dma registers */
-static void msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma)
+static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
+  struct scatterlist *sg_cmd, unsigned int sglen)
 {
void __iomem *base = host->base;
-   //u32 i, j, num, bdlen, arg, xfersz;
-   u32 j, num;
struct scatterlist *sg;
struct gpd *gpd;
struct bd *bd;
+   u32 j, num;
+
+   BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
+
+   dma->sg = sg_cmd;
+   dma->sglen = sglen;
+
+   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
+   num = (sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
BUG_ON(num != 1);
 
gpd = dma->gpd;
@@ -1055,13 +1061,13 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
 
/* modify bd*/
-   for_each_sg(dma->sg, sg, dma->sglen, j) {
+   for_each_sg(sg_cmd, sg, sglen, j) {
bd[j].blkpad = 0;
bd[j].dwpad = 0;
bd[j].ptr = (void *)sg_dma_address(sg);
bd[j].buflen = sg_dma_len(sg);
 
-   if (j == dma->sglen - 1)
+   if (j == sglen - 1)
bd[j].eol = 1;  /* the last bd */
else
bd[j].eol = 0;
@@ -1080,20 +1086,6 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
N_MSG(DMA, "DMA_CTRL = 0x%x", readl(MSDC_DMA_CTRL));
N_MSG(DMA, "DMA_CFG  = 0x%x", readl(MSDC_DMA_CFG));
N_MSG(DMA, "DMA_SA   = 0x%x", readl(MSDC_DMA_SA));
-
-}
-
-static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
-  struct scatterlist *sg, unsigned int sglen)
-{
-   BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
-
-   dma->sg = sg;
-   dma->sglen = sglen;
-
-   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", dma->sglen, host->xfer_size);
-
-   msdc_dma_config(host, dma);
 }
 
 static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 27/34] staging: mt7621-mmc: Remove unused define IRQ_SDC

2018-06-16 Thread Christian Lütke-Stetzkamp
The define IRQ_SDC is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 101ceca2ee4c..31ee9c533f35 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -50,13 +50,11 @@
 #include "dbg.h"
 #include "mt6575_sd.h"
 
-//#define IRQ_SDC 14   //MT7620 /*FIXME*/
 #ifdef CONFIG_SOC_MT7621
 #define RALINK_SYSCTL_BASE 0xbe00
 #else
 #define RALINK_SYSCTL_BASE 0xb000
 #endif
-#define IRQ_SDC22  /*FIXME*/
 
 #define DRV_NAME"mtk-sd"
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 32/34] staging: mt7621-mmc: Factor out from msdc_command_start()

2018-06-16 Thread Christian Lütke-Stetzkamp
Currently msdc_command_start does multiple things and is hard to read,
so factor out the finding of the response type.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 40 +---
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 93f14c9694b9..f7df3221a302 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -705,25 +705,11 @@ static void msdc_pm(pm_message_t state, void *data)
 }
 #endif
 
-/*--*/
-/* mmc_host_ops members  */
-/*--*/
-static unsigned int msdc_command_start(struct msdc_host   *host,
-  struct mmc_command *cmd,
-  unsigned long   timeout)
+static inline u32 msdc_cmd_find_resp(struct mmc_command *cmd)
 {
u32 opcode = cmd->opcode;
-   u32 rawcmd;
-   u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
-   MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
-   MSDC_INT_ACMD19_DONE;
-
u32 resp;
-   unsigned long tmo;
 
-   /* Protocol layer does not provide response type, but our hardware needs
-* to know exact type, not just size!
-*/
if (opcode == MMC_SEND_OP_COND || opcode == SD_APP_OP_COND) {
resp = RESP_R3;
} else if (opcode == MMC_SET_RELATIVE_ADDR) {
@@ -759,6 +745,30 @@ static unsigned int msdc_command_start(struct msdc_host   
*host,
}
}
 
+   return resp;
+}
+
+/*--*/
+/* mmc_host_ops members  */
+/*--*/
+static unsigned int msdc_command_start(struct msdc_host   *host,
+  struct mmc_command *cmd,
+  unsigned long   timeout)
+{
+   u32 opcode = cmd->opcode;
+   u32 rawcmd;
+   u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
+   MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
+   MSDC_INT_ACMD19_DONE;
+
+   u32 resp;
+   unsigned long tmo;
+
+   /* Protocol layer does not provide response type, but our hardware needs
+* to know exact type, not just size!
+*/
+   resp = msdc_cmd_find_resp(cmd);
+
cmd->error = 0;
/* rawcmd :
 * vol_swt << 30 | auto_cmd << 28 | blklen << 16 | go_irq << 15 |
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 30/34] staging: mt7621-mmc: Remove unused macro is_card_present

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro is_card_present is unused and also a duplicate of a macro in
mmc, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 45d9b62f4a58..cfe7517f8bdf 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -218,10 +218,6 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
writel((cmd), host->base + SDC_CMD);\
} while (0)
 
-// can modify to read h/w register.
-//#define is_card_present(h)   ((readl(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
-#define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
-
 /* +++ by chhung */
 #ifndef __ASSEMBLY__
 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fff)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 34/34] staging: mt7621-mmc: Find response of SD_APP_OP_COND by default

2018-06-16 Thread Christian Lütke-Stetzkamp
The response type of the SD_APP_OP_COND command is correctly
determined using the mmc_resp_type macro, because the only use of that
opcode, mmc_send_app_op_cond, correctly places MMC_RSP_R3 in cmd.flags.

So there is no need to treat that opcode separately.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 69123cfd7309..04d23cc7cd4a 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,9 +710,7 @@ static inline u32 msdc_cmd_find_resp(struct mmc_command 
*cmd)
u32 opcode = cmd->opcode;
u32 resp;
 
-   if (opcode == SD_APP_OP_COND) {
-   resp = RESP_R3;
-   } else if (opcode == MMC_SET_RELATIVE_ADDR) {
+   if (opcode == MMC_SET_RELATIVE_ADDR) {
resp = (mmc_cmd_type(cmd) == MMC_CMD_BCR) ? RESP_R6 : RESP_R1;
} else if (opcode == MMC_FAST_IO) {
resp = RESP_R4;
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 31/34] staging: mt7621-mmc: Remove unused argument from msdc_do_command

2018-06-16 Thread Christian Lütke-Stetzkamp
The argument tune of msdc_do_command is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index cfe7517f8bdf..93f14c9694b9 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,7 +710,6 @@ static void msdc_pm(pm_message_t state, void *data)
 /*--*/
 static unsigned int msdc_command_start(struct msdc_host   *host,
   struct mmc_command *cmd,
-  int tune,   /* not used 
*/
   unsigned long   timeout)
 {
u32 opcode = cmd->opcode;
@@ -932,7 +931,7 @@ static unsigned int msdc_do_command(struct msdc_host   
*host,
int tune,
unsigned long   timeout)
 {
-   if (msdc_command_start(host, cmd, tune, timeout))
+   if (msdc_command_start(host, cmd, timeout))
goto end;
 
if (msdc_command_resp(host, cmd, tune, timeout))
@@ -1098,7 +1097,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
init_completion(&host->xfer_done);
 
/* start the command first*/
-   if (msdc_command_start(host, cmd, 1, CMD_TIMEOUT) != 0)
+   if (msdc_command_start(host, cmd, CMD_TIMEOUT) != 0)
goto done;
 
data->sg_count = dma_map_sg(mmc_dev(mmc), data->sg,
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 33/34] staging: mt7621-mmc: Find response of MMC_SEND_OP_COND by default

2018-06-16 Thread Christian Lütke-Stetzkamp
The response type of the MMC_SEND_OP_COND command is correctly
determined using the mmc_resp_type macro, because the only use of that
opcode, mmc_send_op_cond, correctly places MMC_RSP_R3 in cmd.flags.

So there is no need to treat that opcode separately.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index f7df3221a302..69123cfd7309 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,7 +710,7 @@ static inline u32 msdc_cmd_find_resp(struct mmc_command 
*cmd)
u32 opcode = cmd->opcode;
u32 resp;
 
-   if (opcode == MMC_SEND_OP_COND || opcode == SD_APP_OP_COND) {
+   if (opcode == SD_APP_OP_COND) {
resp = RESP_R3;
} else if (opcode == MMC_SET_RELATIVE_ADDR) {
resp = (mmc_cmd_type(cmd) == MMC_CMD_BCR) ? RESP_R6 : RESP_R1;
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 25/34] staging: mt7621-mmc: Cleanup source of base address for io

2018-06-16 Thread Christian Lütke-Stetzkamp
Currently the base address for all io operations is hidden behind a
macro, REG_ADD. This macro uses the symbol "base" as the base address
and all functions set base = host->base. This is hard to read, so the
whole wrapping is removed and host->base is directly inserted in the
io access.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 161 --
 drivers/staging/mt7621-mmc/sd.c| 378 +
 2 files changed, 236 insertions(+), 303 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 9b6cd6db37df..4e287c140acb 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -41,11 +41,6 @@
 
 // #include  /* --- by chhung */
 
-/*--*/
-/* Common Macro */
-/*--*/
-#define REG_ADDR(x) (base + OFFSET_##x)
-
 /*--*/
 /* Common Definition*/
 /*--*/
@@ -95,117 +90,51 @@ enum {
 /*--*/
 /* Register Offset  */
 /*--*/
-#define OFFSET_MSDC_CFG (0x0)
-#define OFFSET_MSDC_IOCON   (0x04)
-#define OFFSET_MSDC_PS  (0x08)
-#define OFFSET_MSDC_INT (0x0c)
-#define OFFSET_MSDC_INTEN   (0x10)
-#define OFFSET_MSDC_FIFOCS  (0x14)
-#define OFFSET_MSDC_TXDATA  (0x18)
-#define OFFSET_MSDC_RXDATA  (0x1c)
-#define OFFSET_SDC_CFG  (0x30)
-#define OFFSET_SDC_CMD  (0x34)
-#define OFFSET_SDC_ARG  (0x38)
-#define OFFSET_SDC_STS  (0x3c)
-#define OFFSET_SDC_RESP0(0x40)
-#define OFFSET_SDC_RESP1(0x44)
-#define OFFSET_SDC_RESP2(0x48)
-#define OFFSET_SDC_RESP3(0x4c)
-#define OFFSET_SDC_BLK_NUM  (0x50)
-#define OFFSET_SDC_CSTS (0x58)
-#define OFFSET_SDC_CSTS_EN  (0x5c)
-#define OFFSET_SDC_DCRC_STS (0x60)
-#define OFFSET_EMMC_CFG0(0x70)
-#define OFFSET_EMMC_CFG1(0x74)
-#define OFFSET_EMMC_STS (0x78)
-#define OFFSET_EMMC_IOCON   (0x7c)
-#define OFFSET_SDC_ACMD_RESP(0x80)
-#define OFFSET_SDC_ACMD19_TRG   (0x84)
-#define OFFSET_SDC_ACMD19_STS   (0x88)
-#define OFFSET_MSDC_DMA_SA  (0x90)
-#define OFFSET_MSDC_DMA_CA  (0x94)
-#define OFFSET_MSDC_DMA_CTRL(0x98)
-#define OFFSET_MSDC_DMA_CFG (0x9c)
-#define OFFSET_MSDC_DBG_SEL (0xa0)
-#define OFFSET_MSDC_DBG_OUT (0xa4)
-#define OFFSET_MSDC_PATCH_BIT   (0xb0)
-#define OFFSET_MSDC_PATCH_BIT1  (0xb4)
-#define OFFSET_MSDC_PAD_CTL0(0xe0)
-#define OFFSET_MSDC_PAD_CTL1(0xe4)
-#define OFFSET_MSDC_PAD_CTL2(0xe8)
-#define OFFSET_MSDC_PAD_TUNE(0xec)
-#define OFFSET_MSDC_DAT_RDDLY0  (0xf0)
-#define OFFSET_MSDC_DAT_RDDLY1  (0xf4)
-#define OFFSET_MSDC_HW_DBG  (0xf8)
-#define OFFSET_MSDC_VERSION (0x100)
-#define OFFSET_MSDC_ECO_VER (0x104)
-
-/*--*/
-/* Register Address */
-/*--*/
-
-/* common register */
-#define MSDC_CFGREG_ADDR(MSDC_CFG)
-#define MSDC_IOCON  REG_ADDR(MSDC_IOCON)
-#define MSDC_PS REG_ADDR(MSDC_PS)
-#define MSDC_INTREG_ADDR(MSDC_INT)
-#define MSDC_INTEN  REG_ADDR(MSDC_INTEN)
-#define MSDC_FIFOCS REG_ADDR(MSDC_FIFOCS)
-#define MSDC_TXDATA REG_ADDR(MSDC_TXDATA)
-#define MSDC_RXDATA REG_ADDR(MSDC_RXDATA)
-#define MSDC_PATCH_BIT0 REG_ADDR(MSDC_PATCH_BIT)
-
-/* sdmmc register */
-#define SDC_CFG REG_ADDR(SDC_CFG)
-#define SDC_CMD REG_ADDR(SDC_CMD)
-#define SDC_ARG REG_ADDR(SDC_ARG)
-#define SDC_STS REG_ADDR(SDC_STS)
-#define SDC_RESP0   REG_ADDR(SDC_RESP0)
-#define SDC_RESP1   REG_ADDR(SDC_RESP1)
-#define SDC_RESP2   REG_ADDR(SDC_RESP2)
-#define SDC_RESP3   REG_ADDR(SDC_RESP3)
-#define SDC_BLK_NUM REG_ADDR(SDC_BLK_NUM)
-#define SDC_CSTSREG_ADDR(SDC_CSTS)
-#define SDC_CSTS_EN REG_ADDR(SDC_CSTS_EN)
-#define SDC_DCRC_STSREG_ADDR(SDC_DCRC_STS)
-
-/* emmc register*/
-#define EMMC_CFG0   REG_ADDR(EMMC_CFG0)
-#define EMMC_CFG1   REG_ADDR(EMMC_CFG1)
-#define EMMC_STSREG_ADDR(EMMC_STS)
-#d

[PATCH v2 29/34] staging: mt7621-mmc: Remove unused define MAX_PHY_SGMTS

2018-06-16 Thread Christian Lütke-Stetzkamp
The define MAX_PHY_SGMTS is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 31ee9c533f35..45d9b62f4a58 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -89,7 +89,6 @@
 #define MAX_BD_NUM  (1024)
 
 #define MAX_HW_SGMTS(MAX_BD_NUM)
-#define MAX_PHY_SGMTS   (MAX_BD_NUM)
 #define MAX_SGMT_SZ (MAX_DMA_CNT)
 #define MAX_REQ_SZ  (MAX_SGMT_SZ * 8)
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 28/34] staging: mt7621-mmc: Remove unused enum msdc_mode

2018-06-16 Thread Christian Lütke-Stetzkamp
The enum msdc_mode is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/dbg.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/dbg.h b/drivers/staging/mt7621-mmc/dbg.h
index 5a25a69b00c9..2f2c56b73987 100644
--- a/drivers/staging/mt7621-mmc/dbg.h
+++ b/drivers/staging/mt7621-mmc/dbg.h
@@ -73,12 +73,6 @@ enum msdc_dbg {
SD_TOOL_SDIO_PROFILE = 3,
 };
 
-enum msdc_mode {
-   MODE_PIO = 0,
-   MODE_DMA = 1,
-   MODE_SIZE_DEP = 2,
-};
-
 /* Debug message event */
 #define DBG_EVT_NONE(0)   /* No event */
 #define DBG_EVT_DMA (1 << 0)  /* DMA related event */
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 05/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_read32

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_read32 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 9e00f86a0398..0f9cba918586 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,7 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-#define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 12/34] staging: mt7621-mmc: Remove register debugging structures

2018-06-16 Thread Christian Lütke-Stetzkamp
Current code has structures for all the registers of the device, but
these are never used and there are also masks for all of them, so
these structures do not contain any useful information.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 411 -
 1 file changed, 411 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 375cb109806e..07f48d526888 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -478,417 +478,6 @@ struct bd {
u32  rsv3:16;
 };
 
-/*--*/
-/* Register Debugging Structure */
-/*--*/
-
-struct msdc_cfg_reg {
-   u32 msdc:1;
-   u32 ckpwn:1;
-   u32 rst:1;
-   u32 pio:1;
-   u32 ckdrven:1;
-   u32 start18v:1;
-   u32 pass18v:1;
-   u32 ckstb:1;
-   u32 ckdiv:8;
-   u32 ckmod:2;
-   u32 pad:14;
-};
-
-struct msdc_iocon_reg {
-   u32 sdr104cksel:1;
-   u32 rsmpl:1;
-   u32 dsmpl:1;
-   u32 ddlysel:1;
-   u32 ddr50ckd:1;
-   u32 dsplsel:1;
-   u32 pad1:10;
-   u32 d0spl:1;
-   u32 d1spl:1;
-   u32 d2spl:1;
-   u32 d3spl:1;
-   u32 d4spl:1;
-   u32 d5spl:1;
-   u32 d6spl:1;
-   u32 d7spl:1;
-   u32 riscsz:1;
-   u32 pad2:7;
-};
-
-struct msdc_ps_reg {
-   u32 cden:1;
-   u32 cdsts:1;
-   u32 pad1:10;
-   u32 cddebounce:4;
-   u32 dat:8;
-   u32 cmd:1;
-   u32 pad2:6;
-   u32 wp:1;
-};
-
-struct msdc_int_reg {
-   u32 mmcirq:1;
-   u32 cdsc:1;
-   u32 pad1:1;
-   u32 atocmdrdy:1;
-   u32 atocmdtmo:1;
-   u32 atocmdcrc:1;
-   u32 dmaqempty:1;
-   u32 sdioirq:1;
-   u32 cmdrdy:1;
-   u32 cmdtmo:1;
-   u32 rspcrc:1;
-   u32 csta:1;
-   u32 xfercomp:1;
-   u32 dxferdone:1;
-   u32 dattmo:1;
-   u32 datcrc:1;
-   u32 atocmd19done:1;
-   u32 pad2:15;
-};
-
-struct msdc_inten_reg {
-   u32 mmcirq:1;
-   u32 cdsc:1;
-   u32 pad1:1;
-   u32 atocmdrdy:1;
-   u32 atocmdtmo:1;
-   u32 atocmdcrc:1;
-   u32 dmaqempty:1;
-   u32 sdioirq:1;
-   u32 cmdrdy:1;
-   u32 cmdtmo:1;
-   u32 rspcrc:1;
-   u32 csta:1;
-   u32 xfercomp:1;
-   u32 dxferdone:1;
-   u32 dattmo:1;
-   u32 datcrc:1;
-   u32 atocmd19done:1;
-   u32 pad2:15;
-};
-
-struct msdc_fifocs_reg {
-   u32 rxcnt:8;
-   u32 pad1:8;
-   u32 txcnt:8;
-   u32 pad2:7;
-   u32 clr:1;
-};
-
-struct msdc_txdat_reg {
-   u32 val;
-};
-
-struct msdc_rxdat_reg {
-   u32 val;
-};
-
-struct sdc_cfg_reg {
-   u32 sdiowkup:1;
-   u32 inswkup:1;
-   u32 pad1:14;
-   u32 buswidth:2;
-   u32 pad2:1;
-   u32 sdio:1;
-   u32 sdioide:1;
-   u32 intblkgap:1;
-   u32 pad4:2;
-   u32 dtoc:8;
-};
-
-struct sdc_cmd_reg {
-   u32 cmd:6;
-   u32 brk:1;
-   u32 rsptyp:3;
-   u32 pad1:1;
-   u32 dtype:2;
-   u32 rw:1;
-   u32 stop:1;
-   u32 goirq:1;
-   u32 blklen:12;
-   u32 atocmd:2;
-   u32 volswth:1;
-   u32 pad2:1;
-};
-
-struct sdc_arg_reg {
-   u32 arg;
-};
-
-struct sdc_sts_reg {
-   u32 sdcbusy:1;
-   u32 cmdbusy:1;
-   u32 pad:29;
-   u32 swrcmpl:1;
-};
-
-struct sdc_resp0_reg {
-   u32 val;
-};
-
-struct sdc_resp1_reg {
-   u32 val;
-};
-
-struct sdc_resp2_reg {
-   u32 val;
-};
-
-struct sdc_resp3_reg {
-   u32 val;
-};
-
-struct sdc_blknum_reg {
-   u32 num;
-};
-
-struct sdc_csts_reg {
-   u32 sts;
-};
-
-struct sdc_cstsen_reg {
-   u32 sts;
-};
-
-struct sdc_datcrcsts_reg {
-   u32 datcrcsts:8;
-   u32 ddrcrcsts:4;
-   u32 pad:20;
-};
-
-struct emmc_cfg0_reg {
-   u32 bootstart:1;
-   u32 bootstop:1;
-   u32 bootmode:1;
-   u32 pad1:9;
-   u32 bootwaidly:3;
-   u32 bootsupp:1;
-   u32 pad2:16;
-};
-
-struct emmc_cfg1_reg {
-   u32 bootcrctmc:16;
-   u32 pad:4;
-   u32 bootacktmc:12;
-};
-
-struct emmc_sts_reg {
-   u32 bootcrcerr:1;
-   u32 bootackerr:1;
-   u32 bootdattmo:1;
-   u32 bootacktmo:1;
-   u32 bootupstate:1;
-   u32 bootackrcv:1;
-   u32 bootdatrcv:1;
-   u32 pad:25;
-};
-
-struct emmc_iocon_reg {
-   u32 bootrst:1;
-   u32 pad:31;
-};
-
-struct msdc_acmd_resp_reg {
-   u32 val;
-};
-
-struct msdc_acmd19_trg_reg {
-   u32 tunesel:4;
-   u32 pad:28;
-};
-
-struct msdc_acmd19_sts_reg {
-   u32 val;
-};
-
-struct msdc_dma_sa_reg {
-   u32 addr;
-};
-
-struct msdc_dma_ca_reg {
-   u32 addr;
-};
-
-struct msdc_dma_ctrl_reg {
-   u32 start:1;
-   u32 stop:1;
-   u32 resume:1;
-   u32 pad1:5;
-   u32 mode:1

[PATCH v2 19/34] staging: mt7621-mmc: Remove unnecessary BUG_ON() in msdc_dma_setup

2018-06-16 Thread Christian Lütke-Stetzkamp
The BUG_ON() removed by this patch is just a duplicate of a prior
BUG_ON() statement. There the condition is just clearer, it checks
weather sglen > MAX_BD_NUM and MAX_BD_NUM is equal MAX_BD_PER_GPD. So
this statement can be safely removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 68dfbf38b0ea..a506c7e19086 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1043,9 +1043,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
-   /* calculate the required number of gpd */
-   BUG_ON(((sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD) != 1);
-
gpd = dma->gpd;
bd  = dma->bd;
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 00/34] staging: mt7621-mmc: Cleanup continues

2018-06-16 Thread Christian Lütke-Stetzkamp
Here are the next cleanups for the mt7621-mmc driver. Again much of
unused code is removed and the IO is cleaned up.  The next major step
will be the complete refactoring of the tuning, because it does not
use the tuning capabilities of sd-core, but kind of re-implements that.

Changes since v1:
- commit "Factor out from msdc_command_start()" had a wrong parameter definition

Christian Lütke-Stetzkamp (34):
  staging: mt7621-mmc: Remove unused variable in msdc_command_resp
  staging: mt7621-mmc: Remove unused macro msdc_fifo_write8
  staging: mt7621-mmc: Remove unused macro msdc_fifo_read8
  staging: mt7621-mmc: Remove unused macro msdc_fifo_write32
  staging: mt7621-mmc: Remove unused macro msdc_fifo_read32
  staging: mt7621-mmc: Remove unused macro msdc_txfifocnt
  staging: mt7621-mmc: Remove unused macro msdc_rxfifocnt
  staging: mt7621-mmc: Replace sdr_write32 with writel
  staging: mt7621-mmc: Replace sdr_read32 with readl
  staging: mt7621-mmc: Remove unused macro sdr_read8
  staging: mt7621-mmc: Remove unused macro sdr_write8
  staging: mt7621-mmc: Remove register debugging structures
  staging: mt7621-mmc: Remove DMA basic mode code
  staging: mt7621-mmc: Remove unused field mode from msdc_dma
  staging: mt7621-mmc: Refactor dma setup process
  staging: mt7621-mmc: Remove unused field sg from msdc_dma
  staging: mt7621-mmc: Remove unused field sglen from msdc_dma
  staging: mt7621-mmc: Remove variable num form msdc_dma_setup
  staging: mt7621-mmc: Remove unnecessary BUG_ON() in msdc_dma_setup
  staging: mt7621-mmc: Make msdc_clr_fifo a function and relax cpu
  staging: mt7621-mmc: Remove unused macro msdc_retry
  staging: mt7621-mmc: Remove unused macro MAX_BD_PER_GPD
  staging: mt7621-mmc: Remove unused variable from msdc_tune_request
  staging: mt7621-mmc: Remove MSDC_MODE_* defines
  staging: mt7621-mmc: Cleanup source of base address for io
  staging: mt7621-mmc: Remove unused define RALINK_MSDC_BASE
  staging: mt7621-mmc: Remove unused define IRQ_SDC
  staging: mt7621-mmc: Remove unused enum msdc_mode
  staging: mt7621-mmc: Remove unused define MAX_PHY_SGMTS
  staging: mt7621-mmc: Remove unused macro is_card_present
  staging: mt7621-mmc: Remove unused argument from msdc_do_command
  staging: mt7621-mmc: Factor out from msdc_command_start()
  staging: mt7621-mmc: Find response of MMC_SEND_OP_COND by default
  staging: mt7621-mmc: Find response of SD_APP_OP_COND by default

 drivers/staging/mt7621-mmc/dbg.h   |   6 -
 drivers/staging/mt7621-mmc/mt6575_sd.h | 588 +++--
 drivers/staging/mt7621-mmc/sd.c| 584 +++-
 3 files changed, 305 insertions(+), 873 deletions(-)

-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 24/34] staging: mt7621-mmc: Remove MSDC_MODE_* defines

2018-06-16 Thread Christian Lütke-Stetzkamp
The MSDC_MODE_* defines are all never used and do not contain any
information about the device, so remove them.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 4b56d9a37b84..9b6cd6db37df 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -56,13 +56,6 @@
 #define MSDC_MS (0)
 #define MSDC_SDMMC  (1)
 
-#define MSDC_MODE_UNKNOWN   (0)
-#define MSDC_MODE_PIO   (1)
-#define MSDC_MODE_DMA_BASIC (2)
-#define MSDC_MODE_DMA_DESC  (3)
-#define MSDC_MODE_DMA_ENHANCED  (4)
-#define MSDC_MODE_MMC_STREAM(5)
-
 #define MSDC_BUS_1BITS  (0)
 #define MSDC_BUS_4BITS  (1)
 #define MSDC_BUS_8BITS  (2)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 11/34] staging: mt7621-mmc: Remove unused macro sdr_write8

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro sdr_write8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index adccabe32660..375cb109806e 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -947,8 +947,6 @@ struct msdc_host {
u32 app_cmd_arg;
 };
 
-#define sdr_write8(reg, val)  writeb(val, reg)
-
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
 {
u32 val = readl(reg);
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 18/34] staging: mt7621-mmc: Remove variable num form msdc_dma_setup

2018-06-16 Thread Christian Lütke-Stetzkamp
The variable num in msdc_dma_setup is only used for a BUG_ON
statement, so it can be removed by inlining the condition.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e1077068604d..68dfbf38b0ea 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1037,15 +1037,14 @@ static void msdc_dma_setup(struct msdc_host *host, 
struct msdc_dma *dma,
struct scatterlist *sg;
struct gpd *gpd;
struct bd *bd;
-   u32 j, num;
+   u32 j;
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-   num = (sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
-   BUG_ON(num != 1);
+   BUG_ON(((sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD) != 1);
 
gpd = dma->gpd;
bd  = dma->bd;
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 14/34] staging: mt7621-mmc: Remove unused field mode from msdc_dma

2018-06-16 Thread Christian Lütke-Stetzkamp
The field mode of struct msdc_dma has no remaining use, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 5 +
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 07f48d526888..8eb30d908f9d 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -481,7 +481,6 @@ struct bd {
 struct msdc_dma {
u32 sglen;   /* size of scatter list */
struct scatterlist *sg;  /* I/O scatter list */
-   u8  mode;/* dma mode*/
 
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 1196e8eb86c5..3066fa3799ac 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1091,10 +1091,7 @@ static void msdc_dma_setup(struct msdc_host *host, 
struct msdc_dma *dma,
dma->sg = sg;
dma->sglen = sglen;
 
-   dma->mode = MSDC_MODE_DMA_DESC;
-
-   N_MSG(DMA, "DMA mode<%d> sglen<%d> xfersz<%d>", dma->mode, dma->sglen,
- host->xfer_size);
+   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", dma->sglen, host->xfer_size);
 
msdc_dma_config(host, dma);
 }
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 10/34] staging: mt7621-mmc: Remove unused macro sdr_read8

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro sdr_read8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 29e2ede6816b..adccabe32660 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -947,7 +947,6 @@ struct msdc_host {
u32 app_cmd_arg;
 };
 
-#define sdr_read8(reg)readb(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 21/34] staging: mt7621-mmc: Remove unused macro msdc_retry

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_retry is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 01a925ae662e..0e94bb0d5927 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,19 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-#define msdc_retry(expr, retry, cnt) \
-   do {\
-   int backup = cnt;   \
-   while (retry) { \
-   if (!(expr))\
-   break;  \
-   if (cnt-- == 0) {   \
-   retry--; mdelay(1); cnt = backup;   \
-   }   \
-   }   \
-   WARN_ON(retry == 0);\
-   } while (0)
-
 static void msdc_reset_hw(struct msdc_host *host)
 {
void __iomem *base = host->base;
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 09/34] staging: mt7621-mmc: Replace sdr_read32 with readl

2018-06-16 Thread Christian Lütke-Stetzkamp
The current code uses a macro (sdr_read32) for reading from hardware,
but it is only a readl, so replace it to get nearer to upstream code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h |  1 -
 drivers/staging/mt7621-mmc/sd.c| 98 +-
 2 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index e8e79aab52f8..29e2ede6816b 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -948,7 +948,6 @@ struct msdc_host {
 };
 
 #define sdr_read8(reg)readb(reg)
-#define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e6232f5ac6a8..1d0829e6 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -167,13 +167,13 @@ static void msdc_reset_hw(struct msdc_host *host)
void __iomem *base = host->base;
 
sdr_set_bits(MSDC_CFG, MSDC_CFG_RST);
-   while (sdr_read32(MSDC_CFG) & MSDC_CFG_RST)
+   while (readl(MSDC_CFG) & MSDC_CFG_RST)
cpu_relax();
 }
 
 #define msdc_clr_int() \
do {\
-   volatile u32 val = sdr_read32(MSDC_INT);\
+   volatile u32 val = readl(MSDC_INT); \
writel(val, MSDC_INT);  \
} while (0)
 
@@ -181,12 +181,12 @@ static void msdc_reset_hw(struct msdc_host *host)
do {\
int retry = 3, cnt = 1000;  \
sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR); \
-   msdc_retry(sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, 
cnt); \
+   msdc_retry(readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, cnt); \
} while (0)
 
 #define msdc_irq_save(val) \
do {\
-   val = sdr_read32(MSDC_INTEN);   \
+   val = readl(MSDC_INTEN);\
sdr_clr_bits(MSDC_INTEN, val);  \
} while (0)
 
@@ -230,8 +230,8 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
(void)hwPowerDown(MT65XX_POWER_LDO_VMCH, "SD"); \
} while (0)
 
-#define sdc_is_busy()  (sdr_read32(SDC_STS) & SDC_STS_SDCBUSY)
-#define sdc_is_cmd_busy()  (sdr_read32(SDC_STS) & SDC_STS_CMDBUSY)
+#define sdc_is_busy()  (readl(SDC_STS) & SDC_STS_SDCBUSY)
+#define sdc_is_cmd_busy()  (readl(SDC_STS) & SDC_STS_CMDBUSY)
 
 #define sdc_send_cmd(cmd, arg) \
do {\
@@ -240,7 +240,7 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
} while (0)
 
 // can modify to read h/w register.
-//#define is_card_present(h)   ((sdr_read32(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
+//#define is_card_present(h)   ((readl(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
 #define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
 
 /* +++ by chhung */
@@ -426,7 +426,7 @@ static void msdc_tasklet_card(struct work_struct *work)
 
spin_lock(&host->lock);
 
-   status = sdr_read32(MSDC_PS);
+   status = readl(MSDC_PS);
if (cd_active_low)
inserted = (status & MSDC_PS_CDSTS) ? 0 : 1;
else
@@ -469,8 +469,8 @@ static void msdc_select_clksrc(struct msdc_host *host, 
unsigned char clksrc)
BUG_ON(clksrc > 3);
INIT_MSG("set clock source to <%d>", clksrc);
 
-   val = sdr_read32(MSDC_CLKSRC_REG);
-   if (sdr_read32(MSDC_ECO_VER) >= 4) {
+   val = readl(MSDC_CLKSRC_REG);
+   if (readl(MSDC_ECO_VER) >= 4) {
val &= ~(0x3  << clk_src_bit[host->id]);
val |= clksrc << clk_src_bit[host->id];
} else {
@@ -531,7 +531,7 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, 
unsigned int hz)
sdr_set_field(MSDC_CFG, MSDC_CFG_CKDIV, div);
 
/* wait clock stable */
-   while (!(sdr_read32(MSDC_CFG) & MSDC_CFG_CKSTB))
+   while (!(readl(MSDC_CFG) & MSDC_CFG_CKSTB))
cpu_relax();
 
host->sclk = sclk;
@@ -940,7 +940,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
 
/* memory card CRC */
if (host->hw->flags & MSDC_REMOVABLE && cmd->error == -EIO) {
-   if (sdr_read32(SDC_CMD) & 0x1800) { /* check if has data phase 
*/
+   if (readl(SDC_CMD) & 0x1800) { /* check if has data phase */
msdc_abort_data(host);
} else {
/* do ba

[PATCH v2 26/34] staging: mt7621-mmc: Remove unused define RALINK_MSDC_BASE

2018-06-16 Thread Christian Lütke-Stetzkamp
The define RALINK_MSDC_BASE is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e639ceb2ba85..101ceca2ee4c 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -53,10 +53,8 @@
 //#define IRQ_SDC 14   //MT7620 /*FIXME*/
 #ifdef CONFIG_SOC_MT7621
 #define RALINK_SYSCTL_BASE 0xbe00
-#define RALINK_MSDC_BASE   0xbe13
 #else
 #define RALINK_SYSCTL_BASE 0xb000
-#define RALINK_MSDC_BASE   0xb013
 #endif
 #define IRQ_SDC22  /*FIXME*/
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 13/34] staging: mt7621-mmc: Remove DMA basic mode code

2018-06-16 Thread Christian Lütke-Stetzkamp
The driver currently only uses DMA linked mode and the upstream
driver does the same, so remove the basic mode code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 88 +++--
 1 file changed, 32 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 1d0829e6..1196e8eb86c5 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1040,66 +1040,42 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
struct gpd *gpd;
struct bd *bd;
 
-   switch (dma->mode) {
-   case MSDC_MODE_DMA_BASIC:
-   BUG_ON(host->xfer_size > 65535);
-   BUG_ON(dma->sglen != 1);
-   writel(PHYSADDR(sg_dma_address(sg)), MSDC_DMA_SA);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_LASTBUF, 1);
-//#if defined (CONFIG_RALINK_MT7620)
-   if (ralink_soc == MT762X_SOC_MT7620A)
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_XFERSZ, 
sg_dma_len(sg));
-//#elif defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628)
+   /* calculate the required number of gpd */
+   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
+   BUG_ON(num != 1);
+
+   gpd = dma->gpd;
+   bd  = dma->bd;
+
+   /* modify gpd*/
+   //gpd->intr = 0;
+   gpd->hwo = 1;  /* hw will clear it */
+   gpd->bdp = 1;
+   gpd->chksum = 0;  /* need to clear first. */
+   gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
+
+   /* modify bd*/
+   for_each_sg(dma->sg, sg, dma->sglen, j) {
+   bd[j].blkpad = 0;
+   bd[j].dwpad = 0;
+   bd[j].ptr = (void *)sg_dma_address(sg);
+   bd[j].buflen = sg_dma_len(sg);
+
+   if (j == dma->sglen - 1)
+   bd[j].eol = 1;  /* the last bd */
else
-   writel(sg_dma_len(sg), (void __iomem 
*)(RALINK_MSDC_BASE + 0xa8));
-//#endif
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
- MSDC_BRUST_64B);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 0);
-   break;
-   case MSDC_MODE_DMA_DESC:
-
-   /* calculate the required number of gpd */
-   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
-   BUG_ON(num != 1);
-
-   gpd = dma->gpd;
-   bd  = dma->bd;
-
-   /* modify gpd*/
-   //gpd->intr = 0;
-   gpd->hwo = 1;  /* hw will clear it */
-   gpd->bdp = 1;
-   gpd->chksum = 0;  /* need to clear first. */
-   gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
-
-   /* modify bd*/
-   for_each_sg(dma->sg, sg, dma->sglen, j) {
-   bd[j].blkpad = 0;
-   bd[j].dwpad = 0;
-   bd[j].ptr = (void *)sg_dma_address(sg);
-   bd[j].buflen = sg_dma_len(sg);
-
-   if (j == dma->sglen - 1)
-   bd[j].eol = 1;  /* the last bd */
-   else
-   bd[j].eol = 0;
+   bd[j].eol = 0;
 
-   bd[j].chksum = 0; /* checksume need to clear first */
-   bd[j].chksum = msdc_dma_calcs((u8 *)(&bd[j]), 16);
-   }
+   bd[j].chksum = 0; /* checksume need to clear first */
+   bd[j].chksum = msdc_dma_calcs((u8 *)(&bd[j]), 16);
+   }
 
-   sdr_set_field(MSDC_DMA_CFG, MSDC_DMA_CFG_DECSEN, 1);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
- MSDC_BRUST_64B);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
+   sdr_set_field(MSDC_DMA_CFG, MSDC_DMA_CFG_DECSEN, 1);
+   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
+ MSDC_BRUST_64B);
+   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
 
-   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
-   break;
-
-   default:
-   break;
-   }
+   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
 
N_MSG(DMA, "DMA_CTRL = 0x%x", readl(MSDC_DMA_CTRL));
N_MSG(DMA, "DMA_CFG  = 0x%x", readl(MSDC_DMA_CFG));
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 04/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_write32

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_write32 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 98bcb0fe6f40..9e00f86a0398 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,7 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-#define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 03/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_read8

2018-06-16 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_read8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 4a69bc84bbd2..98bcb0fe6f40 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -151,7 +151,6 @@ static int msdc_rsp[] = {
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 #define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
-#define msdc_fifo_read8()sdr_read8(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-- 
2.16.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/34] staging: mt7621-mmc: Remove register debugging structures

2018-06-11 Thread Christian Lütke-Stetzkamp
Current code has structures for all the registers of the device, but
these are never used and there are also masks for all of them, so
these structures do not contain any useful information.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 411 -
 1 file changed, 411 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 375cb109806e..07f48d526888 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -478,417 +478,6 @@ struct bd {
u32  rsv3:16;
 };
 
-/*--*/
-/* Register Debugging Structure */
-/*--*/
-
-struct msdc_cfg_reg {
-   u32 msdc:1;
-   u32 ckpwn:1;
-   u32 rst:1;
-   u32 pio:1;
-   u32 ckdrven:1;
-   u32 start18v:1;
-   u32 pass18v:1;
-   u32 ckstb:1;
-   u32 ckdiv:8;
-   u32 ckmod:2;
-   u32 pad:14;
-};
-
-struct msdc_iocon_reg {
-   u32 sdr104cksel:1;
-   u32 rsmpl:1;
-   u32 dsmpl:1;
-   u32 ddlysel:1;
-   u32 ddr50ckd:1;
-   u32 dsplsel:1;
-   u32 pad1:10;
-   u32 d0spl:1;
-   u32 d1spl:1;
-   u32 d2spl:1;
-   u32 d3spl:1;
-   u32 d4spl:1;
-   u32 d5spl:1;
-   u32 d6spl:1;
-   u32 d7spl:1;
-   u32 riscsz:1;
-   u32 pad2:7;
-};
-
-struct msdc_ps_reg {
-   u32 cden:1;
-   u32 cdsts:1;
-   u32 pad1:10;
-   u32 cddebounce:4;
-   u32 dat:8;
-   u32 cmd:1;
-   u32 pad2:6;
-   u32 wp:1;
-};
-
-struct msdc_int_reg {
-   u32 mmcirq:1;
-   u32 cdsc:1;
-   u32 pad1:1;
-   u32 atocmdrdy:1;
-   u32 atocmdtmo:1;
-   u32 atocmdcrc:1;
-   u32 dmaqempty:1;
-   u32 sdioirq:1;
-   u32 cmdrdy:1;
-   u32 cmdtmo:1;
-   u32 rspcrc:1;
-   u32 csta:1;
-   u32 xfercomp:1;
-   u32 dxferdone:1;
-   u32 dattmo:1;
-   u32 datcrc:1;
-   u32 atocmd19done:1;
-   u32 pad2:15;
-};
-
-struct msdc_inten_reg {
-   u32 mmcirq:1;
-   u32 cdsc:1;
-   u32 pad1:1;
-   u32 atocmdrdy:1;
-   u32 atocmdtmo:1;
-   u32 atocmdcrc:1;
-   u32 dmaqempty:1;
-   u32 sdioirq:1;
-   u32 cmdrdy:1;
-   u32 cmdtmo:1;
-   u32 rspcrc:1;
-   u32 csta:1;
-   u32 xfercomp:1;
-   u32 dxferdone:1;
-   u32 dattmo:1;
-   u32 datcrc:1;
-   u32 atocmd19done:1;
-   u32 pad2:15;
-};
-
-struct msdc_fifocs_reg {
-   u32 rxcnt:8;
-   u32 pad1:8;
-   u32 txcnt:8;
-   u32 pad2:7;
-   u32 clr:1;
-};
-
-struct msdc_txdat_reg {
-   u32 val;
-};
-
-struct msdc_rxdat_reg {
-   u32 val;
-};
-
-struct sdc_cfg_reg {
-   u32 sdiowkup:1;
-   u32 inswkup:1;
-   u32 pad1:14;
-   u32 buswidth:2;
-   u32 pad2:1;
-   u32 sdio:1;
-   u32 sdioide:1;
-   u32 intblkgap:1;
-   u32 pad4:2;
-   u32 dtoc:8;
-};
-
-struct sdc_cmd_reg {
-   u32 cmd:6;
-   u32 brk:1;
-   u32 rsptyp:3;
-   u32 pad1:1;
-   u32 dtype:2;
-   u32 rw:1;
-   u32 stop:1;
-   u32 goirq:1;
-   u32 blklen:12;
-   u32 atocmd:2;
-   u32 volswth:1;
-   u32 pad2:1;
-};
-
-struct sdc_arg_reg {
-   u32 arg;
-};
-
-struct sdc_sts_reg {
-   u32 sdcbusy:1;
-   u32 cmdbusy:1;
-   u32 pad:29;
-   u32 swrcmpl:1;
-};
-
-struct sdc_resp0_reg {
-   u32 val;
-};
-
-struct sdc_resp1_reg {
-   u32 val;
-};
-
-struct sdc_resp2_reg {
-   u32 val;
-};
-
-struct sdc_resp3_reg {
-   u32 val;
-};
-
-struct sdc_blknum_reg {
-   u32 num;
-};
-
-struct sdc_csts_reg {
-   u32 sts;
-};
-
-struct sdc_cstsen_reg {
-   u32 sts;
-};
-
-struct sdc_datcrcsts_reg {
-   u32 datcrcsts:8;
-   u32 ddrcrcsts:4;
-   u32 pad:20;
-};
-
-struct emmc_cfg0_reg {
-   u32 bootstart:1;
-   u32 bootstop:1;
-   u32 bootmode:1;
-   u32 pad1:9;
-   u32 bootwaidly:3;
-   u32 bootsupp:1;
-   u32 pad2:16;
-};
-
-struct emmc_cfg1_reg {
-   u32 bootcrctmc:16;
-   u32 pad:4;
-   u32 bootacktmc:12;
-};
-
-struct emmc_sts_reg {
-   u32 bootcrcerr:1;
-   u32 bootackerr:1;
-   u32 bootdattmo:1;
-   u32 bootacktmo:1;
-   u32 bootupstate:1;
-   u32 bootackrcv:1;
-   u32 bootdatrcv:1;
-   u32 pad:25;
-};
-
-struct emmc_iocon_reg {
-   u32 bootrst:1;
-   u32 pad:31;
-};
-
-struct msdc_acmd_resp_reg {
-   u32 val;
-};
-
-struct msdc_acmd19_trg_reg {
-   u32 tunesel:4;
-   u32 pad:28;
-};
-
-struct msdc_acmd19_sts_reg {
-   u32 val;
-};
-
-struct msdc_dma_sa_reg {
-   u32 addr;
-};
-
-struct msdc_dma_ca_reg {
-   u32 addr;
-};
-
-struct msdc_dma_ctrl_reg {
-   u32 start:1;
-   u32 stop:1;
-   u32 resume:1;
-   u32 pad1:5;
-   u32 mode:1

[PATCH 15/34] staging: mt7621-mmc: Refactor dma setup process

2018-06-11 Thread Christian Lütke-Stetzkamp
Current code uses two functions for dma setup, msdc_dma_config and
msdc_dma_setup. By now msdc_dma_setup is nearly empty and mainly calls
msdc_dma_config, so the later one can be inline into the first
one. While doing this there is also some refactoring done.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 34 +-
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 3066fa3799ac..923b0687918d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1030,18 +1030,24 @@ static u8 msdc_dma_calcs(u8 *buf, u32 len)
return 0xFF - (u8)sum;
 }
 
-/* gpd bd setup + dma registers */
-static void msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma)
+static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
+  struct scatterlist *sg_cmd, unsigned int sglen)
 {
void __iomem *base = host->base;
-   //u32 i, j, num, bdlen, arg, xfersz;
-   u32 j, num;
struct scatterlist *sg;
struct gpd *gpd;
struct bd *bd;
+   u32 j, num;
+
+   BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
+
+   dma->sg = sg_cmd;
+   dma->sglen = sglen;
+
+   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
+   num = (sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
BUG_ON(num != 1);
 
gpd = dma->gpd;
@@ -1055,13 +1061,13 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
 
/* modify bd*/
-   for_each_sg(dma->sg, sg, dma->sglen, j) {
+   for_each_sg(sg_cmd, sg, sglen, j) {
bd[j].blkpad = 0;
bd[j].dwpad = 0;
bd[j].ptr = (void *)sg_dma_address(sg);
bd[j].buflen = sg_dma_len(sg);
 
-   if (j == dma->sglen - 1)
+   if (j == sglen - 1)
bd[j].eol = 1;  /* the last bd */
else
bd[j].eol = 0;
@@ -1080,20 +1086,6 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
N_MSG(DMA, "DMA_CTRL = 0x%x", readl(MSDC_DMA_CTRL));
N_MSG(DMA, "DMA_CFG  = 0x%x", readl(MSDC_DMA_CFG));
N_MSG(DMA, "DMA_SA   = 0x%x", readl(MSDC_DMA_SA));
-
-}
-
-static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
-  struct scatterlist *sg, unsigned int sglen)
-{
-   BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
-
-   dma->sg = sg;
-   dma->sglen = sglen;
-
-   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", dma->sglen, host->xfer_size);
-
-   msdc_dma_config(host, dma);
 }
 
 static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/34] staging: mt7621-mmc: Remove unused variable in msdc_command_resp

2018-06-11 Thread Christian Lütke-Stetzkamp
The variable resp in msdc_command_resp is once set and never read,
delete it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 648a2dd1436e..7cfadb41a53d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -886,13 +886,10 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
void __iomem *base = host->base;
u32 opcode = cmd->opcode;
//u32 rawcmd;
-   u32 resp;
u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
MSDC_INT_ACMD19_DONE;
 
-   resp = host->cmd_rsp;
-
BUG_ON(in_interrupt());
//init_completion(&host->cmd_done);
//sdr_set_bits(MSDC_INTEN, wints);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 21/34] staging: mt7621-mmc: Remove unused macro msdc_retry

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_retry is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 01a925ae662e..0e94bb0d5927 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,19 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-#define msdc_retry(expr, retry, cnt) \
-   do {\
-   int backup = cnt;   \
-   while (retry) { \
-   if (!(expr))\
-   break;  \
-   if (cnt-- == 0) {   \
-   retry--; mdelay(1); cnt = backup;   \
-   }   \
-   }   \
-   WARN_ON(retry == 0);\
-   } while (0)
-
 static void msdc_reset_hw(struct msdc_host *host)
 {
void __iomem *base = host->base;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/34] staging: mt7621-mmc: Remove unused macro msdc_txfifocnt

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_txfifocnt is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0f9cba918586..c6aced0c0a6a 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -147,7 +147,6 @@ static int msdc_rsp[] = {
7,  /* RESP_R1b */
 };
 
-#define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 23/34] staging: mt7621-mmc: Remove unused variable from msdc_tune_request

2018-06-11 Thread Christian Lütke-Stetzkamp
The variable cmd in the function msdc_tune_request is set but never
used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e99a12002646..c5139a20e10f 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1556,12 +1556,10 @@ static int msdc_check_busy(struct mmc_host *mmc, struct 
msdc_host *host)
 static int msdc_tune_request(struct mmc_host *mmc, struct mmc_request *mrq)
 {
struct msdc_host *host = mmc_priv(mmc);
-   struct mmc_command *cmd;
struct mmc_data *data;
//u32 base = host->base;
int ret = 0, read;
 
-   cmd  = mrq->cmd;
data = mrq->cmd->data;
 
read = data->flags & MMC_DATA_READ ? 1 : 0;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 25/34] staging: mt7621-mmc: Cleanup source of base address for io

2018-06-11 Thread Christian Lütke-Stetzkamp
Currently the base address for all io operations is hidden behind a
macro, REG_ADD. This macro uses the symbol "base" as the base address
and all functions set base = host->base. This is hard to read, so the
whole wrapping is removed and host->base is directly inserted in the
io access.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 161 --
 drivers/staging/mt7621-mmc/sd.c| 378 +
 2 files changed, 236 insertions(+), 303 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 9b6cd6db37df..4e287c140acb 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -41,11 +41,6 @@
 
 // #include  /* --- by chhung */
 
-/*--*/
-/* Common Macro */
-/*--*/
-#define REG_ADDR(x) (base + OFFSET_##x)
-
 /*--*/
 /* Common Definition*/
 /*--*/
@@ -95,117 +90,51 @@ enum {
 /*--*/
 /* Register Offset  */
 /*--*/
-#define OFFSET_MSDC_CFG (0x0)
-#define OFFSET_MSDC_IOCON   (0x04)
-#define OFFSET_MSDC_PS  (0x08)
-#define OFFSET_MSDC_INT (0x0c)
-#define OFFSET_MSDC_INTEN   (0x10)
-#define OFFSET_MSDC_FIFOCS  (0x14)
-#define OFFSET_MSDC_TXDATA  (0x18)
-#define OFFSET_MSDC_RXDATA  (0x1c)
-#define OFFSET_SDC_CFG  (0x30)
-#define OFFSET_SDC_CMD  (0x34)
-#define OFFSET_SDC_ARG  (0x38)
-#define OFFSET_SDC_STS  (0x3c)
-#define OFFSET_SDC_RESP0(0x40)
-#define OFFSET_SDC_RESP1(0x44)
-#define OFFSET_SDC_RESP2(0x48)
-#define OFFSET_SDC_RESP3(0x4c)
-#define OFFSET_SDC_BLK_NUM  (0x50)
-#define OFFSET_SDC_CSTS (0x58)
-#define OFFSET_SDC_CSTS_EN  (0x5c)
-#define OFFSET_SDC_DCRC_STS (0x60)
-#define OFFSET_EMMC_CFG0(0x70)
-#define OFFSET_EMMC_CFG1(0x74)
-#define OFFSET_EMMC_STS (0x78)
-#define OFFSET_EMMC_IOCON   (0x7c)
-#define OFFSET_SDC_ACMD_RESP(0x80)
-#define OFFSET_SDC_ACMD19_TRG   (0x84)
-#define OFFSET_SDC_ACMD19_STS   (0x88)
-#define OFFSET_MSDC_DMA_SA  (0x90)
-#define OFFSET_MSDC_DMA_CA  (0x94)
-#define OFFSET_MSDC_DMA_CTRL(0x98)
-#define OFFSET_MSDC_DMA_CFG (0x9c)
-#define OFFSET_MSDC_DBG_SEL (0xa0)
-#define OFFSET_MSDC_DBG_OUT (0xa4)
-#define OFFSET_MSDC_PATCH_BIT   (0xb0)
-#define OFFSET_MSDC_PATCH_BIT1  (0xb4)
-#define OFFSET_MSDC_PAD_CTL0(0xe0)
-#define OFFSET_MSDC_PAD_CTL1(0xe4)
-#define OFFSET_MSDC_PAD_CTL2(0xe8)
-#define OFFSET_MSDC_PAD_TUNE(0xec)
-#define OFFSET_MSDC_DAT_RDDLY0  (0xf0)
-#define OFFSET_MSDC_DAT_RDDLY1  (0xf4)
-#define OFFSET_MSDC_HW_DBG  (0xf8)
-#define OFFSET_MSDC_VERSION (0x100)
-#define OFFSET_MSDC_ECO_VER (0x104)
-
-/*--*/
-/* Register Address */
-/*--*/
-
-/* common register */
-#define MSDC_CFGREG_ADDR(MSDC_CFG)
-#define MSDC_IOCON  REG_ADDR(MSDC_IOCON)
-#define MSDC_PS REG_ADDR(MSDC_PS)
-#define MSDC_INTREG_ADDR(MSDC_INT)
-#define MSDC_INTEN  REG_ADDR(MSDC_INTEN)
-#define MSDC_FIFOCS REG_ADDR(MSDC_FIFOCS)
-#define MSDC_TXDATA REG_ADDR(MSDC_TXDATA)
-#define MSDC_RXDATA REG_ADDR(MSDC_RXDATA)
-#define MSDC_PATCH_BIT0 REG_ADDR(MSDC_PATCH_BIT)
-
-/* sdmmc register */
-#define SDC_CFG REG_ADDR(SDC_CFG)
-#define SDC_CMD REG_ADDR(SDC_CMD)
-#define SDC_ARG REG_ADDR(SDC_ARG)
-#define SDC_STS REG_ADDR(SDC_STS)
-#define SDC_RESP0   REG_ADDR(SDC_RESP0)
-#define SDC_RESP1   REG_ADDR(SDC_RESP1)
-#define SDC_RESP2   REG_ADDR(SDC_RESP2)
-#define SDC_RESP3   REG_ADDR(SDC_RESP3)
-#define SDC_BLK_NUM REG_ADDR(SDC_BLK_NUM)
-#define SDC_CSTSREG_ADDR(SDC_CSTS)
-#define SDC_CSTS_EN REG_ADDR(SDC_CSTS_EN)
-#define SDC_DCRC_STSREG_ADDR(SDC_DCRC_STS)
-
-/* emmc register*/
-#define EMMC_CFG0   REG_ADDR(EMMC_CFG0)
-#define EMMC_CFG1   REG_ADDR(EMMC_CFG1)
-#define EMMC_STSREG_ADDR(EMMC_STS)
-#d

[PATCH 00/34] staging: mt7621-mmc: Cleanup continues

2018-06-11 Thread Christian Lütke-Stetzkamp
Here are the next cleanups for the mt7621-mmc driver. Again much of
unused code is removed and the IO is cleaned up.  The next major step
will be the complete refactoring of the tuning, because it does not
use the tuning capabilities of sd-core, but kind of re-implements that.

Christian Lütke-Stetzkamp (34):
  staging: mt7621-mmc: Remove unused variable in msdc_command_resp
  staging: mt7621-mmc: Remove unused macro msdc_fifo_write8
  staging: mt7621-mmc: Remove unused macro msdc_fifo_read8
  staging: mt7621-mmc: Remove unused macro msdc_fifo_write32
  staging: mt7621-mmc: Remove unused macro msdc_fifo_read32
  staging: mt7621-mmc: Remove unused macro msdc_txfifocnt
  staging: mt7621-mmc: Remove unused macro msdc_rxfifocnt
  staging: mt7621-mmc: Replace sdr_write32 with writel
  staging: mt7621-mmc: Replace sdr_read32 with readl
  staging: mt7621-mmc: Remove unused macro sdr_read8
  staging: mt7621-mmc: Remove unused macro sdr_write8
  staging: mt7621-mmc: Remove register debugging structures
  staging: mt7621-mmc: Remove DMA basic mode code
  staging: mt7621-mmc: Remove unused field mode from msdc_dma
  staging: mt7621-mmc: Refactor dma setup process
  staging: mt7621-mmc: Remove unused field sg from msdc_dma
  staging: mt7621-mmc: Remove unused field sglen from msdc_dma
  staging: mt7621-mmc: Remove variable num form msdc_dma_setup
  staging: mt7621-mmc: Remove unnecessary BUG_ON() in msdc_dma_setup
  staging: mt7621-mmc: Make msdc_clr_fifo a function and relax cpu
  staging: mt7621-mmc: Remove unused macro msdc_retry
  staging: mt7621-mmc: Remove unused macro MAX_BD_PER_GPD
  staging: mt7621-mmc: Remove unused variable from msdc_tune_request
  staging: mt7621-mmc: Remove MSDC_MODE_* defines
  staging: mt7621-mmc: Cleanup source of base address for io
  staging: mt7621-mmc: Remove unused define RALINK_MSDC_BASE
  staging: mt7621-mmc: Remove unused define IRQ_SDC
  staging: mt7621-mmc: Remove unused enum msdc_mode
  staging: mt7621-mmc: Remove unused define MAX_PHY_SGMTS
  staging: mt7621-mmc: Remove unused macro is_card_present
  staging: mt7621-mmc: Remove unused argument from msdc_do_command
  staging: mt7621-mmc: Factor out from msdc_command_start()
  staging: mt7621-mmc: Find response of MMC_SEND_OP_COND by default
  staging: mt7621-mmc: Find response of SD_APP_OP_COND by default

 drivers/staging/mt7621-mmc/dbg.h   |   6 -
 drivers/staging/mt7621-mmc/mt6575_sd.h | 588 +++--
 drivers/staging/mt7621-mmc/sd.c| 584 +++-
 3 files changed, 305 insertions(+), 873 deletions(-)

-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 17/34] staging: mt7621-mmc: Remove unused field sglen from msdc_dma

2018-06-11 Thread Christian Lütke-Stetzkamp
The field sglen from struct msdc_dma is once set and never read, so
remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 2 --
 drivers/staging/mt7621-mmc/sd.c| 2 --
 2 files changed, 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index c8c5c349adf8..4b56d9a37b84 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -479,8 +479,6 @@ struct bd {
 };
 
 struct msdc_dma {
-   u32 sglen;   /* size of scatter list */
-
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
dma_addr_t gpd_addr; /* the physical address of gpd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 050c4a910aef..e1077068604d 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1041,8 +1041,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
-   dma->sglen = sglen;
-
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 18/34] staging: mt7621-mmc: Remove variable num form msdc_dma_setup

2018-06-11 Thread Christian Lütke-Stetzkamp
The variable num in msdc_dma_setup is only used for a BUG_ON
statement, so it can be removed by inlining the condition.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e1077068604d..68dfbf38b0ea 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1037,15 +1037,14 @@ static void msdc_dma_setup(struct msdc_host *host, 
struct msdc_dma *dma,
struct scatterlist *sg;
struct gpd *gpd;
struct bd *bd;
-   u32 j, num;
+   u32 j;
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
/* calculate the required number of gpd */
-   num = (sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
-   BUG_ON(num != 1);
+   BUG_ON(((sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD) != 1);
 
gpd = dma->gpd;
bd  = dma->bd;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 22/34] staging: mt7621-mmc: Remove unused macro MAX_BD_PER_GPD

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro MAX_BD_PER_GPD is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0e94bb0d5927..e99a12002646 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -91,7 +91,6 @@
 
 #define MAX_GPD_NUM (1 + 1)  /* one null gpd */
 #define MAX_BD_NUM  (1024)
-#define MAX_BD_PER_GPD  (MAX_BD_NUM)
 
 #define MAX_HW_SGMTS(MAX_BD_NUM)
 #define MAX_PHY_SGMTS   (MAX_BD_NUM)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/34] staging: mt7621-mmc: Replace sdr_read32 with readl

2018-06-11 Thread Christian Lütke-Stetzkamp
The current code uses a macro (sdr_read32) for reading from hardware,
but it is only a readl, so replace it to get nearer to upstream code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h |  1 -
 drivers/staging/mt7621-mmc/sd.c| 98 +-
 2 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index e8e79aab52f8..29e2ede6816b 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -948,7 +948,6 @@ struct msdc_host {
 };
 
 #define sdr_read8(reg)readb(reg)
-#define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e6232f5ac6a8..1d0829e6 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -167,13 +167,13 @@ static void msdc_reset_hw(struct msdc_host *host)
void __iomem *base = host->base;
 
sdr_set_bits(MSDC_CFG, MSDC_CFG_RST);
-   while (sdr_read32(MSDC_CFG) & MSDC_CFG_RST)
+   while (readl(MSDC_CFG) & MSDC_CFG_RST)
cpu_relax();
 }
 
 #define msdc_clr_int() \
do {\
-   volatile u32 val = sdr_read32(MSDC_INT);\
+   volatile u32 val = readl(MSDC_INT); \
writel(val, MSDC_INT);  \
} while (0)
 
@@ -181,12 +181,12 @@ static void msdc_reset_hw(struct msdc_host *host)
do {\
int retry = 3, cnt = 1000;  \
sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR); \
-   msdc_retry(sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, 
cnt); \
+   msdc_retry(readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, cnt); \
} while (0)
 
 #define msdc_irq_save(val) \
do {\
-   val = sdr_read32(MSDC_INTEN);   \
+   val = readl(MSDC_INTEN);\
sdr_clr_bits(MSDC_INTEN, val);  \
} while (0)
 
@@ -230,8 +230,8 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
(void)hwPowerDown(MT65XX_POWER_LDO_VMCH, "SD"); \
} while (0)
 
-#define sdc_is_busy()  (sdr_read32(SDC_STS) & SDC_STS_SDCBUSY)
-#define sdc_is_cmd_busy()  (sdr_read32(SDC_STS) & SDC_STS_CMDBUSY)
+#define sdc_is_busy()  (readl(SDC_STS) & SDC_STS_SDCBUSY)
+#define sdc_is_cmd_busy()  (readl(SDC_STS) & SDC_STS_CMDBUSY)
 
 #define sdc_send_cmd(cmd, arg) \
do {\
@@ -240,7 +240,7 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
} while (0)
 
 // can modify to read h/w register.
-//#define is_card_present(h)   ((sdr_read32(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
+//#define is_card_present(h)   ((readl(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
 #define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
 
 /* +++ by chhung */
@@ -426,7 +426,7 @@ static void msdc_tasklet_card(struct work_struct *work)
 
spin_lock(&host->lock);
 
-   status = sdr_read32(MSDC_PS);
+   status = readl(MSDC_PS);
if (cd_active_low)
inserted = (status & MSDC_PS_CDSTS) ? 0 : 1;
else
@@ -469,8 +469,8 @@ static void msdc_select_clksrc(struct msdc_host *host, 
unsigned char clksrc)
BUG_ON(clksrc > 3);
INIT_MSG("set clock source to <%d>", clksrc);
 
-   val = sdr_read32(MSDC_CLKSRC_REG);
-   if (sdr_read32(MSDC_ECO_VER) >= 4) {
+   val = readl(MSDC_CLKSRC_REG);
+   if (readl(MSDC_ECO_VER) >= 4) {
val &= ~(0x3  << clk_src_bit[host->id]);
val |= clksrc << clk_src_bit[host->id];
} else {
@@ -531,7 +531,7 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, 
unsigned int hz)
sdr_set_field(MSDC_CFG, MSDC_CFG_CKDIV, div);
 
/* wait clock stable */
-   while (!(sdr_read32(MSDC_CFG) & MSDC_CFG_CKSTB))
+   while (!(readl(MSDC_CFG) & MSDC_CFG_CKSTB))
cpu_relax();
 
host->sclk = sclk;
@@ -940,7 +940,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
 
/* memory card CRC */
if (host->hw->flags & MSDC_REMOVABLE && cmd->error == -EIO) {
-   if (sdr_read32(SDC_CMD) & 0x1800) { /* check if has data phase 
*/
+   if (readl(SDC_CMD) & 0x1800) { /* check if has data phase */
msdc_abort_data(host);
} else {
/* do ba

[PATCH 03/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_read8

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_read8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 4a69bc84bbd2..98bcb0fe6f40 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -151,7 +151,6 @@ static int msdc_rsp[] = {
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 #define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
-#define msdc_fifo_read8()sdr_read8(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 24/34] staging: mt7621-mmc: Remove MSDC_MODE_* defines

2018-06-11 Thread Christian Lütke-Stetzkamp
The MSDC_MODE_* defines are all never used and do not contain any
information about the device, so remove them.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 4b56d9a37b84..9b6cd6db37df 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -56,13 +56,6 @@
 #define MSDC_MS (0)
 #define MSDC_SDMMC  (1)
 
-#define MSDC_MODE_UNKNOWN   (0)
-#define MSDC_MODE_PIO   (1)
-#define MSDC_MODE_DMA_BASIC (2)
-#define MSDC_MODE_DMA_DESC  (3)
-#define MSDC_MODE_DMA_ENHANCED  (4)
-#define MSDC_MODE_MMC_STREAM(5)
-
 #define MSDC_BUS_1BITS  (0)
 #define MSDC_BUS_4BITS  (1)
 #define MSDC_BUS_8BITS  (2)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 31/34] staging: mt7621-mmc: Remove unused argument from msdc_do_command

2018-06-11 Thread Christian Lütke-Stetzkamp
The argument tune of msdc_do_command is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index cfe7517f8bdf..93f14c9694b9 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,7 +710,6 @@ static void msdc_pm(pm_message_t state, void *data)
 /*--*/
 static unsigned int msdc_command_start(struct msdc_host   *host,
   struct mmc_command *cmd,
-  int tune,   /* not used 
*/
   unsigned long   timeout)
 {
u32 opcode = cmd->opcode;
@@ -932,7 +931,7 @@ static unsigned int msdc_do_command(struct msdc_host   
*host,
int tune,
unsigned long   timeout)
 {
-   if (msdc_command_start(host, cmd, tune, timeout))
+   if (msdc_command_start(host, cmd, timeout))
goto end;
 
if (msdc_command_resp(host, cmd, tune, timeout))
@@ -1098,7 +1097,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
init_completion(&host->xfer_done);
 
/* start the command first*/
-   if (msdc_command_start(host, cmd, 1, CMD_TIMEOUT) != 0)
+   if (msdc_command_start(host, cmd, CMD_TIMEOUT) != 0)
goto done;
 
data->sg_count = dma_map_sg(mmc_dev(mmc), data->sg,
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 29/34] staging: mt7621-mmc: Remove unused define MAX_PHY_SGMTS

2018-06-11 Thread Christian Lütke-Stetzkamp
The define MAX_PHY_SGMTS is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 31ee9c533f35..45d9b62f4a58 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -89,7 +89,6 @@
 #define MAX_BD_NUM  (1024)
 
 #define MAX_HW_SGMTS(MAX_BD_NUM)
-#define MAX_PHY_SGMTS   (MAX_BD_NUM)
 #define MAX_SGMT_SZ (MAX_DMA_CNT)
 #define MAX_REQ_SZ  (MAX_SGMT_SZ * 8)
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/34] staging: mt7621-mmc: Remove unused macro sdr_read8

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro sdr_read8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 29e2ede6816b..adccabe32660 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -947,7 +947,6 @@ struct msdc_host {
u32 app_cmd_arg;
 };
 
-#define sdr_read8(reg)readb(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 27/34] staging: mt7621-mmc: Remove unused define IRQ_SDC

2018-06-11 Thread Christian Lütke-Stetzkamp
The define IRQ_SDC is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 101ceca2ee4c..31ee9c533f35 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -50,13 +50,11 @@
 #include "dbg.h"
 #include "mt6575_sd.h"
 
-//#define IRQ_SDC 14   //MT7620 /*FIXME*/
 #ifdef CONFIG_SOC_MT7621
 #define RALINK_SYSCTL_BASE 0xbe00
 #else
 #define RALINK_SYSCTL_BASE 0xb000
 #endif
-#define IRQ_SDC22  /*FIXME*/
 
 #define DRV_NAME"mtk-sd"
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 14/34] staging: mt7621-mmc: Remove unused field mode from msdc_dma

2018-06-11 Thread Christian Lütke-Stetzkamp
The field mode of struct msdc_dma has no remaining use, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 5 +
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 07f48d526888..8eb30d908f9d 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -481,7 +481,6 @@ struct bd {
 struct msdc_dma {
u32 sglen;   /* size of scatter list */
struct scatterlist *sg;  /* I/O scatter list */
-   u8  mode;/* dma mode*/
 
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 1196e8eb86c5..3066fa3799ac 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1091,10 +1091,7 @@ static void msdc_dma_setup(struct msdc_host *host, 
struct msdc_dma *dma,
dma->sg = sg;
dma->sglen = sglen;
 
-   dma->mode = MSDC_MODE_DMA_DESC;
-
-   N_MSG(DMA, "DMA mode<%d> sglen<%d> xfersz<%d>", dma->mode, dma->sglen,
- host->xfer_size);
+   N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", dma->sglen, host->xfer_size);
 
msdc_dma_config(host, dma);
 }
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 32/34] staging: mt7621-mmc: Factor out from msdc_command_start()

2018-06-11 Thread Christian Lütke-Stetzkamp
Currently msdc_command_start does multiple things and is hard to read,
so factor out the finding of the response type.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 40 +---
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 93f14c9694b9..c02799acb9e4 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -705,25 +705,11 @@ static void msdc_pm(pm_message_t state, void *data)
 }
 #endif
 
-/*--*/
-/* mmc_host_ops members  */
-/*--*/
-static unsigned int msdc_command_start(struct msdc_host   *host,
-  struct mmc_command *cmd,
-  unsigned long   timeout)
+static inline u32 msdc_cmd_find_resp(struct mmc_command cmd)
 {
u32 opcode = cmd->opcode;
-   u32 rawcmd;
-   u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
-   MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
-   MSDC_INT_ACMD19_DONE;
-
u32 resp;
-   unsigned long tmo;
 
-   /* Protocol layer does not provide response type, but our hardware needs
-* to know exact type, not just size!
-*/
if (opcode == MMC_SEND_OP_COND || opcode == SD_APP_OP_COND) {
resp = RESP_R3;
} else if (opcode == MMC_SET_RELATIVE_ADDR) {
@@ -759,6 +745,30 @@ static unsigned int msdc_command_start(struct msdc_host   
*host,
}
}
 
+   return resp;
+}
+
+/*--*/
+/* mmc_host_ops members  */
+/*--*/
+static unsigned int msdc_command_start(struct msdc_host   *host,
+  struct mmc_command *cmd,
+  unsigned long   timeout)
+{
+   u32 opcode = cmd->opcode;
+   u32 rawcmd;
+   u32 wints = MSDC_INT_CMDRDY  | MSDC_INT_RSPCRCERR  | MSDC_INT_CMDTMO  |
+   MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR | MSDC_INT_ACMDTMO |
+   MSDC_INT_ACMD19_DONE;
+
+   u32 resp;
+   unsigned long tmo;
+
+   /* Protocol layer does not provide response type, but our hardware needs
+* to know exact type, not just size!
+*/
+   resp = msdc_cmd_find_resp(cmd);
+
cmd->error = 0;
/* rawcmd :
 * vol_swt << 30 | auto_cmd << 28 | blklen << 16 | go_irq << 15 |
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 20/34] staging: mt7621-mmc: Make msdc_clr_fifo a function and relax cpu

2018-06-11 Thread Christian Lütke-Stetzkamp
In the current code, msdc_clr_fifo is a macro and just busy waits for
a limited amount of time for the fifo clear to finish. That is not
correct, the programming manual hits, that the user should wait until
the bit is cleared by hardware and not a limited amount of time.

So the code is changed to a function, that also relaxes the cpu while
busy waiting.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index a506c7e19086..01a925ae662e 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -177,12 +177,14 @@ static void msdc_reset_hw(struct msdc_host *host)
writel(val, MSDC_INT);  \
} while (0)
 
-#define msdc_clr_fifo() \
-   do {\
-   int retry = 3, cnt = 1000;  \
-   sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR); \
-   msdc_retry(readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR, retry, cnt); \
-   } while (0)
+static void msdc_clr_fifo(struct msdc_host *host)
+{
+   void __iomem *base = host->base;
+
+   sdr_set_bits(MSDC_FIFOCS, MSDC_FIFOCS_CLR);
+   while (readl(MSDC_FIFOCS) & MSDC_FIFOCS_CLR)
+   cpu_relax();
+}
 
 #define msdc_irq_save(val) \
do {\
@@ -554,7 +556,7 @@ static void msdc_abort_data(struct msdc_host *host)
ERR_MSG("Need to Abort.");
 
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
 
// need to check FIFO count 0 ?
@@ -945,7 +947,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
} else {
/* do basic: reset*/
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
cmd->error = msdc_tune_cmdrsp(host, cmd);
@@ -1131,7 +1133,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
}
 
writel(data->blocks, SDC_BLK_NUM);
-   //msdc_clr_fifo();  /* no need */
+   //msdc_clr_fifo(host);  /* no need */
 
msdc_dma_on();  /* enable DMA mode first!! */
init_completion(&host->xfer_done);
@@ -1165,7 +1167,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
data->error = -ETIMEDOUT;
 
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
spin_lock(&host->lock);
@@ -1868,7 +1870,7 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
if (intsts & datsts) {
/* do basic reset, or stop command will sdc_busy */
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
 
if (intsts & MSDC_INT_DATTMO) {
@@ -1917,7 +1919,7 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
IRQ_MSG("XXX CMD<%d> MSDC_INT_CMDTMO", 
cmd->opcode);
cmd->error = -ETIMEDOUT;
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
msdc_clr_int();
}
complete(&host->cmd_done);
@@ -2029,7 +2031,7 @@ static void msdc_init_hw(struct msdc_host *host)
 
/* Reset */
msdc_reset_hw(host);
-   msdc_clr_fifo();
+   msdc_clr_fifo(host);
 
/* Disable card detection */
sdr_clr_bits(MSDC_PS, MSDC_PS_CDEN);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/34] staging: mt7621-mmc: Remove unused macro sdr_write8

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro sdr_write8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index adccabe32660..375cb109806e 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -947,8 +947,6 @@ struct msdc_host {
u32 app_cmd_arg;
 };
 
-#define sdr_write8(reg, val)  writeb(val, reg)
-
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
 {
u32 val = readl(reg);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/34] staging: mt7621-mmc: Replace sdr_write32 with writel

2018-06-11 Thread Christian Lütke-Stetzkamp
The current code uses a macro (sdr_write32) for writing to hardware,
but it is only a writel with switched arguments, so replace it to get
nearer to upstream code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h |  1 -
 drivers/staging/mt7621-mmc/sd.c| 64 +-
 2 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 33fa59a019ec..e8e79aab52f8 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -950,7 +950,6 @@ struct msdc_host {
 #define sdr_read8(reg)readb(reg)
 #define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
-#define sdr_write32(reg, val) writel(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
 {
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 78a681a72f11..e6232f5ac6a8 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -174,7 +174,7 @@ static void msdc_reset_hw(struct msdc_host *host)
 #define msdc_clr_int() \
do {\
volatile u32 val = sdr_read32(MSDC_INT);\
-   sdr_write32(MSDC_INT, val); \
+   writel(val, MSDC_INT);  \
} while (0)
 
 #define msdc_clr_fifo() \
@@ -235,8 +235,8 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
 
 #define sdc_send_cmd(cmd, arg) \
do {\
-   sdr_write32(SDC_ARG, (arg));\
-   sdr_write32(SDC_CMD, (cmd));\
+   writel((arg), SDC_ARG); \
+   writel((cmd), SDC_CMD); \
} while (0)
 
 // can modify to read h/w register.
@@ -476,7 +476,7 @@ static void msdc_select_clksrc(struct msdc_host *host, 
unsigned char clksrc)
} else {
val &= ~0x3; val |= clksrc;
}
-   sdr_write32(MSDC_CLKSRC_REG, val);
+   writel(val, MSDC_CLKSRC_REG);
 
host->hclk = hclks[clksrc];
host->hw->clk_src = clksrc;
@@ -1044,14 +1044,14 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
case MSDC_MODE_DMA_BASIC:
BUG_ON(host->xfer_size > 65535);
BUG_ON(dma->sglen != 1);
-   sdr_write32(MSDC_DMA_SA, PHYSADDR(sg_dma_address(sg)));
+   writel(PHYSADDR(sg_dma_address(sg)), MSDC_DMA_SA);
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_LASTBUF, 1);
 //#if defined (CONFIG_RALINK_MT7620)
if (ralink_soc == MT762X_SOC_MT7620A)
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_XFERSZ, 
sg_dma_len(sg));
 //#elif defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628)
else
-   sdr_write32((void __iomem *)(RALINK_MSDC_BASE + 0xa8), 
sg_dma_len(sg));
+   writel(sg_dma_len(sg), (void __iomem 
*)(RALINK_MSDC_BASE + 0xa8));
 //#endif
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
  MSDC_BRUST_64B);
@@ -1094,7 +1094,7 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
  MSDC_BRUST_64B);
sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
 
-   sdr_write32(MSDC_DMA_SA, PHYSADDR((u32)dma->gpd_addr));
+   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
break;
 
default:
@@ -1172,7 +1172,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
}
}
 
-   sdr_write32(SDC_BLK_NUM, data->blocks);
+   writel(data->blocks, SDC_BLK_NUM);
//msdc_clr_fifo();  /* no need */
 
msdc_dma_on();  /* enable DMA mode first!! */
@@ -1465,8 +1465,8 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct 
mmc_request *mrq)
cur_rxdly0 = (cur_dat0 << 24) | (cur_dat1 << 16) | (cur_dat2 << 
8) | (cur_dat3 << 0);
cur_rxdly1 = (cur_dat4 << 24) | (cur_dat5 << 16) | (cur_dat6 << 
8) | (cur_dat7 << 0);
 
-   sdr_write32(MSDC_DAT_RDDLY0, cur_rxdly0);
-   sdr_write32(MSDC_DAT_RDDLY1, cur_rxdly1);
+   writel(cur_rxdly0, MSDC_DAT_RDDLY0);
+   writel(cur_rxdly1, MSDC_DAT_RDDLY1);
 
} while (++rxdly < 32);
 
@@ -1555,7 +1555,7 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct 
mmc_request *mrq)
cur_dat3 = orig_dat3;
 
cur_rxdly0 = (cur_dat0 << 24) | (cur_dat1 << 16) | (cur_dat2 << 
8) | (cur_dat3 << 0);
-   sdr_write32(MSDC_DAT_RDDLY0, cur_rxdl

[PATCH 34/34] staging: mt7621-mmc: Find response of SD_APP_OP_COND by default

2018-06-11 Thread Christian Lütke-Stetzkamp
The response type of the SD_APP_OP_COND command is correctly
determined using the mmc_resp_type macro, because the only use of that
opcode, mmc_send_app_op_cond, correctly places MMC_RSP_R3 in cmd.flags.

So there is no need to treat that opcode separately.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 3f4de63b25a8..f1b3472b96c3 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,9 +710,7 @@ static inline u32 msdc_cmd_find_resp(struct mmc_command cmd)
u32 opcode = cmd->opcode;
u32 resp;
 
-   if (opcode == SD_APP_OP_COND) {
-   resp = RESP_R3;
-   } else if (opcode == MMC_SET_RELATIVE_ADDR) {
+   if (opcode == MMC_SET_RELATIVE_ADDR) {
resp = (mmc_cmd_type(cmd) == MMC_CMD_BCR) ? RESP_R6 : RESP_R1;
} else if (opcode == MMC_FAST_IO) {
resp = RESP_R4;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 19/34] staging: mt7621-mmc: Remove unnecessary BUG_ON() in msdc_dma_setup

2018-06-11 Thread Christian Lütke-Stetzkamp
The BUG_ON() removed by this patch is just a duplicate of a prior
BUG_ON() statement. There the condition is just clearer, it checks
weather sglen > MAX_BD_NUM and MAX_BD_NUM is equal MAX_BD_PER_GPD. So
this statement can be safely removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 68dfbf38b0ea..a506c7e19086 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1043,9 +1043,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
 
-   /* calculate the required number of gpd */
-   BUG_ON(((sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD) != 1);
-
gpd = dma->gpd;
bd  = dma->bd;
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 28/34] staging: mt7621-mmc: Remove unused enum msdc_mode

2018-06-11 Thread Christian Lütke-Stetzkamp
The enum msdc_mode is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/dbg.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/dbg.h b/drivers/staging/mt7621-mmc/dbg.h
index 5a25a69b00c9..2f2c56b73987 100644
--- a/drivers/staging/mt7621-mmc/dbg.h
+++ b/drivers/staging/mt7621-mmc/dbg.h
@@ -73,12 +73,6 @@ enum msdc_dbg {
SD_TOOL_SDIO_PROFILE = 3,
 };
 
-enum msdc_mode {
-   MODE_PIO = 0,
-   MODE_DMA = 1,
-   MODE_SIZE_DEP = 2,
-};
-
 /* Debug message event */
 #define DBG_EVT_NONE(0)   /* No event */
 #define DBG_EVT_DMA (1 << 0)  /* DMA related event */
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/34] staging: mt7621-mmc: Remove unused field sg from msdc_dma

2018-06-11 Thread Christian Lütke-Stetzkamp
The field sg from struct msdc_dma is once set and never read, so
remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 8eb30d908f9d..c8c5c349adf8 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -480,7 +480,6 @@ struct bd {
 
 struct msdc_dma {
u32 sglen;   /* size of scatter list */
-   struct scatterlist *sg;  /* I/O scatter list */
 
struct gpd *gpd;  /* pointer to gpd array */
struct bd  *bd;   /* pointer to bd array */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 923b0687918d..050c4a910aef 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1041,7 +1041,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct 
msdc_dma *dma,
 
BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
 
-   dma->sg = sg_cmd;
dma->sglen = sglen;
 
N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_write8

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_write8 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 7cfadb41a53d..4a69bc84bbd2 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -150,7 +150,6 @@ static int msdc_rsp[] = {
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 #define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
-#define msdc_fifo_write8(v)sdr_write8(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 #define msdc_fifo_read8()sdr_read8(MSDC_RXDATA)
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_read32

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_read32 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 9e00f86a0398..0f9cba918586 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,7 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-#define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 30/34] staging: mt7621-mmc: Remove unused macro is_card_present

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro is_card_present is unused and also a duplicate of a macro in
mmc, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 45d9b62f4a58..cfe7517f8bdf 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -218,10 +218,6 @@ static u32 hclks[] = {5000}; /* +/- by chhung */
writel((cmd), host->base + SDC_CMD);\
} while (0)
 
-// can modify to read h/w register.
-//#define is_card_present(h)   ((readl(MSDC_PS) & MSDC_PS_CDSTS) ? 0 : 1);
-#define is_card_present(h) (((struct msdc_host *)(h))->card_inserted)
-
 /* +++ by chhung */
 #ifndef __ASSEMBLY__
 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fff)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/34] staging: mt7621-mmc: Remove unused macro msdc_fifo_write32

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_fifo_write32 is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 98bcb0fe6f40..9e00f86a0398 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -149,7 +149,6 @@ static int msdc_rsp[] = {
 
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-#define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
 #define msdc_fifo_read32()   sdr_read32(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 33/34] staging: mt7621-mmc: Find response of MMC_SEND_OP_COND by default

2018-06-11 Thread Christian Lütke-Stetzkamp
The response type of the MMC_SEND_OP_COND command is correctly
determined using the mmc_resp_type macro, because the only use of that
opcode, mmc_send_op_cond, correctly places MMC_RSP_R3 in cmd.flags.

So there is no need to treat that opcode separately.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index c02799acb9e4..3f4de63b25a8 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -710,7 +710,7 @@ static inline u32 msdc_cmd_find_resp(struct mmc_command cmd)
u32 opcode = cmd->opcode;
u32 resp;
 
-   if (opcode == MMC_SEND_OP_COND || opcode == SD_APP_OP_COND) {
+   if (opcode == SD_APP_OP_COND) {
resp = RESP_R3;
} else if (opcode == MMC_SET_RELATIVE_ADDR) {
resp = (mmc_cmd_type(cmd) == MMC_CMD_BCR) ? RESP_R6 : RESP_R1;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/34] staging: mt7621-mmc: Remove unused macro msdc_rxfifocnt

2018-06-11 Thread Christian Lütke-Stetzkamp
The macro msdc_rxfifocnt is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index c6aced0c0a6a..78a681a72f11 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -147,8 +147,6 @@ static int msdc_rsp[] = {
7,  /* RESP_R1b */
 };
 
-#define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
-
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
 
 #define msdc_retry(expr, retry, cnt) \
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 26/34] staging: mt7621-mmc: Remove unused define RALINK_MSDC_BASE

2018-06-11 Thread Christian Lütke-Stetzkamp
The define RALINK_MSDC_BASE is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e639ceb2ba85..101ceca2ee4c 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -53,10 +53,8 @@
 //#define IRQ_SDC 14   //MT7620 /*FIXME*/
 #ifdef CONFIG_SOC_MT7621
 #define RALINK_SYSCTL_BASE 0xbe00
-#define RALINK_MSDC_BASE   0xbe13
 #else
 #define RALINK_SYSCTL_BASE 0xb000
-#define RALINK_MSDC_BASE   0xb013
 #endif
 #define IRQ_SDC22  /*FIXME*/
 
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/34] staging: mt7621-mmc: Remove DMA basic mode code

2018-06-11 Thread Christian Lütke-Stetzkamp
The driver currently only uses DMA linked mode and the upstream
driver does the same, so remove the basic mode code.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 88 +++--
 1 file changed, 32 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 1d0829e6..1196e8eb86c5 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1040,66 +1040,42 @@ static void msdc_dma_config(struct msdc_host *host, 
struct msdc_dma *dma)
struct gpd *gpd;
struct bd *bd;
 
-   switch (dma->mode) {
-   case MSDC_MODE_DMA_BASIC:
-   BUG_ON(host->xfer_size > 65535);
-   BUG_ON(dma->sglen != 1);
-   writel(PHYSADDR(sg_dma_address(sg)), MSDC_DMA_SA);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_LASTBUF, 1);
-//#if defined (CONFIG_RALINK_MT7620)
-   if (ralink_soc == MT762X_SOC_MT7620A)
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_XFERSZ, 
sg_dma_len(sg));
-//#elif defined (CONFIG_RALINK_MT7621) || defined (CONFIG_RALINK_MT7628)
+   /* calculate the required number of gpd */
+   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
+   BUG_ON(num != 1);
+
+   gpd = dma->gpd;
+   bd  = dma->bd;
+
+   /* modify gpd*/
+   //gpd->intr = 0;
+   gpd->hwo = 1;  /* hw will clear it */
+   gpd->bdp = 1;
+   gpd->chksum = 0;  /* need to clear first. */
+   gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
+
+   /* modify bd*/
+   for_each_sg(dma->sg, sg, dma->sglen, j) {
+   bd[j].blkpad = 0;
+   bd[j].dwpad = 0;
+   bd[j].ptr = (void *)sg_dma_address(sg);
+   bd[j].buflen = sg_dma_len(sg);
+
+   if (j == dma->sglen - 1)
+   bd[j].eol = 1;  /* the last bd */
else
-   writel(sg_dma_len(sg), (void __iomem 
*)(RALINK_MSDC_BASE + 0xa8));
-//#endif
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
- MSDC_BRUST_64B);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 0);
-   break;
-   case MSDC_MODE_DMA_DESC:
-
-   /* calculate the required number of gpd */
-   num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD;
-   BUG_ON(num != 1);
-
-   gpd = dma->gpd;
-   bd  = dma->bd;
-
-   /* modify gpd*/
-   //gpd->intr = 0;
-   gpd->hwo = 1;  /* hw will clear it */
-   gpd->bdp = 1;
-   gpd->chksum = 0;  /* need to clear first. */
-   gpd->chksum = msdc_dma_calcs((u8 *)gpd, 16);
-
-   /* modify bd*/
-   for_each_sg(dma->sg, sg, dma->sglen, j) {
-   bd[j].blkpad = 0;
-   bd[j].dwpad = 0;
-   bd[j].ptr = (void *)sg_dma_address(sg);
-   bd[j].buflen = sg_dma_len(sg);
-
-   if (j == dma->sglen - 1)
-   bd[j].eol = 1;  /* the last bd */
-   else
-   bd[j].eol = 0;
+   bd[j].eol = 0;
 
-   bd[j].chksum = 0; /* checksume need to clear first */
-   bd[j].chksum = msdc_dma_calcs((u8 *)(&bd[j]), 16);
-   }
+   bd[j].chksum = 0; /* checksume need to clear first */
+   bd[j].chksum = msdc_dma_calcs((u8 *)(&bd[j]), 16);
+   }
 
-   sdr_set_field(MSDC_DMA_CFG, MSDC_DMA_CFG_DECSEN, 1);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
- MSDC_BRUST_64B);
-   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
+   sdr_set_field(MSDC_DMA_CFG, MSDC_DMA_CFG_DECSEN, 1);
+   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ,
+ MSDC_BRUST_64B);
+   sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
 
-   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
-   break;
-
-   default:
-   break;
-   }
+   writel(PHYSADDR((u32)dma->gpd_addr), MSDC_DMA_SA);
 
N_MSG(DMA, "DMA_CTRL = 0x%x", readl(MSDC_DMA_CTRL));
N_MSG(DMA, "DMA_CFG  = 0x%x", readl(MSDC_DMA_CFG));
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/30] staging: mt7621-mmc: Next cleanups

2018-04-30 Thread Christian Lütke-Stetzkamp
On Mon, Apr 30, 2018 at 08:57:38AM +1000, NeilBrown wrote:
> On Sun, Apr 29 2018, Christian Lütke-Stetzkamp wrote:
> 
> > Here are the next cleanups for the mt7621-mmc driver. It contains the
> > removal of some unused things, the removal of the non DMA code and
> > always using linked DMA mode together with some minor cleanups.
> 
> Thanks for these.
> As mentioned separately I found one bug, but the relevant code becomes
> inactive and can now be removed.

I totally overlooked the part of the function, where the bug is, was
already moving towards the removal, sorry. The removal will be in the
next series.

> I'm happy for this to go in as-is with a couple of fix-ups to come in
> the next batch.
> 
> I've tested and I can still access my sd card with no apparent issues.
> 
>  Reviewed-by: NeilBrown 

Thanks for your fast review,
Christian
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 24/30] staging: mt7621-mmc: Inline function msdc_set_blknum

2018-04-30 Thread Christian Lütke-Stetzkamp
On Mon, Apr 30, 2018 at 08:51:45AM +1000, NeilBrown wrote:
> On Sun, Apr 29 2018, Christian Lütke-Stetzkamp wrote:
> 
> > The function msdc_set_blknum consists of one (real) line of code and
> > is only called once, so inline it makes the code shorter and more
> > readable.
> >
> > Signed-off-by: Christian Lütke-Stetzkamp 
> > ---
> >  drivers/staging/mt7621-mmc/sd.c | 10 +-
> >  1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/drivers/staging/mt7621-mmc/sd.c 
> > b/drivers/staging/mt7621-mmc/sd.c
> > index c9f0180f3220..00c862b02419 100644
> > --- a/drivers/staging/mt7621-mmc/sd.c
> > +++ b/drivers/staging/mt7621-mmc/sd.c
> > @@ -1182,14 +1182,6 @@ static void msdc_dma_setup(struct msdc_host *host, 
> > struct msdc_dma *dma,
> > msdc_dma_config(host, dma);
> >  }
> >  
> > -/* set block number before send command */
> > -static void msdc_set_blknum(struct msdc_host *host, u32 blknum)
> > -{
> > -   void __iomem *base = host->base;
> > -
> > -   sdr_write32(SDC_BLK_NUM, blknum);
> > -}
> > -
> 
> This change is correct, but the reason isn't obvious.
> In mt6575_sd.h are:
> 
> #define SDC_BLK_NUM REG_ADDR(SDC_BLK_NUM)
> 
> #define REG_ADDR(x) (base + OFFSET_##x)
> 
> So the above becomes
> 
>sdr_write32((base + OFFSET_SDC_BLK_NUM), blknum);
> 
> so the base is important.
> 
> msdc_do_request() starts with
> 
>   void __iomem *base = host->base;
> 
> and never changes host.  So that "base" that is used in the new code is
> the same as the "base" used in the old code.
> 
> Ugh.. what a horrible way to write code!

Yes it is horrible and in a future cleanup I will remove all the
things depending on that "magic" base variable. But currently this is
the common (bad) idiom all over this driver and I would like to
address them all at once.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 11/30] staging: mt7621-mmc: Replace macro sdr_get_field with function

2018-04-30 Thread Christian Lütke-Stetzkamp
On Mon, Apr 30, 2018 at 08:33:07AM +1000, NeilBrown wrote:
> On Sun, Apr 29 2018, Christian Lütke-Stetzkamp wrote:
> 
> > Currently sdr_get_field is a macro, to bring the code in line with the
> > upstream driver mtk-sd, it is changed to a function.
> >
> > Signed-off-by: Christian Lütke-Stetzkamp 
> > ---
> >  drivers/staging/mt7621-mmc/mt6575_sd.h | 10 +-
> >  drivers/staging/mt7621-mmc/sd.c| 14 --
> >  2 files changed, 13 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
> > b/drivers/staging/mt7621-mmc/mt6575_sd.h
> > index 90b4ee6b396b..195c7333f77d 100644
> > --- a/drivers/staging/mt7621-mmc/mt6575_sd.h
> > +++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
> > @@ -980,10 +980,10 @@ static inline void sdr_set_field(void __iomem *reg, 
> > u32 field, u32 val)
> > writel(tv, reg);
> >  }
> >  
> > -#define sdr_get_field(reg, field, val) 
> > \
> > -do {   \
> > -   volatile unsigned int tv = sdr_read32(reg); \
> > -   val = ((tv & (field)) >> (ffs((unsigned int)field) - 1));   \
> > -} while (0)
> > +static inline void sdr_get_field(void __iomem *reg, u32 field, u32 *val)
> > +{
> > +   unsigned int tv = readl(reg);
> > +   *val = ((tv & field) >> (ffs((unsigned int)field) - 1));
> > +}
> 
> Converting this to a function it good, but it should return val rather
> than set *val.

Yes, I completely agree, that your proposal is easier to understand,
again the reason for me to choose the current version is the current
code in the mtk-sd driver.

> >  
> >  #endif
> > diff --git a/drivers/staging/mt7621-mmc/sd.c 
> > b/drivers/staging/mt7621-mmc/sd.c
> > index 00dacf8c9625..f4da48a5772b 100644
> > --- a/drivers/staging/mt7621-mmc/sd.c
> > +++ b/drivers/staging/mt7621-mmc/sd.c
> > @@ -1577,8 +1577,8 @@ static int msdc_tune_cmdrsp(struct msdc_host *host, 
> > struct mmc_command *cmd)
> >==*/
> >  
> > // save the previous tune result
> > -   sdr_get_field(MSDC_IOCON,MSDC_IOCON_RSPL,orig_rsmpl);
> > -   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_CMDRRDLY, orig_rrdly);
> > +   sdr_get_field(MSDC_IOCON,MSDC_IOCON_RSPL,&orig_rsmpl);
> > +   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_CMDRRDLY, &orig_rrdly);
> 
> So this becomes
> 
> > +   orig_rsmpl = sdr_get_field(MSDC_IOCON,MSDC_IOCON_RSPL);
> > +   orig_rrdly = sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_CMDRRDLY);
> 
> which is much easier to understand at first glance.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 09/30] staging: mt7621-mmc: Remove function uffs

2018-04-30 Thread Christian Lütke-Stetzkamp
On Mon, Apr 30, 2018 at 08:28:26AM +1000, NeilBrown wrote:
> On Sun, Apr 29 2018, Christian Lütke-Stetzkamp wrote:
> 
> > The function uffs that is implemented by this driver returns the same
> > values as the kernel function ffs. So the uffs function is removed and
> > the calls to it are replaced with calls to ffs.
> 
> This difference is that uffs receives and returns an "unsigned int".
> Maybe not a significant difference, but worth mentioning that you
> noticed it and reasoned that it wasn't significant.
>
Yes the type of the uffs function is unsigned int but I tested it for
all values, that the number returned is the same (in binary form). So
I don't think that it is significant.

> > @@ -1004,13 +975,13 @@ static inline void sdr_clr_bits(void __iomem *reg, 
> > u32 bs)
> >  do {   \
> > volatile unsigned int tv = sdr_read32(reg); \
> > tv &= ~(field); \
> > -   tv |= ((val) << (uffs((unsigned int)field) - 1));   \
> > +   tv |= ((val) << (ffs((unsigned int)field) - 1));\
> 
> Given that ffs() takes an "int", it is odd to cast "field" to an
> unsigned int to pass it.
> "field" is always a constant int, so no cast is needed.

That's correct, but I took it that way, because that is how the mtk-sd
driver does it. This makes the similarities more significant, but if
you like I'll change it.

Regards,
Christian
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/30] staging: mt7621-mmc: Remove function uffs

2018-04-29 Thread Christian Lütke-Stetzkamp
The function uffs that is implemented by this driver returns the same
values as the kernel function ffs. So the uffs function is removed and
the calls to it are replaced with calls to ffs.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 33 ++---
 1 file changed, 2 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 62e6beefa3db..5a50b6a47469 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -950,35 +950,6 @@ struct msdc_host {
u32 app_cmd_arg;
 };
 
-static inline unsigned int uffs(unsigned int x)
-{
-   unsigned int r = 1;
-
-   if (!x)
-   return 0;
-   if (!(x & 0x)) {
-   x >>= 16;
-   r += 16;
-   }
-   if (!(x & 0xff)) {
-   x >>= 8;
-   r += 8;
-   }
-   if (!(x & 0xf)) {
-   x >>= 4;
-   r += 4;
-   }
-   if (!(x & 3)) {
-   x >>= 2;
-   r += 2;
-   }
-   if (!(x & 1)) {
-   x >>= 1;
-   r += 1;
-   }
-   return r;
-}
-
 #define sdr_read8(reg)readb(reg)
 #define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
@@ -1004,13 +975,13 @@ static inline void sdr_clr_bits(void __iomem *reg, u32 
bs)
 do {   \
volatile unsigned int tv = sdr_read32(reg); \
tv &= ~(field); \
-   tv |= ((val) << (uffs((unsigned int)field) - 1));   \
+   tv |= ((val) << (ffs((unsigned int)field) - 1));\
sdr_write32(reg, tv);   \
 } while (0)
 #define sdr_get_field(reg, field, val) \
 do {   \
volatile unsigned int tv = sdr_read32(reg); \
-   val = ((tv & (field)) >> (uffs((unsigned int)field) - 1));  \
+   val = ((tv & (field)) >> (ffs((unsigned int)field) - 1));   \
 } while (0)
 
 #endif
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/30] staging: mt7621-mmc: Remove unused field dat_drv from msdc_hw

2018-04-29 Thread Christian Lütke-Stetzkamp
The field dat_drv of msdc_hw is set to a constant and only used once,
replace that position with the constant and remove the unused field.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index 22edbb8bbc31..a2ad8237cf13 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -56,7 +56,6 @@ struct msdc_hw {
unsigned char  clk_src;  /* host clock source */
unsigned char  clk_drv;  /* clock pad driving */
unsigned char  cmd_drv;  /* command pad driving */
-   unsigned char  dat_drv;  /* data pad driving */
unsigned long  flags;/* hardware capability flags */
 
/* config gpio pull mode */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 9dba15edc812..0daf06f3c4a9 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -179,7 +179,6 @@ struct msdc_hw msdc0_hw = {
.clk_src= 0,
.clk_drv= 4,
.cmd_drv= 4,
-   .dat_drv= 4,
.flags  = MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 // .flags  = MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 };
@@ -2447,8 +2446,8 @@ static void msdc_init_hw(struct msdc_host *host)
sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVP, hw->clk_drv);
sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVN, hw->cmd_drv);
sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVP, hw->cmd_drv);
-   sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVN, hw->dat_drv);
-   sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVP, hw->dat_drv);
+   sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVN, 4);
+   sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVP, 4);
 #else
sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVN, 0);
sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVP, 0);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/30] staging: mt7621-mmc: Remove non-DMA transfer code

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently the driver is capable of DMA and non-DMA transfer. But the
option to choose non-DMA transfer has already been removed. Now remove
also the code for the non-DMA transfer.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 261 ++--
 1 file changed, 36 insertions(+), 225 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index c1640689aded..95b5db80250a 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1032,145 +1032,6 @@ static unsigned int msdc_do_command(struct msdc_host   
*host,
return cmd->error;
 }
 
-/* The abort condition when PIO read/write
-   tmo:
-*/
-static int msdc_pio_abort(struct msdc_host *host, struct mmc_data *data, 
unsigned long tmo)
-{
-   int  ret = 0;
-   void __iomem *base = host->base;
-
-   if (atomic_read(&host->abort))
-   ret = 1;
-
-   if (time_after(jiffies, tmo)) {
-   data->error = (unsigned int)-ETIMEDOUT;
-   ERR_MSG("XXX PIO Data Timeout: CMD<%d>", 
host->mrq->cmd->opcode);
-   ret = 1;
-   }
-
-   if (ret) {
-   msdc_reset_hw(host);
-   msdc_clr_fifo();
-   msdc_clr_int();
-   ERR_MSG("msdc pio find abort");
-   }
-   return ret;
-}
-
-/*
-   Need to add a timeout, or WDT timeout, system reboot.
-*/
-// pio mode data read/write
-static int msdc_pio_read(struct msdc_host *host, struct mmc_data *data)
-{
-   struct scatterlist *sg = data->sg;
-   void __iomem *base = host->base;
-   u32  num = data->sg_len;
-   u32 *ptr;
-   u8  *u8ptr;
-   u32  left = 0;
-   u32  count, size = 0;
-   u32  wints = MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR;
-   unsigned long tmo = jiffies + DAT_TIMEOUT;
-
-   sdr_set_bits(MSDC_INTEN, wints);
-   while (num) {
-   left = sg_dma_len(sg);
-   ptr = sg_virt(sg);
-   while (left) {
-   if ((left >=  MSDC_FIFO_THD) && (msdc_rxfifocnt() >= 
MSDC_FIFO_THD)) {
-   count = MSDC_FIFO_THD >> 2;
-   do {
-   *ptr++ = msdc_fifo_read32();
-   } while (--count);
-   left -= MSDC_FIFO_THD;
-   } else if ((left < MSDC_FIFO_THD) && msdc_rxfifocnt() 
>= left) {
-   while (left > 3) {
-   *ptr++ = msdc_fifo_read32();
-   left -= 4;
-   }
-
-   u8ptr = (u8 *)ptr;
-   while (left) {
-   *u8ptr++ = msdc_fifo_read8();
-   left--;
-   }
-   }
-
-   if (msdc_pio_abort(host, data, tmo))
-   goto end;
-   }
-   size += sg_dma_len(sg);
-   sg = sg_next(sg); num--;
-   }
-end:
-   data->bytes_xfered += size;
-   N_MSG(FIO, "PIO Read<%d>bytes", size);
-
-   sdr_clr_bits(MSDC_INTEN, wints);
-   if (data->error)
-   ERR_MSG("read pio data->error<%d> left<%d> size<%d>", 
data->error, left, size);
-   return data->error;
-}
-
-/* please make sure won't using PIO when size >= 512
-   which means, memory card block read/write won't using pio
-   then don't need to handle the CMD12 when data error.
-*/
-static int msdc_pio_write(struct msdc_host *host, struct mmc_data *data)
-{
-   void __iomem *base = host->base;
-   struct scatterlist *sg = data->sg;
-   u32  num = data->sg_len;
-   u32 *ptr;
-   u8  *u8ptr;
-   u32  left;
-   u32  count, size = 0;
-   u32  wints = MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR;
-   unsigned long tmo = jiffies + DAT_TIMEOUT;
-
-   sdr_set_bits(MSDC_INTEN, wints);
-   while (num) {
-   left = sg_dma_len(sg);
-   ptr = sg_virt(sg);
-
-   while (left) {
-   if (left >= MSDC_FIFO_SZ && msdc_txfifocnt() == 0) {
-   count = MSDC_FIFO_SZ >> 2;
-   do {
-   msdc_fifo_write32(*ptr); ptr++;
-   } while (--count);
-   left -= MSDC_FIFO_SZ;
-   } else if (left < MSDC_FIFO_SZ && msdc_txfifocnt() == 
0) {
-   while (left > 3) {
-  

[PATCH 01/30] staging: mt7621-mmc: Fix typo in function parameters

2018-04-29 Thread Christian Lütke-Stetzkamp
The type pm_message does not exist in the kernel, the correct type is
pm_message_t, so the type of the parameter is corrected.

Fixes: 9673d9f6f44b ("staging: mt7621-mmc: Refactor suspend, resume")
Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index a003f8324088..b78f68016190 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -2689,7 +2689,7 @@ static int msdc_drv_remove(struct platform_device *pdev)
 /* Fix me: Power Flow */
 #ifdef CONFIG_PM
 
-static void msdc_drv_pm(struct platform_device *pdev, pm_message state)
+static void msdc_drv_pm(struct platform_device *pdev, pm_message_t state)
 {
struct mmc_host *mmc = platform_get_drvdata(pdev);
if (mmc) {
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 22/30] staging: mt7621-mmc: Remove redundant check for card status

2018-04-29 Thread Christian Lütke-Stetzkamp
Current code checks the card status at the beginning of
msdc_ops_request. This is not necessary because mmc core always checks
the card status before calling this operation.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 7549ef40ac17..a2dce54e386c 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1718,20 +1718,6 @@ static void msdc_ops_request(struct mmc_host *mmc, 
struct mmc_request *mrq)
 
WARN_ON(host->mrq);
 
-   if (!is_card_present(host) || host->power_mode == MMC_POWER_OFF) {
-   ERR_MSG("cmd<%d> card<%d> power<%d>", mrq->cmd->opcode, 
is_card_present(host), host->power_mode);
-   mrq->cmd->error = -ENOMEDIUM;
-
-#if 1
-   mrq->done(mrq); // call done directly.
-#else
-   mrq->cmd->retries = 0;  // please don't retry.
-   mmc_request_done(mmc, mrq);
-#endif
-
-   return;
-   }
-
/* start to process */
spin_lock(&host->lock);
 #if 0 /* --- by chhung */
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/30] staging: mt7621-mmc: Remove transfer mode setting from proc

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently the transfer mode can be chosen between DMA, a size
dependent mode and non-DMA by writing to a proc file. The upstream
driver mtk-sd uses DMA all times.

There is no apparent reason why somebody would like to change the
transfer mode and the position of the setting in the debug part of the
driver also indicates, that the option was used for debugging
purposes. So it is removed to clean up the driver and bring it more in
line with the upstream one.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/dbg.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/dbg.c b/drivers/staging/mt7621-mmc/dbg.c
index 0d6e21557d8f..8f38484c8dbb 100644
--- a/drivers/staging/mt7621-mmc/dbg.c
+++ b/drivers/staging/mt7621-mmc/dbg.c
@@ -286,21 +286,6 @@ static ssize_t msdc_debug_proc_write(struct file *file,
} else {
printk("msdc host_id error when set debug zone\n");
}
-   } else if (cmd == SD_TOOL_DMA_SIZE) {
-   id = p1 >> 4;
-   mode = (p1 & 0xf);
-   size = p2;
-   if (id >= 0 && id <= 3) {
-   drv_mode[id] = mode;
-   dma_size[id] = p2;
-   } else if (id == 4) {
-   drv_mode[0] = drv_mode[1] = mode;
-   drv_mode[2] = drv_mode[3] = mode;
-   dma_size[0] = dma_size[1] = p2;
-   dma_size[2] = dma_size[3] = p2;
-   } else {
-   printk("msdc host_id error when select mode\n");
-   }
} else if (cmd == SD_TOOL_SDIO_PROFILE) {
if (p1 == 1) { /* enable profile */
if (gpt_enable == 0) {
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 20/30] staging: mt7621-mmc: Remove unused sdio irq code

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently the code for the sdio irq is never used, because the flags
for it (MSDC_(EXT_)SDIO_IRQ) are never set. So the whole code for it
can be removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h |  2 --
 drivers/staging/mt7621-mmc/sd.c| 25 -
 2 files changed, 27 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index 7e0c469a444d..a7d82f321b00 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -39,8 +39,6 @@
 #define MSDC_CD_PIN_EN  (1 << 0)  /* card detection pin is wired   */
 #define MSDC_WP_PIN_EN  (1 << 1)  /* write protection pin is wired */
 #define MSDC_RST_PIN_EN (1 << 2)  /* emmc reset pin is wired   */
-#define MSDC_SDIO_IRQ   (1 << 3)  /* use internal sdio irq (bus)   */
-#define MSDC_EXT_SDIO_IRQ   (1 << 4)  /* use external sdio irq */
 #define MSDC_REMOVABLE  (1 << 5)  /* removable slot*/
 
 #define MSDC_SMPL_RISING(0)
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 614e6a72a50a..7a6101e62891 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1942,33 +1942,11 @@ static int msdc_ops_get_cd(struct mmc_host *mmc)
return present;
 }
 
-/* ops.enable_sdio_irq */
-static void msdc_ops_enable_sdio_irq(struct mmc_host *mmc, int enable)
-{
-   struct msdc_host *host = mmc_priv(mmc);
-   struct msdc_hw *hw = host->hw;
-   void __iomem *base = host->base;
-   u32 tmp;
-
-   if (hw->flags & MSDC_EXT_SDIO_IRQ) { /* yes for sdio */
-   } else {
-   ERR_MSG("XXX ");  /* so never enter here */
-   tmp = sdr_read32(SDC_CFG);
-   /* FIXME. Need to interrupt gap detection */
-   if (enable)
-   tmp |= (SDC_CFG_SDIOIDE | SDC_CFG_SDIOINTWKUP);
-   else
-   tmp &= ~(SDC_CFG_SDIOIDE | SDC_CFG_SDIOINTWKUP);
-   sdr_write32(SDC_CFG, tmp);
-   }
-}
-
 static struct mmc_host_ops mt_msdc_ops = {
.request = msdc_ops_request,
.set_ios = msdc_ops_set_ios,
.get_ro  = msdc_ops_get_ro,
.get_cd  = msdc_ops_get_cd,
-   .enable_sdio_irq = msdc_ops_enable_sdio_irq,
 };
 
 /*--*/
@@ -2330,9 +2308,6 @@ static int msdc_drv_probe(struct platform_device *pdev)
//TODO: read this as bus-width from dt (via mmc_of_parse)
mmc->caps  |= MMC_CAP_4_BIT_DATA;
 
-   if ((hw->flags & MSDC_SDIO_IRQ) || (hw->flags & MSDC_EXT_SDIO_IRQ))
-   mmc->caps |= MMC_CAP_SDIO_IRQ;  /* yes for sdio */
-
cd_active_low = !of_property_read_bool(pdev->dev.of_node, 
"mediatek,cd-high");
 
if (of_property_read_bool(pdev->dev.of_node, "mediatek,cd-poll"))
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 25/30] staging: mt7621-mmc: Don't disables DMA

2018-04-29 Thread Christian Lütke-Stetzkamp
Current code disables the DMA after the transfer. That only changes
the transfer mode to non-DMA and does not save any power. This is not
necessary any more, because now DMA transfer is always used. The macro
for disabling DMA transfer is also removed, because it is not used any
more.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 00c862b02419..0d1eed2a7964 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -199,7 +199,6 @@ static int msdc_rsp[] = {
 #define msdc_fifo_read8()sdr_read8(MSDC_RXDATA)
 
 #define msdc_dma_on()sdr_clr_bits(MSDC_CFG, MSDC_CFG_PIO)
-#define msdc_dma_off()   sdr_set_bits(MSDC_CFG, MSDC_CFG_PIO)
 
 #define msdc_retry(expr, retry, cnt) \
do {\
@@ -1282,7 +1281,6 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
 done:
if (data != NULL) {
host->data = NULL;
-   msdc_dma_off();
dma_unmap_sg(mmc_dev(mmc), data->sg, data->sg_len,
 mmc_get_dma_dir(data));
host->blksz = 0;
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 21/30] staging: mt7621-mmc: Do not BUG() if mrq set in msdc_ops_request

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently the code BUG()'s, if host->mrq is set at the beginning of
msdc_ops_request. This shoould normally not happen, but it is not that
critical, because the critical sections are protected by a spin lock
and in the worst case, some commands to the card are lost, so it is
sufficient to just WARN_ON().

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 7a6101e62891..7549ef40ac17 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1716,10 +1716,7 @@ static void msdc_ops_request(struct mmc_host *mmc, 
struct mmc_request *mrq)
u32 ticks = 0, opcode = 0, sizes = 0, bRx = 0;
 #endif /* end of --- */
 
-   if (host->mrq) {
-   ERR_MSG("XXX host->mrq<0x%.8x>", (int)host->mrq);
-   BUG();
-   }
+   WARN_ON(host->mrq);
 
if (!is_card_present(host) || host->power_mode == MMC_POWER_OFF) {
ERR_MSG("cmd<%d> card<%d> power<%d>", mrq->cmd->opcode, 
is_card_present(host), host->power_mode);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 18/30] staging: mt7621-mmc: Fix error number assignment

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently the value that data->error is set to is converted to an
unsigned int, but it is a usual error number, so it should be
negative.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 44d75f3f2c3e..0da9ff5b2f50 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -891,7 +891,7 @@ static unsigned int msdc_command_start(struct msdc_host   
*host,
 
if (time_after(jiffies, tmo)) {
ERR_MSG("XXX cmd_busy timeout: before CMD<%d>", 
opcode);
-   cmd->error = (unsigned int)-ETIMEDOUT;
+   cmd->error = -ETIMEDOUT;
msdc_reset_hw(host);
goto end;
}
@@ -902,7 +902,7 @@ static unsigned int msdc_command_start(struct msdc_host   
*host,
break;
if (time_after(jiffies, tmo)) {
ERR_MSG("XXX sdc_busy timeout: before CMD<%d>", 
opcode);
-   cmd->error = (unsigned int)-ETIMEDOUT;
+   cmd->error = -ETIMEDOUT;
msdc_reset_hw(host);
goto end;
}
@@ -945,7 +945,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
spin_unlock(&host->lock);
if (!wait_for_completion_timeout(&host->cmd_done, 10 * timeout)) {
ERR_MSG("XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>", 
opcode, cmd->arg);
-   cmd->error = (unsigned int)-ETIMEDOUT;
+   cmd->error = -ETIMEDOUT;
msdc_reset_hw(host);
}
spin_lock(&host->lock);
@@ -994,7 +994,7 @@ static unsigned int msdc_command_resp(struct msdc_host   
*host,
return cmd->error;
 
/* memory card CRC */
-   if (host->hw->flags & MSDC_REMOVABLE && cmd->error == (unsigned 
int)(-EIO)) {
+   if (host->hw->flags & MSDC_REMOVABLE && cmd->error == -EIO) {
if (sdr_read32(SDC_CMD) & 0x1800) { /* check if has data phase 
*/
msdc_abort_data(host);
} else {
@@ -1272,7 +1272,7 @@ static int msdc_do_request(struct mmc_host *mmc, struct 
mmc_request *mrq)
ERR_MSG("DMA_CA   = 0x%x", sdr_read32(MSDC_DMA_CA));
ERR_MSG("DMA_CTRL = 0x%x", 
sdr_read32(MSDC_DMA_CTRL));
ERR_MSG("DMA_CFG  = 0x%x", 
sdr_read32(MSDC_DMA_CFG));
-   data->error = (unsigned int)-ETIMEDOUT;
+   data->error = -ETIMEDOUT;
 
msdc_reset_hw(host);
msdc_clr_fifo();
@@ -1409,7 +1409,7 @@ static int msdc_tune_cmdrsp(struct msdc_host *host, 
struct mmc_command *cmd)
 
if (result == 0)
return 0;
-   if (result != (unsigned int)(-EIO)) {
+   if (result != -EIO) {
ERR_MSG("TUNE_CMD<%d> Error<%d> not -EIO", 
cmd->opcode, result);
return result;
}
@@ -1482,7 +1482,8 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct 
mmc_request *mrq)
goto done;
} else {
/* there is a case: command timeout, and data 
phase not processed */
-   if (mrq->data->error != 0 && mrq->data->error 
!= (unsigned int)(-EIO)) {
+   if (mrq->data->error != 0 &&
+   mrq->data->error != -EIO) {
ERR_MSG("TUNE_READ: result<0x%x> 
cmd_error<%d> data_error<%d>",
result, mrq->cmd->error, 
mrq->data->error);
goto done;
@@ -1606,7 +1607,7 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct 
mmc_request *mrq)
goto done;
} else {
/* there is a case: command timeout, 
and data phase not processed */
-   if (mrq->data->error != (unsigned 
int)(-EIO)) {
+   if (mrq->data->error != -EIO) {
 

[PATCH 12/30] staging: mt7621-mmc: Remove unused static msdc_regs

2018-04-29 Thread Christian Lütke-Stetzkamp
The static variable msdc_regs is set once, but never used, so remove
it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index f4da48a5772b..ddd0b301fef3 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -142,10 +142,6 @@
 #define MAX_SGMT_SZ (MAX_DMA_CNT)
 #define MAX_REQ_SZ  (MAX_SGMT_SZ * 8)
 
-#ifdef MT6575_SD_DEBUG
-static struct msdc_regs *msdc_reg[HOST_MAX_NUM];
-#endif
-
 static int cd_active_low = 1;
 
 //=
@@ -2364,10 +2360,6 @@ static void msdc_init_hw(struct msdc_host *host)
 {
void __iomem *base = host->base;
 
-#ifdef MT6575_SD_DEBUG
-   msdc_reg[host->id] = (struct msdc_regs *)host->base;
-#endif
-
/* Power on */
 #if 0 /* --- by chhung */
msdc_vcore_on(host);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 27/30] staging: mt7621-mmc: Always use linked DMA mode

2018-04-29 Thread Christian Lütke-Stetzkamp
Current code uses linked DMA mode only when there is more than one
entry in the scatterlist. But the overhead of the linked DMA is very
small, so the code is easier when only using linked DMA and this is
also the way, the upstream driver mtk-sd handles it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index b51a4b156605..706eab4e1237 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1169,10 +1169,7 @@ static void msdc_dma_setup(struct msdc_host *host, 
struct msdc_dma *dma,
dma->sg = sg;
dma->sglen = sglen;
 
-   if (sglen == 1 && sg_dma_len(sg) <= MAX_DMA_CNT)
-   dma->mode = MSDC_MODE_DMA_BASIC;
-   else
-   dma->mode = MSDC_MODE_DMA_DESC;
+   dma->mode = MSDC_MODE_DMA_DESC;
 
N_MSG(DMA, "DMA mode<%d> sglen<%d> xfersz<%d>", dma->mode, dma->sglen,
  host->xfer_size);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 26/30] staging: mt7621-mmc: Change return value of msdc_dma_config to void

2018-04-29 Thread Christian Lütke-Stetzkamp
The msdc_dma_config function currently returns always 0. Remove the
return and change to void.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0d1eed2a7964..b51a4b156605 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1085,7 +1085,7 @@ static u8 msdc_dma_calcs(u8 *buf, u32 len)
 }
 
 /* gpd bd setup + dma registers */
-static int msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma)
+static void msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma)
 {
void __iomem *base = host->base;
//u32 i, j, num, bdlen, arg, xfersz;
@@ -1159,7 +1159,6 @@ static int msdc_dma_config(struct msdc_host *host, struct 
msdc_dma *dma)
N_MSG(DMA, "DMA_CFG  = 0x%x", sdr_read32(MSDC_DMA_CFG));
N_MSG(DMA, "DMA_SA   = 0x%x", sdr_read32(MSDC_DMA_SA));
 
-   return 0;
 }
 
 static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/30] staging: mt7621-mmc: Remove unused macro msdc_init_gpd_ex

2018-04-29 Thread Christian Lütke-Stetzkamp
The macro msdc_init_gpd_ex is never used and does not provied any
information about the hardware, so it is removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index e94b2bafa8eb..00dacf8c9625 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -195,15 +195,6 @@ static int msdc_rsp[] = {
7,  /* RESP_R1b */
 };
 
-/* For Inhanced DMA */
-#define msdc_init_gpd_ex(_gpd, extlen, cmd, arg, blknum) \
-   do {\
-   ((struct gpd *)_gpd)->extlen = extlen;  \
-   ((struct gpd *)_gpd)->cmd= cmd; \
-   ((struct gpd *)_gpd)->arg= arg; \
-   ((struct gpd *)_gpd)->blknum = blknum;  \
-   } while (0)
-
 #define msdc_txfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 
16)
 #define msdc_rxfifocnt()   ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0)
 #define msdc_fifo_write32(v)   sdr_write32(MSDC_TXDATA, (v))
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/30] staging: mt7621-mmc: Remove unused macros sdr_{read, write}16

2018-04-29 Thread Christian Lütke-Stetzkamp
The sdr_{read,write}16 macros are never used and does not provide any
information about the device, so they are removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index b77f8412ae2c..62e6beefa3db 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -980,10 +980,8 @@ static inline unsigned int uffs(unsigned int x)
 }
 
 #define sdr_read8(reg)readb(reg)
-#define sdr_read16(reg)   readw(reg)
 #define sdr_read32(reg)   readl(reg)
 #define sdr_write8(reg, val)  writeb(val, reg)
-#define sdr_write16(reg, val) writew(val, reg)
 #define sdr_write32(reg, val) writel(val, reg)
 
 static inline void sdr_set_bits(void __iomem *reg, u32 bs)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/30] staging: mt7621-mmc: Remove unused field data_edge from msdc_hw

2018-04-29 Thread Christian Lütke-Stetzkamp
The field data_edge of msdc_hw is set to a constant and only used once,
replace that position with the constant and remove the unused field.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 7 +++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index af192a8205b0..22edbb8bbc31 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -54,7 +54,6 @@
 
 struct msdc_hw {
unsigned char  clk_src;  /* host clock source */
-   unsigned char  data_edge;/* data latch edge */
unsigned char  clk_drv;  /* clock pad driving */
unsigned char  cmd_drv;  /* command pad driving */
unsigned char  dat_drv;  /* data pad driving */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index f4c33f02e75e..9dba15edc812 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -177,7 +177,6 @@ void msdc_clk_status(int *status)
 /* +++ by chhung */
 struct msdc_hw msdc0_hw = {
.clk_src= 0,
-   .data_edge  = MSDC_SMPL_FALLING,
.clk_drv= 4,
.cmd_drv= 4,
.dat_drv= 4,
@@ -2027,7 +2026,6 @@ static void msdc_set_buswidth(struct msdc_host *host, u32 
width)
 static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 {
struct msdc_host *host = mmc_priv(mmc);
-   struct msdc_hw *hw = host->hw;
void __iomem *base = host->base;
u32 ddr = 0;
 
@@ -2073,10 +2071,11 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, 
struct mmc_ios *ios)
if (host->mclk != ios->clock) {
if (ios->clock > 2500) {
//if (!(host->hw->flags & MSDC_REMOVABLE)) {
-   INIT_MSG("SD data latch edge<%d>", hw->data_edge);
+   INIT_MSG("SD data latch edge<%d>", MSDC_SMPL_FALLING);
sdr_set_field(MSDC_IOCON, MSDC_IOCON_RSPL,
  MSDC_SMPL_FALLING);
-   sdr_set_field(MSDC_IOCON, MSDC_IOCON_DSPL, 
hw->data_edge);
+   sdr_set_field(MSDC_IOCON, MSDC_IOCON_DSPL,
+ MSDC_SMPL_FALLING);
//} /* for tuning debug */
} else { /* default value */
sdr_write32(MSDC_IOCON,  0x);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/30] staging: mt7621-mmc: Remove unused field cmd_drv from msdc_hw

2018-04-29 Thread Christian Lütke-Stetzkamp
The field cmd_drv of msdc_hw is set to a constant and only used once,
replace that position with the constant and remove the unused field.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index a2ad8237cf13..4c8499891c2f 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -55,7 +55,6 @@
 struct msdc_hw {
unsigned char  clk_src;  /* host clock source */
unsigned char  clk_drv;  /* clock pad driving */
-   unsigned char  cmd_drv;  /* command pad driving */
unsigned long  flags;/* hardware capability flags */
 
/* config gpio pull mode */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 0daf06f3c4a9..6c901ac83e2f 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -178,7 +178,6 @@ void msdc_clk_status(int *status)
 struct msdc_hw msdc0_hw = {
.clk_src= 0,
.clk_drv= 4,
-   .cmd_drv= 4,
.flags  = MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 // .flags  = MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 };
@@ -2444,8 +2443,8 @@ static void msdc_init_hw(struct msdc_host *host)
/* set clk, cmd, dat pad driving */
sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVN, hw->clk_drv);
sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVP, hw->clk_drv);
-   sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVN, hw->cmd_drv);
-   sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVP, hw->cmd_drv);
+   sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVN, 4);
+   sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVP, 4);
sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVN, 4);
sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVP, 4);
 #else
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/30] staging: mt7621-mmc: Remove unused field cmd_edge from msdc_hw

2018-04-29 Thread Christian Lütke-Stetzkamp
The field cmd_edge of msdc_hw is set to a constant and only used once,
replace that position with the constant and remove the unused field.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index 544d736e2dad..af192a8205b0 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -54,7 +54,6 @@
 
 struct msdc_hw {
unsigned char  clk_src;  /* host clock source */
-   unsigned char  cmd_edge; /* command latch edge */
unsigned char  data_edge;/* data latch edge */
unsigned char  clk_drv;  /* clock pad driving */
unsigned char  cmd_drv;  /* command pad driving */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index b78f68016190..f4c33f02e75e 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -177,7 +177,6 @@ void msdc_clk_status(int *status)
 /* +++ by chhung */
 struct msdc_hw msdc0_hw = {
.clk_src= 0,
-   .cmd_edge   = MSDC_SMPL_FALLING,
.data_edge  = MSDC_SMPL_FALLING,
.clk_drv= 4,
.cmd_drv= 4,
@@ -2075,7 +2074,8 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct 
mmc_ios *ios)
if (ios->clock > 2500) {
//if (!(host->hw->flags & MSDC_REMOVABLE)) {
INIT_MSG("SD data latch edge<%d>", hw->data_edge);
-   sdr_set_field(MSDC_IOCON, MSDC_IOCON_RSPL, 
hw->cmd_edge);
+   sdr_set_field(MSDC_IOCON, MSDC_IOCON_RSPL,
+ MSDC_SMPL_FALLING);
sdr_set_field(MSDC_IOCON, MSDC_IOCON_DSPL, 
hw->data_edge);
//} /* for tuning debug */
} else { /* default value */
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 17/30] staging: mt7621-mmc: Remove unused variable dma_xfer from msdc_host

2018-04-29 Thread Christian Lütke-Stetzkamp
The field dma_xfer of the struct msdc_host is not used anymore, remove
it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 195c7333f77d..aa7e9c250e02 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -922,7 +922,6 @@ struct msdc_host {
 
struct msdc_dma dma;/* dma channel */
u32 dma_xfer_size;  /* dma transfer size in 
bytes */
-   int dma_xfer;   /* dma transfer mode */
 
u32 timeout_ns; /* data timeout ns */
u32 timeout_clks;   /* data timeout clks */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 95b5db80250a..44d75f3f2c3e 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -603,7 +603,7 @@ static void msdc_abort_data(struct msdc_host *host)
void __iomem *base = host->base;
struct mmc_command *stop = host->mrq->stop;
 
-   ERR_MSG("Need to Abort. dma<%d>", host->dma_xfer);
+   ERR_MSG("Need to Abort.");
 
msdc_reset_hw(host);
msdc_clr_fifo();
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 29/30] staging: mt7621-mmc: Cleanup includes

2018-04-29 Thread Christian Lütke-Stetzkamp
This commit cleans the includes in the sd.c file. Those which are not
needed are removed, the remaining ones are sorted alphabetically.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 51 +++--
 1 file changed, 8 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 2da079238966..d92234a96551 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -34,31 +34,21 @@
  */
 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
+
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
 
-/* +++ by chhung */
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
+
+#include "board.h"
+#include "dbg.h"
+#include "mt6575_sd.h"
 
 //#define IRQ_SDC 14   //MT7620 /*FIXME*/
 #ifdef CONFIG_SOC_MT7621
@@ -70,31 +60,6 @@
 #endif
 #define IRQ_SDC22  /*FIXME*/
 
-#include 
-/* end of +++ */
-
-#include 
-
-#if 0 /* --- by chhung */
-#include 
-#include 
-#include 
-#include 
-#include 
-//#include 
-//#include 
-//#include 
-#include 
-// #include 
-#endif /* end of --- */
-
-#include "mt6575_sd.h"
-#include "dbg.h"
-
-/* +++ by chhung */
-#include "board.h"
-/* end of +++ */
-
 #if 0 /* --- by chhung */
 #define isb() __asm__ __volatile__ ("" : : : "memory")
 #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/30] staging: mt7621-mmc: Replace macro sdr_get_field with function

2018-04-29 Thread Christian Lütke-Stetzkamp
Currently sdr_get_field is a macro, to bring the code in line with the
upstream driver mtk-sd, it is changed to a function.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/mt6575_sd.h | 10 +-
 drivers/staging/mt7621-mmc/sd.c| 14 --
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/mt6575_sd.h 
b/drivers/staging/mt7621-mmc/mt6575_sd.h
index 90b4ee6b396b..195c7333f77d 100644
--- a/drivers/staging/mt7621-mmc/mt6575_sd.h
+++ b/drivers/staging/mt7621-mmc/mt6575_sd.h
@@ -980,10 +980,10 @@ static inline void sdr_set_field(void __iomem *reg, u32 
field, u32 val)
writel(tv, reg);
 }
 
-#define sdr_get_field(reg, field, val) \
-do {   \
-   volatile unsigned int tv = sdr_read32(reg); \
-   val = ((tv & (field)) >> (ffs((unsigned int)field) - 1));   \
-} while (0)
+static inline void sdr_get_field(void __iomem *reg, u32 field, u32 *val)
+{
+   unsigned int tv = readl(reg);
+   *val = ((tv & field) >> (ffs((unsigned int)field) - 1));
+}
 
 #endif
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 00dacf8c9625..f4da48a5772b 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -1577,8 +1577,8 @@ static int msdc_tune_cmdrsp(struct msdc_host *host, 
struct mmc_command *cmd)
   ==*/
 
// save the previous tune result
-   sdr_get_field(MSDC_IOCON,MSDC_IOCON_RSPL,orig_rsmpl);
-   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_CMDRRDLY, orig_rrdly);
+   sdr_get_field(MSDC_IOCON,MSDC_IOCON_RSPL,&orig_rsmpl);
+   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_CMDRRDLY, &orig_rrdly);
 
rrdly = 0;
do {
@@ -1640,7 +1640,7 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct 
mmc_request *mrq)
int result = -1;
u32 skip = 1;
 
-   sdr_get_field(MSDC_IOCON, MSDC_IOCON_DSPL, orig_dsmpl);
+   sdr_get_field(MSDC_IOCON, MSDC_IOCON_DSPL, &orig_dsmpl);
 
/* Tune Method 2. */
sdr_set_field(MSDC_IOCON, MSDC_IOCON_DDLSEL, 1);
@@ -1664,7 +1664,9 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct 
mmc_request *mrq)
}
result = msdc_do_request(mmc, mrq);
 
-   sdr_get_field(SDC_DCRC_STS, SDC_DCRC_STS_POS | 
SDC_DCRC_STS_NEG, dcrc); /* RO */
+   sdr_get_field(SDC_DCRC_STS,
+ SDC_DCRC_STS_POS | SDC_DCRC_STS_NEG,
+ &dcrc); /* RO */
if (!ddr)
dcrc &= ~SDC_DCRC_STS_NEG;
ERR_MSG("TUNE_BREAD<%s> dcrc<0x%x> 
DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>",
@@ -1751,8 +1753,8 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct 
mmc_request *mrq)
 
// MSDC_IOCON_DDR50CKD need to check. [Fix me]
 
-   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_DATWRDLY, orig_wrrdly);
-   sdr_get_field(MSDC_IOCON,MSDC_IOCON_DSPL,orig_dsmpl);
+   sdr_get_field(MSDC_PAD_TUNE, MSDC_PAD_TUNE_DATWRDLY, &orig_wrrdly);
+   sdr_get_field(MSDC_IOCON,MSDC_IOCON_DSPL,&orig_dsmpl);
 
/* Tune Method 2. just DAT0 */
sdr_set_field(MSDC_IOCON, MSDC_IOCON_DDLSEL, 1);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/30] staging: mt7621-mmc: Remove unused field clk_drv from msdc_hw

2018-04-29 Thread Christian Lütke-Stetzkamp
The field clk_drv of msdc_hw is set to a constant and only used once,
replace that position with the constant and remove the unused field.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/board.h | 1 -
 drivers/staging/mt7621-mmc/sd.c| 6 ++
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/board.h 
b/drivers/staging/mt7621-mmc/board.h
index 4c8499891c2f..7e0c469a444d 100644
--- a/drivers/staging/mt7621-mmc/board.h
+++ b/drivers/staging/mt7621-mmc/board.h
@@ -54,7 +54,6 @@
 
 struct msdc_hw {
unsigned char  clk_src;  /* host clock source */
-   unsigned char  clk_drv;  /* clock pad driving */
unsigned long  flags;/* hardware capability flags */
 
/* config gpio pull mode */
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 6c901ac83e2f..e94b2bafa8eb 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -177,7 +177,6 @@ void msdc_clk_status(int *status)
 /* +++ by chhung */
 struct msdc_hw msdc0_hw = {
.clk_src= 0,
-   .clk_drv= 4,
.flags  = MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 // .flags  = MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE,
 };
@@ -2371,7 +2370,6 @@ static void msdc_enable_cd_irq(struct msdc_host *host, 
int enable)
 static void msdc_init_hw(struct msdc_host *host)
 {
void __iomem *base = host->base;
-   struct msdc_hw *hw = host->hw;
 
 #ifdef MT6575_SD_DEBUG
msdc_reg[host->id] = (struct msdc_regs *)host->base;
@@ -2441,8 +2439,8 @@ static void msdc_init_hw(struct msdc_host *host)
 
 #if 1
/* set clk, cmd, dat pad driving */
-   sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVN, hw->clk_drv);
-   sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVP, hw->clk_drv);
+   sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVN, 4);
+   sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKDRVP, 4);
sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVN, 4);
sdr_set_field(MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDDRVP, 4);
sdr_set_field(MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATDRVN, 4);
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 28/30] staging: mt7621-mmc: Remove unused macro HOST_MAX_NUM

2018-04-29 Thread Christian Lütke-Stetzkamp
The macro HOST_MAX_NUM is never used, so remove it.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/sd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 706eab4e1237..2da079238966 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -104,8 +104,6 @@
 
 #define DRV_NAME"mtk-sd"
 
-#define HOST_MAX_NUM(1) /* +/- by chhung */
-
 #if defined(CONFIG_SOC_MT7620)
 #define HOST_MAX_MCLK   (4800) /* +/- by chhung */
 #elif defined(CONFIG_SOC_MT7621)
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 15/30] staging: mt7621-mmc: Remove unused global dma_size

2018-04-29 Thread Christian Lütke-Stetzkamp
The global variable dma_size was previously used to select DMA or
non-DMA transfer mode based on the size of the data that should be
transferred. This option was removed preivously, so the variable is not
used any more and can be removed.

Signed-off-by: Christian Lütke-Stetzkamp 
---
 drivers/staging/mt7621-mmc/dbg.c | 8 
 drivers/staging/mt7621-mmc/dbg.h | 2 --
 2 files changed, 10 deletions(-)

diff --git a/drivers/staging/mt7621-mmc/dbg.c b/drivers/staging/mt7621-mmc/dbg.c
index 163c061b440c..d897b1216348 100644
--- a/drivers/staging/mt7621-mmc/dbg.c
+++ b/drivers/staging/mt7621-mmc/dbg.c
@@ -58,14 +58,6 @@ unsigned int sd_debug_zone[4] = {
0
 };
 
-/* mode select */
-u32 dma_size[4] = {
-   512,
-   512,
-   512,
-   512
-};
-
 #if defined(MT6575_SD_DEBUG)
 /* for driver profile */
 #define TICKS_ONE_MS  (13000)
diff --git a/drivers/staging/mt7621-mmc/dbg.h b/drivers/staging/mt7621-mmc/dbg.h
index 9412d73f33a8..5a25a69b00c9 100644
--- a/drivers/staging/mt7621-mmc/dbg.h
+++ b/drivers/staging/mt7621-mmc/dbg.h
@@ -79,8 +79,6 @@ enum msdc_mode {
MODE_SIZE_DEP = 2,
 };
 
-extern u32 dma_size[4];
-
 /* Debug message event */
 #define DBG_EVT_NONE(0)   /* No event */
 #define DBG_EVT_DMA (1 << 0)  /* DMA related event */
-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 00/30] staging: mt7621-mmc: Next cleanups

2018-04-29 Thread Christian Lütke-Stetzkamp
Here are the next cleanups for the mt7621-mmc driver. It contains the
removal of some unused things, the removal of the non DMA code and
always using linked DMA mode together with some minor cleanups.

Christian Lütke-Stetzkamp (30):
  staging: mt7621-mmc: Fix typo in function parameters
  staging: mt7621-mmc: Remove unused field cmd_edge from msdc_hw
  staging: mt7621-mmc: Remove unused field data_edge from msdc_hw
  staging: mt7621-mmc: Remove unused field dat_drv from msdc_hw
  staging: mt7621-mmc: Remove unused field cmd_drv from msdc_hw
  staging: mt7621-mmc: Remove unused field clk_drv from msdc_hw
  staging: mt7621-mmc: Remove unused macro msdc_init_gpd_ex
  staging: mt7621-mmc: Remove unused macros sdr_{read,write}16
  staging: mt7621-mmc: Remove function uffs
  staging: mt7621-mmc: Replace macro sdr_set_field with function
  staging: mt7621-mmc: Replace macro sdr_get_field with function
  staging: mt7621-mmc: Remove unused static msdc_regs
  staging: mt7621-mmc: Remove transfer mode setting from proc
  staging: mt7621-mmc: Remove transfer mode setting variable
  staging: mt7621-mmc: Remove unused global dma_size
  staging: mt7621-mmc: Remove non-DMA transfer code
  staging: mt7621-mmc: Remove unused variable dma_xfer from msdc_host
  staging: mt7621-mmc: Fix error number assignment
  staging: mt7621-mmc: Remove unused field abort from msdc_host
  staging: mt7621-mmc: Remove unused sdio irq code
  staging: mt7621-mmc: Do not BUG() if mrq set in msdc_ops_request
  staging: mt7621-mmc: Remove redundant check for card status
  staging: mt7621-mmc: Remove initialisation in msdc_dma_config
  staging: mt7621-mmc: Inline function msdc_set_blknum
  staging: mt7621-mmc: Don't disables DMA
  staging: mt7621-mmc: Change return value of msdc_dma_config to void
  staging: mt7621-mmc: Always use linked DMA mode
  staging: mt7621-mmc: Remove unused macro HOST_MAX_NUM
  staging: mt7621-mmc: Cleanup includes
  staging: mt7621-mmc: Remove unused barrier macros

 drivers/staging/mt7621-mmc/board.h |   7 -
 drivers/staging/mt7621-mmc/dbg.c   |  38 ---
 drivers/staging/mt7621-mmc/dbg.h   |   3 -
 drivers/staging/mt7621-mmc/mt6575_sd.h |  60 +
 drivers/staging/mt7621-mmc/sd.c| 479 ++---
 5 files changed, 96 insertions(+), 491 deletions(-)

-- 
2.16.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


  1   2   3   >