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