linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
@ 2008-04-15 18:52 Scott Wood
  2008-04-15 21:32 ` Anton Vorontsov
  2008-04-15 23:20 ` Kumar Gala
  0 siblings, 2 replies; 6+ messages in thread
From: Scott Wood @ 2008-04-15 18:52 UTC (permalink / raw)
  To: galak; +Cc: linuxppc-dev

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
 arch/powerpc/sysdev/fsl_soc.c |   70 ++++++++++++++++++----------------------
 arch/powerpc/sysdev/fsl_soc.h |    1 +
 2 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 642e45e..b6d6bda 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -75,6 +75,33 @@ phys_addr_t get_immrbase(void)
 
 EXPORT_SYMBOL(get_immrbase);
 
+static u32 sysfreq = -1;
+
+u32 fsl_get_sys_freq(void)
+{
+	struct device_node *soc;
+	const u32 *prop;
+	int size;
+
+	if (sysfreq != -1)
+		return sysfreq;
+
+	soc = of_find_node_by_type(NULL, "soc");
+	if (!soc)
+		return -1;
+
+	prop = of_get_property(soc, "clock-frequency", &size);
+	if (!prop || size != sizeof(*prop) || *prop == 0)
+		prop = of_get_property(soc, "bus-frequency", &size);
+
+	if (prop && size == sizeof(*prop))
+		sysfreq = *prop;
+
+	of_node_put(soc);
+	return sysfreq;
+}
+EXPORT_SYMBOL(fsl_get_sys_freq);
+
 #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
 
 static u32 brgfreq = -1;
@@ -516,9 +543,9 @@ arch_initcall(fsl_i2c_of_init);
 static int __init mpc83xx_wdt_init(void)
 {
 	struct resource r;
-	struct device_node *soc, *np;
+	struct device_node *np;
 	struct platform_device *dev;
-	const unsigned int *freq;
+	u32 freq = fsl_get_sys_freq();
 	int ret;
 
 	np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
@@ -528,19 +555,6 @@ static int __init mpc83xx_wdt_init(void)
 		goto nodev;
 	}
 
-	soc = of_find_node_by_type(NULL, "soc");
-
-	if (!soc) {
-		ret = -ENODEV;
-		goto nosoc;
-	}
-
-	freq = of_get_property(soc, "bus-frequency", NULL);
-	if (!freq) {
-		ret = -ENODEV;
-		goto err;
-	}
-
 	memset(&r, 0, sizeof(r));
 
 	ret = of_address_to_resource(np, 0, &r);
@@ -553,20 +567,16 @@ static int __init mpc83xx_wdt_init(void)
 		goto err;
 	}
 
-	ret = platform_device_add_data(dev, freq, sizeof(int));
+	ret = platform_device_add_data(dev, &freq, sizeof(freq));
 	if (ret)
 		goto unreg;
 
-	of_node_put(soc);
 	of_node_put(np);
-
 	return 0;
 
 unreg:
 	platform_device_unregister(dev);
 err:
-	of_node_put(soc);
-nosoc:
 	of_node_put(np);
 nodev:
 	return ret;
