setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. *
  3. * Copyright 2001 MontaVista Software Inc.
  4. * Author: jsun@mvista.com or jsun@junsun.net
  5. *
  6. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  7. *
  8. * arch/mips/ddb5xxx/ddb5477/setup.c
  9. * Setup file for DDB5477.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/sched.h>
  20. #include <linux/pci.h>
  21. #include <linux/ide.h>
  22. #include <linux/irq.h>
  23. #include <linux/fs.h>
  24. #include <linux/ioport.h>
  25. #include <linux/param.h> /* for HZ */
  26. #include <linux/major.h>
  27. #include <linux/kdev_t.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/pm.h>
  30. #include <asm/cpu.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/addrspace.h>
  33. #include <asm/time.h>
  34. #include <asm/bcache.h>
  35. #include <asm/irq.h>
  36. #include <asm/reboot.h>
  37. #include <asm/gdb-stub.h>
  38. #include <asm/traps.h>
  39. #include <asm/debug.h>
  40. #include <asm/ddb5xxx/ddb5xxx.h>
  41. #include "lcd44780.h"
  42. #define USE_CPU_COUNTER_TIMER /* whether we use cpu counter */
  43. #define SP_TIMER_BASE DDB_SPT1CTRL_L
  44. #define SP_TIMER_IRQ VRC5477_IRQ_SPT1
  45. static int bus_frequency = CONFIG_DDB5477_BUS_FREQUENCY*1000;
  46. static void ddb_machine_restart(char *command)
  47. {
  48. static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
  49. u32 t;
  50. /* PCI cold reset */
  51. ddb_pci_reset_bus();
  52. /* CPU cold reset */
  53. t = ddb_in32(DDB_CPUSTAT);
  54. db_assert((t&1));
  55. ddb_out32(DDB_CPUSTAT, t);
  56. /* Call the PROM */
  57. back_to_prom();
  58. }
  59. static void ddb_machine_halt(void)
  60. {
  61. printk("DDB Vrc-5477 halted.\n");
  62. while (1);
  63. }
  64. static void ddb_machine_power_off(void)
  65. {
  66. printk("DDB Vrc-5477 halted. Please turn off the power.\n");
  67. while (1);
  68. }
  69. extern void rtc_ds1386_init(unsigned long base);
  70. static unsigned int __init detect_bus_frequency(unsigned long rtc_base)
  71. {
  72. unsigned int freq;
  73. unsigned char c;
  74. unsigned int t1, t2;
  75. unsigned i;
  76. ddb_out32(SP_TIMER_BASE, 0xffffffff);
  77. ddb_out32(SP_TIMER_BASE+4, 0x1);
  78. ddb_out32(SP_TIMER_BASE+8, 0xffffffff);
  79. /* check if rtc is running */
  80. c= *(volatile unsigned char*)rtc_base;
  81. for(i=0; (c == *(volatile unsigned char*)rtc_base) && (i<100000000); i++);
  82. if (c == *(volatile unsigned char*)rtc_base) {
  83. printk("Failed to detect bus frequency. Use default 83.3MHz.\n");
  84. return 83333000;
  85. }
  86. c= *(volatile unsigned char*)rtc_base;
  87. while (c == *(volatile unsigned char*)rtc_base);
  88. /* we are now at the turn of 1/100th second, if no error. */
  89. t1 = ddb_in32(SP_TIMER_BASE+8);
  90. for (i=0; i< 10; i++) {
  91. c= *(volatile unsigned char*)rtc_base;
  92. while (c == *(volatile unsigned char*)rtc_base);
  93. /* we are now at the turn of another 1/100th second */
  94. t2 = ddb_in32(SP_TIMER_BASE+8);
  95. }
  96. ddb_out32(SP_TIMER_BASE+4, 0x0); /* disable it again */
  97. freq = (t1 - t2)*10;
  98. printk("DDB bus frequency detection : %u \n", freq);
  99. return freq;
  100. }
  101. static void __init ddb_time_init(void)
  102. {
  103. unsigned long rtc_base;
  104. unsigned int i;
  105. /* we have ds1396 RTC chip */
  106. if (mips_machtype == MACH_NEC_ROCKHOPPER
  107. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  108. rtc_base = KSEG1ADDR(DDB_LCS2_BASE);
  109. } else {
  110. rtc_base = KSEG1ADDR(DDB_LCS1_BASE);
  111. }
  112. rtc_ds1386_init(rtc_base);
  113. /* do we need to do run-time detection of bus speed? */
  114. if (bus_frequency == 0) {
  115. bus_frequency = detect_bus_frequency(rtc_base);
  116. }
  117. /* mips_hpt_frequency is 1/2 of the cpu core freq */
  118. i = (read_c0_config() >> 28 ) & 7;
  119. if ((current_cpu_data.cputype == CPU_R5432) && (i == 3))
  120. i = 4;
  121. mips_hpt_frequency = bus_frequency*(i+4)/4;
  122. }
  123. void __init plat_timer_setup(struct irqaction *irq)
  124. {
  125. #if defined(USE_CPU_COUNTER_TIMER)
  126. /* we are using the cpu counter for timer interrupts */
  127. setup_irq(CPU_IRQ_BASE + 7, irq);
  128. #else
  129. /* if we use Special purpose timer 1 */
  130. ddb_out32(SP_TIMER_BASE, bus_frequency/HZ);
  131. ddb_out32(SP_TIMER_BASE+4, 0x1);
  132. setup_irq(SP_TIMER_IRQ, irq);
  133. #endif
  134. }
  135. static void ddb5477_board_init(void);
  136. extern struct pci_controller ddb5477_ext_controller;
  137. extern struct pci_controller ddb5477_io_controller;
  138. void __init plat_mem_setup(void)
  139. {
  140. /* initialize board - we don't trust the loader */
  141. ddb5477_board_init();
  142. set_io_port_base(KSEG1ADDR(DDB_PCI_IO_BASE));
  143. board_time_init = ddb_time_init;
  144. _machine_restart = ddb_machine_restart;
  145. _machine_halt = ddb_machine_halt;
  146. pm_power_off = ddb_machine_power_off;
  147. /* setup resource limits */
  148. ioport_resource.end = DDB_PCI0_IO_SIZE + DDB_PCI1_IO_SIZE - 1;
  149. iomem_resource.end = 0xffffffff;
  150. /* Reboot on panic */
  151. panic_timeout = 180;
  152. register_pci_controller (&ddb5477_ext_controller);
  153. register_pci_controller (&ddb5477_io_controller);
  154. }
  155. static void __init ddb5477_board_init(void)
  156. {
  157. /* ----------- setup PDARs ------------ */
  158. /* SDRAM should have been set */
  159. db_assert(ddb_in32(DDB_SDRAM0) ==
  160. ddb_calc_pdar(DDB_SDRAM_BASE, board_ram_size, 32, 0, 1));
  161. /* SDRAM1 should be turned off. What is this for anyway ? */
  162. db_assert( (ddb_in32(DDB_SDRAM1) & 0xf) == 0);
  163. /* Setup local bus. */
  164. /* Flash U12 PDAR and timing. */
  165. ddb_set_pdar(DDB_LCS0, DDB_LCS0_BASE, DDB_LCS0_SIZE, 16, 0, 0);
  166. ddb_out32(DDB_LCST0, 0x00090842);
  167. /* We need to setup LCS1 and LCS2 differently based on the
  168. board_version */
  169. if (mips_machtype == MACH_NEC_ROCKHOPPER) {
  170. /* Flash U13 PDAR and timing. */
  171. ddb_set_pdar(DDB_LCS1, DDB_LCS1_BASE, DDB_LCS1_SIZE, 16, 0, 0);
  172. ddb_out32(DDB_LCST1, 0x00090842);
  173. /* EPLD (NVRAM, switch, LCD, and mezzanie). */
  174. ddb_set_pdar(DDB_LCS2, DDB_LCS2_BASE, DDB_LCS2_SIZE, 8, 0, 0);
  175. } else {
  176. /* misc */
  177. ddb_set_pdar(DDB_LCS1, DDB_LCS1_BASE, DDB_LCS1_SIZE, 8, 0, 0);
  178. /* mezzanie (?) */
  179. ddb_set_pdar(DDB_LCS2, DDB_LCS2_BASE, DDB_LCS2_SIZE, 16, 0, 0);
  180. }
  181. /* verify VRC5477 base addr */
  182. db_assert(ddb_in32(DDB_VRC5477) ==
  183. ddb_calc_pdar(DDB_VRC5477_BASE, DDB_VRC5477_SIZE, 32, 0, 1));
  184. /* verify BOOT ROM addr */
  185. db_assert(ddb_in32(DDB_BOOTCS) ==
  186. ddb_calc_pdar(DDB_BOOTCS_BASE, DDB_BOOTCS_SIZE, 8, 0, 0));
  187. /* setup PCI windows - window0 for MEM/config, window1 for IO */
  188. ddb_set_pdar(DDB_PCIW0, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
  189. ddb_set_pdar(DDB_PCIW1, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
  190. ddb_set_pdar(DDB_IOPCIW0, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
  191. ddb_set_pdar(DDB_IOPCIW1, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
  192. /* ------------ reset PCI bus and BARs ----------------- */
  193. ddb_pci_reset_bus();
  194. ddb_out32(DDB_BARM010, 0x00000008);
  195. ddb_out32(DDB_BARM011, 0x00000008);
  196. ddb_out32(DDB_BARC0, 0xffffffff);
  197. ddb_out32(DDB_BARM230, 0xffffffff);
  198. ddb_out32(DDB_BAR00, 0xffffffff);
  199. ddb_out32(DDB_BAR10, 0xffffffff);
  200. ddb_out32(DDB_BAR20, 0xffffffff);
  201. ddb_out32(DDB_BAR30, 0xffffffff);
  202. ddb_out32(DDB_BAR40, 0xffffffff);
  203. ddb_out32(DDB_BAR50, 0xffffffff);
  204. ddb_out32(DDB_BARB0, 0xffffffff);
  205. ddb_out32(DDB_BARC1, 0xffffffff);
  206. ddb_out32(DDB_BARM231, 0xffffffff);
  207. ddb_out32(DDB_BAR01, 0xffffffff);
  208. ddb_out32(DDB_BAR11, 0xffffffff);
  209. ddb_out32(DDB_BAR21, 0xffffffff);
  210. ddb_out32(DDB_BAR31, 0xffffffff);
  211. ddb_out32(DDB_BAR41, 0xffffffff);
  212. ddb_out32(DDB_BAR51, 0xffffffff);
  213. ddb_out32(DDB_BARB1, 0xffffffff);
  214. /*
  215. * We use pci master register 0 for memory space / config space
  216. * And we use register 1 for IO space.
  217. * Note that for memory space, we bump up the pci base address
  218. * so that we have 1:1 mapping between PCI memory and cpu physical.
  219. * For PCI IO space, it starts from 0 in PCI IO space but with
  220. * DDB_xx_IO_BASE in CPU physical address space.
  221. */
  222. ddb_set_pmr(DDB_PCIINIT00, DDB_PCICMD_MEM, DDB_PCI0_MEM_BASE,
  223. DDB_PCI_ACCESS_32);
  224. ddb_set_pmr(DDB_PCIINIT10, DDB_PCICMD_IO, 0, DDB_PCI_ACCESS_32);
  225. ddb_set_pmr(DDB_PCIINIT01, DDB_PCICMD_MEM, DDB_PCI1_MEM_BASE,
  226. DDB_PCI_ACCESS_32);
  227. ddb_set_pmr(DDB_PCIINIT11, DDB_PCICMD_IO, DDB_PCI0_IO_SIZE,
  228. DDB_PCI_ACCESS_32);
  229. /* PCI cross window should be set properly */
  230. ddb_set_pdar(DDB_BARP00, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
  231. ddb_set_pdar(DDB_BARP10, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
  232. ddb_set_pdar(DDB_BARP01, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
  233. ddb_set_pdar(DDB_BARP11, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
  234. if (mips_machtype == MACH_NEC_ROCKHOPPER
  235. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  236. /* Disable bus diagnostics. */
  237. ddb_out32(DDB_PCICTL0_L, 0);
  238. ddb_out32(DDB_PCICTL0_H, 0);
  239. ddb_out32(DDB_PCICTL1_L, 0);
  240. ddb_out32(DDB_PCICTL1_H, 0);
  241. }
  242. if (mips_machtype == MACH_NEC_ROCKHOPPER) {
  243. u16 vid;
  244. struct pci_bus bus;
  245. struct pci_dev dev_m1533;
  246. extern struct pci_ops ddb5477_ext_pci_ops;
  247. bus.parent = NULL; /* we scan the top level only */
  248. bus.ops = &ddb5477_ext_pci_ops;
  249. dev_m1533.bus = &bus;
  250. dev_m1533.sysdata = NULL;
  251. dev_m1533.devfn = 7*8; // slot 7: M1533 SouthBridge.
  252. pci_read_config_word(&dev_m1533, 0, &vid);
  253. if (vid == PCI_VENDOR_ID_AL) {
  254. printk("Changing mips_machtype to MACH_NEC_ROCKHOPPERII\n");
  255. mips_machtype = MACH_NEC_ROCKHOPPERII;
  256. }
  257. }
  258. /* enable USB input buffers */
  259. ddb_out32(DDB_PIBMISC, 0x00000007);
  260. /* For dual-function pins, make them all non-GPIO */
  261. ddb_out32(DDB_GIUFUNSEL, 0x0);
  262. // ddb_out32(DDB_GIUFUNSEL, 0xfe0fcfff); /* NEC recommanded value */
  263. if (mips_machtype == MACH_NEC_ROCKHOPPERII) {
  264. /* enable IDE controller on Ali chip (south bridge) */
  265. u8 temp8;
  266. struct pci_bus bus;
  267. struct pci_dev dev_m1533;
  268. struct pci_dev dev_m5229;
  269. extern struct pci_ops ddb5477_ext_pci_ops;
  270. /* Setup M1535 registers */
  271. bus.parent = NULL; /* we scan the top level only */
  272. bus.ops = &ddb5477_ext_pci_ops;
  273. dev_m1533.bus = &bus;
  274. dev_m1533.sysdata = NULL;
  275. dev_m1533.devfn = 7*8; // slot 7: M1533 SouthBridge.
  276. /* setup IDE controller
  277. * enable IDE controller (bit 6 - 1)
  278. * IDE IDSEL to be addr:A15 (bit 4:5 - 11)
  279. * disable IDE ATA Secondary Bus Signal Pad Control (bit 3 - 0)
  280. * enable IDE ATA Primary Bus Signal Pad Control (bit 2 - 1)
  281. */
  282. pci_write_config_byte(&dev_m1533, 0x58, 0x74);
  283. /*
  284. * positive decode (bit6 -0)
  285. * enable IDE controler interrupt (bit 4 -1)
  286. * setup SIRQ to point to IRQ 14 (bit 3:0 - 1101)
  287. */
  288. pci_write_config_byte(&dev_m1533, 0x44, 0x1d);
  289. /* Setup M5229 registers */
  290. dev_m5229.bus = &bus;
  291. dev_m5229.sysdata = NULL;
  292. dev_m5229.devfn = 4*8; // slot 4 (AD15): M5229 IDE
  293. /*
  294. * enable IDE in the M5229 config register 0x50 (bit 0 - 1)
  295. * M5229 IDSEL is addr:15; see above setting
  296. */
  297. pci_read_config_byte(&dev_m5229, 0x50, &temp8);
  298. pci_write_config_byte(&dev_m5229, 0x50, temp8 | 0x1);
  299. /*
  300. * enable bus master (bit 2) and IO decoding (bit 0)
  301. */
  302. pci_read_config_byte(&dev_m5229, 0x04, &temp8);
  303. pci_write_config_byte(&dev_m5229, 0x04, temp8 | 0x5);
  304. /*
  305. * enable native, copied from arch/ppc/k2boot/head.S
  306. * TODO - need volatile, need to be portable
  307. */
  308. pci_write_config_byte(&dev_m5229, 0x09, 0xef);
  309. /* Set Primary Channel Command Block Timing */
  310. pci_write_config_byte(&dev_m5229, 0x59, 0x31);
  311. /*
  312. * Enable primary channel 40-pin cable
  313. * M5229 register 0x4a (bit 0)
  314. */
  315. pci_read_config_byte(&dev_m5229, 0x4a, &temp8);
  316. pci_write_config_byte(&dev_m5229, 0x4a, temp8 | 0x1);
  317. }
  318. if (mips_machtype == MACH_NEC_ROCKHOPPER
  319. || mips_machtype == MACH_NEC_ROCKHOPPERII) {
  320. printk("lcd44780: initializing\n");
  321. lcd44780_init();
  322. lcd44780_puts("MontaVista Linux");
  323. }
  324. }