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