]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm/mach-keystone/keystone.c
155eb062e8d18f7a643f21c809ea5abf192020e9
[karo-tx-linux.git] / arch / arm / mach-keystone / keystone.c
1 /*
2  * Keystone2 based boards and SOC related code.
3  *
4  * Copyright 2013 Texas Instruments, Inc.
5  *      Cyril Chemparathy <cyril@ti.com>
6  *      Santosh Shilimkar <santosh.shillimkar@ti.com>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  */
12 #include <linux/io.h>
13 #include <linux/of.h>
14 #include <linux/init.h>
15 #include <linux/of_platform.h>
16 #include <linux/of_address.h>
17
18 #include <asm/setup.h>
19 #include <asm/mach/map.h>
20 #include <asm/mach/arch.h>
21 #include <asm/mach/time.h>
22 #include <asm/smp_plat.h>
23 #include <asm/memory.h>
24
25 #include "memory.h"
26
27 #include "keystone.h"
28
29 #define PLL_RESET_WRITE_KEY_MASK                0xffff0000
30 #define PLL_RESET_WRITE_KEY                     0x5a69
31 #define PLL_RESET                               BIT(16)
32
33 static void __iomem *keystone_rstctrl;
34
35 static void __init keystone_init(void)
36 {
37         struct device_node *node;
38
39         node = of_find_compatible_node(NULL, NULL, "ti,keystone-reset");
40         if (WARN_ON(!node))
41                 pr_warn("ti,keystone-reset node undefined\n");
42
43         keystone_rstctrl = of_iomap(node, 0);
44         if (WARN_ON(!keystone_rstctrl))
45                 pr_warn("ti,keystone-reset iomap error\n");
46
47         keystone_pm_runtime_init();
48         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
49 }
50
51 static phys_addr_t keystone_virt_to_idmap(unsigned long x)
52 {
53         return (phys_addr_t)(x) - CONFIG_PAGE_OFFSET + KEYSTONE_LOW_PHYS_START;
54 }
55
56 static void __init keystone_init_meminfo(void)
57 {
58         bool lpae = IS_ENABLED(CONFIG_ARM_LPAE);
59         bool pvpatch = IS_ENABLED(CONFIG_ARM_PATCH_PHYS_VIRT);
60         phys_addr_t offset = PHYS_OFFSET - KEYSTONE_LOW_PHYS_START;
61         phys_addr_t mem_start, mem_end;
62
63         BUG_ON(meminfo.nr_banks < 1);
64         mem_start = meminfo.bank[0].start;
65         mem_end = mem_start + meminfo.bank[0].size - 1;
66
67         /* nothing to do if we are running out of the <32-bit space */
68         if (mem_start >= KEYSTONE_LOW_PHYS_START &&
69             mem_end   <= KEYSTONE_LOW_PHYS_END)
70                 return;
71
72         if (!lpae || !pvpatch) {
73                 pr_crit("Enable %s%s%s to run outside 32-bit space\n",
74                       !lpae ? __stringify(CONFIG_ARM_LPAE) : "",
75                       (!lpae && !pvpatch) ? " and " : "",
76                       !pvpatch ? __stringify(CONFIG_ARM_PATCH_PHYS_VIRT) : "");
77         }
78
79         if (mem_start < KEYSTONE_HIGH_PHYS_START ||
80             mem_end   > KEYSTONE_HIGH_PHYS_END) {
81                 pr_crit("Invalid address space for memory (%08llx-%08llx)\n",
82                       (u64)mem_start, (u64)mem_end);
83         }
84
85         offset += KEYSTONE_HIGH_PHYS_START;
86         __pv_phys_pfn_offset = PFN_DOWN(offset);
87         __pv_offset = (offset - PAGE_OFFSET);
88
89         /* Populate the arch idmap hook */
90         arch_virt_to_idmap = keystone_virt_to_idmap;
91
92         pr_info("Switching to high address space at 0x%llx\n", (u64)offset);
93 }
94
95 static const char *keystone_match[] __initconst = {
96         "ti,keystone",
97         NULL,
98 };
99
100 void keystone_restart(enum reboot_mode mode, const char *cmd)
101 {
102         u32 val;
103
104         BUG_ON(!keystone_rstctrl);
105
106         /* Enable write access to RSTCTRL */
107         val = readl(keystone_rstctrl);
108         val &= PLL_RESET_WRITE_KEY_MASK;
109         val |= PLL_RESET_WRITE_KEY;
110         writel(val, keystone_rstctrl);
111
112         /* Reset the SOC */
113         val = readl(keystone_rstctrl);
114         val &= ~PLL_RESET;
115         writel(val, keystone_rstctrl);
116 }
117
118 DT_MACHINE_START(KEYSTONE, "Keystone")
119 #if defined(CONFIG_ZONE_DMA) && defined(CONFIG_ARM_LPAE)
120         .dma_zone_size  = SZ_2G,
121 #endif
122         .smp            = smp_ops(keystone_smp_ops),
123         .init_machine   = keystone_init,
124         .dt_compat      = keystone_match,
125         .restart        = keystone_restart,
126         .init_meminfo   = keystone_init_meminfo,
127 MACHINE_END