Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/mips/txx9/generic/setup.c |
| 3 | * |
| 4 | * Based on linux/arch/mips/txx9/rbtx4938/setup.c, |
| 5 | * and RBTX49xx patch from CELF patch archive. |
| 6 | * |
| 7 | * 2003-2005 (c) MontaVista Software, Inc. |
| 8 | * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007 |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General Public |
| 11 | * License. See the file "COPYING" in the main directory of this archive |
| 12 | * for more details. |
| 13 | */ |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/types.h> |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/err.h> |
Atsushi Nemoto | e0eb730 | 2008-07-19 01:51:52 +0900 | [diff] [blame] | 22 | #include <linux/gpio.h> |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 24 | #include <linux/serial_core.h> |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 25 | #include <linux/mtd/physmap.h> |
Atsushi Nemoto | ae027ea | 2008-09-01 22:22:38 +0900 | [diff] [blame] | 26 | #include <linux/leds.h> |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 27 | #include <asm/bootinfo.h> |
Atsushi Nemoto | e0eb730 | 2008-07-19 01:51:52 +0900 | [diff] [blame] | 28 | #include <asm/time.h> |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 29 | #include <asm/reboot.h> |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 30 | #include <asm/r4kcache.h> |
Atsushi Nemoto | b6263ff | 2008-09-01 22:22:41 +0900 | [diff] [blame] | 31 | #include <asm/sections.h> |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 32 | #include <asm/txx9/generic.h> |
Atsushi Nemoto | 0751752 | 2008-07-24 00:25:15 +0900 | [diff] [blame] | 33 | #include <asm/txx9/pci.h> |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame] | 34 | #include <asm/txx9tmr.h> |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 35 | #ifdef CONFIG_CPU_TX49XX |
| 36 | #include <asm/txx9/tx4938.h> |
| 37 | #endif |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 38 | |
| 39 | /* EBUSC settings of TX4927, etc. */ |
| 40 | struct resource txx9_ce_res[8]; |
| 41 | static char txx9_ce_res_name[8][4]; /* "CEn" */ |
| 42 | |
| 43 | /* pcode, internal register */ |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 44 | unsigned int txx9_pcode; |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 45 | char txx9_pcode_str[8]; |
| 46 | static struct resource txx9_reg_res = { |
| 47 | .name = txx9_pcode_str, |
| 48 | .flags = IORESOURCE_MEM, |
| 49 | }; |
| 50 | void __init |
| 51 | txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) |
| 52 | { |
| 53 | int i; |
| 54 | |
| 55 | for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { |
| 56 | sprintf(txx9_ce_res_name[i], "CE%d", i); |
| 57 | txx9_ce_res[i].flags = IORESOURCE_MEM; |
| 58 | txx9_ce_res[i].name = txx9_ce_res_name[i]; |
| 59 | } |
| 60 | |
Atsushi Nemoto | 073828d | 2008-08-26 21:29:58 +0900 | [diff] [blame] | 61 | txx9_pcode = pcode; |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 62 | sprintf(txx9_pcode_str, "TX%x", pcode); |
| 63 | if (base) { |
| 64 | txx9_reg_res.start = base & 0xfffffffffULL; |
| 65 | txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); |
| 66 | request_resource(&iomem_resource, &txx9_reg_res); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* clocks */ |
| 71 | unsigned int txx9_master_clock; |
| 72 | unsigned int txx9_cpu_clock; |
| 73 | unsigned int txx9_gbus_clock; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 74 | |
Atsushi Nemoto | c7b95bc | 2008-08-19 22:55:10 +0900 | [diff] [blame] | 75 | #ifdef CONFIG_CPU_TX39XX |
| 76 | /* don't enable by default - see errata */ |
| 77 | int txx9_ccfg_toeon __initdata; |
| 78 | #else |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 79 | int txx9_ccfg_toeon __initdata = 1; |
Atsushi Nemoto | c7b95bc | 2008-08-19 22:55:10 +0900 | [diff] [blame] | 80 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 81 | |
| 82 | /* Minimum CLK support */ |
| 83 | |
| 84 | struct clk *clk_get(struct device *dev, const char *id) |
| 85 | { |
| 86 | if (!strcmp(id, "spi-baseclk")) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 87 | return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 88 | if (!strcmp(id, "imbus_clk")) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 89 | return (struct clk *)((unsigned long)txx9_gbus_clock / 2); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 90 | return ERR_PTR(-ENOENT); |
| 91 | } |
| 92 | EXPORT_SYMBOL(clk_get); |
| 93 | |
| 94 | int clk_enable(struct clk *clk) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | EXPORT_SYMBOL(clk_enable); |
| 99 | |
| 100 | void clk_disable(struct clk *clk) |
| 101 | { |
| 102 | } |
| 103 | EXPORT_SYMBOL(clk_disable); |
| 104 | |
| 105 | unsigned long clk_get_rate(struct clk *clk) |
| 106 | { |
| 107 | return (unsigned long)clk; |
| 108 | } |
| 109 | EXPORT_SYMBOL(clk_get_rate); |
| 110 | |
| 111 | void clk_put(struct clk *clk) |
| 112 | { |
| 113 | } |
| 114 | EXPORT_SYMBOL(clk_put); |
| 115 | |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 116 | /* GPIO support */ |
| 117 | |
| 118 | #ifdef CONFIG_GENERIC_GPIO |
| 119 | int gpio_to_irq(unsigned gpio) |
| 120 | { |
| 121 | return -EINVAL; |
| 122 | } |
| 123 | EXPORT_SYMBOL(gpio_to_irq); |
| 124 | |
| 125 | int irq_to_gpio(unsigned irq) |
| 126 | { |
| 127 | return -EINVAL; |
| 128 | } |
| 129 | EXPORT_SYMBOL(irq_to_gpio); |
| 130 | #endif |
| 131 | |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 132 | #define BOARD_VEC(board) extern struct txx9_board_vec board; |
| 133 | #include <asm/txx9/boards.h> |
| 134 | #undef BOARD_VEC |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 135 | |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 136 | struct txx9_board_vec *txx9_board_vec __initdata; |
| 137 | static char txx9_system_type[32]; |
| 138 | |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 139 | static struct txx9_board_vec *board_vecs[] __initdata = { |
| 140 | #define BOARD_VEC(board) &board, |
| 141 | #include <asm/txx9/boards.h> |
| 142 | #undef BOARD_VEC |
| 143 | }; |
| 144 | |
| 145 | static struct txx9_board_vec *__init find_board_byname(const char *name) |
| 146 | { |
| 147 | int i; |
| 148 | |
| 149 | /* search board_vecs table */ |
| 150 | for (i = 0; i < ARRAY_SIZE(board_vecs); i++) { |
| 151 | if (strstr(board_vecs[i]->system, name)) |
| 152 | return board_vecs[i]; |
| 153 | } |
| 154 | return NULL; |
| 155 | } |
| 156 | |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 157 | static void __init prom_init_cmdline(void) |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 158 | { |
| 159 | int argc = (int)fw_arg0; |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 160 | int *argv32 = (int *)fw_arg1; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 161 | int i; /* Always ignore the "-c" at argv[0] */ |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 162 | char builtin[CL_SIZE]; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 163 | |
| 164 | /* ignore all built-in args if any f/w args given */ |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 165 | /* |
| 166 | * But if built-in strings was started with '+', append them |
| 167 | * to command line args. If built-in was started with '-', |
| 168 | * ignore all f/w args. |
| 169 | */ |
| 170 | builtin[0] = '\0'; |
| 171 | if (arcs_cmdline[0] == '+') |
| 172 | strcpy(builtin, arcs_cmdline + 1); |
| 173 | else if (arcs_cmdline[0] == '-') { |
| 174 | strcpy(builtin, arcs_cmdline + 1); |
| 175 | argc = 0; |
| 176 | } else if (argc <= 1) |
| 177 | strcpy(builtin, arcs_cmdline); |
| 178 | arcs_cmdline[0] = '\0'; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 179 | |
| 180 | for (i = 1; i < argc; i++) { |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 181 | char *str = (char *)(long)argv32[i]; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 182 | if (i != 1) |
| 183 | strcat(arcs_cmdline, " "); |
Atsushi Nemoto | e0dfb20 | 2008-08-19 22:55:06 +0900 | [diff] [blame] | 184 | if (strchr(str, ' ')) { |
| 185 | strcat(arcs_cmdline, "\""); |
| 186 | strcat(arcs_cmdline, str); |
| 187 | strcat(arcs_cmdline, "\""); |
| 188 | } else |
| 189 | strcat(arcs_cmdline, str); |
| 190 | } |
| 191 | /* append saved builtin args */ |
| 192 | if (builtin[0]) { |
| 193 | if (arcs_cmdline[0]) |
| 194 | strcat(arcs_cmdline, " "); |
| 195 | strcat(arcs_cmdline, builtin); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 199 | static int txx9_ic_disable __initdata; |
| 200 | static int txx9_dc_disable __initdata; |
| 201 | |
| 202 | #if defined(CONFIG_CPU_TX49XX) |
| 203 | /* flush all cache on very early stage (before 4k_cache_init) */ |
| 204 | static void __init early_flush_dcache(void) |
| 205 | { |
| 206 | unsigned int conf = read_c0_config(); |
| 207 | unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6)); |
| 208 | unsigned int linesz = 32; |
| 209 | unsigned long addr, end; |
| 210 | |
| 211 | end = INDEX_BASE + dc_size / 4; |
| 212 | /* 4way, waybit=0 */ |
| 213 | for (addr = INDEX_BASE; addr < end; addr += linesz) { |
| 214 | cache_op(Index_Writeback_Inv_D, addr | 0); |
| 215 | cache_op(Index_Writeback_Inv_D, addr | 1); |
| 216 | cache_op(Index_Writeback_Inv_D, addr | 2); |
| 217 | cache_op(Index_Writeback_Inv_D, addr | 3); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static void __init txx9_cache_fixup(void) |
| 222 | { |
| 223 | unsigned int conf; |
| 224 | |
| 225 | conf = read_c0_config(); |
| 226 | /* flush and disable */ |
| 227 | if (txx9_ic_disable) { |
| 228 | conf |= TX49_CONF_IC; |
| 229 | write_c0_config(conf); |
| 230 | } |
| 231 | if (txx9_dc_disable) { |
| 232 | early_flush_dcache(); |
| 233 | conf |= TX49_CONF_DC; |
| 234 | write_c0_config(conf); |
| 235 | } |
| 236 | |
| 237 | /* enable cache */ |
| 238 | conf = read_c0_config(); |
| 239 | if (!txx9_ic_disable) |
| 240 | conf &= ~TX49_CONF_IC; |
| 241 | if (!txx9_dc_disable) |
| 242 | conf &= ~TX49_CONF_DC; |
| 243 | write_c0_config(conf); |
| 244 | |
| 245 | if (conf & TX49_CONF_IC) |
| 246 | pr_info("TX49XX I-Cache disabled.\n"); |
| 247 | if (conf & TX49_CONF_DC) |
| 248 | pr_info("TX49XX D-Cache disabled.\n"); |
| 249 | } |
| 250 | #elif defined(CONFIG_CPU_TX39XX) |
| 251 | /* flush all cache on very early stage (before tx39_cache_init) */ |
| 252 | static void __init early_flush_dcache(void) |
| 253 | { |
| 254 | unsigned int conf = read_c0_config(); |
| 255 | unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >> |
| 256 | TX39_CONF_DCS_SHIFT)); |
| 257 | unsigned int linesz = 16; |
| 258 | unsigned long addr, end; |
| 259 | |
| 260 | end = INDEX_BASE + dc_size / 2; |
| 261 | /* 2way, waybit=0 */ |
| 262 | for (addr = INDEX_BASE; addr < end; addr += linesz) { |
| 263 | cache_op(Index_Writeback_Inv_D, addr | 0); |
| 264 | cache_op(Index_Writeback_Inv_D, addr | 1); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static void __init txx9_cache_fixup(void) |
| 269 | { |
| 270 | unsigned int conf; |
| 271 | |
| 272 | conf = read_c0_config(); |
| 273 | /* flush and disable */ |
| 274 | if (txx9_ic_disable) { |
| 275 | conf &= ~TX39_CONF_ICE; |
| 276 | write_c0_config(conf); |
| 277 | } |
| 278 | if (txx9_dc_disable) { |
| 279 | early_flush_dcache(); |
| 280 | conf &= ~TX39_CONF_DCE; |
| 281 | write_c0_config(conf); |
| 282 | } |
| 283 | |
| 284 | /* enable cache */ |
| 285 | conf = read_c0_config(); |
| 286 | if (!txx9_ic_disable) |
| 287 | conf |= TX39_CONF_ICE; |
| 288 | if (!txx9_dc_disable) |
| 289 | conf |= TX39_CONF_DCE; |
| 290 | write_c0_config(conf); |
| 291 | |
| 292 | if (!(conf & TX39_CONF_ICE)) |
| 293 | pr_info("TX39XX I-Cache disabled.\n"); |
| 294 | if (!(conf & TX39_CONF_DCE)) |
| 295 | pr_info("TX39XX D-Cache disabled.\n"); |
| 296 | } |
| 297 | #else |
| 298 | static inline void txx9_cache_fixup(void) |
| 299 | { |
| 300 | } |
| 301 | #endif |
| 302 | |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 303 | static void __init preprocess_cmdline(void) |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 304 | { |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 305 | char cmdline[CL_SIZE]; |
| 306 | char *s; |
| 307 | |
| 308 | strcpy(cmdline, arcs_cmdline); |
| 309 | s = cmdline; |
| 310 | arcs_cmdline[0] = '\0'; |
| 311 | while (s && *s) { |
| 312 | char *str = strsep(&s, " "); |
| 313 | if (strncmp(str, "board=", 6) == 0) { |
| 314 | txx9_board_vec = find_board_byname(str + 6); |
| 315 | continue; |
| 316 | } else if (strncmp(str, "masterclk=", 10) == 0) { |
| 317 | unsigned long val; |
| 318 | if (strict_strtoul(str + 10, 10, &val) == 0) |
| 319 | txx9_master_clock = val; |
| 320 | continue; |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 321 | } else if (strcmp(str, "icdisable") == 0) { |
| 322 | txx9_ic_disable = 1; |
| 323 | continue; |
| 324 | } else if (strcmp(str, "dcdisable") == 0) { |
| 325 | txx9_dc_disable = 1; |
| 326 | continue; |
Atsushi Nemoto | c7b95bc | 2008-08-19 22:55:10 +0900 | [diff] [blame] | 327 | } else if (strcmp(str, "toeoff") == 0) { |
| 328 | txx9_ccfg_toeon = 0; |
| 329 | continue; |
| 330 | } else if (strcmp(str, "toeon") == 0) { |
| 331 | txx9_ccfg_toeon = 1; |
| 332 | continue; |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 333 | } |
| 334 | if (arcs_cmdline[0]) |
| 335 | strcat(arcs_cmdline, " "); |
| 336 | strcat(arcs_cmdline, str); |
| 337 | } |
Atsushi Nemoto | d10e025 | 2008-08-19 22:55:09 +0900 | [diff] [blame] | 338 | |
| 339 | txx9_cache_fixup(); |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static void __init select_board(void) |
| 343 | { |
| 344 | const char *envstr; |
| 345 | |
| 346 | /* first, determine by "board=" argument in preprocess_cmdline() */ |
| 347 | if (txx9_board_vec) |
| 348 | return; |
| 349 | /* next, determine by "board" envvar */ |
| 350 | envstr = prom_getenv("board"); |
| 351 | if (envstr) { |
| 352 | txx9_board_vec = find_board_byname(envstr); |
| 353 | if (txx9_board_vec) |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | /* select "default" board */ |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 358 | #ifdef CONFIG_CPU_TX39XX |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 359 | txx9_board_vec = &jmr3927_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 360 | #endif |
| 361 | #ifdef CONFIG_CPU_TX49XX |
| 362 | switch (TX4938_REV_PCODE()) { |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 363 | #ifdef CONFIG_TOSHIBA_RBTX4927 |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 364 | case 0x4927: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 365 | txx9_board_vec = &rbtx4927_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 366 | break; |
| 367 | case 0x4937: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 368 | txx9_board_vec = &rbtx4937_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 369 | break; |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 370 | #endif |
| 371 | #ifdef CONFIG_TOSHIBA_RBTX4938 |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 372 | case 0x4938: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 373 | txx9_board_vec = &rbtx4938_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 374 | break; |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 375 | #endif |
Atsushi Nemoto | b27311e | 2008-09-01 22:22:40 +0900 | [diff] [blame] | 376 | #ifdef CONFIG_TOSHIBA_RBTX4939 |
| 377 | case 0x4939: |
| 378 | txx9_board_vec = &rbtx4939_vec; |
| 379 | break; |
| 380 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 381 | } |
| 382 | #endif |
Atsushi Nemoto | 860e546 | 2008-08-19 22:55:08 +0900 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | void __init prom_init(void) |
| 386 | { |
| 387 | prom_init_cmdline(); |
| 388 | preprocess_cmdline(); |
| 389 | select_board(); |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 390 | |
| 391 | strcpy(txx9_system_type, txx9_board_vec->system); |
| 392 | |
Atsushi Nemoto | 7b22609 | 2008-07-14 00:15:04 +0900 | [diff] [blame] | 393 | txx9_board_vec->prom_init(); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void __init prom_free_prom_memory(void) |
| 397 | { |
Atsushi Nemoto | b6263ff | 2008-09-01 22:22:41 +0900 | [diff] [blame] | 398 | unsigned long saddr = PAGE_SIZE; |
| 399 | unsigned long eaddr = __pa_symbol(&_text); |
| 400 | |
| 401 | if (saddr < eaddr) |
| 402 | free_init_pages("prom memory", saddr, eaddr); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | const char *get_system_type(void) |
| 406 | { |
| 407 | return txx9_system_type; |
| 408 | } |
| 409 | |
| 410 | char * __init prom_getcmdline(void) |
| 411 | { |
| 412 | return &(arcs_cmdline[0]); |
| 413 | } |
| 414 | |
Atsushi Nemoto | 265b89d | 2008-08-19 22:55:07 +0900 | [diff] [blame] | 415 | const char *__init prom_getenv(const char *name) |
| 416 | { |
| 417 | const s32 *str = (const s32 *)fw_arg2; |
| 418 | |
| 419 | if (!str) |
| 420 | return NULL; |
| 421 | /* YAMON style ("name", "value" pairs) */ |
| 422 | while (str[0] && str[1]) { |
| 423 | if (!strcmp((const char *)(unsigned long)str[0], name)) |
| 424 | return (const char *)(unsigned long)str[1]; |
| 425 | str += 2; |
| 426 | } |
| 427 | return NULL; |
| 428 | } |
| 429 | |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 430 | static void __noreturn txx9_machine_halt(void) |
| 431 | { |
| 432 | local_irq_disable(); |
| 433 | clear_c0_status(ST0_IM); |
| 434 | while (1) { |
| 435 | if (cpu_wait) { |
| 436 | (*cpu_wait)(); |
| 437 | if (cpu_has_counter) { |
| 438 | /* |
| 439 | * Clear counter interrupt while it |
| 440 | * breaks WAIT instruction even if |
| 441 | * masked. |
| 442 | */ |
| 443 | write_c0_compare(0); |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 449 | /* Watchdog support */ |
| 450 | void __init txx9_wdt_init(unsigned long base) |
| 451 | { |
| 452 | struct resource res = { |
| 453 | .start = base, |
| 454 | .end = base + 0x100 - 1, |
| 455 | .flags = IORESOURCE_MEM, |
| 456 | }; |
| 457 | platform_device_register_simple("txx9wdt", -1, &res, 1); |
| 458 | } |
| 459 | |
Atsushi Nemoto | 496a3b5 | 2008-08-19 22:55:15 +0900 | [diff] [blame] | 460 | void txx9_wdt_now(unsigned long base) |
| 461 | { |
| 462 | struct txx9_tmr_reg __iomem *tmrptr = |
| 463 | ioremap(base, sizeof(struct txx9_tmr_reg)); |
| 464 | /* disable watch dog timer */ |
| 465 | __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr); |
| 466 | __raw_writel(0, &tmrptr->tcr); |
| 467 | /* kick watchdog */ |
| 468 | __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr); |
| 469 | __raw_writel(1, &tmrptr->cpra); /* immediate */ |
| 470 | __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG, |
| 471 | &tmrptr->tcr); |
| 472 | } |
| 473 | |
Atsushi Nemoto | c49f91f | 2008-07-24 00:25:20 +0900 | [diff] [blame] | 474 | /* SPI support */ |
| 475 | void __init txx9_spi_init(int busid, unsigned long base, int irq) |
| 476 | { |
| 477 | struct resource res[] = { |
| 478 | { |
| 479 | .start = base, |
| 480 | .end = base + 0x20 - 1, |
| 481 | .flags = IORESOURCE_MEM, |
| 482 | }, { |
| 483 | .start = irq, |
| 484 | .flags = IORESOURCE_IRQ, |
| 485 | }, |
| 486 | }; |
| 487 | platform_device_register_simple("spi_txx9", busid, |
| 488 | res, ARRAY_SIZE(res)); |
| 489 | } |
| 490 | |
| 491 | void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr) |
| 492 | { |
| 493 | struct platform_device *pdev = |
| 494 | platform_device_alloc("tc35815-mac", id); |
| 495 | if (!pdev || |
| 496 | platform_device_add_data(pdev, ethaddr, 6) || |
| 497 | platform_device_add(pdev)) |
| 498 | platform_device_put(pdev); |
| 499 | } |
| 500 | |
Atsushi Nemoto | 7779a5e | 2008-07-25 23:08:06 +0900 | [diff] [blame] | 501 | void __init txx9_sio_init(unsigned long baseaddr, int irq, |
| 502 | unsigned int line, unsigned int sclk, int nocts) |
| 503 | { |
| 504 | #ifdef CONFIG_SERIAL_TXX9 |
| 505 | struct uart_port req; |
| 506 | |
| 507 | memset(&req, 0, sizeof(req)); |
| 508 | req.line = line; |
| 509 | req.iotype = UPIO_MEM; |
| 510 | req.membase = ioremap(baseaddr, 0x24); |
| 511 | req.mapbase = baseaddr; |
| 512 | req.irq = irq; |
| 513 | if (!nocts) |
| 514 | req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/; |
| 515 | if (sclk) { |
| 516 | req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/; |
| 517 | req.uartclk = sclk; |
| 518 | } else |
| 519 | req.uartclk = TXX9_IMCLK; |
| 520 | early_serial_txx9_setup(&req); |
| 521 | #endif /* CONFIG_SERIAL_TXX9 */ |
| 522 | } |
| 523 | |
Atsushi Nemoto | e352953 | 2008-07-29 22:10:08 +0900 | [diff] [blame] | 524 | #ifdef CONFIG_EARLY_PRINTK |
| 525 | static void __init null_prom_putchar(char c) |
| 526 | { |
| 527 | } |
| 528 | void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar; |
| 529 | |
| 530 | void __init prom_putchar(char c) |
| 531 | { |
| 532 | txx9_prom_putchar(c); |
| 533 | } |
| 534 | |
| 535 | static void __iomem *early_txx9_sio_port; |
| 536 | |
| 537 | static void __init early_txx9_sio_putchar(char c) |
| 538 | { |
| 539 | #define TXX9_SICISR 0x0c |
| 540 | #define TXX9_SITFIFO 0x1c |
| 541 | #define TXX9_SICISR_TXALS 0x00000002 |
| 542 | while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) & |
| 543 | TXX9_SICISR_TXALS)) |
| 544 | ; |
| 545 | __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO); |
| 546 | } |
| 547 | |
| 548 | void __init txx9_sio_putchar_init(unsigned long baseaddr) |
| 549 | { |
| 550 | early_txx9_sio_port = ioremap(baseaddr, 0x24); |
| 551 | txx9_prom_putchar = early_txx9_sio_putchar; |
| 552 | } |
| 553 | #endif /* CONFIG_EARLY_PRINTK */ |
| 554 | |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 555 | /* wrappers */ |
| 556 | void __init plat_mem_setup(void) |
| 557 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 558 | ioport_resource.start = 0; |
| 559 | ioport_resource.end = ~0UL; /* no limit */ |
| 560 | iomem_resource.start = 0; |
| 561 | iomem_resource.end = ~0UL; /* no limit */ |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 562 | |
| 563 | /* fallback restart/halt routines */ |
| 564 | _machine_restart = (void (*)(char *))txx9_machine_halt; |
| 565 | _machine_halt = txx9_machine_halt; |
| 566 | pm_power_off = txx9_machine_halt; |
| 567 | |
Atsushi Nemoto | 0751752 | 2008-07-24 00:25:15 +0900 | [diff] [blame] | 568 | #ifdef CONFIG_PCI |
| 569 | pcibios_plat_setup = txx9_pcibios_setup; |
| 570 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 571 | txx9_board_vec->mem_setup(); |
| 572 | } |
| 573 | |
| 574 | void __init arch_init_irq(void) |
| 575 | { |
| 576 | txx9_board_vec->irq_setup(); |
| 577 | } |
| 578 | |
| 579 | void __init plat_time_init(void) |
| 580 | { |
Atsushi Nemoto | 1374d08 | 2008-07-31 22:29:53 +0900 | [diff] [blame] | 581 | #ifdef CONFIG_CPU_TX49XX |
| 582 | mips_hpt_frequency = txx9_cpu_clock / 2; |
| 583 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 584 | txx9_board_vec->time_init(); |
| 585 | } |
| 586 | |
| 587 | static int __init _txx9_arch_init(void) |
| 588 | { |
| 589 | if (txx9_board_vec->arch_init) |
| 590 | txx9_board_vec->arch_init(); |
| 591 | return 0; |
| 592 | } |
| 593 | arch_initcall(_txx9_arch_init); |
| 594 | |
| 595 | static int __init _txx9_device_init(void) |
| 596 | { |
| 597 | if (txx9_board_vec->device_init) |
| 598 | txx9_board_vec->device_init(); |
| 599 | return 0; |
| 600 | } |
| 601 | device_initcall(_txx9_device_init); |
| 602 | |
| 603 | int (*txx9_irq_dispatch)(int pending); |
| 604 | asmlinkage void plat_irq_dispatch(void) |
| 605 | { |
| 606 | int pending = read_c0_status() & read_c0_cause() & ST0_IM; |
| 607 | int irq = txx9_irq_dispatch(pending); |
| 608 | |
| 609 | if (likely(irq >= 0)) |
| 610 | do_IRQ(irq); |
| 611 | else |
| 612 | spurious_interrupt(); |
| 613 | } |
Atsushi Nemoto | 4c642f3 | 2008-07-13 23:37:56 +0900 | [diff] [blame] | 614 | |
| 615 | /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ |
| 616 | #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B |
| 617 | static unsigned long __swizzle_addr_none(unsigned long port) |
| 618 | { |
| 619 | return port; |
| 620 | } |
| 621 | unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; |
| 622 | EXPORT_SYMBOL(__swizzle_addr_b); |
| 623 | #endif |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 624 | |
Atsushi Nemoto | 1ba5a17 | 2008-10-21 00:01:06 +0900 | [diff] [blame] | 625 | #ifdef NEEDS_TXX9_IOSWABW |
| 626 | static u16 ioswabw_default(volatile u16 *a, u16 x) |
| 627 | { |
| 628 | return le16_to_cpu(x); |
| 629 | } |
| 630 | static u16 __mem_ioswabw_default(volatile u16 *a, u16 x) |
| 631 | { |
| 632 | return x; |
| 633 | } |
| 634 | u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default; |
| 635 | EXPORT_SYMBOL(ioswabw); |
| 636 | u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default; |
| 637 | EXPORT_SYMBOL(__mem_ioswabw); |
| 638 | #endif |
| 639 | |
Atsushi Nemoto | 51f607c | 2008-08-19 22:55:11 +0900 | [diff] [blame] | 640 | void __init txx9_physmap_flash_init(int no, unsigned long addr, |
| 641 | unsigned long size, |
| 642 | const struct physmap_flash_data *pdata) |
| 643 | { |
| 644 | #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) |
| 645 | struct resource res = { |
| 646 | .start = addr, |
| 647 | .end = addr + size - 1, |
| 648 | .flags = IORESOURCE_MEM, |
| 649 | }; |
| 650 | struct platform_device *pdev; |
| 651 | #ifdef CONFIG_MTD_PARTITIONS |
| 652 | static struct mtd_partition parts[2]; |
| 653 | struct physmap_flash_data pdata_part; |
| 654 | |
| 655 | /* If this area contained boot area, make separate partition */ |
| 656 | if (pdata->nr_parts == 0 && !pdata->parts && |
| 657 | addr < 0x1fc00000 && addr + size > 0x1fc00000 && |
| 658 | !parts[0].name) { |
| 659 | parts[0].name = "boot"; |
| 660 | parts[0].offset = 0x1fc00000 - addr; |
| 661 | parts[0].size = addr + size - 0x1fc00000; |
| 662 | parts[1].name = "user"; |
| 663 | parts[1].offset = 0; |
| 664 | parts[1].size = 0x1fc00000 - addr; |
| 665 | pdata_part = *pdata; |
| 666 | pdata_part.nr_parts = ARRAY_SIZE(parts); |
| 667 | pdata_part.parts = parts; |
| 668 | pdata = &pdata_part; |
| 669 | } |
| 670 | #endif |
| 671 | pdev = platform_device_alloc("physmap-flash", no); |
| 672 | if (!pdev || |
| 673 | platform_device_add_resources(pdev, &res, 1) || |
| 674 | platform_device_add_data(pdev, pdata, sizeof(*pdata)) || |
| 675 | platform_device_add(pdev)) |
| 676 | platform_device_put(pdev); |
| 677 | #endif |
| 678 | } |
Atsushi Nemoto | ae027ea | 2008-09-01 22:22:38 +0900 | [diff] [blame] | 679 | |
| 680 | #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) |
| 681 | static DEFINE_SPINLOCK(txx9_iocled_lock); |
| 682 | |
| 683 | #define TXX9_IOCLED_MAXLEDS 8 |
| 684 | |
| 685 | struct txx9_iocled_data { |
| 686 | struct gpio_chip chip; |
| 687 | u8 cur_val; |
| 688 | void __iomem *mmioaddr; |
| 689 | struct gpio_led_platform_data pdata; |
| 690 | struct gpio_led leds[TXX9_IOCLED_MAXLEDS]; |
| 691 | char names[TXX9_IOCLED_MAXLEDS][32]; |
| 692 | }; |
| 693 | |
| 694 | static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset) |
| 695 | { |
| 696 | struct txx9_iocled_data *data = |
| 697 | container_of(chip, struct txx9_iocled_data, chip); |
| 698 | return data->cur_val & (1 << offset); |
| 699 | } |
| 700 | |
| 701 | static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset, |
| 702 | int value) |
| 703 | { |
| 704 | struct txx9_iocled_data *data = |
| 705 | container_of(chip, struct txx9_iocled_data, chip); |
| 706 | unsigned long flags; |
| 707 | spin_lock_irqsave(&txx9_iocled_lock, flags); |
| 708 | if (value) |
| 709 | data->cur_val |= 1 << offset; |
| 710 | else |
| 711 | data->cur_val &= ~(1 << offset); |
| 712 | writeb(data->cur_val, data->mmioaddr); |
| 713 | mmiowb(); |
| 714 | spin_unlock_irqrestore(&txx9_iocled_lock, flags); |
| 715 | } |
| 716 | |
| 717 | static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset) |
| 718 | { |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset, |
| 723 | int value) |
| 724 | { |
| 725 | txx9_iocled_set(chip, offset, value); |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | void __init txx9_iocled_init(unsigned long baseaddr, |
| 730 | int basenum, unsigned int num, int lowactive, |
| 731 | const char *color, char **deftriggers) |
| 732 | { |
| 733 | struct txx9_iocled_data *iocled; |
| 734 | struct platform_device *pdev; |
| 735 | int i; |
| 736 | static char *default_triggers[] __initdata = { |
| 737 | "heartbeat", |
| 738 | "ide-disk", |
| 739 | "nand-disk", |
| 740 | NULL, |
| 741 | }; |
| 742 | |
| 743 | if (!deftriggers) |
| 744 | deftriggers = default_triggers; |
| 745 | iocled = kzalloc(sizeof(*iocled), GFP_KERNEL); |
| 746 | if (!iocled) |
| 747 | return; |
| 748 | iocled->mmioaddr = ioremap(baseaddr, 1); |
| 749 | if (!iocled->mmioaddr) |
| 750 | return; |
| 751 | iocled->chip.get = txx9_iocled_get; |
| 752 | iocled->chip.set = txx9_iocled_set; |
| 753 | iocled->chip.direction_input = txx9_iocled_dir_in; |
| 754 | iocled->chip.direction_output = txx9_iocled_dir_out; |
| 755 | iocled->chip.label = "iocled"; |
| 756 | iocled->chip.base = basenum; |
| 757 | iocled->chip.ngpio = num; |
| 758 | if (gpiochip_add(&iocled->chip)) |
| 759 | return; |
| 760 | if (basenum < 0) |
| 761 | basenum = iocled->chip.base; |
| 762 | |
| 763 | pdev = platform_device_alloc("leds-gpio", basenum); |
| 764 | if (!pdev) |
| 765 | return; |
| 766 | iocled->pdata.num_leds = num; |
| 767 | iocled->pdata.leds = iocled->leds; |
| 768 | for (i = 0; i < num; i++) { |
| 769 | struct gpio_led *led = &iocled->leds[i]; |
| 770 | snprintf(iocled->names[i], sizeof(iocled->names[i]), |
| 771 | "iocled:%s:%u", color, i); |
| 772 | led->name = iocled->names[i]; |
| 773 | led->gpio = basenum + i; |
| 774 | led->active_low = lowactive; |
| 775 | if (deftriggers && *deftriggers) |
| 776 | led->default_trigger = *deftriggers++; |
| 777 | } |
| 778 | pdev->dev.platform_data = &iocled->pdata; |
| 779 | if (platform_device_add(pdev)) |
| 780 | platform_device_put(pdev); |
| 781 | } |
| 782 | #else /* CONFIG_LEDS_GPIO */ |
| 783 | void __init txx9_iocled_init(unsigned long baseaddr, |
| 784 | int basenum, unsigned int num, int lowactive, |
| 785 | const char *color, char **deftriggers) |
| 786 | { |
| 787 | } |
| 788 | #endif /* CONFIG_LEDS_GPIO */ |