S3C24XX SD/MMC driver series
cover S3C24XX SD/MMC driver series
This series provides support for the SD/MMC controller contained in many of the Samsung SoCs. The patches have been gathered from both the OpenMoko[1] kernel support series (from various contributors) and my own updates to update and add functionality.
I would like people to check over this series and ensure that I have correctly attributed the patch source, and to any objections to this seriese being submitted for 2.6.27.
The series has been kept seperate due to the fact that there are several contributors, including myself.
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 1/15 MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
This is the latest S3C MMC/SD driver by Thomas Kleffel
include/asm-arm/arch-s3c2410/regs-sdi.h +17 -3
@@ -28,9 +28,15 @@#define S3C2410_SDIDCNT (0x30)#define S3C2410_SDIDSTA (0x34)#define S3C2410_SDIFSTA (0x38) +#define S3C2410_SDIDATA (0x3C)#define S3C2410_SDIIMSK (0x40) +#define S3C2440_SDIDATA (0x40) +#define S3C2440_SDIIMSK (0x3C) + +#define S3C2440_SDICON_SDRESET (1<<8) +#define S3C2440_SDICON_MMCCLOCK (1<<5)#define S3C2410_SDICON_BYTEORDER (1<<4)#define S3C2410_SDICON_SDIOIRQ (1<<3)#define S3C2410_SDICON_RWAITEN (1<<2)
@@ -42,7 +48,8 @@#define S3C2410_SDICMDCON_LONGRSP (1<<10)#define S3C2410_SDICMDCON_WAITRSP (1<<9)#define S3C2410_SDICMDCON_CMDSTART (1<<8) -#define S3C2410_SDICMDCON_INDEX (0xff) +#define S3C2410_SDICMDCON_SENDERHOST (1<<6) +#define S3C2410_SDICMDCON_INDEX (0x3f)#define S3C2410_SDICMDSTAT_CRCFAIL (1<<12)#define S3C2410_SDICMDSTAT_CMDSENT (1<<11)
@@ -51,6 +58,9 @@#define S3C2410_SDICMDSTAT_XFERING (1<<8)#define S3C2410_SDICMDSTAT_INDEX (0xff) +#define S3C2440_SDIDCON_DS_BYTE (0<<22) +#define S3C2440_SDIDCON_DS_HALFWORD (1<<22) +#define S3C2440_SDIDCON_DS_WORD (2<<22)#define S3C2410_SDIDCON_IRQPERIOD (1<<21)#define S3C2410_SDIDCON_TXAFTERRESP (1<<20)#define S3C2410_SDIDCON_RXAFTERCMD (1<<19)
@@ -59,6 +69,7 @@#define S3C2410_SDIDCON_WIDEBUS (1<<16)#define S3C2410_SDIDCON_DMAEN (1<<15)#define S3C2410_SDIDCON_STOP (1<<14) +#define S3C2440_SDIDCON_DATSTART (1<<14)#define S3C2410_SDIDCON_DATMODE (3<<12)#define S3C2410_SDIDCON_BLKNUM (0x7ff)
@@ -68,6 +79,7 @@#define S3C2410_SDIDCON_XFER_RXSTART (2<<12)#define S3C2410_SDIDCON_XFER_TXSTART (3<<12) +#define S3C2410_SDIDCON_BLKNUM_MASK (0xFFF)#define S3C2410_SDIDCNT_BLKNUM_SHIFT (12)#define S3C2410_SDIDSTA_RDYWAITREQ (1<<10)
@@ -82,10 +94,12 @@#define S3C2410_SDIDSTA_TXDATAON (1<<1)#define S3C2410_SDIDSTA_RXDATAON (1<<0) +#define S3C2440_SDIFSTA_FIFORESET (1<<16) +#define S3C2440_SDIFSTA_FIFOFAIL (3<<14)/* 3 is correct (2 bits) */ #define S3C2410_SDIFSTA_TFDET (1<<13)#define S3C2410_SDIFSTA_RFDET (1<<12) -#define S3C2410_SDIFSTA_TXHALF (1<<11) -#define S3C2410_SDIFSTA_TXEMPTY (1<<10) +#define S3C2410_SDIFSTA_TFHALF (1<<11) +#define S3C2410_SDIFSTA_TFEMPTY (1<<10)#define S3C2410_SDIFSTA_RFLAST (1<<9)#define S3C2410_SDIFSTA_RFFULL (1<<8)#define S3C2410_SDIFSTA_RFHALF (1<<7)
drivers/mmc/host/s3cmci.c new file +1337 -0
1,337 lines not on this page · raw message
drivers/mmc/host/s3cmci.h new file +71 -0
71 lines not on this page · raw message
drivers/mmc/host/Kconfig +11 -0
@@ -130,3 +130,14 @@ config MMC_SPI If unsure, or if your system has no SPI master driver, say N. +config MMC_S3C + tristate "Samsung S3C SD/MMC Card Interface support" + depends on ARCH_S3C2410 && MMC + help + This selects a driver for the MCI interface found in + Samsung's S3C2410, S3C2412, S3C2440, S3C2442 CPUs. + If you have a board based on one of those and a MMC/SD + slot, say Y or M here. + + If unsure, say N. +
drivers/mmc/host/Makefile +1 -1
@@ -17,4 +17,4 @@ obj-$(CONFIG_MMC_OMAP) += omap.o obj-$(CONFIG_MMC_AT91) += at91_mci.o obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o obj-$(CONFIG_MMC_SPI) += mmc_spi.o - +obj-$(CONFIG_MMC_S3C) += s3cmci.o
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
Quoted 1 line · On Fri, 06 Jun 2008 16:51:18 +0100 Ben Dooks <[email protected]> wrote:
This is the latest S3C MMC/SD driver by Thomas Kleffel
If Thomas was the author then this patch should have had
From: Thomas Kleffel <[email protected]>
right at the top of the changelog so that the commit is correctly attributed.
Quoted 1 line
Signed-off-by Ben Dooks <[email protected]>
Please pass these patches through chechpatch? This one alone generates
total: 40 errors, 29 warnings, 1488 lines checked
many of which you would have fixed had you been aware of them. That's what checkpatch is for.
drivers/mmc/host/s3cmci.c line 54
Quoted 12 lines
...
drivers/mmc/host/s3cmci.c new file +9
-0+#define dbg(host, channels, args...) \ + if (dbgmap_err & channels) \ + dev_err(&host->pdev->dev, args); \ + else if (dbgmap_info & channels) \ + dev_info(&host->pdev->dev, args);\ + else if (dbgmap_debug & channels) \ + dev_dbg(&host->pdev->dev, args); + +#define RESSIZE (ressource) (((ressource)->end - (ressource)->start)+1)
Could be written in C. That would fix the bug wherein this macro evaluates its argument twice. "resource" is misspelled.
drivers/mmc/host/s3cmci.c line 66
Quoted 11 lines
drivers/mmc/host/s3cmci.c new file +11
-0+static struct s3c2410_dma_client s3cmci_dma_client = { + .name ="s3c-mci" , +}; + +static void finalize_request (struct s3cmci_host *host); +static void s3cmci_send_request (struct mmc_host *mmc); +static void s3cmci_reset (struct s3cmci_host *host); + +#ifdef CONFIG_MMC_DEBUG + +static inline void dbg_dumpregs (struct s3cmci_host *host,char *prefix)
too large to inline.
Quoted 34 lines
drivers/mmc/host/s3cmci.c new file +33
-0+{ +u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize; +u32 datcon, datcnt, datsta, fsta, imask; + + con =readl (host->base +S3C2410_SDICON ); + pre =readl (host->base +S3C2410_SDIPRE ); + cmdarg =readl (host->base +S3C2410_SDICMDARG ); + cmdcon =readl (host->base +S3C2410_SDICMDCON ); + cmdsta =readl (host->base +S3C2410_SDICMDSTAT ); + r0 =readl (host->base +S3C2410_SDIRSP0 ); + r1 =readl (host->base +S3C2410_SDIRSP1 ); + r2 =readl (host->base +S3C2410_SDIRSP2 ); + r3 =readl (host->base +S3C2410_SDIRSP3 ); + timer =readl (host->base +S3C2410_SDITIMER ); + bsize =readl (host->base +S3C2410_SDIBSIZE ); + datcon =readl (host->base +S3C2410_SDIDCON ); + datcnt =readl (host->base +S3C2410_SDIDCNT ); + datsta =readl (host->base +S3C2410_SDIDSTA ); + fsta =readl (host->base +S3C2410_SDIFSTA ); + imask =readl (host->base + host->sdiimsk); + +dbg (host, dbg_debug,"%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n" , + prefix, con, pre, timer); + +dbg (host, dbg_debug,"%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n" , + prefix, cmdcon, cmdarg, cmdsta); + +dbg (host, dbg_debug,"%s DCON:[%08x] FSTA:[%08x]" +" DSTA:[%08x] DCNT:[%08x]\n" , + prefix, datcon, fsta, datsta, datcnt); + + dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]" + " R2:[%08x] R3:[%08x]\n",
drivers/mmc/host/s3cmci.c line 125
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +7
-0+ prefix, r0, r1, r2, r3); +} + +static void dbg_dumpcmd (struct s3cmci_host *host,struct mmc_command *cmd, +int fail) +{ +unsigned int dbglvl = fail?dbg_fail:dbg_debug;
Spaces around the ? and :, please.
checkpatch misses this.
Quoted 37 lines
drivers/mmc/host/s3cmci.c new file +37
-0+if (!cmd) +return ; + +if (cmd->error ==MMC_ERR_NONE ) { +dbg (host, dbglvl,"CMD[OK] %s R0:0x%08x\n" , + host->dbgmsg_cmd, cmd->resp[0 ]); + }else { +dbg (host, dbglvl,"CMD[ERR %i] %s Status:%s\n" , + cmd->error, host->dbgmsg_cmd, host->status); + } + +if (!cmd->data) +return ; + +if (cmd->data->error ==MMC_ERR_NONE ) { +dbg (host, dbglvl,"DAT[OK] %s\n" , host->dbgmsg_dat); + }else { +dbg (host, dbglvl,"DAT[ERR %i] %s DCNT:0x%08x\n" , + cmd->data->error, host->dbgmsg_dat, +readl (host->base +S3C2410_SDIDCNT )); + } +} +#endif + +static inline u32 enable_imask (struct s3cmci_host *host,u32 imask) +{ +u32 newmask; + + newmask =readl (host->base + host->sdiimsk); + newmask|= imask; + +writel (newmask, host->base + host->sdiimsk); + +return newmask; +} + +static inline u32 disable_imask (struct s3cmci_host *host,u32 imask)
drivers/mmc/host/s3cmci.c line 173
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+{ +u32 newmask; + + newmask =readl (host->base + host->sdiimsk); + newmask&= ~imask; + +writel (newmask, host->base + host->sdiimsk); + +return newmask; +}
Probably too large to inline. A useful metric is to build the .o file with and without the `inline' statements and see which results in the smaller /bin/size output. Smaller is usuall faster. And it's smaller.
Quoted 23 lines
drivers/mmc/host/s3cmci.c new file +23
-0+static inline void clear_imask (struct s3cmci_host *host) +{ +writel (0 , host->base + host->sdiimsk); +} + +static inline int get_data_buffer (struct s3cmci_host *host, +volatile u32 *words,volatile u32 **pointer) +{ +struct scatterlist *sg; + +if (host->pio_active ==XFER_NONE ) +return -EINVAL ; + +if ((!host->mrq) || (!host->mrq->data)) +return -EINVAL ; + +if (host->pio_sgptr >= host->mrq->data->sg_len) { +dbg (host, dbg_debug,"no more buffers (%i/%i)\n" , + host->pio_sgptr, host->mrq->data->sg_len); +return -EBUSY ; + } + sg = &host->mrq->data->sg[host->pio_sgptr]; +
drivers/mmc/host/s3cmci.c line 207
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+ *words = sg->length >>2 ; + *pointer=page_address (sg->page) + sg->offset; + + host->pio_sgptr++; + +dbg (host, dbg_sg,"new buffer (%i/%i)\n" , + host->pio_sgptr, host->mrq->data->sg_len); + +return 0 ; +}
This one has three callsites!
drivers/mmc/host/s3cmci.c line 210
Quoted 2 lines
drivers/mmc/host/s3cmci.c new file +2
-0+#define FIFO_FILL (host) ((readl(host->base + S3C2410_SDIFSTA) & S3C2410_SDIFSTA_COUNTMASK) >> 2) +#define FIFO_FREE (host) ((63 - (readl(host->base + S3C2410_SDIFSTA) & S3C2410_SDIFSTA_COUNTMASK)) >> 2)
These didn't need to be implemented as macros.
Quoted 90 lines
drivers/mmc/host/s3cmci.c new file +90
-0+ +static inline void do_pio_read (struct s3cmci_host *host) +{ +int res; +u32 fifo; +void __iomem *from_ptr; + +//write real prescaler to host, it might be set slow to fix +writel (host->prescaler, host->base +S3C2410_SDIPRE ); + + from_ptr = host->base + host->sdidata; + +while ((fifo =FIFO_FILL (host))) { +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, + &host->pio_ptr); +if (res) { + host->pio_active =XFER_NONE ; + host->complete_what =COMPLETION_FINALIZE ; + +dbg (host, dbg_pio,"pio_read(): " +"complete (no more data).\n" ); +return ; + } + +dbg (host, dbg_pio,"pio_read(): new target: [%i]@[%p]\n" , + host->pio_words, host->pio_ptr); + } + +dbg (host, dbg_pio,"pio_read(): fifo:[%02i] " +"buffer:[%03i] dcnt:[%08X]\n" , + fifo, host->pio_words, +readl (host->base +S3C2410_SDIDCNT )); + +if (fifo > host->pio_words) + fifo = host->pio_words; + + host->pio_words-= fifo; + host->pio_count+= fifo; + +while (fifo--) { + *(host->pio_ptr++) =readl (from_ptr); + } + } + +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, &host->pio_ptr); +if (res) { +dbg (host, dbg_pio,"pio_read(): " +"complete (no more buffers).\n" ); + host->pio_active =XFER_NONE ; + host->complete_what =COMPLETION_FINALIZE ; + +return ; + } + } + +enable_imask (host,S3C2410_SDIIMSK_RXFIFOHALF |S3C2410_SDIIMSK_RXFIFOLAST ); +} + +static inline void do_pio_write (struct s3cmci_host *host) +{ +int res; +u32 fifo; + +void __iomem *to_ptr; + + to_ptr = host->base + host->sdidata; + +while ((fifo =FIFO_FREE (host))) { +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, + &host->pio_ptr); +if (res) { +dbg (host, dbg_pio,"pio_write(): " +"complete (no more data).\n" ); + host->pio_active =XFER_NONE ; + +return ; + } + +dbg (host, dbg_pio,"pio_write(): " +"new source: [%i]@[%p]\n" , + host->pio_words, host->pio_ptr); + + } + +if (fifo > host->pio_words) + fifo = host->pio_words; +
drivers/mmc/host/s3cmci.c line 310
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+ host->pio_words-= fifo; + host->pio_count+= fifo; + +while (fifo--) { +writel (*(host->pio_ptr++), to_ptr); + } + } + +enable_imask (host,S3C2410_SDIIMSK_TXFIFOHALF ); +}
Two callsites :( This is one bloaty driver.
Quoted 16 lines
drivers/mmc/host/s3cmci.c new file +16
-0+static void pio_tasklet (unsigned long data) +{ +struct s3cmci_host *host = (struct s3cmci_host *) data; + + +if (host->pio_active ==XFER_WRITE ) +do_pio_write (host); + +if (host->pio_active ==XFER_READ ) +do_pio_read (host); + +if (host->complete_what ==COMPLETION_FINALIZE ) { +clear_imask (host); +if (host->pio_active !=XFER_NONE ) { + dbg(host, dbg_err, "unfinished %s " + "- pio_count:[%u] pio_words:[%u]\n",
drivers/mmc/host/s3cmci.c line 337
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+ (host->pio_active ==XFER_READ )?"read" :"write" , + host->pio_count, host->pio_words); + + host->mrq->data->error =MMC_ERR_DMA ; + } + +disable_irq (host->irq); +finalize_request (host); + } +}
I see no tasklet_disable() in the driver. Is there anything to prevent the tasklet from running after device close, rmmod, etc?
The disable_irq()/enable_irq() on every interrupt will be quite inefficient and hostile to any device which shares the interrupt. WHy is it necessary?
Quoted 26 lines
drivers/mmc/host/s3cmci.c new file +26
-0+/* +* ISR for SDI Interface IRQ +* Communication between driver and ISR works as follows: +* host->mrq points to current request +* host->complete_what tells the ISR when the request is considered done +* COMPLETION_CMDSENT when the command was sent +* COMPLETION_RSPFIN when a response was received +* COMPLETION_XFERFINISH when the data transfer is finished +* COMPLETION_XFERFINISH_RSPFIN both of the above. +* host->complete_request is the completion-object the driver waits for +* +* 1) Driver sets up host->mrq and host->complete_what +* 2) Driver prepares the transfer +* 3) Driver enables interrupts +* 4) Driver starts transfer +* 5) Driver waits for host->complete_rquest +* 6) ISR checks for request status (errors and success) +* 6) ISR sets host->mrq->cmd->error and host->mrq->data->error +* 7) ISR completes host->complete_request +* 8) ISR disables interrupts +* 9) Driver wakes up and takes care of the request +* +* Note: "->error"-fields are expected to be set to 0 before the request +* was issued by mmc.c - therefore they are only set, when an error +* contition comes up +*/
drivers/mmc/host/s3cmci.c line 374
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+ +static irqreturn_t s3cmci_irq (int irq,void *dev_id) +{ +struct s3cmci_host *host; +struct mmc_command *cmd; +u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt, mci_imsk; +u32 mci_cclear, mci_dclear; +unsigned long iflags; + + host = (struct s3cmci_host *)dev_id;
Unneeded and undesirable cast of void*.
Quoted 17 lines
drivers/mmc/host/s3cmci.c new file +14
-0+spin_lock_irqsave (&host->complete_lock, iflags); + + mci_csta =readl (host->base +S3C2410_SDICMDSTAT ); + mci_dsta =readl (host->base +S3C2410_SDIDSTA ); + mci_dcnt =readl (host->base +S3C2410_SDIDCNT ); + mci_fsta =readl (host->base +S3C2410_SDIFSTA ); + mci_imsk =readl (host->base + host->sdiimsk); +void s3cmci_dma_done_callback (struct s3c2410_dma_chan *dma_ch,void *buf_id, +int size,enum s3c2410_dma_buffresult result) +{ +unsigned long iflags; +u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt; +struct s3cmci_host *host = (struct s3cmci_host *)buf_id; +
drivers/mmc/host/s3cmci.c line 575
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+ mci_csta =readl (host->base +S3C2410_SDICMDSTAT ); + mci_dsta =readl (host->base +S3C2410_SDIDSTA ); + mci_fsta =readl (host->base +S3C2410_SDIFSTA ); + mci_dcnt =readl (host->base +S3C2410_SDIDCNT ); + +if ((!host->mrq) || (!host->mrq) || (!host->mrq->data)) +return ; + +if (!host->dmatogo) +return ;
Can these things all really happen?
Quoted 53 lines
drivers/mmc/host/s3cmci.c new file +50
-0+spin_lock_irqsave (&host->complete_lock, iflags); + +if (result !=S3C2410_RES_OK ) { +dbg (host, dbg_fail,"DMA FAILED: csta=0x%08x dsta=0x%08x " +"fsta=0x%08x dcnt:0x%08x result:0x%08x toGo:%u\n" , + mci_csta, mci_dsta, mci_fsta, + mci_dcnt, result, host->dmatogo); + + goto fail_request; + } + + host->dmatogo--; +if (host->dmatogo) { +dbg (host, dbg_dma,"DMA DONE Size:%i DSTA:[%08x] " +"DCNT:[%08x] toGo:%u\n" , + size, mci_dsta, mci_dcnt, host->dmatogo); + + goto out; + } + +dbg (host, dbg_dma,"DMA FINISHED Size:%i DSTA:%08x DCNT:%08x\n" , + size, mci_dsta, mci_dcnt); + + host->complete_what =COMPLETION_FINALIZE ; + +out: +tasklet_schedule (&host->pio_tasklet); +spin_unlock_irqrestore (&host->complete_lock, iflags); +return ; + + +fail_request: + host->mrq->data->error =MMC_ERR_DMA ; + host->complete_what =COMPLETION_FINALIZE ; +writel (0 , host->base + host->sdiimsk); + goto out; + +} + +static int s3cmci_setup_data (struct s3cmci_host *host,struct mmc_data *data) +{ +u32 dcon, imsk, stoptries=3 ; + +/* write DCON register */ + +if (!data) { +writel (0 , host->base +S3C2410_SDIDCON ); +return 0 ; + } +
drivers/mmc/host/s3cmci.c
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10
-0+while (readl (host->base +S3C2410_SDIDSTA ) & + (S3C2410_SDIDSTA_TXDATAON |S3C2410_SDIDSTA_RXDATAON )) { + +dbg (host, dbg_err, +"mci_setup_data() transfer stillin progress.\n" ); + +writel (0 , host->base +S3C2410_SDIDCON ); +s3cmci_reset (host); + +if (0 == (stoptries--)) {
Swap 'em, please. It's not necessary.
Quoted 33 lines
drivers/mmc/host/s3cmci.c new file +32
-0+#ifdef CONFIG_MMC_DEBUG +dbg_dumpregs (host,"DRF" ); +#endif + +return -EINVAL ; + } + } + + dcon = data->blocks &S3C2410_SDIDCON_BLKNUM_MASK ; + +if (host->dodma) { + dcon |=S3C2410_SDIDCON_DMAEN ; + } + +if (host->bus_width ==MMC_BUS_WIDTH_4 ) { + dcon |=S3C2410_SDIDCON_WIDEBUS ; + } + +if (!(data->flags &MMC_DATA_STREAM )) { + dcon |=S3C2410_SDIDCON_BLOCKMODE ; + } + +if (data->flags &MMC_DATA_WRITE ) { + dcon |=S3C2410_SDIDCON_TXAFTERRESP ; + dcon |=S3C2410_SDIDCON_XFER_TXSTART ; + } + +if (data->flags &MMC_DATA_READ ) { + dcon |=S3C2410_SDIDCON_RXAFTERCMD ; + dcon |=S3C2410_SDIDCON_XFER_RXSTART ; + } +
drivers/mmc/host/s3cmci.c line 887
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +8
-0+static int s3cmci_prepare_dma (struct s3cmci_host *host,struct mmc_data *data) +{ +int dma_len, i; + +int rw = (data->flags &MMC_DATA_WRITE )?1 :0 ; + +if (rw != ((data->flags &MMC_DATA_READ )?0 :1 )) +return -EINVAL ;
That's pretty clumsy looking.
Setting both MMC_DATA_WRITE and MMC_DATA_READ would be a programming bug, wouldn't it? If so, BUG would be a more appropriate response.
Quoted 37 lines
drivers/mmc/host/s3cmci.c new file +35
-0+s3cmci_dma_setup (host, rw?S3C2410_DMASRC_MEM :S3C2410_DMASRC_HW ); +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_FLUSH ); + + dma_len =dma_map_sg (mmc_dev (host->mmc), data->sg, data->sg_len, + (rw)?DMA_TO_DEVICE :DMA_FROM_DEVICE ); + + +if (dma_len ==0 ) +return -ENOMEM ; + + host->dma_complete =0 ; + host->dmatogo = dma_len; + +for (i =0 ; i < dma_len; i++) { +int res; + +dbg (host, dbg_dma,"enqueue %i:%u@%u\n" , i, +sg_dma_address (&data->sg[i]), +sg_dma_len (&data->sg[i])); + + res =s3c2410_dma_enqueue (host->dma, (void *) host, +sg_dma_address (&data->sg[i]), +sg_dma_len (&data->sg[i])); + +if (res) { +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_FLUSH ); +return -EBUSY ; + } + } + +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_START ); + +return 0 ; +} +
drivers/mmc/host/s3cmci.c
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +9
-0+ + host->irq =platform_get_irq (pdev,0 ); +if (host->irq ==0 ) { +dev_err (&pdev->dev,"failed to get interrupt resouce.\n" ); + ret = -EINVAL ; + goto probe_iounmap; + } + +if (request_irq (host->irq, s3cmci_irq,0 ,DRIVER_NAME , host)) {
So these interrupts cannot be shared? The driver will never be used in an environment where interrupt sharing is possible?
Quoted 85 lines
drivers/mmc/host/s3cmci.c new file +85
-0+dev_err (&pdev->dev,"failed to request mci interrupt.\n" ); + ret = -ENOENT ; + goto probe_iounmap; + } + +disable_irq (host->irq); + +s3c2410_gpio_cfgpin (S3C2410_GPF2 ,S3C2410_GPF2_EINT2 ); +set_irq_type (host->irq_cd,IRQT_BOTHEDGE ); + +if (request_irq (host->irq_cd, s3cmci_irq_cd,0 ,DRIVER_NAME , host)) { +dev_err (&pdev->dev, +"failed to request card detect interrupt.\n" ); + + ret = -ENOENT ; + goto probe_free_irq; + } + +if (s3c2410_dma_request (S3CMCI_DMA , &s3cmci_dma_client,NULL )) { +dev_err (&pdev->dev,"unable to get DMA channel.\n" ); + ret = -EBUSY ; + goto probe_free_irq_cd; + } + + host->clk =clk_get (&pdev->dev,"sdi" ); +if (IS_ERR (host->clk)) { +dev_err (&pdev->dev,"failed to find clock source.\n" ); + ret =PTR_ERR (host->clk); + host->clk =NULL ; + goto probe_free_host; + } + +if ((ret =clk_enable (host->clk))) { +dev_err (&pdev->dev,"failed to enable clock source.\n" ); + goto clk_free; + } + + host->clk_rate =clk_get_rate (host->clk); + + mmc->ops = &s3cmci_ops; + mmc->ocr_avail =MMC_VDD_32_33 ; + mmc->caps =MMC_CAP_4_BIT_DATA ; + mmc->f_min = host->clk_rate / (host->clk_div *256 ); + mmc->f_max = host->clk_rate / host->clk_div; + + mmc->max_blk_count =4095 ; + mmc->max_blk_size =4095 ; + mmc->max_req_size =4095 *512 ; + mmc->max_seg_size = mmc->max_req_size; + + mmc->max_phys_segs =128 ; + mmc->max_hw_segs =128 ; + +dbg (host, dbg_debug,"probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%u.\n" , + (host->is2440?"2440" :"" ), + host->base, host->irq, host->irq_cd, host->dma); + +if ((ret =mmc_add_host (mmc))) { +dev_err (&pdev->dev,"failed to add mmc host.\n" ); + goto free_dmabuf; + } + +platform_set_drvdata (pdev, mmc); + +dev_info (&pdev->dev,"initialisation done.\n" ); +return 0 ; + + free_dmabuf: +clk_disable (host->clk); + + clk_free: +clk_put (host->clk); + + probe_free_irq_cd: +free_irq (host->irq_cd, host); + + probe_free_irq: +free_irq (host->irq, host); + + probe_iounmap: +iounmap (host->base); + + probe_free_mem_region: +release_mem_region (host->mem->start,RESSIZE (host->mem)); +
drivers/mmc/host/s3cmci.c
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +7
-0+ probe_free_host: +mmc_free_host (mmc); + probe_out: +return ret; +} + +//FIXME: DMA Resource management ?!
?
Quoted 36 lines
drivers/mmc/host/s3cmci.h new file +36
-0+#define S3CMCI_DMA 0 + +enum s3cmci_waitfor { +COMPLETION_NONE , +COMPLETION_FINALIZE , +COMPLETION_CMDSENT , +COMPLETION_RSPFIN , +COMPLETION_XFERFINISH , +COMPLETION_XFERFINISH_RSPFIN , +}; + +struct s3cmci_host { +struct platform_device *pdev; +struct mmc_host *mmc; +struct resource *mem; +struct clk *clk; +void __iomem *base; +int irq; +int irq_cd; +int dma; + +unsigned long clk_rate; +unsigned long clk_div; +unsigned long real_rate; +u8 prescaler; + +int is2440; +unsigned sdiimsk; +unsigned sdidata; +int dodma; + +volatile int dmatogo; + +struct mmc_request *mrq; +int cmd_is_stop; +
drivers/mmc/host/s3cmci.h line 57
Quoted 10 lines
drivers/mmc/host/s3cmci.h new file +10
-0+spinlock_t complete_lock; +volatile enum s3cmci_waitfor + complete_what; + +volatile int dma_complete; + +volatile u32 pio_sgptr; +volatile u32 pio_words; +volatile u32 pio_count; +volatile u32 *pio_ptr;
volatiles. checkpatch..
Quoted 4 lines
drivers/mmc/host/s3cmci.h new file +4
-0+#define XFER_NONE 0 +#define XFER_READ 1 +#define XFER_WRITE 2 +volatile u32 pio_active;
drivers/mmc/host/s3cmci.h line 71
Quoted 10 lines
drivers/mmc/host/s3cmci.h new file +10
-0+ +int bus_width; + +char dbgmsg_cmd[301 ]; +char dbgmsg_dat[301 ]; +volatile char *status; + +unsigned int ccnt, dcnt; +struct tasklet_struct pio_tasklet; +};
Those problems were really really basic stuff. kernel drivers 101.
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
Quoted 7 lines · Andrew Morton
Quoted 1 line · On Fri, 06 Jun 2008 16:51:18 +0100 Ben Dooks <[email protected]> wrote:
This is the latest S3C MMC/SD driver by Thomas Kleffel
If Thomas was the author then this patch should have had
From: Thomas Kleffel <[email protected]>
I thought I'd done this for all the relevant patches, will fix thus.
Quoted 11 lines
right at the top of the changelog so that the commit is correctly attributed.
Quoted 1 line
Signed-off-by Ben Dooks <[email protected]>Please pass these patches through chechpatch? This one alone generates
total: 40 errors, 29 warnings, 1488 lines checked
many of which you would have fixed had you been aware of them. That's what checkpatch is for.
Is it ok to fit another patch after this one to fixup these problems?
Quoted 16 lines
drivers/mmc/host/s3cmci.c line 54
Quoted 12 lines
...
drivers/mmc/host/s3cmci.c new file +9
-0+#define dbg(host, channels, args...) \ + if (dbgmap_err & channels) \ + dev_err(&host->pdev->dev, args); \ + else if (dbgmap_info & channels) \ + dev_info(&host->pdev->dev, args);\ + else if (dbgmap_debug & channels) \ + dev_dbg(&host->pdev->dev, args); + +#define RESSIZE (ressource) (((ressource)->end - (ressource)->start)+1)Could be written in C. That would fix the bug wherein this macro evaluates its argument twice. "resource" is misspelled.
Quoted 13 lines
drivers/mmc/host/s3cmci.c line 66
Quoted 11 lines
drivers/mmc/host/s3cmci.c new file +11
-0+static struct s3c2410_dma_client s3cmci_dma_client = { + .name ="s3c-mci" , +}; + +static void finalize_request (struct s3cmci_host *host); +static void s3cmci_send_request (struct mmc_host *mmc); +static void s3cmci_reset (struct s3cmci_host *host); + +#ifdef CONFIG_MMC_DEBUG + +static inline void dbg_dumpregs (struct s3cmci_host *host,char *prefix)too large to inline.
yeah, fix that.
Quoted 39 lines
Quoted 39 lines
drivers/mmc/host/s3cmci.c new file +36
-0+{ +u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize; +u32 datcon, datcnt, datsta, fsta, imask; + + con =readl (host->base +S3C2410_SDICON ); + pre =readl (host->base +S3C2410_SDIPRE ); + cmdarg =readl (host->base +S3C2410_SDICMDARG ); + cmdcon =readl (host->base +S3C2410_SDICMDCON ); + cmdsta =readl (host->base +S3C2410_SDICMDSTAT ); + r0 =readl (host->base +S3C2410_SDIRSP0 ); + r1 =readl (host->base +S3C2410_SDIRSP1 ); + r2 =readl (host->base +S3C2410_SDIRSP2 ); + r3 =readl (host->base +S3C2410_SDIRSP3 ); + timer =readl (host->base +S3C2410_SDITIMER ); + bsize =readl (host->base +S3C2410_SDIBSIZE ); + datcon =readl (host->base +S3C2410_SDIDCON ); + datcnt =readl (host->base +S3C2410_SDIDCNT ); + datsta =readl (host->base +S3C2410_SDIDSTA ); + fsta =readl (host->base +S3C2410_SDIFSTA ); + imask =readl (host->base + host->sdiimsk); + +dbg (host, dbg_debug,"%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n" , + prefix, con, pre, timer); + +dbg (host, dbg_debug,"%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n" , + prefix, cmdcon, cmdarg, cmdsta); + +dbg (host, dbg_debug,"%s DCON:[%08x] FSTA:[%08x]" +" DSTA:[%08x] DCNT:[%08x]\n" , + prefix, datcon, fsta, datsta, datcnt); + +dbg (host, dbg_debug,"%s R0:[%08x] R1:[%08x]" +" R2:[%08x] R3:[%08x]\n" , + prefix, r0, r1, r2, r3); +} +
Quoted 7 lines
drivers/mmc/host/s3cmci.c line 125
Quoted 5 lines
drivers/mmc/host/s3cmci.c new file +4
-0+static void dbg_dumpcmd (struct s3cmci_host *host,struct mmc_command *cmd, +int fail) +{ +unsigned int dbglvl = fail?dbg_fail:dbg_debug;Spaces around the ? and :, please.
fixed.
Quoted 45 lines
checkpatch misses this.
Quoted 43 lines
drivers/mmc/host/s3cmci.c new file +43
-0+if (!cmd) +return ; + +if (cmd->error ==MMC_ERR_NONE ) { +dbg (host, dbglvl,"CMD[OK] %s R0:0x%08x\n" , + host->dbgmsg_cmd, cmd->resp[0 ]); + }else { +dbg (host, dbglvl,"CMD[ERR %i] %s Status:%s\n" , + cmd->error, host->dbgmsg_cmd, host->status); + } + +if (!cmd->data) +return ; + +if (cmd->data->error ==MMC_ERR_NONE ) { +dbg (host, dbglvl,"DAT[OK] %s\n" , host->dbgmsg_dat); + }else { +dbg (host, dbglvl,"DAT[ERR %i] %s DCNT:0x%08x\n" , + cmd->data->error, host->dbgmsg_dat, +readl (host->base +S3C2410_SDIDCNT )); + } +} +#endif + +static inline u32 enable_imask (struct s3cmci_host *host,u32 imask) +{ +u32 newmask; + + newmask =readl (host->base + host->sdiimsk); + newmask|= imask; + +writel (newmask, host->base + host->sdiimsk); + +return newmask; +} + +static inline u32 disable_imask (struct s3cmci_host *host,u32 imask) +{ +u32 newmask; + + newmask =readl (host->base + host->sdiimsk); + newmask&= ~imask; +
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 161
Quoted 4 lines
drivers/mmc/host/s3cmci.c new file +4
-0+writel (newmask, host->base + host->sdiimsk); + +return newmask; +}Probably too large to inline. A useful metric is to build the .o file with and without the `inline' statements and see which results in the smaller
/bin/sizeoutput. Smaller is usuall faster. And it's smaller.
I'll have a look, but with the function pre-ambles and call overheads I expect these'll stay inlines.
Quoted 27 lines
Quoted 27 lines
drivers/mmc/host/s3cmci.c new file +27
-0+static inline void clear_imask (struct s3cmci_host *host) +{ +writel (0 , host->base + host->sdiimsk); +} + +static inline int get_data_buffer (struct s3cmci_host *host, +volatile u32 *words,volatile u32 **pointer) +{ +struct scatterlist *sg; + +if (host->pio_active ==XFER_NONE ) +return -EINVAL ; + +if ((!host->mrq) || (!host->mrq->data)) +return -EINVAL ; + +if (host->pio_sgptr >= host->mrq->data->sg_len) { +dbg (host, dbg_debug,"no more buffers (%i/%i)\n" , + host->pio_sgptr, host->mrq->data->sg_len); +return -EBUSY ; + } + sg = &host->mrq->data->sg[host->pio_sgptr]; + + *words = sg->length >>2 ; + *pointer=page_address (sg->page) + sg->offset; + + host->pio_sgptr++;
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 207
Quoted 6 lines
drivers/mmc/host/s3cmci.c new file +6
-0+ +dbg (host, dbg_sg,"new buffer (%i/%i)\n" , + host->pio_sgptr, host->mrq->data->sg_len); + +return 0 ; +}This one has three callsites!
Hmm, I'll leave it up to the compiler whether it wants to try and inline this.
Quoted 4 lines
drivers/mmc/host/s3cmci.c line 210
Quoted 2 lines
drivers/mmc/host/s3cmci.c new file +2
-0+#define FIFO_FILL (host) ((readl(host->base + S3C2410_SDIFSTA) & S3C2410_SDIFSTA_COUNTMASK) >> 2) +#define FIFO_FREE (host) ((63 - (readl(host->base + S3C2410_SDIFSTA) & S3C2410_SDIFSTA_COUNTMASK)) >> 2)These didn't need to be implemented as macros.
these are now inlined.
Quoted 94 lines
Quoted 94 lines
drivers/mmc/host/s3cmci.c new file +94
-0+ +static inline void do_pio_read (struct s3cmci_host *host) +{ +int res; +u32 fifo; +void __iomem *from_ptr; + +//write real prescaler to host, it might be set slow to fix +writel (host->prescaler, host->base +S3C2410_SDIPRE ); + + from_ptr = host->base + host->sdidata; + +while ((fifo =FIFO_FILL (host))) { +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, + &host->pio_ptr); +if (res) { + host->pio_active =XFER_NONE ; + host->complete_what =COMPLETION_FINALIZE ; + +dbg (host, dbg_pio,"pio_read(): " +"complete (no more data).\n" ); +return ; + } + +dbg (host, dbg_pio,"pio_read(): new target: [%i]@[%p]\n" , + host->pio_words, host->pio_ptr); + } + +dbg (host, dbg_pio,"pio_read(): fifo:[%02i] " +"buffer:[%03i] dcnt:[%08X]\n" , + fifo, host->pio_words, +readl (host->base +S3C2410_SDIDCNT )); + +if (fifo > host->pio_words) + fifo = host->pio_words; + + host->pio_words-= fifo; + host->pio_count+= fifo; + +while (fifo--) { + *(host->pio_ptr++) =readl (from_ptr); + } + } + +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, &host->pio_ptr); +if (res) { +dbg (host, dbg_pio,"pio_read(): " +"complete (no more buffers).\n" ); + host->pio_active =XFER_NONE ; + host->complete_what =COMPLETION_FINALIZE ; + +return ; + } + } + +enable_imask (host,S3C2410_SDIIMSK_RXFIFOHALF |S3C2410_SDIIMSK_RXFIFOLAST ); +} + +static inline void do_pio_write (struct s3cmci_host *host) +{ +int res; +u32 fifo; + +void __iomem *to_ptr; + + to_ptr = host->base + host->sdidata; + +while ((fifo =FIFO_FREE (host))) { +if (!host->pio_words) { + res =get_data_buffer (host, &host->pio_words, + &host->pio_ptr); +if (res) { +dbg (host, dbg_pio,"pio_write(): " +"complete (no more data).\n" ); + host->pio_active =XFER_NONE ; + +return ; + } + +dbg (host, dbg_pio,"pio_write(): " +"new source: [%i]@[%p]\n" , + host->pio_words, host->pio_ptr); + + } + +if (fifo > host->pio_words) + fifo = host->pio_words; + + host->pio_words-= fifo; + host->pio_count+= fifo; + +while (fifo--) {
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 310
Quoted 6 lines
drivers/mmc/host/s3cmci.c new file +6
-0+writel (*(host->pio_ptr++), to_ptr); + } + } + +enable_imask (host,S3C2410_SDIIMSK_TXFIFOHALF ); +}Two callsites :( This is one bloaty driver.
un-inlined.
Quoted 21 lines
Quoted 21 lines
drivers/mmc/host/s3cmci.c new file +21
-0+static void pio_tasklet (unsigned long data) +{ +struct s3cmci_host *host = (struct s3cmci_host *) data; + + +if (host->pio_active ==XFER_WRITE ) +do_pio_write (host); + +if (host->pio_active ==XFER_READ ) +do_pio_read (host); + +if (host->complete_what ==COMPLETION_FINALIZE ) { +clear_imask (host); +if (host->pio_active !=XFER_NONE ) { +dbg (host, dbg_err,"unfinished %s " +"- pio_count:[%u] pio_words:[%u]\n" , + (host->pio_active ==XFER_READ )?"read" :"write" , + host->pio_count, host->pio_words); + + host->mrq->data->error =MMC_ERR_DMA ; + }
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 337
Quoted 5 lines
drivers/mmc/host/s3cmci.c new file +5
-0+ +disable_irq (host->irq); +finalize_request (host); + } +}I see no
tasklet_disable()in the driver. Is there anything to prevent the tasklet from running after device close, rmmod, etc?
fixed.
Quoted 3 lines
The disable_irq()/enable_irq() on every interrupt will be quite inefficient and hostile to any device which shares the interrupt. WHy is it necessary?
do you mean "on every request", no the driver won't be sharing interrupts with another block, and I would expect that it is to stop any interrupts when there is no request present, although I have not checked for this.
Quoted 30 lines
Quoted 30 lines
drivers/mmc/host/s3cmci.c new file +30
-0+/* +* ISR for SDI Interface IRQ +* Communication between driver and ISR works as follows: +* host->mrq points to current request +* host->complete_what tells the ISR when the request is considered done +* COMPLETION_CMDSENT when the command was sent +* COMPLETION_RSPFIN when a response was received +* COMPLETION_XFERFINISH when the data transfer is finished +* COMPLETION_XFERFINISH_RSPFIN both of the above. +* host->complete_request is the completion-object the driver waits for +* +* 1) Driver sets up host->mrq and host->complete_what +* 2) Driver prepares the transfer +* 3) Driver enables interrupts +* 4) Driver starts transfer +* 5) Driver waits for host->complete_rquest +* 6) ISR checks for request status (errors and success) +* 6) ISR sets host->mrq->cmd->error and host->mrq->data->error +* 7) ISR completes host->complete_request +* 8) ISR disables interrupts +* 9) Driver wakes up and takes care of the request +* +* Note: "->error"-fields are expected to be set to 0 before the request +* was issued by mmc.c - therefore they are only set, when an error +* contition comes up +*/ + +static irqreturn_t s3cmci_irq (int irq,void *dev_id) +{ +struct s3cmci_host *host;
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 374
Quoted 6 lines
drivers/mmc/host/s3cmci.c new file +6
-0+struct mmc_command *cmd; +u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt, mci_imsk; +u32 mci_cclear, mci_dclear; +unsigned long iflags; + + host = (struct s3cmci_host *)dev_id;Unneeded and undesirable cast of void*.
fuxed
Quoted 21 lines
Quoted 21 lines
drivers/mmc/host/s3cmci.c new file +18
-0+spin_lock_irqsave (&host->complete_lock, iflags); + + mci_csta =readl (host->base +S3C2410_SDICMDSTAT ); + mci_dsta =readl (host->base +S3C2410_SDIDSTA ); + mci_dcnt =readl (host->base +S3C2410_SDIDCNT ); + mci_fsta =readl (host->base +S3C2410_SDIFSTA ); + mci_imsk =readl (host->base + host->sdiimsk); +void s3cmci_dma_done_callback (struct s3c2410_dma_chan *dma_ch,void *buf_id, +int size,enum s3c2410_dma_buffresult result) +{ +unsigned long iflags; +u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt; +struct s3cmci_host *host = (struct s3cmci_host *)buf_id; + + mci_csta =readl (host->base +S3C2410_SDICMDSTAT ); + mci_dsta =readl (host->base +S3C2410_SDIDSTA ); + mci_fsta =readl (host->base +S3C2410_SDIFSTA ); + mci_dcnt =readl (host->base +S3C2410_SDIDCNT );
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 575
Quoted 6 lines
drivers/mmc/host/s3cmci.c new file +6
-0+ +if ((!host->mrq) || (!host->mrq) || (!host->mrq->data)) +return ; + +if (!host->dmatogo) +return ;Can these things all really happen?
I've not tried finding out.
Quoted 57 lines
Quoted 57 lines
drivers/mmc/host/s3cmci.c new file +54
-0+spin_lock_irqsave (&host->complete_lock, iflags); + +if (result !=S3C2410_RES_OK ) { +dbg (host, dbg_fail,"DMA FAILED: csta=0x%08x dsta=0x%08x " +"fsta=0x%08x dcnt:0x%08x result:0x%08x toGo:%u\n" , + mci_csta, mci_dsta, mci_fsta, + mci_dcnt, result, host->dmatogo); + + goto fail_request; + } + + host->dmatogo--; +if (host->dmatogo) { +dbg (host, dbg_dma,"DMA DONE Size:%i DSTA:[%08x] " +"DCNT:[%08x] toGo:%u\n" , + size, mci_dsta, mci_dcnt, host->dmatogo); + + goto out; + } + +dbg (host, dbg_dma,"DMA FINISHED Size:%i DSTA:%08x DCNT:%08x\n" , + size, mci_dsta, mci_dcnt); + + host->complete_what =COMPLETION_FINALIZE ; + +out: +tasklet_schedule (&host->pio_tasklet); +spin_unlock_irqrestore (&host->complete_lock, iflags); +return ; + + +fail_request: + host->mrq->data->error =MMC_ERR_DMA ; + host->complete_what =COMPLETION_FINALIZE ; +writel (0 , host->base + host->sdiimsk); + goto out; + +} + +static int s3cmci_setup_data (struct s3cmci_host *host,struct mmc_data *data) +{ +u32 dcon, imsk, stoptries=3 ; + +/* write DCON register */ + +if (!data) { +writel (0 , host->base +S3C2410_SDIDCON ); +return 0 ; + } + +while (readl (host->base +S3C2410_SDIDSTA ) & + (S3C2410_SDIDSTA_TXDATAON |S3C2410_SDIDSTA_RXDATAON )) { + + dbg(host, dbg_err,
Quoted 8 lines
drivers/mmc/host/s3cmci.c line 789
Quoted 6 lines
drivers/mmc/host/s3cmci.c new file +6
-0+ "mci_setup_data() transfer stillin progress.\n"); + +writel (0 , host->base +S3C2410_SDIDCON ); +s3cmci_reset (host); + +if (0 == (stoptries--)) {Swap 'em, please. It's not necessary.
fixed
Quoted 46 lines
Quoted 33 lines
drivers/mmc/host/s3cmci.c new file +32
-0+#ifdef CONFIG_MMC_DEBUG +dbg_dumpregs (host,"DRF" ); +#endif + +return -EINVAL ; + } + } + + dcon = data->blocks &S3C2410_SDIDCON_BLKNUM_MASK ; + +if (host->dodma) { + dcon |=S3C2410_SDIDCON_DMAEN ; + } + +if (host->bus_width ==MMC_BUS_WIDTH_4 ) { + dcon |=S3C2410_SDIDCON_WIDEBUS ; + } + +if (!(data->flags &MMC_DATA_STREAM )) { + dcon |=S3C2410_SDIDCON_BLOCKMODE ; + } + +if (data->flags &MMC_DATA_WRITE ) { + dcon |=S3C2410_SDIDCON_TXAFTERRESP ; + dcon |=S3C2410_SDIDCON_XFER_TXSTART ; + } + +if (data->flags &MMC_DATA_READ ) { + dcon |=S3C2410_SDIDCON_RXAFTERCMD ; + dcon |=S3C2410_SDIDCON_XFER_RXSTART ; + } +drivers/mmc/host/s3cmci.c line 887
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +8
-0+static int s3cmci_prepare_dma (struct s3cmci_host *host,struct mmc_data *data) +{ +int dma_len, i; + +int rw = (data->flags &MMC_DATA_WRITE )?1 :0 ; + +if (rw != ((data->flags &MMC_DATA_READ )?0 :1 )) +return -EINVAL ;That's pretty clumsy looking.
Quoted 2 lines
Setting both
MMC_DATA_WRITEandMMC_DATA_READwould be a programming bug, wouldn't it? If so, BUG would be a more appropriate response.
ok, changed.
Quoted 38 lines
Quoted 38 lines
drivers/mmc/host/s3cmci.c new file +35
-0+s3cmci_dma_setup (host, rw?S3C2410_DMASRC_MEM :S3C2410_DMASRC_HW ); +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_FLUSH ); + + dma_len =dma_map_sg (mmc_dev (host->mmc), data->sg, data->sg_len, + (rw)?DMA_TO_DEVICE :DMA_FROM_DEVICE ); + + +if (dma_len ==0 ) +return -ENOMEM ; + + host->dma_complete =0 ; + host->dmatogo = dma_len; + +for (i =0 ; i < dma_len; i++) { +int res; + +dbg (host, dbg_dma,"enqueue %i:%u@%u\n" , i, +sg_dma_address (&data->sg[i]), +sg_dma_len (&data->sg[i])); + + res =s3c2410_dma_enqueue (host->dma, (void *) host, +sg_dma_address (&data->sg[i]), +sg_dma_len (&data->sg[i])); + +if (res) { +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_FLUSH ); +return -EBUSY ; + } + } + +s3c2410_dma_ctrl (host->dma,S3C2410_DMAOP_START ); + +return 0 ; +} +
Quoted 12 lines
drivers/mmc/host/s3cmci.c line 1142
Quoted 9 lines
drivers/mmc/host/s3cmci.c new file +9
-0+ + host->irq =platform_get_irq (pdev,0 ); +if (host->irq ==0 ) { +dev_err (&pdev->dev,"failed to get interrupt resouce.\n" ); + ret = -EINVAL ; + goto probe_iounmap; + } + +if (request_irq (host->irq, s3cmci_irq,0 ,DRIVER_NAME , host)) {So these interrupts cannot be shared? The driver will never be used in an environment where interrupt sharing is possible?
All current SoCs in the family have one interrupt for each controller, so this is unlikely.
Quoted 147 lines
Quoted 85 lines
drivers/mmc/host/s3cmci.c new file +85
-0+dev_err (&pdev->dev,"failed to request mci interrupt.\n" ); + ret = -ENOENT ; + goto probe_iounmap; + } + +disable_irq (host->irq); + +s3c2410_gpio_cfgpin (S3C2410_GPF2 ,S3C2410_GPF2_EINT2 ); +set_irq_type (host->irq_cd,IRQT_BOTHEDGE ); + +if (request_irq (host->irq_cd, s3cmci_irq_cd,0 ,DRIVER_NAME , host)) { +dev_err (&pdev->dev, +"failed to request card detect interrupt.\n" ); + + ret = -ENOENT ; + goto probe_free_irq; + } + +if (s3c2410_dma_request (S3CMCI_DMA , &s3cmci_dma_client,NULL )) { +dev_err (&pdev->dev,"unable to get DMA channel.\n" ); + ret = -EBUSY ; + goto probe_free_irq_cd; + } + + host->clk =clk_get (&pdev->dev,"sdi" ); +if (IS_ERR (host->clk)) { +dev_err (&pdev->dev,"failed to find clock source.\n" ); + ret =PTR_ERR (host->clk); + host->clk =NULL ; + goto probe_free_host; + } + +if ((ret =clk_enable (host->clk))) { +dev_err (&pdev->dev,"failed to enable clock source.\n" ); + goto clk_free; + } + + host->clk_rate =clk_get_rate (host->clk); + + mmc->ops = &s3cmci_ops; + mmc->ocr_avail =MMC_VDD_32_33 ; + mmc->caps =MMC_CAP_4_BIT_DATA ; + mmc->f_min = host->clk_rate / (host->clk_div *256 ); + mmc->f_max = host->clk_rate / host->clk_div; + + mmc->max_blk_count =4095 ; + mmc->max_blk_size =4095 ; + mmc->max_req_size =4095 *512 ; + mmc->max_seg_size = mmc->max_req_size; + + mmc->max_phys_segs =128 ; + mmc->max_hw_segs =128 ; + +dbg (host, dbg_debug,"probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%u.\n" , + (host->is2440?"2440" :"" ), + host->base, host->irq, host->irq_cd, host->dma); + +if ((ret =mmc_add_host (mmc))) { +dev_err (&pdev->dev,"failed to add mmc host.\n" ); + goto free_dmabuf; + } + +platform_set_drvdata (pdev, mmc); + +dev_info (&pdev->dev,"initialisation done.\n" ); +return 0 ; + + free_dmabuf: +clk_disable (host->clk); + + clk_free: +clk_put (host->clk); + + probe_free_irq_cd: +free_irq (host->irq_cd, host); + + probe_free_irq: +free_irq (host->irq, host); + + probe_iounmap: +iounmap (host->base); + + probe_free_mem_region: +release_mem_region (host->mem->start,RESSIZE (host->mem)); +drivers/mmc/host/s3cmci.c
Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +7
-0+ probe_free_host: +mmc_free_host (mmc); + probe_out: +return ret; +} + +//FIXME: DMA Resource management ?! ?
Quoted 36 lines
drivers/mmc/host/s3cmci.h new file +36
-0+#define S3CMCI_DMA 0 + +enum s3cmci_waitfor { +COMPLETION_NONE , +COMPLETION_FINALIZE , +COMPLETION_CMDSENT , +COMPLETION_RSPFIN , +COMPLETION_XFERFINISH , +COMPLETION_XFERFINISH_RSPFIN , +}; + +struct s3cmci_host { +struct platform_device *pdev; +struct mmc_host *mmc; +struct resource *mem; +struct clk *clk; +void __iomem *base; +int irq; +int irq_cd; +int dma; + +unsigned long clk_rate; +unsigned long clk_div; +unsigned long real_rate; +u8 prescaler; + +int is2440; +unsigned sdiimsk; +unsigned sdidata; +int dodma; + +volatile int dmatogo; + +struct mmc_request *mrq; +int cmd_is_stop; +drivers/mmc/host/s3cmci.h line 57
Quoted 10 lines
drivers/mmc/host/s3cmci.h new file +10
-0+spinlock_t complete_lock; +volatile enum s3cmci_waitfor + complete_what; + +volatile int dma_complete; + +volatile u32 pio_sgptr; +volatile u32 pio_words; +volatile u32 pio_count; +volatile u32 *pio_ptr;volatiles. checkpatch..
Quoted 16 lines
Quoted 4 lines
drivers/mmc/host/s3cmci.h new file +4
-0+#define XFER_NONE 0 +#define XFER_READ 1 +#define XFER_WRITE 2 +volatile u32 pio_active;drivers/mmc/host/s3cmci.h line 71
Quoted 10 lines
drivers/mmc/host/s3cmci.h new file +10
-0+ +int bus_width; + +char dbgmsg_cmd[301 ]; +char dbgmsg_dat[301 ]; +volatile char *status; + +unsigned int ccnt, dcnt; +struct tasklet_struct pio_tasklet; +};Those problems were really really basic stuff. kernel drivers 101.
Yeah, however I don't want to go about writing a new driver for this from scratch, and having this interface supported would add more support for an SoC series used in an number of PDAs and other devices.
Unfortunatley the original authour isn't interested in getting it submitted (IE, it works for the kernel he needs to use), and other people haven't stepped up to try and get this integrated.
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
(cc's restored. Please don't remove people)
Quoted 5 lines · On Sat, 7 Jun 2008 13:22:27 +0100 Ben Dooks <[email protected]> wrote:
Quoted 5 lines
right at the top of the changelog so that the commit is correctly attributed.
Quoted 1 line
Signed-off-by Ben Dooks <[email protected]>
Quoted 8 lines
Quoted 6 lines
Please pass these patches through chechpatch? This one alone generates
total: 40 errors, 29 warnings, 1488 lines checked
many of which you would have fixed had you been aware of them. That's what checkpatch is for.
Is it ok to fit another patch after this one to fixup these problems?
OK by me, as would be a new patch.
Pierre would be merging this (might have already done so?) - I assume he'd prefer a whole new patch.
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
Quoted 2 lines · Andrew Morton
(cc's restored. Please don't remove people)
Sorry, thought I had replied to all.
Quoted 14 lines · On Sat, 7 Jun 2008 13:22:27 +0100 Ben Dooks <[email protected]> wrote:
Quoted 13 lines
Quoted 12 lines
right at the top of the changelog so that the commit is correctly attributed.
Quoted 1 line
Signed-off-by Ben Dooks <[email protected]>Please pass these patches through chechpatch? This one alone generates
total: 40 errors, 29 warnings, 1488 lines checked
many of which you would have fixed had you been aware of them. That's what checkpatch is for.
Quoted 6 lines
Quoted 1 line
Is it ok to fit another patch after this one to fixup these problems?
OK by me, as would be a new patch.
Pierre would be merging this (might have already done so?) - I assume he'd prefer a whole new patch.
I'll have to post a new series, the changes to cleanup make the rest of the series either fuzz, offset or just fail to apply. I'll run the new series through a test to check that it still works.
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
In reply to Ben DooksQuoted 1 line · On Fri, 06 Jun 2008 16:51:18 +0100 Ben Dooks <[email protected]> wrote:
+#include <
linux/mmc/mmc.h>
You don't need this anymore.
drivers/mmc/host/s3cmci.c line 652
Quoted 1 line
drivers/mmc/host/s3cmci.c new file +1
-0+//if(cmd->flags & MMC_RSP_MAYFAIL) debug_as_failure = 0;
Please remove all the dead code.
drivers/mmc/host/s3cmci.c line 678
Quoted 1 line
drivers/mmc/host/s3cmci.c new file +1
-0+if (mrq->data->error ==MMC_ERR_NONE ) {
And rebase against HEAD. MMC_ERR_* are long gone.
Also, please test using the mmc_test driver available in HEAD. A proper driver should pass all those tests (or possibly mark a few as unsupported if the hardware is utterly incapable of handling those requests).
Rgds
Pierre
Re: [patch 01/15] MMC: S3C24XX MMC/SD driver. From: Thomas Kleffel <[email protected]>
Quoted 6 lines · Pierre Ossman
Quoted 1 line · On Fri, 06 Jun 2008 16:51:18 +0100 Ben Dooks <[email protected]> wrote:
+#include <
linux/mmc/mmc.h>You don't need this anymore.
right, done in patch #2
Quoted 3 lines
drivers/mmc/host/s3cmci.c line 652
Quoted 1 line
drivers/mmc/host/s3cmci.c new file +1
-0+//if(cmd->flags & MMC_RSP_MAYFAIL) debug_as_failure = 0; Please remove all the dead code.
removed in patch #2
Quoted 1 line
drivers/mmc/host/s3cmci.c line 678
Quoted 1 line
drivers/mmc/host/s3cmci.c new file +1
-0+if (mrq->data->error ==MMC_ERR_NONE ) {
ok, i've done:
MMC_ERR_NONE => 0MMC_ERR_DMA => EINVALMMC_ERR_TIMEOUT => ETIMEDOUTMMC_ERR_BADCRC => EILSEQMMC_ERR_FIFO => EILSEQ
Quoted 1 line
And rebase against HEAD. MMC_ERR_* are long gone.
right, will try and build and test as soon as possible.
Quoted 4 lines
Also, please test using the
mmc_testdriver available in HEAD. A proper driver should pass all those tests (or possibly mark a few as unsupported if the hardware is utterly incapable of handling those requests).
Thanks, I'll repost v3 when this is done.
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
PATCH 2/15 MMC: S3C24XX MMC/SD driver write fixes From: Harald Welte <[email protected]>
In reply to Ben DooksThis patch is a workaround of some S3C2410 MMC chip bug
drivers/mmc/host/s3cmci.c +10 -4
@@ -441,11 +441,17 @@ static irqreturn_t s3cmci_irq(int irq, vif (mci_csta &S3C2410_SDICMDSTAT_CRCFAIL ) {if (cmd->flags &MMC_RSP_CRC ) { - cmd->error =MMC_ERR_BADCRC ; - host->status ="error: bad command crc" ; - goto fail_transfer; +if (host->mrq->cmd->flags &MMC_RSP_136 ) { +dbg (host, dbg_irq, +"fixup: ignore CRC fail with long rsp\n" ); + }else { +#if 0 + cmd->error =MMC_ERR_BADCRC ; + host->status ="error: bad command crc" ; + goto fail_transfer; +#endif + } } - mci_cclear |=S3C2410_SDICMDSTAT_CRCFAIL ; }
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 3/15 MMC: DMA free fix for S3C24XX SD/MMC driver From: OpenMoko SVN Harald Welte <[email protected]>
In reply to Ben DooksBugfix to ensure DMA channel allocated is freed on exit.
drivers/mmc/host/s3cmci.c +1 -0
@@ -1245,6 +1245,7 @@ static int s3cmci_remove(struct platformmmc_remove_host (mmc);clk_disable (host->clk);clk_put (host->clk); +s3c2410_dma_free (S3CMCI_DMA , &s3cmci_dma_client);free_irq (host->irq_cd, host);free_irq (host->irq, host);iounmap (host->base);
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 4/15 MMC: S3C24XX MMC/SD stop fix From: Thomas Kleffel <[email protected]>
In reply to Ben DooksFix the request finalisation by ensuring the controller is stopped.
drivers/mmc/host/s3cmci.c +2 -2
@@ -662,7 +662,7 @@ static void finalize_request(struct s3cm#endif //Cleanup controller writel (0 , host->base +S3C2410_SDICMDARG ); -writel (0 , host->base +S3C2410_SDIDCON ); +writel (S3C2410_SDIDCON_STOP , host->base +S3C2410_SDIDCON );writel (0 , host->base +S3C2410_SDICMDCON );writel (0 , host->base + host->sdiimsk);
@@ -789,7 +789,7 @@ static int s3cmci_setup_data(struct s3cmdbg (host, dbg_err,"mci_setup_data() transfer stillin progress.\n" ); -writel (0 , host->base +S3C2410_SDIDCON ); +writel (S3C2410_SDIDCON_STOP , host->base +S3C2410_SDIDCON );s3cmci_reset (host);if (0 == (stoptries--)) {
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 5/15 MMC: Fix S3C24XX IRQ enable during PIO transfers From: Roman Moracik <[email protected]>
In reply to Ben DooksFix Bug #677 - I/O errors on heavy microSD writes for 2.6.22.x.
drivers/mmc/host/s3cmci.c +3 -2
@@ -313,6 +313,7 @@ static void pio_tasklet(unsigned long da {struct s3cmci_host *host = (struct s3cmci_host *) data; +disable_irq (host->irq);if (host->pio_active ==XFER_WRITE )do_pio_write (host);
@@ -331,9 +332,9 @@ static void pio_tasklet(unsigned long da host->mrq->data->error =MMC_ERR_DMA ; } -disable_irq (host->irq);finalize_request (host); - } + }else +enable_irq (host->irq); }/*
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [patch 05/15] MMC: Fix S3C24XX IRQ enable during PIO transfers From: Roman Moracik <[email protected]>
Quoted 9 lines · On Fri, 06 Jun 2008 16:51:22 +0100 Ben Dooks <[email protected]> wrote:
Fix Bug #677 - I/O errors on heavy microSD writes for 2.6.22.x.
Signed-off-by Ben Dooks <[email protected]>Index:
linux-2.6.26-rc5-q/drivers/mmc/host/s3cmci.c
===================================================================
drivers/mmc/host/s3cmci.c static void pio_tasklet(unsigned long da · line 317
Quoted 5 lines
drivers/mmc/host/s3cmci.c +1
-0@@ -313,6 +313,7 @@ static void pio_tasklet(unsigned long da {struct s3cmci_host *host = (struct s3cmci_host *) data; +disable_irq (host->irq);
This seems harsh. Can't you just fiddle with the interrupt mask of this specific device?
PATCH 6/15 MMC: Add platform data for S3C24XX MMC/SD driver
In reply to Ben DooksThis patch adds platform data support to the s3mci driver. This allows flexible board-specific configuration of set_power, card detect and read only pins.
drivers/mmc/host/s3cmci.c +38 -3
@@ -22,6 +22,7 @@#include <asm/io.h> #include <asm/arch/regs-sdi.h> #include <asm/arch/regs-gpio.h> +#include <asm/arch/mci.h> #include "s3cmci.h"
@@ -1009,6 +1010,9 @@ static void s3cmci_set_ios(struct mmc_hos3c2410_gpio_cfgpin (S3C2410_GPE9 ,S3C2410_GPE9_SDDAT2 );s3c2410_gpio_cfgpin (S3C2410_GPE10 ,S3C2410_GPE10_SDDAT3 ); +if (host->pdata->set_power) + host->pdata->set_power (ios->power_mode, ios->vdd); +if (!host->is2440) mci_con|=S3C2410_SDICON_FIFORESET ;
@@ -1019,6 +1023,9 @@ static void s3cmci_set_ios(struct mmc_hos3c2410_gpio_setpin (S3C2410_GPE5 ,0 );s3c2410_gpio_cfgpin (S3C2410_GPE5 ,S3C2410_GPE5_OUTP ); +if (host->pdata->set_power) + host->pdata->set_power (ios->power_mode, ios->vdd); +if (host->is2440) mci_con|=S3C2440_SDICON_SDRESET ;
@@ -1072,9 +1079,26 @@ static void s3cmci_reset(struct s3cmci_hwritel (con, host->base +S3C2410_SDICON ); } +static int s3cmci_get_ro (struct mmc_host *mmc) +{ +struct s3cmci_host *host =mmc_priv (mmc); + +if (host->pdata->gpio_wprotect ==0 ) +return 0 ; + +return s3c2410_gpio_getpin (host->pdata->gpio_wprotect); +} +static struct mmc_host_ops s3cmci_ops = { .request = s3cmci_request, .set_ios = s3cmci_set_ios, + .get_ro = s3cmci_get_ro, +}; + +static struct s3c24xx_mci_pdata s3cmci_def_pdata = { + .gpio_detect =0 , + .set_power =NULL , + .ocr_avail =MMC_VDD_32_33 , };static int s3cmci_probe (struct platform_device *pdev,int is2440)
@@ -1094,6 +1118,12 @@ static int s3cmci_probe(struct platform_ host->mmc = mmc; host->pdev = pdev; + host->pdata = pdev->dev.platform_data; +if (!host->pdata) { + pdev->dev.platform_data = &s3cmci_def_pdata; + host->pdata = &s3cmci_def_pdata; + } +spin_lock_init (&host->complete_lock);tasklet_init (&host->pio_tasklet, pio_tasklet, (unsigned long ) host);if (is2440) {
@@ -1112,7 +1142,8 @@ static int s3cmci_probe(struct platform_ host->pio_active =XFER_NONE ; host->dma =S3CMCI_DMA ; - host->irq_cd =IRQ_EINT2 ; + host->irq_cd =s3c2410_gpio_getirq (host->pdata->gpio_detect); +s3c2410_gpio_cfgpin (host->pdata->gpio_detect,S3C2410_GPIO_IRQ ); host->mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!host->mem) {
@@ -1154,7 +1185,7 @@ static int s3cmci_probe(struct platform_disable_irq (host->irq); -s3c2410_gpio_cfgpin (S3C2410_GPF2 ,S3C2410_GPF2_EINT2 ); +s3c2410_gpio_cfgpin (host->pdata->gpio_detect,S3C2410_GPIO_IRQ );set_irq_type (host->irq_cd,IRQT_BOTHEDGE );if (request_irq (host->irq_cd, s3cmci_irq_cd,0 ,DRIVER_NAME , host)) {
@@ -1165,6 +1196,10 @@ static int s3cmci_probe(struct platform_ goto probe_free_irq; } +if (host->pdata->gpio_wprotect) +s3c2410_gpio_cfgpin (host->pdata->gpio_wprotect, +S3C2410_GPIO_INPUT ); +if (s3c2410_dma_request (S3CMCI_DMA , &s3cmci_dma_client,NULL )) {dev_err (&pdev->dev,"unable to get DMA channel.\n" ); ret = -EBUSY ;
@@ -1187,7 +1222,7 @@ static int s3cmci_probe(struct platform_ host->clk_rate =clk_get_rate (host->clk); mmc->ops = &s3cmci_ops; - mmc->ocr_avail =MMC_VDD_32_33 ; + mmc->ocr_avail = host->pdata->ocr_avail; mmc->caps =MMC_CAP_4_BIT_DATA ; mmc->f_min = host->clk_rate / (host->clk_div *256 ); mmc->f_max = host->clk_rate / host->clk_div;
drivers/mmc/host/s3cmci.h +1 -0
@@ -22,6 +22,7 @@ enum s3cmci_waitfor {struct s3cmci_host {struct platform_device *pdev; +struct s3c24xx_mci_pdata *pdata;struct mmc_host *mmc;struct resource *mem;struct clk *clk;
include/asm-arm/arch-s3c2410/mci.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _ARCH_MCI_H +#define _ARCH_MCI_H + +struct s3c24xx_mci_pdata { +unsigned int gpio_detect; +unsigned int gpio_wprotect; +unsigned long ocr_avail; +void (*set_power)(unsigned char power_mode, +unsigned short vdd); +}; + +#endif /* _ARCH_NCI_H */
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [patch 06/15] MMC: Add platform data for S3C24XX MMC/SD driver
Quoted 6 lines · On Fri, 06 Jun 2008 16:51:23 +0100 Ben Dooks <[email protected]> wrote:
This patch adds platform data support to the s3mci driver. This allows flexible board-specific configuration of
set_power, card detect and read only pins.Signed-off-by Ben Dooks <[email protected]>
Please see the changes in my #next branch where you can return -ENOSYS to indicate that you do not know the state of the read only pin.
drivers/mmc/host/s3cmci.c static void s3cmci_reset(struct s3cmci_h · line 1102
Quoted 6 lines
drivers/mmc/host/s3cmci.c +5
-0+ +static struct s3c24xx_mci_pdata s3cmci_def_pdata = { + .gpio_detect =0 , + .set_power =NULL , + .ocr_avail =MMC_VDD_32_33 , };
You probably want MMC_VDD_32_32 | MMC_VDD_33_34 here.
Re: [patch 06/15] MMC: Add platform data for S3C24XX MMC/SD driver
Quoted 7 lines · Pierre Ossman
Quoted 4 lines · On Fri, 06 Jun 2008 16:51:23 +0100 Ben Dooks <[email protected]> wrote:
This patch adds platform data support to the s3mci driver. This allows flexible board-specific configuration of
set_power, card detect and read only pins.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Ben Dooks <[email protected]>Please see the changes in my #next branch where you can return
-ENOSYSto indicate that you do not know the state of the read only pin.
thanks, fixed.
Quoted 8 lines
drivers/mmc/host/s3cmci.c static void s3cmci_reset(struct s3cmci_h · line 1102
Quoted 6 lines
drivers/mmc/host/s3cmci.c +5
-0+ +static struct s3c24xx_mci_pdata s3cmci_def_pdata = { + .gpio_detect =0 , + .set_power =NULL , + .ocr_avail =MMC_VDD_32_33 , };You probably want
MMC_VDD_32_32|MMC_VDD_33_34here.
Ok, updated.
thanks,
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
PATCH 7/15 MMC: Add support to invert S3C24XX write protect line
In reply to Ben DooksSupport for inverting the sense of the MMC driver's write protect detection line.
drivers/mmc/host/s3cmci.c +9 -2
@@ -1082,11 +1082,18 @@ static void s3cmci_reset(struct s3cmci_hstatic int s3cmci_get_ro (struct mmc_host *mmc) {struct s3cmci_host *host =mmc_priv (mmc); +struct s3c24xx_mci_pdata *pdata = host->pdata; +int ret; -if (host->pdata->gpio_wprotect ==0 ) +if (pdata->gpio_wprotect ==0 )return 0 ; -return s3c2410_gpio_getpin (host->pdata->gpio_wprotect); + ret =s3c2410_gpio_getpin (pdata->gpio_wprotect); + +if (pdata->wprotect_invert) + ret = !ret; + +return ret; }static struct mmc_host_ops s3cmci_ops = {
include/asm-arm/arch-s3c2410/mci.h +2 -0
@@ -2,6 +2,8 @@#define _ARCH_MCI_Hstruct s3c24xx_mci_pdata { +unsigned int wprotect_invert :1 ; +unsigned int gpio_detect;unsigned int gpio_wprotect;unsigned long ocr_avail;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 8/15 MMC: Ensure host->mrq->data is valid in S3C24XX driver
In reply to Ben DooksFix a crash if host->mrq->data is NULL on ending a transfer.
drivers/mmc/host/s3cmci.c +2 -1
@@ -330,7 +330,8 @@ static void pio_tasklet(unsigned long da (host->pio_active ==XFER_READ )?"read" :"write" , host->pio_count, host->pio_words); - host->mrq->data->error =MMC_ERR_DMA ; +if (host->mrq->data) + host->mrq->data->error =MMC_ERR_DMA ; }finalize_request (host);
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 9/15 MMC: Allow card-detect to be on an non-IRQ capable pin on the S3C24XX
In reply to Ben DooksAdd support to the S3C24XX MMC driver to have the card detect be on a pin that is not IRQ capable.
drivers/mmc/host/s3cmci.c +21 -11
@@ -1150,8 +1150,6 @@ static int s3cmci_probe(struct platform_ host->pio_active =XFER_NONE ; host->dma =S3CMCI_DMA ; - host->irq_cd =s3c2410_gpio_getirq (host->pdata->gpio_detect); -s3c2410_gpio_cfgpin (host->pdata->gpio_detect,S3C2410_GPIO_IRQ ); host->mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!host->mem) {
@@ -1193,15 +1191,23 @@ static int s3cmci_probe(struct platform_disable_irq (host->irq); -s3c2410_gpio_cfgpin (host->pdata->gpio_detect,S3C2410_GPIO_IRQ ); -set_irq_type (host->irq_cd,IRQT_BOTHEDGE ); + host->irq_cd =s3c2410_gpio_getirq (host->pdata->gpio_detect); -if (request_irq (host->irq_cd, s3cmci_irq_cd,0 ,DRIVER_NAME , host)) { -dev_err (&pdev->dev, -"failed to request card detect interrupt.\n" ); +if (host->irq_cd >=0 ) { +set_irq_type (host->irq_cd,IRQT_BOTHEDGE ); - ret = -ENOENT ; - goto probe_free_irq; +if (request_irq (host->irq_cd, s3cmci_irq_cd, +IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING ,DRIVER_NAME , host)) { +dev_err (&pdev->dev, +"failed to request card detect interrupt.\n" ); + + ret = -ENOENT ; + goto probe_free_irq; + } + }else { +dev_warn (&pdev->dev,"host detect has no irq available\n" ); +s3c2410_gpio_cfgpin (host->pdata->gpio_detect, +S3C2410_GPIO_INPUT ); }if (host->pdata->gpio_wprotect)
@@ -1264,7 +1270,8 @@ static int s3cmci_probe(struct platform_clk_put (host->clk); probe_free_irq_cd: -free_irq (host->irq_cd, host); +if (host->irq_cd >=0 ) +free_irq (host->irq_cd, host); probe_free_irq:free_irq (host->irq, host);
@@ -1290,8 +1297,11 @@ static int s3cmci_remove(struct platformclk_disable (host->clk);clk_put (host->clk);s3c2410_dma_free (S3CMCI_DMA , &s3cmci_dma_client); -free_irq (host->irq_cd, host); + +if (host->irq_cd >=0 ) +free_irq (host->irq_cd, host);free_irq (host->irq, host); +iounmap (host->base);release_mem_region (host->mem->start,RESSIZE (host->mem));mmc_free_host (mmc);
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [patch 09/15] MMC: Allow card-detect to be on an non-IRQ capable pin on the S3C24XX
Quoted 5 lines · On Fri, 06 Jun 2008 16:51:26 +0100 Ben Dooks <[email protected]> wrote:
Add support to the S3C24XX MMC driver to have the card detect be on a pin that is not IRQ capable.
Signed-off-by Ben Dooks <[email protected]>
How is detection handled in this case? Have a lock in my #next tree for automatic polling by the core.
PATCH 10/15 MMC: Fix s3c24xx driver s3c2410_dma_request() return code check.
In reply to Ben DooksThe driver should be checking for a negative error code from s3c2410_dma_request(), not non-zero. Newer kernels now return the DMA channel number that was allocated by the request.
drivers/mmc/host/s3cmci.c +1 -1
@@ -1214,7 +1214,7 @@ static int s3cmci_probe(struct platform_s3c2410_gpio_cfgpin (host->pdata->gpio_wprotect,S3C2410_GPIO_INPUT ); -if (s3c2410_dma_request (S3CMCI_DMA , &s3cmci_dma_client,NULL )) { +if (s3c2410_dma_request (S3CMCI_DMA , &s3cmci_dma_client,NULL ) <0 ) {dev_err (&pdev->dev,"unable to get DMA channel.\n" ); ret = -EBUSY ; goto probe_free_irq_cd;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 11/15 MMC: Fix the retcode in the S3C24XX MMC/SD driver
In reply to Ben DooksFix the error codes
drivers/mmc/host/s3cmci.c +7 -0
@@ -11,6 +11,7 @@#include <linux/module.h> #include <linux/dma-mapping.h> #include <linux/clk.h> +#include <linux/mmc/core.h> #include <linux/mmc/mmc.h> #include <linux/mmc/host.h> #include <linux/platform_device.h>
@@ -28,6 +29,12 @@#define DRIVER_NAME "s3c-mci" +#define MMC_ERR_NONE (0) +#define MMC_ERR_DMA EINVAL +#define MMC_ERR_TIMEOUT ETIMEDOUT +#define MMC_ERR_BADCRC EILSEQ +#define MMC_ERR_FIFO EILSEQ +enum dbg_channels { dbg_err = (1 <<0 ), dbg_debug = (1 <<1 ),
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Pierre Ossman
NAKRe: [patch 11/15] MMC: Fix the retcode in the S3C24XX MMC/SD driver
Quoted 4 lines · On Fri, 06 Jun 2008 16:51:28 +0100 Ben Dooks <[email protected]> wrote:
Fix the error codes
Signed-off-by Ben Dooks <[email protected]>
NAK, for rather obvious reasons.
Re: [patch 11/15] MMC: Fix the retcode in the S3C24XX MMC/SD driver
Quoted 9 lines · Pierre Ossman
Quoted 4 lines · On Fri, 06 Jun 2008 16:51:28 +0100 Ben Dooks <[email protected]> wrote:
Fix the error codes
Signed-off-by Ben Dooks <[email protected]>NAK, for rather obvious reasons.
Fixed and folded back into patch #2.
thanks,
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
PATCH 12/15 MMC: S3C24XX MMC/SD driver fixes for sg_ access.
In reply to Ben DooksFix sg_ usage in the S3C24XX MMC driver.
drivers/mmc/host/s3cmci.c +1 -1
@@ -204,7 +204,7 @@ static inline int get_data_buffer(struct sg = &host->mrq->data->sg[host->pio_sgptr]; *words = sg->length >>2 ; - *pointer=page_address (sg->page) + sg->offset; + *pointer=sg_virt (sg); host->pio_sgptr++;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 13/15 MMC: s3cmci: Add MODULE_ALIAS() entries for the platform devices
In reply to Ben DooksAdd MODULE_ALIAS() declerations for all the supported platform devices for this driver.
drivers/mmc/host/s3cmci.c +3 -1
@@ -1402,4 +1402,6 @@ module_exit(s3cmci_exit);MODULE_DESCRIPTION ("Samsung S3C MMC/SD Card Interface driver" );MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Thomas Kleffel <[email protected]>" ); - +MODULE_ALIAS ("platform:s3c2410-sdi" ); +MODULE_ALIAS ("platform:s3c2412-sdi" ); +MODULE_ALIAS ("platform:s3c2440-sdi" );
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 14/15 MMC: Fix use of msecs where jiffies are needed
In reply to Ben Dooksmmc_detect_change() takes jiffies, not msecs. Convert the previous value of msecs into jiffies before calling.
drivers/mmc/host/s3cmci.c +1 -1
@@ -567,7 +567,7 @@ static irqreturn_t s3cmci_irq_cd(int irqdbg (host, dbg_irq,"card detect\n" ); -mmc_detect_change (host->mmc,500 ); +mmc_detect_change (host->mmc,msecs_to_jiffies (500 ));return IRQ_HANDLED ; }
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
PATCH 15/15 MMC: Add media presence detection to request handling.
In reply to Ben DooksEnsure that we have physical media present before attempting to send a request to a card. This ensures that we do not get flooded by errors from commands that can never be completed timing out.
drivers/mmc/host/s3cmci.c +20 -1
@@ -991,6 +991,20 @@ static void s3cmci_send_request(struct menable_irq (host->irq); } +static int s3cmci_card_present (struct s3cmci_host *host) +{ +struct s3c24xx_mci_pdata *pdata = host->pdata; +int ret; + +/* if we can't detect the presence, then always have card. */ +if (pdata->gpio_detect ==0 ) +return 1 ; + + ret =s3c2410_gpio_getpin (pdata->gpio_detect) ?0 :1 ; + +return ret ^ pdata->detect_invert; +} +static void s3cmci_request (struct mmc_host *mmc,struct mmc_request *mrq) {struct s3cmci_host *host =mmc_priv (mmc);
@@ -998,7 +1012,12 @@ static void s3cmci_request(struct mmc_ho host->cmd_is_stop =0 ; host->mrq = mrq; -s3cmci_send_request (mmc); +if (!s3cmci_card_present (host)) { +dbg (host, dbg_err,"%s: no medium present\n" , __func__); + host->mrq->cmd->error = -ENOMEDIUM ; +mmc_request_done (mmc, mrq); + }else +s3cmci_send_request (mmc); }static void s3cmci_set_ios (struct mmc_host *mmc,struct mmc_ios *ios)
include/asm-arm/arch-s3c2410/mci.h +1 -0
@@ -3,6 +3,7 @@struct s3c24xx_mci_pdata {unsigned int wprotect_invert :1 ; +unsigned int detect_invert :1 ;/* set => detect active high. */ unsigned int gpio_detect;unsigned int gpio_wprotect;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'