setup.c 6.0 KB

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