FSL eSDHC support
cover FSL eSDHC support
Hi all,
Thanks for the comments on the previous version, here comes another RFC...
Changes since the second RFC:
- Addressed all comments that were raised by Pierre Ossman. There were too many to mention them all, so here is the link:
http://lkml.org/lkml/2009/2/6/320
Changes since the first RFC:
- Use of_iomap() in sdhci-of.c (suggested by Arnd Bergmann). Also added Arnd's Acked-by: line for the sdhci-of patch.
- Kconfig help text improved (thanks to Matt Sealey and M. Warner Losh).
- In "sdhci: Add quirk to suppress PIO interrupts during DMA transfers"
patch: sdhci_init() now clears SDHCI_PIO_DISABLED flag, otherwise we won't disable PIO interrupts after suspend.
- New patch: "sdhci: Add type checking for IO memory accessors"
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
PATCH 1/13 sdhci: Add quirk for controllers with no end-of-busy IRQ
From: Ben Dooks <[email protected]>
The Samsung SDHCI (and FSL eSDHC) controller block seems to fail to generate an INT_DATA_END after the transfer has completed and the bus busy state finished.
Changes in e809517f6fa5803a5a1cd56026f0e2190fc13d5c to use the new busy method are the cause of the behaviour change.
--- drivers/mmc/host/sdhci.c | 5 ++++- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletions(-)
drivers/mmc/host/sdhci.c +4 -1
@@ -1291,8 +1291,11 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)if (host->cmd->data)DBG ("Cannot wait for busy signal when also " "doing a data transfer" ); -else +else if (!(host->quirks &SDHCI_QUIRK_NO_BUSY_IRQ ))return ; + +/* The controller does not support the end-of-busy IRQ, +* fall through and take the SDHCI_INT_RESPONSE */ }if (intmask &SDHCI_INT_RESPONSE )
drivers/mmc/host/sdhci.h +2 -0
@@ -210,6 +210,8 @@ struct sdhci_host {#define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13)/* Controller supports high speed but doesn't have the caps bit set */ #define SDHCI_QUIRK_FORCE_HIGHSPEED (1<<14) +/* Controller does not provide transfer-complete interrupt when not busy */ +#define SDHCI_QUIRK_NO_BUSY_IRQ (1<<15)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 2/13 sdhci: Add support for bus-specific IO memory accessors
In reply to Anton VorontsovCurrently the SDHCI driver works with PCI accessors (write{l,b,w} and read{l,b,w}).
With this patch drivers may change memory accessors, so that we can support hosts with "weird" IO memory access requirments.
For example, in "FSL eSDHC" SDHCI hardware all registers are 32 bit width, with big-endian addressing. That is, readb(0x2f) should turn into readb(0x2c), and readw(0x2c) should be translated to le16_to_cpu(readw(0x2e)).
--- drivers/mmc/host/sdhci-pci.c | 4 +- drivers/mmc/host/sdhci.c | 214 ++++++++++++++++++++++++++---------------- drivers/mmc/host/sdhci.h | 14 +++ 3 files changed, 149 insertions(+), 83 deletions(-)
drivers/mmc/host/sdhci-pci.c +2 -2
@@ -212,7 +212,7 @@ static int jmicron_probe_slot(struct sdhci_pci_slot *slot)if (slot->chip->pdev->revision ==0 ) {u16 version; - version =readl (slot->host->ioaddr +SDHCI_HOST_VERSION ); + version =sdhci_readl (slot->host,SDHCI_HOST_VERSION ); version = (version &SDHCI_VENDOR_VER_MASK ) >>SDHCI_VENDOR_VER_SHIFT ;
@@ -583,7 +583,7 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)u32 scratch; dead =0 ; - scratch =readl (slot->host->ioaddr +SDHCI_INT_STATUS ); + scratch =sdhci_readl (slot->host,SDHCI_INT_STATUS );if (scratch == (u32)-1 ) dead =1 ;
drivers/mmc/host/sdhci.c +133 -81
505 lines not on this page · raw message
drivers/mmc/host/sdhci.h +14 -0
@@ -9,6 +9,7 @@* your option) any later version. */ +#include <linux/types.h> #include <linux/scatterlist.h> /*
@@ -268,9 +269,22 @@ struct sdhci_host {struct sdhci_ops { +u32 (*readl)(struct sdhci_host *host,int reg); +u16 (*readw)(struct sdhci_host *host,int reg); +u8 (*readb)(struct sdhci_host *host,int reg); +void (*writel)(struct sdhci_host *host,u32 val,int reg); +void (*writew)(struct sdhci_host *host,u16 val,int reg); +void (*writeb)(struct sdhci_host *host,u8 val,int reg); +int (*enable_dma)(struct sdhci_host *host); }; +extern void sdhci_writel (struct sdhci_host *host,u32 val,int reg); +extern void sdhci_writew (struct sdhci_host *host,u16 val,int reg); +extern void sdhci_writeb (struct sdhci_host *host,u8 val,int reg); +extern u32 sdhci_readl (struct sdhci_host *host,int reg); +extern u16 sdhci_readw (struct sdhci_host *host,int reg); +extern u8 sdhci_readb (struct sdhci_host *host,int reg);extern struct sdhci_host *sdhci_alloc_host (struct device *dev,size_t priv_size);
Signature · 1 line
1.5.6.5
PATCH 3/13 sdhci: Split card-detection IRQs management from sdhci_init()
In reply to Anton VorontsovCard detection interrupts should be handled separately as they should not be enabled before mmc_add_host() returns and should be disabled before calling mmc_remove_host(). The same is for suspend and resume routines.
sdhci_init() no longer enables card-detection irqs. Instead, two new functions implemented: sdhci_enable_card_detection() and sdhci_disable_card_detection().
New sdhci_reinit() call implemented to behave the same way as the old sdhci_init().
Also, this patch implements and uses few new helpers to manage IRQs in a more conveinient way, that is:
- sdhci_clear_set_irqs()
- sdhci_unmask_irqs()
- sdhci_mask_irqs()
- SDHCI_INT_ALL_MASK constant
sdhci_enable_sdio_irq() converted to these new helpers, plus the helpers will be used by the subsequent patches.
--- drivers/mmc/host/sdhci.c | 78 ++++++++++++++++++++++++++++++++++++---------- drivers/mmc/host/sdhci.h | 4 ++ 2 files changed, 65 insertions(+), 17 deletions(-)
drivers/mmc/host/sdhci.c +61 -17
@@ -142,6 +142,47 @@ u8 sdhci_readb(struct sdhci_host *host, int reg) }EXPORT_SYMBOL_GPL (sdhci_readb); +static void sdhci_clear_set_irqs (struct sdhci_host *host,u32 clear,u32 set) +{ +u32 ier; + + ier =sdhci_readl (host,SDHCI_INT_ENABLE ); + ier &= ~clear; + ier |= set; +sdhci_writel (host, ier,SDHCI_INT_ENABLE ); +sdhci_writel (host, ier,SDHCI_SIGNAL_ENABLE ); +} + +static void sdhci_unmask_irqs (struct sdhci_host *host,u32 irqs) +{ +sdhci_clear_set_irqs (host,0 , irqs); +} + +static void sdhci_mask_irqs (struct sdhci_host *host,u32 irqs) +{ +sdhci_clear_set_irqs (host, irqs,0 ); +} + +static void sdhci_set_card_detection (struct sdhci_host *host,bool enable) +{ +u32 irqs =SDHCI_INT_CARD_REMOVE |SDHCI_INT_CARD_INSERT ; + +if (enable) +sdhci_unmask_irqs (host, irqs); +else +sdhci_mask_irqs (host, irqs); +} + +static void sdhci_enable_card_detection (struct sdhci_host *host) +{ +sdhci_set_card_detection (host, true); +} + +static void sdhci_disable_card_detection (struct sdhci_host *host) +{ +sdhci_set_card_detection (host, false); +} +static void sdhci_reset (struct sdhci_host *host,u8 mask) {unsigned long timeout;
@@ -175,20 +216,21 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)static void sdhci_init (struct sdhci_host *host) { -u32 intmask; -sdhci_reset (host,SDHCI_RESET_ALL ); - intmask =SDHCI_INT_BUS_POWER |SDHCI_INT_DATA_END_BIT | +sdhci_clear_set_irqs (host,SDHCI_INT_ALL_MASK , +SDHCI_INT_BUS_POWER |SDHCI_INT_DATA_END_BIT |SDHCI_INT_DATA_CRC |SDHCI_INT_DATA_TIMEOUT |SDHCI_INT_INDEX |SDHCI_INT_END_BIT |SDHCI_INT_CRC |SDHCI_INT_TIMEOUT | -SDHCI_INT_CARD_REMOVE |SDHCI_INT_CARD_INSERT |SDHCI_INT_DATA_AVAIL |SDHCI_INT_SPACE_AVAIL |SDHCI_INT_DMA_END |SDHCI_INT_DATA_END |SDHCI_INT_RESPONSE | -SDHCI_INT_ADMA_ERROR ; +SDHCI_INT_ADMA_ERROR ); +} -sdhci_writel (host, intmask,SDHCI_INT_ENABLE ); -sdhci_writel (host, intmask,SDHCI_SIGNAL_ENABLE ); +static void sdhci_reinit (struct sdhci_host *host) +{ +sdhci_init (host); +sdhci_enable_card_detection (host); }static void sdhci_activate_led (struct sdhci_host *host)
@@ -1087,7 +1129,7 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)*/ if (ios->power_mode ==MMC_POWER_OFF ) {sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE ); -sdhci_init (host); +sdhci_reinit (host); }sdhci_set_clock (host, ios->clock);
@@ -1148,7 +1190,6 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) {struct sdhci_host *host;unsigned long flags; -u32 ier; host =mmc_priv (mmc);
@@ -1157,15 +1198,10 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)if (host->flags &SDHCI_DEVICE_DEAD ) goto out; - ier =sdhci_readl (host,SDHCI_INT_ENABLE ); - - ier &= ~SDHCI_INT_CARD_INT ;if (enable) - ier |=SDHCI_INT_CARD_INT ; - -sdhci_writel (host, ier,SDHCI_INT_ENABLE ); -sdhci_writel (host, ier,SDHCI_SIGNAL_ENABLE ); - +sdhci_unmask_irqs (host,SDHCI_INT_CARD_INT ); +else +sdhci_mask_irqs (host,SDHCI_INT_CARD_INT ); out:mmiowb ();
@@ -1507,6 +1543,8 @@ int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) {int ret; +sdhci_disable_card_detection (host); + ret =mmc_suspend_host (host->mmc, state);if (ret)return ret;
@@ -1539,6 +1577,8 @@ int sdhci_resume_host(struct sdhci_host *host)if (ret)return ret; +sdhci_enable_card_detection (host); +return 0 ; }
@@ -1792,6 +1832,8 @@ int sdhci_add_host(struct sdhci_host *host)mmc_add_host (mmc); +sdhci_enable_card_detection (host); + printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n", mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), (host->flags & SDHCI_USE_ADMA)?"A":"",
@@ -1833,6 +1875,8 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)spin_unlock_irqrestore (&host->lock, flags); } +sdhci_disable_card_detection (host); +mmc_remove_host (host->mmc);#ifdef SDHCI_USE_LEDS_CLASS
drivers/mmc/host/sdhci.h +4 -0
@@ -124,6 +124,10 @@ SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \ SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \ SDHCI_INT_DATA_END_BIT) +#define SDHCI_INT_ALL_MASK (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK | \ + SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE | \ + SDHCI_INT_CARD_INT | SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER | \ + SDHCI_INT_ACMD12ERR | SDHCI_INT_ADMA_ERROR)#define SDHCI_ACMD12_ERR 0x3C
Signature · 1 line
1.5.6.5
PATCH 4/13 sdhci: Enable only relevant (DMA/PIO) interrupts during transfers
In reply to Anton VorontsovSome hosts (that is, FSL eSDHC) throw PIO interrupts during DMA transfers, this causes tons of unneeded interrupts, and thus highly degraded speed.
This patch modifies the driver so that now we only enable relevant (DMA or PIO) interrupts during transfers.
--- drivers/mmc/host/sdhci.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci.c +14 -3
@@ -222,9 +222,7 @@ static void sdhci_init(struct sdhci_host *host)SDHCI_INT_BUS_POWER |SDHCI_INT_DATA_END_BIT |SDHCI_INT_DATA_CRC |SDHCI_INT_DATA_TIMEOUT |SDHCI_INT_INDEX |SDHCI_INT_END_BIT |SDHCI_INT_CRC |SDHCI_INT_TIMEOUT | -SDHCI_INT_DATA_AVAIL |SDHCI_INT_SPACE_AVAIL | -SDHCI_INT_DMA_END |SDHCI_INT_DATA_END |SDHCI_INT_RESPONSE | - SDHCI_INT_ADMA_ERROR); + SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE); }static void sdhci_reinit (struct sdhci_host *host)
@@ -658,6 +656,17 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)return count; } +static void sdhci_set_transfer_irqs (struct sdhci_host *host) +{ +u32 pio_irqs =SDHCI_INT_DATA_AVAIL |SDHCI_INT_SPACE_AVAIL ; +u32 dma_irqs =SDHCI_INT_DMA_END |SDHCI_INT_ADMA_ERROR ; + +if (host->flags &SDHCI_REQ_USE_DMA ) +sdhci_clear_set_irqs (host, pio_irqs, dma_irqs); +else +sdhci_clear_set_irqs (host, dma_irqs, pio_irqs); +} +static void sdhci_prepare_data (struct sdhci_host *host,struct mmc_data *data) {u8 count;
@@ -806,6 +815,8 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) host->blocks = data->blocks; } +sdhci_set_transfer_irqs (host); +/* We do not handle DMA boundaries, so set it to max (512 KiB) */ sdhci_writew (host,SDHCI_MAKE_BLKSZ (7 , data->blksz),SDHCI_BLOCK_SIZE );sdhci_writew (host, data->blocks,SDHCI_BLOCK_COUNT );
Signature · 1 line
1.5.6.5
PATCH 5/13 sdhci: Add support for card-detection polling
In reply to Anton VorontsovThis patch adds SDHCI_QUIRK_BROKEN_CARD_DETECTION quirk. When specified, sdhci driver will set MMC_CAP_NEEDS_POLL MMC host capability, and won't enable card insert/remove interrupts.
This is needed for hosts with unreliable card detection, such as FSL eSDHC. The original eSDHC driver was tring to "debounce" card-detection IRQs by reading present state and disabling particular interrupts. But with this debouncing scheme I noticed that sometimes we miss card insertion/removal events.
--- drivers/mmc/host/sdhci.c | 17 ++++++++++++++--- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci.c +14 -3
@@ -167,6 +167,9 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) {u32 irqs =SDHCI_INT_CARD_REMOVE |SDHCI_INT_CARD_INSERT ; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) +return ; +if (enable)sdhci_unmask_irqs (host, irqs);else
@@ -1110,13 +1113,18 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) host->mrq = mrq; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) + goto send; +if (!(sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ) || (host->flags &SDHCI_DEVICE_DEAD )) { host->mrq->cmd->error = -ENOMEDIUM ;tasklet_schedule (&host->finish_tasklet); - }else -sdhci_send_command (host, mrq->cmd); - + goto out; + } +send: +sdhci_send_command (host, mrq->cmd); +out:mmiowb ();spin_unlock_irqrestore (&host->lock, flags); }
@@ -1742,6 +1750,9 @@ int sdhci_add_host(struct sdhci_host *host) mmc->f_max = host->max_clk; mmc->caps =MMC_CAP_4_BIT_DATA |MMC_CAP_SDIO_IRQ ; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) + mmc->caps |=MMC_CAP_NEEDS_POLL ; +if ((caps &SDHCI_CAN_DO_HISPD ) || (host->quirks &SDHCI_QUIRK_FORCE_HIGHSPEED )) mmc->caps |=MMC_CAP_SD_HIGHSPEED ;
drivers/mmc/host/sdhci.h +2 -0
@@ -217,6 +217,8 @@ struct sdhci_host {#define SDHCI_QUIRK_FORCE_HIGHSPEED (1<<14)/* Controller does not provide transfer-complete interrupt when not busy */ #define SDHCI_QUIRK_NO_BUSY_IRQ (1<<15) +/* Controller has unreliable card detection */ +#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<16)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 6/13 sdhci: Add support for hosts reporting inverted write-protect state
In reply to Anton VorontsovThis patch adds SDHCI_QUIRK_INVERTED_WRITE_PROTECT quirk. When specified, the sdhci driver will invert WP state.
p.s. Actually, the quirk is more board-specific than
controller-specific.
--- drivers/mmc/host/sdhci.c | 2 ++ drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +2 -0
@@ -1202,6 +1202,8 @@ static int sdhci_get_ro(struct mmc_host *mmc)spin_unlock_irqrestore (&host->lock, flags); +if (host->quirks &SDHCI_QUIRK_INVERTED_WRITE_PROTECT ) +return !!(present &SDHCI_WRITE_PROTECT );return !(present &SDHCI_WRITE_PROTECT ); }
drivers/mmc/host/sdhci.h +2 -0
@@ -219,6 +219,8 @@ struct sdhci_host {#define SDHCI_QUIRK_NO_BUSY_IRQ (1<<15)/* Controller has unreliable card detection */ #define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<16) +/* Controller reports inverted write-protect state */ +#define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<17)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 7/13 sdhci: Add support for hosts with strict 32 bit addressing
In reply to Anton VorontsovSDHCI driver must take special care when working with "triggering" registers on hosts with strict 32 bit addressing.
In FSL eSDHC hosts all registers are 32 bit width, writing to the first half of any register will cause [undefined?] write the second half of the register. That is, 16 bit write to the TRANSFER_MODE register, makes hardware see a bogus write to the COMMAND register (these two registers are adjacent).
This patch adds SDHCI_QUIRK_32BIT_REGISTERS quirk. When specified, the sdhci driver will try to "pack" all dangerous writes into single 32 bit write transaction.
--- drivers/mmc/host/sdhci.c | 19 ++++++++++++++----- drivers/mmc/host/sdhci.h | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci.c +14 -5
@@ -825,13 +825,13 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)sdhci_writew (host, data->blocks,SDHCI_BLOCK_COUNT ); } -static void sdhci_set_transfer_mode (struct sdhci_host *host, +static u16 sdhci_get_transfer_mode (struct sdhci_host *host,struct mmc_data *data) {u16 mode;if (data ==NULL ) -return ; +return 0 ;WARN_ON (!host->data);
@@ -843,7 +843,7 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,if (host->flags &SDHCI_REQ_USE_DMA ) mode |=SDHCI_TRNS_DMA ; -sdhci_writew (host, mode,SDHCI_TRANSFER_MODE ); +return mode; }static void sdhci_finish_data (struct sdhci_host *host)
@@ -895,6 +895,7 @@ static void sdhci_finish_data(struct sdhci_host *host)static void sdhci_send_command (struct sdhci_host *host,struct mmc_command *cmd) {int flags; +u16 xfer_mode;u32 mask;unsigned long timeout;
@@ -933,7 +934,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT ); -sdhci_set_transfer_mode (host, cmd->data); + xfer_mode =sdhci_get_transfer_mode (host, cmd->data);if ((cmd->flags &MMC_RSP_136 ) && (cmd->flags &MMC_RSP_BUSY )) { printk(KERN_ERR "%s: Unsupported response type!\n",
@@ -959,7 +960,15 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)if (cmd->data) flags |=SDHCI_CMD_DATA ; -sdhci_writew (host,SDHCI_MAKE_CMD (cmd->opcode, flags),SDHCI_COMMAND ); +if (host->quirks &SDHCI_QUIRK_32BIT_REGISTERS ) { +sdhci_writel (host, +SDHCI_MAKE_CMD_32BIT (cmd->opcode, flags, xfer_mode), +SDHCI_TRANSFER_MODE ); + }else { +sdhci_writew (host, xfer_mode,SDHCI_TRANSFER_MODE ); +sdhci_writew (host,SDHCI_MAKE_CMD (cmd->opcode, flags), +SDHCI_COMMAND ); + } }static void sdhci_finish_command (struct sdhci_host *host)
drivers/mmc/host/sdhci.h +4 -0
@@ -44,6 +44,8 @@#define SDHCI_CMD_RESP_SHORT_BUSY 0x03#define SDHCI_MAKE_CMD (c, f) (((c & 0xff) << 8) | (f & 0xff)) +#define SDHCI_MAKE_CMD_32BIT (c, f, m) \ + ((((c) & 0xff) << 24) | (((f) & 0xff) << 16) | ((m) & 0x37))#define SDHCI_RESPONSE 0x10
@@ -221,6 +223,8 @@ struct sdhci_host {#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<16)/* Controller reports inverted write-protect state */ #define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<17) +/* Controller has all registers of 32 bit width */ +#define SDHCI_QUIRK_32BIT_REGISTERS (1<<18)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 8/13 sdhci: Add get_{max,timeout}_clock callbacks
In reply to Anton VorontsovFrom: Ben Dooks <[email protected]>
Some controllers do not provide clock information in their capabilities (in the Samsung case, it is because there are multiple clock sources available to the controller). Add hooks to allow the system to supply clock information.
p.s.
In the original Ben's patch there was a bug that makes sdhci_add_host() return -ENODEV even if callbacks were specified. This is fixed now.
--- drivers/mmc/host/sdhci.c | 22 +++++++++++++++------- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-)
drivers/mmc/host/sdhci.c +15 -7
@@ -1736,19 +1736,27 @@ int sdhci_add_host(struct sdhci_host *host) host->max_clk = (caps &SDHCI_CLOCK_BASE_MASK ) >>SDHCI_CLOCK_BASE_SHIFT ; + host->max_clk *=1000000 ;if (host->max_clk ==0 ) { -printk (KERN_ERR "%s: Hardware doesn't specify base clock " -"frequency.\n" ,mmc_hostname (mmc)); -return -ENODEV ; +if (!host->ops->get_max_clock) { +printk (KERN_ERR +"%s: Hardware doesn't specify base clock " +"frequency.\n" ,mmc_hostname (mmc)); +return -ENODEV ; + } + host->max_clk = host->ops->get_max_clock (host); } - host->max_clk *=1000000 ; host->timeout_clk = (caps &SDHCI_TIMEOUT_CLK_MASK ) >>SDHCI_TIMEOUT_CLK_SHIFT ;if (host->timeout_clk ==0 ) { -printk (KERN_ERR "%s: Hardware doesn't specify timeout clock " -"frequency.\n" ,mmc_hostname (mmc)); -return -ENODEV ; +if (!host->ops->get_timeout_clock) { +printk (KERN_ERR +"%s: Hardware doesn't specify timeout clock " +"frequency.\n" ,mmc_hostname (mmc)); +return -ENODEV ; + } + host->timeout_clk = host->ops->get_timeout_clock (host); }if (caps &SDHCI_TIMEOUT_CLK_UNIT ) host->timeout_clk *=1000 ;
drivers/mmc/host/sdhci.h +2 -0
@@ -289,6 +289,8 @@ struct sdhci_ops {void (*writeb)(struct sdhci_host *host,u8 val,int reg);int (*enable_dma)(struct sdhci_host *host); +unsigned int (*get_max_clock)(struct sdhci_host *host); +unsigned int (*get_timeout_clock)(struct sdhci_host *host); };extern void sdhci_writel (struct sdhci_host *host,u32 val,int reg);
Signature · 1 line
1.5.6.5
PATCH 9/13 sdhci: Add set_clock callback and a quirk for nonstandard clocks
In reply to Anton VorontsovFSL eSDHC hosts have incompatible register map to manage the SDCLK. This patch adds set_clock callback so that drivers could overwrite set_clock behaviour.
Similar patch[1] was posted by Ben Dooks, though in Ben's version the callback is named change_clock, plus the patch has some unrelated bits that makes the patch difficult to reuse.
[1] http://lkml.org/lkml/2008/12/2/160
--- drivers/mmc/host/sdhci.c | 6 ++++++ drivers/mmc/host/sdhci.h | 4 ++++ 2 files changed, 10 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +6 -0
@@ -1013,6 +1013,12 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)if (clock == host->clock)return ; +if (host->ops->set_clock) { + host->ops->set_clock (host, clock); +if (host->quirks &SDHCI_QUIRK_NONSTANDARD_CLOCK ) +return ; + } +sdhci_writew (host,0 ,SDHCI_CLOCK_CONTROL );if (clock ==0 )
drivers/mmc/host/sdhci.h +4 -0
@@ -225,6 +225,8 @@ struct sdhci_host {#define SDHCI_QUIRK_INVERTED_WRITE_PROTECT (1<<17)/* Controller has all registers of 32 bit width */ #define SDHCI_QUIRK_32BIT_REGISTERS (1<<18) +/* Controller has nonstandard clock management */ +#define SDHCI_QUIRK_NONSTANDARD_CLOCK (1<<19)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
@@ -288,6 +290,8 @@ struct sdhci_ops {void (*writew)(struct sdhci_host *host,u16 val,int reg);void (*writeb)(struct sdhci_host *host,u8 val,int reg); +void (*set_clock)(struct sdhci_host *host,unsigned int clock); +int (*enable_dma)(struct sdhci_host *host);unsigned int (*get_max_clock)(struct sdhci_host *host);unsigned int (*get_timeout_clock)(struct sdhci_host *host);
Signature · 1 line
1.5.6.5
PATCH 10/13 sdhci: Add quirk for controllers that need small delays for PIO
In reply to Anton VorontsovSmall udelay is needed to make eSDHC work in PIO mode. Without the delay reading causes endless interrupt storm, and writing corrupts data. The first guess would be that we must wait for some bit in some register, but I didn't find any reliable bits that change before and after the delay.
--- drivers/mmc/host/sdhci.c | 3 +++ drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 5 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +3 -0
@@ -391,6 +391,9 @@ static void sdhci_transfer_pio(struct sdhci_host *host) mask = ~0 ;while (sdhci_readl (host,SDHCI_PRESENT_STATE ) & mask) { +if (host->quirks &SDHCI_QUIRK_PIO_NEEDS_DELAY ) +udelay (100 ); +if (host->data->flags &MMC_DATA_READ )sdhci_read_block_pio (host);else
drivers/mmc/host/sdhci.h +2 -0
@@ -227,6 +227,8 @@ struct sdhci_host {#define SDHCI_QUIRK_32BIT_REGISTERS (1<<18)/* Controller has nonstandard clock management */ #define SDHCI_QUIRK_NONSTANDARD_CLOCK (1<<19) +/* Controller does not like fast PIO transfers */ +#define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<20)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 11/13 sdhci: Add quirk for controllers that need IRQ re-init after reset
In reply to Anton VorontsovFSL eSDHC controllers losing signal/interrupt enable states after reset, so we should re-enable them.
--- drivers/mmc/host/sdhci.c | 7 +++++++ drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 9 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +7 -0
@@ -189,6 +189,7 @@ static void sdhci_disable_card_detection(struct sdhci_host *host)static void sdhci_reset (struct sdhci_host *host,u8 mask) {unsigned long timeout; +u32 ier =0 ;/* shut up gcc */ if (host->quirks &SDHCI_QUIRK_NO_CARD_NO_RESET ) { if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
@@ -196,6 +197,9 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)return ; } +if (host->quirks &SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET ) + ier =sdhci_readl (host,SDHCI_INT_ENABLE ); +sdhci_writeb (host, mask,SDHCI_SOFTWARE_RESET );if (mask &SDHCI_RESET_ALL )
@@ -215,6 +219,9 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask) timeout--;mdelay (1 ); } + +if (host->quirks &SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET ) +sdhci_clear_set_irqs (host,SDHCI_INT_ALL_MASK , ier); }static void sdhci_init (struct sdhci_host *host)
drivers/mmc/host/sdhci.h +2 -0
@@ -229,6 +229,8 @@ struct sdhci_host {#define SDHCI_QUIRK_NONSTANDARD_CLOCK (1<<19)/* Controller does not like fast PIO transfers */ #define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<20) +/* Controller losing signal/interrupt enable states after reset */ +#define SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET (1<<21)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 12/13 sdhci: Add quirk for controllers with max. block size up to 4096 bytes
In reply to Anton VorontsovFSL eSDHC controllers can support maximum block size up to 4096 bytes. The MBL (Maximum Block Length) field in the capabilities register extended by one bit, and bits 13:15 in the block size register reserved.
--- drivers/mmc/host/sdhci.c | 28 ++++++++++++++++++++-------- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci.c +20 -8
@@ -682,6 +682,7 @@ static void sdhci_set_transfer_irqs(struct sdhci_host *host)static void sdhci_prepare_data (struct sdhci_host *host,struct mmc_data *data) { +u16 blksz;u8 count;u8 ctrl;int ret;
@@ -831,7 +832,12 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)sdhci_set_transfer_irqs (host);/* We do not handle DMA boundaries, so set it to max (512 KiB) */ -sdhci_writew (host,SDHCI_MAKE_BLKSZ (7 , data->blksz),SDHCI_BLOCK_SIZE ); +if (host->quirks &SDHCI_QUIRK_MAX_BLK_SZ_4096 ) + blksz = data->blksz; +else + blksz =SDHCI_MAKE_BLKSZ (7 , data->blksz); + +sdhci_writew (host, blksz,SDHCI_BLOCK_SIZE );sdhci_writew (host, data->blocks,SDHCI_BLOCK_COUNT ); }
@@ -1840,13 +1846,19 @@ int sdhci_add_host(struct sdhci_host *host)* Maximum block size. This varies from controller to controller and * is specified in the capabilities register. */ - mmc->max_blk_size = (caps &SDHCI_MAX_BLOCK_MASK ) >>SDHCI_MAX_BLOCK_SHIFT ; -if (mmc->max_blk_size >=3 ) { -printk (KERN_WARNING "%s: Invalid maximum block size, " -"assuming 512 bytes\n" ,mmc_hostname (mmc)); - mmc->max_blk_size =512 ; - }else - mmc->max_blk_size =512 << mmc->max_blk_size; +if (host->quirks &SDHCI_QUIRK_MAX_BLK_SZ_4096 ) { + mmc->max_blk_size =3 ; + }else { + mmc->max_blk_size = (caps &SDHCI_MAX_BLOCK_MASK ) >> +SDHCI_MAX_BLOCK_SHIFT ; +if (mmc->max_blk_size >=3 ) { +printk (KERN_WARNING "%s: Invalid maximum block size, " +"assuming 512 bytes\n" ,mmc_hostname (mmc)); + mmc->max_blk_size =0 ; + } + } + + mmc->max_blk_size =512 << mmc->max_blk_size;/* * Maximum block count.
drivers/mmc/host/sdhci.h +2 -0
@@ -231,6 +231,8 @@ struct sdhci_host {#define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<20)/* Controller losing signal/interrupt enable states after reset */ #define SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET (1<<21) +/* Controller supports nonstandard maximum block length of 4096 bytes */ +#define SDHCI_QUIRK_MAX_BLK_SZ_4096 (1<<22)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 1 line
1.5.6.5
PATCH 13/13 mmc: Add OpenFirmware bindings for SDHCI driver
In reply to Anton VorontsovThis patch adds a new driver: sdhci-of. The driver is similar to the sdhci-pci, it contains common probe code, and controller-specific ops and quirks.
So far there are only Freescale eSDHC ops and quirks.
--- drivers/mmc/host/Kconfig | 10 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-of.c | 286 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 0 deletions(-) create mode 100644 drivers/mmc/host/sdhci-of.c
drivers/mmc/host/Kconfig +10 -0
@@ -65,6 +65,16 @@ config MMC_RICOH_MMC If unsure, say Y. +config MMC_SDHCI_OF + tristate "SDHCI support on OpenFirmware platforms" + depends on MMC_SDHCI && PPC_OF + help + This selects the OF support for Secure Digital Host Controller + Interfaces. So far, only the Freescale eSDHC controller is known + to exist on OF platforms. + + If unsure, say N. + config MMC_OMAP tristate "TI OMAP Multimedia Card Interface support" depends on ARCH_OMAP
drivers/mmc/host/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_MMC_MXC) += mxcmmc.o obj-$(CONFIG_MMC_SDHCI) += sdhci.o obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o obj-$(CONFIG_MMC_RICOH_MMC) += ricoh_mmc.o +obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o obj-$(CONFIG_MMC_WBSD) += wbsd.o obj-$(CONFIG_MMC_AU1X) += au1xmmc.o obj-$(CONFIG_MMC_OMAP) += omap.o
drivers/mmc/host/sdhci-of.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Re: [PATCH 11/13] sdhci: Add quirk for controllers that need IRQ re-init after reset
In reply to Anton VorontsovHi Anton,
Quoted 14 lines · On Friday 13 February 2009 15:47:38 Anton Vorontsov wrote:
FSL eSDHC controllers losing signal/interrupt enable states after reset, so we should re-enable them.
Signed-off-by Anton Vorontsov <[email protected]>--- drivers/mmc/host/sdhci.c | 7 +++++++ drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 9 insertions(+), 0 deletions(-)drivers/mmc/host/sdhci.c +0
-0
drivers/mmc/host/sdhci.c static void sdhci_disable_card_detection(struct · line 192
Quoted 4 lines
drivers/mmc/host/sdhci.c +1
-0@@ -189,6 +189,7 @@ static void sdhci_disable_card_detection(struct sdhci_host *host) static void sdhci_reset(struct sdhci_host *host, u8 mask) {unsigned long timeout; +u32 ier =0 ;/* shut up gcc */
You should use
u32 uninitialized_var(ier);
instead to avoid generating extra code.
Quoted 36 lines
drivers/mmc/host/sdhci.c +6
-0if (host->quirks &SDHCI_QUIRK_NO_CARD_NO_RESET ) { if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) &@@ -196,6 +197,9 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask) return; } +if (host->quirks &SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET ) + ier =sdhci_readl (host,SDHCI_INT_ENABLE ); +sdhci_writeb (host, mask,SDHCI_SOFTWARE_RESET );if (mask &SDHCI_RESET_ALL )@@ -215,6 +219,9 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask) timeout--;mdelay (1 ); } + +if (host->quirks &SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET ) +sdhci_clear_set_irqs (host,SDHCI_INT_ALL_MASK , ier); }static void sdhci_init (struct sdhci_host *host)drivers/mmc/host/sdhci.h +2
-0@@ -229,6 +229,8 @@ struct sdhci_host {#define SDHCI_QUIRK_NONSTANDARD_CLOCK (1<<19)/* Controller does not like fast PIO transfers */ #define SDHCI_QUIRK_PIO_NEEDS_DELAY (1<<20) +/* Controller losing signal/interrupt enable states after reset */ +#define SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET (1<<21)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussee de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Re: [PATCH 11/13] sdhci: Add quirk for controllers that need IRQ re-init after reset
Quoted 3 lines · Laurent Pinchart
Hi Anton,
On Friday 13 February 2009 15:47:38 Anton Vorontsov wrote:
[...]
Quoted 10 lines
drivers/mmc/host/sdhci.c static void sdhci_disable_card_detection(struct sdhci_host *host) · line 192
Quoted 4 lines
sdhci_host*host) static voidsdhci_reset(struct sdhci_host *host, u8 mask)
{drivers/mmc/host/sdhci.c +1
-0unsigned long timeout; +u32 ier =0 ;/* shut up gcc */ You should use
u32 uninitialized_var(ier);instead to avoid generating extra code.
Thanks Laurent, will fix.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 10 lines · Anton Vorontsov
Hi all,
Thanks for the comments on the previous version, here comes another RFC...
Changes since the second RFC:
- Addressed all comments that were raised by Pierre Ossman. There were too many to mention them all, so here is the link:
http://lkml.org/lkml/2009/2/6/320
Quoted 8 lines
Changes since the first RFC:
- Useof_iomap()insdhci-of.c(suggested by Arnd Bergmann). Also added Arnd's Acked-by: line for the sdhci-of patch.
-Kconfighelp text improved (thanks to Matt Sealey and M. Warner Losh).
- In "sdhci: Add quirk to suppress PIO interrupts during DMA transfers"
patch:sdhci_init()now clearsSDHCI_PIO_DISABLEDflag, otherwise we won't disable PIO interrupts after suspend.
- New patch: "sdhci: Add type checking for IO memory accessors"
It would be useful to know what Pierre thinks of these, I would like to update the sdhci-s3c binding before the next merge window.
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Re: [PATCH 03/13] sdhci: Split card-detection IRQs management from sdhci_init()
In reply to Anton VorontsovQuoted 20 lines · On Fri, 13 Feb 2009 17:47:15 +0300 Anton Vorontsov <[email protected]>…
Card detection interrupts should be handled separately as they should not be enabled before
mmc_add_host()returns and should be disabled before callingmmc_remove_host(). The same is for suspend and resume routines.
sdhci_init()no longer enables card-detection irqs. Instead, two new functions implemented:sdhci_enable_card_detection()andsdhci_disable_card_detection().New
sdhci_reinit()call implemented to behave the same way as the oldsdhci_init().Also, this patch implements and uses few new helpers to manage IRQs in a more conveinient way, that is:
-
sdhci_clear_set_irqs()
-sdhci_unmask_irqs()
-sdhci_mask_irqs()
-SDHCI_INT_ALL_MASKconstant
Quoted 5 lines
sdhci_enable_sdio_irq()converted to these new helpers, plus the helpers will be used by the subsequent patches.Signed-off-by Anton Vorontsov <[email protected]>---
That's a lot of indirection, but fair enough. :)
drivers/mmc/host/sdhci.c int sdhci_add_host(struct sdhci_host *host) · line 1839
Quoted 9 lines
drivers/mmc/host/sdhci.c +2
-0@@ -1792,6 +1832,8 @@ int sdhci_add_host(struct sdhci_host *host)mmc_add_host (mmc); +sdhci_enable_card_detection (host); + printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n", mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), (host->flags & SDHCI_USE_ADMA)?"A":"",
There is a small race here, but I'm not sure it's worth dealing with.
drivers/mmc/host/sdhci.h line 131
Quoted 13 lines
drivers/mmc/host/sdhci.h +4
-0@@ -124,6 +124,10 @@ SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \ SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \ SDHCI_INT_DATA_END_BIT) +#define SDHCI_INT_ALL_MASK (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK | \ + SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE | \ + SDHCI_INT_CARD_INT | SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER | \ + SDHCI_INT_ACMD12ERR | SDHCI_INT_ADMA_ERROR)
In the context this is used, why not just use (unsigned)-1?
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 05/13] sdhci: Add support for card-detection polling
In reply to Anton VorontsovQuoted 12 lines · On Fri, 13 Feb 2009 17:47:18 +0300 Anton Vorontsov <[email protected]>…
drivers/mmc/host/sdhci.c +3
-1@@ -1110,13 +1113,18 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) host->mrq = mrq; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) + goto send; +if (!(sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ) || (host->flags &SDHCI_DEVICE_DEAD )) { host->mrq->cmd->error = -ENOMEDIUM ;tasklet_schedule (&host->finish_tasklet); - }else
drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) · line 1130
Quoted 10 lines
drivers/mmc/host/sdhci.c +5
-2-sdhci_send_command (host, mrq->cmd); - + goto out; + } +send: +sdhci_send_command (host, mrq->cmd); +out:mmiowb ();spin_unlock_irqrestore (&host->lock, flags); }
goto:s seem unnecessary here, and your patch is even incorrect as it ignores the SDHCI_DEVICE_DEAD flag. Just modify the if-clause and things will work.
Might want to add a comment also to make it more obvious what the if-clause does.
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 07/13] sdhci: Add support for hosts with strict 32 bit addressing
In reply to Anton VorontsovQuoted 9 lines · On Fri, 13 Feb 2009 17:47:22 +0300 Anton Vorontsov <[email protected]>…
SDHCI driver must take special care when working with "triggering" registers on hosts with strict 32 bit addressing.
In FSL eSDHC hosts all registers are 32 bit width, writing to the first half of any register will cause [undefined?] write the second half of the register. That is, 16 bit write to the
TRANSFER_MODEregister, makes hardware see a bogus write to the COMMAND register (these two registers are adjacent).
Quoted 6 lines
This patch adds
SDHCI_QUIRK_32BIT_REGISTERSquirk. When specified, the sdhci driver will try to "pack" all dangerous writes into single 32 bit write transaction.Signed-off-by Anton Vorontsov <[email protected]>---
What about the other places where we have 16 and 8 bit registers?
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 12/13] sdhci: Add quirk for controllers with max. block size up to 4096 bytes
In reply to Anton VorontsovQuoted 4 lines · On Fri, 13 Feb 2009 17:47:39 +0300 Anton Vorontsov <[email protected]>…
drivers/mmc/host/sdhci.c +0
-0@@ -831,7 +832,12 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)sdhci_set_transfer_irqs (host);/* We do not handle DMA boundaries, so set it to max (512 KiB) */
drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) · line 843
Quoted 10 lines
drivers/mmc/host/sdhci.c +6
-1-sdhci_writew (host,SDHCI_MAKE_BLKSZ (7 , data->blksz),SDHCI_BLOCK_SIZE ); +if (host->quirks &SDHCI_QUIRK_MAX_BLK_SZ_4096 ) + blksz = data->blksz; +else + blksz =SDHCI_MAKE_BLKSZ (7 , data->blksz); + +sdhci_writew (host, blksz,SDHCI_BLOCK_SIZE );sdhci_writew (host, data->blocks,SDHCI_BLOCK_COUNT ); }
Hmm.. I seem to have overlooked this part previously. I guess they've basically stripped out the DMA boundary stuff and used the bits for other things?
At this point I'm leaning more towards simply not supporting their extended block size. After all, is it ever used?
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 12/13] sdhci: Add quirk for controllers with max. block size up to 4096 bytes
Quoted 6 lines · Pierre Ossman
Quoted 3 lines · On Fri, 13 Feb 2009 17:47:39 +0300 Anton Vorontsov <[email protected]>…
drivers/mmc/host/sdhci.c +0
-0@@ -831,7 +832,12 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)sdhci_set_transfer_irqs (host);
Quoted 15 lines
drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) · line 843
Quoted 11 lines
drivers/mmc/host/sdhci.c +6
-1/* We do not handle DMA boundaries, so set it to max (512 KiB) */ -sdhci_writew (host,SDHCI_MAKE_BLKSZ (7 , data->blksz),SDHCI_BLOCK_SIZE ); +if (host->quirks &SDHCI_QUIRK_MAX_BLK_SZ_4096 ) + blksz = data->blksz; +else + blksz =SDHCI_MAKE_BLKSZ (7 , data->blksz); + +sdhci_writew (host, blksz,SDHCI_BLOCK_SIZE );sdhci_writew (host, data->blocks,SDHCI_BLOCK_COUNT ); }Hmm.. I seem to have overlooked this part previously. I guess they've basically stripped out the DMA boundary stuff and used the bits for other things?
Yes, the last two "DMA boundary" bits are reserved, and the first one is re-used for blksz of 4096 bytes.
Quoted 2 lines
At this point I'm leaning more towards simply not supporting their extended block size.
Eh. But well, OK. We can always persuade you later. :-)
I'll get rid of this particular patch, and put some BLOCK_SIZE magic into the writew accessor (to clean the DMA bits) instead.
Though, I'll prepare another patch to force blksz to 2048, since eSDHC specifies "3" in the blksz capability bitfield, and that causes SDHCI core to fall back to the 512 byte blocks.
Quoted 1 line
After all, is it ever used?
Not sure, maybe `dd bs=' can use it? A bit lazy to check this right now, but from the quick tests, enabling/disabling "blksz of 4096 bytes" doesn't cause any performance change. At least with the ordinary SD cards.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Re: [PATCH 07/13] sdhci: Add support for hosts with strict 32 bit addressing
In reply to Pierre OssmanQuoted 12 lines · Pierre Ossman
Quoted 9 lines · On Fri, 13 Feb 2009 17:47:22 +0300 Anton Vorontsov <[email protected]>…
SDHCI driver must take special care when working with "triggering" registers on hosts with strict 32 bit addressing.
In FSL eSDHC hosts all registers are 32 bit width, writing to the first half of any register will cause [undefined?] write the second half of the register. That is, 16 bit write to the
TRANSFER_MODEregister, makes hardware see a bogus write to the COMMAND register (these two registers are adjacent).
Quoted 8 lines
Quoted 6 lines
This patch adds
SDHCI_QUIRK_32BIT_REGISTERSquirk. When specified, the sdhci driver will try to "pack" all dangerous writes into single 32 bit write transaction.Signed-off-by Anton Vorontsov <[email protected]>---
What about the other places where we have 16 and 8 bit registers?
These are handled by the accessors:
+static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg) +{
+ int base = reg & ~0x3;
+ int shift = (reg & 0x3) * 8;
+
+ clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
^^ See, we're always issuing 32bit ops.
The point of this patch is to take care of "triggering" registers, i.e. those registers that are used trigger "send some data" command.
There is just one (from the eSDHC point of view) such register:
TRANSFER_MODE+COMMAND (which is a single 32 bit register in eSDHC, but two independant word-sized registers in standard SDHCI).
That register must be accessed with 32bit ops just _once_ per data transfer, not two 32bit writes (half of a register one time, and half of a register next time -- this won't work).
But I see the point of confusion... Instead of teaching "SDHCI core" to work with 32 bits hosts, we'd better handle this in the eSDHC part, in the accessors.
This is relatively trivial and should not cause much overhead (at least when using DMA), just a small state machine with the xfer mode register shadowed in software (plus, notice that this also handles BLOCK_SIZE, as I promised in another email):
drivers/mmc/host/sdhci-of.c +24 -3
@@ -30,6 +30,7 @@ struct sdhci_of_data {struct sdhci_of_host {unsigned int clock; +u16 xfer_mode_shadow; };/*
@@ -69,9 +70,31 @@ static void esdhc_writel(struct sdhci_host *host, u32 val, int reg)static void esdhc_writew (struct sdhci_host *host,u16 val,int reg) { +struct sdhci_of_host *of_host =sdhci_priv (host);int base = reg & ~0x3 ;int shift = (reg &0x2 ) *8 ; +switch (reg) { +case SDHCI_TRANSFER_MODE : +/* +* Postpone this write, we must do it together with a +* command write that is down below. +*/ + of_host->xfer_mode_shadow = val; +return ; +case SDHCI_COMMAND : +esdhc_writel (host, val <<16 | of_host->xfer_mode_shadow, +SDHCI_TRANSFER_MODE ); +return ; +case SDHCI_BLOCK_SIZE : +/* +* Two last DMA bits are reserved, and first one is used for +* non-standard blksz of 4096 bytes that we don't support +* yet. So clear the DMA boundary bits. +*/ + val &= ~SDHCI_MAKE_BLKSZ (0x7 ,0 ); +/* fall through */ + }clrsetbits_be32 (host->ioaddr + base,0xffff << shift, val << shift); }
@@ -137,13 +160,11 @@ static unsigned int esdhc_get_timeout_clock(struct sdhci_host *host) }static struct sdhci_of_data sdhci_esdhc = { - .quirks =SDHCI_QUIRK_32BIT_REGISTERS | -SDHCI_QUIRK_BROKEN_CARD_DETECTION | + .quirks =SDHCI_QUIRK_BROKEN_CARD_DETECTION |SDHCI_QUIRK_INVERTED_WRITE_PROTECT |SDHCI_QUIRK_NO_BUSY_IRQ |SDHCI_QUIRK_NONSTANDARD_CLOCK |SDHCI_QUIRK_PIO_NEEDS_DELAY | -SDHCI_QUIRK_MAX_BLK_SZ_4096 |SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET |SDHCI_QUIRK_NO_CARD_NO_RESET , .ops = {
Re: [PATCH 05/13] sdhci: Add support for card-detection polling
In reply to Pierre OssmanQuoted 20 lines · Pierre Ossman
Quoted 17 lines · On Fri, 13 Feb 2009 17:47:18 +0300 Anton Vorontsov <[email protected]>…
(quoted diff) +6
-3@@ -1110,13 +1113,18 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) host->mrq = mrq; + if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) + goto send; + if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT) || (host->flags & SDHCI_DEVICE_DEAD)) { host->mrq->cmd->error = -ENOMEDIUM; tasklet_schedule(&host->finish_tasklet); - } else - sdhci_send_command(host, mrq->cmd); - + goto out; + } +send:
Quoted 8 lines
Review static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) · line 1130
Quoted 5 lines
(quoted diff) +2
-0+ sdhci_send_command(host, mrq->cmd); +out: mmiowb(); spin_unlock_irqrestore(&host->lock, flags); }goto:s seem unnecessary here, and your patch is even incorrect as it ignores the
SDHCI_DEVICE_DEADflag.
Oops.
Quoted 2 lines
Just modify the if-clause and
things will work.
That would look horrid...
if ((!(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
SDHCI_CARD_PRESENT)) ||
(host->flags & SDHCI_DEVICE_DEAD)) {Quoted 2 lines
Might want to add a comment also to make it more obvious what the if-clause does.
Let's try to avoid the if-clause above? How about this:
drivers/mmc/host/sdhci.c +15 -2
@@ -167,6 +167,9 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) {u32 irqs =SDHCI_INT_CARD_REMOVE |SDHCI_INT_CARD_INSERT ; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) +return ; +if (enable)sdhci_unmask_irqs (host, irqs);else
@@ -1096,6 +1099,7 @@ out:static void sdhci_request (struct mmc_host *mmc,struct mmc_request *mrq) {struct sdhci_host *host; +bool present;unsigned long flags; host =mmc_priv (mmc);
@@ -1110,8 +1114,14 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) host->mrq = mrq; -if (!(sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ) - || (host->flags &SDHCI_DEVICE_DEAD )) { +/* If polling, assume that the card is always present. */ +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) + present = true; +else + present =sdhci_readl (host,SDHCI_PRESENT_STATE ) & +SDHCI_CARD_PRESENT ; + +if (!present || host->flags &SDHCI_DEVICE_DEAD ) { host->mrq->cmd->error = -ENOMEDIUM ;tasklet_schedule (&host->finish_tasklet); }else
@@ -1745,6 +1755,9 @@ int sdhci_add_host(struct sdhci_host *host)if (caps &SDHCI_CAN_DO_HISPD ) mmc->caps |=MMC_CAP_SD_HIGHSPEED ; +if (host->quirks &SDHCI_QUIRK_BROKEN_CARD_DETECTION ) + mmc->caps |=MMC_CAP_NEEDS_POLL ; + mmc->ocr_avail =0 ;if (caps &SDHCI_CAN_VDD_330 ) mmc->ocr_avail |=MMC_VDD_32_33 |MMC_VDD_33_34 ;
drivers/mmc/host/sdhci.h +2 -0
@@ -212,6 +212,8 @@ struct sdhci_host {#define SDHCI_QUIRK_BROKEN_SMALL_PIO (1<<13)/* Controller does not provide transfer-complete interrupt when not busy */ #define SDHCI_QUIRK_NO_BUSY_IRQ (1<<14) +/* Controller has unreliable card detection */ +#define SDHCI_QUIRK_BROKEN_CARD_DETECTION (1<<15)int irq;/* Device IRQ */ void __iomem * ioaddr;/* Mapped address */
Re: [PATCH 05/13] sdhci: Add support for card-detection polling
Quoted 11 lines · On Wed, 4 Mar 2009 20:49:17 +0300 Anton Vorontsov <[email protected]>…
Quoted 2 lines · Pierre Ossman
Just modify the if-clause and
things will work.That would look horrid...
if ((!(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) || (host->flags & SDHCI_DEVICE_DEAD)) {
There are worse ones in that code, but I see your point. :)
Quoted 5 lines
Quoted 2 lines
Might want to add a comment also to make it more obvious what the if-clause does.
Let's try to avoid the if-clause above? How about this:
Looks ok.
drivers/mmc/host/sdhci.c out: · line 1105
Quoted 8 lines
drivers/mmc/host/sdhci.c +1
-0@@ -1096,6 +1099,7 @@ out:static void sdhci_request (struct mmc_host *mmc,struct mmc_request *mrq) {struct sdhci_host *host; +bool present;unsigned long flags; host =mmc_priv (mmc);
Can we use bool in the kernel?
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 07/13] sdhci: Add support for hosts with strict 32 bit addressing
In reply to Anton VorontsovQuoted 9 lines · On Wed, 4 Mar 2009 20:48:45 +0300 Anton Vorontsov <[email protected]>…
But I see the point of confusion... Instead of teaching "SDHCI core" to work with 32 bits hosts, we'd better handle this in the eSDHC part, in the accessors.
This is relatively trivial and should not cause much overhead (at least when using DMA), just a small state machine with the xfer mode register shadowed in software (plus, notice that this also handles
BLOCK_SIZE, as I promised in another email):
Me like. Keeps my life a lot saner. :)
Just be aware that there is a remote risk of breakage as people hacking on sdhci-core won't be aware of esdhc's, let's call it unique, behaviour. Some testing now and then on your part would be prudent. :)
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 12/13] sdhci: Add quirk for controllers with max. block size up to 4096 bytes
In reply to Anton VorontsovQuoted 8 lines · On Wed, 4 Mar 2009 20:47:44 +0300 Anton Vorontsov <[email protected]>…
I'll get rid of this particular patch, and put some
BLOCK_SIZEmagic into the writew accessor (to clean the DMA bits) instead.Though, I'll prepare another patch to force blksz to 2048, since eSDHC specifies "3" in the blksz capability bitfield, and that causes SDHCI core to fall back to the 512 byte blocks.
Ok.
Quoted 7 lines
Quoted 1 line
After all, is it ever used?
Not sure, maybe `dd bs=' can use it? A bit lazy to check this right now, but from the quick tests, enabling/disabling "blksz of 4096 bytes" doesn't cause any performance change. At least with the ordinary SD cards.
Memory cards will not use this (at least not with the current standards), as the block layer thinks in 512 byte blocks. Also, the sector size propagates to user space in a way that causes filesystems to behave differently, making cards incompatible with all other operating systems (i.e. if we don't use 512 byte blocks).
So the only scenario where this might be used is SDIO, and I'm not sure such big blocks are a win there either because of the overhead of changing block size.
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.
Re: [PATCH 05/13] sdhci: Add support for card-detection polling
In reply to Pierre OssmanQuoted 32 lines · Pierre Ossman
Quoted 11 lines · On Wed, 4 Mar 2009 20:49:17 +0300 Anton Vorontsov <[email protected]>…
Quoted 2 lines · Pierre Ossman
Just modify the if-clause and
things will work.That would look horrid...
if ((!(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) || (host->flags & SDHCI_DEVICE_DEAD)) {There are worse ones in that code, but I see your point. :)
Quoted 5 lines
Quoted 2 lines
Might want to add a comment also to make it more obvious what the if-clause does.
Let's try to avoid the if-clause above? How about this:
Looks ok.
Quoted 7 lines
drivers/mmc/host/sdhci.c +1
-0@@ -1096,6 +1099,7 @@ out:static void sdhci_request (struct mmc_host *mmc,struct mmc_request *mrq) {struct sdhci_host *host; +bool present;unsigned long flags;
Quoted 3 lines
drivers/mmc/host/sdhci.c out: · line 1105
Quoted 1 line
drivers/mmc/host/sdhci.c +0
-0host =mmc_priv (mmc);Can we use bool in the kernel?
Sure, it's widely used in the kernel, even in such places as mm/ or kernel/.
Thanks for the review!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2