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 | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 24 | #include <asm/bootinfo.h> |
Atsushi Nemoto | e0eb730 | 2008-07-19 01:51:52 +0900 | [diff] [blame] | 25 | #include <asm/time.h> |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 26 | #include <asm/reboot.h> |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 27 | #include <asm/txx9/generic.h> |
Atsushi Nemoto | 0751752 | 2008-07-24 00:25:15 +0900 | [diff] [blame] | 28 | #include <asm/txx9/pci.h> |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 29 | #ifdef CONFIG_CPU_TX49XX |
| 30 | #include <asm/txx9/tx4938.h> |
| 31 | #endif |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 32 | |
| 33 | /* EBUSC settings of TX4927, etc. */ |
| 34 | struct resource txx9_ce_res[8]; |
| 35 | static char txx9_ce_res_name[8][4]; /* "CEn" */ |
| 36 | |
| 37 | /* pcode, internal register */ |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 38 | unsigned int txx9_pcode; |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame] | 39 | char txx9_pcode_str[8]; |
| 40 | static struct resource txx9_reg_res = { |
| 41 | .name = txx9_pcode_str, |
| 42 | .flags = IORESOURCE_MEM, |
| 43 | }; |
| 44 | void __init |
| 45 | txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size) |
| 46 | { |
| 47 | int i; |
| 48 | |
| 49 | for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) { |
| 50 | sprintf(txx9_ce_res_name[i], "CE%d", i); |
| 51 | txx9_ce_res[i].flags = IORESOURCE_MEM; |
| 52 | txx9_ce_res[i].name = txx9_ce_res_name[i]; |
| 53 | } |
| 54 | |
| 55 | sprintf(txx9_pcode_str, "TX%x", pcode); |
| 56 | if (base) { |
| 57 | txx9_reg_res.start = base & 0xfffffffffULL; |
| 58 | txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1); |
| 59 | request_resource(&iomem_resource, &txx9_reg_res); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* clocks */ |
| 64 | unsigned int txx9_master_clock; |
| 65 | unsigned int txx9_cpu_clock; |
| 66 | unsigned int txx9_gbus_clock; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 67 | |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 68 | int txx9_ccfg_toeon __initdata = 1; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 69 | |
| 70 | /* Minimum CLK support */ |
| 71 | |
| 72 | struct clk *clk_get(struct device *dev, const char *id) |
| 73 | { |
| 74 | if (!strcmp(id, "spi-baseclk")) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 75 | return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 76 | if (!strcmp(id, "imbus_clk")) |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 77 | return (struct clk *)((unsigned long)txx9_gbus_clock / 2); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 78 | return ERR_PTR(-ENOENT); |
| 79 | } |
| 80 | EXPORT_SYMBOL(clk_get); |
| 81 | |
| 82 | int clk_enable(struct clk *clk) |
| 83 | { |
| 84 | return 0; |
| 85 | } |
| 86 | EXPORT_SYMBOL(clk_enable); |
| 87 | |
| 88 | void clk_disable(struct clk *clk) |
| 89 | { |
| 90 | } |
| 91 | EXPORT_SYMBOL(clk_disable); |
| 92 | |
| 93 | unsigned long clk_get_rate(struct clk *clk) |
| 94 | { |
| 95 | return (unsigned long)clk; |
| 96 | } |
| 97 | EXPORT_SYMBOL(clk_get_rate); |
| 98 | |
| 99 | void clk_put(struct clk *clk) |
| 100 | { |
| 101 | } |
| 102 | EXPORT_SYMBOL(clk_put); |
| 103 | |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 104 | /* GPIO support */ |
| 105 | |
| 106 | #ifdef CONFIG_GENERIC_GPIO |
| 107 | int gpio_to_irq(unsigned gpio) |
| 108 | { |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | EXPORT_SYMBOL(gpio_to_irq); |
| 112 | |
| 113 | int irq_to_gpio(unsigned irq) |
| 114 | { |
| 115 | return -EINVAL; |
| 116 | } |
| 117 | EXPORT_SYMBOL(irq_to_gpio); |
| 118 | #endif |
| 119 | |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 120 | extern struct txx9_board_vec jmr3927_vec; |
| 121 | extern struct txx9_board_vec rbtx4927_vec; |
| 122 | extern struct txx9_board_vec rbtx4937_vec; |
| 123 | extern struct txx9_board_vec rbtx4938_vec; |
| 124 | |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 125 | struct txx9_board_vec *txx9_board_vec __initdata; |
| 126 | static char txx9_system_type[32]; |
| 127 | |
| 128 | void __init prom_init_cmdline(void) |
| 129 | { |
| 130 | int argc = (int)fw_arg0; |
| 131 | char **argv = (char **)fw_arg1; |
| 132 | int i; /* Always ignore the "-c" at argv[0] */ |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 133 | #ifdef CONFIG_64BIT |
| 134 | char *fixed_argv[32]; |
| 135 | for (i = 0; i < argc; i++) |
| 136 | fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i)); |
| 137 | argv = fixed_argv; |
| 138 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 139 | |
| 140 | /* ignore all built-in args if any f/w args given */ |
| 141 | if (argc > 1) |
| 142 | *arcs_cmdline = '\0'; |
| 143 | |
| 144 | for (i = 1; i < argc; i++) { |
| 145 | if (i != 1) |
| 146 | strcat(arcs_cmdline, " "); |
| 147 | strcat(arcs_cmdline, argv[i]); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void __init prom_init(void) |
| 152 | { |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 153 | #ifdef CONFIG_CPU_TX39XX |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 154 | txx9_board_vec = &jmr3927_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 155 | #endif |
| 156 | #ifdef CONFIG_CPU_TX49XX |
| 157 | switch (TX4938_REV_PCODE()) { |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 158 | #ifdef CONFIG_TOSHIBA_RBTX4927 |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 159 | case 0x4927: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 160 | txx9_board_vec = &rbtx4927_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 161 | break; |
| 162 | case 0x4937: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 163 | txx9_board_vec = &rbtx4937_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 164 | break; |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 165 | #endif |
| 166 | #ifdef CONFIG_TOSHIBA_RBTX4938 |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 167 | case 0x4938: |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 168 | txx9_board_vec = &rbtx4938_vec; |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 169 | break; |
Atsushi Nemoto | 8d795f2 | 2008-07-18 00:43:48 +0900 | [diff] [blame] | 170 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 171 | } |
| 172 | #endif |
Yoichi Yuasa | 7a1fdf1 | 2008-07-13 19:51:55 +0900 | [diff] [blame] | 173 | |
| 174 | strcpy(txx9_system_type, txx9_board_vec->system); |
| 175 | |
Atsushi Nemoto | 7b22609 | 2008-07-14 00:15:04 +0900 | [diff] [blame] | 176 | txx9_board_vec->prom_init(); |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void __init prom_free_prom_memory(void) |
| 180 | { |
| 181 | } |
| 182 | |
| 183 | const char *get_system_type(void) |
| 184 | { |
| 185 | return txx9_system_type; |
| 186 | } |
| 187 | |
| 188 | char * __init prom_getcmdline(void) |
| 189 | { |
| 190 | return &(arcs_cmdline[0]); |
| 191 | } |
| 192 | |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 193 | static void __noreturn txx9_machine_halt(void) |
| 194 | { |
| 195 | local_irq_disable(); |
| 196 | clear_c0_status(ST0_IM); |
| 197 | while (1) { |
| 198 | if (cpu_wait) { |
| 199 | (*cpu_wait)(); |
| 200 | if (cpu_has_counter) { |
| 201 | /* |
| 202 | * Clear counter interrupt while it |
| 203 | * breaks WAIT instruction even if |
| 204 | * masked. |
| 205 | */ |
| 206 | write_c0_compare(0); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
Atsushi Nemoto | 6831472 | 2008-07-24 00:25:18 +0900 | [diff] [blame] | 212 | /* Watchdog support */ |
| 213 | void __init txx9_wdt_init(unsigned long base) |
| 214 | { |
| 215 | struct resource res = { |
| 216 | .start = base, |
| 217 | .end = base + 0x100 - 1, |
| 218 | .flags = IORESOURCE_MEM, |
| 219 | }; |
| 220 | platform_device_register_simple("txx9wdt", -1, &res, 1); |
| 221 | } |
| 222 | |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 223 | /* wrappers */ |
| 224 | void __init plat_mem_setup(void) |
| 225 | { |
Atsushi Nemoto | 94a4c32 | 2008-07-19 01:51:47 +0900 | [diff] [blame] | 226 | ioport_resource.start = 0; |
| 227 | ioport_resource.end = ~0UL; /* no limit */ |
| 228 | iomem_resource.start = 0; |
| 229 | iomem_resource.end = ~0UL; /* no limit */ |
Atsushi Nemoto | a49297e | 2008-07-24 00:25:17 +0900 | [diff] [blame] | 230 | |
| 231 | /* fallback restart/halt routines */ |
| 232 | _machine_restart = (void (*)(char *))txx9_machine_halt; |
| 233 | _machine_halt = txx9_machine_halt; |
| 234 | pm_power_off = txx9_machine_halt; |
| 235 | |
Atsushi Nemoto | 0751752 | 2008-07-24 00:25:15 +0900 | [diff] [blame] | 236 | #ifdef CONFIG_PCI |
| 237 | pcibios_plat_setup = txx9_pcibios_setup; |
| 238 | #endif |
Atsushi Nemoto | edcaf1a | 2008-07-11 23:27:54 +0900 | [diff] [blame] | 239 | txx9_board_vec->mem_setup(); |
| 240 | } |
| 241 | |
| 242 | void __init arch_init_irq(void) |
| 243 | { |
| 244 | txx9_board_vec->irq_setup(); |
| 245 | } |
| 246 | |
| 247 | void __init plat_time_init(void) |
| 248 | { |
| 249 | txx9_board_vec->time_init(); |
| 250 | } |
| 251 | |
| 252 | static int __init _txx9_arch_init(void) |
| 253 | { |
| 254 | if (txx9_board_vec->arch_init) |
| 255 | txx9_board_vec->arch_init(); |
| 256 | return 0; |
| 257 | } |
| 258 | arch_initcall(_txx9_arch_init); |
| 259 | |
| 260 | static int __init _txx9_device_init(void) |
| 261 | { |
| 262 | if (txx9_board_vec->device_init) |
| 263 | txx9_board_vec->device_init(); |
| 264 | return 0; |
| 265 | } |
| 266 | device_initcall(_txx9_device_init); |
| 267 | |
| 268 | int (*txx9_irq_dispatch)(int pending); |
| 269 | asmlinkage void plat_irq_dispatch(void) |
| 270 | { |
| 271 | int pending = read_c0_status() & read_c0_cause() & ST0_IM; |
| 272 | int irq = txx9_irq_dispatch(pending); |
| 273 | |
| 274 | if (likely(irq >= 0)) |
| 275 | do_IRQ(irq); |
| 276 | else |
| 277 | spurious_interrupt(); |
| 278 | } |
Atsushi Nemoto | 4c642f3 | 2008-07-13 23:37:56 +0900 | [diff] [blame] | 279 | |
| 280 | /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */ |
| 281 | #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B |
| 282 | static unsigned long __swizzle_addr_none(unsigned long port) |
| 283 | { |
| 284 | return port; |
| 285 | } |
| 286 | unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; |
| 287 | EXPORT_SYMBOL(__swizzle_addr_b); |
| 288 | #endif |