xref: /openbmc/linux/arch/arm/mach-nomadik/cpu-8815.c (revision 1b542757)
128ad94ecSAlessandro Rubini /*
228ad94ecSAlessandro Rubini  * Copyright STMicroelectronics, 2007.
328ad94ecSAlessandro Rubini  *
428ad94ecSAlessandro Rubini  *  This program is free software; you can redistribute it and/or modify
528ad94ecSAlessandro Rubini  *  it under the terms of the GNU General Public License as published by
628ad94ecSAlessandro Rubini  *  the Free Software Foundation; either version 2 of the License, or
728ad94ecSAlessandro Rubini  *  (at your option) any later version.
828ad94ecSAlessandro Rubini  *
928ad94ecSAlessandro Rubini  *  This program is distributed in the hope that it will be useful,
1028ad94ecSAlessandro Rubini  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1128ad94ecSAlessandro Rubini  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1228ad94ecSAlessandro Rubini  *  GNU General Public License for more details.
1328ad94ecSAlessandro Rubini  *
1428ad94ecSAlessandro Rubini  *  You should have received a copy of the GNU General Public License
1528ad94ecSAlessandro Rubini  *  along with this program; if not, write to the Free Software
1628ad94ecSAlessandro Rubini  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1728ad94ecSAlessandro Rubini  */
1828ad94ecSAlessandro Rubini 
1928ad94ecSAlessandro Rubini #include <linux/types.h>
2028ad94ecSAlessandro Rubini #include <linux/init.h>
2128ad94ecSAlessandro Rubini #include <linux/device.h>
222ec1d359SAlessandro Rubini #include <linux/amba/bus.h>
233e3c62caSRabin Vincent #include <linux/platform_device.h>
2435b47a40SRussell King #include <linux/io.h>
257c77852dSLinus Walleij #include <linux/slab.h>
267c77852dSLinus Walleij #include <linux/irq.h>
277c77852dSLinus Walleij #include <linux/dma-mapping.h>
28f8635abdSLinus Walleij #include <linux/irqchip.h>
294a31bd28SLinus Walleij #include <linux/platform_data/clk-nomadik.h>
30bb16bd9bSLinus Walleij #include <linux/platform_data/pinctrl-nomadik.h>
311b542757SLinus Walleij #include <linux/pinctrl/machine.h>
32f8635abdSLinus Walleij #include <linux/platform_data/clocksource-nomadik-mtu.h>
33f8635abdSLinus Walleij #include <linux/of_irq.h>
34f8635abdSLinus Walleij #include <linux/of_address.h>
35f8635abdSLinus Walleij #include <linux/of_platform.h>
3628ad94ecSAlessandro Rubini 
3728ad94ecSAlessandro Rubini #include <mach/hardware.h>
3828ad94ecSAlessandro Rubini #include <mach/irqs.h>
39f8635abdSLinus Walleij #include <asm/mach/arch.h>
4028ad94ecSAlessandro Rubini #include <asm/mach/map.h>
41f8635abdSLinus Walleij #include <asm/mach/time.h>
4228ad94ecSAlessandro Rubini 
430b260fd4SAlessandro Rubini #include <asm/cacheflush.h>
440b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h>
450b260fd4SAlessandro Rubini 
4661b38753SLinus Walleij #include "cpu-8815.h"
47ba327b1eSLinus Walleij 
48056c78d3SLinus Walleij /* The 8815 has 4 GPIO blocks, let's register them immediately */
49056c78d3SLinus Walleij static resource_size_t __initdata cpu8815_gpio_base[] = {
50056c78d3SLinus Walleij 	NOMADIK_GPIO0_BASE,
51056c78d3SLinus Walleij 	NOMADIK_GPIO1_BASE,
52056c78d3SLinus Walleij 	NOMADIK_GPIO2_BASE,
53056c78d3SLinus Walleij 	NOMADIK_GPIO3_BASE,
54056c78d3SLinus Walleij };
55056c78d3SLinus Walleij 
56056c78d3SLinus Walleij static struct platform_device *
57056c78d3SLinus Walleij cpu8815_add_gpio(int id, resource_size_t addr, int irq,
58056c78d3SLinus Walleij 		 struct nmk_gpio_platform_data *pdata)
59056c78d3SLinus Walleij {
60056c78d3SLinus Walleij 	struct resource resources[] = {
61056c78d3SLinus Walleij 		{
62056c78d3SLinus Walleij 			.start	= addr,
63056c78d3SLinus Walleij 			.end	= addr + 127,
64056c78d3SLinus Walleij 			.flags	= IORESOURCE_MEM,
65056c78d3SLinus Walleij 		},
66056c78d3SLinus Walleij 		{
67056c78d3SLinus Walleij 			.start	= irq,
68056c78d3SLinus Walleij 			.end	= irq,
69056c78d3SLinus Walleij 			.flags	= IORESOURCE_IRQ,
70056c78d3SLinus Walleij 		}
71056c78d3SLinus Walleij 	};
72056c78d3SLinus Walleij 
73056c78d3SLinus Walleij 	return platform_device_register_resndata(NULL, "gpio", id,
74056c78d3SLinus Walleij 				resources, ARRAY_SIZE(resources),
75056c78d3SLinus Walleij 				pdata, sizeof(*pdata));
76056c78d3SLinus Walleij }
77056c78d3SLinus Walleij 
78056c78d3SLinus Walleij void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
79056c78d3SLinus Walleij 		       struct nmk_gpio_platform_data *pdata)
80056c78d3SLinus Walleij {
81056c78d3SLinus Walleij 	int first = 0;
82056c78d3SLinus Walleij 	int i;
83056c78d3SLinus Walleij 
84056c78d3SLinus Walleij 	for (i = 0; i < num; i++, first += 32, irq++) {
85056c78d3SLinus Walleij 		pdata->first_gpio = first;
86056c78d3SLinus Walleij 		pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
87056c78d3SLinus Walleij 		pdata->num_gpio = 32;
88056c78d3SLinus Walleij 
89056c78d3SLinus Walleij 		cpu8815_add_gpio(i, base[i], irq, pdata);
90056c78d3SLinus Walleij 	}
91056c78d3SLinus Walleij }
92056c78d3SLinus Walleij 
931b542757SLinus Walleij static unsigned long out_low[] = { PIN_OUTPUT_LOW };
941b542757SLinus Walleij static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
951b542757SLinus Walleij static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
961b542757SLinus Walleij static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
971b542757SLinus Walleij 
981b542757SLinus Walleij static struct pinctrl_map __initdata nhk8815_pinmap[] = {
991b542757SLinus Walleij 	PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
1001b542757SLinus Walleij 	PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
1011b542757SLinus Walleij 	/* Hog in MMC/SD card mux */
1021b542757SLinus Walleij 	PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
1031b542757SLinus Walleij 	/* MCCLK */
1041b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
1051b542757SLinus Walleij 	/* MCCMD */
1061b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
1071b542757SLinus Walleij 	/* MCCMDDIR */
1081b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
1091b542757SLinus Walleij 	/* MCDAT3-0 */
1101b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
1111b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
1121b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
1131b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
1141b542757SLinus Walleij 	/* MCDAT0DIR */
1151b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
1161b542757SLinus Walleij 	/* MCDAT31DIR */
1171b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
1181b542757SLinus Walleij 	/* MCMSFBCLK */
1191b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
1201b542757SLinus Walleij 	/* CD input GPIO */
1211b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
1221b542757SLinus Walleij 	/* CD bias drive */
1231b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
1241b542757SLinus Walleij 	/* I2C0 */
1251b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
1261b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
1271b542757SLinus Walleij 	/* I2C1 */
1281b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
1291b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
1301b542757SLinus Walleij 	/* I2C2 */
1311b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
1321b542757SLinus Walleij 	PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
1331b542757SLinus Walleij };
1341b542757SLinus Walleij 
1352601ccfeSLinus Walleij static inline void
1362601ccfeSLinus Walleij cpu8815_add_pinctrl(struct device *parent, const char *name)
1372601ccfeSLinus Walleij {
1382601ccfeSLinus Walleij 	struct platform_device_info pdevinfo = {
1392601ccfeSLinus Walleij 		.parent = parent,
1402601ccfeSLinus Walleij 		.name = name,
1412601ccfeSLinus Walleij 		.id = -1,
1422601ccfeSLinus Walleij 	};
1432601ccfeSLinus Walleij 
1441b542757SLinus Walleij 	pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
1452601ccfeSLinus Walleij 	platform_device_register_full(&pdevinfo);
1462601ccfeSLinus Walleij }
1472601ccfeSLinus Walleij 
1482ec1d359SAlessandro Rubini static int __init cpu8815_init(void)
1492ec1d359SAlessandro Rubini {
150056c78d3SLinus Walleij 	struct nmk_gpio_platform_data pdata = {
151056c78d3SLinus Walleij 		/* No custom data yet */
152056c78d3SLinus Walleij 	};
1532ec1d359SAlessandro Rubini 
154056c78d3SLinus Walleij 	cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
155056c78d3SLinus Walleij 			  IRQ_GPIO0, &pdata);
1562601ccfeSLinus Walleij 	cpu8815_add_pinctrl(NULL, "pinctrl-stn8815");
1577c77852dSLinus Walleij 	amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0);
158b5111d9eSLinus Walleij 	amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0);
1592ec1d359SAlessandro Rubini 	return 0;
1602ec1d359SAlessandro Rubini }
1612ec1d359SAlessandro Rubini arch_initcall(cpu8815_init);
1622ec1d359SAlessandro Rubini 
16328ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */
16428ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = {
16528ad94ecSAlessandro Rubini 	{
16628ad94ecSAlessandro Rubini 		.virtual =	NOMADIK_IO_VIRTUAL,
16728ad94ecSAlessandro Rubini 		.pfn =		__phys_to_pfn(NOMADIK_IO_PHYSICAL),
16828ad94ecSAlessandro Rubini 		.length =	NOMADIK_IO_SIZE,
16928ad94ecSAlessandro Rubini 		.type = 	MT_DEVICE,
17028ad94ecSAlessandro Rubini 	}
17128ad94ecSAlessandro Rubini 	/* static ram and secured ram may be added later */
17228ad94ecSAlessandro Rubini };
17328ad94ecSAlessandro Rubini 
17428ad94ecSAlessandro Rubini void __init cpu8815_map_io(void)
17528ad94ecSAlessandro Rubini {
17628ad94ecSAlessandro Rubini 	iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
17728ad94ecSAlessandro Rubini }
17828ad94ecSAlessandro Rubini 
17928ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void)
18028ad94ecSAlessandro Rubini {
18128ad94ecSAlessandro Rubini 	/* This modified VIC cell has two register blocks, at 0 and 0x20 */
18228ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START +  0, ~0, 0);
18328ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
184ba327b1eSLinus Walleij 
185ba327b1eSLinus Walleij 	/*
186ba327b1eSLinus Walleij 	 * Init clocks here so that they are available for system timer
187ba327b1eSLinus Walleij 	 * initialization.
188ba327b1eSLinus Walleij 	 */
1894a31bd28SLinus Walleij 	nomadik_clk_init();
19028ad94ecSAlessandro Rubini }
19128ad94ecSAlessandro Rubini 
19228ad94ecSAlessandro Rubini /*
19328ad94ecSAlessandro Rubini  * This function is called from the board init ("init_machine").
19428ad94ecSAlessandro Rubini  */
19528ad94ecSAlessandro Rubini  void __init cpu8815_platform_init(void)
19628ad94ecSAlessandro Rubini {
1970b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0
1980b260fd4SAlessandro Rubini 	/* At full speed latency must be >=2, so 0x249 in low bits */
1990b260fd4SAlessandro Rubini 	l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
2000b260fd4SAlessandro Rubini #endif
20128ad94ecSAlessandro Rubini 	 return;
20228ad94ecSAlessandro Rubini }
20335b47a40SRussell King 
20435b47a40SRussell King void cpu8815_restart(char mode, const char *cmd)
20535b47a40SRussell King {
20635b47a40SRussell King 	void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
20735b47a40SRussell King 
20835b47a40SRussell King 	/* FIXME: use egpio when implemented */
20935b47a40SRussell King 
21035b47a40SRussell King 	/* Write anything to Reset status register */
21135b47a40SRussell King 	writel(1, src_rstsr);
21235b47a40SRussell King }
213f8635abdSLinus Walleij 
214f8635abdSLinus Walleij #ifdef CONFIG_OF
215f8635abdSLinus Walleij 
216f8635abdSLinus Walleij /* Initial value for SRC control register: all timers use MXTAL/8 source */
217f8635abdSLinus Walleij #define SRC_CR_INIT_MASK	0x00007fff
218f8635abdSLinus Walleij #define SRC_CR_INIT_VAL		0x2aaa8000
219f8635abdSLinus Walleij 
220f8635abdSLinus Walleij static void __init cpu8815_timer_init_of(void)
221f8635abdSLinus Walleij {
222f8635abdSLinus Walleij 	struct device_node *mtu;
223f8635abdSLinus Walleij 	void __iomem *base;
224f8635abdSLinus Walleij 	int irq;
225f8635abdSLinus Walleij 	u32 src_cr;
226f8635abdSLinus Walleij 
227f8635abdSLinus Walleij 	/* We need this to be up now */
228f8635abdSLinus Walleij 	nomadik_clk_init();
229f8635abdSLinus Walleij 
230f8635abdSLinus Walleij 	mtu = of_find_node_by_path("/mtu0");
231f8635abdSLinus Walleij 	if (!mtu)
232f8635abdSLinus Walleij 		return;
233f8635abdSLinus Walleij 	base = of_iomap(mtu, 0);
234f8635abdSLinus Walleij 	if (WARN_ON(!base))
235f8635abdSLinus Walleij 		return;
236f8635abdSLinus Walleij 	irq = irq_of_parse_and_map(mtu, 0);
237f8635abdSLinus Walleij 
238f8635abdSLinus Walleij 	pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
239f8635abdSLinus Walleij 
240f8635abdSLinus Walleij 	/* Configure timer sources in "system reset controller" ctrl reg */
241f8635abdSLinus Walleij 	src_cr = readl(base);
242f8635abdSLinus Walleij 	src_cr &= SRC_CR_INIT_MASK;
243f8635abdSLinus Walleij 	src_cr |= SRC_CR_INIT_VAL;
244f8635abdSLinus Walleij 	writel(src_cr, base);
245f8635abdSLinus Walleij 
246f8635abdSLinus Walleij 	nmdk_timer_init(base, irq);
247f8635abdSLinus Walleij }
248f8635abdSLinus Walleij 
249f8635abdSLinus Walleij /* These are mostly to get the right device names for the clock lookups */
250f8635abdSLinus Walleij static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
251f8635abdSLinus Walleij 	OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
252f8635abdSLinus Walleij 		"uart0", NULL),
253f8635abdSLinus Walleij 	OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
254f8635abdSLinus Walleij 		"uart1", NULL),
255f8635abdSLinus Walleij 	{ /* sentinel */ },
256f8635abdSLinus Walleij };
257f8635abdSLinus Walleij 
258f8635abdSLinus Walleij static void __init cpu8815_init_of(void)
259f8635abdSLinus Walleij {
260f8635abdSLinus Walleij #ifdef CONFIG_CACHE_L2X0
261f8635abdSLinus Walleij 	/* At full speed latency must be >=2, so 0x249 in low bits */
262f8635abdSLinus Walleij 	l2x0_of_init(0x00730249, 0xfe000fff);
263f8635abdSLinus Walleij #endif
264f8635abdSLinus Walleij 	of_platform_populate(NULL, of_default_bus_match_table,
265f8635abdSLinus Walleij 			cpu8815_auxdata_lookup, NULL);
266f8635abdSLinus Walleij }
267f8635abdSLinus Walleij 
268f8635abdSLinus Walleij static const char * cpu8815_board_compat[] = {
269f8635abdSLinus Walleij 	"calaosystems,usb-s8815",
270f8635abdSLinus Walleij 	NULL,
271f8635abdSLinus Walleij };
272f8635abdSLinus Walleij 
273f8635abdSLinus Walleij DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
274f8635abdSLinus Walleij 	.map_io		= cpu8815_map_io,
275f8635abdSLinus Walleij 	.init_irq	= irqchip_init,
276f8635abdSLinus Walleij 	.init_time	= cpu8815_timer_init_of,
277f8635abdSLinus Walleij 	.init_machine	= cpu8815_init_of,
278f8635abdSLinus Walleij 	.restart	= cpu8815_restart,
279f8635abdSLinus Walleij 	.dt_compat      = cpu8815_board_compat,
280f8635abdSLinus Walleij MACHINE_END
281f8635abdSLinus Walleij 
282f8635abdSLinus Walleij #endif
283