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> 2828ad94ecSAlessandro Rubini 290f332861SLinus Walleij #include <plat/gpio-nomadik.h> 3028ad94ecSAlessandro Rubini #include <mach/hardware.h> 3128ad94ecSAlessandro Rubini #include <mach/irqs.h> 3228ad94ecSAlessandro Rubini #include <asm/mach/map.h> 3328ad94ecSAlessandro Rubini #include <asm/hardware/vic.h> 3428ad94ecSAlessandro Rubini 350b260fd4SAlessandro Rubini #include <asm/cacheflush.h> 360b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h> 370b260fd4SAlessandro Rubini 38ba327b1eSLinus Walleij #include "clock.h" 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 862ec1d359SAlessandro Rubini static int __init cpu8815_init(void) 872ec1d359SAlessandro Rubini { 88056c78d3SLinus Walleij struct nmk_gpio_platform_data pdata = { 89056c78d3SLinus Walleij /* No custom data yet */ 90056c78d3SLinus Walleij }; 912ec1d359SAlessandro Rubini 92056c78d3SLinus Walleij cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base), 93056c78d3SLinus Walleij IRQ_GPIO0, &pdata); 947c77852dSLinus Walleij amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0); 952ec1d359SAlessandro Rubini return 0; 962ec1d359SAlessandro Rubini } 972ec1d359SAlessandro Rubini arch_initcall(cpu8815_init); 982ec1d359SAlessandro Rubini 9928ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */ 10028ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = { 10128ad94ecSAlessandro Rubini { 10228ad94ecSAlessandro Rubini .virtual = NOMADIK_IO_VIRTUAL, 10328ad94ecSAlessandro Rubini .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), 10428ad94ecSAlessandro Rubini .length = NOMADIK_IO_SIZE, 10528ad94ecSAlessandro Rubini .type = MT_DEVICE, 10628ad94ecSAlessandro Rubini } 10728ad94ecSAlessandro Rubini /* static ram and secured ram may be added later */ 10828ad94ecSAlessandro Rubini }; 10928ad94ecSAlessandro Rubini 11028ad94ecSAlessandro Rubini void __init cpu8815_map_io(void) 11128ad94ecSAlessandro Rubini { 11228ad94ecSAlessandro Rubini iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); 11328ad94ecSAlessandro Rubini } 11428ad94ecSAlessandro Rubini 11528ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void) 11628ad94ecSAlessandro Rubini { 11728ad94ecSAlessandro Rubini /* This modified VIC cell has two register blocks, at 0 and 0x20 */ 11828ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0); 11928ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0); 120ba327b1eSLinus Walleij 121ba327b1eSLinus Walleij /* 122ba327b1eSLinus Walleij * Init clocks here so that they are available for system timer 123ba327b1eSLinus Walleij * initialization. 124ba327b1eSLinus Walleij */ 125ba327b1eSLinus Walleij clk_init(); 12628ad94ecSAlessandro Rubini } 12728ad94ecSAlessandro Rubini 12828ad94ecSAlessandro Rubini /* 12928ad94ecSAlessandro Rubini * This function is called from the board init ("init_machine"). 13028ad94ecSAlessandro Rubini */ 13128ad94ecSAlessandro Rubini void __init cpu8815_platform_init(void) 13228ad94ecSAlessandro Rubini { 1330b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0 1340b260fd4SAlessandro Rubini /* At full speed latency must be >=2, so 0x249 in low bits */ 1350b260fd4SAlessandro Rubini l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff); 1360b260fd4SAlessandro Rubini #endif 13728ad94ecSAlessandro Rubini return; 13828ad94ecSAlessandro Rubini } 13935b47a40SRussell King 14035b47a40SRussell King void cpu8815_restart(char mode, const char *cmd) 14135b47a40SRussell King { 14235b47a40SRussell King void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); 14335b47a40SRussell King 14435b47a40SRussell King /* FIXME: use egpio when implemented */ 14535b47a40SRussell King 14635b47a40SRussell King /* Write anything to Reset status register */ 14735b47a40SRussell King writel(1, src_rstsr); 14835b47a40SRussell King } 149