ftsdc010: add support of ftsdc010 mmc controller
PATCH 1/1 ftsdc010: add support of ftsdc010 mmc controller
Faraday FTSDC010 controller is a SD/MMC controller for SoC chip.
--- drivers/mmc/Makefile | 1 + drivers/mmc/ftsdc010_esdhc.c | 666 ++++++++++++++++++++++++++++++++++++++++++ include/faraday/ftsdc010.h | 245 ++++++++++++++++ 3 files changed, 912 insertions(+), 0 deletions(-) create mode 100644 drivers/mmc/ftsdc010_esdhc.c create mode 100644 include/faraday/ftsdc010.h
drivers/mmc/Makefile +1 -0
@@ -29,6 +29,7 @@ COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o COBJS-$(CONFIG_DAVINCI_MMC) += davinci_mmc.o COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o +COBJS-$(CONFIG_FTSDC010) += ftsdc010_esdhc.o COBJS-$(CONFIG_GENERIC_MMC) += mmc.o COBJS-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
drivers/mmc/ftsdc010_esdhc.c new file +666 -0
666 lines not on this page · raw message
include/faraday/ftsdc010.h new file +245 -0
245 lines not on this page · raw message
Signature · 1 line
1.7.3.5
PATCH 1/1 ftsdc010: add support of ftsdc010 mmc controller
Hi all
2011/7/8 Macpaul Lin <[email protected]>:
Quoted 3 lines
Faraday FTSDC010 controller is a SD/MMC controller for SoC chip.
Signed-off-by Macpaul Lin <[email protected]>
Sorry for the mail server has problem again.
I've send 2 patches which is exactly the same one to the mailist. I'll delete one of the patch in patchwork.
http://patchwork.ozlabs.org/patch/103776/
Please review the other one.
Thanks.
Signature · 2 lines
Best regards, Macpaul Lin
PATCH 1/1 ftsdc010: add support of ftsdc010 mmc controller
In reply to Macpaul Lindrivers/mmc/ftsdc010_esdhc.c line 36
Quoted 3 lines · Macpaul Lin
+ */
drivers/mmc/ftsdc010_esdhc.c new file +2
-0+static struct mmc mmc_dev[CONFIG_FTSDC010_NUMBER ]; +static struct mmc_host mmc_host[CONFIG_FTSDC010_NUMBER ];
Probably should have less generic names for all of these.
drivers/mmc/ftsdc010_esdhc.c
Quoted 5 lines
drivers/mmc/ftsdc010_esdhc.c new file +5
-0+ +static struct ftsdc010_mmc *ftsdc010_get_base_mmc (int dev_index) +{ + ? ? ? unsigned long offset = dev_index * sizeof(struct ftsdc010_mmc); + ? ? ? return (struct ftsdc010_mmc *)(CONFIG_FTSDC010_BASE + offset);
This might be clearer as straightforward pointer math:
return (struct ftsdc010_mmc *)(CONFIG_FTSDC010_BASE) + dev_index;
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static void mmc_pio_read(struct mmc_host *host, char *buf, unsigned int size)
This is a very generic name
drivers/mmc/ftsdc010_esdhc.c
Quoted 5 lines
drivers/mmc/ftsdc010_esdhc.c new file +5
-0+ +static int mmc_pio_check_status (struct mmc *mmc,struct mmc_cmd *cmd, + ? ? ? ? ? ? ? ? ? ? ? struct mmc_data *data) +{ + ? ? ? struct mmc_host *host = (struct mmc_host *)mmc->priv;
This cast is unnecessary. A void * can be cast to another pointer type without a cast, and that is the preferred style.
Quoted 83 lines
(quoted diff) +83
-0+ + ? ? ? unsigned int sta, clear; + ? ? ? unsigned int i; + + ? ? ? /* check response and hardware status */ + ? ? ? clear = 0; + + ? ? ? /* chech CMD_SEND */ + ? ? ? for (i = 0; i < FTSDC010_CMD_RETRY; i++) { + ? ? ? ? ? ? ? sta = readl(&host->reg->status); + ? ? ? ? ? ? ? /* Command Complete */ + ? ? ? ? ? ? ? if (sta & FTSDC010_STATUS_CMD_SEND) { + ? ? ? ? ? ? ? ? ? ? ? if (!data) + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_CLR_CMD_SEND; + ? ? ? ? ? ? ? ? ? ? ? break; + ? ? ? ? ? ? ? } + ? ? ? } + + ? ? ? if (i > FTSDC010_CMD_RETRY) { + ? ? ? ? ? ? ? printf("%s: send command timeout\n", __func__); + ? ? ? ? ? ? ? return TIMEOUT; + ? ? ? } + + ? ? ? /* debug: print status register and command index*/ + ? ? ? debug("sta: %08x cmd %d\n", sta, cmd->cmdidx); + + ? ? ? /* handle data FIFO */ + ? ? ? if ((sta & FTSDC010_STATUS_FIFO_ORUN) || + ? ? ? ? ? ? ? (sta & FTSDC010_STATUS_FIFO_URUN)) { + + ? ? ? ? ? ? ? /* Wrong DATA FIFO Flag */ + ? ? ? ? ? ? ? if (data == NULL) + ? ? ? ? ? ? ? ? ? ? ? printf("%s, data fifo wrong: sta: %08x cmd %d\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __func__, sta, cmd->cmdidx); + + ? ? ? ? ? ? ? if (sta & FTSDC010_STATUS_FIFO_ORUN) + ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_STATUS_FIFO_ORUN; + ? ? ? ? ? ? ? if (sta & FTSDC010_STATUS_FIFO_URUN) + ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_STATUS_FIFO_URUN; + ? ? ? } + + ? ? ? /* check RSP TIMEOUT or FAIL */ + ? ? ? if (sta & FTSDC010_STATUS_RSP_TIMEOUT) { + ? ? ? ? ? ? ? /* RSP TIMEOUT */ + ? ? ? ? ? ? ? debug("%s: RSP timeout: sta: %08x cmd %d\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __func__, sta, cmd->cmdidx); + + ? ? ? ? ? ? ? clear |= FTSDC010_CLR_RSP_TIMEOUT; + ? ? ? ? ? ? ? writel(clear, &host->reg->clr); + + ? ? ? ? ? ? ? return TIMEOUT; + ? ? ? } else if (sta & FTSDC010_STATUS_RSP_CRC_FAIL) { + ? ? ? ? ? ? ? /* clear response fail bit */ + ? ? ? ? ? ? ? debug("%s: RSP CRC FAIL: sta: %08x cmd %d\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __func__, sta, cmd->cmdidx); + + ? ? ? ? ? ? ? clear |= FTSDC010_CLR_RSP_CRC_FAIL; + ? ? ? ? ? ? ? writel(clear, &host->reg->clr); + + ? ? ? ? ? ? ? return -1; + ? ? ? } else if (sta & FTSDC010_STATUS_RSP_CRC_OK) { + + ? ? ? ? ? ? ? /* clear response CRC OK bit */ + ? ? ? ? ? ? ? clear |= FTSDC010_CLR_RSP_CRC_OK; + ? ? ? } + + ? ? ? /* check DATA TIMEOUT or FAIL */ + ? ? ? if (data) { + ? ? ? ? ? ? ? if (sta & FTSDC010_STATUS_DATA_TIMEOUT) { + ? ? ? ? ? ? ? ? ? ? ? /* DATA TIMEOUT */ + ? ? ? ? ? ? ? ? ? ? ? debug("%s: DATA TIMEOUT: sta: %08x\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __func__, sta); + + ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_STATUS_DATA_TIMEOUT; + ? ? ? ? ? ? ? ? ? ? ? writel(sta, &host->reg->clr); + ? ? ? ? ? ? ? ? ? ? ? return TIMEOUT; + ? ? ? ? ? ? ? } else if (sta & FTSDC010_STATUS_DATA_CRC_FAIL) { + ? ? ? ? ? ? ? ? ? ? ? /* Error Interrupt */ + ? ? ? ? ? ? ? ? ? ? ? debug("%s: DATA CRC FAIL: sta: %08x\n", + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __func__, sta); + + ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_STATUS_DATA_CRC_FAIL; + ? ? ? ? ? ? ? ? ? ? ? writel(clear, &host->reg->clr);
Review
Quoted 10 lines
(quoted diff) +10
-0+ + ? ? ? ? ? ? ? ? ? ? ? return -1; + ? ? ? ? ? ? ? } else if (sta & FTSDC010_STATUS_DATA_END) { + ? ? ? ? ? ? ? ? ? ? ? /* Transfer Complete */ + ? ? ? ? ? ? ? ? ? ? ? clear |= FTSDC010_STATUS_DATA_END; + ? ? ? ? ? ? ? } + ? ? ? } + + ? ? ? /* transaction is success and clear status register */ + ? ? ? writel(sta, &host->reg->clr);
I'm confused by the use of the "clear" variable. Some of the if clauses are totally useless, because "clear" is never read after being written. And some of the users of clear don't clear all of the status bits. Are you going to come back around and read the bits you didn't clear? If it's always safe to write "sta" to "clr", then why not just do that every time, and remove the "clear" variable?
drivers/mmc/ftsdc010_esdhc.c
Quoted 6 lines
drivers/mmc/ftsdc010_esdhc.c new file +6
-0+ + ? ? ? return 0; +} + +static int mmc_send_cmd (struct mmc *mmc,struct mmc_cmd *cmd, + ? ? ? ? ? ? ? ? ? ? ? struct mmc_data *data)
This name actually conflicts with the global mmc framework's command name. It would be much better if you named it something like ftsdc010_send_cmd()
Quoted 15 lines
(quoted diff) +15
-0+static int ftsdc010_setup_data(struct mmc *mmc, struct mmc_data *data) +{ + ? ? ? struct mmc_host *host = (struct mmc_host *)mmc->priv; + ? ? ? unsigned int dcon, newmask; + + ? ? ? /* configure data transfer paramter */ + ? ? ? if (!data) + ? ? ? ? ? ? ? return 0; + + ? ? ? if (((data->blocksize - 1) & data->blocksize) != 0) { + ? ? ? ? ? ? ? printf("%s: can't do non-power-of 2 sized block transfers" + ? ? ? ? ? ? ? ? ? ? ? " (blksz %d)\n", __func__, data->blocksize); + ? ? ? ? ? ? ? return -1; + ? ? ? } +
Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? if (data->blocksize <= 2) { + ? ? ? ? ? ? ? /* We cannot deal with unaligned blocks with more than + ? ? ? ? ? ? ? ?* one block being transfered. */ + + ? ? ? ? ? ? ? if (data->blocks > 1) { + ? ? ? ? ? ? ? ? ? ? ? printf("%s: can't do non-word sized block transfers" + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " (blksz %d)\n", __func__, data->blocksize); + ? ? ? ? ? ? ? ? ? ? ? return -1; + ? ? ? ? ? ? ? } + ? ? ? }
I'd put these two conditions in one if statement (if (size <= 2) && (blocks > 1)).
Make name more specific to this controller
drivers/mmc/ftsdc010_esdhc.c line 578
Quoted 2 lines
drivers/mmc/ftsdc010_esdhc.c new file +2
-0+ +static void mmc_reset (struct mmc_host *host)
Change the name
Quoted 1 line
+static int
mmc_core_init(struct mmc *mmc)
Change this name, too
include/faraday/ftsdc010.h
Quoted 7 lines
include/faraday/ftsdc010.h new file +1
-0+struct mmc_host {
Change this name
Andy
Song
[U-Boot] [RFC] mmc:saveenv problem
Hello Dear Andy:
I found in env_mmc.c, mmc_get_env_addr(...)only do *env_addr = CONFIG_ENV_OFFSET.If CONFIG_ENV_OFFSET is defined in partition space,the raw data may cover the env.IF CONFIG_ENV_OFFSET = 0,will it damage MBR?Should it do some protection methods?
Thank you very much
Elen.song
PATCH v3 1/1 ftsdc010: add support of ftsdc010 mmc controller
In reply to Macpaul LinFaraday FTSDC010 controller is a SD/MMC controller for SoC chip.
---
Changes for v2:
- headers: Fix typo from SDC_DATA_CTRL_REG_BLK_SIZE(x)
to SDC_DATA_CTRL_REG_BLK_BYTES(x)
Changes for v3:
- Replace mmc_xxx function to ftsdc010_xxx.
- Replace mmc_xxx structures to ftsdc010_xxx.
- Remove unnessary cast for void type.
- Remove unnessary offset caculation.
- Fix clear variable in ftsdc010_pio_check_status.
- Fix return value in ftsdc010_pio_check_status for command retry for hardware
- Fix if branch for size and block checking in ftsdc010_setup_data.
drivers/mmc/Makefile | 1 + drivers/mmc/ftsdc010_esdhc.c | 667 ++++++++++++++++++++++++++++++++++++++++++ include/faraday/ftsdc010.h | 245 ++++++++++++++++ 3 files changed, 913 insertions(+), 0 deletions(-) create mode 100644 drivers/mmc/ftsdc010_esdhc.c create mode 100644 include/faraday/ftsdc010.h
drivers/mmc/Makefile +1 -0
@@ -29,6 +29,7 @@ COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o COBJS-$(CONFIG_DAVINCI_MMC) += davinci_mmc.o COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o +COBJS-$(CONFIG_FTSDC010) += ftsdc010_esdhc.o COBJS-$(CONFIG_GENERIC_MMC) += mmc.o COBJS-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
drivers/mmc/ftsdc010_esdhc.c new file +667 -0
667 lines not on this page · raw message
include/faraday/ftsdc010.h new file +245 -0
245 lines not on this page · raw message
Signature · 1 line
1.7.3.5
PATCH v3 1/1 ftsdc010: add support of ftsdc010 mmc controller
Hi Andy,
2011/7/21 Macpaul Lin <[email protected]>:
Quoted 15 lines
Faraday FTSDC010 controller is a SD/MMC controller for SoC chip.
Signed-off-by Macpaul Lin <[email protected]>---
Changes for v2:
?- headers: Fix typo fromSDC_DATA_CTRL_REG_BLK_SIZE(x)
? ?toSDC_DATA_CTRL_REG_BLK_BYTES(x)
Changes for v3:
?- Replacemmc_xxxfunction toftsdc010_xxx.
?- Replacemmc_xxxstructures toftsdc010_xxx.
?- Remove unnessary cast for void type.
?- Remove unnessary offset caculation.
?- Fix clear variable inftsdc010_pio_check_status.
?- Fix return value inftsdc010_pio_check_statusfor command retry for hardware ?- Fix if branch for size and block checking inftsdc010_setup_data.
Just want to remind you there is a patch v3 waiting for reviewing which has been sent 3 weeks ago.
Please check it when you have time.
Thanks!
Signature · 2 lines
Best regards, Macpaul Lin
Andy Fleming
AppliedPATCH v3 1/1 ftsdc010: add support of ftsdc010 mmc controller
Quoted 6 lines · ???
Hi Andy,
2011/7/21 Macpaul Lin <[email protected]>:
Quoted 3 lines
Faraday FTSDC010 controller is a SD/MMC controller for SoC chip.
Signed-off-by Macpaul Lin <[email protected]>
Applied, thx!