Skip to contentSkip to conversation

SH Drivers Updates for v4.5

GIT PULL New Simon Horman 1 participant 3 messages Jan 21, 2016 SuperH

lore
Share & tools
lore
#0 lore raw

Hi Linus,

Please consider these SH drivers updates for v4.5.

It is comprised of a cleanup from Geert Uytterhoeven for the clock API.

This pull request is based on the previous round of such requests, which were for v4.4. I can rebase, e.g. on top of v4.4, if that would be better.

The following changes since commit 0ba58de231066e47de87ccc4d61c5e396fe9bd27:

drivers: sh: Get rid of CONFIG_ARCH_SHMOBILE_MULTI (2015-11-17 02:12:46 +0900)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git tags/renesas-sh-drivers-for-v4.5

for you to fetch changes up to 6575a9c69a211ac1cf454f9c76be54f7a5fae9fe:

drivers: sh: clk: Avoid crashes when passing NULL clocks (2015-11-24 11:49:18 +0900)

----------------------------------------------------------------
SH Drivers Updates for v4.5

Clean up the clock API on legacy SH to make it more similar to the Common Clock Framework. This will avoid different behaviour in drivers shared between legacy and CCF-based platforms (e.g. SCIF).

----------------------------------------------------------------
Geert Uytterhoeven (2):
drivers: sh: clk: Remove obsolete and unused clk_round_parent()
drivers: sh: clk: Avoid crashes when passing NULL clocks

 drivers/sh/clk/core.c  | 100 ++++++-------------------------------------------
 include/linux/sh_clk.h |   4 --
 2 files changed, 12 insertions(+), 92 deletions(-)
#1 lore raw

PATCH 1/2 drivers: sh: clk: Remove obsolete and unused clk_round_parent()

From: Geert Uytterhoeven <[email protected]>

clk_round_parent() was only ever used by AP4EVB, until commit b24bd7e97b3784af ("ARM: shmobile: Remove AP4EVB board support").

The Common Clock Framework does not provide clk_round_parent(), hence remove it.

---
 drivers/sh/clk/core.c  | 88 --------------------------------------------------
 include/linux/sh_clk.h |  4 ---
 2 files changed, 92 deletions(-)
drivers/sh/clk/core.c +0 -88
index be56b22ca941..6bf973bd9654 100644
@@ -555,94 +555,6 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_round_rate);
 
-long clk_round_parent(struct clk *clk, unsigned long target,
-		      unsigned long *best_freq, unsigned long *parent_freq,
-		      unsigned int div_min, unsigned int div_max)
-{
-	struct cpufreq_frequency_table *freq, *best = NULL;
-	unsigned long error = ULONG_MAX, freq_high, freq_low, div;
-	struct clk *parent = clk_get_parent(clk);
-
-	if (!parent) {
-		*parent_freq = 0;
-		*best_freq = clk_round_rate(clk, target);
-		return abs(target - *best_freq);
-	}
-
-	cpufreq_for_each_valid_entry(freq, parent->freq_table) {
-		if (unlikely(freq->frequency / target <= div_min - 1)) {
-			unsigned long freq_max;
-
-			freq_max = (freq->frequency + div_min / 2) / div_min;
-			if (error > target - freq_max) {
-				error = target - freq_max;
-				best = freq;
-				if (best_freq)
-					*best_freq = freq_max;
-			}
-
-			pr_debug("too low freq %u, error %lu\n", freq->frequency,
-				 target - freq_max);
-
-			if (!error)
-				break;
-
-			continue;
-		}
-
-		if (unlikely(freq->frequency / target >= div_max)) {
-			unsigned long freq_min;
-
-			freq_min = (freq->frequency + div_max / 2) / div_max;
-			if (error > freq_min - target) {
-				error = freq_min - target;
-				best = freq;
-				if (best_freq)
-					*best_freq = freq_min;
-			}
-
-			pr_debug("too high freq %u, error %lu\n", freq->frequency,
-				 freq_min - target);
-
-			if (!error)
-				break;
-
-			continue;
-		}
-
-		div = freq->frequency / target;
-		freq_high = freq->frequency / div;
-		freq_low = freq->frequency / (div + 1);
-
-		if (freq_high - target < error) {
-			error = freq_high - target;
-			best = freq;
-			if (best_freq)
-				*best_freq = freq_high;
-		}
-
-		if (target - freq_low < error) {
-			error = target - freq_low;
-			best = freq;
-			if (best_freq)
-				*best_freq = freq_low;
-		}
-
-		pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
-			 freq->frequency, div, freq_high, div + 1, freq_low,
-			 *best_freq, best->frequency);
-
-		if (!error)
-			break;
-	}
-
-	if (parent_freq)
-		*parent_freq = best->frequency;
-
-	return error;
-}
-EXPORT_SYMBOL_GPL(clk_round_parent);
-
 #ifdef CONFIG_PM
 static void clks_core_resume(void)
 {
include/linux/sh_clk.h +0 -4
index 1f208b2a1ed6..645896b81244 100644
@@ -113,10 +113,6 @@ long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
 long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
 			       unsigned int mult_max, unsigned long rate);
 
-long clk_round_parent(struct clk *clk, unsigned long target,
-		      unsigned long *best_freq, unsigned long *parent_freq,
-		      unsigned int div_min, unsigned int div_max);
-
 #define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \
 {									\
 	.parent		= _parent,					\
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/2 drivers: sh: clk: Avoid crashes when passing NULL clocks

In reply to Simon Horman

From: Geert Uytterhoeven <[email protected]>

Several clock API functions handle NULL clocks when the Common Clock Framework is used, while their legacy SH counterparts don't, and would just crash when a NULL clock is passed.

Add NULL checks to clk_get_rate(), clk_set_rate(), clk_get_parent(), and clk_round_rate(), to avoid different behavior in drivers shared between legacy and CCF-based platforms.

---
 drivers/sh/clk/core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/sh/clk/core.c +12 -0
index 6bf973bd9654..92863e3818e5 100644
@@ -469,6 +469,9 @@ void clk_enable_init_clocks(void)
 
 unsigned long clk_get_rate(struct clk *clk)
 {
+	if (!clk)
+		return 0;
+
 	return clk->rate;
 }
 EXPORT_SYMBOL_GPL(clk_get_rate);
@@ -478,6 +481,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
 	int ret = -EOPNOTSUPP;
 	unsigned long flags;
 
+	if (!clk)
+		return 0;
+
 	spin_lock_irqsave(&clock_lock, flags);
 
 	if (likely(clk->ops && clk->ops->set_rate)) {
@@ -535,12 +541,18 @@ EXPORT_SYMBOL_GPL(clk_set_parent);
 
 struct clk *clk_get_parent(struct clk *clk)
 {
+	if (!clk)
+		return NULL;
+
 	return clk->parent;
 }
 EXPORT_SYMBOL_GPL(clk_get_parent);
 
 long clk_round_rate(struct clk *clk, unsigned long rate)
 {
+	if (!clk)
+		return 0;
+
 	if (likely(clk->ops && clk->ops->round_rate)) {
 		unsigned long flags, rounded;
 
Signature · 1 line
2.1.4