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> 247779a5e0SAtsushi Nemoto #include <linux/serial_core.h> 2551f607c7SAtsushi Nemoto #include <linux/mtd/physmap.h> 26edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 27e0eb7307SAtsushi Nemoto #include <asm/time.h> 28a49297e8SAtsushi Nemoto #include <asm/reboot.h> 29d10e025fSAtsushi Nemoto #include <asm/r4kcache.h> 3089d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 3107517529SAtsushi Nemoto #include <asm/txx9/pci.h> 32*496a3b5cSAtsushi Nemoto #include <asm/txx9tmr.h> 33edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 34edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 35edcaf1a6SAtsushi Nemoto #endif 3689d63fe1SAtsushi Nemoto 3789d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 3889d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 3989d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 4089d63fe1SAtsushi Nemoto 4189d63fe1SAtsushi Nemoto /* pcode, internal register */ 4294a4c329SAtsushi Nemoto unsigned int txx9_pcode; 4389d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 4489d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 4589d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 4689d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 4789d63fe1SAtsushi Nemoto }; 4889d63fe1SAtsushi Nemoto void __init 4989d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 5089d63fe1SAtsushi Nemoto { 5189d63fe1SAtsushi Nemoto int i; 5289d63fe1SAtsushi Nemoto 5389d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 5489d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 5589d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 5689d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 5789d63fe1SAtsushi Nemoto } 5889d63fe1SAtsushi Nemoto 59073828d0SAtsushi Nemoto txx9_pcode = pcode; 6089d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 6189d63fe1SAtsushi Nemoto if (base) { 6289d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 6389d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 6489d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 6589d63fe1SAtsushi Nemoto } 6689d63fe1SAtsushi Nemoto } 6789d63fe1SAtsushi Nemoto 6889d63fe1SAtsushi Nemoto /* clocks */ 6989d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 7089d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 7189d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 72edcaf1a6SAtsushi Nemoto 73c7b95bcbSAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 74c7b95bcbSAtsushi Nemoto /* don't enable by default - see errata */ 75c7b95bcbSAtsushi Nemoto int txx9_ccfg_toeon __initdata; 76c7b95bcbSAtsushi Nemoto #else 7794a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 78c7b95bcbSAtsushi Nemoto #endif 79edcaf1a6SAtsushi Nemoto 80edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 81edcaf1a6SAtsushi Nemoto 82edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 83edcaf1a6SAtsushi Nemoto { 84edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 8594a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); 86edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 8794a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 88edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 89edcaf1a6SAtsushi Nemoto } 90edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 91edcaf1a6SAtsushi Nemoto 92edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 93edcaf1a6SAtsushi Nemoto { 94edcaf1a6SAtsushi Nemoto return 0; 95edcaf1a6SAtsushi Nemoto } 96edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 97edcaf1a6SAtsushi Nemoto 98edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 99edcaf1a6SAtsushi Nemoto { 100edcaf1a6SAtsushi Nemoto } 101edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 102edcaf1a6SAtsushi Nemoto 103edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 104edcaf1a6SAtsushi Nemoto { 105edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 106edcaf1a6SAtsushi Nemoto } 107edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 108edcaf1a6SAtsushi Nemoto 109edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 110edcaf1a6SAtsushi Nemoto { 111edcaf1a6SAtsushi Nemoto } 112edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 113edcaf1a6SAtsushi Nemoto 1148d795f2aSAtsushi Nemoto /* GPIO support */ 1158d795f2aSAtsushi Nemoto 1168d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1178d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1188d795f2aSAtsushi Nemoto { 1198d795f2aSAtsushi Nemoto return -EINVAL; 1208d795f2aSAtsushi Nemoto } 1218d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1228d795f2aSAtsushi Nemoto 1238d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1248d795f2aSAtsushi Nemoto { 1258d795f2aSAtsushi Nemoto return -EINVAL; 1268d795f2aSAtsushi Nemoto } 1278d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1288d795f2aSAtsushi Nemoto #endif 1298d795f2aSAtsushi Nemoto 130860e546cSAtsushi Nemoto #define BOARD_VEC(board) extern struct txx9_board_vec board; 131860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 132860e546cSAtsushi Nemoto #undef BOARD_VEC 133edcaf1a6SAtsushi Nemoto 134edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 135edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 136edcaf1a6SAtsushi Nemoto 137860e546cSAtsushi Nemoto static struct txx9_board_vec *board_vecs[] __initdata = { 138860e546cSAtsushi Nemoto #define BOARD_VEC(board) &board, 139860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 140860e546cSAtsushi Nemoto #undef BOARD_VEC 141860e546cSAtsushi Nemoto }; 142860e546cSAtsushi Nemoto 143860e546cSAtsushi Nemoto static struct txx9_board_vec *__init find_board_byname(const char *name) 144860e546cSAtsushi Nemoto { 145860e546cSAtsushi Nemoto int i; 146860e546cSAtsushi Nemoto 147860e546cSAtsushi Nemoto /* search board_vecs table */ 148860e546cSAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(board_vecs); i++) { 149860e546cSAtsushi Nemoto if (strstr(board_vecs[i]->system, name)) 150860e546cSAtsushi Nemoto return board_vecs[i]; 151860e546cSAtsushi Nemoto } 152860e546cSAtsushi Nemoto return NULL; 153860e546cSAtsushi Nemoto } 154860e546cSAtsushi Nemoto 155e0dfb20cSAtsushi Nemoto static void __init prom_init_cmdline(void) 156edcaf1a6SAtsushi Nemoto { 157edcaf1a6SAtsushi Nemoto int argc = (int)fw_arg0; 158e0dfb20cSAtsushi Nemoto int *argv32 = (int *)fw_arg1; 159edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 160e0dfb20cSAtsushi Nemoto char builtin[CL_SIZE]; 161edcaf1a6SAtsushi Nemoto 162edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 163e0dfb20cSAtsushi Nemoto /* 164e0dfb20cSAtsushi Nemoto * But if built-in strings was started with '+', append them 165e0dfb20cSAtsushi Nemoto * to command line args. If built-in was started with '-', 166e0dfb20cSAtsushi Nemoto * ignore all f/w args. 167e0dfb20cSAtsushi Nemoto */ 168e0dfb20cSAtsushi Nemoto builtin[0] = '\0'; 169e0dfb20cSAtsushi Nemoto if (arcs_cmdline[0] == '+') 170e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline + 1); 171e0dfb20cSAtsushi Nemoto else if (arcs_cmdline[0] == '-') { 172e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline + 1); 173e0dfb20cSAtsushi Nemoto argc = 0; 174e0dfb20cSAtsushi Nemoto } else if (argc <= 1) 175e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline); 176e0dfb20cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 177edcaf1a6SAtsushi Nemoto 178edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 179e0dfb20cSAtsushi Nemoto char *str = (char *)(long)argv32[i]; 180edcaf1a6SAtsushi Nemoto if (i != 1) 181edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 182e0dfb20cSAtsushi Nemoto if (strchr(str, ' ')) { 183e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 184e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 185e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 186e0dfb20cSAtsushi Nemoto } else 187e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 188e0dfb20cSAtsushi Nemoto } 189e0dfb20cSAtsushi Nemoto /* append saved builtin args */ 190e0dfb20cSAtsushi Nemoto if (builtin[0]) { 191e0dfb20cSAtsushi Nemoto if (arcs_cmdline[0]) 192e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, " "); 193e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, builtin); 194edcaf1a6SAtsushi Nemoto } 195edcaf1a6SAtsushi Nemoto } 196edcaf1a6SAtsushi Nemoto 197d10e025fSAtsushi Nemoto static int txx9_ic_disable __initdata; 198d10e025fSAtsushi Nemoto static int txx9_dc_disable __initdata; 199d10e025fSAtsushi Nemoto 200d10e025fSAtsushi Nemoto #if defined(CONFIG_CPU_TX49XX) 201d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before 4k_cache_init) */ 202d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 203d10e025fSAtsushi Nemoto { 204d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 205d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6)); 206d10e025fSAtsushi Nemoto unsigned int linesz = 32; 207d10e025fSAtsushi Nemoto unsigned long addr, end; 208d10e025fSAtsushi Nemoto 209d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 4; 210d10e025fSAtsushi Nemoto /* 4way, waybit=0 */ 211d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 212d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 213d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 214d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 2); 215d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 3); 216d10e025fSAtsushi Nemoto } 217d10e025fSAtsushi Nemoto } 218d10e025fSAtsushi Nemoto 219d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 220d10e025fSAtsushi Nemoto { 221d10e025fSAtsushi Nemoto unsigned int conf; 222d10e025fSAtsushi Nemoto 223d10e025fSAtsushi Nemoto conf = read_c0_config(); 224d10e025fSAtsushi Nemoto /* flush and disable */ 225d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 226d10e025fSAtsushi Nemoto conf |= TX49_CONF_IC; 227d10e025fSAtsushi Nemoto write_c0_config(conf); 228d10e025fSAtsushi Nemoto } 229d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 230d10e025fSAtsushi Nemoto early_flush_dcache(); 231d10e025fSAtsushi Nemoto conf |= TX49_CONF_DC; 232d10e025fSAtsushi Nemoto write_c0_config(conf); 233d10e025fSAtsushi Nemoto } 234d10e025fSAtsushi Nemoto 235d10e025fSAtsushi Nemoto /* enable cache */ 236d10e025fSAtsushi Nemoto conf = read_c0_config(); 237d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 238d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_IC; 239d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 240d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_DC; 241d10e025fSAtsushi Nemoto write_c0_config(conf); 242d10e025fSAtsushi Nemoto 243d10e025fSAtsushi Nemoto if (conf & TX49_CONF_IC) 244d10e025fSAtsushi Nemoto pr_info("TX49XX I-Cache disabled.\n"); 245d10e025fSAtsushi Nemoto if (conf & TX49_CONF_DC) 246d10e025fSAtsushi Nemoto pr_info("TX49XX D-Cache disabled.\n"); 247d10e025fSAtsushi Nemoto } 248d10e025fSAtsushi Nemoto #elif defined(CONFIG_CPU_TX39XX) 249d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before tx39_cache_init) */ 250d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 251d10e025fSAtsushi Nemoto { 252d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 253d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >> 254d10e025fSAtsushi Nemoto TX39_CONF_DCS_SHIFT)); 255d10e025fSAtsushi Nemoto unsigned int linesz = 16; 256d10e025fSAtsushi Nemoto unsigned long addr, end; 257d10e025fSAtsushi Nemoto 258d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 2; 259d10e025fSAtsushi Nemoto /* 2way, waybit=0 */ 260d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 261d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 262d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 263d10e025fSAtsushi Nemoto } 264d10e025fSAtsushi Nemoto } 265d10e025fSAtsushi Nemoto 266d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 267d10e025fSAtsushi Nemoto { 268d10e025fSAtsushi Nemoto unsigned int conf; 269d10e025fSAtsushi Nemoto 270d10e025fSAtsushi Nemoto conf = read_c0_config(); 271d10e025fSAtsushi Nemoto /* flush and disable */ 272d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 273d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_ICE; 274d10e025fSAtsushi Nemoto write_c0_config(conf); 275d10e025fSAtsushi Nemoto } 276d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 277d10e025fSAtsushi Nemoto early_flush_dcache(); 278d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_DCE; 279d10e025fSAtsushi Nemoto write_c0_config(conf); 280d10e025fSAtsushi Nemoto } 281d10e025fSAtsushi Nemoto 282d10e025fSAtsushi Nemoto /* enable cache */ 283d10e025fSAtsushi Nemoto conf = read_c0_config(); 284d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 285d10e025fSAtsushi Nemoto conf |= TX39_CONF_ICE; 286d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 287d10e025fSAtsushi Nemoto conf |= TX39_CONF_DCE; 288d10e025fSAtsushi Nemoto write_c0_config(conf); 289d10e025fSAtsushi Nemoto 290d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_ICE)) 291d10e025fSAtsushi Nemoto pr_info("TX39XX I-Cache disabled.\n"); 292d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_DCE)) 293d10e025fSAtsushi Nemoto pr_info("TX39XX D-Cache disabled.\n"); 294d10e025fSAtsushi Nemoto } 295d10e025fSAtsushi Nemoto #else 296d10e025fSAtsushi Nemoto static inline void txx9_cache_fixup(void) 297d10e025fSAtsushi Nemoto { 298d10e025fSAtsushi Nemoto } 299d10e025fSAtsushi Nemoto #endif 300d10e025fSAtsushi Nemoto 301860e546cSAtsushi Nemoto static void __init preprocess_cmdline(void) 302edcaf1a6SAtsushi Nemoto { 303860e546cSAtsushi Nemoto char cmdline[CL_SIZE]; 304860e546cSAtsushi Nemoto char *s; 305860e546cSAtsushi Nemoto 306860e546cSAtsushi Nemoto strcpy(cmdline, arcs_cmdline); 307860e546cSAtsushi Nemoto s = cmdline; 308860e546cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 309860e546cSAtsushi Nemoto while (s && *s) { 310860e546cSAtsushi Nemoto char *str = strsep(&s, " "); 311860e546cSAtsushi Nemoto if (strncmp(str, "board=", 6) == 0) { 312860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(str + 6); 313860e546cSAtsushi Nemoto continue; 314860e546cSAtsushi Nemoto } else if (strncmp(str, "masterclk=", 10) == 0) { 315860e546cSAtsushi Nemoto unsigned long val; 316860e546cSAtsushi Nemoto if (strict_strtoul(str + 10, 10, &val) == 0) 317860e546cSAtsushi Nemoto txx9_master_clock = val; 318860e546cSAtsushi Nemoto continue; 319d10e025fSAtsushi Nemoto } else if (strcmp(str, "icdisable") == 0) { 320d10e025fSAtsushi Nemoto txx9_ic_disable = 1; 321d10e025fSAtsushi Nemoto continue; 322d10e025fSAtsushi Nemoto } else if (strcmp(str, "dcdisable") == 0) { 323d10e025fSAtsushi Nemoto txx9_dc_disable = 1; 324d10e025fSAtsushi Nemoto continue; 325c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeoff") == 0) { 326c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 0; 327c7b95bcbSAtsushi Nemoto continue; 328c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeon") == 0) { 329c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 1; 330c7b95bcbSAtsushi Nemoto continue; 331860e546cSAtsushi Nemoto } 332860e546cSAtsushi Nemoto if (arcs_cmdline[0]) 333860e546cSAtsushi Nemoto strcat(arcs_cmdline, " "); 334860e546cSAtsushi Nemoto strcat(arcs_cmdline, str); 335860e546cSAtsushi Nemoto } 336d10e025fSAtsushi Nemoto 337d10e025fSAtsushi Nemoto txx9_cache_fixup(); 338860e546cSAtsushi Nemoto } 339860e546cSAtsushi Nemoto 340860e546cSAtsushi Nemoto static void __init select_board(void) 341860e546cSAtsushi Nemoto { 342860e546cSAtsushi Nemoto const char *envstr; 343860e546cSAtsushi Nemoto 344860e546cSAtsushi Nemoto /* first, determine by "board=" argument in preprocess_cmdline() */ 345860e546cSAtsushi Nemoto if (txx9_board_vec) 346860e546cSAtsushi Nemoto return; 347860e546cSAtsushi Nemoto /* next, determine by "board" envvar */ 348860e546cSAtsushi Nemoto envstr = prom_getenv("board"); 349860e546cSAtsushi Nemoto if (envstr) { 350860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(envstr); 351860e546cSAtsushi Nemoto if (txx9_board_vec) 352860e546cSAtsushi Nemoto return; 353860e546cSAtsushi Nemoto } 354860e546cSAtsushi Nemoto 355860e546cSAtsushi Nemoto /* select "default" board */ 356edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 3577a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 358edcaf1a6SAtsushi Nemoto #endif 359edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 360edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 3618d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 362edcaf1a6SAtsushi Nemoto case 0x4927: 3637a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 364edcaf1a6SAtsushi Nemoto break; 365edcaf1a6SAtsushi Nemoto case 0x4937: 3667a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 367edcaf1a6SAtsushi Nemoto break; 3688d795f2aSAtsushi Nemoto #endif 3698d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 370edcaf1a6SAtsushi Nemoto case 0x4938: 3717a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 372edcaf1a6SAtsushi Nemoto break; 3738d795f2aSAtsushi Nemoto #endif 374edcaf1a6SAtsushi Nemoto } 375edcaf1a6SAtsushi Nemoto #endif 376860e546cSAtsushi Nemoto } 377860e546cSAtsushi Nemoto 378860e546cSAtsushi Nemoto void __init prom_init(void) 379860e546cSAtsushi Nemoto { 380860e546cSAtsushi Nemoto prom_init_cmdline(); 381860e546cSAtsushi Nemoto preprocess_cmdline(); 382860e546cSAtsushi Nemoto select_board(); 3837a1fdf19SYoichi Yuasa 384edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 3857a1fdf19SYoichi Yuasa 3867b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 387edcaf1a6SAtsushi Nemoto } 388edcaf1a6SAtsushi Nemoto 389edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 390edcaf1a6SAtsushi Nemoto { 391edcaf1a6SAtsushi Nemoto } 392edcaf1a6SAtsushi Nemoto 393edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 394edcaf1a6SAtsushi Nemoto { 395edcaf1a6SAtsushi Nemoto return txx9_system_type; 396edcaf1a6SAtsushi Nemoto } 397edcaf1a6SAtsushi Nemoto 398edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 399edcaf1a6SAtsushi Nemoto { 400edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 401edcaf1a6SAtsushi Nemoto } 402edcaf1a6SAtsushi Nemoto 403265b89dbSAtsushi Nemoto const char *__init prom_getenv(const char *name) 404265b89dbSAtsushi Nemoto { 405265b89dbSAtsushi Nemoto const s32 *str = (const s32 *)fw_arg2; 406265b89dbSAtsushi Nemoto 407265b89dbSAtsushi Nemoto if (!str) 408265b89dbSAtsushi Nemoto return NULL; 409265b89dbSAtsushi Nemoto /* YAMON style ("name", "value" pairs) */ 410265b89dbSAtsushi Nemoto while (str[0] && str[1]) { 411265b89dbSAtsushi Nemoto if (!strcmp((const char *)(unsigned long)str[0], name)) 412265b89dbSAtsushi Nemoto return (const char *)(unsigned long)str[1]; 413265b89dbSAtsushi Nemoto str += 2; 414265b89dbSAtsushi Nemoto } 415265b89dbSAtsushi Nemoto return NULL; 416265b89dbSAtsushi Nemoto } 417265b89dbSAtsushi Nemoto 418a49297e8SAtsushi Nemoto static void __noreturn txx9_machine_halt(void) 419a49297e8SAtsushi Nemoto { 420a49297e8SAtsushi Nemoto local_irq_disable(); 421a49297e8SAtsushi Nemoto clear_c0_status(ST0_IM); 422a49297e8SAtsushi Nemoto while (1) { 423a49297e8SAtsushi Nemoto if (cpu_wait) { 424a49297e8SAtsushi Nemoto (*cpu_wait)(); 425a49297e8SAtsushi Nemoto if (cpu_has_counter) { 426a49297e8SAtsushi Nemoto /* 427a49297e8SAtsushi Nemoto * Clear counter interrupt while it 428a49297e8SAtsushi Nemoto * breaks WAIT instruction even if 429a49297e8SAtsushi Nemoto * masked. 430a49297e8SAtsushi Nemoto */ 431a49297e8SAtsushi Nemoto write_c0_compare(0); 432a49297e8SAtsushi Nemoto } 433a49297e8SAtsushi Nemoto } 434a49297e8SAtsushi Nemoto } 435a49297e8SAtsushi Nemoto } 436a49297e8SAtsushi Nemoto 43768314725SAtsushi Nemoto /* Watchdog support */ 43868314725SAtsushi Nemoto void __init txx9_wdt_init(unsigned long base) 43968314725SAtsushi Nemoto { 44068314725SAtsushi Nemoto struct resource res = { 44168314725SAtsushi Nemoto .start = base, 44268314725SAtsushi Nemoto .end = base + 0x100 - 1, 44368314725SAtsushi Nemoto .flags = IORESOURCE_MEM, 44468314725SAtsushi Nemoto }; 44568314725SAtsushi Nemoto platform_device_register_simple("txx9wdt", -1, &res, 1); 44668314725SAtsushi Nemoto } 44768314725SAtsushi Nemoto 448*496a3b5cSAtsushi Nemoto void txx9_wdt_now(unsigned long base) 449*496a3b5cSAtsushi Nemoto { 450*496a3b5cSAtsushi Nemoto struct txx9_tmr_reg __iomem *tmrptr = 451*496a3b5cSAtsushi Nemoto ioremap(base, sizeof(struct txx9_tmr_reg)); 452*496a3b5cSAtsushi Nemoto /* disable watch dog timer */ 453*496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr); 454*496a3b5cSAtsushi Nemoto __raw_writel(0, &tmrptr->tcr); 455*496a3b5cSAtsushi Nemoto /* kick watchdog */ 456*496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr); 457*496a3b5cSAtsushi Nemoto __raw_writel(1, &tmrptr->cpra); /* immediate */ 458*496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG, 459*496a3b5cSAtsushi Nemoto &tmrptr->tcr); 460*496a3b5cSAtsushi Nemoto } 461*496a3b5cSAtsushi Nemoto 462c49f91f5SAtsushi Nemoto /* SPI support */ 463c49f91f5SAtsushi Nemoto void __init txx9_spi_init(int busid, unsigned long base, int irq) 464c49f91f5SAtsushi Nemoto { 465c49f91f5SAtsushi Nemoto struct resource res[] = { 466c49f91f5SAtsushi Nemoto { 467c49f91f5SAtsushi Nemoto .start = base, 468c49f91f5SAtsushi Nemoto .end = base + 0x20 - 1, 469c49f91f5SAtsushi Nemoto .flags = IORESOURCE_MEM, 470c49f91f5SAtsushi Nemoto }, { 471c49f91f5SAtsushi Nemoto .start = irq, 472c49f91f5SAtsushi Nemoto .flags = IORESOURCE_IRQ, 473c49f91f5SAtsushi Nemoto }, 474c49f91f5SAtsushi Nemoto }; 475c49f91f5SAtsushi Nemoto platform_device_register_simple("spi_txx9", busid, 476c49f91f5SAtsushi Nemoto res, ARRAY_SIZE(res)); 477c49f91f5SAtsushi Nemoto } 478c49f91f5SAtsushi Nemoto 479c49f91f5SAtsushi Nemoto void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) 480c49f91f5SAtsushi Nemoto { 481c49f91f5SAtsushi Nemoto struct platform_device *pdev = 482c49f91f5SAtsushi Nemoto platform_device_alloc("tc35815-mac", id); 483c49f91f5SAtsushi Nemoto if (!pdev || 484c49f91f5SAtsushi Nemoto platform_device_add_data(pdev, ethaddr, 6) || 485c49f91f5SAtsushi Nemoto platform_device_add(pdev)) 486c49f91f5SAtsushi Nemoto platform_device_put(pdev); 487c49f91f5SAtsushi Nemoto } 488c49f91f5SAtsushi Nemoto 4897779a5e0SAtsushi Nemoto void __init txx9_sio_init(unsigned long baseaddr, int irq, 4907779a5e0SAtsushi Nemoto unsigned int line, unsigned int sclk, int nocts) 4917779a5e0SAtsushi Nemoto { 4927779a5e0SAtsushi Nemoto #ifdef CONFIG_SERIAL_TXX9 4937779a5e0SAtsushi Nemoto struct uart_port req; 4947779a5e0SAtsushi Nemoto 4957779a5e0SAtsushi Nemoto memset(&req, 0, sizeof(req)); 4967779a5e0SAtsushi Nemoto req.line = line; 4977779a5e0SAtsushi Nemoto req.iotype = UPIO_MEM; 4987779a5e0SAtsushi Nemoto req.membase = ioremap(baseaddr, 0x24); 4997779a5e0SAtsushi Nemoto req.mapbase = baseaddr; 5007779a5e0SAtsushi Nemoto req.irq = irq; 5017779a5e0SAtsushi Nemoto if (!nocts) 5027779a5e0SAtsushi Nemoto req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; 5037779a5e0SAtsushi Nemoto if (sclk) { 5047779a5e0SAtsushi Nemoto req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; 5057779a5e0SAtsushi Nemoto req.uartclk = sclk; 5067779a5e0SAtsushi Nemoto } else 5077779a5e0SAtsushi Nemoto req.uartclk = TXX9_IMCLK; 5087779a5e0SAtsushi Nemoto early_serial_txx9_setup(&req); 5097779a5e0SAtsushi Nemoto #endif /* CONFIG_SERIAL_TXX9 */ 5107779a5e0SAtsushi Nemoto } 5117779a5e0SAtsushi Nemoto 512e352953cSAtsushi Nemoto #ifdef CONFIG_EARLY_PRINTK 513e352953cSAtsushi Nemoto static void __init null_prom_putchar(char c) 514e352953cSAtsushi Nemoto { 515e352953cSAtsushi Nemoto } 516e352953cSAtsushi Nemoto void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar; 517e352953cSAtsushi Nemoto 518e352953cSAtsushi Nemoto void __init prom_putchar(char c) 519e352953cSAtsushi Nemoto { 520e352953cSAtsushi Nemoto txx9_prom_putchar(c); 521e352953cSAtsushi Nemoto } 522e352953cSAtsushi Nemoto 523e352953cSAtsushi Nemoto static void __iomem *early_txx9_sio_port; 524e352953cSAtsushi Nemoto 525e352953cSAtsushi Nemoto static void __init early_txx9_sio_putchar(char c) 526e352953cSAtsushi Nemoto { 527e352953cSAtsushi Nemoto #define TXX9_SICISR 0x0c 528e352953cSAtsushi Nemoto #define TXX9_SITFIFO 0x1c 529e352953cSAtsushi Nemoto #define TXX9_SICISR_TXALS 0x00000002 530e352953cSAtsushi Nemoto while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) & 531e352953cSAtsushi Nemoto TXX9_SICISR_TXALS)) 532e352953cSAtsushi Nemoto ; 533e352953cSAtsushi Nemoto __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO); 534e352953cSAtsushi Nemoto } 535e352953cSAtsushi Nemoto 536e352953cSAtsushi Nemoto void __init txx9_sio_putchar_init(unsigned long baseaddr) 537e352953cSAtsushi Nemoto { 538e352953cSAtsushi Nemoto early_txx9_sio_port = ioremap(baseaddr, 0x24); 539e352953cSAtsushi Nemoto txx9_prom_putchar = early_txx9_sio_putchar; 540e352953cSAtsushi Nemoto } 541e352953cSAtsushi Nemoto #endif /* CONFIG_EARLY_PRINTK */ 542e352953cSAtsushi Nemoto 543edcaf1a6SAtsushi Nemoto /* wrappers */ 544edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 545edcaf1a6SAtsushi Nemoto { 54694a4c329SAtsushi Nemoto ioport_resource.start = 0; 54794a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 54894a4c329SAtsushi Nemoto iomem_resource.start = 0; 54994a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 550a49297e8SAtsushi Nemoto 551a49297e8SAtsushi Nemoto /* fallback restart/halt routines */ 552a49297e8SAtsushi Nemoto _machine_restart = (void (*)(char *))txx9_machine_halt; 553a49297e8SAtsushi Nemoto _machine_halt = txx9_machine_halt; 554a49297e8SAtsushi Nemoto pm_power_off = txx9_machine_halt; 555a49297e8SAtsushi Nemoto 55607517529SAtsushi Nemoto #ifdef CONFIG_PCI 55707517529SAtsushi Nemoto pcibios_plat_setup = txx9_pcibios_setup; 55807517529SAtsushi Nemoto #endif 559edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 560edcaf1a6SAtsushi Nemoto } 561edcaf1a6SAtsushi Nemoto 562edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 563edcaf1a6SAtsushi Nemoto { 564edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 565edcaf1a6SAtsushi Nemoto } 566edcaf1a6SAtsushi Nemoto 567edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 568edcaf1a6SAtsushi Nemoto { 5691374d084SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 5701374d084SAtsushi Nemoto mips_hpt_frequency = txx9_cpu_clock / 2; 5711374d084SAtsushi Nemoto #endif 572edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 573edcaf1a6SAtsushi Nemoto } 574edcaf1a6SAtsushi Nemoto 575edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 576edcaf1a6SAtsushi Nemoto { 577edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 578edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 579edcaf1a6SAtsushi Nemoto return 0; 580edcaf1a6SAtsushi Nemoto } 581edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 582edcaf1a6SAtsushi Nemoto 583edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 584edcaf1a6SAtsushi Nemoto { 585edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 586edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 587edcaf1a6SAtsushi Nemoto return 0; 588edcaf1a6SAtsushi Nemoto } 589edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 590edcaf1a6SAtsushi Nemoto 591edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 592edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 593edcaf1a6SAtsushi Nemoto { 594edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 595edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 596edcaf1a6SAtsushi Nemoto 597edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 598edcaf1a6SAtsushi Nemoto do_IRQ(irq); 599edcaf1a6SAtsushi Nemoto else 600edcaf1a6SAtsushi Nemoto spurious_interrupt(); 601edcaf1a6SAtsushi Nemoto } 6024c642f3fSAtsushi Nemoto 6034c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 6044c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 6054c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 6064c642f3fSAtsushi Nemoto { 6074c642f3fSAtsushi Nemoto return port; 6084c642f3fSAtsushi Nemoto } 6094c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 6104c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 6114c642f3fSAtsushi Nemoto #endif 61251f607c7SAtsushi Nemoto 61351f607c7SAtsushi Nemoto void __init txx9_physmap_flash_init(int no, unsigned long addr, 61451f607c7SAtsushi Nemoto unsigned long size, 61551f607c7SAtsushi Nemoto const struct physmap_flash_data *pdata) 61651f607c7SAtsushi Nemoto { 61751f607c7SAtsushi Nemoto #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) 61851f607c7SAtsushi Nemoto struct resource res = { 61951f607c7SAtsushi Nemoto .start = addr, 62051f607c7SAtsushi Nemoto .end = addr + size - 1, 62151f607c7SAtsushi Nemoto .flags = IORESOURCE_MEM, 62251f607c7SAtsushi Nemoto }; 62351f607c7SAtsushi Nemoto struct platform_device *pdev; 62451f607c7SAtsushi Nemoto #ifdef CONFIG_MTD_PARTITIONS 62551f607c7SAtsushi Nemoto static struct mtd_partition parts[2]; 62651f607c7SAtsushi Nemoto struct physmap_flash_data pdata_part; 62751f607c7SAtsushi Nemoto 62851f607c7SAtsushi Nemoto /* If this area contained boot area, make separate partition */ 62951f607c7SAtsushi Nemoto if (pdata->nr_parts == 0 && !pdata->parts && 63051f607c7SAtsushi Nemoto addr < 0x1fc00000 && addr + size > 0x1fc00000 && 63151f607c7SAtsushi Nemoto !parts[0].name) { 63251f607c7SAtsushi Nemoto parts[0].name = "boot"; 63351f607c7SAtsushi Nemoto parts[0].offset = 0x1fc00000 - addr; 63451f607c7SAtsushi Nemoto parts[0].size = addr + size - 0x1fc00000; 63551f607c7SAtsushi Nemoto parts[1].name = "user"; 63651f607c7SAtsushi Nemoto parts[1].offset = 0; 63751f607c7SAtsushi Nemoto parts[1].size = 0x1fc00000 - addr; 63851f607c7SAtsushi Nemoto pdata_part = *pdata; 63951f607c7SAtsushi Nemoto pdata_part.nr_parts = ARRAY_SIZE(parts); 64051f607c7SAtsushi Nemoto pdata_part.parts = parts; 64151f607c7SAtsushi Nemoto pdata = &pdata_part; 64251f607c7SAtsushi Nemoto } 64351f607c7SAtsushi Nemoto #endif 64451f607c7SAtsushi Nemoto pdev = platform_device_alloc("physmap-flash", no); 64551f607c7SAtsushi Nemoto if (!pdev || 64651f607c7SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 64751f607c7SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 64851f607c7SAtsushi Nemoto platform_device_add(pdev)) 64951f607c7SAtsushi Nemoto platform_device_put(pdev); 65051f607c7SAtsushi Nemoto #endif 65151f607c7SAtsushi Nemoto } 652