setup.c 9.7 KB

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