@@ -830,25 +840,9 @@ int __init fsl_spi_init(struct spi_board_info *board_infos,
 	sysclk = get_brgfreq();
 #endif
 	if (sysclk == -1) {
-		struct device_node *np;
-		const u32 *freq;
-		int size;
-
-		np = of_find_node_by_type(NULL, "soc");
-		if (!np)
+		sysclk = fsl_get_sys_freq();
+		if (sysclk == -1)
 			return -ENODEV;
-
-		freq = of_get_property(np, "clock-frequency", &size);
-		if (!freq || size != sizeof(*freq) || *freq == 0) {
-			freq = of_get_property(np, "bus-frequency", &size);
-			if (!freq || size != sizeof(*freq) || *freq == 0) {
-				of_node_put(np);
-				return -ENODEV;
-			}
-		}
-
-		sysclk = *freq;
-		of_node_put(np);
 	}
 
 	ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h
index 63e7db3..74c4a96 100644
--- a/arch/powerpc/sysdev/fsl_soc.h
+++ b/arch/powerpc/sysdev/fsl_soc.h
@@ -7,6 +7,7 @@
 extern phys_addr_t get_immrbase(void);
 extern u32 get_brgfreq(void);
 extern u32 get_baudrate(void);
+extern u32 fsl_get_sys_freq(void);
 
 struct spi_board_info;
 
-- 
1.5.4.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
  2008-04-15 18:52 [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits Scott Wood
@ 2008-04-15 21:32 ` Anton Vorontsov
  2008-04-15 21:35   ` Scott Wood
  2008-04-15 23:20 ` Kumar Gala
  1 sibling, 1 reply; 6+ messages in thread
From: Anton Vorontsov @ 2008-04-15 21:32 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev

On Tue, Apr 15, 2008 at 01:52:34PM -0500, Scott Wood wrote:
> Signed-off-by: Scott Wood <scottwood@freescale.com>
> ---
>  arch/powerpc/sysdev/fsl_soc.c |   70 ++++++++++++++++++----------------------
>  arch/powerpc/sysdev/fsl_soc.h |    1 +
>  2 files changed, 33 insertions(+), 38 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
> index 642e45e..b6d6bda 100644
> --- a/arch/powerpc/sysdev/fsl_soc.c
> +++ b/arch/powerpc/sysdev/fsl_soc.c
> @@ -75,6 +75,33 @@ phys_addr_t get_immrbase(void)
>  
>  EXPORT_SYMBOL(get_immrbase);
>  
> +static u32 sysfreq = -1;
> +
> +u32 fsl_get_sys_freq(void)
> +{
> +	struct device_node *soc;
> +	const u32 *prop;
> +	int size;
> +
> +	if (sysfreq != -1)
> +		return sysfreq;
> +
> +	soc = of_find_node_by_type(NULL, "soc");
> +	if (!soc)
> +		return -1;

Um.. can we finally decide on compatible for the soc nodes,
and add there compatible matching from the start?

> +
> +	prop = of_get_property(soc, "clock-frequency", &size);
> +	if (!prop || size != sizeof(*prop) || *prop == 0)
> +		prop = of_get_property(soc, "bus-frequency", &size);
> +
> +	if (prop && size == sizeof(*prop))
> +		sysfreq = *prop;
> +
> +	of_node_put(soc);
> +	return sysfreq;
> +}
> +EXPORT_SYMBOL(fsl_get_sys_freq);
> +
>  #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
>  
>  static u32 brgfreq = -1;
> @@ -516,9 +543,9 @@ arch_initcall(fsl_i2c_of_init);
>  static int __init mpc83xx_wdt_init(void)
>  {
>  	struct resource r;
> -	struct device_node *soc, *np;
> +	struct device_node *np;
>  	struct platform_device *dev;
> -	const unsigned int *freq;
> +	u32 freq = fsl_get_sys_freq();
>  	int ret;
>  
>  	np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
> @@ -528,19 +555,6 @@ static int __init mpc83xx_wdt_init(void)
>  		goto nodev;
>  	}
>  
> -	soc = of_find_node_by_type(NULL, "soc");
> -
> -	if (!soc) {
> -		ret = -ENODEV;
> -		goto nosoc;
> -	}
> -
> -	freq = of_get_property(soc, "bus-frequency", NULL);
> -	if (!freq) {
> -		ret = -ENODEV;
> -		goto err;
> -	}
> -
>  	memset(&r, 0, sizeof(r));
>  
>  	ret = of_address_to_resource(np, 0, &r);
> @@ -553,20 +567,16 @@ static int __init mpc83xx_wdt_init(void)
>  		goto err;
>  	}
>  
> -	ret = platform_device_add_data(dev, freq, sizeof(int));
> +	ret = platform_device_add_data(dev, &freq, sizeof(freq));
>  	if (ret)
>  		goto unreg;
>  
> -	of_node_put(soc);
>  	of_node_put(np);
> -
>  	return 0;
>  
>  unreg:
>  	platform_device_unregister(dev);
>  err:
> -	of_node_put(soc);
> -nosoc:
>  	of_node_put(np);
>  nodev:
>  	return ret;
> @@ -830,25 +840,9 @@ int __init fsl_spi_init(struct spi_board_info *board_infos,
>  	sysclk = get_brgfreq();
>  #endif
>  	if (sysclk == -1) {
> -		struct device_node *np;
> -		const u32 *freq;
> -		int size;
> -
> -		np = of_find_node_by_type(NULL, "soc");
> -		if (!np)
> +		sysclk = fsl_get_sys_freq();
> +		if (sysclk == -1)
>  			return -ENODEV;
> -
> -		freq = of_get_property(np, "clock-frequency", &size);
> -		if (!freq || size != sizeof(*freq) || *freq == 0) {
> -			freq = of_get_property(np, "bus-frequency", &size);
> -			if (!freq || size != sizeof(*freq) || *freq == 0) {
> -				of_node_put(np);
> -				return -ENODEV;
> -			}
> -		}
> -
> -		sysclk = *freq;
> -		of_node_put(np);
>  	}
>  
>  	ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
> diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h
> index 63e7db3..74c4a96 100644
> --- a/arch/powerpc/sysdev/fsl_soc.h
> +++ b/arch/powerpc/sysdev/fsl_soc.h
> @@ -7,6 +7,7 @@
>  extern phys_addr_t get_immrbase(void);
>  extern u32 get_brgfreq(void);
>  extern u32 get_baudrate(void);
> +extern u32 fsl_get_sys_freq(void);
>  
>  struct spi_board_info;

-- 
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
  2008-04-15 21:32 ` Anton Vorontsov
@ 2008-04-15 21:35   ` Scott Wood
  2008-04-15 21:52     ` Kumar Gala
  2008-04-16 14:02     ` Anton Vorontsov
  0 siblings, 2 replies; 6+ messages in thread
From: Scott Wood @ 2008-04-15 21:35 UTC (permalink / raw)
  To: cbouatmailru; +Cc: linuxppc-dev

Anton Vorontsov wrote:
>> +u32 fsl_get_sys_freq(void)
>> +{
>> +	struct device_node *soc;
>> +	const u32 *prop;
>> +	int size;
>> +
>> +	if (sysfreq != -1)
>> +		return sysfreq;
>> +
>> +	soc = of_find_node_by_type(NULL, "soc");
>> +	if (!soc)
>> +		return -1;
> 
> Um.. can we finally decide on compatible for the soc nodes,
> and add there compatible matching from the start?

This is just a code reorganization; any change in what we match on 
should be a separate patch.

-Scott

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
  2008-04-15 21:35   ` Scott Wood
@ 2008-04-15 21:52     ` Kumar Gala
  2008-04-16 14:02     ` Anton Vorontsov
  1 sibling, 0 replies; 6+ messages in thread
From: Kumar Gala @ 2008-04-15 21:52 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev


On Apr 15, 2008, at 4:35 PM, Scott Wood wrote:
> Anton Vorontsov wrote:
>>> +u32 fsl_get_sys_freq(void)
>>> +{
>>> +	struct device_node *soc;
>>> +	const u32 *prop;
>>> +	int size;
>>> +
>>> +	if (sysfreq != -1)
>>> +		return sysfreq;
>>> +
>>> +	soc = of_find_node_by_type(NULL, "soc");
>>> +	if (!soc)
>>> +		return -1;
>> Um.. can we finally decide on compatible for the soc nodes,
>> and add there compatible matching from the start?
>
> This is just a code reorganization; any change in what we match on  
> should be a separate patch.

I agree and Scott has posted a version of this long ago.

- k

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
  2008-04-15 18:52 [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits Scott Wood
  2008-04-15 21:32 ` Anton Vorontsov
@ 2008-04-15 23:20 ` Kumar Gala
  1 sibling, 0 replies; 6+ messages in thread
From: Kumar Gala @ 2008-04-15 23:20 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev


On Apr 15, 2008, at 1:52 PM, Scott Wood wrote:
> Signed-off-by: Scott Wood <scottwood@freescale.com>
> ---
> arch/powerpc/sysdev/fsl_soc.c |   70 +++++++++++++++++ 
> +----------------------
> arch/powerpc/sysdev/fsl_soc.h |    1 +
> 2 files changed, 33 insertions(+), 38 deletions(-)

applied.

- k

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
  2008-04-15 21:35   ` Scott Wood
  2008-04-15 21:52     ` Kumar Gala
@ 2008-04-16 14:02     ` Anton Vorontsov
  1 sibling, 0 replies; 6+ messages in thread
From: Anton Vorontsov @ 2008-04-16 14:02 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev

On Tue, Apr 15, 2008 at 04:35:54PM -0500, Scott Wood wrote:
> Anton Vorontsov wrote:
>>> +u32 fsl_get_sys_freq(void)
>>> +{
>>> +	struct device_node *soc;
>>> +	const u32 *prop;
>>> +	int size;
>>> +
>>> +	if (sysfreq != -1)
>>> +		return sysfreq;
>>> +
>>> +	soc = of_find_node_by_type(NULL, "soc");
>>> +	if (!soc)
>>> +		return -1;
>>
>> Um.. can we finally decide on compatible for the soc nodes,
>> and add there compatible matching from the start?
>
> This is just a code reorganization; any change in what we match on  
> should be a separate patch.

Yes, it makes sense of course. Just wanted to get rid of the device_type
asap, because I'm going to submit mpc836x_rdk board, and I'd preferred to
submit it w/o device_type = "soc"... Oh well, ok.. later.

-- 
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-04-16 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-15 18:52 [PATCH] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits Scott Wood
2008-04-15 21:32 ` Anton Vorontsov
2008-04-15 21:35   ` Scott Wood
2008-04-15 21:52     ` Kumar Gala
2008-04-16 14:02     ` Anton Vorontsov
2008-04-15 23:20 ` Kumar Gala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).