blob: 772a7cf2010e78a7f3c6aa32f3ae49fe263355a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-integrator/integrator_cp.c
3 *
4 * Copyright (C) 2003 Deep Blue Solutions Ltd
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
Linus Walleij6ef297f2009-09-22 14:29:36 +010011#include <linux/amba/mmci.h>
Russell Kingfced80c2008-09-06 12:10:45 +010012#include <linux/io.h>
Rob Herring44fa72d2014-05-29 16:44:27 -050013#include <linux/irqchip.h>
Linus Walleij4980f9b2012-09-06 09:08:24 +010014#include <linux/of_irq.h>
15#include <linux/of_address.h>
Linus Walleij4672cdd2012-09-06 09:08:47 +010016#include <linux/of_platform.h>
Linus Walleija79528e2014-02-13 21:35:07 +010017#include <linux/sched_clock.h>
Linus Walleijbdb249f2016-08-30 12:23:55 +020018#include <linux/regmap.h>
19#include <linux/mfd/syscon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/mach/arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/mach/map.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Walleij1b1ef752014-02-13 21:26:24 +010024#include "hardware.h"
Linus Walleijbb4dbef2013-06-16 02:44:27 +020025#include "cm.h"
Russell King98c672c2010-05-22 18:18:57 +010026#include "common.h"
27
Linus Walleijbdb249f2016-08-30 12:23:55 +020028/* Base address to the core module header */
29static struct regmap *cm_map;
Linus Walleije6fae082012-11-04 21:03:02 +010030/* Base address to the CP controller */
31static void __iomem *intcp_con_base;
32
Linus Walleijbdb249f2016-08-30 12:23:55 +020033#define CM_COUNTER_OFFSET 0x28
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
36 * Logical Physical
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 * f1400000 14000000 Interrupt controller
38 * f1600000 16000000 UART 0
Russell Kingda7ba952010-01-17 19:59:58 +000039 * fca00000 ca000000 SIC
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 */
41
Arnd Bergmann060fd1b2013-02-14 13:50:57 +010042static struct map_desc intcp_io_desc[] __initdata __maybe_unused = {
Deepak Saxenac8d27292005-10-28 15:19:10 +010043 {
Deepak Saxenac8d27292005-10-28 15:19:10 +010044 .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
45 .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
46 .length = SZ_4K,
47 .type = MT_DEVICE
48 }, {
49 .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
50 .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
51 .length = SZ_4K,
52 .type = MT_DEVICE
53 }, {
Russell Kingda7ba952010-01-17 19:59:58 +000054 .virtual = IO_ADDRESS(INTEGRATOR_CP_SIC_BASE),
55 .pfn = __phys_to_pfn(INTEGRATOR_CP_SIC_BASE),
Deepak Saxenac8d27292005-10-28 15:19:10 +010056 .length = SZ_4K,
57 .type = MT_DEVICE
Deepak Saxenac8d27292005-10-28 15:19:10 +010058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
61static void __init intcp_map_io(void)
62{
63 iotable_init(intcp_io_desc, ARRAY_SIZE(intcp_io_desc));
64}
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 * It seems that the card insertion interrupt remains active after
68 * we've acknowledged it. We therefore ignore the interrupt, and
69 * rely on reading it from the SIC. This also means that we must
70 * clear the latched interrupt.
71 */
72static unsigned int mmc_status(struct device *dev)
73{
Arnd Bergmannb7a3f8d2012-09-14 20:16:39 +000074 unsigned int status = readl(__io_address(0xca000000 + 4));
Linus Walleije6fae082012-11-04 21:03:02 +010075 writel(8, intcp_con_base + 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 return status & 8;
78}
79
Linus Walleij6ef297f2009-09-22 14:29:36 +010080static struct mmci_platform_data mmc_data = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
82 .status = mmc_status,
Russell King7fb2bbf2009-07-09 15:15:12 +010083 .gpio_wp = -1,
84 .gpio_cd = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
Linus Walleija79528e2014-02-13 21:35:07 +010087static u64 notrace intcp_read_sched_clock(void)
88{
Linus Walleijbdb249f2016-08-30 12:23:55 +020089 unsigned int val;
90
91 /* MMIO so discard return code */
92 regmap_read(cm_map, CM_COUNTER_OFFSET, &val);
93 return val;
Linus Walleija79528e2014-02-13 21:35:07 +010094}
95
Russell Kingc735c982011-01-11 13:00:04 +000096static void __init intcp_init_early(void)
97{
Linus Walleijbdb249f2016-08-30 12:23:55 +020098 cm_map = syscon_regmap_lookup_by_compatible("arm,core-module-integrator");
99 if (IS_ERR(cm_map))
100 return;
Linus Walleija79528e2014-02-13 21:35:07 +0100101 sched_clock_register(intcp_read_sched_clock, 32, 24000000);
Russell Kingc735c982011-01-11 13:00:04 +0000102}
103
Linus Walleij4980f9b2012-09-06 09:08:24 +0100104static void __init intcp_init_irq_of(void)
105{
Linus Walleijbb4dbef2013-06-16 02:44:27 +0200106 cm_init();
Rob Herring44fa72d2014-05-29 16:44:27 -0500107 irqchip_init();
Linus Walleij4980f9b2012-09-06 09:08:24 +0100108}
109
Linus Walleij4672cdd2012-09-06 09:08:47 +0100110/*
111 * For the Device Tree, add in the UART, MMC and CLCD specifics as AUXDATA
112 * and enforce the bus names since these are used for clock lookups.
113 */
114static struct of_dev_auxdata intcp_auxdata_lookup[] __initdata = {
Linus Walleij4672cdd2012-09-06 09:08:47 +0100115 OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_CP_MMC_BASE,
116 "mmci", &mmc_data),
Linus Walleij4672cdd2012-09-06 09:08:47 +0100117 { /* sentinel */ },
118};
119
Linus Walleijdf366802013-10-10 18:24:58 +0200120static const struct of_device_id intcp_syscon_match[] = {
121 { .compatible = "arm,integrator-cp-syscon"},
122 { },
123};
124
Linus Walleij4672cdd2012-09-06 09:08:47 +0100125static void __init intcp_init_of(void)
126{
Linus Walleij64100a02012-11-02 01:20:43 +0100127 struct device_node *cpcon;
Linus Walleij64100a02012-11-02 01:20:43 +0100128
Linus Walleij11f93232014-06-24 14:08:07 +0200129 cpcon = of_find_matching_node(NULL, intcp_syscon_match);
Linus Walleij64100a02012-11-02 01:20:43 +0100130 if (!cpcon)
131 return;
132
133 intcp_con_base = of_iomap(cpcon, 0);
134 if (!intcp_con_base)
135 return;
136
Kefeng Wang435ebcb2016-06-01 14:53:05 +0800137 of_platform_default_populate(NULL, intcp_auxdata_lookup, NULL);
Linus Walleij4672cdd2012-09-06 09:08:47 +0100138}
139
Linus Walleij4980f9b2012-09-06 09:08:24 +0100140static const char * intcp_dt_board_compat[] = {
141 "arm,integrator-cp",
142 NULL,
143};
144
145DT_MACHINE_START(INTEGRATOR_CP_DT, "ARM Integrator/CP (Device Tree)")
146 .reserve = integrator_reserve,
147 .map_io = intcp_map_io,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100148 .init_early = intcp_init_early,
149 .init_irq = intcp_init_irq_of,
Linus Walleij4672cdd2012-09-06 09:08:47 +0100150 .init_machine = intcp_init_of,
Linus Walleij4980f9b2012-09-06 09:08:24 +0100151 .dt_compat = intcp_dt_board_compat,
152MACHINE_END