3 * Utility functions for the Freescale MPC52xx.
5 * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
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.
15 #include <linux/kernel.h>
16 #include <linux/of_platform.h>
19 #include <asm/mpc52xx.h>
21 /* MPC5200 device tree match tables */
22 static struct of_device_id mpc52xx_xlb_ids[] __initdata = {
23 { .compatible = "fsl,mpc5200-xlb", },
24 { .compatible = "mpc5200-xlb", },
27 static struct of_device_id mpc52xx_bus_ids[] __initdata = {
28 { .compatible = "fsl,mpc5200-immr", },
29 { .compatible = "fsl,mpc5200b-immr", },
30 { .compatible = "fsl,lpb", },
32 /* depreciated matches; shouldn't be used in new device trees */
33 { .type = "builtin", .compatible = "mpc5200", }, /* efika */
34 { .type = "soc", .compatible = "mpc5200", }, /* lite5200 */
39 * This variable is mapped in mpc52xx_map_wdt() and used in mpc52xx_restart().
40 * Permanent mapping is required because mpc52xx_restart() can be called
41 * from interrupt context while node mapping (which calls ioremap())
42 * cannot be used at such point.
44 static volatile struct mpc52xx_gpt *mpc52xx_wdt = NULL;
47 * mpc52xx_find_ipb_freq - Find the IPB bus frequency for a device
50 * Returns IPB bus frequency, or 0 if the bus frequency cannot be found.
53 mpc52xx_find_ipb_freq(struct device_node *node)
55 struct device_node *np;
56 const unsigned int *p_ipb_freq = NULL;
60 p_ipb_freq = of_get_property(node, "bus-frequency", NULL);
64 np = of_get_parent(node);
71 return p_ipb_freq ? *p_ipb_freq : 0;
73 EXPORT_SYMBOL(mpc52xx_find_ipb_freq);
77 * Configure the XLB arbiter settings to match what Linux expects.
80 mpc5200_setup_xlb_arbiter(void)
82 struct device_node *np;
83 struct mpc52xx_xlb __iomem *xlb;
85 np = of_find_matching_node(NULL, mpc52xx_xlb_ids);
86 xlb = of_iomap(np, 0);
89 printk(KERN_ERR __FILE__ ": "
90 "Error mapping XLB in mpc52xx_setup_cpu(). "
91 "Expect some abnormal behavior\n");
95 /* Configure the XLB Arbiter priorities */
96 out_be32(&xlb->master_pri_enable, 0xff);
97 out_be32(&xlb->master_priority, 0x11111111);
99 /* Disable XLB pipelining
100 * (cfr errate 292. We could do this only just before ATA PIO
101 * transaction and re-enable it afterwards ...)
103 out_be32(&xlb->config, in_be32(&xlb->config) | MPC52xx_XLB_CFG_PLDIS);
109 * mpc52xx_declare_of_platform_devices: register internal devices and children
110 * of the localplus bus to the of_platform
114 mpc52xx_declare_of_platform_devices(void)
116 /* Find every child of the SOC node and add it to of_platform */
117 if (of_platform_bus_probe(NULL, mpc52xx_bus_ids, NULL))
118 printk(KERN_ERR __FILE__ ": "
119 "Error while probing of_platform bus\n");
123 * match tables used by mpc52xx_map_wdt()
125 static struct of_device_id mpc52xx_gpt_ids[] __initdata = {
126 { .compatible = "fsl,mpc5200-gpt", },
127 { .compatible = "mpc5200-gpt", }, /* old */
132 mpc52xx_map_wdt(void)
134 struct device_node *np;
135 /* mpc52xx_wdt is mapped here and used in mpc52xx_restart,
136 * possibly from a interrupt context. wdt is only implement
137 * on a gpt0, so check has-wdt property before mapping.
139 for_each_matching_node(np, mpc52xx_gpt_ids) {
140 if (of_get_property(np, "fsl,has-wdt", NULL) ||
141 of_get_property(np, "has-wdt", NULL)) {
142 mpc52xx_wdt = of_iomap(np, 0);
150 mpc52xx_restart(char *cmd)
154 /* Turn on the watchdog and wait for it to expire.
155 * It effectively does a reset. */
157 out_be32(&mpc52xx_wdt->mode, 0x00000000);
158 out_be32(&mpc52xx_wdt->count, 0x000000ff);
159 out_be32(&mpc52xx_wdt->mode, 0x00009004);
161 printk("mpc52xx_restart: Can't access wdt. "
162 "Restart impossible, system halted.\n");