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 | |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 78 | static u32 sysfreq = -1; |
| 79 | |
| 80 | u32 fsl_get_sys_freq(void) |
| 81 | { |
| 82 | struct device_node *soc; |
| 83 | const u32 *prop; |
| 84 | int size; |
| 85 | |
| 86 | if (sysfreq != -1) |
| 87 | return sysfreq; |
| 88 | |
| 89 | soc = of_find_node_by_type(NULL, "soc"); |
| 90 | if (!soc) |
| 91 | return -1; |
| 92 | |
| 93 | prop = of_get_property(soc, "clock-frequency", &size); |
| 94 | if (!prop || size != sizeof(*prop) || *prop == 0) |
| 95 | prop = of_get_property(soc, "bus-frequency", &size); |
| 96 | |
| 97 | if (prop && size == sizeof(*prop)) |
| 98 | sysfreq = *prop; |
| 99 | |
| 100 | of_node_put(soc); |
| 101 | return sysfreq; |
| 102 | } |
| 103 | EXPORT_SYMBOL(fsl_get_sys_freq); |
| 104 | |
Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 105 | #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx) |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 106 | |
| 107 | static u32 brgfreq = -1; |
| 108 | |
| 109 | u32 get_brgfreq(void) |
| 110 | { |
| 111 | struct device_node *node; |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 112 | const unsigned int *prop; |
| 113 | int size; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 114 | |
| 115 | if (brgfreq != -1) |
| 116 | return brgfreq; |
| 117 | |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 118 | node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg"); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 119 | if (node) { |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 120 | prop = of_get_property(node, "clock-frequency", &size); |
| 121 | if (prop && size == 4) |
| 122 | brgfreq = *prop; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 123 | |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 124 | of_node_put(node); |
| 125 | return brgfreq; |
| 126 | } |
| 127 | |
| 128 | /* Legacy device binding -- will go away when no users are left. */ |
| 129 | node = of_find_node_by_type(NULL, "cpm"); |
Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 130 | if (!node) |
| 131 | node = of_find_compatible_node(NULL, NULL, "fsl,qe"); |
| 132 | if (!node) |
| 133 | node = of_find_node_by_type(NULL, "qe"); |
| 134 | |
Scott Wood | 6d817aa | 2007-08-29 15:08:40 -0500 | [diff] [blame] | 135 | if (node) { |
| 136 | prop = of_get_property(node, "brg-frequency", &size); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 137 | if (prop && size == 4) |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 138 | brgfreq = *prop; |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 139 | |
Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 140 | if (brgfreq == -1 || brgfreq == 0) { |
| 141 | prop = of_get_property(node, "bus-frequency", &size); |
| 142 | if (prop && size == 4) |
| 143 | brgfreq = *prop / 2; |
| 144 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 145 | of_node_put(node); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 146 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 147 | |
| 148 | return brgfreq; |
| 149 | } |
| 150 | |
| 151 | EXPORT_SYMBOL(get_brgfreq); |
| 152 | |
| 153 | static u32 fs_baudrate = -1; |
| 154 | |
| 155 | u32 get_baudrate(void) |
| 156 | { |
| 157 | struct device_node *node; |
| 158 | |
| 159 | if (fs_baudrate != -1) |
| 160 | return fs_baudrate; |
| 161 | |
| 162 | node = of_find_node_by_type(NULL, "serial"); |
| 163 | if (node) { |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 164 | int size; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 165 | const unsigned int *prop = of_get_property(node, |
| 166 | "current-speed", &size); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 167 | |
| 168 | if (prop) |
| 169 | fs_baudrate = *prop; |
| 170 | of_node_put(node); |
Scott Wood | f923473 | 2007-08-20 11:38:12 -0500 | [diff] [blame] | 171 | } |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 172 | |
| 173 | return fs_baudrate; |
| 174 | } |
| 175 | |
| 176 | EXPORT_SYMBOL(get_baudrate); |
| 177 | #endif /* CONFIG_CPM2 */ |
| 178 | |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 179 | #ifdef CONFIG_FIXED_PHY |
| 180 | static int __init of_add_fixed_phys(void) |
| 181 | { |
| 182 | int ret; |
| 183 | struct device_node *np; |
| 184 | u32 *fixed_link; |
| 185 | struct fixed_phy_status status = {}; |
| 186 | |
| 187 | for_each_node_by_name(np, "ethernet") { |
| 188 | fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL); |
| 189 | if (!fixed_link) |
| 190 | continue; |
| 191 | |
| 192 | status.link = 1; |
| 193 | status.duplex = fixed_link[1]; |
| 194 | status.speed = fixed_link[2]; |
| 195 | status.pause = fixed_link[3]; |
| 196 | status.asym_pause = fixed_link[4]; |
| 197 | |
| 198 | ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status); |
| 199 | if (ret) { |
| 200 | of_node_put(np); |
| 201 | return ret; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | arch_initcall(of_add_fixed_phys); |
| 208 | #endif /* CONFIG_FIXED_PHY */ |
| 209 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 210 | static int __init gfar_mdio_of_init(void) |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 211 | { |
Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 212 | struct device_node *np = NULL; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 213 | struct platform_device *mdio_dev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 214 | struct resource res; |
| 215 | int ret; |
| 216 | |
Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 217 | np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio"); |
| 218 | |
| 219 | /* try the deprecated version */ |
| 220 | if (!np) |
| 221 | np = of_find_compatible_node(np, "mdio", "gianfar"); |
| 222 | |
| 223 | if (np) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 224 | int k; |
| 225 | struct device_node *child = NULL; |
| 226 | struct gianfar_mdio_data mdio_data; |
| 227 | |
| 228 | memset(&res, 0, sizeof(res)); |
| 229 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 230 | |
| 231 | ret = of_address_to_resource(np, 0, &res); |
| 232 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 233 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 234 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 235 | mdio_dev = |
| 236 | platform_device_register_simple("fsl-gianfar_mdio", |
| 237 | res.start, &res, 1); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 238 | if (IS_ERR(mdio_dev)) { |
| 239 | ret = PTR_ERR(mdio_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 240 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | for (k = 0; k < 32; k++) |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 244 | mdio_data.irq[k] = PHY_POLL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 245 | |
| 246 | while ((child = of_get_next_child(np, child)) != NULL) { |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 247 | int irq = irq_of_parse_and_map(child, 0); |
| 248 | if (irq != NO_IRQ) { |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 249 | const u32 *id = of_get_property(child, |
| 250 | "reg", NULL); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 251 | mdio_data.irq[*id] = irq; |
| 252 | } |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 253 | } |
| 254 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 255 | ret = |
| 256 | platform_device_add_data(mdio_dev, &mdio_data, |
| 257 | sizeof(struct gianfar_mdio_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 258 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 259 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 262 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 263 | return 0; |
| 264 | |
| 265 | unreg: |
| 266 | platform_device_unregister(mdio_dev); |
| 267 | err: |
Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 268 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | arch_initcall(gfar_mdio_of_init); |
| 273 | |
| 274 | static const char *gfar_tx_intr = "tx"; |
| 275 | static const char *gfar_rx_intr = "rx"; |
| 276 | static const char *gfar_err_intr = "error"; |
| 277 | |
| 278 | static int __init gfar_of_init(void) |
| 279 | { |
| 280 | struct device_node *np; |
| 281 | unsigned int i; |
| 282 | struct platform_device *gfar_dev; |
| 283 | struct resource res; |
| 284 | int ret; |
| 285 | |
| 286 | for (np = NULL, i = 0; |
| 287 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; |
| 288 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 289 | struct resource r[4]; |
| 290 | struct device_node *phy, *mdio; |
| 291 | struct gianfar_platform_data gfar_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 292 | const unsigned int *id; |
| 293 | const char *model; |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 294 | const char *ctype; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 295 | const void *mac_addr; |
| 296 | const phandle *ph; |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 297 | int n_res = 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 298 | |
| 299 | memset(r, 0, sizeof(r)); |
| 300 | memset(&gfar_data, 0, sizeof(gfar_data)); |
| 301 | |
| 302 | ret = of_address_to_resource(np, 0, &r[0]); |
| 303 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 304 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 305 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 306 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 307 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 308 | model = of_get_property(np, "model", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 309 | |
| 310 | /* If we aren't the FEC we have multiple interrupts */ |
| 311 | if (model && strcasecmp(model, "FEC")) { |
| 312 | r[1].name = gfar_tx_intr; |
| 313 | |
| 314 | r[2].name = gfar_rx_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 315 | of_irq_to_resource(np, 1, &r[2]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 316 | |
| 317 | r[3].name = gfar_err_intr; |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 318 | of_irq_to_resource(np, 2, &r[3]); |
Jon Loeliger | 919fede | 2006-07-31 15:35:41 -0500 | [diff] [blame] | 319 | |
| 320 | n_res += 2; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 321 | } |
| 322 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 323 | gfar_dev = |
| 324 | platform_device_register_simple("fsl-gianfar", i, &r[0], |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 325 | n_res); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 326 | |
| 327 | if (IS_ERR(gfar_dev)) { |
| 328 | ret = PTR_ERR(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 329 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 330 | } |
| 331 | |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 332 | mac_addr = of_get_mac_address(np); |
Jon Loeliger | f583165 | 2006-08-17 08:42:35 -0500 | [diff] [blame] | 333 | if (mac_addr) |
| 334 | memcpy(gfar_data.mac_addr, mac_addr, 6); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 335 | |
| 336 | if (model && !strcasecmp(model, "TSEC")) |
| 337 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 338 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 339 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 340 | FSL_GIANFAR_DEV_HAS_RMON | |
| 341 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 342 | if (model && !strcasecmp(model, "eTSEC")) |
| 343 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 344 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 345 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 346 | FSL_GIANFAR_DEV_HAS_RMON | |
| 347 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
| 348 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 349 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 350 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 351 | |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 352 | ctype = of_get_property(np, "phy-connection-type", NULL); |
| 353 | |
| 354 | /* We only care about rgmii-id. The rest are autodetected */ |
| 355 | if (ctype && !strcmp(ctype, "rgmii-id")) |
| 356 | gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID; |
| 357 | else |
| 358 | gfar_data.interface = PHY_INTERFACE_MODE_MII; |
| 359 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 360 | ph = of_get_property(np, "phy-handle", NULL); |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 361 | if (ph == NULL) { |
| 362 | u32 *fixed_link; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 363 | |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 364 | fixed_link = (u32 *)of_get_property(np, "fixed-link", |
| 365 | NULL); |
| 366 | if (!fixed_link) { |
| 367 | ret = -ENODEV; |
| 368 | goto unreg; |
| 369 | } |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 370 | |
Andy Fleming | 9d9326d | 2008-04-09 19:38:13 -0500 | [diff] [blame] | 371 | snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0"); |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 372 | gfar_data.phy_id = fixed_link[0]; |
| 373 | } else { |
| 374 | phy = of_find_node_by_phandle(*ph); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 375 | |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 376 | if (phy == NULL) { |
| 377 | ret = -ENODEV; |
| 378 | goto unreg; |
| 379 | } |
| 380 | |
| 381 | mdio = of_get_parent(phy); |
| 382 | |
| 383 | id = of_get_property(phy, "reg", NULL); |
| 384 | ret = of_address_to_resource(mdio, 0, &res); |
| 385 | if (ret) { |
| 386 | of_node_put(phy); |
| 387 | of_node_put(mdio); |
| 388 | goto unreg; |
| 389 | } |
| 390 | |
| 391 | gfar_data.phy_id = *id; |
Becky Bruce | 128cf7f | 2008-05-01 18:15:45 -0500 | [diff] [blame] | 392 | snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx", |
| 393 | (unsigned long long)res.start); |
Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 394 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 395 | of_node_put(phy); |
| 396 | of_node_put(mdio); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 397 | } |
| 398 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 399 | ret = |
| 400 | platform_device_add_data(gfar_dev, &gfar_data, |
| 401 | sizeof(struct |
| 402 | gianfar_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 403 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 404 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | return 0; |
| 408 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 409 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 410 | platform_device_unregister(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 411 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 412 | return ret; |
| 413 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 414 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 415 | arch_initcall(gfar_of_init); |
| 416 | |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 417 | #ifdef CONFIG_I2C_BOARDINFO |
| 418 | #include <linux/i2c.h> |
| 419 | struct i2c_driver_device { |
| 420 | char *of_device; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 421 | char *i2c_type; |
| 422 | }; |
| 423 | |
| 424 | static struct i2c_driver_device i2c_devices[] __initdata = { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 425 | {"ricoh,rs5c372a", "rs5c372a"}, |
| 426 | {"ricoh,rs5c372b", "rs5c372b"}, |
| 427 | {"ricoh,rv5c386", "rv5c386"}, |
| 428 | {"ricoh,rv5c387a", "rv5c387a"}, |
| 429 | {"dallas,ds1307", "ds1307"}, |
| 430 | {"dallas,ds1337", "ds1337"}, |
| 431 | {"dallas,ds1338", "ds1338"}, |
| 432 | {"dallas,ds1339", "ds1339"}, |
| 433 | {"dallas,ds1340", "ds1340"}, |
| 434 | {"stm,m41t00", "m41t00"}, |
| 435 | {"dallas,ds1374", "rtc-ds1374"}, |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 436 | }; |
| 437 | |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 438 | static int __init of_find_i2c_driver(struct device_node *node, |
| 439 | struct i2c_board_info *info) |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 440 | { |
| 441 | int i; |
| 442 | |
| 443 | for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) { |
| 444 | if (!of_device_is_compatible(node, i2c_devices[i].of_device)) |
| 445 | continue; |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 446 | if (strlcpy(info->type, i2c_devices[i].i2c_type, |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 447 | I2C_NAME_SIZE) >= I2C_NAME_SIZE) |
| 448 | return -ENOMEM; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 449 | return 0; |
| 450 | } |
Timur Tabi | 22fb7d9 | 2008-05-15 17:04:57 -0500 | [diff] [blame^] | 451 | |
| 452 | pr_warning("fsl_soc.c: unrecognized i2c node %s\n", |
| 453 | (const char *) of_get_property(node, "compatible", NULL)); |
| 454 | |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 455 | return -ENODEV; |
| 456 | } |
| 457 | |
Guennadi Liakhovetski | e78bb5d | 2007-08-16 05:15:03 +1000 | [diff] [blame] | 458 | static void __init of_register_i2c_devices(struct device_node *adap_node, |
| 459 | int bus_num) |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 460 | { |
| 461 | struct device_node *node = NULL; |
| 462 | |
| 463 | while ((node = of_get_next_child(adap_node, node))) { |
Anton Vorontsov | da1bb3a | 2007-10-02 17:47:40 +0400 | [diff] [blame] | 464 | struct i2c_board_info info = {}; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 465 | const u32 *addr; |
| 466 | int len; |
| 467 | |
| 468 | addr = of_get_property(node, "reg", &len); |
| 469 | if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) { |
Peter Korsgaard | 210805e | 2007-09-20 12:42:12 +0200 | [diff] [blame] | 470 | printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n"); |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 471 | continue; |
| 472 | } |
| 473 | |
| 474 | info.irq = irq_of_parse_and_map(node, 0); |
| 475 | if (info.irq == NO_IRQ) |
| 476 | info.irq = -1; |
| 477 | |
| 478 | if (of_find_i2c_driver(node, &info) < 0) |
| 479 | continue; |
| 480 | |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 481 | info.addr = *addr; |
| 482 | |
| 483 | i2c_register_board_info(bus_num, &info, 1); |
| 484 | } |
| 485 | } |
| 486 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 487 | static int __init fsl_i2c_of_init(void) |
| 488 | { |
| 489 | struct device_node *np; |
Kumar Gala | ec9686c | 2007-12-11 23:17:24 -0600 | [diff] [blame] | 490 | unsigned int i = 0; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 491 | struct platform_device *i2c_dev; |
| 492 | int ret; |
| 493 | |
Kumar Gala | ec9686c | 2007-12-11 23:17:24 -0600 | [diff] [blame] | 494 | for_each_compatible_node(np, NULL, "fsl-i2c") { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 495 | struct resource r[2]; |
| 496 | struct fsl_i2c_platform_data i2c_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 497 | const unsigned char *flags = NULL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 498 | |
| 499 | memset(&r, 0, sizeof(r)); |
| 500 | memset(&i2c_data, 0, sizeof(i2c_data)); |
| 501 | |
| 502 | ret = of_address_to_resource(np, 0, &r[0]); |
| 503 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 504 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 505 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 506 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 507 | |
| 508 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); |
| 509 | if (IS_ERR(i2c_dev)) { |
| 510 | ret = PTR_ERR(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 511 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | i2c_data.device_flags = 0; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 515 | flags = of_get_property(np, "dfsrr", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 516 | if (flags) |
| 517 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; |
| 518 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 519 | flags = of_get_property(np, "fsl5200-clocking", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 520 | if (flags) |
| 521 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; |
| 522 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 523 | ret = |
| 524 | platform_device_add_data(i2c_dev, &i2c_data, |
| 525 | sizeof(struct |
| 526 | fsl_i2c_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 527 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 528 | goto unreg; |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 529 | |
Kumar Gala | ec9686c | 2007-12-11 23:17:24 -0600 | [diff] [blame] | 530 | of_register_i2c_devices(np, i++); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | return 0; |
| 534 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 535 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 536 | platform_device_unregister(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 537 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 538 | return ret; |
| 539 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 540 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 541 | arch_initcall(fsl_i2c_of_init); |
Guennadi Liakhovetski | d13ae86 | 2007-07-21 06:26:15 +1000 | [diff] [blame] | 542 | #endif |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 543 | |
| 544 | #ifdef CONFIG_PPC_83xx |
| 545 | static int __init mpc83xx_wdt_init(void) |
| 546 | { |
| 547 | struct resource r; |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 548 | struct device_node *np; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 549 | struct platform_device *dev; |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 550 | u32 freq = fsl_get_sys_freq(); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 551 | int ret; |
| 552 | |
| 553 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
| 554 | |
| 555 | if (!np) { |
| 556 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 557 | goto nodev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 558 | } |
| 559 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 560 | memset(&r, 0, sizeof(r)); |
| 561 | |
| 562 | ret = of_address_to_resource(np, 0, &r); |
| 563 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 564 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 565 | |
| 566 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 567 | if (IS_ERR(dev)) { |
| 568 | ret = PTR_ERR(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 569 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 570 | } |
| 571 | |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 572 | ret = platform_device_add_data(dev, &freq, sizeof(freq)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 573 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 574 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 575 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 576 | of_node_put(np); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 577 | return 0; |
| 578 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 579 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 580 | platform_device_unregister(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 581 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 582 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 583 | nodev: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 584 | return ret; |
| 585 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 586 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 587 | arch_initcall(mpc83xx_wdt_init); |
| 588 | #endif |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 589 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 590 | 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] | 591 | { |
| 592 | if (!phy_type) |
| 593 | return FSL_USB2_PHY_NONE; |
| 594 | if (!strcasecmp(phy_type, "ulpi")) |
| 595 | return FSL_USB2_PHY_ULPI; |
| 596 | if (!strcasecmp(phy_type, "utmi")) |
| 597 | return FSL_USB2_PHY_UTMI; |
| 598 | if (!strcasecmp(phy_type, "utmi_wide")) |
| 599 | return FSL_USB2_PHY_UTMI_WIDE; |
| 600 | if (!strcasecmp(phy_type, "serial")) |
| 601 | return FSL_USB2_PHY_SERIAL; |
| 602 | |
| 603 | return FSL_USB2_PHY_NONE; |
| 604 | } |
| 605 | |
| 606 | static int __init fsl_usb_of_init(void) |
| 607 | { |
| 608 | struct device_node *np; |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 609 | unsigned int i = 0; |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 610 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, |
| 611 | *usb_dev_dr_client = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 612 | int ret; |
| 613 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 614 | for_each_compatible_node(np, NULL, "fsl-usb2-mph") { |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 615 | struct resource r[2]; |
| 616 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 617 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 618 | |
| 619 | memset(&r, 0, sizeof(r)); |
| 620 | memset(&usb_data, 0, sizeof(usb_data)); |
| 621 | |
| 622 | ret = of_address_to_resource(np, 0, &r[0]); |
| 623 | if (ret) |
| 624 | goto err; |
| 625 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 626 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 627 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 628 | usb_dev_mph = |
| 629 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 630 | if (IS_ERR(usb_dev_mph)) { |
| 631 | ret = PTR_ERR(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 632 | goto err; |
| 633 | } |
| 634 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 635 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
| 636 | 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] | 637 | |
| 638 | usb_data.operating_mode = FSL_USB2_MPH_HOST; |
| 639 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 640 | prop = of_get_property(np, "port0", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 641 | if (prop) |
| 642 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; |
| 643 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 644 | prop = of_get_property(np, "port1", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 645 | if (prop) |
| 646 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; |
| 647 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 648 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 649 | usb_data.phy_mode = determine_usb_phy(prop); |
| 650 | |
| 651 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 652 | platform_device_add_data(usb_dev_mph, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 653 | sizeof(struct |
| 654 | fsl_usb2_platform_data)); |
| 655 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 656 | goto unreg_mph; |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 657 | i++; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 658 | } |
| 659 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 660 | for_each_compatible_node(np, NULL, "fsl-usb2-dr") { |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 661 | struct resource r[2]; |
| 662 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 663 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 664 | |
| 665 | memset(&r, 0, sizeof(r)); |
| 666 | memset(&usb_data, 0, sizeof(usb_data)); |
| 667 | |
| 668 | ret = of_address_to_resource(np, 0, &r[0]); |
| 669 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 670 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 671 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 672 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 673 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 674 | prop = of_get_property(np, "dr_mode", NULL); |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 675 | |
| 676 | if (!prop || !strcmp(prop, "host")) { |
| 677 | usb_data.operating_mode = FSL_USB2_DR_HOST; |
| 678 | usb_dev_dr_host = platform_device_register_simple( |
| 679 | "fsl-ehci", i, r, 2); |
| 680 | if (IS_ERR(usb_dev_dr_host)) { |
| 681 | ret = PTR_ERR(usb_dev_dr_host); |
| 682 | goto err; |
| 683 | } |
| 684 | } else if (prop && !strcmp(prop, "peripheral")) { |
| 685 | usb_data.operating_mode = FSL_USB2_DR_DEVICE; |
| 686 | usb_dev_dr_client = platform_device_register_simple( |
| 687 | "fsl-usb2-udc", i, r, 2); |
| 688 | if (IS_ERR(usb_dev_dr_client)) { |
| 689 | ret = PTR_ERR(usb_dev_dr_client); |
| 690 | goto err; |
| 691 | } |
| 692 | } else if (prop && !strcmp(prop, "otg")) { |
| 693 | usb_data.operating_mode = FSL_USB2_DR_OTG; |
| 694 | usb_dev_dr_host = platform_device_register_simple( |
| 695 | "fsl-ehci", i, r, 2); |
| 696 | if (IS_ERR(usb_dev_dr_host)) { |
| 697 | ret = PTR_ERR(usb_dev_dr_host); |
| 698 | goto err; |
| 699 | } |
| 700 | usb_dev_dr_client = platform_device_register_simple( |
| 701 | "fsl-usb2-udc", i, r, 2); |
| 702 | if (IS_ERR(usb_dev_dr_client)) { |
| 703 | ret = PTR_ERR(usb_dev_dr_client); |
| 704 | goto err; |
| 705 | } |
| 706 | } else { |
| 707 | ret = -EINVAL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 708 | goto err; |
| 709 | } |
| 710 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 711 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 712 | usb_data.phy_mode = determine_usb_phy(prop); |
| 713 | |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 714 | if (usb_dev_dr_host) { |
| 715 | usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; |
| 716 | usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> |
| 717 | dev.coherent_dma_mask; |
| 718 | if ((ret = platform_device_add_data(usb_dev_dr_host, |
| 719 | &usb_data, sizeof(struct |
| 720 | fsl_usb2_platform_data)))) |
| 721 | goto unreg_dr; |
| 722 | } |
| 723 | if (usb_dev_dr_client) { |
| 724 | usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; |
| 725 | usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> |
| 726 | dev.coherent_dma_mask; |
| 727 | if ((ret = platform_device_add_data(usb_dev_dr_client, |
| 728 | &usb_data, sizeof(struct |
| 729 | fsl_usb2_platform_data)))) |
| 730 | goto unreg_dr; |
| 731 | } |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 732 | i++; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 733 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 734 | return 0; |
| 735 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 736 | unreg_dr: |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 737 | if (usb_dev_dr_host) |
| 738 | platform_device_unregister(usb_dev_dr_host); |
| 739 | if (usb_dev_dr_client) |
| 740 | platform_device_unregister(usb_dev_dr_client); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 741 | unreg_mph: |
| 742 | if (usb_dev_mph) |
| 743 | platform_device_unregister(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 744 | err: |
| 745 | return ret; |
| 746 | } |
| 747 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 748 | arch_initcall(fsl_usb_of_init); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 749 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 750 | static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk, |
| 751 | struct spi_board_info *board_infos, |
| 752 | unsigned int num_board_infos, |
| 753 | void (*activate_cs)(u8 cs, u8 polarity), |
| 754 | void (*deactivate_cs)(u8 cs, u8 polarity)) |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 755 | { |
| 756 | struct device_node *np; |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 757 | unsigned int i = 0; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 758 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 759 | for_each_compatible_node(np, type, compatible) { |
| 760 | int ret; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 761 | unsigned int j; |
| 762 | const void *prop; |
| 763 | struct resource res[2]; |
| 764 | struct platform_device *pdev; |
| 765 | struct fsl_spi_platform_data pdata = { |
| 766 | .activate_cs = activate_cs, |
| 767 | .deactivate_cs = deactivate_cs, |
| 768 | }; |
| 769 | |
| 770 | memset(res, 0, sizeof(res)); |
| 771 | |
Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 772 | pdata.sysclk = sysclk; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 773 | |
| 774 | prop = of_get_property(np, "reg", NULL); |
| 775 | if (!prop) |
| 776 | goto err; |
| 777 | pdata.bus_num = *(u32 *)prop; |
| 778 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 779 | prop = of_get_property(np, "cell-index", NULL); |
| 780 | if (prop) |
| 781 | i = *(u32 *)prop; |
| 782 | |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 783 | prop = of_get_property(np, "mode", NULL); |
| 784 | if (prop && !strcmp(prop, "cpu-qe")) |
| 785 | pdata.qe_mode = 1; |
| 786 | |
| 787 | for (j = 0; j < num_board_infos; j++) { |
| 788 | if (board_infos[j].bus_num == pdata.bus_num) |
| 789 | pdata.max_chipselect++; |
| 790 | } |
| 791 | |
| 792 | if (!pdata.max_chipselect) |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 793 | continue; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 794 | |
| 795 | ret = of_address_to_resource(np, 0, &res[0]); |
| 796 | if (ret) |
| 797 | goto err; |
| 798 | |
| 799 | ret = of_irq_to_resource(np, 0, &res[1]); |
| 800 | if (ret == NO_IRQ) |
| 801 | goto err; |
| 802 | |
| 803 | pdev = platform_device_alloc("mpc83xx_spi", i); |
| 804 | if (!pdev) |
| 805 | goto err; |
| 806 | |
| 807 | ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 808 | if (ret) |
| 809 | goto unreg; |
| 810 | |
| 811 | ret = platform_device_add_resources(pdev, res, |
| 812 | ARRAY_SIZE(res)); |
| 813 | if (ret) |
| 814 | goto unreg; |
| 815 | |
Kim Phillips | dc4e420 | 2008-02-01 18:09:58 -0600 | [diff] [blame] | 816 | ret = platform_device_add(pdev); |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 817 | if (ret) |
| 818 | goto unreg; |
| 819 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 820 | goto next; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 821 | unreg: |
| 822 | platform_device_del(pdev); |
| 823 | err: |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 824 | pr_err("%s: registration failed\n", np->full_name); |
| 825 | next: |
| 826 | i++; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 827 | } |
| 828 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 829 | return i; |
| 830 | } |
| 831 | |
| 832 | int __init fsl_spi_init(struct spi_board_info *board_infos, |
| 833 | unsigned int num_board_infos, |
| 834 | void (*activate_cs)(u8 cs, u8 polarity), |
| 835 | void (*deactivate_cs)(u8 cs, u8 polarity)) |
| 836 | { |
| 837 | u32 sysclk = -1; |
| 838 | int ret; |
| 839 | |
| 840 | #ifdef CONFIG_QUICC_ENGINE |
| 841 | /* SPI controller is either clocked from QE or SoC clock */ |
| 842 | sysclk = get_brgfreq(); |
| 843 | #endif |
| 844 | if (sysclk == -1) { |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 845 | sysclk = fsl_get_sys_freq(); |
| 846 | if (sysclk == -1) |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 847 | return -ENODEV; |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos, |
| 851 | num_board_infos, activate_cs, deactivate_cs); |
| 852 | if (!ret) |
| 853 | of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos, |
| 854 | num_board_infos, activate_cs, deactivate_cs); |
| 855 | |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 856 | return spi_register_board_info(board_infos, num_board_infos); |
| 857 | } |
Kumar Gala | e1c1575 | 2007-10-04 01:04:57 -0500 | [diff] [blame] | 858 | |
| 859 | #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx) |
| 860 | static __be32 __iomem *rstcr; |
| 861 | |
| 862 | static int __init setup_rstcr(void) |
| 863 | { |
| 864 | struct device_node *np; |
| 865 | np = of_find_node_by_name(NULL, "global-utilities"); |
| 866 | if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) { |
| 867 | const u32 *prop = of_get_property(np, "reg", NULL); |
| 868 | if (prop) { |
| 869 | /* map reset control register |
| 870 | * 0xE00B0 is offset of reset control register |
| 871 | */ |
| 872 | rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff); |
| 873 | if (!rstcr) |
| 874 | printk (KERN_EMERG "Error: reset control " |
| 875 | "register not mapped!\n"); |
| 876 | } |
| 877 | } else |
| 878 | printk (KERN_INFO "rstcr compatible register does not exist!\n"); |
| 879 | if (np) |
| 880 | of_node_put(np); |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | arch_initcall(setup_rstcr); |
| 885 | |
| 886 | void fsl_rstcr_restart(char *cmd) |
| 887 | { |
| 888 | local_irq_disable(); |
| 889 | if (rstcr) |
| 890 | /* set reset control register */ |
| 891 | out_be32(rstcr, 0x2); /* HRESET_REQ */ |
| 892 | |
| 893 | while (1) ; |
| 894 | } |
| 895 | #endif |
York Sun | 6f90a8bd | 2008-04-28 02:15:36 -0700 | [diff] [blame] | 896 | |
| 897 | #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) |
| 898 | struct platform_diu_data_ops diu_ops = { |
| 899 | .diu_size = 1280 * 1024 * 4, /* default one 1280x1024 buffer */ |
| 900 | }; |
| 901 | EXPORT_SYMBOL(diu_ops); |
| 902 | |
| 903 | int __init preallocate_diu_videomemory(void) |
| 904 | { |
| 905 | pr_debug("diu_size=%lu\n", diu_ops.diu_size); |
| 906 | |
| 907 | diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0); |
| 908 | if (!diu_ops.diu_mem) { |
| 909 | printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n", |
| 910 | diu_ops.diu_size); |
| 911 | return -ENOMEM; |
| 912 | } |
| 913 | |
| 914 | pr_debug("diu_mem=%p\n", diu_ops.diu_mem); |
| 915 | |
| 916 | rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block), |
| 917 | diu_ops.diu_rh_block); |
| 918 | return rh_attach_region(&diu_ops.diu_rh_info, |
| 919 | (unsigned long) diu_ops.diu_mem, |
| 920 | diu_ops.diu_size); |
| 921 | } |
| 922 | |
| 923 | static int __init early_parse_diufb(char *p) |
| 924 | { |
| 925 | if (!p) |
| 926 | return 1; |
| 927 | |
| 928 | diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8); |
| 929 | |
| 930 | pr_debug("diu_size=%lu\n", diu_ops.diu_size); |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | early_param("diufb", early_parse_diufb); |
| 935 | |
| 936 | #endif |