arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / arm / mach-versatile / versatile_dt.c
blobc00ea4f77af68843ac43a85d63de8ee2f0f56572
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Versatile board support using the device tree
5 * Copyright (C) 2010 Secret Lab Technologies Ltd.
6 * Copyright (C) 2009 Jeremy Kerr <jeremy.kerr@canonical.com>
7 * Copyright (C) 2004 ARM Limited
8 * Copyright (C) 2000 Deep Blue Solutions Ltd
9 */
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/of.h>
14 #include <linux/of_address.h>
15 #include <linux/of_irq.h>
16 #include <linux/of_platform.h>
17 #include <linux/slab.h>
18 #include <linux/amba/bus.h>
19 #include <linux/amba/mmci.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/arch.h>
22 #include <asm/mach/map.h>
24 /* macro to get at MMIO space when running virtually */
25 #define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
26 #define __io_address(n) ((void __iomem __force *)IO_ADDRESS(n))
29 * ------------------------------------------------------------------------
30 * Versatile Registers
31 * ------------------------------------------------------------------------
33 #define VERSATILE_SYS_PCICTL_OFFSET 0x44
34 #define VERSATILE_SYS_MCI_OFFSET 0x48
37 * VERSATILE peripheral addresses
39 #define VERSATILE_MMCI0_BASE 0x10005000 /* MMC interface */
40 #define VERSATILE_MMCI1_BASE 0x1000B000 /* MMC Interface */
41 #define VERSATILE_SCTL_BASE 0x101E0000 /* System controller */
42 #define VERSATILE_IB2_BASE 0x24000000 /* IB2 module */
43 #define VERSATILE_IB2_CTL_BASE (VERSATILE_IB2_BASE + 0x03000000)
46 * System controller bit assignment
48 #define VERSATILE_REFCLK 0
49 #define VERSATILE_TIMCLK 1
51 #define VERSATILE_TIMER1_EnSel 15
52 #define VERSATILE_TIMER2_EnSel 17
53 #define VERSATILE_TIMER3_EnSel 19
54 #define VERSATILE_TIMER4_EnSel 21
56 static void __iomem *versatile_sys_base;
57 static void __iomem *versatile_ib2_ctrl;
59 unsigned int mmc_status(struct device *dev)
61 struct amba_device *adev = container_of(dev, struct amba_device, dev);
62 u32 mask;
64 if (adev->res.start == VERSATILE_MMCI0_BASE)
65 mask = 1;
66 else
67 mask = 2;
69 return readl(versatile_sys_base + VERSATILE_SYS_MCI_OFFSET) & mask;
72 static struct mmci_platform_data mmc0_plat_data = {
73 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
74 .status = mmc_status,
77 static struct mmci_platform_data mmc1_plat_data = {
78 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
79 .status = mmc_status,
83 * Lookup table for attaching a specific name and platform_data pointer to
84 * devices as they get created by of_platform_populate(). Ideally this table
85 * would not exist, but the current clock implementation depends on some devices
86 * having a specific name.
88 struct of_dev_auxdata versatile_auxdata_lookup[] __initdata = {
89 OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI0_BASE, "fpga:05", &mmc0_plat_data),
90 OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI1_BASE, "fpga:0b", &mmc1_plat_data),
94 static struct map_desc versatile_io_desc[] __initdata __maybe_unused = {
96 .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
97 .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
98 .length = SZ_4K * 9,
99 .type = MT_DEVICE
103 static void __init versatile_map_io(void)
105 debug_ll_io_init();
106 iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
109 static void __init versatile_init_early(void)
111 u32 val;
114 * set clock frequency:
115 * VERSATILE_REFCLK is 32KHz
116 * VERSATILE_TIMCLK is 1MHz
118 val = readl(__io_address(VERSATILE_SCTL_BASE));
119 writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
120 (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
121 (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
122 (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
123 __io_address(VERSATILE_SCTL_BASE));
126 static void __init versatile_dt_pci_init(void)
128 u32 val;
129 struct device_node *np;
130 struct property *newprop;
132 np = of_find_compatible_node(NULL, NULL, "arm,versatile-pci");
133 if (!np)
134 return;
136 /* Check if PCI backplane is detected */
137 val = readl(versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
138 if (val & 1) {
140 * Enable PCI accesses. Note that the documentaton is
141 * inconsistent whether or not this is needed, but the old
142 * driver had it so we will keep it.
144 writel(1, versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
145 goto out_put_node;
148 newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
149 if (!newprop)
150 goto out_put_node;
152 newprop->name = kstrdup("status", GFP_KERNEL);
153 newprop->value = kstrdup("disabled", GFP_KERNEL);
154 newprop->length = sizeof("disabled");
155 of_update_property(np, newprop);
157 pr_info("Not plugged into PCI backplane!\n");
159 out_put_node:
160 of_node_put(np);
163 static void __init versatile_dt_init(void)
165 struct device_node *np;
167 np = of_find_compatible_node(NULL, NULL, "arm,core-module-versatile");
168 if (np)
169 versatile_sys_base = of_iomap(np, 0);
170 WARN_ON(!versatile_sys_base);
172 versatile_ib2_ctrl = ioremap(VERSATILE_IB2_CTL_BASE, SZ_4K);
174 versatile_dt_pci_init();
176 of_platform_default_populate(NULL, versatile_auxdata_lookup, NULL);
179 static const char *const versatile_dt_match[] __initconst = {
180 "arm,versatile-ab",
181 "arm,versatile-pb",
182 NULL,
185 DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
186 .map_io = versatile_map_io,
187 .init_early = versatile_init_early,
188 .init_machine = versatile_dt_init,
189 .dt_compat = versatile_dt_match,
190 MACHINE_END