setup.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 <linux/serial_core.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/time.h>
  27. #include <asm/reboot.h>
  28. #include <asm/txx9/generic.h>
  29. #include <asm/txx9/pci.h>
  30. #ifdef CONFIG_CPU_TX49XX
  31. #include <asm/txx9/tx4938.h>
  32. #endif
  33. /* EBUSC settings of TX4927, etc. */
  34. struct resource txx9_ce_res[8];
  35. static char txx9_ce_res_name[8][4]; /* "CEn" */
  36. /* pcode, internal register */
  37. unsigned int txx9_pcode;
  38. char txx9_pcode_str[8];
  39. static struct resource txx9_reg_res = {
  40. .name = txx9_pcode_str,
  41. .flags = IORESOURCE_MEM,
  42. };
  43. void __init
  44. txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
  45. {
  46. int i;
  47. for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
  48. sprintf(txx9_ce_res_name[i], "CE%d", i);
  49. txx9_ce_res[i].flags = IORESOURCE_MEM;
  50. txx9_ce_res[i].name = txx9_ce_res_name[i];
  51. }
  52. txx9_pcode = pcode;
  53. sprintf(txx9_pcode_str, "TX%x", pcode);
  54. if (base) {
  55. txx9_reg_res.start = base & 0xfffffffffULL;
  56. txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
  57. request_resource(&iomem_resource, &txx9_reg_res);
  58. }
  59. }
  60. /* clocks */
  61. unsigned int txx9_master_clock;
  62. unsigned int txx9_cpu_clock;
  63. unsigned int txx9_gbus_clock;
  64. int txx9_ccfg_toeon __initdata = 1;
  65. /* Minimum CLK support */
  66. struct clk *clk_get(struct device *dev, const char *id)
  67. {
  68. if (!strcmp(id, "spi-baseclk"))
  69. return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
  70. if (!strcmp(id, "imbus_clk"))
  71. return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
  72. return ERR_PTR(-ENOENT);
  73. }
  74. EXPORT_SYMBOL(clk_get);
  75. int clk_enable(struct clk *clk)
  76. {
  77. return 0;
  78. }
  79. EXPORT_SYMBOL(clk_enable);
  80. void clk_disable(struct clk *clk)
  81. {
  82. }
  83. EXPORT_SYMBOL(clk_disable);
  84. unsigned long clk_get_rate(struct clk *clk)
  85. {
  86. return (unsigned long)clk;
  87. }
  88. EXPORT_SYMBOL(clk_get_rate);
  89. void clk_put(struct clk *clk)
  90. {
  91. }
  92. EXPORT_SYMBOL(clk_put);
  93. /* GPIO support */
  94. #ifdef CONFIG_GENERIC_GPIO
  95. int gpio_to_irq(unsigned gpio)
  96. {
  97. return -EINVAL;
  98. }
  99. EXPORT_SYMBOL(gpio_to_irq);
  100. int irq_to_gpio(unsigned irq)
  101. {
  102. return -EINVAL;
  103. }
  104. EXPORT_SYMBOL(irq_to_gpio);
  105. #endif
  106. extern struct txx9_board_vec jmr3927_vec;
  107. extern struct txx9_board_vec rbtx4927_vec;
  108. extern struct txx9_board_vec rbtx4937_vec;
  109. extern struct txx9_board_vec rbtx4938_vec;
  110. struct txx9_board_vec *txx9_board_vec __initdata;
  111. static char txx9_system_type[32];
  112. void __init prom_init_cmdline(void)
  113. {
  114. int argc = (int)fw_arg0;
  115. char **argv = (char **)fw_arg1;
  116. int i; /* Always ignore the "-c" at argv[0] */
  117. #ifdef CONFIG_64BIT
  118. char *fixed_argv[32];
  119. for (i = 0; i < argc; i++)
  120. fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
  121. argv = fixed_argv;
  122. #endif
  123. /* ignore all built-in args if any f/w args given */
  124. if (argc > 1)
  125. *arcs_cmdline = '\0';
  126. for (i = 1; i < argc; i++) {
  127. if (i != 1)
  128. strcat(arcs_cmdline, " ");
  129. strcat(arcs_cmdline, argv[i]);
  130. }
  131. }
  132. void __init prom_init(void)
  133. {
  134. #ifdef CONFIG_CPU_TX39XX
  135. txx9_board_vec = &jmr3927_vec;
  136. #endif
  137. #ifdef CONFIG_CPU_TX49XX
  138. switch (TX4938_REV_PCODE()) {
  139. #ifdef CONFIG_TOSHIBA_RBTX4927
  140. case 0x4927:
  141. txx9_board_vec = &rbtx4927_vec;
  142. break;
  143. case 0x4937:
  144. txx9_board_vec = &rbtx4937_vec;
  145. break;
  146. #endif
  147. #ifdef CONFIG_TOSHIBA_RBTX4938
  148. case 0x4938:
  149. txx9_board_vec = &rbtx4938_vec;
  150. break;
  151. #endif
  152. }
  153. #endif
  154. strcpy(txx9_system_type, txx9_board_vec->system);
  155. txx9_board_vec->prom_init();
  156. }
  157. void __init prom_free_prom_memory(void)
  158. {
  159. }
  160. const char *get_system_type(void)
  161. {
  162. return txx9_system_type;
  163. }
  164. char * __init prom_getcmdline(void)
  165. {
  166. return &(arcs_cmdline[0]);
  167. }
  168. static void __noreturn txx9_machine_halt(void)
  169. {
  170. local_irq_disable();
  171. clear_c0_status(ST0_IM);
  172. while (1) {
  173. if (cpu_wait) {
  174. (*cpu_wait)();
  175. if (cpu_has_counter) {
  176. /*
  177. * Clear counter interrupt while it
  178. * breaks WAIT instruction even if
  179. * masked.
  180. */
  181. write_c0_compare(0);
  182. }
  183. }
  184. }
  185. }
  186. /* Watchdog support */
  187. void __init txx9_wdt_init(unsigned long base)
  188. {
  189. struct resource res = {
  190. .start = base,
  191. .end = base + 0x100 - 1,
  192. .flags = IORESOURCE_MEM,
  193. };
  194. platform_device_register_simple("txx9wdt", -1, &res, 1);
  195. }
  196. /* SPI support */
  197. void __init txx9_spi_init(int busid, unsigned long base, int irq)
  198. {
  199. struct resource res[] = {
  200. {
  201. .start = base,
  202. .end = base + 0x20 - 1,
  203. .flags = IORESOURCE_MEM,
  204. }, {
  205. .start = irq,
  206. .flags = IORESOURCE_IRQ,
  207. },
  208. };
  209. platform_device_register_simple("spi_txx9", busid,
  210. res, ARRAY_SIZE(res));
  211. }
  212. void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
  213. {
  214. struct platform_device *pdev =
  215. platform_device_alloc("tc35815-mac", id);
  216. if (!pdev ||
  217. platform_device_add_data(pdev, ethaddr, 6) ||
  218. platform_device_add(pdev))
  219. platform_device_put(pdev);
  220. }
  221. void __init txx9_sio_init(unsigned long baseaddr, int irq,
  222. unsigned int line, unsigned int sclk, int nocts)
  223. {
  224. #ifdef CONFIG_SERIAL_TXX9
  225. struct uart_port req;
  226. memset(&req, 0, sizeof(req));
  227. req.line = line;
  228. req.iotype = UPIO_MEM;
  229. req.membase = ioremap(baseaddr, 0x24);
  230. req.mapbase = baseaddr;
  231. req.irq = irq;
  232. if (!nocts)
  233. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  234. if (sclk) {
  235. req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
  236. req.uartclk = sclk;
  237. } else
  238. req.uartclk = TXX9_IMCLK;
  239. early_serial_txx9_setup(&req);
  240. #endif /* CONFIG_SERIAL_TXX9 */
  241. }
  242. #ifdef CONFIG_EARLY_PRINTK
  243. static void __init null_prom_putchar(char c)
  244. {
  245. }
  246. void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
  247. void __init prom_putchar(char c)
  248. {
  249. txx9_prom_putchar(c);
  250. }
  251. static void __iomem *early_txx9_sio_port;
  252. static void __init early_txx9_sio_putchar(char c)
  253. {
  254. #define TXX9_SICISR 0x0c
  255. #define TXX9_SITFIFO 0x1c
  256. #define TXX9_SICISR_TXALS 0x00000002
  257. while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
  258. TXX9_SICISR_TXALS))
  259. ;
  260. __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
  261. }
  262. void __init txx9_sio_putchar_init(unsigned long baseaddr)
  263. {
  264. early_txx9_sio_port = ioremap(baseaddr, 0x24);
  265. txx9_prom_putchar = early_txx9_sio_putchar;
  266. }
  267. #endif /* CONFIG_EARLY_PRINTK */
  268. /* wrappers */
  269. void __init plat_mem_setup(void)
  270. {
  271. ioport_resource.start = 0;
  272. ioport_resource.end = ~0UL; /* no limit */
  273. iomem_resource.start = 0;
  274. iomem_resource.end = ~0UL; /* no limit */
  275. /* fallback restart/halt routines */
  276. _machine_restart = (void (*)(char *))txx9_machine_halt;
  277. _machine_halt = txx9_machine_halt;
  278. pm_power_off = txx9_machine_halt;
  279. #ifdef CONFIG_PCI
  280. pcibios_plat_setup = txx9_pcibios_setup;
  281. #endif
  282. txx9_board_vec->mem_setup();
  283. }
  284. void __init arch_init_irq(void)
  285. {
  286. txx9_board_vec->irq_setup();
  287. }
  288. void __init plat_time_init(void)
  289. {
  290. #ifdef CONFIG_CPU_TX49XX
  291. mips_hpt_frequency = txx9_cpu_clock / 2;
  292. #endif
  293. txx9_board_vec->time_init();
  294. }
  295. static int __init _txx9_arch_init(void)
  296. {
  297. if (txx9_board_vec->arch_init)
  298. txx9_board_vec->arch_init();
  299. return 0;
  300. }
  301. arch_initcall(_txx9_arch_init);
  302. static int __init _txx9_device_init(void)
  303. {
  304. if (txx9_board_vec->device_init)
  305. txx9_board_vec->device_init();
  306. return 0;
  307. }
  308. device_initcall(_txx9_device_init);
  309. int (*txx9_irq_dispatch)(int pending);
  310. asmlinkage void plat_irq_dispatch(void)
  311. {
  312. int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  313. int irq = txx9_irq_dispatch(pending);
  314. if (likely(irq >= 0))
  315. do_IRQ(irq);
  316. else
  317. spurious_interrupt();
  318. }
  319. /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
  320. #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
  321. static unsigned long __swizzle_addr_none(unsigned long port)
  322. {
  323. return port;
  324. }
  325. unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
  326. EXPORT_SYMBOL(__swizzle_addr_b);
  327. #endif