Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 1 | /* |
| 2 | * FSL SoC setup code |
| 3 | * |
| 4 | * Maintained by Kumar Gala (see MAINTAINERS for contact information) |
| 5 | * |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 6 | * 2006 (c) MontaVista Software, Inc. |
| 7 | * Vitaly Bordug <vbordug@ru.mvista.com> |
| 8 | * |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | */ |
| 14 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 15 | #include <linux/stddef.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/major.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/irq.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/platform_device.h> |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 25 | #include <linux/phy.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 26 | #include <linux/fsl_devices.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 27 | #include <linux/fs_enet_pd.h> |
| 28 | #include <linux/fs_uart_pd.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 29 | |
| 30 | #include <asm/system.h> |
| 31 | #include <asm/atomic.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/irq.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 34 | #include <asm/time.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 35 | #include <asm/prom.h> |
| 36 | #include <sysdev/fsl_soc.h> |
| 37 | #include <mm/mmu_decl.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 38 | #include <asm/cpm2.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 39 | |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 40 | extern void init_fcc_ioports(struct fs_platform_info*); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 41 | extern void init_fec_ioports(struct fs_platform_info*); |
| 42 | extern void init_smc_ioports(struct fs_uart_platform_info*); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 43 | static phys_addr_t immrbase = -1; |
| 44 | |
| 45 | phys_addr_t get_immrbase(void) |
| 46 | { |
| 47 | struct device_node *soc; |
| 48 | |
| 49 | if (immrbase != -1) |
| 50 | return immrbase; |
| 51 | |
| 52 | soc = of_find_node_by_type(NULL, "soc"); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 53 | if (soc) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 54 | unsigned int size; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 55 | const void *prop = get_property(soc, "reg", &size); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 56 | |
| 57 | if (prop) |
| 58 | immrbase = of_translate_address(soc, prop); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 59 | of_node_put(soc); |
| 60 | }; |
| 61 | |
| 62 | return immrbase; |
| 63 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 64 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 65 | EXPORT_SYMBOL(get_immrbase); |
| 66 | |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 67 | #if defined(CONFIG_CPM2) || defined(CONFIG_8xx) |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 68 | |
| 69 | static u32 brgfreq = -1; |
| 70 | |
| 71 | u32 get_brgfreq(void) |
| 72 | { |
| 73 | struct device_node *node; |
| 74 | |
| 75 | if (brgfreq != -1) |
| 76 | return brgfreq; |
| 77 | |
| 78 | node = of_find_node_by_type(NULL, "cpm"); |
| 79 | if (node) { |
| 80 | unsigned int size; |
| 81 | const unsigned int *prop = get_property(node, "brg-frequency", |
| 82 | &size); |
| 83 | |
| 84 | if (prop) |
| 85 | brgfreq = *prop; |
| 86 | of_node_put(node); |
| 87 | }; |
| 88 | |
| 89 | return brgfreq; |
| 90 | } |
| 91 | |
| 92 | EXPORT_SYMBOL(get_brgfreq); |
| 93 | |
| 94 | static u32 fs_baudrate = -1; |
| 95 | |
| 96 | u32 get_baudrate(void) |
| 97 | { |
| 98 | struct device_node *node; |
| 99 | |
| 100 | if (fs_baudrate != -1) |
| 101 | return fs_baudrate; |
| 102 | |
| 103 | node = of_find_node_by_type(NULL, "serial"); |
| 104 | if (node) { |
| 105 | unsigned int size; |
| 106 | const unsigned int *prop = get_property(node, "current-speed", |
| 107 | &size); |
| 108 | |
| 109 | if (prop) |
| 110 | fs_baudrate = *prop; |
| 111 | of_node_put(node); |
| 112 | }; |
| 113 | |
| 114 | return fs_baudrate; |
| 115 | } |
| 116 | |
| 117 | EXPORT_SYMBOL(get_baudrate); |
| 118 | #endif /* CONFIG_CPM2 */ |
| 119 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 120 | static int __init gfar_mdio_of_init(void) |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 121 | { |
| 122 | struct device_node *np; |
| 123 | unsigned int i; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 124 | struct platform_device *mdio_dev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 125 | struct resource res; |
| 126 | int ret; |
| 127 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 128 | for (np = NULL, i = 0; |
| 129 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; |
| 130 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 131 | int k; |
| 132 | struct device_node *child = NULL; |
| 133 | struct gianfar_mdio_data mdio_data; |
| 134 | |
| 135 | memset(&res, 0, sizeof(res)); |
| 136 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 137 | |
| 138 | ret = of_address_to_resource(np, 0, &res); |
| 139 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 140 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 141 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 142 | mdio_dev = |
| 143 | platform_device_register_simple("fsl-gianfar_mdio", |
| 144 | res.start, &res, 1); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 145 | if (IS_ERR(mdio_dev)) { |
| 146 | ret = PTR_ERR(mdio_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 147 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | for (k = 0; k < 32; k++) |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 151 | mdio_data.irq[k] = PHY_POLL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 152 | |
| 153 | while ((child = of_get_next_child(np, child)) != NULL) { |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 154 | int irq = irq_of_parse_and_map(child, 0); |
| 155 | if (irq != NO_IRQ) { |
| 156 | const u32 *id = get_property(child, "reg", NULL); |
| 157 | mdio_data.irq[*id] = irq; |
| 158 | } |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 159 | } |
| 160 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 161 | ret = |
| 162 | platform_device_add_data(mdio_dev, &mdio_data, |
| 163 | sizeof(struct gianfar_mdio_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 164 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 165 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 166 | } |
| 167 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 168 | return 0; |
| 169 | |
| 170 | unreg: |
| 171 | platform_device_unregister(mdio_dev); |
| 172 | err: |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | arch_initcall(gfar_mdio_of_init); |
| 177 | |
| 178 | static const char *gfar_tx_intr = "tx"; |
| 179 | static const char *gfar_rx_intr = "rx"; |
| 180 | static const char *gfar_err_intr = "error"; |
| 181 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 182 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 183 | static int __init gfar_of_init(void) |
| 184 | { |
| 185 | struct device_node *np; |
| 186 | unsigned int i; |
| 187 | struct platform_device *gfar_dev; |
| 188 | struct resource res; |
| 189 | int ret; |
| 190 | |
| 191 | for (np = NULL, i = 0; |
| 192 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; |
| 193 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 194 | struct resource r[4]; |
| 195 | struct device_node *phy, *mdio; |
| 196 | struct gianfar_platform_data gfar_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 197 | const unsigned int *id; |
| 198 | const char *model; |
| 199 | const void *mac_addr; |
| 200 | const phandle *ph; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 201 | int n_res = 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 202 | |
| 203 | memset(r, 0, sizeof(r)); |
| 204 | memset(&gfar_data, 0, sizeof(gfar_data)); |
| 205 | |
| 206 | ret = of_address_to_resource(np, 0, &r[0]); |
| 207 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 208 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 209 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 210 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 211 | |
| 212 | model = get_property(np, "model", NULL); |
| 213 | |
| 214 | /* If we aren't the FEC we have multiple interrupts */ |
| 215 | if (model && strcasecmp(model, "FEC")) { |
| 216 | r[1].name = gfar_tx_intr; |
| 217 | |
| 218 | r[2].name = gfar_rx_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 219 | of_irq_to_resource(np, 1, &r[2]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 220 | |
| 221 | r[3].name = gfar_err_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 222 | of_irq_to_resource(np, 2, &r[3]); |
Jon Loeliger | 919fede | 2006-07-31 15:35:41 -0500 | [diff] [blame] | 223 | |
| 224 | n_res += 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 225 | } |
| 226 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 227 | gfar_dev = |
| 228 | platform_device_register_simple("fsl-gianfar", i, &r[0], |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 229 | n_res); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 230 | |
| 231 | if (IS_ERR(gfar_dev)) { |
| 232 | ret = PTR_ERR(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 233 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 234 | } |
| 235 | |
Jon Loeliger | f583165 | 2006-08-17 08:42:35 -0500 | [diff] [blame] | 236 | mac_addr = get_property(np, "local-mac-address", NULL); |
| 237 | if (mac_addr == NULL) |
| 238 | mac_addr = get_property(np, "mac-address", NULL); |
| 239 | if (mac_addr == NULL) { |
| 240 | /* Obsolete */ |
| 241 | mac_addr = get_property(np, "address", NULL); |
| 242 | } |
| 243 | |
| 244 | if (mac_addr) |
| 245 | memcpy(gfar_data.mac_addr, mac_addr, 6); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 246 | |
| 247 | if (model && !strcasecmp(model, "TSEC")) |
| 248 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 249 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 250 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 251 | FSL_GIANFAR_DEV_HAS_RMON | |
| 252 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 253 | if (model && !strcasecmp(model, "eTSEC")) |
| 254 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 255 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 256 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 257 | FSL_GIANFAR_DEV_HAS_RMON | |
| 258 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
| 259 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 260 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 261 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 262 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 263 | ph = get_property(np, "phy-handle", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 264 | phy = of_find_node_by_phandle(*ph); |
| 265 | |
| 266 | if (phy == NULL) { |
| 267 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 268 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | mdio = of_get_parent(phy); |
| 272 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 273 | id = get_property(phy, "reg", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 274 | ret = of_address_to_resource(mdio, 0, &res); |
| 275 | if (ret) { |
| 276 | of_node_put(phy); |
| 277 | of_node_put(mdio); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 278 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | gfar_data.phy_id = *id; |
| 282 | gfar_data.bus_id = res.start; |
| 283 | |
| 284 | of_node_put(phy); |
| 285 | of_node_put(mdio); |
| 286 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 287 | ret = |
| 288 | platform_device_add_data(gfar_dev, &gfar_data, |
| 289 | sizeof(struct |
| 290 | gianfar_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 291 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 292 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | return 0; |
| 296 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 297 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 298 | platform_device_unregister(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 299 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 300 | return ret; |
| 301 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 302 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 303 | arch_initcall(gfar_of_init); |
| 304 | |
| 305 | static int __init fsl_i2c_of_init(void) |
| 306 | { |
| 307 | struct device_node *np; |
| 308 | unsigned int i; |
| 309 | struct platform_device *i2c_dev; |
| 310 | int ret; |
| 311 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 312 | for (np = NULL, i = 0; |
| 313 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; |
| 314 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 315 | struct resource r[2]; |
| 316 | struct fsl_i2c_platform_data i2c_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 317 | const unsigned char *flags = NULL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 318 | |
| 319 | memset(&r, 0, sizeof(r)); |
| 320 | memset(&i2c_data, 0, sizeof(i2c_data)); |
| 321 | |
| 322 | ret = of_address_to_resource(np, 0, &r[0]); |
| 323 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 324 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 325 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 326 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 327 | |
| 328 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); |
| 329 | if (IS_ERR(i2c_dev)) { |
| 330 | ret = PTR_ERR(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 331 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | i2c_data.device_flags = 0; |
| 335 | flags = get_property(np, "dfsrr", NULL); |
| 336 | if (flags) |
| 337 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; |
| 338 | |
| 339 | flags = get_property(np, "fsl5200-clocking", NULL); |
| 340 | if (flags) |
| 341 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; |
| 342 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 343 | ret = |
| 344 | platform_device_add_data(i2c_dev, &i2c_data, |
| 345 | sizeof(struct |
| 346 | fsl_i2c_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 347 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 348 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | return 0; |
| 352 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 353 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 354 | platform_device_unregister(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 355 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 356 | return ret; |
| 357 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 358 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 359 | arch_initcall(fsl_i2c_of_init); |
| 360 | |
| 361 | #ifdef CONFIG_PPC_83xx |
| 362 | static int __init mpc83xx_wdt_init(void) |
| 363 | { |
| 364 | struct resource r; |
| 365 | struct device_node *soc, *np; |
| 366 | struct platform_device *dev; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 367 | const unsigned int *freq; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 368 | int ret; |
| 369 | |
| 370 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
| 371 | |
| 372 | if (!np) { |
| 373 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 374 | goto nodev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | soc = of_find_node_by_type(NULL, "soc"); |
| 378 | |
| 379 | if (!soc) { |
| 380 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 381 | goto nosoc; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 382 | } |
| 383 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 384 | freq = get_property(soc, "bus-frequency", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 385 | if (!freq) { |
| 386 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 387 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | memset(&r, 0, sizeof(r)); |
| 391 | |
| 392 | ret = of_address_to_resource(np, 0, &r); |
| 393 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 394 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 395 | |
| 396 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 397 | if (IS_ERR(dev)) { |
| 398 | ret = PTR_ERR(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 399 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | ret = platform_device_add_data(dev, freq, sizeof(int)); |
| 403 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 404 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 405 | |
| 406 | of_node_put(soc); |
| 407 | of_node_put(np); |
| 408 | |
| 409 | return 0; |
| 410 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 411 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 412 | platform_device_unregister(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 413 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 414 | of_node_put(soc); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 415 | nosoc: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 416 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 417 | nodev: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 418 | return ret; |
| 419 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 420 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 421 | arch_initcall(mpc83xx_wdt_init); |
| 422 | #endif |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 423 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 424 | static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type) |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 425 | { |
| 426 | if (!phy_type) |
| 427 | return FSL_USB2_PHY_NONE; |
| 428 | if (!strcasecmp(phy_type, "ulpi")) |
| 429 | return FSL_USB2_PHY_ULPI; |
| 430 | if (!strcasecmp(phy_type, "utmi")) |
| 431 | return FSL_USB2_PHY_UTMI; |
| 432 | if (!strcasecmp(phy_type, "utmi_wide")) |
| 433 | return FSL_USB2_PHY_UTMI_WIDE; |
| 434 | if (!strcasecmp(phy_type, "serial")) |
| 435 | return FSL_USB2_PHY_SERIAL; |
| 436 | |
| 437 | return FSL_USB2_PHY_NONE; |
| 438 | } |
| 439 | |
| 440 | static int __init fsl_usb_of_init(void) |
| 441 | { |
| 442 | struct device_node *np; |
| 443 | unsigned int i; |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 444 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, |
| 445 | *usb_dev_dr_client = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 446 | int ret; |
| 447 | |
| 448 | for (np = NULL, i = 0; |
| 449 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; |
| 450 | i++) { |
| 451 | struct resource r[2]; |
| 452 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 453 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 454 | |
| 455 | memset(&r, 0, sizeof(r)); |
| 456 | memset(&usb_data, 0, sizeof(usb_data)); |
| 457 | |
| 458 | ret = of_address_to_resource(np, 0, &r[0]); |
| 459 | if (ret) |
| 460 | goto err; |
| 461 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 462 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 463 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 464 | usb_dev_mph = |
| 465 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 466 | if (IS_ERR(usb_dev_mph)) { |
| 467 | ret = PTR_ERR(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 468 | goto err; |
| 469 | } |
| 470 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 471 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
| 472 | usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 473 | |
| 474 | usb_data.operating_mode = FSL_USB2_MPH_HOST; |
| 475 | |
| 476 | prop = get_property(np, "port0", NULL); |
| 477 | if (prop) |
| 478 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; |
| 479 | |
| 480 | prop = get_property(np, "port1", NULL); |
| 481 | if (prop) |
| 482 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; |
| 483 | |
| 484 | prop = get_property(np, "phy_type", NULL); |
| 485 | usb_data.phy_mode = determine_usb_phy(prop); |
| 486 | |
| 487 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 488 | platform_device_add_data(usb_dev_mph, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 489 | sizeof(struct |
| 490 | fsl_usb2_platform_data)); |
| 491 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 492 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 493 | } |
| 494 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 495 | for (np = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 496 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; |
| 497 | i++) { |
| 498 | struct resource r[2]; |
| 499 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 500 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 501 | |
| 502 | memset(&r, 0, sizeof(r)); |
| 503 | memset(&usb_data, 0, sizeof(usb_data)); |
| 504 | |
| 505 | ret = of_address_to_resource(np, 0, &r[0]); |
| 506 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 507 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 508 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 509 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 510 | |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 511 | prop = get_property(np, "dr_mode", NULL); |
| 512 | |
| 513 | if (!prop || !strcmp(prop, "host")) { |
| 514 | usb_data.operating_mode = FSL_USB2_DR_HOST; |
| 515 | usb_dev_dr_host = platform_device_register_simple( |
| 516 | "fsl-ehci", i, r, 2); |
| 517 | if (IS_ERR(usb_dev_dr_host)) { |
| 518 | ret = PTR_ERR(usb_dev_dr_host); |
| 519 | goto err; |
| 520 | } |
| 521 | } else if (prop && !strcmp(prop, "peripheral")) { |
| 522 | usb_data.operating_mode = FSL_USB2_DR_DEVICE; |
| 523 | usb_dev_dr_client = platform_device_register_simple( |
| 524 | "fsl-usb2-udc", i, r, 2); |
| 525 | if (IS_ERR(usb_dev_dr_client)) { |
| 526 | ret = PTR_ERR(usb_dev_dr_client); |
| 527 | goto err; |
| 528 | } |
| 529 | } else if (prop && !strcmp(prop, "otg")) { |
| 530 | usb_data.operating_mode = FSL_USB2_DR_OTG; |
| 531 | usb_dev_dr_host = platform_device_register_simple( |
| 532 | "fsl-ehci", i, r, 2); |
| 533 | if (IS_ERR(usb_dev_dr_host)) { |
| 534 | ret = PTR_ERR(usb_dev_dr_host); |
| 535 | goto err; |
| 536 | } |
| 537 | usb_dev_dr_client = platform_device_register_simple( |
| 538 | "fsl-usb2-udc", i, r, 2); |
| 539 | if (IS_ERR(usb_dev_dr_client)) { |
| 540 | ret = PTR_ERR(usb_dev_dr_client); |
| 541 | goto err; |
| 542 | } |
| 543 | } else { |
| 544 | ret = -EINVAL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 545 | goto err; |
| 546 | } |
| 547 | |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 548 | prop = get_property(np, "phy_type", NULL); |
| 549 | usb_data.phy_mode = determine_usb_phy(prop); |
| 550 | |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 551 | if (usb_dev_dr_host) { |
| 552 | usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; |
| 553 | usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> |
| 554 | dev.coherent_dma_mask; |
| 555 | if ((ret = platform_device_add_data(usb_dev_dr_host, |
| 556 | &usb_data, sizeof(struct |
| 557 | fsl_usb2_platform_data)))) |
| 558 | goto unreg_dr; |
| 559 | } |
| 560 | if (usb_dev_dr_client) { |
| 561 | usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; |
| 562 | usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> |
| 563 | dev.coherent_dma_mask; |
| 564 | if ((ret = platform_device_add_data(usb_dev_dr_client, |
| 565 | &usb_data, sizeof(struct |
| 566 | fsl_usb2_platform_data)))) |
| 567 | goto unreg_dr; |
| 568 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 569 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 570 | return 0; |
| 571 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 572 | unreg_dr: |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 573 | if (usb_dev_dr_host) |
| 574 | platform_device_unregister(usb_dev_dr_host); |
| 575 | if (usb_dev_dr_client) |
| 576 | platform_device_unregister(usb_dev_dr_client); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 577 | unreg_mph: |
| 578 | if (usb_dev_mph) |
| 579 | platform_device_unregister(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 580 | err: |
| 581 | return ret; |
| 582 | } |
| 583 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 584 | arch_initcall(fsl_usb_of_init); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 585 | |
| 586 | #ifdef CONFIG_CPM2 |
| 587 | |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 588 | extern void init_scc_ioports(struct fs_uart_platform_info*); |
| 589 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 590 | static const char fcc_regs[] = "fcc_regs"; |
| 591 | static const char fcc_regs_c[] = "fcc_regs_c"; |
| 592 | static const char fcc_pram[] = "fcc_pram"; |
| 593 | static char bus_id[9][BUS_ID_SIZE]; |
| 594 | |
| 595 | static int __init fs_enet_of_init(void) |
| 596 | { |
| 597 | struct device_node *np; |
| 598 | unsigned int i; |
| 599 | struct platform_device *fs_enet_dev; |
| 600 | struct resource res; |
| 601 | int ret; |
| 602 | |
| 603 | for (np = NULL, i = 0; |
| 604 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; |
| 605 | i++) { |
| 606 | struct resource r[4]; |
| 607 | struct device_node *phy, *mdio; |
| 608 | struct fs_platform_info fs_enet_data; |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 609 | const unsigned int *id, *phy_addr, *phy_irq; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 610 | const void *mac_addr; |
| 611 | const phandle *ph; |
| 612 | const char *model; |
| 613 | |
| 614 | memset(r, 0, sizeof(r)); |
| 615 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); |
| 616 | |
| 617 | ret = of_address_to_resource(np, 0, &r[0]); |
| 618 | if (ret) |
| 619 | goto err; |
| 620 | r[0].name = fcc_regs; |
| 621 | |
| 622 | ret = of_address_to_resource(np, 1, &r[1]); |
| 623 | if (ret) |
| 624 | goto err; |
| 625 | r[1].name = fcc_pram; |
| 626 | |
| 627 | ret = of_address_to_resource(np, 2, &r[2]); |
| 628 | if (ret) |
| 629 | goto err; |
| 630 | r[2].name = fcc_regs_c; |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 631 | fs_enet_data.fcc_regs_c = r[2].start; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 632 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 633 | of_irq_to_resource(np, 0, &r[3]); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 634 | |
| 635 | fs_enet_dev = |
| 636 | platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4); |
| 637 | |
| 638 | if (IS_ERR(fs_enet_dev)) { |
| 639 | ret = PTR_ERR(fs_enet_dev); |
| 640 | goto err; |
| 641 | } |
| 642 | |
| 643 | model = get_property(np, "model", NULL); |
| 644 | if (model == NULL) { |
| 645 | ret = -ENODEV; |
| 646 | goto unreg; |
| 647 | } |
| 648 | |
| 649 | mac_addr = get_property(np, "mac-address", NULL); |
| 650 | memcpy(fs_enet_data.macaddr, mac_addr, 6); |
| 651 | |
| 652 | ph = get_property(np, "phy-handle", NULL); |
| 653 | phy = of_find_node_by_phandle(*ph); |
| 654 | |
| 655 | if (phy == NULL) { |
| 656 | ret = -ENODEV; |
| 657 | goto unreg; |
| 658 | } |
| 659 | |
| 660 | phy_addr = get_property(phy, "reg", NULL); |
| 661 | fs_enet_data.phy_addr = *phy_addr; |
| 662 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 663 | phy_irq = get_property(phy, "interrupts", NULL); |
| 664 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 665 | id = get_property(np, "device-id", NULL); |
| 666 | fs_enet_data.fs_no = *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 667 | strcpy(fs_enet_data.fs_type, model); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 668 | |
| 669 | mdio = of_get_parent(phy); |
| 670 | ret = of_address_to_resource(mdio, 0, &res); |
| 671 | if (ret) { |
| 672 | of_node_put(phy); |
| 673 | of_node_put(mdio); |
| 674 | goto unreg; |
| 675 | } |
| 676 | |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 677 | fs_enet_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
| 678 | fs_enet_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); |
| 679 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 680 | if (strstr(model, "FCC")) { |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 681 | int fcc_index = *id - 1; |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 682 | const unsigned char *mdio_bb_prop; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 683 | |
Vitaly Bordug | fc8e50e | 2006-09-21 22:37:58 +0400 | [diff] [blame] | 684 | fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 685 | fs_enet_data.rx_ring = 32; |
| 686 | fs_enet_data.tx_ring = 32; |
| 687 | fs_enet_data.rx_copybreak = 240; |
| 688 | fs_enet_data.use_napi = 0; |
| 689 | fs_enet_data.napi_weight = 17; |
| 690 | fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index); |
| 691 | fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index); |
| 692 | fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index); |
| 693 | |
| 694 | snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x", |
| 695 | (u32)res.start, fs_enet_data.phy_addr); |
| 696 | fs_enet_data.bus_id = (char*)&bus_id[(*id)]; |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 697 | fs_enet_data.init_ioports = init_fcc_ioports; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 698 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 699 | mdio_bb_prop = get_property(phy, "bitbang", NULL); |
| 700 | if (mdio_bb_prop) { |
| 701 | struct platform_device *fs_enet_mdio_bb_dev; |
| 702 | struct fs_mii_bb_platform_info fs_enet_mdio_bb_data; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 703 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 704 | fs_enet_mdio_bb_dev = |
| 705 | platform_device_register_simple("fsl-bb-mdio", |
| 706 | i, NULL, 0); |
| 707 | memset(&fs_enet_mdio_bb_data, 0, |
| 708 | sizeof(struct fs_mii_bb_platform_info)); |
| 709 | fs_enet_mdio_bb_data.mdio_dat.bit = |
| 710 | mdio_bb_prop[0]; |
| 711 | fs_enet_mdio_bb_data.mdio_dir.bit = |
| 712 | mdio_bb_prop[1]; |
| 713 | fs_enet_mdio_bb_data.mdc_dat.bit = |
| 714 | mdio_bb_prop[2]; |
| 715 | fs_enet_mdio_bb_data.mdio_port = |
| 716 | mdio_bb_prop[3]; |
| 717 | fs_enet_mdio_bb_data.mdc_port = |
| 718 | mdio_bb_prop[4]; |
| 719 | fs_enet_mdio_bb_data.delay = |
| 720 | mdio_bb_prop[5]; |
| 721 | |
| 722 | fs_enet_mdio_bb_data.irq[0] = phy_irq[0]; |
| 723 | fs_enet_mdio_bb_data.irq[1] = -1; |
| 724 | fs_enet_mdio_bb_data.irq[2] = -1; |
| 725 | fs_enet_mdio_bb_data.irq[3] = phy_irq[0]; |
| 726 | fs_enet_mdio_bb_data.irq[31] = -1; |
| 727 | |
| 728 | fs_enet_mdio_bb_data.mdio_dat.offset = |
| 729 | (u32)&cpm2_immr->im_ioport.iop_pdatc; |
| 730 | fs_enet_mdio_bb_data.mdio_dir.offset = |
| 731 | (u32)&cpm2_immr->im_ioport.iop_pdirc; |
| 732 | fs_enet_mdio_bb_data.mdc_dat.offset = |
| 733 | (u32)&cpm2_immr->im_ioport.iop_pdatc; |
| 734 | |
| 735 | ret = platform_device_add_data( |
| 736 | fs_enet_mdio_bb_dev, |
| 737 | &fs_enet_mdio_bb_data, |
| 738 | sizeof(struct fs_mii_bb_platform_info)); |
| 739 | if (ret) |
| 740 | goto unreg; |
| 741 | } |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 742 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 743 | of_node_put(phy); |
| 744 | of_node_put(mdio); |
| 745 | |
| 746 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
| 747 | sizeof(struct |
| 748 | fs_platform_info)); |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 749 | if (ret) |
| 750 | goto unreg; |
| 751 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 752 | } |
| 753 | return 0; |
| 754 | |
| 755 | unreg: |
| 756 | platform_device_unregister(fs_enet_dev); |
| 757 | err: |
| 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | arch_initcall(fs_enet_of_init); |
| 762 | |
| 763 | static const char scc_regs[] = "regs"; |
| 764 | static const char scc_pram[] = "pram"; |
| 765 | |
| 766 | static int __init cpm_uart_of_init(void) |
| 767 | { |
| 768 | struct device_node *np; |
| 769 | unsigned int i; |
| 770 | struct platform_device *cpm_uart_dev; |
| 771 | int ret; |
| 772 | |
| 773 | for (np = NULL, i = 0; |
| 774 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; |
| 775 | i++) { |
| 776 | struct resource r[3]; |
| 777 | struct fs_uart_platform_info cpm_uart_data; |
| 778 | const int *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 779 | const char *model; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 780 | |
| 781 | memset(r, 0, sizeof(r)); |
| 782 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); |
| 783 | |
| 784 | ret = of_address_to_resource(np, 0, &r[0]); |
| 785 | if (ret) |
| 786 | goto err; |
| 787 | |
| 788 | r[0].name = scc_regs; |
| 789 | |
| 790 | ret = of_address_to_resource(np, 1, &r[1]); |
| 791 | if (ret) |
| 792 | goto err; |
| 793 | r[1].name = scc_pram; |
| 794 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 795 | of_irq_to_resource(np, 0, &r[2]); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 796 | |
| 797 | cpm_uart_dev = |
| 798 | platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3); |
| 799 | |
| 800 | if (IS_ERR(cpm_uart_dev)) { |
| 801 | ret = PTR_ERR(cpm_uart_dev); |
| 802 | goto err; |
| 803 | } |
| 804 | |
| 805 | id = get_property(np, "device-id", NULL); |
| 806 | cpm_uart_data.fs_no = *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 807 | |
| 808 | model = (char*)get_property(np, "model", NULL); |
| 809 | strcpy(cpm_uart_data.fs_type, model); |
| 810 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 811 | cpm_uart_data.uart_clk = ppc_proc_freq; |
| 812 | |
| 813 | cpm_uart_data.tx_num_fifo = 4; |
| 814 | cpm_uart_data.tx_buf_size = 32; |
| 815 | cpm_uart_data.rx_num_fifo = 4; |
| 816 | cpm_uart_data.rx_buf_size = 32; |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 817 | cpm_uart_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL)); |
| 818 | cpm_uart_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL)); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 819 | |
| 820 | ret = |
| 821 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, |
| 822 | sizeof(struct |
| 823 | fs_uart_platform_info)); |
| 824 | if (ret) |
| 825 | goto unreg; |
| 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | |
| 830 | unreg: |
| 831 | platform_device_unregister(cpm_uart_dev); |
| 832 | err: |
| 833 | return ret; |
| 834 | } |
| 835 | |
| 836 | arch_initcall(cpm_uart_of_init); |
| 837 | #endif /* CONFIG_CPM2 */ |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 838 | |
| 839 | #ifdef CONFIG_8xx |
| 840 | |
| 841 | extern void init_scc_ioports(struct fs_platform_info*); |
| 842 | extern int platform_device_skip(char *model, int id); |
| 843 | |
| 844 | static int __init fs_enet_mdio_of_init(void) |
| 845 | { |
| 846 | struct device_node *np; |
| 847 | unsigned int i; |
| 848 | struct platform_device *mdio_dev; |
| 849 | struct resource res; |
| 850 | int ret; |
| 851 | |
| 852 | for (np = NULL, i = 0; |
| 853 | (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL; |
| 854 | i++) { |
| 855 | struct fs_mii_fec_platform_info mdio_data; |
| 856 | |
| 857 | memset(&res, 0, sizeof(res)); |
| 858 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 859 | |
| 860 | ret = of_address_to_resource(np, 0, &res); |
| 861 | if (ret) |
| 862 | goto err; |
| 863 | |
| 864 | mdio_dev = |
| 865 | platform_device_register_simple("fsl-cpm-fec-mdio", |
| 866 | res.start, &res, 1); |
| 867 | if (IS_ERR(mdio_dev)) { |
| 868 | ret = PTR_ERR(mdio_dev); |
| 869 | goto err; |
| 870 | } |
| 871 | |
| 872 | mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1; |
| 873 | |
| 874 | ret = |
| 875 | platform_device_add_data(mdio_dev, &mdio_data, |
| 876 | sizeof(struct fs_mii_fec_platform_info)); |
| 877 | if (ret) |
| 878 | goto unreg; |
| 879 | } |
| 880 | return 0; |
| 881 | |
| 882 | unreg: |
| 883 | platform_device_unregister(mdio_dev); |
| 884 | err: |
| 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | arch_initcall(fs_enet_mdio_of_init); |
| 889 | |
| 890 | static const char *enet_regs = "regs"; |
| 891 | static const char *enet_pram = "pram"; |
| 892 | static const char *enet_irq = "interrupt"; |
| 893 | static char bus_id[9][BUS_ID_SIZE]; |
| 894 | |
| 895 | static int __init fs_enet_of_init(void) |
| 896 | { |
| 897 | struct device_node *np; |
| 898 | unsigned int i; |
| 899 | struct platform_device *fs_enet_dev = NULL; |
| 900 | struct resource res; |
| 901 | int ret; |
| 902 | |
| 903 | for (np = NULL, i = 0; |
| 904 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; |
| 905 | i++) { |
| 906 | struct resource r[4]; |
| 907 | struct device_node *phy = NULL, *mdio = NULL; |
| 908 | struct fs_platform_info fs_enet_data; |
| 909 | unsigned int *id, *phy_addr; |
| 910 | void *mac_addr; |
| 911 | phandle *ph; |
| 912 | char *model; |
| 913 | |
| 914 | memset(r, 0, sizeof(r)); |
| 915 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); |
| 916 | |
| 917 | model = (char *)get_property(np, "model", NULL); |
| 918 | if (model == NULL) { |
| 919 | ret = -ENODEV; |
| 920 | goto unreg; |
| 921 | } |
| 922 | |
| 923 | id = (u32 *) get_property(np, "device-id", NULL); |
| 924 | fs_enet_data.fs_no = *id; |
| 925 | |
| 926 | if (platform_device_skip(model, *id)) |
| 927 | continue; |
| 928 | |
| 929 | ret = of_address_to_resource(np, 0, &r[0]); |
| 930 | if (ret) |
| 931 | goto err; |
| 932 | r[0].name = enet_regs; |
| 933 | |
| 934 | mac_addr = (void *)get_property(np, "mac-address", NULL); |
| 935 | memcpy(fs_enet_data.macaddr, mac_addr, 6); |
| 936 | |
| 937 | ph = (phandle *) get_property(np, "phy-handle", NULL); |
| 938 | if (ph != NULL) |
| 939 | phy = of_find_node_by_phandle(*ph); |
| 940 | |
| 941 | if (phy != NULL) { |
| 942 | phy_addr = (u32 *) get_property(phy, "reg", NULL); |
| 943 | fs_enet_data.phy_addr = *phy_addr; |
| 944 | fs_enet_data.has_phy = 1; |
| 945 | |
| 946 | mdio = of_get_parent(phy); |
| 947 | ret = of_address_to_resource(mdio, 0, &res); |
| 948 | if (ret) { |
| 949 | of_node_put(phy); |
| 950 | of_node_put(mdio); |
| 951 | goto unreg; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | model = (char*)get_property(np, "model", NULL); |
| 956 | strcpy(fs_enet_data.fs_type, model); |
| 957 | |
| 958 | if (strstr(model, "FEC")) { |
| 959 | r[1].start = r[1].end = irq_of_parse_and_map(np, 0); |
| 960 | r[1].flags = IORESOURCE_IRQ; |
| 961 | r[1].name = enet_irq; |
| 962 | |
| 963 | fs_enet_dev = |
| 964 | platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2); |
| 965 | |
| 966 | if (IS_ERR(fs_enet_dev)) { |
| 967 | ret = PTR_ERR(fs_enet_dev); |
| 968 | goto err; |
| 969 | } |
| 970 | |
| 971 | fs_enet_data.rx_ring = 128; |
| 972 | fs_enet_data.tx_ring = 16; |
| 973 | fs_enet_data.rx_copybreak = 240; |
| 974 | fs_enet_data.use_napi = 1; |
| 975 | fs_enet_data.napi_weight = 17; |
| 976 | |
| 977 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x", |
| 978 | (u32)res.start, fs_enet_data.phy_addr); |
| 979 | fs_enet_data.bus_id = (char*)&bus_id[i]; |
| 980 | fs_enet_data.init_ioports = init_fec_ioports; |
| 981 | } |
| 982 | if (strstr(model, "SCC")) { |
| 983 | ret = of_address_to_resource(np, 1, &r[1]); |
| 984 | if (ret) |
| 985 | goto err; |
| 986 | r[1].name = enet_pram; |
| 987 | |
| 988 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); |
| 989 | r[2].flags = IORESOURCE_IRQ; |
| 990 | r[2].name = enet_irq; |
| 991 | |
| 992 | fs_enet_dev = |
| 993 | platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3); |
| 994 | |
| 995 | if (IS_ERR(fs_enet_dev)) { |
| 996 | ret = PTR_ERR(fs_enet_dev); |
| 997 | goto err; |
| 998 | } |
| 999 | |
| 1000 | fs_enet_data.rx_ring = 64; |
| 1001 | fs_enet_data.tx_ring = 8; |
| 1002 | fs_enet_data.rx_copybreak = 240; |
| 1003 | fs_enet_data.use_napi = 1; |
| 1004 | fs_enet_data.napi_weight = 17; |
| 1005 | |
| 1006 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1"); |
| 1007 | fs_enet_data.bus_id = (char*)&bus_id[i]; |
| 1008 | fs_enet_data.init_ioports = init_scc_ioports; |
| 1009 | } |
| 1010 | |
| 1011 | of_node_put(phy); |
| 1012 | of_node_put(mdio); |
| 1013 | |
| 1014 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
| 1015 | sizeof(struct |
| 1016 | fs_platform_info)); |
| 1017 | if (ret) |
| 1018 | goto unreg; |
| 1019 | } |
| 1020 | return 0; |
| 1021 | |
| 1022 | unreg: |
| 1023 | platform_device_unregister(fs_enet_dev); |
| 1024 | err: |
| 1025 | return ret; |
| 1026 | } |
| 1027 | |
| 1028 | arch_initcall(fs_enet_of_init); |
| 1029 | |
| 1030 | |
| 1031 | static const char *smc_regs = "regs"; |
| 1032 | static const char *smc_pram = "pram"; |
| 1033 | |
| 1034 | static int __init cpm_smc_uart_of_init(void) |
| 1035 | { |
| 1036 | struct device_node *np; |
| 1037 | unsigned int i; |
| 1038 | struct platform_device *cpm_uart_dev; |
| 1039 | int ret; |
| 1040 | |
| 1041 | for (np = NULL, i = 0; |
| 1042 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; |
| 1043 | i++) { |
| 1044 | struct resource r[3]; |
| 1045 | struct fs_uart_platform_info cpm_uart_data; |
| 1046 | int *id; |
| 1047 | char *model; |
| 1048 | |
| 1049 | memset(r, 0, sizeof(r)); |
| 1050 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); |
| 1051 | |
| 1052 | ret = of_address_to_resource(np, 0, &r[0]); |
| 1053 | if (ret) |
| 1054 | goto err; |
| 1055 | |
| 1056 | r[0].name = smc_regs; |
| 1057 | |
| 1058 | ret = of_address_to_resource(np, 1, &r[1]); |
| 1059 | if (ret) |
| 1060 | goto err; |
| 1061 | r[1].name = smc_pram; |
| 1062 | |
| 1063 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); |
| 1064 | r[2].flags = IORESOURCE_IRQ; |
| 1065 | |
| 1066 | cpm_uart_dev = |
| 1067 | platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3); |
| 1068 | |
| 1069 | if (IS_ERR(cpm_uart_dev)) { |
| 1070 | ret = PTR_ERR(cpm_uart_dev); |
| 1071 | goto err; |
| 1072 | } |
| 1073 | |
| 1074 | model = (char*)get_property(np, "model", NULL); |
| 1075 | strcpy(cpm_uart_data.fs_type, model); |
| 1076 | |
| 1077 | id = (int*)get_property(np, "device-id", NULL); |
| 1078 | cpm_uart_data.fs_no = *id; |
| 1079 | cpm_uart_data.uart_clk = ppc_proc_freq; |
| 1080 | |
| 1081 | cpm_uart_data.tx_num_fifo = 4; |
| 1082 | cpm_uart_data.tx_buf_size = 32; |
| 1083 | cpm_uart_data.rx_num_fifo = 4; |
| 1084 | cpm_uart_data.rx_buf_size = 32; |
| 1085 | |
| 1086 | ret = |
| 1087 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, |
| 1088 | sizeof(struct |
| 1089 | fs_uart_platform_info)); |
| 1090 | if (ret) |
| 1091 | goto unreg; |
| 1092 | } |
| 1093 | |
| 1094 | return 0; |
| 1095 | |
| 1096 | unreg: |
| 1097 | platform_device_unregister(cpm_uart_dev); |
| 1098 | err: |
| 1099 | return ret; |
| 1100 | } |
| 1101 | |
| 1102 | arch_initcall(cpm_smc_uart_of_init); |
| 1103 | |
| 1104 | #endif /* CONFIG_8xx */ |