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> 31f8635abdSLinus Walleij #include <linux/platform_data/clocksource-nomadik-mtu.h> 32f8635abdSLinus Walleij #include <linux/of_irq.h> 33f8635abdSLinus Walleij #include <linux/of_address.h> 34f8635abdSLinus Walleij #include <linux/of_platform.h> 3528ad94ecSAlessandro Rubini 3628ad94ecSAlessandro Rubini #include <mach/hardware.h> 3728ad94ecSAlessandro Rubini #include <mach/irqs.h> 38f8635abdSLinus Walleij #include <asm/mach/arch.h> 3928ad94ecSAlessandro Rubini #include <asm/mach/map.h> 40f8635abdSLinus Walleij #include <asm/mach/time.h> 4128ad94ecSAlessandro Rubini 420b260fd4SAlessandro Rubini #include <asm/cacheflush.h> 430b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h> 440b260fd4SAlessandro Rubini 4561b38753SLinus Walleij #include "cpu-8815.h" 46ba327b1eSLinus Walleij 47056c78d3SLinus Walleij /* The 8815 has 4 GPIO blocks, let's register them immediately */ 48056c78d3SLinus Walleij static resource_size_t __initdata cpu8815_gpio_base[] = { 49056c78d3SLinus Walleij NOMADIK_GPIO0_BASE, 50056c78d3SLinus Walleij NOMADIK_GPIO1_BASE, 51056c78d3SLinus Walleij NOMADIK_GPIO2_BASE, 52056c78d3SLinus Walleij NOMADIK_GPIO3_BASE, 53056c78d3SLinus Walleij }; 54056c78d3SLinus Walleij 55056c78d3SLinus Walleij static struct platform_device * 56056c78d3SLinus Walleij cpu8815_add_gpio(int id, resource_size_t addr, int irq, 57056c78d3SLinus Walleij struct nmk_gpio_platform_data *pdata) 58056c78d3SLinus Walleij { 59056c78d3SLinus Walleij struct resource resources[] = { 60056c78d3SLinus Walleij { 61056c78d3SLinus Walleij .start = addr, 62056c78d3SLinus Walleij .end = addr + 127, 63056c78d3SLinus Walleij .flags = IORESOURCE_MEM, 64056c78d3SLinus Walleij }, 65056c78d3SLinus Walleij { 66056c78d3SLinus Walleij .start = irq, 67056c78d3SLinus Walleij .end = irq, 68056c78d3SLinus Walleij .flags = IORESOURCE_IRQ, 69056c78d3SLinus Walleij } 70056c78d3SLinus Walleij }; 71056c78d3SLinus Walleij 72056c78d3SLinus Walleij return platform_device_register_resndata(NULL, "gpio", id, 73056c78d3SLinus Walleij resources, ARRAY_SIZE(resources), 74056c78d3SLinus Walleij pdata, sizeof(*pdata)); 75056c78d3SLinus Walleij } 76056c78d3SLinus Walleij 77056c78d3SLinus Walleij void cpu8815_add_gpios(resource_size_t *base, int num, int irq, 78056c78d3SLinus Walleij struct nmk_gpio_platform_data *pdata) 79056c78d3SLinus Walleij { 80056c78d3SLinus Walleij int first = 0; 81056c78d3SLinus Walleij int i; 82056c78d3SLinus Walleij 83056c78d3SLinus Walleij for (i = 0; i < num; i++, first += 32, irq++) { 84056c78d3SLinus Walleij pdata->first_gpio = first; 85056c78d3SLinus Walleij pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first); 86056c78d3SLinus Walleij pdata->num_gpio = 32; 87056c78d3SLinus Walleij 88056c78d3SLinus Walleij cpu8815_add_gpio(i, base[i], irq, pdata); 89056c78d3SLinus Walleij } 90056c78d3SLinus Walleij } 91056c78d3SLinus Walleij 922601ccfeSLinus Walleij static inline void 932601ccfeSLinus Walleij cpu8815_add_pinctrl(struct device *parent, const char *name) 942601ccfeSLinus Walleij { 952601ccfeSLinus Walleij struct platform_device_info pdevinfo = { 962601ccfeSLinus Walleij .parent = parent, 972601ccfeSLinus Walleij .name = name, 982601ccfeSLinus Walleij .id = -1, 992601ccfeSLinus Walleij }; 1002601ccfeSLinus Walleij 1012601ccfeSLinus Walleij platform_device_register_full(&pdevinfo); 1022601ccfeSLinus Walleij } 1032601ccfeSLinus Walleij 1042ec1d359SAlessandro Rubini static int __init cpu8815_init(void) 1052ec1d359SAlessandro Rubini { 106056c78d3SLinus Walleij struct nmk_gpio_platform_data pdata = { 107056c78d3SLinus Walleij /* No custom data yet */ 108056c78d3SLinus Walleij }; 1092ec1d359SAlessandro Rubini 110056c78d3SLinus Walleij cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base), 111056c78d3SLinus Walleij IRQ_GPIO0, &pdata); 1122601ccfeSLinus Walleij cpu8815_add_pinctrl(NULL, "pinctrl-stn8815"); 1137c77852dSLinus Walleij amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0); 114b5111d9eSLinus Walleij amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0); 1152ec1d359SAlessandro Rubini return 0; 1162ec1d359SAlessandro Rubini } 1172ec1d359SAlessandro Rubini arch_initcall(cpu8815_init); 1182ec1d359SAlessandro Rubini 11928ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */ 12028ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = { 12128ad94ecSAlessandro Rubini { 12228ad94ecSAlessandro Rubini .virtual = NOMADIK_IO_VIRTUAL, 12328ad94ecSAlessandro Rubini .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), 12428ad94ecSAlessandro Rubini .length = NOMADIK_IO_SIZE, 12528ad94ecSAlessandro Rubini .type = MT_DEVICE, 12628ad94ecSAlessandro Rubini } 12728ad94ecSAlessandro Rubini /* static ram and secured ram may be added later */ 12828ad94ecSAlessandro Rubini }; 12928ad94ecSAlessandro Rubini 13028ad94ecSAlessandro Rubini void __init cpu8815_map_io(void) 13128ad94ecSAlessandro Rubini { 13228ad94ecSAlessandro Rubini iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); 13328ad94ecSAlessandro Rubini } 13428ad94ecSAlessandro Rubini 13528ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void) 13628ad94ecSAlessandro Rubini { 13728ad94ecSAlessandro Rubini /* This modified VIC cell has two register blocks, at 0 and 0x20 */ 13828ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0); 13928ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0); 140ba327b1eSLinus Walleij 141ba327b1eSLinus Walleij /* 142ba327b1eSLinus Walleij * Init clocks here so that they are available for system timer 143ba327b1eSLinus Walleij * initialization. 144ba327b1eSLinus Walleij */ 1454a31bd28SLinus Walleij nomadik_clk_init(); 14628ad94ecSAlessandro Rubini } 14728ad94ecSAlessandro Rubini 14828ad94ecSAlessandro Rubini /* 14928ad94ecSAlessandro Rubini * This function is called from the board init ("init_machine"). 15028ad94ecSAlessandro Rubini */ 15128ad94ecSAlessandro Rubini void __init cpu8815_platform_init(void) 15228ad94ecSAlessandro Rubini { 1530b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0 1540b260fd4SAlessandro Rubini /* At full speed latency must be >=2, so 0x249 in low bits */ 1550b260fd4SAlessandro Rubini l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff); 1560b260fd4SAlessandro Rubini #endif 15728ad94ecSAlessandro Rubini return; 15828ad94ecSAlessandro Rubini } 15935b47a40SRussell King 16035b47a40SRussell King void cpu8815_restart(char mode, const char *cmd) 16135b47a40SRussell King { 16235b47a40SRussell King void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); 16335b47a40SRussell King 16435b47a40SRussell King /* FIXME: use egpio when implemented */ 16535b47a40SRussell King 16635b47a40SRussell King /* Write anything to Reset status register */ 16735b47a40SRussell King writel(1, src_rstsr); 16835b47a40SRussell King } 169f8635abdSLinus Walleij 170f8635abdSLinus Walleij #ifdef CONFIG_OF 171f8635abdSLinus Walleij 172f8635abdSLinus Walleij /* Initial value for SRC control register: all timers use MXTAL/8 source */ 173f8635abdSLinus Walleij #define SRC_CR_INIT_MASK 0x00007fff 174f8635abdSLinus Walleij #define SRC_CR_INIT_VAL 0x2aaa8000 175f8635abdSLinus Walleij 176f8635abdSLinus Walleij static void __init cpu8815_timer_init_of(void) 177f8635abdSLinus Walleij { 178f8635abdSLinus Walleij struct device_node *mtu; 179f8635abdSLinus Walleij void __iomem *base; 180f8635abdSLinus Walleij int irq; 181f8635abdSLinus Walleij u32 src_cr; 182f8635abdSLinus Walleij 183f8635abdSLinus Walleij /* We need this to be up now */ 184f8635abdSLinus Walleij nomadik_clk_init(); 185f8635abdSLinus Walleij 186f8635abdSLinus Walleij mtu = of_find_node_by_path("/mtu0"); 187f8635abdSLinus Walleij if (!mtu) 188f8635abdSLinus Walleij return; 189f8635abdSLinus Walleij base = of_iomap(mtu, 0); 190f8635abdSLinus Walleij if (WARN_ON(!base)) 191f8635abdSLinus Walleij return; 192f8635abdSLinus Walleij irq = irq_of_parse_and_map(mtu, 0); 193f8635abdSLinus Walleij 194f8635abdSLinus Walleij pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); 195f8635abdSLinus Walleij 196f8635abdSLinus Walleij /* Configure timer sources in "system reset controller" ctrl reg */ 197f8635abdSLinus Walleij src_cr = readl(base); 198f8635abdSLinus Walleij src_cr &= SRC_CR_INIT_MASK; 199f8635abdSLinus Walleij src_cr |= SRC_CR_INIT_VAL; 200f8635abdSLinus Walleij writel(src_cr, base); 201f8635abdSLinus Walleij 202f8635abdSLinus Walleij nmdk_timer_init(base, irq); 203f8635abdSLinus Walleij } 204f8635abdSLinus Walleij 205f8635abdSLinus Walleij /* These are mostly to get the right device names for the clock lookups */ 206f8635abdSLinus Walleij static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { 207f8635abdSLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, 208f8635abdSLinus Walleij "uart0", NULL), 209f8635abdSLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, 210f8635abdSLinus Walleij "uart1", NULL), 211f8635abdSLinus Walleij { /* sentinel */ }, 212f8635abdSLinus Walleij }; 213f8635abdSLinus Walleij 214f8635abdSLinus Walleij static void __init cpu8815_init_of(void) 215f8635abdSLinus Walleij { 216f8635abdSLinus Walleij #ifdef CONFIG_CACHE_L2X0 217f8635abdSLinus Walleij /* At full speed latency must be >=2, so 0x249 in low bits */ 218f8635abdSLinus Walleij l2x0_of_init(0x00730249, 0xfe000fff); 219f8635abdSLinus Walleij #endif 220f8635abdSLinus Walleij of_platform_populate(NULL, of_default_bus_match_table, 221f8635abdSLinus Walleij cpu8815_auxdata_lookup, NULL); 222f8635abdSLinus Walleij } 223f8635abdSLinus Walleij 224f8635abdSLinus Walleij static const char * cpu8815_board_compat[] = { 225f8635abdSLinus Walleij "calaosystems,usb-s8815", 226f8635abdSLinus Walleij NULL, 227f8635abdSLinus Walleij }; 228f8635abdSLinus Walleij 229f8635abdSLinus Walleij DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") 230f8635abdSLinus Walleij .map_io = cpu8815_map_io, 231f8635abdSLinus Walleij .init_irq = irqchip_init, 232f8635abdSLinus Walleij .init_time = cpu8815_timer_init_of, 233f8635abdSLinus Walleij .init_machine = cpu8815_init_of, 234f8635abdSLinus Walleij .restart = cpu8815_restart, 235f8635abdSLinus Walleij .dt_compat = cpu8815_board_compat, 236f8635abdSLinus Walleij MACHINE_END 237f8635abdSLinus Walleij 238f8635abdSLinus Walleij #endif 239