Skip to contentSkip to conversation

FSL eSDHC support: second call for comments

RFC PATCH In review Anton Vorontsov 2 participants 25 messages Feb 6, 2009 – Mar 8, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover FSL eSDHC support: second call for comments

Hi all,

There were only a few comments on the previous version. So, here is the second call for comments.

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"

That's all, for now.

Pierre, what do you think about memory accessors, what is your preference regarding mem ops? Some options were discussed here:
http://lkml.org/lkml/2009/1/22/261

Thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#1 lore raw

PATCH 1/11 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
index 6b2d1f9..0a1f5c5 100644
@@ -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
index 3efba23..2d08dd4 100644
@@ -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
#2 lore raw

PATCH 2/11 sdhci: Add support for bus-specific IO memory accessors

In reply to Anton Vorontsov

Currently 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     |  205 +++++++++++++++++++++++++-----------------
 drivers/mmc/host/sdhci.h     |   48 ++++++++++
 3 files changed, 174 insertions(+), 83 deletions(-)
drivers/mmc/host/sdhci-pci.c +2 -2
index f07255c..a3ced4d 100644
@@ -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 +124 -81

492 lines not on this page · raw message

drivers/mmc/host/sdhci.h +48 -0

68 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#3 lore raw

Re: [PATCH 02/11] sdhci: Add support for bus-specific IO memory accessors

Quoted 6 lines · On Fri, 6 Feb 2009 21:06:45 +0300 Anton Vorontsov <[email protected]>…

Currently 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.

Quoted 7 lines

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)).

---

I was hoping we wouldn't have to do a lot of magic in the accessors since the spec is rather clear on the register interface. :/

Let's see if I've understood this correctly.

1. The CPU is big-endian but the register are little-endian (as the spec requires). I was under the impression that the read*/write* accessor handled any endian conversion between the bus and the cpu? How do e.g. PCI work on Sparc?

2. Register access must be done 32 bits at a time. Now this is just broken and might cause big problems as some registers cannot just be read and written back to. OTOH you refer to readw() in your example, not readl(). What's the deal here?

drivers/mmc/host/sdhci.h struct sdhci_host { · line 296

Quoted 4 lines
drivers/mmc/host/sdhci.h +4 -0
+static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
+{
+	host->writel(host, val, reg);
+}

Having to override these are worst case scenario as far as I'm concerned, so I'd prefer something like:

if (!host->ops->writel)

	writel(host->ioaddr + reg, val);
else
	host->ops->writel(host, val, reg);

and maybe even a likely() up there.

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.
#4 lore raw

Re: [PATCH 02/11] sdhci: Add support for bus-specific IO memory accessors

Quoted 16 lines · Pierre Ossman
Quoted 6 lines · On Fri, 6 Feb 2009 21:06:45 +0300 Anton Vorontsov <[email protected]>…

Currently 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.

Quoted 7 lines

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)).

---

Quoted 7 lines

I was hoping we wouldn't have to do a lot of magic in the accessors since the spec is rather clear on the register interface. :/

Let's see if I've understood this correctly.

1. The CPU is big-endian but the register are little-endian (as the spec requires).

No, on eSDHC the registers are big-endian, 32-bit width, with, for example, two 16-bit "logical" registers packed into it.

That is,

0x4 0x5 0x6 0x7

|~~~~~~~~:~~~~~~~~|
| BLKCNT : BLKSZ  |
|________:________|
 31              0

( The register looks wrong, right? BLKSZ should be at 0x4. But imagine
that you swapped bytes in this 32 bit register... then the registers and their byte addresses will look normal. )

So if we try to issue readw(SDHCI_BLOCK_SIZE), i.e. readw(0x4):

- We'll read BLKCNT, while we wanted BLKSZ. This is because the address bits should be translated before we try word or byte reads/writes.
- On powerpc read{l,w}() convert the read value from little-endian to big-endian byte order, which is wrong for our case (the register is big-endian already).

That means that we have to convert address, but we don't want to convert the result of read/write ops.

Quoted 3 lines

I was under the impression that the read*/write*
accessor handled any endian conversion between the bus and the cpu? How do e.g. PCI work on Sparc?

read{l,w} are guaranteed to return values in CPU byte order, so if CPU is in big-endian mode, then the PCI IO accessors should convert values. And just as on PowerPC, Sparc's read*() accessors swap bytes of a result:

static inline u32 __readl(const volatile void __iomem *addr)

{
        return flip_dword(*(__force volatile u32 *)addr);
}

#define readl(__addr) __readl(__addr)

Quoted 3 lines

2. Register access must be done 32 bits at a time. Now this is just broken and might cause big problems as some registers cannot just be read and written back to.

We must only take special care when working with "triggering" registers, and that's handled by the "sdhci: Add support for hosts with strict 32 bit addressing" patch.

Quoted 2 lines

OTOH you refer to readw() in your example,
not readl(). What's the deal here?

readw() was just an example (most complicated one).

Quoted 6 lines

