setup.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * arch/mips/ddb5476/setup.c -- NEC DDB Vrc-5476 setup routines
  3. *
  4. * Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
  5. * Sony Software Development Center Europe (SDCE), Brussels
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kbd_ll.h>
  9. #include <linux/kernel.h>
  10. #include <linux/kdev_t.h>
  11. #include <linux/types.h>
  12. #include <linux/sched.h>
  13. #include <linux/pci.h>
  14. #include <asm/addrspace.h>
  15. #include <asm/bcache.h>
  16. #include <asm/irq.h>
  17. #include <asm/reboot.h>
  18. #include <asm/gdb-stub.h>
  19. #include <asm/time.h>
  20. #include <asm/debug.h>
  21. #include <asm/traps.h>
  22. #include <asm/ddb5xxx/ddb5xxx.h>
  23. // #define USE_CPU_COUNTER_TIMER /* whether we use cpu counter */
  24. #ifdef USE_CPU_COUNTER_TIMER
  25. #define CPU_COUNTER_FREQUENCY 83000000
  26. #else
  27. /* otherwise we use general purpose timer */
  28. #define TIMER_FREQUENCY 83000000
  29. #define TIMER_BASE DDB_T2CTRL
  30. #define TIMER_IRQ (VRC5476_IRQ_BASE + VRC5476_IRQ_GPT)
  31. #endif
  32. static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
  33. static void ddb_machine_restart(char *command)
  34. {
  35. u32 t;
  36. /* PCI cold reset */
  37. t = ddb_in32(DDB_PCICTRL + 4);
  38. t |= 0x40000000;
  39. ddb_out32(DDB_PCICTRL + 4, t);
  40. /* CPU cold reset */
  41. t = ddb_in32(DDB_CPUSTAT);
  42. t |= 1;
  43. ddb_out32(DDB_CPUSTAT, t);
  44. /* Call the PROM */
  45. back_to_prom();
  46. }
  47. static void ddb_machine_halt(void)
  48. {
  49. printk(KERN_NOTICE "DDB Vrc-5476 halted.\n");
  50. while (1);
  51. }
  52. static void ddb_machine_power_off(void)
  53. {
  54. printk(KERN_NOTICE "DDB Vrc-5476 halted. Please turn off the power.\n");
  55. while (1);
  56. }
  57. extern void rtc_ds1386_init(unsigned long base);
  58. static void __init ddb_time_init(void)
  59. {
  60. #if defined(USE_CPU_COUNTER_TIMER)
  61. mips_hpt_frequency = CPU_COUNTER_FREQUENCY;
  62. #endif
  63. /* we have ds1396 RTC chip */
  64. rtc_ds1386_init(KSEG1ADDR(DDB_PCI_MEM_BASE));
  65. }
  66. extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
  67. static void __init ddb_timer_setup(struct irqaction *irq)
  68. {
  69. #if defined(USE_CPU_COUNTER_TIMER)
  70. unsigned int count;
  71. /* we are using the cpu counter for timer interrupts */
  72. setup_irq(CPU_IRQ_BASE + 7, irq);
  73. /* to generate the first timer interrupt */
  74. count = read_c0_count();
  75. write_c0_compare(count + 1000);
  76. #else
  77. ddb_out32(TIMER_BASE, TIMER_FREQUENCY/HZ);
  78. ddb_out32(TIMER_BASE+4, 0x1); /* enable timer */
  79. setup_irq(TIMER_IRQ, irq);
  80. #endif
  81. }
  82. static struct {
  83. struct resource dma1;
  84. struct resource timer;
  85. struct resource rtc;
  86. struct resource dma_page_reg;
  87. struct resource dma2;
  88. } ddb5476_ioport = {
  89. {
  90. "dma1", 0x00, 0x1f, IORESOURCE_BUSY}, {
  91. "timer", 0x40, 0x5f, IORESOURCE_BUSY}, {
  92. "rtc", 0x70, 0x7f, IORESOURCE_BUSY}, {
  93. "dma page reg", 0x80, 0x8f, IORESOURCE_BUSY}, {
  94. "dma2", 0xc0, 0xdf, IORESOURCE_BUSY}
  95. };
  96. static struct {
  97. struct resource nile4;
  98. } ddb5476_iomem = {
  99. { "Nile 4", DDB_BASE, DDB_BASE + DDB_SIZE - 1, IORESOURCE_BUSY}
  100. };
  101. static void ddb5476_board_init(void);
  102. static void __init ddb5476_setup(void)
  103. {
  104. set_io_port_base(KSEG1ADDR(DDB_PCI_IO_BASE));
  105. board_time_init = ddb_time_init;
  106. board_timer_setup = ddb_timer_setup;
  107. _machine_restart = ddb_machine_restart;
  108. _machine_halt = ddb_machine_halt;
  109. _machine_power_off = ddb_machine_power_off;
  110. /* request io port/mem resources */
  111. if (request_resource(&ioport_resource, &ddb5476_ioport.dma1) ||
  112. request_resource(&ioport_resource, &ddb5476_ioport.timer) ||
  113. request_resource(&ioport_resource, &ddb5476_ioport.rtc) ||
  114. request_resource(&ioport_resource,
  115. &ddb5476_ioport.dma_page_reg)
  116. || request_resource(&ioport_resource, &ddb5476_ioport.dma2)
  117. || request_resource(&iomem_resource, &ddb5476_iomem.nile4)) {
  118. printk
  119. ("ddb_setup - requesting oo port resources failed.\n");
  120. for (;;);
  121. }
  122. /* Reboot on panic */
  123. panic_timeout = 180;
  124. /* [jsun] we need to set BAR0 so that SDRAM 0 appears at 0x0 in PCI */
  125. /* *(long*)0xbfa00218 = 0x8; */
  126. /* board initialization stuff */
  127. ddb5476_board_init();
  128. }
  129. early_initcall(ddb5476_setup);
  130. /*
  131. * We don't trust bios. We essentially does hardware re-initialization
  132. * as complete as possible, as far as we know we can safely do.
  133. */
  134. static void ddb5476_board_init(void)
  135. {
  136. /* ----------- setup PDARs ------------ */
  137. /* check SDRAM0, whether we are on MEM bus does not matter */
  138. db_assert((ddb_in32(DDB_SDRAM0) & 0xffffffef) ==
  139. ddb_calc_pdar(DDB_SDRAM_BASE, DDB_SDRAM_SIZE, 32, 0, 1));
  140. /* SDRAM1 should be turned off. What is this for anyway ? */
  141. db_assert( (ddb_in32(DDB_SDRAM1) & 0xf) == 0);
  142. /* flash 1&2, DDB status, DDB control */
  143. ddb_set_pdar(DDB_DCS2, DDB_DCS2_BASE, DDB_DCS2_SIZE, 16, 0, 0);
  144. ddb_set_pdar(DDB_DCS3, DDB_DCS3_BASE, DDB_DCS3_SIZE, 16, 0, 0);
  145. ddb_set_pdar(DDB_DCS4, DDB_DCS4_BASE, DDB_DCS4_SIZE, 8, 0, 0);
  146. ddb_set_pdar(DDB_DCS5, DDB_DCS5_BASE, DDB_DCS5_SIZE, 8, 0, 0);
  147. /* shut off other pdar so they don't accidentally get into the way */
  148. ddb_set_pdar(DDB_DCS6, 0xffffffff, 0, 32, 0, 0);
  149. ddb_set_pdar(DDB_DCS7, 0xffffffff, 0, 32, 0, 0);
  150. ddb_set_pdar(DDB_DCS8, 0xffffffff, 0, 32, 0, 0);
  151. /* verify VRC5477 base addr */
  152. /* don't care about some details */
  153. db_assert((ddb_in32(DDB_INTCS) & 0xffffff0f) ==
  154. ddb_calc_pdar(DDB_INTCS_BASE, DDB_INTCS_SIZE, 8, 0, 0));
  155. /* verify BOOT ROM addr */
  156. /* don't care about some details */
  157. db_assert((ddb_in32(DDB_BOOTCS) & 0xffffff0f) ==
  158. ddb_calc_pdar(DDB_BOOTCS_BASE, DDB_BOOTCS_SIZE, 8, 0, 0));
  159. /* setup PCI windows - window1 for MEM/config, window0 for IO */
  160. ddb_set_pdar(DDB_PCIW0, DDB_PCI_IO_BASE, DDB_PCI_IO_SIZE, 32, 0, 1);
  161. ddb_set_pmr(DDB_PCIINIT0, DDB_PCICMD_IO, 0, DDB_PCI_ACCESS_32);
  162. ddb_set_pdar(DDB_PCIW1, DDB_PCI_MEM_BASE, DDB_PCI_MEM_SIZE, 32, 0, 1);
  163. ddb_set_pmr(DDB_PCIINIT1, DDB_PCICMD_MEM, DDB_PCI_MEM_BASE, DDB_PCI_ACCESS_32);
  164. /* ----------- setup PDARs ------------ */
  165. /* this is problematic - it will reset Aladin which cause we loose
  166. * serial port, and we don't know how to set up Aladin chip again.
  167. */
  168. // ddb_pci_reset_bus();
  169. ddb_out32(DDB_BAR0, 0x00000008);
  170. ddb_out32(DDB_BARC, 0xffffffff);
  171. ddb_out32(DDB_BARB, 0xffffffff);
  172. ddb_out32(DDB_BAR1, 0xffffffff);
  173. ddb_out32(DDB_BAR2, 0xffffffff);
  174. ddb_out32(DDB_BAR3, 0xffffffff);
  175. ddb_out32(DDB_BAR4, 0xffffffff);
  176. ddb_out32(DDB_BAR5, 0xffffffff);
  177. ddb_out32(DDB_BAR6, 0xffffffff);
  178. ddb_out32(DDB_BAR7, 0xffffffff);
  179. ddb_out32(DDB_BAR8, 0xffffffff);
  180. /* ----------- switch PCI1 to PCI CONFIG space ------------ */
  181. ddb_set_pdar(DDB_PCIW1, DDB_PCI_CONFIG_BASE, DDB_PCI_CONFIG_SIZE, 32, 0, 1);
  182. ddb_set_pmr(DDB_PCIINIT1, DDB_PCICMD_CFG, 0x0, DDB_PCI_ACCESS_32);
  183. /* ----- M1543 PCI setup ------ */
  184. /* we know M1543 PCI-ISA controller is at addr:18 */
  185. /* xxxx1010 makes USB at addr:13 and PMU at addr:14 */
  186. *(volatile unsigned char *) 0xa8040072 &= 0xf0;
  187. *(volatile unsigned char *) 0xa8040072 |= 0xa;
  188. /* setup USB interrupt to IRQ 9, (bit 0:3 - 0001)
  189. * no IOCHRDY signal, (bit 7 - 1)
  190. * M1543C & M7101 VID and Subsys Device ID are read-only (bit 6 - 1)
  191. * Make USB Master INTAJ level to edge conversion (bit 4 - 1)
  192. */
  193. *(unsigned char *) 0xa8040074 = 0xd1;
  194. /* setup PMU(SCI to IRQ 10 (bit 0:3 - 0011)
  195. * SCI routing to IRQ 13 disabled (bit 7 - 1)
  196. * SCI interrupt level to edge conversion bypassed (bit 4 - 0)
  197. */
  198. *(unsigned char *) 0xa8040076 = 0x83;
  199. /* setup IDE controller
  200. * enable IDE controller (bit 6 - 1)
  201. * IDE IDSEL to be addr:24 (bit 4:5 - 11)
  202. * no IDE ATA Secondary Bus Signal Pad Control (bit 3 - 0)
  203. * no IDE ATA Primary Bus Signal Pad Control (bit 2 - 0)
  204. * primary IRQ is 14, secondary is 15 (bit 1:0 - 01
  205. */
  206. // *(unsigned char*)0xa8040058 = 0x71;
  207. // *(unsigned char*)0xa8040058 = 0x79;
  208. // *(unsigned char*)0xa8040058 = 0x74; // use SIRQ, primary tri-state
  209. *(unsigned char *) 0xa8040058 = 0x75; // primary tri-state
  210. #if 0
  211. /* this is not necessary if M5229 does not use SIRQ */
  212. *(unsigned char *) 0xa8040044 = 0x0d; // primary to IRQ 14
  213. *(unsigned char *) 0xa8040075 = 0x0d; // secondary to IRQ 14
  214. #endif
  215. /* enable IDE in the M5229 config register 0x50 (bit 0 - 1) */
  216. /* M5229 IDSEL is addr:24; see above setting */
  217. *(unsigned char *) 0xa9000050 |= 0x1;
  218. /* enable bus master (bit 2) and IO decoding (bit 0) */
  219. *(unsigned char *) 0xa9000004 |= 0x5;
  220. /* enable native, copied from arch/ppc/k2boot/head.S */
  221. /* TODO - need volatile, need to be portable */
  222. *(unsigned char *) 0xa9000009 = 0xff;
  223. /* ----- end of M1543 PCI setup ------ */
  224. /* ----- reset on-board ether chip ------ */
  225. *((volatile u32 *) 0xa8020004) |= 1; /* decode I/O */
  226. *((volatile u32 *) 0xa8020010) = 0; /* set BAR address */
  227. /* send reset command */
  228. *((volatile u32 *) 0xa6000000) = 1; /* do a soft reset */
  229. /* disable ether chip */
  230. *((volatile u32 *) 0xa8020004) = 0; /* disable any decoding */
  231. /* put it into sleep */
  232. *((volatile u32 *) 0xa8020040) = 0x80000000;
  233. /* ----- end of reset on-board ether chip ------ */
  234. /* ----------- switch PCI1 back to PCI MEM space ------------ */
  235. ddb_set_pdar(DDB_PCIW1, DDB_PCI_MEM_BASE, DDB_PCI_MEM_SIZE, 32, 0, 1);
  236. ddb_set_pmr(DDB_PCIINIT1, DDB_PCICMD_MEM, DDB_PCI_MEM_BASE, DDB_PCI_ACCESS_32);
  237. }