1b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn/* 2b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * This file contains common code that is intended to be used across 3b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * boards so that it's not replicated. 4b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * 5b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * Copyright (C) 2011 Xilinx 6b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * 7b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * This software is licensed under the terms of the GNU General Public 8b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * License version 2, as published by the Free Software Foundation, and 9b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * may be copied, distributed, and modified under those terms. 10b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * 11b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * This program is distributed in the hope that it will be useful, 12b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * but WITHOUT ANY WARRANTY; without even the implied warranty of 13b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn * GNU General Public License for more details. 15b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn */ 16b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn 17b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/init.h> 18b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/kernel.h> 19b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/cpumask.h> 20b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/platform_device.h> 21b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/clk.h> 224a32c74e762236a53627536b9b9c1693d3073359Michal Simek#include <linux/clk-provider.h> 230f586fbf6f6a9119392a5cb0f193ac11c753b09eJosh Cartwright#include <linux/clk/zynq.h> 24e932900a3279b5dbb6d8f43c7b369003620e137cMichal Simek#include <linux/clocksource.h> 250f586fbf6f6a9119392a5cb0f193ac11c753b09eJosh Cartwright#include <linux/of_address.h> 26b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/of_irq.h> 27b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <linux/of_platform.h> 283d64b4496f5fd90618106555344205a522178c0cArnd Bergmann#include <linux/of.h> 2946f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek#include <linux/memblock.h> 309f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann#include <linux/irqchip.h> 319f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann#include <linux/irqchip/arm-gic.h> 3200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#include <linux/slab.h> 3300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#include <linux/sys_soc.h> 34b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn 353d64b4496f5fd90618106555344205a522178c0cArnd Bergmann#include <asm/mach/arch.h> 36b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <asm/mach/map.h> 3703e07595febc4857b2b6ad756826f369c7628ec8Josh Cartwright#include <asm/mach/time.h> 383d64b4496f5fd90618106555344205a522178c0cArnd Bergmann#include <asm/mach-types.h> 39b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <asm/page.h> 409a45eb691d8712b64a733178746557f708043444Josh Cartwright#include <asm/pgtable.h> 41732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek#include <asm/smp_scu.h> 4200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#include <asm/system_info.h> 43b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include <asm/hardware/cache-l2x0.h> 44b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn 45b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn#include "common.h" 46b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn 4700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#define ZYNQ_DEVCFG_MCTRL 0x80 4800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#define ZYNQ_DEVCFG_PS_VERSION_SHIFT 28 4900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek#define ZYNQ_DEVCFG_PS_VERSION_MASK 0xF 5000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 51732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simekvoid __iomem *zynq_scu_base; 52732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek 5346f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek/** 5446f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek * zynq_memory_init - Initialize special memory 5546f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek * 5646f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek * We need to stop things allocating the low memory as DMA can't work in 5746f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek * the 1st 512K of memory. 5846f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek */ 5946f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simekstatic void __init zynq_memory_init(void) 6046f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek{ 6146f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek if (!__pa(PAGE_OFFSET)) 6246f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek memblock_reserve(__pa(PAGE_OFFSET), __pa(swapper_pg_dir)); 6346f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek} 6446f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek 653e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcanostatic struct platform_device zynq_cpuidle_device = { 663e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcano .name = "cpuidle-zynq", 673e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcano}; 683e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcano 69b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn/** 7000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek * zynq_get_revision - Get Zynq silicon revision 7100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek * 7200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek * Return: Silicon version or -1 otherwise 7300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek */ 7400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simekstatic int __init zynq_get_revision(void) 7500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek{ 7600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek struct device_node *np; 7700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek void __iomem *zynq_devcfg_base; 7800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek u32 revision; 7900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 8000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-devcfg-1.0"); 8100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek if (!np) { 8200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek pr_err("%s: no devcfg node found\n", __func__); 8300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek return -1; 8400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek } 8500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 8600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek zynq_devcfg_base = of_iomap(np, 0); 8700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek if (!zynq_devcfg_base) { 8800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek pr_err("%s: Unable to map I/O memory\n", __func__); 8900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek return -1; 9000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek } 9100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 9200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek revision = readl(zynq_devcfg_base + ZYNQ_DEVCFG_MCTRL); 9300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek revision >>= ZYNQ_DEVCFG_PS_VERSION_SHIFT; 9400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek revision &= ZYNQ_DEVCFG_PS_VERSION_MASK; 9500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 9600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek iounmap(zynq_devcfg_base); 9700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 9800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek return revision; 9900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek} 10000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 101ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmannstatic void __init zynq_init_late(void) 102ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmann{ 103ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmann zynq_core_pm_init(); 1040beb2bd36f6216f455363f47f8ba32fdf26667fbSoren Brinkmann zynq_pm_late_init(); 105ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmann} 106ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmann 10700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek/** 108889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek * zynq_init_machine - System specific initialization, intended to be 109889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek * called from board specific initialization. 110b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn */ 111889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simekstatic void __init zynq_init_machine(void) 112b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn{ 113bbcf071969b20f356877c8067986be0a2dcaa2aaViresh Kumar struct platform_device_info devinfo = { .name = "cpufreq-dt", }; 11400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek struct soc_device_attribute *soc_dev_attr; 11500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek struct soc_device *soc_dev; 11600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek struct device *parent = NULL; 117cd325295871fbd172340a73f323f6a19c0b0525dSoren Brinkmann 11800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 11900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek if (!soc_dev_attr) 12000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek goto out; 12100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 12200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek system_rev = zynq_get_revision(); 12300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 12400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek soc_dev_attr->family = kasprintf(GFP_KERNEL, "Xilinx Zynq"); 12500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek soc_dev_attr->revision = kasprintf(GFP_KERNEL, "0x%x", system_rev); 12600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%x", 12700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek zynq_slcr_get_device_id()); 12800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 12900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek soc_dev = soc_device_register(soc_dev_attr); 13000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek if (IS_ERR(soc_dev)) { 13100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek kfree(soc_dev_attr->family); 13200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek kfree(soc_dev_attr->revision); 13300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek kfree(soc_dev_attr->soc_id); 13400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek kfree(soc_dev_attr); 13500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek goto out; 13600f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek } 13700f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 13800f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek parent = soc_device_to_device(soc_dev); 13900f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek 14000f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simekout: 14100f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek /* 14200f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek * Finished with the static registrations now; fill in the missing 14300f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek * devices 14400f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek */ 14500f7dc636366f72474b1896f4990b3c086cd2c6dMichal Simek of_platform_populate(NULL, of_default_bus_match_table, NULL, parent); 1463e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcano 1473e8ceca6c76ec2d5ee47ece0420cf10d041cf58fDaniel Lezcano platform_device_register(&zynq_cpuidle_device); 148cd325295871fbd172340a73f323f6a19c0b0525dSoren Brinkmann platform_device_register_full(&devinfo); 149016f4dcae81e842a2b7dbfbc0fc9257f9f16e785Michal Simek 150016f4dcae81e842a2b7dbfbc0fc9257f9f16e785Michal Simek zynq_slcr_init(); 151b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn} 152b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn 153889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simekstatic void __init zynq_timer_init(void) 15403e07595febc4857b2b6ad756826f369c7628ec8Josh Cartwright{ 155016f4dcae81e842a2b7dbfbc0fc9257f9f16e785Michal Simek zynq_early_slcr_init(); 1566f69c7f21ce89409ccc54bd596434fa61d5b26ffSteffen Trumtrar 157b0504e39c27b00101c9c1fa2c58fd896ae0f64f5Michal Simek zynq_clock_init(); 1584a32c74e762236a53627536b9b9c1693d3073359Michal Simek of_clk_init(NULL); 159c5263bb8b7944f1e34b36b5ea8a9119fc48a31aeMichal Simek clocksource_of_init(); 16003e07595febc4857b2b6ad756826f369c7628ec8Josh Cartwright} 16103e07595febc4857b2b6ad756826f369c7628ec8Josh Cartwright 162732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simekstatic struct map_desc zynq_cortex_a9_scu_map __initdata = { 163732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek .length = SZ_256, 164732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek .type = MT_DEVICE, 165732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek}; 166732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek 167732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simekstatic void __init zynq_scu_map_io(void) 168732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek{ 169732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek unsigned long base; 170732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek 171732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek base = scu_a9_get_base(); 172732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek zynq_cortex_a9_scu_map.pfn = __phys_to_pfn(base); 173732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek /* Expected address is in vmalloc area that's why simple assign here */ 174732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek zynq_cortex_a9_scu_map.virtual = base; 175732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek iotable_init(&zynq_cortex_a9_scu_map, 1); 176732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek zynq_scu_base = (void __iomem *)base; 177732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek BUG_ON(!zynq_scu_base); 178732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek} 179732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek 180b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn/** 181889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek * zynq_map_io - Create memory mappings needed for early I/O. 182b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn */ 183889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simekstatic void __init zynq_map_io(void) 184b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn{ 185385f02b1696004461d89589e69ae7247081a74a2Josh Cartwright debug_ll_io_init(); 186732078c369f0b6ad9fe75c1faff721e91260bc5dMichal Simek zynq_scu_map_io(); 187b85a3ef4ac65169b65fd2fe9bec7912bbf475ba4John Linn} 1883d64b4496f5fd90618106555344205a522178c0cArnd Bergmann 1899f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmannstatic void __init zynq_irq_init(void) 1909f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann{ 1919f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann gic_arch_extn.flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND; 1929f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann irqchip_init(); 1939f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann} 1949f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann 195fe08bf9f46d6ae8e08de32d29234a2c928eebf8fVincent Stehléstatic void zynq_system_reset(enum reboot_mode mode, const char *cmd) 19696790f0a283976bc59f68657237293fe97b02334Michal Simek{ 19796790f0a283976bc59f68657237293fe97b02334Michal Simek zynq_slcr_system_reset(); 19896790f0a283976bc59f68657237293fe97b02334Michal Simek} 19996790f0a283976bc59f68657237293fe97b02334Michal Simek 200889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simekstatic const char * const zynq_dt_match[] = { 201e06f1a9ed7ebff170ba05d2606d079fb36c6a52dJosh Cartwright "xlnx,zynq-7000", 2023d64b4496f5fd90618106555344205a522178c0cArnd Bergmann NULL 2033d64b4496f5fd90618106555344205a522178c0cArnd Bergmann}; 2043d64b4496f5fd90618106555344205a522178c0cArnd Bergmann 205514a590847ff42dc00ba6c6165736128ad7730a8Arnd BergmannDT_MACHINE_START(XILINX_EP107, "Xilinx Zynq Platform") 206dcf9c7f9f4c5acd9ea72782263d2d76bbeadd9f7Russell King /* 64KB way size, 8-way associativity, parity disabled */ 2078097171e19bb69f3e2226827440b71ececa5d74fMichal Simek .l2c_aux_val = 0x00000000, 2088097171e19bb69f3e2226827440b71ececa5d74fMichal Simek .l2c_aux_mask = 0xffffffff, 209aa7eb2bb4e4a22e41bbe4612ff46e5885b13c33eMichal Simek .smp = smp_ops(zynq_smp_ops), 210889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek .map_io = zynq_map_io, 2119f4f5d26c66153bc63ea60f4f05dd6f19e9e7b48Soren Brinkmann .init_irq = zynq_irq_init, 212889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek .init_machine = zynq_init_machine, 213ae88b85e801ba77939b07eb9214f1d6542fa23f7Soren Brinkmann .init_late = zynq_init_late, 214889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek .init_time = zynq_timer_init, 215889faa88142801ee6bec2de2b8fb4c606076d52fMichal Simek .dt_compat = zynq_dt_match, 21646f5b96085b03f9e71a0134de77efc6a1f9d84c3Michal Simek .reserve = zynq_memory_init, 21796790f0a283976bc59f68657237293fe97b02334Michal Simek .restart = zynq_system_reset, 2183d64b4496f5fd90618106555344205a522178c0cArnd BergmannMACHINE_END 219