Christoffer Dall | 3d28a18 | 2012-11-17 22:46:19 -0500 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Architected Timer setup for SMDK5250 board based on EXYNOS5 |
| 4 | * |
| 5 | * Copyright (C) 2012 Christoffer Dall <cdall@cs.columbia.edu> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <config.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/arch/spl.h> |
| 30 | |
| 31 | #include "setup.h" |
| 32 | |
| 33 | #define ARM_GICV2_DIST_CTRL 0x00 |
| 34 | #define ARM_GICV2_DIST_TYPE 0x04 |
| 35 | #define ARM_GICV2_DIST_SEC_REG 0x80 |
| 36 | |
| 37 | #define ARM_GICV2_CPU_CTRL 0x00 |
| 38 | |
| 39 | #define ARM_GICV2_ICCPMR 0x04 |
| 40 | |
| 41 | static unsigned long read_mpidr(void) |
| 42 | { |
| 43 | unsigned long val; |
| 44 | asm volatile("mrc p15, 0, %0, c0, c0, 5": "=r" (val)); |
| 45 | return val; |
| 46 | } |
| 47 | |
| 48 | static unsigned long read_nsacr(void) |
| 49 | { |
| 50 | unsigned long val; |
| 51 | asm volatile("mrc p15, 0, %0, c1, c1, 2": "=r" (val)); |
| 52 | return val; |
| 53 | } |
| 54 | |
| 55 | static void write_nsacr(unsigned long val) |
| 56 | { |
| 57 | asm volatile("mcr p15, 0, %0, c1, c1, 2": : "r" (val)); |
| 58 | } |
| 59 | |
| 60 | void non_secure_init(void) |
| 61 | { |
| 62 | unsigned long addr, type, num_regs; |
| 63 | unsigned long nsacr, ctrl; |
| 64 | int i; |
| 65 | |
| 66 | addr = EXYNOS5_GIC_DIST_BASE; |
| 67 | type = readl(addr + ARM_GICV2_DIST_TYPE); |
| 68 | num_regs = (type & 0x1f) + 1; |
| 69 | |
| 70 | /* Set all interrupts to be non-secure */ |
| 71 | addr = EXYNOS5_GIC_DIST_BASE + ARM_GICV2_DIST_SEC_REG; |
| 72 | for (i = 0; i < num_regs; i++) { |
| 73 | writel(0xffffffff, addr); |
| 74 | addr += 4; |
| 75 | } |
| 76 | |
| 77 | /* Set GIC priority mask bit [7] = 1 */ |
| 78 | addr = EXYNOS5_GIC_CPU_BASE; |
| 79 | writel(0x80, addr + ARM_GICV2_ICCPMR); |
| 80 | |
| 81 | /* Set NSACR to allow coprocessor access from non-secure */ |
| 82 | nsacr = read_nsacr(); |
| 83 | nsacr |= 0x43fff; |
| 84 | write_nsacr(nsacr); |
| 85 | |
| 86 | /* Enable group 1 interrupts on CPU interface */ |
| 87 | addr = EXYNOS5_GIC_CPU_BASE + ARM_GICV2_CPU_CTRL; |
| 88 | ctrl = readl(addr); |
| 89 | writel(ctrl | 0x1, addr); |
| 90 | |
| 91 | /* Disable group 0 interrupts and enable group 1 interrupts on Dist */ |
| 92 | addr = EXYNOS5_GIC_DIST_BASE + ARM_GICV2_DIST_CTRL; |
| 93 | ctrl = readl(addr); |
| 94 | ctrl = (ctrl & ~0x1) | 0x2; |
| 95 | writel(ctrl | 0x1, addr); |
| 96 | } |