189d63fe1SAtsushi Nemoto /* 289d63fe1SAtsushi Nemoto * linux/arch/mips/txx9/generic/setup.c 389d63fe1SAtsushi Nemoto * 489d63fe1SAtsushi Nemoto * Based on linux/arch/mips/txx9/rbtx4938/setup.c, 589d63fe1SAtsushi Nemoto * and RBTX49xx patch from CELF patch archive. 689d63fe1SAtsushi Nemoto * 789d63fe1SAtsushi Nemoto * 2003-2005 (c) MontaVista Software, Inc. 889d63fe1SAtsushi Nemoto * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007 989d63fe1SAtsushi Nemoto * 1089d63fe1SAtsushi Nemoto * This file is subject to the terms and conditions of the GNU General Public 1189d63fe1SAtsushi Nemoto * License. See the file "COPYING" in the main directory of this archive 1289d63fe1SAtsushi Nemoto * for more details. 1389d63fe1SAtsushi Nemoto */ 1489d63fe1SAtsushi Nemoto #include <linux/init.h> 1589d63fe1SAtsushi Nemoto #include <linux/kernel.h> 1689d63fe1SAtsushi Nemoto #include <linux/types.h> 17edcaf1a6SAtsushi Nemoto #include <linux/interrupt.h> 18edcaf1a6SAtsushi Nemoto #include <linux/string.h> 19edcaf1a6SAtsushi Nemoto #include <linux/module.h> 20edcaf1a6SAtsushi Nemoto #include <linux/clk.h> 21edcaf1a6SAtsushi Nemoto #include <linux/err.h> 22edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 2389d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 24edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 25edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 26edcaf1a6SAtsushi Nemoto #endif 2789d63fe1SAtsushi Nemoto 2889d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 2989d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 3089d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 3189d63fe1SAtsushi Nemoto 3289d63fe1SAtsushi Nemoto /* pcode, internal register */ 33*94a4c329SAtsushi Nemoto unsigned int txx9_pcode; 3489d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 3589d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 3689d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 3789d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 3889d63fe1SAtsushi Nemoto }; 3989d63fe1SAtsushi Nemoto void __init 4089d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 4189d63fe1SAtsushi Nemoto { 4289d63fe1SAtsushi Nemoto int i; 4389d63fe1SAtsushi Nemoto 4489d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 4589d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 4689d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 4789d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 4889d63fe1SAtsushi Nemoto } 4989d63fe1SAtsushi Nemoto 5089d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 5189d63fe1SAtsushi Nemoto if (base) { 5289d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 5389d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 5489d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 5589d63fe1SAtsushi Nemoto } 5689d63fe1SAtsushi Nemoto } 5789d63fe1SAtsushi Nemoto 5889d63fe1SAtsushi Nemoto /* clocks */ 5989d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 6089d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 6189d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 62edcaf1a6SAtsushi Nemoto 63*94a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 64edcaf1a6SAtsushi Nemoto 65edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 66edcaf1a6SAtsushi Nemoto 67edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 68edcaf1a6SAtsushi Nemoto { 69edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 70*94a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); 71edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 72*94a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 73edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 74edcaf1a6SAtsushi Nemoto } 75edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 76edcaf1a6SAtsushi Nemoto 77edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 78edcaf1a6SAtsushi Nemoto { 79edcaf1a6SAtsushi Nemoto return 0; 80edcaf1a6SAtsushi Nemoto } 81edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 82edcaf1a6SAtsushi Nemoto 83edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 84edcaf1a6SAtsushi Nemoto { 85edcaf1a6SAtsushi Nemoto } 86edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 87edcaf1a6SAtsushi Nemoto 88edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 89edcaf1a6SAtsushi Nemoto { 90edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 91edcaf1a6SAtsushi Nemoto } 92edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 93edcaf1a6SAtsushi Nemoto 94edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 95edcaf1a6SAtsushi Nemoto { 96edcaf1a6SAtsushi Nemoto } 97edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 98edcaf1a6SAtsushi Nemoto 998d795f2aSAtsushi Nemoto /* GPIO support */ 1008d795f2aSAtsushi Nemoto 1018d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1028d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1038d795f2aSAtsushi Nemoto { 1048d795f2aSAtsushi Nemoto return -EINVAL; 1058d795f2aSAtsushi Nemoto } 1068d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1078d795f2aSAtsushi Nemoto 1088d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1098d795f2aSAtsushi Nemoto { 1108d795f2aSAtsushi Nemoto return -EINVAL; 1118d795f2aSAtsushi Nemoto } 1128d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1138d795f2aSAtsushi Nemoto #endif 1148d795f2aSAtsushi Nemoto 115edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec jmr3927_vec; 116edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4927_vec; 117edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4937_vec; 118edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4938_vec; 119edcaf1a6SAtsushi Nemoto 120edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 121edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 122edcaf1a6SAtsushi Nemoto 123edcaf1a6SAtsushi Nemoto void __init prom_init_cmdline(void) 124edcaf1a6SAtsushi Nemoto { 125edcaf1a6SAtsushi Nemoto int argc = (int)fw_arg0; 126edcaf1a6SAtsushi Nemoto char **argv = (char **)fw_arg1; 127edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 128*94a4c329SAtsushi Nemoto #ifdef CONFIG_64BIT 129*94a4c329SAtsushi Nemoto char *fixed_argv[32]; 130*94a4c329SAtsushi Nemoto for (i = 0; i < argc; i++) 131*94a4c329SAtsushi Nemoto fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i)); 132*94a4c329SAtsushi Nemoto argv = fixed_argv; 133*94a4c329SAtsushi Nemoto #endif 134edcaf1a6SAtsushi Nemoto 135edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 136edcaf1a6SAtsushi Nemoto if (argc > 1) 137edcaf1a6SAtsushi Nemoto *arcs_cmdline = '\0'; 138edcaf1a6SAtsushi Nemoto 139edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 140edcaf1a6SAtsushi Nemoto if (i != 1) 141edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 142edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, argv[i]); 143edcaf1a6SAtsushi Nemoto } 144edcaf1a6SAtsushi Nemoto } 145edcaf1a6SAtsushi Nemoto 146edcaf1a6SAtsushi Nemoto void __init prom_init(void) 147edcaf1a6SAtsushi Nemoto { 148edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 1497a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 150edcaf1a6SAtsushi Nemoto #endif 151edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 152edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 1538d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 154edcaf1a6SAtsushi Nemoto case 0x4927: 1557a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 156edcaf1a6SAtsushi Nemoto break; 157edcaf1a6SAtsushi Nemoto case 0x4937: 1587a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 159edcaf1a6SAtsushi Nemoto break; 1608d795f2aSAtsushi Nemoto #endif 1618d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 162edcaf1a6SAtsushi Nemoto case 0x4938: 1637a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 164edcaf1a6SAtsushi Nemoto break; 1658d795f2aSAtsushi Nemoto #endif 166edcaf1a6SAtsushi Nemoto } 167edcaf1a6SAtsushi Nemoto #endif 1687a1fdf19SYoichi Yuasa 169edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 1707a1fdf19SYoichi Yuasa 1717b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 172edcaf1a6SAtsushi Nemoto } 173edcaf1a6SAtsushi Nemoto 174edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 175edcaf1a6SAtsushi Nemoto { 176edcaf1a6SAtsushi Nemoto } 177edcaf1a6SAtsushi Nemoto 178edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 179edcaf1a6SAtsushi Nemoto { 180edcaf1a6SAtsushi Nemoto return txx9_system_type; 181edcaf1a6SAtsushi Nemoto } 182edcaf1a6SAtsushi Nemoto 183edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 184edcaf1a6SAtsushi Nemoto { 185edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 186edcaf1a6SAtsushi Nemoto } 187edcaf1a6SAtsushi Nemoto 188edcaf1a6SAtsushi Nemoto /* wrappers */ 189edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 190edcaf1a6SAtsushi Nemoto { 191*94a4c329SAtsushi Nemoto ioport_resource.start = 0; 192*94a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 193*94a4c329SAtsushi Nemoto iomem_resource.start = 0; 194*94a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 195edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 196edcaf1a6SAtsushi Nemoto } 197edcaf1a6SAtsushi Nemoto 198edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 199edcaf1a6SAtsushi Nemoto { 200edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 201edcaf1a6SAtsushi Nemoto } 202edcaf1a6SAtsushi Nemoto 203edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 204edcaf1a6SAtsushi Nemoto { 205edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 206edcaf1a6SAtsushi Nemoto } 207edcaf1a6SAtsushi Nemoto 208edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 209edcaf1a6SAtsushi Nemoto { 210edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 211edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 212edcaf1a6SAtsushi Nemoto return 0; 213edcaf1a6SAtsushi Nemoto } 214edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 215edcaf1a6SAtsushi Nemoto 216edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 217edcaf1a6SAtsushi Nemoto { 218edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 219edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 220edcaf1a6SAtsushi Nemoto return 0; 221edcaf1a6SAtsushi Nemoto } 222edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 223edcaf1a6SAtsushi Nemoto 224edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 225edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 226edcaf1a6SAtsushi Nemoto { 227edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 228edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 229edcaf1a6SAtsushi Nemoto 230edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 231edcaf1a6SAtsushi Nemoto do_IRQ(irq); 232edcaf1a6SAtsushi Nemoto else 233edcaf1a6SAtsushi Nemoto spurious_interrupt(); 234edcaf1a6SAtsushi Nemoto } 2354c642f3fSAtsushi Nemoto 2364c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 2374c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 2384c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 2394c642f3fSAtsushi Nemoto { 2404c642f3fSAtsushi Nemoto return port; 2414c642f3fSAtsushi Nemoto } 2424c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 2434c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 2444c642f3fSAtsushi Nemoto #endif 245