From patchwork Thu May 5 11:51:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 756722 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p45BqUp5019336 for ; Thu, 5 May 2011 11:52:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753397Ab1EELw1 (ORCPT ); Thu, 5 May 2011 07:52:27 -0400 Received: from smtp.nokia.com ([147.243.128.24]:62867 "EHLO mgw-da01.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753463Ab1EELw0 (ORCPT ); Thu, 5 May 2011 07:52:26 -0400 Received: from nokia.com (localhost [127.0.0.1]) by mgw-da01.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p45BqG1s024970; Thu, 5 May 2011 14:52:16 +0300 Received: from localhost.localdomain ([[172.21.24.109]]) by mgw-da01.nokia.com with RELAY id p45BpO71023786 ; Thu, 5 May 2011 14:52:02 +0300 From: Adrian Hunter To: Tony Lindgren Cc: Madhusudhan Chikkature , linux-omap Mailing List , linux-mmc Mailing List , linux-arm Mailing List , Andy Shevchenko , Adrian Hunter Subject: [PATCH 11/22] mmc: omap_hsmmc: split duplicate code to calc_divisor() function Date: Thu, 5 May 2011 14:51:11 +0300 Message-Id: <1304596282-4095-12-git-send-email-adrian.hunter@nokia.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1304596282-4095-1-git-send-email-adrian.hunter@nokia.com> References: <1304596282-4095-1-git-send-email-adrian.hunter@nokia.com> X-Nokia-AV: Clean Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 05 May 2011 11:52:30 +0000 (UTC) From: Andy Shevchenko There are two places where the same calculations are done. Let's split them to separate function. In addition the new function is simplified by usage DIV_ROUND_UP kernel macro. Signed-off-by: Andy Shevchenko Signed-off-by: Adrian Hunter --- drivers/mmc/host/omap_hsmmc.c | 45 ++++++++++++++++------------------------ 1 files changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 7a153af..045c581 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -596,6 +596,20 @@ static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host) OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); } +/* Calculate divisor for the given clock frequency */ +static u16 calc_divisor(struct mmc_ios *ios) +{ + u16 dsor = 0; + + if (ios->clock) { + dsor = DIV_ROUND_UP(OMAP_MMC_MASTER_CLOCK, ios->clock); + if (dsor > 250) + dsor = 250; + } + + return dsor; +} + #ifdef CONFIG_PM /* @@ -608,7 +622,6 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) struct omap_mmc_platform_data *pdata = host->pdata; int context_loss = 0; u32 hctl, capa, con; - u16 dsor = 0; unsigned long timeout; if (pdata->get_context_loss_count) { @@ -687,21 +700,10 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) break; } - if (ios->clock) { - dsor = OMAP_MMC_MASTER_CLOCK / ios->clock; - if (dsor < 1) - dsor = 1; - - if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock) - dsor++; - - if (dsor > 250) - dsor = 250; - } - OMAP_HSMMC_WRITE(host->base, SYSCTL, OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); - OMAP_HSMMC_WRITE(host->base, SYSCTL, (dsor << 6) | (DTO << 16)); + OMAP_HSMMC_WRITE(host->base, SYSCTL, + (calc_divisor(ios) << 6) | (DTO << 16)); OMAP_HSMMC_WRITE(host->base, SYSCTL, OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); @@ -1612,7 +1614,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) { struct omap_hsmmc_host *host = mmc_priv(mmc); - u16 dsor = 0; unsigned long regval; unsigned long timeout; u32 con; @@ -1676,21 +1677,11 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) } } - if (ios->clock) { - dsor = OMAP_MMC_MASTER_CLOCK / ios->clock; - if (dsor < 1) - dsor = 1; - - if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock) - dsor++; - - if (dsor > 250) - dsor = 250; - } omap_hsmmc_stop_clock(host); + regval = OMAP_HSMMC_READ(host->base, SYSCTL); regval = regval & ~(CLKD_MASK); - regval = regval | (dsor << 6) | (DTO << 16); + regval = regval | (calc_divisor(ios) << 6) | (DTO << 16); OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); OMAP_HSMMC_WRITE(host->base, SYSCTL, OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);