Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Dec 2015 01:25:30 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r292419 - head/sys/arm/freescale/imx
Message-ID:  <201512180125.tBI1PUnZ076695@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Fri Dec 18 01:25:30 2015
New Revision: 292419
URL: https://svnweb.freebsd.org/changeset/base/292419

Log:
  Fix the clock divisor calc for imx6 sdcard bus speed.
  
  I don't know what alternate universe I was inhabiting when I wrote it
  originally, but apparently the basic workings of mathematics were different
  than in this universe.  I also can't explain how it ever worked, except "by
  accident", because completely bogus values were being written into the
  divisor register.

Modified:
  head/sys/arm/freescale/imx/imx_sdhci.c

Modified: head/sys/arm/freescale/imx/imx_sdhci.c
==============================================================================
--- head/sys/arm/freescale/imx/imx_sdhci.c	Fri Dec 18 01:03:34 2015	(r292418)
+++ head/sys/arm/freescale/imx/imx_sdhci.c	Fri Dec 18 01:25:30 2015	(r292419)
@@ -522,12 +522,19 @@ imx_sdhc_set_clock(struct imx_sdhci_soft
 	else
 		freq = sc->baseclk_hz / (2 * divisor);
 
-	for (prescale = 2; prescale < freq / prescale / 16;)
+	for (prescale = 2; freq < sc->baseclk_hz / (prescale * 16);)
 		prescale <<= 1;
 
-	for (divisor = 1; freq < freq / prescale / divisor;)
+	for (divisor = 1; freq < sc->baseclk_hz / (prescale * divisor);)
 		++divisor;
 
+#ifdef DEBUG	
+	device_printf(sc->dev,
+	    "desired SD freq: %d, actual: %d; base %d prescale %d divisor %d\n",
+	    freq, sc->baseclk_hz / (prescale * divisor), sc->baseclk_hz, 
+	    prescale, divisor);
+#endif	
+
 	prescale >>= 1;
 	divisor -= 1;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512180125.tBI1PUnZ076695>