blob: 3543c3bacb75d828cd9681f9e5b93740822a9467 [file] [log] [blame]
Magnus Damm0468b2d2013-03-28 00:49:34 +09001/*
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>
Magnus Damm0468b2d2013-03-28 00:49:34 +090022#include <linux/kernel.h>
23#include <linux/of_platform.h>
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020024#include <linux/platform_data/gpio-rcar.h>
Magnus Damm8f5ec0a2013-03-28 00:49:54 +090025#include <linux/platform_data/irq-renesas-irqc.h>
Magnus Damm99ade1a2013-06-28 20:27:04 +090026#include <linux/serial_sci.h>
27#include <linux/sh_timer.h>
Magnus Damm0468b2d2013-03-28 00:49:34 +090028#include <mach/common.h>
29#include <mach/irqs.h>
30#include <mach/r8a7790.h>
31#include <asm/mach/arch.h>
32
Laurent Pinchartcde214a2013-08-08 00:34:53 +020033static const struct resource pfc_resources[] __initconst = {
Magnus Damm69e351d2013-03-28 00:50:03 +090034 DEFINE_RES_MEM(0xe6060000, 0x250),
35};
36
Magnus Damm8d0b3bf2013-10-17 06:51:46 +090037#define r8a7790_register_pfc() \
38 platform_device_register_simple("pfc-r8a7790", -1, pfc_resources, \
39 ARRAY_SIZE(pfc_resources))
40
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020041#define R8A7790_GPIO(idx) \
Laurent Pinchartcde214a2013-08-08 00:34:53 +020042static const struct resource r8a7790_gpio##idx##_resources[] __initconst = { \
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020043 DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \
44 DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
45}; \
46 \
Laurent Pinchartcde214a2013-08-08 00:34:53 +020047static const struct gpio_rcar_config \
48r8a7790_gpio##idx##_platform_data __initconst = { \
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020049 .gpio_base = 32 * (idx), \
50 .irq_base = 0, \
51 .number_of_pins = 32, \
52 .pctl_name = "pfc-r8a7790", \
Simon Hormand93906b82013-05-13 17:53:52 +090053 .has_both_edge_trigger = 1, \
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020054}; \
55
56R8A7790_GPIO(0);
57R8A7790_GPIO(1);
58R8A7790_GPIO(2);
59R8A7790_GPIO(3);
60R8A7790_GPIO(4);
61R8A7790_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
Magnus Damm69e351d2013-03-28 00:50:03 +090070void __init r8a7790_pinmux_init(void)
71{
Magnus Damm8d0b3bf2013-10-17 06:51:46 +090072 r8a7790_register_pfc();
Laurent Pinchart43ca9cb2013-04-08 11:36:17 +020073 r8a7790_register_gpio(0);
74 r8a7790_register_gpio(1);
75 r8a7790_register_gpio(2);
76 r8a7790_register_gpio(3);
77 r8a7790_register_gpio(4);
78 r8a7790_register_gpio(5);
Magnus Damm69e351d2013-03-28 00:50:03 +090079}
80
Magnus Damm55d9fab2013-03-28 00:49:44 +090081#define SCIF_COMMON(scif_type, baseaddr, irq) \
82 .type = scif_type, \
83 .mapbase = baseaddr, \
84 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
85 .irqs = SCIx_IRQ_MUXED(irq)
86
87#define SCIFA_DATA(index, baseaddr, irq) \
88[index] = { \
89 SCIF_COMMON(PORT_SCIFA, baseaddr, irq), \
90 .scbrr_algo_id = SCBRR_ALGO_4, \
91 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
92}
93
94#define SCIFB_DATA(index, baseaddr, irq) \
95[index] = { \
96 SCIF_COMMON(PORT_SCIFB, baseaddr, irq), \
97 .scbrr_algo_id = SCBRR_ALGO_4, \
98 .scscr = SCSCR_RE | SCSCR_TE, \
99}
100
101#define SCIF_DATA(index, baseaddr, irq) \
102[index] = { \
103 SCIF_COMMON(PORT_SCIF, baseaddr, irq), \
104 .scbrr_algo_id = SCBRR_ALGO_2, \
Ulrich Hechtc972f022013-05-31 17:57:04 +0200105 .scscr = SCSCR_RE | SCSCR_TE, \
Magnus Damm55d9fab2013-03-28 00:49:44 +0900106}
107
Ulrich Hechtd44f8302013-05-31 17:57:02 +0200108#define HSCIF_DATA(index, baseaddr, irq) \
109[index] = { \
110 SCIF_COMMON(PORT_HSCIF, baseaddr, irq), \
111 .scbrr_algo_id = SCBRR_ALGO_6, \
112 .scscr = SCSCR_RE | SCSCR_TE, \
113}
114
115enum { SCIFA0, SCIFA1, SCIFB0, SCIFB1, SCIFB2, SCIFA2, SCIF0, SCIF1,
116 HSCIF0, HSCIF1 };
Magnus Damm55d9fab2013-03-28 00:49:44 +0900117
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200118static const struct plat_sci_port scif[] __initconst = {
Magnus Damm55d9fab2013-03-28 00:49:44 +0900119 SCIFA_DATA(SCIFA0, 0xe6c40000, gic_spi(144)), /* SCIFA0 */
120 SCIFA_DATA(SCIFA1, 0xe6c50000, gic_spi(145)), /* SCIFA1 */
121 SCIFB_DATA(SCIFB0, 0xe6c20000, gic_spi(148)), /* SCIFB0 */
122 SCIFB_DATA(SCIFB1, 0xe6c30000, gic_spi(149)), /* SCIFB1 */
123 SCIFB_DATA(SCIFB2, 0xe6ce0000, gic_spi(150)), /* SCIFB2 */
124 SCIFA_DATA(SCIFA2, 0xe6c60000, gic_spi(151)), /* SCIFA2 */
125 SCIF_DATA(SCIF0, 0xe6e60000, gic_spi(152)), /* SCIF0 */
126 SCIF_DATA(SCIF1, 0xe6e68000, gic_spi(153)), /* SCIF1 */
Ulrich Hechtd44f8302013-05-31 17:57:02 +0200127 HSCIF_DATA(HSCIF0, 0xe62c0000, gic_spi(154)), /* HSCIF0 */
128 HSCIF_DATA(HSCIF1, 0xe62c8000, gic_spi(155)), /* HSCIF1 */
Magnus Damm55d9fab2013-03-28 00:49:44 +0900129};
130
131static inline void r8a7790_register_scif(int idx)
132{
133 platform_device_register_data(&platform_bus, "sh-sci", idx, &scif[idx],
134 sizeof(struct plat_sci_port));
135}
136
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200137static const struct renesas_irqc_config irqc0_data __initconst = {
Magnus Damm8f5ec0a2013-03-28 00:49:54 +0900138 .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
139};
140
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200141static const struct resource irqc0_resources[] __initconst = {
Magnus Damm8f5ec0a2013-03-28 00:49:54 +0900142 DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
143 DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
144 DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
145 DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
146 DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
147};
148
149#define r8a7790_register_irqc(idx) \
150 platform_device_register_resndata(&platform_bus, "renesas_irqc", \
151 idx, irqc##idx##_resources, \
152 ARRAY_SIZE(irqc##idx##_resources), \
153 &irqc##idx##_data, \
154 sizeof(struct renesas_irqc_config))
155
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200156static const struct resource thermal_resources[] __initconst = {
Simon Horman0b8eeba2013-06-26 16:22:21 +0900157 DEFINE_RES_MEM(0xe61f0000, 0x14),
158 DEFINE_RES_MEM(0xe61f0100, 0x38),
159 DEFINE_RES_IRQ(gic_spi(69)),
160};
161
162#define r8a7790_register_thermal() \
163 platform_device_register_simple("rcar_thermal", -1, \
164 thermal_resources, \
165 ARRAY_SIZE(thermal_resources))
166
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200167static const struct sh_timer_config cmt00_platform_data __initconst = {
Magnus Damm99ade1a2013-06-28 20:27:04 +0900168 .name = "CMT00",
169 .timer_bit = 0,
170 .clockevent_rating = 80,
171};
172
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200173static const struct resource cmt00_resources[] __initconst = {
Magnus Damm99ade1a2013-06-28 20:27:04 +0900174 DEFINE_RES_MEM(0xffca0510, 0x0c),
175 DEFINE_RES_MEM(0xffca0500, 0x04),
176 DEFINE_RES_IRQ(gic_spi(142)), /* CMT0_0 */
177};
178
179#define r8a7790_register_cmt(idx) \
180 platform_device_register_resndata(&platform_bus, "sh_cmt", \
181 idx, cmt##idx##_resources, \
182 ARRAY_SIZE(cmt##idx##_resources), \
183 &cmt##idx##_platform_data, \
184 sizeof(struct sh_timer_config))
185
Simon Horman6dace672013-06-28 13:42:16 +0900186void __init r8a7790_add_dt_devices(void)
Magnus Damm0468b2d2013-03-28 00:49:34 +0900187{
Magnus Damm55d9fab2013-03-28 00:49:44 +0900188 r8a7790_register_scif(SCIFA0);
189 r8a7790_register_scif(SCIFA1);
190 r8a7790_register_scif(SCIFB0);
191 r8a7790_register_scif(SCIFB1);
192 r8a7790_register_scif(SCIFB2);
193 r8a7790_register_scif(SCIFA2);
194 r8a7790_register_scif(SCIF0);
195 r8a7790_register_scif(SCIF1);
Ulrich Hechtd44f8302013-05-31 17:57:02 +0200196 r8a7790_register_scif(HSCIF0);
197 r8a7790_register_scif(HSCIF1);
Simon Horman6dace672013-06-28 13:42:16 +0900198 r8a7790_register_cmt(00);
199}
200
201void __init r8a7790_add_standard_devices(void)
202{
203 r8a7790_add_dt_devices();
Magnus Damm8f5ec0a2013-03-28 00:49:54 +0900204 r8a7790_register_irqc(0);
Simon Horman0b8eeba2013-06-26 16:22:21 +0900205 r8a7790_register_thermal();
Magnus Damm0468b2d2013-03-28 00:49:34 +0900206}
207
Magnus Damm0efd7fa2013-08-08 07:27:01 +0900208void __init r8a7790_init_early(void)
Magnus Damm8333d8c2013-06-28 20:27:13 +0900209{
210#ifndef CONFIG_ARM_ARCH_TIMER
211 shmobile_setup_delay(1300, 2, 4); /* Cortex-A15 @ 1300MHz */
212#endif
213}
214
Magnus Damm0468b2d2013-03-28 00:49:34 +0900215#ifdef CONFIG_USE_OF
Magnus Damm0468b2d2013-03-28 00:49:34 +0900216
Laurent Pinchartcde214a2013-08-08 00:34:53 +0200217static const char * const r8a7790_boards_compat_dt[] __initconst = {
Magnus Damm0468b2d2013-03-28 00:49:34 +0900218 "renesas,r8a7790",
219 NULL,
220};
221
222DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)")
Magnus Dammad09cb82013-08-29 08:22:07 +0900223 .smp = smp_ops(r8a7790_smp_ops),
Magnus Damm0efd7fa2013-08-08 07:27:01 +0900224 .init_early = r8a7790_init_early,
Magnus Damm50c517d2013-09-12 09:32:49 +0900225 .init_time = rcar_gen2_timer_init,
Magnus Damm0468b2d2013-03-28 00:49:34 +0900226 .dt_compat = r8a7790_boards_compat_dt,
227MACHINE_END
228#endif /* CONFIG_USE_OF */