2 * Copyright (C) 2007,2008 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: John Rigby <jrigby@freescale.com>
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/kernel.h>
17 #include <linux/irq.h>
18 #include <linux/of_platform.h>
20 #include <asm/machdep.h>
24 #include <asm/mpc5121.h>
25 #include <asm/mpc52xx_psc.h>
29 static struct mpc512x_reset_module __iomem *reset_module_base;
31 static void __init mpc512x_restart_init(void)
33 struct device_node *np;
35 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-reset");
39 reset_module_base = of_iomap(np, 0);
43 void mpc512x_restart(char *cmd)
45 if (reset_module_base) {
46 /* Enable software reset "RSTE" */
47 out_be32(&reset_module_base->rpr, 0x52535445);
48 /* Set software hard reset */
49 out_be32(&reset_module_base->rcr, 0x2);
51 pr_err("Restart module not mapped.\n");
57 void __init mpc512x_init_IRQ(void)
59 struct device_node *np;
61 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-ipic");
69 * Initialize the default interrupt mapping priorities,
70 * in case the boot rom changed something on us.
72 ipic_set_default_priority();
76 * Nodes to do bus probe on, soc and localbus
78 static struct of_device_id __initdata of_bus_ids[] = {
79 { .compatible = "fsl,mpc5121-immr", },
80 { .compatible = "fsl,mpc5121-localbus", },
84 void __init mpc512x_declare_of_platform_devices(void)
86 struct device_node *np;
88 if (of_platform_bus_probe(NULL, of_bus_ids, NULL))
89 printk(KERN_ERR __FILE__ ": "
90 "Error while probing of_platform bus\n");
92 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-nfc");
94 of_platform_device_create(np, NULL, NULL);
99 #define DEFAULT_FIFO_SIZE 16
101 static unsigned int __init get_fifo_size(struct device_node *np,
104 const unsigned int *fp;
106 fp = of_get_property(np, prop_name, NULL);
110 pr_warning("no %s property in %s node, defaulting to %d\n",
111 prop_name, np->full_name, DEFAULT_FIFO_SIZE);
113 return DEFAULT_FIFO_SIZE;
116 #define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
117 ((u32)(_base) + sizeof(struct mpc52xx_psc)))
119 /* Init PSC FIFO space for TX and RX slices */
120 void __init mpc512x_psc_fifo_init(void)
122 struct device_node *np;
124 unsigned int tx_fifo_size;
125 unsigned int rx_fifo_size;
126 int fifobase = 0; /* current fifo address in 32 bit words */
128 for_each_compatible_node(np, NULL, "fsl,mpc5121-psc") {
129 tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
130 rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
132 /* size in register is in 4 byte units */
140 psc = of_iomap(np, 0);
142 pr_err("%s: Can't map %s device\n",
143 __func__, np->full_name);
147 /* FIFO space is 4KiB, check if requested size is available */
148 if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
149 pr_err("%s: no fifo space available for %s\n",
150 __func__, np->full_name);
153 * chances are that another device requests less
154 * fifo space, so we continue.
159 /* set tx and rx fifo size registers */
160 out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
161 fifobase += tx_fifo_size;
162 out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
163 fifobase += rx_fifo_size;
165 /* reset and enable the slices */
166 out_be32(&FIFOC(psc)->txcmd, 0x80);
167 out_be32(&FIFOC(psc)->txcmd, 0x01);
168 out_be32(&FIFOC(psc)->rxcmd, 0x80);
169 out_be32(&FIFOC(psc)->rxcmd, 0x01);
175 void __init mpc512x_init(void)
177 mpc512x_declare_of_platform_devices();
179 mpc512x_restart_init();
180 mpc512x_psc_fifo_init();