Linux 3.14.25
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / arm / mach-shmobile / setup-r8a7790.c
1 /*
2  * r8a7790 processor support
3  *
4  * Copyright (C) 2013  Renesas Solutions Corp.
5  * Copyright (C) 2013  Magnus Damm
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include <linux/irq.h>
22 #include <linux/kernel.h>
23 #include <linux/of_platform.h>
24 #include <linux/platform_data/gpio-rcar.h>
25 #include <linux/platform_data/irq-renesas-irqc.h>
26 #include <linux/serial_sci.h>
27 #include <linux/sh_timer.h>
28 #include <mach/common.h>
29 #include <mach/irqs.h>
30 #include <mach/r8a7790.h>
31 #include <asm/mach/arch.h>
32
33 static const struct resource pfc_resources[] __initconst = {
34         DEFINE_RES_MEM(0xe6060000, 0x250),
35 };
36
37 #define r8a7790_register_pfc()                                          \
38         platform_device_register_simple("pfc-r8a7790", -1, pfc_resources, \
39                                         ARRAY_SIZE(pfc_resources))
40
41 #define R8A7790_GPIO(idx)                                               \
42 static const struct resource r8a7790_gpio##idx##_resources[] __initconst = { \
43         DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50),              \
44         DEFINE_RES_IRQ(gic_spi(4 + (idx))),                             \
45 };                                                                      \
46                                                                         \
47 static const struct gpio_rcar_config                                    \
48 r8a7790_gpio##idx##_platform_data __initconst = {                       \
49         .gpio_base      = 32 * (idx),                                   \
50         .irq_base       = 0,                                            \
51         .number_of_pins = 32,                                           \
52         .pctl_name      = "pfc-r8a7790",                                \
53         .has_both_edge_trigger = 1,                                     \
54 };                                                                      \
55
56 R8A7790_GPIO(0);
57 R8A7790_GPIO(1);
58 R8A7790_GPIO(2);
59 R8A7790_GPIO(3);
60 R8A7790_GPIO(4);
61 R8A7790_GPIO(5);
62
63 #define r8a7790_register_gpio(idx)                                      \
64         platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \
65                 r8a7790_gpio##idx##_resources,                          \
66                 ARRAY_SIZE(r8a7790_gpio##idx##_resources),              \
67                 &r8a7790_gpio##idx##_platform_data,                     \
68                 sizeof(r8a7790_gpio##idx##_platform_data))
69
70 static struct resource i2c_resources[] __initdata = {
71         /* I2C0 */
72         DEFINE_RES_MEM(0xE6508000, 0x40),
73         DEFINE_RES_IRQ(gic_spi(287)),
74         /* I2C1 */
75         DEFINE_RES_MEM(0xE6518000, 0x40),
76         DEFINE_RES_IRQ(gic_spi(288)),
77         /* I2C2 */
78         DEFINE_RES_MEM(0xE6530000, 0x40),
79         DEFINE_RES_IRQ(gic_spi(286)),
80         /* I2C3 */
81         DEFINE_RES_MEM(0xE6540000, 0x40),
82         DEFINE_RES_IRQ(gic_spi(290)),
83
84 };
85
86 #define r8a7790_register_i2c(idx)               \
87         platform_device_register_simple(        \
88                 "i2c-rcar_gen2", idx,           \
89                 i2c_resources + (2 * idx), 2);  \
90
91 void __init r8a7790_pinmux_init(void)
92 {
93         r8a7790_register_pfc();
94         r8a7790_register_gpio(0);
95         r8a7790_register_gpio(1);
96         r8a7790_register_gpio(2);
97         r8a7790_register_gpio(3);
98         r8a7790_register_gpio(4);
99         r8a7790_register_gpio(5);
100         r8a7790_register_i2c(0);
101         r8a7790_register_i2c(1);
102         r8a7790_register_i2c(2);
103         r8a7790_register_i2c(3);
104 }
105
106 #define __R8A7790_SCIF(scif_type, _scscr, index, baseaddr, irq)         \
107 static struct plat_sci_port scif##index##_platform_data = {             \
108         .type           = scif_type,                                    \
109         .flags          = UPF_BOOT_AUTOCONF | UPF_IOREMAP,              \
110         .scscr          = _scscr,                                       \
111 };                                                                      \
112                                                                         \
113 static struct resource scif##index##_resources[] = {                    \
114         DEFINE_RES_MEM(baseaddr, 0x100),                                \
115         DEFINE_RES_IRQ(irq),                                            \
116 }
117
118 #define R8A7790_SCIF(index, baseaddr, irq)                              \
119         __R8A7790_SCIF(PORT_SCIF, SCSCR_RE | SCSCR_TE,                  \
120                        index, baseaddr, irq)
121
122 #define R8A7790_SCIFA(index, baseaddr, irq)                             \
123         __R8A7790_SCIF(PORT_SCIFA, SCSCR_RE | SCSCR_TE | SCSCR_CKE0,    \
124                        index, baseaddr, irq)
125
126 #define R8A7790_SCIFB(index, baseaddr, irq)                             \
127         __R8A7790_SCIF(PORT_SCIFB, SCSCR_RE | SCSCR_TE,                 \
128                        index, baseaddr, irq)
129
130 #define R8A7790_HSCIF(index, baseaddr, irq)                             \
131         __R8A7790_SCIF(PORT_HSCIF, SCSCR_RE | SCSCR_TE,                 \
132                        index, baseaddr, irq)
133
134 R8A7790_SCIFA(0, 0xe6c40000, gic_spi(144)); /* SCIFA0 */
135 R8A7790_SCIFA(1, 0xe6c50000, gic_spi(145)); /* SCIFA1 */
136 R8A7790_SCIFB(2, 0xe6c20000, gic_spi(148)); /* SCIFB0 */
137 R8A7790_SCIFB(3, 0xe6c30000, gic_spi(149)); /* SCIFB1 */
138 R8A7790_SCIFB(4, 0xe6ce0000, gic_spi(150)); /* SCIFB2 */
139 R8A7790_SCIFA(5, 0xe6c60000, gic_spi(151)); /* SCIFA2 */
140 R8A7790_SCIF(6,  0xe6e60000, gic_spi(152)); /* SCIF0 */
141 R8A7790_SCIF(7,  0xe6e68000, gic_spi(153)); /* SCIF1 */
142 R8A7790_HSCIF(8, 0xe62c0000, gic_spi(154)); /* HSCIF0 */
143 R8A7790_HSCIF(9, 0xe62c8000, gic_spi(155)); /* HSCIF1 */
144
145 #define r8a7790_register_scif(index)                                           \
146         platform_device_register_resndata(&platform_bus, "sh-sci", index,      \
147                                           scif##index##_resources,             \
148                                           ARRAY_SIZE(scif##index##_resources), \
149                                           &scif##index##_platform_data,        \
150                                           sizeof(scif##index##_platform_data))
151
152 static const struct renesas_irqc_config irqc0_data __initconst = {
153         .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
154 };
155
156 static const struct resource irqc0_resources[] __initconst = {
157         DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
158         DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
159         DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
160         DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
161         DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
162 };
163
164 #define r8a7790_register_irqc(idx)                                      \
165         platform_device_register_resndata(&platform_bus, "renesas_irqc", \
166                                           idx, irqc##idx##_resources,   \
167                                           ARRAY_SIZE(irqc##idx##_resources), \
168                                           &irqc##idx##_data,            \
169                                           sizeof(struct renesas_irqc_config))
170
171 static const struct resource thermal_resources[] __initconst = {
172         DEFINE_RES_MEM(0xe61f0000, 0x14),
173         DEFINE_RES_MEM(0xe61f0100, 0x38),
174         DEFINE_RES_IRQ(gic_spi(69)),
175 };
176
177 #define r8a7790_register_thermal()                                      \
178         platform_device_register_simple("rcar_thermal", -1,             \
179                                         thermal_resources,              \
180                                         ARRAY_SIZE(thermal_resources))
181
182 static const struct sh_timer_config cmt00_platform_data __initconst = {
183         .name = "CMT00",
184         .timer_bit = 0,
185         .clockevent_rating = 80,
186 };
187
188 static const struct resource cmt00_resources[] __initconst = {
189         DEFINE_RES_MEM(0xffca0510, 0x0c),
190         DEFINE_RES_MEM(0xffca0500, 0x04),
191         DEFINE_RES_IRQ(gic_spi(142)), /* CMT0_0 */
192 };
193
194 #define r8a7790_register_cmt(idx)                                       \
195         platform_device_register_resndata(&platform_bus, "sh_cmt",      \
196                                           idx, cmt##idx##_resources,    \
197                                           ARRAY_SIZE(cmt##idx##_resources), \
198                                           &cmt##idx##_platform_data,    \
199                                           sizeof(struct sh_timer_config))
200
201 void __init r8a7790_add_dt_devices(void)
202 {
203         r8a7790_register_scif(0);
204         r8a7790_register_scif(1);
205         r8a7790_register_scif(2);
206         r8a7790_register_scif(3);
207         r8a7790_register_scif(4);
208         r8a7790_register_scif(5);
209         r8a7790_register_scif(6);
210         r8a7790_register_scif(7);
211         r8a7790_register_scif(8);
212         r8a7790_register_scif(9);
213         r8a7790_register_cmt(00);
214 }
215
216 void __init r8a7790_add_standard_devices(void)
217 {
218         r8a7790_add_dt_devices();
219         r8a7790_register_irqc(0);
220         r8a7790_register_thermal();
221 }
222
223 void __init r8a7790_init_early(void)
224 {
225 #ifndef CONFIG_ARM_ARCH_TIMER
226         shmobile_setup_delay(1300, 2, 4); /* Cortex-A15 @ 1300MHz */
227 #endif
228 }
229
230 #ifdef CONFIG_USE_OF
231
232 static const char * const r8a7790_boards_compat_dt[] __initconst = {
233         "renesas,r8a7790",
234         NULL,
235 };
236
237 DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)")
238         .smp            = smp_ops(r8a7790_smp_ops),
239         .init_early     = r8a7790_init_early,
240         .init_time      = rcar_gen2_timer_init,
241         .dt_compat      = r8a7790_boards_compat_dt,
242 MACHINE_END
243 #endif /* CONFIG_USE_OF */