Skip to contentSkip to conversation

mmci: corrected calculation of clock div for ux500

PATCH New Linus Walleij 3 participants 3 messages Dec 2, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmci: corrected calculation of clock div for ux500

From: Ulf Hansson <[email protected]>

The Ux500 variant of this block has a different divider. The value used right now is too big and which means a loss in performance. This fix corrects it.

---
 drivers/mmc/host/mmci.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/mmc/host/mmci.c +9 -0
index cabd386..21fd486 100644
@@ -57,6 +57,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;
@@ -69,6 +70,7 @@ struct variant_data {
 	bool			broken_blockend;
 	bool			broken_blockend_dma;
 	bool			sdio;
+	bool			st_clkdiv;
 };
 
 static struct variant_data variant_arm = {
@@ -96,7 +98,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
  */
@@ -109,6 +113,11 @@ 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) {
+			clk = ((host->mclk + desired - 1) / desired) - 2;
+			if (clk >= 256)
+				clk = 255;
+			host->cclk = host->mclk / (clk + 2);
 		} else {
 			clk = host->mclk / (2 * desired) - 1;
 			if (clk >= 256)
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH 1/1 mmci: corrected calculation of clock div for ux500

Quoted 5 lines · Linus Walleij

From: Ulf Hansson <[email protected]>

The Ux500 variant of this block has a different divider. The value used right now is too big and which means a loss in performance. This fix corrects it.

Err.

drivers/mmc/host/mmci.c static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) · line 120

Quoted 5 lines
drivers/mmc/host/mmci.c +5 -0
+		} else if (variant->st_clkdiv) {
+			clk = ((host->mclk + desired - 1) / desired) - 2;
+			if (clk >= 256)
+				clk = 255;
+			host->cclk = host->mclk / (clk + 2);

This causes the divider to be selected for the 'nearest' frequency. You are not allowed to _exceed_ the desired frequency - you must always round down.

IOW, if 10MHz is requested and you can't do 10MHz, 10.5MHz will not do - you must select a frequency below 10MHz.

#2 lore raw

PATCH 1/1 mmci: corrected calculation of clock div for ux500

2010/12/2 Russell King - ARM Linux <[email protected]>:

Quoted 15 lines · Linus Walleij
Quoted 5 lines

From: Ulf Hansson <[email protected]>

The Ux500 variant of this block has a different divider. The value used right now is too big and which means a loss in performance. This fix corrects it.

Err.

Quoted 5 lines

+ ? ? ? ? ? ? } else if (variant->st_clkdiv) {
+ ? ? ? ? ? ? ? ? ? ? clk = ((host->mclk + desired - 1) / desired) - 2;
+ ? ? ? ? ? ? ? ? ? ? if (clk >= 256)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? clk = 255;
+ ? ? ? ? ? ? ? ? ? ? host->cclk = host->mclk / (clk + 2);

Quoted 3 lines

This causes the divider to be selected for the 'nearest' frequency. You are not allowed to _exceed_ the desired frequency - you must always round down.

I don't get it because what we try to do is round the divider up so the divided result will be rounded down... Is it the -2 part that confuse things? That is just a constant from the datasheet. (Some default divider offset.)

I rewrote the patch using DIV_ROUND_UP() and expanded the maths from the datasheets so I properly understand it myself, is this better: