xref: /linux/arch/arm/mach-shmobile/setup-r8a73a4.c (revision 8826478e1125db9f05f902c5c7105ada164a8358)
1 /*
2  * r8a73a4 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 #include <linux/irq.h>
21 #include <linux/kernel.h>
22 #include <linux/of_platform.h>
23 #include <linux/platform_data/irq-renesas-irqc.h>
24 #include <linux/serial_sci.h>
25 #include <linux/sh_dma.h>
26 #include <linux/sh_timer.h>
27 #include <mach/common.h>
28 #include <mach/dma-register.h>
29 #include <mach/irqs.h>
30 #include <mach/r8a73a4.h>
31 #include <asm/mach/arch.h>
32 
33 static const struct resource pfc_resources[] = {
34 	DEFINE_RES_MEM(0xe6050000, 0x9000),
35 };
36 
37 void __init r8a73a4_pinmux_init(void)
38 {
39 	platform_device_register_simple("pfc-r8a73a4", -1, pfc_resources,
40 					ARRAY_SIZE(pfc_resources));
41 }
42 
43 #define R8A73A4_SCIF(scif_type, _scscr, index, baseaddr, irq)	\
44 static struct plat_sci_port scif##index##_platform_data = {	\
45 	.type		= scif_type,				\
46 	.flags		= UPF_BOOT_AUTOCONF | UPF_IOREMAP,	\
47 	.scbrr_algo_id	= SCBRR_ALGO_4,				\
48 	.scscr		= _scscr,				\
49 };								\
50 								\
51 static struct resource scif##index##_resources[] = {		\
52 	DEFINE_RES_MEM(baseaddr, 0x100),			\
53 	DEFINE_RES_IRQ(irq),					\
54 }
55 
56 #define R8A73A4_SCIFA(index, baseaddr, irq)	\
57 	R8A73A4_SCIF(PORT_SCIFA, SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
58 		     index, baseaddr, irq)
59 
60 #define R8A73A4_SCIFB(index, baseaddr, irq)	\
61 	R8A73A4_SCIF(PORT_SCIFB, SCSCR_RE | SCSCR_TE, \
62 		     index, baseaddr, irq)
63 
64 R8A73A4_SCIFA(0, 0xe6c40000, gic_spi(144)); /* SCIFA0 */
65 R8A73A4_SCIFA(1, 0xe6c50000, gic_spi(145)); /* SCIFA1 */
66 R8A73A4_SCIFB(2, 0xe6c20000, gic_spi(148)); /* SCIFB0 */
67 R8A73A4_SCIFB(3, 0xe6c30000, gic_spi(149)); /* SCIFB1 */
68 R8A73A4_SCIFB(4, 0xe6ce0000, gic_spi(150)); /* SCIFB2 */
69 R8A73A4_SCIFB(5, 0xe6cf0000, gic_spi(151)); /* SCIFB3 */
70 
71 #define r8a73a4_register_scif(index)					       \
72 	platform_device_register_resndata(&platform_bus, "sh-sci", index,      \
73 					  scif##index##_resources,	       \
74 					  ARRAY_SIZE(scif##index##_resources), \
75 					  &scif##index##_platform_data,	       \
76 					  sizeof(scif##index##_platform_data))
77 
78 static const struct renesas_irqc_config irqc0_data = {
79 	.irq_base = irq_pin(0), /* IRQ0 -> IRQ31 */
80 };
81 
82 static const struct resource irqc0_resources[] = {
83 	DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
84 	DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
85 	DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
86 	DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
87 	DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
88 	DEFINE_RES_IRQ(gic_spi(4)), /* IRQ4 */
89 	DEFINE_RES_IRQ(gic_spi(5)), /* IRQ5 */
90 	DEFINE_RES_IRQ(gic_spi(6)), /* IRQ6 */
91 	DEFINE_RES_IRQ(gic_spi(7)), /* IRQ7 */
92 	DEFINE_RES_IRQ(gic_spi(8)), /* IRQ8 */
93 	DEFINE_RES_IRQ(gic_spi(9)), /* IRQ9 */
94 	DEFINE_RES_IRQ(gic_spi(10)), /* IRQ10 */
95 	DEFINE_RES_IRQ(gic_spi(11)), /* IRQ11 */
96 	DEFINE_RES_IRQ(gic_spi(12)), /* IRQ12 */
97 	DEFINE_RES_IRQ(gic_spi(13)), /* IRQ13 */
98 	DEFINE_RES_IRQ(gic_spi(14)), /* IRQ14 */
99 	DEFINE_RES_IRQ(gic_spi(15)), /* IRQ15 */
100 	DEFINE_RES_IRQ(gic_spi(16)), /* IRQ16 */
101 	DEFINE_RES_IRQ(gic_spi(17)), /* IRQ17 */
102 	DEFINE_RES_IRQ(gic_spi(18)), /* IRQ18 */
103 	DEFINE_RES_IRQ(gic_spi(19)), /* IRQ19 */
104 	DEFINE_RES_IRQ(gic_spi(20)), /* IRQ20 */
105 	DEFINE_RES_IRQ(gic_spi(21)), /* IRQ21 */
106 	DEFINE_RES_IRQ(gic_spi(22)), /* IRQ22 */
107 	DEFINE_RES_IRQ(gic_spi(23)), /* IRQ23 */
108 	DEFINE_RES_IRQ(gic_spi(24)), /* IRQ24 */
109 	DEFINE_RES_IRQ(gic_spi(25)), /* IRQ25 */
110 	DEFINE_RES_IRQ(gic_spi(26)), /* IRQ26 */
111 	DEFINE_RES_IRQ(gic_spi(27)), /* IRQ27 */
112 	DEFINE_RES_IRQ(gic_spi(28)), /* IRQ28 */
113 	DEFINE_RES_IRQ(gic_spi(29)), /* IRQ29 */
114 	DEFINE_RES_IRQ(gic_spi(30)), /* IRQ30 */
115 	DEFINE_RES_IRQ(gic_spi(31)), /* IRQ31 */
116 };
117 
118 static const struct renesas_irqc_config irqc1_data = {
119 	.irq_base = irq_pin(32), /* IRQ32 -> IRQ57 */
120 };
121 
122 static const struct resource irqc1_resources[] = {
123 	DEFINE_RES_MEM(0xe61c0200, 0x200), /* IRQC Event Detector Block_1 */
124 	DEFINE_RES_IRQ(gic_spi(32)), /* IRQ32 */
125 	DEFINE_RES_IRQ(gic_spi(33)), /* IRQ33 */
126 	DEFINE_RES_IRQ(gic_spi(34)), /* IRQ34 */
127 	DEFINE_RES_IRQ(gic_spi(35)), /* IRQ35 */
128 	DEFINE_RES_IRQ(gic_spi(36)), /* IRQ36 */
129 	DEFINE_RES_IRQ(gic_spi(37)), /* IRQ37 */
130 	DEFINE_RES_IRQ(gic_spi(38)), /* IRQ38 */
131 	DEFINE_RES_IRQ(gic_spi(39)), /* IRQ39 */
132 	DEFINE_RES_IRQ(gic_spi(40)), /* IRQ40 */
133 	DEFINE_RES_IRQ(gic_spi(41)), /* IRQ41 */
134 	DEFINE_RES_IRQ(gic_spi(42)), /* IRQ42 */
135 	DEFINE_RES_IRQ(gic_spi(43)), /* IRQ43 */
136 	DEFINE_RES_IRQ(gic_spi(44)), /* IRQ44 */
137 	DEFINE_RES_IRQ(gic_spi(45)), /* IRQ45 */
138 	DEFINE_RES_IRQ(gic_spi(46)), /* IRQ46 */
139 	DEFINE_RES_IRQ(gic_spi(47)), /* IRQ47 */
140 	DEFINE_RES_IRQ(gic_spi(48)), /* IRQ48 */
141 	DEFINE_RES_IRQ(gic_spi(49)), /* IRQ49 */
142 	DEFINE_RES_IRQ(gic_spi(50)), /* IRQ50 */
143 	DEFINE_RES_IRQ(gic_spi(51)), /* IRQ51 */
144 	DEFINE_RES_IRQ(gic_spi(52)), /* IRQ52 */
145 	DEFINE_RES_IRQ(gic_spi(53)), /* IRQ53 */
146 	DEFINE_RES_IRQ(gic_spi(54)), /* IRQ54 */
147 	DEFINE_RES_IRQ(gic_spi(55)), /* IRQ55 */
148 	DEFINE_RES_IRQ(gic_spi(56)), /* IRQ56 */
149 	DEFINE_RES_IRQ(gic_spi(57)), /* IRQ57 */
150 };
151 
152 #define r8a73a4_register_irqc(idx)					\
153 	platform_device_register_resndata(&platform_bus, "renesas_irqc", \
154 					  idx, irqc##idx##_resources,	\
155 					  ARRAY_SIZE(irqc##idx##_resources), \
156 					  &irqc##idx##_data,		\
157 					  sizeof(struct renesas_irqc_config))
158 
159 /* Thermal0 -> Thermal2 */
160 static const struct resource thermal0_resources[] = {
161 	DEFINE_RES_MEM(0xe61f0000, 0x14),
162 	DEFINE_RES_MEM(0xe61f0100, 0x38),
163 	DEFINE_RES_MEM(0xe61f0200, 0x38),
164 	DEFINE_RES_MEM(0xe61f0300, 0x38),
165 	DEFINE_RES_IRQ(gic_spi(69)),
166 };
167 
168 #define r8a73a4_register_thermal()					\
169 	platform_device_register_simple("rcar_thermal", -1,		\
170 					thermal0_resources,		\
171 					ARRAY_SIZE(thermal0_resources))
172 
173 static struct sh_timer_config cmt10_platform_data = {
174 	.name = "CMT10",
175 	.timer_bit = 0,
176 	.clockevent_rating = 80,
177 };
178 
179 static struct resource cmt10_resources[] = {
180 	DEFINE_RES_MEM(0xe6130010, 0x0c),
181 	DEFINE_RES_MEM(0xe6130000, 0x04),
182 	DEFINE_RES_IRQ(gic_spi(120)), /* CMT1_0 */
183 };
184 
185 #define r8a7790_register_cmt(idx)					\
186 	platform_device_register_resndata(&platform_bus, "sh_cmt",	\
187 					  idx, cmt##idx##_resources,	\
188 					  ARRAY_SIZE(cmt##idx##_resources), \
189 					  &cmt##idx##_platform_data,	\
190 					  sizeof(struct sh_timer_config))
191 
192 void __init r8a73a4_add_dt_devices(void)
193 {
194 	r8a73a4_register_scif(0);
195 	r8a73a4_register_scif(1);
196 	r8a73a4_register_scif(2);
197 	r8a73a4_register_scif(3);
198 	r8a73a4_register_scif(4);
199 	r8a73a4_register_scif(5);
200 	r8a7790_register_cmt(10);
201 }
202 
203 /* DMA */
204 static const struct sh_dmae_slave_config dma_slaves[] = {
205 	{
206 		.slave_id	= SHDMA_SLAVE_MMCIF0_TX,
207 		.addr		= 0xee200034,
208 		.chcr		= CHCR_TX(XMIT_SZ_32BIT),
209 		.mid_rid	= 0xd1,
210 	}, {
211 		.slave_id	= SHDMA_SLAVE_MMCIF0_RX,
212 		.addr		= 0xee200034,
213 		.chcr		= CHCR_RX(XMIT_SZ_32BIT),
214 		.mid_rid	= 0xd2,
215 	}, {
216 		.slave_id	= SHDMA_SLAVE_MMCIF1_TX,
217 		.addr		= 0xee220034,
218 		.chcr		= CHCR_TX(XMIT_SZ_32BIT),
219 		.mid_rid	= 0xe1,
220 	}, {
221 		.slave_id	= SHDMA_SLAVE_MMCIF1_RX,
222 		.addr		= 0xee220034,
223 		.chcr		= CHCR_RX(XMIT_SZ_32BIT),
224 		.mid_rid	= 0xe2,
225 	},
226 };
227 
228 #define DMAE_CHANNEL(a, b)				\
229 	{						\
230 		.offset         = (a) - 0x20,		\
231 		.dmars          = (a) - 0x20 + 0x40,	\
232 		.chclr_bit	= (b),			\
233 		.chclr_offset	= 0x80 - 0x20,		\
234 	}
235 
236 static const struct sh_dmae_channel dma_channels[] = {
237 	DMAE_CHANNEL(0x8000, 0),
238 	DMAE_CHANNEL(0x8080, 1),
239 	DMAE_CHANNEL(0x8100, 2),
240 	DMAE_CHANNEL(0x8180, 3),
241 	DMAE_CHANNEL(0x8200, 4),
242 	DMAE_CHANNEL(0x8280, 5),
243 	DMAE_CHANNEL(0x8300, 6),
244 	DMAE_CHANNEL(0x8380, 7),
245 	DMAE_CHANNEL(0x8400, 8),
246 	DMAE_CHANNEL(0x8480, 9),
247 	DMAE_CHANNEL(0x8500, 10),
248 	DMAE_CHANNEL(0x8580, 11),
249 	DMAE_CHANNEL(0x8600, 12),
250 	DMAE_CHANNEL(0x8680, 13),
251 	DMAE_CHANNEL(0x8700, 14),
252 	DMAE_CHANNEL(0x8780, 15),
253 	DMAE_CHANNEL(0x8800, 16),
254 	DMAE_CHANNEL(0x8880, 17),
255 	DMAE_CHANNEL(0x8900, 18),
256 	DMAE_CHANNEL(0x8980, 19),
257 };
258 
259 static const struct sh_dmae_pdata dma_pdata = {
260 	.slave		= dma_slaves,
261 	.slave_num	= ARRAY_SIZE(dma_slaves),
262 	.channel	= dma_channels,
263 	.channel_num	= ARRAY_SIZE(dma_channels),
264 	.ts_low_shift	= TS_LOW_SHIFT,
265 	.ts_low_mask	= TS_LOW_BIT << TS_LOW_SHIFT,
266 	.ts_high_shift	= TS_HI_SHIFT,
267 	.ts_high_mask	= TS_HI_BIT << TS_HI_SHIFT,
268 	.ts_shift	= dma_ts_shift,
269 	.ts_shift_num	= ARRAY_SIZE(dma_ts_shift),
270 	.dmaor_init     = DMAOR_DME,
271 	.chclr_present	= 1,
272 	.chclr_bitwise	= 1,
273 };
274 
275 static struct resource dma_resources[] = {
276 	DEFINE_RES_MEM(0xe6700020, 0x89e0),
277 	DEFINE_RES_IRQ(gic_spi(220)),
278 	{
279 		/* IRQ for channels 0-19 */
280 		.start  = gic_spi(200),
281 		.end    = gic_spi(219),
282 		.flags  = IORESOURCE_IRQ,
283 	},
284 };
285 
286 #define r8a73a4_register_dmac()							\
287 	platform_device_register_resndata(&platform_bus, "sh-dma-engine", 0,	\
288 				dma_resources, ARRAY_SIZE(dma_resources),	\
289 				&dma_pdata, sizeof(dma_pdata))
290 
291 void __init r8a73a4_add_standard_devices(void)
292 {
293 	r8a73a4_add_dt_devices();
294 	r8a73a4_register_irqc(0);
295 	r8a73a4_register_irqc(1);
296 	r8a73a4_register_thermal();
297 	r8a73a4_register_dmac();
298 }
299 
300 void __init r8a73a4_init_early(void)
301 {
302 #ifndef CONFIG_ARM_ARCH_TIMER
303 	shmobile_setup_delay(1500, 2, 4); /* Cortex-A15 @ 1500MHz */
304 #endif
305 }
306 
307 #ifdef CONFIG_USE_OF
308 
309 static const char *r8a73a4_boards_compat_dt[] __initdata = {
310 	"renesas,r8a73a4",
311 	NULL,
312 };
313 
314 DT_MACHINE_START(R8A73A4_DT, "Generic R8A73A4 (Flattened Device Tree)")
315 	.init_early	= r8a73a4_init_early,
316 	.dt_compat	= r8a73a4_boards_compat_dt,
317 MACHINE_END
318 #endif /* CONFIG_USE_OF */
319