Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8880a4a5 authored by Tomasz Figa's avatar Tomasz Figa Committed by Chris Ball
Browse files

mmc: sdhci-s3c: Use shifts to divide by powers of two



Current implementation of sdhci_s3c_consider_clock() is highly
inefficient due to multiple integer divisions by variable performed in a
loop. Since only divisors that are powers of two are considered, this
patch replaces them with respective shifts, removing all the integer
divisions.

Signed-off-by: default avatarTomasz Figa <tomasz.figa@gmail.com>
Tested-by: default avatarHeiko Stuebner <heiko@sntech.de>
Acked-by: default avatarHeiko Stuebner <heiko@sntech.de>
Tested-by: default avatarJaehoon Chung <jh80.chung@samsung.com>
Acked-by; Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: default avatarChris Ball <chris@printf.net>
parent d9c3f5df
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -144,7 +144,7 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
{
{
	unsigned long rate;
	unsigned long rate;
	struct clk *clksrc = ourhost->clk_bus[src];
	struct clk *clksrc = ourhost->clk_bus[src];
	int div;
	int shift;


	if (!clksrc)
	if (!clksrc)
		return UINT_MAX;
		return UINT_MAX;
@@ -160,15 +160,15 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,


	rate = clk_get_rate(clksrc);
	rate = clk_get_rate(clksrc);


	for (div = 1; div < 256; div *= 2) {
	for (shift = 0; shift < 8; ++shift) {
		if ((rate / div) <= wanted)
		if ((rate >> shift) <= wanted)
			break;
			break;
	}
	}


	dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
	dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
		src, rate, wanted, rate / div);
		src, rate, wanted, rate >> shift);


	return wanted - (rate / div);
	return wanted - (rate >> shift);
}
}


/**
/**