]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/powerpc/platforms/52xx/mpc52xx_common.c
[POWERPC] mpc5200: eliminate mpc52xx_*_map_*() functions.
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / 52xx / mpc52xx_common.c
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>
16 #include <linux/of_platform.h>
17 #include <asm/io.h>
18 #include <asm/prom.h>
19 #include <asm/mpc52xx.h>
20
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;
28
29 /**
30  *      mpc52xx_find_ipb_freq - Find the IPB bus frequency for a device
31  *      @node:  device node
32  *
33  *      Returns IPB bus frequency, or 0 if the bus frequency cannot be found.
34  */
35 unsigned int
36 mpc52xx_find_ipb_freq(struct device_node *node)
37 {
38         struct device_node *np;
39         const unsigned int *p_ipb_freq = NULL;
40
41         of_node_get(node);
42         while (node) {
43                 p_ipb_freq = of_get_property(node, "bus-frequency", NULL);
44                 if (p_ipb_freq)
45                         break;
46
47                 np = of_get_parent(node);
48                 of_node_put(node);
49                 node = np;
50         }
51         if (node)
52                 of_node_put(node);
53
54         return p_ipb_freq ? *p_ipb_freq : 0;
55 }
56 EXPORT_SYMBOL(mpc52xx_find_ipb_freq);
57
58
59 /*
60  * Configure the XLB arbiter settings to match what Linux expects.
61  */
62 void __init
63 mpc5200_setup_xlb_arbiter(void)
64 {
65         struct device_node *np;
66         struct mpc52xx_xlb  __iomem *xlb;
67
68         np = of_find_compatible_node(NULL, NULL, "mpc5200-xlb");
69         xlb = of_iomap(np, 0);
70         of_node_put(np);
71         if (!xlb) {
72                 printk(KERN_ERR __FILE__ ": "
73                         "Error mapping XLB in mpc52xx_setup_cpu().  "
74                         "Expect some abnormal behavior\n");
75                 return;
76         }
77
78         /* Configure the XLB Arbiter priorities */
79         out_be32(&xlb->master_pri_enable, 0xff);
80         out_be32(&xlb->master_priority, 0x11111111);
81
82         /* Disable XLB pipelining
83          * (cfr errate 292. We could do this only just before ATA PIO
84          *  transaction and re-enable it afterwards ...)
85          */
86         out_be32(&xlb->config, in_be32(&xlb->config) | MPC52xx_XLB_CFG_PLDIS);
87
88         iounmap(xlb);
89 }
90
91 static struct of_device_id mpc52xx_bus_ids[] __initdata= {
92         { .compatible = "fsl,mpc5200-immr", },
93         { .compatible = "fsl,lpb", },
94
95         /* depreciated matches; shouldn't be used in new device trees */
96         { .type = "builtin", .compatible = "mpc5200", }, /* efika */
97         { .type = "soc", .compatible = "mpc5200", }, /* lite5200 */
98         {},
99 };
100
101 void __init
102 mpc52xx_declare_of_platform_devices(void)
103 {
104         /* Find every child of the SOC node and add it to of_platform */
105         if (of_platform_bus_probe(NULL, mpc52xx_bus_ids, NULL))
106                 printk(KERN_ERR __FILE__ ": "
107                         "Error while probing of_platform bus\n");
108 }
109
110 void __init
111 mpc52xx_map_wdt(void)
112 {
113         const void *has_wdt;
114         struct device_node *np;
115
116         /* mpc52xx_wdt is mapped here and used in mpc52xx_restart,
117          * possibly from a interrupt context. wdt is only implement
118          * on a gpt0, so check has-wdt property before mapping.
119          */
120         for_each_compatible_node(np, NULL, "fsl,mpc5200-gpt") {
121                 has_wdt = of_get_property(np, "fsl,has-wdt", NULL);
122                 if (has_wdt) {
123                         mpc52xx_wdt = of_iomap(np, 0);
124                         of_node_put(np);
125                         return;
126                 }
127         }
128         for_each_compatible_node(np, NULL, "mpc5200-gpt") {
129                 has_wdt = of_get_property(np, "has-wdt", NULL);
130                 if (has_wdt) {
131                         mpc52xx_wdt = of_iomap(np, 0);
132                         of_node_put(np);
133                         return;
134                 }
135
136         }
137 }
138
139 void
140 mpc52xx_restart(char *cmd)
141 {
142         local_irq_disable();
143
144         /* Turn on the watchdog and wait for it to expire.
145          * It effectively does a reset. */
146         if (mpc52xx_wdt) {
147                 out_be32(&mpc52xx_wdt->mode, 0x00000000);
148                 out_be32(&mpc52xx_wdt->count, 0x000000ff);
149                 out_be32(&mpc52xx_wdt->mode, 0x00009004);
150         } else
151                 printk("mpc52xx_restart: Can't access wdt. "
152                         "Restart impossible, system halted.\n");
153
154         while (1);
155 }