Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * r8a7778 processor support |
| 3 | * |
| 4 | * Copyright (C) 2013 Renesas Solutions Corp. |
| 5 | * Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
Sergei Shtylyov | 5242191 | 2013-04-04 18:55:46 +0000 | [diff] [blame] | 6 | * Copyright (C) 2013 Cogent Embedded, Inc. |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 7 | * |
| 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 Morimoto | 3a42fa2 | 2013-04-01 21:19:37 -0700 | [diff] [blame] | 27 | #include <linux/platform_data/irq-renesas-intc-irqpin.h> |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/irqchip.h> |
Kuninori Morimoto | db331fc | 2013-03-21 03:02:38 -0700 | [diff] [blame] | 30 | #include <linux/serial_sci.h> |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 31 | #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 Morimoto | db331fc | 2013-03-21 03:02:38 -0700 | [diff] [blame] | 38 | /* 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 | |
| 49 | static 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 Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 58 | /* TMU */ |
| 59 | static struct resource sh_tmu0_resources[] = { |
| 60 | DEFINE_RES_MEM(0xffd80008, 12), |
| 61 | DEFINE_RES_IRQ(gic_iid(0x40)), |
| 62 | }; |
| 63 | |
| 64 | static 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 | |
| 71 | static struct resource sh_tmu1_resources[] = { |
| 72 | DEFINE_RES_MEM(0xffd80014, 12), |
| 73 | DEFINE_RES_IRQ(gic_iid(0x41)), |
| 74 | }; |
| 75 | |
| 76 | static 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 | |
Sergei Shtylyov | 5242191 | 2013-04-04 18:55:46 +0000 | [diff] [blame] | 83 | /* Ether */ |
| 84 | static struct resource ether_resources[] = { |
| 85 | DEFINE_RES_MEM(0xfde00000, 0x400), |
| 86 | DEFINE_RES_IRQ(gic_iid(0x89)), |
| 87 | }; |
| 88 | |
Kuninori Morimoto | 8148448 | 2013-04-01 21:19:17 -0700 | [diff] [blame] | 89 | #define r8a7778_register_tmu(idx) \ |
| 90 | platform_device_register_resndata( \ |
| 91 | &platform_bus, "sh_tmu", idx, \ |
| 92 | sh_tmu##idx##_resources, \ |
| 93 | ARRAY_SIZE(sh_tmu##idx##_resources), \ |
| 94 | &sh_tmu##idx##_platform_data, \ |
| 95 | sizeof(sh_tmu##idx##_platform_data)) |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 96 | |
Kuninori Morimoto | 369b00b | 2013-04-12 05:37:50 +0000 | [diff] [blame^] | 97 | /* PFC */ |
| 98 | static struct resource pfc_resources[] = { |
| 99 | DEFINE_RES_MEM(0xfffc0000, 0x118), |
| 100 | }; |
| 101 | |
| 102 | void __init r8a7778_pinmux_init(void) |
| 103 | { |
| 104 | platform_device_register_simple( |
| 105 | "pfc-r8a7778", -1, |
| 106 | pfc_resources, |
| 107 | ARRAY_SIZE(pfc_resources)); |
| 108 | } |
| 109 | |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 110 | void __init r8a7778_add_standard_devices(void) |
| 111 | { |
| 112 | int i; |
| 113 | |
| 114 | #ifdef CONFIG_CACHE_L2X0 |
| 115 | void __iomem *base = ioremap_nocache(0xf0100000, 0x1000); |
| 116 | if (base) { |
| 117 | /* |
| 118 | * Early BRESP enable, Shared attribute override enable, 64K*16way |
| 119 | * don't call iounmap(base) |
| 120 | */ |
| 121 | l2x0_init(base, 0x40470000, 0x82000fff); |
| 122 | } |
| 123 | #endif |
| 124 | |
Kuninori Morimoto | db331fc | 2013-03-21 03:02:38 -0700 | [diff] [blame] | 125 | for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++) |
| 126 | platform_device_register_data(&platform_bus, "sh-sci", i, |
| 127 | &scif_platform_data[i], |
| 128 | sizeof(struct plat_sci_port)); |
| 129 | |
Kuninori Morimoto | 8148448 | 2013-04-01 21:19:17 -0700 | [diff] [blame] | 130 | r8a7778_register_tmu(0); |
| 131 | r8a7778_register_tmu(1); |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Sergei Shtylyov | 5242191 | 2013-04-04 18:55:46 +0000 | [diff] [blame] | 134 | void __init r8a7778_add_ether_device(struct sh_eth_plat_data *pdata) |
| 135 | { |
| 136 | platform_device_register_resndata(&platform_bus, "sh_eth", -1, |
| 137 | ether_resources, |
| 138 | ARRAY_SIZE(ether_resources), |
| 139 | pdata, sizeof(*pdata)); |
| 140 | } |
| 141 | |
Kuninori Morimoto | 3a42fa2 | 2013-04-01 21:19:37 -0700 | [diff] [blame] | 142 | static struct renesas_intc_irqpin_config irqpin_platform_data = { |
| 143 | .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */ |
| 144 | .sense_bitfield_width = 2, |
| 145 | }; |
| 146 | |
| 147 | static struct resource irqpin_resources[] = { |
| 148 | DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */ |
| 149 | DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */ |
| 150 | DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */ |
| 151 | DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */ |
| 152 | DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */ |
| 153 | DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */ |
| 154 | DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */ |
| 155 | DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */ |
| 156 | DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */ |
| 157 | }; |
| 158 | |
| 159 | void __init r8a7778_init_irq_extpin(int irlm) |
| 160 | { |
| 161 | void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE); |
| 162 | unsigned long tmp; |
| 163 | |
| 164 | if (!icr0) { |
| 165 | pr_warn("r8a7778: unable to setup external irq pin mode\n"); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | tmp = ioread32(icr0); |
| 170 | if (irlm) |
| 171 | tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */ |
| 172 | else |
| 173 | tmp &= ~(1 << 23); /* IRL mode - not supported */ |
| 174 | tmp |= (1 << 21); /* LVLMODE = 1 */ |
| 175 | iowrite32(tmp, icr0); |
| 176 | iounmap(icr0); |
| 177 | |
| 178 | if (irlm) |
| 179 | platform_device_register_resndata( |
| 180 | &platform_bus, "renesas_intc_irqpin", -1, |
| 181 | irqpin_resources, ARRAY_SIZE(irqpin_resources), |
| 182 | &irqpin_platform_data, sizeof(irqpin_platform_data)); |
| 183 | } |
| 184 | |
Kuninori Morimoto | ccb7cc7 | 2013-03-21 03:01:36 -0700 | [diff] [blame] | 185 | #define INT2SMSKCR0 0x82288 /* 0xfe782288 */ |
| 186 | #define INT2SMSKCR1 0x8228c /* 0xfe78228c */ |
| 187 | |
| 188 | #define INT2NTSR0 0x00018 /* 0xfe700018 */ |
| 189 | #define INT2NTSR1 0x0002c /* 0xfe70002c */ |
| 190 | static void __init r8a7778_init_irq_common(void) |
| 191 | { |
| 192 | void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000); |
| 193 | |
| 194 | BUG_ON(!base); |
| 195 | |
| 196 | /* route all interrupts to ARM */ |
| 197 | __raw_writel(0x73ffffff, base + INT2NTSR0); |
| 198 | __raw_writel(0xffffffff, base + INT2NTSR1); |
| 199 | |
| 200 | /* unmask all known interrupts in INTCS2 */ |
| 201 | __raw_writel(0x08330773, base + INT2SMSKCR0); |
| 202 | __raw_writel(0x00311110, base + INT2SMSKCR1); |
| 203 | |
| 204 | iounmap(base); |
| 205 | } |
| 206 | |
| 207 | void __init r8a7778_init_irq(void) |
| 208 | { |
| 209 | void __iomem *gic_dist_base; |
| 210 | void __iomem *gic_cpu_base; |
| 211 | |
| 212 | gic_dist_base = ioremap_nocache(0xfe438000, PAGE_SIZE); |
| 213 | gic_cpu_base = ioremap_nocache(0xfe430000, PAGE_SIZE); |
| 214 | BUG_ON(!gic_dist_base || !gic_cpu_base); |
| 215 | |
| 216 | /* use GIC to handle interrupts */ |
| 217 | gic_init(0, 29, gic_dist_base, gic_cpu_base); |
| 218 | |
| 219 | r8a7778_init_irq_common(); |
| 220 | } |
| 221 | |
| 222 | void __init r8a7778_init_delay(void) |
| 223 | { |
| 224 | shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */ |
| 225 | } |
| 226 | |
| 227 | #ifdef CONFIG_USE_OF |
| 228 | void __init r8a7778_init_irq_dt(void) |
| 229 | { |
| 230 | irqchip_init(); |
| 231 | r8a7778_init_irq_common(); |
| 232 | } |
| 233 | |
| 234 | static const struct of_dev_auxdata r8a7778_auxdata_lookup[] __initconst = { |
| 235 | {}, |
| 236 | }; |
| 237 | |
| 238 | void __init r8a7778_add_standard_devices_dt(void) |
| 239 | { |
| 240 | of_platform_populate(NULL, of_default_bus_match_table, |
| 241 | r8a7778_auxdata_lookup, NULL); |
| 242 | } |
| 243 | |
| 244 | static const char *r8a7778_compat_dt[] __initdata = { |
| 245 | "renesas,r8a7778", |
| 246 | NULL, |
| 247 | }; |
| 248 | |
| 249 | DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)") |
| 250 | .init_early = r8a7778_init_delay, |
| 251 | .init_irq = r8a7778_init_irq_dt, |
| 252 | .init_machine = r8a7778_add_standard_devices_dt, |
| 253 | .init_time = shmobile_timer_init, |
| 254 | .dt_compat = r8a7778_compat_dt, |
| 255 | MACHINE_END |
| 256 | |
| 257 | #endif /* CONFIG_USE_OF */ |