drivers/mmc/host/sdhci.h struct sdhci_host { · line 296

Quoted 4 lines
drivers/mmc/host/sdhci.h +4 -0
+static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
+{
+	host->writel(host, val, reg);
+}

Having to override these are worst case scenario

Hm. It's not a worst case scenario, it's a normal scenario for eSDHC. Why should we treat eSDHC as a second-class citizen?

Quoted 7 lines

as far as I'm
concerned, so I'd prefer something like:

if (!host->ops->writel)

	writel(host->ioaddr + reg, val);
else
	host->ops->writel(host, val, reg);

Hm.

-- What I purpose:

$ size drivers/mmc/host/sdhci.o
   text    data     bss     dec     hex filename
  15173       8       4   15185    3b51 drivers/mmc/host/sdhci.o

And there is a minimum run-time overhead (dereference + branch).

+ no first/second-class citizen separation.

-- What you purpose (inlined):

$ size drivers/mmc/host/sdhci.o
   text    data     bss     dec     hex filename
  17853       8       4   17865    45c9 drivers/mmc/host/sdhci.o

Runtime overhead: dereference + dereference + compare + (maybe)branch + larger code.

-- What you purpose (uninlined):

$ size drivers/mmc/host/sdhci.o
   text    data     bss     dec     hex filename
  14692       8       4   14704    3970 drivers/mmc/host/sdhci.o

Better. But the runtime overhead: branch + dereference + dereference + compare + (maybe)branch.

Surely the overhead isn't measurable... but why we purposely make things worse?

Though, this is not something I'm going to argue about, I'll just do it the way you prefer. ;-) For an updated patch set I took the uninlined variant, hope this is OK.

Thanks for the review,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#5 lore raw

Re: [PATCH 02/11] sdhci: Add support for bus-specific IO memory accessors

Quoted 25 lines · On Fri, 13 Feb 2009 17:40:39 +0300 Anton Vorontsov <[email protected]>…

No, on eSDHC the registers are big-endian, 32-bit width, with, for example, two 16-bit "logical" registers packed into it.

That is,

0x4 0x5 0x6 0x7

|~~~~~~~~:~~~~~~~~|
| BLKCNT : BLKSZ  |
|________:________|
 31              0

( The register looks wrong, right? BLKSZ should be at 0x4. But imagine
that you swapped bytes in this 32 bit register... then the registers and their byte addresses will look normal. )

So if we try to issue readw(SDHCI_BLOCK_SIZE), i.e. readw(0x4):

- We'll read BLKCNT, while we wanted BLKSZ. This is because the address bits should be translated before we try word or byte reads/writes.
- On powerpc read{l,w}() convert the read value from little-endian to big-endian byte order, which is wrong for our case (the register is big-endian already).

Quoted 3 lines

That means that we have to convert address, but we don't want to convert the result of read/write ops.

*cries*

Now this is just incredibly horrible. Why the hell did they try to use the sdhci interface and then do stupid things like this?

Quoted 10 lines
Quoted 6 lines

drivers/mmc/host/sdhci.h struct sdhci_host { · line 296

Quoted 4 lines
drivers/mmc/host/sdhci.h +4 -0
+static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
+{
+	host->writel(host, val, reg);
+}

Having to override these are worst case scenario

Hm. It's not a worst case scenario, it's a normal scenario for eSDHC. Why should we treat eSDHC as a second-class citizen?

Because it's complete and utter crap. Freescale has completely ignored the basic register interface requirements of the SDHCI spec. Treating eSDHC as a second-class citizen is generous IMO.

Quoted 11 lines
Quoted 7 lines

as far as I'm
concerned, so I'd prefer something like:

if (!host->ops->writel)

	writel(host->ioaddr + reg, val);
else
	host->ops->writel(host, val, reg);

Surely the overhead isn't measurable... but why we purposely make things worse?

We can most likely do some micro-optimisation do make the compare part cheaper, but the point was to avoid a function call for all the properly implemented controllers out there. We could have a flag so that it only has to check host->flags, which will most likely be in the cache anyway.

Overhead for eSDHC is not a concern in my book, what is interesting is how much this change slows things down for other controllers.

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.
#6 lore raw

Re: [PATCH 02/11] sdhci: Add support for bus-specific IO memory accessors

Quoted 28 lines · Pierre Ossman
Quoted 25 lines · On Fri, 13 Feb 2009 17:40:39 +0300 Anton Vorontsov <[email protected]>…

No, on eSDHC the registers are big-endian, 32-bit width, with, for example, two 16-bit "logical" registers packed into it.

That is,

0x4 0x5 0x6 0x7

|~~~~~~~~:~~~~~~~~|
| BLKCNT : BLKSZ  |
|________:________|
 31              0

( The register looks wrong, right? BLKSZ should be at 0x4. But imagine
that you swapped bytes in this 32 bit register... then the registers and their byte addresses will look normal. )

So if we try to issue readw(SDHCI_BLOCK_SIZE), i.e. readw(0x4):

- We'll read BLKCNT, while we wanted BLKSZ. This is because the address bits should be translated before we try word or byte reads/writes.
- On powerpc read{l,w}() convert the read value from little-endian to big-endian byte order, which is wrong for our case (the register is big-endian already).

Quoted 5 lines
Quoted 3 lines

That means that we have to convert address, but we don't want to convert the result of read/write ops.

*cries*

:-)

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines

