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 */ 3389d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 3489d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 3589d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 3689d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 3789d63fe1SAtsushi Nemoto }; 3889d63fe1SAtsushi Nemoto void __init 3989d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 4089d63fe1SAtsushi Nemoto { 4189d63fe1SAtsushi Nemoto int i; 4289d63fe1SAtsushi Nemoto 4389d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 4489d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 4589d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 4689d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 4789d63fe1SAtsushi Nemoto } 4889d63fe1SAtsushi Nemoto 4989d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 5089d63fe1SAtsushi Nemoto if (base) { 5189d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 5289d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 5389d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 5489d63fe1SAtsushi Nemoto } 5589d63fe1SAtsushi Nemoto } 5689d63fe1SAtsushi Nemoto 5789d63fe1SAtsushi Nemoto /* clocks */ 5889d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 5989d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 6089d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 61edcaf1a6SAtsushi Nemoto 62edcaf1a6SAtsushi Nemoto 63edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 64edcaf1a6SAtsushi Nemoto 65edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 66edcaf1a6SAtsushi Nemoto { 67edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 68edcaf1a6SAtsushi Nemoto return (struct clk *)(txx9_gbus_clock / 2 / 4); 69edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 70edcaf1a6SAtsushi Nemoto return (struct clk *)(txx9_gbus_clock / 2); 71edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 72edcaf1a6SAtsushi Nemoto } 73edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 74edcaf1a6SAtsushi Nemoto 75edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 76edcaf1a6SAtsushi Nemoto { 77edcaf1a6SAtsushi Nemoto return 0; 78edcaf1a6SAtsushi Nemoto } 79edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 80edcaf1a6SAtsushi Nemoto 81edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 82edcaf1a6SAtsushi Nemoto { 83edcaf1a6SAtsushi Nemoto } 84edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 85edcaf1a6SAtsushi Nemoto 86edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 87edcaf1a6SAtsushi Nemoto { 88edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 89edcaf1a6SAtsushi Nemoto } 90edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 91edcaf1a6SAtsushi Nemoto 92edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 93edcaf1a6SAtsushi Nemoto { 94edcaf1a6SAtsushi Nemoto } 95edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 96edcaf1a6SAtsushi Nemoto 97*8d795f2aSAtsushi Nemoto /* GPIO support */ 98*8d795f2aSAtsushi Nemoto 99*8d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 100*8d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 101*8d795f2aSAtsushi Nemoto { 102*8d795f2aSAtsushi Nemoto return -EINVAL; 103*8d795f2aSAtsushi Nemoto } 104*8d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 105*8d795f2aSAtsushi Nemoto 106*8d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 107*8d795f2aSAtsushi Nemoto { 108*8d795f2aSAtsushi Nemoto return -EINVAL; 109*8d795f2aSAtsushi Nemoto } 110*8d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 111*8d795f2aSAtsushi Nemoto #endif 112*8d795f2aSAtsushi Nemoto 113edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec jmr3927_vec; 114edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4927_vec; 115edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4937_vec; 116edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4938_vec; 117edcaf1a6SAtsushi Nemoto 118edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 119edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 120edcaf1a6SAtsushi Nemoto 121edcaf1a6SAtsushi Nemoto void __init prom_init_cmdline(void) 122edcaf1a6SAtsushi Nemoto { 123edcaf1a6SAtsushi Nemoto int argc = (int)fw_arg0; 124edcaf1a6SAtsushi Nemoto char **argv = (char **)fw_arg1; 125edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 126edcaf1a6SAtsushi Nemoto 127edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 128edcaf1a6SAtsushi Nemoto if (argc > 1) 129edcaf1a6SAtsushi Nemoto *arcs_cmdline = '\0'; 130edcaf1a6SAtsushi Nemoto 131edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 132edcaf1a6SAtsushi Nemoto if (i != 1) 133edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 134edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, argv[i]); 135edcaf1a6SAtsushi Nemoto } 136edcaf1a6SAtsushi Nemoto } 137edcaf1a6SAtsushi Nemoto 138edcaf1a6SAtsushi Nemoto void __init prom_init(void) 139edcaf1a6SAtsushi Nemoto { 140edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 1417a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 142edcaf1a6SAtsushi Nemoto #endif 143edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 144edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 145*8d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 146edcaf1a6SAtsushi Nemoto case 0x4927: 1477a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 148edcaf1a6SAtsushi Nemoto break; 149edcaf1a6SAtsushi Nemoto case 0x4937: 1507a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 151edcaf1a6SAtsushi Nemoto break; 152*8d795f2aSAtsushi Nemoto #endif 153*8d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 154edcaf1a6SAtsushi Nemoto case 0x4938: 1557a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 156edcaf1a6SAtsushi Nemoto break; 157*8d795f2aSAtsushi Nemoto #endif 158edcaf1a6SAtsushi Nemoto } 159edcaf1a6SAtsushi Nemoto #endif 1607a1fdf19SYoichi Yuasa 161edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 1627a1fdf19SYoichi Yuasa 1637b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 164edcaf1a6SAtsushi Nemoto } 165edcaf1a6SAtsushi Nemoto 166edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 167edcaf1a6SAtsushi Nemoto { 168edcaf1a6SAtsushi Nemoto } 169edcaf1a6SAtsushi Nemoto 170edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 171edcaf1a6SAtsushi Nemoto { 172edcaf1a6SAtsushi Nemoto return txx9_system_type; 173edcaf1a6SAtsushi Nemoto } 174edcaf1a6SAtsushi Nemoto 175edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 176edcaf1a6SAtsushi Nemoto { 177edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 178edcaf1a6SAtsushi Nemoto } 179edcaf1a6SAtsushi Nemoto 180edcaf1a6SAtsushi Nemoto /* wrappers */ 181edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 182edcaf1a6SAtsushi Nemoto { 183edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 184edcaf1a6SAtsushi Nemoto } 185edcaf1a6SAtsushi Nemoto 186edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 187edcaf1a6SAtsushi Nemoto { 188edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 189edcaf1a6SAtsushi Nemoto } 190edcaf1a6SAtsushi Nemoto 191edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 192edcaf1a6SAtsushi Nemoto { 193edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 194edcaf1a6SAtsushi Nemoto } 195edcaf1a6SAtsushi Nemoto 196edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 197edcaf1a6SAtsushi Nemoto { 198edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 199edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 200edcaf1a6SAtsushi Nemoto return 0; 201edcaf1a6SAtsushi Nemoto } 202edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 203edcaf1a6SAtsushi Nemoto 204edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 205edcaf1a6SAtsushi Nemoto { 206edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 207edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 208edcaf1a6SAtsushi Nemoto return 0; 209edcaf1a6SAtsushi Nemoto } 210edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 211edcaf1a6SAtsushi Nemoto 212edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 213edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 214edcaf1a6SAtsushi Nemoto { 215edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 216edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 217edcaf1a6SAtsushi Nemoto 218edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 219edcaf1a6SAtsushi Nemoto do_IRQ(irq); 220edcaf1a6SAtsushi Nemoto else 221edcaf1a6SAtsushi Nemoto spurious_interrupt(); 222edcaf1a6SAtsushi Nemoto } 2234c642f3fSAtsushi Nemoto 2244c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 2254c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 2264c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 2274c642f3fSAtsushi Nemoto { 2284c642f3fSAtsushi Nemoto return port; 2294c642f3fSAtsushi Nemoto } 2304c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 2314c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 2324c642f3fSAtsushi Nemoto #endif 233