Stefan Roese | 4666990 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* define DEBUG for debugging output (obviously ;-)) */ |
| 25 | #if 0 |
| 26 | #define DEBUG |
| 27 | #endif |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <watchdog.h> |
| 31 | #include <command.h> |
| 32 | #include <asm/cache.h> |
| 33 | #include <ppc4xx.h> |
| 34 | |
| 35 | #if defined(CONFIG_OF_LIBFDT) |
| 36 | #include <libfdt.h> |
| 37 | #include <libfdt_env.h> |
| 38 | |
| 39 | static void do_fixup(void *fdt, const char *node, const char *prop, |
| 40 | const void *val, int len, int create) |
| 41 | { |
| 42 | #if defined(DEBUG) |
| 43 | int i; |
| 44 | debug("Updating property '%s/%s' = ", node, prop); |
| 45 | for (i = 0; i < len; i++) |
| 46 | debug(" %.2x", *(u8*)(val+i)); |
| 47 | debug("\n"); |
| 48 | #endif |
| 49 | int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create); |
| 50 | if (rc) |
| 51 | printf("Unable to update property %s:%s, err=%s\n", |
| 52 | node, prop, fdt_strerror(rc)); |
| 53 | } |
| 54 | |
| 55 | static void do_fixup_macaddr(void *fdt, int offset, const void *val, int i) |
| 56 | { |
| 57 | int rc; |
| 58 | |
| 59 | debug("Updating node EMAC%d\n", i); |
| 60 | |
| 61 | rc = fdt_setprop(fdt, offset, "mac-address", val, 6); |
| 62 | if (rc) |
| 63 | printf("Unable to update property %s, err=%s\n", |
| 64 | "mac-address", fdt_strerror(rc)); |
| 65 | rc = fdt_setprop(fdt, offset, "local-mac-address", val, 6); |
| 66 | if (rc) |
| 67 | printf("Unable to update property %s, err=%s\n", |
| 68 | "local-mac-address", fdt_strerror(rc)); |
| 69 | } |
| 70 | |
| 71 | static void do_fixup_u32(void *fdt, const char *node, const char *prop, |
| 72 | u32 val, int create) |
| 73 | { |
| 74 | val = cpu_to_fdt32(val); |
| 75 | do_fixup(fdt, node, prop, &val, sizeof(val), create); |
| 76 | } |
| 77 | |
| 78 | static void do_fixup_uart(void *fdt, int offset, int i, bd_t *bd) |
| 79 | { |
| 80 | int rc; |
| 81 | u32 val; |
| 82 | |
| 83 | debug("Updating node UART%d\n", i); |
| 84 | |
| 85 | val = cpu_to_fdt32(CFG_EXT_SERIAL_CLOCK); |
| 86 | rc = fdt_setprop(fdt, offset, "clock-frequency", &val, 4); |
| 87 | if (rc) |
| 88 | printf("Unable to update node UART, err=%s\n", fdt_strerror(rc)); |
| 89 | |
| 90 | val = cpu_to_fdt32(bd->bi_baudrate); |
| 91 | rc = fdt_setprop(fdt, offset, "current-speed", &val, 4); |
| 92 | if (rc) |
| 93 | printf("Unable to update node UART, err=%s\n", fdt_strerror(rc)); |
| 94 | } |
| 95 | |
| 96 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 97 | { |
| 98 | char * cpu_path = "/cpus/" OF_CPU; |
| 99 | sys_info_t sys_info; |
| 100 | int offset; |
| 101 | int i; |
| 102 | int tmp[2]; |
| 103 | |
| 104 | get_sys_info (&sys_info); |
| 105 | |
| 106 | do_fixup_u32(blob, cpu_path, "timebase-frequency", bd->bi_intfreq, 1); |
| 107 | do_fixup_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1); |
| 108 | do_fixup_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1); |
| 109 | do_fixup_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1); |
| 110 | do_fixup_u32(blob, "/plb/opb/ebc", "clock-frequency", sys_info.freqEBC, 1); |
| 111 | |
| 112 | /* update, or add and update /memory node */ |
| 113 | offset = fdt_find_node_by_path(blob, "/memory"); |
| 114 | if (offset < 0) { |
| 115 | offset = fdt_add_subnode(blob, 0, "memory"); |
| 116 | if (offset < 0) |
| 117 | debug("failed to add /memory node: %s\n", |
| 118 | fdt_strerror(offset)); |
| 119 | } |
| 120 | if (offset >= 0) { |
| 121 | fdt_setprop(blob, offset, "device_type", |
| 122 | "memory", sizeof("memory")); |
| 123 | tmp[0] = cpu_to_fdt32(bd->bi_memstart); |
| 124 | tmp[1] = cpu_to_fdt32(bd->bi_memsize); |
| 125 | fdt_setprop(blob, offset, "reg", tmp, sizeof(tmp)); |
Stefan Roese | ae2f5cd | 2007-10-11 11:11:45 +0200 | [diff] [blame] | 126 | debug("Updating /memory node to %d:%d\n", |
| 127 | bd->bi_memstart, bd->bi_memsize); |
Stefan Roese | 4666990 | 2007-10-05 17:07:50 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Setup all baudrates for the UARTs |
| 132 | */ |
| 133 | offset = 0; |
| 134 | for (i = 0; i < 4; i++) { |
| 135 | offset = fdt_find_node_by_type(blob, offset, "serial"); |
| 136 | if (offset < 0) |
| 137 | break; |
| 138 | |
| 139 | do_fixup_uart(blob, offset, i, bd); |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Setup all MAC addresses in fdt |
| 144 | */ |
| 145 | offset = 0; |
| 146 | for (i = 0; i < 4; i++) { |
| 147 | offset = fdt_find_node_by_type(blob, offset, "network"); |
| 148 | if (offset < 0) |
| 149 | break; |
| 150 | |
| 151 | switch (i) { |
| 152 | case 0: |
| 153 | do_fixup_macaddr(blob, offset, bd->bi_enetaddr, 0); |
| 154 | break; |
| 155 | #ifdef CONFIG_HAS_ETH1 |
| 156 | case 1: |
| 157 | do_fixup_macaddr(blob, offset, bd->bi_enet1addr, 1); |
| 158 | break; |
| 159 | #endif |
| 160 | #ifdef CONFIG_HAS_ETH2 |
| 161 | case 2: |
| 162 | do_fixup_macaddr(blob, offset, bd->bi_enet2addr, 2); |
| 163 | break; |
| 164 | #endif |
| 165 | #ifdef CONFIG_HAS_ETH3 |
| 166 | case 3: |
| 167 | do_fixup_macaddr(blob, offset, bd->bi_enet3addr, 3); |
| 168 | break; |
| 169 | #endif |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | #endif /* CONFIG_OF_LIBFDT */ |