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