setup.c 9.0 KB

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