Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Utility functions for the Freescale MPC52xx. |
| 4 | * |
| 5 | * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com> |
| 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public License |
| 8 | * version 2. This program is licensed "as is" without any warranty of any |
| 9 | * kind, whether express or implied. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #undef DEBUG |
| 14 | |
| 15 | #include <linux/kernel.h> |
Grant Likely | 9fe2e79 | 2007-10-10 09:52:00 -0600 | [diff] [blame] | 16 | #include <linux/of_platform.h> |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | #include <asm/prom.h> |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 19 | #include <asm/mpc52xx.h> |
| 20 | |
Marian Balakowicz | 86b92cd | 2007-10-19 04:44:33 +1000 | [diff] [blame] | 21 | /* |
| 22 | * This variable is mapped in mpc52xx_map_wdt() and used in mpc52xx_restart(). |
| 23 | * Permanent mapping is required because mpc52xx_restart() can be called |
| 24 | * from interrupt context while node mapping (which calls ioremap()) |
| 25 | * cannot be used at such point. |
| 26 | */ |
| 27 | static volatile struct mpc52xx_gpt *mpc52xx_wdt = NULL; |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 28 | |
Marian Balakowicz | c5c01c9 | 2007-10-19 04:44:14 +1000 | [diff] [blame] | 29 | static void __iomem * |
| 30 | mpc52xx_map_node(struct device_node *ofn) |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 31 | { |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 32 | const u32 *regaddr_p; |
| 33 | u64 regaddr64, size64; |
| 34 | |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 35 | if (!ofn) |
| 36 | return NULL; |
| 37 | |
| 38 | regaddr_p = of_get_address(ofn, 0, &size64, NULL); |
| 39 | if (!regaddr_p) { |
| 40 | of_node_put(ofn); |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | regaddr64 = of_translate_address(ofn, regaddr_p); |
| 45 | |
| 46 | of_node_put(ofn); |
| 47 | |
| 48 | return ioremap((u32)regaddr64, (u32)size64); |
| 49 | } |
Marian Balakowicz | c5c01c9 | 2007-10-19 04:44:14 +1000 | [diff] [blame] | 50 | |
| 51 | void __iomem * |
| 52 | mpc52xx_find_and_map(const char *compatible) |
| 53 | { |
| 54 | return mpc52xx_map_node( |
| 55 | of_find_compatible_node(NULL, NULL, compatible)); |
| 56 | } |
| 57 | |
Grant Likely | d8594d6 | 2006-12-04 17:29:12 -0700 | [diff] [blame] | 58 | EXPORT_SYMBOL(mpc52xx_find_and_map); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 59 | |
Marian Balakowicz | c5c01c9 | 2007-10-19 04:44:14 +1000 | [diff] [blame] | 60 | void __iomem * |
| 61 | mpc52xx_find_and_map_path(const char *path) |
| 62 | { |
| 63 | return mpc52xx_map_node(of_find_node_by_path(path)); |
| 64 | } |
| 65 | |
| 66 | EXPORT_SYMBOL(mpc52xx_find_and_map_path); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * mpc52xx_find_ipb_freq - Find the IPB bus frequency for a device |
| 70 | * @node: device node |
| 71 | * |
| 72 | * Returns IPB bus frequency, or 0 if the bus frequency cannot be found. |
| 73 | */ |
| 74 | unsigned int |
| 75 | mpc52xx_find_ipb_freq(struct device_node *node) |
| 76 | { |
| 77 | struct device_node *np; |
| 78 | const unsigned int *p_ipb_freq = NULL; |
| 79 | |
| 80 | of_node_get(node); |
| 81 | while (node) { |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 82 | p_ipb_freq = of_get_property(node, "bus-frequency", NULL); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 83 | if (p_ipb_freq) |
| 84 | break; |
| 85 | |
| 86 | np = of_get_parent(node); |
| 87 | of_node_put(node); |
| 88 | node = np; |
| 89 | } |
| 90 | if (node) |
| 91 | of_node_put(node); |
| 92 | |
| 93 | return p_ipb_freq ? *p_ipb_freq : 0; |
| 94 | } |
Grant Likely | d8594d6 | 2006-12-04 17:29:12 -0700 | [diff] [blame] | 95 | EXPORT_SYMBOL(mpc52xx_find_ipb_freq); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 96 | |
| 97 | |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 98 | /* |
| 99 | * Configure the XLB arbiter settings to match what Linux expects. |
| 100 | */ |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 101 | void __init |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 102 | mpc5200_setup_xlb_arbiter(void) |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 103 | { |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 104 | struct mpc52xx_xlb __iomem *xlb; |
| 105 | |
Grant Likely | e3aba81 | 2007-02-12 13:36:55 -0700 | [diff] [blame] | 106 | xlb = mpc52xx_find_and_map("mpc5200-xlb"); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 107 | if (!xlb) { |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 108 | printk(KERN_ERR __FILE__ ": " |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 109 | "Error mapping XLB in mpc52xx_setup_cpu(). " |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 110 | "Expect some abnormal behavior\n"); |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 111 | return; |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 114 | /* Configure the XLB Arbiter priorities */ |
| 115 | out_be32(&xlb->master_pri_enable, 0xff); |
| 116 | out_be32(&xlb->master_priority, 0x11111111); |
| 117 | |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 118 | /* Disable XLB pipelining |
| 119 | * (cfr errate 292. We could do this only just before ATA PIO |
| 120 | * transaction and re-enable it afterwards ...) |
| 121 | */ |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 122 | out_be32(&xlb->config, in_be32(&xlb->config) | MPC52xx_XLB_CFG_PLDIS); |
| 123 | |
Grant Likely | 4de3b99 | 2007-10-09 14:45:28 -0600 | [diff] [blame] | 124 | iounmap(xlb); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Sylvain Munaut | 5c334ee | 2007-01-02 23:29:53 +0100 | [diff] [blame] | 127 | void __init |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 128 | mpc52xx_declare_of_platform_devices(void) |
| 129 | { |
| 130 | /* Find every child of the SOC node and add it to of_platform */ |
Sylvain Munaut | 5c334ee | 2007-01-02 23:29:53 +0100 | [diff] [blame] | 131 | if (of_platform_bus_probe(NULL, NULL, NULL)) |
| 132 | printk(KERN_ERR __FILE__ ": " |
| 133 | "Error while probing of_platform bus\n"); |
Grant Likely | 6065170 | 2006-11-27 14:16:27 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Marian Balakowicz | 86b92cd | 2007-10-19 04:44:33 +1000 | [diff] [blame] | 136 | void __init |
| 137 | mpc52xx_map_wdt(void) |
| 138 | { |
| 139 | const void *has_wdt; |
| 140 | struct device_node *np; |
| 141 | |
| 142 | /* mpc52xx_wdt is mapped here and used in mpc52xx_restart, |
| 143 | * possibly from a interrupt context. wdt is only implement |
| 144 | * on a gpt0, so check has-wdt property before mapping. |
| 145 | */ |
| 146 | for_each_compatible_node(np, NULL, "fsl,mpc5200-gpt") { |
| 147 | has_wdt = of_get_property(np, "fsl,has-wdt", NULL); |
| 148 | if (has_wdt) { |
| 149 | mpc52xx_wdt = mpc52xx_map_node(np); |
| 150 | return; |
| 151 | } |
| 152 | } |
| 153 | for_each_compatible_node(np, NULL, "mpc5200-gpt") { |
| 154 | has_wdt = of_get_property(np, "has-wdt", NULL); |
| 155 | if (has_wdt) { |
| 156 | mpc52xx_wdt = mpc52xx_map_node(np); |
| 157 | return; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | mpc52xx_restart(char *cmd) |
| 164 | { |
| 165 | local_irq_disable(); |
| 166 | |
| 167 | /* Turn on the watchdog and wait for it to expire. |
| 168 | * It effectively does a reset. */ |
| 169 | if (mpc52xx_wdt) { |
| 170 | out_be32(&mpc52xx_wdt->mode, 0x00000000); |
| 171 | out_be32(&mpc52xx_wdt->count, 0x000000ff); |
| 172 | out_be32(&mpc52xx_wdt->mode, 0x00009004); |
| 173 | } else |
| 174 | printk("mpc52xx_restart: Can't access wdt. " |
| 175 | "Restart impossible, system halted.\n"); |
| 176 | |
| 177 | while (1); |
| 178 | } |