19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2b85a3ef4SJohn Linn /*
3b85a3ef4SJohn Linn * This file contains common code that is intended to be used across
4b85a3ef4SJohn Linn * boards so that it's not replicated.
5b85a3ef4SJohn Linn *
6b85a3ef4SJohn Linn * Copyright (C) 2011 Xilinx
7b85a3ef4SJohn Linn */
8b85a3ef4SJohn Linn
9b85a3ef4SJohn Linn #include <linux/init.h>
1062e59c4eSStephen Boyd #include <linux/io.h>
11b85a3ef4SJohn Linn #include <linux/kernel.h>
12b85a3ef4SJohn Linn #include <linux/cpumask.h>
13b85a3ef4SJohn Linn #include <linux/platform_device.h>
14b85a3ef4SJohn Linn #include <linux/clk.h>
150f586fbfSJosh Cartwright #include <linux/clk/zynq.h>
16e932900aSMichal Simek #include <linux/clocksource.h>
170f586fbfSJosh Cartwright #include <linux/of_address.h>
181a1a9fafSGeert Uytterhoeven #include <linux/of_clk.h>
19b85a3ef4SJohn Linn #include <linux/of_irq.h>
20b85a3ef4SJohn Linn #include <linux/of_platform.h>
213d64b449SArnd Bergmann #include <linux/of.h>
2246f5b960SMichal Simek #include <linux/memblock.h>
239f4f5d26SSoren Brinkmann #include <linux/irqchip.h>
249f4f5d26SSoren Brinkmann #include <linux/irqchip/arm-gic.h>
2500f7dc63SMichal Simek #include <linux/slab.h>
2600f7dc63SMichal Simek #include <linux/sys_soc.h>
2765fddcfcSMike Rapoport #include <linux/pgtable.h>
28b85a3ef4SJohn Linn
293d64b449SArnd Bergmann #include <asm/mach/arch.h>
30b85a3ef4SJohn Linn #include <asm/mach/map.h>
3103e07595SJosh Cartwright #include <asm/mach/time.h>
323d64b449SArnd Bergmann #include <asm/mach-types.h>
33b85a3ef4SJohn Linn #include <asm/page.h>
34732078c3SMichal Simek #include <asm/smp_scu.h>
3500f7dc63SMichal Simek #include <asm/system_info.h>
36b85a3ef4SJohn Linn #include <asm/hardware/cache-l2x0.h>
37b85a3ef4SJohn Linn
38b85a3ef4SJohn Linn #include "common.h"
39b85a3ef4SJohn Linn
4000f7dc63SMichal Simek #define ZYNQ_DEVCFG_MCTRL 0x80
4100f7dc63SMichal Simek #define ZYNQ_DEVCFG_PS_VERSION_SHIFT 28
4200f7dc63SMichal Simek #define ZYNQ_DEVCFG_PS_VERSION_MASK 0xF
4300f7dc63SMichal Simek
44732078c3SMichal Simek void __iomem *zynq_scu_base;
45732078c3SMichal Simek
4646f5b960SMichal Simek /**
4746f5b960SMichal Simek * zynq_memory_init - Initialize special memory
4846f5b960SMichal Simek *
4946f5b960SMichal Simek * We need to stop things allocating the low memory as DMA can't work in
5046f5b960SMichal Simek * the 1st 512K of memory.
5146f5b960SMichal Simek */
zynq_memory_init(void)5246f5b960SMichal Simek static void __init zynq_memory_init(void)
5346f5b960SMichal Simek {
5446f5b960SMichal Simek if (!__pa(PAGE_OFFSET))
557a3cc2a7SKyle Roeschley memblock_reserve(__pa(PAGE_OFFSET), 0x80000);
5646f5b960SMichal Simek }
5746f5b960SMichal Simek
583e8ceca6SDaniel Lezcano static struct platform_device zynq_cpuidle_device = {
593e8ceca6SDaniel Lezcano .name = "cpuidle-zynq",
603e8ceca6SDaniel Lezcano };
613e8ceca6SDaniel Lezcano
62b85a3ef4SJohn Linn /**
6300f7dc63SMichal Simek * zynq_get_revision - Get Zynq silicon revision
6400f7dc63SMichal Simek *
6500f7dc63SMichal Simek * Return: Silicon version or -1 otherwise
6600f7dc63SMichal Simek */
zynq_get_revision(void)6700f7dc63SMichal Simek static int __init zynq_get_revision(void)
6800f7dc63SMichal Simek {
6900f7dc63SMichal Simek struct device_node *np;
7000f7dc63SMichal Simek void __iomem *zynq_devcfg_base;
7100f7dc63SMichal Simek u32 revision;
7200f7dc63SMichal Simek
7300f7dc63SMichal Simek np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-devcfg-1.0");
7400f7dc63SMichal Simek if (!np) {
7500f7dc63SMichal Simek pr_err("%s: no devcfg node found\n", __func__);
7600f7dc63SMichal Simek return -1;
7700f7dc63SMichal Simek }
7800f7dc63SMichal Simek
7900f7dc63SMichal Simek zynq_devcfg_base = of_iomap(np, 0);
80*d1ff2559SMiaoqian Lin of_node_put(np);
8100f7dc63SMichal Simek if (!zynq_devcfg_base) {
8200f7dc63SMichal Simek pr_err("%s: Unable to map I/O memory\n", __func__);
8300f7dc63SMichal Simek return -1;
8400f7dc63SMichal Simek }
8500f7dc63SMichal Simek
8600f7dc63SMichal Simek revision = readl(zynq_devcfg_base + ZYNQ_DEVCFG_MCTRL);
8700f7dc63SMichal Simek revision >>= ZYNQ_DEVCFG_PS_VERSION_SHIFT;
8800f7dc63SMichal Simek revision &= ZYNQ_DEVCFG_PS_VERSION_MASK;
8900f7dc63SMichal Simek
9000f7dc63SMichal Simek iounmap(zynq_devcfg_base);
9100f7dc63SMichal Simek
9200f7dc63SMichal Simek return revision;
9300f7dc63SMichal Simek }
9400f7dc63SMichal Simek
zynq_init_late(void)95ae88b85eSSoren Brinkmann static void __init zynq_init_late(void)
96ae88b85eSSoren Brinkmann {
97ae88b85eSSoren Brinkmann zynq_core_pm_init();
980beb2bd3SSoren Brinkmann zynq_pm_late_init();
99ae88b85eSSoren Brinkmann }
100ae88b85eSSoren Brinkmann
10100f7dc63SMichal Simek /**
102889faa88SMichal Simek * zynq_init_machine - System specific initialization, intended to be
103b85a3ef4SJohn Linn * called from board specific initialization.
104b85a3ef4SJohn Linn */
zynq_init_machine(void)105889faa88SMichal Simek static void __init zynq_init_machine(void)
106b85a3ef4SJohn Linn {
10700f7dc63SMichal Simek struct soc_device_attribute *soc_dev_attr;
10800f7dc63SMichal Simek struct soc_device *soc_dev;
10900f7dc63SMichal Simek struct device *parent = NULL;
110cd325295SSoren Brinkmann
11100f7dc63SMichal Simek soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
11200f7dc63SMichal Simek if (!soc_dev_attr)
11300f7dc63SMichal Simek goto out;
11400f7dc63SMichal Simek
11500f7dc63SMichal Simek system_rev = zynq_get_revision();
11600f7dc63SMichal Simek
11700f7dc63SMichal Simek soc_dev_attr->family = kasprintf(GFP_KERNEL, "Xilinx Zynq");
11800f7dc63SMichal Simek soc_dev_attr->revision = kasprintf(GFP_KERNEL, "0x%x", system_rev);
11900f7dc63SMichal Simek soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%x",
12000f7dc63SMichal Simek zynq_slcr_get_device_id());
12100f7dc63SMichal Simek
12200f7dc63SMichal Simek soc_dev = soc_device_register(soc_dev_attr);
12300f7dc63SMichal Simek if (IS_ERR(soc_dev)) {
12400f7dc63SMichal Simek kfree(soc_dev_attr->family);
12500f7dc63SMichal Simek kfree(soc_dev_attr->revision);
12600f7dc63SMichal Simek kfree(soc_dev_attr->soc_id);
12700f7dc63SMichal Simek kfree(soc_dev_attr);
12800f7dc63SMichal Simek goto out;
12900f7dc63SMichal Simek }
13000f7dc63SMichal Simek
13100f7dc63SMichal Simek parent = soc_device_to_device(soc_dev);
13200f7dc63SMichal Simek
13300f7dc63SMichal Simek out:
13400f7dc63SMichal Simek /*
13500f7dc63SMichal Simek * Finished with the static registrations now; fill in the missing
13600f7dc63SMichal Simek * devices
13700f7dc63SMichal Simek */
138435ebcbcSKefeng Wang of_platform_default_populate(NULL, NULL, parent);
1393e8ceca6SDaniel Lezcano
1403e8ceca6SDaniel Lezcano platform_device_register(&zynq_cpuidle_device);
141b85a3ef4SJohn Linn }
142b85a3ef4SJohn Linn
zynq_timer_init(void)143889faa88SMichal Simek static void __init zynq_timer_init(void)
14403e07595SJosh Cartwright {
145b0504e39SMichal Simek zynq_clock_init();
1464a32c74eSMichal Simek of_clk_init(NULL);
147ba5d08c0SDaniel Lezcano timer_probe();
14803e07595SJosh Cartwright }
14903e07595SJosh Cartwright
150732078c3SMichal Simek static struct map_desc zynq_cortex_a9_scu_map __initdata = {
151732078c3SMichal Simek .length = SZ_256,
152732078c3SMichal Simek .type = MT_DEVICE,
153732078c3SMichal Simek };
154732078c3SMichal Simek
zynq_scu_map_io(void)155732078c3SMichal Simek static void __init zynq_scu_map_io(void)
156732078c3SMichal Simek {
157732078c3SMichal Simek unsigned long base;
158732078c3SMichal Simek
159732078c3SMichal Simek base = scu_a9_get_base();
160732078c3SMichal Simek zynq_cortex_a9_scu_map.pfn = __phys_to_pfn(base);
161732078c3SMichal Simek /* Expected address is in vmalloc area that's why simple assign here */
162732078c3SMichal Simek zynq_cortex_a9_scu_map.virtual = base;
163732078c3SMichal Simek iotable_init(&zynq_cortex_a9_scu_map, 1);
164732078c3SMichal Simek zynq_scu_base = (void __iomem *)base;
165732078c3SMichal Simek BUG_ON(!zynq_scu_base);
166732078c3SMichal Simek }
167732078c3SMichal Simek
168b85a3ef4SJohn Linn /**
169889faa88SMichal Simek * zynq_map_io - Create memory mappings needed for early I/O.
170b85a3ef4SJohn Linn */
zynq_map_io(void)171889faa88SMichal Simek static void __init zynq_map_io(void)
172b85a3ef4SJohn Linn {
173385f02b1SJosh Cartwright debug_ll_io_init();
174732078c3SMichal Simek zynq_scu_map_io();
175b85a3ef4SJohn Linn }
1763d64b449SArnd Bergmann
zynq_irq_init(void)1779f4f5d26SSoren Brinkmann static void __init zynq_irq_init(void)
1789f4f5d26SSoren Brinkmann {
1799388187fSJosh Cartwright zynq_early_slcr_init();
1809f4f5d26SSoren Brinkmann irqchip_init();
1819f4f5d26SSoren Brinkmann }
1829f4f5d26SSoren Brinkmann
183889faa88SMichal Simek static const char * const zynq_dt_match[] = {
184e06f1a9eSJosh Cartwright "xlnx,zynq-7000",
1853d64b449SArnd Bergmann NULL
1863d64b449SArnd Bergmann };
1873d64b449SArnd Bergmann
188514a5908SArnd Bergmann DT_MACHINE_START(XILINX_EP107, "Xilinx Zynq Platform")
189dcf9c7f9SRussell King /* 64KB way size, 8-way associativity, parity disabled */
1906632d4fdSThomas Betker .l2c_aux_val = 0x00400000,
1916632d4fdSThomas Betker .l2c_aux_mask = 0xffbfffff,
192aa7eb2bbSMichal Simek .smp = smp_ops(zynq_smp_ops),
193889faa88SMichal Simek .map_io = zynq_map_io,
1949f4f5d26SSoren Brinkmann .init_irq = zynq_irq_init,
195889faa88SMichal Simek .init_machine = zynq_init_machine,
196ae88b85eSSoren Brinkmann .init_late = zynq_init_late,
197889faa88SMichal Simek .init_time = zynq_timer_init,
198889faa88SMichal Simek .dt_compat = zynq_dt_match,
19946f5b960SMichal Simek .reserve = zynq_memory_init,
2003d64b449SArnd Bergmann MACHINE_END
201