setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 <linux/leds.h>
  53. #include <asm/io.h>
  54. #include <asm/reboot.h>
  55. #include <asm/txx9pio.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. tx4927_setup_pcierr_irq();
  102. }
  103. static void __init tx4937_pci_setup(void)
  104. {
  105. int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
  106. struct pci_controller *c = &txx9_primary_pcic;
  107. register_pci_controller(c);
  108. if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
  109. txx9_pci_option =
  110. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  111. TXX9_PCI_OPT_CLK_66; /* already configured */
  112. /* Reset PCI Bus */
  113. writeb(1, rbtx4927_pcireset_addr);
  114. /* Reset PCIC */
  115. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  116. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  117. TXX9_PCI_OPT_CLK_66)
  118. tx4938_pciclk66_setup();
  119. mdelay(10);
  120. /* clear PCIC reset */
  121. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  122. writeb(0, rbtx4927_pcireset_addr);
  123. iob();
  124. tx4938_report_pciclk();
  125. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  126. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  127. TXX9_PCI_OPT_CLK_AUTO &&
  128. txx9_pci66_check(c, 0, 0)) {
  129. /* Reset PCI Bus */
  130. writeb(1, rbtx4927_pcireset_addr);
  131. /* Reset PCIC */
  132. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  133. tx4938_pciclk66_setup();
  134. mdelay(10);
  135. /* clear PCIC reset */
  136. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  137. writeb(0, rbtx4927_pcireset_addr);
  138. iob();
  139. /* Reinitialize PCIC */
  140. tx4938_report_pciclk();
  141. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  142. }
  143. tx4938_setup_pcierr_irq();
  144. }
  145. #else
  146. static inline void tx4927_pci_setup(void) {}
  147. static inline void tx4937_pci_setup(void) {}
  148. #endif /* CONFIG_PCI */
  149. static void __init rbtx4927_gpio_init(void)
  150. {
  151. /* TX4927-SIO DTR on (PIO[15]) */
  152. gpio_request(15, "sio-dtr");
  153. gpio_direction_output(15, 1);
  154. tx4927_sio_init(0, 0);
  155. }
  156. static void __init rbtx4927_arch_init(void)
  157. {
  158. txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO);
  159. rbtx4927_gpio_init();
  160. tx4927_pci_setup();
  161. }
  162. static void __init rbtx4937_arch_init(void)
  163. {
  164. txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
  165. rbtx4927_gpio_init();
  166. tx4937_pci_setup();
  167. }
  168. static void toshiba_rbtx4927_restart(char *command)
  169. {
  170. /* enable the s/w reset register */
  171. writeb(1, rbtx4927_softresetlock_addr);
  172. /* wait for enable to be seen */
  173. while (!(readb(rbtx4927_softresetlock_addr) & 1))
  174. ;
  175. /* do a s/w reset */
  176. writeb(1, rbtx4927_softreset_addr);
  177. /* fallback */
  178. (*_machine_halt)();
  179. }
  180. static void __init rbtx4927_clock_init(void);
  181. static void __init rbtx4937_clock_init(void);
  182. static void __init rbtx4927_mem_setup(void)
  183. {
  184. if (TX4927_REV_PCODE() == 0x4927) {
  185. rbtx4927_clock_init();
  186. tx4927_setup();
  187. } else {
  188. rbtx4937_clock_init();
  189. tx4938_setup();
  190. }
  191. _machine_restart = toshiba_rbtx4927_restart;
  192. #ifdef CONFIG_PCI
  193. txx9_alloc_pci_controller(&txx9_primary_pcic,
  194. RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE,
  195. RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE);
  196. txx9_board_pcibios_setup = tx4927_pcibios_setup;
  197. #else
  198. set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET);
  199. #endif
  200. }
  201. static void __init rbtx4927_clock_init(void)
  202. {
  203. /*
  204. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  205. *
  206. * For TX4927:
  207. * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1).
  208. * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5)
  209. * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3)
  210. * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5)
  211. * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6)
  212. * i.e. S9[3]: ON (83MHz), OFF (100MHz)
  213. */
  214. switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) &
  215. TX4927_CCFG_PCIDIVMODE_MASK) {
  216. case TX4927_CCFG_PCIDIVMODE_2_5:
  217. case TX4927_CCFG_PCIDIVMODE_5:
  218. txx9_cpu_clock = 166666666; /* 166MHz */
  219. break;
  220. default:
  221. txx9_cpu_clock = 200000000; /* 200MHz */
  222. }
  223. }
  224. static void __init rbtx4937_clock_init(void)
  225. {
  226. /*
  227. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  228. *
  229. * For TX4937:
  230. * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1)
  231. * PCIDIVMODE[10] is 0.
  232. * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8)
  233. * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4)
  234. * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9)
  235. * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5)
  236. * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10)
  237. * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5)
  238. */
  239. switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) &
  240. TX4938_CCFG_PCIDIVMODE_MASK) {
  241. case TX4938_CCFG_PCIDIVMODE_8:
  242. case TX4938_CCFG_PCIDIVMODE_4:
  243. txx9_cpu_clock = 266666666; /* 266MHz */
  244. break;
  245. case TX4938_CCFG_PCIDIVMODE_9:
  246. case TX4938_CCFG_PCIDIVMODE_4_5:
  247. txx9_cpu_clock = 300000000; /* 300MHz */
  248. break;
  249. default:
  250. txx9_cpu_clock = 333333333; /* 333MHz */
  251. }
  252. }
  253. static void __init rbtx4927_time_init(void)
  254. {
  255. tx4927_time_init(0);
  256. }
  257. static void __init toshiba_rbtx4927_rtc_init(void)
  258. {
  259. struct resource res = {
  260. .start = RBTX4927_BRAMRTC_BASE - IO_BASE,
  261. .end = RBTX4927_BRAMRTC_BASE - IO_BASE + 0x800 - 1,
  262. .flags = IORESOURCE_MEM,
  263. };
  264. platform_device_register_simple("rtc-ds1742", -1, &res, 1);
  265. }
  266. static void __init rbtx4927_ne_init(void)
  267. {
  268. struct resource res[] = {
  269. {
  270. .start = RBTX4927_RTL_8019_BASE,
  271. .end = RBTX4927_RTL_8019_BASE + 0x20 - 1,
  272. .flags = IORESOURCE_IO,
  273. }, {
  274. .start = RBTX4927_RTL_8019_IRQ,
  275. .flags = IORESOURCE_IRQ,
  276. }
  277. };
  278. platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res));
  279. }
  280. static void __init rbtx4927_mtd_init(void)
  281. {
  282. int i;
  283. for (i = 0; i < 2; i++)
  284. tx4927_mtd_init(i);
  285. }
  286. static void __init rbtx4927_gpioled_init(void)
  287. {
  288. static struct gpio_led leds[] = {
  289. { .name = "gpioled:green:0", .gpio = 0, .active_low = 1, },
  290. { .name = "gpioled:green:1", .gpio = 1, .active_low = 1, },
  291. };
  292. static struct gpio_led_platform_data pdata = {
  293. .num_leds = ARRAY_SIZE(leds),
  294. .leds = leds,
  295. };
  296. struct platform_device *pdev = platform_device_alloc("leds-gpio", 0);
  297. if (!pdev)
  298. return;
  299. pdev->dev.platform_data = &pdata;
  300. if (platform_device_add(pdev))
  301. platform_device_put(pdev);
  302. }
  303. static void __init rbtx4927_device_init(void)
  304. {
  305. toshiba_rbtx4927_rtc_init();
  306. rbtx4927_ne_init();
  307. tx4927_wdt_init();
  308. rbtx4927_mtd_init();
  309. if (TX4927_REV_PCODE() == 0x4927) {
  310. tx4927_dmac_init(2);
  311. tx4927_aclc_init(0, 1);
  312. } else {
  313. tx4938_dmac_init(0, 2);
  314. tx4938_aclc_init();
  315. }
  316. platform_device_register_simple("txx9aclc-generic", -1, NULL, 0);
  317. txx9_iocled_init(RBTX4927_LED_ADDR - IO_BASE, -1, 3, 1, "green", NULL);
  318. rbtx4927_gpioled_init();
  319. }
  320. struct txx9_board_vec rbtx4927_vec __initdata = {
  321. .system = "Toshiba RBTX4927",
  322. .prom_init = rbtx4927_prom_init,
  323. .mem_setup = rbtx4927_mem_setup,
  324. .irq_setup = rbtx4927_irq_setup,
  325. .time_init = rbtx4927_time_init,
  326. .device_init = rbtx4927_device_init,
  327. .arch_init = rbtx4927_arch_init,
  328. #ifdef CONFIG_PCI
  329. .pci_map_irq = rbtx4927_pci_map_irq,
  330. #endif
  331. };
  332. struct txx9_board_vec rbtx4937_vec __initdata = {
  333. .system = "Toshiba RBTX4937",
  334. .prom_init = rbtx4927_prom_init,
  335. .mem_setup = rbtx4927_mem_setup,
  336. .irq_setup = rbtx4927_irq_setup,
  337. .time_init = rbtx4927_time_init,
  338. .device_init = rbtx4927_device_init,
  339. .arch_init = rbtx4937_arch_init,
  340. #ifdef CONFIG_PCI
  341. .pci_map_irq = rbtx4927_pci_map_irq,
  342. #endif
  343. };