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 | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 210 | #ifdef CONFIG_PPC_83xx |
| 211 | static int __init mpc83xx_wdt_init(void) |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 212 | { |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 213 | struct resource r; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 214 | struct device_node *np; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 215 | struct platform_device *dev; |
| 216 | u32 freq = fsl_get_sys_freq(); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 217 | int ret; |
| 218 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 219 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 220 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 221 | if (!np) { |
| 222 | ret = -ENODEV; |
| 223 | goto nodev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 224 | } |
| 225 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 226 | memset(&r, 0, sizeof(r)); |
| 227 | |
| 228 | ret = of_address_to_resource(np, 0, &r); |
| 229 | if (ret) |
| 230 | goto err; |
| 231 | |
| 232 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 233 | if (IS_ERR(dev)) { |
| 234 | ret = PTR_ERR(dev); |
| 235 | goto err; |
| 236 | } |
| 237 | |
| 238 | ret = platform_device_add_data(dev, &freq, sizeof(freq)); |
| 239 | if (ret) |
| 240 | goto unreg; |
| 241 | |
| 242 | of_node_put(np); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 243 | return 0; |
| 244 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 245 | unreg: |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 246 | platform_device_unregister(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 247 | err: |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 248 | of_node_put(np); |
| 249 | nodev: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 250 | return ret; |
| 251 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 252 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 253 | arch_initcall(mpc83xx_wdt_init); |
| 254 | #endif |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 255 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 256 | 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] | 257 | { |
| 258 | if (!phy_type) |
| 259 | return FSL_USB2_PHY_NONE; |
| 260 | if (!strcasecmp(phy_type, "ulpi")) |
| 261 | return FSL_USB2_PHY_ULPI; |
| 262 | if (!strcasecmp(phy_type, "utmi")) |
| 263 | return FSL_USB2_PHY_UTMI; |
| 264 | if (!strcasecmp(phy_type, "utmi_wide")) |
| 265 | return FSL_USB2_PHY_UTMI_WIDE; |
| 266 | if (!strcasecmp(phy_type, "serial")) |
| 267 | return FSL_USB2_PHY_SERIAL; |
| 268 | |
| 269 | return FSL_USB2_PHY_NONE; |
| 270 | } |
| 271 | |
| 272 | static int __init fsl_usb_of_init(void) |
| 273 | { |
| 274 | struct device_node *np; |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 275 | unsigned int i = 0; |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 276 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, |
| 277 | *usb_dev_dr_client = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 278 | int ret; |
| 279 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 280 | for_each_compatible_node(np, NULL, "fsl-usb2-mph") { |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 281 | struct resource r[2]; |
| 282 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 283 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 284 | |
| 285 | memset(&r, 0, sizeof(r)); |
| 286 | memset(&usb_data, 0, sizeof(usb_data)); |
| 287 | |
| 288 | ret = of_address_to_resource(np, 0, &r[0]); |
| 289 | if (ret) |
| 290 | goto err; |
| 291 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 292 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 293 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 294 | usb_dev_mph = |
| 295 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 296 | if (IS_ERR(usb_dev_mph)) { |
| 297 | ret = PTR_ERR(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 298 | goto err; |
| 299 | } |
| 300 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 301 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
| 302 | 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] | 303 | |
| 304 | usb_data.operating_mode = FSL_USB2_MPH_HOST; |
| 305 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 306 | prop = of_get_property(np, "port0", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 307 | if (prop) |
| 308 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; |
| 309 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 310 | prop = of_get_property(np, "port1", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 311 | if (prop) |
| 312 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; |
| 313 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 314 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 315 | usb_data.phy_mode = determine_usb_phy(prop); |
| 316 | |
| 317 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 318 | platform_device_add_data(usb_dev_mph, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 319 | sizeof(struct |
| 320 | fsl_usb2_platform_data)); |
| 321 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 322 | goto unreg_mph; |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 323 | i++; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 324 | } |
| 325 | |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 326 | for_each_compatible_node(np, NULL, "fsl-usb2-dr") { |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 327 | struct resource r[2]; |
| 328 | struct fsl_usb2_platform_data usb_data; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 329 | const unsigned char *prop = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 330 | |
| 331 | memset(&r, 0, sizeof(r)); |
| 332 | memset(&usb_data, 0, sizeof(usb_data)); |
| 333 | |
| 334 | ret = of_address_to_resource(np, 0, &r[0]); |
| 335 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 336 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 337 | |
Andy Fleming | a9b1497 | 2006-10-19 19:52:26 -0500 | [diff] [blame] | 338 | of_irq_to_resource(np, 0, &r[1]); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 339 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 340 | prop = of_get_property(np, "dr_mode", NULL); |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 341 | |
| 342 | if (!prop || !strcmp(prop, "host")) { |
| 343 | usb_data.operating_mode = FSL_USB2_DR_HOST; |
| 344 | usb_dev_dr_host = platform_device_register_simple( |
| 345 | "fsl-ehci", i, r, 2); |
| 346 | if (IS_ERR(usb_dev_dr_host)) { |
| 347 | ret = PTR_ERR(usb_dev_dr_host); |
| 348 | goto err; |
| 349 | } |
| 350 | } else if (prop && !strcmp(prop, "peripheral")) { |
| 351 | usb_data.operating_mode = FSL_USB2_DR_DEVICE; |
| 352 | usb_dev_dr_client = platform_device_register_simple( |
| 353 | "fsl-usb2-udc", i, r, 2); |
| 354 | if (IS_ERR(usb_dev_dr_client)) { |
| 355 | ret = PTR_ERR(usb_dev_dr_client); |
| 356 | goto err; |
| 357 | } |
| 358 | } else if (prop && !strcmp(prop, "otg")) { |
| 359 | usb_data.operating_mode = FSL_USB2_DR_OTG; |
| 360 | usb_dev_dr_host = platform_device_register_simple( |
| 361 | "fsl-ehci", i, r, 2); |
| 362 | if (IS_ERR(usb_dev_dr_host)) { |
| 363 | ret = PTR_ERR(usb_dev_dr_host); |
| 364 | goto err; |
| 365 | } |
| 366 | usb_dev_dr_client = platform_device_register_simple( |
| 367 | "fsl-usb2-udc", i, r, 2); |
| 368 | if (IS_ERR(usb_dev_dr_client)) { |
| 369 | ret = PTR_ERR(usb_dev_dr_client); |
| 370 | goto err; |
| 371 | } |
| 372 | } else { |
| 373 | ret = -EINVAL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 374 | goto err; |
| 375 | } |
| 376 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 377 | prop = of_get_property(np, "phy_type", NULL); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 378 | usb_data.phy_mode = determine_usb_phy(prop); |
| 379 | |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 380 | if (usb_dev_dr_host) { |
| 381 | usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; |
| 382 | usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> |
| 383 | dev.coherent_dma_mask; |
| 384 | if ((ret = platform_device_add_data(usb_dev_dr_host, |
| 385 | &usb_data, sizeof(struct |
| 386 | fsl_usb2_platform_data)))) |
| 387 | goto unreg_dr; |
| 388 | } |
| 389 | if (usb_dev_dr_client) { |
| 390 | usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; |
| 391 | usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> |
| 392 | dev.coherent_dma_mask; |
| 393 | if ((ret = platform_device_add_data(usb_dev_dr_client, |
| 394 | &usb_data, sizeof(struct |
| 395 | fsl_usb2_platform_data)))) |
| 396 | goto unreg_dr; |
| 397 | } |
Li Yang | 866b6dd | 2008-01-08 15:18:46 +0800 | [diff] [blame] | 398 | i++; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 399 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 400 | return 0; |
| 401 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 402 | unreg_dr: |
Li Yang | 97c5a20 | 2007-02-07 13:49:24 +0800 | [diff] [blame] | 403 | if (usb_dev_dr_host) |
| 404 | platform_device_unregister(usb_dev_dr_host); |
| 405 | if (usb_dev_dr_client) |
| 406 | platform_device_unregister(usb_dev_dr_client); |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 407 | unreg_mph: |
| 408 | if (usb_dev_mph) |
| 409 | platform_device_unregister(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 410 | err: |
| 411 | return ret; |
| 412 | } |
| 413 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 414 | arch_initcall(fsl_usb_of_init); |
Vitaly Bordug | fba4366 | 2006-09-21 17:26:34 +0400 | [diff] [blame] | 415 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 416 | static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk, |
| 417 | struct spi_board_info *board_infos, |
| 418 | unsigned int num_board_infos, |
| 419 | void (*activate_cs)(u8 cs, u8 polarity), |
| 420 | void (*deactivate_cs)(u8 cs, u8 polarity)) |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 421 | { |
| 422 | struct device_node *np; |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 423 | unsigned int i = 0; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 424 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 425 | for_each_compatible_node(np, type, compatible) { |
| 426 | int ret; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 427 | unsigned int j; |
| 428 | const void *prop; |
| 429 | struct resource res[2]; |
| 430 | struct platform_device *pdev; |
| 431 | struct fsl_spi_platform_data pdata = { |
| 432 | .activate_cs = activate_cs, |
| 433 | .deactivate_cs = deactivate_cs, |
| 434 | }; |
| 435 | |
| 436 | memset(res, 0, sizeof(res)); |
| 437 | |
Anton Vorontsov | 59a0ea5 | 2008-01-24 18:40:03 +0300 | [diff] [blame] | 438 | pdata.sysclk = sysclk; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 439 | |
| 440 | prop = of_get_property(np, "reg", NULL); |
| 441 | if (!prop) |
| 442 | goto err; |
| 443 | pdata.bus_num = *(u32 *)prop; |
| 444 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 445 | prop = of_get_property(np, "cell-index", NULL); |
| 446 | if (prop) |
| 447 | i = *(u32 *)prop; |
| 448 | |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 449 | prop = of_get_property(np, "mode", NULL); |
| 450 | if (prop && !strcmp(prop, "cpu-qe")) |
| 451 | pdata.qe_mode = 1; |
| 452 | |
| 453 | for (j = 0; j < num_board_infos; j++) { |
| 454 | if (board_infos[j].bus_num == pdata.bus_num) |
| 455 | pdata.max_chipselect++; |
| 456 | } |
| 457 | |
| 458 | if (!pdata.max_chipselect) |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 459 | continue; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 460 | |
| 461 | ret = of_address_to_resource(np, 0, &res[0]); |
| 462 | if (ret) |
| 463 | goto err; |
| 464 | |
| 465 | ret = of_irq_to_resource(np, 0, &res[1]); |
| 466 | if (ret == NO_IRQ) |
| 467 | goto err; |
| 468 | |
| 469 | pdev = platform_device_alloc("mpc83xx_spi", i); |
| 470 | if (!pdev) |
| 471 | goto err; |
| 472 | |
| 473 | ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 474 | if (ret) |
| 475 | goto unreg; |
| 476 | |
| 477 | ret = platform_device_add_resources(pdev, res, |
| 478 | ARRAY_SIZE(res)); |
| 479 | if (ret) |
| 480 | goto unreg; |
| 481 | |
Kim Phillips | dc4e420 | 2008-02-01 18:09:58 -0600 | [diff] [blame] | 482 | ret = platform_device_add(pdev); |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 483 | if (ret) |
| 484 | goto unreg; |
| 485 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 486 | goto next; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 487 | unreg: |
| 488 | platform_device_del(pdev); |
| 489 | err: |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 490 | pr_err("%s: registration failed\n", np->full_name); |
| 491 | next: |
| 492 | i++; |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 493 | } |
| 494 | |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 495 | return i; |
| 496 | } |
| 497 | |
| 498 | int __init fsl_spi_init(struct spi_board_info *board_infos, |
| 499 | unsigned int num_board_infos, |
| 500 | void (*activate_cs)(u8 cs, u8 polarity), |
| 501 | void (*deactivate_cs)(u8 cs, u8 polarity)) |
| 502 | { |
| 503 | u32 sysclk = -1; |
| 504 | int ret; |
| 505 | |
| 506 | #ifdef CONFIG_QUICC_ENGINE |
| 507 | /* SPI controller is either clocked from QE or SoC clock */ |
| 508 | sysclk = get_brgfreq(); |
| 509 | #endif |
| 510 | if (sysclk == -1) { |
Scott Wood | 3866409 | 2008-04-15 13:52:34 -0500 | [diff] [blame] | 511 | sysclk = fsl_get_sys_freq(); |
| 512 | if (sysclk == -1) |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 513 | return -ENODEV; |
Anton Vorontsov | f3a2b29 | 2008-01-24 18:40:07 +0300 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos, |
| 517 | num_board_infos, activate_cs, deactivate_cs); |
| 518 | if (!ret) |
| 519 | of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos, |
| 520 | num_board_infos, activate_cs, deactivate_cs); |
| 521 | |
Anton Vorontsov | 26f6cb9 | 2007-08-23 15:35:56 +0400 | [diff] [blame] | 522 | return spi_register_board_info(board_infos, num_board_infos); |
| 523 | } |
Kumar Gala | e1c1575 | 2007-10-04 01:04:57 -0500 | [diff] [blame] | 524 | |
| 525 | #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx) |
| 526 | static __be32 __iomem *rstcr; |
| 527 | |
| 528 | static int __init setup_rstcr(void) |
| 529 | { |
| 530 | struct device_node *np; |
| 531 | np = of_find_node_by_name(NULL, "global-utilities"); |
| 532 | if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) { |
| 533 | const u32 *prop = of_get_property(np, "reg", NULL); |
| 534 | if (prop) { |
| 535 | /* map reset control register |
| 536 | * 0xE00B0 is offset of reset control register |
| 537 | */ |
| 538 | rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff); |
| 539 | if (!rstcr) |
| 540 | printk (KERN_EMERG "Error: reset control " |
| 541 | "register not mapped!\n"); |
| 542 | } |
| 543 | } else |
| 544 | printk (KERN_INFO "rstcr compatible register does not exist!\n"); |
| 545 | if (np) |
| 546 | of_node_put(np); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | arch_initcall(setup_rstcr); |
| 551 | |
| 552 | void fsl_rstcr_restart(char *cmd) |
| 553 | { |
| 554 | local_irq_disable(); |
| 555 | if (rstcr) |
| 556 | /* set reset control register */ |
| 557 | out_be32(rstcr, 0x2); /* HRESET_REQ */ |
| 558 | |
| 559 | while (1) ; |
| 560 | } |
| 561 | #endif |
York Sun | 6f90a8bd | 2008-04-28 02:15:36 -0700 | [diff] [blame] | 562 | |
| 563 | #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) |
Timur Tabi | 43c9f43 | 2008-09-23 09:47:01 -0500 | [diff] [blame] | 564 | struct platform_diu_data_ops diu_ops; |
York Sun | 6f90a8bd | 2008-04-28 02:15:36 -0700 | [diff] [blame] | 565 | EXPORT_SYMBOL(diu_ops); |
York Sun | 6f90a8bd | 2008-04-28 02:15:36 -0700 | [diff] [blame] | 566 | #endif |