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> 311b542757SLinus Walleij #include <linux/pinctrl/machine.h> 32f8635abdSLinus Walleij #include <linux/platform_data/clocksource-nomadik-mtu.h> 33f8635abdSLinus Walleij #include <linux/of_irq.h> 34f8635abdSLinus Walleij #include <linux/of_address.h> 35f8635abdSLinus Walleij #include <linux/of_platform.h> 3628ad94ecSAlessandro Rubini 3728ad94ecSAlessandro Rubini #include <mach/hardware.h> 3828ad94ecSAlessandro Rubini #include <mach/irqs.h> 39f8635abdSLinus Walleij #include <asm/mach/arch.h> 4028ad94ecSAlessandro Rubini #include <asm/mach/map.h> 41f8635abdSLinus Walleij #include <asm/mach/time.h> 4227bda036SLinus Walleij #include <asm/mach-types.h> 4328ad94ecSAlessandro Rubini 440b260fd4SAlessandro Rubini #include <asm/cacheflush.h> 450b260fd4SAlessandro Rubini #include <asm/hardware/cache-l2x0.h> 460b260fd4SAlessandro Rubini 4761b38753SLinus Walleij #include "cpu-8815.h" 48ba327b1eSLinus Walleij 49056c78d3SLinus Walleij /* The 8815 has 4 GPIO blocks, let's register them immediately */ 50056c78d3SLinus Walleij static resource_size_t __initdata cpu8815_gpio_base[] = { 51056c78d3SLinus Walleij NOMADIK_GPIO0_BASE, 52056c78d3SLinus Walleij NOMADIK_GPIO1_BASE, 53056c78d3SLinus Walleij NOMADIK_GPIO2_BASE, 54056c78d3SLinus Walleij NOMADIK_GPIO3_BASE, 55056c78d3SLinus Walleij }; 56056c78d3SLinus Walleij 57056c78d3SLinus Walleij static struct platform_device * 58056c78d3SLinus Walleij cpu8815_add_gpio(int id, resource_size_t addr, int irq, 59056c78d3SLinus Walleij struct nmk_gpio_platform_data *pdata) 60056c78d3SLinus Walleij { 61056c78d3SLinus Walleij struct resource resources[] = { 62056c78d3SLinus Walleij { 63056c78d3SLinus Walleij .start = addr, 64056c78d3SLinus Walleij .end = addr + 127, 65056c78d3SLinus Walleij .flags = IORESOURCE_MEM, 66056c78d3SLinus Walleij }, 67056c78d3SLinus Walleij { 68056c78d3SLinus Walleij .start = irq, 69056c78d3SLinus Walleij .end = irq, 70056c78d3SLinus Walleij .flags = IORESOURCE_IRQ, 71056c78d3SLinus Walleij } 72056c78d3SLinus Walleij }; 73056c78d3SLinus Walleij 74056c78d3SLinus Walleij return platform_device_register_resndata(NULL, "gpio", id, 75056c78d3SLinus Walleij resources, ARRAY_SIZE(resources), 76056c78d3SLinus Walleij pdata, sizeof(*pdata)); 77056c78d3SLinus Walleij } 78056c78d3SLinus Walleij 79056c78d3SLinus Walleij void cpu8815_add_gpios(resource_size_t *base, int num, int irq, 80056c78d3SLinus Walleij struct nmk_gpio_platform_data *pdata) 81056c78d3SLinus Walleij { 82056c78d3SLinus Walleij int first = 0; 83056c78d3SLinus Walleij int i; 84056c78d3SLinus Walleij 85056c78d3SLinus Walleij for (i = 0; i < num; i++, first += 32, irq++) { 86056c78d3SLinus Walleij pdata->first_gpio = first; 87056c78d3SLinus Walleij pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first); 88056c78d3SLinus Walleij pdata->num_gpio = 32; 89056c78d3SLinus Walleij 90056c78d3SLinus Walleij cpu8815_add_gpio(i, base[i], irq, pdata); 91056c78d3SLinus Walleij } 92056c78d3SLinus Walleij } 93056c78d3SLinus Walleij 941b542757SLinus Walleij static unsigned long out_low[] = { PIN_OUTPUT_LOW }; 951b542757SLinus Walleij static unsigned long out_high[] = { PIN_OUTPUT_HIGH }; 961b542757SLinus Walleij static unsigned long in_nopull[] = { PIN_INPUT_NOPULL }; 971b542757SLinus Walleij static unsigned long in_pullup[] = { PIN_INPUT_PULLUP }; 981b542757SLinus Walleij 991b542757SLinus Walleij static struct pinctrl_map __initdata nhk8815_pinmap[] = { 1001b542757SLinus Walleij PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"), 1011b542757SLinus Walleij PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"), 1021b542757SLinus Walleij /* Hog in MMC/SD card mux */ 1031b542757SLinus Walleij PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"), 1041b542757SLinus Walleij /* MCCLK */ 1051b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low), 1061b542757SLinus Walleij /* MCCMD */ 1071b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup), 1081b542757SLinus Walleij /* MCCMDDIR */ 1091b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high), 1101b542757SLinus Walleij /* MCDAT3-0 */ 1111b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup), 1121b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup), 1131b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup), 1141b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup), 1151b542757SLinus Walleij /* MCDAT0DIR */ 1161b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high), 1171b542757SLinus Walleij /* MCDAT31DIR */ 1181b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high), 1191b542757SLinus Walleij /* MCMSFBCLK */ 1201b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup), 1211b542757SLinus Walleij /* CD input GPIO */ 1221b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull), 1231b542757SLinus Walleij /* CD bias drive */ 1241b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low), 1251b542757SLinus Walleij /* I2C0 */ 1261b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup), 1271b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup), 1281b542757SLinus Walleij /* I2C1 */ 1291b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup), 1301b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup), 1311b542757SLinus Walleij /* I2C2 */ 1321b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup), 1331b542757SLinus Walleij PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup), 1341b542757SLinus Walleij }; 1351b542757SLinus Walleij 1362601ccfeSLinus Walleij static inline void 1372601ccfeSLinus Walleij cpu8815_add_pinctrl(struct device *parent, const char *name) 1382601ccfeSLinus Walleij { 1392601ccfeSLinus Walleij struct platform_device_info pdevinfo = { 1402601ccfeSLinus Walleij .parent = parent, 1412601ccfeSLinus Walleij .name = name, 1422601ccfeSLinus Walleij .id = -1, 1432601ccfeSLinus Walleij }; 1442601ccfeSLinus Walleij 1451b542757SLinus Walleij pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); 1462601ccfeSLinus Walleij platform_device_register_full(&pdevinfo); 1472601ccfeSLinus Walleij } 1482601ccfeSLinus Walleij 1492ec1d359SAlessandro Rubini static int __init cpu8815_init(void) 1502ec1d359SAlessandro Rubini { 151056c78d3SLinus Walleij struct nmk_gpio_platform_data pdata = { 152056c78d3SLinus Walleij /* No custom data yet */ 153056c78d3SLinus Walleij }; 1542ec1d359SAlessandro Rubini 155056c78d3SLinus Walleij cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base), 156056c78d3SLinus Walleij IRQ_GPIO0, &pdata); 1572601ccfeSLinus Walleij cpu8815_add_pinctrl(NULL, "pinctrl-stn8815"); 15827bda036SLinus Walleij if (machine_is_nomadik()) { 1597c77852dSLinus Walleij amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0); 160b5111d9eSLinus Walleij amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0); 16127bda036SLinus Walleij } 1622ec1d359SAlessandro Rubini return 0; 1632ec1d359SAlessandro Rubini } 1642ec1d359SAlessandro Rubini arch_initcall(cpu8815_init); 1652ec1d359SAlessandro Rubini 16628ad94ecSAlessandro Rubini /* All SoC devices live in the same area (see hardware.h) */ 16728ad94ecSAlessandro Rubini static struct map_desc nomadik_io_desc[] __initdata = { 16828ad94ecSAlessandro Rubini { 16928ad94ecSAlessandro Rubini .virtual = NOMADIK_IO_VIRTUAL, 17028ad94ecSAlessandro Rubini .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), 17128ad94ecSAlessandro Rubini .length = NOMADIK_IO_SIZE, 17228ad94ecSAlessandro Rubini .type = MT_DEVICE, 17328ad94ecSAlessandro Rubini } 17428ad94ecSAlessandro Rubini /* static ram and secured ram may be added later */ 17528ad94ecSAlessandro Rubini }; 17628ad94ecSAlessandro Rubini 17728ad94ecSAlessandro Rubini void __init cpu8815_map_io(void) 17828ad94ecSAlessandro Rubini { 17928ad94ecSAlessandro Rubini iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); 18028ad94ecSAlessandro Rubini } 18128ad94ecSAlessandro Rubini 18228ad94ecSAlessandro Rubini void __init cpu8815_init_irq(void) 18328ad94ecSAlessandro Rubini { 18428ad94ecSAlessandro Rubini /* This modified VIC cell has two register blocks, at 0 and 0x20 */ 18528ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0); 18628ad94ecSAlessandro Rubini vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0); 187ba327b1eSLinus Walleij 188ba327b1eSLinus Walleij /* 189ba327b1eSLinus Walleij * Init clocks here so that they are available for system timer 190ba327b1eSLinus Walleij * initialization. 191ba327b1eSLinus Walleij */ 1924a31bd28SLinus Walleij nomadik_clk_init(); 19328ad94ecSAlessandro Rubini } 19428ad94ecSAlessandro Rubini 19528ad94ecSAlessandro Rubini /* 19628ad94ecSAlessandro Rubini * This function is called from the board init ("init_machine"). 19728ad94ecSAlessandro Rubini */ 19828ad94ecSAlessandro Rubini void __init cpu8815_platform_init(void) 19928ad94ecSAlessandro Rubini { 2000b260fd4SAlessandro Rubini #ifdef CONFIG_CACHE_L2X0 2010b260fd4SAlessandro Rubini /* At full speed latency must be >=2, so 0x249 in low bits */ 2020b260fd4SAlessandro Rubini l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff); 2030b260fd4SAlessandro Rubini #endif 20428ad94ecSAlessandro Rubini return; 20528ad94ecSAlessandro Rubini } 20635b47a40SRussell King 20735b47a40SRussell King void cpu8815_restart(char mode, const char *cmd) 20835b47a40SRussell King { 20935b47a40SRussell King void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); 21035b47a40SRussell King 21135b47a40SRussell King /* FIXME: use egpio when implemented */ 21235b47a40SRussell King 21335b47a40SRussell King /* Write anything to Reset status register */ 21435b47a40SRussell King writel(1, src_rstsr); 21535b47a40SRussell King } 216f8635abdSLinus Walleij 217f8635abdSLinus Walleij #ifdef CONFIG_OF 218f8635abdSLinus Walleij 219f8635abdSLinus Walleij /* Initial value for SRC control register: all timers use MXTAL/8 source */ 220f8635abdSLinus Walleij #define SRC_CR_INIT_MASK 0x00007fff 221f8635abdSLinus Walleij #define SRC_CR_INIT_VAL 0x2aaa8000 222f8635abdSLinus Walleij 223f8635abdSLinus Walleij static void __init cpu8815_timer_init_of(void) 224f8635abdSLinus Walleij { 225f8635abdSLinus Walleij struct device_node *mtu; 226f8635abdSLinus Walleij void __iomem *base; 227f8635abdSLinus Walleij int irq; 228f8635abdSLinus Walleij u32 src_cr; 229f8635abdSLinus Walleij 230f8635abdSLinus Walleij /* We need this to be up now */ 231f8635abdSLinus Walleij nomadik_clk_init(); 232f8635abdSLinus Walleij 233f8635abdSLinus Walleij mtu = of_find_node_by_path("/mtu0"); 234f8635abdSLinus Walleij if (!mtu) 235f8635abdSLinus Walleij return; 236f8635abdSLinus Walleij base = of_iomap(mtu, 0); 237f8635abdSLinus Walleij if (WARN_ON(!base)) 238f8635abdSLinus Walleij return; 239f8635abdSLinus Walleij irq = irq_of_parse_and_map(mtu, 0); 240f8635abdSLinus Walleij 241f8635abdSLinus Walleij pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); 242f8635abdSLinus Walleij 243f8635abdSLinus Walleij /* Configure timer sources in "system reset controller" ctrl reg */ 244f8635abdSLinus Walleij src_cr = readl(base); 245f8635abdSLinus Walleij src_cr &= SRC_CR_INIT_MASK; 246f8635abdSLinus Walleij src_cr |= SRC_CR_INIT_VAL; 247f8635abdSLinus Walleij writel(src_cr, base); 248f8635abdSLinus Walleij 249f8635abdSLinus Walleij nmdk_timer_init(base, irq); 250f8635abdSLinus Walleij } 251f8635abdSLinus Walleij 252f8635abdSLinus Walleij /* These are mostly to get the right device names for the clock lookups */ 253f8635abdSLinus Walleij static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { 254f8635abdSLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, 255f8635abdSLinus Walleij "uart0", NULL), 256f8635abdSLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, 257f8635abdSLinus Walleij "uart1", NULL), 25827bda036SLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE, 25927bda036SLinus Walleij "rng", NULL), 26027bda036SLinus Walleij OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE, 26127bda036SLinus Walleij "rtc-pl031", NULL), 262f8635abdSLinus Walleij { /* sentinel */ }, 263f8635abdSLinus Walleij }; 264f8635abdSLinus Walleij 265f8635abdSLinus Walleij static void __init cpu8815_init_of(void) 266f8635abdSLinus Walleij { 267f8635abdSLinus Walleij #ifdef CONFIG_CACHE_L2X0 268f8635abdSLinus Walleij /* At full speed latency must be >=2, so 0x249 in low bits */ 269f8635abdSLinus Walleij l2x0_of_init(0x00730249, 0xfe000fff); 270f8635abdSLinus Walleij #endif 271f8635abdSLinus Walleij of_platform_populate(NULL, of_default_bus_match_table, 272f8635abdSLinus Walleij cpu8815_auxdata_lookup, NULL); 273f8635abdSLinus Walleij } 274f8635abdSLinus Walleij 275f8635abdSLinus Walleij static const char * cpu8815_board_compat[] = { 276f8635abdSLinus Walleij "calaosystems,usb-s8815", 277f8635abdSLinus Walleij NULL, 278f8635abdSLinus Walleij }; 279f8635abdSLinus Walleij 280f8635abdSLinus Walleij DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") 281f8635abdSLinus Walleij .map_io = cpu8815_map_io, 282f8635abdSLinus Walleij .init_irq = irqchip_init, 283f8635abdSLinus Walleij .init_time = cpu8815_timer_init_of, 284f8635abdSLinus Walleij .init_machine = cpu8815_init_of, 285f8635abdSLinus Walleij .restart = cpu8815_restart, 286f8635abdSLinus Walleij .dt_compat = cpu8815_board_compat, 287f8635abdSLinus Walleij MACHINE_END 288f8635abdSLinus Walleij 289f8635abdSLinus Walleij #endif 290