Thomas Gleixner | 25d5bf4 | 2019-06-01 10:08:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Cavium Networks CNS3420 Validation Board |
| 4 | * |
| 5 | * Copyright 2000 Deep Blue Solutions Ltd |
| 6 | * Copyright 2008 ARM Limited |
| 7 | * Copyright 2008 Cavium Networks |
| 8 | * Scott Shu |
| 9 | * Copyright 2010 MontaVista Software, LLC. |
| 10 | * Anton Vorontsov <avorontsov@mvista.com> |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/compiler.h> |
| 16 | #include <linux/io.h> |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 17 | #include <linux/dma-mapping.h> |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 18 | #include <linux/serial_core.h> |
| 19 | #include <linux/serial_8250.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/mtd/mtd.h> |
| 22 | #include <linux/mtd/physmap.h> |
| 23 | #include <linux/mtd/partitions.h> |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 24 | #include <linux/usb/ehci_pdriver.h> |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 25 | #include <linux/usb/ohci_pdriver.h> |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 26 | #include <asm/setup.h> |
| 27 | #include <asm/mach-types.h> |
| 28 | #include <asm/mach/arch.h> |
| 29 | #include <asm/mach/map.h> |
| 30 | #include <asm/mach/time.h> |
Arnd Bergmann | 3f9fb2a | 2013-03-13 13:15:25 +0100 | [diff] [blame] | 31 | #include "cns3xxx.h" |
| 32 | #include "pm.h" |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 33 | #include "core.h" |
Anton Vorontsov | 6279d0e | 2010-05-28 13:14:44 +0400 | [diff] [blame] | 34 | #include "devices.h" |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * NOR Flash |
| 38 | */ |
| 39 | static struct mtd_partition cns3420_nor_partitions[] = { |
| 40 | { |
| 41 | .name = "uboot", |
| 42 | .size = 0x00040000, |
| 43 | .offset = 0, |
| 44 | .mask_flags = MTD_WRITEABLE, |
| 45 | }, { |
| 46 | .name = "kernel", |
| 47 | .size = 0x004C0000, |
| 48 | .offset = MTDPART_OFS_APPEND, |
| 49 | }, { |
| 50 | .name = "filesystem", |
| 51 | .size = 0x7000000, |
| 52 | .offset = MTDPART_OFS_APPEND, |
| 53 | }, { |
| 54 | .name = "filesystem2", |
| 55 | .size = 0x0AE0000, |
| 56 | .offset = MTDPART_OFS_APPEND, |
| 57 | }, { |
| 58 | .name = "ubootenv", |
| 59 | .size = MTDPART_SIZ_FULL, |
| 60 | .offset = MTDPART_OFS_APPEND, |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | static struct physmap_flash_data cns3420_nor_pdata = { |
| 65 | .width = 2, |
| 66 | .parts = cns3420_nor_partitions, |
| 67 | .nr_parts = ARRAY_SIZE(cns3420_nor_partitions), |
| 68 | }; |
| 69 | |
| 70 | static struct resource cns3420_nor_res = { |
| 71 | .start = CNS3XXX_FLASH_BASE, |
| 72 | .end = CNS3XXX_FLASH_BASE + SZ_128M - 1, |
| 73 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
| 74 | }; |
| 75 | |
| 76 | static struct platform_device cns3420_nor_pdev = { |
| 77 | .name = "physmap-flash", |
| 78 | .id = 0, |
| 79 | .resource = &cns3420_nor_res, |
| 80 | .num_resources = 1, |
| 81 | .dev = { |
| 82 | .platform_data = &cns3420_nor_pdata, |
| 83 | }, |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * UART |
| 88 | */ |
| 89 | static void __init cns3420_early_serial_setup(void) |
| 90 | { |
| 91 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 92 | static struct uart_port cns3420_serial_port = { |
| 93 | .membase = (void __iomem *)CNS3XXX_UART0_BASE_VIRT, |
| 94 | .mapbase = CNS3XXX_UART0_BASE, |
| 95 | .irq = IRQ_CNS3XXX_UART0, |
| 96 | .iotype = UPIO_MEM, |
| 97 | .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, |
| 98 | .regshift = 2, |
| 99 | .uartclk = 24000000, |
| 100 | .line = 0, |
| 101 | .type = PORT_16550A, |
| 102 | .fifosize = 16, |
| 103 | }; |
| 104 | |
| 105 | early_serial_setup(&cns3420_serial_port); |
| 106 | #endif |
| 107 | } |
| 108 | |
| 109 | /* |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 110 | * USB |
| 111 | */ |
| 112 | static struct resource cns3xxx_usb_ehci_resources[] = { |
| 113 | [0] = { |
| 114 | .start = CNS3XXX_USB_BASE, |
| 115 | .end = CNS3XXX_USB_BASE + SZ_16M - 1, |
| 116 | .flags = IORESOURCE_MEM, |
| 117 | }, |
| 118 | [1] = { |
| 119 | .start = IRQ_CNS3XXX_USB_EHCI, |
| 120 | .flags = IORESOURCE_IRQ, |
| 121 | }, |
| 122 | }; |
| 123 | |
| 124 | static u64 cns3xxx_usb_ehci_dma_mask = DMA_BIT_MASK(32); |
| 125 | |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 126 | static int csn3xxx_usb_power_on(struct platform_device *pdev) |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 127 | { |
| 128 | /* |
| 129 | * EHCI and OHCI share the same clock and power, |
| 130 | * resetting twice would cause the 1st controller been reset. |
| 131 | * Therefore only do power up at the first up device, and |
| 132 | * power down at the last down device. |
| 133 | * |
| 134 | * Set USB AHB INCR length to 16 |
| 135 | */ |
| 136 | if (atomic_inc_return(&usb_pwr_ref) == 1) { |
| 137 | cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB); |
| 138 | cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST); |
| 139 | cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST); |
| 140 | __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)), |
| 141 | MISC_CHIP_CONFIG_REG); |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 147 | static void csn3xxx_usb_power_off(struct platform_device *pdev) |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 148 | { |
| 149 | /* |
| 150 | * EHCI and OHCI share the same clock and power, |
| 151 | * resetting twice would cause the 1st controller been reset. |
| 152 | * Therefore only do power up at the first up device, and |
| 153 | * power down at the last down device. |
| 154 | */ |
| 155 | if (atomic_dec_return(&usb_pwr_ref) == 0) |
| 156 | cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST); |
| 157 | } |
| 158 | |
| 159 | static struct usb_ehci_pdata cns3xxx_usb_ehci_pdata = { |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 160 | .power_on = csn3xxx_usb_power_on, |
| 161 | .power_off = csn3xxx_usb_power_off, |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 164 | static struct platform_device cns3xxx_usb_ehci_device = { |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 165 | .name = "ehci-platform", |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 166 | .num_resources = ARRAY_SIZE(cns3xxx_usb_ehci_resources), |
| 167 | .resource = cns3xxx_usb_ehci_resources, |
| 168 | .dev = { |
| 169 | .dma_mask = &cns3xxx_usb_ehci_dma_mask, |
| 170 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Florian Fainelli | b898f5f | 2012-10-08 15:11:24 +0200 | [diff] [blame] | 171 | .platform_data = &cns3xxx_usb_ehci_pdata, |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 172 | }, |
| 173 | }; |
| 174 | |
| 175 | static struct resource cns3xxx_usb_ohci_resources[] = { |
| 176 | [0] = { |
| 177 | .start = CNS3XXX_USB_OHCI_BASE, |
| 178 | .end = CNS3XXX_USB_OHCI_BASE + SZ_16M - 1, |
| 179 | .flags = IORESOURCE_MEM, |
| 180 | }, |
| 181 | [1] = { |
| 182 | .start = IRQ_CNS3XXX_USB_OHCI, |
| 183 | .flags = IORESOURCE_IRQ, |
| 184 | }, |
| 185 | }; |
| 186 | |
| 187 | static u64 cns3xxx_usb_ohci_dma_mask = DMA_BIT_MASK(32); |
| 188 | |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 189 | static struct usb_ohci_pdata cns3xxx_usb_ohci_pdata = { |
| 190 | .num_ports = 1, |
| 191 | .power_on = csn3xxx_usb_power_on, |
| 192 | .power_off = csn3xxx_usb_power_off, |
| 193 | }; |
| 194 | |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 195 | static struct platform_device cns3xxx_usb_ohci_device = { |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 196 | .name = "ohci-platform", |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 197 | .num_resources = ARRAY_SIZE(cns3xxx_usb_ohci_resources), |
| 198 | .resource = cns3xxx_usb_ohci_resources, |
| 199 | .dev = { |
| 200 | .dma_mask = &cns3xxx_usb_ohci_dma_mask, |
| 201 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Florian Fainelli | 6da00dd | 2012-10-08 15:11:32 +0200 | [diff] [blame] | 202 | .platform_data = &cns3xxx_usb_ohci_pdata, |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 203 | }, |
| 204 | }; |
| 205 | |
| 206 | /* |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 207 | * Initialization |
| 208 | */ |
| 209 | static struct platform_device *cns3420_pdevs[] __initdata = { |
| 210 | &cns3420_nor_pdev, |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 211 | &cns3xxx_usb_ehci_device, |
| 212 | &cns3xxx_usb_ohci_device, |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | static void __init cns3420_init(void) |
| 216 | { |
Anton Vorontsov | 93e85d8 | 2011-07-06 16:45:09 +0400 | [diff] [blame] | 217 | cns3xxx_l2x0_init(); |
| 218 | |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 219 | platform_add_devices(cns3420_pdevs, ARRAY_SIZE(cns3420_pdevs)); |
| 220 | |
Anton Vorontsov | 23f5cac | 2010-03-25 23:10:58 +0300 | [diff] [blame] | 221 | cns3xxx_ahci_init(); |
Anton Vorontsov | 6279d0e | 2010-05-28 13:14:44 +0400 | [diff] [blame] | 222 | cns3xxx_sdhci_init(); |
| 223 | |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 224 | pm_power_off = cns3xxx_power_off; |
| 225 | } |
| 226 | |
| 227 | static struct map_desc cns3420_io_desc[] __initdata = { |
| 228 | { |
| 229 | .virtual = CNS3XXX_UART0_BASE_VIRT, |
| 230 | .pfn = __phys_to_pfn(CNS3XXX_UART0_BASE), |
| 231 | .length = SZ_4K, |
| 232 | .type = MT_DEVICE, |
| 233 | }, |
| 234 | }; |
| 235 | |
| 236 | static void __init cns3420_map_io(void) |
| 237 | { |
| 238 | cns3xxx_map_io(); |
| 239 | iotable_init(cns3420_io_desc, ARRAY_SIZE(cns3420_io_desc)); |
| 240 | |
| 241 | cns3420_early_serial_setup(); |
| 242 | } |
| 243 | |
| 244 | MACHINE_START(CNS3420VB, "Cavium Networks CNS3420 Validation Board") |
Nicolas Pitre | 03e6720 | 2011-07-05 22:38:11 -0400 | [diff] [blame] | 245 | .atag_offset = 0x100, |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 246 | .map_io = cns3420_map_io, |
| 247 | .init_irq = cns3xxx_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 248 | .init_time = cns3xxx_timer_init, |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 249 | .init_machine = cns3420_init, |
Xia Kaixu | 0a2e912 | 2014-09-03 21:18:12 +0800 | [diff] [blame] | 250 | .init_late = cns3xxx_pcie_init_late, |
Russell King | 3921470 | 2011-11-05 15:32:23 +0000 | [diff] [blame] | 251 | .restart = cns3xxx_restart, |
Anton Vorontsov | e94cdef | 2010-03-26 21:19:02 +0300 | [diff] [blame] | 252 | MACHINE_END |