setup.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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/platform_device.h>
  50. #include <linux/delay.h>
  51. #include <asm/io.h>
  52. #include <asm/reboot.h>
  53. #include <asm/txx9/generic.h>
  54. #include <asm/txx9/pci.h>
  55. #include <asm/txx9/rbtx4927.h>
  56. #include <asm/txx9/tx4938.h> /* for TX4937 */
  57. #ifdef CONFIG_PCI
  58. static void __init tx4927_pci_setup(void)
  59. {
  60. int extarb = !(__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB);
  61. struct pci_controller *c = &txx9_primary_pcic;
  62. register_pci_controller(c);
  63. if (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66)
  64. txx9_pci_option =
  65. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  66. TXX9_PCI_OPT_CLK_66; /* already configured */
  67. /* Reset PCI Bus */
  68. writeb(1, rbtx4927_pcireset_addr);
  69. /* Reset PCIC */
  70. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  71. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  72. TXX9_PCI_OPT_CLK_66)
  73. tx4927_pciclk66_setup();
  74. mdelay(10);
  75. /* clear PCIC reset */
  76. txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  77. writeb(0, rbtx4927_pcireset_addr);
  78. iob();
  79. tx4927_report_pciclk();
  80. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  81. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  82. TXX9_PCI_OPT_CLK_AUTO &&
  83. txx9_pci66_check(c, 0, 0)) {
  84. /* Reset PCI Bus */
  85. writeb(1, rbtx4927_pcireset_addr);
  86. /* Reset PCIC */
  87. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  88. tx4927_pciclk66_setup();
  89. mdelay(10);
  90. /* clear PCIC reset */
  91. txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  92. writeb(0, rbtx4927_pcireset_addr);
  93. iob();
  94. /* Reinitialize PCIC */
  95. tx4927_report_pciclk();
  96. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  97. }
  98. tx4927_setup_pcierr_irq();
  99. }
  100. static void __init tx4937_pci_setup(void)
  101. {
  102. int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
  103. struct pci_controller *c = &txx9_primary_pcic;
  104. register_pci_controller(c);
  105. if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
  106. txx9_pci_option =
  107. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  108. TXX9_PCI_OPT_CLK_66; /* already configured */
  109. /* Reset PCI Bus */
  110. writeb(1, rbtx4927_pcireset_addr);
  111. /* Reset PCIC */
  112. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  113. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  114. TXX9_PCI_OPT_CLK_66)
  115. tx4938_pciclk66_setup();
  116. mdelay(10);
  117. /* clear PCIC reset */
  118. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  119. writeb(0, rbtx4927_pcireset_addr);
  120. iob();
  121. tx4938_report_pciclk();
  122. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  123. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  124. TXX9_PCI_OPT_CLK_AUTO &&
  125. txx9_pci66_check(c, 0, 0)) {
  126. /* Reset PCI Bus */
  127. writeb(1, rbtx4927_pcireset_addr);
  128. /* Reset PCIC */
  129. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  130. tx4938_pciclk66_setup();
  131. mdelay(10);
  132. /* clear PCIC reset */
  133. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  134. writeb(0, rbtx4927_pcireset_addr);
  135. iob();
  136. /* Reinitialize PCIC */
  137. tx4938_report_pciclk();
  138. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  139. }
  140. tx4938_setup_pcierr_irq();
  141. }
  142. static void __init rbtx4927_arch_init(void)
  143. {
  144. tx4927_pci_setup();
  145. }
  146. static void __init rbtx4937_arch_init(void)
  147. {
  148. tx4937_pci_setup();
  149. }
  150. #else
  151. #define rbtx4927_arch_init NULL
  152. #define rbtx4937_arch_init NULL
  153. #endif /* CONFIG_PCI */
  154. static void toshiba_rbtx4927_restart(char *command)
  155. {
  156. /* enable the s/w reset register */
  157. writeb(1, rbtx4927_softresetlock_addr);
  158. /* wait for enable to be seen */
  159. while (!(readb(rbtx4927_softresetlock_addr) & 1))
  160. ;
  161. /* do a s/w reset */
  162. writeb(1, rbtx4927_softreset_addr);
  163. /* fallback */
  164. (*_machine_halt)();
  165. }
  166. static void __init rbtx4927_clock_init(void);
  167. static void __init rbtx4937_clock_init(void);
  168. static void __init rbtx4927_mem_setup(void)
  169. {
  170. u32 cp0_config;
  171. char *argptr;
  172. /* enable caches -- HCP5 does this, pmon does not */
  173. cp0_config = read_c0_config();
  174. cp0_config = cp0_config & ~(TX49_CONF_IC | TX49_CONF_DC);
  175. write_c0_config(cp0_config);
  176. if (TX4927_REV_PCODE() == 0x4927) {
  177. rbtx4927_clock_init();
  178. tx4927_setup();
  179. } else {
  180. rbtx4937_clock_init();
  181. tx4938_setup();
  182. }
  183. _machine_restart = toshiba_rbtx4927_restart;
  184. #ifdef CONFIG_PCI
  185. txx9_alloc_pci_controller(&txx9_primary_pcic,
  186. RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE,
  187. RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE);
  188. txx9_board_pcibios_setup = tx4927_pcibios_setup;
  189. #else
  190. set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET);
  191. #endif
  192. tx4927_sio_init(0, 0);
  193. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  194. argptr = prom_getcmdline();
  195. if (!strstr(argptr, "console="))
  196. strcat(argptr, " console=ttyS0,38400");
  197. #endif
  198. }
  199. static void __init rbtx4927_clock_init(void)
  200. {
  201. /*
  202. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  203. *
  204. * For TX4927:
  205. * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1).
  206. * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5)
  207. * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3)
  208. * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5)
  209. * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6)
  210. * i.e. S9[3]: ON (83MHz), OFF (100MHz)
  211. */
  212. switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) &
  213. TX4927_CCFG_PCIDIVMODE_MASK) {
  214. case TX4927_CCFG_PCIDIVMODE_2_5:
  215. case TX4927_CCFG_PCIDIVMODE_5:
  216. txx9_cpu_clock = 166666666; /* 166MHz */
  217. break;
  218. default:
  219. txx9_cpu_clock = 200000000; /* 200MHz */
  220. }
  221. }
  222. static void __init rbtx4937_clock_init(void)
  223. {
  224. /*
  225. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  226. *
  227. * For TX4937:
  228. * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1)
  229. * PCIDIVMODE[10] is 0.
  230. * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8)
  231. * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4)
  232. * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9)
  233. * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5)
  234. * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10)
  235. * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5)
  236. */
  237. switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) &
  238. TX4938_CCFG_PCIDIVMODE_MASK) {
  239. case TX4938_CCFG_PCIDIVMODE_8:
  240. case TX4938_CCFG_PCIDIVMODE_4:
  241. txx9_cpu_clock = 266666666; /* 266MHz */
  242. break;
  243. case TX4938_CCFG_PCIDIVMODE_9:
  244. case TX4938_CCFG_PCIDIVMODE_4_5:
  245. txx9_cpu_clock = 300000000; /* 300MHz */
  246. break;
  247. default:
  248. txx9_cpu_clock = 333333333; /* 333MHz */
  249. }
  250. }
  251. static void __init rbtx4927_time_init(void)
  252. {
  253. tx4927_time_init(0);
  254. }
  255. static void __init toshiba_rbtx4927_rtc_init(void)
  256. {
  257. struct resource res = {
  258. .start = RBTX4927_BRAMRTC_BASE - IO_BASE,
  259. .end = RBTX4927_BRAMRTC_BASE - IO_BASE + 0x800 - 1,
  260. .flags = IORESOURCE_MEM,
  261. };
  262. platform_device_register_simple("rtc-ds1742", -1, &res, 1);
  263. }
  264. static void __init rbtx4927_ne_init(void)
  265. {
  266. struct resource res[] = {
  267. {
  268. .start = RBTX4927_RTL_8019_BASE,
  269. .end = RBTX4927_RTL_8019_BASE + 0x20 - 1,
  270. .flags = IORESOURCE_IO,
  271. }, {
  272. .start = RBTX4927_RTL_8019_IRQ,
  273. .flags = IORESOURCE_IRQ,
  274. }
  275. };
  276. platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res));
  277. }
  278. static void __init rbtx4927_device_init(void)
  279. {
  280. toshiba_rbtx4927_rtc_init();
  281. rbtx4927_ne_init();
  282. tx4927_wdt_init();
  283. }
  284. struct txx9_board_vec rbtx4927_vec __initdata = {
  285. .system = "Toshiba RBTX4927",
  286. .prom_init = rbtx4927_prom_init,
  287. .mem_setup = rbtx4927_mem_setup,
  288. .irq_setup = rbtx4927_irq_setup,
  289. .time_init = rbtx4927_time_init,
  290. .device_init = rbtx4927_device_init,
  291. .arch_init = rbtx4927_arch_init,
  292. #ifdef CONFIG_PCI
  293. .pci_map_irq = rbtx4927_pci_map_irq,
  294. #endif
  295. };
  296. struct txx9_board_vec rbtx4937_vec __initdata = {
  297. .system = "Toshiba RBTX4937",
  298. .prom_init = rbtx4927_prom_init,
  299. .mem_setup = rbtx4927_mem_setup,
  300. .irq_setup = rbtx4927_irq_setup,
  301. .time_init = rbtx4927_time_init,
  302. .device_init = rbtx4927_device_init,
  303. .arch_init = rbtx4937_arch_init,
  304. #ifdef CONFIG_PCI
  305. .pci_map_irq = rbtx4927_pci_map_irq,
  306. #endif
  307. };