From patchwork Tue Mar 29 08:53:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Vinni X-Patchwork-Id: 670912 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 p2T8rqWO019967 for ; Tue, 29 Mar 2011 08:54:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751854Ab1C2IyN (ORCPT ); Tue, 29 Mar 2011 04:54:13 -0400 Received: from mail1.shellit.org ([81.22.255.73]:60359 "EHLO mail.shellit.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751516Ab1C2IyM (ORCPT ); Tue, 29 Mar 2011 04:54:12 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.shellit.org (Postfix) with ESMTP id 1F65E7BA020; Tue, 29 Mar 2011 11:54:10 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at !change-mydomain-variable!.example.com X-Spam-Flag: NO X-Spam-Score: -1.358 X-Spam-Level: X-Spam-Status: No, score=-1.358 required=4.5 tests=[ALL_TRUSTED=-1.8, AWL=0.744, BAYES_00=-2.599, FORGED_YAHOO_RCVD=2.297] Received: from mail.shellit.org ([127.0.0.1]) by localhost (mail1.shellit.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GCaiCUQFkFMX; Tue, 29 Mar 2011 11:54:06 +0300 (EEST) Received: from localhost.localdomain (h-62-142-174-204.joensuunelli.fi [62.142.174.204]) by mail.shellit.org (Postfix) with ESMTPSA id 3FA907BA022; Tue, 29 Mar 2011 11:54:05 +0300 (EEST) From: Mikko Vinni To: Wolfram Sang Cc: linux-mmc@vger.kernel.org, Mikko Vinni Subject: [RFC] mmc: sdhci: work around broken dma boundary behavior Date: Tue, 29 Mar 2011 11:53:34 +0300 Message-Id: <1301388814-10931-1-git-send-email-mmvinni@yahoo.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <20110314172129.GA20654@pengutronix.de> References: <20110314172129.GA20654@pengutronix.de> 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]); Tue, 29 Mar 2011 08:54:13 +0000 (UTC) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 9e15f41..0319903 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -669,6 +669,7 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) host->data = data; host->data_early = 0; + host->data->bytes_xfered = 0; count = sdhci_calc_timeout(host, data); sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); @@ -807,8 +808,9 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) sdhci_set_transfer_irqs(host); - /* We do not handle DMA boundaries, so set it to max (512 KiB) */ - sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, data->blksz), SDHCI_BLOCK_SIZE); + /* Set the DMA boundary value and block size */ + sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG, + data->blksz), SDHCI_BLOCK_SIZE); sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); } @@ -1544,10 +1546,28 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) * We currently don't do anything fancy with DMA * boundaries, but as we can't disable the feature * we need to at least restart the transfer. + * + * According to the spec sdhci_readl(host, SDHCI_DMA_ADDRESS) + * should return a valid address to continue from, but as + * some controllers are faulty, don't trust them. */ - if (intmask & SDHCI_INT_DMA_END) - sdhci_writel(host, sdhci_readl(host, SDHCI_DMA_ADDRESS), - SDHCI_DMA_ADDRESS); + if (intmask & SDHCI_INT_DMA_END) { + u32 dmastart, dmanow; + dmastart = sg_dma_address(host->data->sg); + dmanow = dmastart + host->data->bytes_xfered; + /* + * Force update to the next DMA block boundary. + */ + dmanow = (dmanow & + ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1)) + + SDHCI_DEFAULT_BOUNDARY_SIZE; + host->data->bytes_xfered = dmanow - dmastart; + DBG("%s: DMA base 0x%08x, transferred 0x%06x bytes," + " next 0x%08x\n", + mmc_hostname(host->mmc), dmastart, + host->data->bytes_xfered, dmanow); + sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS); + } if (intmask & SDHCI_INT_DATA_END) { if (host->cmd) { diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 25e8bde..85750a9 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -202,6 +202,12 @@ #define SDHCI_MAX_DIV_SPEC_200 256 #define SDHCI_MAX_DIV_SPEC_300 2046 +/* + * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2. + */ +#define SDHCI_DEFAULT_BOUNDARY_SIZE (512 * 1024) +#define SDHCI_DEFAULT_BOUNDARY_ARG (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12) + struct sdhci_ops { #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS u32 (*read_l)(struct sdhci_host *host, int reg);