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> 25*269a3eb1SKay Sievers #include <linux/device.h> 265a0e3ad6STejun Heo #include <linux/slab.h> 27ca4d3e67SDavid Howells #include <linux/irq.h> 28edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 29e0eb7307SAtsushi Nemoto #include <asm/time.h> 30a49297e8SAtsushi Nemoto #include <asm/reboot.h> 31d10e025fSAtsushi Nemoto #include <asm/r4kcache.h> 32b6263ff2SAtsushi Nemoto #include <asm/sections.h> 3389d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 3407517529SAtsushi Nemoto #include <asm/txx9/pci.h> 35496a3b5cSAtsushi Nemoto #include <asm/txx9tmr.h> 36a591f5d3SAtsushi Nemoto #include <asm/txx9/ndfmc.h> 37f48c8c95SAtsushi Nemoto #include <asm/txx9/dmac.h> 38edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 39edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 40edcaf1a6SAtsushi Nemoto #endif 4189d63fe1SAtsushi Nemoto 4289d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 4389d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 4489d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 4589d63fe1SAtsushi Nemoto 4689d63fe1SAtsushi Nemoto /* pcode, internal register */ 4794a4c329SAtsushi Nemoto unsigned int txx9_pcode; 4889d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 4989d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 5089d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 5189d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 5289d63fe1SAtsushi Nemoto }; 5389d63fe1SAtsushi Nemoto void __init 5489d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 5589d63fe1SAtsushi Nemoto { 5689d63fe1SAtsushi Nemoto int i; 5789d63fe1SAtsushi Nemoto 5889d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 5989d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 6089d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 6189d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 6289d63fe1SAtsushi Nemoto } 6389d63fe1SAtsushi Nemoto 64073828d0SAtsushi Nemoto txx9_pcode = pcode; 6589d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 6689d63fe1SAtsushi Nemoto if (base) { 6789d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 6889d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 6989d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 7089d63fe1SAtsushi Nemoto } 7189d63fe1SAtsushi Nemoto } 7289d63fe1SAtsushi Nemoto 7389d63fe1SAtsushi Nemoto /* clocks */ 7489d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 7589d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 7689d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 77edcaf1a6SAtsushi Nemoto 78c7b95bcbSAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 79c7b95bcbSAtsushi Nemoto /* don't enable by default - see errata */ 80c7b95bcbSAtsushi Nemoto int txx9_ccfg_toeon __initdata; 81c7b95bcbSAtsushi Nemoto #else 8294a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 83c7b95bcbSAtsushi Nemoto #endif 84edcaf1a6SAtsushi Nemoto 85edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 86edcaf1a6SAtsushi Nemoto 87edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 88edcaf1a6SAtsushi Nemoto { 89edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 90fcc152f3SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2); 91edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 9294a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 93edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 94edcaf1a6SAtsushi Nemoto } 95edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 96edcaf1a6SAtsushi Nemoto 97edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 98edcaf1a6SAtsushi Nemoto { 99edcaf1a6SAtsushi Nemoto return 0; 100edcaf1a6SAtsushi Nemoto } 101edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 102edcaf1a6SAtsushi Nemoto 103edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 104edcaf1a6SAtsushi Nemoto { 105edcaf1a6SAtsushi Nemoto } 106edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 107edcaf1a6SAtsushi Nemoto 108edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 109edcaf1a6SAtsushi Nemoto { 110edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 111edcaf1a6SAtsushi Nemoto } 112edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 113edcaf1a6SAtsushi Nemoto 114edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 115edcaf1a6SAtsushi Nemoto { 116edcaf1a6SAtsushi Nemoto } 117edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 118edcaf1a6SAtsushi Nemoto 1198d795f2aSAtsushi Nemoto /* GPIO support */ 1208d795f2aSAtsushi Nemoto 1218d795f2aSAtsushi Nemoto #ifdef CONFIG_GENERIC_GPIO 1228d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1238d795f2aSAtsushi Nemoto { 1248d795f2aSAtsushi Nemoto return -EINVAL; 1258d795f2aSAtsushi Nemoto } 1268d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1278d795f2aSAtsushi Nemoto 1288d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1298d795f2aSAtsushi Nemoto { 1308d795f2aSAtsushi Nemoto return -EINVAL; 1318d795f2aSAtsushi Nemoto } 1328d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1338d795f2aSAtsushi Nemoto #endif 1348d795f2aSAtsushi Nemoto 135860e546cSAtsushi Nemoto #define BOARD_VEC(board) extern struct txx9_board_vec board; 136860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 137860e546cSAtsushi Nemoto #undef BOARD_VEC 138edcaf1a6SAtsushi Nemoto 139edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 140edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 141edcaf1a6SAtsushi Nemoto 142860e546cSAtsushi Nemoto static struct txx9_board_vec *board_vecs[] __initdata = { 143860e546cSAtsushi Nemoto #define BOARD_VEC(board) &board, 144860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 145860e546cSAtsushi Nemoto #undef BOARD_VEC 146860e546cSAtsushi Nemoto }; 147860e546cSAtsushi Nemoto 148860e546cSAtsushi Nemoto static struct txx9_board_vec *__init find_board_byname(const char *name) 149860e546cSAtsushi Nemoto { 150860e546cSAtsushi Nemoto int i; 151860e546cSAtsushi Nemoto 152860e546cSAtsushi Nemoto /* search board_vecs table */ 153860e546cSAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(board_vecs); i++) { 154860e546cSAtsushi Nemoto if (strstr(board_vecs[i]->system, name)) 155860e546cSAtsushi Nemoto return board_vecs[i]; 156860e546cSAtsushi Nemoto } 157860e546cSAtsushi Nemoto return NULL; 158860e546cSAtsushi Nemoto } 159860e546cSAtsushi Nemoto 160e0dfb20cSAtsushi Nemoto static void __init prom_init_cmdline(void) 161edcaf1a6SAtsushi Nemoto { 16297b0511cSGeert Uytterhoeven int argc; 16397b0511cSGeert Uytterhoeven int *argv32; 164edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 165edcaf1a6SAtsushi Nemoto 16697b0511cSGeert Uytterhoeven if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) { 16797b0511cSGeert Uytterhoeven /* 16897b0511cSGeert Uytterhoeven * argc is not a valid number, or argv32 is not a valid 16997b0511cSGeert Uytterhoeven * pointer 17097b0511cSGeert Uytterhoeven */ 17197b0511cSGeert Uytterhoeven argc = 0; 17297b0511cSGeert Uytterhoeven argv32 = NULL; 17397b0511cSGeert Uytterhoeven } else { 17497b0511cSGeert Uytterhoeven argc = (int)fw_arg0; 17597b0511cSGeert Uytterhoeven argv32 = (int *)fw_arg1; 17697b0511cSGeert Uytterhoeven } 17797b0511cSGeert Uytterhoeven 178e0dfb20cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 179edcaf1a6SAtsushi Nemoto 180edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 181e0dfb20cSAtsushi Nemoto char *str = (char *)(long)argv32[i]; 182edcaf1a6SAtsushi Nemoto if (i != 1) 183edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 184e0dfb20cSAtsushi Nemoto if (strchr(str, ' ')) { 185e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 186e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 187e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 188e0dfb20cSAtsushi Nemoto } else 189e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 190e0dfb20cSAtsushi Nemoto } 191edcaf1a6SAtsushi Nemoto } 192edcaf1a6SAtsushi Nemoto 193d10e025fSAtsushi Nemoto static int txx9_ic_disable __initdata; 194d10e025fSAtsushi Nemoto static int txx9_dc_disable __initdata; 195d10e025fSAtsushi Nemoto 196d10e025fSAtsushi Nemoto #if defined(CONFIG_CPU_TX49XX) 197d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before 4k_cache_init) */ 198d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 199d10e025fSAtsushi Nemoto { 200d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 201d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6)); 202d10e025fSAtsushi Nemoto unsigned int linesz = 32; 203d10e025fSAtsushi Nemoto unsigned long addr, end; 204d10e025fSAtsushi Nemoto 205d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 4; 206d10e025fSAtsushi Nemoto /* 4way, waybit=0 */ 207d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 208d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 209d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 210d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 2); 211d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 3); 212d10e025fSAtsushi Nemoto } 213d10e025fSAtsushi Nemoto } 214d10e025fSAtsushi Nemoto 215d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 216d10e025fSAtsushi Nemoto { 217d10e025fSAtsushi Nemoto unsigned int conf; 218d10e025fSAtsushi Nemoto 219d10e025fSAtsushi Nemoto conf = read_c0_config(); 220d10e025fSAtsushi Nemoto /* flush and disable */ 221d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 222d10e025fSAtsushi Nemoto conf |= TX49_CONF_IC; 223d10e025fSAtsushi Nemoto write_c0_config(conf); 224d10e025fSAtsushi Nemoto } 225d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 226d10e025fSAtsushi Nemoto early_flush_dcache(); 227d10e025fSAtsushi Nemoto conf |= TX49_CONF_DC; 228d10e025fSAtsushi Nemoto write_c0_config(conf); 229d10e025fSAtsushi Nemoto } 230d10e025fSAtsushi Nemoto 231d10e025fSAtsushi Nemoto /* enable cache */ 232d10e025fSAtsushi Nemoto conf = read_c0_config(); 233d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 234d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_IC; 235d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 236d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_DC; 237d10e025fSAtsushi Nemoto write_c0_config(conf); 238d10e025fSAtsushi Nemoto 239d10e025fSAtsushi Nemoto if (conf & TX49_CONF_IC) 240d10e025fSAtsushi Nemoto pr_info("TX49XX I-Cache disabled.\n"); 241d10e025fSAtsushi Nemoto if (conf & TX49_CONF_DC) 242d10e025fSAtsushi Nemoto pr_info("TX49XX D-Cache disabled.\n"); 243d10e025fSAtsushi Nemoto } 244d10e025fSAtsushi Nemoto #elif defined(CONFIG_CPU_TX39XX) 245d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before tx39_cache_init) */ 246d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 247d10e025fSAtsushi Nemoto { 248d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 249d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >> 250d10e025fSAtsushi Nemoto TX39_CONF_DCS_SHIFT)); 251d10e025fSAtsushi Nemoto unsigned int linesz = 16; 252d10e025fSAtsushi Nemoto unsigned long addr, end; 253d10e025fSAtsushi Nemoto 254d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 2; 255d10e025fSAtsushi Nemoto /* 2way, waybit=0 */ 256d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 257d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 258d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 259d10e025fSAtsushi Nemoto } 260d10e025fSAtsushi Nemoto } 261d10e025fSAtsushi Nemoto 262d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 263d10e025fSAtsushi Nemoto { 264d10e025fSAtsushi Nemoto unsigned int conf; 265d10e025fSAtsushi Nemoto 266d10e025fSAtsushi Nemoto conf = read_c0_config(); 267d10e025fSAtsushi Nemoto /* flush and disable */ 268d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 269d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_ICE; 270d10e025fSAtsushi Nemoto write_c0_config(conf); 271d10e025fSAtsushi Nemoto } 272d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 273d10e025fSAtsushi Nemoto early_flush_dcache(); 274d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_DCE; 275d10e025fSAtsushi Nemoto write_c0_config(conf); 276d10e025fSAtsushi Nemoto } 277d10e025fSAtsushi Nemoto 278d10e025fSAtsushi Nemoto /* enable cache */ 279d10e025fSAtsushi Nemoto conf = read_c0_config(); 280d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 281d10e025fSAtsushi Nemoto conf |= TX39_CONF_ICE; 282d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 283d10e025fSAtsushi Nemoto conf |= TX39_CONF_DCE; 284d10e025fSAtsushi Nemoto write_c0_config(conf); 285d10e025fSAtsushi Nemoto 286d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_ICE)) 287d10e025fSAtsushi Nemoto pr_info("TX39XX I-Cache disabled.\n"); 288d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_DCE)) 289d10e025fSAtsushi Nemoto pr_info("TX39XX D-Cache disabled.\n"); 290d10e025fSAtsushi Nemoto } 291d10e025fSAtsushi Nemoto #else 292d10e025fSAtsushi Nemoto static inline void txx9_cache_fixup(void) 293d10e025fSAtsushi Nemoto { 294d10e025fSAtsushi Nemoto } 295d10e025fSAtsushi Nemoto #endif 296d10e025fSAtsushi Nemoto 297860e546cSAtsushi Nemoto static void __init preprocess_cmdline(void) 298edcaf1a6SAtsushi Nemoto { 2997580c9c3SDmitri Vorobiev static char cmdline[COMMAND_LINE_SIZE] __initdata; 300860e546cSAtsushi Nemoto char *s; 301860e546cSAtsushi Nemoto 302860e546cSAtsushi Nemoto strcpy(cmdline, arcs_cmdline); 303860e546cSAtsushi Nemoto s = cmdline; 304860e546cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 305860e546cSAtsushi Nemoto while (s && *s) { 306860e546cSAtsushi Nemoto char *str = strsep(&s, " "); 307860e546cSAtsushi Nemoto if (strncmp(str, "board=", 6) == 0) { 308860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(str + 6); 309860e546cSAtsushi Nemoto continue; 310860e546cSAtsushi Nemoto } else if (strncmp(str, "masterclk=", 10) == 0) { 311860e546cSAtsushi Nemoto unsigned long val; 312860e546cSAtsushi Nemoto if (strict_strtoul(str + 10, 10, &val) == 0) 313860e546cSAtsushi Nemoto txx9_master_clock = val; 314860e546cSAtsushi Nemoto continue; 315d10e025fSAtsushi Nemoto } else if (strcmp(str, "icdisable") == 0) { 316d10e025fSAtsushi Nemoto txx9_ic_disable = 1; 317d10e025fSAtsushi Nemoto continue; 318d10e025fSAtsushi Nemoto } else if (strcmp(str, "dcdisable") == 0) { 319d10e025fSAtsushi Nemoto txx9_dc_disable = 1; 320d10e025fSAtsushi Nemoto continue; 321c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeoff") == 0) { 322c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 0; 323c7b95bcbSAtsushi Nemoto continue; 324c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeon") == 0) { 325c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 1; 326c7b95bcbSAtsushi Nemoto continue; 327860e546cSAtsushi Nemoto } 328860e546cSAtsushi Nemoto if (arcs_cmdline[0]) 329860e546cSAtsushi Nemoto strcat(arcs_cmdline, " "); 330860e546cSAtsushi Nemoto strcat(arcs_cmdline, str); 331860e546cSAtsushi Nemoto } 332d10e025fSAtsushi Nemoto 333d10e025fSAtsushi Nemoto txx9_cache_fixup(); 334860e546cSAtsushi Nemoto } 335860e546cSAtsushi Nemoto 336860e546cSAtsushi Nemoto static void __init select_board(void) 337860e546cSAtsushi Nemoto { 338860e546cSAtsushi Nemoto const char *envstr; 339860e546cSAtsushi Nemoto 340860e546cSAtsushi Nemoto /* first, determine by "board=" argument in preprocess_cmdline() */ 341860e546cSAtsushi Nemoto if (txx9_board_vec) 342860e546cSAtsushi Nemoto return; 343860e546cSAtsushi Nemoto /* next, determine by "board" envvar */ 344860e546cSAtsushi Nemoto envstr = prom_getenv("board"); 345860e546cSAtsushi Nemoto if (envstr) { 346860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(envstr); 347860e546cSAtsushi Nemoto if (txx9_board_vec) 348860e546cSAtsushi Nemoto return; 349860e546cSAtsushi Nemoto } 350860e546cSAtsushi Nemoto 351860e546cSAtsushi Nemoto /* select "default" board */ 352edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 3537a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 354edcaf1a6SAtsushi Nemoto #endif 355edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 356edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 3578d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 358edcaf1a6SAtsushi Nemoto case 0x4927: 3597a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 360edcaf1a6SAtsushi Nemoto break; 361edcaf1a6SAtsushi Nemoto case 0x4937: 3627a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 363edcaf1a6SAtsushi Nemoto break; 3648d795f2aSAtsushi Nemoto #endif 3658d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 366edcaf1a6SAtsushi Nemoto case 0x4938: 3677a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 368edcaf1a6SAtsushi Nemoto break; 3698d795f2aSAtsushi Nemoto #endif 370b27311e1SAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4939 371b27311e1SAtsushi Nemoto case 0x4939: 372b27311e1SAtsushi Nemoto txx9_board_vec = &rbtx4939_vec; 373b27311e1SAtsushi Nemoto break; 374b27311e1SAtsushi Nemoto #endif 375edcaf1a6SAtsushi Nemoto } 376edcaf1a6SAtsushi Nemoto #endif 377860e546cSAtsushi Nemoto } 378860e546cSAtsushi Nemoto 379860e546cSAtsushi Nemoto void __init prom_init(void) 380860e546cSAtsushi Nemoto { 381860e546cSAtsushi Nemoto prom_init_cmdline(); 382860e546cSAtsushi Nemoto preprocess_cmdline(); 383860e546cSAtsushi Nemoto select_board(); 3847a1fdf19SYoichi Yuasa 385edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 3867a1fdf19SYoichi Yuasa 3877b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 388edcaf1a6SAtsushi Nemoto } 389edcaf1a6SAtsushi Nemoto 390edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 391edcaf1a6SAtsushi Nemoto { 392b6263ff2SAtsushi Nemoto unsigned long saddr = PAGE_SIZE; 393b6263ff2SAtsushi Nemoto unsigned long eaddr = __pa_symbol(&_text); 394b6263ff2SAtsushi Nemoto 395b6263ff2SAtsushi Nemoto if (saddr < eaddr) 396b6263ff2SAtsushi Nemoto free_init_pages("prom memory", saddr, eaddr); 397edcaf1a6SAtsushi Nemoto } 398edcaf1a6SAtsushi Nemoto 399edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 400edcaf1a6SAtsushi Nemoto { 401edcaf1a6SAtsushi Nemoto return txx9_system_type; 402edcaf1a6SAtsushi Nemoto } 403edcaf1a6SAtsushi Nemoto 404265b89dbSAtsushi Nemoto const char *__init prom_getenv(const char *name) 405265b89dbSAtsushi Nemoto { 40697b0511cSGeert Uytterhoeven const s32 *str; 407265b89dbSAtsushi Nemoto 40897b0511cSGeert Uytterhoeven if (fw_arg2 < CKSEG0) 409265b89dbSAtsushi Nemoto return NULL; 41097b0511cSGeert Uytterhoeven 41197b0511cSGeert Uytterhoeven str = (const s32 *)fw_arg2; 412265b89dbSAtsushi Nemoto /* YAMON style ("name", "value" pairs) */ 413265b89dbSAtsushi Nemoto while (str[0] && str[1]) { 414265b89dbSAtsushi Nemoto if (!strcmp((const char *)(unsigned long)str[0], name)) 415265b89dbSAtsushi Nemoto return (const char *)(unsigned long)str[1]; 416265b89dbSAtsushi Nemoto str += 2; 417265b89dbSAtsushi Nemoto } 418265b89dbSAtsushi Nemoto return NULL; 419265b89dbSAtsushi Nemoto } 420265b89dbSAtsushi Nemoto 421a49297e8SAtsushi Nemoto static void __noreturn txx9_machine_halt(void) 422a49297e8SAtsushi Nemoto { 423a49297e8SAtsushi Nemoto local_irq_disable(); 424a49297e8SAtsushi Nemoto clear_c0_status(ST0_IM); 425a49297e8SAtsushi Nemoto while (1) { 426a49297e8SAtsushi Nemoto if (cpu_wait) { 427a49297e8SAtsushi Nemoto (*cpu_wait)(); 428a49297e8SAtsushi Nemoto if (cpu_has_counter) { 429a49297e8SAtsushi Nemoto /* 430a49297e8SAtsushi Nemoto * Clear counter interrupt while it 431a49297e8SAtsushi Nemoto * breaks WAIT instruction even if 432a49297e8SAtsushi Nemoto * masked. 433a49297e8SAtsushi Nemoto */ 434a49297e8SAtsushi Nemoto write_c0_compare(0); 435a49297e8SAtsushi Nemoto } 436a49297e8SAtsushi Nemoto } 437a49297e8SAtsushi Nemoto } 438a49297e8SAtsushi Nemoto } 439a49297e8SAtsushi Nemoto 44068314725SAtsushi Nemoto /* Watchdog support */ 44168314725SAtsushi Nemoto void __init txx9_wdt_init(unsigned long base) 44268314725SAtsushi Nemoto { 44368314725SAtsushi Nemoto struct resource res = { 44468314725SAtsushi Nemoto .start = base, 44568314725SAtsushi Nemoto .end = base + 0x100 - 1, 44668314725SAtsushi Nemoto .flags = IORESOURCE_MEM, 44768314725SAtsushi Nemoto }; 44868314725SAtsushi Nemoto platform_device_register_simple("txx9wdt", -1, &res, 1); 44968314725SAtsushi Nemoto } 45068314725SAtsushi Nemoto 451496a3b5cSAtsushi Nemoto void txx9_wdt_now(unsigned long base) 452496a3b5cSAtsushi Nemoto { 453496a3b5cSAtsushi Nemoto struct txx9_tmr_reg __iomem *tmrptr = 454496a3b5cSAtsushi Nemoto ioremap(base, sizeof(struct txx9_tmr_reg)); 455496a3b5cSAtsushi Nemoto /* disable watch dog timer */ 456496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr); 457496a3b5cSAtsushi Nemoto __raw_writel(0, &tmrptr->tcr); 458496a3b5cSAtsushi Nemoto /* kick watchdog */ 459496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr); 460496a3b5cSAtsushi Nemoto __raw_writel(1, &tmrptr->cpra); /* immediate */ 461496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG, 462496a3b5cSAtsushi Nemoto &tmrptr->tcr); 463496a3b5cSAtsushi Nemoto } 464496a3b5cSAtsushi Nemoto 465c49f91f5SAtsushi Nemoto /* SPI support */ 466c49f91f5SAtsushi Nemoto void __init txx9_spi_init(int busid, unsigned long base, int irq) 467c49f91f5SAtsushi Nemoto { 468c49f91f5SAtsushi Nemoto struct resource res[] = { 469c49f91f5SAtsushi Nemoto { 470c49f91f5SAtsushi Nemoto .start = base, 471c49f91f5SAtsushi Nemoto .end = base + 0x20 - 1, 472c49f91f5SAtsushi Nemoto .flags = IORESOURCE_MEM, 473c49f91f5SAtsushi Nemoto }, { 474c49f91f5SAtsushi Nemoto .start = irq, 475c49f91f5SAtsushi Nemoto .flags = IORESOURCE_IRQ, 476c49f91f5SAtsushi Nemoto }, 477c49f91f5SAtsushi Nemoto }; 478c49f91f5SAtsushi Nemoto platform_device_register_simple("spi_txx9", busid, 479c49f91f5SAtsushi Nemoto res, ARRAY_SIZE(res)); 480c49f91f5SAtsushi Nemoto } 481c49f91f5SAtsushi Nemoto 482c49f91f5SAtsushi Nemoto void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) 483c49f91f5SAtsushi Nemoto { 484c49f91f5SAtsushi Nemoto struct platform_device *pdev = 485c49f91f5SAtsushi Nemoto platform_device_alloc("tc35815-mac", id); 486c49f91f5SAtsushi Nemoto if (!pdev || 487c49f91f5SAtsushi Nemoto platform_device_add_data(pdev, ethaddr, 6) || 488c49f91f5SAtsushi Nemoto platform_device_add(pdev)) 489c49f91f5SAtsushi Nemoto platform_device_put(pdev); 490c49f91f5SAtsushi Nemoto } 491c49f91f5SAtsushi Nemoto 4927779a5e0SAtsushi Nemoto void __init txx9_sio_init(unsigned long baseaddr, int irq, 4937779a5e0SAtsushi Nemoto unsigned int line, unsigned int sclk, int nocts) 4947779a5e0SAtsushi Nemoto { 4957779a5e0SAtsushi Nemoto #ifdef CONFIG_SERIAL_TXX9 4967779a5e0SAtsushi Nemoto struct uart_port req; 4977779a5e0SAtsushi Nemoto 4987779a5e0SAtsushi Nemoto memset(&req, 0, sizeof(req)); 4997779a5e0SAtsushi Nemoto req.line = line; 5007779a5e0SAtsushi Nemoto req.iotype = UPIO_MEM; 5017779a5e0SAtsushi Nemoto req.membase = ioremap(baseaddr, 0x24); 5027779a5e0SAtsushi Nemoto req.mapbase = baseaddr; 5037779a5e0SAtsushi Nemoto req.irq = irq; 5047779a5e0SAtsushi Nemoto if (!nocts) 5057779a5e0SAtsushi Nemoto req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; 5067779a5e0SAtsushi Nemoto if (sclk) { 5077779a5e0SAtsushi Nemoto req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; 5087779a5e0SAtsushi Nemoto req.uartclk = sclk; 5097779a5e0SAtsushi Nemoto } else 5107779a5e0SAtsushi Nemoto req.uartclk = TXX9_IMCLK; 5117779a5e0SAtsushi Nemoto early_serial_txx9_setup(&req); 5127779a5e0SAtsushi Nemoto #endif /* CONFIG_SERIAL_TXX9 */ 5137779a5e0SAtsushi Nemoto } 5147779a5e0SAtsushi Nemoto 515e352953cSAtsushi Nemoto #ifdef CONFIG_EARLY_PRINTK 516e352953cSAtsushi Nemoto static void __init null_prom_putchar(char c) 517e352953cSAtsushi Nemoto { 518e352953cSAtsushi Nemoto } 519e352953cSAtsushi Nemoto void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar; 520e352953cSAtsushi Nemoto 521e352953cSAtsushi Nemoto void __init prom_putchar(char c) 522e352953cSAtsushi Nemoto { 523e352953cSAtsushi Nemoto txx9_prom_putchar(c); 524e352953cSAtsushi Nemoto } 525e352953cSAtsushi Nemoto 526e352953cSAtsushi Nemoto static void __iomem *early_txx9_sio_port; 527e352953cSAtsushi Nemoto 528e352953cSAtsushi Nemoto static void __init early_txx9_sio_putchar(char c) 529e352953cSAtsushi Nemoto { 530e352953cSAtsushi Nemoto #define TXX9_SICISR 0x0c 531e352953cSAtsushi Nemoto #define TXX9_SITFIFO 0x1c 532e352953cSAtsushi Nemoto #define TXX9_SICISR_TXALS 0x00000002 533e352953cSAtsushi Nemoto while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) & 534e352953cSAtsushi Nemoto TXX9_SICISR_TXALS)) 535e352953cSAtsushi Nemoto ; 536e352953cSAtsushi Nemoto __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO); 537e352953cSAtsushi Nemoto } 538e352953cSAtsushi Nemoto 539e352953cSAtsushi Nemoto void __init txx9_sio_putchar_init(unsigned long baseaddr) 540e352953cSAtsushi Nemoto { 541e352953cSAtsushi Nemoto early_txx9_sio_port = ioremap(baseaddr, 0x24); 542e352953cSAtsushi Nemoto txx9_prom_putchar = early_txx9_sio_putchar; 543e352953cSAtsushi Nemoto } 544e352953cSAtsushi Nemoto #endif /* CONFIG_EARLY_PRINTK */ 545e352953cSAtsushi Nemoto 546edcaf1a6SAtsushi Nemoto /* wrappers */ 547edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 548edcaf1a6SAtsushi Nemoto { 54994a4c329SAtsushi Nemoto ioport_resource.start = 0; 55094a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 55194a4c329SAtsushi Nemoto iomem_resource.start = 0; 55294a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 553a49297e8SAtsushi Nemoto 554a49297e8SAtsushi Nemoto /* fallback restart/halt routines */ 555a49297e8SAtsushi Nemoto _machine_restart = (void (*)(char *))txx9_machine_halt; 556a49297e8SAtsushi Nemoto _machine_halt = txx9_machine_halt; 557a49297e8SAtsushi Nemoto pm_power_off = txx9_machine_halt; 558a49297e8SAtsushi Nemoto 55907517529SAtsushi Nemoto #ifdef CONFIG_PCI 56007517529SAtsushi Nemoto pcibios_plat_setup = txx9_pcibios_setup; 56107517529SAtsushi Nemoto #endif 562edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 563edcaf1a6SAtsushi Nemoto } 564edcaf1a6SAtsushi Nemoto 565edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 566edcaf1a6SAtsushi Nemoto { 567edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 568edcaf1a6SAtsushi Nemoto } 569edcaf1a6SAtsushi Nemoto 570edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 571edcaf1a6SAtsushi Nemoto { 5721374d084SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 5731374d084SAtsushi Nemoto mips_hpt_frequency = txx9_cpu_clock / 2; 5741374d084SAtsushi Nemoto #endif 575edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 576edcaf1a6SAtsushi Nemoto } 577edcaf1a6SAtsushi Nemoto 578edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 579edcaf1a6SAtsushi Nemoto { 580edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 581edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 582edcaf1a6SAtsushi Nemoto return 0; 583edcaf1a6SAtsushi Nemoto } 584edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 585edcaf1a6SAtsushi Nemoto 586edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 587edcaf1a6SAtsushi Nemoto { 588edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 589edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 590edcaf1a6SAtsushi Nemoto return 0; 591edcaf1a6SAtsushi Nemoto } 592edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 593edcaf1a6SAtsushi Nemoto 594edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 595edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 596edcaf1a6SAtsushi Nemoto { 597edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 598edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 599edcaf1a6SAtsushi Nemoto 600edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 601edcaf1a6SAtsushi Nemoto do_IRQ(irq); 602edcaf1a6SAtsushi Nemoto else 603edcaf1a6SAtsushi Nemoto spurious_interrupt(); 604edcaf1a6SAtsushi Nemoto } 6054c642f3fSAtsushi Nemoto 6064c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 6074c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 6084c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 6094c642f3fSAtsushi Nemoto { 6104c642f3fSAtsushi Nemoto return port; 6114c642f3fSAtsushi Nemoto } 6124c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 6134c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 6144c642f3fSAtsushi Nemoto #endif 61551f607c7SAtsushi Nemoto 6161ba5a176SAtsushi Nemoto #ifdef NEEDS_TXX9_IOSWABW 6171ba5a176SAtsushi Nemoto static u16 ioswabw_default(volatile u16 *a, u16 x) 6181ba5a176SAtsushi Nemoto { 6191ba5a176SAtsushi Nemoto return le16_to_cpu(x); 6201ba5a176SAtsushi Nemoto } 6211ba5a176SAtsushi Nemoto static u16 __mem_ioswabw_default(volatile u16 *a, u16 x) 6221ba5a176SAtsushi Nemoto { 6231ba5a176SAtsushi Nemoto return x; 6241ba5a176SAtsushi Nemoto } 6251ba5a176SAtsushi Nemoto u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default; 6261ba5a176SAtsushi Nemoto EXPORT_SYMBOL(ioswabw); 6271ba5a176SAtsushi Nemoto u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default; 6281ba5a176SAtsushi Nemoto EXPORT_SYMBOL(__mem_ioswabw); 6291ba5a176SAtsushi Nemoto #endif 6301ba5a176SAtsushi Nemoto 63151f607c7SAtsushi Nemoto void __init txx9_physmap_flash_init(int no, unsigned long addr, 63251f607c7SAtsushi Nemoto unsigned long size, 63351f607c7SAtsushi Nemoto const struct physmap_flash_data *pdata) 63451f607c7SAtsushi Nemoto { 63551f607c7SAtsushi Nemoto #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) 63651f607c7SAtsushi Nemoto struct resource res = { 63751f607c7SAtsushi Nemoto .start = addr, 63851f607c7SAtsushi Nemoto .end = addr + size - 1, 63951f607c7SAtsushi Nemoto .flags = IORESOURCE_MEM, 64051f607c7SAtsushi Nemoto }; 64151f607c7SAtsushi Nemoto struct platform_device *pdev; 64251f607c7SAtsushi Nemoto static struct mtd_partition parts[2]; 64351f607c7SAtsushi Nemoto struct physmap_flash_data pdata_part; 64451f607c7SAtsushi Nemoto 64551f607c7SAtsushi Nemoto /* If this area contained boot area, make separate partition */ 64651f607c7SAtsushi Nemoto if (pdata->nr_parts == 0 && !pdata->parts && 64751f607c7SAtsushi Nemoto addr < 0x1fc00000 && addr + size > 0x1fc00000 && 64851f607c7SAtsushi Nemoto !parts[0].name) { 64951f607c7SAtsushi Nemoto parts[0].name = "boot"; 65051f607c7SAtsushi Nemoto parts[0].offset = 0x1fc00000 - addr; 65151f607c7SAtsushi Nemoto parts[0].size = addr + size - 0x1fc00000; 65251f607c7SAtsushi Nemoto parts[1].name = "user"; 65351f607c7SAtsushi Nemoto parts[1].offset = 0; 65451f607c7SAtsushi Nemoto parts[1].size = 0x1fc00000 - addr; 65551f607c7SAtsushi Nemoto pdata_part = *pdata; 65651f607c7SAtsushi Nemoto pdata_part.nr_parts = ARRAY_SIZE(parts); 65751f607c7SAtsushi Nemoto pdata_part.parts = parts; 65851f607c7SAtsushi Nemoto pdata = &pdata_part; 65951f607c7SAtsushi Nemoto } 66047854888SJamie Iles 66151f607c7SAtsushi Nemoto pdev = platform_device_alloc("physmap-flash", no); 66251f607c7SAtsushi Nemoto if (!pdev || 66351f607c7SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 66451f607c7SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 66551f607c7SAtsushi Nemoto platform_device_add(pdev)) 66651f607c7SAtsushi Nemoto platform_device_put(pdev); 66751f607c7SAtsushi Nemoto #endif 66851f607c7SAtsushi Nemoto } 669ae027eadSAtsushi Nemoto 670a591f5d3SAtsushi Nemoto void __init txx9_ndfmc_init(unsigned long baseaddr, 671a591f5d3SAtsushi Nemoto const struct txx9ndfmc_platform_data *pdata) 672a591f5d3SAtsushi Nemoto { 673a591f5d3SAtsushi Nemoto #if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \ 674a591f5d3SAtsushi Nemoto defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE) 675a591f5d3SAtsushi Nemoto struct resource res = { 676a591f5d3SAtsushi Nemoto .start = baseaddr, 677a591f5d3SAtsushi Nemoto .end = baseaddr + 0x1000 - 1, 678a591f5d3SAtsushi Nemoto .flags = IORESOURCE_MEM, 679a591f5d3SAtsushi Nemoto }; 680a591f5d3SAtsushi Nemoto struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1); 681a591f5d3SAtsushi Nemoto 682a591f5d3SAtsushi Nemoto if (!pdev || 683a591f5d3SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 684a591f5d3SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 685a591f5d3SAtsushi Nemoto platform_device_add(pdev)) 686a591f5d3SAtsushi Nemoto platform_device_put(pdev); 687a591f5d3SAtsushi Nemoto #endif 688a591f5d3SAtsushi Nemoto } 689a591f5d3SAtsushi Nemoto 690ae027eadSAtsushi Nemoto #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) 691ae027eadSAtsushi Nemoto static DEFINE_SPINLOCK(txx9_iocled_lock); 692ae027eadSAtsushi Nemoto 693ae027eadSAtsushi Nemoto #define TXX9_IOCLED_MAXLEDS 8 694ae027eadSAtsushi Nemoto 695ae027eadSAtsushi Nemoto struct txx9_iocled_data { 696ae027eadSAtsushi Nemoto struct gpio_chip chip; 697ae027eadSAtsushi Nemoto u8 cur_val; 698ae027eadSAtsushi Nemoto void __iomem *mmioaddr; 699ae027eadSAtsushi Nemoto struct gpio_led_platform_data pdata; 700ae027eadSAtsushi Nemoto struct gpio_led leds[TXX9_IOCLED_MAXLEDS]; 701ae027eadSAtsushi Nemoto char names[TXX9_IOCLED_MAXLEDS][32]; 702ae027eadSAtsushi Nemoto }; 703ae027eadSAtsushi Nemoto 704ae027eadSAtsushi Nemoto static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset) 705ae027eadSAtsushi Nemoto { 706ae027eadSAtsushi Nemoto struct txx9_iocled_data *data = 707ae027eadSAtsushi Nemoto container_of(chip, struct txx9_iocled_data, chip); 708ae027eadSAtsushi Nemoto return data->cur_val & (1 << offset); 709ae027eadSAtsushi Nemoto } 710ae027eadSAtsushi Nemoto 711ae027eadSAtsushi Nemoto static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset, 712ae027eadSAtsushi Nemoto int value) 713ae027eadSAtsushi Nemoto { 714ae027eadSAtsushi Nemoto struct txx9_iocled_data *data = 715ae027eadSAtsushi Nemoto container_of(chip, struct txx9_iocled_data, chip); 716ae027eadSAtsushi Nemoto unsigned long flags; 717ae027eadSAtsushi Nemoto spin_lock_irqsave(&txx9_iocled_lock, flags); 718ae027eadSAtsushi Nemoto if (value) 719ae027eadSAtsushi Nemoto data->cur_val |= 1 << offset; 720ae027eadSAtsushi Nemoto else 721ae027eadSAtsushi Nemoto data->cur_val &= ~(1 << offset); 722ae027eadSAtsushi Nemoto writeb(data->cur_val, data->mmioaddr); 723ae027eadSAtsushi Nemoto mmiowb(); 724ae027eadSAtsushi Nemoto spin_unlock_irqrestore(&txx9_iocled_lock, flags); 725ae027eadSAtsushi Nemoto } 726ae027eadSAtsushi Nemoto 727ae027eadSAtsushi Nemoto static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset) 728ae027eadSAtsushi Nemoto { 729ae027eadSAtsushi Nemoto return 0; 730ae027eadSAtsushi Nemoto } 731ae027eadSAtsushi Nemoto 732ae027eadSAtsushi Nemoto static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset, 733ae027eadSAtsushi Nemoto int value) 734ae027eadSAtsushi Nemoto { 735ae027eadSAtsushi Nemoto txx9_iocled_set(chip, offset, value); 736ae027eadSAtsushi Nemoto return 0; 737ae027eadSAtsushi Nemoto } 738ae027eadSAtsushi Nemoto 739ae027eadSAtsushi Nemoto void __init txx9_iocled_init(unsigned long baseaddr, 740ae027eadSAtsushi Nemoto int basenum, unsigned int num, int lowactive, 741ae027eadSAtsushi Nemoto const char *color, char **deftriggers) 742ae027eadSAtsushi Nemoto { 743ae027eadSAtsushi Nemoto struct txx9_iocled_data *iocled; 744ae027eadSAtsushi Nemoto struct platform_device *pdev; 745ae027eadSAtsushi Nemoto int i; 746ae027eadSAtsushi Nemoto static char *default_triggers[] __initdata = { 747ae027eadSAtsushi Nemoto "heartbeat", 748ae027eadSAtsushi Nemoto "ide-disk", 749ae027eadSAtsushi Nemoto "nand-disk", 750ae027eadSAtsushi Nemoto NULL, 751ae027eadSAtsushi Nemoto }; 752ae027eadSAtsushi Nemoto 753ae027eadSAtsushi Nemoto if (!deftriggers) 754ae027eadSAtsushi Nemoto deftriggers = default_triggers; 755ae027eadSAtsushi Nemoto iocled = kzalloc(sizeof(*iocled), GFP_KERNEL); 756ae027eadSAtsushi Nemoto if (!iocled) 757ae027eadSAtsushi Nemoto return; 758ae027eadSAtsushi Nemoto iocled->mmioaddr = ioremap(baseaddr, 1); 759ae027eadSAtsushi Nemoto if (!iocled->mmioaddr) 76070ebadc8SJulia Lawall goto out_free; 761ae027eadSAtsushi Nemoto iocled->chip.get = txx9_iocled_get; 762ae027eadSAtsushi Nemoto iocled->chip.set = txx9_iocled_set; 763ae027eadSAtsushi Nemoto iocled->chip.direction_input = txx9_iocled_dir_in; 764ae027eadSAtsushi Nemoto iocled->chip.direction_output = txx9_iocled_dir_out; 765ae027eadSAtsushi Nemoto iocled->chip.label = "iocled"; 766ae027eadSAtsushi Nemoto iocled->chip.base = basenum; 767ae027eadSAtsushi Nemoto iocled->chip.ngpio = num; 768ae027eadSAtsushi Nemoto if (gpiochip_add(&iocled->chip)) 76970ebadc8SJulia Lawall goto out_unmap; 770ae027eadSAtsushi Nemoto if (basenum < 0) 771ae027eadSAtsushi Nemoto basenum = iocled->chip.base; 772ae027eadSAtsushi Nemoto 773ae027eadSAtsushi Nemoto pdev = platform_device_alloc("leds-gpio", basenum); 774ae027eadSAtsushi Nemoto if (!pdev) 77570ebadc8SJulia Lawall goto out_gpio; 776ae027eadSAtsushi Nemoto iocled->pdata.num_leds = num; 777ae027eadSAtsushi Nemoto iocled->pdata.leds = iocled->leds; 778ae027eadSAtsushi Nemoto for (i = 0; i < num; i++) { 779ae027eadSAtsushi Nemoto struct gpio_led *led = &iocled->leds[i]; 780ae027eadSAtsushi Nemoto snprintf(iocled->names[i], sizeof(iocled->names[i]), 781ae027eadSAtsushi Nemoto "iocled:%s:%u", color, i); 782ae027eadSAtsushi Nemoto led->name = iocled->names[i]; 783ae027eadSAtsushi Nemoto led->gpio = basenum + i; 784ae027eadSAtsushi Nemoto led->active_low = lowactive; 785ae027eadSAtsushi Nemoto if (deftriggers && *deftriggers) 786ae027eadSAtsushi Nemoto led->default_trigger = *deftriggers++; 787ae027eadSAtsushi Nemoto } 788ae027eadSAtsushi Nemoto pdev->dev.platform_data = &iocled->pdata; 789ae027eadSAtsushi Nemoto if (platform_device_add(pdev)) 79070ebadc8SJulia Lawall goto out_pdev; 79170ebadc8SJulia Lawall return; 79270ebadc8SJulia Lawall out_pdev: 793ae027eadSAtsushi Nemoto platform_device_put(pdev); 79470ebadc8SJulia Lawall out_gpio: 795a2e62f3aSRalf Roesch if (gpiochip_remove(&iocled->chip)) 796a2e62f3aSRalf Roesch return; 79770ebadc8SJulia Lawall out_unmap: 79870ebadc8SJulia Lawall iounmap(iocled->mmioaddr); 79970ebadc8SJulia Lawall out_free: 80070ebadc8SJulia Lawall kfree(iocled); 801ae027eadSAtsushi Nemoto } 802ae027eadSAtsushi Nemoto #else /* CONFIG_LEDS_GPIO */ 803ae027eadSAtsushi Nemoto void __init txx9_iocled_init(unsigned long baseaddr, 804ae027eadSAtsushi Nemoto int basenum, unsigned int num, int lowactive, 805ae027eadSAtsushi Nemoto const char *color, char **deftriggers) 806ae027eadSAtsushi Nemoto { 807ae027eadSAtsushi Nemoto } 808ae027eadSAtsushi Nemoto #endif /* CONFIG_LEDS_GPIO */ 809f48c8c95SAtsushi Nemoto 810f48c8c95SAtsushi Nemoto void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq, 811f48c8c95SAtsushi Nemoto const struct txx9dmac_platform_data *pdata) 812f48c8c95SAtsushi Nemoto { 813f48c8c95SAtsushi Nemoto #if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE) 814f48c8c95SAtsushi Nemoto struct resource res[] = { 815f48c8c95SAtsushi Nemoto { 816f48c8c95SAtsushi Nemoto .start = baseaddr, 817f48c8c95SAtsushi Nemoto .end = baseaddr + 0x800 - 1, 818f48c8c95SAtsushi Nemoto .flags = IORESOURCE_MEM, 819f48c8c95SAtsushi Nemoto #ifndef CONFIG_MACH_TX49XX 820f48c8c95SAtsushi Nemoto }, { 821f48c8c95SAtsushi Nemoto .start = irq, 822f48c8c95SAtsushi Nemoto .flags = IORESOURCE_IRQ, 823f48c8c95SAtsushi Nemoto #endif 824f48c8c95SAtsushi Nemoto } 825f48c8c95SAtsushi Nemoto }; 826f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 827f48c8c95SAtsushi Nemoto struct resource chan_res[] = { 828f48c8c95SAtsushi Nemoto { 829f48c8c95SAtsushi Nemoto .flags = IORESOURCE_IRQ, 830f48c8c95SAtsushi Nemoto } 831f48c8c95SAtsushi Nemoto }; 832f48c8c95SAtsushi Nemoto #endif 833f48c8c95SAtsushi Nemoto struct platform_device *pdev = platform_device_alloc("txx9dmac", id); 834f48c8c95SAtsushi Nemoto struct txx9dmac_chan_platform_data cpdata; 835f48c8c95SAtsushi Nemoto int i; 836f48c8c95SAtsushi Nemoto 837f48c8c95SAtsushi Nemoto if (!pdev || 838f48c8c95SAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) || 839f48c8c95SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 840f48c8c95SAtsushi Nemoto platform_device_add(pdev)) { 841f48c8c95SAtsushi Nemoto platform_device_put(pdev); 842f48c8c95SAtsushi Nemoto return; 843f48c8c95SAtsushi Nemoto } 844f48c8c95SAtsushi Nemoto memset(&cpdata, 0, sizeof(cpdata)); 845f48c8c95SAtsushi Nemoto cpdata.dmac_dev = pdev; 846f48c8c95SAtsushi Nemoto for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) { 847f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 848f48c8c95SAtsushi Nemoto chan_res[0].start = irq + i; 849f48c8c95SAtsushi Nemoto #endif 850f48c8c95SAtsushi Nemoto pdev = platform_device_alloc("txx9dmac-chan", 851f48c8c95SAtsushi Nemoto id * TXX9_DMA_MAX_NR_CHANNELS + i); 852f48c8c95SAtsushi Nemoto if (!pdev || 853f48c8c95SAtsushi Nemoto #ifdef CONFIG_MACH_TX49XX 854f48c8c95SAtsushi Nemoto platform_device_add_resources(pdev, chan_res, 855f48c8c95SAtsushi Nemoto ARRAY_SIZE(chan_res)) || 856f48c8c95SAtsushi Nemoto #endif 857f48c8c95SAtsushi Nemoto platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) || 858f48c8c95SAtsushi Nemoto platform_device_add(pdev)) 859f48c8c95SAtsushi Nemoto platform_device_put(pdev); 860f48c8c95SAtsushi Nemoto } 861f48c8c95SAtsushi Nemoto #endif 862f48c8c95SAtsushi Nemoto } 863742cd586SAtsushi Nemoto 864742cd586SAtsushi Nemoto void __init txx9_aclc_init(unsigned long baseaddr, int irq, 865742cd586SAtsushi Nemoto unsigned int dmac_id, 866742cd586SAtsushi Nemoto unsigned int dma_chan_out, 867742cd586SAtsushi Nemoto unsigned int dma_chan_in) 868742cd586SAtsushi Nemoto { 869742cd586SAtsushi Nemoto #if defined(CONFIG_SND_SOC_TXX9ACLC) || \ 870742cd586SAtsushi Nemoto defined(CONFIG_SND_SOC_TXX9ACLC_MODULE) 871742cd586SAtsushi Nemoto unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS; 872742cd586SAtsushi Nemoto struct resource res[] = { 873742cd586SAtsushi Nemoto { 874742cd586SAtsushi Nemoto .start = baseaddr, 875742cd586SAtsushi Nemoto .end = baseaddr + 0x100 - 1, 876742cd586SAtsushi Nemoto .flags = IORESOURCE_MEM, 877742cd586SAtsushi Nemoto }, { 878742cd586SAtsushi Nemoto .start = irq, 879742cd586SAtsushi Nemoto .flags = IORESOURCE_IRQ, 880742cd586SAtsushi Nemoto }, { 881742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 882742cd586SAtsushi Nemoto .start = dma_base + dma_chan_out, 883742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 884742cd586SAtsushi Nemoto }, { 885742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 886742cd586SAtsushi Nemoto .start = dma_base + dma_chan_in, 887742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 888742cd586SAtsushi Nemoto } 889742cd586SAtsushi Nemoto }; 890742cd586SAtsushi Nemoto struct platform_device *pdev = 891742cd586SAtsushi Nemoto platform_device_alloc("txx9aclc-ac97", -1); 892742cd586SAtsushi Nemoto 893742cd586SAtsushi Nemoto if (!pdev || 894742cd586SAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) || 895742cd586SAtsushi Nemoto platform_device_add(pdev)) 896742cd586SAtsushi Nemoto platform_device_put(pdev); 897742cd586SAtsushi Nemoto #endif 898742cd586SAtsushi Nemoto } 899c3b28ae2SAtsushi Nemoto 900*269a3eb1SKay Sievers static struct bus_type txx9_sramc_subsys = { 901*269a3eb1SKay Sievers .name = "txx9_sram", 902*269a3eb1SKay Sievers .dev_name = "txx9_sram", 903*269a3eb1SKay Sievers }; 904c3b28ae2SAtsushi Nemoto 905*269a3eb1SKay Sievers struct txx9_sramc_dev { 906*269a3eb1SKay Sievers struct device dev; 907c3b28ae2SAtsushi Nemoto struct bin_attribute bindata_attr; 908c3b28ae2SAtsushi Nemoto void __iomem *base; 909c3b28ae2SAtsushi Nemoto }; 910c3b28ae2SAtsushi Nemoto 9112c3c8beaSChris Wright static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj, 912c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 913c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 914c3b28ae2SAtsushi Nemoto { 915*269a3eb1SKay Sievers struct txx9_sramc_dev *dev = bin_attr->private; 916c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 917c3b28ae2SAtsushi Nemoto 918c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 919c3b28ae2SAtsushi Nemoto return 0; 920c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 921c3b28ae2SAtsushi Nemoto size = ramsize - pos; 922c3b28ae2SAtsushi Nemoto memcpy_fromio(buf, dev->base + pos, size); 923c3b28ae2SAtsushi Nemoto return size; 924c3b28ae2SAtsushi Nemoto } 925c3b28ae2SAtsushi Nemoto 9262c3c8beaSChris Wright static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj, 927c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 928c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 929c3b28ae2SAtsushi Nemoto { 930*269a3eb1SKay Sievers struct txx9_sramc_dev *dev = bin_attr->private; 931c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 932c3b28ae2SAtsushi Nemoto 933c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 934c3b28ae2SAtsushi Nemoto return 0; 935c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 936c3b28ae2SAtsushi Nemoto size = ramsize - pos; 937c3b28ae2SAtsushi Nemoto memcpy_toio(dev->base + pos, buf, size); 938c3b28ae2SAtsushi Nemoto return size; 939c3b28ae2SAtsushi Nemoto } 940c3b28ae2SAtsushi Nemoto 941c3b28ae2SAtsushi Nemoto void __init txx9_sramc_init(struct resource *r) 942c3b28ae2SAtsushi Nemoto { 943*269a3eb1SKay Sievers struct txx9_sramc_dev *dev; 944c3b28ae2SAtsushi Nemoto size_t size; 945c3b28ae2SAtsushi Nemoto int err; 946c3b28ae2SAtsushi Nemoto 947*269a3eb1SKay Sievers err = subsys_system_register(&txx9_sramc_subsys, NULL); 948*269a3eb1SKay Sievers if (err) 949c3b28ae2SAtsushi Nemoto return; 950c3b28ae2SAtsushi Nemoto dev = kzalloc(sizeof(*dev), GFP_KERNEL); 951c3b28ae2SAtsushi Nemoto if (!dev) 952c3b28ae2SAtsushi Nemoto return; 953c3b28ae2SAtsushi Nemoto size = resource_size(r); 954c3b28ae2SAtsushi Nemoto dev->base = ioremap(r->start, size); 955c3b28ae2SAtsushi Nemoto if (!dev->base) 956c3b28ae2SAtsushi Nemoto goto exit; 957*269a3eb1SKay Sievers dev->dev.bus = &txx9_sramc_subsys; 958f937331bSWolfram Sang sysfs_bin_attr_init(&dev->bindata_attr); 959c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.name = "bindata"; 960c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR; 961c3b28ae2SAtsushi Nemoto dev->bindata_attr.read = txx9_sram_read; 962c3b28ae2SAtsushi Nemoto dev->bindata_attr.write = txx9_sram_write; 963c3b28ae2SAtsushi Nemoto dev->bindata_attr.size = size; 964c3b28ae2SAtsushi Nemoto dev->bindata_attr.private = dev; 965*269a3eb1SKay Sievers err = device_register(&dev->dev); 966c3b28ae2SAtsushi Nemoto if (err) 967c3b28ae2SAtsushi Nemoto goto exit; 968c3b28ae2SAtsushi Nemoto err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr); 969c3b28ae2SAtsushi Nemoto if (err) { 970*269a3eb1SKay Sievers device_unregister(&dev->dev); 971c3b28ae2SAtsushi Nemoto goto exit; 972c3b28ae2SAtsushi Nemoto } 973c3b28ae2SAtsushi Nemoto return; 974c3b28ae2SAtsushi Nemoto exit: 975c3b28ae2SAtsushi Nemoto if (dev) { 976c3b28ae2SAtsushi Nemoto if (dev->base) 977c3b28ae2SAtsushi Nemoto iounmap(dev->base); 978c3b28ae2SAtsushi Nemoto kfree(dev); 979c3b28ae2SAtsushi Nemoto } 980c3b28ae2SAtsushi Nemoto } 981