xref: /openbmc/linux/arch/arm/mach-nomadik/cpu-8815.c (revision 056c78d3)
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 
3853d68af1SRussell King static AMBA_APB_DEVICE(cpu8815_amba_rng, "rng", 0, NOMADIK_RNG_BASE, { }, NULL);
39d2392ba0SAlessandro Rubini 
402ec1d359SAlessandro Rubini static struct amba_device *amba_devs[] __initdata = {
4153d68af1SRussell King 	&cpu8815_amba_rng_device
422ec1d359SAlessandro Rubini };
432ec1d359SAlessandro Rubini 
44056c78d3SLinus Walleij /* The 8815 has 4 GPIO blocks, let's register them immediately */
45056c78d3SLinus Walleij static resource_size_t __initdata cpu8815_gpio_base[] = {
46056c78d3SLinus Walleij 	NOMADIK_GPIO0_BASE,
47056c78d3SLinus Walleij 	NOMADIK_GPIO1_BASE,
48056c78d3SLinus Walleij 	NOMADIK_GPIO2_BASE,
49056c78d3SLinus Walleij 	NOMADIK_GPIO3_BASE,
50056c78d3SLinus Walleij };
51056c78d3SLinus Walleij 
52056c78d3SLinus Walleij static struct platform_device *
53056c78d3SLinus Walleij cpu8815_add_gpio(int id, resource_size_t addr, int irq,
54056c78d3SLinus Walleij 		 struct nmk_gpio_platform_data *pdata)
55056c78d3SLinus Walleij {
56056c78d3SLinus Walleij 	struct resource resources[] = {
57056c78d3SLinus Walleij 		{
58056c78d3SLinus Walleij 			.start	= addr,
59056c78d3SLinus Walleij 			.end	= addr + 127,
60056c78d3SLinus Walleij 			.flags	= IORESOURCE_MEM,
61056c78d3SLinus Walleij 		},
62056c78d3SLinus Walleij 		{
63056c78d3SLinus Walleij 			.start	= irq,
64056c78d3SLinus Walleij 			.end	= irq,
65056c78d3SLinus Walleij 			.flags	= IORESOURCE_IRQ,
66056c78d3SLinus Walleij 		}
67056c78d3SLinus Walleij 	};
68056c78d3SLinus Walleij 
69056c78d3SLinus Walleij 	return platform_device_register_resndata(NULL, "gpio", id,
70056c78d3SLinus Walleij 				resources, ARRAY_SIZE(resources),
71056c78d3SLinus Walleij 				pdata, sizeof(*pdata));
72056c78d3SLinus Walleij }
73056c78d3SLinus Walleij 
74056c78d3SLinus Walleij void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
75056c78d3SLinus Walleij 		       struct nmk_gpio_platform_data *pdata)
76056c78d3SLinus Walleij {
77056c78d3SLinus Walleij 	int first = 0;
78056c78d3SLinus Walleij 	int i;
79056c78d3SLinus Walleij 
80056c78d3SLinus Walleij 	for (i = 0; i < num; i++, first += 32, irq++) {
81056c78d3SLinus Walleij 		pdata->first_gpio = first;
82056c78d3SLinus Walleij 		pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
83056c78d3SLinus Walleij 		pdata->num_gpio = 32;
84056c78d3SLinus Walleij 
85056c78d3SLinus Walleij 		cpu8815_add_gpio(i, base[i], irq, pdata);
86056c78d3SLinus Walleij 	}
87056c78d3SLinus Walleij }
88056c78d3SLinus Walleij 
892ec1d359SAlessandro Rubini static int __init cpu8815_init(void)
902ec1d359SAlessandro Rubini {
912ec1d359SAlessandro Rubini 	int i;
92056c78d3SLinus Walleij 	struct nmk_gpio_platform_data pdata = {
93056c78d3SLinus Walleij 		/* No custom data yet */
94056c78d3SLinus Walleij 	};
952ec1d359SAlessandro Rubini 
96056c78d3SLinus Walleij 	cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
97056c78d3SLinus Walleij 			  IRQ_GPIO0, &pdata);
982ec1d359SAlessandro Rubini 	for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
992ec1d359SAlessandro Rubini 		amba_device_register(amba_devs[i], &iomem_resource);
1002ec1d359SAlessandro Rubini 	return 0;
1012ec1d359SAlessandro Rubini }
1022ec1d359SAlessandro Rubini arch_initcall(cpu8815_init);
1032ec1d359SAlessandro Rubini 
10428ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */
10528ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = {
10628ad94ecSAlessandro Rubini 	{
10728ad94ecSAlessandro Rubini 		.virtual =	NOMADIK_IO_VIRTUAL,
10828ad94ecSAlessandro Rubini 		.pfn =		__phys_to_pfn(NOMADIK_IO_PHYSICAL),
10928ad94ecSAlessandro Rubini 		.length =	NOMADIK_IO_SIZE,
11028ad94ecSAlessandro Rubini 		.type = 	MT_DEVICE,
11128ad94ecSAlessandro Rubini 	}
11228ad94ecSAlessandro Rubini 	/* static ram and secured ram may be added later */
11328ad94ecSAlessandro Rubini };
11428ad94ecSAlessandro Rubini 
11528ad94ecSAlessandro Rubini void __init cpu8815_map_io(void)
11628ad94ecSAlessandro Rubini {
11728ad94ecSAlessandro Rubini 	iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
11828ad94ecSAlessandro Rubini }
11928ad94ecSAlessandro Rubini 
12028ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void)
12128ad94ecSAlessandro Rubini {
12228ad94ecSAlessandro Rubini 	/* This modified VIC cell has two register blocks, at 0 and 0x20 */
12328ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START +  0, ~0, 0);
12428ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
125ba327b1eSLinus Walleij 
126ba327b1eSLinus Walleij 	/*
127ba327b1eSLinus Walleij 	 * Init clocks here so that they are available for system timer
128ba327b1eSLinus Walleij 	 * initialization.
129ba327b1eSLinus Walleij 	 */
130ba327b1eSLinus Walleij 	clk_init();
13128ad94ecSAlessandro Rubini }
13228ad94ecSAlessandro Rubini 
13328ad94ecSAlessandro Rubini /*
13428ad94ecSAlessandro Rubini  * This function is called from the board init ("init_machine").
13528ad94ecSAlessandro Rubini  */
13628ad94ecSAlessandro Rubini  void __init cpu8815_platform_init(void)
13728ad94ecSAlessandro Rubini {
1380b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0
1390b260fd4SAlessandro Rubini 	/* At full speed latency must be >=2, so 0x249 in low bits */
1400b260fd4SAlessandro Rubini 	l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
1410b260fd4SAlessandro Rubini #endif
14228ad94ecSAlessandro Rubini 	 return;
14328ad94ecSAlessandro Rubini }
14435b47a40SRussell King 
14535b47a40SRussell King void cpu8815_restart(char mode, const char *cmd)
14635b47a40SRussell King {
14735b47a40SRussell King 	void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
14835b47a40SRussell King 
14935b47a40SRussell King 	/* FIXME: use egpio when implemented */
15035b47a40SRussell King 
15135b47a40SRussell King 	/* Write anything to Reset status register */
15235b47a40SRussell King 	writel(1, src_rstsr);
15335b47a40SRussell King }
154