Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 1 | /* |
| 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> |
| 22 | #include <linux/irqchip.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/of_platform.h> |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 25 | #include <linux/serial_sci.h> |
Laurent Pinchart | 43ca9cb | 2013-04-08 11:36:17 +0200 | [diff] [blame] | 26 | #include <linux/platform_data/gpio-rcar.h> |
Magnus Damm | 8f5ec0a | 2013-03-28 00:49:54 +0900 | [diff] [blame] | 27 | #include <linux/platform_data/irq-renesas-irqc.h> |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 28 | #include <mach/common.h> |
| 29 | #include <mach/irqs.h> |
| 30 | #include <mach/r8a7790.h> |
| 31 | #include <asm/mach/arch.h> |
| 32 | |
Magnus Damm | 69e351d | 2013-03-28 00:50:03 +0900 | [diff] [blame] | 33 | static const struct resource pfc_resources[] = { |
| 34 | DEFINE_RES_MEM(0xe6060000, 0x250), |
| 35 | }; |
| 36 | |
Laurent Pinchart | 43ca9cb | 2013-04-08 11:36:17 +0200 | [diff] [blame] | 37 | #define R8A7790_GPIO(idx) \ |
| 38 | static struct resource r8a7790_gpio##idx##_resources[] = { \ |
| 39 | DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \ |
| 40 | DEFINE_RES_IRQ(gic_spi(4 + (idx))), \ |
| 41 | }; \ |
| 42 | \ |
| 43 | static struct gpio_rcar_config r8a7790_gpio##idx##_platform_data = { \ |
| 44 | .gpio_base = 32 * (idx), \ |
| 45 | .irq_base = 0, \ |
| 46 | .number_of_pins = 32, \ |
| 47 | .pctl_name = "pfc-r8a7790", \ |
Simon Horman | d93906b8 | 2013-05-13 17:53:52 +0900 | [diff] [blame^] | 48 | .has_both_edge_trigger = 1, \ |
Laurent Pinchart | 43ca9cb | 2013-04-08 11:36:17 +0200 | [diff] [blame] | 49 | }; \ |
| 50 | |
| 51 | R8A7790_GPIO(0); |
| 52 | R8A7790_GPIO(1); |
| 53 | R8A7790_GPIO(2); |
| 54 | R8A7790_GPIO(3); |
| 55 | R8A7790_GPIO(4); |
| 56 | R8A7790_GPIO(5); |
| 57 | |
| 58 | #define r8a7790_register_gpio(idx) \ |
| 59 | platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \ |
| 60 | r8a7790_gpio##idx##_resources, \ |
| 61 | ARRAY_SIZE(r8a7790_gpio##idx##_resources), \ |
| 62 | &r8a7790_gpio##idx##_platform_data, \ |
| 63 | sizeof(r8a7790_gpio##idx##_platform_data)) |
| 64 | |
Magnus Damm | 69e351d | 2013-03-28 00:50:03 +0900 | [diff] [blame] | 65 | void __init r8a7790_pinmux_init(void) |
| 66 | { |
| 67 | platform_device_register_simple("pfc-r8a7790", -1, pfc_resources, |
| 68 | ARRAY_SIZE(pfc_resources)); |
Laurent Pinchart | 43ca9cb | 2013-04-08 11:36:17 +0200 | [diff] [blame] | 69 | r8a7790_register_gpio(0); |
| 70 | r8a7790_register_gpio(1); |
| 71 | r8a7790_register_gpio(2); |
| 72 | r8a7790_register_gpio(3); |
| 73 | r8a7790_register_gpio(4); |
| 74 | r8a7790_register_gpio(5); |
Magnus Damm | 69e351d | 2013-03-28 00:50:03 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 77 | #define SCIF_COMMON(scif_type, baseaddr, irq) \ |
| 78 | .type = scif_type, \ |
| 79 | .mapbase = baseaddr, \ |
| 80 | .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \ |
| 81 | .irqs = SCIx_IRQ_MUXED(irq) |
| 82 | |
| 83 | #define SCIFA_DATA(index, baseaddr, irq) \ |
| 84 | [index] = { \ |
| 85 | SCIF_COMMON(PORT_SCIFA, baseaddr, irq), \ |
| 86 | .scbrr_algo_id = SCBRR_ALGO_4, \ |
| 87 | .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \ |
| 88 | } |
| 89 | |
| 90 | #define SCIFB_DATA(index, baseaddr, irq) \ |
| 91 | [index] = { \ |
| 92 | SCIF_COMMON(PORT_SCIFB, baseaddr, irq), \ |
| 93 | .scbrr_algo_id = SCBRR_ALGO_4, \ |
| 94 | .scscr = SCSCR_RE | SCSCR_TE, \ |
| 95 | } |
| 96 | |
| 97 | #define SCIF_DATA(index, baseaddr, irq) \ |
| 98 | [index] = { \ |
| 99 | SCIF_COMMON(PORT_SCIF, baseaddr, irq), \ |
| 100 | .scbrr_algo_id = SCBRR_ALGO_2, \ |
| 101 | .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1, \ |
| 102 | } |
| 103 | |
| 104 | enum { SCIFA0, SCIFA1, SCIFB0, SCIFB1, SCIFB2, SCIFA2, SCIF0, SCIF1 }; |
| 105 | |
| 106 | static const struct plat_sci_port scif[] = { |
| 107 | SCIFA_DATA(SCIFA0, 0xe6c40000, gic_spi(144)), /* SCIFA0 */ |
| 108 | SCIFA_DATA(SCIFA1, 0xe6c50000, gic_spi(145)), /* SCIFA1 */ |
| 109 | SCIFB_DATA(SCIFB0, 0xe6c20000, gic_spi(148)), /* SCIFB0 */ |
| 110 | SCIFB_DATA(SCIFB1, 0xe6c30000, gic_spi(149)), /* SCIFB1 */ |
| 111 | SCIFB_DATA(SCIFB2, 0xe6ce0000, gic_spi(150)), /* SCIFB2 */ |
| 112 | SCIFA_DATA(SCIFA2, 0xe6c60000, gic_spi(151)), /* SCIFA2 */ |
| 113 | SCIF_DATA(SCIF0, 0xe6e60000, gic_spi(152)), /* SCIF0 */ |
| 114 | SCIF_DATA(SCIF1, 0xe6e68000, gic_spi(153)), /* SCIF1 */ |
| 115 | }; |
| 116 | |
| 117 | static inline void r8a7790_register_scif(int idx) |
| 118 | { |
| 119 | platform_device_register_data(&platform_bus, "sh-sci", idx, &scif[idx], |
| 120 | sizeof(struct plat_sci_port)); |
| 121 | } |
| 122 | |
Magnus Damm | 8f5ec0a | 2013-03-28 00:49:54 +0900 | [diff] [blame] | 123 | static struct renesas_irqc_config irqc0_data = { |
| 124 | .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */ |
| 125 | }; |
| 126 | |
| 127 | static struct resource irqc0_resources[] = { |
| 128 | DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */ |
| 129 | DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */ |
| 130 | DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */ |
| 131 | DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */ |
| 132 | DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */ |
| 133 | }; |
| 134 | |
| 135 | #define r8a7790_register_irqc(idx) \ |
| 136 | platform_device_register_resndata(&platform_bus, "renesas_irqc", \ |
| 137 | idx, irqc##idx##_resources, \ |
| 138 | ARRAY_SIZE(irqc##idx##_resources), \ |
| 139 | &irqc##idx##_data, \ |
| 140 | sizeof(struct renesas_irqc_config)) |
| 141 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 142 | void __init r8a7790_add_standard_devices(void) |
| 143 | { |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 144 | r8a7790_register_scif(SCIFA0); |
| 145 | r8a7790_register_scif(SCIFA1); |
| 146 | r8a7790_register_scif(SCIFB0); |
| 147 | r8a7790_register_scif(SCIFB1); |
| 148 | r8a7790_register_scif(SCIFB2); |
| 149 | r8a7790_register_scif(SCIFA2); |
| 150 | r8a7790_register_scif(SCIF0); |
| 151 | r8a7790_register_scif(SCIF1); |
Magnus Damm | 8f5ec0a | 2013-03-28 00:49:54 +0900 | [diff] [blame] | 152 | r8a7790_register_irqc(0); |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 153 | } |
| 154 | |
Magnus Damm | ab5fdfd | 2013-04-08 10:23:28 +0900 | [diff] [blame] | 155 | void __init r8a7790_timer_init(void) |
| 156 | { |
| 157 | void __iomem *cntcr; |
| 158 | |
| 159 | /* make sure arch timer is started by setting bit 0 of CNTCT */ |
| 160 | cntcr = ioremap(0xe6080000, PAGE_SIZE); |
| 161 | iowrite32(1, cntcr); |
| 162 | iounmap(cntcr); |
| 163 | |
| 164 | shmobile_timer_init(); |
| 165 | } |
| 166 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 167 | #ifdef CONFIG_USE_OF |
| 168 | void __init r8a7790_add_standard_devices_dt(void) |
| 169 | { |
| 170 | of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); |
| 171 | } |
| 172 | |
| 173 | static const char *r8a7790_boards_compat_dt[] __initdata = { |
| 174 | "renesas,r8a7790", |
| 175 | NULL, |
| 176 | }; |
| 177 | |
| 178 | DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)") |
| 179 | .init_irq = irqchip_init, |
| 180 | .init_machine = r8a7790_add_standard_devices_dt, |
Magnus Damm | ab5fdfd | 2013-04-08 10:23:28 +0900 | [diff] [blame] | 181 | .init_time = r8a7790_timer_init, |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 182 | .dt_compat = r8a7790_boards_compat_dt, |
| 183 | MACHINE_END |
| 184 | #endif /* CONFIG_USE_OF */ |