2 * R-Car Generation 2 support
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Magnus Damm
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/clk/shmobile.h>
18 #include <linux/clocksource.h>
19 #include <linux/device.h>
20 #include <linux/dma-contiguous.h>
22 #include <linux/kernel.h>
23 #include <linux/of_fdt.h>
24 #include <asm/mach/arch.h>
26 #include "rcar-gen2.h"
28 #define MODEMR 0xe6160060
30 u32 rcar_gen2_read_mode_pins(void)
33 static bool mode_valid;
36 void __iomem *modemr = ioremap_nocache(MODEMR, 4);
38 mode = ioread32(modemr);
49 void __init rcar_gen2_timer_init(void)
51 #if defined(CONFIG_ARM_ARCH_TIMER) || defined(CONFIG_COMMON_CLK)
52 u32 mode = rcar_gen2_read_mode_pins();
54 #ifdef CONFIG_ARM_ARCH_TIMER
59 /* At Linux boot time the r8a7790 arch timer comes up
60 * with the counter disabled. Moreover, it may also report
61 * a potentially incorrect fixed 13 MHz frequency. To be
62 * correct these registers need to be updated to use the
63 * frequency EXTAL / 2 which can be determined by the MD pins.
66 switch (mode & (MD(14) | MD(13))) {
81 /* The arch timer frequency equals EXTAL / 2 */
82 freq = extal_mhz * (1000000 / 2);
84 /* Remap "armgcnt address map" space */
85 base = ioremap(0xe6080000, PAGE_SIZE);
88 * Update the timer if it is either not running, or is not at the
89 * right frequency. The timer is only configurable in secure mode
90 * so this avoids an abort if the loader started the timer and
91 * entered the kernel in non-secure mode.
94 if ((ioread32(base + CNTCR) & 1) == 0 ||
95 ioread32(base + CNTFID0) != freq) {
96 /* Update registers with correct frequency */
97 iowrite32(freq, base + CNTFID0);
98 asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
100 /* make sure arch timer is started by setting bit 0 of CNTCR */
101 iowrite32(1, base + CNTCR);
105 #endif /* CONFIG_ARM_ARCH_TIMER */
107 #ifdef CONFIG_COMMON_CLK
108 rcar_gen2_clocks_init(mode);
110 clocksource_of_init();
113 struct memory_reserve_config {
118 static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname,
119 int depth, void *data)
121 const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
122 const __be32 *reg, *endp;
124 struct memory_reserve_config *mrc = data;
125 u64 lpae_start = 1ULL << 32;
127 /* We are scanning "memory" nodes only */
128 if (type == NULL || strcmp(type, "memory"))
131 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
133 reg = of_get_flat_dt_prop(node, "reg", &l);
137 endp = reg + (l / sizeof(__be32));
138 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
141 base = dt_mem_next_cell(dt_root_addr_cells, ®);
142 size = dt_mem_next_cell(dt_root_size_cells, ®);
144 if (base >= lpae_start)
147 if ((base + size) >= lpae_start)
148 size = lpae_start - base;
150 if (size < mrc->reserved)
153 if (base < mrc->base)
156 /* keep the area at top near the 32-bit legacy limit */
157 mrc->base = base + size - mrc->reserved;
158 mrc->size = mrc->reserved;
164 struct cma *rcar_gen2_dma_contiguous;
166 void __init rcar_gen2_reserve(void)
168 struct memory_reserve_config mrc;
170 /* reserve 256 MiB at the top of the physical legacy 32-bit space */
171 memset(&mrc, 0, sizeof(mrc));
172 mrc.reserved = SZ_256M;
174 of_scan_flat_dt(rcar_gen2_scan_mem, &mrc);
175 #ifdef CONFIG_DMA_CMA
177 dma_contiguous_reserve_area(mrc.size, mrc.base, 0,
178 &rcar_gen2_dma_contiguous, true);