blob: 0114d4f878a18e5a2ade985699cd501aaa737626 [file] [log] [blame]
Alessandro Rubini28ad94e2009-07-02 19:06:47 +01001/*
2 * Copyright STMicroelectronics, 2007.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/device.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010022#include <linux/amba/bus.h>
Rabin Vincent3e3c62c2010-03-03 04:52:34 +010023#include <linux/platform_device.h>
Russell King35b47a4052011-11-28 10:48:02 +000024#include <linux/io.h>
Linus Walleij7c778522012-01-09 12:40:02 +010025#include <linux/slab.h>
26#include <linux/irq.h>
27#include <linux/dma-mapping.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010028#include <linux/irqchip.h>
Linus Walleij4a31bd22012-01-11 13:52:34 +010029#include <linux/platform_data/clk-nomadik.h>
Linus Walleijbb16bd92012-10-10 14:27:58 +020030#include <linux/platform_data/pinctrl-nomadik.h>
Linus Walleij1b542752013-01-05 01:00:59 +010031#include <linux/pinctrl/machine.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010032#include <linux/platform_data/clocksource-nomadik-mtu.h>
33#include <linux/of_irq.h>
34#include <linux/of_address.h>
35#include <linux/of_platform.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010036
37#include <mach/hardware.h>
38#include <mach/irqs.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010039#include <asm/mach/arch.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010040#include <asm/mach/map.h>
Linus Walleijf8635ab2013-01-05 00:29:31 +010041#include <asm/mach/time.h>
Alessandro Rubini28ad94e2009-07-02 19:06:47 +010042
Alessandro Rubini0b260fd2009-07-02 15:29:43 +010043#include <asm/cacheflush.h>
44#include <asm/hardware/cache-l2x0.h>
45
Linus Walleij61b38752011-11-28 12:20:53 +010046#include "cpu-8815.h"
Linus Walleijba327b12010-05-26 07:38:54 +010047
Linus Walleij056c78d2012-01-09 11:42:39 +010048/* The 8815 has 4 GPIO blocks, let's register them immediately */
49static resource_size_t __initdata cpu8815_gpio_base[] = {
50 NOMADIK_GPIO0_BASE,
51 NOMADIK_GPIO1_BASE,
52 NOMADIK_GPIO2_BASE,
53 NOMADIK_GPIO3_BASE,
54};
55
56static struct platform_device *
57cpu8815_add_gpio(int id, resource_size_t addr, int irq,
58 struct nmk_gpio_platform_data *pdata)
59{
60 struct resource resources[] = {
61 {
62 .start = addr,
63 .end = addr + 127,
64 .flags = IORESOURCE_MEM,
65 },
66 {
67 .start = irq,
68 .end = irq,
69 .flags = IORESOURCE_IRQ,
70 }
71 };
72
73 return platform_device_register_resndata(NULL, "gpio", id,
74 resources, ARRAY_SIZE(resources),
75 pdata, sizeof(*pdata));
76}
77
78void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
79 struct nmk_gpio_platform_data *pdata)
80{
81 int first = 0;
82 int i;
83
84 for (i = 0; i < num; i++, first += 32, irq++) {
85 pdata->first_gpio = first;
86 pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
87 pdata->num_gpio = 32;
88
89 cpu8815_add_gpio(i, base[i], irq, pdata);
90 }
91}
92
Linus Walleij1b542752013-01-05 01:00:59 +010093static unsigned long out_low[] = { PIN_OUTPUT_LOW };
94static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
95static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
96static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
97
98static struct pinctrl_map __initdata nhk8815_pinmap[] = {
99 PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
100 PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
101 /* Hog in MMC/SD card mux */
102 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
103 /* MCCLK */
104 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
105 /* MCCMD */
106 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
107 /* MCCMDDIR */
108 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
109 /* MCDAT3-0 */
110 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
111 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
112 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
113 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
114 /* MCDAT0DIR */
115 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
116 /* MCDAT31DIR */
117 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
118 /* MCMSFBCLK */
119 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
120 /* CD input GPIO */
121 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
122 /* CD bias drive */
123 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
124 /* I2C0 */
125 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
126 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
127 /* I2C1 */
128 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
129 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
130 /* I2C2 */
131 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
132 PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
133};
134
Linus Walleij2601ccf2012-08-10 00:43:40 +0200135static inline void
136cpu8815_add_pinctrl(struct device *parent, const char *name)
137{
138 struct platform_device_info pdevinfo = {
139 .parent = parent,
140 .name = name,
141 .id = -1,
142 };
143
Linus Walleij1b542752013-01-05 01:00:59 +0100144 pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
Linus Walleij2601ccf2012-08-10 00:43:40 +0200145 platform_device_register_full(&pdevinfo);
146}
147
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100148static int __init cpu8815_init(void)
149{
Linus Walleij056c78d2012-01-09 11:42:39 +0100150 struct nmk_gpio_platform_data pdata = {
151 /* No custom data yet */
152 };
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100153
Linus Walleij056c78d2012-01-09 11:42:39 +0100154 cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
155 IRQ_GPIO0, &pdata);
Linus Walleij2601ccf2012-08-10 00:43:40 +0200156 cpu8815_add_pinctrl(NULL, "pinctrl-stn8815");
Linus Walleij7c778522012-01-09 12:40:02 +0100157 amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0);
Linus Walleijb5111d92012-01-09 14:17:01 +0100158 amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100159 return 0;
160}
161arch_initcall(cpu8815_init);
162
Alessandro Rubini28ad94e2009-07-02 19:06:47 +0100163/* All SoC devices live in the same area (see hardware.h) */
164static struct map_desc nomadik_io_desc[] __initdata = {
165 {
166 .virtual = NOMADIK_IO_VIRTUAL,
167 .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL),
168 .length = NOMADIK_IO_SIZE,
169 .type = MT_DEVICE,
170 }
171 /* static ram and secured ram may be added later */
172};
173
174void __init cpu8815_map_io(void)
175{
176 iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
177}
178
179void __init cpu8815_init_irq(void)
180{
181 /* This modified VIC cell has two register blocks, at 0 and 0x20 */
182 vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0);
183 vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
Linus Walleijba327b12010-05-26 07:38:54 +0100184
185 /*
186 * Init clocks here so that they are available for system timer
187 * initialization.
188 */
Linus Walleij4a31bd22012-01-11 13:52:34 +0100189 nomadik_clk_init();
Alessandro Rubini28ad94e2009-07-02 19:06:47 +0100190}
191
192/*
193 * This function is called from the board init ("init_machine").
Alessandro Rubini28ad94e2009-07-02 19:06:47 +0100194 */
195 void __init cpu8815_platform_init(void)
196{
Alessandro Rubini0b260fd2009-07-02 15:29:43 +0100197#ifdef CONFIG_CACHE_L2X0
198 /* At full speed latency must be >=2, so 0x249 in low bits */
199 l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
200#endif
Alessandro Rubini28ad94e2009-07-02 19:06:47 +0100201 return;
202}
Russell King35b47a4052011-11-28 10:48:02 +0000203
204void cpu8815_restart(char mode, const char *cmd)
205{
206 void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
207
208 /* FIXME: use egpio when implemented */
209
210 /* Write anything to Reset status register */
211 writel(1, src_rstsr);
212}
Linus Walleijf8635ab2013-01-05 00:29:31 +0100213
214#ifdef CONFIG_OF
215
216/* Initial value for SRC control register: all timers use MXTAL/8 source */
217#define SRC_CR_INIT_MASK 0x00007fff
218#define SRC_CR_INIT_VAL 0x2aaa8000
219
220static void __init cpu8815_timer_init_of(void)
221{
222 struct device_node *mtu;
223 void __iomem *base;
224 int irq;
225 u32 src_cr;
226
227 /* We need this to be up now */
228 nomadik_clk_init();
229
230 mtu = of_find_node_by_path("/mtu0");
231 if (!mtu)
232 return;
233 base = of_iomap(mtu, 0);
234 if (WARN_ON(!base))
235 return;
236 irq = irq_of_parse_and_map(mtu, 0);
237
238 pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
239
240 /* Configure timer sources in "system reset controller" ctrl reg */
241 src_cr = readl(base);
242 src_cr &= SRC_CR_INIT_MASK;
243 src_cr |= SRC_CR_INIT_VAL;
244 writel(src_cr, base);
245
246 nmdk_timer_init(base, irq);
247}
248
249/* These are mostly to get the right device names for the clock lookups */
250static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
251 OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
252 "uart0", NULL),
253 OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
254 "uart1", NULL),
255 { /* sentinel */ },
256};
257
258static void __init cpu8815_init_of(void)
259{
260#ifdef CONFIG_CACHE_L2X0
261 /* At full speed latency must be >=2, so 0x249 in low bits */
262 l2x0_of_init(0x00730249, 0xfe000fff);
263#endif
264 of_platform_populate(NULL, of_default_bus_match_table,
265 cpu8815_auxdata_lookup, NULL);
266}
267
268static const char * cpu8815_board_compat[] = {
269 "calaosystems,usb-s8815",
270 NULL,
271};
272
273DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
274 .map_io = cpu8815_map_io,
275 .init_irq = irqchip_init,
276 .init_time = cpu8815_timer_init_of,
277 .init_machine = cpu8815_init_of,
278 .restart = cpu8815_restart,
279 .dt_compat = cpu8815_board_compat,
280MACHINE_END
281
282#endif