Commit 38664095 authored by Scott Wood's avatar Scott Wood Committed by Kumar Gala

[POWERPC] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.

Signed-off-by: default avatarScott Wood <scottwood@freescale.com>
Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent 9c432797
...@@ -75,6 +75,33 @@ phys_addr_t get_immrbase(void) ...@@ -75,6 +75,33 @@ phys_addr_t get_immrbase(void)
EXPORT_SYMBOL(get_immrbase); 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) #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
static u32 brgfreq = -1; static u32 brgfreq = -1;
...@@ -516,9 +543,9 @@ arch_initcall(fsl_i2c_of_init); ...@@ -516,9 +543,9 @@ arch_initcall(fsl_i2c_of_init);
static int __init mpc83xx_wdt_init(void) static int __init mpc83xx_wdt_init(void)
{ {
struct resource r; struct resource r;
struct device_node *soc, *np; struct device_node *np;
struct platform_device *dev; struct platform_device *dev;
const unsigned int *freq; u32 freq = fsl_get_sys_freq();
int ret; int ret;
np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
...@@ -528,19 +555,6 @@ static int __init mpc83xx_wdt_init(void) ...@@ -528,19 +555,6 @@ static int __init mpc83xx_wdt_init(void)
goto nodev; 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)); memset(&r, 0, sizeof(r));
ret = of_address_to_resource(np, 0, &r); ret = of_address_to_resource(np, 0, &r);
...@@ -553,20 +567,16 @@ static int __init mpc83xx_wdt_init(void) ...@@ -553,20 +567,16 @@ static int __init mpc83xx_wdt_init(void)
goto err; goto err;
} }
ret = platform_device_add_data(dev, freq, sizeof(int)); ret = platform_device_add_data(dev, &freq, sizeof(freq));
if (ret) if (ret)
goto unreg; goto unreg;
of_node_put(soc);
of_node_put(np); of_node_put(np);
return 0; return 0;
unreg: unreg:
platform_device_unregister(dev); platform_device_unregister(dev);
err: err:
of_node_put(soc);
nosoc:
of_node_put(np); of_node_put(np);
nodev: nodev:
return ret; return ret;
...@@ -830,25 +840,9 @@ int __init fsl_spi_init(struct spi_board_info *board_infos, ...@@ -830,25 +840,9 @@ int __init fsl_spi_init(struct spi_board_info *board_infos,
sysclk = get_brgfreq(); sysclk = get_brgfreq();
#endif #endif
if (sysclk == -1) { if (sysclk == -1) {
struct device_node *np; sysclk = fsl_get_sys_freq();
const u32 *freq; if (sysclk == -1)
int size;
np = of_find_node_by_type(NULL, "soc");
if (!np)
return -ENODEV; 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, ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
extern phys_addr_t get_immrbase(void); extern phys_addr_t get_immrbase(void);
extern u32 get_brgfreq(void); extern u32 get_brgfreq(void);
extern u32 get_baudrate(void); extern u32 get_baudrate(void);
extern u32 fsl_get_sys_freq(void);
struct spi_board_info; struct spi_board_info;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment