diff options
author | Andy Shevchenko <ext-andriy.shevchenko@nokia.com> | 2011-05-10 08:51:54 -0400 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2011-07-21 10:35:02 -0400 |
commit | ac330f44c6bcc5f8ef7eb6ea7fd00575a1d5ef1a (patch) | |
tree | d2797250070bb1a7b833113deef6962ff7706065 /drivers/mmc | |
parent | 6b206efeccacafc8cd0cc0b72ff92f2be175ca9e (diff) |
mmc: omap_hsmmc: split duplicate code to calc_divisor() function
There are two places where the same calculations are done.
Let's split them into a separate function.
In addition, simplify by using the DIV_ROUND_UP kernel macro.
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Signed-off-by: Adrian Hunter <adrian.hunter@nokia.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/host/omap_hsmmc.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index b0b52ced4554..2840c7af02c2 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/kernel.h> | ||
20 | #include <linux/debugfs.h> | 21 | #include <linux/debugfs.h> |
21 | #include <linux/seq_file.h> | 22 | #include <linux/seq_file.h> |
22 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
@@ -588,6 +589,20 @@ static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host) | |||
588 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); | 589 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
589 | } | 590 | } |
590 | 591 | ||
592 | /* Calculate divisor for the given clock frequency */ | ||
593 | static u16 calc_divisor(struct mmc_ios *ios) | ||
594 | { | ||
595 | u16 dsor = 0; | ||
596 | |||
597 | if (ios->clock) { | ||
598 | dsor = DIV_ROUND_UP(OMAP_MMC_MASTER_CLOCK, ios->clock); | ||
599 | if (dsor > 250) | ||
600 | dsor = 250; | ||
601 | } | ||
602 | |||
603 | return dsor; | ||
604 | } | ||
605 | |||
591 | #ifdef CONFIG_PM | 606 | #ifdef CONFIG_PM |
592 | 607 | ||
593 | /* | 608 | /* |
@@ -600,7 +615,6 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) | |||
600 | struct omap_mmc_platform_data *pdata = host->pdata; | 615 | struct omap_mmc_platform_data *pdata = host->pdata; |
601 | int context_loss = 0; | 616 | int context_loss = 0; |
602 | u32 hctl, capa, con; | 617 | u32 hctl, capa, con; |
603 | u16 dsor = 0; | ||
604 | unsigned long timeout; | 618 | unsigned long timeout; |
605 | 619 | ||
606 | if (pdata->get_context_loss_count) { | 620 | if (pdata->get_context_loss_count) { |
@@ -679,21 +693,10 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) | |||
679 | break; | 693 | break; |
680 | } | 694 | } |
681 | 695 | ||
682 | if (ios->clock) { | ||
683 | dsor = OMAP_MMC_MASTER_CLOCK / ios->clock; | ||
684 | if (dsor < 1) | ||
685 | dsor = 1; | ||
686 | |||
687 | if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock) | ||
688 | dsor++; | ||
689 | |||
690 | if (dsor > 250) | ||
691 | dsor = 250; | ||
692 | } | ||
693 | |||
694 | OMAP_HSMMC_WRITE(host->base, SYSCTL, | 696 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
695 | OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); | 697 | OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); |
696 | OMAP_HSMMC_WRITE(host->base, SYSCTL, (dsor << 6) | (DTO << 16)); | 698 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
699 | (calc_divisor(ios) << 6) | (DTO << 16)); | ||
697 | OMAP_HSMMC_WRITE(host->base, SYSCTL, | 700 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
698 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); | 701 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); |
699 | 702 | ||
@@ -1603,7 +1606,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req) | |||
1603 | static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | 1606 | static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
1604 | { | 1607 | { |
1605 | struct omap_hsmmc_host *host = mmc_priv(mmc); | 1608 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
1606 | u16 dsor = 0; | ||
1607 | unsigned long regval; | 1609 | unsigned long regval; |
1608 | unsigned long timeout; | 1610 | unsigned long timeout; |
1609 | u32 con; | 1611 | u32 con; |
@@ -1667,21 +1669,11 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
1667 | } | 1669 | } |
1668 | } | 1670 | } |
1669 | 1671 | ||
1670 | if (ios->clock) { | ||
1671 | dsor = OMAP_MMC_MASTER_CLOCK / ios->clock; | ||
1672 | if (dsor < 1) | ||
1673 | dsor = 1; | ||
1674 | |||
1675 | if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock) | ||
1676 | dsor++; | ||
1677 | |||
1678 | if (dsor > 250) | ||
1679 | dsor = 250; | ||
1680 | } | ||
1681 | omap_hsmmc_stop_clock(host); | 1672 | omap_hsmmc_stop_clock(host); |
1673 | |||
1682 | regval = OMAP_HSMMC_READ(host->base, SYSCTL); | 1674 | regval = OMAP_HSMMC_READ(host->base, SYSCTL); |
1683 | regval = regval & ~(CLKD_MASK); | 1675 | regval = regval & ~(CLKD_MASK); |
1684 | regval = regval | (dsor << 6) | (DTO << 16); | 1676 | regval = regval | (calc_divisor(ios) << 6) | (DTO << 16); |
1685 | OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); | 1677 | OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); |
1686 | OMAP_HSMMC_WRITE(host->base, SYSCTL, | 1678 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
1687 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); | 1679 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); |