}
 
 #if defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
+void ft_board_setup(void *blob, bd_t *bd)
 {
+#if defined(CONFIG_OF_FLAT_TREE)
+       u32 *p;
+       int len;
+
+       p = ft_get_prop(blob, "/memory/reg", &len);
+       if (p != NULL) {
+               *p++ = cpu_to_be32(bd->bi_memstart);
+               *p = cpu_to_be32(bd->bi_memsize);
+       }
+#endif
        ft_cpu_setup(blob, bd);
 #ifdef CONFIG_PCI
        ft_pci_setup(blob, bd);
 #endif
 }
-#endif /* CONFIG_OF_BOARD_SETUP */
+#endif
 
  */
 
 #include <common.h>
+#if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
+#endif
 #include <pci.h>
 #include <mpc83xx.h>
 
        mpc83xx_pci_init(1, reg, warmboot);
 }
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
+#if defined(CONFIG_OF_BOARD_SETUP)
 void ft_board_setup(void *blob, bd_t *bd)
 {
+#if defined(CONFIG_OF_FLAT_TREE)
        u32 *p;
        int len;
 
-#ifdef CONFIG_PCI
-       ft_pci_setup(blob, bd);
-#endif
-       ft_cpu_setup(blob, bd);
-
        p = ft_get_prop(blob, "/memory/reg", &len);
-       if (p) {
+       if (p != NULL) {
                *p++ = cpu_to_be32(bd->bi_memstart);
                *p = cpu_to_be32(bd->bi_memsize);
        }
+#endif
+       ft_cpu_setup(blob, bd);
+#ifdef CONFIG_PCI
+       ft_pci_setup(blob, bd);
+#endif
 }
 #endif
 
 #endif
 #if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
 #endif
 
 const qe_iop_conf_t qe_iop_conf_tab[] = {
        return 0;
 }
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
 {
+#if defined(CONFIG_OF_FLAT_TREE)
        u32 *p;
        int len;
 
-#ifdef CONFIG_PCI
-       ft_pci_setup(blob, bd);
-#endif
-       ft_cpu_setup(blob, bd);
-
        p = ft_get_prop(blob, "/memory/reg", &len);
        if (p != NULL) {
                *p++ = cpu_to_be32(bd->bi_memstart);
                *p = cpu_to_be32(bd->bi_memsize);
        }
+#endif
+       ft_cpu_setup(blob, bd);
+#ifdef CONFIG_PCI
+       ft_pci_setup(blob, bd);
+#endif
 }
 #endif
 
 #include <i2c.h>
 #if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
 #endif
 
 #include <asm/fsl_i2c.h>
 }
 #endif                         /* CONFIG_PCISLAVE */
 
-#ifdef CONFIG_OF_FLAT_TREE
+#if defined(CONFIG_OF_LIBFDT)
+void
+ft_pci_setup(void *blob, bd_t *bd)
+{
+       int nodeoffset;
+       int err;
+       int tmp[2];
+
+       nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
+       if (nodeoffset >= 0) {
+               tmp[0] = cpu_to_be32(hose[0].first_busno);
+               tmp[1] = cpu_to_be32(hose[0].last_busno);
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
+       }
+}
+#elif defined(CONFIG_OF_FLAT_TREE)
 void
 ft_pci_setup(void *blob, bd_t *bd)
 {
 
 #endif
 #if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
 #endif
 
 int fixed_sdram(void);
 }
 #endif
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
 {
+#if defined(CONFIG_OF_FLAT_TREE)
        u32 *p;
        int len;
 
-#ifdef CONFIG_PCI
-       ft_pci_setup(blob, bd);
-#endif
-       ft_cpu_setup(blob, bd);
-
        p = ft_get_prop(blob, "/memory/reg", &len);
        if (p != NULL) {
                *p++ = cpu_to_be32(bd->bi_memstart);
                *p = cpu_to_be32(bd->bi_memsize);
        }
+#endif
+       ft_cpu_setup(blob, bd);
+#ifdef CONFIG_PCI
+       ft_pci_setup(blob, bd);
+#endif
 }
 #endif
 
 #include <pci.h>
 #include <asm/mpc8349_pci.h>
 #include <i2c.h>
+#if defined(CONFIG_OF_FLAT_TREE)
+#include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
+#endif
+
 
 DECLARE_GLOBAL_DATA_PTR;
 
 
 }
 
