blob: 6625a386abaf489b5a325b20f4d099555a927ab8 [file] [log] [blame]
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -07001/*
2 * r8a7778 processor support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Sergei Shtylyov52421912013-04-04 18:55:46 +00006 * Copyright (C) 2013 Cogent Embedded, Inc.
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <linux/irqchip/arm-gic.h>
25#include <linux/of.h>
26#include <linux/of_platform.h>
Kuninori Morimoto3a42fa22013-04-01 21:19:37 -070027#include <linux/platform_data/irq-renesas-intc-irqpin.h>
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -070028#include <linux/platform_device.h>
29#include <linux/irqchip.h>
Kuninori Morimotodb331fc2013-03-21 03:02:38 -070030#include <linux/serial_sci.h>
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -070031#include <linux/sh_timer.h>
32#include <mach/irqs.h>
33#include <mach/r8a7778.h>
34#include <mach/common.h>
35#include <asm/mach/arch.h>
36#include <asm/hardware/cache-l2x0.h>
37
Kuninori Morimotodb331fc2013-03-21 03:02:38 -070038/* SCIF */
39#define SCIF_INFO(baseaddr, irq) \
40{ \
41 .mapbase = baseaddr, \
42 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
43 .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1, \
44 .scbrr_algo_id = SCBRR_ALGO_2, \
45 .type = PORT_SCIF, \
46 .irqs = SCIx_IRQ_MUXED(irq), \
47}
48
49static struct plat_sci_port scif_platform_data[] = {
50 SCIF_INFO(0xffe40000, gic_iid(0x66)),
51 SCIF_INFO(0xffe41000, gic_iid(0x67)),
52 SCIF_INFO(0xffe42000, gic_iid(0x68)),
53 SCIF_INFO(0xffe43000, gic_iid(0x69)),
54 SCIF_INFO(0xffe44000, gic_iid(0x6a)),
55 SCIF_INFO(0xffe45000, gic_iid(0x6b)),
56};
57
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -070058/* TMU */
59static struct resource sh_tmu0_resources[] = {
60 DEFINE_RES_MEM(0xffd80008, 12),
61 DEFINE_RES_IRQ(gic_iid(0x40)),
62};
63
64static struct sh_timer_config sh_tmu0_platform_data = {
65 .name = "TMU00",
66 .channel_offset = 0x4,
67 .timer_bit = 0,
68 .clockevent_rating = 200,
69};
70
71static struct resource sh_tmu1_resources[] = {
72 DEFINE_RES_MEM(0xffd80014, 12),
73 DEFINE_RES_IRQ(gic_iid(0x41)),
74};
75
76static struct sh_timer_config sh_tmu1_platform_data = {
77 .name = "TMU01",
78 .channel_offset = 0x10,
79 .timer_bit = 1,
80 .clocksource_rating = 200,
81};
82
Kuninori Morimoto81484482013-04-01 21:19:17 -070083#define r8a7778_register_tmu(idx) \
84 platform_device_register_resndata( \
85 &platform_bus, "sh_tmu", idx, \
86 sh_tmu##idx##_resources, \
87 ARRAY_SIZE(sh_tmu##idx##_resources), \
88 &sh_tmu##idx##_platform_data, \
89 sizeof(sh_tmu##idx##_platform_data))
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -070090
Kuninori Morimoto734e02f2013-04-08 22:33:44 -070091/* Ether */
92static struct resource ether_resources[] = {
93 DEFINE_RES_MEM(0xfde00000, 0x400),
94 DEFINE_RES_IRQ(gic_iid(0x89)),
95};
96
97void __init r8a7778_add_ether_device(struct sh_eth_plat_data *pdata)
98{
Sergei Shtylyovc02f8462013-06-09 01:23:24 +040099 platform_device_register_resndata(&platform_bus, "r8a777x-ether", -1,
Kuninori Morimoto734e02f2013-04-08 22:33:44 -0700100 ether_resources,
101 ARRAY_SIZE(ether_resources),
102 pdata, sizeof(*pdata));
103}
104
Kuninori Morimotodab58112013-04-16 22:17:25 -0700105/* SDHI */
106static struct resource sdhi_resources[] = {
107 /* SDHI0 */
108 DEFINE_RES_MEM(0xFFE4C000, 0x100),
109 DEFINE_RES_IRQ(gic_iid(0x77)),
110 /* SDHI1 */
111 DEFINE_RES_MEM(0xFFE4D000, 0x100),
112 DEFINE_RES_IRQ(gic_iid(0x78)),
113 /* SDHI2 */
114 DEFINE_RES_MEM(0xFFE4F000, 0x100),
115 DEFINE_RES_IRQ(gic_iid(0x76)),
116};
117
118void __init r8a7778_sdhi_init(int id,
119 struct sh_mobile_sdhi_info *info)
120{
121 BUG_ON(id < 0 || id > 2);
122
123 platform_device_register_resndata(
124 &platform_bus, "sh_mobile_sdhi", id,
125 sdhi_resources + (2 * id), 2,
126 info, sizeof(*info));
127}
128
Kuninori Morimoto46b9a092013-06-03 22:11:58 -0700129/* I2C */
130static struct resource i2c_resources[] __initdata = {
131 /* I2C0 */
132 DEFINE_RES_MEM(0xffc70000, 0x1000),
133 DEFINE_RES_IRQ(gic_iid(0x63)),
134 /* I2C1 */
135 DEFINE_RES_MEM(0xffc71000, 0x1000),
136 DEFINE_RES_IRQ(gic_iid(0x6e)),
137 /* I2C2 */
138 DEFINE_RES_MEM(0xffc72000, 0x1000),
139 DEFINE_RES_IRQ(gic_iid(0x6c)),
140 /* I2C3 */
141 DEFINE_RES_MEM(0xffc73000, 0x1000),
142 DEFINE_RES_IRQ(gic_iid(0x6d)),
143};
144
145void __init r8a7778_add_i2c_device(int id)
146{
147 BUG_ON(id < 0 || id > 3);
148
149 platform_device_register_simple(
150 "i2c-rcar", id,
151 i2c_resources + (2 * id), 2);
152}
153
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -0700154void __init r8a7778_add_standard_devices(void)
155{
156 int i;
157
158#ifdef CONFIG_CACHE_L2X0
159 void __iomem *base = ioremap_nocache(0xf0100000, 0x1000);
160 if (base) {
161 /*
162 * Early BRESP enable, Shared attribute override enable, 64K*16way
163 * don't call iounmap(base)
164 */
165 l2x0_init(base, 0x40470000, 0x82000fff);
166 }
167#endif
168
Kuninori Morimotodb331fc2013-03-21 03:02:38 -0700169 for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++)
170 platform_device_register_data(&platform_bus, "sh-sci", i,
171 &scif_platform_data[i],
172 sizeof(struct plat_sci_port));
173
Kuninori Morimoto81484482013-04-01 21:19:17 -0700174 r8a7778_register_tmu(0);
175 r8a7778_register_tmu(1);
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -0700176}
177
Kuninori Morimoto3a42fa22013-04-01 21:19:37 -0700178static struct renesas_intc_irqpin_config irqpin_platform_data = {
179 .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
180 .sense_bitfield_width = 2,
181};
182
183static struct resource irqpin_resources[] = {
184 DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
185 DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
186 DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
187 DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
188 DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
189 DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */
190 DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */
191 DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */
192 DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */
193};
194
195void __init r8a7778_init_irq_extpin(int irlm)
196{
197 void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
198 unsigned long tmp;
199
200 if (!icr0) {
201 pr_warn("r8a7778: unable to setup external irq pin mode\n");
202 return;
203 }
204
205 tmp = ioread32(icr0);
206 if (irlm)
207 tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
208 else
209 tmp &= ~(1 << 23); /* IRL mode - not supported */
210 tmp |= (1 << 21); /* LVLMODE = 1 */
211 iowrite32(tmp, icr0);
212 iounmap(icr0);
213
214 if (irlm)
215 platform_device_register_resndata(
216 &platform_bus, "renesas_intc_irqpin", -1,
217 irqpin_resources, ARRAY_SIZE(irqpin_resources),
218 &irqpin_platform_data, sizeof(irqpin_platform_data));
219}
220
Kuninori Morimotoccb7cc72013-03-21 03:01:36 -0700221#define INT2SMSKCR0 0x82288 /* 0xfe782288 */
222#define INT2SMSKCR1 0x8228c /* 0xfe78228c */
223
224#define INT2NTSR0 0x00018 /* 0xfe700018 */
225#define INT2NTSR1 0x0002c /* 0xfe70002c */
226static void __init r8a7778_init_irq_common(void)
227{
228 void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000);
229
230 BUG_ON(!base);
231
232 /* route all interrupts to ARM */
233 __raw_writel(0x73ffffff, base + INT2NTSR0);
234 __raw_writel(0xffffffff, base + INT2NTSR1);
235
236 /* unmask all known interrupts in INTCS2 */
237 __raw_writel(0x08330773, base + INT2SMSKCR0);
238 __raw_writel(0x00311110, base + INT2SMSKCR1);
239
240 iounmap(base);
241}
242
243void __init r8a7778_init_irq(void)
244{
245 void __iomem *gic_dist_base;
246 void __iomem *gic_cpu_base;
247
248 gic_dist_base = ioremap_nocache(0xfe438000, PAGE_SIZE);
249 gic_cpu_base = ioremap_nocache(0xfe430000, PAGE_SIZE);
250 BUG_ON(!gic_dist_base || !gic_cpu_base);
251
252 /* use GIC to handle interrupts */
253 gic_init(0, 29, gic_dist_base, gic_cpu_base);
254
255 r8a7778_init_irq_common();
256}
257
258void __init r8a7778_init_delay(void)
259{
260 shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
261}
262
263#ifdef CONFIG_USE_OF
264void __init r8a7778_init_irq_dt(void)
265{
266 irqchip_init();
267 r8a7778_init_irq_common();
268}
269
270static const struct of_dev_auxdata r8a7778_auxdata_lookup[] __initconst = {
271 {},
272};
273
274void __init r8a7778_add_standard_devices_dt(void)
275{
276 of_platform_populate(NULL, of_default_bus_match_table,
277 r8a7778_auxdata_lookup, NULL);
278}
279
280static const char *r8a7778_compat_dt[] __initdata = {
281 "renesas,r8a7778",
282 NULL,
283};
284
285DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
286 .init_early = r8a7778_init_delay,
287 .init_irq = r8a7778_init_irq_dt,
288 .init_machine = r8a7778_add_standard_devices_dt,
289 .init_time = shmobile_timer_init,
290 .dt_compat = r8a7778_compat_dt,
291MACHINE_END
292
293#endif /* CONFIG_USE_OF */