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> 22*e0eb7307SAtsushi Nemoto #include <linux/gpio.h> 23edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 24*e0eb7307SAtsushi Nemoto #include <asm/time.h> 2589d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 26edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 27edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 28edcaf1a6SAtsushi Nemoto #endif 2989d63fe1SAtsushi Nemoto 3089d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 3189d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 3289d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 3389d63fe1SAtsushi Nemoto 3489d63fe1SAtsushi Nemoto /* pcode, internal register */ 3594a4c329SAtsushi Nemoto unsigned int txx9_pcode; 3689d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 3789d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 3889d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 3989d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 4089d63fe1SAtsushi Nemoto }; 4189d63fe1SAtsushi Nemoto void __init 4289d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 4389d63fe1SAtsushi Nemoto { 4489d63fe1SAtsushi Nemoto int i; 4589d63fe1SAtsushi Nemoto 4689d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 4789d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 4889d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 4989d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 5089d63fe1SAtsushi Nemoto } 5189d63fe1SAtsushi Nemoto 5289d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 5389d63fe1SAtsushi Nemoto if (base) { 5489d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 5589d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 5689d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 5789d63fe1SAtsushi Nemoto } 5889d63fe1SAtsushi Nemoto } 5989d63fe1SAtsushi Nemoto 6089d63fe1SAtsushi Nemoto /* clocks */ 6189d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 6289d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 6389d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 64edcaf1a6SAtsushi Nemoto 6594a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 66edcaf1a6SAtsushi Nemoto 67edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 68edcaf1a6SAtsushi Nemoto 69edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 70edcaf1a6SAtsushi Nemoto { 71edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 7294a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); 73edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 7494a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 75edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 76edcaf1a6SAtsushi Nemoto } 77edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 78edcaf1a6SAtsushi Nemoto 79edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 80edcaf1a6SAtsushi Nemoto { 81edcaf1a6SAtsushi Nemoto return 0; 82edcaf1a6SAtsushi Nemoto } 83edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 84edcaf1a6SAtsushi Nemoto 85edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 86edcaf1a6SAtsushi Nemoto { 87edcaf1a6SAtsushi Nemoto } 88edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 89edcaf1a6SAtsushi Nemoto 90edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 91edcaf1a6SAtsushi Nemoto { 92edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 93edcaf1a6SAtsushi Nemoto } 94edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 95edcaf1a6SAtsushi Nemoto 96edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 97edcaf1a6SAtsushi Nemoto { 98edcaf1a6SAtsushi Nemoto } 99edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 100edcaf1a6SAtsushi Nemoto 1018d795f2aSAtsushi Nemoto /* GPIO support */ 1028d795f2aSAtsushi Nemoto 1038d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1048d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1058d795f2aSAtsushi Nemoto { 1068d795f2aSAtsushi Nemoto return -EINVAL; 1078d795f2aSAtsushi Nemoto } 1088d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1098d795f2aSAtsushi Nemoto 1108d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1118d795f2aSAtsushi Nemoto { 1128d795f2aSAtsushi Nemoto return -EINVAL; 1138d795f2aSAtsushi Nemoto } 1148d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1158d795f2aSAtsushi Nemoto #endif 1168d795f2aSAtsushi Nemoto 117edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec jmr3927_vec; 118edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4927_vec; 119edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4937_vec; 120edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4938_vec; 121edcaf1a6SAtsushi Nemoto 122edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 123edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 124edcaf1a6SAtsushi Nemoto 125edcaf1a6SAtsushi Nemoto void __init prom_init_cmdline(void) 126edcaf1a6SAtsushi Nemoto { 127edcaf1a6SAtsushi Nemoto int argc = (int)fw_arg0; 128edcaf1a6SAtsushi Nemoto char **argv = (char **)fw_arg1; 129edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 13094a4c329SAtsushi Nemoto #ifdef CONFIG_64BIT 13194a4c329SAtsushi Nemoto char *fixed_argv[32]; 13294a4c329SAtsushi Nemoto for (i = 0; i < argc; i++) 13394a4c329SAtsushi Nemoto fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i)); 13494a4c329SAtsushi Nemoto argv = fixed_argv; 13594a4c329SAtsushi Nemoto #endif 136edcaf1a6SAtsushi Nemoto 137edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 138edcaf1a6SAtsushi Nemoto if (argc > 1) 139edcaf1a6SAtsushi Nemoto *arcs_cmdline = '\0'; 140edcaf1a6SAtsushi Nemoto 141edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 142edcaf1a6SAtsushi Nemoto if (i != 1) 143edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 144edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, argv[i]); 145edcaf1a6SAtsushi Nemoto } 146edcaf1a6SAtsushi Nemoto } 147edcaf1a6SAtsushi Nemoto 148edcaf1a6SAtsushi Nemoto void __init prom_init(void) 149edcaf1a6SAtsushi Nemoto { 150edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 1517a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 152edcaf1a6SAtsushi Nemoto #endif 153edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 154edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 1558d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 156edcaf1a6SAtsushi Nemoto case 0x4927: 1577a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 158edcaf1a6SAtsushi Nemoto break; 159edcaf1a6SAtsushi Nemoto case 0x4937: 1607a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 161edcaf1a6SAtsushi Nemoto break; 1628d795f2aSAtsushi Nemoto #endif 1638d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 164edcaf1a6SAtsushi Nemoto case 0x4938: 1657a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 166edcaf1a6SAtsushi Nemoto break; 1678d795f2aSAtsushi Nemoto #endif 168edcaf1a6SAtsushi Nemoto } 169edcaf1a6SAtsushi Nemoto #endif 1707a1fdf19SYoichi Yuasa 171edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 1727a1fdf19SYoichi Yuasa 1737b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 174edcaf1a6SAtsushi Nemoto } 175edcaf1a6SAtsushi Nemoto 176edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 177edcaf1a6SAtsushi Nemoto { 178edcaf1a6SAtsushi Nemoto } 179edcaf1a6SAtsushi Nemoto 180edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 181edcaf1a6SAtsushi Nemoto { 182edcaf1a6SAtsushi Nemoto return txx9_system_type; 183edcaf1a6SAtsushi Nemoto } 184edcaf1a6SAtsushi Nemoto 185edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 186edcaf1a6SAtsushi Nemoto { 187edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 188edcaf1a6SAtsushi Nemoto } 189edcaf1a6SAtsushi Nemoto 190edcaf1a6SAtsushi Nemoto /* wrappers */ 191edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 192edcaf1a6SAtsushi Nemoto { 19394a4c329SAtsushi Nemoto ioport_resource.start = 0; 19494a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 19594a4c329SAtsushi Nemoto iomem_resource.start = 0; 19694a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 197edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 198edcaf1a6SAtsushi Nemoto } 199edcaf1a6SAtsushi Nemoto 200edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 201edcaf1a6SAtsushi Nemoto { 202edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 203edcaf1a6SAtsushi Nemoto } 204edcaf1a6SAtsushi Nemoto 205edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 206edcaf1a6SAtsushi Nemoto { 207edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 208edcaf1a6SAtsushi Nemoto } 209edcaf1a6SAtsushi Nemoto 210edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 211edcaf1a6SAtsushi Nemoto { 212edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 213edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 214edcaf1a6SAtsushi Nemoto return 0; 215edcaf1a6SAtsushi Nemoto } 216edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 217edcaf1a6SAtsushi Nemoto 218edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 219edcaf1a6SAtsushi Nemoto { 220edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 221edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 222edcaf1a6SAtsushi Nemoto return 0; 223edcaf1a6SAtsushi Nemoto } 224edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 225edcaf1a6SAtsushi Nemoto 226edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 227edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 228edcaf1a6SAtsushi Nemoto { 229edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 230edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 231edcaf1a6SAtsushi Nemoto 232edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 233edcaf1a6SAtsushi Nemoto do_IRQ(irq); 234edcaf1a6SAtsushi Nemoto else 235edcaf1a6SAtsushi Nemoto spurious_interrupt(); 236edcaf1a6SAtsushi Nemoto } 2374c642f3fSAtsushi Nemoto 2384c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 2394c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 2404c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 2414c642f3fSAtsushi Nemoto { 2424c642f3fSAtsushi Nemoto return port; 2434c642f3fSAtsushi Nemoto } 2444c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 2454c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 2464c642f3fSAtsushi Nemoto #endif 247