xref: /openbmc/linux/arch/arm/mach-nomadik/cpu-8815.c (revision bb16bd9b)
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>
284a31bd28SLinus Walleij #include <linux/platform_data/clk-nomadik.h>
29bb16bd9bSLinus Walleij #include <linux/platform_data/pinctrl-nomadik.h>
3028ad94ecSAlessandro Rubini 
3128ad94ecSAlessandro Rubini #include <mach/hardware.h>
3228ad94ecSAlessandro Rubini #include <mach/irqs.h>
3328ad94ecSAlessandro Rubini #include <asm/mach/map.h>
3428ad94ecSAlessandro Rubini #include <asm/hardware/vic.h>
3528ad94ecSAlessandro Rubini 
360b260fd4SAlessandro Rubini #include <asm/cacheflush.h>
370b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h>
380b260fd4SAlessandro Rubini 
3961b38753SLinus Walleij #include "cpu-8815.h"
40ba327b1eSLinus Walleij 
41056c78d3SLinus Walleij /* The 8815 has 4 GPIO blocks, let's register them immediately */
42056c78d3SLinus Walleij static resource_size_t __initdata cpu8815_gpio_base[] = {
43056c78d3SLinus Walleij 	NOMADIK_GPIO0_BASE,
44056c78d3SLinus Walleij 	NOMADIK_GPIO1_BASE,
45056c78d3SLinus Walleij 	NOMADIK_GPIO2_BASE,
46056c78d3SLinus Walleij 	NOMADIK_GPIO3_BASE,
47056c78d3SLinus Walleij };
48056c78d3SLinus Walleij 
49056c78d3SLinus Walleij static struct platform_device *
50056c78d3SLinus Walleij cpu8815_add_gpio(int id, resource_size_t addr, int irq,
51056c78d3SLinus Walleij 		 struct nmk_gpio_platform_data *pdata)
52056c78d3SLinus Walleij {
53056c78d3SLinus Walleij 	struct resource resources[] = {
54056c78d3SLinus Walleij 		{
55056c78d3SLinus Walleij 			.start	= addr,
56056c78d3SLinus Walleij 			.end	= addr + 127,
57056c78d3SLinus Walleij 			.flags	= IORESOURCE_MEM,
58056c78d3SLinus Walleij 		},
59056c78d3SLinus Walleij 		{
60056c78d3SLinus Walleij 			.start	= irq,
61056c78d3SLinus Walleij 			.end	= irq,
62056c78d3SLinus Walleij 			.flags	= IORESOURCE_IRQ,
63056c78d3SLinus Walleij 		}
64056c78d3SLinus Walleij 	};
65056c78d3SLinus Walleij 
66056c78d3SLinus Walleij 	return platform_device_register_resndata(NULL, "gpio", id,
67056c78d3SLinus Walleij 				resources, ARRAY_SIZE(resources),
68056c78d3SLinus Walleij 				pdata, sizeof(*pdata));
69056c78d3SLinus Walleij }
70056c78d3SLinus Walleij 
71056c78d3SLinus Walleij void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
72056c78d3SLinus Walleij 		       struct nmk_gpio_platform_data *pdata)
73056c78d3SLinus Walleij {
74056c78d3SLinus Walleij 	int first = 0;
75056c78d3SLinus Walleij 	int i;
76056c78d3SLinus Walleij 
77056c78d3SLinus Walleij 	for (i = 0; i < num; i++, first += 32, irq++) {
78056c78d3SLinus Walleij 		pdata->first_gpio = first;
79056c78d3SLinus Walleij 		pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
80056c78d3SLinus Walleij 		pdata->num_gpio = 32;
81056c78d3SLinus Walleij 
82056c78d3SLinus Walleij 		cpu8815_add_gpio(i, base[i], irq, pdata);
83056c78d3SLinus Walleij 	}
84056c78d3SLinus Walleij }
85056c78d3SLinus Walleij 
862601ccfeSLinus Walleij static inline void
872601ccfeSLinus Walleij cpu8815_add_pinctrl(struct device *parent, const char *name)
882601ccfeSLinus Walleij {
892601ccfeSLinus Walleij 	struct platform_device_info pdevinfo = {
902601ccfeSLinus Walleij 		.parent = parent,
912601ccfeSLinus Walleij 		.name = name,
922601ccfeSLinus Walleij 		.id = -1,
932601ccfeSLinus Walleij 	};
942601ccfeSLinus Walleij 
952601ccfeSLinus Walleij 	platform_device_register_full(&pdevinfo);
962601ccfeSLinus Walleij }
972601ccfeSLinus Walleij 
982ec1d359SAlessandro Rubini static int __init cpu8815_init(void)
992ec1d359SAlessandro Rubini {
100056c78d3SLinus Walleij 	struct nmk_gpio_platform_data pdata = {
101056c78d3SLinus Walleij 		/* No custom data yet */
102056c78d3SLinus Walleij 	};
1032ec1d359SAlessandro Rubini 
104056c78d3SLinus Walleij 	cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
105056c78d3SLinus Walleij 			  IRQ_GPIO0, &pdata);
1062601ccfeSLinus Walleij 	cpu8815_add_pinctrl(NULL, "pinctrl-stn8815");
1077c77852dSLinus Walleij 	amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0);
108b5111d9eSLinus Walleij 	amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0);
1092ec1d359SAlessandro Rubini 	return 0;
1102ec1d359SAlessandro Rubini }
1112ec1d359SAlessandro Rubini arch_initcall(cpu8815_init);
1122ec1d359SAlessandro Rubini 
11328ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */
11428ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = {
11528ad94ecSAlessandro Rubini 	{
11628ad94ecSAlessandro Rubini 		.virtual =	NOMADIK_IO_VIRTUAL,
11728ad94ecSAlessandro Rubini 		.pfn =		__phys_to_pfn(NOMADIK_IO_PHYSICAL),
11828ad94ecSAlessandro Rubini 		.length =	NOMADIK_IO_SIZE,
11928ad94ecSAlessandro Rubini 		.type = 	MT_DEVICE,
12028ad94ecSAlessandro Rubini 	}
12128ad94ecSAlessandro Rubini 	/* static ram and secured ram may be added later */
12228ad94ecSAlessandro Rubini };
12328ad94ecSAlessandro Rubini 
12428ad94ecSAlessandro Rubini void __init cpu8815_map_io(void)
12528ad94ecSAlessandro Rubini {
12628ad94ecSAlessandro Rubini 	iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
12728ad94ecSAlessandro Rubini }
12828ad94ecSAlessandro Rubini 
12928ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void)
13028ad94ecSAlessandro Rubini {
13128ad94ecSAlessandro Rubini 	/* This modified VIC cell has two register blocks, at 0 and 0x20 */
13228ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START +  0, ~0, 0);
13328ad94ecSAlessandro Rubini 	vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
134ba327b1eSLinus Walleij 
135ba327b1eSLinus Walleij 	/*
136ba327b1eSLinus Walleij 	 * Init clocks here so that they are available for system timer
137ba327b1eSLinus Walleij 	 * initialization.
138ba327b1eSLinus Walleij 	 */
1394a31bd28SLinus Walleij 	nomadik_clk_init();
14028ad94ecSAlessandro Rubini }
14128ad94ecSAlessandro Rubini 
14228ad94ecSAlessandro Rubini /*
14328ad94ecSAlessandro Rubini  * This function is called from the board init ("init_machine").
14428ad94ecSAlessandro Rubini  */
14528ad94ecSAlessandro Rubini  void __init cpu8815_platform_init(void)
14628ad94ecSAlessandro Rubini {
1470b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0
1480b260fd4SAlessandro Rubini 	/* At full speed latency must be >=2, so 0x249 in low bits */
1490b260fd4SAlessandro Rubini 	l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
1500b260fd4SAlessandro Rubini #endif
15128ad94ecSAlessandro Rubini 	 return;
15228ad94ecSAlessandro Rubini }
15335b47a40SRussell King 
15435b47a40SRussell King void cpu8815_restart(char mode, const char *cmd)
15535b47a40SRussell King {
15635b47a40SRussell King 	void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
15735b47a40SRussell King 
15835b47a40SRussell King 	/* FIXME: use egpio when implemented */
15935b47a40SRussell King 
16035b47a40SRussell King 	/* Write anything to Reset status register */
16135b47a40SRussell King 	writel(1, src_rstsr);
16235b47a40SRussell King }
163