From patchwork Thu Apr 8 15:01:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thomas.koeller@baslerweb.com X-Patchwork-Id: 91288 Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o38F54MO002602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 8 Apr 2010 15:05:40 GMT Received: from dlep35.itg.ti.com ([157.170.170.118]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id o38F3Tpa011688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Apr 2010 10:03:29 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep35.itg.ti.com (8.13.7/8.13.7) with ESMTP id o38F3QPW018381; Thu, 8 Apr 2010 10:03:26 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 4F55E80667; Thu, 8 Apr 2010 10:03:10 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp52.itg.ti.com (dflp52.itg.ti.com [128.247.22.96]) by linux.omap.com (Postfix) with ESMTP id BAD338062E for ; Thu, 8 Apr 2010 10:02:14 -0500 (CDT) Received: from neches.ext.ti.com (localhost [127.0.0.1]) by dflp52.itg.ti.com (8.13.7/8.13.7) with ESMTP id o38F2Eg2020893 for ; Thu, 8 Apr 2010 10:02:14 -0500 (CDT) Received: from psmtp.com (na3sys009amx237.postini.com [74.125.149.121]) by neches.ext.ti.com (8.13.7/8.13.7) with SMTP id o38F2DOB025007 for ; Thu, 8 Apr 2010 10:02:13 -0500 Received: from source ([80.156.24.166]) by na3sys009amx237.postini.com ([74.125.148.10]) with SMTP; Thu, 08 Apr 2010 11:02:13 EDT Received: from unknown (HELO AHR075S.basler.corp) ([172.16.20.75]) by mail01-out.baslerweb.com with ESMTP; 08 Apr 2010 17:02:13 +0200 Received: from localhost.localdomain ([172.16.13.131]) by AHR075S.basler.corp with Microsoft SMTPSVC(6.0.3790.3959); Thu, 8 Apr 2010 17:02:08 +0200 From: thomas.koeller@baslerweb.com To: davinci-linux-open-source@linux.davincidsp.com Subject: [PATCH 3/4] DaVinci SPI: Fix SPI clock prescale factor computation Date: Thu, 8 Apr 2010 17:01:57 +0200 Message-Id: <1270738918-30050-5-git-send-email-thomas.koeller@baslerweb.com> X-Mailer: git-send-email 1.7.0.3 In-Reply-To: <1270738918-30050-1-git-send-email-thomas.koeller@baslerweb.com> References: <1270738918-30050-1-git-send-email-thomas.koeller@baslerweb.com> X-OriginalArrivalTime: 08 Apr 2010 15:02:08.0261 (UTC) FILETIME=[7574EB50:01CAD72C] X-pstn-neptune: 0/0/0.00/0 X-pstn-levels: (S:99.90000/99.90000 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) X-pstn-settings: 2 (0.5000:0.5000) s cv gt3 gt2 gt1 r p m c X-pstn-addresses: from [db-null] X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Greylist: Sender succeeded STARTTLS authentication, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 08 Apr 2010 15:05:40 +0000 (UTC) diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index 956f617..02e1a76 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c @@ -153,7 +153,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, struct davinci_spi *davinci_spi; struct davinci_spi_platform_data *pdata; u8 bits_per_word = 0; - u32 hz = 0, prescale; + u32 hz = 0, prescale = 0, clkspeed; davinci_spi = spi_master_get_devdata(spi->master); pdata = davinci_spi->pdata; @@ -190,10 +190,16 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f, spi->chip_select); - prescale = ((clk_get_rate(davinci_spi->clk) / hz) - 1) & 0xff; + clkspeed = clk_get_rate(davinci_spi->clk); + if (hz > clkspeed / 2) + prescale = 1 << 8; + if (hz < clkspeed / 256) + prescale = 255 << 8; + if (!prescale) + prescale = ((clkspeed / hz - 1) << 8) & 0x0000ff00; clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select); - set_fmt_bits(davinci_spi->base, prescale << 8, spi->chip_select); + set_fmt_bits(davinci_spi->base, prescale, spi->chip_select); return 0; }