1*d7445676SArnd Bergmann // SPDX-License-Identifier: GPL-2.0-only
2*d7445676SArnd Bergmann /*
3*d7445676SArnd Bergmann * Copyright (C) 2003 Deep Blue Solutions Ltd
4*d7445676SArnd Bergmann */
5*d7445676SArnd Bergmann #include <linux/kernel.h>
6*d7445676SArnd Bergmann #include <linux/amba/mmci.h>
7*d7445676SArnd Bergmann #include <linux/io.h>
8*d7445676SArnd Bergmann #include <linux/irqchip.h>
9*d7445676SArnd Bergmann #include <linux/of_irq.h>
10*d7445676SArnd Bergmann #include <linux/of_address.h>
11*d7445676SArnd Bergmann #include <linux/of_platform.h>
12*d7445676SArnd Bergmann #include <linux/sched_clock.h>
13*d7445676SArnd Bergmann #include <linux/regmap.h>
14*d7445676SArnd Bergmann #include <linux/mfd/syscon.h>
15*d7445676SArnd Bergmann
16*d7445676SArnd Bergmann #include <asm/mach/arch.h>
17*d7445676SArnd Bergmann #include <asm/mach/map.h>
18*d7445676SArnd Bergmann
19*d7445676SArnd Bergmann #include "integrator-hardware.h"
20*d7445676SArnd Bergmann #include "integrator-cm.h"
21*d7445676SArnd Bergmann #include "integrator.h"
22*d7445676SArnd Bergmann
23*d7445676SArnd Bergmann /* Base address to the core module header */
24*d7445676SArnd Bergmann static struct regmap *cm_map;
25*d7445676SArnd Bergmann /* Base address to the CP controller */
26*d7445676SArnd Bergmann static void __iomem *intcp_con_base;
27*d7445676SArnd Bergmann
28*d7445676SArnd Bergmann #define CM_COUNTER_OFFSET 0x28
29*d7445676SArnd Bergmann
30*d7445676SArnd Bergmann /*
31*d7445676SArnd Bergmann * Logical Physical
32*d7445676SArnd Bergmann * f1400000 14000000 Interrupt controller
33*d7445676SArnd Bergmann * f1600000 16000000 UART 0
34*d7445676SArnd Bergmann * fca00000 ca000000 SIC
35*d7445676SArnd Bergmann */
36*d7445676SArnd Bergmann
37*d7445676SArnd Bergmann static struct map_desc intcp_io_desc[] __initdata __maybe_unused = {
38*d7445676SArnd Bergmann {
39*d7445676SArnd Bergmann .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
40*d7445676SArnd Bergmann .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
41*d7445676SArnd Bergmann .length = SZ_4K,
42*d7445676SArnd Bergmann .type = MT_DEVICE
43*d7445676SArnd Bergmann }, {
44*d7445676SArnd Bergmann .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
45*d7445676SArnd Bergmann .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
46*d7445676SArnd Bergmann .length = SZ_4K,
47*d7445676SArnd Bergmann .type = MT_DEVICE
48*d7445676SArnd Bergmann }, {
49*d7445676SArnd Bergmann .virtual = IO_ADDRESS(INTEGRATOR_CP_SIC_BASE),
50*d7445676SArnd Bergmann .pfn = __phys_to_pfn(INTEGRATOR_CP_SIC_BASE),
51*d7445676SArnd Bergmann .length = SZ_4K,
52*d7445676SArnd Bergmann .type = MT_DEVICE
53*d7445676SArnd Bergmann }
54*d7445676SArnd Bergmann };
55*d7445676SArnd Bergmann
intcp_map_io(void)56*d7445676SArnd Bergmann static void __init intcp_map_io(void)
57*d7445676SArnd Bergmann {
58*d7445676SArnd Bergmann iotable_init(intcp_io_desc, ARRAY_SIZE(intcp_io_desc));
59*d7445676SArnd Bergmann }
60*d7445676SArnd Bergmann
61*d7445676SArnd Bergmann /*
62*d7445676SArnd Bergmann * It seems that the card insertion interrupt remains active after
63*d7445676SArnd Bergmann * we've acknowledged it. We therefore ignore the interrupt, and
64*d7445676SArnd Bergmann * rely on reading it from the SIC. This also means that we must
65*d7445676SArnd Bergmann * clear the latched interrupt.
66*d7445676SArnd Bergmann */
mmc_status(struct device * dev)67*d7445676SArnd Bergmann static unsigned int mmc_status(struct device *dev)
68*d7445676SArnd Bergmann {
69*d7445676SArnd Bergmann unsigned int status = readl(__io_address(0xca000000 + 4));
70*d7445676SArnd Bergmann writel(8, intcp_con_base + 8);
71*d7445676SArnd Bergmann
72*d7445676SArnd Bergmann return status & 8;
73*d7445676SArnd Bergmann }
74*d7445676SArnd Bergmann
75*d7445676SArnd Bergmann static struct mmci_platform_data mmc_data = {
76*d7445676SArnd Bergmann .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
77*d7445676SArnd Bergmann .status = mmc_status,
78*d7445676SArnd Bergmann };
79*d7445676SArnd Bergmann
intcp_read_sched_clock(void)80*d7445676SArnd Bergmann static u64 notrace intcp_read_sched_clock(void)
81*d7445676SArnd Bergmann {
82*d7445676SArnd Bergmann unsigned int val;
83*d7445676SArnd Bergmann
84*d7445676SArnd Bergmann /* MMIO so discard return code */
85*d7445676SArnd Bergmann regmap_read(cm_map, CM_COUNTER_OFFSET, &val);
86*d7445676SArnd Bergmann return val;
87*d7445676SArnd Bergmann }
88*d7445676SArnd Bergmann
intcp_init_early(void)89*d7445676SArnd Bergmann static void __init intcp_init_early(void)
90*d7445676SArnd Bergmann {
91*d7445676SArnd Bergmann cm_map = syscon_regmap_lookup_by_compatible("arm,core-module-integrator");
92*d7445676SArnd Bergmann if (IS_ERR(cm_map))
93*d7445676SArnd Bergmann return;
94*d7445676SArnd Bergmann sched_clock_register(intcp_read_sched_clock, 32, 24000000);
95*d7445676SArnd Bergmann }
96*d7445676SArnd Bergmann
intcp_init_irq_of(void)97*d7445676SArnd Bergmann static void __init intcp_init_irq_of(void)
98*d7445676SArnd Bergmann {
99*d7445676SArnd Bergmann cm_init();
100*d7445676SArnd Bergmann irqchip_init();
101*d7445676SArnd Bergmann }
102*d7445676SArnd Bergmann
103*d7445676SArnd Bergmann /*
104*d7445676SArnd Bergmann * For the Device Tree, add in the UART, MMC and CLCD specifics as AUXDATA
105*d7445676SArnd Bergmann * and enforce the bus names since these are used for clock lookups.
106*d7445676SArnd Bergmann */
107*d7445676SArnd Bergmann static struct of_dev_auxdata intcp_auxdata_lookup[] __initdata = {
108*d7445676SArnd Bergmann OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_CP_MMC_BASE,
109*d7445676SArnd Bergmann "mmci", &mmc_data),
110*d7445676SArnd Bergmann { /* sentinel */ },
111*d7445676SArnd Bergmann };
112*d7445676SArnd Bergmann
113*d7445676SArnd Bergmann static const struct of_device_id intcp_syscon_match[] = {
114*d7445676SArnd Bergmann { .compatible = "arm,integrator-cp-syscon"},
115*d7445676SArnd Bergmann { },
116*d7445676SArnd Bergmann };
117*d7445676SArnd Bergmann
intcp_init_of(void)118*d7445676SArnd Bergmann static void __init intcp_init_of(void)
119*d7445676SArnd Bergmann {
120*d7445676SArnd Bergmann struct device_node *cpcon;
121*d7445676SArnd Bergmann
122*d7445676SArnd Bergmann cpcon = of_find_matching_node(NULL, intcp_syscon_match);
123*d7445676SArnd Bergmann if (!cpcon)
124*d7445676SArnd Bergmann return;
125*d7445676SArnd Bergmann
126*d7445676SArnd Bergmann intcp_con_base = of_iomap(cpcon, 0);
127*d7445676SArnd Bergmann if (!intcp_con_base)
128*d7445676SArnd Bergmann return;
129*d7445676SArnd Bergmann
130*d7445676SArnd Bergmann of_platform_default_populate(NULL, intcp_auxdata_lookup, NULL);
131*d7445676SArnd Bergmann }
132*d7445676SArnd Bergmann
133*d7445676SArnd Bergmann static const char * intcp_dt_board_compat[] = {
134*d7445676SArnd Bergmann "arm,integrator-cp",
135*d7445676SArnd Bergmann NULL,
136*d7445676SArnd Bergmann };
137*d7445676SArnd Bergmann
138*d7445676SArnd Bergmann DT_MACHINE_START(INTEGRATOR_CP_DT, "ARM Integrator/CP (Device Tree)")
139*d7445676SArnd Bergmann .reserve = integrator_reserve,
140*d7445676SArnd Bergmann .map_io = intcp_map_io,
141*d7445676SArnd Bergmann .init_early = intcp_init_early,
142*d7445676SArnd Bergmann .init_irq = intcp_init_irq_of,
143*d7445676SArnd Bergmann .init_machine = intcp_init_of,
144*d7445676SArnd Bergmann .dt_compat = intcp_dt_board_compat,
145*d7445676SArnd Bergmann MACHINE_END
146