sdhci-of: avoid writing reserved bits into host control register
[safe/jmp/linux-2.6] / drivers / mmc / host / sdhci-of.c
index 09cc597..3439fc1 100644 (file)
@@ -48,6 +48,8 @@ struct sdhci_of_host {
 #define ESDHC_CLOCK_HCKEN      0x00000002
 #define ESDHC_CLOCK_IPGEN      0x00000001
 
+#define ESDHC_HOST_CONTROL_RES 0x05
+
 static u32 esdhc_readl(struct sdhci_host *host, int reg)
 {
        return in_be32(host->ioaddr + reg);
@@ -55,7 +57,13 @@ static u32 esdhc_readl(struct sdhci_host *host, int reg)
 
 static u16 esdhc_readw(struct sdhci_host *host, int reg)
 {
-       return in_be16(host->ioaddr + (reg ^ 0x2));
+       u16 ret;
+
+       if (unlikely(reg == SDHCI_HOST_VERSION))
+               ret = in_be16(host->ioaddr + reg);
+       else
+               ret = in_be16(host->ioaddr + (reg ^ 0x2));
+       return ret;
 }
 
 static u8 esdhc_readb(struct sdhci_host *host, int reg)
@@ -103,6 +111,10 @@ static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
        int base = reg & ~0x3;
        int shift = (reg & 0x3) * 8;
 
+       /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
+       if (reg == SDHCI_HOST_CONTROL)
+               val &= ~ESDHC_HOST_CONTROL_RES;
+
        clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
 }
 
@@ -130,6 +142,7 @@ static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
        }
 
        pre_div >>= 1;
+       div--;
 
        setbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
                  ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
@@ -152,6 +165,13 @@ static unsigned int esdhc_get_max_clock(struct sdhci_host *host)
        return of_host->clock;
 }
 
+static unsigned int esdhc_get_min_clock(struct sdhci_host *host)
+{
+       struct sdhci_of_host *of_host = sdhci_priv(host);
+
+       return of_host->clock / 256 / 16;
+}
+
 static unsigned int esdhc_get_timeout_clock(struct sdhci_host *host)
 {
        struct sdhci_of_host *of_host = sdhci_priv(host);
@@ -178,6 +198,7 @@ static struct sdhci_of_data sdhci_esdhc = {
                .set_clock = esdhc_set_clock,
                .enable_dma = esdhc_enable_dma,
                .get_max_clock = esdhc_get_max_clock,
+               .get_min_clock = esdhc_get_min_clock,
                .get_timeout_clock = esdhc_get_timeout_clock,
        },
 };
@@ -220,7 +241,7 @@ static int __devinit sdhci_of_probe(struct of_device *ofdev,
                return -ENODEV;
 
        host = sdhci_alloc_host(&ofdev->dev, sizeof(*of_host));
-       if (!host)
+       if (IS_ERR(host))
                return -ENOMEM;
 
        of_host = sdhci_priv(host);
@@ -244,6 +265,9 @@ static int __devinit sdhci_of_probe(struct of_device *ofdev,
                host->ops = &sdhci_of_data->ops;
        }
 
+       if (of_get_property(np, "sdhci,1-bit-only", NULL))
+               host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
+
        clk = of_get_property(np, "clock-frequency", &size);
        if (clk && size == sizeof(*clk) && *clk)
                of_host->clock = *clk;