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> 22e0eb7307SAtsushi Nemoto #include <linux/gpio.h> 2368314725SAtsushi Nemoto #include <linux/platform_device.h> 24*7779a5e0SAtsushi Nemoto #include <linux/serial_core.h> 25edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 26e0eb7307SAtsushi Nemoto #include <asm/time.h> 27a49297e8SAtsushi Nemoto #include <asm/reboot.h> 2889d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 2907517529SAtsushi Nemoto #include <asm/txx9/pci.h> 30edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 31edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 32edcaf1a6SAtsushi Nemoto #endif 3389d63fe1SAtsushi Nemoto 3489d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 3589d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 3689d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 3789d63fe1SAtsushi Nemoto 3889d63fe1SAtsushi Nemoto /* pcode, internal register */ 3994a4c329SAtsushi Nemoto unsigned int txx9_pcode; 4089d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 4189d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 4289d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 4389d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 4489d63fe1SAtsushi Nemoto }; 4589d63fe1SAtsushi Nemoto void __init 4689d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 4789d63fe1SAtsushi Nemoto { 4889d63fe1SAtsushi Nemoto int i; 4989d63fe1SAtsushi Nemoto 5089d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 5189d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 5289d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 5389d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 5489d63fe1SAtsushi Nemoto } 5589d63fe1SAtsushi Nemoto 5689d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 5789d63fe1SAtsushi Nemoto if (base) { 5889d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 5989d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 6089d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 6189d63fe1SAtsushi Nemoto } 6289d63fe1SAtsushi Nemoto } 6389d63fe1SAtsushi Nemoto 6489d63fe1SAtsushi Nemoto /* clocks */ 6589d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 6689d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 6789d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 68edcaf1a6SAtsushi Nemoto 6994a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 70edcaf1a6SAtsushi Nemoto 71edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 72edcaf1a6SAtsushi Nemoto 73edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 74edcaf1a6SAtsushi Nemoto { 75edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 7694a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); 77edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 7894a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 79edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 80edcaf1a6SAtsushi Nemoto } 81edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 82edcaf1a6SAtsushi Nemoto 83edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 84edcaf1a6SAtsushi Nemoto { 85edcaf1a6SAtsushi Nemoto return 0; 86edcaf1a6SAtsushi Nemoto } 87edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 88edcaf1a6SAtsushi Nemoto 89edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 90edcaf1a6SAtsushi Nemoto { 91edcaf1a6SAtsushi Nemoto } 92edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 93edcaf1a6SAtsushi Nemoto 94edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 95edcaf1a6SAtsushi Nemoto { 96edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 97edcaf1a6SAtsushi Nemoto } 98edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 99edcaf1a6SAtsushi Nemoto 100edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 101edcaf1a6SAtsushi Nemoto { 102edcaf1a6SAtsushi Nemoto } 103edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 104edcaf1a6SAtsushi Nemoto 1058d795f2aSAtsushi Nemoto /* GPIO support */ 1068d795f2aSAtsushi Nemoto 1078d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1088d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1098d795f2aSAtsushi Nemoto { 1108d795f2aSAtsushi Nemoto return -EINVAL; 1118d795f2aSAtsushi Nemoto } 1128d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1138d795f2aSAtsushi Nemoto 1148d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1158d795f2aSAtsushi Nemoto { 1168d795f2aSAtsushi Nemoto return -EINVAL; 1178d795f2aSAtsushi Nemoto } 1188d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1198d795f2aSAtsushi Nemoto #endif 1208d795f2aSAtsushi Nemoto 121edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec jmr3927_vec; 122edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4927_vec; 123edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4937_vec; 124edcaf1a6SAtsushi Nemoto extern struct txx9_board_vec rbtx4938_vec; 125edcaf1a6SAtsushi Nemoto 126edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 127edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 128edcaf1a6SAtsushi Nemoto 129edcaf1a6SAtsushi Nemoto void __init prom_init_cmdline(void) 130edcaf1a6SAtsushi Nemoto { 131edcaf1a6SAtsushi Nemoto int argc = (int)fw_arg0; 132edcaf1a6SAtsushi Nemoto char **argv = (char **)fw_arg1; 133edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 13494a4c329SAtsushi Nemoto #ifdef CONFIG_64BIT 13594a4c329SAtsushi Nemoto char *fixed_argv[32]; 13694a4c329SAtsushi Nemoto for (i = 0; i < argc; i++) 13794a4c329SAtsushi Nemoto fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i)); 13894a4c329SAtsushi Nemoto argv = fixed_argv; 13994a4c329SAtsushi Nemoto #endif 140edcaf1a6SAtsushi Nemoto 141edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 142edcaf1a6SAtsushi Nemoto if (argc > 1) 143edcaf1a6SAtsushi Nemoto *arcs_cmdline = '\0'; 144edcaf1a6SAtsushi Nemoto 145edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 146edcaf1a6SAtsushi Nemoto if (i != 1) 147edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 148edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, argv[i]); 149edcaf1a6SAtsushi Nemoto } 150edcaf1a6SAtsushi Nemoto } 151edcaf1a6SAtsushi Nemoto 152edcaf1a6SAtsushi Nemoto void __init prom_init(void) 153edcaf1a6SAtsushi Nemoto { 154edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 1557a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 156edcaf1a6SAtsushi Nemoto #endif 157edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 158edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 1598d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 160edcaf1a6SAtsushi Nemoto case 0x4927: 1617a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 162edcaf1a6SAtsushi Nemoto break; 163edcaf1a6SAtsushi Nemoto case 0x4937: 1647a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 165edcaf1a6SAtsushi Nemoto break; 1668d795f2aSAtsushi Nemoto #endif 1678d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 168edcaf1a6SAtsushi Nemoto case 0x4938: 1697a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 170edcaf1a6SAtsushi Nemoto break; 1718d795f2aSAtsushi Nemoto #endif 172edcaf1a6SAtsushi Nemoto } 173edcaf1a6SAtsushi Nemoto #endif 1747a1fdf19SYoichi Yuasa 175edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 1767a1fdf19SYoichi Yuasa 1777b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 178edcaf1a6SAtsushi Nemoto } 179edcaf1a6SAtsushi Nemoto 180edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 181edcaf1a6SAtsushi Nemoto { 182edcaf1a6SAtsushi Nemoto } 183edcaf1a6SAtsushi Nemoto 184edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 185edcaf1a6SAtsushi Nemoto { 186edcaf1a6SAtsushi Nemoto return txx9_system_type; 187edcaf1a6SAtsushi Nemoto } 188edcaf1a6SAtsushi Nemoto 189edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 190edcaf1a6SAtsushi Nemoto { 191edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 192edcaf1a6SAtsushi Nemoto } 193edcaf1a6SAtsushi Nemoto 194a49297e8SAtsushi Nemoto static void __noreturn txx9_machine_halt(void) 195a49297e8SAtsushi Nemoto { 196a49297e8SAtsushi Nemoto local_irq_disable(); 197a49297e8SAtsushi Nemoto clear_c0_status(ST0_IM); 198a49297e8SAtsushi Nemoto while (1) { 199a49297e8SAtsushi Nemoto if (cpu_wait) { 200a49297e8SAtsushi Nemoto (*cpu_wait)(); 201a49297e8SAtsushi Nemoto if (cpu_has_counter) { 202a49297e8SAtsushi Nemoto /* 203a49297e8SAtsushi Nemoto * Clear counter interrupt while it 204a49297e8SAtsushi Nemoto * breaks WAIT instruction even if 205a49297e8SAtsushi Nemoto * masked. 206a49297e8SAtsushi Nemoto */ 207a49297e8SAtsushi Nemoto write_c0_compare(0); 208a49297e8SAtsushi Nemoto } 209a49297e8SAtsushi Nemoto } 210a49297e8SAtsushi Nemoto } 211a49297e8SAtsushi Nemoto } 212a49297e8SAtsushi Nemoto 21368314725SAtsushi Nemoto /* Watchdog support */ 21468314725SAtsushi Nemoto void __init txx9_wdt_init(unsigned long base) 21568314725SAtsushi Nemoto { 21668314725SAtsushi Nemoto struct resource res = { 21768314725SAtsushi Nemoto .start = base, 21868314725SAtsushi Nemoto .end = base + 0x100 - 1, 21968314725SAtsushi Nemoto .flags = IORESOURCE_MEM, 22068314725SAtsushi Nemoto }; 22168314725SAtsushi Nemoto platform_device_register_simple("txx9wdt", -1, &res, 1); 22268314725SAtsushi Nemoto } 22368314725SAtsushi Nemoto 224c49f91f5SAtsushi Nemoto /* SPI support */ 225c49f91f5SAtsushi Nemoto void __init txx9_spi_init(int busid, unsigned long base, int irq) 226c49f91f5SAtsushi Nemoto { 227c49f91f5SAtsushi Nemoto struct resource res[] = { 228c49f91f5SAtsushi Nemoto { 229c49f91f5SAtsushi Nemoto .start = base, 230c49f91f5SAtsushi Nemoto .end = base + 0x20 - 1, 231c49f91f5SAtsushi Nemoto .flags = IORESOURCE_MEM, 232c49f91f5SAtsushi Nemoto }, { 233c49f91f5SAtsushi Nemoto .start = irq, 234c49f91f5SAtsushi Nemoto .flags = IORESOURCE_IRQ, 235c49f91f5SAtsushi Nemoto }, 236c49f91f5SAtsushi Nemoto }; 237c49f91f5SAtsushi Nemoto platform_device_register_simple("spi_txx9", busid, 238c49f91f5SAtsushi Nemoto res, ARRAY_SIZE(res)); 239c49f91f5SAtsushi Nemoto } 240c49f91f5SAtsushi Nemoto 241c49f91f5SAtsushi Nemoto void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) 242c49f91f5SAtsushi Nemoto { 243c49f91f5SAtsushi Nemoto struct platform_device *pdev = 244c49f91f5SAtsushi Nemoto platform_device_alloc("tc35815-mac", id); 245c49f91f5SAtsushi Nemoto if (!pdev || 246c49f91f5SAtsushi Nemoto platform_device_add_data(pdev, ethaddr, 6) || 247c49f91f5SAtsushi Nemoto platform_device_add(pdev)) 248c49f91f5SAtsushi Nemoto platform_device_put(pdev); 249c49f91f5SAtsushi Nemoto } 250c49f91f5SAtsushi Nemoto 251*7779a5e0SAtsushi Nemoto void __init txx9_sio_init(unsigned long baseaddr, int irq, 252*7779a5e0SAtsushi Nemoto unsigned int line, unsigned int sclk, int nocts) 253*7779a5e0SAtsushi Nemoto { 254*7779a5e0SAtsushi Nemoto #ifdef CONFIG_SERIAL_TXX9 255*7779a5e0SAtsushi Nemoto struct uart_port req; 256*7779a5e0SAtsushi Nemoto 257*7779a5e0SAtsushi Nemoto memset(&req, 0, sizeof(req)); 258*7779a5e0SAtsushi Nemoto req.line = line; 259*7779a5e0SAtsushi Nemoto req.iotype = UPIO_MEM; 260*7779a5e0SAtsushi Nemoto req.membase = ioremap(baseaddr, 0x24); 261*7779a5e0SAtsushi Nemoto req.mapbase = baseaddr; 262*7779a5e0SAtsushi Nemoto req.irq = irq; 263*7779a5e0SAtsushi Nemoto if (!nocts) 264*7779a5e0SAtsushi Nemoto req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; 265*7779a5e0SAtsushi Nemoto if (sclk) { 266*7779a5e0SAtsushi Nemoto req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; 267*7779a5e0SAtsushi Nemoto req.uartclk = sclk; 268*7779a5e0SAtsushi Nemoto } else 269*7779a5e0SAtsushi Nemoto req.uartclk = TXX9_IMCLK; 270*7779a5e0SAtsushi Nemoto early_serial_txx9_setup(&req); 271*7779a5e0SAtsushi Nemoto #endif /* CONFIG_SERIAL_TXX9 */ 272*7779a5e0SAtsushi Nemoto } 273*7779a5e0SAtsushi Nemoto 274edcaf1a6SAtsushi Nemoto /* wrappers */ 275edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 276edcaf1a6SAtsushi Nemoto { 27794a4c329SAtsushi Nemoto ioport_resource.start = 0; 27894a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 27994a4c329SAtsushi Nemoto iomem_resource.start = 0; 28094a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 281a49297e8SAtsushi Nemoto 282a49297e8SAtsushi Nemoto /* fallback restart/halt routines */ 283a49297e8SAtsushi Nemoto _machine_restart = (void (*)(char *))txx9_machine_halt; 284a49297e8SAtsushi Nemoto _machine_halt = txx9_machine_halt; 285a49297e8SAtsushi Nemoto pm_power_off = txx9_machine_halt; 286a49297e8SAtsushi Nemoto 28707517529SAtsushi Nemoto #ifdef CONFIG_PCI 28807517529SAtsushi Nemoto pcibios_plat_setup = txx9_pcibios_setup; 28907517529SAtsushi Nemoto #endif 290edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 291edcaf1a6SAtsushi Nemoto } 292edcaf1a6SAtsushi Nemoto 293edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 294edcaf1a6SAtsushi Nemoto { 295edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 296edcaf1a6SAtsushi Nemoto } 297edcaf1a6SAtsushi Nemoto 298edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 299edcaf1a6SAtsushi Nemoto { 300edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 301edcaf1a6SAtsushi Nemoto } 302edcaf1a6SAtsushi Nemoto 303edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 304edcaf1a6SAtsushi Nemoto { 305edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 306edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 307edcaf1a6SAtsushi Nemoto return 0; 308edcaf1a6SAtsushi Nemoto } 309edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 310edcaf1a6SAtsushi Nemoto 311edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 312edcaf1a6SAtsushi Nemoto { 313edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 314edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 315edcaf1a6SAtsushi Nemoto return 0; 316edcaf1a6SAtsushi Nemoto } 317edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 318edcaf1a6SAtsushi Nemoto 319edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 320edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 321edcaf1a6SAtsushi Nemoto { 322edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 323edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 324edcaf1a6SAtsushi Nemoto 325edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 326edcaf1a6SAtsushi Nemoto do_IRQ(irq); 327edcaf1a6SAtsushi Nemoto else 328edcaf1a6SAtsushi Nemoto spurious_interrupt(); 329edcaf1a6SAtsushi Nemoto } 3304c642f3fSAtsushi Nemoto 3314c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 3324c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 3334c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 3344c642f3fSAtsushi Nemoto { 3354c642f3fSAtsushi Nemoto return port; 3364c642f3fSAtsushi Nemoto } 3374c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 3384c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 3394c642f3fSAtsushi Nemoto #endif 340