| 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 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 210 | static int gfar_mdio_of_init_one(struct device_node *np) | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 211 | { | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 212 | int k; | 
|  | 213 | struct device_node *child = NULL; | 
|  | 214 | struct gianfar_mdio_data mdio_data; | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 215 | struct platform_device *mdio_dev; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 216 | struct resource res; | 
|  | 217 | int ret; | 
|  | 218 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 219 | memset(&res, 0, sizeof(res)); | 
|  | 220 | memset(&mdio_data, 0, sizeof(mdio_data)); | 
| Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 221 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 222 | ret = of_address_to_resource(np, 0, &res); | 
|  | 223 | if (ret) | 
|  | 224 | return ret; | 
| Kumar Gala | e77b28e | 2007-12-12 00:28:35 -0600 | [diff] [blame] | 225 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 226 | mdio_dev = platform_device_register_simple("fsl-gianfar_mdio", | 
|  | 227 | res.start&0xfffff, &res, 1); | 
|  | 228 | if (IS_ERR(mdio_dev)) | 
|  | 229 | return PTR_ERR(mdio_dev); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 230 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 231 | for (k = 0; k < 32; k++) | 
|  | 232 | mdio_data.irq[k] = PHY_POLL; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 233 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 234 | while ((child = of_get_next_child(np, child)) != NULL) { | 
|  | 235 | int irq = irq_of_parse_and_map(child, 0); | 
|  | 236 | if (irq != NO_IRQ) { | 
|  | 237 | const u32 *id = of_get_property(child, "reg", NULL); | 
|  | 238 | mdio_data.irq[*id] = irq; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 239 | } | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 242 | ret = platform_device_add_data(mdio_dev, &mdio_data, | 
|  | 243 | sizeof(struct gianfar_mdio_data)); | 
|  | 244 | if (ret) | 
|  | 245 | platform_device_unregister(mdio_dev); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 246 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 247 | return ret; | 
|  | 248 | } | 
|  | 249 |  | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 250 | static int __init gfar_mdio_of_init(void) | 
|  | 251 | { | 
|  | 252 | struct device_node *np = NULL; | 
|  | 253 |  | 
|  | 254 | for_each_compatible_node(np, NULL, "fsl,gianfar-mdio") | 
|  | 255 | gfar_mdio_of_init_one(np); | 
|  | 256 |  | 
|  | 257 | /* try the deprecated version */ | 
|  | 258 | for_each_compatible_node(np, "mdio", "gianfar"); | 
|  | 259 | gfar_mdio_of_init_one(np); | 
|  | 260 |  | 
|  | 261 | return 0; | 
|  | 262 | } | 
|  | 263 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 264 | arch_initcall(gfar_mdio_of_init); | 
|  | 265 |  | 
|  | 266 | static const char *gfar_tx_intr = "tx"; | 
|  | 267 | static const char *gfar_rx_intr = "rx"; | 
|  | 268 | static const char *gfar_err_intr = "error"; | 
|  | 269 |  | 
|  | 270 | static int __init gfar_of_init(void) | 
|  | 271 | { | 
|  | 272 | struct device_node *np; | 
|  | 273 | unsigned int i; | 
|  | 274 | struct platform_device *gfar_dev; | 
|  | 275 | struct resource res; | 
|  | 276 | int ret; | 
|  | 277 |  | 
|  | 278 | for (np = NULL, i = 0; | 
|  | 279 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; | 
|  | 280 | i++) { | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 281 | struct resource r[4]; | 
|  | 282 | struct device_node *phy, *mdio; | 
|  | 283 | struct gianfar_platform_data gfar_data; | 
| Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 284 | const unsigned int *id; | 
|  | 285 | const char *model; | 
| Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 286 | const char *ctype; | 
| Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 287 | const void *mac_addr; | 
|  | 288 | const phandle *ph; | 
| Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 289 | int n_res = 2; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 290 |  | 
| Anton Vorontsov | 69ad7e7 | 2008-07-08 21:36:40 +0400 | [diff] [blame] | 291 | if (!of_device_is_available(np)) | 
|  | 292 | continue; | 
|  | 293 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 294 | memset(r, 0, sizeof(r)); | 
|  | 295 | memset(&gfar_data, 0, sizeof(gfar_data)); | 
|  | 296 |  | 
|  | 297 | ret = of_address_to_resource(np, 0, &r[0]); | 
|  | 298 | if (ret) | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 299 | goto err; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 300 |  | 
| Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 301 | of_irq_to_resource(np, 0, &r[1]); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 302 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 303 | model = of_get_property(np, "model", NULL); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 304 |  | 
|  | 305 | /* If we aren't the FEC we have multiple interrupts */ | 
|  | 306 | if (model && strcasecmp(model, "FEC")) { | 
|  | 307 | r[1].name = gfar_tx_intr; | 
|  | 308 |  | 
|  | 309 | r[2].name = gfar_rx_intr; | 
| Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 310 | of_irq_to_resource(np, 1, &r[2]); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 311 |  | 
|  | 312 | r[3].name = gfar_err_intr; | 
| Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 313 | of_irq_to_resource(np, 2, &r[3]); | 
| Jon Loeliger | 919fede | 2006-07-31 15:35:41 -0500 | [diff] [blame] | 314 |  | 
|  | 315 | n_res += 2; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 316 | } | 
|  | 317 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 318 | gfar_dev = | 
|  | 319 | platform_device_register_simple("fsl-gianfar", i, &r[0], | 
| Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 320 | n_res); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 321 |  | 
|  | 322 | if (IS_ERR(gfar_dev)) { | 
|  | 323 | ret = PTR_ERR(gfar_dev); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 324 | goto err; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 325 | } | 
|  | 326 |  | 
| Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 327 | mac_addr = of_get_mac_address(np); | 
| Jon Loeliger | f583165 | 2006-08-17 08:42:35 -0500 | [diff] [blame] | 328 | if (mac_addr) | 
|  | 329 | memcpy(gfar_data.mac_addr, mac_addr, 6); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 330 |  | 
|  | 331 | if (model && !strcasecmp(model, "TSEC")) | 
|  | 332 | gfar_data.device_flags = | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 333 | FSL_GIANFAR_DEV_HAS_GIGABIT | | 
|  | 334 | FSL_GIANFAR_DEV_HAS_COALESCE | | 
|  | 335 | FSL_GIANFAR_DEV_HAS_RMON | | 
|  | 336 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 337 | if (model && !strcasecmp(model, "eTSEC")) | 
|  | 338 | gfar_data.device_flags = | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 339 | FSL_GIANFAR_DEV_HAS_GIGABIT | | 
|  | 340 | FSL_GIANFAR_DEV_HAS_COALESCE | | 
|  | 341 | FSL_GIANFAR_DEV_HAS_RMON | | 
|  | 342 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | | 
|  | 343 | FSL_GIANFAR_DEV_HAS_CSUM | | 
|  | 344 | FSL_GIANFAR_DEV_HAS_VLAN | | 
|  | 345 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 346 |  | 
| Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 347 | ctype = of_get_property(np, "phy-connection-type", NULL); | 
|  | 348 |  | 
|  | 349 | /* We only care about rgmii-id.  The rest are autodetected */ | 
|  | 350 | if (ctype && !strcmp(ctype, "rgmii-id")) | 
|  | 351 | gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID; | 
|  | 352 | else | 
|  | 353 | gfar_data.interface = PHY_INTERFACE_MODE_MII; | 
|  | 354 |  | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 355 | if (of_get_property(np, "fsl,magic-packet", NULL)) | 
|  | 356 | gfar_data.device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET; | 
|  | 357 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 358 | ph = of_get_property(np, "phy-handle", NULL); | 
| Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 359 | if (ph == NULL) { | 
|  | 360 | u32 *fixed_link; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 361 |  | 
| Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 362 | fixed_link = (u32 *)of_get_property(np, "fixed-link", | 
|  | 363 | NULL); | 
|  | 364 | if (!fixed_link) { | 
|  | 365 | ret = -ENODEV; | 
|  | 366 | goto unreg; | 
|  | 367 | } | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 368 |  | 
| Andy Fleming | 9d9326d | 2008-04-09 19:38:13 -0500 | [diff] [blame] | 369 | snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0"); | 
| Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 370 | gfar_data.phy_id = fixed_link[0]; | 
|  | 371 | } else { | 
|  | 372 | phy = of_find_node_by_phandle(*ph); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 373 |  | 
| Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 374 | if (phy == NULL) { | 
|  | 375 | ret = -ENODEV; | 
|  | 376 | goto unreg; | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | mdio = of_get_parent(phy); | 
|  | 380 |  | 
|  | 381 | id = of_get_property(phy, "reg", NULL); | 
|  | 382 | ret = of_address_to_resource(mdio, 0, &res); | 
|  | 383 | if (ret) { | 
|  | 384 | of_node_put(phy); | 
|  | 385 | of_node_put(mdio); | 
|  | 386 | goto unreg; | 
|  | 387 | } | 
|  | 388 |  | 
|  | 389 | gfar_data.phy_id = *id; | 
| Becky Bruce | 128cf7f | 2008-05-01 18:15:45 -0500 | [diff] [blame] | 390 | snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx", | 
| Andy Fleming | 4cd7e1c | 2008-05-02 13:03:50 -0500 | [diff] [blame] | 391 | (unsigned long long)res.start&0xfffff); | 
| Vitaly Bordug | a21e282 | 2007-12-07 01:51:31 +0300 | [diff] [blame] | 392 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 393 | of_node_put(phy); | 
|  | 394 | of_node_put(mdio); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 395 | } | 
|  | 396 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 397 | ret = | 
|  | 398 | platform_device_add_data(gfar_dev, &gfar_data, | 
|  | 399 | sizeof(struct | 
|  | 400 | gianfar_platform_data)); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 401 | if (ret) | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 402 | goto unreg; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 403 | } | 
|  | 404 |  | 
|  | 405 | return 0; | 
|  | 406 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 407 | unreg: | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 408 | platform_device_unregister(gfar_dev); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 409 | err: | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 410 | return ret; | 
|  | 411 | } | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 412 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 413 | arch_initcall(gfar_of_init); | 
|  | 414 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 415 |  | 
|  | 416 | #ifdef CONFIG_PPC_83xx | 
|  | 417 | static int __init mpc83xx_wdt_init(void) | 
|  | 418 | { | 
|  | 419 | struct resource r; | 
| Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 420 | struct device_node *np; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 421 | struct platform_device *dev; | 
| Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 422 | u32 freq = fsl_get_sys_freq(); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 423 | int ret; | 
|  | 424 |  | 
|  | 425 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); | 
|  | 426 |  | 
|  | 427 | if (!np) { | 
|  | 428 | ret = -ENODEV; | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 429 | goto nodev; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 430 | } | 
|  | 431 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 432 | memset(&r, 0, sizeof(r)); | 
|  | 433 |  | 
|  | 434 | ret = of_address_to_resource(np, 0, &r); | 
|  | 435 | if (ret) | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 436 | goto err; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 437 |  | 
|  | 438 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); | 
|  | 439 | if (IS_ERR(dev)) { | 
|  | 440 | ret = PTR_ERR(dev); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 441 | goto err; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 442 | } | 
|  | 443 |  | 
| Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 444 | ret = platform_device_add_data(dev, &freq, sizeof(freq)); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 445 | if (ret) | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 446 | goto unreg; | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 447 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 448 | of_node_put(np); | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 449 | return 0; | 
|  | 450 |  | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 451 | unreg: | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 452 | platform_device_unregister(dev); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 453 | err: | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 454 | of_node_put(np); | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 455 | nodev: | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 456 | return ret; | 
|  | 457 | } | 
| Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 458 |  | 
| Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 459 | arch_initcall(mpc83xx_wdt_init); | 
|  | 460 | #endif | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 461 |  | 
| Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 462 | 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] | 463 | { | 
|  | 464 | if (!phy_type) | 
|  | 465 | return FSL_USB2_PHY_NONE; | 
|  | 466 | if (!strcasecmp(phy_type, "ulpi")) | 
|  | 467 | return FSL_USB2_PHY_ULPI; | 
|  | 468 | if (!strcasecmp(phy_type, "utmi")) | 
|  | 469 | return FSL_USB2_PHY_UTMI; | 
|  | 470 | if (!strcasecmp(phy_type, "utmi_wide")) | 
|  | 471 | return FSL_USB2_PHY_UTMI_WIDE; | 
|  | 472 | if (!strcasecmp(phy_type, "serial")) | 
|  | 473 | return FSL_USB2_PHY_SERIAL; | 
|  | 474 |  | 
|  | 475 | return FSL_USB2_PHY_NONE; | 
|  | 476 | } | 
|  | 477 |  | 
|  | 478 | static int __init fsl_usb_of_init(void) | 
|  | 479 | { | 
|  | 480 | struct device_node *np; | 
| Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 481 | unsigned int i = 0; | 
| Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 482 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, | 
|  | 483 | *usb_dev_dr_client = NULL; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 484 | int ret; | 
|  | 485 |  | 
| Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 486 | for_each_compatible_node(np, NULL, "fsl-usb2-mph") { | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 487 | struct resource r[2]; | 
|  | 488 | struct fsl_usb2_platform_data usb_data; | 
| Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 489 | const unsigned char *prop = NULL; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 490 |  | 
|  | 491 | memset(&r, 0, sizeof(r)); | 
|  | 492 | memset(&usb_data, 0, sizeof(usb_data)); | 
|  | 493 |  | 
|  | 494 | ret = of_address_to_resource(np, 0, &r[0]); | 
|  | 495 | if (ret) | 
|  | 496 | goto err; | 
|  | 497 |  | 
| Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 498 | of_irq_to_resource(np, 0, &r[1]); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 499 |  | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 500 | usb_dev_mph = | 
|  | 501 | platform_device_register_simple("fsl-ehci", i, r, 2); | 
|  | 502 | if (IS_ERR(usb_dev_mph)) { | 
|  | 503 | ret = PTR_ERR(usb_dev_mph); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 504 | goto err; | 
|  | 505 | } | 
|  | 506 |  | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 507 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; | 
|  | 508 | 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] | 509 |  | 
|  | 510 | usb_data.operating_mode = FSL_USB2_MPH_HOST; | 
|  | 511 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 512 | prop = of_get_property(np, "port0", NULL); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 513 | if (prop) | 
|  | 514 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; | 
|  | 515 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 516 | prop = of_get_property(np, "port1", NULL); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 517 | if (prop) | 
|  | 518 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; | 
|  | 519 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 520 | prop = of_get_property(np, "phy_type", NULL); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 521 | usb_data.phy_mode = determine_usb_phy(prop); | 
|  | 522 |  | 
|  | 523 | ret = | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 524 | platform_device_add_data(usb_dev_mph, &usb_data, | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 525 | sizeof(struct | 
|  | 526 | fsl_usb2_platform_data)); | 
|  | 527 | if (ret) | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 528 | goto unreg_mph; | 
| Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 529 | i++; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 530 | } | 
|  | 531 |  | 
| Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 532 | for_each_compatible_node(np, NULL, "fsl-usb2-dr") { | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 533 | struct resource r[2]; | 
|  | 534 | struct fsl_usb2_platform_data usb_data; | 
| Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 535 | const unsigned char *prop = NULL; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 536 |  | 
|  | 537 | memset(&r, 0, sizeof(r)); | 
|  | 538 | memset(&usb_data, 0, sizeof(usb_data)); | 
|  | 539 |  | 
|  | 540 | ret = of_address_to_resource(np, 0, &r[0]); | 
|  | 541 | if (ret) | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 542 | goto unreg_mph; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 543 |  | 
| Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 544 | of_irq_to_resource(np, 0, &r[1]); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 545 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 546 | prop = of_get_property(np, "dr_mode", NULL); | 
| Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 547 |  | 
|  | 548 | if (!prop || !strcmp(prop, "host")) { | 
|  | 549 | usb_data.operating_mode = FSL_USB2_DR_HOST; | 
|  | 550 | usb_dev_dr_host = platform_device_register_simple( | 
|  | 551 | "fsl-ehci", i, r, 2); | 
|  | 552 | if (IS_ERR(usb_dev_dr_host)) { | 
|  | 553 | ret = PTR_ERR(usb_dev_dr_host); | 
|  | 554 | goto err; | 
|  | 555 | } | 
|  | 556 | } else if (prop && !strcmp(prop, "peripheral")) { | 
|  | 557 | usb_data.operating_mode = FSL_USB2_DR_DEVICE; | 
|  | 558 | usb_dev_dr_client = platform_device_register_simple( | 
|  | 559 | "fsl-usb2-udc", i, r, 2); | 
|  | 560 | if (IS_ERR(usb_dev_dr_client)) { | 
|  | 561 | ret = PTR_ERR(usb_dev_dr_client); | 
|  | 562 | goto err; | 
|  | 563 | } | 
|  | 564 | } else if (prop && !strcmp(prop, "otg")) { | 
|  | 565 | usb_data.operating_mode = FSL_USB2_DR_OTG; | 
|  | 566 | usb_dev_dr_host = platform_device_register_simple( | 
|  | 567 | "fsl-ehci", i, r, 2); | 
|  | 568 | if (IS_ERR(usb_dev_dr_host)) { | 
|  | 569 | ret = PTR_ERR(usb_dev_dr_host); | 
|  | 570 | goto err; | 
|  | 571 | } | 
|  | 572 | usb_dev_dr_client = platform_device_register_simple( | 
|  | 573 | "fsl-usb2-udc", i, r, 2); | 
|  | 574 | if (IS_ERR(usb_dev_dr_client)) { | 
|  | 575 | ret = PTR_ERR(usb_dev_dr_client); | 
|  | 576 | goto err; | 
|  | 577 | } | 
|  | 578 | } else { | 
|  | 579 | ret = -EINVAL; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 580 | goto err; | 
|  | 581 | } | 
|  | 582 |  | 
| Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 583 | prop = of_get_property(np, "phy_type", NULL); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 584 | usb_data.phy_mode = determine_usb_phy(prop); | 
|  | 585 |  | 
| Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 586 | if (usb_dev_dr_host) { | 
|  | 587 | usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; | 
|  | 588 | usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> | 
|  | 589 | dev.coherent_dma_mask; | 
|  | 590 | if ((ret = platform_device_add_data(usb_dev_dr_host, | 
|  | 591 | &usb_data, sizeof(struct | 
|  | 592 | fsl_usb2_platform_data)))) | 
|  | 593 | goto unreg_dr; | 
|  | 594 | } | 
|  | 595 | if (usb_dev_dr_client) { | 
|  | 596 | usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; | 
|  | 597 | usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> | 
|  | 598 | dev.coherent_dma_mask; | 
|  | 599 | if ((ret = platform_device_add_data(usb_dev_dr_client, | 
|  | 600 | &usb_data, sizeof(struct | 
|  | 601 | fsl_usb2_platform_data)))) | 
|  | 602 | goto unreg_dr; | 
|  | 603 | } | 
| Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 604 | i++; | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 605 | } | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 606 | return 0; | 
|  | 607 |  | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 608 | unreg_dr: | 
| Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 609 | if (usb_dev_dr_host) | 
|  | 610 | platform_device_unregister(usb_dev_dr_host); | 
|  | 611 | if (usb_dev_dr_client) | 
|  | 612 | platform_device_unregister(usb_dev_dr_client); | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 613 | unreg_mph: | 
|  | 614 | if (usb_dev_mph) | 
|  | 615 | platform_device_unregister(usb_dev_mph); | 
| Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 616 | err: | 
|  | 617 | return ret; | 
|  | 618 | } | 
|  | 619 |  | 
| Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 620 | arch_initcall(fsl_usb_of_init); | 
| Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 621 |  | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 622 | static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk, | 
|  | 623 | struct spi_board_info *board_infos, | 
|  | 624 | unsigned int num_board_infos, | 
|  | 625 | void (*activate_cs)(u8 cs, u8 polarity), | 
|  | 626 | void (*deactivate_cs)(u8 cs, u8 polarity)) | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 627 | { | 
|  | 628 | struct device_node *np; | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 629 | unsigned int i = 0; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 630 |  | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 631 | for_each_compatible_node(np, type, compatible) { | 
|  | 632 | int ret; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 633 | unsigned int j; | 
|  | 634 | const void *prop; | 
|  | 635 | struct resource res[2]; | 
|  | 636 | struct platform_device *pdev; | 
|  | 637 | struct fsl_spi_platform_data pdata = { | 
|  | 638 | .activate_cs = activate_cs, | 
|  | 639 | .deactivate_cs = deactivate_cs, | 
|  | 640 | }; | 
|  | 641 |  | 
|  | 642 | memset(res, 0, sizeof(res)); | 
|  | 643 |  | 
| Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 644 | pdata.sysclk = sysclk; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 645 |  | 
|  | 646 | prop = of_get_property(np, "reg", NULL); | 
|  | 647 | if (!prop) | 
|  | 648 | goto err; | 
|  | 649 | pdata.bus_num = *(u32 *)prop; | 
|  | 650 |  | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 651 | prop = of_get_property(np, "cell-index", NULL); | 
|  | 652 | if (prop) | 
|  | 653 | i = *(u32 *)prop; | 
|  | 654 |  | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 655 | prop = of_get_property(np, "mode", NULL); | 
|  | 656 | if (prop && !strcmp(prop, "cpu-qe")) | 
|  | 657 | pdata.qe_mode = 1; | 
|  | 658 |  | 
|  | 659 | for (j = 0; j < num_board_infos; j++) { | 
|  | 660 | if (board_infos[j].bus_num == pdata.bus_num) | 
|  | 661 | pdata.max_chipselect++; | 
|  | 662 | } | 
|  | 663 |  | 
|  | 664 | if (!pdata.max_chipselect) | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 665 | continue; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 666 |  | 
|  | 667 | ret = of_address_to_resource(np, 0, &res[0]); | 
|  | 668 | if (ret) | 
|  | 669 | goto err; | 
|  | 670 |  | 
|  | 671 | ret = of_irq_to_resource(np, 0, &res[1]); | 
|  | 672 | if (ret == NO_IRQ) | 
|  | 673 | goto err; | 
|  | 674 |  | 
|  | 675 | pdev = platform_device_alloc("mpc83xx_spi", i); | 
|  | 676 | if (!pdev) | 
|  | 677 | goto err; | 
|  | 678 |  | 
|  | 679 | ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); | 
|  | 680 | if (ret) | 
|  | 681 | goto unreg; | 
|  | 682 |  | 
|  | 683 | ret = platform_device_add_resources(pdev, res, | 
|  | 684 | ARRAY_SIZE(res)); | 
|  | 685 | if (ret) | 
|  | 686 | goto unreg; | 
|  | 687 |  | 
| Kim Phillips | dc4e420 | 2008-02-01 18:09:58 -0600 | [diff] [blame] | 688 | ret = platform_device_add(pdev); | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 689 | if (ret) | 
|  | 690 | goto unreg; | 
|  | 691 |  | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 692 | goto next; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 693 | unreg: | 
|  | 694 | platform_device_del(pdev); | 
|  | 695 | err: | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 696 | pr_err("%s: registration failed\n", np->full_name); | 
|  | 697 | next: | 
|  | 698 | i++; | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 699 | } | 
|  | 700 |  | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 701 | return i; | 
|  | 702 | } | 
|  | 703 |  | 
|  | 704 | int __init fsl_spi_init(struct spi_board_info *board_infos, | 
|  | 705 | unsigned int num_board_infos, | 
|  | 706 | void (*activate_cs)(u8 cs, u8 polarity), | 
|  | 707 | void (*deactivate_cs)(u8 cs, u8 polarity)) | 
|  | 708 | { | 
|  | 709 | u32 sysclk = -1; | 
|  | 710 | int ret; | 
|  | 711 |  | 
|  | 712 | #ifdef CONFIG_QUICC_ENGINE | 
|  | 713 | /* SPI controller is either clocked from QE or SoC clock */ | 
|  | 714 | sysclk = get_brgfreq(); | 
|  | 715 | #endif | 
|  | 716 | if (sysclk == -1) { | 
| Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 717 | sysclk = fsl_get_sys_freq(); | 
|  | 718 | if (sysclk == -1) | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 719 | return -ENODEV; | 
| Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 720 | } | 
|  | 721 |  | 
|  | 722 | ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos, | 
|  | 723 | num_board_infos, activate_cs, deactivate_cs); | 
|  | 724 | if (!ret) | 
|  | 725 | of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos, | 
|  | 726 | num_board_infos, activate_cs, deactivate_cs); | 
|  | 727 |  | 
| Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 728 | return spi_register_board_info(board_infos, num_board_infos); | 
|  | 729 | } | 
| Kumar Gala | e1c1575 | 2007-10-04 01:04:57 -0500 | [diff] [blame] | 730 |  | 
|  | 731 | #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx) | 
|  | 732 | static __be32 __iomem *rstcr; | 
|  | 733 |  | 
|  | 734 | static int __init setup_rstcr(void) | 
|  | 735 | { | 
|  | 736 | struct device_node *np; | 
|  | 737 | np = of_find_node_by_name(NULL, "global-utilities"); | 
|  | 738 | if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) { | 
|  | 739 | const u32 *prop = of_get_property(np, "reg", NULL); | 
|  | 740 | if (prop) { | 
|  | 741 | /* map reset control register | 
|  | 742 | * 0xE00B0 is offset of reset control register | 
|  | 743 | */ | 
|  | 744 | rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff); | 
|  | 745 | if (!rstcr) | 
|  | 746 | printk (KERN_EMERG "Error: reset control " | 
|  | 747 | "register not mapped!\n"); | 
|  | 748 | } | 
|  | 749 | } else | 
|  | 750 | printk (KERN_INFO "rstcr compatible register does not exist!\n"); | 
|  | 751 | if (np) | 
|  | 752 | of_node_put(np); | 
|  | 753 | return 0; | 
|  | 754 | } | 
|  | 755 |  | 
|  | 756 | arch_initcall(setup_rstcr); | 
|  | 757 |  | 
|  | 758 | void fsl_rstcr_restart(char *cmd) | 
|  | 759 | { | 
|  | 760 | local_irq_disable(); | 
|  | 761 | if (rstcr) | 
|  | 762 | /* set reset control register */ | 
|  | 763 | out_be32(rstcr, 0x2);	/* HRESET_REQ */ | 
|  | 764 |  | 
|  | 765 | while (1) ; | 
|  | 766 | } | 
|  | 767 | #endif | 
| York Sun | 6f90a8bd | 2008-04-28 02:15:36 -0700 | [diff] [blame] | 768 |  | 
|  | 769 | #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) | 
|  | 770 | struct platform_diu_data_ops diu_ops = { | 
|  | 771 | .diu_size = 1280 * 1024 * 4,	/* default one 1280x1024 buffer */ | 
|  | 772 | }; | 
|  | 773 | EXPORT_SYMBOL(diu_ops); | 
|  | 774 |  | 
|  | 775 | int __init preallocate_diu_videomemory(void) | 
|  | 776 | { | 
|  | 777 | pr_debug("diu_size=%lu\n", diu_ops.diu_size); | 
|  | 778 |  | 
|  | 779 | diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0); | 
|  | 780 | if (!diu_ops.diu_mem) { | 
|  | 781 | printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n", | 
|  | 782 | diu_ops.diu_size); | 
|  | 783 | return -ENOMEM; | 
|  | 784 | } | 
|  | 785 |  | 
|  | 786 | pr_debug("diu_mem=%p\n", diu_ops.diu_mem); | 
|  | 787 |  | 
|  | 788 | rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block), | 
|  | 789 | diu_ops.diu_rh_block); | 
|  | 790 | return rh_attach_region(&diu_ops.diu_rh_info, | 
|  | 791 | (unsigned long) diu_ops.diu_mem, | 
|  | 792 | diu_ops.diu_size); | 
|  | 793 | } | 
|  | 794 |  | 
|  | 795 | static int __init early_parse_diufb(char *p) | 
|  | 796 | { | 
|  | 797 | if (!p) | 
|  | 798 | return 1; | 
|  | 799 |  | 
|  | 800 | diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8); | 
|  | 801 |  | 
|  | 802 | pr_debug("diu_size=%lu\n", diu_ops.diu_size); | 
|  | 803 |  | 
|  | 804 | return 0; | 
|  | 805 | } | 
|  | 806 | early_param("diufb", early_parse_diufb); | 
|  | 807 |  | 
|  | 808 | #endif |