I'd rather it's implemented something like below (it's only for illustration
purpose):

diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 793ab2a..6fa7a05 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -73,42 +73,28 @@ struct pxamci_host {
 };

 #ifdef CONFIG_REGULATOR
-static int pxamci_regulator_get(struct device *dev, struct pxamci_host *host)
+static void pxamci_set_power(struct pxamci_host *host, unsigned int vdd)
 {
-       struct regulator *reg = regulator_get(dev, "vmmc");
+       struct mmc_host *mmc = host->mmc;

-       if (IS_ERR(reg))
-               return PTR_ERR(reg);
+       if (host->pdata->setpower) {
+               host->pdata->setpower(host->dev, vdd);
+               return;
+       }

-       host->vcc = reg;
-       return 0;
-}
+#ifdef CONFIG_REGULATOR
+       /* use regulator API */
+       if (!host->vcc) {
+               host->vcc = regulator_get(dev, "vmmc");
+               if (IS_ERR(host->vcc))
+                       return PTR_ERR(host->vcc);

-static int pxamci_regulator_get_ocrmask(struct pxamci_host *host)
-{
-       return mmc_regulator_get_ocrmask(host->vcc);
-}
+               mmc->ocr_avail = mmc_regulator_get_ocrmask(host->vcc);
+       }

-static int pxamci_regulator_set_ocr(struct pxamci_host *host,
-                                                       unsigned short vdd)
-{
-       return mmc_regulator_set_ocr(host->vcc, vdd);
-}
-#else
-static int pxamci_regulator_get(struct device *dev, struct pxamci_host *host)
-{
-       return -ENOTSUPP;
-}
-static int pxamci_regulator_get_ocrmask(struct pxamci_host *host)
-{
-       return 0;
-}
-static int pxamci_regulator_set_ocr(struct pxamci_host *host,
-                                                       unsigned short vdd)
-{
-       return 0;
-}
+       mmc_regulator_set_ocr(host->vcc, vdd);
 #endif
+}

 static void pxamci_stop_clock(struct pxamci_host *host)
 {
@@ -479,10 +465,7 @@ static void pxamci_set_ios(struct mmc_host *mmc,
struct mmc_ios *ios)
        if (host->power_mode != ios->power_mode) {
                host->power_mode = ios->power_mode;

-               if (host->vcc)
-                       pxamci_regulator_set_ocr(host, ios->vdd);
-               else if (host->pdata && host->pdata->setpower)
-                       host->pdata->setpower(mmc_dev(mmc), ios->vdd);
+               pxamci_set_power(host, ios->vdd);

                if (ios->power_mode == MMC_POWER_ON)
                        host->cmdat |= CMDAT_INIT;

Reply via email to