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> 25269a3eb1SKay Sievers #include <linux/device.h> 265a0e3ad6STejun Heo #include <linux/slab.h> 27ca4d3e67SDavid Howells #include <linux/irq.h> 28edcaf1a6SAtsushi Nemoto #include <asm/bootinfo.h> 29bdc92d74SRalf Baechle #include <asm/idle.h> 30e0eb7307SAtsushi Nemoto #include <asm/time.h> 31a49297e8SAtsushi Nemoto #include <asm/reboot.h> 32d10e025fSAtsushi Nemoto #include <asm/r4kcache.h> 33b6263ff2SAtsushi Nemoto #include <asm/sections.h> 3489d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h> 3507517529SAtsushi Nemoto #include <asm/txx9/pci.h> 36496a3b5cSAtsushi Nemoto #include <asm/txx9tmr.h> 37a591f5d3SAtsushi Nemoto #include <asm/txx9/ndfmc.h> 38f48c8c95SAtsushi Nemoto #include <asm/txx9/dmac.h> 39edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 40edcaf1a6SAtsushi Nemoto #include <asm/txx9/tx4938.h> 41edcaf1a6SAtsushi Nemoto #endif 4289d63fe1SAtsushi Nemoto 4389d63fe1SAtsushi Nemoto /* EBUSC settings of TX4927, etc. */ 4489d63fe1SAtsushi Nemoto struct resource txx9_ce_res[8]; 4589d63fe1SAtsushi Nemoto static char txx9_ce_res_name[8][4]; /* "CEn" */ 4689d63fe1SAtsushi Nemoto 4789d63fe1SAtsushi Nemoto /* pcode, internal register */ 4894a4c329SAtsushi Nemoto unsigned int txx9_pcode; 4989d63fe1SAtsushi Nemoto char txx9_pcode_str[8]; 5089d63fe1SAtsushi Nemoto static struct resource txx9_reg_res = { 5189d63fe1SAtsushi Nemoto .name = txx9_pcode_str, 5289d63fe1SAtsushi Nemoto .flags = IORESOURCE_MEM, 5389d63fe1SAtsushi Nemoto }; 5489d63fe1SAtsushi Nemoto void __init 5589d63fe1SAtsushi Nemoto txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) 5689d63fe1SAtsushi Nemoto { 5789d63fe1SAtsushi Nemoto int i; 5889d63fe1SAtsushi Nemoto 5989d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { 6089d63fe1SAtsushi Nemoto sprintf(txx9_ce_res_name[i], "CE%d", i); 6189d63fe1SAtsushi Nemoto txx9_ce_res[i].flags = IORESOURCE_MEM; 6289d63fe1SAtsushi Nemoto txx9_ce_res[i].name = txx9_ce_res_name[i]; 6389d63fe1SAtsushi Nemoto } 6489d63fe1SAtsushi Nemoto 65073828d0SAtsushi Nemoto txx9_pcode = pcode; 6689d63fe1SAtsushi Nemoto sprintf(txx9_pcode_str, "TX%x", pcode); 6789d63fe1SAtsushi Nemoto if (base) { 6889d63fe1SAtsushi Nemoto txx9_reg_res.start = base & 0xfffffffffULL; 6989d63fe1SAtsushi Nemoto txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); 7089d63fe1SAtsushi Nemoto request_resource(&iomem_resource, &txx9_reg_res); 7189d63fe1SAtsushi Nemoto } 7289d63fe1SAtsushi Nemoto } 7389d63fe1SAtsushi Nemoto 7489d63fe1SAtsushi Nemoto /* clocks */ 7589d63fe1SAtsushi Nemoto unsigned int txx9_master_clock; 7689d63fe1SAtsushi Nemoto unsigned int txx9_cpu_clock; 7789d63fe1SAtsushi Nemoto unsigned int txx9_gbus_clock; 78edcaf1a6SAtsushi Nemoto 79c7b95bcbSAtsushi Nemoto #ifdef CONFIG_CPU_TX39XX 80c7b95bcbSAtsushi Nemoto /* don't enable by default - see errata */ 81c7b95bcbSAtsushi Nemoto int txx9_ccfg_toeon __initdata; 82c7b95bcbSAtsushi Nemoto #else 8394a4c329SAtsushi Nemoto int txx9_ccfg_toeon __initdata = 1; 84c7b95bcbSAtsushi Nemoto #endif 85edcaf1a6SAtsushi Nemoto 86edcaf1a6SAtsushi Nemoto /* Minimum CLK support */ 87edcaf1a6SAtsushi Nemoto 88edcaf1a6SAtsushi Nemoto struct clk *clk_get(struct device *dev, const char *id) 89edcaf1a6SAtsushi Nemoto { 90edcaf1a6SAtsushi Nemoto if (!strcmp(id, "spi-baseclk")) 91fcc152f3SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2); 92edcaf1a6SAtsushi Nemoto if (!strcmp(id, "imbus_clk")) 9394a4c329SAtsushi Nemoto return (struct clk *)((unsigned long)txx9_gbus_clock / 2); 94edcaf1a6SAtsushi Nemoto return ERR_PTR(-ENOENT); 95edcaf1a6SAtsushi Nemoto } 96edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get); 97edcaf1a6SAtsushi Nemoto 98edcaf1a6SAtsushi Nemoto int clk_enable(struct clk *clk) 99edcaf1a6SAtsushi Nemoto { 100edcaf1a6SAtsushi Nemoto return 0; 101edcaf1a6SAtsushi Nemoto } 102edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_enable); 103edcaf1a6SAtsushi Nemoto 104edcaf1a6SAtsushi Nemoto void clk_disable(struct clk *clk) 105edcaf1a6SAtsushi Nemoto { 106edcaf1a6SAtsushi Nemoto } 107edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_disable); 108edcaf1a6SAtsushi Nemoto 109edcaf1a6SAtsushi Nemoto unsigned long clk_get_rate(struct clk *clk) 110edcaf1a6SAtsushi Nemoto { 111edcaf1a6SAtsushi Nemoto return (unsigned long)clk; 112edcaf1a6SAtsushi Nemoto } 113edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_get_rate); 114edcaf1a6SAtsushi Nemoto 115edcaf1a6SAtsushi Nemoto void clk_put(struct clk *clk) 116edcaf1a6SAtsushi Nemoto { 117edcaf1a6SAtsushi Nemoto } 118edcaf1a6SAtsushi Nemoto EXPORT_SYMBOL(clk_put); 119edcaf1a6SAtsushi Nemoto 1208d795f2aSAtsushi Nemoto /* GPIO support */ 1218d795f2aSAtsushi Nemoto 122f9612a65SAlexandre Courbot #ifdef CONFIG_GPIOLIB 1238d795f2aSAtsushi Nemoto int gpio_to_irq(unsigned gpio) 1248d795f2aSAtsushi Nemoto { 1258d795f2aSAtsushi Nemoto return -EINVAL; 1268d795f2aSAtsushi Nemoto } 1278d795f2aSAtsushi Nemoto EXPORT_SYMBOL(gpio_to_irq); 1288d795f2aSAtsushi Nemoto 1298d795f2aSAtsushi Nemoto int irq_to_gpio(unsigned irq) 1308d795f2aSAtsushi Nemoto { 1318d795f2aSAtsushi Nemoto return -EINVAL; 1328d795f2aSAtsushi Nemoto } 1338d795f2aSAtsushi Nemoto EXPORT_SYMBOL(irq_to_gpio); 1348d795f2aSAtsushi Nemoto #endif 1358d795f2aSAtsushi Nemoto 136860e546cSAtsushi Nemoto #define BOARD_VEC(board) extern struct txx9_board_vec board; 137860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 138860e546cSAtsushi Nemoto #undef BOARD_VEC 139edcaf1a6SAtsushi Nemoto 140edcaf1a6SAtsushi Nemoto struct txx9_board_vec *txx9_board_vec __initdata; 141edcaf1a6SAtsushi Nemoto static char txx9_system_type[32]; 142edcaf1a6SAtsushi Nemoto 143860e546cSAtsushi Nemoto static struct txx9_board_vec *board_vecs[] __initdata = { 144860e546cSAtsushi Nemoto #define BOARD_VEC(board) &board, 145860e546cSAtsushi Nemoto #include <asm/txx9/boards.h> 146860e546cSAtsushi Nemoto #undef BOARD_VEC 147860e546cSAtsushi Nemoto }; 148860e546cSAtsushi Nemoto 149860e546cSAtsushi Nemoto static struct txx9_board_vec *__init find_board_byname(const char *name) 150860e546cSAtsushi Nemoto { 151860e546cSAtsushi Nemoto int i; 152860e546cSAtsushi Nemoto 153860e546cSAtsushi Nemoto /* search board_vecs table */ 154860e546cSAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(board_vecs); i++) { 155860e546cSAtsushi Nemoto if (strstr(board_vecs[i]->system, name)) 156860e546cSAtsushi Nemoto return board_vecs[i]; 157860e546cSAtsushi Nemoto } 158860e546cSAtsushi Nemoto return NULL; 159860e546cSAtsushi Nemoto } 160860e546cSAtsushi Nemoto 161e0dfb20cSAtsushi Nemoto static void __init prom_init_cmdline(void) 162edcaf1a6SAtsushi Nemoto { 16397b0511cSGeert Uytterhoeven int argc; 16497b0511cSGeert Uytterhoeven int *argv32; 165edcaf1a6SAtsushi Nemoto int i; /* Always ignore the "-c" at argv[0] */ 166edcaf1a6SAtsushi Nemoto 16797b0511cSGeert Uytterhoeven if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) { 16897b0511cSGeert Uytterhoeven /* 16997b0511cSGeert Uytterhoeven * argc is not a valid number, or argv32 is not a valid 17097b0511cSGeert Uytterhoeven * pointer 17197b0511cSGeert Uytterhoeven */ 17297b0511cSGeert Uytterhoeven argc = 0; 17397b0511cSGeert Uytterhoeven argv32 = NULL; 17497b0511cSGeert Uytterhoeven } else { 17597b0511cSGeert Uytterhoeven argc = (int)fw_arg0; 17697b0511cSGeert Uytterhoeven argv32 = (int *)fw_arg1; 17797b0511cSGeert Uytterhoeven } 17897b0511cSGeert Uytterhoeven 179e0dfb20cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 180edcaf1a6SAtsushi Nemoto 181edcaf1a6SAtsushi Nemoto for (i = 1; i < argc; i++) { 182e0dfb20cSAtsushi Nemoto char *str = (char *)(long)argv32[i]; 183edcaf1a6SAtsushi Nemoto if (i != 1) 184edcaf1a6SAtsushi Nemoto strcat(arcs_cmdline, " "); 185e0dfb20cSAtsushi Nemoto if (strchr(str, ' ')) { 186e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 187e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 188e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, "\""); 189e0dfb20cSAtsushi Nemoto } else 190e0dfb20cSAtsushi Nemoto strcat(arcs_cmdline, str); 191e0dfb20cSAtsushi Nemoto } 192edcaf1a6SAtsushi Nemoto } 193edcaf1a6SAtsushi Nemoto 194d10e025fSAtsushi Nemoto static int txx9_ic_disable __initdata; 195d10e025fSAtsushi Nemoto static int txx9_dc_disable __initdata; 196d10e025fSAtsushi Nemoto 197d10e025fSAtsushi Nemoto #if defined(CONFIG_CPU_TX49XX) 198d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before 4k_cache_init) */ 199d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 200d10e025fSAtsushi Nemoto { 201d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 202d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6)); 203d10e025fSAtsushi Nemoto unsigned int linesz = 32; 204d10e025fSAtsushi Nemoto unsigned long addr, end; 205d10e025fSAtsushi Nemoto 206d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 4; 207d10e025fSAtsushi Nemoto /* 4way, waybit=0 */ 208d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 209d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 210d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 211d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 2); 212d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 3); 213d10e025fSAtsushi Nemoto } 214d10e025fSAtsushi Nemoto } 215d10e025fSAtsushi Nemoto 216d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 217d10e025fSAtsushi Nemoto { 218d10e025fSAtsushi Nemoto unsigned int conf; 219d10e025fSAtsushi Nemoto 220d10e025fSAtsushi Nemoto conf = read_c0_config(); 221d10e025fSAtsushi Nemoto /* flush and disable */ 222d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 223d10e025fSAtsushi Nemoto conf |= TX49_CONF_IC; 224d10e025fSAtsushi Nemoto write_c0_config(conf); 225d10e025fSAtsushi Nemoto } 226d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 227d10e025fSAtsushi Nemoto early_flush_dcache(); 228d10e025fSAtsushi Nemoto conf |= TX49_CONF_DC; 229d10e025fSAtsushi Nemoto write_c0_config(conf); 230d10e025fSAtsushi Nemoto } 231d10e025fSAtsushi Nemoto 232d10e025fSAtsushi Nemoto /* enable cache */ 233d10e025fSAtsushi Nemoto conf = read_c0_config(); 234d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 235d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_IC; 236d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 237d10e025fSAtsushi Nemoto conf &= ~TX49_CONF_DC; 238d10e025fSAtsushi Nemoto write_c0_config(conf); 239d10e025fSAtsushi Nemoto 240d10e025fSAtsushi Nemoto if (conf & TX49_CONF_IC) 241d10e025fSAtsushi Nemoto pr_info("TX49XX I-Cache disabled.\n"); 242d10e025fSAtsushi Nemoto if (conf & TX49_CONF_DC) 243d10e025fSAtsushi Nemoto pr_info("TX49XX D-Cache disabled.\n"); 244d10e025fSAtsushi Nemoto } 245d10e025fSAtsushi Nemoto #elif defined(CONFIG_CPU_TX39XX) 246d10e025fSAtsushi Nemoto /* flush all cache on very early stage (before tx39_cache_init) */ 247d10e025fSAtsushi Nemoto static void __init early_flush_dcache(void) 248d10e025fSAtsushi Nemoto { 249d10e025fSAtsushi Nemoto unsigned int conf = read_c0_config(); 250d10e025fSAtsushi Nemoto unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >> 251d10e025fSAtsushi Nemoto TX39_CONF_DCS_SHIFT)); 252d10e025fSAtsushi Nemoto unsigned int linesz = 16; 253d10e025fSAtsushi Nemoto unsigned long addr, end; 254d10e025fSAtsushi Nemoto 255d10e025fSAtsushi Nemoto end = INDEX_BASE + dc_size / 2; 256d10e025fSAtsushi Nemoto /* 2way, waybit=0 */ 257d10e025fSAtsushi Nemoto for (addr = INDEX_BASE; addr < end; addr += linesz) { 258d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 0); 259d10e025fSAtsushi Nemoto cache_op(Index_Writeback_Inv_D, addr | 1); 260d10e025fSAtsushi Nemoto } 261d10e025fSAtsushi Nemoto } 262d10e025fSAtsushi Nemoto 263d10e025fSAtsushi Nemoto static void __init txx9_cache_fixup(void) 264d10e025fSAtsushi Nemoto { 265d10e025fSAtsushi Nemoto unsigned int conf; 266d10e025fSAtsushi Nemoto 267d10e025fSAtsushi Nemoto conf = read_c0_config(); 268d10e025fSAtsushi Nemoto /* flush and disable */ 269d10e025fSAtsushi Nemoto if (txx9_ic_disable) { 270d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_ICE; 271d10e025fSAtsushi Nemoto write_c0_config(conf); 272d10e025fSAtsushi Nemoto } 273d10e025fSAtsushi Nemoto if (txx9_dc_disable) { 274d10e025fSAtsushi Nemoto early_flush_dcache(); 275d10e025fSAtsushi Nemoto conf &= ~TX39_CONF_DCE; 276d10e025fSAtsushi Nemoto write_c0_config(conf); 277d10e025fSAtsushi Nemoto } 278d10e025fSAtsushi Nemoto 279d10e025fSAtsushi Nemoto /* enable cache */ 280d10e025fSAtsushi Nemoto conf = read_c0_config(); 281d10e025fSAtsushi Nemoto if (!txx9_ic_disable) 282d10e025fSAtsushi Nemoto conf |= TX39_CONF_ICE; 283d10e025fSAtsushi Nemoto if (!txx9_dc_disable) 284d10e025fSAtsushi Nemoto conf |= TX39_CONF_DCE; 285d10e025fSAtsushi Nemoto write_c0_config(conf); 286d10e025fSAtsushi Nemoto 287d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_ICE)) 288d10e025fSAtsushi Nemoto pr_info("TX39XX I-Cache disabled.\n"); 289d10e025fSAtsushi Nemoto if (!(conf & TX39_CONF_DCE)) 290d10e025fSAtsushi Nemoto pr_info("TX39XX D-Cache disabled.\n"); 291d10e025fSAtsushi Nemoto } 292d10e025fSAtsushi Nemoto #else 293d10e025fSAtsushi Nemoto static inline void txx9_cache_fixup(void) 294d10e025fSAtsushi Nemoto { 295d10e025fSAtsushi Nemoto } 296d10e025fSAtsushi Nemoto #endif 297d10e025fSAtsushi Nemoto 298860e546cSAtsushi Nemoto static void __init preprocess_cmdline(void) 299edcaf1a6SAtsushi Nemoto { 3007580c9c3SDmitri Vorobiev static char cmdline[COMMAND_LINE_SIZE] __initdata; 301860e546cSAtsushi Nemoto char *s; 302860e546cSAtsushi Nemoto 303860e546cSAtsushi Nemoto strcpy(cmdline, arcs_cmdline); 304860e546cSAtsushi Nemoto s = cmdline; 305860e546cSAtsushi Nemoto arcs_cmdline[0] = '\0'; 306860e546cSAtsushi Nemoto while (s && *s) { 307860e546cSAtsushi Nemoto char *str = strsep(&s, " "); 308860e546cSAtsushi Nemoto if (strncmp(str, "board=", 6) == 0) { 309860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(str + 6); 310860e546cSAtsushi Nemoto continue; 311860e546cSAtsushi Nemoto } else if (strncmp(str, "masterclk=", 10) == 0) { 312*8e9ecbc5SDaniel Walter unsigned int val; 313*8e9ecbc5SDaniel Walter if (kstrtouint(str + 10, 10, &val) == 0) 314860e546cSAtsushi Nemoto txx9_master_clock = val; 315860e546cSAtsushi Nemoto continue; 316d10e025fSAtsushi Nemoto } else if (strcmp(str, "icdisable") == 0) { 317d10e025fSAtsushi Nemoto txx9_ic_disable = 1; 318d10e025fSAtsushi Nemoto continue; 319d10e025fSAtsushi Nemoto } else if (strcmp(str, "dcdisable") == 0) { 320d10e025fSAtsushi Nemoto txx9_dc_disable = 1; 321d10e025fSAtsushi Nemoto continue; 322c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeoff") == 0) { 323c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 0; 324c7b95bcbSAtsushi Nemoto continue; 325c7b95bcbSAtsushi Nemoto } else if (strcmp(str, "toeon") == 0) { 326c7b95bcbSAtsushi Nemoto txx9_ccfg_toeon = 1; 327c7b95bcbSAtsushi Nemoto continue; 328860e546cSAtsushi Nemoto } 329860e546cSAtsushi Nemoto if (arcs_cmdline[0]) 330860e546cSAtsushi Nemoto strcat(arcs_cmdline, " "); 331860e546cSAtsushi Nemoto strcat(arcs_cmdline, str); 332860e546cSAtsushi Nemoto } 333d10e025fSAtsushi Nemoto 334d10e025fSAtsushi Nemoto txx9_cache_fixup(); 335860e546cSAtsushi Nemoto } 336860e546cSAtsushi Nemoto 337860e546cSAtsushi Nemoto static void __init select_board(void) 338860e546cSAtsushi Nemoto { 339860e546cSAtsushi Nemoto const char *envstr; 340860e546cSAtsushi Nemoto 341860e546cSAtsushi Nemoto /* first, determine by "board=" argument in preprocess_cmdline() */ 342860e546cSAtsushi Nemoto if (txx9_board_vec) 343860e546cSAtsushi Nemoto return; 344860e546cSAtsushi Nemoto /* next, determine by "board" envvar */ 345860e546cSAtsushi Nemoto envstr = prom_getenv("board"); 346860e546cSAtsushi Nemoto if (envstr) { 347860e546cSAtsushi Nemoto txx9_board_vec = find_board_byname(envstr); 348860e546cSAtsushi Nemoto if (txx9_board_vec) 349860e546cSAtsushi Nemoto return; 350860e546cSAtsushi Nemoto } 351860e546cSAtsushi Nemoto 352860e546cSAtsushi Nemoto /* select "default" board */ 353c8acd40dSMarkos Chandras #ifdef CONFIG_TOSHIBA_JMR3927 3547a1fdf19SYoichi Yuasa txx9_board_vec = &jmr3927_vec; 355edcaf1a6SAtsushi Nemoto #endif 356edcaf1a6SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 357edcaf1a6SAtsushi Nemoto switch (TX4938_REV_PCODE()) { 3588d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4927 359edcaf1a6SAtsushi Nemoto case 0x4927: 3607a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4927_vec; 361edcaf1a6SAtsushi Nemoto break; 362edcaf1a6SAtsushi Nemoto case 0x4937: 3637a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4937_vec; 364edcaf1a6SAtsushi Nemoto break; 3658d795f2aSAtsushi Nemoto #endif 3668d795f2aSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4938 367edcaf1a6SAtsushi Nemoto case 0x4938: 3687a1fdf19SYoichi Yuasa txx9_board_vec = &rbtx4938_vec; 369edcaf1a6SAtsushi Nemoto break; 3708d795f2aSAtsushi Nemoto #endif 371b27311e1SAtsushi Nemoto #ifdef CONFIG_TOSHIBA_RBTX4939 372b27311e1SAtsushi Nemoto case 0x4939: 373b27311e1SAtsushi Nemoto txx9_board_vec = &rbtx4939_vec; 374b27311e1SAtsushi Nemoto break; 375b27311e1SAtsushi Nemoto #endif 376edcaf1a6SAtsushi Nemoto } 377edcaf1a6SAtsushi Nemoto #endif 378860e546cSAtsushi Nemoto } 379860e546cSAtsushi Nemoto 380860e546cSAtsushi Nemoto void __init prom_init(void) 381860e546cSAtsushi Nemoto { 382860e546cSAtsushi Nemoto prom_init_cmdline(); 383860e546cSAtsushi Nemoto preprocess_cmdline(); 384860e546cSAtsushi Nemoto select_board(); 3857a1fdf19SYoichi Yuasa 386edcaf1a6SAtsushi Nemoto strcpy(txx9_system_type, txx9_board_vec->system); 3877a1fdf19SYoichi Yuasa 3887b226094SAtsushi Nemoto txx9_board_vec->prom_init(); 389edcaf1a6SAtsushi Nemoto } 390edcaf1a6SAtsushi Nemoto 391edcaf1a6SAtsushi Nemoto void __init prom_free_prom_memory(void) 392edcaf1a6SAtsushi Nemoto { 393b6263ff2SAtsushi Nemoto unsigned long saddr = PAGE_SIZE; 394b6263ff2SAtsushi Nemoto unsigned long eaddr = __pa_symbol(&_text); 395b6263ff2SAtsushi Nemoto 396b6263ff2SAtsushi Nemoto if (saddr < eaddr) 397b6263ff2SAtsushi Nemoto free_init_pages("prom memory", saddr, eaddr); 398edcaf1a6SAtsushi Nemoto } 399edcaf1a6SAtsushi Nemoto 400edcaf1a6SAtsushi Nemoto const char *get_system_type(void) 401edcaf1a6SAtsushi Nemoto { 402edcaf1a6SAtsushi Nemoto return txx9_system_type; 403edcaf1a6SAtsushi Nemoto } 404edcaf1a6SAtsushi Nemoto 405265b89dbSAtsushi Nemoto const char *__init prom_getenv(const char *name) 406265b89dbSAtsushi Nemoto { 40797b0511cSGeert Uytterhoeven const s32 *str; 408265b89dbSAtsushi Nemoto 40997b0511cSGeert Uytterhoeven if (fw_arg2 < CKSEG0) 410265b89dbSAtsushi Nemoto return NULL; 41197b0511cSGeert Uytterhoeven 41297b0511cSGeert Uytterhoeven str = (const s32 *)fw_arg2; 413265b89dbSAtsushi Nemoto /* YAMON style ("name", "value" pairs) */ 414265b89dbSAtsushi Nemoto while (str[0] && str[1]) { 415265b89dbSAtsushi Nemoto if (!strcmp((const char *)(unsigned long)str[0], name)) 416265b89dbSAtsushi Nemoto return (const char *)(unsigned long)str[1]; 417265b89dbSAtsushi Nemoto str += 2; 418265b89dbSAtsushi Nemoto } 419265b89dbSAtsushi Nemoto return NULL; 420265b89dbSAtsushi Nemoto } 421265b89dbSAtsushi Nemoto 422a49297e8SAtsushi Nemoto static void __noreturn txx9_machine_halt(void) 423a49297e8SAtsushi Nemoto { 424a49297e8SAtsushi Nemoto local_irq_disable(); 425a49297e8SAtsushi Nemoto clear_c0_status(ST0_IM); 426a49297e8SAtsushi Nemoto while (1) { 427a49297e8SAtsushi Nemoto if (cpu_wait) { 428a49297e8SAtsushi Nemoto (*cpu_wait)(); 429a49297e8SAtsushi Nemoto if (cpu_has_counter) { 430a49297e8SAtsushi Nemoto /* 431a49297e8SAtsushi Nemoto * Clear counter interrupt while it 432a49297e8SAtsushi Nemoto * breaks WAIT instruction even if 433a49297e8SAtsushi Nemoto * masked. 434a49297e8SAtsushi Nemoto */ 435a49297e8SAtsushi Nemoto write_c0_compare(0); 436a49297e8SAtsushi Nemoto } 437a49297e8SAtsushi Nemoto } 438a49297e8SAtsushi Nemoto } 439a49297e8SAtsushi Nemoto } 440a49297e8SAtsushi Nemoto 44168314725SAtsushi Nemoto /* Watchdog support */ 44268314725SAtsushi Nemoto void __init txx9_wdt_init(unsigned long base) 44368314725SAtsushi Nemoto { 44468314725SAtsushi Nemoto struct resource res = { 44568314725SAtsushi Nemoto .start = base, 44668314725SAtsushi Nemoto .end = base + 0x100 - 1, 44768314725SAtsushi Nemoto .flags = IORESOURCE_MEM, 44868314725SAtsushi Nemoto }; 44968314725SAtsushi Nemoto platform_device_register_simple("txx9wdt", -1, &res, 1); 45068314725SAtsushi Nemoto } 45168314725SAtsushi Nemoto 452496a3b5cSAtsushi Nemoto void txx9_wdt_now(unsigned long base) 453496a3b5cSAtsushi Nemoto { 454496a3b5cSAtsushi Nemoto struct txx9_tmr_reg __iomem *tmrptr = 455496a3b5cSAtsushi Nemoto ioremap(base, sizeof(struct txx9_tmr_reg)); 456496a3b5cSAtsushi Nemoto /* disable watch dog timer */ 457496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr); 458496a3b5cSAtsushi Nemoto __raw_writel(0, &tmrptr->tcr); 459496a3b5cSAtsushi Nemoto /* kick watchdog */ 460496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr); 461496a3b5cSAtsushi Nemoto __raw_writel(1, &tmrptr->cpra); /* immediate */ 462496a3b5cSAtsushi Nemoto __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG, 463496a3b5cSAtsushi Nemoto &tmrptr->tcr); 464496a3b5cSAtsushi Nemoto } 465496a3b5cSAtsushi Nemoto 466c49f91f5SAtsushi Nemoto /* SPI support */ 467c49f91f5SAtsushi Nemoto void __init txx9_spi_init(int busid, unsigned long base, int irq) 468c49f91f5SAtsushi Nemoto { 469c49f91f5SAtsushi Nemoto struct resource res[] = { 470c49f91f5SAtsushi Nemoto { 471c49f91f5SAtsushi Nemoto .start = base, 472c49f91f5SAtsushi Nemoto .end = base + 0x20 - 1, 473c49f91f5SAtsushi Nemoto .flags = IORESOURCE_MEM, 474c49f91f5SAtsushi Nemoto }, { 475c49f91f5SAtsushi Nemoto .start = irq, 476c49f91f5SAtsushi Nemoto .flags = IORESOURCE_IRQ, 477c49f91f5SAtsushi Nemoto }, 478c49f91f5SAtsushi Nemoto }; 479c49f91f5SAtsushi Nemoto platform_device_register_simple("spi_txx9", busid, 480c49f91f5SAtsushi Nemoto res, ARRAY_SIZE(res)); 481c49f91f5SAtsushi Nemoto } 482c49f91f5SAtsushi Nemoto 483c49f91f5SAtsushi Nemoto void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) 484c49f91f5SAtsushi Nemoto { 485c49f91f5SAtsushi Nemoto struct platform_device *pdev = 486c49f91f5SAtsushi Nemoto platform_device_alloc("tc35815-mac", id); 487c49f91f5SAtsushi Nemoto if (!pdev || 488c49f91f5SAtsushi Nemoto platform_device_add_data(pdev, ethaddr, 6) || 489c49f91f5SAtsushi Nemoto platform_device_add(pdev)) 490c49f91f5SAtsushi Nemoto platform_device_put(pdev); 491c49f91f5SAtsushi Nemoto } 492c49f91f5SAtsushi Nemoto 4937779a5e0SAtsushi Nemoto void __init txx9_sio_init(unsigned long baseaddr, int irq, 4947779a5e0SAtsushi Nemoto unsigned int line, unsigned int sclk, int nocts) 4957779a5e0SAtsushi Nemoto { 4967779a5e0SAtsushi Nemoto #ifdef CONFIG_SERIAL_TXX9 4977779a5e0SAtsushi Nemoto struct uart_port req; 4987779a5e0SAtsushi Nemoto 4997779a5e0SAtsushi Nemoto memset(&req, 0, sizeof(req)); 5007779a5e0SAtsushi Nemoto req.line = line; 5017779a5e0SAtsushi Nemoto req.iotype = UPIO_MEM; 5027779a5e0SAtsushi Nemoto req.membase = ioremap(baseaddr, 0x24); 5037779a5e0SAtsushi Nemoto req.mapbase = baseaddr; 5047779a5e0SAtsushi Nemoto req.irq = irq; 5057779a5e0SAtsushi Nemoto if (!nocts) 5067779a5e0SAtsushi Nemoto req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; 5077779a5e0SAtsushi Nemoto if (sclk) { 5087779a5e0SAtsushi Nemoto req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; 5097779a5e0SAtsushi Nemoto req.uartclk = sclk; 5107779a5e0SAtsushi Nemoto } else 5117779a5e0SAtsushi Nemoto req.uartclk = TXX9_IMCLK; 5127779a5e0SAtsushi Nemoto early_serial_txx9_setup(&req); 5137779a5e0SAtsushi Nemoto #endif /* CONFIG_SERIAL_TXX9 */ 5147779a5e0SAtsushi Nemoto } 5157779a5e0SAtsushi Nemoto 516e352953cSAtsushi Nemoto #ifdef CONFIG_EARLY_PRINTK 517f7be4e75SAaro Koskinen static void null_prom_putchar(char c) 518e352953cSAtsushi Nemoto { 519e352953cSAtsushi Nemoto } 520f7be4e75SAaro Koskinen void (*txx9_prom_putchar)(char c) = null_prom_putchar; 521e352953cSAtsushi Nemoto 522f7be4e75SAaro Koskinen void prom_putchar(char c) 523e352953cSAtsushi Nemoto { 524e352953cSAtsushi Nemoto txx9_prom_putchar(c); 525e352953cSAtsushi Nemoto } 526e352953cSAtsushi Nemoto 527e352953cSAtsushi Nemoto static void __iomem *early_txx9_sio_port; 528e352953cSAtsushi Nemoto 529f7be4e75SAaro Koskinen static void early_txx9_sio_putchar(char c) 530e352953cSAtsushi Nemoto { 531e352953cSAtsushi Nemoto #define TXX9_SICISR 0x0c 532e352953cSAtsushi Nemoto #define TXX9_SITFIFO 0x1c 533e352953cSAtsushi Nemoto #define TXX9_SICISR_TXALS 0x00000002 534e352953cSAtsushi Nemoto while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) & 535e352953cSAtsushi Nemoto TXX9_SICISR_TXALS)) 536e352953cSAtsushi Nemoto ; 537e352953cSAtsushi Nemoto __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO); 538e352953cSAtsushi Nemoto } 539e352953cSAtsushi Nemoto 540e352953cSAtsushi Nemoto void __init txx9_sio_putchar_init(unsigned long baseaddr) 541e352953cSAtsushi Nemoto { 542e352953cSAtsushi Nemoto early_txx9_sio_port = ioremap(baseaddr, 0x24); 543e352953cSAtsushi Nemoto txx9_prom_putchar = early_txx9_sio_putchar; 544e352953cSAtsushi Nemoto } 545e352953cSAtsushi Nemoto #endif /* CONFIG_EARLY_PRINTK */ 546e352953cSAtsushi Nemoto 547edcaf1a6SAtsushi Nemoto /* wrappers */ 548edcaf1a6SAtsushi Nemoto void __init plat_mem_setup(void) 549edcaf1a6SAtsushi Nemoto { 55094a4c329SAtsushi Nemoto ioport_resource.start = 0; 55194a4c329SAtsushi Nemoto ioport_resource.end = ~0UL; /* no limit */ 55294a4c329SAtsushi Nemoto iomem_resource.start = 0; 55394a4c329SAtsushi Nemoto iomem_resource.end = ~0UL; /* no limit */ 554a49297e8SAtsushi Nemoto 555a49297e8SAtsushi Nemoto /* fallback restart/halt routines */ 556a49297e8SAtsushi Nemoto _machine_restart = (void (*)(char *))txx9_machine_halt; 557a49297e8SAtsushi Nemoto _machine_halt = txx9_machine_halt; 558a49297e8SAtsushi Nemoto pm_power_off = txx9_machine_halt; 559a49297e8SAtsushi Nemoto 56007517529SAtsushi Nemoto #ifdef CONFIG_PCI 56107517529SAtsushi Nemoto pcibios_plat_setup = txx9_pcibios_setup; 56207517529SAtsushi Nemoto #endif 563edcaf1a6SAtsushi Nemoto txx9_board_vec->mem_setup(); 564edcaf1a6SAtsushi Nemoto } 565edcaf1a6SAtsushi Nemoto 566edcaf1a6SAtsushi Nemoto void __init arch_init_irq(void) 567edcaf1a6SAtsushi Nemoto { 568edcaf1a6SAtsushi Nemoto txx9_board_vec->irq_setup(); 569edcaf1a6SAtsushi Nemoto } 570edcaf1a6SAtsushi Nemoto 571edcaf1a6SAtsushi Nemoto void __init plat_time_init(void) 572edcaf1a6SAtsushi Nemoto { 5731374d084SAtsushi Nemoto #ifdef CONFIG_CPU_TX49XX 5741374d084SAtsushi Nemoto mips_hpt_frequency = txx9_cpu_clock / 2; 5751374d084SAtsushi Nemoto #endif 576edcaf1a6SAtsushi Nemoto txx9_board_vec->time_init(); 577edcaf1a6SAtsushi Nemoto } 578edcaf1a6SAtsushi Nemoto 579edcaf1a6SAtsushi Nemoto static int __init _txx9_arch_init(void) 580edcaf1a6SAtsushi Nemoto { 581edcaf1a6SAtsushi Nemoto if (txx9_board_vec->arch_init) 582edcaf1a6SAtsushi Nemoto txx9_board_vec->arch_init(); 583edcaf1a6SAtsushi Nemoto return 0; 584edcaf1a6SAtsushi Nemoto } 585edcaf1a6SAtsushi Nemoto arch_initcall(_txx9_arch_init); 586edcaf1a6SAtsushi Nemoto 587edcaf1a6SAtsushi Nemoto static int __init _txx9_device_init(void) 588edcaf1a6SAtsushi Nemoto { 589edcaf1a6SAtsushi Nemoto if (txx9_board_vec->device_init) 590edcaf1a6SAtsushi Nemoto txx9_board_vec->device_init(); 591edcaf1a6SAtsushi Nemoto return 0; 592edcaf1a6SAtsushi Nemoto } 593edcaf1a6SAtsushi Nemoto device_initcall(_txx9_device_init); 594edcaf1a6SAtsushi Nemoto 595edcaf1a6SAtsushi Nemoto int (*txx9_irq_dispatch)(int pending); 596edcaf1a6SAtsushi Nemoto asmlinkage void plat_irq_dispatch(void) 597edcaf1a6SAtsushi Nemoto { 598edcaf1a6SAtsushi Nemoto int pending = read_c0_status() & read_c0_cause() & ST0_IM; 599edcaf1a6SAtsushi Nemoto int irq = txx9_irq_dispatch(pending); 600edcaf1a6SAtsushi Nemoto 601edcaf1a6SAtsushi Nemoto if (likely(irq >= 0)) 602edcaf1a6SAtsushi Nemoto do_IRQ(irq); 603edcaf1a6SAtsushi Nemoto else 604edcaf1a6SAtsushi Nemoto spurious_interrupt(); 605edcaf1a6SAtsushi Nemoto } 6064c642f3fSAtsushi Nemoto 6074c642f3fSAtsushi Nemoto /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ 6084c642f3fSAtsushi Nemoto #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B 6094c642f3fSAtsushi Nemoto static unsigned long __swizzle_addr_none(unsigned long port) 6104c642f3fSAtsushi Nemoto { 6114c642f3fSAtsushi Nemoto return port; 6124c642f3fSAtsushi Nemoto } 6134c642f3fSAtsushi Nemoto unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 6144c642f3fSAtsushi Nemoto EXPORT_SYMBOL(__swizzle_addr_b); 6154c642f3fSAtsushi Nemoto #endif 61651f607c7SAtsushi Nemoto 6171ba5a176SAtsushi Nemoto #ifdef NEEDS_TXX9_IOSWABW 6181ba5a176SAtsushi Nemoto static u16 ioswabw_default(volatile u16 *a, u16 x) 6191ba5a176SAtsushi Nemoto { 6201ba5a176SAtsushi Nemoto return le16_to_cpu(x); 6211ba5a176SAtsushi Nemoto } 6221ba5a176SAtsushi Nemoto static u16 __mem_ioswabw_default(volatile u16 *a, u16 x) 6231ba5a176SAtsushi Nemoto { 6241ba5a176SAtsushi Nemoto return x; 6251ba5a176SAtsushi Nemoto } 6261ba5a176SAtsushi Nemoto u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default; 6271ba5a176SAtsushi Nemoto EXPORT_SYMBOL(ioswabw); 6281ba5a176SAtsushi Nemoto u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default; 6291ba5a176SAtsushi Nemoto EXPORT_SYMBOL(__mem_ioswabw); 6301ba5a176SAtsushi Nemoto #endif 6311ba5a176SAtsushi Nemoto 63251f607c7SAtsushi Nemoto void __init txx9_physmap_flash_init(int no, unsigned long addr, 63351f607c7SAtsushi Nemoto unsigned long size, 63451f607c7SAtsushi Nemoto const struct physmap_flash_data *pdata) 63551f607c7SAtsushi Nemoto { 636b33b4407SFlorian Fainelli #if IS_ENABLED(CONFIG_MTD_PHYSMAP) 63751f607c7SAtsushi Nemoto struct resource res = { 63851f607c7SAtsushi Nemoto .start = addr, 63951f607c7SAtsushi Nemoto .end = addr + size - 1, 64051f607c7SAtsushi Nemoto .flags = IORESOURCE_MEM, 64151f607c7SAtsushi Nemoto }; 64251f607c7SAtsushi Nemoto struct platform_device *pdev; 64351f607c7SAtsushi Nemoto static struct mtd_partition parts[2]; 64451f607c7SAtsushi Nemoto struct physmap_flash_data pdata_part; 64551f607c7SAtsushi Nemoto 64651f607c7SAtsushi Nemoto /* If this area contained boot area, make separate partition */ 64751f607c7SAtsushi Nemoto if (pdata->nr_parts == 0 && !pdata->parts && 64851f607c7SAtsushi Nemoto addr < 0x1fc00000 && addr + size > 0x1fc00000 && 64951f607c7SAtsushi Nemoto !parts[0].name) { 65051f607c7SAtsushi Nemoto parts[0].name = "boot"; 65151f607c7SAtsushi Nemoto parts[0].offset = 0x1fc00000 - addr; 65251f607c7SAtsushi Nemoto parts[0].size = addr + size - 0x1fc00000; 65351f607c7SAtsushi Nemoto parts[1].name = "user"; 65451f607c7SAtsushi Nemoto parts[1].offset = 0; 65551f607c7SAtsushi Nemoto parts[1].size = 0x1fc00000 - addr; 65651f607c7SAtsushi Nemoto pdata_part = *pdata; 65751f607c7SAtsushi Nemoto pdata_part.nr_parts = ARRAY_SIZE(parts); 65851f607c7SAtsushi Nemoto pdata_part.parts = parts; 65951f607c7SAtsushi Nemoto pdata = &pdata_part; 66051f607c7SAtsushi Nemoto } 66147854888SJamie Iles 66251f607c7SAtsushi Nemoto pdev = platform_device_alloc("physmap-flash", no); 66351f607c7SAtsushi Nemoto if (!pdev || 66451f607c7SAtsushi Nemoto platform_device_add_resources(pdev, &res, 1) || 66551f607c7SAtsushi Nemoto platform_device_add_data(pdev, pdata, sizeof(*pdata)) || 66651f607c7SAtsushi Nemoto platform_device_add(pdev)) 66751f607c7SAtsushi Nemoto platform_device_put(pdev); 66851f607c7SAtsushi Nemoto #endif 66951f607c7SAtsushi Nemoto } 670ae027eadSAtsushi Nemoto 671a591f5d3SAtsushi Nemoto void __init txx9_ndfmc_init(unsigned long baseaddr, 672a591f5d3SAtsushi Nemoto const struct txx9ndfmc_platform_data *pdata) 673a591f5d3SAtsushi Nemoto { 674b33b4407SFlorian Fainelli #if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC) 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 690b33b4407SFlorian Fainelli #if IS_ENABLED(CONFIG_LEDS_GPIO) 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 { 813b33b4407SFlorian Fainelli #if IS_ENABLED(CONFIG_TXX9_DMAC) 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 { 869b33b4407SFlorian Fainelli #if IS_ENABLED(CONFIG_SND_SOC_TXX9ACLC) 870742cd586SAtsushi Nemoto unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS; 871742cd586SAtsushi Nemoto struct resource res[] = { 872742cd586SAtsushi Nemoto { 873742cd586SAtsushi Nemoto .start = baseaddr, 874742cd586SAtsushi Nemoto .end = baseaddr + 0x100 - 1, 875742cd586SAtsushi Nemoto .flags = IORESOURCE_MEM, 876742cd586SAtsushi Nemoto }, { 877742cd586SAtsushi Nemoto .start = irq, 878742cd586SAtsushi Nemoto .flags = IORESOURCE_IRQ, 879742cd586SAtsushi Nemoto }, { 880742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 881742cd586SAtsushi Nemoto .start = dma_base + dma_chan_out, 882742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 883742cd586SAtsushi Nemoto }, { 884742cd586SAtsushi Nemoto .name = "txx9dmac-chan", 885742cd586SAtsushi Nemoto .start = dma_base + dma_chan_in, 886742cd586SAtsushi Nemoto .flags = IORESOURCE_DMA, 887742cd586SAtsushi Nemoto } 888742cd586SAtsushi Nemoto }; 889742cd586SAtsushi Nemoto struct platform_device *pdev = 890742cd586SAtsushi Nemoto platform_device_alloc("txx9aclc-ac97", -1); 891742cd586SAtsushi Nemoto 892742cd586SAtsushi Nemoto if (!pdev || 893742cd586SAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) || 894742cd586SAtsushi Nemoto platform_device_add(pdev)) 895742cd586SAtsushi Nemoto platform_device_put(pdev); 896742cd586SAtsushi Nemoto #endif 897742cd586SAtsushi Nemoto } 898c3b28ae2SAtsushi Nemoto 899269a3eb1SKay Sievers static struct bus_type txx9_sramc_subsys = { 900269a3eb1SKay Sievers .name = "txx9_sram", 901269a3eb1SKay Sievers .dev_name = "txx9_sram", 902269a3eb1SKay Sievers }; 903c3b28ae2SAtsushi Nemoto 904269a3eb1SKay Sievers struct txx9_sramc_dev { 905269a3eb1SKay Sievers struct device dev; 906c3b28ae2SAtsushi Nemoto struct bin_attribute bindata_attr; 907c3b28ae2SAtsushi Nemoto void __iomem *base; 908c3b28ae2SAtsushi Nemoto }; 909c3b28ae2SAtsushi Nemoto 9102c3c8beaSChris Wright static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj, 911c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 912c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 913c3b28ae2SAtsushi Nemoto { 914269a3eb1SKay Sievers struct txx9_sramc_dev *dev = bin_attr->private; 915c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 916c3b28ae2SAtsushi Nemoto 917c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 918c3b28ae2SAtsushi Nemoto return 0; 919c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 920c3b28ae2SAtsushi Nemoto size = ramsize - pos; 921c3b28ae2SAtsushi Nemoto memcpy_fromio(buf, dev->base + pos, size); 922c3b28ae2SAtsushi Nemoto return size; 923c3b28ae2SAtsushi Nemoto } 924c3b28ae2SAtsushi Nemoto 9252c3c8beaSChris Wright static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj, 926c3b28ae2SAtsushi Nemoto struct bin_attribute *bin_attr, 927c3b28ae2SAtsushi Nemoto char *buf, loff_t pos, size_t size) 928c3b28ae2SAtsushi Nemoto { 929269a3eb1SKay Sievers struct txx9_sramc_dev *dev = bin_attr->private; 930c3b28ae2SAtsushi Nemoto size_t ramsize = bin_attr->size; 931c3b28ae2SAtsushi Nemoto 932c3b28ae2SAtsushi Nemoto if (pos >= ramsize) 933c3b28ae2SAtsushi Nemoto return 0; 934c3b28ae2SAtsushi Nemoto if (pos + size > ramsize) 935c3b28ae2SAtsushi Nemoto size = ramsize - pos; 936c3b28ae2SAtsushi Nemoto memcpy_toio(dev->base + pos, buf, size); 937c3b28ae2SAtsushi Nemoto return size; 938c3b28ae2SAtsushi Nemoto } 939c3b28ae2SAtsushi Nemoto 940c3b28ae2SAtsushi Nemoto void __init txx9_sramc_init(struct resource *r) 941c3b28ae2SAtsushi Nemoto { 942269a3eb1SKay Sievers struct txx9_sramc_dev *dev; 943c3b28ae2SAtsushi Nemoto size_t size; 944c3b28ae2SAtsushi Nemoto int err; 945c3b28ae2SAtsushi Nemoto 946269a3eb1SKay Sievers err = subsys_system_register(&txx9_sramc_subsys, NULL); 947269a3eb1SKay Sievers if (err) 948c3b28ae2SAtsushi Nemoto return; 949c3b28ae2SAtsushi Nemoto dev = kzalloc(sizeof(*dev), GFP_KERNEL); 950c3b28ae2SAtsushi Nemoto if (!dev) 951c3b28ae2SAtsushi Nemoto return; 952c3b28ae2SAtsushi Nemoto size = resource_size(r); 953c3b28ae2SAtsushi Nemoto dev->base = ioremap(r->start, size); 954c3b28ae2SAtsushi Nemoto if (!dev->base) 955c3b28ae2SAtsushi Nemoto goto exit; 956269a3eb1SKay Sievers dev->dev.bus = &txx9_sramc_subsys; 957f937331bSWolfram Sang sysfs_bin_attr_init(&dev->bindata_attr); 958c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.name = "bindata"; 959c3b28ae2SAtsushi Nemoto dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR; 960c3b28ae2SAtsushi Nemoto dev->bindata_attr.read = txx9_sram_read; 961c3b28ae2SAtsushi Nemoto dev->bindata_attr.write = txx9_sram_write; 962c3b28ae2SAtsushi Nemoto dev->bindata_attr.size = size; 963c3b28ae2SAtsushi Nemoto dev->bindata_attr.private = dev; 964269a3eb1SKay Sievers err = device_register(&dev->dev); 965c3b28ae2SAtsushi Nemoto if (err) 966c3b28ae2SAtsushi Nemoto goto exit; 967c3b28ae2SAtsushi Nemoto err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr); 968c3b28ae2SAtsushi Nemoto if (err) { 969269a3eb1SKay Sievers device_unregister(&dev->dev); 970c3b28ae2SAtsushi Nemoto goto exit; 971c3b28ae2SAtsushi Nemoto } 972c3b28ae2SAtsushi Nemoto return; 973c3b28ae2SAtsushi Nemoto exit: 974c3b28ae2SAtsushi Nemoto if (dev) { 975c3b28ae2SAtsushi Nemoto if (dev->base) 976c3b28ae2SAtsushi Nemoto iounmap(dev->base); 977c3b28ae2SAtsushi Nemoto kfree(dev); 978c3b28ae2SAtsushi Nemoto } 979c3b28ae2SAtsushi Nemoto } 980