Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Versatile Express V2M Motherboard Support |
| 3 | */ |
| 4 | #include <linux/device.h> |
| 5 | #include <linux/amba/bus.h> |
| 6 | #include <linux/amba/mmci.h> |
| 7 | #include <linux/io.h> |
Marc Zyngier | 3695adc | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 8 | #include <linux/smp.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 9 | #include <linux/init.h> |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 10 | #include <linux/of_address.h> |
| 11 | #include <linux/of_fdt.h> |
| 12 | #include <linux/of_irq.h> |
| 13 | #include <linux/of_platform.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Nick Bowler | 95c34f8 | 2011-01-21 15:51:06 +0100 | [diff] [blame] | 15 | #include <linux/ata_platform.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 16 | #include <linux/smsc911x.h> |
| 17 | #include <linux/spinlock.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 18 | #include <linux/usb/isp1760.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 19 | #include <linux/clkdev.h> |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 20 | #include <linux/clk-provider.h> |
Marc Zyngier | 0f71fd4 | 2011-05-18 10:51:51 +0100 | [diff] [blame] | 21 | #include <linux/mtd/physmap.h> |
Pawel Moll | b2a54ff | 2012-07-09 11:33:47 +0100 | [diff] [blame] | 22 | #include <linux/regulator/fixed.h> |
| 23 | #include <linux/regulator/machine.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 24 | |
Marc Zyngier | 120f3d6 | 2012-03-28 17:13:53 +0100 | [diff] [blame] | 25 | #include <asm/arch_timer.h> |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 27 | #include <asm/sizes.h> |
Marc Zyngier | 120f3d6 | 2012-03-28 17:13:53 +0100 | [diff] [blame] | 28 | #include <asm/smp_twd.h> |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 29 | #include <asm/mach/arch.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 30 | #include <asm/mach/map.h> |
| 31 | #include <asm/mach/time.h> |
| 32 | #include <asm/hardware/arm_timer.h> |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 33 | #include <asm/hardware/cache-l2x0.h> |
| 34 | #include <asm/hardware/gic.h> |
Russell King | 58daf18 | 2011-01-05 18:09:03 +0000 | [diff] [blame] | 35 | #include <asm/hardware/timer-sp.h> |
Pawel Moll | baaece2 | 2011-01-25 15:53:03 +0100 | [diff] [blame] | 36 | #include <asm/hardware/sp810.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 37 | |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 38 | #include <mach/ct-ca9x4.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 39 | #include <mach/motherboard.h> |
| 40 | |
Russell King | 0af85dd | 2010-12-15 21:58:50 +0000 | [diff] [blame] | 41 | #include <plat/sched_clock.h> |
Marc Zyngier | 3695adc | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 42 | #include <plat/platsmp.h> |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 43 | |
| 44 | #include "core.h" |
| 45 | |
| 46 | #define V2M_PA_CS0 0x40000000 |
| 47 | #define V2M_PA_CS1 0x44000000 |
| 48 | #define V2M_PA_CS2 0x48000000 |
| 49 | #define V2M_PA_CS3 0x4c000000 |
| 50 | #define V2M_PA_CS7 0x10000000 |
| 51 | |
| 52 | static struct map_desc v2m_io_desc[] __initdata = { |
| 53 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 54 | .virtual = V2M_PERIPH, |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 55 | .pfn = __phys_to_pfn(V2M_PA_CS7), |
| 56 | .length = SZ_128K, |
| 57 | .type = MT_DEVICE, |
| 58 | }, |
| 59 | }; |
| 60 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 61 | static void __iomem *v2m_sysreg_base; |
| 62 | |
| 63 | static void __init v2m_sysctl_init(void __iomem *base) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 64 | { |
Pawel Moll | baaece2 | 2011-01-25 15:53:03 +0100 | [diff] [blame] | 65 | u32 scctrl; |
| 66 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 67 | if (WARN_ON(!base)) |
| 68 | return; |
| 69 | |
Pawel Moll | baaece2 | 2011-01-25 15:53:03 +0100 | [diff] [blame] | 70 | /* Select 1MHz TIMCLK as the reference clock for SP804 timers */ |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 71 | scctrl = readl(base + SCCTRL); |
Pawel Moll | baaece2 | 2011-01-25 15:53:03 +0100 | [diff] [blame] | 72 | scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK; |
| 73 | scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK; |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 74 | writel(scctrl, base + SCCTRL); |
| 75 | } |
Pawel Moll | baaece2 | 2011-01-25 15:53:03 +0100 | [diff] [blame] | 76 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 77 | static void __init v2m_sp804_init(void __iomem *base, unsigned int irq) |
| 78 | { |
| 79 | if (WARN_ON(!base || irq == NO_IRQ)) |
| 80 | return; |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 81 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 82 | writel(0, base + TIMER_1_BASE + TIMER_CTRL); |
| 83 | writel(0, base + TIMER_2_BASE + TIMER_CTRL); |
| 84 | |
| 85 | sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1"); |
| 86 | sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0"); |
| 87 | } |
| 88 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 89 | |
| 90 | static DEFINE_SPINLOCK(v2m_cfg_lock); |
| 91 | |
| 92 | int v2m_cfg_write(u32 devfn, u32 data) |
| 93 | { |
| 94 | /* Configuration interface broken? */ |
| 95 | u32 val; |
| 96 | |
| 97 | printk("%s: writing %08x to %08x\n", __func__, data, devfn); |
| 98 | |
| 99 | devfn |= SYS_CFG_START | SYS_CFG_WRITE; |
| 100 | |
| 101 | spin_lock(&v2m_cfg_lock); |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 102 | val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT); |
| 103 | writel(val & ~SYS_CFG_COMPLETE, v2m_sysreg_base + V2M_SYS_CFGSTAT); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 104 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 105 | writel(data, v2m_sysreg_base + V2M_SYS_CFGDATA); |
| 106 | writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 107 | |
| 108 | do { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 109 | val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 110 | } while (val == 0); |
| 111 | spin_unlock(&v2m_cfg_lock); |
| 112 | |
| 113 | return !!(val & SYS_CFG_ERR); |
| 114 | } |
| 115 | |
| 116 | int v2m_cfg_read(u32 devfn, u32 *data) |
| 117 | { |
| 118 | u32 val; |
| 119 | |
| 120 | devfn |= SYS_CFG_START; |
| 121 | |
| 122 | spin_lock(&v2m_cfg_lock); |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 123 | writel(0, v2m_sysreg_base + V2M_SYS_CFGSTAT); |
| 124 | writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 125 | |
| 126 | mb(); |
| 127 | |
| 128 | do { |
| 129 | cpu_relax(); |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 130 | val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 131 | } while (val == 0); |
| 132 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 133 | *data = readl(v2m_sysreg_base + V2M_SYS_CFGDATA); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 134 | spin_unlock(&v2m_cfg_lock); |
| 135 | |
| 136 | return !!(val & SYS_CFG_ERR); |
| 137 | } |
| 138 | |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 139 | void __init v2m_flags_set(u32 data) |
| 140 | { |
| 141 | writel(~0, v2m_sysreg_base + V2M_SYS_FLAGSCLR); |
| 142 | writel(data, v2m_sysreg_base + V2M_SYS_FLAGSSET); |
| 143 | } |
| 144 | |
Pawel Moll | d927daf | 2012-06-12 16:14:03 +0100 | [diff] [blame] | 145 | int v2m_get_master_site(void) |
| 146 | { |
| 147 | u32 misc = readl(v2m_sysreg_base + V2M_SYS_MISC); |
| 148 | |
| 149 | return misc & SYS_MISC_MASTERSITE ? SYS_CFG_SITE_DB2 : SYS_CFG_SITE_DB1; |
| 150 | } |
| 151 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 152 | |
| 153 | static struct resource v2m_pcie_i2c_resource = { |
| 154 | .start = V2M_SERIAL_BUS_PCI, |
| 155 | .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1, |
| 156 | .flags = IORESOURCE_MEM, |
| 157 | }; |
| 158 | |
| 159 | static struct platform_device v2m_pcie_i2c_device = { |
| 160 | .name = "versatile-i2c", |
| 161 | .id = 0, |
| 162 | .num_resources = 1, |
| 163 | .resource = &v2m_pcie_i2c_resource, |
| 164 | }; |
| 165 | |
| 166 | static struct resource v2m_ddc_i2c_resource = { |
| 167 | .start = V2M_SERIAL_BUS_DVI, |
| 168 | .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1, |
| 169 | .flags = IORESOURCE_MEM, |
| 170 | }; |
| 171 | |
| 172 | static struct platform_device v2m_ddc_i2c_device = { |
| 173 | .name = "versatile-i2c", |
| 174 | .id = 1, |
| 175 | .num_resources = 1, |
| 176 | .resource = &v2m_ddc_i2c_resource, |
| 177 | }; |
| 178 | |
| 179 | static struct resource v2m_eth_resources[] = { |
| 180 | { |
| 181 | .start = V2M_LAN9118, |
| 182 | .end = V2M_LAN9118 + SZ_64K - 1, |
| 183 | .flags = IORESOURCE_MEM, |
| 184 | }, { |
| 185 | .start = IRQ_V2M_LAN9118, |
| 186 | .end = IRQ_V2M_LAN9118, |
| 187 | .flags = IORESOURCE_IRQ, |
| 188 | }, |
| 189 | }; |
| 190 | |
| 191 | static struct smsc911x_platform_config v2m_eth_config = { |
| 192 | .flags = SMSC911X_USE_32BIT, |
| 193 | .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH, |
| 194 | .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL, |
| 195 | .phy_interface = PHY_INTERFACE_MODE_MII, |
| 196 | }; |
| 197 | |
| 198 | static struct platform_device v2m_eth_device = { |
| 199 | .name = "smsc911x", |
| 200 | .id = -1, |
| 201 | .resource = v2m_eth_resources, |
| 202 | .num_resources = ARRAY_SIZE(v2m_eth_resources), |
| 203 | .dev.platform_data = &v2m_eth_config, |
| 204 | }; |
| 205 | |
Pawel Moll | b2a54ff | 2012-07-09 11:33:47 +0100 | [diff] [blame] | 206 | static struct regulator_consumer_supply v2m_eth_supplies[] = { |
| 207 | REGULATOR_SUPPLY("vddvario", "smsc911x"), |
| 208 | REGULATOR_SUPPLY("vdd33a", "smsc911x"), |
| 209 | }; |
| 210 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 211 | static struct resource v2m_usb_resources[] = { |
| 212 | { |
| 213 | .start = V2M_ISP1761, |
| 214 | .end = V2M_ISP1761 + SZ_128K - 1, |
| 215 | .flags = IORESOURCE_MEM, |
| 216 | }, { |
| 217 | .start = IRQ_V2M_ISP1761, |
| 218 | .end = IRQ_V2M_ISP1761, |
| 219 | .flags = IORESOURCE_IRQ, |
| 220 | }, |
| 221 | }; |
| 222 | |
| 223 | static struct isp1760_platform_data v2m_usb_config = { |
| 224 | .is_isp1761 = true, |
| 225 | .bus_width_16 = false, |
| 226 | .port1_otg = true, |
| 227 | .analog_oc = false, |
| 228 | .dack_polarity_high = false, |
| 229 | .dreq_polarity_high = false, |
| 230 | }; |
| 231 | |
| 232 | static struct platform_device v2m_usb_device = { |
| 233 | .name = "isp1760", |
| 234 | .id = -1, |
| 235 | .resource = v2m_usb_resources, |
| 236 | .num_resources = ARRAY_SIZE(v2m_usb_resources), |
| 237 | .dev.platform_data = &v2m_usb_config, |
| 238 | }; |
| 239 | |
Marc Zyngier | 667f390 | 2011-05-18 10:51:55 +0100 | [diff] [blame] | 240 | static void v2m_flash_set_vpp(struct platform_device *pdev, int on) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 241 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 242 | writel(on != 0, v2m_sysreg_base + V2M_SYS_FLASH); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Marc Zyngier | 0f71fd4 | 2011-05-18 10:51:51 +0100 | [diff] [blame] | 245 | static struct physmap_flash_data v2m_flash_data = { |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 246 | .width = 4, |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 247 | .set_vpp = v2m_flash_set_vpp, |
| 248 | }; |
| 249 | |
| 250 | static struct resource v2m_flash_resources[] = { |
| 251 | { |
| 252 | .start = V2M_NOR0, |
| 253 | .end = V2M_NOR0 + SZ_64M - 1, |
| 254 | .flags = IORESOURCE_MEM, |
| 255 | }, { |
| 256 | .start = V2M_NOR1, |
| 257 | .end = V2M_NOR1 + SZ_64M - 1, |
| 258 | .flags = IORESOURCE_MEM, |
| 259 | }, |
| 260 | }; |
| 261 | |
| 262 | static struct platform_device v2m_flash_device = { |
Marc Zyngier | 0f71fd4 | 2011-05-18 10:51:51 +0100 | [diff] [blame] | 263 | .name = "physmap-flash", |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 264 | .id = -1, |
| 265 | .resource = v2m_flash_resources, |
| 266 | .num_resources = ARRAY_SIZE(v2m_flash_resources), |
| 267 | .dev.platform_data = &v2m_flash_data, |
| 268 | }; |
| 269 | |
Nick Bowler | 95c34f8 | 2011-01-21 15:51:06 +0100 | [diff] [blame] | 270 | static struct pata_platform_info v2m_pata_data = { |
| 271 | .ioport_shift = 2, |
| 272 | }; |
| 273 | |
| 274 | static struct resource v2m_pata_resources[] = { |
| 275 | { |
| 276 | .start = V2M_CF, |
| 277 | .end = V2M_CF + 0xff, |
| 278 | .flags = IORESOURCE_MEM, |
| 279 | }, { |
| 280 | .start = V2M_CF + 0x100, |
| 281 | .end = V2M_CF + SZ_4K - 1, |
| 282 | .flags = IORESOURCE_MEM, |
| 283 | }, |
| 284 | }; |
| 285 | |
| 286 | static struct platform_device v2m_cf_device = { |
| 287 | .name = "pata_platform", |
| 288 | .id = -1, |
| 289 | .resource = v2m_pata_resources, |
| 290 | .num_resources = ARRAY_SIZE(v2m_pata_resources), |
| 291 | .dev.platform_data = &v2m_pata_data, |
| 292 | }; |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 293 | |
| 294 | static unsigned int v2m_mmci_status(struct device *dev) |
| 295 | { |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 296 | return readl(v2m_sysreg_base + V2M_SYS_MCI) & (1 << 0); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static struct mmci_platform_data v2m_mmci_data = { |
| 300 | .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, |
| 301 | .status = v2m_mmci_status, |
| 302 | }; |
| 303 | |
Russell King | cdd4e1a | 2011-12-18 12:07:09 +0000 | [diff] [blame] | 304 | static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL); |
| 305 | static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data); |
| 306 | static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL); |
| 307 | static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL); |
| 308 | static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL); |
| 309 | static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL); |
| 310 | static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL); |
| 311 | static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL); |
| 312 | static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL); |
| 313 | static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 314 | |
| 315 | static struct amba_device *v2m_amba_devs[] __initdata = { |
| 316 | &aaci_device, |
| 317 | &mmci_device, |
| 318 | &kmi0_device, |
| 319 | &kmi1_device, |
| 320 | &uart0_device, |
| 321 | &uart1_device, |
| 322 | &uart2_device, |
| 323 | &uart3_device, |
| 324 | &wdt_device, |
| 325 | &rtc_device, |
| 326 | }; |
| 327 | |
| 328 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 329 | static unsigned long v2m_osc_recalc_rate(struct clk_hw *hw, |
| 330 | unsigned long parent_rate) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 331 | { |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 332 | struct v2m_osc *osc = to_v2m_osc(hw); |
| 333 | |
| 334 | return !parent_rate ? osc->rate_default : parent_rate; |
| 335 | } |
| 336 | |
| 337 | static long v2m_osc_round_rate(struct clk_hw *hw, unsigned long rate, |
| 338 | unsigned long *parent_rate) |
| 339 | { |
| 340 | struct v2m_osc *osc = to_v2m_osc(hw); |
| 341 | |
| 342 | if (WARN_ON(rate < osc->rate_min)) |
| 343 | rate = osc->rate_min; |
| 344 | |
| 345 | if (WARN_ON(rate > osc->rate_max)) |
| 346 | rate = osc->rate_max; |
| 347 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 348 | return rate; |
| 349 | } |
| 350 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 351 | static int v2m_osc_set_rate(struct clk_hw *hw, unsigned long rate, |
| 352 | unsigned long parent_rate) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 353 | { |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 354 | struct v2m_osc *osc = to_v2m_osc(hw); |
| 355 | |
| 356 | v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE(osc->site) | |
| 357 | SYS_CFG_STACK(osc->stack) | osc->osc, rate); |
| 358 | |
| 359 | return 0; |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 362 | static struct clk_ops v2m_osc_ops = { |
| 363 | .recalc_rate = v2m_osc_recalc_rate, |
| 364 | .round_rate = v2m_osc_round_rate, |
| 365 | .set_rate = v2m_osc_set_rate, |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 366 | }; |
| 367 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 368 | struct clk * __init v2m_osc_register(const char *name, struct v2m_osc *osc) |
| 369 | { |
| 370 | struct clk_init_data init; |
| 371 | |
| 372 | WARN_ON(osc->site > 2); |
| 373 | WARN_ON(osc->stack > 15); |
| 374 | WARN_ON(osc->osc > 4095); |
| 375 | |
| 376 | init.name = name; |
| 377 | init.ops = &v2m_osc_ops; |
| 378 | init.flags = CLK_IS_ROOT; |
| 379 | init.num_parents = 0; |
| 380 | |
| 381 | osc->hw.init = &init; |
| 382 | |
| 383 | return clk_register(NULL, &osc->hw); |
| 384 | } |
| 385 | |
| 386 | static struct v2m_osc v2m_mb_osc1 = { |
| 387 | .site = SYS_CFG_SITE_MB, |
| 388 | .osc = 1, |
| 389 | .rate_min = 23750000, |
| 390 | .rate_max = 63500000, |
| 391 | .rate_default = 23750000, |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 392 | }; |
| 393 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 394 | static const char *v2m_ref_clk_periphs[] __initconst = { |
| 395 | "mb:wdt", "1000f000.wdt", "1c0f0000.wdt", /* SP805 WDT */ |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 398 | static const char *v2m_osc1_periphs[] __initconst = { |
| 399 | "mb:clcd", "1001f000.clcd", "1c1f0000.clcd", /* PL111 CLCD */ |
Russell King | 7ff550d | 2011-05-12 13:31:48 +0100 | [diff] [blame] | 400 | }; |
| 401 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 402 | static const char *v2m_osc2_periphs[] __initconst = { |
| 403 | "mb:mmci", "10005000.mmci", "1c050000.mmci", /* PL180 MMCI */ |
| 404 | "mb:kmi0", "10006000.kmi", "1c060000.kmi", /* PL050 KMI0 */ |
| 405 | "mb:kmi1", "10007000.kmi", "1c070000.kmi", /* PL050 KMI1 */ |
| 406 | "mb:uart0", "10009000.uart", "1c090000.uart", /* PL011 UART0 */ |
| 407 | "mb:uart1", "1000a000.uart", "1c0a0000.uart", /* PL011 UART1 */ |
| 408 | "mb:uart2", "1000b000.uart", "1c0b0000.uart", /* PL011 UART2 */ |
| 409 | "mb:uart3", "1000c000.uart", "1c0c0000.uart", /* PL011 UART3 */ |
Nick Bowler | 0ebb962 | 2011-07-20 15:43:42 +0100 | [diff] [blame] | 410 | }; |
| 411 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 412 | static void __init v2m_clk_init(void) |
| 413 | { |
| 414 | struct clk *clk; |
| 415 | int i; |
Russell King | 3126c7b | 2010-07-15 11:01:17 +0100 | [diff] [blame] | 416 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 417 | clk = clk_register_fixed_rate(NULL, "dummy_apb_pclk", NULL, |
| 418 | CLK_IS_ROOT, 0); |
| 419 | WARN_ON(clk_register_clkdev(clk, "apb_pclk", NULL)); |
| 420 | |
| 421 | clk = clk_register_fixed_rate(NULL, "mb:ref_clk", NULL, |
| 422 | CLK_IS_ROOT, 32768); |
| 423 | for (i = 0; i < ARRAY_SIZE(v2m_ref_clk_periphs); i++) |
| 424 | WARN_ON(clk_register_clkdev(clk, NULL, v2m_ref_clk_periphs[i])); |
| 425 | |
| 426 | clk = clk_register_fixed_rate(NULL, "mb:sp804_clk", NULL, |
| 427 | CLK_IS_ROOT, 1000000); |
| 428 | WARN_ON(clk_register_clkdev(clk, "v2m-timer0", "sp804")); |
| 429 | WARN_ON(clk_register_clkdev(clk, "v2m-timer1", "sp804")); |
| 430 | |
| 431 | clk = v2m_osc_register("mb:osc1", &v2m_mb_osc1); |
| 432 | for (i = 0; i < ARRAY_SIZE(v2m_osc1_periphs); i++) |
| 433 | WARN_ON(clk_register_clkdev(clk, NULL, v2m_osc1_periphs[i])); |
| 434 | |
| 435 | clk = clk_register_fixed_rate(NULL, "mb:osc2", NULL, |
| 436 | CLK_IS_ROOT, 24000000); |
| 437 | for (i = 0; i < ARRAY_SIZE(v2m_osc2_periphs); i++) |
| 438 | WARN_ON(clk_register_clkdev(clk, NULL, v2m_osc2_periphs[i])); |
| 439 | } |
| 440 | |
| 441 | static void __init v2m_timer_init(void) |
| 442 | { |
| 443 | v2m_sysctl_init(ioremap(V2M_SYSCTL, SZ_4K)); |
| 444 | v2m_clk_init(); |
| 445 | v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0); |
| 446 | } |
| 447 | |
| 448 | static struct sys_timer v2m_timer = { |
| 449 | .init = v2m_timer_init, |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 450 | }; |
| 451 | |
Rob Herring | 2fdf999 | 2011-05-30 19:44:22 +0100 | [diff] [blame] | 452 | static void __init v2m_init_early(void) |
| 453 | { |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 454 | if (ct_desc->init_early) |
| 455 | ct_desc->init_early(); |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 456 | versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000); |
Rob Herring | 2fdf999 | 2011-05-30 19:44:22 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 459 | static void v2m_power_off(void) |
| 460 | { |
Pawel Moll | d927daf | 2012-06-12 16:14:03 +0100 | [diff] [blame] | 461 | if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE(SYS_CFG_SITE_MB), 0)) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 462 | printk(KERN_EMERG "Unable to shutdown\n"); |
| 463 | } |
| 464 | |
| 465 | static void v2m_restart(char str, const char *cmd) |
| 466 | { |
Pawel Moll | d927daf | 2012-06-12 16:14:03 +0100 | [diff] [blame] | 467 | if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE(SYS_CFG_SITE_MB), 0)) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 468 | printk(KERN_EMERG "Unable to reboot\n"); |
| 469 | } |
| 470 | |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 471 | struct ct_desc *ct_desc; |
| 472 | |
| 473 | static struct ct_desc *ct_descs[] __initdata = { |
| 474 | #ifdef CONFIG_ARCH_VEXPRESS_CA9X4 |
| 475 | &ct_ca9x4_desc, |
| 476 | #endif |
| 477 | }; |
| 478 | |
| 479 | static void __init v2m_populate_ct_desc(void) |
| 480 | { |
| 481 | int i; |
| 482 | u32 current_tile_id; |
| 483 | |
| 484 | ct_desc = NULL; |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 485 | current_tile_id = readl(v2m_sysreg_base + V2M_SYS_PROCID0) |
| 486 | & V2M_CT_ID_MASK; |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 487 | |
| 488 | for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i) |
| 489 | if (ct_descs[i]->id == current_tile_id) |
| 490 | ct_desc = ct_descs[i]; |
| 491 | |
| 492 | if (!ct_desc) |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 493 | panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n" |
| 494 | "You may need a device tree blob or a different kernel to boot on this board.\n", |
| 495 | current_tile_id); |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void __init v2m_map_io(void) |
| 499 | { |
| 500 | iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc)); |
Pawel Moll | 98ed4ce | 2012-01-25 15:37:29 +0000 | [diff] [blame] | 501 | v2m_sysreg_base = ioremap(V2M_SYSREGS, SZ_4K); |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 502 | v2m_populate_ct_desc(); |
| 503 | ct_desc->map_io(); |
| 504 | } |
| 505 | |
| 506 | static void __init v2m_init_irq(void) |
| 507 | { |
| 508 | ct_desc->init_irq(); |
| 509 | } |
| 510 | |
| 511 | static void __init v2m_init(void) |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 512 | { |
| 513 | int i; |
| 514 | |
Pawel Moll | b2a54ff | 2012-07-09 11:33:47 +0100 | [diff] [blame] | 515 | regulator_register_fixed(0, v2m_eth_supplies, |
| 516 | ARRAY_SIZE(v2m_eth_supplies)); |
| 517 | |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 518 | platform_device_register(&v2m_pcie_i2c_device); |
| 519 | platform_device_register(&v2m_ddc_i2c_device); |
| 520 | platform_device_register(&v2m_flash_device); |
Nick Bowler | 95c34f8 | 2011-01-21 15:51:06 +0100 | [diff] [blame] | 521 | platform_device_register(&v2m_cf_device); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 522 | platform_device_register(&v2m_eth_device); |
| 523 | platform_device_register(&v2m_usb_device); |
| 524 | |
| 525 | for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++) |
| 526 | amba_device_register(v2m_amba_devs[i], &iomem_resource); |
| 527 | |
| 528 | pm_power_off = v2m_power_off; |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 529 | |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 530 | ct_desc->init_tile(); |
Russell King | ceade89 | 2010-02-11 21:44:53 +0000 | [diff] [blame] | 531 | } |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 532 | |
| 533 | MACHINE_START(VEXPRESS, "ARM-Versatile Express") |
Nicolas Pitre | e9ce8e5 | 2011-07-05 22:38:18 -0400 | [diff] [blame] | 534 | .atag_offset = 0x100, |
Marc Zyngier | 3695adc | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 535 | .smp = smp_ops(vexpress_smp_ops), |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 536 | .map_io = v2m_map_io, |
| 537 | .init_early = v2m_init_early, |
| 538 | .init_irq = v2m_init_irq, |
| 539 | .timer = &v2m_timer, |
Marc Zyngier | abd3ca5 | 2011-09-06 10:23:45 +0100 | [diff] [blame] | 540 | .handle_irq = gic_handle_irq, |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 541 | .init_machine = v2m_init, |
Russell King | f5733a1 | 2011-11-04 15:47:50 +0000 | [diff] [blame] | 542 | .restart = v2m_restart, |
Will Deacon | 80b5efbd | 2011-02-28 17:01:04 +0100 | [diff] [blame] | 543 | MACHINE_END |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 544 | |
Pawel Moll | 6a37195 | 2011-12-09 18:47:39 +0000 | [diff] [blame] | 545 | static struct map_desc v2m_rs1_io_desc __initdata = { |
| 546 | .virtual = V2M_PERIPH, |
| 547 | .pfn = __phys_to_pfn(0x1c000000), |
| 548 | .length = SZ_2M, |
| 549 | .type = MT_DEVICE, |
| 550 | }; |
| 551 | |
| 552 | static int __init v2m_dt_scan_memory_map(unsigned long node, const char *uname, |
| 553 | int depth, void *data) |
| 554 | { |
| 555 | const char **map = data; |
| 556 | |
| 557 | if (strcmp(uname, "motherboard") != 0) |
| 558 | return 0; |
| 559 | |
| 560 | *map = of_get_flat_dt_prop(node, "arm,v2m-memory-map", NULL); |
| 561 | |
| 562 | return 1; |
| 563 | } |
| 564 | |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 565 | void __init v2m_dt_map_io(void) |
| 566 | { |
Pawel Moll | 6a37195 | 2011-12-09 18:47:39 +0000 | [diff] [blame] | 567 | const char *map = NULL; |
| 568 | |
| 569 | of_scan_flat_dt(v2m_dt_scan_memory_map, &map); |
| 570 | |
| 571 | if (map && strcmp(map, "rs1") == 0) |
| 572 | iotable_init(&v2m_rs1_io_desc, 1); |
| 573 | else |
| 574 | iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc)); |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 575 | |
| 576 | #if defined(CONFIG_SMP) |
| 577 | vexpress_dt_smp_map_io(); |
| 578 | #endif |
| 579 | } |
| 580 | |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 581 | void __init v2m_dt_init_early(void) |
| 582 | { |
| 583 | struct device_node *node; |
| 584 | u32 dt_hbi; |
| 585 | |
| 586 | node = of_find_compatible_node(NULL, NULL, "arm,vexpress-sysreg"); |
| 587 | v2m_sysreg_base = of_iomap(node, 0); |
| 588 | if (WARN_ON(!v2m_sysreg_base)) |
| 589 | return; |
| 590 | |
| 591 | /* Confirm board type against DT property, if available */ |
Randy Dunlap | 465aac6 | 2012-11-30 10:01:51 +0000 | [diff] [blame^] | 592 | if (of_property_read_u32(of_allnodes, "arm,hbi", &dt_hbi) == 0) { |
Pawel Moll | d927daf | 2012-06-12 16:14:03 +0100 | [diff] [blame] | 593 | int site = v2m_get_master_site(); |
| 594 | u32 id = readl(v2m_sysreg_base + (site == SYS_CFG_SITE_DB2 ? |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 595 | V2M_SYS_PROCID1 : V2M_SYS_PROCID0)); |
| 596 | u32 hbi = id & SYS_PROCIDx_HBI_MASK; |
| 597 | |
| 598 | if (WARN_ON(dt_hbi != hbi)) |
| 599 | pr_warning("vexpress: DT HBI (%x) is not matching " |
| 600 | "hardware (%x)!\n", dt_hbi, hbi); |
| 601 | } |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static struct of_device_id vexpress_irq_match[] __initdata = { |
| 605 | { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, }, |
| 606 | {} |
| 607 | }; |
| 608 | |
| 609 | static void __init v2m_dt_init_irq(void) |
| 610 | { |
| 611 | of_irq_init(vexpress_irq_match); |
| 612 | } |
| 613 | |
| 614 | static void __init v2m_dt_timer_init(void) |
| 615 | { |
| 616 | struct device_node *node; |
| 617 | const char *path; |
| 618 | int err; |
| 619 | |
| 620 | node = of_find_compatible_node(NULL, NULL, "arm,sp810"); |
| 621 | v2m_sysctl_init(of_iomap(node, 0)); |
| 622 | |
Pawel Moll | d1b8a77 | 2012-07-13 11:48:16 +0100 | [diff] [blame] | 623 | v2m_clk_init(); |
| 624 | |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 625 | err = of_property_read_string(of_aliases, "arm,v2m_timer", &path); |
| 626 | if (WARN_ON(err)) |
| 627 | return; |
| 628 | node = of_find_node_by_path(path); |
| 629 | v2m_sp804_init(of_iomap(node, 0), irq_of_parse_and_map(node, 0)); |
Marc Zyngier | 120f3d6 | 2012-03-28 17:13:53 +0100 | [diff] [blame] | 630 | if (arch_timer_of_register() != 0) |
| 631 | twd_local_timer_of_register(); |
| 632 | |
| 633 | if (arch_timer_sched_clock_init() != 0) |
| 634 | versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000); |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static struct sys_timer v2m_dt_timer = { |
| 638 | .init = v2m_dt_timer_init, |
| 639 | }; |
| 640 | |
| 641 | static struct of_dev_auxdata v2m_dt_auxdata_lookup[] __initdata = { |
| 642 | OF_DEV_AUXDATA("arm,vexpress-flash", V2M_NOR0, "physmap-flash", |
| 643 | &v2m_flash_data), |
| 644 | OF_DEV_AUXDATA("arm,primecell", V2M_MMCI, "mb:mmci", &v2m_mmci_data), |
Pawel Moll | 6a37195 | 2011-12-09 18:47:39 +0000 | [diff] [blame] | 645 | /* RS1 memory map */ |
| 646 | OF_DEV_AUXDATA("arm,vexpress-flash", 0x08000000, "physmap-flash", |
| 647 | &v2m_flash_data), |
| 648 | OF_DEV_AUXDATA("arm,primecell", 0x1c050000, "mb:mmci", &v2m_mmci_data), |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 649 | {} |
| 650 | }; |
| 651 | |
| 652 | static void __init v2m_dt_init(void) |
| 653 | { |
| 654 | l2x0_of_init(0x00400000, 0xfe0fffff); |
| 655 | of_platform_populate(NULL, of_default_bus_match_table, |
| 656 | v2m_dt_auxdata_lookup, NULL); |
| 657 | pm_power_off = v2m_power_off; |
| 658 | } |
| 659 | |
| 660 | const static char *v2m_dt_match[] __initconst = { |
| 661 | "arm,vexpress", |
Stefano Stabellini | bbd6eb2 | 2012-09-24 16:40:52 +0000 | [diff] [blame] | 662 | "xen,xenvm", |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 663 | NULL, |
| 664 | }; |
| 665 | |
| 666 | DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express") |
| 667 | .dt_compat = v2m_dt_match, |
Marc Zyngier | 3695adc | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 668 | .smp = smp_ops(vexpress_smp_ops), |
Pawel Moll | 8deed17 | 2012-02-23 13:04:51 +0000 | [diff] [blame] | 669 | .map_io = v2m_dt_map_io, |
| 670 | .init_early = v2m_dt_init_early, |
| 671 | .init_irq = v2m_dt_init_irq, |
| 672 | .timer = &v2m_dt_timer, |
| 673 | .init_machine = v2m_dt_init, |
| 674 | .handle_irq = gic_handle_irq, |
| 675 | .restart = v2m_restart, |
| 676 | MACHINE_END |