as far as I'm
concerned, so I'd prefer something like:

if (!host->ops->writel)

	writel(host->ioaddr + reg, val);
else
	host->ops->writel(host, val, reg);

Surely the overhead isn't measurable... but why we purposely make things worse?

Quoted 8 lines

We can most likely do some micro-optimisation do make the compare part cheaper, but the point was to avoid a function call for all the properly implemented controllers out there. We could have a flag so that it only has to check host->flags, which will most likely be in the cache anyway.

Overhead for eSDHC is not a concern in my book, what is interesting is how much this change slows things down for other controllers.

OK, I see. Will the patch down below make you a little bit more happy wrt normal controllers? Two #ifdefs, but then there is absolutely zero overhead for the fully compliant SDHCI controllers.

(So far it's just on top of this series, but I can incorporate it into the "sdhci: Add support for bus-specific IO memory accessors" patch, if you like).

drivers/mmc/host/Kconfig +8 -0
index 73b79e1..69bd124 100644
@@ -37,6 +37,13 @@ config MMC_SDHCI
 
 	  If unsure, say N.
 
+config MMC_SDHCI_IO_ACCESSORS
+	bool
+	depends on MMC_SDHCI
+	help
+	  This is silent Kconfig symbol that is selected by the drivers that
+	  need to overwrite SDHCI IO memory accessors.
+
 config MMC_SDHCI_PCI
 	tristate "SDHCI support on PCI bus"
 	depends on MMC_SDHCI && PCI
@@ -68,6 +75,7 @@ config MMC_RICOH_MMC
 config MMC_SDHCI_OF
 	tristate "SDHCI support on OpenFirmware platforms"
 	depends on MMC_SDHCI && PPC_OF
+	select MMC_SDHCI_IO_ACCESSORS
 	help
 	  This selects the OF support for Secure Digital Host Controller
 	  Interfaces. So far, only the Freescale eSDHC controller is known
drivers/mmc/host/sdhci.c +0 -54

60 lines not on this page · raw message

drivers/mmc/host/sdhci.h +85 -6

109 lines not on this page · raw message

#7 lore raw

Re: [PATCH 02/11] sdhci: Add support for bus-specific IO memory accessors

Quoted 8 lines · On Wed, 4 Mar 2009 20:46:58 +0300 Anton Vorontsov <[email protected]>…
Quoted 7 lines · Pierre Ossman

We can most likely do some micro-optimisation do make the compare part cheaper, but the point was to avoid a function call for all the properly implemented controllers out there. We could have a flag so that it only has to check host->flags, which will most likely be in the cache anyway.

Quoted 7 lines
Quoted 2 lines

Overhead for eSDHC is not a concern in my book, what is interesting is how much this change slows things down for other controllers.

OK, I see. Will the patch down below make you a little bit more happy wrt normal controllers? Two #ifdefs, but then there is absolutely zero overhead for the fully compliant SDHCI controllers.

I can't say this makes me happy either, but I think it's acceptable for now so that we can move forward. I'd like a common code path for this thing, but I think I'm going to have to put a bit more time into it myself than I currently have available.

Quoted 4 lines

(So far it's just on top of this series, but I can incorporate it into the "sdhci: Add support for bus-specific IO memory accessors" patch, if you like).

Please do. Have one patch add some code and another remove it in the same set is just silly. :)

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.
#8 lore raw

PATCH 3/11 sdhci: Add type checking for IO memory accessors

In reply to Anton Vorontsov

A new restricted integer type introduced: sdhci_reg_t.

Header file now specifies registers via sdhci_reg() inline function. Only one place (not counting sdhci_def_*() accessors) need to cast a register back to an offset, i.e. sdhci_finish_command().

Quoted 1 line

From now on sparse tool will warn about IO memory accessors misuses,

for exampple:

sdhci_writeb(host, SDHCI_TIMEOUT_CONTROL, count);

CHECK sdhci.c
sdhci.c:614:21: warning: incorrect type in argument 2 (different base types)
sdhci.c:614:21: expected unsigned char [unsigned] [usertype] val
sdhci.c:614:21: got restricted int
sdhci.c:614:44: warning: incorrect type in argument 3 (different base types)
sdhci.c:614:44: expected restricted int [usertype] reg
sdhci.c:614:44: got unsigned char [unsigned] [assigned] [usertype] count

---
 drivers/mmc/host/sdhci.c |   32 +++++++------
 drivers/mmc/host/sdhci.h |  113 ++++++++++++++++++++++++++-------------------
 2 files changed, 82 insertions(+), 63 deletions(-)
drivers/mmc/host/sdhci.c +17 -15
index 8557521..b7a79a0 100644
@@ -87,34 +87,34 @@ static void sdhci_dumpregs(struct sdhci_host *host)
  *                                                                           *
 \*****************************************************************************/
 
-static u32 sdhci_def_readl(struct sdhci_host *host, int reg)
+static u32 sdhci_def_readl(struct sdhci_host *host, sdhci_reg_t reg)
 {
-	return readl(host->ioaddr + reg);
+	return readl(host->ioaddr + sdhci_off(reg));
 }
 
-static u16 sdhci_def_readw(struct sdhci_host *host, int reg)
+static u16 sdhci_def_readw(struct sdhci_host *host, sdhci_reg_t reg)
 {
-	return readw(host->ioaddr + reg);
+	return readw(host->ioaddr + sdhci_off(reg));
 }
 
-static u8 sdhci_def_readb(struct sdhci_host *host, int reg)
+static u8 sdhci_def_readb(struct sdhci_host *host, sdhci_reg_t reg)
 {
-	return readb(host->ioaddr + reg);
+	return readb(host->ioaddr + sdhci_off(reg));
 }
 
-static void sdhci_def_writel(struct sdhci_host *host, u32 val, int reg)
+static void sdhci_def_writel(struct sdhci_host *host, u32 val, sdhci_reg_t reg)
 {
-	writel(val, host->ioaddr + reg);
+	writel(val, host->ioaddr + sdhci_off(reg));
 }
 
-static void sdhci_def_writew(struct sdhci_host *host, u16 val, int reg)
+static void sdhci_def_writew(struct sdhci_host *host, u16 val, sdhci_reg_t reg)
 {
-	writew(val, host->ioaddr + reg);
+	writew(val, host->ioaddr + sdhci_off(reg));
 }
 
-static void sdhci_def_writeb(struct sdhci_host *host, u8 val, int reg)
+static void sdhci_def_writeb(struct sdhci_host *host, u8 val, sdhci_reg_t reg)
 {
-	writeb(val, host->ioaddr + reg);
+	writeb(val, host->ioaddr + sdhci_off(reg));
 }
 
 static void sdhci_reset(struct sdhci_host *host, u8 mask)
@@ -891,12 +891,14 @@ static void sdhci_finish_command(struct sdhci_host *host)
 		if (host->cmd->flags & MMC_RSP_136) {
 			/* CRC is stripped so we need to do some shifting. */
 			for (i = 0;i < 4;i++) {
+				int resp = sdhci_off(SDHCI_RESPONSE);
+
 				host->cmd->resp[i] = sdhci_readl(host,
-					SDHCI_RESPONSE + (3-i)*4) << 8;
+					sdhci_reg(resp + (3-i)*4)) << 8;
 				if (i != 3)
 					host->cmd->resp[i] |=
-						sdhci_readb(host,
-						SDHCI_RESPONSE + (3-i)*4-1);
+						sdhci_readb(host, sdhci_reg(
+							resp + (3-i)*4-1));
 			}
 		} else {
 			host->cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE);
