xref: /openbmc/linux/arch/arm/mach-nomadik/cpu-8815.c (revision 53d68af1)
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>
2528ad94ecSAlessandro Rubini 
260f332861SLinus Walleij #include <plat/gpio-nomadik.h>
2728ad94ecSAlessandro Rubini #include <mach/hardware.h>
2828ad94ecSAlessandro Rubini #include <mach/irqs.h>
2928ad94ecSAlessandro Rubini #include <asm/mach/map.h>
3028ad94ecSAlessandro Rubini #include <asm/hardware/vic.h>
3128ad94ecSAlessandro Rubini 
320b260fd4SAlessandro Rubini #include <asm/cacheflush.h>
330b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h>
340b260fd4SAlessandro Rubini 
35ba327b1eSLinus Walleij #include "clock.h"
3661b38753SLinus Walleij #include "cpu-8815.h"
37ba327b1eSLinus Walleij 
383e3c62caSRabin Vincent #define __MEM_4K_RESOURCE(x) \
393e3c62caSRabin Vincent 	.res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
403e3c62caSRabin Vincent 
412ec1d359SAlessandro Rubini /* The 8815 has 4 GPIO blocks, let's register them immediately */
423e3c62caSRabin Vincent 
433e3c62caSRabin Vincent #define GPIO_RESOURCE(block)						\
443e3c62caSRabin Vincent 	{								\
453e3c62caSRabin Vincent 		.start	= NOMADIK_GPIO##block##_BASE,			\
463e3c62caSRabin Vincent 		.end	= NOMADIK_GPIO##block##_BASE + SZ_4K - 1,	\
473e3c62caSRabin Vincent 		.flags	= IORESOURCE_MEM,				\
483e3c62caSRabin Vincent 	},								\
493e3c62caSRabin Vincent 	{								\
503e3c62caSRabin Vincent 		.start	= IRQ_GPIO##block,				\
513e3c62caSRabin Vincent 		.end	= IRQ_GPIO##block,				\
523e3c62caSRabin Vincent 		.flags	= IORESOURCE_IRQ,				\
533e3c62caSRabin Vincent 	}
543e3c62caSRabin Vincent 
553e3c62caSRabin Vincent #define GPIO_DEVICE(block)						\
563e3c62caSRabin Vincent 	{								\
573e3c62caSRabin Vincent 		.name 		= "gpio",				\
583e3c62caSRabin Vincent 		.id		= block,				\
593e3c62caSRabin Vincent 		.num_resources 	= 2,					\
603e3c62caSRabin Vincent 		.resource	= &cpu8815_gpio_resources[block * 2],	\
613e3c62caSRabin Vincent 		.dev = {						\
623e3c62caSRabin Vincent 			.platform_data = &cpu8815_gpio[block],		\
633e3c62caSRabin Vincent 		},							\
643e3c62caSRabin Vincent 	}
653e3c62caSRabin Vincent 
662ec1d359SAlessandro Rubini static struct nmk_gpio_platform_data cpu8815_gpio[] = {
672ec1d359SAlessandro Rubini 	{
682ec1d359SAlessandro Rubini 		.name = "GPIO-0-31",
692ec1d359SAlessandro Rubini 		.first_gpio = 0,
702ec1d359SAlessandro Rubini 		.first_irq = NOMADIK_GPIO_TO_IRQ(0),
712ec1d359SAlessandro Rubini 	}, {
722ec1d359SAlessandro Rubini 		.name = "GPIO-32-63",
732ec1d359SAlessandro Rubini 		.first_gpio = 32,
742ec1d359SAlessandro Rubini 		.first_irq = NOMADIK_GPIO_TO_IRQ(32),
752ec1d359SAlessandro Rubini 	}, {
762ec1d359SAlessandro Rubini 		.name = "GPIO-64-95",
772ec1d359SAlessandro Rubini 		.first_gpio = 64,
782ec1d359SAlessandro Rubini 		.first_irq = NOMADIK_GPIO_TO_IRQ(64),
792ec1d359SAlessandro Rubini 	}, {
802ec1d359SAlessandro Rubini 		.name = "GPIO-96-127", /* 124..127 not routed to pin */
812ec1d359SAlessandro Rubini 		.first_gpio = 96,
822ec1d359SAlessandro Rubini 		.first_irq = NOMADIK_GPIO_TO_IRQ(96),
832ec1d359SAlessandro Rubini 	}
842ec1d359SAlessandro Rubini };
852ec1d359SAlessandro Rubini 
863e3c62caSRabin Vincent static struct resource cpu8815_gpio_resources[] = {
873e3c62caSRabin Vincent 	GPIO_RESOURCE(0),
883e3c62caSRabin Vincent 	GPIO_RESOURCE(1),
893e3c62caSRabin Vincent 	GPIO_RESOURCE(2),
903e3c62caSRabin Vincent 	GPIO_RESOURCE(3),
913e3c62caSRabin Vincent };
922ec1d359SAlessandro Rubini 
933e3c62caSRabin Vincent static struct platform_device cpu8815_platform_gpio[] = {
943e3c62caSRabin Vincent 	GPIO_DEVICE(0),
953e3c62caSRabin Vincent 	GPIO_DEVICE(1),
963e3c62caSRabin Vincent 	GPIO_DEVICE(2),
973e3c62caSRabin Vincent 	GPIO_DEVICE(3),
982ec1d359SAlessandro Rubini };
992ec1d359SAlessandro Rubini 
10053d68af1SRussell King static AMBA_APB_DEVICE(cpu8815_amba_rng, "rng", 0, NOMADIK_RNG_BASE, { }, NULL);
101d2392ba0SAlessandro Rubini 
1023e3c62caSRabin Vincent static struct platform_device *platform_devs[] __initdata = {
1033e3c62caSRabin Vincent 	cpu8815_platform_gpio + 0,
1043e3c62caSRabin Vincent 	cpu8815_platform_gpio + 1,
1053e3c62caSRabin Vincent 	cpu8815_platform_gpio + 2,
1063e3c62caSRabin Vincent 	cpu8815_platform_gpio + 3,
1073e3c62caSRabin Vincent };
1083e3c62caSRabin Vincent 
1092ec1d359SAlessandro Rubini static struct amba_device *amba_devs[] __initdata = {
11053d68af1SRussell King 	&cpu8815_amba_rng_device
1112ec1d359SAlessandro Rubini };
1122ec1d359SAlessandro Rubini 
1132ec1d359SAlessandro Rubini static int __init cpu8815_init(void)
1142ec1d359SAlessandro Rubini {
1152ec1d359SAlessandro Rubini 	int i;
1162ec1d359SAlessandro Rubini 
1173e3c62caSRabin Vincent 	platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
1182ec1d359SAlessandro Rubini 	for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
1192ec1d359SAlessandro Rubini 		amba_device_register(amba_devs[i], &iomem_resource);
1202ec1d359SAlessandro Rubini 	return 0;
1212ec1d359SAlessandro Rubini }
1222ec1d359SAlessandro Rubini arch_initcall(cpu8815_init);
1232ec1d359SAlessandro Rubini 
12428ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */
12528ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = {
12628ad94ecSAlessandro Rubini 	{
12728ad94ecSAlessandro Rubini 		.virtual =	NOMADIK_IO_VIRTUAL,
12828ad94ecSAlessandro Rubini 		.pfn =		__phys_to_pfn(NOMADIK_IO_PHYSICAL),
12928ad94ecSAlessandro Rubini 		.length =	NOMADIK_IO_SIZE,
13028ad94ecSAlessandro Rubini 		.type = 	MT_DEVICE,
13128ad94ecSAlessandro Rubini 	}
13228ad94ecSAlessandro Rubini 	/* static ram and secured ram may be added later */
13328ad94ecSAlessandro Rubini };
13428ad94ecSAlessandro Rubini 
13528ad94ecSAlessandro Rubini void __init cpu8815_map_io(void)
13628ad94ecSAlessandro Rubini {
13728ad94ecSAlessandro Rubini 	iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
13828ad94ecSAlessandro Rubini }
13928ad94ecSAlessandro Rubini 
14028ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void)
14128ad94ecSAlessandro Rubini {
14228ad94ecSAlessandro Rubini 	/* This modified VIC cell has two register blocks, at 0 and 0x20 */
14328ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START +  0, ~0, 0);
14428ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
145ba327b1eSLinus Walleij 
146ba327b1eSLinus Walleij 	/*
147ba327b1eSLinus Walleij 	 * Init clocks here so that they are available for system timer
148ba327b1eSLinus Walleij 	 * initialization.
149ba327b1eSLinus Walleij 	 */
150ba327b1eSLinus Walleij 	clk_init();
15128ad94ecSAlessandro Rubini }
15228ad94ecSAlessandro Rubini 
15328ad94ecSAlessandro Rubini /*
15428ad94ecSAlessandro Rubini  * This function is called from the board init ("init_machine").
15528ad94ecSAlessandro Rubini  */
15628ad94ecSAlessandro Rubini  void __init cpu8815_platform_init(void)
15728ad94ecSAlessandro Rubini {
1580b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0
1590b260fd4SAlessandro Rubini 	/* At full speed latency must be >=2, so 0x249 in low bits */
1600b260fd4SAlessandro Rubini 	l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
1610b260fd4SAlessandro Rubini #endif
16228ad94ecSAlessandro Rubini 	 return;
16328ad94ecSAlessandro Rubini }
16435b47a40SRussell King 
16535b47a40SRussell King void cpu8815_restart(char mode, const char *cmd)
16635b47a40SRussell King {
16735b47a40SRussell King 	void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
16835b47a40SRussell King 
16935b47a40SRussell King 	/* FIXME: use egpio when implemented */
17035b47a40SRussell King 
17135b47a40SRussell King 	/* Write anything to Reset status register */
17235b47a40SRussell King 	writel(1, src_rstsr);
17335b47a40SRussell King }
174