2 * r8a7790 processor support
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Magnus Damm
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.
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.
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
21 #include <linux/clocksource.h>
22 #include <linux/irq.h>
23 #include <linux/kernel.h>
24 #include <linux/of_platform.h>
25 #include <linux/platform_data/gpio-rcar.h>
26 #include <linux/platform_data/irq-renesas-irqc.h>
27 #include <linux/serial_sci.h>
28 #include <linux/sh_timer.h>
29 #include <mach/common.h>
30 #include <mach/irqs.h>
31 #include <mach/r8a7790.h>
32 #include <asm/mach/arch.h>
34 static const struct resource pfc_resources
[] __initconst
= {
35 DEFINE_RES_MEM(0xe6060000, 0x250),
38 #define R8A7790_GPIO(idx) \
39 static const struct resource r8a7790_gpio##idx##_resources[] __initconst = { \
40 DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \
41 DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
44 static const struct gpio_rcar_config \
45 r8a7790_gpio##idx##_platform_data __initconst = { \
46 .gpio_base = 32 * (idx), \
48 .number_of_pins = 32, \
49 .pctl_name = "pfc-r8a7790", \
50 .has_both_edge_trigger = 1, \
60 #define r8a7790_register_gpio(idx) \
61 platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \
62 r8a7790_gpio##idx##_resources, \
63 ARRAY_SIZE(r8a7790_gpio##idx##_resources), \
64 &r8a7790_gpio##idx##_platform_data, \
65 sizeof(r8a7790_gpio##idx##_platform_data))
67 void __init
r8a7790_pinmux_init(void)
69 platform_device_register_simple("pfc-r8a7790", -1, pfc_resources
,
70 ARRAY_SIZE(pfc_resources
));
71 r8a7790_register_gpio(0);
72 r8a7790_register_gpio(1);
73 r8a7790_register_gpio(2);
74 r8a7790_register_gpio(3);
75 r8a7790_register_gpio(4);
76 r8a7790_register_gpio(5);
79 #define SCIF_COMMON(scif_type, baseaddr, irq) \
81 .mapbase = baseaddr, \
82 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
83 .irqs = SCIx_IRQ_MUXED(irq)
85 #define SCIFA_DATA(index, baseaddr, irq) \
87 SCIF_COMMON(PORT_SCIFA, baseaddr, irq), \
88 .scbrr_algo_id = SCBRR_ALGO_4, \
89 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
92 #define SCIFB_DATA(index, baseaddr, irq) \
94 SCIF_COMMON(PORT_SCIFB, baseaddr, irq), \
95 .scbrr_algo_id = SCBRR_ALGO_4, \
96 .scscr = SCSCR_RE | SCSCR_TE, \
99 #define SCIF_DATA(index, baseaddr, irq) \
101 SCIF_COMMON(PORT_SCIF, baseaddr, irq), \
102 .scbrr_algo_id = SCBRR_ALGO_2, \
103 .scscr = SCSCR_RE | SCSCR_TE, \
106 #define HSCIF_DATA(index, baseaddr, irq) \
108 SCIF_COMMON(PORT_HSCIF, baseaddr, irq), \
109 .scbrr_algo_id = SCBRR_ALGO_6, \
110 .scscr = SCSCR_RE | SCSCR_TE, \
113 enum { SCIFA0
, SCIFA1
, SCIFB0
, SCIFB1
, SCIFB2
, SCIFA2
, SCIF0
, SCIF1
,
116 static const struct plat_sci_port scif
[] __initconst
= {
117 SCIFA_DATA(SCIFA0
, 0xe6c40000, gic_spi(144)), /* SCIFA0 */
118 SCIFA_DATA(SCIFA1
, 0xe6c50000, gic_spi(145)), /* SCIFA1 */
119 SCIFB_DATA(SCIFB0
, 0xe6c20000, gic_spi(148)), /* SCIFB0 */
120 SCIFB_DATA(SCIFB1
, 0xe6c30000, gic_spi(149)), /* SCIFB1 */
121 SCIFB_DATA(SCIFB2
, 0xe6ce0000, gic_spi(150)), /* SCIFB2 */
122 SCIFA_DATA(SCIFA2
, 0xe6c60000, gic_spi(151)), /* SCIFA2 */
123 SCIF_DATA(SCIF0
, 0xe6e60000, gic_spi(152)), /* SCIF0 */
124 SCIF_DATA(SCIF1
, 0xe6e68000, gic_spi(153)), /* SCIF1 */
125 HSCIF_DATA(HSCIF0
, 0xe62c0000, gic_spi(154)), /* HSCIF0 */
126 HSCIF_DATA(HSCIF1
, 0xe62c8000, gic_spi(155)), /* HSCIF1 */
129 static inline void r8a7790_register_scif(int idx
)
131 platform_device_register_data(&platform_bus
, "sh-sci", idx
, &scif
[idx
],
132 sizeof(struct plat_sci_port
));
135 static const struct renesas_irqc_config irqc0_data __initconst
= {
136 .irq_base
= irq_pin(0), /* IRQ0 -> IRQ3 */
139 static const struct resource irqc0_resources
[] __initconst
= {
140 DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
141 DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
142 DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
143 DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
144 DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
147 #define r8a7790_register_irqc(idx) \
148 platform_device_register_resndata(&platform_bus, "renesas_irqc", \
149 idx, irqc##idx##_resources, \
150 ARRAY_SIZE(irqc##idx##_resources), \
152 sizeof(struct renesas_irqc_config))
154 static const struct resource thermal_resources
[] __initconst
= {
155 DEFINE_RES_MEM(0xe61f0000, 0x14),
156 DEFINE_RES_MEM(0xe61f0100, 0x38),
157 DEFINE_RES_IRQ(gic_spi(69)),
160 #define r8a7790_register_thermal() \
161 platform_device_register_simple("rcar_thermal", -1, \
163 ARRAY_SIZE(thermal_resources))
165 static const struct sh_timer_config cmt00_platform_data __initconst
= {
168 .clockevent_rating
= 80,
171 static const struct resource cmt00_resources
[] __initconst
= {
172 DEFINE_RES_MEM(0xffca0510, 0x0c),
173 DEFINE_RES_MEM(0xffca0500, 0x04),
174 DEFINE_RES_IRQ(gic_spi(142)), /* CMT0_0 */
177 #define r8a7790_register_cmt(idx) \
178 platform_device_register_resndata(&platform_bus, "sh_cmt", \
179 idx, cmt##idx##_resources, \
180 ARRAY_SIZE(cmt##idx##_resources), \
181 &cmt##idx##_platform_data, \
182 sizeof(struct sh_timer_config))
184 void __init
r8a7790_add_dt_devices(void)
186 r8a7790_register_scif(SCIFA0
);
187 r8a7790_register_scif(SCIFA1
);
188 r8a7790_register_scif(SCIFB0
);
189 r8a7790_register_scif(SCIFB1
);
190 r8a7790_register_scif(SCIFB2
);
191 r8a7790_register_scif(SCIFA2
);
192 r8a7790_register_scif(SCIF0
);
193 r8a7790_register_scif(SCIF1
);
194 r8a7790_register_scif(HSCIF0
);
195 r8a7790_register_scif(HSCIF1
);
196 r8a7790_register_cmt(00);
199 void __init
r8a7790_add_standard_devices(void)
201 r8a7790_add_dt_devices();
202 r8a7790_register_irqc(0);
203 r8a7790_register_thermal();
206 #define MODEMR 0xe6160060
208 u32 __init
r8a7790_read_mode_pins(void)
210 void __iomem
*modemr
= ioremap_nocache(MODEMR
, 4);
214 mode
= ioread32(modemr
);
223 void __init
r8a7790_timer_init(void)
225 #ifdef CONFIG_ARM_ARCH_TIMER
226 u32 mode
= r8a7790_read_mode_pins();
231 /* At Linux boot time the r8a7790 arch timer comes up
232 * with the counter disabled. Moreover, it may also report
233 * a potentially incorrect fixed 13 MHz frequency. To be
234 * correct these registers need to be updated to use the
235 * frequency EXTAL / 2 which can be determined by the MD pins.
238 switch (mode
& (MD(14) | MD(13))) {
248 case MD(13) | MD(14):
253 /* The arch timer frequency equals EXTAL / 2 */
254 freq
= extal_mhz
* (1000000 / 2);
256 /* Remap "armgcnt address map" space */
257 base
= ioremap(0xe6080000, PAGE_SIZE
);
259 /* Update registers with correct frequency */
260 iowrite32(freq
, base
+ CNTFID0
);
261 asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq
));
263 /* make sure arch timer is started by setting bit 0 of CNTCR */
264 iowrite32(1, base
+ CNTCR
);
266 #endif /* CONFIG_ARM_ARCH_TIMER */
268 clocksource_of_init();
271 void __init
r8a7790_init_early(void)
273 #ifndef CONFIG_ARM_ARCH_TIMER
274 shmobile_setup_delay(1300, 2, 4); /* Cortex-A15 @ 1300MHz */
280 static const char * const r8a7790_boards_compat_dt
[] __initconst
= {
285 DT_MACHINE_START(R8A7790_DT
, "Generic R8A7790 (Flattened Device Tree)")
286 .init_early
= r8a7790_init_early
,
287 .init_time
= r8a7790_timer_init
,
288 .dt_compat
= r8a7790_boards_compat_dt
,
290 #endif /* CONFIG_USE_OF */