Merge tag 'for-linus-20130909' of git://git.infradead.org/linux-mtd
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-shmobile / setup-emev2.c
1 /*
2  * Emma Mobile EV2 processor support
3  *
4  * Copyright (C) 2012  Magnus Damm
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/platform_device.h>
24 #include <linux/platform_data/gpio-em.h>
25 #include <linux/of_platform.h>
26 #include <linux/delay.h>
27 #include <linux/input.h>
28 #include <linux/io.h>
29 #include <linux/irqchip/arm-gic.h>
30 #include <mach/hardware.h>
31 #include <mach/common.h>
32 #include <mach/emev2.h>
33 #include <mach/irqs.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/time.h>
38
39 static struct map_desc emev2_io_desc[] __initdata = {
40 #ifdef CONFIG_SMP
41         /* 2M mapping for SCU + L2 controller */
42         {
43                 .virtual        = 0xf0000000,
44                 .pfn            = __phys_to_pfn(0x1e000000),
45                 .length         = SZ_2M,
46                 .type           = MT_DEVICE
47         },
48 #endif
49 };
50
51 void __init emev2_map_io(void)
52 {
53         iotable_init(emev2_io_desc, ARRAY_SIZE(emev2_io_desc));
54 }
55
56 /* UART */
57 static struct resource uart0_resources[] = {
58         DEFINE_RES_MEM(0xe1020000, 0x38),
59         DEFINE_RES_IRQ(40),
60 };
61
62 static struct resource uart1_resources[] = {
63         DEFINE_RES_MEM(0xe1030000, 0x38),
64         DEFINE_RES_IRQ(41),
65 };
66
67 static struct resource uart2_resources[] = {
68         DEFINE_RES_MEM(0xe1040000, 0x38),
69         DEFINE_RES_IRQ(42),
70 };
71
72 static struct resource uart3_resources[] = {
73         DEFINE_RES_MEM(0xe1050000, 0x38),
74         DEFINE_RES_IRQ(43),
75 };
76
77 #define emev2_register_uart(idx)                                        \
78         platform_device_register_simple("serial8250-em", idx,           \
79                                         uart##idx##_resources,          \
80                                         ARRAY_SIZE(uart##idx##_resources))
81
82 /* STI */
83 static struct resource sti_resources[] = {
84         DEFINE_RES_MEM(0xe0180000, 0x54),
85         DEFINE_RES_IRQ(157),
86 };
87
88 #define emev2_register_sti()                                    \
89         platform_device_register_simple("em_sti", 0,            \
90                                         sti_resources,          \
91                                         ARRAY_SIZE(sti_resources))
92
93 /* GIO */
94 static struct gpio_em_config gio0_config = {
95         .gpio_base = 0,
96         .irq_base = EMEV2_GPIO_IRQ(0),
97         .number_of_pins = 32,
98 };
99
100 static struct resource gio0_resources[] = {
101         DEFINE_RES_MEM(0xe0050000, 0x2c),
102         DEFINE_RES_MEM(0xe0050040, 0x20),
103         DEFINE_RES_IRQ(99),
104         DEFINE_RES_IRQ(100),
105 };
106
107 static struct gpio_em_config gio1_config = {
108         .gpio_base = 32,
109         .irq_base = EMEV2_GPIO_IRQ(32),
110         .number_of_pins = 32,
111 };
112
113 static struct resource gio1_resources[] = {
114         DEFINE_RES_MEM(0xe0050080, 0x2c),
115         DEFINE_RES_MEM(0xe00500c0, 0x20),
116         DEFINE_RES_IRQ(101),
117         DEFINE_RES_IRQ(102),
118 };
119
120 static struct gpio_em_config gio2_config = {
121         .gpio_base = 64,
122         .irq_base = EMEV2_GPIO_IRQ(64),
123         .number_of_pins = 32,
124 };
125
126 static struct resource gio2_resources[] = {
127         DEFINE_RES_MEM(0xe0050100, 0x2c),
128         DEFINE_RES_MEM(0xe0050140, 0x20),
129         DEFINE_RES_IRQ(103),
130         DEFINE_RES_IRQ(104),
131 };
132
133 static struct gpio_em_config gio3_config = {
134         .gpio_base = 96,
135         .irq_base = EMEV2_GPIO_IRQ(96),
136         .number_of_pins = 32,
137 };
138
139 static struct resource gio3_resources[] = {
140         DEFINE_RES_MEM(0xe0050180, 0x2c),
141         DEFINE_RES_MEM(0xe00501c0, 0x20),
142         DEFINE_RES_IRQ(105),
143         DEFINE_RES_IRQ(106),
144 };
145
146 static struct gpio_em_config gio4_config = {
147         .gpio_base = 128,
148         .irq_base = EMEV2_GPIO_IRQ(128),
149         .number_of_pins = 31,
150 };
151
152 static struct resource gio4_resources[] = {
153         DEFINE_RES_MEM(0xe0050200, 0x2c),
154         DEFINE_RES_MEM(0xe0050240, 0x20),
155         DEFINE_RES_IRQ(107),
156         DEFINE_RES_IRQ(108),
157 };
158
159 #define emev2_register_gio(idx)                                         \
160         platform_device_register_resndata(&platform_bus, "em_gio",      \
161                                           idx, gio##idx##_resources,    \
162                                           ARRAY_SIZE(gio##idx##_resources), \
163                                           &gio##idx##_config,           \
164                                           sizeof(struct gpio_em_config))
165
166 static struct resource pmu_resources[] = {
167         DEFINE_RES_IRQ(152),
168         DEFINE_RES_IRQ(153),
169 };
170
171 #define emev2_register_pmu()                                    \
172         platform_device_register_simple("arm-pmu", -1,          \
173                                         pmu_resources,          \
174                                         ARRAY_SIZE(pmu_resources))
175
176 void __init emev2_add_standard_devices(void)
177 {
178         if (!IS_ENABLED(CONFIG_COMMON_CLK))
179                 emev2_clock_init();
180
181         emev2_register_uart(0);
182         emev2_register_uart(1);
183         emev2_register_uart(2);
184         emev2_register_uart(3);
185         emev2_register_sti();
186         emev2_register_gio(0);
187         emev2_register_gio(1);
188         emev2_register_gio(2);
189         emev2_register_gio(3);
190         emev2_register_gio(4);
191         emev2_register_pmu();
192 }
193
194 void __init emev2_init_delay(void)
195 {
196         shmobile_setup_delay(533, 1, 3); /* Cortex-A9 @ 533MHz */
197 }
198
199 #ifdef CONFIG_USE_OF
200
201 static const char *emev2_boards_compat_dt[] __initdata = {
202         "renesas,emev2",
203         NULL,
204 };
205
206 DT_MACHINE_START(EMEV2_DT, "Generic Emma Mobile EV2 (Flattened Device Tree)")
207         .smp            = smp_ops(emev2_smp_ops),
208         .map_io         = emev2_map_io,
209         .init_early     = emev2_init_delay,
210         .dt_compat      = emev2_boards_compat_dt,
211 MACHINE_END
212
213 #endif /* CONFIG_USE_OF */