setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * Toshiba rbtx4927 specific setup
  3. *
  4. * Author: MontaVista Software, Inc.
  5. * source@mvista.com
  6. *
  7. * Copyright 2001-2002 MontaVista Software Inc.
  8. *
  9. * Copyright (C) 1996, 97, 2001, 04 Ralf Baechle (ralf@linux-mips.org)
  10. * Copyright (C) 2000 RidgeRun, Inc.
  11. * Author: RidgeRun, Inc.
  12. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  13. *
  14. * Copyright 2001 MontaVista Software Inc.
  15. * Author: jsun@mvista.com or jsun@junsun.net
  16. *
  17. * Copyright 2002 MontaVista Software Inc.
  18. * Author: Michael Pruznick, michael_pruznick@mvista.com
  19. *
  20. * Copyright (C) 2000-2001 Toshiba Corporation
  21. *
  22. * Copyright (C) 2004 MontaVista Software Inc.
  23. * Author: Manish Lachwani, mlachwani@mvista.com
  24. *
  25. * This program is free software; you can redistribute it and/or modify it
  26. * under the terms of the GNU General Public License as published by the
  27. * Free Software Foundation; either version 2 of the License, or (at your
  28. * option) any later version.
  29. *
  30. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  31. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  32. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  33. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  34. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  35. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  36. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  37. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  38. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * You should have received a copy of the GNU General Public License along
  42. * with this program; if not, write to the Free Software Foundation, Inc.,
  43. * 675 Mass Ave, Cambridge, MA 02139, USA.
  44. */
  45. #include <linux/init.h>
  46. #include <linux/kernel.h>
  47. #include <linux/types.h>
  48. #include <linux/ioport.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/pm.h>
  51. #include <linux/platform_device.h>
  52. #include <linux/delay.h>
  53. #include <asm/io.h>
  54. #include <asm/processor.h>
  55. #include <asm/reboot.h>
  56. #include <asm/txx9/generic.h>
  57. #include <asm/txx9/pci.h>
  58. #include <asm/txx9/rbtx4927.h>
  59. #include <asm/txx9/tx4938.h> /* for TX4937 */
  60. #ifdef CONFIG_PCI
  61. static void __init tx4927_pci_setup(void)
  62. {
  63. int extarb = !(__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB);
  64. struct pci_controller *c = &txx9_primary_pcic;
  65. register_pci_controller(c);
  66. if (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66)
  67. txx9_pci_option =
  68. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  69. TXX9_PCI_OPT_CLK_66; /* already configured */
  70. /* Reset PCI Bus */
  71. writeb(1, rbtx4927_pcireset_addr);
  72. /* Reset PCIC */
  73. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  74. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  75. TXX9_PCI_OPT_CLK_66)
  76. tx4927_pciclk66_setup();
  77. mdelay(10);
  78. /* clear PCIC reset */
  79. txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  80. writeb(0, rbtx4927_pcireset_addr);
  81. iob();
  82. tx4927_report_pciclk();
  83. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  84. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  85. TXX9_PCI_OPT_CLK_AUTO &&
  86. txx9_pci66_check(c, 0, 0)) {
  87. /* Reset PCI Bus */
  88. writeb(1, rbtx4927_pcireset_addr);
  89. /* Reset PCIC */
  90. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  91. tx4927_pciclk66_setup();
  92. mdelay(10);
  93. /* clear PCIC reset */
  94. txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  95. writeb(0, rbtx4927_pcireset_addr);
  96. iob();
  97. /* Reinitialize PCIC */
  98. tx4927_report_pciclk();
  99. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  100. }
  101. }
  102. static void __init tx4937_pci_setup(void)
  103. {
  104. int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
  105. struct pci_controller *c = &txx9_primary_pcic;
  106. register_pci_controller(c);
  107. if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
  108. txx9_pci_option =
  109. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  110. TXX9_PCI_OPT_CLK_66; /* already configured */
  111. /* Reset PCI Bus */
  112. writeb(1, rbtx4927_pcireset_addr);
  113. /* Reset PCIC */
  114. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  115. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  116. TXX9_PCI_OPT_CLK_66)
  117. tx4938_pciclk66_setup();
  118. mdelay(10);
  119. /* clear PCIC reset */
  120. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  121. writeb(0, rbtx4927_pcireset_addr);
  122. iob();
  123. tx4938_report_pciclk();
  124. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  125. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  126. TXX9_PCI_OPT_CLK_AUTO &&
  127. txx9_pci66_check(c, 0, 0)) {
  128. /* Reset PCI Bus */
  129. writeb(1, rbtx4927_pcireset_addr);
  130. /* Reset PCIC */
  131. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  132. tx4938_pciclk66_setup();
  133. mdelay(10);
  134. /* clear PCIC reset */
  135. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  136. writeb(0, rbtx4927_pcireset_addr);
  137. iob();
  138. /* Reinitialize PCIC */
  139. tx4938_report_pciclk();
  140. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  141. }
  142. }
  143. static void __init rbtx4927_arch_init(void)
  144. {
  145. tx4927_pci_setup();
  146. }
  147. static void __init rbtx4937_arch_init(void)
  148. {
  149. tx4937_pci_setup();
  150. }
  151. #else
  152. #define rbtx4927_arch_init NULL
  153. #define rbtx4937_arch_init NULL
  154. #endif /* CONFIG_PCI */
  155. static void __noreturn wait_forever(void)
  156. {
  157. while (1)
  158. if (cpu_wait)
  159. (*cpu_wait)();
  160. }
  161. static void toshiba_rbtx4927_restart(char *command)
  162. {
  163. printk(KERN_NOTICE "System Rebooting...\n");
  164. /* enable the s/w reset register */
  165. writeb(1, rbtx4927_softresetlock_addr);
  166. /* wait for enable to be seen */
  167. while (!(readb(rbtx4927_softresetlock_addr) & 1))
  168. ;
  169. /* do a s/w reset */
  170. writeb(1, rbtx4927_softreset_addr);
  171. /* do something passive while waiting for reset */
  172. local_irq_disable();
  173. wait_forever();
  174. /* no return */
  175. }
  176. static void toshiba_rbtx4927_halt(void)
  177. {
  178. printk(KERN_NOTICE "System Halted\n");
  179. local_irq_disable();
  180. wait_forever();
  181. /* no return */
  182. }
  183. static void toshiba_rbtx4927_power_off(void)
  184. {
  185. toshiba_rbtx4927_halt();
  186. /* no return */
  187. }
  188. static void __init rbtx4927_clock_init(void);
  189. static void __init rbtx4937_clock_init(void);
  190. static void __init rbtx4927_mem_setup(void)
  191. {
  192. u32 cp0_config;
  193. char *argptr;
  194. /* f/w leaves this on at startup */
  195. clear_c0_status(ST0_ERL);
  196. /* enable caches -- HCP5 does this, pmon does not */
  197. cp0_config = read_c0_config();
  198. cp0_config = cp0_config & ~(TX49_CONF_IC | TX49_CONF_DC);
  199. write_c0_config(cp0_config);
  200. if (TX4927_REV_PCODE() == 0x4927) {
  201. rbtx4927_clock_init();
  202. tx4927_setup();
  203. } else {
  204. rbtx4937_clock_init();
  205. tx4938_setup();
  206. }
  207. _machine_restart = toshiba_rbtx4927_restart;
  208. _machine_halt = toshiba_rbtx4927_halt;
  209. pm_power_off = toshiba_rbtx4927_power_off;
  210. #ifdef CONFIG_PCI
  211. txx9_alloc_pci_controller(&txx9_primary_pcic,
  212. RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE,
  213. RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE);
  214. #else
  215. set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET);
  216. #endif
  217. tx4927_setup_serial();
  218. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  219. argptr = prom_getcmdline();
  220. if (strstr(argptr, "console=") == NULL) {
  221. strcat(argptr, " console=ttyS0,38400");
  222. }
  223. #endif
  224. #ifdef CONFIG_ROOT_NFS
  225. argptr = prom_getcmdline();
  226. if (strstr(argptr, "root=") == NULL) {
  227. strcat(argptr, " root=/dev/nfs rw");
  228. }
  229. #endif
  230. #ifdef CONFIG_IP_PNP
  231. argptr = prom_getcmdline();
  232. if (strstr(argptr, "ip=") == NULL) {
  233. strcat(argptr, " ip=any");
  234. }
  235. #endif
  236. }
  237. static void __init rbtx4927_clock_init(void)
  238. {
  239. /*
  240. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  241. *
  242. * For TX4927:
  243. * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1).
  244. * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5)
  245. * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3)
  246. * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5)
  247. * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6)
  248. * i.e. S9[3]: ON (83MHz), OFF (100MHz)
  249. */
  250. switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) &
  251. TX4927_CCFG_PCIDIVMODE_MASK) {
  252. case TX4927_CCFG_PCIDIVMODE_2_5:
  253. case TX4927_CCFG_PCIDIVMODE_5:
  254. txx9_cpu_clock = 166666666; /* 166MHz */
  255. break;
  256. default:
  257. txx9_cpu_clock = 200000000; /* 200MHz */
  258. }
  259. }
  260. static void __init rbtx4937_clock_init(void)
  261. {
  262. /*
  263. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  264. *
  265. * For TX4937:
  266. * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1)
  267. * PCIDIVMODE[10] is 0.
  268. * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8)
  269. * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4)
  270. * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9)
  271. * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5)
  272. * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10)
  273. * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5)
  274. */
  275. switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) &
  276. TX4938_CCFG_PCIDIVMODE_MASK) {
  277. case TX4938_CCFG_PCIDIVMODE_8:
  278. case TX4938_CCFG_PCIDIVMODE_4:
  279. txx9_cpu_clock = 266666666; /* 266MHz */
  280. break;
  281. case TX4938_CCFG_PCIDIVMODE_9:
  282. case TX4938_CCFG_PCIDIVMODE_4_5:
  283. txx9_cpu_clock = 300000000; /* 300MHz */
  284. break;
  285. default:
  286. txx9_cpu_clock = 333333333; /* 333MHz */
  287. }
  288. }
  289. static void __init rbtx4927_time_init(void)
  290. {
  291. tx4927_time_init(0);
  292. }
  293. static int __init toshiba_rbtx4927_rtc_init(void)
  294. {
  295. struct resource res = {
  296. .start = RBTX4927_BRAMRTC_BASE - IO_BASE,
  297. .end = RBTX4927_BRAMRTC_BASE - IO_BASE + 0x800 - 1,
  298. .flags = IORESOURCE_MEM,
  299. };
  300. struct platform_device *dev =
  301. platform_device_register_simple("rtc-ds1742", -1, &res, 1);
  302. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  303. }
  304. static int __init rbtx4927_ne_init(void)
  305. {
  306. struct resource res[] = {
  307. {
  308. .start = RBTX4927_RTL_8019_BASE,
  309. .end = RBTX4927_RTL_8019_BASE + 0x20 - 1,
  310. .flags = IORESOURCE_IO,
  311. }, {
  312. .start = RBTX4927_RTL_8019_IRQ,
  313. .flags = IORESOURCE_IRQ,
  314. }
  315. };
  316. struct platform_device *dev =
  317. platform_device_register_simple("ne", -1,
  318. res, ARRAY_SIZE(res));
  319. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  320. }
  321. /* Watchdog support */
  322. static int __init txx9_wdt_init(unsigned long base)
  323. {
  324. struct resource res = {
  325. .start = base,
  326. .end = base + 0x100 - 1,
  327. .flags = IORESOURCE_MEM,
  328. };
  329. struct platform_device *dev =
  330. platform_device_register_simple("txx9wdt", -1, &res, 1);
  331. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  332. }
  333. static int __init rbtx4927_wdt_init(void)
  334. {
  335. return txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
  336. }
  337. static void __init rbtx4927_device_init(void)
  338. {
  339. toshiba_rbtx4927_rtc_init();
  340. rbtx4927_ne_init();
  341. rbtx4927_wdt_init();
  342. }
  343. struct txx9_board_vec rbtx4927_vec __initdata = {
  344. .system = "Toshiba RBTX4927",
  345. .prom_init = rbtx4927_prom_init,
  346. .mem_setup = rbtx4927_mem_setup,
  347. .irq_setup = rbtx4927_irq_setup,
  348. .time_init = rbtx4927_time_init,
  349. .device_init = rbtx4927_device_init,
  350. .arch_init = rbtx4927_arch_init,
  351. #ifdef CONFIG_PCI
  352. .pci_map_irq = rbtx4927_pci_map_irq,
  353. #endif
  354. };
  355. struct txx9_board_vec rbtx4937_vec __initdata = {
  356. .system = "Toshiba RBTX4937",
  357. .prom_init = rbtx4927_prom_init,
  358. .mem_setup = rbtx4927_mem_setup,
  359. .irq_setup = rbtx4927_irq_setup,
  360. .time_init = rbtx4927_time_init,
  361. .device_init = rbtx4927_device_init,
  362. .arch_init = rbtx4937_arch_init,
  363. #ifdef CONFIG_PCI
  364. .pci_map_irq = rbtx4927_pci_map_irq,
  365. #endif
  366. };