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> |
Kumar Gala | 0af666f | 2007-08-17 08:23:06 -0500 | [diff] [blame] | 25 | #include <linux/of_platform.h> |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 26 | #include <linux/phy.h> |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 27 | #include <linux/spi/spi.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 28 | #include <linux/fsl_devices.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 29 | #include <linux/fs_enet_pd.h> |
| 30 | #include <linux/fs_uart_pd.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 31 | |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/atomic.h> |
| 34 | #include <asm/io.h> |
| 35 | #include <asm/irq.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 36 | #include <asm/time.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 37 | #include <asm/prom.h> |
| 38 | #include <sysdev/fsl_soc.h> |
| 39 | #include <mm/mmu_decl.h> |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 40 | #include <asm/cpm2.h> |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 41 | |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 42 | extern void init_fcc_ioports(struct fs_platform_info*); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 43 | extern void init_fec_ioports(struct fs_platform_info*); |
| 44 | extern void init_smc_ioports(struct fs_uart_platform_info*); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 45 | static phys_addr_t immrbase = -1; |
| 46 | |
| 47 | phys_addr_t get_immrbase(void) |
| 48 | { |
| 49 | struct device_node *soc; |
| 50 | |
| 51 | if (immrbase != -1) |
| 52 | return immrbase; |
| 53 | |
| 54 | soc = of_find_node_by_type(NULL, "soc"); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 55 | if (soc) { |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 56 | int size; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 57 | const void *prop = of_get_property(soc, "reg", &size); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 58 | |
| 59 | if (prop) |
| 60 | immrbase = of_translate_address(soc, prop); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 61 | of_node_put(soc); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 62 | } |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 63 | |
| 64 | return immrbase; |
| 65 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 66 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 67 | EXPORT_SYMBOL(get_immrbase); |
| 68 | |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 69 | #if defined(CONFIG_CPM2) || defined(CONFIG_8xx) |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 70 | |
| 71 | static u32 brgfreq = -1; |
| 72 | |
| 73 | u32 get_brgfreq(void) |
| 74 | { |
| 75 | struct device_node *node; |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 76 | const unsigned int *prop; |
| 77 | int size; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 78 | |
| 79 | if (brgfreq != -1) |
| 80 | return brgfreq; |
| 81 | |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 82 | node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg"); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 83 | if (node) { |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 84 | prop = of_get_property(node, "clock-frequency", &size); |
| 85 | if (prop && size == 4) |
| 86 | brgfreq = *prop; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 87 | |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 88 | of_node_put(node); |
| 89 | return brgfreq; |
| 90 | } |
| 91 | |
| 92 | /* Legacy device binding -- will go away when no users are left. */ |
| 93 | node = of_find_node_by_type(NULL, "cpm"); |
| 94 | if (node) { |
| 95 | prop = of_get_property(node, "brg-frequency", &size); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 96 | if (prop && size == 4) |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 97 | brgfreq = *prop; |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 98 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 99 | of_node_put(node); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 100 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 101 | |
| 102 | return brgfreq; |
| 103 | } |
| 104 | |
| 105 | EXPORT_SYMBOL(get_brgfreq); |
| 106 | |
| 107 | static u32 fs_baudrate = -1; |
| 108 | |
| 109 | u32 get_baudrate(void) |
| 110 | { |
| 111 | struct device_node *node; |
| 112 | |
| 113 | if (fs_baudrate != -1) |
| 114 | return fs_baudrate; |
| 115 | |
| 116 | node = of_find_node_by_type(NULL, "serial"); |
| 117 | if (node) { |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 118 | int size; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 119 | const unsigned int *prop = of_get_property(node, |
| 120 | "current-speed", &size); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 121 | |
| 122 | if (prop) |
| 123 | fs_baudrate = *prop; |
| 124 | of_node_put(node); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 125 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 126 | |
| 127 | return fs_baudrate; |
| 128 | } |
| 129 | |
| 130 | EXPORT_SYMBOL(get_baudrate); |
| 131 | #endif /* CONFIG_CPM2 */ |
| 132 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 133 | static int __init gfar_mdio_of_init(void) |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 134 | { |
| 135 | struct device_node *np; |
| 136 | unsigned int i; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 137 | struct platform_device *mdio_dev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 138 | struct resource res; |
| 139 | int ret; |
| 140 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 141 | for (np = NULL, i = 0; |
| 142 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; |
| 143 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 144 | int k; |
| 145 | struct device_node *child = NULL; |
| 146 | struct gianfar_mdio_data mdio_data; |
| 147 | |
| 148 | memset(&res, 0, sizeof(res)); |
| 149 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 150 | |
| 151 | ret = of_address_to_resource(np, 0, &res); |
| 152 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 153 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 154 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 155 | mdio_dev = |
| 156 | platform_device_register_simple("fsl-gianfar_mdio", |
| 157 | res.start, &res, 1); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 158 | if (IS_ERR(mdio_dev)) { |
| 159 | ret = PTR_ERR(mdio_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 160 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | for (k = 0; k < 32; k++) |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 164 | mdio_data.irq[k] = PHY_POLL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 165 | |
| 166 | while ((child = of_get_next_child(np, child)) != NULL) { |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 167 | int irq = irq_of_parse_and_map(child, 0); |
| 168 | if (irq != NO_IRQ) { |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 169 | const u32 *id = of_get_property(child, |
| 170 | "reg", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 171 | mdio_data.irq[*id] = irq; |
| 172 | } |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 173 | } |
| 174 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 175 | ret = |
| 176 | platform_device_add_data(mdio_dev, &mdio_data, |
| 177 | sizeof(struct gianfar_mdio_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 178 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 179 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 180 | } |
| 181 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 182 | return 0; |
| 183 | |
| 184 | unreg: |
| 185 | platform_device_unregister(mdio_dev); |
| 186 | err: |
| 187 | return ret; |
| 188 | } |
| 189 | |
| 190 | arch_initcall(gfar_mdio_of_init); |
| 191 | |
| 192 | static const char *gfar_tx_intr = "tx"; |
| 193 | static const char *gfar_rx_intr = "rx"; |
| 194 | static const char *gfar_err_intr = "error"; |
| 195 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 196 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 197 | static int __init gfar_of_init(void) |
| 198 | { |
| 199 | struct device_node *np; |
| 200 | unsigned int i; |
| 201 | struct platform_device *gfar_dev; |
| 202 | struct resource res; |
| 203 | int ret; |
| 204 | |
| 205 | for (np = NULL, i = 0; |
| 206 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; |
| 207 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 208 | struct resource r[4]; |
| 209 | struct device_node *phy, *mdio; |
| 210 | struct gianfar_platform_data gfar_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 211 | const unsigned int *id; |
| 212 | const char *model; |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 213 | const char *ctype; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 214 | const void *mac_addr; |
| 215 | const phandle *ph; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 216 | int n_res = 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 217 | |
| 218 | memset(r, 0, sizeof(r)); |
| 219 | memset(&gfar_data, 0, sizeof(gfar_data)); |
| 220 | |
| 221 | ret = of_address_to_resource(np, 0, &r[0]); |
| 222 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 223 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 224 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 225 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 226 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 227 | model = of_get_property(np, "model", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 228 | |
| 229 | /* If we aren't the FEC we have multiple interrupts */ |
| 230 | if (model && strcasecmp(model, "FEC")) { |
| 231 | r[1].name = gfar_tx_intr; |
| 232 | |
| 233 | r[2].name = gfar_rx_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 234 | of_irq_to_resource(np, 1, &r[2]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 235 | |
| 236 | r[3].name = gfar_err_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 237 | of_irq_to_resource(np, 2, &r[3]); |
Jon Loeliger | 919fede | 2006-07-31 15:35:41 -0500 | [diff] [blame] | 238 | |
| 239 | n_res += 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 240 | } |
| 241 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 242 | gfar_dev = |
| 243 | platform_device_register_simple("fsl-gianfar", i, &r[0], |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 244 | n_res); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 245 | |
| 246 | if (IS_ERR(gfar_dev)) { |
| 247 | ret = PTR_ERR(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 248 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 249 | } |
| 250 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 251 | mac_addr = of_get_mac_address(np); |
Jon Loeliger | f583165 | 2006-08-17 08:42:35 -0500 | [diff] [blame] | 252 | if (mac_addr) |
| 253 | memcpy(gfar_data.mac_addr, mac_addr, 6); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 254 | |
| 255 | if (model && !strcasecmp(model, "TSEC")) |
| 256 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 257 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 258 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 259 | FSL_GIANFAR_DEV_HAS_RMON | |
| 260 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 261 | if (model && !strcasecmp(model, "eTSEC")) |
| 262 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 263 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 264 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 265 | FSL_GIANFAR_DEV_HAS_RMON | |
| 266 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
| 267 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 268 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 269 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 270 | |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 271 | ctype = of_get_property(np, "phy-connection-type", NULL); |
| 272 | |
| 273 | /* We only care about rgmii-id. The rest are autodetected */ |
| 274 | if (ctype && !strcmp(ctype, "rgmii-id")) |
| 275 | gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID; |
| 276 | else |
| 277 | gfar_data.interface = PHY_INTERFACE_MODE_MII; |
| 278 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 279 | ph = of_get_property(np, "phy-handle", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 280 | phy = of_find_node_by_phandle(*ph); |
| 281 | |
| 282 | if (phy == NULL) { |
| 283 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 284 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | mdio = of_get_parent(phy); |
| 288 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 289 | id = of_get_property(phy, "reg", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 290 | ret = of_address_to_resource(mdio, 0, &res); |
| 291 | if (ret) { |
| 292 | of_node_put(phy); |
| 293 | of_node_put(mdio); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 294 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | gfar_data.phy_id = *id; |
| 298 | gfar_data.bus_id = res.start; |
| 299 | |
| 300 | of_node_put(phy); |
| 301 | of_node_put(mdio); |
| 302 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 303 | ret = |
| 304 | platform_device_add_data(gfar_dev, &gfar_data, |
| 305 | sizeof(struct |
| 306 | gianfar_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 307 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 308 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | return 0; |
| 312 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 313 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 314 | platform_device_unregister(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 315 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 316 | return ret; |
| 317 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 318 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 319 | arch_initcall(gfar_of_init); |
| 320 | |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 321 | #ifdef CONFIG_I2C_BOARDINFO |
| 322 | #include <linux/i2c.h> |
| 323 | struct i2c_driver_device { |
| 324 | char *of_device; |
| 325 | char *i2c_driver; |
| 326 | char *i2c_type; |
| 327 | }; |
| 328 | |
| 329 | static struct i2c_driver_device i2c_devices[] __initdata = { |
| 330 | {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",}, |
| 331 | {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",}, |
| 332 | {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",}, |
| 333 | {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",}, |
Peter Korsgaard | 0438c28 | 2007-09-20 12:42:13 +0200 | [diff] [blame] | 334 | {"dallas,ds1307", "rtc-ds1307", "ds1307",}, |
| 335 | {"dallas,ds1337", "rtc-ds1307", "ds1337",}, |
| 336 | {"dallas,ds1338", "rtc-ds1307", "ds1338",}, |
| 337 | {"dallas,ds1339", "rtc-ds1307", "ds1339",}, |
| 338 | {"dallas,ds1340", "rtc-ds1307", "ds1340",}, |
| 339 | {"stm,m41t00", "rtc-ds1307", "m41t00"}, |
Anton Vorontsov | c0e4eb2 | 2007-10-02 17:47:43 +0400 | [diff] [blame] | 340 | {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",}, |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 341 | }; |
| 342 | |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 343 | static int __init of_find_i2c_driver(struct device_node *node, |
| 344 | struct i2c_board_info *info) |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 345 | { |
| 346 | int i; |
| 347 | |
| 348 | for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) { |
| 349 | if (!of_device_is_compatible(node, i2c_devices[i].of_device)) |
| 350 | continue; |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 351 | if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver, |
| 352 | KOBJ_NAME_LEN) >= KOBJ_NAME_LEN || |
| 353 | strlcpy(info->type, i2c_devices[i].i2c_type, |
| 354 | I2C_NAME_SIZE) >= I2C_NAME_SIZE) |
| 355 | return -ENOMEM; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | return -ENODEV; |
| 359 | } |
| 360 | |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 361 | static void __init of_register_i2c_devices(struct device_node *adap_node, |
| 362 | int bus_num) |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 363 | { |
| 364 | struct device_node *node = NULL; |
| 365 | |
| 366 | while ((node = of_get_next_child(adap_node, node))) { |
Anton Vorontsov | da1bb3a | 2007-10-02 17:47:40 +0400 | [diff] [blame] | 367 | struct i2c_board_info info = {}; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 368 | const u32 *addr; |
| 369 | int len; |
| 370 | |
| 371 | addr = of_get_property(node, "reg", &len); |
| 372 | if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) { |
Peter Korsgaard | 210805e | 2007-09-20 12:42:12 +0200 | [diff] [blame] | 373 | printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n"); |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 374 | continue; |
| 375 | } |
| 376 | |
| 377 | info.irq = irq_of_parse_and_map(node, 0); |
| 378 | if (info.irq == NO_IRQ) |
| 379 | info.irq = -1; |
| 380 | |
| 381 | if (of_find_i2c_driver(node, &info) < 0) |
| 382 | continue; |
| 383 | |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 384 | info.addr = *addr; |
| 385 | |
| 386 | i2c_register_board_info(bus_num, &info, 1); |
| 387 | } |
| 388 | } |
| 389 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 390 | static int __init fsl_i2c_of_init(void) |
| 391 | { |
| 392 | struct device_node *np; |
| 393 | unsigned int i; |
| 394 | struct platform_device *i2c_dev; |
| 395 | int ret; |
| 396 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 397 | for (np = NULL, i = 0; |
| 398 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; |
| 399 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 400 | struct resource r[2]; |
| 401 | struct fsl_i2c_platform_data i2c_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 402 | const unsigned char *flags = NULL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 403 | |
| 404 | memset(&r, 0, sizeof(r)); |
| 405 | memset(&i2c_data, 0, sizeof(i2c_data)); |
| 406 | |
| 407 | ret = of_address_to_resource(np, 0, &r[0]); |
| 408 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 409 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 410 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 411 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 412 | |
| 413 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); |
| 414 | if (IS_ERR(i2c_dev)) { |
| 415 | ret = PTR_ERR(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 416 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | i2c_data.device_flags = 0; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 420 | flags = of_get_property(np, "dfsrr", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 421 | if (flags) |
| 422 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; |
| 423 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 424 | flags = of_get_property(np, "fsl5200-clocking", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 425 | if (flags) |
| 426 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; |
| 427 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 428 | ret = |
| 429 | platform_device_add_data(i2c_dev, &i2c_data, |
| 430 | sizeof(struct |
| 431 | fsl_i2c_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 432 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 433 | goto unreg; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 434 | |
| 435 | of_register_i2c_devices(np, i); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | return 0; |
| 439 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 440 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 441 | platform_device_unregister(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 442 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 443 | return ret; |
| 444 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 445 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 446 | arch_initcall(fsl_i2c_of_init); |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 447 | #endif |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 448 | |
| 449 | #ifdef CONFIG_PPC_83xx |
| 450 | static int __init mpc83xx_wdt_init(void) |
| 451 | { |
| 452 | struct resource r; |
| 453 | struct device_node *soc, *np; |
| 454 | struct platform_device *dev; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 455 | const unsigned int *freq; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 456 | int ret; |
| 457 | |
| 458 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
| 459 | |
| 460 | if (!np) { |
| 461 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 462 | goto nodev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | soc = of_find_node_by_type(NULL, "soc"); |
| 466 | |
| 467 | if (!soc) { |
| 468 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 469 | goto nosoc; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 470 | } |
| 471 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 472 | freq = of_get_property(soc, "bus-frequency", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 473 | if (!freq) { |
| 474 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 475 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | memset(&r, 0, sizeof(r)); |
| 479 | |
| 480 | ret = of_address_to_resource(np, 0, &r); |
| 481 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 482 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 483 | |
| 484 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 485 | if (IS_ERR(dev)) { |
| 486 | ret = PTR_ERR(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 487 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | ret = platform_device_add_data(dev, freq, sizeof(int)); |
| 491 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 492 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 493 | |
| 494 | of_node_put(soc); |
| 495 | of_node_put(np); |
| 496 | |
| 497 | return 0; |
| 498 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 499 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 500 | platform_device_unregister(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 501 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 502 | of_node_put(soc); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 503 | nosoc: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 504 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 505 | nodev: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 506 | return ret; |
| 507 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 508 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 509 | arch_initcall(mpc83xx_wdt_init); |
| 510 | #endif |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 511 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 512 | 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] | 513 | { |
| 514 | if (!phy_type) |
| 515 | return FSL_USB2_PHY_NONE; |
| 516 | if (!strcasecmp(phy_type, "ulpi")) |
| 517 | return FSL_USB2_PHY_ULPI; |
| 518 | if (!strcasecmp(phy_type, "utmi")) |
| 519 | return FSL_USB2_PHY_UTMI; |
| 520 | if (!strcasecmp(phy_type, "utmi_wide")) |
| 521 | return FSL_USB2_PHY_UTMI_WIDE; |
| 522 | if (!strcasecmp(phy_type, "serial")) |
| 523 | return FSL_USB2_PHY_SERIAL; |
| 524 | |
| 525 | return FSL_USB2_PHY_NONE; |
| 526 | } |
| 527 | |
| 528 | static int __init fsl_usb_of_init(void) |
| 529 | { |
| 530 | struct device_node *np; |
| 531 | unsigned int i; |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 532 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, |
| 533 | *usb_dev_dr_client = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 534 | int ret; |
| 535 | |
| 536 | for (np = NULL, i = 0; |
| 537 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; |
| 538 | i++) { |
| 539 | struct resource r[2]; |
| 540 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 541 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 542 | |
| 543 | memset(&r, 0, sizeof(r)); |
| 544 | memset(&usb_data, 0, sizeof(usb_data)); |
| 545 | |
| 546 | ret = of_address_to_resource(np, 0, &r[0]); |
| 547 | if (ret) |
| 548 | goto err; |
| 549 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 550 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 551 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 552 | usb_dev_mph = |
| 553 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 554 | if (IS_ERR(usb_dev_mph)) { |
| 555 | ret = PTR_ERR(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 556 | goto err; |
| 557 | } |
| 558 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 559 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
| 560 | 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] | 561 | |
| 562 | usb_data.operating_mode = FSL_USB2_MPH_HOST; |
| 563 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 564 | prop = of_get_property(np, "port0", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 565 | if (prop) |
| 566 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; |
| 567 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 568 | prop = of_get_property(np, "port1", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 569 | if (prop) |
| 570 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; |
| 571 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 572 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 573 | usb_data.phy_mode = determine_usb_phy(prop); |
| 574 | |
| 575 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 576 | platform_device_add_data(usb_dev_mph, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 577 | sizeof(struct |
| 578 | fsl_usb2_platform_data)); |
| 579 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 580 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 581 | } |
| 582 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 583 | for (np = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 584 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; |
| 585 | i++) { |
| 586 | struct resource r[2]; |
| 587 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 588 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 589 | |
| 590 | memset(&r, 0, sizeof(r)); |
| 591 | memset(&usb_data, 0, sizeof(usb_data)); |
| 592 | |
| 593 | ret = of_address_to_resource(np, 0, &r[0]); |
| 594 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 595 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 596 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 597 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 598 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 599 | prop = of_get_property(np, "dr_mode", NULL); |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 600 | |
| 601 | if (!prop || !strcmp(prop, "host")) { |
| 602 | usb_data.operating_mode = FSL_USB2_DR_HOST; |
| 603 | usb_dev_dr_host = platform_device_register_simple( |
| 604 | "fsl-ehci", i, r, 2); |
| 605 | if (IS_ERR(usb_dev_dr_host)) { |
| 606 | ret = PTR_ERR(usb_dev_dr_host); |
| 607 | goto err; |
| 608 | } |
| 609 | } else if (prop && !strcmp(prop, "peripheral")) { |
| 610 | usb_data.operating_mode = FSL_USB2_DR_DEVICE; |
| 611 | usb_dev_dr_client = platform_device_register_simple( |
| 612 | "fsl-usb2-udc", i, r, 2); |
| 613 | if (IS_ERR(usb_dev_dr_client)) { |
| 614 | ret = PTR_ERR(usb_dev_dr_client); |
| 615 | goto err; |
| 616 | } |
| 617 | } else if (prop && !strcmp(prop, "otg")) { |
| 618 | usb_data.operating_mode = FSL_USB2_DR_OTG; |
| 619 | usb_dev_dr_host = platform_device_register_simple( |
| 620 | "fsl-ehci", i, r, 2); |
| 621 | if (IS_ERR(usb_dev_dr_host)) { |
| 622 | ret = PTR_ERR(usb_dev_dr_host); |
| 623 | goto err; |
| 624 | } |
| 625 | usb_dev_dr_client = platform_device_register_simple( |
| 626 | "fsl-usb2-udc", i, r, 2); |
| 627 | if (IS_ERR(usb_dev_dr_client)) { |
| 628 | ret = PTR_ERR(usb_dev_dr_client); |
| 629 | goto err; |
| 630 | } |
| 631 | } else { |
| 632 | ret = -EINVAL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 633 | goto err; |
| 634 | } |
| 635 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 636 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 637 | usb_data.phy_mode = determine_usb_phy(prop); |
| 638 | |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 639 | if (usb_dev_dr_host) { |
| 640 | usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; |
| 641 | usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> |
| 642 | dev.coherent_dma_mask; |
| 643 | if ((ret = platform_device_add_data(usb_dev_dr_host, |
| 644 | &usb_data, sizeof(struct |
| 645 | fsl_usb2_platform_data)))) |
| 646 | goto unreg_dr; |
| 647 | } |
| 648 | if (usb_dev_dr_client) { |
| 649 | usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; |
| 650 | usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> |
| 651 | dev.coherent_dma_mask; |
| 652 | if ((ret = platform_device_add_data(usb_dev_dr_client, |
| 653 | &usb_data, sizeof(struct |
| 654 | fsl_usb2_platform_data)))) |
| 655 | goto unreg_dr; |
| 656 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 657 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 658 | return 0; |
| 659 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 660 | unreg_dr: |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 661 | if (usb_dev_dr_host) |
| 662 | platform_device_unregister(usb_dev_dr_host); |
| 663 | if (usb_dev_dr_client) |
| 664 | platform_device_unregister(usb_dev_dr_client); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 665 | unreg_mph: |
| 666 | if (usb_dev_mph) |
| 667 | platform_device_unregister(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 668 | err: |
| 669 | return ret; |
| 670 | } |
| 671 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 672 | arch_initcall(fsl_usb_of_init); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 673 | |
Scott Wood | e631ae3 | 2007-09-14 13:04:54 -0500 | [diff] [blame] | 674 | #ifndef CONFIG_PPC_CPM_NEW_BINDING |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 675 | #ifdef CONFIG_CPM2 |
| 676 | |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 677 | extern void init_scc_ioports(struct fs_uart_platform_info*); |
| 678 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 679 | static const char fcc_regs[] = "fcc_regs"; |
| 680 | static const char fcc_regs_c[] = "fcc_regs_c"; |
| 681 | static const char fcc_pram[] = "fcc_pram"; |
| 682 | static char bus_id[9][BUS_ID_SIZE]; |
| 683 | |
| 684 | static int __init fs_enet_of_init(void) |
| 685 | { |
| 686 | struct device_node *np; |
| 687 | unsigned int i; |
| 688 | struct platform_device *fs_enet_dev; |
| 689 | struct resource res; |
| 690 | int ret; |
| 691 | |
| 692 | for (np = NULL, i = 0; |
| 693 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; |
| 694 | i++) { |
| 695 | struct resource r[4]; |
| 696 | struct device_node *phy, *mdio; |
| 697 | struct fs_platform_info fs_enet_data; |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 698 | const unsigned int *id, *phy_addr, *phy_irq; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 699 | const void *mac_addr; |
| 700 | const phandle *ph; |
| 701 | const char *model; |
| 702 | |
| 703 | memset(r, 0, sizeof(r)); |
| 704 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); |
| 705 | |
| 706 | ret = of_address_to_resource(np, 0, &r[0]); |
| 707 | if (ret) |
| 708 | goto err; |
| 709 | r[0].name = fcc_regs; |
| 710 | |
| 711 | ret = of_address_to_resource(np, 1, &r[1]); |
| 712 | if (ret) |
| 713 | goto err; |
| 714 | r[1].name = fcc_pram; |
| 715 | |
| 716 | ret = of_address_to_resource(np, 2, &r[2]); |
| 717 | if (ret) |
| 718 | goto err; |
| 719 | r[2].name = fcc_regs_c; |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 720 | fs_enet_data.fcc_regs_c = r[2].start; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 721 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 722 | of_irq_to_resource(np, 0, &r[3]); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 723 | |
| 724 | fs_enet_dev = |
| 725 | platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4); |
| 726 | |
| 727 | if (IS_ERR(fs_enet_dev)) { |
| 728 | ret = PTR_ERR(fs_enet_dev); |
| 729 | goto err; |
| 730 | } |
| 731 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 732 | model = of_get_property(np, "model", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 733 | if (model == NULL) { |
| 734 | ret = -ENODEV; |
| 735 | goto unreg; |
| 736 | } |
| 737 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 738 | mac_addr = of_get_mac_address(np); |
| 739 | if (mac_addr) |
| 740 | memcpy(fs_enet_data.macaddr, mac_addr, 6); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 741 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 742 | ph = of_get_property(np, "phy-handle", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 743 | phy = of_find_node_by_phandle(*ph); |
| 744 | |
| 745 | if (phy == NULL) { |
| 746 | ret = -ENODEV; |
| 747 | goto unreg; |
| 748 | } |
| 749 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 750 | phy_addr = of_get_property(phy, "reg", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 751 | fs_enet_data.phy_addr = *phy_addr; |
| 752 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 753 | phy_irq = of_get_property(phy, "interrupts", NULL); |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 754 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 755 | id = of_get_property(np, "device-id", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 756 | fs_enet_data.fs_no = *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 757 | strcpy(fs_enet_data.fs_type, model); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 758 | |
| 759 | mdio = of_get_parent(phy); |
| 760 | ret = of_address_to_resource(mdio, 0, &res); |
| 761 | if (ret) { |
| 762 | of_node_put(phy); |
| 763 | of_node_put(mdio); |
| 764 | goto unreg; |
| 765 | } |
| 766 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 767 | fs_enet_data.clk_rx = *((u32 *)of_get_property(np, |
| 768 | "rx-clock", NULL)); |
| 769 | fs_enet_data.clk_tx = *((u32 *)of_get_property(np, |
| 770 | "tx-clock", NULL)); |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 771 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 772 | if (strstr(model, "FCC")) { |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 773 | int fcc_index = *id - 1; |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 774 | const unsigned char *mdio_bb_prop; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 775 | |
Vitaly Bordug | fc8e50e | 2006-09-21 22:37:58 +0400 | [diff] [blame] | 776 | fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 777 | fs_enet_data.rx_ring = 32; |
| 778 | fs_enet_data.tx_ring = 32; |
| 779 | fs_enet_data.rx_copybreak = 240; |
| 780 | fs_enet_data.use_napi = 0; |
| 781 | fs_enet_data.napi_weight = 17; |
| 782 | fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index); |
| 783 | fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index); |
| 784 | fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index); |
| 785 | |
| 786 | snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x", |
| 787 | (u32)res.start, fs_enet_data.phy_addr); |
| 788 | fs_enet_data.bus_id = (char*)&bus_id[(*id)]; |
Vitaly Bordug | d3465c9 | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 789 | fs_enet_data.init_ioports = init_fcc_ioports; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 790 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 791 | mdio_bb_prop = of_get_property(phy, "bitbang", NULL); |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 792 | if (mdio_bb_prop) { |
| 793 | struct platform_device *fs_enet_mdio_bb_dev; |
| 794 | struct fs_mii_bb_platform_info fs_enet_mdio_bb_data; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 795 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 796 | fs_enet_mdio_bb_dev = |
| 797 | platform_device_register_simple("fsl-bb-mdio", |
| 798 | i, NULL, 0); |
| 799 | memset(&fs_enet_mdio_bb_data, 0, |
| 800 | sizeof(struct fs_mii_bb_platform_info)); |
| 801 | fs_enet_mdio_bb_data.mdio_dat.bit = |
| 802 | mdio_bb_prop[0]; |
| 803 | fs_enet_mdio_bb_data.mdio_dir.bit = |
| 804 | mdio_bb_prop[1]; |
| 805 | fs_enet_mdio_bb_data.mdc_dat.bit = |
| 806 | mdio_bb_prop[2]; |
| 807 | fs_enet_mdio_bb_data.mdio_port = |
| 808 | mdio_bb_prop[3]; |
| 809 | fs_enet_mdio_bb_data.mdc_port = |
| 810 | mdio_bb_prop[4]; |
| 811 | fs_enet_mdio_bb_data.delay = |
| 812 | mdio_bb_prop[5]; |
| 813 | |
| 814 | fs_enet_mdio_bb_data.irq[0] = phy_irq[0]; |
| 815 | fs_enet_mdio_bb_data.irq[1] = -1; |
| 816 | fs_enet_mdio_bb_data.irq[2] = -1; |
| 817 | fs_enet_mdio_bb_data.irq[3] = phy_irq[0]; |
| 818 | fs_enet_mdio_bb_data.irq[31] = -1; |
| 819 | |
| 820 | fs_enet_mdio_bb_data.mdio_dat.offset = |
| 821 | (u32)&cpm2_immr->im_ioport.iop_pdatc; |
| 822 | fs_enet_mdio_bb_data.mdio_dir.offset = |
| 823 | (u32)&cpm2_immr->im_ioport.iop_pdirc; |
| 824 | fs_enet_mdio_bb_data.mdc_dat.offset = |
| 825 | (u32)&cpm2_immr->im_ioport.iop_pdatc; |
| 826 | |
| 827 | ret = platform_device_add_data( |
| 828 | fs_enet_mdio_bb_dev, |
| 829 | &fs_enet_mdio_bb_data, |
| 830 | sizeof(struct fs_mii_bb_platform_info)); |
| 831 | if (ret) |
| 832 | goto unreg; |
| 833 | } |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 834 | |
Vitaly Bordug | ed943c1 | 2006-10-02 22:41:50 +0400 | [diff] [blame] | 835 | of_node_put(phy); |
| 836 | of_node_put(mdio); |
| 837 | |
| 838 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
| 839 | sizeof(struct |
| 840 | fs_platform_info)); |
Olof Johansson | 2b00b25 | 2006-10-05 21:16:48 -0500 | [diff] [blame] | 841 | if (ret) |
| 842 | goto unreg; |
| 843 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 844 | } |
| 845 | return 0; |
| 846 | |
| 847 | unreg: |
| 848 | platform_device_unregister(fs_enet_dev); |
| 849 | err: |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | arch_initcall(fs_enet_of_init); |
| 854 | |
| 855 | static const char scc_regs[] = "regs"; |
| 856 | static const char scc_pram[] = "pram"; |
| 857 | |
| 858 | static int __init cpm_uart_of_init(void) |
| 859 | { |
| 860 | struct device_node *np; |
| 861 | unsigned int i; |
| 862 | struct platform_device *cpm_uart_dev; |
| 863 | int ret; |
| 864 | |
| 865 | for (np = NULL, i = 0; |
| 866 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; |
| 867 | i++) { |
| 868 | struct resource r[3]; |
| 869 | struct fs_uart_platform_info cpm_uart_data; |
| 870 | const int *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 871 | const char *model; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 872 | |
| 873 | memset(r, 0, sizeof(r)); |
| 874 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); |
| 875 | |
| 876 | ret = of_address_to_resource(np, 0, &r[0]); |
| 877 | if (ret) |
| 878 | goto err; |
| 879 | |
| 880 | r[0].name = scc_regs; |
| 881 | |
| 882 | ret = of_address_to_resource(np, 1, &r[1]); |
| 883 | if (ret) |
| 884 | goto err; |
| 885 | r[1].name = scc_pram; |
| 886 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 887 | of_irq_to_resource(np, 0, &r[2]); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 888 | |
| 889 | cpm_uart_dev = |
| 890 | platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3); |
| 891 | |
| 892 | if (IS_ERR(cpm_uart_dev)) { |
| 893 | ret = PTR_ERR(cpm_uart_dev); |
| 894 | goto err; |
| 895 | } |
| 896 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 897 | id = of_get_property(np, "device-id", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 898 | cpm_uart_data.fs_no = *id; |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 899 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 900 | model = of_get_property(np, "model", NULL); |
Vitaly Bordug | 611a15a | 2006-09-21 22:38:05 +0400 | [diff] [blame] | 901 | strcpy(cpm_uart_data.fs_type, model); |
| 902 | |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 903 | cpm_uart_data.uart_clk = ppc_proc_freq; |
| 904 | |
| 905 | cpm_uart_data.tx_num_fifo = 4; |
| 906 | cpm_uart_data.tx_buf_size = 32; |
| 907 | cpm_uart_data.rx_num_fifo = 4; |
| 908 | cpm_uart_data.rx_buf_size = 32; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 909 | cpm_uart_data.clk_rx = *((u32 *)of_get_property(np, |
| 910 | "rx-clock", NULL)); |
| 911 | cpm_uart_data.clk_tx = *((u32 *)of_get_property(np, |
| 912 | "tx-clock", NULL)); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 913 | |
| 914 | ret = |
| 915 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, |
| 916 | sizeof(struct |
| 917 | fs_uart_platform_info)); |
| 918 | if (ret) |
| 919 | goto unreg; |
| 920 | } |
| 921 | |
| 922 | return 0; |
| 923 | |
| 924 | unreg: |
| 925 | platform_device_unregister(cpm_uart_dev); |
| 926 | err: |
| 927 | return ret; |
| 928 | } |
| 929 | |
| 930 | arch_initcall(cpm_uart_of_init); |
| 931 | #endif /* CONFIG_CPM2 */ |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 932 | |
| 933 | #ifdef CONFIG_8xx |
| 934 | |
| 935 | extern void init_scc_ioports(struct fs_platform_info*); |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 936 | extern int platform_device_skip(const char *model, int id); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 937 | |
| 938 | static int __init fs_enet_mdio_of_init(void) |
| 939 | { |
| 940 | struct device_node *np; |
| 941 | unsigned int i; |
| 942 | struct platform_device *mdio_dev; |
| 943 | struct resource res; |
| 944 | int ret; |
| 945 | |
| 946 | for (np = NULL, i = 0; |
| 947 | (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL; |
| 948 | i++) { |
| 949 | struct fs_mii_fec_platform_info mdio_data; |
| 950 | |
| 951 | memset(&res, 0, sizeof(res)); |
| 952 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 953 | |
| 954 | ret = of_address_to_resource(np, 0, &res); |
| 955 | if (ret) |
| 956 | goto err; |
| 957 | |
| 958 | mdio_dev = |
| 959 | platform_device_register_simple("fsl-cpm-fec-mdio", |
| 960 | res.start, &res, 1); |
| 961 | if (IS_ERR(mdio_dev)) { |
| 962 | ret = PTR_ERR(mdio_dev); |
| 963 | goto err; |
| 964 | } |
| 965 | |
| 966 | mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1; |
| 967 | |
| 968 | ret = |
| 969 | platform_device_add_data(mdio_dev, &mdio_data, |
| 970 | sizeof(struct fs_mii_fec_platform_info)); |
| 971 | if (ret) |
| 972 | goto unreg; |
| 973 | } |
| 974 | return 0; |
| 975 | |
| 976 | unreg: |
| 977 | platform_device_unregister(mdio_dev); |
| 978 | err: |
| 979 | return ret; |
| 980 | } |
| 981 | |
| 982 | arch_initcall(fs_enet_mdio_of_init); |
| 983 | |
| 984 | static const char *enet_regs = "regs"; |
| 985 | static const char *enet_pram = "pram"; |
| 986 | static const char *enet_irq = "interrupt"; |
| 987 | static char bus_id[9][BUS_ID_SIZE]; |
| 988 | |
| 989 | static int __init fs_enet_of_init(void) |
| 990 | { |
| 991 | struct device_node *np; |
| 992 | unsigned int i; |
| 993 | struct platform_device *fs_enet_dev = NULL; |
| 994 | struct resource res; |
| 995 | int ret; |
| 996 | |
| 997 | for (np = NULL, i = 0; |
| 998 | (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; |
| 999 | i++) { |
| 1000 | struct resource r[4]; |
| 1001 | struct device_node *phy = NULL, *mdio = NULL; |
| 1002 | struct fs_platform_info fs_enet_data; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1003 | const unsigned int *id; |
| 1004 | const unsigned int *phy_addr; |
Scott Wood | b7a6912 | 2007-05-09 03:15:34 +1000 | [diff] [blame] | 1005 | const void *mac_addr; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1006 | const phandle *ph; |
| 1007 | const char *model; |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1008 | |
| 1009 | memset(r, 0, sizeof(r)); |
| 1010 | memset(&fs_enet_data, 0, sizeof(fs_enet_data)); |
| 1011 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1012 | model = of_get_property(np, "model", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1013 | if (model == NULL) { |
| 1014 | ret = -ENODEV; |
| 1015 | goto unreg; |
| 1016 | } |
| 1017 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1018 | id = of_get_property(np, "device-id", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1019 | fs_enet_data.fs_no = *id; |
| 1020 | |
| 1021 | if (platform_device_skip(model, *id)) |
| 1022 | continue; |
| 1023 | |
| 1024 | ret = of_address_to_resource(np, 0, &r[0]); |
| 1025 | if (ret) |
| 1026 | goto err; |
| 1027 | r[0].name = enet_regs; |
| 1028 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 1029 | mac_addr = of_get_mac_address(np); |
| 1030 | if (mac_addr) |
| 1031 | memcpy(fs_enet_data.macaddr, mac_addr, 6); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1032 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1033 | ph = of_get_property(np, "phy-handle", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1034 | if (ph != NULL) |
| 1035 | phy = of_find_node_by_phandle(*ph); |
| 1036 | |
| 1037 | if (phy != NULL) { |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1038 | phy_addr = of_get_property(phy, "reg", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1039 | fs_enet_data.phy_addr = *phy_addr; |
| 1040 | fs_enet_data.has_phy = 1; |
| 1041 | |
| 1042 | mdio = of_get_parent(phy); |
| 1043 | ret = of_address_to_resource(mdio, 0, &res); |
| 1044 | if (ret) { |
| 1045 | of_node_put(phy); |
| 1046 | of_node_put(mdio); |
| 1047 | goto unreg; |
| 1048 | } |
| 1049 | } |
| 1050 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1051 | model = of_get_property(np, "model", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1052 | strcpy(fs_enet_data.fs_type, model); |
| 1053 | |
| 1054 | if (strstr(model, "FEC")) { |
| 1055 | r[1].start = r[1].end = irq_of_parse_and_map(np, 0); |
| 1056 | r[1].flags = IORESOURCE_IRQ; |
| 1057 | r[1].name = enet_irq; |
| 1058 | |
| 1059 | fs_enet_dev = |
| 1060 | platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2); |
| 1061 | |
| 1062 | if (IS_ERR(fs_enet_dev)) { |
| 1063 | ret = PTR_ERR(fs_enet_dev); |
| 1064 | goto err; |
| 1065 | } |
| 1066 | |
| 1067 | fs_enet_data.rx_ring = 128; |
| 1068 | fs_enet_data.tx_ring = 16; |
| 1069 | fs_enet_data.rx_copybreak = 240; |
| 1070 | fs_enet_data.use_napi = 1; |
| 1071 | fs_enet_data.napi_weight = 17; |
| 1072 | |
| 1073 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x", |
| 1074 | (u32)res.start, fs_enet_data.phy_addr); |
| 1075 | fs_enet_data.bus_id = (char*)&bus_id[i]; |
| 1076 | fs_enet_data.init_ioports = init_fec_ioports; |
| 1077 | } |
| 1078 | if (strstr(model, "SCC")) { |
| 1079 | ret = of_address_to_resource(np, 1, &r[1]); |
| 1080 | if (ret) |
| 1081 | goto err; |
| 1082 | r[1].name = enet_pram; |
| 1083 | |
| 1084 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); |
| 1085 | r[2].flags = IORESOURCE_IRQ; |
| 1086 | r[2].name = enet_irq; |
| 1087 | |
| 1088 | fs_enet_dev = |
| 1089 | platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3); |
| 1090 | |
| 1091 | if (IS_ERR(fs_enet_dev)) { |
| 1092 | ret = PTR_ERR(fs_enet_dev); |
| 1093 | goto err; |
| 1094 | } |
| 1095 | |
| 1096 | fs_enet_data.rx_ring = 64; |
| 1097 | fs_enet_data.tx_ring = 8; |
| 1098 | fs_enet_data.rx_copybreak = 240; |
| 1099 | fs_enet_data.use_napi = 1; |
| 1100 | fs_enet_data.napi_weight = 17; |
| 1101 | |
| 1102 | snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1"); |
| 1103 | fs_enet_data.bus_id = (char*)&bus_id[i]; |
| 1104 | fs_enet_data.init_ioports = init_scc_ioports; |
| 1105 | } |
| 1106 | |
| 1107 | of_node_put(phy); |
| 1108 | of_node_put(mdio); |
| 1109 | |
| 1110 | ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, |
| 1111 | sizeof(struct |
| 1112 | fs_platform_info)); |
| 1113 | if (ret) |
| 1114 | goto unreg; |
| 1115 | } |
| 1116 | return 0; |
| 1117 | |
| 1118 | unreg: |
| 1119 | platform_device_unregister(fs_enet_dev); |
| 1120 | err: |
| 1121 | return ret; |
| 1122 | } |
| 1123 | |
| 1124 | arch_initcall(fs_enet_of_init); |
| 1125 | |
Vitaly Bordug | 80128ff | 2007-07-09 11:37:35 -0700 | [diff] [blame] | 1126 | static int __init fsl_pcmcia_of_init(void) |
| 1127 | { |
| 1128 | struct device_node *np = NULL; |
| 1129 | /* |
| 1130 | * Register all the devices which type is "pcmcia" |
| 1131 | */ |
| 1132 | while ((np = of_find_compatible_node(np, |
| 1133 | "pcmcia", "fsl,pq-pcmcia")) != NULL) |
| 1134 | of_platform_device_create(np, "m8xx-pcmcia", NULL); |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
| 1138 | arch_initcall(fsl_pcmcia_of_init); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1139 | |
| 1140 | static const char *smc_regs = "regs"; |
| 1141 | static const char *smc_pram = "pram"; |
| 1142 | |
| 1143 | static int __init cpm_smc_uart_of_init(void) |
| 1144 | { |
| 1145 | struct device_node *np; |
| 1146 | unsigned int i; |
| 1147 | struct platform_device *cpm_uart_dev; |
| 1148 | int ret; |
| 1149 | |
| 1150 | for (np = NULL, i = 0; |
| 1151 | (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; |
| 1152 | i++) { |
| 1153 | struct resource r[3]; |
| 1154 | struct fs_uart_platform_info cpm_uart_data; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1155 | const int *id; |
| 1156 | const char *model; |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1157 | |
| 1158 | memset(r, 0, sizeof(r)); |
| 1159 | memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); |
| 1160 | |
| 1161 | ret = of_address_to_resource(np, 0, &r[0]); |
| 1162 | if (ret) |
| 1163 | goto err; |
| 1164 | |
| 1165 | r[0].name = smc_regs; |
| 1166 | |
| 1167 | ret = of_address_to_resource(np, 1, &r[1]); |
| 1168 | if (ret) |
| 1169 | goto err; |
| 1170 | r[1].name = smc_pram; |
| 1171 | |
| 1172 | r[2].start = r[2].end = irq_of_parse_and_map(np, 0); |
| 1173 | r[2].flags = IORESOURCE_IRQ; |
| 1174 | |
| 1175 | cpm_uart_dev = |
| 1176 | platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3); |
| 1177 | |
| 1178 | if (IS_ERR(cpm_uart_dev)) { |
| 1179 | ret = PTR_ERR(cpm_uart_dev); |
| 1180 | goto err; |
| 1181 | } |
| 1182 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1183 | model = of_get_property(np, "model", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1184 | strcpy(cpm_uart_data.fs_type, model); |
| 1185 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 1186 | id = of_get_property(np, "device-id", NULL); |
Vitaly Bordug | 88bdc6f | 2007-01-24 22:41:15 +0300 | [diff] [blame] | 1187 | cpm_uart_data.fs_no = *id; |
| 1188 | cpm_uart_data.uart_clk = ppc_proc_freq; |
| 1189 | |
| 1190 | cpm_uart_data.tx_num_fifo = 4; |
| 1191 | cpm_uart_data.tx_buf_size = 32; |
| 1192 | cpm_uart_data.rx_num_fifo = 4; |
| 1193 | cpm_uart_data.rx_buf_size = 32; |
| 1194 | |
| 1195 | ret = |
| 1196 | platform_device_add_data(cpm_uart_dev, &cpm_uart_data, |
| 1197 | sizeof(struct |
| 1198 | fs_uart_platform_info)); |
| 1199 | if (ret) |
| 1200 | goto unreg; |
| 1201 | } |
| 1202 | |
| 1203 | return 0; |
| 1204 | |
| 1205 | unreg: |
| 1206 | platform_device_unregister(cpm_uart_dev); |
| 1207 | err: |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
| 1211 | arch_initcall(cpm_smc_uart_of_init); |
| 1212 | |
| 1213 | #endif /* CONFIG_8xx */ |
Scott Wood | e631ae3 | 2007-09-14 13:04:54 -0500 | [diff] [blame] | 1214 | #endif /* CONFIG_PPC_CPM_NEW_BINDING */ |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 1215 | |
| 1216 | int __init fsl_spi_init(struct spi_board_info *board_infos, |
| 1217 | unsigned int num_board_infos, |
| 1218 | void (*activate_cs)(u8 cs, u8 polarity), |
| 1219 | void (*deactivate_cs)(u8 cs, u8 polarity)) |
| 1220 | { |
| 1221 | struct device_node *np; |
| 1222 | unsigned int i; |
| 1223 | const u32 *sysclk; |
| 1224 | |
Peter Korsgaard | 082ea86 | 2007-10-06 22:06:40 +0200 | [diff] [blame^] | 1225 | /* SPI controller is either clocked from QE or SoC clock */ |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 1226 | np = of_find_node_by_type(NULL, "qe"); |
| 1227 | if (!np) |
Peter Korsgaard | 082ea86 | 2007-10-06 22:06:40 +0200 | [diff] [blame^] | 1228 | np = of_find_node_by_type(NULL, "soc"); |
| 1229 | |
| 1230 | if (!np) |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 1231 | return -ENODEV; |
| 1232 | |
| 1233 | sysclk = of_get_property(np, "bus-frequency", NULL); |
| 1234 | if (!sysclk) |
| 1235 | return -ENODEV; |
| 1236 | |
| 1237 | for (np = NULL, i = 1; |
| 1238 | (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL; |
| 1239 | i++) { |
| 1240 | int ret = 0; |
| 1241 | unsigned int j; |
| 1242 | const void *prop; |
| 1243 | struct resource res[2]; |
| 1244 | struct platform_device *pdev; |
| 1245 | struct fsl_spi_platform_data pdata = { |
| 1246 | .activate_cs = activate_cs, |
| 1247 | .deactivate_cs = deactivate_cs, |
| 1248 | }; |
| 1249 | |
| 1250 | memset(res, 0, sizeof(res)); |
| 1251 | |
| 1252 | pdata.sysclk = *sysclk; |
| 1253 | |
| 1254 | prop = of_get_property(np, "reg", NULL); |
| 1255 | if (!prop) |
| 1256 | goto err; |
| 1257 | pdata.bus_num = *(u32 *)prop; |
| 1258 | |
| 1259 | prop = of_get_property(np, "mode", NULL); |
| 1260 | if (prop && !strcmp(prop, "cpu-qe")) |
| 1261 | pdata.qe_mode = 1; |
| 1262 | |
| 1263 | for (j = 0; j < num_board_infos; j++) { |
| 1264 | if (board_infos[j].bus_num == pdata.bus_num) |
| 1265 | pdata.max_chipselect++; |
| 1266 | } |
| 1267 | |
| 1268 | if (!pdata.max_chipselect) |
| 1269 | goto err; |
| 1270 | |
| 1271 | ret = of_address_to_resource(np, 0, &res[0]); |
| 1272 | if (ret) |
| 1273 | goto err; |
| 1274 | |
| 1275 | ret = of_irq_to_resource(np, 0, &res[1]); |
| 1276 | if (ret == NO_IRQ) |
| 1277 | goto err; |
| 1278 | |
| 1279 | pdev = platform_device_alloc("mpc83xx_spi", i); |
| 1280 | if (!pdev) |
| 1281 | goto err; |
| 1282 | |
| 1283 | ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 1284 | if (ret) |
| 1285 | goto unreg; |
| 1286 | |
| 1287 | ret = platform_device_add_resources(pdev, res, |
| 1288 | ARRAY_SIZE(res)); |
| 1289 | if (ret) |
| 1290 | goto unreg; |
| 1291 | |
| 1292 | ret = platform_device_register(pdev); |
| 1293 | if (ret) |
| 1294 | goto unreg; |
| 1295 | |
| 1296 | continue; |
| 1297 | unreg: |
| 1298 | platform_device_del(pdev); |
| 1299 | err: |
| 1300 | continue; |
| 1301 | } |
| 1302 | |
| 1303 | return spi_register_board_info(board_infos, num_board_infos); |
| 1304 | } |
Kumar Gala | e1c1575 | 2007-10-04 01:04:57 -0500 | [diff] [blame] | 1305 | |
| 1306 | #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx) |
| 1307 | static __be32 __iomem *rstcr; |
| 1308 | |
| 1309 | static int __init setup_rstcr(void) |
| 1310 | { |
| 1311 | struct device_node *np; |
| 1312 | np = of_find_node_by_name(NULL, "global-utilities"); |
| 1313 | if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) { |
| 1314 | const u32 *prop = of_get_property(np, "reg", NULL); |
| 1315 | if (prop) { |
| 1316 | /* map reset control register |
| 1317 | * 0xE00B0 is offset of reset control register |
| 1318 | */ |
| 1319 | rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff); |
| 1320 | if (!rstcr) |
| 1321 | printk (KERN_EMERG "Error: reset control " |
| 1322 | "register not mapped!\n"); |
| 1323 | } |
| 1324 | } else |
| 1325 | printk (KERN_INFO "rstcr compatible register does not exist!\n"); |
| 1326 | if (np) |
| 1327 | of_node_put(np); |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | arch_initcall(setup_rstcr); |
| 1332 | |
| 1333 | void fsl_rstcr_restart(char *cmd) |
| 1334 | { |
| 1335 | local_irq_disable(); |
| 1336 | if (rstcr) |
| 1337 | /* set reset control register */ |
| 1338 | out_be32(rstcr, 0x2); /* HRESET_REQ */ |
| 1339 | |
| 1340 | while (1) ; |
| 1341 | } |
| 1342 | #endif |