Merge tag 'powerpc-6.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[platform/kernel/linux-rpi.git] / arch / powerpc / platforms / 8xx / tqm8xx_setup.c
1 /*
2  * Platform setup for the MPC8xx based boards from TQM.
3  *
4  * Heiko Schocher <hs@denx.de>
5  * Copyright 2010 DENX Software Engineering GmbH
6  *
7  * based on:
8  * Vitaly Bordug <vbordug@ru.mvista.com>
9  *
10  * Copyright 2005 MontaVista Software Inc.
11  *
12  * Heavily modified by Scott Wood <scottwood@freescale.com>
13  * Copyright 2007 Freescale Semiconductor, Inc.
14  *
15  * This file is licensed under the terms of the GNU General Public License
16  * version 2. This program is licensed "as is" without any warranty of any
17  * kind, whether express or implied.
18  */
19
20 #include <linux/init.h>
21 #include <linux/param.h>
22 #include <linux/string.h>
23 #include <linux/ioport.h>
24 #include <linux/device.h>
25 #include <linux/delay.h>
26
27 #include <linux/fs_uart_pd.h>
28 #include <linux/fsl_devices.h>
29 #include <linux/mii.h>
30 #include <linux/of_fdt.h>
31 #include <linux/of_platform.h>
32
33 #include <asm/delay.h>
34 #include <asm/io.h>
35 #include <asm/machdep.h>
36 #include <asm/page.h>
37 #include <asm/processor.h>
38 #include <asm/time.h>
39 #include <asm/8xx_immap.h>
40 #include <asm/cpm1.h>
41 #include <asm/udbg.h>
42
43 #include "mpc8xx.h"
44 #include "pic.h"
45
46 struct cpm_pin {
47         int port, pin, flags;
48 };
49
50 static struct cpm_pin tqm8xx_pins[] __initdata = {
51         /* SMC1 */
52         {CPM_PORTB, 24, CPM_PIN_INPUT}, /* RX */
53         {CPM_PORTB, 25, CPM_PIN_INPUT | CPM_PIN_SECONDARY}, /* TX */
54
55         /* SCC1 */
56         {CPM_PORTA, 5, CPM_PIN_INPUT}, /* CLK1 */
57         {CPM_PORTA, 7, CPM_PIN_INPUT}, /* CLK2 */
58         {CPM_PORTA, 14, CPM_PIN_INPUT}, /* TX */
59         {CPM_PORTA, 15, CPM_PIN_INPUT}, /* RX */
60         {CPM_PORTC, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY}, /* TENA */
61         {CPM_PORTC, 10, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_GPIO},
62         {CPM_PORTC, 11, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_GPIO},
63 };
64
65 static struct cpm_pin tqm8xx_fec_pins[] __initdata = {
66         /* MII */
67         {CPM_PORTD, 3, CPM_PIN_OUTPUT},
68         {CPM_PORTD, 4, CPM_PIN_OUTPUT},
69         {CPM_PORTD, 5, CPM_PIN_OUTPUT},
70         {CPM_PORTD, 6, CPM_PIN_OUTPUT},
71         {CPM_PORTD, 7, CPM_PIN_OUTPUT},
72         {CPM_PORTD, 8, CPM_PIN_OUTPUT},
73         {CPM_PORTD, 9, CPM_PIN_OUTPUT},
74         {CPM_PORTD, 10, CPM_PIN_OUTPUT},
75         {CPM_PORTD, 11, CPM_PIN_OUTPUT},
76         {CPM_PORTD, 12, CPM_PIN_OUTPUT},
77         {CPM_PORTD, 13, CPM_PIN_OUTPUT},
78         {CPM_PORTD, 14, CPM_PIN_OUTPUT},
79         {CPM_PORTD, 15, CPM_PIN_OUTPUT},
80 };
81
82 static void __init init_pins(int n, struct cpm_pin *pin)
83 {
84         int i;
85
86         for (i = 0; i < n; i++) {
87                 cpm1_set_pin(pin->port, pin->pin, pin->flags);
88                 pin++;
89         }
90 }
91
92 static void __init init_ioports(void)
93 {
94         struct device_node *dnode;
95         struct property *prop;
96         int     len;
97
98         init_pins(ARRAY_SIZE(tqm8xx_pins), &tqm8xx_pins[0]);
99
100         cpm1_clk_setup(CPM_CLK_SMC1, CPM_BRG1, CPM_CLK_RTX);
101
102         dnode = of_find_node_by_name(NULL, "aliases");
103         if (dnode == NULL)
104                 return;
105         prop = of_find_property(dnode, "ethernet1", &len);
106
107         of_node_put(dnode);
108
109         if (prop == NULL)
110                 return;
111
112         /* init FEC pins */
113         init_pins(ARRAY_SIZE(tqm8xx_fec_pins), &tqm8xx_fec_pins[0]);
114 }
115
116 static void __init tqm8xx_setup_arch(void)
117 {
118         cpm_reset();
119         init_ioports();
120 }
121
122 static const struct of_device_id of_bus_ids[] __initconst = {
123         { .name = "soc", },
124         { .name = "cpm", },
125         { .name = "localbus", },
126         { .compatible = "simple-bus" },
127         {},
128 };
129
130 static int __init declare_of_platform_devices(void)
131 {
132         of_platform_bus_probe(NULL, of_bus_ids, NULL);
133
134         return 0;
135 }
136 machine_device_initcall(tqm8xx, declare_of_platform_devices);
137
138 define_machine(tqm8xx) {
139         .name                   = "TQM8xx",
140         .compatible             = "tqc,tqm8xx",
141         .setup_arch             = tqm8xx_setup_arch,
142         .init_IRQ               = mpc8xx_pic_init,
143         .get_irq                = mpc8xx_get_irq,
144         .restart                = mpc8xx_restart,
145         .calibrate_decr         = mpc8xx_calibrate_decr,
146         .set_rtc_time           = mpc8xx_set_rtc_time,
147         .get_rtc_time           = mpc8xx_get_rtc_time,
148         .progress               = udbg_progress,
149 };