setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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/bootinfo.h>
  54. #include <asm/io.h>
  55. #include <asm/processor.h>
  56. #include <asm/reboot.h>
  57. #include <asm/time.h>
  58. #include <asm/txx9tmr.h>
  59. #include <asm/txx9/generic.h>
  60. #include <asm/txx9/pci.h>
  61. #include <asm/txx9/rbtx4927.h>
  62. #include <asm/txx9/tx4938.h> /* for TX4937 */
  63. #ifdef CONFIG_SERIAL_TXX9
  64. #include <linux/serial_core.h>
  65. #endif
  66. /* These functions are used for rebooting or halting the machine*/
  67. extern void toshiba_rbtx4927_restart(char *command);
  68. extern void toshiba_rbtx4927_halt(void);
  69. extern void toshiba_rbtx4927_power_off(void);
  70. extern void toshiba_rbtx4927_irq_setup(void);
  71. char *prom_getcmdline(void);
  72. static int tx4927_ccfg_toeon = 1;
  73. #ifdef CONFIG_PCI
  74. static void __init tx4927_pci_setup(void)
  75. {
  76. int extarb = !(__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB);
  77. struct pci_controller *c = &txx9_primary_pcic;
  78. register_pci_controller(c);
  79. if (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66)
  80. txx9_pci_option =
  81. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  82. TXX9_PCI_OPT_CLK_66; /* already configured */
  83. /* Reset PCI Bus */
  84. writeb(1, rbtx4927_pcireset_addr);
  85. /* Reset PCIC */
  86. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  87. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  88. TXX9_PCI_OPT_CLK_66)
  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. tx4927_report_pciclk();
  96. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  97. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  98. TXX9_PCI_OPT_CLK_AUTO &&
  99. txx9_pci66_check(c, 0, 0)) {
  100. /* Reset PCI Bus */
  101. writeb(1, rbtx4927_pcireset_addr);
  102. /* Reset PCIC */
  103. txx9_set64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  104. tx4927_pciclk66_setup();
  105. mdelay(10);
  106. /* clear PCIC reset */
  107. txx9_clear64(&tx4927_ccfgptr->clkctr, TX4927_CLKCTR_PCIRST);
  108. writeb(0, rbtx4927_pcireset_addr);
  109. iob();
  110. /* Reinitialize PCIC */
  111. tx4927_report_pciclk();
  112. tx4927_pcic_setup(tx4927_pcicptr, c, extarb);
  113. }
  114. }
  115. static void __init tx4937_pci_setup(void)
  116. {
  117. int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
  118. struct pci_controller *c = &txx9_primary_pcic;
  119. register_pci_controller(c);
  120. if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
  121. txx9_pci_option =
  122. (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
  123. TXX9_PCI_OPT_CLK_66; /* already configured */
  124. /* Reset PCI Bus */
  125. writeb(1, rbtx4927_pcireset_addr);
  126. /* Reset PCIC */
  127. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  128. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  129. TXX9_PCI_OPT_CLK_66)
  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. tx4938_report_pciclk();
  137. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  138. if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
  139. TXX9_PCI_OPT_CLK_AUTO &&
  140. txx9_pci66_check(c, 0, 0)) {
  141. /* Reset PCI Bus */
  142. writeb(1, rbtx4927_pcireset_addr);
  143. /* Reset PCIC */
  144. txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  145. tx4938_pciclk66_setup();
  146. mdelay(10);
  147. /* clear PCIC reset */
  148. txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
  149. writeb(0, rbtx4927_pcireset_addr);
  150. iob();
  151. /* Reinitialize PCIC */
  152. tx4938_report_pciclk();
  153. tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
  154. }
  155. }
  156. static void __init rbtx4927_arch_init(void)
  157. {
  158. if (mips_machtype == MACH_TOSHIBA_RBTX4937)
  159. tx4937_pci_setup();
  160. else
  161. tx4927_pci_setup();
  162. }
  163. #else
  164. #define rbtx4927_arch_init NULL
  165. #endif /* CONFIG_PCI */
  166. static void __noreturn wait_forever(void)
  167. {
  168. while (1)
  169. if (cpu_wait)
  170. (*cpu_wait)();
  171. }
  172. void toshiba_rbtx4927_restart(char *command)
  173. {
  174. printk(KERN_NOTICE "System Rebooting...\n");
  175. /* enable the s/w reset register */
  176. writeb(RBTX4927_SW_RESET_ENABLE_SET, RBTX4927_SW_RESET_ENABLE);
  177. /* wait for enable to be seen */
  178. while ((readb(RBTX4927_SW_RESET_ENABLE) &
  179. RBTX4927_SW_RESET_ENABLE_SET) == 0x00);
  180. /* do a s/w reset */
  181. writeb(RBTX4927_SW_RESET_DO_SET, RBTX4927_SW_RESET_DO);
  182. /* do something passive while waiting for reset */
  183. local_irq_disable();
  184. wait_forever();
  185. /* no return */
  186. }
  187. void toshiba_rbtx4927_halt(void)
  188. {
  189. printk(KERN_NOTICE "System Halted\n");
  190. local_irq_disable();
  191. wait_forever();
  192. /* no return */
  193. }
  194. void toshiba_rbtx4927_power_off(void)
  195. {
  196. toshiba_rbtx4927_halt();
  197. /* no return */
  198. }
  199. static void __init rbtx4927_mem_setup(void)
  200. {
  201. int i;
  202. u32 cp0_config;
  203. char *argptr;
  204. /* f/w leaves this on at startup */
  205. clear_c0_status(ST0_ERL);
  206. /* enable caches -- HCP5 does this, pmon does not */
  207. cp0_config = read_c0_config();
  208. cp0_config = cp0_config & ~(TX49_CONF_IC | TX49_CONF_DC);
  209. write_c0_config(cp0_config);
  210. ioport_resource.end = 0xffffffff;
  211. iomem_resource.end = 0xffffffff;
  212. _machine_restart = toshiba_rbtx4927_restart;
  213. _machine_halt = toshiba_rbtx4927_halt;
  214. pm_power_off = toshiba_rbtx4927_power_off;
  215. for (i = 0; i < TX4927_NR_TMR; i++)
  216. txx9_tmr_init(TX4927_TMR_REG(0) & 0xfffffffffULL);
  217. #ifdef CONFIG_PCI
  218. txx9_alloc_pci_controller(&txx9_primary_pcic,
  219. RBTX4927_PCIMEM, RBTX4927_PCIMEM_SIZE,
  220. RBTX4927_PCIIO, RBTX4927_PCIIO_SIZE);
  221. #else
  222. set_io_port_base(KSEG1 + RBTX4927_ISA_IO_OFFSET);
  223. #endif
  224. /* CCFG */
  225. /* do reset on watchdog */
  226. tx4927_ccfg_set(TX4927_CCFG_WR);
  227. /* enable Timeout BusError */
  228. if (tx4927_ccfg_toeon)
  229. tx4927_ccfg_set(TX4927_CCFG_TOE);
  230. #ifdef CONFIG_SERIAL_TXX9
  231. {
  232. extern int early_serial_txx9_setup(struct uart_port *port);
  233. struct uart_port req;
  234. for(i = 0; i < 2; i++) {
  235. memset(&req, 0, sizeof(req));
  236. req.line = i;
  237. req.iotype = UPIO_MEM;
  238. req.membase = (char *)(0xff1ff300 + i * 0x100);
  239. req.mapbase = 0xff1ff300 + i * 0x100;
  240. req.irq = TXX9_IRQ_BASE + TX4927_IR_SIO(i);
  241. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  242. req.uartclk = 50000000;
  243. early_serial_txx9_setup(&req);
  244. }
  245. }
  246. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  247. argptr = prom_getcmdline();
  248. if (strstr(argptr, "console=") == NULL) {
  249. strcat(argptr, " console=ttyS0,38400");
  250. }
  251. #endif
  252. #endif
  253. #ifdef CONFIG_ROOT_NFS
  254. argptr = prom_getcmdline();
  255. if (strstr(argptr, "root=") == NULL) {
  256. strcat(argptr, " root=/dev/nfs rw");
  257. }
  258. #endif
  259. #ifdef CONFIG_IP_PNP
  260. argptr = prom_getcmdline();
  261. if (strstr(argptr, "ip=") == NULL) {
  262. strcat(argptr, " ip=any");
  263. }
  264. #endif
  265. }
  266. static void __init rbtx4927_time_init(void)
  267. {
  268. /*
  269. * ASSUMPTION: PCIDIVMODE is configured for PCI 33MHz or 66MHz.
  270. *
  271. * For TX4927:
  272. * PCIDIVMODE[12:11]'s initial value is given by S9[4:3] (ON:0, OFF:1).
  273. * CPU 166MHz: PCI 66MHz : PCIDIVMODE: 00 (1/2.5)
  274. * CPU 200MHz: PCI 66MHz : PCIDIVMODE: 01 (1/3)
  275. * CPU 166MHz: PCI 33MHz : PCIDIVMODE: 10 (1/5)
  276. * CPU 200MHz: PCI 33MHz : PCIDIVMODE: 11 (1/6)
  277. * i.e. S9[3]: ON (83MHz), OFF (100MHz)
  278. *
  279. * For TX4937:
  280. * PCIDIVMODE[12:11]'s initial value is given by S1[5:4] (ON:0, OFF:1)
  281. * PCIDIVMODE[10] is 0.
  282. * CPU 266MHz: PCI 33MHz : PCIDIVMODE: 000 (1/8)
  283. * CPU 266MHz: PCI 66MHz : PCIDIVMODE: 001 (1/4)
  284. * CPU 300MHz: PCI 33MHz : PCIDIVMODE: 010 (1/9)
  285. * CPU 300MHz: PCI 66MHz : PCIDIVMODE: 011 (1/4.5)
  286. * CPU 333MHz: PCI 33MHz : PCIDIVMODE: 100 (1/10)
  287. * CPU 333MHz: PCI 66MHz : PCIDIVMODE: 101 (1/5)
  288. */
  289. if (mips_machtype == MACH_TOSHIBA_RBTX4937)
  290. switch ((unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg) &
  291. TX4938_CCFG_PCIDIVMODE_MASK) {
  292. case TX4938_CCFG_PCIDIVMODE_8:
  293. case TX4938_CCFG_PCIDIVMODE_4:
  294. txx9_cpu_clock = 266666666; /* 266MHz */
  295. break;
  296. case TX4938_CCFG_PCIDIVMODE_9:
  297. case TX4938_CCFG_PCIDIVMODE_4_5:
  298. txx9_cpu_clock = 300000000; /* 300MHz */
  299. break;
  300. default:
  301. txx9_cpu_clock = 333333333; /* 333MHz */
  302. }
  303. else
  304. switch ((unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg) &
  305. TX4927_CCFG_PCIDIVMODE_MASK) {
  306. case TX4927_CCFG_PCIDIVMODE_2_5:
  307. case TX4927_CCFG_PCIDIVMODE_5:
  308. txx9_cpu_clock = 166666666; /* 166MHz */
  309. break;
  310. default:
  311. txx9_cpu_clock = 200000000; /* 200MHz */
  312. }
  313. /* change default value to udelay/mdelay take reasonable time */
  314. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  315. mips_hpt_frequency = txx9_cpu_clock / 2;
  316. if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)
  317. txx9_clockevent_init(TX4927_TMR_REG(0) & 0xfffffffffULL,
  318. TXX9_IRQ_BASE + 17,
  319. 50000000);
  320. }
  321. static int __init toshiba_rbtx4927_rtc_init(void)
  322. {
  323. static struct resource __initdata res = {
  324. .start = 0x1c010000,
  325. .end = 0x1c010000 + 0x800 - 1,
  326. .flags = IORESOURCE_MEM,
  327. };
  328. struct platform_device *dev =
  329. platform_device_register_simple("rtc-ds1742", -1, &res, 1);
  330. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  331. }
  332. static int __init rbtx4927_ne_init(void)
  333. {
  334. static struct resource __initdata res[] = {
  335. {
  336. .start = RBTX4927_RTL_8019_BASE,
  337. .end = RBTX4927_RTL_8019_BASE + 0x20 - 1,
  338. .flags = IORESOURCE_IO,
  339. }, {
  340. .start = RBTX4927_RTL_8019_IRQ,
  341. .flags = IORESOURCE_IRQ,
  342. }
  343. };
  344. struct platform_device *dev =
  345. platform_device_register_simple("ne", -1,
  346. res, ARRAY_SIZE(res));
  347. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  348. }
  349. /* Watchdog support */
  350. static int __init txx9_wdt_init(unsigned long base)
  351. {
  352. struct resource res = {
  353. .start = base,
  354. .end = base + 0x100 - 1,
  355. .flags = IORESOURCE_MEM,
  356. };
  357. struct platform_device *dev =
  358. platform_device_register_simple("txx9wdt", -1, &res, 1);
  359. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  360. }
  361. static int __init rbtx4927_wdt_init(void)
  362. {
  363. return txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
  364. }
  365. static void __init rbtx4927_device_init(void)
  366. {
  367. toshiba_rbtx4927_rtc_init();
  368. rbtx4927_ne_init();
  369. rbtx4927_wdt_init();
  370. }
  371. struct txx9_board_vec rbtx4927_vec __initdata = {
  372. .type = MACH_TOSHIBA_RBTX4927,
  373. .system = "Toshiba RBTX4927",
  374. .prom_init = rbtx4927_prom_init,
  375. .mem_setup = rbtx4927_mem_setup,
  376. .irq_setup = rbtx4927_irq_setup,
  377. .time_init = rbtx4927_time_init,
  378. .device_init = rbtx4927_device_init,
  379. .arch_init = rbtx4927_arch_init,
  380. #ifdef CONFIG_PCI
  381. .pci_map_irq = rbtx4927_pci_map_irq,
  382. #endif
  383. };
  384. struct txx9_board_vec rbtx4937_vec __initdata = {
  385. .type = MACH_TOSHIBA_RBTX4937,
  386. .system = "Toshiba RBTX4937",
  387. .prom_init = rbtx4927_prom_init,
  388. .mem_setup = rbtx4927_mem_setup,
  389. .irq_setup = rbtx4927_irq_setup,
  390. .time_init = rbtx4927_time_init,
  391. .device_init = rbtx4927_device_init,
  392. .arch_init = rbtx4927_arch_init,
  393. #ifdef CONFIG_PCI
  394. .pci_map_irq = rbtx4927_pci_map_irq,
  395. #endif
  396. };