From patchwork Thu Dec 2 20:39:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 375821 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 oB2KcAJ5024804 for ; Thu, 2 Dec 2010 20:39:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756328Ab0LBUj1 (ORCPT ); Thu, 2 Dec 2010 15:39:27 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:34219 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755425Ab0LBUj1 convert rfc822-to-8bit (ORCPT ); Thu, 2 Dec 2010 15:39:27 -0500 Received: by wwa36 with SMTP id 36so9180874wwa.1 for ; Thu, 02 Dec 2010 12:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9kEH0b4guNEkrMKMDO5PWB6YRdhZOdyLzUtMQ9Xz8o4=; b=dAGf/xS8OPhc207fxLBgJC80Izsfb4LsinpRxJ5nsWKrpwQQKM35YZl3Unw1F+0Tno n51rEU45qWD4uCteZlTqBbkKpn3choag/UCPPUQgWzpaoUlh5rrDhZDFpfC6HinnA5FC z/MleqmfyI7zRTNxzHfm7/n7jUPIe//YMQL2Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=t0P2XumDgQbMotMhqqISI7Y1u7xQE4o4B3s3z1auWIlggbtoeAFTAOQJBIPllvK/H7 7JCIwoQiS6ftjnWEw23Xjg8gS/fu+sNSqVgkR518FTueQDO9//QmMTNxiK/waQkyQyd5 kjgKmM21hgPPYAaIN8/whxIYDPIrgjBHrpNn0= MIME-Version: 1.0 Received: by 10.216.187.82 with SMTP id x60mr2426318wem.9.1291322365868; Thu, 02 Dec 2010 12:39:25 -0800 (PST) Received: by 10.216.132.160 with HTTP; Thu, 2 Dec 2010 12:39:25 -0800 (PST) In-Reply-To: <20101202174550.GJ29347@n2100.arm.linux.org.uk> References: <1291308678-15497-1-git-send-email-linus.walleij@stericsson.com> <20101202174550.GJ29347@n2100.arm.linux.org.uk> Date: Thu, 2 Dec 2010 21:39:25 +0100 Message-ID: Subject: Re: [PATCH] mmci: corrected calculation of clock div for ux500 From: Linus Walleij To: Russell King - ARM Linux Cc: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ulf Hansson 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.3 (demeter1.kernel.org [140.211.167.41]); Thu, 02 Dec 2010 20:39:28 +0000 (UTC) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 7567872..0a95377 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -51,6 +51,7 @@ static unsigned int fmax = 515633; * @broken_blockend_dma: the MCI_DATABLOCKEND is broken on the hardware when * using DMA. * @sdio: variant supports SDIO + * @st_clkdiv: true if using a ST-specific clock divider algorithm */ struct variant_data { unsigned int clkreg; @@ -61,6 +62,7 @@ struct variant_data { bool broken_blockend; bool broken_blockend_dma; bool sdio; + bool st_clkdiv; }; static struct variant_data variant_arm = { @@ -86,7 +88,9 @@ static struct variant_data variant_ux500 = { .datalength_bits = 24, .broken_blockend = true, .sdio = true, + .st_clkdiv = true, }; + /* * This must be called with host->lock held */ @@ -99,7 +103,22 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) if (desired >= host->mclk) { clk = MCI_CLK_BYPASS; host->cclk = host->mclk; + } else if (variant->st_clkdiv) { + /* + * DB8500 TRM says f = mclk / (clkdiv + 2) + * => clkdiv = (mclk / f) - 2 + * Round the divider up so we don't exceed the max + * frequency + */ + clk = DIV_ROUND_UP(host->mclk, desired) - 2; + if (clk >= 256) + clk = 255; + host->cclk = host->mclk / (clk + 2); } else { + /* + * PL180 TRM says f = mclk / (2 * (clkdiv + 1)) + * => clkdiv = mclk / (2 * f) - 1 + */ clk = host->mclk / (2 * desired) - 1; if (clk >= 256)