setup.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. static void __init prom_init_cmdline(void)
  113. {
  114. int argc = (int)fw_arg0;
  115. int *argv32 = (int *)fw_arg1;
  116. int i; /* Always ignore the "-c" at argv[0] */
  117. char builtin[CL_SIZE];
  118. /* ignore all built-in args if any f/w args given */
  119. /*
  120. * But if built-in strings was started with '+', append them
  121. * to command line args. If built-in was started with '-',
  122. * ignore all f/w args.
  123. */
  124. builtin[0] = '\0';
  125. if (arcs_cmdline[0] == '+')
  126. strcpy(builtin, arcs_cmdline + 1);
  127. else if (arcs_cmdline[0] == '-') {
  128. strcpy(builtin, arcs_cmdline + 1);
  129. argc = 0;
  130. } else if (argc <= 1)
  131. strcpy(builtin, arcs_cmdline);
  132. arcs_cmdline[0] = '\0';
  133. for (i = 1; i < argc; i++) {
  134. char *str = (char *)(long)argv32[i];
  135. if (i != 1)
  136. strcat(arcs_cmdline, " ");
  137. if (strchr(str, ' ')) {
  138. strcat(arcs_cmdline, "\"");
  139. strcat(arcs_cmdline, str);
  140. strcat(arcs_cmdline, "\"");
  141. } else
  142. strcat(arcs_cmdline, str);
  143. }
  144. /* append saved builtin args */
  145. if (builtin[0]) {
  146. if (arcs_cmdline[0])
  147. strcat(arcs_cmdline, " ");
  148. strcat(arcs_cmdline, builtin);
  149. }
  150. }
  151. void __init prom_init(void)
  152. {
  153. prom_init_cmdline();
  154. #ifdef CONFIG_CPU_TX39XX
  155. txx9_board_vec = &jmr3927_vec;
  156. #endif
  157. #ifdef CONFIG_CPU_TX49XX
  158. switch (TX4938_REV_PCODE()) {
  159. #ifdef CONFIG_TOSHIBA_RBTX4927
  160. case 0x4927:
  161. txx9_board_vec = &rbtx4927_vec;
  162. break;
  163. case 0x4937:
  164. txx9_board_vec = &rbtx4937_vec;
  165. break;
  166. #endif
  167. #ifdef CONFIG_TOSHIBA_RBTX4938
  168. case 0x4938:
  169. txx9_board_vec = &rbtx4938_vec;
  170. break;
  171. #endif
  172. }
  173. #endif
  174. strcpy(txx9_system_type, txx9_board_vec->system);
  175. txx9_board_vec->prom_init();
  176. }
  177. void __init prom_free_prom_memory(void)
  178. {
  179. }
  180. const char *get_system_type(void)
  181. {
  182. return txx9_system_type;
  183. }
  184. char * __init prom_getcmdline(void)
  185. {
  186. return &(arcs_cmdline[0]);
  187. }
  188. const char *__init prom_getenv(const char *name)
  189. {
  190. const s32 *str = (const s32 *)fw_arg2;
  191. if (!str)
  192. return NULL;
  193. /* YAMON style ("name", "value" pairs) */
  194. while (str[0] && str[1]) {
  195. if (!strcmp((const char *)(unsigned long)str[0], name))
  196. return (const char *)(unsigned long)str[1];
  197. str += 2;
  198. }
  199. return NULL;
  200. }
  201. static void __noreturn txx9_machine_halt(void)
  202. {
  203. local_irq_disable();
  204. clear_c0_status(ST0_IM);
  205. while (1) {
  206. if (cpu_wait) {
  207. (*cpu_wait)();
  208. if (cpu_has_counter) {
  209. /*
  210. * Clear counter interrupt while it
  211. * breaks WAIT instruction even if
  212. * masked.
  213. */
  214. write_c0_compare(0);
  215. }
  216. }
  217. }
  218. }
  219. /* Watchdog support */
  220. void __init txx9_wdt_init(unsigned long base)
  221. {
  222. struct resource res = {
  223. .start = base,
  224. .end = base + 0x100 - 1,
  225. .flags = IORESOURCE_MEM,
  226. };
  227. platform_device_register_simple("txx9wdt", -1, &res, 1);
  228. }
  229. /* SPI support */
  230. void __init txx9_spi_init(int busid, unsigned long base, int irq)
  231. {
  232. struct resource res[] = {
  233. {
  234. .start = base,
  235. .end = base + 0x20 - 1,
  236. .flags = IORESOURCE_MEM,
  237. }, {
  238. .start = irq,
  239. .flags = IORESOURCE_IRQ,
  240. },
  241. };
  242. platform_device_register_simple("spi_txx9", busid,
  243. res, ARRAY_SIZE(res));
  244. }
  245. void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
  246. {
  247. struct platform_device *pdev =
  248. platform_device_alloc("tc35815-mac", id);
  249. if (!pdev ||
  250. platform_device_add_data(pdev, ethaddr, 6) ||
  251. platform_device_add(pdev))
  252. platform_device_put(pdev);
  253. }
  254. void __init txx9_sio_init(unsigned long baseaddr, int irq,
  255. unsigned int line, unsigned int sclk, int nocts)
  256. {
  257. #ifdef CONFIG_SERIAL_TXX9
  258. struct uart_port req;
  259. memset(&req, 0, sizeof(req));
  260. req.line = line;
  261. req.iotype = UPIO_MEM;
  262. req.membase = ioremap(baseaddr, 0x24);
  263. req.mapbase = baseaddr;
  264. req.irq = irq;
  265. if (!nocts)
  266. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  267. if (sclk) {
  268. req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
  269. req.uartclk = sclk;
  270. } else
  271. req.uartclk = TXX9_IMCLK;
  272. early_serial_txx9_setup(&req);
  273. #endif /* CONFIG_SERIAL_TXX9 */
  274. }
  275. #ifdef CONFIG_EARLY_PRINTK
  276. static void __init null_prom_putchar(char c)
  277. {
  278. }
  279. void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
  280. void __init prom_putchar(char c)
  281. {
  282. txx9_prom_putchar(c);
  283. }
  284. static void __iomem *early_txx9_sio_port;
  285. static void __init early_txx9_sio_putchar(char c)
  286. {
  287. #define TXX9_SICISR 0x0c
  288. #define TXX9_SITFIFO 0x1c
  289. #define TXX9_SICISR_TXALS 0x00000002
  290. while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
  291. TXX9_SICISR_TXALS))
  292. ;
  293. __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
  294. }
  295. void __init txx9_sio_putchar_init(unsigned long baseaddr)
  296. {
  297. early_txx9_sio_port = ioremap(baseaddr, 0x24);
  298. txx9_prom_putchar = early_txx9_sio_putchar;
  299. }
  300. #endif /* CONFIG_EARLY_PRINTK */
  301. /* wrappers */
  302. void __init plat_mem_setup(void)
  303. {
  304. ioport_resource.start = 0;
  305. ioport_resource.end = ~0UL; /* no limit */
  306. iomem_resource.start = 0;
  307. iomem_resource.end = ~0UL; /* no limit */
  308. /* fallback restart/halt routines */
  309. _machine_restart = (void (*)(char *))txx9_machine_halt;
  310. _machine_halt = txx9_machine_halt;
  311. pm_power_off = txx9_machine_halt;
  312. #ifdef CONFIG_PCI
  313. pcibios_plat_setup = txx9_pcibios_setup;
  314. #endif
  315. txx9_board_vec->mem_setup();
  316. }
  317. void __init arch_init_irq(void)
  318. {
  319. txx9_board_vec->irq_setup();
  320. }
  321. void __init plat_time_init(void)
  322. {
  323. #ifdef CONFIG_CPU_TX49XX
  324. mips_hpt_frequency = txx9_cpu_clock / 2;
  325. #endif
  326. txx9_board_vec->time_init();
  327. }
  328. static int __init _txx9_arch_init(void)
  329. {
  330. if (txx9_board_vec->arch_init)
  331. txx9_board_vec->arch_init();
  332. return 0;
  333. }
  334. arch_initcall(_txx9_arch_init);
  335. static int __init _txx9_device_init(void)
  336. {
  337. if (txx9_board_vec->device_init)
  338. txx9_board_vec->device_init();
  339. return 0;
  340. }
  341. device_initcall(_txx9_device_init);
  342. int (*txx9_irq_dispatch)(int pending);
  343. asmlinkage void plat_irq_dispatch(void)
  344. {
  345. int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  346. int irq = txx9_irq_dispatch(pending);
  347. if (likely(irq >= 0))
  348. do_IRQ(irq);
  349. else
  350. spurious_interrupt();
  351. }
  352. /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
  353. #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
  354. static unsigned long __swizzle_addr_none(unsigned long port)
  355. {
  356. return port;
  357. }
  358. unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
  359. EXPORT_SYMBOL(__swizzle_addr_b);
  360. #endif