Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 1 | /* |
| 2 | * marzen board support |
| 3 | * |
| 4 | * Copyright (C) 2011 Renesas Solutions Corp. |
| 5 | * Copyright (C) 2011 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/kernel.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/irq.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/io.h> |
Magnus Damm | 14f691c | 2011-12-14 01:36:42 +0900 | [diff] [blame] | 28 | #include <linux/gpio.h> |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
Guennadi Liakhovetski | b354e22 | 2012-06-27 00:32:32 +0200 | [diff] [blame] | 30 | #include <linux/regulator/fixed.h> |
| 31 | #include <linux/regulator/machine.h> |
Magnus Damm | db5eb99 | 2011-12-14 01:36:51 +0900 | [diff] [blame] | 32 | #include <linux/smsc911x.h> |
Kuninori Morimoto | b82573e | 2012-10-10 19:57:02 -0700 | [diff] [blame] | 33 | #include <linux/spi/spi.h> |
| 34 | #include <linux/spi/sh_hspi.h> |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 35 | #include <linux/mmc/sh_mobile_sdhi.h> |
| 36 | #include <linux/mfd/tmio.h> |
Kuninori Morimoto | 94e1f7f | 2012-10-29 01:15:34 -0700 | [diff] [blame^] | 37 | #include <linux/usb/otg.h> |
| 38 | #include <linux/usb/ehci_pdriver.h> |
| 39 | #include <linux/pm_runtime.h> |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 40 | #include <mach/hardware.h> |
| 41 | #include <mach/r8a7779.h> |
| 42 | #include <mach/common.h> |
Rob Herring | 250a272 | 2012-01-03 16:57:33 -0600 | [diff] [blame] | 43 | #include <mach/irqs.h> |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 44 | #include <asm/mach-types.h> |
| 45 | #include <asm/mach/arch.h> |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 46 | #include <asm/hardware/gic.h> |
| 47 | #include <asm/traps.h> |
| 48 | |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 49 | /* Fixed 3.3V regulator to be used by SDHI0 */ |
| 50 | static struct regulator_consumer_supply fixed3v3_power_consumers[] = { |
| 51 | REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"), |
| 52 | REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"), |
| 53 | }; |
| 54 | |
Guennadi Liakhovetski | b354e22 | 2012-06-27 00:32:32 +0200 | [diff] [blame] | 55 | /* Dummy supplies, where voltage doesn't matter */ |
| 56 | static struct regulator_consumer_supply dummy_supplies[] = { |
| 57 | REGULATOR_SUPPLY("vddvario", "smsc911x"), |
| 58 | REGULATOR_SUPPLY("vdd33a", "smsc911x"), |
| 59 | }; |
| 60 | |
Magnus Damm | db5eb99 | 2011-12-14 01:36:51 +0900 | [diff] [blame] | 61 | /* SMSC LAN89218 */ |
| 62 | static struct resource smsc911x_resources[] = { |
| 63 | [0] = { |
| 64 | .start = 0x18000000, /* ExCS0 */ |
| 65 | .end = 0x180000ff, /* A1->A7 */ |
| 66 | .flags = IORESOURCE_MEM, |
| 67 | }, |
| 68 | [1] = { |
| 69 | .start = gic_spi(28), /* IRQ 1 */ |
| 70 | .flags = IORESOURCE_IRQ, |
| 71 | }, |
| 72 | }; |
| 73 | |
| 74 | static struct smsc911x_platform_config smsc911x_platdata = { |
| 75 | .flags = SMSC911X_USE_32BIT, /* 32-bit SW on 16-bit HW bus */ |
| 76 | .phy_interface = PHY_INTERFACE_MODE_MII, |
| 77 | .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW, |
| 78 | .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL, |
| 79 | }; |
| 80 | |
| 81 | static struct platform_device eth_device = { |
| 82 | .name = "smsc911x", |
Kuninori Morimoto | 497dcf6 | 2012-08-29 18:58:01 -0700 | [diff] [blame] | 83 | .id = -1, |
Magnus Damm | db5eb99 | 2011-12-14 01:36:51 +0900 | [diff] [blame] | 84 | .dev = { |
| 85 | .platform_data = &smsc911x_platdata, |
| 86 | }, |
| 87 | .resource = smsc911x_resources, |
| 88 | .num_resources = ARRAY_SIZE(smsc911x_resources), |
| 89 | }; |
| 90 | |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 91 | static struct resource sdhi0_resources[] = { |
| 92 | [0] = { |
| 93 | .name = "sdhi0", |
| 94 | .start = 0xffe4c000, |
| 95 | .end = 0xffe4c0ff, |
| 96 | .flags = IORESOURCE_MEM, |
| 97 | }, |
| 98 | [1] = { |
| 99 | .start = gic_spi(104), |
| 100 | .flags = IORESOURCE_IRQ, |
| 101 | }, |
| 102 | }; |
| 103 | |
| 104 | static struct sh_mobile_sdhi_info sdhi0_platform_data = { |
| 105 | .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT, |
| 106 | .tmio_caps = MMC_CAP_SD_HIGHSPEED, |
| 107 | }; |
| 108 | |
| 109 | static struct platform_device sdhi0_device = { |
| 110 | .name = "sh_mobile_sdhi", |
| 111 | .num_resources = ARRAY_SIZE(sdhi0_resources), |
| 112 | .resource = sdhi0_resources, |
| 113 | .id = 0, |
| 114 | .dev = { |
| 115 | .platform_data = &sdhi0_platform_data, |
| 116 | } |
| 117 | }; |
| 118 | |
Kuninori Morimoto | eb8ca94 | 2012-08-27 19:00:15 -0700 | [diff] [blame] | 119 | /* Thermal */ |
| 120 | static struct resource thermal_resources[] = { |
| 121 | [0] = { |
| 122 | .start = 0xFFC48000, |
| 123 | .end = 0xFFC48038 - 1, |
| 124 | .flags = IORESOURCE_MEM, |
| 125 | }, |
| 126 | }; |
| 127 | |
| 128 | static struct platform_device thermal_device = { |
| 129 | .name = "rcar_thermal", |
| 130 | .resource = thermal_resources, |
| 131 | .num_resources = ARRAY_SIZE(thermal_resources), |
| 132 | }; |
| 133 | |
Kuninori Morimoto | b82573e | 2012-10-10 19:57:02 -0700 | [diff] [blame] | 134 | /* HSPI */ |
| 135 | static struct resource hspi_resources[] = { |
| 136 | [0] = { |
| 137 | .start = 0xFFFC7000, |
| 138 | .end = 0xFFFC7018 - 1, |
| 139 | .flags = IORESOURCE_MEM, |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | static struct platform_device hspi_device = { |
| 144 | .name = "sh-hspi", |
| 145 | .id = 0, |
| 146 | .resource = hspi_resources, |
| 147 | .num_resources = ARRAY_SIZE(hspi_resources), |
| 148 | }; |
| 149 | |
Kuninori Morimoto | b5ce635 | 2012-10-29 01:15:25 -0700 | [diff] [blame] | 150 | /* USB PHY */ |
| 151 | static struct resource usb_phy_resources[] = { |
| 152 | [0] = { |
| 153 | .start = 0xffe70000, |
| 154 | .end = 0xffe70900 - 1, |
| 155 | .flags = IORESOURCE_MEM, |
| 156 | }, |
| 157 | [1] = { |
| 158 | .start = 0xfff70000, |
| 159 | .end = 0xfff70900 - 1, |
| 160 | .flags = IORESOURCE_MEM, |
| 161 | }, |
| 162 | }; |
| 163 | |
| 164 | static struct platform_device usb_phy_device = { |
| 165 | .name = "rcar_usb_phy", |
| 166 | .resource = usb_phy_resources, |
| 167 | .num_resources = ARRAY_SIZE(usb_phy_resources), |
| 168 | }; |
| 169 | |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 170 | static struct platform_device *marzen_devices[] __initdata = { |
Magnus Damm | db5eb99 | 2011-12-14 01:36:51 +0900 | [diff] [blame] | 171 | ð_device, |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 172 | &sdhi0_device, |
Kuninori Morimoto | eb8ca94 | 2012-08-27 19:00:15 -0700 | [diff] [blame] | 173 | &thermal_device, |
Kuninori Morimoto | b82573e | 2012-10-10 19:57:02 -0700 | [diff] [blame] | 174 | &hspi_device, |
Kuninori Morimoto | b5ce635 | 2012-10-29 01:15:25 -0700 | [diff] [blame] | 175 | &usb_phy_device, |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 176 | }; |
| 177 | |
Kuninori Morimoto | 94e1f7f | 2012-10-29 01:15:34 -0700 | [diff] [blame^] | 178 | /* USB */ |
| 179 | static struct usb_phy *phy; |
| 180 | static int usb_power_on(struct platform_device *pdev) |
| 181 | { |
| 182 | if (!phy) |
| 183 | return -EIO; |
| 184 | |
| 185 | pm_runtime_enable(&pdev->dev); |
| 186 | pm_runtime_get_sync(&pdev->dev); |
| 187 | |
| 188 | usb_phy_init(phy); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static void usb_power_off(struct platform_device *pdev) |
| 194 | { |
| 195 | if (!phy) |
| 196 | return; |
| 197 | |
| 198 | usb_phy_shutdown(phy); |
| 199 | |
| 200 | pm_runtime_put_sync(&pdev->dev); |
| 201 | pm_runtime_disable(&pdev->dev); |
| 202 | } |
| 203 | |
| 204 | static struct usb_ehci_pdata ehcix_pdata = { |
| 205 | .power_on = usb_power_on, |
| 206 | .power_off = usb_power_off, |
| 207 | .power_suspend = usb_power_off, |
| 208 | }; |
| 209 | |
| 210 | static struct resource ehci0_resources[] = { |
| 211 | [0] = { |
| 212 | .start = 0xffe70000, |
| 213 | .end = 0xffe70400 - 1, |
| 214 | .flags = IORESOURCE_MEM, |
| 215 | }, |
| 216 | [1] = { |
| 217 | .start = gic_spi(44), |
| 218 | .flags = IORESOURCE_IRQ, |
| 219 | }, |
| 220 | }; |
| 221 | |
| 222 | static struct platform_device ehci0_device = { |
| 223 | .name = "ehci-platform", |
| 224 | .id = 0, |
| 225 | .dev = { |
| 226 | .dma_mask = &ehci0_device.dev.coherent_dma_mask, |
| 227 | .coherent_dma_mask = 0xffffffff, |
| 228 | .platform_data = &ehcix_pdata, |
| 229 | }, |
| 230 | .num_resources = ARRAY_SIZE(ehci0_resources), |
| 231 | .resource = ehci0_resources, |
| 232 | }; |
| 233 | |
| 234 | static struct resource ehci1_resources[] = { |
| 235 | [0] = { |
| 236 | .start = 0xfff70000, |
| 237 | .end = 0xfff70400 - 1, |
| 238 | .flags = IORESOURCE_MEM, |
| 239 | }, |
| 240 | [1] = { |
| 241 | .start = gic_spi(45), |
| 242 | .flags = IORESOURCE_IRQ, |
| 243 | }, |
| 244 | }; |
| 245 | |
| 246 | static struct platform_device ehci1_device = { |
| 247 | .name = "ehci-platform", |
| 248 | .id = 1, |
| 249 | .dev = { |
| 250 | .dma_mask = &ehci1_device.dev.coherent_dma_mask, |
| 251 | .coherent_dma_mask = 0xffffffff, |
| 252 | .platform_data = &ehcix_pdata, |
| 253 | }, |
| 254 | .num_resources = ARRAY_SIZE(ehci1_resources), |
| 255 | .resource = ehci1_resources, |
| 256 | }; |
| 257 | |
| 258 | static struct platform_device *marzen_late_devices[] __initdata = { |
| 259 | &ehci0_device, |
| 260 | &ehci1_device, |
| 261 | }; |
| 262 | |
| 263 | void __init marzen_init_late(void) |
| 264 | { |
| 265 | /* get usb phy */ |
| 266 | phy = usb_get_phy(USB_PHY_TYPE_USB2); |
| 267 | |
| 268 | shmobile_init_late(); |
| 269 | platform_add_devices(marzen_late_devices, |
| 270 | ARRAY_SIZE(marzen_late_devices)); |
| 271 | } |
| 272 | |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 273 | static void __init marzen_init(void) |
| 274 | { |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 275 | regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers, |
| 276 | ARRAY_SIZE(fixed3v3_power_consumers), 3300000); |
Kuninori Morimoto | 90b85af | 2012-08-29 18:58:15 -0700 | [diff] [blame] | 277 | regulator_register_fixed(1, dummy_supplies, |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 278 | ARRAY_SIZE(dummy_supplies)); |
Guennadi Liakhovetski | b354e22 | 2012-06-27 00:32:32 +0200 | [diff] [blame] | 279 | |
Magnus Damm | 19c43fc | 2011-12-14 01:36:22 +0900 | [diff] [blame] | 280 | r8a7779_pinmux_init(); |
| 281 | |
Magnus Damm | 14f691c | 2011-12-14 01:36:42 +0900 | [diff] [blame] | 282 | /* SCIF2 (CN18: DEBUG0) */ |
| 283 | gpio_request(GPIO_FN_TX2_C, NULL); |
| 284 | gpio_request(GPIO_FN_RX2_C, NULL); |
| 285 | |
| 286 | /* SCIF4 (CN19: DEBUG1) */ |
| 287 | gpio_request(GPIO_FN_TX4, NULL); |
| 288 | gpio_request(GPIO_FN_RX4, NULL); |
| 289 | |
Magnus Damm | db5eb99 | 2011-12-14 01:36:51 +0900 | [diff] [blame] | 290 | /* LAN89218 */ |
| 291 | gpio_request(GPIO_FN_EX_CS0, NULL); /* nCS */ |
| 292 | gpio_request(GPIO_FN_IRQ1_B, NULL); /* IRQ + PME */ |
| 293 | |
Phil Edworthy | 894cda1 | 2012-08-06 13:31:05 +0100 | [diff] [blame] | 294 | /* SD0 (CN20) */ |
| 295 | gpio_request(GPIO_FN_SD0_CLK, NULL); |
| 296 | gpio_request(GPIO_FN_SD0_CMD, NULL); |
| 297 | gpio_request(GPIO_FN_SD0_DAT0, NULL); |
| 298 | gpio_request(GPIO_FN_SD0_DAT1, NULL); |
| 299 | gpio_request(GPIO_FN_SD0_DAT2, NULL); |
| 300 | gpio_request(GPIO_FN_SD0_DAT3, NULL); |
| 301 | gpio_request(GPIO_FN_SD0_CD, NULL); |
| 302 | gpio_request(GPIO_FN_SD0_WP, NULL); |
| 303 | |
Kuninori Morimoto | b82573e | 2012-10-10 19:57:02 -0700 | [diff] [blame] | 304 | /* HSPI 0 */ |
| 305 | gpio_request(GPIO_FN_HSPI_CLK0, NULL); |
| 306 | gpio_request(GPIO_FN_HSPI_CS0, NULL); |
| 307 | gpio_request(GPIO_FN_HSPI_TX0, NULL); |
| 308 | gpio_request(GPIO_FN_HSPI_RX0, NULL); |
| 309 | |
Kuninori Morimoto | 94e1f7f | 2012-10-29 01:15:34 -0700 | [diff] [blame^] | 310 | /* USB (CN21) */ |
| 311 | gpio_request(GPIO_FN_USB_OVC0, NULL); |
| 312 | gpio_request(GPIO_FN_USB_OVC1, NULL); |
| 313 | gpio_request(GPIO_FN_USB_OVC2, NULL); |
| 314 | |
| 315 | /* USB (CN22) */ |
| 316 | gpio_request(GPIO_FN_USB_PENC2, NULL); |
| 317 | |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 318 | r8a7779_add_standard_devices(); |
| 319 | platform_add_devices(marzen_devices, ARRAY_SIZE(marzen_devices)); |
| 320 | } |
| 321 | |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 322 | MACHINE_START(MARZEN, "marzen") |
Marc Zyngier | a62580e | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 323 | .smp = smp_ops(r8a7779_smp_ops), |
Magnus Damm | 3e353b87 | 2012-02-29 21:37:43 +0900 | [diff] [blame] | 324 | .map_io = r8a7779_map_io, |
| 325 | .init_early = r8a7779_add_early_devices, |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 326 | .nr_irqs = NR_IRQS_LEGACY, |
| 327 | .init_irq = r8a7779_init_irq, |
Paul Mundt | 77761b6 | 2012-01-10 13:33:23 +0900 | [diff] [blame] | 328 | .handle_irq = gic_handle_irq, |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 329 | .init_machine = marzen_init, |
Kuninori Morimoto | 94e1f7f | 2012-10-29 01:15:34 -0700 | [diff] [blame^] | 330 | .init_late = marzen_init_late, |
Magnus Damm | df27a2d | 2012-03-06 17:37:01 +0900 | [diff] [blame] | 331 | .timer = &shmobile_timer, |
Magnus Damm | f411fad | 2011-12-14 01:36:12 +0900 | [diff] [blame] | 332 | MACHINE_END |