Merge branch 'iop-raid6' into async-tx-next
[pandora-kernel.git] / arch / arm / mach-omap2 / mmc-twl4030.c
index df1539e..dc40b3e 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/delay.h>
 #include <linux/gpio.h>
 #include <linux/i2c/twl4030.h>
+#include <linux/regulator/machine.h>
 
 #include <mach/hardware.h>
 #include <mach/control.h>
@@ -61,7 +62,7 @@ static struct twl_mmc_controller {
        u8              twl_vmmc_dev_grp;
        u8              twl_mmc_dedicated;
        char            name[HSMMC_NAME_LEN + 1];
-} hsmmc[] = {
+} hsmmc[OMAP34XX_NR_MMC] = {
        {
                .twl_vmmc_dev_grp               = VMMC1_DEV_GRP,
                .twl_mmc_dedicated              = VMMC1_DEDICATED,
@@ -99,6 +100,14 @@ static int twl_mmc_get_ro(struct device *dev, int slot)
        return gpio_get_value_cansleep(mmc->slots[0].gpio_wp);
 }
 
+static int twl_mmc_get_cover_state(struct device *dev, int slot)
+{
+       struct omap_mmc_platform_data *mmc = dev->platform_data;
+
+       /* NOTE: assumes card detect signal is active-low */
+       return !gpio_get_value_cansleep(mmc->slots[0].switch_pin);
+}
+
 /*
  * MMC Slot Initialization.
  */
@@ -177,7 +186,10 @@ static int twl_mmc_resume(struct device *dev, int slot)
 static int twl_mmc_set_voltage(struct twl_mmc_controller *c, int vdd)
 {
        int ret;
-       u8 vmmc, dev_grp_val;
+       u8 vmmc = 0, dev_grp_val;
+
+       if (!vdd)
+               goto doit;
 
        if (c->twl_vmmc_dev_grp == VMMC1_DEV_GRP) {
                /* VMMC1:  max 220 mA.  And for 8-bit mode,
@@ -202,8 +214,7 @@ static int twl_mmc_set_voltage(struct twl_mmc_controller *c, int vdd)
                        /* error if VSIM needed */
                        break;
                default:
-                       vmmc = 0;
-                       break;
+                       return -EINVAL;
                }
        } else if (c->twl_vmmc_dev_grp == VMMC2_DEV_GRP) {
                /* VMMC2:  max 100 mA */
@@ -229,21 +240,21 @@ static int twl_mmc_set_voltage(struct twl_mmc_controller *c, int vdd)
                        vmmc = VMMC2_315V;
                        break;
                default:
-                       vmmc = 0;
-                       break;
+                       return -EINVAL;
                }
        } else {
-               return 0;
+               return -EINVAL;
        }
 
-       if (vmmc)
+doit:
+       if (vdd)
                dev_grp_val = VMMC_DEV_GRP_P1;  /* Power up */
        else
                dev_grp_val = LDO_CLR;          /* Power down */
 
        ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
                                        dev_grp_val, c->twl_vmmc_dev_grp);
-       if (ret)
+       if (ret || !vdd)
                return ret;
 
        ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
@@ -346,6 +357,16 @@ static int twl_mmc2_set_power(struct device *dev, int slot, int power_on, int vd
        return ret;
 }
 
+static int twl_mmc3_set_power(struct device *dev, int slot, int power_on,
+               int vdd)
+{
+       /*
+        * Assume MMC3 has self-powered device connected, for example on-board
+        * chip with external power source.
+        */
+       return 0;
+}
+
 static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
 
 void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
@@ -381,8 +402,11 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
                        return;
                }
 
-               snprintf(twl->name, ARRAY_SIZE(twl->name), "mmc%islot%i",
-                               c->mmc, 1);
+               if (c->name)
+                       strncpy(twl->name, c->name, HSMMC_NAME_LEN);
+               else
+                       snprintf(twl->name, ARRAY_SIZE(twl->name),
+                               "mmc%islot%i", c->mmc, 1);
                mmc->slots[0].name = twl->name;
                mmc->nr_slots = 1;
                mmc->slots[0].wires = c->wires;
@@ -398,7 +422,10 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 
                        mmc->slots[0].switch_pin = c->gpio_cd;
                        mmc->slots[0].card_detect_irq = gpio_to_irq(c->gpio_cd);
-                       mmc->slots[0].card_detect = twl_mmc_card_detect;
+                       if (c->cover_only)
+                               mmc->slots[0].get_cover_state = twl_mmc_get_cover_state;
+                       else
+                               mmc->slots[0].card_detect = twl_mmc_card_detect;
                } else
                        mmc->slots[0].switch_pin = -EINVAL;
 
@@ -414,7 +441,7 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
 
                /* NOTE:  we assume OMAP's MMC1 and MMC2 use
                 * the TWL4030's VMMC1 and VMMC2, respectively;
-                * and that OMAP's MMC3 isn't used.
+                * and that MMC3 device has it's own power source.
                 */
 
                switch (c->mmc) {
@@ -429,14 +456,28 @@ void __init twl4030_mmc_init(struct twl4030_hsmmc_info *controllers)
                        else
                                mmc->slots[0].ocr_mask = MMC_VDD_165_195;
                        break;
+               case 3:
+                       mmc->slots[0].set_power = twl_mmc3_set_power;
+                       mmc->slots[0].ocr_mask = MMC_VDD_165_195;
+                       break;
                default:
                        pr_err("MMC%d configuration not supported!\n", c->mmc);
+                       kfree(mmc);
                        continue;
                }
                hsmmc_data[c->mmc - 1] = mmc;
        }
 
        omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
+
+       /* pass the device nodes back to board setup code */
+       for (c = controllers; c->mmc; c++) {
+               struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
+
+               if (!c->mmc || c->mmc > nr_hsmmc)
+                       continue;
+               c->dev = mmc->dev;
+       }
 }
 
 #endif