drivers/mmc/host/sdhci.h +65 -48

231 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#9 lore raw

Re: [PATCH 03/11] sdhci: Add type checking for IO memory accessors

Quoted 19 lines · On Fri, 6 Feb 2009 21:06:48 +0300 Anton Vorontsov <[email protected]>…

A new restricted integer type introduced: sdhci_reg_t.

Header file now specifies registers via sdhci_reg() inline function. Only one place (not counting sdhci_def_*() accessors) need to cast a register back to an offset, i.e. sdhci_finish_command().

From now on sparse tool will warn about IO memory accessors misuses, for exampple:

sdhci_writeb(host, SDHCI_TIMEOUT_CONTROL, count);

CHECK sdhci.c
sdhci.c:614:21: warning: incorrect type in argument 2 (different base types)
sdhci.c:614:21: expected unsigned char [unsigned] [usertype] val
sdhci.c:614:21: got restricted int
sdhci.c:614:44: warning: incorrect type in argument 3 (different base types)
sdhci.c:614:44: expected restricted int [usertype] reg
sdhci.c:614:44: got unsigned char [unsigned] [assigned] [usertype] count

Quoted 2 lines

---

Is this really a problem? It's a lot of noise in the code and I can't really see this as a major issue, or even a minor one. :)

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.
#10 lore raw

PATCH 4/11 sdhci: Add support for card-detection polling

In reply to Anton Vorontsov

This 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 |    6 ++++++
 drivers/mmc/host/sdhci.h |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +6 -0
index b7a79a0..45c5f1f 100644
@@ -162,6 +162,9 @@ static void sdhci_init(struct sdhci_host *host)
 		SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
 		SDHCI_INT_ADMA_ERROR;
 
+	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
+		intmask &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT);
+
 	sdhci_writel(host, intmask, SDHCI_INT_ENABLE);
 	sdhci_writel(host, intmask, SDHCI_SIGNAL_ENABLE);
 }
@@ -1684,6 +1687,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
index 5a5c119..03f035e 100644
@@ -227,6 +227,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
#11 lore raw

Re: [PATCH 04/11] sdhci: Add support for card-detection polling

Quoted 4 lines · On Fri, 6 Feb 2009 21:06:50 +0300 Anton Vorontsov <[email protected]>…

This 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.

Quoted 8 lines

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.

---

I guess you need to fix the check at the start of the request function as well.

drivers/mmc/host/sdhci.c static void sdhci_init(struct sdhci_host *host) · line 167