-#ifdef CONFIG_OF_FLAT_TREE
+#if defined(CONFIG_OF_LIBFDT)
+void
+ft_pci_setup(void *blob, bd_t *bd)
+{
+       int nodeoffset;
+       int err;
+       int tmp[2];
+
+       nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
+       if (nodeoffset >= 0) {
+               tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
+               tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
+       }
+#ifdef CONFIG_MPC83XX_PCI2
+       nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8600");
+       if (nodeoffset >= 0) {
+               tmp[0] = cpu_to_be32(pci_hose[1].first_busno);
+               tmp[1] = cpu_to_be32(pci_hose[1].last_busno);
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
+       }
+#endif
+}
+#elif defined(CONFIG_OF_FLAT_TREE)
 void
 ft_pci_setup(void *blob, bd_t *bd)
 {
 
 #endif
 #if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
 #endif
 
 #ifndef CONFIG_SPD_EEPROM
        return rc;
 }
 
-#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
 {
+#if defined(CONFIG_OF_FLAT_TREE)
        u32 *p;
        int len;
 
-#ifdef CONFIG_PCI
-       ft_pci_setup(blob, bd);
-#endif
-       ft_cpu_setup(blob, bd);
-
        p = ft_get_prop(blob, "/memory/reg", &len);
        if (p != NULL) {
                *p++ = cpu_to_be32(bd->bi_memstart);
                *p = cpu_to_be32(bd->bi_memsize);
        }
+#endif
+       ft_cpu_setup(blob, bd);
+#ifdef CONFIG_PCI
+       ft_pci_setup(blob, bd);
+#endif
 }
 #endif
 
 #include <i2c.h>
 #if defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
+#elif defined(CONFIG_OF_LIBFDT)
+#include <libfdt.h>
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
 #endif
 }
 
-#endif                         /* CONFIG_PCI */
-#ifdef CONFIG_OF_FLAT_TREE
+#if defined(CONFIG_OF_LIBFDT)
+void
+ft_pci_setup(void *blob, bd_t *bd)
+{
+       int nodeoffset;
+       int err;
+       int tmp[2];
+
+       nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
+       if (nodeoffset >= 0) {
+               tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
+               tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
+       }
+#ifdef CONFIG_MPC83XX_PCI2
+       nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
+       if (nodeoffset >= 0) {
+               tmp[0] = cpu_to_be32(pci_hose[1].first_busno);
+               tmp[1] = cpu_to_be32(pci_hose[1].last_busno);
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
+       }
+#endif
+}
+#elif defined(CONFIG_OF_FLAT_TREE)
 void
 ft_pci_setup(void *blob, bd_t *bd)
 {
 #endif
 }
 #endif /* CONFIG_OF_FLAT_TREE */
+#endif /* CONFIG_PCI */
 
 }
 #endif
 
-#if (defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)) \
-     && defined(CONFIG_OF_BOARD_SETUP)
-void
-ft_board_setup(void *blob, bd_t *bd)
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
 {
 #if defined(CONFIG_OF_FLAT_TREE)
        u32 *p;
                *p = cpu_to_be32(bd->bi_memsize);
        }
 #endif
-
+       ft_cpu_setup(blob, bd);
 #ifdef CONFIG_PCI
        ft_pci_setup(blob, bd);
 #endif
-       ft_cpu_setup(blob, bd);
 }
-#endif /* CONFIG_OF_x */
+#endif
 
 
 #if defined(CONFIG_OF_LIBFDT)
 #include <libfdt.h>
-#include <libfdt_env.h>
 #elif defined(CONFIG_OF_FLAT_TREE)
 #include <ft_build.h>
 #endif
        if (nodeoffset >= 0) {
                tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
                tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
-               err = fdt_setprop(blob, nodeoffset, "bus-range", tmp, sizeof(tmp));
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
        }
 
        if (pci_num_buses < 2)
        if (nodeoffset >= 0) {
                tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
                tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
-               err = fdt_setprop(blob, nodeoffset, "bus-range", tmp, sizeof(tmp));
+               err = fdt_setprop(blob, nodeoffset, "bus-range",
+                                 tmp, sizeof(tmp));
+
+               tmp[0] = cpu_to_be32(gd->pci_clk);
+               err = fdt_setprop(blob, nodeoffset, "clock-frequency",
+                                 tmp, sizeof(tmp[0]));
        }
 }
 #elif CONFIG_OF_FLAT_TREE