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