Quoted 11 lines
drivers/mmc/host/sdhci.c +3 -0
index b7a79a0..45c5f1f 100644
@@ -162,6 +162,9 @@ static void sdhci_init(struct sdhci_host *host)
 		SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
 		SDHCI_INT_ADMA_ERROR;
 
+	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
+		intmask &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT);
+

A matter of taste perhaps, but I think it would make more sense to not add them in the first place than to add and then remove them.

Card detection interrupts should be handled separately anyway as they should not be enabled before mmc_add_host() returns and should be disabled before calling mmc_remove_host(). Patch welcome. ;)

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.
#12 lore raw

PATCH 5/11 sdhci: Add support for hosts reporting inverted write-protect state

In reply to Anton Vorontsov

This 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
index 45c5f1f..85f3780 100644
@@ -1121,6 +1121,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
index 03f035e..fd151a1 100644
@@ -229,6 +229,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
#13 lore raw

PATCH 6/11 sdhci: Add support for hosts with strict 32 bit addressing

In reply to Anton Vorontsov

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_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
index 85f3780..9b43588 100644
@@ -747,13 +747,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);
 
@@ -765,7 +765,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)
@@ -817,6 +817,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;
 
@@ -855,7 +856,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",
@@ -881,7 +882,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
index fd151a1..c4edd52 100644
@@ -58,6 +58,8 @@ static inline int sdhci_off(sdhci_reg_t reg)
 #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		sdhci_reg(0x10)
 
@@ -231,6 +233,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
#14 lore raw

PATCH 7/11 sdhci: Add quirk to suppress PIO interrupts during DMA transfers

In reply to Anton Vorontsov

Some hosts (that is, FSL eSDHC) throw PIO interrupts during DMA transfers, this causes tons of unneeded interrupts, and thus highly degraded speed.

This patch adds SDHCI_QUIRK_PIO_IRQS_DURING_DMA quirk. When specified, the sdhci driver will disable PIO interrupts during DMA transfers.

---
 drivers/mmc/host/sdhci.c |   32 ++++++++++++++++++++++++++++++++
 drivers/mmc/host/sdhci.h |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +32 -0
index 9b43588..ede3790 100644
@@ -167,6 +167,8 @@ static void sdhci_init(struct sdhci_host *host)
 
 	sdhci_writel(host, intmask, SDHCI_INT_ENABLE);
 	sdhci_writel(host, intmask, SDHCI_SIGNAL_ENABLE);
+
+	host->flags &= ~SDHCI_PIO_DISABLED;
 }
 
 static void sdhci_activate_led(struct sdhci_host *host)
@@ -594,6 +596,33 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
 	return count;
 }
 
+static void sdhci_set_pio_irqs(struct sdhci_host *host, bool state)
+{
+	bool current_state = !(host->flags & SDHCI_PIO_DISABLED);
+	u32 ier;
+
+	/*
+	 * We only care about PIO IRQs if the host issues PIO IRQs during
+	 * DMA transfers. Otherwise we can keep the irqs always enabled.
+	 */
+	if (!(host->quirks & SDHCI_QUIRK_PIO_IRQS_DURING_DMA))
+		return;
+
+	if (current_state == state)
+		return;
+
+	ier = sdhci_readl(host, SDHCI_INT_ENABLE);
+	if (state) {
+		ier |= SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
+		host->flags &= ~SDHCI_PIO_DISABLED;
+	} else {
+		ier &= ~(SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL);
+		host->flags |= SDHCI_PIO_DISABLED;
+	}
+	sdhci_writel(host, ier, SDHCI_INT_ENABLE);
+	sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
+}
+
 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
 {
 	u8 count;
@@ -740,6 +769,9 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
 		sg_miter_start(&host->sg_miter,
 			data->sg, data->sg_len, SG_MITER_ATOMIC);
 		host->blocks = data->blocks;
+		sdhci_set_pio_irqs(host, true);
+	} else {
+		sdhci_set_pio_irqs(host, false);
 	}
 
 	/* We do not handle DMA boundaries, so set it to max (512 KiB) */
drivers/mmc/host/sdhci.h +3 -0
index c4edd52..2e8dfd1 100644
@@ -235,6 +235,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 issues PIO interrupts during DMA transfers */
+#define SDHCI_QUIRK_PIO_IRQS_DURING_DMA			(1<<19)
 
 	int			irq;		/* Device IRQ */
 	void __iomem *		ioaddr;		/* Mapped address */
