Commit 3796fb8a authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Chris Ball

mmc: omap_hsmmc: refactor duplicated code

There are a few places with the same functionality. This patch creates
two functions omap_hsmmc_set_bus_width() and omap_hsmmc_set_bus_mode()
to do the job.
Signed-off-by: default avatarAndy Shevchenko <ext-andriy.shevchenko@nokia.com>
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@nokia.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 5934df2f
...@@ -638,6 +638,41 @@ static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host) ...@@ -638,6 +638,41 @@ static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
omap_hsmmc_start_clock(host); omap_hsmmc_start_clock(host);
} }
static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
{
struct mmc_ios *ios = &host->mmc->ios;
u32 con;
con = OMAP_HSMMC_READ(host->base, CON);
switch (ios->bus_width) {
case MMC_BUS_WIDTH_8:
OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
break;
case MMC_BUS_WIDTH_4:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
break;
case MMC_BUS_WIDTH_1:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
break;
}
}
static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
{
struct mmc_ios *ios = &host->mmc->ios;
u32 con;
con = OMAP_HSMMC_READ(host->base, CON);
if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
OMAP_HSMMC_WRITE(host->base, CON, con | OD);
else
OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
/* /*
...@@ -649,7 +684,7 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) ...@@ -649,7 +684,7 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
struct mmc_ios *ios = &host->mmc->ios; struct mmc_ios *ios = &host->mmc->ios;
struct omap_mmc_platform_data *pdata = host->pdata; struct omap_mmc_platform_data *pdata = host->pdata;
int context_loss = 0; int context_loss = 0;
u32 hctl, capa, con; u32 hctl, capa;
unsigned long timeout; unsigned long timeout;
if (pdata->get_context_loss_count) { if (pdata->get_context_loss_count) {
...@@ -711,30 +746,12 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) ...@@ -711,30 +746,12 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
if (host->power_mode == MMC_POWER_OFF) if (host->power_mode == MMC_POWER_OFF)
goto out; goto out;
con = OMAP_HSMMC_READ(host->base, CON); omap_hsmmc_set_bus_width(host);
switch (ios->bus_width) {
case MMC_BUS_WIDTH_8:
OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
break;
case MMC_BUS_WIDTH_4:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
break;
case MMC_BUS_WIDTH_1:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
break;
}
omap_hsmmc_set_clock(host); omap_hsmmc_set_clock(host);
con = OMAP_HSMMC_READ(host->base, CON); omap_hsmmc_set_bus_mode(host);
if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
OMAP_HSMMC_WRITE(host->base, CON, con | OD);
else
OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
out: out:
host->context_loss = context_loss; host->context_loss = context_loss;
...@@ -1628,7 +1645,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req) ...@@ -1628,7 +1645,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
{ {
struct omap_hsmmc_host *host = mmc_priv(mmc); struct omap_hsmmc_host *host = mmc_priv(mmc);
u32 con;
int do_send_init_stream = 0; int do_send_init_stream = 0;
pm_runtime_get_sync(host->dev); pm_runtime_get_sync(host->dev);
...@@ -1654,22 +1670,7 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -1654,22 +1670,7 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
/* FIXME: set registers based only on changes to ios */ /* FIXME: set registers based only on changes to ios */
con = OMAP_HSMMC_READ(host->base, CON); omap_hsmmc_set_bus_width(host);
switch (mmc->ios.bus_width) {
case MMC_BUS_WIDTH_8:
OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
break;
case MMC_BUS_WIDTH_4:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
break;
case MMC_BUS_WIDTH_1:
OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
OMAP_HSMMC_WRITE(host->base, HCTL,
OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
break;
}
if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
/* Only MMC1 can interface at 3V without some flavor /* Only MMC1 can interface at 3V without some flavor
...@@ -1694,11 +1695,7 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -1694,11 +1695,7 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
if (do_send_init_stream) if (do_send_init_stream)
send_init_stream(host); send_init_stream(host);
con = OMAP_HSMMC_READ(host->base, CON); omap_hsmmc_set_bus_mode(host);
if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
OMAP_HSMMC_WRITE(host->base, CON, con | OD);
else
OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
pm_runtime_put_autosuspend(host->dev); pm_runtime_put_autosuspend(host->dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment