diff options
author | Scott Wood <scottwood@freescale.com> | 2008-04-15 14:52:34 -0400 |
---|---|---|
committer | Kumar Gala <galak@kernel.crashing.org> | 2008-04-17 02:01:40 -0400 |
commit | 3866409541b1ae87a2e42ee7f483843f1af56917 (patch) | |
tree | ff1a3f4a8f4d9540a8791db22d5b04bc5b7b1482 /arch | |
parent | 9c432797d30ffd10d5510854a0f762dc42903898 (diff) |
[POWERPC] fsl_soc: Factor fsl_get_sys_freq() out of the wdt and spi inits.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/sysdev/fsl_soc.c | 70 | ||||
-rw-r--r-- | 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 642e45e1f160..b6d6bdae95f2 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) | |||
75 | 75 | ||
76 | EXPORT_SYMBOL(get_immrbase); | 76 | EXPORT_SYMBOL(get_immrbase); |
77 | 77 | ||
78 | static u32 sysfreq = -1; | ||
79 | |||
80 | u32 fsl_get_sys_freq(void) | ||
81 | { | ||
82 | struct device_node *soc; | ||
83 | const u32 *prop; | ||
84 | int size; | ||
85 | |||
86 | if (sysfreq != -1) | ||
87 | return sysfreq; | ||
88 | |||
89 | soc = of_find_node_by_type(NULL, "soc"); | ||
90 | if (!soc) | ||
91 | return -1; | ||
92 | |||
93 | prop = of_get_property(soc, "clock-frequency", &size); | ||
94 | if (!prop || size != sizeof(*prop) || *prop == 0) | ||
95 | prop = of_get_property(soc, "bus-frequency", &size); | ||
96 | |||
97 | if (prop && size == sizeof(*prop)) | ||
98 | sysfreq = *prop; | ||
99 | |||
100 | of_node_put(soc); | ||
101 | return sysfreq; | ||
102 | } | ||
103 | EXPORT_SYMBOL(fsl_get_sys_freq); | ||
104 | |||
78 | #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx) | 105 | #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx) |
79 | 106 | ||
80 | static u32 brgfreq = -1; | 107 | static u32 brgfreq = -1; |
@@ -516,9 +543,9 @@ arch_initcall(fsl_i2c_of_init); | |||
516 | static int __init mpc83xx_wdt_init(void) | 543 | static int __init mpc83xx_wdt_init(void) |
517 | { | 544 | { |
518 | struct resource r; | 545 | struct resource r; |
519 | struct device_node *soc, *np; | 546 | struct device_node *np; |
520 | struct platform_device *dev; | 547 | struct platform_device *dev; |
521 | const unsigned int *freq; | 548 | u32 freq = fsl_get_sys_freq(); |
522 | int ret; | 549 | int ret; |
523 | 550 | ||
524 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); | 551 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
@@ -528,19 +555,6 @@ static int __init mpc83xx_wdt_init(void) | |||
528 | goto nodev; | 555 | goto nodev; |
529 | } | 556 | } |
530 | 557 | ||
531 | soc = of_find_node_by_type(NULL, "soc"); | ||
532 | |||
533 | if (!soc) { | ||
534 | ret = -ENODEV; | ||
535 | goto nosoc; | ||
536 | } | ||
537 | |||
538 | freq = of_get_property(soc, "bus-frequency", NULL); | ||
539 | if (!freq) { | ||
540 | ret = -ENODEV; | ||
541 | goto err; | ||
542 | } | ||
543 | |||
544 | memset(&r, 0, sizeof(r)); | 558 | memset(&r, 0, sizeof(r)); |
545 | 559 | ||
546 | ret = of_address_to_resource(np, 0, &r); | 560 | ret = of_address_to_resource(np, 0, &r); |
@@ -553,20 +567,16 @@ static int __init mpc83xx_wdt_init(void) | |||
553 | goto err; | 567 | goto err; |
554 | } | 568 | } |
555 | 569 | ||
556 | ret = platform_device_add_data(dev, freq, sizeof(int)); | 570 | ret = platform_device_add_data(dev, &freq, sizeof(freq)); |
557 | if (ret) | 571 | if (ret) |
558 | goto unreg; | 572 | goto unreg; |
559 | 573 | ||
560 | of_node_put(soc); | ||
561 | of_node_put(np); | 574 | of_node_put(np); |
562 | |||
563 | return 0; | 575 | return 0; |
564 | 576 | ||
565 | unreg: | 577 | unreg: |
566 | platform_device_unregister(dev); | 578 | platform_device_unregister(dev); |
567 | err: | 579 | err: |
568 | of_node_put(soc); | ||
569 | nosoc: | ||
570 | of_node_put(np); | 580 | of_node_put(np); |
571 | nodev: | 581 | nodev: |
572 | return ret; | 582 | return ret; |
@@ -830,25 +840,9 @@ int __init fsl_spi_init(struct spi_board_info *board_infos, | |||
830 | sysclk = get_brgfreq(); | 840 | sysclk = get_brgfreq(); |
831 | #endif | 841 | #endif |
832 | if (sysclk == -1) { | 842 | if (sysclk == -1) { |
833 | struct device_node *np; | 843 | sysclk = fsl_get_sys_freq(); |
834 | const u32 *freq; | 844 | if (sysclk == -1) |
835 | int size; | ||
836 | |||
837 | np = of_find_node_by_type(NULL, "soc"); | ||
838 | if (!np) | ||
839 | return -ENODEV; | 845 | return -ENODEV; |
840 | |||
841 | freq = of_get_property(np, "clock-frequency", &size); | ||
842 | if (!freq || size != sizeof(*freq) || *freq == 0) { | ||
843 | freq = of_get_property(np, "bus-frequency", &size); | ||
844 | if (!freq || size != sizeof(*freq) || *freq == 0) { | ||
845 | of_node_put(np); | ||
846 | return -ENODEV; | ||
847 | } | ||
848 | } | ||
849 | |||
850 | sysclk = *freq; | ||
851 | of_node_put(np); | ||
852 | } | 846 | } |
853 | 847 | ||
854 | ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos, | 848 | 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 63e7db30a4cd..74c4a9657b33 100644 --- a/arch/powerpc/sysdev/fsl_soc.h +++ b/arch/powerpc/sysdev/fsl_soc.h | |||
@@ -7,6 +7,7 @@ | |||
7 | extern phys_addr_t get_immrbase(void); | 7 | extern phys_addr_t get_immrbase(void); |
8 | extern u32 get_brgfreq(void); | 8 | extern u32 get_brgfreq(void); |
9 | extern u32 get_baudrate(void); | 9 | extern u32 get_baudrate(void); |
10 | extern u32 fsl_get_sys_freq(void); | ||
10 | 11 | ||
11 | struct spi_board_info; | 12 | struct spi_board_info; |
12 | 13 | ||