@@ -256,6 +258,7 @@ struct sdhci_host {
 #define SDHCI_USE_ADMA		(1<<1)		/* Host is ADMA capable */
 #define SDHCI_REQ_USE_DMA	(1<<2)		/* Use DMA for this req. */
 #define SDHCI_DEVICE_DEAD	(1<<3)		/* Device unresponsive */
+#define SDHCI_PIO_DISABLED	(1<<4)		/* PIO IRQs disabled */
 
 	unsigned int		version;	/* SDHCI spec. version */
 
Signature · 1 line
1.5.6.5
#15 lore raw

Re: [PATCH 07/11] sdhci: Add quirk to suppress PIO interrupts during DMA transfers

Quoted 9 lines · On Fri, 6 Feb 2009 21:06:55 +0300 Anton Vorontsov <[email protected]>…

Some hosts (that is, FSL eSDHC) throw PIO interrupts during DMA transfers, this causes tons of unneeded interrupts, and thus highly degraded speed.

This patch adds SDHCI_QUIRK_PIO_IRQS_DURING_DMA quirk. When specified, the sdhci driver will disable PIO interrupts during DMA transfers.

---

It's probably better to change the interrupt handling to only enable relevant interrupts instead of having everything on constantly. Too many quirks just makes the driver difficult to understand.

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.
#16 lore raw

PATCH 8/11 sdhci: Add support for hosts that don't specify clocks in the cap. register

In reply to Anton Vorontsov

FSL eSDHC hosts don't provide clocks bits in the capabilities register, instead we're getting clocks values from the device tree.

There is somewhat similar change[1] from Ben Dooks, the change adds callbacks for getting the clocks. But for eSDHC the callbacks are superfluous, since the clocks are static.

[1] http://lkml.org/lkml/2008/12/2/157

---
 drivers/mmc/host/sdhci.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)
drivers/mmc/host/sdhci.c +14 -15
index ede3790..0293368 100644
@@ -1703,24 +1703,23 @@ int sdhci_add_host(struct sdhci_host *host)
 		mmc_dev(host->mmc)->dma_mask = &host->dma_mask;
 	}
 
-	host->max_clk =
-		(caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
-	if (host->max_clk == 0) {
-		printk(KERN_ERR "%s: Hardware doesn't specify base clock "
-			"frequency.\n", mmc_hostname(mmc));
-		return -ENODEV;
+	if (!host->max_clk) {
+		host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) >>
+						SDHCI_CLOCK_BASE_SHIFT;
+		if (host->max_clk == 0) {
+			printk(KERN_ERR "%s: Hardware doesn't specify base "
+				"clock frequency.\n", mmc_hostname(mmc));
+			return -ENODEV;
+		}
+		host->max_clk *= 1000000;
 	}
-	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->timeout_clk) {
+		host->timeout_clk = (caps & SDHCI_TIMEOUT_CLK_MASK) >>
+						SDHCI_TIMEOUT_CLK_SHIFT;
+		if (caps & SDHCI_TIMEOUT_CLK_UNIT)
+			host->timeout_clk *= 1000;
 	}
-	if (caps & SDHCI_TIMEOUT_CLK_UNIT)
-		host->timeout_clk *= 1000;
 
 	/*
 	 * Set host parameters.
Signature · 1 line
1.5.6.5
#17 lore raw

Re: [PATCH 08/11] sdhci: Add support for hosts that don't specify clocks in the cap. register

Quoted 11 lines · On Fri, 6 Feb 2009 21:06:57 +0300 Anton Vorontsov <[email protected]>…

FSL eSDHC hosts don't provide clocks bits in the capabilities register, instead we're getting clocks values from the device tree.

There is somewhat similar change[1] from Ben Dooks, the change adds callbacks for getting the clocks. But for eSDHC the callbacks are superfluous, since the clocks are static.

[1] http://lkml.org/lkml/2008/12/2/157

---

As I told Ben, I prefer if we stick to the standard as much as possible. So no external info unless the register is set to zero.

And since we know the Samsung chip needs callbacks, we might as well add them here. It's not like this is a performance critical path.

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.
#18 lore raw

PATCH 9/11 sdhci: Add set_clock callback

In reply to Anton Vorontsov

FSL 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 |    5 +++++
 drivers/mmc/host/sdhci.h |    2 ++
 2 files changed, 7 insertions(+), 0 deletions(-)
drivers/mmc/host/sdhci.c +5 -0
index 0293368..3c1f1d5 100644
@@ -969,6 +969,11 @@ 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);
+		return;
+	}
+
 	sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
 
 	if (clock == 0)
drivers/mmc/host/sdhci.h +2 -0
index 2e8dfd1..497276b 100644
@@ -312,6 +312,8 @@ struct sdhci_ops {
 	void	(*writew)(struct sdhci_host *host, u16 val, sdhci_reg_t reg);
 	void	(*writeb)(struct sdhci_host *host, u8 val, sdhci_reg_t reg);
 
+	void	(*set_clock)(struct sdhci_host *host, unsigned int clock);
+
 	int	(*enable_dma)(struct sdhci_host *host);
 };
 
Signature · 1 line
1.5.6.5
#19 lore raw

Re: [PATCH 09/11] sdhci: Add set_clock callback

Quoted 4 lines · On Fri, 6 Feb 2009 21:06:59 +0300 Anton Vorontsov <[email protected]>…

FSL eSDHC hosts have incompatible register map to manage the SDCLK. This patch adds set_clock callback so that drivers could overwrite set_clock behaviour.

Quoted 8 lines

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

---

A set_clock() callback is reasonable as there might be a clock source that needs to be set up, but completely overriding the normal routine (i.e. the "return") should be quirked IMO.

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.
#20 lore raw

PATCH 10/11 sdhci: Add quirk for Freescale eSDHC controllers

In reply to Anton Vorontsov

This patch adds SDHCI_QUIRK_FSL quirk. The quirk is used to instruct the sdhci driver about various FSL eSDHC host incompatibilities:

1) FSL 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.

(Should we implement a dedicated quirk for this? I.e.

    SDHCI_QUIRK_MAX_BLK_SZ_4096?)

2) sdhci_init() is needed after error conditions.

(Can we safely do this for all controllers?)

3) Small 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 changes before and after the delay. Though, more investigation on this is in my todo list.

---
 drivers/mmc/host/sdhci.c |   36 ++++++++++++++++++++++++++++++------
 drivers/mmc/host/sdhci.h |    3 +++
 2 files changed, 33 insertions(+), 6 deletions(-)
drivers/mmc/host/sdhci.c +30 -6
index 3c1f1d5..87ba0ed 100644
@@ -328,6 +328,10 @@ static void sdhci_transfer_pio(struct sdhci_host *host)
 		mask = ~0;
 
 	while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
+		/* FIXME */
+		if (host->quirks & SDHCI_QUIRK_FSL)
+			udelay(100);
+
 		if (host->data->flags & MMC_DATA_READ)
 			sdhci_read_block_pio(host);
 		else
@@ -625,6 +629,7 @@ static void sdhci_set_pio_irqs(struct sdhci_host *host, bool state)
 
 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
 {
+	u16 blksz;
 	u8 count;
 	u8 ctrl;
 	int ret;
@@ -775,7 +780,12 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
 	}
 
 	/* 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_FSL)
+		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);
 }
 
@@ -1280,6 +1290,9 @@ static void sdhci_tasklet_finish(unsigned long param)
 		   controllers do not like that. */
 		sdhci_reset(host, SDHCI_RESET_CMD);
 		sdhci_reset(host, SDHCI_RESET_DATA);
+		/* FSL controllers need this. */
+		if (host->quirks & SDHCI_QUIRK_FSL)
+			sdhci_init(host);
 	}
 
 	host->mrq = NULL;
@@ -1789,13 +1802,24 @@ 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) {
+	if (host->quirks & SDHCI_QUIRK_FSL) {
+		mmc->max_blk_size = (caps & SDHCI_FSL_MAX_BLOCK_MASK) >>
+				SDHCI_MAX_BLOCK_SHIFT;
+		if (mmc->max_blk_size >= 4)
+			mmc->max_blk_size = ~0;
+	} else {
+		mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
+				SDHCI_MAX_BLOCK_SHIFT;
+		if (mmc->max_blk_size >= 3)
+			mmc->max_blk_size = ~0;
+	}
+
+	if (mmc->max_blk_size == ~0) {
 		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;
+		mmc->max_blk_size = 0;
+	}
+	mmc->max_blk_size = 512 << mmc->max_blk_size;
 
 	/*
 	 * Maximum block count.
drivers/mmc/host/sdhci.h +3 -0
index 497276b..cb575f3 100644
@@ -152,6 +152,7 @@ static inline int sdhci_off(sdhci_reg_t reg)
 #define  SDHCI_CLOCK_BASE_MASK	0x00003F00
 #define  SDHCI_CLOCK_BASE_SHIFT	8
 #define  SDHCI_MAX_BLOCK_MASK	0x00030000
+#define  SDHCI_FSL_MAX_BLOCK_MASK 0x00070000
 #define  SDHCI_MAX_BLOCK_SHIFT  16
 #define  SDHCI_CAN_DO_ADMA2	0x00080000
 #define  SDHCI_CAN_DO_ADMA1	0x00100000
@@ -237,6 +238,8 @@ struct sdhci_host {
 #define SDHCI_QUIRK_32BIT_REGISTERS			(1<<18)
 /* Controller issues PIO interrupts during DMA transfers */
 #define SDHCI_QUIRK_PIO_IRQS_DURING_DMA			(1<<19)
+/* Controller is Freescale eSDHC */
+#define SDHCI_QUIRK_FSL					(1<<20)
 
 	int			irq;		/* Device IRQ */
 	void __iomem *		ioaddr;		/* Mapped address */
Signature · 1 line
1.5.6.5
#21 lore raw

Re: [PATCH 10/11] sdhci: Add quirk for Freescale eSDHC controllers

Quoted 3 lines · On Fri, 6 Feb 2009 21:07:01 +0300 Anton Vorontsov <[email protected]>…

This patch adds SDHCI_QUIRK_FSL quirk. The quirk is used to instruct the sdhci driver about various FSL eSDHC host incompatibilities:

No device quirks please. They should be for specific bugs, not lumping things together like this. Otherwise we'll soon have an unmanageable mess.

Quoted 7 lines

1) FSL 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.

(Should we implement a dedicated quirk for this? I.e.

    SDHCI_QUIRK_MAX_BLK_SZ_4096?)

Yes please. It would have to mean "always support 4096" though, not "turn reserved bit 18 into a block length bit".

Quoted 4 lines

2) sdhci_init() is needed after error conditions.

