189d63fe1SAtsushi Nemoto /* 289d63fe1SAtsushi Nemoto * Based on linux/arch/mips/txx9/rbtx4938/setup.c, 389d63fe1SAtsushi Nemoto * and RBTX49xx patch from CELF patch archive. 489d63fe1SAtsushi Nemoto * 589d63fe1SAtsushi Nemoto * 2003-2005 (c) MontaVista Software, Inc. 689d63fe1SAtsushi Nemoto * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007 789d63fe1SAtsushi Nemoto * 889d63fe1SAtsushi Nemoto * This file is subject to the terms and conditions of the GNU General Public 989d63fe1SAtsushi Nemoto * License. See the file "COPYING" in the main directory of this archive 1089d63fe1SAtsushi Nemoto * for more details. 1189d63fe1SAtsushi Nemoto */ 1289d63fe1SAtsushi Nemoto #include <linux/init.h> 1389d63fe1SAtsushi Nemoto #include <linux/kernel.h> 1489d63fe1SAtsushi Nemoto #include <linux/types.h> 15edcaf1a6SAtsushi Nemoto #include <linux/interrupt.h> 16edcaf1a6SAtsushi Nemoto #include <linux/string.h> 17edcaf1a6SAtsushi Nemoto #include <linux/module.h> 18edcaf1a6SAtsushi Nemoto #include <linux/clk.h> 19edcaf1a6SAtsushi Nemoto #include <linux/err.h> 20e0eb7307SAtsushi Nemoto #include <linux/gpio.h> 2168314725SAtsushi Nemoto #include <linux/platform_device.h> 227779a5e0SAtsushi Nemoto #include <linux/serial_core.h> 2351f607c7SAtsushi Nemoto #include <linux/mtd/physmap.h> 24ae027eadSAtsushi Nemoto #include <linux/leds.h> 25c3b28ae2SAtsushi Nemoto #include <linux/sysdev.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> 30b6263ff2SAtsushi Nemoto #include <asm/sections.h> 3189d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 3207517529SAtsushi Nemoto #include <asm/txx9/pci.h> 33496a3b5cSAtsushi Nemoto #include <asm/txx9tmr.h> 34a591f5d3SAtsushi Nemoto #include <asm/txx9/ndfmc.h> 35f48c8c95SAtsushi Nemoto #include <asm/txx9/dmac.h> 36edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 37edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 38edcaf1a6SAtsushi Nemoto #endif 3989d63fe1SAtsushi Nemoto 4089d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 4189d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 4289d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 4389d63fe1SAtsushi Nemoto 4489d63fe1SAtsushi Nemoto /* pcode, internal register */ 4594a4c329SAtsushi Nemoto unsigned int txx9_pcode; 4689d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 4789d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 4889d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 4989d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 5089d63fe1SAtsushi Nemoto }; 5189d63fe1SAtsushi Nemoto void __init 5289d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 5389d63fe1SAtsushi Nemoto { 5489d63fe1SAtsushi Nemoto int i; 5589d63fe1SAtsushi Nemoto 5689d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 5789d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 5889d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 5989d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 6089d63fe1SAtsushi Nemoto } 6189d63fe1SAtsushi Nemoto 62073828d0SAtsushi Nemoto txx9_pcode = pcode; 6389d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 6489d63fe1SAtsushi Nemoto if (base) { 6589d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 6689d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 6789d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 6889d63fe1SAtsushi Nemoto } 6989d63fe1SAtsushi Nemoto } 7089d63fe1SAtsushi Nemoto 7189d63fe1SAtsushi Nemoto /* clocks */ 7289d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 7389d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 7489d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 75edcaf1a6SAtsushi Nemoto 76c7b95bcbSAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 77c7b95bcbSAtsushi Nemoto /* don't enable by default - see errata */ 78c7b95bcbSAtsushi Nemoto int txx9_ccfg_toeon __initdata; 79c7b95bcbSAtsushi Nemoto #else 8094a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 81c7b95bcbSAtsushi Nemoto #endif 82edcaf1a6SAtsushi Nemoto 83edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 84edcaf1a6SAtsushi Nemoto 85edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 86edcaf1a6SAtsushi Nemoto { 87edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 88*fcc152f3SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2); 89edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 9094a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 91edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 92edcaf1a6SAtsushi Nemoto } 93edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 94edcaf1a6SAtsushi Nemoto 95edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 96edcaf1a6SAtsushi Nemoto { 97edcaf1a6SAtsushi Nemoto return 0; 98edcaf1a6SAtsushi Nemoto } 99edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 100edcaf1a6SAtsushi Nemoto 101edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 102edcaf1a6SAtsushi Nemoto { 103edcaf1a6SAtsushi Nemoto } 104edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 105edcaf1a6SAtsushi Nemoto 106edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 107edcaf1a6SAtsushi Nemoto { 108edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 109edcaf1a6SAtsushi Nemoto } 110edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 111edcaf1a6SAtsushi Nemoto 112edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 113edcaf1a6SAtsushi Nemoto { 114edcaf1a6SAtsushi Nemoto } 115edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 116edcaf1a6SAtsushi Nemoto 1178d795f2aSAtsushi Nemoto /* GPIO support */ 1188d795f2aSAtsushi Nemoto 1198d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1208d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1218d795f2aSAtsushi Nemoto { 1228d795f2aSAtsushi Nemoto return -EINVAL; 1238d795f2aSAtsushi Nemoto } 1248d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1258d795f2aSAtsushi Nemoto 1268d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1278d795f2aSAtsushi Nemoto { 1288d795f2aSAtsushi Nemoto return -EINVAL; 1298d795f2aSAtsushi Nemoto } 1308d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1318d795f2aSAtsushi Nemoto #endif 1328d795f2aSAtsushi Nemoto 133860e546cSAtsushi Nemoto #define BOARD_VEC(board) extern struct txx9_board_vec board; 134860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 135860e546cSAtsushi Nemoto #undef BOARD_VEC 136edcaf1a6SAtsushi Nemoto 137edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 138edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 139edcaf1a6SAtsushi Nemoto 140860e546cSAtsushi Nemoto static struct txx9_board_vec *board_vecs[] __initdata = { 141860e546cSAtsushi Nemoto #define BOARD_VEC(board) &board, 142860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 143860e546cSAtsushi Nemoto #undef BOARD_VEC 144860e546cSAtsushi Nemoto }; 145860e546cSAtsushi Nemoto 146860e546cSAtsushi Nemoto static struct txx9_board_vec *__init find_board_byname(const char *name) 147860e546cSAtsushi Nemoto { 148860e546cSAtsushi Nemoto int i; 149860e546cSAtsushi Nemoto 150860e546cSAtsushi Nemoto /* search board_vecs table */ 151860e546cSAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(board_vecs); i++) { 152860e546cSAtsushi Nemoto if (strstr(board_vecs[i]->system, name)) 153860e546cSAtsushi Nemoto return board_vecs[i]; 154860e546cSAtsushi Nemoto } 155860e546cSAtsushi Nemoto return NULL; 156860e546cSAtsushi Nemoto } 157860e546cSAtsushi Nemoto 158e0dfb20cSAtsushi Nemoto static void __init prom_init_cmdline(void) 159edcaf1a6SAtsushi Nemoto { 16097b0511cSGeert Uytterhoeven int argc; 16197b0511cSGeert Uytterhoeven int *argv32; 162edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 163e0dfb20cSAtsushi Nemoto char builtin[CL_SIZE]; 164edcaf1a6SAtsushi Nemoto 16597b0511cSGeert Uytterhoeven if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) { 16697b0511cSGeert Uytterhoeven /* 16797b0511cSGeert Uytterhoeven * argc is not a valid number, or argv32 is not a valid 16897b0511cSGeert Uytterhoeven * pointer 16997b0511cSGeert Uytterhoeven */ 17097b0511cSGeert Uytterhoeven argc = 0; 17197b0511cSGeert Uytterhoeven argv32 = NULL; 17297b0511cSGeert Uytterhoeven } else { 17397b0511cSGeert Uytterhoeven argc = (int)fw_arg0; 17497b0511cSGeert Uytterhoeven argv32 = (int *)fw_arg1; 17597b0511cSGeert Uytterhoeven } 17697b0511cSGeert Uytterhoeven 177edcaf1a6SAtsushi Nemoto /* ignore all built-in args if any f/w args given */ 178e0dfb20cSAtsushi Nemoto /* 179e0dfb20cSAtsushi Nemoto * But if built-in strings was started with '+', append them 180e0dfb20cSAtsushi Nemoto * to command line args. If built-in was started with '-', 181e0dfb20cSAtsushi Nemoto * ignore all f/w args. 182e0dfb20cSAtsushi Nemoto */ 183e0dfb20cSAtsushi Nemoto builtin[0] = '\0'; 184e0dfb20cSAtsushi Nemoto if (arcs_cmdline[0] == '+') 185e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline + 1); 186e0dfb20cSAtsushi Nemoto else if (arcs_cmdline[0] == '-') { 187e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline + 1); 188e0dfb20cSAtsushi Nemoto argc = 0; 189e0dfb20cSAtsushi Nemoto } else if (argc <= 1) 190e0dfb20cSAtsushi Nemoto strcpy(builtin, arcs_cmdline); 191e0dfb20cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 192edcaf1a6SAtsushi Nemoto 193edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 194e0dfb20cSAtsushi Nemoto char *str = (char *)(long)argv32[i]; 195edcaf1a6SAtsushi Nemoto if (i != 1) 196edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 197e0dfb20cSAtsushi Nemoto if (strchr(str, ' ')) { 198e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 199e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 200e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 201e0dfb20cSAtsushi Nemoto } else 202e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 203e0dfb20cSAtsushi Nemoto } 204e0dfb20cSAtsushi Nemoto /* append saved builtin args */ 205e0dfb20cSAtsushi Nemoto if (builtin[0]) { 206e0dfb20cSAtsushi Nemoto if (arcs_cmdline[0]) 207e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, " "); 208e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, builtin); 209edcaf1a6SAtsushi Nemoto } 210edcaf1a6SAtsushi Nemoto } 211edcaf1a6SAtsushi Nemoto 212d10e025fSAtsushi Nemoto static int txx9_ic_disable __initdata; 213d10e025fSAtsushi Nemoto static int txx9_dc_disable __initdata; 214d10e025fSAtsushi Nemoto 215d10e025fSAtsushi Nemoto #if defined(CONFIG_CPU_TX49XX) 216d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before 4k_cache_init) */ 217d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 218d10e025fSAtsushi Nemoto { 219d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 220d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6)); 221d10e025fSAtsushi Nemoto unsigned int linesz = 32; 222d10e025fSAtsushi Nemoto unsigned long addr, end; 223d10e025fSAtsushi Nemoto 224d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 4; 225d10e025fSAtsushi Nemoto /* 4way, waybit=0 */ 226d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 227d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 228d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 229d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 2); 230d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 3); 231d10e025fSAtsushi Nemoto } 232d10e025fSAtsushi Nemoto } 233d10e025fSAtsushi Nemoto 234d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 235d10e025fSAtsushi Nemoto { 236d10e025fSAtsushi Nemoto unsigned int conf; 237d10e025fSAtsushi Nemoto 238d10e025fSAtsushi Nemoto conf = read_c0_config(); 239d10e025fSAtsushi Nemoto /* flush and disable */ 240d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 241d10e025fSAtsushi Nemoto conf |= TX49_CONF_IC; 242d10e025fSAtsushi Nemoto write_c0_config(conf); 243d10e025fSAtsushi Nemoto } 244d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 245d10e025fSAtsushi Nemoto early_flush_dcache(); 246d10e025fSAtsushi Nemoto conf |= TX49_CONF_DC; 247d10e025fSAtsushi Nemoto write_c0_config(conf); 248d10e025fSAtsushi Nemoto } 249d10e025fSAtsushi Nemoto 250d10e025fSAtsushi Nemoto /* enable cache */ 251d10e025fSAtsushi Nemoto conf = read_c0_config(); 252d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 253d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_IC; 254d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 255d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_DC; 256d10e025fSAtsushi Nemoto write_c0_config(conf); 257d10e025fSAtsushi Nemoto 258d10e025fSAtsushi Nemoto if (conf & TX49_CONF_IC) 259d10e025fSAtsushi Nemoto pr_info("TX49XX I-Cache disabled.\n"); 260d10e025fSAtsushi Nemoto if (conf & TX49_CONF_DC) 261d10e025fSAtsushi Nemoto pr_info("TX49XX D-Cache disabled.\n"); 262d10e025fSAtsushi Nemoto } 263d10e025fSAtsushi Nemoto #elif defined(CONFIG_CPU_TX39XX) 264d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before tx39_cache_init) */ 265d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 266d10e025fSAtsushi Nemoto { 267d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 268d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >> 269d10e025fSAtsushi Nemoto TX39_CONF_DCS_SHIFT)); 270d10e025fSAtsushi Nemoto unsigned int linesz = 16; 271d10e025fSAtsushi Nemoto unsigned long addr, end; 272d10e025fSAtsushi Nemoto 273d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 2; 274d10e025fSAtsushi Nemoto /* 2way, waybit=0 */ 275d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 276d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 277d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 278d10e025fSAtsushi Nemoto } 279d10e025fSAtsushi Nemoto } 280d10e025fSAtsushi Nemoto 281d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 282d10e025fSAtsushi Nemoto { 283d10e025fSAtsushi Nemoto unsigned int conf; 284d10e025fSAtsushi Nemoto 285d10e025fSAtsushi Nemoto conf = read_c0_config(); 286d10e025fSAtsushi Nemoto /* flush and disable */ 287d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 288d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_ICE; 289d10e025fSAtsushi Nemoto write_c0_config(conf); 290d10e025fSAtsushi Nemoto } 291d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 292d10e025fSAtsushi Nemoto early_flush_dcache(); 293d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_DCE; 294d10e025fSAtsushi Nemoto write_c0_config(conf); 295d10e025fSAtsushi Nemoto } 296d10e025fSAtsushi Nemoto 297d10e025fSAtsushi Nemoto /* enable cache */ 298d10e025fSAtsushi Nemoto conf = read_c0_config(); 299d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 300d10e025fSAtsushi Nemoto conf |= TX39_CONF_ICE; 301d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 302d10e025fSAtsushi Nemoto conf |= TX39_CONF_DCE; 303d10e025fSAtsushi Nemoto write_c0_config(conf); 304d10e025fSAtsushi Nemoto 305d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_ICE)) 306d10e025fSAtsushi Nemoto pr_info("TX39XX I-Cache disabled.\n"); 307d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_DCE)) 308d10e025fSAtsushi Nemoto pr_info("TX39XX D-Cache disabled.\n"); 309d10e025fSAtsushi Nemoto } 310d10e025fSAtsushi Nemoto #else 311d10e025fSAtsushi Nemoto static inline void txx9_cache_fixup(void) 312d10e025fSAtsushi Nemoto { 313d10e025fSAtsushi Nemoto } 314d10e025fSAtsushi Nemoto #endif 315d10e025fSAtsushi Nemoto 316860e546cSAtsushi Nemoto static void __init preprocess_cmdline(void) 317edcaf1a6SAtsushi Nemoto { 318860e546cSAtsushi Nemoto char cmdline[CL_SIZE]; 319860e546cSAtsushi Nemoto char *s; 320860e546cSAtsushi Nemoto 321860e546cSAtsushi Nemoto strcpy(cmdline, arcs_cmdline); 322860e546cSAtsushi Nemoto s = cmdline; 323860e546cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 324860e546cSAtsushi Nemoto while (s && *s) { 325860e546cSAtsushi Nemoto char *str = strsep(&s, " "); 326860e546cSAtsushi Nemoto if (strncmp(str, "board=", 6) == 0) { 327860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(str + 6); 328860e546cSAtsushi Nemoto continue; 329860e546cSAtsushi Nemoto } else if (strncmp(str, "masterclk=", 10) == 0) { 330860e546cSAtsushi Nemoto unsigned long val; 331860e546cSAtsushi Nemoto if (strict_strtoul(str + 10, 10, &val) == 0) 332860e546cSAtsushi Nemoto txx9_master_clock = val; 333860e546cSAtsushi Nemoto continue; 334d10e025fSAtsushi Nemoto } else if (strcmp(str, "icdisable") == 0) { 335d10e025fSAtsushi Nemoto txx9_ic_disable = 1; 336d10e025fSAtsushi Nemoto continue; 337d10e025fSAtsushi Nemoto } else if (strcmp(str, "dcdisable") == 0) { 338d10e025fSAtsushi Nemoto txx9_dc_disable = 1; 339d10e025fSAtsushi Nemoto continue; 340c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeoff") == 0) { 341c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 0; 342c7b95bcbSAtsushi Nemoto continue; 343c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeon") == 0) { 344c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 1; 345c7b95bcbSAtsushi Nemoto continue; 346860e546cSAtsushi Nemoto } 347860e546cSAtsushi Nemoto if (arcs_cmdline[0]) 348860e546cSAtsushi Nemoto strcat(arcs_cmdline, " "); 349860e546cSAtsushi Nemoto strcat(arcs_cmdline, str); 350860e546cSAtsushi Nemoto } 351d10e025fSAtsushi Nemoto 352d10e025fSAtsushi Nemoto txx9_cache_fixup(); 353860e546cSAtsushi Nemoto } 354860e546cSAtsushi Nemoto 355860e546cSAtsushi Nemoto static void __init select_board(void) 356860e546cSAtsushi Nemoto { 357860e546cSAtsushi Nemoto const char *envstr; 358860e546cSAtsushi Nemoto 359860e546cSAtsushi Nemoto /* first, determine by "board=" argument in preprocess_cmdline() */ 360860e546cSAtsushi Nemoto if (txx9_board_vec) 361860e546cSAtsushi Nemoto return; 362860e546cSAtsushi Nemoto /* next, determine by "board" envvar */ 363860e546cSAtsushi Nemoto envstr = prom_getenv("board"); 364860e546cSAtsushi Nemoto if (envstr) { 365860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(envstr); 366860e546cSAtsushi Nemoto if (txx9_board_vec) 367860e546cSAtsushi Nemoto return; 368860e546cSAtsushi Nemoto } 369860e546cSAtsushi Nemoto 370860e546cSAtsushi Nemoto /* select "default" board */ 371edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 3727a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 373edcaf1a6SAtsushi Nemoto #endif 374edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 375edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 3768d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 377edcaf1a6SAtsushi Nemoto case 0x4927: 3787a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 379edcaf1a6SAtsushi Nemoto break; 380edcaf1a6SAtsushi Nemoto case 0x4937: 3817a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 382edcaf1a6SAtsushi Nemoto break; 3838d795f2aSAtsushi Nemoto #endif 3848d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 385edcaf1a6SAtsushi Nemoto case 0x4938: 3867a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 387edcaf1a6SAtsushi Nemoto break; 3888d795f2aSAtsushi Nemoto #endif 389b27311e1SAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4939 390b27311e1SAtsushi Nemoto case 0x4939: 391b27311e1SAtsushi Nemoto txx9_board_vec = &rbtx4939_vec; 392b27311e1SAtsushi Nemoto break; 393b27311e1SAtsushi Nemoto #endif 394edcaf1a6SAtsushi Nemoto } 395edcaf1a6SAtsushi Nemoto #endif 396860e546cSAtsushi Nemoto } 397860e546cSAtsushi Nemoto 398860e546cSAtsushi Nemoto void __init prom_init(void) 399860e546cSAtsushi Nemoto { 400860e546cSAtsushi Nemoto prom_init_cmdline(); 401860e546cSAtsushi Nemoto preprocess_cmdline(); 402860e546cSAtsushi Nemoto select_board(); 4037a1fdf19SYoichi Yuasa 404edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 4057a1fdf19SYoichi Yuasa 4067b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 407edcaf1a6SAtsushi Nemoto } 408edcaf1a6SAtsushi Nemoto 409edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 410edcaf1a6SAtsushi Nemoto { 411b6263ff2SAtsushi Nemoto unsigned long saddr = PAGE_SIZE; 412b6263ff2SAtsushi Nemoto unsigned long eaddr = __pa_symbol(&_text); 413b6263ff2SAtsushi Nemoto 414b6263ff2SAtsushi Nemoto if (saddr < eaddr) 415b6263ff2SAtsushi Nemoto free_init_pages("prom memory", saddr, eaddr); 416edcaf1a6SAtsushi Nemoto } 417edcaf1a6SAtsushi Nemoto 418edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 419edcaf1a6SAtsushi Nemoto { 420edcaf1a6SAtsushi Nemoto return txx9_system_type; 421edcaf1a6SAtsushi Nemoto } 422edcaf1a6SAtsushi Nemoto 423edcaf1a6SAtsushi Nemoto char * __init prom_getcmdline(void) 424edcaf1a6SAtsushi Nemoto { 425edcaf1a6SAtsushi Nemoto return &(arcs_cmdline[0]); 426edcaf1a6SAtsushi Nemoto } 427edcaf1a6SAtsushi Nemoto 428265b89dbSAtsushi Nemoto const char *__init prom_getenv(const char *name) 429265b89dbSAtsushi Nemoto { 43097b0511cSGeert Uytterhoeven const s32 *str; 431265b89dbSAtsushi Nemoto 43297b0511cSGeert Uytterhoeven if (fw_arg2 < CKSEG0) 433265b89dbSAtsushi Nemoto return NULL; 43497b0511cSGeert Uytterhoeven 43597b0511cSGeert Uytterhoeven str = (const s32 *)fw_arg2; 436265b89dbSAtsushi Nemoto /* YAMON style ("name", "value" pairs) */ 437265b89dbSAtsushi Nemoto while (str[0] && str[1]) { 438265b89dbSAtsushi Nemoto if (!strcmp((const char *)(unsigned long)str[0], name)) 439265b89dbSAtsushi Nemoto return (const char *)(unsigned long)str[1]; 440265b89dbSAtsushi Nemoto str += 2; 441265b89dbSAtsushi Nemoto } 442265b89dbSAtsushi Nemoto return NULL; 443265b89dbSAtsushi Nemoto } 444265b89dbSAtsushi Nemoto 445a49297e8SAtsushi Nemoto static void __noreturn txx9_machine_halt(void) 446a49297e8SAtsushi Nemoto { 447a49297e8SAtsushi Nemoto local_irq_disable(); 448a49297e8SAtsushi Nemoto clear_c0_status(ST0_IM); 449a49297e8SAtsushi Nemoto while (1) { 450a49297e8SAtsushi Nemoto if (cpu_wait) { 451a49297e8SAtsushi Nemoto (*cpu_wait)(); 452a49297e8SAtsushi Nemoto if (cpu_has_counter) { 453a49297e8SAtsushi Nemoto /* 454a49297e8SAtsushi Nemoto * Clear counter interrupt while it 455a49297e8SAtsushi Nemoto * breaks WAIT instruction even if 456a49297e8SAtsushi Nemoto * masked. 457a49297e8SAtsushi Nemoto */ 458a49297e8SAtsushi Nemoto write_c0_compare(0); 459a49297e8SAtsushi Nemoto } 460a49297e8SAtsushi Nemoto } 461a49297e8SAtsushi Nemoto } 462a49297e8SAtsushi Nemoto } 463a49297e8SAtsushi Nemoto 46468314725SAtsushi Nemoto /* Watchdog support */ 46568314725SAtsushi Nemoto void __init txx9_wdt_init(unsigned long base) 46668314725SAtsushi Nemoto { 46768314725SAtsushi Nemoto struct resource res = { 46868314725SAtsushi Nemoto .start = base, 46968314725SAtsushi Nemoto .end = base + 0x100 - 1, 47068314725SAtsushi Nemoto .flags = IORESOURCE_MEM, 47168314725SAtsushi Nemoto }; 47268314725SAtsushi Nemoto platform_device_register_simple("txx9wdt", -1, &res, 1); 47368314725SAtsushi Nemoto } 47468314725SAtsushi Nemoto 475496a3b5cSAtsushi Nemoto void txx9_wdt_now(unsigned long base) 476496a3b5cSAtsushi Nemoto { 477496a3b5cSAtsushi Nemoto struct txx9_tmr_reg __iomem *tmrptr = 478496a3b5cSAtsushi Nemoto ioremap(base, sizeof(struct txx9_tmr_reg)); 479496a3b5cSAtsushi Nemoto /* disable watch dog timer */ 480496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr); 481496a3b5cSAtsushi Nemoto __raw_writel(0, &tmrptr->tcr); 482496a3b5cSAtsushi Nemoto /* kick watchdog */ 483496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr); 484496a3b5cSAtsushi Nemoto __raw_writel(1, &tmrptr->cpra); /* immediate */ 485496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG, 486496a3b5cSAtsushi Nemoto &tmrptr->tcr); 487496a3b5cSAtsushi Nemoto } 488496a3b5cSAtsushi Nemoto 489c49f91f5SAtsushi Nemoto /* SPI support */ 490c49f91f5SAtsushi Nemoto void __init txx9_spi_init(int busid, unsigned long base, int irq) 491c49f91f5SAtsushi Nemoto { 492c49f91f5SAtsushi Nemoto struct resource res[] = { 493c49f91f5SAtsushi Nemoto { 494c49f91f5SAtsushi Nemoto .start = base, 495c49f91f5SAtsushi Nemoto .end = base + 0x20 - 1, 496c49f91f5SAtsushi Nemoto .flags = IORESOURCE_MEM, 497c49f91f5SAtsushi Nemoto }, { 498c49f91f5SAtsushi Nemoto .start = irq, 499c49f91f5SAtsushi Nemoto .flags = IORESOURCE_IRQ, 500c49f91f5SAtsushi Nemoto }, 501c49f91f5SAtsushi Nemoto }; 502c49f91f5SAtsushi Nemoto platform_device_register_simple("spi_txx9", busid, 503c49f91f5SAtsushi Nemoto res, ARRAY_SIZE(res)); 504c49f91f5SAtsushi Nemoto } 505c49f91f5SAtsushi Nemoto 506c49f91f5SAtsushi Nemoto void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) 507c49f91f5SAtsushi Nemoto { 508c49f91f5SAtsushi Nemoto struct platform_device *pdev = 509c49f91f5SAtsushi Nemoto platform_device_alloc("tc35815-mac", id); 510c49f91f5SAtsushi Nemoto if (!pdev || 511c49f91f5SAtsushi Nemoto platform_device_add_data(pdev, ethaddr, 6) || 512c49f91f5SAtsushi Nemoto platform_device_add(pdev)) 513c49f91f5SAtsushi Nemoto platform_device_put(pdev); 514c49f91f5SAtsushi Nemoto } 515c49f91f5SAtsushi Nemoto 5167779a5e0SAtsushi Nemoto void __init txx9_sio_init(unsigned long baseaddr, int irq, 5177779a5e0SAtsushi Nemoto unsigned int line, unsigned int sclk, int nocts) 5187779a5e0SAtsushi Nemoto { 5197779a5e0SAtsushi Nemoto #ifdef CONFIG_SERIAL_TXX9 5207779a5e0SAtsushi Nemoto struct uart_port req; 5217779a5e0SAtsushi Nemoto 5227779a5e0SAtsushi Nemoto memset(&req, 0, sizeof(req)); 5237779a5e0SAtsushi Nemoto req.line = line; 5247779a5e0SAtsushi Nemoto req.iotype = UPIO_MEM; 5257779a5e0SAtsushi Nemoto req.membase = ioremap(baseaddr, 0x24); 5267779a5e0SAtsushi Nemoto req.mapbase = baseaddr; 5277779a5e0SAtsushi Nemoto req.irq = irq; 5287779a5e0SAtsushi Nemoto if (!nocts) 5297779a5e0SAtsushi Nemoto req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; 5307779a5e0SAtsushi Nemoto if (sclk) { 5317779a5e0SAtsushi Nemoto req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; 5327779a5e0SAtsushi Nemoto req.uartclk = sclk; 5337779a5e0SAtsushi Nemoto } else 5347779a5e0SAtsushi Nemoto req.uartclk = TXX9_IMCLK; 5357779a5e0SAtsushi Nemoto early_serial_txx9_setup(&req); 5367779a5e0SAtsushi Nemoto #endif /* CONFIG_SERIAL_TXX9 */ 5377779a5e0SAtsushi Nemoto } 5387779a5e0SAtsushi Nemoto 539e352953cSAtsushi Nemoto #ifdef CONFIG_EARLY_PRINTK 540e352953cSAtsushi Nemoto static void __init null_prom_putchar(char c) 541e352953cSAtsushi Nemoto { 542e352953cSAtsushi Nemoto } 543e352953cSAtsushi Nemoto void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar; 544e352953cSAtsushi Nemoto 545e352953cSAtsushi Nemoto void __init prom_putchar(char c) 546e352953cSAtsushi Nemoto { 547e352953cSAtsushi Nemoto txx9_prom_putchar(c); 548e352953cSAtsushi Nemoto } 549e352953cSAtsushi Nemoto 550e352953cSAtsushi Nemoto static void __iomem *early_txx9_sio_port; 551e352953cSAtsushi Nemoto 552e352953cSAtsushi Nemoto static void __init early_txx9_sio_putchar(char c) 553e352953cSAtsushi Nemoto { 554e352953cSAtsushi Nemoto #define TXX9_SICISR 0x0c 555e352953cSAtsushi Nemoto #define TXX9_SITFIFO 0x1c 556e352953cSAtsushi Nemoto #define TXX9_SICISR_TXALS 0x00000002 557e352953cSAtsushi Nemoto while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) & 558e352953cSAtsushi Nemoto TXX9_SICISR_TXALS)) 559e352953cSAtsushi Nemoto ; 560e352953cSAtsushi Nemoto __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO); 561e352953cSAtsushi Nemoto } 562e352953cSAtsushi Nemoto 563e352953cSAtsushi Nemoto void __init txx9_sio_putchar_init(unsigned long baseaddr) 564e352953cSAtsushi Nemoto { 565e352953cSAtsushi Nemoto early_txx9_sio_port = ioremap(baseaddr, 0x24); 566e352953cSAtsushi Nemoto txx9_prom_putchar = early_txx9_sio_putchar; 567e352953cSAtsushi Nemoto } 568e352953cSAtsushi Nemoto #endif /* CONFIG_EARLY_PRINTK */ 569e352953cSAtsushi Nemoto 570edcaf1a6SAtsushi Nemoto /* wrappers */ 571edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 572edcaf1a6SAtsushi Nemoto { 57394a4c329SAtsushi Nemoto ioport_resource.start = 0; 57494a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 57594a4c329SAtsushi Nemoto iomem_resource.start = 0; 57694a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 577a49297e8SAtsushi Nemoto 578a49297e8SAtsushi Nemoto /* fallback restart/halt routines */ 579a49297e8SAtsushi Nemoto _machine_restart = (void (*)(char *))txx9_machine_halt; 580a49297e8SAtsushi Nemoto _machine_halt = txx9_machine_halt; 581a49297e8SAtsushi Nemoto pm_power_off = txx9_machine_halt; 582a49297e8SAtsushi Nemoto 58307517529SAtsushi Nemoto #ifdef CONFIG_PCI 58407517529SAtsushi Nemoto pcibios_plat_setup = txx9_pcibios_setup; 58507517529SAtsushi Nemoto #endif 586edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 587edcaf1a6SAtsushi Nemoto } 588edcaf1a6SAtsushi Nemoto 589edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 590edcaf1a6SAtsushi Nemoto { 591edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 592edcaf1a6SAtsushi Nemoto } 593edcaf1a6SAtsushi Nemoto 594edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 595edcaf1a6SAtsushi Nemoto { 5961374d084SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 5971374d084SAtsushi Nemoto mips_hpt_frequency = txx9_cpu_clock / 2; 5981374d084SAtsushi Nemoto #endif 599edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 600edcaf1a6SAtsushi Nemoto } 601edcaf1a6SAtsushi Nemoto 602edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 603edcaf1a6SAtsushi Nemoto { 604edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 605edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 606edcaf1a6SAtsushi Nemoto return 0; 607edcaf1a6SAtsushi Nemoto } 608edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 609edcaf1a6SAtsushi Nemoto 610edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 611edcaf1a6SAtsushi Nemoto { 612edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 613edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 614edcaf1a6SAtsushi Nemoto return 0; 615edcaf1a6SAtsushi Nemoto } 616edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 617edcaf1a6SAtsushi Nemoto 618edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 619edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 620edcaf1a6SAtsushi Nemoto { 621edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 622edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 623edcaf1a6SAtsushi Nemoto 624edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 625edcaf1a6SAtsushi Nemoto do_IRQ(irq); 626edcaf1a6SAtsushi Nemoto else 627edcaf1a6SAtsushi Nemoto spurious_interrupt(); 628edcaf1a6SAtsushi Nemoto } 6294c642f3fSAtsushi Nemoto 6304c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 6314c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 6324c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 6334c642f3fSAtsushi Nemoto { 6344c642f3fSAtsushi Nemoto return port; 6354c642f3fSAtsushi Nemoto } 6364c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 6374c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 6384c642f3fSAtsushi Nemoto #endif 63951f607c7SAtsushi Nemoto 6401ba5a176SAtsushi Nemoto #ifdef NEEDS_TXX9_IOSWABW 6411ba5a176SAtsushi Nemoto static u16 ioswabw_default(volatile u16 *a, u16 x) 6421ba5a176SAtsushi Nemoto { 6431ba5a176SAtsushi Nemoto return le16_to_cpu(x); 6441ba5a176SAtsushi Nemoto } 6451ba5a176SAtsushi Nemoto static u16 __mem_ioswabw_default(volatile u16 *a, u16 x) 6461ba5a176SAtsushi Nemoto { 6471ba5a176SAtsushi Nemoto return x; 6481ba5a176SAtsushi Nemoto } 6491ba5a176SAtsushi Nemoto u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default; 6501ba5a176SAtsushi Nemoto EXPORT_SYMBOL(ioswabw); 6511ba5a176SAtsushi Nemoto u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default; 6521ba5a176SAtsushi Nemoto EXPORT_SYMBOL(__mem_ioswabw); 6531ba5a176SAtsushi Nemoto #endif 6541ba5a176SAtsushi Nemoto 65551f607c7SAtsushi Nemoto void __init txx9_physmap_flash_init(int no, unsigned long addr, 65651f607c7SAtsushi Nemoto unsigned long size, 65751f607c7SAtsushi Nemoto const struct physmap_flash_data *pdata) 65851f607c7SAtsushi Nemoto { 65951f607c7SAtsushi Nemoto #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) 66051f607c7SAtsushi Nemoto struct resource res = { 66151f607c7SAtsushi Nemoto .start = addr, 66251f607c7SAtsushi Nemoto .end = addr + size - 1, 66351f607c7SAtsushi Nemoto .flags = IORESOURCE_MEM, 66451f607c7SAtsushi Nemoto }; 66551f607c7SAtsushi Nemoto struct platform_device *pdev; 66651f607c7SAtsushi Nemoto #ifdef CONFIG_MTD_PARTITIONS 66751f607c7SAtsushi Nemoto static struct mtd_partition parts[2]; 66851f607c7SAtsushi Nemoto struct physmap_flash_data pdata_part; 66951f607c7SAtsushi Nemoto 67051f607c7SAtsushi Nemoto /* If this area contained boot area, make separate partition */ 67151f607c7SAtsushi Nemoto if (pdata->nr_parts == 0 && !pdata->parts && 67251f607c7SAtsushi Nemoto addr < 0x1fc00000 && addr + size > 0x1fc00000 && 67351f607c7SAtsushi Nemoto !parts[0].name) { 67451f607c7SAtsushi Nemoto parts[0].name = "boot"; 67551f607c7SAtsushi Nemoto parts[0].offset = 0x1fc00000 - addr; 67651f607c7SAtsushi Nemoto parts[0].size = addr + size - 0x1fc00000; 67751f607c7SAtsushi Nemoto parts[1].name = "user"; 67851f607c7SAtsushi Nemoto parts[1].offset = 0; 67951f607c7SAtsushi Nemoto parts[1].size = 0x1fc00000 - addr; 68051f607c7SAtsushi Nemoto pdata_part = *pdata; 68151f607c7SAtsushi Nemoto pdata_part.nr_parts = ARRAY_SIZE(parts); 68251f607c7SAtsushi Nemoto pdata_part.parts = parts; 68351f607c7SAtsushi Nemoto pdata = &pdata_part; 68451f607c7SAtsushi Nemoto } 68551f607c7SAtsushi Nemoto #endif 68651f607c7SAtsushi Nemoto pdev = platform_device_alloc("physmap-flash", no); 68751f607c7SAtsushi Nemoto if (!pdev || 68851f607c7SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 68951f607c7SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 69051f607c7SAtsushi Nemoto platform_device_add(pdev)) 69151f607c7SAtsushi Nemoto platform_device_put(pdev); 69251f607c7SAtsushi Nemoto #endif 69351f607c7SAtsushi Nemoto } 694ae027eadSAtsushi Nemoto 695a591f5d3SAtsushi Nemoto void __init txx9_ndfmc_init(unsigned long baseaddr, 696a591f5d3SAtsushi Nemoto const struct txx9ndfmc_platform_data *pdata) 697a591f5d3SAtsushi Nemoto { 698a591f5d3SAtsushi Nemoto #if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \ 699a591f5d3SAtsushi Nemoto defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE) 700a591f5d3SAtsushi Nemoto struct resource res = { 701a591f5d3SAtsushi Nemoto .start = baseaddr, 702a591f5d3SAtsushi Nemoto .end = baseaddr + 0x1000 - 1, 703a591f5d3SAtsushi Nemoto .flags = IORESOURCE_MEM, 704a591f5d3SAtsushi Nemoto }; 705a591f5d3SAtsushi Nemoto struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1); 706a591f5d3SAtsushi Nemoto 707a591f5d3SAtsushi Nemoto if (!pdev || 708a591f5d3SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 709a591f5d3SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 710a591f5d3SAtsushi Nemoto platform_device_add(pdev)) 711a591f5d3SAtsushi Nemoto platform_device_put(pdev); 712a591f5d3SAtsushi Nemoto #endif 713a591f5d3SAtsushi Nemoto } 714a591f5d3SAtsushi Nemoto 715ae027eadSAtsushi Nemoto #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) 716ae027eadSAtsushi Nemoto static DEFINE_SPINLOCK(txx9_iocled_lock); 717ae027eadSAtsushi Nemoto 718ae027eadSAtsushi Nemoto #define TXX9_IOCLED_MAXLEDS 8 719ae027eadSAtsushi Nemoto 720ae027eadSAtsushi Nemoto struct txx9_iocled_data { 721ae027eadSAtsushi Nemoto struct gpio_chip chip; 722ae027eadSAtsushi Nemoto u8 cur_val; 723ae027eadSAtsushi Nemoto void __iomem *mmioaddr; 724ae027eadSAtsushi Nemoto struct gpio_led_platform_data pdata; 725ae027eadSAtsushi Nemoto struct gpio_led leds[TXX9_IOCLED_MAXLEDS]; 726ae027eadSAtsushi Nemoto char names[TXX9_IOCLED_MAXLEDS][32]; 727ae027eadSAtsushi Nemoto }; 728ae027eadSAtsushi Nemoto 729ae027eadSAtsushi Nemoto static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset) 730ae027eadSAtsushi Nemoto { 731ae027eadSAtsushi Nemoto struct txx9_iocled_data *data = 732ae027eadSAtsushi Nemoto container_of(chip, struct txx9_iocled_data, chip); 733ae027eadSAtsushi Nemoto return data->cur_val & (1 << offset); 734ae027eadSAtsushi Nemoto } 735ae027eadSAtsushi Nemoto 736ae027eadSAtsushi Nemoto static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset, 737ae027eadSAtsushi Nemoto int value) 738ae027eadSAtsushi Nemoto { 739ae027eadSAtsushi Nemoto struct txx9_iocled_data *data = 740ae027eadSAtsushi Nemoto container_of(chip, struct txx9_iocled_data, chip); 741ae027eadSAtsushi Nemoto unsigned long flags; 742ae027eadSAtsushi Nemoto spin_lock_irqsave(&txx9_iocled_lock, flags); 743ae027eadSAtsushi Nemoto if (value) 744ae027eadSAtsushi Nemoto data->cur_val |= 1 << offset; 745ae027eadSAtsushi Nemoto else 746ae027eadSAtsushi Nemoto data->cur_val &= ~(1 << offset); 747ae027eadSAtsushi Nemoto writeb(data->cur_val, data->mmioaddr); 748ae027eadSAtsushi Nemoto mmiowb(); 749ae027eadSAtsushi Nemoto spin_unlock_irqrestore(&txx9_iocled_lock, flags); 750ae027eadSAtsushi Nemoto } 751ae027eadSAtsushi Nemoto 752ae027eadSAtsushi Nemoto static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset) 753ae027eadSAtsushi Nemoto { 754ae027eadSAtsushi Nemoto return 0; 755ae027eadSAtsushi Nemoto } 756ae027eadSAtsushi Nemoto 757ae027eadSAtsushi Nemoto static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset, 758ae027eadSAtsushi Nemoto int value) 759ae027eadSAtsushi Nemoto { 760ae027eadSAtsushi Nemoto txx9_iocled_set(chip, offset, value); 761ae027eadSAtsushi Nemoto return 0; 762ae027eadSAtsushi Nemoto } 763ae027eadSAtsushi Nemoto 764ae027eadSAtsushi Nemoto void __init txx9_iocled_init(unsigned long baseaddr, 765ae027eadSAtsushi Nemoto int basenum, unsigned int num, int lowactive, 766ae027eadSAtsushi Nemoto const char *color, char **deftriggers) 767ae027eadSAtsushi Nemoto { 768ae027eadSAtsushi Nemoto struct txx9_iocled_data *iocled; 769ae027eadSAtsushi Nemoto struct platform_device *pdev; 770ae027eadSAtsushi Nemoto int i; 771ae027eadSAtsushi Nemoto static char *default_triggers[] __initdata = { 772ae027eadSAtsushi Nemoto "heartbeat", 773ae027eadSAtsushi Nemoto "ide-disk", 774ae027eadSAtsushi Nemoto "nand-disk", 775ae027eadSAtsushi Nemoto NULL, 776ae027eadSAtsushi Nemoto }; 777ae027eadSAtsushi Nemoto 778ae027eadSAtsushi Nemoto if (!deftriggers) 779ae027eadSAtsushi Nemoto deftriggers = default_triggers; 780ae027eadSAtsushi Nemoto iocled = kzalloc(sizeof(*iocled), GFP_KERNEL); 781ae027eadSAtsushi Nemoto if (!iocled) 782ae027eadSAtsushi Nemoto return; 783ae027eadSAtsushi Nemoto iocled->mmioaddr = ioremap(baseaddr, 1); 784ae027eadSAtsushi Nemoto if (!iocled->mmioaddr) 78570ebadc8SJulia Lawall goto out_free; 786ae027eadSAtsushi Nemoto iocled->chip.get = txx9_iocled_get; 787ae027eadSAtsushi Nemoto iocled->chip.set = txx9_iocled_set; 788ae027eadSAtsushi Nemoto iocled->chip.direction_input = txx9_iocled_dir_in; 789ae027eadSAtsushi Nemoto iocled->chip.direction_output = txx9_iocled_dir_out; 790ae027eadSAtsushi Nemoto iocled->chip.label = "iocled"; 791ae027eadSAtsushi Nemoto iocled->chip.base = basenum; 792ae027eadSAtsushi Nemoto iocled->chip.ngpio = num; 793ae027eadSAtsushi Nemoto if (gpiochip_add(&iocled->chip)) 79470ebadc8SJulia Lawall goto out_unmap; 795ae027eadSAtsushi Nemoto if (basenum < 0) 796ae027eadSAtsushi Nemoto basenum = iocled->chip.base; 797ae027eadSAtsushi Nemoto 798ae027eadSAtsushi Nemoto pdev = platform_device_alloc("leds-gpio", basenum); 799ae027eadSAtsushi Nemoto if (!pdev) 80070ebadc8SJulia Lawall goto out_gpio; 801ae027eadSAtsushi Nemoto iocled->pdata.num_leds = num; 802ae027eadSAtsushi Nemoto iocled->pdata.leds = iocled->leds; 803ae027eadSAtsushi Nemoto for (i = 0; i < num; i++) { 804ae027eadSAtsushi Nemoto struct gpio_led *led = &iocled->leds[i]; 805ae027eadSAtsushi Nemoto snprintf(iocled->names[i], sizeof(iocled->names[i]), 806ae027eadSAtsushi Nemoto "iocled:%s:%u", color, i); 807ae027eadSAtsushi Nemoto led->name = iocled->names[i]; 808ae027eadSAtsushi Nemoto led->gpio = basenum + i; 809ae027eadSAtsushi Nemoto led->active_low = lowactive; 810ae027eadSAtsushi Nemoto if (deftriggers && *deftriggers) 811ae027eadSAtsushi Nemoto led->default_trigger = *deftriggers++; 812ae027eadSAtsushi Nemoto } 813ae027eadSAtsushi Nemoto pdev->dev.platform_data = &iocled->pdata; 814ae027eadSAtsushi Nemoto if (platform_device_add(pdev)) 81570ebadc8SJulia Lawall goto out_pdev; 81670ebadc8SJulia Lawall return; 81770ebadc8SJulia Lawall out_pdev: 818ae027eadSAtsushi Nemoto platform_device_put(pdev); 81970ebadc8SJulia Lawall out_gpio: 820a2e62f3aSRalf Roesch if (gpiochip_remove(&iocled->chip)) 821a2e62f3aSRalf Roesch return; 82270ebadc8SJulia Lawall out_unmap: 82370ebadc8SJulia Lawall iounmap(iocled->mmioaddr); 82470ebadc8SJulia Lawall out_free: 82570ebadc8SJulia Lawall kfree(iocled); 826ae027eadSAtsushi Nemoto } 827ae027eadSAtsushi Nemoto #else /* CONFIG_LEDS_GPIO */ 828ae027eadSAtsushi Nemoto void __init txx9_iocled_init(unsigned long baseaddr, 829ae027eadSAtsushi Nemoto int basenum, unsigned int num, int lowactive, 830ae027eadSAtsushi Nemoto const char *color, char **deftriggers) 831ae027eadSAtsushi Nemoto { 832ae027eadSAtsushi Nemoto } 833ae027eadSAtsushi Nemoto #endif /* CONFIG_LEDS_GPIO */ 834f48c8c95SAtsushi Nemoto 835f48c8c95SAtsushi Nemoto void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq, 836f48c8c95SAtsushi Nemoto const struct txx9dmac_platform_data *pdata) 837f48c8c95SAtsushi Nemoto { 838f48c8c95SAtsushi Nemoto #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE) 839f48c8c95SAtsushi Nemoto struct resource res[] = { 840f48c8c95SAtsushi Nemoto { 841f48c8c95SAtsushi Nemoto .start = baseaddr, 842f48c8c95SAtsushi Nemoto .end = baseaddr + 0x800 - 1, 843f48c8c95SAtsushi Nemoto .flags = IORESOURCE_MEM, 844f48c8c95SAtsushi Nemoto #ifndef CONFIG_MACH_TX49XX 845f48c8c95SAtsushi Nemoto }, { 846f48c8c95SAtsushi Nemoto .start = irq, 847f48c8c95SAtsushi Nemoto .flags = IORESOURCE_IRQ, 848f48c8c95SAtsushi Nemoto #endif 849f48c8c95SAtsushi Nemoto } 850f48c8c95SAtsushi Nemoto }; 851f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 852f48c8c95SAtsushi Nemoto struct resource chan_res[] = { 853f48c8c95SAtsushi Nemoto { 854f48c8c95SAtsushi Nemoto .flags = IORESOURCE_IRQ, 855f48c8c95SAtsushi Nemoto } 856f48c8c95SAtsushi Nemoto }; 857f48c8c95SAtsushi Nemoto #endif 858f48c8c95SAtsushi Nemoto struct platform_device *pdev = platform_device_alloc("txx9dmac", id); 859f48c8c95SAtsushi Nemoto struct txx9dmac_chan_platform_data cpdata; 860f48c8c95SAtsushi Nemoto int i; 861f48c8c95SAtsushi Nemoto 862f48c8c95SAtsushi Nemoto if (!pdev || 863f48c8c95SAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) || 864f48c8c95SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 865f48c8c95SAtsushi Nemoto platform_device_add(pdev)) { 866f48c8c95SAtsushi Nemoto platform_device_put(pdev); 867f48c8c95SAtsushi Nemoto return; 868f48c8c95SAtsushi Nemoto } 869f48c8c95SAtsushi Nemoto memset(&cpdata, 0, sizeof(cpdata)); 870f48c8c95SAtsushi Nemoto cpdata.dmac_dev = pdev; 871f48c8c95SAtsushi Nemoto for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) { 872f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 873f48c8c95SAtsushi Nemoto chan_res[0].start = irq + i; 874f48c8c95SAtsushi Nemoto #endif 875f48c8c95SAtsushi Nemoto pdev = platform_device_alloc("txx9dmac-chan", 876f48c8c95SAtsushi Nemoto id * TXX9_DMA_MAX_NR_CHANNELS + i); 877f48c8c95SAtsushi Nemoto if (!pdev || 878f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 879f48c8c95SAtsushi Nemoto platform_device_add_resources(pdev, chan_res, 880f48c8c95SAtsushi Nemoto ARRAY_SIZE(chan_res)) || 881f48c8c95SAtsushi Nemoto #endif 882f48c8c95SAtsushi Nemoto platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) || 883f48c8c95SAtsushi Nemoto platform_device_add(pdev)) 884f48c8c95SAtsushi Nemoto platform_device_put(pdev); 885f48c8c95SAtsushi Nemoto } 886f48c8c95SAtsushi Nemoto #endif 887f48c8c95SAtsushi Nemoto } 888742cd586SAtsushi Nemoto 889742cd586SAtsushi Nemoto void __init txx9_aclc_init(unsigned long baseaddr, int irq, 890742cd586SAtsushi Nemoto unsigned int dmac_id, 891742cd586SAtsushi Nemoto unsigned int dma_chan_out, 892742cd586SAtsushi Nemoto unsigned int dma_chan_in) 893742cd586SAtsushi Nemoto { 894742cd586SAtsushi Nemoto #if defined(CONFIG_SND_SOC_TXX9ACLC) || \ 895742cd586SAtsushi Nemoto defined(CONFIG_SND_SOC_TXX9ACLC_MODULE) 896742cd586SAtsushi Nemoto unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS; 897742cd586SAtsushi Nemoto struct resource res[] = { 898742cd586SAtsushi Nemoto { 899742cd586SAtsushi Nemoto .start = baseaddr, 900742cd586SAtsushi Nemoto .end = baseaddr + 0x100 - 1, 901742cd586SAtsushi Nemoto .flags = IORESOURCE_MEM, 902742cd586SAtsushi Nemoto }, { 903742cd586SAtsushi Nemoto .start = irq, 904742cd586SAtsushi Nemoto .flags = IORESOURCE_IRQ, 905742cd586SAtsushi Nemoto }, { 906742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 907742cd586SAtsushi Nemoto .start = dma_base + dma_chan_out, 908742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 909742cd586SAtsushi Nemoto }, { 910742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 911742cd586SAtsushi Nemoto .start = dma_base + dma_chan_in, 912742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 913742cd586SAtsushi Nemoto } 914742cd586SAtsushi Nemoto }; 915742cd586SAtsushi Nemoto struct platform_device *pdev = 916742cd586SAtsushi Nemoto platform_device_alloc("txx9aclc-ac97", -1); 917742cd586SAtsushi Nemoto 918742cd586SAtsushi Nemoto if (!pdev || 919742cd586SAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) || 920742cd586SAtsushi Nemoto platform_device_add(pdev)) 921742cd586SAtsushi Nemoto platform_device_put(pdev); 922742cd586SAtsushi Nemoto #endif 923742cd586SAtsushi Nemoto } 924c3b28ae2SAtsushi Nemoto 925c3b28ae2SAtsushi Nemoto static struct sysdev_class txx9_sramc_sysdev_class; 926c3b28ae2SAtsushi Nemoto 927c3b28ae2SAtsushi Nemoto struct txx9_sramc_sysdev { 928c3b28ae2SAtsushi Nemoto struct sys_device dev; 929c3b28ae2SAtsushi Nemoto struct bin_attribute bindata_attr; 930c3b28ae2SAtsushi Nemoto void __iomem *base; 931c3b28ae2SAtsushi Nemoto }; 932c3b28ae2SAtsushi Nemoto 933c3b28ae2SAtsushi Nemoto static ssize_t txx9_sram_read(struct kobject *kobj, 934c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 935c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 936c3b28ae2SAtsushi Nemoto { 937c3b28ae2SAtsushi Nemoto struct txx9_sramc_sysdev *dev = bin_attr->private; 938c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 939c3b28ae2SAtsushi Nemoto 940c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 941c3b28ae2SAtsushi Nemoto return 0; 942c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 943c3b28ae2SAtsushi Nemoto size = ramsize - pos; 944c3b28ae2SAtsushi Nemoto memcpy_fromio(buf, dev->base + pos, size); 945c3b28ae2SAtsushi Nemoto return size; 946c3b28ae2SAtsushi Nemoto } 947c3b28ae2SAtsushi Nemoto 948c3b28ae2SAtsushi Nemoto static ssize_t txx9_sram_write(struct kobject *kobj, 949c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 950c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 951c3b28ae2SAtsushi Nemoto { 952c3b28ae2SAtsushi Nemoto struct txx9_sramc_sysdev *dev = bin_attr->private; 953c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 954c3b28ae2SAtsushi Nemoto 955c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 956c3b28ae2SAtsushi Nemoto return 0; 957c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 958c3b28ae2SAtsushi Nemoto size = ramsize - pos; 959c3b28ae2SAtsushi Nemoto memcpy_toio(dev->base + pos, buf, size); 960c3b28ae2SAtsushi Nemoto return size; 961c3b28ae2SAtsushi Nemoto } 962c3b28ae2SAtsushi Nemoto 963c3b28ae2SAtsushi Nemoto void __init txx9_sramc_init(struct resource *r) 964c3b28ae2SAtsushi Nemoto { 965c3b28ae2SAtsushi Nemoto struct txx9_sramc_sysdev *dev; 966c3b28ae2SAtsushi Nemoto size_t size; 967c3b28ae2SAtsushi Nemoto int err; 968c3b28ae2SAtsushi Nemoto 969c3b28ae2SAtsushi Nemoto if (!txx9_sramc_sysdev_class.name) { 970c3b28ae2SAtsushi Nemoto txx9_sramc_sysdev_class.name = "txx9_sram"; 971c3b28ae2SAtsushi Nemoto err = sysdev_class_register(&txx9_sramc_sysdev_class); 972c3b28ae2SAtsushi Nemoto if (err) { 973c3b28ae2SAtsushi Nemoto txx9_sramc_sysdev_class.name = NULL; 974c3b28ae2SAtsushi Nemoto return; 975c3b28ae2SAtsushi Nemoto } 976c3b28ae2SAtsushi Nemoto } 977c3b28ae2SAtsushi Nemoto dev = kzalloc(sizeof(*dev), GFP_KERNEL); 978c3b28ae2SAtsushi Nemoto if (!dev) 979c3b28ae2SAtsushi Nemoto return; 980c3b28ae2SAtsushi Nemoto size = resource_size(r); 981c3b28ae2SAtsushi Nemoto dev->base = ioremap(r->start, size); 982c3b28ae2SAtsushi Nemoto if (!dev->base) 983c3b28ae2SAtsushi Nemoto goto exit; 984c3b28ae2SAtsushi Nemoto dev->dev.cls = &txx9_sramc_sysdev_class; 985c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.name = "bindata"; 986c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR; 987c3b28ae2SAtsushi Nemoto dev->bindata_attr.read = txx9_sram_read; 988c3b28ae2SAtsushi Nemoto dev->bindata_attr.write = txx9_sram_write; 989c3b28ae2SAtsushi Nemoto dev->bindata_attr.size = size; 990c3b28ae2SAtsushi Nemoto dev->bindata_attr.private = dev; 991c3b28ae2SAtsushi Nemoto err = sysdev_register(&dev->dev); 992c3b28ae2SAtsushi Nemoto if (err) 993c3b28ae2SAtsushi Nemoto goto exit; 994c3b28ae2SAtsushi Nemoto err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr); 995c3b28ae2SAtsushi Nemoto if (err) { 996c3b28ae2SAtsushi Nemoto sysdev_unregister(&dev->dev); 997c3b28ae2SAtsushi Nemoto goto exit; 998c3b28ae2SAtsushi Nemoto } 999c3b28ae2SAtsushi Nemoto return; 1000c3b28ae2SAtsushi Nemoto exit: 1001c3b28ae2SAtsushi Nemoto if (dev) { 1002c3b28ae2SAtsushi Nemoto if (dev->base) 1003c3b28ae2SAtsushi Nemoto iounmap(dev->base); 1004c3b28ae2SAtsushi Nemoto kfree(dev); 1005c3b28ae2SAtsushi Nemoto } 1006c3b28ae2SAtsushi Nemoto } 1007