(Can we safely do this for all controllers?)

Please investigate which part of sdhci_init() is needed. How does it break without this?

Quoted 6 lines

3) Small 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 changes before and after the delay. Though, more investigation on this is in my todo list.

Please try to investigate more, but if you cannot improve it further then a specific quirk can be added.

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.
#22 lore raw

Re: [PATCH 10/11] sdhci: Add quirk for Freescale eSDHC controllers

Quoted 10 lines · Pierre Ossman
Quoted 3 lines · On Fri, 6 Feb 2009 21:07:01 +0300 Anton Vorontsov <[email protected]>…

This patch adds SDHCI_QUIRK_FSL quirk. The quirk is used to instruct the sdhci driver about various FSL eSDHC host incompatibilities:

No device quirks please. They should be for specific bugs, not lumping things together like this. Otherwise we'll soon have an unmanageable mess.

OK.

Quoted 10 lines
Quoted 7 lines

1) FSL 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.

(Should we implement a dedicated quirk for this? I.e.

    SDHCI_QUIRK_MAX_BLK_SZ_4096?)

Yes please. It would have to mean "always support 4096" though, not "turn reserved bit 18 into a block length bit".

OK.

Quoted 7 lines
Quoted 4 lines

2) sdhci_init() is needed after error conditions.

(Can we safely do this for all controllers?)

Please investigate which part of sdhci_init() is needed. How does it break without this?

After reset eSDHC lose signal/interrupt enable states:

Before reset:

sdhci: ============== REGISTER DUMP ==============
sdhci: Sys addr: 0x00000008 | Version: 0x00000000
sdhci: Blk size: 0x00000008 | Blk cnt: 0x00000000
sdhci: Argument: 0x000001aa | Trn mode: 0x00000000
sdhci: Present: 0xff850000 | Host ctl: 0x00000021
sdhci: Power: 0x00000000 | Blk gap: 0x00000000
sdhci: Wake-up: 0x00000000 | Clock: 0x00001077
sdhci: Timeout: 0x00000000 | Int stat: 0x00000000
sdhci: Int enab: 0x007f0003 | Sig enab: 0x007f0003
sdhci: AC12 err: 0x00000000 | Slot int: 0x00000001
sdhci: Caps: 0x01e30000 | Max curr: 0x00000000
sdhci: ===========================================

after sdhci_reset(host, SDHCI_RESET_CMD):

sdhci: ============== REGISTER DUMP ==============
sdhci: Sys addr: 0x00000008 | Version: 0x00000000
sdhci: Blk size: 0x00000008 | Blk cnt: 0x00000000
sdhci: Argument: 0x00000000 | Trn mode: 0x00000000
sdhci: Present: 0xff850000 | Host ctl: 0x00000021
sdhci: Power: 0x00000000 | Blk gap: 0x00000000
sdhci: Wake-up: 0x00000000 | Clock: 0x00001077
sdhci: Timeout: 0x00000000 | Int stat: 0x00000000
sdhci: Int enab: 0x017f0003 | Sig enab: 0x00700002
sdhci: AC12 err: 0x00000000 | Slot int: 0x00000001
sdhci: Caps: 0x01e30000 | Max curr: 0x00000000
sdhci: ===========================================

After sdhci_reset(host, SDHCI_RESET_DATA):

sdhci: ============== REGISTER DUMP ==============
sdhci: Sys addr: 0x00000008 | Version: 0x00000000
sdhci: Blk size: 0x00000008 | Blk cnt: 0x00000000
sdhci: Argument: 0x00000000 | Trn mode: 0x00000000
sdhci: Present: 0xff850000 | Host ctl: 0x00000021
sdhci: Power: 0x00000000 | Blk gap: 0x00000000
sdhci: Wake-up: 0x00000000 | Clock: 0x00001077
sdhci: Timeout: 0x00000000 | Int stat: 0x00000000
sdhci: Int enab: 0x117f003f | Sig enab: 0x00000000
sdhci: AC12 err: 0x00000000 | Slot int: 0x00000001
sdhci: Caps: 0x01e30000 | Max curr: 0x00000000
sdhci: ===========================================

Quoted 9 lines
Quoted 6 lines

3) Small 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 changes before and after the delay. Though, more investigation on this is in my todo list.

Please try to investigate more, but if you cannot improve it further then a specific quirk can be added.

No luck so far... :-/

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#23 lore raw

PATCH 11/11 mmc: Add OpenFirmware bindings for SDHCI driver

In reply to Anton Vorontsov

This 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 |  264 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/host/sdhci-of.c
drivers/mmc/host/Kconfig +10 -0
index 99d4b28..73b79e1 100644
@@ -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
index dedec55..dd512d9 100644
@@ -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 +264 -0

264 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#24 lore raw
In reply to Anton Vorontsov
Quoted 5 lines · On Fri, 6 Feb 2009 21:05:20 +0300 Anton Vorontsov <[email protected]>…

Hi all,

There were only a few comments on the previous version. So, here is the second call for comments.

Yeah sorry, haven't really had time for looking over your patches properly. See my first comments to relevant patches now though.

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.